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/>.
21 #include "wbc_async.h"
26 static fstring host, workgroup, share, password, username, myname;
27 static int max_protocol = PROTOCOL_NT1;
28 static const char *sockops="TCP_NODELAY";
30 static int port_to_use=0;
31 int torture_numops=100;
32 int torture_blocksize=1024*1024;
33 static int procnum; /* records process count number when forking */
34 static struct cli_state *current_cli;
35 static fstring randomfname;
36 static bool use_oplocks;
37 static bool use_level_II_oplocks;
38 static const char *client_txt = "client_oplocks.txt";
39 static bool use_kerberos;
40 static fstring multishare_conn_fname;
41 static bool use_multishare_conn = False;
42 static bool do_encrypt;
44 bool torture_showall = False;
46 static double create_procs(bool (*fn)(int), bool *result);
49 static struct timeval tp1,tp2;
52 void start_timer(void)
57 double end_timer(void)
60 return((tp2.tv_sec - tp1.tv_sec) +
61 (tp2.tv_usec - tp1.tv_usec)*1.0e-6);
65 /* return a pointer to a anonymous shared memory segment of size "size"
66 which will persist across fork() but will disappear when all processes
69 The memory is not zeroed
71 This function uses system5 shared memory. It takes advantage of a property
72 that the memory is not destroyed if it is attached when the id is removed
74 void *shm_setup(int size)
79 shmid = shmget(IPC_PRIVATE, size, S_IRUSR | S_IWUSR);
81 printf("can't get shared memory\n");
84 ret = (void *)shmat(shmid, 0, 0);
85 if (!ret || ret == (void *)-1) {
86 printf("can't attach to shared memory\n");
89 /* the following releases the ipc, but note that this process
90 and all its children will still have access to the memory, its
91 just that the shmid is no longer valid for other shm calls. This
92 means we don't leave behind lots of shm segments after we exit
94 See Stevens "advanced programming in unix env" for details
96 shmctl(shmid, IPC_RMID, 0);
101 /********************************************************************
102 Ensure a connection is encrypted.
103 ********************************************************************/
105 static bool force_cli_encryption(struct cli_state *c,
106 const char *sharename)
109 uint32 caplow, caphigh;
112 if (!SERVER_HAS_UNIX_CIFS(c)) {
113 d_printf("Encryption required and "
114 "server that doesn't support "
115 "UNIX extensions - failing connect\n");
119 if (!cli_unix_extensions_version(c, &major, &minor, &caplow, &caphigh)) {
120 d_printf("Encryption required and "
121 "can't get UNIX CIFS extensions "
122 "version from server.\n");
126 if (!(caplow & CIFS_UNIX_TRANSPORT_ENCRYPTION_CAP)) {
127 d_printf("Encryption required and "
128 "share %s doesn't support "
129 "encryption.\n", sharename);
133 if (c->use_kerberos) {
134 status = cli_gss_smb_encryption_start(c);
136 status = cli_raw_ntlm_smb_encryption_start(c,
142 if (!NT_STATUS_IS_OK(status)) {
143 d_printf("Encryption required and "
144 "setup failed with error %s.\n",
153 static struct cli_state *open_nbt_connection(void)
155 struct nmb_name called, calling;
156 struct sockaddr_storage ss;
160 make_nmb_name(&calling, myname, 0x0);
161 make_nmb_name(&called , host, 0x20);
165 if (!(c = cli_initialise())) {
166 printf("Failed initialize cli_struct to connect with %s\n", host);
170 c->port = port_to_use;
172 status = cli_connect(c, host, &ss);
173 if (!NT_STATUS_IS_OK(status)) {
174 printf("Failed to connect with %s. Error %s\n", host, nt_errstr(status) );
178 c->use_kerberos = use_kerberos;
180 c->timeout = 120000; /* set a really long timeout (2 minutes) */
181 if (use_oplocks) c->use_oplocks = True;
182 if (use_level_II_oplocks) c->use_level_II_oplocks = True;
184 if (!cli_session_request(c, &calling, &called)) {
186 * Well, that failed, try *SMBSERVER ...
187 * However, we must reconnect as well ...
189 status = cli_connect(c, host, &ss);
190 if (!NT_STATUS_IS_OK(status)) {
191 printf("Failed to connect with %s. Error %s\n", host, nt_errstr(status) );
195 make_nmb_name(&called, "*SMBSERVER", 0x20);
196 if (!cli_session_request(c, &calling, &called)) {
197 printf("%s rejected the session\n",host);
198 printf("We tried with a called name of %s & %s\n",
208 /* Insert a NULL at the first separator of the given path and return a pointer
209 * to the remainder of the string.
212 terminate_path_at_separator(char * path)
220 if ((p = strchr_m(path, '/'))) {
225 if ((p = strchr_m(path, '\\'))) {
235 parse a //server/share type UNC name
237 bool smbcli_parse_unc(const char *unc_name, TALLOC_CTX *mem_ctx,
238 char **hostname, char **sharename)
242 *hostname = *sharename = NULL;
244 if (strncmp(unc_name, "\\\\", 2) &&
245 strncmp(unc_name, "//", 2)) {
249 *hostname = talloc_strdup(mem_ctx, &unc_name[2]);
250 p = terminate_path_at_separator(*hostname);
253 *sharename = talloc_strdup(mem_ctx, p);
254 terminate_path_at_separator(*sharename);
257 if (*hostname && *sharename) {
261 TALLOC_FREE(*hostname);
262 TALLOC_FREE(*sharename);
266 static bool torture_open_connection_share(struct cli_state **c,
267 const char *hostname,
268 const char *sharename)
275 flags |= CLI_FULL_CONNECTION_USE_KERBEROS;
277 status = cli_full_connection(c, myname,
278 hostname, NULL, port_to_use,
281 password, flags, Undefined, &retry);
282 if (!NT_STATUS_IS_OK(status)) {
283 printf("failed to open share connection: //%s/%s port:%d - %s\n",
284 hostname, sharename, port_to_use, nt_errstr(status));
288 if (use_oplocks) (*c)->use_oplocks = True;
289 if (use_level_II_oplocks) (*c)->use_level_II_oplocks = True;
290 (*c)->timeout = 120000; /* set a really long timeout (2 minutes) */
293 return force_cli_encryption(*c,
299 bool torture_open_connection(struct cli_state **c, int conn_index)
301 char **unc_list = NULL;
302 int num_unc_names = 0;
305 if (use_multishare_conn==True) {
307 unc_list = file_lines_load(multishare_conn_fname, &num_unc_names, 0, NULL);
308 if (!unc_list || num_unc_names <= 0) {
309 printf("Failed to load unc names list from '%s'\n", multishare_conn_fname);
313 if (!smbcli_parse_unc(unc_list[conn_index % num_unc_names],
315 printf("Failed to parse UNC name %s\n",
316 unc_list[conn_index % num_unc_names]);
317 TALLOC_FREE(unc_list);
321 result = torture_open_connection_share(c, h, s);
323 /* h, s were copied earlier */
324 TALLOC_FREE(unc_list);
328 return torture_open_connection_share(c, host, share);
331 bool torture_cli_session_setup2(struct cli_state *cli, uint16 *new_vuid)
333 uint16 old_vuid = cli->vuid;
334 fstring old_user_name;
335 size_t passlen = strlen(password);
338 fstrcpy(old_user_name, cli->user_name);
340 ret = NT_STATUS_IS_OK(cli_session_setup(cli, username,
344 *new_vuid = cli->vuid;
345 cli->vuid = old_vuid;
346 fstrcpy(cli->user_name, old_user_name);
351 bool torture_close_connection(struct cli_state *c)
355 printf("tdis failed (%s)\n", cli_errstr(c));
365 /* check if the server produced the expected error code */
366 static bool check_error(int line, struct cli_state *c,
367 uint8 eclass, uint32 ecode, NTSTATUS nterr)
369 if (cli_is_dos_error(c)) {
373 /* Check DOS error */
375 cli_dos_error(c, &cclass, &num);
377 if (eclass != cclass || ecode != num) {
378 printf("unexpected error code class=%d code=%d\n",
379 (int)cclass, (int)num);
380 printf(" expected %d/%d %s (line=%d)\n",
381 (int)eclass, (int)ecode, nt_errstr(nterr), line);
390 status = cli_nt_error(c);
392 if (NT_STATUS_V(nterr) != NT_STATUS_V(status)) {
393 printf("unexpected error code %s\n", nt_errstr(status));
394 printf(" expected %s (line=%d)\n", nt_errstr(nterr), line);
403 static bool wait_lock(struct cli_state *c, int fnum, uint32 offset, uint32 len)
405 while (!cli_lock(c, fnum, offset, len, -1, WRITE_LOCK)) {
406 if (!check_error(__LINE__, c, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
412 static bool rw_torture(struct cli_state *c)
414 const char *lockfname = "\\torture.lck";
418 pid_t pid2, pid = getpid();
423 memset(buf, '\0', sizeof(buf));
425 fnum2 = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
428 fnum2 = cli_open(c, lockfname, O_RDWR, DENY_NONE);
430 printf("open of %s failed (%s)\n", lockfname, cli_errstr(c));
435 for (i=0;i<torture_numops;i++) {
436 unsigned n = (unsigned)sys_random()%10;
438 printf("%d\r", i); fflush(stdout);
440 slprintf(fname, sizeof(fstring) - 1, "\\torture.%u", n);
442 if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) {
446 fnum = cli_open(c, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL);
448 printf("open failed (%s)\n", cli_errstr(c));
453 if (cli_write(c, fnum, 0, (char *)&pid, 0, sizeof(pid)) != sizeof(pid)) {
454 printf("write failed (%s)\n", cli_errstr(c));
459 if (cli_write(c, fnum, 0, (char *)buf,
460 sizeof(pid)+(j*sizeof(buf)),
461 sizeof(buf)) != sizeof(buf)) {
462 printf("write failed (%s)\n", cli_errstr(c));
469 if (cli_read(c, fnum, (char *)&pid2, 0, sizeof(pid)) != sizeof(pid)) {
470 printf("read failed (%s)\n", cli_errstr(c));
475 printf("data corruption!\n");
479 if (!cli_close(c, fnum)) {
480 printf("close failed (%s)\n", cli_errstr(c));
484 if (!cli_unlink(c, fname)) {
485 printf("unlink failed (%s)\n", cli_errstr(c));
489 if (!cli_unlock(c, fnum2, n*sizeof(int), sizeof(int))) {
490 printf("unlock failed (%s)\n", cli_errstr(c));
496 cli_unlink(c, lockfname);
503 static bool run_torture(int dummy)
505 struct cli_state *cli;
510 cli_sockopt(cli, sockops);
512 ret = rw_torture(cli);
514 if (!torture_close_connection(cli)) {
521 static bool rw_torture3(struct cli_state *c, char *lockfname)
528 unsigned countprev = 0;
533 for (i = 0; i < sizeof(buf); i += sizeof(uint32))
535 SIVAL(buf, i, sys_random());
540 fnum = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
543 printf("first open read/write of %s failed (%s)\n",
544 lockfname, cli_errstr(c));
550 for (i = 0; i < 500 && fnum == -1; i++)
552 fnum = cli_open(c, lockfname, O_RDONLY,
557 printf("second open read-only of %s failed (%s)\n",
558 lockfname, cli_errstr(c));
564 for (count = 0; count < sizeof(buf); count += sent)
566 if (count >= countprev) {
567 printf("%d %8d\r", i, count);
570 countprev += (sizeof(buf) / 20);
575 sent = ((unsigned)sys_random()%(20))+ 1;
576 if (sent > sizeof(buf) - count)
578 sent = sizeof(buf) - count;
581 if (cli_write(c, fnum, 0, buf+count, count, (size_t)sent) != sent) {
582 printf("write failed (%s)\n", cli_errstr(c));
588 sent = cli_read(c, fnum, buf_rd+count, count,
592 printf("read failed offset:%d size:%ld (%s)\n",
593 count, (unsigned long)sizeof(buf)-count,
600 if (memcmp(buf_rd+count, buf+count, sent) != 0)
602 printf("read/write compare failed\n");
603 printf("offset: %d req %ld recvd %ld\n", count, (unsigned long)sizeof(buf)-count, (unsigned long)sent);
612 if (!cli_close(c, fnum)) {
613 printf("close failed (%s)\n", cli_errstr(c));
620 static bool rw_torture2(struct cli_state *c1, struct cli_state *c2)
622 const char *lockfname = "\\torture2.lck";
631 if (!cli_unlink(c1, lockfname)) {
632 printf("unlink failed (%s) (normal, this file should not exist)\n", cli_errstr(c1));
635 fnum1 = cli_open(c1, lockfname, O_RDWR | O_CREAT | O_EXCL,
638 printf("first open read/write of %s failed (%s)\n",
639 lockfname, cli_errstr(c1));
642 fnum2 = cli_open(c2, lockfname, O_RDONLY,
645 printf("second open read-only of %s failed (%s)\n",
646 lockfname, cli_errstr(c2));
647 cli_close(c1, fnum1);
651 for (i=0;i<torture_numops;i++)
653 size_t buf_size = ((unsigned)sys_random()%(sizeof(buf)-1))+ 1;
655 printf("%d\r", i); fflush(stdout);
658 generate_random_buffer((unsigned char *)buf, buf_size);
660 if (cli_write(c1, fnum1, 0, buf, 0, buf_size) != buf_size) {
661 printf("write failed (%s)\n", cli_errstr(c1));
666 if ((bytes_read = cli_read(c2, fnum2, buf_rd, 0, buf_size)) != buf_size) {
667 printf("read failed (%s)\n", cli_errstr(c2));
668 printf("read %d, expected %ld\n", (int)bytes_read,
669 (unsigned long)buf_size);
674 if (memcmp(buf_rd, buf, buf_size) != 0)
676 printf("read/write compare failed\n");
682 if (!cli_close(c2, fnum2)) {
683 printf("close failed (%s)\n", cli_errstr(c2));
686 if (!cli_close(c1, fnum1)) {
687 printf("close failed (%s)\n", cli_errstr(c1));
691 if (!cli_unlink(c1, lockfname)) {
692 printf("unlink failed (%s)\n", cli_errstr(c1));
699 static bool run_readwritetest(int dummy)
701 static struct cli_state *cli1, *cli2;
702 bool test1, test2 = False;
704 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
707 cli_sockopt(cli1, sockops);
708 cli_sockopt(cli2, sockops);
710 printf("starting readwritetest\n");
712 test1 = rw_torture2(cli1, cli2);
713 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1));
716 test2 = rw_torture2(cli1, cli1);
717 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2));
720 if (!torture_close_connection(cli1)) {
724 if (!torture_close_connection(cli2)) {
728 return (test1 && test2);
731 static bool run_readwritemulti(int dummy)
733 struct cli_state *cli;
738 cli_sockopt(cli, sockops);
740 printf("run_readwritemulti: fname %s\n", randomfname);
741 test = rw_torture3(cli, randomfname);
743 if (!torture_close_connection(cli)) {
750 static bool run_readwritelarge(int dummy)
752 static struct cli_state *cli1;
754 const char *lockfname = "\\large.dat";
759 if (!torture_open_connection(&cli1, 0)) {
762 cli_sockopt(cli1, sockops);
763 memset(buf,'\0',sizeof(buf));
765 cli1->max_xmit = 128*1024;
767 printf("starting readwritelarge\n");
769 cli_unlink(cli1, lockfname);
771 fnum1 = cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE);
773 printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(cli1));
777 cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf));
779 if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
780 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
784 if (fsize == sizeof(buf))
785 printf("readwritelarge test 1 succeeded (size = %lx)\n",
786 (unsigned long)fsize);
788 printf("readwritelarge test 1 failed (size = %lx)\n",
789 (unsigned long)fsize);
793 if (!cli_close(cli1, fnum1)) {
794 printf("close failed (%s)\n", cli_errstr(cli1));
798 if (!cli_unlink(cli1, lockfname)) {
799 printf("unlink failed (%s)\n", cli_errstr(cli1));
803 fnum1 = cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE);
805 printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(cli1));
809 cli1->max_xmit = 4*1024;
811 cli_smbwrite(cli1, fnum1, buf, 0, sizeof(buf));
813 if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
814 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
818 if (fsize == sizeof(buf))
819 printf("readwritelarge test 2 succeeded (size = %lx)\n",
820 (unsigned long)fsize);
822 printf("readwritelarge test 2 failed (size = %lx)\n",
823 (unsigned long)fsize);
828 /* ToDo - set allocation. JRA */
829 if(!cli_set_allocation_size(cli1, fnum1, 0)) {
830 printf("set allocation size to zero failed (%s)\n", cli_errstr(&cli1));
833 if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
834 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
838 printf("readwritelarge test 3 (truncate test) succeeded (size = %x)\n", fsize);
841 if (!cli_close(cli1, fnum1)) {
842 printf("close failed (%s)\n", cli_errstr(cli1));
846 if (!torture_close_connection(cli1)) {
855 #define ival(s) strtol(s, NULL, 0)
857 /* run a test that simulates an approximate netbench client load */
858 static bool run_netbench(int client)
860 struct cli_state *cli;
865 const char *params[20];
872 cli_sockopt(cli, sockops);
876 slprintf(cname,sizeof(cname)-1, "client%d", client);
878 f = fopen(client_txt, "r");
885 while (fgets(line, sizeof(line)-1, f)) {
889 line[strlen(line)-1] = 0;
891 /* printf("[%d] %s\n", line_count, line); */
893 all_string_sub(line,"client1", cname, sizeof(line));
895 /* parse the command parameters */
896 params[0] = strtok_r(line, " ", &saveptr);
898 while (params[i]) params[++i] = strtok_r(NULL, " ", &saveptr);
904 if (!strncmp(params[0],"SMB", 3)) {
905 printf("ERROR: You are using a dbench 1 load file\n");
909 if (!strcmp(params[0],"NTCreateX")) {
910 nb_createx(params[1], ival(params[2]), ival(params[3]),
912 } else if (!strcmp(params[0],"Close")) {
913 nb_close(ival(params[1]));
914 } else if (!strcmp(params[0],"Rename")) {
915 nb_rename(params[1], params[2]);
916 } else if (!strcmp(params[0],"Unlink")) {
917 nb_unlink(params[1]);
918 } else if (!strcmp(params[0],"Deltree")) {
919 nb_deltree(params[1]);
920 } else if (!strcmp(params[0],"Rmdir")) {
922 } else if (!strcmp(params[0],"QUERY_PATH_INFORMATION")) {
923 nb_qpathinfo(params[1]);
924 } else if (!strcmp(params[0],"QUERY_FILE_INFORMATION")) {
925 nb_qfileinfo(ival(params[1]));
926 } else if (!strcmp(params[0],"QUERY_FS_INFORMATION")) {
927 nb_qfsinfo(ival(params[1]));
928 } else if (!strcmp(params[0],"FIND_FIRST")) {
929 nb_findfirst(params[1]);
930 } else if (!strcmp(params[0],"WriteX")) {
931 nb_writex(ival(params[1]),
932 ival(params[2]), ival(params[3]), ival(params[4]));
933 } else if (!strcmp(params[0],"ReadX")) {
934 nb_readx(ival(params[1]),
935 ival(params[2]), ival(params[3]), ival(params[4]));
936 } else if (!strcmp(params[0],"Flush")) {
937 nb_flush(ival(params[1]));
939 printf("Unknown operation %s\n", params[0]);
947 if (!torture_close_connection(cli)) {
955 /* run a test that simulates an approximate netbench client load */
956 static bool run_nbench(int dummy)
965 signal(SIGALRM, nb_alarm);
967 t = create_procs(run_netbench, &correct);
970 printf("\nThroughput %g MB/sec\n",
971 1.0e-6 * nbio_total() / t);
977 This test checks for two things:
979 1) correct support for retaining locks over a close (ie. the server
980 must not use posix semantics)
981 2) support for lock timeouts
983 static bool run_locktest1(int dummy)
985 struct cli_state *cli1, *cli2;
986 const char *fname = "\\lockt1.lck";
987 int fnum1, fnum2, fnum3;
989 unsigned lock_timeout;
991 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
994 cli_sockopt(cli1, sockops);
995 cli_sockopt(cli2, sockops);
997 printf("starting locktest1\n");
999 cli_unlink(cli1, fname);
1001 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1003 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
1006 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1008 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli1));
1011 fnum3 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1013 printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli2));
1017 if (!cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
1018 printf("lock1 failed (%s)\n", cli_errstr(cli1));
1023 if (cli_lock(cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
1024 printf("lock2 succeeded! This is a locking bug\n");
1027 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
1028 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1032 lock_timeout = (1 + (random() % 20));
1033 printf("Testing lock timeout with timeout=%u\n", lock_timeout);
1035 if (cli_lock(cli2, fnum3, 0, 4, lock_timeout * 1000, WRITE_LOCK)) {
1036 printf("lock3 succeeded! This is a locking bug\n");
1039 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
1040 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
1044 if (ABS(t2 - t1) < lock_timeout-1) {
1045 printf("error: This server appears not to support timed lock requests\n");
1048 printf("server slept for %u seconds for a %u second timeout\n",
1049 (unsigned int)(t2-t1), lock_timeout);
1051 if (!cli_close(cli1, fnum2)) {
1052 printf("close1 failed (%s)\n", cli_errstr(cli1));
1056 if (cli_lock(cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
1057 printf("lock4 succeeded! This is a locking bug\n");
1060 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
1061 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
1064 if (!cli_close(cli1, fnum1)) {
1065 printf("close2 failed (%s)\n", cli_errstr(cli1));
1069 if (!cli_close(cli2, fnum3)) {
1070 printf("close3 failed (%s)\n", cli_errstr(cli2));
1074 if (!cli_unlink(cli1, fname)) {
1075 printf("unlink failed (%s)\n", cli_errstr(cli1));
1080 if (!torture_close_connection(cli1)) {
1084 if (!torture_close_connection(cli2)) {
1088 printf("Passed locktest1\n");
1093 this checks to see if a secondary tconx can use open files from an
1096 static bool run_tcon_test(int dummy)
1098 static struct cli_state *cli;
1099 const char *fname = "\\tcontest.tmp";
1101 uint16 cnum1, cnum2, cnum3;
1102 uint16 vuid1, vuid2;
1107 memset(buf, '\0', sizeof(buf));
1109 if (!torture_open_connection(&cli, 0)) {
1112 cli_sockopt(cli, sockops);
1114 printf("starting tcontest\n");
1116 cli_unlink(cli, fname);
1118 fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1120 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
1127 if (cli_write(cli, fnum1, 0, buf, 130, 4) != 4) {
1128 printf("initial write failed (%s)", cli_errstr(cli));
1132 status = cli_tcon_andx(cli, share, "?????",
1133 password, strlen(password)+1);
1134 if (!NT_STATUS_IS_OK(status)) {
1135 printf("%s refused 2nd tree connect (%s)\n", host,
1142 cnum3 = MAX(cnum1, cnum2) + 1; /* any invalid number */
1143 vuid2 = cli->vuid + 1;
1145 /* try a write with the wrong tid */
1148 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
1149 printf("* server allows write with wrong TID\n");
1152 printf("server fails write with wrong TID : %s\n", cli_errstr(cli));
1156 /* try a write with an invalid tid */
1159 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
1160 printf("* server allows write with invalid TID\n");
1163 printf("server fails write with invalid TID : %s\n", cli_errstr(cli));
1166 /* try a write with an invalid vuid */
1170 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
1171 printf("* server allows write with invalid VUID\n");
1174 printf("server fails write with invalid VUID : %s\n", cli_errstr(cli));
1180 if (!cli_close(cli, fnum1)) {
1181 printf("close failed (%s)\n", cli_errstr(cli));
1187 if (!cli_tdis(cli)) {
1188 printf("secondary tdis failed (%s)\n", cli_errstr(cli));
1194 if (!torture_close_connection(cli)) {
1203 checks for old style tcon support
1205 static bool run_tcon2_test(int dummy)
1207 static struct cli_state *cli;
1208 uint16 cnum, max_xmit;
1212 if (!torture_open_connection(&cli, 0)) {
1215 cli_sockopt(cli, sockops);
1217 printf("starting tcon2 test\n");
1219 if (asprintf(&service, "\\\\%s\\%s", host, share) == -1) {
1223 status = cli_raw_tcon(cli, service, password, "?????", &max_xmit, &cnum);
1225 if (!NT_STATUS_IS_OK(status)) {
1226 printf("tcon2 failed : %s\n", cli_errstr(cli));
1228 printf("tcon OK : max_xmit=%d cnum=%d tid=%d\n",
1229 (int)max_xmit, (int)cnum, SVAL(cli->inbuf, smb_tid));
1232 if (!torture_close_connection(cli)) {
1236 printf("Passed tcon2 test\n");
1240 static bool tcon_devtest(struct cli_state *cli,
1241 const char *myshare, const char *devtype,
1242 const char *return_devtype,
1243 NTSTATUS expected_error)
1248 status = cli_tcon_andx(cli, myshare, devtype,
1249 password, strlen(password)+1);
1251 if (NT_STATUS_IS_OK(expected_error)) {
1252 if (NT_STATUS_IS_OK(status)) {
1253 if (strcmp(cli->dev, return_devtype) == 0) {
1256 printf("tconX to share %s with type %s "
1257 "succeeded but returned the wrong "
1258 "device type (got [%s] but should have got [%s])\n",
1259 myshare, devtype, cli->dev, return_devtype);
1263 printf("tconX to share %s with type %s "
1264 "should have succeeded but failed\n",
1270 if (NT_STATUS_IS_OK(status)) {
1271 printf("tconx to share %s with type %s "
1272 "should have failed but succeeded\n",
1276 if (NT_STATUS_EQUAL(cli_nt_error(cli),
1280 printf("Returned unexpected error\n");
1289 checks for correct tconX support
1291 static bool run_tcon_devtype_test(int dummy)
1293 static struct cli_state *cli1 = NULL;
1299 status = cli_full_connection(&cli1, myname,
1300 host, NULL, port_to_use,
1302 username, workgroup,
1303 password, flags, Undefined, &retry);
1305 if (!NT_STATUS_IS_OK(status)) {
1306 printf("could not open connection\n");
1310 if (!tcon_devtest(cli1, "IPC$", "A:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1313 if (!tcon_devtest(cli1, "IPC$", "?????", "IPC", NT_STATUS_OK))
1316 if (!tcon_devtest(cli1, "IPC$", "LPT:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1319 if (!tcon_devtest(cli1, "IPC$", "IPC", "IPC", NT_STATUS_OK))
1322 if (!tcon_devtest(cli1, "IPC$", "FOOBA", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1325 if (!tcon_devtest(cli1, share, "A:", "A:", NT_STATUS_OK))
1328 if (!tcon_devtest(cli1, share, "?????", "A:", NT_STATUS_OK))
1331 if (!tcon_devtest(cli1, share, "LPT:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1334 if (!tcon_devtest(cli1, share, "IPC", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1337 if (!tcon_devtest(cli1, share, "FOOBA", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1343 printf("Passed tcondevtest\n");
1350 This test checks that
1352 1) the server supports multiple locking contexts on the one SMB
1353 connection, distinguished by PID.
1355 2) the server correctly fails overlapping locks made by the same PID (this
1356 goes against POSIX behaviour, which is why it is tricky to implement)
1358 3) the server denies unlock requests by an incorrect client PID
1360 static bool run_locktest2(int dummy)
1362 static struct cli_state *cli;
1363 const char *fname = "\\lockt2.lck";
1364 int fnum1, fnum2, fnum3;
1365 bool correct = True;
1367 if (!torture_open_connection(&cli, 0)) {
1371 cli_sockopt(cli, sockops);
1373 printf("starting locktest2\n");
1375 cli_unlink(cli, fname);
1379 fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1381 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
1385 fnum2 = cli_open(cli, fname, O_RDWR, DENY_NONE);
1387 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli));
1393 fnum3 = cli_open(cli, fname, O_RDWR, DENY_NONE);
1395 printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli));
1401 if (!cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
1402 printf("lock1 failed (%s)\n", cli_errstr(cli));
1406 if (cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
1407 printf("WRITE lock1 succeeded! This is a locking bug\n");
1410 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1411 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1414 if (cli_lock(cli, fnum2, 0, 4, 0, WRITE_LOCK)) {
1415 printf("WRITE lock2 succeeded! This is a locking bug\n");
1418 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1419 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1422 if (cli_lock(cli, fnum2, 0, 4, 0, READ_LOCK)) {
1423 printf("READ lock2 succeeded! This is a locking bug\n");
1426 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1427 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
1430 if (!cli_lock(cli, fnum1, 100, 4, 0, WRITE_LOCK)) {
1431 printf("lock at 100 failed (%s)\n", cli_errstr(cli));
1434 if (cli_unlock(cli, fnum1, 100, 4)) {
1435 printf("unlock at 100 succeeded! This is a locking bug\n");
1439 if (cli_unlock(cli, fnum1, 0, 4)) {
1440 printf("unlock1 succeeded! This is a locking bug\n");
1443 if (!check_error(__LINE__, cli,
1445 NT_STATUS_RANGE_NOT_LOCKED)) return False;
1448 if (cli_unlock(cli, fnum1, 0, 8)) {
1449 printf("unlock2 succeeded! This is a locking bug\n");
1452 if (!check_error(__LINE__, cli,
1454 NT_STATUS_RANGE_NOT_LOCKED)) return False;
1457 if (cli_lock(cli, fnum3, 0, 4, 0, WRITE_LOCK)) {
1458 printf("lock3 succeeded! This is a locking bug\n");
1461 if (!check_error(__LINE__, cli, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
1466 if (!cli_close(cli, fnum1)) {
1467 printf("close1 failed (%s)\n", cli_errstr(cli));
1471 if (!cli_close(cli, fnum2)) {
1472 printf("close2 failed (%s)\n", cli_errstr(cli));
1476 if (!cli_close(cli, fnum3)) {
1477 printf("close3 failed (%s)\n", cli_errstr(cli));
1481 if (!torture_close_connection(cli)) {
1485 printf("locktest2 finished\n");
1492 This test checks that
1494 1) the server supports the full offset range in lock requests
1496 static bool run_locktest3(int dummy)
1498 static struct cli_state *cli1, *cli2;
1499 const char *fname = "\\lockt3.lck";
1500 int fnum1, fnum2, i;
1502 bool correct = True;
1504 #define NEXT_OFFSET offset += (~(uint32)0) / torture_numops
1506 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1509 cli_sockopt(cli1, sockops);
1510 cli_sockopt(cli2, sockops);
1512 printf("starting locktest3\n");
1514 cli_unlink(cli1, fname);
1516 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1518 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
1521 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1523 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli2));
1527 for (offset=i=0;i<torture_numops;i++) {
1529 if (!cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1530 printf("lock1 %d failed (%s)\n",
1536 if (!cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1537 printf("lock2 %d failed (%s)\n",
1544 for (offset=i=0;i<torture_numops;i++) {
1547 if (cli_lock(cli1, fnum1, offset-2, 1, 0, WRITE_LOCK)) {
1548 printf("error: lock1 %d succeeded!\n", i);
1552 if (cli_lock(cli2, fnum2, offset-1, 1, 0, WRITE_LOCK)) {
1553 printf("error: lock2 %d succeeded!\n", i);
1557 if (cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1558 printf("error: lock3 %d succeeded!\n", i);
1562 if (cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1563 printf("error: lock4 %d succeeded!\n", i);
1568 for (offset=i=0;i<torture_numops;i++) {
1571 if (!cli_unlock(cli1, fnum1, offset-1, 1)) {
1572 printf("unlock1 %d failed (%s)\n",
1578 if (!cli_unlock(cli2, fnum2, offset-2, 1)) {
1579 printf("unlock2 %d failed (%s)\n",
1586 if (!cli_close(cli1, fnum1)) {
1587 printf("close1 failed (%s)\n", cli_errstr(cli1));
1591 if (!cli_close(cli2, fnum2)) {
1592 printf("close2 failed (%s)\n", cli_errstr(cli2));
1596 if (!cli_unlink(cli1, fname)) {
1597 printf("unlink failed (%s)\n", cli_errstr(cli1));
1601 if (!torture_close_connection(cli1)) {
1605 if (!torture_close_connection(cli2)) {
1609 printf("finished locktest3\n");
1614 #define EXPECTED(ret, v) if ((ret) != (v)) { \
1615 printf("** "); correct = False; \
1619 looks at overlapping locks
1621 static bool run_locktest4(int dummy)
1623 static struct cli_state *cli1, *cli2;
1624 const char *fname = "\\lockt4.lck";
1625 int fnum1, fnum2, f;
1628 bool correct = True;
1630 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1634 cli_sockopt(cli1, sockops);
1635 cli_sockopt(cli2, sockops);
1637 printf("starting locktest4\n");
1639 cli_unlink(cli1, fname);
1641 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1642 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1644 memset(buf, 0, sizeof(buf));
1646 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1647 printf("Failed to create file\n");
1652 ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1653 cli_lock(cli1, fnum1, 2, 4, 0, WRITE_LOCK);
1654 EXPECTED(ret, False);
1655 printf("the same process %s set overlapping write locks\n", ret?"can":"cannot");
1657 ret = cli_lock(cli1, fnum1, 10, 4, 0, READ_LOCK) &&
1658 cli_lock(cli1, fnum1, 12, 4, 0, READ_LOCK);
1659 EXPECTED(ret, True);
1660 printf("the same process %s set overlapping read locks\n", ret?"can":"cannot");
1662 ret = cli_lock(cli1, fnum1, 20, 4, 0, WRITE_LOCK) &&
1663 cli_lock(cli2, fnum2, 22, 4, 0, WRITE_LOCK);
1664 EXPECTED(ret, False);
1665 printf("a different connection %s set overlapping write locks\n", ret?"can":"cannot");
1667 ret = cli_lock(cli1, fnum1, 30, 4, 0, READ_LOCK) &&
1668 cli_lock(cli2, fnum2, 32, 4, 0, READ_LOCK);
1669 EXPECTED(ret, True);
1670 printf("a different connection %s set overlapping read locks\n", ret?"can":"cannot");
1672 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 40, 4, 0, WRITE_LOCK)) &&
1673 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 42, 4, 0, WRITE_LOCK));
1674 EXPECTED(ret, False);
1675 printf("a different pid %s set overlapping write locks\n", ret?"can":"cannot");
1677 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 50, 4, 0, READ_LOCK)) &&
1678 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 52, 4, 0, READ_LOCK));
1679 EXPECTED(ret, True);
1680 printf("a different pid %s set overlapping read locks\n", ret?"can":"cannot");
1682 ret = cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK) &&
1683 cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK);
1684 EXPECTED(ret, True);
1685 printf("the same process %s set the same read lock twice\n", ret?"can":"cannot");
1687 ret = cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK) &&
1688 cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK);
1689 EXPECTED(ret, False);
1690 printf("the same process %s set the same write lock twice\n", ret?"can":"cannot");
1692 ret = cli_lock(cli1, fnum1, 80, 4, 0, READ_LOCK) &&
1693 cli_lock(cli1, fnum1, 80, 4, 0, WRITE_LOCK);
1694 EXPECTED(ret, False);
1695 printf("the same process %s overlay a read lock with a write lock\n", ret?"can":"cannot");
1697 ret = cli_lock(cli1, fnum1, 90, 4, 0, WRITE_LOCK) &&
1698 cli_lock(cli1, fnum1, 90, 4, 0, READ_LOCK);
1699 EXPECTED(ret, True);
1700 printf("the same process %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1702 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 100, 4, 0, WRITE_LOCK)) &&
1703 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 100, 4, 0, READ_LOCK));
1704 EXPECTED(ret, False);
1705 printf("a different pid %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1707 ret = cli_lock(cli1, fnum1, 110, 4, 0, READ_LOCK) &&
1708 cli_lock(cli1, fnum1, 112, 4, 0, READ_LOCK) &&
1709 cli_unlock(cli1, fnum1, 110, 6);
1710 EXPECTED(ret, False);
1711 printf("the same process %s coalesce read locks\n", ret?"can":"cannot");
1714 ret = cli_lock(cli1, fnum1, 120, 4, 0, WRITE_LOCK) &&
1715 (cli_read(cli2, fnum2, buf, 120, 4) == 4);
1716 EXPECTED(ret, False);
1717 printf("this server %s strict write locking\n", ret?"doesn't do":"does");
1719 ret = cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK) &&
1720 (cli_write(cli2, fnum2, 0, buf, 130, 4) == 4);
1721 EXPECTED(ret, False);
1722 printf("this server %s strict read locking\n", ret?"doesn't do":"does");
1725 ret = cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1726 cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1727 cli_unlock(cli1, fnum1, 140, 4) &&
1728 cli_unlock(cli1, fnum1, 140, 4);
1729 EXPECTED(ret, True);
1730 printf("this server %s do recursive read locking\n", ret?"does":"doesn't");
1733 ret = cli_lock(cli1, fnum1, 150, 4, 0, WRITE_LOCK) &&
1734 cli_lock(cli1, fnum1, 150, 4, 0, READ_LOCK) &&
1735 cli_unlock(cli1, fnum1, 150, 4) &&
1736 (cli_read(cli2, fnum2, buf, 150, 4) == 4) &&
1737 !(cli_write(cli2, fnum2, 0, buf, 150, 4) == 4) &&
1738 cli_unlock(cli1, fnum1, 150, 4);
1739 EXPECTED(ret, True);
1740 printf("this server %s do recursive lock overlays\n", ret?"does":"doesn't");
1742 ret = cli_lock(cli1, fnum1, 160, 4, 0, READ_LOCK) &&
1743 cli_unlock(cli1, fnum1, 160, 4) &&
1744 (cli_write(cli2, fnum2, 0, buf, 160, 4) == 4) &&
1745 (cli_read(cli2, fnum2, buf, 160, 4) == 4);
1746 EXPECTED(ret, True);
1747 printf("the same process %s remove a read lock using write locking\n", ret?"can":"cannot");
1749 ret = cli_lock(cli1, fnum1, 170, 4, 0, WRITE_LOCK) &&
1750 cli_unlock(cli1, fnum1, 170, 4) &&
1751 (cli_write(cli2, fnum2, 0, buf, 170, 4) == 4) &&
1752 (cli_read(cli2, fnum2, buf, 170, 4) == 4);
1753 EXPECTED(ret, True);
1754 printf("the same process %s remove a write lock using read locking\n", ret?"can":"cannot");
1756 ret = cli_lock(cli1, fnum1, 190, 4, 0, WRITE_LOCK) &&
1757 cli_lock(cli1, fnum1, 190, 4, 0, READ_LOCK) &&
1758 cli_unlock(cli1, fnum1, 190, 4) &&
1759 !(cli_write(cli2, fnum2, 0, buf, 190, 4) == 4) &&
1760 (cli_read(cli2, fnum2, buf, 190, 4) == 4);
1761 EXPECTED(ret, True);
1762 printf("the same process %s remove the first lock first\n", ret?"does":"doesn't");
1764 cli_close(cli1, fnum1);
1765 cli_close(cli2, fnum2);
1766 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1767 f = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1768 ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1769 cli_lock(cli1, f, 0, 1, 0, READ_LOCK) &&
1770 cli_close(cli1, fnum1) &&
1771 ((fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE)) != -1) &&
1772 cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1774 cli_close(cli1, fnum1);
1775 EXPECTED(ret, True);
1776 printf("the server %s have the NT byte range lock bug\n", !ret?"does":"doesn't");
1779 cli_close(cli1, fnum1);
1780 cli_close(cli2, fnum2);
1781 cli_unlink(cli1, fname);
1782 torture_close_connection(cli1);
1783 torture_close_connection(cli2);
1785 printf("finished locktest4\n");
1790 looks at lock upgrade/downgrade.
1792 static bool run_locktest5(int dummy)
1794 static struct cli_state *cli1, *cli2;
1795 const char *fname = "\\lockt5.lck";
1796 int fnum1, fnum2, fnum3;
1799 bool correct = True;
1801 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1805 cli_sockopt(cli1, sockops);
1806 cli_sockopt(cli2, sockops);
1808 printf("starting locktest5\n");
1810 cli_unlink(cli1, fname);
1812 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1813 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1814 fnum3 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1816 memset(buf, 0, sizeof(buf));
1818 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1819 printf("Failed to create file\n");
1824 /* Check for NT bug... */
1825 ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1826 cli_lock(cli1, fnum3, 0, 1, 0, READ_LOCK);
1827 cli_close(cli1, fnum1);
1828 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1829 ret = cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1830 EXPECTED(ret, True);
1831 printf("this server %s the NT locking bug\n", ret ? "doesn't have" : "has");
1832 cli_close(cli1, fnum1);
1833 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1834 cli_unlock(cli1, fnum3, 0, 1);
1836 ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1837 cli_lock(cli1, fnum1, 1, 1, 0, READ_LOCK);
1838 EXPECTED(ret, True);
1839 printf("the same process %s overlay a write with a read lock\n", ret?"can":"cannot");
1841 ret = cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK);
1842 EXPECTED(ret, False);
1844 printf("a different processs %s get a read lock on the first process lock stack\n", ret?"can":"cannot");
1846 /* Unlock the process 2 lock. */
1847 cli_unlock(cli2, fnum2, 0, 4);
1849 ret = cli_lock(cli1, fnum3, 0, 4, 0, READ_LOCK);
1850 EXPECTED(ret, False);
1852 printf("the same processs on a different fnum %s get a read lock\n", ret?"can":"cannot");
1854 /* Unlock the process 1 fnum3 lock. */
1855 cli_unlock(cli1, fnum3, 0, 4);
1857 /* Stack 2 more locks here. */
1858 ret = cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK) &&
1859 cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK);
1861 EXPECTED(ret, True);
1862 printf("the same process %s stack read locks\n", ret?"can":"cannot");
1864 /* Unlock the first process lock, then check this was the WRITE lock that was
1867 ret = cli_unlock(cli1, fnum1, 0, 4) &&
1868 cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK);
1870 EXPECTED(ret, True);
1871 printf("the first unlock removes the %s lock\n", ret?"WRITE":"READ");
1873 /* Unlock the process 2 lock. */
1874 cli_unlock(cli2, fnum2, 0, 4);
1876 /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */
1878 ret = cli_unlock(cli1, fnum1, 1, 1) &&
1879 cli_unlock(cli1, fnum1, 0, 4) &&
1880 cli_unlock(cli1, fnum1, 0, 4);
1882 EXPECTED(ret, True);
1883 printf("the same process %s unlock the stack of 4 locks\n", ret?"can":"cannot");
1885 /* Ensure the next unlock fails. */
1886 ret = cli_unlock(cli1, fnum1, 0, 4);
1887 EXPECTED(ret, False);
1888 printf("the same process %s count the lock stack\n", !ret?"can":"cannot");
1890 /* Ensure connection 2 can get a write lock. */
1891 ret = cli_lock(cli2, fnum2, 0, 4, 0, WRITE_LOCK);
1892 EXPECTED(ret, True);
1894 printf("a different processs %s get a write lock on the unlocked stack\n", ret?"can":"cannot");
1898 cli_close(cli1, fnum1);
1899 cli_close(cli2, fnum2);
1900 cli_unlink(cli1, fname);
1901 if (!torture_close_connection(cli1)) {
1904 if (!torture_close_connection(cli2)) {
1908 printf("finished locktest5\n");
1914 tries the unusual lockingX locktype bits
1916 static bool run_locktest6(int dummy)
1918 static struct cli_state *cli;
1919 const char *fname[1] = { "\\lock6.txt" };
1924 if (!torture_open_connection(&cli, 0)) {
1928 cli_sockopt(cli, sockops);
1930 printf("starting locktest6\n");
1933 printf("Testing %s\n", fname[i]);
1935 cli_unlink(cli, fname[i]);
1937 fnum = cli_open(cli, fname[i], O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1938 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE);
1939 cli_close(cli, fnum);
1940 printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status));
1942 fnum = cli_open(cli, fname[i], O_RDWR, DENY_NONE);
1943 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK);
1944 cli_close(cli, fnum);
1945 printf("CANCEL_LOCK gave %s\n", nt_errstr(status));
1947 cli_unlink(cli, fname[i]);
1950 torture_close_connection(cli);
1952 printf("finished locktest6\n");
1956 static bool run_locktest7(int dummy)
1958 struct cli_state *cli1;
1959 const char *fname = "\\lockt7.lck";
1962 bool correct = False;
1964 if (!torture_open_connection(&cli1, 0)) {
1968 cli_sockopt(cli1, sockops);
1970 printf("starting locktest7\n");
1972 cli_unlink(cli1, fname);
1974 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1976 memset(buf, 0, sizeof(buf));
1978 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1979 printf("Failed to create file\n");
1983 cli_setpid(cli1, 1);
1985 if (!cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK)) {
1986 printf("Unable to apply read lock on range 130:4, error was %s\n", cli_errstr(cli1));
1989 printf("pid1 successfully locked range 130:4 for READ\n");
1992 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1993 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1996 printf("pid1 successfully read the range 130:4\n");
1999 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
2000 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
2001 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
2002 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2006 printf("pid1 successfully wrote to the range 130:4 (should be denied)\n");
2010 cli_setpid(cli1, 2);
2012 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
2013 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
2015 printf("pid2 successfully read the range 130:4\n");
2018 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
2019 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
2020 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
2021 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2025 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
2029 cli_setpid(cli1, 1);
2030 cli_unlock(cli1, fnum1, 130, 4);
2032 if (!cli_lock(cli1, fnum1, 130, 4, 0, WRITE_LOCK)) {
2033 printf("Unable to apply write lock on range 130:4, error was %s\n", cli_errstr(cli1));
2036 printf("pid1 successfully locked range 130:4 for WRITE\n");
2039 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
2040 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
2043 printf("pid1 successfully read the range 130:4\n");
2046 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
2047 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
2050 printf("pid1 successfully wrote to the range 130:4\n");
2053 cli_setpid(cli1, 2);
2055 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
2056 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
2057 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
2058 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2062 printf("pid2 successfully read the range 130:4 (should be denied)\n");
2066 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
2067 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
2068 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
2069 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2073 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
2077 cli_unlock(cli1, fnum1, 130, 0);
2081 cli_close(cli1, fnum1);
2082 cli_unlink(cli1, fname);
2083 torture_close_connection(cli1);
2085 printf("finished locktest7\n");
2090 test whether fnums and tids open on one VC are available on another (a major
2093 static bool run_fdpasstest(int dummy)
2095 struct cli_state *cli1, *cli2;
2096 const char *fname = "\\fdpass.tst";
2100 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
2103 cli_sockopt(cli1, sockops);
2104 cli_sockopt(cli2, sockops);
2106 printf("starting fdpasstest\n");
2108 cli_unlink(cli1, fname);
2110 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2112 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2116 if (cli_write(cli1, fnum1, 0, "hello world\n", 0, 13) != 13) {
2117 printf("write failed (%s)\n", cli_errstr(cli1));
2121 cli2->vuid = cli1->vuid;
2122 cli2->cnum = cli1->cnum;
2123 cli2->pid = cli1->pid;
2125 if (cli_read(cli2, fnum1, buf, 0, 13) == 13) {
2126 printf("read succeeded! nasty security hole [%s]\n",
2131 cli_close(cli1, fnum1);
2132 cli_unlink(cli1, fname);
2134 torture_close_connection(cli1);
2135 torture_close_connection(cli2);
2137 printf("finished fdpasstest\n");
2141 static bool run_fdsesstest(int dummy)
2143 struct cli_state *cli;
2148 const char *fname = "\\fdsess.tst";
2149 const char *fname1 = "\\fdsess1.tst";
2155 if (!torture_open_connection(&cli, 0))
2157 cli_sockopt(cli, sockops);
2159 if (!torture_cli_session_setup2(cli, &new_vuid))
2162 saved_cnum = cli->cnum;
2163 if (!NT_STATUS_IS_OK(cli_tcon_andx(cli, share, "?????", "", 1)))
2165 new_cnum = cli->cnum;
2166 cli->cnum = saved_cnum;
2168 printf("starting fdsesstest\n");
2170 cli_unlink(cli, fname);
2171 cli_unlink(cli, fname1);
2173 fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2175 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
2179 if (cli_write(cli, fnum1, 0, "hello world\n", 0, 13) != 13) {
2180 printf("write failed (%s)\n", cli_errstr(cli));
2184 saved_vuid = cli->vuid;
2185 cli->vuid = new_vuid;
2187 if (cli_read(cli, fnum1, buf, 0, 13) == 13) {
2188 printf("read succeeded with different vuid! nasty security hole [%s]\n",
2192 /* Try to open a file with different vuid, samba cnum. */
2193 fnum2 = cli_open(cli, fname1, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2195 printf("create with different vuid, same cnum succeeded.\n");
2196 cli_close(cli, fnum2);
2197 cli_unlink(cli, fname1);
2199 printf("create with different vuid, same cnum failed.\n");
2200 printf("This will cause problems with service clients.\n");
2204 cli->vuid = saved_vuid;
2206 /* Try with same vuid, different cnum. */
2207 cli->cnum = new_cnum;
2209 if (cli_read(cli, fnum1, buf, 0, 13) == 13) {
2210 printf("read succeeded with different cnum![%s]\n",
2215 cli->cnum = saved_cnum;
2216 cli_close(cli, fnum1);
2217 cli_unlink(cli, fname);
2219 torture_close_connection(cli);
2221 printf("finished fdsesstest\n");
2226 This test checks that
2228 1) the server does not allow an unlink on a file that is open
2230 static bool run_unlinktest(int dummy)
2232 struct cli_state *cli;
2233 const char *fname = "\\unlink.tst";
2235 bool correct = True;
2237 if (!torture_open_connection(&cli, 0)) {
2241 cli_sockopt(cli, sockops);
2243 printf("starting unlink test\n");
2245 cli_unlink(cli, fname);
2249 fnum = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2251 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
2255 if (cli_unlink(cli, fname)) {
2256 printf("error: server allowed unlink on an open file\n");
2259 correct = check_error(__LINE__, cli, ERRDOS, ERRbadshare,
2260 NT_STATUS_SHARING_VIOLATION);
2263 cli_close(cli, fnum);
2264 cli_unlink(cli, fname);
2266 if (!torture_close_connection(cli)) {
2270 printf("unlink test finished\n");
2277 test how many open files this server supports on the one socket
2279 static bool run_maxfidtest(int dummy)
2281 struct cli_state *cli;
2282 const char *ftemplate = "\\maxfid.%d.%d";
2284 int fnums[0x11000], i;
2286 bool correct = True;
2291 printf("failed to connect\n");
2295 cli_sockopt(cli, sockops);
2297 for (i=0; i<0x11000; i++) {
2298 slprintf(fname,sizeof(fname)-1,ftemplate, i,(int)getpid());
2299 if ((fnums[i] = cli_open(cli, fname,
2300 O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) ==
2302 printf("open of %s failed (%s)\n",
2303 fname, cli_errstr(cli));
2304 printf("maximum fnum is %d\n", i);
2312 printf("cleaning up\n");
2314 slprintf(fname,sizeof(fname)-1,ftemplate, i,(int)getpid());
2315 cli_close(cli, fnums[i]);
2316 if (!cli_unlink(cli, fname)) {
2317 printf("unlink of %s failed (%s)\n",
2318 fname, cli_errstr(cli));
2325 printf("maxfid test finished\n");
2326 if (!torture_close_connection(cli)) {
2332 /* generate a random buffer */
2333 static void rand_buf(char *buf, int len)
2336 *buf = (char)sys_random();
2341 /* send smb negprot commands, not reading the response */
2342 static bool run_negprot_nowait(int dummy)
2345 static struct cli_state *cli;
2346 bool correct = True;
2348 printf("starting negprot nowait test\n");
2350 if (!(cli = open_nbt_connection())) {
2354 for (i=0;i<50000;i++) {
2355 cli_negprot_sendsync(cli);
2358 if (!torture_close_connection(cli)) {
2362 printf("finished negprot nowait test\n");
2368 /* send random IPC commands */
2369 static bool run_randomipc(int dummy)
2371 char *rparam = NULL;
2373 unsigned int rdrcnt,rprcnt;
2375 int api, param_len, i;
2376 struct cli_state *cli;
2377 bool correct = True;
2380 printf("starting random ipc test\n");
2382 if (!torture_open_connection(&cli, 0)) {
2386 for (i=0;i<count;i++) {
2387 api = sys_random() % 500;
2388 param_len = (sys_random() % 64);
2390 rand_buf(param, param_len);
2395 param, param_len, 8,
2396 NULL, 0, BUFFER_SIZE,
2400 printf("%d/%d\r", i,count);
2403 printf("%d/%d\n", i, count);
2405 if (!torture_close_connection(cli)) {
2409 printf("finished random ipc test\n");
2416 static void browse_callback(const char *sname, uint32 stype,
2417 const char *comment, void *state)
2419 printf("\t%20.20s %08x %s\n", sname, stype, comment);
2425 This test checks the browse list code
2428 static bool run_browsetest(int dummy)
2430 static struct cli_state *cli;
2431 bool correct = True;
2433 printf("starting browse test\n");
2435 if (!torture_open_connection(&cli, 0)) {
2439 printf("domain list:\n");
2440 cli_NetServerEnum(cli, cli->server_domain,
2441 SV_TYPE_DOMAIN_ENUM,
2442 browse_callback, NULL);
2444 printf("machine list:\n");
2445 cli_NetServerEnum(cli, cli->server_domain,
2447 browse_callback, NULL);
2449 if (!torture_close_connection(cli)) {
2453 printf("browse test finished\n");
2461 This checks how the getatr calls works
2463 static bool run_attrtest(int dummy)
2465 struct cli_state *cli;
2468 const char *fname = "\\attrib123456789.tst";
2469 bool correct = True;
2471 printf("starting attrib test\n");
2473 if (!torture_open_connection(&cli, 0)) {
2477 cli_unlink(cli, fname);
2478 fnum = cli_open(cli, fname,
2479 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2480 cli_close(cli, fnum);
2481 if (!cli_getatr(cli, fname, NULL, NULL, &t)) {
2482 printf("getatr failed (%s)\n", cli_errstr(cli));
2486 if (abs(t - time(NULL)) > 60*60*24*10) {
2487 printf("ERROR: SMBgetatr bug. time is %s",
2493 t2 = t-60*60*24; /* 1 day ago */
2495 if (!cli_setatr(cli, fname, 0, t2)) {
2496 printf("setatr failed (%s)\n", cli_errstr(cli));
2500 if (!cli_getatr(cli, fname, NULL, NULL, &t)) {
2501 printf("getatr failed (%s)\n", cli_errstr(cli));
2506 printf("ERROR: getatr/setatr bug. times are\n%s",
2508 printf("%s", ctime(&t2));
2512 cli_unlink(cli, fname);
2514 if (!torture_close_connection(cli)) {
2518 printf("attrib test finished\n");
2525 This checks a couple of trans2 calls
2527 static bool run_trans2test(int dummy)
2529 struct cli_state *cli;
2532 time_t c_time, a_time, m_time;
2533 struct timespec c_time_ts, a_time_ts, m_time_ts, w_time_ts, m_time2_ts;
2534 const char *fname = "\\trans2.tst";
2535 const char *dname = "\\trans2";
2536 const char *fname2 = "\\trans2\\trans2.tst";
2538 bool correct = True;
2540 printf("starting trans2 test\n");
2542 if (!torture_open_connection(&cli, 0)) {
2546 cli_unlink(cli, fname);
2547 fnum = cli_open(cli, fname,
2548 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2549 if (!cli_qfileinfo(cli, fnum, NULL, &size, &c_time_ts, &a_time_ts, &w_time_ts,
2550 &m_time_ts, NULL)) {
2551 printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(cli));
2555 if (!cli_qfilename(cli, fnum, pname, sizeof(pname))) {
2556 printf("ERROR: qfilename failed (%s)\n", cli_errstr(cli));
2560 if (strcmp(pname, fname)) {
2561 printf("qfilename gave different name? [%s] [%s]\n",
2566 cli_close(cli, fnum);
2570 cli_unlink(cli, fname);
2571 fnum = cli_open(cli, fname,
2572 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2574 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
2577 cli_close(cli, fnum);
2579 if (!cli_qpathinfo(cli, fname, &c_time, &a_time, &m_time, &size, NULL)) {
2580 printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(cli));
2583 if (c_time != m_time) {
2584 printf("create time=%s", ctime(&c_time));
2585 printf("modify time=%s", ctime(&m_time));
2586 printf("This system appears to have sticky create times\n");
2588 if (a_time % (60*60) == 0) {
2589 printf("access time=%s", ctime(&a_time));
2590 printf("This system appears to set a midnight access time\n");
2594 if (abs(m_time - time(NULL)) > 60*60*24*7) {
2595 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
2601 cli_unlink(cli, fname);
2602 fnum = cli_open(cli, fname,
2603 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2604 cli_close(cli, fnum);
2605 if (!cli_qpathinfo2(cli, fname, &c_time_ts, &a_time_ts, &w_time_ts,
2606 &m_time_ts, &size, NULL, NULL)) {
2607 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2610 if (w_time_ts.tv_sec < 60*60*24*2) {
2611 printf("write time=%s", ctime(&w_time_ts.tv_sec));
2612 printf("This system appears to set a initial 0 write time\n");
2617 cli_unlink(cli, fname);
2620 /* check if the server updates the directory modification time
2621 when creating a new file */
2622 if (!cli_mkdir(cli, dname)) {
2623 printf("ERROR: mkdir failed (%s)\n", cli_errstr(cli));
2627 if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts, &w_time_ts,
2628 &m_time_ts, &size, NULL, NULL)) {
2629 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2633 fnum = cli_open(cli, fname2,
2634 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2635 cli_write(cli, fnum, 0, (char *)&fnum, 0, sizeof(fnum));
2636 cli_close(cli, fnum);
2637 if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts, &w_time_ts,
2638 &m_time2_ts, &size, NULL, NULL)) {
2639 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2642 if (memcmp(&m_time_ts, &m_time2_ts, sizeof(struct timespec))
2644 printf("This system does not update directory modification times\n");
2648 cli_unlink(cli, fname2);
2649 cli_rmdir(cli, dname);
2651 if (!torture_close_connection(cli)) {
2655 printf("trans2 test finished\n");
2661 This checks new W2K calls.
2664 static bool new_trans(struct cli_state *pcli, int fnum, int level)
2668 bool correct = True;
2670 if (!cli_qfileinfo_test(pcli, fnum, level, &buf, &len)) {
2671 printf("ERROR: qfileinfo (%d) failed (%s)\n", level, cli_errstr(pcli));
2674 printf("qfileinfo: level %d, len = %u\n", level, len);
2675 dump_data(0, (uint8 *)buf, len);
2682 static bool run_w2ktest(int dummy)
2684 struct cli_state *cli;
2686 const char *fname = "\\w2ktest\\w2k.tst";
2688 bool correct = True;
2690 printf("starting w2k test\n");
2692 if (!torture_open_connection(&cli, 0)) {
2696 fnum = cli_open(cli, fname,
2697 O_RDWR | O_CREAT , DENY_NONE);
2699 for (level = 1004; level < 1040; level++) {
2700 new_trans(cli, fnum, level);
2703 cli_close(cli, fnum);
2705 if (!torture_close_connection(cli)) {
2709 printf("w2k test finished\n");
2716 this is a harness for some oplock tests
2718 static bool run_oplock1(int dummy)
2720 struct cli_state *cli1;
2721 const char *fname = "\\lockt1.lck";
2723 bool correct = True;
2725 printf("starting oplock test 1\n");
2727 if (!torture_open_connection(&cli1, 0)) {
2731 cli_unlink(cli1, fname);
2733 cli_sockopt(cli1, sockops);
2735 cli1->use_oplocks = True;
2737 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2739 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2743 cli1->use_oplocks = False;
2745 cli_unlink(cli1, fname);
2746 cli_unlink(cli1, fname);
2748 if (!cli_close(cli1, fnum1)) {
2749 printf("close2 failed (%s)\n", cli_errstr(cli1));
2753 if (!cli_unlink(cli1, fname)) {
2754 printf("unlink failed (%s)\n", cli_errstr(cli1));
2758 if (!torture_close_connection(cli1)) {
2762 printf("finished oplock test 1\n");
2767 static bool run_oplock2(int dummy)
2769 struct cli_state *cli1, *cli2;
2770 const char *fname = "\\lockt2.lck";
2772 int saved_use_oplocks = use_oplocks;
2774 bool correct = True;
2775 volatile bool *shared_correct;
2777 shared_correct = (volatile bool *)shm_setup(sizeof(bool));
2778 *shared_correct = True;
2780 use_level_II_oplocks = True;
2783 printf("starting oplock test 2\n");
2785 if (!torture_open_connection(&cli1, 0)) {
2786 use_level_II_oplocks = False;
2787 use_oplocks = saved_use_oplocks;
2791 cli1->use_oplocks = True;
2792 cli1->use_level_II_oplocks = True;
2794 if (!torture_open_connection(&cli2, 1)) {
2795 use_level_II_oplocks = False;
2796 use_oplocks = saved_use_oplocks;
2800 cli2->use_oplocks = True;
2801 cli2->use_level_II_oplocks = True;
2803 cli_unlink(cli1, fname);
2805 cli_sockopt(cli1, sockops);
2806 cli_sockopt(cli2, sockops);
2808 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2810 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2814 /* Don't need the globals any more. */
2815 use_level_II_oplocks = False;
2816 use_oplocks = saved_use_oplocks;
2820 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
2822 printf("second open of %s failed (%s)\n", fname, cli_errstr(cli1));
2823 *shared_correct = False;
2829 if (!cli_close(cli2, fnum2)) {
2830 printf("close2 failed (%s)\n", cli_errstr(cli1));
2831 *shared_correct = False;
2839 /* Ensure cli1 processes the break. Empty file should always return 0
2842 if (cli_read(cli1, fnum1, buf, 0, 4) != 0) {
2843 printf("read on fnum1 failed (%s)\n", cli_errstr(cli1));
2847 /* Should now be at level II. */
2848 /* Test if sending a write locks causes a break to none. */
2850 if (!cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK)) {
2851 printf("lock failed (%s)\n", cli_errstr(cli1));
2855 cli_unlock(cli1, fnum1, 0, 4);
2859 if (!cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
2860 printf("lock failed (%s)\n", cli_errstr(cli1));
2864 cli_unlock(cli1, fnum1, 0, 4);
2868 cli_read(cli1, fnum1, buf, 0, 4);
2871 if (cli_write(cli1, fnum1, 0, buf, 0, 4) != 4) {
2872 printf("write on fnum1 failed (%s)\n", cli_errstr(cli1));
2877 if (!cli_close(cli1, fnum1)) {
2878 printf("close1 failed (%s)\n", cli_errstr(cli1));
2884 if (!cli_unlink(cli1, fname)) {
2885 printf("unlink failed (%s)\n", cli_errstr(cli1));
2889 if (!torture_close_connection(cli1)) {
2893 if (!*shared_correct) {
2897 printf("finished oplock test 2\n");
2902 /* handler for oplock 3 tests */
2903 static bool oplock3_handler(struct cli_state *cli, int fnum, unsigned char level)
2905 printf("got oplock break fnum=%d level=%d\n",
2907 return cli_oplock_ack(cli, fnum, level);
2910 static bool run_oplock3(int dummy)
2912 struct cli_state *cli;
2913 const char *fname = "\\oplockt3.dat";
2915 char buf[4] = "abcd";
2916 bool correct = True;
2917 volatile bool *shared_correct;
2919 shared_correct = (volatile bool *)shm_setup(sizeof(bool));
2920 *shared_correct = True;
2922 printf("starting oplock test 3\n");
2927 use_level_II_oplocks = True;
2928 if (!torture_open_connection(&cli, 0)) {
2929 *shared_correct = False;
2933 /* try to trigger a oplock break in parent */
2934 fnum = cli_open(cli, fname, O_RDWR, DENY_NONE);
2935 cli_write(cli, fnum, 0, buf, 0, 4);
2941 use_level_II_oplocks = True;
2942 if (!torture_open_connection(&cli, 1)) { /* other is forked */
2945 cli_oplock_handler(cli, oplock3_handler);
2946 fnum = cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE);
2947 cli_write(cli, fnum, 0, buf, 0, 4);
2948 cli_close(cli, fnum);
2949 fnum = cli_open(cli, fname, O_RDWR, DENY_NONE);
2950 cli->timeout = 20000;
2951 cli_receive_smb(cli);
2952 printf("finished oplock test 3\n");
2954 return (correct && *shared_correct);
2956 /* What are we looking for here? What's sucess and what's FAILURE? */
2962 Test delete on close semantics.
2964 static bool run_deletetest(int dummy)
2966 struct cli_state *cli1 = NULL;
2967 struct cli_state *cli2 = NULL;
2968 const char *fname = "\\delete.file";
2971 bool correct = True;
2973 printf("starting delete test\n");
2975 if (!torture_open_connection(&cli1, 0)) {
2979 cli_sockopt(cli1, sockops);
2981 /* Test 1 - this should delete the file on close. */
2983 cli_setatr(cli1, fname, 0, 0);
2984 cli_unlink(cli1, fname);
2986 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
2987 0, FILE_OVERWRITE_IF,
2988 FILE_DELETE_ON_CLOSE, 0);
2991 printf("[1] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2998 uint32 *accinfo = NULL;
3000 cli_qfileinfo_test(cli1, fnum1, SMB_FILE_ACCESS_INFORMATION, (char **)&accinfo, &len);
3002 printf("access mode = 0x%lx\n", *accinfo);
3007 if (!cli_close(cli1, fnum1)) {
3008 printf("[1] close failed (%s)\n", cli_errstr(cli1));
3013 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
3015 printf("[1] open of %s succeeded (should fail)\n", fname);
3020 printf("first delete on close test succeeded.\n");
3022 /* Test 2 - this should delete the file on close. */
3024 cli_setatr(cli1, fname, 0, 0);
3025 cli_unlink(cli1, fname);
3027 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_ALL_ACCESS,
3028 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
3029 FILE_OVERWRITE_IF, 0, 0);
3032 printf("[2] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3037 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
3038 printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
3043 if (!cli_close(cli1, fnum1)) {
3044 printf("[2] close failed (%s)\n", cli_errstr(cli1));
3049 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
3051 printf("[2] open of %s succeeded should have been deleted on close !\n", fname);
3052 if (!cli_close(cli1, fnum1)) {
3053 printf("[2] close failed (%s)\n", cli_errstr(cli1));
3057 cli_unlink(cli1, fname);
3059 printf("second delete on close test succeeded.\n");
3062 cli_setatr(cli1, fname, 0, 0);
3063 cli_unlink(cli1, fname);
3065 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
3066 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0);
3069 printf("[3] open - 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3074 /* This should fail with a sharing violation - open for delete is only compatible
3075 with SHARE_DELETE. */
3077 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3078 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0, 0);
3081 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname);
3086 /* This should succeed. */
3088 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3089 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0, 0);
3092 printf("[3] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
3097 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
3098 printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
3103 if (!cli_close(cli1, fnum1)) {
3104 printf("[3] close 1 failed (%s)\n", cli_errstr(cli1));
3109 if (!cli_close(cli1, fnum2)) {
3110 printf("[3] close 2 failed (%s)\n", cli_errstr(cli1));
3115 /* This should fail - file should no longer be there. */
3117 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
3119 printf("[3] open of %s succeeded should have been deleted on close !\n", fname);
3120 if (!cli_close(cli1, fnum1)) {
3121 printf("[3] close failed (%s)\n", cli_errstr(cli1));
3123 cli_unlink(cli1, fname);
3127 printf("third delete on close test succeeded.\n");
3130 cli_setatr(cli1, fname, 0, 0);
3131 cli_unlink(cli1, fname);
3133 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3134 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0);
3137 printf("[4] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3142 /* This should succeed. */
3143 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS,
3144 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0, 0);
3146 printf("[4] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
3151 if (!cli_close(cli1, fnum2)) {
3152 printf("[4] close - 1 failed (%s)\n", cli_errstr(cli1));
3157 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
3158 printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
3163 /* This should fail - no more opens once delete on close set. */
3164 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS,
3165 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3168 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname );
3172 printf("fourth delete on close test succeeded.\n");
3174 if (!cli_close(cli1, fnum1)) {
3175 printf("[4] close - 2 failed (%s)\n", cli_errstr(cli1));
3181 cli_setatr(cli1, fname, 0, 0);
3182 cli_unlink(cli1, fname);
3184 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT, DENY_NONE);
3186 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3191 /* This should fail - only allowed on NT opens with DELETE access. */
3193 if (cli_nt_delete_on_close(cli1, fnum1, True)) {
3194 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
3199 if (!cli_close(cli1, fnum1)) {
3200 printf("[5] close - 2 failed (%s)\n", cli_errstr(cli1));
3205 printf("fifth delete on close test succeeded.\n");
3208 cli_setatr(cli1, fname, 0, 0);
3209 cli_unlink(cli1, fname);
3211 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
3212 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3213 FILE_OVERWRITE_IF, 0, 0);
3216 printf("[6] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3221 /* This should fail - only allowed on NT opens with DELETE access. */
3223 if (cli_nt_delete_on_close(cli1, fnum1, True)) {
3224 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
3229 if (!cli_close(cli1, fnum1)) {
3230 printf("[6] close - 2 failed (%s)\n", cli_errstr(cli1));
3235 printf("sixth delete on close test succeeded.\n");
3238 cli_setatr(cli1, fname, 0, 0);
3239 cli_unlink(cli1, fname);
3241 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3242 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0, 0);
3245 printf("[7] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3250 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
3251 printf("[7] setting delete_on_close on file failed !\n");
3256 if (!cli_nt_delete_on_close(cli1, fnum1, False)) {
3257 printf("[7] unsetting delete_on_close on file failed !\n");
3262 if (!cli_close(cli1, fnum1)) {
3263 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
3268 /* This next open should succeed - we reset the flag. */
3270 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
3272 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3277 if (!cli_close(cli1, fnum1)) {
3278 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
3283 printf("seventh delete on close test succeeded.\n");
3286 cli_setatr(cli1, fname, 0, 0);
3287 cli_unlink(cli1, fname);
3289 if (!torture_open_connection(&cli2, 1)) {
3290 printf("[8] failed to open second connection.\n");
3295 cli_sockopt(cli1, sockops);
3297 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3298 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3299 FILE_OVERWRITE_IF, 0, 0);
3302 printf("[8] open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3307 fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3308 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3312 printf("[8] open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3317 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
3318 printf("[8] setting delete_on_close on file failed !\n");
3323 if (!cli_close(cli1, fnum1)) {
3324 printf("[8] close - 1 failed (%s)\n", cli_errstr(cli1));
3329 if (!cli_close(cli2, fnum2)) {
3330 printf("[8] close - 2 failed (%s)\n", cli_errstr(cli2));
3335 /* This should fail.. */
3336 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
3338 printf("[8] open of %s succeeded should have been deleted on close !\n", fname);
3342 printf("eighth delete on close test succeeded.\n");
3344 /* This should fail - we need to set DELETE_ACCESS. */
3345 fnum1 = cli_nt_create_full(cli1, fname, 0,FILE_READ_DATA|FILE_WRITE_DATA,
3346 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, 0);
3349 printf("[9] open of %s succeeded should have failed!\n", fname);
3354 printf("ninth delete on close test succeeded.\n");
3356 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3357 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, 0);
3359 printf("[10] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3364 /* This should delete the file. */
3365 if (!cli_close(cli1, fnum1)) {
3366 printf("[10] close failed (%s)\n", cli_errstr(cli1));
3371 /* This should fail.. */
3372 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
3374 printf("[10] open of %s succeeded should have been deleted on close !\n", fname);
3378 printf("tenth delete on close test succeeded.\n");
3380 cli_setatr(cli1, fname, 0, 0);
3381 cli_unlink(cli1, fname);
3383 /* What error do we get when attempting to open a read-only file with
3386 /* Create a readonly file. */
3387 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
3388 FILE_ATTRIBUTE_READONLY, FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3390 printf("[11] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3395 if (!cli_close(cli1, fnum1)) {
3396 printf("[11] close failed (%s)\n", cli_errstr(cli1));
3401 /* Now try open for delete access. */
3402 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_ATTRIBUTES|DELETE_ACCESS,
3403 0, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3404 FILE_OVERWRITE_IF, 0, 0);
3407 printf("[11] open of %s succeeded should have been denied with ACCESS_DENIED!\n", fname);
3408 cli_close(cli1, fnum1);
3412 NTSTATUS nterr = cli_nt_error(cli1);
3413 if (!NT_STATUS_EQUAL(nterr,NT_STATUS_ACCESS_DENIED)) {
3414 printf("[11] open of %s should have been denied with ACCESS_DENIED! Got error %s\n", fname, nt_errstr(nterr));
3418 printf("eleventh delete on close test succeeded.\n");
3422 printf("finished delete test\n");
3425 /* FIXME: This will crash if we aborted before cli2 got
3426 * intialized, because these functions don't handle
3427 * uninitialized connections. */
3429 if (fnum1 != -1) cli_close(cli1, fnum1);
3430 if (fnum2 != -1) cli_close(cli1, fnum2);
3431 cli_setatr(cli1, fname, 0, 0);
3432 cli_unlink(cli1, fname);
3434 if (cli1 && !torture_close_connection(cli1)) {
3437 if (cli2 && !torture_close_connection(cli2)) {
3445 print out server properties
3447 static bool run_properties(int dummy)
3449 static struct cli_state *cli;
3450 bool correct = True;
3452 printf("starting properties test\n");
3456 if (!torture_open_connection(&cli, 0)) {
3460 cli_sockopt(cli, sockops);
3462 d_printf("Capabilities 0x%08x\n", cli->capabilities);
3464 if (!torture_close_connection(cli)) {
3473 /* FIRST_DESIRED_ACCESS 0xf019f */
3474 #define FIRST_DESIRED_ACCESS FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|\
3475 FILE_READ_EA| /* 0xf */ \
3476 FILE_WRITE_EA|FILE_READ_ATTRIBUTES| /* 0x90 */ \
3477 FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
3478 DELETE_ACCESS|READ_CONTROL_ACCESS|\
3479 WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS /* 0xf0000 */
3480 /* SECOND_DESIRED_ACCESS 0xe0080 */
3481 #define SECOND_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
3482 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
3483 WRITE_OWNER_ACCESS /* 0xe0000 */
3486 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
3487 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
3489 WRITE_OWNER_ACCESS /* */
3493 Test ntcreate calls made by xcopy
3495 static bool run_xcopy(int dummy)
3497 static struct cli_state *cli1;
3498 const char *fname = "\\test.txt";
3499 bool correct = True;
3502 printf("starting xcopy test\n");
3504 if (!torture_open_connection(&cli1, 0)) {
3508 fnum1 = cli_nt_create_full(cli1, fname, 0,
3509 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
3510 FILE_SHARE_NONE, FILE_OVERWRITE_IF,
3514 printf("First open failed - %s\n", cli_errstr(cli1));
3518 fnum2 = cli_nt_create_full(cli1, fname, 0,
3519 SECOND_DESIRED_ACCESS, 0,
3520 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN,
3523 printf("second open failed - %s\n", cli_errstr(cli1));
3527 if (!torture_close_connection(cli1)) {
3535 Test rename on files open with share delete and no share delete.
3537 static bool run_rename(int dummy)
3539 static struct cli_state *cli1;
3540 const char *fname = "\\test.txt";
3541 const char *fname1 = "\\test1.txt";
3542 bool correct = True;
3545 printf("starting rename test\n");
3547 if (!torture_open_connection(&cli1, 0)) {
3551 cli_unlink(cli1, fname);
3552 cli_unlink(cli1, fname1);
3553 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3554 FILE_SHARE_READ, FILE_OVERWRITE_IF, 0, 0);
3557 printf("First open failed - %s\n", cli_errstr(cli1));
3561 if (!cli_rename(cli1, fname, fname1)) {
3562 printf("First rename failed (SHARE_READ) (this is correct) - %s\n", cli_errstr(cli1));
3564 printf("First rename succeeded (SHARE_READ) - this should have failed !\n");
3568 if (!cli_close(cli1, fnum1)) {
3569 printf("close - 1 failed (%s)\n", cli_errstr(cli1));
3573 cli_unlink(cli1, fname);
3574 cli_unlink(cli1, fname1);
3575 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3577 FILE_SHARE_DELETE|FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3579 FILE_SHARE_DELETE|FILE_SHARE_READ, FILE_OVERWRITE_IF, 0, 0);
3583 printf("Second open failed - %s\n", cli_errstr(cli1));
3587 if (!cli_rename(cli1, fname, fname1)) {
3588 printf("Second rename failed (SHARE_DELETE | SHARE_READ) - this should have succeeded - %s\n", cli_errstr(cli1));
3591 printf("Second rename succeeded (SHARE_DELETE | SHARE_READ)\n");
3594 if (!cli_close(cli1, fnum1)) {
3595 printf("close - 2 failed (%s)\n", cli_errstr(cli1));
3599 cli_unlink(cli1, fname);
3600 cli_unlink(cli1, fname1);
3602 fnum1 = cli_nt_create_full(cli1, fname, 0, READ_CONTROL_ACCESS, FILE_ATTRIBUTE_NORMAL,
3603 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3606 printf("Third open failed - %s\n", cli_errstr(cli1));
3615 fnum2 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
3616 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3619 printf("Fourth open failed - %s\n", cli_errstr(cli1));
3622 if (!cli_nt_delete_on_close(cli1, fnum2, True)) {
3623 printf("[8] setting delete_on_close on file failed !\n");
3627 if (!cli_close(cli1, fnum2)) {
3628 printf("close - 4 failed (%s)\n", cli_errstr(cli1));
3634 if (!cli_rename(cli1, fname, fname1)) {
3635 printf("Third rename failed (SHARE_NONE) - this should have succeeded - %s\n", cli_errstr(cli1));
3638 printf("Third rename succeeded (SHARE_NONE)\n");
3641 if (!cli_close(cli1, fnum1)) {
3642 printf("close - 3 failed (%s)\n", cli_errstr(cli1));
3646 cli_unlink(cli1, fname);
3647 cli_unlink(cli1, fname1);
3651 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3652 FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0);
3655 printf("Fourth open failed - %s\n", cli_errstr(cli1));
3659 if (!cli_rename(cli1, fname, fname1)) {
3660 printf("Fourth rename failed (SHARE_READ | SHARE_WRITE) (this is correct) - %s\n", cli_errstr(cli1));
3662 printf("Fourth rename succeeded (SHARE_READ | SHARE_WRITE) - this should have failed !\n");
3666 if (!cli_close(cli1, fnum1)) {
3667 printf("close - 4 failed (%s)\n", cli_errstr(cli1));
3671 cli_unlink(cli1, fname);
3672 cli_unlink(cli1, fname1);
3676 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3677 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0);
3680 printf("Fifth open failed - %s\n", cli_errstr(cli1));
3684 if (!cli_rename(cli1, fname, fname1)) {
3685 printf("Fifth rename failed (SHARE_READ | SHARE_WRITE | SHARE_DELETE) - this should have succeeded - %s ! \n",
3689 printf("Fifth rename succeeded (SHARE_READ | SHARE_WRITE | SHARE_DELETE) (this is correct) - %s\n", cli_errstr(cli1));
3693 * Now check if the first name still exists ...
3696 /*fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3697 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0);
3700 printf("Opening original file after rename of open file fails: %s\n",
3704 printf("Opening original file after rename of open file works ...\n");
3705 (void)cli_close(cli1, fnum2);
3711 if (!cli_close(cli1, fnum1)) {
3712 printf("close - 5 failed (%s)\n", cli_errstr(cli1));
3716 cli_unlink(cli1, fname);
3717 cli_unlink(cli1, fname1);
3719 if (!torture_close_connection(cli1)) {
3726 static bool run_pipe_number(int dummy)
3728 struct cli_state *cli1;
3729 const char *pipe_name = "\\SPOOLSS";
3733 printf("starting pipenumber test\n");
3734 if (!torture_open_connection(&cli1, 0)) {
3738 cli_sockopt(cli1, sockops);
3740 fnum = cli_nt_create_full(cli1, pipe_name, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
3741 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN_IF, 0, 0);
3744 printf("Open of pipe %s failed with error (%s)\n", pipe_name, cli_errstr(cli1));
3748 printf("\r%6d", num_pipes);
3751 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes, pipe_name );
3752 torture_close_connection(cli1);
3757 Test open mode returns on read-only files.
3759 static bool run_opentest(int dummy)
3761 static struct cli_state *cli1;
3762 static struct cli_state *cli2;
3763 const char *fname = "\\readonly.file";
3767 bool correct = True;
3770 printf("starting open test\n");
3772 if (!torture_open_connection(&cli1, 0)) {
3776 cli_setatr(cli1, fname, 0, 0);
3777 cli_unlink(cli1, fname);
3779 cli_sockopt(cli1, sockops);
3781 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
3783 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
3787 if (!cli_close(cli1, fnum1)) {
3788 printf("close2 failed (%s)\n", cli_errstr(cli1));
3792 if (!cli_setatr(cli1, fname, aRONLY, 0)) {
3793 printf("cli_setatr failed (%s)\n", cli_errstr(cli1));
3797 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_WRITE);
3799 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
3803 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
3804 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_ALL);
3806 if (check_error(__LINE__, cli1, ERRDOS, ERRnoaccess,
3807 NT_STATUS_ACCESS_DENIED)) {
3808 printf("correct error code ERRDOS/ERRnoaccess returned\n");
3811 printf("finished open test 1\n");
3813 cli_close(cli1, fnum1);
3815 /* Now try not readonly and ensure ERRbadshare is returned. */
3817 cli_setatr(cli1, fname, 0, 0);
3819 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_WRITE);
3821 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
3825 /* This will fail - but the error should be ERRshare. */
3826 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_ALL);
3828 if (check_error(__LINE__, cli1, ERRDOS, ERRbadshare,
3829 NT_STATUS_SHARING_VIOLATION)) {
3830 printf("correct error code ERRDOS/ERRbadshare returned\n");
3833 if (!cli_close(cli1, fnum1)) {
3834 printf("close2 failed (%s)\n", cli_errstr(cli1));
3838 cli_unlink(cli1, fname);
3840 printf("finished open test 2\n");
3842 /* Test truncate open disposition on file opened for read. */
3844 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
3846 printf("(3) open (1) of %s failed (%s)\n", fname, cli_errstr(cli1));
3850 /* write 20 bytes. */
3852 memset(buf, '\0', 20);
3854 if (cli_write(cli1, fnum1, 0, buf, 0, 20) != 20) {
3855 printf("write failed (%s)\n", cli_errstr(cli1));
3859 if (!cli_close(cli1, fnum1)) {
3860 printf("(3) close1 failed (%s)\n", cli_errstr(cli1));
3864 /* Ensure size == 20. */
3865 if (!cli_getatr(cli1, fname, NULL, &fsize, NULL)) {
3866 printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
3871 printf("(3) file size != 20\n");
3875 /* Now test if we can truncate a file opened for readonly. */
3877 fnum1 = cli_open(cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE);
3879 printf("(3) open (2) of %s failed (%s)\n", fname, cli_errstr(cli1));
3883 if (!cli_close(cli1, fnum1)) {
3884 printf("close2 failed (%s)\n", cli_errstr(cli1));
3888 /* Ensure size == 0. */
3889 if (!cli_getatr(cli1, fname, NULL, &fsize, NULL)) {
3890 printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
3895 printf("(3) file size != 0\n");
3898 printf("finished open test 3\n");
3900 cli_unlink(cli1, fname);
3903 printf("testing ctemp\n");
3904 fnum1 = cli_ctemp(cli1, "\\", &tmp_path);
3906 printf("ctemp failed (%s)\n", cli_errstr(cli1));
3909 printf("ctemp gave path %s\n", tmp_path);
3910 if (!cli_close(cli1, fnum1)) {
3911 printf("close of temp failed (%s)\n", cli_errstr(cli1));
3913 if (!cli_unlink(cli1, tmp_path)) {
3914 printf("unlink of temp failed (%s)\n", cli_errstr(cli1));
3917 /* Test the non-io opens... */
3919 if (!torture_open_connection(&cli2, 1)) {
3923 cli_setatr(cli2, fname, 0, 0);
3924 cli_unlink(cli2, fname);
3926 cli_sockopt(cli2, sockops);
3928 printf("TEST #1 testing 2 non-io opens (no delete)\n");
3930 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3931 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3934 printf("test 1 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3938 fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3939 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
3942 printf("test 1 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3946 if (!cli_close(cli1, fnum1)) {
3947 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3950 if (!cli_close(cli2, fnum2)) {
3951 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3955 printf("non-io open test #1 passed.\n");
3957 cli_unlink(cli1, fname);
3959 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
3961 fnum1 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3962 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3965 printf("test 2 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3969 fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3970 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
3973 printf("test 2 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3977 if (!cli_close(cli1, fnum1)) {
3978 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3981 if (!cli_close(cli2, fnum2)) {
3982 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
3986 printf("non-io open test #2 passed.\n");
3988 cli_unlink(cli1, fname);
3990 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
3992 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3993 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3996 printf("test 3 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4000 fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4001 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
4004 printf("test 3 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4008 if (!cli_close(cli1, fnum1)) {
4009 printf("test 3 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4012 if (!cli_close(cli2, fnum2)) {
4013 printf("test 3 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4017 printf("non-io open test #3 passed.\n");
4019 cli_unlink(cli1, fname);
4021 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
4023 fnum1 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4024 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
4027 printf("test 4 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4031 fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4032 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
4035 printf("test 4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
4039 printf("test 3 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
4041 if (!cli_close(cli1, fnum1)) {
4042 printf("test 4 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4046 printf("non-io open test #4 passed.\n");
4048 cli_unlink(cli1, fname);
4050 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
4052 fnum1 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4053 FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0);
4056 printf("test 5 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4060 fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4061 FILE_SHARE_DELETE, FILE_OPEN_IF, 0, 0);
4064 printf("test 5 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4068 if (!cli_close(cli1, fnum1)) {
4069 printf("test 5 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4073 if (!cli_close(cli2, fnum2)) {
4074 printf("test 5 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4078 printf("non-io open test #5 passed.\n");
4080 printf("TEST #6 testing 1 non-io open, one io open\n");
4082 cli_unlink(cli1, fname);
4084 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
4085 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
4088 printf("test 6 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4092 fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4093 FILE_SHARE_READ, FILE_OPEN_IF, 0, 0);
4096 printf("test 6 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4100 if (!cli_close(cli1, fnum1)) {
4101 printf("test 6 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4105 if (!cli_close(cli2, fnum2)) {
4106 printf("test 6 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4110 printf("non-io open test #6 passed.\n");
4112 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
4114 cli_unlink(cli1, fname);
4116 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
4117 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
4120 printf("test 7 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4124 fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4125 FILE_SHARE_READ|FILE_SHARE_DELETE, FILE_OPEN_IF, 0, 0);
4128 printf("test 7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
4132 printf("test 7 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
4134 if (!cli_close(cli1, fnum1)) {
4135 printf("test 7 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4139 printf("non-io open test #7 passed.\n");
4141 cli_unlink(cli1, fname);
4143 if (!torture_close_connection(cli1)) {
4146 if (!torture_close_connection(cli2)) {
4153 static uint32 open_attrs_table[] = {
4154 FILE_ATTRIBUTE_NORMAL,
4155 FILE_ATTRIBUTE_ARCHIVE,
4156 FILE_ATTRIBUTE_READONLY,
4157 FILE_ATTRIBUTE_HIDDEN,
4158 FILE_ATTRIBUTE_SYSTEM,
4160 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY,
4161 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN,
4162 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM,
4163 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
4164 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
4165 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
4167 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
4168 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
4169 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
4170 FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_SYSTEM,
4173 struct trunc_open_results {
4180 static struct trunc_open_results attr_results[] = {
4181 { 0, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
4182 { 1, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
4183 { 2, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
4184 { 16, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
4185 { 17, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
4186 { 18, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
4187 { 51, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4188 { 54, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4189 { 56, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
4190 { 68, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4191 { 71, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4192 { 73, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM },
4193 { 99, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4194 { 102, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4195 { 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 },
4196 { 116, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4197 { 119, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4198 { 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 },
4199 { 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 },
4200 { 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 },
4201 { 227, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4202 { 230, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4203 { 232, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
4204 { 244, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4205 { 247, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4206 { 249, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM }
4209 static bool run_openattrtest(int dummy)
4211 static struct cli_state *cli1;
4212 const char *fname = "\\openattr.file";
4214 bool correct = True;
4216 unsigned int i, j, k, l;
4218 printf("starting open attr test\n");
4220 if (!torture_open_connection(&cli1, 0)) {
4224 cli_sockopt(cli1, sockops);
4226 for (k = 0, i = 0; i < sizeof(open_attrs_table)/sizeof(uint32); i++) {
4227 cli_setatr(cli1, fname, 0, 0);
4228 cli_unlink(cli1, fname);
4229 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_WRITE_DATA, open_attrs_table[i],
4230 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
4233 printf("open %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
4237 if (!cli_close(cli1, fnum1)) {
4238 printf("close %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
4242 for (j = 0; j < sizeof(open_attrs_table)/sizeof(uint32); j++) {
4243 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA, open_attrs_table[j],
4244 FILE_SHARE_NONE, FILE_OVERWRITE, 0, 0);
4247 for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
4248 if (attr_results[l].num == k) {
4249 printf("[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(0x%x:%s)\n",
4250 k, open_attrs_table[i],
4251 open_attrs_table[j],
4252 fname, NT_STATUS_V(cli_nt_error(cli1)), cli_errstr(cli1));
4256 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_ACCESS_DENIED)) {
4257 printf("[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s\n",
4258 k, open_attrs_table[i], open_attrs_table[j],
4263 printf("[%d] trunc open 0x%x -> 0x%x failed\n", k, open_attrs_table[i], open_attrs_table[j]);
4269 if (!cli_close(cli1, fnum1)) {
4270 printf("close %d (2) of %s failed (%s)\n", j, fname, cli_errstr(cli1));
4274 if (!cli_getatr(cli1, fname, &attr, NULL, NULL)) {
4275 printf("getatr(2) failed (%s)\n", cli_errstr(cli1));
4280 printf("[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n",
4281 k, open_attrs_table[i], open_attrs_table[j], attr );
4284 for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
4285 if (attr_results[l].num == k) {
4286 if (attr != attr_results[l].result_attr ||
4287 open_attrs_table[i] != attr_results[l].init_attr ||
4288 open_attrs_table[j] != attr_results[l].trunc_attr) {
4289 printf("getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x\n",
4290 open_attrs_table[i],
4291 open_attrs_table[j],
4293 attr_results[l].result_attr);
4303 cli_setatr(cli1, fname, 0, 0);
4304 cli_unlink(cli1, fname);
4306 printf("open attr test %s.\n", correct ? "passed" : "failed");
4308 if (!torture_close_connection(cli1)) {
4314 static void list_fn(const char *mnt, file_info *finfo, const char *name, void *state)
4320 test directory listing speed
4322 static bool run_dirtest(int dummy)
4325 static struct cli_state *cli;
4328 bool correct = True;
4330 printf("starting directory test\n");
4332 if (!torture_open_connection(&cli, 0)) {
4336 cli_sockopt(cli, sockops);
4339 for (i=0;i<torture_numops;i++) {
4341 slprintf(fname, sizeof(fname), "\\%x", (int)random());
4342 fnum = cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE);
4344 fprintf(stderr,"Failed to open %s\n", fname);
4347 cli_close(cli, fnum);
4352 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
4353 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
4354 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
4356 printf("dirtest core %g seconds\n", end_timer() - t1);
4359 for (i=0;i<torture_numops;i++) {
4361 slprintf(fname, sizeof(fname), "\\%x", (int)random());
4362 cli_unlink(cli, fname);
4365 if (!torture_close_connection(cli)) {
4369 printf("finished dirtest\n");
4374 static void del_fn(const char *mnt, file_info *finfo, const char *mask, void *state)
4376 struct cli_state *pcli = (struct cli_state *)state;
4378 slprintf(fname, sizeof(fname), "\\LISTDIR\\%s", finfo->name);
4380 if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
4383 if (finfo->mode & aDIR) {
4384 if (!cli_rmdir(pcli, fname))
4385 printf("del_fn: failed to rmdir %s\n,", fname );
4387 if (!cli_unlink(pcli, fname))
4388 printf("del_fn: failed to unlink %s\n,", fname );
4394 sees what IOCTLs are supported
4396 bool torture_ioctl_test(int dummy)
4398 static struct cli_state *cli;
4399 uint16 device, function;
4401 const char *fname = "\\ioctl.dat";
4405 if (!torture_open_connection(&cli, 0)) {
4409 printf("starting ioctl test\n");
4411 cli_unlink(cli, fname);
4413 fnum = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
4415 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
4419 status = cli_raw_ioctl(cli, fnum, 0x2d0000 | (0x0420<<2), &blob);
4420 printf("ioctl device info: %s\n", cli_errstr(cli));
4422 status = cli_raw_ioctl(cli, fnum, IOCTL_QUERY_JOB_INFO, &blob);
4423 printf("ioctl job info: %s\n", cli_errstr(cli));
4425 for (device=0;device<0x100;device++) {
4426 printf("testing device=0x%x\n", device);
4427 for (function=0;function<0x100;function++) {
4428 uint32 code = (device<<16) | function;
4430 status = cli_raw_ioctl(cli, fnum, code, &blob);
4432 if (NT_STATUS_IS_OK(status)) {
4433 printf("ioctl 0x%x OK : %d bytes\n", (int)code,
4435 data_blob_free(&blob);
4440 if (!torture_close_connection(cli)) {
4449 tries varients of chkpath
4451 bool torture_chkpath_test(int dummy)
4453 static struct cli_state *cli;
4457 if (!torture_open_connection(&cli, 0)) {
4461 printf("starting chkpath test\n");
4463 /* cleanup from an old run */
4464 cli_rmdir(cli, "\\chkpath.dir\\dir2");
4465 cli_unlink(cli, "\\chkpath.dir\\*");
4466 cli_rmdir(cli, "\\chkpath.dir");
4468 if (!cli_mkdir(cli, "\\chkpath.dir")) {
4469 printf("mkdir1 failed : %s\n", cli_errstr(cli));
4473 if (!cli_mkdir(cli, "\\chkpath.dir\\dir2")) {
4474 printf("mkdir2 failed : %s\n", cli_errstr(cli));
4478 fnum = cli_open(cli, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
4480 printf("open1 failed (%s)\n", cli_errstr(cli));
4483 cli_close(cli, fnum);
4485 if (!cli_chkpath(cli, "\\chkpath.dir")) {
4486 printf("chkpath1 failed: %s\n", cli_errstr(cli));
4490 if (!cli_chkpath(cli, "\\chkpath.dir\\dir2")) {
4491 printf("chkpath2 failed: %s\n", cli_errstr(cli));
4495 if (!cli_chkpath(cli, "\\chkpath.dir\\foo.txt")) {
4496 ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath,
4497 NT_STATUS_NOT_A_DIRECTORY);
4499 printf("* chkpath on a file should fail\n");
4503 if (!cli_chkpath(cli, "\\chkpath.dir\\bar.txt")) {
4504 ret = check_error(__LINE__, cli, ERRDOS, ERRbadfile,
4505 NT_STATUS_OBJECT_NAME_NOT_FOUND);
4507 printf("* chkpath on a non existant file should fail\n");
4511 if (!cli_chkpath(cli, "\\chkpath.dir\\dirxx\\bar.txt")) {
4512 ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath,
4513 NT_STATUS_OBJECT_PATH_NOT_FOUND);
4515 printf("* chkpath on a non existent component should fail\n");
4519 cli_rmdir(cli, "\\chkpath.dir\\dir2");
4520 cli_unlink(cli, "\\chkpath.dir\\*");
4521 cli_rmdir(cli, "\\chkpath.dir");
4523 if (!torture_close_connection(cli)) {
4530 static bool run_eatest(int dummy)
4532 static struct cli_state *cli;
4533 const char *fname = "\\eatest.txt";
4534 bool correct = True;
4537 struct ea_struct *ea_list = NULL;
4538 TALLOC_CTX *mem_ctx = talloc_init("eatest");
4540 printf("starting eatest\n");
4542 if (!torture_open_connection(&cli, 0)) {
4543 talloc_destroy(mem_ctx);
4547 cli_unlink(cli, fname);
4548 fnum = cli_nt_create_full(cli, fname, 0,
4549 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
4550 FILE_SHARE_NONE, FILE_OVERWRITE_IF,
4554 printf("open failed - %s\n", cli_errstr(cli));
4555 talloc_destroy(mem_ctx);
4559 for (i = 0; i < 10; i++) {
4560 fstring ea_name, ea_val;
4562 slprintf(ea_name, sizeof(ea_name), "EA_%d", i);
4563 memset(ea_val, (char)i+1, i+1);
4564 if (!cli_set_ea_fnum(cli, fnum, ea_name, ea_val, i+1)) {
4565 printf("ea_set of name %s failed - %s\n", ea_name, cli_errstr(cli));
4566 talloc_destroy(mem_ctx);
4571 cli_close(cli, fnum);
4572 for (i = 0; i < 10; i++) {
4573 fstring ea_name, ea_val;
4575 slprintf(ea_name, sizeof(ea_name), "EA_%d", i+10);
4576 memset(ea_val, (char)i+1, i+1);
4577 if (!cli_set_ea_path(cli, fname, ea_name, ea_val, i+1)) {
4578 printf("ea_set of name %s failed - %s\n", ea_name, cli_errstr(cli));
4579 talloc_destroy(mem_ctx);
4584 if (!cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list)) {
4585 printf("ea_get list failed - %s\n", cli_errstr(cli));
4589 printf("num_eas = %d\n", (int)num_eas);
4591 if (num_eas != 20) {
4592 printf("Should be 20 EA's stored... failing.\n");
4596 for (i = 0; i < num_eas; i++) {
4597 printf("%d: ea_name = %s. Val = ", i, ea_list[i].name);
4598 dump_data(0, ea_list[i].value.data,
4599 ea_list[i].value.length);
4602 /* Setting EA's to zero length deletes them. Test this */
4603 printf("Now deleting all EA's - case indepenent....\n");
4606 cli_set_ea_path(cli, fname, "", "", 0);
4608 for (i = 0; i < 20; i++) {
4610 slprintf(ea_name, sizeof(ea_name), "ea_%d", i);
4611 if (!cli_set_ea_path(cli, fname, ea_name, "", 0)) {
4612 printf("ea_set of name %s failed - %s\n", ea_name, cli_errstr(cli));
4613 talloc_destroy(mem_ctx);
4619 if (!cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list)) {
4620 printf("ea_get list failed - %s\n", cli_errstr(cli));
4624 printf("num_eas = %d\n", (int)num_eas);
4625 for (i = 0; i < num_eas; i++) {
4626 printf("%d: ea_name = %s. Val = ", i, ea_list[i].name);
4627 dump_data(0, ea_list[i].value.data,
4628 ea_list[i].value.length);
4632 printf("deleting EA's failed.\n");
4636 /* Try and delete a non existant EA. */
4637 if (!cli_set_ea_path(cli, fname, "foo", "", 0)) {
4638 printf("deleting non-existant EA 'foo' should succeed. %s\n", cli_errstr(cli));
4642 talloc_destroy(mem_ctx);
4643 if (!torture_close_connection(cli)) {
4650 static bool run_dirtest1(int dummy)
4653 static struct cli_state *cli;
4655 bool correct = True;
4657 printf("starting directory test\n");
4659 if (!torture_open_connection(&cli, 0)) {
4663 cli_sockopt(cli, sockops);
4665 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
4666 cli_list(cli, "\\LISTDIR\\*", aDIR, del_fn, cli);
4667 cli_rmdir(cli, "\\LISTDIR");
4668 cli_mkdir(cli, "\\LISTDIR");
4670 /* Create 1000 files and 1000 directories. */
4671 for (i=0;i<1000;i++) {
4673 slprintf(fname, sizeof(fname), "\\LISTDIR\\f%d", i);
4674 fnum = cli_nt_create_full(cli, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
4675 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0);
4677 fprintf(stderr,"Failed to open %s\n", fname);
4680 cli_close(cli, fnum);
4682 for (i=0;i<1000;i++) {
4684 slprintf(fname, sizeof(fname), "\\LISTDIR\\d%d", i);
4685 if (!cli_mkdir(cli, fname)) {
4686 fprintf(stderr,"Failed to open %s\n", fname);
4691 /* Now ensure that doing an old list sees both files and directories. */
4692 num_seen = cli_list_old(cli, "\\LISTDIR\\*", aDIR, list_fn, NULL);
4693 printf("num_seen = %d\n", num_seen );
4694 /* We should see 100 files + 1000 directories + . and .. */
4695 if (num_seen != 2002)
4698 /* Ensure if we have the "must have" bits we only see the
4701 num_seen = cli_list_old(cli, "\\LISTDIR\\*", (aDIR<<8)|aDIR, list_fn, NULL);
4702 printf("num_seen = %d\n", num_seen );
4703 if (num_seen != 1002)
4706 num_seen = cli_list_old(cli, "\\LISTDIR\\*", (aARCH<<8)|aDIR, list_fn, NULL);
4707 printf("num_seen = %d\n", num_seen );
4708 if (num_seen != 1000)
4711 /* Delete everything. */
4712 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
4713 cli_list(cli, "\\LISTDIR\\*", aDIR, del_fn, cli);
4714 cli_rmdir(cli, "\\LISTDIR");
4717 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
4718 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
4719 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
4722 if (!torture_close_connection(cli)) {
4726 printf("finished dirtest1\n");
4731 static bool run_error_map_extract(int dummy) {
4733 static struct cli_state *c_dos;
4734 static struct cli_state *c_nt;
4739 uint32 flgs2, errnum;
4746 /* NT-Error connection */
4748 if (!(c_nt = open_nbt_connection())) {
4752 c_nt->use_spnego = False;
4754 status = cli_negprot(c_nt);
4756 if (!NT_STATUS_IS_OK(status)) {
4757 printf("%s rejected the NT-error negprot (%s)\n", host,
4763 if (!NT_STATUS_IS_OK(cli_session_setup(c_nt, "", "", 0, "", 0,
4765 printf("%s rejected the NT-error initial session setup (%s)\n",host, cli_errstr(c_nt));
4769 /* DOS-Error connection */
4771 if (!(c_dos = open_nbt_connection())) {
4775 c_dos->use_spnego = False;
4776 c_dos->force_dos_errors = True;
4778 status = cli_negprot(c_dos);
4779 if (!NT_STATUS_IS_OK(status)) {
4780 printf("%s rejected the DOS-error negprot (%s)\n", host,
4782 cli_shutdown(c_dos);
4786 if (!NT_STATUS_IS_OK(cli_session_setup(c_dos, "", "", 0, "", 0,
4788 printf("%s rejected the DOS-error initial session setup (%s)\n",host, cli_errstr(c_dos));
4792 for (error=(0xc0000000 | 0x1); error < (0xc0000000| 0xFFF); error++) {
4793 fstr_sprintf(user, "%X", error);
4795 if (NT_STATUS_IS_OK(cli_session_setup(c_nt, user,
4796 password, strlen(password),
4797 password, strlen(password),
4799 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
4802 flgs2 = SVAL(c_nt->inbuf,smb_flg2);
4804 /* Case #1: 32-bit NT errors */
4805 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
4806 nt_status = NT_STATUS(IVAL(c_nt->inbuf,smb_rcls));
4808 printf("/** Dos error on NT connection! (%s) */\n",
4810 nt_status = NT_STATUS(0xc0000000);
4813 if (NT_STATUS_IS_OK(cli_session_setup(c_dos, user,
4814 password, strlen(password),
4815 password, strlen(password),
4817 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
4819 flgs2 = SVAL(c_dos->inbuf,smb_flg2), errnum;
4821 /* Case #1: 32-bit NT errors */
4822 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
4823 printf("/** NT error on DOS connection! (%s) */\n",
4825 errnum = errclass = 0;
4827 cli_dos_error(c_dos, &errclass, &errnum);
4830 if (NT_STATUS_V(nt_status) != error) {
4831 printf("/*\t{ This NT error code was 'sqashed'\n\t from %s to %s \n\t during the session setup }\n*/\n",
4832 get_nt_error_c_code(NT_STATUS(error)),
4833 get_nt_error_c_code(nt_status));
4836 printf("\t{%s,\t%s,\t%s},\n",
4837 smb_dos_err_class(errclass),
4838 smb_dos_err_name(errclass, errnum),
4839 get_nt_error_c_code(NT_STATUS(error)));
4844 static bool run_sesssetup_bench(int dummy)
4846 static struct cli_state *c;
4847 const char *fname = "\\file.dat";
4852 if (!torture_open_connection(&c, 0)) {
4856 fnum = cli_nt_create_full(
4857 c, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
4858 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
4859 FILE_DELETE_ON_CLOSE, 0);
4861 d_printf("open %s failed: %s\n", fname, cli_errstr(c));
4865 for (i=0; i<torture_numops; i++) {
4866 status = cli_session_setup(
4868 password, strlen(password),
4869 password, strlen(password),
4871 if (!NT_STATUS_IS_OK(status)) {
4872 d_printf("(%s) cli_session_setup failed: %s\n",
4873 __location__, nt_errstr(status));
4877 d_printf("\r%d ", (int)c->vuid);
4879 if (!cli_ulogoff(c)) {
4880 d_printf("(%s) cli_ulogoff failed: %s\n",
4881 __location__, cli_errstr(c));
4890 static bool subst_test(const char *str, const char *user, const char *domain,
4891 uid_t uid, gid_t gid, const char *expected)
4896 subst = talloc_sub_specified(talloc_tos(), str, user, domain, uid, gid);
4898 if (strcmp(subst, expected) != 0) {
4899 printf("sub_specified(%s, %s, %s, %d, %d) returned [%s], expected "
4900 "[%s]\n", str, user, domain, (int)uid, (int)gid, subst,
4909 static void chain1_open_completion(struct async_req *req)
4914 status = cli_open_recv(req, &fnum);
4917 d_printf("cli_open_recv returned %s: %d\n",
4919 NT_STATUS_IS_OK(status) ? fnum : -1);
4922 static void chain1_read_completion(struct async_req *req)
4928 status = cli_read_andx_recv(req, &received, &rcvbuf);
4929 if (!NT_STATUS_IS_OK(status)) {
4931 d_printf("cli_read_andx_recv returned %s\n",
4936 d_printf("got %d bytes: %.*s\n", (int)received, (int)received,
4941 static void chain1_write_completion(struct async_req *req)
4946 status = cli_write_andx_recv(req, &written);
4947 if (!NT_STATUS_IS_OK(status)) {
4949 d_printf("cli_write_andx_recv returned %s\n",
4954 d_printf("wrote %d bytes\n", (int)written);
4958 static void chain1_close_completion(struct async_req *req)
4962 status = cli_close_recv(req);
4963 *((bool *)(req->async.priv)) = true;
4967 d_printf("cli_close returned %s\n", nt_errstr(status));
4970 static bool run_chain1(int dummy)
4972 struct cli_state *cli1;
4973 struct event_context *evt = event_context_init(NULL);
4974 struct async_req *reqs[4];
4976 const char *text = "hallo";
4978 printf("starting chain1 test\n");
4979 if (!torture_open_connection(&cli1, 0)) {
4983 cli_sockopt(cli1, sockops);
4985 cli_chain_cork(cli1, evt, 0);
4986 reqs[0] = cli_open_send(talloc_tos(), evt, cli1, "\\test",
4988 reqs[0]->async.fn = chain1_open_completion;
4989 reqs[1] = cli_write_andx_send(talloc_tos(), evt, cli1, 0, 0,
4990 (uint8_t *)text, 0, strlen(text));
4991 reqs[1]->async.fn = chain1_write_completion;
4992 reqs[2] = cli_read_andx_send(talloc_tos(), evt, cli1, 0, 1, 10);
4993 reqs[2]->async.fn = chain1_read_completion;
4994 reqs[3] = cli_close_send(talloc_tos(), evt, cli1, 0);
4995 reqs[3]->async.fn = chain1_close_completion;
4996 reqs[3]->async.priv = (void *)&done;
4997 cli_chain_uncork(cli1);
5000 event_loop_once(evt);
5003 torture_close_connection(cli1);
5007 static size_t null_source(uint8_t *buf, size_t n, void *priv)
5009 size_t *to_pull = (size_t *)priv;
5010 size_t thistime = *to_pull;
5012 thistime = MIN(thistime, n);
5013 if (thistime == 0) {
5017 memset(buf, 0, thistime);
5018 *to_pull -= thistime;
5022 static bool run_windows_write(int dummy)
5024 struct cli_state *cli1;
5028 const char *fname = "\\writetest.txt";
5032 printf("starting windows_write test\n");
5033 if (!torture_open_connection(&cli1, 0)) {
5037 fnum = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
5039 printf("open failed (%s)\n", cli_errstr(cli1));
5043 cli_sockopt(cli1, sockops);
5047 for (i=0; i<torture_numops; i++) {
5049 off_t start = i * torture_blocksize;
5051 size_t to_pull = torture_blocksize - 1;
5053 if (cli_write(cli1, fnum, 0, &c,
5054 start + torture_blocksize - 1, 1) != 1) {
5055 printf("cli_write failed: %s\n", cli_errstr(cli1));
5059 status = cli_push(cli1, fnum, 0, i * torture_blocksize, torture_blocksize,
5060 null_source, &to_pull);
5061 if (!NT_STATUS_IS_OK(status)) {
5062 printf("cli_push returned: %s\n", nt_errstr(status));
5067 seconds = end_timer();
5068 kbytes = (double)torture_blocksize * torture_numops;
5071 printf("Wrote %d kbytes in %.2f seconds: %d kb/sec\n", (int)kbytes,
5072 (double)seconds, (int)(kbytes/seconds));
5076 cli_close(cli1, fnum);
5077 cli_unlink(cli1, fname);
5078 torture_close_connection(cli1);
5082 static bool run_cli_echo(int dummy)
5084 struct cli_state *cli;
5085 struct event_context *ev = event_context_init(NULL);
5086 struct async_req *req;
5089 printf("starting chain1 test\n");
5090 if (!torture_open_connection(&cli, 0)) {
5093 cli_sockopt(cli, sockops);
5095 req = cli_echo_send(ev, ev, cli, 5, data_blob_const("hello", 5));
5097 d_printf("cli_echo_send failed\n");
5101 while (req->state < ASYNC_REQ_DONE) {
5102 event_loop_once(ev);
5105 status = cli_echo_recv(req);
5106 d_printf("cli_echo returned %s\n", nt_errstr(status));
5110 torture_close_connection(cli);
5111 return NT_STATUS_IS_OK(status);
5114 static bool run_local_substitute(int dummy)
5118 ok &= subst_test("%U", "bla", "", -1, -1, "bla");
5119 ok &= subst_test("%u%U", "bla", "", -1, -1, "blabla");
5120 ok &= subst_test("%g", "", "", -1, -1, "NO_GROUP");
5121 ok &= subst_test("%G", "", "", -1, -1, "NO_GROUP");
5122 ok &= subst_test("%g", "", "", -1, 0, gidtoname(0));
5123 ok &= subst_test("%G", "", "", -1, 0, gidtoname(0));
5124 ok &= subst_test("%D%u", "u", "dom", -1, 0, "domu");
5125 ok &= subst_test("%i %I", "", "", -1, -1, "0.0.0.0 0.0.0.0");
5127 /* Different captialization rules in sub_basic... */
5129 ok &= (strcmp(talloc_sub_basic(talloc_tos(), "BLA", "dom", "%U%D"),
5135 static bool run_local_gencache(int dummy)
5141 if (!gencache_init()) {
5142 d_printf("%s: gencache_init() failed\n", __location__);
5146 if (!gencache_set("foo", "bar", time(NULL) + 1000)) {
5147 d_printf("%s: gencache_set() failed\n", __location__);
5151 if (!gencache_get("foo", &val, &tm)) {
5152 d_printf("%s: gencache_get() failed\n", __location__);
5156 if (strcmp(val, "bar") != 0) {
5157 d_printf("%s: gencache_get() returned %s, expected %s\n",
5158 __location__, val, "bar");
5165 if (!gencache_del("foo")) {
5166 d_printf("%s: gencache_del() failed\n", __location__);
5169 if (gencache_del("foo")) {
5170 d_printf("%s: second gencache_del() succeeded\n",
5175 if (gencache_get("foo", &val, &tm)) {
5176 d_printf("%s: gencache_get() on deleted entry "
5177 "succeeded\n", __location__);
5181 blob = data_blob_string_const_null("bar");
5184 if (!gencache_set_data_blob("foo", &blob, tm)) {
5185 d_printf("%s: gencache_set_data_blob() failed\n", __location__);
5189 data_blob_free(&blob);
5191 if (!gencache_get_data_blob("foo", &blob, NULL)) {
5192 d_printf("%s: gencache_get_data_blob() failed\n", __location__);
5196 if (strcmp((const char *)blob.data, "bar") != 0) {
5197 d_printf("%s: gencache_get_data_blob() returned %s, expected %s\n",
5198 __location__, (const char *)blob.data, "bar");
5199 data_blob_free(&blob);
5203 data_blob_free(&blob);
5205 if (!gencache_del("foo")) {
5206 d_printf("%s: gencache_del() failed\n", __location__);
5209 if (gencache_del("foo")) {
5210 d_printf("%s: second gencache_del() succeeded\n",
5215 if (gencache_get_data_blob("foo", &blob, NULL)) {
5216 d_printf("%s: gencache_get_data_blob() on deleted entry "
5217 "succeeded\n", __location__);
5221 if (!gencache_shutdown()) {
5222 d_printf("%s: gencache_shutdown() failed\n", __location__);
5226 if (gencache_shutdown()) {
5227 d_printf("%s: second gencache_shutdown() succeeded\n",
5235 static bool rbt_testval(struct db_context *db, const char *key,
5238 struct db_record *rec;
5239 TDB_DATA data = string_tdb_data(value);
5243 rec = db->fetch_locked(db, db, string_tdb_data(key));
5245 d_fprintf(stderr, "fetch_locked failed\n");
5248 status = rec->store(rec, data, 0);
5249 if (!NT_STATUS_IS_OK(status)) {
5250 d_fprintf(stderr, "store failed: %s\n", nt_errstr(status));
5255 rec = db->fetch_locked(db, db, string_tdb_data(key));
5257 d_fprintf(stderr, "second fetch_locked failed\n");
5260 if ((rec->value.dsize != data.dsize)
5261 || (memcmp(rec->value.dptr, data.dptr, data.dsize) != 0)) {
5262 d_fprintf(stderr, "Got wrong data back\n");
5272 static bool run_local_rbtree(int dummy)
5274 struct db_context *db;
5278 db = db_open_rbt(NULL);
5281 d_fprintf(stderr, "db_open_rbt failed\n");
5285 for (i=0; i<1000; i++) {
5288 if (asprintf(&key, "key%ld", random()) == -1) {
5291 if (asprintf(&value, "value%ld", random()) == -1) {
5296 if (!rbt_testval(db, key, value)) {
5303 if (asprintf(&value, "value%ld", random()) == -1) {
5308 if (!rbt_testval(db, key, value)) {
5325 static bool test_stream_name(const char *fname, const char *expected_base,
5326 const char *expected_stream,
5327 NTSTATUS expected_status)
5331 char *stream = NULL;
5333 status = split_ntfs_stream_name(talloc_tos(), fname, &base, &stream);
5334 if (!NT_STATUS_EQUAL(status, expected_status)) {
5338 if (!NT_STATUS_IS_OK(status)) {
5342 if (base == NULL) goto error;
5344 if (strcmp(expected_base, base) != 0) goto error;
5346 if ((expected_stream != NULL) && (stream == NULL)) goto error;
5347 if ((expected_stream == NULL) && (stream != NULL)) goto error;
5349 if ((stream != NULL) && (strcmp(expected_stream, stream) != 0))
5353 TALLOC_FREE(stream);
5357 d_fprintf(stderr, "test_stream(%s, %s, %s, %s)\n",
5358 fname, expected_base ? expected_base : "<NULL>",
5359 expected_stream ? expected_stream : "<NULL>",
5360 nt_errstr(expected_status));
5361 d_fprintf(stderr, "-> base=%s, stream=%s, status=%s\n",
5362 base ? base : "<NULL>", stream ? stream : "<NULL>",
5365 TALLOC_FREE(stream);
5369 static bool run_local_stream_name(int dummy)
5373 ret &= test_stream_name(
5374 "bla", "bla", NULL, NT_STATUS_OK);
5375 ret &= test_stream_name(
5376 "bla::$DATA", "bla", NULL, NT_STATUS_OK);
5377 ret &= test_stream_name(
5378 "bla:blub:", "bla", NULL, NT_STATUS_OBJECT_NAME_INVALID);
5379 ret &= test_stream_name(
5380 "bla::", NULL, NULL, NT_STATUS_OBJECT_NAME_INVALID);
5381 ret &= test_stream_name(
5382 "bla::123", "bla", NULL, NT_STATUS_OBJECT_NAME_INVALID);
5383 ret &= test_stream_name(
5384 "bla:$DATA", "bla", "$DATA:$DATA", NT_STATUS_OK);
5385 ret &= test_stream_name(
5386 "bla:x:$DATA", "bla", "x:$DATA", NT_STATUS_OK);
5387 ret &= test_stream_name(
5388 "bla:x", "bla", "x:$DATA", NT_STATUS_OK);
5393 static bool data_blob_equal(DATA_BLOB a, DATA_BLOB b)
5395 if (a.length != b.length) {
5396 printf("a.length=%d != b.length=%d\n",
5397 (int)a.length, (int)b.length);
5400 if (memcmp(a.data, b.data, a.length) != 0) {
5401 printf("a.data and b.data differ\n");
5407 static bool run_local_memcache(int dummy)
5409 struct memcache *cache;
5411 DATA_BLOB d1, d2, d3;
5412 DATA_BLOB v1, v2, v3;
5414 TALLOC_CTX *mem_ctx;
5416 size_t size1, size2;
5419 cache = memcache_init(NULL, 100);
5421 if (cache == NULL) {
5422 printf("memcache_init failed\n");
5426 d1 = data_blob_const("d1", 2);
5427 d2 = data_blob_const("d2", 2);
5428 d3 = data_blob_const("d3", 2);
5430 k1 = data_blob_const("d1", 2);
5431 k2 = data_blob_const("d2", 2);
5433 memcache_add(cache, STAT_CACHE, k1, d1);
5434 memcache_add(cache, GETWD_CACHE, k2, d2);
5436 if (!memcache_lookup(cache, STAT_CACHE, k1, &v1)) {
5437 printf("could not find k1\n");
5440 if (!data_blob_equal(d1, v1)) {
5444 if (!memcache_lookup(cache, GETWD_CACHE, k2, &v2)) {
5445 printf("could not find k2\n");
5448 if (!data_blob_equal(d2, v2)) {
5452 memcache_add(cache, STAT_CACHE, k1, d3);
5454 if (!memcache_lookup(cache, STAT_CACHE, k1, &v3)) {
5455 printf("could not find replaced k1\n");
5458 if (!data_blob_equal(d3, v3)) {
5462 memcache_add(cache, GETWD_CACHE, k1, d1);
5464 if (memcache_lookup(cache, GETWD_CACHE, k2, &v2)) {
5465 printf("Did find k2, should have been purged\n");
5471 cache = memcache_init(NULL, 0);
5473 mem_ctx = talloc_init("foo");
5475 str1 = talloc_strdup(mem_ctx, "string1");
5476 str2 = talloc_strdup(mem_ctx, "string2");
5478 memcache_add_talloc(cache, SINGLETON_CACHE_TALLOC,
5479 data_blob_string_const("torture"), &str1);
5480 size1 = talloc_total_size(cache);
5482 memcache_add_talloc(cache, SINGLETON_CACHE_TALLOC,
5483 data_blob_string_const("torture"), &str2);
5484 size2 = talloc_total_size(cache);
5486 printf("size1=%d, size2=%d\n", (int)size1, (int)size2);
5488 if (size2 > size1) {
5489 printf("memcache leaks memory!\n");
5499 static void wbclient_done(struct async_req *req)
5502 struct winbindd_response *wb_resp;
5503 int *i = (int *)req->async.priv;
5505 wbc_err = wb_trans_recv(req, req, &wb_resp);
5508 d_printf("wb_trans_recv %d returned %s\n", *i, wbcErrorString(wbc_err));
5511 static bool run_local_wbclient(int dummy)
5513 struct event_context *ev;
5514 struct wb_context **wb_ctx;
5515 struct winbindd_request wb_req;
5516 bool result = false;
5519 BlockSignals(True, SIGPIPE);
5521 ev = event_context_init(talloc_tos());
5526 wb_ctx = TALLOC_ARRAY(ev, struct wb_context *, torture_numops);
5527 if (wb_ctx == NULL) {
5531 ZERO_STRUCT(wb_req);
5532 wb_req.cmd = WINBINDD_PING;
5534 for (i=0; i<torture_numops; i++) {
5535 wb_ctx[i] = wb_context_init(ev);
5536 if (wb_ctx[i] == NULL) {
5539 for (j=0; j<5; j++) {
5540 struct async_req *req;
5541 req = wb_trans_send(ev, ev, wb_ctx[i],
5542 (j % 2) == 0, &wb_req);
5546 req->async.fn = wbclient_done;
5547 req->async.priv = &i;
5553 while (i < 5 * torture_numops) {
5554 event_loop_once(ev);
5563 static double create_procs(bool (*fn)(int), bool *result)
5566 volatile pid_t *child_status;
5567 volatile bool *child_status_out;
5573 child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*nprocs);
5574 if (!child_status) {
5575 printf("Failed to setup shared memory\n");
5579 child_status_out = (volatile bool *)shm_setup(sizeof(bool)*nprocs);
5580 if (!child_status_out) {
5581 printf("Failed to setup result status shared memory\n");
5585 for (i = 0; i < nprocs; i++) {
5586 child_status[i] = 0;
5587 child_status_out[i] = True;
5592 for (i=0;i<nprocs;i++) {
5595 pid_t mypid = getpid();
5596 sys_srandom(((int)mypid) ^ ((int)time(NULL)));
5598 slprintf(myname,sizeof(myname),"CLIENT%d", i);
5601 if (torture_open_connection(¤t_cli, i)) break;
5603 printf("pid %d failed to start\n", (int)getpid());
5609 child_status[i] = getpid();
5611 while (child_status[i] && end_timer() < 5) smb_msleep(2);
5613 child_status_out[i] = fn(i);
5620 for (i=0;i<nprocs;i++) {
5621 if (child_status[i]) synccount++;
5623 if (synccount == nprocs) break;
5625 } while (end_timer() < 30);
5627 if (synccount != nprocs) {
5628 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs, synccount);
5633 /* start the client load */
5636 for (i=0;i<nprocs;i++) {
5637 child_status[i] = 0;
5640 printf("%d clients started\n", nprocs);
5642 for (i=0;i<nprocs;i++) {
5643 while (waitpid(0, &status, 0) == -1 && errno == EINTR) /* noop */ ;
5648 for (i=0;i<nprocs;i++) {
5649 if (!child_status_out[i]) {
5656 #define FLAG_MULTIPROC 1
5663 {"FDPASS", run_fdpasstest, 0},
5664 {"LOCK1", run_locktest1, 0},
5665 {"LOCK2", run_locktest2, 0},
5666 {"LOCK3", run_locktest3, 0},
5667 {"LOCK4", run_locktest4, 0},
5668 {"LOCK5", run_locktest5, 0},
5669 {"LOCK6", run_locktest6, 0},
5670 {"LOCK7", run_locktest7, 0},
5671 {"UNLINK", run_unlinktest, 0},
5672 {"BROWSE", run_browsetest, 0},
5673 {"ATTR", run_attrtest, 0},
5674 {"TRANS2", run_trans2test, 0},
5675 {"MAXFID", run_maxfidtest, FLAG_MULTIPROC},
5676 {"TORTURE",run_torture, FLAG_MULTIPROC},
5677 {"RANDOMIPC", run_randomipc, 0},
5678 {"NEGNOWAIT", run_negprot_nowait, 0},
5679 {"NBENCH", run_nbench, 0},
5680 {"OPLOCK1", run_oplock1, 0},
5681 {"OPLOCK2", run_oplock2, 0},
5682 {"OPLOCK3", run_oplock3, 0},
5683 {"DIR", run_dirtest, 0},
5684 {"DIR1", run_dirtest1, 0},
5685 {"DENY1", torture_denytest1, 0},
5686 {"DENY2", torture_denytest2, 0},
5687 {"TCON", run_tcon_test, 0},
5688 {"TCONDEV", run_tcon_devtype_test, 0},
5689 {"RW1", run_readwritetest, 0},
5690 {"RW2", run_readwritemulti, FLAG_MULTIPROC},
5691 {"RW3", run_readwritelarge, 0},
5692 {"OPEN", run_opentest, 0},
5694 {"OPENATTR", run_openattrtest, 0},
5696 {"XCOPY", run_xcopy, 0},
5697 {"RENAME", run_rename, 0},
5698 {"DELETE", run_deletetest, 0},
5699 {"PROPERTIES", run_properties, 0},
5700 {"MANGLE", torture_mangle, 0},
5701 {"W2K", run_w2ktest, 0},
5702 {"TRANS2SCAN", torture_trans2_scan, 0},
5703 {"NTTRANSSCAN", torture_nttrans_scan, 0},
5704 {"UTABLE", torture_utable, 0},
5705 {"CASETABLE", torture_casetable, 0},
5706 {"ERRMAPEXTRACT", run_error_map_extract, 0},
5707 {"PIPE_NUMBER", run_pipe_number, 0},
5708 {"TCON2", run_tcon2_test, 0},
5709 {"IOCTL", torture_ioctl_test, 0},
5710 {"CHKPATH", torture_chkpath_test, 0},
5711 {"FDSESS", run_fdsesstest, 0},
5712 { "EATEST", run_eatest, 0},
5713 { "SESSSETUP_BENCH", run_sesssetup_bench, 0},
5714 { "CHAIN1", run_chain1, 0},
5715 { "WINDOWS-WRITE", run_windows_write, 0},
5716 { "CLI_ECHO", run_cli_echo, 0},
5717 { "LOCAL-SUBSTITUTE", run_local_substitute, 0},
5718 { "LOCAL-GENCACHE", run_local_gencache, 0},
5719 { "LOCAL-RBTREE", run_local_rbtree, 0},
5720 { "LOCAL-MEMCACHE", run_local_memcache, 0},
5721 { "LOCAL-STREAM-NAME", run_local_stream_name, 0},
5722 { "LOCAL-WBCLIENT", run_local_wbclient, 0},
5727 /****************************************************************************
5728 run a specified test or "ALL"
5729 ****************************************************************************/
5730 static bool run_test(const char *name)
5737 if (strequal(name,"ALL")) {
5738 for (i=0;torture_ops[i].name;i++) {
5739 run_test(torture_ops[i].name);
5744 for (i=0;torture_ops[i].name;i++) {
5745 fstr_sprintf(randomfname, "\\XX%x",
5746 (unsigned)random());
5748 if (strequal(name, torture_ops[i].name)) {
5750 printf("Running %s\n", name);
5751 if (torture_ops[i].flags & FLAG_MULTIPROC) {
5752 t = create_procs(torture_ops[i].fn, &result);
5755 printf("TEST %s FAILED!\n", name);
5760 if (!torture_ops[i].fn(0)) {
5762 printf("TEST %s FAILED!\n", name);
5766 printf("%s took %g secs\n\n", name, t);
5771 printf("Did not find a test named %s\n", name);
5779 static void usage(void)
5783 printf("WARNING samba4 test suite is much more complete nowadays.\n");
5784 printf("Please use samba4 torture.\n\n");
5786 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
5788 printf("\t-d debuglevel\n");
5789 printf("\t-U user%%pass\n");
5790 printf("\t-k use kerberos\n");
5791 printf("\t-N numprocs\n");
5792 printf("\t-n my_netbios_name\n");
5793 printf("\t-W workgroup\n");
5794 printf("\t-o num_operations\n");
5795 printf("\t-O socket_options\n");
5796 printf("\t-m maximum protocol\n");
5797 printf("\t-L use oplocks\n");
5798 printf("\t-c CLIENT.TXT specify client load file for NBENCH\n");
5799 printf("\t-A showall\n");
5800 printf("\t-p port\n");
5801 printf("\t-s seed\n");
5802 printf("\t-b unclist_filename specify multiple shares for multiple connections\n");
5805 printf("tests are:");
5806 for (i=0;torture_ops[i].name;i++) {
5807 printf(" %s", torture_ops[i].name);
5811 printf("default test is ALL\n");
5816 /****************************************************************************
5818 ****************************************************************************/
5819 int main(int argc,char *argv[])
5825 bool correct = True;
5826 TALLOC_CTX *frame = talloc_stackframe();
5827 int seed = time(NULL);
5831 #ifdef HAVE_SETBUFFER
5832 setbuffer(stdout, NULL, 0);
5837 if (is_default_dyn_CONFIGFILE()) {
5838 if(getenv("SMB_CONF_PATH")) {
5839 set_dyn_CONFIGFILE(getenv("SMB_CONF_PATH"));
5842 lp_load(get_dyn_CONFIGFILE(),True,False,False,True);
5849 for(p = argv[1]; *p; p++)
5853 if (strncmp(argv[1], "//", 2)) {
5857 fstrcpy(host, &argv[1][2]);
5858 p = strchr_m(&host[2],'/');
5863 fstrcpy(share, p+1);
5865 fstrcpy(myname, get_myname(talloc_tos()));
5867 fprintf(stderr, "Failed to get my hostname.\n");
5871 if (*username == 0 && getenv("LOGNAME")) {
5872 fstrcpy(username,getenv("LOGNAME"));
5878 fstrcpy(workgroup, lp_workgroup());
5880 while ((opt = getopt(argc, argv, "p:hW:U:n:N:O:o:m:Ld:Aec:ks:b:B:")) != EOF) {
5883 port_to_use = atoi(optarg);
5886 seed = atoi(optarg);
5889 fstrcpy(workgroup,optarg);
5892 max_protocol = interpret_protocol(optarg, max_protocol);
5895 nprocs = atoi(optarg);
5898 torture_numops = atoi(optarg);
5901 DEBUGLEVEL = atoi(optarg);
5910 torture_showall = True;
5913 fstrcpy(myname, optarg);
5916 client_txt = optarg;
5923 use_kerberos = True;
5925 d_printf("No kerberos support compiled in\n");
5931 fstrcpy(username,optarg);
5932 p = strchr_m(username,'%');
5935 fstrcpy(password, p+1);
5940 fstrcpy(multishare_conn_fname, optarg);
5941 use_multishare_conn = True;
5944 torture_blocksize = atoi(optarg);
5947 printf("Unknown option %c (%d)\n", (char)opt, opt);
5952 d_printf("using seed %d\n", seed);
5956 if(use_kerberos && !gotuser) gotpass = True;
5959 p = getpass("Password:");
5961 fstrcpy(password, p);
5966 printf("host=%s share=%s user=%s myname=%s\n",
5967 host, share, username, myname);
5969 if (argc == optind) {
5970 correct = run_test("ALL");
5972 for (i=optind;i<argc;i++) {
5973 if (!run_test(argv[i])) {