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
)
547 status
= cli_lock32(c
, fnum
, offset
, len
, -1, WRITE_LOCK
);
549 while (!NT_STATUS_IS_OK(status
)) {
550 if (!check_both_error(__LINE__
, status
, ERRDOS
,
551 ERRlock
, NT_STATUS_LOCK_NOT_GRANTED
)) {
555 status
= cli_lock32(c
, fnum
, offset
, len
, -1, WRITE_LOCK
);
562 static bool rw_torture(struct cli_state
*c
)
564 const char *lockfname
= "\\torture.lck";
568 pid_t pid2
, pid
= getpid();
575 memset(buf
, '\0', sizeof(buf
));
577 status
= cli_open(c
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
,
579 if (!NT_STATUS_IS_OK(status
)) {
580 status
= cli_open(c
, lockfname
, O_RDWR
, DENY_NONE
, &fnum2
);
582 if (!NT_STATUS_IS_OK(status
)) {
583 printf("open of %s failed (%s)\n",
584 lockfname
, nt_errstr(status
));
588 for (i
=0;i
<torture_numops
;i
++) {
589 unsigned n
= (unsigned)sys_random()%10;
592 printf("%d\r", i
); fflush(stdout
);
594 slprintf(fname
, sizeof(fstring
) - 1, "\\torture.%u", n
);
596 if (!wait_lock(c
, fnum2
, n
*sizeof(int), sizeof(int))) {
600 status
= cli_open(c
, fname
, O_RDWR
| O_CREAT
| O_TRUNC
,
602 if (!NT_STATUS_IS_OK(status
)) {
603 printf("open failed (%s)\n", nt_errstr(status
));
608 status
= cli_writeall(c
, fnum
, 0, (uint8_t *)&pid
, 0,
610 if (!NT_STATUS_IS_OK(status
)) {
611 printf("write failed (%s)\n", nt_errstr(status
));
616 status
= cli_writeall(c
, fnum
, 0, (uint8_t *)buf
,
617 sizeof(pid
)+(j
*sizeof(buf
)),
619 if (!NT_STATUS_IS_OK(status
)) {
620 printf("write failed (%s)\n",
628 status
= cli_read(c
, fnum
, (char *)&pid2
, 0, sizeof(pid
),
630 if (!NT_STATUS_IS_OK(status
)) {
631 printf("read failed (%s)\n", nt_errstr(status
));
633 } else if (nread
!= sizeof(pid
)) {
634 printf("read/write compare failed: "
635 "recv %ld req %ld\n", (unsigned long)nread
,
636 (unsigned long)sizeof(pid
));
641 printf("data corruption!\n");
645 status
= cli_close(c
, fnum
);
646 if (!NT_STATUS_IS_OK(status
)) {
647 printf("close failed (%s)\n", nt_errstr(status
));
651 status
= cli_unlink(c
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
652 if (!NT_STATUS_IS_OK(status
)) {
653 printf("unlink failed (%s)\n", nt_errstr(status
));
657 status
= cli_unlock(c
, fnum2
, n
*sizeof(int), sizeof(int));
658 if (!NT_STATUS_IS_OK(status
)) {
659 printf("unlock failed (%s)\n", nt_errstr(status
));
665 cli_unlink(c
, lockfname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
672 static bool run_torture(int dummy
)
674 struct cli_state
*cli
;
679 cli_sockopt(cli
, sockops
);
681 ret
= rw_torture(cli
);
683 if (!torture_close_connection(cli
)) {
690 static bool rw_torture3(struct cli_state
*c
, char *lockfname
)
692 uint16_t fnum
= (uint16_t)-1;
697 unsigned countprev
= 0;
700 NTSTATUS status
= NT_STATUS_OK
;
703 for (i
= 0; i
< sizeof(buf
); i
+= sizeof(uint32
))
705 SIVAL(buf
, i
, sys_random());
712 FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
713 if (!NT_STATUS_IS_OK(status
)) {
714 printf("unlink failed (%s) (normal, this file should "
715 "not exist)\n", nt_errstr(status
));
718 status
= cli_open(c
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
,
720 if (!NT_STATUS_IS_OK(status
)) {
721 printf("first open read/write of %s failed (%s)\n",
722 lockfname
, nt_errstr(status
));
728 for (i
= 0; i
< 500 && fnum
== (uint16_t)-1; i
++)
730 status
= cli_open(c
, lockfname
, O_RDONLY
,
732 if (!NT_STATUS_IS_OK(status
)) {
737 if (!NT_STATUS_IS_OK(status
)) {
738 printf("second open read-only of %s failed (%s)\n",
739 lockfname
, nt_errstr(status
));
745 for (count
= 0; count
< sizeof(buf
); count
+= sent
)
747 if (count
>= countprev
) {
748 printf("%d %8d\r", i
, count
);
751 countprev
+= (sizeof(buf
) / 20);
756 sent
= ((unsigned)sys_random()%(20))+ 1;
757 if (sent
> sizeof(buf
) - count
)
759 sent
= sizeof(buf
) - count
;
762 status
= cli_writeall(c
, fnum
, 0, (uint8_t *)buf
+count
,
764 if (!NT_STATUS_IS_OK(status
)) {
765 printf("write failed (%s)\n",
772 status
= cli_read(c
, fnum
, buf_rd
+count
, count
,
773 sizeof(buf
)-count
, &sent
);
774 if(!NT_STATUS_IS_OK(status
)) {
775 printf("read failed offset:%d size:%ld (%s)\n",
776 count
, (unsigned long)sizeof(buf
)-count
,
780 } else if (sent
> 0) {
781 if (memcmp(buf_rd
+count
, buf
+count
, sent
) != 0)
783 printf("read/write compare failed\n");
784 printf("offset: %d req %ld recvd %ld\n", count
, (unsigned long)sizeof(buf
)-count
, (unsigned long)sent
);
793 status
= cli_close(c
, fnum
);
794 if (!NT_STATUS_IS_OK(status
)) {
795 printf("close failed (%s)\n", nt_errstr(status
));
802 static bool rw_torture2(struct cli_state
*c1
, struct cli_state
*c2
)
804 const char *lockfname
= "\\torture2.lck";
814 status
= cli_unlink(c1
, lockfname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
815 if (!NT_STATUS_IS_OK(status
)) {
816 printf("unlink failed (%s) (normal, this file should not exist)\n", nt_errstr(status
));
819 status
= cli_open(c1
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
,
821 if (!NT_STATUS_IS_OK(status
)) {
822 printf("first open read/write of %s failed (%s)\n",
823 lockfname
, nt_errstr(status
));
827 status
= cli_open(c2
, lockfname
, O_RDONLY
, DENY_NONE
, &fnum2
);
828 if (!NT_STATUS_IS_OK(status
)) {
829 printf("second open read-only of %s failed (%s)\n",
830 lockfname
, nt_errstr(status
));
831 cli_close(c1
, fnum1
);
835 for (i
= 0; i
< torture_numops
; i
++)
837 size_t buf_size
= ((unsigned)sys_random()%(sizeof(buf
)-1))+ 1;
839 printf("%d\r", i
); fflush(stdout
);
842 generate_random_buffer((unsigned char *)buf
, buf_size
);
844 status
= cli_writeall(c1
, fnum1
, 0, (uint8_t *)buf
, 0,
846 if (!NT_STATUS_IS_OK(status
)) {
847 printf("write failed (%s)\n", nt_errstr(status
));
852 status
= cli_read(c2
, fnum2
, buf_rd
, 0, buf_size
, &bytes_read
);
853 if(!NT_STATUS_IS_OK(status
)) {
854 printf("read failed (%s)\n", nt_errstr(status
));
857 } else if (bytes_read
!= buf_size
) {
858 printf("read failed\n");
859 printf("read %ld, expected %ld\n",
860 (unsigned long)bytes_read
,
861 (unsigned long)buf_size
);
866 if (memcmp(buf_rd
, buf
, buf_size
) != 0)
868 printf("read/write compare failed\n");
874 status
= cli_close(c2
, fnum2
);
875 if (!NT_STATUS_IS_OK(status
)) {
876 printf("close failed (%s)\n", nt_errstr(status
));
880 status
= cli_close(c1
, fnum1
);
881 if (!NT_STATUS_IS_OK(status
)) {
882 printf("close failed (%s)\n", nt_errstr(status
));
886 status
= cli_unlink(c1
, lockfname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
887 if (!NT_STATUS_IS_OK(status
)) {
888 printf("unlink failed (%s)\n", nt_errstr(status
));
895 static bool run_readwritetest(int dummy
)
897 struct cli_state
*cli1
, *cli2
;
898 bool test1
, test2
= False
;
900 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
903 cli_sockopt(cli1
, sockops
);
904 cli_sockopt(cli2
, sockops
);
906 printf("starting readwritetest\n");
908 test1
= rw_torture2(cli1
, cli2
);
909 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1
));
912 test2
= rw_torture2(cli1
, cli1
);
913 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2
));
916 if (!torture_close_connection(cli1
)) {
920 if (!torture_close_connection(cli2
)) {
924 return (test1
&& test2
);
927 static bool run_readwritemulti(int dummy
)
929 struct cli_state
*cli
;
934 cli_sockopt(cli
, sockops
);
936 printf("run_readwritemulti: fname %s\n", randomfname
);
937 test
= rw_torture3(cli
, randomfname
);
939 if (!torture_close_connection(cli
)) {
946 static bool run_readwritelarge_internal(int max_xmit_k
)
948 static struct cli_state
*cli1
;
950 const char *lockfname
= "\\large.dat";
956 if (!torture_open_connection(&cli1
, 0)) {
959 cli_sockopt(cli1
, sockops
);
960 memset(buf
,'\0',sizeof(buf
));
962 cli1
->max_xmit
= max_xmit_k
*1024;
964 if (signing_state
== Required
) {
965 /* Horrible cheat to force
966 multiple signed outstanding
967 packets against a Samba server.
969 cli1
->is_samba
= false;
972 printf("starting readwritelarge_internal\n");
974 cli_unlink(cli1
, lockfname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
976 status
= cli_open(cli1
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
,
978 if (!NT_STATUS_IS_OK(status
)) {
979 printf("open read/write of %s failed (%s)\n", lockfname
, nt_errstr(status
));
983 cli_writeall(cli1
, fnum1
, 0, (uint8_t *)buf
, 0, sizeof(buf
), NULL
);
985 status
= cli_qfileinfo_basic(cli1
, fnum1
, NULL
, &fsize
, NULL
, NULL
,
987 if (!NT_STATUS_IS_OK(status
)) {
988 printf("qfileinfo failed (%s)\n", nt_errstr(status
));
992 if (fsize
== sizeof(buf
))
993 printf("readwritelarge_internal test 1 succeeded (size = %lx)\n",
994 (unsigned long)fsize
);
996 printf("readwritelarge_internal test 1 failed (size = %lx)\n",
997 (unsigned long)fsize
);
1001 status
= cli_close(cli1
, fnum1
);
1002 if (!NT_STATUS_IS_OK(status
)) {
1003 printf("close failed (%s)\n", nt_errstr(status
));
1007 status
= cli_unlink(cli1
, lockfname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
1008 if (!NT_STATUS_IS_OK(status
)) {
1009 printf("unlink failed (%s)\n", nt_errstr(status
));
1013 status
= cli_open(cli1
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
,
1015 if (!NT_STATUS_IS_OK(status
)) {
1016 printf("open read/write of %s failed (%s)\n", lockfname
, nt_errstr(status
));
1020 cli1
->max_xmit
= 4*1024;
1022 cli_smbwrite(cli1
, fnum1
, buf
, 0, sizeof(buf
), NULL
);
1024 status
= cli_qfileinfo_basic(cli1
, fnum1
, NULL
, &fsize
, NULL
, NULL
,
1026 if (!NT_STATUS_IS_OK(status
)) {
1027 printf("qfileinfo failed (%s)\n", nt_errstr(status
));
1031 if (fsize
== sizeof(buf
))
1032 printf("readwritelarge_internal test 2 succeeded (size = %lx)\n",
1033 (unsigned long)fsize
);
1035 printf("readwritelarge_internal test 2 failed (size = %lx)\n",
1036 (unsigned long)fsize
);
1041 /* ToDo - set allocation. JRA */
1042 if(!cli_set_allocation_size(cli1
, fnum1
, 0)) {
1043 printf("set allocation size to zero failed (%s)\n", cli_errstr(&cli1
));
1046 if (!cli_qfileinfo_basic(cli1
, fnum1
, NULL
, &fsize
, NULL
, NULL
, NULL
,
1048 printf("qfileinfo failed (%s)\n", cli_errstr(cli1
));
1052 printf("readwritelarge test 3 (truncate test) succeeded (size = %x)\n", fsize
);
1055 status
= cli_close(cli1
, fnum1
);
1056 if (!NT_STATUS_IS_OK(status
)) {
1057 printf("close failed (%s)\n", nt_errstr(status
));
1061 if (!torture_close_connection(cli1
)) {
1067 static bool run_readwritelarge(int dummy
)
1069 return run_readwritelarge_internal(128);
1072 static bool run_readwritelarge_signtest(int dummy
)
1075 signing_state
= Required
;
1076 ret
= run_readwritelarge_internal(2);
1077 signing_state
= Undefined
;
1084 #define ival(s) strtol(s, NULL, 0)
1086 /* run a test that simulates an approximate netbench client load */
1087 static bool run_netbench(int client
)
1089 struct cli_state
*cli
;
1094 const char *params
[20];
1095 bool correct
= True
;
1101 cli_sockopt(cli
, sockops
);
1105 slprintf(cname
,sizeof(cname
)-1, "client%d", client
);
1107 f
= fopen(client_txt
, "r");
1114 while (fgets(line
, sizeof(line
)-1, f
)) {
1118 line
[strlen(line
)-1] = 0;
1120 /* printf("[%d] %s\n", line_count, line); */
1122 all_string_sub(line
,"client1", cname
, sizeof(line
));
1124 /* parse the command parameters */
1125 params
[0] = strtok_r(line
, " ", &saveptr
);
1127 while (params
[i
]) params
[++i
] = strtok_r(NULL
, " ", &saveptr
);
1131 if (i
< 2) continue;
1133 if (!strncmp(params
[0],"SMB", 3)) {
1134 printf("ERROR: You are using a dbench 1 load file\n");
1138 if (!strcmp(params
[0],"NTCreateX")) {
1139 nb_createx(params
[1], ival(params
[2]), ival(params
[3]),
1141 } else if (!strcmp(params
[0],"Close")) {
1142 nb_close(ival(params
[1]));
1143 } else if (!strcmp(params
[0],"Rename")) {
1144 nb_rename(params
[1], params
[2]);
1145 } else if (!strcmp(params
[0],"Unlink")) {
1146 nb_unlink(params
[1]);
1147 } else if (!strcmp(params
[0],"Deltree")) {
1148 nb_deltree(params
[1]);
1149 } else if (!strcmp(params
[0],"Rmdir")) {
1150 nb_rmdir(params
[1]);
1151 } else if (!strcmp(params
[0],"QUERY_PATH_INFORMATION")) {
1152 nb_qpathinfo(params
[1]);
1153 } else if (!strcmp(params
[0],"QUERY_FILE_INFORMATION")) {
1154 nb_qfileinfo(ival(params
[1]));
1155 } else if (!strcmp(params
[0],"QUERY_FS_INFORMATION")) {
1156 nb_qfsinfo(ival(params
[1]));
1157 } else if (!strcmp(params
[0],"FIND_FIRST")) {
1158 nb_findfirst(params
[1]);
1159 } else if (!strcmp(params
[0],"WriteX")) {
1160 nb_writex(ival(params
[1]),
1161 ival(params
[2]), ival(params
[3]), ival(params
[4]));
1162 } else if (!strcmp(params
[0],"ReadX")) {
1163 nb_readx(ival(params
[1]),
1164 ival(params
[2]), ival(params
[3]), ival(params
[4]));
1165 } else if (!strcmp(params
[0],"Flush")) {
1166 nb_flush(ival(params
[1]));
1168 printf("Unknown operation %s\n", params
[0]);
1176 if (!torture_close_connection(cli
)) {
1184 /* run a test that simulates an approximate netbench client load */
1185 static bool run_nbench(int dummy
)
1188 bool correct
= True
;
1194 signal(SIGALRM
, nb_alarm
);
1196 t
= create_procs(run_netbench
, &correct
);
1199 printf("\nThroughput %g MB/sec\n",
1200 1.0e-6 * nbio_total() / t
);
1206 This test checks for two things:
1208 1) correct support for retaining locks over a close (ie. the server
1209 must not use posix semantics)
1210 2) support for lock timeouts
1212 static bool run_locktest1(int dummy
)
1214 struct cli_state
*cli1
, *cli2
;
1215 const char *fname
= "\\lockt1.lck";
1216 uint16_t fnum1
, fnum2
, fnum3
;
1218 unsigned lock_timeout
;
1221 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
1224 cli_sockopt(cli1
, sockops
);
1225 cli_sockopt(cli2
, sockops
);
1227 printf("starting locktest1\n");
1229 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
1231 status
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
,
1233 if (!NT_STATUS_IS_OK(status
)) {
1234 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
1238 status
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum2
);
1239 if (!NT_STATUS_IS_OK(status
)) {
1240 printf("open2 of %s failed (%s)\n", fname
, nt_errstr(status
));
1244 status
= cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
, &fnum3
);
1245 if (!NT_STATUS_IS_OK(status
)) {
1246 printf("open3 of %s failed (%s)\n", fname
, nt_errstr(status
));
1250 status
= cli_lock32(cli1
, fnum1
, 0, 4, 0, WRITE_LOCK
);
1251 if (!NT_STATUS_IS_OK(status
)) {
1252 printf("lock1 failed (%s)\n", nt_errstr(status
));
1256 status
= cli_lock32(cli2
, fnum3
, 0, 4, 0, WRITE_LOCK
);
1257 if (NT_STATUS_IS_OK(status
)) {
1258 printf("lock2 succeeded! This is a locking bug\n");
1261 if (!check_both_error(__LINE__
, status
, ERRDOS
, ERRlock
,
1262 NT_STATUS_LOCK_NOT_GRANTED
)) {
1267 lock_timeout
= (1 + (random() % 20));
1268 printf("Testing lock timeout with timeout=%u\n", lock_timeout
);
1270 status
= cli_lock32(cli2
, fnum3
, 0, 4, lock_timeout
* 1000, WRITE_LOCK
);
1271 if (NT_STATUS_IS_OK(status
)) {
1272 printf("lock3 succeeded! This is a locking bug\n");
1275 if (!check_both_error(__LINE__
, status
, ERRDOS
, ERRlock
,
1276 NT_STATUS_FILE_LOCK_CONFLICT
)) {
1282 if (ABS(t2
- t1
) < lock_timeout
-1) {
1283 printf("error: This server appears not to support timed lock requests\n");
1286 printf("server slept for %u seconds for a %u second timeout\n",
1287 (unsigned int)(t2
-t1
), lock_timeout
);
1289 status
= cli_close(cli1
, fnum2
);
1290 if (!NT_STATUS_IS_OK(status
)) {
1291 printf("close1 failed (%s)\n", nt_errstr(status
));
1295 status
= cli_lock32(cli2
, fnum3
, 0, 4, 0, WRITE_LOCK
);
1296 if (NT_STATUS_IS_OK(status
)) {
1297 printf("lock4 succeeded! This is a locking bug\n");
1300 if (!check_both_error(__LINE__
, status
, ERRDOS
, ERRlock
,
1301 NT_STATUS_FILE_LOCK_CONFLICT
)) {
1306 status
= cli_close(cli1
, fnum1
);
1307 if (!NT_STATUS_IS_OK(status
)) {
1308 printf("close2 failed (%s)\n", nt_errstr(status
));
1312 status
= cli_close(cli2
, fnum3
);
1313 if (!NT_STATUS_IS_OK(status
)) {
1314 printf("close3 failed (%s)\n", nt_errstr(status
));
1318 status
= cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
1319 if (!NT_STATUS_IS_OK(status
)) {
1320 printf("unlink failed (%s)\n", nt_errstr(status
));
1325 if (!torture_close_connection(cli1
)) {
1329 if (!torture_close_connection(cli2
)) {
1333 printf("Passed locktest1\n");
1338 this checks to see if a secondary tconx can use open files from an
1341 static bool run_tcon_test(int dummy
)
1343 static struct cli_state
*cli
;
1344 const char *fname
= "\\tcontest.tmp";
1346 uint16 cnum1
, cnum2
, cnum3
;
1347 uint16 vuid1
, vuid2
;
1352 memset(buf
, '\0', sizeof(buf
));
1354 if (!torture_open_connection(&cli
, 0)) {
1357 cli_sockopt(cli
, sockops
);
1359 printf("starting tcontest\n");
1361 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
1363 status
= cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
);
1364 if (!NT_STATUS_IS_OK(status
)) {
1365 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
1369 cnum1
= cli_state_get_tid(cli
);
1372 status
= cli_writeall(cli
, fnum1
, 0, (uint8_t *)buf
, 130, 4, NULL
);
1373 if (!NT_STATUS_IS_OK(status
)) {
1374 printf("initial write failed (%s)", nt_errstr(status
));
1378 status
= cli_tcon_andx(cli
, share
, "?????",
1379 password
, strlen(password
)+1);
1380 if (!NT_STATUS_IS_OK(status
)) {
1381 printf("%s refused 2nd tree connect (%s)\n", host
,
1387 cnum2
= cli_state_get_tid(cli
);
1388 cnum3
= MAX(cnum1
, cnum2
) + 1; /* any invalid number */
1389 vuid2
= cli
->vuid
+ 1;
1391 /* try a write with the wrong tid */
1392 cli_state_set_tid(cli
, cnum2
);
1394 status
= cli_writeall(cli
, fnum1
, 0, (uint8_t *)buf
, 130, 4, NULL
);
1395 if (NT_STATUS_IS_OK(status
)) {
1396 printf("* server allows write with wrong TID\n");
1399 printf("server fails write with wrong TID : %s\n",
1404 /* try a write with an invalid tid */
1405 cli_state_set_tid(cli
, cnum3
);
1407 status
= cli_writeall(cli
, fnum1
, 0, (uint8_t *)buf
, 130, 4, NULL
);
1408 if (NT_STATUS_IS_OK(status
)) {
1409 printf("* server allows write with invalid TID\n");
1412 printf("server fails write with invalid TID : %s\n",
1416 /* try a write with an invalid vuid */
1418 cli_state_set_tid(cli
, cnum1
);
1420 status
= cli_writeall(cli
, fnum1
, 0, (uint8_t *)buf
, 130, 4, NULL
);
1421 if (NT_STATUS_IS_OK(status
)) {
1422 printf("* server allows write with invalid VUID\n");
1425 printf("server fails write with invalid VUID : %s\n",
1429 cli_state_set_tid(cli
, cnum1
);
1432 status
= cli_close(cli
, fnum1
);
1433 if (!NT_STATUS_IS_OK(status
)) {
1434 printf("close failed (%s)\n", nt_errstr(status
));
1438 cli_state_set_tid(cli
, cnum2
);
1440 status
= cli_tdis(cli
);
1441 if (!NT_STATUS_IS_OK(status
)) {
1442 printf("secondary tdis failed (%s)\n", nt_errstr(status
));
1446 cli_state_set_tid(cli
, cnum1
);
1448 if (!torture_close_connection(cli
)) {
1457 checks for old style tcon support
1459 static bool run_tcon2_test(int dummy
)
1461 static struct cli_state
*cli
;
1462 uint16 cnum
, max_xmit
;
1466 if (!torture_open_connection(&cli
, 0)) {
1469 cli_sockopt(cli
, sockops
);
1471 printf("starting tcon2 test\n");
1473 if (asprintf(&service
, "\\\\%s\\%s", host
, share
) == -1) {
1477 status
= cli_raw_tcon(cli
, service
, password
, "?????", &max_xmit
, &cnum
);
1481 if (!NT_STATUS_IS_OK(status
)) {
1482 printf("tcon2 failed : %s\n", nt_errstr(status
));
1484 printf("tcon OK : max_xmit=%d cnum=%d\n",
1485 (int)max_xmit
, (int)cnum
);
1488 if (!torture_close_connection(cli
)) {
1492 printf("Passed tcon2 test\n");
1496 static bool tcon_devtest(struct cli_state
*cli
,
1497 const char *myshare
, const char *devtype
,
1498 const char *return_devtype
,
1499 NTSTATUS expected_error
)
1504 status
= cli_tcon_andx(cli
, myshare
, devtype
,
1505 password
, strlen(password
)+1);
1507 if (NT_STATUS_IS_OK(expected_error
)) {
1508 if (NT_STATUS_IS_OK(status
)) {
1509 if (strcmp(cli
->dev
, return_devtype
) == 0) {
1512 printf("tconX to share %s with type %s "
1513 "succeeded but returned the wrong "
1514 "device type (got [%s] but should have got [%s])\n",
1515 myshare
, devtype
, cli
->dev
, return_devtype
);
1519 printf("tconX to share %s with type %s "
1520 "should have succeeded but failed\n",
1526 if (NT_STATUS_IS_OK(status
)) {
1527 printf("tconx to share %s with type %s "
1528 "should have failed but succeeded\n",
1532 if (NT_STATUS_EQUAL(cli_nt_error(cli
),
1536 printf("Returned unexpected error\n");
1545 checks for correct tconX support
1547 static bool run_tcon_devtype_test(int dummy
)
1549 static struct cli_state
*cli1
= NULL
;
1554 status
= cli_full_connection(&cli1
, myname
,
1555 host
, NULL
, port_to_use
,
1557 username
, workgroup
,
1558 password
, flags
, signing_state
);
1560 if (!NT_STATUS_IS_OK(status
)) {
1561 printf("could not open connection\n");
1565 if (!tcon_devtest(cli1
, "IPC$", "A:", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1568 if (!tcon_devtest(cli1
, "IPC$", "?????", "IPC", NT_STATUS_OK
))
1571 if (!tcon_devtest(cli1
, "IPC$", "LPT:", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1574 if (!tcon_devtest(cli1
, "IPC$", "IPC", "IPC", NT_STATUS_OK
))
1577 if (!tcon_devtest(cli1
, "IPC$", "FOOBA", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1580 if (!tcon_devtest(cli1
, share
, "A:", "A:", NT_STATUS_OK
))
1583 if (!tcon_devtest(cli1
, share
, "?????", "A:", NT_STATUS_OK
))
1586 if (!tcon_devtest(cli1
, share
, "LPT:", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1589 if (!tcon_devtest(cli1
, share
, "IPC", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1592 if (!tcon_devtest(cli1
, share
, "FOOBA", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1598 printf("Passed tcondevtest\n");
1605 This test checks that
1607 1) the server supports multiple locking contexts on the one SMB
1608 connection, distinguished by PID.
1610 2) the server correctly fails overlapping locks made by the same PID (this
1611 goes against POSIX behaviour, which is why it is tricky to implement)
1613 3) the server denies unlock requests by an incorrect client PID
1615 static bool run_locktest2(int dummy
)
1617 static struct cli_state
*cli
;
1618 const char *fname
= "\\lockt2.lck";
1619 uint16_t fnum1
, fnum2
, fnum3
;
1620 bool correct
= True
;
1623 if (!torture_open_connection(&cli
, 0)) {
1627 cli_sockopt(cli
, sockops
);
1629 printf("starting locktest2\n");
1631 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
1635 status
= cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
);
1636 if (!NT_STATUS_IS_OK(status
)) {
1637 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
1641 status
= cli_open(cli
, fname
, O_RDWR
, DENY_NONE
, &fnum2
);
1642 if (!NT_STATUS_IS_OK(status
)) {
1643 printf("open2 of %s failed (%s)\n", fname
, nt_errstr(status
));
1649 status
= cli_open(cli
, fname
, O_RDWR
, DENY_NONE
, &fnum3
);
1650 if (!NT_STATUS_IS_OK(status
)) {
1651 printf("open3 of %s failed (%s)\n", fname
, nt_errstr(status
));
1657 status
= cli_lock32(cli
, fnum1
, 0, 4, 0, WRITE_LOCK
);
1658 if (!NT_STATUS_IS_OK(status
)) {
1659 printf("lock1 failed (%s)\n", nt_errstr(status
));
1663 status
= cli_lock32(cli
, fnum1
, 0, 4, 0, WRITE_LOCK
);
1664 if (NT_STATUS_IS_OK(status
)) {
1665 printf("WRITE lock1 succeeded! This is a locking bug\n");
1668 if (!check_both_error(__LINE__
, status
, ERRDOS
, ERRlock
,
1669 NT_STATUS_LOCK_NOT_GRANTED
)) {
1674 status
= cli_lock32(cli
, fnum2
, 0, 4, 0, WRITE_LOCK
);
1675 if (NT_STATUS_IS_OK(status
)) {
1676 printf("WRITE lock2 succeeded! This is a locking bug\n");
1679 if (!check_both_error(__LINE__
, status
, ERRDOS
, ERRlock
,
1680 NT_STATUS_LOCK_NOT_GRANTED
)) {
1685 status
= cli_lock32(cli
, fnum2
, 0, 4, 0, READ_LOCK
);
1686 if (NT_STATUS_IS_OK(status
)) {
1687 printf("READ lock2 succeeded! This is a locking bug\n");
1690 if (!check_both_error(__LINE__
, status
, ERRDOS
, ERRlock
,
1691 NT_STATUS_FILE_LOCK_CONFLICT
)) {
1696 status
= cli_lock32(cli
, fnum1
, 100, 4, 0, WRITE_LOCK
);
1697 if (!NT_STATUS_IS_OK(status
)) {
1698 printf("lock at 100 failed (%s)\n", nt_errstr(status
));
1701 if (NT_STATUS_IS_OK(cli_unlock(cli
, fnum1
, 100, 4))) {
1702 printf("unlock at 100 succeeded! This is a locking bug\n");
1706 status
= cli_unlock(cli
, fnum1
, 0, 4);
1707 if (NT_STATUS_IS_OK(status
)) {
1708 printf("unlock1 succeeded! This is a locking bug\n");
1711 if (!check_both_error(__LINE__
, status
, ERRDOS
, ERRlock
,
1712 NT_STATUS_RANGE_NOT_LOCKED
)) {
1717 status
= cli_unlock(cli
, fnum1
, 0, 8);
1718 if (NT_STATUS_IS_OK(status
)) {
1719 printf("unlock2 succeeded! This is a locking bug\n");
1722 if (!check_both_error(__LINE__
, status
, ERRDOS
, ERRlock
,
1723 NT_STATUS_RANGE_NOT_LOCKED
)) {
1728 status
= cli_lock32(cli
, fnum3
, 0, 4, 0, WRITE_LOCK
);
1729 if (NT_STATUS_IS_OK(status
)) {
1730 printf("lock3 succeeded! This is a locking bug\n");
1733 if (!check_both_error(__LINE__
, status
, ERRDOS
, ERRlock
,
1734 NT_STATUS_LOCK_NOT_GRANTED
)) {
1741 status
= cli_close(cli
, fnum1
);
1742 if (!NT_STATUS_IS_OK(status
)) {
1743 printf("close1 failed (%s)\n", nt_errstr(status
));
1747 status
= cli_close(cli
, fnum2
);
1748 if (!NT_STATUS_IS_OK(status
)) {
1749 printf("close2 failed (%s)\n", nt_errstr(status
));
1753 status
= cli_close(cli
, fnum3
);
1754 if (!NT_STATUS_IS_OK(status
)) {
1755 printf("close3 failed (%s)\n", nt_errstr(status
));
1759 if (!torture_close_connection(cli
)) {
1763 printf("locktest2 finished\n");
1770 This test checks that
1772 1) the server supports the full offset range in lock requests
1774 static bool run_locktest3(int dummy
)
1776 static struct cli_state
*cli1
, *cli2
;
1777 const char *fname
= "\\lockt3.lck";
1778 uint16_t fnum1
, fnum2
;
1781 bool correct
= True
;
1784 #define NEXT_OFFSET offset += (~(uint32)0) / torture_numops
1786 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
1789 cli_sockopt(cli1
, sockops
);
1790 cli_sockopt(cli2
, sockops
);
1792 printf("starting locktest3\n");
1794 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
1796 status
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
,
1798 if (!NT_STATUS_IS_OK(status
)) {
1799 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
1803 status
= cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
, &fnum2
);
1804 if (!NT_STATUS_IS_OK(status
)) {
1805 printf("open2 of %s failed (%s)\n", fname
, nt_errstr(status
));
1809 for (offset
=i
=0;i
<torture_numops
;i
++) {
1812 status
= cli_lock32(cli1
, fnum1
, offset
-1, 1, 0, WRITE_LOCK
);
1813 if (!NT_STATUS_IS_OK(status
)) {
1814 printf("lock1 %d failed (%s)\n",
1820 status
= cli_lock32(cli2
, fnum2
, offset
-2, 1, 0, WRITE_LOCK
);
1821 if (!NT_STATUS_IS_OK(status
)) {
1822 printf("lock2 %d failed (%s)\n",
1829 for (offset
=i
=0;i
<torture_numops
;i
++) {
1832 status
= cli_lock32(cli1
, fnum1
, offset
-2, 1, 0, WRITE_LOCK
);
1833 if (NT_STATUS_IS_OK(status
)) {
1834 printf("error: lock1 %d succeeded!\n", i
);
1838 status
= cli_lock32(cli2
, fnum2
, offset
-1, 1, 0, WRITE_LOCK
);
1839 if (NT_STATUS_IS_OK(status
)) {
1840 printf("error: lock2 %d succeeded!\n", i
);
1844 status
= cli_lock32(cli1
, fnum1
, offset
-1, 1, 0, WRITE_LOCK
);
1845 if (NT_STATUS_IS_OK(status
)) {
1846 printf("error: lock3 %d succeeded!\n", i
);
1850 status
= cli_lock32(cli2
, fnum2
, offset
-2, 1, 0, WRITE_LOCK
);
1851 if (NT_STATUS_IS_OK(status
)) {
1852 printf("error: lock4 %d succeeded!\n", i
);
1857 for (offset
=i
=0;i
<torture_numops
;i
++) {
1860 status
= cli_unlock(cli1
, fnum1
, offset
-1, 1);
1861 if (!NT_STATUS_IS_OK(status
)) {
1862 printf("unlock1 %d failed (%s)\n",
1868 status
= cli_unlock(cli2
, fnum2
, offset
-2, 1);
1869 if (!NT_STATUS_IS_OK(status
)) {
1870 printf("unlock2 %d failed (%s)\n",
1877 status
= cli_close(cli1
, fnum1
);
1878 if (!NT_STATUS_IS_OK(status
)) {
1879 printf("close1 failed (%s)\n", nt_errstr(status
));
1883 status
= cli_close(cli2
, fnum2
);
1884 if (!NT_STATUS_IS_OK(status
)) {
1885 printf("close2 failed (%s)\n", nt_errstr(status
));
1889 status
= cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
1890 if (!NT_STATUS_IS_OK(status
)) {
1891 printf("unlink failed (%s)\n", nt_errstr(status
));
1895 if (!torture_close_connection(cli1
)) {
1899 if (!torture_close_connection(cli2
)) {
1903 printf("finished locktest3\n");
1908 #define EXPECTED(ret, v) if ((ret) != (v)) { \
1909 printf("** "); correct = False; \
1913 looks at overlapping locks
1915 static bool run_locktest4(int dummy
)
1917 static struct cli_state
*cli1
, *cli2
;
1918 const char *fname
= "\\lockt4.lck";
1919 uint16_t fnum1
, fnum2
, f
;
1922 bool correct
= True
;
1925 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
1929 cli_sockopt(cli1
, sockops
);
1930 cli_sockopt(cli2
, sockops
);
1932 printf("starting locktest4\n");
1934 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
1936 cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
);
1937 cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
, &fnum2
);
1939 memset(buf
, 0, sizeof(buf
));
1941 status
= cli_writeall(cli1
, fnum1
, 0, (uint8_t *)buf
, 0, sizeof(buf
),
1943 if (!NT_STATUS_IS_OK(status
)) {
1944 printf("Failed to create file: %s\n", nt_errstr(status
));
1949 ret
= NT_STATUS_IS_OK(cli_lock32(cli1
, fnum1
, 0, 4, 0, WRITE_LOCK
)) &&
1950 NT_STATUS_IS_OK(cli_lock32(cli1
, fnum1
, 2, 4, 0, WRITE_LOCK
));
1951 EXPECTED(ret
, False
);
1952 printf("the same process %s set overlapping write locks\n", ret
?"can":"cannot");
1954 ret
= NT_STATUS_IS_OK(cli_lock32(cli1
, fnum1
, 10, 4, 0, READ_LOCK
)) &&
1955 NT_STATUS_IS_OK(cli_lock32(cli1
, fnum1
, 12, 4, 0, READ_LOCK
));
1956 EXPECTED(ret
, True
);
1957 printf("the same process %s set overlapping read locks\n", ret
?"can":"cannot");
1959 ret
= NT_STATUS_IS_OK(cli_lock32(cli1
, fnum1
, 20, 4, 0, WRITE_LOCK
)) &&
1960 NT_STATUS_IS_OK(cli_lock32(cli2
, fnum2
, 22, 4, 0, WRITE_LOCK
));
1961 EXPECTED(ret
, False
);
1962 printf("a different connection %s set overlapping write locks\n", ret
?"can":"cannot");
1964 ret
= NT_STATUS_IS_OK(cli_lock32(cli1
, fnum1
, 30, 4, 0, READ_LOCK
)) &&
1965 NT_STATUS_IS_OK(cli_lock32(cli2
, fnum2
, 32, 4, 0, READ_LOCK
));
1966 EXPECTED(ret
, True
);
1967 printf("a different connection %s set overlapping read locks\n", ret
?"can":"cannot");
1969 ret
= (cli_setpid(cli1
, 1),
1970 NT_STATUS_IS_OK(cli_lock32(cli1
, fnum1
, 40, 4, 0, WRITE_LOCK
))) &&
1971 (cli_setpid(cli1
, 2),
1972 NT_STATUS_IS_OK(cli_lock32(cli1
, fnum1
, 42, 4, 0, WRITE_LOCK
)));
1973 EXPECTED(ret
, False
);
1974 printf("a different pid %s set overlapping write locks\n", ret
?"can":"cannot");
1976 ret
= (cli_setpid(cli1
, 1),
1977 NT_STATUS_IS_OK(cli_lock32(cli1
, fnum1
, 50, 4, 0, READ_LOCK
))) &&
1978 (cli_setpid(cli1
, 2),
1979 NT_STATUS_IS_OK(cli_lock32(cli1
, fnum1
, 52, 4, 0, READ_LOCK
)));
1980 EXPECTED(ret
, True
);
1981 printf("a different pid %s set overlapping read locks\n", ret
?"can":"cannot");
1983 ret
= NT_STATUS_IS_OK(cli_lock32(cli1
, fnum1
, 60, 4, 0, READ_LOCK
)) &&
1984 NT_STATUS_IS_OK(cli_lock32(cli1
, fnum1
, 60, 4, 0, READ_LOCK
));
1985 EXPECTED(ret
, True
);
1986 printf("the same process %s set the same read lock twice\n", ret
?"can":"cannot");
1988 ret
= NT_STATUS_IS_OK(cli_lock32(cli1
, fnum1
, 70, 4, 0, WRITE_LOCK
)) &&
1989 NT_STATUS_IS_OK(cli_lock32(cli1
, fnum1
, 70, 4, 0, WRITE_LOCK
));
1990 EXPECTED(ret
, False
);
1991 printf("the same process %s set the same write lock twice\n", ret
?"can":"cannot");
1993 ret
= NT_STATUS_IS_OK(cli_lock32(cli1
, fnum1
, 80, 4, 0, READ_LOCK
)) &&
1994 NT_STATUS_IS_OK(cli_lock32(cli1
, fnum1
, 80, 4, 0, WRITE_LOCK
));
1995 EXPECTED(ret
, False
);
1996 printf("the same process %s overlay a read lock with a write lock\n", ret
?"can":"cannot");
1998 ret
= NT_STATUS_IS_OK(cli_lock32(cli1
, fnum1
, 90, 4, 0, WRITE_LOCK
)) &&
1999 NT_STATUS_IS_OK(cli_lock32(cli1
, fnum1
, 90, 4, 0, READ_LOCK
));
2000 EXPECTED(ret
, True
);
2001 printf("the same process %s overlay a write lock with a read lock\n", ret
?"can":"cannot");
2003 ret
= (cli_setpid(cli1
, 1),
2004 NT_STATUS_IS_OK(cli_lock32(cli1
, fnum1
, 100, 4, 0, WRITE_LOCK
))) &&
2005 (cli_setpid(cli1
, 2),
2006 NT_STATUS_IS_OK(cli_lock32(cli1
, fnum1
, 100, 4, 0, READ_LOCK
)));
2007 EXPECTED(ret
, False
);
2008 printf("a different pid %s overlay a write lock with a read lock\n", ret
?"can":"cannot");
2010 ret
= NT_STATUS_IS_OK(cli_lock32(cli1
, fnum1
, 110, 4, 0, READ_LOCK
)) &&
2011 NT_STATUS_IS_OK(cli_lock32(cli1
, fnum1
, 112, 4, 0, READ_LOCK
)) &&
2012 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 110, 6));
2013 EXPECTED(ret
, False
);
2014 printf("the same process %s coalesce read locks\n", ret
?"can":"cannot");
2017 ret
= NT_STATUS_IS_OK(cli_lock32(cli1
, fnum1
, 120, 4, 0, WRITE_LOCK
)) &&
2018 (cli_read_old(cli2
, fnum2
, buf
, 120, 4) == 4);
2019 EXPECTED(ret
, False
);
2020 printf("this server %s strict write locking\n", ret
?"doesn't do":"does");
2022 status
= cli_lock32(cli1
, fnum1
, 130, 4, 0, READ_LOCK
);
2023 ret
= NT_STATUS_IS_OK(status
);
2025 status
= cli_writeall(cli2
, fnum2
, 0, (uint8_t *)buf
, 130, 4,
2027 ret
= NT_STATUS_IS_OK(status
);
2029 EXPECTED(ret
, False
);
2030 printf("this server %s strict read locking\n", ret
?"doesn't do":"does");
2033 ret
= NT_STATUS_IS_OK(cli_lock32(cli1
, fnum1
, 140, 4, 0, READ_LOCK
)) &&
2034 NT_STATUS_IS_OK(cli_lock32(cli1
, fnum1
, 140, 4, 0, READ_LOCK
)) &&
2035 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 140, 4)) &&
2036 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 140, 4));
2037 EXPECTED(ret
, True
);
2038 printf("this server %s do recursive read locking\n", ret
?"does":"doesn't");
2041 ret
= NT_STATUS_IS_OK(cli_lock32(cli1
, fnum1
, 150, 4, 0, WRITE_LOCK
)) &&
2042 NT_STATUS_IS_OK(cli_lock32(cli1
, fnum1
, 150, 4, 0, READ_LOCK
)) &&
2043 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 150, 4)) &&
2044 (cli_read_old(cli2
, fnum2
, buf
, 150, 4) == 4) &&
2045 !(NT_STATUS_IS_OK(cli_writeall(cli2
, fnum2
, 0, (uint8_t *)buf
,
2047 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 150, 4));
2048 EXPECTED(ret
, True
);
2049 printf("this server %s do recursive lock overlays\n", ret
?"does":"doesn't");
2051 ret
= NT_STATUS_IS_OK(cli_lock32(cli1
, fnum1
, 160, 4, 0, READ_LOCK
)) &&
2052 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 160, 4)) &&
2053 NT_STATUS_IS_OK(cli_writeall(cli2
, fnum2
, 0, (uint8_t *)buf
,
2055 (cli_read_old(cli2
, fnum2
, buf
, 160, 4) == 4);
2056 EXPECTED(ret
, True
);
2057 printf("the same process %s remove a read lock using write locking\n", ret
?"can":"cannot");
2059 ret
= NT_STATUS_IS_OK(cli_lock32(cli1
, fnum1
, 170, 4, 0, WRITE_LOCK
)) &&
2060 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 170, 4)) &&
2061 NT_STATUS_IS_OK(cli_writeall(cli2
, fnum2
, 0, (uint8_t *)buf
,
2063 (cli_read_old(cli2
, fnum2
, buf
, 170, 4) == 4);
2064 EXPECTED(ret
, True
);
2065 printf("the same process %s remove a write lock using read locking\n", ret
?"can":"cannot");
2067 ret
= NT_STATUS_IS_OK(cli_lock32(cli1
, fnum1
, 190, 4, 0, WRITE_LOCK
)) &&
2068 NT_STATUS_IS_OK(cli_lock32(cli1
, fnum1
, 190, 4, 0, READ_LOCK
)) &&
2069 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 190, 4)) &&
2070 !NT_STATUS_IS_OK(cli_writeall(cli2
, fnum2
, 0, (uint8_t *)buf
,
2072 (cli_read_old(cli2
, fnum2
, buf
, 190, 4) == 4);
2073 EXPECTED(ret
, True
);
2074 printf("the same process %s remove the first lock first\n", ret
?"does":"doesn't");
2076 cli_close(cli1
, fnum1
);
2077 cli_close(cli2
, fnum2
);
2078 cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
);
2079 cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &f
);
2080 ret
= NT_STATUS_IS_OK(cli_lock32(cli1
, fnum1
, 0, 8, 0, READ_LOCK
)) &&
2081 NT_STATUS_IS_OK(cli_lock32(cli1
, f
, 0, 1, 0, READ_LOCK
)) &&
2082 NT_STATUS_IS_OK(cli_close(cli1
, fnum1
)) &&
2083 NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
)) &&
2084 NT_STATUS_IS_OK(cli_lock32(cli1
, fnum1
, 7, 1, 0, WRITE_LOCK
));
2086 cli_close(cli1
, fnum1
);
2087 EXPECTED(ret
, True
);
2088 printf("the server %s have the NT byte range lock bug\n", !ret
?"does":"doesn't");
2091 cli_close(cli1
, fnum1
);
2092 cli_close(cli2
, fnum2
);
2093 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2094 torture_close_connection(cli1
);
2095 torture_close_connection(cli2
);
2097 printf("finished locktest4\n");
2102 looks at lock upgrade/downgrade.
2104 static bool run_locktest5(int dummy
)
2106 static struct cli_state
*cli1
, *cli2
;
2107 const char *fname
= "\\lockt5.lck";
2108 uint16_t fnum1
, fnum2
, fnum3
;
2111 bool correct
= True
;
2114 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
2118 cli_sockopt(cli1
, sockops
);
2119 cli_sockopt(cli2
, sockops
);
2121 printf("starting locktest5\n");
2123 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2125 cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
);
2126 cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
, &fnum2
);
2127 cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum3
);
2129 memset(buf
, 0, sizeof(buf
));
2131 status
= cli_writeall(cli1
, fnum1
, 0, (uint8_t *)buf
, 0, sizeof(buf
),
2133 if (!NT_STATUS_IS_OK(status
)) {
2134 printf("Failed to create file: %s\n", nt_errstr(status
));
2139 /* Check for NT bug... */
2140 ret
= NT_STATUS_IS_OK(cli_lock32(cli1
, fnum1
, 0, 8, 0, READ_LOCK
)) &&
2141 NT_STATUS_IS_OK(cli_lock32(cli1
, fnum3
, 0, 1, 0, READ_LOCK
));
2142 cli_close(cli1
, fnum1
);
2143 cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
);
2144 status
= cli_lock32(cli1
, fnum1
, 7, 1, 0, WRITE_LOCK
);
2145 ret
= NT_STATUS_IS_OK(status
);
2146 EXPECTED(ret
, True
);
2147 printf("this server %s the NT locking bug\n", ret
? "doesn't have" : "has");
2148 cli_close(cli1
, fnum1
);
2149 cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
);
2150 cli_unlock(cli1
, fnum3
, 0, 1);
2152 ret
= NT_STATUS_IS_OK(cli_lock32(cli1
, fnum1
, 0, 4, 0, WRITE_LOCK
)) &&
2153 NT_STATUS_IS_OK(cli_lock32(cli1
, fnum1
, 1, 1, 0, READ_LOCK
));
2154 EXPECTED(ret
, True
);
2155 printf("the same process %s overlay a write with a read lock\n", ret
?"can":"cannot");
2157 status
= cli_lock32(cli2
, fnum2
, 0, 4, 0, READ_LOCK
);
2158 ret
= NT_STATUS_IS_OK(status
);
2159 EXPECTED(ret
, False
);
2161 printf("a different processs %s get a read lock on the first process lock stack\n", ret
?"can":"cannot");
2163 /* Unlock the process 2 lock. */
2164 cli_unlock(cli2
, fnum2
, 0, 4);
2166 status
= cli_lock32(cli1
, fnum3
, 0, 4, 0, READ_LOCK
);
2167 ret
= NT_STATUS_IS_OK(status
);
2168 EXPECTED(ret
, False
);
2170 printf("the same processs on a different fnum %s get a read lock\n", ret
?"can":"cannot");
2172 /* Unlock the process 1 fnum3 lock. */
2173 cli_unlock(cli1
, fnum3
, 0, 4);
2175 /* Stack 2 more locks here. */
2176 ret
= NT_STATUS_IS_OK(cli_lock32(cli1
, fnum1
, 0, 4, 0, READ_LOCK
)) &&
2177 NT_STATUS_IS_OK(cli_lock32(cli1
, fnum1
, 0, 4, 0, READ_LOCK
));
2179 EXPECTED(ret
, True
);
2180 printf("the same process %s stack read locks\n", ret
?"can":"cannot");
2182 /* Unlock the first process lock, then check this was the WRITE lock that was
2185 ret
= NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 0, 4)) &&
2186 NT_STATUS_IS_OK(cli_lock32(cli2
, fnum2
, 0, 4, 0, READ_LOCK
));
2188 EXPECTED(ret
, True
);
2189 printf("the first unlock removes the %s lock\n", ret
?"WRITE":"READ");
2191 /* Unlock the process 2 lock. */
2192 cli_unlock(cli2
, fnum2
, 0, 4);
2194 /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */
2196 ret
= NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 1, 1)) &&
2197 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 0, 4)) &&
2198 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 0, 4));
2200 EXPECTED(ret
, True
);
2201 printf("the same process %s unlock the stack of 4 locks\n", ret
?"can":"cannot");
2203 /* Ensure the next unlock fails. */
2204 ret
= NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 0, 4));
2205 EXPECTED(ret
, False
);
2206 printf("the same process %s count the lock stack\n", !ret
?"can":"cannot");
2208 /* Ensure connection 2 can get a write lock. */
2209 status
= cli_lock32(cli2
, fnum2
, 0, 4, 0, WRITE_LOCK
);
2210 ret
= NT_STATUS_IS_OK(status
);
2211 EXPECTED(ret
, True
);
2213 printf("a different processs %s get a write lock on the unlocked stack\n", ret
?"can":"cannot");
2217 cli_close(cli1
, fnum1
);
2218 cli_close(cli2
, fnum2
);
2219 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2220 if (!torture_close_connection(cli1
)) {
2223 if (!torture_close_connection(cli2
)) {
2227 printf("finished locktest5\n");
2233 tries the unusual lockingX locktype bits
2235 static bool run_locktest6(int dummy
)
2237 static struct cli_state
*cli
;
2238 const char *fname
[1] = { "\\lock6.txt" };
2243 if (!torture_open_connection(&cli
, 0)) {
2247 cli_sockopt(cli
, sockops
);
2249 printf("starting locktest6\n");
2252 printf("Testing %s\n", fname
[i
]);
2254 cli_unlink(cli
, fname
[i
], FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2256 cli_open(cli
, fname
[i
], O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum
);
2257 status
= cli_locktype(cli
, fnum
, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE
);
2258 cli_close(cli
, fnum
);
2259 printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status
));
2261 cli_open(cli
, fname
[i
], O_RDWR
, DENY_NONE
, &fnum
);
2262 status
= cli_locktype(cli
, fnum
, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK
);
2263 cli_close(cli
, fnum
);
2264 printf("CANCEL_LOCK gave %s\n", nt_errstr(status
));
2266 cli_unlink(cli
, fname
[i
], FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2269 torture_close_connection(cli
);
2271 printf("finished locktest6\n");
2275 static bool run_locktest7(int dummy
)
2277 struct cli_state
*cli1
;
2278 const char *fname
= "\\lockt7.lck";
2281 bool correct
= False
;
2284 if (!torture_open_connection(&cli1
, 0)) {
2288 cli_sockopt(cli1
, sockops
);
2290 printf("starting locktest7\n");
2292 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2294 cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
);
2296 memset(buf
, 0, sizeof(buf
));
2298 status
= cli_writeall(cli1
, fnum1
, 0, (uint8_t *)buf
, 0, sizeof(buf
),
2300 if (!NT_STATUS_IS_OK(status
)) {
2301 printf("Failed to create file: %s\n", nt_errstr(status
));
2305 cli_setpid(cli1
, 1);
2307 status
= cli_lock32(cli1
, fnum1
, 130, 4, 0, READ_LOCK
);
2308 if (!NT_STATUS_IS_OK(status
)) {
2309 printf("Unable to apply read lock on range 130:4, error was %s\n", nt_errstr(status
));
2312 printf("pid1 successfully locked range 130:4 for READ\n");
2315 if (cli_read_old(cli1
, fnum1
, buf
, 130, 4) != 4) {
2316 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1
));
2319 printf("pid1 successfully read the range 130:4\n");
2322 status
= cli_writeall(cli1
, fnum1
, 0, (uint8_t *)buf
, 130, 4, NULL
);
2323 if (!NT_STATUS_IS_OK(status
)) {
2324 printf("pid1 unable to write to the range 130:4, error was "
2325 "%s\n", nt_errstr(status
));
2326 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_LOCK_CONFLICT
)) {
2327 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2331 printf("pid1 successfully wrote to the range 130:4 (should be denied)\n");
2335 cli_setpid(cli1
, 2);
2337 if (cli_read_old(cli1
, fnum1
, buf
, 130, 4) != 4) {
2338 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1
));
2340 printf("pid2 successfully read the range 130:4\n");
2343 status
= cli_writeall(cli1
, fnum1
, 0, (uint8_t *)buf
, 130, 4, NULL
);
2344 if (!NT_STATUS_IS_OK(status
)) {
2345 printf("pid2 unable to write to the range 130:4, error was "
2346 "%s\n", nt_errstr(status
));
2347 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_LOCK_CONFLICT
)) {
2348 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2352 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
2356 cli_setpid(cli1
, 1);
2357 cli_unlock(cli1
, fnum1
, 130, 4);
2359 status
= cli_lock32(cli1
, fnum1
, 130, 4, 0, WRITE_LOCK
);
2360 if (!NT_STATUS_IS_OK(status
)) {
2361 printf("Unable to apply write lock on range 130:4, error was %s\n", nt_errstr(status
));
2364 printf("pid1 successfully locked range 130:4 for WRITE\n");
2367 if (cli_read_old(cli1
, fnum1
, buf
, 130, 4) != 4) {
2368 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1
));
2371 printf("pid1 successfully read the range 130:4\n");
2374 status
= cli_writeall(cli1
, fnum1
, 0, (uint8_t *)buf
, 130, 4, NULL
);
2375 if (!NT_STATUS_IS_OK(status
)) {
2376 printf("pid1 unable to write to the range 130:4, error was "
2377 "%s\n", nt_errstr(status
));
2380 printf("pid1 successfully wrote to the range 130:4\n");
2383 cli_setpid(cli1
, 2);
2385 if (cli_read_old(cli1
, fnum1
, buf
, 130, 4) != 4) {
2386 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1
));
2387 if (NT_STATUS_V(cli_nt_error(cli1
)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT
)) {
2388 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2392 printf("pid2 successfully read the range 130:4 (should be denied)\n");
2396 status
= cli_writeall(cli1
, fnum1
, 0, (uint8_t *)buf
, 130, 4, NULL
);
2397 if (!NT_STATUS_IS_OK(status
)) {
2398 printf("pid2 unable to write to the range 130:4, error was "
2399 "%s\n", nt_errstr(status
));
2400 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_LOCK_CONFLICT
)) {
2401 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2405 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
2409 cli_unlock(cli1
, fnum1
, 130, 0);
2413 cli_close(cli1
, fnum1
);
2414 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2415 torture_close_connection(cli1
);
2417 printf("finished locktest7\n");
2422 * This demonstrates a problem with our use of GPFS share modes: A file
2423 * descriptor sitting in the pending close queue holding a GPFS share mode
2424 * blocks opening a file another time. Happens with Word 2007 temp files.
2425 * With "posix locking = yes" and "gpfs:sharemodes = yes" enabled, the third
2426 * open is denied with NT_STATUS_SHARING_VIOLATION.
2429 static bool run_locktest8(int dummy
)
2431 struct cli_state
*cli1
;
2432 const char *fname
= "\\lockt8.lck";
2433 uint16_t fnum1
, fnum2
;
2435 bool correct
= False
;
2438 if (!torture_open_connection(&cli1
, 0)) {
2442 cli_sockopt(cli1
, sockops
);
2444 printf("starting locktest8\n");
2446 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2448 status
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_WRITE
,
2450 if (!NT_STATUS_IS_OK(status
)) {
2451 d_fprintf(stderr
, "cli_open returned %s\n", nt_errstr(status
));
2455 memset(buf
, 0, sizeof(buf
));
2457 status
= cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
, &fnum2
);
2458 if (!NT_STATUS_IS_OK(status
)) {
2459 d_fprintf(stderr
, "cli_open second time returned %s\n",
2464 status
= cli_lock32(cli1
, fnum2
, 1, 1, 0, READ_LOCK
);
2465 if (!NT_STATUS_IS_OK(status
)) {
2466 printf("Unable to apply read lock on range 1:1, error was "
2467 "%s\n", nt_errstr(status
));
2471 status
= cli_close(cli1
, fnum1
);
2472 if (!NT_STATUS_IS_OK(status
)) {
2473 d_fprintf(stderr
, "cli_close(fnum1) %s\n", nt_errstr(status
));
2477 status
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
);
2478 if (!NT_STATUS_IS_OK(status
)) {
2479 d_fprintf(stderr
, "cli_open third time returned %s\n",
2487 cli_close(cli1
, fnum1
);
2488 cli_close(cli1
, fnum2
);
2489 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2490 torture_close_connection(cli1
);
2492 printf("finished locktest8\n");
2497 * This test is designed to be run in conjunction with
2498 * external NFS or POSIX locks taken in the filesystem.
2499 * It checks that the smbd server will block until the
2500 * lock is released and then acquire it. JRA.
2503 static bool got_alarm
;
2504 static int alarm_fd
;
2506 static void alarm_handler(int dummy
)
2511 static void alarm_handler_parent(int dummy
)
2516 static void do_local_lock(int read_fd
, int write_fd
)
2521 const char *local_pathname
= NULL
;
2524 local_pathname
= talloc_asprintf(talloc_tos(),
2525 "%s/lockt9.lck", local_path
);
2526 if (!local_pathname
) {
2527 printf("child: alloc fail\n");
2531 unlink(local_pathname
);
2532 fd
= open(local_pathname
, O_RDWR
|O_CREAT
, 0666);
2534 printf("child: open of %s failed %s.\n",
2535 local_pathname
, strerror(errno
));
2539 /* Now take a fcntl lock. */
2540 lock
.l_type
= F_WRLCK
;
2541 lock
.l_whence
= SEEK_SET
;
2544 lock
.l_pid
= getpid();
2546 ret
= fcntl(fd
,F_SETLK
,&lock
);
2548 printf("child: failed to get lock 0:4 on file %s. Error %s\n",
2549 local_pathname
, strerror(errno
));
2552 printf("child: got lock 0:4 on file %s.\n",
2557 CatchSignal(SIGALRM
, alarm_handler
);
2559 /* Signal the parent. */
2560 if (write(write_fd
, &c
, 1) != 1) {
2561 printf("child: start signal fail %s.\n",
2568 /* Wait for the parent to be ready. */
2569 if (read(read_fd
, &c
, 1) != 1) {
2570 printf("child: reply signal fail %s.\n",
2578 printf("child: released lock 0:4 on file %s.\n",
2584 static bool run_locktest9(int dummy
)
2586 struct cli_state
*cli1
;
2587 const char *fname
= "\\lockt9.lck";
2589 bool correct
= False
;
2590 int pipe_in
[2], pipe_out
[2];
2594 struct timeval start
;
2598 printf("starting locktest9\n");
2600 if (local_path
== NULL
) {
2601 d_fprintf(stderr
, "locktest9 must be given a local path via -l <localpath>\n");
2605 if (pipe(pipe_in
) == -1 || pipe(pipe_out
) == -1) {
2610 if (child_pid
== -1) {
2614 if (child_pid
== 0) {
2616 do_local_lock(pipe_out
[0], pipe_in
[1]);
2626 ret
= read(pipe_in
[0], &c
, 1);
2628 d_fprintf(stderr
, "failed to read start signal from child. %s\n",
2633 if (!torture_open_connection(&cli1
, 0)) {
2637 cli_sockopt(cli1
, sockops
);
2639 status
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
,
2641 if (!NT_STATUS_IS_OK(status
)) {
2642 d_fprintf(stderr
, "cli_open returned %s\n", nt_errstr(status
));
2646 /* Ensure the child has the lock. */
2647 status
= cli_lock32(cli1
, fnum
, 0, 4, 0, WRITE_LOCK
);
2648 if (NT_STATUS_IS_OK(status
)) {
2649 d_fprintf(stderr
, "Got the lock on range 0:4 - this should not happen !\n");
2652 d_printf("Child has the lock.\n");
2655 /* Tell the child to wait 5 seconds then exit. */
2656 ret
= write(pipe_out
[1], &c
, 1);
2658 d_fprintf(stderr
, "failed to send exit signal to child. %s\n",
2663 /* Wait 20 seconds for the lock. */
2664 alarm_fd
= cli1
->fd
;
2665 CatchSignal(SIGALRM
, alarm_handler_parent
);
2668 start
= timeval_current();
2670 status
= cli_lock32(cli1
, fnum
, 0, 4, -1, WRITE_LOCK
);
2671 if (!NT_STATUS_IS_OK(status
)) {
2672 d_fprintf(stderr
, "Unable to apply write lock on range 0:4, error was "
2673 "%s\n", nt_errstr(status
));
2678 seconds
= timeval_elapsed(&start
);
2680 printf("Parent got the lock after %.2f seconds.\n",
2683 status
= cli_close(cli1
, fnum
);
2684 if (!NT_STATUS_IS_OK(status
)) {
2685 d_fprintf(stderr
, "cli_close(fnum1) %s\n", nt_errstr(status
));
2692 cli_close(cli1
, fnum
);
2693 torture_close_connection(cli1
);
2697 printf("finished locktest9\n");
2702 test whether fnums and tids open on one VC are available on another (a major
2705 static bool run_fdpasstest(int dummy
)
2707 struct cli_state
*cli1
, *cli2
;
2708 const char *fname
= "\\fdpass.tst";
2713 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
2716 cli_sockopt(cli1
, sockops
);
2717 cli_sockopt(cli2
, sockops
);
2719 printf("starting fdpasstest\n");
2721 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2723 status
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
,
2725 if (!NT_STATUS_IS_OK(status
)) {
2726 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
2730 status
= cli_writeall(cli1
, fnum1
, 0, (const uint8_t *)"hello world\n", 0,
2732 if (!NT_STATUS_IS_OK(status
)) {
2733 printf("write failed (%s)\n", nt_errstr(status
));
2737 cli2
->vuid
= cli1
->vuid
;
2738 cli_state_set_tid(cli2
, cli_state_get_tid(cli1
));
2739 cli_setpid(cli2
, cli_getpid(cli1
));
2741 if (cli_read_old(cli2
, fnum1
, buf
, 0, 13) == 13) {
2742 printf("read succeeded! nasty security hole [%s]\n",
2747 cli_close(cli1
, fnum1
);
2748 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2750 torture_close_connection(cli1
);
2751 torture_close_connection(cli2
);
2753 printf("finished fdpasstest\n");
2757 static bool run_fdsesstest(int dummy
)
2759 struct cli_state
*cli
;
2764 const char *fname
= "\\fdsess.tst";
2765 const char *fname1
= "\\fdsess1.tst";
2772 if (!torture_open_connection(&cli
, 0))
2774 cli_sockopt(cli
, sockops
);
2776 if (!torture_cli_session_setup2(cli
, &new_vuid
))
2779 saved_cnum
= cli_state_get_tid(cli
);
2780 if (!NT_STATUS_IS_OK(cli_tcon_andx(cli
, share
, "?????", "", 1)))
2782 new_cnum
= cli_state_get_tid(cli
);
2783 cli_state_set_tid(cli
, saved_cnum
);
2785 printf("starting fdsesstest\n");
2787 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2788 cli_unlink(cli
, fname1
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2790 status
= cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
);
2791 if (!NT_STATUS_IS_OK(status
)) {
2792 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
2796 status
= cli_writeall(cli
, fnum1
, 0, (const uint8_t *)"hello world\n", 0, 13,
2798 if (!NT_STATUS_IS_OK(status
)) {
2799 printf("write failed (%s)\n", nt_errstr(status
));
2803 saved_vuid
= cli
->vuid
;
2804 cli
->vuid
= new_vuid
;
2806 if (cli_read_old(cli
, fnum1
, buf
, 0, 13) == 13) {
2807 printf("read succeeded with different vuid! nasty security hole [%s]\n",
2811 /* Try to open a file with different vuid, samba cnum. */
2812 if (NT_STATUS_IS_OK(cli_open(cli
, fname1
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum2
))) {
2813 printf("create with different vuid, same cnum succeeded.\n");
2814 cli_close(cli
, fnum2
);
2815 cli_unlink(cli
, fname1
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2817 printf("create with different vuid, same cnum failed.\n");
2818 printf("This will cause problems with service clients.\n");
2822 cli
->vuid
= saved_vuid
;
2824 /* Try with same vuid, different cnum. */
2825 cli_state_set_tid(cli
, new_cnum
);
2827 if (cli_read_old(cli
, fnum1
, buf
, 0, 13) == 13) {
2828 printf("read succeeded with different cnum![%s]\n",
2833 cli_state_set_tid(cli
, saved_cnum
);
2834 cli_close(cli
, fnum1
);
2835 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2837 torture_close_connection(cli
);
2839 printf("finished fdsesstest\n");
2844 This test checks that
2846 1) the server does not allow an unlink on a file that is open
2848 static bool run_unlinktest(int dummy
)
2850 struct cli_state
*cli
;
2851 const char *fname
= "\\unlink.tst";
2853 bool correct
= True
;
2856 if (!torture_open_connection(&cli
, 0)) {
2860 cli_sockopt(cli
, sockops
);
2862 printf("starting unlink test\n");
2864 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2868 status
= cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum
);
2869 if (!NT_STATUS_IS_OK(status
)) {
2870 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
2874 status
= cli_unlink(cli
, fname
,
2875 FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2876 if (NT_STATUS_IS_OK(status
)) {
2877 printf("error: server allowed unlink on an open file\n");
2880 correct
= check_error(__LINE__
, cli
, ERRDOS
, ERRbadshare
,
2881 NT_STATUS_SHARING_VIOLATION
);
2884 cli_close(cli
, fnum
);
2885 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2887 if (!torture_close_connection(cli
)) {
2891 printf("unlink test finished\n");
2898 test how many open files this server supports on the one socket
2900 static bool run_maxfidtest(int dummy
)
2902 struct cli_state
*cli
;
2904 uint16_t fnums
[0x11000];
2907 bool correct
= True
;
2913 printf("failed to connect\n");
2917 cli_sockopt(cli
, sockops
);
2919 for (i
=0; i
<0x11000; i
++) {
2920 slprintf(fname
,sizeof(fname
)-1,"\\maxfid.%d.%d", i
,(int)getpid());
2921 status
= cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_TRUNC
, DENY_NONE
,
2923 if (!NT_STATUS_IS_OK(status
)) {
2924 printf("open of %s failed (%s)\n",
2925 fname
, nt_errstr(status
));
2926 printf("maximum fnum is %d\n", i
);
2934 printf("cleaning up\n");
2936 slprintf(fname
,sizeof(fname
)-1,"\\maxfid.%d.%d", i
,(int)getpid());
2937 cli_close(cli
, fnums
[i
]);
2939 status
= cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2940 if (!NT_STATUS_IS_OK(status
)) {
2941 printf("unlink of %s failed (%s)\n",
2942 fname
, nt_errstr(status
));
2949 printf("maxfid test finished\n");
2950 if (!torture_close_connection(cli
)) {
2956 /* generate a random buffer */
2957 static void rand_buf(char *buf
, int len
)
2960 *buf
= (char)sys_random();
2965 /* send smb negprot commands, not reading the response */
2966 static bool run_negprot_nowait(int dummy
)
2968 struct tevent_context
*ev
;
2970 struct cli_state
*cli
;
2971 bool correct
= True
;
2973 printf("starting negprot nowait test\n");
2975 ev
= tevent_context_init(talloc_tos());
2980 if (!(cli
= open_nbt_connection())) {
2985 for (i
=0;i
<50000;i
++) {
2986 struct tevent_req
*req
;
2988 req
= cli_negprot_send(ev
, ev
, cli
);
2993 if (!tevent_req_poll(req
, ev
)) {
2994 d_fprintf(stderr
, "tevent_req_poll failed: %s\n",
3002 if (torture_close_connection(cli
)) {
3006 printf("finished negprot nowait test\n");
3011 /* send smb negprot commands, not reading the response */
3012 static bool run_bad_nbt_session(int dummy
)
3014 struct nmb_name called
, calling
;
3015 struct sockaddr_storage ss
;
3020 printf("starting bad nbt session test\n");
3022 make_nmb_name(&calling
, myname
, 0x0);
3023 make_nmb_name(&called
, host
, 0x20);
3025 if (!resolve_name(host
, &ss
, 0x20, true)) {
3026 d_fprintf(stderr
, "Could not resolve name %s\n", host
);
3030 status
= open_socket_out(&ss
, 139, 10000, &fd
);
3031 if (!NT_STATUS_IS_OK(status
)) {
3032 d_fprintf(stderr
, "open_socket_out failed: %s\n",
3037 ret
= cli_bad_session_request(fd
, &calling
, &called
);
3040 d_fprintf(stderr
, "open_socket_out failed: %s\n",
3045 printf("finished bad nbt session test\n");
3049 /* send random IPC commands */
3050 static bool run_randomipc(int dummy
)
3052 char *rparam
= NULL
;
3054 unsigned int rdrcnt
,rprcnt
;
3056 int api
, param_len
, i
;
3057 struct cli_state
*cli
;
3058 bool correct
= True
;
3061 printf("starting random ipc test\n");
3063 if (!torture_open_connection(&cli
, 0)) {
3067 for (i
=0;i
<count
;i
++) {
3068 api
= sys_random() % 500;
3069 param_len
= (sys_random() % 64);
3071 rand_buf(param
, param_len
);
3076 param
, param_len
, 8,
3077 NULL
, 0, BUFFER_SIZE
,
3081 printf("%d/%d\r", i
,count
);
3084 printf("%d/%d\n", i
, count
);
3086 if (!torture_close_connection(cli
)) {
3090 printf("finished random ipc test\n");
3097 static void browse_callback(const char *sname
, uint32 stype
,
3098 const char *comment
, void *state
)
3100 printf("\t%20.20s %08x %s\n", sname
, stype
, comment
);
3106 This test checks the browse list code
3109 static bool run_browsetest(int dummy
)
3111 static struct cli_state
*cli
;
3112 bool correct
= True
;
3114 printf("starting browse test\n");
3116 if (!torture_open_connection(&cli
, 0)) {
3120 printf("domain list:\n");
3121 cli_NetServerEnum(cli
, cli
->server_domain
,
3122 SV_TYPE_DOMAIN_ENUM
,
3123 browse_callback
, NULL
);
3125 printf("machine list:\n");
3126 cli_NetServerEnum(cli
, cli
->server_domain
,
3128 browse_callback
, NULL
);
3130 if (!torture_close_connection(cli
)) {
3134 printf("browse test finished\n");
3142 This checks how the getatr calls works
3144 static bool run_attrtest(int dummy
)
3146 struct cli_state
*cli
;
3149 const char *fname
= "\\attrib123456789.tst";
3150 bool correct
= True
;
3153 printf("starting attrib test\n");
3155 if (!torture_open_connection(&cli
, 0)) {
3159 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3160 cli_open(cli
, fname
,
3161 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
, &fnum
);
3162 cli_close(cli
, fnum
);
3164 status
= cli_getatr(cli
, fname
, NULL
, NULL
, &t
);
3165 if (!NT_STATUS_IS_OK(status
)) {
3166 printf("getatr failed (%s)\n", nt_errstr(status
));
3170 if (abs(t
- time(NULL
)) > 60*60*24*10) {
3171 printf("ERROR: SMBgetatr bug. time is %s",
3177 t2
= t
-60*60*24; /* 1 day ago */
3179 status
= cli_setatr(cli
, fname
, 0, t2
);
3180 if (!NT_STATUS_IS_OK(status
)) {
3181 printf("setatr failed (%s)\n", nt_errstr(status
));
3185 status
= cli_getatr(cli
, fname
, NULL
, NULL
, &t
);
3186 if (!NT_STATUS_IS_OK(status
)) {
3187 printf("getatr failed (%s)\n", nt_errstr(status
));
3192 printf("ERROR: getatr/setatr bug. times are\n%s",
3194 printf("%s", ctime(&t2
));
3198 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3200 if (!torture_close_connection(cli
)) {
3204 printf("attrib test finished\n");
3211 This checks a couple of trans2 calls
3213 static bool run_trans2test(int dummy
)
3215 struct cli_state
*cli
;
3218 time_t c_time
, a_time
, m_time
;
3219 struct timespec c_time_ts
, a_time_ts
, m_time_ts
, w_time_ts
, m_time2_ts
;
3220 const char *fname
= "\\trans2.tst";
3221 const char *dname
= "\\trans2";
3222 const char *fname2
= "\\trans2\\trans2.tst";
3224 bool correct
= True
;
3228 printf("starting trans2 test\n");
3230 if (!torture_open_connection(&cli
, 0)) {
3234 status
= cli_get_fs_attr_info(cli
, &fs_attr
);
3235 if (!NT_STATUS_IS_OK(status
)) {
3236 printf("ERROR: cli_get_fs_attr_info returned %s\n",
3241 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3242 cli_open(cli
, fname
, O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
, &fnum
);
3243 status
= cli_qfileinfo_basic(cli
, fnum
, NULL
, &size
, &c_time_ts
,
3244 &a_time_ts
, &w_time_ts
, &m_time_ts
, NULL
);
3245 if (!NT_STATUS_IS_OK(status
)) {
3246 printf("ERROR: qfileinfo failed (%s)\n", nt_errstr(status
));
3250 status
= cli_qfilename(cli
, fnum
, talloc_tos(), &pname
);
3251 if (!NT_STATUS_IS_OK(status
)) {
3252 printf("ERROR: qfilename failed (%s)\n", nt_errstr(status
));
3256 if (strcmp(pname
, fname
)) {
3257 printf("qfilename gave different name? [%s] [%s]\n",
3262 cli_close(cli
, fnum
);
3266 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3267 status
= cli_open(cli
, fname
, O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
,
3269 if (!NT_STATUS_IS_OK(status
)) {
3270 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
3273 cli_close(cli
, fnum
);
3275 status
= cli_qpathinfo1(cli
, fname
, &c_time
, &a_time
, &m_time
, &size
,
3277 if (!NT_STATUS_IS_OK(status
)) {
3278 printf("ERROR: qpathinfo failed (%s)\n", nt_errstr(status
));
3281 if (c_time
!= m_time
) {
3282 printf("create time=%s", ctime(&c_time
));
3283 printf("modify time=%s", ctime(&m_time
));
3284 printf("This system appears to have sticky create times\n");
3286 if (a_time
% (60*60) == 0) {
3287 printf("access time=%s", ctime(&a_time
));
3288 printf("This system appears to set a midnight access time\n");
3292 if (abs(m_time
- time(NULL
)) > 60*60*24*7) {
3293 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time
));
3299 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3300 cli_open(cli
, fname
,
3301 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
, &fnum
);
3302 cli_close(cli
, fnum
);
3303 status
= cli_qpathinfo2(cli
, fname
, &c_time_ts
, &a_time_ts
, &w_time_ts
,
3304 &m_time_ts
, &size
, NULL
, NULL
);
3305 if (!NT_STATUS_IS_OK(status
)) {
3306 printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status
));
3309 if (w_time_ts
.tv_sec
< 60*60*24*2) {
3310 printf("write time=%s", ctime(&w_time_ts
.tv_sec
));
3311 printf("This system appears to set a initial 0 write time\n");
3316 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3319 /* check if the server updates the directory modification time
3320 when creating a new file */
3321 status
= cli_mkdir(cli
, dname
);
3322 if (!NT_STATUS_IS_OK(status
)) {
3323 printf("ERROR: mkdir failed (%s)\n", nt_errstr(status
));
3327 status
= cli_qpathinfo2(cli
, "\\trans2\\", &c_time_ts
, &a_time_ts
,
3328 &w_time_ts
, &m_time_ts
, &size
, NULL
, NULL
);
3329 if (!NT_STATUS_IS_OK(status
)) {
3330 printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status
));
3334 cli_open(cli
, fname2
,
3335 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
, &fnum
);
3336 cli_writeall(cli
, fnum
, 0, (uint8_t *)&fnum
, 0, sizeof(fnum
), NULL
);
3337 cli_close(cli
, fnum
);
3338 status
= cli_qpathinfo2(cli
, "\\trans2\\", &c_time_ts
, &a_time_ts
,
3339 &w_time_ts
, &m_time2_ts
, &size
, NULL
, NULL
);
3340 if (!NT_STATUS_IS_OK(status
)) {
3341 printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status
));
3344 if (memcmp(&m_time_ts
, &m_time2_ts
, sizeof(struct timespec
))
3346 printf("This system does not update directory modification times\n");
3350 cli_unlink(cli
, fname2
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3351 cli_rmdir(cli
, dname
);
3353 if (!torture_close_connection(cli
)) {
3357 printf("trans2 test finished\n");
3363 This checks new W2K calls.
3366 static NTSTATUS
new_trans(struct cli_state
*pcli
, int fnum
, int level
)
3368 uint8_t *buf
= NULL
;
3372 status
= cli_qfileinfo(talloc_tos(), pcli
, fnum
, level
, 0,
3373 pcli
->max_xmit
, NULL
, &buf
, &len
);
3374 if (!NT_STATUS_IS_OK(status
)) {
3375 printf("ERROR: qfileinfo (%d) failed (%s)\n", level
,
3378 printf("qfileinfo: level %d, len = %u\n", level
, len
);
3379 dump_data(0, (uint8
*)buf
, len
);
3386 static bool run_w2ktest(int dummy
)
3388 struct cli_state
*cli
;
3390 const char *fname
= "\\w2ktest\\w2k.tst";
3392 bool correct
= True
;
3394 printf("starting w2k test\n");
3396 if (!torture_open_connection(&cli
, 0)) {
3400 cli_open(cli
, fname
,
3401 O_RDWR
| O_CREAT
, DENY_NONE
, &fnum
);
3403 for (level
= 1004; level
< 1040; level
++) {
3404 new_trans(cli
, fnum
, level
);
3407 cli_close(cli
, fnum
);
3409 if (!torture_close_connection(cli
)) {
3413 printf("w2k test finished\n");
3420 this is a harness for some oplock tests
3422 static bool run_oplock1(int dummy
)
3424 struct cli_state
*cli1
;
3425 const char *fname
= "\\lockt1.lck";
3427 bool correct
= True
;
3430 printf("starting oplock test 1\n");
3432 if (!torture_open_connection(&cli1
, 0)) {
3436 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3438 cli_sockopt(cli1
, sockops
);
3440 cli1
->use_oplocks
= True
;
3442 status
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
,
3444 if (!NT_STATUS_IS_OK(status
)) {
3445 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
3449 cli1
->use_oplocks
= False
;
3451 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3452 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3454 status
= cli_close(cli1
, fnum1
);
3455 if (!NT_STATUS_IS_OK(status
)) {
3456 printf("close2 failed (%s)\n", nt_errstr(status
));
3460 status
= cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3461 if (!NT_STATUS_IS_OK(status
)) {
3462 printf("unlink failed (%s)\n", nt_errstr(status
));
3466 if (!torture_close_connection(cli1
)) {
3470 printf("finished oplock test 1\n");
3475 static bool run_oplock2(int dummy
)
3477 struct cli_state
*cli1
, *cli2
;
3478 const char *fname
= "\\lockt2.lck";
3479 uint16_t fnum1
, fnum2
;
3480 int saved_use_oplocks
= use_oplocks
;
3482 bool correct
= True
;
3483 volatile bool *shared_correct
;
3486 shared_correct
= (volatile bool *)shm_setup(sizeof(bool));
3487 *shared_correct
= True
;
3489 use_level_II_oplocks
= True
;
3492 printf("starting oplock test 2\n");
3494 if (!torture_open_connection(&cli1
, 0)) {
3495 use_level_II_oplocks
= False
;
3496 use_oplocks
= saved_use_oplocks
;
3500 cli1
->use_oplocks
= True
;
3501 cli1
->use_level_II_oplocks
= True
;
3503 if (!torture_open_connection(&cli2
, 1)) {
3504 use_level_II_oplocks
= False
;
3505 use_oplocks
= saved_use_oplocks
;
3509 cli2
->use_oplocks
= True
;
3510 cli2
->use_level_II_oplocks
= True
;
3512 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3514 cli_sockopt(cli1
, sockops
);
3515 cli_sockopt(cli2
, sockops
);
3517 status
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
,
3519 if (!NT_STATUS_IS_OK(status
)) {
3520 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
3524 /* Don't need the globals any more. */
3525 use_level_II_oplocks
= False
;
3526 use_oplocks
= saved_use_oplocks
;
3530 status
= cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
, &fnum2
);
3531 if (!NT_STATUS_IS_OK(status
)) {
3532 printf("second open of %s failed (%s)\n", fname
, nt_errstr(status
));
3533 *shared_correct
= False
;
3539 status
= cli_close(cli2
, fnum2
);
3540 if (!NT_STATUS_IS_OK(status
)) {
3541 printf("close2 failed (%s)\n", nt_errstr(status
));
3542 *shared_correct
= False
;
3550 /* Ensure cli1 processes the break. Empty file should always return 0
3553 if (cli_read_old(cli1
, fnum1
, buf
, 0, 4) != 0) {
3554 printf("read on fnum1 failed (%s)\n", cli_errstr(cli1
));
3558 /* Should now be at level II. */
3559 /* Test if sending a write locks causes a break to none. */
3560 status
= cli_lock32(cli1
, fnum1
, 0, 4, 0, READ_LOCK
);
3561 if (!NT_STATUS_IS_OK(status
)) {
3562 printf("lock failed (%s)\n", nt_errstr(status
));
3566 cli_unlock(cli1
, fnum1
, 0, 4);
3570 status
= cli_lock32(cli1
, fnum1
, 0, 4, 0, WRITE_LOCK
);
3571 if (!NT_STATUS_IS_OK(status
)) {
3572 printf("lock failed (%s)\n", nt_errstr(status
));
3576 cli_unlock(cli1
, fnum1
, 0, 4);
3580 cli_read_old(cli1
, fnum1
, buf
, 0, 4);
3582 status
= cli_close(cli1
, fnum1
);
3583 if (!NT_STATUS_IS_OK(status
)) {
3584 printf("close1 failed (%s)\n", nt_errstr(status
));
3590 status
= cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3591 if (!NT_STATUS_IS_OK(status
)) {
3592 printf("unlink failed (%s)\n", nt_errstr(status
));
3596 if (!torture_close_connection(cli1
)) {
3600 if (!*shared_correct
) {
3604 printf("finished oplock test 2\n");
3609 struct oplock4_state
{
3610 struct tevent_context
*ev
;
3611 struct cli_state
*cli
;
3616 static void oplock4_got_break(struct tevent_req
*req
);
3617 static void oplock4_got_open(struct tevent_req
*req
);
3619 static bool run_oplock4(int dummy
)
3621 struct tevent_context
*ev
;
3622 struct cli_state
*cli1
, *cli2
;
3623 struct tevent_req
*oplock_req
, *open_req
;
3624 const char *fname
= "\\lockt4.lck";
3625 const char *fname_ln
= "\\lockt4_ln.lck";
3626 uint16_t fnum1
, fnum2
;
3627 int saved_use_oplocks
= use_oplocks
;
3629 bool correct
= true;
3633 struct oplock4_state
*state
;
3635 printf("starting oplock test 4\n");
3637 if (!torture_open_connection(&cli1
, 0)) {
3638 use_level_II_oplocks
= false;
3639 use_oplocks
= saved_use_oplocks
;
3643 if (!torture_open_connection(&cli2
, 1)) {
3644 use_level_II_oplocks
= false;
3645 use_oplocks
= saved_use_oplocks
;
3649 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3650 cli_unlink(cli1
, fname_ln
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3652 cli_sockopt(cli1
, sockops
);
3653 cli_sockopt(cli2
, sockops
);
3655 /* Create the file. */
3656 status
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
,
3658 if (!NT_STATUS_IS_OK(status
)) {
3659 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
3663 status
= cli_close(cli1
, fnum1
);
3664 if (!NT_STATUS_IS_OK(status
)) {
3665 printf("close1 failed (%s)\n", nt_errstr(status
));
3669 /* Now create a hardlink. */
3670 status
= cli_nt_hardlink(cli1
, fname
, fname_ln
);
3671 if (!NT_STATUS_IS_OK(status
)) {
3672 printf("nt hardlink failed (%s)\n", nt_errstr(status
));
3676 /* Prove that opening hardlinks cause deny modes to conflict. */
3677 status
= cli_open(cli1
, fname
, O_RDWR
, DENY_ALL
, &fnum1
);
3678 if (!NT_STATUS_IS_OK(status
)) {
3679 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
3683 status
= cli_open(cli1
, fname_ln
, O_RDWR
, DENY_NONE
, &fnum2
);
3684 if (NT_STATUS_IS_OK(status
)) {
3685 printf("open of %s succeeded - should fail with sharing violation.\n",
3690 if (!NT_STATUS_EQUAL(status
, NT_STATUS_SHARING_VIOLATION
)) {
3691 printf("open of %s should fail with sharing violation. Got %s\n",
3692 fname_ln
, nt_errstr(status
));
3696 status
= cli_close(cli1
, fnum1
);
3697 if (!NT_STATUS_IS_OK(status
)) {
3698 printf("close1 failed (%s)\n", nt_errstr(status
));
3702 cli1
->use_oplocks
= true;
3703 cli1
->use_level_II_oplocks
= true;
3705 cli2
->use_oplocks
= true;
3706 cli2
->use_level_II_oplocks
= true;
3708 status
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
);
3709 if (!NT_STATUS_IS_OK(status
)) {
3710 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
3714 ev
= tevent_context_init(talloc_tos());
3716 printf("tevent_req_create failed\n");
3720 state
= talloc(ev
, struct oplock4_state
);
3721 if (state
== NULL
) {
3722 printf("talloc failed\n");
3727 state
->got_break
= &got_break
;
3728 state
->fnum2
= &fnum2
;
3730 oplock_req
= cli_smb_oplock_break_waiter_send(
3731 talloc_tos(), ev
, cli1
);
3732 if (oplock_req
== NULL
) {
3733 printf("cli_smb_oplock_break_waiter_send failed\n");
3736 tevent_req_set_callback(oplock_req
, oplock4_got_break
, state
);
3738 open_req
= cli_open_send(
3739 talloc_tos(), ev
, cli2
, fname_ln
, O_RDWR
, DENY_NONE
);
3740 if (oplock_req
== NULL
) {
3741 printf("cli_open_send failed\n");
3744 tevent_req_set_callback(open_req
, oplock4_got_open
, state
);
3749 while (!got_break
|| fnum2
== 0xffff) {
3751 ret
= tevent_loop_once(ev
);
3753 printf("tevent_loop_once failed: %s\n",
3759 status
= cli_close(cli2
, fnum2
);
3760 if (!NT_STATUS_IS_OK(status
)) {
3761 printf("close2 failed (%s)\n", nt_errstr(status
));
3765 status
= cli_close(cli1
, fnum1
);
3766 if (!NT_STATUS_IS_OK(status
)) {
3767 printf("close1 failed (%s)\n", nt_errstr(status
));
3771 status
= cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3772 if (!NT_STATUS_IS_OK(status
)) {
3773 printf("unlink failed (%s)\n", nt_errstr(status
));
3777 status
= cli_unlink(cli1
, fname_ln
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3778 if (!NT_STATUS_IS_OK(status
)) {
3779 printf("unlink failed (%s)\n", nt_errstr(status
));
3783 if (!torture_close_connection(cli1
)) {
3791 printf("finished oplock test 4\n");
3796 static void oplock4_got_break(struct tevent_req
*req
)
3798 struct oplock4_state
*state
= tevent_req_callback_data(
3799 req
, struct oplock4_state
);
3804 status
= cli_smb_oplock_break_waiter_recv(req
, &fnum
, &level
);
3806 if (!NT_STATUS_IS_OK(status
)) {
3807 printf("cli_smb_oplock_break_waiter_recv returned %s\n",
3811 *state
->got_break
= true;
3813 req
= cli_oplock_ack_send(state
, state
->ev
, state
->cli
, fnum
,
3816 printf("cli_oplock_ack_send failed\n");
3821 static void oplock4_got_open(struct tevent_req
*req
)
3823 struct oplock4_state
*state
= tevent_req_callback_data(
3824 req
, struct oplock4_state
);
3827 status
= cli_open_recv(req
, state
->fnum2
);
3828 if (!NT_STATUS_IS_OK(status
)) {
3829 printf("cli_open_recv returned %s\n", nt_errstr(status
));
3830 *state
->fnum2
= 0xffff;
3835 Test delete on close semantics.
3837 static bool run_deletetest(int dummy
)
3839 struct cli_state
*cli1
= NULL
;
3840 struct cli_state
*cli2
= NULL
;
3841 const char *fname
= "\\delete.file";
3842 uint16_t fnum1
= (uint16_t)-1;
3843 uint16_t fnum2
= (uint16_t)-1;
3844 bool correct
= True
;
3847 printf("starting delete test\n");
3849 if (!torture_open_connection(&cli1
, 0)) {
3853 cli_sockopt(cli1
, sockops
);
3855 /* Test 1 - this should delete the file on close. */
3857 cli_setatr(cli1
, fname
, 0, 0);
3858 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3860 status
= cli_ntcreate(cli1
, fname
, 0, GENERIC_ALL_ACCESS
|DELETE_ACCESS
,
3861 FILE_ATTRIBUTE_NORMAL
, 0, FILE_OVERWRITE_IF
,
3862 FILE_DELETE_ON_CLOSE
, 0, &fnum1
);
3863 if (!NT_STATUS_IS_OK(status
)) {
3864 printf("[1] open of %s failed (%s)\n", fname
, nt_errstr(status
));
3869 status
= cli_close(cli1
, fnum1
);
3870 if (!NT_STATUS_IS_OK(status
)) {
3871 printf("[1] close failed (%s)\n", nt_errstr(status
));
3876 if (NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
))) {
3877 printf("[1] open of %s succeeded (should fail)\n", fname
);
3882 printf("first delete on close test succeeded.\n");
3884 /* Test 2 - this should delete the file on close. */
3886 cli_setatr(cli1
, fname
, 0, 0);
3887 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3889 status
= cli_ntcreate(cli1
, fname
, 0, GENERIC_ALL_ACCESS
,
3890 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
3891 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
3892 if (!NT_STATUS_IS_OK(status
)) {
3893 printf("[2] open of %s failed (%s)\n", fname
, nt_errstr(status
));
3898 status
= cli_nt_delete_on_close(cli1
, fnum1
, true);
3899 if (!NT_STATUS_IS_OK(status
)) {
3900 printf("[2] setting delete_on_close failed (%s)\n", nt_errstr(status
));
3905 status
= cli_close(cli1
, fnum1
);
3906 if (!NT_STATUS_IS_OK(status
)) {
3907 printf("[2] close failed (%s)\n", nt_errstr(status
));
3912 if (NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
, &fnum1
))) {
3913 printf("[2] open of %s succeeded should have been deleted on close !\n", fname
);
3914 status
= cli_close(cli1
, fnum1
);
3915 if (!NT_STATUS_IS_OK(status
)) {
3916 printf("[2] close failed (%s)\n", nt_errstr(status
));
3920 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3922 printf("second delete on close test succeeded.\n");
3925 cli_setatr(cli1
, fname
, 0, 0);
3926 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3928 status
= cli_ntcreate(cli1
, fname
, 0, GENERIC_ALL_ACCESS
,
3929 FILE_ATTRIBUTE_NORMAL
,
3930 FILE_SHARE_READ
|FILE_SHARE_WRITE
,
3931 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
3932 if (!NT_STATUS_IS_OK(status
)) {
3933 printf("[3] open - 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
3938 /* This should fail with a sharing violation - open for delete is only compatible
3939 with SHARE_DELETE. */
3941 if (NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3942 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN
, 0, 0, &fnum2
))) {
3943 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname
);
3948 /* This should succeed. */
3949 status
= cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
,
3950 FILE_ATTRIBUTE_NORMAL
,
3951 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
3952 FILE_OPEN
, 0, 0, &fnum2
);
3953 if (!NT_STATUS_IS_OK(status
)) {
3954 printf("[3] open - 2 of %s failed (%s)\n", fname
, nt_errstr(status
));
3959 status
= cli_nt_delete_on_close(cli1
, fnum1
, true);
3960 if (!NT_STATUS_IS_OK(status
)) {
3961 printf("[3] setting delete_on_close failed (%s)\n", nt_errstr(status
));
3966 status
= cli_close(cli1
, fnum1
);
3967 if (!NT_STATUS_IS_OK(status
)) {
3968 printf("[3] close 1 failed (%s)\n", nt_errstr(status
));
3973 status
= cli_close(cli1
, fnum2
);
3974 if (!NT_STATUS_IS_OK(status
)) {
3975 printf("[3] close 2 failed (%s)\n", nt_errstr(status
));
3980 /* This should fail - file should no longer be there. */
3982 if (NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
, &fnum1
))) {
3983 printf("[3] open of %s succeeded should have been deleted on close !\n", fname
);
3984 status
= cli_close(cli1
, fnum1
);
3985 if (!NT_STATUS_IS_OK(status
)) {
3986 printf("[3] close failed (%s)\n", nt_errstr(status
));
3988 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3992 printf("third delete on close test succeeded.\n");
3995 cli_setatr(cli1
, fname
, 0, 0);
3996 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3998 status
= cli_ntcreate(cli1
, fname
, 0,
3999 FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
4000 FILE_ATTRIBUTE_NORMAL
,
4001 FILE_SHARE_READ
|FILE_SHARE_WRITE
,
4002 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
4003 if (!NT_STATUS_IS_OK(status
)) {
4004 printf("[4] open of %s failed (%s)\n", fname
, nt_errstr(status
));
4009 /* This should succeed. */
4010 status
= cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
,
4011 FILE_ATTRIBUTE_NORMAL
,
4012 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
4013 FILE_OPEN
, 0, 0, &fnum2
);
4014 if (!NT_STATUS_IS_OK(status
)) {
4015 printf("[4] open - 2 of %s failed (%s)\n", fname
, nt_errstr(status
));
4020 status
= cli_close(cli1
, fnum2
);
4021 if (!NT_STATUS_IS_OK(status
)) {
4022 printf("[4] close - 1 failed (%s)\n", nt_errstr(status
));
4027 status
= cli_nt_delete_on_close(cli1
, fnum1
, true);
4028 if (!NT_STATUS_IS_OK(status
)) {
4029 printf("[4] setting delete_on_close failed (%s)\n", nt_errstr(status
));
4034 /* This should fail - no more opens once delete on close set. */
4035 if (NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
,
4036 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
4037 FILE_OPEN
, 0, 0, &fnum2
))) {
4038 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname
);
4042 printf("fourth delete on close test succeeded.\n");
4044 status
= cli_close(cli1
, fnum1
);
4045 if (!NT_STATUS_IS_OK(status
)) {
4046 printf("[4] close - 2 failed (%s)\n", nt_errstr(status
));
4052 cli_setatr(cli1
, fname
, 0, 0);
4053 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4055 status
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
, DENY_NONE
, &fnum1
);
4056 if (!NT_STATUS_IS_OK(status
)) {
4057 printf("[5] open of %s failed (%s)\n", fname
, nt_errstr(status
));
4062 /* This should fail - only allowed on NT opens with DELETE access. */
4064 if (NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, true))) {
4065 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
4070 status
= cli_close(cli1
, fnum1
);
4071 if (!NT_STATUS_IS_OK(status
)) {
4072 printf("[5] close - 2 failed (%s)\n", nt_errstr(status
));
4077 printf("fifth delete on close test succeeded.\n");
4080 cli_setatr(cli1
, fname
, 0, 0);
4081 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4083 status
= cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
,
4084 FILE_ATTRIBUTE_NORMAL
,
4085 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
4086 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
4087 if (!NT_STATUS_IS_OK(status
)) {
4088 printf("[6] open of %s failed (%s)\n", fname
,
4094 /* This should fail - only allowed on NT opens with DELETE access. */
4096 if (NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, true))) {
4097 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
4102 status
= cli_close(cli1
, fnum1
);
4103 if (!NT_STATUS_IS_OK(status
)) {
4104 printf("[6] close - 2 failed (%s)\n", nt_errstr(status
));
4109 printf("sixth delete on close test succeeded.\n");
4112 cli_setatr(cli1
, fname
, 0, 0);
4113 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4115 status
= cli_ntcreate(cli1
, fname
, 0,
4116 FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
4117 FILE_ATTRIBUTE_NORMAL
, 0, FILE_OVERWRITE_IF
,
4119 if (!NT_STATUS_IS_OK(status
)) {
4120 printf("[7] open of %s failed (%s)\n", fname
, nt_errstr(status
));
4125 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, true))) {
4126 printf("[7] setting delete_on_close on file failed !\n");
4131 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, false))) {
4132 printf("[7] unsetting delete_on_close on file failed !\n");
4137 status
= cli_close(cli1
, fnum1
);
4138 if (!NT_STATUS_IS_OK(status
)) {
4139 printf("[7] close - 2 failed (%s)\n", nt_errstr(status
));
4144 /* This next open should succeed - we reset the flag. */
4145 status
= cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
, &fnum1
);
4146 if (!NT_STATUS_IS_OK(status
)) {
4147 printf("[5] open of %s failed (%s)\n", fname
, nt_errstr(status
));
4152 status
= cli_close(cli1
, fnum1
);
4153 if (!NT_STATUS_IS_OK(status
)) {
4154 printf("[7] close - 2 failed (%s)\n", nt_errstr(status
));
4159 printf("seventh delete on close test succeeded.\n");
4162 cli_setatr(cli1
, fname
, 0, 0);
4163 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4165 if (!torture_open_connection(&cli2
, 1)) {
4166 printf("[8] failed to open second connection.\n");
4171 cli_sockopt(cli1
, sockops
);
4173 status
= cli_ntcreate(cli1
, fname
, 0,
4174 FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
4175 FILE_ATTRIBUTE_NORMAL
,
4176 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
4177 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
4178 if (!NT_STATUS_IS_OK(status
)) {
4179 printf("[8] open 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
4184 status
= cli_ntcreate(cli2
, fname
, 0,
4185 FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
4186 FILE_ATTRIBUTE_NORMAL
,
4187 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
4188 FILE_OPEN
, 0, 0, &fnum2
);
4189 if (!NT_STATUS_IS_OK(status
)) {
4190 printf("[8] open 2 of %s failed (%s)\n", fname
, nt_errstr(status
));
4195 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, true))) {
4196 printf("[8] setting delete_on_close on file failed !\n");
4201 status
= cli_close(cli1
, fnum1
);
4202 if (!NT_STATUS_IS_OK(status
)) {
4203 printf("[8] close - 1 failed (%s)\n", nt_errstr(status
));
4208 status
= cli_close(cli2
, fnum2
);
4209 if (!NT_STATUS_IS_OK(status
)) {
4210 printf("[8] close - 2 failed (%s)\n", nt_errstr(status
));
4215 /* This should fail.. */
4216 status
= cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
, &fnum1
);
4217 if (NT_STATUS_IS_OK(status
)) {
4218 printf("[8] open of %s succeeded should have been deleted on close !\n", fname
);
4222 printf("eighth delete on close test succeeded.\n");
4224 /* This should fail - we need to set DELETE_ACCESS. */
4225 if (NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0,FILE_READ_DATA
|FILE_WRITE_DATA
,
4226 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, FILE_DELETE_ON_CLOSE
, 0, &fnum1
))) {
4227 printf("[9] open of %s succeeded should have failed!\n", fname
);
4232 printf("ninth delete on close test succeeded.\n");
4234 status
= cli_ntcreate(cli1
, fname
, 0,
4235 FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
4236 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
4237 FILE_OVERWRITE_IF
, FILE_DELETE_ON_CLOSE
,
4239 if (!NT_STATUS_IS_OK(status
)) {
4240 printf("[10] open of %s failed (%s)\n", fname
, nt_errstr(status
));
4245 /* This should delete the file. */
4246 status
= cli_close(cli1
, fnum1
);
4247 if (!NT_STATUS_IS_OK(status
)) {
4248 printf("[10] close failed (%s)\n", nt_errstr(status
));
4253 /* This should fail.. */
4254 if (NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
, &fnum1
))) {
4255 printf("[10] open of %s succeeded should have been deleted on close !\n", fname
);
4259 printf("tenth delete on close test succeeded.\n");
4261 cli_setatr(cli1
, fname
, 0, 0);
4262 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4264 /* What error do we get when attempting to open a read-only file with
4267 /* Create a readonly file. */
4268 status
= cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
,
4269 FILE_ATTRIBUTE_READONLY
, FILE_SHARE_NONE
,
4270 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
4271 if (!NT_STATUS_IS_OK(status
)) {
4272 printf("[11] open of %s failed (%s)\n", fname
, nt_errstr(status
));
4277 status
= cli_close(cli1
, fnum1
);
4278 if (!NT_STATUS_IS_OK(status
)) {
4279 printf("[11] close failed (%s)\n", nt_errstr(status
));
4284 /* Now try open for delete access. */
4285 if (NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_ATTRIBUTES
|DELETE_ACCESS
,
4286 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
4287 FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
4288 printf("[11] open of %s succeeded should have been denied with ACCESS_DENIED!\n", fname
);
4289 cli_close(cli1
, fnum1
);
4293 NTSTATUS nterr
= cli_nt_error(cli1
);
4294 if (!NT_STATUS_EQUAL(nterr
,NT_STATUS_ACCESS_DENIED
)) {
4295 printf("[11] open of %s should have been denied with ACCESS_DENIED! Got error %s\n", fname
, nt_errstr(nterr
));
4299 printf("eleventh delete on close test succeeded.\n");
4303 printf("finished delete test\n");
4306 /* FIXME: This will crash if we aborted before cli2 got
4307 * intialized, because these functions don't handle
4308 * uninitialized connections. */
4310 if (fnum1
!= (uint16_t)-1) cli_close(cli1
, fnum1
);
4311 if (fnum2
!= (uint16_t)-1) cli_close(cli1
, fnum2
);
4312 cli_setatr(cli1
, fname
, 0, 0);
4313 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4315 if (cli1
&& !torture_close_connection(cli1
)) {
4318 if (cli2
&& !torture_close_connection(cli2
)) {
4324 static bool run_deletetest_ln(int dummy
)
4326 struct cli_state
*cli
;
4327 const char *fname
= "\\delete1";
4328 const char *fname_ln
= "\\delete1_ln";
4332 bool correct
= true;
4335 printf("starting deletetest-ln\n");
4337 if (!torture_open_connection(&cli
, 0)) {
4341 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4342 cli_unlink(cli
, fname_ln
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4344 cli_sockopt(cli
, sockops
);
4346 /* Create the file. */
4347 status
= cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum
);
4348 if (!NT_STATUS_IS_OK(status
)) {
4349 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
4353 status
= cli_close(cli
, fnum
);
4354 if (!NT_STATUS_IS_OK(status
)) {
4355 printf("close1 failed (%s)\n", nt_errstr(status
));
4359 /* Now create a hardlink. */
4360 status
= cli_nt_hardlink(cli
, fname
, fname_ln
);
4361 if (!NT_STATUS_IS_OK(status
)) {
4362 printf("nt hardlink failed (%s)\n", nt_errstr(status
));
4366 /* Open the original file. */
4367 status
= cli_ntcreate(cli
, fname
, 0, FILE_READ_DATA
,
4368 FILE_ATTRIBUTE_NORMAL
,
4369 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
4370 FILE_OPEN_IF
, 0, 0, &fnum
);
4371 if (!NT_STATUS_IS_OK(status
)) {
4372 printf("ntcreate of %s failed (%s)\n", fname
, nt_errstr(status
));
4376 /* Unlink the hard link path. */
4377 status
= cli_ntcreate(cli
, fname_ln
, 0, DELETE_ACCESS
,
4378 FILE_ATTRIBUTE_NORMAL
,
4379 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
4380 FILE_OPEN_IF
, 0, 0, &fnum1
);
4381 if (!NT_STATUS_IS_OK(status
)) {
4382 printf("ntcreate of %s failed (%s)\n", fname_ln
, nt_errstr(status
));
4385 status
= cli_nt_delete_on_close(cli
, fnum1
, true);
4386 if (!NT_STATUS_IS_OK(status
)) {
4387 d_printf("(%s) failed to set delete_on_close %s: %s\n",
4388 __location__
, fname_ln
, nt_errstr(status
));
4392 status
= cli_close(cli
, fnum1
);
4393 if (!NT_STATUS_IS_OK(status
)) {
4394 printf("close %s failed (%s)\n",
4395 fname_ln
, nt_errstr(status
));
4399 status
= cli_close(cli
, fnum
);
4400 if (!NT_STATUS_IS_OK(status
)) {
4401 printf("close %s failed (%s)\n",
4402 fname
, nt_errstr(status
));
4406 /* Ensure the original file is still there. */
4407 status
= cli_getatr(cli
, fname
, NULL
, NULL
, &t
);
4408 if (!NT_STATUS_IS_OK(status
)) {
4409 printf("%s getatr on file %s failed (%s)\n",
4416 /* Ensure the link path is gone. */
4417 status
= cli_getatr(cli
, fname_ln
, NULL
, NULL
, &t
);
4418 if (!NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
4419 printf("%s, getatr for file %s returned wrong error code %s "
4420 "- should have been deleted\n",
4422 fname_ln
, nt_errstr(status
));
4426 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4427 cli_unlink(cli
, fname_ln
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4429 if (!torture_close_connection(cli
)) {
4433 printf("finished deletetest-ln\n");
4439 print out server properties
4441 static bool run_properties(int dummy
)
4443 struct cli_state
*cli
;
4444 bool correct
= True
;
4446 printf("starting properties test\n");
4450 if (!torture_open_connection(&cli
, 0)) {
4454 cli_sockopt(cli
, sockops
);
4456 d_printf("Capabilities 0x%08x\n", cli
->capabilities
);
4458 if (!torture_close_connection(cli
)) {
4467 /* FIRST_DESIRED_ACCESS 0xf019f */
4468 #define FIRST_DESIRED_ACCESS FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|\
4469 FILE_READ_EA| /* 0xf */ \
4470 FILE_WRITE_EA|FILE_READ_ATTRIBUTES| /* 0x90 */ \
4471 FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
4472 DELETE_ACCESS|READ_CONTROL_ACCESS|\
4473 WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS /* 0xf0000 */
4474 /* SECOND_DESIRED_ACCESS 0xe0080 */
4475 #define SECOND_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
4476 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
4477 WRITE_OWNER_ACCESS /* 0xe0000 */
4480 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
4481 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
4483 WRITE_OWNER_ACCESS /* */
4487 Test ntcreate calls made by xcopy
4489 static bool run_xcopy(int dummy
)
4491 static struct cli_state
*cli1
;
4492 const char *fname
= "\\test.txt";
4493 bool correct
= True
;
4494 uint16_t fnum1
, fnum2
;
4497 printf("starting xcopy test\n");
4499 if (!torture_open_connection(&cli1
, 0)) {
4503 status
= cli_ntcreate(cli1
, fname
, 0, FIRST_DESIRED_ACCESS
,
4504 FILE_ATTRIBUTE_ARCHIVE
, FILE_SHARE_NONE
,
4505 FILE_OVERWRITE_IF
, 0x4044, 0, &fnum1
);
4506 if (!NT_STATUS_IS_OK(status
)) {
4507 printf("First open failed - %s\n", nt_errstr(status
));
4511 status
= cli_ntcreate(cli1
, fname
, 0, SECOND_DESIRED_ACCESS
, 0,
4512 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
4513 FILE_OPEN
, 0x200000, 0, &fnum2
);
4514 if (!NT_STATUS_IS_OK(status
)) {
4515 printf("second open failed - %s\n", nt_errstr(status
));
4519 if (!torture_close_connection(cli1
)) {
4527 Test rename on files open with share delete and no share delete.
4529 static bool run_rename(int dummy
)
4531 static struct cli_state
*cli1
;
4532 const char *fname
= "\\test.txt";
4533 const char *fname1
= "\\test1.txt";
4534 bool correct
= True
;
4539 printf("starting rename test\n");
4541 if (!torture_open_connection(&cli1
, 0)) {
4545 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4546 cli_unlink(cli1
, fname1
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4548 status
= cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
,
4549 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
,
4550 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
4551 if (!NT_STATUS_IS_OK(status
)) {
4552 printf("First open failed - %s\n", nt_errstr(status
));
4556 status
= cli_rename(cli1
, fname
, fname1
);
4557 if (!NT_STATUS_IS_OK(status
)) {
4558 printf("First rename failed (SHARE_READ) (this is correct) - %s\n", nt_errstr(status
));
4560 printf("First rename succeeded (SHARE_READ) - this should have failed !\n");
4564 status
= cli_close(cli1
, fnum1
);
4565 if (!NT_STATUS_IS_OK(status
)) {
4566 printf("close - 1 failed (%s)\n", nt_errstr(status
));
4570 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4571 cli_unlink(cli1
, fname1
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4572 status
= cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
4574 FILE_SHARE_DELETE
|FILE_SHARE_NONE
,
4576 FILE_SHARE_DELETE
|FILE_SHARE_READ
,
4578 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
4579 if (!NT_STATUS_IS_OK(status
)) {
4580 printf("Second open failed - %s\n", nt_errstr(status
));
4584 status
= cli_rename(cli1
, fname
, fname1
);
4585 if (!NT_STATUS_IS_OK(status
)) {
4586 printf("Second rename failed (SHARE_DELETE | SHARE_READ) - this should have succeeded - %s\n", nt_errstr(status
));
4589 printf("Second rename succeeded (SHARE_DELETE | SHARE_READ)\n");
4592 status
= cli_close(cli1
, fnum1
);
4593 if (!NT_STATUS_IS_OK(status
)) {
4594 printf("close - 2 failed (%s)\n", nt_errstr(status
));
4598 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4599 cli_unlink(cli1
, fname1
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4601 status
= cli_ntcreate(cli1
, fname
, 0, READ_CONTROL_ACCESS
,
4602 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
4603 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
4604 if (!NT_STATUS_IS_OK(status
)) {
4605 printf("Third open failed - %s\n", nt_errstr(status
));
4614 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, DELETE_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
4615 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0, &fnum2
))) {
4616 printf("Fourth open failed - %s\n", cli_errstr(cli1
));
4619 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum2
, true))) {
4620 printf("[8] setting delete_on_close on file failed !\n");
4624 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum2
))) {
4625 printf("close - 4 failed (%s)\n", cli_errstr(cli1
));
4631 status
= cli_rename(cli1
, fname
, fname1
);
4632 if (!NT_STATUS_IS_OK(status
)) {
4633 printf("Third rename failed (SHARE_NONE) - this should have succeeded - %s\n", nt_errstr(status
));
4636 printf("Third rename succeeded (SHARE_NONE)\n");
4639 status
= cli_close(cli1
, fnum1
);
4640 if (!NT_STATUS_IS_OK(status
)) {
4641 printf("close - 3 failed (%s)\n", nt_errstr(status
));
4645 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4646 cli_unlink(cli1
, fname1
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4650 status
= cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
,
4651 FILE_ATTRIBUTE_NORMAL
,
4652 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
4653 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
4654 if (!NT_STATUS_IS_OK(status
)) {
4655 printf("Fourth open failed - %s\n", nt_errstr(status
));
4659 status
= cli_rename(cli1
, fname
, fname1
);
4660 if (!NT_STATUS_IS_OK(status
)) {
4661 printf("Fourth rename failed (SHARE_READ | SHARE_WRITE) (this is correct) - %s\n", nt_errstr(status
));
4663 printf("Fourth rename succeeded (SHARE_READ | SHARE_WRITE) - this should have failed !\n");
4667 status
= cli_close(cli1
, fnum1
);
4668 if (!NT_STATUS_IS_OK(status
)) {
4669 printf("close - 4 failed (%s)\n", nt_errstr(status
));
4673 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4674 cli_unlink(cli1
, fname1
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4678 status
= cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
,
4679 FILE_ATTRIBUTE_NORMAL
,
4680 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
4681 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
4682 if (!NT_STATUS_IS_OK(status
)) {
4683 printf("Fifth open failed - %s\n", nt_errstr(status
));
4687 status
= cli_rename(cli1
, fname
, fname1
);
4688 if (!NT_STATUS_IS_OK(status
)) {
4689 printf("Fifth rename failed (SHARE_READ | SHARE_WRITE | SHARE_DELETE) - this should have succeeded - %s ! \n", nt_errstr(status
));
4692 printf("Fifth rename succeeded (SHARE_READ | SHARE_WRITE | SHARE_DELETE) (this is correct) - %s\n", nt_errstr(status
));
4696 * Now check if the first name still exists ...
4699 /* if (!NT_STATUS_OP(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
4700 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0, &fnum2))) {
4701 printf("Opening original file after rename of open file fails: %s\n",
4705 printf("Opening original file after rename of open file works ...\n");
4706 (void)cli_close(cli1, fnum2);
4710 status
= cli_close(cli1
, fnum1
);
4711 if (!NT_STATUS_IS_OK(status
)) {
4712 printf("close - 5 failed (%s)\n", nt_errstr(status
));
4716 /* Check that the renamed file has FILE_ATTRIBUTE_ARCHIVE. */
4717 status
= cli_getatr(cli1
, fname1
, &attr
, NULL
, NULL
);
4718 if (!NT_STATUS_IS_OK(status
)) {
4719 printf("getatr on file %s failed - %s ! \n",
4720 fname1
, nt_errstr(status
));
4723 if (attr
!= FILE_ATTRIBUTE_ARCHIVE
) {
4724 printf("Renamed file %s has wrong attr 0x%x "
4725 "(should be 0x%x)\n",
4728 (unsigned int)FILE_ATTRIBUTE_ARCHIVE
);
4731 printf("Renamed file %s has archive bit set\n", fname1
);
4735 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4736 cli_unlink(cli1
, fname1
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4738 if (!torture_close_connection(cli1
)) {
4745 static bool run_pipe_number(int dummy
)
4747 struct cli_state
*cli1
;
4748 const char *pipe_name
= "\\SPOOLSS";
4753 printf("starting pipenumber test\n");
4754 if (!torture_open_connection(&cli1
, 0)) {
4758 cli_sockopt(cli1
, sockops
);
4760 status
= cli_ntcreate(cli1
, pipe_name
, 0, FILE_READ_DATA
,
4761 FILE_ATTRIBUTE_NORMAL
,
4762 FILE_SHARE_READ
|FILE_SHARE_WRITE
,
4763 FILE_OPEN_IF
, 0, 0, &fnum
);
4764 if (!NT_STATUS_IS_OK(status
)) {
4765 printf("Open of pipe %s failed with error (%s)\n", pipe_name
, nt_errstr(status
));
4769 printf("\r%6d", num_pipes
);
4772 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes
, pipe_name
);
4773 torture_close_connection(cli1
);
4778 Test open mode returns on read-only files.
4780 static bool run_opentest(int dummy
)
4782 static struct cli_state
*cli1
;
4783 static struct cli_state
*cli2
;
4784 const char *fname
= "\\readonly.file";
4785 uint16_t fnum1
, fnum2
;
4788 bool correct
= True
;
4792 printf("starting open test\n");
4794 if (!torture_open_connection(&cli1
, 0)) {
4798 cli_setatr(cli1
, fname
, 0, 0);
4799 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4801 cli_sockopt(cli1
, sockops
);
4803 status
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
);
4804 if (!NT_STATUS_IS_OK(status
)) {
4805 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
4809 status
= cli_close(cli1
, fnum1
);
4810 if (!NT_STATUS_IS_OK(status
)) {
4811 printf("close2 failed (%s)\n", nt_errstr(status
));
4815 status
= cli_setatr(cli1
, fname
, FILE_ATTRIBUTE_READONLY
, 0);
4816 if (!NT_STATUS_IS_OK(status
)) {
4817 printf("cli_setatr failed (%s)\n", nt_errstr(status
));
4821 status
= cli_open(cli1
, fname
, O_RDONLY
, DENY_WRITE
, &fnum1
);
4822 if (!NT_STATUS_IS_OK(status
)) {
4823 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
4827 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
4828 cli_open(cli1
, fname
, O_RDWR
, DENY_ALL
, &fnum2
);
4830 if (check_error(__LINE__
, cli1
, ERRDOS
, ERRnoaccess
,
4831 NT_STATUS_ACCESS_DENIED
)) {
4832 printf("correct error code ERRDOS/ERRnoaccess returned\n");
4835 printf("finished open test 1\n");
4837 cli_close(cli1
, fnum1
);
4839 /* Now try not readonly and ensure ERRbadshare is returned. */
4841 cli_setatr(cli1
, fname
, 0, 0);
4843 status
= cli_open(cli1
, fname
, O_RDONLY
, DENY_WRITE
, &fnum1
);
4844 if (!NT_STATUS_IS_OK(status
)) {
4845 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
4849 /* This will fail - but the error should be ERRshare. */
4850 cli_open(cli1
, fname
, O_RDWR
, DENY_ALL
, &fnum2
);
4852 if (check_error(__LINE__
, cli1
, ERRDOS
, ERRbadshare
,
4853 NT_STATUS_SHARING_VIOLATION
)) {
4854 printf("correct error code ERRDOS/ERRbadshare returned\n");
4857 status
= cli_close(cli1
, fnum1
);
4858 if (!NT_STATUS_IS_OK(status
)) {
4859 printf("close2 failed (%s)\n", nt_errstr(status
));
4863 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4865 printf("finished open test 2\n");
4867 /* Test truncate open disposition on file opened for read. */
4868 status
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
);
4869 if (!NT_STATUS_IS_OK(status
)) {
4870 printf("(3) open (1) of %s failed (%s)\n", fname
, nt_errstr(status
));
4874 /* write 20 bytes. */
4876 memset(buf
, '\0', 20);
4878 status
= cli_writeall(cli1
, fnum1
, 0, (uint8_t *)buf
, 0, 20, NULL
);
4879 if (!NT_STATUS_IS_OK(status
)) {
4880 printf("write failed (%s)\n", nt_errstr(status
));
4884 status
= cli_close(cli1
, fnum1
);
4885 if (!NT_STATUS_IS_OK(status
)) {
4886 printf("(3) close1 failed (%s)\n", nt_errstr(status
));
4890 /* Ensure size == 20. */
4891 status
= cli_getatr(cli1
, fname
, NULL
, &fsize
, NULL
);
4892 if (!NT_STATUS_IS_OK(status
)) {
4893 printf("(3) getatr failed (%s)\n", nt_errstr(status
));
4898 printf("(3) file size != 20\n");
4902 /* Now test if we can truncate a file opened for readonly. */
4903 status
= cli_open(cli1
, fname
, O_RDONLY
|O_TRUNC
, DENY_NONE
, &fnum1
);
4904 if (!NT_STATUS_IS_OK(status
)) {
4905 printf("(3) open (2) of %s failed (%s)\n", fname
, nt_errstr(status
));
4909 status
= cli_close(cli1
, fnum1
);
4910 if (!NT_STATUS_IS_OK(status
)) {
4911 printf("close2 failed (%s)\n", nt_errstr(status
));
4915 /* Ensure size == 0. */
4916 status
= cli_getatr(cli1
, fname
, NULL
, &fsize
, NULL
);
4917 if (!NT_STATUS_IS_OK(status
)) {
4918 printf("(3) getatr failed (%s)\n", nt_errstr(status
));
4923 printf("(3) file size != 0\n");
4926 printf("finished open test 3\n");
4928 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4930 printf("Do ctemp tests\n");
4931 status
= cli_ctemp(cli1
, talloc_tos(), "\\", &fnum1
, &tmp_path
);
4932 if (!NT_STATUS_IS_OK(status
)) {
4933 printf("ctemp failed (%s)\n", nt_errstr(status
));
4937 printf("ctemp gave path %s\n", tmp_path
);
4938 status
= cli_close(cli1
, fnum1
);
4939 if (!NT_STATUS_IS_OK(status
)) {
4940 printf("close of temp failed (%s)\n", nt_errstr(status
));
4943 status
= cli_unlink(cli1
, tmp_path
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4944 if (!NT_STATUS_IS_OK(status
)) {
4945 printf("unlink of temp failed (%s)\n", nt_errstr(status
));
4948 /* Test the non-io opens... */
4950 if (!torture_open_connection(&cli2
, 1)) {
4954 cli_setatr(cli2
, fname
, 0, 0);
4955 cli_unlink(cli2
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4957 cli_sockopt(cli2
, sockops
);
4959 printf("TEST #1 testing 2 non-io opens (no delete)\n");
4960 status
= cli_ntcreate(cli1
, fname
, 0, FILE_READ_ATTRIBUTES
,
4961 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
4962 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
4963 if (!NT_STATUS_IS_OK(status
)) {
4964 printf("TEST #1 open 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
4968 status
= cli_ntcreate(cli2
, fname
, 0, FILE_READ_ATTRIBUTES
,
4969 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
4970 FILE_OPEN_IF
, 0, 0, &fnum2
);
4971 if (!NT_STATUS_IS_OK(status
)) {
4972 printf("TEST #1 open 2 of %s failed (%s)\n", fname
, nt_errstr(status
));
4976 status
= cli_close(cli1
, fnum1
);
4977 if (!NT_STATUS_IS_OK(status
)) {
4978 printf("TEST #1 close 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
4982 status
= cli_close(cli2
, fnum2
);
4983 if (!NT_STATUS_IS_OK(status
)) {
4984 printf("TEST #1 close 2 of %s failed (%s)\n", fname
, nt_errstr(status
));
4988 printf("non-io open test #1 passed.\n");
4990 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4992 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
4994 status
= cli_ntcreate(cli1
, fname
, 0,
4995 DELETE_ACCESS
|FILE_READ_ATTRIBUTES
,
4996 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
4997 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
4998 if (!NT_STATUS_IS_OK(status
)) {
4999 printf("TEST #2 open 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
5003 status
= cli_ntcreate(cli2
, fname
, 0, FILE_READ_ATTRIBUTES
,
5004 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
5005 FILE_OPEN_IF
, 0, 0, &fnum2
);
5006 if (!NT_STATUS_IS_OK(status
)) {
5007 printf("TEST #2 open 2 of %s failed (%s)\n", fname
, nt_errstr(status
));
5011 status
= cli_close(cli1
, fnum1
);
5012 if (!NT_STATUS_IS_OK(status
)) {
5013 printf("TEST #2 close 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
5017 status
= cli_close(cli2
, fnum2
);
5018 if (!NT_STATUS_IS_OK(status
)) {
5019 printf("TEST #2 close 2 of %s failed (%s)\n", fname
, nt_errstr(status
));
5023 printf("non-io open test #2 passed.\n");
5025 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
5027 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
5029 status
= cli_ntcreate(cli1
, fname
, 0, FILE_READ_ATTRIBUTES
,
5030 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
5031 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
5032 if (!NT_STATUS_IS_OK(status
)) {
5033 printf("TEST #3 open 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
5037 status
= cli_ntcreate(cli2
, fname
, 0,
5038 DELETE_ACCESS
|FILE_READ_ATTRIBUTES
,
5039 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
5040 FILE_OPEN_IF
, 0, 0, &fnum2
);
5041 if (!NT_STATUS_IS_OK(status
)) {
5042 printf("TEST #3 open 2 of %s failed (%s)\n", fname
, nt_errstr(status
));
5046 status
= cli_close(cli1
, fnum1
);
5047 if (!NT_STATUS_IS_OK(status
)) {
5048 printf("TEST #3 close 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
5052 status
= cli_close(cli2
, fnum2
);
5053 if (!NT_STATUS_IS_OK(status
)) {
5054 printf("TEST #3 close 2 of %s failed (%s)\n", fname
, nt_errstr(status
));
5058 printf("non-io open test #3 passed.\n");
5060 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
5062 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
5064 status
= cli_ntcreate(cli1
, fname
, 0,
5065 DELETE_ACCESS
|FILE_READ_ATTRIBUTES
,
5066 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
5067 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
5068 if (!NT_STATUS_IS_OK(status
)) {
5069 printf("TEST #4 open 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
5073 status
= cli_ntcreate(cli2
, fname
, 0,
5074 DELETE_ACCESS
|FILE_READ_ATTRIBUTES
,
5075 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
5076 FILE_OPEN_IF
, 0, 0, &fnum2
);
5077 if (NT_STATUS_IS_OK(status
)) {
5078 printf("TEST #4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname
, nt_errstr(status
));
5082 printf("TEST #4 open 2 of %s gave %s (correct error should be %s)\n", fname
, nt_errstr(status
), "sharing violation");
5084 status
= cli_close(cli1
, fnum1
);
5085 if (!NT_STATUS_IS_OK(status
)) {
5086 printf("TEST #4 close 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
5090 printf("non-io open test #4 passed.\n");
5092 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
5094 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
5096 status
= cli_ntcreate(cli1
, fname
, 0,
5097 DELETE_ACCESS
|FILE_READ_ATTRIBUTES
,
5098 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_DELETE
,
5099 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
5100 if (!NT_STATUS_IS_OK(status
)) {
5101 printf("TEST #5 open 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
5105 status
= cli_ntcreate(cli2
, fname
, 0,
5106 DELETE_ACCESS
|FILE_READ_ATTRIBUTES
,
5107 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_DELETE
,
5108 FILE_OPEN_IF
, 0, 0, &fnum2
);
5109 if (!NT_STATUS_IS_OK(status
)) {
5110 printf("TEST #5 open 2 of %s failed (%s)\n", fname
, nt_errstr(status
));
5114 status
= cli_close(cli1
, fnum1
);
5115 if (!NT_STATUS_IS_OK(status
)) {
5116 printf("TEST #5 close 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
5120 status
= cli_close(cli2
, fnum2
);
5121 if (!NT_STATUS_IS_OK(status
)) {
5122 printf("TEST #5 close 2 of %s failed (%s)\n", fname
, nt_errstr(status
));
5126 printf("non-io open test #5 passed.\n");
5128 printf("TEST #6 testing 1 non-io open, one io open\n");
5130 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
5132 status
= cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
,
5133 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
5134 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
5135 if (!NT_STATUS_IS_OK(status
)) {
5136 printf("TEST #6 open 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
5140 status
= cli_ntcreate(cli2
, fname
, 0, FILE_READ_ATTRIBUTES
,
5141 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
,
5142 FILE_OPEN_IF
, 0, 0, &fnum2
);
5143 if (!NT_STATUS_IS_OK(status
)) {
5144 printf("TEST #6 open 2 of %s failed (%s)\n", fname
, nt_errstr(status
));
5148 status
= cli_close(cli1
, fnum1
);
5149 if (!NT_STATUS_IS_OK(status
)) {
5150 printf("TEST #6 close 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
5154 status
= cli_close(cli2
, fnum2
);
5155 if (!NT_STATUS_IS_OK(status
)) {
5156 printf("TEST #6 close 2 of %s failed (%s)\n", fname
, nt_errstr(status
));
5160 printf("non-io open test #6 passed.\n");
5162 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
5164 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
5166 status
= cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
,
5167 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
5168 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
5169 if (!NT_STATUS_IS_OK(status
)) {
5170 printf("TEST #7 open 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
5174 status
= cli_ntcreate(cli2
, fname
, 0,
5175 DELETE_ACCESS
|FILE_READ_ATTRIBUTES
,
5176 FILE_ATTRIBUTE_NORMAL
,
5177 FILE_SHARE_READ
|FILE_SHARE_DELETE
,
5178 FILE_OPEN_IF
, 0, 0, &fnum2
);
5179 if (NT_STATUS_IS_OK(status
)) {
5180 printf("TEST #7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname
, nt_errstr(status
));
5184 printf("TEST #7 open 2 of %s gave %s (correct error should be %s)\n", fname
, nt_errstr(status
), "sharing violation");
5186 status
= cli_close(cli1
, fnum1
);
5187 if (!NT_STATUS_IS_OK(status
)) {
5188 printf("TEST #7 close 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
5192 printf("non-io open test #7 passed.\n");
5194 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
5196 printf("TEST #8 testing open without WRITE_ATTRIBUTES, updating close write time.\n");
5197 status
= cli_ntcreate(cli1
, fname
, 0, FILE_WRITE_DATA
, FILE_ATTRIBUTE_NORMAL
,
5198 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
5199 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
5200 if (!NT_STATUS_IS_OK(status
)) {
5201 printf("TEST #8 open of %s failed (%s)\n", fname
, nt_errstr(status
));
5206 /* Write to ensure we have to update the file time. */
5207 status
= cli_writeall(cli1
, fnum1
, 0, (const uint8_t *)"TEST DATA\n", 0, 10,
5209 if (!NT_STATUS_IS_OK(status
)) {
5210 printf("TEST #8 cli_write failed: %s\n", nt_errstr(status
));
5215 status
= cli_close(cli1
, fnum1
);
5216 if (!NT_STATUS_IS_OK(status
)) {
5217 printf("TEST #8 close of %s failed (%s)\n", fname
, nt_errstr(status
));
5223 if (!torture_close_connection(cli1
)) {
5226 if (!torture_close_connection(cli2
)) {
5233 NTSTATUS
torture_setup_unix_extensions(struct cli_state
*cli
)
5235 uint16 major
, minor
;
5236 uint32 caplow
, caphigh
;
5239 if (!SERVER_HAS_UNIX_CIFS(cli
)) {
5240 printf("Server doesn't support UNIX CIFS extensions.\n");
5241 return NT_STATUS_NOT_SUPPORTED
;
5244 status
= cli_unix_extensions_version(cli
, &major
, &minor
, &caplow
,
5246 if (!NT_STATUS_IS_OK(status
)) {
5247 printf("Server didn't return UNIX CIFS extensions: %s\n",
5252 status
= cli_set_unix_extensions_capabilities(cli
, major
, minor
,
5254 if (!NT_STATUS_IS_OK(status
)) {
5255 printf("Server doesn't support setting UNIX CIFS extensions: "
5256 "%s.\n", nt_errstr(status
));
5260 return NT_STATUS_OK
;
5264 Test POSIX open /mkdir calls.
5266 static bool run_simple_posix_open_test(int dummy
)
5268 static struct cli_state
*cli1
;
5269 const char *fname
= "posix:file";
5270 const char *hname
= "posix:hlink";
5271 const char *sname
= "posix:symlink";
5272 const char *dname
= "posix:dir";
5275 uint16_t fnum1
= (uint16_t)-1;
5276 SMB_STRUCT_STAT sbuf
;
5277 bool correct
= false;
5280 printf("Starting simple POSIX open test\n");
5282 if (!torture_open_connection(&cli1
, 0)) {
5286 cli_sockopt(cli1
, sockops
);
5288 status
= torture_setup_unix_extensions(cli1
);
5289 if (!NT_STATUS_IS_OK(status
)) {
5293 cli_setatr(cli1
, fname
, 0, 0);
5294 cli_posix_unlink(cli1
, fname
);
5295 cli_setatr(cli1
, dname
, 0, 0);
5296 cli_posix_rmdir(cli1
, dname
);
5297 cli_setatr(cli1
, hname
, 0, 0);
5298 cli_posix_unlink(cli1
, hname
);
5299 cli_setatr(cli1
, sname
, 0, 0);
5300 cli_posix_unlink(cli1
, sname
);
5302 /* Create a directory. */
5303 status
= cli_posix_mkdir(cli1
, dname
, 0777);
5304 if (!NT_STATUS_IS_OK(status
)) {
5305 printf("POSIX mkdir of %s failed (%s)\n", dname
, nt_errstr(status
));
5309 status
= cli_posix_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
,
5311 if (!NT_STATUS_IS_OK(status
)) {
5312 printf("POSIX create of %s failed (%s)\n", fname
, nt_errstr(status
));
5316 /* Test ftruncate - set file size. */
5317 status
= cli_ftruncate(cli1
, fnum1
, 1000);
5318 if (!NT_STATUS_IS_OK(status
)) {
5319 printf("ftruncate failed (%s)\n", nt_errstr(status
));
5323 /* Ensure st_size == 1000 */
5324 status
= cli_posix_stat(cli1
, fname
, &sbuf
);
5325 if (!NT_STATUS_IS_OK(status
)) {
5326 printf("stat failed (%s)\n", nt_errstr(status
));
5330 if (sbuf
.st_ex_size
!= 1000) {
5331 printf("ftruncate - stat size (%u) != 1000\n", (unsigned int)sbuf
.st_ex_size
);
5335 /* Test ftruncate - set file size back to zero. */
5336 status
= cli_ftruncate(cli1
, fnum1
, 0);
5337 if (!NT_STATUS_IS_OK(status
)) {
5338 printf("ftruncate failed (%s)\n", nt_errstr(status
));
5342 status
= cli_close(cli1
, fnum1
);
5343 if (!NT_STATUS_IS_OK(status
)) {
5344 printf("close failed (%s)\n", nt_errstr(status
));
5348 /* Now open the file again for read only. */
5349 status
= cli_posix_open(cli1
, fname
, O_RDONLY
, 0, &fnum1
);
5350 if (!NT_STATUS_IS_OK(status
)) {
5351 printf("POSIX open of %s failed (%s)\n", fname
, nt_errstr(status
));
5355 /* Now unlink while open. */
5356 status
= cli_posix_unlink(cli1
, fname
);
5357 if (!NT_STATUS_IS_OK(status
)) {
5358 printf("POSIX unlink of %s failed (%s)\n", fname
, nt_errstr(status
));
5362 status
= cli_close(cli1
, fnum1
);
5363 if (!NT_STATUS_IS_OK(status
)) {
5364 printf("close(2) failed (%s)\n", nt_errstr(status
));
5368 /* Ensure the file has gone. */
5369 status
= cli_posix_open(cli1
, fname
, O_RDONLY
, 0, &fnum1
);
5370 if (NT_STATUS_IS_OK(status
)) {
5371 printf("POSIX open of %s succeeded, should have been deleted.\n", fname
);
5375 /* Create again to test open with O_TRUNC. */
5376 status
= cli_posix_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, 0600, &fnum1
);
5377 if (!NT_STATUS_IS_OK(status
)) {
5378 printf("POSIX create of %s failed (%s)\n", fname
, nt_errstr(status
));
5382 /* Test ftruncate - set file size. */
5383 status
= cli_ftruncate(cli1
, fnum1
, 1000);
5384 if (!NT_STATUS_IS_OK(status
)) {
5385 printf("ftruncate failed (%s)\n", nt_errstr(status
));
5389 /* Ensure st_size == 1000 */
5390 status
= cli_posix_stat(cli1
, fname
, &sbuf
);
5391 if (!NT_STATUS_IS_OK(status
)) {
5392 printf("stat failed (%s)\n", nt_errstr(status
));
5396 if (sbuf
.st_ex_size
!= 1000) {
5397 printf("ftruncate - stat size (%u) != 1000\n", (unsigned int)sbuf
.st_ex_size
);
5401 status
= cli_close(cli1
, fnum1
);
5402 if (!NT_STATUS_IS_OK(status
)) {
5403 printf("close(2) failed (%s)\n", nt_errstr(status
));
5407 /* Re-open with O_TRUNC. */
5408 status
= cli_posix_open(cli1
, fname
, O_WRONLY
|O_TRUNC
, 0600, &fnum1
);
5409 if (!NT_STATUS_IS_OK(status
)) {
5410 printf("POSIX create of %s failed (%s)\n", fname
, nt_errstr(status
));
5414 /* Ensure st_size == 0 */
5415 status
= cli_posix_stat(cli1
, fname
, &sbuf
);
5416 if (!NT_STATUS_IS_OK(status
)) {
5417 printf("stat failed (%s)\n", nt_errstr(status
));
5421 if (sbuf
.st_ex_size
!= 0) {
5422 printf("O_TRUNC - stat size (%u) != 0\n", (unsigned int)sbuf
.st_ex_size
);
5426 status
= cli_close(cli1
, fnum1
);
5427 if (!NT_STATUS_IS_OK(status
)) {
5428 printf("close failed (%s)\n", nt_errstr(status
));
5432 status
= cli_posix_unlink(cli1
, fname
);
5433 if (!NT_STATUS_IS_OK(status
)) {
5434 printf("POSIX unlink of %s failed (%s)\n", fname
, nt_errstr(status
));
5438 status
= cli_posix_open(cli1
, dname
, O_RDONLY
, 0, &fnum1
);
5439 if (!NT_STATUS_IS_OK(status
)) {
5440 printf("POSIX open directory O_RDONLY of %s failed (%s)\n",
5441 dname
, nt_errstr(status
));
5445 cli_close(cli1
, fnum1
);
5447 /* What happens when we try and POSIX open a directory for write ? */
5448 status
= cli_posix_open(cli1
, dname
, O_RDWR
, 0, &fnum1
);
5449 if (NT_STATUS_IS_OK(status
)) {
5450 printf("POSIX open of directory %s succeeded, should have failed.\n", fname
);
5453 if (!check_both_error(__LINE__
, status
, ERRDOS
, EISDIR
,
5454 NT_STATUS_FILE_IS_A_DIRECTORY
)) {
5459 /* Create the file. */
5460 status
= cli_posix_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
,
5462 if (!NT_STATUS_IS_OK(status
)) {
5463 printf("POSIX create of %s failed (%s)\n", fname
, nt_errstr(status
));
5467 /* Write some data into it. */
5468 status
= cli_writeall(cli1
, fnum1
, 0, (const uint8_t *)"TEST DATA\n", 0, 10,
5470 if (!NT_STATUS_IS_OK(status
)) {
5471 printf("cli_write failed: %s\n", nt_errstr(status
));
5475 cli_close(cli1
, fnum1
);
5477 /* Now create a hardlink. */
5478 status
= cli_posix_hardlink(cli1
, fname
, hname
);
5479 if (!NT_STATUS_IS_OK(status
)) {
5480 printf("POSIX hardlink of %s failed (%s)\n", hname
, nt_errstr(status
));
5484 /* Now create a symlink. */
5485 status
= cli_posix_symlink(cli1
, fname
, sname
);
5486 if (!NT_STATUS_IS_OK(status
)) {
5487 printf("POSIX symlink of %s failed (%s)\n", sname
, nt_errstr(status
));
5491 /* Open the hardlink for read. */
5492 status
= cli_posix_open(cli1
, hname
, O_RDONLY
, 0, &fnum1
);
5493 if (!NT_STATUS_IS_OK(status
)) {
5494 printf("POSIX open of %s failed (%s)\n", hname
, nt_errstr(status
));
5498 if (cli_read_old(cli1
, fnum1
, buf
, 0, 10) != 10) {
5499 printf("POSIX read of %s failed (%s)\n", hname
, cli_errstr(cli1
));
5503 if (memcmp(buf
, "TEST DATA\n", 10)) {
5504 printf("invalid data read from hardlink\n");
5508 /* Do a POSIX lock/unlock. */
5509 status
= cli_posix_lock(cli1
, fnum1
, 0, 100, true, READ_LOCK
);
5510 if (!NT_STATUS_IS_OK(status
)) {
5511 printf("POSIX lock failed %s\n", nt_errstr(status
));
5515 /* Punch a hole in the locked area. */
5516 status
= cli_posix_unlock(cli1
, fnum1
, 10, 80);
5517 if (!NT_STATUS_IS_OK(status
)) {
5518 printf("POSIX unlock failed %s\n", nt_errstr(status
));
5522 cli_close(cli1
, fnum1
);
5524 /* Open the symlink for read - this should fail. A POSIX
5525 client should not be doing opens on a symlink. */
5526 status
= cli_posix_open(cli1
, sname
, O_RDONLY
, 0, &fnum1
);
5527 if (NT_STATUS_IS_OK(status
)) {
5528 printf("POSIX open of %s succeeded (should have failed)\n", sname
);
5531 if (!check_both_error(__LINE__
, status
, ERRDOS
, ERRbadpath
,
5532 NT_STATUS_OBJECT_PATH_NOT_FOUND
)) {
5533 printf("POSIX open of %s should have failed "
5534 "with NT_STATUS_OBJECT_PATH_NOT_FOUND, "
5535 "failed with %s instead.\n",
5536 sname
, nt_errstr(status
));
5541 status
= cli_posix_readlink(cli1
, sname
, namebuf
, sizeof(namebuf
));
5542 if (!NT_STATUS_IS_OK(status
)) {
5543 printf("POSIX readlink on %s failed (%s)\n", sname
, nt_errstr(status
));
5547 if (strcmp(namebuf
, fname
) != 0) {
5548 printf("POSIX readlink on %s failed to match name %s (read %s)\n",
5549 sname
, fname
, namebuf
);
5553 status
= cli_posix_rmdir(cli1
, dname
);
5554 if (!NT_STATUS_IS_OK(status
)) {
5555 printf("POSIX rmdir failed (%s)\n", nt_errstr(status
));
5559 printf("Simple POSIX open test passed\n");
5564 if (fnum1
!= (uint16_t)-1) {
5565 cli_close(cli1
, fnum1
);
5566 fnum1
= (uint16_t)-1;
5569 cli_setatr(cli1
, sname
, 0, 0);
5570 cli_posix_unlink(cli1
, sname
);
5571 cli_setatr(cli1
, hname
, 0, 0);
5572 cli_posix_unlink(cli1
, hname
);
5573 cli_setatr(cli1
, fname
, 0, 0);
5574 cli_posix_unlink(cli1
, fname
);
5575 cli_setatr(cli1
, dname
, 0, 0);
5576 cli_posix_rmdir(cli1
, dname
);
5578 if (!torture_close_connection(cli1
)) {
5586 static uint32 open_attrs_table
[] = {
5587 FILE_ATTRIBUTE_NORMAL
,
5588 FILE_ATTRIBUTE_ARCHIVE
,
5589 FILE_ATTRIBUTE_READONLY
,
5590 FILE_ATTRIBUTE_HIDDEN
,
5591 FILE_ATTRIBUTE_SYSTEM
,
5593 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
,
5594 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
,
5595 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
,
5596 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
,
5597 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
,
5598 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
,
5600 FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
,
5601 FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
,
5602 FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
,
5603 FILE_ATTRIBUTE_HIDDEN
,FILE_ATTRIBUTE_SYSTEM
,
5606 struct trunc_open_results
{
5613 static struct trunc_open_results attr_results
[] = {
5614 { 0, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_ARCHIVE
},
5615 { 1, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_ARCHIVE
},
5616 { 2, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_READONLY
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
},
5617 { 16, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_ARCHIVE
},
5618 { 17, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_ARCHIVE
},
5619 { 18, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_READONLY
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
},
5620 { 51, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
5621 { 54, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
5622 { 56, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
},
5623 { 68, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
5624 { 71, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
5625 { 73, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
},
5626 { 99, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_HIDDEN
,FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
5627 { 102, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
5628 { 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
},
5629 { 116, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
5630 { 119, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
5631 { 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
},
5632 { 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
},
5633 { 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
},
5634 { 227, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
5635 { 230, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
5636 { 232, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
},
5637 { 244, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
5638 { 247, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
5639 { 249, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
}
5642 static bool run_openattrtest(int dummy
)
5644 static struct cli_state
*cli1
;
5645 const char *fname
= "\\openattr.file";
5647 bool correct
= True
;
5649 unsigned int i
, j
, k
, l
;
5652 printf("starting open attr test\n");
5654 if (!torture_open_connection(&cli1
, 0)) {
5658 cli_sockopt(cli1
, sockops
);
5660 for (k
= 0, i
= 0; i
< sizeof(open_attrs_table
)/sizeof(uint32
); i
++) {
5661 cli_setatr(cli1
, fname
, 0, 0);
5662 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
5664 status
= cli_ntcreate(cli1
, fname
, 0, FILE_WRITE_DATA
,
5665 open_attrs_table
[i
], FILE_SHARE_NONE
,
5666 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
5667 if (!NT_STATUS_IS_OK(status
)) {
5668 printf("open %d (1) of %s failed (%s)\n", i
, fname
, nt_errstr(status
));
5672 status
= cli_close(cli1
, fnum1
);
5673 if (!NT_STATUS_IS_OK(status
)) {
5674 printf("close %d (1) of %s failed (%s)\n", i
, fname
, nt_errstr(status
));
5678 for (j
= 0; j
< sizeof(open_attrs_table
)/sizeof(uint32
); j
++) {
5679 status
= cli_ntcreate(cli1
, fname
, 0,
5680 FILE_READ_DATA
|FILE_WRITE_DATA
,
5681 open_attrs_table
[j
],
5682 FILE_SHARE_NONE
, FILE_OVERWRITE
,
5684 if (!NT_STATUS_IS_OK(status
)) {
5685 for (l
= 0; l
< sizeof(attr_results
)/sizeof(struct trunc_open_results
); l
++) {
5686 if (attr_results
[l
].num
== k
) {
5687 printf("[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(0x%x:%s)\n",
5688 k
, open_attrs_table
[i
],
5689 open_attrs_table
[j
],
5690 fname
, NT_STATUS_V(status
), nt_errstr(status
));
5695 if (!NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
)) {
5696 printf("[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s\n",
5697 k
, open_attrs_table
[i
], open_attrs_table
[j
],
5702 printf("[%d] trunc open 0x%x -> 0x%x failed\n", k
, open_attrs_table
[i
], open_attrs_table
[j
]);
5708 status
= cli_close(cli1
, fnum1
);
5709 if (!NT_STATUS_IS_OK(status
)) {
5710 printf("close %d (2) of %s failed (%s)\n", j
, fname
, nt_errstr(status
));
5714 status
= cli_getatr(cli1
, fname
, &attr
, NULL
, NULL
);
5715 if (!NT_STATUS_IS_OK(status
)) {
5716 printf("getatr(2) failed (%s)\n", nt_errstr(status
));
5721 printf("[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n",
5722 k
, open_attrs_table
[i
], open_attrs_table
[j
], attr
);
5725 for (l
= 0; l
< sizeof(attr_results
)/sizeof(struct trunc_open_results
); l
++) {
5726 if (attr_results
[l
].num
== k
) {
5727 if (attr
!= attr_results
[l
].result_attr
||
5728 open_attrs_table
[i
] != attr_results
[l
].init_attr
||
5729 open_attrs_table
[j
] != attr_results
[l
].trunc_attr
) {
5730 printf("getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x\n",
5731 open_attrs_table
[i
],
5732 open_attrs_table
[j
],
5734 attr_results
[l
].result_attr
);
5744 cli_setatr(cli1
, fname
, 0, 0);
5745 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
5747 printf("open attr test %s.\n", correct
? "passed" : "failed");
5749 if (!torture_close_connection(cli1
)) {
5755 static NTSTATUS
list_fn(const char *mnt
, struct file_info
*finfo
,
5756 const char *name
, void *state
)
5758 int *matched
= (int *)state
;
5759 if (matched
!= NULL
) {
5762 return NT_STATUS_OK
;
5766 test directory listing speed
5768 static bool run_dirtest(int dummy
)
5771 static struct cli_state
*cli
;
5773 struct timeval core_start
;
5774 bool correct
= True
;
5777 printf("starting directory test\n");
5779 if (!torture_open_connection(&cli
, 0)) {
5783 cli_sockopt(cli
, sockops
);
5786 for (i
=0;i
<torture_numops
;i
++) {
5788 slprintf(fname
, sizeof(fname
), "\\%x", (int)random());
5789 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
, O_RDWR
|O_CREAT
, DENY_NONE
, &fnum
))) {
5790 fprintf(stderr
,"Failed to open %s\n", fname
);
5793 cli_close(cli
, fnum
);
5796 core_start
= timeval_current();
5799 cli_list(cli
, "a*.*", 0, list_fn
, &matched
);
5800 printf("Matched %d\n", matched
);
5803 cli_list(cli
, "b*.*", 0, list_fn
, &matched
);
5804 printf("Matched %d\n", matched
);
5807 cli_list(cli
, "xyzabc", 0, list_fn
, &matched
);
5808 printf("Matched %d\n", matched
);
5810 printf("dirtest core %g seconds\n", timeval_elapsed(&core_start
));
5813 for (i
=0;i
<torture_numops
;i
++) {
5815 slprintf(fname
, sizeof(fname
), "\\%x", (int)random());
5816 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
5819 if (!torture_close_connection(cli
)) {
5823 printf("finished dirtest\n");
5828 static NTSTATUS
del_fn(const char *mnt
, struct file_info
*finfo
, const char *mask
,
5831 struct cli_state
*pcli
= (struct cli_state
*)state
;
5833 slprintf(fname
, sizeof(fname
), "\\LISTDIR\\%s", finfo
->name
);
5835 if (strcmp(finfo
->name
, ".") == 0 || strcmp(finfo
->name
, "..") == 0)
5836 return NT_STATUS_OK
;
5838 if (finfo
->mode
& FILE_ATTRIBUTE_DIRECTORY
) {
5839 if (!NT_STATUS_IS_OK(cli_rmdir(pcli
, fname
)))
5840 printf("del_fn: failed to rmdir %s\n,", fname
);
5842 if (!NT_STATUS_IS_OK(cli_unlink(pcli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
)))
5843 printf("del_fn: failed to unlink %s\n,", fname
);
5845 return NT_STATUS_OK
;
5850 sees what IOCTLs are supported
5852 bool torture_ioctl_test(int dummy
)
5854 static struct cli_state
*cli
;
5855 uint16_t device
, function
;
5857 const char *fname
= "\\ioctl.dat";
5861 if (!torture_open_connection(&cli
, 0)) {
5865 printf("starting ioctl test\n");
5867 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
5869 status
= cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum
);
5870 if (!NT_STATUS_IS_OK(status
)) {
5871 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
5875 status
= cli_raw_ioctl(cli
, fnum
, 0x2d0000 | (0x0420<<2), &blob
);
5876 printf("ioctl device info: %s\n", nt_errstr(status
));
5878 status
= cli_raw_ioctl(cli
, fnum
, IOCTL_QUERY_JOB_INFO
, &blob
);
5879 printf("ioctl job info: %s\n", nt_errstr(status
));
5881 for (device
=0;device
<0x100;device
++) {
5882 printf("ioctl test with device = 0x%x\n", device
);
5883 for (function
=0;function
<0x100;function
++) {
5884 uint32 code
= (device
<<16) | function
;
5886 status
= cli_raw_ioctl(cli
, fnum
, code
, &blob
);
5888 if (NT_STATUS_IS_OK(status
)) {
5889 printf("ioctl 0x%x OK : %d bytes\n", (int)code
,
5891 data_blob_free(&blob
);
5896 if (!torture_close_connection(cli
)) {
5905 tries varients of chkpath
5907 bool torture_chkpath_test(int dummy
)
5909 static struct cli_state
*cli
;
5914 if (!torture_open_connection(&cli
, 0)) {
5918 printf("starting chkpath test\n");
5920 /* cleanup from an old run */
5921 cli_rmdir(cli
, "\\chkpath.dir\\dir2");
5922 cli_unlink(cli
, "\\chkpath.dir\\*", FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
5923 cli_rmdir(cli
, "\\chkpath.dir");
5925 status
= cli_mkdir(cli
, "\\chkpath.dir");
5926 if (!NT_STATUS_IS_OK(status
)) {
5927 printf("mkdir1 failed : %s\n", nt_errstr(status
));
5931 status
= cli_mkdir(cli
, "\\chkpath.dir\\dir2");
5932 if (!NT_STATUS_IS_OK(status
)) {
5933 printf("mkdir2 failed : %s\n", nt_errstr(status
));
5937 status
= cli_open(cli
, "\\chkpath.dir\\foo.txt", O_RDWR
|O_CREAT
|O_EXCL
,
5939 if (!NT_STATUS_IS_OK(status
)) {
5940 printf("open1 failed (%s)\n", nt_errstr(status
));
5943 cli_close(cli
, fnum
);
5945 status
= cli_chkpath(cli
, "\\chkpath.dir");
5946 if (!NT_STATUS_IS_OK(status
)) {
5947 printf("chkpath1 failed: %s\n", nt_errstr(status
));
5951 status
= cli_chkpath(cli
, "\\chkpath.dir\\dir2");
5952 if (!NT_STATUS_IS_OK(status
)) {
5953 printf("chkpath2 failed: %s\n", nt_errstr(status
));
5957 status
= cli_chkpath(cli
, "\\chkpath.dir\\foo.txt");
5958 if (!NT_STATUS_IS_OK(status
)) {
5959 ret
= check_error(__LINE__
, cli
, ERRDOS
, ERRbadpath
,
5960 NT_STATUS_NOT_A_DIRECTORY
);
5962 printf("* chkpath on a file should fail\n");
5966 if (!NT_STATUS_IS_OK(cli_chkpath(cli
, "\\chkpath.dir\\bar.txt"))) {
5967 ret
= check_error(__LINE__
, cli
, ERRDOS
, ERRbadfile
,
5968 NT_STATUS_OBJECT_NAME_NOT_FOUND
);
5970 printf("* chkpath on a non existant file should fail\n");
5974 if (!NT_STATUS_IS_OK(cli_chkpath(cli
, "\\chkpath.dir\\dirxx\\bar.txt"))) {
5975 ret
= check_error(__LINE__
, cli
, ERRDOS
, ERRbadpath
,
5976 NT_STATUS_OBJECT_PATH_NOT_FOUND
);
5978 printf("* chkpath on a non existent component should fail\n");
5982 cli_rmdir(cli
, "\\chkpath.dir\\dir2");
5983 cli_unlink(cli
, "\\chkpath.dir\\*", FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
5984 cli_rmdir(cli
, "\\chkpath.dir");
5986 if (!torture_close_connection(cli
)) {
5993 static bool run_eatest(int dummy
)
5995 static struct cli_state
*cli
;
5996 const char *fname
= "\\eatest.txt";
5997 bool correct
= True
;
6001 struct ea_struct
*ea_list
= NULL
;
6002 TALLOC_CTX
*mem_ctx
= talloc_init("eatest");
6005 printf("starting eatest\n");
6007 if (!torture_open_connection(&cli
, 0)) {
6008 talloc_destroy(mem_ctx
);
6012 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
6014 status
= cli_ntcreate(cli
, fname
, 0,
6015 FIRST_DESIRED_ACCESS
, FILE_ATTRIBUTE_ARCHIVE
,
6016 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
,
6018 if (!NT_STATUS_IS_OK(status
)) {
6019 printf("open failed - %s\n", nt_errstr(status
));
6020 talloc_destroy(mem_ctx
);
6024 for (i
= 0; i
< 10; i
++) {
6025 fstring ea_name
, ea_val
;
6027 slprintf(ea_name
, sizeof(ea_name
), "EA_%d", i
);
6028 memset(ea_val
, (char)i
+1, i
+1);
6029 status
= cli_set_ea_fnum(cli
, fnum
, ea_name
, ea_val
, i
+1);
6030 if (!NT_STATUS_IS_OK(status
)) {
6031 printf("ea_set of name %s failed - %s\n", ea_name
,
6033 talloc_destroy(mem_ctx
);
6038 cli_close(cli
, fnum
);
6039 for (i
= 0; i
< 10; i
++) {
6040 fstring ea_name
, ea_val
;
6042 slprintf(ea_name
, sizeof(ea_name
), "EA_%d", i
+10);
6043 memset(ea_val
, (char)i
+1, i
+1);
6044 status
= cli_set_ea_path(cli
, fname
, ea_name
, ea_val
, i
+1);
6045 if (!NT_STATUS_IS_OK(status
)) {
6046 printf("ea_set of name %s failed - %s\n", ea_name
,
6048 talloc_destroy(mem_ctx
);
6053 status
= cli_get_ea_list_path(cli
, fname
, mem_ctx
, &num_eas
, &ea_list
);
6054 if (!NT_STATUS_IS_OK(status
)) {
6055 printf("ea_get list failed - %s\n", nt_errstr(status
));
6059 printf("num_eas = %d\n", (int)num_eas
);
6061 if (num_eas
!= 20) {
6062 printf("Should be 20 EA's stored... failing.\n");
6066 for (i
= 0; i
< num_eas
; i
++) {
6067 printf("%d: ea_name = %s. Val = ", i
, ea_list
[i
].name
);
6068 dump_data(0, ea_list
[i
].value
.data
,
6069 ea_list
[i
].value
.length
);
6072 /* Setting EA's to zero length deletes them. Test this */
6073 printf("Now deleting all EA's - case indepenent....\n");
6076 cli_set_ea_path(cli
, fname
, "", "", 0);
6078 for (i
= 0; i
< 20; i
++) {
6080 slprintf(ea_name
, sizeof(ea_name
), "ea_%d", i
);
6081 status
= cli_set_ea_path(cli
, fname
, ea_name
, "", 0);
6082 if (!NT_STATUS_IS_OK(status
)) {
6083 printf("ea_set of name %s failed - %s\n", ea_name
,
6085 talloc_destroy(mem_ctx
);
6091 status
= cli_get_ea_list_path(cli
, fname
, mem_ctx
, &num_eas
, &ea_list
);
6092 if (!NT_STATUS_IS_OK(status
)) {
6093 printf("ea_get list failed - %s\n", nt_errstr(status
));
6097 printf("num_eas = %d\n", (int)num_eas
);
6098 for (i
= 0; i
< num_eas
; i
++) {
6099 printf("%d: ea_name = %s. Val = ", i
, ea_list
[i
].name
);
6100 dump_data(0, ea_list
[i
].value
.data
,
6101 ea_list
[i
].value
.length
);
6105 printf("deleting EA's failed.\n");
6109 /* Try and delete a non existant EA. */
6110 status
= cli_set_ea_path(cli
, fname
, "foo", "", 0);
6111 if (!NT_STATUS_IS_OK(status
)) {
6112 printf("deleting non-existant EA 'foo' should succeed. %s\n",
6117 talloc_destroy(mem_ctx
);
6118 if (!torture_close_connection(cli
)) {
6125 static bool run_dirtest1(int dummy
)
6128 static struct cli_state
*cli
;
6131 bool correct
= True
;
6133 printf("starting directory test\n");
6135 if (!torture_open_connection(&cli
, 0)) {
6139 cli_sockopt(cli
, sockops
);
6141 cli_list(cli
, "\\LISTDIR\\*", 0, del_fn
, cli
);
6142 cli_list(cli
, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY
, del_fn
, cli
);
6143 cli_rmdir(cli
, "\\LISTDIR");
6144 cli_mkdir(cli
, "\\LISTDIR");
6146 /* Create 1000 files and 1000 directories. */
6147 for (i
=0;i
<1000;i
++) {
6149 slprintf(fname
, sizeof(fname
), "\\LISTDIR\\f%d", i
);
6150 if (!NT_STATUS_IS_OK(cli_ntcreate(cli
, fname
, 0, GENERIC_ALL_ACCESS
, FILE_ATTRIBUTE_ARCHIVE
,
6151 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OVERWRITE_IF
, 0, 0, &fnum
))) {
6152 fprintf(stderr
,"Failed to open %s\n", fname
);
6155 cli_close(cli
, fnum
);
6157 for (i
=0;i
<1000;i
++) {
6159 slprintf(fname
, sizeof(fname
), "\\LISTDIR\\d%d", i
);
6160 if (!NT_STATUS_IS_OK(cli_mkdir(cli
, fname
))) {
6161 fprintf(stderr
,"Failed to open %s\n", fname
);
6166 /* Now ensure that doing an old list sees both files and directories. */
6168 cli_list_old(cli
, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY
, list_fn
, &num_seen
);
6169 printf("num_seen = %d\n", num_seen
);
6170 /* We should see 100 files + 1000 directories + . and .. */
6171 if (num_seen
!= 2002)
6174 /* Ensure if we have the "must have" bits we only see the
6178 cli_list_old(cli
, "\\LISTDIR\\*", (FILE_ATTRIBUTE_DIRECTORY
<<8)|FILE_ATTRIBUTE_DIRECTORY
, list_fn
, &num_seen
);
6179 printf("num_seen = %d\n", num_seen
);
6180 if (num_seen
!= 1002)
6184 cli_list_old(cli
, "\\LISTDIR\\*", (FILE_ATTRIBUTE_ARCHIVE
<<8)|FILE_ATTRIBUTE_DIRECTORY
, list_fn
, &num_seen
);
6185 printf("num_seen = %d\n", num_seen
);
6186 if (num_seen
!= 1000)
6189 /* Delete everything. */
6190 cli_list(cli
, "\\LISTDIR\\*", 0, del_fn
, cli
);
6191 cli_list(cli
, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY
, del_fn
, cli
);
6192 cli_rmdir(cli
, "\\LISTDIR");
6195 printf("Matched %d\n", cli_list(cli
, "a*.*", 0, list_fn
, NULL
));
6196 printf("Matched %d\n", cli_list(cli
, "b*.*", 0, list_fn
, NULL
));
6197 printf("Matched %d\n", cli_list(cli
, "xyzabc", 0, list_fn
, NULL
));
6200 if (!torture_close_connection(cli
)) {
6204 printf("finished dirtest1\n");
6209 static bool run_error_map_extract(int dummy
) {
6211 static struct cli_state
*c_dos
;
6212 static struct cli_state
*c_nt
;
6224 /* NT-Error connection */
6226 if (!(c_nt
= open_nbt_connection())) {
6230 c_nt
->use_spnego
= False
;
6232 status
= cli_negprot(c_nt
);
6234 if (!NT_STATUS_IS_OK(status
)) {
6235 printf("%s rejected the NT-error negprot (%s)\n", host
,
6241 status
= cli_session_setup(c_nt
, "", "", 0, "", 0, workgroup
);
6242 if (!NT_STATUS_IS_OK(status
)) {
6243 printf("%s rejected the NT-error initial session setup (%s)\n",host
, nt_errstr(status
));
6247 /* DOS-Error connection */
6249 if (!(c_dos
= open_nbt_connection())) {
6253 c_dos
->use_spnego
= False
;
6254 c_dos
->force_dos_errors
= True
;
6256 status
= cli_negprot(c_dos
);
6257 if (!NT_STATUS_IS_OK(status
)) {
6258 printf("%s rejected the DOS-error negprot (%s)\n", host
,
6260 cli_shutdown(c_dos
);
6264 status
= cli_session_setup(c_dos
, "", "", 0, "", 0, workgroup
);
6265 if (!NT_STATUS_IS_OK(status
)) {
6266 printf("%s rejected the DOS-error initial session setup (%s)\n",
6267 host
, nt_errstr(status
));
6271 for (error
=(0xc0000000 | 0x1); error
< (0xc0000000| 0xFFF); error
++) {
6272 fstr_sprintf(user
, "%X", error
);
6274 status
= cli_session_setup(c_nt
, user
,
6275 password
, strlen(password
),
6276 password
, strlen(password
),
6278 if (NT_STATUS_IS_OK(status
)) {
6279 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
6282 /* Case #1: 32-bit NT errors */
6283 if (cli_is_nt_error(c_nt
)) {
6284 nt_status
= cli_nt_error(c_nt
);
6286 printf("/** Dos error on NT connection! (%s) */\n",
6288 nt_status
= NT_STATUS(0xc0000000);
6291 status
= cli_session_setup(c_dos
, user
,
6292 password
, strlen(password
),
6293 password
, strlen(password
),
6295 if (NT_STATUS_IS_OK(status
)) {
6296 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
6299 /* Case #1: 32-bit NT errors */
6300 if (!cli_is_dos_error(c_dos
)) {
6301 printf("/** NT error on DOS connection! (%s) */\n",
6303 errnum
= errclass
= 0;
6305 cli_dos_error(c_dos
, &errclass
, &errnum
);
6308 if (NT_STATUS_V(nt_status
) != error
) {
6309 printf("/*\t{ This NT error code was 'sqashed'\n\t from %s to %s \n\t during the session setup }\n*/\n",
6310 get_nt_error_c_code(talloc_tos(), NT_STATUS(error
)),
6311 get_nt_error_c_code(talloc_tos(), nt_status
));
6314 printf("\t{%s,\t%s,\t%s},\n",
6315 smb_dos_err_class(errclass
),
6316 smb_dos_err_name(errclass
, errnum
),
6317 get_nt_error_c_code(talloc_tos(), NT_STATUS(error
)));
6322 static bool run_sesssetup_bench(int dummy
)
6324 static struct cli_state
*c
;
6325 const char *fname
= "\\file.dat";
6330 if (!torture_open_connection(&c
, 0)) {
6334 status
= cli_ntcreate(c
, fname
, 0, GENERIC_ALL_ACCESS
|DELETE_ACCESS
,
6335 FILE_ATTRIBUTE_NORMAL
, 0, FILE_OVERWRITE_IF
,
6336 FILE_DELETE_ON_CLOSE
, 0, &fnum
);
6337 if (!NT_STATUS_IS_OK(status
)) {
6338 d_printf("open %s failed: %s\n", fname
, nt_errstr(status
));
6342 for (i
=0; i
<torture_numops
; i
++) {
6343 status
= cli_session_setup(
6345 password
, strlen(password
),
6346 password
, strlen(password
),
6348 if (!NT_STATUS_IS_OK(status
)) {
6349 d_printf("(%s) cli_session_setup failed: %s\n",
6350 __location__
, nt_errstr(status
));
6354 d_printf("\r%d ", (int)c
->vuid
);
6356 status
= cli_ulogoff(c
);
6357 if (!NT_STATUS_IS_OK(status
)) {
6358 d_printf("(%s) cli_ulogoff failed: %s\n",
6359 __location__
, nt_errstr(status
));
6368 static bool subst_test(const char *str
, const char *user
, const char *domain
,
6369 uid_t uid
, gid_t gid
, const char *expected
)
6374 subst
= talloc_sub_specified(talloc_tos(), str
, user
, domain
, uid
, gid
);
6376 if (strcmp(subst
, expected
) != 0) {
6377 printf("sub_specified(%s, %s, %s, %d, %d) returned [%s], expected "
6378 "[%s]\n", str
, user
, domain
, (int)uid
, (int)gid
, subst
,
6387 static void chain1_open_completion(struct tevent_req
*req
)
6391 status
= cli_open_recv(req
, &fnum
);
6394 d_printf("cli_open_recv returned %s: %d\n",
6396 NT_STATUS_IS_OK(status
) ? fnum
: -1);
6399 static void chain1_write_completion(struct tevent_req
*req
)
6403 status
= cli_write_andx_recv(req
, &written
);
6406 d_printf("cli_write_andx_recv returned %s: %d\n",
6408 NT_STATUS_IS_OK(status
) ? (int)written
: -1);
6411 static void chain1_close_completion(struct tevent_req
*req
)
6414 bool *done
= (bool *)tevent_req_callback_data_void(req
);
6416 status
= cli_close_recv(req
);
6421 d_printf("cli_close returned %s\n", nt_errstr(status
));
6424 static bool run_chain1(int dummy
)
6426 struct cli_state
*cli1
;
6427 struct event_context
*evt
= event_context_init(NULL
);
6428 struct tevent_req
*reqs
[3], *smbreqs
[3];
6430 const char *str
= "foobar";
6433 printf("starting chain1 test\n");
6434 if (!torture_open_connection(&cli1
, 0)) {
6438 cli_sockopt(cli1
, sockops
);
6440 reqs
[0] = cli_open_create(talloc_tos(), evt
, cli1
, "\\test",
6441 O_CREAT
|O_RDWR
, 0, &smbreqs
[0]);
6442 if (reqs
[0] == NULL
) return false;
6443 tevent_req_set_callback(reqs
[0], chain1_open_completion
, NULL
);
6446 reqs
[1] = cli_write_andx_create(talloc_tos(), evt
, cli1
, 0, 0,
6447 (const uint8_t *)str
, 0, strlen(str
)+1,
6448 smbreqs
, 1, &smbreqs
[1]);
6449 if (reqs
[1] == NULL
) return false;
6450 tevent_req_set_callback(reqs
[1], chain1_write_completion
, NULL
);
6452 reqs
[2] = cli_close_create(talloc_tos(), evt
, cli1
, 0, &smbreqs
[2]);
6453 if (reqs
[2] == NULL
) return false;
6454 tevent_req_set_callback(reqs
[2], chain1_close_completion
, &done
);
6456 status
= cli_smb_chain_send(smbreqs
, ARRAY_SIZE(smbreqs
));
6457 if (!NT_STATUS_IS_OK(status
)) {
6462 event_loop_once(evt
);
6465 torture_close_connection(cli1
);
6469 static void chain2_sesssetup_completion(struct tevent_req
*req
)
6472 status
= cli_session_setup_guest_recv(req
);
6473 d_printf("sesssetup returned %s\n", nt_errstr(status
));
6476 static void chain2_tcon_completion(struct tevent_req
*req
)
6478 bool *done
= (bool *)tevent_req_callback_data_void(req
);
6480 status
= cli_tcon_andx_recv(req
);
6481 d_printf("tcon_and_x returned %s\n", nt_errstr(status
));
6485 static bool run_chain2(int dummy
)
6487 struct cli_state
*cli1
;
6488 struct event_context
*evt
= event_context_init(NULL
);
6489 struct tevent_req
*reqs
[2], *smbreqs
[2];
6493 printf("starting chain2 test\n");
6494 status
= cli_start_connection(&cli1
, lp_netbios_name(), host
, NULL
,
6495 port_to_use
, Undefined
, 0);
6496 if (!NT_STATUS_IS_OK(status
)) {
6500 cli_sockopt(cli1
, sockops
);
6502 reqs
[0] = cli_session_setup_guest_create(talloc_tos(), evt
, cli1
,
6504 if (reqs
[0] == NULL
) return false;
6505 tevent_req_set_callback(reqs
[0], chain2_sesssetup_completion
, NULL
);
6507 reqs
[1] = cli_tcon_andx_create(talloc_tos(), evt
, cli1
, "IPC$",
6508 "?????", NULL
, 0, &smbreqs
[1]);
6509 if (reqs
[1] == NULL
) return false;
6510 tevent_req_set_callback(reqs
[1], chain2_tcon_completion
, &done
);
6512 status
= cli_smb_chain_send(smbreqs
, ARRAY_SIZE(smbreqs
));
6513 if (!NT_STATUS_IS_OK(status
)) {
6518 event_loop_once(evt
);
6521 torture_close_connection(cli1
);
6526 struct torture_createdel_state
{
6527 struct tevent_context
*ev
;
6528 struct cli_state
*cli
;
6531 static void torture_createdel_created(struct tevent_req
*subreq
);
6532 static void torture_createdel_closed(struct tevent_req
*subreq
);
6534 static struct tevent_req
*torture_createdel_send(TALLOC_CTX
*mem_ctx
,
6535 struct tevent_context
*ev
,
6536 struct cli_state
*cli
,
6539 struct tevent_req
*req
, *subreq
;
6540 struct torture_createdel_state
*state
;
6542 req
= tevent_req_create(mem_ctx
, &state
,
6543 struct torture_createdel_state
);
6550 subreq
= cli_ntcreate_send(
6551 state
, ev
, cli
, name
, 0,
6552 FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
6553 FILE_ATTRIBUTE_NORMAL
,
6554 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
6555 FILE_OPEN_IF
, FILE_DELETE_ON_CLOSE
, 0);
6557 if (tevent_req_nomem(subreq
, req
)) {
6558 return tevent_req_post(req
, ev
);
6560 tevent_req_set_callback(subreq
, torture_createdel_created
, req
);
6564 static void torture_createdel_created(struct tevent_req
*subreq
)
6566 struct tevent_req
*req
= tevent_req_callback_data(
6567 subreq
, struct tevent_req
);
6568 struct torture_createdel_state
*state
= tevent_req_data(
6569 req
, struct torture_createdel_state
);
6573 status
= cli_ntcreate_recv(subreq
, &fnum
);
6574 TALLOC_FREE(subreq
);
6575 if (!NT_STATUS_IS_OK(status
)) {
6576 DEBUG(10, ("cli_ntcreate_recv returned %s\n",
6577 nt_errstr(status
)));
6578 tevent_req_nterror(req
, status
);
6582 subreq
= cli_close_send(state
, state
->ev
, state
->cli
, fnum
);
6583 if (tevent_req_nomem(subreq
, req
)) {
6586 tevent_req_set_callback(subreq
, torture_createdel_closed
, req
);
6589 static void torture_createdel_closed(struct tevent_req
*subreq
)
6591 struct tevent_req
*req
= tevent_req_callback_data(
6592 subreq
, struct tevent_req
);
6595 status
= cli_close_recv(subreq
);
6596 if (!NT_STATUS_IS_OK(status
)) {
6597 DEBUG(10, ("cli_close_recv returned %s\n", nt_errstr(status
)));
6598 tevent_req_nterror(req
, status
);
6601 tevent_req_done(req
);
6604 static NTSTATUS
torture_createdel_recv(struct tevent_req
*req
)
6606 return tevent_req_simple_recv_ntstatus(req
);
6609 struct torture_createdels_state
{
6610 struct tevent_context
*ev
;
6611 struct cli_state
*cli
;
6612 const char *base_name
;
6616 struct tevent_req
**reqs
;
6619 static void torture_createdels_done(struct tevent_req
*subreq
);
6621 static struct tevent_req
*torture_createdels_send(TALLOC_CTX
*mem_ctx
,
6622 struct tevent_context
*ev
,
6623 struct cli_state
*cli
,
6624 const char *base_name
,
6628 struct tevent_req
*req
;
6629 struct torture_createdels_state
*state
;
6632 req
= tevent_req_create(mem_ctx
, &state
,
6633 struct torture_createdels_state
);
6639 state
->base_name
= talloc_strdup(state
, base_name
);
6640 if (tevent_req_nomem(state
->base_name
, req
)) {
6641 return tevent_req_post(req
, ev
);
6643 state
->num_files
= MAX(num_parallel
, num_files
);
6645 state
->received
= 0;
6647 state
->reqs
= talloc_array(state
, struct tevent_req
*, num_parallel
);
6648 if (tevent_req_nomem(state
->reqs
, req
)) {
6649 return tevent_req_post(req
, ev
);
6652 for (i
=0; i
<num_parallel
; i
++) {
6655 name
= talloc_asprintf(state
, "%s%8.8d", state
->base_name
,
6657 if (tevent_req_nomem(name
, req
)) {
6658 return tevent_req_post(req
, ev
);
6660 state
->reqs
[i
] = torture_createdel_send(
6661 state
->reqs
, state
->ev
, state
->cli
, name
);
6662 if (tevent_req_nomem(state
->reqs
[i
], req
)) {
6663 return tevent_req_post(req
, ev
);
6665 name
= talloc_move(state
->reqs
[i
], &name
);
6666 tevent_req_set_callback(state
->reqs
[i
],
6667 torture_createdels_done
, req
);
6673 static void torture_createdels_done(struct tevent_req
*subreq
)
6675 struct tevent_req
*req
= tevent_req_callback_data(
6676 subreq
, struct tevent_req
);
6677 struct torture_createdels_state
*state
= tevent_req_data(
6678 req
, struct torture_createdels_state
);
6679 size_t num_parallel
= talloc_array_length(state
->reqs
);
6684 status
= torture_createdel_recv(subreq
);
6685 if (!NT_STATUS_IS_OK(status
)){
6686 DEBUG(10, ("torture_createdel_recv returned %s\n",
6687 nt_errstr(status
)));
6688 TALLOC_FREE(subreq
);
6689 tevent_req_nterror(req
, status
);
6693 for (i
=0; i
<num_parallel
; i
++) {
6694 if (subreq
== state
->reqs
[i
]) {
6698 if (i
== num_parallel
) {
6699 DEBUG(10, ("received something we did not send\n"));
6700 tevent_req_nterror(req
, NT_STATUS_INTERNAL_ERROR
);
6703 TALLOC_FREE(state
->reqs
[i
]);
6705 if (state
->sent
>= state
->num_files
) {
6706 tevent_req_done(req
);
6710 name
= talloc_asprintf(state
, "%s%8.8d", state
->base_name
,
6712 if (tevent_req_nomem(name
, req
)) {
6715 state
->reqs
[i
] = torture_createdel_send(state
->reqs
, state
->ev
,
6717 if (tevent_req_nomem(state
->reqs
[i
], req
)) {
6720 name
= talloc_move(state
->reqs
[i
], &name
);
6721 tevent_req_set_callback(state
->reqs
[i
], torture_createdels_done
, req
);
6725 static NTSTATUS
torture_createdels_recv(struct tevent_req
*req
)
6727 return tevent_req_simple_recv_ntstatus(req
);
6730 struct swallow_notify_state
{
6731 struct tevent_context
*ev
;
6732 struct cli_state
*cli
;
6734 uint32_t completion_filter
;
6736 bool (*fn
)(uint32_t action
, const char *name
, void *priv
);
6740 static void swallow_notify_done(struct tevent_req
*subreq
);
6742 static struct tevent_req
*swallow_notify_send(TALLOC_CTX
*mem_ctx
,
6743 struct tevent_context
*ev
,
6744 struct cli_state
*cli
,
6746 uint32_t completion_filter
,
6748 bool (*fn
)(uint32_t action
,
6753 struct tevent_req
*req
, *subreq
;
6754 struct swallow_notify_state
*state
;
6756 req
= tevent_req_create(mem_ctx
, &state
,
6757 struct swallow_notify_state
);
6764 state
->completion_filter
= completion_filter
;
6765 state
->recursive
= recursive
;
6769 subreq
= cli_notify_send(state
, state
->ev
, state
->cli
, state
->fnum
,
6770 0xffff, state
->completion_filter
,
6772 if (tevent_req_nomem(subreq
, req
)) {
6773 return tevent_req_post(req
, ev
);
6775 tevent_req_set_callback(subreq
, swallow_notify_done
, req
);
6779 static void swallow_notify_done(struct tevent_req
*subreq
)
6781 struct tevent_req
*req
= tevent_req_callback_data(
6782 subreq
, struct tevent_req
);
6783 struct swallow_notify_state
*state
= tevent_req_data(
6784 req
, struct swallow_notify_state
);
6786 uint32_t i
, num_changes
;
6787 struct notify_change
*changes
;
6789 status
= cli_notify_recv(subreq
, state
, &num_changes
, &changes
);
6790 TALLOC_FREE(subreq
);
6791 if (!NT_STATUS_IS_OK(status
)) {
6792 DEBUG(10, ("cli_notify_recv returned %s\n",
6793 nt_errstr(status
)));
6794 tevent_req_nterror(req
, status
);
6798 for (i
=0; i
<num_changes
; i
++) {
6799 state
->fn(changes
[i
].action
, changes
[i
].name
, state
->priv
);
6801 TALLOC_FREE(changes
);
6803 subreq
= cli_notify_send(state
, state
->ev
, state
->cli
, state
->fnum
,
6804 0xffff, state
->completion_filter
,
6806 if (tevent_req_nomem(subreq
, req
)) {
6809 tevent_req_set_callback(subreq
, swallow_notify_done
, req
);
6812 static bool print_notifies(uint32_t action
, const char *name
, void *priv
)
6814 if (DEBUGLEVEL
> 5) {
6815 d_printf("%d %s\n", (int)action
, name
);
6820 static void notify_bench_done(struct tevent_req
*req
)
6822 int *num_finished
= (int *)tevent_req_callback_data_void(req
);
6826 static bool run_notify_bench(int dummy
)
6828 const char *dname
= "\\notify-bench";
6829 struct tevent_context
*ev
;
6832 struct tevent_req
*req1
;
6833 struct tevent_req
*req2
= NULL
;
6834 int i
, num_unc_names
;
6835 int num_finished
= 0;
6837 printf("starting notify-bench test\n");
6839 if (use_multishare_conn
) {
6841 unc_list
= file_lines_load(multishare_conn_fname
,
6842 &num_unc_names
, 0, NULL
);
6843 if (!unc_list
|| num_unc_names
<= 0) {
6844 d_printf("Failed to load unc names list from '%s'\n",
6845 multishare_conn_fname
);
6848 TALLOC_FREE(unc_list
);
6853 ev
= tevent_context_init(talloc_tos());
6855 d_printf("tevent_context_init failed\n");
6859 for (i
=0; i
<num_unc_names
; i
++) {
6860 struct cli_state
*cli
;
6863 base_fname
= talloc_asprintf(talloc_tos(), "%s\\file%3.3d.",
6865 if (base_fname
== NULL
) {
6869 if (!torture_open_connection(&cli
, i
)) {
6873 status
= cli_ntcreate(cli
, dname
, 0,
6874 MAXIMUM_ALLOWED_ACCESS
,
6875 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
|
6877 FILE_OPEN_IF
, FILE_DIRECTORY_FILE
, 0,
6880 if (!NT_STATUS_IS_OK(status
)) {
6881 d_printf("Could not create %s: %s\n", dname
,
6886 req1
= swallow_notify_send(talloc_tos(), ev
, cli
, dnum
,
6887 FILE_NOTIFY_CHANGE_FILE_NAME
|
6888 FILE_NOTIFY_CHANGE_DIR_NAME
|
6889 FILE_NOTIFY_CHANGE_ATTRIBUTES
|
6890 FILE_NOTIFY_CHANGE_LAST_WRITE
,
6891 false, print_notifies
, NULL
);
6893 d_printf("Could not create notify request\n");
6897 req2
= torture_createdels_send(talloc_tos(), ev
, cli
,
6898 base_fname
, 10, torture_numops
);
6900 d_printf("Could not create createdels request\n");
6903 TALLOC_FREE(base_fname
);
6905 tevent_req_set_callback(req2
, notify_bench_done
,
6909 while (num_finished
< num_unc_names
) {
6911 ret
= tevent_loop_once(ev
);
6913 d_printf("tevent_loop_once failed\n");
6918 if (!tevent_req_poll(req2
, ev
)) {
6919 d_printf("tevent_req_poll failed\n");
6922 status
= torture_createdels_recv(req2
);
6923 d_printf("torture_createdels_recv returned %s\n", nt_errstr(status
));
6928 static bool run_mangle1(int dummy
)
6930 struct cli_state
*cli
;
6931 const char *fname
= "this_is_a_long_fname_to_be_mangled.txt";
6935 time_t change_time
, access_time
, write_time
;
6939 printf("starting mangle1 test\n");
6940 if (!torture_open_connection(&cli
, 0)) {
6944 cli_sockopt(cli
, sockops
);
6946 status
= cli_ntcreate(cli
, fname
, 0, GENERIC_ALL_ACCESS
|DELETE_ACCESS
,
6947 FILE_ATTRIBUTE_NORMAL
, 0, FILE_OVERWRITE_IF
,
6949 if (!NT_STATUS_IS_OK(status
)) {
6950 d_printf("open %s failed: %s\n", fname
, nt_errstr(status
));
6953 cli_close(cli
, fnum
);
6955 status
= cli_qpathinfo_alt_name(cli
, fname
, alt_name
);
6956 if (!NT_STATUS_IS_OK(status
)) {
6957 d_printf("cli_qpathinfo_alt_name failed: %s\n",
6961 d_printf("alt_name: %s\n", alt_name
);
6963 status
= cli_open(cli
, alt_name
, O_RDONLY
, DENY_NONE
, &fnum
);
6964 if (!NT_STATUS_IS_OK(status
)) {
6965 d_printf("cli_open(%s) failed: %s\n", alt_name
,
6969 cli_close(cli
, fnum
);
6971 status
= cli_qpathinfo1(cli
, alt_name
, &change_time
, &access_time
,
6972 &write_time
, &size
, &mode
);
6973 if (!NT_STATUS_IS_OK(status
)) {
6974 d_printf("cli_qpathinfo1(%s) failed: %s\n", alt_name
,
6982 static size_t null_source(uint8_t *buf
, size_t n
, void *priv
)
6984 size_t *to_pull
= (size_t *)priv
;
6985 size_t thistime
= *to_pull
;
6987 thistime
= MIN(thistime
, n
);
6988 if (thistime
== 0) {
6992 memset(buf
, 0, thistime
);
6993 *to_pull
-= thistime
;
6997 static bool run_windows_write(int dummy
)
6999 struct cli_state
*cli1
;
7003 const char *fname
= "\\writetest.txt";
7004 struct timeval start_time
;
7009 printf("starting windows_write test\n");
7010 if (!torture_open_connection(&cli1
, 0)) {
7014 status
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum
);
7015 if (!NT_STATUS_IS_OK(status
)) {
7016 printf("open failed (%s)\n", nt_errstr(status
));
7020 cli_sockopt(cli1
, sockops
);
7022 start_time
= timeval_current();
7024 for (i
=0; i
<torture_numops
; i
++) {
7026 off_t start
= i
* torture_blocksize
;
7027 size_t to_pull
= torture_blocksize
- 1;
7029 status
= cli_writeall(cli1
, fnum
, 0, &c
,
7030 start
+ torture_blocksize
- 1, 1, NULL
);
7031 if (!NT_STATUS_IS_OK(status
)) {
7032 printf("cli_write failed: %s\n", nt_errstr(status
));
7036 status
= cli_push(cli1
, fnum
, 0, i
* torture_blocksize
, torture_blocksize
,
7037 null_source
, &to_pull
);
7038 if (!NT_STATUS_IS_OK(status
)) {
7039 printf("cli_push returned: %s\n", nt_errstr(status
));
7044 seconds
= timeval_elapsed(&start_time
);
7045 kbytes
= (double)torture_blocksize
* torture_numops
;
7048 printf("Wrote %d kbytes in %.2f seconds: %d kb/sec\n", (int)kbytes
,
7049 (double)seconds
, (int)(kbytes
/seconds
));
7053 cli_close(cli1
, fnum
);
7054 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
7055 torture_close_connection(cli1
);
7059 static bool run_cli_echo(int dummy
)
7061 struct cli_state
*cli
;
7064 printf("starting cli_echo test\n");
7065 if (!torture_open_connection(&cli
, 0)) {
7068 cli_sockopt(cli
, sockops
);
7070 status
= cli_echo(cli
, 5, data_blob_const("hello", 5));
7072 d_printf("cli_echo returned %s\n", nt_errstr(status
));
7074 torture_close_connection(cli
);
7075 return NT_STATUS_IS_OK(status
);
7078 static bool run_uid_regression_test(int dummy
)
7080 static struct cli_state
*cli
;
7083 bool correct
= True
;
7086 printf("starting uid regression test\n");
7088 if (!torture_open_connection(&cli
, 0)) {
7092 cli_sockopt(cli
, sockops
);
7094 /* Ok - now save then logoff our current user. */
7095 old_vuid
= cli
->vuid
;
7097 status
= cli_ulogoff(cli
);
7098 if (!NT_STATUS_IS_OK(status
)) {
7099 d_printf("(%s) cli_ulogoff failed: %s\n",
7100 __location__
, nt_errstr(status
));
7105 cli
->vuid
= old_vuid
;
7107 /* Try an operation. */
7108 status
= cli_mkdir(cli
, "\\uid_reg_test");
7109 if (NT_STATUS_IS_OK(status
)) {
7110 d_printf("(%s) cli_mkdir succeeded\n",
7115 /* Should be bad uid. */
7116 if (!check_error(__LINE__
, cli
, ERRSRV
, ERRbaduid
,
7117 NT_STATUS_USER_SESSION_DELETED
)) {
7123 old_cnum
= cli_state_get_tid(cli
);
7125 /* Now try a SMBtdis with the invald vuid set to zero. */
7128 /* This should succeed. */
7129 status
= cli_tdis(cli
);
7131 if (NT_STATUS_IS_OK(status
)) {
7132 d_printf("First tdis with invalid vuid should succeed.\n");
7134 d_printf("First tdis failed (%s)\n", nt_errstr(status
));
7139 cli
->vuid
= old_vuid
;
7140 cli_state_set_tid(cli
, old_cnum
);
7142 /* This should fail. */
7143 status
= cli_tdis(cli
);
7144 if (NT_STATUS_IS_OK(status
)) {
7145 d_printf("Second tdis with invalid vuid should fail - succeeded instead !.\n");
7149 /* Should be bad tid. */
7150 if (!check_error(__LINE__
, cli
, ERRSRV
, ERRinvnid
,
7151 NT_STATUS_NETWORK_NAME_DELETED
)) {
7157 cli_rmdir(cli
, "\\uid_reg_test");
7166 static const char *illegal_chars
= "*\\/?<>|\":";
7167 static char force_shortname_chars
[] = " +,.[];=\177";
7169 static NTSTATUS
shortname_del_fn(const char *mnt
, struct file_info
*finfo
,
7170 const char *mask
, void *state
)
7172 struct cli_state
*pcli
= (struct cli_state
*)state
;
7174 NTSTATUS status
= NT_STATUS_OK
;
7176 slprintf(fname
, sizeof(fname
), "\\shortname\\%s", finfo
->name
);
7178 if (strcmp(finfo
->name
, ".") == 0 || strcmp(finfo
->name
, "..") == 0)
7179 return NT_STATUS_OK
;
7181 if (finfo
->mode
& FILE_ATTRIBUTE_DIRECTORY
) {
7182 status
= cli_rmdir(pcli
, fname
);
7183 if (!NT_STATUS_IS_OK(status
)) {
7184 printf("del_fn: failed to rmdir %s\n,", fname
);
7187 status
= cli_unlink(pcli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
7188 if (!NT_STATUS_IS_OK(status
)) {
7189 printf("del_fn: failed to unlink %s\n,", fname
);
7201 static NTSTATUS
shortname_list_fn(const char *mnt
, struct file_info
*finfo
,
7202 const char *name
, void *state
)
7204 struct sn_state
*s
= (struct sn_state
*)state
;
7208 printf("shortname list: i = %d, name = |%s|, shortname = |%s|\n",
7209 i
, finfo
->name
, finfo
->short_name
);
7212 if (strchr(force_shortname_chars
, i
)) {
7213 if (!finfo
->short_name
) {
7214 /* Shortname not created when it should be. */
7215 d_printf("(%s) ERROR: Shortname was not created for file %s containing %d\n",
7216 __location__
, finfo
->name
, i
);
7219 } else if (finfo
->short_name
){
7220 /* Shortname created when it should not be. */
7221 d_printf("(%s) ERROR: Shortname %s was created for file %s\n",
7222 __location__
, finfo
->short_name
, finfo
->name
);
7226 return NT_STATUS_OK
;
7229 static bool run_shortname_test(int dummy
)
7231 static struct cli_state
*cli
;
7232 bool correct
= True
;
7238 printf("starting shortname test\n");
7240 if (!torture_open_connection(&cli
, 0)) {
7244 cli_sockopt(cli
, sockops
);
7246 cli_list(cli
, "\\shortname\\*", 0, shortname_del_fn
, cli
);
7247 cli_list(cli
, "\\shortname\\*", FILE_ATTRIBUTE_DIRECTORY
, shortname_del_fn
, cli
);
7248 cli_rmdir(cli
, "\\shortname");
7250 status
= cli_mkdir(cli
, "\\shortname");
7251 if (!NT_STATUS_IS_OK(status
)) {
7252 d_printf("(%s) cli_mkdir of \\shortname failed: %s\n",
7253 __location__
, nt_errstr(status
));
7258 strlcpy(fname
, "\\shortname\\", sizeof(fname
));
7259 strlcat(fname
, "test .txt", sizeof(fname
));
7263 for (i
= 32; i
< 128; i
++) {
7264 uint16_t fnum
= (uint16_t)-1;
7268 if (strchr(illegal_chars
, i
)) {
7273 status
= cli_ntcreate(cli
, fname
, 0, GENERIC_ALL_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
7274 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OVERWRITE_IF
, 0, 0, &fnum
);
7275 if (!NT_STATUS_IS_OK(status
)) {
7276 d_printf("(%s) cli_nt_create of %s failed: %s\n",
7277 __location__
, fname
, nt_errstr(status
));
7281 cli_close(cli
, fnum
);
7284 status
= cli_list(cli
, "\\shortname\\test*.*", 0,
7285 shortname_list_fn
, &s
);
7286 if (s
.matched
!= 1) {
7287 d_printf("(%s) failed to list %s: %s\n",
7288 __location__
, fname
, nt_errstr(status
));
7293 status
= cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
7294 if (!NT_STATUS_IS_OK(status
)) {
7295 d_printf("(%s) failed to delete %s: %s\n",
7296 __location__
, fname
, nt_errstr(status
));
7309 cli_list(cli
, "\\shortname\\*", 0, shortname_del_fn
, cli
);
7310 cli_list(cli
, "\\shortname\\*", FILE_ATTRIBUTE_DIRECTORY
, shortname_del_fn
, cli
);
7311 cli_rmdir(cli
, "\\shortname");
7312 torture_close_connection(cli
);
7316 static void pagedsearch_cb(struct tevent_req
*req
)
7319 struct tldap_message
*msg
;
7322 rc
= tldap_search_paged_recv(req
, talloc_tos(), &msg
);
7323 if (rc
!= TLDAP_SUCCESS
) {
7324 d_printf("tldap_search_paged_recv failed: %s\n",
7325 tldap_err2string(rc
));
7328 if (tldap_msg_type(msg
) != TLDAP_RES_SEARCH_ENTRY
) {
7332 if (!tldap_entry_dn(msg
, &dn
)) {
7333 d_printf("tldap_entry_dn failed\n");
7336 d_printf("%s\n", dn
);
7340 static bool run_tldap(int dummy
)
7342 struct tldap_context
*ld
;
7345 struct sockaddr_storage addr
;
7346 struct tevent_context
*ev
;
7347 struct tevent_req
*req
;
7351 if (!resolve_name(host
, &addr
, 0, false)) {
7352 d_printf("could not find host %s\n", host
);
7355 status
= open_socket_out(&addr
, 389, 9999, &fd
);
7356 if (!NT_STATUS_IS_OK(status
)) {
7357 d_printf("open_socket_out failed: %s\n", nt_errstr(status
));
7361 ld
= tldap_context_create(talloc_tos(), fd
);
7364 d_printf("tldap_context_create failed\n");
7368 rc
= tldap_fetch_rootdse(ld
);
7369 if (rc
!= TLDAP_SUCCESS
) {
7370 d_printf("tldap_fetch_rootdse failed: %s\n",
7371 tldap_errstr(talloc_tos(), ld
, rc
));
7375 basedn
= tldap_talloc_single_attribute(
7376 tldap_rootdse(ld
), "defaultNamingContext", talloc_tos());
7377 if (basedn
== NULL
) {
7378 d_printf("no defaultNamingContext\n");
7381 d_printf("defaultNamingContext: %s\n", basedn
);
7383 ev
= tevent_context_init(talloc_tos());
7385 d_printf("tevent_context_init failed\n");
7389 req
= tldap_search_paged_send(talloc_tos(), ev
, ld
, basedn
,
7390 TLDAP_SCOPE_SUB
, "(objectclass=*)",
7392 NULL
, 0, NULL
, 0, 0, 0, 0, 5);
7394 d_printf("tldap_search_paged_send failed\n");
7397 tevent_req_set_callback(req
, pagedsearch_cb
, NULL
);
7399 tevent_req_poll(req
, ev
);
7403 /* test search filters against rootDSE */
7404 filter
= "(&(|(name=samba)(nextRid<=10000000)(usnChanged>=10)(samba~=ambas)(!(name=s*m*a)))"
7405 "(|(name:=samba)(name:dn:2.5.13.5:=samba)(:dn:2.5.13.5:=samba)(!(name=*samba))))";
7407 rc
= tldap_search(ld
, "", TLDAP_SCOPE_BASE
, filter
,
7408 NULL
, 0, 0, NULL
, 0, NULL
, 0, 0, 0, 0,
7409 talloc_tos(), NULL
, NULL
);
7410 if (rc
!= TLDAP_SUCCESS
) {
7411 d_printf("tldap_search with complex filter failed: %s\n",
7412 tldap_errstr(talloc_tos(), ld
, rc
));
7420 /* Torture test to ensure no regression of :
7421 https://bugzilla.samba.org/show_bug.cgi?id=7084
7424 static bool run_dir_createtime(int dummy
)
7426 struct cli_state
*cli
;
7427 const char *dname
= "\\testdir";
7428 const char *fname
= "\\testdir\\testfile";
7430 struct timespec create_time
;
7431 struct timespec create_time1
;
7435 if (!torture_open_connection(&cli
, 0)) {
7439 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
7440 cli_rmdir(cli
, dname
);
7442 status
= cli_mkdir(cli
, dname
);
7443 if (!NT_STATUS_IS_OK(status
)) {
7444 printf("mkdir failed: %s\n", nt_errstr(status
));
7448 status
= cli_qpathinfo2(cli
, dname
, &create_time
, NULL
, NULL
, NULL
,
7450 if (!NT_STATUS_IS_OK(status
)) {
7451 printf("cli_qpathinfo2 returned %s\n",
7456 /* Sleep 3 seconds, then create a file. */
7459 status
= cli_open(cli
, fname
, O_RDWR
| O_CREAT
| O_EXCL
,
7461 if (!NT_STATUS_IS_OK(status
)) {
7462 printf("cli_open failed: %s\n", nt_errstr(status
));
7466 status
= cli_qpathinfo2(cli
, dname
, &create_time1
, NULL
, NULL
, NULL
,
7468 if (!NT_STATUS_IS_OK(status
)) {
7469 printf("cli_qpathinfo2 (2) returned %s\n",
7474 if (timespec_compare(&create_time1
, &create_time
)) {
7475 printf("run_dir_createtime: create time was updated (error)\n");
7477 printf("run_dir_createtime: create time was not updated (correct)\n");
7483 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
7484 cli_rmdir(cli
, dname
);
7485 if (!torture_close_connection(cli
)) {
7492 static bool run_streamerror(int dummy
)
7494 struct cli_state
*cli
;
7495 const char *dname
= "\\testdir";
7496 const char *streamname
=
7497 "testdir:{4c8cc155-6c1e-11d1-8e41-00c04fb9386d}:$DATA";
7499 time_t change_time
, access_time
, write_time
;
7501 uint16_t mode
, fnum
;
7504 if (!torture_open_connection(&cli
, 0)) {
7508 cli_unlink(cli
, "\\testdir\\*", FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
7509 cli_rmdir(cli
, dname
);
7511 status
= cli_mkdir(cli
, dname
);
7512 if (!NT_STATUS_IS_OK(status
)) {
7513 printf("mkdir failed: %s\n", nt_errstr(status
));
7517 cli_qpathinfo1(cli
, streamname
, &change_time
, &access_time
, &write_time
,
7519 status
= cli_nt_error(cli
);
7521 if (!NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
7522 printf("pathinfo returned %s, expected "
7523 "NT_STATUS_OBJECT_NAME_NOT_FOUND\n",
7528 status
= cli_ntcreate(cli
, streamname
, 0x16,
7529 FILE_READ_DATA
|FILE_READ_EA
|
7530 FILE_READ_ATTRIBUTES
|READ_CONTROL_ACCESS
,
7531 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
,
7532 FILE_OPEN
, 0, 0, &fnum
);
7534 if (!NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
7535 printf("ntcreate returned %s, expected "
7536 "NT_STATUS_OBJECT_NAME_NOT_FOUND\n",
7542 cli_rmdir(cli
, dname
);
7546 static bool run_local_substitute(int dummy
)
7550 ok
&= subst_test("%U", "bla", "", -1, -1, "bla");
7551 ok
&= subst_test("%u%U", "bla", "", -1, -1, "blabla");
7552 ok
&= subst_test("%g", "", "", -1, -1, "NO_GROUP");
7553 ok
&= subst_test("%G", "", "", -1, -1, "NO_GROUP");
7554 ok
&= subst_test("%g", "", "", -1, 0, gidtoname(0));
7555 ok
&= subst_test("%G", "", "", -1, 0, gidtoname(0));
7556 ok
&= subst_test("%D%u", "u", "dom", -1, 0, "domu");
7557 ok
&= subst_test("%i %I", "", "", -1, -1, "0.0.0.0 0.0.0.0");
7559 /* Different captialization rules in sub_basic... */
7561 ok
&= (strcmp(talloc_sub_basic(talloc_tos(), "BLA", "dom", "%U%D"),
7567 static bool run_local_base64(int dummy
)
7572 for (i
=1; i
<2000; i
++) {
7573 DATA_BLOB blob1
, blob2
;
7576 blob1
.data
= talloc_array(talloc_tos(), uint8_t, i
);
7578 generate_random_buffer(blob1
.data
, blob1
.length
);
7580 b64
= base64_encode_data_blob(talloc_tos(), blob1
);
7582 d_fprintf(stderr
, "base64_encode_data_blob failed "
7583 "for %d bytes\n", i
);
7586 blob2
= base64_decode_data_blob(b64
);
7589 if (data_blob_cmp(&blob1
, &blob2
)) {
7590 d_fprintf(stderr
, "data_blob_cmp failed for %d "
7594 TALLOC_FREE(blob1
.data
);
7595 data_blob_free(&blob2
);
7600 static bool run_local_gencache(int dummy
)
7606 if (!gencache_set("foo", "bar", time(NULL
) + 1000)) {
7607 d_printf("%s: gencache_set() failed\n", __location__
);
7611 if (!gencache_get("foo", NULL
, NULL
)) {
7612 d_printf("%s: gencache_get() failed\n", __location__
);
7616 if (!gencache_get("foo", &val
, &tm
)) {
7617 d_printf("%s: gencache_get() failed\n", __location__
);
7621 if (strcmp(val
, "bar") != 0) {
7622 d_printf("%s: gencache_get() returned %s, expected %s\n",
7623 __location__
, val
, "bar");
7630 if (!gencache_del("foo")) {
7631 d_printf("%s: gencache_del() failed\n", __location__
);
7634 if (gencache_del("foo")) {
7635 d_printf("%s: second gencache_del() succeeded\n",
7640 if (gencache_get("foo", &val
, &tm
)) {
7641 d_printf("%s: gencache_get() on deleted entry "
7642 "succeeded\n", __location__
);
7646 blob
= data_blob_string_const_null("bar");
7647 tm
= time(NULL
) + 60;
7649 if (!gencache_set_data_blob("foo", &blob
, tm
)) {
7650 d_printf("%s: gencache_set_data_blob() failed\n", __location__
);
7654 if (!gencache_get_data_blob("foo", &blob
, NULL
, NULL
)) {
7655 d_printf("%s: gencache_get_data_blob() failed\n", __location__
);
7659 if (strcmp((const char *)blob
.data
, "bar") != 0) {
7660 d_printf("%s: gencache_get_data_blob() returned %s, expected %s\n",
7661 __location__
, (const char *)blob
.data
, "bar");
7662 data_blob_free(&blob
);
7666 data_blob_free(&blob
);
7668 if (!gencache_del("foo")) {
7669 d_printf("%s: gencache_del() failed\n", __location__
);
7672 if (gencache_del("foo")) {
7673 d_printf("%s: second gencache_del() succeeded\n",
7678 if (gencache_get_data_blob("foo", &blob
, NULL
, NULL
)) {
7679 d_printf("%s: gencache_get_data_blob() on deleted entry "
7680 "succeeded\n", __location__
);
7687 static bool rbt_testval(struct db_context
*db
, const char *key
,
7690 struct db_record
*rec
;
7691 TDB_DATA data
= string_tdb_data(value
);
7695 rec
= db
->fetch_locked(db
, db
, string_tdb_data(key
));
7697 d_fprintf(stderr
, "fetch_locked failed\n");
7700 status
= rec
->store(rec
, data
, 0);
7701 if (!NT_STATUS_IS_OK(status
)) {
7702 d_fprintf(stderr
, "store failed: %s\n", nt_errstr(status
));
7707 rec
= db
->fetch_locked(db
, db
, string_tdb_data(key
));
7709 d_fprintf(stderr
, "second fetch_locked failed\n");
7712 if ((rec
->value
.dsize
!= data
.dsize
)
7713 || (memcmp(rec
->value
.dptr
, data
.dptr
, data
.dsize
) != 0)) {
7714 d_fprintf(stderr
, "Got wrong data back\n");
7724 static bool run_local_rbtree(int dummy
)
7726 struct db_context
*db
;
7730 db
= db_open_rbt(NULL
);
7733 d_fprintf(stderr
, "db_open_rbt failed\n");
7737 for (i
=0; i
<1000; i
++) {
7740 if (asprintf(&key
, "key%ld", random()) == -1) {
7743 if (asprintf(&value
, "value%ld", random()) == -1) {
7748 if (!rbt_testval(db
, key
, value
)) {
7755 if (asprintf(&value
, "value%ld", random()) == -1) {
7760 if (!rbt_testval(db
, key
, value
)) {
7779 local test for character set functions
7781 This is a very simple test for the functionality in convert_string_error()
7783 static bool run_local_convert_string(int dummy
)
7785 TALLOC_CTX
*tmp_ctx
= talloc_new(NULL
);
7786 const char *test_strings
[2] = { "March", "M\303\244rz" };
7790 for (i
=0; i
<2; i
++) {
7791 const char *str
= test_strings
[i
];
7792 int len
= strlen(str
);
7793 size_t converted_size
;
7796 memset(dst
, 'X', sizeof(dst
));
7798 /* first try with real source length */
7799 ret
= convert_string_error(CH_UNIX
, CH_UTF8
,
7804 d_fprintf(stderr
, "Failed to convert '%s' to CH_DISPLAY\n", str
);
7808 if (converted_size
!= len
) {
7809 d_fprintf(stderr
, "Converted size of '%s' should be %d - got %d\n",
7810 str
, len
, (int)converted_size
);
7814 if (strncmp(str
, dst
, converted_size
) != 0) {
7815 d_fprintf(stderr
, "Expected '%s' to match '%s'\n", str
, dst
);
7819 if (strlen(str
) != converted_size
) {
7820 d_fprintf(stderr
, "Expected '%s' length %d - got %d\n", str
,
7821 (int)strlen(str
), (int)converted_size
);
7825 if (dst
[converted_size
] != 'X') {
7826 d_fprintf(stderr
, "Expected no termination of '%s'\n", dst
);
7830 /* now with srclen==-1, this causes the nul to be
7832 ret
= convert_string_error(CH_UNIX
, CH_UTF8
,
7837 d_fprintf(stderr
, "Failed to convert '%s' to CH_DISPLAY\n", str
);
7841 if (converted_size
!= len
+1) {
7842 d_fprintf(stderr
, "Converted size of '%s' should be %d - got %d\n",
7843 str
, len
, (int)converted_size
);
7847 if (strncmp(str
, dst
, converted_size
) != 0) {
7848 d_fprintf(stderr
, "Expected '%s' to match '%s'\n", str
, dst
);
7852 if (len
+1 != converted_size
) {
7853 d_fprintf(stderr
, "Expected '%s' length %d - got %d\n", str
,
7854 len
+1, (int)converted_size
);
7858 if (dst
[converted_size
] != 'X') {
7859 d_fprintf(stderr
, "Expected no termination of '%s'\n", dst
);
7866 TALLOC_FREE(tmp_ctx
);
7869 TALLOC_FREE(tmp_ctx
);
7874 struct talloc_dict_test
{
7878 static int talloc_dict_traverse_fn(DATA_BLOB key
, void *data
, void *priv
)
7880 int *count
= (int *)priv
;
7885 static bool run_local_talloc_dict(int dummy
)
7887 struct talloc_dict
*dict
;
7888 struct talloc_dict_test
*t
;
7891 dict
= talloc_dict_init(talloc_tos());
7896 t
= talloc(talloc_tos(), struct talloc_dict_test
);
7903 if (!talloc_dict_set(dict
, data_blob_const(&key
, sizeof(key
)), t
)) {
7908 if (talloc_dict_traverse(dict
, talloc_dict_traverse_fn
, &count
) != 0) {
7921 static bool run_local_string_to_sid(int dummy
) {
7924 if (string_to_sid(&sid
, "S--1-5-32-545")) {
7925 printf("allowing S--1-5-32-545\n");
7928 if (string_to_sid(&sid
, "S-1-5-32-+545")) {
7929 printf("allowing S-1-5-32-+545\n");
7932 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")) {
7933 printf("allowing S-1-2-3-4-5-6-7-8-9-0-1-2-3-4-5-6-7-8-9-0\n");
7936 if (string_to_sid(&sid
, "S-1-5-32-545-abc")) {
7937 printf("allowing S-1-5-32-545-abc\n");
7940 if (!string_to_sid(&sid
, "S-1-5-32-545")) {
7941 printf("could not parse S-1-5-32-545\n");
7944 if (!dom_sid_equal(&sid
, &global_sid_Builtin_Users
)) {
7945 printf("mis-parsed S-1-5-32-545 as %s\n",
7946 sid_string_tos(&sid
));
7952 static bool run_local_binary_to_sid(int dummy
) {
7953 struct dom_sid
*sid
= talloc(NULL
, struct dom_sid
);
7954 static const char good_binary_sid
[] = {
7955 0x1, /* revision number */
7957 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, /* id_auth */
7958 0x1, 0x1, 0x1, 0x1, /* auth[0] */
7959 0x1, 0x1, 0x1, 0x1, /* auth[1] */
7960 0x1, 0x1, 0x1, 0x1, /* auth[2] */
7961 0x1, 0x1, 0x1, 0x1, /* auth[3] */
7962 0x1, 0x1, 0x1, 0x1, /* auth[4] */
7963 0x1, 0x1, 0x1, 0x1, /* auth[5] */
7964 0x1, 0x1, 0x1, 0x1, /* auth[6] */
7965 0x1, 0x1, 0x1, 0x1, /* auth[7] */
7966 0x1, 0x1, 0x1, 0x1, /* auth[8] */
7967 0x1, 0x1, 0x1, 0x1, /* auth[9] */
7968 0x1, 0x1, 0x1, 0x1, /* auth[10] */
7969 0x1, 0x1, 0x1, 0x1, /* auth[11] */
7970 0x1, 0x1, 0x1, 0x1, /* auth[12] */
7971 0x1, 0x1, 0x1, 0x1, /* auth[13] */
7972 0x1, 0x1, 0x1, 0x1, /* auth[14] */
7975 static const char long_binary_sid
[] = {
7976 0x1, /* revision number */
7978 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, /* id_auth */
7979 0x1, 0x1, 0x1, 0x1, /* auth[0] */
7980 0x1, 0x1, 0x1, 0x1, /* auth[1] */
7981 0x1, 0x1, 0x1, 0x1, /* auth[2] */
7982 0x1, 0x1, 0x1, 0x1, /* auth[3] */
7983 0x1, 0x1, 0x1, 0x1, /* auth[4] */
7984 0x1, 0x1, 0x1, 0x1, /* auth[5] */
7985 0x1, 0x1, 0x1, 0x1, /* auth[6] */
7986 0x1, 0x1, 0x1, 0x1, /* auth[7] */
7987 0x1, 0x1, 0x1, 0x1, /* auth[8] */
7988 0x1, 0x1, 0x1, 0x1, /* auth[9] */
7989 0x1, 0x1, 0x1, 0x1, /* auth[10] */
7990 0x1, 0x1, 0x1, 0x1, /* auth[11] */
7991 0x1, 0x1, 0x1, 0x1, /* auth[12] */
7992 0x1, 0x1, 0x1, 0x1, /* auth[13] */
7993 0x1, 0x1, 0x1, 0x1, /* auth[14] */
7994 0x1, 0x1, 0x1, 0x1, /* auth[15] */
7995 0x1, 0x1, 0x1, 0x1, /* auth[16] */
7996 0x1, 0x1, 0x1, 0x1, /* auth[17] */
7999 static const char long_binary_sid2
[] = {
8000 0x1, /* revision number */
8002 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, /* id_auth */
8003 0x1, 0x1, 0x1, 0x1, /* auth[0] */
8004 0x1, 0x1, 0x1, 0x1, /* auth[1] */
8005 0x1, 0x1, 0x1, 0x1, /* auth[2] */
8006 0x1, 0x1, 0x1, 0x1, /* auth[3] */
8007 0x1, 0x1, 0x1, 0x1, /* auth[4] */
8008 0x1, 0x1, 0x1, 0x1, /* auth[5] */
8009 0x1, 0x1, 0x1, 0x1, /* auth[6] */
8010 0x1, 0x1, 0x1, 0x1, /* auth[7] */
8011 0x1, 0x1, 0x1, 0x1, /* auth[8] */
8012 0x1, 0x1, 0x1, 0x1, /* auth[9] */
8013 0x1, 0x1, 0x1, 0x1, /* auth[10] */
8014 0x1, 0x1, 0x1, 0x1, /* auth[11] */
8015 0x1, 0x1, 0x1, 0x1, /* auth[12] */
8016 0x1, 0x1, 0x1, 0x1, /* auth[13] */
8017 0x1, 0x1, 0x1, 0x1, /* auth[14] */
8018 0x1, 0x1, 0x1, 0x1, /* auth[15] */
8019 0x1, 0x1, 0x1, 0x1, /* auth[16] */
8020 0x1, 0x1, 0x1, 0x1, /* auth[17] */
8021 0x1, 0x1, 0x1, 0x1, /* auth[18] */
8022 0x1, 0x1, 0x1, 0x1, /* auth[19] */
8023 0x1, 0x1, 0x1, 0x1, /* auth[20] */
8024 0x1, 0x1, 0x1, 0x1, /* auth[21] */
8025 0x1, 0x1, 0x1, 0x1, /* auth[22] */
8026 0x1, 0x1, 0x1, 0x1, /* auth[23] */
8027 0x1, 0x1, 0x1, 0x1, /* auth[24] */
8028 0x1, 0x1, 0x1, 0x1, /* auth[25] */
8029 0x1, 0x1, 0x1, 0x1, /* auth[26] */
8030 0x1, 0x1, 0x1, 0x1, /* auth[27] */
8031 0x1, 0x1, 0x1, 0x1, /* auth[28] */
8032 0x1, 0x1, 0x1, 0x1, /* auth[29] */
8033 0x1, 0x1, 0x1, 0x1, /* auth[30] */
8034 0x1, 0x1, 0x1, 0x1, /* auth[31] */
8037 if (!sid_parse(good_binary_sid
, sizeof(good_binary_sid
), sid
)) {
8040 if (sid_parse(long_binary_sid2
, sizeof(long_binary_sid2
), sid
)) {
8043 if (sid_parse(long_binary_sid
, sizeof(long_binary_sid
), sid
)) {
8049 /* Split a path name into filename and stream name components. Canonicalise
8050 * such that an implicit $DATA token is always explicit.
8052 * The "specification" of this function can be found in the
8053 * run_local_stream_name() function in torture.c, I've tried those
8054 * combinations against a W2k3 server.
8057 static NTSTATUS
split_ntfs_stream_name(TALLOC_CTX
*mem_ctx
, const char *fname
,
8058 char **pbase
, char **pstream
)
8061 char *stream
= NULL
;
8062 char *sname
; /* stream name */
8063 const char *stype
; /* stream type */
8065 DEBUG(10, ("split_ntfs_stream_name called for [%s]\n", fname
));
8067 sname
= strchr_m(fname
, ':');
8069 if (lp_posix_pathnames() || (sname
== NULL
)) {
8070 if (pbase
!= NULL
) {
8071 base
= talloc_strdup(mem_ctx
, fname
);
8072 NT_STATUS_HAVE_NO_MEMORY(base
);
8077 if (pbase
!= NULL
) {
8078 base
= talloc_strndup(mem_ctx
, fname
, PTR_DIFF(sname
, fname
));
8079 NT_STATUS_HAVE_NO_MEMORY(base
);
8084 stype
= strchr_m(sname
, ':');
8086 if (stype
== NULL
) {
8087 sname
= talloc_strdup(mem_ctx
, sname
);
8091 if (strcasecmp_m(stype
, ":$DATA") != 0) {
8093 * If there is an explicit stream type, so far we only
8094 * allow $DATA. Is there anything else allowed? -- vl
8096 DEBUG(10, ("[%s] is an invalid stream type\n", stype
));
8098 return NT_STATUS_OBJECT_NAME_INVALID
;
8100 sname
= talloc_strndup(mem_ctx
, sname
, PTR_DIFF(stype
, sname
));
8104 if (sname
== NULL
) {
8106 return NT_STATUS_NO_MEMORY
;
8109 if (sname
[0] == '\0') {
8111 * no stream name, so no stream
8116 if (pstream
!= NULL
) {
8117 stream
= talloc_asprintf(mem_ctx
, "%s:%s", sname
, stype
);
8118 if (stream
== NULL
) {
8121 return NT_STATUS_NO_MEMORY
;
8124 * upper-case the type field
8126 strupper_m(strchr_m(stream
, ':')+1);
8130 if (pbase
!= NULL
) {
8133 if (pstream
!= NULL
) {
8136 return NT_STATUS_OK
;
8139 static bool test_stream_name(const char *fname
, const char *expected_base
,
8140 const char *expected_stream
,
8141 NTSTATUS expected_status
)
8145 char *stream
= NULL
;
8147 status
= split_ntfs_stream_name(talloc_tos(), fname
, &base
, &stream
);
8148 if (!NT_STATUS_EQUAL(status
, expected_status
)) {
8152 if (!NT_STATUS_IS_OK(status
)) {
8156 if (base
== NULL
) goto error
;
8158 if (strcmp(expected_base
, base
) != 0) goto error
;
8160 if ((expected_stream
!= NULL
) && (stream
== NULL
)) goto error
;
8161 if ((expected_stream
== NULL
) && (stream
!= NULL
)) goto error
;
8163 if ((stream
!= NULL
) && (strcmp(expected_stream
, stream
) != 0))
8167 TALLOC_FREE(stream
);
8171 d_fprintf(stderr
, "Do test_stream(%s, %s, %s, %s)\n",
8172 fname
, expected_base
? expected_base
: "<NULL>",
8173 expected_stream
? expected_stream
: "<NULL>",
8174 nt_errstr(expected_status
));
8175 d_fprintf(stderr
, "-> base=%s, stream=%s, status=%s\n",
8176 base
? base
: "<NULL>", stream
? stream
: "<NULL>",
8179 TALLOC_FREE(stream
);
8183 static bool run_local_stream_name(int dummy
)
8187 ret
&= test_stream_name(
8188 "bla", "bla", NULL
, NT_STATUS_OK
);
8189 ret
&= test_stream_name(
8190 "bla::$DATA", "bla", NULL
, NT_STATUS_OK
);
8191 ret
&= test_stream_name(
8192 "bla:blub:", "bla", NULL
, NT_STATUS_OBJECT_NAME_INVALID
);
8193 ret
&= test_stream_name(
8194 "bla::", NULL
, NULL
, NT_STATUS_OBJECT_NAME_INVALID
);
8195 ret
&= test_stream_name(
8196 "bla::123", "bla", NULL
, NT_STATUS_OBJECT_NAME_INVALID
);
8197 ret
&= test_stream_name(
8198 "bla:$DATA", "bla", "$DATA:$DATA", NT_STATUS_OK
);
8199 ret
&= test_stream_name(
8200 "bla:x:$DATA", "bla", "x:$DATA", NT_STATUS_OK
);
8201 ret
&= test_stream_name(
8202 "bla:x", "bla", "x:$DATA", NT_STATUS_OK
);
8207 static bool data_blob_equal(DATA_BLOB a
, DATA_BLOB b
)
8209 if (a
.length
!= b
.length
) {
8210 printf("a.length=%d != b.length=%d\n",
8211 (int)a
.length
, (int)b
.length
);
8214 if (memcmp(a
.data
, b
.data
, a
.length
) != 0) {
8215 printf("a.data and b.data differ\n");
8221 static bool run_local_memcache(int dummy
)
8223 struct memcache
*cache
;
8225 DATA_BLOB d1
, d2
, d3
;
8226 DATA_BLOB v1
, v2
, v3
;
8228 TALLOC_CTX
*mem_ctx
;
8230 size_t size1
, size2
;
8233 cache
= memcache_init(NULL
, 100);
8235 if (cache
== NULL
) {
8236 printf("memcache_init failed\n");
8240 d1
= data_blob_const("d1", 2);
8241 d2
= data_blob_const("d2", 2);
8242 d3
= data_blob_const("d3", 2);
8244 k1
= data_blob_const("d1", 2);
8245 k2
= data_blob_const("d2", 2);
8247 memcache_add(cache
, STAT_CACHE
, k1
, d1
);
8248 memcache_add(cache
, GETWD_CACHE
, k2
, d2
);
8250 if (!memcache_lookup(cache
, STAT_CACHE
, k1
, &v1
)) {
8251 printf("could not find k1\n");
8254 if (!data_blob_equal(d1
, v1
)) {
8258 if (!memcache_lookup(cache
, GETWD_CACHE
, k2
, &v2
)) {
8259 printf("could not find k2\n");
8262 if (!data_blob_equal(d2
, v2
)) {
8266 memcache_add(cache
, STAT_CACHE
, k1
, d3
);
8268 if (!memcache_lookup(cache
, STAT_CACHE
, k1
, &v3
)) {
8269 printf("could not find replaced k1\n");
8272 if (!data_blob_equal(d3
, v3
)) {
8276 memcache_add(cache
, GETWD_CACHE
, k1
, d1
);
8278 if (memcache_lookup(cache
, GETWD_CACHE
, k2
, &v2
)) {
8279 printf("Did find k2, should have been purged\n");
8285 cache
= memcache_init(NULL
, 0);
8287 mem_ctx
= talloc_init("foo");
8289 str1
= talloc_strdup(mem_ctx
, "string1");
8290 str2
= talloc_strdup(mem_ctx
, "string2");
8292 memcache_add_talloc(cache
, SINGLETON_CACHE_TALLOC
,
8293 data_blob_string_const("torture"), &str1
);
8294 size1
= talloc_total_size(cache
);
8296 memcache_add_talloc(cache
, SINGLETON_CACHE_TALLOC
,
8297 data_blob_string_const("torture"), &str2
);
8298 size2
= talloc_total_size(cache
);
8300 printf("size1=%d, size2=%d\n", (int)size1
, (int)size2
);
8302 if (size2
> size1
) {
8303 printf("memcache leaks memory!\n");
8313 static void wbclient_done(struct tevent_req
*req
)
8316 struct winbindd_response
*wb_resp
;
8317 int *i
= (int *)tevent_req_callback_data_void(req
);
8319 wbc_err
= wb_trans_recv(req
, req
, &wb_resp
);
8322 d_printf("wb_trans_recv %d returned %s\n", *i
, wbcErrorString(wbc_err
));
8325 static bool run_local_wbclient(int dummy
)
8327 struct event_context
*ev
;
8328 struct wb_context
**wb_ctx
;
8329 struct winbindd_request wb_req
;
8330 bool result
= false;
8333 BlockSignals(True
, SIGPIPE
);
8335 ev
= tevent_context_init_byname(talloc_tos(), "epoll");
8340 wb_ctx
= talloc_array(ev
, struct wb_context
*, nprocs
);
8341 if (wb_ctx
== NULL
) {
8345 ZERO_STRUCT(wb_req
);
8346 wb_req
.cmd
= WINBINDD_PING
;
8348 d_printf("nprocs=%d, numops=%d\n", (int)nprocs
, (int)torture_numops
);
8350 for (i
=0; i
<nprocs
; i
++) {
8351 wb_ctx
[i
] = wb_context_init(ev
, NULL
);
8352 if (wb_ctx
[i
] == NULL
) {
8355 for (j
=0; j
<torture_numops
; j
++) {
8356 struct tevent_req
*req
;
8357 req
= wb_trans_send(ev
, ev
, wb_ctx
[i
],
8358 (j
% 2) == 0, &wb_req
);
8362 tevent_req_set_callback(req
, wbclient_done
, &i
);
8368 while (i
< nprocs
* torture_numops
) {
8369 event_loop_once(ev
);
8378 static void getaddrinfo_finished(struct tevent_req
*req
)
8380 char *name
= (char *)tevent_req_callback_data_void(req
);
8381 struct addrinfo
*ainfo
;
8384 res
= getaddrinfo_recv(req
, &ainfo
);
8386 d_printf("gai(%s) returned %s\n", name
, gai_strerror(res
));
8389 d_printf("gai(%s) succeeded\n", name
);
8390 freeaddrinfo(ainfo
);
8393 static bool run_getaddrinfo_send(int dummy
)
8395 TALLOC_CTX
*frame
= talloc_stackframe();
8396 struct fncall_context
*ctx
;
8397 struct tevent_context
*ev
;
8398 bool result
= false;
8399 const char *names
[4] = { "www.samba.org", "notfound.samba.org",
8400 "www.slashdot.org", "heise.de" };
8401 struct tevent_req
*reqs
[4];
8404 ev
= event_context_init(frame
);
8409 ctx
= fncall_context_init(frame
, 4);
8411 for (i
=0; i
<ARRAY_SIZE(names
); i
++) {
8412 reqs
[i
] = getaddrinfo_send(frame
, ev
, ctx
, names
[i
], NULL
,
8414 if (reqs
[i
] == NULL
) {
8417 tevent_req_set_callback(reqs
[i
], getaddrinfo_finished
,
8418 discard_const_p(void, names
[i
]));
8421 for (i
=0; i
<ARRAY_SIZE(reqs
); i
++) {
8422 tevent_loop_once(ev
);
8431 static bool dbtrans_inc(struct db_context
*db
)
8433 struct db_record
*rec
;
8438 rec
= db
->fetch_locked(db
, db
, string_term_tdb_data("transtest"));
8440 printf(__location__
"fetch_lock failed\n");
8444 if (rec
->value
.dsize
!= sizeof(uint32_t)) {
8445 printf(__location__
"value.dsize = %d\n",
8446 (int)rec
->value
.dsize
);
8450 val
= (uint32_t *)rec
->value
.dptr
;
8453 status
= rec
->store(rec
, make_tdb_data((uint8_t *)val
,
8456 if (!NT_STATUS_IS_OK(status
)) {
8457 printf(__location__
"store failed: %s\n",
8468 static bool run_local_dbtrans(int dummy
)
8470 struct db_context
*db
;
8471 struct db_record
*rec
;
8476 db
= db_open(talloc_tos(), "transtest.tdb", 0, TDB_DEFAULT
,
8477 O_RDWR
|O_CREAT
, 0600);
8479 printf("Could not open transtest.db\n");
8483 res
= db
->transaction_start(db
);
8485 printf(__location__
"transaction_start failed\n");
8489 rec
= db
->fetch_locked(db
, db
, string_term_tdb_data("transtest"));
8491 printf(__location__
"fetch_lock failed\n");
8495 if (rec
->value
.dptr
== NULL
) {
8497 status
= rec
->store(
8498 rec
, make_tdb_data((uint8_t *)&initial
,
8501 if (!NT_STATUS_IS_OK(status
)) {
8502 printf(__location__
"store returned %s\n",
8510 res
= db
->transaction_commit(db
);
8512 printf(__location__
"transaction_commit failed\n");
8520 res
= db
->transaction_start(db
);
8522 printf(__location__
"transaction_start failed\n");
8526 if (!dbwrap_fetch_uint32(db
, "transtest", &val
)) {
8527 printf(__location__
"dbwrap_fetch_uint32 failed\n");
8531 for (i
=0; i
<10; i
++) {
8532 if (!dbtrans_inc(db
)) {
8537 if (!dbwrap_fetch_uint32(db
, "transtest", &val2
)) {
8538 printf(__location__
"dbwrap_fetch_uint32 failed\n");
8542 if (val2
!= val
+ 10) {
8543 printf(__location__
"val=%d, val2=%d\n",
8544 (int)val
, (int)val2
);
8548 printf("val2=%d\r", val2
);
8550 res
= db
->transaction_commit(db
);
8552 printf(__location__
"transaction_commit failed\n");
8562 * Just a dummy test to be run under a debugger. There's no real way
8563 * to inspect the tevent_select specific function from outside of
8567 static bool run_local_tevent_select(int dummy
)
8569 struct tevent_context
*ev
;
8570 struct tevent_fd
*fd1
, *fd2
;
8571 bool result
= false;
8573 ev
= tevent_context_init_byname(NULL
, "select");
8575 d_fprintf(stderr
, "tevent_context_init_byname failed\n");
8579 fd1
= tevent_add_fd(ev
, ev
, 2, 0, NULL
, NULL
);
8581 d_fprintf(stderr
, "tevent_add_fd failed\n");
8584 fd2
= tevent_add_fd(ev
, ev
, 3, 0, NULL
, NULL
);
8586 d_fprintf(stderr
, "tevent_add_fd failed\n");
8591 fd2
= tevent_add_fd(ev
, ev
, 1, 0, NULL
, NULL
);
8593 d_fprintf(stderr
, "tevent_add_fd failed\n");
8603 static double create_procs(bool (*fn
)(int), bool *result
)
8606 volatile pid_t
*child_status
;
8607 volatile bool *child_status_out
;
8610 struct timeval start
;
8614 child_status
= (volatile pid_t
*)shm_setup(sizeof(pid_t
)*nprocs
);
8615 if (!child_status
) {
8616 printf("Failed to setup shared memory\n");
8620 child_status_out
= (volatile bool *)shm_setup(sizeof(bool)*nprocs
);
8621 if (!child_status_out
) {
8622 printf("Failed to setup result status shared memory\n");
8626 for (i
= 0; i
< nprocs
; i
++) {
8627 child_status
[i
] = 0;
8628 child_status_out
[i
] = True
;
8631 start
= timeval_current();
8633 for (i
=0;i
<nprocs
;i
++) {
8636 pid_t mypid
= getpid();
8637 sys_srandom(((int)mypid
) ^ ((int)time(NULL
)));
8639 slprintf(myname
,sizeof(myname
),"CLIENT%d", i
);
8642 if (torture_open_connection(¤t_cli
, i
)) break;
8644 printf("pid %d failed to start\n", (int)getpid());
8650 child_status
[i
] = getpid();
8652 while (child_status
[i
] && timeval_elapsed(&start
) < 5) smb_msleep(2);
8654 child_status_out
[i
] = fn(i
);
8661 for (i
=0;i
<nprocs
;i
++) {
8662 if (child_status
[i
]) synccount
++;
8664 if (synccount
== nprocs
) break;
8666 } while (timeval_elapsed(&start
) < 30);
8668 if (synccount
!= nprocs
) {
8669 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs
, synccount
);
8671 return timeval_elapsed(&start
);
8674 /* start the client load */
8675 start
= timeval_current();
8677 for (i
=0;i
<nprocs
;i
++) {
8678 child_status
[i
] = 0;
8681 printf("%d clients started\n", nprocs
);
8683 for (i
=0;i
<nprocs
;i
++) {
8684 while (waitpid(0, &status
, 0) == -1 && errno
== EINTR
) /* noop */ ;
8689 for (i
=0;i
<nprocs
;i
++) {
8690 if (!child_status_out
[i
]) {
8694 return timeval_elapsed(&start
);
8697 #define FLAG_MULTIPROC 1
8704 {"FDPASS", run_fdpasstest
, 0},
8705 {"LOCK1", run_locktest1
, 0},
8706 {"LOCK2", run_locktest2
, 0},
8707 {"LOCK3", run_locktest3
, 0},
8708 {"LOCK4", run_locktest4
, 0},
8709 {"LOCK5", run_locktest5
, 0},
8710 {"LOCK6", run_locktest6
, 0},
8711 {"LOCK7", run_locktest7
, 0},
8712 {"LOCK8", run_locktest8
, 0},
8713 {"LOCK9", run_locktest9
, 0},
8714 {"UNLINK", run_unlinktest
, 0},
8715 {"BROWSE", run_browsetest
, 0},
8716 {"ATTR", run_attrtest
, 0},
8717 {"TRANS2", run_trans2test
, 0},
8718 {"MAXFID", run_maxfidtest
, FLAG_MULTIPROC
},
8719 {"TORTURE",run_torture
, FLAG_MULTIPROC
},
8720 {"RANDOMIPC", run_randomipc
, 0},
8721 {"NEGNOWAIT", run_negprot_nowait
, 0},
8722 {"NBENCH", run_nbench
, 0},
8723 {"NBENCH2", run_nbench2
, 0},
8724 {"OPLOCK1", run_oplock1
, 0},
8725 {"OPLOCK2", run_oplock2
, 0},
8726 {"OPLOCK4", run_oplock4
, 0},
8727 {"DIR", run_dirtest
, 0},
8728 {"DIR1", run_dirtest1
, 0},
8729 {"DIR-CREATETIME", run_dir_createtime
, 0},
8730 {"DENY1", torture_denytest1
, 0},
8731 {"DENY2", torture_denytest2
, 0},
8732 {"TCON", run_tcon_test
, 0},
8733 {"TCONDEV", run_tcon_devtype_test
, 0},
8734 {"RW1", run_readwritetest
, 0},
8735 {"RW2", run_readwritemulti
, FLAG_MULTIPROC
},
8736 {"RW3", run_readwritelarge
, 0},
8737 {"RW-SIGNING", run_readwritelarge_signtest
, 0},
8738 {"OPEN", run_opentest
, 0},
8739 {"POSIX", run_simple_posix_open_test
, 0},
8740 {"POSIX-APPEND", run_posix_append
, 0},
8741 {"CASE-INSENSITIVE-CREATE", run_case_insensitive_create
, 0},
8742 {"ASYNC-ECHO", run_async_echo
, 0},
8743 { "UID-REGRESSION-TEST", run_uid_regression_test
, 0},
8744 { "SHORTNAME-TEST", run_shortname_test
, 0},
8745 { "ADDRCHANGE", run_addrchange
, 0},
8747 {"OPENATTR", run_openattrtest
, 0},
8749 {"XCOPY", run_xcopy
, 0},
8750 {"RENAME", run_rename
, 0},
8751 {"DELETE", run_deletetest
, 0},
8752 {"DELETE-LN", run_deletetest_ln
, 0},
8753 {"PROPERTIES", run_properties
, 0},
8754 {"MANGLE", torture_mangle
, 0},
8755 {"MANGLE1", run_mangle1
, 0},
8756 {"W2K", run_w2ktest
, 0},
8757 {"TRANS2SCAN", torture_trans2_scan
, 0},
8758 {"NTTRANSSCAN", torture_nttrans_scan
, 0},
8759 {"UTABLE", torture_utable
, 0},
8760 {"CASETABLE", torture_casetable
, 0},
8761 {"ERRMAPEXTRACT", run_error_map_extract
, 0},
8762 {"PIPE_NUMBER", run_pipe_number
, 0},
8763 {"TCON2", run_tcon2_test
, 0},
8764 {"IOCTL", torture_ioctl_test
, 0},
8765 {"CHKPATH", torture_chkpath_test
, 0},
8766 {"FDSESS", run_fdsesstest
, 0},
8767 { "EATEST", run_eatest
, 0},
8768 { "SESSSETUP_BENCH", run_sesssetup_bench
, 0},
8769 { "CHAIN1", run_chain1
, 0},
8770 { "CHAIN2", run_chain2
, 0},
8771 { "WINDOWS-WRITE", run_windows_write
, 0},
8772 { "NTTRANS-CREATE", run_nttrans_create
, 0},
8773 { "CLI_ECHO", run_cli_echo
, 0},
8774 { "GETADDRINFO", run_getaddrinfo_send
, 0},
8775 { "TLDAP", run_tldap
},
8776 { "STREAMERROR", run_streamerror
},
8777 { "NOTIFY-BENCH", run_notify_bench
},
8778 { "BAD-NBT-SESSION", run_bad_nbt_session
},
8779 { "SMB-ANY-CONNECT", run_smb_any_connect
},
8780 { "NOTIFY-ONLINE", run_notify_online
},
8781 { "SMB2-BASIC", run_smb2_basic
},
8782 { "LOCAL-SUBSTITUTE", run_local_substitute
, 0},
8783 { "LOCAL-GENCACHE", run_local_gencache
, 0},
8784 { "LOCAL-TALLOC-DICT", run_local_talloc_dict
, 0},
8785 { "LOCAL-BASE64", run_local_base64
, 0},
8786 { "LOCAL-RBTREE", run_local_rbtree
, 0},
8787 { "LOCAL-MEMCACHE", run_local_memcache
, 0},
8788 { "LOCAL-STREAM-NAME", run_local_stream_name
, 0},
8789 { "LOCAL-WBCLIENT", run_local_wbclient
, 0},
8790 { "LOCAL-string_to_sid", run_local_string_to_sid
, 0},
8791 { "LOCAL-binary_to_sid", run_local_binary_to_sid
, 0},
8792 { "LOCAL-DBTRANS", run_local_dbtrans
, 0},
8793 { "LOCAL-TEVENT-SELECT", run_local_tevent_select
, 0},
8794 { "LOCAL-CONVERT-STRING", run_local_convert_string
, 0},
8799 /****************************************************************************
8800 run a specified test or "ALL"
8801 ****************************************************************************/
8802 static bool run_test(const char *name
)
8809 if (strequal(name
,"ALL")) {
8810 for (i
=0;torture_ops
[i
].name
;i
++) {
8811 run_test(torture_ops
[i
].name
);
8816 for (i
=0;torture_ops
[i
].name
;i
++) {
8817 fstr_sprintf(randomfname
, "\\XX%x",
8818 (unsigned)random());
8820 if (strequal(name
, torture_ops
[i
].name
)) {
8822 printf("Running %s\n", name
);
8823 if (torture_ops
[i
].flags
& FLAG_MULTIPROC
) {
8824 t
= create_procs(torture_ops
[i
].fn
, &result
);
8827 printf("TEST %s FAILED!\n", name
);
8830 struct timeval start
;
8831 start
= timeval_current();
8832 if (!torture_ops
[i
].fn(0)) {
8834 printf("TEST %s FAILED!\n", name
);
8836 t
= timeval_elapsed(&start
);
8838 printf("%s took %g secs\n\n", name
, t
);
8843 printf("Did not find a test named %s\n", name
);
8851 static void usage(void)
8855 printf("WARNING samba4 test suite is much more complete nowadays.\n");
8856 printf("Please use samba4 torture.\n\n");
8858 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
8860 printf("\t-d debuglevel\n");
8861 printf("\t-U user%%pass\n");
8862 printf("\t-k use kerberos\n");
8863 printf("\t-N numprocs\n");
8864 printf("\t-n my_netbios_name\n");
8865 printf("\t-W workgroup\n");
8866 printf("\t-o num_operations\n");
8867 printf("\t-O socket_options\n");
8868 printf("\t-m maximum protocol\n");
8869 printf("\t-L use oplocks\n");
8870 printf("\t-c CLIENT.TXT specify client load file for NBENCH\n");
8871 printf("\t-A showall\n");
8872 printf("\t-p port\n");
8873 printf("\t-s seed\n");
8874 printf("\t-b unclist_filename specify multiple shares for multiple connections\n");
8875 printf("\t-f filename filename to test\n");
8878 printf("tests are:");
8879 for (i
=0;torture_ops
[i
].name
;i
++) {
8880 printf(" %s", torture_ops
[i
].name
);
8884 printf("default test is ALL\n");
8889 /****************************************************************************
8891 ****************************************************************************/
8892 int main(int argc
,char *argv
[])
8898 bool correct
= True
;
8899 TALLOC_CTX
*frame
= talloc_stackframe();
8900 int seed
= time(NULL
);
8902 #ifdef HAVE_SETBUFFER
8903 setbuffer(stdout
, NULL
, 0);
8906 setup_logging("smbtorture", DEBUG_STDOUT
);
8910 if (is_default_dyn_CONFIGFILE()) {
8911 if(getenv("SMB_CONF_PATH")) {
8912 set_dyn_CONFIGFILE(getenv("SMB_CONF_PATH"));
8915 lp_load(get_dyn_CONFIGFILE(),True
,False
,False
,True
);
8922 for(p
= argv
[1]; *p
; p
++)
8926 if (strncmp(argv
[1], "//", 2)) {
8930 fstrcpy(host
, &argv
[1][2]);
8931 p
= strchr_m(&host
[2],'/');
8936 fstrcpy(share
, p
+1);
8938 fstrcpy(myname
, get_myname(talloc_tos()));
8940 fprintf(stderr
, "Failed to get my hostname.\n");
8944 if (*username
== 0 && getenv("LOGNAME")) {
8945 fstrcpy(username
,getenv("LOGNAME"));
8951 fstrcpy(workgroup
, lp_workgroup());
8953 while ((opt
= getopt(argc
, argv
, "p:hW:U:n:N:O:o:m:Ll:d:Aec:ks:b:B:f:"))
8957 port_to_use
= atoi(optarg
);
8960 seed
= atoi(optarg
);
8963 fstrcpy(workgroup
,optarg
);
8966 max_protocol
= interpret_protocol(optarg
, max_protocol
);
8969 nprocs
= atoi(optarg
);
8972 torture_numops
= atoi(optarg
);
8975 lp_set_cmdline("log level", optarg
);
8984 local_path
= optarg
;
8987 torture_showall
= True
;
8990 fstrcpy(myname
, optarg
);
8993 client_txt
= optarg
;
9000 use_kerberos
= True
;
9002 d_printf("No kerberos support compiled in\n");
9008 fstrcpy(username
,optarg
);
9009 p
= strchr_m(username
,'%');
9012 fstrcpy(password
, p
+1);
9017 fstrcpy(multishare_conn_fname
, optarg
);
9018 use_multishare_conn
= True
;
9021 torture_blocksize
= atoi(optarg
);
9024 test_filename
= SMB_STRDUP(optarg
);
9027 printf("Unknown option %c (%d)\n", (char)opt
, opt
);
9032 d_printf("using seed %d\n", seed
);
9036 if(use_kerberos
&& !gotuser
) gotpass
= True
;
9039 p
= getpass("Password:");
9041 fstrcpy(password
, p
);
9046 printf("host=%s share=%s user=%s myname=%s\n",
9047 host
, share
, username
, myname
);
9049 if (argc
== optind
) {
9050 correct
= run_test("ALL");
9052 for (i
=optind
;i
<argc
;i
++) {
9053 if (!run_test(argv
[i
])) {