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.
23 #include "lib/cmdline/popt_common.h"
24 #include "libcli/raw/libcliraw.h"
25 #include "system/time.h"
26 #include "system/wait.h"
30 int torture_numops=100;
31 int torture_entries=1000;
32 int torture_failures=1;
34 static int procnum; /* records process count number when forking */
35 static struct smbcli_state *current_cli;
36 static BOOL use_oplocks;
37 static BOOL use_level_II_oplocks;
38 static BOOL use_kerberos;
40 BOOL torture_showall = False;
42 #define CHECK_MAX_FAILURES(label) do { if (++failures >= torture_failures) goto label; } while (0)
44 static struct smbcli_state *open_nbt_connection(void)
46 struct nmb_name called, calling;
47 struct smbcli_state *cli;
48 const char *host = lp_parm_string(-1, "torture", "host");
50 make_nmb_name(&calling, lp_netbios_name(), 0x0);
51 choose_called_name(&called, host, 0x20);
53 cli = smbcli_state_init(NULL);
55 printf("Failed initialize smbcli_struct to connect with %s\n", host);
59 if (!smbcli_socket_connect(cli, host)) {
60 printf("Failed to connect with %s\n", host);
64 cli->transport->socket->timeout = 120000; /* set a really long timeout (2 minutes) */
66 if (!smbcli_transport_establish(cli, &calling, &called)) {
68 * Well, that failed, try *SMBSERVER ...
69 * However, we must reconnect as well ...
71 if (!smbcli_socket_connect(cli, host)) {
72 printf("Failed to connect with %s\n", host);
76 make_nmb_name(&called, "*SMBSERVER", 0x20);
77 if (!smbcli_transport_establish(cli, &calling, &called)) {
78 printf("%s rejected the session\n",host);
79 printf("We tried with a called name of %s & %s\n",
89 BOOL torture_open_connection_share(struct smbcli_state **c,
91 const char *sharename)
96 const char *username = lp_parm_string(-1, "torture", "username");
97 const char *userdomain = lp_parm_string(-1, "torture", "userdomain");
98 const char *password = lp_parm_string(-1, "torture", "password");
101 flags |= SMBCLI_FULL_CONNECTION_USE_KERBEROS;
103 status = smbcli_full_connection(NULL,
104 c, lp_netbios_name(),
107 username, username[0]?userdomain:"",
108 password, flags, &retry);
109 if (!NT_STATUS_IS_OK(status)) {
110 printf("Failed to open connection - %s\n", nt_errstr(status));
114 (*c)->transport->options.use_oplocks = use_oplocks;
115 (*c)->transport->options.use_level2_oplocks = use_level_II_oplocks;
116 (*c)->transport->socket->timeout = 120000;
121 BOOL torture_open_connection(struct smbcli_state **c)
123 const char *host = lp_parm_string(-1, "torture", "host");
124 const char *share = lp_parm_string(-1, "torture", "share");
126 return torture_open_connection_share(c, host, share);
131 BOOL torture_close_connection(struct smbcli_state *c)
135 if (NT_STATUS_IS_ERR(smbcli_tdis(c))) {
136 printf("tdis failed (%s)\n", smbcli_errstr(c->tree));
144 /* open a rpc connection to the chosen binding string */
145 NTSTATUS torture_rpc_connection(struct dcerpc_pipe **p,
146 const char *pipe_name,
147 const char *pipe_uuid,
148 uint32_t pipe_version)
151 const char *binding = lp_parm_string(-1, "torture", "binding");
154 printf("You must specify a ncacn binding string\n");
155 return NT_STATUS_INVALID_PARAMETER;
158 status = dcerpc_pipe_connect(p, binding, pipe_uuid, pipe_version,
159 lp_parm_string(-1, "torture", "userdomain"),
160 lp_parm_string(-1, "torture", "username"),
161 lp_parm_string(-1, "torture", "password"));
166 /* open a rpc connection to a specific transport */
167 NTSTATUS torture_rpc_connection_transport(struct dcerpc_pipe **p,
168 const char *pipe_name,
169 const char *pipe_uuid,
170 uint32_t pipe_version,
171 enum dcerpc_transport_t transport)
174 const char *binding = lp_parm_string(-1, "torture", "binding");
175 struct dcerpc_binding b;
176 TALLOC_CTX *mem_ctx = talloc_init("torture_rpc_connection_smb");
179 printf("You must specify a ncacn binding string\n");
180 return NT_STATUS_INVALID_PARAMETER;
183 status = dcerpc_parse_binding(mem_ctx, binding, &b);
184 if (!NT_STATUS_IS_OK(status)) {
185 DEBUG(0,("Failed to parse dcerpc binding '%s'\n", binding));
186 talloc_destroy(mem_ctx);
190 b.transport = transport;
192 status = dcerpc_pipe_connect_b(p, &b, pipe_uuid, pipe_version,
193 lp_parm_string(-1, "torture", "userdomain"),
194 lp_parm_string(-1, "torture", "username"),
195 lp_parm_string(-1, "torture", "password"));
200 /* close a rpc connection to a named pipe */
201 NTSTATUS torture_rpc_close(struct dcerpc_pipe *p)
203 dcerpc_pipe_close(p);
208 /* check if the server produced the expected error code */
209 BOOL check_error(const char *location, struct smbcli_state *c,
210 uint8_t eclass, uint32_t ecode, NTSTATUS nterr)
212 if (smbcli_is_dos_error(c->tree)) {
216 /* Check DOS error */
218 smbcli_dos_error(c, &class, &num);
220 if (eclass != class || ecode != num) {
221 printf("unexpected error code class=%d code=%d\n",
222 (int)class, (int)num);
223 printf(" expected %d/%d %s (at %s)\n",
224 (int)eclass, (int)ecode, nt_errstr(nterr), location);
233 status = smbcli_nt_error(c->tree);
235 if (NT_STATUS_V(nterr) != NT_STATUS_V(status)) {
236 printf("unexpected error code %s\n", nt_errstr(status));
237 printf(" expected %s (at %s)\n", nt_errstr(nterr), location);
246 static BOOL wait_lock(struct smbcli_state *c, int fnum, uint32_t offset, uint32_t len)
248 while (NT_STATUS_IS_ERR(smbcli_lock(c->tree, fnum, offset, len, -1, WRITE_LOCK))) {
249 if (!check_error(__location__, c, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
255 static BOOL rw_torture(struct smbcli_state *c)
257 const char *lockfname = "\\torture.lck";
261 pid_t pid2, pid = getpid();
266 fnum2 = smbcli_open(c->tree, lockfname, O_RDWR | O_CREAT | O_EXCL,
269 fnum2 = smbcli_open(c->tree, lockfname, O_RDWR, DENY_NONE);
271 printf("open of %s failed (%s)\n", lockfname, smbcli_errstr(c->tree));
276 for (i=0;i<torture_numops;i++) {
277 uint_t n = (uint_t)sys_random()%10;
279 printf("%d\r", i); fflush(stdout);
281 asprintf(&fname, "\\torture.%u", n);
283 if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) {
287 fnum = smbcli_open(c->tree, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL);
289 printf("open failed (%s)\n", smbcli_errstr(c->tree));
294 if (smbcli_write(c->tree, fnum, 0, (char *)&pid, 0, sizeof(pid)) != sizeof(pid)) {
295 printf("write failed (%s)\n", smbcli_errstr(c->tree));
300 if (smbcli_write(c->tree, fnum, 0, (char *)buf,
301 sizeof(pid)+(j*sizeof(buf)),
302 sizeof(buf)) != sizeof(buf)) {
303 printf("write failed (%s)\n", smbcli_errstr(c->tree));
310 if (smbcli_read(c->tree, fnum, (char *)&pid2, 0, sizeof(pid)) != sizeof(pid)) {
311 printf("read failed (%s)\n", smbcli_errstr(c->tree));
316 printf("data corruption!\n");
320 if (NT_STATUS_IS_ERR(smbcli_close(c->tree, fnum))) {
321 printf("close failed (%s)\n", smbcli_errstr(c->tree));
325 if (NT_STATUS_IS_ERR(smbcli_unlink(c->tree, fname))) {
326 printf("unlink failed (%s)\n", smbcli_errstr(c->tree));
330 if (NT_STATUS_IS_ERR(smbcli_unlock(c->tree, fnum2, n*sizeof(int), sizeof(int)))) {
331 printf("unlock failed (%s)\n", smbcli_errstr(c->tree));
337 smbcli_close(c->tree, fnum2);
338 smbcli_unlink(c->tree, lockfname);
345 static BOOL run_torture(struct smbcli_state *cli, int dummy)
349 ret = rw_torture(cli);
351 if (!torture_close_connection(cli)) {
358 static BOOL rw_torture3(struct smbcli_state *c, const char *lockfname)
365 uint_t countprev = 0;
369 for (i = 0; i < sizeof(buf); i += sizeof(uint32_t))
371 SIVAL(buf, i, sys_random());
376 fnum = smbcli_open(c->tree, lockfname, O_RDWR | O_CREAT | O_EXCL,
379 printf("first open read/write of %s failed (%s)\n",
380 lockfname, smbcli_errstr(c->tree));
386 for (i = 0; i < 500 && fnum == -1; i++)
388 fnum = smbcli_open(c->tree, lockfname, O_RDONLY,
393 printf("second open read-only of %s failed (%s)\n",
394 lockfname, smbcli_errstr(c->tree));
400 for (count = 0; count < sizeof(buf); count += sent)
402 if (count >= countprev) {
403 printf("%d %8d\r", i, count);
406 countprev += (sizeof(buf) / 20);
411 sent = ((uint_t)sys_random()%(20))+ 1;
412 if (sent > sizeof(buf) - count)
414 sent = sizeof(buf) - count;
417 if (smbcli_write(c->tree, fnum, 0, buf+count, count, (size_t)sent) != sent) {
418 printf("write failed (%s)\n", smbcli_errstr(c->tree));
424 sent = smbcli_read(c->tree, fnum, buf_rd+count, count,
428 printf("read failed offset:%d size:%d (%s)\n",
429 count, sizeof(buf)-count,
430 smbcli_errstr(c->tree));
436 if (memcmp(buf_rd+count, buf+count, sent) != 0)
438 printf("read/write compare failed\n");
439 printf("offset: %d req %d recvd %d\n",
440 count, sizeof(buf)-count, sent);
449 if (NT_STATUS_IS_ERR(smbcli_close(c->tree, fnum))) {
450 printf("close failed (%s)\n", smbcli_errstr(c->tree));
457 static BOOL rw_torture2(struct smbcli_state *c1, struct smbcli_state *c2)
459 const char *lockfname = "\\torture2.lck";
464 uint8_t buf_rd[131072];
466 ssize_t bytes_read, bytes_written;
468 if (smbcli_deltree(c1->tree, lockfname) == -1) {
469 printf("unlink failed (%s)\n", smbcli_errstr(c1->tree));
472 fnum1 = smbcli_open(c1->tree, lockfname, O_RDWR | O_CREAT | O_EXCL,
475 printf("first open read/write of %s failed (%s)\n",
476 lockfname, smbcli_errstr(c1->tree));
479 fnum2 = smbcli_open(c2->tree, lockfname, O_RDONLY,
482 printf("second open read-only of %s failed (%s)\n",
483 lockfname, smbcli_errstr(c2->tree));
484 smbcli_close(c1->tree, fnum1);
488 printf("Checking data integrity over %d ops\n", torture_numops);
490 for (i=0;i<torture_numops;i++)
492 size_t buf_size = ((uint_t)sys_random()%(sizeof(buf)-1))+ 1;
494 printf("%d\r", i); fflush(stdout);
497 generate_random_buffer(buf, buf_size);
499 if ((bytes_written = smbcli_write(c1->tree, fnum1, 0, buf, 0, buf_size)) != buf_size) {
500 printf("write failed (%s)\n", smbcli_errstr(c1->tree));
501 printf("wrote %d, expected %d\n", bytes_written, buf_size);
506 if ((bytes_read = smbcli_read(c2->tree, fnum2, buf_rd, 0, buf_size)) != buf_size) {
507 printf("read failed (%s)\n", smbcli_errstr(c2->tree));
508 printf("read %d, expected %d\n", bytes_read, buf_size);
513 if (memcmp(buf_rd, buf, buf_size) != 0)
515 printf("read/write compare failed\n");
521 if (NT_STATUS_IS_ERR(smbcli_close(c2->tree, fnum2))) {
522 printf("close failed (%s)\n", smbcli_errstr(c2->tree));
525 if (NT_STATUS_IS_ERR(smbcli_close(c1->tree, fnum1))) {
526 printf("close failed (%s)\n", smbcli_errstr(c1->tree));
530 if (NT_STATUS_IS_ERR(smbcli_unlink(c1->tree, lockfname))) {
531 printf("unlink failed (%s)\n", smbcli_errstr(c1->tree));
538 static BOOL run_readwritetest(void)
540 struct smbcli_state *cli1, *cli2;
541 BOOL test1, test2 = True;
543 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
547 printf("starting readwritetest\n");
549 test1 = rw_torture2(cli1, cli2);
550 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1));
553 test2 = rw_torture2(cli1, cli1);
554 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2));
557 if (!torture_close_connection(cli1)) {
561 if (!torture_close_connection(cli2)) {
565 return (test1 && test2);
568 static BOOL run_readwritemulti(struct smbcli_state *cli, int dummy)
572 test = rw_torture3(cli, "\\multitest.txt");
574 if (!torture_close_connection(cli)) {
583 this checks to see if a secondary tconx can use open files from an
586 static BOOL run_tcon_test(void)
588 struct smbcli_state *cli;
589 const char *fname = "\\tcontest.tmp";
591 uint16_t cnum1, cnum2, cnum3;
592 uint16_t vuid1, vuid2;
595 struct smbcli_tree *tree1;
596 const char *host = lp_parm_string(-1, "torture", "host");
597 const char *share = lp_parm_string(-1, "torture", "share");
598 const char *password = lp_parm_string(-1, "torture", "password");
600 if (!torture_open_connection(&cli)) {
604 printf("starting tcontest\n");
606 if (smbcli_deltree(cli->tree, fname) == -1) {
607 printf("unlink of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
610 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
612 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
616 cnum1 = cli->tree->tid;
617 vuid1 = cli->session->vuid;
619 memset(&buf, 0, 4); /* init buf so valgrind won't complain */
620 if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) != 4) {
621 printf("initial write failed (%s)\n", smbcli_errstr(cli->tree));
625 tree1 = cli->tree; /* save old tree connection */
626 if (NT_STATUS_IS_ERR(smbcli_send_tconX(cli, share, "?????", password))) {
627 printf("%s refused 2nd tree connect (%s)\n", host,
628 smbcli_errstr(cli->tree));
629 smbcli_shutdown(cli);
633 cnum2 = cli->tree->tid;
634 cnum3 = MAX(cnum1, cnum2) + 1; /* any invalid number */
635 vuid2 = cli->session->vuid + 1;
637 /* try a write with the wrong tid */
638 cli->tree->tid = cnum2;
640 if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) == 4) {
641 printf("* server allows write with wrong TID\n");
644 printf("server fails write with wrong TID : %s\n", smbcli_errstr(cli->tree));
648 /* try a write with an invalid tid */
649 cli->tree->tid = cnum3;
651 if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) == 4) {
652 printf("* server allows write with invalid TID\n");
655 printf("server fails write with invalid TID : %s\n", smbcli_errstr(cli->tree));
658 /* try a write with an invalid vuid */
659 cli->session->vuid = vuid2;
660 cli->tree->tid = cnum1;
662 if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) == 4) {
663 printf("* server allows write with invalid VUID\n");
666 printf("server fails write with invalid VUID : %s\n", smbcli_errstr(cli->tree));
669 cli->session->vuid = vuid1;
670 cli->tree->tid = cnum1;
672 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum1))) {
673 printf("close failed (%s)\n", smbcli_errstr(cli->tree));
677 cli->tree->tid = cnum2;
679 if (NT_STATUS_IS_ERR(smbcli_tdis(cli))) {
680 printf("secondary tdis failed (%s)\n", smbcli_errstr(cli->tree));
684 cli->tree = tree1; /* restore initial tree */
685 cli->tree->tid = cnum1;
687 if (!torture_close_connection(cli)) {
696 static BOOL tcon_devtest(struct smbcli_state *cli,
697 const char *myshare, const char *devtype,
698 NTSTATUS expected_error)
702 const char *password = lp_parm_string(-1, "torture", "password");
704 status = NT_STATUS_IS_OK(smbcli_send_tconX(cli, myshare, devtype,
707 printf("Trying share %s with devtype %s\n", myshare, devtype);
709 if (NT_STATUS_IS_OK(expected_error)) {
713 printf("tconX to share %s with type %s "
714 "should have succeeded but failed\n",
721 printf("tconx to share %s with type %s "
722 "should have failed but succeeded\n",
726 if (NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),
730 printf("Returned unexpected error\n");
739 checks for correct tconX support
741 static BOOL run_tcon_devtype_test(void)
743 struct smbcli_state *cli1 = NULL;
748 const char *host = lp_parm_string(-1, "torture", "host");
749 const char *share = lp_parm_string(-1, "torture", "share");
750 const char *username = lp_parm_string(-1, "torture", "username");
751 const char *userdomain = lp_parm_string(-1, "torture", "userdomain");
752 const char *password = lp_parm_string(-1, "torture", "password");
754 status = smbcli_full_connection(NULL,
755 &cli1, lp_netbios_name(),
758 username, userdomain,
759 password, flags, &retry);
761 if (!NT_STATUS_IS_OK(status)) {
762 printf("could not open connection\n");
766 if (!tcon_devtest(cli1, "IPC$", "A:", NT_STATUS_BAD_DEVICE_TYPE))
769 if (!tcon_devtest(cli1, "IPC$", "?????", NT_STATUS_OK))
772 if (!tcon_devtest(cli1, "IPC$", "LPT:", NT_STATUS_BAD_DEVICE_TYPE))
775 if (!tcon_devtest(cli1, "IPC$", "IPC", NT_STATUS_OK))
778 if (!tcon_devtest(cli1, "IPC$", "FOOBA", NT_STATUS_BAD_DEVICE_TYPE))
781 if (!tcon_devtest(cli1, share, "A:", NT_STATUS_OK))
784 if (!tcon_devtest(cli1, share, "?????", NT_STATUS_OK))
787 if (!tcon_devtest(cli1, share, "LPT:", NT_STATUS_BAD_DEVICE_TYPE))
790 if (!tcon_devtest(cli1, share, "IPC", NT_STATUS_BAD_DEVICE_TYPE))
793 if (!tcon_devtest(cli1, share, "FOOBA", NT_STATUS_BAD_DEVICE_TYPE))
796 smbcli_shutdown(cli1);
799 printf("Passed tcondevtest\n");
806 test whether fnums and tids open on one VC are available on another (a major
809 static BOOL run_fdpasstest(void)
811 struct smbcli_state *cli1, *cli2;
812 const char *fname = "\\fdpass.tst";
816 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
820 printf("starting fdpasstest\n");
822 smbcli_unlink(cli1->tree, fname);
824 printf("Opening a file on connection 1\n");
826 fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
828 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
832 printf("writing to file on connection 1\n");
834 if (smbcli_write(cli1->tree, fnum1, 0, "hello world\n", 0, 13) != 13) {
835 printf("write failed (%s)\n", smbcli_errstr(cli1->tree));
839 oldtid = cli2->tree->tid;
840 cli2->session->vuid = cli1->session->vuid;
841 cli2->tree->tid = cli1->tree->tid;
842 cli2->session->pid = cli1->session->pid;
844 printf("reading from file on connection 2\n");
846 if (smbcli_read(cli2->tree, fnum1, buf, 0, 13) == 13) {
847 printf("read succeeded! nasty security hole [%s]\n",
852 smbcli_close(cli1->tree, fnum1);
853 smbcli_unlink(cli1->tree, fname);
855 cli2->tree->tid = oldtid;
857 torture_close_connection(cli1);
858 torture_close_connection(cli2);
860 printf("finished fdpasstest\n");
866 This test checks that
868 1) the server does not allow an unlink on a file that is open
870 static BOOL run_unlinktest(void)
872 struct smbcli_state *cli;
873 const char *fname = "\\unlink.tst";
877 if (!torture_open_connection(&cli)) {
881 printf("starting unlink test\n");
883 smbcli_unlink(cli->tree, fname);
885 cli->session->pid = 1;
887 printf("Opening a file\n");
889 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
891 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
895 printf("Unlinking a open file\n");
897 if (NT_STATUS_IS_OK(smbcli_unlink(cli->tree, fname))) {
898 printf("error: server allowed unlink on an open file\n");
901 correct = check_error(__location__, cli, ERRDOS, ERRbadshare,
902 NT_STATUS_SHARING_VIOLATION);
905 smbcli_close(cli->tree, fnum);
906 smbcli_unlink(cli->tree, fname);
908 if (!torture_close_connection(cli)) {
912 printf("unlink test finished\n");
919 test the timing of deferred open requests
921 static BOOL run_deferopen(struct smbcli_state *cli, int dummy)
923 const char *fname = "\\defer_open_test.dat";
929 printf("failed to connect\n");
933 printf("Testing deferred open requests.\n");
939 struct timeval tv_start, tv_end;
940 GetTimeOfDay(&tv_start);
941 fnum = smbcli_nt_create_full(cli->tree, fname, 0, GENERIC_RIGHTS_FILE_ALL_ACCESS,
942 FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_NONE,
943 NTCREATEX_DISP_OPEN_IF, 0, 0);
947 GetTimeOfDay(&tv_end);
948 if (NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),NT_STATUS_SHARING_VIOLATION)) {
949 /* Sharing violation errors need to be 1 second apart. */
950 int64_t tdif = usec_time_diff(&tv_end, &tv_start);
951 if (tdif < 500000 || tdif > 1500000) {
952 fprintf(stderr,"Timing incorrect %lld.%lld for share violation\n",
953 tdif / (int64_t)1000000,
954 tdif % (int64_t)1000000);
957 } while (NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),NT_STATUS_SHARING_VIOLATION));
960 fprintf(stderr,"Failed to open %s, error=%s\n", fname, smbcli_errstr(cli->tree));
964 printf("pid %u open %d\n", getpid(), i);
968 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum))) {
969 fprintf(stderr,"Failed to close %s, error=%s\n", fname, smbcli_errstr(cli->tree));
975 if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fname))) {
976 /* All until the last unlink will fail with sharing violation. */
977 if (!NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),NT_STATUS_SHARING_VIOLATION)) {
978 printf("unlink of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
983 printf("deferred test finished\n");
984 if (!torture_close_connection(cli)) {
991 test how many open files this server supports on the one socket
993 static BOOL run_maxfidtest(struct smbcli_state *cli, int dummy)
995 #define MAXFID_TEMPLATE "\\maxfid\\fid%d\\maxfid.%d.%d"
997 int fnums[0x11000], i;
998 int retries=4, maxfid;
1002 printf("failed to connect\n");
1006 if (smbcli_deltree(cli->tree, "\\maxfid") == -1) {
1007 printf("Failed to deltree \\maxfid - %s\n",
1008 smbcli_errstr(cli->tree));
1011 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, "\\maxfid"))) {
1012 printf("Failed to mkdir \\maxfid, error=%s\n",
1013 smbcli_errstr(cli->tree));
1017 printf("Testing maximum number of open files\n");
1019 for (i=0; i<0x11000; i++) {
1020 if (i % 1000 == 0) {
1021 asprintf(&fname, "\\maxfid\\fid%d", i/1000);
1022 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, fname))) {
1023 printf("Failed to mkdir %s, error=%s\n",
1024 fname, smbcli_errstr(cli->tree));
1029 asprintf(&fname, MAXFID_TEMPLATE, i/1000, i,(int)getpid());
1030 if ((fnums[i] = smbcli_open(cli->tree, fname,
1031 O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) ==
1033 printf("open of %s failed (%s)\n",
1034 fname, smbcli_errstr(cli->tree));
1035 printf("maximum fnum is %d\n", i);
1046 printf("cleaning up\n");
1047 for (i=0;i<maxfid/2;i++) {
1048 asprintf(&fname, MAXFID_TEMPLATE, i/1000, i,(int)getpid());
1049 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnums[i]))) {
1050 printf("Close of fnum %d failed - %s\n", fnums[i], smbcli_errstr(cli->tree));
1052 if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fname))) {
1053 printf("unlink of %s failed (%s)\n",
1054 fname, smbcli_errstr(cli->tree));
1059 asprintf(&fname, MAXFID_TEMPLATE, (maxfid-i)/1000, maxfid-i,(int)getpid());
1060 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnums[maxfid-i]))) {
1061 printf("Close of fnum %d failed - %s\n", fnums[maxfid-i], smbcli_errstr(cli->tree));
1063 if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fname))) {
1064 printf("unlink of %s failed (%s)\n",
1065 fname, smbcli_errstr(cli->tree));
1070 printf("%6d %6d\r", i, maxfid-i);
1074 if (smbcli_deltree(cli->tree, "\\maxfid") == -1) {
1075 printf("Failed to deltree \\maxfid - %s\n",
1076 smbcli_errstr(cli->tree));
1080 printf("maxfid test finished\n");
1081 if (!torture_close_connection(cli)) {
1085 #undef MAXFID_TEMPLATE
1088 /* send smb negprot commands, not reading the response */
1089 static BOOL run_negprot_nowait(void)
1092 struct smbcli_state *cli, *cli2;
1093 BOOL correct = True;
1095 printf("starting negprot nowait test\n");
1097 cli = open_nbt_connection();
1102 printf("Filling send buffer\n");
1104 for (i=0;i<10000;i++) {
1105 struct smbcli_request *req;
1106 time_t t1 = time(NULL);
1107 req = smb_negprot_send(cli->transport, PROTOCOL_NT1);
1108 while (req->state == SMBCLI_REQUEST_SEND && time(NULL) < t1+5) {
1109 smbcli_transport_process(cli->transport);
1111 if (req->state == SMBCLI_REQUEST_ERROR) {
1112 printf("Failed to fill pipe - %s\n", nt_errstr(req->status));
1113 torture_close_connection(cli);
1116 if (req->state == SMBCLI_REQUEST_SEND) {
1122 printf("send buffer failed to fill\n");
1123 if (!torture_close_connection(cli)) {
1129 printf("send buffer filled after %d requests\n", i);
1131 printf("Opening secondary connection\n");
1132 if (!torture_open_connection(&cli2)) {
1136 if (!torture_close_connection(cli)) {
1140 if (!torture_close_connection(cli2)) {
1144 printf("finished negprot nowait test\n");
1151 This checks how the getatr calls works
1153 static BOOL run_attrtest(void)
1155 struct smbcli_state *cli;
1158 const char *fname = "\\attrib123456789.tst";
1159 BOOL correct = True;
1161 printf("starting attrib test\n");
1163 if (!torture_open_connection(&cli)) {
1167 smbcli_unlink(cli->tree, fname);
1168 fnum = smbcli_open(cli->tree, fname,
1169 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1170 smbcli_close(cli->tree, fnum);
1172 if (NT_STATUS_IS_ERR(smbcli_getatr(cli->tree, fname, NULL, NULL, &t))) {
1173 printf("getatr failed (%s)\n", smbcli_errstr(cli->tree));
1177 printf("New file time is %s", ctime(&t));
1179 if (abs(t - time(NULL)) > 60*60*24*10) {
1180 printf("ERROR: SMBgetatr bug. time is %s",
1186 t2 = t-60*60*24; /* 1 day ago */
1188 printf("Setting file time to %s", ctime(&t2));
1190 if (NT_STATUS_IS_ERR(smbcli_setatr(cli->tree, fname, 0, t2))) {
1191 printf("setatr failed (%s)\n", smbcli_errstr(cli->tree));
1195 if (NT_STATUS_IS_ERR(smbcli_getatr(cli->tree, fname, NULL, NULL, &t))) {
1196 printf("getatr failed (%s)\n", smbcli_errstr(cli->tree));
1200 printf("Retrieved file time as %s", ctime(&t));
1203 printf("ERROR: getatr/setatr bug. times are\n%s",
1205 printf("%s", ctime(&t2));
1209 smbcli_unlink(cli->tree, fname);
1211 if (!torture_close_connection(cli)) {
1215 printf("attrib test finished\n");
1222 This checks a couple of trans2 calls
1224 static BOOL run_trans2test(void)
1226 struct smbcli_state *cli;
1229 time_t c_time, a_time, m_time, w_time, m_time2;
1230 const char *fname = "\\trans2.tst";
1231 const char *dname = "\\trans2";
1232 const char *fname2 = "\\trans2\\trans2.tst";
1234 BOOL correct = True;
1236 printf("starting trans2 test\n");
1238 if (!torture_open_connection(&cli)) {
1242 smbcli_unlink(cli->tree, fname);
1244 printf("Testing qfileinfo\n");
1246 fnum = smbcli_open(cli->tree, fname,
1247 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1248 if (NT_STATUS_IS_ERR(smbcli_qfileinfo(cli->tree, fnum, NULL, &size, &c_time, &a_time, &m_time,
1250 printf("ERROR: qfileinfo failed (%s)\n", smbcli_errstr(cli->tree));
1254 printf("Testing NAME_INFO\n");
1256 if (NT_STATUS_IS_ERR(smbcli_qfilename(cli->tree, fnum, &pname))) {
1257 printf("ERROR: qfilename failed (%s)\n", smbcli_errstr(cli->tree));
1261 if (!pname || strcmp(pname, fname)) {
1262 printf("qfilename gave different name? [%s] [%s]\n",
1267 smbcli_close(cli->tree, fnum);
1268 smbcli_unlink(cli->tree, fname);
1270 fnum = smbcli_open(cli->tree, fname,
1271 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1273 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
1276 smbcli_close(cli->tree, fnum);
1278 printf("Checking for sticky create times\n");
1280 if (NT_STATUS_IS_ERR(smbcli_qpathinfo(cli->tree, fname, &c_time, &a_time, &m_time, &size, NULL))) {
1281 printf("ERROR: qpathinfo failed (%s)\n", smbcli_errstr(cli->tree));
1284 if (c_time != m_time) {
1285 printf("create time=%s", ctime(&c_time));
1286 printf("modify time=%s", ctime(&m_time));
1287 printf("This system appears to have sticky create times\n");
1289 if (a_time % (60*60) == 0) {
1290 printf("access time=%s", ctime(&a_time));
1291 printf("This system appears to set a midnight access time\n");
1295 if (abs(m_time - time(NULL)) > 60*60*24*7) {
1296 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
1302 smbcli_unlink(cli->tree, fname);
1303 fnum = smbcli_open(cli->tree, fname,
1304 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1305 smbcli_close(cli->tree, fnum);
1306 if (NT_STATUS_IS_ERR(smbcli_qpathinfo2(cli->tree, fname, &c_time, &a_time, &m_time, &w_time, &size, NULL, NULL))) {
1307 printf("ERROR: qpathinfo2 failed (%s)\n", smbcli_errstr(cli->tree));
1310 if (w_time < 60*60*24*2) {
1311 printf("write time=%s", ctime(&w_time));
1312 printf("This system appears to set a initial 0 write time\n");
1317 smbcli_unlink(cli->tree, fname);
1320 /* check if the server updates the directory modification time
1321 when creating a new file */
1322 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, dname))) {
1323 printf("ERROR: mkdir failed (%s)\n", smbcli_errstr(cli->tree));
1327 if (NT_STATUS_IS_ERR(smbcli_qpathinfo2(cli->tree, "\\trans2\\", &c_time, &a_time, &m_time, &w_time, &size, NULL, NULL))) {
1328 printf("ERROR: qpathinfo2 failed (%s)\n", smbcli_errstr(cli->tree));
1332 fnum = smbcli_open(cli->tree, fname2,
1333 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1334 smbcli_write(cli->tree, fnum, 0, (char *)&fnum, 0, sizeof(fnum));
1335 smbcli_close(cli->tree, fnum);
1336 if (NT_STATUS_IS_ERR(smbcli_qpathinfo2(cli->tree, "\\trans2\\", &c_time, &a_time, &m_time2, &w_time, &size, NULL, NULL))) {
1337 printf("ERROR: qpathinfo2 failed (%s)\n", smbcli_errstr(cli->tree));
1340 if (m_time2 == m_time) {
1341 printf("This system does not update directory modification times\n");
1345 smbcli_unlink(cli->tree, fname2);
1346 smbcli_rmdir(cli->tree, dname);
1348 if (!torture_close_connection(cli)) {
1352 printf("trans2 test finished\n");
1359 print out server properties
1361 static BOOL run_properties(void)
1363 struct smbcli_state *cli;
1364 BOOL correct = True;
1366 printf("starting properties test\n");
1370 if (!torture_open_connection(&cli)) {
1374 d_printf("Capabilities 0x%08x\n", cli->transport->negotiate.capabilities);
1376 if (!torture_close_connection(cli)) {
1385 /* FIRST_DESIRED_ACCESS 0xf019f */
1386 #define FIRST_DESIRED_ACCESS SA_RIGHT_FILE_READ_DATA|SA_RIGHT_FILE_WRITE_DATA|SA_RIGHT_FILE_APPEND_DATA|\
1387 SA_RIGHT_FILE_READ_EA| /* 0xf */ \
1388 SA_RIGHT_FILE_WRITE_EA|SA_RIGHT_FILE_READ_ATTRIBUTES| /* 0x90 */ \
1389 SA_RIGHT_FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
1390 STD_RIGHT_DELETE_ACCESS|STD_RIGHT_READ_CONTROL_ACCESS|\
1391 STD_RIGHT_WRITE_DAC_ACCESS|STD_RIGHT_WRITE_OWNER_ACCESS /* 0xf0000 */
1392 /* SECOND_DESIRED_ACCESS 0xe0080 */
1393 #define SECOND_DESIRED_ACCESS SA_RIGHT_FILE_READ_ATTRIBUTES| /* 0x80 */ \
1394 STD_RIGHT_READ_CONTROL_ACCESS|STD_RIGHT_WRITE_DAC_ACCESS|\
1395 STD_RIGHT_WRITE_OWNER_ACCESS /* 0xe0000 */
1398 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
1399 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
1400 SA_RIGHT_FILE_READ_DATA|\
1401 WRITE_OWNER_ACCESS /* */
1405 Test ntcreate calls made by xcopy
1407 static BOOL run_xcopy(void)
1409 struct smbcli_state *cli1;
1410 const char *fname = "\\test.txt";
1411 BOOL correct = True;
1414 printf("starting xcopy test\n");
1416 if (!torture_open_connection(&cli1)) {
1420 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0,
1421 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
1422 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF,
1426 printf("First open failed - %s\n", smbcli_errstr(cli1->tree));
1430 fnum2 = smbcli_nt_create_full(cli1->tree, fname, 0,
1431 SECOND_DESIRED_ACCESS, 0,
1432 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN,
1435 printf("second open failed - %s\n", smbcli_errstr(cli1->tree));
1439 if (!torture_close_connection(cli1)) {
1448 see how many RPC pipes we can open at once
1450 static BOOL run_pipe_number(void)
1452 struct smbcli_state *cli1;
1453 const char *pipe_name = "\\WKSSVC";
1457 printf("starting pipenumber test\n");
1458 if (!torture_open_connection(&cli1)) {
1463 fnum = smbcli_nt_create_full(cli1->tree, pipe_name, 0, SA_RIGHT_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
1464 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1467 printf("Open of pipe %s failed with error (%s)\n", pipe_name, smbcli_errstr(cli1->tree));
1471 printf("%d\r", num_pipes);
1475 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes, pipe_name );
1476 torture_close_connection(cli1);
1484 open N connections to the server and just hold them open
1485 used for testing performance when there are N idle users
1488 static BOOL torture_holdcon(void)
1491 struct smbcli_state **cli;
1494 printf("Opening %d connections\n", torture_numops);
1496 cli = malloc(sizeof(struct smbcli_state *) * torture_numops);
1498 for (i=0;i<torture_numops;i++) {
1499 if (!torture_open_connection(&cli[i])) {
1502 printf("opened %d connections\r", i);
1506 printf("\nStarting pings\n");
1509 for (i=0;i<torture_numops;i++) {
1512 status = smbcli_chkpath(cli[i]->tree, "\\");
1513 if (!NT_STATUS_IS_OK(status)) {
1514 printf("Connection %d is dead\n", i);
1522 if (num_dead == torture_numops) {
1523 printf("All connections dead - finishing\n");
1535 Try with a wrong vuid and check error message.
1538 static BOOL run_vuidtest(void)
1540 struct smbcli_state *cli;
1541 const char *fname = "\\vuid.tst";
1544 time_t c_time, a_time, m_time;
1545 BOOL correct = True;
1550 printf("starting vuid test\n");
1552 if (!torture_open_connection(&cli)) {
1556 smbcli_unlink(cli->tree, fname);
1558 fnum = smbcli_open(cli->tree, fname,
1559 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1561 orig_vuid = cli->session->vuid;
1563 cli->session->vuid += 1234;
1565 printf("Testing qfileinfo with wrong vuid\n");
1567 if (NT_STATUS_IS_OK(result = smbcli_qfileinfo(cli->tree, fnum, NULL,
1568 &size, &c_time, &a_time,
1569 &m_time, NULL, NULL))) {
1570 printf("ERROR: qfileinfo passed with wrong vuid\n");
1574 if ( (cli->transport->error.etype != ETYPE_DOS) ||
1575 (cli->transport->error.e.dos.eclass != ERRSRV) ||
1576 (cli->transport->error.e.dos.ecode != ERRbaduid) ) {
1577 printf("ERROR: qfileinfo should have returned DOS error "
1578 "ERRSRV:ERRbaduid\n but returned %s\n",
1579 smbcli_errstr(cli->tree));
1583 cli->session->vuid -= 1234;
1585 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum))) {
1586 printf("close failed (%s)\n", smbcli_errstr(cli->tree));
1590 smbcli_unlink(cli->tree, fname);
1592 if (!torture_close_connection(cli)) {
1596 printf("vuid test finished\n");
1602 Test open mode returns on read-only files.
1604 static BOOL run_opentest(void)
1606 static struct smbcli_state *cli1;
1607 static struct smbcli_state *cli2;
1608 const char *fname = "\\readonly.file";
1612 BOOL correct = True;
1616 printf("starting open test\n");
1618 if (!torture_open_connection(&cli1)) {
1622 smbcli_setatr(cli1->tree, fname, 0, 0);
1623 smbcli_unlink(cli1->tree, fname);
1625 fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1627 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1631 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1632 printf("close2 failed (%s)\n", smbcli_errstr(cli1->tree));
1636 if (NT_STATUS_IS_ERR(smbcli_setatr(cli1->tree, fname, FILE_ATTRIBUTE_READONLY, 0))) {
1637 printf("smbcli_setatr failed (%s)\n", smbcli_errstr(cli1->tree));
1638 CHECK_MAX_FAILURES(error_test1);
1642 fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY, DENY_WRITE);
1644 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1645 CHECK_MAX_FAILURES(error_test1);
1649 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
1650 fnum2 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_ALL);
1652 if (check_error(__location__, cli1, ERRDOS, ERRnoaccess,
1653 NT_STATUS_ACCESS_DENIED)) {
1654 printf("correct error code ERRDOS/ERRnoaccess returned\n");
1657 printf("finished open test 1\n");
1659 smbcli_close(cli1->tree, fnum1);
1661 /* Now try not readonly and ensure ERRbadshare is returned. */
1663 smbcli_setatr(cli1->tree, fname, 0, 0);
1665 fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY, DENY_WRITE);
1667 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1671 /* This will fail - but the error should be ERRshare. */
1672 fnum2 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_ALL);
1674 if (check_error(__location__, cli1, ERRDOS, ERRbadshare,
1675 NT_STATUS_SHARING_VIOLATION)) {
1676 printf("correct error code ERRDOS/ERRbadshare returned\n");
1679 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1680 printf("close2 failed (%s)\n", smbcli_errstr(cli1->tree));
1684 smbcli_unlink(cli1->tree, fname);
1686 printf("finished open test 2\n");
1688 /* Test truncate open disposition on file opened for read. */
1690 fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1692 printf("(3) open (1) of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1696 /* write 20 bytes. */
1698 memset(buf, '\0', 20);
1700 if (smbcli_write(cli1->tree, fnum1, 0, buf, 0, 20) != 20) {
1701 printf("write failed (%s)\n", smbcli_errstr(cli1->tree));
1705 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1706 printf("(3) close1 failed (%s)\n", smbcli_errstr(cli1->tree));
1710 /* Ensure size == 20. */
1711 if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
1712 printf("(3) getatr failed (%s)\n", smbcli_errstr(cli1->tree));
1713 CHECK_MAX_FAILURES(error_test3);
1718 printf("(3) file size != 20\n");
1719 CHECK_MAX_FAILURES(error_test3);
1723 /* Now test if we can truncate a file opened for readonly. */
1725 fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY|O_TRUNC, DENY_NONE);
1727 printf("(3) open (2) of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1728 CHECK_MAX_FAILURES(error_test3);
1732 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1733 printf("close2 failed (%s)\n", smbcli_errstr(cli1->tree));
1737 /* Ensure size == 0. */
1738 if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
1739 printf("(3) getatr failed (%s)\n", smbcli_errstr(cli1->tree));
1740 CHECK_MAX_FAILURES(error_test3);
1745 printf("(3) file size != 0\n");
1746 CHECK_MAX_FAILURES(error_test3);
1749 printf("finished open test 3\n");
1751 smbcli_unlink(cli1->tree, fname);
1754 printf("testing ctemp\n");
1755 fnum1 = smbcli_ctemp(cli1->tree, "\\", &tmp_path);
1757 printf("ctemp failed (%s)\n", smbcli_errstr(cli1->tree));
1758 CHECK_MAX_FAILURES(error_test4);
1761 printf("ctemp gave path %s\n", tmp_path);
1762 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1763 printf("close of temp failed (%s)\n", smbcli_errstr(cli1->tree));
1765 if (NT_STATUS_IS_ERR(smbcli_unlink(cli1->tree, tmp_path))) {
1766 printf("unlink of temp failed (%s)\n", smbcli_errstr(cli1->tree));
1769 /* Test the non-io opens... */
1771 if (!torture_open_connection(&cli2)) {
1775 smbcli_setatr(cli2->tree, fname, 0, 0);
1776 smbcli_unlink(cli2->tree, fname);
1778 printf("TEST #1 testing 2 non-io opens (no delete)\n");
1780 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1781 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1784 printf("test 1 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1785 CHECK_MAX_FAILURES(error_test10);
1789 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1790 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1792 printf("test 1 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1793 CHECK_MAX_FAILURES(error_test10);
1797 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1798 printf("test 1 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1801 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1802 printf("test 1 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1806 printf("non-io open test #1 passed.\n");
1808 smbcli_unlink(cli1->tree, fname);
1810 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
1812 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1813 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1816 printf("test 2 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1817 CHECK_MAX_FAILURES(error_test20);
1821 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1822 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1825 printf("test 2 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1826 CHECK_MAX_FAILURES(error_test20);
1830 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1831 printf("test 1 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1834 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1835 printf("test 1 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1839 printf("non-io open test #2 passed.\n");
1841 smbcli_unlink(cli1->tree, fname);
1843 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
1845 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1846 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1849 printf("test 3 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1850 CHECK_MAX_FAILURES(error_test30);
1854 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1855 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1858 printf("test 3 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1859 CHECK_MAX_FAILURES(error_test30);
1863 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1864 printf("test 3 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1867 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1868 printf("test 3 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1872 printf("non-io open test #3 passed.\n");
1874 smbcli_unlink(cli1->tree, fname);
1876 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
1878 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1879 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1882 printf("test 4 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1883 CHECK_MAX_FAILURES(error_test40);
1887 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1888 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1891 printf("test 4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1892 CHECK_MAX_FAILURES(error_test40);
1896 printf("test 4 open 2 of %s gave %s (correct error should be %s)\n", fname, smbcli_errstr(cli2->tree), "sharing violation");
1898 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1899 printf("test 4 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1903 printf("non-io open test #4 passed.\n");
1905 smbcli_unlink(cli1->tree, fname);
1907 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
1909 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1910 NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1913 printf("test 5 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1914 CHECK_MAX_FAILURES(error_test50);
1918 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1919 NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1922 printf("test 5 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1923 CHECK_MAX_FAILURES(error_test50);
1927 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1928 printf("test 5 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1932 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1933 printf("test 5 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1937 printf("non-io open test #5 passed.\n");
1939 printf("TEST #6 testing 1 non-io open, one io open\n");
1941 smbcli_unlink(cli1->tree, fname);
1943 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SA_RIGHT_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
1944 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1947 printf("test 6 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1948 CHECK_MAX_FAILURES(error_test60);
1952 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1953 NTCREATEX_SHARE_ACCESS_READ, NTCREATEX_DISP_OPEN_IF, 0, 0);
1956 printf("test 6 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1957 CHECK_MAX_FAILURES(error_test60);
1961 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1962 printf("test 6 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1966 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1967 printf("test 6 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1971 printf("non-io open test #6 passed.\n");
1973 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
1975 smbcli_unlink(cli1->tree, fname);
1977 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SA_RIGHT_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
1978 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1981 printf("test 7 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1982 CHECK_MAX_FAILURES(error_test70);
1986 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1987 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1990 printf("test 7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1991 CHECK_MAX_FAILURES(error_test70);
1995 printf("test 7 open 2 of %s gave %s (correct error should be %s)\n", fname, smbcli_errstr(cli2->tree), "sharing violation");
1997 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1998 printf("test 7 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
2002 printf("non-io open test #7 passed.\n");
2006 printf("TEST #8 testing one normal open, followed by lock, followed by open with truncate\n");
2008 smbcli_unlink(cli1->tree, fname);
2010 fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
2012 printf("(8) open (1) of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
2016 /* write 20 bytes. */
2018 memset(buf, '\0', 20);
2020 if (smbcli_write(cli1->tree, fnum1, 0, buf, 0, 20) != 20) {
2021 printf("(8) write failed (%s)\n", smbcli_errstr(cli1->tree));
2025 /* Ensure size == 20. */
2026 if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
2027 printf("(8) getatr (1) failed (%s)\n", smbcli_errstr(cli1->tree));
2028 CHECK_MAX_FAILURES(error_test80);
2033 printf("(8) file size != 20\n");
2034 CHECK_MAX_FAILURES(error_test80);
2038 /* Get an exclusive lock on the open file. */
2039 if (NT_STATUS_IS_ERR(smbcli_lock(cli1->tree, fnum1, 0, 4, 0, WRITE_LOCK))) {
2040 printf("(8) lock1 failed (%s)\n", smbcli_errstr(cli1->tree));
2041 CHECK_MAX_FAILURES(error_test80);
2045 fnum2 = smbcli_open(cli1->tree, fname, O_RDWR|O_TRUNC, DENY_NONE);
2047 printf("(8) open (2) of %s with truncate failed (%s)\n", fname, smbcli_errstr(cli1->tree));
2051 /* Ensure size == 0. */
2052 if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
2053 printf("(8) getatr (2) failed (%s)\n", smbcli_errstr(cli1->tree));
2054 CHECK_MAX_FAILURES(error_test80);
2059 printf("(8) file size != 0\n");
2060 CHECK_MAX_FAILURES(error_test80);
2064 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
2065 printf("(8) close1 failed (%s)\n", smbcli_errstr(cli1->tree));
2069 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum2))) {
2070 printf("(8) close1 failed (%s)\n", smbcli_errstr(cli1->tree));
2076 printf("open test #8 passed.\n");
2078 smbcli_unlink(cli1->tree, fname);
2080 if (!torture_close_connection(cli1)) {
2083 if (!torture_close_connection(cli2)) {
2092 sees what IOCTLs are supported
2094 BOOL torture_ioctl_test(void)
2096 struct smbcli_state *cli;
2097 uint16_t device, function;
2099 const char *fname = "\\ioctl.dat";
2101 union smb_ioctl parms;
2102 TALLOC_CTX *mem_ctx;
2104 if (!torture_open_connection(&cli)) {
2108 mem_ctx = talloc_init("ioctl_test");
2110 printf("starting ioctl test\n");
2112 smbcli_unlink(cli->tree, fname);
2114 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2116 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
2120 parms.ioctl.level = RAW_IOCTL_IOCTL;
2121 parms.ioctl.in.fnum = fnum;
2122 parms.ioctl.in.request = IOCTL_QUERY_JOB_INFO;
2123 status = smb_raw_ioctl(cli->tree, mem_ctx, &parms);
2124 printf("ioctl job info: %s\n", smbcli_errstr(cli->tree));
2126 for (device=0;device<0x100;device++) {
2127 printf("testing device=0x%x\n", device);
2128 for (function=0;function<0x100;function++) {
2129 parms.ioctl.in.request = (device << 16) | function;
2130 status = smb_raw_ioctl(cli->tree, mem_ctx, &parms);
2132 if (NT_STATUS_IS_OK(status)) {
2133 printf("ioctl device=0x%x function=0x%x OK : %d bytes\n",
2134 device, function, parms.ioctl.out.blob.length);
2139 if (!torture_close_connection(cli)) {
2148 tries variants of chkpath
2150 BOOL torture_chkpath_test(void)
2152 struct smbcli_state *cli;
2156 if (!torture_open_connection(&cli)) {
2160 printf("starting chkpath test\n");
2162 printf("Testing valid and invalid paths\n");
2164 /* cleanup from an old run */
2165 smbcli_rmdir(cli->tree, "\\chkpath.dir\\dir2");
2166 smbcli_unlink(cli->tree, "\\chkpath.dir\\*");
2167 smbcli_rmdir(cli->tree, "\\chkpath.dir");
2169 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, "\\chkpath.dir"))) {
2170 printf("mkdir1 failed : %s\n", smbcli_errstr(cli->tree));
2174 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, "\\chkpath.dir\\dir2"))) {
2175 printf("mkdir2 failed : %s\n", smbcli_errstr(cli->tree));
2179 fnum = smbcli_open(cli->tree, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2181 printf("open1 failed (%s)\n", smbcli_errstr(cli->tree));
2184 smbcli_close(cli->tree, fnum);
2186 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir"))) {
2187 printf("chkpath1 failed: %s\n", smbcli_errstr(cli->tree));
2191 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\dir2"))) {
2192 printf("chkpath2 failed: %s\n", smbcli_errstr(cli->tree));
2196 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\foo.txt"))) {
2197 ret = check_error(__location__, cli, ERRDOS, ERRbadpath,
2198 NT_STATUS_NOT_A_DIRECTORY);
2200 printf("* chkpath on a file should fail\n");
2204 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\bar.txt"))) {
2205 ret = check_error(__location__, cli, ERRDOS, ERRbadfile,
2206 NT_STATUS_OBJECT_NAME_NOT_FOUND);
2208 printf("* chkpath on a non existent file should fail\n");
2212 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\dirxx\\bar.txt"))) {
2213 ret = check_error(__location__, cli, ERRDOS, ERRbadpath,
2214 NT_STATUS_OBJECT_PATH_NOT_FOUND);
2216 printf("* chkpath on a non existent component should fail\n");
2220 smbcli_rmdir(cli->tree, "\\chkpath.dir\\dir2");
2221 smbcli_unlink(cli->tree, "\\chkpath.dir\\*");
2222 smbcli_rmdir(cli->tree, "\\chkpath.dir");
2224 if (!torture_close_connection(cli)) {
2233 parse a //server/share type UNC name
2235 static BOOL parse_unc(const char *unc_name, char **hostname, char **sharename)
2239 if (strncmp(unc_name, "//", 2)) {
2243 *hostname = strdup(&unc_name[2]);
2244 p = strchr_m(&(*hostname)[2],'/');
2249 *sharename = strdup(p+1);
2256 static void sigcont(int sig)
2260 double torture_create_procs(BOOL (*fn)(struct smbcli_state *, int), BOOL *result)
2263 volatile pid_t *child_status;
2264 volatile BOOL *child_status_out;
2267 double start_time_limit = 10 + (torture_nprocs * 1.5);
2268 char **unc_list = NULL;
2270 int num_unc_names = 0;
2274 signal(SIGCONT, sigcont);
2276 child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*torture_nprocs);
2277 if (!child_status) {
2278 printf("Failed to setup shared memory\n");
2282 child_status_out = (volatile BOOL *)shm_setup(sizeof(BOOL)*torture_nprocs);
2283 if (!child_status_out) {
2284 printf("Failed to setup result status shared memory\n");
2288 p = lp_parm_string(-1, "torture", "unclist");
2290 unc_list = file_lines_load(p, &num_unc_names);
2291 if (!unc_list || num_unc_names <= 0) {
2292 printf("Failed to load unc names list from '%s'\n", p);
2297 for (i = 0; i < torture_nprocs; i++) {
2298 child_status[i] = 0;
2299 child_status_out[i] = True;
2304 for (i=0;i<torture_nprocs;i++) {
2308 char *hostname=NULL, *sharename;
2310 pid_t mypid = getpid();
2311 sys_srandom(((int)mypid) ^ ((int)time(NULL)));
2313 asprintf(&myname, "CLIENT%d", i);
2314 lp_set_cmdline("netbios name", myname);
2319 if (!parse_unc(unc_list[i % num_unc_names],
2320 &hostname, &sharename)) {
2321 printf("Failed to parse UNC name %s\n",
2322 unc_list[i % num_unc_names]);
2329 if (torture_open_connection_share(¤t_cli,
2334 } else if (torture_open_connection(¤t_cli)) {
2338 printf("pid %d failed to start\n", (int)getpid());
2344 child_status[i] = getpid();
2348 if (child_status[i]) {
2349 printf("Child %d failed to start!\n", i);
2350 child_status_out[i] = 1;
2354 child_status_out[i] = fn(current_cli, i);
2361 for (i=0;i<torture_nprocs;i++) {
2362 if (child_status[i]) synccount++;
2364 if (synccount == torture_nprocs) break;
2366 } while (end_timer() < start_time_limit);
2368 if (synccount != torture_nprocs) {
2369 printf("FAILED TO START %d CLIENTS (started %d)\n", torture_nprocs, synccount);
2374 printf("Starting %d clients\n", torture_nprocs);
2376 /* start the client load */
2378 for (i=0;i<torture_nprocs;i++) {
2379 child_status[i] = 0;
2383 printf("%d clients started\n", torture_nprocs);
2385 for (i=0;i<torture_nprocs;i++) {
2387 while ((ret=sys_waitpid(0, &status, 0)) == -1 && errno == EINTR) /* noop */ ;
2388 if (ret == -1 || WEXITSTATUS(status) != 0) {
2395 for (i=0;i<torture_nprocs;i++) {
2396 if (!child_status_out[i]) {
2403 #define FLAG_MULTIPROC 1
2408 BOOL (*multi_fn)(struct smbcli_state *, int );
2411 {"BASE-FDPASS", run_fdpasstest, 0},
2412 {"BASE-LOCK1", torture_locktest1, 0},
2413 {"BASE-LOCK2", torture_locktest2, 0},
2414 {"BASE-LOCK3", torture_locktest3, 0},
2415 {"BASE-LOCK4", torture_locktest4, 0},
2416 {"BASE-LOCK5", torture_locktest5, 0},
2417 {"BASE-LOCK6", torture_locktest6, 0},
2418 {"BASE-LOCK7", torture_locktest7, 0},
2419 {"BASE-UNLINK", run_unlinktest, 0},
2420 {"BASE-ATTR", run_attrtest, 0},
2421 {"BASE-TRANS2", run_trans2test, 0},
2422 {"BASE-NEGNOWAIT", run_negprot_nowait, 0},
2423 {"BASE-DIR1", torture_dirtest1, 0},
2424 {"BASE-DIR2", torture_dirtest2, 0},
2425 {"BASE-DENY1", torture_denytest1, 0},
2426 {"BASE-DENY2", torture_denytest2, 0},
2427 {"BASE-DENY3", torture_denytest3, 0},
2428 {"BASE-NTDENY1", NULL, torture_ntdenytest1},
2429 {"BASE-NTDENY2", torture_ntdenytest2, 0},
2430 {"BASE-TCON", run_tcon_test, 0},
2431 {"BASE-TCONDEV", run_tcon_devtype_test, 0},
2432 {"BASE-VUID", run_vuidtest, 0},
2433 {"BASE-RW1", run_readwritetest, 0},
2434 {"BASE-RW2", NULL, run_readwritemulti},
2435 {"BASE-OPEN", run_opentest, 0},
2436 {"BASE-DEFER_OPEN", NULL, run_deferopen},
2437 {"BASE-XCOPY", run_xcopy, 0},
2438 {"BASE-RENAME", torture_test_rename, 0},
2439 {"BASE-DELETE", torture_test_delete, 0},
2440 {"BASE-PROPERTIES", run_properties, 0},
2441 {"BASE-MANGLE", torture_mangle, 0},
2442 {"BASE-OPENATTR", torture_openattrtest, 0},
2443 {"BASE-CHARSET", torture_charset, 0},
2444 {"BASE-CHKPATH", torture_chkpath_test, 0},
2445 {"BASE-SECLEAK", torture_sec_leak, 0},
2447 /* benchmarking tests */
2448 {"BENCH-HOLDCON", torture_holdcon, 0},
2449 {"BENCH-NBENCH", torture_nbench, 0},
2450 {"BENCH-TORTURE", NULL, run_torture},
2453 {"RAW-QFSINFO", torture_raw_qfsinfo, 0},
2454 {"RAW-QFILEINFO", torture_raw_qfileinfo, 0},
2455 {"RAW-SFILEINFO", torture_raw_sfileinfo, 0},
2456 {"RAW-SFILEINFO-BUG", torture_raw_sfileinfo_bug, 0},
2457 {"RAW-SEARCH", torture_raw_search, 0},
2458 {"RAW-CLOSE", torture_raw_close, 0},
2459 {"RAW-OPEN", torture_raw_open, 0},
2460 {"RAW-MKDIR", torture_raw_mkdir, 0},
2461 {"RAW-OPLOCK", torture_raw_oplock, 0},
2462 {"RAW-NOTIFY", torture_raw_notify, 0},
2463 {"RAW-MUX", torture_raw_mux, 0},
2464 {"RAW-IOCTL", torture_raw_ioctl, 0},
2465 {"RAW-CHKPATH", torture_raw_chkpath, 0},
2466 {"RAW-UNLINK", torture_raw_unlink, 0},
2467 {"RAW-READ", torture_raw_read, 0},
2468 {"RAW-WRITE", torture_raw_write, 0},
2469 {"RAW-LOCK", torture_raw_lock, 0},
2470 {"RAW-CONTEXT", torture_raw_context, 0},
2471 {"RAW-RENAME", torture_raw_rename, 0},
2472 {"RAW-SEEK", torture_raw_seek, 0},
2473 {"RAW-RAP", torture_raw_rap, 0},
2475 /* protocol scanners */
2476 {"SCAN-TRANS2", torture_trans2_scan, 0},
2477 {"SCAN-NTTRANS", torture_nttrans_scan, 0},
2478 {"SCAN-ALIASES", torture_trans2_aliases, 0},
2479 {"SCAN-SMB", torture_smb_scan, 0},
2480 {"SCAN-MAXFID", NULL, run_maxfidtest},
2481 {"SCAN-UTABLE", torture_utable, 0},
2482 {"SCAN-CASETABLE", torture_casetable, 0},
2483 {"SCAN-PIPE_NUMBER", run_pipe_number, 0},
2484 {"SCAN-IOCTL", torture_ioctl_test, 0},
2487 {"RPC-LSA", torture_rpc_lsa, 0},
2488 {"RPC-ECHO", torture_rpc_echo, 0},
2489 {"RPC-DFS", torture_rpc_dfs, 0},
2490 {"RPC-SPOOLSS", torture_rpc_spoolss, 0},
2491 {"RPC-SAMR", torture_rpc_samr, 0},
2492 {"RPC-NETLOGON", torture_rpc_netlogon, 0},
2493 {"RPC-SCHANNEL", torture_rpc_schannel, 0},
2494 {"RPC-WKSSVC", torture_rpc_wkssvc, 0},
2495 {"RPC-SRVSVC", torture_rpc_srvsvc, 0},
2496 {"RPC-SVCCTL", torture_rpc_svcctl, 0},
2497 {"RPC-ATSVC", torture_rpc_atsvc, 0},
2498 {"RPC-EVENTLOG", torture_rpc_eventlog, 0},
2499 {"RPC-EPMAPPER", torture_rpc_epmapper, 0},
2500 {"RPC-WINREG", torture_rpc_winreg, 0},
2501 {"RPC-OXIDRESOLVE", torture_rpc_oxidresolve, 0},
2502 {"RPC-REMACT", torture_rpc_remact, 0},
2503 {"RPC-MGMT", torture_rpc_mgmt, 0},
2504 {"RPC-SCANNER", torture_rpc_scanner, 0},
2505 {"RPC-AUTOIDL", torture_rpc_autoidl, 0},
2506 {"RPC-COUNTCALLS", torture_rpc_countcalls, 0},
2507 {"RPC-MULTIBIND", torture_multi_bind, 0},
2508 {"RPC-DRSUAPI", torture_rpc_drsuapi, 0},
2510 /* local (no server) testers */
2511 {"LOCAL-NTLMSSP", torture_ntlmssp_self_check, 0},
2512 {"LOCAL-ICONV", torture_local_iconv, 0},
2513 {"LOCAL-TALLOC", torture_local_talloc, 0},
2514 {"LOCAL-MESSAGING", torture_local_messaging, 0},
2515 {"LOCAL-BINDING", torture_local_binding_string, 0},
2516 {"LOCAL-IDTREE", torture_local_idtree, 0},
2519 {"LDAP-BASIC", torture_ldap_basic, 0},
2525 /****************************************************************************
2526 run a specified test or "ALL"
2527 ****************************************************************************/
2528 static BOOL run_test(const char *name)
2532 BOOL matched = False;
2534 if (strequal(name,"ALL")) {
2535 for (i=0;torture_ops[i].name;i++) {
2536 if (!run_test(torture_ops[i].name)) {
2543 for (i=0;torture_ops[i].name;i++) {
2544 if (gen_fnmatch(name, torture_ops[i].name) == 0) {
2548 printf("Running %s\n", torture_ops[i].name);
2549 if (torture_ops[i].multi_fn) {
2551 t = torture_create_procs(torture_ops[i].multi_fn,
2555 printf("TEST %s FAILED!\n", torture_ops[i].name);
2560 if (!torture_ops[i].fn()) {
2562 printf("TEST %s FAILED!\n", torture_ops[i].name);
2566 printf("%s took %g secs\n\n", torture_ops[i].name, t);
2571 printf("Unknown torture operation '%s'\n", name);
2578 static void parse_dns(const char *dns)
2580 char *userdn, *basedn, *secret;
2583 /* retrievieng the userdn */
2584 p = strchr_m(dns, '#');
2586 lp_set_cmdline("torture:ldap_userdn", "");
2587 lp_set_cmdline("torture:ldap_basedn", "");
2588 lp_set_cmdline("torture:ldap_secret", "");
2591 userdn = strndup(dns, p - dns);
2592 lp_set_cmdline("torture:ldap_userdn", userdn);
2594 /* retrieve the basedn */
2596 p = strchr_m(d, '#');
2598 lp_set_cmdline("torture:ldap_basedn", "");
2599 lp_set_cmdline("torture:ldap_secret", "");
2602 basedn = strndup(d, p - d);
2603 lp_set_cmdline("torture:ldap_basedn", basedn);
2605 /* retrieve the secret */
2608 lp_set_cmdline("torture:ldap_secret", "");
2612 lp_set_cmdline("torture:ldap_secret", secret);
2614 printf ("%s - %s - %s\n", userdn, basedn, secret);
2618 static void usage(poptContext pc)
2623 poptPrintUsage(pc, stdout, 0);
2626 printf("tests are:");
2627 for (i=0;torture_ops[i].name;i++) {
2628 if ((i%perline)==0) {
2631 printf("%s ", torture_ops[i].name);
2635 printf("default test is ALL\n");
2640 static BOOL is_binding_string(const char *binding_string)
2642 TALLOC_CTX *mem_ctx = talloc_init("is_binding_string");
2643 struct dcerpc_binding binding_struct;
2646 status = dcerpc_parse_binding(mem_ctx, binding_string, &binding_struct);
2648 talloc_destroy(mem_ctx);
2649 return NT_STATUS_IS_OK(status);
2652 /****************************************************************************
2654 ****************************************************************************/
2655 int main(int argc,char *argv[])
2659 BOOL correct = True;
2663 enum {OPT_LOADFILE=1000,OPT_UNCLIST,OPT_TIMELIMIT,OPT_DNS,OPT_DANGEROUS};
2664 struct poptOption long_options[] = {
2666 {"smb-ports", 'p', POPT_ARG_STRING, NULL, 0, "SMB ports", NULL},
2667 {"seed", 0, POPT_ARG_INT, &torture_seed, 0, "seed", NULL},
2668 {"num-progs", 0, POPT_ARG_INT, &torture_nprocs, 0, "num progs", NULL},
2669 {"num-ops", 0, POPT_ARG_INT, &torture_numops, 0, "num ops", NULL},
2670 {"entries", 0, POPT_ARG_INT, &torture_entries, 0, "entries", NULL},
2671 {"use-oplocks", 'L', POPT_ARG_NONE, &use_oplocks, 0, "use oplocks", NULL},
2672 {"show-all", 0, POPT_ARG_NONE, &torture_showall, 0, "show all", NULL},
2673 {"loadfile", 0, POPT_ARG_STRING, NULL, OPT_LOADFILE, "loadfile", NULL},
2674 {"unclist", 0, POPT_ARG_STRING, NULL, OPT_UNCLIST, "unclist", NULL},
2675 {"timelimit", 't', POPT_ARG_STRING, NULL, OPT_TIMELIMIT, "timelimit", NULL},
2676 {"failures", 'f', POPT_ARG_INT, &torture_failures, 0, "failures", NULL},
2677 {"parse-dns", 'D', POPT_ARG_STRING, NULL, OPT_DNS, "parse-dns", NULL},
2678 {"dangerous", 'X', POPT_ARG_NONE, NULL, OPT_DANGEROUS, "dangerous", NULL},
2680 POPT_COMMON_CONNECTION
2681 POPT_COMMON_CREDENTIALS
2686 setup_logging("smbtorture", DEBUG_STDOUT);
2688 #ifdef HAVE_SETBUFFER
2689 setbuffer(stdout, NULL, 0);
2692 pc = poptGetContext("smbtorture", argc, (const char **) argv, long_options,
2693 POPT_CONTEXT_KEEP_FIRST);
2695 poptSetOtherOptionHelp(pc, "<binding>|<unc> TEST1 TEST2 ...");
2697 while((opt = poptGetNextOpt(pc)) != -1) {
2700 lp_set_cmdline("torture:loadfile", poptGetOptArg(pc));
2703 lp_set_cmdline("torture:unclist", poptGetOptArg(pc));
2706 lp_set_cmdline("torture:timelimit", poptGetOptArg(pc));
2709 parse_dns(poptGetOptArg(pc));
2712 lp_set_cmdline("torture:dangerous", "1");
2715 d_printf("Invalid option %s: %s\n",
2716 poptBadOption(pc, 0), poptStrerror(opt));
2722 lp_load(dyn_CONFIGFILE,True,False,False);
2724 if (torture_seed == 0) {
2725 torture_seed = time(NULL);
2727 printf("Using seed %d\n", torture_seed);
2728 srandom(torture_seed);
2730 argv_new = discard_const_p(char *, poptGetArgs(pc));
2733 for (i=0; i<argc; i++) {
2734 if (argv_new[i] == NULL) {
2745 for(p = argv_new[1]; *p; p++) {
2750 /* see if its a RPC transport specifier */
2751 if (is_binding_string(argv_new[1])) {
2752 lp_set_cmdline("torture:binding", argv_new[1]);
2754 char *binding = NULL;
2755 char *host = NULL, *share = NULL;
2757 if (!parse_unc(argv_new[1], &host, &share)) {
2758 d_printf("Invalid option: %s is not a valid torture target (share or binding string)\n\n", argv_new[1]);
2762 lp_set_cmdline("torture:host", host);
2763 lp_set_cmdline("torture:share", share);
2764 asprintf(&binding, "ncacn_np:%s", host);
2765 lp_set_cmdline("torture:binding", binding);
2768 if (!lp_parm_string(-1,"torture","username")) {
2769 lp_set_cmdline("torture:username", cmdline_get_username());
2771 if (!lp_parm_string(-1,"torture","userdomain")) {
2773 * backward compatibility
2774 * maybe we should remove this to make this consistent
2775 * for all cmdline tools
2778 if (strequal(lp_netbios_name(),cmdline_get_userdomain())) {
2779 cmdline_set_userdomain(lp_workgroup());
2781 lp_set_cmdline("torture:userdomain", cmdline_get_userdomain());
2783 if (!lp_parm_string(-1,"torture","password")) {
2784 lp_set_cmdline("torture:password", cmdline_get_userpassword());
2787 if (argc_new == 0) {
2788 printf("You must specify a test to run, or 'ALL'\n");
2790 for (i=2;i<argc_new;i++) {
2791 if (!run_test(argv_new[i])) {