2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1997-2003
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "lib/cmdline/popt_common.h"
23 #include "libcli/raw/libcliraw.h"
24 #include "system/time.h"
27 int torture_numops=100;
28 int torture_entries=1000;
29 int torture_failures=1;
31 static int procnum; /* records process count number when forking */
32 static struct smbcli_state *current_cli;
33 static BOOL use_oplocks;
34 static BOOL use_level_II_oplocks;
35 static BOOL use_kerberos;
37 BOOL torture_showall = False;
39 #define CHECK_MAX_FAILURES(label) do { if (++failures >= torture_failures) goto label; } while (0)
41 static struct smbcli_state *open_nbt_connection(void)
43 struct nmb_name called, calling;
44 struct smbcli_state *cli;
45 const char *host = lp_parm_string(-1, "torture", "host");
47 make_nmb_name(&calling, lp_netbios_name(), 0x0);
48 choose_called_name(&called, host, 0x20);
50 cli = smbcli_state_init(NULL);
52 printf("Failed initialize smbcli_struct to connect with %s\n", host);
56 if (!smbcli_socket_connect(cli, host)) {
57 printf("Failed to connect with %s\n", host);
61 cli->transport->socket->timeout = 120000; /* set a really long timeout (2 minutes) */
63 if (!smbcli_transport_establish(cli, &calling, &called)) {
65 * Well, that failed, try *SMBSERVER ...
66 * However, we must reconnect as well ...
68 if (!smbcli_socket_connect(cli, host)) {
69 printf("Failed to connect with %s\n", host);
73 make_nmb_name(&called, "*SMBSERVER", 0x20);
74 if (!smbcli_transport_establish(cli, &calling, &called)) {
75 printf("%s rejected the session\n",host);
76 printf("We tried with a called name of %s & %s\n",
86 BOOL torture_open_connection_share(struct smbcli_state **c,
88 const char *sharename)
93 const char *username = lp_parm_string(-1, "torture", "username");
94 const char *userdomain = lp_parm_string(-1, "torture", "userdomain");
95 const char *password = lp_parm_string(-1, "torture", "password");
98 flags |= SMBCLI_FULL_CONNECTION_USE_KERBEROS;
100 status = smbcli_full_connection(NULL,
101 c, lp_netbios_name(),
104 username, username[0]?userdomain:"",
105 password, flags, &retry);
106 if (!NT_STATUS_IS_OK(status)) {
107 printf("Failed to open connection - %s\n", nt_errstr(status));
111 (*c)->transport->options.use_oplocks = use_oplocks;
112 (*c)->transport->options.use_level2_oplocks = use_level_II_oplocks;
113 (*c)->transport->socket->timeout = 120000;
118 BOOL torture_open_connection(struct smbcli_state **c)
120 const char *host = lp_parm_string(-1, "torture", "host");
121 const char *share = lp_parm_string(-1, "torture", "share");
123 return torture_open_connection_share(c, host, share);
128 BOOL torture_close_connection(struct smbcli_state *c)
132 if (NT_STATUS_IS_ERR(smbcli_tdis(c))) {
133 printf("tdis failed (%s)\n", smbcli_errstr(c->tree));
141 /* open a rpc connection to the chosen binding string */
142 NTSTATUS torture_rpc_connection(struct dcerpc_pipe **p,
143 const char *pipe_name,
144 const char *pipe_uuid,
145 uint32_t pipe_version)
148 const char *binding = lp_parm_string(-1, "torture", "binding");
151 printf("You must specify a ncacn binding string\n");
152 return NT_STATUS_INVALID_PARAMETER;
155 status = dcerpc_pipe_connect(p, binding, pipe_uuid, pipe_version,
156 lp_parm_string(-1, "torture", "userdomain"),
157 lp_parm_string(-1, "torture", "username"),
158 lp_parm_string(-1, "torture", "password"));
163 /* open a rpc connection to a specific transport */
164 NTSTATUS torture_rpc_connection_transport(struct dcerpc_pipe **p,
165 const char *pipe_name,
166 const char *pipe_uuid,
167 uint32_t pipe_version,
168 enum dcerpc_transport_t transport)
171 const char *binding = lp_parm_string(-1, "torture", "binding");
172 struct dcerpc_binding b;
173 TALLOC_CTX *mem_ctx = talloc_init("torture_rpc_connection_smb");
176 printf("You must specify a ncacn binding string\n");
177 return NT_STATUS_INVALID_PARAMETER;
180 status = dcerpc_parse_binding(mem_ctx, binding, &b);
181 if (!NT_STATUS_IS_OK(status)) {
182 DEBUG(0,("Failed to parse dcerpc binding '%s'\n", binding));
183 talloc_destroy(mem_ctx);
187 b.transport = transport;
189 status = dcerpc_pipe_connect_b(p, &b, pipe_uuid, pipe_version,
190 lp_parm_string(-1, "torture", "userdomain"),
191 lp_parm_string(-1, "torture", "username"),
192 lp_parm_string(-1, "torture", "password"));
197 /* close a rpc connection to a named pipe */
198 NTSTATUS torture_rpc_close(struct dcerpc_pipe *p)
200 dcerpc_pipe_close(p);
205 /* check if the server produced the expected error code */
206 BOOL check_error(const char *location, struct smbcli_state *c,
207 uint8_t eclass, uint32_t ecode, NTSTATUS nterr)
209 if (smbcli_is_dos_error(c->tree)) {
213 /* Check DOS error */
215 smbcli_dos_error(c, &class, &num);
217 if (eclass != class || ecode != num) {
218 printf("unexpected error code class=%d code=%d\n",
219 (int)class, (int)num);
220 printf(" expected %d/%d %s (at %s)\n",
221 (int)eclass, (int)ecode, nt_errstr(nterr), location);
230 status = smbcli_nt_error(c->tree);
232 if (NT_STATUS_V(nterr) != NT_STATUS_V(status)) {
233 printf("unexpected error code %s\n", nt_errstr(status));
234 printf(" expected %s (at %s)\n", nt_errstr(nterr), location);
243 static BOOL wait_lock(struct smbcli_state *c, int fnum, uint32_t offset, uint32_t len)
245 while (NT_STATUS_IS_ERR(smbcli_lock(c->tree, fnum, offset, len, -1, WRITE_LOCK))) {
246 if (!check_error(__location__, c, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
252 static BOOL rw_torture(struct smbcli_state *c)
254 const char *lockfname = "\\torture.lck";
258 pid_t pid2, pid = getpid();
263 fnum2 = smbcli_open(c->tree, lockfname, O_RDWR | O_CREAT | O_EXCL,
266 fnum2 = smbcli_open(c->tree, lockfname, O_RDWR, DENY_NONE);
268 printf("open of %s failed (%s)\n", lockfname, smbcli_errstr(c->tree));
273 for (i=0;i<torture_numops;i++) {
274 uint_t n = (uint_t)sys_random()%10;
276 printf("%d\r", i); fflush(stdout);
278 asprintf(&fname, "\\torture.%u", n);
280 if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) {
284 fnum = smbcli_open(c->tree, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL);
286 printf("open failed (%s)\n", smbcli_errstr(c->tree));
291 if (smbcli_write(c->tree, fnum, 0, (char *)&pid, 0, sizeof(pid)) != sizeof(pid)) {
292 printf("write failed (%s)\n", smbcli_errstr(c->tree));
297 if (smbcli_write(c->tree, fnum, 0, (char *)buf,
298 sizeof(pid)+(j*sizeof(buf)),
299 sizeof(buf)) != sizeof(buf)) {
300 printf("write failed (%s)\n", smbcli_errstr(c->tree));
307 if (smbcli_read(c->tree, fnum, (char *)&pid2, 0, sizeof(pid)) != sizeof(pid)) {
308 printf("read failed (%s)\n", smbcli_errstr(c->tree));
313 printf("data corruption!\n");
317 if (NT_STATUS_IS_ERR(smbcli_close(c->tree, fnum))) {
318 printf("close failed (%s)\n", smbcli_errstr(c->tree));
322 if (NT_STATUS_IS_ERR(smbcli_unlink(c->tree, fname))) {
323 printf("unlink failed (%s)\n", smbcli_errstr(c->tree));
327 if (NT_STATUS_IS_ERR(smbcli_unlock(c->tree, fnum2, n*sizeof(int), sizeof(int)))) {
328 printf("unlock failed (%s)\n", smbcli_errstr(c->tree));
334 smbcli_close(c->tree, fnum2);
335 smbcli_unlink(c->tree, lockfname);
342 static BOOL run_torture(struct smbcli_state *cli, int dummy)
346 ret = rw_torture(cli);
348 if (!torture_close_connection(cli)) {
355 static BOOL rw_torture3(struct smbcli_state *c, const char *lockfname)
362 uint_t countprev = 0;
366 for (i = 0; i < sizeof(buf); i += sizeof(uint32_t))
368 SIVAL(buf, i, sys_random());
373 fnum = smbcli_open(c->tree, lockfname, O_RDWR | O_CREAT | O_EXCL,
376 printf("first open read/write of %s failed (%s)\n",
377 lockfname, smbcli_errstr(c->tree));
383 for (i = 0; i < 500 && fnum == -1; i++)
385 fnum = smbcli_open(c->tree, lockfname, O_RDONLY,
390 printf("second open read-only of %s failed (%s)\n",
391 lockfname, smbcli_errstr(c->tree));
397 for (count = 0; count < sizeof(buf); count += sent)
399 if (count >= countprev) {
400 printf("%d %8d\r", i, count);
403 countprev += (sizeof(buf) / 20);
408 sent = ((uint_t)sys_random()%(20))+ 1;
409 if (sent > sizeof(buf) - count)
411 sent = sizeof(buf) - count;
414 if (smbcli_write(c->tree, fnum, 0, buf+count, count, (size_t)sent) != sent) {
415 printf("write failed (%s)\n", smbcli_errstr(c->tree));
421 sent = smbcli_read(c->tree, fnum, buf_rd+count, count,
425 printf("read failed offset:%d size:%d (%s)\n",
426 count, sizeof(buf)-count,
427 smbcli_errstr(c->tree));
433 if (memcmp(buf_rd+count, buf+count, sent) != 0)
435 printf("read/write compare failed\n");
436 printf("offset: %d req %d recvd %d\n",
437 count, sizeof(buf)-count, sent);
446 if (NT_STATUS_IS_ERR(smbcli_close(c->tree, fnum))) {
447 printf("close failed (%s)\n", smbcli_errstr(c->tree));
454 static BOOL rw_torture2(struct smbcli_state *c1, struct smbcli_state *c2)
456 const char *lockfname = "\\torture2.lck";
461 uint8_t buf_rd[131072];
463 ssize_t bytes_read, bytes_written;
465 if (smbcli_deltree(c1->tree, lockfname) == -1) {
466 printf("unlink failed (%s)\n", smbcli_errstr(c1->tree));
469 fnum1 = smbcli_open(c1->tree, lockfname, O_RDWR | O_CREAT | O_EXCL,
472 printf("first open read/write of %s failed (%s)\n",
473 lockfname, smbcli_errstr(c1->tree));
476 fnum2 = smbcli_open(c2->tree, lockfname, O_RDONLY,
479 printf("second open read-only of %s failed (%s)\n",
480 lockfname, smbcli_errstr(c2->tree));
481 smbcli_close(c1->tree, fnum1);
485 printf("Checking data integrity over %d ops\n", torture_numops);
487 for (i=0;i<torture_numops;i++)
489 size_t buf_size = ((uint_t)sys_random()%(sizeof(buf)-1))+ 1;
491 printf("%d\r", i); fflush(stdout);
494 generate_random_buffer(buf, buf_size);
496 if ((bytes_written = smbcli_write(c1->tree, fnum1, 0, buf, 0, buf_size)) != buf_size) {
497 printf("write failed (%s)\n", smbcli_errstr(c1->tree));
498 printf("wrote %d, expected %d\n", bytes_written, buf_size);
503 if ((bytes_read = smbcli_read(c2->tree, fnum2, buf_rd, 0, buf_size)) != buf_size) {
504 printf("read failed (%s)\n", smbcli_errstr(c2->tree));
505 printf("read %d, expected %d\n", bytes_read, buf_size);
510 if (memcmp(buf_rd, buf, buf_size) != 0)
512 printf("read/write compare failed\n");
518 if (NT_STATUS_IS_ERR(smbcli_close(c2->tree, fnum2))) {
519 printf("close failed (%s)\n", smbcli_errstr(c2->tree));
522 if (NT_STATUS_IS_ERR(smbcli_close(c1->tree, fnum1))) {
523 printf("close failed (%s)\n", smbcli_errstr(c1->tree));
527 if (NT_STATUS_IS_ERR(smbcli_unlink(c1->tree, lockfname))) {
528 printf("unlink failed (%s)\n", smbcli_errstr(c1->tree));
535 static BOOL run_readwritetest(void)
537 struct smbcli_state *cli1, *cli2;
538 BOOL test1, test2 = True;
540 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
544 printf("starting readwritetest\n");
546 test1 = rw_torture2(cli1, cli2);
547 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1));
550 test2 = rw_torture2(cli1, cli1);
551 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2));
554 if (!torture_close_connection(cli1)) {
558 if (!torture_close_connection(cli2)) {
562 return (test1 && test2);
565 static BOOL run_readwritemulti(struct smbcli_state *cli, int dummy)
569 test = rw_torture3(cli, "\\multitest.txt");
571 if (!torture_close_connection(cli)) {
580 this checks to see if a secondary tconx can use open files from an
583 static BOOL run_tcon_test(void)
585 struct smbcli_state *cli;
586 const char *fname = "\\tcontest.tmp";
588 uint16_t cnum1, cnum2, cnum3;
589 uint16_t vuid1, vuid2;
592 struct smbcli_tree *tree1;
593 const char *host = lp_parm_string(-1, "torture", "host");
594 const char *share = lp_parm_string(-1, "torture", "share");
595 const char *password = lp_parm_string(-1, "torture", "password");
597 if (!torture_open_connection(&cli)) {
601 printf("starting tcontest\n");
603 if (smbcli_deltree(cli->tree, fname) == -1) {
604 printf("unlink of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
607 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
609 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
613 cnum1 = cli->tree->tid;
614 vuid1 = cli->session->vuid;
616 memset(&buf, 0, 4); /* init buf so valgrind won't complain */
617 if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) != 4) {
618 printf("initial write failed (%s)\n", smbcli_errstr(cli->tree));
622 tree1 = cli->tree; /* save old tree connection */
623 if (NT_STATUS_IS_ERR(smbcli_send_tconX(cli, share, "?????", password))) {
624 printf("%s refused 2nd tree connect (%s)\n", host,
625 smbcli_errstr(cli->tree));
626 smbcli_shutdown(cli);
630 cnum2 = cli->tree->tid;
631 cnum3 = MAX(cnum1, cnum2) + 1; /* any invalid number */
632 vuid2 = cli->session->vuid + 1;
634 /* try a write with the wrong tid */
635 cli->tree->tid = cnum2;
637 if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) == 4) {
638 printf("* server allows write with wrong TID\n");
641 printf("server fails write with wrong TID : %s\n", smbcli_errstr(cli->tree));
645 /* try a write with an invalid tid */
646 cli->tree->tid = cnum3;
648 if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) == 4) {
649 printf("* server allows write with invalid TID\n");
652 printf("server fails write with invalid TID : %s\n", smbcli_errstr(cli->tree));
655 /* try a write with an invalid vuid */
656 cli->session->vuid = vuid2;
657 cli->tree->tid = cnum1;
659 if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) == 4) {
660 printf("* server allows write with invalid VUID\n");
663 printf("server fails write with invalid VUID : %s\n", smbcli_errstr(cli->tree));
666 cli->session->vuid = vuid1;
667 cli->tree->tid = cnum1;
669 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum1))) {
670 printf("close failed (%s)\n", smbcli_errstr(cli->tree));
674 cli->tree->tid = cnum2;
676 if (NT_STATUS_IS_ERR(smbcli_tdis(cli))) {
677 printf("secondary tdis failed (%s)\n", smbcli_errstr(cli->tree));
681 cli->tree = tree1; /* restore initial tree */
682 cli->tree->tid = cnum1;
684 if (!torture_close_connection(cli)) {
693 static BOOL tcon_devtest(struct smbcli_state *cli,
694 const char *myshare, const char *devtype,
695 NTSTATUS expected_error)
699 const char *password = lp_parm_string(-1, "torture", "password");
701 status = NT_STATUS_IS_OK(smbcli_send_tconX(cli, myshare, devtype,
704 printf("Trying share %s with devtype %s\n", myshare, devtype);
706 if (NT_STATUS_IS_OK(expected_error)) {
710 printf("tconX to share %s with type %s "
711 "should have succeeded but failed\n",
718 printf("tconx to share %s with type %s "
719 "should have failed but succeeded\n",
723 if (NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),
727 printf("Returned unexpected error\n");
736 checks for correct tconX support
738 static BOOL run_tcon_devtype_test(void)
740 struct smbcli_state *cli1 = NULL;
745 const char *host = lp_parm_string(-1, "torture", "host");
746 const char *share = lp_parm_string(-1, "torture", "share");
747 const char *username = lp_parm_string(-1, "torture", "username");
748 const char *userdomain = lp_parm_string(-1, "torture", "userdomain");
749 const char *password = lp_parm_string(-1, "torture", "password");
751 status = smbcli_full_connection(NULL,
752 &cli1, lp_netbios_name(),
755 username, userdomain,
756 password, flags, &retry);
758 if (!NT_STATUS_IS_OK(status)) {
759 printf("could not open connection\n");
763 if (!tcon_devtest(cli1, "IPC$", "A:", NT_STATUS_BAD_DEVICE_TYPE))
766 if (!tcon_devtest(cli1, "IPC$", "?????", NT_STATUS_OK))
769 if (!tcon_devtest(cli1, "IPC$", "LPT:", NT_STATUS_BAD_DEVICE_TYPE))
772 if (!tcon_devtest(cli1, "IPC$", "IPC", NT_STATUS_OK))
775 if (!tcon_devtest(cli1, "IPC$", "FOOBA", NT_STATUS_BAD_DEVICE_TYPE))
778 if (!tcon_devtest(cli1, share, "A:", NT_STATUS_OK))
781 if (!tcon_devtest(cli1, share, "?????", NT_STATUS_OK))
784 if (!tcon_devtest(cli1, share, "LPT:", NT_STATUS_BAD_DEVICE_TYPE))
787 if (!tcon_devtest(cli1, share, "IPC", NT_STATUS_BAD_DEVICE_TYPE))
790 if (!tcon_devtest(cli1, share, "FOOBA", NT_STATUS_BAD_DEVICE_TYPE))
793 smbcli_shutdown(cli1);
796 printf("Passed tcondevtest\n");
803 test whether fnums and tids open on one VC are available on another (a major
806 static BOOL run_fdpasstest(void)
808 struct smbcli_state *cli1, *cli2;
809 const char *fname = "\\fdpass.tst";
813 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
817 printf("starting fdpasstest\n");
819 smbcli_unlink(cli1->tree, fname);
821 printf("Opening a file on connection 1\n");
823 fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
825 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
829 printf("writing to file on connection 1\n");
831 if (smbcli_write(cli1->tree, fnum1, 0, "hello world\n", 0, 13) != 13) {
832 printf("write failed (%s)\n", smbcli_errstr(cli1->tree));
836 oldtid = cli2->tree->tid;
837 cli2->session->vuid = cli1->session->vuid;
838 cli2->tree->tid = cli1->tree->tid;
839 cli2->session->pid = cli1->session->pid;
841 printf("reading from file on connection 2\n");
843 if (smbcli_read(cli2->tree, fnum1, buf, 0, 13) == 13) {
844 printf("read succeeded! nasty security hole [%s]\n",
849 smbcli_close(cli1->tree, fnum1);
850 smbcli_unlink(cli1->tree, fname);
852 cli2->tree->tid = oldtid;
854 torture_close_connection(cli1);
855 torture_close_connection(cli2);
857 printf("finished fdpasstest\n");
863 This test checks that
865 1) the server does not allow an unlink on a file that is open
867 static BOOL run_unlinktest(void)
869 struct smbcli_state *cli;
870 const char *fname = "\\unlink.tst";
874 if (!torture_open_connection(&cli)) {
878 printf("starting unlink test\n");
880 smbcli_unlink(cli->tree, fname);
882 cli->session->pid = 1;
884 printf("Opening a file\n");
886 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
888 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
892 printf("Unlinking a open file\n");
894 if (NT_STATUS_IS_OK(smbcli_unlink(cli->tree, fname))) {
895 printf("error: server allowed unlink on an open file\n");
898 correct = check_error(__location__, cli, ERRDOS, ERRbadshare,
899 NT_STATUS_SHARING_VIOLATION);
902 smbcli_close(cli->tree, fnum);
903 smbcli_unlink(cli->tree, fname);
905 if (!torture_close_connection(cli)) {
909 printf("unlink test finished\n");
916 test the timing of deferred open requests
918 static BOOL run_deferopen(struct smbcli_state *cli, int dummy)
920 const char *fname = "\\defer_open_test.dat";
926 printf("failed to connect\n");
930 printf("Testing deferred open requests.\n");
936 struct timeval tv_start, tv_end;
937 GetTimeOfDay(&tv_start);
938 fnum = smbcli_nt_create_full(cli->tree, fname, 0, GENERIC_RIGHTS_FILE_ALL_ACCESS,
939 FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_NONE,
940 NTCREATEX_DISP_OPEN_IF, 0, 0);
944 GetTimeOfDay(&tv_end);
945 if (NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),NT_STATUS_SHARING_VIOLATION)) {
946 /* Sharing violation errors need to be 1 second apart. */
947 int64_t tdif = usec_time_diff(&tv_end, &tv_start);
948 if (tdif < 500000 || tdif > 1500000) {
949 fprintf(stderr,"Timing incorrect %lld.%lld for share violation\n",
950 tdif / (int64_t)1000000,
951 tdif % (int64_t)1000000);
954 } while (NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),NT_STATUS_SHARING_VIOLATION));
957 fprintf(stderr,"Failed to open %s, error=%s\n", fname, smbcli_errstr(cli->tree));
961 printf("pid %u open %d\n", getpid(), i);
965 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum))) {
966 fprintf(stderr,"Failed to close %s, error=%s\n", fname, smbcli_errstr(cli->tree));
972 if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fname))) {
973 /* All until the last unlink will fail with sharing violation. */
974 if (!NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),NT_STATUS_SHARING_VIOLATION)) {
975 printf("unlink of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
980 printf("deferred test finished\n");
981 if (!torture_close_connection(cli)) {
988 test how many open files this server supports on the one socket
990 static BOOL run_maxfidtest(struct smbcli_state *cli, int dummy)
992 #define MAXFID_TEMPLATE "\\maxfid\\fid%d\\maxfid.%d.%d"
994 int fnums[0x11000], i;
995 int retries=4, maxfid;
999 printf("failed to connect\n");
1003 if (smbcli_deltree(cli->tree, "\\maxfid") == -1) {
1004 printf("Failed to deltree \\maxfid - %s\n",
1005 smbcli_errstr(cli->tree));
1008 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, "\\maxfid"))) {
1009 printf("Failed to mkdir \\maxfid, error=%s\n",
1010 smbcli_errstr(cli->tree));
1014 printf("Testing maximum number of open files\n");
1016 for (i=0; i<0x11000; i++) {
1017 if (i % 1000 == 0) {
1018 asprintf(&fname, "\\maxfid\\fid%d", i/1000);
1019 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, fname))) {
1020 printf("Failed to mkdir %s, error=%s\n",
1021 fname, smbcli_errstr(cli->tree));
1026 asprintf(&fname, MAXFID_TEMPLATE, i/1000, i,(int)getpid());
1027 if ((fnums[i] = smbcli_open(cli->tree, fname,
1028 O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) ==
1030 printf("open of %s failed (%s)\n",
1031 fname, smbcli_errstr(cli->tree));
1032 printf("maximum fnum is %d\n", i);
1043 printf("cleaning up\n");
1044 for (i=0;i<maxfid/2;i++) {
1045 asprintf(&fname, MAXFID_TEMPLATE, i/1000, i,(int)getpid());
1046 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnums[i]))) {
1047 printf("Close of fnum %d failed - %s\n", fnums[i], smbcli_errstr(cli->tree));
1049 if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fname))) {
1050 printf("unlink of %s failed (%s)\n",
1051 fname, smbcli_errstr(cli->tree));
1056 asprintf(&fname, MAXFID_TEMPLATE, (maxfid-i)/1000, maxfid-i,(int)getpid());
1057 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnums[maxfid-i]))) {
1058 printf("Close of fnum %d failed - %s\n", fnums[maxfid-i], smbcli_errstr(cli->tree));
1060 if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fname))) {
1061 printf("unlink of %s failed (%s)\n",
1062 fname, smbcli_errstr(cli->tree));
1067 printf("%6d %6d\r", i, maxfid-i);
1071 if (smbcli_deltree(cli->tree, "\\maxfid") == -1) {
1072 printf("Failed to deltree \\maxfid - %s\n",
1073 smbcli_errstr(cli->tree));
1077 printf("maxfid test finished\n");
1078 if (!torture_close_connection(cli)) {
1082 #undef MAXFID_TEMPLATE
1085 /* send smb negprot commands, not reading the response */
1086 static BOOL run_negprot_nowait(void)
1089 struct smbcli_state *cli, *cli2;
1090 BOOL correct = True;
1092 printf("starting negprot nowait test\n");
1094 cli = open_nbt_connection();
1099 printf("Filling send buffer\n");
1101 for (i=0;i<10000;i++) {
1102 struct smbcli_request *req;
1103 time_t t1 = time(NULL);
1104 req = smb_negprot_send(cli->transport, PROTOCOL_NT1);
1105 while (req->state == SMBCLI_REQUEST_SEND && time(NULL) < t1+5) {
1106 smbcli_transport_process(cli->transport);
1108 if (req->state == SMBCLI_REQUEST_ERROR) {
1109 printf("Failed to fill pipe - %s\n", nt_errstr(req->status));
1110 torture_close_connection(cli);
1113 if (req->state == SMBCLI_REQUEST_SEND) {
1119 printf("send buffer failed to fill\n");
1120 if (!torture_close_connection(cli)) {
1126 printf("send buffer filled after %d requests\n", i);
1128 printf("Opening secondary connection\n");
1129 if (!torture_open_connection(&cli2)) {
1133 if (!torture_close_connection(cli)) {
1137 if (!torture_close_connection(cli2)) {
1141 printf("finished negprot nowait test\n");
1148 This checks how the getatr calls works
1150 static BOOL run_attrtest(void)
1152 struct smbcli_state *cli;
1155 const char *fname = "\\attrib123456789.tst";
1156 BOOL correct = True;
1158 printf("starting attrib test\n");
1160 if (!torture_open_connection(&cli)) {
1164 smbcli_unlink(cli->tree, fname);
1165 fnum = smbcli_open(cli->tree, fname,
1166 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1167 smbcli_close(cli->tree, fnum);
1169 if (NT_STATUS_IS_ERR(smbcli_getatr(cli->tree, fname, NULL, NULL, &t))) {
1170 printf("getatr failed (%s)\n", smbcli_errstr(cli->tree));
1174 printf("New file time is %s", ctime(&t));
1176 if (abs(t - time(NULL)) > 60*60*24*10) {
1177 printf("ERROR: SMBgetatr bug. time is %s",
1183 t2 = t-60*60*24; /* 1 day ago */
1185 printf("Setting file time to %s", ctime(&t2));
1187 if (NT_STATUS_IS_ERR(smbcli_setatr(cli->tree, fname, 0, t2))) {
1188 printf("setatr failed (%s)\n", smbcli_errstr(cli->tree));
1192 if (NT_STATUS_IS_ERR(smbcli_getatr(cli->tree, fname, NULL, NULL, &t))) {
1193 printf("getatr failed (%s)\n", smbcli_errstr(cli->tree));
1197 printf("Retrieved file time as %s", ctime(&t));
1200 printf("ERROR: getatr/setatr bug. times are\n%s",
1202 printf("%s", ctime(&t2));
1206 smbcli_unlink(cli->tree, fname);
1208 if (!torture_close_connection(cli)) {
1212 printf("attrib test finished\n");
1219 This checks a couple of trans2 calls
1221 static BOOL run_trans2test(void)
1223 struct smbcli_state *cli;
1226 time_t c_time, a_time, m_time, w_time, m_time2;
1227 const char *fname = "\\trans2.tst";
1228 const char *dname = "\\trans2";
1229 const char *fname2 = "\\trans2\\trans2.tst";
1231 BOOL correct = True;
1233 printf("starting trans2 test\n");
1235 if (!torture_open_connection(&cli)) {
1239 smbcli_unlink(cli->tree, fname);
1241 printf("Testing qfileinfo\n");
1243 fnum = smbcli_open(cli->tree, fname,
1244 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1245 if (NT_STATUS_IS_ERR(smbcli_qfileinfo(cli->tree, fnum, NULL, &size, &c_time, &a_time, &m_time,
1247 printf("ERROR: qfileinfo failed (%s)\n", smbcli_errstr(cli->tree));
1251 printf("Testing NAME_INFO\n");
1253 if (NT_STATUS_IS_ERR(smbcli_qfilename(cli->tree, fnum, &pname))) {
1254 printf("ERROR: qfilename failed (%s)\n", smbcli_errstr(cli->tree));
1258 if (!pname || strcmp(pname, fname)) {
1259 printf("qfilename gave different name? [%s] [%s]\n",
1264 smbcli_close(cli->tree, fnum);
1265 smbcli_unlink(cli->tree, fname);
1267 fnum = smbcli_open(cli->tree, fname,
1268 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1270 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
1273 smbcli_close(cli->tree, fnum);
1275 printf("Checking for sticky create times\n");
1277 if (NT_STATUS_IS_ERR(smbcli_qpathinfo(cli->tree, fname, &c_time, &a_time, &m_time, &size, NULL))) {
1278 printf("ERROR: qpathinfo failed (%s)\n", smbcli_errstr(cli->tree));
1281 if (c_time != m_time) {
1282 printf("create time=%s", ctime(&c_time));
1283 printf("modify time=%s", ctime(&m_time));
1284 printf("This system appears to have sticky create times\n");
1286 if (a_time % (60*60) == 0) {
1287 printf("access time=%s", ctime(&a_time));
1288 printf("This system appears to set a midnight access time\n");
1292 if (abs(m_time - time(NULL)) > 60*60*24*7) {
1293 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
1299 smbcli_unlink(cli->tree, fname);
1300 fnum = smbcli_open(cli->tree, fname,
1301 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1302 smbcli_close(cli->tree, fnum);
1303 if (NT_STATUS_IS_ERR(smbcli_qpathinfo2(cli->tree, fname, &c_time, &a_time, &m_time, &w_time, &size, NULL, NULL))) {
1304 printf("ERROR: qpathinfo2 failed (%s)\n", smbcli_errstr(cli->tree));
1307 if (w_time < 60*60*24*2) {
1308 printf("write time=%s", ctime(&w_time));
1309 printf("This system appears to set a initial 0 write time\n");
1314 smbcli_unlink(cli->tree, fname);
1317 /* check if the server updates the directory modification time
1318 when creating a new file */
1319 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, dname))) {
1320 printf("ERROR: mkdir failed (%s)\n", smbcli_errstr(cli->tree));
1324 if (NT_STATUS_IS_ERR(smbcli_qpathinfo2(cli->tree, "\\trans2\\", &c_time, &a_time, &m_time, &w_time, &size, NULL, NULL))) {
1325 printf("ERROR: qpathinfo2 failed (%s)\n", smbcli_errstr(cli->tree));
1329 fnum = smbcli_open(cli->tree, fname2,
1330 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1331 smbcli_write(cli->tree, fnum, 0, (char *)&fnum, 0, sizeof(fnum));
1332 smbcli_close(cli->tree, fnum);
1333 if (NT_STATUS_IS_ERR(smbcli_qpathinfo2(cli->tree, "\\trans2\\", &c_time, &a_time, &m_time2, &w_time, &size, NULL, NULL))) {
1334 printf("ERROR: qpathinfo2 failed (%s)\n", smbcli_errstr(cli->tree));
1337 if (m_time2 == m_time) {
1338 printf("This system does not update directory modification times\n");
1342 smbcli_unlink(cli->tree, fname2);
1343 smbcli_rmdir(cli->tree, dname);
1345 if (!torture_close_connection(cli)) {
1349 printf("trans2 test finished\n");
1356 print out server properties
1358 static BOOL run_properties(void)
1360 struct smbcli_state *cli;
1361 BOOL correct = True;
1363 printf("starting properties test\n");
1367 if (!torture_open_connection(&cli)) {
1371 d_printf("Capabilities 0x%08x\n", cli->transport->negotiate.capabilities);
1373 if (!torture_close_connection(cli)) {
1382 /* FIRST_DESIRED_ACCESS 0xf019f */
1383 #define FIRST_DESIRED_ACCESS SA_RIGHT_FILE_READ_DATA|SA_RIGHT_FILE_WRITE_DATA|SA_RIGHT_FILE_APPEND_DATA|\
1384 SA_RIGHT_FILE_READ_EA| /* 0xf */ \
1385 SA_RIGHT_FILE_WRITE_EA|SA_RIGHT_FILE_READ_ATTRIBUTES| /* 0x90 */ \
1386 SA_RIGHT_FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
1387 STD_RIGHT_DELETE_ACCESS|STD_RIGHT_READ_CONTROL_ACCESS|\
1388 STD_RIGHT_WRITE_DAC_ACCESS|STD_RIGHT_WRITE_OWNER_ACCESS /* 0xf0000 */
1389 /* SECOND_DESIRED_ACCESS 0xe0080 */
1390 #define SECOND_DESIRED_ACCESS SA_RIGHT_FILE_READ_ATTRIBUTES| /* 0x80 */ \
1391 STD_RIGHT_READ_CONTROL_ACCESS|STD_RIGHT_WRITE_DAC_ACCESS|\
1392 STD_RIGHT_WRITE_OWNER_ACCESS /* 0xe0000 */
1395 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
1396 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
1397 SA_RIGHT_FILE_READ_DATA|\
1398 WRITE_OWNER_ACCESS /* */
1402 Test ntcreate calls made by xcopy
1404 static BOOL run_xcopy(void)
1406 struct smbcli_state *cli1;
1407 const char *fname = "\\test.txt";
1408 BOOL correct = True;
1411 printf("starting xcopy test\n");
1413 if (!torture_open_connection(&cli1)) {
1417 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0,
1418 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
1419 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF,
1423 printf("First open failed - %s\n", smbcli_errstr(cli1->tree));
1427 fnum2 = smbcli_nt_create_full(cli1->tree, fname, 0,
1428 SECOND_DESIRED_ACCESS, 0,
1429 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN,
1432 printf("second open failed - %s\n", smbcli_errstr(cli1->tree));
1436 if (!torture_close_connection(cli1)) {
1445 see how many RPC pipes we can open at once
1447 static BOOL run_pipe_number(void)
1449 struct smbcli_state *cli1;
1450 const char *pipe_name = "\\WKSSVC";
1454 printf("starting pipenumber test\n");
1455 if (!torture_open_connection(&cli1)) {
1460 fnum = smbcli_nt_create_full(cli1->tree, pipe_name, 0, SA_RIGHT_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
1461 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1464 printf("Open of pipe %s failed with error (%s)\n", pipe_name, smbcli_errstr(cli1->tree));
1468 printf("%d\r", num_pipes);
1472 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes, pipe_name );
1473 torture_close_connection(cli1);
1481 open N connections to the server and just hold them open
1482 used for testing performance when there are N idle users
1485 static BOOL torture_holdcon(void)
1488 struct smbcli_state **cli;
1491 printf("Opening %d connections\n", torture_numops);
1493 cli = malloc(sizeof(struct smbcli_state *) * torture_numops);
1495 for (i=0;i<torture_numops;i++) {
1496 if (!torture_open_connection(&cli[i])) {
1499 printf("opened %d connections\r", i);
1503 printf("\nStarting pings\n");
1506 for (i=0;i<torture_numops;i++) {
1509 status = smbcli_chkpath(cli[i]->tree, "\\");
1510 if (!NT_STATUS_IS_OK(status)) {
1511 printf("Connection %d is dead\n", i);
1519 if (num_dead == torture_numops) {
1520 printf("All connections dead - finishing\n");
1532 Try with a wrong vuid and check error message.
1535 static BOOL run_vuidtest(void)
1537 struct smbcli_state *cli;
1538 const char *fname = "\\vuid.tst";
1541 time_t c_time, a_time, m_time;
1542 BOOL correct = True;
1547 printf("starting vuid test\n");
1549 if (!torture_open_connection(&cli)) {
1553 smbcli_unlink(cli->tree, fname);
1555 fnum = smbcli_open(cli->tree, fname,
1556 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1558 orig_vuid = cli->session->vuid;
1560 cli->session->vuid += 1234;
1562 printf("Testing qfileinfo with wrong vuid\n");
1564 if (NT_STATUS_IS_OK(result = smbcli_qfileinfo(cli->tree, fnum, NULL,
1565 &size, &c_time, &a_time,
1566 &m_time, NULL, NULL))) {
1567 printf("ERROR: qfileinfo passed with wrong vuid\n");
1571 if ( (cli->transport->error.etype != ETYPE_DOS) ||
1572 (cli->transport->error.e.dos.eclass != ERRSRV) ||
1573 (cli->transport->error.e.dos.ecode != ERRbaduid) ) {
1574 printf("ERROR: qfileinfo should have returned DOS error "
1575 "ERRSRV:ERRbaduid\n but returned %s\n",
1576 smbcli_errstr(cli->tree));
1580 cli->session->vuid -= 1234;
1582 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum))) {
1583 printf("close failed (%s)\n", smbcli_errstr(cli->tree));
1587 smbcli_unlink(cli->tree, fname);
1589 if (!torture_close_connection(cli)) {
1593 printf("vuid test finished\n");
1599 Test open mode returns on read-only files.
1601 static BOOL run_opentest(void)
1603 static struct smbcli_state *cli1;
1604 static struct smbcli_state *cli2;
1605 const char *fname = "\\readonly.file";
1609 BOOL correct = True;
1613 printf("starting open test\n");
1615 if (!torture_open_connection(&cli1)) {
1619 smbcli_setatr(cli1->tree, fname, 0, 0);
1620 smbcli_unlink(cli1->tree, fname);
1622 fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1624 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1628 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1629 printf("close2 failed (%s)\n", smbcli_errstr(cli1->tree));
1633 if (NT_STATUS_IS_ERR(smbcli_setatr(cli1->tree, fname, FILE_ATTRIBUTE_READONLY, 0))) {
1634 printf("smbcli_setatr failed (%s)\n", smbcli_errstr(cli1->tree));
1635 CHECK_MAX_FAILURES(error_test1);
1639 fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY, DENY_WRITE);
1641 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1642 CHECK_MAX_FAILURES(error_test1);
1646 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
1647 fnum2 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_ALL);
1649 if (check_error(__location__, cli1, ERRDOS, ERRnoaccess,
1650 NT_STATUS_ACCESS_DENIED)) {
1651 printf("correct error code ERRDOS/ERRnoaccess returned\n");
1654 printf("finished open test 1\n");
1656 smbcli_close(cli1->tree, fnum1);
1658 /* Now try not readonly and ensure ERRbadshare is returned. */
1660 smbcli_setatr(cli1->tree, fname, 0, 0);
1662 fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY, DENY_WRITE);
1664 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1668 /* This will fail - but the error should be ERRshare. */
1669 fnum2 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_ALL);
1671 if (check_error(__location__, cli1, ERRDOS, ERRbadshare,
1672 NT_STATUS_SHARING_VIOLATION)) {
1673 printf("correct error code ERRDOS/ERRbadshare returned\n");
1676 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1677 printf("close2 failed (%s)\n", smbcli_errstr(cli1->tree));
1681 smbcli_unlink(cli1->tree, fname);
1683 printf("finished open test 2\n");
1685 /* Test truncate open disposition on file opened for read. */
1687 fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1689 printf("(3) open (1) of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1693 /* write 20 bytes. */
1695 memset(buf, '\0', 20);
1697 if (smbcli_write(cli1->tree, fnum1, 0, buf, 0, 20) != 20) {
1698 printf("write failed (%s)\n", smbcli_errstr(cli1->tree));
1702 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1703 printf("(3) close1 failed (%s)\n", smbcli_errstr(cli1->tree));
1707 /* Ensure size == 20. */
1708 if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
1709 printf("(3) getatr failed (%s)\n", smbcli_errstr(cli1->tree));
1710 CHECK_MAX_FAILURES(error_test3);
1715 printf("(3) file size != 20\n");
1716 CHECK_MAX_FAILURES(error_test3);
1720 /* Now test if we can truncate a file opened for readonly. */
1722 fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY|O_TRUNC, DENY_NONE);
1724 printf("(3) open (2) of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1725 CHECK_MAX_FAILURES(error_test3);
1729 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1730 printf("close2 failed (%s)\n", smbcli_errstr(cli1->tree));
1734 /* Ensure size == 0. */
1735 if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
1736 printf("(3) getatr failed (%s)\n", smbcli_errstr(cli1->tree));
1737 CHECK_MAX_FAILURES(error_test3);
1742 printf("(3) file size != 0\n");
1743 CHECK_MAX_FAILURES(error_test3);
1746 printf("finished open test 3\n");
1748 smbcli_unlink(cli1->tree, fname);
1751 printf("testing ctemp\n");
1752 fnum1 = smbcli_ctemp(cli1->tree, "\\", &tmp_path);
1754 printf("ctemp failed (%s)\n", smbcli_errstr(cli1->tree));
1755 CHECK_MAX_FAILURES(error_test4);
1758 printf("ctemp gave path %s\n", tmp_path);
1759 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1760 printf("close of temp failed (%s)\n", smbcli_errstr(cli1->tree));
1762 if (NT_STATUS_IS_ERR(smbcli_unlink(cli1->tree, tmp_path))) {
1763 printf("unlink of temp failed (%s)\n", smbcli_errstr(cli1->tree));
1766 /* Test the non-io opens... */
1768 if (!torture_open_connection(&cli2)) {
1772 smbcli_setatr(cli2->tree, fname, 0, 0);
1773 smbcli_unlink(cli2->tree, fname);
1775 printf("TEST #1 testing 2 non-io opens (no delete)\n");
1777 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1778 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1781 printf("test 1 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1782 CHECK_MAX_FAILURES(error_test10);
1786 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1787 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1789 printf("test 1 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1790 CHECK_MAX_FAILURES(error_test10);
1794 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1795 printf("test 1 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1798 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1799 printf("test 1 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1803 printf("non-io open test #1 passed.\n");
1805 smbcli_unlink(cli1->tree, fname);
1807 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
1809 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1810 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1813 printf("test 2 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1814 CHECK_MAX_FAILURES(error_test20);
1818 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1819 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1822 printf("test 2 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1823 CHECK_MAX_FAILURES(error_test20);
1827 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1828 printf("test 1 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1831 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1832 printf("test 1 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1836 printf("non-io open test #2 passed.\n");
1838 smbcli_unlink(cli1->tree, fname);
1840 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
1842 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1843 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1846 printf("test 3 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1847 CHECK_MAX_FAILURES(error_test30);
1851 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1852 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1855 printf("test 3 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1856 CHECK_MAX_FAILURES(error_test30);
1860 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1861 printf("test 3 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1864 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1865 printf("test 3 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1869 printf("non-io open test #3 passed.\n");
1871 smbcli_unlink(cli1->tree, fname);
1873 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
1875 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1876 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1879 printf("test 4 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1880 CHECK_MAX_FAILURES(error_test40);
1884 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1885 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1888 printf("test 4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1889 CHECK_MAX_FAILURES(error_test40);
1893 printf("test 4 open 2 of %s gave %s (correct error should be %s)\n", fname, smbcli_errstr(cli2->tree), "sharing violation");
1895 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1896 printf("test 4 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1900 printf("non-io open test #4 passed.\n");
1902 smbcli_unlink(cli1->tree, fname);
1904 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
1906 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1907 NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1910 printf("test 5 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1911 CHECK_MAX_FAILURES(error_test50);
1915 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1916 NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1919 printf("test 5 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1920 CHECK_MAX_FAILURES(error_test50);
1924 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1925 printf("test 5 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1929 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1930 printf("test 5 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1934 printf("non-io open test #5 passed.\n");
1936 printf("TEST #6 testing 1 non-io open, one io open\n");
1938 smbcli_unlink(cli1->tree, fname);
1940 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SA_RIGHT_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
1941 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1944 printf("test 6 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1945 CHECK_MAX_FAILURES(error_test60);
1949 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1950 NTCREATEX_SHARE_ACCESS_READ, NTCREATEX_DISP_OPEN_IF, 0, 0);
1953 printf("test 6 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1954 CHECK_MAX_FAILURES(error_test60);
1958 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1959 printf("test 6 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1963 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1964 printf("test 6 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1968 printf("non-io open test #6 passed.\n");
1970 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
1972 smbcli_unlink(cli1->tree, fname);
1974 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SA_RIGHT_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
1975 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1978 printf("test 7 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1979 CHECK_MAX_FAILURES(error_test70);
1983 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1984 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1987 printf("test 7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1988 CHECK_MAX_FAILURES(error_test70);
1992 printf("test 7 open 2 of %s gave %s (correct error should be %s)\n", fname, smbcli_errstr(cli2->tree), "sharing violation");
1994 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1995 printf("test 7 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1999 printf("non-io open test #7 passed.\n");
2003 printf("TEST #8 testing one normal open, followed by lock, followed by open with truncate\n");
2005 smbcli_unlink(cli1->tree, fname);
2007 fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
2009 printf("(8) open (1) of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
2013 /* write 20 bytes. */
2015 memset(buf, '\0', 20);
2017 if (smbcli_write(cli1->tree, fnum1, 0, buf, 0, 20) != 20) {
2018 printf("(8) write failed (%s)\n", smbcli_errstr(cli1->tree));
2022 /* Ensure size == 20. */
2023 if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
2024 printf("(8) getatr (1) failed (%s)\n", smbcli_errstr(cli1->tree));
2025 CHECK_MAX_FAILURES(error_test80);
2030 printf("(8) file size != 20\n");
2031 CHECK_MAX_FAILURES(error_test80);
2035 /* Get an exclusive lock on the open file. */
2036 if (NT_STATUS_IS_ERR(smbcli_lock(cli1->tree, fnum1, 0, 4, 0, WRITE_LOCK))) {
2037 printf("(8) lock1 failed (%s)\n", smbcli_errstr(cli1->tree));
2038 CHECK_MAX_FAILURES(error_test80);
2042 fnum2 = smbcli_open(cli1->tree, fname, O_RDWR|O_TRUNC, DENY_NONE);
2044 printf("(8) open (2) of %s with truncate failed (%s)\n", fname, smbcli_errstr(cli1->tree));
2048 /* Ensure size == 0. */
2049 if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
2050 printf("(8) getatr (2) failed (%s)\n", smbcli_errstr(cli1->tree));
2051 CHECK_MAX_FAILURES(error_test80);
2056 printf("(8) file size != 0\n");
2057 CHECK_MAX_FAILURES(error_test80);
2061 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
2062 printf("(8) close1 failed (%s)\n", smbcli_errstr(cli1->tree));
2066 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum2))) {
2067 printf("(8) close1 failed (%s)\n", smbcli_errstr(cli1->tree));
2073 printf("open test #8 passed.\n");
2075 smbcli_unlink(cli1->tree, fname);
2077 if (!torture_close_connection(cli1)) {
2080 if (!torture_close_connection(cli2)) {
2089 sees what IOCTLs are supported
2091 BOOL torture_ioctl_test(void)
2093 struct smbcli_state *cli;
2094 uint16_t device, function;
2096 const char *fname = "\\ioctl.dat";
2098 union smb_ioctl parms;
2099 TALLOC_CTX *mem_ctx;
2101 if (!torture_open_connection(&cli)) {
2105 mem_ctx = talloc_init("ioctl_test");
2107 printf("starting ioctl test\n");
2109 smbcli_unlink(cli->tree, fname);
2111 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2113 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
2117 parms.ioctl.level = RAW_IOCTL_IOCTL;
2118 parms.ioctl.in.fnum = fnum;
2119 parms.ioctl.in.request = IOCTL_QUERY_JOB_INFO;
2120 status = smb_raw_ioctl(cli->tree, mem_ctx, &parms);
2121 printf("ioctl job info: %s\n", smbcli_errstr(cli->tree));
2123 for (device=0;device<0x100;device++) {
2124 printf("testing device=0x%x\n", device);
2125 for (function=0;function<0x100;function++) {
2126 parms.ioctl.in.request = (device << 16) | function;
2127 status = smb_raw_ioctl(cli->tree, mem_ctx, &parms);
2129 if (NT_STATUS_IS_OK(status)) {
2130 printf("ioctl device=0x%x function=0x%x OK : %d bytes\n",
2131 device, function, parms.ioctl.out.blob.length);
2136 if (!torture_close_connection(cli)) {
2145 tries variants of chkpath
2147 BOOL torture_chkpath_test(void)
2149 struct smbcli_state *cli;
2153 if (!torture_open_connection(&cli)) {
2157 printf("starting chkpath test\n");
2159 printf("Testing valid and invalid paths\n");
2161 /* cleanup from an old run */
2162 smbcli_rmdir(cli->tree, "\\chkpath.dir\\dir2");
2163 smbcli_unlink(cli->tree, "\\chkpath.dir\\*");
2164 smbcli_rmdir(cli->tree, "\\chkpath.dir");
2166 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, "\\chkpath.dir"))) {
2167 printf("mkdir1 failed : %s\n", smbcli_errstr(cli->tree));
2171 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, "\\chkpath.dir\\dir2"))) {
2172 printf("mkdir2 failed : %s\n", smbcli_errstr(cli->tree));
2176 fnum = smbcli_open(cli->tree, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2178 printf("open1 failed (%s)\n", smbcli_errstr(cli->tree));
2181 smbcli_close(cli->tree, fnum);
2183 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir"))) {
2184 printf("chkpath1 failed: %s\n", smbcli_errstr(cli->tree));
2188 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\dir2"))) {
2189 printf("chkpath2 failed: %s\n", smbcli_errstr(cli->tree));
2193 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\foo.txt"))) {
2194 ret = check_error(__location__, cli, ERRDOS, ERRbadpath,
2195 NT_STATUS_NOT_A_DIRECTORY);
2197 printf("* chkpath on a file should fail\n");
2201 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\bar.txt"))) {
2202 ret = check_error(__location__, cli, ERRDOS, ERRbadfile,
2203 NT_STATUS_OBJECT_NAME_NOT_FOUND);
2205 printf("* chkpath on a non existent file should fail\n");
2209 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\dirxx\\bar.txt"))) {
2210 ret = check_error(__location__, cli, ERRDOS, ERRbadpath,
2211 NT_STATUS_OBJECT_PATH_NOT_FOUND);
2213 printf("* chkpath on a non existent component should fail\n");
2217 smbcli_rmdir(cli->tree, "\\chkpath.dir\\dir2");
2218 smbcli_unlink(cli->tree, "\\chkpath.dir\\*");
2219 smbcli_rmdir(cli->tree, "\\chkpath.dir");
2221 if (!torture_close_connection(cli)) {
2230 parse a //server/share type UNC name
2232 static BOOL parse_unc(const char *unc_name, char **hostname, char **sharename)
2236 if (strncmp(unc_name, "//", 2)) {
2240 *hostname = strdup(&unc_name[2]);
2241 p = strchr_m(&(*hostname)[2],'/');
2246 *sharename = strdup(p+1);
2253 static void sigcont(int sig)
2257 double torture_create_procs(BOOL (*fn)(struct smbcli_state *, int), BOOL *result)
2260 volatile pid_t *child_status;
2261 volatile BOOL *child_status_out;
2264 double start_time_limit = 10 + (torture_nprocs * 1.5);
2265 char **unc_list = NULL;
2267 int num_unc_names = 0;
2271 signal(SIGCONT, sigcont);
2273 child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*torture_nprocs);
2274 if (!child_status) {
2275 printf("Failed to setup shared memory\n");
2279 child_status_out = (volatile BOOL *)shm_setup(sizeof(BOOL)*torture_nprocs);
2280 if (!child_status_out) {
2281 printf("Failed to setup result status shared memory\n");
2285 p = lp_parm_string(-1, "torture", "unclist");
2287 unc_list = file_lines_load(p, &num_unc_names);
2288 if (!unc_list || num_unc_names <= 0) {
2289 printf("Failed to load unc names list from '%s'\n", p);
2294 for (i = 0; i < torture_nprocs; i++) {
2295 child_status[i] = 0;
2296 child_status_out[i] = True;
2301 for (i=0;i<torture_nprocs;i++) {
2305 char *hostname=NULL, *sharename;
2307 pid_t mypid = getpid();
2308 sys_srandom(((int)mypid) ^ ((int)time(NULL)));
2310 asprintf(&myname, "CLIENT%d", i);
2311 lp_set_cmdline("netbios name", myname);
2316 if (!parse_unc(unc_list[i % num_unc_names],
2317 &hostname, &sharename)) {
2318 printf("Failed to parse UNC name %s\n",
2319 unc_list[i % num_unc_names]);
2326 if (torture_open_connection_share(¤t_cli,
2331 } else if (torture_open_connection(¤t_cli)) {
2335 printf("pid %d failed to start\n", (int)getpid());
2341 child_status[i] = getpid();
2345 if (child_status[i]) {
2346 printf("Child %d failed to start!\n", i);
2347 child_status_out[i] = 1;
2351 child_status_out[i] = fn(current_cli, i);
2358 for (i=0;i<torture_nprocs;i++) {
2359 if (child_status[i]) synccount++;
2361 if (synccount == torture_nprocs) break;
2363 } while (end_timer() < start_time_limit);
2365 if (synccount != torture_nprocs) {
2366 printf("FAILED TO START %d CLIENTS (started %d)\n", torture_nprocs, synccount);
2371 printf("Starting %d clients\n", torture_nprocs);
2373 /* start the client load */
2375 for (i=0;i<torture_nprocs;i++) {
2376 child_status[i] = 0;
2380 printf("%d clients started\n", torture_nprocs);
2382 for (i=0;i<torture_nprocs;i++) {
2384 while ((ret=sys_waitpid(0, &status, 0)) == -1 && errno == EINTR) /* noop */ ;
2385 if (ret == -1 || WEXITSTATUS(status) != 0) {
2392 for (i=0;i<torture_nprocs;i++) {
2393 if (!child_status_out[i]) {
2400 #define FLAG_MULTIPROC 1
2405 BOOL (*multi_fn)(struct smbcli_state *, int );
2408 {"BASE-FDPASS", run_fdpasstest, 0},
2409 {"BASE-LOCK1", torture_locktest1, 0},
2410 {"BASE-LOCK2", torture_locktest2, 0},
2411 {"BASE-LOCK3", torture_locktest3, 0},
2412 {"BASE-LOCK4", torture_locktest4, 0},
2413 {"BASE-LOCK5", torture_locktest5, 0},
2414 {"BASE-LOCK6", torture_locktest6, 0},
2415 {"BASE-LOCK7", torture_locktest7, 0},
2416 {"BASE-UNLINK", run_unlinktest, 0},
2417 {"BASE-ATTR", run_attrtest, 0},
2418 {"BASE-TRANS2", run_trans2test, 0},
2419 {"BASE-NEGNOWAIT", run_negprot_nowait, 0},
2420 {"BASE-DIR1", torture_dirtest1, 0},
2421 {"BASE-DIR2", torture_dirtest2, 0},
2422 {"BASE-DENY1", torture_denytest1, 0},
2423 {"BASE-DENY2", torture_denytest2, 0},
2424 {"BASE-DENY3", torture_denytest3, 0},
2425 {"BASE-NTDENY1", NULL, torture_ntdenytest1},
2426 {"BASE-NTDENY2", torture_ntdenytest2, 0},
2427 {"BASE-TCON", run_tcon_test, 0},
2428 {"BASE-TCONDEV", run_tcon_devtype_test, 0},
2429 {"BASE-VUID", run_vuidtest, 0},
2430 {"BASE-RW1", run_readwritetest, 0},
2431 {"BASE-RW2", NULL, run_readwritemulti},
2432 {"BASE-OPEN", run_opentest, 0},
2433 {"BASE-DEFER_OPEN", NULL, run_deferopen},
2434 {"BASE-XCOPY", run_xcopy, 0},
2435 {"BASE-RENAME", torture_test_rename, 0},
2436 {"BASE-DELETE", torture_test_delete, 0},
2437 {"BASE-PROPERTIES", run_properties, 0},
2438 {"BASE-MANGLE", torture_mangle, 0},
2439 {"BASE-OPENATTR", torture_openattrtest, 0},
2440 {"BASE-CHARSET", torture_charset, 0},
2441 {"BASE-CHKPATH", torture_chkpath_test, 0},
2442 {"BASE-SECLEAK", torture_sec_leak, 0},
2444 /* benchmarking tests */
2445 {"BENCH-HOLDCON", torture_holdcon, 0},
2446 {"BENCH-NBENCH", torture_nbench, 0},
2447 {"BENCH-TORTURE", NULL, run_torture},
2450 {"RAW-QFSINFO", torture_raw_qfsinfo, 0},
2451 {"RAW-QFILEINFO", torture_raw_qfileinfo, 0},
2452 {"RAW-SFILEINFO", torture_raw_sfileinfo, 0},
2453 {"RAW-SFILEINFO-BUG", torture_raw_sfileinfo_bug, 0},
2454 {"RAW-SEARCH", torture_raw_search, 0},
2455 {"RAW-CLOSE", torture_raw_close, 0},
2456 {"RAW-OPEN", torture_raw_open, 0},
2457 {"RAW-MKDIR", torture_raw_mkdir, 0},
2458 {"RAW-OPLOCK", torture_raw_oplock, 0},
2459 {"RAW-NOTIFY", torture_raw_notify, 0},
2460 {"RAW-MUX", torture_raw_mux, 0},
2461 {"RAW-IOCTL", torture_raw_ioctl, 0},
2462 {"RAW-CHKPATH", torture_raw_chkpath, 0},
2463 {"RAW-UNLINK", torture_raw_unlink, 0},
2464 {"RAW-READ", torture_raw_read, 0},
2465 {"RAW-WRITE", torture_raw_write, 0},
2466 {"RAW-LOCK", torture_raw_lock, 0},
2467 {"RAW-CONTEXT", torture_raw_context, 0},
2468 {"RAW-RENAME", torture_raw_rename, 0},
2469 {"RAW-SEEK", torture_raw_seek, 0},
2470 {"RAW-RAP", torture_raw_rap, 0},
2472 /* protocol scanners */
2473 {"SCAN-TRANS2", torture_trans2_scan, 0},
2474 {"SCAN-NTTRANS", torture_nttrans_scan, 0},
2475 {"SCAN-ALIASES", torture_trans2_aliases, 0},
2476 {"SCAN-SMB", torture_smb_scan, 0},
2477 {"SCAN-MAXFID", NULL, run_maxfidtest},
2478 {"SCAN-UTABLE", torture_utable, 0},
2479 {"SCAN-CASETABLE", torture_casetable, 0},
2480 {"SCAN-PIPE_NUMBER", run_pipe_number, 0},
2481 {"SCAN-IOCTL", torture_ioctl_test, 0},
2484 {"RPC-LSA", torture_rpc_lsa, 0},
2485 {"RPC-ECHO", torture_rpc_echo, 0},
2486 {"RPC-DFS", torture_rpc_dfs, 0},
2487 {"RPC-SPOOLSS", torture_rpc_spoolss, 0},
2488 {"RPC-SAMR", torture_rpc_samr, 0},
2489 {"RPC-NETLOGON", torture_rpc_netlogon, 0},
2490 {"RPC-SCHANNEL", torture_rpc_schannel, 0},
2491 {"RPC-WKSSVC", torture_rpc_wkssvc, 0},
2492 {"RPC-SRVSVC", torture_rpc_srvsvc, 0},
2493 {"RPC-SVCCTL", torture_rpc_svcctl, 0},
2494 {"RPC-ATSVC", torture_rpc_atsvc, 0},
2495 {"RPC-EVENTLOG", torture_rpc_eventlog, 0},
2496 {"RPC-EPMAPPER", torture_rpc_epmapper, 0},
2497 {"RPC-WINREG", torture_rpc_winreg, 0},
2498 {"RPC-OXIDRESOLVE", torture_rpc_oxidresolve, 0},
2499 {"RPC-REMACT", torture_rpc_remact, 0},
2500 {"RPC-MGMT", torture_rpc_mgmt, 0},
2501 {"RPC-SCANNER", torture_rpc_scanner, 0},
2502 {"RPC-AUTOIDL", torture_rpc_autoidl, 0},
2503 {"RPC-COUNTCALLS", torture_rpc_countcalls, 0},
2504 {"RPC-MULTIBIND", torture_multi_bind, 0},
2505 {"RPC-DRSUAPI", torture_rpc_drsuapi, 0},
2507 /* local (no server) testers */
2508 {"LOCAL-NTLMSSP", torture_ntlmssp_self_check, 0},
2509 {"LOCAL-ICONV", torture_local_iconv, 0},
2510 {"LOCAL-TALLOC", torture_local_talloc, 0},
2511 {"LOCAL-MESSAGING", torture_local_messaging, 0},
2512 {"LOCAL-BINDING", torture_local_binding_string, 0},
2513 {"LOCAL-IDTREE", torture_local_idtree, 0},
2516 {"LDAP-BASIC", torture_ldap_basic, 0},
2522 /****************************************************************************
2523 run a specified test or "ALL"
2524 ****************************************************************************/
2525 static BOOL run_test(const char *name)
2529 BOOL matched = False;
2531 if (strequal(name,"ALL")) {
2532 for (i=0;torture_ops[i].name;i++) {
2533 if (!run_test(torture_ops[i].name)) {
2540 for (i=0;torture_ops[i].name;i++) {
2541 if (gen_fnmatch(name, torture_ops[i].name) == 0) {
2545 printf("Running %s\n", torture_ops[i].name);
2546 if (torture_ops[i].multi_fn) {
2548 t = torture_create_procs(torture_ops[i].multi_fn,
2552 printf("TEST %s FAILED!\n", torture_ops[i].name);
2557 if (!torture_ops[i].fn()) {
2559 printf("TEST %s FAILED!\n", torture_ops[i].name);
2563 printf("%s took %g secs\n\n", torture_ops[i].name, t);
2568 printf("Unknown torture operation '%s'\n", name);
2575 static void parse_dns(const char *dns)
2577 char *userdn, *basedn, *secret;
2580 /* retrievieng the userdn */
2581 p = strchr_m(dns, '#');
2583 lp_set_cmdline("torture:ldap_userdn", "");
2584 lp_set_cmdline("torture:ldap_basedn", "");
2585 lp_set_cmdline("torture:ldap_secret", "");
2588 userdn = strndup(dns, p - dns);
2589 lp_set_cmdline("torture:ldap_userdn", userdn);
2591 /* retrieve the basedn */
2593 p = strchr_m(d, '#');
2595 lp_set_cmdline("torture:ldap_basedn", "");
2596 lp_set_cmdline("torture:ldap_secret", "");
2599 basedn = strndup(d, p - d);
2600 lp_set_cmdline("torture:ldap_basedn", basedn);
2602 /* retrieve the secret */
2605 lp_set_cmdline("torture:ldap_secret", "");
2609 lp_set_cmdline("torture:ldap_secret", secret);
2611 printf ("%s - %s - %s\n", userdn, basedn, secret);
2615 static void usage(poptContext pc)
2620 poptPrintUsage(pc, stdout, 0);
2623 printf("tests are:");
2624 for (i=0;torture_ops[i].name;i++) {
2625 if ((i%perline)==0) {
2628 printf("%s ", torture_ops[i].name);
2632 printf("default test is ALL\n");
2637 static BOOL is_binding_string(const char *binding_string)
2639 TALLOC_CTX *mem_ctx = talloc_init("is_binding_string");
2640 struct dcerpc_binding binding_struct;
2643 status = dcerpc_parse_binding(mem_ctx, binding_string, &binding_struct);
2645 talloc_destroy(mem_ctx);
2646 return NT_STATUS_IS_OK(status);
2649 /****************************************************************************
2651 ****************************************************************************/
2652 int main(int argc,char *argv[])
2656 BOOL correct = True;
2660 enum {OPT_LOADFILE=1000,OPT_UNCLIST,OPT_TIMELIMIT,OPT_DNS,OPT_DANGEROUS};
2661 struct poptOption long_options[] = {
2663 {"smb-ports", 'p', POPT_ARG_STRING, NULL, 0, "SMB ports", NULL},
2664 {"seed", 0, POPT_ARG_INT, &torture_seed, 0, "seed", NULL},
2665 {"num-progs", 0, POPT_ARG_INT, &torture_nprocs, 0, "num progs", NULL},
2666 {"num-ops", 0, POPT_ARG_INT, &torture_numops, 0, "num ops", NULL},
2667 {"entries", 0, POPT_ARG_INT, &torture_entries, 0, "entries", NULL},
2668 {"use-oplocks", 'L', POPT_ARG_NONE, &use_oplocks, 0, "use oplocks", NULL},
2669 {"show-all", 0, POPT_ARG_NONE, &torture_showall, 0, "show all", NULL},
2670 {"loadfile", 0, POPT_ARG_STRING, NULL, OPT_LOADFILE, "loadfile", NULL},
2671 {"unclist", 0, POPT_ARG_STRING, NULL, OPT_UNCLIST, "unclist", NULL},
2672 {"timelimit", 't', POPT_ARG_STRING, NULL, OPT_TIMELIMIT, "timelimit", NULL},
2673 {"failures", 'f', POPT_ARG_INT, &torture_failures, 0, "failures", NULL},
2674 {"parse-dns", 'D', POPT_ARG_STRING, NULL, OPT_DNS, "parse-dns", NULL},
2675 {"dangerous", 'X', POPT_ARG_NONE, NULL, OPT_DANGEROUS, "dangerous", NULL},
2677 POPT_COMMON_CONNECTION
2678 POPT_COMMON_CREDENTIALS
2683 setup_logging("smbtorture", DEBUG_STDOUT);
2685 #ifdef HAVE_SETBUFFER
2686 setbuffer(stdout, NULL, 0);
2689 pc = poptGetContext("smbtorture", argc, (const char **) argv, long_options,
2690 POPT_CONTEXT_KEEP_FIRST);
2692 poptSetOtherOptionHelp(pc, "<binding>|<unc> TEST1 TEST2 ...");
2694 while((opt = poptGetNextOpt(pc)) != -1) {
2697 lp_set_cmdline("torture:loadfile", poptGetOptArg(pc));
2700 lp_set_cmdline("torture:unclist", poptGetOptArg(pc));
2703 lp_set_cmdline("torture:timelimit", poptGetOptArg(pc));
2706 parse_dns(poptGetOptArg(pc));
2709 lp_set_cmdline("torture:dangerous", "1");
2712 d_printf("Invalid option %s: %s\n",
2713 poptBadOption(pc, 0), poptStrerror(opt));
2719 lp_load(dyn_CONFIGFILE,True,False,False);
2721 if (torture_seed == 0) {
2722 torture_seed = time(NULL);
2724 printf("Using seed %d\n", torture_seed);
2725 srandom(torture_seed);
2727 argv_new = discard_const_p(char *, poptGetArgs(pc));
2730 for (i=0; i<argc; i++) {
2731 if (argv_new[i] == NULL) {
2742 for(p = argv_new[1]; *p; p++) {
2747 /* see if its a RPC transport specifier */
2748 if (is_binding_string(argv_new[1])) {
2749 lp_set_cmdline("torture:binding", argv_new[1]);
2751 char *binding = NULL;
2752 char *host = NULL, *share = NULL;
2754 if (!parse_unc(argv_new[1], &host, &share)) {
2755 d_printf("Invalid option: %s is not a valid torture target (share or binding string)\n\n", argv_new[1]);
2759 lp_set_cmdline("torture:host", host);
2760 lp_set_cmdline("torture:share", share);
2761 asprintf(&binding, "ncacn_np:%s", host);
2762 lp_set_cmdline("torture:binding", binding);
2765 if (!lp_parm_string(-1,"torture","username")) {
2766 lp_set_cmdline("torture:username", cmdline_get_username());
2768 if (!lp_parm_string(-1,"torture","userdomain")) {
2770 * backward compatibility
2771 * maybe we should remove this to make this consistent
2772 * for all cmdline tools
2775 if (strequal(lp_netbios_name(),cmdline_get_userdomain())) {
2776 cmdline_set_userdomain(lp_workgroup());
2778 lp_set_cmdline("torture:userdomain", cmdline_get_userdomain());
2780 if (!lp_parm_string(-1,"torture","password")) {
2781 lp_set_cmdline("torture:password", cmdline_get_userpassword());
2784 if (argc_new == 0) {
2785 printf("You must specify a test to run, or 'ALL'\n");
2787 for (i=2;i<argc_new;i++) {
2788 if (!run_test(argv_new[i])) {