2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1997-1998
5 Copyright (C) Jeremy Allison 2009
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "system/shmem.h"
23 #include "wbc_async.h"
24 #include "torture/proto.h"
25 #include "libcli/security/security.h"
27 #include "tldap_util.h"
28 #include "../librpc/gen_ndr/svcctl.h"
30 #include "nsswitch/winbind_client.h"
32 #include "dbwrap/dbwrap_open.h"
33 #include "talloc_dict.h"
34 #include "async_smb.h"
35 #include "libsmb/libsmb.h"
36 #include "libsmb/clirap.h"
38 #include "libsmb/nmblib.h"
39 #include "../lib/util/tevent_ntstatus.h"
41 #include "libsmb/read_smb.h"
46 fstring host, workgroup, share, password, username, myname;
47 static int max_protocol = PROTOCOL_NT1;
48 static const char *sockops="TCP_NODELAY";
50 static int port_to_use=0;
51 int torture_numops=100;
52 int torture_blocksize=1024*1024;
53 static int procnum; /* records process count number when forking */
54 static struct cli_state *current_cli;
55 static fstring randomfname;
56 static bool use_oplocks;
57 static bool use_level_II_oplocks;
58 static const char *client_txt = "client_oplocks.txt";
59 static bool use_kerberos;
60 static fstring multishare_conn_fname;
61 static bool use_multishare_conn = False;
62 static bool do_encrypt;
63 static const char *local_path = NULL;
64 static int signing_state = Undefined;
67 bool torture_showall = False;
69 static double create_procs(bool (*fn)(int), bool *result);
72 /* return a pointer to a anonymous shared memory segment of size "size"
73 which will persist across fork() but will disappear when all processes
76 The memory is not zeroed
78 This function uses system5 shared memory. It takes advantage of a property
79 that the memory is not destroyed if it is attached when the id is removed
81 void *shm_setup(int size)
87 shmid = shm_open("private", O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
89 printf("can't get shared memory\n");
92 shm_unlink("private");
93 if (ftruncate(shmid, size) == -1) {
94 printf("can't set shared memory size\n");
97 ret = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, shmid, 0);
98 if (ret == MAP_FAILED) {
99 printf("can't map shared memory\n");
103 shmid = shmget(IPC_PRIVATE, size, S_IRUSR | S_IWUSR);
105 printf("can't get shared memory\n");
108 ret = (void *)shmat(shmid, 0, 0);
109 if (!ret || ret == (void *)-1) {
110 printf("can't attach to shared memory\n");
113 /* the following releases the ipc, but note that this process
114 and all its children will still have access to the memory, its
115 just that the shmid is no longer valid for other shm calls. This
116 means we don't leave behind lots of shm segments after we exit
118 See Stevens "advanced programming in unix env" for details
120 shmctl(shmid, IPC_RMID, 0);
126 /********************************************************************
127 Ensure a connection is encrypted.
128 ********************************************************************/
130 static bool force_cli_encryption(struct cli_state *c,
131 const char *sharename)
134 uint32 caplow, caphigh;
137 if (!SERVER_HAS_UNIX_CIFS(c)) {
138 d_printf("Encryption required and "
139 "server that doesn't support "
140 "UNIX extensions - failing connect\n");
144 status = cli_unix_extensions_version(c, &major, &minor, &caplow,
146 if (!NT_STATUS_IS_OK(status)) {
147 d_printf("Encryption required and "
148 "can't get UNIX CIFS extensions "
149 "version from server: %s\n", nt_errstr(status));
153 if (!(caplow & CIFS_UNIX_TRANSPORT_ENCRYPTION_CAP)) {
154 d_printf("Encryption required and "
155 "share %s doesn't support "
156 "encryption.\n", sharename);
160 if (c->use_kerberos) {
161 status = cli_gss_smb_encryption_start(c);
163 status = cli_raw_ntlm_smb_encryption_start(c,
169 if (!NT_STATUS_IS_OK(status)) {
170 d_printf("Encryption required and "
171 "setup failed with error %s.\n",
180 static struct cli_state *open_nbt_connection(void)
185 status = cli_connect_nb(host, NULL, port_to_use, 0x20, myname,
187 if (!NT_STATUS_IS_OK(status)) {
188 printf("Failed to connect with %s. Error %s\n", host, nt_errstr(status) );
192 c->use_kerberos = use_kerberos;
194 c->timeout = 120000; /* set a really long timeout (2 minutes) */
195 if (use_oplocks) c->use_oplocks = True;
196 if (use_level_II_oplocks) c->use_level_II_oplocks = True;
201 /****************************************************************************
202 Send a corrupt session request. See rfc1002.txt 4.3 and 4.3.2.
203 ****************************************************************************/
205 static bool cli_bad_session_request(int fd,
206 struct nmb_name *calling, struct nmb_name *called)
215 uint8_t message_type;
218 frame = talloc_stackframe();
220 iov[0].iov_base = len_buf;
221 iov[0].iov_len = sizeof(len_buf);
223 /* put in the destination name */
225 iov[1].iov_base = name_mangle(talloc_tos(), called->name,
227 if (iov[1].iov_base == NULL) {
230 iov[1].iov_len = name_len((unsigned char *)iov[1].iov_base,
231 talloc_get_size(iov[1].iov_base));
235 iov[2].iov_base = name_mangle(talloc_tos(), calling->name,
237 if (iov[2].iov_base == NULL) {
240 iov[2].iov_len = name_len((unsigned char *)iov[2].iov_base,
241 talloc_get_size(iov[2].iov_base));
243 /* Deliberately corrupt the name len (first byte) */
244 *((uint8_t *)iov[2].iov_base) = 100;
246 /* send a session request (RFC 1002) */
247 /* setup the packet length
248 * Remove four bytes from the length count, since the length
249 * field in the NBT Session Service header counts the number
250 * of bytes which follow. The cli_send_smb() function knows
251 * about this and accounts for those four bytes.
255 _smb_setlen(len_buf, iov[1].iov_len + iov[2].iov_len);
256 SCVAL(len_buf,0,0x81);
258 len = write_data_iov(fd, iov, 3);
262 len = read_smb(fd, talloc_tos(), &inbuf, &err);
268 message_type = CVAL(inbuf, 0);
269 if (message_type != 0x83) {
270 d_fprintf(stderr, "Expected msg type 0x83, got 0x%2.2x\n",
275 if (smb_len(inbuf) != 1) {
276 d_fprintf(stderr, "Expected smb_len 1, got %d\n",
277 (int)smb_len(inbuf));
281 error = CVAL(inbuf, 4);
283 d_fprintf(stderr, "Expected error 0x82, got %d\n",
294 /* Insert a NULL at the first separator of the given path and return a pointer
295 * to the remainder of the string.
298 terminate_path_at_separator(char * path)
306 if ((p = strchr_m(path, '/'))) {
311 if ((p = strchr_m(path, '\\'))) {
321 parse a //server/share type UNC name
323 bool smbcli_parse_unc(const char *unc_name, TALLOC_CTX *mem_ctx,
324 char **hostname, char **sharename)
328 *hostname = *sharename = NULL;
330 if (strncmp(unc_name, "\\\\", 2) &&
331 strncmp(unc_name, "//", 2)) {
335 *hostname = talloc_strdup(mem_ctx, &unc_name[2]);
336 p = terminate_path_at_separator(*hostname);
339 *sharename = talloc_strdup(mem_ctx, p);
340 terminate_path_at_separator(*sharename);
343 if (*hostname && *sharename) {
347 TALLOC_FREE(*hostname);
348 TALLOC_FREE(*sharename);
352 static bool torture_open_connection_share(struct cli_state **c,
353 const char *hostname,
354 const char *sharename)
360 flags |= CLI_FULL_CONNECTION_USE_KERBEROS;
362 flags |= CLI_FULL_CONNECTION_OPLOCKS;
363 if (use_level_II_oplocks)
364 flags |= CLI_FULL_CONNECTION_LEVEL_II_OPLOCKS;
366 status = cli_full_connection(c, myname,
367 hostname, NULL, port_to_use,
370 password, flags, signing_state);
371 if (!NT_STATUS_IS_OK(status)) {
372 printf("failed to open share connection: //%s/%s port:%d - %s\n",
373 hostname, sharename, port_to_use, nt_errstr(status));
377 (*c)->timeout = 120000; /* set a really long timeout (2 minutes) */
380 return force_cli_encryption(*c,
386 bool torture_open_connection(struct cli_state **c, int conn_index)
388 char **unc_list = NULL;
389 int num_unc_names = 0;
392 if (use_multishare_conn==True) {
394 unc_list = file_lines_load(multishare_conn_fname, &num_unc_names, 0, NULL);
395 if (!unc_list || num_unc_names <= 0) {
396 printf("Failed to load unc names list from '%s'\n", multishare_conn_fname);
400 if (!smbcli_parse_unc(unc_list[conn_index % num_unc_names],
402 printf("Failed to parse UNC name %s\n",
403 unc_list[conn_index % num_unc_names]);
404 TALLOC_FREE(unc_list);
408 result = torture_open_connection_share(c, h, s);
410 /* h, s were copied earlier */
411 TALLOC_FREE(unc_list);
415 return torture_open_connection_share(c, host, share);
418 bool torture_init_connection(struct cli_state **pcli)
420 struct cli_state *cli;
422 cli = open_nbt_connection();
431 bool torture_cli_session_setup2(struct cli_state *cli, uint16 *new_vuid)
433 uint16_t old_vuid = cli_state_get_uid(cli);
434 fstring old_user_name;
435 size_t passlen = strlen(password);
439 fstrcpy(old_user_name, cli->user_name);
440 cli_state_set_uid(cli, 0);
441 ret = NT_STATUS_IS_OK(cli_session_setup(cli, username,
445 *new_vuid = cli_state_get_uid(cli);
446 cli_state_set_uid(cli, old_vuid);
447 status = cli_set_username(cli, old_user_name);
448 if (!NT_STATUS_IS_OK(status)) {
455 bool torture_close_connection(struct cli_state *c)
460 status = cli_tdis(c);
461 if (!NT_STATUS_IS_OK(status)) {
462 printf("tdis failed (%s)\n", nt_errstr(status));
472 /* check if the server produced the expected dos or nt error code */
473 static bool check_both_error(int line, NTSTATUS status,
474 uint8 eclass, uint32 ecode, NTSTATUS nterr)
476 if (NT_STATUS_IS_DOS(status)) {
480 /* Check DOS error */
481 cclass = NT_STATUS_DOS_CLASS(status);
482 num = NT_STATUS_DOS_CODE(status);
484 if (eclass != cclass || ecode != num) {
485 printf("unexpected error code class=%d code=%d\n",
486 (int)cclass, (int)num);
487 printf(" expected %d/%d %s (line=%d)\n",
488 (int)eclass, (int)ecode, nt_errstr(nterr), line);
493 if (!NT_STATUS_EQUAL(nterr, status)) {
494 printf("unexpected error code %s\n",
496 printf(" expected %s (line=%d)\n",
497 nt_errstr(nterr), line);
506 /* check if the server produced the expected error code */
507 static bool check_error(int line, NTSTATUS status,
508 uint8 eclass, uint32 ecode, NTSTATUS nterr)
510 if (NT_STATUS_IS_DOS(status)) {
514 /* Check DOS error */
516 cclass = NT_STATUS_DOS_CLASS(status);
517 num = NT_STATUS_DOS_CODE(status);
519 if (eclass != cclass || ecode != num) {
520 printf("unexpected error code class=%d code=%d\n",
521 (int)cclass, (int)num);
522 printf(" expected %d/%d %s (line=%d)\n",
523 (int)eclass, (int)ecode, nt_errstr(nterr),
531 if (NT_STATUS_V(nterr) != NT_STATUS_V(status)) {
532 printf("unexpected error code %s\n",
534 printf(" expected %s (line=%d)\n", nt_errstr(nterr),
544 static bool wait_lock(struct cli_state *c, int fnum, uint32 offset, uint32 len)
548 status = cli_lock32(c, fnum, offset, len, -1, WRITE_LOCK);
550 while (!NT_STATUS_IS_OK(status)) {
551 if (!check_both_error(__LINE__, status, ERRDOS,
552 ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) {
556 status = cli_lock32(c, fnum, offset, len, -1, WRITE_LOCK);
563 static bool rw_torture(struct cli_state *c)
565 const char *lockfname = "\\torture.lck";
569 pid_t pid2, pid = getpid();
576 memset(buf, '\0', sizeof(buf));
578 status = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
580 if (!NT_STATUS_IS_OK(status)) {
581 status = cli_open(c, lockfname, O_RDWR, DENY_NONE, &fnum2);
583 if (!NT_STATUS_IS_OK(status)) {
584 printf("open of %s failed (%s)\n",
585 lockfname, nt_errstr(status));
589 for (i=0;i<torture_numops;i++) {
590 unsigned n = (unsigned)sys_random()%10;
593 printf("%d\r", i); fflush(stdout);
595 slprintf(fname, sizeof(fstring) - 1, "\\torture.%u", n);
597 if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) {
601 status = cli_open(c, fname, O_RDWR | O_CREAT | O_TRUNC,
603 if (!NT_STATUS_IS_OK(status)) {
604 printf("open failed (%s)\n", nt_errstr(status));
609 status = cli_writeall(c, fnum, 0, (uint8_t *)&pid, 0,
611 if (!NT_STATUS_IS_OK(status)) {
612 printf("write failed (%s)\n", nt_errstr(status));
617 status = cli_writeall(c, fnum, 0, (uint8_t *)buf,
618 sizeof(pid)+(j*sizeof(buf)),
620 if (!NT_STATUS_IS_OK(status)) {
621 printf("write failed (%s)\n",
629 status = cli_read(c, fnum, (char *)&pid2, 0, sizeof(pid),
631 if (!NT_STATUS_IS_OK(status)) {
632 printf("read failed (%s)\n", nt_errstr(status));
634 } else if (nread != sizeof(pid)) {
635 printf("read/write compare failed: "
636 "recv %ld req %ld\n", (unsigned long)nread,
637 (unsigned long)sizeof(pid));
642 printf("data corruption!\n");
646 status = cli_close(c, fnum);
647 if (!NT_STATUS_IS_OK(status)) {
648 printf("close failed (%s)\n", nt_errstr(status));
652 status = cli_unlink(c, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
653 if (!NT_STATUS_IS_OK(status)) {
654 printf("unlink failed (%s)\n", nt_errstr(status));
658 status = cli_unlock(c, fnum2, n*sizeof(int), sizeof(int));
659 if (!NT_STATUS_IS_OK(status)) {
660 printf("unlock failed (%s)\n", nt_errstr(status));
666 cli_unlink(c, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
673 static bool run_torture(int dummy)
675 struct cli_state *cli;
680 cli_sockopt(cli, sockops);
682 ret = rw_torture(cli);
684 if (!torture_close_connection(cli)) {
691 static bool rw_torture3(struct cli_state *c, char *lockfname)
693 uint16_t fnum = (uint16_t)-1;
698 unsigned countprev = 0;
701 NTSTATUS status = NT_STATUS_OK;
704 for (i = 0; i < sizeof(buf); i += sizeof(uint32))
706 SIVAL(buf, i, sys_random());
713 FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
714 if (!NT_STATUS_IS_OK(status)) {
715 printf("unlink failed (%s) (normal, this file should "
716 "not exist)\n", nt_errstr(status));
719 status = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
721 if (!NT_STATUS_IS_OK(status)) {
722 printf("first open read/write of %s failed (%s)\n",
723 lockfname, nt_errstr(status));
729 for (i = 0; i < 500 && fnum == (uint16_t)-1; i++)
731 status = cli_open(c, lockfname, O_RDONLY,
733 if (!NT_STATUS_IS_OK(status)) {
738 if (!NT_STATUS_IS_OK(status)) {
739 printf("second open read-only of %s failed (%s)\n",
740 lockfname, nt_errstr(status));
746 for (count = 0; count < sizeof(buf); count += sent)
748 if (count >= countprev) {
749 printf("%d %8d\r", i, count);
752 countprev += (sizeof(buf) / 20);
757 sent = ((unsigned)sys_random()%(20))+ 1;
758 if (sent > sizeof(buf) - count)
760 sent = sizeof(buf) - count;
763 status = cli_writeall(c, fnum, 0, (uint8_t *)buf+count,
765 if (!NT_STATUS_IS_OK(status)) {
766 printf("write failed (%s)\n",
773 status = cli_read(c, fnum, buf_rd+count, count,
774 sizeof(buf)-count, &sent);
775 if(!NT_STATUS_IS_OK(status)) {
776 printf("read failed offset:%d size:%ld (%s)\n",
777 count, (unsigned long)sizeof(buf)-count,
781 } else if (sent > 0) {
782 if (memcmp(buf_rd+count, buf+count, sent) != 0)
784 printf("read/write compare failed\n");
785 printf("offset: %d req %ld recvd %ld\n", count, (unsigned long)sizeof(buf)-count, (unsigned long)sent);
794 status = cli_close(c, fnum);
795 if (!NT_STATUS_IS_OK(status)) {
796 printf("close failed (%s)\n", nt_errstr(status));
803 static bool rw_torture2(struct cli_state *c1, struct cli_state *c2)
805 const char *lockfname = "\\torture2.lck";
815 status = cli_unlink(c1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
816 if (!NT_STATUS_IS_OK(status)) {
817 printf("unlink failed (%s) (normal, this file should not exist)\n", nt_errstr(status));
820 status = cli_open(c1, lockfname, O_RDWR | O_CREAT | O_EXCL,
822 if (!NT_STATUS_IS_OK(status)) {
823 printf("first open read/write of %s failed (%s)\n",
824 lockfname, nt_errstr(status));
828 status = cli_open(c2, lockfname, O_RDONLY, DENY_NONE, &fnum2);
829 if (!NT_STATUS_IS_OK(status)) {
830 printf("second open read-only of %s failed (%s)\n",
831 lockfname, nt_errstr(status));
832 cli_close(c1, fnum1);
836 for (i = 0; i < torture_numops; i++)
838 size_t buf_size = ((unsigned)sys_random()%(sizeof(buf)-1))+ 1;
840 printf("%d\r", i); fflush(stdout);
843 generate_random_buffer((unsigned char *)buf, buf_size);
845 status = cli_writeall(c1, fnum1, 0, (uint8_t *)buf, 0,
847 if (!NT_STATUS_IS_OK(status)) {
848 printf("write failed (%s)\n", nt_errstr(status));
853 status = cli_read(c2, fnum2, buf_rd, 0, buf_size, &bytes_read);
854 if(!NT_STATUS_IS_OK(status)) {
855 printf("read failed (%s)\n", nt_errstr(status));
858 } else if (bytes_read != buf_size) {
859 printf("read failed\n");
860 printf("read %ld, expected %ld\n",
861 (unsigned long)bytes_read,
862 (unsigned long)buf_size);
867 if (memcmp(buf_rd, buf, buf_size) != 0)
869 printf("read/write compare failed\n");
875 status = cli_close(c2, fnum2);
876 if (!NT_STATUS_IS_OK(status)) {
877 printf("close failed (%s)\n", nt_errstr(status));
881 status = cli_close(c1, fnum1);
882 if (!NT_STATUS_IS_OK(status)) {
883 printf("close failed (%s)\n", nt_errstr(status));
887 status = cli_unlink(c1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
888 if (!NT_STATUS_IS_OK(status)) {
889 printf("unlink failed (%s)\n", nt_errstr(status));
896 static bool run_readwritetest(int dummy)
898 struct cli_state *cli1, *cli2;
899 bool test1, test2 = False;
901 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
904 cli_sockopt(cli1, sockops);
905 cli_sockopt(cli2, sockops);
907 printf("starting readwritetest\n");
909 test1 = rw_torture2(cli1, cli2);
910 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1));
913 test2 = rw_torture2(cli1, cli1);
914 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2));
917 if (!torture_close_connection(cli1)) {
921 if (!torture_close_connection(cli2)) {
925 return (test1 && test2);
928 static bool run_readwritemulti(int dummy)
930 struct cli_state *cli;
935 cli_sockopt(cli, sockops);
937 printf("run_readwritemulti: fname %s\n", randomfname);
938 test = rw_torture3(cli, randomfname);
940 if (!torture_close_connection(cli)) {
947 static bool run_readwritelarge_internal(int max_xmit_k)
949 static struct cli_state *cli1;
951 const char *lockfname = "\\large.dat";
957 if (!torture_open_connection(&cli1, 0)) {
960 cli_sockopt(cli1, sockops);
961 memset(buf,'\0',sizeof(buf));
963 cli1->max_xmit = max_xmit_k*1024;
965 if (signing_state == Required) {
966 /* Horrible cheat to force
967 multiple signed outstanding
968 packets against a Samba server.
970 cli1->is_samba = false;
973 printf("starting readwritelarge_internal\n");
975 cli_unlink(cli1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
977 status = cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL,
979 if (!NT_STATUS_IS_OK(status)) {
980 printf("open read/write of %s failed (%s)\n", lockfname, nt_errstr(status));
984 cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 0, sizeof(buf), NULL);
986 status = cli_qfileinfo_basic(cli1, fnum1, NULL, &fsize, NULL, NULL,
988 if (!NT_STATUS_IS_OK(status)) {
989 printf("qfileinfo failed (%s)\n", nt_errstr(status));
993 if (fsize == sizeof(buf))
994 printf("readwritelarge_internal test 1 succeeded (size = %lx)\n",
995 (unsigned long)fsize);
997 printf("readwritelarge_internal test 1 failed (size = %lx)\n",
998 (unsigned long)fsize);
1002 status = cli_close(cli1, fnum1);
1003 if (!NT_STATUS_IS_OK(status)) {
1004 printf("close failed (%s)\n", nt_errstr(status));
1008 status = cli_unlink(cli1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1009 if (!NT_STATUS_IS_OK(status)) {
1010 printf("unlink failed (%s)\n", nt_errstr(status));
1014 status = cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL,
1016 if (!NT_STATUS_IS_OK(status)) {
1017 printf("open read/write of %s failed (%s)\n", lockfname, nt_errstr(status));
1021 cli1->max_xmit = 4*1024;
1023 cli_smbwrite(cli1, fnum1, buf, 0, sizeof(buf), NULL);
1025 status = cli_qfileinfo_basic(cli1, fnum1, NULL, &fsize, NULL, NULL,
1027 if (!NT_STATUS_IS_OK(status)) {
1028 printf("qfileinfo failed (%s)\n", nt_errstr(status));
1032 if (fsize == sizeof(buf))
1033 printf("readwritelarge_internal test 2 succeeded (size = %lx)\n",
1034 (unsigned long)fsize);
1036 printf("readwritelarge_internal test 2 failed (size = %lx)\n",
1037 (unsigned long)fsize);
1042 /* ToDo - set allocation. JRA */
1043 if(!cli_set_allocation_size(cli1, fnum1, 0)) {
1044 printf("set allocation size to zero failed (%s)\n", cli_errstr(&cli1));
1047 if (!cli_qfileinfo_basic(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL,
1049 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
1053 printf("readwritelarge test 3 (truncate test) succeeded (size = %x)\n", fsize);
1056 status = cli_close(cli1, fnum1);
1057 if (!NT_STATUS_IS_OK(status)) {
1058 printf("close failed (%s)\n", nt_errstr(status));
1062 if (!torture_close_connection(cli1)) {
1068 static bool run_readwritelarge(int dummy)
1070 return run_readwritelarge_internal(128);
1073 static bool run_readwritelarge_signtest(int dummy)
1076 signing_state = Required;
1077 ret = run_readwritelarge_internal(2);
1078 signing_state = Undefined;
1085 #define ival(s) strtol(s, NULL, 0)
1087 /* run a test that simulates an approximate netbench client load */
1088 static bool run_netbench(int client)
1090 struct cli_state *cli;
1095 const char *params[20];
1096 bool correct = True;
1102 cli_sockopt(cli, sockops);
1106 slprintf(cname,sizeof(cname)-1, "client%d", client);
1108 f = fopen(client_txt, "r");
1115 while (fgets(line, sizeof(line)-1, f)) {
1119 line[strlen(line)-1] = 0;
1121 /* printf("[%d] %s\n", line_count, line); */
1123 all_string_sub(line,"client1", cname, sizeof(line));
1125 /* parse the command parameters */
1126 params[0] = strtok_r(line, " ", &saveptr);
1128 while (params[i]) params[++i] = strtok_r(NULL, " ", &saveptr);
1132 if (i < 2) continue;
1134 if (!strncmp(params[0],"SMB", 3)) {
1135 printf("ERROR: You are using a dbench 1 load file\n");
1139 if (!strcmp(params[0],"NTCreateX")) {
1140 nb_createx(params[1], ival(params[2]), ival(params[3]),
1142 } else if (!strcmp(params[0],"Close")) {
1143 nb_close(ival(params[1]));
1144 } else if (!strcmp(params[0],"Rename")) {
1145 nb_rename(params[1], params[2]);
1146 } else if (!strcmp(params[0],"Unlink")) {
1147 nb_unlink(params[1]);
1148 } else if (!strcmp(params[0],"Deltree")) {
1149 nb_deltree(params[1]);
1150 } else if (!strcmp(params[0],"Rmdir")) {
1151 nb_rmdir(params[1]);
1152 } else if (!strcmp(params[0],"QUERY_PATH_INFORMATION")) {
1153 nb_qpathinfo(params[1]);
1154 } else if (!strcmp(params[0],"QUERY_FILE_INFORMATION")) {
1155 nb_qfileinfo(ival(params[1]));
1156 } else if (!strcmp(params[0],"QUERY_FS_INFORMATION")) {
1157 nb_qfsinfo(ival(params[1]));
1158 } else if (!strcmp(params[0],"FIND_FIRST")) {
1159 nb_findfirst(params[1]);
1160 } else if (!strcmp(params[0],"WriteX")) {
1161 nb_writex(ival(params[1]),
1162 ival(params[2]), ival(params[3]), ival(params[4]));
1163 } else if (!strcmp(params[0],"ReadX")) {
1164 nb_readx(ival(params[1]),
1165 ival(params[2]), ival(params[3]), ival(params[4]));
1166 } else if (!strcmp(params[0],"Flush")) {
1167 nb_flush(ival(params[1]));
1169 printf("Unknown operation %s\n", params[0]);
1177 if (!torture_close_connection(cli)) {
1185 /* run a test that simulates an approximate netbench client load */
1186 static bool run_nbench(int dummy)
1189 bool correct = True;
1195 signal(SIGALRM, nb_alarm);
1197 t = create_procs(run_netbench, &correct);
1200 printf("\nThroughput %g MB/sec\n",
1201 1.0e-6 * nbio_total() / t);
1207 This test checks for two things:
1209 1) correct support for retaining locks over a close (ie. the server
1210 must not use posix semantics)
1211 2) support for lock timeouts
1213 static bool run_locktest1(int dummy)
1215 struct cli_state *cli1, *cli2;
1216 const char *fname = "\\lockt1.lck";
1217 uint16_t fnum1, fnum2, fnum3;
1219 unsigned lock_timeout;
1222 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1225 cli_sockopt(cli1, sockops);
1226 cli_sockopt(cli2, sockops);
1228 printf("starting locktest1\n");
1230 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1232 status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
1234 if (!NT_STATUS_IS_OK(status)) {
1235 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
1239 status = cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum2);
1240 if (!NT_STATUS_IS_OK(status)) {
1241 printf("open2 of %s failed (%s)\n", fname, nt_errstr(status));
1245 status = cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum3);
1246 if (!NT_STATUS_IS_OK(status)) {
1247 printf("open3 of %s failed (%s)\n", fname, nt_errstr(status));
1251 status = cli_lock32(cli1, fnum1, 0, 4, 0, WRITE_LOCK);
1252 if (!NT_STATUS_IS_OK(status)) {
1253 printf("lock1 failed (%s)\n", nt_errstr(status));
1257 status = cli_lock32(cli2, fnum3, 0, 4, 0, WRITE_LOCK);
1258 if (NT_STATUS_IS_OK(status)) {
1259 printf("lock2 succeeded! This is a locking bug\n");
1262 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1263 NT_STATUS_LOCK_NOT_GRANTED)) {
1268 lock_timeout = (1 + (random() % 20));
1269 printf("Testing lock timeout with timeout=%u\n", lock_timeout);
1271 status = cli_lock32(cli2, fnum3, 0, 4, lock_timeout * 1000, WRITE_LOCK);
1272 if (NT_STATUS_IS_OK(status)) {
1273 printf("lock3 succeeded! This is a locking bug\n");
1276 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1277 NT_STATUS_FILE_LOCK_CONFLICT)) {
1283 if (ABS(t2 - t1) < lock_timeout-1) {
1284 printf("error: This server appears not to support timed lock requests\n");
1287 printf("server slept for %u seconds for a %u second timeout\n",
1288 (unsigned int)(t2-t1), lock_timeout);
1290 status = cli_close(cli1, fnum2);
1291 if (!NT_STATUS_IS_OK(status)) {
1292 printf("close1 failed (%s)\n", nt_errstr(status));
1296 status = cli_lock32(cli2, fnum3, 0, 4, 0, WRITE_LOCK);
1297 if (NT_STATUS_IS_OK(status)) {
1298 printf("lock4 succeeded! This is a locking bug\n");
1301 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1302 NT_STATUS_FILE_LOCK_CONFLICT)) {
1307 status = cli_close(cli1, fnum1);
1308 if (!NT_STATUS_IS_OK(status)) {
1309 printf("close2 failed (%s)\n", nt_errstr(status));
1313 status = cli_close(cli2, fnum3);
1314 if (!NT_STATUS_IS_OK(status)) {
1315 printf("close3 failed (%s)\n", nt_errstr(status));
1319 status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1320 if (!NT_STATUS_IS_OK(status)) {
1321 printf("unlink failed (%s)\n", nt_errstr(status));
1326 if (!torture_close_connection(cli1)) {
1330 if (!torture_close_connection(cli2)) {
1334 printf("Passed locktest1\n");
1339 this checks to see if a secondary tconx can use open files from an
1342 static bool run_tcon_test(int dummy)
1344 static struct cli_state *cli;
1345 const char *fname = "\\tcontest.tmp";
1347 uint16 cnum1, cnum2, cnum3;
1348 uint16 vuid1, vuid2;
1353 memset(buf, '\0', sizeof(buf));
1355 if (!torture_open_connection(&cli, 0)) {
1358 cli_sockopt(cli, sockops);
1360 printf("starting tcontest\n");
1362 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1364 status = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
1365 if (!NT_STATUS_IS_OK(status)) {
1366 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
1370 cnum1 = cli_state_get_tid(cli);
1371 vuid1 = cli_state_get_uid(cli);
1373 status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
1374 if (!NT_STATUS_IS_OK(status)) {
1375 printf("initial write failed (%s)", nt_errstr(status));
1379 status = cli_tcon_andx(cli, share, "?????",
1380 password, strlen(password)+1);
1381 if (!NT_STATUS_IS_OK(status)) {
1382 printf("%s refused 2nd tree connect (%s)\n", host,
1388 cnum2 = cli_state_get_tid(cli);
1389 cnum3 = MAX(cnum1, cnum2) + 1; /* any invalid number */
1390 vuid2 = cli_state_get_uid(cli) + 1;
1392 /* try a write with the wrong tid */
1393 cli_state_set_tid(cli, cnum2);
1395 status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
1396 if (NT_STATUS_IS_OK(status)) {
1397 printf("* server allows write with wrong TID\n");
1400 printf("server fails write with wrong TID : %s\n",
1405 /* try a write with an invalid tid */
1406 cli_state_set_tid(cli, cnum3);
1408 status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
1409 if (NT_STATUS_IS_OK(status)) {
1410 printf("* server allows write with invalid TID\n");
1413 printf("server fails write with invalid TID : %s\n",
1417 /* try a write with an invalid vuid */
1418 cli_state_set_uid(cli, vuid2);
1419 cli_state_set_tid(cli, cnum1);
1421 status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
1422 if (NT_STATUS_IS_OK(status)) {
1423 printf("* server allows write with invalid VUID\n");
1426 printf("server fails write with invalid VUID : %s\n",
1430 cli_state_set_tid(cli, cnum1);
1431 cli_state_set_uid(cli, vuid1);
1433 status = cli_close(cli, fnum1);
1434 if (!NT_STATUS_IS_OK(status)) {
1435 printf("close failed (%s)\n", nt_errstr(status));
1439 cli_state_set_tid(cli, cnum2);
1441 status = cli_tdis(cli);
1442 if (!NT_STATUS_IS_OK(status)) {
1443 printf("secondary tdis failed (%s)\n", nt_errstr(status));
1447 cli_state_set_tid(cli, cnum1);
1449 if (!torture_close_connection(cli)) {
1458 checks for old style tcon support
1460 static bool run_tcon2_test(int dummy)
1462 static struct cli_state *cli;
1463 uint16 cnum, max_xmit;
1467 if (!torture_open_connection(&cli, 0)) {
1470 cli_sockopt(cli, sockops);
1472 printf("starting tcon2 test\n");
1474 if (asprintf(&service, "\\\\%s\\%s", host, share) == -1) {
1478 status = cli_raw_tcon(cli, service, password, "?????", &max_xmit, &cnum);
1482 if (!NT_STATUS_IS_OK(status)) {
1483 printf("tcon2 failed : %s\n", nt_errstr(status));
1485 printf("tcon OK : max_xmit=%d cnum=%d\n",
1486 (int)max_xmit, (int)cnum);
1489 if (!torture_close_connection(cli)) {
1493 printf("Passed tcon2 test\n");
1497 static bool tcon_devtest(struct cli_state *cli,
1498 const char *myshare, const char *devtype,
1499 const char *return_devtype,
1500 NTSTATUS expected_error)
1505 status = cli_tcon_andx(cli, myshare, devtype,
1506 password, strlen(password)+1);
1508 if (NT_STATUS_IS_OK(expected_error)) {
1509 if (NT_STATUS_IS_OK(status)) {
1510 if (strcmp(cli->dev, return_devtype) == 0) {
1513 printf("tconX to share %s with type %s "
1514 "succeeded but returned the wrong "
1515 "device type (got [%s] but should have got [%s])\n",
1516 myshare, devtype, cli->dev, return_devtype);
1520 printf("tconX to share %s with type %s "
1521 "should have succeeded but failed\n",
1527 if (NT_STATUS_IS_OK(status)) {
1528 printf("tconx to share %s with type %s "
1529 "should have failed but succeeded\n",
1533 if (NT_STATUS_EQUAL(cli_nt_error(cli),
1537 printf("Returned unexpected error\n");
1546 checks for correct tconX support
1548 static bool run_tcon_devtype_test(int dummy)
1550 static struct cli_state *cli1 = NULL;
1555 status = cli_full_connection(&cli1, myname,
1556 host, NULL, port_to_use,
1558 username, workgroup,
1559 password, flags, signing_state);
1561 if (!NT_STATUS_IS_OK(status)) {
1562 printf("could not open connection\n");
1566 if (!tcon_devtest(cli1, "IPC$", "A:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1569 if (!tcon_devtest(cli1, "IPC$", "?????", "IPC", NT_STATUS_OK))
1572 if (!tcon_devtest(cli1, "IPC$", "LPT:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1575 if (!tcon_devtest(cli1, "IPC$", "IPC", "IPC", NT_STATUS_OK))
1578 if (!tcon_devtest(cli1, "IPC$", "FOOBA", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1581 if (!tcon_devtest(cli1, share, "A:", "A:", NT_STATUS_OK))
1584 if (!tcon_devtest(cli1, share, "?????", "A:", NT_STATUS_OK))
1587 if (!tcon_devtest(cli1, share, "LPT:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1590 if (!tcon_devtest(cli1, share, "IPC", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1593 if (!tcon_devtest(cli1, share, "FOOBA", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1599 printf("Passed tcondevtest\n");
1606 This test checks that
1608 1) the server supports multiple locking contexts on the one SMB
1609 connection, distinguished by PID.
1611 2) the server correctly fails overlapping locks made by the same PID (this
1612 goes against POSIX behaviour, which is why it is tricky to implement)
1614 3) the server denies unlock requests by an incorrect client PID
1616 static bool run_locktest2(int dummy)
1618 static struct cli_state *cli;
1619 const char *fname = "\\lockt2.lck";
1620 uint16_t fnum1, fnum2, fnum3;
1621 bool correct = True;
1624 if (!torture_open_connection(&cli, 0)) {
1628 cli_sockopt(cli, sockops);
1630 printf("starting locktest2\n");
1632 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1636 status = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
1637 if (!NT_STATUS_IS_OK(status)) {
1638 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
1642 status = cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum2);
1643 if (!NT_STATUS_IS_OK(status)) {
1644 printf("open2 of %s failed (%s)\n", fname, nt_errstr(status));
1650 status = cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum3);
1651 if (!NT_STATUS_IS_OK(status)) {
1652 printf("open3 of %s failed (%s)\n", fname, nt_errstr(status));
1658 status = cli_lock32(cli, fnum1, 0, 4, 0, WRITE_LOCK);
1659 if (!NT_STATUS_IS_OK(status)) {
1660 printf("lock1 failed (%s)\n", nt_errstr(status));
1664 status = cli_lock32(cli, fnum1, 0, 4, 0, WRITE_LOCK);
1665 if (NT_STATUS_IS_OK(status)) {
1666 printf("WRITE lock1 succeeded! This is a locking bug\n");
1669 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1670 NT_STATUS_LOCK_NOT_GRANTED)) {
1675 status = cli_lock32(cli, fnum2, 0, 4, 0, WRITE_LOCK);
1676 if (NT_STATUS_IS_OK(status)) {
1677 printf("WRITE lock2 succeeded! This is a locking bug\n");
1680 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1681 NT_STATUS_LOCK_NOT_GRANTED)) {
1686 status = cli_lock32(cli, fnum2, 0, 4, 0, READ_LOCK);
1687 if (NT_STATUS_IS_OK(status)) {
1688 printf("READ lock2 succeeded! This is a locking bug\n");
1691 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1692 NT_STATUS_FILE_LOCK_CONFLICT)) {
1697 status = cli_lock32(cli, fnum1, 100, 4, 0, WRITE_LOCK);
1698 if (!NT_STATUS_IS_OK(status)) {
1699 printf("lock at 100 failed (%s)\n", nt_errstr(status));
1702 if (NT_STATUS_IS_OK(cli_unlock(cli, fnum1, 100, 4))) {
1703 printf("unlock at 100 succeeded! This is a locking bug\n");
1707 status = cli_unlock(cli, fnum1, 0, 4);
1708 if (NT_STATUS_IS_OK(status)) {
1709 printf("unlock1 succeeded! This is a locking bug\n");
1712 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1713 NT_STATUS_RANGE_NOT_LOCKED)) {
1718 status = cli_unlock(cli, fnum1, 0, 8);
1719 if (NT_STATUS_IS_OK(status)) {
1720 printf("unlock2 succeeded! This is a locking bug\n");
1723 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1724 NT_STATUS_RANGE_NOT_LOCKED)) {
1729 status = cli_lock32(cli, fnum3, 0, 4, 0, WRITE_LOCK);
1730 if (NT_STATUS_IS_OK(status)) {
1731 printf("lock3 succeeded! This is a locking bug\n");
1734 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1735 NT_STATUS_LOCK_NOT_GRANTED)) {
1742 status = cli_close(cli, fnum1);
1743 if (!NT_STATUS_IS_OK(status)) {
1744 printf("close1 failed (%s)\n", nt_errstr(status));
1748 status = cli_close(cli, fnum2);
1749 if (!NT_STATUS_IS_OK(status)) {
1750 printf("close2 failed (%s)\n", nt_errstr(status));
1754 status = cli_close(cli, fnum3);
1755 if (!NT_STATUS_IS_OK(status)) {
1756 printf("close3 failed (%s)\n", nt_errstr(status));
1760 if (!torture_close_connection(cli)) {
1764 printf("locktest2 finished\n");
1771 This test checks that
1773 1) the server supports the full offset range in lock requests
1775 static bool run_locktest3(int dummy)
1777 static struct cli_state *cli1, *cli2;
1778 const char *fname = "\\lockt3.lck";
1779 uint16_t fnum1, fnum2;
1782 bool correct = True;
1785 #define NEXT_OFFSET offset += (~(uint32)0) / torture_numops
1787 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1790 cli_sockopt(cli1, sockops);
1791 cli_sockopt(cli2, sockops);
1793 printf("starting locktest3\n");
1795 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1797 status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
1799 if (!NT_STATUS_IS_OK(status)) {
1800 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
1804 status = cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
1805 if (!NT_STATUS_IS_OK(status)) {
1806 printf("open2 of %s failed (%s)\n", fname, nt_errstr(status));
1810 for (offset=i=0;i<torture_numops;i++) {
1813 status = cli_lock32(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK);
1814 if (!NT_STATUS_IS_OK(status)) {
1815 printf("lock1 %d failed (%s)\n",
1821 status = cli_lock32(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK);
1822 if (!NT_STATUS_IS_OK(status)) {
1823 printf("lock2 %d failed (%s)\n",
1830 for (offset=i=0;i<torture_numops;i++) {
1833 status = cli_lock32(cli1, fnum1, offset-2, 1, 0, WRITE_LOCK);
1834 if (NT_STATUS_IS_OK(status)) {
1835 printf("error: lock1 %d succeeded!\n", i);
1839 status = cli_lock32(cli2, fnum2, offset-1, 1, 0, WRITE_LOCK);
1840 if (NT_STATUS_IS_OK(status)) {
1841 printf("error: lock2 %d succeeded!\n", i);
1845 status = cli_lock32(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK);
1846 if (NT_STATUS_IS_OK(status)) {
1847 printf("error: lock3 %d succeeded!\n", i);
1851 status = cli_lock32(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK);
1852 if (NT_STATUS_IS_OK(status)) {
1853 printf("error: lock4 %d succeeded!\n", i);
1858 for (offset=i=0;i<torture_numops;i++) {
1861 status = cli_unlock(cli1, fnum1, offset-1, 1);
1862 if (!NT_STATUS_IS_OK(status)) {
1863 printf("unlock1 %d failed (%s)\n",
1869 status = cli_unlock(cli2, fnum2, offset-2, 1);
1870 if (!NT_STATUS_IS_OK(status)) {
1871 printf("unlock2 %d failed (%s)\n",
1878 status = cli_close(cli1, fnum1);
1879 if (!NT_STATUS_IS_OK(status)) {
1880 printf("close1 failed (%s)\n", nt_errstr(status));
1884 status = cli_close(cli2, fnum2);
1885 if (!NT_STATUS_IS_OK(status)) {
1886 printf("close2 failed (%s)\n", nt_errstr(status));
1890 status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1891 if (!NT_STATUS_IS_OK(status)) {
1892 printf("unlink failed (%s)\n", nt_errstr(status));
1896 if (!torture_close_connection(cli1)) {
1900 if (!torture_close_connection(cli2)) {
1904 printf("finished locktest3\n");
1909 static bool test_cli_read(struct cli_state *cli, uint16_t fnum,
1910 char *buf, off_t offset, size_t size,
1911 size_t *nread, size_t expect)
1916 status = cli_read(cli, fnum, buf, offset, size, &l_nread);
1918 if(!NT_STATUS_IS_OK(status)) {
1920 } else if (l_nread != expect) {
1931 #define EXPECTED(ret, v) if ((ret) != (v)) { \
1932 printf("** "); correct = False; \
1936 looks at overlapping locks
1938 static bool run_locktest4(int dummy)
1940 static struct cli_state *cli1, *cli2;
1941 const char *fname = "\\lockt4.lck";
1942 uint16_t fnum1, fnum2, f;
1945 bool correct = True;
1948 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1952 cli_sockopt(cli1, sockops);
1953 cli_sockopt(cli2, sockops);
1955 printf("starting locktest4\n");
1957 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1959 cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
1960 cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
1962 memset(buf, 0, sizeof(buf));
1964 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 0, sizeof(buf),
1966 if (!NT_STATUS_IS_OK(status)) {
1967 printf("Failed to create file: %s\n", nt_errstr(status));
1972 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) &&
1973 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 2, 4, 0, WRITE_LOCK));
1974 EXPECTED(ret, False);
1975 printf("the same process %s set overlapping write locks\n", ret?"can":"cannot");
1977 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 10, 4, 0, READ_LOCK)) &&
1978 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 12, 4, 0, READ_LOCK));
1979 EXPECTED(ret, True);
1980 printf("the same process %s set overlapping read locks\n", ret?"can":"cannot");
1982 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 20, 4, 0, WRITE_LOCK)) &&
1983 NT_STATUS_IS_OK(cli_lock32(cli2, fnum2, 22, 4, 0, WRITE_LOCK));
1984 EXPECTED(ret, False);
1985 printf("a different connection %s set overlapping write locks\n", ret?"can":"cannot");
1987 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 30, 4, 0, READ_LOCK)) &&
1988 NT_STATUS_IS_OK(cli_lock32(cli2, fnum2, 32, 4, 0, READ_LOCK));
1989 EXPECTED(ret, True);
1990 printf("a different connection %s set overlapping read locks\n", ret?"can":"cannot");
1992 ret = (cli_setpid(cli1, 1),
1993 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 40, 4, 0, WRITE_LOCK))) &&
1994 (cli_setpid(cli1, 2),
1995 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 42, 4, 0, WRITE_LOCK)));
1996 EXPECTED(ret, False);
1997 printf("a different pid %s set overlapping write locks\n", ret?"can":"cannot");
1999 ret = (cli_setpid(cli1, 1),
2000 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 50, 4, 0, READ_LOCK))) &&
2001 (cli_setpid(cli1, 2),
2002 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 52, 4, 0, READ_LOCK)));
2003 EXPECTED(ret, True);
2004 printf("a different pid %s set overlapping read locks\n", ret?"can":"cannot");
2006 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 60, 4, 0, READ_LOCK)) &&
2007 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 60, 4, 0, READ_LOCK));
2008 EXPECTED(ret, True);
2009 printf("the same process %s set the same read lock twice\n", ret?"can":"cannot");
2011 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 70, 4, 0, WRITE_LOCK)) &&
2012 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 70, 4, 0, WRITE_LOCK));
2013 EXPECTED(ret, False);
2014 printf("the same process %s set the same write lock twice\n", ret?"can":"cannot");
2016 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 80, 4, 0, READ_LOCK)) &&
2017 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 80, 4, 0, WRITE_LOCK));
2018 EXPECTED(ret, False);
2019 printf("the same process %s overlay a read lock with a write lock\n", ret?"can":"cannot");
2021 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 90, 4, 0, WRITE_LOCK)) &&
2022 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 90, 4, 0, READ_LOCK));
2023 EXPECTED(ret, True);
2024 printf("the same process %s overlay a write lock with a read lock\n", ret?"can":"cannot");
2026 ret = (cli_setpid(cli1, 1),
2027 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 100, 4, 0, WRITE_LOCK))) &&
2028 (cli_setpid(cli1, 2),
2029 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 100, 4, 0, READ_LOCK)));
2030 EXPECTED(ret, False);
2031 printf("a different pid %s overlay a write lock with a read lock\n", ret?"can":"cannot");
2033 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 110, 4, 0, READ_LOCK)) &&
2034 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 112, 4, 0, READ_LOCK)) &&
2035 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 110, 6));
2036 EXPECTED(ret, False);
2037 printf("the same process %s coalesce read locks\n", ret?"can":"cannot");
2040 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 120, 4, 0, WRITE_LOCK)) &&
2041 test_cli_read(cli2, fnum2, buf, 120, 4, NULL, 4);
2042 EXPECTED(ret, False);
2043 printf("this server %s strict write locking\n", ret?"doesn't do":"does");
2045 status = cli_lock32(cli1, fnum1, 130, 4, 0, READ_LOCK);
2046 ret = NT_STATUS_IS_OK(status);
2048 status = cli_writeall(cli2, fnum2, 0, (uint8_t *)buf, 130, 4,
2050 ret = NT_STATUS_IS_OK(status);
2052 EXPECTED(ret, False);
2053 printf("this server %s strict read locking\n", ret?"doesn't do":"does");
2056 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 140, 4, 0, READ_LOCK)) &&
2057 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 140, 4, 0, READ_LOCK)) &&
2058 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 140, 4)) &&
2059 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 140, 4));
2060 EXPECTED(ret, True);
2061 printf("this server %s do recursive read locking\n", ret?"does":"doesn't");
2064 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 150, 4, 0, WRITE_LOCK)) &&
2065 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 150, 4, 0, READ_LOCK)) &&
2066 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 150, 4)) &&
2067 test_cli_read(cli2, fnum2, buf, 150, 4, NULL, 4) &&
2068 !(NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf,
2070 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 150, 4));
2071 EXPECTED(ret, True);
2072 printf("this server %s do recursive lock overlays\n", ret?"does":"doesn't");
2074 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 160, 4, 0, READ_LOCK)) &&
2075 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 160, 4)) &&
2076 NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf,
2078 test_cli_read(cli2, fnum2, buf, 160, 4, NULL, 4);
2079 EXPECTED(ret, True);
2080 printf("the same process %s remove a read lock using write locking\n", ret?"can":"cannot");
2082 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 170, 4, 0, WRITE_LOCK)) &&
2083 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 170, 4)) &&
2084 NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf,
2086 test_cli_read(cli2, fnum2, buf, 170, 4, NULL, 4);
2087 EXPECTED(ret, True);
2088 printf("the same process %s remove a write lock using read locking\n", ret?"can":"cannot");
2090 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 190, 4, 0, WRITE_LOCK)) &&
2091 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 190, 4, 0, READ_LOCK)) &&
2092 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 190, 4)) &&
2093 !NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf,
2095 test_cli_read(cli2, fnum2, buf, 190, 4, NULL, 4);
2096 EXPECTED(ret, True);
2097 printf("the same process %s remove the first lock first\n", ret?"does":"doesn't");
2099 cli_close(cli1, fnum1);
2100 cli_close(cli2, fnum2);
2101 cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
2102 cli_open(cli1, fname, O_RDWR, DENY_NONE, &f);
2103 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 8, 0, READ_LOCK)) &&
2104 NT_STATUS_IS_OK(cli_lock32(cli1, f, 0, 1, 0, READ_LOCK)) &&
2105 NT_STATUS_IS_OK(cli_close(cli1, fnum1)) &&
2106 NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1)) &&
2107 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 7, 1, 0, WRITE_LOCK));
2109 cli_close(cli1, fnum1);
2110 EXPECTED(ret, True);
2111 printf("the server %s have the NT byte range lock bug\n", !ret?"does":"doesn't");
2114 cli_close(cli1, fnum1);
2115 cli_close(cli2, fnum2);
2116 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2117 torture_close_connection(cli1);
2118 torture_close_connection(cli2);
2120 printf("finished locktest4\n");
2125 looks at lock upgrade/downgrade.
2127 static bool run_locktest5(int dummy)
2129 static struct cli_state *cli1, *cli2;
2130 const char *fname = "\\lockt5.lck";
2131 uint16_t fnum1, fnum2, fnum3;
2134 bool correct = True;
2137 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
2141 cli_sockopt(cli1, sockops);
2142 cli_sockopt(cli2, sockops);
2144 printf("starting locktest5\n");
2146 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2148 cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
2149 cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
2150 cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum3);
2152 memset(buf, 0, sizeof(buf));
2154 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 0, sizeof(buf),
2156 if (!NT_STATUS_IS_OK(status)) {
2157 printf("Failed to create file: %s\n", nt_errstr(status));
2162 /* Check for NT bug... */
2163 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 8, 0, READ_LOCK)) &&
2164 NT_STATUS_IS_OK(cli_lock32(cli1, fnum3, 0, 1, 0, READ_LOCK));
2165 cli_close(cli1, fnum1);
2166 cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
2167 status = cli_lock32(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
2168 ret = NT_STATUS_IS_OK(status);
2169 EXPECTED(ret, True);
2170 printf("this server %s the NT locking bug\n", ret ? "doesn't have" : "has");
2171 cli_close(cli1, fnum1);
2172 cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
2173 cli_unlock(cli1, fnum3, 0, 1);
2175 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) &&
2176 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 1, 1, 0, READ_LOCK));
2177 EXPECTED(ret, True);
2178 printf("the same process %s overlay a write with a read lock\n", ret?"can":"cannot");
2180 status = cli_lock32(cli2, fnum2, 0, 4, 0, READ_LOCK);
2181 ret = NT_STATUS_IS_OK(status);
2182 EXPECTED(ret, False);
2184 printf("a different processs %s get a read lock on the first process lock stack\n", ret?"can":"cannot");
2186 /* Unlock the process 2 lock. */
2187 cli_unlock(cli2, fnum2, 0, 4);
2189 status = cli_lock32(cli1, fnum3, 0, 4, 0, READ_LOCK);
2190 ret = NT_STATUS_IS_OK(status);
2191 EXPECTED(ret, False);
2193 printf("the same processs on a different fnum %s get a read lock\n", ret?"can":"cannot");
2195 /* Unlock the process 1 fnum3 lock. */
2196 cli_unlock(cli1, fnum3, 0, 4);
2198 /* Stack 2 more locks here. */
2199 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 4, 0, READ_LOCK)) &&
2200 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 4, 0, READ_LOCK));
2202 EXPECTED(ret, True);
2203 printf("the same process %s stack read locks\n", ret?"can":"cannot");
2205 /* Unlock the first process lock, then check this was the WRITE lock that was
2208 ret = NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 0, 4)) &&
2209 NT_STATUS_IS_OK(cli_lock32(cli2, fnum2, 0, 4, 0, READ_LOCK));
2211 EXPECTED(ret, True);
2212 printf("the first unlock removes the %s lock\n", ret?"WRITE":"READ");
2214 /* Unlock the process 2 lock. */
2215 cli_unlock(cli2, fnum2, 0, 4);
2217 /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */
2219 ret = NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 1, 1)) &&
2220 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 0, 4)) &&
2221 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 0, 4));
2223 EXPECTED(ret, True);
2224 printf("the same process %s unlock the stack of 4 locks\n", ret?"can":"cannot");
2226 /* Ensure the next unlock fails. */
2227 ret = NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 0, 4));
2228 EXPECTED(ret, False);
2229 printf("the same process %s count the lock stack\n", !ret?"can":"cannot");
2231 /* Ensure connection 2 can get a write lock. */
2232 status = cli_lock32(cli2, fnum2, 0, 4, 0, WRITE_LOCK);
2233 ret = NT_STATUS_IS_OK(status);
2234 EXPECTED(ret, True);
2236 printf("a different processs %s get a write lock on the unlocked stack\n", ret?"can":"cannot");
2240 cli_close(cli1, fnum1);
2241 cli_close(cli2, fnum2);
2242 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2243 if (!torture_close_connection(cli1)) {
2246 if (!torture_close_connection(cli2)) {
2250 printf("finished locktest5\n");
2256 tries the unusual lockingX locktype bits
2258 static bool run_locktest6(int dummy)
2260 static struct cli_state *cli;
2261 const char *fname[1] = { "\\lock6.txt" };
2266 if (!torture_open_connection(&cli, 0)) {
2270 cli_sockopt(cli, sockops);
2272 printf("starting locktest6\n");
2275 printf("Testing %s\n", fname[i]);
2277 cli_unlink(cli, fname[i], FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2279 cli_open(cli, fname[i], O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
2280 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE);
2281 cli_close(cli, fnum);
2282 printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status));
2284 cli_open(cli, fname[i], O_RDWR, DENY_NONE, &fnum);
2285 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK);
2286 cli_close(cli, fnum);
2287 printf("CANCEL_LOCK gave %s\n", nt_errstr(status));
2289 cli_unlink(cli, fname[i], FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2292 torture_close_connection(cli);
2294 printf("finished locktest6\n");
2298 static bool run_locktest7(int dummy)
2300 struct cli_state *cli1;
2301 const char *fname = "\\lockt7.lck";
2304 bool correct = False;
2308 if (!torture_open_connection(&cli1, 0)) {
2312 cli_sockopt(cli1, sockops);
2314 printf("starting locktest7\n");
2316 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2318 cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
2320 memset(buf, 0, sizeof(buf));
2322 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 0, sizeof(buf),
2324 if (!NT_STATUS_IS_OK(status)) {
2325 printf("Failed to create file: %s\n", nt_errstr(status));
2329 cli_setpid(cli1, 1);
2331 status = cli_lock32(cli1, fnum1, 130, 4, 0, READ_LOCK);
2332 if (!NT_STATUS_IS_OK(status)) {
2333 printf("Unable to apply read lock on range 130:4, "
2334 "error was %s\n", nt_errstr(status));
2337 printf("pid1 successfully locked range 130:4 for READ\n");
2340 status = cli_read(cli1, fnum1, buf, 130, 4, &nread);
2341 if (!NT_STATUS_IS_OK(status)) {
2342 printf("pid1 unable to read the range 130:4, error was %s\n",
2345 } else if (nread != 4) {
2346 printf("pid1 unable to read the range 130:4, "
2347 "recv %ld req %d\n", (unsigned long)nread, 4);
2350 printf("pid1 successfully read the range 130:4\n");
2353 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
2354 if (!NT_STATUS_IS_OK(status)) {
2355 printf("pid1 unable to write to the range 130:4, error was "
2356 "%s\n", nt_errstr(status));
2357 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_LOCK_CONFLICT)) {
2358 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2362 printf("pid1 successfully wrote to the range 130:4 (should be denied)\n");
2366 cli_setpid(cli1, 2);
2368 status = cli_read(cli1, fnum1, buf, 130, 4, &nread);
2369 if (!NT_STATUS_IS_OK(status)) {
2370 printf("pid2 unable to read the range 130:4, error was %s\n",
2373 } else if (nread != 4) {
2374 printf("pid2 unable to read the range 130:4, "
2375 "recv %ld req %d\n", (unsigned long)nread, 4);
2378 printf("pid2 successfully read the range 130:4\n");
2381 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
2382 if (!NT_STATUS_IS_OK(status)) {
2383 printf("pid2 unable to write to the range 130:4, error was "
2384 "%s\n", nt_errstr(status));
2385 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_LOCK_CONFLICT)) {
2386 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2390 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
2394 cli_setpid(cli1, 1);
2395 cli_unlock(cli1, fnum1, 130, 4);
2397 status = cli_lock32(cli1, fnum1, 130, 4, 0, WRITE_LOCK);
2398 if (!NT_STATUS_IS_OK(status)) {
2399 printf("Unable to apply write lock on range 130:4, error was %s\n", nt_errstr(status));
2402 printf("pid1 successfully locked range 130:4 for WRITE\n");
2405 status = cli_read(cli1, fnum1, buf, 130, 4, &nread);
2406 if (!NT_STATUS_IS_OK(status)) {
2407 printf("pid1 unable to read the range 130:4, error was %s\n",
2410 } else if (nread != 4) {
2411 printf("pid1 unable to read the range 130:4, "
2412 "recv %ld req %d\n", (unsigned long)nread, 4);
2415 printf("pid1 successfully read the range 130:4\n");
2418 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
2419 if (!NT_STATUS_IS_OK(status)) {
2420 printf("pid1 unable to write to the range 130:4, error was "
2421 "%s\n", nt_errstr(status));
2424 printf("pid1 successfully wrote to the range 130:4\n");
2427 cli_setpid(cli1, 2);
2429 status = cli_read(cli1, fnum1, buf, 130, 4, &nread);
2430 if (!NT_STATUS_IS_OK(status)) {
2431 printf("pid2 unable to read the range 130:4, error was "
2432 "%s\n", nt_errstr(status));
2433 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_LOCK_CONFLICT)) {
2434 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2438 printf("pid2 successfully read the range 130:4 (should be denied) recv %ld\n",
2439 (unsigned long)nread);
2443 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
2444 if (!NT_STATUS_IS_OK(status)) {
2445 printf("pid2 unable to write to the range 130:4, error was "
2446 "%s\n", nt_errstr(status));
2447 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_LOCK_CONFLICT)) {
2448 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2452 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
2456 cli_unlock(cli1, fnum1, 130, 0);
2460 cli_close(cli1, fnum1);
2461 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2462 torture_close_connection(cli1);
2464 printf("finished locktest7\n");
2469 * This demonstrates a problem with our use of GPFS share modes: A file
2470 * descriptor sitting in the pending close queue holding a GPFS share mode
2471 * blocks opening a file another time. Happens with Word 2007 temp files.
2472 * With "posix locking = yes" and "gpfs:sharemodes = yes" enabled, the third
2473 * open is denied with NT_STATUS_SHARING_VIOLATION.
2476 static bool run_locktest8(int dummy)
2478 struct cli_state *cli1;
2479 const char *fname = "\\lockt8.lck";
2480 uint16_t fnum1, fnum2;
2482 bool correct = False;
2485 if (!torture_open_connection(&cli1, 0)) {
2489 cli_sockopt(cli1, sockops);
2491 printf("starting locktest8\n");
2493 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2495 status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_WRITE,
2497 if (!NT_STATUS_IS_OK(status)) {
2498 d_fprintf(stderr, "cli_open returned %s\n", nt_errstr(status));
2502 memset(buf, 0, sizeof(buf));
2504 status = cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum2);
2505 if (!NT_STATUS_IS_OK(status)) {
2506 d_fprintf(stderr, "cli_open second time returned %s\n",
2511 status = cli_lock32(cli1, fnum2, 1, 1, 0, READ_LOCK);
2512 if (!NT_STATUS_IS_OK(status)) {
2513 printf("Unable to apply read lock on range 1:1, error was "
2514 "%s\n", nt_errstr(status));
2518 status = cli_close(cli1, fnum1);
2519 if (!NT_STATUS_IS_OK(status)) {
2520 d_fprintf(stderr, "cli_close(fnum1) %s\n", nt_errstr(status));
2524 status = cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
2525 if (!NT_STATUS_IS_OK(status)) {
2526 d_fprintf(stderr, "cli_open third time returned %s\n",
2534 cli_close(cli1, fnum1);
2535 cli_close(cli1, fnum2);
2536 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2537 torture_close_connection(cli1);
2539 printf("finished locktest8\n");
2544 * This test is designed to be run in conjunction with
2545 * external NFS or POSIX locks taken in the filesystem.
2546 * It checks that the smbd server will block until the
2547 * lock is released and then acquire it. JRA.
2550 static bool got_alarm;
2551 static struct cli_state *alarm_cli;
2553 static void alarm_handler(int dummy)
2558 static void alarm_handler_parent(int dummy)
2560 cli_state_disconnect(alarm_cli);
2563 static void do_local_lock(int read_fd, int write_fd)
2568 const char *local_pathname = NULL;
2571 local_pathname = talloc_asprintf(talloc_tos(),
2572 "%s/lockt9.lck", local_path);
2573 if (!local_pathname) {
2574 printf("child: alloc fail\n");
2578 unlink(local_pathname);
2579 fd = open(local_pathname, O_RDWR|O_CREAT, 0666);
2581 printf("child: open of %s failed %s.\n",
2582 local_pathname, strerror(errno));
2586 /* Now take a fcntl lock. */
2587 lock.l_type = F_WRLCK;
2588 lock.l_whence = SEEK_SET;
2591 lock.l_pid = getpid();
2593 ret = fcntl(fd,F_SETLK,&lock);
2595 printf("child: failed to get lock 0:4 on file %s. Error %s\n",
2596 local_pathname, strerror(errno));
2599 printf("child: got lock 0:4 on file %s.\n",
2604 CatchSignal(SIGALRM, alarm_handler);
2606 /* Signal the parent. */
2607 if (write(write_fd, &c, 1) != 1) {
2608 printf("child: start signal fail %s.\n",
2615 /* Wait for the parent to be ready. */
2616 if (read(read_fd, &c, 1) != 1) {
2617 printf("child: reply signal fail %s.\n",
2625 printf("child: released lock 0:4 on file %s.\n",
2631 static bool run_locktest9(int dummy)
2633 struct cli_state *cli1;
2634 const char *fname = "\\lockt9.lck";
2636 bool correct = False;
2637 int pipe_in[2], pipe_out[2];
2641 struct timeval start;
2645 printf("starting locktest9\n");
2647 if (local_path == NULL) {
2648 d_fprintf(stderr, "locktest9 must be given a local path via -l <localpath>\n");
2652 if (pipe(pipe_in) == -1 || pipe(pipe_out) == -1) {
2657 if (child_pid == -1) {
2661 if (child_pid == 0) {
2663 do_local_lock(pipe_out[0], pipe_in[1]);
2673 ret = read(pipe_in[0], &c, 1);
2675 d_fprintf(stderr, "failed to read start signal from child. %s\n",
2680 if (!torture_open_connection(&cli1, 0)) {
2684 cli_sockopt(cli1, sockops);
2686 status = cli_open(cli1, fname, O_RDWR, DENY_NONE,
2688 if (!NT_STATUS_IS_OK(status)) {
2689 d_fprintf(stderr, "cli_open returned %s\n", nt_errstr(status));
2693 /* Ensure the child has the lock. */
2694 status = cli_lock32(cli1, fnum, 0, 4, 0, WRITE_LOCK);
2695 if (NT_STATUS_IS_OK(status)) {
2696 d_fprintf(stderr, "Got the lock on range 0:4 - this should not happen !\n");
2699 d_printf("Child has the lock.\n");
2702 /* Tell the child to wait 5 seconds then exit. */
2703 ret = write(pipe_out[1], &c, 1);
2705 d_fprintf(stderr, "failed to send exit signal to child. %s\n",
2710 /* Wait 20 seconds for the lock. */
2712 CatchSignal(SIGALRM, alarm_handler_parent);
2715 start = timeval_current();
2717 status = cli_lock32(cli1, fnum, 0, 4, -1, WRITE_LOCK);
2718 if (!NT_STATUS_IS_OK(status)) {
2719 d_fprintf(stderr, "Unable to apply write lock on range 0:4, error was "
2720 "%s\n", nt_errstr(status));
2725 seconds = timeval_elapsed(&start);
2727 printf("Parent got the lock after %.2f seconds.\n",
2730 status = cli_close(cli1, fnum);
2731 if (!NT_STATUS_IS_OK(status)) {
2732 d_fprintf(stderr, "cli_close(fnum1) %s\n", nt_errstr(status));
2739 cli_close(cli1, fnum);
2740 torture_close_connection(cli1);
2744 printf("finished locktest9\n");
2749 test whether fnums and tids open on one VC are available on another (a major
2752 static bool run_fdpasstest(int dummy)
2754 struct cli_state *cli1, *cli2;
2755 const char *fname = "\\fdpass.tst";
2760 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
2763 cli_sockopt(cli1, sockops);
2764 cli_sockopt(cli2, sockops);
2766 printf("starting fdpasstest\n");
2768 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2770 status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
2772 if (!NT_STATUS_IS_OK(status)) {
2773 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
2777 status = cli_writeall(cli1, fnum1, 0, (const uint8_t *)"hello world\n", 0,
2779 if (!NT_STATUS_IS_OK(status)) {
2780 printf("write failed (%s)\n", nt_errstr(status));
2784 cli_state_set_uid(cli2, cli_state_get_uid(cli1));
2785 cli_state_set_tid(cli2, cli_state_get_tid(cli1));
2786 cli_setpid(cli2, cli_getpid(cli1));
2788 if (test_cli_read(cli2, fnum1, buf, 0, 13, NULL, 13)) {
2789 printf("read succeeded! nasty security hole [%s]\n", buf);
2793 cli_close(cli1, fnum1);
2794 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2796 torture_close_connection(cli1);
2797 torture_close_connection(cli2);
2799 printf("finished fdpasstest\n");
2803 static bool run_fdsesstest(int dummy)
2805 struct cli_state *cli;
2810 const char *fname = "\\fdsess.tst";
2811 const char *fname1 = "\\fdsess1.tst";
2818 if (!torture_open_connection(&cli, 0))
2820 cli_sockopt(cli, sockops);
2822 if (!torture_cli_session_setup2(cli, &new_vuid))
2825 saved_cnum = cli_state_get_tid(cli);
2826 if (!NT_STATUS_IS_OK(cli_tcon_andx(cli, share, "?????", "", 1)))
2828 new_cnum = cli_state_get_tid(cli);
2829 cli_state_set_tid(cli, saved_cnum);
2831 printf("starting fdsesstest\n");
2833 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2834 cli_unlink(cli, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2836 status = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
2837 if (!NT_STATUS_IS_OK(status)) {
2838 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
2842 status = cli_writeall(cli, fnum1, 0, (const uint8_t *)"hello world\n", 0, 13,
2844 if (!NT_STATUS_IS_OK(status)) {
2845 printf("write failed (%s)\n", nt_errstr(status));
2849 saved_vuid = cli_state_get_uid(cli);
2850 cli_state_set_uid(cli, new_vuid);
2852 if (test_cli_read(cli, fnum1, buf, 0, 13, NULL, 13)) {
2853 printf("read succeeded with different vuid! "
2854 "nasty security hole [%s]\n", buf);
2857 /* Try to open a file with different vuid, samba cnum. */
2858 if (NT_STATUS_IS_OK(cli_open(cli, fname1, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum2))) {
2859 printf("create with different vuid, same cnum succeeded.\n");
2860 cli_close(cli, fnum2);
2861 cli_unlink(cli, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2863 printf("create with different vuid, same cnum failed.\n");
2864 printf("This will cause problems with service clients.\n");
2868 cli_state_set_uid(cli, saved_vuid);
2870 /* Try with same vuid, different cnum. */
2871 cli_state_set_tid(cli, new_cnum);
2873 if (test_cli_read(cli, fnum1, buf, 0, 13, NULL, 13)) {
2874 printf("read succeeded with different cnum![%s]\n", buf);
2878 cli_state_set_tid(cli, saved_cnum);
2879 cli_close(cli, fnum1);
2880 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2882 torture_close_connection(cli);
2884 printf("finished fdsesstest\n");
2889 This test checks that
2891 1) the server does not allow an unlink on a file that is open
2893 static bool run_unlinktest(int dummy)
2895 struct cli_state *cli;
2896 const char *fname = "\\unlink.tst";
2898 bool correct = True;
2901 if (!torture_open_connection(&cli, 0)) {
2905 cli_sockopt(cli, sockops);
2907 printf("starting unlink test\n");
2909 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2913 status = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
2914 if (!NT_STATUS_IS_OK(status)) {
2915 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
2919 status = cli_unlink(cli, fname,
2920 FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2921 if (NT_STATUS_IS_OK(status)) {
2922 printf("error: server allowed unlink on an open file\n");
2925 correct = check_error(__LINE__, status, ERRDOS, ERRbadshare,
2926 NT_STATUS_SHARING_VIOLATION);
2929 cli_close(cli, fnum);
2930 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2932 if (!torture_close_connection(cli)) {
2936 printf("unlink test finished\n");
2943 test how many open files this server supports on the one socket
2945 static bool run_maxfidtest(int dummy)
2947 struct cli_state *cli;
2949 uint16_t fnums[0x11000];
2952 bool correct = True;
2958 printf("failed to connect\n");
2962 cli_sockopt(cli, sockops);
2964 for (i=0; i<0x11000; i++) {
2965 slprintf(fname,sizeof(fname)-1,"\\maxfid.%d.%d", i,(int)getpid());
2966 status = cli_open(cli, fname, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE,
2968 if (!NT_STATUS_IS_OK(status)) {
2969 printf("open of %s failed (%s)\n",
2970 fname, nt_errstr(status));
2971 printf("maximum fnum is %d\n", i);
2979 printf("cleaning up\n");
2981 slprintf(fname,sizeof(fname)-1,"\\maxfid.%d.%d", i,(int)getpid());
2982 cli_close(cli, fnums[i]);
2984 status = cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2985 if (!NT_STATUS_IS_OK(status)) {
2986 printf("unlink of %s failed (%s)\n",
2987 fname, nt_errstr(status));
2994 printf("maxfid test finished\n");
2995 if (!torture_close_connection(cli)) {
3001 /* generate a random buffer */
3002 static void rand_buf(char *buf, int len)
3005 *buf = (char)sys_random();
3010 /* send smb negprot commands, not reading the response */
3011 static bool run_negprot_nowait(int dummy)
3013 struct tevent_context *ev;
3015 struct cli_state *cli;
3016 bool correct = True;
3018 printf("starting negprot nowait test\n");
3020 ev = tevent_context_init(talloc_tos());
3025 if (!(cli = open_nbt_connection())) {
3030 for (i=0;i<50000;i++) {
3031 struct tevent_req *req;
3033 req = cli_negprot_send(ev, ev, cli);
3038 if (!tevent_req_poll(req, ev)) {
3039 d_fprintf(stderr, "tevent_req_poll failed: %s\n",
3047 if (torture_close_connection(cli)) {
3051 printf("finished negprot nowait test\n");
3056 /* send smb negprot commands, not reading the response */
3057 static bool run_bad_nbt_session(int dummy)
3059 struct nmb_name called, calling;
3060 struct sockaddr_storage ss;
3065 printf("starting bad nbt session test\n");
3067 make_nmb_name(&calling, myname, 0x0);
3068 make_nmb_name(&called , host, 0x20);
3070 if (!resolve_name(host, &ss, 0x20, true)) {
3071 d_fprintf(stderr, "Could not resolve name %s\n", host);
3075 status = open_socket_out(&ss, 139, 10000, &fd);
3076 if (!NT_STATUS_IS_OK(status)) {
3077 d_fprintf(stderr, "open_socket_out failed: %s\n",
3082 ret = cli_bad_session_request(fd, &calling, &called);
3085 d_fprintf(stderr, "open_socket_out failed: %s\n",
3090 printf("finished bad nbt session test\n");
3094 /* send random IPC commands */
3095 static bool run_randomipc(int dummy)
3097 char *rparam = NULL;
3099 unsigned int rdrcnt,rprcnt;
3101 int api, param_len, i;
3102 struct cli_state *cli;
3103 bool correct = True;
3106 printf("starting random ipc test\n");
3108 if (!torture_open_connection(&cli, 0)) {
3112 for (i=0;i<count;i++) {
3113 api = sys_random() % 500;
3114 param_len = (sys_random() % 64);
3116 rand_buf(param, param_len);
3121 param, param_len, 8,
3122 NULL, 0, BUFFER_SIZE,
3126 printf("%d/%d\r", i,count);
3129 printf("%d/%d\n", i, count);
3131 if (!torture_close_connection(cli)) {
3135 printf("finished random ipc test\n");
3142 static void browse_callback(const char *sname, uint32 stype,
3143 const char *comment, void *state)
3145 printf("\t%20.20s %08x %s\n", sname, stype, comment);
3151 This test checks the browse list code
3154 static bool run_browsetest(int dummy)
3156 static struct cli_state *cli;
3157 bool correct = True;
3159 printf("starting browse test\n");
3161 if (!torture_open_connection(&cli, 0)) {
3165 printf("domain list:\n");
3166 cli_NetServerEnum(cli, cli->server_domain,
3167 SV_TYPE_DOMAIN_ENUM,
3168 browse_callback, NULL);
3170 printf("machine list:\n");
3171 cli_NetServerEnum(cli, cli->server_domain,
3173 browse_callback, NULL);
3175 if (!torture_close_connection(cli)) {
3179 printf("browse test finished\n");
3187 This checks how the getatr calls works
3189 static bool run_attrtest(int dummy)
3191 struct cli_state *cli;
3194 const char *fname = "\\attrib123456789.tst";
3195 bool correct = True;
3198 printf("starting attrib test\n");
3200 if (!torture_open_connection(&cli, 0)) {
3204 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3205 cli_open(cli, fname,
3206 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
3207 cli_close(cli, fnum);
3209 status = cli_getatr(cli, fname, NULL, NULL, &t);
3210 if (!NT_STATUS_IS_OK(status)) {
3211 printf("getatr failed (%s)\n", nt_errstr(status));
3215 if (abs(t - time(NULL)) > 60*60*24*10) {
3216 printf("ERROR: SMBgetatr bug. time is %s",
3222 t2 = t-60*60*24; /* 1 day ago */
3224 status = cli_setatr(cli, fname, 0, t2);
3225 if (!NT_STATUS_IS_OK(status)) {
3226 printf("setatr failed (%s)\n", nt_errstr(status));
3230 status = cli_getatr(cli, fname, NULL, NULL, &t);
3231 if (!NT_STATUS_IS_OK(status)) {
3232 printf("getatr failed (%s)\n", nt_errstr(status));
3237 printf("ERROR: getatr/setatr bug. times are\n%s",
3239 printf("%s", ctime(&t2));
3243 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3245 if (!torture_close_connection(cli)) {
3249 printf("attrib test finished\n");
3256 This checks a couple of trans2 calls
3258 static bool run_trans2test(int dummy)
3260 struct cli_state *cli;
3263 time_t c_time, a_time, m_time;
3264 struct timespec c_time_ts, a_time_ts, m_time_ts, w_time_ts, m_time2_ts;
3265 const char *fname = "\\trans2.tst";
3266 const char *dname = "\\trans2";
3267 const char *fname2 = "\\trans2\\trans2.tst";
3269 bool correct = True;
3273 printf("starting trans2 test\n");
3275 if (!torture_open_connection(&cli, 0)) {
3279 status = cli_get_fs_attr_info(cli, &fs_attr);
3280 if (!NT_STATUS_IS_OK(status)) {
3281 printf("ERROR: cli_get_fs_attr_info returned %s\n",
3286 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3287 cli_open(cli, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
3288 status = cli_qfileinfo_basic(cli, fnum, NULL, &size, &c_time_ts,
3289 &a_time_ts, &w_time_ts, &m_time_ts, NULL);
3290 if (!NT_STATUS_IS_OK(status)) {
3291 printf("ERROR: qfileinfo failed (%s)\n", nt_errstr(status));
3295 status = cli_qfilename(cli, fnum, talloc_tos(), &pname);
3296 if (!NT_STATUS_IS_OK(status)) {
3297 printf("ERROR: qfilename failed (%s)\n", nt_errstr(status));
3301 if (strcmp(pname, fname)) {
3302 printf("qfilename gave different name? [%s] [%s]\n",
3307 cli_close(cli, fnum);
3311 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3312 status = cli_open(cli, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE,
3314 if (!NT_STATUS_IS_OK(status)) {
3315 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
3318 cli_close(cli, fnum);
3320 status = cli_qpathinfo1(cli, fname, &c_time, &a_time, &m_time, &size,
3322 if (!NT_STATUS_IS_OK(status)) {
3323 printf("ERROR: qpathinfo failed (%s)\n", nt_errstr(status));
3326 if (c_time != m_time) {
3327 printf("create time=%s", ctime(&c_time));
3328 printf("modify time=%s", ctime(&m_time));
3329 printf("This system appears to have sticky create times\n");
3331 if (a_time % (60*60) == 0) {
3332 printf("access time=%s", ctime(&a_time));
3333 printf("This system appears to set a midnight access time\n");
3337 if (abs(m_time - time(NULL)) > 60*60*24*7) {
3338 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
3344 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3345 cli_open(cli, fname,
3346 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
3347 cli_close(cli, fnum);
3348 status = cli_qpathinfo2(cli, fname, &c_time_ts, &a_time_ts, &w_time_ts,
3349 &m_time_ts, &size, NULL, NULL);
3350 if (!NT_STATUS_IS_OK(status)) {
3351 printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status));
3354 if (w_time_ts.tv_sec < 60*60*24*2) {
3355 printf("write time=%s", ctime(&w_time_ts.tv_sec));
3356 printf("This system appears to set a initial 0 write time\n");
3361 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3364 /* check if the server updates the directory modification time
3365 when creating a new file */
3366 status = cli_mkdir(cli, dname);
3367 if (!NT_STATUS_IS_OK(status)) {
3368 printf("ERROR: mkdir failed (%s)\n", nt_errstr(status));
3372 status = cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts,
3373 &w_time_ts, &m_time_ts, &size, NULL, NULL);
3374 if (!NT_STATUS_IS_OK(status)) {
3375 printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status));
3379 cli_open(cli, fname2,
3380 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
3381 cli_writeall(cli, fnum, 0, (uint8_t *)&fnum, 0, sizeof(fnum), NULL);
3382 cli_close(cli, fnum);
3383 status = cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts,
3384 &w_time_ts, &m_time2_ts, &size, NULL, NULL);
3385 if (!NT_STATUS_IS_OK(status)) {
3386 printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status));
3389 if (memcmp(&m_time_ts, &m_time2_ts, sizeof(struct timespec))
3391 printf("This system does not update directory modification times\n");
3395 cli_unlink(cli, fname2, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3396 cli_rmdir(cli, dname);
3398 if (!torture_close_connection(cli)) {
3402 printf("trans2 test finished\n");
3408 This checks new W2K calls.
3411 static NTSTATUS new_trans(struct cli_state *pcli, int fnum, int level)
3413 uint8_t *buf = NULL;
3417 status = cli_qfileinfo(talloc_tos(), pcli, fnum, level, 0,
3418 pcli->max_xmit, NULL, &buf, &len);
3419 if (!NT_STATUS_IS_OK(status)) {
3420 printf("ERROR: qfileinfo (%d) failed (%s)\n", level,
3423 printf("qfileinfo: level %d, len = %u\n", level, len);
3424 dump_data(0, (uint8 *)buf, len);
3431 static bool run_w2ktest(int dummy)
3433 struct cli_state *cli;
3435 const char *fname = "\\w2ktest\\w2k.tst";
3437 bool correct = True;
3439 printf("starting w2k test\n");
3441 if (!torture_open_connection(&cli, 0)) {
3445 cli_open(cli, fname,
3446 O_RDWR | O_CREAT , DENY_NONE, &fnum);
3448 for (level = 1004; level < 1040; level++) {
3449 new_trans(cli, fnum, level);
3452 cli_close(cli, fnum);
3454 if (!torture_close_connection(cli)) {
3458 printf("w2k test finished\n");
3465 this is a harness for some oplock tests
3467 static bool run_oplock1(int dummy)
3469 struct cli_state *cli1;
3470 const char *fname = "\\lockt1.lck";
3472 bool correct = True;
3475 printf("starting oplock test 1\n");
3477 if (!torture_open_connection(&cli1, 0)) {
3481 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3483 cli_sockopt(cli1, sockops);
3485 cli1->use_oplocks = True;
3487 status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
3489 if (!NT_STATUS_IS_OK(status)) {
3490 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
3494 cli1->use_oplocks = False;
3496 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3497 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3499 status = cli_close(cli1, fnum1);
3500 if (!NT_STATUS_IS_OK(status)) {
3501 printf("close2 failed (%s)\n", nt_errstr(status));
3505 status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3506 if (!NT_STATUS_IS_OK(status)) {
3507 printf("unlink failed (%s)\n", nt_errstr(status));
3511 if (!torture_close_connection(cli1)) {
3515 printf("finished oplock test 1\n");
3520 static bool run_oplock2(int dummy)
3522 struct cli_state *cli1, *cli2;
3523 const char *fname = "\\lockt2.lck";
3524 uint16_t fnum1, fnum2;
3525 int saved_use_oplocks = use_oplocks;
3527 bool correct = True;
3528 volatile bool *shared_correct;
3532 shared_correct = (volatile bool *)shm_setup(sizeof(bool));
3533 *shared_correct = True;
3535 use_level_II_oplocks = True;
3538 printf("starting oplock test 2\n");
3540 if (!torture_open_connection(&cli1, 0)) {
3541 use_level_II_oplocks = False;
3542 use_oplocks = saved_use_oplocks;
3546 cli1->use_oplocks = True;
3547 cli1->use_level_II_oplocks = True;
3549 if (!torture_open_connection(&cli2, 1)) {
3550 use_level_II_oplocks = False;
3551 use_oplocks = saved_use_oplocks;
3555 cli2->use_oplocks = True;
3556 cli2->use_level_II_oplocks = True;
3558 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3560 cli_sockopt(cli1, sockops);
3561 cli_sockopt(cli2, sockops);
3563 status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
3565 if (!NT_STATUS_IS_OK(status)) {
3566 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
3570 /* Don't need the globals any more. */
3571 use_level_II_oplocks = False;
3572 use_oplocks = saved_use_oplocks;
3576 status = cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
3577 if (!NT_STATUS_IS_OK(status)) {
3578 printf("second open of %s failed (%s)\n", fname, nt_errstr(status));
3579 *shared_correct = False;
3585 status = cli_close(cli2, fnum2);
3586 if (!NT_STATUS_IS_OK(status)) {
3587 printf("close2 failed (%s)\n", nt_errstr(status));
3588 *shared_correct = False;
3596 /* Ensure cli1 processes the break. Empty file should always return 0
3598 status = cli_read(cli1, fnum1, buf, 0, 4, &nread);
3599 if (!NT_STATUS_IS_OK(status)) {
3600 printf("read on fnum1 failed (%s)\n", nt_errstr(status));
3602 } else if (nread != 0) {
3603 printf("read on empty fnum1 failed. recv %ld expected %d\n",
3604 (unsigned long)nread, 0);
3608 /* Should now be at level II. */
3609 /* Test if sending a write locks causes a break to none. */
3610 status = cli_lock32(cli1, fnum1, 0, 4, 0, READ_LOCK);
3611 if (!NT_STATUS_IS_OK(status)) {
3612 printf("lock failed (%s)\n", nt_errstr(status));
3616 cli_unlock(cli1, fnum1, 0, 4);
3620 status = cli_lock32(cli1, fnum1, 0, 4, 0, WRITE_LOCK);
3621 if (!NT_STATUS_IS_OK(status)) {
3622 printf("lock failed (%s)\n", nt_errstr(status));
3626 cli_unlock(cli1, fnum1, 0, 4);
3630 cli_read(cli1, fnum1, buf, 0, 4, NULL);
3632 status = cli_close(cli1, fnum1);
3633 if (!NT_STATUS_IS_OK(status)) {
3634 printf("close1 failed (%s)\n", nt_errstr(status));
3640 status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3641 if (!NT_STATUS_IS_OK(status)) {
3642 printf("unlink failed (%s)\n", nt_errstr(status));
3646 if (!torture_close_connection(cli1)) {
3650 if (!*shared_correct) {
3654 printf("finished oplock test 2\n");
3659 struct oplock4_state {
3660 struct tevent_context *ev;
3661 struct cli_state *cli;
3666 static void oplock4_got_break(struct tevent_req *req);
3667 static void oplock4_got_open(struct tevent_req *req);
3669 static bool run_oplock4(int dummy)
3671 struct tevent_context *ev;
3672 struct cli_state *cli1, *cli2;
3673 struct tevent_req *oplock_req, *open_req;
3674 const char *fname = "\\lockt4.lck";
3675 const char *fname_ln = "\\lockt4_ln.lck";
3676 uint16_t fnum1, fnum2;
3677 int saved_use_oplocks = use_oplocks;
3679 bool correct = true;
3683 struct oplock4_state *state;
3685 printf("starting oplock test 4\n");
3687 if (!torture_open_connection(&cli1, 0)) {
3688 use_level_II_oplocks = false;
3689 use_oplocks = saved_use_oplocks;
3693 if (!torture_open_connection(&cli2, 1)) {
3694 use_level_II_oplocks = false;
3695 use_oplocks = saved_use_oplocks;
3699 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3700 cli_unlink(cli1, fname_ln, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3702 cli_sockopt(cli1, sockops);
3703 cli_sockopt(cli2, sockops);
3705 /* Create the file. */
3706 status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
3708 if (!NT_STATUS_IS_OK(status)) {
3709 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
3713 status = cli_close(cli1, fnum1);
3714 if (!NT_STATUS_IS_OK(status)) {
3715 printf("close1 failed (%s)\n", nt_errstr(status));
3719 /* Now create a hardlink. */
3720 status = cli_nt_hardlink(cli1, fname, fname_ln);
3721 if (!NT_STATUS_IS_OK(status)) {
3722 printf("nt hardlink failed (%s)\n", nt_errstr(status));
3726 /* Prove that opening hardlinks cause deny modes to conflict. */
3727 status = cli_open(cli1, fname, O_RDWR, DENY_ALL, &fnum1);
3728 if (!NT_STATUS_IS_OK(status)) {
3729 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
3733 status = cli_open(cli1, fname_ln, O_RDWR, DENY_NONE, &fnum2);
3734 if (NT_STATUS_IS_OK(status)) {
3735 printf("open of %s succeeded - should fail with sharing violation.\n",
3740 if (!NT_STATUS_EQUAL(status, NT_STATUS_SHARING_VIOLATION)) {
3741 printf("open of %s should fail with sharing violation. Got %s\n",
3742 fname_ln, nt_errstr(status));
3746 status = cli_close(cli1, fnum1);
3747 if (!NT_STATUS_IS_OK(status)) {
3748 printf("close1 failed (%s)\n", nt_errstr(status));
3752 cli1->use_oplocks = true;
3753 cli1->use_level_II_oplocks = true;
3755 cli2->use_oplocks = true;
3756 cli2->use_level_II_oplocks = true;
3758 status = cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
3759 if (!NT_STATUS_IS_OK(status)) {
3760 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
3764 ev = tevent_context_init(talloc_tos());
3766 printf("tevent_req_create failed\n");
3770 state = talloc(ev, struct oplock4_state);
3771 if (state == NULL) {
3772 printf("talloc failed\n");
3777 state->got_break = &got_break;
3778 state->fnum2 = &fnum2;
3780 oplock_req = cli_smb_oplock_break_waiter_send(
3781 talloc_tos(), ev, cli1);
3782 if (oplock_req == NULL) {
3783 printf("cli_smb_oplock_break_waiter_send failed\n");
3786 tevent_req_set_callback(oplock_req, oplock4_got_break, state);
3788 open_req = cli_open_send(
3789 talloc_tos(), ev, cli2, fname_ln, O_RDWR, DENY_NONE);
3790 if (oplock_req == NULL) {
3791 printf("cli_open_send failed\n");
3794 tevent_req_set_callback(open_req, oplock4_got_open, state);
3799 while (!got_break || fnum2 == 0xffff) {
3801 ret = tevent_loop_once(ev);
3803 printf("tevent_loop_once failed: %s\n",
3809 status = cli_close(cli2, fnum2);
3810 if (!NT_STATUS_IS_OK(status)) {
3811 printf("close2 failed (%s)\n", nt_errstr(status));
3815 status = cli_close(cli1, fnum1);
3816 if (!NT_STATUS_IS_OK(status)) {
3817 printf("close1 failed (%s)\n", nt_errstr(status));
3821 status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3822 if (!NT_STATUS_IS_OK(status)) {
3823 printf("unlink failed (%s)\n", nt_errstr(status));
3827 status = cli_unlink(cli1, fname_ln, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3828 if (!NT_STATUS_IS_OK(status)) {
3829 printf("unlink failed (%s)\n", nt_errstr(status));
3833 if (!torture_close_connection(cli1)) {
3841 printf("finished oplock test 4\n");
3846 static void oplock4_got_break(struct tevent_req *req)
3848 struct oplock4_state *state = tevent_req_callback_data(
3849 req, struct oplock4_state);
3854 status = cli_smb_oplock_break_waiter_recv(req, &fnum, &level);
3856 if (!NT_STATUS_IS_OK(status)) {
3857 printf("cli_smb_oplock_break_waiter_recv returned %s\n",
3861 *state->got_break = true;
3863 req = cli_oplock_ack_send(state, state->ev, state->cli, fnum,
3866 printf("cli_oplock_ack_send failed\n");
3871 static void oplock4_got_open(struct tevent_req *req)
3873 struct oplock4_state *state = tevent_req_callback_data(
3874 req, struct oplock4_state);
3877 status = cli_open_recv(req, state->fnum2);
3878 if (!NT_STATUS_IS_OK(status)) {
3879 printf("cli_open_recv returned %s\n", nt_errstr(status));
3880 *state->fnum2 = 0xffff;
3885 Test delete on close semantics.
3887 static bool run_deletetest(int dummy)
3889 struct cli_state *cli1 = NULL;
3890 struct cli_state *cli2 = NULL;
3891 const char *fname = "\\delete.file";
3892 uint16_t fnum1 = (uint16_t)-1;
3893 uint16_t fnum2 = (uint16_t)-1;
3894 bool correct = True;
3897 printf("starting delete test\n");
3899 if (!torture_open_connection(&cli1, 0)) {
3903 cli_sockopt(cli1, sockops);
3905 /* Test 1 - this should delete the file on close. */
3907 cli_setatr(cli1, fname, 0, 0);
3908 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3910 status = cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
3911 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
3912 FILE_DELETE_ON_CLOSE, 0, &fnum1);
3913 if (!NT_STATUS_IS_OK(status)) {
3914 printf("[1] open of %s failed (%s)\n", fname, nt_errstr(status));
3919 status = cli_close(cli1, fnum1);
3920 if (!NT_STATUS_IS_OK(status)) {
3921 printf("[1] close failed (%s)\n", nt_errstr(status));
3926 if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1))) {
3927 printf("[1] open of %s succeeded (should fail)\n", fname);
3932 printf("first delete on close test succeeded.\n");
3934 /* Test 2 - this should delete the file on close. */
3936 cli_setatr(cli1, fname, 0, 0);
3937 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3939 status = cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS,
3940 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
3941 FILE_OVERWRITE_IF, 0, 0, &fnum1);
3942 if (!NT_STATUS_IS_OK(status)) {
3943 printf("[2] open of %s failed (%s)\n", fname, nt_errstr(status));
3948 status = cli_nt_delete_on_close(cli1, fnum1, true);
3949 if (!NT_STATUS_IS_OK(status)) {
3950 printf("[2] setting delete_on_close failed (%s)\n", nt_errstr(status));
3955 status = cli_close(cli1, fnum1);
3956 if (!NT_STATUS_IS_OK(status)) {
3957 printf("[2] close failed (%s)\n", nt_errstr(status));
3962 if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
3963 printf("[2] open of %s succeeded should have been deleted on close !\n", fname);
3964 status = cli_close(cli1, fnum1);
3965 if (!NT_STATUS_IS_OK(status)) {
3966 printf("[2] close failed (%s)\n", nt_errstr(status));
3970 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3972 printf("second delete on close test succeeded.\n");
3975 cli_setatr(cli1, fname, 0, 0);
3976 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3978 status = cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS,
3979 FILE_ATTRIBUTE_NORMAL,
3980 FILE_SHARE_READ|FILE_SHARE_WRITE,
3981 FILE_OVERWRITE_IF, 0, 0, &fnum1);
3982 if (!NT_STATUS_IS_OK(status)) {
3983 printf("[3] open - 1 of %s failed (%s)\n", fname, nt_errstr(status));
3988 /* This should fail with a sharing violation - open for delete is only compatible
3989 with SHARE_DELETE. */
3991 if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3992 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0, 0, &fnum2))) {
3993 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname);
3998 /* This should succeed. */
3999 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
4000 FILE_ATTRIBUTE_NORMAL,
4001 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4002 FILE_OPEN, 0, 0, &fnum2);
4003 if (!NT_STATUS_IS_OK(status)) {
4004 printf("[3] open - 2 of %s failed (%s)\n", fname, nt_errstr(status));
4009 status = cli_nt_delete_on_close(cli1, fnum1, true);
4010 if (!NT_STATUS_IS_OK(status)) {
4011 printf("[3] setting delete_on_close failed (%s)\n", nt_errstr(status));
4016 status = cli_close(cli1, fnum1);
4017 if (!NT_STATUS_IS_OK(status)) {
4018 printf("[3] close 1 failed (%s)\n", nt_errstr(status));
4023 status = cli_close(cli1, fnum2);
4024 if (!NT_STATUS_IS_OK(status)) {
4025 printf("[3] close 2 failed (%s)\n", nt_errstr(status));
4030 /* This should fail - file should no longer be there. */
4032 if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
4033 printf("[3] open of %s succeeded should have been deleted on close !\n", fname);
4034 status = cli_close(cli1, fnum1);
4035 if (!NT_STATUS_IS_OK(status)) {
4036 printf("[3] close failed (%s)\n", nt_errstr(status));
4038 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4042 printf("third delete on close test succeeded.\n");
4045 cli_setatr(cli1, fname, 0, 0);
4046 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4048 status = cli_ntcreate(cli1, fname, 0,
4049 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
4050 FILE_ATTRIBUTE_NORMAL,
4051 FILE_SHARE_READ|FILE_SHARE_WRITE,
4052 FILE_OVERWRITE_IF, 0, 0, &fnum1);
4053 if (!NT_STATUS_IS_OK(status)) {
4054 printf("[4] open of %s failed (%s)\n", fname, nt_errstr(status));
4059 /* This should succeed. */
4060 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
4061 FILE_ATTRIBUTE_NORMAL,
4062 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4063 FILE_OPEN, 0, 0, &fnum2);
4064 if (!NT_STATUS_IS_OK(status)) {
4065 printf("[4] open - 2 of %s failed (%s)\n", fname, nt_errstr(status));
4070 status = cli_close(cli1, fnum2);
4071 if (!NT_STATUS_IS_OK(status)) {
4072 printf("[4] close - 1 failed (%s)\n", nt_errstr(status));
4077 status = cli_nt_delete_on_close(cli1, fnum1, true);
4078 if (!NT_STATUS_IS_OK(status)) {
4079 printf("[4] setting delete_on_close failed (%s)\n", nt_errstr(status));
4084 /* This should fail - no more opens once delete on close set. */
4085 if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
4086 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4087 FILE_OPEN, 0, 0, &fnum2))) {
4088 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname );
4092 printf("fourth delete on close test succeeded.\n");
4094 status = cli_close(cli1, fnum1);
4095 if (!NT_STATUS_IS_OK(status)) {
4096 printf("[4] close - 2 failed (%s)\n", nt_errstr(status));
4102 cli_setatr(cli1, fname, 0, 0);
4103 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4105 status = cli_open(cli1, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum1);
4106 if (!NT_STATUS_IS_OK(status)) {
4107 printf("[5] open of %s failed (%s)\n", fname, nt_errstr(status));
4112 /* This should fail - only allowed on NT opens with DELETE access. */
4114 if (NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
4115 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
4120 status = cli_close(cli1, fnum1);
4121 if (!NT_STATUS_IS_OK(status)) {
4122 printf("[5] close - 2 failed (%s)\n", nt_errstr(status));
4127 printf("fifth delete on close test succeeded.\n");
4130 cli_setatr(cli1, fname, 0, 0);
4131 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4133 status = cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
4134 FILE_ATTRIBUTE_NORMAL,
4135 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4136 FILE_OVERWRITE_IF, 0, 0, &fnum1);
4137 if (!NT_STATUS_IS_OK(status)) {
4138 printf("[6] open of %s failed (%s)\n", fname,
4144 /* This should fail - only allowed on NT opens with DELETE access. */
4146 if (NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
4147 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
4152 status = cli_close(cli1, fnum1);
4153 if (!NT_STATUS_IS_OK(status)) {
4154 printf("[6] close - 2 failed (%s)\n", nt_errstr(status));
4159 printf("sixth delete on close test succeeded.\n");
4162 cli_setatr(cli1, fname, 0, 0);
4163 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4165 status = cli_ntcreate(cli1, fname, 0,
4166 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
4167 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
4169 if (!NT_STATUS_IS_OK(status)) {
4170 printf("[7] open of %s failed (%s)\n", fname, nt_errstr(status));
4175 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
4176 printf("[7] setting delete_on_close on file failed !\n");
4181 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, false))) {
4182 printf("[7] unsetting delete_on_close on file failed !\n");
4187 status = cli_close(cli1, fnum1);
4188 if (!NT_STATUS_IS_OK(status)) {
4189 printf("[7] close - 2 failed (%s)\n", nt_errstr(status));
4194 /* This next open should succeed - we reset the flag. */
4195 status = cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1);
4196 if (!NT_STATUS_IS_OK(status)) {
4197 printf("[5] open of %s failed (%s)\n", fname, nt_errstr(status));
4202 status = cli_close(cli1, fnum1);
4203 if (!NT_STATUS_IS_OK(status)) {
4204 printf("[7] close - 2 failed (%s)\n", nt_errstr(status));
4209 printf("seventh delete on close test succeeded.\n");
4212 cli_setatr(cli1, fname, 0, 0);
4213 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4215 if (!torture_open_connection(&cli2, 1)) {
4216 printf("[8] failed to open second connection.\n");
4221 cli_sockopt(cli1, sockops);
4223 status = cli_ntcreate(cli1, fname, 0,
4224 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
4225 FILE_ATTRIBUTE_NORMAL,
4226 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4227 FILE_OVERWRITE_IF, 0, 0, &fnum1);
4228 if (!NT_STATUS_IS_OK(status)) {
4229 printf("[8] open 1 of %s failed (%s)\n", fname, nt_errstr(status));
4234 status = cli_ntcreate(cli2, fname, 0,
4235 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
4236 FILE_ATTRIBUTE_NORMAL,
4237 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4238 FILE_OPEN, 0, 0, &fnum2);
4239 if (!NT_STATUS_IS_OK(status)) {
4240 printf("[8] open 2 of %s failed (%s)\n", fname, nt_errstr(status));
4245 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
4246 printf("[8] setting delete_on_close on file failed !\n");
4251 status = cli_close(cli1, fnum1);
4252 if (!NT_STATUS_IS_OK(status)) {
4253 printf("[8] close - 1 failed (%s)\n", nt_errstr(status));
4258 status = cli_close(cli2, fnum2);
4259 if (!NT_STATUS_IS_OK(status)) {
4260 printf("[8] close - 2 failed (%s)\n", nt_errstr(status));
4265 /* This should fail.. */
4266 status = cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1);
4267 if (NT_STATUS_IS_OK(status)) {
4268 printf("[8] open of %s succeeded should have been deleted on close !\n", fname);
4272 printf("eighth delete on close test succeeded.\n");
4274 /* This should fail - we need to set DELETE_ACCESS. */
4275 if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0,FILE_READ_DATA|FILE_WRITE_DATA,
4276 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, 0, &fnum1))) {
4277 printf("[9] open of %s succeeded should have failed!\n", fname);
4282 printf("ninth delete on close test succeeded.\n");
4284 status = cli_ntcreate(cli1, fname, 0,
4285 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
4286 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
4287 FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE,
4289 if (!NT_STATUS_IS_OK(status)) {
4290 printf("[10] open of %s failed (%s)\n", fname, nt_errstr(status));
4295 /* This should delete the file. */
4296 status = cli_close(cli1, fnum1);
4297 if (!NT_STATUS_IS_OK(status)) {
4298 printf("[10] close failed (%s)\n", nt_errstr(status));
4303 /* This should fail.. */
4304 if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
4305 printf("[10] open of %s succeeded should have been deleted on close !\n", fname);
4309 printf("tenth delete on close test succeeded.\n");
4311 cli_setatr(cli1, fname, 0, 0);
4312 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4314 /* What error do we get when attempting to open a read-only file with
4317 /* Create a readonly file. */
4318 status = cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
4319 FILE_ATTRIBUTE_READONLY, FILE_SHARE_NONE,
4320 FILE_OVERWRITE_IF, 0, 0, &fnum1);
4321 if (!NT_STATUS_IS_OK(status)) {
4322 printf("[11] open of %s failed (%s)\n", fname, nt_errstr(status));
4327 status = cli_close(cli1, fnum1);
4328 if (!NT_STATUS_IS_OK(status)) {
4329 printf("[11] close failed (%s)\n", nt_errstr(status));
4334 /* Now try open for delete access. */
4335 if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES|DELETE_ACCESS,
4336 0, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4337 FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
4338 printf("[11] open of %s succeeded should have been denied with ACCESS_DENIED!\n", fname);
4339 cli_close(cli1, fnum1);
4343 NTSTATUS nterr = cli_nt_error(cli1);
4344 if (!NT_STATUS_EQUAL(nterr,NT_STATUS_ACCESS_DENIED)) {
4345 printf("[11] open of %s should have been denied with ACCESS_DENIED! Got error %s\n", fname, nt_errstr(nterr));
4349 printf("eleventh delete on close test succeeded.\n");
4353 printf("finished delete test\n");
4356 /* FIXME: This will crash if we aborted before cli2 got
4357 * intialized, because these functions don't handle
4358 * uninitialized connections. */
4360 if (fnum1 != (uint16_t)-1) cli_close(cli1, fnum1);
4361 if (fnum2 != (uint16_t)-1) cli_close(cli1, fnum2);
4362 cli_setatr(cli1, fname, 0, 0);
4363 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4365 if (cli1 && !torture_close_connection(cli1)) {
4368 if (cli2 && !torture_close_connection(cli2)) {
4374 static bool run_deletetest_ln(int dummy)
4376 struct cli_state *cli;
4377 const char *fname = "\\delete1";
4378 const char *fname_ln = "\\delete1_ln";
4382 bool correct = true;
4385 printf("starting deletetest-ln\n");
4387 if (!torture_open_connection(&cli, 0)) {
4391 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4392 cli_unlink(cli, fname_ln, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4394 cli_sockopt(cli, sockops);
4396 /* Create the file. */
4397 status = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
4398 if (!NT_STATUS_IS_OK(status)) {
4399 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
4403 status = cli_close(cli, fnum);
4404 if (!NT_STATUS_IS_OK(status)) {
4405 printf("close1 failed (%s)\n", nt_errstr(status));
4409 /* Now create a hardlink. */
4410 status = cli_nt_hardlink(cli, fname, fname_ln);
4411 if (!NT_STATUS_IS_OK(status)) {
4412 printf("nt hardlink failed (%s)\n", nt_errstr(status));
4416 /* Open the original file. */
4417 status = cli_ntcreate(cli, fname, 0, FILE_READ_DATA,
4418 FILE_ATTRIBUTE_NORMAL,
4419 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4420 FILE_OPEN_IF, 0, 0, &fnum);
4421 if (!NT_STATUS_IS_OK(status)) {
4422 printf("ntcreate of %s failed (%s)\n", fname, nt_errstr(status));
4426 /* Unlink the hard link path. */
4427 status = cli_ntcreate(cli, fname_ln, 0, DELETE_ACCESS,
4428 FILE_ATTRIBUTE_NORMAL,
4429 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4430 FILE_OPEN_IF, 0, 0, &fnum1);
4431 if (!NT_STATUS_IS_OK(status)) {
4432 printf("ntcreate of %s failed (%s)\n", fname_ln, nt_errstr(status));
4435 status = cli_nt_delete_on_close(cli, fnum1, true);
4436 if (!NT_STATUS_IS_OK(status)) {
4437 d_printf("(%s) failed to set delete_on_close %s: %s\n",
4438 __location__, fname_ln, nt_errstr(status));
4442 status = cli_close(cli, fnum1);
4443 if (!NT_STATUS_IS_OK(status)) {
4444 printf("close %s failed (%s)\n",
4445 fname_ln, nt_errstr(status));
4449 status = cli_close(cli, fnum);
4450 if (!NT_STATUS_IS_OK(status)) {
4451 printf("close %s failed (%s)\n",
4452 fname, nt_errstr(status));
4456 /* Ensure the original file is still there. */
4457 status = cli_getatr(cli, fname, NULL, NULL, &t);
4458 if (!NT_STATUS_IS_OK(status)) {
4459 printf("%s getatr on file %s failed (%s)\n",
4466 /* Ensure the link path is gone. */
4467 status = cli_getatr(cli, fname_ln, NULL, NULL, &t);
4468 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
4469 printf("%s, getatr for file %s returned wrong error code %s "
4470 "- should have been deleted\n",
4472 fname_ln, nt_errstr(status));
4476 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4477 cli_unlink(cli, fname_ln, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4479 if (!torture_close_connection(cli)) {
4483 printf("finished deletetest-ln\n");
4489 print out server properties
4491 static bool run_properties(int dummy)
4493 struct cli_state *cli;
4494 bool correct = True;
4496 printf("starting properties test\n");
4500 if (!torture_open_connection(&cli, 0)) {
4504 cli_sockopt(cli, sockops);
4506 d_printf("Capabilities 0x%08x\n", cli->capabilities);
4508 if (!torture_close_connection(cli)) {
4517 /* FIRST_DESIRED_ACCESS 0xf019f */
4518 #define FIRST_DESIRED_ACCESS FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|\
4519 FILE_READ_EA| /* 0xf */ \
4520 FILE_WRITE_EA|FILE_READ_ATTRIBUTES| /* 0x90 */ \
4521 FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
4522 DELETE_ACCESS|READ_CONTROL_ACCESS|\
4523 WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS /* 0xf0000 */
4524 /* SECOND_DESIRED_ACCESS 0xe0080 */
4525 #define SECOND_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
4526 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
4527 WRITE_OWNER_ACCESS /* 0xe0000 */
4530 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
4531 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
4533 WRITE_OWNER_ACCESS /* */
4537 Test ntcreate calls made by xcopy
4539 static bool run_xcopy(int dummy)
4541 static struct cli_state *cli1;
4542 const char *fname = "\\test.txt";
4543 bool correct = True;
4544 uint16_t fnum1, fnum2;
4547 printf("starting xcopy test\n");
4549 if (!torture_open_connection(&cli1, 0)) {
4553 status = cli_ntcreate(cli1, fname, 0, FIRST_DESIRED_ACCESS,
4554 FILE_ATTRIBUTE_ARCHIVE, FILE_SHARE_NONE,
4555 FILE_OVERWRITE_IF, 0x4044, 0, &fnum1);
4556 if (!NT_STATUS_IS_OK(status)) {
4557 printf("First open failed - %s\n", nt_errstr(status));
4561 status = cli_ntcreate(cli1, fname, 0, SECOND_DESIRED_ACCESS, 0,
4562 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4563 FILE_OPEN, 0x200000, 0, &fnum2);
4564 if (!NT_STATUS_IS_OK(status)) {
4565 printf("second open failed - %s\n", nt_errstr(status));
4569 if (!torture_close_connection(cli1)) {
4577 Test rename on files open with share delete and no share delete.
4579 static bool run_rename(int dummy)
4581 static struct cli_state *cli1;
4582 const char *fname = "\\test.txt";
4583 const char *fname1 = "\\test1.txt";
4584 bool correct = True;
4589 printf("starting rename test\n");
4591 if (!torture_open_connection(&cli1, 0)) {
4595 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4596 cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4598 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
4599 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ,
4600 FILE_OVERWRITE_IF, 0, 0, &fnum1);
4601 if (!NT_STATUS_IS_OK(status)) {
4602 printf("First open failed - %s\n", nt_errstr(status));
4606 status = cli_rename(cli1, fname, fname1);
4607 if (!NT_STATUS_IS_OK(status)) {
4608 printf("First rename failed (SHARE_READ) (this is correct) - %s\n", nt_errstr(status));
4610 printf("First rename succeeded (SHARE_READ) - this should have failed !\n");
4614 status = cli_close(cli1, fnum1);
4615 if (!NT_STATUS_IS_OK(status)) {
4616 printf("close - 1 failed (%s)\n", nt_errstr(status));
4620 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4621 cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4622 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
4624 FILE_SHARE_DELETE|FILE_SHARE_NONE,
4626 FILE_SHARE_DELETE|FILE_SHARE_READ,
4628 FILE_OVERWRITE_IF, 0, 0, &fnum1);
4629 if (!NT_STATUS_IS_OK(status)) {
4630 printf("Second open failed - %s\n", nt_errstr(status));
4634 status = cli_rename(cli1, fname, fname1);
4635 if (!NT_STATUS_IS_OK(status)) {
4636 printf("Second rename failed (SHARE_DELETE | SHARE_READ) - this should have succeeded - %s\n", nt_errstr(status));
4639 printf("Second rename succeeded (SHARE_DELETE | SHARE_READ)\n");
4642 status = cli_close(cli1, fnum1);
4643 if (!NT_STATUS_IS_OK(status)) {
4644 printf("close - 2 failed (%s)\n", nt_errstr(status));
4648 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4649 cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4651 status = cli_ntcreate(cli1, fname, 0, READ_CONTROL_ACCESS,
4652 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
4653 FILE_OVERWRITE_IF, 0, 0, &fnum1);
4654 if (!NT_STATUS_IS_OK(status)) {
4655 printf("Third open failed - %s\n", nt_errstr(status));
4664 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
4665 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum2))) {
4666 printf("Fourth open failed - %s\n", cli_errstr(cli1));
4669 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum2, true))) {
4670 printf("[8] setting delete_on_close on file failed !\n");
4674 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum2))) {
4675 printf("close - 4 failed (%s)\n", cli_errstr(cli1));
4681 status = cli_rename(cli1, fname, fname1);
4682 if (!NT_STATUS_IS_OK(status)) {
4683 printf("Third rename failed (SHARE_NONE) - this should have succeeded - %s\n", nt_errstr(status));
4686 printf("Third rename succeeded (SHARE_NONE)\n");
4689 status = cli_close(cli1, fnum1);
4690 if (!NT_STATUS_IS_OK(status)) {
4691 printf("close - 3 failed (%s)\n", nt_errstr(status));
4695 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4696 cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4700 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
4701 FILE_ATTRIBUTE_NORMAL,
4702 FILE_SHARE_READ | FILE_SHARE_WRITE,
4703 FILE_OVERWRITE_IF, 0, 0, &fnum1);
4704 if (!NT_STATUS_IS_OK(status)) {
4705 printf("Fourth open failed - %s\n", nt_errstr(status));
4709 status = cli_rename(cli1, fname, fname1);
4710 if (!NT_STATUS_IS_OK(status)) {
4711 printf("Fourth rename failed (SHARE_READ | SHARE_WRITE) (this is correct) - %s\n", nt_errstr(status));
4713 printf("Fourth rename succeeded (SHARE_READ | SHARE_WRITE) - this should have failed !\n");
4717 status = cli_close(cli1, fnum1);
4718 if (!NT_STATUS_IS_OK(status)) {
4719 printf("close - 4 failed (%s)\n", nt_errstr(status));
4723 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4724 cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4728 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
4729 FILE_ATTRIBUTE_NORMAL,
4730 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
4731 FILE_OVERWRITE_IF, 0, 0, &fnum1);
4732 if (!NT_STATUS_IS_OK(status)) {
4733 printf("Fifth open failed - %s\n", nt_errstr(status));
4737 status = cli_rename(cli1, fname, fname1);
4738 if (!NT_STATUS_IS_OK(status)) {
4739 printf("Fifth rename failed (SHARE_READ | SHARE_WRITE | SHARE_DELETE) - this should have succeeded - %s ! \n", nt_errstr(status));
4742 printf("Fifth rename succeeded (SHARE_READ | SHARE_WRITE | SHARE_DELETE) (this is correct) - %s\n", nt_errstr(status));
4746 * Now check if the first name still exists ...
4749 /* if (!NT_STATUS_OP(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
4750 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0, &fnum2))) {
4751 printf("Opening original file after rename of open file fails: %s\n",
4755 printf("Opening original file after rename of open file works ...\n");
4756 (void)cli_close(cli1, fnum2);
4760 status = cli_close(cli1, fnum1);
4761 if (!NT_STATUS_IS_OK(status)) {
4762 printf("close - 5 failed (%s)\n", nt_errstr(status));
4766 /* Check that the renamed file has FILE_ATTRIBUTE_ARCHIVE. */
4767 status = cli_getatr(cli1, fname1, &attr, NULL, NULL);
4768 if (!NT_STATUS_IS_OK(status)) {
4769 printf("getatr on file %s failed - %s ! \n",
4770 fname1, nt_errstr(status));
4773 if (attr != FILE_ATTRIBUTE_ARCHIVE) {
4774 printf("Renamed file %s has wrong attr 0x%x "
4775 "(should be 0x%x)\n",
4778 (unsigned int)FILE_ATTRIBUTE_ARCHIVE);
4781 printf("Renamed file %s has archive bit set\n", fname1);
4785 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4786 cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4788 if (!torture_close_connection(cli1)) {
4795 static bool run_pipe_number(int dummy)
4797 struct cli_state *cli1;
4798 const char *pipe_name = "\\SPOOLSS";
4803 printf("starting pipenumber test\n");
4804 if (!torture_open_connection(&cli1, 0)) {
4808 cli_sockopt(cli1, sockops);
4810 status = cli_ntcreate(cli1, pipe_name, 0, FILE_READ_DATA,
4811 FILE_ATTRIBUTE_NORMAL,
4812 FILE_SHARE_READ|FILE_SHARE_WRITE,
4813 FILE_OPEN_IF, 0, 0, &fnum);
4814 if (!NT_STATUS_IS_OK(status)) {
4815 printf("Open of pipe %s failed with error (%s)\n", pipe_name, nt_errstr(status));
4819 printf("\r%6d", num_pipes);
4822 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes, pipe_name );
4823 torture_close_connection(cli1);
4828 Test open mode returns on read-only files.
4830 static bool run_opentest(int dummy)
4832 static struct cli_state *cli1;
4833 static struct cli_state *cli2;
4834 const char *fname = "\\readonly.file";
4835 uint16_t fnum1, fnum2;
4838 bool correct = True;
4842 printf("starting open test\n");
4844 if (!torture_open_connection(&cli1, 0)) {
4848 cli_setatr(cli1, fname, 0, 0);
4849 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4851 cli_sockopt(cli1, sockops);
4853 status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
4854 if (!NT_STATUS_IS_OK(status)) {
4855 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
4859 status = cli_close(cli1, fnum1);
4860 if (!NT_STATUS_IS_OK(status)) {
4861 printf("close2 failed (%s)\n", nt_errstr(status));
4865 status = cli_setatr(cli1, fname, FILE_ATTRIBUTE_READONLY, 0);
4866 if (!NT_STATUS_IS_OK(status)) {
4867 printf("cli_setatr failed (%s)\n", nt_errstr(status));
4871 status = cli_open(cli1, fname, O_RDONLY, DENY_WRITE, &fnum1);
4872 if (!NT_STATUS_IS_OK(status)) {
4873 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
4877 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
4878 status = cli_open(cli1, fname, O_RDWR, DENY_ALL, &fnum2);
4880 if (check_error(__LINE__, status, ERRDOS, ERRnoaccess,
4881 NT_STATUS_ACCESS_DENIED)) {
4882 printf("correct error code ERRDOS/ERRnoaccess returned\n");
4885 printf("finished open test 1\n");
4887 cli_close(cli1, fnum1);
4889 /* Now try not readonly and ensure ERRbadshare is returned. */
4891 cli_setatr(cli1, fname, 0, 0);
4893 status = cli_open(cli1, fname, O_RDONLY, DENY_WRITE, &fnum1);
4894 if (!NT_STATUS_IS_OK(status)) {
4895 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
4899 /* This will fail - but the error should be ERRshare. */
4900 status = cli_open(cli1, fname, O_RDWR, DENY_ALL, &fnum2);
4902 if (check_error(__LINE__, status, ERRDOS, ERRbadshare,
4903 NT_STATUS_SHARING_VIOLATION)) {
4904 printf("correct error code ERRDOS/ERRbadshare returned\n");
4907 status = cli_close(cli1, fnum1);
4908 if (!NT_STATUS_IS_OK(status)) {
4909 printf("close2 failed (%s)\n", nt_errstr(status));
4913 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4915 printf("finished open test 2\n");
4917 /* Test truncate open disposition on file opened for read. */
4918 status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
4919 if (!NT_STATUS_IS_OK(status)) {
4920 printf("(3) open (1) of %s failed (%s)\n", fname, nt_errstr(status));
4924 /* write 20 bytes. */
4926 memset(buf, '\0', 20);
4928 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 0, 20, NULL);
4929 if (!NT_STATUS_IS_OK(status)) {
4930 printf("write failed (%s)\n", nt_errstr(status));
4934 status = cli_close(cli1, fnum1);
4935 if (!NT_STATUS_IS_OK(status)) {
4936 printf("(3) close1 failed (%s)\n", nt_errstr(status));
4940 /* Ensure size == 20. */
4941 status = cli_getatr(cli1, fname, NULL, &fsize, NULL);
4942 if (!NT_STATUS_IS_OK(status)) {
4943 printf("(3) getatr failed (%s)\n", nt_errstr(status));
4948 printf("(3) file size != 20\n");
4952 /* Now test if we can truncate a file opened for readonly. */
4953 status = cli_open(cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE, &fnum1);
4954 if (!NT_STATUS_IS_OK(status)) {
4955 printf("(3) open (2) of %s failed (%s)\n", fname, nt_errstr(status));
4959 status = cli_close(cli1, fnum1);
4960 if (!NT_STATUS_IS_OK(status)) {
4961 printf("close2 failed (%s)\n", nt_errstr(status));
4965 /* Ensure size == 0. */
4966 status = cli_getatr(cli1, fname, NULL, &fsize, NULL);
4967 if (!NT_STATUS_IS_OK(status)) {
4968 printf("(3) getatr failed (%s)\n", nt_errstr(status));
4973 printf("(3) file size != 0\n");
4976 printf("finished open test 3\n");
4978 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4980 printf("Do ctemp tests\n");
4981 status = cli_ctemp(cli1, talloc_tos(), "\\", &fnum1, &tmp_path);
4982 if (!NT_STATUS_IS_OK(status)) {
4983 printf("ctemp failed (%s)\n", nt_errstr(status));
4987 printf("ctemp gave path %s\n", tmp_path);
4988 status = cli_close(cli1, fnum1);
4989 if (!NT_STATUS_IS_OK(status)) {
4990 printf("close of temp failed (%s)\n", nt_errstr(status));
4993 status = cli_unlink(cli1, tmp_path, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4994 if (!NT_STATUS_IS_OK(status)) {
4995 printf("unlink of temp failed (%s)\n", nt_errstr(status));
4998 /* Test the non-io opens... */
5000 if (!torture_open_connection(&cli2, 1)) {
5004 cli_setatr(cli2, fname, 0, 0);
5005 cli_unlink(cli2, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5007 cli_sockopt(cli2, sockops);
5009 printf("TEST #1 testing 2 non-io opens (no delete)\n");
5010 status = cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES,
5011 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5012 FILE_OVERWRITE_IF, 0, 0, &fnum1);
5013 if (!NT_STATUS_IS_OK(status)) {
5014 printf("TEST #1 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
5018 status = cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES,
5019 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5020 FILE_OPEN_IF, 0, 0, &fnum2);
5021 if (!NT_STATUS_IS_OK(status)) {
5022 printf("TEST #1 open 2 of %s failed (%s)\n", fname, nt_errstr(status));
5026 status = cli_close(cli1, fnum1);
5027 if (!NT_STATUS_IS_OK(status)) {
5028 printf("TEST #1 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
5032 status = cli_close(cli2, fnum2);
5033 if (!NT_STATUS_IS_OK(status)) {
5034 printf("TEST #1 close 2 of %s failed (%s)\n", fname, nt_errstr(status));
5038 printf("non-io open test #1 passed.\n");
5040 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5042 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
5044 status = cli_ntcreate(cli1, fname, 0,
5045 DELETE_ACCESS|FILE_READ_ATTRIBUTES,
5046 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5047 FILE_OVERWRITE_IF, 0, 0, &fnum1);
5048 if (!NT_STATUS_IS_OK(status)) {
5049 printf("TEST #2 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
5053 status = cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES,
5054 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5055 FILE_OPEN_IF, 0, 0, &fnum2);
5056 if (!NT_STATUS_IS_OK(status)) {
5057 printf("TEST #2 open 2 of %s failed (%s)\n", fname, nt_errstr(status));
5061 status = cli_close(cli1, fnum1);
5062 if (!NT_STATUS_IS_OK(status)) {
5063 printf("TEST #2 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
5067 status = cli_close(cli2, fnum2);
5068 if (!NT_STATUS_IS_OK(status)) {
5069 printf("TEST #2 close 2 of %s failed (%s)\n", fname, nt_errstr(status));
5073 printf("non-io open test #2 passed.\n");
5075 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5077 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
5079 status = cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES,
5080 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5081 FILE_OVERWRITE_IF, 0, 0, &fnum1);
5082 if (!NT_STATUS_IS_OK(status)) {
5083 printf("TEST #3 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
5087 status = cli_ntcreate(cli2, fname, 0,
5088 DELETE_ACCESS|FILE_READ_ATTRIBUTES,
5089 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5090 FILE_OPEN_IF, 0, 0, &fnum2);
5091 if (!NT_STATUS_IS_OK(status)) {
5092 printf("TEST #3 open 2 of %s failed (%s)\n", fname, nt_errstr(status));
5096 status = cli_close(cli1, fnum1);
5097 if (!NT_STATUS_IS_OK(status)) {
5098 printf("TEST #3 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
5102 status = cli_close(cli2, fnum2);
5103 if (!NT_STATUS_IS_OK(status)) {
5104 printf("TEST #3 close 2 of %s failed (%s)\n", fname, nt_errstr(status));
5108 printf("non-io open test #3 passed.\n");
5110 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5112 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
5114 status = cli_ntcreate(cli1, fname, 0,
5115 DELETE_ACCESS|FILE_READ_ATTRIBUTES,
5116 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5117 FILE_OVERWRITE_IF, 0, 0, &fnum1);
5118 if (!NT_STATUS_IS_OK(status)) {
5119 printf("TEST #4 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
5123 status = cli_ntcreate(cli2, fname, 0,
5124 DELETE_ACCESS|FILE_READ_ATTRIBUTES,
5125 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5126 FILE_OPEN_IF, 0, 0, &fnum2);
5127 if (NT_STATUS_IS_OK(status)) {
5128 printf("TEST #4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, nt_errstr(status));
5132 printf("TEST #4 open 2 of %s gave %s (correct error should be %s)\n", fname, nt_errstr(status), "sharing violation");
5134 status = cli_close(cli1, fnum1);
5135 if (!NT_STATUS_IS_OK(status)) {
5136 printf("TEST #4 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
5140 printf("non-io open test #4 passed.\n");
5142 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5144 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
5146 status = cli_ntcreate(cli1, fname, 0,
5147 DELETE_ACCESS|FILE_READ_ATTRIBUTES,
5148 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_DELETE,
5149 FILE_OVERWRITE_IF, 0, 0, &fnum1);
5150 if (!NT_STATUS_IS_OK(status)) {
5151 printf("TEST #5 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
5155 status = cli_ntcreate(cli2, fname, 0,
5156 DELETE_ACCESS|FILE_READ_ATTRIBUTES,
5157 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_DELETE,
5158 FILE_OPEN_IF, 0, 0, &fnum2);
5159 if (!NT_STATUS_IS_OK(status)) {
5160 printf("TEST #5 open 2 of %s failed (%s)\n", fname, nt_errstr(status));
5164 status = cli_close(cli1, fnum1);
5165 if (!NT_STATUS_IS_OK(status)) {
5166 printf("TEST #5 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
5170 status = cli_close(cli2, fnum2);
5171 if (!NT_STATUS_IS_OK(status)) {
5172 printf("TEST #5 close 2 of %s failed (%s)\n", fname, nt_errstr(status));
5176 printf("non-io open test #5 passed.\n");
5178 printf("TEST #6 testing 1 non-io open, one io open\n");
5180 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5182 status = cli_ntcreate(cli1, fname, 0, FILE_READ_DATA,
5183 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5184 FILE_OVERWRITE_IF, 0, 0, &fnum1);
5185 if (!NT_STATUS_IS_OK(status)) {
5186 printf("TEST #6 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
5190 status = cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES,
5191 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ,
5192 FILE_OPEN_IF, 0, 0, &fnum2);
5193 if (!NT_STATUS_IS_OK(status)) {
5194 printf("TEST #6 open 2 of %s failed (%s)\n", fname, nt_errstr(status));
5198 status = cli_close(cli1, fnum1);
5199 if (!NT_STATUS_IS_OK(status)) {
5200 printf("TEST #6 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
5204 status = cli_close(cli2, fnum2);
5205 if (!NT_STATUS_IS_OK(status)) {
5206 printf("TEST #6 close 2 of %s failed (%s)\n", fname, nt_errstr(status));
5210 printf("non-io open test #6 passed.\n");
5212 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
5214 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5216 status = cli_ntcreate(cli1, fname, 0, FILE_READ_DATA,
5217 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5218 FILE_OVERWRITE_IF, 0, 0, &fnum1);
5219 if (!NT_STATUS_IS_OK(status)) {
5220 printf("TEST #7 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
5224 status = cli_ntcreate(cli2, fname, 0,
5225 DELETE_ACCESS|FILE_READ_ATTRIBUTES,
5226 FILE_ATTRIBUTE_NORMAL,
5227 FILE_SHARE_READ|FILE_SHARE_DELETE,
5228 FILE_OPEN_IF, 0, 0, &fnum2);
5229 if (NT_STATUS_IS_OK(status)) {
5230 printf("TEST #7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, nt_errstr(status));
5234 printf("TEST #7 open 2 of %s gave %s (correct error should be %s)\n", fname, nt_errstr(status), "sharing violation");
5236 status = cli_close(cli1, fnum1);
5237 if (!NT_STATUS_IS_OK(status)) {
5238 printf("TEST #7 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
5242 printf("non-io open test #7 passed.\n");
5244 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5246 printf("TEST #8 testing open without WRITE_ATTRIBUTES, updating close write time.\n");
5247 status = cli_ntcreate(cli1, fname, 0, FILE_WRITE_DATA, FILE_ATTRIBUTE_NORMAL,
5248 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
5249 FILE_OVERWRITE_IF, 0, 0, &fnum1);
5250 if (!NT_STATUS_IS_OK(status)) {
5251 printf("TEST #8 open of %s failed (%s)\n", fname, nt_errstr(status));
5256 /* Write to ensure we have to update the file time. */
5257 status = cli_writeall(cli1, fnum1, 0, (const uint8_t *)"TEST DATA\n", 0, 10,
5259 if (!NT_STATUS_IS_OK(status)) {
5260 printf("TEST #8 cli_write failed: %s\n", nt_errstr(status));
5265 status = cli_close(cli1, fnum1);
5266 if (!NT_STATUS_IS_OK(status)) {
5267 printf("TEST #8 close of %s failed (%s)\n", fname, nt_errstr(status));
5273 if (!torture_close_connection(cli1)) {
5276 if (!torture_close_connection(cli2)) {
5283 NTSTATUS torture_setup_unix_extensions(struct cli_state *cli)
5285 uint16 major, minor;
5286 uint32 caplow, caphigh;
5289 if (!SERVER_HAS_UNIX_CIFS(cli)) {
5290 printf("Server doesn't support UNIX CIFS extensions.\n");
5291 return NT_STATUS_NOT_SUPPORTED;
5294 status = cli_unix_extensions_version(cli, &major, &minor, &caplow,
5296 if (!NT_STATUS_IS_OK(status)) {
5297 printf("Server didn't return UNIX CIFS extensions: %s\n",
5302 status = cli_set_unix_extensions_capabilities(cli, major, minor,
5304 if (!NT_STATUS_IS_OK(status)) {
5305 printf("Server doesn't support setting UNIX CIFS extensions: "
5306 "%s.\n", nt_errstr(status));
5310 return NT_STATUS_OK;
5314 Test POSIX open /mkdir calls.
5316 static bool run_simple_posix_open_test(int dummy)
5318 static struct cli_state *cli1;
5319 const char *fname = "posix:file";
5320 const char *hname = "posix:hlink";
5321 const char *sname = "posix:symlink";
5322 const char *dname = "posix:dir";
5325 uint16_t fnum1 = (uint16_t)-1;
5326 SMB_STRUCT_STAT sbuf;
5327 bool correct = false;
5331 printf("Starting simple POSIX open test\n");
5333 if (!torture_open_connection(&cli1, 0)) {
5337 cli_sockopt(cli1, sockops);
5339 status = torture_setup_unix_extensions(cli1);
5340 if (!NT_STATUS_IS_OK(status)) {
5344 cli_setatr(cli1, fname, 0, 0);
5345 cli_posix_unlink(cli1, fname);
5346 cli_setatr(cli1, dname, 0, 0);
5347 cli_posix_rmdir(cli1, dname);
5348 cli_setatr(cli1, hname, 0, 0);
5349 cli_posix_unlink(cli1, hname);
5350 cli_setatr(cli1, sname, 0, 0);
5351 cli_posix_unlink(cli1, sname);
5353 /* Create a directory. */
5354 status = cli_posix_mkdir(cli1, dname, 0777);
5355 if (!NT_STATUS_IS_OK(status)) {
5356 printf("POSIX mkdir of %s failed (%s)\n", dname, nt_errstr(status));
5360 status = cli_posix_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL,
5362 if (!NT_STATUS_IS_OK(status)) {
5363 printf("POSIX create of %s failed (%s)\n", fname, nt_errstr(status));
5367 /* Test ftruncate - set file size. */
5368 status = cli_ftruncate(cli1, fnum1, 1000);
5369 if (!NT_STATUS_IS_OK(status)) {
5370 printf("ftruncate failed (%s)\n", nt_errstr(status));
5374 /* Ensure st_size == 1000 */
5375 status = cli_posix_stat(cli1, fname, &sbuf);
5376 if (!NT_STATUS_IS_OK(status)) {
5377 printf("stat failed (%s)\n", nt_errstr(status));
5381 if (sbuf.st_ex_size != 1000) {
5382 printf("ftruncate - stat size (%u) != 1000\n", (unsigned int)sbuf.st_ex_size);
5386 /* Test ftruncate - set file size back to zero. */
5387 status = cli_ftruncate(cli1, fnum1, 0);
5388 if (!NT_STATUS_IS_OK(status)) {
5389 printf("ftruncate failed (%s)\n", nt_errstr(status));
5393 status = cli_close(cli1, fnum1);
5394 if (!NT_STATUS_IS_OK(status)) {
5395 printf("close failed (%s)\n", nt_errstr(status));
5399 /* Now open the file again for read only. */
5400 status = cli_posix_open(cli1, fname, O_RDONLY, 0, &fnum1);
5401 if (!NT_STATUS_IS_OK(status)) {
5402 printf("POSIX open of %s failed (%s)\n", fname, nt_errstr(status));
5406 /* Now unlink while open. */
5407 status = cli_posix_unlink(cli1, fname);
5408 if (!NT_STATUS_IS_OK(status)) {
5409 printf("POSIX unlink of %s failed (%s)\n", fname, nt_errstr(status));
5413 status = cli_close(cli1, fnum1);
5414 if (!NT_STATUS_IS_OK(status)) {
5415 printf("close(2) failed (%s)\n", nt_errstr(status));
5419 /* Ensure the file has gone. */
5420 status = cli_posix_open(cli1, fname, O_RDONLY, 0, &fnum1);
5421 if (NT_STATUS_IS_OK(status)) {
5422 printf("POSIX open of %s succeeded, should have been deleted.\n", fname);
5426 /* Create again to test open with O_TRUNC. */
5427 status = cli_posix_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, 0600, &fnum1);
5428 if (!NT_STATUS_IS_OK(status)) {
5429 printf("POSIX create of %s failed (%s)\n", fname, nt_errstr(status));
5433 /* Test ftruncate - set file size. */
5434 status = cli_ftruncate(cli1, fnum1, 1000);
5435 if (!NT_STATUS_IS_OK(status)) {
5436 printf("ftruncate failed (%s)\n", nt_errstr(status));
5440 /* Ensure st_size == 1000 */
5441 status = cli_posix_stat(cli1, fname, &sbuf);
5442 if (!NT_STATUS_IS_OK(status)) {
5443 printf("stat failed (%s)\n", nt_errstr(status));
5447 if (sbuf.st_ex_size != 1000) {
5448 printf("ftruncate - stat size (%u) != 1000\n", (unsigned int)sbuf.st_ex_size);
5452 status = cli_close(cli1, fnum1);
5453 if (!NT_STATUS_IS_OK(status)) {
5454 printf("close(2) failed (%s)\n", nt_errstr(status));
5458 /* Re-open with O_TRUNC. */
5459 status = cli_posix_open(cli1, fname, O_WRONLY|O_TRUNC, 0600, &fnum1);
5460 if (!NT_STATUS_IS_OK(status)) {
5461 printf("POSIX create of %s failed (%s)\n", fname, nt_errstr(status));
5465 /* Ensure st_size == 0 */
5466 status = cli_posix_stat(cli1, fname, &sbuf);
5467 if (!NT_STATUS_IS_OK(status)) {
5468 printf("stat failed (%s)\n", nt_errstr(status));
5472 if (sbuf.st_ex_size != 0) {
5473 printf("O_TRUNC - stat size (%u) != 0\n", (unsigned int)sbuf.st_ex_size);
5477 status = cli_close(cli1, fnum1);
5478 if (!NT_STATUS_IS_OK(status)) {
5479 printf("close failed (%s)\n", nt_errstr(status));
5483 status = cli_posix_unlink(cli1, fname);
5484 if (!NT_STATUS_IS_OK(status)) {
5485 printf("POSIX unlink of %s failed (%s)\n", fname, nt_errstr(status));
5489 status = cli_posix_open(cli1, dname, O_RDONLY, 0, &fnum1);
5490 if (!NT_STATUS_IS_OK(status)) {
5491 printf("POSIX open directory O_RDONLY of %s failed (%s)\n",
5492 dname, nt_errstr(status));
5496 cli_close(cli1, fnum1);
5498 /* What happens when we try and POSIX open a directory for write ? */
5499 status = cli_posix_open(cli1, dname, O_RDWR, 0, &fnum1);
5500 if (NT_STATUS_IS_OK(status)) {
5501 printf("POSIX open of directory %s succeeded, should have failed.\n", fname);
5504 if (!check_both_error(__LINE__, status, ERRDOS, EISDIR,
5505 NT_STATUS_FILE_IS_A_DIRECTORY)) {
5510 /* Create the file. */
5511 status = cli_posix_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL,
5513 if (!NT_STATUS_IS_OK(status)) {
5514 printf("POSIX create of %s failed (%s)\n", fname, nt_errstr(status));
5518 /* Write some data into it. */
5519 status = cli_writeall(cli1, fnum1, 0, (const uint8_t *)"TEST DATA\n", 0, 10,
5521 if (!NT_STATUS_IS_OK(status)) {
5522 printf("cli_write failed: %s\n", nt_errstr(status));
5526 cli_close(cli1, fnum1);
5528 /* Now create a hardlink. */
5529 status = cli_posix_hardlink(cli1, fname, hname);
5530 if (!NT_STATUS_IS_OK(status)) {
5531 printf("POSIX hardlink of %s failed (%s)\n", hname, nt_errstr(status));
5535 /* Now create a symlink. */
5536 status = cli_posix_symlink(cli1, fname, sname);
5537 if (!NT_STATUS_IS_OK(status)) {
5538 printf("POSIX symlink of %s failed (%s)\n", sname, nt_errstr(status));
5542 /* Open the hardlink for read. */
5543 status = cli_posix_open(cli1, hname, O_RDONLY, 0, &fnum1);
5544 if (!NT_STATUS_IS_OK(status)) {
5545 printf("POSIX open of %s failed (%s)\n", hname, nt_errstr(status));
5549 status = cli_read(cli1, fnum1, buf, 0, 10, &nread);
5550 if (!NT_STATUS_IS_OK(status)) {
5551 printf("POSIX read of %s failed (%s)\n", hname,
5554 } else if (nread != 10) {
5555 printf("POSIX read of %s failed. Received %ld, expected %d\n",
5556 hname, (unsigned long)nread, 10);
5560 if (memcmp(buf, "TEST DATA\n", 10)) {
5561 printf("invalid data read from hardlink\n");
5565 /* Do a POSIX lock/unlock. */
5566 status = cli_posix_lock(cli1, fnum1, 0, 100, true, READ_LOCK);
5567 if (!NT_STATUS_IS_OK(status)) {
5568 printf("POSIX lock failed %s\n", nt_errstr(status));
5572 /* Punch a hole in the locked area. */
5573 status = cli_posix_unlock(cli1, fnum1, 10, 80);
5574 if (!NT_STATUS_IS_OK(status)) {
5575 printf("POSIX unlock failed %s\n", nt_errstr(status));
5579 cli_close(cli1, fnum1);
5581 /* Open the symlink for read - this should fail. A POSIX
5582 client should not be doing opens on a symlink. */
5583 status = cli_posix_open(cli1, sname, O_RDONLY, 0, &fnum1);
5584 if (NT_STATUS_IS_OK(status)) {
5585 printf("POSIX open of %s succeeded (should have failed)\n", sname);
5588 if (!check_both_error(__LINE__, status, ERRDOS, ERRbadpath,
5589 NT_STATUS_OBJECT_PATH_NOT_FOUND)) {
5590 printf("POSIX open of %s should have failed "
5591 "with NT_STATUS_OBJECT_PATH_NOT_FOUND, "
5592 "failed with %s instead.\n",
5593 sname, nt_errstr(status));
5598 status = cli_posix_readlink(cli1, sname, namebuf, sizeof(namebuf));
5599 if (!NT_STATUS_IS_OK(status)) {
5600 printf("POSIX readlink on %s failed (%s)\n", sname, nt_errstr(status));
5604 if (strcmp(namebuf, fname) != 0) {
5605 printf("POSIX readlink on %s failed to match name %s (read %s)\n",
5606 sname, fname, namebuf);
5610 status = cli_posix_rmdir(cli1, dname);
5611 if (!NT_STATUS_IS_OK(status)) {
5612 printf("POSIX rmdir failed (%s)\n", nt_errstr(status));
5616 printf("Simple POSIX open test passed\n");
5621 if (fnum1 != (uint16_t)-1) {
5622 cli_close(cli1, fnum1);
5623 fnum1 = (uint16_t)-1;
5626 cli_setatr(cli1, sname, 0, 0);
5627 cli_posix_unlink(cli1, sname);
5628 cli_setatr(cli1, hname, 0, 0);
5629 cli_posix_unlink(cli1, hname);
5630 cli_setatr(cli1, fname, 0, 0);
5631 cli_posix_unlink(cli1, fname);
5632 cli_setatr(cli1, dname, 0, 0);
5633 cli_posix_rmdir(cli1, dname);
5635 if (!torture_close_connection(cli1)) {
5643 static uint32 open_attrs_table[] = {
5644 FILE_ATTRIBUTE_NORMAL,
5645 FILE_ATTRIBUTE_ARCHIVE,
5646 FILE_ATTRIBUTE_READONLY,
5647 FILE_ATTRIBUTE_HIDDEN,
5648 FILE_ATTRIBUTE_SYSTEM,
5650 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY,
5651 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN,
5652 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM,
5653 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
5654 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
5655 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
5657 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
5658 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
5659 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
5660 FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_SYSTEM,
5663 struct trunc_open_results {
5670 static struct trunc_open_results attr_results[] = {
5671 { 0, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
5672 { 1, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
5673 { 2, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
5674 { 16, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
5675 { 17, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
5676 { 18, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
5677 { 51, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
5678 { 54, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
5679 { 56, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
5680 { 68, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
5681 { 71, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
5682 { 73, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM },
5683 { 99, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
5684 { 102, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
5685 { 104, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
5686 { 116, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
5687 { 119, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
5688 { 121, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM },
5689 { 170, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN },
5690 { 173, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM },
5691 { 227, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
5692 { 230, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
5693 { 232, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
5694 { 244, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
5695 { 247, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
5696 { 249, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM }
5699 static bool run_openattrtest(int dummy)
5701 static struct cli_state *cli1;
5702 const char *fname = "\\openattr.file";
5704 bool correct = True;
5706 unsigned int i, j, k, l;
5709 printf("starting open attr test\n");
5711 if (!torture_open_connection(&cli1, 0)) {
5715 cli_sockopt(cli1, sockops);
5717 for (k = 0, i = 0; i < sizeof(open_attrs_table)/sizeof(uint32); i++) {
5718 cli_setatr(cli1, fname, 0, 0);
5719 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5721 status = cli_ntcreate(cli1, fname, 0, FILE_WRITE_DATA,
5722 open_attrs_table[i], FILE_SHARE_NONE,
5723 FILE_OVERWRITE_IF, 0, 0, &fnum1);
5724 if (!NT_STATUS_IS_OK(status)) {
5725 printf("open %d (1) of %s failed (%s)\n", i, fname, nt_errstr(status));
5729 status = cli_close(cli1, fnum1);
5730 if (!NT_STATUS_IS_OK(status)) {
5731 printf("close %d (1) of %s failed (%s)\n", i, fname, nt_errstr(status));
5735 for (j = 0; j < sizeof(open_attrs_table)/sizeof(uint32); j++) {
5736 status = cli_ntcreate(cli1, fname, 0,
5737 FILE_READ_DATA|FILE_WRITE_DATA,
5738 open_attrs_table[j],
5739 FILE_SHARE_NONE, FILE_OVERWRITE,
5741 if (!NT_STATUS_IS_OK(status)) {
5742 for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
5743 if (attr_results[l].num == k) {
5744 printf("[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(0x%x:%s)\n",
5745 k, open_attrs_table[i],
5746 open_attrs_table[j],
5747 fname, NT_STATUS_V(status), nt_errstr(status));
5752 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
5753 printf("[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s\n",
5754 k, open_attrs_table[i], open_attrs_table[j],
5759 printf("[%d] trunc open 0x%x -> 0x%x failed\n", k, open_attrs_table[i], open_attrs_table[j]);
5765 status = cli_close(cli1, fnum1);
5766 if (!NT_STATUS_IS_OK(status)) {
5767 printf("close %d (2) of %s failed (%s)\n", j, fname, nt_errstr(status));
5771 status = cli_getatr(cli1, fname, &attr, NULL, NULL);
5772 if (!NT_STATUS_IS_OK(status)) {
5773 printf("getatr(2) failed (%s)\n", nt_errstr(status));
5778 printf("[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n",
5779 k, open_attrs_table[i], open_attrs_table[j], attr );
5782 for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
5783 if (attr_results[l].num == k) {
5784 if (attr != attr_results[l].result_attr ||
5785 open_attrs_table[i] != attr_results[l].init_attr ||
5786 open_attrs_table[j] != attr_results[l].trunc_attr) {
5787 printf("getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x\n",
5788 open_attrs_table[i],
5789 open_attrs_table[j],
5791 attr_results[l].result_attr);
5801 cli_setatr(cli1, fname, 0, 0);
5802 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5804 printf("open attr test %s.\n", correct ? "passed" : "failed");
5806 if (!torture_close_connection(cli1)) {
5812 static NTSTATUS list_fn(const char *mnt, struct file_info *finfo,
5813 const char *name, void *state)
5815 int *matched = (int *)state;
5816 if (matched != NULL) {
5819 return NT_STATUS_OK;
5823 test directory listing speed
5825 static bool run_dirtest(int dummy)
5828 static struct cli_state *cli;
5830 struct timeval core_start;
5831 bool correct = True;
5834 printf("starting directory test\n");
5836 if (!torture_open_connection(&cli, 0)) {
5840 cli_sockopt(cli, sockops);
5843 for (i=0;i<torture_numops;i++) {
5845 slprintf(fname, sizeof(fname), "\\%x", (int)random());
5846 if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum))) {
5847 fprintf(stderr,"Failed to open %s\n", fname);
5850 cli_close(cli, fnum);
5853 core_start = timeval_current();
5856 cli_list(cli, "a*.*", 0, list_fn, &matched);
5857 printf("Matched %d\n", matched);
5860 cli_list(cli, "b*.*", 0, list_fn, &matched);
5861 printf("Matched %d\n", matched);
5864 cli_list(cli, "xyzabc", 0, list_fn, &matched);
5865 printf("Matched %d\n", matched);
5867 printf("dirtest core %g seconds\n", timeval_elapsed(&core_start));
5870 for (i=0;i<torture_numops;i++) {
5872 slprintf(fname, sizeof(fname), "\\%x", (int)random());
5873 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5876 if (!torture_close_connection(cli)) {
5880 printf("finished dirtest\n");
5885 static NTSTATUS del_fn(const char *mnt, struct file_info *finfo, const char *mask,
5888 struct cli_state *pcli = (struct cli_state *)state;
5890 slprintf(fname, sizeof(fname), "\\LISTDIR\\%s", finfo->name);
5892 if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
5893 return NT_STATUS_OK;
5895 if (finfo->mode & FILE_ATTRIBUTE_DIRECTORY) {
5896 if (!NT_STATUS_IS_OK(cli_rmdir(pcli, fname)))
5897 printf("del_fn: failed to rmdir %s\n,", fname );
5899 if (!NT_STATUS_IS_OK(cli_unlink(pcli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN)))
5900 printf("del_fn: failed to unlink %s\n,", fname );
5902 return NT_STATUS_OK;
5907 sees what IOCTLs are supported
5909 bool torture_ioctl_test(int dummy)
5911 static struct cli_state *cli;
5912 uint16_t device, function;
5914 const char *fname = "\\ioctl.dat";
5918 if (!torture_open_connection(&cli, 0)) {
5922 printf("starting ioctl test\n");
5924 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5926 status = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
5927 if (!NT_STATUS_IS_OK(status)) {
5928 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
5932 status = cli_raw_ioctl(cli, fnum, 0x2d0000 | (0x0420<<2), &blob);
5933 printf("ioctl device info: %s\n", nt_errstr(status));
5935 status = cli_raw_ioctl(cli, fnum, IOCTL_QUERY_JOB_INFO, &blob);
5936 printf("ioctl job info: %s\n", nt_errstr(status));
5938 for (device=0;device<0x100;device++) {
5939 printf("ioctl test with device = 0x%x\n", device);
5940 for (function=0;function<0x100;function++) {
5941 uint32 code = (device<<16) | function;
5943 status = cli_raw_ioctl(cli, fnum, code, &blob);
5945 if (NT_STATUS_IS_OK(status)) {
5946 printf("ioctl 0x%x OK : %d bytes\n", (int)code,
5948 data_blob_free(&blob);
5953 if (!torture_close_connection(cli)) {
5962 tries varients of chkpath
5964 bool torture_chkpath_test(int dummy)
5966 static struct cli_state *cli;
5971 if (!torture_open_connection(&cli, 0)) {
5975 printf("starting chkpath test\n");
5977 /* cleanup from an old run */
5978 cli_rmdir(cli, "\\chkpath.dir\\dir2");
5979 cli_unlink(cli, "\\chkpath.dir\\*", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5980 cli_rmdir(cli, "\\chkpath.dir");
5982 status = cli_mkdir(cli, "\\chkpath.dir");
5983 if (!NT_STATUS_IS_OK(status)) {
5984 printf("mkdir1 failed : %s\n", nt_errstr(status));
5988 status = cli_mkdir(cli, "\\chkpath.dir\\dir2");
5989 if (!NT_STATUS_IS_OK(status)) {
5990 printf("mkdir2 failed : %s\n", nt_errstr(status));
5994 status = cli_open(cli, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL,
5996 if (!NT_STATUS_IS_OK(status)) {
5997 printf("open1 failed (%s)\n", nt_errstr(status));
6000 cli_close(cli, fnum);
6002 status = cli_chkpath(cli, "\\chkpath.dir");
6003 if (!NT_STATUS_IS_OK(status)) {
6004 printf("chkpath1 failed: %s\n", nt_errstr(status));
6008 status = cli_chkpath(cli, "\\chkpath.dir\\dir2");
6009 if (!NT_STATUS_IS_OK(status)) {
6010 printf("chkpath2 failed: %s\n", nt_errstr(status));
6014 status = cli_chkpath(cli, "\\chkpath.dir\\foo.txt");
6015 if (!NT_STATUS_IS_OK(status)) {
6016 ret = check_error(__LINE__, status, ERRDOS, ERRbadpath,
6017 NT_STATUS_NOT_A_DIRECTORY);
6019 printf("* chkpath on a file should fail\n");
6023 status = cli_chkpath(cli, "\\chkpath.dir\\bar.txt");
6024 if (!NT_STATUS_IS_OK(status)) {
6025 ret = check_error(__LINE__, status, ERRDOS, ERRbadfile,
6026 NT_STATUS_OBJECT_NAME_NOT_FOUND);
6028 printf("* chkpath on a non existant file should fail\n");
6032 status = cli_chkpath(cli, "\\chkpath.dir\\dirxx\\bar.txt");
6033 if (!NT_STATUS_IS_OK(status)) {
6034 ret = check_error(__LINE__, status, ERRDOS, ERRbadpath,
6035 NT_STATUS_OBJECT_PATH_NOT_FOUND);
6037 printf("* chkpath on a non existent component should fail\n");
6041 cli_rmdir(cli, "\\chkpath.dir\\dir2");
6042 cli_unlink(cli, "\\chkpath.dir\\*", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
6043 cli_rmdir(cli, "\\chkpath.dir");
6045 if (!torture_close_connection(cli)) {
6052 static bool run_eatest(int dummy)
6054 static struct cli_state *cli;
6055 const char *fname = "\\eatest.txt";
6056 bool correct = True;
6060 struct ea_struct *ea_list = NULL;
6061 TALLOC_CTX *mem_ctx = talloc_init("eatest");
6064 printf("starting eatest\n");
6066 if (!torture_open_connection(&cli, 0)) {
6067 talloc_destroy(mem_ctx);
6071 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
6073 status = cli_ntcreate(cli, fname, 0,
6074 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
6075 FILE_SHARE_NONE, FILE_OVERWRITE_IF,
6077 if (!NT_STATUS_IS_OK(status)) {
6078 printf("open failed - %s\n", nt_errstr(status));
6079 talloc_destroy(mem_ctx);
6083 for (i = 0; i < 10; i++) {
6084 fstring ea_name, ea_val;
6086 slprintf(ea_name, sizeof(ea_name), "EA_%d", i);
6087 memset(ea_val, (char)i+1, i+1);
6088 status = cli_set_ea_fnum(cli, fnum, ea_name, ea_val, i+1);
6089 if (!NT_STATUS_IS_OK(status)) {
6090 printf("ea_set of name %s failed - %s\n", ea_name,
6092 talloc_destroy(mem_ctx);
6097 cli_close(cli, fnum);
6098 for (i = 0; i < 10; i++) {
6099 fstring ea_name, ea_val;
6101 slprintf(ea_name, sizeof(ea_name), "EA_%d", i+10);
6102 memset(ea_val, (char)i+1, i+1);
6103 status = cli_set_ea_path(cli, fname, ea_name, ea_val, i+1);
6104 if (!NT_STATUS_IS_OK(status)) {
6105 printf("ea_set of name %s failed - %s\n", ea_name,
6107 talloc_destroy(mem_ctx);
6112 status = cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list);
6113 if (!NT_STATUS_IS_OK(status)) {
6114 printf("ea_get list failed - %s\n", nt_errstr(status));
6118 printf("num_eas = %d\n", (int)num_eas);
6120 if (num_eas != 20) {
6121 printf("Should be 20 EA's stored... failing.\n");
6125 for (i = 0; i < num_eas; i++) {
6126 printf("%d: ea_name = %s. Val = ", i, ea_list[i].name);
6127 dump_data(0, ea_list[i].value.data,
6128 ea_list[i].value.length);
6131 /* Setting EA's to zero length deletes them. Test this */
6132 printf("Now deleting all EA's - case indepenent....\n");
6135 cli_set_ea_path(cli, fname, "", "", 0);
6137 for (i = 0; i < 20; i++) {
6139 slprintf(ea_name, sizeof(ea_name), "ea_%d", i);
6140 status = cli_set_ea_path(cli, fname, ea_name, "", 0);
6141 if (!NT_STATUS_IS_OK(status)) {
6142 printf("ea_set of name %s failed - %s\n", ea_name,
6144 talloc_destroy(mem_ctx);
6150 status = cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list);
6151 if (!NT_STATUS_IS_OK(status)) {
6152 printf("ea_get list failed - %s\n", nt_errstr(status));
6156 printf("num_eas = %d\n", (int)num_eas);
6157 for (i = 0; i < num_eas; i++) {
6158 printf("%d: ea_name = %s. Val = ", i, ea_list[i].name);
6159 dump_data(0, ea_list[i].value.data,
6160 ea_list[i].value.length);
6164 printf("deleting EA's failed.\n");
6168 /* Try and delete a non existant EA. */
6169 status = cli_set_ea_path(cli, fname, "foo", "", 0);
6170 if (!NT_STATUS_IS_OK(status)) {
6171 printf("deleting non-existant EA 'foo' should succeed. %s\n",
6176 talloc_destroy(mem_ctx);
6177 if (!torture_close_connection(cli)) {
6184 static bool run_dirtest1(int dummy)
6187 static struct cli_state *cli;
6190 bool correct = True;
6192 printf("starting directory test\n");
6194 if (!torture_open_connection(&cli, 0)) {
6198 cli_sockopt(cli, sockops);
6200 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
6201 cli_list(cli, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, del_fn, cli);
6202 cli_rmdir(cli, "\\LISTDIR");
6203 cli_mkdir(cli, "\\LISTDIR");
6205 /* Create 1000 files and 1000 directories. */
6206 for (i=0;i<1000;i++) {
6208 slprintf(fname, sizeof(fname), "\\LISTDIR\\f%d", i);
6209 if (!NT_STATUS_IS_OK(cli_ntcreate(cli, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
6210 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum))) {
6211 fprintf(stderr,"Failed to open %s\n", fname);
6214 cli_close(cli, fnum);
6216 for (i=0;i<1000;i++) {
6218 slprintf(fname, sizeof(fname), "\\LISTDIR\\d%d", i);
6219 if (!NT_STATUS_IS_OK(cli_mkdir(cli, fname))) {
6220 fprintf(stderr,"Failed to open %s\n", fname);
6225 /* Now ensure that doing an old list sees both files and directories. */
6227 cli_list_old(cli, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, list_fn, &num_seen);
6228 printf("num_seen = %d\n", num_seen );
6229 /* We should see 100 files + 1000 directories + . and .. */
6230 if (num_seen != 2002)
6233 /* Ensure if we have the "must have" bits we only see the
6237 cli_list_old(cli, "\\LISTDIR\\*", (FILE_ATTRIBUTE_DIRECTORY<<8)|FILE_ATTRIBUTE_DIRECTORY, list_fn, &num_seen);
6238 printf("num_seen = %d\n", num_seen );
6239 if (num_seen != 1002)
6243 cli_list_old(cli, "\\LISTDIR\\*", (FILE_ATTRIBUTE_ARCHIVE<<8)|FILE_ATTRIBUTE_DIRECTORY, list_fn, &num_seen);
6244 printf("num_seen = %d\n", num_seen );
6245 if (num_seen != 1000)
6248 /* Delete everything. */
6249 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
6250 cli_list(cli, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, del_fn, cli);
6251 cli_rmdir(cli, "\\LISTDIR");
6254 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
6255 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
6256 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
6259 if (!torture_close_connection(cli)) {
6263 printf("finished dirtest1\n");
6268 static bool run_error_map_extract(int dummy) {
6270 static struct cli_state *c_dos;
6271 static struct cli_state *c_nt;
6283 /* NT-Error connection */
6285 if (!(c_nt = open_nbt_connection())) {
6289 c_nt->use_spnego = False;
6291 status = cli_negprot(c_nt);
6293 if (!NT_STATUS_IS_OK(status)) {
6294 printf("%s rejected the NT-error negprot (%s)\n", host,
6300 status = cli_session_setup(c_nt, "", "", 0, "", 0, workgroup);
6301 if (!NT_STATUS_IS_OK(status)) {
6302 printf("%s rejected the NT-error initial session setup (%s)\n",host, nt_errstr(status));
6306 /* DOS-Error connection */
6308 if (!(c_dos = open_nbt_connection())) {
6312 c_dos->use_spnego = False;
6313 c_dos->force_dos_errors = True;
6315 status = cli_negprot(c_dos);
6316 if (!NT_STATUS_IS_OK(status)) {
6317 printf("%s rejected the DOS-error negprot (%s)\n", host,
6319 cli_shutdown(c_dos);
6323 status = cli_session_setup(c_dos, "", "", 0, "", 0, workgroup);
6324 if (!NT_STATUS_IS_OK(status)) {
6325 printf("%s rejected the DOS-error initial session setup (%s)\n",
6326 host, nt_errstr(status));
6330 for (error=(0xc0000000 | 0x1); error < (0xc0000000| 0xFFF); error++) {
6331 fstr_sprintf(user, "%X", error);
6333 status = cli_session_setup(c_nt, user,
6334 password, strlen(password),
6335 password, strlen(password),
6337 if (NT_STATUS_IS_OK(status)) {
6338 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
6341 /* Case #1: 32-bit NT errors */
6342 if (cli_is_nt_error(c_nt)) {
6343 nt_status = cli_nt_error(c_nt);
6345 printf("/** Dos error on NT connection! (%s) */\n",
6347 nt_status = NT_STATUS(0xc0000000);
6350 status = cli_session_setup(c_dos, user,
6351 password, strlen(password),
6352 password, strlen(password),
6354 if (NT_STATUS_IS_OK(status)) {
6355 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
6358 /* Case #1: 32-bit NT errors */
6359 if (!cli_is_dos_error(c_dos)) {
6360 printf("/** NT error on DOS connection! (%s) */\n",
6362 errnum = errclass = 0;
6364 cli_dos_error(c_dos, &errclass, &errnum);
6367 if (NT_STATUS_V(nt_status) != error) {
6368 printf("/*\t{ This NT error code was 'sqashed'\n\t from %s to %s \n\t during the session setup }\n*/\n",
6369 get_nt_error_c_code(talloc_tos(), NT_STATUS(error)),
6370 get_nt_error_c_code(talloc_tos(), nt_status));
6373 printf("\t{%s,\t%s,\t%s},\n",
6374 smb_dos_err_class(errclass),
6375 smb_dos_err_name(errclass, errnum),
6376 get_nt_error_c_code(talloc_tos(), NT_STATUS(error)));
6381 static bool run_sesssetup_bench(int dummy)
6383 static struct cli_state *c;
6384 const char *fname = "\\file.dat";
6389 if (!torture_open_connection(&c, 0)) {
6393 status = cli_ntcreate(c, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
6394 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
6395 FILE_DELETE_ON_CLOSE, 0, &fnum);
6396 if (!NT_STATUS_IS_OK(status)) {
6397 d_printf("open %s failed: %s\n", fname, nt_errstr(status));
6401 for (i=0; i<torture_numops; i++) {
6402 status = cli_session_setup(
6404 password, strlen(password),
6405 password, strlen(password),
6407 if (!NT_STATUS_IS_OK(status)) {
6408 d_printf("(%s) cli_session_setup failed: %s\n",
6409 __location__, nt_errstr(status));
6413 d_printf("\r%d ", (int)cli_state_get_uid(c));
6415 status = cli_ulogoff(c);
6416 if (!NT_STATUS_IS_OK(status)) {
6417 d_printf("(%s) cli_ulogoff failed: %s\n",
6418 __location__, nt_errstr(status));
6426 static bool subst_test(const char *str, const char *user, const char *domain,
6427 uid_t uid, gid_t gid, const char *expected)
6432 subst = talloc_sub_specified(talloc_tos(), str, user, domain, uid, gid);
6434 if (strcmp(subst, expected) != 0) {
6435 printf("sub_specified(%s, %s, %s, %d, %d) returned [%s], expected "
6436 "[%s]\n", str, user, domain, (int)uid, (int)gid, subst,
6445 static void chain1_open_completion(struct tevent_req *req)
6449 status = cli_open_recv(req, &fnum);
6452 d_printf("cli_open_recv returned %s: %d\n",
6454 NT_STATUS_IS_OK(status) ? fnum : -1);
6457 static void chain1_write_completion(struct tevent_req *req)
6461 status = cli_write_andx_recv(req, &written);
6464 d_printf("cli_write_andx_recv returned %s: %d\n",
6466 NT_STATUS_IS_OK(status) ? (int)written : -1);
6469 static void chain1_close_completion(struct tevent_req *req)
6472 bool *done = (bool *)tevent_req_callback_data_void(req);
6474 status = cli_close_recv(req);
6479 d_printf("cli_close returned %s\n", nt_errstr(status));
6482 static bool run_chain1(int dummy)
6484 struct cli_state *cli1;
6485 struct event_context *evt = event_context_init(NULL);
6486 struct tevent_req *reqs[3], *smbreqs[3];
6488 const char *str = "foobar";
6491 printf("starting chain1 test\n");
6492 if (!torture_open_connection(&cli1, 0)) {
6496 cli_sockopt(cli1, sockops);
6498 reqs[0] = cli_open_create(talloc_tos(), evt, cli1, "\\test",
6499 O_CREAT|O_RDWR, 0, &smbreqs[0]);
6500 if (reqs[0] == NULL) return false;
6501 tevent_req_set_callback(reqs[0], chain1_open_completion, NULL);
6504 reqs[1] = cli_write_andx_create(talloc_tos(), evt, cli1, 0, 0,
6505 (const uint8_t *)str, 0, strlen(str)+1,
6506 smbreqs, 1, &smbreqs[1]);
6507 if (reqs[1] == NULL) return false;
6508 tevent_req_set_callback(reqs[1], chain1_write_completion, NULL);
6510 reqs[2] = cli_close_create(talloc_tos(), evt, cli1, 0, &smbreqs[2]);
6511 if (reqs[2] == NULL) return false;
6512 tevent_req_set_callback(reqs[2], chain1_close_completion, &done);
6514 status = cli_smb_chain_send(smbreqs, ARRAY_SIZE(smbreqs));
6515 if (!NT_STATUS_IS_OK(status)) {
6520 event_loop_once(evt);
6523 torture_close_connection(cli1);
6527 static void chain2_sesssetup_completion(struct tevent_req *req)
6530 status = cli_session_setup_guest_recv(req);
6531 d_printf("sesssetup returned %s\n", nt_errstr(status));
6534 static void chain2_tcon_completion(struct tevent_req *req)
6536 bool *done = (bool *)tevent_req_callback_data_void(req);
6538 status = cli_tcon_andx_recv(req);
6539 d_printf("tcon_and_x returned %s\n", nt_errstr(status));
6543 static bool run_chain2(int dummy)
6545 struct cli_state *cli1;
6546 struct event_context *evt = event_context_init(NULL);
6547 struct tevent_req *reqs[2], *smbreqs[2];
6551 printf("starting chain2 test\n");
6552 status = cli_start_connection(&cli1, lp_netbios_name(), host, NULL,
6553 port_to_use, Undefined, 0);
6554 if (!NT_STATUS_IS_OK(status)) {
6558 cli_sockopt(cli1, sockops);
6560 reqs[0] = cli_session_setup_guest_create(talloc_tos(), evt, cli1,
6562 if (reqs[0] == NULL) return false;
6563 tevent_req_set_callback(reqs[0], chain2_sesssetup_completion, NULL);
6565 reqs[1] = cli_tcon_andx_create(talloc_tos(), evt, cli1, "IPC$",
6566 "?????", NULL, 0, &smbreqs[1]);
6567 if (reqs[1] == NULL) return false;
6568 tevent_req_set_callback(reqs[1], chain2_tcon_completion, &done);
6570 status = cli_smb_chain_send(smbreqs, ARRAY_SIZE(smbreqs));
6571 if (!NT_STATUS_IS_OK(status)) {
6576 event_loop_once(evt);
6579 torture_close_connection(cli1);
6584 struct torture_createdel_state {
6585 struct tevent_context *ev;
6586 struct cli_state *cli;
6589 static void torture_createdel_created(struct tevent_req *subreq);
6590 static void torture_createdel_closed(struct tevent_req *subreq);
6592 static struct tevent_req *torture_createdel_send(TALLOC_CTX *mem_ctx,
6593 struct tevent_context *ev,
6594 struct cli_state *cli,
6597 struct tevent_req *req, *subreq;
6598 struct torture_createdel_state *state;
6600 req = tevent_req_create(mem_ctx, &state,
6601 struct torture_createdel_state);
6608 subreq = cli_ntcreate_send(
6609 state, ev, cli, name, 0,
6610 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
6611 FILE_ATTRIBUTE_NORMAL,
6612 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
6613 FILE_OPEN_IF, FILE_DELETE_ON_CLOSE, 0);
6615 if (tevent_req_nomem(subreq, req)) {
6616 return tevent_req_post(req, ev);
6618 tevent_req_set_callback(subreq, torture_createdel_created, req);
6622 static void torture_createdel_created(struct tevent_req *subreq)
6624 struct tevent_req *req = tevent_req_callback_data(
6625 subreq, struct tevent_req);
6626 struct torture_createdel_state *state = tevent_req_data(
6627 req, struct torture_createdel_state);
6631 status = cli_ntcreate_recv(subreq, &fnum);
6632 TALLOC_FREE(subreq);
6633 if (!NT_STATUS_IS_OK(status)) {
6634 DEBUG(10, ("cli_ntcreate_recv returned %s\n",
6635 nt_errstr(status)));
6636 tevent_req_nterror(req, status);
6640 subreq = cli_close_send(state, state->ev, state->cli, fnum);
6641 if (tevent_req_nomem(subreq, req)) {
6644 tevent_req_set_callback(subreq, torture_createdel_closed, req);
6647 static void torture_createdel_closed(struct tevent_req *subreq)
6649 struct tevent_req *req = tevent_req_callback_data(
6650 subreq, struct tevent_req);
6653 status = cli_close_recv(subreq);
6654 if (!NT_STATUS_IS_OK(status)) {
6655 DEBUG(10, ("cli_close_recv returned %s\n", nt_errstr(status)));
6656 tevent_req_nterror(req, status);
6659 tevent_req_done(req);
6662 static NTSTATUS torture_createdel_recv(struct tevent_req *req)
6664 return tevent_req_simple_recv_ntstatus(req);
6667 struct torture_createdels_state {
6668 struct tevent_context *ev;
6669 struct cli_state *cli;
6670 const char *base_name;
6674 struct tevent_req **reqs;
6677 static void torture_createdels_done(struct tevent_req *subreq);
6679 static struct tevent_req *torture_createdels_send(TALLOC_CTX *mem_ctx,
6680 struct tevent_context *ev,
6681 struct cli_state *cli,
6682 const char *base_name,
6686 struct tevent_req *req;
6687 struct torture_createdels_state *state;
6690 req = tevent_req_create(mem_ctx, &state,
6691 struct torture_createdels_state);
6697 state->base_name = talloc_strdup(state, base_name);
6698 if (tevent_req_nomem(state->base_name, req)) {
6699 return tevent_req_post(req, ev);
6701 state->num_files = MAX(num_parallel, num_files);
6703 state->received = 0;
6705 state->reqs = talloc_array(state, struct tevent_req *, num_parallel);
6706 if (tevent_req_nomem(state->reqs, req)) {
6707 return tevent_req_post(req, ev);
6710 for (i=0; i<num_parallel; i++) {
6713 name = talloc_asprintf(state, "%s%8.8d", state->base_name,
6715 if (tevent_req_nomem(name, req)) {
6716 return tevent_req_post(req, ev);
6718 state->reqs[i] = torture_createdel_send(
6719 state->reqs, state->ev, state->cli, name);
6720 if (tevent_req_nomem(state->reqs[i], req)) {
6721 return tevent_req_post(req, ev);
6723 name = talloc_move(state->reqs[i], &name);
6724 tevent_req_set_callback(state->reqs[i],
6725 torture_createdels_done, req);
6731 static void torture_createdels_done(struct tevent_req *subreq)
6733 struct tevent_req *req = tevent_req_callback_data(
6734 subreq, struct tevent_req);
6735 struct torture_createdels_state *state = tevent_req_data(
6736 req, struct torture_createdels_state);
6737 size_t num_parallel = talloc_array_length(state->reqs);
6742 status = torture_createdel_recv(subreq);
6743 if (!NT_STATUS_IS_OK(status)){
6744 DEBUG(10, ("torture_createdel_recv returned %s\n",
6745 nt_errstr(status)));
6746 TALLOC_FREE(subreq);
6747 tevent_req_nterror(req, status);
6751 for (i=0; i<num_parallel; i++) {
6752 if (subreq == state->reqs[i]) {
6756 if (i == num_parallel) {
6757 DEBUG(10, ("received something we did not send\n"));
6758 tevent_req_nterror(req, NT_STATUS_INTERNAL_ERROR);
6761 TALLOC_FREE(state->reqs[i]);
6763 if (state->sent >= state->num_files) {
6764 tevent_req_done(req);
6768 name = talloc_asprintf(state, "%s%8.8d", state->base_name,
6770 if (tevent_req_nomem(name, req)) {
6773 state->reqs[i] = torture_createdel_send(state->reqs, state->ev,
6775 if (tevent_req_nomem(state->reqs[i], req)) {
6778 name = talloc_move(state->reqs[i], &name);
6779 tevent_req_set_callback(state->reqs[i], torture_createdels_done, req);
6783 static NTSTATUS torture_createdels_recv(struct tevent_req *req)
6785 return tevent_req_simple_recv_ntstatus(req);
6788 struct swallow_notify_state {
6789 struct tevent_context *ev;
6790 struct cli_state *cli;
6792 uint32_t completion_filter;
6794 bool (*fn)(uint32_t action, const char *name, void *priv);
6798 static void swallow_notify_done(struct tevent_req *subreq);
6800 static struct tevent_req *swallow_notify_send(TALLOC_CTX *mem_ctx,
6801 struct tevent_context *ev,
6802 struct cli_state *cli,
6804 uint32_t completion_filter,
6806 bool (*fn)(uint32_t action,
6811 struct tevent_req *req, *subreq;
6812 struct swallow_notify_state *state;
6814 req = tevent_req_create(mem_ctx, &state,
6815 struct swallow_notify_state);
6822 state->completion_filter = completion_filter;
6823 state->recursive = recursive;
6827 subreq = cli_notify_send(state, state->ev, state->cli, state->fnum,
6828 0xffff, state->completion_filter,
6830 if (tevent_req_nomem(subreq, req)) {
6831 return tevent_req_post(req, ev);
6833 tevent_req_set_callback(subreq, swallow_notify_done, req);
6837 static void swallow_notify_done(struct tevent_req *subreq)
6839 struct tevent_req *req = tevent_req_callback_data(
6840 subreq, struct tevent_req);
6841 struct swallow_notify_state *state = tevent_req_data(
6842 req, struct swallow_notify_state);
6844 uint32_t i, num_changes;
6845 struct notify_change *changes;
6847 status = cli_notify_recv(subreq, state, &num_changes, &changes);
6848 TALLOC_FREE(subreq);
6849 if (!NT_STATUS_IS_OK(status)) {
6850 DEBUG(10, ("cli_notify_recv returned %s\n",
6851 nt_errstr(status)));
6852 tevent_req_nterror(req, status);
6856 for (i=0; i<num_changes; i++) {
6857 state->fn(changes[i].action, changes[i].name, state->priv);
6859 TALLOC_FREE(changes);
6861 subreq = cli_notify_send(state, state->ev, state->cli, state->fnum,
6862 0xffff, state->completion_filter,
6864 if (tevent_req_nomem(subreq, req)) {
6867 tevent_req_set_callback(subreq, swallow_notify_done, req);
6870 static bool print_notifies(uint32_t action, const char *name, void *priv)
6872 if (DEBUGLEVEL > 5) {
6873 d_printf("%d %s\n", (int)action, name);
6878 static void notify_bench_done(struct tevent_req *req)
6880 int *num_finished = (int *)tevent_req_callback_data_void(req);
6884 static bool run_notify_bench(int dummy)
6886 const char *dname = "\\notify-bench";
6887 struct tevent_context *ev;
6890 struct tevent_req *req1;
6891 struct tevent_req *req2 = NULL;
6892 int i, num_unc_names;
6893 int num_finished = 0;
6895 printf("starting notify-bench test\n");
6897 if (use_multishare_conn) {
6899 unc_list = file_lines_load(multishare_conn_fname,
6900 &num_unc_names, 0, NULL);
6901 if (!unc_list || num_unc_names <= 0) {
6902 d_printf("Failed to load unc names list from '%s'\n",
6903 multishare_conn_fname);
6906 TALLOC_FREE(unc_list);
6911 ev = tevent_context_init(talloc_tos());
6913 d_printf("tevent_context_init failed\n");
6917 for (i=0; i<num_unc_names; i++) {
6918 struct cli_state *cli;
6921 base_fname = talloc_asprintf(talloc_tos(), "%s\\file%3.3d.",
6923 if (base_fname == NULL) {
6927 if (!torture_open_connection(&cli, i)) {
6931 status = cli_ntcreate(cli, dname, 0,
6932 MAXIMUM_ALLOWED_ACCESS,
6933 0, FILE_SHARE_READ|FILE_SHARE_WRITE|
6935 FILE_OPEN_IF, FILE_DIRECTORY_FILE, 0,
6938 if (!NT_STATUS_IS_OK(status)) {
6939 d_printf("Could not create %s: %s\n", dname,
6944 req1 = swallow_notify_send(talloc_tos(), ev, cli, dnum,
6945 FILE_NOTIFY_CHANGE_FILE_NAME |
6946 FILE_NOTIFY_CHANGE_DIR_NAME |
6947 FILE_NOTIFY_CHANGE_ATTRIBUTES |
6948 FILE_NOTIFY_CHANGE_LAST_WRITE,
6949 false, print_notifies, NULL);
6951 d_printf("Could not create notify request\n");
6955 req2 = torture_createdels_send(talloc_tos(), ev, cli,
6956 base_fname, 10, torture_numops);
6958 d_printf("Could not create createdels request\n");
6961 TALLOC_FREE(base_fname);
6963 tevent_req_set_callback(req2, notify_bench_done,
6967 while (num_finished < num_unc_names) {
6969 ret = tevent_loop_once(ev);
6971 d_printf("tevent_loop_once failed\n");
6976 if (!tevent_req_poll(req2, ev)) {
6977 d_printf("tevent_req_poll failed\n");
6980 status = torture_createdels_recv(req2);
6981 d_printf("torture_createdels_recv returned %s\n", nt_errstr(status));
6986 static bool run_mangle1(int dummy)
6988 struct cli_state *cli;
6989 const char *fname = "this_is_a_long_fname_to_be_mangled.txt";
6993 time_t change_time, access_time, write_time;
6997 printf("starting mangle1 test\n");
6998 if (!torture_open_connection(&cli, 0)) {
7002 cli_sockopt(cli, sockops);
7004 status = cli_ntcreate(cli, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
7005 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
7007 if (!NT_STATUS_IS_OK(status)) {
7008 d_printf("open %s failed: %s\n", fname, nt_errstr(status));
7011 cli_close(cli, fnum);
7013 status = cli_qpathinfo_alt_name(cli, fname, alt_name);
7014 if (!NT_STATUS_IS_OK(status)) {
7015 d_printf("cli_qpathinfo_alt_name failed: %s\n",
7019 d_printf("alt_name: %s\n", alt_name);
7021 status = cli_open(cli, alt_name, O_RDONLY, DENY_NONE, &fnum);
7022 if (!NT_STATUS_IS_OK(status)) {
7023 d_printf("cli_open(%s) failed: %s\n", alt_name,
7027 cli_close(cli, fnum);
7029 status = cli_qpathinfo1(cli, alt_name, &change_time, &access_time,
7030 &write_time, &size, &mode);
7031 if (!NT_STATUS_IS_OK(status)) {
7032 d_printf("cli_qpathinfo1(%s) failed: %s\n", alt_name,
7040 static size_t null_source(uint8_t *buf, size_t n, void *priv)
7042 size_t *to_pull = (size_t *)priv;
7043 size_t thistime = *to_pull;
7045 thistime = MIN(thistime, n);
7046 if (thistime == 0) {
7050 memset(buf, 0, thistime);
7051 *to_pull -= thistime;
7055 static bool run_windows_write(int dummy)
7057 struct cli_state *cli1;
7061 const char *fname = "\\writetest.txt";
7062 struct timeval start_time;
7067 printf("starting windows_write test\n");
7068 if (!torture_open_connection(&cli1, 0)) {
7072 status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
7073 if (!NT_STATUS_IS_OK(status)) {
7074 printf("open failed (%s)\n", nt_errstr(status));
7078 cli_sockopt(cli1, sockops);
7080 start_time = timeval_current();
7082 for (i=0; i<torture_numops; i++) {
7084 off_t start = i * torture_blocksize;
7085 size_t to_pull = torture_blocksize - 1;
7087 status = cli_writeall(cli1, fnum, 0, &c,
7088 start + torture_blocksize - 1, 1, NULL);
7089 if (!NT_STATUS_IS_OK(status)) {
7090 printf("cli_write failed: %s\n", nt_errstr(status));
7094 status = cli_push(cli1, fnum, 0, i * torture_blocksize, torture_blocksize,
7095 null_source, &to_pull);
7096 if (!NT_STATUS_IS_OK(status)) {
7097 printf("cli_push returned: %s\n", nt_errstr(status));
7102 seconds = timeval_elapsed(&start_time);
7103 kbytes = (double)torture_blocksize * torture_numops;
7106 printf("Wrote %d kbytes in %.2f seconds: %d kb/sec\n", (int)kbytes,
7107 (double)seconds, (int)(kbytes/seconds));
7111 cli_close(cli1, fnum);
7112 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7113 torture_close_connection(cli1);
7117 static bool run_cli_echo(int dummy)
7119 struct cli_state *cli;
7122 printf("starting cli_echo test\n");
7123 if (!torture_open_connection(&cli, 0)) {
7126 cli_sockopt(cli, sockops);
7128 status = cli_echo(cli, 5, data_blob_const("hello", 5));
7130 d_printf("cli_echo returned %s\n", nt_errstr(status));
7132 torture_close_connection(cli);
7133 return NT_STATUS_IS_OK(status);
7136 static bool run_uid_regression_test(int dummy)
7138 static struct cli_state *cli;
7141 bool correct = True;
7144 printf("starting uid regression test\n");
7146 if (!torture_open_connection(&cli, 0)) {
7150 cli_sockopt(cli, sockops);
7152 /* Ok - now save then logoff our current user. */
7153 old_vuid = cli_state_get_uid(cli);
7155 status = cli_ulogoff(cli);
7156 if (!NT_STATUS_IS_OK(status)) {
7157 d_printf("(%s) cli_ulogoff failed: %s\n",
7158 __location__, nt_errstr(status));
7163 cli_state_set_uid(cli, old_vuid);
7165 /* Try an operation. */
7166 status = cli_mkdir(cli, "\\uid_reg_test");
7167 if (NT_STATUS_IS_OK(status)) {
7168 d_printf("(%s) cli_mkdir succeeded\n",
7173 /* Should be bad uid. */
7174 if (!check_error(__LINE__, status, ERRSRV, ERRbaduid,
7175 NT_STATUS_USER_SESSION_DELETED)) {
7181 old_cnum = cli_state_get_tid(cli);
7183 /* Now try a SMBtdis with the invald vuid set to zero. */
7184 cli_state_set_uid(cli, 0);
7186 /* This should succeed. */
7187 status = cli_tdis(cli);
7189 if (NT_STATUS_IS_OK(status)) {
7190 d_printf("First tdis with invalid vuid should succeed.\n");
7192 d_printf("First tdis failed (%s)\n", nt_errstr(status));
7197 cli_state_set_uid(cli, old_vuid);
7198 cli_state_set_tid(cli, old_cnum);
7200 /* This should fail. */
7201 status = cli_tdis(cli);
7202 if (NT_STATUS_IS_OK(status)) {
7203 d_printf("Second tdis with invalid vuid should fail - succeeded instead !.\n");
7207 /* Should be bad tid. */
7208 if (!check_error(__LINE__, status, ERRSRV, ERRinvnid,
7209 NT_STATUS_NETWORK_NAME_DELETED)) {
7215 cli_rmdir(cli, "\\uid_reg_test");
7224 static const char *illegal_chars = "*\\/?<>|\":";
7225 static char force_shortname_chars[] = " +,.[];=\177";
7227 static NTSTATUS shortname_del_fn(const char *mnt, struct file_info *finfo,
7228 const char *mask, void *state)
7230 struct cli_state *pcli = (struct cli_state *)state;
7232 NTSTATUS status = NT_STATUS_OK;
7234 slprintf(fname, sizeof(fname), "\\shortname\\%s", finfo->name);
7236 if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
7237 return NT_STATUS_OK;
7239 if (finfo->mode & FILE_ATTRIBUTE_DIRECTORY) {
7240 status = cli_rmdir(pcli, fname);
7241 if (!NT_STATUS_IS_OK(status)) {
7242 printf("del_fn: failed to rmdir %s\n,", fname );
7245 status = cli_unlink(pcli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7246 if (!NT_STATUS_IS_OK(status)) {
7247 printf("del_fn: failed to unlink %s\n,", fname );
7259 static NTSTATUS shortname_list_fn(const char *mnt, struct file_info *finfo,
7260 const char *name, void *state)
7262 struct sn_state *s = (struct sn_state *)state;
7266 printf("shortname list: i = %d, name = |%s|, shortname = |%s|\n",
7267 i, finfo->name, finfo->short_name);
7270 if (strchr(force_shortname_chars, i)) {
7271 if (!finfo->short_name) {
7272 /* Shortname not created when it should be. */
7273 d_printf("(%s) ERROR: Shortname was not created for file %s containing %d\n",
7274 __location__, finfo->name, i);
7277 } else if (finfo->short_name){
7278 /* Shortname created when it should not be. */
7279 d_printf("(%s) ERROR: Shortname %s was created for file %s\n",
7280 __location__, finfo->short_name, finfo->name);
7284 return NT_STATUS_OK;
7287 static bool run_shortname_test(int dummy)
7289 static struct cli_state *cli;
7290 bool correct = True;
7296 printf("starting shortname test\n");
7298 if (!torture_open_connection(&cli, 0)) {
7302 cli_sockopt(cli, sockops);
7304 cli_list(cli, "\\shortname\\*", 0, shortname_del_fn, cli);
7305 cli_list(cli, "\\shortname\\*", FILE_ATTRIBUTE_DIRECTORY, shortname_del_fn, cli);
7306 cli_rmdir(cli, "\\shortname");
7308 status = cli_mkdir(cli, "\\shortname");
7309 if (!NT_STATUS_IS_OK(status)) {
7310 d_printf("(%s) cli_mkdir of \\shortname failed: %s\n",
7311 __location__, nt_errstr(status));
7316 strlcpy(fname, "\\shortname\\", sizeof(fname));
7317 strlcat(fname, "test .txt", sizeof(fname));
7321 for (i = 32; i < 128; i++) {
7322 uint16_t fnum = (uint16_t)-1;
7326 if (strchr(illegal_chars, i)) {
7331 status = cli_ntcreate(cli, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
7332 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum);
7333 if (!NT_STATUS_IS_OK(status)) {
7334 d_printf("(%s) cli_nt_create of %s failed: %s\n",
7335 __location__, fname, nt_errstr(status));
7339 cli_close(cli, fnum);
7342 status = cli_list(cli, "\\shortname\\test*.*", 0,
7343 shortname_list_fn, &s);
7344 if (s.matched != 1) {
7345 d_printf("(%s) failed to list %s: %s\n",
7346 __location__, fname, nt_errstr(status));
7351 status = cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7352 if (!NT_STATUS_IS_OK(status)) {
7353 d_printf("(%s) failed to delete %s: %s\n",
7354 __location__, fname, nt_errstr(status));
7367 cli_list(cli, "\\shortname\\*", 0, shortname_del_fn, cli);
7368 cli_list(cli, "\\shortname\\*", FILE_ATTRIBUTE_DIRECTORY, shortname_del_fn, cli);
7369 cli_rmdir(cli, "\\shortname");
7370 torture_close_connection(cli);
7374 static void pagedsearch_cb(struct tevent_req *req)
7377 struct tldap_message *msg;
7380 rc = tldap_search_paged_recv(req, talloc_tos(), &msg);
7381 if (rc != TLDAP_SUCCESS) {
7382 d_printf("tldap_search_paged_recv failed: %s\n",
7383 tldap_err2string(rc));
7386 if (tldap_msg_type(msg) != TLDAP_RES_SEARCH_ENTRY) {
7390 if (!tldap_entry_dn(msg, &dn)) {
7391 d_printf("tldap_entry_dn failed\n");
7394 d_printf("%s\n", dn);
7398 static bool run_tldap(int dummy)
7400 struct tldap_context *ld;
7403 struct sockaddr_storage addr;
7404 struct tevent_context *ev;
7405 struct tevent_req *req;
7409 if (!resolve_name(host, &addr, 0, false)) {
7410 d_printf("could not find host %s\n", host);
7413 status = open_socket_out(&addr, 389, 9999, &fd);
7414 if (!NT_STATUS_IS_OK(status)) {
7415 d_printf("open_socket_out failed: %s\n", nt_errstr(status));
7419 ld = tldap_context_create(talloc_tos(), fd);
7422 d_printf("tldap_context_create failed\n");
7426 rc = tldap_fetch_rootdse(ld);
7427 if (rc != TLDAP_SUCCESS) {
7428 d_printf("tldap_fetch_rootdse failed: %s\n",
7429 tldap_errstr(talloc_tos(), ld, rc));
7433 basedn = tldap_talloc_single_attribute(
7434 tldap_rootdse(ld), "defaultNamingContext", talloc_tos());
7435 if (basedn == NULL) {
7436 d_printf("no defaultNamingContext\n");
7439 d_printf("defaultNamingContext: %s\n", basedn);
7441 ev = tevent_context_init(talloc_tos());
7443 d_printf("tevent_context_init failed\n");
7447 req = tldap_search_paged_send(talloc_tos(), ev, ld, basedn,
7448 TLDAP_SCOPE_SUB, "(objectclass=*)",
7450 NULL, 0, NULL, 0, 0, 0, 0, 5);
7452 d_printf("tldap_search_paged_send failed\n");
7455 tevent_req_set_callback(req, pagedsearch_cb, NULL);
7457 tevent_req_poll(req, ev);
7461 /* test search filters against rootDSE */
7462 filter = "(&(|(name=samba)(nextRid<=10000000)(usnChanged>=10)(samba~=ambas)(!(name=s*m*a)))"
7463 "(|(name:=samba)(name:dn:2.5.13.5:=samba)(:dn:2.5.13.5:=samba)(!(name=*samba))))";
7465 rc = tldap_search(ld, "", TLDAP_SCOPE_BASE, filter,
7466 NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0,
7467 talloc_tos(), NULL, NULL);
7468 if (rc != TLDAP_SUCCESS) {
7469 d_printf("tldap_search with complex filter failed: %s\n",
7470 tldap_errstr(talloc_tos(), ld, rc));
7478 /* Torture test to ensure no regression of :
7479 https://bugzilla.samba.org/show_bug.cgi?id=7084
7482 static bool run_dir_createtime(int dummy)
7484 struct cli_state *cli;
7485 const char *dname = "\\testdir";
7486 const char *fname = "\\testdir\\testfile";
7488 struct timespec create_time;
7489 struct timespec create_time1;
7493 if (!torture_open_connection(&cli, 0)) {
7497 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7498 cli_rmdir(cli, dname);
7500 status = cli_mkdir(cli, dname);
7501 if (!NT_STATUS_IS_OK(status)) {
7502 printf("mkdir failed: %s\n", nt_errstr(status));
7506 status = cli_qpathinfo2(cli, dname, &create_time, NULL, NULL, NULL,
7508 if (!NT_STATUS_IS_OK(status)) {
7509 printf("cli_qpathinfo2 returned %s\n",
7514 /* Sleep 3 seconds, then create a file. */
7517 status = cli_open(cli, fname, O_RDWR | O_CREAT | O_EXCL,
7519 if (!NT_STATUS_IS_OK(status)) {
7520 printf("cli_open failed: %s\n", nt_errstr(status));
7524 status = cli_qpathinfo2(cli, dname, &create_time1, NULL, NULL, NULL,
7526 if (!NT_STATUS_IS_OK(status)) {
7527 printf("cli_qpathinfo2 (2) returned %s\n",
7532 if (timespec_compare(&create_time1, &create_time)) {
7533 printf("run_dir_createtime: create time was updated (error)\n");
7535 printf("run_dir_createtime: create time was not updated (correct)\n");
7541 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7542 cli_rmdir(cli, dname);
7543 if (!torture_close_connection(cli)) {
7550 static bool run_streamerror(int dummy)
7552 struct cli_state *cli;
7553 const char *dname = "\\testdir";
7554 const char *streamname =
7555 "testdir:{4c8cc155-6c1e-11d1-8e41-00c04fb9386d}:$DATA";
7557 time_t change_time, access_time, write_time;
7559 uint16_t mode, fnum;
7562 if (!torture_open_connection(&cli, 0)) {
7566 cli_unlink(cli, "\\testdir\\*", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7567 cli_rmdir(cli, dname);
7569 status = cli_mkdir(cli, dname);
7570 if (!NT_STATUS_IS_OK(status)) {
7571 printf("mkdir failed: %s\n", nt_errstr(status));
7575 cli_qpathinfo1(cli, streamname, &change_time, &access_time, &write_time,
7577 status = cli_nt_error(cli);
7579 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
7580 printf("pathinfo returned %s, expected "
7581 "NT_STATUS_OBJECT_NAME_NOT_FOUND\n",
7586 status = cli_ntcreate(cli, streamname, 0x16,
7587 FILE_READ_DATA|FILE_READ_EA|
7588 FILE_READ_ATTRIBUTES|READ_CONTROL_ACCESS,
7589 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ,
7590 FILE_OPEN, 0, 0, &fnum);
7592 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
7593 printf("ntcreate returned %s, expected "
7594 "NT_STATUS_OBJECT_NAME_NOT_FOUND\n",
7600 cli_rmdir(cli, dname);
7604 static bool run_local_substitute(int dummy)
7608 ok &= subst_test("%U", "bla", "", -1, -1, "bla");
7609 ok &= subst_test("%u%U", "bla", "", -1, -1, "blabla");
7610 ok &= subst_test("%g", "", "", -1, -1, "NO_GROUP");
7611 ok &= subst_test("%G", "", "", -1, -1, "NO_GROUP");
7612 ok &= subst_test("%g", "", "", -1, 0, gidtoname(0));
7613 ok &= subst_test("%G", "", "", -1, 0, gidtoname(0));
7614 ok &= subst_test("%D%u", "u", "dom", -1, 0, "domu");
7615 ok &= subst_test("%i %I", "", "", -1, -1, "0.0.0.0 0.0.0.0");
7617 /* Different captialization rules in sub_basic... */
7619 ok &= (strcmp(talloc_sub_basic(talloc_tos(), "BLA", "dom", "%U%D"),
7625 static bool run_local_base64(int dummy)
7630 for (i=1; i<2000; i++) {
7631 DATA_BLOB blob1, blob2;
7634 blob1.data = talloc_array(talloc_tos(), uint8_t, i);
7636 generate_random_buffer(blob1.data, blob1.length);
7638 b64 = base64_encode_data_blob(talloc_tos(), blob1);
7640 d_fprintf(stderr, "base64_encode_data_blob failed "
7641 "for %d bytes\n", i);
7644 blob2 = base64_decode_data_blob(b64);
7647 if (data_blob_cmp(&blob1, &blob2)) {
7648 d_fprintf(stderr, "data_blob_cmp failed for %d "
7652 TALLOC_FREE(blob1.data);
7653 data_blob_free(&blob2);
7658 static bool run_local_gencache(int dummy)
7664 if (!gencache_set("foo", "bar", time(NULL) + 1000)) {
7665 d_printf("%s: gencache_set() failed\n", __location__);
7669 if (!gencache_get("foo", NULL, NULL)) {
7670 d_printf("%s: gencache_get() failed\n", __location__);
7674 if (!gencache_get("foo", &val, &tm)) {
7675 d_printf("%s: gencache_get() failed\n", __location__);
7679 if (strcmp(val, "bar") != 0) {
7680 d_printf("%s: gencache_get() returned %s, expected %s\n",
7681 __location__, val, "bar");
7688 if (!gencache_del("foo")) {
7689 d_printf("%s: gencache_del() failed\n", __location__);
7692 if (gencache_del("foo")) {
7693 d_printf("%s: second gencache_del() succeeded\n",
7698 if (gencache_get("foo", &val, &tm)) {
7699 d_printf("%s: gencache_get() on deleted entry "
7700 "succeeded\n", __location__);
7704 blob = data_blob_string_const_null("bar");
7705 tm = time(NULL) + 60;
7707 if (!gencache_set_data_blob("foo", &blob, tm)) {
7708 d_printf("%s: gencache_set_data_blob() failed\n", __location__);
7712 if (!gencache_get_data_blob("foo", &blob, NULL, NULL)) {
7713 d_printf("%s: gencache_get_data_blob() failed\n", __location__);
7717 if (strcmp((const char *)blob.data, "bar") != 0) {
7718 d_printf("%s: gencache_get_data_blob() returned %s, expected %s\n",
7719 __location__, (const char *)blob.data, "bar");
7720 data_blob_free(&blob);
7724 data_blob_free(&blob);
7726 if (!gencache_del("foo")) {
7727 d_printf("%s: gencache_del() failed\n", __location__);
7730 if (gencache_del("foo")) {
7731 d_printf("%s: second gencache_del() succeeded\n",
7736 if (gencache_get_data_blob("foo", &blob, NULL, NULL)) {
7737 d_printf("%s: gencache_get_data_blob() on deleted entry "
7738 "succeeded\n", __location__);
7745 static bool rbt_testval(struct db_context *db, const char *key,
7748 struct db_record *rec;
7749 TDB_DATA data = string_tdb_data(value);
7753 rec = db->fetch_locked(db, db, string_tdb_data(key));
7755 d_fprintf(stderr, "fetch_locked failed\n");
7758 status = rec->store(rec, data, 0);
7759 if (!NT_STATUS_IS_OK(status)) {
7760 d_fprintf(stderr, "store failed: %s\n", nt_errstr(status));
7765 rec = db->fetch_locked(db, db, string_tdb_data(key));
7767 d_fprintf(stderr, "second fetch_locked failed\n");
7770 if ((rec->value.dsize != data.dsize)
7771 || (memcmp(rec->value.dptr, data.dptr, data.dsize) != 0)) {
7772 d_fprintf(stderr, "Got wrong data back\n");
7782 static bool run_local_rbtree(int dummy)
7784 struct db_context *db;
7788 db = db_open_rbt(NULL);
7791 d_fprintf(stderr, "db_open_rbt failed\n");
7795 for (i=0; i<1000; i++) {
7798 if (asprintf(&key, "key%ld", random()) == -1) {
7801 if (asprintf(&value, "value%ld", random()) == -1) {
7806 if (!rbt_testval(db, key, value)) {
7813 if (asprintf(&value, "value%ld", random()) == -1) {
7818 if (!rbt_testval(db, key, value)) {
7837 local test for character set functions
7839 This is a very simple test for the functionality in convert_string_error()
7841 static bool run_local_convert_string(int dummy)
7843 TALLOC_CTX *tmp_ctx = talloc_new(NULL);
7844 const char *test_strings[2] = { "March", "M\303\244rz" };
7848 for (i=0; i<2; i++) {
7849 const char *str = test_strings[i];
7850 int len = strlen(str);
7851 size_t converted_size;
7854 memset(dst, 'X', sizeof(dst));
7856 /* first try with real source length */
7857 ret = convert_string_error(CH_UNIX, CH_UTF8,
7862 d_fprintf(stderr, "Failed to convert '%s' to CH_DISPLAY\n", str);
7866 if (converted_size != len) {
7867 d_fprintf(stderr, "Converted size of '%s' should be %d - got %d\n",
7868 str, len, (int)converted_size);
7872 if (strncmp(str, dst, converted_size) != 0) {
7873 d_fprintf(stderr, "Expected '%s' to match '%s'\n", str, dst);
7877 if (strlen(str) != converted_size) {
7878 d_fprintf(stderr, "Expected '%s' length %d - got %d\n", str,
7879 (int)strlen(str), (int)converted_size);
7883 if (dst[converted_size] != 'X') {
7884 d_fprintf(stderr, "Expected no termination of '%s'\n", dst);
7888 /* now with srclen==-1, this causes the nul to be
7890 ret = convert_string_error(CH_UNIX, CH_UTF8,
7895 d_fprintf(stderr, "Failed to convert '%s' to CH_DISPLAY\n", str);
7899 if (converted_size != len+1) {
7900 d_fprintf(stderr, "Converted size of '%s' should be %d - got %d\n",
7901 str, len, (int)converted_size);
7905 if (strncmp(str, dst, converted_size) != 0) {
7906 d_fprintf(stderr, "Expected '%s' to match '%s'\n", str, dst);
7910 if (len+1 != converted_size) {
7911 d_fprintf(stderr, "Expected '%s' length %d - got %d\n", str,
7912 len+1, (int)converted_size);
7916 if (dst[converted_size] != 'X') {
7917 d_fprintf(stderr, "Expected no termination of '%s'\n", dst);
7924 TALLOC_FREE(tmp_ctx);
7927 TALLOC_FREE(tmp_ctx);
7932 struct talloc_dict_test {
7936 static int talloc_dict_traverse_fn(DATA_BLOB key, void *data, void *priv)
7938 int *count = (int *)priv;
7943 static bool run_local_talloc_dict(int dummy)
7945 struct talloc_dict *dict;
7946 struct talloc_dict_test *t;
7949 dict = talloc_dict_init(talloc_tos());
7954 t = talloc(talloc_tos(), struct talloc_dict_test);
7961 if (!talloc_dict_set(dict, data_blob_const(&key, sizeof(key)), t)) {
7966 if (talloc_dict_traverse(dict, talloc_dict_traverse_fn, &count) != 0) {
7979 static bool run_local_string_to_sid(int dummy) {
7982 if (string_to_sid(&sid, "S--1-5-32-545")) {
7983 printf("allowing S--1-5-32-545\n");
7986 if (string_to_sid(&sid, "S-1-5-32-+545")) {
7987 printf("allowing S-1-5-32-+545\n");
7990 if (string_to_sid(&sid, "S-1-2-3-4-5-6-7-8-9-0-1-2-3-4-5-6-7-8-9-0")) {
7991 printf("allowing S-1-2-3-4-5-6-7-8-9-0-1-2-3-4-5-6-7-8-9-0\n");
7994 if (string_to_sid(&sid, "S-1-5-32-545-abc")) {
7995 printf("allowing S-1-5-32-545-abc\n");
7998 if (!string_to_sid(&sid, "S-1-5-32-545")) {
7999 printf("could not parse S-1-5-32-545\n");
8002 if (!dom_sid_equal(&sid, &global_sid_Builtin_Users)) {
8003 printf("mis-parsed S-1-5-32-545 as %s\n",
8004 sid_string_tos(&sid));
8010 static bool run_local_binary_to_sid(int dummy) {
8011 struct dom_sid *sid = talloc(NULL, struct dom_sid);
8012 static const char good_binary_sid[] = {
8013 0x1, /* revision number */
8015 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, /* id_auth */
8016 0x1, 0x1, 0x1, 0x1, /* auth[0] */
8017 0x1, 0x1, 0x1, 0x1, /* auth[1] */
8018 0x1, 0x1, 0x1, 0x1, /* auth[2] */
8019 0x1, 0x1, 0x1, 0x1, /* auth[3] */
8020 0x1, 0x1, 0x1, 0x1, /* auth[4] */
8021 0x1, 0x1, 0x1, 0x1, /* auth[5] */
8022 0x1, 0x1, 0x1, 0x1, /* auth[6] */
8023 0x1, 0x1, 0x1, 0x1, /* auth[7] */
8024 0x1, 0x1, 0x1, 0x1, /* auth[8] */
8025 0x1, 0x1, 0x1, 0x1, /* auth[9] */
8026 0x1, 0x1, 0x1, 0x1, /* auth[10] */
8027 0x1, 0x1, 0x1, 0x1, /* auth[11] */
8028 0x1, 0x1, 0x1, 0x1, /* auth[12] */
8029 0x1, 0x1, 0x1, 0x1, /* auth[13] */
8030 0x1, 0x1, 0x1, 0x1, /* auth[14] */
8033 static const char long_binary_sid[] = {
8034 0x1, /* revision number */
8036 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, /* id_auth */
8037 0x1, 0x1, 0x1, 0x1, /* auth[0] */
8038 0x1, 0x1, 0x1, 0x1, /* auth[1] */
8039 0x1, 0x1, 0x1, 0x1, /* auth[2] */
8040 0x1, 0x1, 0x1, 0x1, /* auth[3] */
8041 0x1, 0x1, 0x1, 0x1, /* auth[4] */
8042 0x1, 0x1, 0x1, 0x1, /* auth[5] */
8043 0x1, 0x1, 0x1, 0x1, /* auth[6] */
8044 0x1, 0x1, 0x1, 0x1, /* auth[7] */
8045 0x1, 0x1, 0x1, 0x1, /* auth[8] */
8046 0x1, 0x1, 0x1, 0x1, /* auth[9] */
8047 0x1, 0x1, 0x1, 0x1, /* auth[10] */
8048 0x1, 0x1, 0x1, 0x1, /* auth[11] */
8049 0x1, 0x1, 0x1, 0x1, /* auth[12] */
8050 0x1, 0x1, 0x1, 0x1, /* auth[13] */
8051 0x1, 0x1, 0x1, 0x1, /* auth[14] */
8052 0x1, 0x1, 0x1, 0x1, /* auth[15] */
8053 0x1, 0x1, 0x1, 0x1, /* auth[16] */
8054 0x1, 0x1, 0x1, 0x1, /* auth[17] */
8057 static const char long_binary_sid2[] = {
8058 0x1, /* revision number */
8060 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, /* id_auth */
8061 0x1, 0x1, 0x1, 0x1, /* auth[0] */
8062 0x1, 0x1, 0x1, 0x1, /* auth[1] */
8063 0x1, 0x1, 0x1, 0x1, /* auth[2] */
8064 0x1, 0x1, 0x1, 0x1, /* auth[3] */
8065 0x1, 0x1, 0x1, 0x1, /* auth[4] */
8066 0x1, 0x1, 0x1, 0x1, /* auth[5] */
8067 0x1, 0x1, 0x1, 0x1, /* auth[6] */
8068 0x1, 0x1, 0x1, 0x1, /* auth[7] */
8069 0x1, 0x1, 0x1, 0x1, /* auth[8] */
8070 0x1, 0x1, 0x1, 0x1, /* auth[9] */
8071 0x1, 0x1, 0x1, 0x1, /* auth[10] */
8072 0x1, 0x1, 0x1, 0x1, /* auth[11] */
8073 0x1, 0x1, 0x1, 0x1, /* auth[12] */
8074 0x1, 0x1, 0x1, 0x1, /* auth[13] */
8075 0x1, 0x1, 0x1, 0x1, /* auth[14] */
8076 0x1, 0x1, 0x1, 0x1, /* auth[15] */
8077 0x1, 0x1, 0x1, 0x1, /* auth[16] */
8078 0x1, 0x1, 0x1, 0x1, /* auth[17] */
8079 0x1, 0x1, 0x1, 0x1, /* auth[18] */
8080 0x1, 0x1, 0x1, 0x1, /* auth[19] */
8081 0x1, 0x1, 0x1, 0x1, /* auth[20] */
8082 0x1, 0x1, 0x1, 0x1, /* auth[21] */
8083 0x1, 0x1, 0x1, 0x1, /* auth[22] */
8084 0x1, 0x1, 0x1, 0x1, /* auth[23] */
8085 0x1, 0x1, 0x1, 0x1, /* auth[24] */
8086 0x1, 0x1, 0x1, 0x1, /* auth[25] */
8087 0x1, 0x1, 0x1, 0x1, /* auth[26] */
8088 0x1, 0x1, 0x1, 0x1, /* auth[27] */
8089 0x1, 0x1, 0x1, 0x1, /* auth[28] */
8090 0x1, 0x1, 0x1, 0x1, /* auth[29] */
8091 0x1, 0x1, 0x1, 0x1, /* auth[30] */
8092 0x1, 0x1, 0x1, 0x1, /* auth[31] */
8095 if (!sid_parse(good_binary_sid, sizeof(good_binary_sid), sid)) {
8098 if (sid_parse(long_binary_sid2, sizeof(long_binary_sid2), sid)) {
8101 if (sid_parse(long_binary_sid, sizeof(long_binary_sid), sid)) {
8107 /* Split a path name into filename and stream name components. Canonicalise
8108 * such that an implicit $DATA token is always explicit.
8110 * The "specification" of this function can be found in the
8111 * run_local_stream_name() function in torture.c, I've tried those
8112 * combinations against a W2k3 server.
8115 static NTSTATUS split_ntfs_stream_name(TALLOC_CTX *mem_ctx, const char *fname,
8116 char **pbase, char **pstream)
8119 char *stream = NULL;
8120 char *sname; /* stream name */
8121 const char *stype; /* stream type */
8123 DEBUG(10, ("split_ntfs_stream_name called for [%s]\n", fname));
8125 sname = strchr_m(fname, ':');
8127 if (lp_posix_pathnames() || (sname == NULL)) {
8128 if (pbase != NULL) {
8129 base = talloc_strdup(mem_ctx, fname);
8130 NT_STATUS_HAVE_NO_MEMORY(base);
8135 if (pbase != NULL) {
8136 base = talloc_strndup(mem_ctx, fname, PTR_DIFF(sname, fname));
8137 NT_STATUS_HAVE_NO_MEMORY(base);
8142 stype = strchr_m(sname, ':');
8144 if (stype == NULL) {
8145 sname = talloc_strdup(mem_ctx, sname);
8149 if (strcasecmp_m(stype, ":$DATA") != 0) {
8151 * If there is an explicit stream type, so far we only
8152 * allow $DATA. Is there anything else allowed? -- vl
8154 DEBUG(10, ("[%s] is an invalid stream type\n", stype));
8156 return NT_STATUS_OBJECT_NAME_INVALID;
8158 sname = talloc_strndup(mem_ctx, sname, PTR_DIFF(stype, sname));
8162 if (sname == NULL) {
8164 return NT_STATUS_NO_MEMORY;
8167 if (sname[0] == '\0') {
8169 * no stream name, so no stream
8174 if (pstream != NULL) {
8175 stream = talloc_asprintf(mem_ctx, "%s:%s", sname, stype);
8176 if (stream == NULL) {
8179 return NT_STATUS_NO_MEMORY;
8182 * upper-case the type field
8184 strupper_m(strchr_m(stream, ':')+1);
8188 if (pbase != NULL) {
8191 if (pstream != NULL) {
8194 return NT_STATUS_OK;
8197 static bool test_stream_name(const char *fname, const char *expected_base,
8198 const char *expected_stream,
8199 NTSTATUS expected_status)
8203 char *stream = NULL;
8205 status = split_ntfs_stream_name(talloc_tos(), fname, &base, &stream);
8206 if (!NT_STATUS_EQUAL(status, expected_status)) {
8210 if (!NT_STATUS_IS_OK(status)) {
8214 if (base == NULL) goto error;
8216 if (strcmp(expected_base, base) != 0) goto error;
8218 if ((expected_stream != NULL) && (stream == NULL)) goto error;
8219 if ((expected_stream == NULL) && (stream != NULL)) goto error;
8221 if ((stream != NULL) && (strcmp(expected_stream, stream) != 0))
8225 TALLOC_FREE(stream);
8229 d_fprintf(stderr, "Do test_stream(%s, %s, %s, %s)\n",
8230 fname, expected_base ? expected_base : "<NULL>",
8231 expected_stream ? expected_stream : "<NULL>",
8232 nt_errstr(expected_status));
8233 d_fprintf(stderr, "-> base=%s, stream=%s, status=%s\n",
8234 base ? base : "<NULL>", stream ? stream : "<NULL>",
8237 TALLOC_FREE(stream);
8241 static bool run_local_stream_name(int dummy)
8245 ret &= test_stream_name(
8246 "bla", "bla", NULL, NT_STATUS_OK);
8247 ret &= test_stream_name(
8248 "bla::$DATA", "bla", NULL, NT_STATUS_OK);
8249 ret &= test_stream_name(
8250 "bla:blub:", "bla", NULL, NT_STATUS_OBJECT_NAME_INVALID);
8251 ret &= test_stream_name(
8252 "bla::", NULL, NULL, NT_STATUS_OBJECT_NAME_INVALID);
8253 ret &= test_stream_name(
8254 "bla::123", "bla", NULL, NT_STATUS_OBJECT_NAME_INVALID);
8255 ret &= test_stream_name(
8256 "bla:$DATA", "bla", "$DATA:$DATA", NT_STATUS_OK);
8257 ret &= test_stream_name(
8258 "bla:x:$DATA", "bla", "x:$DATA", NT_STATUS_OK);
8259 ret &= test_stream_name(
8260 "bla:x", "bla", "x:$DATA", NT_STATUS_OK);
8265 static bool data_blob_equal(DATA_BLOB a, DATA_BLOB b)
8267 if (a.length != b.length) {
8268 printf("a.length=%d != b.length=%d\n",
8269 (int)a.length, (int)b.length);
8272 if (memcmp(a.data, b.data, a.length) != 0) {
8273 printf("a.data and b.data differ\n");
8279 static bool run_local_memcache(int dummy)
8281 struct memcache *cache;
8283 DATA_BLOB d1, d2, d3;
8284 DATA_BLOB v1, v2, v3;
8286 TALLOC_CTX *mem_ctx;
8288 size_t size1, size2;
8291 cache = memcache_init(NULL, 100);
8293 if (cache == NULL) {
8294 printf("memcache_init failed\n");
8298 d1 = data_blob_const("d1", 2);
8299 d2 = data_blob_const("d2", 2);
8300 d3 = data_blob_const("d3", 2);
8302 k1 = data_blob_const("d1", 2);
8303 k2 = data_blob_const("d2", 2);
8305 memcache_add(cache, STAT_CACHE, k1, d1);
8306 memcache_add(cache, GETWD_CACHE, k2, d2);
8308 if (!memcache_lookup(cache, STAT_CACHE, k1, &v1)) {
8309 printf("could not find k1\n");
8312 if (!data_blob_equal(d1, v1)) {
8316 if (!memcache_lookup(cache, GETWD_CACHE, k2, &v2)) {
8317 printf("could not find k2\n");
8320 if (!data_blob_equal(d2, v2)) {
8324 memcache_add(cache, STAT_CACHE, k1, d3);
8326 if (!memcache_lookup(cache, STAT_CACHE, k1, &v3)) {
8327 printf("could not find replaced k1\n");
8330 if (!data_blob_equal(d3, v3)) {
8334 memcache_add(cache, GETWD_CACHE, k1, d1);
8336 if (memcache_lookup(cache, GETWD_CACHE, k2, &v2)) {
8337 printf("Did find k2, should have been purged\n");
8343 cache = memcache_init(NULL, 0);
8345 mem_ctx = talloc_init("foo");
8347 str1 = talloc_strdup(mem_ctx, "string1");
8348 str2 = talloc_strdup(mem_ctx, "string2");
8350 memcache_add_talloc(cache, SINGLETON_CACHE_TALLOC,
8351 data_blob_string_const("torture"), &str1);
8352 size1 = talloc_total_size(cache);
8354 memcache_add_talloc(cache, SINGLETON_CACHE_TALLOC,
8355 data_blob_string_const("torture"), &str2);
8356 size2 = talloc_total_size(cache);
8358 printf("size1=%d, size2=%d\n", (int)size1, (int)size2);
8360 if (size2 > size1) {
8361 printf("memcache leaks memory!\n");
8371 static void wbclient_done(struct tevent_req *req)
8374 struct winbindd_response *wb_resp;
8375 int *i = (int *)tevent_req_callback_data_void(req);
8377 wbc_err = wb_trans_recv(req, req, &wb_resp);
8380 d_printf("wb_trans_recv %d returned %s\n", *i, wbcErrorString(wbc_err));
8383 static bool run_local_wbclient(int dummy)
8385 struct event_context *ev;
8386 struct wb_context **wb_ctx;
8387 struct winbindd_request wb_req;
8388 bool result = false;
8391 BlockSignals(True, SIGPIPE);
8393 ev = tevent_context_init_byname(talloc_tos(), "epoll");
8398 wb_ctx = talloc_array(ev, struct wb_context *, nprocs);
8399 if (wb_ctx == NULL) {
8403 ZERO_STRUCT(wb_req);
8404 wb_req.cmd = WINBINDD_PING;
8406 d_printf("nprocs=%d, numops=%d\n", (int)nprocs, (int)torture_numops);
8408 for (i=0; i<nprocs; i++) {
8409 wb_ctx[i] = wb_context_init(ev, NULL);
8410 if (wb_ctx[i] == NULL) {
8413 for (j=0; j<torture_numops; j++) {
8414 struct tevent_req *req;
8415 req = wb_trans_send(ev, ev, wb_ctx[i],
8416 (j % 2) == 0, &wb_req);
8420 tevent_req_set_callback(req, wbclient_done, &i);
8426 while (i < nprocs * torture_numops) {
8427 event_loop_once(ev);
8436 static void getaddrinfo_finished(struct tevent_req *req)
8438 char *name = (char *)tevent_req_callback_data_void(req);
8439 struct addrinfo *ainfo;
8442 res = getaddrinfo_recv(req, &ainfo);
8444 d_printf("gai(%s) returned %s\n", name, gai_strerror(res));
8447 d_printf("gai(%s) succeeded\n", name);
8448 freeaddrinfo(ainfo);
8451 static bool run_getaddrinfo_send(int dummy)
8453 TALLOC_CTX *frame = talloc_stackframe();
8454 struct fncall_context *ctx;
8455 struct tevent_context *ev;
8456 bool result = false;
8457 const char *names[4] = { "www.samba.org", "notfound.samba.org",
8458 "www.slashdot.org", "heise.de" };
8459 struct tevent_req *reqs[4];
8462 ev = event_context_init(frame);
8467 ctx = fncall_context_init(frame, 4);
8469 for (i=0; i<ARRAY_SIZE(names); i++) {
8470 reqs[i] = getaddrinfo_send(frame, ev, ctx, names[i], NULL,
8472 if (reqs[i] == NULL) {
8475 tevent_req_set_callback(reqs[i], getaddrinfo_finished,
8476 discard_const_p(void, names[i]));
8479 for (i=0; i<ARRAY_SIZE(reqs); i++) {
8480 tevent_loop_once(ev);
8489 static bool dbtrans_inc(struct db_context *db)
8491 struct db_record *rec;
8496 rec = db->fetch_locked(db, db, string_term_tdb_data("transtest"));
8498 printf(__location__ "fetch_lock failed\n");
8502 if (rec->value.dsize != sizeof(uint32_t)) {
8503 printf(__location__ "value.dsize = %d\n",
8504 (int)rec->value.dsize);
8508 val = (uint32_t *)rec->value.dptr;
8511 status = rec->store(rec, make_tdb_data((uint8_t *)val,
8514 if (!NT_STATUS_IS_OK(status)) {
8515 printf(__location__ "store failed: %s\n",
8526 static bool run_local_dbtrans(int dummy)
8528 struct db_context *db;
8529 struct db_record *rec;
8534 db = db_open(talloc_tos(), "transtest.tdb", 0, TDB_DEFAULT,
8535 O_RDWR|O_CREAT, 0600);
8537 printf("Could not open transtest.db\n");
8541 res = db->transaction_start(db);
8543 printf(__location__ "transaction_start failed\n");
8547 rec = db->fetch_locked(db, db, string_term_tdb_data("transtest"));
8549 printf(__location__ "fetch_lock failed\n");
8553 if (rec->value.dptr == NULL) {
8555 status = rec->store(
8556 rec, make_tdb_data((uint8_t *)&initial,
8559 if (!NT_STATUS_IS_OK(status)) {
8560 printf(__location__ "store returned %s\n",
8568 res = db->transaction_commit(db);
8570 printf(__location__ "transaction_commit failed\n");
8578 res = db->transaction_start(db);
8580 printf(__location__ "transaction_start failed\n");
8584 if (!dbwrap_fetch_uint32(db, "transtest", &val)) {
8585 printf(__location__ "dbwrap_fetch_uint32 failed\n");
8589 for (i=0; i<10; i++) {
8590 if (!dbtrans_inc(db)) {
8595 if (!dbwrap_fetch_uint32(db, "transtest", &val2)) {
8596 printf(__location__ "dbwrap_fetch_uint32 failed\n");
8600 if (val2 != val + 10) {
8601 printf(__location__ "val=%d, val2=%d\n",
8602 (int)val, (int)val2);
8606 printf("val2=%d\r", val2);
8608 res = db->transaction_commit(db);
8610 printf(__location__ "transaction_commit failed\n");
8620 * Just a dummy test to be run under a debugger. There's no real way
8621 * to inspect the tevent_select specific function from outside of
8625 static bool run_local_tevent_select(int dummy)
8627 struct tevent_context *ev;
8628 struct tevent_fd *fd1, *fd2;
8629 bool result = false;
8631 ev = tevent_context_init_byname(NULL, "select");
8633 d_fprintf(stderr, "tevent_context_init_byname failed\n");
8637 fd1 = tevent_add_fd(ev, ev, 2, 0, NULL, NULL);
8639 d_fprintf(stderr, "tevent_add_fd failed\n");
8642 fd2 = tevent_add_fd(ev, ev, 3, 0, NULL, NULL);
8644 d_fprintf(stderr, "tevent_add_fd failed\n");
8649 fd2 = tevent_add_fd(ev, ev, 1, 0, NULL, NULL);
8651 d_fprintf(stderr, "tevent_add_fd failed\n");
8661 static double create_procs(bool (*fn)(int), bool *result)
8664 volatile pid_t *child_status;
8665 volatile bool *child_status_out;
8668 struct timeval start;
8672 child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*nprocs);
8673 if (!child_status) {
8674 printf("Failed to setup shared memory\n");
8678 child_status_out = (volatile bool *)shm_setup(sizeof(bool)*nprocs);
8679 if (!child_status_out) {
8680 printf("Failed to setup result status shared memory\n");
8684 for (i = 0; i < nprocs; i++) {
8685 child_status[i] = 0;
8686 child_status_out[i] = True;
8689 start = timeval_current();
8691 for (i=0;i<nprocs;i++) {
8694 pid_t mypid = getpid();
8695 sys_srandom(((int)mypid) ^ ((int)time(NULL)));
8697 slprintf(myname,sizeof(myname),"CLIENT%d", i);
8700 if (torture_open_connection(¤t_cli, i)) break;
8702 printf("pid %d failed to start\n", (int)getpid());
8708 child_status[i] = getpid();
8710 while (child_status[i] && timeval_elapsed(&start) < 5) smb_msleep(2);
8712 child_status_out[i] = fn(i);
8719 for (i=0;i<nprocs;i++) {
8720 if (child_status[i]) synccount++;
8722 if (synccount == nprocs) break;
8724 } while (timeval_elapsed(&start) < 30);
8726 if (synccount != nprocs) {
8727 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs, synccount);
8729 return timeval_elapsed(&start);
8732 /* start the client load */
8733 start = timeval_current();
8735 for (i=0;i<nprocs;i++) {
8736 child_status[i] = 0;
8739 printf("%d clients started\n", nprocs);
8741 for (i=0;i<nprocs;i++) {
8742 while (waitpid(0, &status, 0) == -1 && errno == EINTR) /* noop */ ;
8747 for (i=0;i<nprocs;i++) {
8748 if (!child_status_out[i]) {
8752 return timeval_elapsed(&start);
8755 #define FLAG_MULTIPROC 1
8762 {"FDPASS", run_fdpasstest, 0},
8763 {"LOCK1", run_locktest1, 0},
8764 {"LOCK2", run_locktest2, 0},
8765 {"LOCK3", run_locktest3, 0},
8766 {"LOCK4", run_locktest4, 0},
8767 {"LOCK5", run_locktest5, 0},
8768 {"LOCK6", run_locktest6, 0},
8769 {"LOCK7", run_locktest7, 0},
8770 {"LOCK8", run_locktest8, 0},
8771 {"LOCK9", run_locktest9, 0},
8772 {"UNLINK", run_unlinktest, 0},
8773 {"BROWSE", run_browsetest, 0},
8774 {"ATTR", run_attrtest, 0},
8775 {"TRANS2", run_trans2test, 0},
8776 {"MAXFID", run_maxfidtest, FLAG_MULTIPROC},
8777 {"TORTURE",run_torture, FLAG_MULTIPROC},
8778 {"RANDOMIPC", run_randomipc, 0},
8779 {"NEGNOWAIT", run_negprot_nowait, 0},
8780 {"NBENCH", run_nbench, 0},
8781 {"NBENCH2", run_nbench2, 0},
8782 {"OPLOCK1", run_oplock1, 0},
8783 {"OPLOCK2", run_oplock2, 0},
8784 {"OPLOCK4", run_oplock4, 0},
8785 {"DIR", run_dirtest, 0},
8786 {"DIR1", run_dirtest1, 0},
8787 {"DIR-CREATETIME", run_dir_createtime, 0},
8788 {"DENY1", torture_denytest1, 0},
8789 {"DENY2", torture_denytest2, 0},
8790 {"TCON", run_tcon_test, 0},
8791 {"TCONDEV", run_tcon_devtype_test, 0},
8792 {"RW1", run_readwritetest, 0},
8793 {"RW2", run_readwritemulti, FLAG_MULTIPROC},
8794 {"RW3", run_readwritelarge, 0},
8795 {"RW-SIGNING", run_readwritelarge_signtest, 0},
8796 {"OPEN", run_opentest, 0},
8797 {"POSIX", run_simple_posix_open_test, 0},
8798 {"POSIX-APPEND", run_posix_append, 0},
8799 {"CASE-INSENSITIVE-CREATE", run_case_insensitive_create, 0},
8800 {"ASYNC-ECHO", run_async_echo, 0},
8801 { "UID-REGRESSION-TEST", run_uid_regression_test, 0},
8802 { "SHORTNAME-TEST", run_shortname_test, 0},
8803 { "ADDRCHANGE", run_addrchange, 0},
8805 {"OPENATTR", run_openattrtest, 0},
8807 {"XCOPY", run_xcopy, 0},
8808 {"RENAME", run_rename, 0},
8809 {"DELETE", run_deletetest, 0},
8810 {"DELETE-LN", run_deletetest_ln, 0},
8811 {"PROPERTIES", run_properties, 0},
8812 {"MANGLE", torture_mangle, 0},
8813 {"MANGLE1", run_mangle1, 0},
8814 {"W2K", run_w2ktest, 0},
8815 {"TRANS2SCAN", torture_trans2_scan, 0},
8816 {"NTTRANSSCAN", torture_nttrans_scan, 0},
8817 {"UTABLE", torture_utable, 0},
8818 {"CASETABLE", torture_casetable, 0},
8819 {"ERRMAPEXTRACT", run_error_map_extract, 0},
8820 {"PIPE_NUMBER", run_pipe_number, 0},
8821 {"TCON2", run_tcon2_test, 0},
8822 {"IOCTL", torture_ioctl_test, 0},
8823 {"CHKPATH", torture_chkpath_test, 0},
8824 {"FDSESS", run_fdsesstest, 0},
8825 { "EATEST", run_eatest, 0},
8826 { "SESSSETUP_BENCH", run_sesssetup_bench, 0},
8827 { "CHAIN1", run_chain1, 0},
8828 { "CHAIN2", run_chain2, 0},
8829 { "WINDOWS-WRITE", run_windows_write, 0},
8830 { "NTTRANS-CREATE", run_nttrans_create, 0},
8831 { "CLI_ECHO", run_cli_echo, 0},
8832 { "GETADDRINFO", run_getaddrinfo_send, 0},
8833 { "TLDAP", run_tldap },
8834 { "STREAMERROR", run_streamerror },
8835 { "NOTIFY-BENCH", run_notify_bench },
8836 { "BAD-NBT-SESSION", run_bad_nbt_session },
8837 { "SMB-ANY-CONNECT", run_smb_any_connect },
8838 { "NOTIFY-ONLINE", run_notify_online },
8839 { "SMB2-BASIC", run_smb2_basic },
8840 { "LOCAL-SUBSTITUTE", run_local_substitute, 0},
8841 { "LOCAL-GENCACHE", run_local_gencache, 0},
8842 { "LOCAL-TALLOC-DICT", run_local_talloc_dict, 0},
8843 { "LOCAL-BASE64", run_local_base64, 0},
8844 { "LOCAL-RBTREE", run_local_rbtree, 0},
8845 { "LOCAL-MEMCACHE", run_local_memcache, 0},
8846 { "LOCAL-STREAM-NAME", run_local_stream_name, 0},
8847 { "LOCAL-WBCLIENT", run_local_wbclient, 0},
8848 { "LOCAL-string_to_sid", run_local_string_to_sid, 0},
8849 { "LOCAL-binary_to_sid", run_local_binary_to_sid, 0},
8850 { "LOCAL-DBTRANS", run_local_dbtrans, 0},
8851 { "LOCAL-TEVENT-SELECT", run_local_tevent_select, 0},
8852 { "LOCAL-CONVERT-STRING", run_local_convert_string, 0},
8857 /****************************************************************************
8858 run a specified test or "ALL"
8859 ****************************************************************************/
8860 static bool run_test(const char *name)
8867 if (strequal(name,"ALL")) {
8868 for (i=0;torture_ops[i].name;i++) {
8869 run_test(torture_ops[i].name);
8874 for (i=0;torture_ops[i].name;i++) {
8875 fstr_sprintf(randomfname, "\\XX%x",
8876 (unsigned)random());
8878 if (strequal(name, torture_ops[i].name)) {
8880 printf("Running %s\n", name);
8881 if (torture_ops[i].flags & FLAG_MULTIPROC) {
8882 t = create_procs(torture_ops[i].fn, &result);
8885 printf("TEST %s FAILED!\n", name);
8888 struct timeval start;
8889 start = timeval_current();
8890 if (!torture_ops[i].fn(0)) {
8892 printf("TEST %s FAILED!\n", name);
8894 t = timeval_elapsed(&start);
8896 printf("%s took %g secs\n\n", name, t);
8901 printf("Did not find a test named %s\n", name);
8909 static void usage(void)
8913 printf("WARNING samba4 test suite is much more complete nowadays.\n");
8914 printf("Please use samba4 torture.\n\n");
8916 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
8918 printf("\t-d debuglevel\n");
8919 printf("\t-U user%%pass\n");
8920 printf("\t-k use kerberos\n");
8921 printf("\t-N numprocs\n");
8922 printf("\t-n my_netbios_name\n");
8923 printf("\t-W workgroup\n");
8924 printf("\t-o num_operations\n");
8925 printf("\t-O socket_options\n");
8926 printf("\t-m maximum protocol\n");
8927 printf("\t-L use oplocks\n");
8928 printf("\t-c CLIENT.TXT specify client load file for NBENCH\n");
8929 printf("\t-A showall\n");
8930 printf("\t-p port\n");
8931 printf("\t-s seed\n");
8932 printf("\t-b unclist_filename specify multiple shares for multiple connections\n");
8933 printf("\t-f filename filename to test\n");
8936 printf("tests are:");
8937 for (i=0;torture_ops[i].name;i++) {
8938 printf(" %s", torture_ops[i].name);
8942 printf("default test is ALL\n");
8947 /****************************************************************************
8949 ****************************************************************************/
8950 int main(int argc,char *argv[])
8956 bool correct = True;
8957 TALLOC_CTX *frame = talloc_stackframe();
8958 int seed = time(NULL);
8960 #ifdef HAVE_SETBUFFER
8961 setbuffer(stdout, NULL, 0);
8964 setup_logging("smbtorture", DEBUG_STDOUT);
8968 if (is_default_dyn_CONFIGFILE()) {
8969 if(getenv("SMB_CONF_PATH")) {
8970 set_dyn_CONFIGFILE(getenv("SMB_CONF_PATH"));
8973 lp_load_global(get_dyn_CONFIGFILE());
8980 for(p = argv[1]; *p; p++)
8984 if (strncmp(argv[1], "//", 2)) {
8988 fstrcpy(host, &argv[1][2]);
8989 p = strchr_m(&host[2],'/');
8994 fstrcpy(share, p+1);
8996 fstrcpy(myname, get_myname(talloc_tos()));
8998 fprintf(stderr, "Failed to get my hostname.\n");
9002 if (*username == 0 && getenv("LOGNAME")) {
9003 fstrcpy(username,getenv("LOGNAME"));
9009 fstrcpy(workgroup, lp_workgroup());
9011 while ((opt = getopt(argc, argv, "p:hW:U:n:N:O:o:m:Ll:d:Aec:ks:b:B:f:"))
9015 port_to_use = atoi(optarg);
9018 seed = atoi(optarg);
9021 fstrcpy(workgroup,optarg);
9024 max_protocol = interpret_protocol(optarg, max_protocol);
9027 nprocs = atoi(optarg);
9030 torture_numops = atoi(optarg);
9033 lp_set_cmdline("log level", optarg);
9042 local_path = optarg;
9045 torture_showall = True;
9048 fstrcpy(myname, optarg);
9051 client_txt = optarg;
9058 use_kerberos = True;
9060 d_printf("No kerberos support compiled in\n");
9066 fstrcpy(username,optarg);
9067 p = strchr_m(username,'%');
9070 fstrcpy(password, p+1);
9075 fstrcpy(multishare_conn_fname, optarg);
9076 use_multishare_conn = True;
9079 torture_blocksize = atoi(optarg);
9082 test_filename = SMB_STRDUP(optarg);
9085 printf("Unknown option %c (%d)\n", (char)opt, opt);
9090 d_printf("using seed %d\n", seed);
9094 if(use_kerberos && !gotuser) gotpass = True;
9097 p = getpass("Password:");
9099 fstrcpy(password, p);
9104 printf("host=%s share=%s user=%s myname=%s\n",
9105 host, share, username, myname);
9107 if (argc == optind) {
9108 correct = run_test("ALL");
9110 for (i=optind;i<argc;i++) {
9111 if (!run_test(argv[i])) {