2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1997-1998
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 static fstring host, workgroup, share, password, username, myname;
26 static int max_protocol = PROTOCOL_NT1;
27 static const char *sockops="TCP_NODELAY";
29 static int port_to_use=0;
30 int torture_numops=100;
31 static int procnum; /* records process count number when forking */
32 static struct cli_state *current_cli;
33 static fstring randomfname;
34 static bool use_oplocks;
35 static bool use_level_II_oplocks;
36 static const char *client_txt = "client_oplocks.txt";
37 static bool use_kerberos;
38 static fstring multishare_conn_fname;
39 static bool use_multishare_conn = False;
41 bool torture_showall = False;
43 static double create_procs(bool (*fn)(int), bool *result);
46 static struct timeval tp1,tp2;
49 void start_timer(void)
54 double end_timer(void)
57 return((tp2.tv_sec - tp1.tv_sec) +
58 (tp2.tv_usec - tp1.tv_usec)*1.0e-6);
62 /* return a pointer to a anonymous shared memory segment of size "size"
63 which will persist across fork() but will disappear when all processes
66 The memory is not zeroed
68 This function uses system5 shared memory. It takes advantage of a property
69 that the memory is not destroyed if it is attached when the id is removed
71 void *shm_setup(int size)
76 shmid = shmget(IPC_PRIVATE, size, S_IRUSR | S_IWUSR);
78 printf("can't get shared memory\n");
81 ret = (void *)shmat(shmid, 0, 0);
82 if (!ret || ret == (void *)-1) {
83 printf("can't attach to shared memory\n");
86 /* the following releases the ipc, but note that this process
87 and all its children will still have access to the memory, its
88 just that the shmid is no longer valid for other shm calls. This
89 means we don't leave behind lots of shm segments after we exit
91 See Stevens "advanced programming in unix env" for details
93 shmctl(shmid, IPC_RMID, 0);
99 static struct cli_state *open_nbt_connection(void)
101 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 status = cli_connect(c, host, &ip);
119 if (!NT_STATUS_IS_OK(status)) {
120 printf("Failed to connect with %s. Error %s\n", host, nt_errstr(status) );
124 c->use_kerberos = use_kerberos;
126 c->timeout = 120000; /* set a really long timeout (2 minutes) */
127 if (use_oplocks) c->use_oplocks = True;
128 if (use_level_II_oplocks) c->use_level_II_oplocks = True;
130 if (!cli_session_request(c, &calling, &called)) {
132 * Well, that failed, try *SMBSERVER ...
133 * However, we must reconnect as well ...
135 status = cli_connect(c, host, &ip);
136 if (!NT_STATUS_IS_OK(status)) {
137 printf("Failed to connect with %s. Error %s\n", host, nt_errstr(status) );
141 make_nmb_name(&called, "*SMBSERVER", 0x20);
142 if (!cli_session_request(c, &calling, &called)) {
143 printf("%s rejected the session\n",host);
144 printf("We tried with a called name of %s & %s\n",
154 /* Insert a NULL at the first separator of the given path and return a pointer
155 * to the remainder of the string.
158 terminate_path_at_separator(char * path)
166 if ((p = strchr_m(path, '/'))) {
171 if ((p = strchr_m(path, '\\'))) {
181 parse a //server/share type UNC name
183 bool smbcli_parse_unc(const char *unc_name, TALLOC_CTX *mem_ctx,
184 char **hostname, char **sharename)
188 *hostname = *sharename = NULL;
190 if (strncmp(unc_name, "\\\\", 2) &&
191 strncmp(unc_name, "//", 2)) {
195 *hostname = talloc_strdup(mem_ctx, &unc_name[2]);
196 p = terminate_path_at_separator(*hostname);
199 *sharename = talloc_strdup(mem_ctx, p);
200 terminate_path_at_separator(*sharename);
203 if (*hostname && *sharename) {
207 TALLOC_FREE(*hostname);
208 TALLOC_FREE(*sharename);
212 static bool torture_open_connection_share(struct cli_state **c,
213 const char *hostname,
214 const char *sharename)
221 flags |= CLI_FULL_CONNECTION_USE_KERBEROS;
223 status = cli_full_connection(c, myname,
224 hostname, NULL, port_to_use,
227 password, flags, Undefined, &retry);
228 if (!NT_STATUS_IS_OK(status)) {
229 printf("failed to open share connection: //%s/%s port:%d - %s\n",
230 hostname, sharename, port_to_use, nt_errstr(status));
234 if (use_oplocks) (*c)->use_oplocks = True;
235 if (use_level_II_oplocks) (*c)->use_level_II_oplocks = True;
236 (*c)->timeout = 120000; /* set a really long timeout (2 minutes) */
241 void torture_open_connection_free_unclist(char **unc_list)
245 SAFE_FREE(unc_list[0]);
250 bool torture_open_connection(struct cli_state **c, int conn_index)
252 char **unc_list = NULL;
253 int num_unc_names = 0;
256 if (use_multishare_conn==True) {
258 unc_list = file_lines_load(multishare_conn_fname, &num_unc_names, 0);
259 if (!unc_list || num_unc_names <= 0) {
260 printf("Failed to load unc names list from '%s'\n", multishare_conn_fname);
264 if (!smbcli_parse_unc(unc_list[conn_index % num_unc_names],
266 printf("Failed to parse UNC name %s\n",
267 unc_list[conn_index % num_unc_names]);
268 torture_open_connection_free_unclist(unc_list);
272 result = torture_open_connection_share(c, h, s);
274 /* h, s were copied earlier */
275 torture_open_connection_free_unclist(unc_list);
279 return torture_open_connection_share(c, host, share);
282 bool torture_cli_session_setup2(struct cli_state *cli, uint16 *new_vuid)
284 uint16 old_vuid = cli->vuid;
285 fstring old_user_name;
286 size_t passlen = strlen(password);
289 fstrcpy(old_user_name, cli->user_name);
291 ret = NT_STATUS_IS_OK(cli_session_setup(cli, username,
295 *new_vuid = cli->vuid;
296 cli->vuid = old_vuid;
297 fstrcpy(cli->user_name, old_user_name);
302 bool torture_close_connection(struct cli_state *c)
306 printf("tdis failed (%s)\n", cli_errstr(c));
316 /* check if the server produced the expected error code */
317 static bool check_error(int line, struct cli_state *c,
318 uint8 eclass, uint32 ecode, NTSTATUS nterr)
320 if (cli_is_dos_error(c)) {
324 /* Check DOS error */
326 cli_dos_error(c, &cclass, &num);
328 if (eclass != cclass || ecode != num) {
329 printf("unexpected error code class=%d code=%d\n",
330 (int)cclass, (int)num);
331 printf(" expected %d/%d %s (line=%d)\n",
332 (int)eclass, (int)ecode, nt_errstr(nterr), line);
341 status = cli_nt_error(c);
343 if (NT_STATUS_V(nterr) != NT_STATUS_V(status)) {
344 printf("unexpected error code %s\n", nt_errstr(status));
345 printf(" expected %s (line=%d)\n", nt_errstr(nterr), line);
354 static bool wait_lock(struct cli_state *c, int fnum, uint32 offset, uint32 len)
356 while (!cli_lock(c, fnum, offset, len, -1, WRITE_LOCK)) {
357 if (!check_error(__LINE__, c, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
363 static bool rw_torture(struct cli_state *c)
365 const char *lockfname = "\\torture.lck";
369 pid_t pid2, pid = getpid();
374 memset(buf, '\0', sizeof(buf));
376 fnum2 = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
379 fnum2 = cli_open(c, lockfname, O_RDWR, DENY_NONE);
381 printf("open of %s failed (%s)\n", lockfname, cli_errstr(c));
386 for (i=0;i<torture_numops;i++) {
387 unsigned n = (unsigned)sys_random()%10;
389 printf("%d\r", i); fflush(stdout);
391 slprintf(fname, sizeof(fstring) - 1, "\\torture.%u", n);
393 if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) {
397 fnum = cli_open(c, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL);
399 printf("open failed (%s)\n", cli_errstr(c));
404 if (cli_write(c, fnum, 0, (char *)&pid, 0, sizeof(pid)) != sizeof(pid)) {
405 printf("write failed (%s)\n", cli_errstr(c));
410 if (cli_write(c, fnum, 0, (char *)buf,
411 sizeof(pid)+(j*sizeof(buf)),
412 sizeof(buf)) != sizeof(buf)) {
413 printf("write failed (%s)\n", cli_errstr(c));
420 if (cli_read(c, fnum, (char *)&pid2, 0, sizeof(pid)) != sizeof(pid)) {
421 printf("read failed (%s)\n", cli_errstr(c));
426 printf("data corruption!\n");
430 if (!cli_close(c, fnum)) {
431 printf("close failed (%s)\n", cli_errstr(c));
435 if (!cli_unlink(c, fname)) {
436 printf("unlink failed (%s)\n", cli_errstr(c));
440 if (!cli_unlock(c, fnum2, n*sizeof(int), sizeof(int))) {
441 printf("unlock failed (%s)\n", cli_errstr(c));
447 cli_unlink(c, lockfname);
454 static bool run_torture(int dummy)
456 struct cli_state *cli;
461 cli_sockopt(cli, sockops);
463 ret = rw_torture(cli);
465 if (!torture_close_connection(cli)) {
472 static bool rw_torture3(struct cli_state *c, char *lockfname)
479 unsigned countprev = 0;
484 for (i = 0; i < sizeof(buf); i += sizeof(uint32))
486 SIVAL(buf, i, sys_random());
491 fnum = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
494 printf("first open read/write of %s failed (%s)\n",
495 lockfname, cli_errstr(c));
501 for (i = 0; i < 500 && fnum == -1; i++)
503 fnum = cli_open(c, lockfname, O_RDONLY,
508 printf("second open read-only of %s failed (%s)\n",
509 lockfname, cli_errstr(c));
515 for (count = 0; count < sizeof(buf); count += sent)
517 if (count >= countprev) {
518 printf("%d %8d\r", i, count);
521 countprev += (sizeof(buf) / 20);
526 sent = ((unsigned)sys_random()%(20))+ 1;
527 if (sent > sizeof(buf) - count)
529 sent = sizeof(buf) - count;
532 if (cli_write(c, fnum, 0, buf+count, count, (size_t)sent) != sent) {
533 printf("write failed (%s)\n", cli_errstr(c));
539 sent = cli_read(c, fnum, buf_rd+count, count,
543 printf("read failed offset:%d size:%ld (%s)\n",
544 count, (unsigned long)sizeof(buf)-count,
551 if (memcmp(buf_rd+count, buf+count, sent) != 0)
553 printf("read/write compare failed\n");
554 printf("offset: %d req %ld recvd %ld\n", count, (unsigned long)sizeof(buf)-count, (unsigned long)sent);
563 if (!cli_close(c, fnum)) {
564 printf("close failed (%s)\n", cli_errstr(c));
571 static bool rw_torture2(struct cli_state *c1, struct cli_state *c2)
573 const char *lockfname = "\\torture2.lck";
582 if (!cli_unlink(c1, lockfname)) {
583 printf("unlink failed (%s) (normal, this file should not exist)\n", cli_errstr(c1));
586 fnum1 = cli_open(c1, lockfname, O_RDWR | O_CREAT | O_EXCL,
589 printf("first open read/write of %s failed (%s)\n",
590 lockfname, cli_errstr(c1));
593 fnum2 = cli_open(c2, lockfname, O_RDONLY,
596 printf("second open read-only of %s failed (%s)\n",
597 lockfname, cli_errstr(c2));
598 cli_close(c1, fnum1);
602 for (i=0;i<torture_numops;i++)
604 size_t buf_size = ((unsigned)sys_random()%(sizeof(buf)-1))+ 1;
606 printf("%d\r", i); fflush(stdout);
609 generate_random_buffer((unsigned char *)buf, buf_size);
611 if (cli_write(c1, fnum1, 0, buf, 0, buf_size) != buf_size) {
612 printf("write failed (%s)\n", cli_errstr(c1));
617 if ((bytes_read = cli_read(c2, fnum2, buf_rd, 0, buf_size)) != buf_size) {
618 printf("read failed (%s)\n", cli_errstr(c2));
619 printf("read %d, expected %ld\n", (int)bytes_read,
620 (unsigned long)buf_size);
625 if (memcmp(buf_rd, buf, buf_size) != 0)
627 printf("read/write compare failed\n");
633 if (!cli_close(c2, fnum2)) {
634 printf("close failed (%s)\n", cli_errstr(c2));
637 if (!cli_close(c1, fnum1)) {
638 printf("close failed (%s)\n", cli_errstr(c1));
642 if (!cli_unlink(c1, lockfname)) {
643 printf("unlink failed (%s)\n", cli_errstr(c1));
650 static bool run_readwritetest(int dummy)
652 static struct cli_state *cli1, *cli2;
653 bool test1, test2 = False;
655 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
658 cli_sockopt(cli1, sockops);
659 cli_sockopt(cli2, sockops);
661 printf("starting readwritetest\n");
663 test1 = rw_torture2(cli1, cli2);
664 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1));
667 test2 = rw_torture2(cli1, cli1);
668 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2));
671 if (!torture_close_connection(cli1)) {
675 if (!torture_close_connection(cli2)) {
679 return (test1 && test2);
682 static bool run_readwritemulti(int dummy)
684 struct cli_state *cli;
689 cli_sockopt(cli, sockops);
691 printf("run_readwritemulti: fname %s\n", randomfname);
692 test = rw_torture3(cli, randomfname);
694 if (!torture_close_connection(cli)) {
701 static bool run_readwritelarge(int dummy)
703 static struct cli_state *cli1;
705 const char *lockfname = "\\large.dat";
710 if (!torture_open_connection(&cli1, 0)) {
713 cli_sockopt(cli1, sockops);
714 memset(buf,'\0',sizeof(buf));
716 cli1->max_xmit = 128*1024;
718 printf("starting readwritelarge\n");
720 cli_unlink(cli1, lockfname);
722 fnum1 = cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE);
724 printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(cli1));
728 cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf));
730 if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
731 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
735 if (fsize == sizeof(buf))
736 printf("readwritelarge test 1 succeeded (size = %lx)\n",
737 (unsigned long)fsize);
739 printf("readwritelarge test 1 failed (size = %lx)\n",
740 (unsigned long)fsize);
744 if (!cli_close(cli1, fnum1)) {
745 printf("close failed (%s)\n", cli_errstr(cli1));
749 if (!cli_unlink(cli1, lockfname)) {
750 printf("unlink failed (%s)\n", cli_errstr(cli1));
754 fnum1 = cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE);
756 printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(cli1));
760 cli1->max_xmit = 4*1024;
762 cli_smbwrite(cli1, fnum1, buf, 0, sizeof(buf));
764 if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
765 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
769 if (fsize == sizeof(buf))
770 printf("readwritelarge test 2 succeeded (size = %lx)\n",
771 (unsigned long)fsize);
773 printf("readwritelarge test 2 failed (size = %lx)\n",
774 (unsigned long)fsize);
779 /* ToDo - set allocation. JRA */
780 if(!cli_set_allocation_size(cli1, fnum1, 0)) {
781 printf("set allocation size to zero failed (%s)\n", cli_errstr(&cli1));
784 if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
785 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
789 printf("readwritelarge test 3 (truncate test) succeeded (size = %x)\n", fsize);
792 if (!cli_close(cli1, fnum1)) {
793 printf("close failed (%s)\n", cli_errstr(cli1));
797 if (!torture_close_connection(cli1)) {
806 #define ival(s) strtol(s, NULL, 0)
808 /* run a test that simulates an approximate netbench client load */
809 static bool run_netbench(int client)
811 struct cli_state *cli;
816 const char *params[20];
823 cli_sockopt(cli, sockops);
827 slprintf(cname,sizeof(cname)-1, "client%d", client);
829 f = fopen(client_txt, "r");
836 while (fgets(line, sizeof(line)-1, f)) {
839 line[strlen(line)-1] = 0;
841 /* printf("[%d] %s\n", line_count, line); */
843 all_string_sub(line,"client1", cname, sizeof(line));
845 /* parse the command parameters */
846 params[0] = strtok(line," ");
848 while (params[i]) params[++i] = strtok(NULL," ");
854 if (!strncmp(params[0],"SMB", 3)) {
855 printf("ERROR: You are using a dbench 1 load file\n");
859 if (!strcmp(params[0],"NTCreateX")) {
860 nb_createx(params[1], ival(params[2]), ival(params[3]),
862 } else if (!strcmp(params[0],"Close")) {
863 nb_close(ival(params[1]));
864 } else if (!strcmp(params[0],"Rename")) {
865 nb_rename(params[1], params[2]);
866 } else if (!strcmp(params[0],"Unlink")) {
867 nb_unlink(params[1]);
868 } else if (!strcmp(params[0],"Deltree")) {
869 nb_deltree(params[1]);
870 } else if (!strcmp(params[0],"Rmdir")) {
872 } else if (!strcmp(params[0],"QUERY_PATH_INFORMATION")) {
873 nb_qpathinfo(params[1]);
874 } else if (!strcmp(params[0],"QUERY_FILE_INFORMATION")) {
875 nb_qfileinfo(ival(params[1]));
876 } else if (!strcmp(params[0],"QUERY_FS_INFORMATION")) {
877 nb_qfsinfo(ival(params[1]));
878 } else if (!strcmp(params[0],"FIND_FIRST")) {
879 nb_findfirst(params[1]);
880 } else if (!strcmp(params[0],"WriteX")) {
881 nb_writex(ival(params[1]),
882 ival(params[2]), ival(params[3]), ival(params[4]));
883 } else if (!strcmp(params[0],"ReadX")) {
884 nb_readx(ival(params[1]),
885 ival(params[2]), ival(params[3]), ival(params[4]));
886 } else if (!strcmp(params[0],"Flush")) {
887 nb_flush(ival(params[1]));
889 printf("Unknown operation %s\n", params[0]);
897 if (!torture_close_connection(cli)) {
905 /* run a test that simulates an approximate netbench client load */
906 static bool run_nbench(int dummy)
915 signal(SIGALRM, nb_alarm);
917 t = create_procs(run_netbench, &correct);
920 printf("\nThroughput %g MB/sec\n",
921 1.0e-6 * nbio_total() / t);
927 This test checks for two things:
929 1) correct support for retaining locks over a close (ie. the server
930 must not use posix semantics)
931 2) support for lock timeouts
933 static bool run_locktest1(int dummy)
935 struct cli_state *cli1, *cli2;
936 const char *fname = "\\lockt1.lck";
937 int fnum1, fnum2, fnum3;
939 unsigned lock_timeout;
941 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
944 cli_sockopt(cli1, sockops);
945 cli_sockopt(cli2, sockops);
947 printf("starting locktest1\n");
949 cli_unlink(cli1, fname);
951 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
953 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
956 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
958 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli1));
961 fnum3 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
963 printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli2));
967 if (!cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
968 printf("lock1 failed (%s)\n", cli_errstr(cli1));
973 if (cli_lock(cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
974 printf("lock2 succeeded! This is a locking bug\n");
977 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
978 NT_STATUS_LOCK_NOT_GRANTED)) return False;
982 lock_timeout = (1 + (random() % 20));
983 printf("Testing lock timeout with timeout=%u\n", lock_timeout);
985 if (cli_lock(cli2, fnum3, 0, 4, lock_timeout * 1000, WRITE_LOCK)) {
986 printf("lock3 succeeded! This is a locking bug\n");
989 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
990 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
994 if (ABS(t2 - t1) < lock_timeout-1) {
995 printf("error: This server appears not to support timed lock requests\n");
998 printf("server slept for %u seconds for a %u second timeout\n",
999 (unsigned int)(t2-t1), lock_timeout);
1001 if (!cli_close(cli1, fnum2)) {
1002 printf("close1 failed (%s)\n", cli_errstr(cli1));
1006 if (cli_lock(cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
1007 printf("lock4 succeeded! This is a locking bug\n");
1010 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
1011 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
1014 if (!cli_close(cli1, fnum1)) {
1015 printf("close2 failed (%s)\n", cli_errstr(cli1));
1019 if (!cli_close(cli2, fnum3)) {
1020 printf("close3 failed (%s)\n", cli_errstr(cli2));
1024 if (!cli_unlink(cli1, fname)) {
1025 printf("unlink failed (%s)\n", cli_errstr(cli1));
1030 if (!torture_close_connection(cli1)) {
1034 if (!torture_close_connection(cli2)) {
1038 printf("Passed locktest1\n");
1043 this checks to see if a secondary tconx can use open files from an
1046 static bool run_tcon_test(int dummy)
1048 static struct cli_state *cli;
1049 const char *fname = "\\tcontest.tmp";
1051 uint16 cnum1, cnum2, cnum3;
1052 uint16 vuid1, vuid2;
1056 memset(buf, '\0', sizeof(buf));
1058 if (!torture_open_connection(&cli, 0)) {
1061 cli_sockopt(cli, sockops);
1063 printf("starting tcontest\n");
1065 cli_unlink(cli, fname);
1067 fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1069 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
1076 if (cli_write(cli, fnum1, 0, buf, 130, 4) != 4) {
1077 printf("initial write failed (%s)", cli_errstr(cli));
1081 if (!cli_send_tconX(cli, share, "?????",
1082 password, strlen(password)+1)) {
1083 printf("%s refused 2nd tree connect (%s)\n", host,
1090 cnum3 = MAX(cnum1, cnum2) + 1; /* any invalid number */
1091 vuid2 = cli->vuid + 1;
1093 /* try a write with the wrong tid */
1096 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
1097 printf("* server allows write with wrong TID\n");
1100 printf("server fails write with wrong TID : %s\n", cli_errstr(cli));
1104 /* try a write with an invalid tid */
1107 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
1108 printf("* server allows write with invalid TID\n");
1111 printf("server fails write with invalid TID : %s\n", cli_errstr(cli));
1114 /* try a write with an invalid vuid */
1118 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
1119 printf("* server allows write with invalid VUID\n");
1122 printf("server fails write with invalid VUID : %s\n", cli_errstr(cli));
1128 if (!cli_close(cli, fnum1)) {
1129 printf("close failed (%s)\n", cli_errstr(cli));
1135 if (!cli_tdis(cli)) {
1136 printf("secondary tdis failed (%s)\n", cli_errstr(cli));
1142 if (!torture_close_connection(cli)) {
1151 checks for old style tcon support
1153 static bool run_tcon2_test(int dummy)
1155 static struct cli_state *cli;
1156 uint16 cnum, max_xmit;
1160 if (!torture_open_connection(&cli, 0)) {
1163 cli_sockopt(cli, sockops);
1165 printf("starting tcon2 test\n");
1167 asprintf(&service, "\\\\%s\\%s", host, share);
1169 status = cli_raw_tcon(cli, service, password, "?????", &max_xmit, &cnum);
1171 if (!NT_STATUS_IS_OK(status)) {
1172 printf("tcon2 failed : %s\n", cli_errstr(cli));
1174 printf("tcon OK : max_xmit=%d cnum=%d tid=%d\n",
1175 (int)max_xmit, (int)cnum, SVAL(cli->inbuf, smb_tid));
1178 if (!torture_close_connection(cli)) {
1182 printf("Passed tcon2 test\n");
1186 static bool tcon_devtest(struct cli_state *cli,
1187 const char *myshare, const char *devtype,
1188 const char *return_devtype,
1189 NTSTATUS expected_error)
1194 status = cli_send_tconX(cli, myshare, devtype,
1195 password, strlen(password)+1);
1197 if (NT_STATUS_IS_OK(expected_error)) {
1199 if (strcmp(cli->dev, return_devtype) == 0) {
1202 printf("tconX to share %s with type %s "
1203 "succeeded but returned the wrong "
1204 "device type (got [%s] but should have got [%s])\n",
1205 myshare, devtype, cli->dev, return_devtype);
1209 printf("tconX to share %s with type %s "
1210 "should have succeeded but failed\n",
1217 printf("tconx to share %s with type %s "
1218 "should have failed but succeeded\n",
1222 if (NT_STATUS_EQUAL(cli_nt_error(cli),
1226 printf("Returned unexpected error\n");
1235 checks for correct tconX support
1237 static bool run_tcon_devtype_test(int dummy)
1239 static struct cli_state *cli1 = NULL;
1245 status = cli_full_connection(&cli1, myname,
1246 host, NULL, port_to_use,
1248 username, workgroup,
1249 password, flags, Undefined, &retry);
1251 if (!NT_STATUS_IS_OK(status)) {
1252 printf("could not open connection\n");
1256 if (!tcon_devtest(cli1, "IPC$", "A:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1259 if (!tcon_devtest(cli1, "IPC$", "?????", "IPC", NT_STATUS_OK))
1262 if (!tcon_devtest(cli1, "IPC$", "LPT:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1265 if (!tcon_devtest(cli1, "IPC$", "IPC", "IPC", NT_STATUS_OK))
1268 if (!tcon_devtest(cli1, "IPC$", "FOOBA", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1271 if (!tcon_devtest(cli1, share, "A:", "A:", NT_STATUS_OK))
1274 if (!tcon_devtest(cli1, share, "?????", "A:", NT_STATUS_OK))
1277 if (!tcon_devtest(cli1, share, "LPT:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1280 if (!tcon_devtest(cli1, share, "IPC", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1283 if (!tcon_devtest(cli1, share, "FOOBA", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1289 printf("Passed tcondevtest\n");
1296 This test checks that
1298 1) the server supports multiple locking contexts on the one SMB
1299 connection, distinguished by PID.
1301 2) the server correctly fails overlapping locks made by the same PID (this
1302 goes against POSIX behaviour, which is why it is tricky to implement)
1304 3) the server denies unlock requests by an incorrect client PID
1306 static bool run_locktest2(int dummy)
1308 static struct cli_state *cli;
1309 const char *fname = "\\lockt2.lck";
1310 int fnum1, fnum2, fnum3;
1311 bool correct = True;
1313 if (!torture_open_connection(&cli, 0)) {
1317 cli_sockopt(cli, sockops);
1319 printf("starting locktest2\n");
1321 cli_unlink(cli, fname);
1325 fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1327 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
1331 fnum2 = cli_open(cli, fname, O_RDWR, DENY_NONE);
1333 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli));
1339 fnum3 = cli_open(cli, fname, O_RDWR, DENY_NONE);
1341 printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli));
1347 if (!cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
1348 printf("lock1 failed (%s)\n", cli_errstr(cli));
1352 if (cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
1353 printf("WRITE lock1 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, WRITE_LOCK)) {
1361 printf("WRITE lock2 succeeded! This is a locking bug\n");
1364 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1365 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1368 if (cli_lock(cli, fnum2, 0, 4, 0, READ_LOCK)) {
1369 printf("READ lock2 succeeded! This is a locking bug\n");
1372 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1373 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
1376 if (!cli_lock(cli, fnum1, 100, 4, 0, WRITE_LOCK)) {
1377 printf("lock at 100 failed (%s)\n", cli_errstr(cli));
1380 if (cli_unlock(cli, fnum1, 100, 4)) {
1381 printf("unlock at 100 succeeded! This is a locking bug\n");
1385 if (cli_unlock(cli, fnum1, 0, 4)) {
1386 printf("unlock1 succeeded! This is a locking bug\n");
1389 if (!check_error(__LINE__, cli,
1391 NT_STATUS_RANGE_NOT_LOCKED)) return False;
1394 if (cli_unlock(cli, fnum1, 0, 8)) {
1395 printf("unlock2 succeeded! This is a locking bug\n");
1398 if (!check_error(__LINE__, cli,
1400 NT_STATUS_RANGE_NOT_LOCKED)) return False;
1403 if (cli_lock(cli, fnum3, 0, 4, 0, WRITE_LOCK)) {
1404 printf("lock3 succeeded! This is a locking bug\n");
1407 if (!check_error(__LINE__, cli, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
1412 if (!cli_close(cli, fnum1)) {
1413 printf("close1 failed (%s)\n", cli_errstr(cli));
1417 if (!cli_close(cli, fnum2)) {
1418 printf("close2 failed (%s)\n", cli_errstr(cli));
1422 if (!cli_close(cli, fnum3)) {
1423 printf("close3 failed (%s)\n", cli_errstr(cli));
1427 if (!torture_close_connection(cli)) {
1431 printf("locktest2 finished\n");
1438 This test checks that
1440 1) the server supports the full offset range in lock requests
1442 static bool run_locktest3(int dummy)
1444 static struct cli_state *cli1, *cli2;
1445 const char *fname = "\\lockt3.lck";
1446 int fnum1, fnum2, i;
1448 bool correct = True;
1450 #define NEXT_OFFSET offset += (~(uint32)0) / torture_numops
1452 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1455 cli_sockopt(cli1, sockops);
1456 cli_sockopt(cli2, sockops);
1458 printf("starting locktest3\n");
1460 cli_unlink(cli1, fname);
1462 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1464 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
1467 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1469 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli2));
1473 for (offset=i=0;i<torture_numops;i++) {
1475 if (!cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1476 printf("lock1 %d failed (%s)\n",
1482 if (!cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1483 printf("lock2 %d failed (%s)\n",
1490 for (offset=i=0;i<torture_numops;i++) {
1493 if (cli_lock(cli1, fnum1, offset-2, 1, 0, WRITE_LOCK)) {
1494 printf("error: lock1 %d succeeded!\n", i);
1498 if (cli_lock(cli2, fnum2, offset-1, 1, 0, WRITE_LOCK)) {
1499 printf("error: lock2 %d succeeded!\n", i);
1503 if (cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1504 printf("error: lock3 %d succeeded!\n", i);
1508 if (cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1509 printf("error: lock4 %d succeeded!\n", i);
1514 for (offset=i=0;i<torture_numops;i++) {
1517 if (!cli_unlock(cli1, fnum1, offset-1, 1)) {
1518 printf("unlock1 %d failed (%s)\n",
1524 if (!cli_unlock(cli2, fnum2, offset-2, 1)) {
1525 printf("unlock2 %d failed (%s)\n",
1532 if (!cli_close(cli1, fnum1)) {
1533 printf("close1 failed (%s)\n", cli_errstr(cli1));
1537 if (!cli_close(cli2, fnum2)) {
1538 printf("close2 failed (%s)\n", cli_errstr(cli2));
1542 if (!cli_unlink(cli1, fname)) {
1543 printf("unlink failed (%s)\n", cli_errstr(cli1));
1547 if (!torture_close_connection(cli1)) {
1551 if (!torture_close_connection(cli2)) {
1555 printf("finished locktest3\n");
1560 #define EXPECTED(ret, v) if ((ret) != (v)) { \
1561 printf("** "); correct = False; \
1565 looks at overlapping locks
1567 static bool run_locktest4(int dummy)
1569 static struct cli_state *cli1, *cli2;
1570 const char *fname = "\\lockt4.lck";
1571 int fnum1, fnum2, f;
1574 bool correct = True;
1576 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1580 cli_sockopt(cli1, sockops);
1581 cli_sockopt(cli2, sockops);
1583 printf("starting locktest4\n");
1585 cli_unlink(cli1, fname);
1587 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1588 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1590 memset(buf, 0, sizeof(buf));
1592 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1593 printf("Failed to create file\n");
1598 ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1599 cli_lock(cli1, fnum1, 2, 4, 0, WRITE_LOCK);
1600 EXPECTED(ret, False);
1601 printf("the same process %s set overlapping write locks\n", ret?"can":"cannot");
1603 ret = cli_lock(cli1, fnum1, 10, 4, 0, READ_LOCK) &&
1604 cli_lock(cli1, fnum1, 12, 4, 0, READ_LOCK);
1605 EXPECTED(ret, True);
1606 printf("the same process %s set overlapping read locks\n", ret?"can":"cannot");
1608 ret = cli_lock(cli1, fnum1, 20, 4, 0, WRITE_LOCK) &&
1609 cli_lock(cli2, fnum2, 22, 4, 0, WRITE_LOCK);
1610 EXPECTED(ret, False);
1611 printf("a different connection %s set overlapping write locks\n", ret?"can":"cannot");
1613 ret = cli_lock(cli1, fnum1, 30, 4, 0, READ_LOCK) &&
1614 cli_lock(cli2, fnum2, 32, 4, 0, READ_LOCK);
1615 EXPECTED(ret, True);
1616 printf("a different connection %s set overlapping read locks\n", ret?"can":"cannot");
1618 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 40, 4, 0, WRITE_LOCK)) &&
1619 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 42, 4, 0, WRITE_LOCK));
1620 EXPECTED(ret, False);
1621 printf("a different pid %s set overlapping write locks\n", ret?"can":"cannot");
1623 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 50, 4, 0, READ_LOCK)) &&
1624 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 52, 4, 0, READ_LOCK));
1625 EXPECTED(ret, True);
1626 printf("a different pid %s set overlapping read locks\n", ret?"can":"cannot");
1628 ret = cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK) &&
1629 cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK);
1630 EXPECTED(ret, True);
1631 printf("the same process %s set the same read lock twice\n", ret?"can":"cannot");
1633 ret = cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK) &&
1634 cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK);
1635 EXPECTED(ret, False);
1636 printf("the same process %s set the same write lock twice\n", ret?"can":"cannot");
1638 ret = cli_lock(cli1, fnum1, 80, 4, 0, READ_LOCK) &&
1639 cli_lock(cli1, fnum1, 80, 4, 0, WRITE_LOCK);
1640 EXPECTED(ret, False);
1641 printf("the same process %s overlay a read lock with a write lock\n", ret?"can":"cannot");
1643 ret = cli_lock(cli1, fnum1, 90, 4, 0, WRITE_LOCK) &&
1644 cli_lock(cli1, fnum1, 90, 4, 0, READ_LOCK);
1645 EXPECTED(ret, True);
1646 printf("the same process %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1648 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 100, 4, 0, WRITE_LOCK)) &&
1649 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 100, 4, 0, READ_LOCK));
1650 EXPECTED(ret, False);
1651 printf("a different pid %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1653 ret = cli_lock(cli1, fnum1, 110, 4, 0, READ_LOCK) &&
1654 cli_lock(cli1, fnum1, 112, 4, 0, READ_LOCK) &&
1655 cli_unlock(cli1, fnum1, 110, 6);
1656 EXPECTED(ret, False);
1657 printf("the same process %s coalesce read locks\n", ret?"can":"cannot");
1660 ret = cli_lock(cli1, fnum1, 120, 4, 0, WRITE_LOCK) &&
1661 (cli_read(cli2, fnum2, buf, 120, 4) == 4);
1662 EXPECTED(ret, False);
1663 printf("this server %s strict write locking\n", ret?"doesn't do":"does");
1665 ret = cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK) &&
1666 (cli_write(cli2, fnum2, 0, buf, 130, 4) == 4);
1667 EXPECTED(ret, False);
1668 printf("this server %s strict read locking\n", ret?"doesn't do":"does");
1671 ret = cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1672 cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1673 cli_unlock(cli1, fnum1, 140, 4) &&
1674 cli_unlock(cli1, fnum1, 140, 4);
1675 EXPECTED(ret, True);
1676 printf("this server %s do recursive read locking\n", ret?"does":"doesn't");
1679 ret = cli_lock(cli1, fnum1, 150, 4, 0, WRITE_LOCK) &&
1680 cli_lock(cli1, fnum1, 150, 4, 0, READ_LOCK) &&
1681 cli_unlock(cli1, fnum1, 150, 4) &&
1682 (cli_read(cli2, fnum2, buf, 150, 4) == 4) &&
1683 !(cli_write(cli2, fnum2, 0, buf, 150, 4) == 4) &&
1684 cli_unlock(cli1, fnum1, 150, 4);
1685 EXPECTED(ret, True);
1686 printf("this server %s do recursive lock overlays\n", ret?"does":"doesn't");
1688 ret = cli_lock(cli1, fnum1, 160, 4, 0, READ_LOCK) &&
1689 cli_unlock(cli1, fnum1, 160, 4) &&
1690 (cli_write(cli2, fnum2, 0, buf, 160, 4) == 4) &&
1691 (cli_read(cli2, fnum2, buf, 160, 4) == 4);
1692 EXPECTED(ret, True);
1693 printf("the same process %s remove a read lock using write locking\n", ret?"can":"cannot");
1695 ret = cli_lock(cli1, fnum1, 170, 4, 0, WRITE_LOCK) &&
1696 cli_unlock(cli1, fnum1, 170, 4) &&
1697 (cli_write(cli2, fnum2, 0, buf, 170, 4) == 4) &&
1698 (cli_read(cli2, fnum2, buf, 170, 4) == 4);
1699 EXPECTED(ret, True);
1700 printf("the same process %s remove a write lock using read locking\n", ret?"can":"cannot");
1702 ret = cli_lock(cli1, fnum1, 190, 4, 0, WRITE_LOCK) &&
1703 cli_lock(cli1, fnum1, 190, 4, 0, READ_LOCK) &&
1704 cli_unlock(cli1, fnum1, 190, 4) &&
1705 !(cli_write(cli2, fnum2, 0, buf, 190, 4) == 4) &&
1706 (cli_read(cli2, fnum2, buf, 190, 4) == 4);
1707 EXPECTED(ret, True);
1708 printf("the same process %s remove the first lock first\n", ret?"does":"doesn't");
1710 cli_close(cli1, fnum1);
1711 cli_close(cli2, fnum2);
1712 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1713 f = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1714 ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1715 cli_lock(cli1, f, 0, 1, 0, READ_LOCK) &&
1716 cli_close(cli1, fnum1) &&
1717 ((fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE)) != -1) &&
1718 cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1720 cli_close(cli1, fnum1);
1721 EXPECTED(ret, True);
1722 printf("the server %s have the NT byte range lock bug\n", !ret?"does":"doesn't");
1725 cli_close(cli1, fnum1);
1726 cli_close(cli2, fnum2);
1727 cli_unlink(cli1, fname);
1728 torture_close_connection(cli1);
1729 torture_close_connection(cli2);
1731 printf("finished locktest4\n");
1736 looks at lock upgrade/downgrade.
1738 static bool run_locktest5(int dummy)
1740 static struct cli_state *cli1, *cli2;
1741 const char *fname = "\\lockt5.lck";
1742 int fnum1, fnum2, fnum3;
1745 bool correct = True;
1747 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1751 cli_sockopt(cli1, sockops);
1752 cli_sockopt(cli2, sockops);
1754 printf("starting locktest5\n");
1756 cli_unlink(cli1, fname);
1758 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1759 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1760 fnum3 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1762 memset(buf, 0, sizeof(buf));
1764 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1765 printf("Failed to create file\n");
1770 /* Check for NT bug... */
1771 ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1772 cli_lock(cli1, fnum3, 0, 1, 0, READ_LOCK);
1773 cli_close(cli1, fnum1);
1774 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1775 ret = cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1776 EXPECTED(ret, True);
1777 printf("this server %s the NT locking bug\n", ret ? "doesn't have" : "has");
1778 cli_close(cli1, fnum1);
1779 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1780 cli_unlock(cli1, fnum3, 0, 1);
1782 ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1783 cli_lock(cli1, fnum1, 1, 1, 0, READ_LOCK);
1784 EXPECTED(ret, True);
1785 printf("the same process %s overlay a write with a read lock\n", ret?"can":"cannot");
1787 ret = cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK);
1788 EXPECTED(ret, False);
1790 printf("a different processs %s get a read lock on the first process lock stack\n", ret?"can":"cannot");
1792 /* Unlock the process 2 lock. */
1793 cli_unlock(cli2, fnum2, 0, 4);
1795 ret = cli_lock(cli1, fnum3, 0, 4, 0, READ_LOCK);
1796 EXPECTED(ret, False);
1798 printf("the same processs on a different fnum %s get a read lock\n", ret?"can":"cannot");
1800 /* Unlock the process 1 fnum3 lock. */
1801 cli_unlock(cli1, fnum3, 0, 4);
1803 /* Stack 2 more locks here. */
1804 ret = cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK) &&
1805 cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK);
1807 EXPECTED(ret, True);
1808 printf("the same process %s stack read locks\n", ret?"can":"cannot");
1810 /* Unlock the first process lock, then check this was the WRITE lock that was
1813 ret = cli_unlock(cli1, fnum1, 0, 4) &&
1814 cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK);
1816 EXPECTED(ret, True);
1817 printf("the first unlock removes the %s lock\n", ret?"WRITE":"READ");
1819 /* Unlock the process 2 lock. */
1820 cli_unlock(cli2, fnum2, 0, 4);
1822 /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */
1824 ret = cli_unlock(cli1, fnum1, 1, 1) &&
1825 cli_unlock(cli1, fnum1, 0, 4) &&
1826 cli_unlock(cli1, fnum1, 0, 4);
1828 EXPECTED(ret, True);
1829 printf("the same process %s unlock the stack of 4 locks\n", ret?"can":"cannot");
1831 /* Ensure the next unlock fails. */
1832 ret = cli_unlock(cli1, fnum1, 0, 4);
1833 EXPECTED(ret, False);
1834 printf("the same process %s count the lock stack\n", !ret?"can":"cannot");
1836 /* Ensure connection 2 can get a write lock. */
1837 ret = cli_lock(cli2, fnum2, 0, 4, 0, WRITE_LOCK);
1838 EXPECTED(ret, True);
1840 printf("a different processs %s get a write lock on the unlocked stack\n", ret?"can":"cannot");
1844 cli_close(cli1, fnum1);
1845 cli_close(cli2, fnum2);
1846 cli_unlink(cli1, fname);
1847 if (!torture_close_connection(cli1)) {
1850 if (!torture_close_connection(cli2)) {
1854 printf("finished locktest5\n");
1860 tries the unusual lockingX locktype bits
1862 static bool run_locktest6(int dummy)
1864 static struct cli_state *cli;
1865 const char *fname[1] = { "\\lock6.txt" };
1870 if (!torture_open_connection(&cli, 0)) {
1874 cli_sockopt(cli, sockops);
1876 printf("starting locktest6\n");
1879 printf("Testing %s\n", fname[i]);
1881 cli_unlink(cli, fname[i]);
1883 fnum = cli_open(cli, fname[i], O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1884 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE);
1885 cli_close(cli, fnum);
1886 printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status));
1888 fnum = cli_open(cli, fname[i], O_RDWR, DENY_NONE);
1889 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK);
1890 cli_close(cli, fnum);
1891 printf("CANCEL_LOCK gave %s\n", nt_errstr(status));
1893 cli_unlink(cli, fname[i]);
1896 torture_close_connection(cli);
1898 printf("finished locktest6\n");
1902 static bool run_locktest7(int dummy)
1904 struct cli_state *cli1;
1905 const char *fname = "\\lockt7.lck";
1908 bool correct = False;
1910 if (!torture_open_connection(&cli1, 0)) {
1914 cli_sockopt(cli1, sockops);
1916 printf("starting locktest7\n");
1918 cli_unlink(cli1, fname);
1920 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1922 memset(buf, 0, sizeof(buf));
1924 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1925 printf("Failed to create file\n");
1929 cli_setpid(cli1, 1);
1931 if (!cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK)) {
1932 printf("Unable to apply read lock on range 130:4, error was %s\n", cli_errstr(cli1));
1935 printf("pid1 successfully locked range 130:4 for READ\n");
1938 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1939 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1942 printf("pid1 successfully read the range 130:4\n");
1945 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1946 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1947 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1948 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1952 printf("pid1 successfully wrote to the range 130:4 (should be denied)\n");
1956 cli_setpid(cli1, 2);
1958 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1959 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1961 printf("pid2 successfully read the range 130:4\n");
1964 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1965 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1966 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1967 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1971 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
1975 cli_setpid(cli1, 1);
1976 cli_unlock(cli1, fnum1, 130, 4);
1978 if (!cli_lock(cli1, fnum1, 130, 4, 0, WRITE_LOCK)) {
1979 printf("Unable to apply write lock on range 130:4, error was %s\n", cli_errstr(cli1));
1982 printf("pid1 successfully locked range 130:4 for WRITE\n");
1985 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1986 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1989 printf("pid1 successfully read the range 130:4\n");
1992 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1993 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1996 printf("pid1 successfully wrote to the range 130:4\n");
1999 cli_setpid(cli1, 2);
2001 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
2002 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
2003 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
2004 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2008 printf("pid2 successfully read the range 130:4 (should be denied)\n");
2012 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
2013 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
2014 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
2015 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2019 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
2023 cli_unlock(cli1, fnum1, 130, 0);
2027 cli_close(cli1, fnum1);
2028 cli_unlink(cli1, fname);
2029 torture_close_connection(cli1);
2031 printf("finished locktest7\n");
2036 test whether fnums and tids open on one VC are available on another (a major
2039 static bool run_fdpasstest(int dummy)
2041 struct cli_state *cli1, *cli2;
2042 const char *fname = "\\fdpass.tst";
2046 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
2049 cli_sockopt(cli1, sockops);
2050 cli_sockopt(cli2, sockops);
2052 printf("starting fdpasstest\n");
2054 cli_unlink(cli1, fname);
2056 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2058 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2062 if (cli_write(cli1, fnum1, 0, "hello world\n", 0, 13) != 13) {
2063 printf("write failed (%s)\n", cli_errstr(cli1));
2067 cli2->vuid = cli1->vuid;
2068 cli2->cnum = cli1->cnum;
2069 cli2->pid = cli1->pid;
2071 if (cli_read(cli2, fnum1, buf, 0, 13) == 13) {
2072 printf("read succeeded! nasty security hole [%s]\n",
2077 cli_close(cli1, fnum1);
2078 cli_unlink(cli1, fname);
2080 torture_close_connection(cli1);
2081 torture_close_connection(cli2);
2083 printf("finished fdpasstest\n");
2087 static bool run_fdsesstest(int dummy)
2089 struct cli_state *cli;
2094 const char *fname = "\\fdsess.tst";
2095 const char *fname1 = "\\fdsess1.tst";
2101 if (!torture_open_connection(&cli, 0))
2103 cli_sockopt(cli, sockops);
2105 if (!torture_cli_session_setup2(cli, &new_vuid))
2108 saved_cnum = cli->cnum;
2109 if (!cli_send_tconX(cli, share, "?????", "", 1))
2111 new_cnum = cli->cnum;
2112 cli->cnum = saved_cnum;
2114 printf("starting fdsesstest\n");
2116 cli_unlink(cli, fname);
2117 cli_unlink(cli, fname1);
2119 fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2121 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
2125 if (cli_write(cli, fnum1, 0, "hello world\n", 0, 13) != 13) {
2126 printf("write failed (%s)\n", cli_errstr(cli));
2130 saved_vuid = cli->vuid;
2131 cli->vuid = new_vuid;
2133 if (cli_read(cli, fnum1, buf, 0, 13) == 13) {
2134 printf("read succeeded with different vuid! nasty security hole [%s]\n",
2138 /* Try to open a file with different vuid, samba cnum. */
2139 fnum2 = cli_open(cli, fname1, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2141 printf("create with different vuid, same cnum succeeded.\n");
2142 cli_close(cli, fnum2);
2143 cli_unlink(cli, fname1);
2145 printf("create with different vuid, same cnum failed.\n");
2146 printf("This will cause problems with service clients.\n");
2150 cli->vuid = saved_vuid;
2152 /* Try with same vuid, different cnum. */
2153 cli->cnum = new_cnum;
2155 if (cli_read(cli, fnum1, buf, 0, 13) == 13) {
2156 printf("read succeeded with different cnum![%s]\n",
2161 cli->cnum = saved_cnum;
2162 cli_close(cli, fnum1);
2163 cli_unlink(cli, fname);
2165 torture_close_connection(cli);
2167 printf("finished fdsesstest\n");
2172 This test checks that
2174 1) the server does not allow an unlink on a file that is open
2176 static bool run_unlinktest(int dummy)
2178 struct cli_state *cli;
2179 const char *fname = "\\unlink.tst";
2181 bool correct = True;
2183 if (!torture_open_connection(&cli, 0)) {
2187 cli_sockopt(cli, sockops);
2189 printf("starting unlink test\n");
2191 cli_unlink(cli, fname);
2195 fnum = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2197 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
2201 if (cli_unlink(cli, fname)) {
2202 printf("error: server allowed unlink on an open file\n");
2205 correct = check_error(__LINE__, cli, ERRDOS, ERRbadshare,
2206 NT_STATUS_SHARING_VIOLATION);
2209 cli_close(cli, fnum);
2210 cli_unlink(cli, fname);
2212 if (!torture_close_connection(cli)) {
2216 printf("unlink test finished\n");
2223 test how many open files this server supports on the one socket
2225 static bool run_maxfidtest(int dummy)
2227 struct cli_state *cli;
2228 const char *ftemplate = "\\maxfid.%d.%d";
2230 int fnums[0x11000], i;
2232 bool correct = True;
2237 printf("failed to connect\n");
2241 cli_sockopt(cli, sockops);
2243 for (i=0; i<0x11000; i++) {
2244 slprintf(fname,sizeof(fname)-1,ftemplate, i,(int)getpid());
2245 if ((fnums[i] = cli_open(cli, fname,
2246 O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) ==
2248 printf("open of %s failed (%s)\n",
2249 fname, cli_errstr(cli));
2250 printf("maximum fnum is %d\n", i);
2258 printf("cleaning up\n");
2260 slprintf(fname,sizeof(fname)-1,ftemplate, i,(int)getpid());
2261 cli_close(cli, fnums[i]);
2262 if (!cli_unlink(cli, fname)) {
2263 printf("unlink of %s failed (%s)\n",
2264 fname, cli_errstr(cli));
2271 printf("maxfid test finished\n");
2272 if (!torture_close_connection(cli)) {
2278 /* generate a random buffer */
2279 static void rand_buf(char *buf, int len)
2282 *buf = (char)sys_random();
2287 /* send smb negprot commands, not reading the response */
2288 static bool run_negprot_nowait(int dummy)
2291 static struct cli_state *cli;
2292 bool correct = True;
2294 printf("starting negprot nowait test\n");
2296 if (!(cli = open_nbt_connection())) {
2300 for (i=0;i<50000;i++) {
2301 cli_negprot_send(cli);
2304 if (!torture_close_connection(cli)) {
2308 printf("finished negprot nowait test\n");
2314 /* send random IPC commands */
2315 static bool run_randomipc(int dummy)
2317 char *rparam = NULL;
2319 unsigned int rdrcnt,rprcnt;
2321 int api, param_len, i;
2322 struct cli_state *cli;
2323 bool correct = True;
2326 printf("starting random ipc test\n");
2328 if (!torture_open_connection(&cli, 0)) {
2332 for (i=0;i<count;i++) {
2333 api = sys_random() % 500;
2334 param_len = (sys_random() % 64);
2336 rand_buf(param, param_len);
2341 param, param_len, 8,
2342 NULL, 0, BUFFER_SIZE,
2346 printf("%d/%d\r", i,count);
2349 printf("%d/%d\n", i, count);
2351 if (!torture_close_connection(cli)) {
2355 printf("finished random ipc test\n");
2362 static void browse_callback(const char *sname, uint32 stype,
2363 const char *comment, void *state)
2365 printf("\t%20.20s %08x %s\n", sname, stype, comment);
2371 This test checks the browse list code
2374 static bool run_browsetest(int dummy)
2376 static struct cli_state *cli;
2377 bool correct = True;
2379 printf("starting browse test\n");
2381 if (!torture_open_connection(&cli, 0)) {
2385 printf("domain list:\n");
2386 cli_NetServerEnum(cli, cli->server_domain,
2387 SV_TYPE_DOMAIN_ENUM,
2388 browse_callback, NULL);
2390 printf("machine list:\n");
2391 cli_NetServerEnum(cli, cli->server_domain,
2393 browse_callback, NULL);
2395 if (!torture_close_connection(cli)) {
2399 printf("browse test finished\n");
2407 This checks how the getatr calls works
2409 static bool run_attrtest(int dummy)
2411 struct cli_state *cli;
2414 const char *fname = "\\attrib123456789.tst";
2415 bool correct = True;
2417 printf("starting attrib test\n");
2419 if (!torture_open_connection(&cli, 0)) {
2423 cli_unlink(cli, fname);
2424 fnum = cli_open(cli, fname,
2425 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2426 cli_close(cli, fnum);
2427 if (!cli_getatr(cli, fname, NULL, NULL, &t)) {
2428 printf("getatr failed (%s)\n", cli_errstr(cli));
2432 if (abs(t - time(NULL)) > 60*60*24*10) {
2433 printf("ERROR: SMBgetatr bug. time is %s",
2439 t2 = t-60*60*24; /* 1 day ago */
2441 if (!cli_setatr(cli, fname, 0, t2)) {
2442 printf("setatr failed (%s)\n", cli_errstr(cli));
2446 if (!cli_getatr(cli, fname, NULL, NULL, &t)) {
2447 printf("getatr failed (%s)\n", cli_errstr(cli));
2452 printf("ERROR: getatr/setatr bug. times are\n%s",
2454 printf("%s", ctime(&t2));
2458 cli_unlink(cli, fname);
2460 if (!torture_close_connection(cli)) {
2464 printf("attrib test finished\n");
2471 This checks a couple of trans2 calls
2473 static bool run_trans2test(int dummy)
2475 struct cli_state *cli;
2478 time_t c_time, a_time, m_time;
2479 struct timespec c_time_ts, a_time_ts, m_time_ts, w_time_ts, m_time2_ts;
2480 const char *fname = "\\trans2.tst";
2481 const char *dname = "\\trans2";
2482 const char *fname2 = "\\trans2\\trans2.tst";
2484 bool correct = True;
2486 printf("starting trans2 test\n");
2488 if (!torture_open_connection(&cli, 0)) {
2492 cli_unlink(cli, fname);
2493 fnum = cli_open(cli, fname,
2494 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2495 if (!cli_qfileinfo(cli, fnum, NULL, &size, &c_time_ts, &a_time_ts, &w_time_ts,
2496 &m_time_ts, NULL)) {
2497 printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(cli));
2501 if (!cli_qfilename(cli, fnum, pname)) {
2502 printf("ERROR: qfilename failed (%s)\n", cli_errstr(cli));
2506 if (strcmp(pname, fname)) {
2507 printf("qfilename gave different name? [%s] [%s]\n",
2512 cli_close(cli, fnum);
2516 cli_unlink(cli, fname);
2517 fnum = cli_open(cli, fname,
2518 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2520 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
2523 cli_close(cli, fnum);
2525 if (!cli_qpathinfo(cli, fname, &c_time, &a_time, &m_time, &size, NULL)) {
2526 printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(cli));
2529 if (c_time != m_time) {
2530 printf("create time=%s", ctime(&c_time));
2531 printf("modify time=%s", ctime(&m_time));
2532 printf("This system appears to have sticky create times\n");
2534 if (a_time % (60*60) == 0) {
2535 printf("access time=%s", ctime(&a_time));
2536 printf("This system appears to set a midnight access time\n");
2540 if (abs(m_time - time(NULL)) > 60*60*24*7) {
2541 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
2547 cli_unlink(cli, fname);
2548 fnum = cli_open(cli, fname,
2549 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2550 cli_close(cli, fnum);
2551 if (!cli_qpathinfo2(cli, fname, &c_time_ts, &a_time_ts, &w_time_ts,
2552 &m_time_ts, &size, NULL, NULL)) {
2553 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2556 if (w_time_ts.tv_sec < 60*60*24*2) {
2557 printf("write time=%s", ctime(&w_time_ts.tv_sec));
2558 printf("This system appears to set a initial 0 write time\n");
2563 cli_unlink(cli, fname);
2566 /* check if the server updates the directory modification time
2567 when creating a new file */
2568 if (!cli_mkdir(cli, dname)) {
2569 printf("ERROR: mkdir failed (%s)\n", cli_errstr(cli));
2573 if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts, &w_time_ts,
2574 &m_time_ts, &size, NULL, NULL)) {
2575 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2579 fnum = cli_open(cli, fname2,
2580 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2581 cli_write(cli, fnum, 0, (char *)&fnum, 0, sizeof(fnum));
2582 cli_close(cli, fnum);
2583 if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts, &w_time_ts,
2584 &m_time2_ts, &size, NULL, NULL)) {
2585 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2588 if (memcmp(&m_time_ts, &m_time2_ts, sizeof(struct timespec))
2590 printf("This system does not update directory modification times\n");
2594 cli_unlink(cli, fname2);
2595 cli_rmdir(cli, dname);
2597 if (!torture_close_connection(cli)) {
2601 printf("trans2 test finished\n");
2607 This checks new W2K calls.
2610 static bool new_trans(struct cli_state *pcli, int fnum, int level)
2614 bool correct = True;
2616 if (!cli_qfileinfo_test(pcli, fnum, level, &buf, &len)) {
2617 printf("ERROR: qfileinfo (%d) failed (%s)\n", level, cli_errstr(pcli));
2620 printf("qfileinfo: level %d, len = %u\n", level, len);
2621 dump_data(0, (uint8 *)buf, len);
2628 static bool run_w2ktest(int dummy)
2630 struct cli_state *cli;
2632 const char *fname = "\\w2ktest\\w2k.tst";
2634 bool correct = True;
2636 printf("starting w2k test\n");
2638 if (!torture_open_connection(&cli, 0)) {
2642 fnum = cli_open(cli, fname,
2643 O_RDWR | O_CREAT , DENY_NONE);
2645 for (level = 1004; level < 1040; level++) {
2646 new_trans(cli, fnum, level);
2649 cli_close(cli, fnum);
2651 if (!torture_close_connection(cli)) {
2655 printf("w2k test finished\n");
2662 this is a harness for some oplock tests
2664 static bool run_oplock1(int dummy)
2666 struct cli_state *cli1;
2667 const char *fname = "\\lockt1.lck";
2669 bool correct = True;
2671 printf("starting oplock test 1\n");
2673 if (!torture_open_connection(&cli1, 0)) {
2677 cli_unlink(cli1, fname);
2679 cli_sockopt(cli1, sockops);
2681 cli1->use_oplocks = True;
2683 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2685 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2689 cli1->use_oplocks = False;
2691 cli_unlink(cli1, fname);
2692 cli_unlink(cli1, fname);
2694 if (!cli_close(cli1, fnum1)) {
2695 printf("close2 failed (%s)\n", cli_errstr(cli1));
2699 if (!cli_unlink(cli1, fname)) {
2700 printf("unlink failed (%s)\n", cli_errstr(cli1));
2704 if (!torture_close_connection(cli1)) {
2708 printf("finished oplock test 1\n");
2713 static bool run_oplock2(int dummy)
2715 struct cli_state *cli1, *cli2;
2716 const char *fname = "\\lockt2.lck";
2718 int saved_use_oplocks = use_oplocks;
2720 bool correct = True;
2721 volatile bool *shared_correct;
2723 shared_correct = (volatile bool *)shm_setup(sizeof(bool));
2724 *shared_correct = True;
2726 use_level_II_oplocks = True;
2729 printf("starting oplock test 2\n");
2731 if (!torture_open_connection(&cli1, 0)) {
2732 use_level_II_oplocks = False;
2733 use_oplocks = saved_use_oplocks;
2737 cli1->use_oplocks = True;
2738 cli1->use_level_II_oplocks = True;
2740 if (!torture_open_connection(&cli2, 1)) {
2741 use_level_II_oplocks = False;
2742 use_oplocks = saved_use_oplocks;
2746 cli2->use_oplocks = True;
2747 cli2->use_level_II_oplocks = True;
2749 cli_unlink(cli1, fname);
2751 cli_sockopt(cli1, sockops);
2752 cli_sockopt(cli2, sockops);
2754 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2756 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2760 /* Don't need the globals any more. */
2761 use_level_II_oplocks = False;
2762 use_oplocks = saved_use_oplocks;
2766 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
2768 printf("second open of %s failed (%s)\n", fname, cli_errstr(cli1));
2769 *shared_correct = False;
2775 if (!cli_close(cli2, fnum2)) {
2776 printf("close2 failed (%s)\n", cli_errstr(cli1));
2777 *shared_correct = False;
2785 /* Ensure cli1 processes the break. Empty file should always return 0
2788 if (cli_read(cli1, fnum1, buf, 0, 4) != 0) {
2789 printf("read on fnum1 failed (%s)\n", cli_errstr(cli1));
2793 /* Should now be at level II. */
2794 /* Test if sending a write locks causes a break to none. */
2796 if (!cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK)) {
2797 printf("lock failed (%s)\n", cli_errstr(cli1));
2801 cli_unlock(cli1, fnum1, 0, 4);
2805 if (!cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
2806 printf("lock failed (%s)\n", cli_errstr(cli1));
2810 cli_unlock(cli1, fnum1, 0, 4);
2814 cli_read(cli1, fnum1, buf, 0, 4);
2817 if (cli_write(cli1, fnum1, 0, buf, 0, 4) != 4) {
2818 printf("write on fnum1 failed (%s)\n", cli_errstr(cli1));
2823 if (!cli_close(cli1, fnum1)) {
2824 printf("close1 failed (%s)\n", cli_errstr(cli1));
2830 if (!cli_unlink(cli1, fname)) {
2831 printf("unlink failed (%s)\n", cli_errstr(cli1));
2835 if (!torture_close_connection(cli1)) {
2839 if (!*shared_correct) {
2843 printf("finished oplock test 2\n");
2848 /* handler for oplock 3 tests */
2849 static bool oplock3_handler(struct cli_state *cli, int fnum, unsigned char level)
2851 printf("got oplock break fnum=%d level=%d\n",
2853 return cli_oplock_ack(cli, fnum, level);
2856 static bool run_oplock3(int dummy)
2858 struct cli_state *cli;
2859 const char *fname = "\\oplockt3.dat";
2861 char buf[4] = "abcd";
2862 bool correct = True;
2863 volatile bool *shared_correct;
2865 shared_correct = (volatile bool *)shm_setup(sizeof(bool));
2866 *shared_correct = True;
2868 printf("starting oplock test 3\n");
2873 use_level_II_oplocks = True;
2874 if (!torture_open_connection(&cli, 0)) {
2875 *shared_correct = False;
2879 /* try to trigger a oplock break in parent */
2880 fnum = cli_open(cli, fname, O_RDWR, DENY_NONE);
2881 cli_write(cli, fnum, 0, buf, 0, 4);
2887 use_level_II_oplocks = True;
2888 if (!torture_open_connection(&cli, 1)) { /* other is forked */
2891 cli_oplock_handler(cli, oplock3_handler);
2892 fnum = cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE);
2893 cli_write(cli, fnum, 0, buf, 0, 4);
2894 cli_close(cli, fnum);
2895 fnum = cli_open(cli, fname, O_RDWR, DENY_NONE);
2896 cli->timeout = 20000;
2897 cli_receive_smb(cli);
2898 printf("finished oplock test 3\n");
2900 return (correct && *shared_correct);
2902 /* What are we looking for here? What's sucess and what's FAILURE? */
2908 Test delete on close semantics.
2910 static bool run_deletetest(int dummy)
2912 struct cli_state *cli1 = NULL;
2913 struct cli_state *cli2 = NULL;
2914 const char *fname = "\\delete.file";
2917 bool correct = True;
2919 printf("starting delete test\n");
2921 if (!torture_open_connection(&cli1, 0)) {
2925 cli_sockopt(cli1, sockops);
2927 /* Test 1 - this should delete the file on close. */
2929 cli_setatr(cli1, fname, 0, 0);
2930 cli_unlink(cli1, fname);
2932 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
2933 0, FILE_OVERWRITE_IF,
2934 FILE_DELETE_ON_CLOSE, 0);
2937 printf("[1] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2944 uint32 *accinfo = NULL;
2946 cli_qfileinfo_test(cli1, fnum1, SMB_FILE_ACCESS_INFORMATION, (char **)&accinfo, &len);
2948 printf("access mode = 0x%lx\n", *accinfo);
2953 if (!cli_close(cli1, fnum1)) {
2954 printf("[1] close failed (%s)\n", cli_errstr(cli1));
2959 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
2961 printf("[1] open of %s succeeded (should fail)\n", fname);
2966 printf("first delete on close test succeeded.\n");
2968 /* Test 2 - this should delete the file on close. */
2970 cli_setatr(cli1, fname, 0, 0);
2971 cli_unlink(cli1, fname);
2973 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_ALL_ACCESS,
2974 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
2975 FILE_OVERWRITE_IF, 0, 0);
2978 printf("[2] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2983 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
2984 printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
2989 if (!cli_close(cli1, fnum1)) {
2990 printf("[2] close failed (%s)\n", cli_errstr(cli1));
2995 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
2997 printf("[2] open of %s succeeded should have been deleted on close !\n", fname);
2998 if (!cli_close(cli1, fnum1)) {
2999 printf("[2] close failed (%s)\n", cli_errstr(cli1));
3003 cli_unlink(cli1, fname);
3005 printf("second delete on close test succeeded.\n");
3008 cli_setatr(cli1, fname, 0, 0);
3009 cli_unlink(cli1, fname);
3011 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
3012 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0);
3015 printf("[3] open - 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3020 /* This should fail with a sharing violation - open for delete is only compatible
3021 with SHARE_DELETE. */
3023 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3024 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0, 0);
3027 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname);
3032 /* This should succeed. */
3034 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3035 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0, 0);
3038 printf("[3] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
3043 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
3044 printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
3049 if (!cli_close(cli1, fnum1)) {
3050 printf("[3] close 1 failed (%s)\n", cli_errstr(cli1));
3055 if (!cli_close(cli1, fnum2)) {
3056 printf("[3] close 2 failed (%s)\n", cli_errstr(cli1));
3061 /* This should fail - file should no longer be there. */
3063 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
3065 printf("[3] open of %s succeeded should have been deleted on close !\n", fname);
3066 if (!cli_close(cli1, fnum1)) {
3067 printf("[3] close failed (%s)\n", cli_errstr(cli1));
3069 cli_unlink(cli1, fname);
3073 printf("third delete on close test succeeded.\n");
3076 cli_setatr(cli1, fname, 0, 0);
3077 cli_unlink(cli1, fname);
3079 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3080 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0);
3083 printf("[4] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3088 /* This should succeed. */
3089 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS,
3090 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0, 0);
3092 printf("[4] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
3097 if (!cli_close(cli1, fnum2)) {
3098 printf("[4] close - 1 failed (%s)\n", cli_errstr(cli1));
3103 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
3104 printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
3109 /* This should fail - no more opens once delete on close set. */
3110 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS,
3111 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3114 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname );
3118 printf("fourth delete on close test succeeded.\n");
3120 if (!cli_close(cli1, fnum1)) {
3121 printf("[4] close - 2 failed (%s)\n", cli_errstr(cli1));
3127 cli_setatr(cli1, fname, 0, 0);
3128 cli_unlink(cli1, fname);
3130 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT, DENY_NONE);
3132 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3137 /* This should fail - only allowed on NT opens with DELETE access. */
3139 if (cli_nt_delete_on_close(cli1, fnum1, True)) {
3140 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
3145 if (!cli_close(cli1, fnum1)) {
3146 printf("[5] close - 2 failed (%s)\n", cli_errstr(cli1));
3151 printf("fifth delete on close test succeeded.\n");
3154 cli_setatr(cli1, fname, 0, 0);
3155 cli_unlink(cli1, fname);
3157 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
3158 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3159 FILE_OVERWRITE_IF, 0, 0);
3162 printf("[6] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3167 /* This should fail - only allowed on NT opens with DELETE access. */
3169 if (cli_nt_delete_on_close(cli1, fnum1, True)) {
3170 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
3175 if (!cli_close(cli1, fnum1)) {
3176 printf("[6] close - 2 failed (%s)\n", cli_errstr(cli1));
3181 printf("sixth delete on close test succeeded.\n");
3184 cli_setatr(cli1, fname, 0, 0);
3185 cli_unlink(cli1, fname);
3187 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3188 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0, 0);
3191 printf("[7] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3196 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
3197 printf("[7] setting delete_on_close on file failed !\n");
3202 if (!cli_nt_delete_on_close(cli1, fnum1, False)) {
3203 printf("[7] unsetting delete_on_close on file failed !\n");
3208 if (!cli_close(cli1, fnum1)) {
3209 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
3214 /* This next open should succeed - we reset the flag. */
3216 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
3218 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3223 if (!cli_close(cli1, fnum1)) {
3224 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
3229 printf("seventh delete on close test succeeded.\n");
3232 cli_setatr(cli1, fname, 0, 0);
3233 cli_unlink(cli1, fname);
3235 if (!torture_open_connection(&cli2, 1)) {
3236 printf("[8] failed to open second connection.\n");
3241 cli_sockopt(cli1, sockops);
3243 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3244 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3245 FILE_OVERWRITE_IF, 0, 0);
3248 printf("[8] open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3253 fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3254 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3258 printf("[8] open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3263 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
3264 printf("[8] setting delete_on_close on file failed !\n");
3269 if (!cli_close(cli1, fnum1)) {
3270 printf("[8] close - 1 failed (%s)\n", cli_errstr(cli1));
3275 if (!cli_close(cli2, fnum2)) {
3276 printf("[8] close - 2 failed (%s)\n", cli_errstr(cli2));
3281 /* This should fail.. */
3282 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
3284 printf("[8] open of %s succeeded should have been deleted on close !\n", fname);
3288 printf("eighth delete on close test succeeded.\n");
3290 /* This should fail - we need to set DELETE_ACCESS. */
3291 fnum1 = cli_nt_create_full(cli1, fname, 0,FILE_READ_DATA|FILE_WRITE_DATA,
3292 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, 0);
3295 printf("[9] open of %s succeeded should have failed!\n", fname);
3300 printf("ninth delete on close test succeeded.\n");
3302 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3303 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, 0);
3305 printf("[10] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3310 /* This should delete the file. */
3311 if (!cli_close(cli1, fnum1)) {
3312 printf("[10] close failed (%s)\n", cli_errstr(cli1));
3317 /* This should fail.. */
3318 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
3320 printf("[10] open of %s succeeded should have been deleted on close !\n", fname);
3324 printf("tenth delete on close test succeeded.\n");
3326 cli_setatr(cli1, fname, 0, 0);
3327 cli_unlink(cli1, fname);
3329 /* What error do we get when attempting to open a read-only file with
3332 /* Create a readonly file. */
3333 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
3334 FILE_ATTRIBUTE_READONLY, FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3336 printf("[11] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3341 if (!cli_close(cli1, fnum1)) {
3342 printf("[11] close failed (%s)\n", cli_errstr(cli1));
3347 /* Now try open for delete access. */
3348 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_ATTRIBUTES|DELETE_ACCESS,
3349 0, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3350 FILE_OVERWRITE_IF, 0, 0);
3353 printf("[11] open of %s succeeded should have been denied with ACCESS_DENIED!\n", fname);
3354 cli_close(cli1, fnum1);
3358 NTSTATUS nterr = cli_nt_error(cli1);
3359 if (!NT_STATUS_EQUAL(nterr,NT_STATUS_ACCESS_DENIED)) {
3360 printf("[11] open of %s should have been denied with ACCESS_DENIED! Got error %s\n", fname, nt_errstr(nterr));
3364 printf("eleventh delete on close test succeeded.\n");
3368 printf("finished delete test\n");
3371 /* FIXME: This will crash if we aborted before cli2 got
3372 * intialized, because these functions don't handle
3373 * uninitialized connections. */
3375 if (fnum1 != -1) cli_close(cli1, fnum1);
3376 if (fnum2 != -1) cli_close(cli1, fnum2);
3377 cli_setatr(cli1, fname, 0, 0);
3378 cli_unlink(cli1, fname);
3380 if (cli1 && !torture_close_connection(cli1)) {
3383 if (cli2 && !torture_close_connection(cli2)) {
3391 print out server properties
3393 static bool run_properties(int dummy)
3395 static struct cli_state *cli;
3396 bool correct = True;
3398 printf("starting properties test\n");
3402 if (!torture_open_connection(&cli, 0)) {
3406 cli_sockopt(cli, sockops);
3408 d_printf("Capabilities 0x%08x\n", cli->capabilities);
3410 if (!torture_close_connection(cli)) {
3419 /* FIRST_DESIRED_ACCESS 0xf019f */
3420 #define FIRST_DESIRED_ACCESS FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|\
3421 FILE_READ_EA| /* 0xf */ \
3422 FILE_WRITE_EA|FILE_READ_ATTRIBUTES| /* 0x90 */ \
3423 FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
3424 DELETE_ACCESS|READ_CONTROL_ACCESS|\
3425 WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS /* 0xf0000 */
3426 /* SECOND_DESIRED_ACCESS 0xe0080 */
3427 #define SECOND_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
3428 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
3429 WRITE_OWNER_ACCESS /* 0xe0000 */
3432 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
3433 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
3435 WRITE_OWNER_ACCESS /* */
3439 Test ntcreate calls made by xcopy
3441 static bool run_xcopy(int dummy)
3443 static struct cli_state *cli1;
3444 const char *fname = "\\test.txt";
3445 bool correct = True;
3448 printf("starting xcopy test\n");
3450 if (!torture_open_connection(&cli1, 0)) {
3454 fnum1 = cli_nt_create_full(cli1, fname, 0,
3455 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
3456 FILE_SHARE_NONE, FILE_OVERWRITE_IF,
3460 printf("First open failed - %s\n", cli_errstr(cli1));
3464 fnum2 = cli_nt_create_full(cli1, fname, 0,
3465 SECOND_DESIRED_ACCESS, 0,
3466 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN,
3469 printf("second open failed - %s\n", cli_errstr(cli1));
3473 if (!torture_close_connection(cli1)) {
3481 Test rename on files open with share delete and no share delete.
3483 static bool run_rename(int dummy)
3485 static struct cli_state *cli1;
3486 const char *fname = "\\test.txt";
3487 const char *fname1 = "\\test1.txt";
3488 bool correct = True;
3491 printf("starting rename test\n");
3493 if (!torture_open_connection(&cli1, 0)) {
3497 cli_unlink(cli1, fname);
3498 cli_unlink(cli1, fname1);
3499 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3500 FILE_SHARE_READ, FILE_OVERWRITE_IF, 0, 0);
3503 printf("First open failed - %s\n", cli_errstr(cli1));
3507 if (!cli_rename(cli1, fname, fname1)) {
3508 printf("First rename failed (SHARE_READ) (this is correct) - %s\n", cli_errstr(cli1));
3510 printf("First rename succeeded (SHARE_READ) - this should have failed !\n");
3514 if (!cli_close(cli1, fnum1)) {
3515 printf("close - 1 failed (%s)\n", cli_errstr(cli1));
3519 cli_unlink(cli1, fname);
3520 cli_unlink(cli1, fname1);
3521 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3523 FILE_SHARE_DELETE|FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3525 FILE_SHARE_DELETE|FILE_SHARE_READ, FILE_OVERWRITE_IF, 0, 0);
3529 printf("Second open failed - %s\n", cli_errstr(cli1));
3533 if (!cli_rename(cli1, fname, fname1)) {
3534 printf("Second rename failed (SHARE_DELETE | SHARE_READ) - this should have succeeded - %s\n", cli_errstr(cli1));
3537 printf("Second rename succeeded (SHARE_DELETE | SHARE_READ)\n");
3540 if (!cli_close(cli1, fnum1)) {
3541 printf("close - 2 failed (%s)\n", cli_errstr(cli1));
3545 cli_unlink(cli1, fname);
3546 cli_unlink(cli1, fname1);
3548 fnum1 = cli_nt_create_full(cli1, fname, 0, READ_CONTROL_ACCESS, FILE_ATTRIBUTE_NORMAL,
3549 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3552 printf("Third open failed - %s\n", cli_errstr(cli1));
3561 fnum2 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
3562 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3565 printf("Fourth open failed - %s\n", cli_errstr(cli1));
3568 if (!cli_nt_delete_on_close(cli1, fnum2, True)) {
3569 printf("[8] setting delete_on_close on file failed !\n");
3573 if (!cli_close(cli1, fnum2)) {
3574 printf("close - 4 failed (%s)\n", cli_errstr(cli1));
3580 if (!cli_rename(cli1, fname, fname1)) {
3581 printf("Third rename failed (SHARE_NONE) - this should have succeeded - %s\n", cli_errstr(cli1));
3584 printf("Third rename succeeded (SHARE_NONE)\n");
3587 if (!cli_close(cli1, fnum1)) {
3588 printf("close - 3 failed (%s)\n", cli_errstr(cli1));
3592 cli_unlink(cli1, fname);
3593 cli_unlink(cli1, fname1);
3597 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3598 FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0);
3601 printf("Fourth open failed - %s\n", cli_errstr(cli1));
3605 if (!cli_rename(cli1, fname, fname1)) {
3606 printf("Fourth rename failed (SHARE_READ | SHARE_WRITE) (this is correct) - %s\n", cli_errstr(cli1));
3608 printf("Fourth rename succeeded (SHARE_READ | SHARE_WRITE) - this should have failed !\n");
3612 if (!cli_close(cli1, fnum1)) {
3613 printf("close - 4 failed (%s)\n", cli_errstr(cli1));
3617 cli_unlink(cli1, fname);
3618 cli_unlink(cli1, fname1);
3622 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3623 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0);
3626 printf("Fifth open failed - %s\n", cli_errstr(cli1));
3630 if (!cli_rename(cli1, fname, fname1)) {
3631 printf("Fifth rename failed (SHARE_READ | SHARE_WRITE | SHARE_DELETE) - this should have failed ! \n");
3634 printf("Fifth rename succeeded (SHARE_READ | SHARE_WRITE | SHARE_DELETE) (this is correct) - %s\n", cli_errstr(cli1));
3638 * Now check if the first name still exists ...
3641 /*fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3642 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0);
3645 printf("Opening original file after rename of open file fails: %s\n",
3649 printf("Opening original file after rename of open file works ...\n");
3650 (void)cli_close(cli1, fnum2);
3656 if (!cli_close(cli1, fnum1)) {
3657 printf("close - 5 failed (%s)\n", cli_errstr(cli1));
3661 cli_unlink(cli1, fname);
3662 cli_unlink(cli1, fname1);
3664 if (!torture_close_connection(cli1)) {
3671 static bool run_pipe_number(int dummy)
3673 struct cli_state *cli1;
3674 const char *pipe_name = "\\SPOOLSS";
3678 printf("starting pipenumber test\n");
3679 if (!torture_open_connection(&cli1, 0)) {
3683 cli_sockopt(cli1, sockops);
3685 fnum = cli_nt_create_full(cli1, pipe_name, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
3686 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN_IF, 0, 0);
3689 printf("Open of pipe %s failed with error (%s)\n", pipe_name, cli_errstr(cli1));
3693 printf("\r%6d", num_pipes);
3696 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes, pipe_name );
3697 torture_close_connection(cli1);
3702 Test open mode returns on read-only files.
3704 static bool run_opentest(int dummy)
3706 static struct cli_state *cli1;
3707 static struct cli_state *cli2;
3708 const char *fname = "\\readonly.file";
3712 bool correct = True;
3715 printf("starting open test\n");
3717 if (!torture_open_connection(&cli1, 0)) {
3721 cli_setatr(cli1, fname, 0, 0);
3722 cli_unlink(cli1, fname);
3724 cli_sockopt(cli1, sockops);
3726 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
3728 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
3732 if (!cli_close(cli1, fnum1)) {
3733 printf("close2 failed (%s)\n", cli_errstr(cli1));
3737 if (!cli_setatr(cli1, fname, aRONLY, 0)) {
3738 printf("cli_setatr failed (%s)\n", cli_errstr(cli1));
3742 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_WRITE);
3744 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
3748 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
3749 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_ALL);
3751 if (check_error(__LINE__, cli1, ERRDOS, ERRnoaccess,
3752 NT_STATUS_ACCESS_DENIED)) {
3753 printf("correct error code ERRDOS/ERRnoaccess returned\n");
3756 printf("finished open test 1\n");
3758 cli_close(cli1, fnum1);
3760 /* Now try not readonly and ensure ERRbadshare is returned. */
3762 cli_setatr(cli1, fname, 0, 0);
3764 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_WRITE);
3766 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
3770 /* This will fail - but the error should be ERRshare. */
3771 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_ALL);
3773 if (check_error(__LINE__, cli1, ERRDOS, ERRbadshare,
3774 NT_STATUS_SHARING_VIOLATION)) {
3775 printf("correct error code ERRDOS/ERRbadshare returned\n");
3778 if (!cli_close(cli1, fnum1)) {
3779 printf("close2 failed (%s)\n", cli_errstr(cli1));
3783 cli_unlink(cli1, fname);
3785 printf("finished open test 2\n");
3787 /* Test truncate open disposition on file opened for read. */
3789 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
3791 printf("(3) open (1) of %s failed (%s)\n", fname, cli_errstr(cli1));
3795 /* write 20 bytes. */
3797 memset(buf, '\0', 20);
3799 if (cli_write(cli1, fnum1, 0, buf, 0, 20) != 20) {
3800 printf("write failed (%s)\n", cli_errstr(cli1));
3804 if (!cli_close(cli1, fnum1)) {
3805 printf("(3) close1 failed (%s)\n", cli_errstr(cli1));
3809 /* Ensure size == 20. */
3810 if (!cli_getatr(cli1, fname, NULL, &fsize, NULL)) {
3811 printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
3816 printf("(3) file size != 20\n");
3820 /* Now test if we can truncate a file opened for readonly. */
3822 fnum1 = cli_open(cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE);
3824 printf("(3) open (2) of %s failed (%s)\n", fname, cli_errstr(cli1));
3828 if (!cli_close(cli1, fnum1)) {
3829 printf("close2 failed (%s)\n", cli_errstr(cli1));
3833 /* Ensure size == 0. */
3834 if (!cli_getatr(cli1, fname, NULL, &fsize, NULL)) {
3835 printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
3840 printf("(3) file size != 0\n");
3843 printf("finished open test 3\n");
3845 cli_unlink(cli1, fname);
3848 printf("testing ctemp\n");
3849 fnum1 = cli_ctemp(cli1, "\\", &tmp_path);
3851 printf("ctemp failed (%s)\n", cli_errstr(cli1));
3854 printf("ctemp gave path %s\n", tmp_path);
3855 if (!cli_close(cli1, fnum1)) {
3856 printf("close of temp failed (%s)\n", cli_errstr(cli1));
3858 if (!cli_unlink(cli1, tmp_path)) {
3859 printf("unlink of temp failed (%s)\n", cli_errstr(cli1));
3862 /* Test the non-io opens... */
3864 if (!torture_open_connection(&cli2, 1)) {
3868 cli_setatr(cli2, fname, 0, 0);
3869 cli_unlink(cli2, fname);
3871 cli_sockopt(cli2, sockops);
3873 printf("TEST #1 testing 2 non-io opens (no delete)\n");
3875 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3876 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3879 printf("test 1 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3883 fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3884 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
3887 printf("test 1 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3891 if (!cli_close(cli1, fnum1)) {
3892 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3895 if (!cli_close(cli2, fnum2)) {
3896 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3900 printf("non-io open test #1 passed.\n");
3902 cli_unlink(cli1, fname);
3904 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
3906 fnum1 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3907 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3910 printf("test 2 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3914 fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3915 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
3918 printf("test 2 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3922 if (!cli_close(cli1, fnum1)) {
3923 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3926 if (!cli_close(cli2, fnum2)) {
3927 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
3931 printf("non-io open test #2 passed.\n");
3933 cli_unlink(cli1, fname);
3935 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
3937 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3938 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3941 printf("test 3 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3945 fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3946 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
3949 printf("test 3 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3953 if (!cli_close(cli1, fnum1)) {
3954 printf("test 3 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3957 if (!cli_close(cli2, fnum2)) {
3958 printf("test 3 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3962 printf("non-io open test #3 passed.\n");
3964 cli_unlink(cli1, fname);
3966 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
3968 fnum1 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3969 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3972 printf("test 4 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3976 fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3977 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
3980 printf("test 4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
3984 printf("test 3 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
3986 if (!cli_close(cli1, fnum1)) {
3987 printf("test 4 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3991 printf("non-io open test #4 passed.\n");
3993 cli_unlink(cli1, fname);
3995 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
3997 fnum1 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3998 FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0);
4001 printf("test 5 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4005 fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4006 FILE_SHARE_DELETE, FILE_OPEN_IF, 0, 0);
4009 printf("test 5 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4013 if (!cli_close(cli1, fnum1)) {
4014 printf("test 5 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4018 if (!cli_close(cli2, fnum2)) {
4019 printf("test 5 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4023 printf("non-io open test #5 passed.\n");
4025 printf("TEST #6 testing 1 non-io open, one io open\n");
4027 cli_unlink(cli1, fname);
4029 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
4030 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
4033 printf("test 6 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4037 fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4038 FILE_SHARE_READ, FILE_OPEN_IF, 0, 0);
4041 printf("test 6 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4045 if (!cli_close(cli1, fnum1)) {
4046 printf("test 6 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4050 if (!cli_close(cli2, fnum2)) {
4051 printf("test 6 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4055 printf("non-io open test #6 passed.\n");
4057 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
4059 cli_unlink(cli1, fname);
4061 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
4062 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
4065 printf("test 7 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4069 fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4070 FILE_SHARE_READ|FILE_SHARE_DELETE, FILE_OPEN_IF, 0, 0);
4073 printf("test 7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
4077 printf("test 7 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
4079 if (!cli_close(cli1, fnum1)) {
4080 printf("test 7 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4084 printf("non-io open test #7 passed.\n");
4086 cli_unlink(cli1, fname);
4088 if (!torture_close_connection(cli1)) {
4091 if (!torture_close_connection(cli2)) {
4098 static uint32 open_attrs_table[] = {
4099 FILE_ATTRIBUTE_NORMAL,
4100 FILE_ATTRIBUTE_ARCHIVE,
4101 FILE_ATTRIBUTE_READONLY,
4102 FILE_ATTRIBUTE_HIDDEN,
4103 FILE_ATTRIBUTE_SYSTEM,
4105 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY,
4106 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN,
4107 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM,
4108 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
4109 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
4110 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
4112 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
4113 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
4114 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
4115 FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_SYSTEM,
4118 struct trunc_open_results {
4125 static struct trunc_open_results attr_results[] = {
4126 { 0, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
4127 { 1, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
4128 { 2, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
4129 { 16, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
4130 { 17, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
4131 { 18, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
4132 { 51, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4133 { 54, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4134 { 56, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
4135 { 68, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4136 { 71, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4137 { 73, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM },
4138 { 99, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4139 { 102, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4140 { 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 },
4141 { 116, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4142 { 119, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4143 { 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 },
4144 { 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 },
4145 { 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 },
4146 { 227, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4147 { 230, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4148 { 232, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
4149 { 244, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4150 { 247, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4151 { 249, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM }
4154 static bool run_openattrtest(int dummy)
4156 static struct cli_state *cli1;
4157 const char *fname = "\\openattr.file";
4159 bool correct = True;
4161 unsigned int i, j, k, l;
4163 printf("starting open attr test\n");
4165 if (!torture_open_connection(&cli1, 0)) {
4169 cli_sockopt(cli1, sockops);
4171 for (k = 0, i = 0; i < sizeof(open_attrs_table)/sizeof(uint32); i++) {
4172 cli_setatr(cli1, fname, 0, 0);
4173 cli_unlink(cli1, fname);
4174 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_WRITE_DATA, open_attrs_table[i],
4175 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
4178 printf("open %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
4182 if (!cli_close(cli1, fnum1)) {
4183 printf("close %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
4187 for (j = 0; j < sizeof(open_attrs_table)/sizeof(uint32); j++) {
4188 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA, open_attrs_table[j],
4189 FILE_SHARE_NONE, FILE_OVERWRITE, 0, 0);
4192 for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
4193 if (attr_results[l].num == k) {
4194 printf("[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(0x%x:%s)\n",
4195 k, open_attrs_table[i],
4196 open_attrs_table[j],
4197 fname, NT_STATUS_V(cli_nt_error(cli1)), cli_errstr(cli1));
4201 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_ACCESS_DENIED)) {
4202 printf("[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s\n",
4203 k, open_attrs_table[i], open_attrs_table[j],
4208 printf("[%d] trunc open 0x%x -> 0x%x failed\n", k, open_attrs_table[i], open_attrs_table[j]);
4214 if (!cli_close(cli1, fnum1)) {
4215 printf("close %d (2) of %s failed (%s)\n", j, fname, cli_errstr(cli1));
4219 if (!cli_getatr(cli1, fname, &attr, NULL, NULL)) {
4220 printf("getatr(2) failed (%s)\n", cli_errstr(cli1));
4225 printf("[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n",
4226 k, open_attrs_table[i], open_attrs_table[j], attr );
4229 for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
4230 if (attr_results[l].num == k) {
4231 if (attr != attr_results[l].result_attr ||
4232 open_attrs_table[i] != attr_results[l].init_attr ||
4233 open_attrs_table[j] != attr_results[l].trunc_attr) {
4234 printf("getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x\n",
4235 open_attrs_table[i],
4236 open_attrs_table[j],
4238 attr_results[l].result_attr);
4248 cli_setatr(cli1, fname, 0, 0);
4249 cli_unlink(cli1, fname);
4251 printf("open attr test %s.\n", correct ? "passed" : "failed");
4253 if (!torture_close_connection(cli1)) {
4259 static void list_fn(const char *mnt, file_info *finfo, const char *name, void *state)
4265 test directory listing speed
4267 static bool run_dirtest(int dummy)
4270 static struct cli_state *cli;
4273 bool correct = True;
4275 printf("starting directory test\n");
4277 if (!torture_open_connection(&cli, 0)) {
4281 cli_sockopt(cli, sockops);
4284 for (i=0;i<torture_numops;i++) {
4286 slprintf(fname, sizeof(fname), "\\%x", (int)random());
4287 fnum = cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE);
4289 fprintf(stderr,"Failed to open %s\n", fname);
4292 cli_close(cli, fnum);
4297 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
4298 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
4299 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
4301 printf("dirtest core %g seconds\n", end_timer() - t1);
4304 for (i=0;i<torture_numops;i++) {
4306 slprintf(fname, sizeof(fname), "\\%x", (int)random());
4307 cli_unlink(cli, fname);
4310 if (!torture_close_connection(cli)) {
4314 printf("finished dirtest\n");
4319 static void del_fn(const char *mnt, file_info *finfo, const char *mask, void *state)
4321 struct cli_state *pcli = (struct cli_state *)state;
4323 slprintf(fname, sizeof(fname), "\\LISTDIR\\%s", finfo->name);
4325 if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
4328 if (finfo->mode & aDIR) {
4329 if (!cli_rmdir(pcli, fname))
4330 printf("del_fn: failed to rmdir %s\n,", fname );
4332 if (!cli_unlink(pcli, fname))
4333 printf("del_fn: failed to unlink %s\n,", fname );
4339 sees what IOCTLs are supported
4341 bool torture_ioctl_test(int dummy)
4343 static struct cli_state *cli;
4344 uint16 device, function;
4346 const char *fname = "\\ioctl.dat";
4350 if (!torture_open_connection(&cli, 0)) {
4354 printf("starting ioctl test\n");
4356 cli_unlink(cli, fname);
4358 fnum = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
4360 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
4364 status = cli_raw_ioctl(cli, fnum, 0x2d0000 | (0x0420<<2), &blob);
4365 printf("ioctl device info: %s\n", cli_errstr(cli));
4367 status = cli_raw_ioctl(cli, fnum, IOCTL_QUERY_JOB_INFO, &blob);
4368 printf("ioctl job info: %s\n", cli_errstr(cli));
4370 for (device=0;device<0x100;device++) {
4371 printf("testing device=0x%x\n", device);
4372 for (function=0;function<0x100;function++) {
4373 uint32 code = (device<<16) | function;
4375 status = cli_raw_ioctl(cli, fnum, code, &blob);
4377 if (NT_STATUS_IS_OK(status)) {
4378 printf("ioctl 0x%x OK : %d bytes\n", (int)code,
4380 data_blob_free(&blob);
4385 if (!torture_close_connection(cli)) {
4394 tries varients of chkpath
4396 bool torture_chkpath_test(int dummy)
4398 static struct cli_state *cli;
4402 if (!torture_open_connection(&cli, 0)) {
4406 printf("starting chkpath test\n");
4408 /* cleanup from an old run */
4409 cli_rmdir(cli, "\\chkpath.dir\\dir2");
4410 cli_unlink(cli, "\\chkpath.dir\\*");
4411 cli_rmdir(cli, "\\chkpath.dir");
4413 if (!cli_mkdir(cli, "\\chkpath.dir")) {
4414 printf("mkdir1 failed : %s\n", cli_errstr(cli));
4418 if (!cli_mkdir(cli, "\\chkpath.dir\\dir2")) {
4419 printf("mkdir2 failed : %s\n", cli_errstr(cli));
4423 fnum = cli_open(cli, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
4425 printf("open1 failed (%s)\n", cli_errstr(cli));
4428 cli_close(cli, fnum);
4430 if (!cli_chkpath(cli, "\\chkpath.dir")) {
4431 printf("chkpath1 failed: %s\n", cli_errstr(cli));
4435 if (!cli_chkpath(cli, "\\chkpath.dir\\dir2")) {
4436 printf("chkpath2 failed: %s\n", cli_errstr(cli));
4440 if (!cli_chkpath(cli, "\\chkpath.dir\\foo.txt")) {
4441 ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath,
4442 NT_STATUS_NOT_A_DIRECTORY);
4444 printf("* chkpath on a file should fail\n");
4448 if (!cli_chkpath(cli, "\\chkpath.dir\\bar.txt")) {
4449 ret = check_error(__LINE__, cli, ERRDOS, ERRbadfile,
4450 NT_STATUS_OBJECT_NAME_NOT_FOUND);
4452 printf("* chkpath on a non existant file should fail\n");
4456 if (!cli_chkpath(cli, "\\chkpath.dir\\dirxx\\bar.txt")) {
4457 ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath,
4458 NT_STATUS_OBJECT_PATH_NOT_FOUND);
4460 printf("* chkpath on a non existent component should fail\n");
4464 cli_rmdir(cli, "\\chkpath.dir\\dir2");
4465 cli_unlink(cli, "\\chkpath.dir\\*");
4466 cli_rmdir(cli, "\\chkpath.dir");
4468 if (!torture_close_connection(cli)) {
4475 static bool run_eatest(int dummy)
4477 static struct cli_state *cli;
4478 const char *fname = "\\eatest.txt";
4479 bool correct = True;
4482 struct ea_struct *ea_list = NULL;
4483 TALLOC_CTX *mem_ctx = talloc_init("eatest");
4485 printf("starting eatest\n");
4487 if (!torture_open_connection(&cli, 0)) {
4488 talloc_destroy(mem_ctx);
4492 cli_unlink(cli, fname);
4493 fnum = cli_nt_create_full(cli, fname, 0,
4494 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
4495 FILE_SHARE_NONE, FILE_OVERWRITE_IF,
4499 printf("open failed - %s\n", cli_errstr(cli));
4500 talloc_destroy(mem_ctx);
4504 for (i = 0; i < 10; i++) {
4505 fstring ea_name, ea_val;
4507 slprintf(ea_name, sizeof(ea_name), "EA_%d", i);
4508 memset(ea_val, (char)i+1, i+1);
4509 if (!cli_set_ea_fnum(cli, fnum, ea_name, ea_val, i+1)) {
4510 printf("ea_set of name %s failed - %s\n", ea_name, cli_errstr(cli));
4511 talloc_destroy(mem_ctx);
4516 cli_close(cli, fnum);
4517 for (i = 0; i < 10; i++) {
4518 fstring ea_name, ea_val;
4520 slprintf(ea_name, sizeof(ea_name), "EA_%d", i+10);
4521 memset(ea_val, (char)i+1, i+1);
4522 if (!cli_set_ea_path(cli, fname, ea_name, ea_val, i+1)) {
4523 printf("ea_set of name %s failed - %s\n", ea_name, cli_errstr(cli));
4524 talloc_destroy(mem_ctx);
4529 if (!cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list)) {
4530 printf("ea_get list failed - %s\n", cli_errstr(cli));
4534 printf("num_eas = %d\n", (int)num_eas);
4536 if (num_eas != 20) {
4537 printf("Should be 20 EA's stored... failing.\n");
4541 for (i = 0; i < num_eas; i++) {
4542 printf("%d: ea_name = %s. Val = ", i, ea_list[i].name);
4543 dump_data(0, ea_list[i].value.data,
4544 ea_list[i].value.length);
4547 /* Setting EA's to zero length deletes them. Test this */
4548 printf("Now deleting all EA's - case indepenent....\n");
4551 cli_set_ea_path(cli, fname, "", "", 0);
4553 for (i = 0; i < 20; i++) {
4555 slprintf(ea_name, sizeof(ea_name), "ea_%d", i);
4556 if (!cli_set_ea_path(cli, fname, ea_name, "", 0)) {
4557 printf("ea_set of name %s failed - %s\n", ea_name, cli_errstr(cli));
4558 talloc_destroy(mem_ctx);
4564 if (!cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list)) {
4565 printf("ea_get list failed - %s\n", cli_errstr(cli));
4569 printf("num_eas = %d\n", (int)num_eas);
4570 for (i = 0; i < num_eas; i++) {
4571 printf("%d: ea_name = %s. Val = ", i, ea_list[i].name);
4572 dump_data(0, ea_list[i].value.data,
4573 ea_list[i].value.length);
4577 printf("deleting EA's failed.\n");
4581 /* Try and delete a non existant EA. */
4582 if (!cli_set_ea_path(cli, fname, "foo", "", 0)) {
4583 printf("deleting non-existant EA 'foo' should succeed. %s\n", cli_errstr(cli));
4587 talloc_destroy(mem_ctx);
4588 if (!torture_close_connection(cli)) {
4595 static bool run_dirtest1(int dummy)
4598 static struct cli_state *cli;
4600 bool correct = True;
4602 printf("starting directory test\n");
4604 if (!torture_open_connection(&cli, 0)) {
4608 cli_sockopt(cli, sockops);
4610 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
4611 cli_list(cli, "\\LISTDIR\\*", aDIR, del_fn, cli);
4612 cli_rmdir(cli, "\\LISTDIR");
4613 cli_mkdir(cli, "\\LISTDIR");
4615 /* Create 1000 files and 1000 directories. */
4616 for (i=0;i<1000;i++) {
4618 slprintf(fname, sizeof(fname), "\\LISTDIR\\f%d", i);
4619 fnum = cli_nt_create_full(cli, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
4620 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0);
4622 fprintf(stderr,"Failed to open %s\n", fname);
4625 cli_close(cli, fnum);
4627 for (i=0;i<1000;i++) {
4629 slprintf(fname, sizeof(fname), "\\LISTDIR\\d%d", i);
4630 if (!cli_mkdir(cli, fname)) {
4631 fprintf(stderr,"Failed to open %s\n", fname);
4636 /* Now ensure that doing an old list sees both files and directories. */
4637 num_seen = cli_list_old(cli, "\\LISTDIR\\*", aDIR, list_fn, NULL);
4638 printf("num_seen = %d\n", num_seen );
4639 /* We should see 100 files + 1000 directories + . and .. */
4640 if (num_seen != 2002)
4643 /* Ensure if we have the "must have" bits we only see the
4646 num_seen = cli_list_old(cli, "\\LISTDIR\\*", (aDIR<<8)|aDIR, list_fn, NULL);
4647 printf("num_seen = %d\n", num_seen );
4648 if (num_seen != 1002)
4651 num_seen = cli_list_old(cli, "\\LISTDIR\\*", (aARCH<<8)|aDIR, list_fn, NULL);
4652 printf("num_seen = %d\n", num_seen );
4653 if (num_seen != 1000)
4656 /* Delete everything. */
4657 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
4658 cli_list(cli, "\\LISTDIR\\*", aDIR, del_fn, cli);
4659 cli_rmdir(cli, "\\LISTDIR");
4662 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
4663 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
4664 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
4667 if (!torture_close_connection(cli)) {
4671 printf("finished dirtest1\n");
4676 static bool run_error_map_extract(int dummy) {
4678 static struct cli_state *c_dos;
4679 static struct cli_state *c_nt;
4683 uint32 flgs2, errnum;
4690 /* NT-Error connection */
4692 if (!(c_nt = open_nbt_connection())) {
4696 c_nt->use_spnego = False;
4698 if (!cli_negprot(c_nt)) {
4699 printf("%s rejected the NT-error negprot (%s)\n",host, cli_errstr(c_nt));
4704 if (!NT_STATUS_IS_OK(cli_session_setup(c_nt, "", "", 0, "", 0,
4706 printf("%s rejected the NT-error initial session setup (%s)\n",host, cli_errstr(c_nt));
4710 /* DOS-Error connection */
4712 if (!(c_dos = open_nbt_connection())) {
4716 c_dos->use_spnego = False;
4717 c_dos->force_dos_errors = True;
4719 if (!cli_negprot(c_dos)) {
4720 printf("%s rejected the DOS-error negprot (%s)\n",host, cli_errstr(c_dos));
4721 cli_shutdown(c_dos);
4725 if (!NT_STATUS_IS_OK(cli_session_setup(c_dos, "", "", 0, "", 0,
4727 printf("%s rejected the DOS-error initial session setup (%s)\n",host, cli_errstr(c_dos));
4731 for (error=(0xc0000000 | 0x1); error < (0xc0000000| 0xFFF); error++) {
4732 fstr_sprintf(user, "%X", error);
4734 if (NT_STATUS_IS_OK(cli_session_setup(c_nt, user,
4735 password, strlen(password),
4736 password, strlen(password),
4738 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
4741 flgs2 = SVAL(c_nt->inbuf,smb_flg2);
4743 /* Case #1: 32-bit NT errors */
4744 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
4745 nt_status = NT_STATUS(IVAL(c_nt->inbuf,smb_rcls));
4747 printf("/** Dos error on NT connection! (%s) */\n",
4749 nt_status = NT_STATUS(0xc0000000);
4752 if (NT_STATUS_IS_OK(cli_session_setup(c_dos, user,
4753 password, strlen(password),
4754 password, strlen(password),
4756 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
4758 flgs2 = SVAL(c_dos->inbuf,smb_flg2), errnum;
4760 /* Case #1: 32-bit NT errors */
4761 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
4762 printf("/** NT error on DOS connection! (%s) */\n",
4764 errnum = errclass = 0;
4766 cli_dos_error(c_dos, &errclass, &errnum);
4769 if (NT_STATUS_V(nt_status) != error) {
4770 printf("/*\t{ This NT error code was 'sqashed'\n\t from %s to %s \n\t during the session setup }\n*/\n",
4771 get_nt_error_c_code(NT_STATUS(error)),
4772 get_nt_error_c_code(nt_status));
4775 printf("\t{%s,\t%s,\t%s},\n",
4776 smb_dos_err_class(errclass),
4777 smb_dos_err_name(errclass, errnum),
4778 get_nt_error_c_code(NT_STATUS(error)));
4783 static bool subst_test(const char *str, const char *user, const char *domain,
4784 uid_t uid, gid_t gid, const char *expected)
4789 subst = talloc_sub_specified(talloc_tos(), str, user, domain, uid, gid);
4791 if (strcmp(subst, expected) != 0) {
4792 printf("sub_specified(%s, %s, %s, %d, %d) returned [%s], expected "
4793 "[%s]\n", str, user, domain, (int)uid, (int)gid, subst,
4802 static bool run_local_substitute(int dummy)
4806 ok &= subst_test("%U", "bla", "", -1, -1, "bla");
4807 ok &= subst_test("%u%U", "bla", "", -1, -1, "blabla");
4808 ok &= subst_test("%g", "", "", -1, -1, "NO_GROUP");
4809 ok &= subst_test("%G", "", "", -1, -1, "NO_GROUP");
4810 ok &= subst_test("%g", "", "", -1, 0, gidtoname(0));
4811 ok &= subst_test("%G", "", "", -1, 0, gidtoname(0));
4812 ok &= subst_test("%D%u", "u", "dom", -1, 0, "domu");
4813 ok &= subst_test("%i %I", "", "", -1, -1, "0.0.0.0 0.0.0.0");
4815 /* Different captialization rules in sub_basic... */
4817 ok &= (strcmp(talloc_sub_basic(talloc_tos(), "BLA", "dom", "%U%D"),
4823 static bool run_local_gencache(int dummy)
4829 if (!gencache_init()) {
4830 d_printf("%s: gencache_init() failed\n", __location__);
4834 if (!gencache_set("foo", "bar", time(NULL) + 1000)) {
4835 d_printf("%s: gencache_set() failed\n", __location__);
4839 if (!gencache_get("foo", &val, &tm)) {
4840 d_printf("%s: gencache_get() failed\n", __location__);
4844 if (strcmp(val, "bar") != 0) {
4845 d_printf("%s: gencache_get() returned %s, expected %s\n",
4846 __location__, val, "bar");
4853 if (!gencache_del("foo")) {
4854 d_printf("%s: gencache_del() failed\n", __location__);
4857 if (gencache_del("foo")) {
4858 d_printf("%s: second gencache_del() succeeded\n",
4863 if (gencache_get("foo", &val, &tm)) {
4864 d_printf("%s: gencache_get() on deleted entry "
4865 "succeeded\n", __location__);
4869 blob = data_blob_string_const("bar");
4872 if (!gencache_set_data_blob("foo", &blob, tm)) {
4873 d_printf("%s: gencache_set_data_blob() failed\n", __location__);
4877 data_blob_free(&blob);
4879 if (!gencache_get_data_blob("foo", &blob, NULL)) {
4880 d_printf("%s: gencache_get_data_blob() failed\n", __location__);
4884 if (strcmp((const char *)blob.data, "bar") != 0) {
4885 d_printf("%s: gencache_get_data_blob() returned %s, expected %s\n",
4886 __location__, (const char *)blob.data, "bar");
4887 data_blob_free(&blob);
4891 data_blob_free(&blob);
4893 if (!gencache_del("foo")) {
4894 d_printf("%s: gencache_del() failed\n", __location__);
4897 if (gencache_del("foo")) {
4898 d_printf("%s: second gencache_del() succeeded\n",
4903 if (gencache_get_data_blob("foo", &blob, NULL)) {
4904 d_printf("%s: gencache_get_data_blob() on deleted entry "
4905 "succeeded\n", __location__);
4909 if (!gencache_shutdown()) {
4910 d_printf("%s: gencache_shutdown() failed\n", __location__);
4914 if (gencache_shutdown()) {
4915 d_printf("%s: second gencache_shutdown() succeeded\n",
4923 static double create_procs(bool (*fn)(int), bool *result)
4926 volatile pid_t *child_status;
4927 volatile bool *child_status_out;
4933 child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*nprocs);
4934 if (!child_status) {
4935 printf("Failed to setup shared memory\n");
4939 child_status_out = (volatile bool *)shm_setup(sizeof(bool)*nprocs);
4940 if (!child_status_out) {
4941 printf("Failed to setup result status shared memory\n");
4945 for (i = 0; i < nprocs; i++) {
4946 child_status[i] = 0;
4947 child_status_out[i] = True;
4952 for (i=0;i<nprocs;i++) {
4955 pid_t mypid = getpid();
4956 sys_srandom(((int)mypid) ^ ((int)time(NULL)));
4958 slprintf(myname,sizeof(myname),"CLIENT%d", i);
4961 if (torture_open_connection(¤t_cli, i)) break;
4963 printf("pid %d failed to start\n", (int)getpid());
4969 child_status[i] = getpid();
4971 while (child_status[i] && end_timer() < 5) smb_msleep(2);
4973 child_status_out[i] = fn(i);
4980 for (i=0;i<nprocs;i++) {
4981 if (child_status[i]) synccount++;
4983 if (synccount == nprocs) break;
4985 } while (end_timer() < 30);
4987 if (synccount != nprocs) {
4988 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs, synccount);
4993 /* start the client load */
4996 for (i=0;i<nprocs;i++) {
4997 child_status[i] = 0;
5000 printf("%d clients started\n", nprocs);
5002 for (i=0;i<nprocs;i++) {
5003 while (waitpid(0, &status, 0) == -1 && errno == EINTR) /* noop */ ;
5008 for (i=0;i<nprocs;i++) {
5009 if (!child_status_out[i]) {
5016 #define FLAG_MULTIPROC 1
5023 {"FDPASS", run_fdpasstest, 0},
5024 {"LOCK1", run_locktest1, 0},
5025 {"LOCK2", run_locktest2, 0},
5026 {"LOCK3", run_locktest3, 0},
5027 {"LOCK4", run_locktest4, 0},
5028 {"LOCK5", run_locktest5, 0},
5029 {"LOCK6", run_locktest6, 0},
5030 {"LOCK7", run_locktest7, 0},
5031 {"UNLINK", run_unlinktest, 0},
5032 {"BROWSE", run_browsetest, 0},
5033 {"ATTR", run_attrtest, 0},
5034 {"TRANS2", run_trans2test, 0},
5035 {"MAXFID", run_maxfidtest, FLAG_MULTIPROC},
5036 {"TORTURE",run_torture, FLAG_MULTIPROC},
5037 {"RANDOMIPC", run_randomipc, 0},
5038 {"NEGNOWAIT", run_negprot_nowait, 0},
5039 {"NBENCH", run_nbench, 0},
5040 {"OPLOCK1", run_oplock1, 0},
5041 {"OPLOCK2", run_oplock2, 0},
5042 {"OPLOCK3", run_oplock3, 0},
5043 {"DIR", run_dirtest, 0},
5044 {"DIR1", run_dirtest1, 0},
5045 {"DENY1", torture_denytest1, 0},
5046 {"DENY2", torture_denytest2, 0},
5047 {"TCON", run_tcon_test, 0},
5048 {"TCONDEV", run_tcon_devtype_test, 0},
5049 {"RW1", run_readwritetest, 0},
5050 {"RW2", run_readwritemulti, FLAG_MULTIPROC},
5051 {"RW3", run_readwritelarge, 0},
5052 {"OPEN", run_opentest, 0},
5054 {"OPENATTR", run_openattrtest, 0},
5056 {"XCOPY", run_xcopy, 0},
5057 {"RENAME", run_rename, 0},
5058 {"DELETE", run_deletetest, 0},
5059 {"PROPERTIES", run_properties, 0},
5060 {"MANGLE", torture_mangle, 0},
5061 {"W2K", run_w2ktest, 0},
5062 {"TRANS2SCAN", torture_trans2_scan, 0},
5063 {"NTTRANSSCAN", torture_nttrans_scan, 0},
5064 {"UTABLE", torture_utable, 0},
5065 {"CASETABLE", torture_casetable, 0},
5066 {"ERRMAPEXTRACT", run_error_map_extract, 0},
5067 {"PIPE_NUMBER", run_pipe_number, 0},
5068 {"TCON2", run_tcon2_test, 0},
5069 {"IOCTL", torture_ioctl_test, 0},
5070 {"CHKPATH", torture_chkpath_test, 0},
5071 {"FDSESS", run_fdsesstest, 0},
5072 { "EATEST", run_eatest, 0},
5073 { "LOCAL-SUBSTITUTE", run_local_substitute, 0},
5074 { "LOCAL-GENCACHE", run_local_gencache, 0},
5079 /****************************************************************************
5080 run a specified test or "ALL"
5081 ****************************************************************************/
5082 static bool run_test(const char *name)
5089 if (strequal(name,"ALL")) {
5090 for (i=0;torture_ops[i].name;i++) {
5091 run_test(torture_ops[i].name);
5096 for (i=0;torture_ops[i].name;i++) {
5097 fstr_sprintf(randomfname, "\\XX%x",
5098 (unsigned)random());
5100 if (strequal(name, torture_ops[i].name)) {
5102 printf("Running %s\n", name);
5103 if (torture_ops[i].flags & FLAG_MULTIPROC) {
5104 t = create_procs(torture_ops[i].fn, &result);
5107 printf("TEST %s FAILED!\n", name);
5112 if (!torture_ops[i].fn(0)) {
5114 printf("TEST %s FAILED!\n", name);
5118 printf("%s took %g secs\n\n", name, t);
5123 printf("Did not find a test named %s\n", name);
5131 static void usage(void)
5135 printf("WARNING samba4 test suite is much more complete nowadays.\n");
5136 printf("Please use samba4 torture.\n\n");
5138 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
5140 printf("\t-d debuglevel\n");
5141 printf("\t-U user%%pass\n");
5142 printf("\t-k use kerberos\n");
5143 printf("\t-N numprocs\n");
5144 printf("\t-n my_netbios_name\n");
5145 printf("\t-W workgroup\n");
5146 printf("\t-o num_operations\n");
5147 printf("\t-O socket_options\n");
5148 printf("\t-m maximum protocol\n");
5149 printf("\t-L use oplocks\n");
5150 printf("\t-c CLIENT.TXT specify client load file for NBENCH\n");
5151 printf("\t-A showall\n");
5152 printf("\t-p port\n");
5153 printf("\t-s seed\n");
5154 printf("\t-b unclist_filename specify multiple shares for multiple connections\n");
5157 printf("tests are:");
5158 for (i=0;torture_ops[i].name;i++) {
5159 printf(" %s", torture_ops[i].name);
5163 printf("default test is ALL\n");
5168 /****************************************************************************
5170 ****************************************************************************/
5171 int main(int argc,char *argv[])
5177 bool correct = True;
5181 #ifdef HAVE_SETBUFFER
5182 setbuffer(stdout, NULL, 0);
5187 lp_load(dyn_CONFIGFILE,True,False,False,True);
5194 for(p = argv[1]; *p; p++)
5198 if (strncmp(argv[1], "//", 2)) {
5202 fstrcpy(host, &argv[1][2]);
5203 p = strchr_m(&host[2],'/');
5208 fstrcpy(share, p+1);
5212 if (*username == 0 && getenv("LOGNAME")) {
5213 fstrcpy(username,getenv("LOGNAME"));
5219 srandom(time(NULL));
5221 fstrcpy(workgroup, lp_workgroup());
5223 while ((opt = getopt(argc, argv, "p:hW:U:n:N:O:o:m:Ld:Ac:ks:b:")) != EOF) {
5226 port_to_use = atoi(optarg);
5229 srandom(atoi(optarg));
5232 fstrcpy(workgroup,optarg);
5235 max_protocol = interpret_protocol(optarg, max_protocol);
5238 nprocs = atoi(optarg);
5241 torture_numops = atoi(optarg);
5244 DEBUGLEVEL = atoi(optarg);
5253 torture_showall = True;
5256 fstrcpy(myname, optarg);
5259 client_txt = optarg;
5263 use_kerberos = True;
5265 d_printf("No kerberos support compiled in\n");
5271 fstrcpy(username,optarg);
5272 p = strchr_m(username,'%');
5275 fstrcpy(password, p+1);
5280 fstrcpy(multishare_conn_fname, optarg);
5281 use_multishare_conn = True;
5284 printf("Unknown option %c (%d)\n", (char)opt, opt);
5289 if(use_kerberos && !gotuser) gotpass = True;
5292 p = getpass("Password:");
5294 fstrcpy(password, p);
5299 printf("host=%s share=%s user=%s myname=%s\n",
5300 host, share, username, myname);
5302 if (argc == optind) {
5303 correct = run_test("ALL");
5305 for (i=optind;i<argc;i++) {
5306 if (!run_test(argv[i])) {