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 if (!smbcli_transport_establish(cli, &calling, &called)) {
67 * Well, that failed, try *SMBSERVER ...
68 * However, we must reconnect as well ...
70 if (!smbcli_socket_connect(cli, host)) {
71 printf("Failed to connect with %s\n", host);
75 make_nmb_name(&called, "*SMBSERVER", 0x20);
76 if (!smbcli_transport_establish(cli, &calling, &called)) {
77 printf("%s rejected the session\n",host);
78 printf("We tried with a called name of %s & %s\n",
88 BOOL torture_open_connection_share(struct smbcli_state **c,
90 const char *sharename)
95 const char *username = lp_parm_string(-1, "torture", "username");
96 const char *userdomain = lp_parm_string(-1, "torture", "userdomain");
97 const char *password = lp_parm_string(-1, "torture", "password");
99 status = smbcli_full_connection(NULL,
100 c, lp_netbios_name(),
103 username, username[0]?userdomain:"",
104 password, flags, &retry);
105 if (!NT_STATUS_IS_OK(status)) {
106 printf("Failed to open connection - %s\n", nt_errstr(status));
110 (*c)->transport->options.use_oplocks = use_oplocks;
111 (*c)->transport->options.use_level2_oplocks = use_level_II_oplocks;
116 BOOL torture_open_connection(struct smbcli_state **c)
118 const char *host = lp_parm_string(-1, "torture", "host");
119 const char *share = lp_parm_string(-1, "torture", "share");
121 return torture_open_connection_share(c, host, share);
126 BOOL torture_close_connection(struct smbcli_state *c)
130 if (NT_STATUS_IS_ERR(smbcli_tdis(c))) {
131 printf("tdis failed (%s)\n", smbcli_errstr(c->tree));
138 /* initialise a DCOM context */
139 NTSTATUS torture_dcom_init(struct dcom_context **ctx)
141 dcom_init(ctx, lp_parm_string(-1, "torture", "userdomain"),
142 lp_parm_string(-1, "torture", "username"),
143 lp_parm_string(-1, "torture", "password"));
148 /* open a rpc connection to the chosen binding string */
149 NTSTATUS torture_rpc_connection(struct dcerpc_pipe **p,
150 const char *pipe_name,
151 const char *pipe_uuid,
152 uint32_t pipe_version)
155 const char *binding = lp_parm_string(-1, "torture", "binding");
158 printf("You must specify a ncacn binding string\n");
159 return NT_STATUS_INVALID_PARAMETER;
162 status = dcerpc_pipe_connect(p, binding, pipe_uuid, pipe_version,
163 lp_parm_string(-1, "torture", "userdomain"),
164 lp_parm_string(-1, "torture", "username"),
165 lp_parm_string(-1, "torture", "password"));
170 /* open a rpc connection to a specific transport */
171 NTSTATUS torture_rpc_connection_transport(struct dcerpc_pipe **p,
172 const char *pipe_name,
173 const char *pipe_uuid,
174 uint32_t pipe_version,
175 enum dcerpc_transport_t transport)
178 const char *binding = lp_parm_string(-1, "torture", "binding");
179 struct dcerpc_binding b;
180 TALLOC_CTX *mem_ctx = talloc_init("torture_rpc_connection_smb");
183 printf("You must specify a ncacn binding string\n");
184 return NT_STATUS_INVALID_PARAMETER;
187 status = dcerpc_parse_binding(mem_ctx, binding, &b);
188 if (!NT_STATUS_IS_OK(status)) {
189 DEBUG(0,("Failed to parse dcerpc binding '%s'\n", binding));
190 talloc_destroy(mem_ctx);
194 b.transport = transport;
196 status = dcerpc_pipe_connect_b(p, &b, pipe_uuid, pipe_version,
197 lp_parm_string(-1, "torture", "userdomain"),
198 lp_parm_string(-1, "torture", "username"),
199 lp_parm_string(-1, "torture", "password"));
204 /* close a rpc connection to a named pipe */
205 NTSTATUS torture_rpc_close(struct dcerpc_pipe *p)
207 dcerpc_pipe_close(p);
212 /* check if the server produced the expected error code */
213 BOOL check_error(const char *location, struct smbcli_state *c,
214 uint8_t eclass, uint32_t ecode, NTSTATUS nterr)
216 if (smbcli_is_dos_error(c->tree)) {
220 /* Check DOS error */
222 smbcli_dos_error(c, &class, &num);
224 if (eclass != class || ecode != num) {
225 printf("unexpected error code class=%d code=%d\n",
226 (int)class, (int)num);
227 printf(" expected %d/%d %s (at %s)\n",
228 (int)eclass, (int)ecode, nt_errstr(nterr), location);
237 status = smbcli_nt_error(c->tree);
239 if (NT_STATUS_V(nterr) != NT_STATUS_V(status)) {
240 printf("unexpected error code %s\n", nt_errstr(status));
241 printf(" expected %s (at %s)\n", nt_errstr(nterr), location);
250 static BOOL wait_lock(struct smbcli_state *c, int fnum, uint32_t offset, uint32_t len)
252 while (NT_STATUS_IS_ERR(smbcli_lock(c->tree, fnum, offset, len, -1, WRITE_LOCK))) {
253 if (!check_error(__location__, c, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
259 static BOOL rw_torture(struct smbcli_state *c)
261 const char *lockfname = "\\torture.lck";
265 pid_t pid2, pid = getpid();
270 fnum2 = smbcli_open(c->tree, lockfname, O_RDWR | O_CREAT | O_EXCL,
273 fnum2 = smbcli_open(c->tree, lockfname, O_RDWR, DENY_NONE);
275 printf("open of %s failed (%s)\n", lockfname, smbcli_errstr(c->tree));
280 for (i=0;i<torture_numops;i++) {
281 uint_t n = (uint_t)sys_random()%10;
283 printf("%d\r", i); fflush(stdout);
285 asprintf(&fname, "\\torture.%u", n);
287 if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) {
291 fnum = smbcli_open(c->tree, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL);
293 printf("open failed (%s)\n", smbcli_errstr(c->tree));
298 if (smbcli_write(c->tree, fnum, 0, &pid, 0, sizeof(pid)) != sizeof(pid)) {
299 printf("write failed (%s)\n", smbcli_errstr(c->tree));
304 if (smbcli_write(c->tree, fnum, 0, buf,
305 sizeof(pid)+(j*sizeof(buf)),
306 sizeof(buf)) != sizeof(buf)) {
307 printf("write failed (%s)\n", smbcli_errstr(c->tree));
314 if (smbcli_read(c->tree, fnum, &pid2, 0, sizeof(pid)) != sizeof(pid)) {
315 printf("read failed (%s)\n", smbcli_errstr(c->tree));
320 printf("data corruption!\n");
324 if (NT_STATUS_IS_ERR(smbcli_close(c->tree, fnum))) {
325 printf("close failed (%s)\n", smbcli_errstr(c->tree));
329 if (NT_STATUS_IS_ERR(smbcli_unlink(c->tree, fname))) {
330 printf("unlink failed (%s)\n", smbcli_errstr(c->tree));
334 if (NT_STATUS_IS_ERR(smbcli_unlock(c->tree, fnum2, n*sizeof(int), sizeof(int)))) {
335 printf("unlock failed (%s)\n", smbcli_errstr(c->tree));
341 smbcli_close(c->tree, fnum2);
342 smbcli_unlink(c->tree, lockfname);
349 static BOOL run_torture(struct smbcli_state *cli, int dummy)
353 ret = rw_torture(cli);
355 if (!torture_close_connection(cli)) {
362 static BOOL rw_torture3(struct smbcli_state *c, const char *lockfname)
367 uint8_t buf_rd[131072];
369 uint_t countprev = 0;
373 for (i = 0; i < sizeof(buf); i += sizeof(uint32_t))
375 SIVAL(buf, i, sys_random());
380 fnum = smbcli_open(c->tree, lockfname, O_RDWR | O_CREAT | O_EXCL,
383 printf("first open read/write of %s failed (%s)\n",
384 lockfname, smbcli_errstr(c->tree));
390 for (i = 0; i < 500 && fnum == -1; i++)
392 fnum = smbcli_open(c->tree, lockfname, O_RDONLY,
397 printf("second open read-only of %s failed (%s)\n",
398 lockfname, smbcli_errstr(c->tree));
404 for (count = 0; count < sizeof(buf); count += sent)
406 if (count >= countprev) {
407 printf("%d %8d\r", i, count);
410 countprev += (sizeof(buf) / 20);
415 sent = ((uint_t)sys_random()%(20))+ 1;
416 if (sent > sizeof(buf) - count)
418 sent = sizeof(buf) - count;
421 if (smbcli_write(c->tree, fnum, 0, buf+count, count, (size_t)sent) != sent) {
422 printf("write failed (%s)\n", smbcli_errstr(c->tree));
428 sent = smbcli_read(c->tree, fnum, buf_rd+count, count,
432 printf("read failed offset:%d size:%d (%s)\n",
433 count, sizeof(buf)-count,
434 smbcli_errstr(c->tree));
440 if (memcmp(buf_rd+count, buf+count, sent) != 0)
442 printf("read/write compare failed\n");
443 printf("offset: %d req %d recvd %d\n",
444 count, sizeof(buf)-count, sent);
453 if (NT_STATUS_IS_ERR(smbcli_close(c->tree, fnum))) {
454 printf("close failed (%s)\n", smbcli_errstr(c->tree));
461 static BOOL rw_torture2(struct smbcli_state *c1, struct smbcli_state *c2)
463 const char *lockfname = "\\torture2.lck";
468 uint8_t buf_rd[131072];
470 ssize_t bytes_read, bytes_written;
472 if (smbcli_deltree(c1->tree, lockfname) == -1) {
473 printf("unlink failed (%s)\n", smbcli_errstr(c1->tree));
476 fnum1 = smbcli_open(c1->tree, lockfname, O_RDWR | O_CREAT | O_EXCL,
479 printf("first open read/write of %s failed (%s)\n",
480 lockfname, smbcli_errstr(c1->tree));
483 fnum2 = smbcli_open(c2->tree, lockfname, O_RDONLY,
486 printf("second open read-only of %s failed (%s)\n",
487 lockfname, smbcli_errstr(c2->tree));
488 smbcli_close(c1->tree, fnum1);
492 printf("Checking data integrity over %d ops\n", torture_numops);
494 for (i=0;i<torture_numops;i++)
496 size_t buf_size = ((uint_t)sys_random()%(sizeof(buf)-1))+ 1;
498 printf("%d\r", i); fflush(stdout);
501 generate_random_buffer(buf, buf_size);
503 if ((bytes_written = smbcli_write(c1->tree, fnum1, 0, buf, 0, buf_size)) != buf_size) {
504 printf("write failed (%s)\n", smbcli_errstr(c1->tree));
505 printf("wrote %d, expected %d\n", bytes_written, buf_size);
510 if ((bytes_read = smbcli_read(c2->tree, fnum2, buf_rd, 0, buf_size)) != buf_size) {
511 printf("read failed (%s)\n", smbcli_errstr(c2->tree));
512 printf("read %d, expected %d\n", bytes_read, buf_size);
517 if (memcmp(buf_rd, buf, buf_size) != 0)
519 printf("read/write compare failed\n");
525 if (NT_STATUS_IS_ERR(smbcli_close(c2->tree, fnum2))) {
526 printf("close failed (%s)\n", smbcli_errstr(c2->tree));
529 if (NT_STATUS_IS_ERR(smbcli_close(c1->tree, fnum1))) {
530 printf("close failed (%s)\n", smbcli_errstr(c1->tree));
534 if (NT_STATUS_IS_ERR(smbcli_unlink(c1->tree, lockfname))) {
535 printf("unlink failed (%s)\n", smbcli_errstr(c1->tree));
542 static BOOL run_readwritetest(void)
544 struct smbcli_state *cli1, *cli2;
545 BOOL test1, test2 = True;
547 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
551 printf("starting readwritetest\n");
553 test1 = rw_torture2(cli1, cli2);
554 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1));
557 test2 = rw_torture2(cli1, cli1);
558 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2));
561 if (!torture_close_connection(cli1)) {
565 if (!torture_close_connection(cli2)) {
569 return (test1 && test2);
572 static BOOL run_readwritemulti(struct smbcli_state *cli, int dummy)
576 test = rw_torture3(cli, "\\multitest.txt");
578 if (!torture_close_connection(cli)) {
587 this checks to see if a secondary tconx can use open files from an
590 static BOOL run_tcon_test(void)
592 struct smbcli_state *cli;
593 const char *fname = "\\tcontest.tmp";
595 uint16_t cnum1, cnum2, cnum3;
596 uint16_t vuid1, vuid2;
599 struct smbcli_tree *tree1;
600 const char *host = lp_parm_string(-1, "torture", "host");
601 const char *share = lp_parm_string(-1, "torture", "share");
602 const char *password = lp_parm_string(-1, "torture", "password");
604 if (!torture_open_connection(&cli)) {
608 printf("starting tcontest\n");
610 if (smbcli_deltree(cli->tree, fname) == -1) {
611 printf("unlink of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
614 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
616 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
620 cnum1 = cli->tree->tid;
621 vuid1 = cli->session->vuid;
623 memset(&buf, 0, 4); /* init buf so valgrind won't complain */
624 if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) != 4) {
625 printf("initial write failed (%s)\n", smbcli_errstr(cli->tree));
629 tree1 = cli->tree; /* save old tree connection */
630 if (NT_STATUS_IS_ERR(smbcli_send_tconX(cli, share, "?????", password))) {
631 printf("%s refused 2nd tree connect (%s)\n", host,
632 smbcli_errstr(cli->tree));
633 smbcli_shutdown(cli);
637 cnum2 = cli->tree->tid;
638 cnum3 = MAX(cnum1, cnum2) + 1; /* any invalid number */
639 vuid2 = cli->session->vuid + 1;
641 /* try a write with the wrong tid */
642 cli->tree->tid = cnum2;
644 if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) == 4) {
645 printf("* server allows write with wrong TID\n");
648 printf("server fails write with wrong TID : %s\n", smbcli_errstr(cli->tree));
652 /* try a write with an invalid tid */
653 cli->tree->tid = cnum3;
655 if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) == 4) {
656 printf("* server allows write with invalid TID\n");
659 printf("server fails write with invalid TID : %s\n", smbcli_errstr(cli->tree));
662 /* try a write with an invalid vuid */
663 cli->session->vuid = vuid2;
664 cli->tree->tid = cnum1;
666 if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) == 4) {
667 printf("* server allows write with invalid VUID\n");
670 printf("server fails write with invalid VUID : %s\n", smbcli_errstr(cli->tree));
673 cli->session->vuid = vuid1;
674 cli->tree->tid = cnum1;
676 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum1))) {
677 printf("close failed (%s)\n", smbcli_errstr(cli->tree));
681 cli->tree->tid = cnum2;
683 if (NT_STATUS_IS_ERR(smbcli_tdis(cli))) {
684 printf("secondary tdis failed (%s)\n", smbcli_errstr(cli->tree));
688 cli->tree = tree1; /* restore initial tree */
689 cli->tree->tid = cnum1;
691 if (!torture_close_connection(cli)) {
700 static BOOL tcon_devtest(struct smbcli_state *cli,
701 const char *myshare, const char *devtype,
702 NTSTATUS expected_error)
706 const char *password = lp_parm_string(-1, "torture", "password");
708 status = NT_STATUS_IS_OK(smbcli_send_tconX(cli, myshare, devtype,
711 printf("Trying share %s with devtype %s\n", myshare, devtype);
713 if (NT_STATUS_IS_OK(expected_error)) {
717 printf("tconX to share %s with type %s "
718 "should have succeeded but failed\n",
725 printf("tconx to share %s with type %s "
726 "should have failed but succeeded\n",
730 if (NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),
734 printf("Returned unexpected error\n");
743 checks for correct tconX support
745 static BOOL run_tcon_devtype_test(void)
747 struct smbcli_state *cli1 = NULL;
752 const char *host = lp_parm_string(-1, "torture", "host");
753 const char *share = lp_parm_string(-1, "torture", "share");
754 const char *username = lp_parm_string(-1, "torture", "username");
755 const char *userdomain = lp_parm_string(-1, "torture", "userdomain");
756 const char *password = lp_parm_string(-1, "torture", "password");
758 status = smbcli_full_connection(NULL,
759 &cli1, lp_netbios_name(),
762 username, userdomain,
763 password, flags, &retry);
765 if (!NT_STATUS_IS_OK(status)) {
766 printf("could not open connection\n");
770 if (!tcon_devtest(cli1, "IPC$", "A:", NT_STATUS_BAD_DEVICE_TYPE))
773 if (!tcon_devtest(cli1, "IPC$", "?????", NT_STATUS_OK))
776 if (!tcon_devtest(cli1, "IPC$", "LPT:", NT_STATUS_BAD_DEVICE_TYPE))
779 if (!tcon_devtest(cli1, "IPC$", "IPC", NT_STATUS_OK))
782 if (!tcon_devtest(cli1, "IPC$", "FOOBA", NT_STATUS_BAD_DEVICE_TYPE))
785 if (!tcon_devtest(cli1, share, "A:", NT_STATUS_OK))
788 if (!tcon_devtest(cli1, share, "?????", NT_STATUS_OK))
791 if (!tcon_devtest(cli1, share, "LPT:", NT_STATUS_BAD_DEVICE_TYPE))
794 if (!tcon_devtest(cli1, share, "IPC", NT_STATUS_BAD_DEVICE_TYPE))
797 if (!tcon_devtest(cli1, share, "FOOBA", NT_STATUS_BAD_DEVICE_TYPE))
800 smbcli_shutdown(cli1);
803 printf("Passed tcondevtest\n");
810 test whether fnums and tids open on one VC are available on another (a major
813 static BOOL run_fdpasstest(void)
815 struct smbcli_state *cli1, *cli2;
816 const char *fname = "\\fdpass.tst";
820 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
824 printf("starting fdpasstest\n");
826 smbcli_unlink(cli1->tree, fname);
828 printf("Opening a file on connection 1\n");
830 fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
832 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
836 printf("writing to file on connection 1\n");
838 if (smbcli_write(cli1->tree, fnum1, 0, "hello world\n", 0, 13) != 13) {
839 printf("write failed (%s)\n", smbcli_errstr(cli1->tree));
843 oldtid = cli2->tree->tid;
844 cli2->session->vuid = cli1->session->vuid;
845 cli2->tree->tid = cli1->tree->tid;
846 cli2->session->pid = cli1->session->pid;
848 printf("reading from file on connection 2\n");
850 if (smbcli_read(cli2->tree, fnum1, buf, 0, 13) == 13) {
851 printf("read succeeded! nasty security hole [%s]\n",
856 smbcli_close(cli1->tree, fnum1);
857 smbcli_unlink(cli1->tree, fname);
859 cli2->tree->tid = oldtid;
861 torture_close_connection(cli1);
862 torture_close_connection(cli2);
864 printf("finished fdpasstest\n");
870 test the timing of deferred open requests
872 static BOOL run_deferopen(struct smbcli_state *cli, int dummy)
874 const char *fname = "\\defer_open_test.dat";
880 printf("failed to connect\n");
884 printf("Testing deferred open requests.\n");
891 tv = timeval_current();
892 fnum = smbcli_nt_create_full(cli->tree, fname, 0,
894 FILE_ATTRIBUTE_NORMAL,
895 NTCREATEX_SHARE_ACCESS_NONE,
896 NTCREATEX_DISP_OPEN_IF, 0, 0);
900 if (NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),NT_STATUS_SHARING_VIOLATION)) {
901 double e = timeval_elapsed(&tv);
902 if (e < 0.5 || e > 1.5) {
903 fprintf(stderr,"Timing incorrect %.2f violation\n",
907 } while (NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),NT_STATUS_SHARING_VIOLATION));
910 fprintf(stderr,"Failed to open %s, error=%s\n", fname, smbcli_errstr(cli->tree));
914 printf("pid %u open %d\n", getpid(), i);
918 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum))) {
919 fprintf(stderr,"Failed to close %s, error=%s\n", fname, smbcli_errstr(cli->tree));
925 if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fname))) {
926 /* All until the last unlink will fail with sharing violation. */
927 if (!NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),NT_STATUS_SHARING_VIOLATION)) {
928 printf("unlink of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
933 printf("deferred test finished\n");
934 if (!torture_close_connection(cli)) {
941 test how many open files this server supports on the one socket
943 static BOOL run_maxfidtest(struct smbcli_state *cli, int dummy)
945 #define MAXFID_TEMPLATE "\\maxfid\\fid%d\\maxfid.%d.%d"
947 int fnums[0x11000], i;
948 int retries=4, maxfid;
952 printf("failed to connect\n");
956 if (smbcli_deltree(cli->tree, "\\maxfid") == -1) {
957 printf("Failed to deltree \\maxfid - %s\n",
958 smbcli_errstr(cli->tree));
961 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, "\\maxfid"))) {
962 printf("Failed to mkdir \\maxfid, error=%s\n",
963 smbcli_errstr(cli->tree));
967 printf("Testing maximum number of open files\n");
969 for (i=0; i<0x11000; i++) {
971 asprintf(&fname, "\\maxfid\\fid%d", i/1000);
972 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, fname))) {
973 printf("Failed to mkdir %s, error=%s\n",
974 fname, smbcli_errstr(cli->tree));
979 asprintf(&fname, MAXFID_TEMPLATE, i/1000, i,(int)getpid());
980 if ((fnums[i] = smbcli_open(cli->tree, fname,
981 O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) ==
983 printf("open of %s failed (%s)\n",
984 fname, smbcli_errstr(cli->tree));
985 printf("maximum fnum is %d\n", i);
996 printf("cleaning up\n");
997 for (i=0;i<maxfid/2;i++) {
998 asprintf(&fname, MAXFID_TEMPLATE, i/1000, i,(int)getpid());
999 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnums[i]))) {
1000 printf("Close of fnum %d failed - %s\n", fnums[i], smbcli_errstr(cli->tree));
1002 if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fname))) {
1003 printf("unlink of %s failed (%s)\n",
1004 fname, smbcli_errstr(cli->tree));
1009 asprintf(&fname, MAXFID_TEMPLATE, (maxfid-i)/1000, maxfid-i,(int)getpid());
1010 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnums[maxfid-i]))) {
1011 printf("Close of fnum %d failed - %s\n", fnums[maxfid-i], smbcli_errstr(cli->tree));
1013 if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fname))) {
1014 printf("unlink of %s failed (%s)\n",
1015 fname, smbcli_errstr(cli->tree));
1020 printf("%6d %6d\r", i, maxfid-i);
1024 if (smbcli_deltree(cli->tree, "\\maxfid") == -1) {
1025 printf("Failed to deltree \\maxfid - %s\n",
1026 smbcli_errstr(cli->tree));
1030 printf("maxfid test finished\n");
1031 if (!torture_close_connection(cli)) {
1035 #undef MAXFID_TEMPLATE
1038 /* send smb negprot commands, not reading the response */
1039 static BOOL run_negprot_nowait(void)
1042 struct smbcli_state *cli, *cli2;
1043 BOOL correct = True;
1045 printf("starting negprot nowait test\n");
1047 cli = open_nbt_connection();
1052 printf("Filling send buffer\n");
1054 for (i=0;i<10000;i++) {
1055 struct smbcli_request *req;
1056 time_t t1 = time(NULL);
1057 req = smb_negprot_send(cli->transport, PROTOCOL_NT1);
1058 while (req->state == SMBCLI_REQUEST_SEND && time(NULL) < t1+5) {
1059 smbcli_transport_process(cli->transport);
1061 if (req->state == SMBCLI_REQUEST_ERROR) {
1062 printf("Failed to fill pipe - %s\n", nt_errstr(req->status));
1063 torture_close_connection(cli);
1066 if (req->state == SMBCLI_REQUEST_SEND) {
1072 printf("send buffer failed to fill\n");
1073 if (!torture_close_connection(cli)) {
1079 printf("send buffer filled after %d requests\n", i);
1081 printf("Opening secondary connection\n");
1082 if (!torture_open_connection(&cli2)) {
1086 if (!torture_close_connection(cli)) {
1090 if (!torture_close_connection(cli2)) {
1094 printf("finished negprot nowait test\n");
1101 This checks how the getatr calls works
1103 static BOOL run_attrtest(void)
1105 struct smbcli_state *cli;
1108 const char *fname = "\\attrib123456789.tst";
1109 BOOL correct = True;
1111 printf("starting attrib test\n");
1113 if (!torture_open_connection(&cli)) {
1117 smbcli_unlink(cli->tree, fname);
1118 fnum = smbcli_open(cli->tree, fname,
1119 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1120 smbcli_close(cli->tree, fnum);
1122 if (NT_STATUS_IS_ERR(smbcli_getatr(cli->tree, fname, NULL, NULL, &t))) {
1123 printf("getatr failed (%s)\n", smbcli_errstr(cli->tree));
1127 printf("New file time is %s", ctime(&t));
1129 if (abs(t - time(NULL)) > 60*60*24*10) {
1130 printf("ERROR: SMBgetatr bug. time is %s",
1136 t2 = t-60*60*24; /* 1 day ago */
1138 printf("Setting file time to %s", ctime(&t2));
1140 if (NT_STATUS_IS_ERR(smbcli_setatr(cli->tree, fname, 0, t2))) {
1141 printf("setatr failed (%s)\n", smbcli_errstr(cli->tree));
1145 if (NT_STATUS_IS_ERR(smbcli_getatr(cli->tree, fname, NULL, NULL, &t))) {
1146 printf("getatr failed (%s)\n", smbcli_errstr(cli->tree));
1150 printf("Retrieved file time as %s", ctime(&t));
1153 printf("ERROR: getatr/setatr bug. times are\n%s",
1155 printf("%s", ctime(&t2));
1159 smbcli_unlink(cli->tree, fname);
1161 if (!torture_close_connection(cli)) {
1165 printf("attrib test finished\n");
1172 This checks a couple of trans2 calls
1174 static BOOL run_trans2test(void)
1176 struct smbcli_state *cli;
1179 time_t c_time, a_time, m_time, w_time, m_time2;
1180 const char *fname = "\\trans2.tst";
1181 const char *dname = "\\trans2";
1182 const char *fname2 = "\\trans2\\trans2.tst";
1184 BOOL correct = True;
1186 printf("starting trans2 test\n");
1188 if (!torture_open_connection(&cli)) {
1192 smbcli_unlink(cli->tree, fname);
1194 printf("Testing qfileinfo\n");
1196 fnum = smbcli_open(cli->tree, fname,
1197 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1198 if (NT_STATUS_IS_ERR(smbcli_qfileinfo(cli->tree, fnum, NULL, &size, &c_time, &a_time, &m_time,
1200 printf("ERROR: qfileinfo failed (%s)\n", smbcli_errstr(cli->tree));
1204 printf("Testing NAME_INFO\n");
1206 if (NT_STATUS_IS_ERR(smbcli_qfilename(cli->tree, fnum, &pname))) {
1207 printf("ERROR: qfilename failed (%s)\n", smbcli_errstr(cli->tree));
1211 if (!pname || strcmp(pname, fname)) {
1212 printf("qfilename gave different name? [%s] [%s]\n",
1217 smbcli_close(cli->tree, fnum);
1218 smbcli_unlink(cli->tree, fname);
1220 fnum = smbcli_open(cli->tree, fname,
1221 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1223 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
1226 smbcli_close(cli->tree, fnum);
1228 printf("Checking for sticky create times\n");
1230 if (NT_STATUS_IS_ERR(smbcli_qpathinfo(cli->tree, fname, &c_time, &a_time, &m_time, &size, NULL))) {
1231 printf("ERROR: qpathinfo failed (%s)\n", smbcli_errstr(cli->tree));
1234 if (c_time != m_time) {
1235 printf("create time=%s", ctime(&c_time));
1236 printf("modify time=%s", ctime(&m_time));
1237 printf("This system appears to have sticky create times\n");
1239 if (a_time % (60*60) == 0) {
1240 printf("access time=%s", ctime(&a_time));
1241 printf("This system appears to set a midnight access time\n");
1245 if (abs(m_time - time(NULL)) > 60*60*24*7) {
1246 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
1252 smbcli_unlink(cli->tree, fname);
1253 fnum = smbcli_open(cli->tree, fname,
1254 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1255 smbcli_close(cli->tree, fnum);
1256 if (NT_STATUS_IS_ERR(smbcli_qpathinfo2(cli->tree, fname, &c_time, &a_time, &m_time, &w_time, &size, NULL, NULL))) {
1257 printf("ERROR: qpathinfo2 failed (%s)\n", smbcli_errstr(cli->tree));
1260 if (w_time < 60*60*24*2) {
1261 printf("write time=%s", ctime(&w_time));
1262 printf("This system appears to set a initial 0 write time\n");
1267 smbcli_unlink(cli->tree, fname);
1270 /* check if the server updates the directory modification time
1271 when creating a new file */
1272 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, dname))) {
1273 printf("ERROR: mkdir failed (%s)\n", smbcli_errstr(cli->tree));
1277 if (NT_STATUS_IS_ERR(smbcli_qpathinfo2(cli->tree, "\\trans2\\", &c_time, &a_time, &m_time, &w_time, &size, NULL, NULL))) {
1278 printf("ERROR: qpathinfo2 failed (%s)\n", smbcli_errstr(cli->tree));
1282 fnum = smbcli_open(cli->tree, fname2,
1283 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1284 smbcli_write(cli->tree, fnum, 0, &fnum, 0, sizeof(fnum));
1285 smbcli_close(cli->tree, fnum);
1286 if (NT_STATUS_IS_ERR(smbcli_qpathinfo2(cli->tree, "\\trans2\\", &c_time, &a_time, &m_time2, &w_time, &size, NULL, NULL))) {
1287 printf("ERROR: qpathinfo2 failed (%s)\n", smbcli_errstr(cli->tree));
1290 if (m_time2 == m_time) {
1291 printf("This system does not update directory modification times\n");
1295 smbcli_unlink(cli->tree, fname2);
1296 smbcli_rmdir(cli->tree, dname);
1298 if (!torture_close_connection(cli)) {
1302 printf("trans2 test finished\n");
1309 /* FIRST_DESIRED_ACCESS 0xf019f */
1310 #define FIRST_DESIRED_ACCESS SEC_FILE_READ_DATA|SEC_FILE_WRITE_DATA|SEC_FILE_APPEND_DATA|\
1311 SEC_FILE_READ_EA| /* 0xf */ \
1312 SEC_FILE_WRITE_EA|SEC_FILE_READ_ATTRIBUTE| /* 0x90 */ \
1313 SEC_FILE_WRITE_ATTRIBUTE| /* 0x100 */ \
1314 SEC_STD_DELETE|SEC_STD_READ_CONTROL|\
1315 SEC_STD_WRITE_DAC|SEC_STD_WRITE_OWNER /* 0xf0000 */
1316 /* SECOND_DESIRED_ACCESS 0xe0080 */
1317 #define SECOND_DESIRED_ACCESS SEC_FILE_READ_ATTRIBUTE| /* 0x80 */ \
1318 SEC_STD_READ_CONTROL|SEC_STD_WRITE_DAC|\
1319 SEC_STD_WRITE_OWNER /* 0xe0000 */
1322 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTE| /* 0x80 */ \
1323 READ_CONTROL|WRITE_DAC|\
1324 SEC_FILE_READ_DATA|\
1329 Test ntcreate calls made by xcopy
1331 static BOOL run_xcopy(void)
1333 struct smbcli_state *cli1;
1334 const char *fname = "\\test.txt";
1335 BOOL correct = True;
1338 printf("starting xcopy test\n");
1340 if (!torture_open_connection(&cli1)) {
1344 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0,
1345 FIRST_DESIRED_ACCESS,
1346 FILE_ATTRIBUTE_ARCHIVE,
1347 NTCREATEX_SHARE_ACCESS_NONE,
1348 NTCREATEX_DISP_OVERWRITE_IF,
1352 printf("First open failed - %s\n", smbcli_errstr(cli1->tree));
1356 fnum2 = smbcli_nt_create_full(cli1->tree, fname, 0,
1357 SECOND_DESIRED_ACCESS, 0,
1358 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN,
1361 printf("second open failed - %s\n", smbcli_errstr(cli1->tree));
1365 if (!torture_close_connection(cli1)) {
1374 see how many RPC pipes we can open at once
1376 static BOOL run_pipe_number(void)
1378 struct smbcli_state *cli1;
1379 const char *pipe_name = "\\WKSSVC";
1383 printf("starting pipenumber test\n");
1384 if (!torture_open_connection(&cli1)) {
1389 fnum = smbcli_nt_create_full(cli1->tree, pipe_name, 0, SEC_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
1390 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1393 printf("Open of pipe %s failed with error (%s)\n", pipe_name, smbcli_errstr(cli1->tree));
1397 printf("%d\r", num_pipes);
1401 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes, pipe_name );
1402 torture_close_connection(cli1);
1410 open N connections to the server and just hold them open
1411 used for testing performance when there are N idle users
1414 static BOOL torture_holdcon(void)
1417 struct smbcli_state **cli;
1420 printf("Opening %d connections\n", torture_numops);
1422 cli = malloc_array_p(struct smbcli_state *, torture_numops);
1424 for (i=0;i<torture_numops;i++) {
1425 if (!torture_open_connection(&cli[i])) {
1428 printf("opened %d connections\r", i);
1432 printf("\nStarting pings\n");
1435 for (i=0;i<torture_numops;i++) {
1438 status = smbcli_chkpath(cli[i]->tree, "\\");
1439 if (!NT_STATUS_IS_OK(status)) {
1440 printf("Connection %d is dead\n", i);
1448 if (num_dead == torture_numops) {
1449 printf("All connections dead - finishing\n");
1461 Try with a wrong vuid and check error message.
1464 static BOOL run_vuidtest(void)
1466 struct smbcli_state *cli;
1467 const char *fname = "\\vuid.tst";
1470 time_t c_time, a_time, m_time;
1471 BOOL correct = True;
1476 printf("starting vuid test\n");
1478 if (!torture_open_connection(&cli)) {
1482 smbcli_unlink(cli->tree, fname);
1484 fnum = smbcli_open(cli->tree, fname,
1485 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1487 orig_vuid = cli->session->vuid;
1489 cli->session->vuid += 1234;
1491 printf("Testing qfileinfo with wrong vuid\n");
1493 if (NT_STATUS_IS_OK(result = smbcli_qfileinfo(cli->tree, fnum, NULL,
1494 &size, &c_time, &a_time,
1495 &m_time, NULL, NULL))) {
1496 printf("ERROR: qfileinfo passed with wrong vuid\n");
1500 if ( (cli->transport->error.etype != ETYPE_DOS) ||
1501 (cli->transport->error.e.dos.eclass != ERRSRV) ||
1502 (cli->transport->error.e.dos.ecode != ERRbaduid) ) {
1503 printf("ERROR: qfileinfo should have returned DOS error "
1504 "ERRSRV:ERRbaduid\n but returned %s\n",
1505 smbcli_errstr(cli->tree));
1509 cli->session->vuid -= 1234;
1511 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum))) {
1512 printf("close failed (%s)\n", smbcli_errstr(cli->tree));
1516 smbcli_unlink(cli->tree, fname);
1518 if (!torture_close_connection(cli)) {
1522 printf("vuid test finished\n");
1528 Test open mode returns on read-only files.
1530 static BOOL run_opentest(void)
1532 static struct smbcli_state *cli1;
1533 static struct smbcli_state *cli2;
1534 const char *fname = "\\readonly.file";
1538 BOOL correct = True;
1542 printf("starting open test\n");
1544 if (!torture_open_connection(&cli1)) {
1548 smbcli_setatr(cli1->tree, fname, 0, 0);
1549 smbcli_unlink(cli1->tree, fname);
1551 fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1553 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1557 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1558 printf("close2 failed (%s)\n", smbcli_errstr(cli1->tree));
1562 if (NT_STATUS_IS_ERR(smbcli_setatr(cli1->tree, fname, FILE_ATTRIBUTE_READONLY, 0))) {
1563 printf("smbcli_setatr failed (%s)\n", smbcli_errstr(cli1->tree));
1564 CHECK_MAX_FAILURES(error_test1);
1568 fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY, DENY_WRITE);
1570 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1571 CHECK_MAX_FAILURES(error_test1);
1575 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
1576 fnum2 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_ALL);
1578 if (check_error(__location__, cli1, ERRDOS, ERRnoaccess,
1579 NT_STATUS_ACCESS_DENIED)) {
1580 printf("correct error code ERRDOS/ERRnoaccess returned\n");
1583 printf("finished open test 1\n");
1585 smbcli_close(cli1->tree, fnum1);
1587 /* Now try not readonly and ensure ERRbadshare is returned. */
1589 smbcli_setatr(cli1->tree, fname, 0, 0);
1591 fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY, DENY_WRITE);
1593 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1597 /* This will fail - but the error should be ERRshare. */
1598 fnum2 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_ALL);
1600 if (check_error(__location__, cli1, ERRDOS, ERRbadshare,
1601 NT_STATUS_SHARING_VIOLATION)) {
1602 printf("correct error code ERRDOS/ERRbadshare returned\n");
1605 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1606 printf("close2 failed (%s)\n", smbcli_errstr(cli1->tree));
1610 smbcli_unlink(cli1->tree, fname);
1612 printf("finished open test 2\n");
1614 /* Test truncate open disposition on file opened for read. */
1616 fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1618 printf("(3) open (1) of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1622 /* write 20 bytes. */
1624 memset(buf, '\0', 20);
1626 if (smbcli_write(cli1->tree, fnum1, 0, buf, 0, 20) != 20) {
1627 printf("write failed (%s)\n", smbcli_errstr(cli1->tree));
1631 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1632 printf("(3) close1 failed (%s)\n", smbcli_errstr(cli1->tree));
1636 /* Ensure size == 20. */
1637 if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
1638 printf("(3) getatr failed (%s)\n", smbcli_errstr(cli1->tree));
1639 CHECK_MAX_FAILURES(error_test3);
1644 printf("(3) file size != 20\n");
1645 CHECK_MAX_FAILURES(error_test3);
1649 /* Now test if we can truncate a file opened for readonly. */
1651 fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY|O_TRUNC, DENY_NONE);
1653 printf("(3) open (2) of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1654 CHECK_MAX_FAILURES(error_test3);
1658 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1659 printf("close2 failed (%s)\n", smbcli_errstr(cli1->tree));
1663 /* Ensure size == 0. */
1664 if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
1665 printf("(3) getatr failed (%s)\n", smbcli_errstr(cli1->tree));
1666 CHECK_MAX_FAILURES(error_test3);
1671 printf("(3) file size != 0\n");
1672 CHECK_MAX_FAILURES(error_test3);
1675 printf("finished open test 3\n");
1677 smbcli_unlink(cli1->tree, fname);
1680 printf("testing ctemp\n");
1681 fnum1 = smbcli_ctemp(cli1->tree, "\\", &tmp_path);
1683 printf("ctemp failed (%s)\n", smbcli_errstr(cli1->tree));
1684 CHECK_MAX_FAILURES(error_test4);
1687 printf("ctemp gave path %s\n", tmp_path);
1688 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1689 printf("close of temp failed (%s)\n", smbcli_errstr(cli1->tree));
1691 if (NT_STATUS_IS_ERR(smbcli_unlink(cli1->tree, tmp_path))) {
1692 printf("unlink of temp failed (%s)\n", smbcli_errstr(cli1->tree));
1695 /* Test the non-io opens... */
1697 if (!torture_open_connection(&cli2)) {
1701 smbcli_setatr(cli2->tree, fname, 0, 0);
1702 smbcli_unlink(cli2->tree, fname);
1704 printf("TEST #1 testing 2 non-io opens (no delete)\n");
1706 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1707 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1710 printf("test 1 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1711 CHECK_MAX_FAILURES(error_test10);
1715 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1716 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1718 printf("test 1 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1719 CHECK_MAX_FAILURES(error_test10);
1723 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1724 printf("test 1 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1727 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1728 printf("test 1 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1732 printf("non-io open test #1 passed.\n");
1734 smbcli_unlink(cli1->tree, fname);
1736 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
1738 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SEC_STD_DELETE|SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1739 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1742 printf("test 2 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1743 CHECK_MAX_FAILURES(error_test20);
1747 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1748 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1751 printf("test 2 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1752 CHECK_MAX_FAILURES(error_test20);
1756 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1757 printf("test 1 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1760 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1761 printf("test 1 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1765 printf("non-io open test #2 passed.\n");
1767 smbcli_unlink(cli1->tree, fname);
1769 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
1771 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1772 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1775 printf("test 3 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1776 CHECK_MAX_FAILURES(error_test30);
1780 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SEC_STD_DELETE|SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1781 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1784 printf("test 3 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1785 CHECK_MAX_FAILURES(error_test30);
1789 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1790 printf("test 3 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1793 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1794 printf("test 3 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1798 printf("non-io open test #3 passed.\n");
1800 smbcli_unlink(cli1->tree, fname);
1802 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
1804 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SEC_STD_DELETE|SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1805 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1808 printf("test 4 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1809 CHECK_MAX_FAILURES(error_test40);
1813 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SEC_STD_DELETE|SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1814 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1817 printf("test 4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1818 CHECK_MAX_FAILURES(error_test40);
1822 printf("test 4 open 2 of %s gave %s (correct error should be %s)\n", fname, smbcli_errstr(cli2->tree), "sharing violation");
1824 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1825 printf("test 4 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1829 printf("non-io open test #4 passed.\n");
1831 smbcli_unlink(cli1->tree, fname);
1833 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
1835 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SEC_STD_DELETE|SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1836 NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1839 printf("test 5 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1840 CHECK_MAX_FAILURES(error_test50);
1844 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SEC_STD_DELETE|SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1845 NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1848 printf("test 5 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1849 CHECK_MAX_FAILURES(error_test50);
1853 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1854 printf("test 5 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1858 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1859 printf("test 5 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1863 printf("non-io open test #5 passed.\n");
1865 printf("TEST #6 testing 1 non-io open, one io open\n");
1867 smbcli_unlink(cli1->tree, fname);
1869 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SEC_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
1870 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1873 printf("test 6 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1874 CHECK_MAX_FAILURES(error_test60);
1878 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1879 NTCREATEX_SHARE_ACCESS_READ, NTCREATEX_DISP_OPEN_IF, 0, 0);
1882 printf("test 6 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1883 CHECK_MAX_FAILURES(error_test60);
1887 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1888 printf("test 6 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1892 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1893 printf("test 6 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1897 printf("non-io open test #6 passed.\n");
1899 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
1901 smbcli_unlink(cli1->tree, fname);
1903 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SEC_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
1904 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1907 printf("test 7 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1908 CHECK_MAX_FAILURES(error_test70);
1912 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SEC_STD_DELETE|SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1913 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1916 printf("test 7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1917 CHECK_MAX_FAILURES(error_test70);
1921 printf("test 7 open 2 of %s gave %s (correct error should be %s)\n", fname, smbcli_errstr(cli2->tree), "sharing violation");
1923 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1924 printf("test 7 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1928 printf("non-io open test #7 passed.\n");
1932 printf("TEST #8 testing one normal open, followed by lock, followed by open with truncate\n");
1934 smbcli_unlink(cli1->tree, fname);
1936 fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
1938 printf("(8) open (1) of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1942 /* write 20 bytes. */
1944 memset(buf, '\0', 20);
1946 if (smbcli_write(cli1->tree, fnum1, 0, buf, 0, 20) != 20) {
1947 printf("(8) write failed (%s)\n", smbcli_errstr(cli1->tree));
1951 /* Ensure size == 20. */
1952 if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
1953 printf("(8) getatr (1) failed (%s)\n", smbcli_errstr(cli1->tree));
1954 CHECK_MAX_FAILURES(error_test80);
1959 printf("(8) file size != 20\n");
1960 CHECK_MAX_FAILURES(error_test80);
1964 /* Get an exclusive lock on the open file. */
1965 if (NT_STATUS_IS_ERR(smbcli_lock(cli1->tree, fnum1, 0, 4, 0, WRITE_LOCK))) {
1966 printf("(8) lock1 failed (%s)\n", smbcli_errstr(cli1->tree));
1967 CHECK_MAX_FAILURES(error_test80);
1971 fnum2 = smbcli_open(cli1->tree, fname, O_RDWR|O_TRUNC, DENY_NONE);
1973 printf("(8) open (2) of %s with truncate failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1977 /* Ensure size == 0. */
1978 if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
1979 printf("(8) getatr (2) failed (%s)\n", smbcli_errstr(cli1->tree));
1980 CHECK_MAX_FAILURES(error_test80);
1985 printf("(8) file size != 0\n");
1986 CHECK_MAX_FAILURES(error_test80);
1990 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1991 printf("(8) close1 failed (%s)\n", smbcli_errstr(cli1->tree));
1995 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum2))) {
1996 printf("(8) close1 failed (%s)\n", smbcli_errstr(cli1->tree));
2002 printf("open test #8 passed.\n");
2004 smbcli_unlink(cli1->tree, fname);
2006 if (!torture_close_connection(cli1)) {
2009 if (!torture_close_connection(cli2)) {
2018 sees what IOCTLs are supported
2020 BOOL torture_ioctl_test(void)
2022 struct smbcli_state *cli;
2023 uint16_t device, function;
2025 const char *fname = "\\ioctl.dat";
2027 union smb_ioctl parms;
2028 TALLOC_CTX *mem_ctx;
2030 if (!torture_open_connection(&cli)) {
2034 mem_ctx = talloc_init("ioctl_test");
2036 printf("starting ioctl test\n");
2038 smbcli_unlink(cli->tree, fname);
2040 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2042 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
2046 parms.ioctl.level = RAW_IOCTL_IOCTL;
2047 parms.ioctl.in.fnum = fnum;
2048 parms.ioctl.in.request = IOCTL_QUERY_JOB_INFO;
2049 status = smb_raw_ioctl(cli->tree, mem_ctx, &parms);
2050 printf("ioctl job info: %s\n", smbcli_errstr(cli->tree));
2052 for (device=0;device<0x100;device++) {
2053 printf("testing device=0x%x\n", device);
2054 for (function=0;function<0x100;function++) {
2055 parms.ioctl.in.request = (device << 16) | function;
2056 status = smb_raw_ioctl(cli->tree, mem_ctx, &parms);
2058 if (NT_STATUS_IS_OK(status)) {
2059 printf("ioctl device=0x%x function=0x%x OK : %d bytes\n",
2060 device, function, parms.ioctl.out.blob.length);
2065 if (!torture_close_connection(cli)) {
2074 tries variants of chkpath
2076 BOOL torture_chkpath_test(void)
2078 struct smbcli_state *cli;
2082 if (!torture_open_connection(&cli)) {
2086 printf("starting chkpath test\n");
2088 printf("Testing valid and invalid paths\n");
2090 /* cleanup from an old run */
2091 smbcli_rmdir(cli->tree, "\\chkpath.dir\\dir2");
2092 smbcli_unlink(cli->tree, "\\chkpath.dir\\*");
2093 smbcli_rmdir(cli->tree, "\\chkpath.dir");
2095 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, "\\chkpath.dir"))) {
2096 printf("mkdir1 failed : %s\n", smbcli_errstr(cli->tree));
2100 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, "\\chkpath.dir\\dir2"))) {
2101 printf("mkdir2 failed : %s\n", smbcli_errstr(cli->tree));
2105 fnum = smbcli_open(cli->tree, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2107 printf("open1 failed (%s)\n", smbcli_errstr(cli->tree));
2110 smbcli_close(cli->tree, fnum);
2112 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir"))) {
2113 printf("chkpath1 failed: %s\n", smbcli_errstr(cli->tree));
2117 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\dir2"))) {
2118 printf("chkpath2 failed: %s\n", smbcli_errstr(cli->tree));
2122 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\foo.txt"))) {
2123 ret = check_error(__location__, cli, ERRDOS, ERRbadpath,
2124 NT_STATUS_NOT_A_DIRECTORY);
2126 printf("* chkpath on a file should fail\n");
2130 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\bar.txt"))) {
2131 ret = check_error(__location__, cli, ERRDOS, ERRbadfile,
2132 NT_STATUS_OBJECT_NAME_NOT_FOUND);
2134 printf("* chkpath on a non existent file should fail\n");
2138 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\dirxx\\bar.txt"))) {
2139 ret = check_error(__location__, cli, ERRDOS, ERRbadpath,
2140 NT_STATUS_OBJECT_PATH_NOT_FOUND);
2142 printf("* chkpath on a non existent component should fail\n");
2146 smbcli_rmdir(cli->tree, "\\chkpath.dir\\dir2");
2147 smbcli_unlink(cli->tree, "\\chkpath.dir\\*");
2148 smbcli_rmdir(cli->tree, "\\chkpath.dir");
2150 if (!torture_close_connection(cli)) {
2159 parse a //server/share type UNC name
2161 static BOOL parse_unc(const char *unc_name, char **hostname, char **sharename)
2165 if (strncmp(unc_name, "//", 2)) {
2169 *hostname = strdup(&unc_name[2]);
2170 p = strchr_m(&(*hostname)[2],'/');
2175 *sharename = strdup(p+1);
2182 static void sigcont(int sig)
2186 double torture_create_procs(BOOL (*fn)(struct smbcli_state *, int), BOOL *result)
2189 volatile pid_t *child_status;
2190 volatile BOOL *child_status_out;
2193 double start_time_limit = 10 + (torture_nprocs * 1.5);
2194 char **unc_list = NULL;
2196 int num_unc_names = 0;
2203 signal(SIGCONT, sigcont);
2205 child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*torture_nprocs);
2206 if (!child_status) {
2207 printf("Failed to setup shared memory\n");
2211 child_status_out = (volatile BOOL *)shm_setup(sizeof(BOOL)*torture_nprocs);
2212 if (!child_status_out) {
2213 printf("Failed to setup result status shared memory\n");
2217 p = lp_parm_string(-1, "torture", "unclist");
2219 unc_list = file_lines_load(p, &num_unc_names);
2220 if (!unc_list || num_unc_names <= 0) {
2221 printf("Failed to load unc names list from '%s'\n", p);
2226 for (i = 0; i < torture_nprocs; i++) {
2227 child_status[i] = 0;
2228 child_status_out[i] = True;
2231 tv = timeval_current();
2233 for (i=0;i<torture_nprocs;i++) {
2237 char *hostname=NULL, *sharename;
2239 pid_t mypid = getpid();
2240 sys_srandom(((int)mypid) ^ ((int)time(NULL)));
2242 asprintf(&myname, "CLIENT%d", i);
2243 lp_set_cmdline("netbios name", myname);
2248 if (!parse_unc(unc_list[i % num_unc_names],
2249 &hostname, &sharename)) {
2250 printf("Failed to parse UNC name %s\n",
2251 unc_list[i % num_unc_names]);
2258 if (torture_open_connection_share(¤t_cli,
2263 } else if (torture_open_connection(¤t_cli)) {
2267 printf("pid %d failed to start\n", (int)getpid());
2273 child_status[i] = getpid();
2277 if (child_status[i]) {
2278 printf("Child %d failed to start!\n", i);
2279 child_status_out[i] = 1;
2283 child_status_out[i] = fn(current_cli, i);
2290 for (i=0;i<torture_nprocs;i++) {
2291 if (child_status[i]) synccount++;
2293 if (synccount == torture_nprocs) break;
2295 } while (timeval_elapsed(&tv) < start_time_limit);
2297 if (synccount != torture_nprocs) {
2298 printf("FAILED TO START %d CLIENTS (started %d)\n", torture_nprocs, synccount);
2300 return timeval_elapsed(&tv);
2303 printf("Starting %d clients\n", torture_nprocs);
2305 /* start the client load */
2306 tv = timeval_current();
2307 for (i=0;i<torture_nprocs;i++) {
2308 child_status[i] = 0;
2311 printf("%d clients started\n", torture_nprocs);
2315 for (i=0;i<torture_nprocs;i++) {
2317 while ((ret=sys_waitpid(0, &status, 0)) == -1 && errno == EINTR) /* noop */ ;
2318 if (ret == -1 || WEXITSTATUS(status) != 0) {
2325 for (i=0;i<torture_nprocs;i++) {
2326 if (!child_status_out[i]) {
2330 return timeval_elapsed(&tv);
2333 #define FLAG_MULTIPROC 1
2338 BOOL (*multi_fn)(struct smbcli_state *, int );
2341 {"BASE-FDPASS", run_fdpasstest, 0},
2342 {"BASE-LOCK1", torture_locktest1, 0},
2343 {"BASE-LOCK2", torture_locktest2, 0},
2344 {"BASE-LOCK3", torture_locktest3, 0},
2345 {"BASE-LOCK4", torture_locktest4, 0},
2346 {"BASE-LOCK5", torture_locktest5, 0},
2347 {"BASE-LOCK6", torture_locktest6, 0},
2348 {"BASE-LOCK7", torture_locktest7, 0},
2349 {"BASE-UNLINK", torture_unlinktest, 0},
2350 {"BASE-ATTR", run_attrtest, 0},
2351 {"BASE-TRANS2", run_trans2test, 0},
2352 {"BASE-NEGNOWAIT", run_negprot_nowait, 0},
2353 {"BASE-DIR1", torture_dirtest1, 0},
2354 {"BASE-DIR2", torture_dirtest2, 0},
2355 {"BASE-DENY1", torture_denytest1, 0},
2356 {"BASE-DENY2", torture_denytest2, 0},
2357 {"BASE-DENY3", torture_denytest3, 0},
2358 {"BASE-DENYDOS", torture_denydos_sharing, 0},
2359 {"BASE-NTDENY1", NULL, torture_ntdenytest1},
2360 {"BASE-NTDENY2", torture_ntdenytest2, 0},
2361 {"BASE-TCON", run_tcon_test, 0},
2362 {"BASE-TCONDEV", run_tcon_devtype_test, 0},
2363 {"BASE-VUID", run_vuidtest, 0},
2364 {"BASE-RW1", run_readwritetest, 0},
2365 {"BASE-RW2", NULL, run_readwritemulti},
2366 {"BASE-OPEN", run_opentest, 0},
2367 {"BASE-DEFER_OPEN", NULL, run_deferopen},
2368 {"BASE-XCOPY", run_xcopy, 0},
2369 {"BASE-RENAME", torture_test_rename, 0},
2370 {"BASE-DELETE", torture_test_delete, 0},
2371 {"BASE-PROPERTIES", torture_test_properties, 0},
2372 {"BASE-MANGLE", torture_mangle, 0},
2373 {"BASE-OPENATTR", torture_openattrtest, 0},
2374 {"BASE-CHARSET", torture_charset, 0},
2375 {"BASE-CHKPATH", torture_chkpath_test, 0},
2376 {"BASE-SECLEAK", torture_sec_leak, 0},
2377 {"BASE-DISCONNECT", torture_disconnect, 0},
2378 {"BASE-DELAYWRITE", torture_delay_write, 0},
2380 /* benchmarking tests */
2381 {"BENCH-HOLDCON", torture_holdcon, 0},
2382 {"BENCH-NBENCH", torture_nbench, 0},
2383 {"BENCH-TORTURE", NULL, run_torture},
2386 {"RAW-QFSINFO", torture_raw_qfsinfo, 0},
2387 {"RAW-QFILEINFO", torture_raw_qfileinfo, 0},
2388 {"RAW-SFILEINFO", torture_raw_sfileinfo, 0},
2389 {"RAW-SFILEINFO-BUG", torture_raw_sfileinfo_bug, 0},
2390 {"RAW-SEARCH", torture_raw_search, 0},
2391 {"RAW-CLOSE", torture_raw_close, 0},
2392 {"RAW-OPEN", torture_raw_open, 0},
2393 {"RAW-MKDIR", torture_raw_mkdir, 0},
2394 {"RAW-OPLOCK", torture_raw_oplock, 0},
2395 {"RAW-NOTIFY", torture_raw_notify, 0},
2396 {"RAW-MUX", torture_raw_mux, 0},
2397 {"RAW-IOCTL", torture_raw_ioctl, 0},
2398 {"RAW-CHKPATH", torture_raw_chkpath, 0},
2399 {"RAW-UNLINK", torture_raw_unlink, 0},
2400 {"RAW-READ", torture_raw_read, 0},
2401 {"RAW-WRITE", torture_raw_write, 0},
2402 {"RAW-LOCK", torture_raw_lock, 0},
2403 {"RAW-CONTEXT", torture_raw_context, 0},
2404 {"RAW-RENAME", torture_raw_rename, 0},
2405 {"RAW-SEEK", torture_raw_seek, 0},
2406 {"RAW-EAS", torture_raw_eas, 0},
2407 {"RAW-STREAMS", torture_raw_streams, 0},
2408 {"RAW-ACLS", torture_raw_acls, 0},
2409 {"RAW-RAP", torture_raw_rap, 0},
2410 {"RAW-COMPOSITE", torture_raw_composite, 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},
2451 {"RPC-ALTERCONTEXT", torture_rpc_alter_context, 0},
2453 /* Distributed COM testers */
2454 {"DCOM-SIMPLE", torture_dcom_simple, 0},
2456 /* local (no server) testers */
2457 {"LOCAL-NTLMSSP", torture_ntlmssp_self_check, 0},
2458 {"LOCAL-ICONV", torture_local_iconv, 0},
2459 {"LOCAL-TALLOC", torture_local_talloc, 0},
2460 {"LOCAL-MESSAGING", torture_local_messaging, 0},
2461 {"LOCAL-BINDING", torture_local_binding_string, 0},
2462 {"LOCAL-IDTREE", torture_local_idtree, 0},
2465 {"LDAP-BASIC", torture_ldap_basic, 0},
2471 /****************************************************************************
2472 run a specified test or "ALL"
2473 ****************************************************************************/
2474 static BOOL run_test(const char *name)
2478 BOOL matched = False;
2480 if (strequal(name,"ALL")) {
2481 for (i=0;torture_ops[i].name;i++) {
2482 if (!run_test(torture_ops[i].name)) {
2489 for (i=0;torture_ops[i].name;i++) {
2490 if (gen_fnmatch(name, torture_ops[i].name) == 0) {
2494 printf("Running %s\n", torture_ops[i].name);
2495 if (torture_ops[i].multi_fn) {
2496 BOOL result = False;
2497 t = torture_create_procs(torture_ops[i].multi_fn,
2501 printf("TEST %s FAILED!\n", torture_ops[i].name);
2505 struct timeval tv = timeval_current();
2506 if (!torture_ops[i].fn()) {
2508 printf("TEST %s FAILED!\n", torture_ops[i].name);
2510 t = timeval_elapsed(&tv);
2512 printf("%s took %g secs\n\n", torture_ops[i].name, t);
2517 printf("Unknown torture operation '%s'\n", name);
2524 static void parse_dns(const char *dns)
2526 char *userdn, *basedn, *secret;
2529 /* retrievieng the userdn */
2530 p = strchr_m(dns, '#');
2532 lp_set_cmdline("torture:ldap_userdn", "");
2533 lp_set_cmdline("torture:ldap_basedn", "");
2534 lp_set_cmdline("torture:ldap_secret", "");
2537 userdn = strndup(dns, p - dns);
2538 lp_set_cmdline("torture:ldap_userdn", userdn);
2540 /* retrieve the basedn */
2542 p = strchr_m(d, '#');
2544 lp_set_cmdline("torture:ldap_basedn", "");
2545 lp_set_cmdline("torture:ldap_secret", "");
2548 basedn = strndup(d, p - d);
2549 lp_set_cmdline("torture:ldap_basedn", basedn);
2551 /* retrieve the secret */
2554 lp_set_cmdline("torture:ldap_secret", "");
2558 lp_set_cmdline("torture:ldap_secret", secret);
2560 printf ("%s - %s - %s\n", userdn, basedn, secret);
2564 static void usage(poptContext pc)
2569 poptPrintUsage(pc, stdout, 0);
2572 printf("The binding format is:\n\n");
2574 printf(" TRANSPORT:host[flags]\n\n");
2576 printf(" where TRANSPORT is either ncacn_np for SMB or ncacn_ip_tcp for RPC/TCP\n\n");
2578 printf(" 'host' is an IP or hostname or netbios name. If the binding string\n");
2579 printf(" identifies the server side of an endpoint, 'host' may be an empty\n");
2580 printf(" string.\n\n");
2582 printf(" 'flags' can include a SMB pipe name if using the ncacn_np transport or\n");
2583 printf(" a TCP port number if using the ncacn_ip_tcp transport, otherwise they\n");
2584 printf(" will be auto-determined.\n\n");
2586 printf(" other recognised flags are:\n\n");
2588 printf(" sign : enable ntlmssp signing\n");
2589 printf(" seal : enable ntlmssp sealing\n");
2590 printf(" connect : enable rpc connect level auth (auth, but no sign or seal)\n");
2591 printf(" validate: enable the NDR validator\n");
2592 printf(" print: enable debugging of the packets\n");
2593 printf(" bigendian: use bigendian RPC\n");
2594 printf(" padcheck: check reply data for non-zero pad bytes\n\n");
2596 printf(" For example, these all connect to the samr pipe:\n\n");
2598 printf(" ncacn_np:myserver\n");
2599 printf(" ncacn_np:myserver[samr]\n");
2600 printf(" ncacn_np:myserver[\\pipe\\samr]\n");
2601 printf(" ncacn_np:myserver[/pipe/samr]\n");
2602 printf(" ncacn_np:myserver[samr,sign,print]\n");
2603 printf(" ncacn_np:myserver[\\pipe\\samr,sign,seal,bigendian]\n");
2604 printf(" ncacn_np:myserver[/pipe/samr,seal,validate]\n");
2605 printf(" ncacn_np:\n");
2606 printf(" ncacn_np:[/pipe/samr]\n\n");
2608 printf(" ncacn_ip_tcp:myserver\n");
2609 printf(" ncacn_ip_tcp:myserver[1024]\n");
2610 printf(" ncacn_ip_tcp:myserver[1024,sign,seal]\n\n");
2612 printf("The unc format is:\n\n");
2614 printf(" //server/share\n\n");
2616 printf("tests are:");
2617 for (i=0;torture_ops[i].name;i++) {
2618 if ((i%perline)==0) {
2621 printf("%s ", torture_ops[i].name);
2625 printf("default test is ALL\n");
2630 static BOOL is_binding_string(const char *binding_string)
2632 TALLOC_CTX *mem_ctx = talloc_init("is_binding_string");
2633 struct dcerpc_binding binding_struct;
2636 status = dcerpc_parse_binding(mem_ctx, binding_string, &binding_struct);
2638 talloc_destroy(mem_ctx);
2639 return NT_STATUS_IS_OK(status);
2642 /****************************************************************************
2644 ****************************************************************************/
2645 int main(int argc,char *argv[])
2649 BOOL correct = True;
2653 enum {OPT_LOADFILE=1000,OPT_UNCLIST,OPT_TIMELIMIT,OPT_DNS,OPT_DANGEROUS};
2654 struct poptOption long_options[] = {
2656 {"smb-ports", 'p', POPT_ARG_STRING, NULL, 0, "SMB ports", NULL},
2657 {"seed", 0, POPT_ARG_INT, &torture_seed, 0, "seed", NULL},
2658 {"num-progs", 0, POPT_ARG_INT, &torture_nprocs, 0, "num progs", NULL},
2659 {"num-ops", 0, POPT_ARG_INT, &torture_numops, 0, "num ops", NULL},
2660 {"entries", 0, POPT_ARG_INT, &torture_entries, 0, "entries", NULL},
2661 {"use-oplocks", 'L', POPT_ARG_NONE, &use_oplocks, 0, "use oplocks", NULL},
2662 {"show-all", 0, POPT_ARG_NONE, &torture_showall, 0, "show all", NULL},
2663 {"loadfile", 0, POPT_ARG_STRING, NULL, OPT_LOADFILE, "loadfile", NULL},
2664 {"unclist", 0, POPT_ARG_STRING, NULL, OPT_UNCLIST, "unclist", NULL},
2665 {"timelimit", 't', POPT_ARG_STRING, NULL, OPT_TIMELIMIT, "timelimit", NULL},
2666 {"failures", 'f', POPT_ARG_INT, &torture_failures, 0, "failures", NULL},
2667 {"parse-dns", 'D', POPT_ARG_STRING, NULL, OPT_DNS, "parse-dns", NULL},
2668 {"dangerous", 'X', POPT_ARG_NONE, NULL, OPT_DANGEROUS, "dangerous", NULL},
2670 POPT_COMMON_CONNECTION
2671 POPT_COMMON_CREDENTIALS
2676 setup_logging("smbtorture", DEBUG_STDOUT);
2678 #ifdef HAVE_SETBUFFER
2679 setbuffer(stdout, NULL, 0);
2682 pc = poptGetContext("smbtorture", argc, (const char **) argv, long_options,
2683 POPT_CONTEXT_KEEP_FIRST);
2685 poptSetOtherOptionHelp(pc, "<binding>|<unc> TEST1 TEST2 ...");
2687 while((opt = poptGetNextOpt(pc)) != -1) {
2690 lp_set_cmdline("torture:loadfile", poptGetOptArg(pc));
2693 lp_set_cmdline("torture:unclist", poptGetOptArg(pc));
2696 lp_set_cmdline("torture:timelimit", poptGetOptArg(pc));
2699 parse_dns(poptGetOptArg(pc));
2702 lp_set_cmdline("torture:dangerous", "Yes");
2705 d_printf("Invalid option %s: %s\n",
2706 poptBadOption(pc, 0), poptStrerror(opt));
2712 lp_load(dyn_CONFIGFILE,True,False,False);
2715 smbtorture_init_subsystems;
2718 if (torture_seed == 0) {
2719 torture_seed = time(NULL);
2721 printf("Using seed %d\n", torture_seed);
2722 srandom(torture_seed);
2724 argv_new = discard_const_p(char *, poptGetArgs(pc));
2727 for (i=0; i<argc; i++) {
2728 if (argv_new[i] == NULL) {
2739 for(p = argv_new[1]; *p; p++) {
2744 /* see if its a RPC transport specifier */
2745 if (is_binding_string(argv_new[1])) {
2746 lp_set_cmdline("torture:binding", argv_new[1]);
2748 char *binding = NULL;
2749 char *host = NULL, *share = NULL;
2751 if (!parse_unc(argv_new[1], &host, &share)) {
2752 d_printf("Invalid option: %s is not a valid torture target (share or binding string)\n\n", argv_new[1]);
2756 lp_set_cmdline("torture:host", host);
2757 lp_set_cmdline("torture:share", share);
2758 asprintf(&binding, "ncacn_np:%s", host);
2759 lp_set_cmdline("torture:binding", binding);
2762 if (!lp_parm_string(-1,"torture","username")) {
2763 lp_set_cmdline("torture:username", cmdline_get_username());
2765 if (!lp_parm_string(-1,"torture","userdomain")) {
2767 * backward compatibility
2768 * maybe we should remove this to make this consistent
2769 * for all cmdline tools
2772 if (strequal(lp_netbios_name(),cmdline_get_userdomain())) {
2773 cmdline_set_userdomain(lp_workgroup());
2775 lp_set_cmdline("torture:userdomain", cmdline_get_userdomain());
2777 if (!lp_parm_string(-1,"torture","password")) {
2778 lp_set_cmdline("torture:password", cmdline_get_userpassword());
2781 if (argc_new == 0) {
2782 printf("You must specify a test to run, or 'ALL'\n");
2784 for (i=2;i<argc_new;i++) {
2785 if (!run_test(argv_new[i])) {