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 "libcli/raw/libcliraw.h"
25 int torture_numops=100;
26 int torture_entries=1000;
27 int torture_failures=1;
29 static int procnum; /* records process count number when forking */
30 static struct smbcli_state *current_cli;
31 static BOOL use_oplocks;
32 static BOOL use_level_II_oplocks;
33 static BOOL use_kerberos;
35 BOOL torture_showall = False;
37 #define CHECK_MAX_FAILURES(label) do { if (++failures >= torture_failures) goto label; } while (0)
39 static struct smbcli_state *open_nbt_connection(void)
41 struct nmb_name called, calling;
42 struct smbcli_state *cli;
43 const char *host = lp_parm_string(-1, "torture", "host");
45 make_nmb_name(&calling, lp_netbios_name(), 0x0);
46 choose_called_name(&called, host, 0x20);
48 cli = smbcli_state_init(NULL);
50 printf("Failed initialize smbcli_struct to connect with %s\n", host);
54 if (!smbcli_socket_connect(cli, host)) {
55 printf("Failed to connect with %s\n", host);
59 cli->transport->socket->timeout = 120000; /* set a really long timeout (2 minutes) */
61 if (!smbcli_transport_establish(cli, &calling, &called)) {
63 * Well, that failed, try *SMBSERVER ...
64 * However, we must reconnect as well ...
66 if (!smbcli_socket_connect(cli, host)) {
67 printf("Failed to connect with %s\n", host);
71 make_nmb_name(&called, "*SMBSERVER", 0x20);
72 if (!smbcli_transport_establish(cli, &calling, &called)) {
73 printf("%s rejected the session\n",host);
74 printf("We tried with a called name of %s & %s\n",
84 BOOL torture_open_connection_share(struct smbcli_state **c,
86 const char *sharename)
91 const char *username = lp_parm_string(-1, "torture", "username");
92 const char *userdomain = lp_parm_string(-1, "torture", "userdomain");
93 const char *password = lp_parm_string(-1, "torture", "password");
96 flags |= SMBCLI_FULL_CONNECTION_USE_KERBEROS;
98 status = smbcli_full_connection(NULL,
102 username, username[0]?userdomain:"",
103 password, flags, &retry);
104 if (!NT_STATUS_IS_OK(status)) {
105 printf("Failed to open connection - %s\n", nt_errstr(status));
109 (*c)->transport->options.use_oplocks = use_oplocks;
110 (*c)->transport->options.use_level2_oplocks = use_level_II_oplocks;
111 (*c)->transport->socket->timeout = 120000;
116 BOOL torture_open_connection(struct smbcli_state **c)
118 const char *host = lp_parm_string(-1, "torture", "host");
119 const char *share = lp_parm_string(-1, "torture", "share");
121 return torture_open_connection_share(c, host, share);
126 BOOL torture_close_connection(struct smbcli_state *c)
130 if (NT_STATUS_IS_ERR(smbcli_tdis(c))) {
131 printf("tdis failed (%s)\n", smbcli_errstr(c->tree));
139 /* open a rpc connection to the chosen binding string */
140 NTSTATUS torture_rpc_connection(struct dcerpc_pipe **p,
141 const char *pipe_name,
142 const char *pipe_uuid,
143 uint32_t pipe_version)
146 const char *binding = lp_parm_string(-1, "torture", "binding");
149 printf("You must specify a ncacn binding string\n");
150 return NT_STATUS_INVALID_PARAMETER;
153 status = dcerpc_pipe_connect(p, binding, pipe_uuid, pipe_version,
154 lp_parm_string(-1, "torture", "userdomain"),
155 lp_parm_string(-1, "torture", "username"),
156 lp_parm_string(-1, "torture", "password"));
161 /* open a rpc connection to a specific transport */
162 NTSTATUS torture_rpc_connection_transport(struct dcerpc_pipe **p,
163 const char *pipe_name,
164 const char *pipe_uuid,
165 uint32_t pipe_version,
166 enum dcerpc_transport_t transport)
169 const char *binding = lp_parm_string(-1, "torture", "binding");
170 struct dcerpc_binding b;
171 TALLOC_CTX *mem_ctx = talloc_init("torture_rpc_connection_smb");
174 printf("You must specify a ncacn binding string\n");
175 return NT_STATUS_INVALID_PARAMETER;
178 status = dcerpc_parse_binding(mem_ctx, binding, &b);
179 if (!NT_STATUS_IS_OK(status)) {
180 DEBUG(0,("Failed to parse dcerpc binding '%s'\n", binding));
181 talloc_destroy(mem_ctx);
185 b.transport = transport;
187 status = dcerpc_pipe_connect_b(p, &b, pipe_uuid, pipe_version,
188 lp_parm_string(-1, "torture", "userdomain"),
189 lp_parm_string(-1, "torture", "username"),
190 lp_parm_string(-1, "torture", "password"));
195 /* close a rpc connection to a named pipe */
196 NTSTATUS torture_rpc_close(struct dcerpc_pipe *p)
198 dcerpc_pipe_close(p);
203 /* check if the server produced the expected error code */
204 BOOL check_error(const char *location, struct smbcli_state *c,
205 uint8_t eclass, uint32_t ecode, NTSTATUS nterr)
207 if (smbcli_is_dos_error(c->tree)) {
211 /* Check DOS error */
213 smbcli_dos_error(c, &class, &num);
215 if (eclass != class || ecode != num) {
216 printf("unexpected error code class=%d code=%d\n",
217 (int)class, (int)num);
218 printf(" expected %d/%d %s (at %s)\n",
219 (int)eclass, (int)ecode, nt_errstr(nterr), location);
228 status = smbcli_nt_error(c->tree);
230 if (NT_STATUS_V(nterr) != NT_STATUS_V(status)) {
231 printf("unexpected error code %s\n", nt_errstr(status));
232 printf(" expected %s (at %s)\n", nt_errstr(nterr), location);
241 static BOOL wait_lock(struct smbcli_state *c, int fnum, uint32_t offset, uint32_t len)
243 while (NT_STATUS_IS_ERR(smbcli_lock(c->tree, fnum, offset, len, -1, WRITE_LOCK))) {
244 if (!check_error(__location__, c, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
250 static BOOL rw_torture(struct smbcli_state *c)
252 const char *lockfname = "\\torture.lck";
256 pid_t pid2, pid = getpid();
261 fnum2 = smbcli_open(c->tree, lockfname, O_RDWR | O_CREAT | O_EXCL,
264 fnum2 = smbcli_open(c->tree, lockfname, O_RDWR, DENY_NONE);
266 printf("open of %s failed (%s)\n", lockfname, smbcli_errstr(c->tree));
271 for (i=0;i<torture_numops;i++) {
272 uint_t n = (uint_t)sys_random()%10;
274 printf("%d\r", i); fflush(stdout);
276 asprintf(&fname, "\\torture.%u", n);
278 if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) {
282 fnum = smbcli_open(c->tree, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL);
284 printf("open failed (%s)\n", smbcli_errstr(c->tree));
289 if (smbcli_write(c->tree, fnum, 0, (char *)&pid, 0, sizeof(pid)) != sizeof(pid)) {
290 printf("write failed (%s)\n", smbcli_errstr(c->tree));
295 if (smbcli_write(c->tree, fnum, 0, (char *)buf,
296 sizeof(pid)+(j*sizeof(buf)),
297 sizeof(buf)) != sizeof(buf)) {
298 printf("write failed (%s)\n", smbcli_errstr(c->tree));
305 if (smbcli_read(c->tree, fnum, (char *)&pid2, 0, sizeof(pid)) != sizeof(pid)) {
306 printf("read failed (%s)\n", smbcli_errstr(c->tree));
311 printf("data corruption!\n");
315 if (NT_STATUS_IS_ERR(smbcli_close(c->tree, fnum))) {
316 printf("close failed (%s)\n", smbcli_errstr(c->tree));
320 if (NT_STATUS_IS_ERR(smbcli_unlink(c->tree, fname))) {
321 printf("unlink failed (%s)\n", smbcli_errstr(c->tree));
325 if (NT_STATUS_IS_ERR(smbcli_unlock(c->tree, fnum2, n*sizeof(int), sizeof(int)))) {
326 printf("unlock failed (%s)\n", smbcli_errstr(c->tree));
332 smbcli_close(c->tree, fnum2);
333 smbcli_unlink(c->tree, lockfname);
340 static BOOL run_torture(struct smbcli_state *cli, int dummy)
344 ret = rw_torture(cli);
346 if (!torture_close_connection(cli)) {
353 static BOOL rw_torture3(struct smbcli_state *c, const char *lockfname)
360 uint_t countprev = 0;
364 for (i = 0; i < sizeof(buf); i += sizeof(uint32_t))
366 SIVAL(buf, i, sys_random());
371 fnum = smbcli_open(c->tree, lockfname, O_RDWR | O_CREAT | O_EXCL,
374 printf("first open read/write of %s failed (%s)\n",
375 lockfname, smbcli_errstr(c->tree));
381 for (i = 0; i < 500 && fnum == -1; i++)
383 fnum = smbcli_open(c->tree, lockfname, O_RDONLY,
388 printf("second open read-only of %s failed (%s)\n",
389 lockfname, smbcli_errstr(c->tree));
395 for (count = 0; count < sizeof(buf); count += sent)
397 if (count >= countprev) {
398 printf("%d %8d\r", i, count);
401 countprev += (sizeof(buf) / 20);
406 sent = ((uint_t)sys_random()%(20))+ 1;
407 if (sent > sizeof(buf) - count)
409 sent = sizeof(buf) - count;
412 if (smbcli_write(c->tree, fnum, 0, buf+count, count, (size_t)sent) != sent) {
413 printf("write failed (%s)\n", smbcli_errstr(c->tree));
419 sent = smbcli_read(c->tree, fnum, buf_rd+count, count,
423 printf("read failed offset:%d size:%d (%s)\n",
424 count, sizeof(buf)-count,
425 smbcli_errstr(c->tree));
431 if (memcmp(buf_rd+count, buf+count, sent) != 0)
433 printf("read/write compare failed\n");
434 printf("offset: %d req %d recvd %d\n",
435 count, sizeof(buf)-count, sent);
444 if (NT_STATUS_IS_ERR(smbcli_close(c->tree, fnum))) {
445 printf("close failed (%s)\n", smbcli_errstr(c->tree));
452 static BOOL rw_torture2(struct smbcli_state *c1, struct smbcli_state *c2)
454 const char *lockfname = "\\torture2.lck";
459 uint8_t buf_rd[131072];
461 ssize_t bytes_read, bytes_written;
463 if (smbcli_deltree(c1->tree, lockfname) == -1) {
464 printf("unlink failed (%s)\n", smbcli_errstr(c1->tree));
467 fnum1 = smbcli_open(c1->tree, lockfname, O_RDWR | O_CREAT | O_EXCL,
470 printf("first open read/write of %s failed (%s)\n",
471 lockfname, smbcli_errstr(c1->tree));
474 fnum2 = smbcli_open(c2->tree, lockfname, O_RDONLY,
477 printf("second open read-only of %s failed (%s)\n",
478 lockfname, smbcli_errstr(c2->tree));
479 smbcli_close(c1->tree, fnum1);
483 printf("Checking data integrity over %d ops\n", torture_numops);
485 for (i=0;i<torture_numops;i++)
487 size_t buf_size = ((uint_t)sys_random()%(sizeof(buf)-1))+ 1;
489 printf("%d\r", i); fflush(stdout);
492 generate_random_buffer(buf, buf_size);
494 if ((bytes_written = smbcli_write(c1->tree, fnum1, 0, buf, 0, buf_size)) != buf_size) {
495 printf("write failed (%s)\n", smbcli_errstr(c1->tree));
496 printf("wrote %d, expected %d\n", bytes_written, buf_size);
501 if ((bytes_read = smbcli_read(c2->tree, fnum2, buf_rd, 0, buf_size)) != buf_size) {
502 printf("read failed (%s)\n", smbcli_errstr(c2->tree));
503 printf("read %d, expected %d\n", bytes_read, buf_size);
508 if (memcmp(buf_rd, buf, buf_size) != 0)
510 printf("read/write compare failed\n");
516 if (NT_STATUS_IS_ERR(smbcli_close(c2->tree, fnum2))) {
517 printf("close failed (%s)\n", smbcli_errstr(c2->tree));
520 if (NT_STATUS_IS_ERR(smbcli_close(c1->tree, fnum1))) {
521 printf("close failed (%s)\n", smbcli_errstr(c1->tree));
525 if (NT_STATUS_IS_ERR(smbcli_unlink(c1->tree, lockfname))) {
526 printf("unlink failed (%s)\n", smbcli_errstr(c1->tree));
533 static BOOL run_readwritetest(void)
535 struct smbcli_state *cli1, *cli2;
536 BOOL test1, test2 = True;
538 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
542 printf("starting readwritetest\n");
544 test1 = rw_torture2(cli1, cli2);
545 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1));
548 test2 = rw_torture2(cli1, cli1);
549 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2));
552 if (!torture_close_connection(cli1)) {
556 if (!torture_close_connection(cli2)) {
560 return (test1 && test2);
563 static BOOL run_readwritemulti(struct smbcli_state *cli, int dummy)
567 test = rw_torture3(cli, "\\multitest.txt");
569 if (!torture_close_connection(cli)) {
578 this checks to see if a secondary tconx can use open files from an
581 static BOOL run_tcon_test(void)
583 struct smbcli_state *cli;
584 const char *fname = "\\tcontest.tmp";
586 uint16_t cnum1, cnum2, cnum3;
587 uint16_t vuid1, vuid2;
590 struct smbcli_tree *tree1;
591 const char *host = lp_parm_string(-1, "torture", "host");
592 const char *share = lp_parm_string(-1, "torture", "share");
593 const char *password = lp_parm_string(-1, "torture", "password");
595 if (!torture_open_connection(&cli)) {
599 printf("starting tcontest\n");
601 if (smbcli_deltree(cli->tree, fname) == -1) {
602 printf("unlink of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
605 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
607 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
611 cnum1 = cli->tree->tid;
612 vuid1 = cli->session->vuid;
614 memset(&buf, 0, 4); /* init buf so valgrind won't complain */
615 if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) != 4) {
616 printf("initial write failed (%s)\n", smbcli_errstr(cli->tree));
620 tree1 = cli->tree; /* save old tree connection */
621 if (NT_STATUS_IS_ERR(smbcli_send_tconX(cli, share, "?????", password))) {
622 printf("%s refused 2nd tree connect (%s)\n", host,
623 smbcli_errstr(cli->tree));
624 smbcli_shutdown(cli);
628 cnum2 = cli->tree->tid;
629 cnum3 = MAX(cnum1, cnum2) + 1; /* any invalid number */
630 vuid2 = cli->session->vuid + 1;
632 /* try a write with the wrong tid */
633 cli->tree->tid = cnum2;
635 if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) == 4) {
636 printf("* server allows write with wrong TID\n");
639 printf("server fails write with wrong TID : %s\n", smbcli_errstr(cli->tree));
643 /* try a write with an invalid tid */
644 cli->tree->tid = cnum3;
646 if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) == 4) {
647 printf("* server allows write with invalid TID\n");
650 printf("server fails write with invalid TID : %s\n", smbcli_errstr(cli->tree));
653 /* try a write with an invalid vuid */
654 cli->session->vuid = vuid2;
655 cli->tree->tid = cnum1;
657 if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) == 4) {
658 printf("* server allows write with invalid VUID\n");
661 printf("server fails write with invalid VUID : %s\n", smbcli_errstr(cli->tree));
664 cli->session->vuid = vuid1;
665 cli->tree->tid = cnum1;
667 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum1))) {
668 printf("close failed (%s)\n", smbcli_errstr(cli->tree));
672 cli->tree->tid = cnum2;
674 if (NT_STATUS_IS_ERR(smbcli_tdis(cli))) {
675 printf("secondary tdis failed (%s)\n", smbcli_errstr(cli->tree));
679 cli->tree = tree1; /* restore initial tree */
680 cli->tree->tid = cnum1;
682 if (!torture_close_connection(cli)) {
691 static BOOL tcon_devtest(struct smbcli_state *cli,
692 const char *myshare, const char *devtype,
693 NTSTATUS expected_error)
697 const char *password = lp_parm_string(-1, "torture", "password");
699 status = NT_STATUS_IS_OK(smbcli_send_tconX(cli, myshare, devtype,
702 printf("Trying share %s with devtype %s\n", myshare, devtype);
704 if (NT_STATUS_IS_OK(expected_error)) {
708 printf("tconX to share %s with type %s "
709 "should have succeeded but failed\n",
716 printf("tconx to share %s with type %s "
717 "should have failed but succeeded\n",
721 if (NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),
725 printf("Returned unexpected error\n");
734 checks for correct tconX support
736 static BOOL run_tcon_devtype_test(void)
738 struct smbcli_state *cli1 = NULL;
743 const char *host = lp_parm_string(-1, "torture", "host");
744 const char *share = lp_parm_string(-1, "torture", "share");
745 const char *username = lp_parm_string(-1, "torture", "username");
746 const char *userdomain = lp_parm_string(-1, "torture", "userdomain");
747 const char *password = lp_parm_string(-1, "torture", "password");
749 status = smbcli_full_connection(NULL,
750 &cli1, lp_netbios_name(),
753 username, userdomain,
754 password, flags, &retry);
756 if (!NT_STATUS_IS_OK(status)) {
757 printf("could not open connection\n");
761 if (!tcon_devtest(cli1, "IPC$", "A:", NT_STATUS_BAD_DEVICE_TYPE))
764 if (!tcon_devtest(cli1, "IPC$", "?????", NT_STATUS_OK))
767 if (!tcon_devtest(cli1, "IPC$", "LPT:", NT_STATUS_BAD_DEVICE_TYPE))
770 if (!tcon_devtest(cli1, "IPC$", "IPC", NT_STATUS_OK))
773 if (!tcon_devtest(cli1, "IPC$", "FOOBA", NT_STATUS_BAD_DEVICE_TYPE))
776 if (!tcon_devtest(cli1, share, "A:", NT_STATUS_OK))
779 if (!tcon_devtest(cli1, share, "?????", NT_STATUS_OK))
782 if (!tcon_devtest(cli1, share, "LPT:", NT_STATUS_BAD_DEVICE_TYPE))
785 if (!tcon_devtest(cli1, share, "IPC", NT_STATUS_BAD_DEVICE_TYPE))
788 if (!tcon_devtest(cli1, share, "FOOBA", NT_STATUS_BAD_DEVICE_TYPE))
791 smbcli_shutdown(cli1);
794 printf("Passed tcondevtest\n");
801 test whether fnums and tids open on one VC are available on another (a major
804 static BOOL run_fdpasstest(void)
806 struct smbcli_state *cli1, *cli2;
807 const char *fname = "\\fdpass.tst";
811 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
815 printf("starting fdpasstest\n");
817 smbcli_unlink(cli1->tree, fname);
819 printf("Opening a file on connection 1\n");
821 fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
823 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
827 printf("writing to file on connection 1\n");
829 if (smbcli_write(cli1->tree, fnum1, 0, "hello world\n", 0, 13) != 13) {
830 printf("write failed (%s)\n", smbcli_errstr(cli1->tree));
834 oldtid = cli2->tree->tid;
835 cli2->session->vuid = cli1->session->vuid;
836 cli2->tree->tid = cli1->tree->tid;
837 cli2->session->pid = cli1->session->pid;
839 printf("reading from file on connection 2\n");
841 if (smbcli_read(cli2->tree, fnum1, buf, 0, 13) == 13) {
842 printf("read succeeded! nasty security hole [%s]\n",
847 smbcli_close(cli1->tree, fnum1);
848 smbcli_unlink(cli1->tree, fname);
850 cli2->tree->tid = oldtid;
852 torture_close_connection(cli1);
853 torture_close_connection(cli2);
855 printf("finished fdpasstest\n");
861 This test checks that
863 1) the server does not allow an unlink on a file that is open
865 static BOOL run_unlinktest(void)
867 struct smbcli_state *cli;
868 const char *fname = "\\unlink.tst";
872 if (!torture_open_connection(&cli)) {
876 printf("starting unlink test\n");
878 smbcli_unlink(cli->tree, fname);
880 cli->session->pid = 1;
882 printf("Opening a file\n");
884 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
886 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
890 printf("Unlinking a open file\n");
892 if (NT_STATUS_IS_OK(smbcli_unlink(cli->tree, fname))) {
893 printf("error: server allowed unlink on an open file\n");
896 correct = check_error(__location__, cli, ERRDOS, ERRbadshare,
897 NT_STATUS_SHARING_VIOLATION);
900 smbcli_close(cli->tree, fnum);
901 smbcli_unlink(cli->tree, fname);
903 if (!torture_close_connection(cli)) {
907 printf("unlink test finished\n");
914 test the timing of deferred open requests
916 static BOOL run_deferopen(struct smbcli_state *cli, int dummy)
918 const char *fname = "\\defer_open_test.dat";
924 printf("failed to connect\n");
928 printf("Testing deferred open requests.\n");
934 struct timeval tv_start, tv_end;
935 GetTimeOfDay(&tv_start);
936 fnum = smbcli_nt_create_full(cli->tree, fname, 0, GENERIC_RIGHTS_FILE_ALL_ACCESS,
937 FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_NONE,
938 NTCREATEX_DISP_OPEN_IF, 0, 0);
942 GetTimeOfDay(&tv_end);
943 if (NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),NT_STATUS_SHARING_VIOLATION)) {
944 /* Sharing violation errors need to be 1 second apart. */
945 int64_t tdif = usec_time_diff(&tv_end, &tv_start);
946 if (tdif < 500000 || tdif > 1500000) {
947 fprintf(stderr,"Timing incorrect %lld.%lld for share violation\n",
948 tdif / (int64_t)1000000,
949 tdif % (int64_t)1000000);
952 } while (NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),NT_STATUS_SHARING_VIOLATION));
955 fprintf(stderr,"Failed to open %s, error=%s\n", fname, smbcli_errstr(cli->tree));
959 printf("pid %u open %d\n", getpid(), i);
963 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum))) {
964 fprintf(stderr,"Failed to close %s, error=%s\n", fname, smbcli_errstr(cli->tree));
970 if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fname))) {
971 /* All until the last unlink will fail with sharing violation. */
972 if (!NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),NT_STATUS_SHARING_VIOLATION)) {
973 printf("unlink of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
978 printf("deferred test finished\n");
979 if (!torture_close_connection(cli)) {
986 test how many open files this server supports on the one socket
988 static BOOL run_maxfidtest(struct smbcli_state *cli, int dummy)
990 #define MAXFID_TEMPLATE "\\maxfid\\fid%d\\maxfid.%d.%d"
992 int fnums[0x11000], i;
993 int retries=4, maxfid;
997 printf("failed to connect\n");
1001 if (smbcli_deltree(cli->tree, "\\maxfid") == -1) {
1002 printf("Failed to deltree \\maxfid - %s\n",
1003 smbcli_errstr(cli->tree));
1006 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, "\\maxfid"))) {
1007 printf("Failed to mkdir \\maxfid, error=%s\n",
1008 smbcli_errstr(cli->tree));
1012 printf("Testing maximum number of open files\n");
1014 for (i=0; i<0x11000; i++) {
1015 if (i % 1000 == 0) {
1016 asprintf(&fname, "\\maxfid\\fid%d", i/1000);
1017 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, fname))) {
1018 printf("Failed to mkdir %s, error=%s\n",
1019 fname, smbcli_errstr(cli->tree));
1024 asprintf(&fname, MAXFID_TEMPLATE, i/1000, i,(int)getpid());
1025 if ((fnums[i] = smbcli_open(cli->tree, fname,
1026 O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) ==
1028 printf("open of %s failed (%s)\n",
1029 fname, smbcli_errstr(cli->tree));
1030 printf("maximum fnum is %d\n", i);
1041 printf("cleaning up\n");
1042 for (i=0;i<maxfid/2;i++) {
1043 asprintf(&fname, MAXFID_TEMPLATE, i/1000, i,(int)getpid());
1044 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnums[i]))) {
1045 printf("Close of fnum %d failed - %s\n", fnums[i], smbcli_errstr(cli->tree));
1047 if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fname))) {
1048 printf("unlink of %s failed (%s)\n",
1049 fname, smbcli_errstr(cli->tree));
1054 asprintf(&fname, MAXFID_TEMPLATE, (maxfid-i)/1000, maxfid-i,(int)getpid());
1055 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnums[maxfid-i]))) {
1056 printf("Close of fnum %d failed - %s\n", fnums[maxfid-i], smbcli_errstr(cli->tree));
1058 if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fname))) {
1059 printf("unlink of %s failed (%s)\n",
1060 fname, smbcli_errstr(cli->tree));
1065 printf("%6d %6d\r", i, maxfid-i);
1069 if (smbcli_deltree(cli->tree, "\\maxfid") == -1) {
1070 printf("Failed to deltree \\maxfid - %s\n",
1071 smbcli_errstr(cli->tree));
1075 printf("maxfid test finished\n");
1076 if (!torture_close_connection(cli)) {
1080 #undef MAXFID_TEMPLATE
1083 /* send smb negprot commands, not reading the response */
1084 static BOOL run_negprot_nowait(void)
1087 struct smbcli_state *cli, *cli2;
1088 BOOL correct = True;
1090 printf("starting negprot nowait test\n");
1092 cli = open_nbt_connection();
1097 printf("Filling send buffer\n");
1099 for (i=0;i<10000;i++) {
1100 struct smbcli_request *req;
1101 time_t t1 = time(NULL);
1102 req = smb_negprot_send(cli->transport, PROTOCOL_NT1);
1103 while (req->state == SMBCLI_REQUEST_SEND && time(NULL) < t1+5) {
1104 smbcli_transport_process(cli->transport);
1106 if (req->state == SMBCLI_REQUEST_ERROR) {
1107 printf("Failed to fill pipe - %s\n", nt_errstr(req->status));
1108 torture_close_connection(cli);
1111 if (req->state == SMBCLI_REQUEST_SEND) {
1117 printf("send buffer failed to fill\n");
1118 if (!torture_close_connection(cli)) {
1124 printf("send buffer filled after %d requests\n", i);
1126 printf("Opening secondary connection\n");
1127 if (!torture_open_connection(&cli2)) {
1131 if (!torture_close_connection(cli)) {
1135 if (!torture_close_connection(cli2)) {
1139 printf("finished negprot nowait test\n");
1146 This checks how the getatr calls works
1148 static BOOL run_attrtest(void)
1150 struct smbcli_state *cli;
1153 const char *fname = "\\attrib123456789.tst";
1154 BOOL correct = True;
1156 printf("starting attrib test\n");
1158 if (!torture_open_connection(&cli)) {
1162 smbcli_unlink(cli->tree, fname);
1163 fnum = smbcli_open(cli->tree, fname,
1164 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1165 smbcli_close(cli->tree, fnum);
1167 if (NT_STATUS_IS_ERR(smbcli_getatr(cli->tree, fname, NULL, NULL, &t))) {
1168 printf("getatr failed (%s)\n", smbcli_errstr(cli->tree));
1172 printf("New file time is %s", ctime(&t));
1174 if (abs(t - time(NULL)) > 60*60*24*10) {
1175 printf("ERROR: SMBgetatr bug. time is %s",
1181 t2 = t-60*60*24; /* 1 day ago */
1183 printf("Setting file time to %s", ctime(&t2));
1185 if (NT_STATUS_IS_ERR(smbcli_setatr(cli->tree, fname, 0, t2))) {
1186 printf("setatr failed (%s)\n", smbcli_errstr(cli->tree));
1190 if (NT_STATUS_IS_ERR(smbcli_getatr(cli->tree, fname, NULL, NULL, &t))) {
1191 printf("getatr failed (%s)\n", smbcli_errstr(cli->tree));
1195 printf("Retrieved file time as %s", ctime(&t));
1198 printf("ERROR: getatr/setatr bug. times are\n%s",
1200 printf("%s", ctime(&t2));
1204 smbcli_unlink(cli->tree, fname);
1206 if (!torture_close_connection(cli)) {
1210 printf("attrib test finished\n");
1217 This checks a couple of trans2 calls
1219 static BOOL run_trans2test(void)
1221 struct smbcli_state *cli;
1224 time_t c_time, a_time, m_time, w_time, m_time2;
1225 const char *fname = "\\trans2.tst";
1226 const char *dname = "\\trans2";
1227 const char *fname2 = "\\trans2\\trans2.tst";
1229 BOOL correct = True;
1231 printf("starting trans2 test\n");
1233 if (!torture_open_connection(&cli)) {
1237 smbcli_unlink(cli->tree, fname);
1239 printf("Testing qfileinfo\n");
1241 fnum = smbcli_open(cli->tree, fname,
1242 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1243 if (NT_STATUS_IS_ERR(smbcli_qfileinfo(cli->tree, fnum, NULL, &size, &c_time, &a_time, &m_time,
1245 printf("ERROR: qfileinfo failed (%s)\n", smbcli_errstr(cli->tree));
1249 printf("Testing NAME_INFO\n");
1251 if (NT_STATUS_IS_ERR(smbcli_qfilename(cli->tree, fnum, &pname))) {
1252 printf("ERROR: qfilename failed (%s)\n", smbcli_errstr(cli->tree));
1256 if (!pname || strcmp(pname, fname)) {
1257 printf("qfilename gave different name? [%s] [%s]\n",
1262 smbcli_close(cli->tree, fnum);
1263 smbcli_unlink(cli->tree, fname);
1265 fnum = smbcli_open(cli->tree, fname,
1266 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1268 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
1271 smbcli_close(cli->tree, fnum);
1273 printf("Checking for sticky create times\n");
1275 if (NT_STATUS_IS_ERR(smbcli_qpathinfo(cli->tree, fname, &c_time, &a_time, &m_time, &size, NULL))) {
1276 printf("ERROR: qpathinfo failed (%s)\n", smbcli_errstr(cli->tree));
1279 if (c_time != m_time) {
1280 printf("create time=%s", ctime(&c_time));
1281 printf("modify time=%s", ctime(&m_time));
1282 printf("This system appears to have sticky create times\n");
1284 if (a_time % (60*60) == 0) {
1285 printf("access time=%s", ctime(&a_time));
1286 printf("This system appears to set a midnight access time\n");
1290 if (abs(m_time - time(NULL)) > 60*60*24*7) {
1291 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
1297 smbcli_unlink(cli->tree, fname);
1298 fnum = smbcli_open(cli->tree, fname,
1299 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1300 smbcli_close(cli->tree, fnum);
1301 if (NT_STATUS_IS_ERR(smbcli_qpathinfo2(cli->tree, fname, &c_time, &a_time, &m_time, &w_time, &size, NULL, NULL))) {
1302 printf("ERROR: qpathinfo2 failed (%s)\n", smbcli_errstr(cli->tree));
1305 if (w_time < 60*60*24*2) {
1306 printf("write time=%s", ctime(&w_time));
1307 printf("This system appears to set a initial 0 write time\n");
1312 smbcli_unlink(cli->tree, fname);
1315 /* check if the server updates the directory modification time
1316 when creating a new file */
1317 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, dname))) {
1318 printf("ERROR: mkdir failed (%s)\n", smbcli_errstr(cli->tree));
1322 if (NT_STATUS_IS_ERR(smbcli_qpathinfo2(cli->tree, "\\trans2\\", &c_time, &a_time, &m_time, &w_time, &size, NULL, NULL))) {
1323 printf("ERROR: qpathinfo2 failed (%s)\n", smbcli_errstr(cli->tree));
1327 fnum = smbcli_open(cli->tree, fname2,
1328 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1329 smbcli_write(cli->tree, fnum, 0, (char *)&fnum, 0, sizeof(fnum));
1330 smbcli_close(cli->tree, fnum);
1331 if (NT_STATUS_IS_ERR(smbcli_qpathinfo2(cli->tree, "\\trans2\\", &c_time, &a_time, &m_time2, &w_time, &size, NULL, NULL))) {
1332 printf("ERROR: qpathinfo2 failed (%s)\n", smbcli_errstr(cli->tree));
1335 if (m_time2 == m_time) {
1336 printf("This system does not update directory modification times\n");
1340 smbcli_unlink(cli->tree, fname2);
1341 smbcli_rmdir(cli->tree, dname);
1343 if (!torture_close_connection(cli)) {
1347 printf("trans2 test finished\n");
1354 print out server properties
1356 static BOOL run_properties(void)
1358 struct smbcli_state *cli;
1359 BOOL correct = True;
1361 printf("starting properties test\n");
1365 if (!torture_open_connection(&cli)) {
1369 d_printf("Capabilities 0x%08x\n", cli->transport->negotiate.capabilities);
1371 if (!torture_close_connection(cli)) {
1380 /* FIRST_DESIRED_ACCESS 0xf019f */
1381 #define FIRST_DESIRED_ACCESS SA_RIGHT_FILE_READ_DATA|SA_RIGHT_FILE_WRITE_DATA|SA_RIGHT_FILE_APPEND_DATA|\
1382 SA_RIGHT_FILE_READ_EA| /* 0xf */ \
1383 SA_RIGHT_FILE_WRITE_EA|SA_RIGHT_FILE_READ_ATTRIBUTES| /* 0x90 */ \
1384 SA_RIGHT_FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
1385 STD_RIGHT_DELETE_ACCESS|STD_RIGHT_READ_CONTROL_ACCESS|\
1386 STD_RIGHT_WRITE_DAC_ACCESS|STD_RIGHT_WRITE_OWNER_ACCESS /* 0xf0000 */
1387 /* SECOND_DESIRED_ACCESS 0xe0080 */
1388 #define SECOND_DESIRED_ACCESS SA_RIGHT_FILE_READ_ATTRIBUTES| /* 0x80 */ \
1389 STD_RIGHT_READ_CONTROL_ACCESS|STD_RIGHT_WRITE_DAC_ACCESS|\
1390 STD_RIGHT_WRITE_OWNER_ACCESS /* 0xe0000 */
1393 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
1394 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
1395 SA_RIGHT_FILE_READ_DATA|\
1396 WRITE_OWNER_ACCESS /* */
1400 Test ntcreate calls made by xcopy
1402 static BOOL run_xcopy(void)
1404 struct smbcli_state *cli1;
1405 const char *fname = "\\test.txt";
1406 BOOL correct = True;
1409 printf("starting xcopy test\n");
1411 if (!torture_open_connection(&cli1)) {
1415 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0,
1416 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
1417 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF,
1421 printf("First open failed - %s\n", smbcli_errstr(cli1->tree));
1425 fnum2 = smbcli_nt_create_full(cli1->tree, fname, 0,
1426 SECOND_DESIRED_ACCESS, 0,
1427 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN,
1430 printf("second open failed - %s\n", smbcli_errstr(cli1->tree));
1434 if (!torture_close_connection(cli1)) {
1443 see how many RPC pipes we can open at once
1445 static BOOL run_pipe_number(void)
1447 struct smbcli_state *cli1;
1448 const char *pipe_name = "\\WKSSVC";
1452 printf("starting pipenumber test\n");
1453 if (!torture_open_connection(&cli1)) {
1458 fnum = smbcli_nt_create_full(cli1->tree, pipe_name, 0, SA_RIGHT_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
1459 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1462 printf("Open of pipe %s failed with error (%s)\n", pipe_name, smbcli_errstr(cli1->tree));
1466 printf("%d\r", num_pipes);
1470 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes, pipe_name );
1471 torture_close_connection(cli1);
1479 open N connections to the server and just hold them open
1480 used for testing performance when there are N idle users
1483 static BOOL torture_holdcon(void)
1486 struct smbcli_state **cli;
1489 printf("Opening %d connections\n", torture_numops);
1491 cli = malloc(sizeof(struct smbcli_state *) * torture_numops);
1493 for (i=0;i<torture_numops;i++) {
1494 if (!torture_open_connection(&cli[i])) {
1497 printf("opened %d connections\r", i);
1501 printf("\nStarting pings\n");
1504 for (i=0;i<torture_numops;i++) {
1507 status = smbcli_chkpath(cli[i]->tree, "\\");
1508 if (!NT_STATUS_IS_OK(status)) {
1509 printf("Connection %d is dead\n", i);
1517 if (num_dead == torture_numops) {
1518 printf("All connections dead - finishing\n");
1530 Try with a wrong vuid and check error message.
1533 static BOOL run_vuidtest(void)
1535 struct smbcli_state *cli;
1536 const char *fname = "\\vuid.tst";
1539 time_t c_time, a_time, m_time;
1540 BOOL correct = True;
1545 printf("starting vuid test\n");
1547 if (!torture_open_connection(&cli)) {
1551 smbcli_unlink(cli->tree, fname);
1553 fnum = smbcli_open(cli->tree, fname,
1554 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1556 orig_vuid = cli->session->vuid;
1558 cli->session->vuid += 1234;
1560 printf("Testing qfileinfo with wrong vuid\n");
1562 if (NT_STATUS_IS_OK(result = smbcli_qfileinfo(cli->tree, fnum, NULL,
1563 &size, &c_time, &a_time,
1564 &m_time, NULL, NULL))) {
1565 printf("ERROR: qfileinfo passed with wrong vuid\n");
1569 if ( (cli->transport->error.etype != ETYPE_DOS) ||
1570 (cli->transport->error.e.dos.eclass != ERRSRV) ||
1571 (cli->transport->error.e.dos.ecode != ERRbaduid) ) {
1572 printf("ERROR: qfileinfo should have returned DOS error "
1573 "ERRSRV:ERRbaduid\n but returned %s\n",
1574 smbcli_errstr(cli->tree));
1578 cli->session->vuid -= 1234;
1580 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum))) {
1581 printf("close failed (%s)\n", smbcli_errstr(cli->tree));
1585 smbcli_unlink(cli->tree, fname);
1587 if (!torture_close_connection(cli)) {
1591 printf("vuid test finished\n");
1597 Test open mode returns on read-only files.
1599 static BOOL run_opentest(void)
1601 static struct smbcli_state *cli1;
1602 static struct smbcli_state *cli2;
1603 const char *fname = "\\readonly.file";
1607 BOOL correct = True;
1611 printf("starting open test\n");
1613 if (!torture_open_connection(&cli1)) {
1617 smbcli_setatr(cli1->tree, fname, 0, 0);
1618 smbcli_unlink(cli1->tree, fname);
1620 fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1622 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1626 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1627 printf("close2 failed (%s)\n", smbcli_errstr(cli1->tree));
1631 if (NT_STATUS_IS_ERR(smbcli_setatr(cli1->tree, fname, FILE_ATTRIBUTE_READONLY, 0))) {
1632 printf("smbcli_setatr failed (%s)\n", smbcli_errstr(cli1->tree));
1633 CHECK_MAX_FAILURES(error_test1);
1637 fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY, DENY_WRITE);
1639 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1640 CHECK_MAX_FAILURES(error_test1);
1644 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
1645 fnum2 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_ALL);
1647 if (check_error(__location__, cli1, ERRDOS, ERRnoaccess,
1648 NT_STATUS_ACCESS_DENIED)) {
1649 printf("correct error code ERRDOS/ERRnoaccess returned\n");
1652 printf("finished open test 1\n");
1654 smbcli_close(cli1->tree, fnum1);
1656 /* Now try not readonly and ensure ERRbadshare is returned. */
1658 smbcli_setatr(cli1->tree, fname, 0, 0);
1660 fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY, DENY_WRITE);
1662 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1666 /* This will fail - but the error should be ERRshare. */
1667 fnum2 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_ALL);
1669 if (check_error(__location__, cli1, ERRDOS, ERRbadshare,
1670 NT_STATUS_SHARING_VIOLATION)) {
1671 printf("correct error code ERRDOS/ERRbadshare returned\n");
1674 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1675 printf("close2 failed (%s)\n", smbcli_errstr(cli1->tree));
1679 smbcli_unlink(cli1->tree, fname);
1681 printf("finished open test 2\n");
1683 /* Test truncate open disposition on file opened for read. */
1685 fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1687 printf("(3) open (1) of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1691 /* write 20 bytes. */
1693 memset(buf, '\0', 20);
1695 if (smbcli_write(cli1->tree, fnum1, 0, buf, 0, 20) != 20) {
1696 printf("write failed (%s)\n", smbcli_errstr(cli1->tree));
1700 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1701 printf("(3) close1 failed (%s)\n", smbcli_errstr(cli1->tree));
1705 /* Ensure size == 20. */
1706 if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
1707 printf("(3) getatr failed (%s)\n", smbcli_errstr(cli1->tree));
1708 CHECK_MAX_FAILURES(error_test3);
1713 printf("(3) file size != 20\n");
1714 CHECK_MAX_FAILURES(error_test3);
1718 /* Now test if we can truncate a file opened for readonly. */
1720 fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY|O_TRUNC, DENY_NONE);
1722 printf("(3) open (2) of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1723 CHECK_MAX_FAILURES(error_test3);
1727 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1728 printf("close2 failed (%s)\n", smbcli_errstr(cli1->tree));
1732 /* Ensure size == 0. */
1733 if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
1734 printf("(3) getatr failed (%s)\n", smbcli_errstr(cli1->tree));
1735 CHECK_MAX_FAILURES(error_test3);
1740 printf("(3) file size != 0\n");
1741 CHECK_MAX_FAILURES(error_test3);
1744 printf("finished open test 3\n");
1746 smbcli_unlink(cli1->tree, fname);
1749 printf("testing ctemp\n");
1750 fnum1 = smbcli_ctemp(cli1->tree, "\\", &tmp_path);
1752 printf("ctemp failed (%s)\n", smbcli_errstr(cli1->tree));
1753 CHECK_MAX_FAILURES(error_test4);
1756 printf("ctemp gave path %s\n", tmp_path);
1757 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1758 printf("close of temp failed (%s)\n", smbcli_errstr(cli1->tree));
1760 if (NT_STATUS_IS_ERR(smbcli_unlink(cli1->tree, tmp_path))) {
1761 printf("unlink of temp failed (%s)\n", smbcli_errstr(cli1->tree));
1764 /* Test the non-io opens... */
1766 if (!torture_open_connection(&cli2)) {
1770 smbcli_setatr(cli2->tree, fname, 0, 0);
1771 smbcli_unlink(cli2->tree, fname);
1773 printf("TEST #1 testing 2 non-io opens (no delete)\n");
1775 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1776 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1779 printf("test 1 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1780 CHECK_MAX_FAILURES(error_test10);
1784 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1785 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1787 printf("test 1 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1788 CHECK_MAX_FAILURES(error_test10);
1792 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1793 printf("test 1 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1796 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1797 printf("test 1 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1801 printf("non-io open test #1 passed.\n");
1803 smbcli_unlink(cli1->tree, fname);
1805 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
1807 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1808 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1811 printf("test 2 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1812 CHECK_MAX_FAILURES(error_test20);
1816 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1817 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1820 printf("test 2 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1821 CHECK_MAX_FAILURES(error_test20);
1825 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1826 printf("test 1 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1829 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1830 printf("test 1 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1834 printf("non-io open test #2 passed.\n");
1836 smbcli_unlink(cli1->tree, fname);
1838 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
1840 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1841 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1844 printf("test 3 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1845 CHECK_MAX_FAILURES(error_test30);
1849 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1850 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1853 printf("test 3 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1854 CHECK_MAX_FAILURES(error_test30);
1858 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1859 printf("test 3 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1862 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1863 printf("test 3 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1867 printf("non-io open test #3 passed.\n");
1869 smbcli_unlink(cli1->tree, fname);
1871 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
1873 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1874 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1877 printf("test 4 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1878 CHECK_MAX_FAILURES(error_test40);
1882 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1883 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1886 printf("test 4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1887 CHECK_MAX_FAILURES(error_test40);
1891 printf("test 4 open 2 of %s gave %s (correct error should be %s)\n", fname, smbcli_errstr(cli2->tree), "sharing violation");
1893 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1894 printf("test 4 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1898 printf("non-io open test #4 passed.\n");
1900 smbcli_unlink(cli1->tree, fname);
1902 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
1904 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1905 NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1908 printf("test 5 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1909 CHECK_MAX_FAILURES(error_test50);
1913 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1914 NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1917 printf("test 5 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1918 CHECK_MAX_FAILURES(error_test50);
1922 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1923 printf("test 5 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1927 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1928 printf("test 5 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1932 printf("non-io open test #5 passed.\n");
1934 printf("TEST #6 testing 1 non-io open, one io open\n");
1936 smbcli_unlink(cli1->tree, fname);
1938 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SA_RIGHT_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
1939 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1942 printf("test 6 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1943 CHECK_MAX_FAILURES(error_test60);
1947 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1948 NTCREATEX_SHARE_ACCESS_READ, NTCREATEX_DISP_OPEN_IF, 0, 0);
1951 printf("test 6 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1952 CHECK_MAX_FAILURES(error_test60);
1956 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1957 printf("test 6 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1961 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1962 printf("test 6 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1966 printf("non-io open test #6 passed.\n");
1968 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
1970 smbcli_unlink(cli1->tree, fname);
1972 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SA_RIGHT_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
1973 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1976 printf("test 7 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1977 CHECK_MAX_FAILURES(error_test70);
1981 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
1982 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1985 printf("test 7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1986 CHECK_MAX_FAILURES(error_test70);
1990 printf("test 7 open 2 of %s gave %s (correct error should be %s)\n", fname, smbcli_errstr(cli2->tree), "sharing violation");
1992 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1993 printf("test 7 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1997 printf("non-io open test #7 passed.\n");
2001 printf("TEST #8 testing one normal open, followed by lock, followed by open with truncate\n");
2003 smbcli_unlink(cli1->tree, fname);
2005 fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
2007 printf("(8) open (1) of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
2011 /* write 20 bytes. */
2013 memset(buf, '\0', 20);
2015 if (smbcli_write(cli1->tree, fnum1, 0, buf, 0, 20) != 20) {
2016 printf("(8) write failed (%s)\n", smbcli_errstr(cli1->tree));
2020 /* Ensure size == 20. */
2021 if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
2022 printf("(8) getatr (1) failed (%s)\n", smbcli_errstr(cli1->tree));
2023 CHECK_MAX_FAILURES(error_test80);
2028 printf("(8) file size != 20\n");
2029 CHECK_MAX_FAILURES(error_test80);
2033 /* Get an exclusive lock on the open file. */
2034 if (NT_STATUS_IS_ERR(smbcli_lock(cli1->tree, fnum1, 0, 4, 0, WRITE_LOCK))) {
2035 printf("(8) lock1 failed (%s)\n", smbcli_errstr(cli1->tree));
2036 CHECK_MAX_FAILURES(error_test80);
2040 fnum2 = smbcli_open(cli1->tree, fname, O_RDWR|O_TRUNC, DENY_NONE);
2042 printf("(8) open (2) of %s with truncate failed (%s)\n", fname, smbcli_errstr(cli1->tree));
2046 /* Ensure size == 0. */
2047 if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
2048 printf("(8) getatr (2) failed (%s)\n", smbcli_errstr(cli1->tree));
2049 CHECK_MAX_FAILURES(error_test80);
2054 printf("(8) file size != 0\n");
2055 CHECK_MAX_FAILURES(error_test80);
2059 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
2060 printf("(8) close1 failed (%s)\n", smbcli_errstr(cli1->tree));
2064 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum2))) {
2065 printf("(8) close1 failed (%s)\n", smbcli_errstr(cli1->tree));
2071 printf("open test #8 passed.\n");
2073 smbcli_unlink(cli1->tree, fname);
2075 if (!torture_close_connection(cli1)) {
2078 if (!torture_close_connection(cli2)) {
2087 sees what IOCTLs are supported
2089 BOOL torture_ioctl_test(void)
2091 struct smbcli_state *cli;
2092 uint16_t device, function;
2094 const char *fname = "\\ioctl.dat";
2096 union smb_ioctl parms;
2097 TALLOC_CTX *mem_ctx;
2099 if (!torture_open_connection(&cli)) {
2103 mem_ctx = talloc_init("ioctl_test");
2105 printf("starting ioctl test\n");
2107 smbcli_unlink(cli->tree, fname);
2109 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2111 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
2115 parms.ioctl.level = RAW_IOCTL_IOCTL;
2116 parms.ioctl.in.fnum = fnum;
2117 parms.ioctl.in.request = IOCTL_QUERY_JOB_INFO;
2118 status = smb_raw_ioctl(cli->tree, mem_ctx, &parms);
2119 printf("ioctl job info: %s\n", smbcli_errstr(cli->tree));
2121 for (device=0;device<0x100;device++) {
2122 printf("testing device=0x%x\n", device);
2123 for (function=0;function<0x100;function++) {
2124 parms.ioctl.in.request = (device << 16) | function;
2125 status = smb_raw_ioctl(cli->tree, mem_ctx, &parms);
2127 if (NT_STATUS_IS_OK(status)) {
2128 printf("ioctl device=0x%x function=0x%x OK : %d bytes\n",
2129 device, function, parms.ioctl.out.blob.length);
2134 if (!torture_close_connection(cli)) {
2143 tries variants of chkpath
2145 BOOL torture_chkpath_test(void)
2147 struct smbcli_state *cli;
2151 if (!torture_open_connection(&cli)) {
2155 printf("starting chkpath test\n");
2157 printf("Testing valid and invalid paths\n");
2159 /* cleanup from an old run */
2160 smbcli_rmdir(cli->tree, "\\chkpath.dir\\dir2");
2161 smbcli_unlink(cli->tree, "\\chkpath.dir\\*");
2162 smbcli_rmdir(cli->tree, "\\chkpath.dir");
2164 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, "\\chkpath.dir"))) {
2165 printf("mkdir1 failed : %s\n", smbcli_errstr(cli->tree));
2169 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, "\\chkpath.dir\\dir2"))) {
2170 printf("mkdir2 failed : %s\n", smbcli_errstr(cli->tree));
2174 fnum = smbcli_open(cli->tree, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2176 printf("open1 failed (%s)\n", smbcli_errstr(cli->tree));
2179 smbcli_close(cli->tree, fnum);
2181 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir"))) {
2182 printf("chkpath1 failed: %s\n", smbcli_errstr(cli->tree));
2186 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\dir2"))) {
2187 printf("chkpath2 failed: %s\n", smbcli_errstr(cli->tree));
2191 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\foo.txt"))) {
2192 ret = check_error(__location__, cli, ERRDOS, ERRbadpath,
2193 NT_STATUS_NOT_A_DIRECTORY);
2195 printf("* chkpath on a file should fail\n");
2199 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\bar.txt"))) {
2200 ret = check_error(__location__, cli, ERRDOS, ERRbadfile,
2201 NT_STATUS_OBJECT_NAME_NOT_FOUND);
2203 printf("* chkpath on a non existent file should fail\n");
2207 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\dirxx\\bar.txt"))) {
2208 ret = check_error(__location__, cli, ERRDOS, ERRbadpath,
2209 NT_STATUS_OBJECT_PATH_NOT_FOUND);
2211 printf("* chkpath on a non existent component should fail\n");
2215 smbcli_rmdir(cli->tree, "\\chkpath.dir\\dir2");
2216 smbcli_unlink(cli->tree, "\\chkpath.dir\\*");
2217 smbcli_rmdir(cli->tree, "\\chkpath.dir");
2219 if (!torture_close_connection(cli)) {
2228 parse a //server/share type UNC name
2230 static BOOL parse_unc(const char *unc_name, char **hostname, char **sharename)
2234 if (strncmp(unc_name, "//", 2)) {
2238 *hostname = strdup(&unc_name[2]);
2239 p = strchr_m(&(*hostname)[2],'/');
2244 *sharename = strdup(p+1);
2251 static void sigcont(int sig)
2255 double torture_create_procs(BOOL (*fn)(struct smbcli_state *, int), BOOL *result)
2258 volatile pid_t *child_status;
2259 volatile BOOL *child_status_out;
2262 double start_time_limit = 10 + (torture_nprocs * 1.5);
2263 char **unc_list = NULL;
2265 int num_unc_names = 0;
2269 signal(SIGCONT, sigcont);
2271 child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*torture_nprocs);
2272 if (!child_status) {
2273 printf("Failed to setup shared memory\n");
2277 child_status_out = (volatile BOOL *)shm_setup(sizeof(BOOL)*torture_nprocs);
2278 if (!child_status_out) {
2279 printf("Failed to setup result status shared memory\n");
2283 p = lp_parm_string(-1, "torture", "unclist");
2285 unc_list = file_lines_load(p, &num_unc_names);
2286 if (!unc_list || num_unc_names <= 0) {
2287 printf("Failed to load unc names list from '%s'\n", p);
2292 for (i = 0; i < torture_nprocs; i++) {
2293 child_status[i] = 0;
2294 child_status_out[i] = True;
2299 for (i=0;i<torture_nprocs;i++) {
2303 char *hostname=NULL, *sharename;
2305 pid_t mypid = getpid();
2306 sys_srandom(((int)mypid) ^ ((int)time(NULL)));
2308 asprintf(&myname, "CLIENT%d", i);
2309 lp_set_cmdline("netbios name", myname);
2314 if (!parse_unc(unc_list[i % num_unc_names],
2315 &hostname, &sharename)) {
2316 printf("Failed to parse UNC name %s\n",
2317 unc_list[i % num_unc_names]);
2324 if (torture_open_connection_share(¤t_cli,
2329 } else if (torture_open_connection(¤t_cli)) {
2333 printf("pid %d failed to start\n", (int)getpid());
2339 child_status[i] = getpid();
2343 if (child_status[i]) {
2344 printf("Child %d failed to start!\n", i);
2345 child_status_out[i] = 1;
2349 child_status_out[i] = fn(current_cli, i);
2356 for (i=0;i<torture_nprocs;i++) {
2357 if (child_status[i]) synccount++;
2359 if (synccount == torture_nprocs) break;
2361 } while (end_timer() < start_time_limit);
2363 if (synccount != torture_nprocs) {
2364 printf("FAILED TO START %d CLIENTS (started %d)\n", torture_nprocs, synccount);
2369 printf("Starting %d clients\n", torture_nprocs);
2371 /* start the client load */
2373 for (i=0;i<torture_nprocs;i++) {
2374 child_status[i] = 0;
2378 printf("%d clients started\n", torture_nprocs);
2380 for (i=0;i<torture_nprocs;i++) {
2382 while ((ret=sys_waitpid(0, &status, 0)) == -1 && errno == EINTR) /* noop */ ;
2383 if (ret == -1 || WEXITSTATUS(status) != 0) {
2390 for (i=0;i<torture_nprocs;i++) {
2391 if (!child_status_out[i]) {
2398 #define FLAG_MULTIPROC 1
2403 BOOL (*multi_fn)(struct smbcli_state *, int );
2406 {"BASE-FDPASS", run_fdpasstest, 0},
2407 {"BASE-LOCK1", torture_locktest1, 0},
2408 {"BASE-LOCK2", torture_locktest2, 0},
2409 {"BASE-LOCK3", torture_locktest3, 0},
2410 {"BASE-LOCK4", torture_locktest4, 0},
2411 {"BASE-LOCK5", torture_locktest5, 0},
2412 {"BASE-LOCK6", torture_locktest6, 0},
2413 {"BASE-LOCK7", torture_locktest7, 0},
2414 {"BASE-UNLINK", run_unlinktest, 0},
2415 {"BASE-ATTR", run_attrtest, 0},
2416 {"BASE-TRANS2", run_trans2test, 0},
2417 {"BASE-NEGNOWAIT", run_negprot_nowait, 0},
2418 {"BASE-DIR1", torture_dirtest1, 0},
2419 {"BASE-DIR2", torture_dirtest2, 0},
2420 {"BASE-DENY1", torture_denytest1, 0},
2421 {"BASE-DENY2", torture_denytest2, 0},
2422 {"BASE-DENY3", torture_denytest3, 0},
2423 {"BASE-NTDENY1", NULL, torture_ntdenytest1},
2424 {"BASE-NTDENY2", torture_ntdenytest2, 0},
2425 {"BASE-TCON", run_tcon_test, 0},
2426 {"BASE-TCONDEV", run_tcon_devtype_test, 0},
2427 {"BASE-VUID", run_vuidtest, 0},
2428 {"BASE-RW1", run_readwritetest, 0},
2429 {"BASE-RW2", NULL, run_readwritemulti},
2430 {"BASE-OPEN", run_opentest, 0},
2431 {"BASE-DEFER_OPEN", NULL, run_deferopen},
2432 {"BASE-XCOPY", run_xcopy, 0},
2433 {"BASE-RENAME", torture_test_rename, 0},
2434 {"BASE-DELETE", torture_test_delete, 0},
2435 {"BASE-PROPERTIES", run_properties, 0},
2436 {"BASE-MANGLE", torture_mangle, 0},
2437 {"BASE-OPENATTR", torture_openattrtest, 0},
2438 {"BASE-CHARSET", torture_charset, 0},
2439 {"BASE-CHKPATH", torture_chkpath_test, 0},
2440 {"BASE-SECLEAK", torture_sec_leak, 0},
2442 /* benchmarking tests */
2443 {"BENCH-HOLDCON", torture_holdcon, 0},
2444 {"BENCH-NBENCH", torture_nbench, 0},
2445 {"BENCH-TORTURE", NULL, run_torture},
2448 {"RAW-QFSINFO", torture_raw_qfsinfo, 0},
2449 {"RAW-QFILEINFO", torture_raw_qfileinfo, 0},
2450 {"RAW-SFILEINFO", torture_raw_sfileinfo, 0},
2451 {"RAW-SFILEINFO-BUG", torture_raw_sfileinfo_bug, 0},
2452 {"RAW-SEARCH", torture_raw_search, 0},
2453 {"RAW-CLOSE", torture_raw_close, 0},
2454 {"RAW-OPEN", torture_raw_open, 0},
2455 {"RAW-MKDIR", torture_raw_mkdir, 0},
2456 {"RAW-OPLOCK", torture_raw_oplock, 0},
2457 {"RAW-NOTIFY", torture_raw_notify, 0},
2458 {"RAW-MUX", torture_raw_mux, 0},
2459 {"RAW-IOCTL", torture_raw_ioctl, 0},
2460 {"RAW-CHKPATH", torture_raw_chkpath, 0},
2461 {"RAW-UNLINK", torture_raw_unlink, 0},
2462 {"RAW-READ", torture_raw_read, 0},
2463 {"RAW-WRITE", torture_raw_write, 0},
2464 {"RAW-LOCK", torture_raw_lock, 0},
2465 {"RAW-CONTEXT", torture_raw_context, 0},
2466 {"RAW-RENAME", torture_raw_rename, 0},
2467 {"RAW-SEEK", torture_raw_seek, 0},
2468 {"RAW-RAP", torture_raw_rap, 0},
2470 /* protocol scanners */
2471 {"SCAN-TRANS2", torture_trans2_scan, 0},
2472 {"SCAN-NTTRANS", torture_nttrans_scan, 0},
2473 {"SCAN-ALIASES", torture_trans2_aliases, 0},
2474 {"SCAN-SMB", torture_smb_scan, 0},
2475 {"SCAN-MAXFID", NULL, run_maxfidtest},
2476 {"SCAN-UTABLE", torture_utable, 0},
2477 {"SCAN-CASETABLE", torture_casetable, 0},
2478 {"SCAN-PIPE_NUMBER", run_pipe_number, 0},
2479 {"SCAN-IOCTL", torture_ioctl_test, 0},
2482 {"RPC-LSA", torture_rpc_lsa, 0},
2483 {"RPC-ECHO", torture_rpc_echo, 0},
2484 {"RPC-DFS", torture_rpc_dfs, 0},
2485 {"RPC-SPOOLSS", torture_rpc_spoolss, 0},
2486 {"RPC-SAMR", torture_rpc_samr, 0},
2487 {"RPC-NETLOGON", torture_rpc_netlogon, 0},
2488 {"RPC-SCHANNEL", torture_rpc_schannel, 0},
2489 {"RPC-WKSSVC", torture_rpc_wkssvc, 0},
2490 {"RPC-SRVSVC", torture_rpc_srvsvc, 0},
2491 {"RPC-SVCCTL", torture_rpc_svcctl, 0},
2492 {"RPC-ATSVC", torture_rpc_atsvc, 0},
2493 {"RPC-EVENTLOG", torture_rpc_eventlog, 0},
2494 {"RPC-EPMAPPER", torture_rpc_epmapper, 0},
2495 {"RPC-WINREG", torture_rpc_winreg, 0},
2496 {"RPC-OXIDRESOLVE", torture_rpc_oxidresolve, 0},
2497 {"RPC-REMACT", torture_rpc_remact, 0},
2498 {"RPC-MGMT", torture_rpc_mgmt, 0},
2499 {"RPC-SCANNER", torture_rpc_scanner, 0},
2500 {"RPC-AUTOIDL", torture_rpc_autoidl, 0},
2501 {"RPC-COUNTCALLS", torture_rpc_countcalls, 0},
2502 {"RPC-MULTIBIND", torture_multi_bind, 0},
2503 {"RPC-DRSUAPI", torture_rpc_drsuapi, 0},
2505 /* local (no server) testers */
2506 {"LOCAL-NTLMSSP", torture_ntlmssp_self_check, 0},
2507 {"LOCAL-ICONV", torture_local_iconv, 0},
2508 {"LOCAL-TALLOC", torture_local_talloc, 0},
2509 {"LOCAL-MESSAGING", torture_local_messaging, 0},
2510 {"LOCAL-BINDING", torture_local_binding_string, 0},
2511 {"LOCAL-IDTREE", torture_local_idtree, 0},
2514 {"LDAP-BASIC", torture_ldap_basic, 0},
2520 /****************************************************************************
2521 run a specified test or "ALL"
2522 ****************************************************************************/
2523 static BOOL run_test(const char *name)
2527 BOOL matched = False;
2529 if (strequal(name,"ALL")) {
2530 for (i=0;torture_ops[i].name;i++) {
2531 if (!run_test(torture_ops[i].name)) {
2538 for (i=0;torture_ops[i].name;i++) {
2539 if (gen_fnmatch(name, torture_ops[i].name) == 0) {
2543 printf("Running %s\n", torture_ops[i].name);
2544 if (torture_ops[i].multi_fn) {
2546 t = torture_create_procs(torture_ops[i].multi_fn,
2550 printf("TEST %s FAILED!\n", torture_ops[i].name);
2555 if (!torture_ops[i].fn()) {
2557 printf("TEST %s FAILED!\n", torture_ops[i].name);
2561 printf("%s took %g secs\n\n", torture_ops[i].name, t);
2566 printf("Unknown torture operation '%s'\n", name);
2573 static void parse_dns(const char *dns)
2575 char *userdn, *basedn, *secret;
2578 /* retrievieng the userdn */
2579 p = strchr_m(dns, '#');
2581 lp_set_cmdline("torture:ldap_userdn", "");
2582 lp_set_cmdline("torture:ldap_basedn", "");
2583 lp_set_cmdline("torture:ldap_secret", "");
2586 userdn = strndup(dns, p - dns);
2587 lp_set_cmdline("torture:ldap_userdn", userdn);
2589 /* retrieve the basedn */
2591 p = strchr_m(d, '#');
2593 lp_set_cmdline("torture:ldap_basedn", "");
2594 lp_set_cmdline("torture:ldap_secret", "");
2597 basedn = strndup(d, p - d);
2598 lp_set_cmdline("torture:ldap_basedn", basedn);
2600 /* retrieve the secret */
2603 lp_set_cmdline("torture:ldap_secret", "");
2607 lp_set_cmdline("torture:ldap_secret", secret);
2609 printf ("%s - %s - %s\n", userdn, basedn, secret);
2613 static void usage(poptContext pc)
2618 poptPrintUsage(pc, stdout, 0);
2621 printf("tests are:");
2622 for (i=0;torture_ops[i].name;i++) {
2623 if ((i%perline)==0) {
2626 printf("%s ", torture_ops[i].name);
2630 printf("default test is ALL\n");
2635 static BOOL is_binding_string(const char *binding_string)
2637 TALLOC_CTX *mem_ctx = talloc_init("is_binding_string");
2638 struct dcerpc_binding binding_struct;
2641 status = dcerpc_parse_binding(mem_ctx, binding_string, &binding_struct);
2643 talloc_destroy(mem_ctx);
2644 return NT_STATUS_IS_OK(status);
2647 /****************************************************************************
2649 ****************************************************************************/
2650 int main(int argc,char *argv[])
2654 BOOL correct = True;
2658 enum {OPT_LOADFILE=1000,OPT_UNCLIST,OPT_TIMELIMIT,OPT_DNS,OPT_DANGEROUS};
2659 struct poptOption long_options[] = {
2661 {"smb-ports", 'p', POPT_ARG_STRING, NULL, 0, "SMB ports", NULL},
2662 {"seed", 0, POPT_ARG_INT, &torture_seed, 0, "seed", NULL},
2663 {"num-progs", 0, POPT_ARG_INT, &torture_nprocs, 0, "num progs", NULL},
2664 {"num-ops", 0, POPT_ARG_INT, &torture_numops, 0, "num ops", NULL},
2665 {"entries", 0, POPT_ARG_INT, &torture_entries, 0, "entries", NULL},
2666 {"use-oplocks", 'L', POPT_ARG_NONE, &use_oplocks, 0, "use oplocks", NULL},
2667 {"show-all", 0, POPT_ARG_NONE, &torture_showall, 0, "show all", NULL},
2668 {"loadfile", 0, POPT_ARG_STRING, NULL, OPT_LOADFILE, "loadfile", NULL},
2669 {"unclist", 0, POPT_ARG_STRING, NULL, OPT_UNCLIST, "unclist", NULL},
2670 {"timelimit", 't', POPT_ARG_STRING, NULL, OPT_TIMELIMIT, "timelimit", NULL},
2671 {"failures", 'f', POPT_ARG_INT, &torture_failures, 0, "failures", NULL},
2672 {"parse-dns", 'D', POPT_ARG_STRING, NULL, OPT_DNS, "parse-dns", NULL},
2673 {"dangerous", 'X', POPT_ARG_NONE, NULL, OPT_DANGEROUS, "dangerous", NULL},
2675 POPT_COMMON_CONNECTION
2676 POPT_COMMON_CREDENTIALS
2681 setup_logging("smbtorture", DEBUG_STDOUT);
2683 #ifdef HAVE_SETBUFFER
2684 setbuffer(stdout, NULL, 0);
2687 pc = poptGetContext("smbtorture", argc, (const char **) argv, long_options,
2688 POPT_CONTEXT_KEEP_FIRST);
2690 poptSetOtherOptionHelp(pc, "<binding>|<unc> TEST1 TEST2 ...");
2692 while((opt = poptGetNextOpt(pc)) != -1) {
2695 lp_set_cmdline("torture:loadfile", poptGetOptArg(pc));
2698 lp_set_cmdline("torture:unclist", poptGetOptArg(pc));
2701 lp_set_cmdline("torture:timelimit", poptGetOptArg(pc));
2704 parse_dns(poptGetOptArg(pc));
2707 lp_set_cmdline("torture:dangerous", "1");
2710 d_printf("Invalid option %s: %s\n",
2711 poptBadOption(pc, 0), poptStrerror(opt));
2717 lp_load(dyn_CONFIGFILE,True,False,False);
2719 if (torture_seed == 0) {
2720 torture_seed = time(NULL);
2722 printf("Using seed %d\n", torture_seed);
2723 srandom(torture_seed);
2725 argv_new = discard_const_p(char *, poptGetArgs(pc));
2728 for (i=0; i<argc; i++) {
2729 if (argv_new[i] == NULL) {
2740 for(p = argv_new[1]; *p; p++) {
2745 /* see if its a RPC transport specifier */
2746 if (is_binding_string(argv_new[1])) {
2747 lp_set_cmdline("torture:binding", argv_new[1]);
2749 char *binding = NULL;
2750 char *host = NULL, *share = NULL;
2752 if (!parse_unc(argv_new[1], &host, &share)) {
2753 d_printf("Invalid option: %s is not a valid torture target (share or binding string)\n\n", argv_new[1]);
2757 lp_set_cmdline("torture:host", host);
2758 lp_set_cmdline("torture:share", share);
2759 asprintf(&binding, "ncacn_np:%s", host);
2760 lp_set_cmdline("torture:binding", binding);
2763 if (!lp_parm_string(-1,"torture","username")) {
2764 lp_set_cmdline("torture:username", cmdline_get_username());
2766 if (!lp_parm_string(-1,"torture","userdomain")) {
2768 * backward compatibility
2769 * maybe we should remove this to make this consistent
2770 * for all cmdline tools
2773 if (strequal(lp_netbios_name(),cmdline_get_userdomain())) {
2774 cmdline_set_userdomain(lp_workgroup());
2776 lp_set_cmdline("torture:userdomain", cmdline_get_userdomain());
2778 if (!lp_parm_string(-1,"torture","password")) {
2779 lp_set_cmdline("torture:password", cmdline_get_userpassword());
2782 if (argc_new == 0) {
2783 printf("You must specify a test to run, or 'ALL'\n");
2785 for (i=2;i<argc_new;i++) {
2786 if (!run_test(argv_new[i])) {