2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1997-1998
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 static fstring host, workgroup, share, password, username, myname;
26 static int max_protocol = PROTOCOL_NT1;
27 static const char *sockops="TCP_NODELAY";
29 static int port_to_use=0;
30 int torture_numops=100;
31 static int procnum; /* records process count number when forking */
32 static struct cli_state *current_cli;
33 static fstring randomfname;
34 static bool use_oplocks;
35 static bool use_level_II_oplocks;
36 static const char *client_txt = "client_oplocks.txt";
37 static bool use_kerberos;
38 static fstring multishare_conn_fname;
39 static bool use_multishare_conn = False;
40 static bool do_encrypt;
42 bool torture_showall = False;
44 static double create_procs(bool (*fn)(int), bool *result);
47 static struct timeval tp1,tp2;
50 void start_timer(void)
55 double end_timer(void)
58 return((tp2.tv_sec - tp1.tv_sec) +
59 (tp2.tv_usec - tp1.tv_usec)*1.0e-6);
63 /* return a pointer to a anonymous shared memory segment of size "size"
64 which will persist across fork() but will disappear when all processes
67 The memory is not zeroed
69 This function uses system5 shared memory. It takes advantage of a property
70 that the memory is not destroyed if it is attached when the id is removed
72 void *shm_setup(int size)
77 shmid = shmget(IPC_PRIVATE, size, S_IRUSR | S_IWUSR);
79 printf("can't get shared memory\n");
82 ret = (void *)shmat(shmid, 0, 0);
83 if (!ret || ret == (void *)-1) {
84 printf("can't attach to shared memory\n");
87 /* the following releases the ipc, but note that this process
88 and all its children will still have access to the memory, its
89 just that the shmid is no longer valid for other shm calls. This
90 means we don't leave behind lots of shm segments after we exit
92 See Stevens "advanced programming in unix env" for details
94 shmctl(shmid, IPC_RMID, 0);
99 /********************************************************************
100 Ensure a connection is encrypted.
101 ********************************************************************/
103 static bool force_cli_encryption(struct cli_state *c,
104 const char *sharename)
107 uint32 caplow, caphigh;
110 if (!SERVER_HAS_UNIX_CIFS(c)) {
111 d_printf("Encryption required and "
112 "server that doesn't support "
113 "UNIX extensions - failing connect\n");
117 if (!cli_unix_extensions_version(c, &major, &minor, &caplow, &caphigh)) {
118 d_printf("Encryption required and "
119 "can't get UNIX CIFS extensions "
120 "version from server.\n");
124 if (!(caplow & CIFS_UNIX_TRANSPORT_ENCRYPTION_CAP)) {
125 d_printf("Encryption required and "
126 "share %s doesn't support "
127 "encryption.\n", sharename);
131 if (c->use_kerberos) {
132 status = cli_gss_smb_encryption_start(c);
134 status = cli_raw_ntlm_smb_encryption_start(c,
140 if (!NT_STATUS_IS_OK(status)) {
141 d_printf("Encryption required and "
142 "setup failed with error %s.\n",
151 static struct cli_state *open_nbt_connection(void)
153 struct nmb_name called, calling;
154 struct sockaddr_storage ss;
158 make_nmb_name(&calling, myname, 0x0);
159 make_nmb_name(&called , host, 0x20);
163 if (!(c = cli_initialise())) {
164 printf("Failed initialize cli_struct to connect with %s\n", host);
168 c->port = port_to_use;
170 status = cli_connect(c, host, &ss);
171 if (!NT_STATUS_IS_OK(status)) {
172 printf("Failed to connect with %s. Error %s\n", host, nt_errstr(status) );
176 c->use_kerberos = use_kerberos;
178 c->timeout = 120000; /* set a really long timeout (2 minutes) */
179 if (use_oplocks) c->use_oplocks = True;
180 if (use_level_II_oplocks) c->use_level_II_oplocks = True;
182 if (!cli_session_request(c, &calling, &called)) {
184 * Well, that failed, try *SMBSERVER ...
185 * However, we must reconnect as well ...
187 status = cli_connect(c, host, &ss);
188 if (!NT_STATUS_IS_OK(status)) {
189 printf("Failed to connect with %s. Error %s\n", host, nt_errstr(status) );
193 make_nmb_name(&called, "*SMBSERVER", 0x20);
194 if (!cli_session_request(c, &calling, &called)) {
195 printf("%s rejected the session\n",host);
196 printf("We tried with a called name of %s & %s\n",
206 /* Insert a NULL at the first separator of the given path and return a pointer
207 * to the remainder of the string.
210 terminate_path_at_separator(char * path)
218 if ((p = strchr_m(path, '/'))) {
223 if ((p = strchr_m(path, '\\'))) {
233 parse a //server/share type UNC name
235 bool smbcli_parse_unc(const char *unc_name, TALLOC_CTX *mem_ctx,
236 char **hostname, char **sharename)
240 *hostname = *sharename = NULL;
242 if (strncmp(unc_name, "\\\\", 2) &&
243 strncmp(unc_name, "//", 2)) {
247 *hostname = talloc_strdup(mem_ctx, &unc_name[2]);
248 p = terminate_path_at_separator(*hostname);
251 *sharename = talloc_strdup(mem_ctx, p);
252 terminate_path_at_separator(*sharename);
255 if (*hostname && *sharename) {
259 TALLOC_FREE(*hostname);
260 TALLOC_FREE(*sharename);
264 static bool torture_open_connection_share(struct cli_state **c,
265 const char *hostname,
266 const char *sharename)
273 flags |= CLI_FULL_CONNECTION_USE_KERBEROS;
275 status = cli_full_connection(c, myname,
276 hostname, NULL, port_to_use,
279 password, flags, Undefined, &retry);
280 if (!NT_STATUS_IS_OK(status)) {
281 printf("failed to open share connection: //%s/%s port:%d - %s\n",
282 hostname, sharename, port_to_use, nt_errstr(status));
286 if (use_oplocks) (*c)->use_oplocks = True;
287 if (use_level_II_oplocks) (*c)->use_level_II_oplocks = True;
288 (*c)->timeout = 120000; /* set a really long timeout (2 minutes) */
291 return force_cli_encryption(*c,
297 bool torture_open_connection(struct cli_state **c, int conn_index)
299 char **unc_list = NULL;
300 int num_unc_names = 0;
303 if (use_multishare_conn==True) {
305 unc_list = file_lines_load(multishare_conn_fname, &num_unc_names, 0, NULL);
306 if (!unc_list || num_unc_names <= 0) {
307 printf("Failed to load unc names list from '%s'\n", multishare_conn_fname);
311 if (!smbcli_parse_unc(unc_list[conn_index % num_unc_names],
313 printf("Failed to parse UNC name %s\n",
314 unc_list[conn_index % num_unc_names]);
315 TALLOC_FREE(unc_list);
319 result = torture_open_connection_share(c, h, s);
321 /* h, s were copied earlier */
322 TALLOC_FREE(unc_list);
326 return torture_open_connection_share(c, host, share);
329 bool torture_cli_session_setup2(struct cli_state *cli, uint16 *new_vuid)
331 uint16 old_vuid = cli->vuid;
332 fstring old_user_name;
333 size_t passlen = strlen(password);
336 fstrcpy(old_user_name, cli->user_name);
338 ret = NT_STATUS_IS_OK(cli_session_setup(cli, username,
342 *new_vuid = cli->vuid;
343 cli->vuid = old_vuid;
344 fstrcpy(cli->user_name, old_user_name);
349 bool torture_close_connection(struct cli_state *c)
353 printf("tdis failed (%s)\n", cli_errstr(c));
363 /* check if the server produced the expected error code */
364 static bool check_error(int line, struct cli_state *c,
365 uint8 eclass, uint32 ecode, NTSTATUS nterr)
367 if (cli_is_dos_error(c)) {
371 /* Check DOS error */
373 cli_dos_error(c, &cclass, &num);
375 if (eclass != cclass || ecode != num) {
376 printf("unexpected error code class=%d code=%d\n",
377 (int)cclass, (int)num);
378 printf(" expected %d/%d %s (line=%d)\n",
379 (int)eclass, (int)ecode, nt_errstr(nterr), line);
388 status = cli_nt_error(c);
390 if (NT_STATUS_V(nterr) != NT_STATUS_V(status)) {
391 printf("unexpected error code %s\n", nt_errstr(status));
392 printf(" expected %s (line=%d)\n", nt_errstr(nterr), line);
401 static bool wait_lock(struct cli_state *c, int fnum, uint32 offset, uint32 len)
403 while (!cli_lock(c, fnum, offset, len, -1, WRITE_LOCK)) {
404 if (!check_error(__LINE__, c, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
410 static bool rw_torture(struct cli_state *c)
412 const char *lockfname = "\\torture.lck";
416 pid_t pid2, pid = getpid();
421 memset(buf, '\0', sizeof(buf));
423 fnum2 = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
426 fnum2 = cli_open(c, lockfname, O_RDWR, DENY_NONE);
428 printf("open of %s failed (%s)\n", lockfname, cli_errstr(c));
433 for (i=0;i<torture_numops;i++) {
434 unsigned n = (unsigned)sys_random()%10;
436 printf("%d\r", i); fflush(stdout);
438 slprintf(fname, sizeof(fstring) - 1, "\\torture.%u", n);
440 if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) {
444 fnum = cli_open(c, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL);
446 printf("open failed (%s)\n", cli_errstr(c));
451 if (cli_write(c, fnum, 0, (char *)&pid, 0, sizeof(pid)) != sizeof(pid)) {
452 printf("write failed (%s)\n", cli_errstr(c));
457 if (cli_write(c, fnum, 0, (char *)buf,
458 sizeof(pid)+(j*sizeof(buf)),
459 sizeof(buf)) != sizeof(buf)) {
460 printf("write failed (%s)\n", cli_errstr(c));
467 if (cli_read(c, fnum, (char *)&pid2, 0, sizeof(pid)) != sizeof(pid)) {
468 printf("read failed (%s)\n", cli_errstr(c));
473 printf("data corruption!\n");
477 if (!cli_close(c, fnum)) {
478 printf("close failed (%s)\n", cli_errstr(c));
482 if (!cli_unlink(c, fname)) {
483 printf("unlink failed (%s)\n", cli_errstr(c));
487 if (!cli_unlock(c, fnum2, n*sizeof(int), sizeof(int))) {
488 printf("unlock failed (%s)\n", cli_errstr(c));
494 cli_unlink(c, lockfname);
501 static bool run_torture(int dummy)
503 struct cli_state *cli;
508 cli_sockopt(cli, sockops);
510 ret = rw_torture(cli);
512 if (!torture_close_connection(cli)) {
519 static bool rw_torture3(struct cli_state *c, char *lockfname)
526 unsigned countprev = 0;
531 for (i = 0; i < sizeof(buf); i += sizeof(uint32))
533 SIVAL(buf, i, sys_random());
538 fnum = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
541 printf("first open read/write of %s failed (%s)\n",
542 lockfname, cli_errstr(c));
548 for (i = 0; i < 500 && fnum == -1; i++)
550 fnum = cli_open(c, lockfname, O_RDONLY,
555 printf("second open read-only of %s failed (%s)\n",
556 lockfname, cli_errstr(c));
562 for (count = 0; count < sizeof(buf); count += sent)
564 if (count >= countprev) {
565 printf("%d %8d\r", i, count);
568 countprev += (sizeof(buf) / 20);
573 sent = ((unsigned)sys_random()%(20))+ 1;
574 if (sent > sizeof(buf) - count)
576 sent = sizeof(buf) - count;
579 if (cli_write(c, fnum, 0, buf+count, count, (size_t)sent) != sent) {
580 printf("write failed (%s)\n", cli_errstr(c));
586 sent = cli_read(c, fnum, buf_rd+count, count,
590 printf("read failed offset:%d size:%ld (%s)\n",
591 count, (unsigned long)sizeof(buf)-count,
598 if (memcmp(buf_rd+count, buf+count, sent) != 0)
600 printf("read/write compare failed\n");
601 printf("offset: %d req %ld recvd %ld\n", count, (unsigned long)sizeof(buf)-count, (unsigned long)sent);
610 if (!cli_close(c, fnum)) {
611 printf("close failed (%s)\n", cli_errstr(c));
618 static bool rw_torture2(struct cli_state *c1, struct cli_state *c2)
620 const char *lockfname = "\\torture2.lck";
629 if (!cli_unlink(c1, lockfname)) {
630 printf("unlink failed (%s) (normal, this file should not exist)\n", cli_errstr(c1));
633 fnum1 = cli_open(c1, lockfname, O_RDWR | O_CREAT | O_EXCL,
636 printf("first open read/write of %s failed (%s)\n",
637 lockfname, cli_errstr(c1));
640 fnum2 = cli_open(c2, lockfname, O_RDONLY,
643 printf("second open read-only of %s failed (%s)\n",
644 lockfname, cli_errstr(c2));
645 cli_close(c1, fnum1);
649 for (i=0;i<torture_numops;i++)
651 size_t buf_size = ((unsigned)sys_random()%(sizeof(buf)-1))+ 1;
653 printf("%d\r", i); fflush(stdout);
656 generate_random_buffer((unsigned char *)buf, buf_size);
658 if (cli_write(c1, fnum1, 0, buf, 0, buf_size) != buf_size) {
659 printf("write failed (%s)\n", cli_errstr(c1));
664 if ((bytes_read = cli_read(c2, fnum2, buf_rd, 0, buf_size)) != buf_size) {
665 printf("read failed (%s)\n", cli_errstr(c2));
666 printf("read %d, expected %ld\n", (int)bytes_read,
667 (unsigned long)buf_size);
672 if (memcmp(buf_rd, buf, buf_size) != 0)
674 printf("read/write compare failed\n");
680 if (!cli_close(c2, fnum2)) {
681 printf("close failed (%s)\n", cli_errstr(c2));
684 if (!cli_close(c1, fnum1)) {
685 printf("close failed (%s)\n", cli_errstr(c1));
689 if (!cli_unlink(c1, lockfname)) {
690 printf("unlink failed (%s)\n", cli_errstr(c1));
697 static bool run_readwritetest(int dummy)
699 static struct cli_state *cli1, *cli2;
700 bool test1, test2 = False;
702 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
705 cli_sockopt(cli1, sockops);
706 cli_sockopt(cli2, sockops);
708 printf("starting readwritetest\n");
710 test1 = rw_torture2(cli1, cli2);
711 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1));
714 test2 = rw_torture2(cli1, cli1);
715 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2));
718 if (!torture_close_connection(cli1)) {
722 if (!torture_close_connection(cli2)) {
726 return (test1 && test2);
729 static bool run_readwritemulti(int dummy)
731 struct cli_state *cli;
736 cli_sockopt(cli, sockops);
738 printf("run_readwritemulti: fname %s\n", randomfname);
739 test = rw_torture3(cli, randomfname);
741 if (!torture_close_connection(cli)) {
748 static bool run_readwritelarge(int dummy)
750 static struct cli_state *cli1;
752 const char *lockfname = "\\large.dat";
757 if (!torture_open_connection(&cli1, 0)) {
760 cli_sockopt(cli1, sockops);
761 memset(buf,'\0',sizeof(buf));
763 cli1->max_xmit = 128*1024;
765 printf("starting readwritelarge\n");
767 cli_unlink(cli1, lockfname);
769 fnum1 = cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE);
771 printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(cli1));
775 cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf));
777 if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
778 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
782 if (fsize == sizeof(buf))
783 printf("readwritelarge test 1 succeeded (size = %lx)\n",
784 (unsigned long)fsize);
786 printf("readwritelarge test 1 failed (size = %lx)\n",
787 (unsigned long)fsize);
791 if (!cli_close(cli1, fnum1)) {
792 printf("close failed (%s)\n", cli_errstr(cli1));
796 if (!cli_unlink(cli1, lockfname)) {
797 printf("unlink failed (%s)\n", cli_errstr(cli1));
801 fnum1 = cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE);
803 printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(cli1));
807 cli1->max_xmit = 4*1024;
809 cli_smbwrite(cli1, fnum1, buf, 0, sizeof(buf));
811 if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
812 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
816 if (fsize == sizeof(buf))
817 printf("readwritelarge test 2 succeeded (size = %lx)\n",
818 (unsigned long)fsize);
820 printf("readwritelarge test 2 failed (size = %lx)\n",
821 (unsigned long)fsize);
826 /* ToDo - set allocation. JRA */
827 if(!cli_set_allocation_size(cli1, fnum1, 0)) {
828 printf("set allocation size to zero failed (%s)\n", cli_errstr(&cli1));
831 if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
832 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
836 printf("readwritelarge test 3 (truncate test) succeeded (size = %x)\n", fsize);
839 if (!cli_close(cli1, fnum1)) {
840 printf("close failed (%s)\n", cli_errstr(cli1));
844 if (!torture_close_connection(cli1)) {
853 #define ival(s) strtol(s, NULL, 0)
855 /* run a test that simulates an approximate netbench client load */
856 static bool run_netbench(int client)
858 struct cli_state *cli;
863 const char *params[20];
870 cli_sockopt(cli, sockops);
874 slprintf(cname,sizeof(cname)-1, "client%d", client);
876 f = fopen(client_txt, "r");
883 while (fgets(line, sizeof(line)-1, f)) {
887 line[strlen(line)-1] = 0;
889 /* printf("[%d] %s\n", line_count, line); */
891 all_string_sub(line,"client1", cname, sizeof(line));
893 /* parse the command parameters */
894 params[0] = strtok_r(line, " ", &saveptr);
896 while (params[i]) params[++i] = strtok_r(NULL, " ", &saveptr);
902 if (!strncmp(params[0],"SMB", 3)) {
903 printf("ERROR: You are using a dbench 1 load file\n");
907 if (!strcmp(params[0],"NTCreateX")) {
908 nb_createx(params[1], ival(params[2]), ival(params[3]),
910 } else if (!strcmp(params[0],"Close")) {
911 nb_close(ival(params[1]));
912 } else if (!strcmp(params[0],"Rename")) {
913 nb_rename(params[1], params[2]);
914 } else if (!strcmp(params[0],"Unlink")) {
915 nb_unlink(params[1]);
916 } else if (!strcmp(params[0],"Deltree")) {
917 nb_deltree(params[1]);
918 } else if (!strcmp(params[0],"Rmdir")) {
920 } else if (!strcmp(params[0],"QUERY_PATH_INFORMATION")) {
921 nb_qpathinfo(params[1]);
922 } else if (!strcmp(params[0],"QUERY_FILE_INFORMATION")) {
923 nb_qfileinfo(ival(params[1]));
924 } else if (!strcmp(params[0],"QUERY_FS_INFORMATION")) {
925 nb_qfsinfo(ival(params[1]));
926 } else if (!strcmp(params[0],"FIND_FIRST")) {
927 nb_findfirst(params[1]);
928 } else if (!strcmp(params[0],"WriteX")) {
929 nb_writex(ival(params[1]),
930 ival(params[2]), ival(params[3]), ival(params[4]));
931 } else if (!strcmp(params[0],"ReadX")) {
932 nb_readx(ival(params[1]),
933 ival(params[2]), ival(params[3]), ival(params[4]));
934 } else if (!strcmp(params[0],"Flush")) {
935 nb_flush(ival(params[1]));
937 printf("Unknown operation %s\n", params[0]);
945 if (!torture_close_connection(cli)) {
953 /* run a test that simulates an approximate netbench client load */
954 static bool run_nbench(int dummy)
963 signal(SIGALRM, nb_alarm);
965 t = create_procs(run_netbench, &correct);
968 printf("\nThroughput %g MB/sec\n",
969 1.0e-6 * nbio_total() / t);
975 This test checks for two things:
977 1) correct support for retaining locks over a close (ie. the server
978 must not use posix semantics)
979 2) support for lock timeouts
981 static bool run_locktest1(int dummy)
983 struct cli_state *cli1, *cli2;
984 const char *fname = "\\lockt1.lck";
985 int fnum1, fnum2, fnum3;
987 unsigned lock_timeout;
989 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
992 cli_sockopt(cli1, sockops);
993 cli_sockopt(cli2, sockops);
995 printf("starting locktest1\n");
997 cli_unlink(cli1, fname);
999 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1001 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
1004 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1006 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli1));
1009 fnum3 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1011 printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli2));
1015 if (!cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
1016 printf("lock1 failed (%s)\n", cli_errstr(cli1));
1021 if (cli_lock(cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
1022 printf("lock2 succeeded! This is a locking bug\n");
1025 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
1026 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1030 lock_timeout = (1 + (random() % 20));
1031 printf("Testing lock timeout with timeout=%u\n", lock_timeout);
1033 if (cli_lock(cli2, fnum3, 0, 4, lock_timeout * 1000, WRITE_LOCK)) {
1034 printf("lock3 succeeded! This is a locking bug\n");
1037 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
1038 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
1042 if (ABS(t2 - t1) < lock_timeout-1) {
1043 printf("error: This server appears not to support timed lock requests\n");
1046 printf("server slept for %u seconds for a %u second timeout\n",
1047 (unsigned int)(t2-t1), lock_timeout);
1049 if (!cli_close(cli1, fnum2)) {
1050 printf("close1 failed (%s)\n", cli_errstr(cli1));
1054 if (cli_lock(cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
1055 printf("lock4 succeeded! This is a locking bug\n");
1058 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
1059 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
1062 if (!cli_close(cli1, fnum1)) {
1063 printf("close2 failed (%s)\n", cli_errstr(cli1));
1067 if (!cli_close(cli2, fnum3)) {
1068 printf("close3 failed (%s)\n", cli_errstr(cli2));
1072 if (!cli_unlink(cli1, fname)) {
1073 printf("unlink failed (%s)\n", cli_errstr(cli1));
1078 if (!torture_close_connection(cli1)) {
1082 if (!torture_close_connection(cli2)) {
1086 printf("Passed locktest1\n");
1091 this checks to see if a secondary tconx can use open files from an
1094 static bool run_tcon_test(int dummy)
1096 static struct cli_state *cli;
1097 const char *fname = "\\tcontest.tmp";
1099 uint16 cnum1, cnum2, cnum3;
1100 uint16 vuid1, vuid2;
1104 memset(buf, '\0', sizeof(buf));
1106 if (!torture_open_connection(&cli, 0)) {
1109 cli_sockopt(cli, sockops);
1111 printf("starting tcontest\n");
1113 cli_unlink(cli, fname);
1115 fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1117 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
1124 if (cli_write(cli, fnum1, 0, buf, 130, 4) != 4) {
1125 printf("initial write failed (%s)", cli_errstr(cli));
1129 if (!cli_send_tconX(cli, share, "?????",
1130 password, strlen(password)+1)) {
1131 printf("%s refused 2nd tree connect (%s)\n", host,
1138 cnum3 = MAX(cnum1, cnum2) + 1; /* any invalid number */
1139 vuid2 = cli->vuid + 1;
1141 /* try a write with the wrong tid */
1144 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
1145 printf("* server allows write with wrong TID\n");
1148 printf("server fails write with wrong TID : %s\n", cli_errstr(cli));
1152 /* try a write with an invalid tid */
1155 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
1156 printf("* server allows write with invalid TID\n");
1159 printf("server fails write with invalid TID : %s\n", cli_errstr(cli));
1162 /* try a write with an invalid vuid */
1166 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
1167 printf("* server allows write with invalid VUID\n");
1170 printf("server fails write with invalid VUID : %s\n", cli_errstr(cli));
1176 if (!cli_close(cli, fnum1)) {
1177 printf("close failed (%s)\n", cli_errstr(cli));
1183 if (!cli_tdis(cli)) {
1184 printf("secondary tdis failed (%s)\n", cli_errstr(cli));
1190 if (!torture_close_connection(cli)) {
1199 checks for old style tcon support
1201 static bool run_tcon2_test(int dummy)
1203 static struct cli_state *cli;
1204 uint16 cnum, max_xmit;
1208 if (!torture_open_connection(&cli, 0)) {
1211 cli_sockopt(cli, sockops);
1213 printf("starting tcon2 test\n");
1215 asprintf(&service, "\\\\%s\\%s", host, share);
1217 status = cli_raw_tcon(cli, service, password, "?????", &max_xmit, &cnum);
1219 if (!NT_STATUS_IS_OK(status)) {
1220 printf("tcon2 failed : %s\n", cli_errstr(cli));
1222 printf("tcon OK : max_xmit=%d cnum=%d tid=%d\n",
1223 (int)max_xmit, (int)cnum, SVAL(cli->inbuf, smb_tid));
1226 if (!torture_close_connection(cli)) {
1230 printf("Passed tcon2 test\n");
1234 static bool tcon_devtest(struct cli_state *cli,
1235 const char *myshare, const char *devtype,
1236 const char *return_devtype,
1237 NTSTATUS expected_error)
1242 status = cli_send_tconX(cli, myshare, devtype,
1243 password, strlen(password)+1);
1245 if (NT_STATUS_IS_OK(expected_error)) {
1247 if (strcmp(cli->dev, return_devtype) == 0) {
1250 printf("tconX to share %s with type %s "
1251 "succeeded but returned the wrong "
1252 "device type (got [%s] but should have got [%s])\n",
1253 myshare, devtype, cli->dev, return_devtype);
1257 printf("tconX to share %s with type %s "
1258 "should have succeeded but failed\n",
1265 printf("tconx to share %s with type %s "
1266 "should have failed but succeeded\n",
1270 if (NT_STATUS_EQUAL(cli_nt_error(cli),
1274 printf("Returned unexpected error\n");
1283 checks for correct tconX support
1285 static bool run_tcon_devtype_test(int dummy)
1287 static struct cli_state *cli1 = NULL;
1293 status = cli_full_connection(&cli1, myname,
1294 host, NULL, port_to_use,
1296 username, workgroup,
1297 password, flags, Undefined, &retry);
1299 if (!NT_STATUS_IS_OK(status)) {
1300 printf("could not open connection\n");
1304 if (!tcon_devtest(cli1, "IPC$", "A:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1307 if (!tcon_devtest(cli1, "IPC$", "?????", "IPC", NT_STATUS_OK))
1310 if (!tcon_devtest(cli1, "IPC$", "LPT:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1313 if (!tcon_devtest(cli1, "IPC$", "IPC", "IPC", NT_STATUS_OK))
1316 if (!tcon_devtest(cli1, "IPC$", "FOOBA", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1319 if (!tcon_devtest(cli1, share, "A:", "A:", NT_STATUS_OK))
1322 if (!tcon_devtest(cli1, share, "?????", "A:", NT_STATUS_OK))
1325 if (!tcon_devtest(cli1, share, "LPT:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1328 if (!tcon_devtest(cli1, share, "IPC", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1331 if (!tcon_devtest(cli1, share, "FOOBA", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1337 printf("Passed tcondevtest\n");
1344 This test checks that
1346 1) the server supports multiple locking contexts on the one SMB
1347 connection, distinguished by PID.
1349 2) the server correctly fails overlapping locks made by the same PID (this
1350 goes against POSIX behaviour, which is why it is tricky to implement)
1352 3) the server denies unlock requests by an incorrect client PID
1354 static bool run_locktest2(int dummy)
1356 static struct cli_state *cli;
1357 const char *fname = "\\lockt2.lck";
1358 int fnum1, fnum2, fnum3;
1359 bool correct = True;
1361 if (!torture_open_connection(&cli, 0)) {
1365 cli_sockopt(cli, sockops);
1367 printf("starting locktest2\n");
1369 cli_unlink(cli, fname);
1373 fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1375 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
1379 fnum2 = cli_open(cli, fname, O_RDWR, DENY_NONE);
1381 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli));
1387 fnum3 = cli_open(cli, fname, O_RDWR, DENY_NONE);
1389 printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli));
1395 if (!cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
1396 printf("lock1 failed (%s)\n", cli_errstr(cli));
1400 if (cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
1401 printf("WRITE lock1 succeeded! This is a locking bug\n");
1404 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1405 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1408 if (cli_lock(cli, fnum2, 0, 4, 0, WRITE_LOCK)) {
1409 printf("WRITE lock2 succeeded! This is a locking bug\n");
1412 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1413 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1416 if (cli_lock(cli, fnum2, 0, 4, 0, READ_LOCK)) {
1417 printf("READ lock2 succeeded! This is a locking bug\n");
1420 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1421 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
1424 if (!cli_lock(cli, fnum1, 100, 4, 0, WRITE_LOCK)) {
1425 printf("lock at 100 failed (%s)\n", cli_errstr(cli));
1428 if (cli_unlock(cli, fnum1, 100, 4)) {
1429 printf("unlock at 100 succeeded! This is a locking bug\n");
1433 if (cli_unlock(cli, fnum1, 0, 4)) {
1434 printf("unlock1 succeeded! This is a locking bug\n");
1437 if (!check_error(__LINE__, cli,
1439 NT_STATUS_RANGE_NOT_LOCKED)) return False;
1442 if (cli_unlock(cli, fnum1, 0, 8)) {
1443 printf("unlock2 succeeded! This is a locking bug\n");
1446 if (!check_error(__LINE__, cli,
1448 NT_STATUS_RANGE_NOT_LOCKED)) return False;
1451 if (cli_lock(cli, fnum3, 0, 4, 0, WRITE_LOCK)) {
1452 printf("lock3 succeeded! This is a locking bug\n");
1455 if (!check_error(__LINE__, cli, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
1460 if (!cli_close(cli, fnum1)) {
1461 printf("close1 failed (%s)\n", cli_errstr(cli));
1465 if (!cli_close(cli, fnum2)) {
1466 printf("close2 failed (%s)\n", cli_errstr(cli));
1470 if (!cli_close(cli, fnum3)) {
1471 printf("close3 failed (%s)\n", cli_errstr(cli));
1475 if (!torture_close_connection(cli)) {
1479 printf("locktest2 finished\n");
1486 This test checks that
1488 1) the server supports the full offset range in lock requests
1490 static bool run_locktest3(int dummy)
1492 static struct cli_state *cli1, *cli2;
1493 const char *fname = "\\lockt3.lck";
1494 int fnum1, fnum2, i;
1496 bool correct = True;
1498 #define NEXT_OFFSET offset += (~(uint32)0) / torture_numops
1500 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1503 cli_sockopt(cli1, sockops);
1504 cli_sockopt(cli2, sockops);
1506 printf("starting locktest3\n");
1508 cli_unlink(cli1, fname);
1510 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1512 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
1515 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1517 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli2));
1521 for (offset=i=0;i<torture_numops;i++) {
1523 if (!cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1524 printf("lock1 %d failed (%s)\n",
1530 if (!cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1531 printf("lock2 %d failed (%s)\n",
1538 for (offset=i=0;i<torture_numops;i++) {
1541 if (cli_lock(cli1, fnum1, offset-2, 1, 0, WRITE_LOCK)) {
1542 printf("error: lock1 %d succeeded!\n", i);
1546 if (cli_lock(cli2, fnum2, offset-1, 1, 0, WRITE_LOCK)) {
1547 printf("error: lock2 %d succeeded!\n", i);
1551 if (cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1552 printf("error: lock3 %d succeeded!\n", i);
1556 if (cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1557 printf("error: lock4 %d succeeded!\n", i);
1562 for (offset=i=0;i<torture_numops;i++) {
1565 if (!cli_unlock(cli1, fnum1, offset-1, 1)) {
1566 printf("unlock1 %d failed (%s)\n",
1572 if (!cli_unlock(cli2, fnum2, offset-2, 1)) {
1573 printf("unlock2 %d failed (%s)\n",
1580 if (!cli_close(cli1, fnum1)) {
1581 printf("close1 failed (%s)\n", cli_errstr(cli1));
1585 if (!cli_close(cli2, fnum2)) {
1586 printf("close2 failed (%s)\n", cli_errstr(cli2));
1590 if (!cli_unlink(cli1, fname)) {
1591 printf("unlink failed (%s)\n", cli_errstr(cli1));
1595 if (!torture_close_connection(cli1)) {
1599 if (!torture_close_connection(cli2)) {
1603 printf("finished locktest3\n");
1608 #define EXPECTED(ret, v) if ((ret) != (v)) { \
1609 printf("** "); correct = False; \
1613 looks at overlapping locks
1615 static bool run_locktest4(int dummy)
1617 static struct cli_state *cli1, *cli2;
1618 const char *fname = "\\lockt4.lck";
1619 int fnum1, fnum2, f;
1622 bool correct = True;
1624 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1628 cli_sockopt(cli1, sockops);
1629 cli_sockopt(cli2, sockops);
1631 printf("starting locktest4\n");
1633 cli_unlink(cli1, fname);
1635 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1636 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1638 memset(buf, 0, sizeof(buf));
1640 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1641 printf("Failed to create file\n");
1646 ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1647 cli_lock(cli1, fnum1, 2, 4, 0, WRITE_LOCK);
1648 EXPECTED(ret, False);
1649 printf("the same process %s set overlapping write locks\n", ret?"can":"cannot");
1651 ret = cli_lock(cli1, fnum1, 10, 4, 0, READ_LOCK) &&
1652 cli_lock(cli1, fnum1, 12, 4, 0, READ_LOCK);
1653 EXPECTED(ret, True);
1654 printf("the same process %s set overlapping read locks\n", ret?"can":"cannot");
1656 ret = cli_lock(cli1, fnum1, 20, 4, 0, WRITE_LOCK) &&
1657 cli_lock(cli2, fnum2, 22, 4, 0, WRITE_LOCK);
1658 EXPECTED(ret, False);
1659 printf("a different connection %s set overlapping write locks\n", ret?"can":"cannot");
1661 ret = cli_lock(cli1, fnum1, 30, 4, 0, READ_LOCK) &&
1662 cli_lock(cli2, fnum2, 32, 4, 0, READ_LOCK);
1663 EXPECTED(ret, True);
1664 printf("a different connection %s set overlapping read locks\n", ret?"can":"cannot");
1666 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 40, 4, 0, WRITE_LOCK)) &&
1667 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 42, 4, 0, WRITE_LOCK));
1668 EXPECTED(ret, False);
1669 printf("a different pid %s set overlapping write locks\n", ret?"can":"cannot");
1671 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 50, 4, 0, READ_LOCK)) &&
1672 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 52, 4, 0, READ_LOCK));
1673 EXPECTED(ret, True);
1674 printf("a different pid %s set overlapping read locks\n", ret?"can":"cannot");
1676 ret = cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK) &&
1677 cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK);
1678 EXPECTED(ret, True);
1679 printf("the same process %s set the same read lock twice\n", ret?"can":"cannot");
1681 ret = cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK) &&
1682 cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK);
1683 EXPECTED(ret, False);
1684 printf("the same process %s set the same write lock twice\n", ret?"can":"cannot");
1686 ret = cli_lock(cli1, fnum1, 80, 4, 0, READ_LOCK) &&
1687 cli_lock(cli1, fnum1, 80, 4, 0, WRITE_LOCK);
1688 EXPECTED(ret, False);
1689 printf("the same process %s overlay a read lock with a write lock\n", ret?"can":"cannot");
1691 ret = cli_lock(cli1, fnum1, 90, 4, 0, WRITE_LOCK) &&
1692 cli_lock(cli1, fnum1, 90, 4, 0, READ_LOCK);
1693 EXPECTED(ret, True);
1694 printf("the same process %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1696 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 100, 4, 0, WRITE_LOCK)) &&
1697 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 100, 4, 0, READ_LOCK));
1698 EXPECTED(ret, False);
1699 printf("a different pid %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1701 ret = cli_lock(cli1, fnum1, 110, 4, 0, READ_LOCK) &&
1702 cli_lock(cli1, fnum1, 112, 4, 0, READ_LOCK) &&
1703 cli_unlock(cli1, fnum1, 110, 6);
1704 EXPECTED(ret, False);
1705 printf("the same process %s coalesce read locks\n", ret?"can":"cannot");
1708 ret = cli_lock(cli1, fnum1, 120, 4, 0, WRITE_LOCK) &&
1709 (cli_read(cli2, fnum2, buf, 120, 4) == 4);
1710 EXPECTED(ret, False);
1711 printf("this server %s strict write locking\n", ret?"doesn't do":"does");
1713 ret = cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK) &&
1714 (cli_write(cli2, fnum2, 0, buf, 130, 4) == 4);
1715 EXPECTED(ret, False);
1716 printf("this server %s strict read locking\n", ret?"doesn't do":"does");
1719 ret = cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1720 cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1721 cli_unlock(cli1, fnum1, 140, 4) &&
1722 cli_unlock(cli1, fnum1, 140, 4);
1723 EXPECTED(ret, True);
1724 printf("this server %s do recursive read locking\n", ret?"does":"doesn't");
1727 ret = cli_lock(cli1, fnum1, 150, 4, 0, WRITE_LOCK) &&
1728 cli_lock(cli1, fnum1, 150, 4, 0, READ_LOCK) &&
1729 cli_unlock(cli1, fnum1, 150, 4) &&
1730 (cli_read(cli2, fnum2, buf, 150, 4) == 4) &&
1731 !(cli_write(cli2, fnum2, 0, buf, 150, 4) == 4) &&
1732 cli_unlock(cli1, fnum1, 150, 4);
1733 EXPECTED(ret, True);
1734 printf("this server %s do recursive lock overlays\n", ret?"does":"doesn't");
1736 ret = cli_lock(cli1, fnum1, 160, 4, 0, READ_LOCK) &&
1737 cli_unlock(cli1, fnum1, 160, 4) &&
1738 (cli_write(cli2, fnum2, 0, buf, 160, 4) == 4) &&
1739 (cli_read(cli2, fnum2, buf, 160, 4) == 4);
1740 EXPECTED(ret, True);
1741 printf("the same process %s remove a read lock using write locking\n", ret?"can":"cannot");
1743 ret = cli_lock(cli1, fnum1, 170, 4, 0, WRITE_LOCK) &&
1744 cli_unlock(cli1, fnum1, 170, 4) &&
1745 (cli_write(cli2, fnum2, 0, buf, 170, 4) == 4) &&
1746 (cli_read(cli2, fnum2, buf, 170, 4) == 4);
1747 EXPECTED(ret, True);
1748 printf("the same process %s remove a write lock using read locking\n", ret?"can":"cannot");
1750 ret = cli_lock(cli1, fnum1, 190, 4, 0, WRITE_LOCK) &&
1751 cli_lock(cli1, fnum1, 190, 4, 0, READ_LOCK) &&
1752 cli_unlock(cli1, fnum1, 190, 4) &&
1753 !(cli_write(cli2, fnum2, 0, buf, 190, 4) == 4) &&
1754 (cli_read(cli2, fnum2, buf, 190, 4) == 4);
1755 EXPECTED(ret, True);
1756 printf("the same process %s remove the first lock first\n", ret?"does":"doesn't");
1758 cli_close(cli1, fnum1);
1759 cli_close(cli2, fnum2);
1760 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1761 f = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1762 ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1763 cli_lock(cli1, f, 0, 1, 0, READ_LOCK) &&
1764 cli_close(cli1, fnum1) &&
1765 ((fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE)) != -1) &&
1766 cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1768 cli_close(cli1, fnum1);
1769 EXPECTED(ret, True);
1770 printf("the server %s have the NT byte range lock bug\n", !ret?"does":"doesn't");
1773 cli_close(cli1, fnum1);
1774 cli_close(cli2, fnum2);
1775 cli_unlink(cli1, fname);
1776 torture_close_connection(cli1);
1777 torture_close_connection(cli2);
1779 printf("finished locktest4\n");
1784 looks at lock upgrade/downgrade.
1786 static bool run_locktest5(int dummy)
1788 static struct cli_state *cli1, *cli2;
1789 const char *fname = "\\lockt5.lck";
1790 int fnum1, fnum2, fnum3;
1793 bool correct = True;
1795 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1799 cli_sockopt(cli1, sockops);
1800 cli_sockopt(cli2, sockops);
1802 printf("starting locktest5\n");
1804 cli_unlink(cli1, fname);
1806 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1807 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1808 fnum3 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1810 memset(buf, 0, sizeof(buf));
1812 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1813 printf("Failed to create file\n");
1818 /* Check for NT bug... */
1819 ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1820 cli_lock(cli1, fnum3, 0, 1, 0, READ_LOCK);
1821 cli_close(cli1, fnum1);
1822 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1823 ret = cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1824 EXPECTED(ret, True);
1825 printf("this server %s the NT locking bug\n", ret ? "doesn't have" : "has");
1826 cli_close(cli1, fnum1);
1827 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1828 cli_unlock(cli1, fnum3, 0, 1);
1830 ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1831 cli_lock(cli1, fnum1, 1, 1, 0, READ_LOCK);
1832 EXPECTED(ret, True);
1833 printf("the same process %s overlay a write with a read lock\n", ret?"can":"cannot");
1835 ret = cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK);
1836 EXPECTED(ret, False);
1838 printf("a different processs %s get a read lock on the first process lock stack\n", ret?"can":"cannot");
1840 /* Unlock the process 2 lock. */
1841 cli_unlock(cli2, fnum2, 0, 4);
1843 ret = cli_lock(cli1, fnum3, 0, 4, 0, READ_LOCK);
1844 EXPECTED(ret, False);
1846 printf("the same processs on a different fnum %s get a read lock\n", ret?"can":"cannot");
1848 /* Unlock the process 1 fnum3 lock. */
1849 cli_unlock(cli1, fnum3, 0, 4);
1851 /* Stack 2 more locks here. */
1852 ret = cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK) &&
1853 cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK);
1855 EXPECTED(ret, True);
1856 printf("the same process %s stack read locks\n", ret?"can":"cannot");
1858 /* Unlock the first process lock, then check this was the WRITE lock that was
1861 ret = cli_unlock(cli1, fnum1, 0, 4) &&
1862 cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK);
1864 EXPECTED(ret, True);
1865 printf("the first unlock removes the %s lock\n", ret?"WRITE":"READ");
1867 /* Unlock the process 2 lock. */
1868 cli_unlock(cli2, fnum2, 0, 4);
1870 /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */
1872 ret = cli_unlock(cli1, fnum1, 1, 1) &&
1873 cli_unlock(cli1, fnum1, 0, 4) &&
1874 cli_unlock(cli1, fnum1, 0, 4);
1876 EXPECTED(ret, True);
1877 printf("the same process %s unlock the stack of 4 locks\n", ret?"can":"cannot");
1879 /* Ensure the next unlock fails. */
1880 ret = cli_unlock(cli1, fnum1, 0, 4);
1881 EXPECTED(ret, False);
1882 printf("the same process %s count the lock stack\n", !ret?"can":"cannot");
1884 /* Ensure connection 2 can get a write lock. */
1885 ret = cli_lock(cli2, fnum2, 0, 4, 0, WRITE_LOCK);
1886 EXPECTED(ret, True);
1888 printf("a different processs %s get a write lock on the unlocked stack\n", ret?"can":"cannot");
1892 cli_close(cli1, fnum1);
1893 cli_close(cli2, fnum2);
1894 cli_unlink(cli1, fname);
1895 if (!torture_close_connection(cli1)) {
1898 if (!torture_close_connection(cli2)) {
1902 printf("finished locktest5\n");
1908 tries the unusual lockingX locktype bits
1910 static bool run_locktest6(int dummy)
1912 static struct cli_state *cli;
1913 const char *fname[1] = { "\\lock6.txt" };
1918 if (!torture_open_connection(&cli, 0)) {
1922 cli_sockopt(cli, sockops);
1924 printf("starting locktest6\n");
1927 printf("Testing %s\n", fname[i]);
1929 cli_unlink(cli, fname[i]);
1931 fnum = cli_open(cli, fname[i], O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1932 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE);
1933 cli_close(cli, fnum);
1934 printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status));
1936 fnum = cli_open(cli, fname[i], O_RDWR, DENY_NONE);
1937 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK);
1938 cli_close(cli, fnum);
1939 printf("CANCEL_LOCK gave %s\n", nt_errstr(status));
1941 cli_unlink(cli, fname[i]);
1944 torture_close_connection(cli);
1946 printf("finished locktest6\n");
1950 static bool run_locktest7(int dummy)
1952 struct cli_state *cli1;
1953 const char *fname = "\\lockt7.lck";
1956 bool correct = False;
1958 if (!torture_open_connection(&cli1, 0)) {
1962 cli_sockopt(cli1, sockops);
1964 printf("starting locktest7\n");
1966 cli_unlink(cli1, fname);
1968 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1970 memset(buf, 0, sizeof(buf));
1972 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1973 printf("Failed to create file\n");
1977 cli_setpid(cli1, 1);
1979 if (!cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK)) {
1980 printf("Unable to apply read lock on range 130:4, error was %s\n", cli_errstr(cli1));
1983 printf("pid1 successfully locked range 130:4 for READ\n");
1986 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1987 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1990 printf("pid1 successfully read the range 130:4\n");
1993 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1994 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1995 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1996 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2000 printf("pid1 successfully wrote to the range 130:4 (should be denied)\n");
2004 cli_setpid(cli1, 2);
2006 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
2007 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
2009 printf("pid2 successfully read the range 130:4\n");
2012 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
2013 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
2014 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
2015 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2019 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
2023 cli_setpid(cli1, 1);
2024 cli_unlock(cli1, fnum1, 130, 4);
2026 if (!cli_lock(cli1, fnum1, 130, 4, 0, WRITE_LOCK)) {
2027 printf("Unable to apply write lock on range 130:4, error was %s\n", cli_errstr(cli1));
2030 printf("pid1 successfully locked range 130:4 for WRITE\n");
2033 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
2034 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
2037 printf("pid1 successfully read the range 130:4\n");
2040 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
2041 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
2044 printf("pid1 successfully wrote to the range 130:4\n");
2047 cli_setpid(cli1, 2);
2049 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
2050 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
2051 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
2052 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2056 printf("pid2 successfully read the range 130:4 (should be denied)\n");
2060 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
2061 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
2062 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
2063 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2067 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
2071 cli_unlock(cli1, fnum1, 130, 0);
2075 cli_close(cli1, fnum1);
2076 cli_unlink(cli1, fname);
2077 torture_close_connection(cli1);
2079 printf("finished locktest7\n");
2084 test whether fnums and tids open on one VC are available on another (a major
2087 static bool run_fdpasstest(int dummy)
2089 struct cli_state *cli1, *cli2;
2090 const char *fname = "\\fdpass.tst";
2094 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
2097 cli_sockopt(cli1, sockops);
2098 cli_sockopt(cli2, sockops);
2100 printf("starting fdpasstest\n");
2102 cli_unlink(cli1, fname);
2104 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2106 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2110 if (cli_write(cli1, fnum1, 0, "hello world\n", 0, 13) != 13) {
2111 printf("write failed (%s)\n", cli_errstr(cli1));
2115 cli2->vuid = cli1->vuid;
2116 cli2->cnum = cli1->cnum;
2117 cli2->pid = cli1->pid;
2119 if (cli_read(cli2, fnum1, buf, 0, 13) == 13) {
2120 printf("read succeeded! nasty security hole [%s]\n",
2125 cli_close(cli1, fnum1);
2126 cli_unlink(cli1, fname);
2128 torture_close_connection(cli1);
2129 torture_close_connection(cli2);
2131 printf("finished fdpasstest\n");
2135 static bool run_fdsesstest(int dummy)
2137 struct cli_state *cli;
2142 const char *fname = "\\fdsess.tst";
2143 const char *fname1 = "\\fdsess1.tst";
2149 if (!torture_open_connection(&cli, 0))
2151 cli_sockopt(cli, sockops);
2153 if (!torture_cli_session_setup2(cli, &new_vuid))
2156 saved_cnum = cli->cnum;
2157 if (!cli_send_tconX(cli, share, "?????", "", 1))
2159 new_cnum = cli->cnum;
2160 cli->cnum = saved_cnum;
2162 printf("starting fdsesstest\n");
2164 cli_unlink(cli, fname);
2165 cli_unlink(cli, fname1);
2167 fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2169 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
2173 if (cli_write(cli, fnum1, 0, "hello world\n", 0, 13) != 13) {
2174 printf("write failed (%s)\n", cli_errstr(cli));
2178 saved_vuid = cli->vuid;
2179 cli->vuid = new_vuid;
2181 if (cli_read(cli, fnum1, buf, 0, 13) == 13) {
2182 printf("read succeeded with different vuid! nasty security hole [%s]\n",
2186 /* Try to open a file with different vuid, samba cnum. */
2187 fnum2 = cli_open(cli, fname1, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2189 printf("create with different vuid, same cnum succeeded.\n");
2190 cli_close(cli, fnum2);
2191 cli_unlink(cli, fname1);
2193 printf("create with different vuid, same cnum failed.\n");
2194 printf("This will cause problems with service clients.\n");
2198 cli->vuid = saved_vuid;
2200 /* Try with same vuid, different cnum. */
2201 cli->cnum = new_cnum;
2203 if (cli_read(cli, fnum1, buf, 0, 13) == 13) {
2204 printf("read succeeded with different cnum![%s]\n",
2209 cli->cnum = saved_cnum;
2210 cli_close(cli, fnum1);
2211 cli_unlink(cli, fname);
2213 torture_close_connection(cli);
2215 printf("finished fdsesstest\n");
2220 This test checks that
2222 1) the server does not allow an unlink on a file that is open
2224 static bool run_unlinktest(int dummy)
2226 struct cli_state *cli;
2227 const char *fname = "\\unlink.tst";
2229 bool correct = True;
2231 if (!torture_open_connection(&cli, 0)) {
2235 cli_sockopt(cli, sockops);
2237 printf("starting unlink test\n");
2239 cli_unlink(cli, fname);
2243 fnum = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2245 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
2249 if (cli_unlink(cli, fname)) {
2250 printf("error: server allowed unlink on an open file\n");
2253 correct = check_error(__LINE__, cli, ERRDOS, ERRbadshare,
2254 NT_STATUS_SHARING_VIOLATION);
2257 cli_close(cli, fnum);
2258 cli_unlink(cli, fname);
2260 if (!torture_close_connection(cli)) {
2264 printf("unlink test finished\n");
2271 test how many open files this server supports on the one socket
2273 static bool run_maxfidtest(int dummy)
2275 struct cli_state *cli;
2276 const char *ftemplate = "\\maxfid.%d.%d";
2278 int fnums[0x11000], i;
2280 bool correct = True;
2285 printf("failed to connect\n");
2289 cli_sockopt(cli, sockops);
2291 for (i=0; i<0x11000; i++) {
2292 slprintf(fname,sizeof(fname)-1,ftemplate, i,(int)getpid());
2293 if ((fnums[i] = cli_open(cli, fname,
2294 O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) ==
2296 printf("open of %s failed (%s)\n",
2297 fname, cli_errstr(cli));
2298 printf("maximum fnum is %d\n", i);
2306 printf("cleaning up\n");
2308 slprintf(fname,sizeof(fname)-1,ftemplate, i,(int)getpid());
2309 cli_close(cli, fnums[i]);
2310 if (!cli_unlink(cli, fname)) {
2311 printf("unlink of %s failed (%s)\n",
2312 fname, cli_errstr(cli));
2319 printf("maxfid test finished\n");
2320 if (!torture_close_connection(cli)) {
2326 /* generate a random buffer */
2327 static void rand_buf(char *buf, int len)
2330 *buf = (char)sys_random();
2335 /* send smb negprot commands, not reading the response */
2336 static bool run_negprot_nowait(int dummy)
2339 static struct cli_state *cli;
2340 bool correct = True;
2342 printf("starting negprot nowait test\n");
2344 if (!(cli = open_nbt_connection())) {
2348 for (i=0;i<50000;i++) {
2349 cli_negprot_send(cli);
2352 if (!torture_close_connection(cli)) {
2356 printf("finished negprot nowait test\n");
2362 /* send random IPC commands */
2363 static bool run_randomipc(int dummy)
2365 char *rparam = NULL;
2367 unsigned int rdrcnt,rprcnt;
2369 int api, param_len, i;
2370 struct cli_state *cli;
2371 bool correct = True;
2374 printf("starting random ipc test\n");
2376 if (!torture_open_connection(&cli, 0)) {
2380 for (i=0;i<count;i++) {
2381 api = sys_random() % 500;
2382 param_len = (sys_random() % 64);
2384 rand_buf(param, param_len);
2389 param, param_len, 8,
2390 NULL, 0, BUFFER_SIZE,
2394 printf("%d/%d\r", i,count);
2397 printf("%d/%d\n", i, count);
2399 if (!torture_close_connection(cli)) {
2403 printf("finished random ipc test\n");
2410 static void browse_callback(const char *sname, uint32 stype,
2411 const char *comment, void *state)
2413 printf("\t%20.20s %08x %s\n", sname, stype, comment);
2419 This test checks the browse list code
2422 static bool run_browsetest(int dummy)
2424 static struct cli_state *cli;
2425 bool correct = True;
2427 printf("starting browse test\n");
2429 if (!torture_open_connection(&cli, 0)) {
2433 printf("domain list:\n");
2434 cli_NetServerEnum(cli, cli->server_domain,
2435 SV_TYPE_DOMAIN_ENUM,
2436 browse_callback, NULL);
2438 printf("machine list:\n");
2439 cli_NetServerEnum(cli, cli->server_domain,
2441 browse_callback, NULL);
2443 if (!torture_close_connection(cli)) {
2447 printf("browse test finished\n");
2455 This checks how the getatr calls works
2457 static bool run_attrtest(int dummy)
2459 struct cli_state *cli;
2462 const char *fname = "\\attrib123456789.tst";
2463 bool correct = True;
2465 printf("starting attrib test\n");
2467 if (!torture_open_connection(&cli, 0)) {
2471 cli_unlink(cli, fname);
2472 fnum = cli_open(cli, fname,
2473 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2474 cli_close(cli, fnum);
2475 if (!cli_getatr(cli, fname, NULL, NULL, &t)) {
2476 printf("getatr failed (%s)\n", cli_errstr(cli));
2480 if (abs(t - time(NULL)) > 60*60*24*10) {
2481 printf("ERROR: SMBgetatr bug. time is %s",
2487 t2 = t-60*60*24; /* 1 day ago */
2489 if (!cli_setatr(cli, fname, 0, t2)) {
2490 printf("setatr failed (%s)\n", cli_errstr(cli));
2494 if (!cli_getatr(cli, fname, NULL, NULL, &t)) {
2495 printf("getatr failed (%s)\n", cli_errstr(cli));
2500 printf("ERROR: getatr/setatr bug. times are\n%s",
2502 printf("%s", ctime(&t2));
2506 cli_unlink(cli, fname);
2508 if (!torture_close_connection(cli)) {
2512 printf("attrib test finished\n");
2519 This checks a couple of trans2 calls
2521 static bool run_trans2test(int dummy)
2523 struct cli_state *cli;
2526 time_t c_time, a_time, m_time;
2527 struct timespec c_time_ts, a_time_ts, m_time_ts, w_time_ts, m_time2_ts;
2528 const char *fname = "\\trans2.tst";
2529 const char *dname = "\\trans2";
2530 const char *fname2 = "\\trans2\\trans2.tst";
2532 bool correct = True;
2534 printf("starting trans2 test\n");
2536 if (!torture_open_connection(&cli, 0)) {
2540 cli_unlink(cli, fname);
2541 fnum = cli_open(cli, fname,
2542 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2543 if (!cli_qfileinfo(cli, fnum, NULL, &size, &c_time_ts, &a_time_ts, &w_time_ts,
2544 &m_time_ts, NULL)) {
2545 printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(cli));
2549 if (!cli_qfilename(cli, fnum, pname, sizeof(pname))) {
2550 printf("ERROR: qfilename failed (%s)\n", cli_errstr(cli));
2554 if (strcmp(pname, fname)) {
2555 printf("qfilename gave different name? [%s] [%s]\n",
2560 cli_close(cli, fnum);
2564 cli_unlink(cli, fname);
2565 fnum = cli_open(cli, fname,
2566 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2568 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
2571 cli_close(cli, fnum);
2573 if (!cli_qpathinfo(cli, fname, &c_time, &a_time, &m_time, &size, NULL)) {
2574 printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(cli));
2577 if (c_time != m_time) {
2578 printf("create time=%s", ctime(&c_time));
2579 printf("modify time=%s", ctime(&m_time));
2580 printf("This system appears to have sticky create times\n");
2582 if (a_time % (60*60) == 0) {
2583 printf("access time=%s", ctime(&a_time));
2584 printf("This system appears to set a midnight access time\n");
2588 if (abs(m_time - time(NULL)) > 60*60*24*7) {
2589 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
2595 cli_unlink(cli, fname);
2596 fnum = cli_open(cli, fname,
2597 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2598 cli_close(cli, fnum);
2599 if (!cli_qpathinfo2(cli, fname, &c_time_ts, &a_time_ts, &w_time_ts,
2600 &m_time_ts, &size, NULL, NULL)) {
2601 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2604 if (w_time_ts.tv_sec < 60*60*24*2) {
2605 printf("write time=%s", ctime(&w_time_ts.tv_sec));
2606 printf("This system appears to set a initial 0 write time\n");
2611 cli_unlink(cli, fname);
2614 /* check if the server updates the directory modification time
2615 when creating a new file */
2616 if (!cli_mkdir(cli, dname)) {
2617 printf("ERROR: mkdir failed (%s)\n", cli_errstr(cli));
2621 if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts, &w_time_ts,
2622 &m_time_ts, &size, NULL, NULL)) {
2623 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2627 fnum = cli_open(cli, fname2,
2628 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2629 cli_write(cli, fnum, 0, (char *)&fnum, 0, sizeof(fnum));
2630 cli_close(cli, fnum);
2631 if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts, &w_time_ts,
2632 &m_time2_ts, &size, NULL, NULL)) {
2633 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2636 if (memcmp(&m_time_ts, &m_time2_ts, sizeof(struct timespec))
2638 printf("This system does not update directory modification times\n");
2642 cli_unlink(cli, fname2);
2643 cli_rmdir(cli, dname);
2645 if (!torture_close_connection(cli)) {
2649 printf("trans2 test finished\n");
2655 This checks new W2K calls.
2658 static bool new_trans(struct cli_state *pcli, int fnum, int level)
2662 bool correct = True;
2664 if (!cli_qfileinfo_test(pcli, fnum, level, &buf, &len)) {
2665 printf("ERROR: qfileinfo (%d) failed (%s)\n", level, cli_errstr(pcli));
2668 printf("qfileinfo: level %d, len = %u\n", level, len);
2669 dump_data(0, (uint8 *)buf, len);
2676 static bool run_w2ktest(int dummy)
2678 struct cli_state *cli;
2680 const char *fname = "\\w2ktest\\w2k.tst";
2682 bool correct = True;
2684 printf("starting w2k test\n");
2686 if (!torture_open_connection(&cli, 0)) {
2690 fnum = cli_open(cli, fname,
2691 O_RDWR | O_CREAT , DENY_NONE);
2693 for (level = 1004; level < 1040; level++) {
2694 new_trans(cli, fnum, level);
2697 cli_close(cli, fnum);
2699 if (!torture_close_connection(cli)) {
2703 printf("w2k test finished\n");
2710 this is a harness for some oplock tests
2712 static bool run_oplock1(int dummy)
2714 struct cli_state *cli1;
2715 const char *fname = "\\lockt1.lck";
2717 bool correct = True;
2719 printf("starting oplock test 1\n");
2721 if (!torture_open_connection(&cli1, 0)) {
2725 cli_unlink(cli1, fname);
2727 cli_sockopt(cli1, sockops);
2729 cli1->use_oplocks = True;
2731 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2733 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2737 cli1->use_oplocks = False;
2739 cli_unlink(cli1, fname);
2740 cli_unlink(cli1, fname);
2742 if (!cli_close(cli1, fnum1)) {
2743 printf("close2 failed (%s)\n", cli_errstr(cli1));
2747 if (!cli_unlink(cli1, fname)) {
2748 printf("unlink failed (%s)\n", cli_errstr(cli1));
2752 if (!torture_close_connection(cli1)) {
2756 printf("finished oplock test 1\n");
2761 static bool run_oplock2(int dummy)
2763 struct cli_state *cli1, *cli2;
2764 const char *fname = "\\lockt2.lck";
2766 int saved_use_oplocks = use_oplocks;
2768 bool correct = True;
2769 volatile bool *shared_correct;
2771 shared_correct = (volatile bool *)shm_setup(sizeof(bool));
2772 *shared_correct = True;
2774 use_level_II_oplocks = True;
2777 printf("starting oplock test 2\n");
2779 if (!torture_open_connection(&cli1, 0)) {
2780 use_level_II_oplocks = False;
2781 use_oplocks = saved_use_oplocks;
2785 cli1->use_oplocks = True;
2786 cli1->use_level_II_oplocks = True;
2788 if (!torture_open_connection(&cli2, 1)) {
2789 use_level_II_oplocks = False;
2790 use_oplocks = saved_use_oplocks;
2794 cli2->use_oplocks = True;
2795 cli2->use_level_II_oplocks = True;
2797 cli_unlink(cli1, fname);
2799 cli_sockopt(cli1, sockops);
2800 cli_sockopt(cli2, sockops);
2802 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2804 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2808 /* Don't need the globals any more. */
2809 use_level_II_oplocks = False;
2810 use_oplocks = saved_use_oplocks;
2814 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
2816 printf("second open of %s failed (%s)\n", fname, cli_errstr(cli1));
2817 *shared_correct = False;
2823 if (!cli_close(cli2, fnum2)) {
2824 printf("close2 failed (%s)\n", cli_errstr(cli1));
2825 *shared_correct = False;
2833 /* Ensure cli1 processes the break. Empty file should always return 0
2836 if (cli_read(cli1, fnum1, buf, 0, 4) != 0) {
2837 printf("read on fnum1 failed (%s)\n", cli_errstr(cli1));
2841 /* Should now be at level II. */
2842 /* Test if sending a write locks causes a break to none. */
2844 if (!cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK)) {
2845 printf("lock failed (%s)\n", cli_errstr(cli1));
2849 cli_unlock(cli1, fnum1, 0, 4);
2853 if (!cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
2854 printf("lock failed (%s)\n", cli_errstr(cli1));
2858 cli_unlock(cli1, fnum1, 0, 4);
2862 cli_read(cli1, fnum1, buf, 0, 4);
2865 if (cli_write(cli1, fnum1, 0, buf, 0, 4) != 4) {
2866 printf("write on fnum1 failed (%s)\n", cli_errstr(cli1));
2871 if (!cli_close(cli1, fnum1)) {
2872 printf("close1 failed (%s)\n", cli_errstr(cli1));
2878 if (!cli_unlink(cli1, fname)) {
2879 printf("unlink failed (%s)\n", cli_errstr(cli1));
2883 if (!torture_close_connection(cli1)) {
2887 if (!*shared_correct) {
2891 printf("finished oplock test 2\n");
2896 /* handler for oplock 3 tests */
2897 static bool oplock3_handler(struct cli_state *cli, int fnum, unsigned char level)
2899 printf("got oplock break fnum=%d level=%d\n",
2901 return cli_oplock_ack(cli, fnum, level);
2904 static bool run_oplock3(int dummy)
2906 struct cli_state *cli;
2907 const char *fname = "\\oplockt3.dat";
2909 char buf[4] = "abcd";
2910 bool correct = True;
2911 volatile bool *shared_correct;
2913 shared_correct = (volatile bool *)shm_setup(sizeof(bool));
2914 *shared_correct = True;
2916 printf("starting oplock test 3\n");
2921 use_level_II_oplocks = True;
2922 if (!torture_open_connection(&cli, 0)) {
2923 *shared_correct = False;
2927 /* try to trigger a oplock break in parent */
2928 fnum = cli_open(cli, fname, O_RDWR, DENY_NONE);
2929 cli_write(cli, fnum, 0, buf, 0, 4);
2935 use_level_II_oplocks = True;
2936 if (!torture_open_connection(&cli, 1)) { /* other is forked */
2939 cli_oplock_handler(cli, oplock3_handler);
2940 fnum = cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE);
2941 cli_write(cli, fnum, 0, buf, 0, 4);
2942 cli_close(cli, fnum);
2943 fnum = cli_open(cli, fname, O_RDWR, DENY_NONE);
2944 cli->timeout = 20000;
2945 cli_receive_smb(cli);
2946 printf("finished oplock test 3\n");
2948 return (correct && *shared_correct);
2950 /* What are we looking for here? What's sucess and what's FAILURE? */
2956 Test delete on close semantics.
2958 static bool run_deletetest(int dummy)
2960 struct cli_state *cli1 = NULL;
2961 struct cli_state *cli2 = NULL;
2962 const char *fname = "\\delete.file";
2965 bool correct = True;
2967 printf("starting delete test\n");
2969 if (!torture_open_connection(&cli1, 0)) {
2973 cli_sockopt(cli1, sockops);
2975 /* Test 1 - this should delete the file on close. */
2977 cli_setatr(cli1, fname, 0, 0);
2978 cli_unlink(cli1, fname);
2980 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
2981 0, FILE_OVERWRITE_IF,
2982 FILE_DELETE_ON_CLOSE, 0);
2985 printf("[1] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2992 uint32 *accinfo = NULL;
2994 cli_qfileinfo_test(cli1, fnum1, SMB_FILE_ACCESS_INFORMATION, (char **)&accinfo, &len);
2996 printf("access mode = 0x%lx\n", *accinfo);
3001 if (!cli_close(cli1, fnum1)) {
3002 printf("[1] close failed (%s)\n", cli_errstr(cli1));
3007 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
3009 printf("[1] open of %s succeeded (should fail)\n", fname);
3014 printf("first delete on close test succeeded.\n");
3016 /* Test 2 - this should delete the file on close. */
3018 cli_setatr(cli1, fname, 0, 0);
3019 cli_unlink(cli1, fname);
3021 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_ALL_ACCESS,
3022 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
3023 FILE_OVERWRITE_IF, 0, 0);
3026 printf("[2] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3031 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
3032 printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
3037 if (!cli_close(cli1, fnum1)) {
3038 printf("[2] close failed (%s)\n", cli_errstr(cli1));
3043 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
3045 printf("[2] open of %s succeeded should have been deleted on close !\n", fname);
3046 if (!cli_close(cli1, fnum1)) {
3047 printf("[2] close failed (%s)\n", cli_errstr(cli1));
3051 cli_unlink(cli1, fname);
3053 printf("second delete on close test succeeded.\n");
3056 cli_setatr(cli1, fname, 0, 0);
3057 cli_unlink(cli1, fname);
3059 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
3060 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0);
3063 printf("[3] open - 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3068 /* This should fail with a sharing violation - open for delete is only compatible
3069 with SHARE_DELETE. */
3071 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3072 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0, 0);
3075 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname);
3080 /* This should succeed. */
3082 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3083 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0, 0);
3086 printf("[3] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
3091 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
3092 printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
3097 if (!cli_close(cli1, fnum1)) {
3098 printf("[3] close 1 failed (%s)\n", cli_errstr(cli1));
3103 if (!cli_close(cli1, fnum2)) {
3104 printf("[3] close 2 failed (%s)\n", cli_errstr(cli1));
3109 /* This should fail - file should no longer be there. */
3111 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
3113 printf("[3] open of %s succeeded should have been deleted on close !\n", fname);
3114 if (!cli_close(cli1, fnum1)) {
3115 printf("[3] close failed (%s)\n", cli_errstr(cli1));
3117 cli_unlink(cli1, fname);
3121 printf("third delete on close test succeeded.\n");
3124 cli_setatr(cli1, fname, 0, 0);
3125 cli_unlink(cli1, fname);
3127 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3128 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0);
3131 printf("[4] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3136 /* This should succeed. */
3137 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS,
3138 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0, 0);
3140 printf("[4] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
3145 if (!cli_close(cli1, fnum2)) {
3146 printf("[4] close - 1 failed (%s)\n", cli_errstr(cli1));
3151 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
3152 printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
3157 /* This should fail - no more opens once delete on close set. */
3158 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS,
3159 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3162 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname );
3166 printf("fourth delete on close test succeeded.\n");
3168 if (!cli_close(cli1, fnum1)) {
3169 printf("[4] close - 2 failed (%s)\n", cli_errstr(cli1));
3175 cli_setatr(cli1, fname, 0, 0);
3176 cli_unlink(cli1, fname);
3178 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT, DENY_NONE);
3180 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3185 /* This should fail - only allowed on NT opens with DELETE access. */
3187 if (cli_nt_delete_on_close(cli1, fnum1, True)) {
3188 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
3193 if (!cli_close(cli1, fnum1)) {
3194 printf("[5] close - 2 failed (%s)\n", cli_errstr(cli1));
3199 printf("fifth delete on close test succeeded.\n");
3202 cli_setatr(cli1, fname, 0, 0);
3203 cli_unlink(cli1, fname);
3205 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
3206 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3207 FILE_OVERWRITE_IF, 0, 0);
3210 printf("[6] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3215 /* This should fail - only allowed on NT opens with DELETE access. */
3217 if (cli_nt_delete_on_close(cli1, fnum1, True)) {
3218 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
3223 if (!cli_close(cli1, fnum1)) {
3224 printf("[6] close - 2 failed (%s)\n", cli_errstr(cli1));
3229 printf("sixth delete on close test succeeded.\n");
3232 cli_setatr(cli1, fname, 0, 0);
3233 cli_unlink(cli1, fname);
3235 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3236 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0, 0);
3239 printf("[7] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3244 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
3245 printf("[7] setting delete_on_close on file failed !\n");
3250 if (!cli_nt_delete_on_close(cli1, fnum1, False)) {
3251 printf("[7] unsetting delete_on_close on file failed !\n");
3256 if (!cli_close(cli1, fnum1)) {
3257 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
3262 /* This next open should succeed - we reset the flag. */
3264 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
3266 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3271 if (!cli_close(cli1, fnum1)) {
3272 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
3277 printf("seventh delete on close test succeeded.\n");
3280 cli_setatr(cli1, fname, 0, 0);
3281 cli_unlink(cli1, fname);
3283 if (!torture_open_connection(&cli2, 1)) {
3284 printf("[8] failed to open second connection.\n");
3289 cli_sockopt(cli1, sockops);
3291 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3292 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3293 FILE_OVERWRITE_IF, 0, 0);
3296 printf("[8] open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3301 fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3302 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3306 printf("[8] open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3311 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
3312 printf("[8] setting delete_on_close on file failed !\n");
3317 if (!cli_close(cli1, fnum1)) {
3318 printf("[8] close - 1 failed (%s)\n", cli_errstr(cli1));
3323 if (!cli_close(cli2, fnum2)) {
3324 printf("[8] close - 2 failed (%s)\n", cli_errstr(cli2));
3329 /* This should fail.. */
3330 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
3332 printf("[8] open of %s succeeded should have been deleted on close !\n", fname);
3336 printf("eighth delete on close test succeeded.\n");
3338 /* This should fail - we need to set DELETE_ACCESS. */
3339 fnum1 = cli_nt_create_full(cli1, fname, 0,FILE_READ_DATA|FILE_WRITE_DATA,
3340 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, 0);
3343 printf("[9] open of %s succeeded should have failed!\n", fname);
3348 printf("ninth delete on close test succeeded.\n");
3350 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3351 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, 0);
3353 printf("[10] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3358 /* This should delete the file. */
3359 if (!cli_close(cli1, fnum1)) {
3360 printf("[10] close failed (%s)\n", cli_errstr(cli1));
3365 /* This should fail.. */
3366 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
3368 printf("[10] open of %s succeeded should have been deleted on close !\n", fname);
3372 printf("tenth delete on close test succeeded.\n");
3374 cli_setatr(cli1, fname, 0, 0);
3375 cli_unlink(cli1, fname);
3377 /* What error do we get when attempting to open a read-only file with
3380 /* Create a readonly file. */
3381 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
3382 FILE_ATTRIBUTE_READONLY, FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3384 printf("[11] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3389 if (!cli_close(cli1, fnum1)) {
3390 printf("[11] close failed (%s)\n", cli_errstr(cli1));
3395 /* Now try open for delete access. */
3396 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_ATTRIBUTES|DELETE_ACCESS,
3397 0, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3398 FILE_OVERWRITE_IF, 0, 0);
3401 printf("[11] open of %s succeeded should have been denied with ACCESS_DENIED!\n", fname);
3402 cli_close(cli1, fnum1);
3406 NTSTATUS nterr = cli_nt_error(cli1);
3407 if (!NT_STATUS_EQUAL(nterr,NT_STATUS_ACCESS_DENIED)) {
3408 printf("[11] open of %s should have been denied with ACCESS_DENIED! Got error %s\n", fname, nt_errstr(nterr));
3412 printf("eleventh delete on close test succeeded.\n");
3416 printf("finished delete test\n");
3419 /* FIXME: This will crash if we aborted before cli2 got
3420 * intialized, because these functions don't handle
3421 * uninitialized connections. */
3423 if (fnum1 != -1) cli_close(cli1, fnum1);
3424 if (fnum2 != -1) cli_close(cli1, fnum2);
3425 cli_setatr(cli1, fname, 0, 0);
3426 cli_unlink(cli1, fname);
3428 if (cli1 && !torture_close_connection(cli1)) {
3431 if (cli2 && !torture_close_connection(cli2)) {
3439 print out server properties
3441 static bool run_properties(int dummy)
3443 static struct cli_state *cli;
3444 bool correct = True;
3446 printf("starting properties test\n");
3450 if (!torture_open_connection(&cli, 0)) {
3454 cli_sockopt(cli, sockops);
3456 d_printf("Capabilities 0x%08x\n", cli->capabilities);
3458 if (!torture_close_connection(cli)) {
3467 /* FIRST_DESIRED_ACCESS 0xf019f */
3468 #define FIRST_DESIRED_ACCESS FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|\
3469 FILE_READ_EA| /* 0xf */ \
3470 FILE_WRITE_EA|FILE_READ_ATTRIBUTES| /* 0x90 */ \
3471 FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
3472 DELETE_ACCESS|READ_CONTROL_ACCESS|\
3473 WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS /* 0xf0000 */
3474 /* SECOND_DESIRED_ACCESS 0xe0080 */
3475 #define SECOND_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
3476 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
3477 WRITE_OWNER_ACCESS /* 0xe0000 */
3480 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
3481 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
3483 WRITE_OWNER_ACCESS /* */
3487 Test ntcreate calls made by xcopy
3489 static bool run_xcopy(int dummy)
3491 static struct cli_state *cli1;
3492 const char *fname = "\\test.txt";
3493 bool correct = True;
3496 printf("starting xcopy test\n");
3498 if (!torture_open_connection(&cli1, 0)) {
3502 fnum1 = cli_nt_create_full(cli1, fname, 0,
3503 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
3504 FILE_SHARE_NONE, FILE_OVERWRITE_IF,
3508 printf("First open failed - %s\n", cli_errstr(cli1));
3512 fnum2 = cli_nt_create_full(cli1, fname, 0,
3513 SECOND_DESIRED_ACCESS, 0,
3514 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN,
3517 printf("second open failed - %s\n", cli_errstr(cli1));
3521 if (!torture_close_connection(cli1)) {
3529 Test rename on files open with share delete and no share delete.
3531 static bool run_rename(int dummy)
3533 static struct cli_state *cli1;
3534 const char *fname = "\\test.txt";
3535 const char *fname1 = "\\test1.txt";
3536 bool correct = True;
3539 printf("starting rename test\n");
3541 if (!torture_open_connection(&cli1, 0)) {
3545 cli_unlink(cli1, fname);
3546 cli_unlink(cli1, fname1);
3547 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3548 FILE_SHARE_READ, FILE_OVERWRITE_IF, 0, 0);
3551 printf("First open failed - %s\n", cli_errstr(cli1));
3555 if (!cli_rename(cli1, fname, fname1)) {
3556 printf("First rename failed (SHARE_READ) (this is correct) - %s\n", cli_errstr(cli1));
3558 printf("First rename succeeded (SHARE_READ) - this should have failed !\n");
3562 if (!cli_close(cli1, fnum1)) {
3563 printf("close - 1 failed (%s)\n", cli_errstr(cli1));
3567 cli_unlink(cli1, fname);
3568 cli_unlink(cli1, fname1);
3569 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3571 FILE_SHARE_DELETE|FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3573 FILE_SHARE_DELETE|FILE_SHARE_READ, FILE_OVERWRITE_IF, 0, 0);
3577 printf("Second open failed - %s\n", cli_errstr(cli1));
3581 if (!cli_rename(cli1, fname, fname1)) {
3582 printf("Second rename failed (SHARE_DELETE | SHARE_READ) - this should have succeeded - %s\n", cli_errstr(cli1));
3585 printf("Second rename succeeded (SHARE_DELETE | SHARE_READ)\n");
3588 if (!cli_close(cli1, fnum1)) {
3589 printf("close - 2 failed (%s)\n", cli_errstr(cli1));
3593 cli_unlink(cli1, fname);
3594 cli_unlink(cli1, fname1);
3596 fnum1 = cli_nt_create_full(cli1, fname, 0, READ_CONTROL_ACCESS, FILE_ATTRIBUTE_NORMAL,
3597 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3600 printf("Third open failed - %s\n", cli_errstr(cli1));
3609 fnum2 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
3610 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3613 printf("Fourth open failed - %s\n", cli_errstr(cli1));
3616 if (!cli_nt_delete_on_close(cli1, fnum2, True)) {
3617 printf("[8] setting delete_on_close on file failed !\n");
3621 if (!cli_close(cli1, fnum2)) {
3622 printf("close - 4 failed (%s)\n", cli_errstr(cli1));
3628 if (!cli_rename(cli1, fname, fname1)) {
3629 printf("Third rename failed (SHARE_NONE) - this should have succeeded - %s\n", cli_errstr(cli1));
3632 printf("Third rename succeeded (SHARE_NONE)\n");
3635 if (!cli_close(cli1, fnum1)) {
3636 printf("close - 3 failed (%s)\n", cli_errstr(cli1));
3640 cli_unlink(cli1, fname);
3641 cli_unlink(cli1, fname1);
3645 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3646 FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0);
3649 printf("Fourth open failed - %s\n", cli_errstr(cli1));
3653 if (!cli_rename(cli1, fname, fname1)) {
3654 printf("Fourth rename failed (SHARE_READ | SHARE_WRITE) (this is correct) - %s\n", cli_errstr(cli1));
3656 printf("Fourth rename succeeded (SHARE_READ | SHARE_WRITE) - this should have failed !\n");
3660 if (!cli_close(cli1, fnum1)) {
3661 printf("close - 4 failed (%s)\n", cli_errstr(cli1));
3665 cli_unlink(cli1, fname);
3666 cli_unlink(cli1, fname1);
3670 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3671 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0);
3674 printf("Fifth open failed - %s\n", cli_errstr(cli1));
3678 if (!cli_rename(cli1, fname, fname1)) {
3679 printf("Fifth rename failed (SHARE_READ | SHARE_WRITE | SHARE_DELETE) - this should have succeeded - %s ! \n",
3683 printf("Fifth rename succeeded (SHARE_READ | SHARE_WRITE | SHARE_DELETE) (this is correct) - %s\n", cli_errstr(cli1));
3687 * Now check if the first name still exists ...
3690 /*fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3691 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0);
3694 printf("Opening original file after rename of open file fails: %s\n",
3698 printf("Opening original file after rename of open file works ...\n");
3699 (void)cli_close(cli1, fnum2);
3705 if (!cli_close(cli1, fnum1)) {
3706 printf("close - 5 failed (%s)\n", cli_errstr(cli1));
3710 cli_unlink(cli1, fname);
3711 cli_unlink(cli1, fname1);
3713 if (!torture_close_connection(cli1)) {
3720 static bool run_pipe_number(int dummy)
3722 struct cli_state *cli1;
3723 const char *pipe_name = "\\SPOOLSS";
3727 printf("starting pipenumber test\n");
3728 if (!torture_open_connection(&cli1, 0)) {
3732 cli_sockopt(cli1, sockops);
3734 fnum = cli_nt_create_full(cli1, pipe_name, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
3735 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN_IF, 0, 0);
3738 printf("Open of pipe %s failed with error (%s)\n", pipe_name, cli_errstr(cli1));
3742 printf("\r%6d", num_pipes);
3745 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes, pipe_name );
3746 torture_close_connection(cli1);
3751 Test open mode returns on read-only files.
3753 static bool run_opentest(int dummy)
3755 static struct cli_state *cli1;
3756 static struct cli_state *cli2;
3757 const char *fname = "\\readonly.file";
3761 bool correct = True;
3764 printf("starting open test\n");
3766 if (!torture_open_connection(&cli1, 0)) {
3770 cli_setatr(cli1, fname, 0, 0);
3771 cli_unlink(cli1, fname);
3773 cli_sockopt(cli1, sockops);
3775 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
3777 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
3781 if (!cli_close(cli1, fnum1)) {
3782 printf("close2 failed (%s)\n", cli_errstr(cli1));
3786 if (!cli_setatr(cli1, fname, aRONLY, 0)) {
3787 printf("cli_setatr failed (%s)\n", cli_errstr(cli1));
3791 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_WRITE);
3793 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
3797 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
3798 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_ALL);
3800 if (check_error(__LINE__, cli1, ERRDOS, ERRnoaccess,
3801 NT_STATUS_ACCESS_DENIED)) {
3802 printf("correct error code ERRDOS/ERRnoaccess returned\n");
3805 printf("finished open test 1\n");
3807 cli_close(cli1, fnum1);
3809 /* Now try not readonly and ensure ERRbadshare is returned. */
3811 cli_setatr(cli1, fname, 0, 0);
3813 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_WRITE);
3815 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
3819 /* This will fail - but the error should be ERRshare. */
3820 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_ALL);
3822 if (check_error(__LINE__, cli1, ERRDOS, ERRbadshare,
3823 NT_STATUS_SHARING_VIOLATION)) {
3824 printf("correct error code ERRDOS/ERRbadshare returned\n");
3827 if (!cli_close(cli1, fnum1)) {
3828 printf("close2 failed (%s)\n", cli_errstr(cli1));
3832 cli_unlink(cli1, fname);
3834 printf("finished open test 2\n");
3836 /* Test truncate open disposition on file opened for read. */
3838 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
3840 printf("(3) open (1) of %s failed (%s)\n", fname, cli_errstr(cli1));
3844 /* write 20 bytes. */
3846 memset(buf, '\0', 20);
3848 if (cli_write(cli1, fnum1, 0, buf, 0, 20) != 20) {
3849 printf("write failed (%s)\n", cli_errstr(cli1));
3853 if (!cli_close(cli1, fnum1)) {
3854 printf("(3) close1 failed (%s)\n", cli_errstr(cli1));
3858 /* Ensure size == 20. */
3859 if (!cli_getatr(cli1, fname, NULL, &fsize, NULL)) {
3860 printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
3865 printf("(3) file size != 20\n");
3869 /* Now test if we can truncate a file opened for readonly. */
3871 fnum1 = cli_open(cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE);
3873 printf("(3) open (2) of %s failed (%s)\n", fname, cli_errstr(cli1));
3877 if (!cli_close(cli1, fnum1)) {
3878 printf("close2 failed (%s)\n", cli_errstr(cli1));
3882 /* Ensure size == 0. */
3883 if (!cli_getatr(cli1, fname, NULL, &fsize, NULL)) {
3884 printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
3889 printf("(3) file size != 0\n");
3892 printf("finished open test 3\n");
3894 cli_unlink(cli1, fname);
3897 printf("testing ctemp\n");
3898 fnum1 = cli_ctemp(cli1, "\\", &tmp_path);
3900 printf("ctemp failed (%s)\n", cli_errstr(cli1));
3903 printf("ctemp gave path %s\n", tmp_path);
3904 if (!cli_close(cli1, fnum1)) {
3905 printf("close of temp failed (%s)\n", cli_errstr(cli1));
3907 if (!cli_unlink(cli1, tmp_path)) {
3908 printf("unlink of temp failed (%s)\n", cli_errstr(cli1));
3911 /* Test the non-io opens... */
3913 if (!torture_open_connection(&cli2, 1)) {
3917 cli_setatr(cli2, fname, 0, 0);
3918 cli_unlink(cli2, fname);
3920 cli_sockopt(cli2, sockops);
3922 printf("TEST #1 testing 2 non-io opens (no delete)\n");
3924 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3925 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3928 printf("test 1 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3932 fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3933 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
3936 printf("test 1 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3940 if (!cli_close(cli1, fnum1)) {
3941 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3944 if (!cli_close(cli2, fnum2)) {
3945 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3949 printf("non-io open test #1 passed.\n");
3951 cli_unlink(cli1, fname);
3953 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
3955 fnum1 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3956 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3959 printf("test 2 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3963 fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3964 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
3967 printf("test 2 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3971 if (!cli_close(cli1, fnum1)) {
3972 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3975 if (!cli_close(cli2, fnum2)) {
3976 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
3980 printf("non-io open test #2 passed.\n");
3982 cli_unlink(cli1, fname);
3984 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
3986 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3987 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3990 printf("test 3 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3994 fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3995 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
3998 printf("test 3 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4002 if (!cli_close(cli1, fnum1)) {
4003 printf("test 3 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4006 if (!cli_close(cli2, fnum2)) {
4007 printf("test 3 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4011 printf("non-io open test #3 passed.\n");
4013 cli_unlink(cli1, fname);
4015 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
4017 fnum1 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4018 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
4021 printf("test 4 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4025 fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4026 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
4029 printf("test 4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
4033 printf("test 3 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
4035 if (!cli_close(cli1, fnum1)) {
4036 printf("test 4 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4040 printf("non-io open test #4 passed.\n");
4042 cli_unlink(cli1, fname);
4044 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
4046 fnum1 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4047 FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0);
4050 printf("test 5 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4054 fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4055 FILE_SHARE_DELETE, FILE_OPEN_IF, 0, 0);
4058 printf("test 5 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4062 if (!cli_close(cli1, fnum1)) {
4063 printf("test 5 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4067 if (!cli_close(cli2, fnum2)) {
4068 printf("test 5 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4072 printf("non-io open test #5 passed.\n");
4074 printf("TEST #6 testing 1 non-io open, one io open\n");
4076 cli_unlink(cli1, fname);
4078 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
4079 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
4082 printf("test 6 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4086 fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4087 FILE_SHARE_READ, FILE_OPEN_IF, 0, 0);
4090 printf("test 6 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4094 if (!cli_close(cli1, fnum1)) {
4095 printf("test 6 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4099 if (!cli_close(cli2, fnum2)) {
4100 printf("test 6 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4104 printf("non-io open test #6 passed.\n");
4106 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
4108 cli_unlink(cli1, fname);
4110 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
4111 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
4114 printf("test 7 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4118 fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4119 FILE_SHARE_READ|FILE_SHARE_DELETE, FILE_OPEN_IF, 0, 0);
4122 printf("test 7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
4126 printf("test 7 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
4128 if (!cli_close(cli1, fnum1)) {
4129 printf("test 7 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4133 printf("non-io open test #7 passed.\n");
4135 cli_unlink(cli1, fname);
4137 if (!torture_close_connection(cli1)) {
4140 if (!torture_close_connection(cli2)) {
4147 static uint32 open_attrs_table[] = {
4148 FILE_ATTRIBUTE_NORMAL,
4149 FILE_ATTRIBUTE_ARCHIVE,
4150 FILE_ATTRIBUTE_READONLY,
4151 FILE_ATTRIBUTE_HIDDEN,
4152 FILE_ATTRIBUTE_SYSTEM,
4154 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY,
4155 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN,
4156 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM,
4157 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
4158 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
4159 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
4161 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
4162 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
4163 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
4164 FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_SYSTEM,
4167 struct trunc_open_results {
4174 static struct trunc_open_results attr_results[] = {
4175 { 0, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
4176 { 1, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
4177 { 2, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
4178 { 16, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
4179 { 17, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
4180 { 18, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
4181 { 51, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4182 { 54, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4183 { 56, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
4184 { 68, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4185 { 71, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4186 { 73, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM },
4187 { 99, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4188 { 102, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4189 { 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 },
4190 { 116, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4191 { 119, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4192 { 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 },
4193 { 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 },
4194 { 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 },
4195 { 227, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4196 { 230, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4197 { 232, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
4198 { 244, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4199 { 247, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4200 { 249, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM }
4203 static bool run_openattrtest(int dummy)
4205 static struct cli_state *cli1;
4206 const char *fname = "\\openattr.file";
4208 bool correct = True;
4210 unsigned int i, j, k, l;
4212 printf("starting open attr test\n");
4214 if (!torture_open_connection(&cli1, 0)) {
4218 cli_sockopt(cli1, sockops);
4220 for (k = 0, i = 0; i < sizeof(open_attrs_table)/sizeof(uint32); i++) {
4221 cli_setatr(cli1, fname, 0, 0);
4222 cli_unlink(cli1, fname);
4223 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_WRITE_DATA, open_attrs_table[i],
4224 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
4227 printf("open %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
4231 if (!cli_close(cli1, fnum1)) {
4232 printf("close %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
4236 for (j = 0; j < sizeof(open_attrs_table)/sizeof(uint32); j++) {
4237 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA, open_attrs_table[j],
4238 FILE_SHARE_NONE, FILE_OVERWRITE, 0, 0);
4241 for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
4242 if (attr_results[l].num == k) {
4243 printf("[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(0x%x:%s)\n",
4244 k, open_attrs_table[i],
4245 open_attrs_table[j],
4246 fname, NT_STATUS_V(cli_nt_error(cli1)), cli_errstr(cli1));
4250 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_ACCESS_DENIED)) {
4251 printf("[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s\n",
4252 k, open_attrs_table[i], open_attrs_table[j],
4257 printf("[%d] trunc open 0x%x -> 0x%x failed\n", k, open_attrs_table[i], open_attrs_table[j]);
4263 if (!cli_close(cli1, fnum1)) {
4264 printf("close %d (2) of %s failed (%s)\n", j, fname, cli_errstr(cli1));
4268 if (!cli_getatr(cli1, fname, &attr, NULL, NULL)) {
4269 printf("getatr(2) failed (%s)\n", cli_errstr(cli1));
4274 printf("[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n",
4275 k, open_attrs_table[i], open_attrs_table[j], attr );
4278 for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
4279 if (attr_results[l].num == k) {
4280 if (attr != attr_results[l].result_attr ||
4281 open_attrs_table[i] != attr_results[l].init_attr ||
4282 open_attrs_table[j] != attr_results[l].trunc_attr) {
4283 printf("getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x\n",
4284 open_attrs_table[i],
4285 open_attrs_table[j],
4287 attr_results[l].result_attr);
4297 cli_setatr(cli1, fname, 0, 0);
4298 cli_unlink(cli1, fname);
4300 printf("open attr test %s.\n", correct ? "passed" : "failed");
4302 if (!torture_close_connection(cli1)) {
4308 static void list_fn(const char *mnt, file_info *finfo, const char *name, void *state)
4314 test directory listing speed
4316 static bool run_dirtest(int dummy)
4319 static struct cli_state *cli;
4322 bool correct = True;
4324 printf("starting directory test\n");
4326 if (!torture_open_connection(&cli, 0)) {
4330 cli_sockopt(cli, sockops);
4333 for (i=0;i<torture_numops;i++) {
4335 slprintf(fname, sizeof(fname), "\\%x", (int)random());
4336 fnum = cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE);
4338 fprintf(stderr,"Failed to open %s\n", fname);
4341 cli_close(cli, fnum);
4346 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
4347 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
4348 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
4350 printf("dirtest core %g seconds\n", end_timer() - t1);
4353 for (i=0;i<torture_numops;i++) {
4355 slprintf(fname, sizeof(fname), "\\%x", (int)random());
4356 cli_unlink(cli, fname);
4359 if (!torture_close_connection(cli)) {
4363 printf("finished dirtest\n");
4368 static void del_fn(const char *mnt, file_info *finfo, const char *mask, void *state)
4370 struct cli_state *pcli = (struct cli_state *)state;
4372 slprintf(fname, sizeof(fname), "\\LISTDIR\\%s", finfo->name);
4374 if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
4377 if (finfo->mode & aDIR) {
4378 if (!cli_rmdir(pcli, fname))
4379 printf("del_fn: failed to rmdir %s\n,", fname );
4381 if (!cli_unlink(pcli, fname))
4382 printf("del_fn: failed to unlink %s\n,", fname );
4388 sees what IOCTLs are supported
4390 bool torture_ioctl_test(int dummy)
4392 static struct cli_state *cli;
4393 uint16 device, function;
4395 const char *fname = "\\ioctl.dat";
4399 if (!torture_open_connection(&cli, 0)) {
4403 printf("starting ioctl test\n");
4405 cli_unlink(cli, fname);
4407 fnum = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
4409 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
4413 status = cli_raw_ioctl(cli, fnum, 0x2d0000 | (0x0420<<2), &blob);
4414 printf("ioctl device info: %s\n", cli_errstr(cli));
4416 status = cli_raw_ioctl(cli, fnum, IOCTL_QUERY_JOB_INFO, &blob);
4417 printf("ioctl job info: %s\n", cli_errstr(cli));
4419 for (device=0;device<0x100;device++) {
4420 printf("testing device=0x%x\n", device);
4421 for (function=0;function<0x100;function++) {
4422 uint32 code = (device<<16) | function;
4424 status = cli_raw_ioctl(cli, fnum, code, &blob);
4426 if (NT_STATUS_IS_OK(status)) {
4427 printf("ioctl 0x%x OK : %d bytes\n", (int)code,
4429 data_blob_free(&blob);
4434 if (!torture_close_connection(cli)) {
4443 tries varients of chkpath
4445 bool torture_chkpath_test(int dummy)
4447 static struct cli_state *cli;
4451 if (!torture_open_connection(&cli, 0)) {
4455 printf("starting chkpath test\n");
4457 /* cleanup from an old run */
4458 cli_rmdir(cli, "\\chkpath.dir\\dir2");
4459 cli_unlink(cli, "\\chkpath.dir\\*");
4460 cli_rmdir(cli, "\\chkpath.dir");
4462 if (!cli_mkdir(cli, "\\chkpath.dir")) {
4463 printf("mkdir1 failed : %s\n", cli_errstr(cli));
4467 if (!cli_mkdir(cli, "\\chkpath.dir\\dir2")) {
4468 printf("mkdir2 failed : %s\n", cli_errstr(cli));
4472 fnum = cli_open(cli, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
4474 printf("open1 failed (%s)\n", cli_errstr(cli));
4477 cli_close(cli, fnum);
4479 if (!cli_chkpath(cli, "\\chkpath.dir")) {
4480 printf("chkpath1 failed: %s\n", cli_errstr(cli));
4484 if (!cli_chkpath(cli, "\\chkpath.dir\\dir2")) {
4485 printf("chkpath2 failed: %s\n", cli_errstr(cli));
4489 if (!cli_chkpath(cli, "\\chkpath.dir\\foo.txt")) {
4490 ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath,
4491 NT_STATUS_NOT_A_DIRECTORY);
4493 printf("* chkpath on a file should fail\n");
4497 if (!cli_chkpath(cli, "\\chkpath.dir\\bar.txt")) {
4498 ret = check_error(__LINE__, cli, ERRDOS, ERRbadfile,
4499 NT_STATUS_OBJECT_NAME_NOT_FOUND);
4501 printf("* chkpath on a non existant file should fail\n");
4505 if (!cli_chkpath(cli, "\\chkpath.dir\\dirxx\\bar.txt")) {
4506 ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath,
4507 NT_STATUS_OBJECT_PATH_NOT_FOUND);
4509 printf("* chkpath on a non existent component should fail\n");
4513 cli_rmdir(cli, "\\chkpath.dir\\dir2");
4514 cli_unlink(cli, "\\chkpath.dir\\*");
4515 cli_rmdir(cli, "\\chkpath.dir");
4517 if (!torture_close_connection(cli)) {
4524 static bool run_eatest(int dummy)
4526 static struct cli_state *cli;
4527 const char *fname = "\\eatest.txt";
4528 bool correct = True;
4531 struct ea_struct *ea_list = NULL;
4532 TALLOC_CTX *mem_ctx = talloc_init("eatest");
4534 printf("starting eatest\n");
4536 if (!torture_open_connection(&cli, 0)) {
4537 talloc_destroy(mem_ctx);
4541 cli_unlink(cli, fname);
4542 fnum = cli_nt_create_full(cli, fname, 0,
4543 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
4544 FILE_SHARE_NONE, FILE_OVERWRITE_IF,
4548 printf("open failed - %s\n", cli_errstr(cli));
4549 talloc_destroy(mem_ctx);
4553 for (i = 0; i < 10; i++) {
4554 fstring ea_name, ea_val;
4556 slprintf(ea_name, sizeof(ea_name), "EA_%d", i);
4557 memset(ea_val, (char)i+1, i+1);
4558 if (!cli_set_ea_fnum(cli, fnum, ea_name, ea_val, i+1)) {
4559 printf("ea_set of name %s failed - %s\n", ea_name, cli_errstr(cli));
4560 talloc_destroy(mem_ctx);
4565 cli_close(cli, fnum);
4566 for (i = 0; i < 10; i++) {
4567 fstring ea_name, ea_val;
4569 slprintf(ea_name, sizeof(ea_name), "EA_%d", i+10);
4570 memset(ea_val, (char)i+1, i+1);
4571 if (!cli_set_ea_path(cli, fname, ea_name, ea_val, i+1)) {
4572 printf("ea_set of name %s failed - %s\n", ea_name, cli_errstr(cli));
4573 talloc_destroy(mem_ctx);
4578 if (!cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list)) {
4579 printf("ea_get list failed - %s\n", cli_errstr(cli));
4583 printf("num_eas = %d\n", (int)num_eas);
4585 if (num_eas != 20) {
4586 printf("Should be 20 EA's stored... failing.\n");
4590 for (i = 0; i < num_eas; i++) {
4591 printf("%d: ea_name = %s. Val = ", i, ea_list[i].name);
4592 dump_data(0, ea_list[i].value.data,
4593 ea_list[i].value.length);
4596 /* Setting EA's to zero length deletes them. Test this */
4597 printf("Now deleting all EA's - case indepenent....\n");
4600 cli_set_ea_path(cli, fname, "", "", 0);
4602 for (i = 0; i < 20; i++) {
4604 slprintf(ea_name, sizeof(ea_name), "ea_%d", i);
4605 if (!cli_set_ea_path(cli, fname, ea_name, "", 0)) {
4606 printf("ea_set of name %s failed - %s\n", ea_name, cli_errstr(cli));
4607 talloc_destroy(mem_ctx);
4613 if (!cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list)) {
4614 printf("ea_get list failed - %s\n", cli_errstr(cli));
4618 printf("num_eas = %d\n", (int)num_eas);
4619 for (i = 0; i < num_eas; i++) {
4620 printf("%d: ea_name = %s. Val = ", i, ea_list[i].name);
4621 dump_data(0, ea_list[i].value.data,
4622 ea_list[i].value.length);
4626 printf("deleting EA's failed.\n");
4630 /* Try and delete a non existant EA. */
4631 if (!cli_set_ea_path(cli, fname, "foo", "", 0)) {
4632 printf("deleting non-existant EA 'foo' should succeed. %s\n", cli_errstr(cli));
4636 talloc_destroy(mem_ctx);
4637 if (!torture_close_connection(cli)) {
4644 static bool run_dirtest1(int dummy)
4647 static struct cli_state *cli;
4649 bool correct = True;
4651 printf("starting directory test\n");
4653 if (!torture_open_connection(&cli, 0)) {
4657 cli_sockopt(cli, sockops);
4659 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
4660 cli_list(cli, "\\LISTDIR\\*", aDIR, del_fn, cli);
4661 cli_rmdir(cli, "\\LISTDIR");
4662 cli_mkdir(cli, "\\LISTDIR");
4664 /* Create 1000 files and 1000 directories. */
4665 for (i=0;i<1000;i++) {
4667 slprintf(fname, sizeof(fname), "\\LISTDIR\\f%d", i);
4668 fnum = cli_nt_create_full(cli, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
4669 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0);
4671 fprintf(stderr,"Failed to open %s\n", fname);
4674 cli_close(cli, fnum);
4676 for (i=0;i<1000;i++) {
4678 slprintf(fname, sizeof(fname), "\\LISTDIR\\d%d", i);
4679 if (!cli_mkdir(cli, fname)) {
4680 fprintf(stderr,"Failed to open %s\n", fname);
4685 /* Now ensure that doing an old list sees both files and directories. */
4686 num_seen = cli_list_old(cli, "\\LISTDIR\\*", aDIR, list_fn, NULL);
4687 printf("num_seen = %d\n", num_seen );
4688 /* We should see 100 files + 1000 directories + . and .. */
4689 if (num_seen != 2002)
4692 /* Ensure if we have the "must have" bits we only see the
4695 num_seen = cli_list_old(cli, "\\LISTDIR\\*", (aDIR<<8)|aDIR, list_fn, NULL);
4696 printf("num_seen = %d\n", num_seen );
4697 if (num_seen != 1002)
4700 num_seen = cli_list_old(cli, "\\LISTDIR\\*", (aARCH<<8)|aDIR, list_fn, NULL);
4701 printf("num_seen = %d\n", num_seen );
4702 if (num_seen != 1000)
4705 /* Delete everything. */
4706 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
4707 cli_list(cli, "\\LISTDIR\\*", aDIR, del_fn, cli);
4708 cli_rmdir(cli, "\\LISTDIR");
4711 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
4712 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
4713 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
4716 if (!torture_close_connection(cli)) {
4720 printf("finished dirtest1\n");
4725 static bool run_error_map_extract(int dummy) {
4727 static struct cli_state *c_dos;
4728 static struct cli_state *c_nt;
4732 uint32 flgs2, errnum;
4739 /* NT-Error connection */
4741 if (!(c_nt = open_nbt_connection())) {
4745 c_nt->use_spnego = False;
4747 if (!cli_negprot(c_nt)) {
4748 printf("%s rejected the NT-error negprot (%s)\n",host, cli_errstr(c_nt));
4753 if (!NT_STATUS_IS_OK(cli_session_setup(c_nt, "", "", 0, "", 0,
4755 printf("%s rejected the NT-error initial session setup (%s)\n",host, cli_errstr(c_nt));
4759 /* DOS-Error connection */
4761 if (!(c_dos = open_nbt_connection())) {
4765 c_dos->use_spnego = False;
4766 c_dos->force_dos_errors = True;
4768 if (!cli_negprot(c_dos)) {
4769 printf("%s rejected the DOS-error negprot (%s)\n",host, cli_errstr(c_dos));
4770 cli_shutdown(c_dos);
4774 if (!NT_STATUS_IS_OK(cli_session_setup(c_dos, "", "", 0, "", 0,
4776 printf("%s rejected the DOS-error initial session setup (%s)\n",host, cli_errstr(c_dos));
4780 for (error=(0xc0000000 | 0x1); error < (0xc0000000| 0xFFF); error++) {
4781 fstr_sprintf(user, "%X", error);
4783 if (NT_STATUS_IS_OK(cli_session_setup(c_nt, user,
4784 password, strlen(password),
4785 password, strlen(password),
4787 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
4790 flgs2 = SVAL(c_nt->inbuf,smb_flg2);
4792 /* Case #1: 32-bit NT errors */
4793 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
4794 nt_status = NT_STATUS(IVAL(c_nt->inbuf,smb_rcls));
4796 printf("/** Dos error on NT connection! (%s) */\n",
4798 nt_status = NT_STATUS(0xc0000000);
4801 if (NT_STATUS_IS_OK(cli_session_setup(c_dos, user,
4802 password, strlen(password),
4803 password, strlen(password),
4805 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
4807 flgs2 = SVAL(c_dos->inbuf,smb_flg2), errnum;
4809 /* Case #1: 32-bit NT errors */
4810 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
4811 printf("/** NT error on DOS connection! (%s) */\n",
4813 errnum = errclass = 0;
4815 cli_dos_error(c_dos, &errclass, &errnum);
4818 if (NT_STATUS_V(nt_status) != error) {
4819 printf("/*\t{ This NT error code was 'sqashed'\n\t from %s to %s \n\t during the session setup }\n*/\n",
4820 get_nt_error_c_code(NT_STATUS(error)),
4821 get_nt_error_c_code(nt_status));
4824 printf("\t{%s,\t%s,\t%s},\n",
4825 smb_dos_err_class(errclass),
4826 smb_dos_err_name(errclass, errnum),
4827 get_nt_error_c_code(NT_STATUS(error)));
4832 static bool run_sesssetup_bench(int dummy)
4834 static struct cli_state *c;
4838 if (!(c = open_nbt_connection())) {
4842 if (!cli_negprot(c)) {
4843 printf("%s rejected the NT-error negprot (%s)\n", host,
4849 for (i=0; i<torture_numops; i++) {
4850 status = cli_session_setup(
4852 password, strlen(password),
4853 password, strlen(password),
4855 if (!NT_STATUS_IS_OK(status)) {
4856 d_printf("(%s) cli_session_setup failed: %s\n",
4857 __location__, nt_errstr(status));
4861 if (!cli_ulogoff(c)) {
4862 d_printf("(%s) cli_ulogoff failed: %s\n",
4863 __location__, cli_errstr(c));
4872 static bool subst_test(const char *str, const char *user, const char *domain,
4873 uid_t uid, gid_t gid, const char *expected)
4878 subst = talloc_sub_specified(talloc_tos(), str, user, domain, uid, gid);
4880 if (strcmp(subst, expected) != 0) {
4881 printf("sub_specified(%s, %s, %s, %d, %d) returned [%s], expected "
4882 "[%s]\n", str, user, domain, (int)uid, (int)gid, subst,
4891 static void chain1_open_completion(struct async_req *req)
4896 status = cli_open_recv(req, &fnum);
4899 d_printf("cli_open_recv returned %s: %d\n",
4901 NT_STATUS_IS_OK(status) ? fnum : -1);
4904 static void chain1_read_completion(struct async_req *req)
4910 status = cli_read_andx_recv(req, &received, &rcvbuf);
4911 if (!NT_STATUS_IS_OK(status)) {
4913 d_printf("cli_read_andx_recv returned %s\n",
4918 d_printf("got %d bytes: %.*s\n", (int)received, (int)received,
4923 static void chain1_close_completion(struct async_req *req)
4927 status = cli_close_recv(req);
4928 *((bool *)(req->async.priv)) = true;
4932 d_printf("cli_close returned %s\n", nt_errstr(status));
4935 static bool run_chain1(int dummy)
4937 struct cli_state *cli1;
4938 struct event_context *evt = event_context_init(NULL);
4939 struct async_req *reqs[4];
4942 printf("starting chain1 test\n");
4943 if (!torture_open_connection(&cli1, 0)) {
4947 cli_sockopt(cli1, sockops);
4949 cli_chain_cork(cli1, evt, 0);
4950 reqs[0] = cli_open_send(talloc_tos(), evt, cli1, "\\test",
4952 reqs[0]->async.fn = chain1_open_completion;
4953 reqs[1] = cli_read_andx_send(talloc_tos(), evt, cli1, 0, 0, 10);
4954 reqs[1]->async.fn = chain1_read_completion;
4955 reqs[2] = cli_read_andx_send(talloc_tos(), evt, cli1, 0, 1, 10);
4956 reqs[2]->async.fn = chain1_read_completion;
4957 reqs[3] = cli_close_send(talloc_tos(), evt, cli1, 0);
4958 reqs[3]->async.fn = chain1_close_completion;
4959 reqs[3]->async.priv = (void *)&done;
4960 cli_chain_uncork(cli1);
4963 event_loop_once(evt);
4966 torture_close_connection(cli1);
4970 static bool run_cli_echo(int dummy)
4972 struct cli_state *cli;
4973 struct event_context *ev = event_context_init(NULL);
4974 struct async_req *req;
4977 printf("starting chain1 test\n");
4978 if (!torture_open_connection(&cli, 0)) {
4981 cli_sockopt(cli, sockops);
4983 req = cli_echo_send(ev, ev, cli, 5, data_blob_const("hello", 5));
4985 d_printf("cli_echo_send failed\n");
4989 while (req->state < ASYNC_REQ_DONE) {
4990 event_loop_once(ev);
4993 status = cli_echo_recv(req);
4994 d_printf("cli_echo returned %s\n", nt_errstr(status));
4998 torture_close_connection(cli);
4999 return NT_STATUS_IS_OK(status);
5002 static bool run_local_substitute(int dummy)
5006 ok &= subst_test("%U", "bla", "", -1, -1, "bla");
5007 ok &= subst_test("%u%U", "bla", "", -1, -1, "blabla");
5008 ok &= subst_test("%g", "", "", -1, -1, "NO_GROUP");
5009 ok &= subst_test("%G", "", "", -1, -1, "NO_GROUP");
5010 ok &= subst_test("%g", "", "", -1, 0, gidtoname(0));
5011 ok &= subst_test("%G", "", "", -1, 0, gidtoname(0));
5012 ok &= subst_test("%D%u", "u", "dom", -1, 0, "domu");
5013 ok &= subst_test("%i %I", "", "", -1, -1, "0.0.0.0 0.0.0.0");
5015 /* Different captialization rules in sub_basic... */
5017 ok &= (strcmp(talloc_sub_basic(talloc_tos(), "BLA", "dom", "%U%D"),
5023 static bool run_local_gencache(int dummy)
5029 if (!gencache_init()) {
5030 d_printf("%s: gencache_init() failed\n", __location__);
5034 if (!gencache_set("foo", "bar", time(NULL) + 1000)) {
5035 d_printf("%s: gencache_set() failed\n", __location__);
5039 if (!gencache_get("foo", &val, &tm)) {
5040 d_printf("%s: gencache_get() failed\n", __location__);
5044 if (strcmp(val, "bar") != 0) {
5045 d_printf("%s: gencache_get() returned %s, expected %s\n",
5046 __location__, val, "bar");
5053 if (!gencache_del("foo")) {
5054 d_printf("%s: gencache_del() failed\n", __location__);
5057 if (gencache_del("foo")) {
5058 d_printf("%s: second gencache_del() succeeded\n",
5063 if (gencache_get("foo", &val, &tm)) {
5064 d_printf("%s: gencache_get() on deleted entry "
5065 "succeeded\n", __location__);
5069 blob = data_blob_string_const("bar");
5072 if (!gencache_set_data_blob("foo", &blob, tm)) {
5073 d_printf("%s: gencache_set_data_blob() failed\n", __location__);
5077 data_blob_free(&blob);
5079 if (!gencache_get_data_blob("foo", &blob, NULL)) {
5080 d_printf("%s: gencache_get_data_blob() failed\n", __location__);
5084 if (strcmp((const char *)blob.data, "bar") != 0) {
5085 d_printf("%s: gencache_get_data_blob() returned %s, expected %s\n",
5086 __location__, (const char *)blob.data, "bar");
5087 data_blob_free(&blob);
5091 data_blob_free(&blob);
5093 if (!gencache_del("foo")) {
5094 d_printf("%s: gencache_del() failed\n", __location__);
5097 if (gencache_del("foo")) {
5098 d_printf("%s: second gencache_del() succeeded\n",
5103 if (gencache_get_data_blob("foo", &blob, NULL)) {
5104 d_printf("%s: gencache_get_data_blob() on deleted entry "
5105 "succeeded\n", __location__);
5109 if (!gencache_shutdown()) {
5110 d_printf("%s: gencache_shutdown() failed\n", __location__);
5114 if (gencache_shutdown()) {
5115 d_printf("%s: second gencache_shutdown() succeeded\n",
5123 static bool rbt_testval(struct db_context *db, const char *key,
5126 struct db_record *rec;
5127 TDB_DATA data = string_tdb_data(value);
5131 rec = db->fetch_locked(db, db, string_tdb_data(key));
5133 d_fprintf(stderr, "fetch_locked failed\n");
5136 status = rec->store(rec, data, 0);
5137 if (!NT_STATUS_IS_OK(status)) {
5138 d_fprintf(stderr, "store failed: %s\n", nt_errstr(status));
5143 rec = db->fetch_locked(db, db, string_tdb_data(key));
5145 d_fprintf(stderr, "second fetch_locked failed\n");
5148 if ((rec->value.dsize != data.dsize)
5149 || (memcmp(rec->value.dptr, data.dptr, data.dsize) != 0)) {
5150 d_fprintf(stderr, "Got wrong data back\n");
5160 static bool run_local_rbtree(int dummy)
5162 struct db_context *db;
5166 db = db_open_rbt(NULL);
5169 d_fprintf(stderr, "db_open_rbt failed\n");
5173 for (i=0; i<1000; i++) {
5176 asprintf(&key, "key%ld", random());
5177 asprintf(&value, "value%ld", random());
5179 if (!rbt_testval(db, key, value)) {
5186 asprintf(&value, "value%ld", random());
5188 if (!rbt_testval(db, key, value)) {
5205 static bool test_stream_name(const char *fname, const char *expected_base,
5206 const char *expected_stream,
5207 NTSTATUS expected_status)
5211 char *stream = NULL;
5213 status = split_ntfs_stream_name(talloc_tos(), fname, &base, &stream);
5214 if (!NT_STATUS_EQUAL(status, expected_status)) {
5218 if (!NT_STATUS_IS_OK(status)) {
5222 if (base == NULL) goto error;
5224 if (strcmp(expected_base, base) != 0) goto error;
5226 if ((expected_stream != NULL) && (stream == NULL)) goto error;
5227 if ((expected_stream == NULL) && (stream != NULL)) goto error;
5229 if ((stream != NULL) && (strcmp(expected_stream, stream) != 0))
5233 TALLOC_FREE(stream);
5237 d_fprintf(stderr, "test_stream(%s, %s, %s, %s)\n",
5238 fname, expected_base ? expected_base : "<NULL>",
5239 expected_stream ? expected_stream : "<NULL>",
5240 nt_errstr(expected_status));
5241 d_fprintf(stderr, "-> base=%s, stream=%s, status=%s\n",
5242 base ? base : "<NULL>", stream ? stream : "<NULL>",
5245 TALLOC_FREE(stream);
5249 static bool run_local_stream_name(int dummy)
5253 ret &= test_stream_name(
5254 "bla", "bla", NULL, NT_STATUS_OK);
5255 ret &= test_stream_name(
5256 "bla::$DATA", "bla", NULL, NT_STATUS_OK);
5257 ret &= test_stream_name(
5258 "bla:blub:", "bla", NULL, NT_STATUS_OBJECT_NAME_INVALID);
5259 ret &= test_stream_name(
5260 "bla::", NULL, NULL, NT_STATUS_OBJECT_NAME_INVALID);
5261 ret &= test_stream_name(
5262 "bla::123", "bla", NULL, NT_STATUS_OBJECT_NAME_INVALID);
5263 ret &= test_stream_name(
5264 "bla:$DATA", "bla", "$DATA:$DATA", NT_STATUS_OK);
5265 ret &= test_stream_name(
5266 "bla:x:$DATA", "bla", "x:$DATA", NT_STATUS_OK);
5267 ret &= test_stream_name(
5268 "bla:x", "bla", "x:$DATA", NT_STATUS_OK);
5273 static bool data_blob_equal(DATA_BLOB a, DATA_BLOB b)
5275 if (a.length != b.length) {
5276 printf("a.length=%d != b.length=%d\n",
5277 (int)a.length, (int)b.length);
5280 if (memcmp(a.data, b.data, a.length) != 0) {
5281 printf("a.data and b.data differ\n");
5287 static bool run_local_memcache(int dummy)
5289 struct memcache *cache;
5291 DATA_BLOB d1, d2, d3;
5292 DATA_BLOB v1, v2, v3;
5294 cache = memcache_init(NULL, 100);
5296 if (cache == NULL) {
5297 printf("memcache_init failed\n");
5301 d1 = data_blob_const("d1", 2);
5302 d2 = data_blob_const("d2", 2);
5303 d3 = data_blob_const("d3", 2);
5305 k1 = data_blob_const("d1", 2);
5306 k2 = data_blob_const("d2", 2);
5308 memcache_add(cache, STAT_CACHE, k1, d1);
5309 memcache_add(cache, GETWD_CACHE, k2, d2);
5311 if (!memcache_lookup(cache, STAT_CACHE, k1, &v1)) {
5312 printf("could not find k1\n");
5315 if (!data_blob_equal(d1, v1)) {
5319 if (!memcache_lookup(cache, GETWD_CACHE, k2, &v2)) {
5320 printf("could not find k2\n");
5323 if (!data_blob_equal(d2, v2)) {
5327 memcache_add(cache, STAT_CACHE, k1, d3);
5329 if (!memcache_lookup(cache, STAT_CACHE, k1, &v3)) {
5330 printf("could not find replaced k1\n");
5333 if (!data_blob_equal(d3, v3)) {
5337 memcache_add(cache, GETWD_CACHE, k1, d1);
5339 if (memcache_lookup(cache, GETWD_CACHE, k2, &v2)) {
5340 printf("Did find k2, should have been purged\n");
5348 static double create_procs(bool (*fn)(int), bool *result)
5351 volatile pid_t *child_status;
5352 volatile bool *child_status_out;
5358 child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*nprocs);
5359 if (!child_status) {
5360 printf("Failed to setup shared memory\n");
5364 child_status_out = (volatile bool *)shm_setup(sizeof(bool)*nprocs);
5365 if (!child_status_out) {
5366 printf("Failed to setup result status shared memory\n");
5370 for (i = 0; i < nprocs; i++) {
5371 child_status[i] = 0;
5372 child_status_out[i] = True;
5377 for (i=0;i<nprocs;i++) {
5380 pid_t mypid = getpid();
5381 sys_srandom(((int)mypid) ^ ((int)time(NULL)));
5383 slprintf(myname,sizeof(myname),"CLIENT%d", i);
5386 if (torture_open_connection(¤t_cli, i)) break;
5388 printf("pid %d failed to start\n", (int)getpid());
5394 child_status[i] = getpid();
5396 while (child_status[i] && end_timer() < 5) smb_msleep(2);
5398 child_status_out[i] = fn(i);
5405 for (i=0;i<nprocs;i++) {
5406 if (child_status[i]) synccount++;
5408 if (synccount == nprocs) break;
5410 } while (end_timer() < 30);
5412 if (synccount != nprocs) {
5413 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs, synccount);
5418 /* start the client load */
5421 for (i=0;i<nprocs;i++) {
5422 child_status[i] = 0;
5425 printf("%d clients started\n", nprocs);
5427 for (i=0;i<nprocs;i++) {
5428 while (waitpid(0, &status, 0) == -1 && errno == EINTR) /* noop */ ;
5433 for (i=0;i<nprocs;i++) {
5434 if (!child_status_out[i]) {
5441 #define FLAG_MULTIPROC 1
5448 {"FDPASS", run_fdpasstest, 0},
5449 {"LOCK1", run_locktest1, 0},
5450 {"LOCK2", run_locktest2, 0},
5451 {"LOCK3", run_locktest3, 0},
5452 {"LOCK4", run_locktest4, 0},
5453 {"LOCK5", run_locktest5, 0},
5454 {"LOCK6", run_locktest6, 0},
5455 {"LOCK7", run_locktest7, 0},
5456 {"UNLINK", run_unlinktest, 0},
5457 {"BROWSE", run_browsetest, 0},
5458 {"ATTR", run_attrtest, 0},
5459 {"TRANS2", run_trans2test, 0},
5460 {"MAXFID", run_maxfidtest, FLAG_MULTIPROC},
5461 {"TORTURE",run_torture, FLAG_MULTIPROC},
5462 {"RANDOMIPC", run_randomipc, 0},
5463 {"NEGNOWAIT", run_negprot_nowait, 0},
5464 {"NBENCH", run_nbench, 0},
5465 {"OPLOCK1", run_oplock1, 0},
5466 {"OPLOCK2", run_oplock2, 0},
5467 {"OPLOCK3", run_oplock3, 0},
5468 {"DIR", run_dirtest, 0},
5469 {"DIR1", run_dirtest1, 0},
5470 {"DENY1", torture_denytest1, 0},
5471 {"DENY2", torture_denytest2, 0},
5472 {"TCON", run_tcon_test, 0},
5473 {"TCONDEV", run_tcon_devtype_test, 0},
5474 {"RW1", run_readwritetest, 0},
5475 {"RW2", run_readwritemulti, FLAG_MULTIPROC},
5476 {"RW3", run_readwritelarge, 0},
5477 {"OPEN", run_opentest, 0},
5479 {"OPENATTR", run_openattrtest, 0},
5481 {"XCOPY", run_xcopy, 0},
5482 {"RENAME", run_rename, 0},
5483 {"DELETE", run_deletetest, 0},
5484 {"PROPERTIES", run_properties, 0},
5485 {"MANGLE", torture_mangle, 0},
5486 {"W2K", run_w2ktest, 0},
5487 {"TRANS2SCAN", torture_trans2_scan, 0},
5488 {"NTTRANSSCAN", torture_nttrans_scan, 0},
5489 {"UTABLE", torture_utable, 0},
5490 {"CASETABLE", torture_casetable, 0},
5491 {"ERRMAPEXTRACT", run_error_map_extract, 0},
5492 {"PIPE_NUMBER", run_pipe_number, 0},
5493 {"TCON2", run_tcon2_test, 0},
5494 {"IOCTL", torture_ioctl_test, 0},
5495 {"CHKPATH", torture_chkpath_test, 0},
5496 {"FDSESS", run_fdsesstest, 0},
5497 { "EATEST", run_eatest, 0},
5498 { "SESSSETUP_BENCH", run_sesssetup_bench, 0},
5499 { "CHAIN1", run_chain1, 0},
5500 { "CLI_ECHO", run_cli_echo, 0},
5501 { "LOCAL-SUBSTITUTE", run_local_substitute, 0},
5502 { "LOCAL-GENCACHE", run_local_gencache, 0},
5503 { "LOCAL-RBTREE", run_local_rbtree, 0},
5504 { "LOCAL-MEMCACHE", run_local_memcache, 0},
5505 { "LOCAL-STREAM-NAME", run_local_stream_name, 0},
5510 /****************************************************************************
5511 run a specified test or "ALL"
5512 ****************************************************************************/
5513 static bool run_test(const char *name)
5520 if (strequal(name,"ALL")) {
5521 for (i=0;torture_ops[i].name;i++) {
5522 run_test(torture_ops[i].name);
5527 for (i=0;torture_ops[i].name;i++) {
5528 fstr_sprintf(randomfname, "\\XX%x",
5529 (unsigned)random());
5531 if (strequal(name, torture_ops[i].name)) {
5533 printf("Running %s\n", name);
5534 if (torture_ops[i].flags & FLAG_MULTIPROC) {
5535 t = create_procs(torture_ops[i].fn, &result);
5538 printf("TEST %s FAILED!\n", name);
5543 if (!torture_ops[i].fn(0)) {
5545 printf("TEST %s FAILED!\n", name);
5549 printf("%s took %g secs\n\n", name, t);
5554 printf("Did not find a test named %s\n", name);
5562 static void usage(void)
5566 printf("WARNING samba4 test suite is much more complete nowadays.\n");
5567 printf("Please use samba4 torture.\n\n");
5569 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
5571 printf("\t-d debuglevel\n");
5572 printf("\t-U user%%pass\n");
5573 printf("\t-k use kerberos\n");
5574 printf("\t-N numprocs\n");
5575 printf("\t-n my_netbios_name\n");
5576 printf("\t-W workgroup\n");
5577 printf("\t-o num_operations\n");
5578 printf("\t-O socket_options\n");
5579 printf("\t-m maximum protocol\n");
5580 printf("\t-L use oplocks\n");
5581 printf("\t-c CLIENT.TXT specify client load file for NBENCH\n");
5582 printf("\t-A showall\n");
5583 printf("\t-p port\n");
5584 printf("\t-s seed\n");
5585 printf("\t-b unclist_filename specify multiple shares for multiple connections\n");
5588 printf("tests are:");
5589 for (i=0;torture_ops[i].name;i++) {
5590 printf(" %s", torture_ops[i].name);
5594 printf("default test is ALL\n");
5599 /****************************************************************************
5601 ****************************************************************************/
5602 int main(int argc,char *argv[])
5608 bool correct = True;
5609 TALLOC_CTX *frame = talloc_stackframe();
5610 int seed = time(NULL);
5614 #ifdef HAVE_SETBUFFER
5615 setbuffer(stdout, NULL, 0);
5620 lp_load(get_dyn_CONFIGFILE(),True,False,False,True);
5627 for(p = argv[1]; *p; p++)
5631 if (strncmp(argv[1], "//", 2)) {
5635 fstrcpy(host, &argv[1][2]);
5636 p = strchr_m(&host[2],'/');
5641 fstrcpy(share, p+1);
5643 fstrcpy(myname, get_myname(talloc_tos()));
5645 fprintf(stderr, "Failed to get my hostname.\n");
5649 if (*username == 0 && getenv("LOGNAME")) {
5650 fstrcpy(username,getenv("LOGNAME"));
5656 fstrcpy(workgroup, lp_workgroup());
5658 while ((opt = getopt(argc, argv, "p:hW:U:n:N:O:o:m:Ld:Aec:ks:b:")) != EOF) {
5661 port_to_use = atoi(optarg);
5664 seed = atoi(optarg);
5667 fstrcpy(workgroup,optarg);
5670 max_protocol = interpret_protocol(optarg, max_protocol);
5673 nprocs = atoi(optarg);
5676 torture_numops = atoi(optarg);
5679 DEBUGLEVEL = atoi(optarg);
5688 torture_showall = True;
5691 fstrcpy(myname, optarg);
5694 client_txt = optarg;
5701 use_kerberos = True;
5703 d_printf("No kerberos support compiled in\n");
5709 fstrcpy(username,optarg);
5710 p = strchr_m(username,'%');
5713 fstrcpy(password, p+1);
5718 fstrcpy(multishare_conn_fname, optarg);
5719 use_multishare_conn = True;
5722 printf("Unknown option %c (%d)\n", (char)opt, opt);
5727 d_printf("using seed %d\n", seed);
5731 if(use_kerberos && !gotuser) gotpass = True;
5734 p = getpass("Password:");
5736 fstrcpy(password, p);
5741 printf("host=%s share=%s user=%s myname=%s\n",
5742 host, share, username, myname);
5744 if (argc == optind) {
5745 correct = run_test("ALL");
5747 for (i=optind;i<argc;i++) {
5748 if (!run_test(argv[i])) {