2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1997-1998
5 Copyright (C) Jeremy Allison 2009
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "system/shmem.h"
23 #include "wbc_async.h"
24 #include "torture/proto.h"
25 #include "libcli/security/security.h"
27 #include "tldap_util.h"
28 #include "../librpc/gen_ndr/svcctl.h"
30 #include "nsswitch/winbind_client.h"
32 #include "talloc_dict.h"
33 #include "async_smb.h"
34 #include "libsmb/libsmb.h"
35 #include "libsmb/clirap.h"
37 #include "libsmb/nmblib.h"
38 #include "../lib/util/tevent_ntstatus.h"
44 static fstring host
, workgroup
, share
, password
, username
, myname
;
45 static int max_protocol
= PROTOCOL_NT1
;
46 static const char *sockops
="TCP_NODELAY";
48 static int port_to_use
=0;
49 int torture_numops
=100;
50 int torture_blocksize
=1024*1024;
51 static int procnum
; /* records process count number when forking */
52 static struct cli_state
*current_cli
;
53 static fstring randomfname
;
54 static bool use_oplocks
;
55 static bool use_level_II_oplocks
;
56 static const char *client_txt
= "client_oplocks.txt";
57 static bool use_kerberos
;
58 static fstring multishare_conn_fname
;
59 static bool use_multishare_conn
= False
;
60 static bool do_encrypt
;
61 static const char *local_path
= NULL
;
62 static int signing_state
= Undefined
;
65 bool torture_showall
= False
;
67 static double create_procs(bool (*fn
)(int), bool *result
);
70 /* return a pointer to a anonymous shared memory segment of size "size"
71 which will persist across fork() but will disappear when all processes
74 The memory is not zeroed
76 This function uses system5 shared memory. It takes advantage of a property
77 that the memory is not destroyed if it is attached when the id is removed
79 void *shm_setup(int size
)
85 shmid
= shm_open("private", O_RDWR
| O_CREAT
| O_EXCL
, S_IRUSR
| S_IWUSR
);
87 printf("can't get shared memory\n");
90 shm_unlink("private");
91 if (ftruncate(shmid
, size
) == -1) {
92 printf("can't set shared memory size\n");
95 ret
= mmap(0, size
, PROT_READ
| PROT_WRITE
, MAP_SHARED
, shmid
, 0);
96 if (ret
== MAP_FAILED
) {
97 printf("can't map shared memory\n");
101 shmid
= shmget(IPC_PRIVATE
, size
, S_IRUSR
| S_IWUSR
);
103 printf("can't get shared memory\n");
106 ret
= (void *)shmat(shmid
, 0, 0);
107 if (!ret
|| ret
== (void *)-1) {
108 printf("can't attach to shared memory\n");
111 /* the following releases the ipc, but note that this process
112 and all its children will still have access to the memory, its
113 just that the shmid is no longer valid for other shm calls. This
114 means we don't leave behind lots of shm segments after we exit
116 See Stevens "advanced programming in unix env" for details
118 shmctl(shmid
, IPC_RMID
, 0);
124 /********************************************************************
125 Ensure a connection is encrypted.
126 ********************************************************************/
128 static bool force_cli_encryption(struct cli_state
*c
,
129 const char *sharename
)
132 uint32 caplow
, caphigh
;
135 if (!SERVER_HAS_UNIX_CIFS(c
)) {
136 d_printf("Encryption required and "
137 "server that doesn't support "
138 "UNIX extensions - failing connect\n");
142 status
= cli_unix_extensions_version(c
, &major
, &minor
, &caplow
,
144 if (!NT_STATUS_IS_OK(status
)) {
145 d_printf("Encryption required and "
146 "can't get UNIX CIFS extensions "
147 "version from server: %s\n", nt_errstr(status
));
151 if (!(caplow
& CIFS_UNIX_TRANSPORT_ENCRYPTION_CAP
)) {
152 d_printf("Encryption required and "
153 "share %s doesn't support "
154 "encryption.\n", sharename
);
158 if (c
->use_kerberos
) {
159 status
= cli_gss_smb_encryption_start(c
);
161 status
= cli_raw_ntlm_smb_encryption_start(c
,
167 if (!NT_STATUS_IS_OK(status
)) {
168 d_printf("Encryption required and "
169 "setup failed with error %s.\n",
178 static struct cli_state
*open_nbt_connection(void)
180 struct nmb_name called
, calling
;
181 struct sockaddr_storage ss
;
185 make_nmb_name(&calling
, myname
, 0x0);
186 make_nmb_name(&called
, host
, 0x20);
190 if (!(c
= cli_initialise_ex(signing_state
))) {
191 printf("Failed initialize cli_struct to connect with %s\n", host
);
195 c
->port
= port_to_use
;
197 status
= cli_connect(c
, host
, &ss
);
198 if (!NT_STATUS_IS_OK(status
)) {
199 printf("Failed to connect with %s. Error %s\n", host
, nt_errstr(status
) );
203 c
->use_kerberos
= use_kerberos
;
205 c
->timeout
= 120000; /* set a really long timeout (2 minutes) */
206 if (use_oplocks
) c
->use_oplocks
= True
;
207 if (use_level_II_oplocks
) c
->use_level_II_oplocks
= True
;
209 if (!cli_session_request(c
, &calling
, &called
)) {
211 * Well, that failed, try *SMBSERVER ...
212 * However, we must reconnect as well ...
214 status
= cli_connect(c
, host
, &ss
);
215 if (!NT_STATUS_IS_OK(status
)) {
216 printf("Failed to connect with %s. Error %s\n", host
, nt_errstr(status
) );
220 make_nmb_name(&called
, "*SMBSERVER", 0x20);
221 if (!cli_session_request(c
, &calling
, &called
)) {
222 printf("%s rejected the session\n",host
);
223 printf("We tried with a called name of %s & %s\n",
233 /****************************************************************************
234 Send a corrupt session request. See rfc1002.txt 4.3 and 4.3.2.
235 ****************************************************************************/
237 static bool cli_bad_session_request(struct cli_state
*cli
,
238 struct nmb_name
*calling
, struct nmb_name
*called
)
245 memcpy(&(cli
->calling
), calling
, sizeof(*calling
));
246 memcpy(&(cli
->called
), called
, sizeof(*called
));
248 /* put in the destination name */
250 tmp
= name_mangle(talloc_tos(), cli
->called
.name
,
251 cli
->called
.name_type
);
257 namelen
= name_len((unsigned char *)tmp
, talloc_get_size(tmp
));
259 memcpy(p
, tmp
, namelen
);
264 /* Deliberately corrupt the name len (first byte) */
269 tmp
= name_mangle(talloc_tos(), cli
->calling
.name
,
270 cli
->calling
.name_type
);
276 namelen
= name_len((unsigned char *)tmp
, talloc_get_size(tmp
));
278 memcpy(p
, tmp
, namelen
);
282 /* Deliberately corrupt the name len (first byte) */
285 /* send a session request (RFC 1002) */
286 /* setup the packet length
287 * Remove four bytes from the length count, since the length
288 * field in the NBT Session Service header counts the number
289 * of bytes which follow. The cli_send_smb() function knows
290 * about this and accounts for those four bytes.
294 _smb_setlen(cli
->outbuf
,len
);
295 SCVAL(cli
->outbuf
,0,0x81);
298 DEBUG(5,("Sent session request\n"));
300 if (!cli_receive_smb(cli
))
303 if (CVAL(cli
->inbuf
,0) != 0x82) {
304 /* This is the wrong place to put the error... JRA. */
305 cli
->rap_error
= CVAL(cli
->inbuf
,4);
311 static struct cli_state
*open_bad_nbt_connection(void)
313 struct nmb_name called
, calling
;
314 struct sockaddr_storage ss
;
318 make_nmb_name(&calling
, myname
, 0x0);
319 make_nmb_name(&called
, host
, 0x20);
323 if (!(c
= cli_initialise_ex(signing_state
))) {
324 printf("Failed initialize cli_struct to connect with %s\n", host
);
330 status
= cli_connect(c
, host
, &ss
);
331 if (!NT_STATUS_IS_OK(status
)) {
332 printf("Failed to connect with %s. Error %s\n", host
, nt_errstr(status
) );
336 c
->timeout
= 4000; /* set a short timeout (4 seconds) */
338 if (!cli_bad_session_request(c
, &calling
, &called
)) {
339 printf("Failed to connect with %s. Error %s\n", host
, nt_errstr(status
) );
347 /* Insert a NULL at the first separator of the given path and return a pointer
348 * to the remainder of the string.
351 terminate_path_at_separator(char * path
)
359 if ((p
= strchr_m(path
, '/'))) {
364 if ((p
= strchr_m(path
, '\\'))) {
374 parse a //server/share type UNC name
376 bool smbcli_parse_unc(const char *unc_name
, TALLOC_CTX
*mem_ctx
,
377 char **hostname
, char **sharename
)
381 *hostname
= *sharename
= NULL
;
383 if (strncmp(unc_name
, "\\\\", 2) &&
384 strncmp(unc_name
, "//", 2)) {
388 *hostname
= talloc_strdup(mem_ctx
, &unc_name
[2]);
389 p
= terminate_path_at_separator(*hostname
);
392 *sharename
= talloc_strdup(mem_ctx
, p
);
393 terminate_path_at_separator(*sharename
);
396 if (*hostname
&& *sharename
) {
400 TALLOC_FREE(*hostname
);
401 TALLOC_FREE(*sharename
);
405 static bool torture_open_connection_share(struct cli_state
**c
,
406 const char *hostname
,
407 const char *sharename
)
413 flags
|= CLI_FULL_CONNECTION_USE_KERBEROS
;
415 flags
|= CLI_FULL_CONNECTION_OPLOCKS
;
416 if (use_level_II_oplocks
)
417 flags
|= CLI_FULL_CONNECTION_LEVEL_II_OPLOCKS
;
419 status
= cli_full_connection(c
, myname
,
420 hostname
, NULL
, port_to_use
,
423 password
, flags
, signing_state
);
424 if (!NT_STATUS_IS_OK(status
)) {
425 printf("failed to open share connection: //%s/%s port:%d - %s\n",
426 hostname
, sharename
, port_to_use
, nt_errstr(status
));
430 (*c
)->timeout
= 120000; /* set a really long timeout (2 minutes) */
433 return force_cli_encryption(*c
,
439 bool torture_open_connection(struct cli_state
**c
, int conn_index
)
441 char **unc_list
= NULL
;
442 int num_unc_names
= 0;
445 if (use_multishare_conn
==True
) {
447 unc_list
= file_lines_load(multishare_conn_fname
, &num_unc_names
, 0, NULL
);
448 if (!unc_list
|| num_unc_names
<= 0) {
449 printf("Failed to load unc names list from '%s'\n", multishare_conn_fname
);
453 if (!smbcli_parse_unc(unc_list
[conn_index
% num_unc_names
],
455 printf("Failed to parse UNC name %s\n",
456 unc_list
[conn_index
% num_unc_names
]);
457 TALLOC_FREE(unc_list
);
461 result
= torture_open_connection_share(c
, h
, s
);
463 /* h, s were copied earlier */
464 TALLOC_FREE(unc_list
);
468 return torture_open_connection_share(c
, host
, share
);
471 bool torture_cli_session_setup2(struct cli_state
*cli
, uint16
*new_vuid
)
473 uint16 old_vuid
= cli
->vuid
;
474 fstring old_user_name
;
475 size_t passlen
= strlen(password
);
479 fstrcpy(old_user_name
, cli
->user_name
);
481 ret
= NT_STATUS_IS_OK(cli_session_setup(cli
, username
,
485 *new_vuid
= cli
->vuid
;
486 cli
->vuid
= old_vuid
;
487 status
= cli_set_username(cli
, old_user_name
);
488 if (!NT_STATUS_IS_OK(status
)) {
495 bool torture_close_connection(struct cli_state
*c
)
500 status
= cli_tdis(c
);
501 if (!NT_STATUS_IS_OK(status
)) {
502 printf("tdis failed (%s)\n", nt_errstr(status
));
512 /* check if the server produced the expected error code */
513 static bool check_error(int line
, struct cli_state
*c
,
514 uint8 eclass
, uint32 ecode
, NTSTATUS nterr
)
516 if (cli_is_dos_error(c
)) {
520 /* Check DOS error */
522 cli_dos_error(c
, &cclass
, &num
);
524 if (eclass
!= cclass
|| ecode
!= num
) {
525 printf("unexpected error code class=%d code=%d\n",
526 (int)cclass
, (int)num
);
527 printf(" expected %d/%d %s (line=%d)\n",
528 (int)eclass
, (int)ecode
, nt_errstr(nterr
), line
);
537 status
= cli_nt_error(c
);
539 if (NT_STATUS_V(nterr
) != NT_STATUS_V(status
)) {
540 printf("unexpected error code %s\n", nt_errstr(status
));
541 printf(" expected %s (line=%d)\n", nt_errstr(nterr
), line
);
550 static bool wait_lock(struct cli_state
*c
, int fnum
, uint32 offset
, uint32 len
)
552 while (!cli_lock(c
, fnum
, offset
, len
, -1, WRITE_LOCK
)) {
553 if (!check_error(__LINE__
, c
, ERRDOS
, ERRlock
, NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
559 static bool rw_torture(struct cli_state
*c
)
561 const char *lockfname
= "\\torture.lck";
565 pid_t pid2
, pid
= getpid();
571 memset(buf
, '\0', sizeof(buf
));
573 status
= cli_open(c
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
,
575 if (!NT_STATUS_IS_OK(status
)) {
576 status
= cli_open(c
, lockfname
, O_RDWR
, DENY_NONE
, &fnum2
);
578 if (!NT_STATUS_IS_OK(status
)) {
579 printf("open of %s failed (%s)\n",
580 lockfname
, nt_errstr(status
));
584 for (i
=0;i
<torture_numops
;i
++) {
585 unsigned n
= (unsigned)sys_random()%10;
588 printf("%d\r", i
); fflush(stdout
);
590 slprintf(fname
, sizeof(fstring
) - 1, "\\torture.%u", n
);
592 if (!wait_lock(c
, fnum2
, n
*sizeof(int), sizeof(int))) {
596 status
= cli_open(c
, fname
, O_RDWR
| O_CREAT
| O_TRUNC
,
598 if (!NT_STATUS_IS_OK(status
)) {
599 printf("open failed (%s)\n", nt_errstr(status
));
604 status
= cli_writeall(c
, fnum
, 0, (uint8_t *)&pid
, 0,
606 if (!NT_STATUS_IS_OK(status
)) {
607 printf("write failed (%s)\n", nt_errstr(status
));
612 status
= cli_writeall(c
, fnum
, 0, (uint8_t *)buf
,
613 sizeof(pid
)+(j
*sizeof(buf
)),
615 if (!NT_STATUS_IS_OK(status
)) {
616 printf("write failed (%s)\n",
624 if (cli_read(c
, fnum
, (char *)&pid2
, 0, sizeof(pid
)) != sizeof(pid
)) {
625 printf("read failed (%s)\n", cli_errstr(c
));
630 printf("data corruption!\n");
634 status
= cli_close(c
, fnum
);
635 if (!NT_STATUS_IS_OK(status
)) {
636 printf("close failed (%s)\n", nt_errstr(status
));
640 status
= cli_unlink(c
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
641 if (!NT_STATUS_IS_OK(status
)) {
642 printf("unlink failed (%s)\n", nt_errstr(status
));
646 status
= cli_unlock(c
, fnum2
, n
*sizeof(int), sizeof(int));
647 if (!NT_STATUS_IS_OK(status
)) {
648 printf("unlock failed (%s)\n", nt_errstr(status
));
654 cli_unlink(c
, lockfname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
661 static bool run_torture(int dummy
)
663 struct cli_state
*cli
;
668 cli_sockopt(cli
, sockops
);
670 ret
= rw_torture(cli
);
672 if (!torture_close_connection(cli
)) {
679 static bool rw_torture3(struct cli_state
*c
, char *lockfname
)
681 uint16_t fnum
= (uint16_t)-1;
686 unsigned countprev
= 0;
689 NTSTATUS status
= NT_STATUS_OK
;
692 for (i
= 0; i
< sizeof(buf
); i
+= sizeof(uint32
))
694 SIVAL(buf
, i
, sys_random());
699 if (!NT_STATUS_IS_OK(cli_unlink(c
, lockfname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
))) {
700 printf("unlink failed (%s) (normal, this file should not exist)\n", cli_errstr(c
));
703 status
= cli_open(c
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
,
705 if (!NT_STATUS_IS_OK(status
)) {
706 printf("first open read/write of %s failed (%s)\n",
707 lockfname
, nt_errstr(status
));
713 for (i
= 0; i
< 500 && fnum
== (uint16_t)-1; i
++)
715 status
= cli_open(c
, lockfname
, O_RDONLY
,
717 if (!NT_STATUS_IS_OK(status
)) {
722 if (!NT_STATUS_IS_OK(status
)) {
723 printf("second open read-only of %s failed (%s)\n",
724 lockfname
, nt_errstr(status
));
730 for (count
= 0; count
< sizeof(buf
); count
+= sent
)
732 if (count
>= countprev
) {
733 printf("%d %8d\r", i
, count
);
736 countprev
+= (sizeof(buf
) / 20);
741 sent
= ((unsigned)sys_random()%(20))+ 1;
742 if (sent
> sizeof(buf
) - count
)
744 sent
= sizeof(buf
) - count
;
747 status
= cli_writeall(c
, fnum
, 0, (uint8_t *)buf
+count
,
748 count
, (size_t)sent
, NULL
);
749 if (!NT_STATUS_IS_OK(status
)) {
750 printf("write failed (%s)\n",
757 sent
= cli_read(c
, fnum
, buf_rd
+count
, count
,
761 printf("read failed offset:%d size:%ld (%s)\n",
762 count
, (unsigned long)sizeof(buf
)-count
,
769 if (memcmp(buf_rd
+count
, buf
+count
, sent
) != 0)
771 printf("read/write compare failed\n");
772 printf("offset: %d req %ld recvd %ld\n", count
, (unsigned long)sizeof(buf
)-count
, (unsigned long)sent
);
781 status
= cli_close(c
, fnum
);
782 if (!NT_STATUS_IS_OK(status
)) {
783 printf("close failed (%s)\n", nt_errstr(status
));
790 static bool rw_torture2(struct cli_state
*c1
, struct cli_state
*c2
)
792 const char *lockfname
= "\\torture2.lck";
802 status
= cli_unlink(c1
, lockfname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
803 if (!NT_STATUS_IS_OK(status
)) {
804 printf("unlink failed (%s) (normal, this file should not exist)\n", nt_errstr(status
));
807 status
= cli_open(c1
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
,
809 if (!NT_STATUS_IS_OK(status
)) {
810 printf("first open read/write of %s failed (%s)\n",
811 lockfname
, nt_errstr(status
));
815 status
= cli_open(c2
, lockfname
, O_RDONLY
, DENY_NONE
, &fnum2
);
816 if (!NT_STATUS_IS_OK(status
)) {
817 printf("second open read-only of %s failed (%s)\n",
818 lockfname
, nt_errstr(status
));
819 cli_close(c1
, fnum1
);
823 for (i
= 0; i
< torture_numops
; i
++)
825 size_t buf_size
= ((unsigned)sys_random()%(sizeof(buf
)-1))+ 1;
827 printf("%d\r", i
); fflush(stdout
);
830 generate_random_buffer((unsigned char *)buf
, buf_size
);
832 status
= cli_writeall(c1
, fnum1
, 0, (uint8_t *)buf
, 0,
834 if (!NT_STATUS_IS_OK(status
)) {
835 printf("write failed (%s)\n", nt_errstr(status
));
840 if ((bytes_read
= cli_read(c2
, fnum2
, buf_rd
, 0, buf_size
)) != buf_size
) {
841 printf("read failed (%s)\n", cli_errstr(c2
));
842 printf("read %d, expected %ld\n", (int)bytes_read
,
843 (unsigned long)buf_size
);
848 if (memcmp(buf_rd
, buf
, buf_size
) != 0)
850 printf("read/write compare failed\n");
856 status
= cli_close(c2
, fnum2
);
857 if (!NT_STATUS_IS_OK(status
)) {
858 printf("close failed (%s)\n", nt_errstr(status
));
862 status
= cli_close(c1
, fnum1
);
863 if (!NT_STATUS_IS_OK(status
)) {
864 printf("close failed (%s)\n", nt_errstr(status
));
868 status
= cli_unlink(c1
, lockfname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
869 if (!NT_STATUS_IS_OK(status
)) {
870 printf("unlink failed (%s)\n", nt_errstr(status
));
877 static bool run_readwritetest(int dummy
)
879 struct cli_state
*cli1
, *cli2
;
880 bool test1
, test2
= False
;
882 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
885 cli_sockopt(cli1
, sockops
);
886 cli_sockopt(cli2
, sockops
);
888 printf("starting readwritetest\n");
890 test1
= rw_torture2(cli1
, cli2
);
891 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1
));
894 test2
= rw_torture2(cli1
, cli1
);
895 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2
));
898 if (!torture_close_connection(cli1
)) {
902 if (!torture_close_connection(cli2
)) {
906 return (test1
&& test2
);
909 static bool run_readwritemulti(int dummy
)
911 struct cli_state
*cli
;
916 cli_sockopt(cli
, sockops
);
918 printf("run_readwritemulti: fname %s\n", randomfname
);
919 test
= rw_torture3(cli
, randomfname
);
921 if (!torture_close_connection(cli
)) {
928 static bool run_readwritelarge_internal(int max_xmit_k
)
930 static struct cli_state
*cli1
;
932 const char *lockfname
= "\\large.dat";
938 if (!torture_open_connection(&cli1
, 0)) {
941 cli_sockopt(cli1
, sockops
);
942 memset(buf
,'\0',sizeof(buf
));
944 cli1
->max_xmit
= max_xmit_k
*1024;
946 if (signing_state
== Required
) {
947 /* Horrible cheat to force
948 multiple signed outstanding
949 packets against a Samba server.
951 cli1
->is_samba
= false;
954 printf("starting readwritelarge_internal\n");
956 cli_unlink(cli1
, lockfname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
958 status
= cli_open(cli1
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
,
960 if (!NT_STATUS_IS_OK(status
)) {
961 printf("open read/write of %s failed (%s)\n", lockfname
, nt_errstr(status
));
965 cli_writeall(cli1
, fnum1
, 0, (uint8_t *)buf
, 0, sizeof(buf
), NULL
);
967 status
= cli_qfileinfo_basic(cli1
, fnum1
, NULL
, &fsize
, NULL
, NULL
,
969 if (!NT_STATUS_IS_OK(status
)) {
970 printf("qfileinfo failed (%s)\n", nt_errstr(status
));
974 if (fsize
== sizeof(buf
))
975 printf("readwritelarge_internal test 1 succeeded (size = %lx)\n",
976 (unsigned long)fsize
);
978 printf("readwritelarge_internal test 1 failed (size = %lx)\n",
979 (unsigned long)fsize
);
983 status
= cli_close(cli1
, fnum1
);
984 if (!NT_STATUS_IS_OK(status
)) {
985 printf("close failed (%s)\n", nt_errstr(status
));
989 status
= cli_unlink(cli1
, lockfname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
990 if (!NT_STATUS_IS_OK(status
)) {
991 printf("unlink failed (%s)\n", nt_errstr(status
));
995 status
= cli_open(cli1
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
,
997 if (!NT_STATUS_IS_OK(status
)) {
998 printf("open read/write of %s failed (%s)\n", lockfname
, nt_errstr(status
));
1002 cli1
->max_xmit
= 4*1024;
1004 cli_smbwrite(cli1
, fnum1
, buf
, 0, sizeof(buf
), NULL
);
1006 status
= cli_qfileinfo_basic(cli1
, fnum1
, NULL
, &fsize
, NULL
, NULL
,
1008 if (!NT_STATUS_IS_OK(status
)) {
1009 printf("qfileinfo failed (%s)\n", nt_errstr(status
));
1013 if (fsize
== sizeof(buf
))
1014 printf("readwritelarge_internal test 2 succeeded (size = %lx)\n",
1015 (unsigned long)fsize
);
1017 printf("readwritelarge_internal test 2 failed (size = %lx)\n",
1018 (unsigned long)fsize
);
1023 /* ToDo - set allocation. JRA */
1024 if(!cli_set_allocation_size(cli1
, fnum1
, 0)) {
1025 printf("set allocation size to zero failed (%s)\n", cli_errstr(&cli1
));
1028 if (!cli_qfileinfo_basic(cli1
, fnum1
, NULL
, &fsize
, NULL
, NULL
, NULL
,
1030 printf("qfileinfo failed (%s)\n", cli_errstr(cli1
));
1034 printf("readwritelarge test 3 (truncate test) succeeded (size = %x)\n", fsize
);
1037 status
= cli_close(cli1
, fnum1
);
1038 if (!NT_STATUS_IS_OK(status
)) {
1039 printf("close failed (%s)\n", nt_errstr(status
));
1043 if (!torture_close_connection(cli1
)) {
1049 static bool run_readwritelarge(int dummy
)
1051 return run_readwritelarge_internal(128);
1054 static bool run_readwritelarge_signtest(int dummy
)
1057 signing_state
= Required
;
1058 ret
= run_readwritelarge_internal(2);
1059 signing_state
= Undefined
;
1066 #define ival(s) strtol(s, NULL, 0)
1068 /* run a test that simulates an approximate netbench client load */
1069 static bool run_netbench(int client
)
1071 struct cli_state
*cli
;
1076 const char *params
[20];
1077 bool correct
= True
;
1083 cli_sockopt(cli
, sockops
);
1087 slprintf(cname
,sizeof(cname
)-1, "client%d", client
);
1089 f
= fopen(client_txt
, "r");
1096 while (fgets(line
, sizeof(line
)-1, f
)) {
1100 line
[strlen(line
)-1] = 0;
1102 /* printf("[%d] %s\n", line_count, line); */
1104 all_string_sub(line
,"client1", cname
, sizeof(line
));
1106 /* parse the command parameters */
1107 params
[0] = strtok_r(line
, " ", &saveptr
);
1109 while (params
[i
]) params
[++i
] = strtok_r(NULL
, " ", &saveptr
);
1113 if (i
< 2) continue;
1115 if (!strncmp(params
[0],"SMB", 3)) {
1116 printf("ERROR: You are using a dbench 1 load file\n");
1120 if (!strcmp(params
[0],"NTCreateX")) {
1121 nb_createx(params
[1], ival(params
[2]), ival(params
[3]),
1123 } else if (!strcmp(params
[0],"Close")) {
1124 nb_close(ival(params
[1]));
1125 } else if (!strcmp(params
[0],"Rename")) {
1126 nb_rename(params
[1], params
[2]);
1127 } else if (!strcmp(params
[0],"Unlink")) {
1128 nb_unlink(params
[1]);
1129 } else if (!strcmp(params
[0],"Deltree")) {
1130 nb_deltree(params
[1]);
1131 } else if (!strcmp(params
[0],"Rmdir")) {
1132 nb_rmdir(params
[1]);
1133 } else if (!strcmp(params
[0],"QUERY_PATH_INFORMATION")) {
1134 nb_qpathinfo(params
[1]);
1135 } else if (!strcmp(params
[0],"QUERY_FILE_INFORMATION")) {
1136 nb_qfileinfo(ival(params
[1]));
1137 } else if (!strcmp(params
[0],"QUERY_FS_INFORMATION")) {
1138 nb_qfsinfo(ival(params
[1]));
1139 } else if (!strcmp(params
[0],"FIND_FIRST")) {
1140 nb_findfirst(params
[1]);
1141 } else if (!strcmp(params
[0],"WriteX")) {
1142 nb_writex(ival(params
[1]),
1143 ival(params
[2]), ival(params
[3]), ival(params
[4]));
1144 } else if (!strcmp(params
[0],"ReadX")) {
1145 nb_readx(ival(params
[1]),
1146 ival(params
[2]), ival(params
[3]), ival(params
[4]));
1147 } else if (!strcmp(params
[0],"Flush")) {
1148 nb_flush(ival(params
[1]));
1150 printf("Unknown operation %s\n", params
[0]);
1158 if (!torture_close_connection(cli
)) {
1166 /* run a test that simulates an approximate netbench client load */
1167 static bool run_nbench(int dummy
)
1170 bool correct
= True
;
1176 signal(SIGALRM
, nb_alarm
);
1178 t
= create_procs(run_netbench
, &correct
);
1181 printf("\nThroughput %g MB/sec\n",
1182 1.0e-6 * nbio_total() / t
);
1188 This test checks for two things:
1190 1) correct support for retaining locks over a close (ie. the server
1191 must not use posix semantics)
1192 2) support for lock timeouts
1194 static bool run_locktest1(int dummy
)
1196 struct cli_state
*cli1
, *cli2
;
1197 const char *fname
= "\\lockt1.lck";
1198 uint16_t fnum1
, fnum2
, fnum3
;
1200 unsigned lock_timeout
;
1203 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
1206 cli_sockopt(cli1
, sockops
);
1207 cli_sockopt(cli2
, sockops
);
1209 printf("starting locktest1\n");
1211 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
1213 status
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
,
1215 if (!NT_STATUS_IS_OK(status
)) {
1216 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
1220 status
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum2
);
1221 if (!NT_STATUS_IS_OK(status
)) {
1222 printf("open2 of %s failed (%s)\n", fname
, nt_errstr(status
));
1226 status
= cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
, &fnum3
);
1227 if (!NT_STATUS_IS_OK(status
)) {
1228 printf("open3 of %s failed (%s)\n", fname
, nt_errstr(status
));
1232 if (!cli_lock(cli1
, fnum1
, 0, 4, 0, WRITE_LOCK
)) {
1233 printf("lock1 failed (%s)\n", cli_errstr(cli1
));
1238 if (cli_lock(cli2
, fnum3
, 0, 4, 0, WRITE_LOCK
)) {
1239 printf("lock2 succeeded! This is a locking bug\n");
1242 if (!check_error(__LINE__
, cli2
, ERRDOS
, ERRlock
,
1243 NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
1247 lock_timeout
= (1 + (random() % 20));
1248 printf("Testing lock timeout with timeout=%u\n", lock_timeout
);
1250 if (cli_lock(cli2
, fnum3
, 0, 4, lock_timeout
* 1000, WRITE_LOCK
)) {
1251 printf("lock3 succeeded! This is a locking bug\n");
1254 if (!check_error(__LINE__
, cli2
, ERRDOS
, ERRlock
,
1255 NT_STATUS_FILE_LOCK_CONFLICT
)) return False
;
1259 if (ABS(t2
- t1
) < lock_timeout
-1) {
1260 printf("error: This server appears not to support timed lock requests\n");
1263 printf("server slept for %u seconds for a %u second timeout\n",
1264 (unsigned int)(t2
-t1
), lock_timeout
);
1266 status
= cli_close(cli1
, fnum2
);
1267 if (!NT_STATUS_IS_OK(status
)) {
1268 printf("close1 failed (%s)\n", nt_errstr(status
));
1272 if (cli_lock(cli2
, fnum3
, 0, 4, 0, WRITE_LOCK
)) {
1273 printf("lock4 succeeded! This is a locking bug\n");
1276 if (!check_error(__LINE__
, cli2
, ERRDOS
, ERRlock
,
1277 NT_STATUS_FILE_LOCK_CONFLICT
)) return False
;
1280 status
= cli_close(cli1
, fnum1
);
1281 if (!NT_STATUS_IS_OK(status
)) {
1282 printf("close2 failed (%s)\n", nt_errstr(status
));
1286 status
= cli_close(cli2
, fnum3
);
1287 if (!NT_STATUS_IS_OK(status
)) {
1288 printf("close3 failed (%s)\n", nt_errstr(status
));
1292 status
= cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
1293 if (!NT_STATUS_IS_OK(status
)) {
1294 printf("unlink failed (%s)\n", nt_errstr(status
));
1299 if (!torture_close_connection(cli1
)) {
1303 if (!torture_close_connection(cli2
)) {
1307 printf("Passed locktest1\n");
1312 this checks to see if a secondary tconx can use open files from an
1315 static bool run_tcon_test(int dummy
)
1317 static struct cli_state
*cli
;
1318 const char *fname
= "\\tcontest.tmp";
1320 uint16 cnum1
, cnum2
, cnum3
;
1321 uint16 vuid1
, vuid2
;
1326 memset(buf
, '\0', sizeof(buf
));
1328 if (!torture_open_connection(&cli
, 0)) {
1331 cli_sockopt(cli
, sockops
);
1333 printf("starting tcontest\n");
1335 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
1337 status
= cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
);
1338 if (!NT_STATUS_IS_OK(status
)) {
1339 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
1346 status
= cli_writeall(cli
, fnum1
, 0, (uint8_t *)buf
, 130, 4, NULL
);
1347 if (!NT_STATUS_IS_OK(status
)) {
1348 printf("initial write failed (%s)", nt_errstr(status
));
1352 status
= cli_tcon_andx(cli
, share
, "?????",
1353 password
, strlen(password
)+1);
1354 if (!NT_STATUS_IS_OK(status
)) {
1355 printf("%s refused 2nd tree connect (%s)\n", host
,
1362 cnum3
= MAX(cnum1
, cnum2
) + 1; /* any invalid number */
1363 vuid2
= cli
->vuid
+ 1;
1365 /* try a write with the wrong tid */
1368 status
= cli_writeall(cli
, fnum1
, 0, (uint8_t *)buf
, 130, 4, NULL
);
1369 if (NT_STATUS_IS_OK(status
)) {
1370 printf("* server allows write with wrong TID\n");
1373 printf("server fails write with wrong TID : %s\n",
1378 /* try a write with an invalid tid */
1381 status
= cli_writeall(cli
, fnum1
, 0, (uint8_t *)buf
, 130, 4, NULL
);
1382 if (NT_STATUS_IS_OK(status
)) {
1383 printf("* server allows write with invalid TID\n");
1386 printf("server fails write with invalid TID : %s\n",
1390 /* try a write with an invalid vuid */
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 invalid VUID\n");
1399 printf("server fails write with invalid VUID : %s\n",
1406 status
= cli_close(cli
, fnum1
);
1407 if (!NT_STATUS_IS_OK(status
)) {
1408 printf("close failed (%s)\n", nt_errstr(status
));
1414 status
= cli_tdis(cli
);
1415 if (!NT_STATUS_IS_OK(status
)) {
1416 printf("secondary tdis failed (%s)\n", nt_errstr(status
));
1422 if (!torture_close_connection(cli
)) {
1431 checks for old style tcon support
1433 static bool run_tcon2_test(int dummy
)
1435 static struct cli_state
*cli
;
1436 uint16 cnum
, max_xmit
;
1440 if (!torture_open_connection(&cli
, 0)) {
1443 cli_sockopt(cli
, sockops
);
1445 printf("starting tcon2 test\n");
1447 if (asprintf(&service
, "\\\\%s\\%s", host
, share
) == -1) {
1451 status
= cli_raw_tcon(cli
, service
, password
, "?????", &max_xmit
, &cnum
);
1455 if (!NT_STATUS_IS_OK(status
)) {
1456 printf("tcon2 failed : %s\n", nt_errstr(status
));
1458 printf("tcon OK : max_xmit=%d cnum=%d\n",
1459 (int)max_xmit
, (int)cnum
);
1462 if (!torture_close_connection(cli
)) {
1466 printf("Passed tcon2 test\n");
1470 static bool tcon_devtest(struct cli_state
*cli
,
1471 const char *myshare
, const char *devtype
,
1472 const char *return_devtype
,
1473 NTSTATUS expected_error
)
1478 status
= cli_tcon_andx(cli
, myshare
, devtype
,
1479 password
, strlen(password
)+1);
1481 if (NT_STATUS_IS_OK(expected_error
)) {
1482 if (NT_STATUS_IS_OK(status
)) {
1483 if (strcmp(cli
->dev
, return_devtype
) == 0) {
1486 printf("tconX to share %s with type %s "
1487 "succeeded but returned the wrong "
1488 "device type (got [%s] but should have got [%s])\n",
1489 myshare
, devtype
, cli
->dev
, return_devtype
);
1493 printf("tconX to share %s with type %s "
1494 "should have succeeded but failed\n",
1500 if (NT_STATUS_IS_OK(status
)) {
1501 printf("tconx to share %s with type %s "
1502 "should have failed but succeeded\n",
1506 if (NT_STATUS_EQUAL(cli_nt_error(cli
),
1510 printf("Returned unexpected error\n");
1519 checks for correct tconX support
1521 static bool run_tcon_devtype_test(int dummy
)
1523 static struct cli_state
*cli1
= NULL
;
1528 status
= cli_full_connection(&cli1
, myname
,
1529 host
, NULL
, port_to_use
,
1531 username
, workgroup
,
1532 password
, flags
, signing_state
);
1534 if (!NT_STATUS_IS_OK(status
)) {
1535 printf("could not open connection\n");
1539 if (!tcon_devtest(cli1
, "IPC$", "A:", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1542 if (!tcon_devtest(cli1
, "IPC$", "?????", "IPC", NT_STATUS_OK
))
1545 if (!tcon_devtest(cli1
, "IPC$", "LPT:", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1548 if (!tcon_devtest(cli1
, "IPC$", "IPC", "IPC", NT_STATUS_OK
))
1551 if (!tcon_devtest(cli1
, "IPC$", "FOOBA", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1554 if (!tcon_devtest(cli1
, share
, "A:", "A:", NT_STATUS_OK
))
1557 if (!tcon_devtest(cli1
, share
, "?????", "A:", NT_STATUS_OK
))
1560 if (!tcon_devtest(cli1
, share
, "LPT:", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1563 if (!tcon_devtest(cli1
, share
, "IPC", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1566 if (!tcon_devtest(cli1
, share
, "FOOBA", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1572 printf("Passed tcondevtest\n");
1579 This test checks that
1581 1) the server supports multiple locking contexts on the one SMB
1582 connection, distinguished by PID.
1584 2) the server correctly fails overlapping locks made by the same PID (this
1585 goes against POSIX behaviour, which is why it is tricky to implement)
1587 3) the server denies unlock requests by an incorrect client PID
1589 static bool run_locktest2(int dummy
)
1591 static struct cli_state
*cli
;
1592 const char *fname
= "\\lockt2.lck";
1593 uint16_t fnum1
, fnum2
, fnum3
;
1594 bool correct
= True
;
1597 if (!torture_open_connection(&cli
, 0)) {
1601 cli_sockopt(cli
, sockops
);
1603 printf("starting locktest2\n");
1605 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
1609 status
= cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
);
1610 if (!NT_STATUS_IS_OK(status
)) {
1611 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
1615 status
= cli_open(cli
, fname
, O_RDWR
, DENY_NONE
, &fnum2
);
1616 if (!NT_STATUS_IS_OK(status
)) {
1617 printf("open2 of %s failed (%s)\n", fname
, nt_errstr(status
));
1623 status
= cli_open(cli
, fname
, O_RDWR
, DENY_NONE
, &fnum3
);
1624 if (!NT_STATUS_IS_OK(status
)) {
1625 printf("open3 of %s failed (%s)\n", fname
, nt_errstr(status
));
1631 if (!cli_lock(cli
, fnum1
, 0, 4, 0, WRITE_LOCK
)) {
1632 printf("lock1 failed (%s)\n", cli_errstr(cli
));
1636 if (cli_lock(cli
, fnum1
, 0, 4, 0, WRITE_LOCK
)) {
1637 printf("WRITE lock1 succeeded! This is a locking bug\n");
1640 if (!check_error(__LINE__
, cli
, ERRDOS
, ERRlock
,
1641 NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
1644 if (cli_lock(cli
, fnum2
, 0, 4, 0, WRITE_LOCK
)) {
1645 printf("WRITE lock2 succeeded! This is a locking bug\n");
1648 if (!check_error(__LINE__
, cli
, ERRDOS
, ERRlock
,
1649 NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
1652 if (cli_lock(cli
, fnum2
, 0, 4, 0, READ_LOCK
)) {
1653 printf("READ lock2 succeeded! This is a locking bug\n");
1656 if (!check_error(__LINE__
, cli
, ERRDOS
, ERRlock
,
1657 NT_STATUS_FILE_LOCK_CONFLICT
)) return False
;
1660 if (!cli_lock(cli
, fnum1
, 100, 4, 0, WRITE_LOCK
)) {
1661 printf("lock at 100 failed (%s)\n", cli_errstr(cli
));
1664 if (NT_STATUS_IS_OK(cli_unlock(cli
, fnum1
, 100, 4))) {
1665 printf("unlock at 100 succeeded! This is a locking bug\n");
1669 if (NT_STATUS_IS_OK(cli_unlock(cli
, fnum1
, 0, 4))) {
1670 printf("unlock1 succeeded! This is a locking bug\n");
1673 if (!check_error(__LINE__
, cli
,
1675 NT_STATUS_RANGE_NOT_LOCKED
)) return False
;
1678 if (NT_STATUS_IS_OK(cli_unlock(cli
, fnum1
, 0, 8))) {
1679 printf("unlock2 succeeded! This is a locking bug\n");
1682 if (!check_error(__LINE__
, cli
,
1684 NT_STATUS_RANGE_NOT_LOCKED
)) return False
;
1687 if (cli_lock(cli
, fnum3
, 0, 4, 0, WRITE_LOCK
)) {
1688 printf("lock3 succeeded! This is a locking bug\n");
1691 if (!check_error(__LINE__
, cli
, ERRDOS
, ERRlock
, NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
1696 status
= cli_close(cli
, fnum1
);
1697 if (!NT_STATUS_IS_OK(status
)) {
1698 printf("close1 failed (%s)\n", nt_errstr(status
));
1702 status
= cli_close(cli
, fnum2
);
1703 if (!NT_STATUS_IS_OK(status
)) {
1704 printf("close2 failed (%s)\n", nt_errstr(status
));
1708 status
= cli_close(cli
, fnum3
);
1709 if (!NT_STATUS_IS_OK(status
)) {
1710 printf("close3 failed (%s)\n", nt_errstr(status
));
1714 if (!torture_close_connection(cli
)) {
1718 printf("locktest2 finished\n");
1725 This test checks that
1727 1) the server supports the full offset range in lock requests
1729 static bool run_locktest3(int dummy
)
1731 static struct cli_state
*cli1
, *cli2
;
1732 const char *fname
= "\\lockt3.lck";
1733 uint16_t fnum1
, fnum2
;
1736 bool correct
= True
;
1739 #define NEXT_OFFSET offset += (~(uint32)0) / torture_numops
1741 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
1744 cli_sockopt(cli1
, sockops
);
1745 cli_sockopt(cli2
, sockops
);
1747 printf("starting locktest3\n");
1749 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
1751 status
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
,
1753 if (!NT_STATUS_IS_OK(status
)) {
1754 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
1758 status
= cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
, &fnum2
);
1759 if (!NT_STATUS_IS_OK(status
)) {
1760 printf("open2 of %s failed (%s)\n", fname
, nt_errstr(status
));
1764 for (offset
=i
=0;i
<torture_numops
;i
++) {
1766 if (!cli_lock(cli1
, fnum1
, offset
-1, 1, 0, WRITE_LOCK
)) {
1767 printf("lock1 %d failed (%s)\n",
1773 if (!cli_lock(cli2
, fnum2
, offset
-2, 1, 0, WRITE_LOCK
)) {
1774 printf("lock2 %d failed (%s)\n",
1781 for (offset
=i
=0;i
<torture_numops
;i
++) {
1784 if (cli_lock(cli1
, fnum1
, offset
-2, 1, 0, WRITE_LOCK
)) {
1785 printf("error: lock1 %d succeeded!\n", i
);
1789 if (cli_lock(cli2
, fnum2
, offset
-1, 1, 0, WRITE_LOCK
)) {
1790 printf("error: lock2 %d succeeded!\n", i
);
1794 if (cli_lock(cli1
, fnum1
, offset
-1, 1, 0, WRITE_LOCK
)) {
1795 printf("error: lock3 %d succeeded!\n", i
);
1799 if (cli_lock(cli2
, fnum2
, offset
-2, 1, 0, WRITE_LOCK
)) {
1800 printf("error: lock4 %d succeeded!\n", i
);
1805 for (offset
=i
=0;i
<torture_numops
;i
++) {
1808 status
= cli_unlock(cli1
, fnum1
, offset
-1, 1);
1809 if (!NT_STATUS_IS_OK(status
)) {
1810 printf("unlock1 %d failed (%s)\n",
1816 status
= cli_unlock(cli2
, fnum2
, offset
-2, 1);
1817 if (!NT_STATUS_IS_OK(status
)) {
1818 printf("unlock2 %d failed (%s)\n",
1825 status
= cli_close(cli1
, fnum1
);
1826 if (!NT_STATUS_IS_OK(status
)) {
1827 printf("close1 failed (%s)\n", nt_errstr(status
));
1831 status
= cli_close(cli2
, fnum2
);
1832 if (!NT_STATUS_IS_OK(status
)) {
1833 printf("close2 failed (%s)\n", nt_errstr(status
));
1837 status
= cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
1838 if (!NT_STATUS_IS_OK(status
)) {
1839 printf("unlink failed (%s)\n", nt_errstr(status
));
1843 if (!torture_close_connection(cli1
)) {
1847 if (!torture_close_connection(cli2
)) {
1851 printf("finished locktest3\n");
1856 #define EXPECTED(ret, v) if ((ret) != (v)) { \
1857 printf("** "); correct = False; \
1861 looks at overlapping locks
1863 static bool run_locktest4(int dummy
)
1865 static struct cli_state
*cli1
, *cli2
;
1866 const char *fname
= "\\lockt4.lck";
1867 uint16_t fnum1
, fnum2
, f
;
1870 bool correct
= True
;
1873 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
1877 cli_sockopt(cli1
, sockops
);
1878 cli_sockopt(cli2
, sockops
);
1880 printf("starting locktest4\n");
1882 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
1884 cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
);
1885 cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
, &fnum2
);
1887 memset(buf
, 0, sizeof(buf
));
1889 status
= cli_writeall(cli1
, fnum1
, 0, (uint8_t *)buf
, 0, sizeof(buf
),
1891 if (!NT_STATUS_IS_OK(status
)) {
1892 printf("Failed to create file: %s\n", nt_errstr(status
));
1897 ret
= cli_lock(cli1
, fnum1
, 0, 4, 0, WRITE_LOCK
) &&
1898 cli_lock(cli1
, fnum1
, 2, 4, 0, WRITE_LOCK
);
1899 EXPECTED(ret
, False
);
1900 printf("the same process %s set overlapping write locks\n", ret
?"can":"cannot");
1902 ret
= cli_lock(cli1
, fnum1
, 10, 4, 0, READ_LOCK
) &&
1903 cli_lock(cli1
, fnum1
, 12, 4, 0, READ_LOCK
);
1904 EXPECTED(ret
, True
);
1905 printf("the same process %s set overlapping read locks\n", ret
?"can":"cannot");
1907 ret
= cli_lock(cli1
, fnum1
, 20, 4, 0, WRITE_LOCK
) &&
1908 cli_lock(cli2
, fnum2
, 22, 4, 0, WRITE_LOCK
);
1909 EXPECTED(ret
, False
);
1910 printf("a different connection %s set overlapping write locks\n", ret
?"can":"cannot");
1912 ret
= cli_lock(cli1
, fnum1
, 30, 4, 0, READ_LOCK
) &&
1913 cli_lock(cli2
, fnum2
, 32, 4, 0, READ_LOCK
);
1914 EXPECTED(ret
, True
);
1915 printf("a different connection %s set overlapping read locks\n", ret
?"can":"cannot");
1917 ret
= (cli_setpid(cli1
, 1), cli_lock(cli1
, fnum1
, 40, 4, 0, WRITE_LOCK
)) &&
1918 (cli_setpid(cli1
, 2), cli_lock(cli1
, fnum1
, 42, 4, 0, WRITE_LOCK
));
1919 EXPECTED(ret
, False
);
1920 printf("a different pid %s set overlapping write locks\n", ret
?"can":"cannot");
1922 ret
= (cli_setpid(cli1
, 1), cli_lock(cli1
, fnum1
, 50, 4, 0, READ_LOCK
)) &&
1923 (cli_setpid(cli1
, 2), cli_lock(cli1
, fnum1
, 52, 4, 0, READ_LOCK
));
1924 EXPECTED(ret
, True
);
1925 printf("a different pid %s set overlapping read locks\n", ret
?"can":"cannot");
1927 ret
= cli_lock(cli1
, fnum1
, 60, 4, 0, READ_LOCK
) &&
1928 cli_lock(cli1
, fnum1
, 60, 4, 0, READ_LOCK
);
1929 EXPECTED(ret
, True
);
1930 printf("the same process %s set the same read lock twice\n", ret
?"can":"cannot");
1932 ret
= cli_lock(cli1
, fnum1
, 70, 4, 0, WRITE_LOCK
) &&
1933 cli_lock(cli1
, fnum1
, 70, 4, 0, WRITE_LOCK
);
1934 EXPECTED(ret
, False
);
1935 printf("the same process %s set the same write lock twice\n", ret
?"can":"cannot");
1937 ret
= cli_lock(cli1
, fnum1
, 80, 4, 0, READ_LOCK
) &&
1938 cli_lock(cli1
, fnum1
, 80, 4, 0, WRITE_LOCK
);
1939 EXPECTED(ret
, False
);
1940 printf("the same process %s overlay a read lock with a write lock\n", ret
?"can":"cannot");
1942 ret
= cli_lock(cli1
, fnum1
, 90, 4, 0, WRITE_LOCK
) &&
1943 cli_lock(cli1
, fnum1
, 90, 4, 0, READ_LOCK
);
1944 EXPECTED(ret
, True
);
1945 printf("the same process %s overlay a write lock with a read lock\n", ret
?"can":"cannot");
1947 ret
= (cli_setpid(cli1
, 1), cli_lock(cli1
, fnum1
, 100, 4, 0, WRITE_LOCK
)) &&
1948 (cli_setpid(cli1
, 2), cli_lock(cli1
, fnum1
, 100, 4, 0, READ_LOCK
));
1949 EXPECTED(ret
, False
);
1950 printf("a different pid %s overlay a write lock with a read lock\n", ret
?"can":"cannot");
1952 ret
= cli_lock(cli1
, fnum1
, 110, 4, 0, READ_LOCK
) &&
1953 cli_lock(cli1
, fnum1
, 112, 4, 0, READ_LOCK
) &&
1954 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 110, 6));
1955 EXPECTED(ret
, False
);
1956 printf("the same process %s coalesce read locks\n", ret
?"can":"cannot");
1959 ret
= cli_lock(cli1
, fnum1
, 120, 4, 0, WRITE_LOCK
) &&
1960 (cli_read(cli2
, fnum2
, buf
, 120, 4) == 4);
1961 EXPECTED(ret
, False
);
1962 printf("this server %s strict write locking\n", ret
?"doesn't do":"does");
1964 ret
= cli_lock(cli1
, fnum1
, 130, 4, 0, READ_LOCK
);
1966 status
= cli_writeall(cli2
, fnum2
, 0, (uint8_t *)buf
, 130, 4,
1968 ret
= NT_STATUS_IS_OK(status
);
1970 EXPECTED(ret
, False
);
1971 printf("this server %s strict read locking\n", ret
?"doesn't do":"does");
1974 ret
= cli_lock(cli1
, fnum1
, 140, 4, 0, READ_LOCK
) &&
1975 cli_lock(cli1
, fnum1
, 140, 4, 0, READ_LOCK
) &&
1976 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 140, 4)) &&
1977 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 140, 4));
1978 EXPECTED(ret
, True
);
1979 printf("this server %s do recursive read locking\n", ret
?"does":"doesn't");
1982 ret
= cli_lock(cli1
, fnum1
, 150, 4, 0, WRITE_LOCK
) &&
1983 cli_lock(cli1
, fnum1
, 150, 4, 0, READ_LOCK
) &&
1984 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 150, 4)) &&
1985 (cli_read(cli2
, fnum2
, buf
, 150, 4) == 4) &&
1986 !(NT_STATUS_IS_OK(cli_writeall(cli2
, fnum2
, 0, (uint8_t *)buf
,
1988 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 150, 4));
1989 EXPECTED(ret
, True
);
1990 printf("this server %s do recursive lock overlays\n", ret
?"does":"doesn't");
1992 ret
= cli_lock(cli1
, fnum1
, 160, 4, 0, READ_LOCK
) &&
1993 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 160, 4)) &&
1994 NT_STATUS_IS_OK(cli_writeall(cli2
, fnum2
, 0, (uint8_t *)buf
,
1996 (cli_read(cli2
, fnum2
, buf
, 160, 4) == 4);
1997 EXPECTED(ret
, True
);
1998 printf("the same process %s remove a read lock using write locking\n", ret
?"can":"cannot");
2000 ret
= cli_lock(cli1
, fnum1
, 170, 4, 0, WRITE_LOCK
) &&
2001 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 170, 4)) &&
2002 NT_STATUS_IS_OK(cli_writeall(cli2
, fnum2
, 0, (uint8_t *)buf
,
2004 (cli_read(cli2
, fnum2
, buf
, 170, 4) == 4);
2005 EXPECTED(ret
, True
);
2006 printf("the same process %s remove a write lock using read locking\n", ret
?"can":"cannot");
2008 ret
= cli_lock(cli1
, fnum1
, 190, 4, 0, WRITE_LOCK
) &&
2009 cli_lock(cli1
, fnum1
, 190, 4, 0, READ_LOCK
) &&
2010 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 190, 4)) &&
2011 !NT_STATUS_IS_OK(cli_writeall(cli2
, fnum2
, 0, (uint8_t *)buf
,
2013 (cli_read(cli2
, fnum2
, buf
, 190, 4) == 4);
2014 EXPECTED(ret
, True
);
2015 printf("the same process %s remove the first lock first\n", ret
?"does":"doesn't");
2017 cli_close(cli1
, fnum1
);
2018 cli_close(cli2
, fnum2
);
2019 cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
);
2020 cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &f
);
2021 ret
= cli_lock(cli1
, fnum1
, 0, 8, 0, READ_LOCK
) &&
2022 cli_lock(cli1
, f
, 0, 1, 0, READ_LOCK
) &&
2023 NT_STATUS_IS_OK(cli_close(cli1
, fnum1
)) &&
2024 NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
)) &&
2025 cli_lock(cli1
, fnum1
, 7, 1, 0, WRITE_LOCK
);
2027 cli_close(cli1
, fnum1
);
2028 EXPECTED(ret
, True
);
2029 printf("the server %s have the NT byte range lock bug\n", !ret
?"does":"doesn't");
2032 cli_close(cli1
, fnum1
);
2033 cli_close(cli2
, fnum2
);
2034 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2035 torture_close_connection(cli1
);
2036 torture_close_connection(cli2
);
2038 printf("finished locktest4\n");
2043 looks at lock upgrade/downgrade.
2045 static bool run_locktest5(int dummy
)
2047 static struct cli_state
*cli1
, *cli2
;
2048 const char *fname
= "\\lockt5.lck";
2049 uint16_t fnum1
, fnum2
, fnum3
;
2052 bool correct
= True
;
2055 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
2059 cli_sockopt(cli1
, sockops
);
2060 cli_sockopt(cli2
, sockops
);
2062 printf("starting locktest5\n");
2064 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2066 cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
);
2067 cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
, &fnum2
);
2068 cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum3
);
2070 memset(buf
, 0, sizeof(buf
));
2072 status
= cli_writeall(cli1
, fnum1
, 0, (uint8_t *)buf
, 0, sizeof(buf
),
2074 if (!NT_STATUS_IS_OK(status
)) {
2075 printf("Failed to create file: %s\n", nt_errstr(status
));
2080 /* Check for NT bug... */
2081 ret
= cli_lock(cli1
, fnum1
, 0, 8, 0, READ_LOCK
) &&
2082 cli_lock(cli1
, fnum3
, 0, 1, 0, READ_LOCK
);
2083 cli_close(cli1
, fnum1
);
2084 cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
);
2085 ret
= cli_lock(cli1
, fnum1
, 7, 1, 0, WRITE_LOCK
);
2086 EXPECTED(ret
, True
);
2087 printf("this server %s the NT locking bug\n", ret
? "doesn't have" : "has");
2088 cli_close(cli1
, fnum1
);
2089 cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
);
2090 cli_unlock(cli1
, fnum3
, 0, 1);
2092 ret
= cli_lock(cli1
, fnum1
, 0, 4, 0, WRITE_LOCK
) &&
2093 cli_lock(cli1
, fnum1
, 1, 1, 0, READ_LOCK
);
2094 EXPECTED(ret
, True
);
2095 printf("the same process %s overlay a write with a read lock\n", ret
?"can":"cannot");
2097 ret
= cli_lock(cli2
, fnum2
, 0, 4, 0, READ_LOCK
);
2098 EXPECTED(ret
, False
);
2100 printf("a different processs %s get a read lock on the first process lock stack\n", ret
?"can":"cannot");
2102 /* Unlock the process 2 lock. */
2103 cli_unlock(cli2
, fnum2
, 0, 4);
2105 ret
= cli_lock(cli1
, fnum3
, 0, 4, 0, READ_LOCK
);
2106 EXPECTED(ret
, False
);
2108 printf("the same processs on a different fnum %s get a read lock\n", ret
?"can":"cannot");
2110 /* Unlock the process 1 fnum3 lock. */
2111 cli_unlock(cli1
, fnum3
, 0, 4);
2113 /* Stack 2 more locks here. */
2114 ret
= cli_lock(cli1
, fnum1
, 0, 4, 0, READ_LOCK
) &&
2115 cli_lock(cli1
, fnum1
, 0, 4, 0, READ_LOCK
);
2117 EXPECTED(ret
, True
);
2118 printf("the same process %s stack read locks\n", ret
?"can":"cannot");
2120 /* Unlock the first process lock, then check this was the WRITE lock that was
2123 ret
= NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 0, 4)) &&
2124 cli_lock(cli2
, fnum2
, 0, 4, 0, READ_LOCK
);
2126 EXPECTED(ret
, True
);
2127 printf("the first unlock removes the %s lock\n", ret
?"WRITE":"READ");
2129 /* Unlock the process 2 lock. */
2130 cli_unlock(cli2
, fnum2
, 0, 4);
2132 /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */
2134 ret
= NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 1, 1)) &&
2135 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 0, 4)) &&
2136 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 0, 4));
2138 EXPECTED(ret
, True
);
2139 printf("the same process %s unlock the stack of 4 locks\n", ret
?"can":"cannot");
2141 /* Ensure the next unlock fails. */
2142 ret
= NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 0, 4));
2143 EXPECTED(ret
, False
);
2144 printf("the same process %s count the lock stack\n", !ret
?"can":"cannot");
2146 /* Ensure connection 2 can get a write lock. */
2147 ret
= cli_lock(cli2
, fnum2
, 0, 4, 0, WRITE_LOCK
);
2148 EXPECTED(ret
, True
);
2150 printf("a different processs %s get a write lock on the unlocked stack\n", ret
?"can":"cannot");
2154 cli_close(cli1
, fnum1
);
2155 cli_close(cli2
, fnum2
);
2156 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2157 if (!torture_close_connection(cli1
)) {
2160 if (!torture_close_connection(cli2
)) {
2164 printf("finished locktest5\n");
2170 tries the unusual lockingX locktype bits
2172 static bool run_locktest6(int dummy
)
2174 static struct cli_state
*cli
;
2175 const char *fname
[1] = { "\\lock6.txt" };
2180 if (!torture_open_connection(&cli
, 0)) {
2184 cli_sockopt(cli
, sockops
);
2186 printf("starting locktest6\n");
2189 printf("Testing %s\n", fname
[i
]);
2191 cli_unlink(cli
, fname
[i
], FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2193 cli_open(cli
, fname
[i
], O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum
);
2194 status
= cli_locktype(cli
, fnum
, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE
);
2195 cli_close(cli
, fnum
);
2196 printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status
));
2198 cli_open(cli
, fname
[i
], O_RDWR
, DENY_NONE
, &fnum
);
2199 status
= cli_locktype(cli
, fnum
, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK
);
2200 cli_close(cli
, fnum
);
2201 printf("CANCEL_LOCK gave %s\n", nt_errstr(status
));
2203 cli_unlink(cli
, fname
[i
], FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2206 torture_close_connection(cli
);
2208 printf("finished locktest6\n");
2212 static bool run_locktest7(int dummy
)
2214 struct cli_state
*cli1
;
2215 const char *fname
= "\\lockt7.lck";
2218 bool correct
= False
;
2221 if (!torture_open_connection(&cli1
, 0)) {
2225 cli_sockopt(cli1
, sockops
);
2227 printf("starting locktest7\n");
2229 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2231 cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
);
2233 memset(buf
, 0, sizeof(buf
));
2235 status
= cli_writeall(cli1
, fnum1
, 0, (uint8_t *)buf
, 0, sizeof(buf
),
2237 if (!NT_STATUS_IS_OK(status
)) {
2238 printf("Failed to create file: %s\n", nt_errstr(status
));
2242 cli_setpid(cli1
, 1);
2244 if (!cli_lock(cli1
, fnum1
, 130, 4, 0, READ_LOCK
)) {
2245 printf("Unable to apply read lock on range 130:4, error was %s\n", cli_errstr(cli1
));
2248 printf("pid1 successfully locked range 130:4 for READ\n");
2251 if (cli_read(cli1
, fnum1
, buf
, 130, 4) != 4) {
2252 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1
));
2255 printf("pid1 successfully read the range 130:4\n");
2258 status
= cli_writeall(cli1
, fnum1
, 0, (uint8_t *)buf
, 130, 4, NULL
);
2259 if (!NT_STATUS_IS_OK(status
)) {
2260 printf("pid1 unable to write to the range 130:4, error was "
2261 "%s\n", nt_errstr(status
));
2262 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_LOCK_CONFLICT
)) {
2263 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2267 printf("pid1 successfully wrote to the range 130:4 (should be denied)\n");
2271 cli_setpid(cli1
, 2);
2273 if (cli_read(cli1
, fnum1
, buf
, 130, 4) != 4) {
2274 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1
));
2276 printf("pid2 successfully read the range 130:4\n");
2279 status
= cli_writeall(cli1
, fnum1
, 0, (uint8_t *)buf
, 130, 4, NULL
);
2280 if (!NT_STATUS_IS_OK(status
)) {
2281 printf("pid2 unable to write to the range 130:4, error was "
2282 "%s\n", nt_errstr(status
));
2283 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_LOCK_CONFLICT
)) {
2284 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2288 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
2292 cli_setpid(cli1
, 1);
2293 cli_unlock(cli1
, fnum1
, 130, 4);
2295 if (!cli_lock(cli1
, fnum1
, 130, 4, 0, WRITE_LOCK
)) {
2296 printf("Unable to apply write lock on range 130:4, error was %s\n", cli_errstr(cli1
));
2299 printf("pid1 successfully locked range 130:4 for WRITE\n");
2302 if (cli_read(cli1
, fnum1
, buf
, 130, 4) != 4) {
2303 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1
));
2306 printf("pid1 successfully read the range 130:4\n");
2309 status
= cli_writeall(cli1
, fnum1
, 0, (uint8_t *)buf
, 130, 4, NULL
);
2310 if (!NT_STATUS_IS_OK(status
)) {
2311 printf("pid1 unable to write to the range 130:4, error was "
2312 "%s\n", nt_errstr(status
));
2315 printf("pid1 successfully wrote to the range 130:4\n");
2318 cli_setpid(cli1
, 2);
2320 if (cli_read(cli1
, fnum1
, buf
, 130, 4) != 4) {
2321 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1
));
2322 if (NT_STATUS_V(cli_nt_error(cli1
)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT
)) {
2323 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2327 printf("pid2 successfully read the range 130:4 (should be denied)\n");
2331 status
= cli_writeall(cli1
, fnum1
, 0, (uint8_t *)buf
, 130, 4, NULL
);
2332 if (!NT_STATUS_IS_OK(status
)) {
2333 printf("pid2 unable to write to the range 130:4, error was "
2334 "%s\n", nt_errstr(status
));
2335 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_LOCK_CONFLICT
)) {
2336 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2340 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
2344 cli_unlock(cli1
, fnum1
, 130, 0);
2348 cli_close(cli1
, fnum1
);
2349 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2350 torture_close_connection(cli1
);
2352 printf("finished locktest7\n");
2357 * This demonstrates a problem with our use of GPFS share modes: A file
2358 * descriptor sitting in the pending close queue holding a GPFS share mode
2359 * blocks opening a file another time. Happens with Word 2007 temp files.
2360 * With "posix locking = yes" and "gpfs:sharemodes = yes" enabled, the third
2361 * open is denied with NT_STATUS_SHARING_VIOLATION.
2364 static bool run_locktest8(int dummy
)
2366 struct cli_state
*cli1
;
2367 const char *fname
= "\\lockt8.lck";
2368 uint16_t fnum1
, fnum2
;
2370 bool correct
= False
;
2373 if (!torture_open_connection(&cli1
, 0)) {
2377 cli_sockopt(cli1
, sockops
);
2379 printf("starting locktest8\n");
2381 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2383 status
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_WRITE
,
2385 if (!NT_STATUS_IS_OK(status
)) {
2386 d_fprintf(stderr
, "cli_open returned %s\n", nt_errstr(status
));
2390 memset(buf
, 0, sizeof(buf
));
2392 status
= cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
, &fnum2
);
2393 if (!NT_STATUS_IS_OK(status
)) {
2394 d_fprintf(stderr
, "cli_open second time returned %s\n",
2399 if (!cli_lock(cli1
, fnum2
, 1, 1, 0, READ_LOCK
)) {
2400 printf("Unable to apply read lock on range 1:1, error was "
2401 "%s\n", cli_errstr(cli1
));
2405 status
= cli_close(cli1
, fnum1
);
2406 if (!NT_STATUS_IS_OK(status
)) {
2407 d_fprintf(stderr
, "cli_close(fnum1) %s\n", nt_errstr(status
));
2411 status
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
);
2412 if (!NT_STATUS_IS_OK(status
)) {
2413 d_fprintf(stderr
, "cli_open third time returned %s\n",
2421 cli_close(cli1
, fnum1
);
2422 cli_close(cli1
, fnum2
);
2423 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2424 torture_close_connection(cli1
);
2426 printf("finished locktest8\n");
2431 * This test is designed to be run in conjunction with
2432 * external NFS or POSIX locks taken in the filesystem.
2433 * It checks that the smbd server will block until the
2434 * lock is released and then acquire it. JRA.
2437 static bool got_alarm
;
2438 static int alarm_fd
;
2440 static void alarm_handler(int dummy
)
2445 static void alarm_handler_parent(int dummy
)
2450 static void do_local_lock(int read_fd
, int write_fd
)
2455 const char *local_pathname
= NULL
;
2458 local_pathname
= talloc_asprintf(talloc_tos(),
2459 "%s/lockt9.lck", local_path
);
2460 if (!local_pathname
) {
2461 printf("child: alloc fail\n");
2465 unlink(local_pathname
);
2466 fd
= open(local_pathname
, O_RDWR
|O_CREAT
, 0666);
2468 printf("child: open of %s failed %s.\n",
2469 local_pathname
, strerror(errno
));
2473 /* Now take a fcntl lock. */
2474 lock
.l_type
= F_WRLCK
;
2475 lock
.l_whence
= SEEK_SET
;
2478 lock
.l_pid
= getpid();
2480 ret
= fcntl(fd
,F_SETLK
,&lock
);
2482 printf("child: failed to get lock 0:4 on file %s. Error %s\n",
2483 local_pathname
, strerror(errno
));
2486 printf("child: got lock 0:4 on file %s.\n",
2491 CatchSignal(SIGALRM
, alarm_handler
);
2493 /* Signal the parent. */
2494 if (write(write_fd
, &c
, 1) != 1) {
2495 printf("child: start signal fail %s.\n",
2502 /* Wait for the parent to be ready. */
2503 if (read(read_fd
, &c
, 1) != 1) {
2504 printf("child: reply signal fail %s.\n",
2512 printf("child: released lock 0:4 on file %s.\n",
2518 static bool run_locktest9(int dummy
)
2520 struct cli_state
*cli1
;
2521 const char *fname
= "\\lockt9.lck";
2523 bool correct
= False
;
2524 int pipe_in
[2], pipe_out
[2];
2528 struct timeval start
;
2532 printf("starting locktest9\n");
2534 if (local_path
== NULL
) {
2535 d_fprintf(stderr
, "locktest9 must be given a local path via -l <localpath>\n");
2539 if (pipe(pipe_in
) == -1 || pipe(pipe_out
) == -1) {
2544 if (child_pid
== -1) {
2548 if (child_pid
== 0) {
2550 do_local_lock(pipe_out
[0], pipe_in
[1]);
2560 ret
= read(pipe_in
[0], &c
, 1);
2562 d_fprintf(stderr
, "failed to read start signal from child. %s\n",
2567 if (!torture_open_connection(&cli1
, 0)) {
2571 cli_sockopt(cli1
, sockops
);
2573 status
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
,
2575 if (!NT_STATUS_IS_OK(status
)) {
2576 d_fprintf(stderr
, "cli_open returned %s\n", nt_errstr(status
));
2580 /* Ensure the child has the lock. */
2581 if (cli_lock(cli1
, fnum
, 0, 4, 0, WRITE_LOCK
)) {
2582 d_fprintf(stderr
, "Got the lock on range 0:4 - this should not happen !\n");
2585 d_printf("Child has the lock.\n");
2588 /* Tell the child to wait 5 seconds then exit. */
2589 ret
= write(pipe_out
[1], &c
, 1);
2591 d_fprintf(stderr
, "failed to send exit signal to child. %s\n",
2596 /* Wait 20 seconds for the lock. */
2597 alarm_fd
= cli1
->fd
;
2598 CatchSignal(SIGALRM
, alarm_handler_parent
);
2601 start
= timeval_current();
2603 if (!cli_lock(cli1
, fnum
, 0, 4, -1, WRITE_LOCK
)) {
2604 d_fprintf(stderr
, "Unable to apply write lock on range 0:4, error was "
2605 "%s\n", cli_errstr(cli1
));
2610 seconds
= timeval_elapsed(&start
);
2612 printf("Parent got the lock after %.2f seconds.\n",
2615 status
= cli_close(cli1
, fnum
);
2616 if (!NT_STATUS_IS_OK(status
)) {
2617 d_fprintf(stderr
, "cli_close(fnum1) %s\n", nt_errstr(status
));
2624 cli_close(cli1
, fnum
);
2625 torture_close_connection(cli1
);
2629 printf("finished locktest9\n");
2634 test whether fnums and tids open on one VC are available on another (a major
2637 static bool run_fdpasstest(int dummy
)
2639 struct cli_state
*cli1
, *cli2
;
2640 const char *fname
= "\\fdpass.tst";
2645 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
2648 cli_sockopt(cli1
, sockops
);
2649 cli_sockopt(cli2
, sockops
);
2651 printf("starting fdpasstest\n");
2653 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2655 status
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
,
2657 if (!NT_STATUS_IS_OK(status
)) {
2658 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
2662 status
= cli_writeall(cli1
, fnum1
, 0, (const uint8_t *)"hello world\n", 0,
2664 if (!NT_STATUS_IS_OK(status
)) {
2665 printf("write failed (%s)\n", nt_errstr(status
));
2669 cli2
->vuid
= cli1
->vuid
;
2670 cli2
->cnum
= cli1
->cnum
;
2671 cli2
->pid
= cli1
->pid
;
2673 if (cli_read(cli2
, fnum1
, buf
, 0, 13) == 13) {
2674 printf("read succeeded! nasty security hole [%s]\n",
2679 cli_close(cli1
, fnum1
);
2680 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2682 torture_close_connection(cli1
);
2683 torture_close_connection(cli2
);
2685 printf("finished fdpasstest\n");
2689 static bool run_fdsesstest(int dummy
)
2691 struct cli_state
*cli
;
2696 const char *fname
= "\\fdsess.tst";
2697 const char *fname1
= "\\fdsess1.tst";
2704 if (!torture_open_connection(&cli
, 0))
2706 cli_sockopt(cli
, sockops
);
2708 if (!torture_cli_session_setup2(cli
, &new_vuid
))
2711 saved_cnum
= cli
->cnum
;
2712 if (!NT_STATUS_IS_OK(cli_tcon_andx(cli
, share
, "?????", "", 1)))
2714 new_cnum
= cli
->cnum
;
2715 cli
->cnum
= saved_cnum
;
2717 printf("starting fdsesstest\n");
2719 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2720 cli_unlink(cli
, fname1
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2722 status
= cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
);
2723 if (!NT_STATUS_IS_OK(status
)) {
2724 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
2728 status
= cli_writeall(cli
, fnum1
, 0, (const uint8_t *)"hello world\n", 0, 13,
2730 if (!NT_STATUS_IS_OK(status
)) {
2731 printf("write failed (%s)\n", nt_errstr(status
));
2735 saved_vuid
= cli
->vuid
;
2736 cli
->vuid
= new_vuid
;
2738 if (cli_read(cli
, fnum1
, buf
, 0, 13) == 13) {
2739 printf("read succeeded with different vuid! nasty security hole [%s]\n",
2743 /* Try to open a file with different vuid, samba cnum. */
2744 if (NT_STATUS_IS_OK(cli_open(cli
, fname1
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum2
))) {
2745 printf("create with different vuid, same cnum succeeded.\n");
2746 cli_close(cli
, fnum2
);
2747 cli_unlink(cli
, fname1
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2749 printf("create with different vuid, same cnum failed.\n");
2750 printf("This will cause problems with service clients.\n");
2754 cli
->vuid
= saved_vuid
;
2756 /* Try with same vuid, different cnum. */
2757 cli
->cnum
= new_cnum
;
2759 if (cli_read(cli
, fnum1
, buf
, 0, 13) == 13) {
2760 printf("read succeeded with different cnum![%s]\n",
2765 cli
->cnum
= saved_cnum
;
2766 cli_close(cli
, fnum1
);
2767 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2769 torture_close_connection(cli
);
2771 printf("finished fdsesstest\n");
2776 This test checks that
2778 1) the server does not allow an unlink on a file that is open
2780 static bool run_unlinktest(int dummy
)
2782 struct cli_state
*cli
;
2783 const char *fname
= "\\unlink.tst";
2785 bool correct
= True
;
2788 if (!torture_open_connection(&cli
, 0)) {
2792 cli_sockopt(cli
, sockops
);
2794 printf("starting unlink test\n");
2796 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2800 status
= cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum
);
2801 if (!NT_STATUS_IS_OK(status
)) {
2802 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
2806 if (NT_STATUS_IS_OK(cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
))) {
2807 printf("error: server allowed unlink on an open file\n");
2810 correct
= check_error(__LINE__
, cli
, ERRDOS
, ERRbadshare
,
2811 NT_STATUS_SHARING_VIOLATION
);
2814 cli_close(cli
, fnum
);
2815 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2817 if (!torture_close_connection(cli
)) {
2821 printf("unlink test finished\n");
2828 test how many open files this server supports on the one socket
2830 static bool run_maxfidtest(int dummy
)
2832 struct cli_state
*cli
;
2834 uint16_t fnums
[0x11000];
2837 bool correct
= True
;
2843 printf("failed to connect\n");
2847 cli_sockopt(cli
, sockops
);
2849 for (i
=0; i
<0x11000; i
++) {
2850 slprintf(fname
,sizeof(fname
)-1,"\\maxfid.%d.%d", i
,(int)getpid());
2851 status
= cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_TRUNC
, DENY_NONE
,
2853 if (!NT_STATUS_IS_OK(status
)) {
2854 printf("open of %s failed (%s)\n",
2855 fname
, nt_errstr(status
));
2856 printf("maximum fnum is %d\n", i
);
2864 printf("cleaning up\n");
2866 slprintf(fname
,sizeof(fname
)-1,"\\maxfid.%d.%d", i
,(int)getpid());
2867 cli_close(cli
, fnums
[i
]);
2869 status
= cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2870 if (!NT_STATUS_IS_OK(status
)) {
2871 printf("unlink of %s failed (%s)\n",
2872 fname
, nt_errstr(status
));
2879 printf("maxfid test finished\n");
2880 if (!torture_close_connection(cli
)) {
2886 /* generate a random buffer */
2887 static void rand_buf(char *buf
, int len
)
2890 *buf
= (char)sys_random();
2895 /* send smb negprot commands, not reading the response */
2896 static bool run_negprot_nowait(int dummy
)
2898 struct tevent_context
*ev
;
2900 struct cli_state
*cli
;
2901 bool correct
= True
;
2903 printf("starting negprot nowait test\n");
2905 ev
= tevent_context_init(talloc_tos());
2910 if (!(cli
= open_nbt_connection())) {
2915 for (i
=0;i
<50000;i
++) {
2916 struct tevent_req
*req
;
2918 req
= cli_negprot_send(ev
, ev
, cli
);
2923 if (!tevent_req_poll(req
, ev
)) {
2924 d_fprintf(stderr
, "tevent_req_poll failed: %s\n",
2932 if (torture_close_connection(cli
)) {
2936 printf("finished negprot nowait test\n");
2941 /* send smb negprot commands, not reading the response */
2942 static bool run_bad_nbt_session(int dummy
)
2944 static struct cli_state
*cli
;
2946 printf("starting bad nbt session test\n");
2948 if (!(cli
= open_bad_nbt_connection())) {
2953 printf("finished bad nbt session test\n");
2957 /* send random IPC commands */
2958 static bool run_randomipc(int dummy
)
2960 char *rparam
= NULL
;
2962 unsigned int rdrcnt
,rprcnt
;
2964 int api
, param_len
, i
;
2965 struct cli_state
*cli
;
2966 bool correct
= True
;
2969 printf("starting random ipc test\n");
2971 if (!torture_open_connection(&cli
, 0)) {
2975 for (i
=0;i
<count
;i
++) {
2976 api
= sys_random() % 500;
2977 param_len
= (sys_random() % 64);
2979 rand_buf(param
, param_len
);
2984 param
, param_len
, 8,
2985 NULL
, 0, BUFFER_SIZE
,
2989 printf("%d/%d\r", i
,count
);
2992 printf("%d/%d\n", i
, count
);
2994 if (!torture_close_connection(cli
)) {
2998 printf("finished random ipc test\n");
3005 static void browse_callback(const char *sname
, uint32 stype
,
3006 const char *comment
, void *state
)
3008 printf("\t%20.20s %08x %s\n", sname
, stype
, comment
);
3014 This test checks the browse list code
3017 static bool run_browsetest(int dummy
)
3019 static struct cli_state
*cli
;
3020 bool correct
= True
;
3022 printf("starting browse test\n");
3024 if (!torture_open_connection(&cli
, 0)) {
3028 printf("domain list:\n");
3029 cli_NetServerEnum(cli
, cli
->server_domain
,
3030 SV_TYPE_DOMAIN_ENUM
,
3031 browse_callback
, NULL
);
3033 printf("machine list:\n");
3034 cli_NetServerEnum(cli
, cli
->server_domain
,
3036 browse_callback
, NULL
);
3038 if (!torture_close_connection(cli
)) {
3042 printf("browse test finished\n");
3050 This checks how the getatr calls works
3052 static bool run_attrtest(int dummy
)
3054 struct cli_state
*cli
;
3057 const char *fname
= "\\attrib123456789.tst";
3058 bool correct
= True
;
3061 printf("starting attrib test\n");
3063 if (!torture_open_connection(&cli
, 0)) {
3067 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3068 cli_open(cli
, fname
,
3069 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
, &fnum
);
3070 cli_close(cli
, fnum
);
3072 status
= cli_getatr(cli
, fname
, NULL
, NULL
, &t
);
3073 if (!NT_STATUS_IS_OK(status
)) {
3074 printf("getatr failed (%s)\n", nt_errstr(status
));
3078 if (abs(t
- time(NULL
)) > 60*60*24*10) {
3079 printf("ERROR: SMBgetatr bug. time is %s",
3085 t2
= t
-60*60*24; /* 1 day ago */
3087 status
= cli_setatr(cli
, fname
, 0, t2
);
3088 if (!NT_STATUS_IS_OK(status
)) {
3089 printf("setatr failed (%s)\n", nt_errstr(status
));
3093 status
= cli_getatr(cli
, fname
, NULL
, NULL
, &t
);
3094 if (!NT_STATUS_IS_OK(status
)) {
3095 printf("getatr failed (%s)\n", nt_errstr(status
));
3100 printf("ERROR: getatr/setatr bug. times are\n%s",
3102 printf("%s", ctime(&t2
));
3106 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3108 if (!torture_close_connection(cli
)) {
3112 printf("attrib test finished\n");
3119 This checks a couple of trans2 calls
3121 static bool run_trans2test(int dummy
)
3123 struct cli_state
*cli
;
3126 time_t c_time
, a_time
, m_time
;
3127 struct timespec c_time_ts
, a_time_ts
, m_time_ts
, w_time_ts
, m_time2_ts
;
3128 const char *fname
= "\\trans2.tst";
3129 const char *dname
= "\\trans2";
3130 const char *fname2
= "\\trans2\\trans2.tst";
3132 bool correct
= True
;
3136 printf("starting trans2 test\n");
3138 if (!torture_open_connection(&cli
, 0)) {
3142 status
= cli_get_fs_attr_info(cli
, &fs_attr
);
3143 if (!NT_STATUS_IS_OK(status
)) {
3144 printf("ERROR: cli_get_fs_attr_info returned %s\n",
3149 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3150 cli_open(cli
, fname
, O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
, &fnum
);
3151 status
= cli_qfileinfo_basic(cli
, fnum
, NULL
, &size
, &c_time_ts
,
3152 &a_time_ts
, &w_time_ts
, &m_time_ts
, NULL
);
3153 if (!NT_STATUS_IS_OK(status
)) {
3154 printf("ERROR: qfileinfo failed (%s)\n", nt_errstr(status
));
3158 status
= cli_qfilename(cli
, fnum
, pname
, sizeof(pname
));
3159 if (!NT_STATUS_IS_OK(status
)) {
3160 printf("ERROR: qfilename failed (%s)\n", nt_errstr(status
));
3164 if (strcmp(pname
, fname
)) {
3165 printf("qfilename gave different name? [%s] [%s]\n",
3170 cli_close(cli
, fnum
);
3174 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3175 status
= cli_open(cli
, fname
, O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
,
3177 if (!NT_STATUS_IS_OK(status
)) {
3178 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
3181 cli_close(cli
, fnum
);
3183 status
= cli_qpathinfo1(cli
, fname
, &c_time
, &a_time
, &m_time
, &size
,
3185 if (!NT_STATUS_IS_OK(status
)) {
3186 printf("ERROR: qpathinfo failed (%s)\n", nt_errstr(status
));
3189 if (c_time
!= m_time
) {
3190 printf("create time=%s", ctime(&c_time
));
3191 printf("modify time=%s", ctime(&m_time
));
3192 printf("This system appears to have sticky create times\n");
3194 if (a_time
% (60*60) == 0) {
3195 printf("access time=%s", ctime(&a_time
));
3196 printf("This system appears to set a midnight access time\n");
3200 if (abs(m_time
- time(NULL
)) > 60*60*24*7) {
3201 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time
));
3207 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3208 cli_open(cli
, fname
,
3209 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
, &fnum
);
3210 cli_close(cli
, fnum
);
3211 status
= cli_qpathinfo2(cli
, fname
, &c_time_ts
, &a_time_ts
, &w_time_ts
,
3212 &m_time_ts
, &size
, NULL
, NULL
);
3213 if (!NT_STATUS_IS_OK(status
)) {
3214 printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status
));
3217 if (w_time_ts
.tv_sec
< 60*60*24*2) {
3218 printf("write time=%s", ctime(&w_time_ts
.tv_sec
));
3219 printf("This system appears to set a initial 0 write time\n");
3224 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3227 /* check if the server updates the directory modification time
3228 when creating a new file */
3229 status
= cli_mkdir(cli
, dname
);
3230 if (!NT_STATUS_IS_OK(status
)) {
3231 printf("ERROR: mkdir failed (%s)\n", nt_errstr(status
));
3235 status
= cli_qpathinfo2(cli
, "\\trans2\\", &c_time_ts
, &a_time_ts
,
3236 &w_time_ts
, &m_time_ts
, &size
, NULL
, NULL
);
3237 if (!NT_STATUS_IS_OK(status
)) {
3238 printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status
));
3242 cli_open(cli
, fname2
,
3243 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
, &fnum
);
3244 cli_writeall(cli
, fnum
, 0, (uint8_t *)&fnum
, 0, sizeof(fnum
), NULL
);
3245 cli_close(cli
, fnum
);
3246 status
= cli_qpathinfo2(cli
, "\\trans2\\", &c_time_ts
, &a_time_ts
,
3247 &w_time_ts
, &m_time2_ts
, &size
, NULL
, NULL
);
3248 if (!NT_STATUS_IS_OK(status
)) {
3249 printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status
));
3252 if (memcmp(&m_time_ts
, &m_time2_ts
, sizeof(struct timespec
))
3254 printf("This system does not update directory modification times\n");
3258 cli_unlink(cli
, fname2
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3259 cli_rmdir(cli
, dname
);
3261 if (!torture_close_connection(cli
)) {
3265 printf("trans2 test finished\n");
3271 This checks new W2K calls.
3274 static NTSTATUS
new_trans(struct cli_state
*pcli
, int fnum
, int level
)
3276 uint8_t *buf
= NULL
;
3280 status
= cli_qfileinfo(talloc_tos(), pcli
, fnum
, level
, 0,
3281 pcli
->max_xmit
, &buf
, &len
);
3282 if (!NT_STATUS_IS_OK(status
)) {
3283 printf("ERROR: qfileinfo (%d) failed (%s)\n", level
,
3286 printf("qfileinfo: level %d, len = %u\n", level
, len
);
3287 dump_data(0, (uint8
*)buf
, len
);
3294 static bool run_w2ktest(int dummy
)
3296 struct cli_state
*cli
;
3298 const char *fname
= "\\w2ktest\\w2k.tst";
3300 bool correct
= True
;
3302 printf("starting w2k test\n");
3304 if (!torture_open_connection(&cli
, 0)) {
3308 cli_open(cli
, fname
,
3309 O_RDWR
| O_CREAT
, DENY_NONE
, &fnum
);
3311 for (level
= 1004; level
< 1040; level
++) {
3312 new_trans(cli
, fnum
, level
);
3315 cli_close(cli
, fnum
);
3317 if (!torture_close_connection(cli
)) {
3321 printf("w2k test finished\n");
3328 this is a harness for some oplock tests
3330 static bool run_oplock1(int dummy
)
3332 struct cli_state
*cli1
;
3333 const char *fname
= "\\lockt1.lck";
3335 bool correct
= True
;
3338 printf("starting oplock test 1\n");
3340 if (!torture_open_connection(&cli1
, 0)) {
3344 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3346 cli_sockopt(cli1
, sockops
);
3348 cli1
->use_oplocks
= True
;
3350 status
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
,
3352 if (!NT_STATUS_IS_OK(status
)) {
3353 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
3357 cli1
->use_oplocks
= False
;
3359 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3360 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3362 status
= cli_close(cli1
, fnum1
);
3363 if (!NT_STATUS_IS_OK(status
)) {
3364 printf("close2 failed (%s)\n", nt_errstr(status
));
3368 status
= cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3369 if (!NT_STATUS_IS_OK(status
)) {
3370 printf("unlink failed (%s)\n", nt_errstr(status
));
3374 if (!torture_close_connection(cli1
)) {
3378 printf("finished oplock test 1\n");
3383 static bool run_oplock2(int dummy
)
3385 struct cli_state
*cli1
, *cli2
;
3386 const char *fname
= "\\lockt2.lck";
3387 uint16_t fnum1
, fnum2
;
3388 int saved_use_oplocks
= use_oplocks
;
3390 bool correct
= True
;
3391 volatile bool *shared_correct
;
3394 shared_correct
= (volatile bool *)shm_setup(sizeof(bool));
3395 *shared_correct
= True
;
3397 use_level_II_oplocks
= True
;
3400 printf("starting oplock test 2\n");
3402 if (!torture_open_connection(&cli1
, 0)) {
3403 use_level_II_oplocks
= False
;
3404 use_oplocks
= saved_use_oplocks
;
3408 cli1
->use_oplocks
= True
;
3409 cli1
->use_level_II_oplocks
= True
;
3411 if (!torture_open_connection(&cli2
, 1)) {
3412 use_level_II_oplocks
= False
;
3413 use_oplocks
= saved_use_oplocks
;
3417 cli2
->use_oplocks
= True
;
3418 cli2
->use_level_II_oplocks
= True
;
3420 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3422 cli_sockopt(cli1
, sockops
);
3423 cli_sockopt(cli2
, sockops
);
3425 status
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
,
3427 if (!NT_STATUS_IS_OK(status
)) {
3428 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
3432 /* Don't need the globals any more. */
3433 use_level_II_oplocks
= False
;
3434 use_oplocks
= saved_use_oplocks
;
3438 status
= cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
, &fnum2
);
3439 if (!NT_STATUS_IS_OK(status
)) {
3440 printf("second open of %s failed (%s)\n", fname
, nt_errstr(status
));
3441 *shared_correct
= False
;
3447 status
= cli_close(cli2
, fnum2
);
3448 if (!NT_STATUS_IS_OK(status
)) {
3449 printf("close2 failed (%s)\n", nt_errstr(status
));
3450 *shared_correct
= False
;
3458 /* Ensure cli1 processes the break. Empty file should always return 0
3461 if (cli_read(cli1
, fnum1
, buf
, 0, 4) != 0) {
3462 printf("read on fnum1 failed (%s)\n", cli_errstr(cli1
));
3466 /* Should now be at level II. */
3467 /* Test if sending a write locks causes a break to none. */
3469 if (!cli_lock(cli1
, fnum1
, 0, 4, 0, READ_LOCK
)) {
3470 printf("lock failed (%s)\n", cli_errstr(cli1
));
3474 cli_unlock(cli1
, fnum1
, 0, 4);
3478 if (!cli_lock(cli1
, fnum1
, 0, 4, 0, WRITE_LOCK
)) {
3479 printf("lock failed (%s)\n", cli_errstr(cli1
));
3483 cli_unlock(cli1
, fnum1
, 0, 4);
3487 cli_read(cli1
, fnum1
, buf
, 0, 4);
3489 status
= cli_close(cli1
, fnum1
);
3490 if (!NT_STATUS_IS_OK(status
)) {
3491 printf("close1 failed (%s)\n", nt_errstr(status
));
3497 status
= cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3498 if (!NT_STATUS_IS_OK(status
)) {
3499 printf("unlink failed (%s)\n", nt_errstr(status
));
3503 if (!torture_close_connection(cli1
)) {
3507 if (!*shared_correct
) {
3511 printf("finished oplock test 2\n");
3516 /* handler for oplock 3 tests */
3517 static NTSTATUS
oplock3_handler(struct cli_state
*cli
, uint16_t fnum
, unsigned char level
)
3519 printf("got oplock break fnum=%d level=%d\n",
3521 return cli_oplock_ack(cli
, fnum
, level
);
3524 static bool run_oplock3(int dummy
)
3526 struct cli_state
*cli
;
3527 const char *fname
= "\\oplockt3.dat";
3529 char buf
[4] = "abcd";
3530 bool correct
= True
;
3531 volatile bool *shared_correct
;
3533 shared_correct
= (volatile bool *)shm_setup(sizeof(bool));
3534 *shared_correct
= True
;
3536 printf("starting oplock test 3\n");
3541 use_level_II_oplocks
= True
;
3542 if (!torture_open_connection(&cli
, 0)) {
3543 *shared_correct
= False
;
3547 /* try to trigger a oplock break in parent */
3548 cli_open(cli
, fname
, O_RDWR
, DENY_NONE
, &fnum
);
3549 cli_writeall(cli
, fnum
, 0, (uint8_t *)buf
, 0, 4, NULL
);
3555 use_level_II_oplocks
= True
;
3556 if (!torture_open_connection(&cli
, 1)) { /* other is forked */
3559 cli_oplock_handler(cli
, oplock3_handler
);
3560 cli_open(cli
, fname
, O_RDWR
|O_CREAT
, DENY_NONE
, &fnum
);
3561 cli_writeall(cli
, fnum
, 0, (uint8_t *)buf
, 0, 4, NULL
);
3562 cli_close(cli
, fnum
);
3563 cli_open(cli
, fname
, O_RDWR
, DENY_NONE
, &fnum
);
3564 cli
->timeout
= 20000;
3565 cli_receive_smb(cli
);
3566 printf("finished oplock test 3\n");
3568 return (correct
&& *shared_correct
);
3570 /* What are we looking for here? What's sucess and what's FAILURE? */
3573 /* handler for oplock 4 tests */
3574 bool *oplock4_shared_correct
;
3576 static NTSTATUS
oplock4_handler(struct cli_state
*cli
, uint16_t fnum
, unsigned char level
)
3578 printf("got oplock break fnum=%d level=%d\n",
3580 *oplock4_shared_correct
= true;
3581 cli_oplock_ack(cli
, fnum
, level
);
3582 return NT_STATUS_UNSUCCESSFUL
; /* Cause cli_receive_smb to return. */
3585 static bool run_oplock4(int dummy
)
3587 struct cli_state
*cli1
, *cli2
;
3588 const char *fname
= "\\lockt4.lck";
3589 const char *fname_ln
= "\\lockt4_ln.lck";
3590 uint16_t fnum1
, fnum2
;
3591 int saved_use_oplocks
= use_oplocks
;
3593 bool correct
= true;
3595 oplock4_shared_correct
= (bool *)shm_setup(sizeof(bool));
3596 *oplock4_shared_correct
= false;
3598 printf("starting oplock test 4\n");
3600 if (!torture_open_connection(&cli1
, 0)) {
3601 use_level_II_oplocks
= false;
3602 use_oplocks
= saved_use_oplocks
;
3606 if (!torture_open_connection(&cli2
, 1)) {
3607 use_level_II_oplocks
= false;
3608 use_oplocks
= saved_use_oplocks
;
3612 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3613 cli_unlink(cli1
, fname_ln
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3615 cli_sockopt(cli1
, sockops
);
3616 cli_sockopt(cli2
, sockops
);
3618 /* Create the file. */
3619 status
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
,
3621 if (!NT_STATUS_IS_OK(status
)) {
3622 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
3626 status
= cli_close(cli1
, fnum1
);
3627 if (!NT_STATUS_IS_OK(status
)) {
3628 printf("close1 failed (%s)\n", nt_errstr(status
));
3632 /* Now create a hardlink. */
3633 status
= cli_nt_hardlink(cli1
, fname
, fname_ln
);
3634 if (!NT_STATUS_IS_OK(status
)) {
3635 printf("nt hardlink failed (%s)\n", nt_errstr(status
));
3639 /* Prove that opening hardlinks cause deny modes to conflict. */
3640 status
= cli_open(cli1
, fname
, O_RDWR
, DENY_ALL
, &fnum1
);
3641 if (!NT_STATUS_IS_OK(status
)) {
3642 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
3646 status
= cli_open(cli1
, fname_ln
, O_RDWR
, DENY_NONE
, &fnum2
);
3647 if (NT_STATUS_IS_OK(status
)) {
3648 printf("open of %s succeeded - should fail with sharing violation.\n",
3653 if (!NT_STATUS_EQUAL(status
, NT_STATUS_SHARING_VIOLATION
)) {
3654 printf("open of %s should fail with sharing violation. Got %s\n",
3655 fname_ln
, nt_errstr(status
));
3659 status
= cli_close(cli1
, fnum1
);
3660 if (!NT_STATUS_IS_OK(status
)) {
3661 printf("close1 failed (%s)\n", nt_errstr(status
));
3665 cli1
->use_oplocks
= true;
3666 cli1
->use_level_II_oplocks
= true;
3668 cli2
->use_oplocks
= true;
3669 cli2
->use_level_II_oplocks
= true;
3671 cli_oplock_handler(cli1
, oplock4_handler
);
3673 status
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
);
3674 if (!NT_STATUS_IS_OK(status
)) {
3675 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
3681 status
= cli_open(cli2
, fname_ln
, O_RDWR
, DENY_NONE
, &fnum2
);
3682 if (!NT_STATUS_IS_OK(status
)) {
3683 printf("open of %s failed (%s)\n", fname_ln
, nt_errstr(status
));
3684 *oplock4_shared_correct
= false;
3688 status
= cli_close(cli2
, fnum2
);
3689 if (!NT_STATUS_IS_OK(status
)) {
3690 printf("close2 failed (%s)\n", nt_errstr(status
));
3691 *oplock4_shared_correct
= false;
3699 /* Process the oplock break. */
3700 cli_receive_smb(cli1
);
3702 status
= cli_close(cli1
, fnum1
);
3703 if (!NT_STATUS_IS_OK(status
)) {
3704 printf("close1 failed (%s)\n", nt_errstr(status
));
3708 status
= cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3709 if (!NT_STATUS_IS_OK(status
)) {
3710 printf("unlink failed (%s)\n", nt_errstr(status
));
3714 status
= cli_unlink(cli1
, fname_ln
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3715 if (!NT_STATUS_IS_OK(status
)) {
3716 printf("unlink failed (%s)\n", nt_errstr(status
));
3720 if (!torture_close_connection(cli1
)) {
3724 if (!*oplock4_shared_correct
) {
3728 printf("finished oplock test 4\n");
3735 Test delete on close semantics.
3737 static bool run_deletetest(int dummy
)
3739 struct cli_state
*cli1
= NULL
;
3740 struct cli_state
*cli2
= NULL
;
3741 const char *fname
= "\\delete.file";
3742 uint16_t fnum1
= (uint16_t)-1;
3743 uint16_t fnum2
= (uint16_t)-1;
3744 bool correct
= True
;
3747 printf("starting delete test\n");
3749 if (!torture_open_connection(&cli1
, 0)) {
3753 cli_sockopt(cli1
, sockops
);
3755 /* Test 1 - this should delete the file on close. */
3757 cli_setatr(cli1
, fname
, 0, 0);
3758 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3760 status
= cli_ntcreate(cli1
, fname
, 0, GENERIC_ALL_ACCESS
|DELETE_ACCESS
,
3761 FILE_ATTRIBUTE_NORMAL
, 0, FILE_OVERWRITE_IF
,
3762 FILE_DELETE_ON_CLOSE
, 0, &fnum1
);
3763 if (!NT_STATUS_IS_OK(status
)) {
3764 printf("[1] open of %s failed (%s)\n", fname
, nt_errstr(status
));
3769 status
= cli_close(cli1
, fnum1
);
3770 if (!NT_STATUS_IS_OK(status
)) {
3771 printf("[1] close failed (%s)\n", nt_errstr(status
));
3776 if (NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
))) {
3777 printf("[1] open of %s succeeded (should fail)\n", fname
);
3782 printf("first delete on close test succeeded.\n");
3784 /* Test 2 - this should delete the file on close. */
3786 cli_setatr(cli1
, fname
, 0, 0);
3787 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3789 status
= cli_ntcreate(cli1
, fname
, 0, GENERIC_ALL_ACCESS
,
3790 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
3791 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
3792 if (!NT_STATUS_IS_OK(status
)) {
3793 printf("[2] open of %s failed (%s)\n", fname
, nt_errstr(status
));
3798 status
= cli_nt_delete_on_close(cli1
, fnum1
, true);
3799 if (!NT_STATUS_IS_OK(status
)) {
3800 printf("[2] setting delete_on_close failed (%s)\n", nt_errstr(status
));
3805 status
= cli_close(cli1
, fnum1
);
3806 if (!NT_STATUS_IS_OK(status
)) {
3807 printf("[2] close failed (%s)\n", nt_errstr(status
));
3812 if (NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
, &fnum1
))) {
3813 printf("[2] open of %s succeeded should have been deleted on close !\n", fname
);
3814 status
= cli_close(cli1
, fnum1
);
3815 if (!NT_STATUS_IS_OK(status
)) {
3816 printf("[2] close failed (%s)\n", nt_errstr(status
));
3820 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3822 printf("second delete on close test succeeded.\n");
3825 cli_setatr(cli1
, fname
, 0, 0);
3826 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3828 status
= cli_ntcreate(cli1
, fname
, 0, GENERIC_ALL_ACCESS
,
3829 FILE_ATTRIBUTE_NORMAL
,
3830 FILE_SHARE_READ
|FILE_SHARE_WRITE
,
3831 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
3832 if (!NT_STATUS_IS_OK(status
)) {
3833 printf("[3] open - 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
3838 /* This should fail with a sharing violation - open for delete is only compatible
3839 with SHARE_DELETE. */
3841 if (NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3842 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN
, 0, 0, &fnum2
))) {
3843 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname
);
3848 /* This should succeed. */
3849 status
= cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
,
3850 FILE_ATTRIBUTE_NORMAL
,
3851 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
3852 FILE_OPEN
, 0, 0, &fnum2
);
3853 if (!NT_STATUS_IS_OK(status
)) {
3854 printf("[3] open - 2 of %s failed (%s)\n", fname
, nt_errstr(status
));
3859 status
= cli_nt_delete_on_close(cli1
, fnum1
, true);
3860 if (!NT_STATUS_IS_OK(status
)) {
3861 printf("[3] setting delete_on_close failed (%s)\n", nt_errstr(status
));
3866 status
= cli_close(cli1
, fnum1
);
3867 if (!NT_STATUS_IS_OK(status
)) {
3868 printf("[3] close 1 failed (%s)\n", nt_errstr(status
));
3873 status
= cli_close(cli1
, fnum2
);
3874 if (!NT_STATUS_IS_OK(status
)) {
3875 printf("[3] close 2 failed (%s)\n", nt_errstr(status
));
3880 /* This should fail - file should no longer be there. */
3882 if (NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
, &fnum1
))) {
3883 printf("[3] open of %s succeeded should have been deleted on close !\n", fname
);
3884 status
= cli_close(cli1
, fnum1
);
3885 if (!NT_STATUS_IS_OK(status
)) {
3886 printf("[3] close failed (%s)\n", nt_errstr(status
));
3888 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3892 printf("third delete on close test succeeded.\n");
3895 cli_setatr(cli1
, fname
, 0, 0);
3896 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3898 status
= cli_ntcreate(cli1
, fname
, 0,
3899 FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
3900 FILE_ATTRIBUTE_NORMAL
,
3901 FILE_SHARE_READ
|FILE_SHARE_WRITE
,
3902 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
3903 if (!NT_STATUS_IS_OK(status
)) {
3904 printf("[4] open of %s failed (%s)\n", fname
, nt_errstr(status
));
3909 /* This should succeed. */
3910 status
= cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
,
3911 FILE_ATTRIBUTE_NORMAL
,
3912 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
3913 FILE_OPEN
, 0, 0, &fnum2
);
3914 if (!NT_STATUS_IS_OK(status
)) {
3915 printf("[4] open - 2 of %s failed (%s)\n", fname
, nt_errstr(status
));
3920 status
= cli_close(cli1
, fnum2
);
3921 if (!NT_STATUS_IS_OK(status
)) {
3922 printf("[4] close - 1 failed (%s)\n", nt_errstr(status
));
3927 status
= cli_nt_delete_on_close(cli1
, fnum1
, true);
3928 if (!NT_STATUS_IS_OK(status
)) {
3929 printf("[4] setting delete_on_close failed (%s)\n", nt_errstr(status
));
3934 /* This should fail - no more opens once delete on close set. */
3935 if (NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
,
3936 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
3937 FILE_OPEN
, 0, 0, &fnum2
))) {
3938 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname
);
3942 printf("fourth delete on close test succeeded.\n");
3944 status
= cli_close(cli1
, fnum1
);
3945 if (!NT_STATUS_IS_OK(status
)) {
3946 printf("[4] close - 2 failed (%s)\n", nt_errstr(status
));
3952 cli_setatr(cli1
, fname
, 0, 0);
3953 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3955 status
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
, DENY_NONE
, &fnum1
);
3956 if (!NT_STATUS_IS_OK(status
)) {
3957 printf("[5] open of %s failed (%s)\n", fname
, nt_errstr(status
));
3962 /* This should fail - only allowed on NT opens with DELETE access. */
3964 if (NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, true))) {
3965 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
3970 status
= cli_close(cli1
, fnum1
);
3971 if (!NT_STATUS_IS_OK(status
)) {
3972 printf("[5] close - 2 failed (%s)\n", nt_errstr(status
));
3977 printf("fifth delete on close test succeeded.\n");
3980 cli_setatr(cli1
, fname
, 0, 0);
3981 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3983 status
= cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
,
3984 FILE_ATTRIBUTE_NORMAL
,
3985 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
3986 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
3987 if (!NT_STATUS_IS_OK(status
)) {
3988 printf("[6] open of %s failed (%s)\n", fname
,
3994 /* This should fail - only allowed on NT opens with DELETE access. */
3996 if (NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, true))) {
3997 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
4002 status
= cli_close(cli1
, fnum1
);
4003 if (!NT_STATUS_IS_OK(status
)) {
4004 printf("[6] close - 2 failed (%s)\n", nt_errstr(status
));
4009 printf("sixth delete on close test succeeded.\n");
4012 cli_setatr(cli1
, fname
, 0, 0);
4013 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4015 status
= cli_ntcreate(cli1
, fname
, 0,
4016 FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
4017 FILE_ATTRIBUTE_NORMAL
, 0, FILE_OVERWRITE_IF
,
4019 if (!NT_STATUS_IS_OK(status
)) {
4020 printf("[7] open of %s failed (%s)\n", fname
, nt_errstr(status
));
4025 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, true))) {
4026 printf("[7] setting delete_on_close on file failed !\n");
4031 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, false))) {
4032 printf("[7] unsetting delete_on_close on file failed !\n");
4037 status
= cli_close(cli1
, fnum1
);
4038 if (!NT_STATUS_IS_OK(status
)) {
4039 printf("[7] close - 2 failed (%s)\n", nt_errstr(status
));
4044 /* This next open should succeed - we reset the flag. */
4045 status
= cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
, &fnum1
);
4046 if (!NT_STATUS_IS_OK(status
)) {
4047 printf("[5] open of %s failed (%s)\n", fname
, nt_errstr(status
));
4052 status
= cli_close(cli1
, fnum1
);
4053 if (!NT_STATUS_IS_OK(status
)) {
4054 printf("[7] close - 2 failed (%s)\n", nt_errstr(status
));
4059 printf("seventh delete on close test succeeded.\n");
4062 cli_setatr(cli1
, fname
, 0, 0);
4063 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4065 if (!torture_open_connection(&cli2
, 1)) {
4066 printf("[8] failed to open second connection.\n");
4071 cli_sockopt(cli1
, sockops
);
4073 status
= cli_ntcreate(cli1
, fname
, 0,
4074 FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
4075 FILE_ATTRIBUTE_NORMAL
,
4076 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
4077 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
4078 if (!NT_STATUS_IS_OK(status
)) {
4079 printf("[8] open 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
4084 status
= cli_ntcreate(cli2
, fname
, 0,
4085 FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
4086 FILE_ATTRIBUTE_NORMAL
,
4087 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
4088 FILE_OPEN
, 0, 0, &fnum2
);
4089 if (!NT_STATUS_IS_OK(status
)) {
4090 printf("[8] open 2 of %s failed (%s)\n", fname
, nt_errstr(status
));
4095 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, true))) {
4096 printf("[8] setting delete_on_close on file failed !\n");
4101 status
= cli_close(cli1
, fnum1
);
4102 if (!NT_STATUS_IS_OK(status
)) {
4103 printf("[8] close - 1 failed (%s)\n", nt_errstr(status
));
4108 status
= cli_close(cli2
, fnum2
);
4109 if (!NT_STATUS_IS_OK(status
)) {
4110 printf("[8] close - 2 failed (%s)\n", nt_errstr(status
));
4115 /* This should fail.. */
4116 status
= cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
, &fnum1
);
4117 if (NT_STATUS_IS_OK(status
)) {
4118 printf("[8] open of %s succeeded should have been deleted on close !\n", fname
);
4122 printf("eighth delete on close test succeeded.\n");
4124 /* This should fail - we need to set DELETE_ACCESS. */
4125 if (NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0,FILE_READ_DATA
|FILE_WRITE_DATA
,
4126 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, FILE_DELETE_ON_CLOSE
, 0, &fnum1
))) {
4127 printf("[9] open of %s succeeded should have failed!\n", fname
);
4132 printf("ninth delete on close test succeeded.\n");
4134 status
= cli_ntcreate(cli1
, fname
, 0,
4135 FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
4136 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
4137 FILE_OVERWRITE_IF
, FILE_DELETE_ON_CLOSE
,
4139 if (!NT_STATUS_IS_OK(status
)) {
4140 printf("[10] open of %s failed (%s)\n", fname
, nt_errstr(status
));
4145 /* This should delete the file. */
4146 status
= cli_close(cli1
, fnum1
);
4147 if (!NT_STATUS_IS_OK(status
)) {
4148 printf("[10] close failed (%s)\n", nt_errstr(status
));
4153 /* This should fail.. */
4154 if (NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
, &fnum1
))) {
4155 printf("[10] open of %s succeeded should have been deleted on close !\n", fname
);
4159 printf("tenth delete on close test succeeded.\n");
4161 cli_setatr(cli1
, fname
, 0, 0);
4162 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4164 /* What error do we get when attempting to open a read-only file with
4167 /* Create a readonly file. */
4168 status
= cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
,
4169 FILE_ATTRIBUTE_READONLY
, FILE_SHARE_NONE
,
4170 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
4171 if (!NT_STATUS_IS_OK(status
)) {
4172 printf("[11] open of %s failed (%s)\n", fname
, nt_errstr(status
));
4177 status
= cli_close(cli1
, fnum1
);
4178 if (!NT_STATUS_IS_OK(status
)) {
4179 printf("[11] close failed (%s)\n", nt_errstr(status
));
4184 /* Now try open for delete access. */
4185 if (NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_ATTRIBUTES
|DELETE_ACCESS
,
4186 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
4187 FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
4188 printf("[11] open of %s succeeded should have been denied with ACCESS_DENIED!\n", fname
);
4189 cli_close(cli1
, fnum1
);
4193 NTSTATUS nterr
= cli_nt_error(cli1
);
4194 if (!NT_STATUS_EQUAL(nterr
,NT_STATUS_ACCESS_DENIED
)) {
4195 printf("[11] open of %s should have been denied with ACCESS_DENIED! Got error %s\n", fname
, nt_errstr(nterr
));
4199 printf("eleventh delete on close test succeeded.\n");
4203 printf("finished delete test\n");
4206 /* FIXME: This will crash if we aborted before cli2 got
4207 * intialized, because these functions don't handle
4208 * uninitialized connections. */
4210 if (fnum1
!= (uint16_t)-1) cli_close(cli1
, fnum1
);
4211 if (fnum2
!= (uint16_t)-1) cli_close(cli1
, fnum2
);
4212 cli_setatr(cli1
, fname
, 0, 0);
4213 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4215 if (cli1
&& !torture_close_connection(cli1
)) {
4218 if (cli2
&& !torture_close_connection(cli2
)) {
4224 static bool run_deletetest_ln(int dummy
)
4226 struct cli_state
*cli
;
4227 const char *fname
= "\\delete1";
4228 const char *fname_ln
= "\\delete1_ln";
4232 bool correct
= true;
4235 printf("starting deletetest-ln\n");
4237 if (!torture_open_connection(&cli
, 0)) {
4241 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4242 cli_unlink(cli
, fname_ln
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4244 cli_sockopt(cli
, sockops
);
4246 /* Create the file. */
4247 status
= cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum
);
4248 if (!NT_STATUS_IS_OK(status
)) {
4249 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
4253 status
= cli_close(cli
, fnum
);
4254 if (!NT_STATUS_IS_OK(status
)) {
4255 printf("close1 failed (%s)\n", nt_errstr(status
));
4259 /* Now create a hardlink. */
4260 status
= cli_nt_hardlink(cli
, fname
, fname_ln
);
4261 if (!NT_STATUS_IS_OK(status
)) {
4262 printf("nt hardlink failed (%s)\n", nt_errstr(status
));
4266 /* Open the original file. */
4267 status
= cli_ntcreate(cli
, fname
, 0, FILE_READ_DATA
,
4268 FILE_ATTRIBUTE_NORMAL
,
4269 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
4270 FILE_OPEN_IF
, 0, 0, &fnum
);
4271 if (!NT_STATUS_IS_OK(status
)) {
4272 printf("ntcreate of %s failed (%s)\n", fname
, nt_errstr(status
));
4276 /* Unlink the hard link path. */
4277 status
= cli_ntcreate(cli
, fname_ln
, 0, DELETE_ACCESS
,
4278 FILE_ATTRIBUTE_NORMAL
,
4279 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
4280 FILE_OPEN_IF
, 0, 0, &fnum1
);
4281 if (!NT_STATUS_IS_OK(status
)) {
4282 printf("ntcreate of %s failed (%s)\n", fname_ln
, nt_errstr(status
));
4285 status
= cli_nt_delete_on_close(cli
, fnum1
, true);
4286 if (!NT_STATUS_IS_OK(status
)) {
4287 d_printf("(%s) failed to set delete_on_close %s: %s\n",
4288 __location__
, fname_ln
, nt_errstr(status
));
4292 status
= cli_close(cli
, fnum1
);
4293 if (!NT_STATUS_IS_OK(status
)) {
4294 printf("close %s failed (%s)\n",
4295 fname_ln
, nt_errstr(status
));
4299 status
= cli_close(cli
, fnum
);
4300 if (!NT_STATUS_IS_OK(status
)) {
4301 printf("close %s failed (%s)\n",
4302 fname
, nt_errstr(status
));
4306 /* Ensure the original file is still there. */
4307 status
= cli_getatr(cli
, fname
, NULL
, NULL
, &t
);
4308 if (!NT_STATUS_IS_OK(status
)) {
4309 printf("%s getatr on file %s failed (%s)\n",
4316 /* Ensure the link path is gone. */
4317 status
= cli_getatr(cli
, fname_ln
, NULL
, NULL
, &t
);
4318 if (!NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
4319 printf("%s, getatr for file %s returned wrong error code %s "
4320 "- should have been deleted\n",
4322 fname_ln
, nt_errstr(status
));
4326 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4327 cli_unlink(cli
, fname_ln
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4329 if (!torture_close_connection(cli
)) {
4333 printf("finished deletetest-ln\n");
4339 print out server properties
4341 static bool run_properties(int dummy
)
4343 struct cli_state
*cli
;
4344 bool correct
= True
;
4346 printf("starting properties test\n");
4350 if (!torture_open_connection(&cli
, 0)) {
4354 cli_sockopt(cli
, sockops
);
4356 d_printf("Capabilities 0x%08x\n", cli
->capabilities
);
4358 if (!torture_close_connection(cli
)) {
4367 /* FIRST_DESIRED_ACCESS 0xf019f */
4368 #define FIRST_DESIRED_ACCESS FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|\
4369 FILE_READ_EA| /* 0xf */ \
4370 FILE_WRITE_EA|FILE_READ_ATTRIBUTES| /* 0x90 */ \
4371 FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
4372 DELETE_ACCESS|READ_CONTROL_ACCESS|\
4373 WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS /* 0xf0000 */
4374 /* SECOND_DESIRED_ACCESS 0xe0080 */
4375 #define SECOND_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
4376 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
4377 WRITE_OWNER_ACCESS /* 0xe0000 */
4380 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
4381 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
4383 WRITE_OWNER_ACCESS /* */
4387 Test ntcreate calls made by xcopy
4389 static bool run_xcopy(int dummy
)
4391 static struct cli_state
*cli1
;
4392 const char *fname
= "\\test.txt";
4393 bool correct
= True
;
4394 uint16_t fnum1
, fnum2
;
4397 printf("starting xcopy test\n");
4399 if (!torture_open_connection(&cli1
, 0)) {
4403 status
= cli_ntcreate(cli1
, fname
, 0, FIRST_DESIRED_ACCESS
,
4404 FILE_ATTRIBUTE_ARCHIVE
, FILE_SHARE_NONE
,
4405 FILE_OVERWRITE_IF
, 0x4044, 0, &fnum1
);
4406 if (!NT_STATUS_IS_OK(status
)) {
4407 printf("First open failed - %s\n", nt_errstr(status
));
4411 status
= cli_ntcreate(cli1
, fname
, 0, SECOND_DESIRED_ACCESS
, 0,
4412 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
4413 FILE_OPEN
, 0x200000, 0, &fnum2
);
4414 if (!NT_STATUS_IS_OK(status
)) {
4415 printf("second open failed - %s\n", nt_errstr(status
));
4419 if (!torture_close_connection(cli1
)) {
4427 Test rename on files open with share delete and no share delete.
4429 static bool run_rename(int dummy
)
4431 static struct cli_state
*cli1
;
4432 const char *fname
= "\\test.txt";
4433 const char *fname1
= "\\test1.txt";
4434 bool correct
= True
;
4439 printf("starting rename test\n");
4441 if (!torture_open_connection(&cli1
, 0)) {
4445 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4446 cli_unlink(cli1
, fname1
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4448 status
= cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
,
4449 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
,
4450 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
4451 if (!NT_STATUS_IS_OK(status
)) {
4452 printf("First open failed - %s\n", nt_errstr(status
));
4456 status
= cli_rename(cli1
, fname
, fname1
);
4457 if (!NT_STATUS_IS_OK(status
)) {
4458 printf("First rename failed (SHARE_READ) (this is correct) - %s\n", nt_errstr(status
));
4460 printf("First rename succeeded (SHARE_READ) - this should have failed !\n");
4464 status
= cli_close(cli1
, fnum1
);
4465 if (!NT_STATUS_IS_OK(status
)) {
4466 printf("close - 1 failed (%s)\n", nt_errstr(status
));
4470 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4471 cli_unlink(cli1
, fname1
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4472 status
= cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
4474 FILE_SHARE_DELETE
|FILE_SHARE_NONE
,
4476 FILE_SHARE_DELETE
|FILE_SHARE_READ
,
4478 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
4479 if (!NT_STATUS_IS_OK(status
)) {
4480 printf("Second open failed - %s\n", nt_errstr(status
));
4484 status
= cli_rename(cli1
, fname
, fname1
);
4485 if (!NT_STATUS_IS_OK(status
)) {
4486 printf("Second rename failed (SHARE_DELETE | SHARE_READ) - this should have succeeded - %s\n", nt_errstr(status
));
4489 printf("Second rename succeeded (SHARE_DELETE | SHARE_READ)\n");
4492 status
= cli_close(cli1
, fnum1
);
4493 if (!NT_STATUS_IS_OK(status
)) {
4494 printf("close - 2 failed (%s)\n", nt_errstr(status
));
4498 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4499 cli_unlink(cli1
, fname1
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4501 status
= cli_ntcreate(cli1
, fname
, 0, READ_CONTROL_ACCESS
,
4502 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
4503 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
4504 if (!NT_STATUS_IS_OK(status
)) {
4505 printf("Third open failed - %s\n", nt_errstr(status
));
4514 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, DELETE_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
4515 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0, &fnum2
))) {
4516 printf("Fourth open failed - %s\n", cli_errstr(cli1
));
4519 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum2
, true))) {
4520 printf("[8] setting delete_on_close on file failed !\n");
4524 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum2
))) {
4525 printf("close - 4 failed (%s)\n", cli_errstr(cli1
));
4531 status
= cli_rename(cli1
, fname
, fname1
);
4532 if (!NT_STATUS_IS_OK(status
)) {
4533 printf("Third rename failed (SHARE_NONE) - this should have succeeded - %s\n", nt_errstr(status
));
4536 printf("Third rename succeeded (SHARE_NONE)\n");
4539 status
= cli_close(cli1
, fnum1
);
4540 if (!NT_STATUS_IS_OK(status
)) {
4541 printf("close - 3 failed (%s)\n", nt_errstr(status
));
4545 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4546 cli_unlink(cli1
, fname1
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4550 status
= cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
,
4551 FILE_ATTRIBUTE_NORMAL
,
4552 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
4553 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
4554 if (!NT_STATUS_IS_OK(status
)) {
4555 printf("Fourth open failed - %s\n", nt_errstr(status
));
4559 status
= cli_rename(cli1
, fname
, fname1
);
4560 if (!NT_STATUS_IS_OK(status
)) {
4561 printf("Fourth rename failed (SHARE_READ | SHARE_WRITE) (this is correct) - %s\n", nt_errstr(status
));
4563 printf("Fourth rename succeeded (SHARE_READ | SHARE_WRITE) - this should have failed !\n");
4567 status
= cli_close(cli1
, fnum1
);
4568 if (!NT_STATUS_IS_OK(status
)) {
4569 printf("close - 4 failed (%s)\n", nt_errstr(status
));
4573 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4574 cli_unlink(cli1
, fname1
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4578 status
= cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
,
4579 FILE_ATTRIBUTE_NORMAL
,
4580 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
4581 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
4582 if (!NT_STATUS_IS_OK(status
)) {
4583 printf("Fifth open failed - %s\n", nt_errstr(status
));
4587 status
= cli_rename(cli1
, fname
, fname1
);
4588 if (!NT_STATUS_IS_OK(status
)) {
4589 printf("Fifth rename failed (SHARE_READ | SHARE_WRITE | SHARE_DELETE) - this should have succeeded - %s ! \n", nt_errstr(status
));
4592 printf("Fifth rename succeeded (SHARE_READ | SHARE_WRITE | SHARE_DELETE) (this is correct) - %s\n", nt_errstr(status
));
4596 * Now check if the first name still exists ...
4599 /* if (!NT_STATUS_OP(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
4600 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0, &fnum2))) {
4601 printf("Opening original file after rename of open file fails: %s\n",
4605 printf("Opening original file after rename of open file works ...\n");
4606 (void)cli_close(cli1, fnum2);
4610 status
= cli_close(cli1
, fnum1
);
4611 if (!NT_STATUS_IS_OK(status
)) {
4612 printf("close - 5 failed (%s)\n", nt_errstr(status
));
4616 /* Check that the renamed file has FILE_ATTRIBUTE_ARCHIVE. */
4617 status
= cli_getatr(cli1
, fname1
, &attr
, NULL
, NULL
);
4618 if (!NT_STATUS_IS_OK(status
)) {
4619 printf("getatr on file %s failed - %s ! \n",
4620 fname1
, nt_errstr(status
));
4623 if (attr
!= FILE_ATTRIBUTE_ARCHIVE
) {
4624 printf("Renamed file %s has wrong attr 0x%x "
4625 "(should be 0x%x)\n",
4628 (unsigned int)FILE_ATTRIBUTE_ARCHIVE
);
4631 printf("Renamed file %s has archive bit set\n", fname1
);
4635 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4636 cli_unlink(cli1
, fname1
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4638 if (!torture_close_connection(cli1
)) {
4645 static bool run_pipe_number(int dummy
)
4647 struct cli_state
*cli1
;
4648 const char *pipe_name
= "\\SPOOLSS";
4653 printf("starting pipenumber test\n");
4654 if (!torture_open_connection(&cli1
, 0)) {
4658 cli_sockopt(cli1
, sockops
);
4660 status
= cli_ntcreate(cli1
, pipe_name
, 0, FILE_READ_DATA
,
4661 FILE_ATTRIBUTE_NORMAL
,
4662 FILE_SHARE_READ
|FILE_SHARE_WRITE
,
4663 FILE_OPEN_IF
, 0, 0, &fnum
);
4664 if (!NT_STATUS_IS_OK(status
)) {
4665 printf("Open of pipe %s failed with error (%s)\n", pipe_name
, nt_errstr(status
));
4669 printf("\r%6d", num_pipes
);
4672 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes
, pipe_name
);
4673 torture_close_connection(cli1
);
4678 Test open mode returns on read-only files.
4680 static bool run_opentest(int dummy
)
4682 static struct cli_state
*cli1
;
4683 static struct cli_state
*cli2
;
4684 const char *fname
= "\\readonly.file";
4685 uint16_t fnum1
, fnum2
;
4688 bool correct
= True
;
4692 printf("starting open test\n");
4694 if (!torture_open_connection(&cli1
, 0)) {
4698 cli_setatr(cli1
, fname
, 0, 0);
4699 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4701 cli_sockopt(cli1
, sockops
);
4703 status
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
);
4704 if (!NT_STATUS_IS_OK(status
)) {
4705 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
4709 status
= cli_close(cli1
, fnum1
);
4710 if (!NT_STATUS_IS_OK(status
)) {
4711 printf("close2 failed (%s)\n", nt_errstr(status
));
4715 status
= cli_setatr(cli1
, fname
, FILE_ATTRIBUTE_READONLY
, 0);
4716 if (!NT_STATUS_IS_OK(status
)) {
4717 printf("cli_setatr failed (%s)\n", nt_errstr(status
));
4721 status
= cli_open(cli1
, fname
, O_RDONLY
, DENY_WRITE
, &fnum1
);
4722 if (!NT_STATUS_IS_OK(status
)) {
4723 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
4727 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
4728 cli_open(cli1
, fname
, O_RDWR
, DENY_ALL
, &fnum2
);
4730 if (check_error(__LINE__
, cli1
, ERRDOS
, ERRnoaccess
,
4731 NT_STATUS_ACCESS_DENIED
)) {
4732 printf("correct error code ERRDOS/ERRnoaccess returned\n");
4735 printf("finished open test 1\n");
4737 cli_close(cli1
, fnum1
);
4739 /* Now try not readonly and ensure ERRbadshare is returned. */
4741 cli_setatr(cli1
, fname
, 0, 0);
4743 status
= cli_open(cli1
, fname
, O_RDONLY
, DENY_WRITE
, &fnum1
);
4744 if (!NT_STATUS_IS_OK(status
)) {
4745 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
4749 /* This will fail - but the error should be ERRshare. */
4750 cli_open(cli1
, fname
, O_RDWR
, DENY_ALL
, &fnum2
);
4752 if (check_error(__LINE__
, cli1
, ERRDOS
, ERRbadshare
,
4753 NT_STATUS_SHARING_VIOLATION
)) {
4754 printf("correct error code ERRDOS/ERRbadshare returned\n");
4757 status
= cli_close(cli1
, fnum1
);
4758 if (!NT_STATUS_IS_OK(status
)) {
4759 printf("close2 failed (%s)\n", nt_errstr(status
));
4763 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4765 printf("finished open test 2\n");
4767 /* Test truncate open disposition on file opened for read. */
4768 status
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
);
4769 if (!NT_STATUS_IS_OK(status
)) {
4770 printf("(3) open (1) of %s failed (%s)\n", fname
, nt_errstr(status
));
4774 /* write 20 bytes. */
4776 memset(buf
, '\0', 20);
4778 status
= cli_writeall(cli1
, fnum1
, 0, (uint8_t *)buf
, 0, 20, NULL
);
4779 if (!NT_STATUS_IS_OK(status
)) {
4780 printf("write failed (%s)\n", nt_errstr(status
));
4784 status
= cli_close(cli1
, fnum1
);
4785 if (!NT_STATUS_IS_OK(status
)) {
4786 printf("(3) close1 failed (%s)\n", nt_errstr(status
));
4790 /* Ensure size == 20. */
4791 status
= cli_getatr(cli1
, fname
, NULL
, &fsize
, NULL
);
4792 if (!NT_STATUS_IS_OK(status
)) {
4793 printf("(3) getatr failed (%s)\n", nt_errstr(status
));
4798 printf("(3) file size != 20\n");
4802 /* Now test if we can truncate a file opened for readonly. */
4803 status
= cli_open(cli1
, fname
, O_RDONLY
|O_TRUNC
, DENY_NONE
, &fnum1
);
4804 if (!NT_STATUS_IS_OK(status
)) {
4805 printf("(3) open (2) 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 /* Ensure size == 0. */
4816 status
= cli_getatr(cli1
, fname
, NULL
, &fsize
, NULL
);
4817 if (!NT_STATUS_IS_OK(status
)) {
4818 printf("(3) getatr failed (%s)\n", nt_errstr(status
));
4823 printf("(3) file size != 0\n");
4826 printf("finished open test 3\n");
4828 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4830 printf("Do ctemp tests\n");
4831 status
= cli_ctemp(cli1
, talloc_tos(), "\\", &fnum1
, &tmp_path
);
4832 if (!NT_STATUS_IS_OK(status
)) {
4833 printf("ctemp failed (%s)\n", nt_errstr(status
));
4837 printf("ctemp gave path %s\n", tmp_path
);
4838 status
= cli_close(cli1
, fnum1
);
4839 if (!NT_STATUS_IS_OK(status
)) {
4840 printf("close of temp failed (%s)\n", nt_errstr(status
));
4843 status
= cli_unlink(cli1
, tmp_path
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4844 if (!NT_STATUS_IS_OK(status
)) {
4845 printf("unlink of temp failed (%s)\n", nt_errstr(status
));
4848 /* Test the non-io opens... */
4850 if (!torture_open_connection(&cli2
, 1)) {
4854 cli_setatr(cli2
, fname
, 0, 0);
4855 cli_unlink(cli2
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4857 cli_sockopt(cli2
, sockops
);
4859 printf("TEST #1 testing 2 non-io opens (no delete)\n");
4860 status
= cli_ntcreate(cli1
, fname
, 0, FILE_READ_ATTRIBUTES
,
4861 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
4862 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
4863 if (!NT_STATUS_IS_OK(status
)) {
4864 printf("TEST #1 open 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
4868 status
= cli_ntcreate(cli2
, fname
, 0, FILE_READ_ATTRIBUTES
,
4869 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
4870 FILE_OPEN_IF
, 0, 0, &fnum2
);
4871 if (!NT_STATUS_IS_OK(status
)) {
4872 printf("TEST #1 open 2 of %s failed (%s)\n", fname
, nt_errstr(status
));
4876 status
= cli_close(cli1
, fnum1
);
4877 if (!NT_STATUS_IS_OK(status
)) {
4878 printf("TEST #1 close 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
4882 status
= cli_close(cli2
, fnum2
);
4883 if (!NT_STATUS_IS_OK(status
)) {
4884 printf("TEST #1 close 2 of %s failed (%s)\n", fname
, nt_errstr(status
));
4888 printf("non-io open test #1 passed.\n");
4890 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4892 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
4894 status
= cli_ntcreate(cli1
, fname
, 0,
4895 DELETE_ACCESS
|FILE_READ_ATTRIBUTES
,
4896 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
4897 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
4898 if (!NT_STATUS_IS_OK(status
)) {
4899 printf("TEST #2 open 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
4903 status
= cli_ntcreate(cli2
, fname
, 0, FILE_READ_ATTRIBUTES
,
4904 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
4905 FILE_OPEN_IF
, 0, 0, &fnum2
);
4906 if (!NT_STATUS_IS_OK(status
)) {
4907 printf("TEST #2 open 2 of %s failed (%s)\n", fname
, nt_errstr(status
));
4911 status
= cli_close(cli1
, fnum1
);
4912 if (!NT_STATUS_IS_OK(status
)) {
4913 printf("TEST #2 close 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
4917 status
= cli_close(cli2
, fnum2
);
4918 if (!NT_STATUS_IS_OK(status
)) {
4919 printf("TEST #2 close 2 of %s failed (%s)\n", fname
, nt_errstr(status
));
4923 printf("non-io open test #2 passed.\n");
4925 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4927 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
4929 status
= cli_ntcreate(cli1
, fname
, 0, FILE_READ_ATTRIBUTES
,
4930 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
4931 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
4932 if (!NT_STATUS_IS_OK(status
)) {
4933 printf("TEST #3 open 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
4937 status
= cli_ntcreate(cli2
, fname
, 0,
4938 DELETE_ACCESS
|FILE_READ_ATTRIBUTES
,
4939 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
4940 FILE_OPEN_IF
, 0, 0, &fnum2
);
4941 if (!NT_STATUS_IS_OK(status
)) {
4942 printf("TEST #3 open 2 of %s failed (%s)\n", fname
, nt_errstr(status
));
4946 status
= cli_close(cli1
, fnum1
);
4947 if (!NT_STATUS_IS_OK(status
)) {
4948 printf("TEST #3 close 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
4952 status
= cli_close(cli2
, fnum2
);
4953 if (!NT_STATUS_IS_OK(status
)) {
4954 printf("TEST #3 close 2 of %s failed (%s)\n", fname
, nt_errstr(status
));
4958 printf("non-io open test #3 passed.\n");
4960 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4962 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
4964 status
= cli_ntcreate(cli1
, fname
, 0,
4965 DELETE_ACCESS
|FILE_READ_ATTRIBUTES
,
4966 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
4967 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
4968 if (!NT_STATUS_IS_OK(status
)) {
4969 printf("TEST #4 open 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
4973 status
= cli_ntcreate(cli2
, fname
, 0,
4974 DELETE_ACCESS
|FILE_READ_ATTRIBUTES
,
4975 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
4976 FILE_OPEN_IF
, 0, 0, &fnum2
);
4977 if (NT_STATUS_IS_OK(status
)) {
4978 printf("TEST #4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname
, nt_errstr(status
));
4982 printf("TEST #4 open 2 of %s gave %s (correct error should be %s)\n", fname
, nt_errstr(status
), "sharing violation");
4984 status
= cli_close(cli1
, fnum1
);
4985 if (!NT_STATUS_IS_OK(status
)) {
4986 printf("TEST #4 close 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
4990 printf("non-io open test #4 passed.\n");
4992 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4994 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
4996 status
= cli_ntcreate(cli1
, fname
, 0,
4997 DELETE_ACCESS
|FILE_READ_ATTRIBUTES
,
4998 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_DELETE
,
4999 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
5000 if (!NT_STATUS_IS_OK(status
)) {
5001 printf("TEST #5 open 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
5005 status
= cli_ntcreate(cli2
, fname
, 0,
5006 DELETE_ACCESS
|FILE_READ_ATTRIBUTES
,
5007 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_DELETE
,
5008 FILE_OPEN_IF
, 0, 0, &fnum2
);
5009 if (!NT_STATUS_IS_OK(status
)) {
5010 printf("TEST #5 open 2 of %s failed (%s)\n", fname
, nt_errstr(status
));
5014 status
= cli_close(cli1
, fnum1
);
5015 if (!NT_STATUS_IS_OK(status
)) {
5016 printf("TEST #5 close 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
5020 status
= cli_close(cli2
, fnum2
);
5021 if (!NT_STATUS_IS_OK(status
)) {
5022 printf("TEST #5 close 2 of %s failed (%s)\n", fname
, nt_errstr(status
));
5026 printf("non-io open test #5 passed.\n");
5028 printf("TEST #6 testing 1 non-io open, one io open\n");
5030 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
5032 status
= cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
,
5033 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
5034 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
5035 if (!NT_STATUS_IS_OK(status
)) {
5036 printf("TEST #6 open 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
5040 status
= cli_ntcreate(cli2
, fname
, 0, FILE_READ_ATTRIBUTES
,
5041 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
,
5042 FILE_OPEN_IF
, 0, 0, &fnum2
);
5043 if (!NT_STATUS_IS_OK(status
)) {
5044 printf("TEST #6 open 2 of %s failed (%s)\n", fname
, nt_errstr(status
));
5048 status
= cli_close(cli1
, fnum1
);
5049 if (!NT_STATUS_IS_OK(status
)) {
5050 printf("TEST #6 close 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
5054 status
= cli_close(cli2
, fnum2
);
5055 if (!NT_STATUS_IS_OK(status
)) {
5056 printf("TEST #6 close 2 of %s failed (%s)\n", fname
, nt_errstr(status
));
5060 printf("non-io open test #6 passed.\n");
5062 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
5064 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
5066 status
= cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
,
5067 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
5068 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
5069 if (!NT_STATUS_IS_OK(status
)) {
5070 printf("TEST #7 open 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
5074 status
= cli_ntcreate(cli2
, fname
, 0,
5075 DELETE_ACCESS
|FILE_READ_ATTRIBUTES
,
5076 FILE_ATTRIBUTE_NORMAL
,
5077 FILE_SHARE_READ
|FILE_SHARE_DELETE
,
5078 FILE_OPEN_IF
, 0, 0, &fnum2
);
5079 if (NT_STATUS_IS_OK(status
)) {
5080 printf("TEST #7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname
, nt_errstr(status
));
5084 printf("TEST #7 open 2 of %s gave %s (correct error should be %s)\n", fname
, nt_errstr(status
), "sharing violation");
5086 status
= cli_close(cli1
, fnum1
);
5087 if (!NT_STATUS_IS_OK(status
)) {
5088 printf("TEST #7 close 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
5092 printf("non-io open test #7 passed.\n");
5094 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
5096 printf("TEST #8 testing open without WRITE_ATTRIBUTES, updating close write time.\n");
5097 status
= cli_ntcreate(cli1
, fname
, 0, FILE_WRITE_DATA
, FILE_ATTRIBUTE_NORMAL
,
5098 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
5099 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
5100 if (!NT_STATUS_IS_OK(status
)) {
5101 printf("TEST #8 open of %s failed (%s)\n", fname
, nt_errstr(status
));
5106 /* Write to ensure we have to update the file time. */
5107 status
= cli_writeall(cli1
, fnum1
, 0, (const uint8_t *)"TEST DATA\n", 0, 10,
5109 if (!NT_STATUS_IS_OK(status
)) {
5110 printf("TEST #8 cli_write failed: %s\n", nt_errstr(status
));
5115 status
= cli_close(cli1
, fnum1
);
5116 if (!NT_STATUS_IS_OK(status
)) {
5117 printf("TEST #8 close of %s failed (%s)\n", fname
, nt_errstr(status
));
5123 if (!torture_close_connection(cli1
)) {
5126 if (!torture_close_connection(cli2
)) {
5133 NTSTATUS
torture_setup_unix_extensions(struct cli_state
*cli
)
5135 uint16 major
, minor
;
5136 uint32 caplow
, caphigh
;
5139 if (!SERVER_HAS_UNIX_CIFS(cli
)) {
5140 printf("Server doesn't support UNIX CIFS extensions.\n");
5141 return NT_STATUS_NOT_SUPPORTED
;
5144 status
= cli_unix_extensions_version(cli
, &major
, &minor
, &caplow
,
5146 if (!NT_STATUS_IS_OK(status
)) {
5147 printf("Server didn't return UNIX CIFS extensions: %s\n",
5152 status
= cli_set_unix_extensions_capabilities(cli
, major
, minor
,
5154 if (!NT_STATUS_IS_OK(status
)) {
5155 printf("Server doesn't support setting UNIX CIFS extensions: "
5156 "%s.\n", nt_errstr(status
));
5160 return NT_STATUS_OK
;
5164 Test POSIX open /mkdir calls.
5166 static bool run_simple_posix_open_test(int dummy
)
5168 static struct cli_state
*cli1
;
5169 const char *fname
= "posix:file";
5170 const char *hname
= "posix:hlink";
5171 const char *sname
= "posix:symlink";
5172 const char *dname
= "posix:dir";
5175 uint16_t fnum1
= (uint16_t)-1;
5176 SMB_STRUCT_STAT sbuf
;
5177 bool correct
= false;
5180 printf("Starting simple POSIX open test\n");
5182 if (!torture_open_connection(&cli1
, 0)) {
5186 cli_sockopt(cli1
, sockops
);
5188 status
= torture_setup_unix_extensions(cli1
);
5189 if (!NT_STATUS_IS_OK(status
)) {
5193 cli_setatr(cli1
, fname
, 0, 0);
5194 cli_posix_unlink(cli1
, fname
);
5195 cli_setatr(cli1
, dname
, 0, 0);
5196 cli_posix_rmdir(cli1
, dname
);
5197 cli_setatr(cli1
, hname
, 0, 0);
5198 cli_posix_unlink(cli1
, hname
);
5199 cli_setatr(cli1
, sname
, 0, 0);
5200 cli_posix_unlink(cli1
, sname
);
5202 /* Create a directory. */
5203 status
= cli_posix_mkdir(cli1
, dname
, 0777);
5204 if (!NT_STATUS_IS_OK(status
)) {
5205 printf("POSIX mkdir of %s failed (%s)\n", dname
, nt_errstr(status
));
5209 status
= cli_posix_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
,
5211 if (!NT_STATUS_IS_OK(status
)) {
5212 printf("POSIX create of %s failed (%s)\n", fname
, nt_errstr(status
));
5216 /* Test ftruncate - set file size. */
5217 status
= cli_ftruncate(cli1
, fnum1
, 1000);
5218 if (!NT_STATUS_IS_OK(status
)) {
5219 printf("ftruncate failed (%s)\n", nt_errstr(status
));
5223 /* Ensure st_size == 1000 */
5224 status
= cli_posix_stat(cli1
, fname
, &sbuf
);
5225 if (!NT_STATUS_IS_OK(status
)) {
5226 printf("stat failed (%s)\n", nt_errstr(status
));
5230 if (sbuf
.st_ex_size
!= 1000) {
5231 printf("ftruncate - stat size (%u) != 1000\n", (unsigned int)sbuf
.st_ex_size
);
5235 /* Test ftruncate - set file size back to zero. */
5236 status
= cli_ftruncate(cli1
, fnum1
, 0);
5237 if (!NT_STATUS_IS_OK(status
)) {
5238 printf("ftruncate failed (%s)\n", nt_errstr(status
));
5242 status
= cli_close(cli1
, fnum1
);
5243 if (!NT_STATUS_IS_OK(status
)) {
5244 printf("close failed (%s)\n", nt_errstr(status
));
5248 /* Now open the file again for read only. */
5249 status
= cli_posix_open(cli1
, fname
, O_RDONLY
, 0, &fnum1
);
5250 if (!NT_STATUS_IS_OK(status
)) {
5251 printf("POSIX open of %s failed (%s)\n", fname
, nt_errstr(status
));
5255 /* Now unlink while open. */
5256 status
= cli_posix_unlink(cli1
, fname
);
5257 if (!NT_STATUS_IS_OK(status
)) {
5258 printf("POSIX unlink of %s failed (%s)\n", fname
, nt_errstr(status
));
5262 status
= cli_close(cli1
, fnum1
);
5263 if (!NT_STATUS_IS_OK(status
)) {
5264 printf("close(2) failed (%s)\n", nt_errstr(status
));
5268 /* Ensure the file has gone. */
5269 status
= cli_posix_open(cli1
, fname
, O_RDONLY
, 0, &fnum1
);
5270 if (NT_STATUS_IS_OK(status
)) {
5271 printf("POSIX open of %s succeeded, should have been deleted.\n", fname
);
5275 /* Create again to test open with O_TRUNC. */
5276 if (!NT_STATUS_IS_OK(cli_posix_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, 0600, &fnum1
))) {
5277 printf("POSIX create of %s failed (%s)\n", fname
, cli_errstr(cli1
));
5281 /* Test ftruncate - set file size. */
5282 if (!NT_STATUS_IS_OK(cli_ftruncate(cli1
, fnum1
, 1000))) {
5283 printf("ftruncate failed (%s)\n", cli_errstr(cli1
));
5287 /* Ensure st_size == 1000 */
5288 if (!NT_STATUS_IS_OK(cli_posix_stat(cli1
, fname
, &sbuf
))) {
5289 printf("stat failed (%s)\n", cli_errstr(cli1
));
5293 if (sbuf
.st_ex_size
!= 1000) {
5294 printf("ftruncate - stat size (%u) != 1000\n", (unsigned int)sbuf
.st_ex_size
);
5298 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
5299 printf("close(2) failed (%s)\n", cli_errstr(cli1
));
5303 /* Re-open with O_TRUNC. */
5304 if (!NT_STATUS_IS_OK(cli_posix_open(cli1
, fname
, O_WRONLY
|O_TRUNC
, 0600, &fnum1
))) {
5305 printf("POSIX create of %s failed (%s)\n", fname
, cli_errstr(cli1
));
5309 /* Ensure st_size == 0 */
5310 if (!NT_STATUS_IS_OK(cli_posix_stat(cli1
, fname
, &sbuf
))) {
5311 printf("stat failed (%s)\n", cli_errstr(cli1
));
5315 if (sbuf
.st_ex_size
!= 0) {
5316 printf("O_TRUNC - stat size (%u) != 0\n", (unsigned int)sbuf
.st_ex_size
);
5320 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
5321 printf("close failed (%s)\n", cli_errstr(cli1
));
5325 if (!NT_STATUS_IS_OK(cli_posix_unlink(cli1
, fname
))) {
5326 printf("POSIX unlink of %s failed (%s)\n", fname
, cli_errstr(cli1
));
5330 if (!NT_STATUS_IS_OK(cli_posix_open(cli1
, dname
, O_RDONLY
, 0, &fnum1
))) {
5331 printf("POSIX open directory O_RDONLY of %s failed (%s)\n",
5332 dname
, cli_errstr(cli1
));
5336 cli_close(cli1
, fnum1
);
5338 /* What happens when we try and POSIX open a directory for write ? */
5339 if (NT_STATUS_IS_OK(cli_posix_open(cli1
, dname
, O_RDWR
, 0, &fnum1
))) {
5340 printf("POSIX open of directory %s succeeded, should have failed.\n", fname
);
5343 if (!check_error(__LINE__
, cli1
, ERRDOS
, EISDIR
,
5344 NT_STATUS_FILE_IS_A_DIRECTORY
)) {
5349 /* Create the file. */
5350 status
= cli_posix_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
,
5352 if (!NT_STATUS_IS_OK(status
)) {
5353 printf("POSIX create of %s failed (%s)\n", fname
, nt_errstr(status
));
5357 /* Write some data into it. */
5358 status
= cli_writeall(cli1
, fnum1
, 0, (const uint8_t *)"TEST DATA\n", 0, 10,
5360 if (!NT_STATUS_IS_OK(status
)) {
5361 printf("cli_write failed: %s\n", nt_errstr(status
));
5365 cli_close(cli1
, fnum1
);
5367 /* Now create a hardlink. */
5368 status
= cli_posix_hardlink(cli1
, fname
, hname
);
5369 if (!NT_STATUS_IS_OK(status
)) {
5370 printf("POSIX hardlink of %s failed (%s)\n", hname
, nt_errstr(status
));
5374 /* Now create a symlink. */
5375 status
= cli_posix_symlink(cli1
, fname
, sname
);
5376 if (!NT_STATUS_IS_OK(status
)) {
5377 printf("POSIX symlink of %s failed (%s)\n", sname
, nt_errstr(status
));
5381 /* Open the hardlink for read. */
5382 status
= cli_posix_open(cli1
, hname
, O_RDONLY
, 0, &fnum1
);
5383 if (!NT_STATUS_IS_OK(status
)) {
5384 printf("POSIX open of %s failed (%s)\n", hname
, nt_errstr(status
));
5388 if (cli_read(cli1
, fnum1
, buf
, 0, 10) != 10) {
5389 printf("POSIX read of %s failed (%s)\n", hname
, cli_errstr(cli1
));
5393 if (memcmp(buf
, "TEST DATA\n", 10)) {
5394 printf("invalid data read from hardlink\n");
5398 /* Do a POSIX lock/unlock. */
5399 status
= cli_posix_lock(cli1
, fnum1
, 0, 100, true, READ_LOCK
);
5400 if (!NT_STATUS_IS_OK(status
)) {
5401 printf("POSIX lock failed %s\n", nt_errstr(status
));
5405 /* Punch a hole in the locked area. */
5406 status
= cli_posix_unlock(cli1
, fnum1
, 10, 80);
5407 if (!NT_STATUS_IS_OK(status
)) {
5408 printf("POSIX unlock failed %s\n", nt_errstr(status
));
5412 cli_close(cli1
, fnum1
);
5414 /* Open the symlink for read - this should fail. A POSIX
5415 client should not be doing opens on a symlink. */
5416 status
= cli_posix_open(cli1
, sname
, O_RDONLY
, 0, &fnum1
);
5417 if (NT_STATUS_IS_OK(status
)) {
5418 printf("POSIX open of %s succeeded (should have failed)\n", sname
);
5421 if (!check_error(__LINE__
, cli1
, ERRDOS
, ERRbadpath
,
5422 NT_STATUS_OBJECT_PATH_NOT_FOUND
)) {
5423 printf("POSIX open of %s should have failed "
5424 "with NT_STATUS_OBJECT_PATH_NOT_FOUND, "
5425 "failed with %s instead.\n",
5426 sname
, nt_errstr(status
));
5431 status
= cli_posix_readlink(cli1
, sname
, namebuf
, sizeof(namebuf
));
5432 if (!NT_STATUS_IS_OK(status
)) {
5433 printf("POSIX readlink on %s failed (%s)\n", sname
, nt_errstr(status
));
5437 if (strcmp(namebuf
, fname
) != 0) {
5438 printf("POSIX readlink on %s failed to match name %s (read %s)\n",
5439 sname
, fname
, namebuf
);
5443 status
= cli_posix_rmdir(cli1
, dname
);
5444 if (!NT_STATUS_IS_OK(status
)) {
5445 printf("POSIX rmdir failed (%s)\n", nt_errstr(status
));
5449 printf("Simple POSIX open test passed\n");
5454 if (fnum1
!= (uint16_t)-1) {
5455 cli_close(cli1
, fnum1
);
5456 fnum1
= (uint16_t)-1;
5459 cli_setatr(cli1
, sname
, 0, 0);
5460 cli_posix_unlink(cli1
, sname
);
5461 cli_setatr(cli1
, hname
, 0, 0);
5462 cli_posix_unlink(cli1
, hname
);
5463 cli_setatr(cli1
, fname
, 0, 0);
5464 cli_posix_unlink(cli1
, fname
);
5465 cli_setatr(cli1
, dname
, 0, 0);
5466 cli_posix_rmdir(cli1
, dname
);
5468 if (!torture_close_connection(cli1
)) {
5476 static uint32 open_attrs_table
[] = {
5477 FILE_ATTRIBUTE_NORMAL
,
5478 FILE_ATTRIBUTE_ARCHIVE
,
5479 FILE_ATTRIBUTE_READONLY
,
5480 FILE_ATTRIBUTE_HIDDEN
,
5481 FILE_ATTRIBUTE_SYSTEM
,
5483 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
,
5484 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
,
5485 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
,
5486 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
,
5487 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
,
5488 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
,
5490 FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
,
5491 FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
,
5492 FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
,
5493 FILE_ATTRIBUTE_HIDDEN
,FILE_ATTRIBUTE_SYSTEM
,
5496 struct trunc_open_results
{
5503 static struct trunc_open_results attr_results
[] = {
5504 { 0, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_ARCHIVE
},
5505 { 1, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_ARCHIVE
},
5506 { 2, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_READONLY
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
},
5507 { 16, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_ARCHIVE
},
5508 { 17, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_ARCHIVE
},
5509 { 18, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_READONLY
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
},
5510 { 51, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
5511 { 54, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
5512 { 56, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
},
5513 { 68, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
5514 { 71, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
5515 { 73, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
},
5516 { 99, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_HIDDEN
,FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
5517 { 102, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
5518 { 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
},
5519 { 116, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
5520 { 119, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
5521 { 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
},
5522 { 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
},
5523 { 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
},
5524 { 227, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
5525 { 230, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
5526 { 232, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
},
5527 { 244, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
5528 { 247, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
5529 { 249, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
}
5532 static bool run_openattrtest(int dummy
)
5534 static struct cli_state
*cli1
;
5535 const char *fname
= "\\openattr.file";
5537 bool correct
= True
;
5539 unsigned int i
, j
, k
, l
;
5542 printf("starting open attr test\n");
5544 if (!torture_open_connection(&cli1
, 0)) {
5548 cli_sockopt(cli1
, sockops
);
5550 for (k
= 0, i
= 0; i
< sizeof(open_attrs_table
)/sizeof(uint32
); i
++) {
5551 cli_setatr(cli1
, fname
, 0, 0);
5552 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
5554 status
= cli_ntcreate(cli1
, fname
, 0, FILE_WRITE_DATA
,
5555 open_attrs_table
[i
], FILE_SHARE_NONE
,
5556 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
5557 if (!NT_STATUS_IS_OK(status
)) {
5558 printf("open %d (1) of %s failed (%s)\n", i
, fname
, nt_errstr(status
));
5562 status
= cli_close(cli1
, fnum1
);
5563 if (!NT_STATUS_IS_OK(status
)) {
5564 printf("close %d (1) of %s failed (%s)\n", i
, fname
, nt_errstr(status
));
5568 for (j
= 0; j
< sizeof(open_attrs_table
)/sizeof(uint32
); j
++) {
5569 status
= cli_ntcreate(cli1
, fname
, 0,
5570 FILE_READ_DATA
|FILE_WRITE_DATA
,
5571 open_attrs_table
[j
],
5572 FILE_SHARE_NONE
, FILE_OVERWRITE
,
5574 if (!NT_STATUS_IS_OK(status
)) {
5575 for (l
= 0; l
< sizeof(attr_results
)/sizeof(struct trunc_open_results
); l
++) {
5576 if (attr_results
[l
].num
== k
) {
5577 printf("[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(0x%x:%s)\n",
5578 k
, open_attrs_table
[i
],
5579 open_attrs_table
[j
],
5580 fname
, NT_STATUS_V(status
), nt_errstr(status
));
5585 if (!NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
)) {
5586 printf("[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s\n",
5587 k
, open_attrs_table
[i
], open_attrs_table
[j
],
5592 printf("[%d] trunc open 0x%x -> 0x%x failed\n", k
, open_attrs_table
[i
], open_attrs_table
[j
]);
5598 status
= cli_close(cli1
, fnum1
);
5599 if (!NT_STATUS_IS_OK(status
)) {
5600 printf("close %d (2) of %s failed (%s)\n", j
, fname
, nt_errstr(status
));
5604 status
= cli_getatr(cli1
, fname
, &attr
, NULL
, NULL
);
5605 if (!NT_STATUS_IS_OK(status
)) {
5606 printf("getatr(2) failed (%s)\n", nt_errstr(status
));
5611 printf("[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n",
5612 k
, open_attrs_table
[i
], open_attrs_table
[j
], attr
);
5615 for (l
= 0; l
< sizeof(attr_results
)/sizeof(struct trunc_open_results
); l
++) {
5616 if (attr_results
[l
].num
== k
) {
5617 if (attr
!= attr_results
[l
].result_attr
||
5618 open_attrs_table
[i
] != attr_results
[l
].init_attr
||
5619 open_attrs_table
[j
] != attr_results
[l
].trunc_attr
) {
5620 printf("getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x\n",
5621 open_attrs_table
[i
],
5622 open_attrs_table
[j
],
5624 attr_results
[l
].result_attr
);
5634 cli_setatr(cli1
, fname
, 0, 0);
5635 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
5637 printf("open attr test %s.\n", correct
? "passed" : "failed");
5639 if (!torture_close_connection(cli1
)) {
5645 static NTSTATUS
list_fn(const char *mnt
, struct file_info
*finfo
,
5646 const char *name
, void *state
)
5648 int *matched
= (int *)state
;
5649 if (matched
!= NULL
) {
5652 return NT_STATUS_OK
;
5656 test directory listing speed
5658 static bool run_dirtest(int dummy
)
5661 static struct cli_state
*cli
;
5663 struct timeval core_start
;
5664 bool correct
= True
;
5667 printf("starting directory test\n");
5669 if (!torture_open_connection(&cli
, 0)) {
5673 cli_sockopt(cli
, sockops
);
5676 for (i
=0;i
<torture_numops
;i
++) {
5678 slprintf(fname
, sizeof(fname
), "\\%x", (int)random());
5679 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
, O_RDWR
|O_CREAT
, DENY_NONE
, &fnum
))) {
5680 fprintf(stderr
,"Failed to open %s\n", fname
);
5683 cli_close(cli
, fnum
);
5686 core_start
= timeval_current();
5689 cli_list(cli
, "a*.*", 0, list_fn
, &matched
);
5690 printf("Matched %d\n", matched
);
5693 cli_list(cli
, "b*.*", 0, list_fn
, &matched
);
5694 printf("Matched %d\n", matched
);
5697 cli_list(cli
, "xyzabc", 0, list_fn
, &matched
);
5698 printf("Matched %d\n", matched
);
5700 printf("dirtest core %g seconds\n", timeval_elapsed(&core_start
));
5703 for (i
=0;i
<torture_numops
;i
++) {
5705 slprintf(fname
, sizeof(fname
), "\\%x", (int)random());
5706 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
5709 if (!torture_close_connection(cli
)) {
5713 printf("finished dirtest\n");
5718 static NTSTATUS
del_fn(const char *mnt
, struct file_info
*finfo
, const char *mask
,
5721 struct cli_state
*pcli
= (struct cli_state
*)state
;
5723 slprintf(fname
, sizeof(fname
), "\\LISTDIR\\%s", finfo
->name
);
5725 if (strcmp(finfo
->name
, ".") == 0 || strcmp(finfo
->name
, "..") == 0)
5726 return NT_STATUS_OK
;
5728 if (finfo
->mode
& FILE_ATTRIBUTE_DIRECTORY
) {
5729 if (!NT_STATUS_IS_OK(cli_rmdir(pcli
, fname
)))
5730 printf("del_fn: failed to rmdir %s\n,", fname
);
5732 if (!NT_STATUS_IS_OK(cli_unlink(pcli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
)))
5733 printf("del_fn: failed to unlink %s\n,", fname
);
5735 return NT_STATUS_OK
;
5740 sees what IOCTLs are supported
5742 bool torture_ioctl_test(int dummy
)
5744 static struct cli_state
*cli
;
5745 uint16_t device
, function
;
5747 const char *fname
= "\\ioctl.dat";
5751 if (!torture_open_connection(&cli
, 0)) {
5755 printf("starting ioctl test\n");
5757 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
5759 status
= cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum
);
5760 if (!NT_STATUS_IS_OK(status
)) {
5761 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
5765 status
= cli_raw_ioctl(cli
, fnum
, 0x2d0000 | (0x0420<<2), &blob
);
5766 printf("ioctl device info: %s\n", nt_errstr(status
));
5768 status
= cli_raw_ioctl(cli
, fnum
, IOCTL_QUERY_JOB_INFO
, &blob
);
5769 printf("ioctl job info: %s\n", nt_errstr(status
));
5771 for (device
=0;device
<0x100;device
++) {
5772 printf("ioctl test with device = 0x%x\n", device
);
5773 for (function
=0;function
<0x100;function
++) {
5774 uint32 code
= (device
<<16) | function
;
5776 status
= cli_raw_ioctl(cli
, fnum
, code
, &blob
);
5778 if (NT_STATUS_IS_OK(status
)) {
5779 printf("ioctl 0x%x OK : %d bytes\n", (int)code
,
5781 data_blob_free(&blob
);
5786 if (!torture_close_connection(cli
)) {
5795 tries varients of chkpath
5797 bool torture_chkpath_test(int dummy
)
5799 static struct cli_state
*cli
;
5804 if (!torture_open_connection(&cli
, 0)) {
5808 printf("starting chkpath test\n");
5810 /* cleanup from an old run */
5811 cli_rmdir(cli
, "\\chkpath.dir\\dir2");
5812 cli_unlink(cli
, "\\chkpath.dir\\*", FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
5813 cli_rmdir(cli
, "\\chkpath.dir");
5815 status
= cli_mkdir(cli
, "\\chkpath.dir");
5816 if (!NT_STATUS_IS_OK(status
)) {
5817 printf("mkdir1 failed : %s\n", nt_errstr(status
));
5821 status
= cli_mkdir(cli
, "\\chkpath.dir\\dir2");
5822 if (!NT_STATUS_IS_OK(status
)) {
5823 printf("mkdir2 failed : %s\n", nt_errstr(status
));
5827 status
= cli_open(cli
, "\\chkpath.dir\\foo.txt", O_RDWR
|O_CREAT
|O_EXCL
,
5829 if (!NT_STATUS_IS_OK(status
)) {
5830 printf("open1 failed (%s)\n", nt_errstr(status
));
5833 cli_close(cli
, fnum
);
5835 status
= cli_chkpath(cli
, "\\chkpath.dir");
5836 if (!NT_STATUS_IS_OK(status
)) {
5837 printf("chkpath1 failed: %s\n", nt_errstr(status
));
5841 status
= cli_chkpath(cli
, "\\chkpath.dir\\dir2");
5842 if (!NT_STATUS_IS_OK(status
)) {
5843 printf("chkpath2 failed: %s\n", nt_errstr(status
));
5847 status
= cli_chkpath(cli
, "\\chkpath.dir\\foo.txt");
5848 if (!NT_STATUS_IS_OK(status
)) {
5849 ret
= check_error(__LINE__
, cli
, ERRDOS
, ERRbadpath
,
5850 NT_STATUS_NOT_A_DIRECTORY
);
5852 printf("* chkpath on a file should fail\n");
5856 if (!NT_STATUS_IS_OK(cli_chkpath(cli
, "\\chkpath.dir\\bar.txt"))) {
5857 ret
= check_error(__LINE__
, cli
, ERRDOS
, ERRbadfile
,
5858 NT_STATUS_OBJECT_NAME_NOT_FOUND
);
5860 printf("* chkpath on a non existant file should fail\n");
5864 if (!NT_STATUS_IS_OK(cli_chkpath(cli
, "\\chkpath.dir\\dirxx\\bar.txt"))) {
5865 ret
= check_error(__LINE__
, cli
, ERRDOS
, ERRbadpath
,
5866 NT_STATUS_OBJECT_PATH_NOT_FOUND
);
5868 printf("* chkpath on a non existent component should fail\n");
5872 cli_rmdir(cli
, "\\chkpath.dir\\dir2");
5873 cli_unlink(cli
, "\\chkpath.dir\\*", FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
5874 cli_rmdir(cli
, "\\chkpath.dir");
5876 if (!torture_close_connection(cli
)) {
5883 static bool run_eatest(int dummy
)
5885 static struct cli_state
*cli
;
5886 const char *fname
= "\\eatest.txt";
5887 bool correct
= True
;
5891 struct ea_struct
*ea_list
= NULL
;
5892 TALLOC_CTX
*mem_ctx
= talloc_init("eatest");
5895 printf("starting eatest\n");
5897 if (!torture_open_connection(&cli
, 0)) {
5898 talloc_destroy(mem_ctx
);
5902 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
5904 status
= cli_ntcreate(cli
, fname
, 0,
5905 FIRST_DESIRED_ACCESS
, FILE_ATTRIBUTE_ARCHIVE
,
5906 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
,
5908 if (!NT_STATUS_IS_OK(status
)) {
5909 printf("open failed - %s\n", nt_errstr(status
));
5910 talloc_destroy(mem_ctx
);
5914 for (i
= 0; i
< 10; i
++) {
5915 fstring ea_name
, ea_val
;
5917 slprintf(ea_name
, sizeof(ea_name
), "EA_%d", i
);
5918 memset(ea_val
, (char)i
+1, i
+1);
5919 status
= cli_set_ea_fnum(cli
, fnum
, ea_name
, ea_val
, i
+1);
5920 if (!NT_STATUS_IS_OK(status
)) {
5921 printf("ea_set of name %s failed - %s\n", ea_name
,
5923 talloc_destroy(mem_ctx
);
5928 cli_close(cli
, fnum
);
5929 for (i
= 0; i
< 10; i
++) {
5930 fstring ea_name
, ea_val
;
5932 slprintf(ea_name
, sizeof(ea_name
), "EA_%d", i
+10);
5933 memset(ea_val
, (char)i
+1, i
+1);
5934 status
= cli_set_ea_path(cli
, fname
, ea_name
, ea_val
, i
+1);
5935 if (!NT_STATUS_IS_OK(status
)) {
5936 printf("ea_set of name %s failed - %s\n", ea_name
,
5938 talloc_destroy(mem_ctx
);
5943 status
= cli_get_ea_list_path(cli
, fname
, mem_ctx
, &num_eas
, &ea_list
);
5944 if (!NT_STATUS_IS_OK(status
)) {
5945 printf("ea_get list failed - %s\n", nt_errstr(status
));
5949 printf("num_eas = %d\n", (int)num_eas
);
5951 if (num_eas
!= 20) {
5952 printf("Should be 20 EA's stored... failing.\n");
5956 for (i
= 0; i
< num_eas
; i
++) {
5957 printf("%d: ea_name = %s. Val = ", i
, ea_list
[i
].name
);
5958 dump_data(0, ea_list
[i
].value
.data
,
5959 ea_list
[i
].value
.length
);
5962 /* Setting EA's to zero length deletes them. Test this */
5963 printf("Now deleting all EA's - case indepenent....\n");
5966 cli_set_ea_path(cli
, fname
, "", "", 0);
5968 for (i
= 0; i
< 20; i
++) {
5970 slprintf(ea_name
, sizeof(ea_name
), "ea_%d", i
);
5971 status
= cli_set_ea_path(cli
, fname
, ea_name
, "", 0);
5972 if (!NT_STATUS_IS_OK(status
)) {
5973 printf("ea_set of name %s failed - %s\n", ea_name
,
5975 talloc_destroy(mem_ctx
);
5981 status
= cli_get_ea_list_path(cli
, fname
, mem_ctx
, &num_eas
, &ea_list
);
5982 if (!NT_STATUS_IS_OK(status
)) {
5983 printf("ea_get list failed - %s\n", nt_errstr(status
));
5987 printf("num_eas = %d\n", (int)num_eas
);
5988 for (i
= 0; i
< num_eas
; i
++) {
5989 printf("%d: ea_name = %s. Val = ", i
, ea_list
[i
].name
);
5990 dump_data(0, ea_list
[i
].value
.data
,
5991 ea_list
[i
].value
.length
);
5995 printf("deleting EA's failed.\n");
5999 /* Try and delete a non existant EA. */
6000 status
= cli_set_ea_path(cli
, fname
, "foo", "", 0);
6001 if (!NT_STATUS_IS_OK(status
)) {
6002 printf("deleting non-existant EA 'foo' should succeed. %s\n",
6007 talloc_destroy(mem_ctx
);
6008 if (!torture_close_connection(cli
)) {
6015 static bool run_dirtest1(int dummy
)
6018 static struct cli_state
*cli
;
6021 bool correct
= True
;
6023 printf("starting directory test\n");
6025 if (!torture_open_connection(&cli
, 0)) {
6029 cli_sockopt(cli
, sockops
);
6031 cli_list(cli
, "\\LISTDIR\\*", 0, del_fn
, cli
);
6032 cli_list(cli
, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY
, del_fn
, cli
);
6033 cli_rmdir(cli
, "\\LISTDIR");
6034 cli_mkdir(cli
, "\\LISTDIR");
6036 /* Create 1000 files and 1000 directories. */
6037 for (i
=0;i
<1000;i
++) {
6039 slprintf(fname
, sizeof(fname
), "\\LISTDIR\\f%d", i
);
6040 if (!NT_STATUS_IS_OK(cli_ntcreate(cli
, fname
, 0, GENERIC_ALL_ACCESS
, FILE_ATTRIBUTE_ARCHIVE
,
6041 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OVERWRITE_IF
, 0, 0, &fnum
))) {
6042 fprintf(stderr
,"Failed to open %s\n", fname
);
6045 cli_close(cli
, fnum
);
6047 for (i
=0;i
<1000;i
++) {
6049 slprintf(fname
, sizeof(fname
), "\\LISTDIR\\d%d", i
);
6050 if (!NT_STATUS_IS_OK(cli_mkdir(cli
, fname
))) {
6051 fprintf(stderr
,"Failed to open %s\n", fname
);
6056 /* Now ensure that doing an old list sees both files and directories. */
6058 cli_list_old(cli
, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY
, list_fn
, &num_seen
);
6059 printf("num_seen = %d\n", num_seen
);
6060 /* We should see 100 files + 1000 directories + . and .. */
6061 if (num_seen
!= 2002)
6064 /* Ensure if we have the "must have" bits we only see the
6068 cli_list_old(cli
, "\\LISTDIR\\*", (FILE_ATTRIBUTE_DIRECTORY
<<8)|FILE_ATTRIBUTE_DIRECTORY
, list_fn
, &num_seen
);
6069 printf("num_seen = %d\n", num_seen
);
6070 if (num_seen
!= 1002)
6074 cli_list_old(cli
, "\\LISTDIR\\*", (FILE_ATTRIBUTE_ARCHIVE
<<8)|FILE_ATTRIBUTE_DIRECTORY
, list_fn
, &num_seen
);
6075 printf("num_seen = %d\n", num_seen
);
6076 if (num_seen
!= 1000)
6079 /* Delete everything. */
6080 cli_list(cli
, "\\LISTDIR\\*", 0, del_fn
, cli
);
6081 cli_list(cli
, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY
, del_fn
, cli
);
6082 cli_rmdir(cli
, "\\LISTDIR");
6085 printf("Matched %d\n", cli_list(cli
, "a*.*", 0, list_fn
, NULL
));
6086 printf("Matched %d\n", cli_list(cli
, "b*.*", 0, list_fn
, NULL
));
6087 printf("Matched %d\n", cli_list(cli
, "xyzabc", 0, list_fn
, NULL
));
6090 if (!torture_close_connection(cli
)) {
6094 printf("finished dirtest1\n");
6099 static bool run_error_map_extract(int dummy
) {
6101 static struct cli_state
*c_dos
;
6102 static struct cli_state
*c_nt
;
6107 uint32 flgs2
, errnum
;
6114 /* NT-Error connection */
6116 if (!(c_nt
= open_nbt_connection())) {
6120 c_nt
->use_spnego
= False
;
6122 status
= cli_negprot(c_nt
);
6124 if (!NT_STATUS_IS_OK(status
)) {
6125 printf("%s rejected the NT-error negprot (%s)\n", host
,
6131 status
= cli_session_setup(c_nt
, "", "", 0, "", 0, workgroup
);
6132 if (!NT_STATUS_IS_OK(status
)) {
6133 printf("%s rejected the NT-error initial session setup (%s)\n",host
, nt_errstr(status
));
6137 /* DOS-Error connection */
6139 if (!(c_dos
= open_nbt_connection())) {
6143 c_dos
->use_spnego
= False
;
6144 c_dos
->force_dos_errors
= True
;
6146 status
= cli_negprot(c_dos
);
6147 if (!NT_STATUS_IS_OK(status
)) {
6148 printf("%s rejected the DOS-error negprot (%s)\n", host
,
6150 cli_shutdown(c_dos
);
6154 status
= cli_session_setup(c_dos
, "", "", 0, "", 0, workgroup
);
6155 if (!NT_STATUS_IS_OK(status
)) {
6156 printf("%s rejected the DOS-error initial session setup (%s)\n",
6157 host
, nt_errstr(status
));
6161 for (error
=(0xc0000000 | 0x1); error
< (0xc0000000| 0xFFF); error
++) {
6162 fstr_sprintf(user
, "%X", error
);
6164 status
= cli_session_setup(c_nt
, user
,
6165 password
, strlen(password
),
6166 password
, strlen(password
),
6168 if (NT_STATUS_IS_OK(status
)) {
6169 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
6172 flgs2
= SVAL(c_nt
->inbuf
,smb_flg2
);
6174 /* Case #1: 32-bit NT errors */
6175 if (flgs2
& FLAGS2_32_BIT_ERROR_CODES
) {
6176 nt_status
= NT_STATUS(IVAL(c_nt
->inbuf
,smb_rcls
));
6178 printf("/** Dos error on NT connection! (%s) */\n",
6180 nt_status
= NT_STATUS(0xc0000000);
6183 if (NT_STATUS_IS_OK(cli_session_setup(c_dos
, user
,
6184 password
, strlen(password
),
6185 password
, strlen(password
),
6187 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
6189 flgs2
= SVAL(c_dos
->inbuf
,smb_flg2
), errnum
;
6191 /* Case #1: 32-bit NT errors */
6192 if (flgs2
& FLAGS2_32_BIT_ERROR_CODES
) {
6193 printf("/** NT error on DOS connection! (%s) */\n",
6195 errnum
= errclass
= 0;
6197 cli_dos_error(c_dos
, &errclass
, &errnum
);
6200 if (NT_STATUS_V(nt_status
) != error
) {
6201 printf("/*\t{ This NT error code was 'sqashed'\n\t from %s to %s \n\t during the session setup }\n*/\n",
6202 get_nt_error_c_code(talloc_tos(), NT_STATUS(error
)),
6203 get_nt_error_c_code(talloc_tos(), nt_status
));
6206 printf("\t{%s,\t%s,\t%s},\n",
6207 smb_dos_err_class(errclass
),
6208 smb_dos_err_name(errclass
, errnum
),
6209 get_nt_error_c_code(talloc_tos(), NT_STATUS(error
)));
6214 static bool run_sesssetup_bench(int dummy
)
6216 static struct cli_state
*c
;
6217 const char *fname
= "\\file.dat";
6222 if (!torture_open_connection(&c
, 0)) {
6226 status
= cli_ntcreate(c
, fname
, 0, GENERIC_ALL_ACCESS
|DELETE_ACCESS
,
6227 FILE_ATTRIBUTE_NORMAL
, 0, FILE_OVERWRITE_IF
,
6228 FILE_DELETE_ON_CLOSE
, 0, &fnum
);
6229 if (!NT_STATUS_IS_OK(status
)) {
6230 d_printf("open %s failed: %s\n", fname
, nt_errstr(status
));
6234 for (i
=0; i
<torture_numops
; i
++) {
6235 status
= cli_session_setup(
6237 password
, strlen(password
),
6238 password
, strlen(password
),
6240 if (!NT_STATUS_IS_OK(status
)) {
6241 d_printf("(%s) cli_session_setup failed: %s\n",
6242 __location__
, nt_errstr(status
));
6246 d_printf("\r%d ", (int)c
->vuid
);
6248 status
= cli_ulogoff(c
);
6249 if (!NT_STATUS_IS_OK(status
)) {
6250 d_printf("(%s) cli_ulogoff failed: %s\n",
6251 __location__
, nt_errstr(status
));
6260 static bool subst_test(const char *str
, const char *user
, const char *domain
,
6261 uid_t uid
, gid_t gid
, const char *expected
)
6266 subst
= talloc_sub_specified(talloc_tos(), str
, user
, domain
, uid
, gid
);
6268 if (strcmp(subst
, expected
) != 0) {
6269 printf("sub_specified(%s, %s, %s, %d, %d) returned [%s], expected "
6270 "[%s]\n", str
, user
, domain
, (int)uid
, (int)gid
, subst
,
6279 static void chain1_open_completion(struct tevent_req
*req
)
6283 status
= cli_open_recv(req
, &fnum
);
6286 d_printf("cli_open_recv returned %s: %d\n",
6288 NT_STATUS_IS_OK(status
) ? fnum
: -1);
6291 static void chain1_write_completion(struct tevent_req
*req
)
6295 status
= cli_write_andx_recv(req
, &written
);
6298 d_printf("cli_write_andx_recv returned %s: %d\n",
6300 NT_STATUS_IS_OK(status
) ? (int)written
: -1);
6303 static void chain1_close_completion(struct tevent_req
*req
)
6306 bool *done
= (bool *)tevent_req_callback_data_void(req
);
6308 status
= cli_close_recv(req
);
6313 d_printf("cli_close returned %s\n", nt_errstr(status
));
6316 static bool run_chain1(int dummy
)
6318 struct cli_state
*cli1
;
6319 struct event_context
*evt
= event_context_init(NULL
);
6320 struct tevent_req
*reqs
[3], *smbreqs
[3];
6322 const char *str
= "foobar";
6325 printf("starting chain1 test\n");
6326 if (!torture_open_connection(&cli1
, 0)) {
6330 cli_sockopt(cli1
, sockops
);
6332 reqs
[0] = cli_open_create(talloc_tos(), evt
, cli1
, "\\test",
6333 O_CREAT
|O_RDWR
, 0, &smbreqs
[0]);
6334 if (reqs
[0] == NULL
) return false;
6335 tevent_req_set_callback(reqs
[0], chain1_open_completion
, NULL
);
6338 reqs
[1] = cli_write_andx_create(talloc_tos(), evt
, cli1
, 0, 0,
6339 (const uint8_t *)str
, 0, strlen(str
)+1,
6340 smbreqs
, 1, &smbreqs
[1]);
6341 if (reqs
[1] == NULL
) return false;
6342 tevent_req_set_callback(reqs
[1], chain1_write_completion
, NULL
);
6344 reqs
[2] = cli_close_create(talloc_tos(), evt
, cli1
, 0, &smbreqs
[2]);
6345 if (reqs
[2] == NULL
) return false;
6346 tevent_req_set_callback(reqs
[2], chain1_close_completion
, &done
);
6348 status
= cli_smb_chain_send(smbreqs
, ARRAY_SIZE(smbreqs
));
6349 if (!NT_STATUS_IS_OK(status
)) {
6354 event_loop_once(evt
);
6357 torture_close_connection(cli1
);
6361 static void chain2_sesssetup_completion(struct tevent_req
*req
)
6364 status
= cli_session_setup_guest_recv(req
);
6365 d_printf("sesssetup returned %s\n", nt_errstr(status
));
6368 static void chain2_tcon_completion(struct tevent_req
*req
)
6370 bool *done
= (bool *)tevent_req_callback_data_void(req
);
6372 status
= cli_tcon_andx_recv(req
);
6373 d_printf("tcon_and_x returned %s\n", nt_errstr(status
));
6377 static bool run_chain2(int dummy
)
6379 struct cli_state
*cli1
;
6380 struct event_context
*evt
= event_context_init(NULL
);
6381 struct tevent_req
*reqs
[2], *smbreqs
[2];
6385 printf("starting chain2 test\n");
6386 status
= cli_start_connection(&cli1
, global_myname(), host
, NULL
,
6387 port_to_use
, Undefined
, 0);
6388 if (!NT_STATUS_IS_OK(status
)) {
6392 cli_sockopt(cli1
, sockops
);
6394 reqs
[0] = cli_session_setup_guest_create(talloc_tos(), evt
, cli1
,
6396 if (reqs
[0] == NULL
) return false;
6397 tevent_req_set_callback(reqs
[0], chain2_sesssetup_completion
, NULL
);
6399 reqs
[1] = cli_tcon_andx_create(talloc_tos(), evt
, cli1
, "IPC$",
6400 "?????", NULL
, 0, &smbreqs
[1]);
6401 if (reqs
[1] == NULL
) return false;
6402 tevent_req_set_callback(reqs
[1], chain2_tcon_completion
, &done
);
6404 status
= cli_smb_chain_send(smbreqs
, ARRAY_SIZE(smbreqs
));
6405 if (!NT_STATUS_IS_OK(status
)) {
6410 event_loop_once(evt
);
6413 torture_close_connection(cli1
);
6418 struct torture_createdel_state
{
6419 struct tevent_context
*ev
;
6420 struct cli_state
*cli
;
6423 static void torture_createdel_created(struct tevent_req
*subreq
);
6424 static void torture_createdel_closed(struct tevent_req
*subreq
);
6426 static struct tevent_req
*torture_createdel_send(TALLOC_CTX
*mem_ctx
,
6427 struct tevent_context
*ev
,
6428 struct cli_state
*cli
,
6431 struct tevent_req
*req
, *subreq
;
6432 struct torture_createdel_state
*state
;
6434 req
= tevent_req_create(mem_ctx
, &state
,
6435 struct torture_createdel_state
);
6442 subreq
= cli_ntcreate_send(
6443 state
, ev
, cli
, name
, 0,
6444 FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
6445 FILE_ATTRIBUTE_NORMAL
,
6446 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
6447 FILE_OPEN_IF
, FILE_DELETE_ON_CLOSE
, 0);
6449 if (tevent_req_nomem(subreq
, req
)) {
6450 return tevent_req_post(req
, ev
);
6452 tevent_req_set_callback(subreq
, torture_createdel_created
, req
);
6456 static void torture_createdel_created(struct tevent_req
*subreq
)
6458 struct tevent_req
*req
= tevent_req_callback_data(
6459 subreq
, struct tevent_req
);
6460 struct torture_createdel_state
*state
= tevent_req_data(
6461 req
, struct torture_createdel_state
);
6465 status
= cli_ntcreate_recv(subreq
, &fnum
);
6466 TALLOC_FREE(subreq
);
6467 if (!NT_STATUS_IS_OK(status
)) {
6468 DEBUG(10, ("cli_ntcreate_recv returned %s\n",
6469 nt_errstr(status
)));
6470 tevent_req_nterror(req
, status
);
6474 subreq
= cli_close_send(state
, state
->ev
, state
->cli
, fnum
);
6475 if (tevent_req_nomem(subreq
, req
)) {
6478 tevent_req_set_callback(subreq
, torture_createdel_closed
, req
);
6481 static void torture_createdel_closed(struct tevent_req
*subreq
)
6483 struct tevent_req
*req
= tevent_req_callback_data(
6484 subreq
, struct tevent_req
);
6487 status
= cli_close_recv(subreq
);
6488 if (!NT_STATUS_IS_OK(status
)) {
6489 DEBUG(10, ("cli_close_recv returned %s\n", nt_errstr(status
)));
6490 tevent_req_nterror(req
, status
);
6493 tevent_req_done(req
);
6496 static NTSTATUS
torture_createdel_recv(struct tevent_req
*req
)
6498 return tevent_req_simple_recv_ntstatus(req
);
6501 struct torture_createdels_state
{
6502 struct tevent_context
*ev
;
6503 struct cli_state
*cli
;
6504 const char *base_name
;
6508 struct tevent_req
**reqs
;
6511 static void torture_createdels_done(struct tevent_req
*subreq
);
6513 static struct tevent_req
*torture_createdels_send(TALLOC_CTX
*mem_ctx
,
6514 struct tevent_context
*ev
,
6515 struct cli_state
*cli
,
6516 const char *base_name
,
6520 struct tevent_req
*req
;
6521 struct torture_createdels_state
*state
;
6524 req
= tevent_req_create(mem_ctx
, &state
,
6525 struct torture_createdels_state
);
6531 state
->base_name
= talloc_strdup(state
, base_name
);
6532 if (tevent_req_nomem(state
->base_name
, req
)) {
6533 return tevent_req_post(req
, ev
);
6535 state
->num_files
= MAX(num_parallel
, num_files
);
6537 state
->received
= 0;
6539 state
->reqs
= talloc_array(state
, struct tevent_req
*, num_parallel
);
6540 if (tevent_req_nomem(state
->reqs
, req
)) {
6541 return tevent_req_post(req
, ev
);
6544 for (i
=0; i
<num_parallel
; i
++) {
6547 name
= talloc_asprintf(state
, "%s%8.8d", state
->base_name
,
6549 if (tevent_req_nomem(name
, req
)) {
6550 return tevent_req_post(req
, ev
);
6552 state
->reqs
[i
] = torture_createdel_send(
6553 state
->reqs
, state
->ev
, state
->cli
, name
);
6554 if (tevent_req_nomem(state
->reqs
[i
], req
)) {
6555 return tevent_req_post(req
, ev
);
6557 name
= talloc_move(state
->reqs
[i
], &name
);
6558 tevent_req_set_callback(state
->reqs
[i
],
6559 torture_createdels_done
, req
);
6565 static void torture_createdels_done(struct tevent_req
*subreq
)
6567 struct tevent_req
*req
= tevent_req_callback_data(
6568 subreq
, struct tevent_req
);
6569 struct torture_createdels_state
*state
= tevent_req_data(
6570 req
, struct torture_createdels_state
);
6571 size_t num_parallel
= talloc_array_length(state
->reqs
);
6576 status
= torture_createdel_recv(subreq
);
6577 if (!NT_STATUS_IS_OK(status
)){
6578 DEBUG(10, ("torture_createdel_recv returned %s\n",
6579 nt_errstr(status
)));
6580 TALLOC_FREE(subreq
);
6581 tevent_req_nterror(req
, status
);
6585 for (i
=0; i
<num_parallel
; i
++) {
6586 if (subreq
== state
->reqs
[i
]) {
6590 if (i
== num_parallel
) {
6591 DEBUG(10, ("received something we did not send\n"));
6592 tevent_req_nterror(req
, NT_STATUS_INTERNAL_ERROR
);
6595 TALLOC_FREE(state
->reqs
[i
]);
6597 if (state
->sent
>= state
->num_files
) {
6598 tevent_req_done(req
);
6602 name
= talloc_asprintf(state
, "%s%8.8d", state
->base_name
,
6604 if (tevent_req_nomem(name
, req
)) {
6607 state
->reqs
[i
] = torture_createdel_send(state
->reqs
, state
->ev
,
6609 if (tevent_req_nomem(state
->reqs
[i
], req
)) {
6612 name
= talloc_move(state
->reqs
[i
], &name
);
6613 tevent_req_set_callback(state
->reqs
[i
], torture_createdels_done
, req
);
6617 static NTSTATUS
torture_createdels_recv(struct tevent_req
*req
)
6619 return tevent_req_simple_recv_ntstatus(req
);
6622 struct swallow_notify_state
{
6623 struct tevent_context
*ev
;
6624 struct cli_state
*cli
;
6626 uint32_t completion_filter
;
6628 bool (*fn
)(uint32_t action
, const char *name
, void *priv
);
6632 static void swallow_notify_done(struct tevent_req
*subreq
);
6634 static struct tevent_req
*swallow_notify_send(TALLOC_CTX
*mem_ctx
,
6635 struct tevent_context
*ev
,
6636 struct cli_state
*cli
,
6638 uint32_t completion_filter
,
6640 bool (*fn
)(uint32_t action
,
6645 struct tevent_req
*req
, *subreq
;
6646 struct swallow_notify_state
*state
;
6648 req
= tevent_req_create(mem_ctx
, &state
,
6649 struct swallow_notify_state
);
6656 state
->completion_filter
= completion_filter
;
6657 state
->recursive
= recursive
;
6661 subreq
= cli_notify_send(state
, state
->ev
, state
->cli
, state
->fnum
,
6662 0xffff, state
->completion_filter
,
6664 if (tevent_req_nomem(subreq
, req
)) {
6665 return tevent_req_post(req
, ev
);
6667 tevent_req_set_callback(subreq
, swallow_notify_done
, req
);
6671 static void swallow_notify_done(struct tevent_req
*subreq
)
6673 struct tevent_req
*req
= tevent_req_callback_data(
6674 subreq
, struct tevent_req
);
6675 struct swallow_notify_state
*state
= tevent_req_data(
6676 req
, struct swallow_notify_state
);
6678 uint32_t i
, num_changes
;
6679 struct notify_change
*changes
;
6681 status
= cli_notify_recv(subreq
, state
, &num_changes
, &changes
);
6682 TALLOC_FREE(subreq
);
6683 if (!NT_STATUS_IS_OK(status
)) {
6684 DEBUG(10, ("cli_notify_recv returned %s\n",
6685 nt_errstr(status
)));
6686 tevent_req_nterror(req
, status
);
6690 for (i
=0; i
<num_changes
; i
++) {
6691 state
->fn(changes
[i
].action
, changes
[i
].name
, state
->priv
);
6693 TALLOC_FREE(changes
);
6695 subreq
= cli_notify_send(state
, state
->ev
, state
->cli
, state
->fnum
,
6696 0xffff, state
->completion_filter
,
6698 if (tevent_req_nomem(subreq
, req
)) {
6701 tevent_req_set_callback(subreq
, swallow_notify_done
, req
);
6704 static bool print_notifies(uint32_t action
, const char *name
, void *priv
)
6706 if (DEBUGLEVEL
> 5) {
6707 d_printf("%d %s\n", (int)action
, name
);
6712 static void notify_bench_done(struct tevent_req
*req
)
6714 int *num_finished
= (int *)tevent_req_callback_data_void(req
);
6718 static bool run_notify_bench(int dummy
)
6720 const char *dname
= "\\notify-bench";
6721 struct tevent_context
*ev
;
6724 struct tevent_req
*req1
;
6725 struct tevent_req
*req2
= NULL
;
6726 int i
, num_unc_names
;
6727 int num_finished
= 0;
6729 printf("starting notify-bench test\n");
6731 if (use_multishare_conn
) {
6733 unc_list
= file_lines_load(multishare_conn_fname
,
6734 &num_unc_names
, 0, NULL
);
6735 if (!unc_list
|| num_unc_names
<= 0) {
6736 d_printf("Failed to load unc names list from '%s'\n",
6737 multishare_conn_fname
);
6740 TALLOC_FREE(unc_list
);
6745 ev
= tevent_context_init(talloc_tos());
6747 d_printf("tevent_context_init failed\n");
6751 for (i
=0; i
<num_unc_names
; i
++) {
6752 struct cli_state
*cli
;
6755 base_fname
= talloc_asprintf(talloc_tos(), "%s\\file%3.3d.",
6757 if (base_fname
== NULL
) {
6761 if (!torture_open_connection(&cli
, i
)) {
6765 status
= cli_ntcreate(cli
, dname
, 0,
6766 MAXIMUM_ALLOWED_ACCESS
,
6767 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
|
6769 FILE_OPEN_IF
, FILE_DIRECTORY_FILE
, 0,
6772 if (!NT_STATUS_IS_OK(status
)) {
6773 d_printf("Could not create %s: %s\n", dname
,
6778 req1
= swallow_notify_send(talloc_tos(), ev
, cli
, dnum
,
6779 FILE_NOTIFY_CHANGE_FILE_NAME
|
6780 FILE_NOTIFY_CHANGE_DIR_NAME
|
6781 FILE_NOTIFY_CHANGE_ATTRIBUTES
|
6782 FILE_NOTIFY_CHANGE_LAST_WRITE
,
6783 false, print_notifies
, NULL
);
6785 d_printf("Could not create notify request\n");
6789 req2
= torture_createdels_send(talloc_tos(), ev
, cli
,
6790 base_fname
, 10, torture_numops
);
6792 d_printf("Could not create createdels request\n");
6795 TALLOC_FREE(base_fname
);
6797 tevent_req_set_callback(req2
, notify_bench_done
,
6801 while (num_finished
< num_unc_names
) {
6803 ret
= tevent_loop_once(ev
);
6805 d_printf("tevent_loop_once failed\n");
6810 if (!tevent_req_poll(req2
, ev
)) {
6811 d_printf("tevent_req_poll failed\n");
6814 status
= torture_createdels_recv(req2
);
6815 d_printf("torture_createdels_recv returned %s\n", nt_errstr(status
));
6820 static bool run_mangle1(int dummy
)
6822 struct cli_state
*cli
;
6823 const char *fname
= "this_is_a_long_fname_to_be_mangled.txt";
6827 time_t change_time
, access_time
, write_time
;
6831 printf("starting mangle1 test\n");
6832 if (!torture_open_connection(&cli
, 0)) {
6836 cli_sockopt(cli
, sockops
);
6838 status
= cli_ntcreate(cli
, fname
, 0, GENERIC_ALL_ACCESS
|DELETE_ACCESS
,
6839 FILE_ATTRIBUTE_NORMAL
, 0, FILE_OVERWRITE_IF
,
6841 if (!NT_STATUS_IS_OK(status
)) {
6842 d_printf("open %s failed: %s\n", fname
, nt_errstr(status
));
6845 cli_close(cli
, fnum
);
6847 status
= cli_qpathinfo_alt_name(cli
, fname
, alt_name
);
6848 if (!NT_STATUS_IS_OK(status
)) {
6849 d_printf("cli_qpathinfo_alt_name failed: %s\n",
6853 d_printf("alt_name: %s\n", alt_name
);
6855 status
= cli_open(cli
, alt_name
, O_RDONLY
, DENY_NONE
, &fnum
);
6856 if (!NT_STATUS_IS_OK(status
)) {
6857 d_printf("cli_open(%s) failed: %s\n", alt_name
,
6861 cli_close(cli
, fnum
);
6863 status
= cli_qpathinfo1(cli
, alt_name
, &change_time
, &access_time
,
6864 &write_time
, &size
, &mode
);
6865 if (!NT_STATUS_IS_OK(status
)) {
6866 d_printf("cli_qpathinfo1(%s) failed: %s\n", alt_name
,
6874 static size_t null_source(uint8_t *buf
, size_t n
, void *priv
)
6876 size_t *to_pull
= (size_t *)priv
;
6877 size_t thistime
= *to_pull
;
6879 thistime
= MIN(thistime
, n
);
6880 if (thistime
== 0) {
6884 memset(buf
, 0, thistime
);
6885 *to_pull
-= thistime
;
6889 static bool run_windows_write(int dummy
)
6891 struct cli_state
*cli1
;
6895 const char *fname
= "\\writetest.txt";
6896 struct timeval start_time
;
6901 printf("starting windows_write test\n");
6902 if (!torture_open_connection(&cli1
, 0)) {
6906 status
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum
);
6907 if (!NT_STATUS_IS_OK(status
)) {
6908 printf("open failed (%s)\n", nt_errstr(status
));
6912 cli_sockopt(cli1
, sockops
);
6914 start_time
= timeval_current();
6916 for (i
=0; i
<torture_numops
; i
++) {
6918 off_t start
= i
* torture_blocksize
;
6919 size_t to_pull
= torture_blocksize
- 1;
6921 status
= cli_writeall(cli1
, fnum
, 0, &c
,
6922 start
+ torture_blocksize
- 1, 1, NULL
);
6923 if (!NT_STATUS_IS_OK(status
)) {
6924 printf("cli_write failed: %s\n", nt_errstr(status
));
6928 status
= cli_push(cli1
, fnum
, 0, i
* torture_blocksize
, torture_blocksize
,
6929 null_source
, &to_pull
);
6930 if (!NT_STATUS_IS_OK(status
)) {
6931 printf("cli_push returned: %s\n", nt_errstr(status
));
6936 seconds
= timeval_elapsed(&start_time
);
6937 kbytes
= (double)torture_blocksize
* torture_numops
;
6940 printf("Wrote %d kbytes in %.2f seconds: %d kb/sec\n", (int)kbytes
,
6941 (double)seconds
, (int)(kbytes
/seconds
));
6945 cli_close(cli1
, fnum
);
6946 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
6947 torture_close_connection(cli1
);
6951 static bool run_cli_echo(int dummy
)
6953 struct cli_state
*cli
;
6956 printf("starting cli_echo test\n");
6957 if (!torture_open_connection(&cli
, 0)) {
6960 cli_sockopt(cli
, sockops
);
6962 status
= cli_echo(cli
, 5, data_blob_const("hello", 5));
6964 d_printf("cli_echo returned %s\n", nt_errstr(status
));
6966 torture_close_connection(cli
);
6967 return NT_STATUS_IS_OK(status
);
6970 static bool run_uid_regression_test(int dummy
)
6972 static struct cli_state
*cli
;
6975 bool correct
= True
;
6978 printf("starting uid regression test\n");
6980 if (!torture_open_connection(&cli
, 0)) {
6984 cli_sockopt(cli
, sockops
);
6986 /* Ok - now save then logoff our current user. */
6987 old_vuid
= cli
->vuid
;
6989 status
= cli_ulogoff(cli
);
6990 if (!NT_STATUS_IS_OK(status
)) {
6991 d_printf("(%s) cli_ulogoff failed: %s\n",
6992 __location__
, nt_errstr(status
));
6997 cli
->vuid
= old_vuid
;
6999 /* Try an operation. */
7000 status
= cli_mkdir(cli
, "\\uid_reg_test");
7001 if (NT_STATUS_IS_OK(status
)) {
7002 d_printf("(%s) cli_mkdir succeeded\n",
7007 /* Should be bad uid. */
7008 if (!check_error(__LINE__
, cli
, ERRSRV
, ERRbaduid
,
7009 NT_STATUS_USER_SESSION_DELETED
)) {
7015 old_cnum
= cli
->cnum
;
7017 /* Now try a SMBtdis with the invald vuid set to zero. */
7020 /* This should succeed. */
7021 status
= cli_tdis(cli
);
7023 if (NT_STATUS_IS_OK(status
)) {
7024 d_printf("First tdis with invalid vuid should succeed.\n");
7026 d_printf("First tdis failed (%s)\n", nt_errstr(status
));
7031 cli
->vuid
= old_vuid
;
7032 cli
->cnum
= old_cnum
;
7034 /* This should fail. */
7035 status
= cli_tdis(cli
);
7036 if (NT_STATUS_IS_OK(status
)) {
7037 d_printf("Second tdis with invalid vuid should fail - succeeded instead !.\n");
7041 /* Should be bad tid. */
7042 if (!check_error(__LINE__
, cli
, ERRSRV
, ERRinvnid
,
7043 NT_STATUS_NETWORK_NAME_DELETED
)) {
7049 cli_rmdir(cli
, "\\uid_reg_test");
7058 static const char *illegal_chars
= "*\\/?<>|\":";
7059 static char force_shortname_chars
[] = " +,.[];=\177";
7061 static NTSTATUS
shortname_del_fn(const char *mnt
, struct file_info
*finfo
,
7062 const char *mask
, void *state
)
7064 struct cli_state
*pcli
= (struct cli_state
*)state
;
7066 NTSTATUS status
= NT_STATUS_OK
;
7068 slprintf(fname
, sizeof(fname
), "\\shortname\\%s", finfo
->name
);
7070 if (strcmp(finfo
->name
, ".") == 0 || strcmp(finfo
->name
, "..") == 0)
7071 return NT_STATUS_OK
;
7073 if (finfo
->mode
& FILE_ATTRIBUTE_DIRECTORY
) {
7074 status
= cli_rmdir(pcli
, fname
);
7075 if (!NT_STATUS_IS_OK(status
)) {
7076 printf("del_fn: failed to rmdir %s\n,", fname
);
7079 status
= cli_unlink(pcli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
7080 if (!NT_STATUS_IS_OK(status
)) {
7081 printf("del_fn: failed to unlink %s\n,", fname
);
7093 static NTSTATUS
shortname_list_fn(const char *mnt
, struct file_info
*finfo
,
7094 const char *name
, void *state
)
7096 struct sn_state
*s
= (struct sn_state
*)state
;
7100 printf("shortname list: i = %d, name = |%s|, shortname = |%s|\n",
7101 i
, finfo
->name
, finfo
->short_name
);
7104 if (strchr(force_shortname_chars
, i
)) {
7105 if (!finfo
->short_name
[0]) {
7106 /* Shortname not created when it should be. */
7107 d_printf("(%s) ERROR: Shortname was not created for file %s containing %d\n",
7108 __location__
, finfo
->name
, i
);
7111 } else if (finfo
->short_name
[0]){
7112 /* Shortname created when it should not be. */
7113 d_printf("(%s) ERROR: Shortname %s was created for file %s\n",
7114 __location__
, finfo
->short_name
, finfo
->name
);
7118 return NT_STATUS_OK
;
7121 static bool run_shortname_test(int dummy
)
7123 static struct cli_state
*cli
;
7124 bool correct
= True
;
7130 printf("starting shortname test\n");
7132 if (!torture_open_connection(&cli
, 0)) {
7136 cli_sockopt(cli
, sockops
);
7138 cli_list(cli
, "\\shortname\\*", 0, shortname_del_fn
, cli
);
7139 cli_list(cli
, "\\shortname\\*", FILE_ATTRIBUTE_DIRECTORY
, shortname_del_fn
, cli
);
7140 cli_rmdir(cli
, "\\shortname");
7142 status
= cli_mkdir(cli
, "\\shortname");
7143 if (!NT_STATUS_IS_OK(status
)) {
7144 d_printf("(%s) cli_mkdir of \\shortname failed: %s\n",
7145 __location__
, nt_errstr(status
));
7150 strlcpy(fname
, "\\shortname\\", sizeof(fname
));
7151 strlcat(fname
, "test .txt", sizeof(fname
));
7155 for (i
= 32; i
< 128; i
++) {
7156 uint16_t fnum
= (uint16_t)-1;
7160 if (strchr(illegal_chars
, i
)) {
7165 status
= cli_ntcreate(cli
, fname
, 0, GENERIC_ALL_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
7166 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OVERWRITE_IF
, 0, 0, &fnum
);
7167 if (!NT_STATUS_IS_OK(status
)) {
7168 d_printf("(%s) cli_nt_create of %s failed: %s\n",
7169 __location__
, fname
, nt_errstr(status
));
7173 cli_close(cli
, fnum
);
7176 cli_list(cli
, "\\shortname\\test*.*", 0, shortname_list_fn
,
7178 if (s
.matched
!= 1) {
7179 d_printf("(%s) failed to list %s: %s\n",
7180 __location__
, fname
, cli_errstr(cli
));
7185 status
= cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
7186 if (!NT_STATUS_IS_OK(status
)) {
7187 d_printf("(%s) failed to delete %s: %s\n",
7188 __location__
, fname
, nt_errstr(status
));
7201 cli_list(cli
, "\\shortname\\*", 0, shortname_del_fn
, cli
);
7202 cli_list(cli
, "\\shortname\\*", FILE_ATTRIBUTE_DIRECTORY
, shortname_del_fn
, cli
);
7203 cli_rmdir(cli
, "\\shortname");
7204 torture_close_connection(cli
);
7208 static void pagedsearch_cb(struct tevent_req
*req
)
7211 struct tldap_message
*msg
;
7214 rc
= tldap_search_paged_recv(req
, talloc_tos(), &msg
);
7215 if (rc
!= TLDAP_SUCCESS
) {
7216 d_printf("tldap_search_paged_recv failed: %s\n",
7217 tldap_err2string(rc
));
7220 if (tldap_msg_type(msg
) != TLDAP_RES_SEARCH_ENTRY
) {
7224 if (!tldap_entry_dn(msg
, &dn
)) {
7225 d_printf("tldap_entry_dn failed\n");
7228 d_printf("%s\n", dn
);
7232 static bool run_tldap(int dummy
)
7234 struct tldap_context
*ld
;
7237 struct sockaddr_storage addr
;
7238 struct tevent_context
*ev
;
7239 struct tevent_req
*req
;
7243 if (!resolve_name(host
, &addr
, 0, false)) {
7244 d_printf("could not find host %s\n", host
);
7247 status
= open_socket_out(&addr
, 389, 9999, &fd
);
7248 if (!NT_STATUS_IS_OK(status
)) {
7249 d_printf("open_socket_out failed: %s\n", nt_errstr(status
));
7253 ld
= tldap_context_create(talloc_tos(), fd
);
7256 d_printf("tldap_context_create failed\n");
7260 rc
= tldap_fetch_rootdse(ld
);
7261 if (rc
!= TLDAP_SUCCESS
) {
7262 d_printf("tldap_fetch_rootdse failed: %s\n",
7263 tldap_errstr(talloc_tos(), ld
, rc
));
7267 basedn
= tldap_talloc_single_attribute(
7268 tldap_rootdse(ld
), "defaultNamingContext", talloc_tos());
7269 if (basedn
== NULL
) {
7270 d_printf("no defaultNamingContext\n");
7273 d_printf("defaultNamingContext: %s\n", basedn
);
7275 ev
= tevent_context_init(talloc_tos());
7277 d_printf("tevent_context_init failed\n");
7281 req
= tldap_search_paged_send(talloc_tos(), ev
, ld
, basedn
,
7282 TLDAP_SCOPE_SUB
, "(objectclass=*)",
7284 NULL
, 0, NULL
, 0, 0, 0, 0, 5);
7286 d_printf("tldap_search_paged_send failed\n");
7289 tevent_req_set_callback(req
, pagedsearch_cb
, NULL
);
7291 tevent_req_poll(req
, ev
);
7295 /* test search filters against rootDSE */
7296 filter
= "(&(|(name=samba)(nextRid<=10000000)(usnChanged>=10)(samba~=ambas)(!(name=s*m*a)))"
7297 "(|(name:=samba)(name:dn:2.5.13.5:=samba)(:dn:2.5.13.5:=samba)(!(name=*samba))))";
7299 rc
= tldap_search(ld
, "", TLDAP_SCOPE_BASE
, filter
,
7300 NULL
, 0, 0, NULL
, 0, NULL
, 0, 0, 0, 0,
7301 talloc_tos(), NULL
, NULL
);
7302 if (rc
!= TLDAP_SUCCESS
) {
7303 d_printf("tldap_search with complex filter failed: %s\n",
7304 tldap_errstr(talloc_tos(), ld
, rc
));
7312 /* Torture test to ensure no regression of :
7313 https://bugzilla.samba.org/show_bug.cgi?id=7084
7316 static bool run_dir_createtime(int dummy
)
7318 struct cli_state
*cli
;
7319 const char *dname
= "\\testdir";
7320 const char *fname
= "\\testdir\\testfile";
7322 struct timespec create_time
;
7323 struct timespec create_time1
;
7327 if (!torture_open_connection(&cli
, 0)) {
7331 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
7332 cli_rmdir(cli
, dname
);
7334 status
= cli_mkdir(cli
, dname
);
7335 if (!NT_STATUS_IS_OK(status
)) {
7336 printf("mkdir failed: %s\n", nt_errstr(status
));
7340 status
= cli_qpathinfo2(cli
, dname
, &create_time
, NULL
, NULL
, NULL
,
7342 if (!NT_STATUS_IS_OK(status
)) {
7343 printf("cli_qpathinfo2 returned %s\n",
7348 /* Sleep 3 seconds, then create a file. */
7351 status
= cli_open(cli
, fname
, O_RDWR
| O_CREAT
| O_EXCL
,
7353 if (!NT_STATUS_IS_OK(status
)) {
7354 printf("cli_open failed: %s\n", nt_errstr(status
));
7358 status
= cli_qpathinfo2(cli
, dname
, &create_time1
, NULL
, NULL
, NULL
,
7360 if (!NT_STATUS_IS_OK(status
)) {
7361 printf("cli_qpathinfo2 (2) returned %s\n",
7366 if (timespec_compare(&create_time1
, &create_time
)) {
7367 printf("run_dir_createtime: create time was updated (error)\n");
7369 printf("run_dir_createtime: create time was not updated (correct)\n");
7375 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
7376 cli_rmdir(cli
, dname
);
7377 if (!torture_close_connection(cli
)) {
7384 static bool run_streamerror(int dummy
)
7386 struct cli_state
*cli
;
7387 const char *dname
= "\\testdir";
7388 const char *streamname
=
7389 "testdir:{4c8cc155-6c1e-11d1-8e41-00c04fb9386d}:$DATA";
7391 time_t change_time
, access_time
, write_time
;
7393 uint16_t mode
, fnum
;
7396 if (!torture_open_connection(&cli
, 0)) {
7400 cli_unlink(cli
, "\\testdir\\*", FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
7401 cli_rmdir(cli
, dname
);
7403 status
= cli_mkdir(cli
, dname
);
7404 if (!NT_STATUS_IS_OK(status
)) {
7405 printf("mkdir failed: %s\n", nt_errstr(status
));
7409 cli_qpathinfo1(cli
, streamname
, &change_time
, &access_time
, &write_time
,
7411 status
= cli_nt_error(cli
);
7413 if (!NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
7414 printf("pathinfo returned %s, expected "
7415 "NT_STATUS_OBJECT_NAME_NOT_FOUND\n",
7420 status
= cli_ntcreate(cli
, streamname
, 0x16,
7421 FILE_READ_DATA
|FILE_READ_EA
|
7422 FILE_READ_ATTRIBUTES
|READ_CONTROL_ACCESS
,
7423 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
,
7424 FILE_OPEN
, 0, 0, &fnum
);
7426 if (!NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
7427 printf("ntcreate returned %s, expected "
7428 "NT_STATUS_OBJECT_NAME_NOT_FOUND\n",
7434 cli_rmdir(cli
, dname
);
7438 static bool run_local_substitute(int dummy
)
7442 ok
&= subst_test("%U", "bla", "", -1, -1, "bla");
7443 ok
&= subst_test("%u%U", "bla", "", -1, -1, "blabla");
7444 ok
&= subst_test("%g", "", "", -1, -1, "NO_GROUP");
7445 ok
&= subst_test("%G", "", "", -1, -1, "NO_GROUP");
7446 ok
&= subst_test("%g", "", "", -1, 0, gidtoname(0));
7447 ok
&= subst_test("%G", "", "", -1, 0, gidtoname(0));
7448 ok
&= subst_test("%D%u", "u", "dom", -1, 0, "domu");
7449 ok
&= subst_test("%i %I", "", "", -1, -1, "0.0.0.0 0.0.0.0");
7451 /* Different captialization rules in sub_basic... */
7453 ok
&= (strcmp(talloc_sub_basic(talloc_tos(), "BLA", "dom", "%U%D"),
7459 static bool run_local_base64(int dummy
)
7464 for (i
=1; i
<2000; i
++) {
7465 DATA_BLOB blob1
, blob2
;
7468 blob1
.data
= talloc_array(talloc_tos(), uint8_t, i
);
7470 generate_random_buffer(blob1
.data
, blob1
.length
);
7472 b64
= base64_encode_data_blob(talloc_tos(), blob1
);
7474 d_fprintf(stderr
, "base64_encode_data_blob failed "
7475 "for %d bytes\n", i
);
7478 blob2
= base64_decode_data_blob(b64
);
7481 if (data_blob_cmp(&blob1
, &blob2
)) {
7482 d_fprintf(stderr
, "data_blob_cmp failed for %d "
7486 TALLOC_FREE(blob1
.data
);
7487 data_blob_free(&blob2
);
7492 static bool run_local_gencache(int dummy
)
7498 if (!gencache_set("foo", "bar", time(NULL
) + 1000)) {
7499 d_printf("%s: gencache_set() failed\n", __location__
);
7503 if (!gencache_get("foo", NULL
, NULL
)) {
7504 d_printf("%s: gencache_get() failed\n", __location__
);
7508 if (!gencache_get("foo", &val
, &tm
)) {
7509 d_printf("%s: gencache_get() failed\n", __location__
);
7513 if (strcmp(val
, "bar") != 0) {
7514 d_printf("%s: gencache_get() returned %s, expected %s\n",
7515 __location__
, val
, "bar");
7522 if (!gencache_del("foo")) {
7523 d_printf("%s: gencache_del() failed\n", __location__
);
7526 if (gencache_del("foo")) {
7527 d_printf("%s: second gencache_del() succeeded\n",
7532 if (gencache_get("foo", &val
, &tm
)) {
7533 d_printf("%s: gencache_get() on deleted entry "
7534 "succeeded\n", __location__
);
7538 blob
= data_blob_string_const_null("bar");
7539 tm
= time(NULL
) + 60;
7541 if (!gencache_set_data_blob("foo", &blob
, tm
)) {
7542 d_printf("%s: gencache_set_data_blob() failed\n", __location__
);
7546 if (!gencache_get_data_blob("foo", &blob
, NULL
, NULL
)) {
7547 d_printf("%s: gencache_get_data_blob() failed\n", __location__
);
7551 if (strcmp((const char *)blob
.data
, "bar") != 0) {
7552 d_printf("%s: gencache_get_data_blob() returned %s, expected %s\n",
7553 __location__
, (const char *)blob
.data
, "bar");
7554 data_blob_free(&blob
);
7558 data_blob_free(&blob
);
7560 if (!gencache_del("foo")) {
7561 d_printf("%s: gencache_del() failed\n", __location__
);
7564 if (gencache_del("foo")) {
7565 d_printf("%s: second gencache_del() succeeded\n",
7570 if (gencache_get_data_blob("foo", &blob
, NULL
, NULL
)) {
7571 d_printf("%s: gencache_get_data_blob() on deleted entry "
7572 "succeeded\n", __location__
);
7579 static bool rbt_testval(struct db_context
*db
, const char *key
,
7582 struct db_record
*rec
;
7583 TDB_DATA data
= string_tdb_data(value
);
7587 rec
= db
->fetch_locked(db
, db
, string_tdb_data(key
));
7589 d_fprintf(stderr
, "fetch_locked failed\n");
7592 status
= rec
->store(rec
, data
, 0);
7593 if (!NT_STATUS_IS_OK(status
)) {
7594 d_fprintf(stderr
, "store failed: %s\n", nt_errstr(status
));
7599 rec
= db
->fetch_locked(db
, db
, string_tdb_data(key
));
7601 d_fprintf(stderr
, "second fetch_locked failed\n");
7604 if ((rec
->value
.dsize
!= data
.dsize
)
7605 || (memcmp(rec
->value
.dptr
, data
.dptr
, data
.dsize
) != 0)) {
7606 d_fprintf(stderr
, "Got wrong data back\n");
7616 static bool run_local_rbtree(int dummy
)
7618 struct db_context
*db
;
7622 db
= db_open_rbt(NULL
);
7625 d_fprintf(stderr
, "db_open_rbt failed\n");
7629 for (i
=0; i
<1000; i
++) {
7632 if (asprintf(&key
, "key%ld", random()) == -1) {
7635 if (asprintf(&value
, "value%ld", random()) == -1) {
7640 if (!rbt_testval(db
, key
, value
)) {
7647 if (asprintf(&value
, "value%ld", random()) == -1) {
7652 if (!rbt_testval(db
, key
, value
)) {
7671 local test for character set functions
7673 This is a very simple test for the functionality in convert_string_error()
7675 static bool run_local_convert_string(int dummy
)
7677 TALLOC_CTX
*tmp_ctx
= talloc_new(NULL
);
7678 const char *test_strings
[2] = { "March", "M\303\244rz" };
7682 for (i
=0; i
<2; i
++) {
7683 const char *str
= test_strings
[i
];
7684 int len
= strlen(str
);
7685 size_t converted_size
;
7688 memset(dst
, 'X', sizeof(dst
));
7690 /* first try with real source length */
7691 ret
= convert_string_error(CH_UNIX
, CH_UTF8
,
7696 d_fprintf(stderr
, "Failed to convert '%s' to CH_DISPLAY\n", str
);
7700 if (converted_size
!= len
) {
7701 d_fprintf(stderr
, "Converted size of '%s' should be %d - got %d\n",
7702 str
, len
, (int)converted_size
);
7706 if (strncmp(str
, dst
, converted_size
) != 0) {
7707 d_fprintf(stderr
, "Expected '%s' to match '%s'\n", str
, dst
);
7711 if (strlen(str
) != converted_size
) {
7712 d_fprintf(stderr
, "Expected '%s' length %d - got %d\n", str
,
7713 (int)strlen(str
), (int)converted_size
);
7717 if (dst
[converted_size
] != 'X') {
7718 d_fprintf(stderr
, "Expected no termination of '%s'\n", dst
);
7722 /* now with srclen==-1, this causes the nul to be
7724 ret
= convert_string_error(CH_UNIX
, CH_UTF8
,
7729 d_fprintf(stderr
, "Failed to convert '%s' to CH_DISPLAY\n", str
);
7733 if (converted_size
!= len
+1) {
7734 d_fprintf(stderr
, "Converted size of '%s' should be %d - got %d\n",
7735 str
, len
, (int)converted_size
);
7739 if (strncmp(str
, dst
, converted_size
) != 0) {
7740 d_fprintf(stderr
, "Expected '%s' to match '%s'\n", str
, dst
);
7744 if (len
+1 != converted_size
) {
7745 d_fprintf(stderr
, "Expected '%s' length %d - got %d\n", str
,
7746 len
+1, (int)converted_size
);
7750 if (dst
[converted_size
] != 'X') {
7751 d_fprintf(stderr
, "Expected no termination of '%s'\n", dst
);
7758 TALLOC_FREE(tmp_ctx
);
7761 TALLOC_FREE(tmp_ctx
);
7766 struct talloc_dict_test
{
7770 static int talloc_dict_traverse_fn(DATA_BLOB key
, void *data
, void *priv
)
7772 int *count
= (int *)priv
;
7777 static bool run_local_talloc_dict(int dummy
)
7779 struct talloc_dict
*dict
;
7780 struct talloc_dict_test
*t
;
7783 dict
= talloc_dict_init(talloc_tos());
7788 t
= talloc(talloc_tos(), struct talloc_dict_test
);
7795 if (!talloc_dict_set(dict
, data_blob_const(&key
, sizeof(key
)), t
)) {
7800 if (talloc_dict_traverse(dict
, talloc_dict_traverse_fn
, &count
) != 0) {
7813 static bool run_local_string_to_sid(int dummy
) {
7816 if (string_to_sid(&sid
, "S--1-5-32-545")) {
7817 printf("allowing S--1-5-32-545\n");
7820 if (string_to_sid(&sid
, "S-1-5-32-+545")) {
7821 printf("allowing S-1-5-32-+545\n");
7824 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")) {
7825 printf("allowing S-1-2-3-4-5-6-7-8-9-0-1-2-3-4-5-6-7-8-9-0\n");
7828 if (string_to_sid(&sid
, "S-1-5-32-545-abc")) {
7829 printf("allowing S-1-5-32-545-abc\n");
7832 if (!string_to_sid(&sid
, "S-1-5-32-545")) {
7833 printf("could not parse S-1-5-32-545\n");
7836 if (!dom_sid_equal(&sid
, &global_sid_Builtin_Users
)) {
7837 printf("mis-parsed S-1-5-32-545 as %s\n",
7838 sid_string_tos(&sid
));
7844 static bool run_local_binary_to_sid(int dummy
) {
7845 struct dom_sid
*sid
= talloc(NULL
, struct dom_sid
);
7846 static const char good_binary_sid
[] = {
7847 0x1, /* revision number */
7849 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, /* id_auth */
7850 0x1, 0x1, 0x1, 0x1, /* auth[0] */
7851 0x1, 0x1, 0x1, 0x1, /* auth[1] */
7852 0x1, 0x1, 0x1, 0x1, /* auth[2] */
7853 0x1, 0x1, 0x1, 0x1, /* auth[3] */
7854 0x1, 0x1, 0x1, 0x1, /* auth[4] */
7855 0x1, 0x1, 0x1, 0x1, /* auth[5] */
7856 0x1, 0x1, 0x1, 0x1, /* auth[6] */
7857 0x1, 0x1, 0x1, 0x1, /* auth[7] */
7858 0x1, 0x1, 0x1, 0x1, /* auth[8] */
7859 0x1, 0x1, 0x1, 0x1, /* auth[9] */
7860 0x1, 0x1, 0x1, 0x1, /* auth[10] */
7861 0x1, 0x1, 0x1, 0x1, /* auth[11] */
7862 0x1, 0x1, 0x1, 0x1, /* auth[12] */
7863 0x1, 0x1, 0x1, 0x1, /* auth[13] */
7864 0x1, 0x1, 0x1, 0x1, /* auth[14] */
7867 static const char long_binary_sid
[] = {
7868 0x1, /* revision number */
7870 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, /* id_auth */
7871 0x1, 0x1, 0x1, 0x1, /* auth[0] */
7872 0x1, 0x1, 0x1, 0x1, /* auth[1] */
7873 0x1, 0x1, 0x1, 0x1, /* auth[2] */
7874 0x1, 0x1, 0x1, 0x1, /* auth[3] */
7875 0x1, 0x1, 0x1, 0x1, /* auth[4] */
7876 0x1, 0x1, 0x1, 0x1, /* auth[5] */
7877 0x1, 0x1, 0x1, 0x1, /* auth[6] */
7878 0x1, 0x1, 0x1, 0x1, /* auth[7] */
7879 0x1, 0x1, 0x1, 0x1, /* auth[8] */
7880 0x1, 0x1, 0x1, 0x1, /* auth[9] */
7881 0x1, 0x1, 0x1, 0x1, /* auth[10] */
7882 0x1, 0x1, 0x1, 0x1, /* auth[11] */
7883 0x1, 0x1, 0x1, 0x1, /* auth[12] */
7884 0x1, 0x1, 0x1, 0x1, /* auth[13] */
7885 0x1, 0x1, 0x1, 0x1, /* auth[14] */
7886 0x1, 0x1, 0x1, 0x1, /* auth[15] */
7887 0x1, 0x1, 0x1, 0x1, /* auth[16] */
7888 0x1, 0x1, 0x1, 0x1, /* auth[17] */
7891 static const char long_binary_sid2
[] = {
7892 0x1, /* revision number */
7894 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, /* id_auth */
7895 0x1, 0x1, 0x1, 0x1, /* auth[0] */
7896 0x1, 0x1, 0x1, 0x1, /* auth[1] */
7897 0x1, 0x1, 0x1, 0x1, /* auth[2] */
7898 0x1, 0x1, 0x1, 0x1, /* auth[3] */
7899 0x1, 0x1, 0x1, 0x1, /* auth[4] */
7900 0x1, 0x1, 0x1, 0x1, /* auth[5] */
7901 0x1, 0x1, 0x1, 0x1, /* auth[6] */
7902 0x1, 0x1, 0x1, 0x1, /* auth[7] */
7903 0x1, 0x1, 0x1, 0x1, /* auth[8] */
7904 0x1, 0x1, 0x1, 0x1, /* auth[9] */
7905 0x1, 0x1, 0x1, 0x1, /* auth[10] */
7906 0x1, 0x1, 0x1, 0x1, /* auth[11] */
7907 0x1, 0x1, 0x1, 0x1, /* auth[12] */
7908 0x1, 0x1, 0x1, 0x1, /* auth[13] */
7909 0x1, 0x1, 0x1, 0x1, /* auth[14] */
7910 0x1, 0x1, 0x1, 0x1, /* auth[15] */
7911 0x1, 0x1, 0x1, 0x1, /* auth[16] */
7912 0x1, 0x1, 0x1, 0x1, /* auth[17] */
7913 0x1, 0x1, 0x1, 0x1, /* auth[18] */
7914 0x1, 0x1, 0x1, 0x1, /* auth[19] */
7915 0x1, 0x1, 0x1, 0x1, /* auth[20] */
7916 0x1, 0x1, 0x1, 0x1, /* auth[21] */
7917 0x1, 0x1, 0x1, 0x1, /* auth[22] */
7918 0x1, 0x1, 0x1, 0x1, /* auth[23] */
7919 0x1, 0x1, 0x1, 0x1, /* auth[24] */
7920 0x1, 0x1, 0x1, 0x1, /* auth[25] */
7921 0x1, 0x1, 0x1, 0x1, /* auth[26] */
7922 0x1, 0x1, 0x1, 0x1, /* auth[27] */
7923 0x1, 0x1, 0x1, 0x1, /* auth[28] */
7924 0x1, 0x1, 0x1, 0x1, /* auth[29] */
7925 0x1, 0x1, 0x1, 0x1, /* auth[30] */
7926 0x1, 0x1, 0x1, 0x1, /* auth[31] */
7929 if (!sid_parse(good_binary_sid
, sizeof(good_binary_sid
), sid
)) {
7932 if (sid_parse(long_binary_sid2
, sizeof(long_binary_sid2
), sid
)) {
7935 if (sid_parse(long_binary_sid
, sizeof(long_binary_sid
), sid
)) {
7941 /* Split a path name into filename and stream name components. Canonicalise
7942 * such that an implicit $DATA token is always explicit.
7944 * The "specification" of this function can be found in the
7945 * run_local_stream_name() function in torture.c, I've tried those
7946 * combinations against a W2k3 server.
7949 static NTSTATUS
split_ntfs_stream_name(TALLOC_CTX
*mem_ctx
, const char *fname
,
7950 char **pbase
, char **pstream
)
7953 char *stream
= NULL
;
7954 char *sname
; /* stream name */
7955 const char *stype
; /* stream type */
7957 DEBUG(10, ("split_ntfs_stream_name called for [%s]\n", fname
));
7959 sname
= strchr_m(fname
, ':');
7961 if (lp_posix_pathnames() || (sname
== NULL
)) {
7962 if (pbase
!= NULL
) {
7963 base
= talloc_strdup(mem_ctx
, fname
);
7964 NT_STATUS_HAVE_NO_MEMORY(base
);
7969 if (pbase
!= NULL
) {
7970 base
= talloc_strndup(mem_ctx
, fname
, PTR_DIFF(sname
, fname
));
7971 NT_STATUS_HAVE_NO_MEMORY(base
);
7976 stype
= strchr_m(sname
, ':');
7978 if (stype
== NULL
) {
7979 sname
= talloc_strdup(mem_ctx
, sname
);
7983 if (strcasecmp_m(stype
, ":$DATA") != 0) {
7985 * If there is an explicit stream type, so far we only
7986 * allow $DATA. Is there anything else allowed? -- vl
7988 DEBUG(10, ("[%s] is an invalid stream type\n", stype
));
7990 return NT_STATUS_OBJECT_NAME_INVALID
;
7992 sname
= talloc_strndup(mem_ctx
, sname
, PTR_DIFF(stype
, sname
));
7996 if (sname
== NULL
) {
7998 return NT_STATUS_NO_MEMORY
;
8001 if (sname
[0] == '\0') {
8003 * no stream name, so no stream
8008 if (pstream
!= NULL
) {
8009 stream
= talloc_asprintf(mem_ctx
, "%s:%s", sname
, stype
);
8010 if (stream
== NULL
) {
8013 return NT_STATUS_NO_MEMORY
;
8016 * upper-case the type field
8018 strupper_m(strchr_m(stream
, ':')+1);
8022 if (pbase
!= NULL
) {
8025 if (pstream
!= NULL
) {
8028 return NT_STATUS_OK
;
8031 static bool test_stream_name(const char *fname
, const char *expected_base
,
8032 const char *expected_stream
,
8033 NTSTATUS expected_status
)
8037 char *stream
= NULL
;
8039 status
= split_ntfs_stream_name(talloc_tos(), fname
, &base
, &stream
);
8040 if (!NT_STATUS_EQUAL(status
, expected_status
)) {
8044 if (!NT_STATUS_IS_OK(status
)) {
8048 if (base
== NULL
) goto error
;
8050 if (strcmp(expected_base
, base
) != 0) goto error
;
8052 if ((expected_stream
!= NULL
) && (stream
== NULL
)) goto error
;
8053 if ((expected_stream
== NULL
) && (stream
!= NULL
)) goto error
;
8055 if ((stream
!= NULL
) && (strcmp(expected_stream
, stream
) != 0))
8059 TALLOC_FREE(stream
);
8063 d_fprintf(stderr
, "Do test_stream(%s, %s, %s, %s)\n",
8064 fname
, expected_base
? expected_base
: "<NULL>",
8065 expected_stream
? expected_stream
: "<NULL>",
8066 nt_errstr(expected_status
));
8067 d_fprintf(stderr
, "-> base=%s, stream=%s, status=%s\n",
8068 base
? base
: "<NULL>", stream
? stream
: "<NULL>",
8071 TALLOC_FREE(stream
);
8075 static bool run_local_stream_name(int dummy
)
8079 ret
&= test_stream_name(
8080 "bla", "bla", NULL
, NT_STATUS_OK
);
8081 ret
&= test_stream_name(
8082 "bla::$DATA", "bla", NULL
, NT_STATUS_OK
);
8083 ret
&= test_stream_name(
8084 "bla:blub:", "bla", NULL
, NT_STATUS_OBJECT_NAME_INVALID
);
8085 ret
&= test_stream_name(
8086 "bla::", NULL
, NULL
, NT_STATUS_OBJECT_NAME_INVALID
);
8087 ret
&= test_stream_name(
8088 "bla::123", "bla", NULL
, NT_STATUS_OBJECT_NAME_INVALID
);
8089 ret
&= test_stream_name(
8090 "bla:$DATA", "bla", "$DATA:$DATA", NT_STATUS_OK
);
8091 ret
&= test_stream_name(
8092 "bla:x:$DATA", "bla", "x:$DATA", NT_STATUS_OK
);
8093 ret
&= test_stream_name(
8094 "bla:x", "bla", "x:$DATA", NT_STATUS_OK
);
8099 static bool data_blob_equal(DATA_BLOB a
, DATA_BLOB b
)
8101 if (a
.length
!= b
.length
) {
8102 printf("a.length=%d != b.length=%d\n",
8103 (int)a
.length
, (int)b
.length
);
8106 if (memcmp(a
.data
, b
.data
, a
.length
) != 0) {
8107 printf("a.data and b.data differ\n");
8113 static bool run_local_memcache(int dummy
)
8115 struct memcache
*cache
;
8117 DATA_BLOB d1
, d2
, d3
;
8118 DATA_BLOB v1
, v2
, v3
;
8120 TALLOC_CTX
*mem_ctx
;
8122 size_t size1
, size2
;
8125 cache
= memcache_init(NULL
, 100);
8127 if (cache
== NULL
) {
8128 printf("memcache_init failed\n");
8132 d1
= data_blob_const("d1", 2);
8133 d2
= data_blob_const("d2", 2);
8134 d3
= data_blob_const("d3", 2);
8136 k1
= data_blob_const("d1", 2);
8137 k2
= data_blob_const("d2", 2);
8139 memcache_add(cache
, STAT_CACHE
, k1
, d1
);
8140 memcache_add(cache
, GETWD_CACHE
, k2
, d2
);
8142 if (!memcache_lookup(cache
, STAT_CACHE
, k1
, &v1
)) {
8143 printf("could not find k1\n");
8146 if (!data_blob_equal(d1
, v1
)) {
8150 if (!memcache_lookup(cache
, GETWD_CACHE
, k2
, &v2
)) {
8151 printf("could not find k2\n");
8154 if (!data_blob_equal(d2
, v2
)) {
8158 memcache_add(cache
, STAT_CACHE
, k1
, d3
);
8160 if (!memcache_lookup(cache
, STAT_CACHE
, k1
, &v3
)) {
8161 printf("could not find replaced k1\n");
8164 if (!data_blob_equal(d3
, v3
)) {
8168 memcache_add(cache
, GETWD_CACHE
, k1
, d1
);
8170 if (memcache_lookup(cache
, GETWD_CACHE
, k2
, &v2
)) {
8171 printf("Did find k2, should have been purged\n");
8177 cache
= memcache_init(NULL
, 0);
8179 mem_ctx
= talloc_init("foo");
8181 str1
= talloc_strdup(mem_ctx
, "string1");
8182 str2
= talloc_strdup(mem_ctx
, "string2");
8184 memcache_add_talloc(cache
, SINGLETON_CACHE_TALLOC
,
8185 data_blob_string_const("torture"), &str1
);
8186 size1
= talloc_total_size(cache
);
8188 memcache_add_talloc(cache
, SINGLETON_CACHE_TALLOC
,
8189 data_blob_string_const("torture"), &str2
);
8190 size2
= talloc_total_size(cache
);
8192 printf("size1=%d, size2=%d\n", (int)size1
, (int)size2
);
8194 if (size2
> size1
) {
8195 printf("memcache leaks memory!\n");
8205 static void wbclient_done(struct tevent_req
*req
)
8208 struct winbindd_response
*wb_resp
;
8209 int *i
= (int *)tevent_req_callback_data_void(req
);
8211 wbc_err
= wb_trans_recv(req
, req
, &wb_resp
);
8214 d_printf("wb_trans_recv %d returned %s\n", *i
, wbcErrorString(wbc_err
));
8217 static bool run_local_wbclient(int dummy
)
8219 struct event_context
*ev
;
8220 struct wb_context
**wb_ctx
;
8221 struct winbindd_request wb_req
;
8222 bool result
= false;
8225 BlockSignals(True
, SIGPIPE
);
8227 ev
= tevent_context_init_byname(talloc_tos(), "epoll");
8232 wb_ctx
= TALLOC_ARRAY(ev
, struct wb_context
*, nprocs
);
8233 if (wb_ctx
== NULL
) {
8237 ZERO_STRUCT(wb_req
);
8238 wb_req
.cmd
= WINBINDD_PING
;
8240 d_printf("nprocs=%d, numops=%d\n", (int)nprocs
, (int)torture_numops
);
8242 for (i
=0; i
<nprocs
; i
++) {
8243 wb_ctx
[i
] = wb_context_init(ev
, NULL
);
8244 if (wb_ctx
[i
] == NULL
) {
8247 for (j
=0; j
<torture_numops
; j
++) {
8248 struct tevent_req
*req
;
8249 req
= wb_trans_send(ev
, ev
, wb_ctx
[i
],
8250 (j
% 2) == 0, &wb_req
);
8254 tevent_req_set_callback(req
, wbclient_done
, &i
);
8260 while (i
< nprocs
* torture_numops
) {
8261 event_loop_once(ev
);
8270 static void getaddrinfo_finished(struct tevent_req
*req
)
8272 char *name
= (char *)tevent_req_callback_data_void(req
);
8273 struct addrinfo
*ainfo
;
8276 res
= getaddrinfo_recv(req
, &ainfo
);
8278 d_printf("gai(%s) returned %s\n", name
, gai_strerror(res
));
8281 d_printf("gai(%s) succeeded\n", name
);
8282 freeaddrinfo(ainfo
);
8285 static bool run_getaddrinfo_send(int dummy
)
8287 TALLOC_CTX
*frame
= talloc_stackframe();
8288 struct fncall_context
*ctx
;
8289 struct tevent_context
*ev
;
8290 bool result
= false;
8291 const char *names
[4] = { "www.samba.org", "notfound.samba.org",
8292 "www.slashdot.org", "heise.de" };
8293 struct tevent_req
*reqs
[4];
8296 ev
= event_context_init(frame
);
8301 ctx
= fncall_context_init(frame
, 4);
8303 for (i
=0; i
<ARRAY_SIZE(names
); i
++) {
8304 reqs
[i
] = getaddrinfo_send(frame
, ev
, ctx
, names
[i
], NULL
,
8306 if (reqs
[i
] == NULL
) {
8309 tevent_req_set_callback(reqs
[i
], getaddrinfo_finished
,
8310 discard_const_p(void, names
[i
]));
8313 for (i
=0; i
<ARRAY_SIZE(reqs
); i
++) {
8314 tevent_loop_once(ev
);
8323 static bool dbtrans_inc(struct db_context
*db
)
8325 struct db_record
*rec
;
8330 rec
= db
->fetch_locked(db
, db
, string_term_tdb_data("transtest"));
8332 printf(__location__
"fetch_lock failed\n");
8336 if (rec
->value
.dsize
!= sizeof(uint32_t)) {
8337 printf(__location__
"value.dsize = %d\n",
8338 (int)rec
->value
.dsize
);
8342 val
= (uint32_t *)rec
->value
.dptr
;
8345 status
= rec
->store(rec
, make_tdb_data((uint8_t *)val
,
8348 if (!NT_STATUS_IS_OK(status
)) {
8349 printf(__location__
"store failed: %s\n",
8360 static bool run_local_dbtrans(int dummy
)
8362 struct db_context
*db
;
8363 struct db_record
*rec
;
8368 db
= db_open(talloc_tos(), "transtest.tdb", 0, TDB_DEFAULT
,
8369 O_RDWR
|O_CREAT
, 0600);
8371 printf("Could not open transtest.db\n");
8375 res
= db
->transaction_start(db
);
8377 printf(__location__
"transaction_start failed\n");
8381 rec
= db
->fetch_locked(db
, db
, string_term_tdb_data("transtest"));
8383 printf(__location__
"fetch_lock failed\n");
8387 if (rec
->value
.dptr
== NULL
) {
8389 status
= rec
->store(
8390 rec
, make_tdb_data((uint8_t *)&initial
,
8393 if (!NT_STATUS_IS_OK(status
)) {
8394 printf(__location__
"store returned %s\n",
8402 res
= db
->transaction_commit(db
);
8404 printf(__location__
"transaction_commit failed\n");
8412 res
= db
->transaction_start(db
);
8414 printf(__location__
"transaction_start failed\n");
8418 if (!dbwrap_fetch_uint32(db
, "transtest", &val
)) {
8419 printf(__location__
"dbwrap_fetch_uint32 failed\n");
8423 for (i
=0; i
<10; i
++) {
8424 if (!dbtrans_inc(db
)) {
8429 if (!dbwrap_fetch_uint32(db
, "transtest", &val2
)) {
8430 printf(__location__
"dbwrap_fetch_uint32 failed\n");
8434 if (val2
!= val
+ 10) {
8435 printf(__location__
"val=%d, val2=%d\n",
8436 (int)val
, (int)val2
);
8440 printf("val2=%d\r", val2
);
8442 res
= db
->transaction_commit(db
);
8444 printf(__location__
"transaction_commit failed\n");
8454 * Just a dummy test to be run under a debugger. There's no real way
8455 * to inspect the tevent_select specific function from outside of
8459 static bool run_local_tevent_select(int dummy
)
8461 struct tevent_context
*ev
;
8462 struct tevent_fd
*fd1
, *fd2
;
8463 bool result
= false;
8465 ev
= tevent_context_init_byname(NULL
, "select");
8467 d_fprintf(stderr
, "tevent_context_init_byname failed\n");
8471 fd1
= tevent_add_fd(ev
, ev
, 2, 0, NULL
, NULL
);
8473 d_fprintf(stderr
, "tevent_add_fd failed\n");
8476 fd2
= tevent_add_fd(ev
, ev
, 3, 0, NULL
, NULL
);
8478 d_fprintf(stderr
, "tevent_add_fd failed\n");
8483 fd2
= tevent_add_fd(ev
, ev
, 1, 0, NULL
, NULL
);
8485 d_fprintf(stderr
, "tevent_add_fd failed\n");
8495 static double create_procs(bool (*fn
)(int), bool *result
)
8498 volatile pid_t
*child_status
;
8499 volatile bool *child_status_out
;
8502 struct timeval start
;
8506 child_status
= (volatile pid_t
*)shm_setup(sizeof(pid_t
)*nprocs
);
8507 if (!child_status
) {
8508 printf("Failed to setup shared memory\n");
8512 child_status_out
= (volatile bool *)shm_setup(sizeof(bool)*nprocs
);
8513 if (!child_status_out
) {
8514 printf("Failed to setup result status shared memory\n");
8518 for (i
= 0; i
< nprocs
; i
++) {
8519 child_status
[i
] = 0;
8520 child_status_out
[i
] = True
;
8523 start
= timeval_current();
8525 for (i
=0;i
<nprocs
;i
++) {
8528 pid_t mypid
= getpid();
8529 sys_srandom(((int)mypid
) ^ ((int)time(NULL
)));
8531 slprintf(myname
,sizeof(myname
),"CLIENT%d", i
);
8534 if (torture_open_connection(¤t_cli
, i
)) break;
8536 printf("pid %d failed to start\n", (int)getpid());
8542 child_status
[i
] = getpid();
8544 while (child_status
[i
] && timeval_elapsed(&start
) < 5) smb_msleep(2);
8546 child_status_out
[i
] = fn(i
);
8553 for (i
=0;i
<nprocs
;i
++) {
8554 if (child_status
[i
]) synccount
++;
8556 if (synccount
== nprocs
) break;
8558 } while (timeval_elapsed(&start
) < 30);
8560 if (synccount
!= nprocs
) {
8561 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs
, synccount
);
8563 return timeval_elapsed(&start
);
8566 /* start the client load */
8567 start
= timeval_current();
8569 for (i
=0;i
<nprocs
;i
++) {
8570 child_status
[i
] = 0;
8573 printf("%d clients started\n", nprocs
);
8575 for (i
=0;i
<nprocs
;i
++) {
8576 while (waitpid(0, &status
, 0) == -1 && errno
== EINTR
) /* noop */ ;
8581 for (i
=0;i
<nprocs
;i
++) {
8582 if (!child_status_out
[i
]) {
8586 return timeval_elapsed(&start
);
8589 #define FLAG_MULTIPROC 1
8596 {"FDPASS", run_fdpasstest
, 0},
8597 {"LOCK1", run_locktest1
, 0},
8598 {"LOCK2", run_locktest2
, 0},
8599 {"LOCK3", run_locktest3
, 0},
8600 {"LOCK4", run_locktest4
, 0},
8601 {"LOCK5", run_locktest5
, 0},
8602 {"LOCK6", run_locktest6
, 0},
8603 {"LOCK7", run_locktest7
, 0},
8604 {"LOCK8", run_locktest8
, 0},
8605 {"LOCK9", run_locktest9
, 0},
8606 {"UNLINK", run_unlinktest
, 0},
8607 {"BROWSE", run_browsetest
, 0},
8608 {"ATTR", run_attrtest
, 0},
8609 {"TRANS2", run_trans2test
, 0},
8610 {"MAXFID", run_maxfidtest
, FLAG_MULTIPROC
},
8611 {"TORTURE",run_torture
, FLAG_MULTIPROC
},
8612 {"RANDOMIPC", run_randomipc
, 0},
8613 {"NEGNOWAIT", run_negprot_nowait
, 0},
8614 {"NBENCH", run_nbench
, 0},
8615 {"NBENCH2", run_nbench2
, 0},
8616 {"OPLOCK1", run_oplock1
, 0},
8617 {"OPLOCK2", run_oplock2
, 0},
8618 {"OPLOCK3", run_oplock3
, 0},
8619 {"OPLOCK4", run_oplock4
, 0},
8620 {"DIR", run_dirtest
, 0},
8621 {"DIR1", run_dirtest1
, 0},
8622 {"DIR-CREATETIME", run_dir_createtime
, 0},
8623 {"DENY1", torture_denytest1
, 0},
8624 {"DENY2", torture_denytest2
, 0},
8625 {"TCON", run_tcon_test
, 0},
8626 {"TCONDEV", run_tcon_devtype_test
, 0},
8627 {"RW1", run_readwritetest
, 0},
8628 {"RW2", run_readwritemulti
, FLAG_MULTIPROC
},
8629 {"RW3", run_readwritelarge
, 0},
8630 {"RW-SIGNING", run_readwritelarge_signtest
, 0},
8631 {"OPEN", run_opentest
, 0},
8632 {"POSIX", run_simple_posix_open_test
, 0},
8633 {"POSIX-APPEND", run_posix_append
, 0},
8634 {"CASE-INSENSITIVE-CREATE", run_case_insensitive_create
, 0},
8635 {"ASYNC-ECHO", run_async_echo
, 0},
8636 { "UID-REGRESSION-TEST", run_uid_regression_test
, 0},
8637 { "SHORTNAME-TEST", run_shortname_test
, 0},
8638 { "ADDRCHANGE", run_addrchange
, 0},
8640 {"OPENATTR", run_openattrtest
, 0},
8642 {"XCOPY", run_xcopy
, 0},
8643 {"RENAME", run_rename
, 0},
8644 {"DELETE", run_deletetest
, 0},
8645 {"DELETE-LN", run_deletetest_ln
, 0},
8646 {"PROPERTIES", run_properties
, 0},
8647 {"MANGLE", torture_mangle
, 0},
8648 {"MANGLE1", run_mangle1
, 0},
8649 {"W2K", run_w2ktest
, 0},
8650 {"TRANS2SCAN", torture_trans2_scan
, 0},
8651 {"NTTRANSSCAN", torture_nttrans_scan
, 0},
8652 {"UTABLE", torture_utable
, 0},
8653 {"CASETABLE", torture_casetable
, 0},
8654 {"ERRMAPEXTRACT", run_error_map_extract
, 0},
8655 {"PIPE_NUMBER", run_pipe_number
, 0},
8656 {"TCON2", run_tcon2_test
, 0},
8657 {"IOCTL", torture_ioctl_test
, 0},
8658 {"CHKPATH", torture_chkpath_test
, 0},
8659 {"FDSESS", run_fdsesstest
, 0},
8660 { "EATEST", run_eatest
, 0},
8661 { "SESSSETUP_BENCH", run_sesssetup_bench
, 0},
8662 { "CHAIN1", run_chain1
, 0},
8663 { "CHAIN2", run_chain2
, 0},
8664 { "WINDOWS-WRITE", run_windows_write
, 0},
8665 { "CLI_ECHO", run_cli_echo
, 0},
8666 { "GETADDRINFO", run_getaddrinfo_send
, 0},
8667 { "TLDAP", run_tldap
},
8668 { "STREAMERROR", run_streamerror
},
8669 { "NOTIFY-BENCH", run_notify_bench
},
8670 { "BAD-NBT-SESSION", run_bad_nbt_session
},
8671 { "SMB-ANY-CONNECT", run_smb_any_connect
},
8672 { "NOTIFY-ONLINE", run_notify_online
},
8673 { "LOCAL-SUBSTITUTE", run_local_substitute
, 0},
8674 { "LOCAL-GENCACHE", run_local_gencache
, 0},
8675 { "LOCAL-TALLOC-DICT", run_local_talloc_dict
, 0},
8676 { "LOCAL-BASE64", run_local_base64
, 0},
8677 { "LOCAL-RBTREE", run_local_rbtree
, 0},
8678 { "LOCAL-MEMCACHE", run_local_memcache
, 0},
8679 { "LOCAL-STREAM-NAME", run_local_stream_name
, 0},
8680 { "LOCAL-WBCLIENT", run_local_wbclient
, 0},
8681 { "LOCAL-string_to_sid", run_local_string_to_sid
, 0},
8682 { "LOCAL-binary_to_sid", run_local_binary_to_sid
, 0},
8683 { "LOCAL-DBTRANS", run_local_dbtrans
, 0},
8684 { "LOCAL-TEVENT-SELECT", run_local_tevent_select
, 0},
8685 { "LOCAL-CONVERT-STRING", run_local_convert_string
, 0},
8690 /****************************************************************************
8691 run a specified test or "ALL"
8692 ****************************************************************************/
8693 static bool run_test(const char *name
)
8700 if (strequal(name
,"ALL")) {
8701 for (i
=0;torture_ops
[i
].name
;i
++) {
8702 run_test(torture_ops
[i
].name
);
8707 for (i
=0;torture_ops
[i
].name
;i
++) {
8708 fstr_sprintf(randomfname
, "\\XX%x",
8709 (unsigned)random());
8711 if (strequal(name
, torture_ops
[i
].name
)) {
8713 printf("Running %s\n", name
);
8714 if (torture_ops
[i
].flags
& FLAG_MULTIPROC
) {
8715 t
= create_procs(torture_ops
[i
].fn
, &result
);
8718 printf("TEST %s FAILED!\n", name
);
8721 struct timeval start
;
8722 start
= timeval_current();
8723 if (!torture_ops
[i
].fn(0)) {
8725 printf("TEST %s FAILED!\n", name
);
8727 t
= timeval_elapsed(&start
);
8729 printf("%s took %g secs\n\n", name
, t
);
8734 printf("Did not find a test named %s\n", name
);
8742 static void usage(void)
8746 printf("WARNING samba4 test suite is much more complete nowadays.\n");
8747 printf("Please use samba4 torture.\n\n");
8749 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
8751 printf("\t-d debuglevel\n");
8752 printf("\t-U user%%pass\n");
8753 printf("\t-k use kerberos\n");
8754 printf("\t-N numprocs\n");
8755 printf("\t-n my_netbios_name\n");
8756 printf("\t-W workgroup\n");
8757 printf("\t-o num_operations\n");
8758 printf("\t-O socket_options\n");
8759 printf("\t-m maximum protocol\n");
8760 printf("\t-L use oplocks\n");
8761 printf("\t-c CLIENT.TXT specify client load file for NBENCH\n");
8762 printf("\t-A showall\n");
8763 printf("\t-p port\n");
8764 printf("\t-s seed\n");
8765 printf("\t-b unclist_filename specify multiple shares for multiple connections\n");
8766 printf("\t-f filename filename to test\n");
8769 printf("tests are:");
8770 for (i
=0;torture_ops
[i
].name
;i
++) {
8771 printf(" %s", torture_ops
[i
].name
);
8775 printf("default test is ALL\n");
8780 /****************************************************************************
8782 ****************************************************************************/
8783 int main(int argc
,char *argv
[])
8789 bool correct
= True
;
8790 TALLOC_CTX
*frame
= talloc_stackframe();
8791 int seed
= time(NULL
);
8793 #ifdef HAVE_SETBUFFER
8794 setbuffer(stdout
, NULL
, 0);
8797 setup_logging("smbtorture", DEBUG_STDOUT
);
8801 if (is_default_dyn_CONFIGFILE()) {
8802 if(getenv("SMB_CONF_PATH")) {
8803 set_dyn_CONFIGFILE(getenv("SMB_CONF_PATH"));
8806 lp_load(get_dyn_CONFIGFILE(),True
,False
,False
,True
);
8813 for(p
= argv
[1]; *p
; p
++)
8817 if (strncmp(argv
[1], "//", 2)) {
8821 fstrcpy(host
, &argv
[1][2]);
8822 p
= strchr_m(&host
[2],'/');
8827 fstrcpy(share
, p
+1);
8829 fstrcpy(myname
, get_myname(talloc_tos()));
8831 fprintf(stderr
, "Failed to get my hostname.\n");
8835 if (*username
== 0 && getenv("LOGNAME")) {
8836 fstrcpy(username
,getenv("LOGNAME"));
8842 fstrcpy(workgroup
, lp_workgroup());
8844 while ((opt
= getopt(argc
, argv
, "p:hW:U:n:N:O:o:m:Ll:d:Aec:ks:b:B:f:"))
8848 port_to_use
= atoi(optarg
);
8851 seed
= atoi(optarg
);
8854 fstrcpy(workgroup
,optarg
);
8857 max_protocol
= interpret_protocol(optarg
, max_protocol
);
8860 nprocs
= atoi(optarg
);
8863 torture_numops
= atoi(optarg
);
8866 lp_set_cmdline("log level", optarg
);
8875 local_path
= optarg
;
8878 torture_showall
= True
;
8881 fstrcpy(myname
, optarg
);
8884 client_txt
= optarg
;
8891 use_kerberos
= True
;
8893 d_printf("No kerberos support compiled in\n");
8899 fstrcpy(username
,optarg
);
8900 p
= strchr_m(username
,'%');
8903 fstrcpy(password
, p
+1);
8908 fstrcpy(multishare_conn_fname
, optarg
);
8909 use_multishare_conn
= True
;
8912 torture_blocksize
= atoi(optarg
);
8915 test_filename
= SMB_STRDUP(optarg
);
8918 printf("Unknown option %c (%d)\n", (char)opt
, opt
);
8923 d_printf("using seed %d\n", seed
);
8927 if(use_kerberos
&& !gotuser
) gotpass
= True
;
8930 p
= getpass("Password:");
8932 fstrcpy(password
, p
);
8937 printf("host=%s share=%s user=%s myname=%s\n",
8938 host
, share
, username
, myname
);
8940 if (argc
== optind
) {
8941 correct
= run_test("ALL");
8943 for (i
=optind
;i
<argc
;i
++) {
8944 if (!run_test(argv
[i
])) {