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"
31 int torture_numops=100;
32 int torture_entries=1000;
33 int torture_failures=1;
35 static int procnum; /* records process count number when forking */
36 static struct smbcli_state *current_cli;
37 static BOOL use_oplocks;
38 static BOOL use_level_II_oplocks;
39 static BOOL use_kerberos;
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");
102 flags |= SMBCLI_FULL_CONNECTION_USE_KERBEROS;
104 status = smbcli_full_connection(NULL,
105 c, lp_netbios_name(),
108 username, username[0]?userdomain:"",
109 password, flags, &retry);
110 if (!NT_STATUS_IS_OK(status)) {
111 printf("Failed to open connection - %s\n", nt_errstr(status));
115 (*c)->transport->options.use_oplocks = use_oplocks;
116 (*c)->transport->options.use_level2_oplocks = use_level_II_oplocks;
117 (*c)->transport->socket->timeout = 120000;
122 BOOL torture_open_connection(struct smbcli_state **c)
124 const char *host = lp_parm_string(-1, "torture", "host");
125 const char *share = lp_parm_string(-1, "torture", "share");
127 return torture_open_connection_share(c, host, share);
132 BOOL torture_close_connection(struct smbcli_state *c)
136 if (NT_STATUS_IS_ERR(smbcli_tdis(c))) {
137 printf("tdis failed (%s)\n", smbcli_errstr(c->tree));
144 /* initialise a DCOM context */
145 NTSTATUS torture_dcom_init(struct dcom_context **ctx)
147 dcom_init(ctx, lp_parm_string(-1, "torture", "userdomain"),
148 lp_parm_string(-1, "torture", "username"),
149 lp_parm_string(-1, "torture", "password"));
154 /* open a rpc connection to the chosen binding string */
155 NTSTATUS torture_rpc_connection(struct dcerpc_pipe **p,
156 const char *pipe_name,
157 const char *pipe_uuid,
158 uint32_t pipe_version)
161 const char *binding = lp_parm_string(-1, "torture", "binding");
164 printf("You must specify a ncacn binding string\n");
165 return NT_STATUS_INVALID_PARAMETER;
168 status = dcerpc_pipe_connect(p, binding, pipe_uuid, pipe_version,
169 lp_parm_string(-1, "torture", "userdomain"),
170 lp_parm_string(-1, "torture", "username"),
171 lp_parm_string(-1, "torture", "password"));
176 /* open a rpc connection to a specific transport */
177 NTSTATUS torture_rpc_connection_transport(struct dcerpc_pipe **p,
178 const char *pipe_name,
179 const char *pipe_uuid,
180 uint32_t pipe_version,
181 enum dcerpc_transport_t transport)
184 const char *binding = lp_parm_string(-1, "torture", "binding");
185 struct dcerpc_binding b;
186 TALLOC_CTX *mem_ctx = talloc_init("torture_rpc_connection_smb");
189 printf("You must specify a ncacn binding string\n");
190 return NT_STATUS_INVALID_PARAMETER;
193 status = dcerpc_parse_binding(mem_ctx, binding, &b);
194 if (!NT_STATUS_IS_OK(status)) {
195 DEBUG(0,("Failed to parse dcerpc binding '%s'\n", binding));
196 talloc_destroy(mem_ctx);
200 b.transport = transport;
202 status = dcerpc_pipe_connect_b(p, &b, pipe_uuid, pipe_version,
203 lp_parm_string(-1, "torture", "userdomain"),
204 lp_parm_string(-1, "torture", "username"),
205 lp_parm_string(-1, "torture", "password"));
210 /* close a rpc connection to a named pipe */
211 NTSTATUS torture_rpc_close(struct dcerpc_pipe *p)
213 dcerpc_pipe_close(p);
218 /* check if the server produced the expected error code */
219 BOOL check_error(const char *location, struct smbcli_state *c,
220 uint8_t eclass, uint32_t ecode, NTSTATUS nterr)
222 if (smbcli_is_dos_error(c->tree)) {
226 /* Check DOS error */
228 smbcli_dos_error(c, &class, &num);
230 if (eclass != class || ecode != num) {
231 printf("unexpected error code class=%d code=%d\n",
232 (int)class, (int)num);
233 printf(" expected %d/%d %s (at %s)\n",
234 (int)eclass, (int)ecode, nt_errstr(nterr), location);
243 status = smbcli_nt_error(c->tree);
245 if (NT_STATUS_V(nterr) != NT_STATUS_V(status)) {
246 printf("unexpected error code %s\n", nt_errstr(status));
247 printf(" expected %s (at %s)\n", nt_errstr(nterr), location);
256 static BOOL wait_lock(struct smbcli_state *c, int fnum, uint32_t offset, uint32_t len)
258 while (NT_STATUS_IS_ERR(smbcli_lock(c->tree, fnum, offset, len, -1, WRITE_LOCK))) {
259 if (!check_error(__location__, c, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
265 static BOOL rw_torture(struct smbcli_state *c)
267 const char *lockfname = "\\torture.lck";
271 pid_t pid2, pid = getpid();
276 fnum2 = smbcli_open(c->tree, lockfname, O_RDWR | O_CREAT | O_EXCL,
279 fnum2 = smbcli_open(c->tree, lockfname, O_RDWR, DENY_NONE);
281 printf("open of %s failed (%s)\n", lockfname, smbcli_errstr(c->tree));
286 for (i=0;i<torture_numops;i++) {
287 uint_t n = (uint_t)sys_random()%10;
289 printf("%d\r", i); fflush(stdout);
291 asprintf(&fname, "\\torture.%u", n);
293 if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) {
297 fnum = smbcli_open(c->tree, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL);
299 printf("open failed (%s)\n", smbcli_errstr(c->tree));
304 if (smbcli_write(c->tree, fnum, 0, (char *)&pid, 0, sizeof(pid)) != sizeof(pid)) {
305 printf("write failed (%s)\n", smbcli_errstr(c->tree));
310 if (smbcli_write(c->tree, fnum, 0, (char *)buf,
311 sizeof(pid)+(j*sizeof(buf)),
312 sizeof(buf)) != sizeof(buf)) {
313 printf("write failed (%s)\n", smbcli_errstr(c->tree));
320 if (smbcli_read(c->tree, fnum, (char *)&pid2, 0, sizeof(pid)) != sizeof(pid)) {
321 printf("read failed (%s)\n", smbcli_errstr(c->tree));
326 printf("data corruption!\n");
330 if (NT_STATUS_IS_ERR(smbcli_close(c->tree, fnum))) {
331 printf("close failed (%s)\n", smbcli_errstr(c->tree));
335 if (NT_STATUS_IS_ERR(smbcli_unlink(c->tree, fname))) {
336 printf("unlink failed (%s)\n", smbcli_errstr(c->tree));
340 if (NT_STATUS_IS_ERR(smbcli_unlock(c->tree, fnum2, n*sizeof(int), sizeof(int)))) {
341 printf("unlock failed (%s)\n", smbcli_errstr(c->tree));
347 smbcli_close(c->tree, fnum2);
348 smbcli_unlink(c->tree, lockfname);
355 static BOOL run_torture(struct smbcli_state *cli, int dummy)
359 ret = rw_torture(cli);
361 if (!torture_close_connection(cli)) {
368 static BOOL rw_torture3(struct smbcli_state *c, const char *lockfname)
375 uint_t countprev = 0;
379 for (i = 0; i < sizeof(buf); i += sizeof(uint32_t))
381 SIVAL(buf, i, sys_random());
386 fnum = smbcli_open(c->tree, lockfname, O_RDWR | O_CREAT | O_EXCL,
389 printf("first open read/write of %s failed (%s)\n",
390 lockfname, smbcli_errstr(c->tree));
396 for (i = 0; i < 500 && fnum == -1; i++)
398 fnum = smbcli_open(c->tree, lockfname, O_RDONLY,
403 printf("second open read-only of %s failed (%s)\n",
404 lockfname, smbcli_errstr(c->tree));
410 for (count = 0; count < sizeof(buf); count += sent)
412 if (count >= countprev) {
413 printf("%d %8d\r", i, count);
416 countprev += (sizeof(buf) / 20);
421 sent = ((uint_t)sys_random()%(20))+ 1;
422 if (sent > sizeof(buf) - count)
424 sent = sizeof(buf) - count;
427 if (smbcli_write(c->tree, fnum, 0, buf+count, count, (size_t)sent) != sent) {
428 printf("write failed (%s)\n", smbcli_errstr(c->tree));
434 sent = smbcli_read(c->tree, fnum, buf_rd+count, count,
438 printf("read failed offset:%d size:%d (%s)\n",
439 count, sizeof(buf)-count,
440 smbcli_errstr(c->tree));
446 if (memcmp(buf_rd+count, buf+count, sent) != 0)
448 printf("read/write compare failed\n");
449 printf("offset: %d req %d recvd %d\n",
450 count, sizeof(buf)-count, sent);
459 if (NT_STATUS_IS_ERR(smbcli_close(c->tree, fnum))) {
460 printf("close failed (%s)\n", smbcli_errstr(c->tree));
467 static BOOL rw_torture2(struct smbcli_state *c1, struct smbcli_state *c2)
469 const char *lockfname = "\\torture2.lck";
474 uint8_t buf_rd[131072];
476 ssize_t bytes_read, bytes_written;
478 if (smbcli_deltree(c1->tree, lockfname) == -1) {
479 printf("unlink failed (%s)\n", smbcli_errstr(c1->tree));
482 fnum1 = smbcli_open(c1->tree, lockfname, O_RDWR | O_CREAT | O_EXCL,
485 printf("first open read/write of %s failed (%s)\n",
486 lockfname, smbcli_errstr(c1->tree));
489 fnum2 = smbcli_open(c2->tree, lockfname, O_RDONLY,
492 printf("second open read-only of %s failed (%s)\n",
493 lockfname, smbcli_errstr(c2->tree));
494 smbcli_close(c1->tree, fnum1);
498 printf("Checking data integrity over %d ops\n", torture_numops);
500 for (i=0;i<torture_numops;i++)
502 size_t buf_size = ((uint_t)sys_random()%(sizeof(buf)-1))+ 1;
504 printf("%d\r", i); fflush(stdout);
507 generate_random_buffer(buf, buf_size);
509 if ((bytes_written = smbcli_write(c1->tree, fnum1, 0, buf, 0, buf_size)) != buf_size) {
510 printf("write failed (%s)\n", smbcli_errstr(c1->tree));
511 printf("wrote %d, expected %d\n", bytes_written, buf_size);
516 if ((bytes_read = smbcli_read(c2->tree, fnum2, buf_rd, 0, buf_size)) != buf_size) {
517 printf("read failed (%s)\n", smbcli_errstr(c2->tree));
518 printf("read %d, expected %d\n", bytes_read, buf_size);
523 if (memcmp(buf_rd, buf, buf_size) != 0)
525 printf("read/write compare failed\n");
531 if (NT_STATUS_IS_ERR(smbcli_close(c2->tree, fnum2))) {
532 printf("close failed (%s)\n", smbcli_errstr(c2->tree));
535 if (NT_STATUS_IS_ERR(smbcli_close(c1->tree, fnum1))) {
536 printf("close failed (%s)\n", smbcli_errstr(c1->tree));
540 if (NT_STATUS_IS_ERR(smbcli_unlink(c1->tree, lockfname))) {
541 printf("unlink failed (%s)\n", smbcli_errstr(c1->tree));
548 static BOOL run_readwritetest(void)
550 struct smbcli_state *cli1, *cli2;
551 BOOL test1, test2 = True;
553 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
557 printf("starting readwritetest\n");
559 test1 = rw_torture2(cli1, cli2);
560 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1));
563 test2 = rw_torture2(cli1, cli1);
564 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2));
567 if (!torture_close_connection(cli1)) {
571 if (!torture_close_connection(cli2)) {
575 return (test1 && test2);
578 static BOOL run_readwritemulti(struct smbcli_state *cli, int dummy)
582 test = rw_torture3(cli, "\\multitest.txt");
584 if (!torture_close_connection(cli)) {
593 this checks to see if a secondary tconx can use open files from an
596 static BOOL run_tcon_test(void)
598 struct smbcli_state *cli;
599 const char *fname = "\\tcontest.tmp";
601 uint16_t cnum1, cnum2, cnum3;
602 uint16_t vuid1, vuid2;
605 struct smbcli_tree *tree1;
606 const char *host = lp_parm_string(-1, "torture", "host");
607 const char *share = lp_parm_string(-1, "torture", "share");
608 const char *password = lp_parm_string(-1, "torture", "password");
610 if (!torture_open_connection(&cli)) {
614 printf("starting tcontest\n");
616 if (smbcli_deltree(cli->tree, fname) == -1) {
617 printf("unlink of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
620 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
622 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
626 cnum1 = cli->tree->tid;
627 vuid1 = cli->session->vuid;
629 memset(&buf, 0, 4); /* init buf so valgrind won't complain */
630 if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) != 4) {
631 printf("initial write failed (%s)\n", smbcli_errstr(cli->tree));
635 tree1 = cli->tree; /* save old tree connection */
636 if (NT_STATUS_IS_ERR(smbcli_send_tconX(cli, share, "?????", password))) {
637 printf("%s refused 2nd tree connect (%s)\n", host,
638 smbcli_errstr(cli->tree));
639 smbcli_shutdown(cli);
643 cnum2 = cli->tree->tid;
644 cnum3 = MAX(cnum1, cnum2) + 1; /* any invalid number */
645 vuid2 = cli->session->vuid + 1;
647 /* try a write with the wrong tid */
648 cli->tree->tid = cnum2;
650 if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) == 4) {
651 printf("* server allows write with wrong TID\n");
654 printf("server fails write with wrong TID : %s\n", smbcli_errstr(cli->tree));
658 /* try a write with an invalid tid */
659 cli->tree->tid = cnum3;
661 if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) == 4) {
662 printf("* server allows write with invalid TID\n");
665 printf("server fails write with invalid TID : %s\n", smbcli_errstr(cli->tree));
668 /* try a write with an invalid vuid */
669 cli->session->vuid = vuid2;
670 cli->tree->tid = cnum1;
672 if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) == 4) {
673 printf("* server allows write with invalid VUID\n");
676 printf("server fails write with invalid VUID : %s\n", smbcli_errstr(cli->tree));
679 cli->session->vuid = vuid1;
680 cli->tree->tid = cnum1;
682 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum1))) {
683 printf("close failed (%s)\n", smbcli_errstr(cli->tree));
687 cli->tree->tid = cnum2;
689 if (NT_STATUS_IS_ERR(smbcli_tdis(cli))) {
690 printf("secondary tdis failed (%s)\n", smbcli_errstr(cli->tree));
694 cli->tree = tree1; /* restore initial tree */
695 cli->tree->tid = cnum1;
697 if (!torture_close_connection(cli)) {
706 static BOOL tcon_devtest(struct smbcli_state *cli,
707 const char *myshare, const char *devtype,
708 NTSTATUS expected_error)
712 const char *password = lp_parm_string(-1, "torture", "password");
714 status = NT_STATUS_IS_OK(smbcli_send_tconX(cli, myshare, devtype,
717 printf("Trying share %s with devtype %s\n", myshare, devtype);
719 if (NT_STATUS_IS_OK(expected_error)) {
723 printf("tconX to share %s with type %s "
724 "should have succeeded but failed\n",
731 printf("tconx to share %s with type %s "
732 "should have failed but succeeded\n",
736 if (NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),
740 printf("Returned unexpected error\n");
749 checks for correct tconX support
751 static BOOL run_tcon_devtype_test(void)
753 struct smbcli_state *cli1 = NULL;
758 const char *host = lp_parm_string(-1, "torture", "host");
759 const char *share = lp_parm_string(-1, "torture", "share");
760 const char *username = lp_parm_string(-1, "torture", "username");
761 const char *userdomain = lp_parm_string(-1, "torture", "userdomain");
762 const char *password = lp_parm_string(-1, "torture", "password");
764 status = smbcli_full_connection(NULL,
765 &cli1, lp_netbios_name(),
768 username, userdomain,
769 password, flags, &retry);
771 if (!NT_STATUS_IS_OK(status)) {
772 printf("could not open connection\n");
776 if (!tcon_devtest(cli1, "IPC$", "A:", NT_STATUS_BAD_DEVICE_TYPE))
779 if (!tcon_devtest(cli1, "IPC$", "?????", NT_STATUS_OK))
782 if (!tcon_devtest(cli1, "IPC$", "LPT:", NT_STATUS_BAD_DEVICE_TYPE))
785 if (!tcon_devtest(cli1, "IPC$", "IPC", NT_STATUS_OK))
788 if (!tcon_devtest(cli1, "IPC$", "FOOBA", NT_STATUS_BAD_DEVICE_TYPE))
791 if (!tcon_devtest(cli1, share, "A:", NT_STATUS_OK))
794 if (!tcon_devtest(cli1, share, "?????", NT_STATUS_OK))
797 if (!tcon_devtest(cli1, share, "LPT:", NT_STATUS_BAD_DEVICE_TYPE))
800 if (!tcon_devtest(cli1, share, "IPC", NT_STATUS_BAD_DEVICE_TYPE))
803 if (!tcon_devtest(cli1, share, "FOOBA", NT_STATUS_BAD_DEVICE_TYPE))
806 smbcli_shutdown(cli1);
809 printf("Passed tcondevtest\n");
816 test whether fnums and tids open on one VC are available on another (a major
819 static BOOL run_fdpasstest(void)
821 struct smbcli_state *cli1, *cli2;
822 const char *fname = "\\fdpass.tst";
826 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
830 printf("starting fdpasstest\n");
832 smbcli_unlink(cli1->tree, fname);
834 printf("Opening a file on connection 1\n");
836 fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
838 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
842 printf("writing to file on connection 1\n");
844 if (smbcli_write(cli1->tree, fnum1, 0, "hello world\n", 0, 13) != 13) {
845 printf("write failed (%s)\n", smbcli_errstr(cli1->tree));
849 oldtid = cli2->tree->tid;
850 cli2->session->vuid = cli1->session->vuid;
851 cli2->tree->tid = cli1->tree->tid;
852 cli2->session->pid = cli1->session->pid;
854 printf("reading from file on connection 2\n");
856 if (smbcli_read(cli2->tree, fnum1, buf, 0, 13) == 13) {
857 printf("read succeeded! nasty security hole [%s]\n",
862 smbcli_close(cli1->tree, fnum1);
863 smbcli_unlink(cli1->tree, fname);
865 cli2->tree->tid = oldtid;
867 torture_close_connection(cli1);
868 torture_close_connection(cli2);
870 printf("finished fdpasstest\n");
876 test the timing of deferred open requests
878 static BOOL run_deferopen(struct smbcli_state *cli, int dummy)
880 const char *fname = "\\defer_open_test.dat";
886 printf("failed to connect\n");
890 printf("Testing deferred open requests.\n");
897 tv = timeval_current();
898 fnum = smbcli_nt_create_full(cli->tree, fname, 0, GENERIC_RIGHTS_FILE_ALL_ACCESS,
899 FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_NONE,
900 NTCREATEX_DISP_OPEN_IF, 0, 0);
904 if (NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),NT_STATUS_SHARING_VIOLATION)) {
905 double e = timeval_elapsed(&tv);
906 if (e < 0.5 || e > 1.5) {
907 fprintf(stderr,"Timing incorrect %.2f violation\n",
911 } while (NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),NT_STATUS_SHARING_VIOLATION));
914 fprintf(stderr,"Failed to open %s, error=%s\n", fname, smbcli_errstr(cli->tree));
918 printf("pid %u open %d\n", getpid(), i);
922 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum))) {
923 fprintf(stderr,"Failed to close %s, error=%s\n", fname, smbcli_errstr(cli->tree));
929 if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fname))) {
930 /* All until the last unlink will fail with sharing violation. */
931 if (!NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),NT_STATUS_SHARING_VIOLATION)) {
932 printf("unlink of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
937 printf("deferred test finished\n");
938 if (!torture_close_connection(cli)) {
945 test how many open files this server supports on the one socket
947 static BOOL run_maxfidtest(struct smbcli_state *cli, int dummy)
949 #define MAXFID_TEMPLATE "\\maxfid\\fid%d\\maxfid.%d.%d"
951 int fnums[0x11000], i;
952 int retries=4, maxfid;
956 printf("failed to connect\n");
960 if (smbcli_deltree(cli->tree, "\\maxfid") == -1) {
961 printf("Failed to deltree \\maxfid - %s\n",
962 smbcli_errstr(cli->tree));
965 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, "\\maxfid"))) {
966 printf("Failed to mkdir \\maxfid, error=%s\n",
967 smbcli_errstr(cli->tree));
971 printf("Testing maximum number of open files\n");
973 for (i=0; i<0x11000; i++) {
975 asprintf(&fname, "\\maxfid\\fid%d", i/1000);
976 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, fname))) {
977 printf("Failed to mkdir %s, error=%s\n",
978 fname, smbcli_errstr(cli->tree));
983 asprintf(&fname, MAXFID_TEMPLATE, i/1000, i,(int)getpid());
984 if ((fnums[i] = smbcli_open(cli->tree, fname,
985 O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) ==
987 printf("open of %s failed (%s)\n",
988 fname, smbcli_errstr(cli->tree));
989 printf("maximum fnum is %d\n", i);
1000 printf("cleaning up\n");
1001 for (i=0;i<maxfid/2;i++) {
1002 asprintf(&fname, MAXFID_TEMPLATE, i/1000, i,(int)getpid());
1003 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnums[i]))) {
1004 printf("Close of fnum %d failed - %s\n", fnums[i], smbcli_errstr(cli->tree));
1006 if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fname))) {
1007 printf("unlink of %s failed (%s)\n",
1008 fname, smbcli_errstr(cli->tree));
1013 asprintf(&fname, MAXFID_TEMPLATE, (maxfid-i)/1000, maxfid-i,(int)getpid());
1014 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnums[maxfid-i]))) {
1015 printf("Close of fnum %d failed - %s\n", fnums[maxfid-i], smbcli_errstr(cli->tree));
1017 if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fname))) {
1018 printf("unlink of %s failed (%s)\n",
1019 fname, smbcli_errstr(cli->tree));
1024 printf("%6d %6d\r", i, maxfid-i);
1028 if (smbcli_deltree(cli->tree, "\\maxfid") == -1) {
1029 printf("Failed to deltree \\maxfid - %s\n",
1030 smbcli_errstr(cli->tree));
1034 printf("maxfid test finished\n");
1035 if (!torture_close_connection(cli)) {
1039 #undef MAXFID_TEMPLATE
1042 /* send smb negprot commands, not reading the response */
1043 static BOOL run_negprot_nowait(void)
1046 struct smbcli_state *cli, *cli2;
1047 BOOL correct = True;
1049 printf("starting negprot nowait test\n");
1051 cli = open_nbt_connection();
1056 printf("Filling send buffer\n");
1058 for (i=0;i<10000;i++) {
1059 struct smbcli_request *req;
1060 time_t t1 = time(NULL);
1061 req = smb_negprot_send(cli->transport, PROTOCOL_NT1);
1062 while (req->state == SMBCLI_REQUEST_SEND && time(NULL) < t1+5) {
1063 smbcli_transport_process(cli->transport);
1065 if (req->state == SMBCLI_REQUEST_ERROR) {
1066 printf("Failed to fill pipe - %s\n", nt_errstr(req->status));
1067 torture_close_connection(cli);
1070 if (req->state == SMBCLI_REQUEST_SEND) {
1076 printf("send buffer failed to fill\n");
1077 if (!torture_close_connection(cli)) {
1083 printf("send buffer filled after %d requests\n", i);
1085 printf("Opening secondary connection\n");
1086 if (!torture_open_connection(&cli2)) {
1090 if (!torture_close_connection(cli)) {
1094 if (!torture_close_connection(cli2)) {
1098 printf("finished negprot nowait test\n");
1105 This checks how the getatr calls works
1107 static BOOL run_attrtest(void)
1109 struct smbcli_state *cli;
1112 const char *fname = "\\attrib123456789.tst";
1113 BOOL correct = True;
1115 printf("starting attrib test\n");
1117 if (!torture_open_connection(&cli)) {
1121 smbcli_unlink(cli->tree, fname);
1122 fnum = smbcli_open(cli->tree, fname,
1123 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1124 smbcli_close(cli->tree, fnum);
1126 if (NT_STATUS_IS_ERR(smbcli_getatr(cli->tree, fname, NULL, NULL, &t))) {
1127 printf("getatr failed (%s)\n", smbcli_errstr(cli->tree));
1131 printf("New file time is %s", ctime(&t));
1133 if (abs(t - time(NULL)) > 60*60*24*10) {
1134 printf("ERROR: SMBgetatr bug. time is %s",
1140 t2 = t-60*60*24; /* 1 day ago */
1142 printf("Setting file time to %s", ctime(&t2));
1144 if (NT_STATUS_IS_ERR(smbcli_setatr(cli->tree, fname, 0, t2))) {
1145 printf("setatr failed (%s)\n", smbcli_errstr(cli->tree));
1149 if (NT_STATUS_IS_ERR(smbcli_getatr(cli->tree, fname, NULL, NULL, &t))) {
1150 printf("getatr failed (%s)\n", smbcli_errstr(cli->tree));
1154 printf("Retrieved file time as %s", ctime(&t));
1157 printf("ERROR: getatr/setatr bug. times are\n%s",
1159 printf("%s", ctime(&t2));
1163 smbcli_unlink(cli->tree, fname);
1165 if (!torture_close_connection(cli)) {
1169 printf("attrib test finished\n");
1176 This checks a couple of trans2 calls
1178 static BOOL run_trans2test(void)
1180 struct smbcli_state *cli;
1183 time_t c_time, a_time, m_time, w_time, m_time2;
1184 const char *fname = "\\trans2.tst";
1185 const char *dname = "\\trans2";
1186 const char *fname2 = "\\trans2\\trans2.tst";
1188 BOOL correct = True;
1190 printf("starting trans2 test\n");
1192 if (!torture_open_connection(&cli)) {
1196 smbcli_unlink(cli->tree, fname);
1198 printf("Testing qfileinfo\n");
1200 fnum = smbcli_open(cli->tree, fname,
1201 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1202 if (NT_STATUS_IS_ERR(smbcli_qfileinfo(cli->tree, fnum, NULL, &size, &c_time, &a_time, &m_time,
1204 printf("ERROR: qfileinfo failed (%s)\n", smbcli_errstr(cli->tree));
1208 printf("Testing NAME_INFO\n");
1210 if (NT_STATUS_IS_ERR(smbcli_qfilename(cli->tree, fnum, &pname))) {
1211 printf("ERROR: qfilename failed (%s)\n", smbcli_errstr(cli->tree));
1215 if (!pname || strcmp(pname, fname)) {
1216 printf("qfilename gave different name? [%s] [%s]\n",
1221 smbcli_close(cli->tree, fnum);
1222 smbcli_unlink(cli->tree, fname);
1224 fnum = smbcli_open(cli->tree, fname,
1225 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1227 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
1230 smbcli_close(cli->tree, fnum);
1232 printf("Checking for sticky create times\n");
1234 if (NT_STATUS_IS_ERR(smbcli_qpathinfo(cli->tree, fname, &c_time, &a_time, &m_time, &size, NULL))) {
1235 printf("ERROR: qpathinfo failed (%s)\n", smbcli_errstr(cli->tree));
1238 if (c_time != m_time) {
1239 printf("create time=%s", ctime(&c_time));
1240 printf("modify time=%s", ctime(&m_time));
1241 printf("This system appears to have sticky create times\n");
1243 if (a_time % (60*60) == 0) {
1244 printf("access time=%s", ctime(&a_time));
1245 printf("This system appears to set a midnight access time\n");
1249 if (abs(m_time - time(NULL)) > 60*60*24*7) {
1250 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
1256 smbcli_unlink(cli->tree, fname);
1257 fnum = smbcli_open(cli->tree, fname,
1258 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1259 smbcli_close(cli->tree, fnum);
1260 if (NT_STATUS_IS_ERR(smbcli_qpathinfo2(cli->tree, fname, &c_time, &a_time, &m_time, &w_time, &size, NULL, NULL))) {
1261 printf("ERROR: qpathinfo2 failed (%s)\n", smbcli_errstr(cli->tree));
1264 if (w_time < 60*60*24*2) {
1265 printf("write time=%s", ctime(&w_time));
1266 printf("This system appears to set a initial 0 write time\n");
1271 smbcli_unlink(cli->tree, fname);
1274 /* check if the server updates the directory modification time
1275 when creating a new file */
1276 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, dname))) {
1277 printf("ERROR: mkdir failed (%s)\n", smbcli_errstr(cli->tree));
1281 if (NT_STATUS_IS_ERR(smbcli_qpathinfo2(cli->tree, "\\trans2\\", &c_time, &a_time, &m_time, &w_time, &size, NULL, NULL))) {
1282 printf("ERROR: qpathinfo2 failed (%s)\n", smbcli_errstr(cli->tree));
1286 fnum = smbcli_open(cli->tree, fname2,
1287 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1288 smbcli_write(cli->tree, fnum, 0, (char *)&fnum, 0, sizeof(fnum));
1289 smbcli_close(cli->tree, fnum);
1290 if (NT_STATUS_IS_ERR(smbcli_qpathinfo2(cli->tree, "\\trans2\\", &c_time, &a_time, &m_time2, &w_time, &size, NULL, NULL))) {
1291 printf("ERROR: qpathinfo2 failed (%s)\n", smbcli_errstr(cli->tree));
1294 if (m_time2 == m_time) {
1295 printf("This system does not update directory modification times\n");
1299 smbcli_unlink(cli->tree, fname2);
1300 smbcli_rmdir(cli->tree, dname);
1302 if (!torture_close_connection(cli)) {
1306 printf("trans2 test finished\n");
1313 print out server properties
1315 static BOOL run_properties(void)
1317 struct smbcli_state *cli;
1318 BOOL correct = True;
1320 printf("starting properties test\n");
1324 if (!torture_open_connection(&cli)) {
1328 d_printf("Capabilities 0x%08x\n", cli->transport->negotiate.capabilities);
1330 if (!torture_close_connection(cli)) {
1339 /* FIRST_DESIRED_ACCESS 0xf019f */
1340 #define FIRST_DESIRED_ACCESS SA_RIGHT_FILE_READ_DATA|SA_RIGHT_FILE_WRITE_DATA|SA_RIGHT_FILE_APPEND_DATA|\
1341 SA_RIGHT_FILE_READ_EA| /* 0xf */ \
1342 SA_RIGHT_FILE_WRITE_EA|SA_RIGHT_FILE_READ_ATTRIBUTES| /* 0x90 */ \
1343 SA_RIGHT_FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
1344 STD_RIGHT_DELETE_ACCESS|STD_RIGHT_READ_CONTROL_ACCESS|\
1345 STD_RIGHT_WRITE_DAC_ACCESS|STD_RIGHT_WRITE_OWNER_ACCESS /* 0xf0000 */
1346 /* SECOND_DESIRED_ACCESS 0xe0080 */
1347 #define SECOND_DESIRED_ACCESS SA_RIGHT_FILE_READ_ATTRIBUTES| /* 0x80 */ \
1348 STD_RIGHT_READ_CONTROL_ACCESS|STD_RIGHT_WRITE_DAC_ACCESS|\
1349 STD_RIGHT_WRITE_OWNER_ACCESS /* 0xe0000 */
1352 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
1353 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
1354 SA_RIGHT_FILE_READ_DATA|\
1355 WRITE_OWNER_ACCESS /* */
1359 Test ntcreate calls made by xcopy
1361 static BOOL run_xcopy(void)
1363 struct smbcli_state *cli1;
1364 const char *fname = "\\test.txt";
1365 BOOL correct = True;
1368 printf("starting xcopy test\n");
1370 if (!torture_open_connection(&cli1)) {
1374 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0,
1375 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
1376 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF,
1380 printf("First open failed - %s\n", smbcli_errstr(cli1->tree));
1384 fnum2 = smbcli_nt_create_full(cli1->tree, fname, 0,
1385 SECOND_DESIRED_ACCESS, 0,
1386 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN,
1389 printf("second open failed - %s\n", smbcli_errstr(cli1->tree));
1393 if (!torture_close_connection(cli1)) {
1402 see how many RPC pipes we can open at once
1404 static BOOL run_pipe_number(void)
1406 struct smbcli_state *cli1;
1407 const char *pipe_name = "\\WKSSVC";
1411 printf("starting pipenumber test\n");
1412 if (!torture_open_connection(&cli1)) {
1417 fnum = smbcli_nt_create_full(cli1->tree, pipe_name, 0, SA_RIGHT_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
1418 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1421 printf("Open of pipe %s failed with error (%s)\n", pipe_name, smbcli_errstr(cli1->tree));
1425 printf("%d\r", num_pipes);
1429 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes, pipe_name );
1430 torture_close_connection(cli1);
1438 open N connections to the server and just hold them open
1439 used for testing performance when there are N idle users
1442 static BOOL torture_holdcon(void)
1445 struct smbcli_state **cli;
1448 printf("Opening %d connections\n", torture_numops);
1450 cli = malloc(sizeof(struct smbcli_state *) * torture_numops);
1452 for (i=0;i<torture_numops;i++) {
1453 if (!torture_open_connection(&cli[i])) {
1456 printf("opened %d connections\r", i);
1460 printf("\nStarting pings\n");
1463 for (i=0;i<torture_numops;i++) {
1466 status = smbcli_chkpath(cli[i]->tree, "\\");
1467 if (!NT_STATUS_IS_OK(status)) {
1468 printf("Connection %d is dead\n", i);
1476 if (num_dead == torture_numops) {
1477 printf("All connections dead - finishing\n");
1489 Try with a wrong vuid and check error message.
1492 static BOOL run_vuidtest(void)
1494 struct smbcli_state *cli;
1495 const char *fname = "\\vuid.tst";
1498 time_t c_time, a_time, m_time;
1499 BOOL correct = True;
1504 printf("starting vuid test\n");
1506 if (!torture_open_connection(&cli)) {
1510 smbcli_unlink(cli->tree, fname);
1512 fnum = smbcli_open(cli->tree, fname,
1513 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1515 orig_vuid = cli->session->vuid;
1517 cli->session->vuid += 1234;
1519 printf("Testing qfileinfo with wrong vuid\n");
1521 if (NT_STATUS_IS_OK(result = smbcli_qfileinfo(cli->tree, fnum, NULL,
1522 &size, &c_time, &a_time,
1523 &m_time, NULL, NULL))) {
1524 printf("ERROR: qfileinfo passed with wrong vuid\n");
1528 if ( (cli->transport->error.etype != ETYPE_DOS) ||
1529 (cli->transport->error.e.dos.eclass != ERRSRV) ||
1530 (cli->transport->error.e.dos.ecode != ERRbaduid) ) {
1531 printf("ERROR: qfileinfo should have returned DOS error "
1532 "ERRSRV:ERRbaduid\n but returned %s\n",
1533 smbcli_errstr(cli->tree));
1537 cli->session->vuid -= 1234;
1539 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum))) {
1540 printf("close failed (%s)\n", smbcli_errstr(cli->tree));
1544 smbcli_unlink(cli->tree, fname);
1546 if (!torture_close_connection(cli)) {
1550 printf("vuid test finished\n");
1556 Test open mode returns on read-only files.
1558 static BOOL run_opentest(void)
1560 static struct smbcli_state *cli1;
1561 static struct smbcli_state *cli2;
1562 const char *fname = "\\readonly.file";
1566 BOOL correct = True;
1570 printf("starting open test\n");
1572 if (!torture_open_connection(&cli1)) {
1576 smbcli_setatr(cli1->tree, fname, 0, 0);
1577 smbcli_unlink(cli1->tree, fname);
1579 fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1581 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1585 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1586 printf("close2 failed (%s)\n", smbcli_errstr(cli1->tree));
1590 if (NT_STATUS_IS_ERR(smbcli_setatr(cli1->tree, fname, FILE_ATTRIBUTE_READONLY, 0))) {
1591 printf("smbcli_setatr failed (%s)\n", smbcli_errstr(cli1->tree));
1592 CHECK_MAX_FAILURES(error_test1);
1596 fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY, DENY_WRITE);
1598 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1599 CHECK_MAX_FAILURES(error_test1);
1603 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
1604 fnum2 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_ALL);
1606 if (check_error(__location__, cli1, ERRDOS, ERRnoaccess,
1607 NT_STATUS_ACCESS_DENIED)) {
1608 printf("correct error code ERRDOS/ERRnoaccess returned\n");
1611 printf("finished open test 1\n");
1613 smbcli_close(cli1->tree, fnum1);
1615 /* Now try not readonly and ensure ERRbadshare is returned. */
1617 smbcli_setatr(cli1->tree, fname, 0, 0);
1619 fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY, DENY_WRITE);
1621 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1625 /* This will fail - but the error should be ERRshare. */
1626 fnum2 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_ALL);
1628 if (check_error(__location__, cli1, ERRDOS, ERRbadshare,
1629 NT_STATUS_SHARING_VIOLATION)) {
1630 printf("correct error code ERRDOS/ERRbadshare returned\n");
1633 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1634 printf("close2 failed (%s)\n", smbcli_errstr(cli1->tree));
1638 smbcli_unlink(cli1->tree, fname);
1640 printf("finished open test 2\n");
1642 /* Test truncate open disposition on file opened for read. */
1644 fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1646 printf("(3) open (1) of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1650 /* write 20 bytes. */
1652 memset(buf, '\0', 20);
1654 if (smbcli_write(cli1->tree, fnum1, 0, buf, 0, 20) != 20) {
1655 printf("write failed (%s)\n", smbcli_errstr(cli1->tree));
1659 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1660 printf("(3) close1 failed (%s)\n", smbcli_errstr(cli1->tree));
1664 /* Ensure size == 20. */
1665 if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
1666 printf("(3) getatr failed (%s)\n", smbcli_errstr(cli1->tree));
1667 CHECK_MAX_FAILURES(error_test3);
1672 printf("(3) file size != 20\n");
1673 CHECK_MAX_FAILURES(error_test3);
1677 /* Now test if we can truncate a file opened for readonly. */
1679 fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY|O_TRUNC, DENY_NONE);
1681 printf("(3) open (2) of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1682 CHECK_MAX_FAILURES(error_test3);
1686 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1687 printf("close2 failed (%s)\n", smbcli_errstr(cli1->tree));
1691 /* Ensure size == 0. */
1692 if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
1693 printf("(3) getatr failed (%s)\n", smbcli_errstr(cli1->tree));
1694 CHECK_MAX_FAILURES(error_test3);
1699 printf("(3) file size != 0\n");
1700 CHECK_MAX_FAILURES(error_test3);
1703 printf("finished open test 3\n");
1705 smbcli_unlink(cli1->tree, fname);
1708 printf("testing ctemp\n");
1709 fnum1 = smbcli_ctemp(cli1->tree, "\\", &tmp_path);
1711 printf("ctemp failed (%s)\n", smbcli_errstr(cli1->tree));
1712 CHECK_MAX_FAILURES(error_test4);
1715 printf("ctemp gave path %s\n", tmp_path);
1716 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1717 printf("close of temp failed (%s)\n", smbcli_errstr(cli1->tree));
1719 if (NT_STATUS_IS_ERR(smbcli_unlink(cli1->tree, tmp_path))) {
1720 printf("unlink of temp failed (%s)\n", smbcli_errstr(cli1->tree));
1723 /* Test the non-io opens... */
1725 if (!torture_open_connection(&cli2)) {
1729 smbcli_setatr(cli2->tree, fname, 0, 0);
1730 smbcli_unlink(cli2->tree, fname);
1732 printf("TEST #1 testing 2 non-io opens (no delete)\n");
1734 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1735 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1738 printf("test 1 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1739 CHECK_MAX_FAILURES(error_test10);
1743 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1744 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1746 printf("test 1 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1747 CHECK_MAX_FAILURES(error_test10);
1751 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1752 printf("test 1 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1755 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1756 printf("test 1 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1760 printf("non-io open test #1 passed.\n");
1762 smbcli_unlink(cli1->tree, fname);
1764 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
1766 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1767 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1770 printf("test 2 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1771 CHECK_MAX_FAILURES(error_test20);
1775 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1776 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1779 printf("test 2 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1780 CHECK_MAX_FAILURES(error_test20);
1784 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1785 printf("test 1 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1788 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1789 printf("test 1 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1793 printf("non-io open test #2 passed.\n");
1795 smbcli_unlink(cli1->tree, fname);
1797 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
1799 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1800 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1803 printf("test 3 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1804 CHECK_MAX_FAILURES(error_test30);
1808 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1809 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1812 printf("test 3 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1813 CHECK_MAX_FAILURES(error_test30);
1817 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1818 printf("test 3 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1821 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1822 printf("test 3 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1826 printf("non-io open test #3 passed.\n");
1828 smbcli_unlink(cli1->tree, fname);
1830 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
1832 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1833 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1836 printf("test 4 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1837 CHECK_MAX_FAILURES(error_test40);
1841 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1842 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1845 printf("test 4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1846 CHECK_MAX_FAILURES(error_test40);
1850 printf("test 4 open 2 of %s gave %s (correct error should be %s)\n", fname, smbcli_errstr(cli2->tree), "sharing violation");
1852 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1853 printf("test 4 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1857 printf("non-io open test #4 passed.\n");
1859 smbcli_unlink(cli1->tree, fname);
1861 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
1863 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1864 NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1867 printf("test 5 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1868 CHECK_MAX_FAILURES(error_test50);
1872 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1873 NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1876 printf("test 5 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1877 CHECK_MAX_FAILURES(error_test50);
1881 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1882 printf("test 5 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1886 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1887 printf("test 5 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1891 printf("non-io open test #5 passed.\n");
1893 printf("TEST #6 testing 1 non-io open, one io open\n");
1895 smbcli_unlink(cli1->tree, fname);
1897 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SA_RIGHT_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
1898 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1901 printf("test 6 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1902 CHECK_MAX_FAILURES(error_test60);
1906 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1907 NTCREATEX_SHARE_ACCESS_READ, NTCREATEX_DISP_OPEN_IF, 0, 0);
1910 printf("test 6 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1911 CHECK_MAX_FAILURES(error_test60);
1915 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1916 printf("test 6 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1920 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1921 printf("test 6 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1925 printf("non-io open test #6 passed.\n");
1927 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
1929 smbcli_unlink(cli1->tree, fname);
1931 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SA_RIGHT_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
1932 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1935 printf("test 7 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1936 CHECK_MAX_FAILURES(error_test70);
1940 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1941 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1944 printf("test 7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1945 CHECK_MAX_FAILURES(error_test70);
1949 printf("test 7 open 2 of %s gave %s (correct error should be %s)\n", fname, smbcli_errstr(cli2->tree), "sharing violation");
1951 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1952 printf("test 7 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1956 printf("non-io open test #7 passed.\n");
1960 printf("TEST #8 testing one normal open, followed by lock, followed by open with truncate\n");
1962 smbcli_unlink(cli1->tree, fname);
1964 fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
1966 printf("(8) open (1) of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1970 /* write 20 bytes. */
1972 memset(buf, '\0', 20);
1974 if (smbcli_write(cli1->tree, fnum1, 0, buf, 0, 20) != 20) {
1975 printf("(8) write failed (%s)\n", smbcli_errstr(cli1->tree));
1979 /* Ensure size == 20. */
1980 if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
1981 printf("(8) getatr (1) failed (%s)\n", smbcli_errstr(cli1->tree));
1982 CHECK_MAX_FAILURES(error_test80);
1987 printf("(8) file size != 20\n");
1988 CHECK_MAX_FAILURES(error_test80);
1992 /* Get an exclusive lock on the open file. */
1993 if (NT_STATUS_IS_ERR(smbcli_lock(cli1->tree, fnum1, 0, 4, 0, WRITE_LOCK))) {
1994 printf("(8) lock1 failed (%s)\n", smbcli_errstr(cli1->tree));
1995 CHECK_MAX_FAILURES(error_test80);
1999 fnum2 = smbcli_open(cli1->tree, fname, O_RDWR|O_TRUNC, DENY_NONE);
2001 printf("(8) open (2) of %s with truncate failed (%s)\n", fname, smbcli_errstr(cli1->tree));
2005 /* Ensure size == 0. */
2006 if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
2007 printf("(8) getatr (2) failed (%s)\n", smbcli_errstr(cli1->tree));
2008 CHECK_MAX_FAILURES(error_test80);
2013 printf("(8) file size != 0\n");
2014 CHECK_MAX_FAILURES(error_test80);
2018 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
2019 printf("(8) close1 failed (%s)\n", smbcli_errstr(cli1->tree));
2023 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum2))) {
2024 printf("(8) close1 failed (%s)\n", smbcli_errstr(cli1->tree));
2030 printf("open test #8 passed.\n");
2032 smbcli_unlink(cli1->tree, fname);
2034 if (!torture_close_connection(cli1)) {
2037 if (!torture_close_connection(cli2)) {
2046 sees what IOCTLs are supported
2048 BOOL torture_ioctl_test(void)
2050 struct smbcli_state *cli;
2051 uint16_t device, function;
2053 const char *fname = "\\ioctl.dat";
2055 union smb_ioctl parms;
2056 TALLOC_CTX *mem_ctx;
2058 if (!torture_open_connection(&cli)) {
2062 mem_ctx = talloc_init("ioctl_test");
2064 printf("starting ioctl test\n");
2066 smbcli_unlink(cli->tree, fname);
2068 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2070 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
2074 parms.ioctl.level = RAW_IOCTL_IOCTL;
2075 parms.ioctl.in.fnum = fnum;
2076 parms.ioctl.in.request = IOCTL_QUERY_JOB_INFO;
2077 status = smb_raw_ioctl(cli->tree, mem_ctx, &parms);
2078 printf("ioctl job info: %s\n", smbcli_errstr(cli->tree));
2080 for (device=0;device<0x100;device++) {
2081 printf("testing device=0x%x\n", device);
2082 for (function=0;function<0x100;function++) {
2083 parms.ioctl.in.request = (device << 16) | function;
2084 status = smb_raw_ioctl(cli->tree, mem_ctx, &parms);
2086 if (NT_STATUS_IS_OK(status)) {
2087 printf("ioctl device=0x%x function=0x%x OK : %d bytes\n",
2088 device, function, parms.ioctl.out.blob.length);
2093 if (!torture_close_connection(cli)) {
2102 tries variants of chkpath
2104 BOOL torture_chkpath_test(void)
2106 struct smbcli_state *cli;
2110 if (!torture_open_connection(&cli)) {
2114 printf("starting chkpath test\n");
2116 printf("Testing valid and invalid paths\n");
2118 /* cleanup from an old run */
2119 smbcli_rmdir(cli->tree, "\\chkpath.dir\\dir2");
2120 smbcli_unlink(cli->tree, "\\chkpath.dir\\*");
2121 smbcli_rmdir(cli->tree, "\\chkpath.dir");
2123 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, "\\chkpath.dir"))) {
2124 printf("mkdir1 failed : %s\n", smbcli_errstr(cli->tree));
2128 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, "\\chkpath.dir\\dir2"))) {
2129 printf("mkdir2 failed : %s\n", smbcli_errstr(cli->tree));
2133 fnum = smbcli_open(cli->tree, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2135 printf("open1 failed (%s)\n", smbcli_errstr(cli->tree));
2138 smbcli_close(cli->tree, fnum);
2140 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir"))) {
2141 printf("chkpath1 failed: %s\n", smbcli_errstr(cli->tree));
2145 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\dir2"))) {
2146 printf("chkpath2 failed: %s\n", smbcli_errstr(cli->tree));
2150 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\foo.txt"))) {
2151 ret = check_error(__location__, cli, ERRDOS, ERRbadpath,
2152 NT_STATUS_NOT_A_DIRECTORY);
2154 printf("* chkpath on a file should fail\n");
2158 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\bar.txt"))) {
2159 ret = check_error(__location__, cli, ERRDOS, ERRbadfile,
2160 NT_STATUS_OBJECT_NAME_NOT_FOUND);
2162 printf("* chkpath on a non existent file should fail\n");
2166 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\dirxx\\bar.txt"))) {
2167 ret = check_error(__location__, cli, ERRDOS, ERRbadpath,
2168 NT_STATUS_OBJECT_PATH_NOT_FOUND);
2170 printf("* chkpath on a non existent component should fail\n");
2174 smbcli_rmdir(cli->tree, "\\chkpath.dir\\dir2");
2175 smbcli_unlink(cli->tree, "\\chkpath.dir\\*");
2176 smbcli_rmdir(cli->tree, "\\chkpath.dir");
2178 if (!torture_close_connection(cli)) {
2187 parse a //server/share type UNC name
2189 static BOOL parse_unc(const char *unc_name, char **hostname, char **sharename)
2193 if (strncmp(unc_name, "//", 2)) {
2197 *hostname = strdup(&unc_name[2]);
2198 p = strchr_m(&(*hostname)[2],'/');
2203 *sharename = strdup(p+1);
2210 static void sigcont(int sig)
2214 double torture_create_procs(BOOL (*fn)(struct smbcli_state *, int), BOOL *result)
2217 volatile pid_t *child_status;
2218 volatile BOOL *child_status_out;
2221 double start_time_limit = 10 + (torture_nprocs * 1.5);
2222 char **unc_list = NULL;
2224 int num_unc_names = 0;
2229 signal(SIGCONT, sigcont);
2231 child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*torture_nprocs);
2232 if (!child_status) {
2233 printf("Failed to setup shared memory\n");
2237 child_status_out = (volatile BOOL *)shm_setup(sizeof(BOOL)*torture_nprocs);
2238 if (!child_status_out) {
2239 printf("Failed to setup result status shared memory\n");
2243 p = lp_parm_string(-1, "torture", "unclist");
2245 unc_list = file_lines_load(p, &num_unc_names);
2246 if (!unc_list || num_unc_names <= 0) {
2247 printf("Failed to load unc names list from '%s'\n", p);
2252 for (i = 0; i < torture_nprocs; i++) {
2253 child_status[i] = 0;
2254 child_status_out[i] = True;
2257 tv = timeval_current();
2259 for (i=0;i<torture_nprocs;i++) {
2263 char *hostname=NULL, *sharename;
2265 pid_t mypid = getpid();
2266 sys_srandom(((int)mypid) ^ ((int)time(NULL)));
2268 asprintf(&myname, "CLIENT%d", i);
2269 lp_set_cmdline("netbios name", myname);
2274 if (!parse_unc(unc_list[i % num_unc_names],
2275 &hostname, &sharename)) {
2276 printf("Failed to parse UNC name %s\n",
2277 unc_list[i % num_unc_names]);
2284 if (torture_open_connection_share(¤t_cli,
2289 } else if (torture_open_connection(¤t_cli)) {
2293 printf("pid %d failed to start\n", (int)getpid());
2299 child_status[i] = getpid();
2303 if (child_status[i]) {
2304 printf("Child %d failed to start!\n", i);
2305 child_status_out[i] = 1;
2309 child_status_out[i] = fn(current_cli, i);
2316 for (i=0;i<torture_nprocs;i++) {
2317 if (child_status[i]) synccount++;
2319 if (synccount == torture_nprocs) break;
2321 } while (timeval_elapsed(&tv) < start_time_limit);
2323 if (synccount != torture_nprocs) {
2324 printf("FAILED TO START %d CLIENTS (started %d)\n", torture_nprocs, synccount);
2326 return timeval_elapsed(&tv);
2329 printf("Starting %d clients\n", torture_nprocs);
2331 /* start the client load */
2332 tv = timeval_current();
2333 for (i=0;i<torture_nprocs;i++) {
2334 child_status[i] = 0;
2338 printf("%d clients started\n", torture_nprocs);
2340 for (i=0;i<torture_nprocs;i++) {
2342 while ((ret=sys_waitpid(0, &status, 0)) == -1 && errno == EINTR) /* noop */ ;
2343 if (ret == -1 || WEXITSTATUS(status) != 0) {
2350 for (i=0;i<torture_nprocs;i++) {
2351 if (!child_status_out[i]) {
2355 return timeval_elapsed(&tv);
2358 #define FLAG_MULTIPROC 1
2363 BOOL (*multi_fn)(struct smbcli_state *, int );
2366 {"BASE-FDPASS", run_fdpasstest, 0},
2367 {"BASE-LOCK1", torture_locktest1, 0},
2368 {"BASE-LOCK2", torture_locktest2, 0},
2369 {"BASE-LOCK3", torture_locktest3, 0},
2370 {"BASE-LOCK4", torture_locktest4, 0},
2371 {"BASE-LOCK5", torture_locktest5, 0},
2372 {"BASE-LOCK6", torture_locktest6, 0},
2373 {"BASE-LOCK7", torture_locktest7, 0},
2374 {"BASE-UNLINK", torture_unlinktest, 0},
2375 {"BASE-ATTR", run_attrtest, 0},
2376 {"BASE-TRANS2", run_trans2test, 0},
2377 {"BASE-NEGNOWAIT", run_negprot_nowait, 0},
2378 {"BASE-DIR1", torture_dirtest1, 0},
2379 {"BASE-DIR2", torture_dirtest2, 0},
2380 {"BASE-DENY1", torture_denytest1, 0},
2381 {"BASE-DENY2", torture_denytest2, 0},
2382 {"BASE-DENY3", torture_denytest3, 0},
2383 {"BASE-DENYDOS", torture_denydos_sharing, 0},
2384 {"BASE-NTDENY1", NULL, torture_ntdenytest1},
2385 {"BASE-NTDENY2", torture_ntdenytest2, 0},
2386 {"BASE-TCON", run_tcon_test, 0},
2387 {"BASE-TCONDEV", run_tcon_devtype_test, 0},
2388 {"BASE-VUID", run_vuidtest, 0},
2389 {"BASE-RW1", run_readwritetest, 0},
2390 {"BASE-RW2", NULL, run_readwritemulti},
2391 {"BASE-OPEN", run_opentest, 0},
2392 {"BASE-DEFER_OPEN", NULL, run_deferopen},
2393 {"BASE-XCOPY", run_xcopy, 0},
2394 {"BASE-RENAME", torture_test_rename, 0},
2395 {"BASE-DELETE", torture_test_delete, 0},
2396 {"BASE-PROPERTIES", run_properties, 0},
2397 {"BASE-MANGLE", torture_mangle, 0},
2398 {"BASE-OPENATTR", torture_openattrtest, 0},
2399 {"BASE-CHARSET", torture_charset, 0},
2400 {"BASE-CHKPATH", torture_chkpath_test, 0},
2401 {"BASE-SECLEAK", torture_sec_leak, 0},
2402 {"BASE-DISCONNECT", torture_disconnect, 0},
2403 {"BASE-DELAYWRITE", torture_delay_write, 0},
2405 /* benchmarking tests */
2406 {"BENCH-HOLDCON", torture_holdcon, 0},
2407 {"BENCH-NBENCH", torture_nbench, 0},
2408 {"BENCH-TORTURE", NULL, run_torture},
2411 {"RAW-QFSINFO", torture_raw_qfsinfo, 0},
2412 {"RAW-QFILEINFO", torture_raw_qfileinfo, 0},
2413 {"RAW-SFILEINFO", torture_raw_sfileinfo, 0},
2414 {"RAW-SFILEINFO-BUG", torture_raw_sfileinfo_bug, 0},
2415 {"RAW-SEARCH", torture_raw_search, 0},
2416 {"RAW-CLOSE", torture_raw_close, 0},
2417 {"RAW-OPEN", torture_raw_open, 0},
2418 {"RAW-MKDIR", torture_raw_mkdir, 0},
2419 {"RAW-OPLOCK", torture_raw_oplock, 0},
2420 {"RAW-NOTIFY", torture_raw_notify, 0},
2421 {"RAW-MUX", torture_raw_mux, 0},
2422 {"RAW-IOCTL", torture_raw_ioctl, 0},
2423 {"RAW-CHKPATH", torture_raw_chkpath, 0},
2424 {"RAW-UNLINK", torture_raw_unlink, 0},
2425 {"RAW-READ", torture_raw_read, 0},
2426 {"RAW-WRITE", torture_raw_write, 0},
2427 {"RAW-LOCK", torture_raw_lock, 0},
2428 {"RAW-CONTEXT", torture_raw_context, 0},
2429 {"RAW-RENAME", torture_raw_rename, 0},
2430 {"RAW-SEEK", torture_raw_seek, 0},
2431 {"RAW-EAS", torture_raw_eas, 0},
2432 {"RAW-STREAMS", torture_raw_streams, 0},
2433 {"RAW-ACLS", torture_raw_acls, 0},
2434 {"RAW-RAP", torture_raw_rap, 0},
2436 /* protocol scanners */
2437 {"SCAN-TRANS2", torture_trans2_scan, 0},
2438 {"SCAN-NTTRANS", torture_nttrans_scan, 0},
2439 {"SCAN-ALIASES", torture_trans2_aliases, 0},
2440 {"SCAN-SMB", torture_smb_scan, 0},
2441 {"SCAN-MAXFID", NULL, run_maxfidtest},
2442 {"SCAN-UTABLE", torture_utable, 0},
2443 {"SCAN-CASETABLE", torture_casetable, 0},
2444 {"SCAN-PIPE_NUMBER", run_pipe_number, 0},
2445 {"SCAN-IOCTL", torture_ioctl_test, 0},
2448 {"RPC-LSA", torture_rpc_lsa, 0},
2449 {"RPC-ECHO", torture_rpc_echo, 0},
2450 {"RPC-DFS", torture_rpc_dfs, 0},
2451 {"RPC-SPOOLSS", torture_rpc_spoolss, 0},
2452 {"RPC-SAMR", torture_rpc_samr, 0},
2453 {"RPC-NETLOGON", torture_rpc_netlogon, 0},
2454 {"RPC-SAMLOGON", torture_rpc_samlogon, 0},
2455 {"RPC-SAMSYNC", torture_rpc_samsync, 0},
2456 {"RPC-SCHANNEL", torture_rpc_schannel, 0},
2457 {"RPC-WKSSVC", torture_rpc_wkssvc, 0},
2458 {"RPC-SRVSVC", torture_rpc_srvsvc, 0},
2459 {"RPC-SVCCTL", torture_rpc_svcctl, 0},
2460 {"RPC-ATSVC", torture_rpc_atsvc, 0},
2461 {"RPC-EVENTLOG", torture_rpc_eventlog, 0},
2462 {"RPC-EPMAPPER", torture_rpc_epmapper, 0},
2463 {"RPC-WINREG", torture_rpc_winreg, 0},
2464 {"RPC-OXIDRESOLVE", torture_rpc_oxidresolve, 0},
2465 {"RPC-REMACT", torture_rpc_remact, 0},
2466 {"RPC-MGMT", torture_rpc_mgmt, 0},
2467 {"RPC-SCANNER", torture_rpc_scanner, 0},
2468 {"RPC-AUTOIDL", torture_rpc_autoidl, 0},
2469 {"RPC-COUNTCALLS", torture_rpc_countcalls, 0},
2470 {"RPC-MULTIBIND", torture_multi_bind, 0},
2471 {"RPC-DRSUAPI", torture_rpc_drsuapi, 0},
2472 {"RPC-LOGIN", torture_rpc_login, 0},
2473 {"RPC-ROT", torture_rpc_rot, 0},
2475 /* Distributed COM testers */
2476 {"DCOM-SIMPLE", torture_dcom_simple, 0},
2478 /* local (no server) testers */
2479 {"LOCAL-NTLMSSP", torture_ntlmssp_self_check, 0},
2480 {"LOCAL-ICONV", torture_local_iconv, 0},
2481 {"LOCAL-TALLOC", torture_local_talloc, 0},
2482 {"LOCAL-MESSAGING", torture_local_messaging, 0},
2483 {"LOCAL-BINDING", torture_local_binding_string, 0},
2484 {"LOCAL-IDTREE", torture_local_idtree, 0},
2487 {"LDAP-BASIC", torture_ldap_basic, 0},
2493 /****************************************************************************
2494 run a specified test or "ALL"
2495 ****************************************************************************/
2496 static BOOL run_test(const char *name)
2500 BOOL matched = False;
2502 if (strequal(name,"ALL")) {
2503 for (i=0;torture_ops[i].name;i++) {
2504 if (!run_test(torture_ops[i].name)) {
2511 for (i=0;torture_ops[i].name;i++) {
2512 if (gen_fnmatch(name, torture_ops[i].name) == 0) {
2516 printf("Running %s\n", torture_ops[i].name);
2517 if (torture_ops[i].multi_fn) {
2519 t = torture_create_procs(torture_ops[i].multi_fn,
2523 printf("TEST %s FAILED!\n", torture_ops[i].name);
2527 struct timeval tv = timeval_current();
2528 if (!torture_ops[i].fn()) {
2530 printf("TEST %s FAILED!\n", torture_ops[i].name);
2532 t = timeval_elapsed(&tv);
2534 printf("%s took %g secs\n\n", torture_ops[i].name, t);
2539 printf("Unknown torture operation '%s'\n", name);
2546 static void parse_dns(const char *dns)
2548 char *userdn, *basedn, *secret;
2551 /* retrievieng the userdn */
2552 p = strchr_m(dns, '#');
2554 lp_set_cmdline("torture:ldap_userdn", "");
2555 lp_set_cmdline("torture:ldap_basedn", "");
2556 lp_set_cmdline("torture:ldap_secret", "");
2559 userdn = strndup(dns, p - dns);
2560 lp_set_cmdline("torture:ldap_userdn", userdn);
2562 /* retrieve the basedn */
2564 p = strchr_m(d, '#');
2566 lp_set_cmdline("torture:ldap_basedn", "");
2567 lp_set_cmdline("torture:ldap_secret", "");
2570 basedn = strndup(d, p - d);
2571 lp_set_cmdline("torture:ldap_basedn", basedn);
2573 /* retrieve the secret */
2576 lp_set_cmdline("torture:ldap_secret", "");
2580 lp_set_cmdline("torture:ldap_secret", secret);
2582 printf ("%s - %s - %s\n", userdn, basedn, secret);
2586 static void usage(poptContext pc)
2591 poptPrintUsage(pc, stdout, 0);
2594 printf("tests are:");
2595 for (i=0;torture_ops[i].name;i++) {
2596 if ((i%perline)==0) {
2599 printf("%s ", torture_ops[i].name);
2603 printf("default test is ALL\n");
2608 static BOOL is_binding_string(const char *binding_string)
2610 TALLOC_CTX *mem_ctx = talloc_init("is_binding_string");
2611 struct dcerpc_binding binding_struct;
2614 status = dcerpc_parse_binding(mem_ctx, binding_string, &binding_struct);
2616 talloc_destroy(mem_ctx);
2617 return NT_STATUS_IS_OK(status);
2620 /****************************************************************************
2622 ****************************************************************************/
2623 int main(int argc,char *argv[])
2627 BOOL correct = True;
2631 enum {OPT_LOADFILE=1000,OPT_UNCLIST,OPT_TIMELIMIT,OPT_DNS,OPT_DANGEROUS};
2632 struct poptOption long_options[] = {
2634 {"smb-ports", 'p', POPT_ARG_STRING, NULL, 0, "SMB ports", NULL},
2635 {"seed", 0, POPT_ARG_INT, &torture_seed, 0, "seed", NULL},
2636 {"num-progs", 0, POPT_ARG_INT, &torture_nprocs, 0, "num progs", NULL},
2637 {"num-ops", 0, POPT_ARG_INT, &torture_numops, 0, "num ops", NULL},
2638 {"entries", 0, POPT_ARG_INT, &torture_entries, 0, "entries", NULL},
2639 {"use-oplocks", 'L', POPT_ARG_NONE, &use_oplocks, 0, "use oplocks", NULL},
2640 {"show-all", 0, POPT_ARG_NONE, &torture_showall, 0, "show all", NULL},
2641 {"loadfile", 0, POPT_ARG_STRING, NULL, OPT_LOADFILE, "loadfile", NULL},
2642 {"unclist", 0, POPT_ARG_STRING, NULL, OPT_UNCLIST, "unclist", NULL},
2643 {"timelimit", 't', POPT_ARG_STRING, NULL, OPT_TIMELIMIT, "timelimit", NULL},
2644 {"failures", 'f', POPT_ARG_INT, &torture_failures, 0, "failures", NULL},
2645 {"parse-dns", 'D', POPT_ARG_STRING, NULL, OPT_DNS, "parse-dns", NULL},
2646 {"dangerous", 'X', POPT_ARG_NONE, NULL, OPT_DANGEROUS, "dangerous", NULL},
2648 POPT_COMMON_CONNECTION
2649 POPT_COMMON_CREDENTIALS
2654 setup_logging("smbtorture", DEBUG_STDOUT);
2656 #ifdef HAVE_SETBUFFER
2657 setbuffer(stdout, NULL, 0);
2660 pc = poptGetContext("smbtorture", argc, (const char **) argv, long_options,
2661 POPT_CONTEXT_KEEP_FIRST);
2663 poptSetOtherOptionHelp(pc, "<binding>|<unc> TEST1 TEST2 ...");
2665 while((opt = poptGetNextOpt(pc)) != -1) {
2668 lp_set_cmdline("torture:loadfile", poptGetOptArg(pc));
2671 lp_set_cmdline("torture:unclist", poptGetOptArg(pc));
2674 lp_set_cmdline("torture:timelimit", poptGetOptArg(pc));
2677 parse_dns(poptGetOptArg(pc));
2680 lp_set_cmdline("torture:dangerous", "1");
2683 d_printf("Invalid option %s: %s\n",
2684 poptBadOption(pc, 0), poptStrerror(opt));
2690 lp_load(dyn_CONFIGFILE,True,False,False);
2693 smbtorture_init_subsystems;
2696 if (torture_seed == 0) {
2697 torture_seed = time(NULL);
2699 printf("Using seed %d\n", torture_seed);
2700 srandom(torture_seed);
2702 argv_new = discard_const_p(char *, poptGetArgs(pc));
2705 for (i=0; i<argc; i++) {
2706 if (argv_new[i] == NULL) {
2717 for(p = argv_new[1]; *p; p++) {
2722 /* see if its a RPC transport specifier */
2723 if (is_binding_string(argv_new[1])) {
2724 lp_set_cmdline("torture:binding", argv_new[1]);
2726 char *binding = NULL;
2727 char *host = NULL, *share = NULL;
2729 if (!parse_unc(argv_new[1], &host, &share)) {
2730 d_printf("Invalid option: %s is not a valid torture target (share or binding string)\n\n", argv_new[1]);
2734 lp_set_cmdline("torture:host", host);
2735 lp_set_cmdline("torture:share", share);
2736 asprintf(&binding, "ncacn_np:%s", host);
2737 lp_set_cmdline("torture:binding", binding);
2740 if (!lp_parm_string(-1,"torture","username")) {
2741 lp_set_cmdline("torture:username", cmdline_get_username());
2743 if (!lp_parm_string(-1,"torture","userdomain")) {
2745 * backward compatibility
2746 * maybe we should remove this to make this consistent
2747 * for all cmdline tools
2750 if (strequal(lp_netbios_name(),cmdline_get_userdomain())) {
2751 cmdline_set_userdomain(lp_workgroup());
2753 lp_set_cmdline("torture:userdomain", cmdline_get_userdomain());
2755 if (!lp_parm_string(-1,"torture","password")) {
2756 lp_set_cmdline("torture:password", cmdline_get_userpassword());
2759 if (argc_new == 0) {
2760 printf("You must specify a test to run, or 'ALL'\n");
2762 for (i=2;i<argc_new;i++) {
2763 if (!run_test(argv_new[i])) {