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 "dynconfig.h"
24 #include "lib/cmdline/popt_common.h"
25 #include "libcli/raw/libcliraw.h"
26 #include "system/time.h"
27 #include "system/wait.h"
29 #include "librpc/gen_ndr/ndr_security.h"
32 int torture_numops=100;
33 int torture_entries=1000;
34 int torture_failures=1;
36 static int procnum; /* records process count number when forking */
37 static struct smbcli_state *current_cli;
38 static BOOL use_oplocks;
39 static BOOL use_level_II_oplocks;
41 BOOL torture_showall = False;
43 #define CHECK_MAX_FAILURES(label) do { if (++failures >= torture_failures) goto label; } while (0)
45 static struct smbcli_state *open_nbt_connection(void)
47 struct nmb_name called, calling;
48 struct smbcli_state *cli;
49 const char *host = lp_parm_string(-1, "torture", "host");
51 make_nmb_name(&calling, lp_netbios_name(), 0x0);
52 choose_called_name(&called, host, 0x20);
54 cli = smbcli_state_init(NULL);
56 printf("Failed initialize smbcli_struct to connect with %s\n", host);
60 if (!smbcli_socket_connect(cli, host)) {
61 printf("Failed to connect with %s\n", host);
65 cli->transport->socket->timeout = 120000; /* set a really long timeout (2 minutes) */
67 if (!smbcli_transport_establish(cli, &calling, &called)) {
69 * Well, that failed, try *SMBSERVER ...
70 * However, we must reconnect as well ...
72 if (!smbcli_socket_connect(cli, host)) {
73 printf("Failed to connect with %s\n", host);
77 make_nmb_name(&called, "*SMBSERVER", 0x20);
78 if (!smbcli_transport_establish(cli, &calling, &called)) {
79 printf("%s rejected the session\n",host);
80 printf("We tried with a called name of %s & %s\n",
90 BOOL torture_open_connection_share(struct smbcli_state **c,
92 const char *sharename)
97 const char *username = lp_parm_string(-1, "torture", "username");
98 const char *userdomain = lp_parm_string(-1, "torture", "userdomain");
99 const char *password = lp_parm_string(-1, "torture", "password");
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));
141 /* initialise a DCOM context */
142 NTSTATUS torture_dcom_init(struct dcom_context **ctx)
144 dcom_init(ctx, lp_parm_string(-1, "torture", "userdomain"),
145 lp_parm_string(-1, "torture", "username"),
146 lp_parm_string(-1, "torture", "password"));
151 /* open a rpc connection to the chosen binding string */
152 NTSTATUS torture_rpc_connection(struct dcerpc_pipe **p,
153 const char *pipe_name,
154 const char *pipe_uuid,
155 uint32_t pipe_version)
158 const char *binding = lp_parm_string(-1, "torture", "binding");
161 printf("You must specify a ncacn binding string\n");
162 return NT_STATUS_INVALID_PARAMETER;
165 status = dcerpc_pipe_connect(p, binding, pipe_uuid, pipe_version,
166 lp_parm_string(-1, "torture", "userdomain"),
167 lp_parm_string(-1, "torture", "username"),
168 lp_parm_string(-1, "torture", "password"));
173 /* open a rpc connection to a specific transport */
174 NTSTATUS torture_rpc_connection_transport(struct dcerpc_pipe **p,
175 const char *pipe_name,
176 const char *pipe_uuid,
177 uint32_t pipe_version,
178 enum dcerpc_transport_t transport)
181 const char *binding = lp_parm_string(-1, "torture", "binding");
182 struct dcerpc_binding b;
183 TALLOC_CTX *mem_ctx = talloc_init("torture_rpc_connection_smb");
186 printf("You must specify a ncacn binding string\n");
187 return NT_STATUS_INVALID_PARAMETER;
190 status = dcerpc_parse_binding(mem_ctx, binding, &b);
191 if (!NT_STATUS_IS_OK(status)) {
192 DEBUG(0,("Failed to parse dcerpc binding '%s'\n", binding));
193 talloc_destroy(mem_ctx);
197 b.transport = transport;
199 status = dcerpc_pipe_connect_b(p, &b, pipe_uuid, pipe_version,
200 lp_parm_string(-1, "torture", "userdomain"),
201 lp_parm_string(-1, "torture", "username"),
202 lp_parm_string(-1, "torture", "password"));
207 /* close a rpc connection to a named pipe */
208 NTSTATUS torture_rpc_close(struct dcerpc_pipe *p)
210 dcerpc_pipe_close(p);
215 /* check if the server produced the expected error code */
216 BOOL check_error(const char *location, struct smbcli_state *c,
217 uint8_t eclass, uint32_t ecode, NTSTATUS nterr)
219 if (smbcli_is_dos_error(c->tree)) {
223 /* Check DOS error */
225 smbcli_dos_error(c, &class, &num);
227 if (eclass != class || ecode != num) {
228 printf("unexpected error code class=%d code=%d\n",
229 (int)class, (int)num);
230 printf(" expected %d/%d %s (at %s)\n",
231 (int)eclass, (int)ecode, nt_errstr(nterr), location);
240 status = smbcli_nt_error(c->tree);
242 if (NT_STATUS_V(nterr) != NT_STATUS_V(status)) {
243 printf("unexpected error code %s\n", nt_errstr(status));
244 printf(" expected %s (at %s)\n", nt_errstr(nterr), location);
253 static BOOL wait_lock(struct smbcli_state *c, int fnum, uint32_t offset, uint32_t len)
255 while (NT_STATUS_IS_ERR(smbcli_lock(c->tree, fnum, offset, len, -1, WRITE_LOCK))) {
256 if (!check_error(__location__, c, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
262 static BOOL rw_torture(struct smbcli_state *c)
264 const char *lockfname = "\\torture.lck";
268 pid_t pid2, pid = getpid();
273 fnum2 = smbcli_open(c->tree, lockfname, O_RDWR | O_CREAT | O_EXCL,
276 fnum2 = smbcli_open(c->tree, lockfname, O_RDWR, DENY_NONE);
278 printf("open of %s failed (%s)\n", lockfname, smbcli_errstr(c->tree));
283 for (i=0;i<torture_numops;i++) {
284 uint_t n = (uint_t)sys_random()%10;
286 printf("%d\r", i); fflush(stdout);
288 asprintf(&fname, "\\torture.%u", n);
290 if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) {
294 fnum = smbcli_open(c->tree, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL);
296 printf("open failed (%s)\n", smbcli_errstr(c->tree));
301 if (smbcli_write(c->tree, fnum, 0, &pid, 0, sizeof(pid)) != sizeof(pid)) {
302 printf("write failed (%s)\n", smbcli_errstr(c->tree));
307 if (smbcli_write(c->tree, fnum, 0, buf,
308 sizeof(pid)+(j*sizeof(buf)),
309 sizeof(buf)) != sizeof(buf)) {
310 printf("write failed (%s)\n", smbcli_errstr(c->tree));
317 if (smbcli_read(c->tree, fnum, &pid2, 0, sizeof(pid)) != sizeof(pid)) {
318 printf("read failed (%s)\n", smbcli_errstr(c->tree));
323 printf("data corruption!\n");
327 if (NT_STATUS_IS_ERR(smbcli_close(c->tree, fnum))) {
328 printf("close failed (%s)\n", smbcli_errstr(c->tree));
332 if (NT_STATUS_IS_ERR(smbcli_unlink(c->tree, fname))) {
333 printf("unlink failed (%s)\n", smbcli_errstr(c->tree));
337 if (NT_STATUS_IS_ERR(smbcli_unlock(c->tree, fnum2, n*sizeof(int), sizeof(int)))) {
338 printf("unlock failed (%s)\n", smbcli_errstr(c->tree));
344 smbcli_close(c->tree, fnum2);
345 smbcli_unlink(c->tree, lockfname);
352 static BOOL run_torture(struct smbcli_state *cli, int dummy)
356 ret = rw_torture(cli);
358 if (!torture_close_connection(cli)) {
365 static BOOL rw_torture3(struct smbcli_state *c, const char *lockfname)
370 uint8_t buf_rd[131072];
372 uint_t countprev = 0;
376 for (i = 0; i < sizeof(buf); i += sizeof(uint32_t))
378 SIVAL(buf, i, sys_random());
383 fnum = smbcli_open(c->tree, lockfname, O_RDWR | O_CREAT | O_EXCL,
386 printf("first open read/write of %s failed (%s)\n",
387 lockfname, smbcli_errstr(c->tree));
393 for (i = 0; i < 500 && fnum == -1; i++)
395 fnum = smbcli_open(c->tree, lockfname, O_RDONLY,
400 printf("second open read-only of %s failed (%s)\n",
401 lockfname, smbcli_errstr(c->tree));
407 for (count = 0; count < sizeof(buf); count += sent)
409 if (count >= countprev) {
410 printf("%d %8d\r", i, count);
413 countprev += (sizeof(buf) / 20);
418 sent = ((uint_t)sys_random()%(20))+ 1;
419 if (sent > sizeof(buf) - count)
421 sent = sizeof(buf) - count;
424 if (smbcli_write(c->tree, fnum, 0, buf+count, count, (size_t)sent) != sent) {
425 printf("write failed (%s)\n", smbcli_errstr(c->tree));
431 sent = smbcli_read(c->tree, fnum, buf_rd+count, count,
435 printf("read failed offset:%d size:%d (%s)\n",
436 count, sizeof(buf)-count,
437 smbcli_errstr(c->tree));
443 if (memcmp(buf_rd+count, buf+count, sent) != 0)
445 printf("read/write compare failed\n");
446 printf("offset: %d req %d recvd %d\n",
447 count, sizeof(buf)-count, sent);
456 if (NT_STATUS_IS_ERR(smbcli_close(c->tree, fnum))) {
457 printf("close failed (%s)\n", smbcli_errstr(c->tree));
464 static BOOL rw_torture2(struct smbcli_state *c1, struct smbcli_state *c2)
466 const char *lockfname = "\\torture2.lck";
471 uint8_t buf_rd[131072];
473 ssize_t bytes_read, bytes_written;
475 if (smbcli_deltree(c1->tree, lockfname) == -1) {
476 printf("unlink failed (%s)\n", smbcli_errstr(c1->tree));
479 fnum1 = smbcli_open(c1->tree, lockfname, O_RDWR | O_CREAT | O_EXCL,
482 printf("first open read/write of %s failed (%s)\n",
483 lockfname, smbcli_errstr(c1->tree));
486 fnum2 = smbcli_open(c2->tree, lockfname, O_RDONLY,
489 printf("second open read-only of %s failed (%s)\n",
490 lockfname, smbcli_errstr(c2->tree));
491 smbcli_close(c1->tree, fnum1);
495 printf("Checking data integrity over %d ops\n", torture_numops);
497 for (i=0;i<torture_numops;i++)
499 size_t buf_size = ((uint_t)sys_random()%(sizeof(buf)-1))+ 1;
501 printf("%d\r", i); fflush(stdout);
504 generate_random_buffer(buf, buf_size);
506 if ((bytes_written = smbcli_write(c1->tree, fnum1, 0, buf, 0, buf_size)) != buf_size) {
507 printf("write failed (%s)\n", smbcli_errstr(c1->tree));
508 printf("wrote %d, expected %d\n", bytes_written, buf_size);
513 if ((bytes_read = smbcli_read(c2->tree, fnum2, buf_rd, 0, buf_size)) != buf_size) {
514 printf("read failed (%s)\n", smbcli_errstr(c2->tree));
515 printf("read %d, expected %d\n", bytes_read, buf_size);
520 if (memcmp(buf_rd, buf, buf_size) != 0)
522 printf("read/write compare failed\n");
528 if (NT_STATUS_IS_ERR(smbcli_close(c2->tree, fnum2))) {
529 printf("close failed (%s)\n", smbcli_errstr(c2->tree));
532 if (NT_STATUS_IS_ERR(smbcli_close(c1->tree, fnum1))) {
533 printf("close failed (%s)\n", smbcli_errstr(c1->tree));
537 if (NT_STATUS_IS_ERR(smbcli_unlink(c1->tree, lockfname))) {
538 printf("unlink failed (%s)\n", smbcli_errstr(c1->tree));
545 static BOOL run_readwritetest(void)
547 struct smbcli_state *cli1, *cli2;
548 BOOL test1, test2 = True;
550 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
554 printf("starting readwritetest\n");
556 test1 = rw_torture2(cli1, cli2);
557 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1));
560 test2 = rw_torture2(cli1, cli1);
561 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2));
564 if (!torture_close_connection(cli1)) {
568 if (!torture_close_connection(cli2)) {
572 return (test1 && test2);
575 static BOOL run_readwritemulti(struct smbcli_state *cli, int dummy)
579 test = rw_torture3(cli, "\\multitest.txt");
581 if (!torture_close_connection(cli)) {
590 this checks to see if a secondary tconx can use open files from an
593 static BOOL run_tcon_test(void)
595 struct smbcli_state *cli;
596 const char *fname = "\\tcontest.tmp";
598 uint16_t cnum1, cnum2, cnum3;
599 uint16_t vuid1, vuid2;
602 struct smbcli_tree *tree1;
603 const char *host = lp_parm_string(-1, "torture", "host");
604 const char *share = lp_parm_string(-1, "torture", "share");
605 const char *password = lp_parm_string(-1, "torture", "password");
607 if (!torture_open_connection(&cli)) {
611 printf("starting tcontest\n");
613 if (smbcli_deltree(cli->tree, fname) == -1) {
614 printf("unlink of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
617 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
619 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
623 cnum1 = cli->tree->tid;
624 vuid1 = cli->session->vuid;
626 memset(&buf, 0, 4); /* init buf so valgrind won't complain */
627 if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) != 4) {
628 printf("initial write failed (%s)\n", smbcli_errstr(cli->tree));
632 tree1 = cli->tree; /* save old tree connection */
633 if (NT_STATUS_IS_ERR(smbcli_send_tconX(cli, share, "?????", password))) {
634 printf("%s refused 2nd tree connect (%s)\n", host,
635 smbcli_errstr(cli->tree));
636 smbcli_shutdown(cli);
640 cnum2 = cli->tree->tid;
641 cnum3 = MAX(cnum1, cnum2) + 1; /* any invalid number */
642 vuid2 = cli->session->vuid + 1;
644 /* try a write with the wrong tid */
645 cli->tree->tid = cnum2;
647 if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) == 4) {
648 printf("* server allows write with wrong TID\n");
651 printf("server fails write with wrong TID : %s\n", smbcli_errstr(cli->tree));
655 /* try a write with an invalid tid */
656 cli->tree->tid = cnum3;
658 if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) == 4) {
659 printf("* server allows write with invalid TID\n");
662 printf("server fails write with invalid TID : %s\n", smbcli_errstr(cli->tree));
665 /* try a write with an invalid vuid */
666 cli->session->vuid = vuid2;
667 cli->tree->tid = cnum1;
669 if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) == 4) {
670 printf("* server allows write with invalid VUID\n");
673 printf("server fails write with invalid VUID : %s\n", smbcli_errstr(cli->tree));
676 cli->session->vuid = vuid1;
677 cli->tree->tid = cnum1;
679 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum1))) {
680 printf("close failed (%s)\n", smbcli_errstr(cli->tree));
684 cli->tree->tid = cnum2;
686 if (NT_STATUS_IS_ERR(smbcli_tdis(cli))) {
687 printf("secondary tdis failed (%s)\n", smbcli_errstr(cli->tree));
691 cli->tree = tree1; /* restore initial tree */
692 cli->tree->tid = cnum1;
694 if (!torture_close_connection(cli)) {
703 static BOOL tcon_devtest(struct smbcli_state *cli,
704 const char *myshare, const char *devtype,
705 NTSTATUS expected_error)
709 const char *password = lp_parm_string(-1, "torture", "password");
711 status = NT_STATUS_IS_OK(smbcli_send_tconX(cli, myshare, devtype,
714 printf("Trying share %s with devtype %s\n", myshare, devtype);
716 if (NT_STATUS_IS_OK(expected_error)) {
720 printf("tconX to share %s with type %s "
721 "should have succeeded but failed\n",
728 printf("tconx to share %s with type %s "
729 "should have failed but succeeded\n",
733 if (NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),
737 printf("Returned unexpected error\n");
746 checks for correct tconX support
748 static BOOL run_tcon_devtype_test(void)
750 struct smbcli_state *cli1 = NULL;
755 const char *host = lp_parm_string(-1, "torture", "host");
756 const char *share = lp_parm_string(-1, "torture", "share");
757 const char *username = lp_parm_string(-1, "torture", "username");
758 const char *userdomain = lp_parm_string(-1, "torture", "userdomain");
759 const char *password = lp_parm_string(-1, "torture", "password");
761 status = smbcli_full_connection(NULL,
762 &cli1, lp_netbios_name(),
765 username, userdomain,
766 password, flags, &retry);
768 if (!NT_STATUS_IS_OK(status)) {
769 printf("could not open connection\n");
773 if (!tcon_devtest(cli1, "IPC$", "A:", NT_STATUS_BAD_DEVICE_TYPE))
776 if (!tcon_devtest(cli1, "IPC$", "?????", NT_STATUS_OK))
779 if (!tcon_devtest(cli1, "IPC$", "LPT:", NT_STATUS_BAD_DEVICE_TYPE))
782 if (!tcon_devtest(cli1, "IPC$", "IPC", NT_STATUS_OK))
785 if (!tcon_devtest(cli1, "IPC$", "FOOBA", NT_STATUS_BAD_DEVICE_TYPE))
788 if (!tcon_devtest(cli1, share, "A:", NT_STATUS_OK))
791 if (!tcon_devtest(cli1, share, "?????", NT_STATUS_OK))
794 if (!tcon_devtest(cli1, share, "LPT:", NT_STATUS_BAD_DEVICE_TYPE))
797 if (!tcon_devtest(cli1, share, "IPC", NT_STATUS_BAD_DEVICE_TYPE))
800 if (!tcon_devtest(cli1, share, "FOOBA", NT_STATUS_BAD_DEVICE_TYPE))
803 smbcli_shutdown(cli1);
806 printf("Passed tcondevtest\n");
813 test whether fnums and tids open on one VC are available on another (a major
816 static BOOL run_fdpasstest(void)
818 struct smbcli_state *cli1, *cli2;
819 const char *fname = "\\fdpass.tst";
823 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
827 printf("starting fdpasstest\n");
829 smbcli_unlink(cli1->tree, fname);
831 printf("Opening a file on connection 1\n");
833 fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
835 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
839 printf("writing to file on connection 1\n");
841 if (smbcli_write(cli1->tree, fnum1, 0, "hello world\n", 0, 13) != 13) {
842 printf("write failed (%s)\n", smbcli_errstr(cli1->tree));
846 oldtid = cli2->tree->tid;
847 cli2->session->vuid = cli1->session->vuid;
848 cli2->tree->tid = cli1->tree->tid;
849 cli2->session->pid = cli1->session->pid;
851 printf("reading from file on connection 2\n");
853 if (smbcli_read(cli2->tree, fnum1, buf, 0, 13) == 13) {
854 printf("read succeeded! nasty security hole [%s]\n",
859 smbcli_close(cli1->tree, fnum1);
860 smbcli_unlink(cli1->tree, fname);
862 cli2->tree->tid = oldtid;
864 torture_close_connection(cli1);
865 torture_close_connection(cli2);
867 printf("finished fdpasstest\n");
873 test the timing of deferred open requests
875 static BOOL run_deferopen(struct smbcli_state *cli, int dummy)
877 const char *fname = "\\defer_open_test.dat";
883 printf("failed to connect\n");
887 printf("Testing deferred open requests.\n");
894 tv = timeval_current();
895 fnum = smbcli_nt_create_full(cli->tree, fname, 0,
897 FILE_ATTRIBUTE_NORMAL,
898 NTCREATEX_SHARE_ACCESS_NONE,
899 NTCREATEX_DISP_OPEN_IF, 0, 0);
903 if (NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),NT_STATUS_SHARING_VIOLATION)) {
904 double e = timeval_elapsed(&tv);
905 if (e < 0.5 || e > 1.5) {
906 fprintf(stderr,"Timing incorrect %.2f violation\n",
910 } while (NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),NT_STATUS_SHARING_VIOLATION));
913 fprintf(stderr,"Failed to open %s, error=%s\n", fname, smbcli_errstr(cli->tree));
917 printf("pid %u open %d\n", getpid(), i);
921 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum))) {
922 fprintf(stderr,"Failed to close %s, error=%s\n", fname, smbcli_errstr(cli->tree));
928 if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fname))) {
929 /* All until the last unlink will fail with sharing violation. */
930 if (!NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),NT_STATUS_SHARING_VIOLATION)) {
931 printf("unlink of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
936 printf("deferred test finished\n");
937 if (!torture_close_connection(cli)) {
944 test how many open files this server supports on the one socket
946 static BOOL run_maxfidtest(struct smbcli_state *cli, int dummy)
948 #define MAXFID_TEMPLATE "\\maxfid\\fid%d\\maxfid.%d.%d"
950 int fnums[0x11000], i;
951 int retries=4, maxfid;
955 printf("failed to connect\n");
959 if (smbcli_deltree(cli->tree, "\\maxfid") == -1) {
960 printf("Failed to deltree \\maxfid - %s\n",
961 smbcli_errstr(cli->tree));
964 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, "\\maxfid"))) {
965 printf("Failed to mkdir \\maxfid, error=%s\n",
966 smbcli_errstr(cli->tree));
970 printf("Testing maximum number of open files\n");
972 for (i=0; i<0x11000; i++) {
974 asprintf(&fname, "\\maxfid\\fid%d", i/1000);
975 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, fname))) {
976 printf("Failed to mkdir %s, error=%s\n",
977 fname, smbcli_errstr(cli->tree));
982 asprintf(&fname, MAXFID_TEMPLATE, i/1000, i,(int)getpid());
983 if ((fnums[i] = smbcli_open(cli->tree, fname,
984 O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) ==
986 printf("open of %s failed (%s)\n",
987 fname, smbcli_errstr(cli->tree));
988 printf("maximum fnum is %d\n", i);
999 printf("cleaning up\n");
1000 for (i=0;i<maxfid/2;i++) {
1001 asprintf(&fname, MAXFID_TEMPLATE, i/1000, i,(int)getpid());
1002 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnums[i]))) {
1003 printf("Close of fnum %d failed - %s\n", fnums[i], smbcli_errstr(cli->tree));
1005 if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fname))) {
1006 printf("unlink of %s failed (%s)\n",
1007 fname, smbcli_errstr(cli->tree));
1012 asprintf(&fname, MAXFID_TEMPLATE, (maxfid-i)/1000, maxfid-i,(int)getpid());
1013 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnums[maxfid-i]))) {
1014 printf("Close of fnum %d failed - %s\n", fnums[maxfid-i], smbcli_errstr(cli->tree));
1016 if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fname))) {
1017 printf("unlink of %s failed (%s)\n",
1018 fname, smbcli_errstr(cli->tree));
1023 printf("%6d %6d\r", i, maxfid-i);
1027 if (smbcli_deltree(cli->tree, "\\maxfid") == -1) {
1028 printf("Failed to deltree \\maxfid - %s\n",
1029 smbcli_errstr(cli->tree));
1033 printf("maxfid test finished\n");
1034 if (!torture_close_connection(cli)) {
1038 #undef MAXFID_TEMPLATE
1041 /* send smb negprot commands, not reading the response */
1042 static BOOL run_negprot_nowait(void)
1045 struct smbcli_state *cli, *cli2;
1046 BOOL correct = True;
1048 printf("starting negprot nowait test\n");
1050 cli = open_nbt_connection();
1055 printf("Filling send buffer\n");
1057 for (i=0;i<10000;i++) {
1058 struct smbcli_request *req;
1059 time_t t1 = time(NULL);
1060 req = smb_negprot_send(cli->transport, PROTOCOL_NT1);
1061 while (req->state == SMBCLI_REQUEST_SEND && time(NULL) < t1+5) {
1062 smbcli_transport_process(cli->transport);
1064 if (req->state == SMBCLI_REQUEST_ERROR) {
1065 printf("Failed to fill pipe - %s\n", nt_errstr(req->status));
1066 torture_close_connection(cli);
1069 if (req->state == SMBCLI_REQUEST_SEND) {
1075 printf("send buffer failed to fill\n");
1076 if (!torture_close_connection(cli)) {
1082 printf("send buffer filled after %d requests\n", i);
1084 printf("Opening secondary connection\n");
1085 if (!torture_open_connection(&cli2)) {
1089 if (!torture_close_connection(cli)) {
1093 if (!torture_close_connection(cli2)) {
1097 printf("finished negprot nowait test\n");
1104 This checks how the getatr calls works
1106 static BOOL run_attrtest(void)
1108 struct smbcli_state *cli;
1111 const char *fname = "\\attrib123456789.tst";
1112 BOOL correct = True;
1114 printf("starting attrib test\n");
1116 if (!torture_open_connection(&cli)) {
1120 smbcli_unlink(cli->tree, fname);
1121 fnum = smbcli_open(cli->tree, fname,
1122 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1123 smbcli_close(cli->tree, fnum);
1125 if (NT_STATUS_IS_ERR(smbcli_getatr(cli->tree, fname, NULL, NULL, &t))) {
1126 printf("getatr failed (%s)\n", smbcli_errstr(cli->tree));
1130 printf("New file time is %s", ctime(&t));
1132 if (abs(t - time(NULL)) > 60*60*24*10) {
1133 printf("ERROR: SMBgetatr bug. time is %s",
1139 t2 = t-60*60*24; /* 1 day ago */
1141 printf("Setting file time to %s", ctime(&t2));
1143 if (NT_STATUS_IS_ERR(smbcli_setatr(cli->tree, fname, 0, t2))) {
1144 printf("setatr failed (%s)\n", smbcli_errstr(cli->tree));
1148 if (NT_STATUS_IS_ERR(smbcli_getatr(cli->tree, fname, NULL, NULL, &t))) {
1149 printf("getatr failed (%s)\n", smbcli_errstr(cli->tree));
1153 printf("Retrieved file time as %s", ctime(&t));
1156 printf("ERROR: getatr/setatr bug. times are\n%s",
1158 printf("%s", ctime(&t2));
1162 smbcli_unlink(cli->tree, fname);
1164 if (!torture_close_connection(cli)) {
1168 printf("attrib test finished\n");
1175 This checks a couple of trans2 calls
1177 static BOOL run_trans2test(void)
1179 struct smbcli_state *cli;
1182 time_t c_time, a_time, m_time, w_time, m_time2;
1183 const char *fname = "\\trans2.tst";
1184 const char *dname = "\\trans2";
1185 const char *fname2 = "\\trans2\\trans2.tst";
1187 BOOL correct = True;
1189 printf("starting trans2 test\n");
1191 if (!torture_open_connection(&cli)) {
1195 smbcli_unlink(cli->tree, fname);
1197 printf("Testing qfileinfo\n");
1199 fnum = smbcli_open(cli->tree, fname,
1200 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1201 if (NT_STATUS_IS_ERR(smbcli_qfileinfo(cli->tree, fnum, NULL, &size, &c_time, &a_time, &m_time,
1203 printf("ERROR: qfileinfo failed (%s)\n", smbcli_errstr(cli->tree));
1207 printf("Testing NAME_INFO\n");
1209 if (NT_STATUS_IS_ERR(smbcli_qfilename(cli->tree, fnum, &pname))) {
1210 printf("ERROR: qfilename failed (%s)\n", smbcli_errstr(cli->tree));
1214 if (!pname || strcmp(pname, fname)) {
1215 printf("qfilename gave different name? [%s] [%s]\n",
1220 smbcli_close(cli->tree, fnum);
1221 smbcli_unlink(cli->tree, fname);
1223 fnum = smbcli_open(cli->tree, fname,
1224 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1226 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
1229 smbcli_close(cli->tree, fnum);
1231 printf("Checking for sticky create times\n");
1233 if (NT_STATUS_IS_ERR(smbcli_qpathinfo(cli->tree, fname, &c_time, &a_time, &m_time, &size, NULL))) {
1234 printf("ERROR: qpathinfo failed (%s)\n", smbcli_errstr(cli->tree));
1237 if (c_time != m_time) {
1238 printf("create time=%s", ctime(&c_time));
1239 printf("modify time=%s", ctime(&m_time));
1240 printf("This system appears to have sticky create times\n");
1242 if (a_time % (60*60) == 0) {
1243 printf("access time=%s", ctime(&a_time));
1244 printf("This system appears to set a midnight access time\n");
1248 if (abs(m_time - time(NULL)) > 60*60*24*7) {
1249 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
1255 smbcli_unlink(cli->tree, fname);
1256 fnum = smbcli_open(cli->tree, fname,
1257 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1258 smbcli_close(cli->tree, fnum);
1259 if (NT_STATUS_IS_ERR(smbcli_qpathinfo2(cli->tree, fname, &c_time, &a_time, &m_time, &w_time, &size, NULL, NULL))) {
1260 printf("ERROR: qpathinfo2 failed (%s)\n", smbcli_errstr(cli->tree));
1263 if (w_time < 60*60*24*2) {
1264 printf("write time=%s", ctime(&w_time));
1265 printf("This system appears to set a initial 0 write time\n");
1270 smbcli_unlink(cli->tree, fname);
1273 /* check if the server updates the directory modification time
1274 when creating a new file */
1275 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, dname))) {
1276 printf("ERROR: mkdir failed (%s)\n", smbcli_errstr(cli->tree));
1280 if (NT_STATUS_IS_ERR(smbcli_qpathinfo2(cli->tree, "\\trans2\\", &c_time, &a_time, &m_time, &w_time, &size, NULL, NULL))) {
1281 printf("ERROR: qpathinfo2 failed (%s)\n", smbcli_errstr(cli->tree));
1285 fnum = smbcli_open(cli->tree, fname2,
1286 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1287 smbcli_write(cli->tree, fnum, 0, &fnum, 0, sizeof(fnum));
1288 smbcli_close(cli->tree, fnum);
1289 if (NT_STATUS_IS_ERR(smbcli_qpathinfo2(cli->tree, "\\trans2\\", &c_time, &a_time, &m_time2, &w_time, &size, NULL, NULL))) {
1290 printf("ERROR: qpathinfo2 failed (%s)\n", smbcli_errstr(cli->tree));
1293 if (m_time2 == m_time) {
1294 printf("This system does not update directory modification times\n");
1298 smbcli_unlink(cli->tree, fname2);
1299 smbcli_rmdir(cli->tree, dname);
1301 if (!torture_close_connection(cli)) {
1305 printf("trans2 test finished\n");
1312 /* FIRST_DESIRED_ACCESS 0xf019f */
1313 #define FIRST_DESIRED_ACCESS SEC_FILE_READ_DATA|SEC_FILE_WRITE_DATA|SEC_FILE_APPEND_DATA|\
1314 SEC_FILE_READ_EA| /* 0xf */ \
1315 SEC_FILE_WRITE_EA|SEC_FILE_READ_ATTRIBUTE| /* 0x90 */ \
1316 SEC_FILE_WRITE_ATTRIBUTE| /* 0x100 */ \
1317 SEC_STD_DELETE|SEC_STD_READ_CONTROL|\
1318 SEC_STD_WRITE_DAC|SEC_STD_WRITE_OWNER /* 0xf0000 */
1319 /* SECOND_DESIRED_ACCESS 0xe0080 */
1320 #define SECOND_DESIRED_ACCESS SEC_FILE_READ_ATTRIBUTE| /* 0x80 */ \
1321 SEC_STD_READ_CONTROL|SEC_STD_WRITE_DAC|\
1322 SEC_STD_WRITE_OWNER /* 0xe0000 */
1325 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTE| /* 0x80 */ \
1326 READ_CONTROL|WRITE_DAC|\
1327 SEC_FILE_READ_DATA|\
1332 Test ntcreate calls made by xcopy
1334 static BOOL run_xcopy(void)
1336 struct smbcli_state *cli1;
1337 const char *fname = "\\test.txt";
1338 BOOL correct = True;
1341 printf("starting xcopy test\n");
1343 if (!torture_open_connection(&cli1)) {
1347 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0,
1348 FIRST_DESIRED_ACCESS,
1349 FILE_ATTRIBUTE_ARCHIVE,
1350 NTCREATEX_SHARE_ACCESS_NONE,
1351 NTCREATEX_DISP_OVERWRITE_IF,
1355 printf("First open failed - %s\n", smbcli_errstr(cli1->tree));
1359 fnum2 = smbcli_nt_create_full(cli1->tree, fname, 0,
1360 SECOND_DESIRED_ACCESS, 0,
1361 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN,
1364 printf("second open failed - %s\n", smbcli_errstr(cli1->tree));
1368 if (!torture_close_connection(cli1)) {
1377 see how many RPC pipes we can open at once
1379 static BOOL run_pipe_number(void)
1381 struct smbcli_state *cli1;
1382 const char *pipe_name = "\\WKSSVC";
1386 printf("starting pipenumber test\n");
1387 if (!torture_open_connection(&cli1)) {
1392 fnum = smbcli_nt_create_full(cli1->tree, pipe_name, 0, SEC_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
1393 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1396 printf("Open of pipe %s failed with error (%s)\n", pipe_name, smbcli_errstr(cli1->tree));
1400 printf("%d\r", num_pipes);
1404 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes, pipe_name );
1405 torture_close_connection(cli1);
1413 open N connections to the server and just hold them open
1414 used for testing performance when there are N idle users
1417 static BOOL torture_holdcon(void)
1420 struct smbcli_state **cli;
1423 printf("Opening %d connections\n", torture_numops);
1425 cli = malloc_array_p(struct smbcli_state *, torture_numops);
1427 for (i=0;i<torture_numops;i++) {
1428 if (!torture_open_connection(&cli[i])) {
1431 printf("opened %d connections\r", i);
1435 printf("\nStarting pings\n");
1438 for (i=0;i<torture_numops;i++) {
1441 status = smbcli_chkpath(cli[i]->tree, "\\");
1442 if (!NT_STATUS_IS_OK(status)) {
1443 printf("Connection %d is dead\n", i);
1451 if (num_dead == torture_numops) {
1452 printf("All connections dead - finishing\n");
1464 Try with a wrong vuid and check error message.
1467 static BOOL run_vuidtest(void)
1469 struct smbcli_state *cli;
1470 const char *fname = "\\vuid.tst";
1473 time_t c_time, a_time, m_time;
1474 BOOL correct = True;
1479 printf("starting vuid test\n");
1481 if (!torture_open_connection(&cli)) {
1485 smbcli_unlink(cli->tree, fname);
1487 fnum = smbcli_open(cli->tree, fname,
1488 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1490 orig_vuid = cli->session->vuid;
1492 cli->session->vuid += 1234;
1494 printf("Testing qfileinfo with wrong vuid\n");
1496 if (NT_STATUS_IS_OK(result = smbcli_qfileinfo(cli->tree, fnum, NULL,
1497 &size, &c_time, &a_time,
1498 &m_time, NULL, NULL))) {
1499 printf("ERROR: qfileinfo passed with wrong vuid\n");
1503 if ( (cli->transport->error.etype != ETYPE_DOS) ||
1504 (cli->transport->error.e.dos.eclass != ERRSRV) ||
1505 (cli->transport->error.e.dos.ecode != ERRbaduid) ) {
1506 printf("ERROR: qfileinfo should have returned DOS error "
1507 "ERRSRV:ERRbaduid\n but returned %s\n",
1508 smbcli_errstr(cli->tree));
1512 cli->session->vuid -= 1234;
1514 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum))) {
1515 printf("close failed (%s)\n", smbcli_errstr(cli->tree));
1519 smbcli_unlink(cli->tree, fname);
1521 if (!torture_close_connection(cli)) {
1525 printf("vuid test finished\n");
1531 Test open mode returns on read-only files.
1533 static BOOL run_opentest(void)
1535 static struct smbcli_state *cli1;
1536 static struct smbcli_state *cli2;
1537 const char *fname = "\\readonly.file";
1541 BOOL correct = True;
1545 printf("starting open test\n");
1547 if (!torture_open_connection(&cli1)) {
1551 smbcli_setatr(cli1->tree, fname, 0, 0);
1552 smbcli_unlink(cli1->tree, fname);
1554 fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1556 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1560 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1561 printf("close2 failed (%s)\n", smbcli_errstr(cli1->tree));
1565 if (NT_STATUS_IS_ERR(smbcli_setatr(cli1->tree, fname, FILE_ATTRIBUTE_READONLY, 0))) {
1566 printf("smbcli_setatr failed (%s)\n", smbcli_errstr(cli1->tree));
1567 CHECK_MAX_FAILURES(error_test1);
1571 fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY, DENY_WRITE);
1573 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1574 CHECK_MAX_FAILURES(error_test1);
1578 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
1579 fnum2 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_ALL);
1581 if (check_error(__location__, cli1, ERRDOS, ERRnoaccess,
1582 NT_STATUS_ACCESS_DENIED)) {
1583 printf("correct error code ERRDOS/ERRnoaccess returned\n");
1586 printf("finished open test 1\n");
1588 smbcli_close(cli1->tree, fnum1);
1590 /* Now try not readonly and ensure ERRbadshare is returned. */
1592 smbcli_setatr(cli1->tree, fname, 0, 0);
1594 fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY, DENY_WRITE);
1596 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1600 /* This will fail - but the error should be ERRshare. */
1601 fnum2 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_ALL);
1603 if (check_error(__location__, cli1, ERRDOS, ERRbadshare,
1604 NT_STATUS_SHARING_VIOLATION)) {
1605 printf("correct error code ERRDOS/ERRbadshare returned\n");
1608 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1609 printf("close2 failed (%s)\n", smbcli_errstr(cli1->tree));
1613 smbcli_unlink(cli1->tree, fname);
1615 printf("finished open test 2\n");
1617 /* Test truncate open disposition on file opened for read. */
1619 fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1621 printf("(3) open (1) of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1625 /* write 20 bytes. */
1627 memset(buf, '\0', 20);
1629 if (smbcli_write(cli1->tree, fnum1, 0, buf, 0, 20) != 20) {
1630 printf("write failed (%s)\n", smbcli_errstr(cli1->tree));
1634 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1635 printf("(3) close1 failed (%s)\n", smbcli_errstr(cli1->tree));
1639 /* Ensure size == 20. */
1640 if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
1641 printf("(3) getatr failed (%s)\n", smbcli_errstr(cli1->tree));
1642 CHECK_MAX_FAILURES(error_test3);
1647 printf("(3) file size != 20\n");
1648 CHECK_MAX_FAILURES(error_test3);
1652 /* Now test if we can truncate a file opened for readonly. */
1654 fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY|O_TRUNC, DENY_NONE);
1656 printf("(3) open (2) of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1657 CHECK_MAX_FAILURES(error_test3);
1661 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1662 printf("close2 failed (%s)\n", smbcli_errstr(cli1->tree));
1666 /* Ensure size == 0. */
1667 if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
1668 printf("(3) getatr failed (%s)\n", smbcli_errstr(cli1->tree));
1669 CHECK_MAX_FAILURES(error_test3);
1674 printf("(3) file size != 0\n");
1675 CHECK_MAX_FAILURES(error_test3);
1678 printf("finished open test 3\n");
1680 smbcli_unlink(cli1->tree, fname);
1683 printf("testing ctemp\n");
1684 fnum1 = smbcli_ctemp(cli1->tree, "\\", &tmp_path);
1686 printf("ctemp failed (%s)\n", smbcli_errstr(cli1->tree));
1687 CHECK_MAX_FAILURES(error_test4);
1690 printf("ctemp gave path %s\n", tmp_path);
1691 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1692 printf("close of temp failed (%s)\n", smbcli_errstr(cli1->tree));
1694 if (NT_STATUS_IS_ERR(smbcli_unlink(cli1->tree, tmp_path))) {
1695 printf("unlink of temp failed (%s)\n", smbcli_errstr(cli1->tree));
1698 /* Test the non-io opens... */
1700 if (!torture_open_connection(&cli2)) {
1704 smbcli_setatr(cli2->tree, fname, 0, 0);
1705 smbcli_unlink(cli2->tree, fname);
1707 printf("TEST #1 testing 2 non-io opens (no delete)\n");
1709 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1710 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1713 printf("test 1 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1714 CHECK_MAX_FAILURES(error_test10);
1718 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1719 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1721 printf("test 1 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1722 CHECK_MAX_FAILURES(error_test10);
1726 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1727 printf("test 1 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1730 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1731 printf("test 1 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1735 printf("non-io open test #1 passed.\n");
1737 smbcli_unlink(cli1->tree, fname);
1739 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
1741 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SEC_STD_DELETE|SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1742 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1745 printf("test 2 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1746 CHECK_MAX_FAILURES(error_test20);
1750 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1751 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1754 printf("test 2 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1755 CHECK_MAX_FAILURES(error_test20);
1759 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1760 printf("test 1 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1763 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1764 printf("test 1 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1768 printf("non-io open test #2 passed.\n");
1770 smbcli_unlink(cli1->tree, fname);
1772 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
1774 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1775 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1778 printf("test 3 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1779 CHECK_MAX_FAILURES(error_test30);
1783 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SEC_STD_DELETE|SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1784 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1787 printf("test 3 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1788 CHECK_MAX_FAILURES(error_test30);
1792 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1793 printf("test 3 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1796 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1797 printf("test 3 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1801 printf("non-io open test #3 passed.\n");
1803 smbcli_unlink(cli1->tree, fname);
1805 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
1807 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SEC_STD_DELETE|SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1808 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1811 printf("test 4 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1812 CHECK_MAX_FAILURES(error_test40);
1816 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SEC_STD_DELETE|SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1817 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1820 printf("test 4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1821 CHECK_MAX_FAILURES(error_test40);
1825 printf("test 4 open 2 of %s gave %s (correct error should be %s)\n", fname, smbcli_errstr(cli2->tree), "sharing violation");
1827 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1828 printf("test 4 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1832 printf("non-io open test #4 passed.\n");
1834 smbcli_unlink(cli1->tree, fname);
1836 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
1838 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SEC_STD_DELETE|SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1839 NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1842 printf("test 5 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1843 CHECK_MAX_FAILURES(error_test50);
1847 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SEC_STD_DELETE|SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1848 NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1851 printf("test 5 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1852 CHECK_MAX_FAILURES(error_test50);
1856 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1857 printf("test 5 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1861 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1862 printf("test 5 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1866 printf("non-io open test #5 passed.\n");
1868 printf("TEST #6 testing 1 non-io open, one io open\n");
1870 smbcli_unlink(cli1->tree, fname);
1872 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SEC_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
1873 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1876 printf("test 6 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1877 CHECK_MAX_FAILURES(error_test60);
1881 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1882 NTCREATEX_SHARE_ACCESS_READ, NTCREATEX_DISP_OPEN_IF, 0, 0);
1885 printf("test 6 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1886 CHECK_MAX_FAILURES(error_test60);
1890 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1891 printf("test 6 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1895 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1896 printf("test 6 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1900 printf("non-io open test #6 passed.\n");
1902 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
1904 smbcli_unlink(cli1->tree, fname);
1906 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SEC_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
1907 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1910 printf("test 7 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1911 CHECK_MAX_FAILURES(error_test70);
1915 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SEC_STD_DELETE|SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1916 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1919 printf("test 7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1920 CHECK_MAX_FAILURES(error_test70);
1924 printf("test 7 open 2 of %s gave %s (correct error should be %s)\n", fname, smbcli_errstr(cli2->tree), "sharing violation");
1926 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1927 printf("test 7 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1931 printf("non-io open test #7 passed.\n");
1935 printf("TEST #8 testing one normal open, followed by lock, followed by open with truncate\n");
1937 smbcli_unlink(cli1->tree, fname);
1939 fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
1941 printf("(8) open (1) of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1945 /* write 20 bytes. */
1947 memset(buf, '\0', 20);
1949 if (smbcli_write(cli1->tree, fnum1, 0, buf, 0, 20) != 20) {
1950 printf("(8) write failed (%s)\n", smbcli_errstr(cli1->tree));
1954 /* Ensure size == 20. */
1955 if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
1956 printf("(8) getatr (1) failed (%s)\n", smbcli_errstr(cli1->tree));
1957 CHECK_MAX_FAILURES(error_test80);
1962 printf("(8) file size != 20\n");
1963 CHECK_MAX_FAILURES(error_test80);
1967 /* Get an exclusive lock on the open file. */
1968 if (NT_STATUS_IS_ERR(smbcli_lock(cli1->tree, fnum1, 0, 4, 0, WRITE_LOCK))) {
1969 printf("(8) lock1 failed (%s)\n", smbcli_errstr(cli1->tree));
1970 CHECK_MAX_FAILURES(error_test80);
1974 fnum2 = smbcli_open(cli1->tree, fname, O_RDWR|O_TRUNC, DENY_NONE);
1976 printf("(8) open (2) of %s with truncate failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1980 /* Ensure size == 0. */
1981 if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
1982 printf("(8) getatr (2) failed (%s)\n", smbcli_errstr(cli1->tree));
1983 CHECK_MAX_FAILURES(error_test80);
1988 printf("(8) file size != 0\n");
1989 CHECK_MAX_FAILURES(error_test80);
1993 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1994 printf("(8) close1 failed (%s)\n", smbcli_errstr(cli1->tree));
1998 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum2))) {
1999 printf("(8) close1 failed (%s)\n", smbcli_errstr(cli1->tree));
2005 printf("open test #8 passed.\n");
2007 smbcli_unlink(cli1->tree, fname);
2009 if (!torture_close_connection(cli1)) {
2012 if (!torture_close_connection(cli2)) {
2021 sees what IOCTLs are supported
2023 BOOL torture_ioctl_test(void)
2025 struct smbcli_state *cli;
2026 uint16_t device, function;
2028 const char *fname = "\\ioctl.dat";
2030 union smb_ioctl parms;
2031 TALLOC_CTX *mem_ctx;
2033 if (!torture_open_connection(&cli)) {
2037 mem_ctx = talloc_init("ioctl_test");
2039 printf("starting ioctl test\n");
2041 smbcli_unlink(cli->tree, fname);
2043 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2045 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
2049 parms.ioctl.level = RAW_IOCTL_IOCTL;
2050 parms.ioctl.in.fnum = fnum;
2051 parms.ioctl.in.request = IOCTL_QUERY_JOB_INFO;
2052 status = smb_raw_ioctl(cli->tree, mem_ctx, &parms);
2053 printf("ioctl job info: %s\n", smbcli_errstr(cli->tree));
2055 for (device=0;device<0x100;device++) {
2056 printf("testing device=0x%x\n", device);
2057 for (function=0;function<0x100;function++) {
2058 parms.ioctl.in.request = (device << 16) | function;
2059 status = smb_raw_ioctl(cli->tree, mem_ctx, &parms);
2061 if (NT_STATUS_IS_OK(status)) {
2062 printf("ioctl device=0x%x function=0x%x OK : %d bytes\n",
2063 device, function, parms.ioctl.out.blob.length);
2068 if (!torture_close_connection(cli)) {
2077 tries variants of chkpath
2079 BOOL torture_chkpath_test(void)
2081 struct smbcli_state *cli;
2085 if (!torture_open_connection(&cli)) {
2089 printf("starting chkpath test\n");
2091 printf("Testing valid and invalid paths\n");
2093 /* cleanup from an old run */
2094 smbcli_rmdir(cli->tree, "\\chkpath.dir\\dir2");
2095 smbcli_unlink(cli->tree, "\\chkpath.dir\\*");
2096 smbcli_rmdir(cli->tree, "\\chkpath.dir");
2098 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, "\\chkpath.dir"))) {
2099 printf("mkdir1 failed : %s\n", smbcli_errstr(cli->tree));
2103 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, "\\chkpath.dir\\dir2"))) {
2104 printf("mkdir2 failed : %s\n", smbcli_errstr(cli->tree));
2108 fnum = smbcli_open(cli->tree, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2110 printf("open1 failed (%s)\n", smbcli_errstr(cli->tree));
2113 smbcli_close(cli->tree, fnum);
2115 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir"))) {
2116 printf("chkpath1 failed: %s\n", smbcli_errstr(cli->tree));
2120 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\dir2"))) {
2121 printf("chkpath2 failed: %s\n", smbcli_errstr(cli->tree));
2125 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\foo.txt"))) {
2126 ret = check_error(__location__, cli, ERRDOS, ERRbadpath,
2127 NT_STATUS_NOT_A_DIRECTORY);
2129 printf("* chkpath on a file should fail\n");
2133 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\bar.txt"))) {
2134 ret = check_error(__location__, cli, ERRDOS, ERRbadfile,
2135 NT_STATUS_OBJECT_NAME_NOT_FOUND);
2137 printf("* chkpath on a non existent file should fail\n");
2141 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\dirxx\\bar.txt"))) {
2142 ret = check_error(__location__, cli, ERRDOS, ERRbadpath,
2143 NT_STATUS_OBJECT_PATH_NOT_FOUND);
2145 printf("* chkpath on a non existent component should fail\n");
2149 smbcli_rmdir(cli->tree, "\\chkpath.dir\\dir2");
2150 smbcli_unlink(cli->tree, "\\chkpath.dir\\*");
2151 smbcli_rmdir(cli->tree, "\\chkpath.dir");
2153 if (!torture_close_connection(cli)) {
2162 parse a //server/share type UNC name
2164 static BOOL parse_unc(const char *unc_name, char **hostname, char **sharename)
2168 if (strncmp(unc_name, "//", 2)) {
2172 *hostname = strdup(&unc_name[2]);
2173 p = strchr_m(&(*hostname)[2],'/');
2178 *sharename = strdup(p+1);
2185 static void sigcont(int sig)
2189 double torture_create_procs(BOOL (*fn)(struct smbcli_state *, int), BOOL *result)
2192 volatile pid_t *child_status;
2193 volatile BOOL *child_status_out;
2196 double start_time_limit = 10 + (torture_nprocs * 1.5);
2197 char **unc_list = NULL;
2199 int num_unc_names = 0;
2204 signal(SIGCONT, sigcont);
2206 child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*torture_nprocs);
2207 if (!child_status) {
2208 printf("Failed to setup shared memory\n");
2212 child_status_out = (volatile BOOL *)shm_setup(sizeof(BOOL)*torture_nprocs);
2213 if (!child_status_out) {
2214 printf("Failed to setup result status shared memory\n");
2218 p = lp_parm_string(-1, "torture", "unclist");
2220 unc_list = file_lines_load(p, &num_unc_names);
2221 if (!unc_list || num_unc_names <= 0) {
2222 printf("Failed to load unc names list from '%s'\n", p);
2227 for (i = 0; i < torture_nprocs; i++) {
2228 child_status[i] = 0;
2229 child_status_out[i] = True;
2232 tv = timeval_current();
2234 for (i=0;i<torture_nprocs;i++) {
2238 char *hostname=NULL, *sharename;
2240 pid_t mypid = getpid();
2241 sys_srandom(((int)mypid) ^ ((int)time(NULL)));
2243 asprintf(&myname, "CLIENT%d", i);
2244 lp_set_cmdline("netbios name", myname);
2249 if (!parse_unc(unc_list[i % num_unc_names],
2250 &hostname, &sharename)) {
2251 printf("Failed to parse UNC name %s\n",
2252 unc_list[i % num_unc_names]);
2259 if (torture_open_connection_share(¤t_cli,
2264 } else if (torture_open_connection(¤t_cli)) {
2268 printf("pid %d failed to start\n", (int)getpid());
2274 child_status[i] = getpid();
2278 if (child_status[i]) {
2279 printf("Child %d failed to start!\n", i);
2280 child_status_out[i] = 1;
2284 child_status_out[i] = fn(current_cli, i);
2291 for (i=0;i<torture_nprocs;i++) {
2292 if (child_status[i]) synccount++;
2294 if (synccount == torture_nprocs) break;
2296 } while (timeval_elapsed(&tv) < start_time_limit);
2298 if (synccount != torture_nprocs) {
2299 printf("FAILED TO START %d CLIENTS (started %d)\n", torture_nprocs, synccount);
2301 return timeval_elapsed(&tv);
2304 printf("Starting %d clients\n", torture_nprocs);
2306 /* start the client load */
2307 tv = timeval_current();
2308 for (i=0;i<torture_nprocs;i++) {
2309 child_status[i] = 0;
2312 printf("%d clients started\n", torture_nprocs);
2316 for (i=0;i<torture_nprocs;i++) {
2318 while ((ret=sys_waitpid(0, &status, 0)) == -1 && errno == EINTR) /* noop */ ;
2319 if (ret == -1 || WEXITSTATUS(status) != 0) {
2326 for (i=0;i<torture_nprocs;i++) {
2327 if (!child_status_out[i]) {
2331 return timeval_elapsed(&tv);
2334 #define FLAG_MULTIPROC 1
2339 BOOL (*multi_fn)(struct smbcli_state *, int );
2342 {"BASE-FDPASS", run_fdpasstest, 0},
2343 {"BASE-LOCK1", torture_locktest1, 0},
2344 {"BASE-LOCK2", torture_locktest2, 0},
2345 {"BASE-LOCK3", torture_locktest3, 0},
2346 {"BASE-LOCK4", torture_locktest4, 0},
2347 {"BASE-LOCK5", torture_locktest5, 0},
2348 {"BASE-LOCK6", torture_locktest6, 0},
2349 {"BASE-LOCK7", torture_locktest7, 0},
2350 {"BASE-UNLINK", torture_unlinktest, 0},
2351 {"BASE-ATTR", run_attrtest, 0},
2352 {"BASE-TRANS2", run_trans2test, 0},
2353 {"BASE-NEGNOWAIT", run_negprot_nowait, 0},
2354 {"BASE-DIR1", torture_dirtest1, 0},
2355 {"BASE-DIR2", torture_dirtest2, 0},
2356 {"BASE-DENY1", torture_denytest1, 0},
2357 {"BASE-DENY2", torture_denytest2, 0},
2358 {"BASE-DENY3", torture_denytest3, 0},
2359 {"BASE-DENYDOS", torture_denydos_sharing, 0},
2360 {"BASE-NTDENY1", NULL, torture_ntdenytest1},
2361 {"BASE-NTDENY2", torture_ntdenytest2, 0},
2362 {"BASE-TCON", run_tcon_test, 0},
2363 {"BASE-TCONDEV", run_tcon_devtype_test, 0},
2364 {"BASE-VUID", run_vuidtest, 0},
2365 {"BASE-RW1", run_readwritetest, 0},
2366 {"BASE-RW2", NULL, run_readwritemulti},
2367 {"BASE-OPEN", run_opentest, 0},
2368 {"BASE-DEFER_OPEN", NULL, run_deferopen},
2369 {"BASE-XCOPY", run_xcopy, 0},
2370 {"BASE-RENAME", torture_test_rename, 0},
2371 {"BASE-DELETE", torture_test_delete, 0},
2372 {"BASE-PROPERTIES", torture_test_properties, 0},
2373 {"BASE-MANGLE", torture_mangle, 0},
2374 {"BASE-OPENATTR", torture_openattrtest, 0},
2375 {"BASE-CHARSET", torture_charset, 0},
2376 {"BASE-CHKPATH", torture_chkpath_test, 0},
2377 {"BASE-SECLEAK", torture_sec_leak, 0},
2378 {"BASE-DISCONNECT", torture_disconnect, 0},
2379 {"BASE-DELAYWRITE", torture_delay_write, 0},
2381 /* benchmarking tests */
2382 {"BENCH-HOLDCON", torture_holdcon, 0},
2383 {"BENCH-NBENCH", torture_nbench, 0},
2384 {"BENCH-TORTURE", NULL, run_torture},
2387 {"RAW-QFSINFO", torture_raw_qfsinfo, 0},
2388 {"RAW-QFILEINFO", torture_raw_qfileinfo, 0},
2389 {"RAW-SFILEINFO", torture_raw_sfileinfo, 0},
2390 {"RAW-SFILEINFO-BUG", torture_raw_sfileinfo_bug, 0},
2391 {"RAW-SEARCH", torture_raw_search, 0},
2392 {"RAW-CLOSE", torture_raw_close, 0},
2393 {"RAW-OPEN", torture_raw_open, 0},
2394 {"RAW-MKDIR", torture_raw_mkdir, 0},
2395 {"RAW-OPLOCK", torture_raw_oplock, 0},
2396 {"RAW-NOTIFY", torture_raw_notify, 0},
2397 {"RAW-MUX", torture_raw_mux, 0},
2398 {"RAW-IOCTL", torture_raw_ioctl, 0},
2399 {"RAW-CHKPATH", torture_raw_chkpath, 0},
2400 {"RAW-UNLINK", torture_raw_unlink, 0},
2401 {"RAW-READ", torture_raw_read, 0},
2402 {"RAW-WRITE", torture_raw_write, 0},
2403 {"RAW-LOCK", torture_raw_lock, 0},
2404 {"RAW-CONTEXT", torture_raw_context, 0},
2405 {"RAW-RENAME", torture_raw_rename, 0},
2406 {"RAW-SEEK", torture_raw_seek, 0},
2407 {"RAW-EAS", torture_raw_eas, 0},
2408 {"RAW-STREAMS", torture_raw_streams, 0},
2409 {"RAW-ACLS", torture_raw_acls, 0},
2410 {"RAW-RAP", torture_raw_rap, 0},
2412 /* protocol scanners */
2413 {"SCAN-TRANS2", torture_trans2_scan, 0},
2414 {"SCAN-NTTRANS", torture_nttrans_scan, 0},
2415 {"SCAN-ALIASES", torture_trans2_aliases, 0},
2416 {"SCAN-SMB", torture_smb_scan, 0},
2417 {"SCAN-MAXFID", NULL, run_maxfidtest},
2418 {"SCAN-UTABLE", torture_utable, 0},
2419 {"SCAN-CASETABLE", torture_casetable, 0},
2420 {"SCAN-PIPE_NUMBER", run_pipe_number, 0},
2421 {"SCAN-IOCTL", torture_ioctl_test, 0},
2424 {"RPC-LSA", torture_rpc_lsa, 0},
2425 {"RPC-ECHO", torture_rpc_echo, 0},
2426 {"RPC-DFS", torture_rpc_dfs, 0},
2427 {"RPC-SPOOLSS", torture_rpc_spoolss, 0},
2428 {"RPC-SAMR", torture_rpc_samr, 0},
2429 {"RPC-NETLOGON", torture_rpc_netlogon, 0},
2430 {"RPC-SAMLOGON", torture_rpc_samlogon, 0},
2431 {"RPC-SAMSYNC", torture_rpc_samsync, 0},
2432 {"RPC-SCHANNEL", torture_rpc_schannel, 0},
2433 {"RPC-WKSSVC", torture_rpc_wkssvc, 0},
2434 {"RPC-SRVSVC", torture_rpc_srvsvc, 0},
2435 {"RPC-SVCCTL", torture_rpc_svcctl, 0},
2436 {"RPC-ATSVC", torture_rpc_atsvc, 0},
2437 {"RPC-EVENTLOG", torture_rpc_eventlog, 0},
2438 {"RPC-EPMAPPER", torture_rpc_epmapper, 0},
2439 {"RPC-WINREG", torture_rpc_winreg, 0},
2440 {"RPC-OXIDRESOLVE", torture_rpc_oxidresolve, 0},
2441 {"RPC-REMACT", torture_rpc_remact, 0},
2442 {"RPC-MGMT", torture_rpc_mgmt, 0},
2443 {"RPC-SCANNER", torture_rpc_scanner, 0},
2444 {"RPC-AUTOIDL", torture_rpc_autoidl, 0},
2445 {"RPC-COUNTCALLS", torture_rpc_countcalls, 0},
2446 {"RPC-MULTIBIND", torture_multi_bind, 0},
2447 {"RPC-DRSUAPI", torture_rpc_drsuapi, 0},
2448 {"RPC-LOGIN", torture_rpc_login, 0},
2449 {"RPC-ROT", torture_rpc_rot, 0},
2450 {"RPC-DSSETUP", torture_rpc_dssetup, 0},
2452 /* Distributed COM testers */
2453 {"DCOM-SIMPLE", torture_dcom_simple, 0},
2455 /* local (no server) testers */
2456 {"LOCAL-NTLMSSP", torture_ntlmssp_self_check, 0},
2457 {"LOCAL-ICONV", torture_local_iconv, 0},
2458 {"LOCAL-TALLOC", torture_local_talloc, 0},
2459 {"LOCAL-MESSAGING", torture_local_messaging, 0},
2460 {"LOCAL-BINDING", torture_local_binding_string, 0},
2461 {"LOCAL-IDTREE", torture_local_idtree, 0},
2464 {"LDAP-BASIC", torture_ldap_basic, 0},
2470 /****************************************************************************
2471 run a specified test or "ALL"
2472 ****************************************************************************/
2473 static BOOL run_test(const char *name)
2477 BOOL matched = False;
2479 if (strequal(name,"ALL")) {
2480 for (i=0;torture_ops[i].name;i++) {
2481 if (!run_test(torture_ops[i].name)) {
2488 for (i=0;torture_ops[i].name;i++) {
2489 if (gen_fnmatch(name, torture_ops[i].name) == 0) {
2493 printf("Running %s\n", torture_ops[i].name);
2494 if (torture_ops[i].multi_fn) {
2496 t = torture_create_procs(torture_ops[i].multi_fn,
2500 printf("TEST %s FAILED!\n", torture_ops[i].name);
2504 struct timeval tv = timeval_current();
2505 if (!torture_ops[i].fn()) {
2507 printf("TEST %s FAILED!\n", torture_ops[i].name);
2509 t = timeval_elapsed(&tv);
2511 printf("%s took %g secs\n\n", torture_ops[i].name, t);
2516 printf("Unknown torture operation '%s'\n", name);
2523 static void parse_dns(const char *dns)
2525 char *userdn, *basedn, *secret;
2528 /* retrievieng the userdn */
2529 p = strchr_m(dns, '#');
2531 lp_set_cmdline("torture:ldap_userdn", "");
2532 lp_set_cmdline("torture:ldap_basedn", "");
2533 lp_set_cmdline("torture:ldap_secret", "");
2536 userdn = strndup(dns, p - dns);
2537 lp_set_cmdline("torture:ldap_userdn", userdn);
2539 /* retrieve the basedn */
2541 p = strchr_m(d, '#');
2543 lp_set_cmdline("torture:ldap_basedn", "");
2544 lp_set_cmdline("torture:ldap_secret", "");
2547 basedn = strndup(d, p - d);
2548 lp_set_cmdline("torture:ldap_basedn", basedn);
2550 /* retrieve the secret */
2553 lp_set_cmdline("torture:ldap_secret", "");
2557 lp_set_cmdline("torture:ldap_secret", secret);
2559 printf ("%s - %s - %s\n", userdn, basedn, secret);
2563 static void usage(poptContext pc)
2568 poptPrintUsage(pc, stdout, 0);
2571 printf("The binding format is:\n\n");
2573 printf(" TRANSPORT:host[flags]\n\n");
2575 printf(" where TRANSPORT is either ncacn_np for SMB or ncacn_ip_tcp for RPC/TCP\n\n");
2577 printf(" 'host' is an IP or hostname or netbios name. If the binding string\n");
2578 printf(" identifies the server side of an endpoint, 'host' may be an empty\n");
2579 printf(" string.\n\n");
2581 printf(" 'flags' can include a SMB pipe name if using the ncacn_np transport or\n");
2582 printf(" a TCP port number if using the ncacn_ip_tcp transport, otherwise they\n");
2583 printf(" will be auto-determined.\n\n");
2585 printf(" other recognised flags are:\n\n");
2587 printf(" sign : enable ntlmssp signing\n");
2588 printf(" seal : enable ntlmssp sealing\n");
2589 printf(" connect : enable rpc connect level auth (auth, but no sign or seal)\n");
2590 printf(" validate: enable the NDR validator\n");
2591 printf(" print: enable debugging of the packets\n");
2592 printf(" bigendian: use bigendian RPC\n");
2593 printf(" padcheck: check reply data for non-zero pad bytes\n\n");
2595 printf(" For example, these all connect to the samr pipe:\n\n");
2597 printf(" ncacn_np:myserver\n");
2598 printf(" ncacn_np:myserver[samr]\n");
2599 printf(" ncacn_np:myserver[\\pipe\\samr]\n");
2600 printf(" ncacn_np:myserver[/pipe/samr]\n");
2601 printf(" ncacn_np:myserver[samr,sign,print]\n");
2602 printf(" ncacn_np:myserver[\\pipe\\samr,sign,seal,bigendian]\n");
2603 printf(" ncacn_np:myserver[/pipe/samr,seal,validate]\n");
2604 printf(" ncacn_np:\n");
2605 printf(" ncacn_np:[/pipe/samr]\n\n");
2607 printf(" ncacn_ip_tcp:myserver\n");
2608 printf(" ncacn_ip_tcp:myserver[1024]\n");
2609 printf(" ncacn_ip_tcp:myserver[1024,sign,seal]\n\n");
2611 printf("The unc format is:\n\n");
2613 printf(" //server/share\n\n");
2615 printf("tests are:");
2616 for (i=0;torture_ops[i].name;i++) {
2617 if ((i%perline)==0) {
2620 printf("%s ", torture_ops[i].name);
2624 printf("default test is ALL\n");
2629 static BOOL is_binding_string(const char *binding_string)
2631 TALLOC_CTX *mem_ctx = talloc_init("is_binding_string");
2632 struct dcerpc_binding binding_struct;
2635 status = dcerpc_parse_binding(mem_ctx, binding_string, &binding_struct);
2637 talloc_destroy(mem_ctx);
2638 return NT_STATUS_IS_OK(status);
2641 /****************************************************************************
2643 ****************************************************************************/
2644 int main(int argc,char *argv[])
2648 BOOL correct = True;
2652 enum {OPT_LOADFILE=1000,OPT_UNCLIST,OPT_TIMELIMIT,OPT_DNS,OPT_DANGEROUS};
2653 struct poptOption long_options[] = {
2655 {"smb-ports", 'p', POPT_ARG_STRING, NULL, 0, "SMB ports", NULL},
2656 {"seed", 0, POPT_ARG_INT, &torture_seed, 0, "seed", NULL},
2657 {"num-progs", 0, POPT_ARG_INT, &torture_nprocs, 0, "num progs", NULL},
2658 {"num-ops", 0, POPT_ARG_INT, &torture_numops, 0, "num ops", NULL},
2659 {"entries", 0, POPT_ARG_INT, &torture_entries, 0, "entries", NULL},
2660 {"use-oplocks", 'L', POPT_ARG_NONE, &use_oplocks, 0, "use oplocks", NULL},
2661 {"show-all", 0, POPT_ARG_NONE, &torture_showall, 0, "show all", NULL},
2662 {"loadfile", 0, POPT_ARG_STRING, NULL, OPT_LOADFILE, "loadfile", NULL},
2663 {"unclist", 0, POPT_ARG_STRING, NULL, OPT_UNCLIST, "unclist", NULL},
2664 {"timelimit", 't', POPT_ARG_STRING, NULL, OPT_TIMELIMIT, "timelimit", NULL},
2665 {"failures", 'f', POPT_ARG_INT, &torture_failures, 0, "failures", NULL},
2666 {"parse-dns", 'D', POPT_ARG_STRING, NULL, OPT_DNS, "parse-dns", NULL},
2667 {"dangerous", 'X', POPT_ARG_NONE, NULL, OPT_DANGEROUS, "dangerous", NULL},
2669 POPT_COMMON_CONNECTION
2670 POPT_COMMON_CREDENTIALS
2675 setup_logging("smbtorture", DEBUG_STDOUT);
2677 #ifdef HAVE_SETBUFFER
2678 setbuffer(stdout, NULL, 0);
2681 pc = poptGetContext("smbtorture", argc, (const char **) argv, long_options,
2682 POPT_CONTEXT_KEEP_FIRST);
2684 poptSetOtherOptionHelp(pc, "<binding>|<unc> TEST1 TEST2 ...");
2686 while((opt = poptGetNextOpt(pc)) != -1) {
2689 lp_set_cmdline("torture:loadfile", poptGetOptArg(pc));
2692 lp_set_cmdline("torture:unclist", poptGetOptArg(pc));
2695 lp_set_cmdline("torture:timelimit", poptGetOptArg(pc));
2698 parse_dns(poptGetOptArg(pc));
2701 lp_set_cmdline("torture:dangerous", "Yes");
2704 d_printf("Invalid option %s: %s\n",
2705 poptBadOption(pc, 0), poptStrerror(opt));
2711 lp_load(dyn_CONFIGFILE,True,False,False);
2714 smbtorture_init_subsystems;
2717 if (torture_seed == 0) {
2718 torture_seed = time(NULL);
2720 printf("Using seed %d\n", torture_seed);
2721 srandom(torture_seed);
2723 argv_new = discard_const_p(char *, poptGetArgs(pc));
2726 for (i=0; i<argc; i++) {
2727 if (argv_new[i] == NULL) {
2738 for(p = argv_new[1]; *p; p++) {
2743 /* see if its a RPC transport specifier */
2744 if (is_binding_string(argv_new[1])) {
2745 lp_set_cmdline("torture:binding", argv_new[1]);
2747 char *binding = NULL;
2748 char *host = NULL, *share = NULL;
2750 if (!parse_unc(argv_new[1], &host, &share)) {
2751 d_printf("Invalid option: %s is not a valid torture target (share or binding string)\n\n", argv_new[1]);
2755 lp_set_cmdline("torture:host", host);
2756 lp_set_cmdline("torture:share", share);
2757 asprintf(&binding, "ncacn_np:%s", host);
2758 lp_set_cmdline("torture:binding", binding);
2761 if (!lp_parm_string(-1,"torture","username")) {
2762 lp_set_cmdline("torture:username", cmdline_get_username());
2764 if (!lp_parm_string(-1,"torture","userdomain")) {
2766 * backward compatibility
2767 * maybe we should remove this to make this consistent
2768 * for all cmdline tools
2771 if (strequal(lp_netbios_name(),cmdline_get_userdomain())) {
2772 cmdline_set_userdomain(lp_workgroup());
2774 lp_set_cmdline("torture:userdomain", cmdline_get_userdomain());
2776 if (!lp_parm_string(-1,"torture","password")) {
2777 lp_set_cmdline("torture:password", cmdline_get_userpassword());
2780 if (argc_new == 0) {
2781 printf("You must specify a test to run, or 'ALL'\n");
2783 for (i=2;i<argc_new;i++) {
2784 if (!run_test(argv_new[i])) {