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 2 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, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 static fstring host, workgroup, share, password, username, myname;
27 static int max_protocol = PROTOCOL_NT1;
28 static const char *sockops="TCP_NODELAY";
30 static int port_to_use=0;
31 int torture_numops=100;
32 static int procnum; /* records process count number when forking */
33 static struct cli_state *current_cli;
34 static fstring randomfname;
35 static BOOL use_oplocks;
36 static BOOL use_level_II_oplocks;
37 static const char *client_txt = "client_oplocks.txt";
38 static BOOL use_kerberos;
39 static fstring multishare_conn_fname;
40 static BOOL use_multishare_conn = False;
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);
100 static struct cli_state *open_nbt_connection(void)
102 struct nmb_name called, calling;
106 make_nmb_name(&calling, myname, 0x0);
107 make_nmb_name(&called , host, 0x20);
111 if (!(c = cli_initialise())) {
112 printf("Failed initialize cli_struct to connect with %s\n", host);
116 c->port = port_to_use;
118 if (!cli_connect(c, host, &ip)) {
119 printf("Failed to connect with %s\n", host);
123 c->use_kerberos = use_kerberos;
125 c->timeout = 120000; /* set a really long timeout (2 minutes) */
126 if (use_oplocks) c->use_oplocks = True;
127 if (use_level_II_oplocks) c->use_level_II_oplocks = True;
129 if (!cli_session_request(c, &calling, &called)) {
131 * Well, that failed, try *SMBSERVER ...
132 * However, we must reconnect as well ...
134 if (!cli_connect(c, host, &ip)) {
135 printf("Failed to connect with %s\n", host);
139 make_nmb_name(&called, "*SMBSERVER", 0x20);
140 if (!cli_session_request(c, &calling, &called)) {
141 printf("%s rejected the session\n",host);
142 printf("We tried with a called name of %s & %s\n",
152 /* Insert a NULL at the first separator of the given path and return a pointer
153 * to the remainder of the string.
156 terminate_path_at_separator(char * path)
164 if ((p = strchr_m(path, '/'))) {
169 if ((p = strchr_m(path, '\\'))) {
179 parse a //server/share type UNC name
181 BOOL smbcli_parse_unc(const char *unc_name, TALLOC_CTX *mem_ctx,
182 char **hostname, char **sharename)
186 *hostname = *sharename = NULL;
188 if (strncmp(unc_name, "\\\\", 2) &&
189 strncmp(unc_name, "//", 2)) {
193 *hostname = talloc_strdup(mem_ctx, &unc_name[2]);
194 p = terminate_path_at_separator(*hostname);
197 *sharename = talloc_strdup(mem_ctx, p);
198 terminate_path_at_separator(*sharename);
201 if (*hostname && *sharename) {
205 TALLOC_FREE(*hostname);
206 TALLOC_FREE(*sharename);
210 static BOOL torture_open_connection_share(struct cli_state **c,
211 const char *hostname,
212 const char *sharename)
219 flags |= CLI_FULL_CONNECTION_USE_KERBEROS;
221 status = cli_full_connection(c, myname,
222 hostname, NULL, port_to_use,
225 password, flags, Undefined, &retry);
226 if (!NT_STATUS_IS_OK(status)) {
230 if (use_oplocks) (*c)->use_oplocks = True;
231 if (use_level_II_oplocks) (*c)->use_level_II_oplocks = True;
232 (*c)->timeout = 120000; /* set a really long timeout (2 minutes) */
237 void torture_open_connection_free_unclist(char **unc_list)
241 SAFE_FREE(unc_list[0]);
246 BOOL torture_open_connection(struct cli_state **c, int conn_index)
248 char **unc_list = NULL;
249 int num_unc_names = 0;
252 if (use_multishare_conn==True) {
254 unc_list = file_lines_load(multishare_conn_fname, &num_unc_names, 0);
255 if (!unc_list || num_unc_names <= 0) {
256 printf("Failed to load unc names list from '%s'\n", multishare_conn_fname);
260 if (!smbcli_parse_unc(unc_list[conn_index % num_unc_names],
262 printf("Failed to parse UNC name %s\n",
263 unc_list[conn_index % num_unc_names]);
264 torture_open_connection_free_unclist(unc_list);
268 result = torture_open_connection_share(c, h, s);
270 /* h, s were copied earlier */
271 torture_open_connection_free_unclist(unc_list);
275 return torture_open_connection_share(c, host, share);
278 BOOL torture_cli_session_setup2(struct cli_state *cli, uint16 *new_vuid)
280 uint16 old_vuid = cli->vuid;
281 fstring old_user_name;
282 size_t passlen = strlen(password);
285 fstrcpy(old_user_name, cli->user_name);
287 ret = NT_STATUS_IS_OK(cli_session_setup(cli, username,
291 *new_vuid = cli->vuid;
292 cli->vuid = old_vuid;
293 fstrcpy(cli->user_name, old_user_name);
298 BOOL torture_close_connection(struct cli_state *c)
302 printf("tdis failed (%s)\n", cli_errstr(c));
312 /* check if the server produced the expected error code */
313 static BOOL check_error(int line, struct cli_state *c,
314 uint8 eclass, uint32 ecode, NTSTATUS nterr)
316 if (cli_is_dos_error(c)) {
320 /* Check DOS error */
322 cli_dos_error(c, &cclass, &num);
324 if (eclass != cclass || ecode != num) {
325 printf("unexpected error code class=%d code=%d\n",
326 (int)cclass, (int)num);
327 printf(" expected %d/%d %s (line=%d)\n",
328 (int)eclass, (int)ecode, nt_errstr(nterr), line);
337 status = cli_nt_error(c);
339 if (NT_STATUS_V(nterr) != NT_STATUS_V(status)) {
340 printf("unexpected error code %s\n", nt_errstr(status));
341 printf(" expected %s (line=%d)\n", nt_errstr(nterr), line);
350 static BOOL wait_lock(struct cli_state *c, int fnum, uint32 offset, uint32 len)
352 while (!cli_lock(c, fnum, offset, len, -1, WRITE_LOCK)) {
353 if (!check_error(__LINE__, c, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
359 static BOOL rw_torture(struct cli_state *c)
361 const char *lockfname = "\\torture.lck";
365 pid_t pid2, pid = getpid();
370 fnum2 = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
373 fnum2 = cli_open(c, lockfname, O_RDWR, DENY_NONE);
375 printf("open of %s failed (%s)\n", lockfname, cli_errstr(c));
380 for (i=0;i<torture_numops;i++) {
381 unsigned n = (unsigned)sys_random()%10;
383 printf("%d\r", i); fflush(stdout);
385 slprintf(fname, sizeof(fstring) - 1, "\\torture.%u", n);
387 if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) {
391 fnum = cli_open(c, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL);
393 printf("open failed (%s)\n", cli_errstr(c));
398 if (cli_write(c, fnum, 0, (char *)&pid, 0, sizeof(pid)) != sizeof(pid)) {
399 printf("write failed (%s)\n", cli_errstr(c));
404 if (cli_write(c, fnum, 0, (char *)buf,
405 sizeof(pid)+(j*sizeof(buf)),
406 sizeof(buf)) != sizeof(buf)) {
407 printf("write failed (%s)\n", cli_errstr(c));
414 if (cli_read(c, fnum, (char *)&pid2, 0, sizeof(pid)) != sizeof(pid)) {
415 printf("read failed (%s)\n", cli_errstr(c));
420 printf("data corruption!\n");
424 if (!cli_close(c, fnum)) {
425 printf("close failed (%s)\n", cli_errstr(c));
429 if (!cli_unlink(c, fname)) {
430 printf("unlink failed (%s)\n", cli_errstr(c));
434 if (!cli_unlock(c, fnum2, n*sizeof(int), sizeof(int))) {
435 printf("unlock failed (%s)\n", cli_errstr(c));
441 cli_unlink(c, lockfname);
448 static BOOL run_torture(int dummy)
450 struct cli_state *cli;
455 cli_sockopt(cli, sockops);
457 ret = rw_torture(cli);
459 if (!torture_close_connection(cli)) {
466 static BOOL rw_torture3(struct cli_state *c, char *lockfname)
473 unsigned countprev = 0;
478 for (i = 0; i < sizeof(buf); i += sizeof(uint32))
480 SIVAL(buf, i, sys_random());
485 fnum = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
488 printf("first open read/write of %s failed (%s)\n",
489 lockfname, cli_errstr(c));
495 for (i = 0; i < 500 && fnum == -1; i++)
497 fnum = cli_open(c, lockfname, O_RDONLY,
502 printf("second open read-only of %s failed (%s)\n",
503 lockfname, cli_errstr(c));
509 for (count = 0; count < sizeof(buf); count += sent)
511 if (count >= countprev) {
512 printf("%d %8d\r", i, count);
515 countprev += (sizeof(buf) / 20);
520 sent = ((unsigned)sys_random()%(20))+ 1;
521 if (sent > sizeof(buf) - count)
523 sent = sizeof(buf) - count;
526 if (cli_write(c, fnum, 0, buf+count, count, (size_t)sent) != sent) {
527 printf("write failed (%s)\n", cli_errstr(c));
533 sent = cli_read(c, fnum, buf_rd+count, count,
537 printf("read failed offset:%d size:%ld (%s)\n",
538 count, (unsigned long)sizeof(buf)-count,
545 if (memcmp(buf_rd+count, buf+count, sent) != 0)
547 printf("read/write compare failed\n");
548 printf("offset: %d req %ld recvd %ld\n", count, (unsigned long)sizeof(buf)-count, (unsigned long)sent);
557 if (!cli_close(c, fnum)) {
558 printf("close failed (%s)\n", cli_errstr(c));
565 static BOOL rw_torture2(struct cli_state *c1, struct cli_state *c2)
567 const char *lockfname = "\\torture2.lck";
576 if (!cli_unlink(c1, lockfname)) {
577 printf("unlink failed (%s) (normal, this file should not exist)\n", cli_errstr(c1));
580 fnum1 = cli_open(c1, lockfname, O_RDWR | O_CREAT | O_EXCL,
583 printf("first open read/write of %s failed (%s)\n",
584 lockfname, cli_errstr(c1));
587 fnum2 = cli_open(c2, lockfname, O_RDONLY,
590 printf("second open read-only of %s failed (%s)\n",
591 lockfname, cli_errstr(c2));
592 cli_close(c1, fnum1);
596 for (i=0;i<torture_numops;i++)
598 size_t buf_size = ((unsigned)sys_random()%(sizeof(buf)-1))+ 1;
600 printf("%d\r", i); fflush(stdout);
603 generate_random_buffer((unsigned char *)buf, buf_size);
605 if (cli_write(c1, fnum1, 0, buf, 0, buf_size) != buf_size) {
606 printf("write failed (%s)\n", cli_errstr(c1));
611 if ((bytes_read = cli_read(c2, fnum2, buf_rd, 0, buf_size)) != buf_size) {
612 printf("read failed (%s)\n", cli_errstr(c2));
613 printf("read %d, expected %ld\n", (int)bytes_read,
614 (unsigned long)buf_size);
619 if (memcmp(buf_rd, buf, buf_size) != 0)
621 printf("read/write compare failed\n");
627 if (!cli_close(c2, fnum2)) {
628 printf("close failed (%s)\n", cli_errstr(c2));
631 if (!cli_close(c1, fnum1)) {
632 printf("close failed (%s)\n", cli_errstr(c1));
636 if (!cli_unlink(c1, lockfname)) {
637 printf("unlink failed (%s)\n", cli_errstr(c1));
644 static BOOL run_readwritetest(int dummy)
646 static struct cli_state *cli1, *cli2;
647 BOOL test1, test2 = False;
649 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
652 cli_sockopt(cli1, sockops);
653 cli_sockopt(cli2, sockops);
655 printf("starting readwritetest\n");
657 test1 = rw_torture2(cli1, cli2);
658 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1));
661 test2 = rw_torture2(cli1, cli1);
662 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2));
665 if (!torture_close_connection(cli1)) {
669 if (!torture_close_connection(cli2)) {
673 return (test1 && test2);
676 static BOOL run_readwritemulti(int dummy)
678 struct cli_state *cli;
683 cli_sockopt(cli, sockops);
685 printf("run_readwritemulti: fname %s\n", randomfname);
686 test = rw_torture3(cli, randomfname);
688 if (!torture_close_connection(cli)) {
695 static BOOL run_readwritelarge(int dummy)
697 static struct cli_state *cli1;
699 const char *lockfname = "\\large.dat";
704 if (!torture_open_connection(&cli1, 0)) {
707 cli_sockopt(cli1, sockops);
708 memset(buf,'\0',sizeof(buf));
710 cli1->max_xmit = 128*1024;
712 printf("starting readwritelarge\n");
714 cli_unlink(cli1, lockfname);
716 fnum1 = cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE);
718 printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(cli1));
722 cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf));
724 if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
725 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
729 if (fsize == sizeof(buf))
730 printf("readwritelarge test 1 succeeded (size = %lx)\n",
731 (unsigned long)fsize);
733 printf("readwritelarge test 1 failed (size = %lx)\n",
734 (unsigned long)fsize);
738 if (!cli_close(cli1, fnum1)) {
739 printf("close failed (%s)\n", cli_errstr(cli1));
743 if (!cli_unlink(cli1, lockfname)) {
744 printf("unlink failed (%s)\n", cli_errstr(cli1));
748 fnum1 = cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE);
750 printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(cli1));
754 cli1->max_xmit = 4*1024;
756 cli_smbwrite(cli1, fnum1, buf, 0, sizeof(buf));
758 if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
759 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
763 if (fsize == sizeof(buf))
764 printf("readwritelarge test 2 succeeded (size = %lx)\n",
765 (unsigned long)fsize);
767 printf("readwritelarge test 2 failed (size = %lx)\n",
768 (unsigned long)fsize);
773 /* ToDo - set allocation. JRA */
774 if(!cli_set_allocation_size(cli1, fnum1, 0)) {
775 printf("set allocation size to zero failed (%s)\n", cli_errstr(&cli1));
778 if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
779 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
783 printf("readwritelarge test 3 (truncate test) succeeded (size = %x)\n", fsize);
786 if (!cli_close(cli1, fnum1)) {
787 printf("close failed (%s)\n", cli_errstr(cli1));
791 if (!torture_close_connection(cli1)) {
800 #define ival(s) strtol(s, NULL, 0)
802 /* run a test that simulates an approximate netbench client load */
803 static BOOL run_netbench(int client)
805 struct cli_state *cli;
810 const char *params[20];
817 cli_sockopt(cli, sockops);
821 slprintf(cname,sizeof(cname)-1, "client%d", client);
823 f = fopen(client_txt, "r");
830 while (fgets(line, sizeof(line)-1, f)) {
833 line[strlen(line)-1] = 0;
835 /* printf("[%d] %s\n", line_count, line); */
837 all_string_sub(line,"client1", cname, sizeof(line));
839 /* parse the command parameters */
840 params[0] = strtok(line," ");
842 while (params[i]) params[++i] = strtok(NULL," ");
848 if (!strncmp(params[0],"SMB", 3)) {
849 printf("ERROR: You are using a dbench 1 load file\n");
853 if (!strcmp(params[0],"NTCreateX")) {
854 nb_createx(params[1], ival(params[2]), ival(params[3]),
856 } else if (!strcmp(params[0],"Close")) {
857 nb_close(ival(params[1]));
858 } else if (!strcmp(params[0],"Rename")) {
859 nb_rename(params[1], params[2]);
860 } else if (!strcmp(params[0],"Unlink")) {
861 nb_unlink(params[1]);
862 } else if (!strcmp(params[0],"Deltree")) {
863 nb_deltree(params[1]);
864 } else if (!strcmp(params[0],"Rmdir")) {
866 } else if (!strcmp(params[0],"QUERY_PATH_INFORMATION")) {
867 nb_qpathinfo(params[1]);
868 } else if (!strcmp(params[0],"QUERY_FILE_INFORMATION")) {
869 nb_qfileinfo(ival(params[1]));
870 } else if (!strcmp(params[0],"QUERY_FS_INFORMATION")) {
871 nb_qfsinfo(ival(params[1]));
872 } else if (!strcmp(params[0],"FIND_FIRST")) {
873 nb_findfirst(params[1]);
874 } else if (!strcmp(params[0],"WriteX")) {
875 nb_writex(ival(params[1]),
876 ival(params[2]), ival(params[3]), ival(params[4]));
877 } else if (!strcmp(params[0],"ReadX")) {
878 nb_readx(ival(params[1]),
879 ival(params[2]), ival(params[3]), ival(params[4]));
880 } else if (!strcmp(params[0],"Flush")) {
881 nb_flush(ival(params[1]));
883 printf("Unknown operation %s\n", params[0]);
891 if (!torture_close_connection(cli)) {
899 /* run a test that simulates an approximate netbench client load */
900 static BOOL run_nbench(int dummy)
909 signal(SIGALRM, nb_alarm);
911 t = create_procs(run_netbench, &correct);
914 printf("\nThroughput %g MB/sec\n",
915 1.0e-6 * nbio_total() / t);
921 This test checks for two things:
923 1) correct support for retaining locks over a close (ie. the server
924 must not use posix semantics)
925 2) support for lock timeouts
927 static BOOL run_locktest1(int dummy)
929 struct cli_state *cli1, *cli2;
930 const char *fname = "\\lockt1.lck";
931 int fnum1, fnum2, fnum3;
933 unsigned lock_timeout;
935 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
938 cli_sockopt(cli1, sockops);
939 cli_sockopt(cli2, sockops);
941 printf("starting locktest1\n");
943 cli_unlink(cli1, fname);
945 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
947 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
950 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
952 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli1));
955 fnum3 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
957 printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli2));
961 if (!cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
962 printf("lock1 failed (%s)\n", cli_errstr(cli1));
967 if (cli_lock(cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
968 printf("lock2 succeeded! This is a locking bug\n");
971 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
972 NT_STATUS_LOCK_NOT_GRANTED)) return False;
976 lock_timeout = (1 + (random() % 20));
977 printf("Testing lock timeout with timeout=%u\n", lock_timeout);
979 if (cli_lock(cli2, fnum3, 0, 4, lock_timeout * 1000, WRITE_LOCK)) {
980 printf("lock3 succeeded! This is a locking bug\n");
983 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
984 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
988 if (ABS(t2 - t1) < lock_timeout-1) {
989 printf("error: This server appears not to support timed lock requests\n");
992 printf("server slept for %u seconds for a %u second timeout\n",
993 (unsigned int)(t2-t1), lock_timeout);
995 if (!cli_close(cli1, fnum2)) {
996 printf("close1 failed (%s)\n", cli_errstr(cli1));
1000 if (cli_lock(cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
1001 printf("lock4 succeeded! This is a locking bug\n");
1004 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
1005 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
1008 if (!cli_close(cli1, fnum1)) {
1009 printf("close2 failed (%s)\n", cli_errstr(cli1));
1013 if (!cli_close(cli2, fnum3)) {
1014 printf("close3 failed (%s)\n", cli_errstr(cli2));
1018 if (!cli_unlink(cli1, fname)) {
1019 printf("unlink failed (%s)\n", cli_errstr(cli1));
1024 if (!torture_close_connection(cli1)) {
1028 if (!torture_close_connection(cli2)) {
1032 printf("Passed locktest1\n");
1037 this checks to see if a secondary tconx can use open files from an
1040 static BOOL run_tcon_test(int dummy)
1042 static struct cli_state *cli;
1043 const char *fname = "\\tcontest.tmp";
1045 uint16 cnum1, cnum2, cnum3;
1046 uint16 vuid1, vuid2;
1050 if (!torture_open_connection(&cli, 0)) {
1053 cli_sockopt(cli, sockops);
1055 printf("starting tcontest\n");
1057 cli_unlink(cli, fname);
1059 fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1061 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
1068 if (cli_write(cli, fnum1, 0, buf, 130, 4) != 4) {
1069 printf("initial write failed (%s)", cli_errstr(cli));
1073 if (!cli_send_tconX(cli, share, "?????",
1074 password, strlen(password)+1)) {
1075 printf("%s refused 2nd tree connect (%s)\n", host,
1082 cnum3 = MAX(cnum1, cnum2) + 1; /* any invalid number */
1083 vuid2 = cli->vuid + 1;
1085 /* try a write with the wrong tid */
1088 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
1089 printf("* server allows write with wrong TID\n");
1092 printf("server fails write with wrong TID : %s\n", cli_errstr(cli));
1096 /* try a write with an invalid tid */
1099 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
1100 printf("* server allows write with invalid TID\n");
1103 printf("server fails write with invalid TID : %s\n", cli_errstr(cli));
1106 /* try a write with an invalid vuid */
1110 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
1111 printf("* server allows write with invalid VUID\n");
1114 printf("server fails write with invalid VUID : %s\n", cli_errstr(cli));
1120 if (!cli_close(cli, fnum1)) {
1121 printf("close failed (%s)\n", cli_errstr(cli));
1127 if (!cli_tdis(cli)) {
1128 printf("secondary tdis failed (%s)\n", cli_errstr(cli));
1134 if (!torture_close_connection(cli)) {
1143 checks for old style tcon support
1145 static BOOL run_tcon2_test(int dummy)
1147 static struct cli_state *cli;
1148 uint16 cnum, max_xmit;
1152 if (!torture_open_connection(&cli, 0)) {
1155 cli_sockopt(cli, sockops);
1157 printf("starting tcon2 test\n");
1159 asprintf(&service, "\\\\%s\\%s", host, share);
1161 status = cli_raw_tcon(cli, service, password, "?????", &max_xmit, &cnum);
1163 if (!NT_STATUS_IS_OK(status)) {
1164 printf("tcon2 failed : %s\n", cli_errstr(cli));
1166 printf("tcon OK : max_xmit=%d cnum=%d tid=%d\n",
1167 (int)max_xmit, (int)cnum, SVAL(cli->inbuf, smb_tid));
1170 if (!torture_close_connection(cli)) {
1174 printf("Passed tcon2 test\n");
1178 static BOOL tcon_devtest(struct cli_state *cli,
1179 const char *myshare, const char *devtype,
1180 const char *return_devtype,
1181 NTSTATUS expected_error)
1186 status = cli_send_tconX(cli, myshare, devtype,
1187 password, strlen(password)+1);
1189 if (NT_STATUS_IS_OK(expected_error)) {
1191 if (strcmp(cli->dev, return_devtype) == 0) {
1194 printf("tconX to share %s with type %s "
1195 "succeeded but returned the wrong "
1196 "device type (got [%s] but should have got [%s])\n",
1197 myshare, devtype, cli->dev, return_devtype);
1201 printf("tconX to share %s with type %s "
1202 "should have succeeded but failed\n",
1209 printf("tconx to share %s with type %s "
1210 "should have failed but succeeded\n",
1214 if (NT_STATUS_EQUAL(cli_nt_error(cli),
1218 printf("Returned unexpected error\n");
1227 checks for correct tconX support
1229 static BOOL run_tcon_devtype_test(int dummy)
1231 static struct cli_state *cli1 = NULL;
1237 status = cli_full_connection(&cli1, myname,
1238 host, NULL, port_to_use,
1240 username, workgroup,
1241 password, flags, Undefined, &retry);
1243 if (!NT_STATUS_IS_OK(status)) {
1244 printf("could not open connection\n");
1248 if (!tcon_devtest(cli1, "IPC$", "A:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1251 if (!tcon_devtest(cli1, "IPC$", "?????", "IPC", NT_STATUS_OK))
1254 if (!tcon_devtest(cli1, "IPC$", "LPT:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1257 if (!tcon_devtest(cli1, "IPC$", "IPC", "IPC", NT_STATUS_OK))
1260 if (!tcon_devtest(cli1, "IPC$", "FOOBA", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1263 if (!tcon_devtest(cli1, share, "A:", "A:", NT_STATUS_OK))
1266 if (!tcon_devtest(cli1, share, "?????", "A:", NT_STATUS_OK))
1269 if (!tcon_devtest(cli1, share, "LPT:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1272 if (!tcon_devtest(cli1, share, "IPC", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1275 if (!tcon_devtest(cli1, share, "FOOBA", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1281 printf("Passed tcondevtest\n");
1288 This test checks that
1290 1) the server supports multiple locking contexts on the one SMB
1291 connection, distinguished by PID.
1293 2) the server correctly fails overlapping locks made by the same PID (this
1294 goes against POSIX behaviour, which is why it is tricky to implement)
1296 3) the server denies unlock requests by an incorrect client PID
1298 static BOOL run_locktest2(int dummy)
1300 static struct cli_state *cli;
1301 const char *fname = "\\lockt2.lck";
1302 int fnum1, fnum2, fnum3;
1303 BOOL correct = True;
1305 if (!torture_open_connection(&cli, 0)) {
1309 cli_sockopt(cli, sockops);
1311 printf("starting locktest2\n");
1313 cli_unlink(cli, fname);
1317 fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1319 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
1323 fnum2 = cli_open(cli, fname, O_RDWR, DENY_NONE);
1325 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli));
1331 fnum3 = cli_open(cli, fname, O_RDWR, DENY_NONE);
1333 printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli));
1339 if (!cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
1340 printf("lock1 failed (%s)\n", cli_errstr(cli));
1344 if (cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
1345 printf("WRITE lock1 succeeded! This is a locking bug\n");
1348 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1349 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1352 if (cli_lock(cli, fnum2, 0, 4, 0, WRITE_LOCK)) {
1353 printf("WRITE lock2 succeeded! This is a locking bug\n");
1356 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1357 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1360 if (cli_lock(cli, fnum2, 0, 4, 0, READ_LOCK)) {
1361 printf("READ lock2 succeeded! This is a locking bug\n");
1364 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1365 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
1368 if (!cli_lock(cli, fnum1, 100, 4, 0, WRITE_LOCK)) {
1369 printf("lock at 100 failed (%s)\n", cli_errstr(cli));
1372 if (cli_unlock(cli, fnum1, 100, 4)) {
1373 printf("unlock at 100 succeeded! This is a locking bug\n");
1377 if (cli_unlock(cli, fnum1, 0, 4)) {
1378 printf("unlock1 succeeded! This is a locking bug\n");
1381 if (!check_error(__LINE__, cli,
1383 NT_STATUS_RANGE_NOT_LOCKED)) return False;
1386 if (cli_unlock(cli, fnum1, 0, 8)) {
1387 printf("unlock2 succeeded! This is a locking bug\n");
1390 if (!check_error(__LINE__, cli,
1392 NT_STATUS_RANGE_NOT_LOCKED)) return False;
1395 if (cli_lock(cli, fnum3, 0, 4, 0, WRITE_LOCK)) {
1396 printf("lock3 succeeded! This is a locking bug\n");
1399 if (!check_error(__LINE__, cli, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
1404 if (!cli_close(cli, fnum1)) {
1405 printf("close1 failed (%s)\n", cli_errstr(cli));
1409 if (!cli_close(cli, fnum2)) {
1410 printf("close2 failed (%s)\n", cli_errstr(cli));
1414 if (!cli_close(cli, fnum3)) {
1415 printf("close3 failed (%s)\n", cli_errstr(cli));
1419 if (!torture_close_connection(cli)) {
1423 printf("locktest2 finished\n");
1430 This test checks that
1432 1) the server supports the full offset range in lock requests
1434 static BOOL run_locktest3(int dummy)
1436 static struct cli_state *cli1, *cli2;
1437 const char *fname = "\\lockt3.lck";
1438 int fnum1, fnum2, i;
1440 BOOL correct = True;
1442 #define NEXT_OFFSET offset += (~(uint32)0) / torture_numops
1444 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1447 cli_sockopt(cli1, sockops);
1448 cli_sockopt(cli2, sockops);
1450 printf("starting locktest3\n");
1452 cli_unlink(cli1, fname);
1454 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1456 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
1459 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1461 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli2));
1465 for (offset=i=0;i<torture_numops;i++) {
1467 if (!cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1468 printf("lock1 %d failed (%s)\n",
1474 if (!cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1475 printf("lock2 %d failed (%s)\n",
1482 for (offset=i=0;i<torture_numops;i++) {
1485 if (cli_lock(cli1, fnum1, offset-2, 1, 0, WRITE_LOCK)) {
1486 printf("error: lock1 %d succeeded!\n", i);
1490 if (cli_lock(cli2, fnum2, offset-1, 1, 0, WRITE_LOCK)) {
1491 printf("error: lock2 %d succeeded!\n", i);
1495 if (cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1496 printf("error: lock3 %d succeeded!\n", i);
1500 if (cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1501 printf("error: lock4 %d succeeded!\n", i);
1506 for (offset=i=0;i<torture_numops;i++) {
1509 if (!cli_unlock(cli1, fnum1, offset-1, 1)) {
1510 printf("unlock1 %d failed (%s)\n",
1516 if (!cli_unlock(cli2, fnum2, offset-2, 1)) {
1517 printf("unlock2 %d failed (%s)\n",
1524 if (!cli_close(cli1, fnum1)) {
1525 printf("close1 failed (%s)\n", cli_errstr(cli1));
1529 if (!cli_close(cli2, fnum2)) {
1530 printf("close2 failed (%s)\n", cli_errstr(cli2));
1534 if (!cli_unlink(cli1, fname)) {
1535 printf("unlink failed (%s)\n", cli_errstr(cli1));
1539 if (!torture_close_connection(cli1)) {
1543 if (!torture_close_connection(cli2)) {
1547 printf("finished locktest3\n");
1552 #define EXPECTED(ret, v) if ((ret) != (v)) { \
1553 printf("** "); correct = False; \
1557 looks at overlapping locks
1559 static BOOL run_locktest4(int dummy)
1561 static struct cli_state *cli1, *cli2;
1562 const char *fname = "\\lockt4.lck";
1563 int fnum1, fnum2, f;
1566 BOOL correct = True;
1568 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1572 cli_sockopt(cli1, sockops);
1573 cli_sockopt(cli2, sockops);
1575 printf("starting locktest4\n");
1577 cli_unlink(cli1, fname);
1579 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1580 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1582 memset(buf, 0, sizeof(buf));
1584 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1585 printf("Failed to create file\n");
1590 ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1591 cli_lock(cli1, fnum1, 2, 4, 0, WRITE_LOCK);
1592 EXPECTED(ret, False);
1593 printf("the same process %s set overlapping write locks\n", ret?"can":"cannot");
1595 ret = cli_lock(cli1, fnum1, 10, 4, 0, READ_LOCK) &&
1596 cli_lock(cli1, fnum1, 12, 4, 0, READ_LOCK);
1597 EXPECTED(ret, True);
1598 printf("the same process %s set overlapping read locks\n", ret?"can":"cannot");
1600 ret = cli_lock(cli1, fnum1, 20, 4, 0, WRITE_LOCK) &&
1601 cli_lock(cli2, fnum2, 22, 4, 0, WRITE_LOCK);
1602 EXPECTED(ret, False);
1603 printf("a different connection %s set overlapping write locks\n", ret?"can":"cannot");
1605 ret = cli_lock(cli1, fnum1, 30, 4, 0, READ_LOCK) &&
1606 cli_lock(cli2, fnum2, 32, 4, 0, READ_LOCK);
1607 EXPECTED(ret, True);
1608 printf("a different connection %s set overlapping read locks\n", ret?"can":"cannot");
1610 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 40, 4, 0, WRITE_LOCK)) &&
1611 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 42, 4, 0, WRITE_LOCK));
1612 EXPECTED(ret, False);
1613 printf("a different pid %s set overlapping write locks\n", ret?"can":"cannot");
1615 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 50, 4, 0, READ_LOCK)) &&
1616 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 52, 4, 0, READ_LOCK));
1617 EXPECTED(ret, True);
1618 printf("a different pid %s set overlapping read locks\n", ret?"can":"cannot");
1620 ret = cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK) &&
1621 cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK);
1622 EXPECTED(ret, True);
1623 printf("the same process %s set the same read lock twice\n", ret?"can":"cannot");
1625 ret = cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK) &&
1626 cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK);
1627 EXPECTED(ret, False);
1628 printf("the same process %s set the same write lock twice\n", ret?"can":"cannot");
1630 ret = cli_lock(cli1, fnum1, 80, 4, 0, READ_LOCK) &&
1631 cli_lock(cli1, fnum1, 80, 4, 0, WRITE_LOCK);
1632 EXPECTED(ret, False);
1633 printf("the same process %s overlay a read lock with a write lock\n", ret?"can":"cannot");
1635 ret = cli_lock(cli1, fnum1, 90, 4, 0, WRITE_LOCK) &&
1636 cli_lock(cli1, fnum1, 90, 4, 0, READ_LOCK);
1637 EXPECTED(ret, True);
1638 printf("the same process %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1640 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 100, 4, 0, WRITE_LOCK)) &&
1641 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 100, 4, 0, READ_LOCK));
1642 EXPECTED(ret, False);
1643 printf("a different pid %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1645 ret = cli_lock(cli1, fnum1, 110, 4, 0, READ_LOCK) &&
1646 cli_lock(cli1, fnum1, 112, 4, 0, READ_LOCK) &&
1647 cli_unlock(cli1, fnum1, 110, 6);
1648 EXPECTED(ret, False);
1649 printf("the same process %s coalesce read locks\n", ret?"can":"cannot");
1652 ret = cli_lock(cli1, fnum1, 120, 4, 0, WRITE_LOCK) &&
1653 (cli_read(cli2, fnum2, buf, 120, 4) == 4);
1654 EXPECTED(ret, False);
1655 printf("this server %s strict write locking\n", ret?"doesn't do":"does");
1657 ret = cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK) &&
1658 (cli_write(cli2, fnum2, 0, buf, 130, 4) == 4);
1659 EXPECTED(ret, False);
1660 printf("this server %s strict read locking\n", ret?"doesn't do":"does");
1663 ret = cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1664 cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1665 cli_unlock(cli1, fnum1, 140, 4) &&
1666 cli_unlock(cli1, fnum1, 140, 4);
1667 EXPECTED(ret, True);
1668 printf("this server %s do recursive read locking\n", ret?"does":"doesn't");
1671 ret = cli_lock(cli1, fnum1, 150, 4, 0, WRITE_LOCK) &&
1672 cli_lock(cli1, fnum1, 150, 4, 0, READ_LOCK) &&
1673 cli_unlock(cli1, fnum1, 150, 4) &&
1674 (cli_read(cli2, fnum2, buf, 150, 4) == 4) &&
1675 !(cli_write(cli2, fnum2, 0, buf, 150, 4) == 4) &&
1676 cli_unlock(cli1, fnum1, 150, 4);
1677 EXPECTED(ret, True);
1678 printf("this server %s do recursive lock overlays\n", ret?"does":"doesn't");
1680 ret = cli_lock(cli1, fnum1, 160, 4, 0, READ_LOCK) &&
1681 cli_unlock(cli1, fnum1, 160, 4) &&
1682 (cli_write(cli2, fnum2, 0, buf, 160, 4) == 4) &&
1683 (cli_read(cli2, fnum2, buf, 160, 4) == 4);
1684 EXPECTED(ret, True);
1685 printf("the same process %s remove a read lock using write locking\n", ret?"can":"cannot");
1687 ret = cli_lock(cli1, fnum1, 170, 4, 0, WRITE_LOCK) &&
1688 cli_unlock(cli1, fnum1, 170, 4) &&
1689 (cli_write(cli2, fnum2, 0, buf, 170, 4) == 4) &&
1690 (cli_read(cli2, fnum2, buf, 170, 4) == 4);
1691 EXPECTED(ret, True);
1692 printf("the same process %s remove a write lock using read locking\n", ret?"can":"cannot");
1694 ret = cli_lock(cli1, fnum1, 190, 4, 0, WRITE_LOCK) &&
1695 cli_lock(cli1, fnum1, 190, 4, 0, READ_LOCK) &&
1696 cli_unlock(cli1, fnum1, 190, 4) &&
1697 !(cli_write(cli2, fnum2, 0, buf, 190, 4) == 4) &&
1698 (cli_read(cli2, fnum2, buf, 190, 4) == 4);
1699 EXPECTED(ret, True);
1700 printf("the same process %s remove the first lock first\n", ret?"does":"doesn't");
1702 cli_close(cli1, fnum1);
1703 cli_close(cli2, fnum2);
1704 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1705 f = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1706 ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1707 cli_lock(cli1, f, 0, 1, 0, READ_LOCK) &&
1708 cli_close(cli1, fnum1) &&
1709 ((fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE)) != -1) &&
1710 cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1712 cli_close(cli1, fnum1);
1713 EXPECTED(ret, True);
1714 printf("the server %s have the NT byte range lock bug\n", !ret?"does":"doesn't");
1717 cli_close(cli1, fnum1);
1718 cli_close(cli2, fnum2);
1719 cli_unlink(cli1, fname);
1720 torture_close_connection(cli1);
1721 torture_close_connection(cli2);
1723 printf("finished locktest4\n");
1728 looks at lock upgrade/downgrade.
1730 static BOOL run_locktest5(int dummy)
1732 static struct cli_state *cli1, *cli2;
1733 const char *fname = "\\lockt5.lck";
1734 int fnum1, fnum2, fnum3;
1737 BOOL correct = True;
1739 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1743 cli_sockopt(cli1, sockops);
1744 cli_sockopt(cli2, sockops);
1746 printf("starting locktest5\n");
1748 cli_unlink(cli1, fname);
1750 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1751 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1752 fnum3 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1754 memset(buf, 0, sizeof(buf));
1756 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1757 printf("Failed to create file\n");
1762 /* Check for NT bug... */
1763 ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1764 cli_lock(cli1, fnum3, 0, 1, 0, READ_LOCK);
1765 cli_close(cli1, fnum1);
1766 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1767 ret = cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1768 EXPECTED(ret, True);
1769 printf("this server %s the NT locking bug\n", ret ? "doesn't have" : "has");
1770 cli_close(cli1, fnum1);
1771 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1772 cli_unlock(cli1, fnum3, 0, 1);
1774 ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1775 cli_lock(cli1, fnum1, 1, 1, 0, READ_LOCK);
1776 EXPECTED(ret, True);
1777 printf("the same process %s overlay a write with a read lock\n", ret?"can":"cannot");
1779 ret = cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK);
1780 EXPECTED(ret, False);
1782 printf("a different processs %s get a read lock on the first process lock stack\n", ret?"can":"cannot");
1784 /* Unlock the process 2 lock. */
1785 cli_unlock(cli2, fnum2, 0, 4);
1787 ret = cli_lock(cli1, fnum3, 0, 4, 0, READ_LOCK);
1788 EXPECTED(ret, False);
1790 printf("the same processs on a different fnum %s get a read lock\n", ret?"can":"cannot");
1792 /* Unlock the process 1 fnum3 lock. */
1793 cli_unlock(cli1, fnum3, 0, 4);
1795 /* Stack 2 more locks here. */
1796 ret = cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK) &&
1797 cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK);
1799 EXPECTED(ret, True);
1800 printf("the same process %s stack read locks\n", ret?"can":"cannot");
1802 /* Unlock the first process lock, then check this was the WRITE lock that was
1805 ret = cli_unlock(cli1, fnum1, 0, 4) &&
1806 cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK);
1808 EXPECTED(ret, True);
1809 printf("the first unlock removes the %s lock\n", ret?"WRITE":"READ");
1811 /* Unlock the process 2 lock. */
1812 cli_unlock(cli2, fnum2, 0, 4);
1814 /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */
1816 ret = cli_unlock(cli1, fnum1, 1, 1) &&
1817 cli_unlock(cli1, fnum1, 0, 4) &&
1818 cli_unlock(cli1, fnum1, 0, 4);
1820 EXPECTED(ret, True);
1821 printf("the same process %s unlock the stack of 4 locks\n", ret?"can":"cannot");
1823 /* Ensure the next unlock fails. */
1824 ret = cli_unlock(cli1, fnum1, 0, 4);
1825 EXPECTED(ret, False);
1826 printf("the same process %s count the lock stack\n", !ret?"can":"cannot");
1828 /* Ensure connection 2 can get a write lock. */
1829 ret = cli_lock(cli2, fnum2, 0, 4, 0, WRITE_LOCK);
1830 EXPECTED(ret, True);
1832 printf("a different processs %s get a write lock on the unlocked stack\n", ret?"can":"cannot");
1836 cli_close(cli1, fnum1);
1837 cli_close(cli2, fnum2);
1838 cli_unlink(cli1, fname);
1839 if (!torture_close_connection(cli1)) {
1842 if (!torture_close_connection(cli2)) {
1846 printf("finished locktest5\n");
1852 tries the unusual lockingX locktype bits
1854 static BOOL run_locktest6(int dummy)
1856 static struct cli_state *cli;
1857 const char *fname[1] = { "\\lock6.txt" };
1862 if (!torture_open_connection(&cli, 0)) {
1866 cli_sockopt(cli, sockops);
1868 printf("starting locktest6\n");
1871 printf("Testing %s\n", fname[i]);
1873 cli_unlink(cli, fname[i]);
1875 fnum = cli_open(cli, fname[i], O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1876 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE);
1877 cli_close(cli, fnum);
1878 printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status));
1880 fnum = cli_open(cli, fname[i], O_RDWR, DENY_NONE);
1881 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK);
1882 cli_close(cli, fnum);
1883 printf("CANCEL_LOCK gave %s\n", nt_errstr(status));
1885 cli_unlink(cli, fname[i]);
1888 torture_close_connection(cli);
1890 printf("finished locktest6\n");
1894 static BOOL run_locktest7(int dummy)
1896 struct cli_state *cli1;
1897 const char *fname = "\\lockt7.lck";
1900 BOOL correct = False;
1902 if (!torture_open_connection(&cli1, 0)) {
1906 cli_sockopt(cli1, sockops);
1908 printf("starting locktest7\n");
1910 cli_unlink(cli1, fname);
1912 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1914 memset(buf, 0, sizeof(buf));
1916 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1917 printf("Failed to create file\n");
1921 cli_setpid(cli1, 1);
1923 if (!cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK)) {
1924 printf("Unable to apply read lock on range 130:4, error was %s\n", cli_errstr(cli1));
1927 printf("pid1 successfully locked range 130:4 for READ\n");
1930 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1931 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1934 printf("pid1 successfully read the range 130:4\n");
1937 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1938 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1939 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1940 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1944 printf("pid1 successfully wrote to the range 130:4 (should be denied)\n");
1948 cli_setpid(cli1, 2);
1950 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1951 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1953 printf("pid2 successfully read the range 130:4\n");
1956 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1957 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1958 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1959 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1963 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
1967 cli_setpid(cli1, 1);
1968 cli_unlock(cli1, fnum1, 130, 4);
1970 if (!cli_lock(cli1, fnum1, 130, 4, 0, WRITE_LOCK)) {
1971 printf("Unable to apply write lock on range 130:4, error was %s\n", cli_errstr(cli1));
1974 printf("pid1 successfully locked range 130:4 for WRITE\n");
1977 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1978 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1981 printf("pid1 successfully read the range 130:4\n");
1984 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1985 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1988 printf("pid1 successfully wrote to the range 130:4\n");
1991 cli_setpid(cli1, 2);
1993 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1994 printf("pid2 unable to read 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("pid2 successfully read the range 130:4 (should be denied)\n");
2004 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
2005 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
2006 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
2007 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2011 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
2015 cli_unlock(cli1, fnum1, 130, 0);
2019 cli_close(cli1, fnum1);
2020 cli_unlink(cli1, fname);
2021 torture_close_connection(cli1);
2023 printf("finished locktest7\n");
2028 test whether fnums and tids open on one VC are available on another (a major
2031 static BOOL run_fdpasstest(int dummy)
2033 struct cli_state *cli1, *cli2;
2034 const char *fname = "\\fdpass.tst";
2038 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
2041 cli_sockopt(cli1, sockops);
2042 cli_sockopt(cli2, sockops);
2044 printf("starting fdpasstest\n");
2046 cli_unlink(cli1, fname);
2048 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2050 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2054 if (cli_write(cli1, fnum1, 0, "hello world\n", 0, 13) != 13) {
2055 printf("write failed (%s)\n", cli_errstr(cli1));
2059 cli2->vuid = cli1->vuid;
2060 cli2->cnum = cli1->cnum;
2061 cli2->pid = cli1->pid;
2063 if (cli_read(cli2, fnum1, buf, 0, 13) == 13) {
2064 printf("read succeeded! nasty security hole [%s]\n",
2069 cli_close(cli1, fnum1);
2070 cli_unlink(cli1, fname);
2072 torture_close_connection(cli1);
2073 torture_close_connection(cli2);
2075 printf("finished fdpasstest\n");
2079 static BOOL run_fdsesstest(int dummy)
2081 struct cli_state *cli;
2086 const char *fname = "\\fdsess.tst";
2087 const char *fname1 = "\\fdsess1.tst";
2093 if (!torture_open_connection(&cli, 0))
2095 cli_sockopt(cli, sockops);
2097 if (!torture_cli_session_setup2(cli, &new_vuid))
2100 saved_cnum = cli->cnum;
2101 if (!cli_send_tconX(cli, share, "?????", "", 1))
2103 new_cnum = cli->cnum;
2104 cli->cnum = saved_cnum;
2106 printf("starting fdsesstest\n");
2108 cli_unlink(cli, fname);
2109 cli_unlink(cli, fname1);
2111 fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2113 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
2117 if (cli_write(cli, fnum1, 0, "hello world\n", 0, 13) != 13) {
2118 printf("write failed (%s)\n", cli_errstr(cli));
2122 saved_vuid = cli->vuid;
2123 cli->vuid = new_vuid;
2125 if (cli_read(cli, fnum1, buf, 0, 13) == 13) {
2126 printf("read succeeded with different vuid! nasty security hole [%s]\n",
2130 /* Try to open a file with different vuid, samba cnum. */
2131 fnum2 = cli_open(cli, fname1, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2133 printf("create with different vuid, same cnum succeeded.\n");
2134 cli_close(cli, fnum2);
2135 cli_unlink(cli, fname1);
2137 printf("create with different vuid, same cnum failed.\n");
2138 printf("This will cause problems with service clients.\n");
2142 cli->vuid = saved_vuid;
2144 /* Try with same vuid, different cnum. */
2145 cli->cnum = new_cnum;
2147 if (cli_read(cli, fnum1, buf, 0, 13) == 13) {
2148 printf("read succeeded with different cnum![%s]\n",
2153 cli->cnum = saved_cnum;
2154 cli_close(cli, fnum1);
2155 cli_unlink(cli, fname);
2157 torture_close_connection(cli);
2159 printf("finished fdsesstest\n");
2164 This test checks that
2166 1) the server does not allow an unlink on a file that is open
2168 static BOOL run_unlinktest(int dummy)
2170 struct cli_state *cli;
2171 const char *fname = "\\unlink.tst";
2173 BOOL correct = True;
2175 if (!torture_open_connection(&cli, 0)) {
2179 cli_sockopt(cli, sockops);
2181 printf("starting unlink test\n");
2183 cli_unlink(cli, fname);
2187 fnum = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2189 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
2193 if (cli_unlink(cli, fname)) {
2194 printf("error: server allowed unlink on an open file\n");
2197 correct = check_error(__LINE__, cli, ERRDOS, ERRbadshare,
2198 NT_STATUS_SHARING_VIOLATION);
2201 cli_close(cli, fnum);
2202 cli_unlink(cli, fname);
2204 if (!torture_close_connection(cli)) {
2208 printf("unlink test finished\n");
2215 test how many open files this server supports on the one socket
2217 static BOOL run_maxfidtest(int dummy)
2219 struct cli_state *cli;
2220 const char *ftemplate = "\\maxfid.%d.%d";
2222 int fnums[0x11000], i;
2224 BOOL correct = True;
2229 printf("failed to connect\n");
2233 cli_sockopt(cli, sockops);
2235 for (i=0; i<0x11000; i++) {
2236 slprintf(fname,sizeof(fname)-1,ftemplate, i,(int)getpid());
2237 if ((fnums[i] = cli_open(cli, fname,
2238 O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) ==
2240 printf("open of %s failed (%s)\n",
2241 fname, cli_errstr(cli));
2242 printf("maximum fnum is %d\n", i);
2250 printf("cleaning up\n");
2252 slprintf(fname,sizeof(fname)-1,ftemplate, i,(int)getpid());
2253 cli_close(cli, fnums[i]);
2254 if (!cli_unlink(cli, fname)) {
2255 printf("unlink of %s failed (%s)\n",
2256 fname, cli_errstr(cli));
2263 printf("maxfid test finished\n");
2264 if (!torture_close_connection(cli)) {
2270 /* generate a random buffer */
2271 static void rand_buf(char *buf, int len)
2274 *buf = (char)sys_random();
2279 /* send smb negprot commands, not reading the response */
2280 static BOOL run_negprot_nowait(int dummy)
2283 static struct cli_state *cli;
2284 BOOL correct = True;
2286 printf("starting negprot nowait test\n");
2288 if (!(cli = open_nbt_connection())) {
2292 for (i=0;i<50000;i++) {
2293 cli_negprot_send(cli);
2296 if (!torture_close_connection(cli)) {
2300 printf("finished negprot nowait test\n");
2306 /* send random IPC commands */
2307 static BOOL run_randomipc(int dummy)
2309 char *rparam = NULL;
2311 unsigned int rdrcnt,rprcnt;
2313 int api, param_len, i;
2314 struct cli_state *cli;
2315 BOOL correct = True;
2318 printf("starting random ipc test\n");
2320 if (!torture_open_connection(&cli, 0)) {
2324 for (i=0;i<count;i++) {
2325 api = sys_random() % 500;
2326 param_len = (sys_random() % 64);
2328 rand_buf(param, param_len);
2333 param, param_len, 8,
2334 NULL, 0, BUFFER_SIZE,
2338 printf("%d/%d\r", i,count);
2341 printf("%d/%d\n", i, count);
2343 if (!torture_close_connection(cli)) {
2347 printf("finished random ipc test\n");
2354 static void browse_callback(const char *sname, uint32 stype,
2355 const char *comment, void *state)
2357 printf("\t%20.20s %08x %s\n", sname, stype, comment);
2363 This test checks the browse list code
2366 static BOOL run_browsetest(int dummy)
2368 static struct cli_state *cli;
2369 BOOL correct = True;
2371 printf("starting browse test\n");
2373 if (!torture_open_connection(&cli, 0)) {
2377 printf("domain list:\n");
2378 cli_NetServerEnum(cli, cli->server_domain,
2379 SV_TYPE_DOMAIN_ENUM,
2380 browse_callback, NULL);
2382 printf("machine list:\n");
2383 cli_NetServerEnum(cli, cli->server_domain,
2385 browse_callback, NULL);
2387 if (!torture_close_connection(cli)) {
2391 printf("browse test finished\n");
2399 This checks how the getatr calls works
2401 static BOOL run_attrtest(int dummy)
2403 struct cli_state *cli;
2406 const char *fname = "\\attrib123456789.tst";
2407 BOOL correct = True;
2409 printf("starting attrib test\n");
2411 if (!torture_open_connection(&cli, 0)) {
2415 cli_unlink(cli, fname);
2416 fnum = cli_open(cli, fname,
2417 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2418 cli_close(cli, fnum);
2419 if (!cli_getatr(cli, fname, NULL, NULL, &t)) {
2420 printf("getatr failed (%s)\n", cli_errstr(cli));
2424 if (abs(t - time(NULL)) > 60*60*24*10) {
2425 printf("ERROR: SMBgetatr bug. time is %s",
2431 t2 = t-60*60*24; /* 1 day ago */
2433 if (!cli_setatr(cli, fname, 0, t2)) {
2434 printf("setatr failed (%s)\n", cli_errstr(cli));
2438 if (!cli_getatr(cli, fname, NULL, NULL, &t)) {
2439 printf("getatr failed (%s)\n", cli_errstr(cli));
2444 printf("ERROR: getatr/setatr bug. times are\n%s",
2446 printf("%s", ctime(&t2));
2450 cli_unlink(cli, fname);
2452 if (!torture_close_connection(cli)) {
2456 printf("attrib test finished\n");
2463 This checks a couple of trans2 calls
2465 static BOOL run_trans2test(int dummy)
2467 struct cli_state *cli;
2470 time_t c_time, a_time, m_time, m_time2;
2471 struct timespec c_time_ts, a_time_ts, m_time_ts, w_time_ts, m_time2_ts;
2472 const char *fname = "\\trans2.tst";
2473 const char *dname = "\\trans2";
2474 const char *fname2 = "\\trans2\\trans2.tst";
2476 BOOL correct = True;
2478 printf("starting trans2 test\n");
2480 if (!torture_open_connection(&cli, 0)) {
2484 cli_unlink(cli, fname);
2485 fnum = cli_open(cli, fname,
2486 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2487 if (!cli_qfileinfo(cli, fnum, NULL, &size, &c_time_ts, &a_time_ts, &w_time_ts,
2488 &m_time_ts, NULL)) {
2489 printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(cli));
2493 if (!cli_qfilename(cli, fnum, pname)) {
2494 printf("ERROR: qfilename failed (%s)\n", cli_errstr(cli));
2498 if (strcmp(pname, fname)) {
2499 printf("qfilename gave different name? [%s] [%s]\n",
2504 cli_close(cli, fnum);
2508 cli_unlink(cli, fname);
2509 fnum = cli_open(cli, fname,
2510 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2512 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
2515 cli_close(cli, fnum);
2517 if (!cli_qpathinfo(cli, fname, &c_time, &a_time, &m_time, &size, NULL)) {
2518 printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(cli));
2521 if (c_time != m_time) {
2522 printf("create time=%s", ctime(&c_time));
2523 printf("modify time=%s", ctime(&m_time));
2524 printf("This system appears to have sticky create times\n");
2526 if (a_time % (60*60) == 0) {
2527 printf("access time=%s", ctime(&a_time));
2528 printf("This system appears to set a midnight access time\n");
2532 if (abs(m_time - time(NULL)) > 60*60*24*7) {
2533 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
2539 cli_unlink(cli, fname);
2540 fnum = cli_open(cli, fname,
2541 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2542 cli_close(cli, fnum);
2543 if (!cli_qpathinfo2(cli, fname, &c_time_ts, &a_time_ts, &w_time_ts,
2544 &m_time_ts, &size, NULL, NULL)) {
2545 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2548 if (w_time_ts.tv_sec < 60*60*24*2) {
2549 printf("write time=%s", ctime(&w_time_ts.tv_sec));
2550 printf("This system appears to set a initial 0 write time\n");
2555 cli_unlink(cli, fname);
2558 /* check if the server updates the directory modification time
2559 when creating a new file */
2560 if (!cli_mkdir(cli, dname)) {
2561 printf("ERROR: mkdir failed (%s)\n", cli_errstr(cli));
2565 if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts, &w_time_ts,
2566 &m_time_ts, &size, NULL, NULL)) {
2567 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2571 fnum = cli_open(cli, fname2,
2572 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2573 cli_write(cli, fnum, 0, (char *)&fnum, 0, sizeof(fnum));
2574 cli_close(cli, fnum);
2575 if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts, &w_time_ts,
2576 &m_time2_ts, &size, NULL, NULL)) {
2577 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2580 if (m_time2 == m_time) {
2581 printf("This system does not update directory modification times\n");
2585 cli_unlink(cli, fname2);
2586 cli_rmdir(cli, dname);
2588 if (!torture_close_connection(cli)) {
2592 printf("trans2 test finished\n");
2598 This checks new W2K calls.
2601 static BOOL new_trans(struct cli_state *pcli, int fnum, int level)
2605 BOOL correct = True;
2607 if (!cli_qfileinfo_test(pcli, fnum, level, &buf, &len)) {
2608 printf("ERROR: qfileinfo (%d) failed (%s)\n", level, cli_errstr(pcli));
2611 printf("qfileinfo: level %d, len = %u\n", level, len);
2612 dump_data(0, buf, len);
2619 static BOOL run_w2ktest(int dummy)
2621 struct cli_state *cli;
2623 const char *fname = "\\w2ktest\\w2k.tst";
2625 BOOL correct = True;
2627 printf("starting w2k test\n");
2629 if (!torture_open_connection(&cli, 0)) {
2633 fnum = cli_open(cli, fname,
2634 O_RDWR | O_CREAT , DENY_NONE);
2636 for (level = 1004; level < 1040; level++) {
2637 new_trans(cli, fnum, level);
2640 cli_close(cli, fnum);
2642 if (!torture_close_connection(cli)) {
2646 printf("w2k test finished\n");
2653 this is a harness for some oplock tests
2655 static BOOL run_oplock1(int dummy)
2657 struct cli_state *cli1;
2658 const char *fname = "\\lockt1.lck";
2660 BOOL correct = True;
2662 printf("starting oplock test 1\n");
2664 if (!torture_open_connection(&cli1, 0)) {
2668 cli_unlink(cli1, fname);
2670 cli_sockopt(cli1, sockops);
2672 cli1->use_oplocks = True;
2674 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2676 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2680 cli1->use_oplocks = False;
2682 cli_unlink(cli1, fname);
2683 cli_unlink(cli1, fname);
2685 if (!cli_close(cli1, fnum1)) {
2686 printf("close2 failed (%s)\n", cli_errstr(cli1));
2690 if (!cli_unlink(cli1, fname)) {
2691 printf("unlink failed (%s)\n", cli_errstr(cli1));
2695 if (!torture_close_connection(cli1)) {
2699 printf("finished oplock test 1\n");
2704 static BOOL run_oplock2(int dummy)
2706 struct cli_state *cli1, *cli2;
2707 const char *fname = "\\lockt2.lck";
2709 int saved_use_oplocks = use_oplocks;
2711 BOOL correct = True;
2712 volatile BOOL *shared_correct;
2714 shared_correct = (volatile BOOL *)shm_setup(sizeof(BOOL));
2715 *shared_correct = True;
2717 use_level_II_oplocks = True;
2720 printf("starting oplock test 2\n");
2722 if (!torture_open_connection(&cli1, 0)) {
2723 use_level_II_oplocks = False;
2724 use_oplocks = saved_use_oplocks;
2728 cli1->use_oplocks = True;
2729 cli1->use_level_II_oplocks = True;
2731 if (!torture_open_connection(&cli2, 1)) {
2732 use_level_II_oplocks = False;
2733 use_oplocks = saved_use_oplocks;
2737 cli2->use_oplocks = True;
2738 cli2->use_level_II_oplocks = True;
2740 cli_unlink(cli1, fname);
2742 cli_sockopt(cli1, sockops);
2743 cli_sockopt(cli2, sockops);
2745 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2747 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2751 /* Don't need the globals any more. */
2752 use_level_II_oplocks = False;
2753 use_oplocks = saved_use_oplocks;
2757 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
2759 printf("second open of %s failed (%s)\n", fname, cli_errstr(cli1));
2760 *shared_correct = False;
2766 if (!cli_close(cli2, fnum2)) {
2767 printf("close2 failed (%s)\n", cli_errstr(cli1));
2768 *shared_correct = False;
2776 /* Ensure cli1 processes the break. Empty file should always return 0
2779 if (cli_read(cli1, fnum1, buf, 0, 4) != 0) {
2780 printf("read on fnum1 failed (%s)\n", cli_errstr(cli1));
2784 /* Should now be at level II. */
2785 /* Test if sending a write locks causes a break to none. */
2787 if (!cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK)) {
2788 printf("lock failed (%s)\n", cli_errstr(cli1));
2792 cli_unlock(cli1, fnum1, 0, 4);
2796 if (!cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
2797 printf("lock failed (%s)\n", cli_errstr(cli1));
2801 cli_unlock(cli1, fnum1, 0, 4);
2805 cli_read(cli1, fnum1, buf, 0, 4);
2808 if (cli_write(cli1, fnum1, 0, buf, 0, 4) != 4) {
2809 printf("write on fnum1 failed (%s)\n", cli_errstr(cli1));
2814 if (!cli_close(cli1, fnum1)) {
2815 printf("close1 failed (%s)\n", cli_errstr(cli1));
2821 if (!cli_unlink(cli1, fname)) {
2822 printf("unlink failed (%s)\n", cli_errstr(cli1));
2826 if (!torture_close_connection(cli1)) {
2830 if (!*shared_correct) {
2834 printf("finished oplock test 2\n");
2839 /* handler for oplock 3 tests */
2840 static BOOL oplock3_handler(struct cli_state *cli, int fnum, unsigned char level)
2842 printf("got oplock break fnum=%d level=%d\n",
2844 return cli_oplock_ack(cli, fnum, level);
2847 static BOOL run_oplock3(int dummy)
2849 struct cli_state *cli;
2850 const char *fname = "\\oplockt3.dat";
2852 char buf[4] = "abcd";
2853 BOOL correct = True;
2854 volatile BOOL *shared_correct;
2856 shared_correct = (volatile BOOL *)shm_setup(sizeof(BOOL));
2857 *shared_correct = True;
2859 printf("starting oplock test 3\n");
2864 use_level_II_oplocks = True;
2865 if (!torture_open_connection(&cli, 0)) {
2866 *shared_correct = False;
2870 /* try to trigger a oplock break in parent */
2871 fnum = cli_open(cli, fname, O_RDWR, DENY_NONE);
2872 cli_write(cli, fnum, 0, buf, 0, 4);
2878 use_level_II_oplocks = True;
2879 if (!torture_open_connection(&cli, 1)) { /* other is forked */
2882 cli_oplock_handler(cli, oplock3_handler);
2883 fnum = cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE);
2884 cli_write(cli, fnum, 0, buf, 0, 4);
2885 cli_close(cli, fnum);
2886 fnum = cli_open(cli, fname, O_RDWR, DENY_NONE);
2887 cli->timeout = 20000;
2888 cli_receive_smb(cli);
2889 printf("finished oplock test 3\n");
2891 return (correct && *shared_correct);
2893 /* What are we looking for here? What's sucess and what's FAILURE? */
2899 Test delete on close semantics.
2901 static BOOL run_deletetest(int dummy)
2903 struct cli_state *cli1 = NULL;
2904 struct cli_state *cli2 = NULL;
2905 const char *fname = "\\delete.file";
2908 BOOL correct = True;
2910 printf("starting delete test\n");
2912 if (!torture_open_connection(&cli1, 0)) {
2916 cli_sockopt(cli1, sockops);
2918 /* Test 1 - this should delete the file on close. */
2920 cli_setatr(cli1, fname, 0, 0);
2921 cli_unlink(cli1, fname);
2923 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
2924 0, FILE_OVERWRITE_IF,
2925 FILE_DELETE_ON_CLOSE, 0);
2928 printf("[1] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2935 uint32 *accinfo = NULL;
2937 cli_qfileinfo_test(cli1, fnum1, SMB_FILE_ACCESS_INFORMATION, (char **)&accinfo, &len);
2939 printf("access mode = 0x%lx\n", *accinfo);
2944 if (!cli_close(cli1, fnum1)) {
2945 printf("[1] close failed (%s)\n", cli_errstr(cli1));
2950 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
2952 printf("[1] open of %s succeeded (should fail)\n", fname);
2957 printf("first delete on close test succeeded.\n");
2959 /* Test 2 - this should delete the file on close. */
2961 cli_setatr(cli1, fname, 0, 0);
2962 cli_unlink(cli1, fname);
2964 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_ALL_ACCESS,
2965 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
2966 FILE_OVERWRITE_IF, 0, 0);
2969 printf("[2] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2974 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
2975 printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
2980 if (!cli_close(cli1, fnum1)) {
2981 printf("[2] close failed (%s)\n", cli_errstr(cli1));
2986 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
2988 printf("[2] open of %s succeeded should have been deleted on close !\n", fname);
2989 if (!cli_close(cli1, fnum1)) {
2990 printf("[2] close failed (%s)\n", cli_errstr(cli1));
2994 cli_unlink(cli1, fname);
2996 printf("second delete on close test succeeded.\n");
2999 cli_setatr(cli1, fname, 0, 0);
3000 cli_unlink(cli1, fname);
3002 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
3003 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0);
3006 printf("[3] open - 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3011 /* This should fail with a sharing violation - open for delete is only compatible
3012 with SHARE_DELETE. */
3014 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3015 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0, 0);
3018 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname);
3023 /* This should succeed. */
3025 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3026 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0, 0);
3029 printf("[3] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
3034 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
3035 printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
3040 if (!cli_close(cli1, fnum1)) {
3041 printf("[3] close 1 failed (%s)\n", cli_errstr(cli1));
3046 if (!cli_close(cli1, fnum2)) {
3047 printf("[3] close 2 failed (%s)\n", cli_errstr(cli1));
3052 /* This should fail - file should no longer be there. */
3054 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
3056 printf("[3] open of %s succeeded should have been deleted on close !\n", fname);
3057 if (!cli_close(cli1, fnum1)) {
3058 printf("[3] close failed (%s)\n", cli_errstr(cli1));
3060 cli_unlink(cli1, fname);
3064 printf("third delete on close test succeeded.\n");
3067 cli_setatr(cli1, fname, 0, 0);
3068 cli_unlink(cli1, fname);
3070 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3071 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0);
3074 printf("[4] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3079 /* This should succeed. */
3080 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS,
3081 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0, 0);
3083 printf("[4] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
3088 if (!cli_close(cli1, fnum2)) {
3089 printf("[4] close - 1 failed (%s)\n", cli_errstr(cli1));
3094 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
3095 printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
3100 /* This should fail - no more opens once delete on close set. */
3101 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS,
3102 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3105 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname );
3109 printf("fourth delete on close test succeeded.\n");
3111 if (!cli_close(cli1, fnum1)) {
3112 printf("[4] close - 2 failed (%s)\n", cli_errstr(cli1));
3118 cli_setatr(cli1, fname, 0, 0);
3119 cli_unlink(cli1, fname);
3121 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT, DENY_NONE);
3123 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3128 /* This should fail - only allowed on NT opens with DELETE access. */
3130 if (cli_nt_delete_on_close(cli1, fnum1, True)) {
3131 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
3136 if (!cli_close(cli1, fnum1)) {
3137 printf("[5] close - 2 failed (%s)\n", cli_errstr(cli1));
3142 printf("fifth delete on close test succeeded.\n");
3145 cli_setatr(cli1, fname, 0, 0);
3146 cli_unlink(cli1, fname);
3148 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
3149 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3150 FILE_OVERWRITE_IF, 0, 0);
3153 printf("[6] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3158 /* This should fail - only allowed on NT opens with DELETE access. */
3160 if (cli_nt_delete_on_close(cli1, fnum1, True)) {
3161 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
3166 if (!cli_close(cli1, fnum1)) {
3167 printf("[6] close - 2 failed (%s)\n", cli_errstr(cli1));
3172 printf("sixth delete on close test succeeded.\n");
3175 cli_setatr(cli1, fname, 0, 0);
3176 cli_unlink(cli1, fname);
3178 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3179 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0, 0);
3182 printf("[7] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3187 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
3188 printf("[7] setting delete_on_close on file failed !\n");
3193 if (!cli_nt_delete_on_close(cli1, fnum1, False)) {
3194 printf("[7] unsetting delete_on_close on file failed !\n");
3199 if (!cli_close(cli1, fnum1)) {
3200 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
3205 /* This next open should succeed - we reset the flag. */
3207 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
3209 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3214 if (!cli_close(cli1, fnum1)) {
3215 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
3220 printf("seventh delete on close test succeeded.\n");
3223 cli_setatr(cli1, fname, 0, 0);
3224 cli_unlink(cli1, fname);
3226 if (!torture_open_connection(&cli2, 1)) {
3227 printf("[8] failed to open second connection.\n");
3232 cli_sockopt(cli1, sockops);
3234 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3235 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3236 FILE_OVERWRITE_IF, 0, 0);
3239 printf("[8] open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3244 fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3245 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3249 printf("[8] open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3254 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
3255 printf("[8] setting delete_on_close on file failed !\n");
3260 if (!cli_close(cli1, fnum1)) {
3261 printf("[8] close - 1 failed (%s)\n", cli_errstr(cli1));
3266 if (!cli_close(cli2, fnum2)) {
3267 printf("[8] close - 2 failed (%s)\n", cli_errstr(cli2));
3272 /* This should fail.. */
3273 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
3275 printf("[8] open of %s succeeded should have been deleted on close !\n", fname);
3279 printf("eighth delete on close test succeeded.\n");
3281 /* This should fail - we need to set DELETE_ACCESS. */
3282 fnum1 = cli_nt_create_full(cli1, fname, 0,FILE_READ_DATA|FILE_WRITE_DATA,
3283 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, 0);
3286 printf("[9] open of %s succeeded should have failed!\n", fname);
3291 printf("ninth delete on close test succeeded.\n");
3293 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3294 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, 0);
3296 printf("[10] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3301 /* This should delete the file. */
3302 if (!cli_close(cli1, fnum1)) {
3303 printf("[10] close failed (%s)\n", cli_errstr(cli1));
3308 /* This should fail.. */
3309 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
3311 printf("[10] open of %s succeeded should have been deleted on close !\n", fname);
3315 printf("tenth delete on close test succeeded.\n");
3317 cli_setatr(cli1, fname, 0, 0);
3318 cli_unlink(cli1, fname);
3320 /* What error do we get when attempting to open a read-only file with
3323 /* Create a readonly file. */
3324 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
3325 FILE_ATTRIBUTE_READONLY, FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3327 printf("[11] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3332 if (!cli_close(cli1, fnum1)) {
3333 printf("[11] close failed (%s)\n", cli_errstr(cli1));
3338 /* Now try open for delete access. */
3339 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_ATTRIBUTES|DELETE_ACCESS,
3340 0, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3341 FILE_OVERWRITE_IF, 0, 0);
3344 printf("[11] open of %s succeeded should have been denied with ACCESS_DENIED!\n", fname);
3345 cli_close(cli1, fnum1);
3349 NTSTATUS nterr = cli_nt_error(cli1);
3350 if (!NT_STATUS_EQUAL(nterr,NT_STATUS_ACCESS_DENIED)) {
3351 printf("[11] open of %s should have been denied with ACCESS_DENIED! Got error %s\n", fname, nt_errstr(nterr));
3355 printf("eleventh delete on close test succeeded.\n");
3359 printf("finished delete test\n");
3362 /* FIXME: This will crash if we aborted before cli2 got
3363 * intialized, because these functions don't handle
3364 * uninitialized connections. */
3366 if (fnum1 != -1) cli_close(cli1, fnum1);
3367 if (fnum2 != -1) cli_close(cli1, fnum2);
3368 cli_setatr(cli1, fname, 0, 0);
3369 cli_unlink(cli1, fname);
3371 if (cli1 && !torture_close_connection(cli1)) {
3374 if (cli2 && !torture_close_connection(cli2)) {
3382 print out server properties
3384 static BOOL run_properties(int dummy)
3386 static struct cli_state *cli;
3387 BOOL correct = True;
3389 printf("starting properties test\n");
3393 if (!torture_open_connection(&cli, 0)) {
3397 cli_sockopt(cli, sockops);
3399 d_printf("Capabilities 0x%08x\n", cli->capabilities);
3401 if (!torture_close_connection(cli)) {
3410 /* FIRST_DESIRED_ACCESS 0xf019f */
3411 #define FIRST_DESIRED_ACCESS FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|\
3412 FILE_READ_EA| /* 0xf */ \
3413 FILE_WRITE_EA|FILE_READ_ATTRIBUTES| /* 0x90 */ \
3414 FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
3415 DELETE_ACCESS|READ_CONTROL_ACCESS|\
3416 WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS /* 0xf0000 */
3417 /* SECOND_DESIRED_ACCESS 0xe0080 */
3418 #define SECOND_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
3419 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
3420 WRITE_OWNER_ACCESS /* 0xe0000 */
3423 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
3424 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
3426 WRITE_OWNER_ACCESS /* */
3430 Test ntcreate calls made by xcopy
3432 static BOOL run_xcopy(int dummy)
3434 static struct cli_state *cli1;
3435 const char *fname = "\\test.txt";
3436 BOOL correct = True;
3439 printf("starting xcopy test\n");
3441 if (!torture_open_connection(&cli1, 0)) {
3445 fnum1 = cli_nt_create_full(cli1, fname, 0,
3446 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
3447 FILE_SHARE_NONE, FILE_OVERWRITE_IF,
3451 printf("First open failed - %s\n", cli_errstr(cli1));
3455 fnum2 = cli_nt_create_full(cli1, fname, 0,
3456 SECOND_DESIRED_ACCESS, 0,
3457 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN,
3460 printf("second open failed - %s\n", cli_errstr(cli1));
3464 if (!torture_close_connection(cli1)) {
3472 Test rename on files open with share delete and no share delete.
3474 static BOOL run_rename(int dummy)
3476 static struct cli_state *cli1;
3477 const char *fname = "\\test.txt";
3478 const char *fname1 = "\\test1.txt";
3479 BOOL correct = True;
3482 printf("starting rename test\n");
3484 if (!torture_open_connection(&cli1, 0)) {
3488 cli_unlink(cli1, fname);
3489 cli_unlink(cli1, fname1);
3490 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3491 FILE_SHARE_READ, FILE_OVERWRITE_IF, 0, 0);
3494 printf("First open failed - %s\n", cli_errstr(cli1));
3498 if (!cli_rename(cli1, fname, fname1)) {
3499 printf("First rename failed (SHARE_READ) (this is correct) - %s\n", cli_errstr(cli1));
3501 printf("First rename succeeded (SHARE_READ) - this should have failed !\n");
3505 if (!cli_close(cli1, fnum1)) {
3506 printf("close - 1 failed (%s)\n", cli_errstr(cli1));
3510 cli_unlink(cli1, fname);
3511 cli_unlink(cli1, fname1);
3512 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3514 FILE_SHARE_DELETE|FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3516 FILE_SHARE_DELETE|FILE_SHARE_READ, FILE_OVERWRITE_IF, 0, 0);
3520 printf("Second open failed - %s\n", cli_errstr(cli1));
3524 if (!cli_rename(cli1, fname, fname1)) {
3525 printf("Second rename failed (SHARE_DELETE | SHARE_READ) - this should have succeeded - %s\n", cli_errstr(cli1));
3528 printf("Second rename succeeded (SHARE_DELETE | SHARE_READ)\n");
3531 if (!cli_close(cli1, fnum1)) {
3532 printf("close - 2 failed (%s)\n", cli_errstr(cli1));
3536 cli_unlink(cli1, fname);
3537 cli_unlink(cli1, fname1);
3539 fnum1 = cli_nt_create_full(cli1, fname, 0, READ_CONTROL_ACCESS, FILE_ATTRIBUTE_NORMAL,
3540 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3543 printf("Third open failed - %s\n", cli_errstr(cli1));
3552 fnum2 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
3553 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3556 printf("Fourth open failed - %s\n", cli_errstr(cli1));
3559 if (!cli_nt_delete_on_close(cli1, fnum2, True)) {
3560 printf("[8] setting delete_on_close on file failed !\n");
3564 if (!cli_close(cli1, fnum2)) {
3565 printf("close - 4 failed (%s)\n", cli_errstr(cli1));
3571 if (!cli_rename(cli1, fname, fname1)) {
3572 printf("Third rename failed (SHARE_NONE) - this should have succeeded - %s\n", cli_errstr(cli1));
3575 printf("Third rename succeeded (SHARE_NONE)\n");
3578 if (!cli_close(cli1, fnum1)) {
3579 printf("close - 3 failed (%s)\n", cli_errstr(cli1));
3583 cli_unlink(cli1, fname);
3584 cli_unlink(cli1, fname1);
3588 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3589 FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0);
3592 printf("Fourth open failed - %s\n", cli_errstr(cli1));
3596 if (!cli_rename(cli1, fname, fname1)) {
3597 printf("Fourth rename failed (SHARE_READ | SHARE_WRITE) (this is correct) - %s\n", cli_errstr(cli1));
3599 printf("Fourth rename succeeded (SHARE_READ | SHARE_WRITE) - this should have failed !\n");
3603 if (!cli_close(cli1, fnum1)) {
3604 printf("close - 4 failed (%s)\n", cli_errstr(cli1));
3608 cli_unlink(cli1, fname);
3609 cli_unlink(cli1, fname1);
3613 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3614 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0);
3617 printf("Fifth open failed - %s\n", cli_errstr(cli1));
3621 if (!cli_rename(cli1, fname, fname1)) {
3622 printf("Fifth rename failed (SHARE_READ | SHARE_WRITE | SHARE_DELETE) - this should have failed ! \n");
3625 printf("Fifth rename succeeded (SHARE_READ | SHARE_WRITE | SHARE_DELETE) (this is correct) - %s\n", cli_errstr(cli1));
3629 * Now check if the first name still exists ...
3632 /*fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3633 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0);
3636 printf("Opening original file after rename of open file fails: %s\n",
3640 printf("Opening original file after rename of open file works ...\n");
3641 (void)cli_close(cli1, fnum2);
3647 if (!cli_close(cli1, fnum1)) {
3648 printf("close - 5 failed (%s)\n", cli_errstr(cli1));
3652 cli_unlink(cli1, fname);
3653 cli_unlink(cli1, fname1);
3655 if (!torture_close_connection(cli1)) {
3662 static BOOL run_pipe_number(int dummy)
3664 struct cli_state *cli1;
3665 const char *pipe_name = "\\SPOOLSS";
3669 printf("starting pipenumber test\n");
3670 if (!torture_open_connection(&cli1, 0)) {
3674 cli_sockopt(cli1, sockops);
3676 fnum = cli_nt_create_full(cli1, pipe_name, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
3677 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN_IF, 0, 0);
3680 printf("Open of pipe %s failed with error (%s)\n", pipe_name, cli_errstr(cli1));
3686 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes, pipe_name );
3687 torture_close_connection(cli1);
3692 Test open mode returns on read-only files.
3694 static BOOL run_opentest(int dummy)
3696 static struct cli_state *cli1;
3697 static struct cli_state *cli2;
3698 const char *fname = "\\readonly.file";
3702 BOOL correct = True;
3705 printf("starting open test\n");
3707 if (!torture_open_connection(&cli1, 0)) {
3711 cli_setatr(cli1, fname, 0, 0);
3712 cli_unlink(cli1, fname);
3714 cli_sockopt(cli1, sockops);
3716 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
3718 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
3722 if (!cli_close(cli1, fnum1)) {
3723 printf("close2 failed (%s)\n", cli_errstr(cli1));
3727 if (!cli_setatr(cli1, fname, aRONLY, 0)) {
3728 printf("cli_setatr failed (%s)\n", cli_errstr(cli1));
3732 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_WRITE);
3734 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
3738 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
3739 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_ALL);
3741 if (check_error(__LINE__, cli1, ERRDOS, ERRnoaccess,
3742 NT_STATUS_ACCESS_DENIED)) {
3743 printf("correct error code ERRDOS/ERRnoaccess returned\n");
3746 printf("finished open test 1\n");
3748 cli_close(cli1, fnum1);
3750 /* Now try not readonly and ensure ERRbadshare is returned. */
3752 cli_setatr(cli1, fname, 0, 0);
3754 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_WRITE);
3756 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
3760 /* This will fail - but the error should be ERRshare. */
3761 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_ALL);
3763 if (check_error(__LINE__, cli1, ERRDOS, ERRbadshare,
3764 NT_STATUS_SHARING_VIOLATION)) {
3765 printf("correct error code ERRDOS/ERRbadshare returned\n");
3768 if (!cli_close(cli1, fnum1)) {
3769 printf("close2 failed (%s)\n", cli_errstr(cli1));
3773 cli_unlink(cli1, fname);
3775 printf("finished open test 2\n");
3777 /* Test truncate open disposition on file opened for read. */
3779 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
3781 printf("(3) open (1) of %s failed (%s)\n", fname, cli_errstr(cli1));
3785 /* write 20 bytes. */
3787 memset(buf, '\0', 20);
3789 if (cli_write(cli1, fnum1, 0, buf, 0, 20) != 20) {
3790 printf("write failed (%s)\n", cli_errstr(cli1));
3794 if (!cli_close(cli1, fnum1)) {
3795 printf("(3) close1 failed (%s)\n", cli_errstr(cli1));
3799 /* Ensure size == 20. */
3800 if (!cli_getatr(cli1, fname, NULL, &fsize, NULL)) {
3801 printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
3806 printf("(3) file size != 20\n");
3810 /* Now test if we can truncate a file opened for readonly. */
3812 fnum1 = cli_open(cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE);
3814 printf("(3) open (2) of %s failed (%s)\n", fname, cli_errstr(cli1));
3818 if (!cli_close(cli1, fnum1)) {
3819 printf("close2 failed (%s)\n", cli_errstr(cli1));
3823 /* Ensure size == 0. */
3824 if (!cli_getatr(cli1, fname, NULL, &fsize, NULL)) {
3825 printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
3830 printf("(3) file size != 0\n");
3833 printf("finished open test 3\n");
3835 cli_unlink(cli1, fname);
3838 printf("testing ctemp\n");
3839 fnum1 = cli_ctemp(cli1, "\\", &tmp_path);
3841 printf("ctemp failed (%s)\n", cli_errstr(cli1));
3844 printf("ctemp gave path %s\n", tmp_path);
3845 if (!cli_close(cli1, fnum1)) {
3846 printf("close of temp failed (%s)\n", cli_errstr(cli1));
3848 if (!cli_unlink(cli1, tmp_path)) {
3849 printf("unlink of temp failed (%s)\n", cli_errstr(cli1));
3852 /* Test the non-io opens... */
3854 if (!torture_open_connection(&cli2, 1)) {
3858 cli_setatr(cli2, fname, 0, 0);
3859 cli_unlink(cli2, fname);
3861 cli_sockopt(cli2, sockops);
3863 printf("TEST #1 testing 2 non-io opens (no delete)\n");
3865 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3866 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3869 printf("test 1 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3873 fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3874 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
3877 printf("test 1 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3881 if (!cli_close(cli1, fnum1)) {
3882 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3885 if (!cli_close(cli2, fnum2)) {
3886 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3890 printf("non-io open test #1 passed.\n");
3892 cli_unlink(cli1, fname);
3894 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
3896 fnum1 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3897 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3900 printf("test 2 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3904 fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3905 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
3908 printf("test 2 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3912 if (!cli_close(cli1, fnum1)) {
3913 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3916 if (!cli_close(cli2, fnum2)) {
3917 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
3921 printf("non-io open test #2 passed.\n");
3923 cli_unlink(cli1, fname);
3925 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
3927 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3928 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3931 printf("test 3 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3935 fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3936 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
3939 printf("test 3 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3943 if (!cli_close(cli1, fnum1)) {
3944 printf("test 3 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3947 if (!cli_close(cli2, fnum2)) {
3948 printf("test 3 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3952 printf("non-io open test #3 passed.\n");
3954 cli_unlink(cli1, fname);
3956 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
3958 fnum1 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3959 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3962 printf("test 4 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3966 fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3967 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
3970 printf("test 4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
3974 printf("test 3 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
3976 if (!cli_close(cli1, fnum1)) {
3977 printf("test 4 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3981 printf("non-io open test #4 passed.\n");
3983 cli_unlink(cli1, fname);
3985 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
3987 fnum1 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3988 FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0);
3991 printf("test 5 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3995 fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3996 FILE_SHARE_DELETE, FILE_OPEN_IF, 0, 0);
3999 printf("test 5 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4003 if (!cli_close(cli1, fnum1)) {
4004 printf("test 5 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4008 if (!cli_close(cli2, fnum2)) {
4009 printf("test 5 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4013 printf("non-io open test #5 passed.\n");
4015 printf("TEST #6 testing 1 non-io open, one io open\n");
4017 cli_unlink(cli1, fname);
4019 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
4020 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
4023 printf("test 6 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4027 fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4028 FILE_SHARE_READ, FILE_OPEN_IF, 0, 0);
4031 printf("test 6 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4035 if (!cli_close(cli1, fnum1)) {
4036 printf("test 6 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4040 if (!cli_close(cli2, fnum2)) {
4041 printf("test 6 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4045 printf("non-io open test #6 passed.\n");
4047 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
4049 cli_unlink(cli1, fname);
4051 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
4052 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
4055 printf("test 7 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4059 fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4060 FILE_SHARE_READ|FILE_SHARE_DELETE, FILE_OPEN_IF, 0, 0);
4063 printf("test 7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
4067 printf("test 7 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
4069 if (!cli_close(cli1, fnum1)) {
4070 printf("test 7 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4074 printf("non-io open test #7 passed.\n");
4076 cli_unlink(cli1, fname);
4078 if (!torture_close_connection(cli1)) {
4081 if (!torture_close_connection(cli2)) {
4088 static uint32 open_attrs_table[] = {
4089 FILE_ATTRIBUTE_NORMAL,
4090 FILE_ATTRIBUTE_ARCHIVE,
4091 FILE_ATTRIBUTE_READONLY,
4092 FILE_ATTRIBUTE_HIDDEN,
4093 FILE_ATTRIBUTE_SYSTEM,
4095 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY,
4096 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN,
4097 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM,
4098 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
4099 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
4100 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
4102 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
4103 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
4104 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
4105 FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_SYSTEM,
4108 struct trunc_open_results {
4115 static struct trunc_open_results attr_results[] = {
4116 { 0, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
4117 { 1, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
4118 { 2, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
4119 { 16, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
4120 { 17, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
4121 { 18, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
4122 { 51, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4123 { 54, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4124 { 56, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
4125 { 68, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4126 { 71, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4127 { 73, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM },
4128 { 99, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4129 { 102, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4130 { 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 },
4131 { 116, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4132 { 119, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4133 { 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 },
4134 { 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 },
4135 { 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 },
4136 { 227, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4137 { 230, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4138 { 232, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
4139 { 244, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4140 { 247, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4141 { 249, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM }
4144 static BOOL run_openattrtest(int dummy)
4146 static struct cli_state *cli1;
4147 const char *fname = "\\openattr.file";
4149 BOOL correct = True;
4151 unsigned int i, j, k, l;
4153 printf("starting open attr test\n");
4155 if (!torture_open_connection(&cli1, 0)) {
4159 cli_sockopt(cli1, sockops);
4161 for (k = 0, i = 0; i < sizeof(open_attrs_table)/sizeof(uint32); i++) {
4162 cli_setatr(cli1, fname, 0, 0);
4163 cli_unlink(cli1, fname);
4164 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_WRITE_DATA, open_attrs_table[i],
4165 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
4168 printf("open %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
4172 if (!cli_close(cli1, fnum1)) {
4173 printf("close %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
4177 for (j = 0; j < sizeof(open_attrs_table)/sizeof(uint32); j++) {
4178 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA, open_attrs_table[j],
4179 FILE_SHARE_NONE, FILE_OVERWRITE, 0, 0);
4182 for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
4183 if (attr_results[l].num == k) {
4184 printf("[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(0x%x:%s)\n",
4185 k, open_attrs_table[i],
4186 open_attrs_table[j],
4187 fname, NT_STATUS_V(cli_nt_error(cli1)), cli_errstr(cli1));
4191 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_ACCESS_DENIED)) {
4192 printf("[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s\n",
4193 k, open_attrs_table[i], open_attrs_table[j],
4198 printf("[%d] trunc open 0x%x -> 0x%x failed\n", k, open_attrs_table[i], open_attrs_table[j]);
4204 if (!cli_close(cli1, fnum1)) {
4205 printf("close %d (2) of %s failed (%s)\n", j, fname, cli_errstr(cli1));
4209 if (!cli_getatr(cli1, fname, &attr, NULL, NULL)) {
4210 printf("getatr(2) failed (%s)\n", cli_errstr(cli1));
4215 printf("[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n",
4216 k, open_attrs_table[i], open_attrs_table[j], attr );
4219 for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
4220 if (attr_results[l].num == k) {
4221 if (attr != attr_results[l].result_attr ||
4222 open_attrs_table[i] != attr_results[l].init_attr ||
4223 open_attrs_table[j] != attr_results[l].trunc_attr) {
4224 printf("getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x\n",
4225 open_attrs_table[i],
4226 open_attrs_table[j],
4228 attr_results[l].result_attr);
4238 cli_setatr(cli1, fname, 0, 0);
4239 cli_unlink(cli1, fname);
4241 printf("open attr test %s.\n", correct ? "passed" : "failed");
4243 if (!torture_close_connection(cli1)) {
4249 static void list_fn(const char *mnt, file_info *finfo, const char *name, void *state)
4255 test directory listing speed
4257 static BOOL run_dirtest(int dummy)
4260 static struct cli_state *cli;
4263 BOOL correct = True;
4265 printf("starting directory test\n");
4267 if (!torture_open_connection(&cli, 0)) {
4271 cli_sockopt(cli, sockops);
4274 for (i=0;i<torture_numops;i++) {
4276 slprintf(fname, sizeof(fname), "\\%x", (int)random());
4277 fnum = cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE);
4279 fprintf(stderr,"Failed to open %s\n", fname);
4282 cli_close(cli, fnum);
4287 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
4288 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
4289 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
4291 printf("dirtest core %g seconds\n", end_timer() - t1);
4294 for (i=0;i<torture_numops;i++) {
4296 slprintf(fname, sizeof(fname), "\\%x", (int)random());
4297 cli_unlink(cli, fname);
4300 if (!torture_close_connection(cli)) {
4304 printf("finished dirtest\n");
4309 static void del_fn(const char *mnt, file_info *finfo, const char *mask, void *state)
4311 struct cli_state *pcli = (struct cli_state *)state;
4313 slprintf(fname, sizeof(fname), "\\LISTDIR\\%s", finfo->name);
4315 if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
4318 if (finfo->mode & aDIR) {
4319 if (!cli_rmdir(pcli, fname))
4320 printf("del_fn: failed to rmdir %s\n,", fname );
4322 if (!cli_unlink(pcli, fname))
4323 printf("del_fn: failed to unlink %s\n,", fname );
4329 sees what IOCTLs are supported
4331 BOOL torture_ioctl_test(int dummy)
4333 static struct cli_state *cli;
4334 uint16 device, function;
4336 const char *fname = "\\ioctl.dat";
4340 if (!torture_open_connection(&cli, 0)) {
4344 printf("starting ioctl test\n");
4346 cli_unlink(cli, fname);
4348 fnum = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
4350 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
4354 status = cli_raw_ioctl(cli, fnum, 0x2d0000 | (0x0420<<2), &blob);
4355 printf("ioctl device info: %s\n", cli_errstr(cli));
4357 status = cli_raw_ioctl(cli, fnum, IOCTL_QUERY_JOB_INFO, &blob);
4358 printf("ioctl job info: %s\n", cli_errstr(cli));
4360 for (device=0;device<0x100;device++) {
4361 printf("testing device=0x%x\n", device);
4362 for (function=0;function<0x100;function++) {
4363 uint32 code = (device<<16) | function;
4365 status = cli_raw_ioctl(cli, fnum, code, &blob);
4367 if (NT_STATUS_IS_OK(status)) {
4368 printf("ioctl 0x%x OK : %d bytes\n", (int)code,
4370 data_blob_free(&blob);
4375 if (!torture_close_connection(cli)) {
4384 tries varients of chkpath
4386 BOOL torture_chkpath_test(int dummy)
4388 static struct cli_state *cli;
4392 if (!torture_open_connection(&cli, 0)) {
4396 printf("starting chkpath test\n");
4398 /* cleanup from an old run */
4399 cli_rmdir(cli, "\\chkpath.dir\\dir2");
4400 cli_unlink(cli, "\\chkpath.dir\\*");
4401 cli_rmdir(cli, "\\chkpath.dir");
4403 if (!cli_mkdir(cli, "\\chkpath.dir")) {
4404 printf("mkdir1 failed : %s\n", cli_errstr(cli));
4408 if (!cli_mkdir(cli, "\\chkpath.dir\\dir2")) {
4409 printf("mkdir2 failed : %s\n", cli_errstr(cli));
4413 fnum = cli_open(cli, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
4415 printf("open1 failed (%s)\n", cli_errstr(cli));
4418 cli_close(cli, fnum);
4420 if (!cli_chkpath(cli, "\\chkpath.dir")) {
4421 printf("chkpath1 failed: %s\n", cli_errstr(cli));
4425 if (!cli_chkpath(cli, "\\chkpath.dir\\dir2")) {
4426 printf("chkpath2 failed: %s\n", cli_errstr(cli));
4430 if (!cli_chkpath(cli, "\\chkpath.dir\\foo.txt")) {
4431 ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath,
4432 NT_STATUS_NOT_A_DIRECTORY);
4434 printf("* chkpath on a file should fail\n");
4438 if (!cli_chkpath(cli, "\\chkpath.dir\\bar.txt")) {
4439 ret = check_error(__LINE__, cli, ERRDOS, ERRbadfile,
4440 NT_STATUS_OBJECT_NAME_NOT_FOUND);
4442 printf("* chkpath on a non existant file should fail\n");
4446 if (!cli_chkpath(cli, "\\chkpath.dir\\dirxx\\bar.txt")) {
4447 ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath,
4448 NT_STATUS_OBJECT_PATH_NOT_FOUND);
4450 printf("* chkpath on a non existent component should fail\n");
4454 cli_rmdir(cli, "\\chkpath.dir\\dir2");
4455 cli_unlink(cli, "\\chkpath.dir\\*");
4456 cli_rmdir(cli, "\\chkpath.dir");
4458 if (!torture_close_connection(cli)) {
4465 static BOOL run_eatest(int dummy)
4467 static struct cli_state *cli;
4468 const char *fname = "\\eatest.txt";
4469 BOOL correct = True;
4472 struct ea_struct *ea_list = NULL;
4473 TALLOC_CTX *mem_ctx = talloc_init("eatest");
4475 printf("starting eatest\n");
4477 if (!torture_open_connection(&cli, 0)) {
4481 cli_unlink(cli, fname);
4482 fnum = cli_nt_create_full(cli, fname, 0,
4483 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
4484 FILE_SHARE_NONE, FILE_OVERWRITE_IF,
4488 printf("open failed - %s\n", cli_errstr(cli));
4492 for (i = 0; i < 10; i++) {
4493 fstring ea_name, ea_val;
4495 slprintf(ea_name, sizeof(ea_name), "EA_%d", i);
4496 memset(ea_val, (char)i+1, i+1);
4497 if (!cli_set_ea_fnum(cli, fnum, ea_name, ea_val, i+1)) {
4498 printf("ea_set of name %s failed - %s\n", ea_name, cli_errstr(cli));
4503 cli_close(cli, fnum);
4504 for (i = 0; i < 10; i++) {
4505 fstring ea_name, ea_val;
4507 slprintf(ea_name, sizeof(ea_name), "EA_%d", i+10);
4508 memset(ea_val, (char)i+1, i+1);
4509 if (!cli_set_ea_path(cli, fname, ea_name, ea_val, i+1)) {
4510 printf("ea_set of name %s failed - %s\n", ea_name, cli_errstr(cli));
4515 if (!cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list)) {
4516 printf("ea_get list failed - %s\n", cli_errstr(cli));
4520 printf("num_eas = %d\n", (int)num_eas);
4522 if (num_eas != 20) {
4523 printf("Should be 20 EA's stored... failing.\n");
4527 for (i = 0; i < num_eas; i++) {
4528 printf("%d: ea_name = %s. Val = ", i, ea_list[i].name);
4529 dump_data(0, (char *)ea_list[i].value.data,
4530 ea_list[i].value.length);
4533 /* Setting EA's to zero length deletes them. Test this */
4534 printf("Now deleting all EA's - case indepenent....\n");
4537 cli_set_ea_path(cli, fname, "", "", 0);
4539 for (i = 0; i < 20; i++) {
4541 slprintf(ea_name, sizeof(ea_name), "ea_%d", i);
4542 if (!cli_set_ea_path(cli, fname, ea_name, "", 0)) {
4543 printf("ea_set of name %s failed - %s\n", ea_name, cli_errstr(cli));
4549 if (!cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list)) {
4550 printf("ea_get list failed - %s\n", cli_errstr(cli));
4554 printf("num_eas = %d\n", (int)num_eas);
4555 for (i = 0; i < num_eas; i++) {
4556 printf("%d: ea_name = %s. Val = ", i, ea_list[i].name);
4557 dump_data(0, (char *)ea_list[i].value.data,
4558 ea_list[i].value.length);
4562 printf("deleting EA's failed.\n");
4566 /* Try and delete a non existant EA. */
4567 if (!cli_set_ea_path(cli, fname, "foo", "", 0)) {
4568 printf("deleting non-existant EA 'foo' should succeed. %s\n", cli_errstr(cli));
4572 talloc_destroy(mem_ctx);
4573 if (!torture_close_connection(cli)) {
4580 static BOOL run_dirtest1(int dummy)
4583 static struct cli_state *cli;
4585 BOOL correct = True;
4587 printf("starting directory test\n");
4589 if (!torture_open_connection(&cli, 0)) {
4593 cli_sockopt(cli, sockops);
4595 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
4596 cli_list(cli, "\\LISTDIR\\*", aDIR, del_fn, cli);
4597 cli_rmdir(cli, "\\LISTDIR");
4598 cli_mkdir(cli, "\\LISTDIR");
4600 /* Create 1000 files and 1000 directories. */
4601 for (i=0;i<1000;i++) {
4603 slprintf(fname, sizeof(fname), "\\LISTDIR\\f%d", i);
4604 fnum = cli_nt_create_full(cli, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
4605 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0);
4607 fprintf(stderr,"Failed to open %s\n", fname);
4610 cli_close(cli, fnum);
4612 for (i=0;i<1000;i++) {
4614 slprintf(fname, sizeof(fname), "\\LISTDIR\\d%d", i);
4615 if (!cli_mkdir(cli, fname)) {
4616 fprintf(stderr,"Failed to open %s\n", fname);
4621 /* Now ensure that doing an old list sees both files and directories. */
4622 num_seen = cli_list_old(cli, "\\LISTDIR\\*", aDIR, list_fn, NULL);
4623 printf("num_seen = %d\n", num_seen );
4624 /* We should see 100 files + 1000 directories + . and .. */
4625 if (num_seen != 2002)
4628 /* Ensure if we have the "must have" bits we only see the
4631 num_seen = cli_list_old(cli, "\\LISTDIR\\*", (aDIR<<8)|aDIR, list_fn, NULL);
4632 printf("num_seen = %d\n", num_seen );
4633 if (num_seen != 1002)
4636 num_seen = cli_list_old(cli, "\\LISTDIR\\*", (aARCH<<8)|aDIR, list_fn, NULL);
4637 printf("num_seen = %d\n", num_seen );
4638 if (num_seen != 1000)
4641 /* Delete everything. */
4642 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
4643 cli_list(cli, "\\LISTDIR\\*", aDIR, del_fn, cli);
4644 cli_rmdir(cli, "\\LISTDIR");
4647 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
4648 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
4649 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
4652 if (!torture_close_connection(cli)) {
4656 printf("finished dirtest1\n");
4661 static BOOL run_error_map_extract(int dummy) {
4663 static struct cli_state *c_dos;
4664 static struct cli_state *c_nt;
4668 uint32 flgs2, errnum;
4675 /* NT-Error connection */
4677 if (!(c_nt = open_nbt_connection())) {
4681 c_nt->use_spnego = False;
4683 if (!cli_negprot(c_nt)) {
4684 printf("%s rejected the NT-error negprot (%s)\n",host, cli_errstr(c_nt));
4689 if (!NT_STATUS_IS_OK(cli_session_setup(c_nt, "", "", 0, "", 0,
4691 printf("%s rejected the NT-error initial session setup (%s)\n",host, cli_errstr(c_nt));
4695 /* DOS-Error connection */
4697 if (!(c_dos = open_nbt_connection())) {
4701 c_dos->use_spnego = False;
4702 c_dos->force_dos_errors = True;
4704 if (!cli_negprot(c_dos)) {
4705 printf("%s rejected the DOS-error negprot (%s)\n",host, cli_errstr(c_dos));
4706 cli_shutdown(c_dos);
4710 if (!NT_STATUS_IS_OK(cli_session_setup(c_dos, "", "", 0, "", 0,
4712 printf("%s rejected the DOS-error initial session setup (%s)\n",host, cli_errstr(c_dos));
4716 for (error=(0xc0000000 | 0x1); error < (0xc0000000| 0xFFF); error++) {
4717 fstr_sprintf(user, "%X", error);
4719 if (NT_STATUS_IS_OK(cli_session_setup(c_nt, user,
4720 password, strlen(password),
4721 password, strlen(password),
4723 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
4726 flgs2 = SVAL(c_nt->inbuf,smb_flg2);
4728 /* Case #1: 32-bit NT errors */
4729 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
4730 nt_status = NT_STATUS(IVAL(c_nt->inbuf,smb_rcls));
4732 printf("/** Dos error on NT connection! (%s) */\n",
4734 nt_status = NT_STATUS(0xc0000000);
4737 if (NT_STATUS_IS_OK(cli_session_setup(c_dos, user,
4738 password, strlen(password),
4739 password, strlen(password),
4741 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
4743 flgs2 = SVAL(c_dos->inbuf,smb_flg2), errnum;
4745 /* Case #1: 32-bit NT errors */
4746 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
4747 printf("/** NT error on DOS connection! (%s) */\n",
4749 errnum = errclass = 0;
4751 cli_dos_error(c_dos, &errclass, &errnum);
4754 if (NT_STATUS_V(nt_status) != error) {
4755 printf("/*\t{ This NT error code was 'sqashed'\n\t from %s to %s \n\t during the session setup }\n*/\n",
4756 get_nt_error_c_code(NT_STATUS(error)),
4757 get_nt_error_c_code(nt_status));
4760 printf("\t{%s,\t%s,\t%s},\n",
4761 smb_dos_err_class(errclass),
4762 smb_dos_err_name(errclass, errnum),
4763 get_nt_error_c_code(NT_STATUS(error)));
4768 static BOOL run_local_substitute(int dummy)
4770 TALLOC_CTX *mem_ctx;
4773 if ((mem_ctx = talloc_init("run_local_subst")) == NULL) {
4774 printf("talloc_init failed\n");
4778 diff |= strcmp(talloc_sub_specified(mem_ctx, "%U", "bla", "", -1, -1),
4780 diff |= strcmp(talloc_sub_specified(mem_ctx, "%u%U", "bla", "", -1, -1),
4782 diff |= strcmp(talloc_sub_specified(mem_ctx, "%g", "", "", -1, -1),
4784 diff |= strcmp(talloc_sub_specified(mem_ctx, "%G", "", "", -1, -1),
4786 diff |= strcmp(talloc_sub_specified(mem_ctx, "%g", "", "", -1, 0),
4788 diff |= strcmp(talloc_sub_specified(mem_ctx, "%G", "", "", -1, 0),
4790 diff |= strcmp(talloc_sub_specified(mem_ctx, "%D%u", "u", "dom", -1, 0),
4792 diff |= strcmp(talloc_sub_specified(mem_ctx, "%i %I", "", "", -1, -1),
4795 /* Different captialization rules in sub_basic... */
4797 diff |= strcmp(talloc_sub_basic(mem_ctx, "BLA", "dom", "%U%D"),
4800 TALLOC_FREE(mem_ctx);
4804 static double create_procs(BOOL (*fn)(int), BOOL *result)
4807 volatile pid_t *child_status;
4808 volatile BOOL *child_status_out;
4814 child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*nprocs);
4815 if (!child_status) {
4816 printf("Failed to setup shared memory\n");
4820 child_status_out = (volatile BOOL *)shm_setup(sizeof(BOOL)*nprocs);
4821 if (!child_status_out) {
4822 printf("Failed to setup result status shared memory\n");
4826 for (i = 0; i < nprocs; i++) {
4827 child_status[i] = 0;
4828 child_status_out[i] = True;
4833 for (i=0;i<nprocs;i++) {
4836 pid_t mypid = getpid();
4837 sys_srandom(((int)mypid) ^ ((int)time(NULL)));
4839 slprintf(myname,sizeof(myname),"CLIENT%d", i);
4842 if (torture_open_connection(¤t_cli, i)) break;
4844 printf("pid %d failed to start\n", (int)getpid());
4850 child_status[i] = getpid();
4852 while (child_status[i] && end_timer() < 5) smb_msleep(2);
4854 child_status_out[i] = fn(i);
4861 for (i=0;i<nprocs;i++) {
4862 if (child_status[i]) synccount++;
4864 if (synccount == nprocs) break;
4866 } while (end_timer() < 30);
4868 if (synccount != nprocs) {
4869 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs, synccount);
4874 /* start the client load */
4877 for (i=0;i<nprocs;i++) {
4878 child_status[i] = 0;
4881 printf("%d clients started\n", nprocs);
4883 for (i=0;i<nprocs;i++) {
4884 while (waitpid(0, &status, 0) == -1 && errno == EINTR) /* noop */ ;
4889 for (i=0;i<nprocs;i++) {
4890 if (!child_status_out[i]) {
4897 #define FLAG_MULTIPROC 1
4904 {"FDPASS", run_fdpasstest, 0},
4905 {"LOCK1", run_locktest1, 0},
4906 {"LOCK2", run_locktest2, 0},
4907 {"LOCK3", run_locktest3, 0},
4908 {"LOCK4", run_locktest4, 0},
4909 {"LOCK5", run_locktest5, 0},
4910 {"LOCK6", run_locktest6, 0},
4911 {"LOCK7", run_locktest7, 0},
4912 {"UNLINK", run_unlinktest, 0},
4913 {"BROWSE", run_browsetest, 0},
4914 {"ATTR", run_attrtest, 0},
4915 {"TRANS2", run_trans2test, 0},
4916 {"MAXFID", run_maxfidtest, FLAG_MULTIPROC},
4917 {"TORTURE",run_torture, FLAG_MULTIPROC},
4918 {"RANDOMIPC", run_randomipc, 0},
4919 {"NEGNOWAIT", run_negprot_nowait, 0},
4920 {"NBENCH", run_nbench, 0},
4921 {"OPLOCK1", run_oplock1, 0},
4922 {"OPLOCK2", run_oplock2, 0},
4923 {"OPLOCK3", run_oplock3, 0},
4924 {"DIR", run_dirtest, 0},
4925 {"DIR1", run_dirtest1, 0},
4926 {"DENY1", torture_denytest1, 0},
4927 {"DENY2", torture_denytest2, 0},
4928 {"TCON", run_tcon_test, 0},
4929 {"TCONDEV", run_tcon_devtype_test, 0},
4930 {"RW1", run_readwritetest, 0},
4931 {"RW2", run_readwritemulti, FLAG_MULTIPROC},
4932 {"RW3", run_readwritelarge, 0},
4933 {"OPEN", run_opentest, 0},
4935 {"OPENATTR", run_openattrtest, 0},
4937 {"XCOPY", run_xcopy, 0},
4938 {"RENAME", run_rename, 0},
4939 {"DELETE", run_deletetest, 0},
4940 {"PROPERTIES", run_properties, 0},
4941 {"MANGLE", torture_mangle, 0},
4942 {"W2K", run_w2ktest, 0},
4943 {"TRANS2SCAN", torture_trans2_scan, 0},
4944 {"NTTRANSSCAN", torture_nttrans_scan, 0},
4945 {"UTABLE", torture_utable, 0},
4946 {"CASETABLE", torture_casetable, 0},
4947 {"ERRMAPEXTRACT", run_error_map_extract, 0},
4948 {"PIPE_NUMBER", run_pipe_number, 0},
4949 {"TCON2", run_tcon2_test, 0},
4950 {"IOCTL", torture_ioctl_test, 0},
4951 {"CHKPATH", torture_chkpath_test, 0},
4952 {"FDSESS", run_fdsesstest, 0},
4953 { "EATEST", run_eatest, 0},
4954 { "LOCAL-SUBSTITUTE", run_local_substitute, 0},
4959 /****************************************************************************
4960 run a specified test or "ALL"
4961 ****************************************************************************/
4962 static BOOL run_test(const char *name)
4969 if (strequal(name,"ALL")) {
4970 for (i=0;torture_ops[i].name;i++) {
4971 run_test(torture_ops[i].name);
4976 for (i=0;torture_ops[i].name;i++) {
4977 fstr_sprintf(randomfname, "\\XX%x",
4978 (unsigned)random());
4980 if (strequal(name, torture_ops[i].name)) {
4982 printf("Running %s\n", name);
4983 if (torture_ops[i].flags & FLAG_MULTIPROC) {
4984 t = create_procs(torture_ops[i].fn, &result);
4987 printf("TEST %s FAILED!\n", name);
4992 if (!torture_ops[i].fn(0)) {
4994 printf("TEST %s FAILED!\n", name);
4998 printf("%s took %g secs\n\n", name, t);
5003 printf("Did not find a test named %s\n", name);
5011 static void usage(void)
5015 printf("WARNING samba4 test suite is much more complete nowadays.\n");
5016 printf("Please use samba4 torture.\n\n");
5018 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
5020 printf("\t-d debuglevel\n");
5021 printf("\t-U user%%pass\n");
5022 printf("\t-k use kerberos\n");
5023 printf("\t-N numprocs\n");
5024 printf("\t-n my_netbios_name\n");
5025 printf("\t-W workgroup\n");
5026 printf("\t-o num_operations\n");
5027 printf("\t-O socket_options\n");
5028 printf("\t-m maximum protocol\n");
5029 printf("\t-L use oplocks\n");
5030 printf("\t-c CLIENT.TXT specify client load file for NBENCH\n");
5031 printf("\t-A showall\n");
5032 printf("\t-p port\n");
5033 printf("\t-s seed\n");
5034 printf("\t-b unclist_filename specify multiple shares for multiple connections\n");
5037 printf("tests are:");
5038 for (i=0;torture_ops[i].name;i++) {
5039 printf(" %s", torture_ops[i].name);
5043 printf("default test is ALL\n");
5048 /****************************************************************************
5050 ****************************************************************************/
5051 int main(int argc,char *argv[])
5057 BOOL correct = True;
5061 #ifdef HAVE_SETBUFFER
5062 setbuffer(stdout, NULL, 0);
5067 lp_load(dyn_CONFIGFILE,True,False,False,True);
5074 for(p = argv[1]; *p; p++)
5078 if (strncmp(argv[1], "//", 2)) {
5082 fstrcpy(host, &argv[1][2]);
5083 p = strchr_m(&host[2],'/');
5088 fstrcpy(share, p+1);
5092 if (*username == 0 && getenv("LOGNAME")) {
5093 fstrcpy(username,getenv("LOGNAME"));
5099 srandom(time(NULL));
5101 fstrcpy(workgroup, lp_workgroup());
5103 while ((opt = getopt(argc, argv, "p:hW:U:n:N:O:o:m:Ld:Ac:ks:b:")) != EOF) {
5106 port_to_use = atoi(optarg);
5109 srandom(atoi(optarg));
5112 fstrcpy(workgroup,optarg);
5115 max_protocol = interpret_protocol(optarg, max_protocol);
5118 nprocs = atoi(optarg);
5121 torture_numops = atoi(optarg);
5124 DEBUGLEVEL = atoi(optarg);
5133 torture_showall = True;
5136 fstrcpy(myname, optarg);
5139 client_txt = optarg;
5143 use_kerberos = True;
5145 d_printf("No kerberos support compiled in\n");
5151 fstrcpy(username,optarg);
5152 p = strchr_m(username,'%');
5155 fstrcpy(password, p+1);
5160 fstrcpy(multishare_conn_fname, optarg);
5161 use_multishare_conn = True;
5164 printf("Unknown option %c (%d)\n", (char)opt, opt);
5169 if(use_kerberos && !gotuser) gotpass = True;
5172 p = getpass("Password:");
5174 fstrcpy(password, p);
5179 printf("host=%s share=%s user=%s myname=%s\n",
5180 host, share, username, myname);
5182 if (argc == optind) {
5183 correct = run_test("ALL");
5185 for (i=optind;i<argc;i++) {
5186 if (!run_test(argv[i])) {