2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1997-1998
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 static fstring host, workgroup, share, password, username, myname;
27 static int max_protocol = PROTOCOL_NT1;
28 static const char *sockops="TCP_NODELAY";
30 static int port_to_use=0;
31 int torture_numops=100;
32 static int procnum; /* records process count number when forking */
33 static struct cli_state *current_cli;
34 static fstring randomfname;
35 static BOOL use_oplocks;
36 static BOOL use_level_II_oplocks;
37 static const char *client_txt = "client_oplocks.txt";
38 static BOOL use_kerberos;
39 static fstring multishare_conn_fname;
40 static BOOL use_multishare_conn = False;
42 BOOL torture_showall = False;
44 static double create_procs(BOOL (*fn)(int), BOOL *result);
47 static struct timeval tp1,tp2;
50 void start_timer(void)
55 double end_timer(void)
58 return((tp2.tv_sec - tp1.tv_sec) +
59 (tp2.tv_usec - tp1.tv_usec)*1.0e-6);
63 /* return a pointer to a anonymous shared memory segment of size "size"
64 which will persist across fork() but will disappear when all processes
67 The memory is not zeroed
69 This function uses system5 shared memory. It takes advantage of a property
70 that the memory is not destroyed if it is attached when the id is removed
72 void *shm_setup(int size)
77 shmid = shmget(IPC_PRIVATE, size, S_IRUSR | S_IWUSR);
79 printf("can't get shared memory\n");
82 ret = (void *)shmat(shmid, 0, 0);
83 if (!ret || ret == (void *)-1) {
84 printf("can't attach to shared memory\n");
87 /* the following releases the ipc, but note that this process
88 and all its children will still have access to the memory, its
89 just that the shmid is no longer valid for other shm calls. This
90 means we don't leave behind lots of shm segments after we exit
92 See Stevens "advanced programming in unix env" for details
94 shmctl(shmid, IPC_RMID, 0);
100 static struct cli_state *open_nbt_connection(void)
102 struct nmb_name called, calling;
106 make_nmb_name(&calling, myname, 0x0);
107 make_nmb_name(&called , host, 0x20);
111 if (!(c = cli_initialise())) {
112 printf("Failed initialize cli_struct to connect with %s\n", host);
116 c->port = port_to_use;
118 if (!cli_connect(c, host, &ip)) {
119 printf("Failed to connect with %s\n", host);
123 c->use_kerberos = use_kerberos;
125 c->timeout = 120000; /* set a really long timeout (2 minutes) */
126 if (use_oplocks) c->use_oplocks = True;
127 if (use_level_II_oplocks) c->use_level_II_oplocks = True;
129 if (!cli_session_request(c, &calling, &called)) {
131 * Well, that failed, try *SMBSERVER ...
132 * However, we must reconnect as well ...
134 if (!cli_connect(c, host, &ip)) {
135 printf("Failed to connect with %s\n", host);
139 make_nmb_name(&called, "*SMBSERVER", 0x20);
140 if (!cli_session_request(c, &calling, &called)) {
141 printf("%s rejected the session\n",host);
142 printf("We tried with a called name of %s & %s\n",
152 /* Insert a NULL at the first separator of the given path and return a pointer
153 * to the remainder of the string.
156 terminate_path_at_separator(char * path)
164 if ((p = strchr_m(path, '/'))) {
169 if ((p = strchr_m(path, '\\'))) {
179 parse a //server/share type UNC name
181 BOOL smbcli_parse_unc(const char *unc_name, TALLOC_CTX *mem_ctx,
182 char **hostname, char **sharename)
186 *hostname = *sharename = NULL;
188 if (strncmp(unc_name, "\\\\", 2) &&
189 strncmp(unc_name, "//", 2)) {
193 *hostname = talloc_strdup(mem_ctx, &unc_name[2]);
194 p = terminate_path_at_separator(*hostname);
197 *sharename = talloc_strdup(mem_ctx, p);
198 terminate_path_at_separator(*sharename);
201 if (*hostname && *sharename) {
205 TALLOC_FREE(*hostname);
206 TALLOC_FREE(*sharename);
210 static BOOL torture_open_connection_share(struct cli_state **c,
211 const char *hostname,
212 const char *sharename)
219 flags |= CLI_FULL_CONNECTION_USE_KERBEROS;
221 status = cli_full_connection(c, myname,
222 hostname, NULL, port_to_use,
225 password, flags, Undefined, &retry);
226 if (!NT_STATUS_IS_OK(status)) {
230 if (use_oplocks) (*c)->use_oplocks = True;
231 if (use_level_II_oplocks) (*c)->use_level_II_oplocks = True;
232 (*c)->timeout = 120000; /* set a really long timeout (2 minutes) */
237 void torture_open_connection_free_unclist(char **unc_list)
241 SAFE_FREE(unc_list[0]);
246 BOOL torture_open_connection(struct cli_state **c, int conn_index)
248 char **unc_list = NULL;
249 int num_unc_names = 0;
252 if (use_multishare_conn==True) {
254 unc_list = file_lines_load(multishare_conn_fname, &num_unc_names, 0);
255 if (!unc_list || num_unc_names <= 0) {
256 printf("Failed to load unc names list from '%s'\n", multishare_conn_fname);
260 if (!smbcli_parse_unc(unc_list[conn_index % num_unc_names],
262 printf("Failed to parse UNC name %s\n",
263 unc_list[conn_index % num_unc_names]);
264 torture_open_connection_free_unclist(unc_list);
268 result = torture_open_connection_share(c, h, s);
270 /* h, s were copied earlier */
271 torture_open_connection_free_unclist(unc_list);
275 return torture_open_connection_share(c, host, share);
278 BOOL torture_cli_session_setup2(struct cli_state *cli, uint16 *new_vuid)
280 uint16 old_vuid = cli->vuid;
281 fstring old_user_name;
282 size_t passlen = strlen(password);
285 fstrcpy(old_user_name, cli->user_name);
287 ret = cli_session_setup(cli, username, password, passlen, password, passlen, workgroup);
288 *new_vuid = cli->vuid;
289 cli->vuid = old_vuid;
290 fstrcpy(cli->user_name, old_user_name);
295 BOOL torture_close_connection(struct cli_state *c)
299 printf("tdis failed (%s)\n", cli_errstr(c));
309 /* check if the server produced the expected error code */
310 static BOOL check_error(int line, struct cli_state *c,
311 uint8 eclass, uint32 ecode, NTSTATUS nterr)
313 if (cli_is_dos_error(c)) {
317 /* Check DOS error */
319 cli_dos_error(c, &cclass, &num);
321 if (eclass != cclass || ecode != num) {
322 printf("unexpected error code class=%d code=%d\n",
323 (int)cclass, (int)num);
324 printf(" expected %d/%d %s (line=%d)\n",
325 (int)eclass, (int)ecode, nt_errstr(nterr), line);
334 status = cli_nt_error(c);
336 if (NT_STATUS_V(nterr) != NT_STATUS_V(status)) {
337 printf("unexpected error code %s\n", nt_errstr(status));
338 printf(" expected %s (line=%d)\n", nt_errstr(nterr), line);
347 static BOOL wait_lock(struct cli_state *c, int fnum, uint32 offset, uint32 len)
349 while (!cli_lock(c, fnum, offset, len, -1, WRITE_LOCK)) {
350 if (!check_error(__LINE__, c, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
356 static BOOL rw_torture(struct cli_state *c)
358 const char *lockfname = "\\torture.lck";
362 pid_t pid2, pid = getpid();
367 fnum2 = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
370 fnum2 = cli_open(c, lockfname, O_RDWR, DENY_NONE);
372 printf("open of %s failed (%s)\n", lockfname, cli_errstr(c));
377 for (i=0;i<torture_numops;i++) {
378 unsigned n = (unsigned)sys_random()%10;
380 printf("%d\r", i); fflush(stdout);
382 slprintf(fname, sizeof(fstring) - 1, "\\torture.%u", n);
384 if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) {
388 fnum = cli_open(c, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL);
390 printf("open failed (%s)\n", cli_errstr(c));
395 if (cli_write(c, fnum, 0, (char *)&pid, 0, sizeof(pid)) != sizeof(pid)) {
396 printf("write failed (%s)\n", cli_errstr(c));
401 if (cli_write(c, fnum, 0, (char *)buf,
402 sizeof(pid)+(j*sizeof(buf)),
403 sizeof(buf)) != sizeof(buf)) {
404 printf("write failed (%s)\n", cli_errstr(c));
411 if (cli_read(c, fnum, (char *)&pid2, 0, sizeof(pid)) != sizeof(pid)) {
412 printf("read failed (%s)\n", cli_errstr(c));
417 printf("data corruption!\n");
421 if (!cli_close(c, fnum)) {
422 printf("close failed (%s)\n", cli_errstr(c));
426 if (!cli_unlink(c, fname)) {
427 printf("unlink failed (%s)\n", cli_errstr(c));
431 if (!cli_unlock(c, fnum2, n*sizeof(int), sizeof(int))) {
432 printf("unlock failed (%s)\n", cli_errstr(c));
438 cli_unlink(c, lockfname);
445 static BOOL run_torture(int dummy)
447 struct cli_state *cli;
452 cli_sockopt(cli, sockops);
454 ret = rw_torture(cli);
456 if (!torture_close_connection(cli)) {
463 static BOOL rw_torture3(struct cli_state *c, char *lockfname)
470 unsigned countprev = 0;
475 for (i = 0; i < sizeof(buf); i += sizeof(uint32))
477 SIVAL(buf, i, sys_random());
482 fnum = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
485 printf("first open read/write of %s failed (%s)\n",
486 lockfname, cli_errstr(c));
492 for (i = 0; i < 500 && fnum == -1; i++)
494 fnum = cli_open(c, lockfname, O_RDONLY,
499 printf("second open read-only of %s failed (%s)\n",
500 lockfname, cli_errstr(c));
506 for (count = 0; count < sizeof(buf); count += sent)
508 if (count >= countprev) {
509 printf("%d %8d\r", i, count);
512 countprev += (sizeof(buf) / 20);
517 sent = ((unsigned)sys_random()%(20))+ 1;
518 if (sent > sizeof(buf) - count)
520 sent = sizeof(buf) - count;
523 if (cli_write(c, fnum, 0, buf+count, count, (size_t)sent) != sent) {
524 printf("write failed (%s)\n", cli_errstr(c));
530 sent = cli_read(c, fnum, buf_rd+count, count,
534 printf("read failed offset:%d size:%ld (%s)\n",
535 count, (unsigned long)sizeof(buf)-count,
542 if (memcmp(buf_rd+count, buf+count, sent) != 0)
544 printf("read/write compare failed\n");
545 printf("offset: %d req %ld recvd %ld\n", count, (unsigned long)sizeof(buf)-count, (unsigned long)sent);
554 if (!cli_close(c, fnum)) {
555 printf("close failed (%s)\n", cli_errstr(c));
562 static BOOL rw_torture2(struct cli_state *c1, struct cli_state *c2)
564 const char *lockfname = "\\torture2.lck";
573 if (!cli_unlink(c1, lockfname)) {
574 printf("unlink failed (%s) (normal, this file should not exist)\n", cli_errstr(c1));
577 fnum1 = cli_open(c1, lockfname, O_RDWR | O_CREAT | O_EXCL,
580 printf("first open read/write of %s failed (%s)\n",
581 lockfname, cli_errstr(c1));
584 fnum2 = cli_open(c2, lockfname, O_RDONLY,
587 printf("second open read-only of %s failed (%s)\n",
588 lockfname, cli_errstr(c2));
589 cli_close(c1, fnum1);
593 for (i=0;i<torture_numops;i++)
595 size_t buf_size = ((unsigned)sys_random()%(sizeof(buf)-1))+ 1;
597 printf("%d\r", i); fflush(stdout);
600 generate_random_buffer((unsigned char *)buf, buf_size);
602 if (cli_write(c1, fnum1, 0, buf, 0, buf_size) != buf_size) {
603 printf("write failed (%s)\n", cli_errstr(c1));
608 if ((bytes_read = cli_read(c2, fnum2, buf_rd, 0, buf_size)) != buf_size) {
609 printf("read failed (%s)\n", cli_errstr(c2));
610 printf("read %d, expected %ld\n", (int)bytes_read,
611 (unsigned long)buf_size);
616 if (memcmp(buf_rd, buf, buf_size) != 0)
618 printf("read/write compare failed\n");
624 if (!cli_close(c2, fnum2)) {
625 printf("close failed (%s)\n", cli_errstr(c2));
628 if (!cli_close(c1, fnum1)) {
629 printf("close failed (%s)\n", cli_errstr(c1));
633 if (!cli_unlink(c1, lockfname)) {
634 printf("unlink failed (%s)\n", cli_errstr(c1));
641 static BOOL run_readwritetest(int dummy)
643 static struct cli_state *cli1, *cli2;
644 BOOL test1, test2 = False;
646 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
649 cli_sockopt(cli1, sockops);
650 cli_sockopt(cli2, sockops);
652 printf("starting readwritetest\n");
654 test1 = rw_torture2(cli1, cli2);
655 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1));
658 test2 = rw_torture2(cli1, cli1);
659 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2));
662 if (!torture_close_connection(cli1)) {
666 if (!torture_close_connection(cli2)) {
670 return (test1 && test2);
673 static BOOL run_readwritemulti(int dummy)
675 struct cli_state *cli;
680 cli_sockopt(cli, sockops);
682 printf("run_readwritemulti: fname %s\n", randomfname);
683 test = rw_torture3(cli, randomfname);
685 if (!torture_close_connection(cli)) {
692 static BOOL run_readwritelarge(int dummy)
694 static struct cli_state *cli1;
696 const char *lockfname = "\\large.dat";
701 if (!torture_open_connection(&cli1, 0)) {
704 cli_sockopt(cli1, sockops);
705 memset(buf,'\0',sizeof(buf));
707 cli1->max_xmit = 128*1024;
709 printf("starting readwritelarge\n");
711 cli_unlink(cli1, lockfname);
713 fnum1 = cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE);
715 printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(cli1));
719 cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf));
721 if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
722 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
726 if (fsize == sizeof(buf))
727 printf("readwritelarge test 1 succeeded (size = %lx)\n",
728 (unsigned long)fsize);
730 printf("readwritelarge test 1 failed (size = %lx)\n",
731 (unsigned long)fsize);
735 if (!cli_close(cli1, fnum1)) {
736 printf("close failed (%s)\n", cli_errstr(cli1));
740 if (!cli_unlink(cli1, lockfname)) {
741 printf("unlink failed (%s)\n", cli_errstr(cli1));
745 fnum1 = cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE);
747 printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(cli1));
751 cli1->max_xmit = 4*1024;
753 cli_smbwrite(cli1, fnum1, buf, 0, sizeof(buf));
755 if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
756 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
760 if (fsize == sizeof(buf))
761 printf("readwritelarge test 2 succeeded (size = %lx)\n",
762 (unsigned long)fsize);
764 printf("readwritelarge test 2 failed (size = %lx)\n",
765 (unsigned long)fsize);
770 /* ToDo - set allocation. JRA */
771 if(!cli_set_allocation_size(cli1, fnum1, 0)) {
772 printf("set allocation size to zero failed (%s)\n", cli_errstr(&cli1));
775 if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
776 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
780 printf("readwritelarge test 3 (truncate test) succeeded (size = %x)\n", fsize);
783 if (!cli_close(cli1, fnum1)) {
784 printf("close failed (%s)\n", cli_errstr(cli1));
788 if (!torture_close_connection(cli1)) {
797 #define ival(s) strtol(s, NULL, 0)
799 /* run a test that simulates an approximate netbench client load */
800 static BOOL run_netbench(int client)
802 struct cli_state *cli;
807 const char *params[20];
814 cli_sockopt(cli, sockops);
818 slprintf(cname,sizeof(cname)-1, "client%d", client);
820 f = fopen(client_txt, "r");
827 while (fgets(line, sizeof(line)-1, f)) {
830 line[strlen(line)-1] = 0;
832 /* printf("[%d] %s\n", line_count, line); */
834 all_string_sub(line,"client1", cname, sizeof(line));
836 /* parse the command parameters */
837 params[0] = strtok(line," ");
839 while (params[i]) params[++i] = strtok(NULL," ");
845 if (!strncmp(params[0],"SMB", 3)) {
846 printf("ERROR: You are using a dbench 1 load file\n");
850 if (!strcmp(params[0],"NTCreateX")) {
851 nb_createx(params[1], ival(params[2]), ival(params[3]),
853 } else if (!strcmp(params[0],"Close")) {
854 nb_close(ival(params[1]));
855 } else if (!strcmp(params[0],"Rename")) {
856 nb_rename(params[1], params[2]);
857 } else if (!strcmp(params[0],"Unlink")) {
858 nb_unlink(params[1]);
859 } else if (!strcmp(params[0],"Deltree")) {
860 nb_deltree(params[1]);
861 } else if (!strcmp(params[0],"Rmdir")) {
863 } else if (!strcmp(params[0],"QUERY_PATH_INFORMATION")) {
864 nb_qpathinfo(params[1]);
865 } else if (!strcmp(params[0],"QUERY_FILE_INFORMATION")) {
866 nb_qfileinfo(ival(params[1]));
867 } else if (!strcmp(params[0],"QUERY_FS_INFORMATION")) {
868 nb_qfsinfo(ival(params[1]));
869 } else if (!strcmp(params[0],"FIND_FIRST")) {
870 nb_findfirst(params[1]);
871 } else if (!strcmp(params[0],"WriteX")) {
872 nb_writex(ival(params[1]),
873 ival(params[2]), ival(params[3]), ival(params[4]));
874 } else if (!strcmp(params[0],"ReadX")) {
875 nb_readx(ival(params[1]),
876 ival(params[2]), ival(params[3]), ival(params[4]));
877 } else if (!strcmp(params[0],"Flush")) {
878 nb_flush(ival(params[1]));
880 printf("Unknown operation %s\n", params[0]);
888 if (!torture_close_connection(cli)) {
896 /* run a test that simulates an approximate netbench client load */
897 static BOOL run_nbench(int dummy)
906 signal(SIGALRM, nb_alarm);
908 t = create_procs(run_netbench, &correct);
911 printf("\nThroughput %g MB/sec\n",
912 1.0e-6 * nbio_total() / t);
918 This test checks for two things:
920 1) correct support for retaining locks over a close (ie. the server
921 must not use posix semantics)
922 2) support for lock timeouts
924 static BOOL run_locktest1(int dummy)
926 struct cli_state *cli1, *cli2;
927 const char *fname = "\\lockt1.lck";
928 int fnum1, fnum2, fnum3;
930 unsigned lock_timeout;
932 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
935 cli_sockopt(cli1, sockops);
936 cli_sockopt(cli2, sockops);
938 printf("starting locktest1\n");
940 cli_unlink(cli1, fname);
942 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
944 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
947 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
949 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli1));
952 fnum3 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
954 printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli2));
958 if (!cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
959 printf("lock1 failed (%s)\n", cli_errstr(cli1));
964 if (cli_lock(cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
965 printf("lock2 succeeded! This is a locking bug\n");
968 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
969 NT_STATUS_LOCK_NOT_GRANTED)) return False;
973 lock_timeout = (1 + (random() % 20));
974 printf("Testing lock timeout with timeout=%u\n", lock_timeout);
976 if (cli_lock(cli2, fnum3, 0, 4, lock_timeout * 1000, WRITE_LOCK)) {
977 printf("lock3 succeeded! This is a locking bug\n");
980 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
981 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
985 if (ABS(t2 - t1) < lock_timeout-1) {
986 printf("error: This server appears not to support timed lock requests\n");
989 printf("server slept for %u seconds for a %u second timeout\n",
990 (unsigned int)(t2-t1), lock_timeout);
992 if (!cli_close(cli1, fnum2)) {
993 printf("close1 failed (%s)\n", cli_errstr(cli1));
997 if (cli_lock(cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
998 printf("lock4 succeeded! This is a locking bug\n");
1001 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
1002 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
1005 if (!cli_close(cli1, fnum1)) {
1006 printf("close2 failed (%s)\n", cli_errstr(cli1));
1010 if (!cli_close(cli2, fnum3)) {
1011 printf("close3 failed (%s)\n", cli_errstr(cli2));
1015 if (!cli_unlink(cli1, fname)) {
1016 printf("unlink failed (%s)\n", cli_errstr(cli1));
1021 if (!torture_close_connection(cli1)) {
1025 if (!torture_close_connection(cli2)) {
1029 printf("Passed locktest1\n");
1034 this checks to see if a secondary tconx can use open files from an
1037 static BOOL run_tcon_test(int dummy)
1039 static struct cli_state *cli;
1040 const char *fname = "\\tcontest.tmp";
1042 uint16 cnum1, cnum2, cnum3;
1043 uint16 vuid1, vuid2;
1047 if (!torture_open_connection(&cli, 0)) {
1050 cli_sockopt(cli, sockops);
1052 printf("starting tcontest\n");
1054 cli_unlink(cli, fname);
1056 fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1058 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
1065 if (cli_write(cli, fnum1, 0, buf, 130, 4) != 4) {
1066 printf("initial write failed (%s)", cli_errstr(cli));
1070 if (!cli_send_tconX(cli, share, "?????",
1071 password, strlen(password)+1)) {
1072 printf("%s refused 2nd tree connect (%s)\n", host,
1079 cnum3 = MAX(cnum1, cnum2) + 1; /* any invalid number */
1080 vuid2 = cli->vuid + 1;
1082 /* try a write with the wrong tid */
1085 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
1086 printf("* server allows write with wrong TID\n");
1089 printf("server fails write with wrong TID : %s\n", cli_errstr(cli));
1093 /* try a write with an invalid tid */
1096 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
1097 printf("* server allows write with invalid TID\n");
1100 printf("server fails write with invalid TID : %s\n", cli_errstr(cli));
1103 /* try a write with an invalid vuid */
1107 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
1108 printf("* server allows write with invalid VUID\n");
1111 printf("server fails write with invalid VUID : %s\n", cli_errstr(cli));
1117 if (!cli_close(cli, fnum1)) {
1118 printf("close failed (%s)\n", cli_errstr(cli));
1124 if (!cli_tdis(cli)) {
1125 printf("secondary tdis failed (%s)\n", cli_errstr(cli));
1131 if (!torture_close_connection(cli)) {
1140 checks for old style tcon support
1142 static BOOL run_tcon2_test(int dummy)
1144 static struct cli_state *cli;
1145 uint16 cnum, max_xmit;
1149 if (!torture_open_connection(&cli, 0)) {
1152 cli_sockopt(cli, sockops);
1154 printf("starting tcon2 test\n");
1156 asprintf(&service, "\\\\%s\\%s", host, share);
1158 status = cli_raw_tcon(cli, service, password, "?????", &max_xmit, &cnum);
1160 if (!NT_STATUS_IS_OK(status)) {
1161 printf("tcon2 failed : %s\n", cli_errstr(cli));
1163 printf("tcon OK : max_xmit=%d cnum=%d tid=%d\n",
1164 (int)max_xmit, (int)cnum, SVAL(cli->inbuf, smb_tid));
1167 if (!torture_close_connection(cli)) {
1171 printf("Passed tcon2 test\n");
1175 static BOOL tcon_devtest(struct cli_state *cli,
1176 const char *myshare, const char *devtype,
1177 const char *return_devtype,
1178 NTSTATUS expected_error)
1183 status = cli_send_tconX(cli, myshare, devtype,
1184 password, strlen(password)+1);
1186 if (NT_STATUS_IS_OK(expected_error)) {
1188 if (strcmp(cli->dev, return_devtype) == 0) {
1191 printf("tconX to share %s with type %s "
1192 "succeeded but returned the wrong "
1193 "device type (got [%s] but should have got [%s])\n",
1194 myshare, devtype, cli->dev, return_devtype);
1198 printf("tconX to share %s with type %s "
1199 "should have succeeded but failed\n",
1206 printf("tconx to share %s with type %s "
1207 "should have failed but succeeded\n",
1211 if (NT_STATUS_EQUAL(cli_nt_error(cli),
1215 printf("Returned unexpected error\n");
1224 checks for correct tconX support
1226 static BOOL run_tcon_devtype_test(int dummy)
1228 static struct cli_state *cli1 = NULL;
1234 status = cli_full_connection(&cli1, myname,
1235 host, NULL, port_to_use,
1237 username, workgroup,
1238 password, flags, Undefined, &retry);
1240 if (!NT_STATUS_IS_OK(status)) {
1241 printf("could not open connection\n");
1245 if (!tcon_devtest(cli1, "IPC$", "A:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1248 if (!tcon_devtest(cli1, "IPC$", "?????", "IPC", NT_STATUS_OK))
1251 if (!tcon_devtest(cli1, "IPC$", "LPT:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1254 if (!tcon_devtest(cli1, "IPC$", "IPC", "IPC", NT_STATUS_OK))
1257 if (!tcon_devtest(cli1, "IPC$", "FOOBA", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1260 if (!tcon_devtest(cli1, share, "A:", "A:", NT_STATUS_OK))
1263 if (!tcon_devtest(cli1, share, "?????", "A:", NT_STATUS_OK))
1266 if (!tcon_devtest(cli1, share, "LPT:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1269 if (!tcon_devtest(cli1, share, "IPC", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1272 if (!tcon_devtest(cli1, share, "FOOBA", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1278 printf("Passed tcondevtest\n");
1285 This test checks that
1287 1) the server supports multiple locking contexts on the one SMB
1288 connection, distinguished by PID.
1290 2) the server correctly fails overlapping locks made by the same PID (this
1291 goes against POSIX behaviour, which is why it is tricky to implement)
1293 3) the server denies unlock requests by an incorrect client PID
1295 static BOOL run_locktest2(int dummy)
1297 static struct cli_state *cli;
1298 const char *fname = "\\lockt2.lck";
1299 int fnum1, fnum2, fnum3;
1300 BOOL correct = True;
1302 if (!torture_open_connection(&cli, 0)) {
1306 cli_sockopt(cli, sockops);
1308 printf("starting locktest2\n");
1310 cli_unlink(cli, fname);
1314 fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1316 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
1320 fnum2 = cli_open(cli, fname, O_RDWR, DENY_NONE);
1322 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli));
1328 fnum3 = cli_open(cli, fname, O_RDWR, DENY_NONE);
1330 printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli));
1336 if (!cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
1337 printf("lock1 failed (%s)\n", cli_errstr(cli));
1341 if (cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
1342 printf("WRITE lock1 succeeded! This is a locking bug\n");
1345 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1346 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1349 if (cli_lock(cli, fnum2, 0, 4, 0, WRITE_LOCK)) {
1350 printf("WRITE lock2 succeeded! This is a locking bug\n");
1353 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1354 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1357 if (cli_lock(cli, fnum2, 0, 4, 0, READ_LOCK)) {
1358 printf("READ lock2 succeeded! This is a locking bug\n");
1361 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1362 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
1365 if (!cli_lock(cli, fnum1, 100, 4, 0, WRITE_LOCK)) {
1366 printf("lock at 100 failed (%s)\n", cli_errstr(cli));
1369 if (cli_unlock(cli, fnum1, 100, 4)) {
1370 printf("unlock at 100 succeeded! This is a locking bug\n");
1374 if (cli_unlock(cli, fnum1, 0, 4)) {
1375 printf("unlock1 succeeded! This is a locking bug\n");
1378 if (!check_error(__LINE__, cli,
1380 NT_STATUS_RANGE_NOT_LOCKED)) return False;
1383 if (cli_unlock(cli, fnum1, 0, 8)) {
1384 printf("unlock2 succeeded! This is a locking bug\n");
1387 if (!check_error(__LINE__, cli,
1389 NT_STATUS_RANGE_NOT_LOCKED)) return False;
1392 if (cli_lock(cli, fnum3, 0, 4, 0, WRITE_LOCK)) {
1393 printf("lock3 succeeded! This is a locking bug\n");
1396 if (!check_error(__LINE__, cli, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
1401 if (!cli_close(cli, fnum1)) {
1402 printf("close1 failed (%s)\n", cli_errstr(cli));
1406 if (!cli_close(cli, fnum2)) {
1407 printf("close2 failed (%s)\n", cli_errstr(cli));
1411 if (!cli_close(cli, fnum3)) {
1412 printf("close3 failed (%s)\n", cli_errstr(cli));
1416 if (!torture_close_connection(cli)) {
1420 printf("locktest2 finished\n");
1427 This test checks that
1429 1) the server supports the full offset range in lock requests
1431 static BOOL run_locktest3(int dummy)
1433 static struct cli_state *cli1, *cli2;
1434 const char *fname = "\\lockt3.lck";
1435 int fnum1, fnum2, i;
1437 BOOL correct = True;
1439 #define NEXT_OFFSET offset += (~(uint32)0) / torture_numops
1441 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1444 cli_sockopt(cli1, sockops);
1445 cli_sockopt(cli2, sockops);
1447 printf("starting locktest3\n");
1449 cli_unlink(cli1, fname);
1451 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1453 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
1456 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1458 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli2));
1462 for (offset=i=0;i<torture_numops;i++) {
1464 if (!cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1465 printf("lock1 %d failed (%s)\n",
1471 if (!cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1472 printf("lock2 %d failed (%s)\n",
1479 for (offset=i=0;i<torture_numops;i++) {
1482 if (cli_lock(cli1, fnum1, offset-2, 1, 0, WRITE_LOCK)) {
1483 printf("error: lock1 %d succeeded!\n", i);
1487 if (cli_lock(cli2, fnum2, offset-1, 1, 0, WRITE_LOCK)) {
1488 printf("error: lock2 %d succeeded!\n", i);
1492 if (cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1493 printf("error: lock3 %d succeeded!\n", i);
1497 if (cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1498 printf("error: lock4 %d succeeded!\n", i);
1503 for (offset=i=0;i<torture_numops;i++) {
1506 if (!cli_unlock(cli1, fnum1, offset-1, 1)) {
1507 printf("unlock1 %d failed (%s)\n",
1513 if (!cli_unlock(cli2, fnum2, offset-2, 1)) {
1514 printf("unlock2 %d failed (%s)\n",
1521 if (!cli_close(cli1, fnum1)) {
1522 printf("close1 failed (%s)\n", cli_errstr(cli1));
1526 if (!cli_close(cli2, fnum2)) {
1527 printf("close2 failed (%s)\n", cli_errstr(cli2));
1531 if (!cli_unlink(cli1, fname)) {
1532 printf("unlink failed (%s)\n", cli_errstr(cli1));
1536 if (!torture_close_connection(cli1)) {
1540 if (!torture_close_connection(cli2)) {
1544 printf("finished locktest3\n");
1549 #define EXPECTED(ret, v) if ((ret) != (v)) { \
1550 printf("** "); correct = False; \
1554 looks at overlapping locks
1556 static BOOL run_locktest4(int dummy)
1558 static struct cli_state *cli1, *cli2;
1559 const char *fname = "\\lockt4.lck";
1560 int fnum1, fnum2, f;
1563 BOOL correct = True;
1565 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1569 cli_sockopt(cli1, sockops);
1570 cli_sockopt(cli2, sockops);
1572 printf("starting locktest4\n");
1574 cli_unlink(cli1, fname);
1576 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1577 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1579 memset(buf, 0, sizeof(buf));
1581 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1582 printf("Failed to create file\n");
1587 ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1588 cli_lock(cli1, fnum1, 2, 4, 0, WRITE_LOCK);
1589 EXPECTED(ret, False);
1590 printf("the same process %s set overlapping write locks\n", ret?"can":"cannot");
1592 ret = cli_lock(cli1, fnum1, 10, 4, 0, READ_LOCK) &&
1593 cli_lock(cli1, fnum1, 12, 4, 0, READ_LOCK);
1594 EXPECTED(ret, True);
1595 printf("the same process %s set overlapping read locks\n", ret?"can":"cannot");
1597 ret = cli_lock(cli1, fnum1, 20, 4, 0, WRITE_LOCK) &&
1598 cli_lock(cli2, fnum2, 22, 4, 0, WRITE_LOCK);
1599 EXPECTED(ret, False);
1600 printf("a different connection %s set overlapping write locks\n", ret?"can":"cannot");
1602 ret = cli_lock(cli1, fnum1, 30, 4, 0, READ_LOCK) &&
1603 cli_lock(cli2, fnum2, 32, 4, 0, READ_LOCK);
1604 EXPECTED(ret, True);
1605 printf("a different connection %s set overlapping read locks\n", ret?"can":"cannot");
1607 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 40, 4, 0, WRITE_LOCK)) &&
1608 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 42, 4, 0, WRITE_LOCK));
1609 EXPECTED(ret, False);
1610 printf("a different pid %s set overlapping write locks\n", ret?"can":"cannot");
1612 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 50, 4, 0, READ_LOCK)) &&
1613 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 52, 4, 0, READ_LOCK));
1614 EXPECTED(ret, True);
1615 printf("a different pid %s set overlapping read locks\n", ret?"can":"cannot");
1617 ret = cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK) &&
1618 cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK);
1619 EXPECTED(ret, True);
1620 printf("the same process %s set the same read lock twice\n", ret?"can":"cannot");
1622 ret = cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK) &&
1623 cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK);
1624 EXPECTED(ret, False);
1625 printf("the same process %s set the same write lock twice\n", ret?"can":"cannot");
1627 ret = cli_lock(cli1, fnum1, 80, 4, 0, READ_LOCK) &&
1628 cli_lock(cli1, fnum1, 80, 4, 0, WRITE_LOCK);
1629 EXPECTED(ret, False);
1630 printf("the same process %s overlay a read lock with a write lock\n", ret?"can":"cannot");
1632 ret = cli_lock(cli1, fnum1, 90, 4, 0, WRITE_LOCK) &&
1633 cli_lock(cli1, fnum1, 90, 4, 0, READ_LOCK);
1634 EXPECTED(ret, True);
1635 printf("the same process %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1637 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 100, 4, 0, WRITE_LOCK)) &&
1638 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 100, 4, 0, READ_LOCK));
1639 EXPECTED(ret, False);
1640 printf("a different pid %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1642 ret = cli_lock(cli1, fnum1, 110, 4, 0, READ_LOCK) &&
1643 cli_lock(cli1, fnum1, 112, 4, 0, READ_LOCK) &&
1644 cli_unlock(cli1, fnum1, 110, 6);
1645 EXPECTED(ret, False);
1646 printf("the same process %s coalesce read locks\n", ret?"can":"cannot");
1649 ret = cli_lock(cli1, fnum1, 120, 4, 0, WRITE_LOCK) &&
1650 (cli_read(cli2, fnum2, buf, 120, 4) == 4);
1651 EXPECTED(ret, False);
1652 printf("this server %s strict write locking\n", ret?"doesn't do":"does");
1654 ret = cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK) &&
1655 (cli_write(cli2, fnum2, 0, buf, 130, 4) == 4);
1656 EXPECTED(ret, False);
1657 printf("this server %s strict read locking\n", ret?"doesn't do":"does");
1660 ret = cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1661 cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1662 cli_unlock(cli1, fnum1, 140, 4) &&
1663 cli_unlock(cli1, fnum1, 140, 4);
1664 EXPECTED(ret, True);
1665 printf("this server %s do recursive read locking\n", ret?"does":"doesn't");
1668 ret = cli_lock(cli1, fnum1, 150, 4, 0, WRITE_LOCK) &&
1669 cli_lock(cli1, fnum1, 150, 4, 0, READ_LOCK) &&
1670 cli_unlock(cli1, fnum1, 150, 4) &&
1671 (cli_read(cli2, fnum2, buf, 150, 4) == 4) &&
1672 !(cli_write(cli2, fnum2, 0, buf, 150, 4) == 4) &&
1673 cli_unlock(cli1, fnum1, 150, 4);
1674 EXPECTED(ret, True);
1675 printf("this server %s do recursive lock overlays\n", ret?"does":"doesn't");
1677 ret = cli_lock(cli1, fnum1, 160, 4, 0, READ_LOCK) &&
1678 cli_unlock(cli1, fnum1, 160, 4) &&
1679 (cli_write(cli2, fnum2, 0, buf, 160, 4) == 4) &&
1680 (cli_read(cli2, fnum2, buf, 160, 4) == 4);
1681 EXPECTED(ret, True);
1682 printf("the same process %s remove a read lock using write locking\n", ret?"can":"cannot");
1684 ret = cli_lock(cli1, fnum1, 170, 4, 0, WRITE_LOCK) &&
1685 cli_unlock(cli1, fnum1, 170, 4) &&
1686 (cli_write(cli2, fnum2, 0, buf, 170, 4) == 4) &&
1687 (cli_read(cli2, fnum2, buf, 170, 4) == 4);
1688 EXPECTED(ret, True);
1689 printf("the same process %s remove a write lock using read locking\n", ret?"can":"cannot");
1691 ret = cli_lock(cli1, fnum1, 190, 4, 0, WRITE_LOCK) &&
1692 cli_lock(cli1, fnum1, 190, 4, 0, READ_LOCK) &&
1693 cli_unlock(cli1, fnum1, 190, 4) &&
1694 !(cli_write(cli2, fnum2, 0, buf, 190, 4) == 4) &&
1695 (cli_read(cli2, fnum2, buf, 190, 4) == 4);
1696 EXPECTED(ret, True);
1697 printf("the same process %s remove the first lock first\n", ret?"does":"doesn't");
1699 cli_close(cli1, fnum1);
1700 cli_close(cli2, fnum2);
1701 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1702 f = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1703 ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1704 cli_lock(cli1, f, 0, 1, 0, READ_LOCK) &&
1705 cli_close(cli1, fnum1) &&
1706 ((fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE)) != -1) &&
1707 cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1709 cli_close(cli1, fnum1);
1710 EXPECTED(ret, True);
1711 printf("the server %s have the NT byte range lock bug\n", !ret?"does":"doesn't");
1714 cli_close(cli1, fnum1);
1715 cli_close(cli2, fnum2);
1716 cli_unlink(cli1, fname);
1717 torture_close_connection(cli1);
1718 torture_close_connection(cli2);
1720 printf("finished locktest4\n");
1725 looks at lock upgrade/downgrade.
1727 static BOOL run_locktest5(int dummy)
1729 static struct cli_state *cli1, *cli2;
1730 const char *fname = "\\lockt5.lck";
1731 int fnum1, fnum2, fnum3;
1734 BOOL correct = True;
1736 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1740 cli_sockopt(cli1, sockops);
1741 cli_sockopt(cli2, sockops);
1743 printf("starting locktest5\n");
1745 cli_unlink(cli1, fname);
1747 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1748 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1749 fnum3 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1751 memset(buf, 0, sizeof(buf));
1753 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1754 printf("Failed to create file\n");
1759 /* Check for NT bug... */
1760 ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1761 cli_lock(cli1, fnum3, 0, 1, 0, READ_LOCK);
1762 cli_close(cli1, fnum1);
1763 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1764 ret = cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1765 EXPECTED(ret, True);
1766 printf("this server %s the NT locking bug\n", ret ? "doesn't have" : "has");
1767 cli_close(cli1, fnum1);
1768 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1769 cli_unlock(cli1, fnum3, 0, 1);
1771 ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1772 cli_lock(cli1, fnum1, 1, 1, 0, READ_LOCK);
1773 EXPECTED(ret, True);
1774 printf("the same process %s overlay a write with a read lock\n", ret?"can":"cannot");
1776 ret = cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK);
1777 EXPECTED(ret, False);
1779 printf("a different processs %s get a read lock on the first process lock stack\n", ret?"can":"cannot");
1781 /* Unlock the process 2 lock. */
1782 cli_unlock(cli2, fnum2, 0, 4);
1784 ret = cli_lock(cli1, fnum3, 0, 4, 0, READ_LOCK);
1785 EXPECTED(ret, False);
1787 printf("the same processs on a different fnum %s get a read lock\n", ret?"can":"cannot");
1789 /* Unlock the process 1 fnum3 lock. */
1790 cli_unlock(cli1, fnum3, 0, 4);
1792 /* Stack 2 more locks here. */
1793 ret = cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK) &&
1794 cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK);
1796 EXPECTED(ret, True);
1797 printf("the same process %s stack read locks\n", ret?"can":"cannot");
1799 /* Unlock the first process lock, then check this was the WRITE lock that was
1802 ret = cli_unlock(cli1, fnum1, 0, 4) &&
1803 cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK);
1805 EXPECTED(ret, True);
1806 printf("the first unlock removes the %s lock\n", ret?"WRITE":"READ");
1808 /* Unlock the process 2 lock. */
1809 cli_unlock(cli2, fnum2, 0, 4);
1811 /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */
1813 ret = cli_unlock(cli1, fnum1, 1, 1) &&
1814 cli_unlock(cli1, fnum1, 0, 4) &&
1815 cli_unlock(cli1, fnum1, 0, 4);
1817 EXPECTED(ret, True);
1818 printf("the same process %s unlock the stack of 4 locks\n", ret?"can":"cannot");
1820 /* Ensure the next unlock fails. */
1821 ret = cli_unlock(cli1, fnum1, 0, 4);
1822 EXPECTED(ret, False);
1823 printf("the same process %s count the lock stack\n", !ret?"can":"cannot");
1825 /* Ensure connection 2 can get a write lock. */
1826 ret = cli_lock(cli2, fnum2, 0, 4, 0, WRITE_LOCK);
1827 EXPECTED(ret, True);
1829 printf("a different processs %s get a write lock on the unlocked stack\n", ret?"can":"cannot");
1833 cli_close(cli1, fnum1);
1834 cli_close(cli2, fnum2);
1835 cli_unlink(cli1, fname);
1836 if (!torture_close_connection(cli1)) {
1839 if (!torture_close_connection(cli2)) {
1843 printf("finished locktest5\n");
1849 tries the unusual lockingX locktype bits
1851 static BOOL run_locktest6(int dummy)
1853 static struct cli_state *cli;
1854 const char *fname[1] = { "\\lock6.txt" };
1859 if (!torture_open_connection(&cli, 0)) {
1863 cli_sockopt(cli, sockops);
1865 printf("starting locktest6\n");
1868 printf("Testing %s\n", fname[i]);
1870 cli_unlink(cli, fname[i]);
1872 fnum = cli_open(cli, fname[i], O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1873 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE);
1874 cli_close(cli, fnum);
1875 printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status));
1877 fnum = cli_open(cli, fname[i], O_RDWR, DENY_NONE);
1878 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK);
1879 cli_close(cli, fnum);
1880 printf("CANCEL_LOCK gave %s\n", nt_errstr(status));
1882 cli_unlink(cli, fname[i]);
1885 torture_close_connection(cli);
1887 printf("finished locktest6\n");
1891 static BOOL run_locktest7(int dummy)
1893 struct cli_state *cli1;
1894 const char *fname = "\\lockt7.lck";
1897 BOOL correct = False;
1899 if (!torture_open_connection(&cli1, 0)) {
1903 cli_sockopt(cli1, sockops);
1905 printf("starting locktest7\n");
1907 cli_unlink(cli1, fname);
1909 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1911 memset(buf, 0, sizeof(buf));
1913 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1914 printf("Failed to create file\n");
1918 cli_setpid(cli1, 1);
1920 if (!cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK)) {
1921 printf("Unable to apply read lock on range 130:4, error was %s\n", cli_errstr(cli1));
1924 printf("pid1 successfully locked range 130:4 for READ\n");
1927 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1928 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1931 printf("pid1 successfully read the range 130:4\n");
1934 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1935 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1936 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1937 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1941 printf("pid1 successfully wrote to the range 130:4 (should be denied)\n");
1945 cli_setpid(cli1, 2);
1947 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1948 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1950 printf("pid2 successfully read the range 130:4\n");
1953 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1954 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1955 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1956 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1960 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
1964 cli_setpid(cli1, 1);
1965 cli_unlock(cli1, fnum1, 130, 4);
1967 if (!cli_lock(cli1, fnum1, 130, 4, 0, WRITE_LOCK)) {
1968 printf("Unable to apply write lock on range 130:4, error was %s\n", cli_errstr(cli1));
1971 printf("pid1 successfully locked range 130:4 for WRITE\n");
1974 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1975 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1978 printf("pid1 successfully read the range 130:4\n");
1981 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1982 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1985 printf("pid1 successfully wrote to the range 130:4\n");
1988 cli_setpid(cli1, 2);
1990 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1991 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1992 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1993 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1997 printf("pid2 successfully read the range 130:4 (should be denied)\n");
2001 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
2002 printf("pid2 unable to write to 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 wrote to the range 130:4 (should be denied)\n");
2012 cli_unlock(cli1, fnum1, 130, 0);
2016 cli_close(cli1, fnum1);
2017 cli_unlink(cli1, fname);
2018 torture_close_connection(cli1);
2020 printf("finished locktest7\n");
2025 test whether fnums and tids open on one VC are available on another (a major
2028 static BOOL run_fdpasstest(int dummy)
2030 struct cli_state *cli1, *cli2;
2031 const char *fname = "\\fdpass.tst";
2035 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
2038 cli_sockopt(cli1, sockops);
2039 cli_sockopt(cli2, sockops);
2041 printf("starting fdpasstest\n");
2043 cli_unlink(cli1, fname);
2045 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2047 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2051 if (cli_write(cli1, fnum1, 0, "hello world\n", 0, 13) != 13) {
2052 printf("write failed (%s)\n", cli_errstr(cli1));
2056 cli2->vuid = cli1->vuid;
2057 cli2->cnum = cli1->cnum;
2058 cli2->pid = cli1->pid;
2060 if (cli_read(cli2, fnum1, buf, 0, 13) == 13) {
2061 printf("read succeeded! nasty security hole [%s]\n",
2066 cli_close(cli1, fnum1);
2067 cli_unlink(cli1, fname);
2069 torture_close_connection(cli1);
2070 torture_close_connection(cli2);
2072 printf("finished fdpasstest\n");
2076 static BOOL run_fdsesstest(int dummy)
2078 struct cli_state *cli;
2083 const char *fname = "\\fdsess.tst";
2084 const char *fname1 = "\\fdsess1.tst";
2090 if (!torture_open_connection(&cli, 0))
2092 cli_sockopt(cli, sockops);
2094 if (!torture_cli_session_setup2(cli, &new_vuid))
2097 saved_cnum = cli->cnum;
2098 if (!cli_send_tconX(cli, share, "?????", "", 1))
2100 new_cnum = cli->cnum;
2101 cli->cnum = saved_cnum;
2103 printf("starting fdsesstest\n");
2105 cli_unlink(cli, fname);
2106 cli_unlink(cli, fname1);
2108 fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2110 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
2114 if (cli_write(cli, fnum1, 0, "hello world\n", 0, 13) != 13) {
2115 printf("write failed (%s)\n", cli_errstr(cli));
2119 saved_vuid = cli->vuid;
2120 cli->vuid = new_vuid;
2122 if (cli_read(cli, fnum1, buf, 0, 13) == 13) {
2123 printf("read succeeded with different vuid! nasty security hole [%s]\n",
2127 /* Try to open a file with different vuid, samba cnum. */
2128 fnum2 = cli_open(cli, fname1, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2130 printf("create with different vuid, same cnum succeeded.\n");
2131 cli_close(cli, fnum2);
2132 cli_unlink(cli, fname1);
2134 printf("create with different vuid, same cnum failed.\n");
2135 printf("This will cause problems with service clients.\n");
2139 cli->vuid = saved_vuid;
2141 /* Try with same vuid, different cnum. */
2142 cli->cnum = new_cnum;
2144 if (cli_read(cli, fnum1, buf, 0, 13) == 13) {
2145 printf("read succeeded with different cnum![%s]\n",
2150 cli->cnum = saved_cnum;
2151 cli_close(cli, fnum1);
2152 cli_unlink(cli, fname);
2154 torture_close_connection(cli);
2156 printf("finished fdsesstest\n");
2161 This test checks that
2163 1) the server does not allow an unlink on a file that is open
2165 static BOOL run_unlinktest(int dummy)
2167 struct cli_state *cli;
2168 const char *fname = "\\unlink.tst";
2170 BOOL correct = True;
2172 if (!torture_open_connection(&cli, 0)) {
2176 cli_sockopt(cli, sockops);
2178 printf("starting unlink test\n");
2180 cli_unlink(cli, fname);
2184 fnum = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2186 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
2190 if (cli_unlink(cli, fname)) {
2191 printf("error: server allowed unlink on an open file\n");
2194 correct = check_error(__LINE__, cli, ERRDOS, ERRbadshare,
2195 NT_STATUS_SHARING_VIOLATION);
2198 cli_close(cli, fnum);
2199 cli_unlink(cli, fname);
2201 if (!torture_close_connection(cli)) {
2205 printf("unlink test finished\n");
2212 test how many open files this server supports on the one socket
2214 static BOOL run_maxfidtest(int dummy)
2216 struct cli_state *cli;
2217 const char *ftemplate = "\\maxfid.%d.%d";
2219 int fnums[0x11000], i;
2221 BOOL correct = True;
2226 printf("failed to connect\n");
2230 cli_sockopt(cli, sockops);
2232 for (i=0; i<0x11000; i++) {
2233 slprintf(fname,sizeof(fname)-1,ftemplate, i,(int)getpid());
2234 if ((fnums[i] = cli_open(cli, fname,
2235 O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) ==
2237 printf("open of %s failed (%s)\n",
2238 fname, cli_errstr(cli));
2239 printf("maximum fnum is %d\n", i);
2247 printf("cleaning up\n");
2249 slprintf(fname,sizeof(fname)-1,ftemplate, i,(int)getpid());
2250 cli_close(cli, fnums[i]);
2251 if (!cli_unlink(cli, fname)) {
2252 printf("unlink of %s failed (%s)\n",
2253 fname, cli_errstr(cli));
2260 printf("maxfid test finished\n");
2261 if (!torture_close_connection(cli)) {
2267 /* generate a random buffer */
2268 static void rand_buf(char *buf, int len)
2271 *buf = (char)sys_random();
2276 /* send smb negprot commands, not reading the response */
2277 static BOOL run_negprot_nowait(int dummy)
2280 static struct cli_state *cli;
2281 BOOL correct = True;
2283 printf("starting negprot nowait test\n");
2285 if (!(cli = open_nbt_connection())) {
2289 for (i=0;i<50000;i++) {
2290 cli_negprot_send(cli);
2293 if (!torture_close_connection(cli)) {
2297 printf("finished negprot nowait test\n");
2303 /* send random IPC commands */
2304 static BOOL run_randomipc(int dummy)
2306 char *rparam = NULL;
2308 unsigned int rdrcnt,rprcnt;
2310 int api, param_len, i;
2311 struct cli_state *cli;
2312 BOOL correct = True;
2315 printf("starting random ipc test\n");
2317 if (!torture_open_connection(&cli, 0)) {
2321 for (i=0;i<count;i++) {
2322 api = sys_random() % 500;
2323 param_len = (sys_random() % 64);
2325 rand_buf(param, param_len);
2330 param, param_len, 8,
2331 NULL, 0, BUFFER_SIZE,
2335 printf("%d/%d\r", i,count);
2338 printf("%d/%d\n", i, count);
2340 if (!torture_close_connection(cli)) {
2344 printf("finished random ipc test\n");
2351 static void browse_callback(const char *sname, uint32 stype,
2352 const char *comment, void *state)
2354 printf("\t%20.20s %08x %s\n", sname, stype, comment);
2360 This test checks the browse list code
2363 static BOOL run_browsetest(int dummy)
2365 static struct cli_state *cli;
2366 BOOL correct = True;
2368 printf("starting browse test\n");
2370 if (!torture_open_connection(&cli, 0)) {
2374 printf("domain list:\n");
2375 cli_NetServerEnum(cli, cli->server_domain,
2376 SV_TYPE_DOMAIN_ENUM,
2377 browse_callback, NULL);
2379 printf("machine list:\n");
2380 cli_NetServerEnum(cli, cli->server_domain,
2382 browse_callback, NULL);
2384 if (!torture_close_connection(cli)) {
2388 printf("browse test finished\n");
2396 This checks how the getatr calls works
2398 static BOOL run_attrtest(int dummy)
2400 struct cli_state *cli;
2403 const char *fname = "\\attrib123456789.tst";
2404 BOOL correct = True;
2406 printf("starting attrib test\n");
2408 if (!torture_open_connection(&cli, 0)) {
2412 cli_unlink(cli, fname);
2413 fnum = cli_open(cli, fname,
2414 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2415 cli_close(cli, fnum);
2416 if (!cli_getatr(cli, fname, NULL, NULL, &t)) {
2417 printf("getatr failed (%s)\n", cli_errstr(cli));
2421 if (abs(t - time(NULL)) > 60*60*24*10) {
2422 printf("ERROR: SMBgetatr bug. time is %s",
2428 t2 = t-60*60*24; /* 1 day ago */
2430 if (!cli_setatr(cli, fname, 0, t2)) {
2431 printf("setatr failed (%s)\n", cli_errstr(cli));
2435 if (!cli_getatr(cli, fname, NULL, NULL, &t)) {
2436 printf("getatr failed (%s)\n", cli_errstr(cli));
2441 printf("ERROR: getatr/setatr bug. times are\n%s",
2443 printf("%s", ctime(&t2));
2447 cli_unlink(cli, fname);
2449 if (!torture_close_connection(cli)) {
2453 printf("attrib test finished\n");
2460 This checks a couple of trans2 calls
2462 static BOOL run_trans2test(int dummy)
2464 struct cli_state *cli;
2467 time_t c_time, a_time, m_time, w_time, m_time2;
2468 const char *fname = "\\trans2.tst";
2469 const char *dname = "\\trans2";
2470 const char *fname2 = "\\trans2\\trans2.tst";
2472 BOOL correct = True;
2474 printf("starting trans2 test\n");
2476 if (!torture_open_connection(&cli, 0)) {
2480 cli_unlink(cli, fname);
2481 fnum = cli_open(cli, fname,
2482 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2483 if (!cli_qfileinfo(cli, fnum, NULL, &size, &c_time, &a_time, &m_time,
2485 printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(cli));
2489 if (!cli_qfilename(cli, fnum, pname)) {
2490 printf("ERROR: qfilename failed (%s)\n", cli_errstr(cli));
2494 if (strcmp(pname, fname)) {
2495 printf("qfilename gave different name? [%s] [%s]\n",
2500 cli_close(cli, fnum);
2504 cli_unlink(cli, fname);
2505 fnum = cli_open(cli, fname,
2506 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2508 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
2511 cli_close(cli, fnum);
2513 if (!cli_qpathinfo(cli, fname, &c_time, &a_time, &m_time, &size, NULL)) {
2514 printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(cli));
2517 if (c_time != m_time) {
2518 printf("create time=%s", ctime(&c_time));
2519 printf("modify time=%s", ctime(&m_time));
2520 printf("This system appears to have sticky create times\n");
2522 if (a_time % (60*60) == 0) {
2523 printf("access time=%s", ctime(&a_time));
2524 printf("This system appears to set a midnight access time\n");
2528 if (abs(m_time - time(NULL)) > 60*60*24*7) {
2529 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
2535 cli_unlink(cli, fname);
2536 fnum = cli_open(cli, fname,
2537 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2538 cli_close(cli, fnum);
2539 if (!cli_qpathinfo2(cli, fname, &c_time, &a_time, &m_time,
2540 &w_time, &size, NULL, NULL)) {
2541 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2544 if (w_time < 60*60*24*2) {
2545 printf("write time=%s", ctime(&w_time));
2546 printf("This system appears to set a initial 0 write time\n");
2551 cli_unlink(cli, fname);
2554 /* check if the server updates the directory modification time
2555 when creating a new file */
2556 if (!cli_mkdir(cli, dname)) {
2557 printf("ERROR: mkdir failed (%s)\n", cli_errstr(cli));
2561 if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time, &a_time, &m_time,
2562 &w_time, &size, NULL, NULL)) {
2563 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2567 fnum = cli_open(cli, fname2,
2568 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2569 cli_write(cli, fnum, 0, (char *)&fnum, 0, sizeof(fnum));
2570 cli_close(cli, fnum);
2571 if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time, &a_time, &m_time2,
2572 &w_time, &size, NULL, NULL)) {
2573 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2576 if (m_time2 == m_time) {
2577 printf("This system does not update directory modification times\n");
2581 cli_unlink(cli, fname2);
2582 cli_rmdir(cli, dname);
2584 if (!torture_close_connection(cli)) {
2588 printf("trans2 test finished\n");
2594 This checks new W2K calls.
2597 static BOOL new_trans(struct cli_state *pcli, int fnum, int level)
2601 BOOL correct = True;
2603 if (!cli_qfileinfo_test(pcli, fnum, level, &buf, &len)) {
2604 printf("ERROR: qfileinfo (%d) failed (%s)\n", level, cli_errstr(pcli));
2607 printf("qfileinfo: level %d, len = %u\n", level, len);
2608 dump_data(0, buf, len);
2615 static BOOL run_w2ktest(int dummy)
2617 struct cli_state *cli;
2619 const char *fname = "\\w2ktest\\w2k.tst";
2621 BOOL correct = True;
2623 printf("starting w2k test\n");
2625 if (!torture_open_connection(&cli, 0)) {
2629 fnum = cli_open(cli, fname,
2630 O_RDWR | O_CREAT , DENY_NONE);
2632 for (level = 1004; level < 1040; level++) {
2633 new_trans(cli, fnum, level);
2636 cli_close(cli, fnum);
2638 if (!torture_close_connection(cli)) {
2642 printf("w2k test finished\n");
2649 this is a harness for some oplock tests
2651 static BOOL run_oplock1(int dummy)
2653 struct cli_state *cli1;
2654 const char *fname = "\\lockt1.lck";
2656 BOOL correct = True;
2658 printf("starting oplock test 1\n");
2660 if (!torture_open_connection(&cli1, 0)) {
2664 cli_unlink(cli1, fname);
2666 cli_sockopt(cli1, sockops);
2668 cli1->use_oplocks = True;
2670 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2672 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2676 cli1->use_oplocks = False;
2678 cli_unlink(cli1, fname);
2679 cli_unlink(cli1, fname);
2681 if (!cli_close(cli1, fnum1)) {
2682 printf("close2 failed (%s)\n", cli_errstr(cli1));
2686 if (!cli_unlink(cli1, fname)) {
2687 printf("unlink failed (%s)\n", cli_errstr(cli1));
2691 if (!torture_close_connection(cli1)) {
2695 printf("finished oplock test 1\n");
2700 static BOOL run_oplock2(int dummy)
2702 struct cli_state *cli1, *cli2;
2703 const char *fname = "\\lockt2.lck";
2705 int saved_use_oplocks = use_oplocks;
2707 BOOL correct = True;
2708 volatile BOOL *shared_correct;
2710 shared_correct = (volatile BOOL *)shm_setup(sizeof(BOOL));
2711 *shared_correct = True;
2713 use_level_II_oplocks = True;
2716 printf("starting oplock test 2\n");
2718 if (!torture_open_connection(&cli1, 0)) {
2719 use_level_II_oplocks = False;
2720 use_oplocks = saved_use_oplocks;
2724 cli1->use_oplocks = True;
2725 cli1->use_level_II_oplocks = True;
2727 if (!torture_open_connection(&cli2, 1)) {
2728 use_level_II_oplocks = False;
2729 use_oplocks = saved_use_oplocks;
2733 cli2->use_oplocks = True;
2734 cli2->use_level_II_oplocks = True;
2736 cli_unlink(cli1, fname);
2738 cli_sockopt(cli1, sockops);
2739 cli_sockopt(cli2, sockops);
2741 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2743 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2747 /* Don't need the globals any more. */
2748 use_level_II_oplocks = False;
2749 use_oplocks = saved_use_oplocks;
2753 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
2755 printf("second open of %s failed (%s)\n", fname, cli_errstr(cli1));
2756 *shared_correct = False;
2762 if (!cli_close(cli2, fnum2)) {
2763 printf("close2 failed (%s)\n", cli_errstr(cli1));
2764 *shared_correct = False;
2772 /* Ensure cli1 processes the break. Empty file should always return 0
2775 if (cli_read(cli1, fnum1, buf, 0, 4) != 0) {
2776 printf("read on fnum1 failed (%s)\n", cli_errstr(cli1));
2780 /* Should now be at level II. */
2781 /* Test if sending a write locks causes a break to none. */
2783 if (!cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK)) {
2784 printf("lock failed (%s)\n", cli_errstr(cli1));
2788 cli_unlock(cli1, fnum1, 0, 4);
2792 if (!cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
2793 printf("lock failed (%s)\n", cli_errstr(cli1));
2797 cli_unlock(cli1, fnum1, 0, 4);
2801 cli_read(cli1, fnum1, buf, 0, 4);
2804 if (cli_write(cli1, fnum1, 0, buf, 0, 4) != 4) {
2805 printf("write on fnum1 failed (%s)\n", cli_errstr(cli1));
2810 if (!cli_close(cli1, fnum1)) {
2811 printf("close1 failed (%s)\n", cli_errstr(cli1));
2817 if (!cli_unlink(cli1, fname)) {
2818 printf("unlink failed (%s)\n", cli_errstr(cli1));
2822 if (!torture_close_connection(cli1)) {
2826 if (!*shared_correct) {
2830 printf("finished oplock test 2\n");
2835 /* handler for oplock 3 tests */
2836 static BOOL oplock3_handler(struct cli_state *cli, int fnum, unsigned char level)
2838 printf("got oplock break fnum=%d level=%d\n",
2840 return cli_oplock_ack(cli, fnum, level);
2843 static BOOL run_oplock3(int dummy)
2845 struct cli_state *cli;
2846 const char *fname = "\\oplockt3.dat";
2848 char buf[4] = "abcd";
2849 BOOL correct = True;
2850 volatile BOOL *shared_correct;
2852 shared_correct = (volatile BOOL *)shm_setup(sizeof(BOOL));
2853 *shared_correct = True;
2855 printf("starting oplock test 3\n");
2860 use_level_II_oplocks = True;
2861 if (!torture_open_connection(&cli, 0)) {
2862 *shared_correct = False;
2866 /* try to trigger a oplock break in parent */
2867 fnum = cli_open(cli, fname, O_RDWR, DENY_NONE);
2868 cli_write(cli, fnum, 0, buf, 0, 4);
2874 use_level_II_oplocks = True;
2875 if (!torture_open_connection(&cli, 1)) { /* other is forked */
2878 cli_oplock_handler(cli, oplock3_handler);
2879 fnum = cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE);
2880 cli_write(cli, fnum, 0, buf, 0, 4);
2881 cli_close(cli, fnum);
2882 fnum = cli_open(cli, fname, O_RDWR, DENY_NONE);
2883 cli->timeout = 20000;
2884 cli_receive_smb(cli);
2885 printf("finished oplock test 3\n");
2887 return (correct && *shared_correct);
2889 /* What are we looking for here? What's sucess and what's FAILURE? */
2895 Test delete on close semantics.
2897 static BOOL run_deletetest(int dummy)
2899 struct cli_state *cli1 = NULL;
2900 struct cli_state *cli2 = NULL;
2901 const char *fname = "\\delete.file";
2904 BOOL correct = True;
2906 printf("starting delete test\n");
2908 if (!torture_open_connection(&cli1, 0)) {
2912 cli_sockopt(cli1, sockops);
2914 /* Test 1 - this should delete the file on close. */
2916 cli_setatr(cli1, fname, 0, 0);
2917 cli_unlink(cli1, fname);
2919 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
2920 0, FILE_OVERWRITE_IF,
2921 FILE_DELETE_ON_CLOSE, 0);
2924 printf("[1] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2931 uint32 *accinfo = NULL;
2933 cli_qfileinfo_test(cli1, fnum1, SMB_FILE_ACCESS_INFORMATION, (char **)&accinfo, &len);
2935 printf("access mode = 0x%lx\n", *accinfo);
2940 if (!cli_close(cli1, fnum1)) {
2941 printf("[1] close failed (%s)\n", cli_errstr(cli1));
2946 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
2948 printf("[1] open of %s succeeded (should fail)\n", fname);
2953 printf("first delete on close test succeeded.\n");
2955 /* Test 2 - this should delete the file on close. */
2957 cli_setatr(cli1, fname, 0, 0);
2958 cli_unlink(cli1, fname);
2960 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_ALL_ACCESS,
2961 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
2962 FILE_OVERWRITE_IF, 0, 0);
2965 printf("[2] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2970 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
2971 printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
2976 if (!cli_close(cli1, fnum1)) {
2977 printf("[2] close failed (%s)\n", cli_errstr(cli1));
2982 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
2984 printf("[2] open of %s succeeded should have been deleted on close !\n", fname);
2985 if (!cli_close(cli1, fnum1)) {
2986 printf("[2] close failed (%s)\n", cli_errstr(cli1));
2990 cli_unlink(cli1, fname);
2992 printf("second delete on close test succeeded.\n");
2995 cli_setatr(cli1, fname, 0, 0);
2996 cli_unlink(cli1, fname);
2998 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2999 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0);
3002 printf("[3] open - 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3007 /* This should fail with a sharing violation - open for delete is only compatible
3008 with SHARE_DELETE. */
3010 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3011 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0, 0);
3014 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname);
3019 /* This should succeed. */
3021 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3022 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0, 0);
3025 printf("[3] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
3030 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
3031 printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
3036 if (!cli_close(cli1, fnum1)) {
3037 printf("[3] close 1 failed (%s)\n", cli_errstr(cli1));
3042 if (!cli_close(cli1, fnum2)) {
3043 printf("[3] close 2 failed (%s)\n", cli_errstr(cli1));
3048 /* This should fail - file should no longer be there. */
3050 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
3052 printf("[3] open of %s succeeded should have been deleted on close !\n", fname);
3053 if (!cli_close(cli1, fnum1)) {
3054 printf("[3] close failed (%s)\n", cli_errstr(cli1));
3056 cli_unlink(cli1, fname);
3060 printf("third delete on close test succeeded.\n");
3063 cli_setatr(cli1, fname, 0, 0);
3064 cli_unlink(cli1, fname);
3066 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3067 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0);
3070 printf("[4] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3075 /* This should succeed. */
3076 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS,
3077 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0, 0);
3079 printf("[4] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
3084 if (!cli_close(cli1, fnum2)) {
3085 printf("[4] close - 1 failed (%s)\n", cli_errstr(cli1));
3090 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
3091 printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
3096 /* This should fail - no more opens once delete on close set. */
3097 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS,
3098 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3101 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname );
3105 printf("fourth delete on close test succeeded.\n");
3107 if (!cli_close(cli1, fnum1)) {
3108 printf("[4] close - 2 failed (%s)\n", cli_errstr(cli1));
3114 cli_setatr(cli1, fname, 0, 0);
3115 cli_unlink(cli1, fname);
3117 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT, DENY_NONE);
3119 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3124 /* This should fail - only allowed on NT opens with DELETE access. */
3126 if (cli_nt_delete_on_close(cli1, fnum1, True)) {
3127 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
3132 if (!cli_close(cli1, fnum1)) {
3133 printf("[5] close - 2 failed (%s)\n", cli_errstr(cli1));
3138 printf("fifth delete on close test succeeded.\n");
3141 cli_setatr(cli1, fname, 0, 0);
3142 cli_unlink(cli1, fname);
3144 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
3145 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3146 FILE_OVERWRITE_IF, 0, 0);
3149 printf("[6] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3154 /* This should fail - only allowed on NT opens with DELETE access. */
3156 if (cli_nt_delete_on_close(cli1, fnum1, True)) {
3157 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
3162 if (!cli_close(cli1, fnum1)) {
3163 printf("[6] close - 2 failed (%s)\n", cli_errstr(cli1));
3168 printf("sixth delete on close test succeeded.\n");
3171 cli_setatr(cli1, fname, 0, 0);
3172 cli_unlink(cli1, fname);
3174 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3175 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0, 0);
3178 printf("[7] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3183 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
3184 printf("[7] setting delete_on_close on file failed !\n");
3189 if (!cli_nt_delete_on_close(cli1, fnum1, False)) {
3190 printf("[7] unsetting delete_on_close on file failed !\n");
3195 if (!cli_close(cli1, fnum1)) {
3196 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
3201 /* This next open should succeed - we reset the flag. */
3203 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
3205 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3210 if (!cli_close(cli1, fnum1)) {
3211 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
3216 printf("seventh delete on close test succeeded.\n");
3219 cli_setatr(cli1, fname, 0, 0);
3220 cli_unlink(cli1, fname);
3222 if (!torture_open_connection(&cli2, 1)) {
3223 printf("[8] failed to open second connection.\n");
3228 cli_sockopt(cli1, sockops);
3230 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3231 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3232 FILE_OVERWRITE_IF, 0, 0);
3235 printf("[8] open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3240 fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3241 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3245 printf("[8] open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3250 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
3251 printf("[8] setting delete_on_close on file failed !\n");
3256 if (!cli_close(cli1, fnum1)) {
3257 printf("[8] close - 1 failed (%s)\n", cli_errstr(cli1));
3262 if (!cli_close(cli2, fnum2)) {
3263 printf("[8] close - 2 failed (%s)\n", cli_errstr(cli2));
3268 /* This should fail.. */
3269 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
3271 printf("[8] open of %s succeeded should have been deleted on close !\n", fname);
3275 printf("eighth delete on close test succeeded.\n");
3277 /* This should fail - we need to set DELETE_ACCESS. */
3278 fnum1 = cli_nt_create_full(cli1, fname, 0,FILE_READ_DATA|FILE_WRITE_DATA,
3279 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, 0);
3282 printf("[9] open of %s succeeded should have failed!\n", fname);
3287 printf("ninth delete on close test succeeded.\n");
3289 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3290 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, 0);
3292 printf("[10] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3297 /* This should delete the file. */
3298 if (!cli_close(cli1, fnum1)) {
3299 printf("[10] close failed (%s)\n", cli_errstr(cli1));
3304 /* This should fail.. */
3305 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
3307 printf("[10] open of %s succeeded should have been deleted on close !\n", fname);
3311 printf("tenth delete on close test succeeded.\n");
3313 cli_setatr(cli1, fname, 0, 0);
3314 cli_unlink(cli1, fname);
3316 /* What error do we get when attempting to open a read-only file with
3319 /* Create a readonly file. */
3320 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
3321 FILE_ATTRIBUTE_READONLY, FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3323 printf("[11] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3328 if (!cli_close(cli1, fnum1)) {
3329 printf("[11] close failed (%s)\n", cli_errstr(cli1));
3334 /* Now try open for delete access. */
3335 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_ATTRIBUTES|DELETE_ACCESS,
3336 0, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3337 FILE_OVERWRITE_IF, 0, 0);
3340 printf("[11] open of %s succeeded should have been denied with ACCESS_DENIED!\n", fname);
3341 cli_close(cli1, fnum1);
3345 NTSTATUS nterr = cli_nt_error(cli1);
3346 if (!NT_STATUS_EQUAL(nterr,NT_STATUS_ACCESS_DENIED)) {
3347 printf("[11] open of %s should have been denied with ACCESS_DENIED! Got error %s\n", fname, nt_errstr(nterr));
3351 printf("eleventh delete on close test succeeded.\n");
3355 printf("finished delete test\n");
3358 /* FIXME: This will crash if we aborted before cli2 got
3359 * intialized, because these functions don't handle
3360 * uninitialized connections. */
3362 if (fnum1 != -1) cli_close(cli1, fnum1);
3363 if (fnum2 != -1) cli_close(cli1, fnum2);
3364 cli_setatr(cli1, fname, 0, 0);
3365 cli_unlink(cli1, fname);
3367 if (cli1 && !torture_close_connection(cli1)) {
3370 if (cli2 && !torture_close_connection(cli2)) {
3378 print out server properties
3380 static BOOL run_properties(int dummy)
3382 static struct cli_state *cli;
3383 BOOL correct = True;
3385 printf("starting properties test\n");
3389 if (!torture_open_connection(&cli, 0)) {
3393 cli_sockopt(cli, sockops);
3395 d_printf("Capabilities 0x%08x\n", cli->capabilities);
3397 if (!torture_close_connection(cli)) {
3406 /* FIRST_DESIRED_ACCESS 0xf019f */
3407 #define FIRST_DESIRED_ACCESS FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|\
3408 FILE_READ_EA| /* 0xf */ \
3409 FILE_WRITE_EA|FILE_READ_ATTRIBUTES| /* 0x90 */ \
3410 FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
3411 DELETE_ACCESS|READ_CONTROL_ACCESS|\
3412 WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS /* 0xf0000 */
3413 /* SECOND_DESIRED_ACCESS 0xe0080 */
3414 #define SECOND_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
3415 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
3416 WRITE_OWNER_ACCESS /* 0xe0000 */
3419 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
3420 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
3422 WRITE_OWNER_ACCESS /* */
3426 Test ntcreate calls made by xcopy
3428 static BOOL run_xcopy(int dummy)
3430 static struct cli_state *cli1;
3431 const char *fname = "\\test.txt";
3432 BOOL correct = True;
3435 printf("starting xcopy test\n");
3437 if (!torture_open_connection(&cli1, 0)) {
3441 fnum1 = cli_nt_create_full(cli1, fname, 0,
3442 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
3443 FILE_SHARE_NONE, FILE_OVERWRITE_IF,
3447 printf("First open failed - %s\n", cli_errstr(cli1));
3451 fnum2 = cli_nt_create_full(cli1, fname, 0,
3452 SECOND_DESIRED_ACCESS, 0,
3453 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN,
3456 printf("second open failed - %s\n", cli_errstr(cli1));
3460 if (!torture_close_connection(cli1)) {
3468 Test rename on files open with share delete and no share delete.
3470 static BOOL run_rename(int dummy)
3472 static struct cli_state *cli1;
3473 const char *fname = "\\test.txt";
3474 const char *fname1 = "\\test1.txt";
3475 BOOL correct = True;
3478 printf("starting rename test\n");
3480 if (!torture_open_connection(&cli1, 0)) {
3484 cli_unlink(cli1, fname);
3485 cli_unlink(cli1, fname1);
3486 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3487 FILE_SHARE_READ, FILE_OVERWRITE_IF, 0, 0);
3490 printf("First open failed - %s\n", cli_errstr(cli1));
3494 if (!cli_rename(cli1, fname, fname1)) {
3495 printf("First rename failed (SHARE_READ) (this is correct) - %s\n", cli_errstr(cli1));
3497 printf("First rename succeeded (SHARE_READ) - this should have failed !\n");
3501 if (!cli_close(cli1, fnum1)) {
3502 printf("close - 1 failed (%s)\n", cli_errstr(cli1));
3506 cli_unlink(cli1, fname);
3507 cli_unlink(cli1, fname1);
3508 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3510 FILE_SHARE_DELETE|FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3512 FILE_SHARE_DELETE|FILE_SHARE_READ, FILE_OVERWRITE_IF, 0, 0);
3516 printf("Second open failed - %s\n", cli_errstr(cli1));
3520 if (!cli_rename(cli1, fname, fname1)) {
3521 printf("Second rename failed (SHARE_DELETE | SHARE_READ) - this should have succeeded - %s\n", cli_errstr(cli1));
3524 printf("Second rename succeeded (SHARE_DELETE | SHARE_READ)\n");
3527 if (!cli_close(cli1, fnum1)) {
3528 printf("close - 2 failed (%s)\n", cli_errstr(cli1));
3532 cli_unlink(cli1, fname);
3533 cli_unlink(cli1, fname1);
3535 fnum1 = cli_nt_create_full(cli1, fname, 0, READ_CONTROL_ACCESS, FILE_ATTRIBUTE_NORMAL,
3536 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3539 printf("Third open failed - %s\n", cli_errstr(cli1));
3548 fnum2 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
3549 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3552 printf("Fourth open failed - %s\n", cli_errstr(cli1));
3555 if (!cli_nt_delete_on_close(cli1, fnum2, True)) {
3556 printf("[8] setting delete_on_close on file failed !\n");
3560 if (!cli_close(cli1, fnum2)) {
3561 printf("close - 4 failed (%s)\n", cli_errstr(cli1));
3567 if (!cli_rename(cli1, fname, fname1)) {
3568 printf("Third rename failed (SHARE_NONE) - this should have succeeded - %s\n", cli_errstr(cli1));
3571 printf("Third rename succeeded (SHARE_NONE)\n");
3574 if (!cli_close(cli1, fnum1)) {
3575 printf("close - 3 failed (%s)\n", cli_errstr(cli1));
3579 cli_unlink(cli1, fname);
3580 cli_unlink(cli1, fname1);
3584 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3585 FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0);
3588 printf("Fourth open failed - %s\n", cli_errstr(cli1));
3592 if (!cli_rename(cli1, fname, fname1)) {
3593 printf("Fourth rename failed (SHARE_READ | SHARE_WRITE) (this is correct) - %s\n", cli_errstr(cli1));
3595 printf("Fourth rename succeeded (SHARE_READ | SHARE_WRITE) - this should have failed !\n");
3599 if (!cli_close(cli1, fnum1)) {
3600 printf("close - 4 failed (%s)\n", cli_errstr(cli1));
3604 cli_unlink(cli1, fname);
3605 cli_unlink(cli1, fname1);
3609 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3610 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0);
3613 printf("Fifth open failed - %s\n", cli_errstr(cli1));
3617 if (!cli_rename(cli1, fname, fname1)) {
3618 printf("Fifth rename failed (SHARE_READ | SHARE_WRITE | SHARE_DELETE) - this should have failed ! \n");
3621 printf("Fifth rename succeeded (SHARE_READ | SHARE_WRITE | SHARE_DELETE) (this is correct) - %s\n", cli_errstr(cli1));
3625 * Now check if the first name still exists ...
3628 /*fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3629 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0);
3632 printf("Opening original file after rename of open file fails: %s\n",
3636 printf("Opening original file after rename of open file works ...\n");
3637 (void)cli_close(cli1, fnum2);
3643 if (!cli_close(cli1, fnum1)) {
3644 printf("close - 5 failed (%s)\n", cli_errstr(cli1));
3648 cli_unlink(cli1, fname);
3649 cli_unlink(cli1, fname1);
3651 if (!torture_close_connection(cli1)) {
3658 static BOOL run_pipe_number(int dummy)
3660 struct cli_state *cli1;
3661 const char *pipe_name = "\\SPOOLSS";
3665 printf("starting pipenumber test\n");
3666 if (!torture_open_connection(&cli1, 0)) {
3670 cli_sockopt(cli1, sockops);
3672 fnum = cli_nt_create_full(cli1, pipe_name, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
3673 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN_IF, 0, 0);
3676 printf("Open of pipe %s failed with error (%s)\n", pipe_name, cli_errstr(cli1));
3682 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes, pipe_name );
3683 torture_close_connection(cli1);
3688 Test open mode returns on read-only files.
3690 static BOOL run_opentest(int dummy)
3692 static struct cli_state *cli1;
3693 static struct cli_state *cli2;
3694 const char *fname = "\\readonly.file";
3698 BOOL correct = True;
3701 printf("starting open test\n");
3703 if (!torture_open_connection(&cli1, 0)) {
3707 cli_setatr(cli1, fname, 0, 0);
3708 cli_unlink(cli1, fname);
3710 cli_sockopt(cli1, sockops);
3712 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
3714 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
3718 if (!cli_close(cli1, fnum1)) {
3719 printf("close2 failed (%s)\n", cli_errstr(cli1));
3723 if (!cli_setatr(cli1, fname, aRONLY, 0)) {
3724 printf("cli_setatr failed (%s)\n", cli_errstr(cli1));
3728 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_WRITE);
3730 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
3734 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
3735 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_ALL);
3737 if (check_error(__LINE__, cli1, ERRDOS, ERRnoaccess,
3738 NT_STATUS_ACCESS_DENIED)) {
3739 printf("correct error code ERRDOS/ERRnoaccess returned\n");
3742 printf("finished open test 1\n");
3744 cli_close(cli1, fnum1);
3746 /* Now try not readonly and ensure ERRbadshare is returned. */
3748 cli_setatr(cli1, fname, 0, 0);
3750 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_WRITE);
3752 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
3756 /* This will fail - but the error should be ERRshare. */
3757 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_ALL);
3759 if (check_error(__LINE__, cli1, ERRDOS, ERRbadshare,
3760 NT_STATUS_SHARING_VIOLATION)) {
3761 printf("correct error code ERRDOS/ERRbadshare returned\n");
3764 if (!cli_close(cli1, fnum1)) {
3765 printf("close2 failed (%s)\n", cli_errstr(cli1));
3769 cli_unlink(cli1, fname);
3771 printf("finished open test 2\n");
3773 /* Test truncate open disposition on file opened for read. */
3775 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
3777 printf("(3) open (1) of %s failed (%s)\n", fname, cli_errstr(cli1));
3781 /* write 20 bytes. */
3783 memset(buf, '\0', 20);
3785 if (cli_write(cli1, fnum1, 0, buf, 0, 20) != 20) {
3786 printf("write failed (%s)\n", cli_errstr(cli1));
3790 if (!cli_close(cli1, fnum1)) {
3791 printf("(3) close1 failed (%s)\n", cli_errstr(cli1));
3795 /* Ensure size == 20. */
3796 if (!cli_getatr(cli1, fname, NULL, &fsize, NULL)) {
3797 printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
3802 printf("(3) file size != 20\n");
3806 /* Now test if we can truncate a file opened for readonly. */
3808 fnum1 = cli_open(cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE);
3810 printf("(3) open (2) of %s failed (%s)\n", fname, cli_errstr(cli1));
3814 if (!cli_close(cli1, fnum1)) {
3815 printf("close2 failed (%s)\n", cli_errstr(cli1));
3819 /* Ensure size == 0. */
3820 if (!cli_getatr(cli1, fname, NULL, &fsize, NULL)) {
3821 printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
3826 printf("(3) file size != 0\n");
3829 printf("finished open test 3\n");
3831 cli_unlink(cli1, fname);
3834 printf("testing ctemp\n");
3835 fnum1 = cli_ctemp(cli1, "\\", &tmp_path);
3837 printf("ctemp failed (%s)\n", cli_errstr(cli1));
3840 printf("ctemp gave path %s\n", tmp_path);
3841 if (!cli_close(cli1, fnum1)) {
3842 printf("close of temp failed (%s)\n", cli_errstr(cli1));
3844 if (!cli_unlink(cli1, tmp_path)) {
3845 printf("unlink of temp failed (%s)\n", cli_errstr(cli1));
3848 /* Test the non-io opens... */
3850 if (!torture_open_connection(&cli2, 1)) {
3854 cli_setatr(cli2, fname, 0, 0);
3855 cli_unlink(cli2, fname);
3857 cli_sockopt(cli2, sockops);
3859 printf("TEST #1 testing 2 non-io opens (no delete)\n");
3861 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3862 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3865 printf("test 1 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3869 fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3870 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
3873 printf("test 1 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3877 if (!cli_close(cli1, fnum1)) {
3878 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3881 if (!cli_close(cli2, fnum2)) {
3882 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3886 printf("non-io open test #1 passed.\n");
3888 cli_unlink(cli1, fname);
3890 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
3892 fnum1 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3893 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3896 printf("test 2 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3900 fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3901 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
3904 printf("test 2 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3908 if (!cli_close(cli1, fnum1)) {
3909 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3912 if (!cli_close(cli2, fnum2)) {
3913 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
3917 printf("non-io open test #2 passed.\n");
3919 cli_unlink(cli1, fname);
3921 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
3923 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3924 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3927 printf("test 3 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3931 fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3932 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
3935 printf("test 3 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3939 if (!cli_close(cli1, fnum1)) {
3940 printf("test 3 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3943 if (!cli_close(cli2, fnum2)) {
3944 printf("test 3 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3948 printf("non-io open test #3 passed.\n");
3950 cli_unlink(cli1, fname);
3952 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
3954 fnum1 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3955 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3958 printf("test 4 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3962 fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3963 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
3966 printf("test 4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
3970 printf("test 3 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
3972 if (!cli_close(cli1, fnum1)) {
3973 printf("test 4 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3977 printf("non-io open test #4 passed.\n");
3979 cli_unlink(cli1, fname);
3981 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
3983 fnum1 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3984 FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0);
3987 printf("test 5 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3991 fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3992 FILE_SHARE_DELETE, FILE_OPEN_IF, 0, 0);
3995 printf("test 5 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3999 if (!cli_close(cli1, fnum1)) {
4000 printf("test 5 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4004 if (!cli_close(cli2, fnum2)) {
4005 printf("test 5 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4009 printf("non-io open test #5 passed.\n");
4011 printf("TEST #6 testing 1 non-io open, one io open\n");
4013 cli_unlink(cli1, fname);
4015 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
4016 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
4019 printf("test 6 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4023 fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4024 FILE_SHARE_READ, FILE_OPEN_IF, 0, 0);
4027 printf("test 6 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4031 if (!cli_close(cli1, fnum1)) {
4032 printf("test 6 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4036 if (!cli_close(cli2, fnum2)) {
4037 printf("test 6 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4041 printf("non-io open test #6 passed.\n");
4043 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
4045 cli_unlink(cli1, fname);
4047 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
4048 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
4051 printf("test 7 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4055 fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4056 FILE_SHARE_READ|FILE_SHARE_DELETE, FILE_OPEN_IF, 0, 0);
4059 printf("test 7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
4063 printf("test 7 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
4065 if (!cli_close(cli1, fnum1)) {
4066 printf("test 7 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4070 printf("non-io open test #7 passed.\n");
4072 cli_unlink(cli1, fname);
4074 if (!torture_close_connection(cli1)) {
4077 if (!torture_close_connection(cli2)) {
4084 static uint32 open_attrs_table[] = {
4085 FILE_ATTRIBUTE_NORMAL,
4086 FILE_ATTRIBUTE_ARCHIVE,
4087 FILE_ATTRIBUTE_READONLY,
4088 FILE_ATTRIBUTE_HIDDEN,
4089 FILE_ATTRIBUTE_SYSTEM,
4091 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY,
4092 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN,
4093 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM,
4094 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
4095 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
4096 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
4098 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
4099 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
4100 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
4101 FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_SYSTEM,
4104 struct trunc_open_results {
4111 static struct trunc_open_results attr_results[] = {
4112 { 0, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
4113 { 1, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
4114 { 2, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
4115 { 16, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
4116 { 17, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
4117 { 18, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
4118 { 51, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4119 { 54, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4120 { 56, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
4121 { 68, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4122 { 71, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4123 { 73, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM },
4124 { 99, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4125 { 102, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4126 { 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 },
4127 { 116, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4128 { 119, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4129 { 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 },
4130 { 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 },
4131 { 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 },
4132 { 227, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4133 { 230, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4134 { 232, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
4135 { 244, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4136 { 247, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4137 { 249, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM }
4140 static BOOL run_openattrtest(int dummy)
4142 static struct cli_state *cli1;
4143 const char *fname = "\\openattr.file";
4145 BOOL correct = True;
4147 unsigned int i, j, k, l;
4149 printf("starting open attr test\n");
4151 if (!torture_open_connection(&cli1, 0)) {
4155 cli_sockopt(cli1, sockops);
4157 for (k = 0, i = 0; i < sizeof(open_attrs_table)/sizeof(uint32); i++) {
4158 cli_setatr(cli1, fname, 0, 0);
4159 cli_unlink(cli1, fname);
4160 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_WRITE_DATA, open_attrs_table[i],
4161 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
4164 printf("open %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
4168 if (!cli_close(cli1, fnum1)) {
4169 printf("close %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
4173 for (j = 0; j < sizeof(open_attrs_table)/sizeof(uint32); j++) {
4174 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA, open_attrs_table[j],
4175 FILE_SHARE_NONE, FILE_OVERWRITE, 0, 0);
4178 for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
4179 if (attr_results[l].num == k) {
4180 printf("[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(0x%x:%s)\n",
4181 k, open_attrs_table[i],
4182 open_attrs_table[j],
4183 fname, NT_STATUS_V(cli_nt_error(cli1)), cli_errstr(cli1));
4187 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_ACCESS_DENIED)) {
4188 printf("[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s\n",
4189 k, open_attrs_table[i], open_attrs_table[j],
4194 printf("[%d] trunc open 0x%x -> 0x%x failed\n", k, open_attrs_table[i], open_attrs_table[j]);
4200 if (!cli_close(cli1, fnum1)) {
4201 printf("close %d (2) of %s failed (%s)\n", j, fname, cli_errstr(cli1));
4205 if (!cli_getatr(cli1, fname, &attr, NULL, NULL)) {
4206 printf("getatr(2) failed (%s)\n", cli_errstr(cli1));
4211 printf("[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n",
4212 k, open_attrs_table[i], open_attrs_table[j], attr );
4215 for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
4216 if (attr_results[l].num == k) {
4217 if (attr != attr_results[l].result_attr ||
4218 open_attrs_table[i] != attr_results[l].init_attr ||
4219 open_attrs_table[j] != attr_results[l].trunc_attr) {
4220 printf("getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x\n",
4221 open_attrs_table[i],
4222 open_attrs_table[j],
4224 attr_results[l].result_attr);
4234 cli_setatr(cli1, fname, 0, 0);
4235 cli_unlink(cli1, fname);
4237 printf("open attr test %s.\n", correct ? "passed" : "failed");
4239 if (!torture_close_connection(cli1)) {
4245 static void list_fn(const char *mnt, file_info *finfo, const char *name, void *state)
4251 test directory listing speed
4253 static BOOL run_dirtest(int dummy)
4256 static struct cli_state *cli;
4259 BOOL correct = True;
4261 printf("starting directory test\n");
4263 if (!torture_open_connection(&cli, 0)) {
4267 cli_sockopt(cli, sockops);
4270 for (i=0;i<torture_numops;i++) {
4272 slprintf(fname, sizeof(fname), "\\%x", (int)random());
4273 fnum = cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE);
4275 fprintf(stderr,"Failed to open %s\n", fname);
4278 cli_close(cli, fnum);
4283 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
4284 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
4285 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
4287 printf("dirtest core %g seconds\n", end_timer() - t1);
4290 for (i=0;i<torture_numops;i++) {
4292 slprintf(fname, sizeof(fname), "\\%x", (int)random());
4293 cli_unlink(cli, fname);
4296 if (!torture_close_connection(cli)) {
4300 printf("finished dirtest\n");
4305 static void del_fn(const char *mnt, file_info *finfo, const char *mask, void *state)
4307 struct cli_state *pcli = (struct cli_state *)state;
4309 slprintf(fname, sizeof(fname), "\\LISTDIR\\%s", finfo->name);
4311 if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
4314 if (finfo->mode & aDIR) {
4315 if (!cli_rmdir(pcli, fname))
4316 printf("del_fn: failed to rmdir %s\n,", fname );
4318 if (!cli_unlink(pcli, fname))
4319 printf("del_fn: failed to unlink %s\n,", fname );
4325 sees what IOCTLs are supported
4327 BOOL torture_ioctl_test(int dummy)
4329 static struct cli_state *cli;
4330 uint16 device, function;
4332 const char *fname = "\\ioctl.dat";
4336 if (!torture_open_connection(&cli, 0)) {
4340 printf("starting ioctl test\n");
4342 cli_unlink(cli, fname);
4344 fnum = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
4346 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
4350 status = cli_raw_ioctl(cli, fnum, 0x2d0000 | (0x0420<<2), &blob);
4351 printf("ioctl device info: %s\n", cli_errstr(cli));
4353 status = cli_raw_ioctl(cli, fnum, IOCTL_QUERY_JOB_INFO, &blob);
4354 printf("ioctl job info: %s\n", cli_errstr(cli));
4356 for (device=0;device<0x100;device++) {
4357 printf("testing device=0x%x\n", device);
4358 for (function=0;function<0x100;function++) {
4359 uint32 code = (device<<16) | function;
4361 status = cli_raw_ioctl(cli, fnum, code, &blob);
4363 if (NT_STATUS_IS_OK(status)) {
4364 printf("ioctl 0x%x OK : %d bytes\n", (int)code,
4366 data_blob_free(&blob);
4371 if (!torture_close_connection(cli)) {
4380 tries varients of chkpath
4382 BOOL torture_chkpath_test(int dummy)
4384 static struct cli_state *cli;
4388 if (!torture_open_connection(&cli, 0)) {
4392 printf("starting chkpath test\n");
4394 /* cleanup from an old run */
4395 cli_rmdir(cli, "\\chkpath.dir\\dir2");
4396 cli_unlink(cli, "\\chkpath.dir\\*");
4397 cli_rmdir(cli, "\\chkpath.dir");
4399 if (!cli_mkdir(cli, "\\chkpath.dir")) {
4400 printf("mkdir1 failed : %s\n", cli_errstr(cli));
4404 if (!cli_mkdir(cli, "\\chkpath.dir\\dir2")) {
4405 printf("mkdir2 failed : %s\n", cli_errstr(cli));
4409 fnum = cli_open(cli, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
4411 printf("open1 failed (%s)\n", cli_errstr(cli));
4414 cli_close(cli, fnum);
4416 if (!cli_chkpath(cli, "\\chkpath.dir")) {
4417 printf("chkpath1 failed: %s\n", cli_errstr(cli));
4421 if (!cli_chkpath(cli, "\\chkpath.dir\\dir2")) {
4422 printf("chkpath2 failed: %s\n", cli_errstr(cli));
4426 if (!cli_chkpath(cli, "\\chkpath.dir\\foo.txt")) {
4427 ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath,
4428 NT_STATUS_NOT_A_DIRECTORY);
4430 printf("* chkpath on a file should fail\n");
4434 if (!cli_chkpath(cli, "\\chkpath.dir\\bar.txt")) {
4435 ret = check_error(__LINE__, cli, ERRDOS, ERRbadfile,
4436 NT_STATUS_OBJECT_NAME_NOT_FOUND);
4438 printf("* chkpath on a non existant file should fail\n");
4442 if (!cli_chkpath(cli, "\\chkpath.dir\\dirxx\\bar.txt")) {
4443 ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath,
4444 NT_STATUS_OBJECT_PATH_NOT_FOUND);
4446 printf("* chkpath on a non existent component should fail\n");
4450 cli_rmdir(cli, "\\chkpath.dir\\dir2");
4451 cli_unlink(cli, "\\chkpath.dir\\*");
4452 cli_rmdir(cli, "\\chkpath.dir");
4454 if (!torture_close_connection(cli)) {
4461 static BOOL run_eatest(int dummy)
4463 static struct cli_state *cli;
4464 const char *fname = "\\eatest.txt";
4465 BOOL correct = True;
4468 struct ea_struct *ea_list = NULL;
4469 TALLOC_CTX *mem_ctx = talloc_init("eatest");
4471 printf("starting eatest\n");
4473 if (!torture_open_connection(&cli, 0)) {
4477 cli_unlink(cli, fname);
4478 fnum = cli_nt_create_full(cli, fname, 0,
4479 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
4480 FILE_SHARE_NONE, FILE_OVERWRITE_IF,
4484 printf("open failed - %s\n", cli_errstr(cli));
4488 for (i = 0; i < 10; i++) {
4489 fstring ea_name, ea_val;
4491 slprintf(ea_name, sizeof(ea_name), "EA_%d", i);
4492 memset(ea_val, (char)i+1, i+1);
4493 if (!cli_set_ea_fnum(cli, fnum, ea_name, ea_val, i+1)) {
4494 printf("ea_set of name %s failed - %s\n", ea_name, cli_errstr(cli));
4499 cli_close(cli, fnum);
4500 for (i = 0; i < 10; i++) {
4501 fstring ea_name, ea_val;
4503 slprintf(ea_name, sizeof(ea_name), "EA_%d", i+10);
4504 memset(ea_val, (char)i+1, i+1);
4505 if (!cli_set_ea_path(cli, fname, ea_name, ea_val, i+1)) {
4506 printf("ea_set of name %s failed - %s\n", ea_name, cli_errstr(cli));
4511 if (!cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list)) {
4512 printf("ea_get list failed - %s\n", cli_errstr(cli));
4516 printf("num_eas = %d\n", (int)num_eas);
4518 if (num_eas != 20) {
4519 printf("Should be 20 EA's stored... failing.\n");
4523 for (i = 0; i < num_eas; i++) {
4524 printf("%d: ea_name = %s. Val = ", i, ea_list[i].name);
4525 dump_data(0, (char *)ea_list[i].value.data,
4526 ea_list[i].value.length);
4529 /* Setting EA's to zero length deletes them. Test this */
4530 printf("Now deleting all EA's - case indepenent....\n");
4533 cli_set_ea_path(cli, fname, "", "", 0);
4535 for (i = 0; i < 20; i++) {
4537 slprintf(ea_name, sizeof(ea_name), "ea_%d", i);
4538 if (!cli_set_ea_path(cli, fname, ea_name, "", 0)) {
4539 printf("ea_set of name %s failed - %s\n", ea_name, cli_errstr(cli));
4545 if (!cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list)) {
4546 printf("ea_get list failed - %s\n", cli_errstr(cli));
4550 printf("num_eas = %d\n", (int)num_eas);
4551 for (i = 0; i < num_eas; i++) {
4552 printf("%d: ea_name = %s. Val = ", i, ea_list[i].name);
4553 dump_data(0, (char *)ea_list[i].value.data,
4554 ea_list[i].value.length);
4558 printf("deleting EA's failed.\n");
4562 /* Try and delete a non existant EA. */
4563 if (!cli_set_ea_path(cli, fname, "foo", "", 0)) {
4564 printf("deleting non-existant EA 'foo' should succeed. %s\n", cli_errstr(cli));
4568 talloc_destroy(mem_ctx);
4569 if (!torture_close_connection(cli)) {
4576 static BOOL run_dirtest1(int dummy)
4579 static struct cli_state *cli;
4581 BOOL correct = True;
4583 printf("starting directory test\n");
4585 if (!torture_open_connection(&cli, 0)) {
4589 cli_sockopt(cli, sockops);
4591 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
4592 cli_list(cli, "\\LISTDIR\\*", aDIR, del_fn, cli);
4593 cli_rmdir(cli, "\\LISTDIR");
4594 cli_mkdir(cli, "\\LISTDIR");
4596 /* Create 1000 files and 1000 directories. */
4597 for (i=0;i<1000;i++) {
4599 slprintf(fname, sizeof(fname), "\\LISTDIR\\f%d", i);
4600 fnum = cli_nt_create_full(cli, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
4601 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0);
4603 fprintf(stderr,"Failed to open %s\n", fname);
4606 cli_close(cli, fnum);
4608 for (i=0;i<1000;i++) {
4610 slprintf(fname, sizeof(fname), "\\LISTDIR\\d%d", i);
4611 if (!cli_mkdir(cli, fname)) {
4612 fprintf(stderr,"Failed to open %s\n", fname);
4617 /* Now ensure that doing an old list sees both files and directories. */
4618 num_seen = cli_list_old(cli, "\\LISTDIR\\*", aDIR, list_fn, NULL);
4619 printf("num_seen = %d\n", num_seen );
4620 /* We should see 100 files + 1000 directories + . and .. */
4621 if (num_seen != 2002)
4624 /* Ensure if we have the "must have" bits we only see the
4627 num_seen = cli_list_old(cli, "\\LISTDIR\\*", (aDIR<<8)|aDIR, list_fn, NULL);
4628 printf("num_seen = %d\n", num_seen );
4629 if (num_seen != 1002)
4632 num_seen = cli_list_old(cli, "\\LISTDIR\\*", (aARCH<<8)|aDIR, list_fn, NULL);
4633 printf("num_seen = %d\n", num_seen );
4634 if (num_seen != 1000)
4637 /* Delete everything. */
4638 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
4639 cli_list(cli, "\\LISTDIR\\*", aDIR, del_fn, cli);
4640 cli_rmdir(cli, "\\LISTDIR");
4643 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
4644 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
4645 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
4648 if (!torture_close_connection(cli)) {
4652 printf("finished dirtest1\n");
4657 static BOOL run_error_map_extract(int dummy) {
4659 static struct cli_state *c_dos;
4660 static struct cli_state *c_nt;
4664 uint32 flgs2, errnum;
4671 /* NT-Error connection */
4673 if (!(c_nt = open_nbt_connection())) {
4677 c_nt->use_spnego = False;
4679 if (!cli_negprot(c_nt)) {
4680 printf("%s rejected the NT-error negprot (%s)\n",host, cli_errstr(c_nt));
4685 if (!cli_session_setup(c_nt, "", "", 0, "", 0,
4687 printf("%s rejected the NT-error initial session setup (%s)\n",host, cli_errstr(c_nt));
4691 /* DOS-Error connection */
4693 if (!(c_dos = open_nbt_connection())) {
4697 c_dos->use_spnego = False;
4698 c_dos->force_dos_errors = True;
4700 if (!cli_negprot(c_dos)) {
4701 printf("%s rejected the DOS-error negprot (%s)\n",host, cli_errstr(c_dos));
4702 cli_shutdown(c_dos);
4706 if (!cli_session_setup(c_dos, "", "", 0, "", 0,
4708 printf("%s rejected the DOS-error initial session setup (%s)\n",host, cli_errstr(c_dos));
4712 for (error=(0xc0000000 | 0x1); error < (0xc0000000| 0xFFF); error++) {
4713 fstr_sprintf(user, "%X", error);
4715 if (cli_session_setup(c_nt, user,
4716 password, strlen(password),
4717 password, strlen(password),
4719 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
4722 flgs2 = SVAL(c_nt->inbuf,smb_flg2);
4724 /* Case #1: 32-bit NT errors */
4725 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
4726 nt_status = NT_STATUS(IVAL(c_nt->inbuf,smb_rcls));
4728 printf("/** Dos error on NT connection! (%s) */\n",
4730 nt_status = NT_STATUS(0xc0000000);
4733 if (cli_session_setup(c_dos, user,
4734 password, strlen(password),
4735 password, strlen(password),
4737 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
4739 flgs2 = SVAL(c_dos->inbuf,smb_flg2), errnum;
4741 /* Case #1: 32-bit NT errors */
4742 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
4743 printf("/** NT error on DOS connection! (%s) */\n",
4745 errnum = errclass = 0;
4747 cli_dos_error(c_dos, &errclass, &errnum);
4750 if (NT_STATUS_V(nt_status) != error) {
4751 printf("/*\t{ This NT error code was 'sqashed'\n\t from %s to %s \n\t during the session setup }\n*/\n",
4752 get_nt_error_c_code(NT_STATUS(error)),
4753 get_nt_error_c_code(nt_status));
4756 printf("\t{%s,\t%s,\t%s},\n",
4757 smb_dos_err_class(errclass),
4758 smb_dos_err_name(errclass, errnum),
4759 get_nt_error_c_code(NT_STATUS(error)));
4764 static BOOL run_local_substitute(int dummy)
4766 TALLOC_CTX *mem_ctx;
4769 if ((mem_ctx = talloc_init("run_local_subst")) == NULL) {
4770 printf("talloc_init failed\n");
4774 diff |= strcmp(talloc_sub_specified(mem_ctx, "%U", "bla", "", -1, -1),
4776 diff |= strcmp(talloc_sub_specified(mem_ctx, "%u%U", "bla", "", -1, -1),
4778 diff |= strcmp(talloc_sub_specified(mem_ctx, "%g", "", "", -1, -1),
4780 diff |= strcmp(talloc_sub_specified(mem_ctx, "%G", "", "", -1, -1),
4782 diff |= strcmp(talloc_sub_specified(mem_ctx, "%g", "", "", -1, 0),
4784 diff |= strcmp(talloc_sub_specified(mem_ctx, "%G", "", "", -1, 0),
4786 diff |= strcmp(talloc_sub_specified(mem_ctx, "%D%u", "u", "dom", -1, 0),
4788 diff |= strcmp(talloc_sub_specified(mem_ctx, "%i %I", "", "", -1, -1),
4791 /* Different captialization rules in sub_basic... */
4793 diff |= strcmp(talloc_sub_basic(mem_ctx, "BLA", "dom", "%U%D"),
4796 TALLOC_FREE(mem_ctx);
4800 static double create_procs(BOOL (*fn)(int), BOOL *result)
4803 volatile pid_t *child_status;
4804 volatile BOOL *child_status_out;
4810 child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*nprocs);
4811 if (!child_status) {
4812 printf("Failed to setup shared memory\n");
4816 child_status_out = (volatile BOOL *)shm_setup(sizeof(BOOL)*nprocs);
4817 if (!child_status_out) {
4818 printf("Failed to setup result status shared memory\n");
4822 for (i = 0; i < nprocs; i++) {
4823 child_status[i] = 0;
4824 child_status_out[i] = True;
4829 for (i=0;i<nprocs;i++) {
4832 pid_t mypid = getpid();
4833 sys_srandom(((int)mypid) ^ ((int)time(NULL)));
4835 slprintf(myname,sizeof(myname),"CLIENT%d", i);
4838 if (torture_open_connection(¤t_cli, i)) break;
4840 printf("pid %d failed to start\n", (int)getpid());
4846 child_status[i] = getpid();
4848 while (child_status[i] && end_timer() < 5) smb_msleep(2);
4850 child_status_out[i] = fn(i);
4857 for (i=0;i<nprocs;i++) {
4858 if (child_status[i]) synccount++;
4860 if (synccount == nprocs) break;
4862 } while (end_timer() < 30);
4864 if (synccount != nprocs) {
4865 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs, synccount);
4870 /* start the client load */
4873 for (i=0;i<nprocs;i++) {
4874 child_status[i] = 0;
4877 printf("%d clients started\n", nprocs);
4879 for (i=0;i<nprocs;i++) {
4880 while (waitpid(0, &status, 0) == -1 && errno == EINTR) /* noop */ ;
4885 for (i=0;i<nprocs;i++) {
4886 if (!child_status_out[i]) {
4893 #define FLAG_MULTIPROC 1
4900 {"FDPASS", run_fdpasstest, 0},
4901 {"LOCK1", run_locktest1, 0},
4902 {"LOCK2", run_locktest2, 0},
4903 {"LOCK3", run_locktest3, 0},
4904 {"LOCK4", run_locktest4, 0},
4905 {"LOCK5", run_locktest5, 0},
4906 {"LOCK6", run_locktest6, 0},
4907 {"LOCK7", run_locktest7, 0},
4908 {"UNLINK", run_unlinktest, 0},
4909 {"BROWSE", run_browsetest, 0},
4910 {"ATTR", run_attrtest, 0},
4911 {"TRANS2", run_trans2test, 0},
4912 {"MAXFID", run_maxfidtest, FLAG_MULTIPROC},
4913 {"TORTURE",run_torture, FLAG_MULTIPROC},
4914 {"RANDOMIPC", run_randomipc, 0},
4915 {"NEGNOWAIT", run_negprot_nowait, 0},
4916 {"NBENCH", run_nbench, 0},
4917 {"OPLOCK1", run_oplock1, 0},
4918 {"OPLOCK2", run_oplock2, 0},
4919 {"OPLOCK3", run_oplock3, 0},
4920 {"DIR", run_dirtest, 0},
4921 {"DIR1", run_dirtest1, 0},
4922 {"DENY1", torture_denytest1, 0},
4923 {"DENY2", torture_denytest2, 0},
4924 {"TCON", run_tcon_test, 0},
4925 {"TCONDEV", run_tcon_devtype_test, 0},
4926 {"RW1", run_readwritetest, 0},
4927 {"RW2", run_readwritemulti, FLAG_MULTIPROC},
4928 {"RW3", run_readwritelarge, 0},
4929 {"OPEN", run_opentest, 0},
4931 {"OPENATTR", run_openattrtest, 0},
4933 {"XCOPY", run_xcopy, 0},
4934 {"RENAME", run_rename, 0},
4935 {"DELETE", run_deletetest, 0},
4936 {"PROPERTIES", run_properties, 0},
4937 {"MANGLE", torture_mangle, 0},
4938 {"W2K", run_w2ktest, 0},
4939 {"TRANS2SCAN", torture_trans2_scan, 0},
4940 {"NTTRANSSCAN", torture_nttrans_scan, 0},
4941 {"UTABLE", torture_utable, 0},
4942 {"CASETABLE", torture_casetable, 0},
4943 {"ERRMAPEXTRACT", run_error_map_extract, 0},
4944 {"PIPE_NUMBER", run_pipe_number, 0},
4945 {"TCON2", run_tcon2_test, 0},
4946 {"IOCTL", torture_ioctl_test, 0},
4947 {"CHKPATH", torture_chkpath_test, 0},
4948 {"FDSESS", run_fdsesstest, 0},
4949 { "EATEST", run_eatest, 0},
4950 { "LOCAL-SUBSTITUTE", run_local_substitute, 0},
4955 /****************************************************************************
4956 run a specified test or "ALL"
4957 ****************************************************************************/
4958 static BOOL run_test(const char *name)
4965 if (strequal(name,"ALL")) {
4966 for (i=0;torture_ops[i].name;i++) {
4967 run_test(torture_ops[i].name);
4972 for (i=0;torture_ops[i].name;i++) {
4973 fstr_sprintf(randomfname, "\\XX%x",
4974 (unsigned)random());
4976 if (strequal(name, torture_ops[i].name)) {
4978 printf("Running %s\n", name);
4979 if (torture_ops[i].flags & FLAG_MULTIPROC) {
4980 t = create_procs(torture_ops[i].fn, &result);
4983 printf("TEST %s FAILED!\n", name);
4988 if (!torture_ops[i].fn(0)) {
4990 printf("TEST %s FAILED!\n", name);
4994 printf("%s took %g secs\n\n", name, t);
4999 printf("Did not find a test named %s\n", name);
5007 static void usage(void)
5011 printf("WARNING samba4 test suite is much more complete nowadays.\n");
5012 printf("Please use samba4 torture.\n\n");
5014 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
5016 printf("\t-d debuglevel\n");
5017 printf("\t-U user%%pass\n");
5018 printf("\t-k use kerberos\n");
5019 printf("\t-N numprocs\n");
5020 printf("\t-n my_netbios_name\n");
5021 printf("\t-W workgroup\n");
5022 printf("\t-o num_operations\n");
5023 printf("\t-O socket_options\n");
5024 printf("\t-m maximum protocol\n");
5025 printf("\t-L use oplocks\n");
5026 printf("\t-c CLIENT.TXT specify client load file for NBENCH\n");
5027 printf("\t-A showall\n");
5028 printf("\t-p port\n");
5029 printf("\t-s seed\n");
5030 printf("\t-b unclist_filename specify multiple shares for multiple connections\n");
5033 printf("tests are:");
5034 for (i=0;torture_ops[i].name;i++) {
5035 printf(" %s", torture_ops[i].name);
5039 printf("default test is ALL\n");
5044 /****************************************************************************
5046 ****************************************************************************/
5047 int main(int argc,char *argv[])
5053 BOOL correct = True;
5057 #ifdef HAVE_SETBUFFER
5058 setbuffer(stdout, NULL, 0);
5063 lp_load(dyn_CONFIGFILE,True,False,False,True);
5070 for(p = argv[1]; *p; p++)
5074 if (strncmp(argv[1], "//", 2)) {
5078 fstrcpy(host, &argv[1][2]);
5079 p = strchr_m(&host[2],'/');
5084 fstrcpy(share, p+1);
5088 if (*username == 0 && getenv("LOGNAME")) {
5089 fstrcpy(username,getenv("LOGNAME"));
5095 srandom(time(NULL));
5097 fstrcpy(workgroup, lp_workgroup());
5099 while ((opt = getopt(argc, argv, "p:hW:U:n:N:O:o:m:Ld:Ac:ks:b:")) != EOF) {
5102 port_to_use = atoi(optarg);
5105 srandom(atoi(optarg));
5108 fstrcpy(workgroup,optarg);
5111 max_protocol = interpret_protocol(optarg, max_protocol);
5114 nprocs = atoi(optarg);
5117 torture_numops = atoi(optarg);
5120 DEBUGLEVEL = atoi(optarg);
5129 torture_showall = True;
5132 fstrcpy(myname, optarg);
5135 client_txt = optarg;
5139 use_kerberos = True;
5141 d_printf("No kerberos support compiled in\n");
5147 fstrcpy(username,optarg);
5148 p = strchr_m(username,'%');
5151 fstrcpy(password, p+1);
5156 fstrcpy(multishare_conn_fname, optarg);
5157 use_multishare_conn = True;
5160 printf("Unknown option %c (%d)\n", (char)opt, opt);
5165 if(use_kerberos && !gotuser) gotpass = True;
5168 p = getpass("Password:");
5170 fstrcpy(password, p);
5175 printf("host=%s share=%s user=%s myname=%s\n",
5176 host, share, username, myname);
5178 if (argc == optind) {
5179 correct = run_test("ALL");
5181 for (i=optind;i<argc;i++) {
5182 if (!run_test(argv[i])) {