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));
145 /* open a rpc connection to the chosen binding string */
146 NTSTATUS torture_rpc_connection(struct dcerpc_pipe **p,
147 const char *pipe_name,
148 const char *pipe_uuid,
149 uint32_t pipe_version)
152 const char *binding = lp_parm_string(-1, "torture", "binding");
155 printf("You must specify a ncacn binding string\n");
156 return NT_STATUS_INVALID_PARAMETER;
159 status = dcerpc_pipe_connect(p, binding, pipe_uuid, pipe_version,
160 lp_parm_string(-1, "torture", "userdomain"),
161 lp_parm_string(-1, "torture", "username"),
162 lp_parm_string(-1, "torture", "password"));
167 /* open a rpc connection to a specific transport */
168 NTSTATUS torture_rpc_connection_transport(struct dcerpc_pipe **p,
169 const char *pipe_name,
170 const char *pipe_uuid,
171 uint32_t pipe_version,
172 enum dcerpc_transport_t transport)
175 const char *binding = lp_parm_string(-1, "torture", "binding");
176 struct dcerpc_binding b;
177 TALLOC_CTX *mem_ctx = talloc_init("torture_rpc_connection_smb");
180 printf("You must specify a ncacn binding string\n");
181 return NT_STATUS_INVALID_PARAMETER;
184 status = dcerpc_parse_binding(mem_ctx, binding, &b);
185 if (!NT_STATUS_IS_OK(status)) {
186 DEBUG(0,("Failed to parse dcerpc binding '%s'\n", binding));
187 talloc_destroy(mem_ctx);
191 b.transport = transport;
193 status = dcerpc_pipe_connect_b(p, &b, pipe_uuid, pipe_version,
194 lp_parm_string(-1, "torture", "userdomain"),
195 lp_parm_string(-1, "torture", "username"),
196 lp_parm_string(-1, "torture", "password"));
201 /* close a rpc connection to a named pipe */
202 NTSTATUS torture_rpc_close(struct dcerpc_pipe *p)
204 dcerpc_pipe_close(p);
209 /* check if the server produced the expected error code */
210 BOOL check_error(const char *location, struct smbcli_state *c,
211 uint8_t eclass, uint32_t ecode, NTSTATUS nterr)
213 if (smbcli_is_dos_error(c->tree)) {
217 /* Check DOS error */
219 smbcli_dos_error(c, &class, &num);
221 if (eclass != class || ecode != num) {
222 printf("unexpected error code class=%d code=%d\n",
223 (int)class, (int)num);
224 printf(" expected %d/%d %s (at %s)\n",
225 (int)eclass, (int)ecode, nt_errstr(nterr), location);
234 status = smbcli_nt_error(c->tree);
236 if (NT_STATUS_V(nterr) != NT_STATUS_V(status)) {
237 printf("unexpected error code %s\n", nt_errstr(status));
238 printf(" expected %s (at %s)\n", nt_errstr(nterr), location);
247 static BOOL wait_lock(struct smbcli_state *c, int fnum, uint32_t offset, uint32_t len)
249 while (NT_STATUS_IS_ERR(smbcli_lock(c->tree, fnum, offset, len, -1, WRITE_LOCK))) {
250 if (!check_error(__location__, c, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
256 static BOOL rw_torture(struct smbcli_state *c)
258 const char *lockfname = "\\torture.lck";
262 pid_t pid2, pid = getpid();
267 fnum2 = smbcli_open(c->tree, lockfname, O_RDWR | O_CREAT | O_EXCL,
270 fnum2 = smbcli_open(c->tree, lockfname, O_RDWR, DENY_NONE);
272 printf("open of %s failed (%s)\n", lockfname, smbcli_errstr(c->tree));
277 for (i=0;i<torture_numops;i++) {
278 uint_t n = (uint_t)sys_random()%10;
280 printf("%d\r", i); fflush(stdout);
282 asprintf(&fname, "\\torture.%u", n);
284 if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) {
288 fnum = smbcli_open(c->tree, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL);
290 printf("open failed (%s)\n", smbcli_errstr(c->tree));
295 if (smbcli_write(c->tree, fnum, 0, (char *)&pid, 0, sizeof(pid)) != sizeof(pid)) {
296 printf("write failed (%s)\n", smbcli_errstr(c->tree));
301 if (smbcli_write(c->tree, fnum, 0, (char *)buf,
302 sizeof(pid)+(j*sizeof(buf)),
303 sizeof(buf)) != sizeof(buf)) {
304 printf("write failed (%s)\n", smbcli_errstr(c->tree));
311 if (smbcli_read(c->tree, fnum, (char *)&pid2, 0, sizeof(pid)) != sizeof(pid)) {
312 printf("read failed (%s)\n", smbcli_errstr(c->tree));
317 printf("data corruption!\n");
321 if (NT_STATUS_IS_ERR(smbcli_close(c->tree, fnum))) {
322 printf("close failed (%s)\n", smbcli_errstr(c->tree));
326 if (NT_STATUS_IS_ERR(smbcli_unlink(c->tree, fname))) {
327 printf("unlink failed (%s)\n", smbcli_errstr(c->tree));
331 if (NT_STATUS_IS_ERR(smbcli_unlock(c->tree, fnum2, n*sizeof(int), sizeof(int)))) {
332 printf("unlock failed (%s)\n", smbcli_errstr(c->tree));
338 smbcli_close(c->tree, fnum2);
339 smbcli_unlink(c->tree, lockfname);
346 static BOOL run_torture(struct smbcli_state *cli, int dummy)
350 ret = rw_torture(cli);
352 if (!torture_close_connection(cli)) {
359 static BOOL rw_torture3(struct smbcli_state *c, const char *lockfname)
366 uint_t countprev = 0;
370 for (i = 0; i < sizeof(buf); i += sizeof(uint32_t))
372 SIVAL(buf, i, sys_random());
377 fnum = smbcli_open(c->tree, lockfname, O_RDWR | O_CREAT | O_EXCL,
380 printf("first open read/write of %s failed (%s)\n",
381 lockfname, smbcli_errstr(c->tree));
387 for (i = 0; i < 500 && fnum == -1; i++)
389 fnum = smbcli_open(c->tree, lockfname, O_RDONLY,
394 printf("second open read-only of %s failed (%s)\n",
395 lockfname, smbcli_errstr(c->tree));
401 for (count = 0; count < sizeof(buf); count += sent)
403 if (count >= countprev) {
404 printf("%d %8d\r", i, count);
407 countprev += (sizeof(buf) / 20);
412 sent = ((uint_t)sys_random()%(20))+ 1;
413 if (sent > sizeof(buf) - count)
415 sent = sizeof(buf) - count;
418 if (smbcli_write(c->tree, fnum, 0, buf+count, count, (size_t)sent) != sent) {
419 printf("write failed (%s)\n", smbcli_errstr(c->tree));
425 sent = smbcli_read(c->tree, fnum, buf_rd+count, count,
429 printf("read failed offset:%d size:%d (%s)\n",
430 count, sizeof(buf)-count,
431 smbcli_errstr(c->tree));
437 if (memcmp(buf_rd+count, buf+count, sent) != 0)
439 printf("read/write compare failed\n");
440 printf("offset: %d req %d recvd %d\n",
441 count, sizeof(buf)-count, sent);
450 if (NT_STATUS_IS_ERR(smbcli_close(c->tree, fnum))) {
451 printf("close failed (%s)\n", smbcli_errstr(c->tree));
458 static BOOL rw_torture2(struct smbcli_state *c1, struct smbcli_state *c2)
460 const char *lockfname = "\\torture2.lck";
465 uint8_t buf_rd[131072];
467 ssize_t bytes_read, bytes_written;
469 if (smbcli_deltree(c1->tree, lockfname) == -1) {
470 printf("unlink failed (%s)\n", smbcli_errstr(c1->tree));
473 fnum1 = smbcli_open(c1->tree, lockfname, O_RDWR | O_CREAT | O_EXCL,
476 printf("first open read/write of %s failed (%s)\n",
477 lockfname, smbcli_errstr(c1->tree));
480 fnum2 = smbcli_open(c2->tree, lockfname, O_RDONLY,
483 printf("second open read-only of %s failed (%s)\n",
484 lockfname, smbcli_errstr(c2->tree));
485 smbcli_close(c1->tree, fnum1);
489 printf("Checking data integrity over %d ops\n", torture_numops);
491 for (i=0;i<torture_numops;i++)
493 size_t buf_size = ((uint_t)sys_random()%(sizeof(buf)-1))+ 1;
495 printf("%d\r", i); fflush(stdout);
498 generate_random_buffer(buf, buf_size);
500 if ((bytes_written = smbcli_write(c1->tree, fnum1, 0, buf, 0, buf_size)) != buf_size) {
501 printf("write failed (%s)\n", smbcli_errstr(c1->tree));
502 printf("wrote %d, expected %d\n", bytes_written, buf_size);
507 if ((bytes_read = smbcli_read(c2->tree, fnum2, buf_rd, 0, buf_size)) != buf_size) {
508 printf("read failed (%s)\n", smbcli_errstr(c2->tree));
509 printf("read %d, expected %d\n", bytes_read, buf_size);
514 if (memcmp(buf_rd, buf, buf_size) != 0)
516 printf("read/write compare failed\n");
522 if (NT_STATUS_IS_ERR(smbcli_close(c2->tree, fnum2))) {
523 printf("close failed (%s)\n", smbcli_errstr(c2->tree));
526 if (NT_STATUS_IS_ERR(smbcli_close(c1->tree, fnum1))) {
527 printf("close failed (%s)\n", smbcli_errstr(c1->tree));
531 if (NT_STATUS_IS_ERR(smbcli_unlink(c1->tree, lockfname))) {
532 printf("unlink failed (%s)\n", smbcli_errstr(c1->tree));
539 static BOOL run_readwritetest(void)
541 struct smbcli_state *cli1, *cli2;
542 BOOL test1, test2 = True;
544 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
548 printf("starting readwritetest\n");
550 test1 = rw_torture2(cli1, cli2);
551 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1));
554 test2 = rw_torture2(cli1, cli1);
555 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2));
558 if (!torture_close_connection(cli1)) {
562 if (!torture_close_connection(cli2)) {
566 return (test1 && test2);
569 static BOOL run_readwritemulti(struct smbcli_state *cli, int dummy)
573 test = rw_torture3(cli, "\\multitest.txt");
575 if (!torture_close_connection(cli)) {
584 this checks to see if a secondary tconx can use open files from an
587 static BOOL run_tcon_test(void)
589 struct smbcli_state *cli;
590 const char *fname = "\\tcontest.tmp";
592 uint16_t cnum1, cnum2, cnum3;
593 uint16_t vuid1, vuid2;
596 struct smbcli_tree *tree1;
597 const char *host = lp_parm_string(-1, "torture", "host");
598 const char *share = lp_parm_string(-1, "torture", "share");
599 const char *password = lp_parm_string(-1, "torture", "password");
601 if (!torture_open_connection(&cli)) {
605 printf("starting tcontest\n");
607 if (smbcli_deltree(cli->tree, fname) == -1) {
608 printf("unlink of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
611 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
613 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
617 cnum1 = cli->tree->tid;
618 vuid1 = cli->session->vuid;
620 memset(&buf, 0, 4); /* init buf so valgrind won't complain */
621 if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) != 4) {
622 printf("initial write failed (%s)\n", smbcli_errstr(cli->tree));
626 tree1 = cli->tree; /* save old tree connection */
627 if (NT_STATUS_IS_ERR(smbcli_send_tconX(cli, share, "?????", password))) {
628 printf("%s refused 2nd tree connect (%s)\n", host,
629 smbcli_errstr(cli->tree));
630 smbcli_shutdown(cli);
634 cnum2 = cli->tree->tid;
635 cnum3 = MAX(cnum1, cnum2) + 1; /* any invalid number */
636 vuid2 = cli->session->vuid + 1;
638 /* try a write with the wrong tid */
639 cli->tree->tid = cnum2;
641 if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) == 4) {
642 printf("* server allows write with wrong TID\n");
645 printf("server fails write with wrong TID : %s\n", smbcli_errstr(cli->tree));
649 /* try a write with an invalid tid */
650 cli->tree->tid = cnum3;
652 if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) == 4) {
653 printf("* server allows write with invalid TID\n");
656 printf("server fails write with invalid TID : %s\n", smbcli_errstr(cli->tree));
659 /* try a write with an invalid vuid */
660 cli->session->vuid = vuid2;
661 cli->tree->tid = cnum1;
663 if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) == 4) {
664 printf("* server allows write with invalid VUID\n");
667 printf("server fails write with invalid VUID : %s\n", smbcli_errstr(cli->tree));
670 cli->session->vuid = vuid1;
671 cli->tree->tid = cnum1;
673 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum1))) {
674 printf("close failed (%s)\n", smbcli_errstr(cli->tree));
678 cli->tree->tid = cnum2;
680 if (NT_STATUS_IS_ERR(smbcli_tdis(cli))) {
681 printf("secondary tdis failed (%s)\n", smbcli_errstr(cli->tree));
685 cli->tree = tree1; /* restore initial tree */
686 cli->tree->tid = cnum1;
688 if (!torture_close_connection(cli)) {
697 static BOOL tcon_devtest(struct smbcli_state *cli,
698 const char *myshare, const char *devtype,
699 NTSTATUS expected_error)
703 const char *password = lp_parm_string(-1, "torture", "password");
705 status = NT_STATUS_IS_OK(smbcli_send_tconX(cli, myshare, devtype,
708 printf("Trying share %s with devtype %s\n", myshare, devtype);
710 if (NT_STATUS_IS_OK(expected_error)) {
714 printf("tconX to share %s with type %s "
715 "should have succeeded but failed\n",
722 printf("tconx to share %s with type %s "
723 "should have failed but succeeded\n",
727 if (NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),
731 printf("Returned unexpected error\n");
740 checks for correct tconX support
742 static BOOL run_tcon_devtype_test(void)
744 struct smbcli_state *cli1 = NULL;
749 const char *host = lp_parm_string(-1, "torture", "host");
750 const char *share = lp_parm_string(-1, "torture", "share");
751 const char *username = lp_parm_string(-1, "torture", "username");
752 const char *userdomain = lp_parm_string(-1, "torture", "userdomain");
753 const char *password = lp_parm_string(-1, "torture", "password");
755 status = smbcli_full_connection(NULL,
756 &cli1, lp_netbios_name(),
759 username, userdomain,
760 password, flags, &retry);
762 if (!NT_STATUS_IS_OK(status)) {
763 printf("could not open connection\n");
767 if (!tcon_devtest(cli1, "IPC$", "A:", NT_STATUS_BAD_DEVICE_TYPE))
770 if (!tcon_devtest(cli1, "IPC$", "?????", NT_STATUS_OK))
773 if (!tcon_devtest(cli1, "IPC$", "LPT:", NT_STATUS_BAD_DEVICE_TYPE))
776 if (!tcon_devtest(cli1, "IPC$", "IPC", NT_STATUS_OK))
779 if (!tcon_devtest(cli1, "IPC$", "FOOBA", NT_STATUS_BAD_DEVICE_TYPE))
782 if (!tcon_devtest(cli1, share, "A:", NT_STATUS_OK))
785 if (!tcon_devtest(cli1, share, "?????", NT_STATUS_OK))
788 if (!tcon_devtest(cli1, share, "LPT:", NT_STATUS_BAD_DEVICE_TYPE))
791 if (!tcon_devtest(cli1, share, "IPC", NT_STATUS_BAD_DEVICE_TYPE))
794 if (!tcon_devtest(cli1, share, "FOOBA", NT_STATUS_BAD_DEVICE_TYPE))
797 smbcli_shutdown(cli1);
800 printf("Passed tcondevtest\n");
807 test whether fnums and tids open on one VC are available on another (a major
810 static BOOL run_fdpasstest(void)
812 struct smbcli_state *cli1, *cli2;
813 const char *fname = "\\fdpass.tst";
817 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
821 printf("starting fdpasstest\n");
823 smbcli_unlink(cli1->tree, fname);
825 printf("Opening a file on connection 1\n");
827 fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
829 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
833 printf("writing to file on connection 1\n");
835 if (smbcli_write(cli1->tree, fnum1, 0, "hello world\n", 0, 13) != 13) {
836 printf("write failed (%s)\n", smbcli_errstr(cli1->tree));
840 oldtid = cli2->tree->tid;
841 cli2->session->vuid = cli1->session->vuid;
842 cli2->tree->tid = cli1->tree->tid;
843 cli2->session->pid = cli1->session->pid;
845 printf("reading from file on connection 2\n");
847 if (smbcli_read(cli2->tree, fnum1, buf, 0, 13) == 13) {
848 printf("read succeeded! nasty security hole [%s]\n",
853 smbcli_close(cli1->tree, fnum1);
854 smbcli_unlink(cli1->tree, fname);
856 cli2->tree->tid = oldtid;
858 torture_close_connection(cli1);
859 torture_close_connection(cli2);
861 printf("finished fdpasstest\n");
867 test the timing of deferred open requests
869 static BOOL run_deferopen(struct smbcli_state *cli, int dummy)
871 const char *fname = "\\defer_open_test.dat";
877 printf("failed to connect\n");
881 printf("Testing deferred open requests.\n");
888 tv = timeval_current();
889 fnum = smbcli_nt_create_full(cli->tree, fname, 0, GENERIC_RIGHTS_FILE_ALL_ACCESS,
890 FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_NONE,
891 NTCREATEX_DISP_OPEN_IF, 0, 0);
895 if (NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),NT_STATUS_SHARING_VIOLATION)) {
896 double e = timeval_elapsed(&tv);
897 if (e < 0.5 || e > 1.5) {
898 fprintf(stderr,"Timing incorrect %.2f violation\n",
902 } while (NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),NT_STATUS_SHARING_VIOLATION));
905 fprintf(stderr,"Failed to open %s, error=%s\n", fname, smbcli_errstr(cli->tree));
909 printf("pid %u open %d\n", getpid(), i);
913 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum))) {
914 fprintf(stderr,"Failed to close %s, error=%s\n", fname, smbcli_errstr(cli->tree));
920 if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fname))) {
921 /* All until the last unlink will fail with sharing violation. */
922 if (!NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),NT_STATUS_SHARING_VIOLATION)) {
923 printf("unlink of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
928 printf("deferred test finished\n");
929 if (!torture_close_connection(cli)) {
936 test how many open files this server supports on the one socket
938 static BOOL run_maxfidtest(struct smbcli_state *cli, int dummy)
940 #define MAXFID_TEMPLATE "\\maxfid\\fid%d\\maxfid.%d.%d"
942 int fnums[0x11000], i;
943 int retries=4, maxfid;
947 printf("failed to connect\n");
951 if (smbcli_deltree(cli->tree, "\\maxfid") == -1) {
952 printf("Failed to deltree \\maxfid - %s\n",
953 smbcli_errstr(cli->tree));
956 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, "\\maxfid"))) {
957 printf("Failed to mkdir \\maxfid, error=%s\n",
958 smbcli_errstr(cli->tree));
962 printf("Testing maximum number of open files\n");
964 for (i=0; i<0x11000; i++) {
966 asprintf(&fname, "\\maxfid\\fid%d", i/1000);
967 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, fname))) {
968 printf("Failed to mkdir %s, error=%s\n",
969 fname, smbcli_errstr(cli->tree));
974 asprintf(&fname, MAXFID_TEMPLATE, i/1000, i,(int)getpid());
975 if ((fnums[i] = smbcli_open(cli->tree, fname,
976 O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) ==
978 printf("open of %s failed (%s)\n",
979 fname, smbcli_errstr(cli->tree));
980 printf("maximum fnum is %d\n", i);
991 printf("cleaning up\n");
992 for (i=0;i<maxfid/2;i++) {
993 asprintf(&fname, MAXFID_TEMPLATE, i/1000, i,(int)getpid());
994 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnums[i]))) {
995 printf("Close of fnum %d failed - %s\n", fnums[i], smbcli_errstr(cli->tree));
997 if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fname))) {
998 printf("unlink of %s failed (%s)\n",
999 fname, smbcli_errstr(cli->tree));
1004 asprintf(&fname, MAXFID_TEMPLATE, (maxfid-i)/1000, maxfid-i,(int)getpid());
1005 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnums[maxfid-i]))) {
1006 printf("Close of fnum %d failed - %s\n", fnums[maxfid-i], smbcli_errstr(cli->tree));
1008 if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fname))) {
1009 printf("unlink of %s failed (%s)\n",
1010 fname, smbcli_errstr(cli->tree));
1015 printf("%6d %6d\r", i, maxfid-i);
1019 if (smbcli_deltree(cli->tree, "\\maxfid") == -1) {
1020 printf("Failed to deltree \\maxfid - %s\n",
1021 smbcli_errstr(cli->tree));
1025 printf("maxfid test finished\n");
1026 if (!torture_close_connection(cli)) {
1030 #undef MAXFID_TEMPLATE
1033 /* send smb negprot commands, not reading the response */
1034 static BOOL run_negprot_nowait(void)
1037 struct smbcli_state *cli, *cli2;
1038 BOOL correct = True;
1040 printf("starting negprot nowait test\n");
1042 cli = open_nbt_connection();
1047 printf("Filling send buffer\n");
1049 for (i=0;i<10000;i++) {
1050 struct smbcli_request *req;
1051 time_t t1 = time(NULL);
1052 req = smb_negprot_send(cli->transport, PROTOCOL_NT1);
1053 while (req->state == SMBCLI_REQUEST_SEND && time(NULL) < t1+5) {
1054 smbcli_transport_process(cli->transport);
1056 if (req->state == SMBCLI_REQUEST_ERROR) {
1057 printf("Failed to fill pipe - %s\n", nt_errstr(req->status));
1058 torture_close_connection(cli);
1061 if (req->state == SMBCLI_REQUEST_SEND) {
1067 printf("send buffer failed to fill\n");
1068 if (!torture_close_connection(cli)) {
1074 printf("send buffer filled after %d requests\n", i);
1076 printf("Opening secondary connection\n");
1077 if (!torture_open_connection(&cli2)) {
1081 if (!torture_close_connection(cli)) {
1085 if (!torture_close_connection(cli2)) {
1089 printf("finished negprot nowait test\n");
1096 This checks how the getatr calls works
1098 static BOOL run_attrtest(void)
1100 struct smbcli_state *cli;
1103 const char *fname = "\\attrib123456789.tst";
1104 BOOL correct = True;
1106 printf("starting attrib test\n");
1108 if (!torture_open_connection(&cli)) {
1112 smbcli_unlink(cli->tree, fname);
1113 fnum = smbcli_open(cli->tree, fname,
1114 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1115 smbcli_close(cli->tree, fnum);
1117 if (NT_STATUS_IS_ERR(smbcli_getatr(cli->tree, fname, NULL, NULL, &t))) {
1118 printf("getatr failed (%s)\n", smbcli_errstr(cli->tree));
1122 printf("New file time is %s", ctime(&t));
1124 if (abs(t - time(NULL)) > 60*60*24*10) {
1125 printf("ERROR: SMBgetatr bug. time is %s",
1131 t2 = t-60*60*24; /* 1 day ago */
1133 printf("Setting file time to %s", ctime(&t2));
1135 if (NT_STATUS_IS_ERR(smbcli_setatr(cli->tree, fname, 0, t2))) {
1136 printf("setatr failed (%s)\n", smbcli_errstr(cli->tree));
1140 if (NT_STATUS_IS_ERR(smbcli_getatr(cli->tree, fname, NULL, NULL, &t))) {
1141 printf("getatr failed (%s)\n", smbcli_errstr(cli->tree));
1145 printf("Retrieved file time as %s", ctime(&t));
1148 printf("ERROR: getatr/setatr bug. times are\n%s",
1150 printf("%s", ctime(&t2));
1154 smbcli_unlink(cli->tree, fname);
1156 if (!torture_close_connection(cli)) {
1160 printf("attrib test finished\n");
1167 This checks a couple of trans2 calls
1169 static BOOL run_trans2test(void)
1171 struct smbcli_state *cli;
1174 time_t c_time, a_time, m_time, w_time, m_time2;
1175 const char *fname = "\\trans2.tst";
1176 const char *dname = "\\trans2";
1177 const char *fname2 = "\\trans2\\trans2.tst";
1179 BOOL correct = True;
1181 printf("starting trans2 test\n");
1183 if (!torture_open_connection(&cli)) {
1187 smbcli_unlink(cli->tree, fname);
1189 printf("Testing qfileinfo\n");
1191 fnum = smbcli_open(cli->tree, fname,
1192 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1193 if (NT_STATUS_IS_ERR(smbcli_qfileinfo(cli->tree, fnum, NULL, &size, &c_time, &a_time, &m_time,
1195 printf("ERROR: qfileinfo failed (%s)\n", smbcli_errstr(cli->tree));
1199 printf("Testing NAME_INFO\n");
1201 if (NT_STATUS_IS_ERR(smbcli_qfilename(cli->tree, fnum, &pname))) {
1202 printf("ERROR: qfilename failed (%s)\n", smbcli_errstr(cli->tree));
1206 if (!pname || strcmp(pname, fname)) {
1207 printf("qfilename gave different name? [%s] [%s]\n",
1212 smbcli_close(cli->tree, fnum);
1213 smbcli_unlink(cli->tree, fname);
1215 fnum = smbcli_open(cli->tree, fname,
1216 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1218 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
1221 smbcli_close(cli->tree, fnum);
1223 printf("Checking for sticky create times\n");
1225 if (NT_STATUS_IS_ERR(smbcli_qpathinfo(cli->tree, fname, &c_time, &a_time, &m_time, &size, NULL))) {
1226 printf("ERROR: qpathinfo failed (%s)\n", smbcli_errstr(cli->tree));
1229 if (c_time != m_time) {
1230 printf("create time=%s", ctime(&c_time));
1231 printf("modify time=%s", ctime(&m_time));
1232 printf("This system appears to have sticky create times\n");
1234 if (a_time % (60*60) == 0) {
1235 printf("access time=%s", ctime(&a_time));
1236 printf("This system appears to set a midnight access time\n");
1240 if (abs(m_time - time(NULL)) > 60*60*24*7) {
1241 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
1247 smbcli_unlink(cli->tree, fname);
1248 fnum = smbcli_open(cli->tree, fname,
1249 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1250 smbcli_close(cli->tree, fnum);
1251 if (NT_STATUS_IS_ERR(smbcli_qpathinfo2(cli->tree, fname, &c_time, &a_time, &m_time, &w_time, &size, NULL, NULL))) {
1252 printf("ERROR: qpathinfo2 failed (%s)\n", smbcli_errstr(cli->tree));
1255 if (w_time < 60*60*24*2) {
1256 printf("write time=%s", ctime(&w_time));
1257 printf("This system appears to set a initial 0 write time\n");
1262 smbcli_unlink(cli->tree, fname);
1265 /* check if the server updates the directory modification time
1266 when creating a new file */
1267 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, dname))) {
1268 printf("ERROR: mkdir failed (%s)\n", smbcli_errstr(cli->tree));
1272 if (NT_STATUS_IS_ERR(smbcli_qpathinfo2(cli->tree, "\\trans2\\", &c_time, &a_time, &m_time, &w_time, &size, NULL, NULL))) {
1273 printf("ERROR: qpathinfo2 failed (%s)\n", smbcli_errstr(cli->tree));
1277 fnum = smbcli_open(cli->tree, fname2,
1278 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1279 smbcli_write(cli->tree, fnum, 0, (char *)&fnum, 0, sizeof(fnum));
1280 smbcli_close(cli->tree, fnum);
1281 if (NT_STATUS_IS_ERR(smbcli_qpathinfo2(cli->tree, "\\trans2\\", &c_time, &a_time, &m_time2, &w_time, &size, NULL, NULL))) {
1282 printf("ERROR: qpathinfo2 failed (%s)\n", smbcli_errstr(cli->tree));
1285 if (m_time2 == m_time) {
1286 printf("This system does not update directory modification times\n");
1290 smbcli_unlink(cli->tree, fname2);
1291 smbcli_rmdir(cli->tree, dname);
1293 if (!torture_close_connection(cli)) {
1297 printf("trans2 test finished\n");
1304 print out server properties
1306 static BOOL run_properties(void)
1308 struct smbcli_state *cli;
1309 BOOL correct = True;
1311 printf("starting properties test\n");
1315 if (!torture_open_connection(&cli)) {
1319 d_printf("Capabilities 0x%08x\n", cli->transport->negotiate.capabilities);
1321 if (!torture_close_connection(cli)) {
1330 /* FIRST_DESIRED_ACCESS 0xf019f */
1331 #define FIRST_DESIRED_ACCESS SA_RIGHT_FILE_READ_DATA|SA_RIGHT_FILE_WRITE_DATA|SA_RIGHT_FILE_APPEND_DATA|\
1332 SA_RIGHT_FILE_READ_EA| /* 0xf */ \
1333 SA_RIGHT_FILE_WRITE_EA|SA_RIGHT_FILE_READ_ATTRIBUTES| /* 0x90 */ \
1334 SA_RIGHT_FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
1335 STD_RIGHT_DELETE_ACCESS|STD_RIGHT_READ_CONTROL_ACCESS|\
1336 STD_RIGHT_WRITE_DAC_ACCESS|STD_RIGHT_WRITE_OWNER_ACCESS /* 0xf0000 */
1337 /* SECOND_DESIRED_ACCESS 0xe0080 */
1338 #define SECOND_DESIRED_ACCESS SA_RIGHT_FILE_READ_ATTRIBUTES| /* 0x80 */ \
1339 STD_RIGHT_READ_CONTROL_ACCESS|STD_RIGHT_WRITE_DAC_ACCESS|\
1340 STD_RIGHT_WRITE_OWNER_ACCESS /* 0xe0000 */
1343 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
1344 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
1345 SA_RIGHT_FILE_READ_DATA|\
1346 WRITE_OWNER_ACCESS /* */
1350 Test ntcreate calls made by xcopy
1352 static BOOL run_xcopy(void)
1354 struct smbcli_state *cli1;
1355 const char *fname = "\\test.txt";
1356 BOOL correct = True;
1359 printf("starting xcopy test\n");
1361 if (!torture_open_connection(&cli1)) {
1365 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0,
1366 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
1367 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF,
1371 printf("First open failed - %s\n", smbcli_errstr(cli1->tree));
1375 fnum2 = smbcli_nt_create_full(cli1->tree, fname, 0,
1376 SECOND_DESIRED_ACCESS, 0,
1377 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN,
1380 printf("second open failed - %s\n", smbcli_errstr(cli1->tree));
1384 if (!torture_close_connection(cli1)) {
1393 see how many RPC pipes we can open at once
1395 static BOOL run_pipe_number(void)
1397 struct smbcli_state *cli1;
1398 const char *pipe_name = "\\WKSSVC";
1402 printf("starting pipenumber test\n");
1403 if (!torture_open_connection(&cli1)) {
1408 fnum = smbcli_nt_create_full(cli1->tree, pipe_name, 0, SA_RIGHT_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
1409 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1412 printf("Open of pipe %s failed with error (%s)\n", pipe_name, smbcli_errstr(cli1->tree));
1416 printf("%d\r", num_pipes);
1420 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes, pipe_name );
1421 torture_close_connection(cli1);
1429 open N connections to the server and just hold them open
1430 used for testing performance when there are N idle users
1433 static BOOL torture_holdcon(void)
1436 struct smbcli_state **cli;
1439 printf("Opening %d connections\n", torture_numops);
1441 cli = malloc(sizeof(struct smbcli_state *) * torture_numops);
1443 for (i=0;i<torture_numops;i++) {
1444 if (!torture_open_connection(&cli[i])) {
1447 printf("opened %d connections\r", i);
1451 printf("\nStarting pings\n");
1454 for (i=0;i<torture_numops;i++) {
1457 status = smbcli_chkpath(cli[i]->tree, "\\");
1458 if (!NT_STATUS_IS_OK(status)) {
1459 printf("Connection %d is dead\n", i);
1467 if (num_dead == torture_numops) {
1468 printf("All connections dead - finishing\n");
1480 Try with a wrong vuid and check error message.
1483 static BOOL run_vuidtest(void)
1485 struct smbcli_state *cli;
1486 const char *fname = "\\vuid.tst";
1489 time_t c_time, a_time, m_time;
1490 BOOL correct = True;
1495 printf("starting vuid test\n");
1497 if (!torture_open_connection(&cli)) {
1501 smbcli_unlink(cli->tree, fname);
1503 fnum = smbcli_open(cli->tree, fname,
1504 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1506 orig_vuid = cli->session->vuid;
1508 cli->session->vuid += 1234;
1510 printf("Testing qfileinfo with wrong vuid\n");
1512 if (NT_STATUS_IS_OK(result = smbcli_qfileinfo(cli->tree, fnum, NULL,
1513 &size, &c_time, &a_time,
1514 &m_time, NULL, NULL))) {
1515 printf("ERROR: qfileinfo passed with wrong vuid\n");
1519 if ( (cli->transport->error.etype != ETYPE_DOS) ||
1520 (cli->transport->error.e.dos.eclass != ERRSRV) ||
1521 (cli->transport->error.e.dos.ecode != ERRbaduid) ) {
1522 printf("ERROR: qfileinfo should have returned DOS error "
1523 "ERRSRV:ERRbaduid\n but returned %s\n",
1524 smbcli_errstr(cli->tree));
1528 cli->session->vuid -= 1234;
1530 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum))) {
1531 printf("close failed (%s)\n", smbcli_errstr(cli->tree));
1535 smbcli_unlink(cli->tree, fname);
1537 if (!torture_close_connection(cli)) {
1541 printf("vuid test finished\n");
1547 Test open mode returns on read-only files.
1549 static BOOL run_opentest(void)
1551 static struct smbcli_state *cli1;
1552 static struct smbcli_state *cli2;
1553 const char *fname = "\\readonly.file";
1557 BOOL correct = True;
1561 printf("starting open test\n");
1563 if (!torture_open_connection(&cli1)) {
1567 smbcli_setatr(cli1->tree, fname, 0, 0);
1568 smbcli_unlink(cli1->tree, fname);
1570 fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1572 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1576 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1577 printf("close2 failed (%s)\n", smbcli_errstr(cli1->tree));
1581 if (NT_STATUS_IS_ERR(smbcli_setatr(cli1->tree, fname, FILE_ATTRIBUTE_READONLY, 0))) {
1582 printf("smbcli_setatr failed (%s)\n", smbcli_errstr(cli1->tree));
1583 CHECK_MAX_FAILURES(error_test1);
1587 fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY, DENY_WRITE);
1589 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1590 CHECK_MAX_FAILURES(error_test1);
1594 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
1595 fnum2 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_ALL);
1597 if (check_error(__location__, cli1, ERRDOS, ERRnoaccess,
1598 NT_STATUS_ACCESS_DENIED)) {
1599 printf("correct error code ERRDOS/ERRnoaccess returned\n");
1602 printf("finished open test 1\n");
1604 smbcli_close(cli1->tree, fnum1);
1606 /* Now try not readonly and ensure ERRbadshare is returned. */
1608 smbcli_setatr(cli1->tree, fname, 0, 0);
1610 fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY, DENY_WRITE);
1612 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1616 /* This will fail - but the error should be ERRshare. */
1617 fnum2 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_ALL);
1619 if (check_error(__location__, cli1, ERRDOS, ERRbadshare,
1620 NT_STATUS_SHARING_VIOLATION)) {
1621 printf("correct error code ERRDOS/ERRbadshare returned\n");
1624 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1625 printf("close2 failed (%s)\n", smbcli_errstr(cli1->tree));
1629 smbcli_unlink(cli1->tree, fname);
1631 printf("finished open test 2\n");
1633 /* Test truncate open disposition on file opened for read. */
1635 fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1637 printf("(3) open (1) of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1641 /* write 20 bytes. */
1643 memset(buf, '\0', 20);
1645 if (smbcli_write(cli1->tree, fnum1, 0, buf, 0, 20) != 20) {
1646 printf("write failed (%s)\n", smbcli_errstr(cli1->tree));
1650 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1651 printf("(3) close1 failed (%s)\n", smbcli_errstr(cli1->tree));
1655 /* Ensure size == 20. */
1656 if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
1657 printf("(3) getatr failed (%s)\n", smbcli_errstr(cli1->tree));
1658 CHECK_MAX_FAILURES(error_test3);
1663 printf("(3) file size != 20\n");
1664 CHECK_MAX_FAILURES(error_test3);
1668 /* Now test if we can truncate a file opened for readonly. */
1670 fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY|O_TRUNC, DENY_NONE);
1672 printf("(3) open (2) of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1673 CHECK_MAX_FAILURES(error_test3);
1677 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1678 printf("close2 failed (%s)\n", smbcli_errstr(cli1->tree));
1682 /* Ensure size == 0. */
1683 if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
1684 printf("(3) getatr failed (%s)\n", smbcli_errstr(cli1->tree));
1685 CHECK_MAX_FAILURES(error_test3);
1690 printf("(3) file size != 0\n");
1691 CHECK_MAX_FAILURES(error_test3);
1694 printf("finished open test 3\n");
1696 smbcli_unlink(cli1->tree, fname);
1699 printf("testing ctemp\n");
1700 fnum1 = smbcli_ctemp(cli1->tree, "\\", &tmp_path);
1702 printf("ctemp failed (%s)\n", smbcli_errstr(cli1->tree));
1703 CHECK_MAX_FAILURES(error_test4);
1706 printf("ctemp gave path %s\n", tmp_path);
1707 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1708 printf("close of temp failed (%s)\n", smbcli_errstr(cli1->tree));
1710 if (NT_STATUS_IS_ERR(smbcli_unlink(cli1->tree, tmp_path))) {
1711 printf("unlink of temp failed (%s)\n", smbcli_errstr(cli1->tree));
1714 /* Test the non-io opens... */
1716 if (!torture_open_connection(&cli2)) {
1720 smbcli_setatr(cli2->tree, fname, 0, 0);
1721 smbcli_unlink(cli2->tree, fname);
1723 printf("TEST #1 testing 2 non-io opens (no delete)\n");
1725 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1726 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1729 printf("test 1 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1730 CHECK_MAX_FAILURES(error_test10);
1734 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1735 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1737 printf("test 1 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1738 CHECK_MAX_FAILURES(error_test10);
1742 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1743 printf("test 1 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1746 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1747 printf("test 1 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1751 printf("non-io open test #1 passed.\n");
1753 smbcli_unlink(cli1->tree, fname);
1755 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
1757 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1758 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1761 printf("test 2 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1762 CHECK_MAX_FAILURES(error_test20);
1766 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1767 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1770 printf("test 2 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1771 CHECK_MAX_FAILURES(error_test20);
1775 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1776 printf("test 1 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1779 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1780 printf("test 1 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1784 printf("non-io open test #2 passed.\n");
1786 smbcli_unlink(cli1->tree, fname);
1788 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
1790 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1791 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1794 printf("test 3 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1795 CHECK_MAX_FAILURES(error_test30);
1799 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1800 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1803 printf("test 3 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1804 CHECK_MAX_FAILURES(error_test30);
1808 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1809 printf("test 3 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1812 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1813 printf("test 3 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1817 printf("non-io open test #3 passed.\n");
1819 smbcli_unlink(cli1->tree, fname);
1821 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
1823 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1824 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1827 printf("test 4 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1828 CHECK_MAX_FAILURES(error_test40);
1832 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1833 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1836 printf("test 4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1837 CHECK_MAX_FAILURES(error_test40);
1841 printf("test 4 open 2 of %s gave %s (correct error should be %s)\n", fname, smbcli_errstr(cli2->tree), "sharing violation");
1843 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1844 printf("test 4 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1848 printf("non-io open test #4 passed.\n");
1850 smbcli_unlink(cli1->tree, fname);
1852 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
1854 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1855 NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1858 printf("test 5 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1859 CHECK_MAX_FAILURES(error_test50);
1863 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1864 NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1867 printf("test 5 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1868 CHECK_MAX_FAILURES(error_test50);
1872 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1873 printf("test 5 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1877 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1878 printf("test 5 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1882 printf("non-io open test #5 passed.\n");
1884 printf("TEST #6 testing 1 non-io open, one io open\n");
1886 smbcli_unlink(cli1->tree, fname);
1888 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SA_RIGHT_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
1889 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1892 printf("test 6 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1893 CHECK_MAX_FAILURES(error_test60);
1897 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1898 NTCREATEX_SHARE_ACCESS_READ, NTCREATEX_DISP_OPEN_IF, 0, 0);
1901 printf("test 6 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1902 CHECK_MAX_FAILURES(error_test60);
1906 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1907 printf("test 6 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1911 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1912 printf("test 6 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1916 printf("non-io open test #6 passed.\n");
1918 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
1920 smbcli_unlink(cli1->tree, fname);
1922 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SA_RIGHT_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
1923 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1926 printf("test 7 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1927 CHECK_MAX_FAILURES(error_test70);
1931 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1932 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1935 printf("test 7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1936 CHECK_MAX_FAILURES(error_test70);
1940 printf("test 7 open 2 of %s gave %s (correct error should be %s)\n", fname, smbcli_errstr(cli2->tree), "sharing violation");
1942 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1943 printf("test 7 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1947 printf("non-io open test #7 passed.\n");
1951 printf("TEST #8 testing one normal open, followed by lock, followed by open with truncate\n");
1953 smbcli_unlink(cli1->tree, fname);
1955 fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
1957 printf("(8) open (1) of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1961 /* write 20 bytes. */
1963 memset(buf, '\0', 20);
1965 if (smbcli_write(cli1->tree, fnum1, 0, buf, 0, 20) != 20) {
1966 printf("(8) write failed (%s)\n", smbcli_errstr(cli1->tree));
1970 /* Ensure size == 20. */
1971 if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
1972 printf("(8) getatr (1) failed (%s)\n", smbcli_errstr(cli1->tree));
1973 CHECK_MAX_FAILURES(error_test80);
1978 printf("(8) file size != 20\n");
1979 CHECK_MAX_FAILURES(error_test80);
1983 /* Get an exclusive lock on the open file. */
1984 if (NT_STATUS_IS_ERR(smbcli_lock(cli1->tree, fnum1, 0, 4, 0, WRITE_LOCK))) {
1985 printf("(8) lock1 failed (%s)\n", smbcli_errstr(cli1->tree));
1986 CHECK_MAX_FAILURES(error_test80);
1990 fnum2 = smbcli_open(cli1->tree, fname, O_RDWR|O_TRUNC, DENY_NONE);
1992 printf("(8) open (2) of %s with truncate failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1996 /* Ensure size == 0. */
1997 if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
1998 printf("(8) getatr (2) failed (%s)\n", smbcli_errstr(cli1->tree));
1999 CHECK_MAX_FAILURES(error_test80);
2004 printf("(8) file size != 0\n");
2005 CHECK_MAX_FAILURES(error_test80);
2009 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
2010 printf("(8) close1 failed (%s)\n", smbcli_errstr(cli1->tree));
2014 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum2))) {
2015 printf("(8) close1 failed (%s)\n", smbcli_errstr(cli1->tree));
2021 printf("open test #8 passed.\n");
2023 smbcli_unlink(cli1->tree, fname);
2025 if (!torture_close_connection(cli1)) {
2028 if (!torture_close_connection(cli2)) {
2037 sees what IOCTLs are supported
2039 BOOL torture_ioctl_test(void)
2041 struct smbcli_state *cli;
2042 uint16_t device, function;
2044 const char *fname = "\\ioctl.dat";
2046 union smb_ioctl parms;
2047 TALLOC_CTX *mem_ctx;
2049 if (!torture_open_connection(&cli)) {
2053 mem_ctx = talloc_init("ioctl_test");
2055 printf("starting ioctl test\n");
2057 smbcli_unlink(cli->tree, fname);
2059 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2061 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
2065 parms.ioctl.level = RAW_IOCTL_IOCTL;
2066 parms.ioctl.in.fnum = fnum;
2067 parms.ioctl.in.request = IOCTL_QUERY_JOB_INFO;
2068 status = smb_raw_ioctl(cli->tree, mem_ctx, &parms);
2069 printf("ioctl job info: %s\n", smbcli_errstr(cli->tree));
2071 for (device=0;device<0x100;device++) {
2072 printf("testing device=0x%x\n", device);
2073 for (function=0;function<0x100;function++) {
2074 parms.ioctl.in.request = (device << 16) | function;
2075 status = smb_raw_ioctl(cli->tree, mem_ctx, &parms);
2077 if (NT_STATUS_IS_OK(status)) {
2078 printf("ioctl device=0x%x function=0x%x OK : %d bytes\n",
2079 device, function, parms.ioctl.out.blob.length);
2084 if (!torture_close_connection(cli)) {
2093 tries variants of chkpath
2095 BOOL torture_chkpath_test(void)
2097 struct smbcli_state *cli;
2101 if (!torture_open_connection(&cli)) {
2105 printf("starting chkpath test\n");
2107 printf("Testing valid and invalid paths\n");
2109 /* cleanup from an old run */
2110 smbcli_rmdir(cli->tree, "\\chkpath.dir\\dir2");
2111 smbcli_unlink(cli->tree, "\\chkpath.dir\\*");
2112 smbcli_rmdir(cli->tree, "\\chkpath.dir");
2114 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, "\\chkpath.dir"))) {
2115 printf("mkdir1 failed : %s\n", smbcli_errstr(cli->tree));
2119 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, "\\chkpath.dir\\dir2"))) {
2120 printf("mkdir2 failed : %s\n", smbcli_errstr(cli->tree));
2124 fnum = smbcli_open(cli->tree, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2126 printf("open1 failed (%s)\n", smbcli_errstr(cli->tree));
2129 smbcli_close(cli->tree, fnum);
2131 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir"))) {
2132 printf("chkpath1 failed: %s\n", smbcli_errstr(cli->tree));
2136 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\dir2"))) {
2137 printf("chkpath2 failed: %s\n", smbcli_errstr(cli->tree));
2141 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\foo.txt"))) {
2142 ret = check_error(__location__, cli, ERRDOS, ERRbadpath,
2143 NT_STATUS_NOT_A_DIRECTORY);
2145 printf("* chkpath on a file should fail\n");
2149 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\bar.txt"))) {
2150 ret = check_error(__location__, cli, ERRDOS, ERRbadfile,
2151 NT_STATUS_OBJECT_NAME_NOT_FOUND);
2153 printf("* chkpath on a non existent file should fail\n");
2157 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\dirxx\\bar.txt"))) {
2158 ret = check_error(__location__, cli, ERRDOS, ERRbadpath,
2159 NT_STATUS_OBJECT_PATH_NOT_FOUND);
2161 printf("* chkpath on a non existent component should fail\n");
2165 smbcli_rmdir(cli->tree, "\\chkpath.dir\\dir2");
2166 smbcli_unlink(cli->tree, "\\chkpath.dir\\*");
2167 smbcli_rmdir(cli->tree, "\\chkpath.dir");
2169 if (!torture_close_connection(cli)) {
2178 parse a //server/share type UNC name
2180 static BOOL parse_unc(const char *unc_name, char **hostname, char **sharename)
2184 if (strncmp(unc_name, "//", 2)) {
2188 *hostname = strdup(&unc_name[2]);
2189 p = strchr_m(&(*hostname)[2],'/');
2194 *sharename = strdup(p+1);
2201 static void sigcont(int sig)
2205 double torture_create_procs(BOOL (*fn)(struct smbcli_state *, int), BOOL *result)
2208 volatile pid_t *child_status;
2209 volatile BOOL *child_status_out;
2212 double start_time_limit = 10 + (torture_nprocs * 1.5);
2213 char **unc_list = NULL;
2215 int num_unc_names = 0;
2220 signal(SIGCONT, sigcont);
2222 child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*torture_nprocs);
2223 if (!child_status) {
2224 printf("Failed to setup shared memory\n");
2228 child_status_out = (volatile BOOL *)shm_setup(sizeof(BOOL)*torture_nprocs);
2229 if (!child_status_out) {
2230 printf("Failed to setup result status shared memory\n");
2234 p = lp_parm_string(-1, "torture", "unclist");
2236 unc_list = file_lines_load(p, &num_unc_names);
2237 if (!unc_list || num_unc_names <= 0) {
2238 printf("Failed to load unc names list from '%s'\n", p);
2243 for (i = 0; i < torture_nprocs; i++) {
2244 child_status[i] = 0;
2245 child_status_out[i] = True;
2248 tv = timeval_current();
2250 for (i=0;i<torture_nprocs;i++) {
2254 char *hostname=NULL, *sharename;
2256 pid_t mypid = getpid();
2257 sys_srandom(((int)mypid) ^ ((int)time(NULL)));
2259 asprintf(&myname, "CLIENT%d", i);
2260 lp_set_cmdline("netbios name", myname);
2265 if (!parse_unc(unc_list[i % num_unc_names],
2266 &hostname, &sharename)) {
2267 printf("Failed to parse UNC name %s\n",
2268 unc_list[i % num_unc_names]);
2275 if (torture_open_connection_share(¤t_cli,
2280 } else if (torture_open_connection(¤t_cli)) {
2284 printf("pid %d failed to start\n", (int)getpid());
2290 child_status[i] = getpid();
2294 if (child_status[i]) {
2295 printf("Child %d failed to start!\n", i);
2296 child_status_out[i] = 1;
2300 child_status_out[i] = fn(current_cli, i);
2307 for (i=0;i<torture_nprocs;i++) {
2308 if (child_status[i]) synccount++;
2310 if (synccount == torture_nprocs) break;
2312 } while (timeval_elapsed(&tv) < start_time_limit);
2314 if (synccount != torture_nprocs) {
2315 printf("FAILED TO START %d CLIENTS (started %d)\n", torture_nprocs, synccount);
2317 return timeval_elapsed(&tv);
2320 printf("Starting %d clients\n", torture_nprocs);
2322 /* start the client load */
2323 tv = timeval_current();
2324 for (i=0;i<torture_nprocs;i++) {
2325 child_status[i] = 0;
2329 printf("%d clients started\n", torture_nprocs);
2331 for (i=0;i<torture_nprocs;i++) {
2333 while ((ret=sys_waitpid(0, &status, 0)) == -1 && errno == EINTR) /* noop */ ;
2334 if (ret == -1 || WEXITSTATUS(status) != 0) {
2341 for (i=0;i<torture_nprocs;i++) {
2342 if (!child_status_out[i]) {
2346 return timeval_elapsed(&tv);
2349 #define FLAG_MULTIPROC 1
2354 BOOL (*multi_fn)(struct smbcli_state *, int );
2357 {"BASE-FDPASS", run_fdpasstest, 0},
2358 {"BASE-LOCK1", torture_locktest1, 0},
2359 {"BASE-LOCK2", torture_locktest2, 0},
2360 {"BASE-LOCK3", torture_locktest3, 0},
2361 {"BASE-LOCK4", torture_locktest4, 0},
2362 {"BASE-LOCK5", torture_locktest5, 0},
2363 {"BASE-LOCK6", torture_locktest6, 0},
2364 {"BASE-LOCK7", torture_locktest7, 0},
2365 {"BASE-UNLINK", torture_unlinktest, 0},
2366 {"BASE-ATTR", run_attrtest, 0},
2367 {"BASE-TRANS2", run_trans2test, 0},
2368 {"BASE-NEGNOWAIT", run_negprot_nowait, 0},
2369 {"BASE-DIR1", torture_dirtest1, 0},
2370 {"BASE-DIR2", torture_dirtest2, 0},
2371 {"BASE-DENY1", torture_denytest1, 0},
2372 {"BASE-DENY2", torture_denytest2, 0},
2373 {"BASE-DENY3", torture_denytest3, 0},
2374 {"BASE-NTDENY1", NULL, torture_ntdenytest1},
2375 {"BASE-NTDENY2", torture_ntdenytest2, 0},
2376 {"BASE-TCON", run_tcon_test, 0},
2377 {"BASE-TCONDEV", run_tcon_devtype_test, 0},
2378 {"BASE-VUID", run_vuidtest, 0},
2379 {"BASE-RW1", run_readwritetest, 0},
2380 {"BASE-RW2", NULL, run_readwritemulti},
2381 {"BASE-OPEN", run_opentest, 0},
2382 {"BASE-DEFER_OPEN", NULL, run_deferopen},
2383 {"BASE-XCOPY", run_xcopy, 0},
2384 {"BASE-RENAME", torture_test_rename, 0},
2385 {"BASE-DELETE", torture_test_delete, 0},
2386 {"BASE-PROPERTIES", run_properties, 0},
2387 {"BASE-MANGLE", torture_mangle, 0},
2388 {"BASE-OPENATTR", torture_openattrtest, 0},
2389 {"BASE-CHARSET", torture_charset, 0},
2390 {"BASE-CHKPATH", torture_chkpath_test, 0},
2391 {"BASE-SECLEAK", torture_sec_leak, 0},
2393 /* benchmarking tests */
2394 {"BENCH-HOLDCON", torture_holdcon, 0},
2395 {"BENCH-NBENCH", torture_nbench, 0},
2396 {"BENCH-TORTURE", NULL, run_torture},
2399 {"RAW-QFSINFO", torture_raw_qfsinfo, 0},
2400 {"RAW-QFILEINFO", torture_raw_qfileinfo, 0},
2401 {"RAW-SFILEINFO", torture_raw_sfileinfo, 0},
2402 {"RAW-SFILEINFO-BUG", torture_raw_sfileinfo_bug, 0},
2403 {"RAW-SEARCH", torture_raw_search, 0},
2404 {"RAW-CLOSE", torture_raw_close, 0},
2405 {"RAW-OPEN", torture_raw_open, 0},
2406 {"RAW-MKDIR", torture_raw_mkdir, 0},
2407 {"RAW-OPLOCK", torture_raw_oplock, 0},
2408 {"RAW-NOTIFY", torture_raw_notify, 0},
2409 {"RAW-MUX", torture_raw_mux, 0},
2410 {"RAW-IOCTL", torture_raw_ioctl, 0},
2411 {"RAW-CHKPATH", torture_raw_chkpath, 0},
2412 {"RAW-UNLINK", torture_raw_unlink, 0},
2413 {"RAW-READ", torture_raw_read, 0},
2414 {"RAW-WRITE", torture_raw_write, 0},
2415 {"RAW-LOCK", torture_raw_lock, 0},
2416 {"RAW-CONTEXT", torture_raw_context, 0},
2417 {"RAW-RENAME", torture_raw_rename, 0},
2418 {"RAW-SEEK", torture_raw_seek, 0},
2419 {"RAW-RAP", torture_raw_rap, 0},
2421 /* protocol scanners */
2422 {"SCAN-TRANS2", torture_trans2_scan, 0},
2423 {"SCAN-NTTRANS", torture_nttrans_scan, 0},
2424 {"SCAN-ALIASES", torture_trans2_aliases, 0},
2425 {"SCAN-SMB", torture_smb_scan, 0},
2426 {"SCAN-MAXFID", NULL, run_maxfidtest},
2427 {"SCAN-UTABLE", torture_utable, 0},
2428 {"SCAN-CASETABLE", torture_casetable, 0},
2429 {"SCAN-PIPE_NUMBER", run_pipe_number, 0},
2430 {"SCAN-IOCTL", torture_ioctl_test, 0},
2433 {"RPC-LSA", torture_rpc_lsa, 0},
2434 {"RPC-ECHO", torture_rpc_echo, 0},
2435 {"RPC-DFS", torture_rpc_dfs, 0},
2436 {"RPC-SPOOLSS", torture_rpc_spoolss, 0},
2437 {"RPC-SAMR", torture_rpc_samr, 0},
2438 {"RPC-NETLOGON", torture_rpc_netlogon, 0},
2439 {"RPC-SCHANNEL", torture_rpc_schannel, 0},
2440 {"RPC-WKSSVC", torture_rpc_wkssvc, 0},
2441 {"RPC-SRVSVC", torture_rpc_srvsvc, 0},
2442 {"RPC-SVCCTL", torture_rpc_svcctl, 0},
2443 {"RPC-ATSVC", torture_rpc_atsvc, 0},
2444 {"RPC-EVENTLOG", torture_rpc_eventlog, 0},
2445 {"RPC-EPMAPPER", torture_rpc_epmapper, 0},
2446 {"RPC-WINREG", torture_rpc_winreg, 0},
2447 {"RPC-OXIDRESOLVE", torture_rpc_oxidresolve, 0},
2448 {"RPC-REMACT", torture_rpc_remact, 0},
2449 {"RPC-MGMT", torture_rpc_mgmt, 0},
2450 {"RPC-SCANNER", torture_rpc_scanner, 0},
2451 {"RPC-AUTOIDL", torture_rpc_autoidl, 0},
2452 {"RPC-COUNTCALLS", torture_rpc_countcalls, 0},
2453 {"RPC-MULTIBIND", torture_multi_bind, 0},
2454 {"RPC-DRSUAPI", torture_rpc_drsuapi, 0},
2456 /* Distributed COM testers */
2457 {"DCOM-SIMPLE", torture_dcom_simple, 0},
2459 /* local (no server) testers */
2460 {"LOCAL-NTLMSSP", torture_ntlmssp_self_check, 0},
2461 {"LOCAL-ICONV", torture_local_iconv, 0},
2462 {"LOCAL-TALLOC", torture_local_talloc, 0},
2463 {"LOCAL-MESSAGING", torture_local_messaging, 0},
2464 {"LOCAL-BINDING", torture_local_binding_string, 0},
2465 {"LOCAL-IDTREE", torture_local_idtree, 0},
2468 {"LDAP-BASIC", torture_ldap_basic, 0},
2474 /****************************************************************************
2475 run a specified test or "ALL"
2476 ****************************************************************************/
2477 static BOOL run_test(const char *name)
2481 BOOL matched = False;
2483 if (strequal(name,"ALL")) {
2484 for (i=0;torture_ops[i].name;i++) {
2485 if (!run_test(torture_ops[i].name)) {
2492 for (i=0;torture_ops[i].name;i++) {
2493 if (gen_fnmatch(name, torture_ops[i].name) == 0) {
2497 printf("Running %s\n", torture_ops[i].name);
2498 if (torture_ops[i].multi_fn) {
2500 t = torture_create_procs(torture_ops[i].multi_fn,
2504 printf("TEST %s FAILED!\n", torture_ops[i].name);
2508 struct timeval tv = timeval_current();
2509 if (!torture_ops[i].fn()) {
2511 printf("TEST %s FAILED!\n", torture_ops[i].name);
2513 t = timeval_elapsed(&tv);
2515 printf("%s took %g secs\n\n", torture_ops[i].name, t);
2520 printf("Unknown torture operation '%s'\n", name);
2527 static void parse_dns(const char *dns)
2529 char *userdn, *basedn, *secret;
2532 /* retrievieng the userdn */
2533 p = strchr_m(dns, '#');
2535 lp_set_cmdline("torture:ldap_userdn", "");
2536 lp_set_cmdline("torture:ldap_basedn", "");
2537 lp_set_cmdline("torture:ldap_secret", "");
2540 userdn = strndup(dns, p - dns);
2541 lp_set_cmdline("torture:ldap_userdn", userdn);
2543 /* retrieve the basedn */
2545 p = strchr_m(d, '#');
2547 lp_set_cmdline("torture:ldap_basedn", "");
2548 lp_set_cmdline("torture:ldap_secret", "");
2551 basedn = strndup(d, p - d);
2552 lp_set_cmdline("torture:ldap_basedn", basedn);
2554 /* retrieve the secret */
2557 lp_set_cmdline("torture:ldap_secret", "");
2561 lp_set_cmdline("torture:ldap_secret", secret);
2563 printf ("%s - %s - %s\n", userdn, basedn, secret);
2567 static void usage(poptContext pc)
2572 poptPrintUsage(pc, stdout, 0);
2575 printf("tests are:");
2576 for (i=0;torture_ops[i].name;i++) {
2577 if ((i%perline)==0) {
2580 printf("%s ", torture_ops[i].name);
2584 printf("default test is ALL\n");
2589 static BOOL is_binding_string(const char *binding_string)
2591 TALLOC_CTX *mem_ctx = talloc_init("is_binding_string");
2592 struct dcerpc_binding binding_struct;
2595 status = dcerpc_parse_binding(mem_ctx, binding_string, &binding_struct);
2597 talloc_destroy(mem_ctx);
2598 return NT_STATUS_IS_OK(status);
2601 /****************************************************************************
2603 ****************************************************************************/
2604 int main(int argc,char *argv[])
2608 BOOL correct = True;
2612 enum {OPT_LOADFILE=1000,OPT_UNCLIST,OPT_TIMELIMIT,OPT_DNS,OPT_DANGEROUS};
2613 struct poptOption long_options[] = {
2615 {"smb-ports", 'p', POPT_ARG_STRING, NULL, 0, "SMB ports", NULL},
2616 {"seed", 0, POPT_ARG_INT, &torture_seed, 0, "seed", NULL},
2617 {"num-progs", 0, POPT_ARG_INT, &torture_nprocs, 0, "num progs", NULL},
2618 {"num-ops", 0, POPT_ARG_INT, &torture_numops, 0, "num ops", NULL},
2619 {"entries", 0, POPT_ARG_INT, &torture_entries, 0, "entries", NULL},
2620 {"use-oplocks", 'L', POPT_ARG_NONE, &use_oplocks, 0, "use oplocks", NULL},
2621 {"show-all", 0, POPT_ARG_NONE, &torture_showall, 0, "show all", NULL},
2622 {"loadfile", 0, POPT_ARG_STRING, NULL, OPT_LOADFILE, "loadfile", NULL},
2623 {"unclist", 0, POPT_ARG_STRING, NULL, OPT_UNCLIST, "unclist", NULL},
2624 {"timelimit", 't', POPT_ARG_STRING, NULL, OPT_TIMELIMIT, "timelimit", NULL},
2625 {"failures", 'f', POPT_ARG_INT, &torture_failures, 0, "failures", NULL},
2626 {"parse-dns", 'D', POPT_ARG_STRING, NULL, OPT_DNS, "parse-dns", NULL},
2627 {"dangerous", 'X', POPT_ARG_NONE, NULL, OPT_DANGEROUS, "dangerous", NULL},
2629 POPT_COMMON_CONNECTION
2630 POPT_COMMON_CREDENTIALS
2635 smbtorture_init_subsystems;
2637 setup_logging("smbtorture", DEBUG_STDOUT);
2639 #ifdef HAVE_SETBUFFER
2640 setbuffer(stdout, NULL, 0);
2643 pc = poptGetContext("smbtorture", argc, (const char **) argv, long_options,
2644 POPT_CONTEXT_KEEP_FIRST);
2646 poptSetOtherOptionHelp(pc, "<binding>|<unc> TEST1 TEST2 ...");
2648 while((opt = poptGetNextOpt(pc)) != -1) {
2651 lp_set_cmdline("torture:loadfile", poptGetOptArg(pc));
2654 lp_set_cmdline("torture:unclist", poptGetOptArg(pc));
2657 lp_set_cmdline("torture:timelimit", poptGetOptArg(pc));
2660 parse_dns(poptGetOptArg(pc));
2663 lp_set_cmdline("torture:dangerous", "1");
2666 d_printf("Invalid option %s: %s\n",
2667 poptBadOption(pc, 0), poptStrerror(opt));
2673 lp_load(dyn_CONFIGFILE,True,False,False);
2675 if (torture_seed == 0) {
2676 torture_seed = time(NULL);
2678 printf("Using seed %d\n", torture_seed);
2679 srandom(torture_seed);
2681 argv_new = discard_const_p(char *, poptGetArgs(pc));
2684 for (i=0; i<argc; i++) {
2685 if (argv_new[i] == NULL) {
2696 for(p = argv_new[1]; *p; p++) {
2701 /* see if its a RPC transport specifier */
2702 if (is_binding_string(argv_new[1])) {
2703 lp_set_cmdline("torture:binding", argv_new[1]);
2705 char *binding = NULL;
2706 char *host = NULL, *share = NULL;
2708 if (!parse_unc(argv_new[1], &host, &share)) {
2709 d_printf("Invalid option: %s is not a valid torture target (share or binding string)\n\n", argv_new[1]);
2713 lp_set_cmdline("torture:host", host);
2714 lp_set_cmdline("torture:share", share);
2715 asprintf(&binding, "ncacn_np:%s", host);
2716 lp_set_cmdline("torture:binding", binding);
2719 if (!lp_parm_string(-1,"torture","username")) {
2720 lp_set_cmdline("torture:username", cmdline_get_username());
2722 if (!lp_parm_string(-1,"torture","userdomain")) {
2724 * backward compatibility
2725 * maybe we should remove this to make this consistent
2726 * for all cmdline tools
2729 if (strequal(lp_netbios_name(),cmdline_get_userdomain())) {
2730 cmdline_set_userdomain(lp_workgroup());
2732 lp_set_cmdline("torture:userdomain", cmdline_get_userdomain());
2734 if (!lp_parm_string(-1,"torture","password")) {
2735 lp_set_cmdline("torture:password", cmdline_get_userpassword());
2738 if (argc_new == 0) {
2739 printf("You must specify a test to run, or 'ALL'\n");
2741 for (i=2;i<argc_new;i++) {
2742 if (!run_test(argv_new[i])) {