2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1997-1998
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 static fstring host
, workgroup
, share
, password
, username
, myname
;
26 static int max_protocol
= PROTOCOL_NT1
;
27 static const char *sockops
="TCP_NODELAY";
29 static int port_to_use
=0;
30 int torture_numops
=100;
31 int torture_blocksize
=1024*1024;
32 static int procnum
; /* records process count number when forking */
33 static struct cli_state
*current_cli
;
34 static fstring randomfname
;
35 static bool use_oplocks
;
36 static bool use_level_II_oplocks
;
37 static const char *client_txt
= "client_oplocks.txt";
38 static bool use_kerberos
;
39 static fstring multishare_conn_fname
;
40 static bool use_multishare_conn
= False
;
41 static bool do_encrypt
;
43 bool torture_showall
= False
;
45 static double create_procs(bool (*fn
)(int), bool *result
);
48 static struct timeval tp1
,tp2
;
51 void start_timer(void)
56 double end_timer(void)
59 return((tp2
.tv_sec
- tp1
.tv_sec
) +
60 (tp2
.tv_usec
- tp1
.tv_usec
)*1.0e-6);
64 /* return a pointer to a anonymous shared memory segment of size "size"
65 which will persist across fork() but will disappear when all processes
68 The memory is not zeroed
70 This function uses system5 shared memory. It takes advantage of a property
71 that the memory is not destroyed if it is attached when the id is removed
73 void *shm_setup(int size
)
78 shmid
= shmget(IPC_PRIVATE
, size
, S_IRUSR
| S_IWUSR
);
80 printf("can't get shared memory\n");
83 ret
= (void *)shmat(shmid
, 0, 0);
84 if (!ret
|| ret
== (void *)-1) {
85 printf("can't attach to shared memory\n");
88 /* the following releases the ipc, but note that this process
89 and all its children will still have access to the memory, its
90 just that the shmid is no longer valid for other shm calls. This
91 means we don't leave behind lots of shm segments after we exit
93 See Stevens "advanced programming in unix env" for details
95 shmctl(shmid
, IPC_RMID
, 0);
100 /********************************************************************
101 Ensure a connection is encrypted.
102 ********************************************************************/
104 static bool force_cli_encryption(struct cli_state
*c
,
105 const char *sharename
)
108 uint32 caplow
, caphigh
;
111 if (!SERVER_HAS_UNIX_CIFS(c
)) {
112 d_printf("Encryption required and "
113 "server that doesn't support "
114 "UNIX extensions - failing connect\n");
118 if (!cli_unix_extensions_version(c
, &major
, &minor
, &caplow
, &caphigh
)) {
119 d_printf("Encryption required and "
120 "can't get UNIX CIFS extensions "
121 "version from server.\n");
125 if (!(caplow
& CIFS_UNIX_TRANSPORT_ENCRYPTION_CAP
)) {
126 d_printf("Encryption required and "
127 "share %s doesn't support "
128 "encryption.\n", sharename
);
132 if (c
->use_kerberos
) {
133 status
= cli_gss_smb_encryption_start(c
);
135 status
= cli_raw_ntlm_smb_encryption_start(c
,
141 if (!NT_STATUS_IS_OK(status
)) {
142 d_printf("Encryption required and "
143 "setup failed with error %s.\n",
152 static struct cli_state
*open_nbt_connection(void)
154 struct nmb_name called
, calling
;
155 struct sockaddr_storage ss
;
159 make_nmb_name(&calling
, myname
, 0x0);
160 make_nmb_name(&called
, host
, 0x20);
164 if (!(c
= cli_initialise())) {
165 printf("Failed initialize cli_struct to connect with %s\n", host
);
169 c
->port
= port_to_use
;
171 status
= cli_connect(c
, host
, &ss
);
172 if (!NT_STATUS_IS_OK(status
)) {
173 printf("Failed to connect with %s. Error %s\n", host
, nt_errstr(status
) );
177 c
->use_kerberos
= use_kerberos
;
179 c
->timeout
= 120000; /* set a really long timeout (2 minutes) */
180 if (use_oplocks
) c
->use_oplocks
= True
;
181 if (use_level_II_oplocks
) c
->use_level_II_oplocks
= True
;
183 if (!cli_session_request(c
, &calling
, &called
)) {
185 * Well, that failed, try *SMBSERVER ...
186 * However, we must reconnect as well ...
188 status
= cli_connect(c
, host
, &ss
);
189 if (!NT_STATUS_IS_OK(status
)) {
190 printf("Failed to connect with %s. Error %s\n", host
, nt_errstr(status
) );
194 make_nmb_name(&called
, "*SMBSERVER", 0x20);
195 if (!cli_session_request(c
, &calling
, &called
)) {
196 printf("%s rejected the session\n",host
);
197 printf("We tried with a called name of %s & %s\n",
207 /* Insert a NULL at the first separator of the given path and return a pointer
208 * to the remainder of the string.
211 terminate_path_at_separator(char * path
)
219 if ((p
= strchr_m(path
, '/'))) {
224 if ((p
= strchr_m(path
, '\\'))) {
234 parse a //server/share type UNC name
236 bool smbcli_parse_unc(const char *unc_name
, TALLOC_CTX
*mem_ctx
,
237 char **hostname
, char **sharename
)
241 *hostname
= *sharename
= NULL
;
243 if (strncmp(unc_name
, "\\\\", 2) &&
244 strncmp(unc_name
, "//", 2)) {
248 *hostname
= talloc_strdup(mem_ctx
, &unc_name
[2]);
249 p
= terminate_path_at_separator(*hostname
);
252 *sharename
= talloc_strdup(mem_ctx
, p
);
253 terminate_path_at_separator(*sharename
);
256 if (*hostname
&& *sharename
) {
260 TALLOC_FREE(*hostname
);
261 TALLOC_FREE(*sharename
);
265 static bool torture_open_connection_share(struct cli_state
**c
,
266 const char *hostname
,
267 const char *sharename
)
274 flags
|= CLI_FULL_CONNECTION_USE_KERBEROS
;
276 status
= cli_full_connection(c
, myname
,
277 hostname
, NULL
, port_to_use
,
280 password
, flags
, Undefined
, &retry
);
281 if (!NT_STATUS_IS_OK(status
)) {
282 printf("failed to open share connection: //%s/%s port:%d - %s\n",
283 hostname
, sharename
, port_to_use
, nt_errstr(status
));
287 if (use_oplocks
) (*c
)->use_oplocks
= True
;
288 if (use_level_II_oplocks
) (*c
)->use_level_II_oplocks
= True
;
289 (*c
)->timeout
= 120000; /* set a really long timeout (2 minutes) */
292 return force_cli_encryption(*c
,
298 bool torture_open_connection(struct cli_state
**c
, int conn_index
)
300 char **unc_list
= NULL
;
301 int num_unc_names
= 0;
304 if (use_multishare_conn
==True
) {
306 unc_list
= file_lines_load(multishare_conn_fname
, &num_unc_names
, 0, NULL
);
307 if (!unc_list
|| num_unc_names
<= 0) {
308 printf("Failed to load unc names list from '%s'\n", multishare_conn_fname
);
312 if (!smbcli_parse_unc(unc_list
[conn_index
% num_unc_names
],
314 printf("Failed to parse UNC name %s\n",
315 unc_list
[conn_index
% num_unc_names
]);
316 TALLOC_FREE(unc_list
);
320 result
= torture_open_connection_share(c
, h
, s
);
322 /* h, s were copied earlier */
323 TALLOC_FREE(unc_list
);
327 return torture_open_connection_share(c
, host
, share
);
330 bool torture_cli_session_setup2(struct cli_state
*cli
, uint16
*new_vuid
)
332 uint16 old_vuid
= cli
->vuid
;
333 fstring old_user_name
;
334 size_t passlen
= strlen(password
);
337 fstrcpy(old_user_name
, cli
->user_name
);
339 ret
= NT_STATUS_IS_OK(cli_session_setup(cli
, username
,
343 *new_vuid
= cli
->vuid
;
344 cli
->vuid
= old_vuid
;
345 fstrcpy(cli
->user_name
, old_user_name
);
350 bool torture_close_connection(struct cli_state
*c
)
354 printf("tdis failed (%s)\n", cli_errstr(c
));
364 /* check if the server produced the expected error code */
365 static bool check_error(int line
, struct cli_state
*c
,
366 uint8 eclass
, uint32 ecode
, NTSTATUS nterr
)
368 if (cli_is_dos_error(c
)) {
372 /* Check DOS error */
374 cli_dos_error(c
, &cclass
, &num
);
376 if (eclass
!= cclass
|| ecode
!= num
) {
377 printf("unexpected error code class=%d code=%d\n",
378 (int)cclass
, (int)num
);
379 printf(" expected %d/%d %s (line=%d)\n",
380 (int)eclass
, (int)ecode
, nt_errstr(nterr
), line
);
389 status
= cli_nt_error(c
);
391 if (NT_STATUS_V(nterr
) != NT_STATUS_V(status
)) {
392 printf("unexpected error code %s\n", nt_errstr(status
));
393 printf(" expected %s (line=%d)\n", nt_errstr(nterr
), line
);
402 static bool wait_lock(struct cli_state
*c
, int fnum
, uint32 offset
, uint32 len
)
404 while (!cli_lock(c
, fnum
, offset
, len
, -1, WRITE_LOCK
)) {
405 if (!check_error(__LINE__
, c
, ERRDOS
, ERRlock
, NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
411 static bool rw_torture(struct cli_state
*c
)
413 const char *lockfname
= "\\torture.lck";
417 pid_t pid2
, pid
= getpid();
422 memset(buf
, '\0', sizeof(buf
));
424 fnum2
= cli_open(c
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
,
427 fnum2
= cli_open(c
, lockfname
, O_RDWR
, DENY_NONE
);
429 printf("open of %s failed (%s)\n", lockfname
, cli_errstr(c
));
434 for (i
=0;i
<torture_numops
;i
++) {
435 unsigned n
= (unsigned)sys_random()%10;
437 printf("%d\r", i
); fflush(stdout
);
439 slprintf(fname
, sizeof(fstring
) - 1, "\\torture.%u", n
);
441 if (!wait_lock(c
, fnum2
, n
*sizeof(int), sizeof(int))) {
445 fnum
= cli_open(c
, fname
, O_RDWR
| O_CREAT
| O_TRUNC
, DENY_ALL
);
447 printf("open failed (%s)\n", cli_errstr(c
));
452 if (cli_write(c
, fnum
, 0, (char *)&pid
, 0, sizeof(pid
)) != sizeof(pid
)) {
453 printf("write failed (%s)\n", cli_errstr(c
));
458 if (cli_write(c
, fnum
, 0, (char *)buf
,
459 sizeof(pid
)+(j
*sizeof(buf
)),
460 sizeof(buf
)) != sizeof(buf
)) {
461 printf("write failed (%s)\n", cli_errstr(c
));
468 if (cli_read(c
, fnum
, (char *)&pid2
, 0, sizeof(pid
)) != sizeof(pid
)) {
469 printf("read failed (%s)\n", cli_errstr(c
));
474 printf("data corruption!\n");
478 if (!cli_close(c
, fnum
)) {
479 printf("close failed (%s)\n", cli_errstr(c
));
483 if (!cli_unlink(c
, fname
)) {
484 printf("unlink failed (%s)\n", cli_errstr(c
));
488 if (!cli_unlock(c
, fnum2
, n
*sizeof(int), sizeof(int))) {
489 printf("unlock failed (%s)\n", cli_errstr(c
));
495 cli_unlink(c
, lockfname
);
502 static bool run_torture(int dummy
)
504 struct cli_state
*cli
;
509 cli_sockopt(cli
, sockops
);
511 ret
= rw_torture(cli
);
513 if (!torture_close_connection(cli
)) {
520 static bool rw_torture3(struct cli_state
*c
, char *lockfname
)
527 unsigned countprev
= 0;
532 for (i
= 0; i
< sizeof(buf
); i
+= sizeof(uint32
))
534 SIVAL(buf
, i
, sys_random());
539 fnum
= cli_open(c
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
,
542 printf("first open read/write of %s failed (%s)\n",
543 lockfname
, cli_errstr(c
));
549 for (i
= 0; i
< 500 && fnum
== -1; i
++)
551 fnum
= cli_open(c
, lockfname
, O_RDONLY
,
556 printf("second open read-only of %s failed (%s)\n",
557 lockfname
, cli_errstr(c
));
563 for (count
= 0; count
< sizeof(buf
); count
+= sent
)
565 if (count
>= countprev
) {
566 printf("%d %8d\r", i
, count
);
569 countprev
+= (sizeof(buf
) / 20);
574 sent
= ((unsigned)sys_random()%(20))+ 1;
575 if (sent
> sizeof(buf
) - count
)
577 sent
= sizeof(buf
) - count
;
580 if (cli_write(c
, fnum
, 0, buf
+count
, count
, (size_t)sent
) != sent
) {
581 printf("write failed (%s)\n", cli_errstr(c
));
587 sent
= cli_read(c
, fnum
, buf_rd
+count
, count
,
591 printf("read failed offset:%d size:%ld (%s)\n",
592 count
, (unsigned long)sizeof(buf
)-count
,
599 if (memcmp(buf_rd
+count
, buf
+count
, sent
) != 0)
601 printf("read/write compare failed\n");
602 printf("offset: %d req %ld recvd %ld\n", count
, (unsigned long)sizeof(buf
)-count
, (unsigned long)sent
);
611 if (!cli_close(c
, fnum
)) {
612 printf("close failed (%s)\n", cli_errstr(c
));
619 static bool rw_torture2(struct cli_state
*c1
, struct cli_state
*c2
)
621 const char *lockfname
= "\\torture2.lck";
630 if (!cli_unlink(c1
, lockfname
)) {
631 printf("unlink failed (%s) (normal, this file should not exist)\n", cli_errstr(c1
));
634 fnum1
= cli_open(c1
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
,
637 printf("first open read/write of %s failed (%s)\n",
638 lockfname
, cli_errstr(c1
));
641 fnum2
= cli_open(c2
, lockfname
, O_RDONLY
,
644 printf("second open read-only of %s failed (%s)\n",
645 lockfname
, cli_errstr(c2
));
646 cli_close(c1
, fnum1
);
650 for (i
=0;i
<torture_numops
;i
++)
652 size_t buf_size
= ((unsigned)sys_random()%(sizeof(buf
)-1))+ 1;
654 printf("%d\r", i
); fflush(stdout
);
657 generate_random_buffer((unsigned char *)buf
, buf_size
);
659 if (cli_write(c1
, fnum1
, 0, buf
, 0, buf_size
) != buf_size
) {
660 printf("write failed (%s)\n", cli_errstr(c1
));
665 if ((bytes_read
= cli_read(c2
, fnum2
, buf_rd
, 0, buf_size
)) != buf_size
) {
666 printf("read failed (%s)\n", cli_errstr(c2
));
667 printf("read %d, expected %ld\n", (int)bytes_read
,
668 (unsigned long)buf_size
);
673 if (memcmp(buf_rd
, buf
, buf_size
) != 0)
675 printf("read/write compare failed\n");
681 if (!cli_close(c2
, fnum2
)) {
682 printf("close failed (%s)\n", cli_errstr(c2
));
685 if (!cli_close(c1
, fnum1
)) {
686 printf("close failed (%s)\n", cli_errstr(c1
));
690 if (!cli_unlink(c1
, lockfname
)) {
691 printf("unlink failed (%s)\n", cli_errstr(c1
));
698 static bool run_readwritetest(int dummy
)
700 static struct cli_state
*cli1
, *cli2
;
701 bool test1
, test2
= False
;
703 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
706 cli_sockopt(cli1
, sockops
);
707 cli_sockopt(cli2
, sockops
);
709 printf("starting readwritetest\n");
711 test1
= rw_torture2(cli1
, cli2
);
712 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1
));
715 test2
= rw_torture2(cli1
, cli1
);
716 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2
));
719 if (!torture_close_connection(cli1
)) {
723 if (!torture_close_connection(cli2
)) {
727 return (test1
&& test2
);
730 static bool run_readwritemulti(int dummy
)
732 struct cli_state
*cli
;
737 cli_sockopt(cli
, sockops
);
739 printf("run_readwritemulti: fname %s\n", randomfname
);
740 test
= rw_torture3(cli
, randomfname
);
742 if (!torture_close_connection(cli
)) {
749 static bool run_readwritelarge(int dummy
)
751 static struct cli_state
*cli1
;
753 const char *lockfname
= "\\large.dat";
758 if (!torture_open_connection(&cli1
, 0)) {
761 cli_sockopt(cli1
, sockops
);
762 memset(buf
,'\0',sizeof(buf
));
764 cli1
->max_xmit
= 128*1024;
766 printf("starting readwritelarge\n");
768 cli_unlink(cli1
, lockfname
);
770 fnum1
= cli_open(cli1
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
, DENY_NONE
);
772 printf("open read/write of %s failed (%s)\n", lockfname
, cli_errstr(cli1
));
776 cli_write(cli1
, fnum1
, 0, buf
, 0, sizeof(buf
));
778 if (!cli_qfileinfo(cli1
, fnum1
, NULL
, &fsize
, NULL
, NULL
, NULL
, NULL
, NULL
)) {
779 printf("qfileinfo failed (%s)\n", cli_errstr(cli1
));
783 if (fsize
== sizeof(buf
))
784 printf("readwritelarge test 1 succeeded (size = %lx)\n",
785 (unsigned long)fsize
);
787 printf("readwritelarge test 1 failed (size = %lx)\n",
788 (unsigned long)fsize
);
792 if (!cli_close(cli1
, fnum1
)) {
793 printf("close failed (%s)\n", cli_errstr(cli1
));
797 if (!cli_unlink(cli1
, lockfname
)) {
798 printf("unlink failed (%s)\n", cli_errstr(cli1
));
802 fnum1
= cli_open(cli1
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
, DENY_NONE
);
804 printf("open read/write of %s failed (%s)\n", lockfname
, cli_errstr(cli1
));
808 cli1
->max_xmit
= 4*1024;
810 cli_smbwrite(cli1
, fnum1
, buf
, 0, sizeof(buf
));
812 if (!cli_qfileinfo(cli1
, fnum1
, NULL
, &fsize
, NULL
, NULL
, NULL
, NULL
, NULL
)) {
813 printf("qfileinfo failed (%s)\n", cli_errstr(cli1
));
817 if (fsize
== sizeof(buf
))
818 printf("readwritelarge test 2 succeeded (size = %lx)\n",
819 (unsigned long)fsize
);
821 printf("readwritelarge test 2 failed (size = %lx)\n",
822 (unsigned long)fsize
);
827 /* ToDo - set allocation. JRA */
828 if(!cli_set_allocation_size(cli1
, fnum1
, 0)) {
829 printf("set allocation size to zero failed (%s)\n", cli_errstr(&cli1
));
832 if (!cli_qfileinfo(cli1
, fnum1
, NULL
, &fsize
, NULL
, NULL
, NULL
, NULL
, NULL
)) {
833 printf("qfileinfo failed (%s)\n", cli_errstr(cli1
));
837 printf("readwritelarge test 3 (truncate test) succeeded (size = %x)\n", fsize
);
840 if (!cli_close(cli1
, fnum1
)) {
841 printf("close failed (%s)\n", cli_errstr(cli1
));
845 if (!torture_close_connection(cli1
)) {
854 #define ival(s) strtol(s, NULL, 0)
856 /* run a test that simulates an approximate netbench client load */
857 static bool run_netbench(int client
)
859 struct cli_state
*cli
;
864 const char *params
[20];
871 cli_sockopt(cli
, sockops
);
875 slprintf(cname
,sizeof(cname
)-1, "client%d", client
);
877 f
= fopen(client_txt
, "r");
884 while (fgets(line
, sizeof(line
)-1, f
)) {
888 line
[strlen(line
)-1] = 0;
890 /* printf("[%d] %s\n", line_count, line); */
892 all_string_sub(line
,"client1", cname
, sizeof(line
));
894 /* parse the command parameters */
895 params
[0] = strtok_r(line
, " ", &saveptr
);
897 while (params
[i
]) params
[++i
] = strtok_r(NULL
, " ", &saveptr
);
903 if (!strncmp(params
[0],"SMB", 3)) {
904 printf("ERROR: You are using a dbench 1 load file\n");
908 if (!strcmp(params
[0],"NTCreateX")) {
909 nb_createx(params
[1], ival(params
[2]), ival(params
[3]),
911 } else if (!strcmp(params
[0],"Close")) {
912 nb_close(ival(params
[1]));
913 } else if (!strcmp(params
[0],"Rename")) {
914 nb_rename(params
[1], params
[2]);
915 } else if (!strcmp(params
[0],"Unlink")) {
916 nb_unlink(params
[1]);
917 } else if (!strcmp(params
[0],"Deltree")) {
918 nb_deltree(params
[1]);
919 } else if (!strcmp(params
[0],"Rmdir")) {
921 } else if (!strcmp(params
[0],"QUERY_PATH_INFORMATION")) {
922 nb_qpathinfo(params
[1]);
923 } else if (!strcmp(params
[0],"QUERY_FILE_INFORMATION")) {
924 nb_qfileinfo(ival(params
[1]));
925 } else if (!strcmp(params
[0],"QUERY_FS_INFORMATION")) {
926 nb_qfsinfo(ival(params
[1]));
927 } else if (!strcmp(params
[0],"FIND_FIRST")) {
928 nb_findfirst(params
[1]);
929 } else if (!strcmp(params
[0],"WriteX")) {
930 nb_writex(ival(params
[1]),
931 ival(params
[2]), ival(params
[3]), ival(params
[4]));
932 } else if (!strcmp(params
[0],"ReadX")) {
933 nb_readx(ival(params
[1]),
934 ival(params
[2]), ival(params
[3]), ival(params
[4]));
935 } else if (!strcmp(params
[0],"Flush")) {
936 nb_flush(ival(params
[1]));
938 printf("Unknown operation %s\n", params
[0]);
946 if (!torture_close_connection(cli
)) {
954 /* run a test that simulates an approximate netbench client load */
955 static bool run_nbench(int dummy
)
964 signal(SIGALRM
, nb_alarm
);
966 t
= create_procs(run_netbench
, &correct
);
969 printf("\nThroughput %g MB/sec\n",
970 1.0e-6 * nbio_total() / t
);
976 This test checks for two things:
978 1) correct support for retaining locks over a close (ie. the server
979 must not use posix semantics)
980 2) support for lock timeouts
982 static bool run_locktest1(int dummy
)
984 struct cli_state
*cli1
, *cli2
;
985 const char *fname
= "\\lockt1.lck";
986 int fnum1
, fnum2
, fnum3
;
988 unsigned lock_timeout
;
990 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
993 cli_sockopt(cli1
, sockops
);
994 cli_sockopt(cli2
, sockops
);
996 printf("starting locktest1\n");
998 cli_unlink(cli1
, fname
);
1000 fnum1
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
1002 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
1005 fnum2
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
);
1007 printf("open2 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
1010 fnum3
= cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
);
1012 printf("open3 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
1016 if (!cli_lock(cli1
, fnum1
, 0, 4, 0, WRITE_LOCK
)) {
1017 printf("lock1 failed (%s)\n", cli_errstr(cli1
));
1022 if (cli_lock(cli2
, fnum3
, 0, 4, 0, WRITE_LOCK
)) {
1023 printf("lock2 succeeded! This is a locking bug\n");
1026 if (!check_error(__LINE__
, cli2
, ERRDOS
, ERRlock
,
1027 NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
1031 lock_timeout
= (1 + (random() % 20));
1032 printf("Testing lock timeout with timeout=%u\n", lock_timeout
);
1034 if (cli_lock(cli2
, fnum3
, 0, 4, lock_timeout
* 1000, WRITE_LOCK
)) {
1035 printf("lock3 succeeded! This is a locking bug\n");
1038 if (!check_error(__LINE__
, cli2
, ERRDOS
, ERRlock
,
1039 NT_STATUS_FILE_LOCK_CONFLICT
)) return False
;
1043 if (ABS(t2
- t1
) < lock_timeout
-1) {
1044 printf("error: This server appears not to support timed lock requests\n");
1047 printf("server slept for %u seconds for a %u second timeout\n",
1048 (unsigned int)(t2
-t1
), lock_timeout
);
1050 if (!cli_close(cli1
, fnum2
)) {
1051 printf("close1 failed (%s)\n", cli_errstr(cli1
));
1055 if (cli_lock(cli2
, fnum3
, 0, 4, 0, WRITE_LOCK
)) {
1056 printf("lock4 succeeded! This is a locking bug\n");
1059 if (!check_error(__LINE__
, cli2
, ERRDOS
, ERRlock
,
1060 NT_STATUS_FILE_LOCK_CONFLICT
)) return False
;
1063 if (!cli_close(cli1
, fnum1
)) {
1064 printf("close2 failed (%s)\n", cli_errstr(cli1
));
1068 if (!cli_close(cli2
, fnum3
)) {
1069 printf("close3 failed (%s)\n", cli_errstr(cli2
));
1073 if (!cli_unlink(cli1
, fname
)) {
1074 printf("unlink failed (%s)\n", cli_errstr(cli1
));
1079 if (!torture_close_connection(cli1
)) {
1083 if (!torture_close_connection(cli2
)) {
1087 printf("Passed locktest1\n");
1092 this checks to see if a secondary tconx can use open files from an
1095 static bool run_tcon_test(int dummy
)
1097 static struct cli_state
*cli
;
1098 const char *fname
= "\\tcontest.tmp";
1100 uint16 cnum1
, cnum2
, cnum3
;
1101 uint16 vuid1
, vuid2
;
1106 memset(buf
, '\0', sizeof(buf
));
1108 if (!torture_open_connection(&cli
, 0)) {
1111 cli_sockopt(cli
, sockops
);
1113 printf("starting tcontest\n");
1115 cli_unlink(cli
, fname
);
1117 fnum1
= cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
1119 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
1126 if (cli_write(cli
, fnum1
, 0, buf
, 130, 4) != 4) {
1127 printf("initial write failed (%s)", cli_errstr(cli
));
1131 status
= cli_tcon_andx(cli
, share
, "?????",
1132 password
, strlen(password
)+1);
1133 if (!NT_STATUS_IS_OK(status
)) {
1134 printf("%s refused 2nd tree connect (%s)\n", host
,
1141 cnum3
= MAX(cnum1
, cnum2
) + 1; /* any invalid number */
1142 vuid2
= cli
->vuid
+ 1;
1144 /* try a write with the wrong tid */
1147 if (cli_write(cli
, fnum1
, 0, buf
, 130, 4) == 4) {
1148 printf("* server allows write with wrong TID\n");
1151 printf("server fails write with wrong TID : %s\n", cli_errstr(cli
));
1155 /* try a write with an invalid tid */
1158 if (cli_write(cli
, fnum1
, 0, buf
, 130, 4) == 4) {
1159 printf("* server allows write with invalid TID\n");
1162 printf("server fails write with invalid TID : %s\n", cli_errstr(cli
));
1165 /* try a write with an invalid vuid */
1169 if (cli_write(cli
, fnum1
, 0, buf
, 130, 4) == 4) {
1170 printf("* server allows write with invalid VUID\n");
1173 printf("server fails write with invalid VUID : %s\n", cli_errstr(cli
));
1179 if (!cli_close(cli
, fnum1
)) {
1180 printf("close failed (%s)\n", cli_errstr(cli
));
1186 if (!cli_tdis(cli
)) {
1187 printf("secondary tdis failed (%s)\n", cli_errstr(cli
));
1193 if (!torture_close_connection(cli
)) {
1202 checks for old style tcon support
1204 static bool run_tcon2_test(int dummy
)
1206 static struct cli_state
*cli
;
1207 uint16 cnum
, max_xmit
;
1211 if (!torture_open_connection(&cli
, 0)) {
1214 cli_sockopt(cli
, sockops
);
1216 printf("starting tcon2 test\n");
1218 if (asprintf(&service
, "\\\\%s\\%s", host
, share
) == -1) {
1222 status
= cli_raw_tcon(cli
, service
, password
, "?????", &max_xmit
, &cnum
);
1224 if (!NT_STATUS_IS_OK(status
)) {
1225 printf("tcon2 failed : %s\n", cli_errstr(cli
));
1227 printf("tcon OK : max_xmit=%d cnum=%d tid=%d\n",
1228 (int)max_xmit
, (int)cnum
, SVAL(cli
->inbuf
, smb_tid
));
1231 if (!torture_close_connection(cli
)) {
1235 printf("Passed tcon2 test\n");
1239 static bool tcon_devtest(struct cli_state
*cli
,
1240 const char *myshare
, const char *devtype
,
1241 const char *return_devtype
,
1242 NTSTATUS expected_error
)
1247 status
= cli_tcon_andx(cli
, myshare
, devtype
,
1248 password
, strlen(password
)+1);
1250 if (NT_STATUS_IS_OK(expected_error
)) {
1251 if (NT_STATUS_IS_OK(status
)) {
1252 if (strcmp(cli
->dev
, return_devtype
) == 0) {
1255 printf("tconX to share %s with type %s "
1256 "succeeded but returned the wrong "
1257 "device type (got [%s] but should have got [%s])\n",
1258 myshare
, devtype
, cli
->dev
, return_devtype
);
1262 printf("tconX to share %s with type %s "
1263 "should have succeeded but failed\n",
1269 if (NT_STATUS_IS_OK(status
)) {
1270 printf("tconx to share %s with type %s "
1271 "should have failed but succeeded\n",
1275 if (NT_STATUS_EQUAL(cli_nt_error(cli
),
1279 printf("Returned unexpected error\n");
1288 checks for correct tconX support
1290 static bool run_tcon_devtype_test(int dummy
)
1292 static struct cli_state
*cli1
= NULL
;
1298 status
= cli_full_connection(&cli1
, myname
,
1299 host
, NULL
, port_to_use
,
1301 username
, workgroup
,
1302 password
, flags
, Undefined
, &retry
);
1304 if (!NT_STATUS_IS_OK(status
)) {
1305 printf("could not open connection\n");
1309 if (!tcon_devtest(cli1
, "IPC$", "A:", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1312 if (!tcon_devtest(cli1
, "IPC$", "?????", "IPC", NT_STATUS_OK
))
1315 if (!tcon_devtest(cli1
, "IPC$", "LPT:", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1318 if (!tcon_devtest(cli1
, "IPC$", "IPC", "IPC", NT_STATUS_OK
))
1321 if (!tcon_devtest(cli1
, "IPC$", "FOOBA", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1324 if (!tcon_devtest(cli1
, share
, "A:", "A:", NT_STATUS_OK
))
1327 if (!tcon_devtest(cli1
, share
, "?????", "A:", NT_STATUS_OK
))
1330 if (!tcon_devtest(cli1
, share
, "LPT:", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1333 if (!tcon_devtest(cli1
, share
, "IPC", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1336 if (!tcon_devtest(cli1
, share
, "FOOBA", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1342 printf("Passed tcondevtest\n");
1349 This test checks that
1351 1) the server supports multiple locking contexts on the one SMB
1352 connection, distinguished by PID.
1354 2) the server correctly fails overlapping locks made by the same PID (this
1355 goes against POSIX behaviour, which is why it is tricky to implement)
1357 3) the server denies unlock requests by an incorrect client PID
1359 static bool run_locktest2(int dummy
)
1361 static struct cli_state
*cli
;
1362 const char *fname
= "\\lockt2.lck";
1363 int fnum1
, fnum2
, fnum3
;
1364 bool correct
= True
;
1366 if (!torture_open_connection(&cli
, 0)) {
1370 cli_sockopt(cli
, sockops
);
1372 printf("starting locktest2\n");
1374 cli_unlink(cli
, fname
);
1378 fnum1
= cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
1380 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
1384 fnum2
= cli_open(cli
, fname
, O_RDWR
, DENY_NONE
);
1386 printf("open2 of %s failed (%s)\n", fname
, cli_errstr(cli
));
1392 fnum3
= cli_open(cli
, fname
, O_RDWR
, DENY_NONE
);
1394 printf("open3 of %s failed (%s)\n", fname
, cli_errstr(cli
));
1400 if (!cli_lock(cli
, fnum1
, 0, 4, 0, WRITE_LOCK
)) {
1401 printf("lock1 failed (%s)\n", cli_errstr(cli
));
1405 if (cli_lock(cli
, fnum1
, 0, 4, 0, WRITE_LOCK
)) {
1406 printf("WRITE lock1 succeeded! This is a locking bug\n");
1409 if (!check_error(__LINE__
, cli
, ERRDOS
, ERRlock
,
1410 NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
1413 if (cli_lock(cli
, fnum2
, 0, 4, 0, WRITE_LOCK
)) {
1414 printf("WRITE lock2 succeeded! This is a locking bug\n");
1417 if (!check_error(__LINE__
, cli
, ERRDOS
, ERRlock
,
1418 NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
1421 if (cli_lock(cli
, fnum2
, 0, 4, 0, READ_LOCK
)) {
1422 printf("READ lock2 succeeded! This is a locking bug\n");
1425 if (!check_error(__LINE__
, cli
, ERRDOS
, ERRlock
,
1426 NT_STATUS_FILE_LOCK_CONFLICT
)) return False
;
1429 if (!cli_lock(cli
, fnum1
, 100, 4, 0, WRITE_LOCK
)) {
1430 printf("lock at 100 failed (%s)\n", cli_errstr(cli
));
1433 if (cli_unlock(cli
, fnum1
, 100, 4)) {
1434 printf("unlock at 100 succeeded! This is a locking bug\n");
1438 if (cli_unlock(cli
, fnum1
, 0, 4)) {
1439 printf("unlock1 succeeded! This is a locking bug\n");
1442 if (!check_error(__LINE__
, cli
,
1444 NT_STATUS_RANGE_NOT_LOCKED
)) return False
;
1447 if (cli_unlock(cli
, fnum1
, 0, 8)) {
1448 printf("unlock2 succeeded! This is a locking bug\n");
1451 if (!check_error(__LINE__
, cli
,
1453 NT_STATUS_RANGE_NOT_LOCKED
)) return False
;
1456 if (cli_lock(cli
, fnum3
, 0, 4, 0, WRITE_LOCK
)) {
1457 printf("lock3 succeeded! This is a locking bug\n");
1460 if (!check_error(__LINE__
, cli
, ERRDOS
, ERRlock
, NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
1465 if (!cli_close(cli
, fnum1
)) {
1466 printf("close1 failed (%s)\n", cli_errstr(cli
));
1470 if (!cli_close(cli
, fnum2
)) {
1471 printf("close2 failed (%s)\n", cli_errstr(cli
));
1475 if (!cli_close(cli
, fnum3
)) {
1476 printf("close3 failed (%s)\n", cli_errstr(cli
));
1480 if (!torture_close_connection(cli
)) {
1484 printf("locktest2 finished\n");
1491 This test checks that
1493 1) the server supports the full offset range in lock requests
1495 static bool run_locktest3(int dummy
)
1497 static struct cli_state
*cli1
, *cli2
;
1498 const char *fname
= "\\lockt3.lck";
1499 int fnum1
, fnum2
, i
;
1501 bool correct
= True
;
1503 #define NEXT_OFFSET offset += (~(uint32)0) / torture_numops
1505 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
1508 cli_sockopt(cli1
, sockops
);
1509 cli_sockopt(cli2
, sockops
);
1511 printf("starting locktest3\n");
1513 cli_unlink(cli1
, fname
);
1515 fnum1
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
1517 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
1520 fnum2
= cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
);
1522 printf("open2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
1526 for (offset
=i
=0;i
<torture_numops
;i
++) {
1528 if (!cli_lock(cli1
, fnum1
, offset
-1, 1, 0, WRITE_LOCK
)) {
1529 printf("lock1 %d failed (%s)\n",
1535 if (!cli_lock(cli2
, fnum2
, offset
-2, 1, 0, WRITE_LOCK
)) {
1536 printf("lock2 %d failed (%s)\n",
1543 for (offset
=i
=0;i
<torture_numops
;i
++) {
1546 if (cli_lock(cli1
, fnum1
, offset
-2, 1, 0, WRITE_LOCK
)) {
1547 printf("error: lock1 %d succeeded!\n", i
);
1551 if (cli_lock(cli2
, fnum2
, offset
-1, 1, 0, WRITE_LOCK
)) {
1552 printf("error: lock2 %d succeeded!\n", i
);
1556 if (cli_lock(cli1
, fnum1
, offset
-1, 1, 0, WRITE_LOCK
)) {
1557 printf("error: lock3 %d succeeded!\n", i
);
1561 if (cli_lock(cli2
, fnum2
, offset
-2, 1, 0, WRITE_LOCK
)) {
1562 printf("error: lock4 %d succeeded!\n", i
);
1567 for (offset
=i
=0;i
<torture_numops
;i
++) {
1570 if (!cli_unlock(cli1
, fnum1
, offset
-1, 1)) {
1571 printf("unlock1 %d failed (%s)\n",
1577 if (!cli_unlock(cli2
, fnum2
, offset
-2, 1)) {
1578 printf("unlock2 %d failed (%s)\n",
1585 if (!cli_close(cli1
, fnum1
)) {
1586 printf("close1 failed (%s)\n", cli_errstr(cli1
));
1590 if (!cli_close(cli2
, fnum2
)) {
1591 printf("close2 failed (%s)\n", cli_errstr(cli2
));
1595 if (!cli_unlink(cli1
, fname
)) {
1596 printf("unlink failed (%s)\n", cli_errstr(cli1
));
1600 if (!torture_close_connection(cli1
)) {
1604 if (!torture_close_connection(cli2
)) {
1608 printf("finished locktest3\n");
1613 #define EXPECTED(ret, v) if ((ret) != (v)) { \
1614 printf("** "); correct = False; \
1618 looks at overlapping locks
1620 static bool run_locktest4(int dummy
)
1622 static struct cli_state
*cli1
, *cli2
;
1623 const char *fname
= "\\lockt4.lck";
1624 int fnum1
, fnum2
, f
;
1627 bool correct
= True
;
1629 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
1633 cli_sockopt(cli1
, sockops
);
1634 cli_sockopt(cli2
, sockops
);
1636 printf("starting locktest4\n");
1638 cli_unlink(cli1
, fname
);
1640 fnum1
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
1641 fnum2
= cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
);
1643 memset(buf
, 0, sizeof(buf
));
1645 if (cli_write(cli1
, fnum1
, 0, buf
, 0, sizeof(buf
)) != sizeof(buf
)) {
1646 printf("Failed to create file\n");
1651 ret
= cli_lock(cli1
, fnum1
, 0, 4, 0, WRITE_LOCK
) &&
1652 cli_lock(cli1
, fnum1
, 2, 4, 0, WRITE_LOCK
);
1653 EXPECTED(ret
, False
);
1654 printf("the same process %s set overlapping write locks\n", ret
?"can":"cannot");
1656 ret
= cli_lock(cli1
, fnum1
, 10, 4, 0, READ_LOCK
) &&
1657 cli_lock(cli1
, fnum1
, 12, 4, 0, READ_LOCK
);
1658 EXPECTED(ret
, True
);
1659 printf("the same process %s set overlapping read locks\n", ret
?"can":"cannot");
1661 ret
= cli_lock(cli1
, fnum1
, 20, 4, 0, WRITE_LOCK
) &&
1662 cli_lock(cli2
, fnum2
, 22, 4, 0, WRITE_LOCK
);
1663 EXPECTED(ret
, False
);
1664 printf("a different connection %s set overlapping write locks\n", ret
?"can":"cannot");
1666 ret
= cli_lock(cli1
, fnum1
, 30, 4, 0, READ_LOCK
) &&
1667 cli_lock(cli2
, fnum2
, 32, 4, 0, READ_LOCK
);
1668 EXPECTED(ret
, True
);
1669 printf("a different connection %s set overlapping read locks\n", ret
?"can":"cannot");
1671 ret
= (cli_setpid(cli1
, 1), cli_lock(cli1
, fnum1
, 40, 4, 0, WRITE_LOCK
)) &&
1672 (cli_setpid(cli1
, 2), cli_lock(cli1
, fnum1
, 42, 4, 0, WRITE_LOCK
));
1673 EXPECTED(ret
, False
);
1674 printf("a different pid %s set overlapping write locks\n", ret
?"can":"cannot");
1676 ret
= (cli_setpid(cli1
, 1), cli_lock(cli1
, fnum1
, 50, 4, 0, READ_LOCK
)) &&
1677 (cli_setpid(cli1
, 2), cli_lock(cli1
, fnum1
, 52, 4, 0, READ_LOCK
));
1678 EXPECTED(ret
, True
);
1679 printf("a different pid %s set overlapping read locks\n", ret
?"can":"cannot");
1681 ret
= cli_lock(cli1
, fnum1
, 60, 4, 0, READ_LOCK
) &&
1682 cli_lock(cli1
, fnum1
, 60, 4, 0, READ_LOCK
);
1683 EXPECTED(ret
, True
);
1684 printf("the same process %s set the same read lock twice\n", ret
?"can":"cannot");
1686 ret
= cli_lock(cli1
, fnum1
, 70, 4, 0, WRITE_LOCK
) &&
1687 cli_lock(cli1
, fnum1
, 70, 4, 0, WRITE_LOCK
);
1688 EXPECTED(ret
, False
);
1689 printf("the same process %s set the same write lock twice\n", ret
?"can":"cannot");
1691 ret
= cli_lock(cli1
, fnum1
, 80, 4, 0, READ_LOCK
) &&
1692 cli_lock(cli1
, fnum1
, 80, 4, 0, WRITE_LOCK
);
1693 EXPECTED(ret
, False
);
1694 printf("the same process %s overlay a read lock with a write lock\n", ret
?"can":"cannot");
1696 ret
= cli_lock(cli1
, fnum1
, 90, 4, 0, WRITE_LOCK
) &&
1697 cli_lock(cli1
, fnum1
, 90, 4, 0, READ_LOCK
);
1698 EXPECTED(ret
, True
);
1699 printf("the same process %s overlay a write lock with a read lock\n", ret
?"can":"cannot");
1701 ret
= (cli_setpid(cli1
, 1), cli_lock(cli1
, fnum1
, 100, 4, 0, WRITE_LOCK
)) &&
1702 (cli_setpid(cli1
, 2), cli_lock(cli1
, fnum1
, 100, 4, 0, READ_LOCK
));
1703 EXPECTED(ret
, False
);
1704 printf("a different pid %s overlay a write lock with a read lock\n", ret
?"can":"cannot");
1706 ret
= cli_lock(cli1
, fnum1
, 110, 4, 0, READ_LOCK
) &&
1707 cli_lock(cli1
, fnum1
, 112, 4, 0, READ_LOCK
) &&
1708 cli_unlock(cli1
, fnum1
, 110, 6);
1709 EXPECTED(ret
, False
);
1710 printf("the same process %s coalesce read locks\n", ret
?"can":"cannot");
1713 ret
= cli_lock(cli1
, fnum1
, 120, 4, 0, WRITE_LOCK
) &&
1714 (cli_read(cli2
, fnum2
, buf
, 120, 4) == 4);
1715 EXPECTED(ret
, False
);
1716 printf("this server %s strict write locking\n", ret
?"doesn't do":"does");
1718 ret
= cli_lock(cli1
, fnum1
, 130, 4, 0, READ_LOCK
) &&
1719 (cli_write(cli2
, fnum2
, 0, buf
, 130, 4) == 4);
1720 EXPECTED(ret
, False
);
1721 printf("this server %s strict read locking\n", ret
?"doesn't do":"does");
1724 ret
= cli_lock(cli1
, fnum1
, 140, 4, 0, READ_LOCK
) &&
1725 cli_lock(cli1
, fnum1
, 140, 4, 0, READ_LOCK
) &&
1726 cli_unlock(cli1
, fnum1
, 140, 4) &&
1727 cli_unlock(cli1
, fnum1
, 140, 4);
1728 EXPECTED(ret
, True
);
1729 printf("this server %s do recursive read locking\n", ret
?"does":"doesn't");
1732 ret
= cli_lock(cli1
, fnum1
, 150, 4, 0, WRITE_LOCK
) &&
1733 cli_lock(cli1
, fnum1
, 150, 4, 0, READ_LOCK
) &&
1734 cli_unlock(cli1
, fnum1
, 150, 4) &&
1735 (cli_read(cli2
, fnum2
, buf
, 150, 4) == 4) &&
1736 !(cli_write(cli2
, fnum2
, 0, buf
, 150, 4) == 4) &&
1737 cli_unlock(cli1
, fnum1
, 150, 4);
1738 EXPECTED(ret
, True
);
1739 printf("this server %s do recursive lock overlays\n", ret
?"does":"doesn't");
1741 ret
= cli_lock(cli1
, fnum1
, 160, 4, 0, READ_LOCK
) &&
1742 cli_unlock(cli1
, fnum1
, 160, 4) &&
1743 (cli_write(cli2
, fnum2
, 0, buf
, 160, 4) == 4) &&
1744 (cli_read(cli2
, fnum2
, buf
, 160, 4) == 4);
1745 EXPECTED(ret
, True
);
1746 printf("the same process %s remove a read lock using write locking\n", ret
?"can":"cannot");
1748 ret
= cli_lock(cli1
, fnum1
, 170, 4, 0, WRITE_LOCK
) &&
1749 cli_unlock(cli1
, fnum1
, 170, 4) &&
1750 (cli_write(cli2
, fnum2
, 0, buf
, 170, 4) == 4) &&
1751 (cli_read(cli2
, fnum2
, buf
, 170, 4) == 4);
1752 EXPECTED(ret
, True
);
1753 printf("the same process %s remove a write lock using read locking\n", ret
?"can":"cannot");
1755 ret
= cli_lock(cli1
, fnum1
, 190, 4, 0, WRITE_LOCK
) &&
1756 cli_lock(cli1
, fnum1
, 190, 4, 0, READ_LOCK
) &&
1757 cli_unlock(cli1
, fnum1
, 190, 4) &&
1758 !(cli_write(cli2
, fnum2
, 0, buf
, 190, 4) == 4) &&
1759 (cli_read(cli2
, fnum2
, buf
, 190, 4) == 4);
1760 EXPECTED(ret
, True
);
1761 printf("the same process %s remove the first lock first\n", ret
?"does":"doesn't");
1763 cli_close(cli1
, fnum1
);
1764 cli_close(cli2
, fnum2
);
1765 fnum1
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
);
1766 f
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
);
1767 ret
= cli_lock(cli1
, fnum1
, 0, 8, 0, READ_LOCK
) &&
1768 cli_lock(cli1
, f
, 0, 1, 0, READ_LOCK
) &&
1769 cli_close(cli1
, fnum1
) &&
1770 ((fnum1
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
)) != -1) &&
1771 cli_lock(cli1
, fnum1
, 7, 1, 0, WRITE_LOCK
);
1773 cli_close(cli1
, fnum1
);
1774 EXPECTED(ret
, True
);
1775 printf("the server %s have the NT byte range lock bug\n", !ret
?"does":"doesn't");
1778 cli_close(cli1
, fnum1
);
1779 cli_close(cli2
, fnum2
);
1780 cli_unlink(cli1
, fname
);
1781 torture_close_connection(cli1
);
1782 torture_close_connection(cli2
);
1784 printf("finished locktest4\n");
1789 looks at lock upgrade/downgrade.
1791 static bool run_locktest5(int dummy
)
1793 static struct cli_state
*cli1
, *cli2
;
1794 const char *fname
= "\\lockt5.lck";
1795 int fnum1
, fnum2
, fnum3
;
1798 bool correct
= True
;
1800 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
1804 cli_sockopt(cli1
, sockops
);
1805 cli_sockopt(cli2
, sockops
);
1807 printf("starting locktest5\n");
1809 cli_unlink(cli1
, fname
);
1811 fnum1
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
1812 fnum2
= cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
);
1813 fnum3
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
);
1815 memset(buf
, 0, sizeof(buf
));
1817 if (cli_write(cli1
, fnum1
, 0, buf
, 0, sizeof(buf
)) != sizeof(buf
)) {
1818 printf("Failed to create file\n");
1823 /* Check for NT bug... */
1824 ret
= cli_lock(cli1
, fnum1
, 0, 8, 0, READ_LOCK
) &&
1825 cli_lock(cli1
, fnum3
, 0, 1, 0, READ_LOCK
);
1826 cli_close(cli1
, fnum1
);
1827 fnum1
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
);
1828 ret
= cli_lock(cli1
, fnum1
, 7, 1, 0, WRITE_LOCK
);
1829 EXPECTED(ret
, True
);
1830 printf("this server %s the NT locking bug\n", ret
? "doesn't have" : "has");
1831 cli_close(cli1
, fnum1
);
1832 fnum1
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
);
1833 cli_unlock(cli1
, fnum3
, 0, 1);
1835 ret
= cli_lock(cli1
, fnum1
, 0, 4, 0, WRITE_LOCK
) &&
1836 cli_lock(cli1
, fnum1
, 1, 1, 0, READ_LOCK
);
1837 EXPECTED(ret
, True
);
1838 printf("the same process %s overlay a write with a read lock\n", ret
?"can":"cannot");
1840 ret
= cli_lock(cli2
, fnum2
, 0, 4, 0, READ_LOCK
);
1841 EXPECTED(ret
, False
);
1843 printf("a different processs %s get a read lock on the first process lock stack\n", ret
?"can":"cannot");
1845 /* Unlock the process 2 lock. */
1846 cli_unlock(cli2
, fnum2
, 0, 4);
1848 ret
= cli_lock(cli1
, fnum3
, 0, 4, 0, READ_LOCK
);
1849 EXPECTED(ret
, False
);
1851 printf("the same processs on a different fnum %s get a read lock\n", ret
?"can":"cannot");
1853 /* Unlock the process 1 fnum3 lock. */
1854 cli_unlock(cli1
, fnum3
, 0, 4);
1856 /* Stack 2 more locks here. */
1857 ret
= cli_lock(cli1
, fnum1
, 0, 4, 0, READ_LOCK
) &&
1858 cli_lock(cli1
, fnum1
, 0, 4, 0, READ_LOCK
);
1860 EXPECTED(ret
, True
);
1861 printf("the same process %s stack read locks\n", ret
?"can":"cannot");
1863 /* Unlock the first process lock, then check this was the WRITE lock that was
1866 ret
= cli_unlock(cli1
, fnum1
, 0, 4) &&
1867 cli_lock(cli2
, fnum2
, 0, 4, 0, READ_LOCK
);
1869 EXPECTED(ret
, True
);
1870 printf("the first unlock removes the %s lock\n", ret
?"WRITE":"READ");
1872 /* Unlock the process 2 lock. */
1873 cli_unlock(cli2
, fnum2
, 0, 4);
1875 /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */
1877 ret
= cli_unlock(cli1
, fnum1
, 1, 1) &&
1878 cli_unlock(cli1
, fnum1
, 0, 4) &&
1879 cli_unlock(cli1
, fnum1
, 0, 4);
1881 EXPECTED(ret
, True
);
1882 printf("the same process %s unlock the stack of 4 locks\n", ret
?"can":"cannot");
1884 /* Ensure the next unlock fails. */
1885 ret
= cli_unlock(cli1
, fnum1
, 0, 4);
1886 EXPECTED(ret
, False
);
1887 printf("the same process %s count the lock stack\n", !ret
?"can":"cannot");
1889 /* Ensure connection 2 can get a write lock. */
1890 ret
= cli_lock(cli2
, fnum2
, 0, 4, 0, WRITE_LOCK
);
1891 EXPECTED(ret
, True
);
1893 printf("a different processs %s get a write lock on the unlocked stack\n", ret
?"can":"cannot");
1897 cli_close(cli1
, fnum1
);
1898 cli_close(cli2
, fnum2
);
1899 cli_unlink(cli1
, fname
);
1900 if (!torture_close_connection(cli1
)) {
1903 if (!torture_close_connection(cli2
)) {
1907 printf("finished locktest5\n");
1913 tries the unusual lockingX locktype bits
1915 static bool run_locktest6(int dummy
)
1917 static struct cli_state
*cli
;
1918 const char *fname
[1] = { "\\lock6.txt" };
1923 if (!torture_open_connection(&cli
, 0)) {
1927 cli_sockopt(cli
, sockops
);
1929 printf("starting locktest6\n");
1932 printf("Testing %s\n", fname
[i
]);
1934 cli_unlink(cli
, fname
[i
]);
1936 fnum
= cli_open(cli
, fname
[i
], O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
1937 status
= cli_locktype(cli
, fnum
, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE
);
1938 cli_close(cli
, fnum
);
1939 printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status
));
1941 fnum
= cli_open(cli
, fname
[i
], O_RDWR
, DENY_NONE
);
1942 status
= cli_locktype(cli
, fnum
, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK
);
1943 cli_close(cli
, fnum
);
1944 printf("CANCEL_LOCK gave %s\n", nt_errstr(status
));
1946 cli_unlink(cli
, fname
[i
]);
1949 torture_close_connection(cli
);
1951 printf("finished locktest6\n");
1955 static bool run_locktest7(int dummy
)
1957 struct cli_state
*cli1
;
1958 const char *fname
= "\\lockt7.lck";
1961 bool correct
= False
;
1963 if (!torture_open_connection(&cli1
, 0)) {
1967 cli_sockopt(cli1
, sockops
);
1969 printf("starting locktest7\n");
1971 cli_unlink(cli1
, fname
);
1973 fnum1
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
1975 memset(buf
, 0, sizeof(buf
));
1977 if (cli_write(cli1
, fnum1
, 0, buf
, 0, sizeof(buf
)) != sizeof(buf
)) {
1978 printf("Failed to create file\n");
1982 cli_setpid(cli1
, 1);
1984 if (!cli_lock(cli1
, fnum1
, 130, 4, 0, READ_LOCK
)) {
1985 printf("Unable to apply read lock on range 130:4, error was %s\n", cli_errstr(cli1
));
1988 printf("pid1 successfully locked range 130:4 for READ\n");
1991 if (cli_read(cli1
, fnum1
, buf
, 130, 4) != 4) {
1992 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1
));
1995 printf("pid1 successfully read the range 130:4\n");
1998 if (cli_write(cli1
, fnum1
, 0, buf
, 130, 4) != 4) {
1999 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1
));
2000 if (NT_STATUS_V(cli_nt_error(cli1
)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT
)) {
2001 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2005 printf("pid1 successfully wrote to the range 130:4 (should be denied)\n");
2009 cli_setpid(cli1
, 2);
2011 if (cli_read(cli1
, fnum1
, buf
, 130, 4) != 4) {
2012 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1
));
2014 printf("pid2 successfully read the range 130:4\n");
2017 if (cli_write(cli1
, fnum1
, 0, buf
, 130, 4) != 4) {
2018 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1
));
2019 if (NT_STATUS_V(cli_nt_error(cli1
)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT
)) {
2020 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2024 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
2028 cli_setpid(cli1
, 1);
2029 cli_unlock(cli1
, fnum1
, 130, 4);
2031 if (!cli_lock(cli1
, fnum1
, 130, 4, 0, WRITE_LOCK
)) {
2032 printf("Unable to apply write lock on range 130:4, error was %s\n", cli_errstr(cli1
));
2035 printf("pid1 successfully locked range 130:4 for WRITE\n");
2038 if (cli_read(cli1
, fnum1
, buf
, 130, 4) != 4) {
2039 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1
));
2042 printf("pid1 successfully read the range 130:4\n");
2045 if (cli_write(cli1
, fnum1
, 0, buf
, 130, 4) != 4) {
2046 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1
));
2049 printf("pid1 successfully wrote to the range 130:4\n");
2052 cli_setpid(cli1
, 2);
2054 if (cli_read(cli1
, fnum1
, buf
, 130, 4) != 4) {
2055 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1
));
2056 if (NT_STATUS_V(cli_nt_error(cli1
)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT
)) {
2057 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2061 printf("pid2 successfully read the range 130:4 (should be denied)\n");
2065 if (cli_write(cli1
, fnum1
, 0, buf
, 130, 4) != 4) {
2066 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1
));
2067 if (NT_STATUS_V(cli_nt_error(cli1
)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT
)) {
2068 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2072 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
2076 cli_unlock(cli1
, fnum1
, 130, 0);
2080 cli_close(cli1
, fnum1
);
2081 cli_unlink(cli1
, fname
);
2082 torture_close_connection(cli1
);
2084 printf("finished locktest7\n");
2089 test whether fnums and tids open on one VC are available on another (a major
2092 static bool run_fdpasstest(int dummy
)
2094 struct cli_state
*cli1
, *cli2
;
2095 const char *fname
= "\\fdpass.tst";
2099 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
2102 cli_sockopt(cli1
, sockops
);
2103 cli_sockopt(cli2
, sockops
);
2105 printf("starting fdpasstest\n");
2107 cli_unlink(cli1
, fname
);
2109 fnum1
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
2111 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
2115 if (cli_write(cli1
, fnum1
, 0, "hello world\n", 0, 13) != 13) {
2116 printf("write failed (%s)\n", cli_errstr(cli1
));
2120 cli2
->vuid
= cli1
->vuid
;
2121 cli2
->cnum
= cli1
->cnum
;
2122 cli2
->pid
= cli1
->pid
;
2124 if (cli_read(cli2
, fnum1
, buf
, 0, 13) == 13) {
2125 printf("read succeeded! nasty security hole [%s]\n",
2130 cli_close(cli1
, fnum1
);
2131 cli_unlink(cli1
, fname
);
2133 torture_close_connection(cli1
);
2134 torture_close_connection(cli2
);
2136 printf("finished fdpasstest\n");
2140 static bool run_fdsesstest(int dummy
)
2142 struct cli_state
*cli
;
2147 const char *fname
= "\\fdsess.tst";
2148 const char *fname1
= "\\fdsess1.tst";
2154 if (!torture_open_connection(&cli
, 0))
2156 cli_sockopt(cli
, sockops
);
2158 if (!torture_cli_session_setup2(cli
, &new_vuid
))
2161 saved_cnum
= cli
->cnum
;
2162 if (!NT_STATUS_IS_OK(cli_tcon_andx(cli
, share
, "?????", "", 1)))
2164 new_cnum
= cli
->cnum
;
2165 cli
->cnum
= saved_cnum
;
2167 printf("starting fdsesstest\n");
2169 cli_unlink(cli
, fname
);
2170 cli_unlink(cli
, fname1
);
2172 fnum1
= cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
2174 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
2178 if (cli_write(cli
, fnum1
, 0, "hello world\n", 0, 13) != 13) {
2179 printf("write failed (%s)\n", cli_errstr(cli
));
2183 saved_vuid
= cli
->vuid
;
2184 cli
->vuid
= new_vuid
;
2186 if (cli_read(cli
, fnum1
, buf
, 0, 13) == 13) {
2187 printf("read succeeded with different vuid! nasty security hole [%s]\n",
2191 /* Try to open a file with different vuid, samba cnum. */
2192 fnum2
= cli_open(cli
, fname1
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
2194 printf("create with different vuid, same cnum succeeded.\n");
2195 cli_close(cli
, fnum2
);
2196 cli_unlink(cli
, fname1
);
2198 printf("create with different vuid, same cnum failed.\n");
2199 printf("This will cause problems with service clients.\n");
2203 cli
->vuid
= saved_vuid
;
2205 /* Try with same vuid, different cnum. */
2206 cli
->cnum
= new_cnum
;
2208 if (cli_read(cli
, fnum1
, buf
, 0, 13) == 13) {
2209 printf("read succeeded with different cnum![%s]\n",
2214 cli
->cnum
= saved_cnum
;
2215 cli_close(cli
, fnum1
);
2216 cli_unlink(cli
, fname
);
2218 torture_close_connection(cli
);
2220 printf("finished fdsesstest\n");
2225 This test checks that
2227 1) the server does not allow an unlink on a file that is open
2229 static bool run_unlinktest(int dummy
)
2231 struct cli_state
*cli
;
2232 const char *fname
= "\\unlink.tst";
2234 bool correct
= True
;
2236 if (!torture_open_connection(&cli
, 0)) {
2240 cli_sockopt(cli
, sockops
);
2242 printf("starting unlink test\n");
2244 cli_unlink(cli
, fname
);
2248 fnum
= cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
2250 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
2254 if (cli_unlink(cli
, fname
)) {
2255 printf("error: server allowed unlink on an open file\n");
2258 correct
= check_error(__LINE__
, cli
, ERRDOS
, ERRbadshare
,
2259 NT_STATUS_SHARING_VIOLATION
);
2262 cli_close(cli
, fnum
);
2263 cli_unlink(cli
, fname
);
2265 if (!torture_close_connection(cli
)) {
2269 printf("unlink test finished\n");
2276 test how many open files this server supports on the one socket
2278 static bool run_maxfidtest(int dummy
)
2280 struct cli_state
*cli
;
2281 const char *ftemplate
= "\\maxfid.%d.%d";
2283 int fnums
[0x11000], i
;
2285 bool correct
= True
;
2290 printf("failed to connect\n");
2294 cli_sockopt(cli
, sockops
);
2296 for (i
=0; i
<0x11000; i
++) {
2297 slprintf(fname
,sizeof(fname
)-1,ftemplate
, i
,(int)getpid());
2298 if ((fnums
[i
] = cli_open(cli
, fname
,
2299 O_RDWR
|O_CREAT
|O_TRUNC
, DENY_NONE
)) ==
2301 printf("open of %s failed (%s)\n",
2302 fname
, cli_errstr(cli
));
2303 printf("maximum fnum is %d\n", i
);
2311 printf("cleaning up\n");
2313 slprintf(fname
,sizeof(fname
)-1,ftemplate
, i
,(int)getpid());
2314 cli_close(cli
, fnums
[i
]);
2315 if (!cli_unlink(cli
, fname
)) {
2316 printf("unlink of %s failed (%s)\n",
2317 fname
, cli_errstr(cli
));
2324 printf("maxfid test finished\n");
2325 if (!torture_close_connection(cli
)) {
2331 /* generate a random buffer */
2332 static void rand_buf(char *buf
, int len
)
2335 *buf
= (char)sys_random();
2340 /* send smb negprot commands, not reading the response */
2341 static bool run_negprot_nowait(int dummy
)
2344 static struct cli_state
*cli
;
2345 bool correct
= True
;
2347 printf("starting negprot nowait test\n");
2349 if (!(cli
= open_nbt_connection())) {
2353 for (i
=0;i
<50000;i
++) {
2354 cli_negprot_sendsync(cli
);
2357 if (!torture_close_connection(cli
)) {
2361 printf("finished negprot nowait test\n");
2367 /* send random IPC commands */
2368 static bool run_randomipc(int dummy
)
2370 char *rparam
= NULL
;
2372 unsigned int rdrcnt
,rprcnt
;
2374 int api
, param_len
, i
;
2375 struct cli_state
*cli
;
2376 bool correct
= True
;
2379 printf("starting random ipc test\n");
2381 if (!torture_open_connection(&cli
, 0)) {
2385 for (i
=0;i
<count
;i
++) {
2386 api
= sys_random() % 500;
2387 param_len
= (sys_random() % 64);
2389 rand_buf(param
, param_len
);
2394 param
, param_len
, 8,
2395 NULL
, 0, BUFFER_SIZE
,
2399 printf("%d/%d\r", i
,count
);
2402 printf("%d/%d\n", i
, count
);
2404 if (!torture_close_connection(cli
)) {
2408 printf("finished random ipc test\n");
2415 static void browse_callback(const char *sname
, uint32 stype
,
2416 const char *comment
, void *state
)
2418 printf("\t%20.20s %08x %s\n", sname
, stype
, comment
);
2424 This test checks the browse list code
2427 static bool run_browsetest(int dummy
)
2429 static struct cli_state
*cli
;
2430 bool correct
= True
;
2432 printf("starting browse test\n");
2434 if (!torture_open_connection(&cli
, 0)) {
2438 printf("domain list:\n");
2439 cli_NetServerEnum(cli
, cli
->server_domain
,
2440 SV_TYPE_DOMAIN_ENUM
,
2441 browse_callback
, NULL
);
2443 printf("machine list:\n");
2444 cli_NetServerEnum(cli
, cli
->server_domain
,
2446 browse_callback
, NULL
);
2448 if (!torture_close_connection(cli
)) {
2452 printf("browse test finished\n");
2460 This checks how the getatr calls works
2462 static bool run_attrtest(int dummy
)
2464 struct cli_state
*cli
;
2467 const char *fname
= "\\attrib123456789.tst";
2468 bool correct
= True
;
2470 printf("starting attrib test\n");
2472 if (!torture_open_connection(&cli
, 0)) {
2476 cli_unlink(cli
, fname
);
2477 fnum
= cli_open(cli
, fname
,
2478 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
);
2479 cli_close(cli
, fnum
);
2480 if (!cli_getatr(cli
, fname
, NULL
, NULL
, &t
)) {
2481 printf("getatr failed (%s)\n", cli_errstr(cli
));
2485 if (abs(t
- time(NULL
)) > 60*60*24*10) {
2486 printf("ERROR: SMBgetatr bug. time is %s",
2492 t2
= t
-60*60*24; /* 1 day ago */
2494 if (!cli_setatr(cli
, fname
, 0, t2
)) {
2495 printf("setatr failed (%s)\n", cli_errstr(cli
));
2499 if (!cli_getatr(cli
, fname
, NULL
, NULL
, &t
)) {
2500 printf("getatr failed (%s)\n", cli_errstr(cli
));
2505 printf("ERROR: getatr/setatr bug. times are\n%s",
2507 printf("%s", ctime(&t2
));
2511 cli_unlink(cli
, fname
);
2513 if (!torture_close_connection(cli
)) {
2517 printf("attrib test finished\n");
2524 This checks a couple of trans2 calls
2526 static bool run_trans2test(int dummy
)
2528 struct cli_state
*cli
;
2531 time_t c_time
, a_time
, m_time
;
2532 struct timespec c_time_ts
, a_time_ts
, m_time_ts
, w_time_ts
, m_time2_ts
;
2533 const char *fname
= "\\trans2.tst";
2534 const char *dname
= "\\trans2";
2535 const char *fname2
= "\\trans2\\trans2.tst";
2537 bool correct
= True
;
2539 printf("starting trans2 test\n");
2541 if (!torture_open_connection(&cli
, 0)) {
2545 cli_unlink(cli
, fname
);
2546 fnum
= cli_open(cli
, fname
,
2547 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
);
2548 if (!cli_qfileinfo(cli
, fnum
, NULL
, &size
, &c_time_ts
, &a_time_ts
, &w_time_ts
,
2549 &m_time_ts
, NULL
)) {
2550 printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(cli
));
2554 if (!cli_qfilename(cli
, fnum
, pname
, sizeof(pname
))) {
2555 printf("ERROR: qfilename failed (%s)\n", cli_errstr(cli
));
2559 if (strcmp(pname
, fname
)) {
2560 printf("qfilename gave different name? [%s] [%s]\n",
2565 cli_close(cli
, fnum
);
2569 cli_unlink(cli
, fname
);
2570 fnum
= cli_open(cli
, fname
,
2571 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
);
2573 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
2576 cli_close(cli
, fnum
);
2578 if (!cli_qpathinfo(cli
, fname
, &c_time
, &a_time
, &m_time
, &size
, NULL
)) {
2579 printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(cli
));
2582 if (c_time
!= m_time
) {
2583 printf("create time=%s", ctime(&c_time
));
2584 printf("modify time=%s", ctime(&m_time
));
2585 printf("This system appears to have sticky create times\n");
2587 if (a_time
% (60*60) == 0) {
2588 printf("access time=%s", ctime(&a_time
));
2589 printf("This system appears to set a midnight access time\n");
2593 if (abs(m_time
- time(NULL
)) > 60*60*24*7) {
2594 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time
));
2600 cli_unlink(cli
, fname
);
2601 fnum
= cli_open(cli
, fname
,
2602 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
);
2603 cli_close(cli
, fnum
);
2604 if (!cli_qpathinfo2(cli
, fname
, &c_time_ts
, &a_time_ts
, &w_time_ts
,
2605 &m_time_ts
, &size
, NULL
, NULL
)) {
2606 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli
));
2609 if (w_time_ts
.tv_sec
< 60*60*24*2) {
2610 printf("write time=%s", ctime(&w_time_ts
.tv_sec
));
2611 printf("This system appears to set a initial 0 write time\n");
2616 cli_unlink(cli
, fname
);
2619 /* check if the server updates the directory modification time
2620 when creating a new file */
2621 if (!cli_mkdir(cli
, dname
)) {
2622 printf("ERROR: mkdir failed (%s)\n", cli_errstr(cli
));
2626 if (!cli_qpathinfo2(cli
, "\\trans2\\", &c_time_ts
, &a_time_ts
, &w_time_ts
,
2627 &m_time_ts
, &size
, NULL
, NULL
)) {
2628 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli
));
2632 fnum
= cli_open(cli
, fname2
,
2633 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
);
2634 cli_write(cli
, fnum
, 0, (char *)&fnum
, 0, sizeof(fnum
));
2635 cli_close(cli
, fnum
);
2636 if (!cli_qpathinfo2(cli
, "\\trans2\\", &c_time_ts
, &a_time_ts
, &w_time_ts
,
2637 &m_time2_ts
, &size
, NULL
, NULL
)) {
2638 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli
));
2641 if (memcmp(&m_time_ts
, &m_time2_ts
, sizeof(struct timespec
))
2643 printf("This system does not update directory modification times\n");
2647 cli_unlink(cli
, fname2
);
2648 cli_rmdir(cli
, dname
);
2650 if (!torture_close_connection(cli
)) {
2654 printf("trans2 test finished\n");
2660 This checks new W2K calls.
2663 static bool new_trans(struct cli_state
*pcli
, int fnum
, int level
)
2667 bool correct
= True
;
2669 if (!cli_qfileinfo_test(pcli
, fnum
, level
, &buf
, &len
)) {
2670 printf("ERROR: qfileinfo (%d) failed (%s)\n", level
, cli_errstr(pcli
));
2673 printf("qfileinfo: level %d, len = %u\n", level
, len
);
2674 dump_data(0, (uint8
*)buf
, len
);
2681 static bool run_w2ktest(int dummy
)
2683 struct cli_state
*cli
;
2685 const char *fname
= "\\w2ktest\\w2k.tst";
2687 bool correct
= True
;
2689 printf("starting w2k test\n");
2691 if (!torture_open_connection(&cli
, 0)) {
2695 fnum
= cli_open(cli
, fname
,
2696 O_RDWR
| O_CREAT
, DENY_NONE
);
2698 for (level
= 1004; level
< 1040; level
++) {
2699 new_trans(cli
, fnum
, level
);
2702 cli_close(cli
, fnum
);
2704 if (!torture_close_connection(cli
)) {
2708 printf("w2k test finished\n");
2715 this is a harness for some oplock tests
2717 static bool run_oplock1(int dummy
)
2719 struct cli_state
*cli1
;
2720 const char *fname
= "\\lockt1.lck";
2722 bool correct
= True
;
2724 printf("starting oplock test 1\n");
2726 if (!torture_open_connection(&cli1
, 0)) {
2730 cli_unlink(cli1
, fname
);
2732 cli_sockopt(cli1
, sockops
);
2734 cli1
->use_oplocks
= True
;
2736 fnum1
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
2738 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
2742 cli1
->use_oplocks
= False
;
2744 cli_unlink(cli1
, fname
);
2745 cli_unlink(cli1
, fname
);
2747 if (!cli_close(cli1
, fnum1
)) {
2748 printf("close2 failed (%s)\n", cli_errstr(cli1
));
2752 if (!cli_unlink(cli1
, fname
)) {
2753 printf("unlink failed (%s)\n", cli_errstr(cli1
));
2757 if (!torture_close_connection(cli1
)) {
2761 printf("finished oplock test 1\n");
2766 static bool run_oplock2(int dummy
)
2768 struct cli_state
*cli1
, *cli2
;
2769 const char *fname
= "\\lockt2.lck";
2771 int saved_use_oplocks
= use_oplocks
;
2773 bool correct
= True
;
2774 volatile bool *shared_correct
;
2776 shared_correct
= (volatile bool *)shm_setup(sizeof(bool));
2777 *shared_correct
= True
;
2779 use_level_II_oplocks
= True
;
2782 printf("starting oplock test 2\n");
2784 if (!torture_open_connection(&cli1
, 0)) {
2785 use_level_II_oplocks
= False
;
2786 use_oplocks
= saved_use_oplocks
;
2790 cli1
->use_oplocks
= True
;
2791 cli1
->use_level_II_oplocks
= True
;
2793 if (!torture_open_connection(&cli2
, 1)) {
2794 use_level_II_oplocks
= False
;
2795 use_oplocks
= saved_use_oplocks
;
2799 cli2
->use_oplocks
= True
;
2800 cli2
->use_level_II_oplocks
= True
;
2802 cli_unlink(cli1
, fname
);
2804 cli_sockopt(cli1
, sockops
);
2805 cli_sockopt(cli2
, sockops
);
2807 fnum1
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
2809 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
2813 /* Don't need the globals any more. */
2814 use_level_II_oplocks
= False
;
2815 use_oplocks
= saved_use_oplocks
;
2819 fnum2
= cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
);
2821 printf("second open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
2822 *shared_correct
= False
;
2828 if (!cli_close(cli2
, fnum2
)) {
2829 printf("close2 failed (%s)\n", cli_errstr(cli1
));
2830 *shared_correct
= False
;
2838 /* Ensure cli1 processes the break. Empty file should always return 0
2841 if (cli_read(cli1
, fnum1
, buf
, 0, 4) != 0) {
2842 printf("read on fnum1 failed (%s)\n", cli_errstr(cli1
));
2846 /* Should now be at level II. */
2847 /* Test if sending a write locks causes a break to none. */
2849 if (!cli_lock(cli1
, fnum1
, 0, 4, 0, READ_LOCK
)) {
2850 printf("lock failed (%s)\n", cli_errstr(cli1
));
2854 cli_unlock(cli1
, fnum1
, 0, 4);
2858 if (!cli_lock(cli1
, fnum1
, 0, 4, 0, WRITE_LOCK
)) {
2859 printf("lock failed (%s)\n", cli_errstr(cli1
));
2863 cli_unlock(cli1
, fnum1
, 0, 4);
2867 cli_read(cli1
, fnum1
, buf
, 0, 4);
2870 if (cli_write(cli1
, fnum1
, 0, buf
, 0, 4) != 4) {
2871 printf("write on fnum1 failed (%s)\n", cli_errstr(cli1
));
2876 if (!cli_close(cli1
, fnum1
)) {
2877 printf("close1 failed (%s)\n", cli_errstr(cli1
));
2883 if (!cli_unlink(cli1
, fname
)) {
2884 printf("unlink failed (%s)\n", cli_errstr(cli1
));
2888 if (!torture_close_connection(cli1
)) {
2892 if (!*shared_correct
) {
2896 printf("finished oplock test 2\n");
2901 /* handler for oplock 3 tests */
2902 static bool oplock3_handler(struct cli_state
*cli
, int fnum
, unsigned char level
)
2904 printf("got oplock break fnum=%d level=%d\n",
2906 return cli_oplock_ack(cli
, fnum
, level
);
2909 static bool run_oplock3(int dummy
)
2911 struct cli_state
*cli
;
2912 const char *fname
= "\\oplockt3.dat";
2914 char buf
[4] = "abcd";
2915 bool correct
= True
;
2916 volatile bool *shared_correct
;
2918 shared_correct
= (volatile bool *)shm_setup(sizeof(bool));
2919 *shared_correct
= True
;
2921 printf("starting oplock test 3\n");
2926 use_level_II_oplocks
= True
;
2927 if (!torture_open_connection(&cli
, 0)) {
2928 *shared_correct
= False
;
2932 /* try to trigger a oplock break in parent */
2933 fnum
= cli_open(cli
, fname
, O_RDWR
, DENY_NONE
);
2934 cli_write(cli
, fnum
, 0, buf
, 0, 4);
2940 use_level_II_oplocks
= True
;
2941 if (!torture_open_connection(&cli
, 1)) { /* other is forked */
2944 cli_oplock_handler(cli
, oplock3_handler
);
2945 fnum
= cli_open(cli
, fname
, O_RDWR
|O_CREAT
, DENY_NONE
);
2946 cli_write(cli
, fnum
, 0, buf
, 0, 4);
2947 cli_close(cli
, fnum
);
2948 fnum
= cli_open(cli
, fname
, O_RDWR
, DENY_NONE
);
2949 cli
->timeout
= 20000;
2950 cli_receive_smb(cli
);
2951 printf("finished oplock test 3\n");
2953 return (correct
&& *shared_correct
);
2955 /* What are we looking for here? What's sucess and what's FAILURE? */
2961 Test delete on close semantics.
2963 static bool run_deletetest(int dummy
)
2965 struct cli_state
*cli1
= NULL
;
2966 struct cli_state
*cli2
= NULL
;
2967 const char *fname
= "\\delete.file";
2970 bool correct
= True
;
2972 printf("starting delete test\n");
2974 if (!torture_open_connection(&cli1
, 0)) {
2978 cli_sockopt(cli1
, sockops
);
2980 /* Test 1 - this should delete the file on close. */
2982 cli_setatr(cli1
, fname
, 0, 0);
2983 cli_unlink(cli1
, fname
);
2985 fnum1
= cli_nt_create_full(cli1
, fname
, 0, GENERIC_ALL_ACCESS
|DELETE_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
2986 0, FILE_OVERWRITE_IF
,
2987 FILE_DELETE_ON_CLOSE
, 0);
2990 printf("[1] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
2997 uint32
*accinfo
= NULL
;
2999 cli_qfileinfo_test(cli1
, fnum1
, SMB_FILE_ACCESS_INFORMATION
, (char **)&accinfo
, &len
);
3001 printf("access mode = 0x%lx\n", *accinfo
);
3006 if (!cli_close(cli1
, fnum1
)) {
3007 printf("[1] close failed (%s)\n", cli_errstr(cli1
));
3012 fnum1
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
);
3014 printf("[1] open of %s succeeded (should fail)\n", fname
);
3019 printf("first delete on close test succeeded.\n");
3021 /* Test 2 - this should delete the file on close. */
3023 cli_setatr(cli1
, fname
, 0, 0);
3024 cli_unlink(cli1
, fname
);
3026 fnum1
= cli_nt_create_full(cli1
, fname
, 0, GENERIC_ALL_ACCESS
,
3027 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
3028 FILE_OVERWRITE_IF
, 0, 0);
3031 printf("[2] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3036 if (!cli_nt_delete_on_close(cli1
, fnum1
, True
)) {
3037 printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(cli1
));
3042 if (!cli_close(cli1
, fnum1
)) {
3043 printf("[2] close failed (%s)\n", cli_errstr(cli1
));
3048 fnum1
= cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
);
3050 printf("[2] open of %s succeeded should have been deleted on close !\n", fname
);
3051 if (!cli_close(cli1
, fnum1
)) {
3052 printf("[2] close failed (%s)\n", cli_errstr(cli1
));
3056 cli_unlink(cli1
, fname
);
3058 printf("second delete on close test succeeded.\n");
3061 cli_setatr(cli1
, fname
, 0, 0);
3062 cli_unlink(cli1
, fname
);
3064 fnum1
= cli_nt_create_full(cli1
, fname
, 0, GENERIC_ALL_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3065 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OVERWRITE_IF
, 0, 0);
3068 printf("[3] open - 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3073 /* This should fail with a sharing violation - open for delete is only compatible
3074 with SHARE_DELETE. */
3076 fnum2
= cli_nt_create_full(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3077 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN
, 0, 0);
3080 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname
);
3085 /* This should succeed. */
3087 fnum2
= cli_nt_create_full(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3088 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, FILE_OPEN
, 0, 0);
3091 printf("[3] open - 2 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3096 if (!cli_nt_delete_on_close(cli1
, fnum1
, True
)) {
3097 printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(cli1
));
3102 if (!cli_close(cli1
, fnum1
)) {
3103 printf("[3] close 1 failed (%s)\n", cli_errstr(cli1
));
3108 if (!cli_close(cli1
, fnum2
)) {
3109 printf("[3] close 2 failed (%s)\n", cli_errstr(cli1
));
3114 /* This should fail - file should no longer be there. */
3116 fnum1
= cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
);
3118 printf("[3] open of %s succeeded should have been deleted on close !\n", fname
);
3119 if (!cli_close(cli1
, fnum1
)) {
3120 printf("[3] close failed (%s)\n", cli_errstr(cli1
));
3122 cli_unlink(cli1
, fname
);
3126 printf("third delete on close test succeeded.\n");
3129 cli_setatr(cli1
, fname
, 0, 0);
3130 cli_unlink(cli1
, fname
);
3132 fnum1
= cli_nt_create_full(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
3133 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OVERWRITE_IF
, 0, 0);
3136 printf("[4] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3141 /* This should succeed. */
3142 fnum2
= cli_nt_create_full(cli1
, fname
, 0, GENERIC_READ_ACCESS
,
3143 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, FILE_OPEN
, 0, 0);
3145 printf("[4] open - 2 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3150 if (!cli_close(cli1
, fnum2
)) {
3151 printf("[4] close - 1 failed (%s)\n", cli_errstr(cli1
));
3156 if (!cli_nt_delete_on_close(cli1
, fnum1
, True
)) {
3157 printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(cli1
));
3162 /* This should fail - no more opens once delete on close set. */
3163 fnum2
= cli_nt_create_full(cli1
, fname
, 0, GENERIC_READ_ACCESS
,
3164 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
3167 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname
);
3171 printf("fourth delete on close test succeeded.\n");
3173 if (!cli_close(cli1
, fnum1
)) {
3174 printf("[4] close - 2 failed (%s)\n", cli_errstr(cli1
));
3180 cli_setatr(cli1
, fname
, 0, 0);
3181 cli_unlink(cli1
, fname
);
3183 fnum1
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
, DENY_NONE
);
3185 printf("[5] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3190 /* This should fail - only allowed on NT opens with DELETE access. */
3192 if (cli_nt_delete_on_close(cli1
, fnum1
, True
)) {
3193 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
3198 if (!cli_close(cli1
, fnum1
)) {
3199 printf("[5] close - 2 failed (%s)\n", cli_errstr(cli1
));
3204 printf("fifth delete on close test succeeded.\n");
3207 cli_setatr(cli1
, fname
, 0, 0);
3208 cli_unlink(cli1
, fname
);
3210 fnum1
= cli_nt_create_full(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
,
3211 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
3212 FILE_OVERWRITE_IF
, 0, 0);
3215 printf("[6] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3220 /* This should fail - only allowed on NT opens with DELETE access. */
3222 if (cli_nt_delete_on_close(cli1
, fnum1
, True
)) {
3223 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
3228 if (!cli_close(cli1
, fnum1
)) {
3229 printf("[6] close - 2 failed (%s)\n", cli_errstr(cli1
));
3234 printf("sixth delete on close test succeeded.\n");
3237 cli_setatr(cli1
, fname
, 0, 0);
3238 cli_unlink(cli1
, fname
);
3240 fnum1
= cli_nt_create_full(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
3241 FILE_ATTRIBUTE_NORMAL
, 0, FILE_OVERWRITE_IF
, 0, 0);
3244 printf("[7] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3249 if (!cli_nt_delete_on_close(cli1
, fnum1
, True
)) {
3250 printf("[7] setting delete_on_close on file failed !\n");
3255 if (!cli_nt_delete_on_close(cli1
, fnum1
, False
)) {
3256 printf("[7] unsetting delete_on_close on file failed !\n");
3261 if (!cli_close(cli1
, fnum1
)) {
3262 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1
));
3267 /* This next open should succeed - we reset the flag. */
3269 fnum1
= cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
);
3271 printf("[5] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3276 if (!cli_close(cli1
, fnum1
)) {
3277 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1
));
3282 printf("seventh delete on close test succeeded.\n");
3285 cli_setatr(cli1
, fname
, 0, 0);
3286 cli_unlink(cli1
, fname
);
3288 if (!torture_open_connection(&cli2
, 1)) {
3289 printf("[8] failed to open second connection.\n");
3294 cli_sockopt(cli1
, sockops
);
3296 fnum1
= cli_nt_create_full(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
3297 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
3298 FILE_OVERWRITE_IF
, 0, 0);
3301 printf("[8] open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3306 fnum2
= cli_nt_create_full(cli2
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
3307 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
3311 printf("[8] open 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
3316 if (!cli_nt_delete_on_close(cli1
, fnum1
, True
)) {
3317 printf("[8] setting delete_on_close on file failed !\n");
3322 if (!cli_close(cli1
, fnum1
)) {
3323 printf("[8] close - 1 failed (%s)\n", cli_errstr(cli1
));
3328 if (!cli_close(cli2
, fnum2
)) {
3329 printf("[8] close - 2 failed (%s)\n", cli_errstr(cli2
));
3334 /* This should fail.. */
3335 fnum1
= cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
);
3337 printf("[8] open of %s succeeded should have been deleted on close !\n", fname
);
3341 printf("eighth delete on close test succeeded.\n");
3343 /* This should fail - we need to set DELETE_ACCESS. */
3344 fnum1
= cli_nt_create_full(cli1
, fname
, 0,FILE_READ_DATA
|FILE_WRITE_DATA
,
3345 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, FILE_DELETE_ON_CLOSE
, 0);
3348 printf("[9] open of %s succeeded should have failed!\n", fname
);
3353 printf("ninth delete on close test succeeded.\n");
3355 fnum1
= cli_nt_create_full(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
3356 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, FILE_DELETE_ON_CLOSE
, 0);
3358 printf("[10] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3363 /* This should delete the file. */
3364 if (!cli_close(cli1
, fnum1
)) {
3365 printf("[10] close failed (%s)\n", cli_errstr(cli1
));
3370 /* This should fail.. */
3371 fnum1
= cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
);
3373 printf("[10] open of %s succeeded should have been deleted on close !\n", fname
);
3377 printf("tenth delete on close test succeeded.\n");
3379 cli_setatr(cli1
, fname
, 0, 0);
3380 cli_unlink(cli1
, fname
);
3382 /* What error do we get when attempting to open a read-only file with
3385 /* Create a readonly file. */
3386 fnum1
= cli_nt_create_full(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
,
3387 FILE_ATTRIBUTE_READONLY
, FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0);
3389 printf("[11] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3394 if (!cli_close(cli1
, fnum1
)) {
3395 printf("[11] close failed (%s)\n", cli_errstr(cli1
));
3400 /* Now try open for delete access. */
3401 fnum1
= cli_nt_create_full(cli1
, fname
, 0, FILE_READ_ATTRIBUTES
|DELETE_ACCESS
,
3402 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
3403 FILE_OVERWRITE_IF
, 0, 0);
3406 printf("[11] open of %s succeeded should have been denied with ACCESS_DENIED!\n", fname
);
3407 cli_close(cli1
, fnum1
);
3411 NTSTATUS nterr
= cli_nt_error(cli1
);
3412 if (!NT_STATUS_EQUAL(nterr
,NT_STATUS_ACCESS_DENIED
)) {
3413 printf("[11] open of %s should have been denied with ACCESS_DENIED! Got error %s\n", fname
, nt_errstr(nterr
));
3417 printf("eleventh delete on close test succeeded.\n");
3421 printf("finished delete test\n");
3424 /* FIXME: This will crash if we aborted before cli2 got
3425 * intialized, because these functions don't handle
3426 * uninitialized connections. */
3428 if (fnum1
!= -1) cli_close(cli1
, fnum1
);
3429 if (fnum2
!= -1) cli_close(cli1
, fnum2
);
3430 cli_setatr(cli1
, fname
, 0, 0);
3431 cli_unlink(cli1
, fname
);
3433 if (cli1
&& !torture_close_connection(cli1
)) {
3436 if (cli2
&& !torture_close_connection(cli2
)) {
3444 print out server properties
3446 static bool run_properties(int dummy
)
3448 static struct cli_state
*cli
;
3449 bool correct
= True
;
3451 printf("starting properties test\n");
3455 if (!torture_open_connection(&cli
, 0)) {
3459 cli_sockopt(cli
, sockops
);
3461 d_printf("Capabilities 0x%08x\n", cli
->capabilities
);
3463 if (!torture_close_connection(cli
)) {
3472 /* FIRST_DESIRED_ACCESS 0xf019f */
3473 #define FIRST_DESIRED_ACCESS FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|\
3474 FILE_READ_EA| /* 0xf */ \
3475 FILE_WRITE_EA|FILE_READ_ATTRIBUTES| /* 0x90 */ \
3476 FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
3477 DELETE_ACCESS|READ_CONTROL_ACCESS|\
3478 WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS /* 0xf0000 */
3479 /* SECOND_DESIRED_ACCESS 0xe0080 */
3480 #define SECOND_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
3481 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
3482 WRITE_OWNER_ACCESS /* 0xe0000 */
3485 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
3486 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
3488 WRITE_OWNER_ACCESS /* */
3492 Test ntcreate calls made by xcopy
3494 static bool run_xcopy(int dummy
)
3496 static struct cli_state
*cli1
;
3497 const char *fname
= "\\test.txt";
3498 bool correct
= True
;
3501 printf("starting xcopy test\n");
3503 if (!torture_open_connection(&cli1
, 0)) {
3507 fnum1
= cli_nt_create_full(cli1
, fname
, 0,
3508 FIRST_DESIRED_ACCESS
, FILE_ATTRIBUTE_ARCHIVE
,
3509 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
,
3513 printf("First open failed - %s\n", cli_errstr(cli1
));
3517 fnum2
= cli_nt_create_full(cli1
, fname
, 0,
3518 SECOND_DESIRED_ACCESS
, 0,
3519 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, FILE_OPEN
,
3522 printf("second open failed - %s\n", cli_errstr(cli1
));
3526 if (!torture_close_connection(cli1
)) {
3534 Test rename on files open with share delete and no share delete.
3536 static bool run_rename(int dummy
)
3538 static struct cli_state
*cli1
;
3539 const char *fname
= "\\test.txt";
3540 const char *fname1
= "\\test1.txt";
3541 bool correct
= True
;
3544 printf("starting rename test\n");
3546 if (!torture_open_connection(&cli1
, 0)) {
3550 cli_unlink(cli1
, fname
);
3551 cli_unlink(cli1
, fname1
);
3552 fnum1
= cli_nt_create_full(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3553 FILE_SHARE_READ
, FILE_OVERWRITE_IF
, 0, 0);
3556 printf("First open failed - %s\n", cli_errstr(cli1
));
3560 if (!cli_rename(cli1
, fname
, fname1
)) {
3561 printf("First rename failed (SHARE_READ) (this is correct) - %s\n", cli_errstr(cli1
));
3563 printf("First rename succeeded (SHARE_READ) - this should have failed !\n");
3567 if (!cli_close(cli1
, fnum1
)) {
3568 printf("close - 1 failed (%s)\n", cli_errstr(cli1
));
3572 cli_unlink(cli1
, fname
);
3573 cli_unlink(cli1
, fname1
);
3574 fnum1
= cli_nt_create_full(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3576 FILE_SHARE_DELETE
|FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0);
3578 FILE_SHARE_DELETE
|FILE_SHARE_READ
, FILE_OVERWRITE_IF
, 0, 0);
3582 printf("Second open failed - %s\n", cli_errstr(cli1
));
3586 if (!cli_rename(cli1
, fname
, fname1
)) {
3587 printf("Second rename failed (SHARE_DELETE | SHARE_READ) - this should have succeeded - %s\n", cli_errstr(cli1
));
3590 printf("Second rename succeeded (SHARE_DELETE | SHARE_READ)\n");
3593 if (!cli_close(cli1
, fnum1
)) {
3594 printf("close - 2 failed (%s)\n", cli_errstr(cli1
));
3598 cli_unlink(cli1
, fname
);
3599 cli_unlink(cli1
, fname1
);
3601 fnum1
= cli_nt_create_full(cli1
, fname
, 0, READ_CONTROL_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3602 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0);
3605 printf("Third open failed - %s\n", cli_errstr(cli1
));
3614 fnum2
= cli_nt_create_full(cli1
, fname
, 0, DELETE_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3615 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0);
3618 printf("Fourth open failed - %s\n", cli_errstr(cli1
));
3621 if (!cli_nt_delete_on_close(cli1
, fnum2
, True
)) {
3622 printf("[8] setting delete_on_close on file failed !\n");
3626 if (!cli_close(cli1
, fnum2
)) {
3627 printf("close - 4 failed (%s)\n", cli_errstr(cli1
));
3633 if (!cli_rename(cli1
, fname
, fname1
)) {
3634 printf("Third rename failed (SHARE_NONE) - this should have succeeded - %s\n", cli_errstr(cli1
));
3637 printf("Third rename succeeded (SHARE_NONE)\n");
3640 if (!cli_close(cli1
, fnum1
)) {
3641 printf("close - 3 failed (%s)\n", cli_errstr(cli1
));
3645 cli_unlink(cli1
, fname
);
3646 cli_unlink(cli1
, fname1
);
3650 fnum1
= cli_nt_create_full(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3651 FILE_SHARE_READ
| FILE_SHARE_WRITE
, FILE_OVERWRITE_IF
, 0, 0);
3654 printf("Fourth open failed - %s\n", cli_errstr(cli1
));
3658 if (!cli_rename(cli1
, fname
, fname1
)) {
3659 printf("Fourth rename failed (SHARE_READ | SHARE_WRITE) (this is correct) - %s\n", cli_errstr(cli1
));
3661 printf("Fourth rename succeeded (SHARE_READ | SHARE_WRITE) - this should have failed !\n");
3665 if (!cli_close(cli1
, fnum1
)) {
3666 printf("close - 4 failed (%s)\n", cli_errstr(cli1
));
3670 cli_unlink(cli1
, fname
);
3671 cli_unlink(cli1
, fname1
);
3675 fnum1
= cli_nt_create_full(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3676 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
, FILE_OVERWRITE_IF
, 0, 0);
3679 printf("Fifth open failed - %s\n", cli_errstr(cli1
));
3683 if (!cli_rename(cli1
, fname
, fname1
)) {
3684 printf("Fifth rename failed (SHARE_READ | SHARE_WRITE | SHARE_DELETE) - this should have succeeded - %s ! \n",
3688 printf("Fifth rename succeeded (SHARE_READ | SHARE_WRITE | SHARE_DELETE) (this is correct) - %s\n", cli_errstr(cli1
));
3692 * Now check if the first name still exists ...
3695 /*fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3696 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0);
3699 printf("Opening original file after rename of open file fails: %s\n",
3703 printf("Opening original file after rename of open file works ...\n");
3704 (void)cli_close(cli1, fnum2);
3710 if (!cli_close(cli1
, fnum1
)) {
3711 printf("close - 5 failed (%s)\n", cli_errstr(cli1
));
3715 cli_unlink(cli1
, fname
);
3716 cli_unlink(cli1
, fname1
);
3718 if (!torture_close_connection(cli1
)) {
3725 static bool run_pipe_number(int dummy
)
3727 struct cli_state
*cli1
;
3728 const char *pipe_name
= "\\SPOOLSS";
3732 printf("starting pipenumber test\n");
3733 if (!torture_open_connection(&cli1
, 0)) {
3737 cli_sockopt(cli1
, sockops
);
3739 fnum
= cli_nt_create_full(cli1
, pipe_name
, 0, FILE_READ_DATA
, FILE_ATTRIBUTE_NORMAL
,
3740 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN_IF
, 0, 0);
3743 printf("Open of pipe %s failed with error (%s)\n", pipe_name
, cli_errstr(cli1
));
3747 printf("\r%6d", num_pipes
);
3750 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes
, pipe_name
);
3751 torture_close_connection(cli1
);
3756 Test open mode returns on read-only files.
3758 static bool run_opentest(int dummy
)
3760 static struct cli_state
*cli1
;
3761 static struct cli_state
*cli2
;
3762 const char *fname
= "\\readonly.file";
3766 bool correct
= True
;
3769 printf("starting open test\n");
3771 if (!torture_open_connection(&cli1
, 0)) {
3775 cli_setatr(cli1
, fname
, 0, 0);
3776 cli_unlink(cli1
, fname
);
3778 cli_sockopt(cli1
, sockops
);
3780 fnum1
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
3782 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3786 if (!cli_close(cli1
, fnum1
)) {
3787 printf("close2 failed (%s)\n", cli_errstr(cli1
));
3791 if (!cli_setatr(cli1
, fname
, aRONLY
, 0)) {
3792 printf("cli_setatr failed (%s)\n", cli_errstr(cli1
));
3796 fnum1
= cli_open(cli1
, fname
, O_RDONLY
, DENY_WRITE
);
3798 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3802 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
3803 fnum2
= cli_open(cli1
, fname
, O_RDWR
, DENY_ALL
);
3805 if (check_error(__LINE__
, cli1
, ERRDOS
, ERRnoaccess
,
3806 NT_STATUS_ACCESS_DENIED
)) {
3807 printf("correct error code ERRDOS/ERRnoaccess returned\n");
3810 printf("finished open test 1\n");
3812 cli_close(cli1
, fnum1
);
3814 /* Now try not readonly and ensure ERRbadshare is returned. */
3816 cli_setatr(cli1
, fname
, 0, 0);
3818 fnum1
= cli_open(cli1
, fname
, O_RDONLY
, DENY_WRITE
);
3820 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3824 /* This will fail - but the error should be ERRshare. */
3825 fnum2
= cli_open(cli1
, fname
, O_RDWR
, DENY_ALL
);
3827 if (check_error(__LINE__
, cli1
, ERRDOS
, ERRbadshare
,
3828 NT_STATUS_SHARING_VIOLATION
)) {
3829 printf("correct error code ERRDOS/ERRbadshare returned\n");
3832 if (!cli_close(cli1
, fnum1
)) {
3833 printf("close2 failed (%s)\n", cli_errstr(cli1
));
3837 cli_unlink(cli1
, fname
);
3839 printf("finished open test 2\n");
3841 /* Test truncate open disposition on file opened for read. */
3843 fnum1
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
3845 printf("(3) open (1) of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3849 /* write 20 bytes. */
3851 memset(buf
, '\0', 20);
3853 if (cli_write(cli1
, fnum1
, 0, buf
, 0, 20) != 20) {
3854 printf("write failed (%s)\n", cli_errstr(cli1
));
3858 if (!cli_close(cli1
, fnum1
)) {
3859 printf("(3) close1 failed (%s)\n", cli_errstr(cli1
));
3863 /* Ensure size == 20. */
3864 if (!cli_getatr(cli1
, fname
, NULL
, &fsize
, NULL
)) {
3865 printf("(3) getatr failed (%s)\n", cli_errstr(cli1
));
3870 printf("(3) file size != 20\n");
3874 /* Now test if we can truncate a file opened for readonly. */
3876 fnum1
= cli_open(cli1
, fname
, O_RDONLY
|O_TRUNC
, DENY_NONE
);
3878 printf("(3) open (2) of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3882 if (!cli_close(cli1
, fnum1
)) {
3883 printf("close2 failed (%s)\n", cli_errstr(cli1
));
3887 /* Ensure size == 0. */
3888 if (!cli_getatr(cli1
, fname
, NULL
, &fsize
, NULL
)) {
3889 printf("(3) getatr failed (%s)\n", cli_errstr(cli1
));
3894 printf("(3) file size != 0\n");
3897 printf("finished open test 3\n");
3899 cli_unlink(cli1
, fname
);
3902 printf("testing ctemp\n");
3903 fnum1
= cli_ctemp(cli1
, "\\", &tmp_path
);
3905 printf("ctemp failed (%s)\n", cli_errstr(cli1
));
3908 printf("ctemp gave path %s\n", tmp_path
);
3909 if (!cli_close(cli1
, fnum1
)) {
3910 printf("close of temp failed (%s)\n", cli_errstr(cli1
));
3912 if (!cli_unlink(cli1
, tmp_path
)) {
3913 printf("unlink of temp failed (%s)\n", cli_errstr(cli1
));
3916 /* Test the non-io opens... */
3918 if (!torture_open_connection(&cli2
, 1)) {
3922 cli_setatr(cli2
, fname
, 0, 0);
3923 cli_unlink(cli2
, fname
);
3925 cli_sockopt(cli2
, sockops
);
3927 printf("TEST #1 testing 2 non-io opens (no delete)\n");
3929 fnum1
= cli_nt_create_full(cli1
, fname
, 0, FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
3930 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0);
3933 printf("test 1 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3937 fnum2
= cli_nt_create_full(cli2
, fname
, 0, FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
3938 FILE_SHARE_NONE
, FILE_OPEN_IF
, 0, 0);
3941 printf("test 1 open 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
3945 if (!cli_close(cli1
, fnum1
)) {
3946 printf("test 1 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3949 if (!cli_close(cli2
, fnum2
)) {
3950 printf("test 1 close 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
3954 printf("non-io open test #1 passed.\n");
3956 cli_unlink(cli1
, fname
);
3958 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
3960 fnum1
= cli_nt_create_full(cli1
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
3961 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0);
3964 printf("test 2 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3968 fnum2
= cli_nt_create_full(cli2
, fname
, 0, FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
3969 FILE_SHARE_NONE
, FILE_OPEN_IF
, 0, 0);
3972 printf("test 2 open 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
3976 if (!cli_close(cli1
, fnum1
)) {
3977 printf("test 1 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3980 if (!cli_close(cli2
, fnum2
)) {
3981 printf("test 1 close 2 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3985 printf("non-io open test #2 passed.\n");
3987 cli_unlink(cli1
, fname
);
3989 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
3991 fnum1
= cli_nt_create_full(cli1
, fname
, 0, FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
3992 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0);
3995 printf("test 3 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3999 fnum2
= cli_nt_create_full(cli2
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4000 FILE_SHARE_NONE
, FILE_OPEN_IF
, 0, 0);
4003 printf("test 3 open 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
4007 if (!cli_close(cli1
, fnum1
)) {
4008 printf("test 3 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4011 if (!cli_close(cli2
, fnum2
)) {
4012 printf("test 3 close 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
4016 printf("non-io open test #3 passed.\n");
4018 cli_unlink(cli1
, fname
);
4020 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
4022 fnum1
= cli_nt_create_full(cli1
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4023 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0);
4026 printf("test 4 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4030 fnum2
= cli_nt_create_full(cli2
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4031 FILE_SHARE_NONE
, FILE_OPEN_IF
, 0, 0);
4034 printf("test 4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname
, cli_errstr(cli2
));
4038 printf("test 3 open 2 of %s gave %s (correct error should be %s)\n", fname
, cli_errstr(cli2
), "sharing violation");
4040 if (!cli_close(cli1
, fnum1
)) {
4041 printf("test 4 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4045 printf("non-io open test #4 passed.\n");
4047 cli_unlink(cli1
, fname
);
4049 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
4051 fnum1
= cli_nt_create_full(cli1
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4052 FILE_SHARE_DELETE
, FILE_OVERWRITE_IF
, 0, 0);
4055 printf("test 5 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4059 fnum2
= cli_nt_create_full(cli2
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4060 FILE_SHARE_DELETE
, FILE_OPEN_IF
, 0, 0);
4063 printf("test 5 open 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
4067 if (!cli_close(cli1
, fnum1
)) {
4068 printf("test 5 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4072 if (!cli_close(cli2
, fnum2
)) {
4073 printf("test 5 close 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
4077 printf("non-io open test #5 passed.\n");
4079 printf("TEST #6 testing 1 non-io open, one io open\n");
4081 cli_unlink(cli1
, fname
);
4083 fnum1
= cli_nt_create_full(cli1
, fname
, 0, FILE_READ_DATA
, FILE_ATTRIBUTE_NORMAL
,
4084 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0);
4087 printf("test 6 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4091 fnum2
= cli_nt_create_full(cli2
, fname
, 0, FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4092 FILE_SHARE_READ
, FILE_OPEN_IF
, 0, 0);
4095 printf("test 6 open 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
4099 if (!cli_close(cli1
, fnum1
)) {
4100 printf("test 6 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4104 if (!cli_close(cli2
, fnum2
)) {
4105 printf("test 6 close 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
4109 printf("non-io open test #6 passed.\n");
4111 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
4113 cli_unlink(cli1
, fname
);
4115 fnum1
= cli_nt_create_full(cli1
, fname
, 0, FILE_READ_DATA
, FILE_ATTRIBUTE_NORMAL
,
4116 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0);
4119 printf("test 7 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4123 fnum2
= cli_nt_create_full(cli2
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4124 FILE_SHARE_READ
|FILE_SHARE_DELETE
, FILE_OPEN_IF
, 0, 0);
4127 printf("test 7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname
, cli_errstr(cli2
));
4131 printf("test 7 open 2 of %s gave %s (correct error should be %s)\n", fname
, cli_errstr(cli2
), "sharing violation");
4133 if (!cli_close(cli1
, fnum1
)) {
4134 printf("test 7 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4138 printf("non-io open test #7 passed.\n");
4140 cli_unlink(cli1
, fname
);
4142 if (!torture_close_connection(cli1
)) {
4145 if (!torture_close_connection(cli2
)) {
4152 static uint32 open_attrs_table
[] = {
4153 FILE_ATTRIBUTE_NORMAL
,
4154 FILE_ATTRIBUTE_ARCHIVE
,
4155 FILE_ATTRIBUTE_READONLY
,
4156 FILE_ATTRIBUTE_HIDDEN
,
4157 FILE_ATTRIBUTE_SYSTEM
,
4159 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
,
4160 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
,
4161 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
,
4162 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
,
4163 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
,
4164 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
,
4166 FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
,
4167 FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
,
4168 FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
,
4169 FILE_ATTRIBUTE_HIDDEN
,FILE_ATTRIBUTE_SYSTEM
,
4172 struct trunc_open_results
{
4179 static struct trunc_open_results attr_results
[] = {
4180 { 0, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_ARCHIVE
},
4181 { 1, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_ARCHIVE
},
4182 { 2, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_READONLY
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
},
4183 { 16, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_ARCHIVE
},
4184 { 17, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_ARCHIVE
},
4185 { 18, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_READONLY
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
},
4186 { 51, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
4187 { 54, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
4188 { 56, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
},
4189 { 68, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
4190 { 71, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
4191 { 73, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
},
4192 { 99, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_HIDDEN
,FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
4193 { 102, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
4194 { 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
},
4195 { 116, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
4196 { 119, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
4197 { 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
},
4198 { 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
},
4199 { 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
},
4200 { 227, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
4201 { 230, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
4202 { 232, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
},
4203 { 244, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
4204 { 247, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
4205 { 249, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
}
4208 static bool run_openattrtest(int dummy
)
4210 static struct cli_state
*cli1
;
4211 const char *fname
= "\\openattr.file";
4213 bool correct
= True
;
4215 unsigned int i
, j
, k
, l
;
4217 printf("starting open attr test\n");
4219 if (!torture_open_connection(&cli1
, 0)) {
4223 cli_sockopt(cli1
, sockops
);
4225 for (k
= 0, i
= 0; i
< sizeof(open_attrs_table
)/sizeof(uint32
); i
++) {
4226 cli_setatr(cli1
, fname
, 0, 0);
4227 cli_unlink(cli1
, fname
);
4228 fnum1
= cli_nt_create_full(cli1
, fname
, 0, FILE_WRITE_DATA
, open_attrs_table
[i
],
4229 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0);
4232 printf("open %d (1) of %s failed (%s)\n", i
, fname
, cli_errstr(cli1
));
4236 if (!cli_close(cli1
, fnum1
)) {
4237 printf("close %d (1) of %s failed (%s)\n", i
, fname
, cli_errstr(cli1
));
4241 for (j
= 0; j
< sizeof(open_attrs_table
)/sizeof(uint32
); j
++) {
4242 fnum1
= cli_nt_create_full(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
, open_attrs_table
[j
],
4243 FILE_SHARE_NONE
, FILE_OVERWRITE
, 0, 0);
4246 for (l
= 0; l
< sizeof(attr_results
)/sizeof(struct trunc_open_results
); l
++) {
4247 if (attr_results
[l
].num
== k
) {
4248 printf("[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(0x%x:%s)\n",
4249 k
, open_attrs_table
[i
],
4250 open_attrs_table
[j
],
4251 fname
, NT_STATUS_V(cli_nt_error(cli1
)), cli_errstr(cli1
));
4255 if (NT_STATUS_V(cli_nt_error(cli1
)) != NT_STATUS_V(NT_STATUS_ACCESS_DENIED
)) {
4256 printf("[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s\n",
4257 k
, open_attrs_table
[i
], open_attrs_table
[j
],
4262 printf("[%d] trunc open 0x%x -> 0x%x failed\n", k
, open_attrs_table
[i
], open_attrs_table
[j
]);
4268 if (!cli_close(cli1
, fnum1
)) {
4269 printf("close %d (2) of %s failed (%s)\n", j
, fname
, cli_errstr(cli1
));
4273 if (!cli_getatr(cli1
, fname
, &attr
, NULL
, NULL
)) {
4274 printf("getatr(2) failed (%s)\n", cli_errstr(cli1
));
4279 printf("[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n",
4280 k
, open_attrs_table
[i
], open_attrs_table
[j
], attr
);
4283 for (l
= 0; l
< sizeof(attr_results
)/sizeof(struct trunc_open_results
); l
++) {
4284 if (attr_results
[l
].num
== k
) {
4285 if (attr
!= attr_results
[l
].result_attr
||
4286 open_attrs_table
[i
] != attr_results
[l
].init_attr
||
4287 open_attrs_table
[j
] != attr_results
[l
].trunc_attr
) {
4288 printf("getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x\n",
4289 open_attrs_table
[i
],
4290 open_attrs_table
[j
],
4292 attr_results
[l
].result_attr
);
4302 cli_setatr(cli1
, fname
, 0, 0);
4303 cli_unlink(cli1
, fname
);
4305 printf("open attr test %s.\n", correct
? "passed" : "failed");
4307 if (!torture_close_connection(cli1
)) {
4313 static void list_fn(const char *mnt
, file_info
*finfo
, const char *name
, void *state
)
4319 test directory listing speed
4321 static bool run_dirtest(int dummy
)
4324 static struct cli_state
*cli
;
4327 bool correct
= True
;
4329 printf("starting directory test\n");
4331 if (!torture_open_connection(&cli
, 0)) {
4335 cli_sockopt(cli
, sockops
);
4338 for (i
=0;i
<torture_numops
;i
++) {
4340 slprintf(fname
, sizeof(fname
), "\\%x", (int)random());
4341 fnum
= cli_open(cli
, fname
, O_RDWR
|O_CREAT
, DENY_NONE
);
4343 fprintf(stderr
,"Failed to open %s\n", fname
);
4346 cli_close(cli
, fnum
);
4351 printf("Matched %d\n", cli_list(cli
, "a*.*", 0, list_fn
, NULL
));
4352 printf("Matched %d\n", cli_list(cli
, "b*.*", 0, list_fn
, NULL
));
4353 printf("Matched %d\n", cli_list(cli
, "xyzabc", 0, list_fn
, NULL
));
4355 printf("dirtest core %g seconds\n", end_timer() - t1
);
4358 for (i
=0;i
<torture_numops
;i
++) {
4360 slprintf(fname
, sizeof(fname
), "\\%x", (int)random());
4361 cli_unlink(cli
, fname
);
4364 if (!torture_close_connection(cli
)) {
4368 printf("finished dirtest\n");
4373 static void del_fn(const char *mnt
, file_info
*finfo
, const char *mask
, void *state
)
4375 struct cli_state
*pcli
= (struct cli_state
*)state
;
4377 slprintf(fname
, sizeof(fname
), "\\LISTDIR\\%s", finfo
->name
);
4379 if (strcmp(finfo
->name
, ".") == 0 || strcmp(finfo
->name
, "..") == 0)
4382 if (finfo
->mode
& aDIR
) {
4383 if (!cli_rmdir(pcli
, fname
))
4384 printf("del_fn: failed to rmdir %s\n,", fname
);
4386 if (!cli_unlink(pcli
, fname
))
4387 printf("del_fn: failed to unlink %s\n,", fname
);
4393 sees what IOCTLs are supported
4395 bool torture_ioctl_test(int dummy
)
4397 static struct cli_state
*cli
;
4398 uint16 device
, function
;
4400 const char *fname
= "\\ioctl.dat";
4404 if (!torture_open_connection(&cli
, 0)) {
4408 printf("starting ioctl test\n");
4410 cli_unlink(cli
, fname
);
4412 fnum
= cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
4414 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
4418 status
= cli_raw_ioctl(cli
, fnum
, 0x2d0000 | (0x0420<<2), &blob
);
4419 printf("ioctl device info: %s\n", cli_errstr(cli
));
4421 status
= cli_raw_ioctl(cli
, fnum
, IOCTL_QUERY_JOB_INFO
, &blob
);
4422 printf("ioctl job info: %s\n", cli_errstr(cli
));
4424 for (device
=0;device
<0x100;device
++) {
4425 printf("testing device=0x%x\n", device
);
4426 for (function
=0;function
<0x100;function
++) {
4427 uint32 code
= (device
<<16) | function
;
4429 status
= cli_raw_ioctl(cli
, fnum
, code
, &blob
);
4431 if (NT_STATUS_IS_OK(status
)) {
4432 printf("ioctl 0x%x OK : %d bytes\n", (int)code
,
4434 data_blob_free(&blob
);
4439 if (!torture_close_connection(cli
)) {
4448 tries varients of chkpath
4450 bool torture_chkpath_test(int dummy
)
4452 static struct cli_state
*cli
;
4456 if (!torture_open_connection(&cli
, 0)) {
4460 printf("starting chkpath test\n");
4462 /* cleanup from an old run */
4463 cli_rmdir(cli
, "\\chkpath.dir\\dir2");
4464 cli_unlink(cli
, "\\chkpath.dir\\*");
4465 cli_rmdir(cli
, "\\chkpath.dir");
4467 if (!cli_mkdir(cli
, "\\chkpath.dir")) {
4468 printf("mkdir1 failed : %s\n", cli_errstr(cli
));
4472 if (!cli_mkdir(cli
, "\\chkpath.dir\\dir2")) {
4473 printf("mkdir2 failed : %s\n", cli_errstr(cli
));
4477 fnum
= cli_open(cli
, "\\chkpath.dir\\foo.txt", O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
4479 printf("open1 failed (%s)\n", cli_errstr(cli
));
4482 cli_close(cli
, fnum
);
4484 if (!cli_chkpath(cli
, "\\chkpath.dir")) {
4485 printf("chkpath1 failed: %s\n", cli_errstr(cli
));
4489 if (!cli_chkpath(cli
, "\\chkpath.dir\\dir2")) {
4490 printf("chkpath2 failed: %s\n", cli_errstr(cli
));
4494 if (!cli_chkpath(cli
, "\\chkpath.dir\\foo.txt")) {
4495 ret
= check_error(__LINE__
, cli
, ERRDOS
, ERRbadpath
,
4496 NT_STATUS_NOT_A_DIRECTORY
);
4498 printf("* chkpath on a file should fail\n");
4502 if (!cli_chkpath(cli
, "\\chkpath.dir\\bar.txt")) {
4503 ret
= check_error(__LINE__
, cli
, ERRDOS
, ERRbadfile
,
4504 NT_STATUS_OBJECT_NAME_NOT_FOUND
);
4506 printf("* chkpath on a non existant file should fail\n");
4510 if (!cli_chkpath(cli
, "\\chkpath.dir\\dirxx\\bar.txt")) {
4511 ret
= check_error(__LINE__
, cli
, ERRDOS
, ERRbadpath
,
4512 NT_STATUS_OBJECT_PATH_NOT_FOUND
);
4514 printf("* chkpath on a non existent component should fail\n");
4518 cli_rmdir(cli
, "\\chkpath.dir\\dir2");
4519 cli_unlink(cli
, "\\chkpath.dir\\*");
4520 cli_rmdir(cli
, "\\chkpath.dir");
4522 if (!torture_close_connection(cli
)) {
4529 static bool run_eatest(int dummy
)
4531 static struct cli_state
*cli
;
4532 const char *fname
= "\\eatest.txt";
4533 bool correct
= True
;
4536 struct ea_struct
*ea_list
= NULL
;
4537 TALLOC_CTX
*mem_ctx
= talloc_init("eatest");
4539 printf("starting eatest\n");
4541 if (!torture_open_connection(&cli
, 0)) {
4542 talloc_destroy(mem_ctx
);
4546 cli_unlink(cli
, fname
);
4547 fnum
= cli_nt_create_full(cli
, fname
, 0,
4548 FIRST_DESIRED_ACCESS
, FILE_ATTRIBUTE_ARCHIVE
,
4549 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
,
4553 printf("open failed - %s\n", cli_errstr(cli
));
4554 talloc_destroy(mem_ctx
);
4558 for (i
= 0; i
< 10; i
++) {
4559 fstring ea_name
, ea_val
;
4561 slprintf(ea_name
, sizeof(ea_name
), "EA_%d", i
);
4562 memset(ea_val
, (char)i
+1, i
+1);
4563 if (!cli_set_ea_fnum(cli
, fnum
, ea_name
, ea_val
, i
+1)) {
4564 printf("ea_set of name %s failed - %s\n", ea_name
, cli_errstr(cli
));
4565 talloc_destroy(mem_ctx
);
4570 cli_close(cli
, fnum
);
4571 for (i
= 0; i
< 10; i
++) {
4572 fstring ea_name
, ea_val
;
4574 slprintf(ea_name
, sizeof(ea_name
), "EA_%d", i
+10);
4575 memset(ea_val
, (char)i
+1, i
+1);
4576 if (!cli_set_ea_path(cli
, fname
, ea_name
, ea_val
, i
+1)) {
4577 printf("ea_set of name %s failed - %s\n", ea_name
, cli_errstr(cli
));
4578 talloc_destroy(mem_ctx
);
4583 if (!cli_get_ea_list_path(cli
, fname
, mem_ctx
, &num_eas
, &ea_list
)) {
4584 printf("ea_get list failed - %s\n", cli_errstr(cli
));
4588 printf("num_eas = %d\n", (int)num_eas
);
4590 if (num_eas
!= 20) {
4591 printf("Should be 20 EA's stored... failing.\n");
4595 for (i
= 0; i
< num_eas
; i
++) {
4596 printf("%d: ea_name = %s. Val = ", i
, ea_list
[i
].name
);
4597 dump_data(0, ea_list
[i
].value
.data
,
4598 ea_list
[i
].value
.length
);
4601 /* Setting EA's to zero length deletes them. Test this */
4602 printf("Now deleting all EA's - case indepenent....\n");
4605 cli_set_ea_path(cli
, fname
, "", "", 0);
4607 for (i
= 0; i
< 20; i
++) {
4609 slprintf(ea_name
, sizeof(ea_name
), "ea_%d", i
);
4610 if (!cli_set_ea_path(cli
, fname
, ea_name
, "", 0)) {
4611 printf("ea_set of name %s failed - %s\n", ea_name
, cli_errstr(cli
));
4612 talloc_destroy(mem_ctx
);
4618 if (!cli_get_ea_list_path(cli
, fname
, mem_ctx
, &num_eas
, &ea_list
)) {
4619 printf("ea_get list failed - %s\n", cli_errstr(cli
));
4623 printf("num_eas = %d\n", (int)num_eas
);
4624 for (i
= 0; i
< num_eas
; i
++) {
4625 printf("%d: ea_name = %s. Val = ", i
, ea_list
[i
].name
);
4626 dump_data(0, ea_list
[i
].value
.data
,
4627 ea_list
[i
].value
.length
);
4631 printf("deleting EA's failed.\n");
4635 /* Try and delete a non existant EA. */
4636 if (!cli_set_ea_path(cli
, fname
, "foo", "", 0)) {
4637 printf("deleting non-existant EA 'foo' should succeed. %s\n", cli_errstr(cli
));
4641 talloc_destroy(mem_ctx
);
4642 if (!torture_close_connection(cli
)) {
4649 static bool run_dirtest1(int dummy
)
4652 static struct cli_state
*cli
;
4654 bool correct
= True
;
4656 printf("starting directory test\n");
4658 if (!torture_open_connection(&cli
, 0)) {
4662 cli_sockopt(cli
, sockops
);
4664 cli_list(cli
, "\\LISTDIR\\*", 0, del_fn
, cli
);
4665 cli_list(cli
, "\\LISTDIR\\*", aDIR
, del_fn
, cli
);
4666 cli_rmdir(cli
, "\\LISTDIR");
4667 cli_mkdir(cli
, "\\LISTDIR");
4669 /* Create 1000 files and 1000 directories. */
4670 for (i
=0;i
<1000;i
++) {
4672 slprintf(fname
, sizeof(fname
), "\\LISTDIR\\f%d", i
);
4673 fnum
= cli_nt_create_full(cli
, fname
, 0, GENERIC_ALL_ACCESS
, FILE_ATTRIBUTE_ARCHIVE
,
4674 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OVERWRITE_IF
, 0, 0);
4676 fprintf(stderr
,"Failed to open %s\n", fname
);
4679 cli_close(cli
, fnum
);
4681 for (i
=0;i
<1000;i
++) {
4683 slprintf(fname
, sizeof(fname
), "\\LISTDIR\\d%d", i
);
4684 if (!cli_mkdir(cli
, fname
)) {
4685 fprintf(stderr
,"Failed to open %s\n", fname
);
4690 /* Now ensure that doing an old list sees both files and directories. */
4691 num_seen
= cli_list_old(cli
, "\\LISTDIR\\*", aDIR
, list_fn
, NULL
);
4692 printf("num_seen = %d\n", num_seen
);
4693 /* We should see 100 files + 1000 directories + . and .. */
4694 if (num_seen
!= 2002)
4697 /* Ensure if we have the "must have" bits we only see the
4700 num_seen
= cli_list_old(cli
, "\\LISTDIR\\*", (aDIR
<<8)|aDIR
, list_fn
, NULL
);
4701 printf("num_seen = %d\n", num_seen
);
4702 if (num_seen
!= 1002)
4705 num_seen
= cli_list_old(cli
, "\\LISTDIR\\*", (aARCH
<<8)|aDIR
, list_fn
, NULL
);
4706 printf("num_seen = %d\n", num_seen
);
4707 if (num_seen
!= 1000)
4710 /* Delete everything. */
4711 cli_list(cli
, "\\LISTDIR\\*", 0, del_fn
, cli
);
4712 cli_list(cli
, "\\LISTDIR\\*", aDIR
, del_fn
, cli
);
4713 cli_rmdir(cli
, "\\LISTDIR");
4716 printf("Matched %d\n", cli_list(cli
, "a*.*", 0, list_fn
, NULL
));
4717 printf("Matched %d\n", cli_list(cli
, "b*.*", 0, list_fn
, NULL
));
4718 printf("Matched %d\n", cli_list(cli
, "xyzabc", 0, list_fn
, NULL
));
4721 if (!torture_close_connection(cli
)) {
4725 printf("finished dirtest1\n");
4730 static bool run_error_map_extract(int dummy
) {
4732 static struct cli_state
*c_dos
;
4733 static struct cli_state
*c_nt
;
4738 uint32 flgs2
, errnum
;
4745 /* NT-Error connection */
4747 if (!(c_nt
= open_nbt_connection())) {
4751 c_nt
->use_spnego
= False
;
4753 status
= cli_negprot(c_nt
);
4755 if (!NT_STATUS_IS_OK(status
)) {
4756 printf("%s rejected the NT-error negprot (%s)\n", host
,
4762 if (!NT_STATUS_IS_OK(cli_session_setup(c_nt
, "", "", 0, "", 0,
4764 printf("%s rejected the NT-error initial session setup (%s)\n",host
, cli_errstr(c_nt
));
4768 /* DOS-Error connection */
4770 if (!(c_dos
= open_nbt_connection())) {
4774 c_dos
->use_spnego
= False
;
4775 c_dos
->force_dos_errors
= True
;
4777 status
= cli_negprot(c_dos
);
4778 if (!NT_STATUS_IS_OK(status
)) {
4779 printf("%s rejected the DOS-error negprot (%s)\n", host
,
4781 cli_shutdown(c_dos
);
4785 if (!NT_STATUS_IS_OK(cli_session_setup(c_dos
, "", "", 0, "", 0,
4787 printf("%s rejected the DOS-error initial session setup (%s)\n",host
, cli_errstr(c_dos
));
4791 for (error
=(0xc0000000 | 0x1); error
< (0xc0000000| 0xFFF); error
++) {
4792 fstr_sprintf(user
, "%X", error
);
4794 if (NT_STATUS_IS_OK(cli_session_setup(c_nt
, user
,
4795 password
, strlen(password
),
4796 password
, strlen(password
),
4798 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
4801 flgs2
= SVAL(c_nt
->inbuf
,smb_flg2
);
4803 /* Case #1: 32-bit NT errors */
4804 if (flgs2
& FLAGS2_32_BIT_ERROR_CODES
) {
4805 nt_status
= NT_STATUS(IVAL(c_nt
->inbuf
,smb_rcls
));
4807 printf("/** Dos error on NT connection! (%s) */\n",
4809 nt_status
= NT_STATUS(0xc0000000);
4812 if (NT_STATUS_IS_OK(cli_session_setup(c_dos
, user
,
4813 password
, strlen(password
),
4814 password
, strlen(password
),
4816 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
4818 flgs2
= SVAL(c_dos
->inbuf
,smb_flg2
), errnum
;
4820 /* Case #1: 32-bit NT errors */
4821 if (flgs2
& FLAGS2_32_BIT_ERROR_CODES
) {
4822 printf("/** NT error on DOS connection! (%s) */\n",
4824 errnum
= errclass
= 0;
4826 cli_dos_error(c_dos
, &errclass
, &errnum
);
4829 if (NT_STATUS_V(nt_status
) != error
) {
4830 printf("/*\t{ This NT error code was 'sqashed'\n\t from %s to %s \n\t during the session setup }\n*/\n",
4831 get_nt_error_c_code(NT_STATUS(error
)),
4832 get_nt_error_c_code(nt_status
));
4835 printf("\t{%s,\t%s,\t%s},\n",
4836 smb_dos_err_class(errclass
),
4837 smb_dos_err_name(errclass
, errnum
),
4838 get_nt_error_c_code(NT_STATUS(error
)));
4843 static bool run_sesssetup_bench(int dummy
)
4845 static struct cli_state
*c
;
4846 const char *fname
= "\\file.dat";
4851 if (!torture_open_connection(&c
, 0)) {
4855 fnum
= cli_nt_create_full(
4856 c
, fname
, 0, GENERIC_ALL_ACCESS
|DELETE_ACCESS
,
4857 FILE_ATTRIBUTE_NORMAL
, 0, FILE_OVERWRITE_IF
,
4858 FILE_DELETE_ON_CLOSE
, 0);
4860 d_printf("open %s failed: %s\n", fname
, cli_errstr(c
));
4864 for (i
=0; i
<torture_numops
; i
++) {
4865 status
= cli_session_setup(
4867 password
, strlen(password
),
4868 password
, strlen(password
),
4870 if (!NT_STATUS_IS_OK(status
)) {
4871 d_printf("(%s) cli_session_setup failed: %s\n",
4872 __location__
, nt_errstr(status
));
4876 d_printf("\r%d ", (int)c
->vuid
);
4878 if (!cli_ulogoff(c
)) {
4879 d_printf("(%s) cli_ulogoff failed: %s\n",
4880 __location__
, cli_errstr(c
));
4889 static bool subst_test(const char *str
, const char *user
, const char *domain
,
4890 uid_t uid
, gid_t gid
, const char *expected
)
4895 subst
= talloc_sub_specified(talloc_tos(), str
, user
, domain
, uid
, gid
);
4897 if (strcmp(subst
, expected
) != 0) {
4898 printf("sub_specified(%s, %s, %s, %d, %d) returned [%s], expected "
4899 "[%s]\n", str
, user
, domain
, (int)uid
, (int)gid
, subst
,
4908 static void chain1_open_completion(struct async_req
*req
)
4913 status
= cli_open_recv(req
, &fnum
);
4916 d_printf("cli_open_recv returned %s: %d\n",
4918 NT_STATUS_IS_OK(status
) ? fnum
: -1);
4921 static void chain1_read_completion(struct async_req
*req
)
4927 status
= cli_read_andx_recv(req
, &received
, &rcvbuf
);
4928 if (!NT_STATUS_IS_OK(status
)) {
4930 d_printf("cli_read_andx_recv returned %s\n",
4935 d_printf("got %d bytes: %.*s\n", (int)received
, (int)received
,
4940 static void chain1_write_completion(struct async_req
*req
)
4945 status
= cli_write_andx_recv(req
, &written
);
4946 if (!NT_STATUS_IS_OK(status
)) {
4948 d_printf("cli_write_andx_recv returned %s\n",
4953 d_printf("wrote %d bytes\n", (int)written
);
4957 static void chain1_close_completion(struct async_req
*req
)
4961 status
= cli_close_recv(req
);
4962 *((bool *)(req
->async
.priv
)) = true;
4966 d_printf("cli_close returned %s\n", nt_errstr(status
));
4969 static bool run_chain1(int dummy
)
4971 struct cli_state
*cli1
;
4972 struct event_context
*evt
= event_context_init(NULL
);
4973 struct async_req
*reqs
[4];
4975 const char *text
= "hallo";
4977 printf("starting chain1 test\n");
4978 if (!torture_open_connection(&cli1
, 0)) {
4982 cli_sockopt(cli1
, sockops
);
4984 cli_chain_cork(cli1
, evt
, 0);
4985 reqs
[0] = cli_open_send(talloc_tos(), evt
, cli1
, "\\test",
4987 reqs
[0]->async
.fn
= chain1_open_completion
;
4988 reqs
[1] = cli_write_andx_send(talloc_tos(), evt
, cli1
, 0, 0,
4989 (uint8_t *)text
, 0, strlen(text
));
4990 reqs
[1]->async
.fn
= chain1_write_completion
;
4991 reqs
[2] = cli_read_andx_send(talloc_tos(), evt
, cli1
, 0, 1, 10);
4992 reqs
[2]->async
.fn
= chain1_read_completion
;
4993 reqs
[3] = cli_close_send(talloc_tos(), evt
, cli1
, 0);
4994 reqs
[3]->async
.fn
= chain1_close_completion
;
4995 reqs
[3]->async
.priv
= (void *)&done
;
4996 cli_chain_uncork(cli1
);
4999 event_loop_once(evt
);
5002 torture_close_connection(cli1
);
5006 static size_t null_source(uint8_t *buf
, size_t n
, void *priv
)
5008 size_t *to_pull
= (size_t *)priv
;
5009 size_t thistime
= *to_pull
;
5011 thistime
= MIN(thistime
, n
);
5012 if (thistime
== 0) {
5016 memset(buf
, 0, thistime
);
5017 *to_pull
-= thistime
;
5021 static bool run_windows_write(int dummy
)
5023 struct cli_state
*cli1
;
5027 const char *fname
= "\\writetest.txt";
5031 printf("starting windows_write test\n");
5032 if (!torture_open_connection(&cli1
, 0)) {
5036 fnum
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
5038 printf("open failed (%s)\n", cli_errstr(cli1
));
5042 cli_sockopt(cli1
, sockops
);
5046 for (i
=0; i
<torture_numops
; i
++) {
5048 off_t start
= i
* torture_blocksize
;
5050 size_t to_pull
= torture_blocksize
- 1;
5052 if (cli_write(cli1
, fnum
, 0, &c
,
5053 start
+ torture_blocksize
- 1, 1) != 1) {
5054 printf("cli_write failed: %s\n", cli_errstr(cli1
));
5058 status
= cli_push(cli1
, fnum
, 0, i
* torture_blocksize
, torture_blocksize
,
5059 null_source
, &to_pull
);
5060 if (!NT_STATUS_IS_OK(status
)) {
5061 printf("cli_push returned: %s\n", nt_errstr(status
));
5066 seconds
= end_timer();
5067 kbytes
= (double)torture_blocksize
* torture_numops
;
5070 printf("Wrote %d kbytes in %.2f seconds: %d kb/sec\n", (int)kbytes
,
5071 (double)seconds
, (int)(kbytes
/seconds
));
5075 cli_close(cli1
, fnum
);
5076 cli_unlink(cli1
, fname
);
5077 torture_close_connection(cli1
);
5081 static bool run_cli_echo(int dummy
)
5083 struct cli_state
*cli
;
5084 struct event_context
*ev
= event_context_init(NULL
);
5085 struct async_req
*req
;
5088 printf("starting chain1 test\n");
5089 if (!torture_open_connection(&cli
, 0)) {
5092 cli_sockopt(cli
, sockops
);
5094 req
= cli_echo_send(ev
, ev
, cli
, 5, data_blob_const("hello", 5));
5096 d_printf("cli_echo_send failed\n");
5100 while (req
->state
< ASYNC_REQ_DONE
) {
5101 event_loop_once(ev
);
5104 status
= cli_echo_recv(req
);
5105 d_printf("cli_echo returned %s\n", nt_errstr(status
));
5109 torture_close_connection(cli
);
5110 return NT_STATUS_IS_OK(status
);
5113 static bool run_local_substitute(int dummy
)
5117 ok
&= subst_test("%U", "bla", "", -1, -1, "bla");
5118 ok
&= subst_test("%u%U", "bla", "", -1, -1, "blabla");
5119 ok
&= subst_test("%g", "", "", -1, -1, "NO_GROUP");
5120 ok
&= subst_test("%G", "", "", -1, -1, "NO_GROUP");
5121 ok
&= subst_test("%g", "", "", -1, 0, gidtoname(0));
5122 ok
&= subst_test("%G", "", "", -1, 0, gidtoname(0));
5123 ok
&= subst_test("%D%u", "u", "dom", -1, 0, "domu");
5124 ok
&= subst_test("%i %I", "", "", -1, -1, "0.0.0.0 0.0.0.0");
5126 /* Different captialization rules in sub_basic... */
5128 ok
&= (strcmp(talloc_sub_basic(talloc_tos(), "BLA", "dom", "%U%D"),
5134 static bool run_local_gencache(int dummy
)
5140 if (!gencache_init()) {
5141 d_printf("%s: gencache_init() failed\n", __location__
);
5145 if (!gencache_set("foo", "bar", time(NULL
) + 1000)) {
5146 d_printf("%s: gencache_set() failed\n", __location__
);
5150 if (!gencache_get("foo", &val
, &tm
)) {
5151 d_printf("%s: gencache_get() failed\n", __location__
);
5155 if (strcmp(val
, "bar") != 0) {
5156 d_printf("%s: gencache_get() returned %s, expected %s\n",
5157 __location__
, val
, "bar");
5164 if (!gencache_del("foo")) {
5165 d_printf("%s: gencache_del() failed\n", __location__
);
5168 if (gencache_del("foo")) {
5169 d_printf("%s: second gencache_del() succeeded\n",
5174 if (gencache_get("foo", &val
, &tm
)) {
5175 d_printf("%s: gencache_get() on deleted entry "
5176 "succeeded\n", __location__
);
5180 blob
= data_blob_string_const_null("bar");
5183 if (!gencache_set_data_blob("foo", &blob
, tm
)) {
5184 d_printf("%s: gencache_set_data_blob() failed\n", __location__
);
5188 data_blob_free(&blob
);
5190 if (!gencache_get_data_blob("foo", &blob
, NULL
)) {
5191 d_printf("%s: gencache_get_data_blob() failed\n", __location__
);
5195 if (strcmp((const char *)blob
.data
, "bar") != 0) {
5196 d_printf("%s: gencache_get_data_blob() returned %s, expected %s\n",
5197 __location__
, (const char *)blob
.data
, "bar");
5198 data_blob_free(&blob
);
5202 data_blob_free(&blob
);
5204 if (!gencache_del("foo")) {
5205 d_printf("%s: gencache_del() failed\n", __location__
);
5208 if (gencache_del("foo")) {
5209 d_printf("%s: second gencache_del() succeeded\n",
5214 if (gencache_get_data_blob("foo", &blob
, NULL
)) {
5215 d_printf("%s: gencache_get_data_blob() on deleted entry "
5216 "succeeded\n", __location__
);
5220 if (!gencache_shutdown()) {
5221 d_printf("%s: gencache_shutdown() failed\n", __location__
);
5225 if (gencache_shutdown()) {
5226 d_printf("%s: second gencache_shutdown() succeeded\n",
5234 static bool rbt_testval(struct db_context
*db
, const char *key
,
5237 struct db_record
*rec
;
5238 TDB_DATA data
= string_tdb_data(value
);
5242 rec
= db
->fetch_locked(db
, db
, string_tdb_data(key
));
5244 d_fprintf(stderr
, "fetch_locked failed\n");
5247 status
= rec
->store(rec
, data
, 0);
5248 if (!NT_STATUS_IS_OK(status
)) {
5249 d_fprintf(stderr
, "store failed: %s\n", nt_errstr(status
));
5254 rec
= db
->fetch_locked(db
, db
, string_tdb_data(key
));
5256 d_fprintf(stderr
, "second fetch_locked failed\n");
5259 if ((rec
->value
.dsize
!= data
.dsize
)
5260 || (memcmp(rec
->value
.dptr
, data
.dptr
, data
.dsize
) != 0)) {
5261 d_fprintf(stderr
, "Got wrong data back\n");
5271 static bool run_local_rbtree(int dummy
)
5273 struct db_context
*db
;
5277 db
= db_open_rbt(NULL
);
5280 d_fprintf(stderr
, "db_open_rbt failed\n");
5284 for (i
=0; i
<1000; i
++) {
5287 if (asprintf(&key
, "key%ld", random()) == -1) {
5290 if (asprintf(&value
, "value%ld", random()) == -1) {
5295 if (!rbt_testval(db
, key
, value
)) {
5302 if (asprintf(&value
, "value%ld", random()) == -1) {
5307 if (!rbt_testval(db
, key
, value
)) {
5324 static bool test_stream_name(const char *fname
, const char *expected_base
,
5325 const char *expected_stream
,
5326 NTSTATUS expected_status
)
5330 char *stream
= NULL
;
5332 status
= split_ntfs_stream_name(talloc_tos(), fname
, &base
, &stream
);
5333 if (!NT_STATUS_EQUAL(status
, expected_status
)) {
5337 if (!NT_STATUS_IS_OK(status
)) {
5341 if (base
== NULL
) goto error
;
5343 if (strcmp(expected_base
, base
) != 0) goto error
;
5345 if ((expected_stream
!= NULL
) && (stream
== NULL
)) goto error
;
5346 if ((expected_stream
== NULL
) && (stream
!= NULL
)) goto error
;
5348 if ((stream
!= NULL
) && (strcmp(expected_stream
, stream
) != 0))
5352 TALLOC_FREE(stream
);
5356 d_fprintf(stderr
, "test_stream(%s, %s, %s, %s)\n",
5357 fname
, expected_base
? expected_base
: "<NULL>",
5358 expected_stream
? expected_stream
: "<NULL>",
5359 nt_errstr(expected_status
));
5360 d_fprintf(stderr
, "-> base=%s, stream=%s, status=%s\n",
5361 base
? base
: "<NULL>", stream
? stream
: "<NULL>",
5364 TALLOC_FREE(stream
);
5368 static bool run_local_stream_name(int dummy
)
5372 ret
&= test_stream_name(
5373 "bla", "bla", NULL
, NT_STATUS_OK
);
5374 ret
&= test_stream_name(
5375 "bla::$DATA", "bla", NULL
, NT_STATUS_OK
);
5376 ret
&= test_stream_name(
5377 "bla:blub:", "bla", NULL
, NT_STATUS_OBJECT_NAME_INVALID
);
5378 ret
&= test_stream_name(
5379 "bla::", NULL
, NULL
, NT_STATUS_OBJECT_NAME_INVALID
);
5380 ret
&= test_stream_name(
5381 "bla::123", "bla", NULL
, NT_STATUS_OBJECT_NAME_INVALID
);
5382 ret
&= test_stream_name(
5383 "bla:$DATA", "bla", "$DATA:$DATA", NT_STATUS_OK
);
5384 ret
&= test_stream_name(
5385 "bla:x:$DATA", "bla", "x:$DATA", NT_STATUS_OK
);
5386 ret
&= test_stream_name(
5387 "bla:x", "bla", "x:$DATA", NT_STATUS_OK
);
5392 static bool data_blob_equal(DATA_BLOB a
, DATA_BLOB b
)
5394 if (a
.length
!= b
.length
) {
5395 printf("a.length=%d != b.length=%d\n",
5396 (int)a
.length
, (int)b
.length
);
5399 if (memcmp(a
.data
, b
.data
, a
.length
) != 0) {
5400 printf("a.data and b.data differ\n");
5406 static bool run_local_memcache(int dummy
)
5408 struct memcache
*cache
;
5410 DATA_BLOB d1
, d2
, d3
;
5411 DATA_BLOB v1
, v2
, v3
;
5413 TALLOC_CTX
*mem_ctx
;
5415 size_t size1
, size2
;
5418 cache
= memcache_init(NULL
, 100);
5420 if (cache
== NULL
) {
5421 printf("memcache_init failed\n");
5425 d1
= data_blob_const("d1", 2);
5426 d2
= data_blob_const("d2", 2);
5427 d3
= data_blob_const("d3", 2);
5429 k1
= data_blob_const("d1", 2);
5430 k2
= data_blob_const("d2", 2);
5432 memcache_add(cache
, STAT_CACHE
, k1
, d1
);
5433 memcache_add(cache
, GETWD_CACHE
, k2
, d2
);
5435 if (!memcache_lookup(cache
, STAT_CACHE
, k1
, &v1
)) {
5436 printf("could not find k1\n");
5439 if (!data_blob_equal(d1
, v1
)) {
5443 if (!memcache_lookup(cache
, GETWD_CACHE
, k2
, &v2
)) {
5444 printf("could not find k2\n");
5447 if (!data_blob_equal(d2
, v2
)) {
5451 memcache_add(cache
, STAT_CACHE
, k1
, d3
);
5453 if (!memcache_lookup(cache
, STAT_CACHE
, k1
, &v3
)) {
5454 printf("could not find replaced k1\n");
5457 if (!data_blob_equal(d3
, v3
)) {
5461 memcache_add(cache
, GETWD_CACHE
, k1
, d1
);
5463 if (memcache_lookup(cache
, GETWD_CACHE
, k2
, &v2
)) {
5464 printf("Did find k2, should have been purged\n");
5470 cache
= memcache_init(NULL
, 0);
5472 mem_ctx
= talloc_init("foo");
5474 str1
= talloc_strdup(mem_ctx
, "string1");
5475 str2
= talloc_strdup(mem_ctx
, "string2");
5477 memcache_add_talloc(cache
, SINGLETON_CACHE_TALLOC
,
5478 data_blob_string_const("torture"), &str1
);
5479 size1
= talloc_total_size(cache
);
5481 memcache_add_talloc(cache
, SINGLETON_CACHE_TALLOC
,
5482 data_blob_string_const("torture"), &str2
);
5483 size2
= talloc_total_size(cache
);
5485 printf("size1=%d, size2=%d\n", (int)size1
, (int)size2
);
5487 if (size2
> size1
) {
5488 printf("memcache leaks memory!\n");
5498 static void wbclient_done(struct async_req
*req
)
5501 struct winbindd_response
*wb_resp
;
5502 int *i
= (int *)req
->async
.priv
;
5504 status
= wb_trans_recv(req
, req
, &wb_resp
);
5507 d_printf("wb_trans_recv %d returned %s\n", *i
, nt_errstr(status
));
5510 static bool run_local_wbclient(int dummy
)
5512 struct event_context
*ev
;
5513 struct wb_context
**wb_ctx
;
5514 struct winbindd_request wb_req
;
5515 bool result
= false;
5518 BlockSignals(True
, SIGPIPE
);
5520 ev
= event_context_init(talloc_tos());
5525 wb_ctx
= TALLOC_ARRAY(ev
, struct wb_context
*, torture_numops
);
5526 if (wb_ctx
== NULL
) {
5530 ZERO_STRUCT(wb_req
);
5531 wb_req
.cmd
= WINBINDD_PING
;
5533 for (i
=0; i
<torture_numops
; i
++) {
5534 wb_ctx
[i
] = wb_context_init(ev
);
5535 if (wb_ctx
[i
] == NULL
) {
5538 for (j
=0; j
<5; j
++) {
5539 struct async_req
*req
;
5540 req
= wb_trans_send(ev
, ev
, wb_ctx
[i
],
5541 (j
% 2) == 0, &wb_req
);
5545 req
->async
.fn
= wbclient_done
;
5546 req
->async
.priv
= &i
;
5552 while (i
< 5 * torture_numops
) {
5553 event_loop_once(ev
);
5562 static double create_procs(bool (*fn
)(int), bool *result
)
5565 volatile pid_t
*child_status
;
5566 volatile bool *child_status_out
;
5572 child_status
= (volatile pid_t
*)shm_setup(sizeof(pid_t
)*nprocs
);
5573 if (!child_status
) {
5574 printf("Failed to setup shared memory\n");
5578 child_status_out
= (volatile bool *)shm_setup(sizeof(bool)*nprocs
);
5579 if (!child_status_out
) {
5580 printf("Failed to setup result status shared memory\n");
5584 for (i
= 0; i
< nprocs
; i
++) {
5585 child_status
[i
] = 0;
5586 child_status_out
[i
] = True
;
5591 for (i
=0;i
<nprocs
;i
++) {
5594 pid_t mypid
= getpid();
5595 sys_srandom(((int)mypid
) ^ ((int)time(NULL
)));
5597 slprintf(myname
,sizeof(myname
),"CLIENT%d", i
);
5600 if (torture_open_connection(¤t_cli
, i
)) break;
5602 printf("pid %d failed to start\n", (int)getpid());
5608 child_status
[i
] = getpid();
5610 while (child_status
[i
] && end_timer() < 5) smb_msleep(2);
5612 child_status_out
[i
] = fn(i
);
5619 for (i
=0;i
<nprocs
;i
++) {
5620 if (child_status
[i
]) synccount
++;
5622 if (synccount
== nprocs
) break;
5624 } while (end_timer() < 30);
5626 if (synccount
!= nprocs
) {
5627 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs
, synccount
);
5632 /* start the client load */
5635 for (i
=0;i
<nprocs
;i
++) {
5636 child_status
[i
] = 0;
5639 printf("%d clients started\n", nprocs
);
5641 for (i
=0;i
<nprocs
;i
++) {
5642 while (waitpid(0, &status
, 0) == -1 && errno
== EINTR
) /* noop */ ;
5647 for (i
=0;i
<nprocs
;i
++) {
5648 if (!child_status_out
[i
]) {
5655 #define FLAG_MULTIPROC 1
5662 {"FDPASS", run_fdpasstest
, 0},
5663 {"LOCK1", run_locktest1
, 0},
5664 {"LOCK2", run_locktest2
, 0},
5665 {"LOCK3", run_locktest3
, 0},
5666 {"LOCK4", run_locktest4
, 0},
5667 {"LOCK5", run_locktest5
, 0},
5668 {"LOCK6", run_locktest6
, 0},
5669 {"LOCK7", run_locktest7
, 0},
5670 {"UNLINK", run_unlinktest
, 0},
5671 {"BROWSE", run_browsetest
, 0},
5672 {"ATTR", run_attrtest
, 0},
5673 {"TRANS2", run_trans2test
, 0},
5674 {"MAXFID", run_maxfidtest
, FLAG_MULTIPROC
},
5675 {"TORTURE",run_torture
, FLAG_MULTIPROC
},
5676 {"RANDOMIPC", run_randomipc
, 0},
5677 {"NEGNOWAIT", run_negprot_nowait
, 0},
5678 {"NBENCH", run_nbench
, 0},
5679 {"OPLOCK1", run_oplock1
, 0},
5680 {"OPLOCK2", run_oplock2
, 0},
5681 {"OPLOCK3", run_oplock3
, 0},
5682 {"DIR", run_dirtest
, 0},
5683 {"DIR1", run_dirtest1
, 0},
5684 {"DENY1", torture_denytest1
, 0},
5685 {"DENY2", torture_denytest2
, 0},
5686 {"TCON", run_tcon_test
, 0},
5687 {"TCONDEV", run_tcon_devtype_test
, 0},
5688 {"RW1", run_readwritetest
, 0},
5689 {"RW2", run_readwritemulti
, FLAG_MULTIPROC
},
5690 {"RW3", run_readwritelarge
, 0},
5691 {"OPEN", run_opentest
, 0},
5693 {"OPENATTR", run_openattrtest
, 0},
5695 {"XCOPY", run_xcopy
, 0},
5696 {"RENAME", run_rename
, 0},
5697 {"DELETE", run_deletetest
, 0},
5698 {"PROPERTIES", run_properties
, 0},
5699 {"MANGLE", torture_mangle
, 0},
5700 {"W2K", run_w2ktest
, 0},
5701 {"TRANS2SCAN", torture_trans2_scan
, 0},
5702 {"NTTRANSSCAN", torture_nttrans_scan
, 0},
5703 {"UTABLE", torture_utable
, 0},
5704 {"CASETABLE", torture_casetable
, 0},
5705 {"ERRMAPEXTRACT", run_error_map_extract
, 0},
5706 {"PIPE_NUMBER", run_pipe_number
, 0},
5707 {"TCON2", run_tcon2_test
, 0},
5708 {"IOCTL", torture_ioctl_test
, 0},
5709 {"CHKPATH", torture_chkpath_test
, 0},
5710 {"FDSESS", run_fdsesstest
, 0},
5711 { "EATEST", run_eatest
, 0},
5712 { "SESSSETUP_BENCH", run_sesssetup_bench
, 0},
5713 { "CHAIN1", run_chain1
, 0},
5714 { "WINDOWS-WRITE", run_windows_write
, 0},
5715 { "CLI_ECHO", run_cli_echo
, 0},
5716 { "LOCAL-SUBSTITUTE", run_local_substitute
, 0},
5717 { "LOCAL-GENCACHE", run_local_gencache
, 0},
5718 { "LOCAL-RBTREE", run_local_rbtree
, 0},
5719 { "LOCAL-MEMCACHE", run_local_memcache
, 0},
5720 { "LOCAL-STREAM-NAME", run_local_stream_name
, 0},
5721 { "LOCAL-WBCLIENT", run_local_wbclient
, 0},
5726 /****************************************************************************
5727 run a specified test or "ALL"
5728 ****************************************************************************/
5729 static bool run_test(const char *name
)
5736 if (strequal(name
,"ALL")) {
5737 for (i
=0;torture_ops
[i
].name
;i
++) {
5738 run_test(torture_ops
[i
].name
);
5743 for (i
=0;torture_ops
[i
].name
;i
++) {
5744 fstr_sprintf(randomfname
, "\\XX%x",
5745 (unsigned)random());
5747 if (strequal(name
, torture_ops
[i
].name
)) {
5749 printf("Running %s\n", name
);
5750 if (torture_ops
[i
].flags
& FLAG_MULTIPROC
) {
5751 t
= create_procs(torture_ops
[i
].fn
, &result
);
5754 printf("TEST %s FAILED!\n", name
);
5759 if (!torture_ops
[i
].fn(0)) {
5761 printf("TEST %s FAILED!\n", name
);
5765 printf("%s took %g secs\n\n", name
, t
);
5770 printf("Did not find a test named %s\n", name
);
5778 static void usage(void)
5782 printf("WARNING samba4 test suite is much more complete nowadays.\n");
5783 printf("Please use samba4 torture.\n\n");
5785 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
5787 printf("\t-d debuglevel\n");
5788 printf("\t-U user%%pass\n");
5789 printf("\t-k use kerberos\n");
5790 printf("\t-N numprocs\n");
5791 printf("\t-n my_netbios_name\n");
5792 printf("\t-W workgroup\n");
5793 printf("\t-o num_operations\n");
5794 printf("\t-O socket_options\n");
5795 printf("\t-m maximum protocol\n");
5796 printf("\t-L use oplocks\n");
5797 printf("\t-c CLIENT.TXT specify client load file for NBENCH\n");
5798 printf("\t-A showall\n");
5799 printf("\t-p port\n");
5800 printf("\t-s seed\n");
5801 printf("\t-b unclist_filename specify multiple shares for multiple connections\n");
5804 printf("tests are:");
5805 for (i
=0;torture_ops
[i
].name
;i
++) {
5806 printf(" %s", torture_ops
[i
].name
);
5810 printf("default test is ALL\n");
5815 /****************************************************************************
5817 ****************************************************************************/
5818 int main(int argc
,char *argv
[])
5824 bool correct
= True
;
5825 TALLOC_CTX
*frame
= talloc_stackframe();
5826 int seed
= time(NULL
);
5830 #ifdef HAVE_SETBUFFER
5831 setbuffer(stdout
, NULL
, 0);
5836 if (is_default_dyn_CONFIGFILE()) {
5837 if(getenv("SMB_CONF_PATH")) {
5838 set_dyn_CONFIGFILE(getenv("SMB_CONF_PATH"));
5841 lp_load(get_dyn_CONFIGFILE(),True
,False
,False
,True
);
5848 for(p
= argv
[1]; *p
; p
++)
5852 if (strncmp(argv
[1], "//", 2)) {
5856 fstrcpy(host
, &argv
[1][2]);
5857 p
= strchr_m(&host
[2],'/');
5862 fstrcpy(share
, p
+1);
5864 fstrcpy(myname
, talloc_get_myname(talloc_tos()));
5866 fprintf(stderr
, "Failed to get my hostname.\n");
5870 if (*username
== 0 && getenv("LOGNAME")) {
5871 fstrcpy(username
,getenv("LOGNAME"));
5877 fstrcpy(workgroup
, lp_workgroup());
5879 while ((opt
= getopt(argc
, argv
, "p:hW:U:n:N:O:o:m:Ld:Aec:ks:b:B:")) != EOF
) {
5882 port_to_use
= atoi(optarg
);
5885 seed
= atoi(optarg
);
5888 fstrcpy(workgroup
,optarg
);
5891 max_protocol
= interpret_protocol(optarg
, max_protocol
);
5894 nprocs
= atoi(optarg
);
5897 torture_numops
= atoi(optarg
);
5900 DEBUGLEVEL
= atoi(optarg
);
5909 torture_showall
= True
;
5912 fstrcpy(myname
, optarg
);
5915 client_txt
= optarg
;
5922 use_kerberos
= True
;
5924 d_printf("No kerberos support compiled in\n");
5930 fstrcpy(username
,optarg
);
5931 p
= strchr_m(username
,'%');
5934 fstrcpy(password
, p
+1);
5939 fstrcpy(multishare_conn_fname
, optarg
);
5940 use_multishare_conn
= True
;
5943 torture_blocksize
= atoi(optarg
);
5946 printf("Unknown option %c (%d)\n", (char)opt
, opt
);
5951 d_printf("using seed %d\n", seed
);
5955 if(use_kerberos
&& !gotuser
) gotpass
= True
;
5958 p
= getpass("Password:");
5960 fstrcpy(password
, p
);
5965 printf("host=%s share=%s user=%s myname=%s\n",
5966 host
, share
, username
, myname
);
5968 if (argc
== optind
) {
5969 correct
= run_test("ALL");
5971 for (i
=optind
;i
<argc
;i
++) {
5972 if (!run_test(argv
[i
])) {