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 "nsswitch/libwbclient/wbc_async.h"
23 #include "torture/proto.h"
24 #include "libcli/security/dom_sid.h"
26 #include "tldap_util.h"
31 static fstring host
, workgroup
, share
, password
, username
, myname
;
32 static int max_protocol
= PROTOCOL_NT1
;
33 static const char *sockops
="TCP_NODELAY";
35 static int port_to_use
=0;
36 int torture_numops
=100;
37 int torture_blocksize
=1024*1024;
38 static int procnum
; /* records process count number when forking */
39 static struct cli_state
*current_cli
;
40 static fstring randomfname
;
41 static bool use_oplocks
;
42 static bool use_level_II_oplocks
;
43 static const char *client_txt
= "client_oplocks.txt";
44 static bool use_kerberos
;
45 static fstring multishare_conn_fname
;
46 static bool use_multishare_conn
= False
;
47 static bool do_encrypt
;
48 static const char *local_path
= NULL
;
50 bool torture_showall
= False
;
52 static double create_procs(bool (*fn
)(int), bool *result
);
55 /* return a pointer to a anonymous shared memory segment of size "size"
56 which will persist across fork() but will disappear when all processes
59 The memory is not zeroed
61 This function uses system5 shared memory. It takes advantage of a property
62 that the memory is not destroyed if it is attached when the id is removed
64 void *shm_setup(int size
)
70 shmid
= shm_open("private", O_RDWR
| O_CREAT
| O_EXCL
, S_IRUSR
| S_IWUSR
);
72 printf("can't get shared memory\n");
75 shm_unlink("private");
76 if (ftruncate(shmid
, size
) == -1) {
77 printf("can't set shared memory size\n");
80 ret
= mmap(0, size
, PROT_READ
| PROT_WRITE
, MAP_SHARED
, shmid
, 0);
81 if (ret
== MAP_FAILED
) {
82 printf("can't map shared memory\n");
86 shmid
= shmget(IPC_PRIVATE
, size
, S_IRUSR
| S_IWUSR
);
88 printf("can't get shared memory\n");
91 ret
= (void *)shmat(shmid
, 0, 0);
92 if (!ret
|| ret
== (void *)-1) {
93 printf("can't attach to shared memory\n");
96 /* the following releases the ipc, but note that this process
97 and all its children will still have access to the memory, its
98 just that the shmid is no longer valid for other shm calls. This
99 means we don't leave behind lots of shm segments after we exit
101 See Stevens "advanced programming in unix env" for details
103 shmctl(shmid
, IPC_RMID
, 0);
109 /********************************************************************
110 Ensure a connection is encrypted.
111 ********************************************************************/
113 static bool force_cli_encryption(struct cli_state
*c
,
114 const char *sharename
)
117 uint32 caplow
, caphigh
;
120 if (!SERVER_HAS_UNIX_CIFS(c
)) {
121 d_printf("Encryption required and "
122 "server that doesn't support "
123 "UNIX extensions - failing connect\n");
127 status
= cli_unix_extensions_version(c
, &major
, &minor
, &caplow
,
129 if (!NT_STATUS_IS_OK(status
)) {
130 d_printf("Encryption required and "
131 "can't get UNIX CIFS extensions "
132 "version from server: %s\n", nt_errstr(status
));
136 if (!(caplow
& CIFS_UNIX_TRANSPORT_ENCRYPTION_CAP
)) {
137 d_printf("Encryption required and "
138 "share %s doesn't support "
139 "encryption.\n", sharename
);
143 if (c
->use_kerberos
) {
144 status
= cli_gss_smb_encryption_start(c
);
146 status
= cli_raw_ntlm_smb_encryption_start(c
,
152 if (!NT_STATUS_IS_OK(status
)) {
153 d_printf("Encryption required and "
154 "setup failed with error %s.\n",
163 static struct cli_state
*open_nbt_connection(void)
165 struct nmb_name called
, calling
;
166 struct sockaddr_storage ss
;
170 make_nmb_name(&calling
, myname
, 0x0);
171 make_nmb_name(&called
, host
, 0x20);
175 if (!(c
= cli_initialise())) {
176 printf("Failed initialize cli_struct to connect with %s\n", host
);
180 c
->port
= port_to_use
;
182 status
= cli_connect(c
, host
, &ss
);
183 if (!NT_STATUS_IS_OK(status
)) {
184 printf("Failed to connect with %s. Error %s\n", host
, nt_errstr(status
) );
188 c
->use_kerberos
= use_kerberos
;
190 c
->timeout
= 120000; /* set a really long timeout (2 minutes) */
191 if (use_oplocks
) c
->use_oplocks
= True
;
192 if (use_level_II_oplocks
) c
->use_level_II_oplocks
= True
;
194 if (!cli_session_request(c
, &calling
, &called
)) {
196 * Well, that failed, try *SMBSERVER ...
197 * However, we must reconnect as well ...
199 status
= cli_connect(c
, host
, &ss
);
200 if (!NT_STATUS_IS_OK(status
)) {
201 printf("Failed to connect with %s. Error %s\n", host
, nt_errstr(status
) );
205 make_nmb_name(&called
, "*SMBSERVER", 0x20);
206 if (!cli_session_request(c
, &calling
, &called
)) {
207 printf("%s rejected the session\n",host
);
208 printf("We tried with a called name of %s & %s\n",
218 /* Insert a NULL at the first separator of the given path and return a pointer
219 * to the remainder of the string.
222 terminate_path_at_separator(char * path
)
230 if ((p
= strchr_m(path
, '/'))) {
235 if ((p
= strchr_m(path
, '\\'))) {
245 parse a //server/share type UNC name
247 bool smbcli_parse_unc(const char *unc_name
, TALLOC_CTX
*mem_ctx
,
248 char **hostname
, char **sharename
)
252 *hostname
= *sharename
= NULL
;
254 if (strncmp(unc_name
, "\\\\", 2) &&
255 strncmp(unc_name
, "//", 2)) {
259 *hostname
= talloc_strdup(mem_ctx
, &unc_name
[2]);
260 p
= terminate_path_at_separator(*hostname
);
263 *sharename
= talloc_strdup(mem_ctx
, p
);
264 terminate_path_at_separator(*sharename
);
267 if (*hostname
&& *sharename
) {
271 TALLOC_FREE(*hostname
);
272 TALLOC_FREE(*sharename
);
276 static bool torture_open_connection_share(struct cli_state
**c
,
277 const char *hostname
,
278 const char *sharename
)
285 flags
|= CLI_FULL_CONNECTION_USE_KERBEROS
;
287 flags
|= CLI_FULL_CONNECTION_OPLOCKS
;
288 if (use_level_II_oplocks
)
289 flags
|= CLI_FULL_CONNECTION_LEVEL_II_OPLOCKS
;
291 status
= cli_full_connection(c
, myname
,
292 hostname
, NULL
, port_to_use
,
295 password
, flags
, Undefined
, &retry
);
296 if (!NT_STATUS_IS_OK(status
)) {
297 printf("failed to open share connection: //%s/%s port:%d - %s\n",
298 hostname
, sharename
, port_to_use
, nt_errstr(status
));
302 (*c
)->timeout
= 120000; /* set a really long timeout (2 minutes) */
305 return force_cli_encryption(*c
,
311 bool torture_open_connection(struct cli_state
**c
, int conn_index
)
313 char **unc_list
= NULL
;
314 int num_unc_names
= 0;
317 if (use_multishare_conn
==True
) {
319 unc_list
= file_lines_load(multishare_conn_fname
, &num_unc_names
, 0, NULL
);
320 if (!unc_list
|| num_unc_names
<= 0) {
321 printf("Failed to load unc names list from '%s'\n", multishare_conn_fname
);
325 if (!smbcli_parse_unc(unc_list
[conn_index
% num_unc_names
],
327 printf("Failed to parse UNC name %s\n",
328 unc_list
[conn_index
% num_unc_names
]);
329 TALLOC_FREE(unc_list
);
333 result
= torture_open_connection_share(c
, h
, s
);
335 /* h, s were copied earlier */
336 TALLOC_FREE(unc_list
);
340 return torture_open_connection_share(c
, host
, share
);
343 bool torture_cli_session_setup2(struct cli_state
*cli
, uint16
*new_vuid
)
345 uint16 old_vuid
= cli
->vuid
;
346 fstring old_user_name
;
347 size_t passlen
= strlen(password
);
351 fstrcpy(old_user_name
, cli
->user_name
);
353 ret
= NT_STATUS_IS_OK(cli_session_setup(cli
, username
,
357 *new_vuid
= cli
->vuid
;
358 cli
->vuid
= old_vuid
;
359 status
= cli_set_username(cli
, old_user_name
);
360 if (!NT_STATUS_IS_OK(status
)) {
367 bool torture_close_connection(struct cli_state
*c
)
372 status
= cli_tdis(c
);
373 if (!NT_STATUS_IS_OK(status
)) {
374 printf("tdis failed (%s)\n", nt_errstr(status
));
384 /* check if the server produced the expected error code */
385 static bool check_error(int line
, struct cli_state
*c
,
386 uint8 eclass
, uint32 ecode
, NTSTATUS nterr
)
388 if (cli_is_dos_error(c
)) {
392 /* Check DOS error */
394 cli_dos_error(c
, &cclass
, &num
);
396 if (eclass
!= cclass
|| ecode
!= num
) {
397 printf("unexpected error code class=%d code=%d\n",
398 (int)cclass
, (int)num
);
399 printf(" expected %d/%d %s (line=%d)\n",
400 (int)eclass
, (int)ecode
, nt_errstr(nterr
), line
);
409 status
= cli_nt_error(c
);
411 if (NT_STATUS_V(nterr
) != NT_STATUS_V(status
)) {
412 printf("unexpected error code %s\n", nt_errstr(status
));
413 printf(" expected %s (line=%d)\n", nt_errstr(nterr
), line
);
422 static bool wait_lock(struct cli_state
*c
, int fnum
, uint32 offset
, uint32 len
)
424 while (!cli_lock(c
, fnum
, offset
, len
, -1, WRITE_LOCK
)) {
425 if (!check_error(__LINE__
, c
, ERRDOS
, ERRlock
, NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
431 static bool rw_torture(struct cli_state
*c
)
433 const char *lockfname
= "\\torture.lck";
437 pid_t pid2
, pid
= getpid();
443 memset(buf
, '\0', sizeof(buf
));
445 status
= cli_open(c
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
,
447 if (!NT_STATUS_IS_OK(status
)) {
448 status
= cli_open(c
, lockfname
, O_RDWR
, DENY_NONE
, &fnum2
);
450 if (!NT_STATUS_IS_OK(status
)) {
451 printf("open of %s failed (%s)\n", lockfname
, cli_errstr(c
));
455 for (i
=0;i
<torture_numops
;i
++) {
456 unsigned n
= (unsigned)sys_random()%10;
458 printf("%d\r", i
); fflush(stdout
);
460 slprintf(fname
, sizeof(fstring
) - 1, "\\torture.%u", n
);
462 if (!wait_lock(c
, fnum2
, n
*sizeof(int), sizeof(int))) {
466 if (!NT_STATUS_IS_OK(cli_open(c
, fname
, O_RDWR
| O_CREAT
| O_TRUNC
, DENY_ALL
, &fnum
))) {
467 printf("open failed (%s)\n", cli_errstr(c
));
472 if (cli_write(c
, fnum
, 0, (char *)&pid
, 0, sizeof(pid
)) != sizeof(pid
)) {
473 printf("write failed (%s)\n", cli_errstr(c
));
478 if (cli_write(c
, fnum
, 0, (char *)buf
,
479 sizeof(pid
)+(j
*sizeof(buf
)),
480 sizeof(buf
)) != sizeof(buf
)) {
481 printf("write failed (%s)\n", cli_errstr(c
));
488 if (cli_read(c
, fnum
, (char *)&pid2
, 0, sizeof(pid
)) != sizeof(pid
)) {
489 printf("read failed (%s)\n", cli_errstr(c
));
494 printf("data corruption!\n");
498 if (!NT_STATUS_IS_OK(cli_close(c
, fnum
))) {
499 printf("close failed (%s)\n", cli_errstr(c
));
503 if (!NT_STATUS_IS_OK(cli_unlink(c
, fname
, aSYSTEM
| aHIDDEN
))) {
504 printf("unlink failed (%s)\n", cli_errstr(c
));
508 if (!NT_STATUS_IS_OK(cli_unlock(c
, fnum2
, n
*sizeof(int), sizeof(int)))) {
509 printf("unlock failed (%s)\n", cli_errstr(c
));
515 cli_unlink(c
, lockfname
, aSYSTEM
| aHIDDEN
);
522 static bool run_torture(int dummy
)
524 struct cli_state
*cli
;
529 cli_sockopt(cli
, sockops
);
531 ret
= rw_torture(cli
);
533 if (!torture_close_connection(cli
)) {
540 static bool rw_torture3(struct cli_state
*c
, char *lockfname
)
542 uint16_t fnum
= (uint16_t)-1;
547 unsigned countprev
= 0;
553 for (i
= 0; i
< sizeof(buf
); i
+= sizeof(uint32
))
555 SIVAL(buf
, i
, sys_random());
560 if (!NT_STATUS_IS_OK(cli_open(c
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
,
561 DENY_NONE
, &fnum
))) {
562 printf("first open read/write of %s failed (%s)\n",
563 lockfname
, cli_errstr(c
));
569 for (i
= 0; i
< 500 && fnum
== (uint16_t)-1; i
++)
571 status
= cli_open(c
, lockfname
, O_RDONLY
,
573 if (!NT_STATUS_IS_OK(status
)) {
578 if (!NT_STATUS_IS_OK(status
)) {
579 printf("second open read-only of %s failed (%s)\n",
580 lockfname
, cli_errstr(c
));
586 for (count
= 0; count
< sizeof(buf
); count
+= sent
)
588 if (count
>= countprev
) {
589 printf("%d %8d\r", i
, count
);
592 countprev
+= (sizeof(buf
) / 20);
597 sent
= ((unsigned)sys_random()%(20))+ 1;
598 if (sent
> sizeof(buf
) - count
)
600 sent
= sizeof(buf
) - count
;
603 if (cli_write(c
, fnum
, 0, buf
+count
, count
, (size_t)sent
) != sent
) {
604 printf("write failed (%s)\n", cli_errstr(c
));
610 sent
= cli_read(c
, fnum
, buf_rd
+count
, count
,
614 printf("read failed offset:%d size:%ld (%s)\n",
615 count
, (unsigned long)sizeof(buf
)-count
,
622 if (memcmp(buf_rd
+count
, buf
+count
, sent
) != 0)
624 printf("read/write compare failed\n");
625 printf("offset: %d req %ld recvd %ld\n", count
, (unsigned long)sizeof(buf
)-count
, (unsigned long)sent
);
634 if (!NT_STATUS_IS_OK(cli_close(c
, fnum
))) {
635 printf("close failed (%s)\n", cli_errstr(c
));
642 static bool rw_torture2(struct cli_state
*c1
, struct cli_state
*c2
)
644 const char *lockfname
= "\\torture2.lck";
653 if (!NT_STATUS_IS_OK(cli_unlink(c1
, lockfname
, aSYSTEM
| aHIDDEN
))) {
654 printf("unlink failed (%s) (normal, this file should not exist)\n", cli_errstr(c1
));
657 if (!NT_STATUS_IS_OK(cli_open(c1
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
,
658 DENY_NONE
, &fnum1
))) {
659 printf("first open read/write of %s failed (%s)\n",
660 lockfname
, cli_errstr(c1
));
663 if (!NT_STATUS_IS_OK(cli_open(c2
, lockfname
, O_RDONLY
,
664 DENY_NONE
, &fnum2
))) {
665 printf("second open read-only of %s failed (%s)\n",
666 lockfname
, cli_errstr(c2
));
667 cli_close(c1
, fnum1
);
671 for (i
=0;i
<torture_numops
;i
++)
673 size_t buf_size
= ((unsigned)sys_random()%(sizeof(buf
)-1))+ 1;
675 printf("%d\r", i
); fflush(stdout
);
678 generate_random_buffer((unsigned char *)buf
, buf_size
);
680 if (cli_write(c1
, fnum1
, 0, buf
, 0, buf_size
) != buf_size
) {
681 printf("write failed (%s)\n", cli_errstr(c1
));
686 if ((bytes_read
= cli_read(c2
, fnum2
, buf_rd
, 0, buf_size
)) != buf_size
) {
687 printf("read failed (%s)\n", cli_errstr(c2
));
688 printf("read %d, expected %ld\n", (int)bytes_read
,
689 (unsigned long)buf_size
);
694 if (memcmp(buf_rd
, buf
, buf_size
) != 0)
696 printf("read/write compare failed\n");
702 if (!NT_STATUS_IS_OK(cli_close(c2
, fnum2
))) {
703 printf("close failed (%s)\n", cli_errstr(c2
));
706 if (!NT_STATUS_IS_OK(cli_close(c1
, fnum1
))) {
707 printf("close failed (%s)\n", cli_errstr(c1
));
711 if (!NT_STATUS_IS_OK(cli_unlink(c1
, lockfname
, aSYSTEM
| aHIDDEN
))) {
712 printf("unlink failed (%s)\n", cli_errstr(c1
));
719 static bool run_readwritetest(int dummy
)
721 struct cli_state
*cli1
, *cli2
;
722 bool test1
, test2
= False
;
724 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
727 cli_sockopt(cli1
, sockops
);
728 cli_sockopt(cli2
, sockops
);
730 printf("starting readwritetest\n");
732 test1
= rw_torture2(cli1
, cli2
);
733 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1
));
736 test2
= rw_torture2(cli1
, cli1
);
737 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2
));
740 if (!torture_close_connection(cli1
)) {
744 if (!torture_close_connection(cli2
)) {
748 return (test1
&& test2
);
751 static bool run_readwritemulti(int dummy
)
753 struct cli_state
*cli
;
758 cli_sockopt(cli
, sockops
);
760 printf("run_readwritemulti: fname %s\n", randomfname
);
761 test
= rw_torture3(cli
, randomfname
);
763 if (!torture_close_connection(cli
)) {
770 static bool run_readwritelarge(int dummy
)
772 static struct cli_state
*cli1
;
774 const char *lockfname
= "\\large.dat";
779 if (!torture_open_connection(&cli1
, 0)) {
782 cli_sockopt(cli1
, sockops
);
783 memset(buf
,'\0',sizeof(buf
));
785 cli1
->max_xmit
= 128*1024;
787 printf("starting readwritelarge\n");
789 cli_unlink(cli1
, lockfname
, aSYSTEM
| aHIDDEN
);
791 if (!NT_STATUS_IS_OK(cli_open(cli1
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
, DENY_NONE
, &fnum1
))) {
792 printf("open read/write of %s failed (%s)\n", lockfname
, cli_errstr(cli1
));
796 cli_write(cli1
, fnum1
, 0, buf
, 0, sizeof(buf
));
798 if (!cli_qfileinfo(cli1
, fnum1
, NULL
, &fsize
, NULL
, NULL
, NULL
, NULL
, NULL
)) {
799 printf("qfileinfo failed (%s)\n", cli_errstr(cli1
));
803 if (fsize
== sizeof(buf
))
804 printf("readwritelarge test 1 succeeded (size = %lx)\n",
805 (unsigned long)fsize
);
807 printf("readwritelarge test 1 failed (size = %lx)\n",
808 (unsigned long)fsize
);
812 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
813 printf("close failed (%s)\n", cli_errstr(cli1
));
817 if (!NT_STATUS_IS_OK(cli_unlink(cli1
, lockfname
, aSYSTEM
| aHIDDEN
))) {
818 printf("unlink failed (%s)\n", cli_errstr(cli1
));
822 if (!NT_STATUS_IS_OK(cli_open(cli1
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
, DENY_NONE
, &fnum1
))) {
823 printf("open read/write of %s failed (%s)\n", lockfname
, cli_errstr(cli1
));
827 cli1
->max_xmit
= 4*1024;
829 cli_smbwrite(cli1
, fnum1
, buf
, 0, sizeof(buf
));
831 if (!cli_qfileinfo(cli1
, fnum1
, NULL
, &fsize
, NULL
, NULL
, NULL
, NULL
, NULL
)) {
832 printf("qfileinfo failed (%s)\n", cli_errstr(cli1
));
836 if (fsize
== sizeof(buf
))
837 printf("readwritelarge test 2 succeeded (size = %lx)\n",
838 (unsigned long)fsize
);
840 printf("readwritelarge test 2 failed (size = %lx)\n",
841 (unsigned long)fsize
);
846 /* ToDo - set allocation. JRA */
847 if(!cli_set_allocation_size(cli1
, fnum1
, 0)) {
848 printf("set allocation size to zero failed (%s)\n", cli_errstr(&cli1
));
851 if (!cli_qfileinfo(cli1
, fnum1
, NULL
, &fsize
, NULL
, NULL
, NULL
, NULL
, NULL
)) {
852 printf("qfileinfo failed (%s)\n", cli_errstr(cli1
));
856 printf("readwritelarge test 3 (truncate test) succeeded (size = %x)\n", fsize
);
859 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
860 printf("close failed (%s)\n", cli_errstr(cli1
));
864 if (!torture_close_connection(cli1
)) {
873 #define ival(s) strtol(s, NULL, 0)
875 /* run a test that simulates an approximate netbench client load */
876 static bool run_netbench(int client
)
878 struct cli_state
*cli
;
883 const char *params
[20];
890 cli_sockopt(cli
, sockops
);
894 slprintf(cname
,sizeof(cname
)-1, "client%d", client
);
896 f
= fopen(client_txt
, "r");
903 while (fgets(line
, sizeof(line
)-1, f
)) {
907 line
[strlen(line
)-1] = 0;
909 /* printf("[%d] %s\n", line_count, line); */
911 all_string_sub(line
,"client1", cname
, sizeof(line
));
913 /* parse the command parameters */
914 params
[0] = strtok_r(line
, " ", &saveptr
);
916 while (params
[i
]) params
[++i
] = strtok_r(NULL
, " ", &saveptr
);
922 if (!strncmp(params
[0],"SMB", 3)) {
923 printf("ERROR: You are using a dbench 1 load file\n");
927 if (!strcmp(params
[0],"NTCreateX")) {
928 nb_createx(params
[1], ival(params
[2]), ival(params
[3]),
930 } else if (!strcmp(params
[0],"Close")) {
931 nb_close(ival(params
[1]));
932 } else if (!strcmp(params
[0],"Rename")) {
933 nb_rename(params
[1], params
[2]);
934 } else if (!strcmp(params
[0],"Unlink")) {
935 nb_unlink(params
[1]);
936 } else if (!strcmp(params
[0],"Deltree")) {
937 nb_deltree(params
[1]);
938 } else if (!strcmp(params
[0],"Rmdir")) {
940 } else if (!strcmp(params
[0],"QUERY_PATH_INFORMATION")) {
941 nb_qpathinfo(params
[1]);
942 } else if (!strcmp(params
[0],"QUERY_FILE_INFORMATION")) {
943 nb_qfileinfo(ival(params
[1]));
944 } else if (!strcmp(params
[0],"QUERY_FS_INFORMATION")) {
945 nb_qfsinfo(ival(params
[1]));
946 } else if (!strcmp(params
[0],"FIND_FIRST")) {
947 nb_findfirst(params
[1]);
948 } else if (!strcmp(params
[0],"WriteX")) {
949 nb_writex(ival(params
[1]),
950 ival(params
[2]), ival(params
[3]), ival(params
[4]));
951 } else if (!strcmp(params
[0],"ReadX")) {
952 nb_readx(ival(params
[1]),
953 ival(params
[2]), ival(params
[3]), ival(params
[4]));
954 } else if (!strcmp(params
[0],"Flush")) {
955 nb_flush(ival(params
[1]));
957 printf("Unknown operation %s\n", params
[0]);
965 if (!torture_close_connection(cli
)) {
973 /* run a test that simulates an approximate netbench client load */
974 static bool run_nbench(int dummy
)
983 signal(SIGALRM
, nb_alarm
);
985 t
= create_procs(run_netbench
, &correct
);
988 printf("\nThroughput %g MB/sec\n",
989 1.0e-6 * nbio_total() / t
);
995 This test checks for two things:
997 1) correct support for retaining locks over a close (ie. the server
998 must not use posix semantics)
999 2) support for lock timeouts
1001 static bool run_locktest1(int dummy
)
1003 struct cli_state
*cli1
, *cli2
;
1004 const char *fname
= "\\lockt1.lck";
1005 uint16_t fnum1
, fnum2
, fnum3
;
1007 unsigned lock_timeout
;
1009 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
1012 cli_sockopt(cli1
, sockops
);
1013 cli_sockopt(cli2
, sockops
);
1015 printf("starting locktest1\n");
1017 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
1019 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
))) {
1020 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
1023 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum2
))) {
1024 printf("open2 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
1027 if (!NT_STATUS_IS_OK(cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
, &fnum3
))) {
1028 printf("open3 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
1032 if (!cli_lock(cli1
, fnum1
, 0, 4, 0, WRITE_LOCK
)) {
1033 printf("lock1 failed (%s)\n", cli_errstr(cli1
));
1038 if (cli_lock(cli2
, fnum3
, 0, 4, 0, WRITE_LOCK
)) {
1039 printf("lock2 succeeded! This is a locking bug\n");
1042 if (!check_error(__LINE__
, cli2
, ERRDOS
, ERRlock
,
1043 NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
1047 lock_timeout
= (1 + (random() % 20));
1048 printf("Testing lock timeout with timeout=%u\n", lock_timeout
);
1050 if (cli_lock(cli2
, fnum3
, 0, 4, lock_timeout
* 1000, WRITE_LOCK
)) {
1051 printf("lock3 succeeded! This is a locking bug\n");
1054 if (!check_error(__LINE__
, cli2
, ERRDOS
, ERRlock
,
1055 NT_STATUS_FILE_LOCK_CONFLICT
)) return False
;
1059 if (ABS(t2
- t1
) < lock_timeout
-1) {
1060 printf("error: This server appears not to support timed lock requests\n");
1063 printf("server slept for %u seconds for a %u second timeout\n",
1064 (unsigned int)(t2
-t1
), lock_timeout
);
1066 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum2
))) {
1067 printf("close1 failed (%s)\n", cli_errstr(cli1
));
1071 if (cli_lock(cli2
, fnum3
, 0, 4, 0, WRITE_LOCK
)) {
1072 printf("lock4 succeeded! This is a locking bug\n");
1075 if (!check_error(__LINE__
, cli2
, ERRDOS
, ERRlock
,
1076 NT_STATUS_FILE_LOCK_CONFLICT
)) return False
;
1079 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
1080 printf("close2 failed (%s)\n", cli_errstr(cli1
));
1084 if (!NT_STATUS_IS_OK(cli_close(cli2
, fnum3
))) {
1085 printf("close3 failed (%s)\n", cli_errstr(cli2
));
1089 if (!NT_STATUS_IS_OK(cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
))) {
1090 printf("unlink failed (%s)\n", cli_errstr(cli1
));
1095 if (!torture_close_connection(cli1
)) {
1099 if (!torture_close_connection(cli2
)) {
1103 printf("Passed locktest1\n");
1108 this checks to see if a secondary tconx can use open files from an
1111 static bool run_tcon_test(int dummy
)
1113 static struct cli_state
*cli
;
1114 const char *fname
= "\\tcontest.tmp";
1116 uint16 cnum1
, cnum2
, cnum3
;
1117 uint16 vuid1
, vuid2
;
1122 memset(buf
, '\0', sizeof(buf
));
1124 if (!torture_open_connection(&cli
, 0)) {
1127 cli_sockopt(cli
, sockops
);
1129 printf("starting tcontest\n");
1131 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
1133 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
))) {
1134 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
1141 if (cli_write(cli
, fnum1
, 0, buf
, 130, 4) != 4) {
1142 printf("initial write failed (%s)", cli_errstr(cli
));
1146 status
= cli_tcon_andx(cli
, share
, "?????",
1147 password
, strlen(password
)+1);
1148 if (!NT_STATUS_IS_OK(status
)) {
1149 printf("%s refused 2nd tree connect (%s)\n", host
,
1156 cnum3
= MAX(cnum1
, cnum2
) + 1; /* any invalid number */
1157 vuid2
= cli
->vuid
+ 1;
1159 /* try a write with the wrong tid */
1162 if (cli_write(cli
, fnum1
, 0, buf
, 130, 4) == 4) {
1163 printf("* server allows write with wrong TID\n");
1166 printf("server fails write with wrong TID : %s\n", cli_errstr(cli
));
1170 /* try a write with an invalid tid */
1173 if (cli_write(cli
, fnum1
, 0, buf
, 130, 4) == 4) {
1174 printf("* server allows write with invalid TID\n");
1177 printf("server fails write with invalid TID : %s\n", cli_errstr(cli
));
1180 /* try a write with an invalid vuid */
1184 if (cli_write(cli
, fnum1
, 0, buf
, 130, 4) == 4) {
1185 printf("* server allows write with invalid VUID\n");
1188 printf("server fails write with invalid VUID : %s\n", cli_errstr(cli
));
1194 if (!NT_STATUS_IS_OK(cli_close(cli
, fnum1
))) {
1195 printf("close failed (%s)\n", cli_errstr(cli
));
1201 status
= cli_tdis(cli
);
1202 if (!NT_STATUS_IS_OK(status
)) {
1203 printf("secondary tdis failed (%s)\n", nt_errstr(status
));
1209 if (!torture_close_connection(cli
)) {
1218 checks for old style tcon support
1220 static bool run_tcon2_test(int dummy
)
1222 static struct cli_state
*cli
;
1223 uint16 cnum
, max_xmit
;
1227 if (!torture_open_connection(&cli
, 0)) {
1230 cli_sockopt(cli
, sockops
);
1232 printf("starting tcon2 test\n");
1234 if (asprintf(&service
, "\\\\%s\\%s", host
, share
) == -1) {
1238 status
= cli_raw_tcon(cli
, service
, password
, "?????", &max_xmit
, &cnum
);
1240 if (!NT_STATUS_IS_OK(status
)) {
1241 printf("tcon2 failed : %s\n", cli_errstr(cli
));
1243 printf("tcon OK : max_xmit=%d cnum=%d tid=%d\n",
1244 (int)max_xmit
, (int)cnum
, SVAL(cli
->inbuf
, smb_tid
));
1247 if (!torture_close_connection(cli
)) {
1251 printf("Passed tcon2 test\n");
1255 static bool tcon_devtest(struct cli_state
*cli
,
1256 const char *myshare
, const char *devtype
,
1257 const char *return_devtype
,
1258 NTSTATUS expected_error
)
1263 status
= cli_tcon_andx(cli
, myshare
, devtype
,
1264 password
, strlen(password
)+1);
1266 if (NT_STATUS_IS_OK(expected_error
)) {
1267 if (NT_STATUS_IS_OK(status
)) {
1268 if (strcmp(cli
->dev
, return_devtype
) == 0) {
1271 printf("tconX to share %s with type %s "
1272 "succeeded but returned the wrong "
1273 "device type (got [%s] but should have got [%s])\n",
1274 myshare
, devtype
, cli
->dev
, return_devtype
);
1278 printf("tconX to share %s with type %s "
1279 "should have succeeded but failed\n",
1285 if (NT_STATUS_IS_OK(status
)) {
1286 printf("tconx to share %s with type %s "
1287 "should have failed but succeeded\n",
1291 if (NT_STATUS_EQUAL(cli_nt_error(cli
),
1295 printf("Returned unexpected error\n");
1304 checks for correct tconX support
1306 static bool run_tcon_devtype_test(int dummy
)
1308 static struct cli_state
*cli1
= NULL
;
1314 status
= cli_full_connection(&cli1
, myname
,
1315 host
, NULL
, port_to_use
,
1317 username
, workgroup
,
1318 password
, flags
, Undefined
, &retry
);
1320 if (!NT_STATUS_IS_OK(status
)) {
1321 printf("could not open connection\n");
1325 if (!tcon_devtest(cli1
, "IPC$", "A:", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1328 if (!tcon_devtest(cli1
, "IPC$", "?????", "IPC", NT_STATUS_OK
))
1331 if (!tcon_devtest(cli1
, "IPC$", "LPT:", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1334 if (!tcon_devtest(cli1
, "IPC$", "IPC", "IPC", NT_STATUS_OK
))
1337 if (!tcon_devtest(cli1
, "IPC$", "FOOBA", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1340 if (!tcon_devtest(cli1
, share
, "A:", "A:", NT_STATUS_OK
))
1343 if (!tcon_devtest(cli1
, share
, "?????", "A:", NT_STATUS_OK
))
1346 if (!tcon_devtest(cli1
, share
, "LPT:", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1349 if (!tcon_devtest(cli1
, share
, "IPC", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1352 if (!tcon_devtest(cli1
, share
, "FOOBA", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1358 printf("Passed tcondevtest\n");
1365 This test checks that
1367 1) the server supports multiple locking contexts on the one SMB
1368 connection, distinguished by PID.
1370 2) the server correctly fails overlapping locks made by the same PID (this
1371 goes against POSIX behaviour, which is why it is tricky to implement)
1373 3) the server denies unlock requests by an incorrect client PID
1375 static bool run_locktest2(int dummy
)
1377 static struct cli_state
*cli
;
1378 const char *fname
= "\\lockt2.lck";
1379 uint16_t fnum1
, fnum2
, fnum3
;
1380 bool correct
= True
;
1382 if (!torture_open_connection(&cli
, 0)) {
1386 cli_sockopt(cli
, sockops
);
1388 printf("starting locktest2\n");
1390 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
1394 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
))) {
1395 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
1399 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
, O_RDWR
, DENY_NONE
, &fnum2
))) {
1400 printf("open2 of %s failed (%s)\n", fname
, cli_errstr(cli
));
1406 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
, O_RDWR
, DENY_NONE
, &fnum3
))) {
1407 printf("open3 of %s failed (%s)\n", fname
, cli_errstr(cli
));
1413 if (!cli_lock(cli
, fnum1
, 0, 4, 0, WRITE_LOCK
)) {
1414 printf("lock1 failed (%s)\n", cli_errstr(cli
));
1418 if (cli_lock(cli
, fnum1
, 0, 4, 0, WRITE_LOCK
)) {
1419 printf("WRITE lock1 succeeded! This is a locking bug\n");
1422 if (!check_error(__LINE__
, cli
, ERRDOS
, ERRlock
,
1423 NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
1426 if (cli_lock(cli
, fnum2
, 0, 4, 0, WRITE_LOCK
)) {
1427 printf("WRITE lock2 succeeded! This is a locking bug\n");
1430 if (!check_error(__LINE__
, cli
, ERRDOS
, ERRlock
,
1431 NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
1434 if (cli_lock(cli
, fnum2
, 0, 4, 0, READ_LOCK
)) {
1435 printf("READ lock2 succeeded! This is a locking bug\n");
1438 if (!check_error(__LINE__
, cli
, ERRDOS
, ERRlock
,
1439 NT_STATUS_FILE_LOCK_CONFLICT
)) return False
;
1442 if (!cli_lock(cli
, fnum1
, 100, 4, 0, WRITE_LOCK
)) {
1443 printf("lock at 100 failed (%s)\n", cli_errstr(cli
));
1446 if (NT_STATUS_IS_OK(cli_unlock(cli
, fnum1
, 100, 4))) {
1447 printf("unlock at 100 succeeded! This is a locking bug\n");
1451 if (NT_STATUS_IS_OK(cli_unlock(cli
, fnum1
, 0, 4))) {
1452 printf("unlock1 succeeded! This is a locking bug\n");
1455 if (!check_error(__LINE__
, cli
,
1457 NT_STATUS_RANGE_NOT_LOCKED
)) return False
;
1460 if (NT_STATUS_IS_OK(cli_unlock(cli
, fnum1
, 0, 8))) {
1461 printf("unlock2 succeeded! This is a locking bug\n");
1464 if (!check_error(__LINE__
, cli
,
1466 NT_STATUS_RANGE_NOT_LOCKED
)) return False
;
1469 if (cli_lock(cli
, fnum3
, 0, 4, 0, WRITE_LOCK
)) {
1470 printf("lock3 succeeded! This is a locking bug\n");
1473 if (!check_error(__LINE__
, cli
, ERRDOS
, ERRlock
, NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
1478 if (!NT_STATUS_IS_OK(cli_close(cli
, fnum1
))) {
1479 printf("close1 failed (%s)\n", cli_errstr(cli
));
1483 if (!NT_STATUS_IS_OK(cli_close(cli
, fnum2
))) {
1484 printf("close2 failed (%s)\n", cli_errstr(cli
));
1488 if (!NT_STATUS_IS_OK(cli_close(cli
, fnum3
))) {
1489 printf("close3 failed (%s)\n", cli_errstr(cli
));
1493 if (!torture_close_connection(cli
)) {
1497 printf("locktest2 finished\n");
1504 This test checks that
1506 1) the server supports the full offset range in lock requests
1508 static bool run_locktest3(int dummy
)
1510 static struct cli_state
*cli1
, *cli2
;
1511 const char *fname
= "\\lockt3.lck";
1512 uint16_t fnum1
, fnum2
;
1515 bool correct
= True
;
1517 #define NEXT_OFFSET offset += (~(uint32)0) / torture_numops
1519 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
1522 cli_sockopt(cli1
, sockops
);
1523 cli_sockopt(cli2
, sockops
);
1525 printf("starting locktest3\n");
1527 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
1529 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
))) {
1530 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
1533 if (!NT_STATUS_IS_OK(cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
, &fnum2
))) {
1534 printf("open2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
1538 for (offset
=i
=0;i
<torture_numops
;i
++) {
1540 if (!cli_lock(cli1
, fnum1
, offset
-1, 1, 0, WRITE_LOCK
)) {
1541 printf("lock1 %d failed (%s)\n",
1547 if (!cli_lock(cli2
, fnum2
, offset
-2, 1, 0, WRITE_LOCK
)) {
1548 printf("lock2 %d failed (%s)\n",
1555 for (offset
=i
=0;i
<torture_numops
;i
++) {
1558 if (cli_lock(cli1
, fnum1
, offset
-2, 1, 0, WRITE_LOCK
)) {
1559 printf("error: lock1 %d succeeded!\n", i
);
1563 if (cli_lock(cli2
, fnum2
, offset
-1, 1, 0, WRITE_LOCK
)) {
1564 printf("error: lock2 %d succeeded!\n", i
);
1568 if (cli_lock(cli1
, fnum1
, offset
-1, 1, 0, WRITE_LOCK
)) {
1569 printf("error: lock3 %d succeeded!\n", i
);
1573 if (cli_lock(cli2
, fnum2
, offset
-2, 1, 0, WRITE_LOCK
)) {
1574 printf("error: lock4 %d succeeded!\n", i
);
1579 for (offset
=i
=0;i
<torture_numops
;i
++) {
1582 if (!NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, offset
-1, 1))) {
1583 printf("unlock1 %d failed (%s)\n",
1589 if (!NT_STATUS_IS_OK(cli_unlock(cli2
, fnum2
, offset
-2, 1))) {
1590 printf("unlock2 %d failed (%s)\n",
1597 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
1598 printf("close1 failed (%s)\n", cli_errstr(cli1
));
1602 if (!NT_STATUS_IS_OK(cli_close(cli2
, fnum2
))) {
1603 printf("close2 failed (%s)\n", cli_errstr(cli2
));
1607 if (!NT_STATUS_IS_OK(cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
))) {
1608 printf("unlink failed (%s)\n", cli_errstr(cli1
));
1612 if (!torture_close_connection(cli1
)) {
1616 if (!torture_close_connection(cli2
)) {
1620 printf("finished locktest3\n");
1625 #define EXPECTED(ret, v) if ((ret) != (v)) { \
1626 printf("** "); correct = False; \
1630 looks at overlapping locks
1632 static bool run_locktest4(int dummy
)
1634 static struct cli_state
*cli1
, *cli2
;
1635 const char *fname
= "\\lockt4.lck";
1636 uint16_t fnum1
, fnum2
, f
;
1639 bool correct
= True
;
1641 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
1645 cli_sockopt(cli1
, sockops
);
1646 cli_sockopt(cli2
, sockops
);
1648 printf("starting locktest4\n");
1650 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
1652 cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
);
1653 cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
, &fnum2
);
1655 memset(buf
, 0, sizeof(buf
));
1657 if (cli_write(cli1
, fnum1
, 0, buf
, 0, sizeof(buf
)) != sizeof(buf
)) {
1658 printf("Failed to create file\n");
1663 ret
= cli_lock(cli1
, fnum1
, 0, 4, 0, WRITE_LOCK
) &&
1664 cli_lock(cli1
, fnum1
, 2, 4, 0, WRITE_LOCK
);
1665 EXPECTED(ret
, False
);
1666 printf("the same process %s set overlapping write locks\n", ret
?"can":"cannot");
1668 ret
= cli_lock(cli1
, fnum1
, 10, 4, 0, READ_LOCK
) &&
1669 cli_lock(cli1
, fnum1
, 12, 4, 0, READ_LOCK
);
1670 EXPECTED(ret
, True
);
1671 printf("the same process %s set overlapping read locks\n", ret
?"can":"cannot");
1673 ret
= cli_lock(cli1
, fnum1
, 20, 4, 0, WRITE_LOCK
) &&
1674 cli_lock(cli2
, fnum2
, 22, 4, 0, WRITE_LOCK
);
1675 EXPECTED(ret
, False
);
1676 printf("a different connection %s set overlapping write locks\n", ret
?"can":"cannot");
1678 ret
= cli_lock(cli1
, fnum1
, 30, 4, 0, READ_LOCK
) &&
1679 cli_lock(cli2
, fnum2
, 32, 4, 0, READ_LOCK
);
1680 EXPECTED(ret
, True
);
1681 printf("a different connection %s set overlapping read locks\n", ret
?"can":"cannot");
1683 ret
= (cli_setpid(cli1
, 1), cli_lock(cli1
, fnum1
, 40, 4, 0, WRITE_LOCK
)) &&
1684 (cli_setpid(cli1
, 2), cli_lock(cli1
, fnum1
, 42, 4, 0, WRITE_LOCK
));
1685 EXPECTED(ret
, False
);
1686 printf("a different pid %s set overlapping write locks\n", ret
?"can":"cannot");
1688 ret
= (cli_setpid(cli1
, 1), cli_lock(cli1
, fnum1
, 50, 4, 0, READ_LOCK
)) &&
1689 (cli_setpid(cli1
, 2), cli_lock(cli1
, fnum1
, 52, 4, 0, READ_LOCK
));
1690 EXPECTED(ret
, True
);
1691 printf("a different pid %s set overlapping read locks\n", ret
?"can":"cannot");
1693 ret
= cli_lock(cli1
, fnum1
, 60, 4, 0, READ_LOCK
) &&
1694 cli_lock(cli1
, fnum1
, 60, 4, 0, READ_LOCK
);
1695 EXPECTED(ret
, True
);
1696 printf("the same process %s set the same read lock twice\n", ret
?"can":"cannot");
1698 ret
= cli_lock(cli1
, fnum1
, 70, 4, 0, WRITE_LOCK
) &&
1699 cli_lock(cli1
, fnum1
, 70, 4, 0, WRITE_LOCK
);
1700 EXPECTED(ret
, False
);
1701 printf("the same process %s set the same write lock twice\n", ret
?"can":"cannot");
1703 ret
= cli_lock(cli1
, fnum1
, 80, 4, 0, READ_LOCK
) &&
1704 cli_lock(cli1
, fnum1
, 80, 4, 0, WRITE_LOCK
);
1705 EXPECTED(ret
, False
);
1706 printf("the same process %s overlay a read lock with a write lock\n", ret
?"can":"cannot");
1708 ret
= cli_lock(cli1
, fnum1
, 90, 4, 0, WRITE_LOCK
) &&
1709 cli_lock(cli1
, fnum1
, 90, 4, 0, READ_LOCK
);
1710 EXPECTED(ret
, True
);
1711 printf("the same process %s overlay a write lock with a read lock\n", ret
?"can":"cannot");
1713 ret
= (cli_setpid(cli1
, 1), cli_lock(cli1
, fnum1
, 100, 4, 0, WRITE_LOCK
)) &&
1714 (cli_setpid(cli1
, 2), cli_lock(cli1
, fnum1
, 100, 4, 0, READ_LOCK
));
1715 EXPECTED(ret
, False
);
1716 printf("a different pid %s overlay a write lock with a read lock\n", ret
?"can":"cannot");
1718 ret
= cli_lock(cli1
, fnum1
, 110, 4, 0, READ_LOCK
) &&
1719 cli_lock(cli1
, fnum1
, 112, 4, 0, READ_LOCK
) &&
1720 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 110, 6));
1721 EXPECTED(ret
, False
);
1722 printf("the same process %s coalesce read locks\n", ret
?"can":"cannot");
1725 ret
= cli_lock(cli1
, fnum1
, 120, 4, 0, WRITE_LOCK
) &&
1726 (cli_read(cli2
, fnum2
, buf
, 120, 4) == 4);
1727 EXPECTED(ret
, False
);
1728 printf("this server %s strict write locking\n", ret
?"doesn't do":"does");
1730 ret
= cli_lock(cli1
, fnum1
, 130, 4, 0, READ_LOCK
) &&
1731 (cli_write(cli2
, fnum2
, 0, buf
, 130, 4) == 4);
1732 EXPECTED(ret
, False
);
1733 printf("this server %s strict read locking\n", ret
?"doesn't do":"does");
1736 ret
= cli_lock(cli1
, fnum1
, 140, 4, 0, READ_LOCK
) &&
1737 cli_lock(cli1
, fnum1
, 140, 4, 0, READ_LOCK
) &&
1738 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 140, 4)) &&
1739 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 140, 4));
1740 EXPECTED(ret
, True
);
1741 printf("this server %s do recursive read locking\n", ret
?"does":"doesn't");
1744 ret
= cli_lock(cli1
, fnum1
, 150, 4, 0, WRITE_LOCK
) &&
1745 cli_lock(cli1
, fnum1
, 150, 4, 0, READ_LOCK
) &&
1746 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 150, 4)) &&
1747 (cli_read(cli2
, fnum2
, buf
, 150, 4) == 4) &&
1748 !(cli_write(cli2
, fnum2
, 0, buf
, 150, 4) == 4) &&
1749 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 150, 4));
1750 EXPECTED(ret
, True
);
1751 printf("this server %s do recursive lock overlays\n", ret
?"does":"doesn't");
1753 ret
= cli_lock(cli1
, fnum1
, 160, 4, 0, READ_LOCK
) &&
1754 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 160, 4)) &&
1755 (cli_write(cli2
, fnum2
, 0, buf
, 160, 4) == 4) &&
1756 (cli_read(cli2
, fnum2
, buf
, 160, 4) == 4);
1757 EXPECTED(ret
, True
);
1758 printf("the same process %s remove a read lock using write locking\n", ret
?"can":"cannot");
1760 ret
= cli_lock(cli1
, fnum1
, 170, 4, 0, WRITE_LOCK
) &&
1761 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 170, 4)) &&
1762 (cli_write(cli2
, fnum2
, 0, buf
, 170, 4) == 4) &&
1763 (cli_read(cli2
, fnum2
, buf
, 170, 4) == 4);
1764 EXPECTED(ret
, True
);
1765 printf("the same process %s remove a write lock using read locking\n", ret
?"can":"cannot");
1767 ret
= cli_lock(cli1
, fnum1
, 190, 4, 0, WRITE_LOCK
) &&
1768 cli_lock(cli1
, fnum1
, 190, 4, 0, READ_LOCK
) &&
1769 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 190, 4)) &&
1770 !(cli_write(cli2
, fnum2
, 0, buf
, 190, 4) == 4) &&
1771 (cli_read(cli2
, fnum2
, buf
, 190, 4) == 4);
1772 EXPECTED(ret
, True
);
1773 printf("the same process %s remove the first lock first\n", ret
?"does":"doesn't");
1775 cli_close(cli1
, fnum1
);
1776 cli_close(cli2
, fnum2
);
1777 cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
);
1778 cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &f
);
1779 ret
= cli_lock(cli1
, fnum1
, 0, 8, 0, READ_LOCK
) &&
1780 cli_lock(cli1
, f
, 0, 1, 0, READ_LOCK
) &&
1781 NT_STATUS_IS_OK(cli_close(cli1
, fnum1
)) &&
1782 NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
)) &&
1783 cli_lock(cli1
, fnum1
, 7, 1, 0, WRITE_LOCK
);
1785 cli_close(cli1
, fnum1
);
1786 EXPECTED(ret
, True
);
1787 printf("the server %s have the NT byte range lock bug\n", !ret
?"does":"doesn't");
1790 cli_close(cli1
, fnum1
);
1791 cli_close(cli2
, fnum2
);
1792 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
1793 torture_close_connection(cli1
);
1794 torture_close_connection(cli2
);
1796 printf("finished locktest4\n");
1801 looks at lock upgrade/downgrade.
1803 static bool run_locktest5(int dummy
)
1805 static struct cli_state
*cli1
, *cli2
;
1806 const char *fname
= "\\lockt5.lck";
1807 uint16_t fnum1
, fnum2
, fnum3
;
1810 bool correct
= True
;
1812 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
1816 cli_sockopt(cli1
, sockops
);
1817 cli_sockopt(cli2
, sockops
);
1819 printf("starting locktest5\n");
1821 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
1823 cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
);
1824 cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
, &fnum2
);
1825 cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum3
);
1827 memset(buf
, 0, sizeof(buf
));
1829 if (cli_write(cli1
, fnum1
, 0, buf
, 0, sizeof(buf
)) != sizeof(buf
)) {
1830 printf("Failed to create file\n");
1835 /* Check for NT bug... */
1836 ret
= cli_lock(cli1
, fnum1
, 0, 8, 0, READ_LOCK
) &&
1837 cli_lock(cli1
, fnum3
, 0, 1, 0, READ_LOCK
);
1838 cli_close(cli1
, fnum1
);
1839 cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
);
1840 ret
= cli_lock(cli1
, fnum1
, 7, 1, 0, WRITE_LOCK
);
1841 EXPECTED(ret
, True
);
1842 printf("this server %s the NT locking bug\n", ret
? "doesn't have" : "has");
1843 cli_close(cli1
, fnum1
);
1844 cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
);
1845 cli_unlock(cli1
, fnum3
, 0, 1);
1847 ret
= cli_lock(cli1
, fnum1
, 0, 4, 0, WRITE_LOCK
) &&
1848 cli_lock(cli1
, fnum1
, 1, 1, 0, READ_LOCK
);
1849 EXPECTED(ret
, True
);
1850 printf("the same process %s overlay a write with a read lock\n", ret
?"can":"cannot");
1852 ret
= cli_lock(cli2
, fnum2
, 0, 4, 0, READ_LOCK
);
1853 EXPECTED(ret
, False
);
1855 printf("a different processs %s get a read lock on the first process lock stack\n", ret
?"can":"cannot");
1857 /* Unlock the process 2 lock. */
1858 cli_unlock(cli2
, fnum2
, 0, 4);
1860 ret
= cli_lock(cli1
, fnum3
, 0, 4, 0, READ_LOCK
);
1861 EXPECTED(ret
, False
);
1863 printf("the same processs on a different fnum %s get a read lock\n", ret
?"can":"cannot");
1865 /* Unlock the process 1 fnum3 lock. */
1866 cli_unlock(cli1
, fnum3
, 0, 4);
1868 /* Stack 2 more locks here. */
1869 ret
= cli_lock(cli1
, fnum1
, 0, 4, 0, READ_LOCK
) &&
1870 cli_lock(cli1
, fnum1
, 0, 4, 0, READ_LOCK
);
1872 EXPECTED(ret
, True
);
1873 printf("the same process %s stack read locks\n", ret
?"can":"cannot");
1875 /* Unlock the first process lock, then check this was the WRITE lock that was
1878 ret
= NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 0, 4)) &&
1879 cli_lock(cli2
, fnum2
, 0, 4, 0, READ_LOCK
);
1881 EXPECTED(ret
, True
);
1882 printf("the first unlock removes the %s lock\n", ret
?"WRITE":"READ");
1884 /* Unlock the process 2 lock. */
1885 cli_unlock(cli2
, fnum2
, 0, 4);
1887 /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */
1889 ret
= NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 1, 1)) &&
1890 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 0, 4)) &&
1891 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 0, 4));
1893 EXPECTED(ret
, True
);
1894 printf("the same process %s unlock the stack of 4 locks\n", ret
?"can":"cannot");
1896 /* Ensure the next unlock fails. */
1897 ret
= NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 0, 4));
1898 EXPECTED(ret
, False
);
1899 printf("the same process %s count the lock stack\n", !ret
?"can":"cannot");
1901 /* Ensure connection 2 can get a write lock. */
1902 ret
= cli_lock(cli2
, fnum2
, 0, 4, 0, WRITE_LOCK
);
1903 EXPECTED(ret
, True
);
1905 printf("a different processs %s get a write lock on the unlocked stack\n", ret
?"can":"cannot");
1909 cli_close(cli1
, fnum1
);
1910 cli_close(cli2
, fnum2
);
1911 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
1912 if (!torture_close_connection(cli1
)) {
1915 if (!torture_close_connection(cli2
)) {
1919 printf("finished locktest5\n");
1925 tries the unusual lockingX locktype bits
1927 static bool run_locktest6(int dummy
)
1929 static struct cli_state
*cli
;
1930 const char *fname
[1] = { "\\lock6.txt" };
1935 if (!torture_open_connection(&cli
, 0)) {
1939 cli_sockopt(cli
, sockops
);
1941 printf("starting locktest6\n");
1944 printf("Testing %s\n", fname
[i
]);
1946 cli_unlink(cli
, fname
[i
], aSYSTEM
| aHIDDEN
);
1948 cli_open(cli
, fname
[i
], O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum
);
1949 status
= cli_locktype(cli
, fnum
, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE
);
1950 cli_close(cli
, fnum
);
1951 printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status
));
1953 cli_open(cli
, fname
[i
], O_RDWR
, DENY_NONE
, &fnum
);
1954 status
= cli_locktype(cli
, fnum
, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK
);
1955 cli_close(cli
, fnum
);
1956 printf("CANCEL_LOCK gave %s\n", nt_errstr(status
));
1958 cli_unlink(cli
, fname
[i
], aSYSTEM
| aHIDDEN
);
1961 torture_close_connection(cli
);
1963 printf("finished locktest6\n");
1967 static bool run_locktest7(int dummy
)
1969 struct cli_state
*cli1
;
1970 const char *fname
= "\\lockt7.lck";
1973 bool correct
= False
;
1975 if (!torture_open_connection(&cli1
, 0)) {
1979 cli_sockopt(cli1
, sockops
);
1981 printf("starting locktest7\n");
1983 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
1985 cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
);
1987 memset(buf
, 0, sizeof(buf
));
1989 if (cli_write(cli1
, fnum1
, 0, buf
, 0, sizeof(buf
)) != sizeof(buf
)) {
1990 printf("Failed to create file\n");
1994 cli_setpid(cli1
, 1);
1996 if (!cli_lock(cli1
, fnum1
, 130, 4, 0, READ_LOCK
)) {
1997 printf("Unable to apply read lock on range 130:4, error was %s\n", cli_errstr(cli1
));
2000 printf("pid1 successfully locked range 130:4 for READ\n");
2003 if (cli_read(cli1
, fnum1
, buf
, 130, 4) != 4) {
2004 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1
));
2007 printf("pid1 successfully read the range 130:4\n");
2010 if (cli_write(cli1
, fnum1
, 0, buf
, 130, 4) != 4) {
2011 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1
));
2012 if (NT_STATUS_V(cli_nt_error(cli1
)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT
)) {
2013 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2017 printf("pid1 successfully wrote to the range 130:4 (should be denied)\n");
2021 cli_setpid(cli1
, 2);
2023 if (cli_read(cli1
, fnum1
, buf
, 130, 4) != 4) {
2024 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1
));
2026 printf("pid2 successfully read the range 130:4\n");
2029 if (cli_write(cli1
, fnum1
, 0, buf
, 130, 4) != 4) {
2030 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1
));
2031 if (NT_STATUS_V(cli_nt_error(cli1
)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT
)) {
2032 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2036 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
2040 cli_setpid(cli1
, 1);
2041 cli_unlock(cli1
, fnum1
, 130, 4);
2043 if (!cli_lock(cli1
, fnum1
, 130, 4, 0, WRITE_LOCK
)) {
2044 printf("Unable to apply write lock on range 130:4, error was %s\n", cli_errstr(cli1
));
2047 printf("pid1 successfully locked range 130:4 for WRITE\n");
2050 if (cli_read(cli1
, fnum1
, buf
, 130, 4) != 4) {
2051 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1
));
2054 printf("pid1 successfully read the range 130:4\n");
2057 if (cli_write(cli1
, fnum1
, 0, buf
, 130, 4) != 4) {
2058 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1
));
2061 printf("pid1 successfully wrote to the range 130:4\n");
2064 cli_setpid(cli1
, 2);
2066 if (cli_read(cli1
, fnum1
, buf
, 130, 4) != 4) {
2067 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1
));
2068 if (NT_STATUS_V(cli_nt_error(cli1
)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT
)) {
2069 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2073 printf("pid2 successfully read the range 130:4 (should be denied)\n");
2077 if (cli_write(cli1
, fnum1
, 0, buf
, 130, 4) != 4) {
2078 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1
));
2079 if (NT_STATUS_V(cli_nt_error(cli1
)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT
)) {
2080 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2084 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
2088 cli_unlock(cli1
, fnum1
, 130, 0);
2092 cli_close(cli1
, fnum1
);
2093 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
2094 torture_close_connection(cli1
);
2096 printf("finished locktest7\n");
2101 * This demonstrates a problem with our use of GPFS share modes: A file
2102 * descriptor sitting in the pending close queue holding a GPFS share mode
2103 * blocks opening a file another time. Happens with Word 2007 temp files.
2104 * With "posix locking = yes" and "gpfs:sharemodes = yes" enabled, the third
2105 * open is denied with NT_STATUS_SHARING_VIOLATION.
2108 static bool run_locktest8(int dummy
)
2110 struct cli_state
*cli1
;
2111 const char *fname
= "\\lockt8.lck";
2112 uint16_t fnum1
, fnum2
;
2114 bool correct
= False
;
2117 if (!torture_open_connection(&cli1
, 0)) {
2121 cli_sockopt(cli1
, sockops
);
2123 printf("starting locktest8\n");
2125 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
2127 status
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_WRITE
,
2129 if (!NT_STATUS_IS_OK(status
)) {
2130 d_fprintf(stderr
, "cli_open returned %s\n", cli_errstr(cli1
));
2134 memset(buf
, 0, sizeof(buf
));
2136 status
= cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
, &fnum2
);
2137 if (!NT_STATUS_IS_OK(status
)) {
2138 d_fprintf(stderr
, "cli_open second time returned %s\n",
2143 if (!cli_lock(cli1
, fnum2
, 1, 1, 0, READ_LOCK
)) {
2144 printf("Unable to apply read lock on range 1:1, error was "
2145 "%s\n", cli_errstr(cli1
));
2149 status
= cli_close(cli1
, fnum1
);
2150 if (!NT_STATUS_IS_OK(status
)) {
2151 d_fprintf(stderr
, "cli_close(fnum1) %s\n", cli_errstr(cli1
));
2155 status
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
);
2156 if (!NT_STATUS_IS_OK(status
)) {
2157 d_fprintf(stderr
, "cli_open third time returned %s\n",
2165 cli_close(cli1
, fnum1
);
2166 cli_close(cli1
, fnum2
);
2167 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
2168 torture_close_connection(cli1
);
2170 printf("finished locktest8\n");
2175 * This test is designed to be run in conjunction with
2176 * external NFS or POSIX locks taken in the filesystem.
2177 * It checks that the smbd server will block until the
2178 * lock is released and then acquire it. JRA.
2181 static bool got_alarm
;
2182 static int alarm_fd
;
2184 static void alarm_handler(int dummy
)
2189 static void alarm_handler_parent(int dummy
)
2194 static void do_local_lock(int read_fd
, int write_fd
)
2199 const char *local_pathname
= NULL
;
2202 local_pathname
= talloc_asprintf(talloc_tos(),
2203 "%s/lockt9.lck", local_path
);
2204 if (!local_pathname
) {
2205 printf("child: alloc fail\n");
2209 unlink(local_pathname
);
2210 fd
= open(local_pathname
, O_RDWR
|O_CREAT
, 0666);
2212 printf("child: open of %s failed %s.\n",
2213 local_pathname
, strerror(errno
));
2217 /* Now take a fcntl lock. */
2218 lock
.l_type
= F_WRLCK
;
2219 lock
.l_whence
= SEEK_SET
;
2222 lock
.l_pid
= getpid();
2224 ret
= fcntl(fd
,F_SETLK
,&lock
);
2226 printf("child: failed to get lock 0:4 on file %s. Error %s\n",
2227 local_pathname
, strerror(errno
));
2230 printf("child: got lock 0:4 on file %s.\n",
2235 CatchSignal(SIGALRM
, alarm_handler
);
2237 /* Signal the parent. */
2238 if (write(write_fd
, &c
, 1) != 1) {
2239 printf("child: start signal fail %s.\n",
2246 /* Wait for the parent to be ready. */
2247 if (read(read_fd
, &c
, 1) != 1) {
2248 printf("child: reply signal fail %s.\n",
2256 printf("child: released lock 0:4 on file %s.\n",
2262 static bool run_locktest9(int dummy
)
2264 struct cli_state
*cli1
;
2265 const char *fname
= "\\lockt9.lck";
2267 bool correct
= False
;
2268 int pipe_in
[2], pipe_out
[2];
2272 struct timeval start
;
2276 printf("starting locktest9\n");
2278 if (local_path
== NULL
) {
2279 d_fprintf(stderr
, "locktest9 must be given a local path via -l <localpath>\n");
2283 if (pipe(pipe_in
) == -1 || pipe(pipe_out
) == -1) {
2288 if (child_pid
== -1) {
2292 if (child_pid
== 0) {
2294 do_local_lock(pipe_out
[0], pipe_in
[1]);
2304 ret
= read(pipe_in
[0], &c
, 1);
2306 d_fprintf(stderr
, "failed to read start signal from child. %s\n",
2311 if (!torture_open_connection(&cli1
, 0)) {
2315 cli_sockopt(cli1
, sockops
);
2317 status
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
,
2319 if (!NT_STATUS_IS_OK(status
)) {
2320 d_fprintf(stderr
, "cli_open returned %s\n", cli_errstr(cli1
));
2324 /* Ensure the child has the lock. */
2325 if (cli_lock(cli1
, fnum
, 0, 4, 0, WRITE_LOCK
)) {
2326 d_fprintf(stderr
, "Got the lock on range 0:4 - this should not happen !\n");
2329 d_printf("Child has the lock.\n");
2332 /* Tell the child to wait 5 seconds then exit. */
2333 ret
= write(pipe_out
[1], &c
, 1);
2335 d_fprintf(stderr
, "failed to send exit signal to child. %s\n",
2340 /* Wait 20 seconds for the lock. */
2341 alarm_fd
= cli1
->fd
;
2342 CatchSignal(SIGALRM
, alarm_handler_parent
);
2345 start
= timeval_current();
2347 if (!cli_lock(cli1
, fnum
, 0, 4, -1, WRITE_LOCK
)) {
2348 d_fprintf(stderr
, "Unable to apply write lock on range 0:4, error was "
2349 "%s\n", cli_errstr(cli1
));
2354 seconds
= timeval_elapsed(&start
);
2356 printf("Parent got the lock after %.2f seconds.\n",
2359 status
= cli_close(cli1
, fnum
);
2360 if (!NT_STATUS_IS_OK(status
)) {
2361 d_fprintf(stderr
, "cli_close(fnum1) %s\n", cli_errstr(cli1
));
2368 cli_close(cli1
, fnum
);
2369 torture_close_connection(cli1
);
2373 printf("finished locktest9\n");
2378 test whether fnums and tids open on one VC are available on another (a major
2381 static bool run_fdpasstest(int dummy
)
2383 struct cli_state
*cli1
, *cli2
;
2384 const char *fname
= "\\fdpass.tst";
2388 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
2391 cli_sockopt(cli1
, sockops
);
2392 cli_sockopt(cli2
, sockops
);
2394 printf("starting fdpasstest\n");
2396 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
2398 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
))) {
2399 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
2403 if (cli_write(cli1
, fnum1
, 0, "hello world\n", 0, 13) != 13) {
2404 printf("write failed (%s)\n", cli_errstr(cli1
));
2408 cli2
->vuid
= cli1
->vuid
;
2409 cli2
->cnum
= cli1
->cnum
;
2410 cli2
->pid
= cli1
->pid
;
2412 if (cli_read(cli2
, fnum1
, buf
, 0, 13) == 13) {
2413 printf("read succeeded! nasty security hole [%s]\n",
2418 cli_close(cli1
, fnum1
);
2419 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
2421 torture_close_connection(cli1
);
2422 torture_close_connection(cli2
);
2424 printf("finished fdpasstest\n");
2428 static bool run_fdsesstest(int dummy
)
2430 struct cli_state
*cli
;
2435 const char *fname
= "\\fdsess.tst";
2436 const char *fname1
= "\\fdsess1.tst";
2442 if (!torture_open_connection(&cli
, 0))
2444 cli_sockopt(cli
, sockops
);
2446 if (!torture_cli_session_setup2(cli
, &new_vuid
))
2449 saved_cnum
= cli
->cnum
;
2450 if (!NT_STATUS_IS_OK(cli_tcon_andx(cli
, share
, "?????", "", 1)))
2452 new_cnum
= cli
->cnum
;
2453 cli
->cnum
= saved_cnum
;
2455 printf("starting fdsesstest\n");
2457 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
2458 cli_unlink(cli
, fname1
, aSYSTEM
| aHIDDEN
);
2460 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
))) {
2461 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
2465 if (cli_write(cli
, fnum1
, 0, "hello world\n", 0, 13) != 13) {
2466 printf("write failed (%s)\n", cli_errstr(cli
));
2470 saved_vuid
= cli
->vuid
;
2471 cli
->vuid
= new_vuid
;
2473 if (cli_read(cli
, fnum1
, buf
, 0, 13) == 13) {
2474 printf("read succeeded with different vuid! nasty security hole [%s]\n",
2478 /* Try to open a file with different vuid, samba cnum. */
2479 if (NT_STATUS_IS_OK(cli_open(cli
, fname1
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum2
))) {
2480 printf("create with different vuid, same cnum succeeded.\n");
2481 cli_close(cli
, fnum2
);
2482 cli_unlink(cli
, fname1
, aSYSTEM
| aHIDDEN
);
2484 printf("create with different vuid, same cnum failed.\n");
2485 printf("This will cause problems with service clients.\n");
2489 cli
->vuid
= saved_vuid
;
2491 /* Try with same vuid, different cnum. */
2492 cli
->cnum
= new_cnum
;
2494 if (cli_read(cli
, fnum1
, buf
, 0, 13) == 13) {
2495 printf("read succeeded with different cnum![%s]\n",
2500 cli
->cnum
= saved_cnum
;
2501 cli_close(cli
, fnum1
);
2502 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
2504 torture_close_connection(cli
);
2506 printf("finished fdsesstest\n");
2511 This test checks that
2513 1) the server does not allow an unlink on a file that is open
2515 static bool run_unlinktest(int dummy
)
2517 struct cli_state
*cli
;
2518 const char *fname
= "\\unlink.tst";
2520 bool correct
= True
;
2522 if (!torture_open_connection(&cli
, 0)) {
2526 cli_sockopt(cli
, sockops
);
2528 printf("starting unlink test\n");
2530 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
2534 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum
))) {
2535 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
2539 if (NT_STATUS_IS_OK(cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
))) {
2540 printf("error: server allowed unlink on an open file\n");
2543 correct
= check_error(__LINE__
, cli
, ERRDOS
, ERRbadshare
,
2544 NT_STATUS_SHARING_VIOLATION
);
2547 cli_close(cli
, fnum
);
2548 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
2550 if (!torture_close_connection(cli
)) {
2554 printf("unlink test finished\n");
2561 test how many open files this server supports on the one socket
2563 static bool run_maxfidtest(int dummy
)
2565 struct cli_state
*cli
;
2566 const char *ftemplate
= "\\maxfid.%d.%d";
2568 uint16_t fnums
[0x11000];
2571 bool correct
= True
;
2576 printf("failed to connect\n");
2580 cli_sockopt(cli
, sockops
);
2582 for (i
=0; i
<0x11000; i
++) {
2583 slprintf(fname
,sizeof(fname
)-1,ftemplate
, i
,(int)getpid());
2584 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
,
2585 O_RDWR
|O_CREAT
|O_TRUNC
, DENY_NONE
, &fnums
[i
]))) {
2586 printf("open of %s failed (%s)\n",
2587 fname
, cli_errstr(cli
));
2588 printf("maximum fnum is %d\n", i
);
2596 printf("cleaning up\n");
2598 slprintf(fname
,sizeof(fname
)-1,ftemplate
, i
,(int)getpid());
2599 cli_close(cli
, fnums
[i
]);
2600 if (!NT_STATUS_IS_OK(cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
))) {
2601 printf("unlink of %s failed (%s)\n",
2602 fname
, cli_errstr(cli
));
2609 printf("maxfid test finished\n");
2610 if (!torture_close_connection(cli
)) {
2616 /* generate a random buffer */
2617 static void rand_buf(char *buf
, int len
)
2620 *buf
= (char)sys_random();
2625 /* send smb negprot commands, not reading the response */
2626 static bool run_negprot_nowait(int dummy
)
2629 static struct cli_state
*cli
;
2630 bool correct
= True
;
2632 printf("starting negprot nowait test\n");
2634 if (!(cli
= open_nbt_connection())) {
2638 for (i
=0;i
<50000;i
++) {
2639 cli_negprot_sendsync(cli
);
2642 if (!torture_close_connection(cli
)) {
2646 printf("finished negprot nowait test\n");
2652 /* send random IPC commands */
2653 static bool run_randomipc(int dummy
)
2655 char *rparam
= NULL
;
2657 unsigned int rdrcnt
,rprcnt
;
2659 int api
, param_len
, i
;
2660 struct cli_state
*cli
;
2661 bool correct
= True
;
2664 printf("starting random ipc test\n");
2666 if (!torture_open_connection(&cli
, 0)) {
2670 for (i
=0;i
<count
;i
++) {
2671 api
= sys_random() % 500;
2672 param_len
= (sys_random() % 64);
2674 rand_buf(param
, param_len
);
2679 param
, param_len
, 8,
2680 NULL
, 0, BUFFER_SIZE
,
2684 printf("%d/%d\r", i
,count
);
2687 printf("%d/%d\n", i
, count
);
2689 if (!torture_close_connection(cli
)) {
2693 printf("finished random ipc test\n");
2700 static void browse_callback(const char *sname
, uint32 stype
,
2701 const char *comment
, void *state
)
2703 printf("\t%20.20s %08x %s\n", sname
, stype
, comment
);
2709 This test checks the browse list code
2712 static bool run_browsetest(int dummy
)
2714 static struct cli_state
*cli
;
2715 bool correct
= True
;
2717 printf("starting browse test\n");
2719 if (!torture_open_connection(&cli
, 0)) {
2723 printf("domain list:\n");
2724 cli_NetServerEnum(cli
, cli
->server_domain
,
2725 SV_TYPE_DOMAIN_ENUM
,
2726 browse_callback
, NULL
);
2728 printf("machine list:\n");
2729 cli_NetServerEnum(cli
, cli
->server_domain
,
2731 browse_callback
, NULL
);
2733 if (!torture_close_connection(cli
)) {
2737 printf("browse test finished\n");
2745 This checks how the getatr calls works
2747 static bool run_attrtest(int dummy
)
2749 struct cli_state
*cli
;
2752 const char *fname
= "\\attrib123456789.tst";
2753 bool correct
= True
;
2755 printf("starting attrib test\n");
2757 if (!torture_open_connection(&cli
, 0)) {
2761 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
2762 cli_open(cli
, fname
,
2763 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
, &fnum
);
2764 cli_close(cli
, fnum
);
2765 if (!NT_STATUS_IS_OK(cli_getatr(cli
, fname
, NULL
, NULL
, &t
))) {
2766 printf("getatr failed (%s)\n", cli_errstr(cli
));
2770 if (abs(t
- time(NULL
)) > 60*60*24*10) {
2771 printf("ERROR: SMBgetatr bug. time is %s",
2777 t2
= t
-60*60*24; /* 1 day ago */
2779 if (!NT_STATUS_IS_OK(cli_setatr(cli
, fname
, 0, t2
))) {
2780 printf("setatr failed (%s)\n", cli_errstr(cli
));
2784 if (!NT_STATUS_IS_OK(cli_getatr(cli
, fname
, NULL
, NULL
, &t
))) {
2785 printf("getatr failed (%s)\n", cli_errstr(cli
));
2790 printf("ERROR: getatr/setatr bug. times are\n%s",
2792 printf("%s", ctime(&t2
));
2796 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
2798 if (!torture_close_connection(cli
)) {
2802 printf("attrib test finished\n");
2809 This checks a couple of trans2 calls
2811 static bool run_trans2test(int dummy
)
2813 struct cli_state
*cli
;
2816 time_t c_time
, a_time
, m_time
;
2817 struct timespec c_time_ts
, a_time_ts
, m_time_ts
, w_time_ts
, m_time2_ts
;
2818 const char *fname
= "\\trans2.tst";
2819 const char *dname
= "\\trans2";
2820 const char *fname2
= "\\trans2\\trans2.tst";
2822 bool correct
= True
;
2826 printf("starting trans2 test\n");
2828 if (!torture_open_connection(&cli
, 0)) {
2832 status
= cli_get_fs_attr_info(cli
, &fs_attr
);
2833 if (!NT_STATUS_IS_OK(status
)) {
2834 printf("ERROR: cli_get_fs_attr_info returned %s\n",
2839 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
2840 cli_open(cli
, fname
,
2841 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
, &fnum
);
2842 if (!cli_qfileinfo(cli
, fnum
, NULL
, &size
, &c_time_ts
, &a_time_ts
, &w_time_ts
,
2843 &m_time_ts
, NULL
)) {
2844 printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(cli
));
2848 if (!cli_qfilename(cli
, fnum
, pname
, sizeof(pname
))) {
2849 printf("ERROR: qfilename failed (%s)\n", cli_errstr(cli
));
2853 if (strcmp(pname
, fname
)) {
2854 printf("qfilename gave different name? [%s] [%s]\n",
2859 cli_close(cli
, fnum
);
2863 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
2864 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
,
2865 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
, &fnum
))) {
2866 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
2869 cli_close(cli
, fnum
);
2871 status
= cli_qpathinfo1(cli
, fname
, &c_time
, &a_time
, &m_time
, &size
,
2873 if (!NT_STATUS_IS_OK(status
)) {
2874 printf("ERROR: qpathinfo failed (%s)\n", nt_errstr(status
));
2877 if (c_time
!= m_time
) {
2878 printf("create time=%s", ctime(&c_time
));
2879 printf("modify time=%s", ctime(&m_time
));
2880 printf("This system appears to have sticky create times\n");
2882 if (a_time
% (60*60) == 0) {
2883 printf("access time=%s", ctime(&a_time
));
2884 printf("This system appears to set a midnight access time\n");
2888 if (abs(m_time
- time(NULL
)) > 60*60*24*7) {
2889 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time
));
2895 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
2896 cli_open(cli
, fname
,
2897 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
, &fnum
);
2898 cli_close(cli
, fnum
);
2899 status
= cli_qpathinfo2(cli
, fname
, &c_time_ts
, &a_time_ts
, &w_time_ts
,
2900 &m_time_ts
, &size
, NULL
, NULL
);
2901 if (!NT_STATUS_IS_OK(status
)) {
2902 printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status
));
2905 if (w_time_ts
.tv_sec
< 60*60*24*2) {
2906 printf("write time=%s", ctime(&w_time_ts
.tv_sec
));
2907 printf("This system appears to set a initial 0 write time\n");
2912 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
2915 /* check if the server updates the directory modification time
2916 when creating a new file */
2917 if (!NT_STATUS_IS_OK(cli_mkdir(cli
, dname
))) {
2918 printf("ERROR: mkdir failed (%s)\n", cli_errstr(cli
));
2922 status
= cli_qpathinfo2(cli
, "\\trans2\\", &c_time_ts
, &a_time_ts
,
2923 &w_time_ts
, &m_time_ts
, &size
, NULL
, NULL
);
2924 if (!NT_STATUS_IS_OK(status
)) {
2925 printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status
));
2929 cli_open(cli
, fname2
,
2930 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
, &fnum
);
2931 cli_write(cli
, fnum
, 0, (char *)&fnum
, 0, sizeof(fnum
));
2932 cli_close(cli
, fnum
);
2933 status
= cli_qpathinfo2(cli
, "\\trans2\\", &c_time_ts
, &a_time_ts
,
2934 &w_time_ts
, &m_time2_ts
, &size
, NULL
, NULL
);
2935 if (!NT_STATUS_IS_OK(status
)) {
2936 printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status
));
2939 if (memcmp(&m_time_ts
, &m_time2_ts
, sizeof(struct timespec
))
2941 printf("This system does not update directory modification times\n");
2945 cli_unlink(cli
, fname2
, aSYSTEM
| aHIDDEN
);
2946 cli_rmdir(cli
, dname
);
2948 if (!torture_close_connection(cli
)) {
2952 printf("trans2 test finished\n");
2958 This checks new W2K calls.
2961 static bool new_trans(struct cli_state
*pcli
, int fnum
, int level
)
2965 bool correct
= True
;
2967 if (!cli_qfileinfo_test(pcli
, fnum
, level
, &buf
, &len
)) {
2968 printf("ERROR: qfileinfo (%d) failed (%s)\n", level
, cli_errstr(pcli
));
2971 printf("qfileinfo: level %d, len = %u\n", level
, len
);
2972 dump_data(0, (uint8
*)buf
, len
);
2979 static bool run_w2ktest(int dummy
)
2981 struct cli_state
*cli
;
2983 const char *fname
= "\\w2ktest\\w2k.tst";
2985 bool correct
= True
;
2987 printf("starting w2k test\n");
2989 if (!torture_open_connection(&cli
, 0)) {
2993 cli_open(cli
, fname
,
2994 O_RDWR
| O_CREAT
, DENY_NONE
, &fnum
);
2996 for (level
= 1004; level
< 1040; level
++) {
2997 new_trans(cli
, fnum
, level
);
3000 cli_close(cli
, fnum
);
3002 if (!torture_close_connection(cli
)) {
3006 printf("w2k test finished\n");
3013 this is a harness for some oplock tests
3015 static bool run_oplock1(int dummy
)
3017 struct cli_state
*cli1
;
3018 const char *fname
= "\\lockt1.lck";
3020 bool correct
= True
;
3022 printf("starting oplock test 1\n");
3024 if (!torture_open_connection(&cli1
, 0)) {
3028 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3030 cli_sockopt(cli1
, sockops
);
3032 cli1
->use_oplocks
= True
;
3034 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
))) {
3035 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3039 cli1
->use_oplocks
= False
;
3041 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3042 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3044 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3045 printf("close2 failed (%s)\n", cli_errstr(cli1
));
3049 if (!NT_STATUS_IS_OK(cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
))) {
3050 printf("unlink failed (%s)\n", cli_errstr(cli1
));
3054 if (!torture_close_connection(cli1
)) {
3058 printf("finished oplock test 1\n");
3063 static bool run_oplock2(int dummy
)
3065 struct cli_state
*cli1
, *cli2
;
3066 const char *fname
= "\\lockt2.lck";
3067 uint16_t fnum1
, fnum2
;
3068 int saved_use_oplocks
= use_oplocks
;
3070 bool correct
= True
;
3071 volatile bool *shared_correct
;
3073 shared_correct
= (volatile bool *)shm_setup(sizeof(bool));
3074 *shared_correct
= True
;
3076 use_level_II_oplocks
= True
;
3079 printf("starting oplock test 2\n");
3081 if (!torture_open_connection(&cli1
, 0)) {
3082 use_level_II_oplocks
= False
;
3083 use_oplocks
= saved_use_oplocks
;
3087 cli1
->use_oplocks
= True
;
3088 cli1
->use_level_II_oplocks
= True
;
3090 if (!torture_open_connection(&cli2
, 1)) {
3091 use_level_II_oplocks
= False
;
3092 use_oplocks
= saved_use_oplocks
;
3096 cli2
->use_oplocks
= True
;
3097 cli2
->use_level_II_oplocks
= True
;
3099 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3101 cli_sockopt(cli1
, sockops
);
3102 cli_sockopt(cli2
, sockops
);
3104 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
))) {
3105 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3109 /* Don't need the globals any more. */
3110 use_level_II_oplocks
= False
;
3111 use_oplocks
= saved_use_oplocks
;
3115 if (!NT_STATUS_IS_OK(cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
, &fnum2
))) {
3116 printf("second open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3117 *shared_correct
= False
;
3123 if (!NT_STATUS_IS_OK(cli_close(cli2
, fnum2
))) {
3124 printf("close2 failed (%s)\n", cli_errstr(cli1
));
3125 *shared_correct
= False
;
3133 /* Ensure cli1 processes the break. Empty file should always return 0
3136 if (cli_read(cli1
, fnum1
, buf
, 0, 4) != 0) {
3137 printf("read on fnum1 failed (%s)\n", cli_errstr(cli1
));
3141 /* Should now be at level II. */
3142 /* Test if sending a write locks causes a break to none. */
3144 if (!cli_lock(cli1
, fnum1
, 0, 4, 0, READ_LOCK
)) {
3145 printf("lock failed (%s)\n", cli_errstr(cli1
));
3149 cli_unlock(cli1
, fnum1
, 0, 4);
3153 if (!cli_lock(cli1
, fnum1
, 0, 4, 0, WRITE_LOCK
)) {
3154 printf("lock failed (%s)\n", cli_errstr(cli1
));
3158 cli_unlock(cli1
, fnum1
, 0, 4);
3162 cli_read(cli1
, fnum1
, buf
, 0, 4);
3165 if (cli_write(cli1
, fnum1
, 0, buf
, 0, 4) != 4) {
3166 printf("write on fnum1 failed (%s)\n", cli_errstr(cli1
));
3171 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3172 printf("close1 failed (%s)\n", cli_errstr(cli1
));
3178 if (!NT_STATUS_IS_OK(cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
))) {
3179 printf("unlink failed (%s)\n", cli_errstr(cli1
));
3183 if (!torture_close_connection(cli1
)) {
3187 if (!*shared_correct
) {
3191 printf("finished oplock test 2\n");
3196 /* handler for oplock 3 tests */
3197 static NTSTATUS
oplock3_handler(struct cli_state
*cli
, uint16_t fnum
, unsigned char level
)
3199 printf("got oplock break fnum=%d level=%d\n",
3201 return cli_oplock_ack(cli
, fnum
, level
);
3204 static bool run_oplock3(int dummy
)
3206 struct cli_state
*cli
;
3207 const char *fname
= "\\oplockt3.dat";
3209 char buf
[4] = "abcd";
3210 bool correct
= True
;
3211 volatile bool *shared_correct
;
3213 shared_correct
= (volatile bool *)shm_setup(sizeof(bool));
3214 *shared_correct
= True
;
3216 printf("starting oplock test 3\n");
3221 use_level_II_oplocks
= True
;
3222 if (!torture_open_connection(&cli
, 0)) {
3223 *shared_correct
= False
;
3227 /* try to trigger a oplock break in parent */
3228 cli_open(cli
, fname
, O_RDWR
, DENY_NONE
, &fnum
);
3229 cli_write(cli
, fnum
, 0, buf
, 0, 4);
3235 use_level_II_oplocks
= True
;
3236 if (!torture_open_connection(&cli
, 1)) { /* other is forked */
3239 cli_oplock_handler(cli
, oplock3_handler
);
3240 cli_open(cli
, fname
, O_RDWR
|O_CREAT
, DENY_NONE
, &fnum
);
3241 cli_write(cli
, fnum
, 0, buf
, 0, 4);
3242 cli_close(cli
, fnum
);
3243 cli_open(cli
, fname
, O_RDWR
, DENY_NONE
, &fnum
);
3244 cli
->timeout
= 20000;
3245 cli_receive_smb(cli
);
3246 printf("finished oplock test 3\n");
3248 return (correct
&& *shared_correct
);
3250 /* What are we looking for here? What's sucess and what's FAILURE? */
3256 Test delete on close semantics.
3258 static bool run_deletetest(int dummy
)
3260 struct cli_state
*cli1
= NULL
;
3261 struct cli_state
*cli2
= NULL
;
3262 const char *fname
= "\\delete.file";
3263 uint16_t fnum1
= (uint16_t)-1;
3264 uint16_t fnum2
= (uint16_t)-1;
3265 bool correct
= True
;
3267 printf("starting delete test\n");
3269 if (!torture_open_connection(&cli1
, 0)) {
3273 cli_sockopt(cli1
, sockops
);
3275 /* Test 1 - this should delete the file on close. */
3277 cli_setatr(cli1
, fname
, 0, 0);
3278 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3280 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_ALL_ACCESS
|DELETE_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3281 0, FILE_OVERWRITE_IF
,
3282 FILE_DELETE_ON_CLOSE
, 0, &fnum1
))) {
3283 printf("[1] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3290 uint32
*accinfo
= NULL
;
3292 cli_qfileinfo_test(cli1
, fnum1
, SMB_FILE_ACCESS_INFORMATION
, (char **)&accinfo
, &len
);
3294 printf("access mode = 0x%lx\n", *accinfo
);
3299 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3300 printf("[1] close failed (%s)\n", cli_errstr(cli1
));
3305 if (NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
))) {
3306 printf("[1] open of %s succeeded (should fail)\n", fname
);
3311 printf("first delete on close test succeeded.\n");
3313 /* Test 2 - this should delete the file on close. */
3315 cli_setatr(cli1
, fname
, 0, 0);
3316 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3318 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_ALL_ACCESS
,
3319 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
3320 FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
3321 printf("[2] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3326 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, true))) {
3327 printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(cli1
));
3332 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3333 printf("[2] close failed (%s)\n", cli_errstr(cli1
));
3338 if (NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
, &fnum1
))) {
3339 printf("[2] open of %s succeeded should have been deleted on close !\n", fname
);
3340 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3341 printf("[2] close failed (%s)\n", cli_errstr(cli1
));
3345 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3347 printf("second delete on close test succeeded.\n");
3350 cli_setatr(cli1
, fname
, 0, 0);
3351 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3353 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_ALL_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3354 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
3355 printf("[3] open - 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3360 /* This should fail with a sharing violation - open for delete is only compatible
3361 with SHARE_DELETE. */
3363 if (NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3364 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN
, 0, 0, &fnum2
))) {
3365 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname
);
3370 /* This should succeed. */
3372 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3373 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, FILE_OPEN
, 0, 0, &fnum2
))) {
3374 printf("[3] open - 2 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3379 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, true))) {
3380 printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(cli1
));
3385 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3386 printf("[3] close 1 failed (%s)\n", cli_errstr(cli1
));
3391 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum2
))) {
3392 printf("[3] close 2 failed (%s)\n", cli_errstr(cli1
));
3397 /* This should fail - file should no longer be there. */
3399 if (NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
, &fnum1
))) {
3400 printf("[3] open of %s succeeded should have been deleted on close !\n", fname
);
3401 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3402 printf("[3] close failed (%s)\n", cli_errstr(cli1
));
3404 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3408 printf("third delete on close test succeeded.\n");
3411 cli_setatr(cli1
, fname
, 0, 0);
3412 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3414 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
3415 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
3416 printf("[4] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3421 /* This should succeed. */
3422 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
,
3423 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, FILE_OPEN
, 0, 0, &fnum2
))) {
3424 printf("[4] open - 2 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3429 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum2
))) {
3430 printf("[4] close - 1 failed (%s)\n", cli_errstr(cli1
));
3435 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, true))) {
3436 printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(cli1
));
3441 /* This should fail - no more opens once delete on close set. */
3442 if (NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
,
3443 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
3444 FILE_OPEN
, 0, 0, &fnum2
))) {
3445 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname
);
3449 printf("fourth delete on close test succeeded.\n");
3451 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3452 printf("[4] close - 2 failed (%s)\n", cli_errstr(cli1
));
3458 cli_setatr(cli1
, fname
, 0, 0);
3459 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3461 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
|O_CREAT
, DENY_NONE
, &fnum1
))) {
3462 printf("[5] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3467 /* This should fail - only allowed on NT opens with DELETE access. */
3469 if (NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, true))) {
3470 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
3475 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3476 printf("[5] close - 2 failed (%s)\n", cli_errstr(cli1
));
3481 printf("fifth delete on close test succeeded.\n");
3484 cli_setatr(cli1
, fname
, 0, 0);
3485 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3487 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
,
3488 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
3489 FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
3490 printf("[6] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3495 /* This should fail - only allowed on NT opens with DELETE access. */
3497 if (NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, true))) {
3498 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
3503 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3504 printf("[6] close - 2 failed (%s)\n", cli_errstr(cli1
));
3509 printf("sixth delete on close test succeeded.\n");
3512 cli_setatr(cli1
, fname
, 0, 0);
3513 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3515 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
3516 FILE_ATTRIBUTE_NORMAL
, 0, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
3517 printf("[7] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3522 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, true))) {
3523 printf("[7] setting delete_on_close on file failed !\n");
3528 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, false))) {
3529 printf("[7] unsetting delete_on_close on file failed !\n");
3534 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3535 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1
));
3540 /* This next open should succeed - we reset the flag. */
3542 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
, &fnum1
))) {
3543 printf("[5] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3548 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3549 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1
));
3554 printf("seventh delete on close test succeeded.\n");
3557 cli_setatr(cli1
, fname
, 0, 0);
3558 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3560 if (!torture_open_connection(&cli2
, 1)) {
3561 printf("[8] failed to open second connection.\n");
3566 cli_sockopt(cli1
, sockops
);
3568 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
3569 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
3570 FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
3571 printf("[8] open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3576 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
3577 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
3578 FILE_OPEN
, 0, 0, &fnum2
))) {
3579 printf("[8] open 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
3584 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, true))) {
3585 printf("[8] setting delete_on_close on file failed !\n");
3590 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3591 printf("[8] close - 1 failed (%s)\n", cli_errstr(cli1
));
3596 if (!NT_STATUS_IS_OK(cli_close(cli2
, fnum2
))) {
3597 printf("[8] close - 2 failed (%s)\n", cli_errstr(cli2
));
3602 /* This should fail.. */
3603 if (NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
, &fnum1
))) {
3604 printf("[8] open of %s succeeded should have been deleted on close !\n", fname
);
3608 printf("eighth delete on close test succeeded.\n");
3610 /* This should fail - we need to set DELETE_ACCESS. */
3611 if (NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0,FILE_READ_DATA
|FILE_WRITE_DATA
,
3612 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, FILE_DELETE_ON_CLOSE
, 0, &fnum1
))) {
3613 printf("[9] open of %s succeeded should have failed!\n", fname
);
3618 printf("ninth delete on close test succeeded.\n");
3620 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
3621 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, FILE_DELETE_ON_CLOSE
, 0, &fnum1
))) {
3622 printf("[10] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3627 /* This should delete the file. */
3628 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3629 printf("[10] close failed (%s)\n", cli_errstr(cli1
));
3634 /* This should fail.. */
3635 if (NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
, &fnum1
))) {
3636 printf("[10] open of %s succeeded should have been deleted on close !\n", fname
);
3640 printf("tenth delete on close test succeeded.\n");
3642 cli_setatr(cli1
, fname
, 0, 0);
3643 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3645 /* What error do we get when attempting to open a read-only file with
3648 /* Create a readonly file. */
3649 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
,
3650 FILE_ATTRIBUTE_READONLY
, FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
3651 printf("[11] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3656 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3657 printf("[11] close failed (%s)\n", cli_errstr(cli1
));
3662 /* Now try open for delete access. */
3663 if (NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_ATTRIBUTES
|DELETE_ACCESS
,
3664 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
3665 FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
3666 printf("[11] open of %s succeeded should have been denied with ACCESS_DENIED!\n", fname
);
3667 cli_close(cli1
, fnum1
);
3671 NTSTATUS nterr
= cli_nt_error(cli1
);
3672 if (!NT_STATUS_EQUAL(nterr
,NT_STATUS_ACCESS_DENIED
)) {
3673 printf("[11] open of %s should have been denied with ACCESS_DENIED! Got error %s\n", fname
, nt_errstr(nterr
));
3677 printf("eleventh delete on close test succeeded.\n");
3681 printf("finished delete test\n");
3684 /* FIXME: This will crash if we aborted before cli2 got
3685 * intialized, because these functions don't handle
3686 * uninitialized connections. */
3688 if (fnum1
!= (uint16_t)-1) cli_close(cli1
, fnum1
);
3689 if (fnum2
!= (uint16_t)-1) cli_close(cli1
, fnum2
);
3690 cli_setatr(cli1
, fname
, 0, 0);
3691 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3693 if (cli1
&& !torture_close_connection(cli1
)) {
3696 if (cli2
&& !torture_close_connection(cli2
)) {
3704 print out server properties
3706 static bool run_properties(int dummy
)
3708 struct cli_state
*cli
;
3709 bool correct
= True
;
3711 printf("starting properties test\n");
3715 if (!torture_open_connection(&cli
, 0)) {
3719 cli_sockopt(cli
, sockops
);
3721 d_printf("Capabilities 0x%08x\n", cli
->capabilities
);
3723 if (!torture_close_connection(cli
)) {
3732 /* FIRST_DESIRED_ACCESS 0xf019f */
3733 #define FIRST_DESIRED_ACCESS FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|\
3734 FILE_READ_EA| /* 0xf */ \
3735 FILE_WRITE_EA|FILE_READ_ATTRIBUTES| /* 0x90 */ \
3736 FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
3737 DELETE_ACCESS|READ_CONTROL_ACCESS|\
3738 WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS /* 0xf0000 */
3739 /* SECOND_DESIRED_ACCESS 0xe0080 */
3740 #define SECOND_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
3741 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
3742 WRITE_OWNER_ACCESS /* 0xe0000 */
3745 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
3746 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
3748 WRITE_OWNER_ACCESS /* */
3752 Test ntcreate calls made by xcopy
3754 static bool run_xcopy(int dummy
)
3756 static struct cli_state
*cli1
;
3757 const char *fname
= "\\test.txt";
3758 bool correct
= True
;
3759 uint16_t fnum1
, fnum2
;
3761 printf("starting xcopy test\n");
3763 if (!torture_open_connection(&cli1
, 0)) {
3767 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0,
3768 FIRST_DESIRED_ACCESS
, FILE_ATTRIBUTE_ARCHIVE
,
3769 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
,
3770 0x4044, 0, &fnum1
))) {
3771 printf("First open failed - %s\n", cli_errstr(cli1
));
3775 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0,
3776 SECOND_DESIRED_ACCESS
, 0,
3777 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, FILE_OPEN
,
3778 0x200000, 0, &fnum2
))) {
3779 printf("second open failed - %s\n", cli_errstr(cli1
));
3783 if (!torture_close_connection(cli1
)) {
3791 Test rename on files open with share delete and no share delete.
3793 static bool run_rename(int dummy
)
3795 static struct cli_state
*cli1
;
3796 const char *fname
= "\\test.txt";
3797 const char *fname1
= "\\test1.txt";
3798 bool correct
= True
;
3803 printf("starting rename test\n");
3805 if (!torture_open_connection(&cli1
, 0)) {
3809 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3810 cli_unlink(cli1
, fname1
, aSYSTEM
| aHIDDEN
);
3811 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3812 FILE_SHARE_READ
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
3813 printf("First open failed - %s\n", cli_errstr(cli1
));
3817 if (!NT_STATUS_IS_OK(cli_rename(cli1
, fname
, fname1
))) {
3818 printf("First rename failed (SHARE_READ) (this is correct) - %s\n", cli_errstr(cli1
));
3820 printf("First rename succeeded (SHARE_READ) - this should have failed !\n");
3824 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3825 printf("close - 1 failed (%s)\n", cli_errstr(cli1
));
3829 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3830 cli_unlink(cli1
, fname1
, aSYSTEM
| aHIDDEN
);
3831 status
= cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3833 FILE_SHARE_DELETE
|FILE_SHARE_NONE
,
3835 FILE_SHARE_DELETE
|FILE_SHARE_READ
,
3837 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
3838 if (!NT_STATUS_IS_OK(status
)) {
3839 printf("Second open failed - %s\n", cli_errstr(cli1
));
3843 if (!NT_STATUS_IS_OK(cli_rename(cli1
, fname
, fname1
))) {
3844 printf("Second rename failed (SHARE_DELETE | SHARE_READ) - this should have succeeded - %s\n", cli_errstr(cli1
));
3847 printf("Second rename succeeded (SHARE_DELETE | SHARE_READ)\n");
3850 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3851 printf("close - 2 failed (%s)\n", cli_errstr(cli1
));
3855 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3856 cli_unlink(cli1
, fname1
, aSYSTEM
| aHIDDEN
);
3858 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, READ_CONTROL_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3859 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
3860 printf("Third open failed - %s\n", cli_errstr(cli1
));
3869 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, DELETE_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3870 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0, &fnum2
))) {
3871 printf("Fourth open failed - %s\n", cli_errstr(cli1
));
3874 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum2
, true))) {
3875 printf("[8] setting delete_on_close on file failed !\n");
3879 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum2
))) {
3880 printf("close - 4 failed (%s)\n", cli_errstr(cli1
));
3886 if (!NT_STATUS_IS_OK(cli_rename(cli1
, fname
, fname1
))) {
3887 printf("Third rename failed (SHARE_NONE) - this should have succeeded - %s\n", cli_errstr(cli1
));
3890 printf("Third rename succeeded (SHARE_NONE)\n");
3893 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3894 printf("close - 3 failed (%s)\n", cli_errstr(cli1
));
3898 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3899 cli_unlink(cli1
, fname1
, aSYSTEM
| aHIDDEN
);
3903 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3904 FILE_SHARE_READ
| FILE_SHARE_WRITE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
3905 printf("Fourth open failed - %s\n", cli_errstr(cli1
));
3909 if (!NT_STATUS_IS_OK(cli_rename(cli1
, fname
, fname1
))) {
3910 printf("Fourth rename failed (SHARE_READ | SHARE_WRITE) (this is correct) - %s\n", cli_errstr(cli1
));
3912 printf("Fourth rename succeeded (SHARE_READ | SHARE_WRITE) - this should have failed !\n");
3916 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3917 printf("close - 4 failed (%s)\n", cli_errstr(cli1
));
3921 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3922 cli_unlink(cli1
, fname1
, aSYSTEM
| aHIDDEN
);
3926 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3927 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
3928 printf("Fifth open failed - %s\n", cli_errstr(cli1
));
3932 if (!NT_STATUS_IS_OK(cli_rename(cli1
, fname
, fname1
))) {
3933 printf("Fifth rename failed (SHARE_READ | SHARE_WRITE | SHARE_DELETE) - this should have succeeded - %s ! \n",
3937 printf("Fifth rename succeeded (SHARE_READ | SHARE_WRITE | SHARE_DELETE) (this is correct) - %s\n", cli_errstr(cli1
));
3941 * Now check if the first name still exists ...
3944 /* if (!NT_STATUS_OP(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3945 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0, &fnum2))) {
3946 printf("Opening original file after rename of open file fails: %s\n",
3950 printf("Opening original file after rename of open file works ...\n");
3951 (void)cli_close(cli1, fnum2);
3955 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3956 printf("close - 5 failed (%s)\n", cli_errstr(cli1
));
3960 /* Check that the renamed file has FILE_ATTRIBUTE_ARCHIVE. */
3961 if (!NT_STATUS_IS_OK(cli_getatr(cli1
, fname1
, &attr
, NULL
, NULL
))) {
3962 printf("getatr on file %s failed - %s ! \n",
3967 if (attr
!= FILE_ATTRIBUTE_ARCHIVE
) {
3968 printf("Renamed file %s has wrong attr 0x%x "
3969 "(should be 0x%x)\n",
3972 (unsigned int)FILE_ATTRIBUTE_ARCHIVE
);
3975 printf("Renamed file %s has archive bit set\n", fname1
);
3979 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3980 cli_unlink(cli1
, fname1
, aSYSTEM
| aHIDDEN
);
3982 if (!torture_close_connection(cli1
)) {
3989 static bool run_pipe_number(int dummy
)
3991 struct cli_state
*cli1
;
3992 const char *pipe_name
= "\\SPOOLSS";
3996 printf("starting pipenumber test\n");
3997 if (!torture_open_connection(&cli1
, 0)) {
4001 cli_sockopt(cli1
, sockops
);
4003 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, pipe_name
, 0, FILE_READ_DATA
, FILE_ATTRIBUTE_NORMAL
,
4004 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN_IF
, 0, 0, &fnum
))) {
4005 printf("Open of pipe %s failed with error (%s)\n", pipe_name
, cli_errstr(cli1
));
4009 printf("\r%6d", num_pipes
);
4012 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes
, pipe_name
);
4013 torture_close_connection(cli1
);
4018 Test open mode returns on read-only files.
4020 static bool run_opentest(int dummy
)
4022 static struct cli_state
*cli1
;
4023 static struct cli_state
*cli2
;
4024 const char *fname
= "\\readonly.file";
4025 uint16_t fnum1
, fnum2
;
4028 bool correct
= True
;
4031 printf("starting open test\n");
4033 if (!torture_open_connection(&cli1
, 0)) {
4037 cli_setatr(cli1
, fname
, 0, 0);
4038 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
4040 cli_sockopt(cli1
, sockops
);
4042 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
))) {
4043 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4047 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4048 printf("close2 failed (%s)\n", cli_errstr(cli1
));
4052 if (!NT_STATUS_IS_OK(cli_setatr(cli1
, fname
, aRONLY
, 0))) {
4053 printf("cli_setatr failed (%s)\n", cli_errstr(cli1
));
4057 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDONLY
, DENY_WRITE
, &fnum1
))) {
4058 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4062 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
4063 cli_open(cli1
, fname
, O_RDWR
, DENY_ALL
, &fnum2
);
4065 if (check_error(__LINE__
, cli1
, ERRDOS
, ERRnoaccess
,
4066 NT_STATUS_ACCESS_DENIED
)) {
4067 printf("correct error code ERRDOS/ERRnoaccess returned\n");
4070 printf("finished open test 1\n");
4072 cli_close(cli1
, fnum1
);
4074 /* Now try not readonly and ensure ERRbadshare is returned. */
4076 cli_setatr(cli1
, fname
, 0, 0);
4078 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDONLY
, DENY_WRITE
, &fnum1
))) {
4079 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4083 /* This will fail - but the error should be ERRshare. */
4084 cli_open(cli1
, fname
, O_RDWR
, DENY_ALL
, &fnum2
);
4086 if (check_error(__LINE__
, cli1
, ERRDOS
, ERRbadshare
,
4087 NT_STATUS_SHARING_VIOLATION
)) {
4088 printf("correct error code ERRDOS/ERRbadshare returned\n");
4091 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4092 printf("close2 failed (%s)\n", cli_errstr(cli1
));
4096 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
4098 printf("finished open test 2\n");
4100 /* Test truncate open disposition on file opened for read. */
4102 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
))) {
4103 printf("(3) open (1) of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4107 /* write 20 bytes. */
4109 memset(buf
, '\0', 20);
4111 if (cli_write(cli1
, fnum1
, 0, buf
, 0, 20) != 20) {
4112 printf("write failed (%s)\n", cli_errstr(cli1
));
4116 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4117 printf("(3) close1 failed (%s)\n", cli_errstr(cli1
));
4121 /* Ensure size == 20. */
4122 if (!NT_STATUS_IS_OK(cli_getatr(cli1
, fname
, NULL
, &fsize
, NULL
))) {
4123 printf("(3) getatr failed (%s)\n", cli_errstr(cli1
));
4128 printf("(3) file size != 20\n");
4132 /* Now test if we can truncate a file opened for readonly. */
4134 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDONLY
|O_TRUNC
, DENY_NONE
, &fnum1
))) {
4135 printf("(3) open (2) of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4139 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4140 printf("close2 failed (%s)\n", cli_errstr(cli1
));
4144 /* Ensure size == 0. */
4145 if (!NT_STATUS_IS_OK(cli_getatr(cli1
, fname
, NULL
, &fsize
, NULL
))) {
4146 printf("(3) getatr failed (%s)\n", cli_errstr(cli1
));
4151 printf("(3) file size != 0\n");
4154 printf("finished open test 3\n");
4156 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
4159 printf("testing ctemp\n");
4160 if (!NT_STATUS_IS_OK(cli_ctemp(cli1
, talloc_tos(), "\\", &fnum1
, &tmp_path
))) {
4161 printf("ctemp failed (%s)\n", cli_errstr(cli1
));
4164 printf("ctemp gave path %s\n", tmp_path
);
4165 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4166 printf("close of temp failed (%s)\n", cli_errstr(cli1
));
4168 if (!NT_STATUS_IS_OK(cli_unlink(cli1
, tmp_path
, aSYSTEM
| aHIDDEN
))) {
4169 printf("unlink of temp failed (%s)\n", cli_errstr(cli1
));
4172 /* Test the non-io opens... */
4174 if (!torture_open_connection(&cli2
, 1)) {
4178 cli_setatr(cli2
, fname
, 0, 0);
4179 cli_unlink(cli2
, fname
, aSYSTEM
| aHIDDEN
);
4181 cli_sockopt(cli2
, sockops
);
4183 printf("TEST #1 testing 2 non-io opens (no delete)\n");
4185 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4186 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
4187 printf("test 1 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4191 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2
, fname
, 0, FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4192 FILE_SHARE_NONE
, FILE_OPEN_IF
, 0, 0, &fnum2
))) {
4193 printf("test 1 open 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
4197 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4198 printf("test 1 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4201 if (!NT_STATUS_IS_OK(cli_close(cli2
, fnum2
))) {
4202 printf("test 1 close 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
4206 printf("non-io open test #1 passed.\n");
4208 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
4210 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
4212 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4213 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
4214 printf("test 2 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4218 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2
, fname
, 0, FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4219 FILE_SHARE_NONE
, FILE_OPEN_IF
, 0, 0, &fnum2
))) {
4220 printf("test 2 open 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
4224 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4225 printf("test 1 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4228 if (!NT_STATUS_IS_OK(cli_close(cli2
, fnum2
))) {
4229 printf("test 1 close 2 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4233 printf("non-io open test #2 passed.\n");
4235 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
4237 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
4239 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4240 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
4241 printf("test 3 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4245 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4246 FILE_SHARE_NONE
, FILE_OPEN_IF
, 0, 0, &fnum2
))) {
4247 printf("test 3 open 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
4251 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4252 printf("test 3 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4255 if (!NT_STATUS_IS_OK(cli_close(cli2
, fnum2
))) {
4256 printf("test 3 close 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
4260 printf("non-io open test #3 passed.\n");
4262 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
4264 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
4266 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4267 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
4268 printf("test 4 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4272 if (NT_STATUS_IS_OK(cli_ntcreate(cli2
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4273 FILE_SHARE_NONE
, FILE_OPEN_IF
, 0, 0, &fnum2
))) {
4274 printf("test 4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname
, cli_errstr(cli2
));
4278 printf("test 3 open 2 of %s gave %s (correct error should be %s)\n", fname
, cli_errstr(cli2
), "sharing violation");
4280 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4281 printf("test 4 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4285 printf("non-io open test #4 passed.\n");
4287 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
4289 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
4291 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4292 FILE_SHARE_DELETE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
4293 printf("test 5 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4297 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4298 FILE_SHARE_DELETE
, FILE_OPEN_IF
, 0, 0, &fnum2
))) {
4299 printf("test 5 open 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
4303 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4304 printf("test 5 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4308 if (!NT_STATUS_IS_OK(cli_close(cli2
, fnum2
))) {
4309 printf("test 5 close 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
4313 printf("non-io open test #5 passed.\n");
4315 printf("TEST #6 testing 1 non-io open, one io open\n");
4317 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
4319 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
, FILE_ATTRIBUTE_NORMAL
,
4320 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
4321 printf("test 6 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4325 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2
, fname
, 0, FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4326 FILE_SHARE_READ
, FILE_OPEN_IF
, 0, 0, &fnum2
))) {
4327 printf("test 6 open 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
4331 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4332 printf("test 6 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4336 if (!NT_STATUS_IS_OK(cli_close(cli2
, fnum2
))) {
4337 printf("test 6 close 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
4341 printf("non-io open test #6 passed.\n");
4343 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
4345 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
4347 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
, FILE_ATTRIBUTE_NORMAL
,
4348 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
4349 printf("test 7 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4353 if (NT_STATUS_IS_OK(cli_ntcreate(cli2
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4354 FILE_SHARE_READ
|FILE_SHARE_DELETE
, FILE_OPEN_IF
, 0, 0, &fnum2
))) {
4355 printf("test 7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname
, cli_errstr(cli2
));
4359 printf("test 7 open 2 of %s gave %s (correct error should be %s)\n", fname
, cli_errstr(cli2
), "sharing violation");
4361 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4362 printf("test 7 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4366 printf("non-io open test #7 passed.\n");
4368 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
4370 if (!torture_close_connection(cli1
)) {
4373 if (!torture_close_connection(cli2
)) {
4380 NTSTATUS
torture_setup_unix_extensions(struct cli_state
*cli
)
4382 uint16 major
, minor
;
4383 uint32 caplow
, caphigh
;
4386 if (!SERVER_HAS_UNIX_CIFS(cli
)) {
4387 printf("Server doesn't support UNIX CIFS extensions.\n");
4388 return NT_STATUS_NOT_SUPPORTED
;
4391 status
= cli_unix_extensions_version(cli
, &major
, &minor
, &caplow
,
4393 if (!NT_STATUS_IS_OK(status
)) {
4394 printf("Server didn't return UNIX CIFS extensions: %s\n",
4399 status
= cli_set_unix_extensions_capabilities(cli
, major
, minor
,
4401 if (!NT_STATUS_IS_OK(status
)) {
4402 printf("Server doesn't support setting UNIX CIFS extensions: "
4403 "%s.\n", nt_errstr(status
));
4407 return NT_STATUS_OK
;
4411 Test POSIX open /mkdir calls.
4413 static bool run_simple_posix_open_test(int dummy
)
4415 static struct cli_state
*cli1
;
4416 const char *fname
= "posix:file";
4417 const char *hname
= "posix:hlink";
4418 const char *sname
= "posix:symlink";
4419 const char *dname
= "posix:dir";
4422 uint16_t fnum1
= (uint16_t)-1;
4423 SMB_STRUCT_STAT sbuf
;
4424 bool correct
= false;
4427 printf("Starting simple POSIX open test\n");
4429 if (!torture_open_connection(&cli1
, 0)) {
4433 cli_sockopt(cli1
, sockops
);
4435 status
= torture_setup_unix_extensions(cli1
);
4436 if (!NT_STATUS_IS_OK(status
)) {
4440 cli_setatr(cli1
, fname
, 0, 0);
4441 cli_posix_unlink(cli1
, fname
);
4442 cli_setatr(cli1
, dname
, 0, 0);
4443 cli_posix_rmdir(cli1
, dname
);
4444 cli_setatr(cli1
, hname
, 0, 0);
4445 cli_posix_unlink(cli1
, hname
);
4446 cli_setatr(cli1
, sname
, 0, 0);
4447 cli_posix_unlink(cli1
, sname
);
4449 /* Create a directory. */
4450 if (!NT_STATUS_IS_OK(cli_posix_mkdir(cli1
, dname
, 0777))) {
4451 printf("POSIX mkdir of %s failed (%s)\n", dname
, cli_errstr(cli1
));
4455 if (!NT_STATUS_IS_OK(cli_posix_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, 0600, &fnum1
))) {
4456 printf("POSIX create of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4460 /* Test ftruncate - set file size. */
4461 if (!NT_STATUS_IS_OK(cli_ftruncate(cli1
, fnum1
, 1000))) {
4462 printf("ftruncate failed (%s)\n", cli_errstr(cli1
));
4466 /* Ensure st_size == 1000 */
4467 if (!NT_STATUS_IS_OK(cli_posix_stat(cli1
, fname
, &sbuf
))) {
4468 printf("stat failed (%s)\n", cli_errstr(cli1
));
4472 if (sbuf
.st_ex_size
!= 1000) {
4473 printf("ftruncate - stat size (%u) != 1000\n", (unsigned int)sbuf
.st_ex_size
);
4477 /* Test ftruncate - set file size back to zero. */
4478 if (!NT_STATUS_IS_OK(cli_ftruncate(cli1
, fnum1
, 0))) {
4479 printf("ftruncate failed (%s)\n", cli_errstr(cli1
));
4483 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4484 printf("close failed (%s)\n", cli_errstr(cli1
));
4488 /* Now open the file again for read only. */
4489 if (!NT_STATUS_IS_OK(cli_posix_open(cli1
, fname
, O_RDONLY
, 0, &fnum1
))) {
4490 printf("POSIX open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4494 /* Now unlink while open. */
4495 if (!NT_STATUS_IS_OK(cli_posix_unlink(cli1
, fname
))) {
4496 printf("POSIX unlink of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4500 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4501 printf("close(2) failed (%s)\n", cli_errstr(cli1
));
4505 /* Ensure the file has gone. */
4506 if (NT_STATUS_IS_OK(cli_posix_open(cli1
, fname
, O_RDONLY
, 0, &fnum1
))) {
4507 printf("POSIX open of %s succeeded, should have been deleted.\n", fname
);
4511 /* What happens when we try and POSIX open a directory ? */
4512 if (NT_STATUS_IS_OK(cli_posix_open(cli1
, dname
, O_RDONLY
, 0, &fnum1
))) {
4513 printf("POSIX open of directory %s succeeded, should have failed.\n", fname
);
4516 if (!check_error(__LINE__
, cli1
, ERRDOS
, EISDIR
,
4517 NT_STATUS_FILE_IS_A_DIRECTORY
)) {
4522 /* Create the file. */
4523 if (!NT_STATUS_IS_OK(cli_posix_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, 0600, &fnum1
))) {
4524 printf("POSIX create of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4528 /* Write some data into it. */
4529 if (cli_write(cli1
, fnum1
, 0, "TEST DATA\n", 0, 10) != 10) {
4530 printf("cli_write failed: %s\n", cli_errstr(cli1
));
4534 cli_close(cli1
, fnum1
);
4536 /* Now create a hardlink. */
4537 if (!NT_STATUS_IS_OK(cli_posix_hardlink(cli1
, fname
, hname
))) {
4538 printf("POSIX hardlink of %s failed (%s)\n", hname
, cli_errstr(cli1
));
4542 /* Now create a symlink. */
4543 if (!NT_STATUS_IS_OK(cli_posix_symlink(cli1
, fname
, sname
))) {
4544 printf("POSIX symlink of %s failed (%s)\n", sname
, cli_errstr(cli1
));
4548 /* Open the hardlink for read. */
4549 if (!NT_STATUS_IS_OK(cli_posix_open(cli1
, hname
, O_RDONLY
, 0, &fnum1
))) {
4550 printf("POSIX open of %s failed (%s)\n", hname
, cli_errstr(cli1
));
4554 if (cli_read(cli1
, fnum1
, buf
, 0, 10) != 10) {
4555 printf("POSIX read of %s failed (%s)\n", hname
, cli_errstr(cli1
));
4559 if (memcmp(buf
, "TEST DATA\n", 10)) {
4560 printf("invalid data read from hardlink\n");
4564 /* Do a POSIX lock/unlock. */
4565 if (!NT_STATUS_IS_OK(cli_posix_lock(cli1
, fnum1
, 0, 100, true, READ_LOCK
))) {
4566 printf("POSIX lock failed %s\n", cli_errstr(cli1
));
4570 /* Punch a hole in the locked area. */
4571 if (!NT_STATUS_IS_OK(cli_posix_unlock(cli1
, fnum1
, 10, 80))) {
4572 printf("POSIX unlock failed %s\n", cli_errstr(cli1
));
4576 cli_close(cli1
, fnum1
);
4578 /* Open the symlink for read - this should fail. A POSIX
4579 client should not be doing opens on a symlink. */
4580 if (NT_STATUS_IS_OK(cli_posix_open(cli1
, sname
, O_RDONLY
, 0, &fnum1
))) {
4581 printf("POSIX open of %s succeeded (should have failed)\n", sname
);
4584 if (!check_error(__LINE__
, cli1
, ERRDOS
, ERRbadpath
,
4585 NT_STATUS_OBJECT_PATH_NOT_FOUND
)) {
4586 printf("POSIX open of %s should have failed "
4587 "with NT_STATUS_OBJECT_PATH_NOT_FOUND, "
4588 "failed with %s instead.\n",
4589 sname
, cli_errstr(cli1
));
4594 if (!NT_STATUS_IS_OK(cli_posix_readlink(cli1
, sname
, namebuf
, sizeof(namebuf
)))) {
4595 printf("POSIX readlink on %s failed (%s)\n", sname
, cli_errstr(cli1
));
4599 if (strcmp(namebuf
, fname
) != 0) {
4600 printf("POSIX readlink on %s failed to match name %s (read %s)\n",
4601 sname
, fname
, namebuf
);
4605 if (!NT_STATUS_IS_OK(cli_posix_rmdir(cli1
, dname
))) {
4606 printf("POSIX rmdir failed (%s)\n", cli_errstr(cli1
));
4610 printf("Simple POSIX open test passed\n");
4615 if (fnum1
!= (uint16_t)-1) {
4616 cli_close(cli1
, fnum1
);
4617 fnum1
= (uint16_t)-1;
4620 cli_setatr(cli1
, sname
, 0, 0);
4621 cli_posix_unlink(cli1
, sname
);
4622 cli_setatr(cli1
, hname
, 0, 0);
4623 cli_posix_unlink(cli1
, hname
);
4624 cli_setatr(cli1
, fname
, 0, 0);
4625 cli_posix_unlink(cli1
, fname
);
4626 cli_setatr(cli1
, dname
, 0, 0);
4627 cli_posix_rmdir(cli1
, dname
);
4629 if (!torture_close_connection(cli1
)) {
4637 static uint32 open_attrs_table
[] = {
4638 FILE_ATTRIBUTE_NORMAL
,
4639 FILE_ATTRIBUTE_ARCHIVE
,
4640 FILE_ATTRIBUTE_READONLY
,
4641 FILE_ATTRIBUTE_HIDDEN
,
4642 FILE_ATTRIBUTE_SYSTEM
,
4644 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
,
4645 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
,
4646 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
,
4647 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
,
4648 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
,
4649 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
,
4651 FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
,
4652 FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
,
4653 FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
,
4654 FILE_ATTRIBUTE_HIDDEN
,FILE_ATTRIBUTE_SYSTEM
,
4657 struct trunc_open_results
{
4664 static struct trunc_open_results attr_results
[] = {
4665 { 0, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_ARCHIVE
},
4666 { 1, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_ARCHIVE
},
4667 { 2, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_READONLY
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
},
4668 { 16, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_ARCHIVE
},
4669 { 17, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_ARCHIVE
},
4670 { 18, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_READONLY
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
},
4671 { 51, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
4672 { 54, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
4673 { 56, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
},
4674 { 68, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
4675 { 71, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
4676 { 73, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
},
4677 { 99, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_HIDDEN
,FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
4678 { 102, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
4679 { 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
},
4680 { 116, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
4681 { 119, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
4682 { 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
},
4683 { 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
},
4684 { 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
},
4685 { 227, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
4686 { 230, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
4687 { 232, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
},
4688 { 244, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
4689 { 247, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
4690 { 249, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
}
4693 static bool run_openattrtest(int dummy
)
4695 static struct cli_state
*cli1
;
4696 const char *fname
= "\\openattr.file";
4698 bool correct
= True
;
4700 unsigned int i
, j
, k
, l
;
4702 printf("starting open attr test\n");
4704 if (!torture_open_connection(&cli1
, 0)) {
4708 cli_sockopt(cli1
, sockops
);
4710 for (k
= 0, i
= 0; i
< sizeof(open_attrs_table
)/sizeof(uint32
); i
++) {
4711 cli_setatr(cli1
, fname
, 0, 0);
4712 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
4713 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_WRITE_DATA
, open_attrs_table
[i
],
4714 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
4715 printf("open %d (1) of %s failed (%s)\n", i
, fname
, cli_errstr(cli1
));
4719 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4720 printf("close %d (1) of %s failed (%s)\n", i
, fname
, cli_errstr(cli1
));
4724 for (j
= 0; j
< sizeof(open_attrs_table
)/sizeof(uint32
); j
++) {
4725 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
, open_attrs_table
[j
],
4726 FILE_SHARE_NONE
, FILE_OVERWRITE
, 0, 0, &fnum1
))) {
4727 for (l
= 0; l
< sizeof(attr_results
)/sizeof(struct trunc_open_results
); l
++) {
4728 if (attr_results
[l
].num
== k
) {
4729 printf("[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(0x%x:%s)\n",
4730 k
, open_attrs_table
[i
],
4731 open_attrs_table
[j
],
4732 fname
, NT_STATUS_V(cli_nt_error(cli1
)), cli_errstr(cli1
));
4736 if (NT_STATUS_V(cli_nt_error(cli1
)) != NT_STATUS_V(NT_STATUS_ACCESS_DENIED
)) {
4737 printf("[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s\n",
4738 k
, open_attrs_table
[i
], open_attrs_table
[j
],
4743 printf("[%d] trunc open 0x%x -> 0x%x failed\n", k
, open_attrs_table
[i
], open_attrs_table
[j
]);
4749 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4750 printf("close %d (2) of %s failed (%s)\n", j
, fname
, cli_errstr(cli1
));
4754 if (!NT_STATUS_IS_OK(cli_getatr(cli1
, fname
, &attr
, NULL
, NULL
))) {
4755 printf("getatr(2) failed (%s)\n", cli_errstr(cli1
));
4760 printf("[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n",
4761 k
, open_attrs_table
[i
], open_attrs_table
[j
], attr
);
4764 for (l
= 0; l
< sizeof(attr_results
)/sizeof(struct trunc_open_results
); l
++) {
4765 if (attr_results
[l
].num
== k
) {
4766 if (attr
!= attr_results
[l
].result_attr
||
4767 open_attrs_table
[i
] != attr_results
[l
].init_attr
||
4768 open_attrs_table
[j
] != attr_results
[l
].trunc_attr
) {
4769 printf("getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x\n",
4770 open_attrs_table
[i
],
4771 open_attrs_table
[j
],
4773 attr_results
[l
].result_attr
);
4783 cli_setatr(cli1
, fname
, 0, 0);
4784 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
4786 printf("open attr test %s.\n", correct
? "passed" : "failed");
4788 if (!torture_close_connection(cli1
)) {
4794 static void list_fn(const char *mnt
, file_info
*finfo
, const char *name
, void *state
)
4800 test directory listing speed
4802 static bool run_dirtest(int dummy
)
4805 static struct cli_state
*cli
;
4807 struct timeval core_start
;
4808 bool correct
= True
;
4810 printf("starting directory test\n");
4812 if (!torture_open_connection(&cli
, 0)) {
4816 cli_sockopt(cli
, sockops
);
4819 for (i
=0;i
<torture_numops
;i
++) {
4821 slprintf(fname
, sizeof(fname
), "\\%x", (int)random());
4822 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
, O_RDWR
|O_CREAT
, DENY_NONE
, &fnum
))) {
4823 fprintf(stderr
,"Failed to open %s\n", fname
);
4826 cli_close(cli
, fnum
);
4829 core_start
= timeval_current();
4831 printf("Matched %d\n", cli_list(cli
, "a*.*", 0, list_fn
, NULL
));
4832 printf("Matched %d\n", cli_list(cli
, "b*.*", 0, list_fn
, NULL
));
4833 printf("Matched %d\n", cli_list(cli
, "xyzabc", 0, list_fn
, NULL
));
4835 printf("dirtest core %g seconds\n", timeval_elapsed(&core_start
));
4838 for (i
=0;i
<torture_numops
;i
++) {
4840 slprintf(fname
, sizeof(fname
), "\\%x", (int)random());
4841 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
4844 if (!torture_close_connection(cli
)) {
4848 printf("finished dirtest\n");
4853 static void del_fn(const char *mnt
, file_info
*finfo
, const char *mask
, void *state
)
4855 struct cli_state
*pcli
= (struct cli_state
*)state
;
4857 slprintf(fname
, sizeof(fname
), "\\LISTDIR\\%s", finfo
->name
);
4859 if (strcmp(finfo
->name
, ".") == 0 || strcmp(finfo
->name
, "..") == 0)
4862 if (finfo
->mode
& aDIR
) {
4863 if (!NT_STATUS_IS_OK(cli_rmdir(pcli
, fname
)))
4864 printf("del_fn: failed to rmdir %s\n,", fname
);
4866 if (!NT_STATUS_IS_OK(cli_unlink(pcli
, fname
, aSYSTEM
| aHIDDEN
)))
4867 printf("del_fn: failed to unlink %s\n,", fname
);
4873 sees what IOCTLs are supported
4875 bool torture_ioctl_test(int dummy
)
4877 static struct cli_state
*cli
;
4878 uint16_t device
, function
;
4880 const char *fname
= "\\ioctl.dat";
4884 if (!torture_open_connection(&cli
, 0)) {
4888 printf("starting ioctl test\n");
4890 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
4892 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum
))) {
4893 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
4897 status
= cli_raw_ioctl(cli
, fnum
, 0x2d0000 | (0x0420<<2), &blob
);
4898 printf("ioctl device info: %s\n", nt_errstr(status
));
4900 status
= cli_raw_ioctl(cli
, fnum
, IOCTL_QUERY_JOB_INFO
, &blob
);
4901 printf("ioctl job info: %s\n", nt_errstr(status
));
4903 for (device
=0;device
<0x100;device
++) {
4904 printf("testing device=0x%x\n", device
);
4905 for (function
=0;function
<0x100;function
++) {
4906 uint32 code
= (device
<<16) | function
;
4908 status
= cli_raw_ioctl(cli
, fnum
, code
, &blob
);
4910 if (NT_STATUS_IS_OK(status
)) {
4911 printf("ioctl 0x%x OK : %d bytes\n", (int)code
,
4913 data_blob_free(&blob
);
4918 if (!torture_close_connection(cli
)) {
4927 tries varients of chkpath
4929 bool torture_chkpath_test(int dummy
)
4931 static struct cli_state
*cli
;
4935 if (!torture_open_connection(&cli
, 0)) {
4939 printf("starting chkpath test\n");
4941 /* cleanup from an old run */
4942 cli_rmdir(cli
, "\\chkpath.dir\\dir2");
4943 cli_unlink(cli
, "\\chkpath.dir\\*", aSYSTEM
| aHIDDEN
);
4944 cli_rmdir(cli
, "\\chkpath.dir");
4946 if (!NT_STATUS_IS_OK(cli_mkdir(cli
, "\\chkpath.dir"))) {
4947 printf("mkdir1 failed : %s\n", cli_errstr(cli
));
4951 if (!NT_STATUS_IS_OK(cli_mkdir(cli
, "\\chkpath.dir\\dir2"))) {
4952 printf("mkdir2 failed : %s\n", cli_errstr(cli
));
4956 if (!NT_STATUS_IS_OK(cli_open(cli
, "\\chkpath.dir\\foo.txt", O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum
))) {
4957 printf("open1 failed (%s)\n", cli_errstr(cli
));
4960 cli_close(cli
, fnum
);
4962 if (!NT_STATUS_IS_OK(cli_chkpath(cli
, "\\chkpath.dir"))) {
4963 printf("chkpath1 failed: %s\n", cli_errstr(cli
));
4967 if (!NT_STATUS_IS_OK(cli_chkpath(cli
, "\\chkpath.dir\\dir2"))) {
4968 printf("chkpath2 failed: %s\n", cli_errstr(cli
));
4972 if (!NT_STATUS_IS_OK(cli_chkpath(cli
, "\\chkpath.dir\\foo.txt"))) {
4973 ret
= check_error(__LINE__
, cli
, ERRDOS
, ERRbadpath
,
4974 NT_STATUS_NOT_A_DIRECTORY
);
4976 printf("* chkpath on a file should fail\n");
4980 if (!NT_STATUS_IS_OK(cli_chkpath(cli
, "\\chkpath.dir\\bar.txt"))) {
4981 ret
= check_error(__LINE__
, cli
, ERRDOS
, ERRbadfile
,
4982 NT_STATUS_OBJECT_NAME_NOT_FOUND
);
4984 printf("* chkpath on a non existant file should fail\n");
4988 if (!NT_STATUS_IS_OK(cli_chkpath(cli
, "\\chkpath.dir\\dirxx\\bar.txt"))) {
4989 ret
= check_error(__LINE__
, cli
, ERRDOS
, ERRbadpath
,
4990 NT_STATUS_OBJECT_PATH_NOT_FOUND
);
4992 printf("* chkpath on a non existent component should fail\n");
4996 cli_rmdir(cli
, "\\chkpath.dir\\dir2");
4997 cli_unlink(cli
, "\\chkpath.dir\\*", aSYSTEM
| aHIDDEN
);
4998 cli_rmdir(cli
, "\\chkpath.dir");
5000 if (!torture_close_connection(cli
)) {
5007 static bool run_eatest(int dummy
)
5009 static struct cli_state
*cli
;
5010 const char *fname
= "\\eatest.txt";
5011 bool correct
= True
;
5015 struct ea_struct
*ea_list
= NULL
;
5016 TALLOC_CTX
*mem_ctx
= talloc_init("eatest");
5019 printf("starting eatest\n");
5021 if (!torture_open_connection(&cli
, 0)) {
5022 talloc_destroy(mem_ctx
);
5026 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
5027 if (!NT_STATUS_IS_OK(cli_ntcreate(cli
, fname
, 0,
5028 FIRST_DESIRED_ACCESS
, FILE_ATTRIBUTE_ARCHIVE
,
5029 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
,
5030 0x4044, 0, &fnum
))) {
5031 printf("open failed - %s\n", cli_errstr(cli
));
5032 talloc_destroy(mem_ctx
);
5036 for (i
= 0; i
< 10; i
++) {
5037 fstring ea_name
, ea_val
;
5039 slprintf(ea_name
, sizeof(ea_name
), "EA_%d", i
);
5040 memset(ea_val
, (char)i
+1, i
+1);
5041 if (!cli_set_ea_fnum(cli
, fnum
, ea_name
, ea_val
, i
+1)) {
5042 printf("ea_set of name %s failed - %s\n", ea_name
, cli_errstr(cli
));
5043 talloc_destroy(mem_ctx
);
5048 cli_close(cli
, fnum
);
5049 for (i
= 0; i
< 10; i
++) {
5050 fstring ea_name
, ea_val
;
5052 slprintf(ea_name
, sizeof(ea_name
), "EA_%d", i
+10);
5053 memset(ea_val
, (char)i
+1, i
+1);
5054 if (!cli_set_ea_path(cli
, fname
, ea_name
, ea_val
, i
+1)) {
5055 printf("ea_set of name %s failed - %s\n", ea_name
, cli_errstr(cli
));
5056 talloc_destroy(mem_ctx
);
5061 status
= cli_get_ea_list_path(cli
, fname
, mem_ctx
, &num_eas
, &ea_list
);
5062 if (!NT_STATUS_IS_OK(status
)) {
5063 printf("ea_get list failed - %s\n", nt_errstr(status
));
5067 printf("num_eas = %d\n", (int)num_eas
);
5069 if (num_eas
!= 20) {
5070 printf("Should be 20 EA's stored... failing.\n");
5074 for (i
= 0; i
< num_eas
; i
++) {
5075 printf("%d: ea_name = %s. Val = ", i
, ea_list
[i
].name
);
5076 dump_data(0, ea_list
[i
].value
.data
,
5077 ea_list
[i
].value
.length
);
5080 /* Setting EA's to zero length deletes them. Test this */
5081 printf("Now deleting all EA's - case indepenent....\n");
5084 cli_set_ea_path(cli
, fname
, "", "", 0);
5086 for (i
= 0; i
< 20; i
++) {
5088 slprintf(ea_name
, sizeof(ea_name
), "ea_%d", i
);
5089 if (!cli_set_ea_path(cli
, fname
, ea_name
, "", 0)) {
5090 printf("ea_set of name %s failed - %s\n", ea_name
, cli_errstr(cli
));
5091 talloc_destroy(mem_ctx
);
5097 status
= cli_get_ea_list_path(cli
, fname
, mem_ctx
, &num_eas
, &ea_list
);
5098 if (!NT_STATUS_IS_OK(status
)) {
5099 printf("ea_get list failed - %s\n", nt_errstr(status
));
5103 printf("num_eas = %d\n", (int)num_eas
);
5104 for (i
= 0; i
< num_eas
; i
++) {
5105 printf("%d: ea_name = %s. Val = ", i
, ea_list
[i
].name
);
5106 dump_data(0, ea_list
[i
].value
.data
,
5107 ea_list
[i
].value
.length
);
5111 printf("deleting EA's failed.\n");
5115 /* Try and delete a non existant EA. */
5116 if (!cli_set_ea_path(cli
, fname
, "foo", "", 0)) {
5117 printf("deleting non-existant EA 'foo' should succeed. %s\n", cli_errstr(cli
));
5121 talloc_destroy(mem_ctx
);
5122 if (!torture_close_connection(cli
)) {
5129 static bool run_dirtest1(int dummy
)
5132 static struct cli_state
*cli
;
5135 bool correct
= True
;
5137 printf("starting directory test\n");
5139 if (!torture_open_connection(&cli
, 0)) {
5143 cli_sockopt(cli
, sockops
);
5145 cli_list(cli
, "\\LISTDIR\\*", 0, del_fn
, cli
);
5146 cli_list(cli
, "\\LISTDIR\\*", aDIR
, del_fn
, cli
);
5147 cli_rmdir(cli
, "\\LISTDIR");
5148 cli_mkdir(cli
, "\\LISTDIR");
5150 /* Create 1000 files and 1000 directories. */
5151 for (i
=0;i
<1000;i
++) {
5153 slprintf(fname
, sizeof(fname
), "\\LISTDIR\\f%d", i
);
5154 if (!NT_STATUS_IS_OK(cli_ntcreate(cli
, fname
, 0, GENERIC_ALL_ACCESS
, FILE_ATTRIBUTE_ARCHIVE
,
5155 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OVERWRITE_IF
, 0, 0, &fnum
))) {
5156 fprintf(stderr
,"Failed to open %s\n", fname
);
5159 cli_close(cli
, fnum
);
5161 for (i
=0;i
<1000;i
++) {
5163 slprintf(fname
, sizeof(fname
), "\\LISTDIR\\d%d", i
);
5164 if (!NT_STATUS_IS_OK(cli_mkdir(cli
, fname
))) {
5165 fprintf(stderr
,"Failed to open %s\n", fname
);
5170 /* Now ensure that doing an old list sees both files and directories. */
5171 num_seen
= cli_list_old(cli
, "\\LISTDIR\\*", aDIR
, list_fn
, NULL
);
5172 printf("num_seen = %d\n", num_seen
);
5173 /* We should see 100 files + 1000 directories + . and .. */
5174 if (num_seen
!= 2002)
5177 /* Ensure if we have the "must have" bits we only see the
5180 num_seen
= cli_list_old(cli
, "\\LISTDIR\\*", (aDIR
<<8)|aDIR
, list_fn
, NULL
);
5181 printf("num_seen = %d\n", num_seen
);
5182 if (num_seen
!= 1002)
5185 num_seen
= cli_list_old(cli
, "\\LISTDIR\\*", (aARCH
<<8)|aDIR
, list_fn
, NULL
);
5186 printf("num_seen = %d\n", num_seen
);
5187 if (num_seen
!= 1000)
5190 /* Delete everything. */
5191 cli_list(cli
, "\\LISTDIR\\*", 0, del_fn
, cli
);
5192 cli_list(cli
, "\\LISTDIR\\*", aDIR
, del_fn
, cli
);
5193 cli_rmdir(cli
, "\\LISTDIR");
5196 printf("Matched %d\n", cli_list(cli
, "a*.*", 0, list_fn
, NULL
));
5197 printf("Matched %d\n", cli_list(cli
, "b*.*", 0, list_fn
, NULL
));
5198 printf("Matched %d\n", cli_list(cli
, "xyzabc", 0, list_fn
, NULL
));
5201 if (!torture_close_connection(cli
)) {
5205 printf("finished dirtest1\n");
5210 static bool run_error_map_extract(int dummy
) {
5212 static struct cli_state
*c_dos
;
5213 static struct cli_state
*c_nt
;
5218 uint32 flgs2
, errnum
;
5225 /* NT-Error connection */
5227 if (!(c_nt
= open_nbt_connection())) {
5231 c_nt
->use_spnego
= False
;
5233 status
= cli_negprot(c_nt
);
5235 if (!NT_STATUS_IS_OK(status
)) {
5236 printf("%s rejected the NT-error negprot (%s)\n", host
,
5242 if (!NT_STATUS_IS_OK(cli_session_setup(c_nt
, "", "", 0, "", 0,
5244 printf("%s rejected the NT-error initial session setup (%s)\n",host
, cli_errstr(c_nt
));
5248 /* DOS-Error connection */
5250 if (!(c_dos
= open_nbt_connection())) {
5254 c_dos
->use_spnego
= False
;
5255 c_dos
->force_dos_errors
= True
;
5257 status
= cli_negprot(c_dos
);
5258 if (!NT_STATUS_IS_OK(status
)) {
5259 printf("%s rejected the DOS-error negprot (%s)\n", host
,
5261 cli_shutdown(c_dos
);
5265 if (!NT_STATUS_IS_OK(cli_session_setup(c_dos
, "", "", 0, "", 0,
5267 printf("%s rejected the DOS-error initial session setup (%s)\n",host
, cli_errstr(c_dos
));
5271 for (error
=(0xc0000000 | 0x1); error
< (0xc0000000| 0xFFF); error
++) {
5272 fstr_sprintf(user
, "%X", error
);
5274 if (NT_STATUS_IS_OK(cli_session_setup(c_nt
, user
,
5275 password
, strlen(password
),
5276 password
, strlen(password
),
5278 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
5281 flgs2
= SVAL(c_nt
->inbuf
,smb_flg2
);
5283 /* Case #1: 32-bit NT errors */
5284 if (flgs2
& FLAGS2_32_BIT_ERROR_CODES
) {
5285 nt_status
= NT_STATUS(IVAL(c_nt
->inbuf
,smb_rcls
));
5287 printf("/** Dos error on NT connection! (%s) */\n",
5289 nt_status
= NT_STATUS(0xc0000000);
5292 if (NT_STATUS_IS_OK(cli_session_setup(c_dos
, user
,
5293 password
, strlen(password
),
5294 password
, strlen(password
),
5296 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
5298 flgs2
= SVAL(c_dos
->inbuf
,smb_flg2
), errnum
;
5300 /* Case #1: 32-bit NT errors */
5301 if (flgs2
& FLAGS2_32_BIT_ERROR_CODES
) {
5302 printf("/** NT error on DOS connection! (%s) */\n",
5304 errnum
= errclass
= 0;
5306 cli_dos_error(c_dos
, &errclass
, &errnum
);
5309 if (NT_STATUS_V(nt_status
) != error
) {
5310 printf("/*\t{ This NT error code was 'sqashed'\n\t from %s to %s \n\t during the session setup }\n*/\n",
5311 get_nt_error_c_code(NT_STATUS(error
)),
5312 get_nt_error_c_code(nt_status
));
5315 printf("\t{%s,\t%s,\t%s},\n",
5316 smb_dos_err_class(errclass
),
5317 smb_dos_err_name(errclass
, errnum
),
5318 get_nt_error_c_code(NT_STATUS(error
)));
5323 static bool run_sesssetup_bench(int dummy
)
5325 static struct cli_state
*c
;
5326 const char *fname
= "\\file.dat";
5331 if (!torture_open_connection(&c
, 0)) {
5335 if (!NT_STATUS_IS_OK(cli_ntcreate(
5336 c
, fname
, 0, GENERIC_ALL_ACCESS
|DELETE_ACCESS
,
5337 FILE_ATTRIBUTE_NORMAL
, 0, FILE_OVERWRITE_IF
,
5338 FILE_DELETE_ON_CLOSE
, 0, &fnum
))) {
5339 d_printf("open %s failed: %s\n", fname
, cli_errstr(c
));
5343 for (i
=0; i
<torture_numops
; i
++) {
5344 status
= cli_session_setup(
5346 password
, strlen(password
),
5347 password
, strlen(password
),
5349 if (!NT_STATUS_IS_OK(status
)) {
5350 d_printf("(%s) cli_session_setup failed: %s\n",
5351 __location__
, nt_errstr(status
));
5355 d_printf("\r%d ", (int)c
->vuid
);
5357 status
= cli_ulogoff(c
);
5358 if (!NT_STATUS_IS_OK(status
)) {
5359 d_printf("(%s) cli_ulogoff failed: %s\n",
5360 __location__
, nt_errstr(status
));
5369 static bool subst_test(const char *str
, const char *user
, const char *domain
,
5370 uid_t uid
, gid_t gid
, const char *expected
)
5375 subst
= talloc_sub_specified(talloc_tos(), str
, user
, domain
, uid
, gid
);
5377 if (strcmp(subst
, expected
) != 0) {
5378 printf("sub_specified(%s, %s, %s, %d, %d) returned [%s], expected "
5379 "[%s]\n", str
, user
, domain
, (int)uid
, (int)gid
, subst
,
5388 static void chain1_open_completion(struct tevent_req
*req
)
5392 status
= cli_open_recv(req
, &fnum
);
5395 d_printf("cli_open_recv returned %s: %d\n",
5397 NT_STATUS_IS_OK(status
) ? fnum
: -1);
5400 static void chain1_write_completion(struct tevent_req
*req
)
5404 status
= cli_write_andx_recv(req
, &written
);
5407 d_printf("cli_write_andx_recv returned %s: %d\n",
5409 NT_STATUS_IS_OK(status
) ? (int)written
: -1);
5412 static void chain1_close_completion(struct tevent_req
*req
)
5415 bool *done
= (bool *)tevent_req_callback_data_void(req
);
5417 status
= cli_close_recv(req
);
5422 d_printf("cli_close returned %s\n", nt_errstr(status
));
5425 static bool run_chain1(int dummy
)
5427 struct cli_state
*cli1
;
5428 struct event_context
*evt
= event_context_init(NULL
);
5429 struct tevent_req
*reqs
[3], *smbreqs
[3];
5431 const char *str
= "foobar";
5434 printf("starting chain1 test\n");
5435 if (!torture_open_connection(&cli1
, 0)) {
5439 cli_sockopt(cli1
, sockops
);
5441 reqs
[0] = cli_open_create(talloc_tos(), evt
, cli1
, "\\test",
5442 O_CREAT
|O_RDWR
, 0, &smbreqs
[0]);
5443 if (reqs
[0] == NULL
) return false;
5444 tevent_req_set_callback(reqs
[0], chain1_open_completion
, NULL
);
5447 reqs
[1] = cli_write_andx_create(talloc_tos(), evt
, cli1
, 0, 0,
5448 (uint8_t *)str
, 0, strlen(str
)+1,
5449 smbreqs
, 1, &smbreqs
[1]);
5450 if (reqs
[1] == NULL
) return false;
5451 tevent_req_set_callback(reqs
[1], chain1_write_completion
, NULL
);
5453 reqs
[2] = cli_close_create(talloc_tos(), evt
, cli1
, 0, &smbreqs
[2]);
5454 if (reqs
[2] == NULL
) return false;
5455 tevent_req_set_callback(reqs
[2], chain1_close_completion
, &done
);
5457 status
= cli_smb_chain_send(smbreqs
, ARRAY_SIZE(smbreqs
));
5458 if (!NT_STATUS_IS_OK(status
)) {
5463 event_loop_once(evt
);
5466 torture_close_connection(cli1
);
5470 static void chain2_sesssetup_completion(struct tevent_req
*req
)
5473 status
= cli_session_setup_guest_recv(req
);
5474 d_printf("sesssetup returned %s\n", nt_errstr(status
));
5477 static void chain2_tcon_completion(struct tevent_req
*req
)
5479 bool *done
= (bool *)tevent_req_callback_data_void(req
);
5481 status
= cli_tcon_andx_recv(req
);
5482 d_printf("tcon_and_x returned %s\n", nt_errstr(status
));
5486 static bool run_chain2(int dummy
)
5488 struct cli_state
*cli1
;
5489 struct event_context
*evt
= event_context_init(NULL
);
5490 struct tevent_req
*reqs
[2], *smbreqs
[2];
5494 printf("starting chain2 test\n");
5495 status
= cli_start_connection(&cli1
, global_myname(), host
, NULL
,
5496 port_to_use
, Undefined
, 0, NULL
);
5497 if (!NT_STATUS_IS_OK(status
)) {
5501 cli_sockopt(cli1
, sockops
);
5503 reqs
[0] = cli_session_setup_guest_create(talloc_tos(), evt
, cli1
,
5505 if (reqs
[0] == NULL
) return false;
5506 tevent_req_set_callback(reqs
[0], chain2_sesssetup_completion
, NULL
);
5508 reqs
[1] = cli_tcon_andx_create(talloc_tos(), evt
, cli1
, "IPC$",
5509 "?????", NULL
, 0, &smbreqs
[1]);
5510 if (reqs
[1] == NULL
) return false;
5511 tevent_req_set_callback(reqs
[1], chain2_tcon_completion
, &done
);
5513 status
= cli_smb_chain_send(smbreqs
, ARRAY_SIZE(smbreqs
));
5514 if (!NT_STATUS_IS_OK(status
)) {
5519 event_loop_once(evt
);
5522 torture_close_connection(cli1
);
5527 struct torture_createdel_state
{
5528 struct tevent_context
*ev
;
5529 struct cli_state
*cli
;
5532 static void torture_createdel_created(struct tevent_req
*subreq
);
5533 static void torture_createdel_closed(struct tevent_req
*subreq
);
5535 static struct tevent_req
*torture_createdel_send(TALLOC_CTX
*mem_ctx
,
5536 struct tevent_context
*ev
,
5537 struct cli_state
*cli
,
5540 struct tevent_req
*req
, *subreq
;
5541 struct torture_createdel_state
*state
;
5543 req
= tevent_req_create(mem_ctx
, &state
,
5544 struct torture_createdel_state
);
5551 subreq
= cli_ntcreate_send(
5552 state
, ev
, cli
, name
, 0,
5553 FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
5554 FILE_ATTRIBUTE_NORMAL
,
5555 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
5556 FILE_OPEN_IF
, FILE_DELETE_ON_CLOSE
, 0);
5558 if (tevent_req_nomem(subreq
, req
)) {
5559 return tevent_req_post(req
, ev
);
5561 tevent_req_set_callback(subreq
, torture_createdel_created
, req
);
5565 static void torture_createdel_created(struct tevent_req
*subreq
)
5567 struct tevent_req
*req
= tevent_req_callback_data(
5568 subreq
, struct tevent_req
);
5569 struct torture_createdel_state
*state
= tevent_req_data(
5570 req
, struct torture_createdel_state
);
5574 status
= cli_ntcreate_recv(subreq
, &fnum
);
5575 TALLOC_FREE(subreq
);
5576 if (!NT_STATUS_IS_OK(status
)) {
5577 DEBUG(10, ("cli_ntcreate_recv returned %s\n",
5578 nt_errstr(status
)));
5579 tevent_req_nterror(req
, status
);
5583 subreq
= cli_close_send(state
, state
->ev
, state
->cli
, fnum
);
5584 if (tevent_req_nomem(subreq
, req
)) {
5587 tevent_req_set_callback(subreq
, torture_createdel_closed
, req
);
5590 static void torture_createdel_closed(struct tevent_req
*subreq
)
5592 struct tevent_req
*req
= tevent_req_callback_data(
5593 subreq
, struct tevent_req
);
5596 status
= cli_close_recv(subreq
);
5597 if (!NT_STATUS_IS_OK(status
)) {
5598 DEBUG(10, ("cli_close_recv returned %s\n", nt_errstr(status
)));
5599 tevent_req_nterror(req
, status
);
5602 tevent_req_done(req
);
5605 static NTSTATUS
torture_createdel_recv(struct tevent_req
*req
)
5607 return tevent_req_simple_recv_ntstatus(req
);
5610 struct torture_createdels_state
{
5611 struct tevent_context
*ev
;
5612 struct cli_state
*cli
;
5613 const char *base_name
;
5617 struct tevent_req
**reqs
;
5620 static void torture_createdels_done(struct tevent_req
*subreq
);
5622 static struct tevent_req
*torture_createdels_send(TALLOC_CTX
*mem_ctx
,
5623 struct tevent_context
*ev
,
5624 struct cli_state
*cli
,
5625 const char *base_name
,
5629 struct tevent_req
*req
;
5630 struct torture_createdels_state
*state
;
5633 req
= tevent_req_create(mem_ctx
, &state
,
5634 struct torture_createdels_state
);
5640 state
->base_name
= talloc_strdup(state
, base_name
);
5641 if (tevent_req_nomem(state
->base_name
, req
)) {
5642 return tevent_req_post(req
, ev
);
5644 state
->num_files
= MAX(num_parallel
, num_files
);
5646 state
->received
= 0;
5648 state
->reqs
= talloc_array(state
, struct tevent_req
*, num_parallel
);
5649 if (tevent_req_nomem(state
->reqs
, req
)) {
5650 return tevent_req_post(req
, ev
);
5653 for (i
=0; i
<num_parallel
; i
++) {
5656 name
= talloc_asprintf(state
, "%s%8.8d", state
->base_name
,
5658 if (tevent_req_nomem(name
, req
)) {
5659 return tevent_req_post(req
, ev
);
5661 state
->reqs
[i
] = torture_createdel_send(
5662 state
->reqs
, state
->ev
, state
->cli
, name
);
5663 if (tevent_req_nomem(state
->reqs
[i
], req
)) {
5664 return tevent_req_post(req
, ev
);
5666 name
= talloc_move(state
->reqs
[i
], &name
);
5667 tevent_req_set_callback(state
->reqs
[i
],
5668 torture_createdels_done
, req
);
5674 static void torture_createdels_done(struct tevent_req
*subreq
)
5676 struct tevent_req
*req
= tevent_req_callback_data(
5677 subreq
, struct tevent_req
);
5678 struct torture_createdels_state
*state
= tevent_req_data(
5679 req
, struct torture_createdels_state
);
5680 size_t num_parallel
= talloc_array_length(state
->reqs
);
5685 status
= torture_createdel_recv(subreq
);
5686 if (!NT_STATUS_IS_OK(status
)){
5687 DEBUG(10, ("torture_createdel_recv returned %s\n",
5688 nt_errstr(status
)));
5689 TALLOC_FREE(subreq
);
5690 tevent_req_nterror(req
, status
);
5694 for (i
=0; i
<num_parallel
; i
++) {
5695 if (subreq
== state
->reqs
[i
]) {
5699 if (i
== num_parallel
) {
5700 DEBUG(10, ("received something we did not send\n"));
5701 tevent_req_nterror(req
, NT_STATUS_INTERNAL_ERROR
);
5704 TALLOC_FREE(state
->reqs
[i
]);
5706 if (state
->sent
>= state
->num_files
) {
5707 tevent_req_done(req
);
5711 name
= talloc_asprintf(state
, "%s%8.8d", state
->base_name
,
5713 if (tevent_req_nomem(name
, req
)) {
5716 state
->reqs
[i
] = torture_createdel_send(state
->reqs
, state
->ev
,
5718 if (tevent_req_nomem(state
->reqs
[i
], req
)) {
5721 name
= talloc_move(state
->reqs
[i
], &name
);
5722 tevent_req_set_callback(state
->reqs
[i
], torture_createdels_done
, req
);
5726 static NTSTATUS
torture_createdels_recv(struct tevent_req
*req
)
5728 return tevent_req_simple_recv_ntstatus(req
);
5731 struct swallow_notify_state
{
5732 struct tevent_context
*ev
;
5733 struct cli_state
*cli
;
5735 uint32_t completion_filter
;
5737 bool (*fn
)(uint32_t action
, const char *name
, void *priv
);
5741 static void swallow_notify_done(struct tevent_req
*subreq
);
5743 static struct tevent_req
*swallow_notify_send(TALLOC_CTX
*mem_ctx
,
5744 struct tevent_context
*ev
,
5745 struct cli_state
*cli
,
5747 uint32_t completion_filter
,
5749 bool (*fn
)(uint32_t action
,
5754 struct tevent_req
*req
, *subreq
;
5755 struct swallow_notify_state
*state
;
5757 req
= tevent_req_create(mem_ctx
, &state
,
5758 struct swallow_notify_state
);
5765 state
->completion_filter
= completion_filter
;
5766 state
->recursive
= recursive
;
5770 subreq
= cli_notify_send(state
, state
->ev
, state
->cli
, state
->fnum
,
5771 0xffff, state
->completion_filter
,
5773 if (tevent_req_nomem(subreq
, req
)) {
5774 return tevent_req_post(req
, ev
);
5776 tevent_req_set_callback(subreq
, swallow_notify_done
, req
);
5780 static void swallow_notify_done(struct tevent_req
*subreq
)
5782 struct tevent_req
*req
= tevent_req_callback_data(
5783 subreq
, struct tevent_req
);
5784 struct swallow_notify_state
*state
= tevent_req_data(
5785 req
, struct swallow_notify_state
);
5787 uint32_t i
, num_changes
;
5788 struct notify_change
*changes
;
5790 status
= cli_notify_recv(subreq
, state
, &num_changes
, &changes
);
5791 TALLOC_FREE(subreq
);
5792 if (!NT_STATUS_IS_OK(status
)) {
5793 DEBUG(10, ("cli_notify_recv returned %s\n",
5794 nt_errstr(status
)));
5795 tevent_req_nterror(req
, status
);
5799 for (i
=0; i
<num_changes
; i
++) {
5800 state
->fn(changes
[i
].action
, changes
[i
].name
, state
->priv
);
5802 TALLOC_FREE(changes
);
5804 subreq
= cli_notify_send(state
, state
->ev
, state
->cli
, state
->fnum
,
5805 0xffff, state
->completion_filter
,
5807 if (tevent_req_nomem(subreq
, req
)) {
5810 tevent_req_set_callback(subreq
, swallow_notify_done
, req
);
5813 static bool print_notifies(uint32_t action
, const char *name
, void *priv
)
5815 if (DEBUGLEVEL
> 5) {
5816 d_printf("%d %s\n", (int)action
, name
);
5821 static void notify_bench_done(struct tevent_req
*req
)
5823 int *num_finished
= (int *)tevent_req_callback_data_void(req
);
5827 static bool run_notify_bench(int dummy
)
5829 const char *dname
= "\\notify-bench";
5830 struct tevent_context
*ev
;
5833 struct tevent_req
*req1
;
5834 struct tevent_req
*req2
= NULL
;
5835 int i
, num_unc_names
;
5836 int num_finished
= 0;
5838 printf("starting notify-bench test\n");
5840 if (use_multishare_conn
) {
5842 unc_list
= file_lines_load(multishare_conn_fname
,
5843 &num_unc_names
, 0, NULL
);
5844 if (!unc_list
|| num_unc_names
<= 0) {
5845 d_printf("Failed to load unc names list from '%s'\n",
5846 multishare_conn_fname
);
5849 TALLOC_FREE(unc_list
);
5854 ev
= tevent_context_init(talloc_tos());
5856 d_printf("tevent_context_init failed\n");
5860 for (i
=0; i
<num_unc_names
; i
++) {
5861 struct cli_state
*cli
;
5864 base_fname
= talloc_asprintf(talloc_tos(), "%s\\file%3.3d.",
5866 if (base_fname
== NULL
) {
5870 if (!torture_open_connection(&cli
, i
)) {
5874 status
= cli_ntcreate(cli
, dname
, 0,
5875 MAXIMUM_ALLOWED_ACCESS
,
5876 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
|
5878 FILE_OPEN_IF
, FILE_DIRECTORY_FILE
, 0,
5881 if (!NT_STATUS_IS_OK(status
)) {
5882 d_printf("Could not create %s: %s\n", dname
,
5887 req1
= swallow_notify_send(talloc_tos(), ev
, cli
, dnum
,
5888 FILE_NOTIFY_CHANGE_FILE_NAME
|
5889 FILE_NOTIFY_CHANGE_DIR_NAME
|
5890 FILE_NOTIFY_CHANGE_ATTRIBUTES
|
5891 FILE_NOTIFY_CHANGE_LAST_WRITE
,
5892 false, print_notifies
, NULL
);
5894 d_printf("Could not create notify request\n");
5898 req2
= torture_createdels_send(talloc_tos(), ev
, cli
,
5899 base_fname
, 10, torture_numops
);
5901 d_printf("Could not create createdels request\n");
5904 TALLOC_FREE(base_fname
);
5906 tevent_req_set_callback(req2
, notify_bench_done
,
5910 while (num_finished
< num_unc_names
) {
5912 ret
= tevent_loop_once(ev
);
5914 d_printf("tevent_loop_once failed\n");
5919 if (!tevent_req_poll(req2
, ev
)) {
5920 d_printf("tevent_req_poll failed\n");
5923 status
= torture_createdels_recv(req2
);
5924 d_printf("torture_createdels_recv returned %s\n", nt_errstr(status
));
5929 static bool run_mangle1(int dummy
)
5931 struct cli_state
*cli
;
5932 const char *fname
= "this_is_a_long_fname_to_be_mangled.txt";
5936 time_t change_time
, access_time
, write_time
;
5940 printf("starting mangle1 test\n");
5941 if (!torture_open_connection(&cli
, 0)) {
5945 cli_sockopt(cli
, sockops
);
5947 if (!NT_STATUS_IS_OK(cli_ntcreate(
5948 cli
, fname
, 0, GENERIC_ALL_ACCESS
|DELETE_ACCESS
,
5949 FILE_ATTRIBUTE_NORMAL
, 0, FILE_OVERWRITE_IF
, 0, 0, &fnum
))) {
5950 d_printf("open %s failed: %s\n", fname
, cli_errstr(cli
));
5953 cli_close(cli
, fnum
);
5955 status
= cli_qpathinfo_alt_name(cli
, fname
, alt_name
);
5956 if (!NT_STATUS_IS_OK(status
)) {
5957 d_printf("cli_qpathinfo_alt_name failed: %s\n",
5961 d_printf("alt_name: %s\n", alt_name
);
5963 if (!NT_STATUS_IS_OK(cli_open(cli
, alt_name
, O_RDONLY
, DENY_NONE
, &fnum
))) {
5964 d_printf("cli_open(%s) failed: %s\n", alt_name
,
5968 cli_close(cli
, fnum
);
5970 status
= cli_qpathinfo1(cli
, alt_name
, &change_time
, &access_time
,
5971 &write_time
, &size
, &mode
);
5972 if (!NT_STATUS_IS_OK(status
)) {
5973 d_printf("cli_qpathinfo1(%s) failed: %s\n", alt_name
,
5981 static size_t null_source(uint8_t *buf
, size_t n
, void *priv
)
5983 size_t *to_pull
= (size_t *)priv
;
5984 size_t thistime
= *to_pull
;
5986 thistime
= MIN(thistime
, n
);
5987 if (thistime
== 0) {
5991 memset(buf
, 0, thistime
);
5992 *to_pull
-= thistime
;
5996 static bool run_windows_write(int dummy
)
5998 struct cli_state
*cli1
;
6002 const char *fname
= "\\writetest.txt";
6003 struct timeval start_time
;
6007 printf("starting windows_write test\n");
6008 if (!torture_open_connection(&cli1
, 0)) {
6012 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum
))) {
6013 printf("open failed (%s)\n", cli_errstr(cli1
));
6017 cli_sockopt(cli1
, sockops
);
6019 start_time
= timeval_current();
6021 for (i
=0; i
<torture_numops
; i
++) {
6023 off_t start
= i
* torture_blocksize
;
6025 size_t to_pull
= torture_blocksize
- 1;
6027 if (cli_write(cli1
, fnum
, 0, &c
,
6028 start
+ torture_blocksize
- 1, 1) != 1) {
6029 printf("cli_write failed: %s\n", cli_errstr(cli1
));
6033 status
= cli_push(cli1
, fnum
, 0, i
* torture_blocksize
, torture_blocksize
,
6034 null_source
, &to_pull
);
6035 if (!NT_STATUS_IS_OK(status
)) {
6036 printf("cli_push returned: %s\n", nt_errstr(status
));
6041 seconds
= timeval_elapsed(&start_time
);
6042 kbytes
= (double)torture_blocksize
* torture_numops
;
6045 printf("Wrote %d kbytes in %.2f seconds: %d kb/sec\n", (int)kbytes
,
6046 (double)seconds
, (int)(kbytes
/seconds
));
6050 cli_close(cli1
, fnum
);
6051 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
6052 torture_close_connection(cli1
);
6056 static bool run_cli_echo(int dummy
)
6058 struct cli_state
*cli
;
6061 printf("starting cli_echo test\n");
6062 if (!torture_open_connection(&cli
, 0)) {
6065 cli_sockopt(cli
, sockops
);
6067 status
= cli_echo(cli
, 5, data_blob_const("hello", 5));
6069 d_printf("cli_echo returned %s\n", nt_errstr(status
));
6071 torture_close_connection(cli
);
6072 return NT_STATUS_IS_OK(status
);
6075 static bool run_uid_regression_test(int dummy
)
6077 static struct cli_state
*cli
;
6080 bool correct
= True
;
6083 printf("starting uid regression test\n");
6085 if (!torture_open_connection(&cli
, 0)) {
6089 cli_sockopt(cli
, sockops
);
6091 /* Ok - now save then logoff our current user. */
6092 old_vuid
= cli
->vuid
;
6094 status
= cli_ulogoff(cli
);
6095 if (!NT_STATUS_IS_OK(status
)) {
6096 d_printf("(%s) cli_ulogoff failed: %s\n",
6097 __location__
, nt_errstr(status
));
6102 cli
->vuid
= old_vuid
;
6104 /* Try an operation. */
6105 if (!NT_STATUS_IS_OK(cli_mkdir(cli
, "\\uid_reg_test"))) {
6106 /* We expect bad uid. */
6107 if (!check_error(__LINE__
, cli
, ERRSRV
, ERRbaduid
,
6108 NT_STATUS_NO_SUCH_USER
)) {
6113 old_cnum
= cli
->cnum
;
6115 /* Now try a SMBtdis with the invald vuid set to zero. */
6118 /* This should succeed. */
6119 status
= cli_tdis(cli
);
6121 if (NT_STATUS_IS_OK(status
)) {
6122 printf("First tdis with invalid vuid should succeed.\n");
6124 printf("First tdis failed (%s)\n", nt_errstr(status
));
6127 cli
->vuid
= old_vuid
;
6128 cli
->cnum
= old_cnum
;
6130 /* This should fail. */
6131 status
= cli_tdis(cli
);
6132 if (NT_STATUS_IS_OK(status
)) {
6133 printf("Second tdis with invalid vuid should fail - succeeded instead !.\n");
6135 /* Should be bad tid. */
6136 if (!check_error(__LINE__
, cli
, ERRSRV
, ERRinvnid
,
6137 NT_STATUS_NETWORK_NAME_DELETED
)) {
6142 cli_rmdir(cli
, "\\uid_reg_test");
6151 static const char *illegal_chars
= "*\\/?<>|\":";
6152 static char force_shortname_chars
[] = " +,.[];=\177";
6154 static void shortname_del_fn(const char *mnt
, file_info
*finfo
, const char *mask
, void *state
)
6156 struct cli_state
*pcli
= (struct cli_state
*)state
;
6158 slprintf(fname
, sizeof(fname
), "\\shortname\\%s", finfo
->name
);
6160 if (strcmp(finfo
->name
, ".") == 0 || strcmp(finfo
->name
, "..") == 0)
6163 if (finfo
->mode
& aDIR
) {
6164 if (!NT_STATUS_IS_OK(cli_rmdir(pcli
, fname
)))
6165 printf("del_fn: failed to rmdir %s\n,", fname
);
6167 if (!NT_STATUS_IS_OK(cli_unlink(pcli
, fname
, aSYSTEM
| aHIDDEN
)))
6168 printf("del_fn: failed to unlink %s\n,", fname
);
6177 static void shortname_list_fn(const char *mnt
, file_info
*finfo
, const char *name
, void *state
)
6179 struct sn_state
*s
= (struct sn_state
*)state
;
6183 printf("shortname list: i = %d, name = |%s|, shortname = |%s|\n",
6184 i
, finfo
->name
, finfo
->short_name
);
6187 if (strchr(force_shortname_chars
, i
)) {
6188 if (!finfo
->short_name
[0]) {
6189 /* Shortname not created when it should be. */
6190 d_printf("(%s) ERROR: Shortname was not created for file %s containing %d\n",
6191 __location__
, finfo
->name
, i
);
6194 } else if (finfo
->short_name
[0]){
6195 /* Shortname created when it should not be. */
6196 d_printf("(%s) ERROR: Shortname %s was created for file %s\n",
6197 __location__
, finfo
->short_name
, finfo
->name
);
6202 static bool run_shortname_test(int dummy
)
6204 static struct cli_state
*cli
;
6205 bool correct
= True
;
6210 printf("starting shortname test\n");
6212 if (!torture_open_connection(&cli
, 0)) {
6216 cli_sockopt(cli
, sockops
);
6218 cli_list(cli
, "\\shortname\\*", 0, shortname_del_fn
, cli
);
6219 cli_list(cli
, "\\shortname\\*", aDIR
, shortname_del_fn
, cli
);
6220 cli_rmdir(cli
, "\\shortname");
6222 if (!NT_STATUS_IS_OK(cli_mkdir(cli
, "\\shortname"))) {
6223 d_printf("(%s) cli_mkdir of \\shortname failed: %s\n",
6224 __location__
, cli_errstr(cli
));
6229 strlcpy(fname
, "\\shortname\\", sizeof(fname
));
6230 strlcat(fname
, "test .txt", sizeof(fname
));
6234 for (i
= 32; i
< 128; i
++) {
6236 uint16_t fnum
= (uint16_t)-1;
6240 if (strchr(illegal_chars
, i
)) {
6245 status
= cli_ntcreate(cli
, fname
, 0, GENERIC_ALL_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
6246 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OVERWRITE_IF
, 0, 0, &fnum
);
6247 if (!NT_STATUS_IS_OK(status
)) {
6248 d_printf("(%s) cli_nt_create of %s failed: %s\n",
6249 __location__
, fname
, cli_errstr(cli
));
6253 cli_close(cli
, fnum
);
6254 if (cli_list(cli
, "\\shortname\\test*.*", 0, shortname_list_fn
, &s
) != 1) {
6255 d_printf("(%s) failed to list %s: %s\n",
6256 __location__
, fname
, cli_errstr(cli
));
6260 if (!NT_STATUS_IS_OK(cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
))) {
6261 d_printf("(%s) failed to delete %s: %s\n",
6262 __location__
, fname
, cli_errstr(cli
));
6275 cli_list(cli
, "\\shortname\\*", 0, shortname_del_fn
, cli
);
6276 cli_list(cli
, "\\shortname\\*", aDIR
, shortname_del_fn
, cli
);
6277 cli_rmdir(cli
, "\\shortname");
6278 torture_close_connection(cli
);
6282 static void pagedsearch_cb(struct tevent_req
*req
)
6285 struct tldap_message
*msg
;
6288 rc
= tldap_search_paged_recv(req
, talloc_tos(), &msg
);
6289 if (rc
!= TLDAP_SUCCESS
) {
6290 d_printf("tldap_search_paged_recv failed: %s\n",
6291 tldap_err2string(rc
));
6294 if (tldap_msg_type(msg
) != TLDAP_RES_SEARCH_ENTRY
) {
6298 if (!tldap_entry_dn(msg
, &dn
)) {
6299 d_printf("tldap_entry_dn failed\n");
6302 d_printf("%s\n", dn
);
6306 static bool run_tldap(int dummy
)
6308 struct tldap_context
*ld
;
6311 struct sockaddr_storage addr
;
6312 struct tevent_context
*ev
;
6313 struct tevent_req
*req
;
6317 if (!resolve_name(host
, &addr
, 0, false)) {
6318 d_printf("could not find host %s\n", host
);
6321 status
= open_socket_out(&addr
, 389, 9999, &fd
);
6322 if (!NT_STATUS_IS_OK(status
)) {
6323 d_printf("open_socket_out failed: %s\n", nt_errstr(status
));
6327 ld
= tldap_context_create(talloc_tos(), fd
);
6330 d_printf("tldap_context_create failed\n");
6334 rc
= tldap_fetch_rootdse(ld
);
6335 if (rc
!= TLDAP_SUCCESS
) {
6336 d_printf("tldap_fetch_rootdse failed: %s\n",
6337 tldap_errstr(talloc_tos(), ld
, rc
));
6341 basedn
= tldap_talloc_single_attribute(
6342 tldap_rootdse(ld
), "defaultNamingContext", talloc_tos());
6343 if (basedn
== NULL
) {
6344 d_printf("no defaultNamingContext\n");
6347 d_printf("defaultNamingContext: %s\n", basedn
);
6349 ev
= tevent_context_init(talloc_tos());
6351 d_printf("tevent_context_init failed\n");
6355 req
= tldap_search_paged_send(talloc_tos(), ev
, ld
, basedn
,
6356 TLDAP_SCOPE_SUB
, "(objectclass=*)",
6358 NULL
, 0, NULL
, 0, 0, 0, 0, 5);
6360 d_printf("tldap_search_paged_send failed\n");
6363 tevent_req_set_callback(req
, pagedsearch_cb
, NULL
);
6365 tevent_req_poll(req
, ev
);
6369 /* test search filters against rootDSE */
6370 filter
= "(&(|(name=samba)(nextRid<=10000000)(usnChanged>=10)(samba~=ambas)(!(name=s*m*a)))"
6371 "(|(name:=samba)(name:dn:2.5.13.5:=samba)(:dn:2.5.13.5:=samba)(!(name=*samba))))";
6373 rc
= tldap_search(ld
, "", TLDAP_SCOPE_BASE
, filter
,
6374 NULL
, 0, 0, NULL
, 0, NULL
, 0, 0, 0, 0,
6375 talloc_tos(), NULL
, NULL
);
6376 if (rc
!= TLDAP_SUCCESS
) {
6377 d_printf("tldap_search with complex filter failed: %s\n",
6378 tldap_errstr(talloc_tos(), ld
, rc
));
6386 /* Torture test to ensure no regression of :
6387 https://bugzilla.samba.org/show_bug.cgi?id=7084
6390 static bool run_dir_createtime(int dummy
)
6392 struct cli_state
*cli
;
6393 const char *dname
= "\\testdir";
6394 const char *fname
= "\\testdir\\testfile";
6396 struct timespec create_time
;
6397 struct timespec create_time1
;
6401 if (!torture_open_connection(&cli
, 0)) {
6405 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
6406 cli_rmdir(cli
, dname
);
6408 status
= cli_mkdir(cli
, dname
);
6409 if (!NT_STATUS_IS_OK(status
)) {
6410 printf("mkdir failed: %s\n", nt_errstr(status
));
6414 status
= cli_qpathinfo2(cli
, dname
, &create_time
, NULL
, NULL
, NULL
,
6416 if (!NT_STATUS_IS_OK(status
)) {
6417 printf("cli_qpathinfo2 returned %s\n",
6422 /* Sleep 3 seconds, then create a file. */
6425 status
= cli_open(cli
, fname
, O_RDWR
| O_CREAT
| O_EXCL
,
6427 if (!NT_STATUS_IS_OK(status
)) {
6428 printf("cli_open failed: %s\n", nt_errstr(status
));
6432 status
= cli_qpathinfo2(cli
, dname
, &create_time1
, NULL
, NULL
, NULL
,
6434 if (!NT_STATUS_IS_OK(status
)) {
6435 printf("cli_qpathinfo2 (2) returned %s\n",
6440 if (timespec_compare(&create_time1
, &create_time
)) {
6441 printf("run_dir_createtime: create time was updated (error)\n");
6443 printf("run_dir_createtime: create time was not updated (correct)\n");
6449 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
6450 cli_rmdir(cli
, dname
);
6451 if (!torture_close_connection(cli
)) {
6458 static bool run_streamerror(int dummy
)
6460 struct cli_state
*cli
;
6461 const char *dname
= "\\testdir";
6462 const char *streamname
=
6463 "testdir:{4c8cc155-6c1e-11d1-8e41-00c04fb9386d}:$DATA";
6465 time_t change_time
, access_time
, write_time
;
6467 uint16_t mode
, fnum
;
6470 if (!torture_open_connection(&cli
, 0)) {
6474 cli_unlink(cli
, "\\testdir\\*", aSYSTEM
| aHIDDEN
);
6475 cli_rmdir(cli
, dname
);
6477 status
= cli_mkdir(cli
, dname
);
6478 if (!NT_STATUS_IS_OK(status
)) {
6479 printf("mkdir failed: %s\n", nt_errstr(status
));
6483 cli_qpathinfo1(cli
, streamname
, &change_time
, &access_time
, &write_time
,
6485 status
= cli_nt_error(cli
);
6487 if (!NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
6488 printf("pathinfo returned %s, expected "
6489 "NT_STATUS_OBJECT_NAME_NOT_FOUND\n",
6494 status
= cli_ntcreate(cli
, streamname
, 0x16,
6495 FILE_READ_DATA
|FILE_READ_EA
|
6496 FILE_READ_ATTRIBUTES
|READ_CONTROL_ACCESS
,
6497 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
,
6498 FILE_OPEN
, 0, 0, &fnum
);
6500 if (!NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
6501 printf("ntcreate returned %s, expected "
6502 "NT_STATUS_OBJECT_NAME_NOT_FOUND\n",
6508 cli_rmdir(cli
, dname
);
6512 static bool run_local_substitute(int dummy
)
6516 ok
&= subst_test("%U", "bla", "", -1, -1, "bla");
6517 ok
&= subst_test("%u%U", "bla", "", -1, -1, "blabla");
6518 ok
&= subst_test("%g", "", "", -1, -1, "NO_GROUP");
6519 ok
&= subst_test("%G", "", "", -1, -1, "NO_GROUP");
6520 ok
&= subst_test("%g", "", "", -1, 0, gidtoname(0));
6521 ok
&= subst_test("%G", "", "", -1, 0, gidtoname(0));
6522 ok
&= subst_test("%D%u", "u", "dom", -1, 0, "domu");
6523 ok
&= subst_test("%i %I", "", "", -1, -1, "0.0.0.0 0.0.0.0");
6525 /* Different captialization rules in sub_basic... */
6527 ok
&= (strcmp(talloc_sub_basic(talloc_tos(), "BLA", "dom", "%U%D"),
6533 static bool run_local_base64(int dummy
)
6538 for (i
=1; i
<2000; i
++) {
6539 DATA_BLOB blob1
, blob2
;
6542 blob1
.data
= talloc_array(talloc_tos(), uint8_t, i
);
6544 generate_random_buffer(blob1
.data
, blob1
.length
);
6546 b64
= base64_encode_data_blob(talloc_tos(), blob1
);
6548 d_fprintf(stderr
, "base64_encode_data_blob failed "
6549 "for %d bytes\n", i
);
6552 blob2
= base64_decode_data_blob(b64
);
6555 if (data_blob_cmp(&blob1
, &blob2
)) {
6556 d_fprintf(stderr
, "data_blob_cmp failed for %d "
6560 TALLOC_FREE(blob1
.data
);
6561 data_blob_free(&blob2
);
6566 static bool run_local_gencache(int dummy
)
6572 if (!gencache_set("foo", "bar", time(NULL
) + 1000)) {
6573 d_printf("%s: gencache_set() failed\n", __location__
);
6577 if (!gencache_get("foo", NULL
, NULL
)) {
6578 d_printf("%s: gencache_get() failed\n", __location__
);
6582 if (!gencache_get("foo", &val
, &tm
)) {
6583 d_printf("%s: gencache_get() failed\n", __location__
);
6587 if (strcmp(val
, "bar") != 0) {
6588 d_printf("%s: gencache_get() returned %s, expected %s\n",
6589 __location__
, val
, "bar");
6596 if (!gencache_del("foo")) {
6597 d_printf("%s: gencache_del() failed\n", __location__
);
6600 if (gencache_del("foo")) {
6601 d_printf("%s: second gencache_del() succeeded\n",
6606 if (gencache_get("foo", &val
, &tm
)) {
6607 d_printf("%s: gencache_get() on deleted entry "
6608 "succeeded\n", __location__
);
6612 blob
= data_blob_string_const_null("bar");
6613 tm
= time(NULL
) + 60;
6615 if (!gencache_set_data_blob("foo", &blob
, tm
)) {
6616 d_printf("%s: gencache_set_data_blob() failed\n", __location__
);
6620 if (!gencache_get_data_blob("foo", &blob
, NULL
, NULL
)) {
6621 d_printf("%s: gencache_get_data_blob() failed\n", __location__
);
6625 if (strcmp((const char *)blob
.data
, "bar") != 0) {
6626 d_printf("%s: gencache_get_data_blob() returned %s, expected %s\n",
6627 __location__
, (const char *)blob
.data
, "bar");
6628 data_blob_free(&blob
);
6632 data_blob_free(&blob
);
6634 if (!gencache_del("foo")) {
6635 d_printf("%s: gencache_del() failed\n", __location__
);
6638 if (gencache_del("foo")) {
6639 d_printf("%s: second gencache_del() succeeded\n",
6644 if (gencache_get_data_blob("foo", &blob
, NULL
, NULL
)) {
6645 d_printf("%s: gencache_get_data_blob() on deleted entry "
6646 "succeeded\n", __location__
);
6653 static bool rbt_testval(struct db_context
*db
, const char *key
,
6656 struct db_record
*rec
;
6657 TDB_DATA data
= string_tdb_data(value
);
6661 rec
= db
->fetch_locked(db
, db
, string_tdb_data(key
));
6663 d_fprintf(stderr
, "fetch_locked failed\n");
6666 status
= rec
->store(rec
, data
, 0);
6667 if (!NT_STATUS_IS_OK(status
)) {
6668 d_fprintf(stderr
, "store failed: %s\n", nt_errstr(status
));
6673 rec
= db
->fetch_locked(db
, db
, string_tdb_data(key
));
6675 d_fprintf(stderr
, "second fetch_locked failed\n");
6678 if ((rec
->value
.dsize
!= data
.dsize
)
6679 || (memcmp(rec
->value
.dptr
, data
.dptr
, data
.dsize
) != 0)) {
6680 d_fprintf(stderr
, "Got wrong data back\n");
6690 static bool run_local_rbtree(int dummy
)
6692 struct db_context
*db
;
6696 db
= db_open_rbt(NULL
);
6699 d_fprintf(stderr
, "db_open_rbt failed\n");
6703 for (i
=0; i
<1000; i
++) {
6706 if (asprintf(&key
, "key%ld", random()) == -1) {
6709 if (asprintf(&value
, "value%ld", random()) == -1) {
6714 if (!rbt_testval(db
, key
, value
)) {
6721 if (asprintf(&value
, "value%ld", random()) == -1) {
6726 if (!rbt_testval(db
, key
, value
)) {
6743 struct talloc_dict_test
{
6747 static int talloc_dict_traverse_fn(DATA_BLOB key
, void *data
, void *priv
)
6749 int *count
= (int *)priv
;
6754 static bool run_local_talloc_dict(int dummy
)
6756 struct talloc_dict
*dict
;
6757 struct talloc_dict_test
*t
;
6760 dict
= talloc_dict_init(talloc_tos());
6765 t
= talloc(talloc_tos(), struct talloc_dict_test
);
6772 if (!talloc_dict_set(dict
, data_blob_const(&key
, sizeof(key
)), t
)) {
6777 if (talloc_dict_traverse(dict
, talloc_dict_traverse_fn
, &count
) != 0) {
6790 static bool run_local_string_to_sid(int dummy
) {
6793 if (string_to_sid(&sid
, "S--1-5-32-545")) {
6794 printf("allowing S--1-5-32-545\n");
6797 if (string_to_sid(&sid
, "S-1-5-32-+545")) {
6798 printf("allowing S-1-5-32-+545\n");
6801 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")) {
6802 printf("allowing S-1-2-3-4-5-6-7-8-9-0-1-2-3-4-5-6-7-8-9-0\n");
6805 if (string_to_sid(&sid
, "S-1-5-32-545-abc")) {
6806 printf("allowing S-1-5-32-545-abc\n");
6809 if (!string_to_sid(&sid
, "S-1-5-32-545")) {
6810 printf("could not parse S-1-5-32-545\n");
6813 if (!sid_equal(&sid
, &global_sid_Builtin_Users
)) {
6814 printf("mis-parsed S-1-5-32-545 as %s\n",
6815 sid_string_tos(&sid
));
6821 /* Split a path name into filename and stream name components. Canonicalise
6822 * such that an implicit $DATA token is always explicit.
6824 * The "specification" of this function can be found in the
6825 * run_local_stream_name() function in torture.c, I've tried those
6826 * combinations against a W2k3 server.
6829 static NTSTATUS
split_ntfs_stream_name(TALLOC_CTX
*mem_ctx
, const char *fname
,
6830 char **pbase
, char **pstream
)
6833 char *stream
= NULL
;
6834 char *sname
; /* stream name */
6835 const char *stype
; /* stream type */
6837 DEBUG(10, ("split_ntfs_stream_name called for [%s]\n", fname
));
6839 sname
= strchr_m(fname
, ':');
6841 if (lp_posix_pathnames() || (sname
== NULL
)) {
6842 if (pbase
!= NULL
) {
6843 base
= talloc_strdup(mem_ctx
, fname
);
6844 NT_STATUS_HAVE_NO_MEMORY(base
);
6849 if (pbase
!= NULL
) {
6850 base
= talloc_strndup(mem_ctx
, fname
, PTR_DIFF(sname
, fname
));
6851 NT_STATUS_HAVE_NO_MEMORY(base
);
6856 stype
= strchr_m(sname
, ':');
6858 if (stype
== NULL
) {
6859 sname
= talloc_strdup(mem_ctx
, sname
);
6863 if (StrCaseCmp(stype
, ":$DATA") != 0) {
6865 * If there is an explicit stream type, so far we only
6866 * allow $DATA. Is there anything else allowed? -- vl
6868 DEBUG(10, ("[%s] is an invalid stream type\n", stype
));
6870 return NT_STATUS_OBJECT_NAME_INVALID
;
6872 sname
= talloc_strndup(mem_ctx
, sname
, PTR_DIFF(stype
, sname
));
6876 if (sname
== NULL
) {
6878 return NT_STATUS_NO_MEMORY
;
6881 if (sname
[0] == '\0') {
6883 * no stream name, so no stream
6888 if (pstream
!= NULL
) {
6889 stream
= talloc_asprintf(mem_ctx
, "%s:%s", sname
, stype
);
6890 if (stream
== NULL
) {
6893 return NT_STATUS_NO_MEMORY
;
6896 * upper-case the type field
6898 strupper_m(strchr_m(stream
, ':')+1);
6902 if (pbase
!= NULL
) {
6905 if (pstream
!= NULL
) {
6908 return NT_STATUS_OK
;
6911 static bool test_stream_name(const char *fname
, const char *expected_base
,
6912 const char *expected_stream
,
6913 NTSTATUS expected_status
)
6917 char *stream
= NULL
;
6919 status
= split_ntfs_stream_name(talloc_tos(), fname
, &base
, &stream
);
6920 if (!NT_STATUS_EQUAL(status
, expected_status
)) {
6924 if (!NT_STATUS_IS_OK(status
)) {
6928 if (base
== NULL
) goto error
;
6930 if (strcmp(expected_base
, base
) != 0) goto error
;
6932 if ((expected_stream
!= NULL
) && (stream
== NULL
)) goto error
;
6933 if ((expected_stream
== NULL
) && (stream
!= NULL
)) goto error
;
6935 if ((stream
!= NULL
) && (strcmp(expected_stream
, stream
) != 0))
6939 TALLOC_FREE(stream
);
6943 d_fprintf(stderr
, "test_stream(%s, %s, %s, %s)\n",
6944 fname
, expected_base
? expected_base
: "<NULL>",
6945 expected_stream
? expected_stream
: "<NULL>",
6946 nt_errstr(expected_status
));
6947 d_fprintf(stderr
, "-> base=%s, stream=%s, status=%s\n",
6948 base
? base
: "<NULL>", stream
? stream
: "<NULL>",
6951 TALLOC_FREE(stream
);
6955 static bool run_local_stream_name(int dummy
)
6959 ret
&= test_stream_name(
6960 "bla", "bla", NULL
, NT_STATUS_OK
);
6961 ret
&= test_stream_name(
6962 "bla::$DATA", "bla", NULL
, NT_STATUS_OK
);
6963 ret
&= test_stream_name(
6964 "bla:blub:", "bla", NULL
, NT_STATUS_OBJECT_NAME_INVALID
);
6965 ret
&= test_stream_name(
6966 "bla::", NULL
, NULL
, NT_STATUS_OBJECT_NAME_INVALID
);
6967 ret
&= test_stream_name(
6968 "bla::123", "bla", NULL
, NT_STATUS_OBJECT_NAME_INVALID
);
6969 ret
&= test_stream_name(
6970 "bla:$DATA", "bla", "$DATA:$DATA", NT_STATUS_OK
);
6971 ret
&= test_stream_name(
6972 "bla:x:$DATA", "bla", "x:$DATA", NT_STATUS_OK
);
6973 ret
&= test_stream_name(
6974 "bla:x", "bla", "x:$DATA", NT_STATUS_OK
);
6979 static bool data_blob_equal(DATA_BLOB a
, DATA_BLOB b
)
6981 if (a
.length
!= b
.length
) {
6982 printf("a.length=%d != b.length=%d\n",
6983 (int)a
.length
, (int)b
.length
);
6986 if (memcmp(a
.data
, b
.data
, a
.length
) != 0) {
6987 printf("a.data and b.data differ\n");
6993 static bool run_local_memcache(int dummy
)
6995 struct memcache
*cache
;
6997 DATA_BLOB d1
, d2
, d3
;
6998 DATA_BLOB v1
, v2
, v3
;
7000 TALLOC_CTX
*mem_ctx
;
7002 size_t size1
, size2
;
7005 cache
= memcache_init(NULL
, 100);
7007 if (cache
== NULL
) {
7008 printf("memcache_init failed\n");
7012 d1
= data_blob_const("d1", 2);
7013 d2
= data_blob_const("d2", 2);
7014 d3
= data_blob_const("d3", 2);
7016 k1
= data_blob_const("d1", 2);
7017 k2
= data_blob_const("d2", 2);
7019 memcache_add(cache
, STAT_CACHE
, k1
, d1
);
7020 memcache_add(cache
, GETWD_CACHE
, k2
, d2
);
7022 if (!memcache_lookup(cache
, STAT_CACHE
, k1
, &v1
)) {
7023 printf("could not find k1\n");
7026 if (!data_blob_equal(d1
, v1
)) {
7030 if (!memcache_lookup(cache
, GETWD_CACHE
, k2
, &v2
)) {
7031 printf("could not find k2\n");
7034 if (!data_blob_equal(d2
, v2
)) {
7038 memcache_add(cache
, STAT_CACHE
, k1
, d3
);
7040 if (!memcache_lookup(cache
, STAT_CACHE
, k1
, &v3
)) {
7041 printf("could not find replaced k1\n");
7044 if (!data_blob_equal(d3
, v3
)) {
7048 memcache_add(cache
, GETWD_CACHE
, k1
, d1
);
7050 if (memcache_lookup(cache
, GETWD_CACHE
, k2
, &v2
)) {
7051 printf("Did find k2, should have been purged\n");
7057 cache
= memcache_init(NULL
, 0);
7059 mem_ctx
= talloc_init("foo");
7061 str1
= talloc_strdup(mem_ctx
, "string1");
7062 str2
= talloc_strdup(mem_ctx
, "string2");
7064 memcache_add_talloc(cache
, SINGLETON_CACHE_TALLOC
,
7065 data_blob_string_const("torture"), &str1
);
7066 size1
= talloc_total_size(cache
);
7068 memcache_add_talloc(cache
, SINGLETON_CACHE_TALLOC
,
7069 data_blob_string_const("torture"), &str2
);
7070 size2
= talloc_total_size(cache
);
7072 printf("size1=%d, size2=%d\n", (int)size1
, (int)size2
);
7074 if (size2
> size1
) {
7075 printf("memcache leaks memory!\n");
7085 static void wbclient_done(struct tevent_req
*req
)
7088 struct winbindd_response
*wb_resp
;
7089 int *i
= (int *)tevent_req_callback_data_void(req
);
7091 wbc_err
= wb_trans_recv(req
, req
, &wb_resp
);
7094 d_printf("wb_trans_recv %d returned %s\n", *i
, wbcErrorString(wbc_err
));
7097 static bool run_local_wbclient(int dummy
)
7099 struct event_context
*ev
;
7100 struct wb_context
**wb_ctx
;
7101 struct winbindd_request wb_req
;
7102 bool result
= false;
7105 BlockSignals(True
, SIGPIPE
);
7107 ev
= tevent_context_init_byname(talloc_tos(), "epoll");
7112 wb_ctx
= TALLOC_ARRAY(ev
, struct wb_context
*, nprocs
);
7113 if (wb_ctx
== NULL
) {
7117 ZERO_STRUCT(wb_req
);
7118 wb_req
.cmd
= WINBINDD_PING
;
7120 d_printf("nprocs=%d, numops=%d\n", (int)nprocs
, (int)torture_numops
);
7122 for (i
=0; i
<nprocs
; i
++) {
7123 wb_ctx
[i
] = wb_context_init(ev
, NULL
);
7124 if (wb_ctx
[i
] == NULL
) {
7127 for (j
=0; j
<torture_numops
; j
++) {
7128 struct tevent_req
*req
;
7129 req
= wb_trans_send(ev
, ev
, wb_ctx
[i
],
7130 (j
% 2) == 0, &wb_req
);
7134 tevent_req_set_callback(req
, wbclient_done
, &i
);
7140 while (i
< nprocs
* torture_numops
) {
7141 event_loop_once(ev
);
7150 static void getaddrinfo_finished(struct tevent_req
*req
)
7152 char *name
= (char *)tevent_req_callback_data_void(req
);
7153 struct addrinfo
*ainfo
;
7156 res
= getaddrinfo_recv(req
, &ainfo
);
7158 d_printf("gai(%s) returned %s\n", name
, gai_strerror(res
));
7161 d_printf("gai(%s) succeeded\n", name
);
7162 freeaddrinfo(ainfo
);
7165 static bool run_getaddrinfo_send(int dummy
)
7167 TALLOC_CTX
*frame
= talloc_stackframe();
7168 struct fncall_context
*ctx
;
7169 struct tevent_context
*ev
;
7170 bool result
= false;
7171 const char *names
[4] = { "www.samba.org", "notfound.samba.org",
7172 "www.slashdot.org", "heise.de" };
7173 struct tevent_req
*reqs
[4];
7176 ev
= event_context_init(frame
);
7181 ctx
= fncall_context_init(frame
, 4);
7183 for (i
=0; i
<ARRAY_SIZE(names
); i
++) {
7184 reqs
[i
] = getaddrinfo_send(frame
, ev
, ctx
, names
[i
], NULL
,
7186 if (reqs
[i
] == NULL
) {
7189 tevent_req_set_callback(reqs
[i
], getaddrinfo_finished
,
7193 for (i
=0; i
<ARRAY_SIZE(reqs
); i
++) {
7194 tevent_loop_once(ev
);
7203 static bool dbtrans_inc(struct db_context
*db
)
7205 struct db_record
*rec
;
7210 rec
= db
->fetch_locked(db
, db
, string_term_tdb_data("transtest"));
7212 printf(__location__
"fetch_lock failed\n");
7216 if (rec
->value
.dsize
!= sizeof(uint32_t)) {
7217 printf(__location__
"value.dsize = %d\n",
7218 (int)rec
->value
.dsize
);
7222 val
= (uint32_t *)rec
->value
.dptr
;
7225 status
= rec
->store(rec
, make_tdb_data((uint8_t *)val
,
7228 if (!NT_STATUS_IS_OK(status
)) {
7229 printf(__location__
"store failed: %s\n",
7240 static bool run_local_dbtrans(int dummy
)
7242 struct db_context
*db
;
7243 struct db_record
*rec
;
7248 db
= db_open(talloc_tos(), "transtest.tdb", 0, TDB_DEFAULT
,
7249 O_RDWR
|O_CREAT
, 0600);
7251 printf("Could not open transtest.db\n");
7255 res
= db
->transaction_start(db
);
7257 printf(__location__
"transaction_start failed\n");
7261 rec
= db
->fetch_locked(db
, db
, string_term_tdb_data("transtest"));
7263 printf(__location__
"fetch_lock failed\n");
7267 if (rec
->value
.dptr
== NULL
) {
7269 status
= rec
->store(
7270 rec
, make_tdb_data((uint8_t *)&initial
,
7273 if (!NT_STATUS_IS_OK(status
)) {
7274 printf(__location__
"store returned %s\n",
7282 res
= db
->transaction_commit(db
);
7284 printf(__location__
"transaction_commit failed\n");
7292 res
= db
->transaction_start(db
);
7294 printf(__location__
"transaction_start failed\n");
7298 if (!dbwrap_fetch_uint32(db
, "transtest", &val
)) {
7299 printf(__location__
"dbwrap_fetch_uint32 failed\n");
7303 for (i
=0; i
<10; i
++) {
7304 if (!dbtrans_inc(db
)) {
7309 if (!dbwrap_fetch_uint32(db
, "transtest", &val2
)) {
7310 printf(__location__
"dbwrap_fetch_uint32 failed\n");
7314 if (val2
!= val
+ 10) {
7315 printf(__location__
"val=%d, val2=%d\n",
7316 (int)val
, (int)val2
);
7320 printf("val2=%d\r", val2
);
7322 res
= db
->transaction_commit(db
);
7324 printf(__location__
"transaction_commit failed\n");
7334 * Just a dummy test to be run under a debugger. There's no real way
7335 * to inspect the tevent_select specific function from outside of
7339 static bool run_local_tevent_select(int dummy
)
7341 struct tevent_context
*ev
;
7342 struct tevent_fd
*fd1
, *fd2
;
7343 bool result
= false;
7345 ev
= tevent_context_init_byname(NULL
, "select");
7347 d_fprintf(stderr
, "tevent_context_init_byname failed\n");
7351 fd1
= tevent_add_fd(ev
, ev
, 2, 0, NULL
, NULL
);
7353 d_fprintf(stderr
, "tevent_add_fd failed\n");
7356 fd2
= tevent_add_fd(ev
, ev
, 3, 0, NULL
, NULL
);
7358 d_fprintf(stderr
, "tevent_add_fd failed\n");
7363 fd2
= tevent_add_fd(ev
, ev
, 1, 0, NULL
, NULL
);
7365 d_fprintf(stderr
, "tevent_add_fd failed\n");
7375 static double create_procs(bool (*fn
)(int), bool *result
)
7378 volatile pid_t
*child_status
;
7379 volatile bool *child_status_out
;
7382 struct timeval start
;
7386 child_status
= (volatile pid_t
*)shm_setup(sizeof(pid_t
)*nprocs
);
7387 if (!child_status
) {
7388 printf("Failed to setup shared memory\n");
7392 child_status_out
= (volatile bool *)shm_setup(sizeof(bool)*nprocs
);
7393 if (!child_status_out
) {
7394 printf("Failed to setup result status shared memory\n");
7398 for (i
= 0; i
< nprocs
; i
++) {
7399 child_status
[i
] = 0;
7400 child_status_out
[i
] = True
;
7403 start
= timeval_current();
7405 for (i
=0;i
<nprocs
;i
++) {
7408 pid_t mypid
= getpid();
7409 sys_srandom(((int)mypid
) ^ ((int)time(NULL
)));
7411 slprintf(myname
,sizeof(myname
),"CLIENT%d", i
);
7414 if (torture_open_connection(¤t_cli
, i
)) break;
7416 printf("pid %d failed to start\n", (int)getpid());
7422 child_status
[i
] = getpid();
7424 while (child_status
[i
] && timeval_elapsed(&start
) < 5) smb_msleep(2);
7426 child_status_out
[i
] = fn(i
);
7433 for (i
=0;i
<nprocs
;i
++) {
7434 if (child_status
[i
]) synccount
++;
7436 if (synccount
== nprocs
) break;
7438 } while (timeval_elapsed(&start
) < 30);
7440 if (synccount
!= nprocs
) {
7441 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs
, synccount
);
7443 return timeval_elapsed(&start
);
7446 /* start the client load */
7447 start
= timeval_current();
7449 for (i
=0;i
<nprocs
;i
++) {
7450 child_status
[i
] = 0;
7453 printf("%d clients started\n", nprocs
);
7455 for (i
=0;i
<nprocs
;i
++) {
7456 while (waitpid(0, &status
, 0) == -1 && errno
== EINTR
) /* noop */ ;
7461 for (i
=0;i
<nprocs
;i
++) {
7462 if (!child_status_out
[i
]) {
7466 return timeval_elapsed(&start
);
7469 #define FLAG_MULTIPROC 1
7476 {"FDPASS", run_fdpasstest
, 0},
7477 {"LOCK1", run_locktest1
, 0},
7478 {"LOCK2", run_locktest2
, 0},
7479 {"LOCK3", run_locktest3
, 0},
7480 {"LOCK4", run_locktest4
, 0},
7481 {"LOCK5", run_locktest5
, 0},
7482 {"LOCK6", run_locktest6
, 0},
7483 {"LOCK7", run_locktest7
, 0},
7484 {"LOCK8", run_locktest8
, 0},
7485 {"LOCK9", run_locktest9
, 0},
7486 {"UNLINK", run_unlinktest
, 0},
7487 {"BROWSE", run_browsetest
, 0},
7488 {"ATTR", run_attrtest
, 0},
7489 {"TRANS2", run_trans2test
, 0},
7490 {"MAXFID", run_maxfidtest
, FLAG_MULTIPROC
},
7491 {"TORTURE",run_torture
, FLAG_MULTIPROC
},
7492 {"RANDOMIPC", run_randomipc
, 0},
7493 {"NEGNOWAIT", run_negprot_nowait
, 0},
7494 {"NBENCH", run_nbench
, 0},
7495 {"OPLOCK1", run_oplock1
, 0},
7496 {"OPLOCK2", run_oplock2
, 0},
7497 {"OPLOCK3", run_oplock3
, 0},
7498 {"DIR", run_dirtest
, 0},
7499 {"DIR1", run_dirtest1
, 0},
7500 {"DIR-CREATETIME", run_dir_createtime
, 0},
7501 {"DENY1", torture_denytest1
, 0},
7502 {"DENY2", torture_denytest2
, 0},
7503 {"TCON", run_tcon_test
, 0},
7504 {"TCONDEV", run_tcon_devtype_test
, 0},
7505 {"RW1", run_readwritetest
, 0},
7506 {"RW2", run_readwritemulti
, FLAG_MULTIPROC
},
7507 {"RW3", run_readwritelarge
, 0},
7508 {"OPEN", run_opentest
, 0},
7509 {"POSIX", run_simple_posix_open_test
, 0},
7510 {"POSIX-APPEND", run_posix_append
, 0},
7511 { "UID-REGRESSION-TEST", run_uid_regression_test
, 0},
7512 { "SHORTNAME-TEST", run_shortname_test
, 0},
7514 {"OPENATTR", run_openattrtest
, 0},
7516 {"XCOPY", run_xcopy
, 0},
7517 {"RENAME", run_rename
, 0},
7518 {"DELETE", run_deletetest
, 0},
7519 {"PROPERTIES", run_properties
, 0},
7520 {"MANGLE", torture_mangle
, 0},
7521 {"MANGLE1", run_mangle1
, 0},
7522 {"W2K", run_w2ktest
, 0},
7523 {"TRANS2SCAN", torture_trans2_scan
, 0},
7524 {"NTTRANSSCAN", torture_nttrans_scan
, 0},
7525 {"UTABLE", torture_utable
, 0},
7526 {"CASETABLE", torture_casetable
, 0},
7527 {"ERRMAPEXTRACT", run_error_map_extract
, 0},
7528 {"PIPE_NUMBER", run_pipe_number
, 0},
7529 {"TCON2", run_tcon2_test
, 0},
7530 {"IOCTL", torture_ioctl_test
, 0},
7531 {"CHKPATH", torture_chkpath_test
, 0},
7532 {"FDSESS", run_fdsesstest
, 0},
7533 { "EATEST", run_eatest
, 0},
7534 { "SESSSETUP_BENCH", run_sesssetup_bench
, 0},
7535 { "CHAIN1", run_chain1
, 0},
7536 { "CHAIN2", run_chain2
, 0},
7537 { "WINDOWS-WRITE", run_windows_write
, 0},
7538 { "CLI_ECHO", run_cli_echo
, 0},
7539 { "GETADDRINFO", run_getaddrinfo_send
, 0},
7540 { "TLDAP", run_tldap
},
7541 { "STREAMERROR", run_streamerror
},
7542 { "NOTIFY-BENCH", run_notify_bench
},
7543 { "LOCAL-SUBSTITUTE", run_local_substitute
, 0},
7544 { "LOCAL-GENCACHE", run_local_gencache
, 0},
7545 { "LOCAL-TALLOC-DICT", run_local_talloc_dict
, 0},
7546 { "LOCAL-BASE64", run_local_base64
, 0},
7547 { "LOCAL-RBTREE", run_local_rbtree
, 0},
7548 { "LOCAL-MEMCACHE", run_local_memcache
, 0},
7549 { "LOCAL-STREAM-NAME", run_local_stream_name
, 0},
7550 { "LOCAL-WBCLIENT", run_local_wbclient
, 0},
7551 { "LOCAL-string_to_sid", run_local_string_to_sid
, 0},
7552 { "LOCAL-DBTRANS", run_local_dbtrans
, 0},
7553 { "LOCAL-TEVENT-SELECT", run_local_tevent_select
, 0},
7558 /****************************************************************************
7559 run a specified test or "ALL"
7560 ****************************************************************************/
7561 static bool run_test(const char *name
)
7568 if (strequal(name
,"ALL")) {
7569 for (i
=0;torture_ops
[i
].name
;i
++) {
7570 run_test(torture_ops
[i
].name
);
7575 for (i
=0;torture_ops
[i
].name
;i
++) {
7576 fstr_sprintf(randomfname
, "\\XX%x",
7577 (unsigned)random());
7579 if (strequal(name
, torture_ops
[i
].name
)) {
7581 printf("Running %s\n", name
);
7582 if (torture_ops
[i
].flags
& FLAG_MULTIPROC
) {
7583 t
= create_procs(torture_ops
[i
].fn
, &result
);
7586 printf("TEST %s FAILED!\n", name
);
7589 struct timeval start
;
7590 start
= timeval_current();
7591 if (!torture_ops
[i
].fn(0)) {
7593 printf("TEST %s FAILED!\n", name
);
7595 t
= timeval_elapsed(&start
);
7597 printf("%s took %g secs\n\n", name
, t
);
7602 printf("Did not find a test named %s\n", name
);
7610 static void usage(void)
7614 printf("WARNING samba4 test suite is much more complete nowadays.\n");
7615 printf("Please use samba4 torture.\n\n");
7617 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
7619 printf("\t-d debuglevel\n");
7620 printf("\t-U user%%pass\n");
7621 printf("\t-k use kerberos\n");
7622 printf("\t-N numprocs\n");
7623 printf("\t-n my_netbios_name\n");
7624 printf("\t-W workgroup\n");
7625 printf("\t-o num_operations\n");
7626 printf("\t-O socket_options\n");
7627 printf("\t-m maximum protocol\n");
7628 printf("\t-L use oplocks\n");
7629 printf("\t-c CLIENT.TXT specify client load file for NBENCH\n");
7630 printf("\t-A showall\n");
7631 printf("\t-p port\n");
7632 printf("\t-s seed\n");
7633 printf("\t-b unclist_filename specify multiple shares for multiple connections\n");
7636 printf("tests are:");
7637 for (i
=0;torture_ops
[i
].name
;i
++) {
7638 printf(" %s", torture_ops
[i
].name
);
7642 printf("default test is ALL\n");
7647 /****************************************************************************
7649 ****************************************************************************/
7650 int main(int argc
,char *argv
[])
7656 bool correct
= True
;
7657 TALLOC_CTX
*frame
= talloc_stackframe();
7658 int seed
= time(NULL
);
7662 #ifdef HAVE_SETBUFFER
7663 setbuffer(stdout
, NULL
, 0);
7668 setup_logging("smbtorture", true);
7670 if (is_default_dyn_CONFIGFILE()) {
7671 if(getenv("SMB_CONF_PATH")) {
7672 set_dyn_CONFIGFILE(getenv("SMB_CONF_PATH"));
7675 lp_load(get_dyn_CONFIGFILE(),True
,False
,False
,True
);
7682 for(p
= argv
[1]; *p
; p
++)
7686 if (strncmp(argv
[1], "//", 2)) {
7690 fstrcpy(host
, &argv
[1][2]);
7691 p
= strchr_m(&host
[2],'/');
7696 fstrcpy(share
, p
+1);
7698 fstrcpy(myname
, get_myname(talloc_tos()));
7700 fprintf(stderr
, "Failed to get my hostname.\n");
7704 if (*username
== 0 && getenv("LOGNAME")) {
7705 fstrcpy(username
,getenv("LOGNAME"));
7711 fstrcpy(workgroup
, lp_workgroup());
7713 while ((opt
= getopt(argc
, argv
, "p:hW:U:n:N:O:o:m:Ll:d:Aec:ks:b:B:")) != EOF
) {
7716 port_to_use
= atoi(optarg
);
7719 seed
= atoi(optarg
);
7722 fstrcpy(workgroup
,optarg
);
7725 max_protocol
= interpret_protocol(optarg
, max_protocol
);
7728 nprocs
= atoi(optarg
);
7731 torture_numops
= atoi(optarg
);
7734 DEBUGLEVEL
= atoi(optarg
);
7743 local_path
= optarg
;
7746 torture_showall
= True
;
7749 fstrcpy(myname
, optarg
);
7752 client_txt
= optarg
;
7759 use_kerberos
= True
;
7761 d_printf("No kerberos support compiled in\n");
7767 fstrcpy(username
,optarg
);
7768 p
= strchr_m(username
,'%');
7771 fstrcpy(password
, p
+1);
7776 fstrcpy(multishare_conn_fname
, optarg
);
7777 use_multishare_conn
= True
;
7780 torture_blocksize
= atoi(optarg
);
7783 printf("Unknown option %c (%d)\n", (char)opt
, opt
);
7788 d_printf("using seed %d\n", seed
);
7792 if(use_kerberos
&& !gotuser
) gotpass
= True
;
7795 p
= getpass("Password:");
7797 fstrcpy(password
, p
);
7802 printf("host=%s share=%s user=%s myname=%s\n",
7803 host
, share
, username
, myname
);
7805 if (argc
== optind
) {
7806 correct
= run_test("ALL");
7808 for (i
=optind
;i
<argc
;i
++) {
7809 if (!run_test(argv
[i
])) {