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.
22 #include "lib/cmdline/popt_common.h"
23 #include "libcli/raw/libcliraw.h"
24 #include "system/time.h"
25 #include "system/wait.h"
28 int torture_numops=100;
29 int torture_entries=1000;
30 int torture_failures=1;
32 static int procnum; /* records process count number when forking */
33 static struct smbcli_state *current_cli;
34 static BOOL use_oplocks;
35 static BOOL use_level_II_oplocks;
36 static BOOL use_kerberos;
38 BOOL torture_showall = False;
40 #define CHECK_MAX_FAILURES(label) do { if (++failures >= torture_failures) goto label; } while (0)
42 static struct smbcli_state *open_nbt_connection(void)
44 struct nmb_name called, calling;
45 struct smbcli_state *cli;
46 const char *host = lp_parm_string(-1, "torture", "host");
48 make_nmb_name(&calling, lp_netbios_name(), 0x0);
49 choose_called_name(&called, host, 0x20);
51 cli = smbcli_state_init(NULL);
53 printf("Failed initialize smbcli_struct to connect with %s\n", host);
57 if (!smbcli_socket_connect(cli, host)) {
58 printf("Failed to connect with %s\n", host);
62 cli->transport->socket->timeout = 120000; /* set a really long timeout (2 minutes) */
64 if (!smbcli_transport_establish(cli, &calling, &called)) {
66 * Well, that failed, try *SMBSERVER ...
67 * However, we must reconnect as well ...
69 if (!smbcli_socket_connect(cli, host)) {
70 printf("Failed to connect with %s\n", host);
74 make_nmb_name(&called, "*SMBSERVER", 0x20);
75 if (!smbcli_transport_establish(cli, &calling, &called)) {
76 printf("%s rejected the session\n",host);
77 printf("We tried with a called name of %s & %s\n",
87 BOOL torture_open_connection_share(struct smbcli_state **c,
89 const char *sharename)
94 const char *username = lp_parm_string(-1, "torture", "username");
95 const char *userdomain = lp_parm_string(-1, "torture", "userdomain");
96 const char *password = lp_parm_string(-1, "torture", "password");
99 flags |= SMBCLI_FULL_CONNECTION_USE_KERBEROS;
101 status = smbcli_full_connection(NULL,
102 c, lp_netbios_name(),
105 username, username[0]?userdomain:"",
106 password, flags, &retry);
107 if (!NT_STATUS_IS_OK(status)) {
108 printf("Failed to open connection - %s\n", nt_errstr(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_open_connection(struct smbcli_state **c)
121 const char *host = lp_parm_string(-1, "torture", "host");
122 const char *share = lp_parm_string(-1, "torture", "share");
124 return torture_open_connection_share(c, host, share);
129 BOOL torture_close_connection(struct smbcli_state *c)
133 if (NT_STATUS_IS_ERR(smbcli_tdis(c))) {
134 printf("tdis failed (%s)\n", smbcli_errstr(c->tree));
142 /* open a rpc connection to the chosen binding string */
143 NTSTATUS torture_rpc_connection(struct dcerpc_pipe **p,
144 const char *pipe_name,
145 const char *pipe_uuid,
146 uint32_t pipe_version)
149 const char *binding = lp_parm_string(-1, "torture", "binding");
152 printf("You must specify a ncacn binding string\n");
153 return NT_STATUS_INVALID_PARAMETER;
156 status = dcerpc_pipe_connect(p, binding, pipe_uuid, pipe_version,
157 lp_parm_string(-1, "torture", "userdomain"),
158 lp_parm_string(-1, "torture", "username"),
159 lp_parm_string(-1, "torture", "password"));
164 /* open a rpc connection to a specific transport */
165 NTSTATUS torture_rpc_connection_transport(struct dcerpc_pipe **p,
166 const char *pipe_name,
167 const char *pipe_uuid,
168 uint32_t pipe_version,
169 enum dcerpc_transport_t transport)
172 const char *binding = lp_parm_string(-1, "torture", "binding");
173 struct dcerpc_binding b;
174 TALLOC_CTX *mem_ctx = talloc_init("torture_rpc_connection_smb");
177 printf("You must specify a ncacn binding string\n");
178 return NT_STATUS_INVALID_PARAMETER;
181 status = dcerpc_parse_binding(mem_ctx, binding, &b);
182 if (!NT_STATUS_IS_OK(status)) {
183 DEBUG(0,("Failed to parse dcerpc binding '%s'\n", binding));
184 talloc_destroy(mem_ctx);
188 b.transport = transport;
190 status = dcerpc_pipe_connect_b(p, &b, pipe_uuid, pipe_version,
191 lp_parm_string(-1, "torture", "userdomain"),
192 lp_parm_string(-1, "torture", "username"),
193 lp_parm_string(-1, "torture", "password"));
198 /* close a rpc connection to a named pipe */
199 NTSTATUS torture_rpc_close(struct dcerpc_pipe *p)
201 dcerpc_pipe_close(p);
206 /* check if the server produced the expected error code */
207 BOOL check_error(const char *location, struct smbcli_state *c,
208 uint8_t eclass, uint32_t ecode, NTSTATUS nterr)
210 if (smbcli_is_dos_error(c->tree)) {
214 /* Check DOS error */
216 smbcli_dos_error(c, &class, &num);
218 if (eclass != class || ecode != num) {
219 printf("unexpected error code class=%d code=%d\n",
220 (int)class, (int)num);
221 printf(" expected %d/%d %s (at %s)\n",
222 (int)eclass, (int)ecode, nt_errstr(nterr), location);
231 status = smbcli_nt_error(c->tree);
233 if (NT_STATUS_V(nterr) != NT_STATUS_V(status)) {
234 printf("unexpected error code %s\n", nt_errstr(status));
235 printf(" expected %s (at %s)\n", nt_errstr(nterr), location);
244 static BOOL wait_lock(struct smbcli_state *c, int fnum, uint32_t offset, uint32_t len)
246 while (NT_STATUS_IS_ERR(smbcli_lock(c->tree, fnum, offset, len, -1, WRITE_LOCK))) {
247 if (!check_error(__location__, c, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
253 static BOOL rw_torture(struct smbcli_state *c)
255 const char *lockfname = "\\torture.lck";
259 pid_t pid2, pid = getpid();
264 fnum2 = smbcli_open(c->tree, lockfname, O_RDWR | O_CREAT | O_EXCL,
267 fnum2 = smbcli_open(c->tree, lockfname, O_RDWR, DENY_NONE);
269 printf("open of %s failed (%s)\n", lockfname, smbcli_errstr(c->tree));
274 for (i=0;i<torture_numops;i++) {
275 uint_t n = (uint_t)sys_random()%10;
277 printf("%d\r", i); fflush(stdout);
279 asprintf(&fname, "\\torture.%u", n);
281 if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) {
285 fnum = smbcli_open(c->tree, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL);
287 printf("open failed (%s)\n", smbcli_errstr(c->tree));
292 if (smbcli_write(c->tree, fnum, 0, (char *)&pid, 0, sizeof(pid)) != sizeof(pid)) {
293 printf("write failed (%s)\n", smbcli_errstr(c->tree));
298 if (smbcli_write(c->tree, fnum, 0, (char *)buf,
299 sizeof(pid)+(j*sizeof(buf)),
300 sizeof(buf)) != sizeof(buf)) {
301 printf("write failed (%s)\n", smbcli_errstr(c->tree));
308 if (smbcli_read(c->tree, fnum, (char *)&pid2, 0, sizeof(pid)) != sizeof(pid)) {
309 printf("read failed (%s)\n", smbcli_errstr(c->tree));
314 printf("data corruption!\n");
318 if (NT_STATUS_IS_ERR(smbcli_close(c->tree, fnum))) {
319 printf("close failed (%s)\n", smbcli_errstr(c->tree));
323 if (NT_STATUS_IS_ERR(smbcli_unlink(c->tree, fname))) {
324 printf("unlink failed (%s)\n", smbcli_errstr(c->tree));
328 if (NT_STATUS_IS_ERR(smbcli_unlock(c->tree, fnum2, n*sizeof(int), sizeof(int)))) {
329 printf("unlock failed (%s)\n", smbcli_errstr(c->tree));
335 smbcli_close(c->tree, fnum2);
336 smbcli_unlink(c->tree, lockfname);
343 static BOOL run_torture(struct smbcli_state *cli, int dummy)
347 ret = rw_torture(cli);
349 if (!torture_close_connection(cli)) {
356 static BOOL rw_torture3(struct smbcli_state *c, const char *lockfname)
363 uint_t countprev = 0;
367 for (i = 0; i < sizeof(buf); i += sizeof(uint32_t))
369 SIVAL(buf, i, sys_random());
374 fnum = smbcli_open(c->tree, lockfname, O_RDWR | O_CREAT | O_EXCL,
377 printf("first open read/write of %s failed (%s)\n",
378 lockfname, smbcli_errstr(c->tree));
384 for (i = 0; i < 500 && fnum == -1; i++)
386 fnum = smbcli_open(c->tree, lockfname, O_RDONLY,
391 printf("second open read-only of %s failed (%s)\n",
392 lockfname, smbcli_errstr(c->tree));
398 for (count = 0; count < sizeof(buf); count += sent)
400 if (count >= countprev) {
401 printf("%d %8d\r", i, count);
404 countprev += (sizeof(buf) / 20);
409 sent = ((uint_t)sys_random()%(20))+ 1;
410 if (sent > sizeof(buf) - count)
412 sent = sizeof(buf) - count;
415 if (smbcli_write(c->tree, fnum, 0, buf+count, count, (size_t)sent) != sent) {
416 printf("write failed (%s)\n", smbcli_errstr(c->tree));
422 sent = smbcli_read(c->tree, fnum, buf_rd+count, count,
426 printf("read failed offset:%d size:%d (%s)\n",
427 count, sizeof(buf)-count,
428 smbcli_errstr(c->tree));
434 if (memcmp(buf_rd+count, buf+count, sent) != 0)
436 printf("read/write compare failed\n");
437 printf("offset: %d req %d recvd %d\n",
438 count, sizeof(buf)-count, sent);
447 if (NT_STATUS_IS_ERR(smbcli_close(c->tree, fnum))) {
448 printf("close failed (%s)\n", smbcli_errstr(c->tree));
455 static BOOL rw_torture2(struct smbcli_state *c1, struct smbcli_state *c2)
457 const char *lockfname = "\\torture2.lck";
462 uint8_t buf_rd[131072];
464 ssize_t bytes_read, bytes_written;
466 if (smbcli_deltree(c1->tree, lockfname) == -1) {
467 printf("unlink failed (%s)\n", smbcli_errstr(c1->tree));
470 fnum1 = smbcli_open(c1->tree, lockfname, O_RDWR | O_CREAT | O_EXCL,
473 printf("first open read/write of %s failed (%s)\n",
474 lockfname, smbcli_errstr(c1->tree));
477 fnum2 = smbcli_open(c2->tree, lockfname, O_RDONLY,
480 printf("second open read-only of %s failed (%s)\n",
481 lockfname, smbcli_errstr(c2->tree));
482 smbcli_close(c1->tree, fnum1);
486 printf("Checking data integrity over %d ops\n", torture_numops);
488 for (i=0;i<torture_numops;i++)
490 size_t buf_size = ((uint_t)sys_random()%(sizeof(buf)-1))+ 1;
492 printf("%d\r", i); fflush(stdout);
495 generate_random_buffer(buf, buf_size);
497 if ((bytes_written = smbcli_write(c1->tree, fnum1, 0, buf, 0, buf_size)) != buf_size) {
498 printf("write failed (%s)\n", smbcli_errstr(c1->tree));
499 printf("wrote %d, expected %d\n", bytes_written, buf_size);
504 if ((bytes_read = smbcli_read(c2->tree, fnum2, buf_rd, 0, buf_size)) != buf_size) {
505 printf("read failed (%s)\n", smbcli_errstr(c2->tree));
506 printf("read %d, expected %d\n", bytes_read, buf_size);
511 if (memcmp(buf_rd, buf, buf_size) != 0)
513 printf("read/write compare failed\n");
519 if (NT_STATUS_IS_ERR(smbcli_close(c2->tree, fnum2))) {
520 printf("close failed (%s)\n", smbcli_errstr(c2->tree));
523 if (NT_STATUS_IS_ERR(smbcli_close(c1->tree, fnum1))) {
524 printf("close failed (%s)\n", smbcli_errstr(c1->tree));
528 if (NT_STATUS_IS_ERR(smbcli_unlink(c1->tree, lockfname))) {
529 printf("unlink failed (%s)\n", smbcli_errstr(c1->tree));
536 static BOOL run_readwritetest(void)
538 struct smbcli_state *cli1, *cli2;
539 BOOL test1, test2 = True;
541 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
545 printf("starting readwritetest\n");
547 test1 = rw_torture2(cli1, cli2);
548 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1));
551 test2 = rw_torture2(cli1, cli1);
552 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2));
555 if (!torture_close_connection(cli1)) {
559 if (!torture_close_connection(cli2)) {
563 return (test1 && test2);
566 static BOOL run_readwritemulti(struct smbcli_state *cli, int dummy)
570 test = rw_torture3(cli, "\\multitest.txt");
572 if (!torture_close_connection(cli)) {
581 this checks to see if a secondary tconx can use open files from an
584 static BOOL run_tcon_test(void)
586 struct smbcli_state *cli;
587 const char *fname = "\\tcontest.tmp";
589 uint16_t cnum1, cnum2, cnum3;
590 uint16_t vuid1, vuid2;
593 struct smbcli_tree *tree1;
594 const char *host = lp_parm_string(-1, "torture", "host");
595 const char *share = lp_parm_string(-1, "torture", "share");
596 const char *password = lp_parm_string(-1, "torture", "password");
598 if (!torture_open_connection(&cli)) {
602 printf("starting tcontest\n");
604 if (smbcli_deltree(cli->tree, fname) == -1) {
605 printf("unlink of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
608 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
610 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
614 cnum1 = cli->tree->tid;
615 vuid1 = cli->session->vuid;
617 memset(&buf, 0, 4); /* init buf so valgrind won't complain */
618 if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) != 4) {
619 printf("initial write failed (%s)\n", smbcli_errstr(cli->tree));
623 tree1 = cli->tree; /* save old tree connection */
624 if (NT_STATUS_IS_ERR(smbcli_send_tconX(cli, share, "?????", password))) {
625 printf("%s refused 2nd tree connect (%s)\n", host,
626 smbcli_errstr(cli->tree));
627 smbcli_shutdown(cli);
631 cnum2 = cli->tree->tid;
632 cnum3 = MAX(cnum1, cnum2) + 1; /* any invalid number */
633 vuid2 = cli->session->vuid + 1;
635 /* try a write with the wrong tid */
636 cli->tree->tid = cnum2;
638 if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) == 4) {
639 printf("* server allows write with wrong TID\n");
642 printf("server fails write with wrong TID : %s\n", smbcli_errstr(cli->tree));
646 /* try a write with an invalid tid */
647 cli->tree->tid = cnum3;
649 if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) == 4) {
650 printf("* server allows write with invalid TID\n");
653 printf("server fails write with invalid TID : %s\n", smbcli_errstr(cli->tree));
656 /* try a write with an invalid vuid */
657 cli->session->vuid = vuid2;
658 cli->tree->tid = cnum1;
660 if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) == 4) {
661 printf("* server allows write with invalid VUID\n");
664 printf("server fails write with invalid VUID : %s\n", smbcli_errstr(cli->tree));
667 cli->session->vuid = vuid1;
668 cli->tree->tid = cnum1;
670 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum1))) {
671 printf("close failed (%s)\n", smbcli_errstr(cli->tree));
675 cli->tree->tid = cnum2;
677 if (NT_STATUS_IS_ERR(smbcli_tdis(cli))) {
678 printf("secondary tdis failed (%s)\n", smbcli_errstr(cli->tree));
682 cli->tree = tree1; /* restore initial tree */
683 cli->tree->tid = cnum1;
685 if (!torture_close_connection(cli)) {
694 static BOOL tcon_devtest(struct smbcli_state *cli,
695 const char *myshare, const char *devtype,
696 NTSTATUS expected_error)
700 const char *password = lp_parm_string(-1, "torture", "password");
702 status = NT_STATUS_IS_OK(smbcli_send_tconX(cli, myshare, devtype,
705 printf("Trying share %s with devtype %s\n", myshare, devtype);
707 if (NT_STATUS_IS_OK(expected_error)) {
711 printf("tconX to share %s with type %s "
712 "should have succeeded but failed\n",
719 printf("tconx to share %s with type %s "
720 "should have failed but succeeded\n",
724 if (NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),
728 printf("Returned unexpected error\n");
737 checks for correct tconX support
739 static BOOL run_tcon_devtype_test(void)
741 struct smbcli_state *cli1 = NULL;
746 const char *host = lp_parm_string(-1, "torture", "host");
747 const char *share = lp_parm_string(-1, "torture", "share");
748 const char *username = lp_parm_string(-1, "torture", "username");
749 const char *userdomain = lp_parm_string(-1, "torture", "userdomain");
750 const char *password = lp_parm_string(-1, "torture", "password");
752 status = smbcli_full_connection(NULL,
753 &cli1, lp_netbios_name(),
756 username, userdomain,
757 password, flags, &retry);
759 if (!NT_STATUS_IS_OK(status)) {
760 printf("could not open connection\n");
764 if (!tcon_devtest(cli1, "IPC$", "A:", NT_STATUS_BAD_DEVICE_TYPE))
767 if (!tcon_devtest(cli1, "IPC$", "?????", NT_STATUS_OK))
770 if (!tcon_devtest(cli1, "IPC$", "LPT:", NT_STATUS_BAD_DEVICE_TYPE))
773 if (!tcon_devtest(cli1, "IPC$", "IPC", NT_STATUS_OK))
776 if (!tcon_devtest(cli1, "IPC$", "FOOBA", NT_STATUS_BAD_DEVICE_TYPE))
779 if (!tcon_devtest(cli1, share, "A:", NT_STATUS_OK))
782 if (!tcon_devtest(cli1, share, "?????", NT_STATUS_OK))
785 if (!tcon_devtest(cli1, share, "LPT:", NT_STATUS_BAD_DEVICE_TYPE))
788 if (!tcon_devtest(cli1, share, "IPC", NT_STATUS_BAD_DEVICE_TYPE))
791 if (!tcon_devtest(cli1, share, "FOOBA", NT_STATUS_BAD_DEVICE_TYPE))
794 smbcli_shutdown(cli1);
797 printf("Passed tcondevtest\n");
804 test whether fnums and tids open on one VC are available on another (a major
807 static BOOL run_fdpasstest(void)
809 struct smbcli_state *cli1, *cli2;
810 const char *fname = "\\fdpass.tst";
814 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
818 printf("starting fdpasstest\n");
820 smbcli_unlink(cli1->tree, fname);
822 printf("Opening a file on connection 1\n");
824 fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
826 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
830 printf("writing to file on connection 1\n");
832 if (smbcli_write(cli1->tree, fnum1, 0, "hello world\n", 0, 13) != 13) {
833 printf("write failed (%s)\n", smbcli_errstr(cli1->tree));
837 oldtid = cli2->tree->tid;
838 cli2->session->vuid = cli1->session->vuid;
839 cli2->tree->tid = cli1->tree->tid;
840 cli2->session->pid = cli1->session->pid;
842 printf("reading from file on connection 2\n");
844 if (smbcli_read(cli2->tree, fnum1, buf, 0, 13) == 13) {
845 printf("read succeeded! nasty security hole [%s]\n",
850 smbcli_close(cli1->tree, fnum1);
851 smbcli_unlink(cli1->tree, fname);
853 cli2->tree->tid = oldtid;
855 torture_close_connection(cli1);
856 torture_close_connection(cli2);
858 printf("finished fdpasstest\n");
864 This test checks that
866 1) the server does not allow an unlink on a file that is open
868 static BOOL run_unlinktest(void)
870 struct smbcli_state *cli;
871 const char *fname = "\\unlink.tst";
875 if (!torture_open_connection(&cli)) {
879 printf("starting unlink test\n");
881 smbcli_unlink(cli->tree, fname);
883 cli->session->pid = 1;
885 printf("Opening a file\n");
887 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
889 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
893 printf("Unlinking a open file\n");
895 if (NT_STATUS_IS_OK(smbcli_unlink(cli->tree, fname))) {
896 printf("error: server allowed unlink on an open file\n");
899 correct = check_error(__location__, cli, ERRDOS, ERRbadshare,
900 NT_STATUS_SHARING_VIOLATION);
903 smbcli_close(cli->tree, fnum);
904 smbcli_unlink(cli->tree, fname);
906 if (!torture_close_connection(cli)) {
910 printf("unlink test finished\n");
917 test the timing of deferred open requests
919 static BOOL run_deferopen(struct smbcli_state *cli, int dummy)
921 const char *fname = "\\defer_open_test.dat";
927 printf("failed to connect\n");
931 printf("Testing deferred open requests.\n");
937 struct timeval tv_start, tv_end;
938 GetTimeOfDay(&tv_start);
939 fnum = smbcli_nt_create_full(cli->tree, fname, 0, GENERIC_RIGHTS_FILE_ALL_ACCESS,
940 FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_NONE,
941 NTCREATEX_DISP_OPEN_IF, 0, 0);
945 GetTimeOfDay(&tv_end);
946 if (NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),NT_STATUS_SHARING_VIOLATION)) {
947 /* Sharing violation errors need to be 1 second apart. */
948 int64_t tdif = usec_time_diff(&tv_end, &tv_start);
949 if (tdif < 500000 || tdif > 1500000) {
950 fprintf(stderr,"Timing incorrect %lld.%lld for share violation\n",
951 tdif / (int64_t)1000000,
952 tdif % (int64_t)1000000);
955 } while (NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),NT_STATUS_SHARING_VIOLATION));
958 fprintf(stderr,"Failed to open %s, error=%s\n", fname, smbcli_errstr(cli->tree));
962 printf("pid %u open %d\n", getpid(), i);
966 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum))) {
967 fprintf(stderr,"Failed to close %s, error=%s\n", fname, smbcli_errstr(cli->tree));
973 if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fname))) {
974 /* All until the last unlink will fail with sharing violation. */
975 if (!NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),NT_STATUS_SHARING_VIOLATION)) {
976 printf("unlink of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
981 printf("deferred test finished\n");
982 if (!torture_close_connection(cli)) {
989 test how many open files this server supports on the one socket
991 static BOOL run_maxfidtest(struct smbcli_state *cli, int dummy)
993 #define MAXFID_TEMPLATE "\\maxfid\\fid%d\\maxfid.%d.%d"
995 int fnums[0x11000], i;
996 int retries=4, maxfid;
1000 printf("failed to connect\n");
1004 if (smbcli_deltree(cli->tree, "\\maxfid") == -1) {
1005 printf("Failed to deltree \\maxfid - %s\n",
1006 smbcli_errstr(cli->tree));
1009 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, "\\maxfid"))) {
1010 printf("Failed to mkdir \\maxfid, error=%s\n",
1011 smbcli_errstr(cli->tree));
1015 printf("Testing maximum number of open files\n");
1017 for (i=0; i<0x11000; i++) {
1018 if (i % 1000 == 0) {
1019 asprintf(&fname, "\\maxfid\\fid%d", i/1000);
1020 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, fname))) {
1021 printf("Failed to mkdir %s, error=%s\n",
1022 fname, smbcli_errstr(cli->tree));
1027 asprintf(&fname, MAXFID_TEMPLATE, i/1000, i,(int)getpid());
1028 if ((fnums[i] = smbcli_open(cli->tree, fname,
1029 O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) ==
1031 printf("open of %s failed (%s)\n",
1032 fname, smbcli_errstr(cli->tree));
1033 printf("maximum fnum is %d\n", i);
1044 printf("cleaning up\n");
1045 for (i=0;i<maxfid/2;i++) {
1046 asprintf(&fname, MAXFID_TEMPLATE, i/1000, i,(int)getpid());
1047 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnums[i]))) {
1048 printf("Close of fnum %d failed - %s\n", fnums[i], smbcli_errstr(cli->tree));
1050 if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fname))) {
1051 printf("unlink of %s failed (%s)\n",
1052 fname, smbcli_errstr(cli->tree));
1057 asprintf(&fname, MAXFID_TEMPLATE, (maxfid-i)/1000, maxfid-i,(int)getpid());
1058 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnums[maxfid-i]))) {
1059 printf("Close of fnum %d failed - %s\n", fnums[maxfid-i], smbcli_errstr(cli->tree));
1061 if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fname))) {
1062 printf("unlink of %s failed (%s)\n",
1063 fname, smbcli_errstr(cli->tree));
1068 printf("%6d %6d\r", i, maxfid-i);
1072 if (smbcli_deltree(cli->tree, "\\maxfid") == -1) {
1073 printf("Failed to deltree \\maxfid - %s\n",
1074 smbcli_errstr(cli->tree));
1078 printf("maxfid test finished\n");
1079 if (!torture_close_connection(cli)) {
1083 #undef MAXFID_TEMPLATE
1086 /* send smb negprot commands, not reading the response */
1087 static BOOL run_negprot_nowait(void)
1090 struct smbcli_state *cli, *cli2;
1091 BOOL correct = True;
1093 printf("starting negprot nowait test\n");
1095 cli = open_nbt_connection();
1100 printf("Filling send buffer\n");
1102 for (i=0;i<10000;i++) {
1103 struct smbcli_request *req;
1104 time_t t1 = time(NULL);
1105 req = smb_negprot_send(cli->transport, PROTOCOL_NT1);
1106 while (req->state == SMBCLI_REQUEST_SEND && time(NULL) < t1+5) {
1107 smbcli_transport_process(cli->transport);
1109 if (req->state == SMBCLI_REQUEST_ERROR) {
1110 printf("Failed to fill pipe - %s\n", nt_errstr(req->status));
1111 torture_close_connection(cli);
1114 if (req->state == SMBCLI_REQUEST_SEND) {
1120 printf("send buffer failed to fill\n");
1121 if (!torture_close_connection(cli)) {
1127 printf("send buffer filled after %d requests\n", i);
1129 printf("Opening secondary connection\n");
1130 if (!torture_open_connection(&cli2)) {
1134 if (!torture_close_connection(cli)) {
1138 if (!torture_close_connection(cli2)) {
1142 printf("finished negprot nowait test\n");
1149 This checks how the getatr calls works
1151 static BOOL run_attrtest(void)
1153 struct smbcli_state *cli;
1156 const char *fname = "\\attrib123456789.tst";
1157 BOOL correct = True;
1159 printf("starting attrib test\n");
1161 if (!torture_open_connection(&cli)) {
1165 smbcli_unlink(cli->tree, fname);
1166 fnum = smbcli_open(cli->tree, fname,
1167 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1168 smbcli_close(cli->tree, fnum);
1170 if (NT_STATUS_IS_ERR(smbcli_getatr(cli->tree, fname, NULL, NULL, &t))) {
1171 printf("getatr failed (%s)\n", smbcli_errstr(cli->tree));
1175 printf("New file time is %s", ctime(&t));
1177 if (abs(t - time(NULL)) > 60*60*24*10) {
1178 printf("ERROR: SMBgetatr bug. time is %s",
1184 t2 = t-60*60*24; /* 1 day ago */
1186 printf("Setting file time to %s", ctime(&t2));
1188 if (NT_STATUS_IS_ERR(smbcli_setatr(cli->tree, fname, 0, t2))) {
1189 printf("setatr failed (%s)\n", smbcli_errstr(cli->tree));
1193 if (NT_STATUS_IS_ERR(smbcli_getatr(cli->tree, fname, NULL, NULL, &t))) {
1194 printf("getatr failed (%s)\n", smbcli_errstr(cli->tree));
1198 printf("Retrieved file time as %s", ctime(&t));
1201 printf("ERROR: getatr/setatr bug. times are\n%s",
1203 printf("%s", ctime(&t2));
1207 smbcli_unlink(cli->tree, fname);
1209 if (!torture_close_connection(cli)) {
1213 printf("attrib test finished\n");
1220 This checks a couple of trans2 calls
1222 static BOOL run_trans2test(void)
1224 struct smbcli_state *cli;
1227 time_t c_time, a_time, m_time, w_time, m_time2;
1228 const char *fname = "\\trans2.tst";
1229 const char *dname = "\\trans2";
1230 const char *fname2 = "\\trans2\\trans2.tst";
1232 BOOL correct = True;
1234 printf("starting trans2 test\n");
1236 if (!torture_open_connection(&cli)) {
1240 smbcli_unlink(cli->tree, fname);
1242 printf("Testing qfileinfo\n");
1244 fnum = smbcli_open(cli->tree, fname,
1245 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1246 if (NT_STATUS_IS_ERR(smbcli_qfileinfo(cli->tree, fnum, NULL, &size, &c_time, &a_time, &m_time,
1248 printf("ERROR: qfileinfo failed (%s)\n", smbcli_errstr(cli->tree));
1252 printf("Testing NAME_INFO\n");
1254 if (NT_STATUS_IS_ERR(smbcli_qfilename(cli->tree, fnum, &pname))) {
1255 printf("ERROR: qfilename failed (%s)\n", smbcli_errstr(cli->tree));
1259 if (!pname || strcmp(pname, fname)) {
1260 printf("qfilename gave different name? [%s] [%s]\n",
1265 smbcli_close(cli->tree, fnum);
1266 smbcli_unlink(cli->tree, fname);
1268 fnum = smbcli_open(cli->tree, fname,
1269 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1271 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
1274 smbcli_close(cli->tree, fnum);
1276 printf("Checking for sticky create times\n");
1278 if (NT_STATUS_IS_ERR(smbcli_qpathinfo(cli->tree, fname, &c_time, &a_time, &m_time, &size, NULL))) {
1279 printf("ERROR: qpathinfo failed (%s)\n", smbcli_errstr(cli->tree));
1282 if (c_time != m_time) {
1283 printf("create time=%s", ctime(&c_time));
1284 printf("modify time=%s", ctime(&m_time));
1285 printf("This system appears to have sticky create times\n");
1287 if (a_time % (60*60) == 0) {
1288 printf("access time=%s", ctime(&a_time));
1289 printf("This system appears to set a midnight access time\n");
1293 if (abs(m_time - time(NULL)) > 60*60*24*7) {
1294 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
1300 smbcli_unlink(cli->tree, fname);
1301 fnum = smbcli_open(cli->tree, fname,
1302 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1303 smbcli_close(cli->tree, fnum);
1304 if (NT_STATUS_IS_ERR(smbcli_qpathinfo2(cli->tree, fname, &c_time, &a_time, &m_time, &w_time, &size, NULL, NULL))) {
1305 printf("ERROR: qpathinfo2 failed (%s)\n", smbcli_errstr(cli->tree));
1308 if (w_time < 60*60*24*2) {
1309 printf("write time=%s", ctime(&w_time));
1310 printf("This system appears to set a initial 0 write time\n");
1315 smbcli_unlink(cli->tree, fname);
1318 /* check if the server updates the directory modification time
1319 when creating a new file */
1320 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, dname))) {
1321 printf("ERROR: mkdir failed (%s)\n", smbcli_errstr(cli->tree));
1325 if (NT_STATUS_IS_ERR(smbcli_qpathinfo2(cli->tree, "\\trans2\\", &c_time, &a_time, &m_time, &w_time, &size, NULL, NULL))) {
1326 printf("ERROR: qpathinfo2 failed (%s)\n", smbcli_errstr(cli->tree));
1330 fnum = smbcli_open(cli->tree, fname2,
1331 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1332 smbcli_write(cli->tree, fnum, 0, (char *)&fnum, 0, sizeof(fnum));
1333 smbcli_close(cli->tree, fnum);
1334 if (NT_STATUS_IS_ERR(smbcli_qpathinfo2(cli->tree, "\\trans2\\", &c_time, &a_time, &m_time2, &w_time, &size, NULL, NULL))) {
1335 printf("ERROR: qpathinfo2 failed (%s)\n", smbcli_errstr(cli->tree));
1338 if (m_time2 == m_time) {
1339 printf("This system does not update directory modification times\n");
1343 smbcli_unlink(cli->tree, fname2);
1344 smbcli_rmdir(cli->tree, dname);
1346 if (!torture_close_connection(cli)) {
1350 printf("trans2 test finished\n");
1357 print out server properties
1359 static BOOL run_properties(void)
1361 struct smbcli_state *cli;
1362 BOOL correct = True;
1364 printf("starting properties test\n");
1368 if (!torture_open_connection(&cli)) {
1372 d_printf("Capabilities 0x%08x\n", cli->transport->negotiate.capabilities);
1374 if (!torture_close_connection(cli)) {
1383 /* FIRST_DESIRED_ACCESS 0xf019f */
1384 #define FIRST_DESIRED_ACCESS SA_RIGHT_FILE_READ_DATA|SA_RIGHT_FILE_WRITE_DATA|SA_RIGHT_FILE_APPEND_DATA|\
1385 SA_RIGHT_FILE_READ_EA| /* 0xf */ \
1386 SA_RIGHT_FILE_WRITE_EA|SA_RIGHT_FILE_READ_ATTRIBUTES| /* 0x90 */ \
1387 SA_RIGHT_FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
1388 STD_RIGHT_DELETE_ACCESS|STD_RIGHT_READ_CONTROL_ACCESS|\
1389 STD_RIGHT_WRITE_DAC_ACCESS|STD_RIGHT_WRITE_OWNER_ACCESS /* 0xf0000 */
1390 /* SECOND_DESIRED_ACCESS 0xe0080 */
1391 #define SECOND_DESIRED_ACCESS SA_RIGHT_FILE_READ_ATTRIBUTES| /* 0x80 */ \
1392 STD_RIGHT_READ_CONTROL_ACCESS|STD_RIGHT_WRITE_DAC_ACCESS|\
1393 STD_RIGHT_WRITE_OWNER_ACCESS /* 0xe0000 */
1396 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
1397 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
1398 SA_RIGHT_FILE_READ_DATA|\
1399 WRITE_OWNER_ACCESS /* */
1403 Test ntcreate calls made by xcopy
1405 static BOOL run_xcopy(void)
1407 struct smbcli_state *cli1;
1408 const char *fname = "\\test.txt";
1409 BOOL correct = True;
1412 printf("starting xcopy test\n");
1414 if (!torture_open_connection(&cli1)) {
1418 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0,
1419 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
1420 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF,
1424 printf("First open failed - %s\n", smbcli_errstr(cli1->tree));
1428 fnum2 = smbcli_nt_create_full(cli1->tree, fname, 0,
1429 SECOND_DESIRED_ACCESS, 0,
1430 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN,
1433 printf("second open failed - %s\n", smbcli_errstr(cli1->tree));
1437 if (!torture_close_connection(cli1)) {
1446 see how many RPC pipes we can open at once
1448 static BOOL run_pipe_number(void)
1450 struct smbcli_state *cli1;
1451 const char *pipe_name = "\\WKSSVC";
1455 printf("starting pipenumber test\n");
1456 if (!torture_open_connection(&cli1)) {
1461 fnum = smbcli_nt_create_full(cli1->tree, pipe_name, 0, SA_RIGHT_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
1462 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1465 printf("Open of pipe %s failed with error (%s)\n", pipe_name, smbcli_errstr(cli1->tree));
1469 printf("%d\r", num_pipes);
1473 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes, pipe_name );
1474 torture_close_connection(cli1);
1482 open N connections to the server and just hold them open
1483 used for testing performance when there are N idle users
1486 static BOOL torture_holdcon(void)
1489 struct smbcli_state **cli;
1492 printf("Opening %d connections\n", torture_numops);
1494 cli = malloc(sizeof(struct smbcli_state *) * torture_numops);
1496 for (i=0;i<torture_numops;i++) {
1497 if (!torture_open_connection(&cli[i])) {
1500 printf("opened %d connections\r", i);
1504 printf("\nStarting pings\n");
1507 for (i=0;i<torture_numops;i++) {
1510 status = smbcli_chkpath(cli[i]->tree, "\\");
1511 if (!NT_STATUS_IS_OK(status)) {
1512 printf("Connection %d is dead\n", i);
1520 if (num_dead == torture_numops) {
1521 printf("All connections dead - finishing\n");
1533 Try with a wrong vuid and check error message.
1536 static BOOL run_vuidtest(void)
1538 struct smbcli_state *cli;
1539 const char *fname = "\\vuid.tst";
1542 time_t c_time, a_time, m_time;
1543 BOOL correct = True;
1548 printf("starting vuid test\n");
1550 if (!torture_open_connection(&cli)) {
1554 smbcli_unlink(cli->tree, fname);
1556 fnum = smbcli_open(cli->tree, fname,
1557 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1559 orig_vuid = cli->session->vuid;
1561 cli->session->vuid += 1234;
1563 printf("Testing qfileinfo with wrong vuid\n");
1565 if (NT_STATUS_IS_OK(result = smbcli_qfileinfo(cli->tree, fnum, NULL,
1566 &size, &c_time, &a_time,
1567 &m_time, NULL, NULL))) {
1568 printf("ERROR: qfileinfo passed with wrong vuid\n");
1572 if ( (cli->transport->error.etype != ETYPE_DOS) ||
1573 (cli->transport->error.e.dos.eclass != ERRSRV) ||
1574 (cli->transport->error.e.dos.ecode != ERRbaduid) ) {
1575 printf("ERROR: qfileinfo should have returned DOS error "
1576 "ERRSRV:ERRbaduid\n but returned %s\n",
1577 smbcli_errstr(cli->tree));
1581 cli->session->vuid -= 1234;
1583 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum))) {
1584 printf("close failed (%s)\n", smbcli_errstr(cli->tree));
1588 smbcli_unlink(cli->tree, fname);
1590 if (!torture_close_connection(cli)) {
1594 printf("vuid test finished\n");
1600 Test open mode returns on read-only files.
1602 static BOOL run_opentest(void)
1604 static struct smbcli_state *cli1;
1605 static struct smbcli_state *cli2;
1606 const char *fname = "\\readonly.file";
1610 BOOL correct = True;
1614 printf("starting open test\n");
1616 if (!torture_open_connection(&cli1)) {
1620 smbcli_setatr(cli1->tree, fname, 0, 0);
1621 smbcli_unlink(cli1->tree, fname);
1623 fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1625 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1629 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1630 printf("close2 failed (%s)\n", smbcli_errstr(cli1->tree));
1634 if (NT_STATUS_IS_ERR(smbcli_setatr(cli1->tree, fname, FILE_ATTRIBUTE_READONLY, 0))) {
1635 printf("smbcli_setatr failed (%s)\n", smbcli_errstr(cli1->tree));
1636 CHECK_MAX_FAILURES(error_test1);
1640 fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY, DENY_WRITE);
1642 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1643 CHECK_MAX_FAILURES(error_test1);
1647 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
1648 fnum2 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_ALL);
1650 if (check_error(__location__, cli1, ERRDOS, ERRnoaccess,
1651 NT_STATUS_ACCESS_DENIED)) {
1652 printf("correct error code ERRDOS/ERRnoaccess returned\n");
1655 printf("finished open test 1\n");
1657 smbcli_close(cli1->tree, fnum1);
1659 /* Now try not readonly and ensure ERRbadshare is returned. */
1661 smbcli_setatr(cli1->tree, fname, 0, 0);
1663 fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY, DENY_WRITE);
1665 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1669 /* This will fail - but the error should be ERRshare. */
1670 fnum2 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_ALL);
1672 if (check_error(__location__, cli1, ERRDOS, ERRbadshare,
1673 NT_STATUS_SHARING_VIOLATION)) {
1674 printf("correct error code ERRDOS/ERRbadshare returned\n");
1677 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1678 printf("close2 failed (%s)\n", smbcli_errstr(cli1->tree));
1682 smbcli_unlink(cli1->tree, fname);
1684 printf("finished open test 2\n");
1686 /* Test truncate open disposition on file opened for read. */
1688 fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1690 printf("(3) open (1) of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1694 /* write 20 bytes. */
1696 memset(buf, '\0', 20);
1698 if (smbcli_write(cli1->tree, fnum1, 0, buf, 0, 20) != 20) {
1699 printf("write failed (%s)\n", smbcli_errstr(cli1->tree));
1703 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1704 printf("(3) close1 failed (%s)\n", smbcli_errstr(cli1->tree));
1708 /* Ensure size == 20. */
1709 if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
1710 printf("(3) getatr failed (%s)\n", smbcli_errstr(cli1->tree));
1711 CHECK_MAX_FAILURES(error_test3);
1716 printf("(3) file size != 20\n");
1717 CHECK_MAX_FAILURES(error_test3);
1721 /* Now test if we can truncate a file opened for readonly. */
1723 fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY|O_TRUNC, DENY_NONE);
1725 printf("(3) open (2) of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1726 CHECK_MAX_FAILURES(error_test3);
1730 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1731 printf("close2 failed (%s)\n", smbcli_errstr(cli1->tree));
1735 /* Ensure size == 0. */
1736 if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
1737 printf("(3) getatr failed (%s)\n", smbcli_errstr(cli1->tree));
1738 CHECK_MAX_FAILURES(error_test3);
1743 printf("(3) file size != 0\n");
1744 CHECK_MAX_FAILURES(error_test3);
1747 printf("finished open test 3\n");
1749 smbcli_unlink(cli1->tree, fname);
1752 printf("testing ctemp\n");
1753 fnum1 = smbcli_ctemp(cli1->tree, "\\", &tmp_path);
1755 printf("ctemp failed (%s)\n", smbcli_errstr(cli1->tree));
1756 CHECK_MAX_FAILURES(error_test4);
1759 printf("ctemp gave path %s\n", tmp_path);
1760 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1761 printf("close of temp failed (%s)\n", smbcli_errstr(cli1->tree));
1763 if (NT_STATUS_IS_ERR(smbcli_unlink(cli1->tree, tmp_path))) {
1764 printf("unlink of temp failed (%s)\n", smbcli_errstr(cli1->tree));
1767 /* Test the non-io opens... */
1769 if (!torture_open_connection(&cli2)) {
1773 smbcli_setatr(cli2->tree, fname, 0, 0);
1774 smbcli_unlink(cli2->tree, fname);
1776 printf("TEST #1 testing 2 non-io opens (no delete)\n");
1778 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1779 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1782 printf("test 1 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1783 CHECK_MAX_FAILURES(error_test10);
1787 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1788 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1790 printf("test 1 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1791 CHECK_MAX_FAILURES(error_test10);
1795 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1796 printf("test 1 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1799 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1800 printf("test 1 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1804 printf("non-io open test #1 passed.\n");
1806 smbcli_unlink(cli1->tree, fname);
1808 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
1810 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1811 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1814 printf("test 2 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1815 CHECK_MAX_FAILURES(error_test20);
1819 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1820 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1823 printf("test 2 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1824 CHECK_MAX_FAILURES(error_test20);
1828 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1829 printf("test 1 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1832 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1833 printf("test 1 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1837 printf("non-io open test #2 passed.\n");
1839 smbcli_unlink(cli1->tree, fname);
1841 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
1843 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1844 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1847 printf("test 3 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1848 CHECK_MAX_FAILURES(error_test30);
1852 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1853 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1856 printf("test 3 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1857 CHECK_MAX_FAILURES(error_test30);
1861 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1862 printf("test 3 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1865 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1866 printf("test 3 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1870 printf("non-io open test #3 passed.\n");
1872 smbcli_unlink(cli1->tree, fname);
1874 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
1876 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1877 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1880 printf("test 4 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1881 CHECK_MAX_FAILURES(error_test40);
1885 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1886 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1889 printf("test 4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1890 CHECK_MAX_FAILURES(error_test40);
1894 printf("test 4 open 2 of %s gave %s (correct error should be %s)\n", fname, smbcli_errstr(cli2->tree), "sharing violation");
1896 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1897 printf("test 4 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1901 printf("non-io open test #4 passed.\n");
1903 smbcli_unlink(cli1->tree, fname);
1905 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
1907 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1908 NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1911 printf("test 5 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1912 CHECK_MAX_FAILURES(error_test50);
1916 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1917 NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1920 printf("test 5 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1921 CHECK_MAX_FAILURES(error_test50);
1925 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1926 printf("test 5 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1930 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1931 printf("test 5 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1935 printf("non-io open test #5 passed.\n");
1937 printf("TEST #6 testing 1 non-io open, one io open\n");
1939 smbcli_unlink(cli1->tree, fname);
1941 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SA_RIGHT_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
1942 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1945 printf("test 6 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1946 CHECK_MAX_FAILURES(error_test60);
1950 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1951 NTCREATEX_SHARE_ACCESS_READ, NTCREATEX_DISP_OPEN_IF, 0, 0);
1954 printf("test 6 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1955 CHECK_MAX_FAILURES(error_test60);
1959 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1960 printf("test 6 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1964 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1965 printf("test 6 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1969 printf("non-io open test #6 passed.\n");
1971 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
1973 smbcli_unlink(cli1->tree, fname);
1975 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SA_RIGHT_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
1976 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1979 printf("test 7 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1980 CHECK_MAX_FAILURES(error_test70);
1984 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1985 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1988 printf("test 7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1989 CHECK_MAX_FAILURES(error_test70);
1993 printf("test 7 open 2 of %s gave %s (correct error should be %s)\n", fname, smbcli_errstr(cli2->tree), "sharing violation");
1995 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1996 printf("test 7 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
2000 printf("non-io open test #7 passed.\n");
2004 printf("TEST #8 testing one normal open, followed by lock, followed by open with truncate\n");
2006 smbcli_unlink(cli1->tree, fname);
2008 fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
2010 printf("(8) open (1) of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
2014 /* write 20 bytes. */
2016 memset(buf, '\0', 20);
2018 if (smbcli_write(cli1->tree, fnum1, 0, buf, 0, 20) != 20) {
2019 printf("(8) write failed (%s)\n", smbcli_errstr(cli1->tree));
2023 /* Ensure size == 20. */
2024 if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
2025 printf("(8) getatr (1) failed (%s)\n", smbcli_errstr(cli1->tree));
2026 CHECK_MAX_FAILURES(error_test80);
2031 printf("(8) file size != 20\n");
2032 CHECK_MAX_FAILURES(error_test80);
2036 /* Get an exclusive lock on the open file. */
2037 if (NT_STATUS_IS_ERR(smbcli_lock(cli1->tree, fnum1, 0, 4, 0, WRITE_LOCK))) {
2038 printf("(8) lock1 failed (%s)\n", smbcli_errstr(cli1->tree));
2039 CHECK_MAX_FAILURES(error_test80);
2043 fnum2 = smbcli_open(cli1->tree, fname, O_RDWR|O_TRUNC, DENY_NONE);
2045 printf("(8) open (2) of %s with truncate failed (%s)\n", fname, smbcli_errstr(cli1->tree));
2049 /* Ensure size == 0. */
2050 if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
2051 printf("(8) getatr (2) failed (%s)\n", smbcli_errstr(cli1->tree));
2052 CHECK_MAX_FAILURES(error_test80);
2057 printf("(8) file size != 0\n");
2058 CHECK_MAX_FAILURES(error_test80);
2062 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
2063 printf("(8) close1 failed (%s)\n", smbcli_errstr(cli1->tree));
2067 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum2))) {
2068 printf("(8) close1 failed (%s)\n", smbcli_errstr(cli1->tree));
2074 printf("open test #8 passed.\n");
2076 smbcli_unlink(cli1->tree, fname);
2078 if (!torture_close_connection(cli1)) {
2081 if (!torture_close_connection(cli2)) {
2090 sees what IOCTLs are supported
2092 BOOL torture_ioctl_test(void)
2094 struct smbcli_state *cli;
2095 uint16_t device, function;
2097 const char *fname = "\\ioctl.dat";
2099 union smb_ioctl parms;
2100 TALLOC_CTX *mem_ctx;
2102 if (!torture_open_connection(&cli)) {
2106 mem_ctx = talloc_init("ioctl_test");
2108 printf("starting ioctl test\n");
2110 smbcli_unlink(cli->tree, fname);
2112 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2114 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
2118 parms.ioctl.level = RAW_IOCTL_IOCTL;
2119 parms.ioctl.in.fnum = fnum;
2120 parms.ioctl.in.request = IOCTL_QUERY_JOB_INFO;
2121 status = smb_raw_ioctl(cli->tree, mem_ctx, &parms);
2122 printf("ioctl job info: %s\n", smbcli_errstr(cli->tree));
2124 for (device=0;device<0x100;device++) {
2125 printf("testing device=0x%x\n", device);
2126 for (function=0;function<0x100;function++) {
2127 parms.ioctl.in.request = (device << 16) | function;
2128 status = smb_raw_ioctl(cli->tree, mem_ctx, &parms);
2130 if (NT_STATUS_IS_OK(status)) {
2131 printf("ioctl device=0x%x function=0x%x OK : %d bytes\n",
2132 device, function, parms.ioctl.out.blob.length);
2137 if (!torture_close_connection(cli)) {
2146 tries variants of chkpath
2148 BOOL torture_chkpath_test(void)
2150 struct smbcli_state *cli;
2154 if (!torture_open_connection(&cli)) {
2158 printf("starting chkpath test\n");
2160 printf("Testing valid and invalid paths\n");
2162 /* cleanup from an old run */
2163 smbcli_rmdir(cli->tree, "\\chkpath.dir\\dir2");
2164 smbcli_unlink(cli->tree, "\\chkpath.dir\\*");
2165 smbcli_rmdir(cli->tree, "\\chkpath.dir");
2167 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, "\\chkpath.dir"))) {
2168 printf("mkdir1 failed : %s\n", smbcli_errstr(cli->tree));
2172 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, "\\chkpath.dir\\dir2"))) {
2173 printf("mkdir2 failed : %s\n", smbcli_errstr(cli->tree));
2177 fnum = smbcli_open(cli->tree, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2179 printf("open1 failed (%s)\n", smbcli_errstr(cli->tree));
2182 smbcli_close(cli->tree, fnum);
2184 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir"))) {
2185 printf("chkpath1 failed: %s\n", smbcli_errstr(cli->tree));
2189 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\dir2"))) {
2190 printf("chkpath2 failed: %s\n", smbcli_errstr(cli->tree));
2194 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\foo.txt"))) {
2195 ret = check_error(__location__, cli, ERRDOS, ERRbadpath,
2196 NT_STATUS_NOT_A_DIRECTORY);
2198 printf("* chkpath on a file should fail\n");
2202 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\bar.txt"))) {
2203 ret = check_error(__location__, cli, ERRDOS, ERRbadfile,
2204 NT_STATUS_OBJECT_NAME_NOT_FOUND);
2206 printf("* chkpath on a non existent file should fail\n");
2210 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\dirxx\\bar.txt"))) {
2211 ret = check_error(__location__, cli, ERRDOS, ERRbadpath,
2212 NT_STATUS_OBJECT_PATH_NOT_FOUND);
2214 printf("* chkpath on a non existent component should fail\n");
2218 smbcli_rmdir(cli->tree, "\\chkpath.dir\\dir2");
2219 smbcli_unlink(cli->tree, "\\chkpath.dir\\*");
2220 smbcli_rmdir(cli->tree, "\\chkpath.dir");
2222 if (!torture_close_connection(cli)) {
2231 parse a //server/share type UNC name
2233 static BOOL parse_unc(const char *unc_name, char **hostname, char **sharename)
2237 if (strncmp(unc_name, "//", 2)) {
2241 *hostname = strdup(&unc_name[2]);
2242 p = strchr_m(&(*hostname)[2],'/');
2247 *sharename = strdup(p+1);
2254 static void sigcont(int sig)
2258 double torture_create_procs(BOOL (*fn)(struct smbcli_state *, int), BOOL *result)
2261 volatile pid_t *child_status;
2262 volatile BOOL *child_status_out;
2265 double start_time_limit = 10 + (torture_nprocs * 1.5);
2266 char **unc_list = NULL;
2268 int num_unc_names = 0;
2272 signal(SIGCONT, sigcont);
2274 child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*torture_nprocs);
2275 if (!child_status) {
2276 printf("Failed to setup shared memory\n");
2280 child_status_out = (volatile BOOL *)shm_setup(sizeof(BOOL)*torture_nprocs);
2281 if (!child_status_out) {
2282 printf("Failed to setup result status shared memory\n");
2286 p = lp_parm_string(-1, "torture", "unclist");
2288 unc_list = file_lines_load(p, &num_unc_names);
2289 if (!unc_list || num_unc_names <= 0) {
2290 printf("Failed to load unc names list from '%s'\n", p);
2295 for (i = 0; i < torture_nprocs; i++) {
2296 child_status[i] = 0;
2297 child_status_out[i] = True;
2302 for (i=0;i<torture_nprocs;i++) {
2306 char *hostname=NULL, *sharename;
2308 pid_t mypid = getpid();
2309 sys_srandom(((int)mypid) ^ ((int)time(NULL)));
2311 asprintf(&myname, "CLIENT%d", i);
2312 lp_set_cmdline("netbios name", myname);
2317 if (!parse_unc(unc_list[i % num_unc_names],
2318 &hostname, &sharename)) {
2319 printf("Failed to parse UNC name %s\n",
2320 unc_list[i % num_unc_names]);
2327 if (torture_open_connection_share(¤t_cli,
2332 } else if (torture_open_connection(¤t_cli)) {
2336 printf("pid %d failed to start\n", (int)getpid());
2342 child_status[i] = getpid();
2346 if (child_status[i]) {
2347 printf("Child %d failed to start!\n", i);
2348 child_status_out[i] = 1;
2352 child_status_out[i] = fn(current_cli, i);
2359 for (i=0;i<torture_nprocs;i++) {
2360 if (child_status[i]) synccount++;
2362 if (synccount == torture_nprocs) break;
2364 } while (end_timer() < start_time_limit);
2366 if (synccount != torture_nprocs) {
2367 printf("FAILED TO START %d CLIENTS (started %d)\n", torture_nprocs, synccount);
2372 printf("Starting %d clients\n", torture_nprocs);
2374 /* start the client load */
2376 for (i=0;i<torture_nprocs;i++) {
2377 child_status[i] = 0;
2381 printf("%d clients started\n", torture_nprocs);
2383 for (i=0;i<torture_nprocs;i++) {
2385 while ((ret=sys_waitpid(0, &status, 0)) == -1 && errno == EINTR) /* noop */ ;
2386 if (ret == -1 || WEXITSTATUS(status) != 0) {
2393 for (i=0;i<torture_nprocs;i++) {
2394 if (!child_status_out[i]) {
2401 #define FLAG_MULTIPROC 1
2406 BOOL (*multi_fn)(struct smbcli_state *, int );
2409 {"BASE-FDPASS", run_fdpasstest, 0},
2410 {"BASE-LOCK1", torture_locktest1, 0},
2411 {"BASE-LOCK2", torture_locktest2, 0},
2412 {"BASE-LOCK3", torture_locktest3, 0},
2413 {"BASE-LOCK4", torture_locktest4, 0},
2414 {"BASE-LOCK5", torture_locktest5, 0},
2415 {"BASE-LOCK6", torture_locktest6, 0},
2416 {"BASE-LOCK7", torture_locktest7, 0},
2417 {"BASE-UNLINK", run_unlinktest, 0},
2418 {"BASE-ATTR", run_attrtest, 0},
2419 {"BASE-TRANS2", run_trans2test, 0},
2420 {"BASE-NEGNOWAIT", run_negprot_nowait, 0},
2421 {"BASE-DIR1", torture_dirtest1, 0},
2422 {"BASE-DIR2", torture_dirtest2, 0},
2423 {"BASE-DENY1", torture_denytest1, 0},
2424 {"BASE-DENY2", torture_denytest2, 0},
2425 {"BASE-DENY3", torture_denytest3, 0},
2426 {"BASE-NTDENY1", NULL, torture_ntdenytest1},
2427 {"BASE-NTDENY2", torture_ntdenytest2, 0},
2428 {"BASE-TCON", run_tcon_test, 0},
2429 {"BASE-TCONDEV", run_tcon_devtype_test, 0},
2430 {"BASE-VUID", run_vuidtest, 0},
2431 {"BASE-RW1", run_readwritetest, 0},
2432 {"BASE-RW2", NULL, run_readwritemulti},
2433 {"BASE-OPEN", run_opentest, 0},
2434 {"BASE-DEFER_OPEN", NULL, run_deferopen},
2435 {"BASE-XCOPY", run_xcopy, 0},
2436 {"BASE-RENAME", torture_test_rename, 0},
2437 {"BASE-DELETE", torture_test_delete, 0},
2438 {"BASE-PROPERTIES", run_properties, 0},
2439 {"BASE-MANGLE", torture_mangle, 0},
2440 {"BASE-OPENATTR", torture_openattrtest, 0},
2441 {"BASE-CHARSET", torture_charset, 0},
2442 {"BASE-CHKPATH", torture_chkpath_test, 0},
2443 {"BASE-SECLEAK", torture_sec_leak, 0},
2445 /* benchmarking tests */
2446 {"BENCH-HOLDCON", torture_holdcon, 0},
2447 {"BENCH-NBENCH", torture_nbench, 0},
2448 {"BENCH-TORTURE", NULL, run_torture},
2451 {"RAW-QFSINFO", torture_raw_qfsinfo, 0},
2452 {"RAW-QFILEINFO", torture_raw_qfileinfo, 0},
2453 {"RAW-SFILEINFO", torture_raw_sfileinfo, 0},
2454 {"RAW-SFILEINFO-BUG", torture_raw_sfileinfo_bug, 0},
2455 {"RAW-SEARCH", torture_raw_search, 0},
2456 {"RAW-CLOSE", torture_raw_close, 0},
2457 {"RAW-OPEN", torture_raw_open, 0},
2458 {"RAW-MKDIR", torture_raw_mkdir, 0},
2459 {"RAW-OPLOCK", torture_raw_oplock, 0},
2460 {"RAW-NOTIFY", torture_raw_notify, 0},
2461 {"RAW-MUX", torture_raw_mux, 0},
2462 {"RAW-IOCTL", torture_raw_ioctl, 0},
2463 {"RAW-CHKPATH", torture_raw_chkpath, 0},
2464 {"RAW-UNLINK", torture_raw_unlink, 0},
2465 {"RAW-READ", torture_raw_read, 0},
2466 {"RAW-WRITE", torture_raw_write, 0},
2467 {"RAW-LOCK", torture_raw_lock, 0},
2468 {"RAW-CONTEXT", torture_raw_context, 0},
2469 {"RAW-RENAME", torture_raw_rename, 0},
2470 {"RAW-SEEK", torture_raw_seek, 0},
2471 {"RAW-RAP", torture_raw_rap, 0},
2473 /* protocol scanners */
2474 {"SCAN-TRANS2", torture_trans2_scan, 0},
2475 {"SCAN-NTTRANS", torture_nttrans_scan, 0},
2476 {"SCAN-ALIASES", torture_trans2_aliases, 0},
2477 {"SCAN-SMB", torture_smb_scan, 0},
2478 {"SCAN-MAXFID", NULL, run_maxfidtest},
2479 {"SCAN-UTABLE", torture_utable, 0},
2480 {"SCAN-CASETABLE", torture_casetable, 0},
2481 {"SCAN-PIPE_NUMBER", run_pipe_number, 0},
2482 {"SCAN-IOCTL", torture_ioctl_test, 0},
2485 {"RPC-LSA", torture_rpc_lsa, 0},
2486 {"RPC-ECHO", torture_rpc_echo, 0},
2487 {"RPC-DFS", torture_rpc_dfs, 0},
2488 {"RPC-SPOOLSS", torture_rpc_spoolss, 0},
2489 {"RPC-SAMR", torture_rpc_samr, 0},
2490 {"RPC-NETLOGON", torture_rpc_netlogon, 0},
2491 {"RPC-SCHANNEL", torture_rpc_schannel, 0},
2492 {"RPC-WKSSVC", torture_rpc_wkssvc, 0},
2493 {"RPC-SRVSVC", torture_rpc_srvsvc, 0},
2494 {"RPC-SVCCTL", torture_rpc_svcctl, 0},
2495 {"RPC-ATSVC", torture_rpc_atsvc, 0},
2496 {"RPC-EVENTLOG", torture_rpc_eventlog, 0},
2497 {"RPC-EPMAPPER", torture_rpc_epmapper, 0},
2498 {"RPC-WINREG", torture_rpc_winreg, 0},
2499 {"RPC-OXIDRESOLVE", torture_rpc_oxidresolve, 0},
2500 {"RPC-REMACT", torture_rpc_remact, 0},
2501 {"RPC-MGMT", torture_rpc_mgmt, 0},
2502 {"RPC-SCANNER", torture_rpc_scanner, 0},
2503 {"RPC-AUTOIDL", torture_rpc_autoidl, 0},
2504 {"RPC-COUNTCALLS", torture_rpc_countcalls, 0},
2505 {"RPC-MULTIBIND", torture_multi_bind, 0},
2506 {"RPC-DRSUAPI", torture_rpc_drsuapi, 0},
2508 /* local (no server) testers */
2509 {"LOCAL-NTLMSSP", torture_ntlmssp_self_check, 0},
2510 {"LOCAL-ICONV", torture_local_iconv, 0},
2511 {"LOCAL-TALLOC", torture_local_talloc, 0},
2512 {"LOCAL-MESSAGING", torture_local_messaging, 0},
2513 {"LOCAL-BINDING", torture_local_binding_string, 0},
2514 {"LOCAL-IDTREE", torture_local_idtree, 0},
2517 {"LDAP-BASIC", torture_ldap_basic, 0},
2523 /****************************************************************************
2524 run a specified test or "ALL"
2525 ****************************************************************************/
2526 static BOOL run_test(const char *name)
2530 BOOL matched = False;
2532 if (strequal(name,"ALL")) {
2533 for (i=0;torture_ops[i].name;i++) {
2534 if (!run_test(torture_ops[i].name)) {
2541 for (i=0;torture_ops[i].name;i++) {
2542 if (gen_fnmatch(name, torture_ops[i].name) == 0) {
2546 printf("Running %s\n", torture_ops[i].name);
2547 if (torture_ops[i].multi_fn) {
2549 t = torture_create_procs(torture_ops[i].multi_fn,
2553 printf("TEST %s FAILED!\n", torture_ops[i].name);
2558 if (!torture_ops[i].fn()) {
2560 printf("TEST %s FAILED!\n", torture_ops[i].name);
2564 printf("%s took %g secs\n\n", torture_ops[i].name, t);
2569 printf("Unknown torture operation '%s'\n", name);
2576 static void parse_dns(const char *dns)
2578 char *userdn, *basedn, *secret;
2581 /* retrievieng the userdn */
2582 p = strchr_m(dns, '#');
2584 lp_set_cmdline("torture:ldap_userdn", "");
2585 lp_set_cmdline("torture:ldap_basedn", "");
2586 lp_set_cmdline("torture:ldap_secret", "");
2589 userdn = strndup(dns, p - dns);
2590 lp_set_cmdline("torture:ldap_userdn", userdn);
2592 /* retrieve the basedn */
2594 p = strchr_m(d, '#');
2596 lp_set_cmdline("torture:ldap_basedn", "");
2597 lp_set_cmdline("torture:ldap_secret", "");
2600 basedn = strndup(d, p - d);
2601 lp_set_cmdline("torture:ldap_basedn", basedn);
2603 /* retrieve the secret */
2606 lp_set_cmdline("torture:ldap_secret", "");
2610 lp_set_cmdline("torture:ldap_secret", secret);
2612 printf ("%s - %s - %s\n", userdn, basedn, secret);
2616 static void usage(poptContext pc)
2621 poptPrintUsage(pc, stdout, 0);
2624 printf("tests are:");
2625 for (i=0;torture_ops[i].name;i++) {
2626 if ((i%perline)==0) {
2629 printf("%s ", torture_ops[i].name);
2633 printf("default test is ALL\n");
2638 static BOOL is_binding_string(const char *binding_string)
2640 TALLOC_CTX *mem_ctx = talloc_init("is_binding_string");
2641 struct dcerpc_binding binding_struct;
2644 status = dcerpc_parse_binding(mem_ctx, binding_string, &binding_struct);
2646 talloc_destroy(mem_ctx);
2647 return NT_STATUS_IS_OK(status);
2650 /****************************************************************************
2652 ****************************************************************************/
2653 int main(int argc,char *argv[])
2657 BOOL correct = True;
2661 enum {OPT_LOADFILE=1000,OPT_UNCLIST,OPT_TIMELIMIT,OPT_DNS,OPT_DANGEROUS};
2662 struct poptOption long_options[] = {
2664 {"smb-ports", 'p', POPT_ARG_STRING, NULL, 0, "SMB ports", NULL},
2665 {"seed", 0, POPT_ARG_INT, &torture_seed, 0, "seed", NULL},
2666 {"num-progs", 0, POPT_ARG_INT, &torture_nprocs, 0, "num progs", NULL},
2667 {"num-ops", 0, POPT_ARG_INT, &torture_numops, 0, "num ops", NULL},
2668 {"entries", 0, POPT_ARG_INT, &torture_entries, 0, "entries", NULL},
2669 {"use-oplocks", 'L', POPT_ARG_NONE, &use_oplocks, 0, "use oplocks", NULL},
2670 {"show-all", 0, POPT_ARG_NONE, &torture_showall, 0, "show all", NULL},
2671 {"loadfile", 0, POPT_ARG_STRING, NULL, OPT_LOADFILE, "loadfile", NULL},
2672 {"unclist", 0, POPT_ARG_STRING, NULL, OPT_UNCLIST, "unclist", NULL},
2673 {"timelimit", 't', POPT_ARG_STRING, NULL, OPT_TIMELIMIT, "timelimit", NULL},
2674 {"failures", 'f', POPT_ARG_INT, &torture_failures, 0, "failures", NULL},
2675 {"parse-dns", 'D', POPT_ARG_STRING, NULL, OPT_DNS, "parse-dns", NULL},
2676 {"dangerous", 'X', POPT_ARG_NONE, NULL, OPT_DANGEROUS, "dangerous", NULL},
2678 POPT_COMMON_CONNECTION
2679 POPT_COMMON_CREDENTIALS
2684 setup_logging("smbtorture", DEBUG_STDOUT);
2686 #ifdef HAVE_SETBUFFER
2687 setbuffer(stdout, NULL, 0);
2690 pc = poptGetContext("smbtorture", argc, (const char **) argv, long_options,
2691 POPT_CONTEXT_KEEP_FIRST);
2693 poptSetOtherOptionHelp(pc, "<binding>|<unc> TEST1 TEST2 ...");
2695 while((opt = poptGetNextOpt(pc)) != -1) {
2698 lp_set_cmdline("torture:loadfile", poptGetOptArg(pc));
2701 lp_set_cmdline("torture:unclist", poptGetOptArg(pc));
2704 lp_set_cmdline("torture:timelimit", poptGetOptArg(pc));
2707 parse_dns(poptGetOptArg(pc));
2710 lp_set_cmdline("torture:dangerous", "1");
2713 d_printf("Invalid option %s: %s\n",
2714 poptBadOption(pc, 0), poptStrerror(opt));
2720 lp_load(dyn_CONFIGFILE,True,False,False);
2722 if (torture_seed == 0) {
2723 torture_seed = time(NULL);
2725 printf("Using seed %d\n", torture_seed);
2726 srandom(torture_seed);
2728 argv_new = discard_const_p(char *, poptGetArgs(pc));
2731 for (i=0; i<argc; i++) {
2732 if (argv_new[i] == NULL) {
2743 for(p = argv_new[1]; *p; p++) {
2748 /* see if its a RPC transport specifier */
2749 if (is_binding_string(argv_new[1])) {
2750 lp_set_cmdline("torture:binding", argv_new[1]);
2752 char *binding = NULL;
2753 char *host = NULL, *share = NULL;
2755 if (!parse_unc(argv_new[1], &host, &share)) {
2756 d_printf("Invalid option: %s is not a valid torture target (share or binding string)\n\n", argv_new[1]);
2760 lp_set_cmdline("torture:host", host);
2761 lp_set_cmdline("torture:share", share);
2762 asprintf(&binding, "ncacn_np:%s", host);
2763 lp_set_cmdline("torture:binding", binding);
2766 if (!lp_parm_string(-1,"torture","username")) {
2767 lp_set_cmdline("torture:username", cmdline_get_username());
2769 if (!lp_parm_string(-1,"torture","userdomain")) {
2771 * backward compatibility
2772 * maybe we should remove this to make this consistent
2773 * for all cmdline tools
2776 if (strequal(lp_netbios_name(),cmdline_get_userdomain())) {
2777 cmdline_set_userdomain(lp_workgroup());
2779 lp_set_cmdline("torture:userdomain", cmdline_get_userdomain());
2781 if (!lp_parm_string(-1,"torture","password")) {
2782 lp_set_cmdline("torture:password", cmdline_get_userpassword());
2785 if (argc_new == 0) {
2786 printf("You must specify a test to run, or 'ALL'\n");
2788 for (i=2;i<argc_new;i++) {
2789 if (!run_test(argv_new[i])) {