2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1997-2003
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.
24 int torture_numops=100;
25 int torture_entries=1000;
26 int torture_failures=1;
27 static int procnum; /* records process count number when forking */
28 static struct cli_state *current_cli;
29 static char *randomfname;
30 static BOOL use_oplocks;
31 static BOOL use_level_II_oplocks;
32 static const char *client_txt = "client_oplocks.txt";
33 static BOOL use_kerberos;
34 static BOOL bypass_io;
36 BOOL torture_showall = False;
38 static double create_procs(BOOL (*fn)(int), BOOL *result);
40 #define CHECK_MAX_FAILURES(label) do { if (++failures >= torture_failures) goto label; } while (0)
42 static struct cli_state *open_nbt_connection(void)
44 struct nmb_name called, calling;
46 struct cli_state *cli;
47 char *host = lp_parm_string(-1, "torture", "host");
49 make_nmb_name(&calling, lp_netbios_name(), 0x0);
50 make_nmb_name(&called , host, 0x20);
54 cli = cli_state_init();
56 printf("Failed initialize cli_struct to connect with %s\n", host);
60 if (!cli_socket_connect(cli, host, &ip)) {
61 printf("Failed to connect with %s\n", host);
65 cli->transport->socket->timeout = 120000; /* set a really long timeout (2 minutes) */
67 if (!cli_transport_establish(cli, &calling, &called)) {
69 * Well, that failed, try *SMBSERVER ...
70 * However, we must reconnect as well ...
72 if (!cli_socket_connect(cli, host, &ip)) {
73 printf("Failed to connect with %s\n", host);
77 make_nmb_name(&called, "*SMBSERVER", 0x20);
78 if (!cli_transport_establish(cli, &calling, &called)) {
79 printf("%s rejected the session\n",host);
80 printf("We tried with a called name of %s & %s\n",
90 BOOL torture_open_connection(struct cli_state **c)
95 char *host = lp_parm_string(-1, "torture", "host");
96 char *share = lp_parm_string(-1, "torture", "share");
97 char *username = lp_parm_string(-1, "torture", "username");
98 char *password = lp_parm_string(-1, "torture", "password");
101 flags |= CLI_FULL_CONNECTION_USE_KERBEROS;
103 status = cli_full_connection(c, lp_netbios_name(),
106 username, lp_workgroup(),
107 password, flags, &retry);
108 if (!NT_STATUS_IS_OK(status)) {
112 (*c)->transport->options.use_oplocks = use_oplocks;
113 (*c)->transport->options.use_level2_oplocks = use_level_II_oplocks;
114 (*c)->transport->socket->timeout = 120000;
119 BOOL torture_close_connection(struct cli_state *c)
122 DEBUG(9,("torture_close_connection: cli_state@%p\n", c));
125 printf("tdis failed (%s)\n", cli_errstr(c));
128 DEBUG(9,("torture_close_connection: call cli_shutdown\n"));
130 DEBUG(9,("torture_close_connection: exit\n"));
135 /* check if the server produced the expected error code */
136 static BOOL check_error(int line, struct cli_state *c,
137 uint8 eclass, uint32 ecode, NTSTATUS nterr)
139 if (cli_is_dos_error(c)) {
143 /* Check DOS error */
145 cli_dos_error(c, &class, &num);
147 if (eclass != class || ecode != num) {
148 printf("unexpected error code class=%d code=%d\n",
149 (int)class, (int)num);
150 printf(" expected %d/%d %s (line=%d)\n",
151 (int)eclass, (int)ecode, nt_errstr(nterr), line);
160 status = cli_nt_error(c);
162 if (NT_STATUS_V(nterr) != NT_STATUS_V(status)) {
163 printf("unexpected error code %s\n", nt_errstr(status));
164 printf(" expected %s (line=%d)\n", nt_errstr(nterr), line);
173 static BOOL wait_lock(struct cli_state *c, int fnum, uint32 offset, uint32 len)
175 while (!cli_lock(c, fnum, offset, len, -1, WRITE_LOCK)) {
176 if (!check_error(__LINE__, c, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
182 static BOOL rw_torture(struct cli_state *c)
184 const char *lockfname = "\\torture.lck";
188 pid_t pid2, pid = getpid();
193 fnum2 = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
196 fnum2 = cli_open(c, lockfname, O_RDWR, DENY_NONE);
198 printf("open of %s failed (%s)\n", lockfname, cli_errstr(c));
203 for (i=0;i<torture_numops;i++) {
204 unsigned n = (unsigned)sys_random()%10;
206 printf("%d\r", i); fflush(stdout);
208 asprintf(&fname, "\\torture.%u", n);
210 if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) {
214 fnum = cli_open(c, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL);
216 printf("open failed (%s)\n", cli_errstr(c));
221 if (cli_write(c, fnum, 0, (char *)&pid, 0, sizeof(pid)) != sizeof(pid)) {
222 printf("write failed (%s)\n", cli_errstr(c));
227 if (cli_write(c, fnum, 0, (char *)buf,
228 sizeof(pid)+(j*sizeof(buf)),
229 sizeof(buf)) != sizeof(buf)) {
230 printf("write failed (%s)\n", cli_errstr(c));
237 if (cli_read(c, fnum, (char *)&pid2, 0, sizeof(pid)) != sizeof(pid)) {
238 printf("read failed (%s)\n", cli_errstr(c));
243 printf("data corruption!\n");
247 if (!cli_close(c, fnum)) {
248 printf("close failed (%s)\n", cli_errstr(c));
252 if (!cli_unlink(c, fname)) {
253 printf("unlink failed (%s)\n", cli_errstr(c));
257 if (!cli_unlock(c, fnum2, n*sizeof(int), sizeof(int))) {
258 printf("unlock failed (%s)\n", cli_errstr(c));
265 cli_unlink(c, lockfname);
272 static BOOL run_torture(int dummy)
274 struct cli_state *cli;
279 ret = rw_torture(cli);
281 if (!torture_close_connection(cli)) {
288 static BOOL rw_torture3(struct cli_state *c, char *lockfname)
295 unsigned countprev = 0;
300 for (i = 0; i < sizeof(buf); i += sizeof(uint32))
302 SIVAL(buf, i, sys_random());
307 fnum = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
310 printf("first open read/write of %s failed (%s)\n",
311 lockfname, cli_errstr(c));
317 for (i = 0; i < 500 && fnum == -1; i++)
319 fnum = cli_open(c, lockfname, O_RDONLY,
324 printf("second open read-only of %s failed (%s)\n",
325 lockfname, cli_errstr(c));
331 for (count = 0; count < sizeof(buf); count += sent)
333 if (count >= countprev) {
334 printf("%d %8d\r", i, count);
337 countprev += (sizeof(buf) / 20);
342 sent = ((unsigned)sys_random()%(20))+ 1;
343 if (sent > sizeof(buf) - count)
345 sent = sizeof(buf) - count;
348 if (cli_write(c, fnum, 0, buf+count, count, (size_t)sent) != sent) {
349 printf("write failed (%s)\n", cli_errstr(c));
355 sent = cli_read(c, fnum, buf_rd+count, count,
359 printf("read failed offset:%d size:%d (%s)\n",
360 count, sizeof(buf)-count,
367 if (memcmp(buf_rd+count, buf+count, sent) != 0)
369 printf("read/write compare failed\n");
370 printf("offset: %d req %d recvd %d\n",
371 count, sizeof(buf)-count, sent);
380 if (!cli_close(c, fnum)) {
381 printf("close failed (%s)\n", cli_errstr(c));
388 static BOOL rw_torture2(struct cli_state *c1, struct cli_state *c2)
390 const char *lockfname = "\\torture2.lck";
395 uchar buf_rd[131072];
397 ssize_t bytes_read, bytes_written;
399 if (cli_deltree(c1, lockfname) == -1) {
400 printf("unlink failed (%s)\n", cli_errstr(c1));
403 fnum1 = cli_open(c1, lockfname, O_RDWR | O_CREAT | O_EXCL,
406 printf("first open read/write of %s failed (%s)\n",
407 lockfname, cli_errstr(c1));
410 fnum2 = cli_open(c2, lockfname, O_RDONLY,
413 printf("second open read-only of %s failed (%s)\n",
414 lockfname, cli_errstr(c2));
415 cli_close(c1, fnum1);
419 printf("Checking data integrity over %d ops\n", torture_numops);
421 for (i=0;i<torture_numops;i++)
423 size_t buf_size = ((unsigned)sys_random()%(sizeof(buf)-1))+ 1;
425 printf("%d\r", i); fflush(stdout);
428 generate_random_buffer(buf, buf_size, False);
430 if ((bytes_written = cli_write(c1, fnum1, 0, buf, 0, buf_size)) != buf_size) {
431 printf("write failed (%s)\n", cli_errstr(c1));
432 printf("wrote %d, expected %d\n", bytes_written, buf_size);
437 if ((bytes_read = cli_read(c2, fnum2, buf_rd, 0, buf_size)) != buf_size) {
438 printf("read failed (%s)\n", cli_errstr(c2));
439 printf("read %d, expected %d\n", bytes_read, buf_size);
444 if (memcmp(buf_rd, buf, buf_size) != 0)
446 printf("read/write compare failed\n");
452 if (!cli_close(c2, fnum2)) {
453 printf("close failed (%s)\n", cli_errstr(c2));
456 if (!cli_close(c1, fnum1)) {
457 printf("close failed (%s)\n", cli_errstr(c1));
461 if (!cli_unlink(c1, lockfname)) {
462 printf("unlink failed (%s)\n", cli_errstr(c1));
469 static BOOL run_readwritetest(int dummy)
471 struct cli_state *cli1, *cli2;
472 BOOL test1, test2 = True;
474 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
478 printf("starting readwritetest\n");
480 test1 = rw_torture2(cli1, cli2);
481 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1));
484 test2 = rw_torture2(cli1, cli1);
485 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2));
488 if (!torture_close_connection(cli1)) {
492 if (!torture_close_connection(cli2)) {
496 return (test1 && test2);
499 static BOOL run_readwritemulti(int dummy)
501 struct cli_state *cli;
506 printf("run_readwritemulti: fname %s\n", randomfname);
507 test = rw_torture3(cli, randomfname);
509 if (!torture_close_connection(cli)) {
520 #define ival(s) strtol(s, NULL, 0)
522 /* run a test that simulates an approximate netbench client load */
523 static BOOL run_netbench(int client)
525 struct cli_state *cli;
530 const char *params[20];
539 asprintf(&cname, "client%d", client);
541 f = fopen(client_txt, "r");
548 while (fgets(line, sizeof(line)-1, f)) {
551 line[strlen(line)-1] = 0;
553 /* printf("[%d] %s\n", line_count, line); */
555 all_string_sub(line,"client1", cname, sizeof(line));
557 /* parse the command parameters */
558 params[0] = strtok(line," ");
560 while (params[i]) params[++i] = strtok(NULL," ");
566 if (!strncmp(params[0],"SMB", 3)) {
567 printf("ERROR: You are using a dbench 1 load file\n");
570 DEBUG(9,("run_netbench(%d): %s %s\n", client, params[0], params[1]));
572 if (!strcmp(params[0],"NTCreateX")) {
573 nb_createx(params[1], ival(params[2]), ival(params[3]),
575 } else if (!strcmp(params[0],"Close")) {
576 nb_close(ival(params[1]));
577 } else if (!strcmp(params[0],"Rename")) {
578 nb_rename(params[1], params[2]);
579 } else if (!strcmp(params[0],"Unlink")) {
580 nb_unlink(params[1]);
581 } else if (!strcmp(params[0],"Deltree")) {
582 nb_deltree(params[1]);
583 } else if (!strcmp(params[0],"Rmdir")) {
585 } else if (!strcmp(params[0],"QUERY_PATH_INFORMATION")) {
586 nb_qpathinfo(params[1]);
587 } else if (!strcmp(params[0],"QUERY_FILE_INFORMATION")) {
588 nb_qfileinfo(ival(params[1]));
589 } else if (!strcmp(params[0],"QUERY_FS_INFORMATION")) {
590 nb_qfsinfo(ival(params[1]));
591 } else if (!strcmp(params[0],"FIND_FIRST")) {
592 nb_findfirst(params[1]);
593 } else if (!strcmp(params[0],"WriteX")) {
594 nb_writex(ival(params[1]),
595 ival(params[2]), ival(params[3]), ival(params[4]));
596 } else if (!strcmp(params[0],"ReadX")) {
597 nb_readx(ival(params[1]),
598 ival(params[2]), ival(params[3]), ival(params[4]));
599 } else if (!strcmp(params[0],"Flush")) {
600 nb_flush(ival(params[1]));
602 printf("Unknown operation %s\n", params[0]);
610 if (!torture_close_connection(cli)) {
618 /* run a test that simulates an approximate netbench client load */
619 static BOOL run_nbench(int dummy)
628 signal(SIGALRM, SIGNAL_CAST nb_alarm);
630 t = create_procs(run_netbench, &correct);
633 printf("\nThroughput %g MB/sec\n",
634 1.0e-6 * nbio_total() / t);
640 This test checks for two things:
642 1) correct support for retaining locks over a close (ie. the server
643 must not use posix semantics)
644 2) support for lock timeouts
646 static BOOL run_locktest1(int dummy)
648 struct cli_state *cli1, *cli2;
649 const char *fname = "\\lockt1.lck";
650 int fnum1, fnum2, fnum3;
652 unsigned lock_timeout;
654 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
658 printf("starting locktest1\n");
660 cli_unlink(cli1, fname);
662 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
664 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
667 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
669 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli1));
672 fnum3 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
674 printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli2));
678 if (!cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
679 printf("lock1 failed (%s)\n", cli_errstr(cli1));
684 if (cli_lock(cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
685 printf("lock2 succeeded! This is a locking bug\n");
688 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
689 NT_STATUS_LOCK_NOT_GRANTED)) return False;
693 lock_timeout = (6 + (random() % 20));
694 printf("Testing lock timeout with timeout=%u\n", lock_timeout);
696 if (cli_lock(cli2, fnum3, 0, 4, lock_timeout * 1000, WRITE_LOCK)) {
697 printf("lock3 succeeded! This is a locking bug\n");
700 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
701 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
706 printf("error: This server appears not to support timed lock requests\n");
708 printf("server slept for %u seconds for a %u second timeout\n",
709 (unsigned int)(t2-t1), lock_timeout);
711 if (!cli_close(cli1, fnum2)) {
712 printf("close1 failed (%s)\n", cli_errstr(cli1));
716 if (cli_lock(cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
717 printf("lock4 succeeded! This is a locking bug\n");
720 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
721 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
724 if (!cli_close(cli1, fnum1)) {
725 printf("close2 failed (%s)\n", cli_errstr(cli1));
729 if (!cli_close(cli2, fnum3)) {
730 printf("close3 failed (%s)\n", cli_errstr(cli2));
734 if (!cli_unlink(cli1, fname)) {
735 printf("unlink failed (%s)\n", cli_errstr(cli1));
740 if (!torture_close_connection(cli1)) {
744 if (!torture_close_connection(cli2)) {
748 printf("Passed locktest1\n");
753 this checks to see if a secondary tconx can use open files from an
756 static BOOL run_tcon_test(int dummy)
758 struct cli_state *cli;
759 const char *fname = "\\tcontest.tmp";
761 uint16 cnum1, cnum2, cnum3;
765 struct cli_tree *tree1;
766 char *host = lp_parm_string(-1, "torture", "host");
767 char *share = lp_parm_string(-1, "torture", "share");
768 char *password = lp_parm_string(-1, "torture", "password");
770 if (!torture_open_connection(&cli)) {
774 printf("starting tcontest\n");
776 if (cli_deltree(cli, fname) == -1) {
777 printf("unlink of %s failed (%s)\n", fname, cli_errstr(cli));
780 fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
782 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
786 cnum1 = cli->tree->tid;
787 vuid1 = cli->session->vuid;
789 memset(&buf, 0, 4); /* init buf so valgrind won't complain */
790 if (cli_write(cli, fnum1, 0, buf, 130, 4) != 4) {
791 printf("initial write failed (%s)\n", cli_errstr(cli));
795 tree1 = cli->tree; /* save old tree connection */
796 if (!cli_send_tconX(cli, share, "?????",
798 printf("%s refused 2nd tree connect (%s)\n", host,
804 cnum2 = cli->tree->tid;
805 cnum3 = MAX(cnum1, cnum2) + 1; /* any invalid number */
806 vuid2 = cli->session->vuid + 1;
808 /* try a write with the wrong tid */
809 cli->tree->tid = cnum2;
811 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
812 printf("* server allows write with wrong TID\n");
815 printf("server fails write with wrong TID : %s\n", cli_errstr(cli));
819 /* try a write with an invalid tid */
820 cli->tree->tid = cnum3;
822 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
823 printf("* server allows write with invalid TID\n");
826 printf("server fails write with invalid TID : %s\n", cli_errstr(cli));
829 /* try a write with an invalid vuid */
830 cli->session->vuid = vuid2;
831 cli->tree->tid = cnum1;
833 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
834 printf("* server allows write with invalid VUID\n");
837 printf("server fails write with invalid VUID : %s\n", cli_errstr(cli));
840 cli->session->vuid = vuid1;
841 cli->tree->tid = cnum1;
843 if (!cli_close(cli, fnum1)) {
844 printf("close failed (%s)\n", cli_errstr(cli));
848 cli->tree->tid = cnum2;
850 if (!cli_tdis(cli)) {
851 printf("secondary tdis failed (%s)\n", cli_errstr(cli));
855 cli->tree = tree1; /* restore initial tree */
856 cli->tree->tid = cnum1;
858 if (!torture_close_connection(cli)) {
867 static BOOL tcon_devtest(struct cli_state *cli,
868 const char *myshare, const char *devtype,
869 NTSTATUS expected_error)
873 char *password = lp_parm_string(-1, "torture", "password");
875 status = cli_send_tconX(cli, myshare, devtype,
878 printf("Trying share %s with devtype %s\n", myshare, devtype);
880 if (NT_STATUS_IS_OK(expected_error)) {
884 printf("tconX to share %s with type %s "
885 "should have succeeded but failed\n",
892 printf("tconx to share %s with type %s "
893 "should have failed but succeeded\n",
897 if (NT_STATUS_EQUAL(cli_nt_error(cli),
901 printf("Returned unexpected error\n");
910 checks for correct tconX support
912 static BOOL run_tcon_devtype_test(int dummy)
914 struct cli_state *cli1 = NULL;
919 char *host = lp_parm_string(-1, "torture", "host");
920 char *share = lp_parm_string(-1, "torture", "share");
921 char *username = lp_parm_string(-1, "torture", "username");
922 char *password = lp_parm_string(-1, "torture", "password");
924 status = cli_full_connection(&cli1, lp_netbios_name(),
927 username, lp_workgroup(),
928 password, flags, &retry);
930 if (!NT_STATUS_IS_OK(status)) {
931 printf("could not open connection\n");
935 if (!tcon_devtest(cli1, "IPC$", "A:", NT_STATUS_BAD_DEVICE_TYPE))
938 if (!tcon_devtest(cli1, "IPC$", "?????", NT_STATUS_OK))
941 if (!tcon_devtest(cli1, "IPC$", "LPT:", NT_STATUS_BAD_DEVICE_TYPE))
944 if (!tcon_devtest(cli1, "IPC$", "IPC", NT_STATUS_OK))
947 if (!tcon_devtest(cli1, "IPC$", "FOOBA", NT_STATUS_BAD_DEVICE_TYPE))
950 if (!tcon_devtest(cli1, share, "A:", NT_STATUS_OK))
953 if (!tcon_devtest(cli1, share, "?????", NT_STATUS_OK))
956 if (!tcon_devtest(cli1, share, "LPT:", NT_STATUS_BAD_DEVICE_TYPE))
959 if (!tcon_devtest(cli1, share, "IPC", NT_STATUS_BAD_DEVICE_TYPE))
962 if (!tcon_devtest(cli1, share, "FOOBA", NT_STATUS_BAD_DEVICE_TYPE))
968 printf("Passed tcondevtest\n");
975 This test checks that
977 1) the server supports multiple locking contexts on the one SMB
978 connection, distinguished by PID.
980 2) the server correctly fails overlapping locks made by the same PID (this
981 goes against POSIX behaviour, which is why it is tricky to implement)
983 3) the server denies unlock requests by an incorrect client PID
985 static BOOL run_locktest2(int dummy)
987 struct cli_state *cli;
988 const char *fname = "\\lockt2.lck";
989 int fnum1, fnum2, fnum3;
992 if (!torture_open_connection(&cli)) {
996 printf("starting locktest2\n");
998 cli_unlink(cli, fname);
1000 printf("Testing pid context\n");
1002 cli->session->pid = 1;
1004 fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1006 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
1010 fnum2 = cli_open(cli, fname, O_RDWR, DENY_NONE);
1012 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli));
1016 cli->session->pid = 2;
1018 fnum3 = cli_open(cli, fname, O_RDWR, DENY_NONE);
1020 printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli));
1024 cli->session->pid = 1;
1026 if (!cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
1027 printf("lock1 failed (%s)\n", cli_errstr(cli));
1031 if (cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
1032 printf("WRITE lock1 succeeded! This is a locking bug\n");
1035 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1036 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1039 if (cli_lock(cli, fnum2, 0, 4, 0, WRITE_LOCK)) {
1040 printf("WRITE lock2 succeeded! This is a locking bug\n");
1043 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1044 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1047 if (cli_lock(cli, fnum2, 0, 4, 0, READ_LOCK)) {
1048 printf("READ lock2 succeeded! This is a locking bug\n");
1051 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1052 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
1055 if (!cli_lock(cli, fnum1, 100, 4, 0, WRITE_LOCK)) {
1056 printf("lock at 100 failed (%s)\n", cli_errstr(cli));
1059 cli->session->pid = 2;
1061 if (cli_unlock(cli, fnum1, 100, 4)) {
1062 printf("unlock at 100 succeeded! This is a locking bug\n");
1066 if (cli_unlock(cli, fnum1, 0, 4)) {
1067 printf("unlock1 succeeded! This is a locking bug\n");
1070 if (!check_error(__LINE__, cli,
1072 NT_STATUS_RANGE_NOT_LOCKED)) return False;
1075 if (cli_unlock(cli, fnum1, 0, 8)) {
1076 printf("unlock2 succeeded! This is a locking bug\n");
1079 if (!check_error(__LINE__, cli,
1081 NT_STATUS_RANGE_NOT_LOCKED)) return False;
1084 if (cli_lock(cli, fnum3, 0, 4, 0, WRITE_LOCK)) {
1085 printf("lock3 succeeded! This is a locking bug\n");
1088 if (!check_error(__LINE__, cli, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
1091 cli->session->pid = 1;
1093 if (!cli_close(cli, fnum1)) {
1094 printf("close1 failed (%s)\n", cli_errstr(cli));
1098 if (!cli_close(cli, fnum2)) {
1099 printf("close2 failed (%s)\n", cli_errstr(cli));
1103 if (!cli_close(cli, fnum3)) {
1104 printf("close3 failed (%s)\n", cli_errstr(cli));
1108 if (!torture_close_connection(cli)) {
1112 printf("locktest2 finished\n");
1119 This test checks that
1121 1) the server supports the full offset range in lock requests
1123 static BOOL run_locktest3(int dummy)
1125 struct cli_state *cli1, *cli2;
1126 const char *fname = "\\lockt3.lck";
1127 int fnum1, fnum2, i;
1129 BOOL correct = True;
1131 #define NEXT_OFFSET offset += (~(uint32)0) / torture_numops
1133 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1137 printf("starting locktest3\n");
1139 printf("Testing 32 bit offset ranges\n");
1141 cli_unlink(cli1, fname);
1143 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1145 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
1148 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1150 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli2));
1154 printf("Establishing %d locks\n", torture_numops);
1156 for (offset=i=0;i<torture_numops;i++) {
1158 if (!cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1159 printf("lock1 %d failed (%s)\n",
1165 if (!cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1166 printf("lock2 %d failed (%s)\n",
1173 printf("Testing %d locks\n", torture_numops);
1175 for (offset=i=0;i<torture_numops;i++) {
1178 if (cli_lock(cli1, fnum1, offset-2, 1, 0, WRITE_LOCK)) {
1179 printf("error: lock1 %d succeeded!\n", i);
1183 if (cli_lock(cli2, fnum2, offset-1, 1, 0, WRITE_LOCK)) {
1184 printf("error: lock2 %d succeeded!\n", i);
1188 if (cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1189 printf("error: lock3 %d succeeded!\n", i);
1193 if (cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1194 printf("error: lock4 %d succeeded!\n", i);
1199 printf("Removing %d locks\n", torture_numops);
1201 for (offset=i=0;i<torture_numops;i++) {
1204 if (!cli_unlock(cli1, fnum1, offset-1, 1)) {
1205 printf("unlock1 %d failed (%s)\n",
1211 if (!cli_unlock(cli2, fnum2, offset-2, 1)) {
1212 printf("unlock2 %d failed (%s)\n",
1219 if (!cli_close(cli1, fnum1)) {
1220 printf("close1 failed (%s)\n", cli_errstr(cli1));
1224 if (!cli_close(cli2, fnum2)) {
1225 printf("close2 failed (%s)\n", cli_errstr(cli2));
1229 if (!cli_unlink(cli1, fname)) {
1230 printf("unlink failed (%s)\n", cli_errstr(cli1));
1234 if (!torture_close_connection(cli1)) {
1238 if (!torture_close_connection(cli2)) {
1242 printf("finished locktest3\n");
1247 #define EXPECTED(ret, v) if ((ret) != (v)) { \
1248 printf("** "); correct = False; \
1252 looks at overlapping locks
1254 static BOOL run_locktest4(int dummy)
1256 struct cli_state *cli1, *cli2;
1257 const char *fname = "\\lockt4.lck";
1258 int fnum1, fnum2, f;
1261 BOOL correct = True;
1263 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1267 printf("starting locktest4\n");
1269 cli_unlink(cli1, fname);
1271 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1272 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1274 memset(buf, 0, sizeof(buf));
1276 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1277 printf("Failed to create file\n");
1282 ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1283 cli_lock(cli1, fnum1, 2, 4, 0, WRITE_LOCK);
1284 EXPECTED(ret, False);
1285 printf("the same process %s set overlapping write locks\n", ret?"can":"cannot");
1287 ret = cli_lock(cli1, fnum1, 10, 4, 0, READ_LOCK) &&
1288 cli_lock(cli1, fnum1, 12, 4, 0, READ_LOCK);
1289 EXPECTED(ret, True);
1290 printf("the same process %s set overlapping read locks\n", ret?"can":"cannot");
1292 ret = cli_lock(cli1, fnum1, 20, 4, 0, WRITE_LOCK) &&
1293 cli_lock(cli2, fnum2, 22, 4, 0, WRITE_LOCK);
1294 EXPECTED(ret, False);
1295 printf("a different connection %s set overlapping write locks\n", ret?"can":"cannot");
1297 ret = cli_lock(cli1, fnum1, 30, 4, 0, READ_LOCK) &&
1298 cli_lock(cli2, fnum2, 32, 4, 0, READ_LOCK);
1299 EXPECTED(ret, True);
1300 printf("a different connection %s set overlapping read locks\n", ret?"can":"cannot");
1302 ret = (cli1->session->pid = 1, cli_lock(cli1, fnum1, 40, 4, 0, WRITE_LOCK)) &&
1303 (cli1->session->pid = 2, cli_lock(cli1, fnum1, 42, 4, 0, WRITE_LOCK));
1304 EXPECTED(ret, False);
1305 printf("a different pid %s set overlapping write locks\n", ret?"can":"cannot");
1307 ret = (cli1->session->pid = 1, cli_lock(cli1, fnum1, 50, 4, 0, READ_LOCK)) &&
1308 (cli1->session->pid = 2, cli_lock(cli1, fnum1, 52, 4, 0, READ_LOCK));
1309 EXPECTED(ret, True);
1310 printf("a different pid %s set overlapping read locks\n", ret?"can":"cannot");
1312 ret = cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK) &&
1313 cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK);
1314 EXPECTED(ret, True);
1315 printf("the same process %s set the same read lock twice\n", ret?"can":"cannot");
1317 ret = cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK) &&
1318 cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK);
1319 EXPECTED(ret, False);
1320 printf("the same process %s set the same write lock twice\n", ret?"can":"cannot");
1322 ret = cli_lock(cli1, fnum1, 80, 4, 0, READ_LOCK) &&
1323 cli_lock(cli1, fnum1, 80, 4, 0, WRITE_LOCK);
1324 EXPECTED(ret, False);
1325 printf("the same process %s overlay a read lock with a write lock\n", ret?"can":"cannot");
1327 ret = cli_lock(cli1, fnum1, 90, 4, 0, WRITE_LOCK) &&
1328 cli_lock(cli1, fnum1, 90, 4, 0, READ_LOCK);
1329 EXPECTED(ret, True);
1330 printf("the same process %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1332 ret = (cli1->session->pid = 1, cli_lock(cli1, fnum1, 100, 4, 0, WRITE_LOCK)) &&
1333 (cli1->session->pid = 2, cli_lock(cli1, fnum1, 100, 4, 0, READ_LOCK));
1334 EXPECTED(ret, False);
1335 printf("a different pid %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1337 ret = cli_lock(cli1, fnum1, 110, 4, 0, READ_LOCK) &&
1338 cli_lock(cli1, fnum1, 112, 4, 0, READ_LOCK) &&
1339 cli_unlock(cli1, fnum1, 110, 6);
1340 EXPECTED(ret, False);
1341 printf("the same process %s coalesce read locks\n", ret?"can":"cannot");
1344 ret = cli_lock(cli1, fnum1, 120, 4, 0, WRITE_LOCK) &&
1345 (cli_read(cli2, fnum2, buf, 120, 4) == 4);
1346 EXPECTED(ret, False);
1347 printf("this server %s strict write locking\n", ret?"doesn't do":"does");
1349 ret = cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK) &&
1350 (cli_write(cli2, fnum2, 0, buf, 130, 4) == 4);
1351 EXPECTED(ret, False);
1352 printf("this server %s strict read locking\n", ret?"doesn't do":"does");
1355 ret = cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1356 cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1357 cli_unlock(cli1, fnum1, 140, 4) &&
1358 cli_unlock(cli1, fnum1, 140, 4);
1359 EXPECTED(ret, True);
1360 printf("this server %s do recursive read locking\n", ret?"does":"doesn't");
1363 ret = cli_lock(cli1, fnum1, 150, 4, 0, WRITE_LOCK) &&
1364 cli_lock(cli1, fnum1, 150, 4, 0, READ_LOCK) &&
1365 cli_unlock(cli1, fnum1, 150, 4) &&
1366 (cli_read(cli2, fnum2, buf, 150, 4) == 4) &&
1367 !(cli_write(cli2, fnum2, 0, buf, 150, 4) == 4) &&
1368 cli_unlock(cli1, fnum1, 150, 4);
1369 EXPECTED(ret, True);
1370 printf("this server %s do recursive lock overlays\n", ret?"does":"doesn't");
1372 ret = cli_lock(cli1, fnum1, 160, 4, 0, READ_LOCK) &&
1373 cli_unlock(cli1, fnum1, 160, 4) &&
1374 (cli_write(cli2, fnum2, 0, buf, 160, 4) == 4) &&
1375 (cli_read(cli2, fnum2, buf, 160, 4) == 4);
1376 EXPECTED(ret, True);
1377 printf("the same process %s remove a read lock using write locking\n", ret?"can":"cannot");
1379 ret = cli_lock(cli1, fnum1, 170, 4, 0, WRITE_LOCK) &&
1380 cli_unlock(cli1, fnum1, 170, 4) &&
1381 (cli_write(cli2, fnum2, 0, buf, 170, 4) == 4) &&
1382 (cli_read(cli2, fnum2, buf, 170, 4) == 4);
1383 EXPECTED(ret, True);
1384 printf("the same process %s remove a write lock using read locking\n", ret?"can":"cannot");
1386 ret = cli_lock(cli1, fnum1, 190, 4, 0, WRITE_LOCK) &&
1387 cli_lock(cli1, fnum1, 190, 4, 0, READ_LOCK) &&
1388 cli_unlock(cli1, fnum1, 190, 4) &&
1389 !(cli_write(cli2, fnum2, 0, buf, 190, 4) == 4) &&
1390 (cli_read(cli2, fnum2, buf, 190, 4) == 4);
1391 EXPECTED(ret, True);
1392 printf("the same process %s remove the first lock first\n", ret?"does":"doesn't");
1394 cli_close(cli1, fnum1);
1395 cli_close(cli2, fnum2);
1396 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1397 f = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1398 ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1399 cli_lock(cli1, f, 0, 1, 0, READ_LOCK) &&
1400 cli_close(cli1, fnum1) &&
1401 ((fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE)) != -1) &&
1402 cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1404 cli_close(cli1, fnum1);
1405 EXPECTED(ret, True);
1406 printf("the server %s have the NT byte range lock bug\n", !ret?"does":"doesn't");
1409 cli_close(cli1, fnum1);
1410 cli_close(cli2, fnum2);
1411 cli_unlink(cli1, fname);
1412 torture_close_connection(cli1);
1413 torture_close_connection(cli2);
1415 printf("finished locktest4\n");
1420 looks at lock upgrade/downgrade.
1422 static BOOL run_locktest5(int dummy)
1424 struct cli_state *cli1, *cli2;
1425 const char *fname = "\\lockt5.lck";
1426 int fnum1, fnum2, fnum3;
1429 BOOL correct = True;
1431 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1435 printf("starting locktest5\n");
1437 cli_unlink(cli1, fname);
1439 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1440 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1441 fnum3 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1443 memset(buf, 0, sizeof(buf));
1445 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1446 printf("Failed to create file\n");
1451 /* Check for NT bug... */
1452 ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1453 cli_lock(cli1, fnum3, 0, 1, 0, READ_LOCK);
1454 cli_close(cli1, fnum1);
1455 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1456 ret = cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1457 EXPECTED(ret, True);
1458 printf("this server %s the NT locking bug\n", ret ? "doesn't have" : "has");
1459 cli_close(cli1, fnum1);
1460 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1461 cli_unlock(cli1, fnum3, 0, 1);
1463 ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1464 cli_lock(cli1, fnum1, 1, 1, 0, READ_LOCK);
1465 EXPECTED(ret, True);
1466 printf("the same process %s overlay a write with a read lock\n", ret?"can":"cannot");
1468 ret = cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK);
1469 EXPECTED(ret, False);
1471 printf("a different processs %s get a read lock on the first process lock stack\n", ret?"can":"cannot");
1473 /* Unlock the process 2 lock. */
1474 cli_unlock(cli2, fnum2, 0, 4);
1476 ret = cli_lock(cli1, fnum3, 0, 4, 0, READ_LOCK);
1477 EXPECTED(ret, False);
1479 printf("the same processs on a different fnum %s get a read lock\n", ret?"can":"cannot");
1481 /* Unlock the process 1 fnum3 lock. */
1482 cli_unlock(cli1, fnum3, 0, 4);
1484 /* Stack 2 more locks here. */
1485 ret = cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK) &&
1486 cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK);
1488 EXPECTED(ret, True);
1489 printf("the same process %s stack read locks\n", ret?"can":"cannot");
1491 /* Unlock the first process lock, then check this was the WRITE lock that was
1494 ret = cli_unlock(cli1, fnum1, 0, 4) &&
1495 cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK);
1497 EXPECTED(ret, True);
1498 printf("the first unlock removes the %s lock\n", ret?"WRITE":"READ");
1500 /* Unlock the process 2 lock. */
1501 cli_unlock(cli2, fnum2, 0, 4);
1503 /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */
1505 ret = cli_unlock(cli1, fnum1, 1, 1) &&
1506 cli_unlock(cli1, fnum1, 0, 4) &&
1507 cli_unlock(cli1, fnum1, 0, 4);
1509 EXPECTED(ret, True);
1510 printf("the same process %s unlock the stack of 4 locks\n", ret?"can":"cannot");
1512 /* Ensure the next unlock fails. */
1513 ret = cli_unlock(cli1, fnum1, 0, 4);
1514 EXPECTED(ret, False);
1515 printf("the same process %s count the lock stack\n", !ret?"can":"cannot");
1517 /* Ensure connection 2 can get a write lock. */
1518 ret = cli_lock(cli2, fnum2, 0, 4, 0, WRITE_LOCK);
1519 EXPECTED(ret, True);
1521 printf("a different processs %s get a write lock on the unlocked stack\n", ret?"can":"cannot");
1525 cli_close(cli1, fnum1);
1526 cli_close(cli2, fnum2);
1527 cli_unlink(cli1, fname);
1528 if (!torture_close_connection(cli1)) {
1531 if (!torture_close_connection(cli2)) {
1535 printf("finished locktest5\n");
1541 tries the unusual lockingX locktype bits
1543 static BOOL run_locktest6(int dummy)
1545 struct cli_state *cli;
1546 const char *fname[1] = { "\\lock6.txt" };
1551 if (!torture_open_connection(&cli)) {
1555 printf("starting locktest6\n");
1558 printf("Testing %s\n", fname[i]);
1560 cli_unlink(cli, fname[i]);
1562 fnum = cli_open(cli, fname[i], O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1563 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE);
1564 cli_close(cli, fnum);
1565 printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status));
1567 fnum = cli_open(cli, fname[i], O_RDWR, DENY_NONE);
1568 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK);
1569 cli_close(cli, fnum);
1570 printf("CANCEL_LOCK gave %s\n", nt_errstr(status));
1572 cli_unlink(cli, fname[i]);
1575 torture_close_connection(cli);
1577 printf("finished locktest6\n");
1581 static BOOL run_locktest7(int dummy)
1583 struct cli_state *cli1;
1584 const char *fname = "\\lockt7.lck";
1587 BOOL correct = False;
1589 if (!torture_open_connection(&cli1)) {
1593 printf("starting locktest7\n");
1595 cli_unlink(cli1, fname);
1597 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1599 memset(buf, 0, sizeof(buf));
1601 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1602 printf("Failed to create file\n");
1606 cli1->session->pid = 1;
1608 if (!cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK)) {
1609 printf("Unable to apply read lock on range 130:4, error was %s\n", cli_errstr(cli1));
1612 printf("pid1 successfully locked range 130:4 for READ\n");
1615 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1616 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1619 printf("pid1 successfully read the range 130:4\n");
1622 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1623 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1624 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1625 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1629 printf("pid1 successfully wrote to the range 130:4 (should be denied)\n");
1633 cli1->session->pid = 2;
1635 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1636 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1638 printf("pid2 successfully read the range 130:4\n");
1641 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1642 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1643 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1644 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1648 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
1652 cli1->session->pid = 1;
1653 cli_unlock(cli1, fnum1, 130, 4);
1655 if (!cli_lock(cli1, fnum1, 130, 4, 0, WRITE_LOCK)) {
1656 printf("Unable to apply write lock on range 130:4, error was %s\n", cli_errstr(cli1));
1659 printf("pid1 successfully locked range 130:4 for WRITE\n");
1662 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1663 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1666 printf("pid1 successfully read the range 130:4\n");
1669 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1670 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1673 printf("pid1 successfully wrote to the range 130:4\n");
1676 cli1->session->pid = 2;
1678 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1679 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1680 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1681 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1685 printf("pid2 successfully read the range 130:4 (should be denied)\n");
1689 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1690 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1691 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1692 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1696 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
1700 cli_unlock(cli1, fnum1, 130, 0);
1704 cli_close(cli1, fnum1);
1705 cli_unlink(cli1, fname);
1706 torture_close_connection(cli1);
1708 printf("finished locktest7\n");
1713 test whether fnums and tids open on one VC are available on another (a major
1716 static BOOL run_fdpasstest(int dummy)
1718 struct cli_state *cli1, *cli2;
1719 const char *fname = "\\fdpass.tst";
1723 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1727 printf("starting fdpasstest\n");
1729 cli_unlink(cli1, fname);
1731 printf("Opening a file on connection 1\n");
1733 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1735 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
1739 printf("writing to file on connection 1\n");
1741 if (cli_write(cli1, fnum1, 0, "hello world\n", 0, 13) != 13) {
1742 printf("write failed (%s)\n", cli_errstr(cli1));
1746 oldtid = cli2->tree->tid;
1747 cli2->session->vuid = cli1->session->vuid;
1748 cli2->tree->tid = cli1->tree->tid;
1749 cli2->session->pid = cli1->session->pid;
1751 printf("reading from file on connection 2\n");
1753 if (cli_read(cli2, fnum1, buf, 0, 13) == 13) {
1754 printf("read succeeded! nasty security hole [%s]\n",
1759 cli_close(cli1, fnum1);
1760 cli_unlink(cli1, fname);
1762 cli2->tree->tid = oldtid;
1764 torture_close_connection(cli1);
1765 torture_close_connection(cli2);
1767 printf("finished fdpasstest\n");
1773 This test checks that
1775 1) the server does not allow an unlink on a file that is open
1777 static BOOL run_unlinktest(int dummy)
1779 struct cli_state *cli;
1780 const char *fname = "\\unlink.tst";
1782 BOOL correct = True;
1784 if (!torture_open_connection(&cli)) {
1788 printf("starting unlink test\n");
1790 cli_unlink(cli, fname);
1792 cli->session->pid = 1;
1794 printf("Opening a file\n");
1796 fnum = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1798 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
1802 printf("Unlinking a open file\n");
1804 if (cli_unlink(cli, fname)) {
1805 printf("error: server allowed unlink on an open file\n");
1808 correct = check_error(__LINE__, cli, ERRDOS, ERRbadshare,
1809 NT_STATUS_SHARING_VIOLATION);
1812 cli_close(cli, fnum);
1813 cli_unlink(cli, fname);
1815 if (!torture_close_connection(cli)) {
1819 printf("unlink test finished\n");
1826 test how many open files this server supports on the one socket
1828 static BOOL run_maxfidtest(int dummy)
1830 struct cli_state *cli;
1831 const char *template = "\\maxfid.%d.%d";
1833 int fnums[0x11000], i;
1835 BOOL correct = True;
1840 printf("failed to connect\n");
1844 printf("Testing maximum number of open files\n");
1846 for (i=0; i<0x11000; i++) {
1847 asprintf(&fname, template, i,(int)getpid());
1848 if ((fnums[i] = cli_open(cli, fname,
1849 O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) ==
1851 printf("open of %s failed (%s)\n",
1852 fname, cli_errstr(cli));
1853 printf("maximum fnum is %d\n", i);
1862 printf("cleaning up\n");
1864 asprintf(&fname, template, i,(int)getpid());
1865 if (!cli_close(cli, fnums[i])) {
1866 printf("Close of fnum %d failed - %s\n", fnums[i], cli_errstr(cli));
1868 if (!cli_unlink(cli, fname)) {
1869 printf("unlink of %s failed (%s)\n",
1870 fname, cli_errstr(cli));
1878 printf("maxfid test finished\n");
1879 if (!torture_close_connection(cli)) {
1885 /* send smb negprot commands, not reading the response */
1886 static BOOL run_negprot_nowait(int dummy)
1889 struct cli_state *cli;
1890 BOOL correct = True;
1892 printf("starting negprot nowait test\n");
1894 cli = open_nbt_connection();
1899 printf("Establishing protocol negotiations - connect with another client\n");
1901 for (i=0;i<50000;i++) {
1902 smb_negprot_send(cli->transport, PROTOCOL_NT1);
1905 if (!torture_close_connection(cli)) {
1909 printf("finished negprot nowait test\n");
1916 This checks how the getatr calls works
1918 static BOOL run_attrtest(int dummy)
1920 struct cli_state *cli;
1923 const char *fname = "\\attrib123456789.tst";
1924 BOOL correct = True;
1926 printf("starting attrib test\n");
1928 if (!torture_open_connection(&cli)) {
1932 cli_unlink(cli, fname);
1933 fnum = cli_open(cli, fname,
1934 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1935 cli_close(cli, fnum);
1937 if (!cli_getatr(cli, fname, NULL, NULL, &t)) {
1938 printf("getatr failed (%s)\n", cli_errstr(cli));
1942 printf("New file time is %s", ctime(&t));
1944 if (abs(t - time(NULL)) > 60*60*24*10) {
1945 printf("ERROR: SMBgetatr bug. time is %s",
1951 t2 = t-60*60*24; /* 1 day ago */
1953 printf("Setting file time to %s", ctime(&t2));
1955 if (!cli_setatr(cli, fname, 0, t2)) {
1956 printf("setatr failed (%s)\n", cli_errstr(cli));
1960 if (!cli_getatr(cli, fname, NULL, NULL, &t)) {
1961 printf("getatr failed (%s)\n", cli_errstr(cli));
1965 printf("Retrieved file time as %s", ctime(&t));
1968 printf("ERROR: getatr/setatr bug. times are\n%s",
1970 printf("%s", ctime(&t2));
1974 cli_unlink(cli, fname);
1976 if (!torture_close_connection(cli)) {
1980 printf("attrib test finished\n");
1987 This checks a couple of trans2 calls
1989 static BOOL run_trans2test(int dummy)
1991 struct cli_state *cli;
1994 time_t c_time, a_time, m_time, w_time, m_time2;
1995 const char *fname = "\\trans2.tst";
1996 const char *dname = "\\trans2";
1997 const char *fname2 = "\\trans2\\trans2.tst";
1999 BOOL correct = True;
2001 printf("starting trans2 test\n");
2003 if (!torture_open_connection(&cli)) {
2007 cli_unlink(cli, fname);
2009 printf("Testing qfileinfo\n");
2011 fnum = cli_open(cli, fname,
2012 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2013 if (!cli_qfileinfo(cli, fnum, NULL, &size, &c_time, &a_time, &m_time,
2015 printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(cli));
2019 printf("Testing NAME_INFO\n");
2021 if (!cli_qfilename(cli, fnum, &pname)) {
2022 printf("ERROR: qfilename failed (%s)\n", cli_errstr(cli));
2026 if (!pname || strcmp(pname, fname)) {
2027 printf("qfilename gave different name? [%s] [%s]\n",
2032 cli_close(cli, fnum);
2033 cli_unlink(cli, fname);
2035 fnum = cli_open(cli, fname,
2036 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2038 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
2041 cli_close(cli, fnum);
2043 printf("Checking for sticky create times\n");
2045 if (!cli_qpathinfo(cli, fname, &c_time, &a_time, &m_time, &size, NULL)) {
2046 printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(cli));
2049 if (c_time != m_time) {
2050 printf("create time=%s", ctime(&c_time));
2051 printf("modify time=%s", ctime(&m_time));
2052 printf("This system appears to have sticky create times\n");
2054 if (a_time % (60*60) == 0) {
2055 printf("access time=%s", ctime(&a_time));
2056 printf("This system appears to set a midnight access time\n");
2060 if (abs(m_time - time(NULL)) > 60*60*24*7) {
2061 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
2067 cli_unlink(cli, fname);
2068 fnum = cli_open(cli, fname,
2069 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2070 cli_close(cli, fnum);
2071 if (!cli_qpathinfo2(cli, fname, &c_time, &a_time, &m_time,
2072 &w_time, &size, NULL, NULL)) {
2073 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2076 if (w_time < 60*60*24*2) {
2077 printf("write time=%s", ctime(&w_time));
2078 printf("This system appears to set a initial 0 write time\n");
2083 cli_unlink(cli, fname);
2086 /* check if the server updates the directory modification time
2087 when creating a new file */
2088 if (!cli_mkdir(cli, dname)) {
2089 printf("ERROR: mkdir failed (%s)\n", cli_errstr(cli));
2093 if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time, &a_time, &m_time,
2094 &w_time, &size, NULL, NULL)) {
2095 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2099 fnum = cli_open(cli, fname2,
2100 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2101 cli_write(cli, fnum, 0, (char *)&fnum, 0, sizeof(fnum));
2102 cli_close(cli, fnum);
2103 if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time, &a_time, &m_time2,
2104 &w_time, &size, NULL, NULL)) {
2105 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2108 if (m_time2 == m_time) {
2109 printf("This system does not update directory modification times\n");
2113 cli_unlink(cli, fname2);
2114 cli_rmdir(cli, dname);
2116 if (!torture_close_connection(cli)) {
2120 printf("trans2 test finished\n");
2126 Test delete on close semantics.
2128 static BOOL run_deletetest(int dummy)
2130 struct cli_state *cli1;
2131 struct cli_state *cli2 = NULL;
2132 const char *fname = "\\delete.file";
2135 BOOL correct = True;
2137 printf("starting delete test\n");
2139 if (!torture_open_connection(&cli1)) {
2143 /* Test 1 - this should delete the file on close. */
2145 cli_setatr(cli1, fname, 0, 0);
2146 cli_unlink(cli1, fname);
2148 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2149 NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OVERWRITE_IF,
2150 NTCREATEX_OPTIONS_DELETE_ON_CLOSE, 0);
2153 printf("[1] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2158 if (!cli_close(cli1, fnum1)) {
2159 printf("[1] close failed (%s)\n", cli_errstr(cli1));
2164 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
2166 printf("[1] open of %s succeeded (should fail)\n", fname);
2171 printf("first delete on close test succeeded.\n");
2173 /* Test 2 - this should delete the file on close. */
2175 cli_setatr(cli1, fname, 0, 0);
2176 cli_unlink(cli1, fname);
2178 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_ALL_ACCESS,
2179 FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_NONE,
2180 NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2183 printf("[2] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2188 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
2189 printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
2194 if (!cli_close(cli1, fnum1)) {
2195 printf("[2] close failed (%s)\n", cli_errstr(cli1));
2200 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
2202 printf("[2] open of %s succeeded should have been deleted on close !\n", fname);
2203 if (!cli_close(cli1, fnum1)) {
2204 printf("[2] close failed (%s)\n", cli_errstr(cli1));
2208 cli_unlink(cli1, fname);
2210 printf("second delete on close test succeeded.\n");
2213 cli_setatr(cli1, fname, 0, 0);
2214 cli_unlink(cli1, fname);
2216 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2217 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2220 printf("[3] open - 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
2225 /* This should fail with a sharing violation - open for delete is only compatible
2226 with SHARE_DELETE. */
2228 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_READ, FILE_ATTRIBUTE_NORMAL,
2229 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE,
2230 NTCREATEX_DISP_OPEN, 0, 0);
2233 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname);
2238 /* This should succeed. */
2240 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_READ, FILE_ATTRIBUTE_NORMAL,
2241 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN, 0, 0);
2244 printf("[3] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
2249 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
2250 printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
2255 if (!cli_close(cli1, fnum1)) {
2256 printf("[3] close 1 failed (%s)\n", cli_errstr(cli1));
2261 if (!cli_close(cli1, fnum2)) {
2262 printf("[3] close 2 failed (%s)\n", cli_errstr(cli1));
2267 /* This should fail - file should no longer be there. */
2269 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
2271 printf("[3] open of %s succeeded should have been deleted on close !\n", fname);
2272 if (!cli_close(cli1, fnum1)) {
2273 printf("[3] close failed (%s)\n", cli_errstr(cli1));
2275 cli_unlink(cli1, fname);
2279 printf("third delete on close test succeeded.\n");
2282 cli_setatr(cli1, fname, 0, 0);
2283 cli_unlink(cli1, fname);
2285 fnum1 = cli_nt_create_full(cli1, fname, 0,
2286 SA_RIGHT_FILE_READ_DATA |
2287 SA_RIGHT_FILE_WRITE_DATA |
2288 STD_RIGHT_DELETE_ACCESS,
2289 FILE_ATTRIBUTE_NORMAL,
2290 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE,
2291 NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2294 printf("[4] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2299 /* This should succeed. */
2300 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_READ,
2301 FILE_ATTRIBUTE_NORMAL,
2302 NTCREATEX_SHARE_ACCESS_READ |
2303 NTCREATEX_SHARE_ACCESS_WRITE |
2304 NTCREATEX_SHARE_ACCESS_DELETE,
2305 NTCREATEX_DISP_OPEN, 0, 0);
2307 printf("[4] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
2312 if (!cli_close(cli1, fnum2)) {
2313 printf("[4] close - 1 failed (%s)\n", cli_errstr(cli1));
2318 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
2319 printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
2324 /* This should fail - no more opens once delete on close set. */
2325 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_READ,
2326 FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE,
2327 NTCREATEX_DISP_OPEN, 0, 0);
2329 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname );
2333 printf("fourth delete on close test succeeded.\n");
2335 if (!cli_close(cli1, fnum1)) {
2336 printf("[4] close - 2 failed (%s)\n", cli_errstr(cli1));
2342 cli_setatr(cli1, fname, 0, 0);
2343 cli_unlink(cli1, fname);
2345 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT, DENY_NONE);
2347 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2352 /* This should fail - only allowed on NT opens with DELETE access. */
2354 if (cli_nt_delete_on_close(cli1, fnum1, True)) {
2355 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
2360 if (!cli_close(cli1, fnum1)) {
2361 printf("[5] close - 2 failed (%s)\n", cli_errstr(cli1));
2366 printf("fifth delete on close test succeeded.\n");
2369 cli_setatr(cli1, fname, 0, 0);
2370 cli_unlink(cli1, fname);
2372 fnum1 = cli_nt_create_full(cli1, fname, 0,
2373 SA_RIGHT_FILE_READ_DATA | SA_RIGHT_FILE_WRITE_DATA,
2374 FILE_ATTRIBUTE_NORMAL,
2375 NTCREATEX_SHARE_ACCESS_READ |
2376 NTCREATEX_SHARE_ACCESS_WRITE |
2377 NTCREATEX_SHARE_ACCESS_DELETE,
2378 NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2381 printf("[6] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2386 /* This should fail - only allowed on NT opens with DELETE access. */
2388 if (cli_nt_delete_on_close(cli1, fnum1, True)) {
2389 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
2394 if (!cli_close(cli1, fnum1)) {
2395 printf("[6] close - 2 failed (%s)\n", cli_errstr(cli1));
2400 printf("sixth delete on close test succeeded.\n");
2403 cli_setatr(cli1, fname, 0, 0);
2404 cli_unlink(cli1, fname);
2406 fnum1 = cli_nt_create_full(cli1, fname, 0,
2407 SA_RIGHT_FILE_READ_DATA |
2408 SA_RIGHT_FILE_WRITE_DATA |
2409 STD_RIGHT_DELETE_ACCESS,
2410 FILE_ATTRIBUTE_NORMAL, 0, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2413 printf("[7] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2418 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
2419 printf("[7] setting delete_on_close on file failed !\n");
2424 if (!cli_nt_delete_on_close(cli1, fnum1, False)) {
2425 printf("[7] unsetting delete_on_close on file failed !\n");
2430 if (!cli_close(cli1, fnum1)) {
2431 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
2436 /* This next open should succeed - we reset the flag. */
2438 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
2440 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2445 if (!cli_close(cli1, fnum1)) {
2446 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
2451 printf("seventh delete on close test succeeded.\n");
2454 cli_setatr(cli1, fname, 0, 0);
2455 cli_unlink(cli1, fname);
2457 if (!torture_open_connection(&cli2)) {
2458 printf("[8] failed to open second connection.\n");
2463 fnum1 = cli_nt_create_full(cli1, fname, 0, SA_RIGHT_FILE_READ_DATA|SA_RIGHT_FILE_WRITE_DATA|STD_RIGHT_DELETE_ACCESS,
2464 FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE,
2465 NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2468 printf("[8] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2473 fnum2 = cli_nt_create_full(cli2, fname, 0, SA_RIGHT_FILE_READ_DATA|SA_RIGHT_FILE_WRITE_DATA|STD_RIGHT_DELETE_ACCESS,
2474 FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE,
2475 NTCREATEX_DISP_OPEN, 0, 0);
2478 printf("[8] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2483 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
2484 printf("[8] setting delete_on_close on file failed !\n");
2489 if (!cli_close(cli1, fnum1)) {
2490 printf("[8] close - 1 failed (%s)\n", cli_errstr(cli1));
2495 if (!cli_close(cli2, fnum2)) {
2496 printf("[8] close - 2 failed (%s)\n", cli_errstr(cli2));
2501 /* This should fail.. */
2502 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
2504 printf("[8] open of %s succeeded should have been deleted on close !\n", fname);
2508 printf("eighth delete on close test succeeded.\n");
2510 /* This should fail - we need to set DELETE_ACCESS. */
2511 fnum1 = cli_nt_create_full(cli1, fname, 0,SA_RIGHT_FILE_READ_DATA|SA_RIGHT_FILE_WRITE_DATA,
2512 FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, NTCREATEX_OPTIONS_DELETE_ON_CLOSE, 0);
2515 printf("[9] open of %s succeeded should have failed!\n", fname);
2520 printf("ninth delete on close test succeeded.\n");
2522 fnum1 = cli_nt_create_full(cli1, fname, 0, SA_RIGHT_FILE_READ_DATA|SA_RIGHT_FILE_WRITE_DATA|STD_RIGHT_DELETE_ACCESS,
2523 FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, NTCREATEX_OPTIONS_DELETE_ON_CLOSE, 0);
2525 printf("[10] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2530 /* This should delete the file. */
2531 if (!cli_close(cli1, fnum1)) {
2532 printf("[10] close failed (%s)\n", cli_errstr(cli1));
2537 /* This should fail.. */
2538 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
2540 printf("[10] open of %s succeeded should have been deleted on close !\n", fname);
2544 printf("tenth delete on close test succeeded.\n");
2545 printf("finished delete test\n");
2548 /* FIXME: This will crash if we aborted before cli2 got
2549 * intialized, because these functions don't handle
2550 * uninitialized connections. */
2552 cli_close(cli1, fnum1);
2553 cli_close(cli1, fnum2);
2554 cli_setatr(cli1, fname, 0, 0);
2555 cli_unlink(cli1, fname);
2557 if (!torture_close_connection(cli1)) {
2560 if (!torture_close_connection(cli2)) {
2568 print out server properties
2570 static BOOL run_properties(int dummy)
2572 struct cli_state *cli;
2573 BOOL correct = True;
2575 printf("starting properties test\n");
2579 if (!torture_open_connection(&cli)) {
2583 d_printf("Capabilities 0x%08x\n", cli->transport->negotiate.capabilities);
2585 if (!torture_close_connection(cli)) {
2594 /* FIRST_DESIRED_ACCESS 0xf019f */
2595 #define FIRST_DESIRED_ACCESS SA_RIGHT_FILE_READ_DATA|SA_RIGHT_FILE_WRITE_DATA|SA_RIGHT_FILE_APPEND_DATA|\
2596 SA_RIGHT_FILE_READ_EA| /* 0xf */ \
2597 SA_RIGHT_FILE_WRITE_EA|SA_RIGHT_FILE_READ_ATTRIBUTES| /* 0x90 */ \
2598 SA_RIGHT_FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
2599 STD_RIGHT_DELETE_ACCESS|STD_RIGHT_READ_CONTROL_ACCESS|\
2600 STD_RIGHT_WRITE_DAC_ACCESS|STD_RIGHT_WRITE_OWNER_ACCESS /* 0xf0000 */
2601 /* SECOND_DESIRED_ACCESS 0xe0080 */
2602 #define SECOND_DESIRED_ACCESS SA_RIGHT_FILE_READ_ATTRIBUTES| /* 0x80 */ \
2603 STD_RIGHT_READ_CONTROL_ACCESS|STD_RIGHT_WRITE_DAC_ACCESS|\
2604 STD_RIGHT_WRITE_OWNER_ACCESS /* 0xe0000 */
2607 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
2608 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
2609 SA_RIGHT_FILE_READ_DATA|\
2610 WRITE_OWNER_ACCESS /* */
2614 Test ntcreate calls made by xcopy
2616 static BOOL run_xcopy(int dummy)
2618 struct cli_state *cli1;
2619 const char *fname = "\\test.txt";
2620 BOOL correct = True;
2623 printf("starting xcopy test\n");
2625 if (!torture_open_connection(&cli1)) {
2629 fnum1 = cli_nt_create_full(cli1, fname, 0,
2630 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
2631 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF,
2635 printf("First open failed - %s\n", cli_errstr(cli1));
2639 fnum2 = cli_nt_create_full(cli1, fname, 0,
2640 SECOND_DESIRED_ACCESS, 0,
2641 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN,
2644 printf("second open failed - %s\n", cli_errstr(cli1));
2648 if (!torture_close_connection(cli1)) {
2656 Test rename on files open with share delete and no share delete.
2658 static BOOL run_rename(int dummy)
2660 struct cli_state *cli1;
2661 const char *fname = "\\test.txt";
2662 const char *fname1 = "\\test1.txt";
2663 BOOL correct = True;
2666 printf("starting rename test\n");
2668 if (!torture_open_connection(&cli1)) {
2672 cli_unlink(cli1, fname);
2673 cli_unlink(cli1, fname1);
2674 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_READ, FILE_ATTRIBUTE_NORMAL,
2675 NTCREATEX_SHARE_ACCESS_READ, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2678 printf("First open failed - %s\n", cli_errstr(cli1));
2682 if (!cli_rename(cli1, fname, fname1)) {
2683 printf("First rename failed (this is correct) - %s\n", cli_errstr(cli1));
2685 printf("First rename succeeded - this should have failed !\n");
2689 if (!cli_close(cli1, fnum1)) {
2690 printf("close - 1 failed (%s)\n", cli_errstr(cli1));
2694 cli_unlink(cli1, fname);
2695 cli_unlink(cli1, fname1);
2696 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_READ, FILE_ATTRIBUTE_NORMAL,
2698 NTCREATEX_SHARE_ACCESS_DELETE|NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2700 NTCREATEX_SHARE_ACCESS_DELETE|NTCREATEX_SHARE_ACCESS_READ, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2704 printf("Second open failed - %s\n", cli_errstr(cli1));
2708 if (!cli_rename(cli1, fname, fname1)) {
2709 printf("Second rename failed - this should have succeeded - %s\n", cli_errstr(cli1));
2712 printf("Second rename succeeded\n");
2715 if (!cli_close(cli1, fnum1)) {
2716 printf("close - 2 failed (%s)\n", cli_errstr(cli1));
2720 cli_unlink(cli1, fname);
2721 cli_unlink(cli1, fname1);
2723 fnum1 = cli_nt_create_full(cli1, fname, 0, STD_RIGHT_READ_CONTROL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2724 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2727 printf("Third open failed - %s\n", cli_errstr(cli1));
2736 fnum2 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
2737 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2740 printf("Fourth open failed - %s\n", cli_errstr(cli1));
2743 if (!cli_nt_delete_on_close(cli1, fnum2, True)) {
2744 printf("[8] setting delete_on_close on file failed !\n");
2748 if (!cli_close(cli1, fnum2)) {
2749 printf("close - 4 failed (%s)\n", cli_errstr(cli1));
2755 if (!cli_rename(cli1, fname, fname1)) {
2756 printf("Third rename failed - this should have succeeded - %s\n", cli_errstr(cli1));
2759 printf("Third rename succeeded\n");
2762 if (!cli_close(cli1, fnum1)) {
2763 printf("close - 3 failed (%s)\n", cli_errstr(cli1));
2767 cli_unlink(cli1, fname);
2768 cli_unlink(cli1, fname1);
2770 if (!torture_close_connection(cli1)) {
2777 static BOOL run_pipe_number(int dummy)
2779 struct cli_state *cli1;
2780 const char *pipe_name = "\\SPOOLSS";
2784 printf("starting pipenumber test\n");
2785 if (!torture_open_connection(&cli1)) {
2790 fnum = cli_nt_create_full(cli1, pipe_name, 0, SA_RIGHT_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
2791 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE, NTCREATEX_DISP_OPEN_IF, 0, 0);
2794 printf("Open of pipe %s failed with error (%s)\n", pipe_name, cli_errstr(cli1));
2800 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes, pipe_name );
2801 torture_close_connection(cli1);
2807 Test open mode returns on read-only files.
2809 static BOOL run_opentest(int dummy)
2811 static struct cli_state *cli1;
2812 static struct cli_state *cli2;
2813 const char *fname = "\\readonly.file";
2817 BOOL correct = True;
2821 printf("starting open test\n");
2823 if (!torture_open_connection(&cli1)) {
2827 cli_setatr(cli1, fname, 0, 0);
2828 cli_unlink(cli1, fname);
2830 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2832 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2836 if (!cli_close(cli1, fnum1)) {
2837 printf("close2 failed (%s)\n", cli_errstr(cli1));
2841 if (!cli_setatr(cli1, fname, FILE_ATTRIBUTE_READONLY, 0)) {
2842 printf("cli_setatr failed (%s)\n", cli_errstr(cli1));
2843 CHECK_MAX_FAILURES(error_test1);
2847 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_WRITE);
2849 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2850 CHECK_MAX_FAILURES(error_test1);
2854 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
2855 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_ALL);
2857 if (check_error(__LINE__, cli1, ERRDOS, ERRnoaccess,
2858 NT_STATUS_ACCESS_DENIED)) {
2859 printf("correct error code ERRDOS/ERRnoaccess returned\n");
2862 printf("finished open test 1\n");
2864 cli_close(cli1, fnum1);
2866 /* Now try not readonly and ensure ERRbadshare is returned. */
2868 cli_setatr(cli1, fname, 0, 0);
2870 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_WRITE);
2872 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2876 /* This will fail - but the error should be ERRshare. */
2877 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_ALL);
2879 if (check_error(__LINE__, cli1, ERRDOS, ERRbadshare,
2880 NT_STATUS_SHARING_VIOLATION)) {
2881 printf("correct error code ERRDOS/ERRbadshare returned\n");
2884 if (!cli_close(cli1, fnum1)) {
2885 printf("close2 failed (%s)\n", cli_errstr(cli1));
2889 cli_unlink(cli1, fname);
2891 printf("finished open test 2\n");
2893 /* Test truncate open disposition on file opened for read. */
2895 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2897 printf("(3) open (1) of %s failed (%s)\n", fname, cli_errstr(cli1));
2901 /* write 20 bytes. */
2903 memset(buf, '\0', 20);
2905 if (cli_write(cli1, fnum1, 0, buf, 0, 20) != 20) {
2906 printf("write failed (%s)\n", cli_errstr(cli1));
2910 if (!cli_close(cli1, fnum1)) {
2911 printf("(3) close1 failed (%s)\n", cli_errstr(cli1));
2915 /* Ensure size == 20. */
2916 if (!cli_getatr(cli1, fname, NULL, &fsize, NULL)) {
2917 printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
2918 CHECK_MAX_FAILURES(error_test3);
2923 printf("(3) file size != 20\n");
2924 CHECK_MAX_FAILURES(error_test3);
2928 /* Now test if we can truncate a file opened for readonly. */
2930 fnum1 = cli_open(cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE);
2932 printf("(3) open (2) of %s failed (%s)\n", fname, cli_errstr(cli1));
2933 CHECK_MAX_FAILURES(error_test3);
2937 if (!cli_close(cli1, fnum1)) {
2938 printf("close2 failed (%s)\n", cli_errstr(cli1));
2942 /* Ensure size == 0. */
2943 if (!cli_getatr(cli1, fname, NULL, &fsize, NULL)) {
2944 printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
2945 CHECK_MAX_FAILURES(error_test3);
2950 printf("(3) file size != 0\n");
2951 CHECK_MAX_FAILURES(error_test3);
2954 printf("finished open test 3\n");
2956 cli_unlink(cli1, fname);
2959 printf("testing ctemp\n");
2960 fnum1 = cli_ctemp(cli1, "\\", &tmp_path);
2962 printf("ctemp failed (%s)\n", cli_errstr(cli1));
2963 CHECK_MAX_FAILURES(error_test4);
2966 printf("ctemp gave path %s\n", tmp_path);
2967 if (!cli_close(cli1, fnum1)) {
2968 printf("close of temp failed (%s)\n", cli_errstr(cli1));
2970 if (!cli_unlink(cli1, tmp_path)) {
2971 printf("unlink of temp failed (%s)\n", cli_errstr(cli1));
2974 /* Test the non-io opens... */
2976 if (!torture_open_connection(&cli2)) {
2980 cli_setatr(cli2, fname, 0, 0);
2981 cli_unlink(cli2, fname);
2983 printf("TEST #1 testing 2 non-io opens (no delete)\n");
2985 fnum1 = cli_nt_create_full(cli1, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
2986 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2989 printf("test 1 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
2990 CHECK_MAX_FAILURES(error_test10);
2994 fnum2 = cli_nt_create_full(cli2, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
2995 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
2997 printf("test 1 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
2998 CHECK_MAX_FAILURES(error_test10);
3002 if (!cli_close(cli1, fnum1)) {
3003 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3006 if (!cli_close(cli2, fnum2)) {
3007 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3011 printf("non-io open test #1 passed.\n");
3013 cli_unlink(cli1, fname);
3015 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
3017 fnum1 = cli_nt_create_full(cli1, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3018 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
3021 printf("test 2 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3022 CHECK_MAX_FAILURES(error_test20);
3026 fnum2 = cli_nt_create_full(cli2, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3027 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
3030 printf("test 2 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3031 CHECK_MAX_FAILURES(error_test20);
3035 if (!cli_close(cli1, fnum1)) {
3036 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3039 if (!cli_close(cli2, fnum2)) {
3040 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
3044 printf("non-io open test #2 passed.\n");
3046 cli_unlink(cli1, fname);
3048 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
3050 fnum1 = cli_nt_create_full(cli1, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3051 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
3054 printf("test 3 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3055 CHECK_MAX_FAILURES(error_test30);
3059 fnum2 = cli_nt_create_full(cli2, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3060 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
3063 printf("test 3 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3064 CHECK_MAX_FAILURES(error_test30);
3068 if (!cli_close(cli1, fnum1)) {
3069 printf("test 3 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3072 if (!cli_close(cli2, fnum2)) {
3073 printf("test 3 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3077 printf("non-io open test #3 passed.\n");
3079 cli_unlink(cli1, fname);
3081 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
3083 fnum1 = cli_nt_create_full(cli1, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3084 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
3087 printf("test 4 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3088 CHECK_MAX_FAILURES(error_test40);
3092 fnum2 = cli_nt_create_full(cli2, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3093 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
3096 printf("test 4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
3097 CHECK_MAX_FAILURES(error_test40);
3101 printf("test 4 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
3103 if (!cli_close(cli1, fnum1)) {
3104 printf("test 4 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3108 printf("non-io open test #4 passed.\n");
3110 cli_unlink(cli1, fname);
3112 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
3114 fnum1 = cli_nt_create_full(cli1, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3115 NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
3118 printf("test 5 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3119 CHECK_MAX_FAILURES(error_test50);
3123 fnum2 = cli_nt_create_full(cli2, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3124 NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN_IF, 0, 0);
3127 printf("test 5 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3128 CHECK_MAX_FAILURES(error_test50);
3132 if (!cli_close(cli1, fnum1)) {
3133 printf("test 5 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3137 if (!cli_close(cli2, fnum2)) {
3138 printf("test 5 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3142 printf("non-io open test #5 passed.\n");
3144 printf("TEST #6 testing 1 non-io open, one io open\n");
3146 cli_unlink(cli1, fname);
3148 fnum1 = cli_nt_create_full(cli1, fname, 0, SA_RIGHT_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
3149 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
3152 printf("test 6 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3153 CHECK_MAX_FAILURES(error_test60);
3157 fnum2 = cli_nt_create_full(cli2, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3158 NTCREATEX_SHARE_ACCESS_READ, NTCREATEX_DISP_OPEN_IF, 0, 0);
3161 printf("test 6 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3162 CHECK_MAX_FAILURES(error_test60);
3166 if (!cli_close(cli1, fnum1)) {
3167 printf("test 6 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3171 if (!cli_close(cli2, fnum2)) {
3172 printf("test 6 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3176 printf("non-io open test #6 passed.\n");
3178 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
3180 cli_unlink(cli1, fname);
3182 fnum1 = cli_nt_create_full(cli1, fname, 0, SA_RIGHT_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
3183 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
3186 printf("test 7 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3187 CHECK_MAX_FAILURES(error_test70);
3191 fnum2 = cli_nt_create_full(cli2, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3192 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN_IF, 0, 0);
3195 printf("test 7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
3196 CHECK_MAX_FAILURES(error_test70);
3200 printf("test 7 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
3202 if (!cli_close(cli1, fnum1)) {
3203 printf("test 7 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3207 printf("non-io open test #7 passed.\n");
3209 cli_unlink(cli1, fname);
3211 if (!torture_close_connection(cli1)) {
3214 if (!torture_close_connection(cli2)) {
3222 static uint32 open_attrs_table[] = {
3223 FILE_ATTRIBUTE_NORMAL,
3224 FILE_ATTRIBUTE_ARCHIVE,
3225 FILE_ATTRIBUTE_READONLY,
3226 FILE_ATTRIBUTE_HIDDEN,
3227 FILE_ATTRIBUTE_SYSTEM,
3229 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY,
3230 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN,
3231 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM,
3232 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
3233 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
3234 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
3236 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
3237 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
3238 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
3239 FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_SYSTEM,
3242 struct trunc_open_results {
3249 static struct trunc_open_results attr_results[] = {
3250 { 0, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
3251 { 1, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
3252 { 2, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
3253 { 16, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
3254 { 17, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
3255 { 18, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
3256 { 51, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3257 { 54, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3258 { 56, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
3259 { 68, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3260 { 71, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3261 { 73, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM },
3262 { 99, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3263 { 102, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3264 { 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 },
3265 { 116, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3266 { 119, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3267 { 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 },
3268 { 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 },
3269 { 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 },
3270 { 227, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3271 { 230, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3272 { 232, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
3273 { 244, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3274 { 247, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3275 { 249, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM }
3278 static BOOL run_openattrtest(int dummy)
3280 struct cli_state *cli1;
3281 const char *fname = "\\openattr.file";
3283 BOOL correct = True;
3285 unsigned int i, j, k, l;
3288 printf("starting open attr test\n");
3290 if (!torture_open_connection(&cli1)) {
3294 for (k = 0, i = 0; i < sizeof(open_attrs_table)/sizeof(uint32); i++) {
3295 cli_setatr(cli1, fname, 0, 0);
3296 cli_unlink(cli1, fname);
3297 fnum1 = cli_nt_create_full(cli1, fname, 0, SA_RIGHT_FILE_WRITE_DATA, open_attrs_table[i],
3298 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
3301 printf("open %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
3305 if (!cli_close(cli1, fnum1)) {
3306 printf("close %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
3310 for (j = 0; j < ARRAY_SIZE(open_attrs_table); j++) {
3311 fnum1 = cli_nt_create_full(cli1, fname, 0,
3312 SA_RIGHT_FILE_READ_DATA|SA_RIGHT_FILE_WRITE_DATA,
3313 open_attrs_table[j],
3314 NTCREATEX_SHARE_ACCESS_NONE,
3315 NTCREATEX_DISP_OVERWRITE, 0, 0);
3318 for (l = 0; l < ARRAY_SIZE(attr_results); l++) {
3319 if (attr_results[l].num == k) {
3320 printf("[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(0x%x:%s)\n",
3321 k, open_attrs_table[i],
3322 open_attrs_table[j],
3323 fname, NT_STATUS_V(cli_nt_error(cli1)), cli_errstr(cli1));
3325 CHECK_MAX_FAILURES(error_exit);
3328 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_ACCESS_DENIED)) {
3329 printf("[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s\n",
3330 k, open_attrs_table[i], open_attrs_table[j],
3333 CHECK_MAX_FAILURES(error_exit);
3336 printf("[%d] trunc open 0x%x -> 0x%x failed\n", k, open_attrs_table[i], open_attrs_table[j]);
3342 if (!cli_close(cli1, fnum1)) {
3343 printf("close %d (2) of %s failed (%s)\n", j, fname, cli_errstr(cli1));
3347 if (!cli_getatr(cli1, fname, &attr, NULL, NULL)) {
3348 printf("getatr(2) failed (%s)\n", cli_errstr(cli1));
3353 printf("[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n",
3354 k, open_attrs_table[i], open_attrs_table[j], attr );
3357 for (l = 0; l < ARRAY_SIZE(attr_results); l++) {
3358 if (attr_results[l].num == k) {
3359 if (attr != attr_results[l].result_attr ||
3360 open_attrs_table[i] != attr_results[l].init_attr ||
3361 open_attrs_table[j] != attr_results[l].trunc_attr) {
3362 printf("[%d] getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x\n",
3363 k, open_attrs_table[i],
3364 open_attrs_table[j],
3366 attr_results[l].result_attr);
3368 CHECK_MAX_FAILURES(error_exit);
3377 cli_setatr(cli1, fname, 0, 0);
3378 cli_unlink(cli1, fname);
3380 printf("open attr test %s.\n", correct ? "passed" : "failed");
3382 if (!torture_close_connection(cli1)) {
3388 static void list_fn(file_info *finfo, const char *name, void *state)
3394 test directory listing speed
3396 static BOOL run_dirtest(int dummy)
3399 struct cli_state *cli;
3402 BOOL correct = True;
3404 printf("starting directory test\n");
3406 if (!torture_open_connection(&cli)) {
3410 printf("Creating %d random filenames\n", torture_numops);
3413 for (i=0;i<torture_numops;i++) {
3415 asprintf(&fname, "\\%x", (int)random());
3416 fnum = cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE);
3418 fprintf(stderr,"Failed to open %s\n", fname);
3421 cli_close(cli, fnum);
3427 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
3428 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
3429 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
3431 printf("dirtest core %g seconds\n", end_timer() - t1);
3434 for (i=0;i<torture_numops;i++) {
3436 asprintf(&fname, "\\%x", (int)random());
3437 cli_unlink(cli, fname);
3441 if (!torture_close_connection(cli)) {
3445 printf("finished dirtest\n");
3450 static void del_fn(file_info *finfo, const char *mask, void *state)
3452 struct cli_state *pcli = (struct cli_state *)state;
3454 asprintf(&fname, "\\LISTDIR\\%s", finfo->name);
3456 if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
3459 if (finfo->mode & FILE_ATTRIBUTE_DIRECTORY) {
3460 if (!cli_rmdir(pcli, fname))
3461 printf("del_fn: failed to rmdir %s, error=%s\n", fname, cli_errstr(pcli) );
3463 if (!cli_unlink(pcli, fname))
3464 printf("del_fn: failed to unlink %s, error=%s\n", fname, cli_errstr(pcli) );
3471 sees what IOCTLs are supported
3473 BOOL torture_ioctl_test(int dummy)
3475 struct cli_state *cli;
3476 uint16 device, function;
3478 const char *fname = "\\ioctl.dat";
3481 struct smb_ioctl parms;
3482 TALLOC_CTX *mem_ctx;
3484 if (!torture_open_connection(&cli)) {
3488 mem_ctx = talloc_init("ioctl_test");
3490 printf("starting ioctl test\n");
3492 cli_unlink(cli, fname);
3494 fnum = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
3496 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
3500 parms.in.request = IOCTL_QUERY_JOB_INFO;
3501 status = smb_raw_ioctl(cli->tree, mem_ctx, &parms);
3502 printf("ioctl job info: %s\n", cli_errstr(cli));
3504 for (device=0;device<0x100;device++) {
3505 printf("testing device=0x%x\n", device);
3506 for (function=0;function<0x100;function++) {
3507 parms.in.request = (device << 16) | function;
3508 status = smb_raw_ioctl(cli->tree, mem_ctx, &parms);
3510 if (NT_STATUS_IS_OK(status)) {
3511 printf("ioctl device=0x%x function=0x%x OK : %d bytes\n",
3512 device, function, blob.length);
3513 data_blob_free(&parms.out.blob);
3518 if (!torture_close_connection(cli)) {
3527 tries variants of chkpath
3529 BOOL torture_chkpath_test(int dummy)
3531 struct cli_state *cli;
3535 if (!torture_open_connection(&cli)) {
3539 printf("starting chkpath test\n");
3541 printf("Testing valid and invalid paths\n");
3543 /* cleanup from an old run */
3544 cli_rmdir(cli, "\\chkpath.dir\\dir2");
3545 cli_unlink(cli, "\\chkpath.dir\\*");
3546 cli_rmdir(cli, "\\chkpath.dir");
3548 if (!cli_mkdir(cli, "\\chkpath.dir")) {
3549 printf("mkdir1 failed : %s\n", cli_errstr(cli));
3553 if (!cli_mkdir(cli, "\\chkpath.dir\\dir2")) {
3554 printf("mkdir2 failed : %s\n", cli_errstr(cli));
3558 fnum = cli_open(cli, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
3560 printf("open1 failed (%s)\n", cli_errstr(cli));
3563 cli_close(cli, fnum);
3565 if (!cli_chkpath(cli, "\\chkpath.dir")) {
3566 printf("chkpath1 failed: %s\n", cli_errstr(cli));
3570 if (!cli_chkpath(cli, "\\chkpath.dir\\dir2")) {
3571 printf("chkpath2 failed: %s\n", cli_errstr(cli));
3575 if (!cli_chkpath(cli, "\\chkpath.dir\\foo.txt")) {
3576 ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath,
3577 NT_STATUS_NOT_A_DIRECTORY);
3579 printf("* chkpath on a file should fail\n");
3583 if (!cli_chkpath(cli, "\\chkpath.dir\\bar.txt")) {
3584 ret = check_error(__LINE__, cli, ERRDOS, ERRbadfile,
3585 NT_STATUS_OBJECT_NAME_NOT_FOUND);
3587 printf("* chkpath on a non existent file should fail\n");
3591 if (!cli_chkpath(cli, "\\chkpath.dir\\dirxx\\bar.txt")) {
3592 ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath,
3593 NT_STATUS_OBJECT_PATH_NOT_FOUND);
3595 printf("* chkpath on a non existent component should fail\n");
3599 cli_rmdir(cli, "\\chkpath.dir\\dir2");
3600 cli_unlink(cli, "\\chkpath.dir\\*");
3601 cli_rmdir(cli, "\\chkpath.dir");
3603 if (!torture_close_connection(cli)) {
3613 static BOOL run_dirtest1(int dummy)
3616 struct cli_state *cli;
3618 BOOL correct = True;
3620 printf("starting directory test\n");
3622 if (!torture_open_connection(&cli)) {
3626 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
3627 cli_list(cli, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, del_fn, cli);
3628 if (cli_deltree(cli, "\\LISTDIR") == -1) {
3629 fprintf(stderr,"Failed to deltree %s, error=%s\n", "\\LISTDIR", cli_errstr(cli));
3632 if (!cli_mkdir(cli, "\\LISTDIR")) {
3633 fprintf(stderr,"Failed to mkdir %s, error=%s\n", "\\LISTDIR", cli_errstr(cli));
3637 printf("Creating %d files\n", torture_entries);
3639 /* Create torture_entries files and torture_entries directories. */
3640 for (i=0;i<torture_entries;i++) {
3642 asprintf(&fname, "\\LISTDIR\\f%d", i);
3643 fnum = cli_nt_create_full(cli, fname, 0, GENERIC_RIGHTS_FILE_ALL_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
3644 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
3646 fprintf(stderr,"Failed to open %s, error=%s\n", fname, cli_errstr(cli));
3650 cli_close(cli, fnum);
3652 for (i=0;i<torture_entries;i++) {
3654 asprintf(&fname, "\\LISTDIR\\d%d", i);
3655 if (!cli_mkdir(cli, fname)) {
3656 fprintf(stderr,"Failed to open %s, error=%s\n", fname, cli_errstr(cli));
3662 /* Now ensure that doing an old list sees both files and directories. */
3663 num_seen = cli_list_old(cli, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, list_fn, NULL);
3664 printf("num_seen = %d\n", num_seen );
3665 /* We should see (torture_entries) each of files & directories + . and .. */
3666 if (num_seen != (2*torture_entries)+2) {
3668 fprintf(stderr,"entry count mismatch, should be %d, was %d\n",
3669 (2*torture_entries)+2, num_seen);
3673 /* Ensure if we have the "must have" bits we only see the
3676 num_seen = cli_list_old(cli, "\\LISTDIR\\*", (FILE_ATTRIBUTE_DIRECTORY<<8)|FILE_ATTRIBUTE_DIRECTORY, list_fn, NULL);
3677 printf("num_seen = %d\n", num_seen );
3678 if (num_seen != torture_entries+2) {
3680 fprintf(stderr,"entry count mismatch, should be %d, was %d\n",
3681 torture_entries+2, num_seen);
3684 num_seen = cli_list_old(cli, "\\LISTDIR\\*", (FILE_ATTRIBUTE_ARCHIVE<<8)|FILE_ATTRIBUTE_DIRECTORY, list_fn, NULL);
3685 printf("num_seen = %d\n", num_seen );
3686 if (num_seen != torture_entries) {
3688 fprintf(stderr,"entry count mismatch, should be %d, was %d\n",
3689 torture_entries, num_seen);
3692 /* Delete everything. */
3693 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
3694 cli_list(cli, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, del_fn, cli);
3695 cli_rmdir(cli, "\\LISTDIR");
3698 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
3699 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
3700 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
3703 if (!torture_close_connection(cli)) {
3707 printf("finished dirtest1\n");
3714 simple test harness for playing with deny modes
3716 static BOOL run_deny3test(int dummy)
3718 struct cli_state *cli1, *cli2;
3722 printf("starting deny3 test\n");
3724 printf("Testing simple deny modes\n");
3726 if (!torture_open_connection(&cli1)) {
3729 if (!torture_open_connection(&cli2)) {
3733 fname = "\\deny_dos1.dat";
3735 cli_unlink(cli1, fname);
3736 fnum1 = cli_open(cli1, fname, O_CREAT|O_TRUNC|O_WRONLY, DENY_DOS);
3737 fnum2 = cli_open(cli1, fname, O_CREAT|O_TRUNC|O_WRONLY, DENY_DOS);
3738 if (fnum1 != -1) cli_close(cli1, fnum1);
3739 if (fnum2 != -1) cli_close(cli1, fnum2);
3740 cli_unlink(cli1, fname);
3741 printf("fnum1=%d fnum2=%d\n", fnum1, fnum2);
3744 fname = "\\deny_dos2.dat";
3746 cli_unlink(cli1, fname);
3747 fnum1 = cli_open(cli1, fname, O_CREAT|O_TRUNC|O_WRONLY, DENY_DOS);
3748 fnum2 = cli_open(cli2, fname, O_CREAT|O_TRUNC|O_WRONLY, DENY_DOS);
3749 if (fnum1 != -1) cli_close(cli1, fnum1);
3750 if (fnum2 != -1) cli_close(cli2, fnum2);
3751 cli_unlink(cli1, fname);
3752 printf("fnum1=%d fnum2=%d\n", fnum1, fnum2);
3755 torture_close_connection(cli1);
3756 torture_close_connection(cli2);
3762 static double create_procs(BOOL (*fn)(int), BOOL *result)
3765 volatile pid_t *child_status;
3766 volatile BOOL *child_status_out;
3772 child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*nprocs);
3773 if (!child_status) {
3774 printf("Failed to setup shared memory\n");
3778 child_status_out = (volatile BOOL *)shm_setup(sizeof(BOOL)*nprocs);
3779 if (!child_status_out) {
3780 printf("Failed to setup result status shared memory\n");
3784 for (i = 0; i < nprocs; i++) {
3785 child_status[i] = 0;
3786 child_status_out[i] = True;
3791 for (i=0;i<nprocs;i++) {
3795 pid_t mypid = getpid();
3796 sys_srandom(((int)mypid) ^ ((int)time(NULL)));
3798 asprintf(&myname, "CLIENT%d", i);
3799 lp_set_cmdline("netbios name", myname);
3803 if (torture_open_connection(¤t_cli)) break;
3805 printf("pid %d failed to start\n", (int)getpid());
3811 child_status[i] = getpid();
3813 while (child_status[i] && end_timer() < 5) msleep(2);
3815 child_status_out[i] = fn(i);
3822 for (i=0;i<nprocs;i++) {
3823 if (child_status[i]) synccount++;
3825 if (synccount == nprocs) break;
3827 } while (end_timer() < 30);
3829 if (synccount != nprocs) {
3830 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs, synccount);
3835 /* start the client load */
3838 for (i=0;i<nprocs;i++) {
3839 child_status[i] = 0;
3842 printf("%d clients started\n", nprocs);
3844 for (i=0;i<nprocs;i++) {
3845 while (waitpid(0, &status, 0) == -1 && errno == EINTR) /* noop */ ;
3850 for (i=0;i<nprocs;i++) {
3851 if (!child_status_out[i]) {
3858 #define FLAG_MULTIPROC 1
3865 {"FDPASS", run_fdpasstest, 0},
3866 {"LOCK1", run_locktest1, 0},
3867 {"LOCK2", run_locktest2, 0},
3868 {"LOCK3", run_locktest3, 0},
3869 {"LOCK4", run_locktest4, 0},
3870 {"LOCK5", run_locktest5, 0},
3871 {"LOCK6", run_locktest6, 0},
3872 {"LOCK7", run_locktest7, 0},
3873 {"UNLINK", run_unlinktest, 0},
3874 {"ATTR", run_attrtest, 0},
3875 {"TRANS2", run_trans2test, 0},
3876 {"MAXFID", run_maxfidtest, FLAG_MULTIPROC},
3877 {"TORTURE",run_torture, FLAG_MULTIPROC},
3878 {"NEGNOWAIT", run_negprot_nowait, 0},
3879 {"NBENCH", run_nbench, 0},
3880 {"DIR", run_dirtest, 0},
3881 {"DIR1", run_dirtest1, 0},
3882 {"DENY1", torture_denytest1, 0},
3883 {"DENY2", torture_denytest2, 0},
3884 {"TCON", run_tcon_test, 0},
3885 {"TCONDEV", run_tcon_devtype_test, 0},
3887 {"DFSBASIC", torture_dfs_basic, 0},
3888 {"DFSRENAME", torture_dfs_rename, 0},
3889 {"DFSRANDOM", torture_dfs_random, 0},
3891 {"RW1", run_readwritetest, 0},
3892 {"RW2", run_readwritemulti, FLAG_MULTIPROC},
3893 {"OPEN", run_opentest, 0},
3894 {"DENY3", run_deny3test, 0},
3896 {"OPENATTR", run_openattrtest, 0},
3898 {"XCOPY", run_xcopy, 0},
3899 {"RENAME", run_rename, 0},
3900 {"DELETE", run_deletetest, 0},
3901 {"PROPERTIES", run_properties, 0},
3902 {"MANGLE", torture_mangle, 0},
3903 {"UTABLE", torture_utable, 0},
3904 {"CASETABLE", torture_casetable, 0},
3905 {"PIPE_NUMBER", run_pipe_number, 0},
3906 {"IOCTL", torture_ioctl_test, 0},
3907 {"CHKPATH", torture_chkpath_test, 0},
3908 {"RAW-QFSINFO", torture_raw_qfsinfo, 0},
3909 {"RAW-QFILEINFO", torture_raw_qfileinfo, 0},
3910 {"RAW-SFILEINFO", torture_raw_sfileinfo, 0},
3911 {"RAW-SFILEINFO-BUG", torture_raw_sfileinfo_bug, 0},
3912 {"RAW-SEARCH", torture_raw_search, 0},
3913 {"RAW-CLOSE", torture_raw_close, 0},
3914 {"RAW-OPEN", torture_raw_open, 0},
3915 {"RAW-MKDIR", torture_raw_mkdir, 0},
3916 {"RAW-OPLOCK", torture_raw_oplock, 0},
3917 {"RAW-NOTIFY", torture_raw_notify, 0},
3918 {"RAW-MUX", torture_raw_mux, 0},
3919 {"RAW-IOCTL", torture_raw_ioctl, 0},
3920 {"RAW-CHKPATH", torture_raw_chkpath, 0},
3921 {"RAW-UNLINK", torture_raw_unlink, 0},
3922 {"RAW-READ", torture_raw_read, 0},
3923 {"RAW-WRITE", torture_raw_write, 0},
3924 {"RAW-LOCK", torture_raw_lock, 0},
3925 {"RAW-CONTEXT", torture_raw_context, 0},
3926 {"RAW-RENAME", torture_raw_rename, 0},
3927 {"RAW-SEEK", torture_raw_seek, 0},
3928 {"SCAN-TRANS2", torture_trans2_scan, 0},
3929 {"SCAN-NTTRANS", torture_nttrans_scan, 0},
3930 {"SCAN-ALIASES", torture_trans2_aliases, 0},
3935 /****************************************************************************
3936 run a specified test or "ALL"
3937 ****************************************************************************/
3938 static BOOL run_test(const char *name)
3942 BOOL matched = False;
3944 if (strequal(name,"ALL")) {
3945 for (i=0;torture_ops[i].name;i++) {
3946 if (!run_test(torture_ops[i].name)) {
3953 for (i=0;torture_ops[i].name;i++) {
3954 asprintf(&randomfname, "\\XX%x",
3955 (unsigned)random());
3957 if (gen_fnmatch(name, torture_ops[i].name) == 0) {
3960 printf("Running %s\n", torture_ops[i].name);
3961 if (torture_ops[i].flags & FLAG_MULTIPROC) {
3963 t = create_procs(torture_ops[i].fn, &result);
3966 printf("TEST %s FAILED!\n", torture_ops[i].name);
3971 if (!torture_ops[i].fn(0)) {
3973 printf("TEST %s FAILED!\n", torture_ops[i].name);
3977 printf("%s took %g secs\n\n", torture_ops[i].name, t);
3982 printf("Unknown torture operation '%s'\n", name);
3989 static void usage(void)
3993 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
3995 printf("\t-d debuglevel\n");
3996 printf("\t-U user%%pass\n");
3997 printf("\t-k use kerberos\n");
3998 printf("\t-N numprocs\n");
3999 printf("\t-n my_netbios_name\n");
4000 printf("\t-W workgroup\n");
4001 printf("\t-o num_operations\n");
4002 printf("\t-e num files(entries)\n");
4003 printf("\t-O socket_options\n");
4004 printf("\t-m maximum protocol\n");
4005 printf("\t-L use oplocks\n");
4006 printf("\t-c CLIENT.TXT specify client load file for NBENCH\n");
4007 printf("\t-A showall\n");
4008 printf("\t-p port\n");
4009 printf("\t-s seed\n");
4010 printf("\t-f max failures\n");
4011 printf("\t-b bypass I/O (NBENCH)\n");
4014 printf("tests are:");
4015 for (i=0;torture_ops[i].name;i++) {
4016 printf(" %s", torture_ops[i].name);
4020 printf("default test is ALL\n");
4025 /****************************************************************************
4027 ****************************************************************************/
4028 int main(int argc,char *argv[])
4034 BOOL correct = True;
4035 char *host, *share, *username, *password;
4037 setup_logging("smbtorture", DEBUG_STDOUT);
4039 #ifdef HAVE_SETBUFFER
4040 setbuffer(stdout, NULL, 0);
4043 lp_load(dyn_CONFIGFILE,True,False,False);
4050 for(p = argv[1]; *p; p++)
4054 if (strncmp(argv[1], "//", 2)) {
4058 host = strdup(&argv[1][2]);
4059 p = strchr_m(&host[2],'/');
4064 share = strdup(p+1);
4066 if (getenv("LOGNAME")) {
4067 username = strdup(getenv("LOGNAME"));
4070 lp_set_cmdline("torture:host", host);
4071 lp_set_cmdline("torture:share", share);
4072 lp_set_cmdline("torture:username", username);
4073 lp_set_cmdline("torture:password", "");
4078 srandom(time(NULL));
4080 while ((opt = getopt(argc, argv, "p:hW:U:n:N:O:o:e:m:Ld:Ac:ks:f:bs:")) != EOF) {
4083 lp_set_cmdline("smb ports", optarg);
4086 lp_set_cmdline("workgroup", optarg);
4089 lp_set_cmdline("protocol", optarg);
4092 lp_set_cmdline("netbios name", optarg);
4095 lp_set_cmdline("debug level", optarg);
4096 setup_logging(NULL,True);
4099 lp_set_cmdline("socket options", optarg);
4102 srandom(atoi(optarg));
4105 nprocs = atoi(optarg);
4108 torture_numops = atoi(optarg);
4111 torture_entries = atoi(optarg);
4117 torture_showall = True;
4120 client_txt = optarg;
4124 use_kerberos = True;
4126 d_printf("No kerberos support compiled in\n");
4132 username = strdup(optarg);
4133 p = strchr_m(username,'%');
4136 password = strdup(p+1);
4139 lp_set_cmdline("torture:username", username);
4140 lp_set_cmdline("torture:password", password);
4143 torture_failures = atoi(optarg);
4150 printf("Unknown option %c (%d)\n", (char)opt, opt);
4155 if(use_kerberos && !gotuser) gotpass = True;
4158 p = getpass("Password:");
4160 lp_set_cmdline("torture:password", p);
4165 printf("host=%s share=%s user=%s myname=%s\n",
4166 host, share, username, lp_netbios_name());
4168 if (argc == optind) {
4169 printf("You must specify a test to run, or 'ALL'\n");
4171 for (i=optind;i<argc;i++) {
4172 if (!run_test(argv[i])) {