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 "talloc_dict.h"
33 #include "async_smb.h"
34 #include "libsmb/libsmb.h"
35 #include "libsmb/clirap.h"
37 #include "libsmb/nmblib.h"
38 #include "../lib/util/tevent_ntstatus.h"
40 #include "libsmb/read_smb.h"
45 fstring host, workgroup, share, password, username, myname;
46 static int max_protocol = PROTOCOL_NT1;
47 static const char *sockops="TCP_NODELAY";
49 static int port_to_use=0;
50 int torture_numops=100;
51 int torture_blocksize=1024*1024;
52 static int procnum; /* records process count number when forking */
53 static struct cli_state *current_cli;
54 static fstring randomfname;
55 static bool use_oplocks;
56 static bool use_level_II_oplocks;
57 static const char *client_txt = "client_oplocks.txt";
58 static bool use_kerberos;
59 static fstring multishare_conn_fname;
60 static bool use_multishare_conn = False;
61 static bool do_encrypt;
62 static const char *local_path = NULL;
63 static int signing_state = Undefined;
66 bool torture_showall = False;
68 static double create_procs(bool (*fn)(int), bool *result);
71 /* return a pointer to a anonymous shared memory segment of size "size"
72 which will persist across fork() but will disappear when all processes
75 The memory is not zeroed
77 This function uses system5 shared memory. It takes advantage of a property
78 that the memory is not destroyed if it is attached when the id is removed
80 void *shm_setup(int size)
86 shmid = shm_open("private", O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
88 printf("can't get shared memory\n");
91 shm_unlink("private");
92 if (ftruncate(shmid, size) == -1) {
93 printf("can't set shared memory size\n");
96 ret = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, shmid, 0);
97 if (ret == MAP_FAILED) {
98 printf("can't map shared memory\n");
102 shmid = shmget(IPC_PRIVATE, size, S_IRUSR | S_IWUSR);
104 printf("can't get shared memory\n");
107 ret = (void *)shmat(shmid, 0, 0);
108 if (!ret || ret == (void *)-1) {
109 printf("can't attach to shared memory\n");
112 /* the following releases the ipc, but note that this process
113 and all its children will still have access to the memory, its
114 just that the shmid is no longer valid for other shm calls. This
115 means we don't leave behind lots of shm segments after we exit
117 See Stevens "advanced programming in unix env" for details
119 shmctl(shmid, IPC_RMID, 0);
125 /********************************************************************
126 Ensure a connection is encrypted.
127 ********************************************************************/
129 static bool force_cli_encryption(struct cli_state *c,
130 const char *sharename)
133 uint32 caplow, caphigh;
136 if (!SERVER_HAS_UNIX_CIFS(c)) {
137 d_printf("Encryption required and "
138 "server that doesn't support "
139 "UNIX extensions - failing connect\n");
143 status = cli_unix_extensions_version(c, &major, &minor, &caplow,
145 if (!NT_STATUS_IS_OK(status)) {
146 d_printf("Encryption required and "
147 "can't get UNIX CIFS extensions "
148 "version from server: %s\n", nt_errstr(status));
152 if (!(caplow & CIFS_UNIX_TRANSPORT_ENCRYPTION_CAP)) {
153 d_printf("Encryption required and "
154 "share %s doesn't support "
155 "encryption.\n", sharename);
159 if (c->use_kerberos) {
160 status = cli_gss_smb_encryption_start(c);
162 status = cli_raw_ntlm_smb_encryption_start(c,
168 if (!NT_STATUS_IS_OK(status)) {
169 d_printf("Encryption required and "
170 "setup failed with error %s.\n",
179 static struct cli_state *open_nbt_connection(void)
184 status = cli_connect_nb(host, NULL, port_to_use, 0x20, myname,
186 if (!NT_STATUS_IS_OK(status)) {
187 printf("Failed to connect with %s. Error %s\n", host, nt_errstr(status) );
191 c->use_kerberos = use_kerberos;
193 c->timeout = 120000; /* set a really long timeout (2 minutes) */
194 if (use_oplocks) c->use_oplocks = True;
195 if (use_level_II_oplocks) c->use_level_II_oplocks = True;
200 /****************************************************************************
201 Send a corrupt session request. See rfc1002.txt 4.3 and 4.3.2.
202 ****************************************************************************/
204 static bool cli_bad_session_request(int fd,
205 struct nmb_name *calling, struct nmb_name *called)
214 uint8_t message_type;
217 frame = talloc_stackframe();
219 iov[0].iov_base = len_buf;
220 iov[0].iov_len = sizeof(len_buf);
222 /* put in the destination name */
224 iov[1].iov_base = name_mangle(talloc_tos(), called->name,
226 if (iov[1].iov_base == NULL) {
229 iov[1].iov_len = name_len((unsigned char *)iov[1].iov_base,
230 talloc_get_size(iov[1].iov_base));
234 iov[2].iov_base = name_mangle(talloc_tos(), calling->name,
236 if (iov[2].iov_base == NULL) {
239 iov[2].iov_len = name_len((unsigned char *)iov[2].iov_base,
240 talloc_get_size(iov[2].iov_base));
242 /* Deliberately corrupt the name len (first byte) */
243 *((uint8_t *)iov[2].iov_base) = 100;
245 /* send a session request (RFC 1002) */
246 /* setup the packet length
247 * Remove four bytes from the length count, since the length
248 * field in the NBT Session Service header counts the number
249 * of bytes which follow. The cli_send_smb() function knows
250 * about this and accounts for those four bytes.
254 _smb_setlen(len_buf, iov[1].iov_len + iov[2].iov_len);
255 SCVAL(len_buf,0,0x81);
257 len = write_data_iov(fd, iov, 3);
261 len = read_smb(fd, talloc_tos(), &inbuf, &err);
267 message_type = CVAL(inbuf, 0);
268 if (message_type != 0x83) {
269 d_fprintf(stderr, "Expected msg type 0x83, got 0x%2.2x\n",
274 if (smb_len(inbuf) != 1) {
275 d_fprintf(stderr, "Expected smb_len 1, got %d\n",
276 (int)smb_len(inbuf));
280 error = CVAL(inbuf, 4);
282 d_fprintf(stderr, "Expected error 0x82, got %d\n",
293 /* Insert a NULL at the first separator of the given path and return a pointer
294 * to the remainder of the string.
297 terminate_path_at_separator(char * path)
305 if ((p = strchr_m(path, '/'))) {
310 if ((p = strchr_m(path, '\\'))) {
320 parse a //server/share type UNC name
322 bool smbcli_parse_unc(const char *unc_name, TALLOC_CTX *mem_ctx,
323 char **hostname, char **sharename)
327 *hostname = *sharename = NULL;
329 if (strncmp(unc_name, "\\\\", 2) &&
330 strncmp(unc_name, "//", 2)) {
334 *hostname = talloc_strdup(mem_ctx, &unc_name[2]);
335 p = terminate_path_at_separator(*hostname);
338 *sharename = talloc_strdup(mem_ctx, p);
339 terminate_path_at_separator(*sharename);
342 if (*hostname && *sharename) {
346 TALLOC_FREE(*hostname);
347 TALLOC_FREE(*sharename);
351 static bool torture_open_connection_share(struct cli_state **c,
352 const char *hostname,
353 const char *sharename)
359 flags |= CLI_FULL_CONNECTION_USE_KERBEROS;
361 flags |= CLI_FULL_CONNECTION_OPLOCKS;
362 if (use_level_II_oplocks)
363 flags |= CLI_FULL_CONNECTION_LEVEL_II_OPLOCKS;
365 status = cli_full_connection(c, myname,
366 hostname, NULL, port_to_use,
369 password, flags, signing_state);
370 if (!NT_STATUS_IS_OK(status)) {
371 printf("failed to open share connection: //%s/%s port:%d - %s\n",
372 hostname, sharename, port_to_use, nt_errstr(status));
376 (*c)->timeout = 120000; /* set a really long timeout (2 minutes) */
379 return force_cli_encryption(*c,
385 bool torture_open_connection(struct cli_state **c, int conn_index)
387 char **unc_list = NULL;
388 int num_unc_names = 0;
391 if (use_multishare_conn==True) {
393 unc_list = file_lines_load(multishare_conn_fname, &num_unc_names, 0, NULL);
394 if (!unc_list || num_unc_names <= 0) {
395 printf("Failed to load unc names list from '%s'\n", multishare_conn_fname);
399 if (!smbcli_parse_unc(unc_list[conn_index % num_unc_names],
401 printf("Failed to parse UNC name %s\n",
402 unc_list[conn_index % num_unc_names]);
403 TALLOC_FREE(unc_list);
407 result = torture_open_connection_share(c, h, s);
409 /* h, s were copied earlier */
410 TALLOC_FREE(unc_list);
414 return torture_open_connection_share(c, host, share);
417 bool torture_init_connection(struct cli_state **pcli)
419 struct cli_state *cli;
421 cli = open_nbt_connection();
430 bool torture_cli_session_setup2(struct cli_state *cli, uint16 *new_vuid)
432 uint16_t old_vuid = cli_state_get_uid(cli);
433 fstring old_user_name;
434 size_t passlen = strlen(password);
438 fstrcpy(old_user_name, cli->user_name);
439 cli_state_set_uid(cli, 0);
440 ret = NT_STATUS_IS_OK(cli_session_setup(cli, username,
444 *new_vuid = cli_state_get_uid(cli);
445 cli_state_set_uid(cli, old_vuid);
446 status = cli_set_username(cli, old_user_name);
447 if (!NT_STATUS_IS_OK(status)) {
454 bool torture_close_connection(struct cli_state *c)
459 status = cli_tdis(c);
460 if (!NT_STATUS_IS_OK(status)) {
461 printf("tdis failed (%s)\n", nt_errstr(status));
471 /* check if the server produced the expected dos or nt error code */
472 static bool check_both_error(int line, NTSTATUS status,
473 uint8 eclass, uint32 ecode, NTSTATUS nterr)
475 if (NT_STATUS_IS_DOS(status)) {
479 /* Check DOS error */
480 cclass = NT_STATUS_DOS_CLASS(status);
481 num = NT_STATUS_DOS_CODE(status);
483 if (eclass != cclass || ecode != num) {
484 printf("unexpected error code class=%d code=%d\n",
485 (int)cclass, (int)num);
486 printf(" expected %d/%d %s (line=%d)\n",
487 (int)eclass, (int)ecode, nt_errstr(nterr), line);
492 if (!NT_STATUS_EQUAL(nterr, status)) {
493 printf("unexpected error code %s\n",
495 printf(" expected %s (line=%d)\n",
496 nt_errstr(nterr), line);
505 /* check if the server produced the expected error code */
506 static bool check_error(int line, NTSTATUS status,
507 uint8 eclass, uint32 ecode, NTSTATUS nterr)
509 if (NT_STATUS_IS_DOS(status)) {
513 /* Check DOS error */
515 cclass = NT_STATUS_DOS_CLASS(status);
516 num = NT_STATUS_DOS_CODE(status);
518 if (eclass != cclass || ecode != num) {
519 printf("unexpected error code class=%d code=%d\n",
520 (int)cclass, (int)num);
521 printf(" expected %d/%d %s (line=%d)\n",
522 (int)eclass, (int)ecode, nt_errstr(nterr),
530 if (NT_STATUS_V(nterr) != NT_STATUS_V(status)) {
531 printf("unexpected error code %s\n",
533 printf(" expected %s (line=%d)\n", nt_errstr(nterr),
543 static bool wait_lock(struct cli_state *c, int fnum, uint32 offset, uint32 len)
547 status = cli_lock32(c, fnum, offset, len, -1, WRITE_LOCK);
549 while (!NT_STATUS_IS_OK(status)) {
550 if (!check_both_error(__LINE__, status, ERRDOS,
551 ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) {
555 status = cli_lock32(c, fnum, offset, len, -1, WRITE_LOCK);
562 static bool rw_torture(struct cli_state *c)
564 const char *lockfname = "\\torture.lck";
568 pid_t pid2, pid = getpid();
575 memset(buf, '\0', sizeof(buf));
577 status = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
579 if (!NT_STATUS_IS_OK(status)) {
580 status = cli_open(c, lockfname, O_RDWR, DENY_NONE, &fnum2);
582 if (!NT_STATUS_IS_OK(status)) {
583 printf("open of %s failed (%s)\n",
584 lockfname, nt_errstr(status));
588 for (i=0;i<torture_numops;i++) {
589 unsigned n = (unsigned)sys_random()%10;
592 printf("%d\r", i); fflush(stdout);
594 slprintf(fname, sizeof(fstring) - 1, "\\torture.%u", n);
596 if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) {
600 status = cli_open(c, fname, O_RDWR | O_CREAT | O_TRUNC,
602 if (!NT_STATUS_IS_OK(status)) {
603 printf("open failed (%s)\n", nt_errstr(status));
608 status = cli_writeall(c, fnum, 0, (uint8_t *)&pid, 0,
610 if (!NT_STATUS_IS_OK(status)) {
611 printf("write failed (%s)\n", nt_errstr(status));
616 status = cli_writeall(c, fnum, 0, (uint8_t *)buf,
617 sizeof(pid)+(j*sizeof(buf)),
619 if (!NT_STATUS_IS_OK(status)) {
620 printf("write failed (%s)\n",
628 status = cli_read(c, fnum, (char *)&pid2, 0, sizeof(pid),
630 if (!NT_STATUS_IS_OK(status)) {
631 printf("read failed (%s)\n", nt_errstr(status));
633 } else if (nread != sizeof(pid)) {
634 printf("read/write compare failed: "
635 "recv %ld req %ld\n", (unsigned long)nread,
636 (unsigned long)sizeof(pid));
641 printf("data corruption!\n");
645 status = cli_close(c, fnum);
646 if (!NT_STATUS_IS_OK(status)) {
647 printf("close failed (%s)\n", nt_errstr(status));
651 status = cli_unlink(c, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
652 if (!NT_STATUS_IS_OK(status)) {
653 printf("unlink failed (%s)\n", nt_errstr(status));
657 status = cli_unlock(c, fnum2, n*sizeof(int), sizeof(int));
658 if (!NT_STATUS_IS_OK(status)) {
659 printf("unlock failed (%s)\n", nt_errstr(status));
665 cli_unlink(c, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
672 static bool run_torture(int dummy)
674 struct cli_state *cli;
679 cli_sockopt(cli, sockops);
681 ret = rw_torture(cli);
683 if (!torture_close_connection(cli)) {
690 static bool rw_torture3(struct cli_state *c, char *lockfname)
692 uint16_t fnum = (uint16_t)-1;
697 unsigned countprev = 0;
700 NTSTATUS status = NT_STATUS_OK;
703 for (i = 0; i < sizeof(buf); i += sizeof(uint32))
705 SIVAL(buf, i, sys_random());
712 FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
713 if (!NT_STATUS_IS_OK(status)) {
714 printf("unlink failed (%s) (normal, this file should "
715 "not exist)\n", nt_errstr(status));
718 status = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
720 if (!NT_STATUS_IS_OK(status)) {
721 printf("first open read/write of %s failed (%s)\n",
722 lockfname, nt_errstr(status));
728 for (i = 0; i < 500 && fnum == (uint16_t)-1; i++)
730 status = cli_open(c, lockfname, O_RDONLY,
732 if (!NT_STATUS_IS_OK(status)) {
737 if (!NT_STATUS_IS_OK(status)) {
738 printf("second open read-only of %s failed (%s)\n",
739 lockfname, nt_errstr(status));
745 for (count = 0; count < sizeof(buf); count += sent)
747 if (count >= countprev) {
748 printf("%d %8d\r", i, count);
751 countprev += (sizeof(buf) / 20);
756 sent = ((unsigned)sys_random()%(20))+ 1;
757 if (sent > sizeof(buf) - count)
759 sent = sizeof(buf) - count;
762 status = cli_writeall(c, fnum, 0, (uint8_t *)buf+count,
764 if (!NT_STATUS_IS_OK(status)) {
765 printf("write failed (%s)\n",
772 status = cli_read(c, fnum, buf_rd+count, count,
773 sizeof(buf)-count, &sent);
774 if(!NT_STATUS_IS_OK(status)) {
775 printf("read failed offset:%d size:%ld (%s)\n",
776 count, (unsigned long)sizeof(buf)-count,
780 } else if (sent > 0) {
781 if (memcmp(buf_rd+count, buf+count, sent) != 0)
783 printf("read/write compare failed\n");
784 printf("offset: %d req %ld recvd %ld\n", count, (unsigned long)sizeof(buf)-count, (unsigned long)sent);
793 status = cli_close(c, fnum);
794 if (!NT_STATUS_IS_OK(status)) {
795 printf("close failed (%s)\n", nt_errstr(status));
802 static bool rw_torture2(struct cli_state *c1, struct cli_state *c2)
804 const char *lockfname = "\\torture2.lck";
814 status = cli_unlink(c1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
815 if (!NT_STATUS_IS_OK(status)) {
816 printf("unlink failed (%s) (normal, this file should not exist)\n", nt_errstr(status));
819 status = cli_open(c1, lockfname, O_RDWR | O_CREAT | O_EXCL,
821 if (!NT_STATUS_IS_OK(status)) {
822 printf("first open read/write of %s failed (%s)\n",
823 lockfname, nt_errstr(status));
827 status = cli_open(c2, lockfname, O_RDONLY, DENY_NONE, &fnum2);
828 if (!NT_STATUS_IS_OK(status)) {
829 printf("second open read-only of %s failed (%s)\n",
830 lockfname, nt_errstr(status));
831 cli_close(c1, fnum1);
835 for (i = 0; i < torture_numops; i++)
837 size_t buf_size = ((unsigned)sys_random()%(sizeof(buf)-1))+ 1;
839 printf("%d\r", i); fflush(stdout);
842 generate_random_buffer((unsigned char *)buf, buf_size);
844 status = cli_writeall(c1, fnum1, 0, (uint8_t *)buf, 0,
846 if (!NT_STATUS_IS_OK(status)) {
847 printf("write failed (%s)\n", nt_errstr(status));
852 status = cli_read(c2, fnum2, buf_rd, 0, buf_size, &bytes_read);
853 if(!NT_STATUS_IS_OK(status)) {
854 printf("read failed (%s)\n", nt_errstr(status));
857 } else if (bytes_read != buf_size) {
858 printf("read failed\n");
859 printf("read %ld, expected %ld\n",
860 (unsigned long)bytes_read,
861 (unsigned long)buf_size);
866 if (memcmp(buf_rd, buf, buf_size) != 0)
868 printf("read/write compare failed\n");
874 status = cli_close(c2, fnum2);
875 if (!NT_STATUS_IS_OK(status)) {
876 printf("close failed (%s)\n", nt_errstr(status));
880 status = cli_close(c1, fnum1);
881 if (!NT_STATUS_IS_OK(status)) {
882 printf("close failed (%s)\n", nt_errstr(status));
886 status = cli_unlink(c1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
887 if (!NT_STATUS_IS_OK(status)) {
888 printf("unlink failed (%s)\n", nt_errstr(status));
895 static bool run_readwritetest(int dummy)
897 struct cli_state *cli1, *cli2;
898 bool test1, test2 = False;
900 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
903 cli_sockopt(cli1, sockops);
904 cli_sockopt(cli2, sockops);
906 printf("starting readwritetest\n");
908 test1 = rw_torture2(cli1, cli2);
909 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1));
912 test2 = rw_torture2(cli1, cli1);
913 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2));
916 if (!torture_close_connection(cli1)) {
920 if (!torture_close_connection(cli2)) {
924 return (test1 && test2);
927 static bool run_readwritemulti(int dummy)
929 struct cli_state *cli;
934 cli_sockopt(cli, sockops);
936 printf("run_readwritemulti: fname %s\n", randomfname);
937 test = rw_torture3(cli, randomfname);
939 if (!torture_close_connection(cli)) {
946 static bool run_readwritelarge_internal(int max_xmit_k)
948 static struct cli_state *cli1;
950 const char *lockfname = "\\large.dat";
956 if (!torture_open_connection(&cli1, 0)) {
959 cli_sockopt(cli1, sockops);
960 memset(buf,'\0',sizeof(buf));
962 cli1->max_xmit = max_xmit_k*1024;
964 if (signing_state == Required) {
965 /* Horrible cheat to force
966 multiple signed outstanding
967 packets against a Samba server.
969 cli1->is_samba = false;
972 printf("starting readwritelarge_internal\n");
974 cli_unlink(cli1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
976 status = cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL,
978 if (!NT_STATUS_IS_OK(status)) {
979 printf("open read/write of %s failed (%s)\n", lockfname, nt_errstr(status));
983 cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 0, sizeof(buf), NULL);
985 status = cli_qfileinfo_basic(cli1, fnum1, NULL, &fsize, NULL, NULL,
987 if (!NT_STATUS_IS_OK(status)) {
988 printf("qfileinfo failed (%s)\n", nt_errstr(status));
992 if (fsize == sizeof(buf))
993 printf("readwritelarge_internal test 1 succeeded (size = %lx)\n",
994 (unsigned long)fsize);
996 printf("readwritelarge_internal test 1 failed (size = %lx)\n",
997 (unsigned long)fsize);
1001 status = cli_close(cli1, fnum1);
1002 if (!NT_STATUS_IS_OK(status)) {
1003 printf("close failed (%s)\n", nt_errstr(status));
1007 status = cli_unlink(cli1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1008 if (!NT_STATUS_IS_OK(status)) {
1009 printf("unlink failed (%s)\n", nt_errstr(status));
1013 status = cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL,
1015 if (!NT_STATUS_IS_OK(status)) {
1016 printf("open read/write of %s failed (%s)\n", lockfname, nt_errstr(status));
1020 cli1->max_xmit = 4*1024;
1022 cli_smbwrite(cli1, fnum1, buf, 0, sizeof(buf), NULL);
1024 status = cli_qfileinfo_basic(cli1, fnum1, NULL, &fsize, NULL, NULL,
1026 if (!NT_STATUS_IS_OK(status)) {
1027 printf("qfileinfo failed (%s)\n", nt_errstr(status));
1031 if (fsize == sizeof(buf))
1032 printf("readwritelarge_internal test 2 succeeded (size = %lx)\n",
1033 (unsigned long)fsize);
1035 printf("readwritelarge_internal test 2 failed (size = %lx)\n",
1036 (unsigned long)fsize);
1041 /* ToDo - set allocation. JRA */
1042 if(!cli_set_allocation_size(cli1, fnum1, 0)) {
1043 printf("set allocation size to zero failed (%s)\n", cli_errstr(&cli1));
1046 if (!cli_qfileinfo_basic(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL,
1048 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
1052 printf("readwritelarge test 3 (truncate test) succeeded (size = %x)\n", fsize);
1055 status = cli_close(cli1, fnum1);
1056 if (!NT_STATUS_IS_OK(status)) {
1057 printf("close failed (%s)\n", nt_errstr(status));
1061 if (!torture_close_connection(cli1)) {
1067 static bool run_readwritelarge(int dummy)
1069 return run_readwritelarge_internal(128);
1072 static bool run_readwritelarge_signtest(int dummy)
1075 signing_state = Required;
1076 ret = run_readwritelarge_internal(2);
1077 signing_state = Undefined;
1084 #define ival(s) strtol(s, NULL, 0)
1086 /* run a test that simulates an approximate netbench client load */
1087 static bool run_netbench(int client)
1089 struct cli_state *cli;
1094 const char *params[20];
1095 bool correct = True;
1101 cli_sockopt(cli, sockops);
1105 slprintf(cname,sizeof(cname)-1, "client%d", client);
1107 f = fopen(client_txt, "r");
1114 while (fgets(line, sizeof(line)-1, f)) {
1118 line[strlen(line)-1] = 0;
1120 /* printf("[%d] %s\n", line_count, line); */
1122 all_string_sub(line,"client1", cname, sizeof(line));
1124 /* parse the command parameters */
1125 params[0] = strtok_r(line, " ", &saveptr);
1127 while (params[i]) params[++i] = strtok_r(NULL, " ", &saveptr);
1131 if (i < 2) continue;
1133 if (!strncmp(params[0],"SMB", 3)) {
1134 printf("ERROR: You are using a dbench 1 load file\n");
1138 if (!strcmp(params[0],"NTCreateX")) {
1139 nb_createx(params[1], ival(params[2]), ival(params[3]),
1141 } else if (!strcmp(params[0],"Close")) {
1142 nb_close(ival(params[1]));
1143 } else if (!strcmp(params[0],"Rename")) {
1144 nb_rename(params[1], params[2]);
1145 } else if (!strcmp(params[0],"Unlink")) {
1146 nb_unlink(params[1]);
1147 } else if (!strcmp(params[0],"Deltree")) {
1148 nb_deltree(params[1]);
1149 } else if (!strcmp(params[0],"Rmdir")) {
1150 nb_rmdir(params[1]);
1151 } else if (!strcmp(params[0],"QUERY_PATH_INFORMATION")) {
1152 nb_qpathinfo(params[1]);
1153 } else if (!strcmp(params[0],"QUERY_FILE_INFORMATION")) {
1154 nb_qfileinfo(ival(params[1]));
1155 } else if (!strcmp(params[0],"QUERY_FS_INFORMATION")) {
1156 nb_qfsinfo(ival(params[1]));
1157 } else if (!strcmp(params[0],"FIND_FIRST")) {
1158 nb_findfirst(params[1]);
1159 } else if (!strcmp(params[0],"WriteX")) {
1160 nb_writex(ival(params[1]),
1161 ival(params[2]), ival(params[3]), ival(params[4]));
1162 } else if (!strcmp(params[0],"ReadX")) {
1163 nb_readx(ival(params[1]),
1164 ival(params[2]), ival(params[3]), ival(params[4]));
1165 } else if (!strcmp(params[0],"Flush")) {
1166 nb_flush(ival(params[1]));
1168 printf("Unknown operation %s\n", params[0]);
1176 if (!torture_close_connection(cli)) {
1184 /* run a test that simulates an approximate netbench client load */
1185 static bool run_nbench(int dummy)
1188 bool correct = True;
1194 signal(SIGALRM, nb_alarm);
1196 t = create_procs(run_netbench, &correct);
1199 printf("\nThroughput %g MB/sec\n",
1200 1.0e-6 * nbio_total() / t);
1206 This test checks for two things:
1208 1) correct support for retaining locks over a close (ie. the server
1209 must not use posix semantics)
1210 2) support for lock timeouts
1212 static bool run_locktest1(int dummy)
1214 struct cli_state *cli1, *cli2;
1215 const char *fname = "\\lockt1.lck";
1216 uint16_t fnum1, fnum2, fnum3;
1218 unsigned lock_timeout;
1221 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1224 cli_sockopt(cli1, sockops);
1225 cli_sockopt(cli2, sockops);
1227 printf("starting locktest1\n");
1229 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1231 status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
1233 if (!NT_STATUS_IS_OK(status)) {
1234 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
1238 status = cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum2);
1239 if (!NT_STATUS_IS_OK(status)) {
1240 printf("open2 of %s failed (%s)\n", fname, nt_errstr(status));
1244 status = cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum3);
1245 if (!NT_STATUS_IS_OK(status)) {
1246 printf("open3 of %s failed (%s)\n", fname, nt_errstr(status));
1250 status = cli_lock32(cli1, fnum1, 0, 4, 0, WRITE_LOCK);
1251 if (!NT_STATUS_IS_OK(status)) {
1252 printf("lock1 failed (%s)\n", nt_errstr(status));
1256 status = cli_lock32(cli2, fnum3, 0, 4, 0, WRITE_LOCK);
1257 if (NT_STATUS_IS_OK(status)) {
1258 printf("lock2 succeeded! This is a locking bug\n");
1261 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1262 NT_STATUS_LOCK_NOT_GRANTED)) {
1267 lock_timeout = (1 + (random() % 20));
1268 printf("Testing lock timeout with timeout=%u\n", lock_timeout);
1270 status = cli_lock32(cli2, fnum3, 0, 4, lock_timeout * 1000, WRITE_LOCK);
1271 if (NT_STATUS_IS_OK(status)) {
1272 printf("lock3 succeeded! This is a locking bug\n");
1275 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1276 NT_STATUS_FILE_LOCK_CONFLICT)) {
1282 if (ABS(t2 - t1) < lock_timeout-1) {
1283 printf("error: This server appears not to support timed lock requests\n");
1286 printf("server slept for %u seconds for a %u second timeout\n",
1287 (unsigned int)(t2-t1), lock_timeout);
1289 status = cli_close(cli1, fnum2);
1290 if (!NT_STATUS_IS_OK(status)) {
1291 printf("close1 failed (%s)\n", nt_errstr(status));
1295 status = cli_lock32(cli2, fnum3, 0, 4, 0, WRITE_LOCK);
1296 if (NT_STATUS_IS_OK(status)) {
1297 printf("lock4 succeeded! This is a locking bug\n");
1300 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1301 NT_STATUS_FILE_LOCK_CONFLICT)) {
1306 status = cli_close(cli1, fnum1);
1307 if (!NT_STATUS_IS_OK(status)) {
1308 printf("close2 failed (%s)\n", nt_errstr(status));
1312 status = cli_close(cli2, fnum3);
1313 if (!NT_STATUS_IS_OK(status)) {
1314 printf("close3 failed (%s)\n", nt_errstr(status));
1318 status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1319 if (!NT_STATUS_IS_OK(status)) {
1320 printf("unlink failed (%s)\n", nt_errstr(status));
1325 if (!torture_close_connection(cli1)) {
1329 if (!torture_close_connection(cli2)) {
1333 printf("Passed locktest1\n");
1338 this checks to see if a secondary tconx can use open files from an
1341 static bool run_tcon_test(int dummy)
1343 static struct cli_state *cli;
1344 const char *fname = "\\tcontest.tmp";
1346 uint16 cnum1, cnum2, cnum3;
1347 uint16 vuid1, vuid2;
1352 memset(buf, '\0', sizeof(buf));
1354 if (!torture_open_connection(&cli, 0)) {
1357 cli_sockopt(cli, sockops);
1359 printf("starting tcontest\n");
1361 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1363 status = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
1364 if (!NT_STATUS_IS_OK(status)) {
1365 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
1369 cnum1 = cli_state_get_tid(cli);
1370 vuid1 = cli_state_get_uid(cli);
1372 status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
1373 if (!NT_STATUS_IS_OK(status)) {
1374 printf("initial write failed (%s)", nt_errstr(status));
1378 status = cli_tcon_andx(cli, share, "?????",
1379 password, strlen(password)+1);
1380 if (!NT_STATUS_IS_OK(status)) {
1381 printf("%s refused 2nd tree connect (%s)\n", host,
1387 cnum2 = cli_state_get_tid(cli);
1388 cnum3 = MAX(cnum1, cnum2) + 1; /* any invalid number */
1389 vuid2 = cli_state_get_uid(cli) + 1;
1391 /* try a write with the wrong tid */
1392 cli_state_set_tid(cli, cnum2);
1394 status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
1395 if (NT_STATUS_IS_OK(status)) {
1396 printf("* server allows write with wrong TID\n");
1399 printf("server fails write with wrong TID : %s\n",
1404 /* try a write with an invalid tid */
1405 cli_state_set_tid(cli, cnum3);
1407 status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
1408 if (NT_STATUS_IS_OK(status)) {
1409 printf("* server allows write with invalid TID\n");
1412 printf("server fails write with invalid TID : %s\n",
1416 /* try a write with an invalid vuid */
1417 cli_state_set_uid(cli, vuid2);
1418 cli_state_set_tid(cli, cnum1);
1420 status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
1421 if (NT_STATUS_IS_OK(status)) {
1422 printf("* server allows write with invalid VUID\n");
1425 printf("server fails write with invalid VUID : %s\n",
1429 cli_state_set_tid(cli, cnum1);
1430 cli_state_set_uid(cli, vuid1);
1432 status = cli_close(cli, fnum1);
1433 if (!NT_STATUS_IS_OK(status)) {
1434 printf("close failed (%s)\n", nt_errstr(status));
1438 cli_state_set_tid(cli, cnum2);
1440 status = cli_tdis(cli);
1441 if (!NT_STATUS_IS_OK(status)) {
1442 printf("secondary tdis failed (%s)\n", nt_errstr(status));
1446 cli_state_set_tid(cli, cnum1);
1448 if (!torture_close_connection(cli)) {
1457 checks for old style tcon support
1459 static bool run_tcon2_test(int dummy)
1461 static struct cli_state *cli;
1462 uint16 cnum, max_xmit;
1466 if (!torture_open_connection(&cli, 0)) {
1469 cli_sockopt(cli, sockops);
1471 printf("starting tcon2 test\n");
1473 if (asprintf(&service, "\\\\%s\\%s", host, share) == -1) {
1477 status = cli_raw_tcon(cli, service, password, "?????", &max_xmit, &cnum);
1481 if (!NT_STATUS_IS_OK(status)) {
1482 printf("tcon2 failed : %s\n", nt_errstr(status));
1484 printf("tcon OK : max_xmit=%d cnum=%d\n",
1485 (int)max_xmit, (int)cnum);
1488 if (!torture_close_connection(cli)) {
1492 printf("Passed tcon2 test\n");
1496 static bool tcon_devtest(struct cli_state *cli,
1497 const char *myshare, const char *devtype,
1498 const char *return_devtype,
1499 NTSTATUS expected_error)
1504 status = cli_tcon_andx(cli, myshare, devtype,
1505 password, strlen(password)+1);
1507 if (NT_STATUS_IS_OK(expected_error)) {
1508 if (NT_STATUS_IS_OK(status)) {
1509 if (strcmp(cli->dev, return_devtype) == 0) {
1512 printf("tconX to share %s with type %s "
1513 "succeeded but returned the wrong "
1514 "device type (got [%s] but should have got [%s])\n",
1515 myshare, devtype, cli->dev, return_devtype);
1519 printf("tconX to share %s with type %s "
1520 "should have succeeded but failed\n",
1526 if (NT_STATUS_IS_OK(status)) {
1527 printf("tconx to share %s with type %s "
1528 "should have failed but succeeded\n",
1532 if (NT_STATUS_EQUAL(cli_nt_error(cli),
1536 printf("Returned unexpected error\n");
1545 checks for correct tconX support
1547 static bool run_tcon_devtype_test(int dummy)
1549 static struct cli_state *cli1 = NULL;
1554 status = cli_full_connection(&cli1, myname,
1555 host, NULL, port_to_use,
1557 username, workgroup,
1558 password, flags, signing_state);
1560 if (!NT_STATUS_IS_OK(status)) {
1561 printf("could not open connection\n");
1565 if (!tcon_devtest(cli1, "IPC$", "A:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1568 if (!tcon_devtest(cli1, "IPC$", "?????", "IPC", NT_STATUS_OK))
1571 if (!tcon_devtest(cli1, "IPC$", "LPT:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1574 if (!tcon_devtest(cli1, "IPC$", "IPC", "IPC", NT_STATUS_OK))
1577 if (!tcon_devtest(cli1, "IPC$", "FOOBA", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1580 if (!tcon_devtest(cli1, share, "A:", "A:", NT_STATUS_OK))
1583 if (!tcon_devtest(cli1, share, "?????", "A:", NT_STATUS_OK))
1586 if (!tcon_devtest(cli1, share, "LPT:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1589 if (!tcon_devtest(cli1, share, "IPC", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1592 if (!tcon_devtest(cli1, share, "FOOBA", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1598 printf("Passed tcondevtest\n");
1605 This test checks that
1607 1) the server supports multiple locking contexts on the one SMB
1608 connection, distinguished by PID.
1610 2) the server correctly fails overlapping locks made by the same PID (this
1611 goes against POSIX behaviour, which is why it is tricky to implement)
1613 3) the server denies unlock requests by an incorrect client PID
1615 static bool run_locktest2(int dummy)
1617 static struct cli_state *cli;
1618 const char *fname = "\\lockt2.lck";
1619 uint16_t fnum1, fnum2, fnum3;
1620 bool correct = True;
1623 if (!torture_open_connection(&cli, 0)) {
1627 cli_sockopt(cli, sockops);
1629 printf("starting locktest2\n");
1631 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1635 status = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
1636 if (!NT_STATUS_IS_OK(status)) {
1637 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
1641 status = cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum2);
1642 if (!NT_STATUS_IS_OK(status)) {
1643 printf("open2 of %s failed (%s)\n", fname, nt_errstr(status));
1649 status = cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum3);
1650 if (!NT_STATUS_IS_OK(status)) {
1651 printf("open3 of %s failed (%s)\n", fname, nt_errstr(status));
1657 status = cli_lock32(cli, fnum1, 0, 4, 0, WRITE_LOCK);
1658 if (!NT_STATUS_IS_OK(status)) {
1659 printf("lock1 failed (%s)\n", nt_errstr(status));
1663 status = cli_lock32(cli, fnum1, 0, 4, 0, WRITE_LOCK);
1664 if (NT_STATUS_IS_OK(status)) {
1665 printf("WRITE lock1 succeeded! This is a locking bug\n");
1668 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1669 NT_STATUS_LOCK_NOT_GRANTED)) {
1674 status = cli_lock32(cli, fnum2, 0, 4, 0, WRITE_LOCK);
1675 if (NT_STATUS_IS_OK(status)) {
1676 printf("WRITE lock2 succeeded! This is a locking bug\n");
1679 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1680 NT_STATUS_LOCK_NOT_GRANTED)) {
1685 status = cli_lock32(cli, fnum2, 0, 4, 0, READ_LOCK);
1686 if (NT_STATUS_IS_OK(status)) {
1687 printf("READ lock2 succeeded! This is a locking bug\n");
1690 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1691 NT_STATUS_FILE_LOCK_CONFLICT)) {
1696 status = cli_lock32(cli, fnum1, 100, 4, 0, WRITE_LOCK);
1697 if (!NT_STATUS_IS_OK(status)) {
1698 printf("lock at 100 failed (%s)\n", nt_errstr(status));
1701 if (NT_STATUS_IS_OK(cli_unlock(cli, fnum1, 100, 4))) {
1702 printf("unlock at 100 succeeded! This is a locking bug\n");
1706 status = cli_unlock(cli, fnum1, 0, 4);
1707 if (NT_STATUS_IS_OK(status)) {
1708 printf("unlock1 succeeded! This is a locking bug\n");
1711 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1712 NT_STATUS_RANGE_NOT_LOCKED)) {
1717 status = cli_unlock(cli, fnum1, 0, 8);
1718 if (NT_STATUS_IS_OK(status)) {
1719 printf("unlock2 succeeded! This is a locking bug\n");
1722 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1723 NT_STATUS_RANGE_NOT_LOCKED)) {
1728 status = cli_lock32(cli, fnum3, 0, 4, 0, WRITE_LOCK);
1729 if (NT_STATUS_IS_OK(status)) {
1730 printf("lock3 succeeded! This is a locking bug\n");
1733 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1734 NT_STATUS_LOCK_NOT_GRANTED)) {
1741 status = cli_close(cli, fnum1);
1742 if (!NT_STATUS_IS_OK(status)) {
1743 printf("close1 failed (%s)\n", nt_errstr(status));
1747 status = cli_close(cli, fnum2);
1748 if (!NT_STATUS_IS_OK(status)) {
1749 printf("close2 failed (%s)\n", nt_errstr(status));
1753 status = cli_close(cli, fnum3);
1754 if (!NT_STATUS_IS_OK(status)) {
1755 printf("close3 failed (%s)\n", nt_errstr(status));
1759 if (!torture_close_connection(cli)) {
1763 printf("locktest2 finished\n");
1770 This test checks that
1772 1) the server supports the full offset range in lock requests
1774 static bool run_locktest3(int dummy)
1776 static struct cli_state *cli1, *cli2;
1777 const char *fname = "\\lockt3.lck";
1778 uint16_t fnum1, fnum2;
1781 bool correct = True;
1784 #define NEXT_OFFSET offset += (~(uint32)0) / torture_numops
1786 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1789 cli_sockopt(cli1, sockops);
1790 cli_sockopt(cli2, sockops);
1792 printf("starting locktest3\n");
1794 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1796 status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
1798 if (!NT_STATUS_IS_OK(status)) {
1799 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
1803 status = cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
1804 if (!NT_STATUS_IS_OK(status)) {
1805 printf("open2 of %s failed (%s)\n", fname, nt_errstr(status));
1809 for (offset=i=0;i<torture_numops;i++) {
1812 status = cli_lock32(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK);
1813 if (!NT_STATUS_IS_OK(status)) {
1814 printf("lock1 %d failed (%s)\n",
1820 status = cli_lock32(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK);
1821 if (!NT_STATUS_IS_OK(status)) {
1822 printf("lock2 %d failed (%s)\n",
1829 for (offset=i=0;i<torture_numops;i++) {
1832 status = cli_lock32(cli1, fnum1, offset-2, 1, 0, WRITE_LOCK);
1833 if (NT_STATUS_IS_OK(status)) {
1834 printf("error: lock1 %d succeeded!\n", i);
1838 status = cli_lock32(cli2, fnum2, offset-1, 1, 0, WRITE_LOCK);
1839 if (NT_STATUS_IS_OK(status)) {
1840 printf("error: lock2 %d succeeded!\n", i);
1844 status = cli_lock32(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK);
1845 if (NT_STATUS_IS_OK(status)) {
1846 printf("error: lock3 %d succeeded!\n", i);
1850 status = cli_lock32(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK);
1851 if (NT_STATUS_IS_OK(status)) {
1852 printf("error: lock4 %d succeeded!\n", i);
1857 for (offset=i=0;i<torture_numops;i++) {
1860 status = cli_unlock(cli1, fnum1, offset-1, 1);
1861 if (!NT_STATUS_IS_OK(status)) {
1862 printf("unlock1 %d failed (%s)\n",
1868 status = cli_unlock(cli2, fnum2, offset-2, 1);
1869 if (!NT_STATUS_IS_OK(status)) {
1870 printf("unlock2 %d failed (%s)\n",
1877 status = cli_close(cli1, fnum1);
1878 if (!NT_STATUS_IS_OK(status)) {
1879 printf("close1 failed (%s)\n", nt_errstr(status));
1883 status = cli_close(cli2, fnum2);
1884 if (!NT_STATUS_IS_OK(status)) {
1885 printf("close2 failed (%s)\n", nt_errstr(status));
1889 status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1890 if (!NT_STATUS_IS_OK(status)) {
1891 printf("unlink failed (%s)\n", nt_errstr(status));
1895 if (!torture_close_connection(cli1)) {
1899 if (!torture_close_connection(cli2)) {
1903 printf("finished locktest3\n");
1908 static bool test_cli_read(struct cli_state *cli, uint16_t fnum,
1909 char *buf, off_t offset, size_t size,
1910 size_t *nread, size_t expect)
1915 status = cli_read(cli, fnum, buf, offset, size, &l_nread);
1917 if(!NT_STATUS_IS_OK(status)) {
1919 } else if (l_nread != expect) {
1930 #define EXPECTED(ret, v) if ((ret) != (v)) { \
1931 printf("** "); correct = False; \
1935 looks at overlapping locks
1937 static bool run_locktest4(int dummy)
1939 static struct cli_state *cli1, *cli2;
1940 const char *fname = "\\lockt4.lck";
1941 uint16_t fnum1, fnum2, f;
1944 bool correct = True;
1947 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1951 cli_sockopt(cli1, sockops);
1952 cli_sockopt(cli2, sockops);
1954 printf("starting locktest4\n");
1956 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1958 cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
1959 cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
1961 memset(buf, 0, sizeof(buf));
1963 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 0, sizeof(buf),
1965 if (!NT_STATUS_IS_OK(status)) {
1966 printf("Failed to create file: %s\n", nt_errstr(status));
1971 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) &&
1972 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 2, 4, 0, WRITE_LOCK));
1973 EXPECTED(ret, False);
1974 printf("the same process %s set overlapping write locks\n", ret?"can":"cannot");
1976 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 10, 4, 0, READ_LOCK)) &&
1977 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 12, 4, 0, READ_LOCK));
1978 EXPECTED(ret, True);
1979 printf("the same process %s set overlapping read locks\n", ret?"can":"cannot");
1981 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 20, 4, 0, WRITE_LOCK)) &&
1982 NT_STATUS_IS_OK(cli_lock32(cli2, fnum2, 22, 4, 0, WRITE_LOCK));
1983 EXPECTED(ret, False);
1984 printf("a different connection %s set overlapping write locks\n", ret?"can":"cannot");
1986 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 30, 4, 0, READ_LOCK)) &&
1987 NT_STATUS_IS_OK(cli_lock32(cli2, fnum2, 32, 4, 0, READ_LOCK));
1988 EXPECTED(ret, True);
1989 printf("a different connection %s set overlapping read locks\n", ret?"can":"cannot");
1991 ret = (cli_setpid(cli1, 1),
1992 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 40, 4, 0, WRITE_LOCK))) &&
1993 (cli_setpid(cli1, 2),
1994 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 42, 4, 0, WRITE_LOCK)));
1995 EXPECTED(ret, False);
1996 printf("a different pid %s set overlapping write locks\n", ret?"can":"cannot");
1998 ret = (cli_setpid(cli1, 1),
1999 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 50, 4, 0, READ_LOCK))) &&
2000 (cli_setpid(cli1, 2),
2001 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 52, 4, 0, READ_LOCK)));
2002 EXPECTED(ret, True);
2003 printf("a different pid %s set overlapping read locks\n", ret?"can":"cannot");
2005 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 60, 4, 0, READ_LOCK)) &&
2006 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 60, 4, 0, READ_LOCK));
2007 EXPECTED(ret, True);
2008 printf("the same process %s set the same read lock twice\n", ret?"can":"cannot");
2010 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 70, 4, 0, WRITE_LOCK)) &&
2011 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 70, 4, 0, WRITE_LOCK));
2012 EXPECTED(ret, False);
2013 printf("the same process %s set the same write lock twice\n", ret?"can":"cannot");
2015 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 80, 4, 0, READ_LOCK)) &&
2016 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 80, 4, 0, WRITE_LOCK));
2017 EXPECTED(ret, False);
2018 printf("the same process %s overlay a read lock with a write lock\n", ret?"can":"cannot");
2020 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 90, 4, 0, WRITE_LOCK)) &&
2021 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 90, 4, 0, READ_LOCK));
2022 EXPECTED(ret, True);
2023 printf("the same process %s overlay a write lock with a read lock\n", ret?"can":"cannot");
2025 ret = (cli_setpid(cli1, 1),
2026 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 100, 4, 0, WRITE_LOCK))) &&
2027 (cli_setpid(cli1, 2),
2028 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 100, 4, 0, READ_LOCK)));
2029 EXPECTED(ret, False);
2030 printf("a different pid %s overlay a write lock with a read lock\n", ret?"can":"cannot");
2032 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 110, 4, 0, READ_LOCK)) &&
2033 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 112, 4, 0, READ_LOCK)) &&
2034 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 110, 6));
2035 EXPECTED(ret, False);
2036 printf("the same process %s coalesce read locks\n", ret?"can":"cannot");
2039 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 120, 4, 0, WRITE_LOCK)) &&
2040 test_cli_read(cli2, fnum2, buf, 120, 4, NULL, 4);
2041 EXPECTED(ret, False);
2042 printf("this server %s strict write locking\n", ret?"doesn't do":"does");
2044 status = cli_lock32(cli1, fnum1, 130, 4, 0, READ_LOCK);
2045 ret = NT_STATUS_IS_OK(status);
2047 status = cli_writeall(cli2, fnum2, 0, (uint8_t *)buf, 130, 4,
2049 ret = NT_STATUS_IS_OK(status);
2051 EXPECTED(ret, False);
2052 printf("this server %s strict read locking\n", ret?"doesn't do":"does");
2055 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 140, 4, 0, READ_LOCK)) &&
2056 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 140, 4, 0, READ_LOCK)) &&
2057 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 140, 4)) &&
2058 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 140, 4));
2059 EXPECTED(ret, True);
2060 printf("this server %s do recursive read locking\n", ret?"does":"doesn't");
2063 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 150, 4, 0, WRITE_LOCK)) &&
2064 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 150, 4, 0, READ_LOCK)) &&
2065 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 150, 4)) &&
2066 test_cli_read(cli2, fnum2, buf, 150, 4, NULL, 4) &&
2067 !(NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf,
2069 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 150, 4));
2070 EXPECTED(ret, True);
2071 printf("this server %s do recursive lock overlays\n", ret?"does":"doesn't");
2073 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 160, 4, 0, READ_LOCK)) &&
2074 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 160, 4)) &&
2075 NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf,
2077 test_cli_read(cli2, fnum2, buf, 160, 4, NULL, 4);
2078 EXPECTED(ret, True);
2079 printf("the same process %s remove a read lock using write locking\n", ret?"can":"cannot");
2081 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 170, 4, 0, WRITE_LOCK)) &&
2082 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 170, 4)) &&
2083 NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf,
2085 test_cli_read(cli2, fnum2, buf, 170, 4, NULL, 4);
2086 EXPECTED(ret, True);
2087 printf("the same process %s remove a write lock using read locking\n", ret?"can":"cannot");
2089 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 190, 4, 0, WRITE_LOCK)) &&
2090 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 190, 4, 0, READ_LOCK)) &&
2091 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 190, 4)) &&
2092 !NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf,
2094 test_cli_read(cli2, fnum2, buf, 190, 4, NULL, 4);
2095 EXPECTED(ret, True);
2096 printf("the same process %s remove the first lock first\n", ret?"does":"doesn't");
2098 cli_close(cli1, fnum1);
2099 cli_close(cli2, fnum2);
2100 cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
2101 cli_open(cli1, fname, O_RDWR, DENY_NONE, &f);
2102 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 8, 0, READ_LOCK)) &&
2103 NT_STATUS_IS_OK(cli_lock32(cli1, f, 0, 1, 0, READ_LOCK)) &&
2104 NT_STATUS_IS_OK(cli_close(cli1, fnum1)) &&
2105 NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1)) &&
2106 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 7, 1, 0, WRITE_LOCK));
2108 cli_close(cli1, fnum1);
2109 EXPECTED(ret, True);
2110 printf("the server %s have the NT byte range lock bug\n", !ret?"does":"doesn't");
2113 cli_close(cli1, fnum1);
2114 cli_close(cli2, fnum2);
2115 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2116 torture_close_connection(cli1);
2117 torture_close_connection(cli2);
2119 printf("finished locktest4\n");
2124 looks at lock upgrade/downgrade.
2126 static bool run_locktest5(int dummy)
2128 static struct cli_state *cli1, *cli2;
2129 const char *fname = "\\lockt5.lck";
2130 uint16_t fnum1, fnum2, fnum3;
2133 bool correct = True;
2136 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
2140 cli_sockopt(cli1, sockops);
2141 cli_sockopt(cli2, sockops);
2143 printf("starting locktest5\n");
2145 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2147 cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
2148 cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
2149 cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum3);
2151 memset(buf, 0, sizeof(buf));
2153 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 0, sizeof(buf),
2155 if (!NT_STATUS_IS_OK(status)) {
2156 printf("Failed to create file: %s\n", nt_errstr(status));
2161 /* Check for NT bug... */
2162 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 8, 0, READ_LOCK)) &&
2163 NT_STATUS_IS_OK(cli_lock32(cli1, fnum3, 0, 1, 0, READ_LOCK));
2164 cli_close(cli1, fnum1);
2165 cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
2166 status = cli_lock32(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
2167 ret = NT_STATUS_IS_OK(status);
2168 EXPECTED(ret, True);
2169 printf("this server %s the NT locking bug\n", ret ? "doesn't have" : "has");
2170 cli_close(cli1, fnum1);
2171 cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
2172 cli_unlock(cli1, fnum3, 0, 1);
2174 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) &&
2175 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 1, 1, 0, READ_LOCK));
2176 EXPECTED(ret, True);
2177 printf("the same process %s overlay a write with a read lock\n", ret?"can":"cannot");
2179 status = cli_lock32(cli2, fnum2, 0, 4, 0, READ_LOCK);
2180 ret = NT_STATUS_IS_OK(status);
2181 EXPECTED(ret, False);
2183 printf("a different processs %s get a read lock on the first process lock stack\n", ret?"can":"cannot");
2185 /* Unlock the process 2 lock. */
2186 cli_unlock(cli2, fnum2, 0, 4);
2188 status = cli_lock32(cli1, fnum3, 0, 4, 0, READ_LOCK);
2189 ret = NT_STATUS_IS_OK(status);
2190 EXPECTED(ret, False);
2192 printf("the same processs on a different fnum %s get a read lock\n", ret?"can":"cannot");
2194 /* Unlock the process 1 fnum3 lock. */
2195 cli_unlock(cli1, fnum3, 0, 4);
2197 /* Stack 2 more locks here. */
2198 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 4, 0, READ_LOCK)) &&
2199 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 4, 0, READ_LOCK));
2201 EXPECTED(ret, True);
2202 printf("the same process %s stack read locks\n", ret?"can":"cannot");
2204 /* Unlock the first process lock, then check this was the WRITE lock that was
2207 ret = NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 0, 4)) &&
2208 NT_STATUS_IS_OK(cli_lock32(cli2, fnum2, 0, 4, 0, READ_LOCK));
2210 EXPECTED(ret, True);
2211 printf("the first unlock removes the %s lock\n", ret?"WRITE":"READ");
2213 /* Unlock the process 2 lock. */
2214 cli_unlock(cli2, fnum2, 0, 4);
2216 /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */
2218 ret = NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 1, 1)) &&
2219 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 0, 4)) &&
2220 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 0, 4));
2222 EXPECTED(ret, True);
2223 printf("the same process %s unlock the stack of 4 locks\n", ret?"can":"cannot");
2225 /* Ensure the next unlock fails. */
2226 ret = NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 0, 4));
2227 EXPECTED(ret, False);
2228 printf("the same process %s count the lock stack\n", !ret?"can":"cannot");
2230 /* Ensure connection 2 can get a write lock. */
2231 status = cli_lock32(cli2, fnum2, 0, 4, 0, WRITE_LOCK);
2232 ret = NT_STATUS_IS_OK(status);
2233 EXPECTED(ret, True);
2235 printf("a different processs %s get a write lock on the unlocked stack\n", ret?"can":"cannot");
2239 cli_close(cli1, fnum1);
2240 cli_close(cli2, fnum2);
2241 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2242 if (!torture_close_connection(cli1)) {
2245 if (!torture_close_connection(cli2)) {
2249 printf("finished locktest5\n");
2255 tries the unusual lockingX locktype bits
2257 static bool run_locktest6(int dummy)
2259 static struct cli_state *cli;
2260 const char *fname[1] = { "\\lock6.txt" };
2265 if (!torture_open_connection(&cli, 0)) {
2269 cli_sockopt(cli, sockops);
2271 printf("starting locktest6\n");
2274 printf("Testing %s\n", fname[i]);
2276 cli_unlink(cli, fname[i], FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2278 cli_open(cli, fname[i], O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
2279 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE);
2280 cli_close(cli, fnum);
2281 printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status));
2283 cli_open(cli, fname[i], O_RDWR, DENY_NONE, &fnum);
2284 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK);
2285 cli_close(cli, fnum);
2286 printf("CANCEL_LOCK gave %s\n", nt_errstr(status));
2288 cli_unlink(cli, fname[i], FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2291 torture_close_connection(cli);
2293 printf("finished locktest6\n");
2297 static bool run_locktest7(int dummy)
2299 struct cli_state *cli1;
2300 const char *fname = "\\lockt7.lck";
2303 bool correct = False;
2307 if (!torture_open_connection(&cli1, 0)) {
2311 cli_sockopt(cli1, sockops);
2313 printf("starting locktest7\n");
2315 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2317 cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
2319 memset(buf, 0, sizeof(buf));
2321 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 0, sizeof(buf),
2323 if (!NT_STATUS_IS_OK(status)) {
2324 printf("Failed to create file: %s\n", nt_errstr(status));
2328 cli_setpid(cli1, 1);
2330 status = cli_lock32(cli1, fnum1, 130, 4, 0, READ_LOCK);
2331 if (!NT_STATUS_IS_OK(status)) {
2332 printf("Unable to apply read lock on range 130:4, "
2333 "error was %s\n", nt_errstr(status));
2336 printf("pid1 successfully locked range 130:4 for READ\n");
2339 status = cli_read(cli1, fnum1, buf, 130, 4, &nread);
2340 if (!NT_STATUS_IS_OK(status)) {
2341 printf("pid1 unable to read the range 130:4, error was %s\n",
2344 } else if (nread != 4) {
2345 printf("pid1 unable to read the range 130:4, "
2346 "recv %ld req %d\n", (unsigned long)nread, 4);
2349 printf("pid1 successfully read the range 130:4\n");
2352 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
2353 if (!NT_STATUS_IS_OK(status)) {
2354 printf("pid1 unable to write to the range 130:4, error was "
2355 "%s\n", nt_errstr(status));
2356 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_LOCK_CONFLICT)) {
2357 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2361 printf("pid1 successfully wrote to the range 130:4 (should be denied)\n");
2365 cli_setpid(cli1, 2);
2367 status = cli_read(cli1, fnum1, buf, 130, 4, &nread);
2368 if (!NT_STATUS_IS_OK(status)) {
2369 printf("pid2 unable to read the range 130:4, error was %s\n",
2372 } else if (nread != 4) {
2373 printf("pid2 unable to read the range 130:4, "
2374 "recv %ld req %d\n", (unsigned long)nread, 4);
2377 printf("pid2 successfully read the range 130:4\n");
2380 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
2381 if (!NT_STATUS_IS_OK(status)) {
2382 printf("pid2 unable to write to the range 130:4, error was "
2383 "%s\n", nt_errstr(status));
2384 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_LOCK_CONFLICT)) {
2385 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2389 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
2393 cli_setpid(cli1, 1);
2394 cli_unlock(cli1, fnum1, 130, 4);
2396 status = cli_lock32(cli1, fnum1, 130, 4, 0, WRITE_LOCK);
2397 if (!NT_STATUS_IS_OK(status)) {
2398 printf("Unable to apply write lock on range 130:4, error was %s\n", nt_errstr(status));
2401 printf("pid1 successfully locked range 130:4 for WRITE\n");
2404 status = cli_read(cli1, fnum1, buf, 130, 4, &nread);
2405 if (!NT_STATUS_IS_OK(status)) {
2406 printf("pid1 unable to read the range 130:4, error was %s\n",
2409 } else if (nread != 4) {
2410 printf("pid1 unable to read the range 130:4, "
2411 "recv %ld req %d\n", (unsigned long)nread, 4);
2414 printf("pid1 successfully read the range 130:4\n");
2417 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
2418 if (!NT_STATUS_IS_OK(status)) {
2419 printf("pid1 unable to write to the range 130:4, error was "
2420 "%s\n", nt_errstr(status));
2423 printf("pid1 successfully wrote to the range 130:4\n");
2426 cli_setpid(cli1, 2);
2428 status = cli_read(cli1, fnum1, buf, 130, 4, &nread);
2429 if (!NT_STATUS_IS_OK(status)) {
2430 printf("pid2 unable to read the range 130:4, error was "
2431 "%s\n", nt_errstr(status));
2432 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_LOCK_CONFLICT)) {
2433 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2437 printf("pid2 successfully read the range 130:4 (should be denied) recv %ld\n",
2438 (unsigned long)nread);
2442 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
2443 if (!NT_STATUS_IS_OK(status)) {
2444 printf("pid2 unable to write to the range 130:4, error was "
2445 "%s\n", nt_errstr(status));
2446 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_LOCK_CONFLICT)) {
2447 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2451 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
2455 cli_unlock(cli1, fnum1, 130, 0);
2459 cli_close(cli1, fnum1);
2460 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2461 torture_close_connection(cli1);
2463 printf("finished locktest7\n");
2468 * This demonstrates a problem with our use of GPFS share modes: A file
2469 * descriptor sitting in the pending close queue holding a GPFS share mode
2470 * blocks opening a file another time. Happens with Word 2007 temp files.
2471 * With "posix locking = yes" and "gpfs:sharemodes = yes" enabled, the third
2472 * open is denied with NT_STATUS_SHARING_VIOLATION.
2475 static bool run_locktest8(int dummy)
2477 struct cli_state *cli1;
2478 const char *fname = "\\lockt8.lck";
2479 uint16_t fnum1, fnum2;
2481 bool correct = False;
2484 if (!torture_open_connection(&cli1, 0)) {
2488 cli_sockopt(cli1, sockops);
2490 printf("starting locktest8\n");
2492 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2494 status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_WRITE,
2496 if (!NT_STATUS_IS_OK(status)) {
2497 d_fprintf(stderr, "cli_open returned %s\n", nt_errstr(status));
2501 memset(buf, 0, sizeof(buf));
2503 status = cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum2);
2504 if (!NT_STATUS_IS_OK(status)) {
2505 d_fprintf(stderr, "cli_open second time returned %s\n",
2510 status = cli_lock32(cli1, fnum2, 1, 1, 0, READ_LOCK);
2511 if (!NT_STATUS_IS_OK(status)) {
2512 printf("Unable to apply read lock on range 1:1, error was "
2513 "%s\n", nt_errstr(status));
2517 status = cli_close(cli1, fnum1);
2518 if (!NT_STATUS_IS_OK(status)) {
2519 d_fprintf(stderr, "cli_close(fnum1) %s\n", nt_errstr(status));
2523 status = cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
2524 if (!NT_STATUS_IS_OK(status)) {
2525 d_fprintf(stderr, "cli_open third time returned %s\n",
2533 cli_close(cli1, fnum1);
2534 cli_close(cli1, fnum2);
2535 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2536 torture_close_connection(cli1);
2538 printf("finished locktest8\n");
2543 * This test is designed to be run in conjunction with
2544 * external NFS or POSIX locks taken in the filesystem.
2545 * It checks that the smbd server will block until the
2546 * lock is released and then acquire it. JRA.
2549 static bool got_alarm;
2550 static struct cli_state *alarm_cli;
2552 static void alarm_handler(int dummy)
2557 static void alarm_handler_parent(int dummy)
2559 cli_state_disconnect(alarm_cli);
2562 static void do_local_lock(int read_fd, int write_fd)
2567 const char *local_pathname = NULL;
2570 local_pathname = talloc_asprintf(talloc_tos(),
2571 "%s/lockt9.lck", local_path);
2572 if (!local_pathname) {
2573 printf("child: alloc fail\n");
2577 unlink(local_pathname);
2578 fd = open(local_pathname, O_RDWR|O_CREAT, 0666);
2580 printf("child: open of %s failed %s.\n",
2581 local_pathname, strerror(errno));
2585 /* Now take a fcntl lock. */
2586 lock.l_type = F_WRLCK;
2587 lock.l_whence = SEEK_SET;
2590 lock.l_pid = getpid();
2592 ret = fcntl(fd,F_SETLK,&lock);
2594 printf("child: failed to get lock 0:4 on file %s. Error %s\n",
2595 local_pathname, strerror(errno));
2598 printf("child: got lock 0:4 on file %s.\n",
2603 CatchSignal(SIGALRM, alarm_handler);
2605 /* Signal the parent. */
2606 if (write(write_fd, &c, 1) != 1) {
2607 printf("child: start signal fail %s.\n",
2614 /* Wait for the parent to be ready. */
2615 if (read(read_fd, &c, 1) != 1) {
2616 printf("child: reply signal fail %s.\n",
2624 printf("child: released lock 0:4 on file %s.\n",
2630 static bool run_locktest9(int dummy)
2632 struct cli_state *cli1;
2633 const char *fname = "\\lockt9.lck";
2635 bool correct = False;
2636 int pipe_in[2], pipe_out[2];
2640 struct timeval start;
2644 printf("starting locktest9\n");
2646 if (local_path == NULL) {
2647 d_fprintf(stderr, "locktest9 must be given a local path via -l <localpath>\n");
2651 if (pipe(pipe_in) == -1 || pipe(pipe_out) == -1) {
2656 if (child_pid == -1) {
2660 if (child_pid == 0) {
2662 do_local_lock(pipe_out[0], pipe_in[1]);
2672 ret = read(pipe_in[0], &c, 1);
2674 d_fprintf(stderr, "failed to read start signal from child. %s\n",
2679 if (!torture_open_connection(&cli1, 0)) {
2683 cli_sockopt(cli1, sockops);
2685 status = cli_open(cli1, fname, O_RDWR, DENY_NONE,
2687 if (!NT_STATUS_IS_OK(status)) {
2688 d_fprintf(stderr, "cli_open returned %s\n", nt_errstr(status));
2692 /* Ensure the child has the lock. */
2693 status = cli_lock32(cli1, fnum, 0, 4, 0, WRITE_LOCK);
2694 if (NT_STATUS_IS_OK(status)) {
2695 d_fprintf(stderr, "Got the lock on range 0:4 - this should not happen !\n");
2698 d_printf("Child has the lock.\n");
2701 /* Tell the child to wait 5 seconds then exit. */
2702 ret = write(pipe_out[1], &c, 1);
2704 d_fprintf(stderr, "failed to send exit signal to child. %s\n",
2709 /* Wait 20 seconds for the lock. */
2711 CatchSignal(SIGALRM, alarm_handler_parent);
2714 start = timeval_current();
2716 status = cli_lock32(cli1, fnum, 0, 4, -1, WRITE_LOCK);
2717 if (!NT_STATUS_IS_OK(status)) {
2718 d_fprintf(stderr, "Unable to apply write lock on range 0:4, error was "
2719 "%s\n", nt_errstr(status));
2724 seconds = timeval_elapsed(&start);
2726 printf("Parent got the lock after %.2f seconds.\n",
2729 status = cli_close(cli1, fnum);
2730 if (!NT_STATUS_IS_OK(status)) {
2731 d_fprintf(stderr, "cli_close(fnum1) %s\n", nt_errstr(status));
2738 cli_close(cli1, fnum);
2739 torture_close_connection(cli1);
2743 printf("finished locktest9\n");
2748 test whether fnums and tids open on one VC are available on another (a major
2751 static bool run_fdpasstest(int dummy)
2753 struct cli_state *cli1, *cli2;
2754 const char *fname = "\\fdpass.tst";
2759 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
2762 cli_sockopt(cli1, sockops);
2763 cli_sockopt(cli2, sockops);
2765 printf("starting fdpasstest\n");
2767 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2769 status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
2771 if (!NT_STATUS_IS_OK(status)) {
2772 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
2776 status = cli_writeall(cli1, fnum1, 0, (const uint8_t *)"hello world\n", 0,
2778 if (!NT_STATUS_IS_OK(status)) {
2779 printf("write failed (%s)\n", nt_errstr(status));
2783 cli_state_set_uid(cli2, cli_state_get_uid(cli1));
2784 cli_state_set_tid(cli2, cli_state_get_tid(cli1));
2785 cli_setpid(cli2, cli_getpid(cli1));
2787 if (test_cli_read(cli2, fnum1, buf, 0, 13, NULL, 13)) {
2788 printf("read succeeded! nasty security hole [%s]\n", buf);
2792 cli_close(cli1, fnum1);
2793 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2795 torture_close_connection(cli1);
2796 torture_close_connection(cli2);
2798 printf("finished fdpasstest\n");
2802 static bool run_fdsesstest(int dummy)
2804 struct cli_state *cli;
2809 const char *fname = "\\fdsess.tst";
2810 const char *fname1 = "\\fdsess1.tst";
2817 if (!torture_open_connection(&cli, 0))
2819 cli_sockopt(cli, sockops);
2821 if (!torture_cli_session_setup2(cli, &new_vuid))
2824 saved_cnum = cli_state_get_tid(cli);
2825 if (!NT_STATUS_IS_OK(cli_tcon_andx(cli, share, "?????", "", 1)))
2827 new_cnum = cli_state_get_tid(cli);
2828 cli_state_set_tid(cli, saved_cnum);
2830 printf("starting fdsesstest\n");
2832 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2833 cli_unlink(cli, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2835 status = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
2836 if (!NT_STATUS_IS_OK(status)) {
2837 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
2841 status = cli_writeall(cli, fnum1, 0, (const uint8_t *)"hello world\n", 0, 13,
2843 if (!NT_STATUS_IS_OK(status)) {
2844 printf("write failed (%s)\n", nt_errstr(status));
2848 saved_vuid = cli_state_get_uid(cli);
2849 cli_state_set_uid(cli, new_vuid);
2851 if (test_cli_read(cli, fnum1, buf, 0, 13, NULL, 13)) {
2852 printf("read succeeded with different vuid! "
2853 "nasty security hole [%s]\n", buf);
2856 /* Try to open a file with different vuid, samba cnum. */
2857 if (NT_STATUS_IS_OK(cli_open(cli, fname1, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum2))) {
2858 printf("create with different vuid, same cnum succeeded.\n");
2859 cli_close(cli, fnum2);
2860 cli_unlink(cli, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2862 printf("create with different vuid, same cnum failed.\n");
2863 printf("This will cause problems with service clients.\n");
2867 cli_state_set_uid(cli, saved_vuid);
2869 /* Try with same vuid, different cnum. */
2870 cli_state_set_tid(cli, new_cnum);
2872 if (test_cli_read(cli, fnum1, buf, 0, 13, NULL, 13)) {
2873 printf("read succeeded with different cnum![%s]\n", buf);
2877 cli_state_set_tid(cli, saved_cnum);
2878 cli_close(cli, fnum1);
2879 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2881 torture_close_connection(cli);
2883 printf("finished fdsesstest\n");
2888 This test checks that
2890 1) the server does not allow an unlink on a file that is open
2892 static bool run_unlinktest(int dummy)
2894 struct cli_state *cli;
2895 const char *fname = "\\unlink.tst";
2897 bool correct = True;
2900 if (!torture_open_connection(&cli, 0)) {
2904 cli_sockopt(cli, sockops);
2906 printf("starting unlink test\n");
2908 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2912 status = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
2913 if (!NT_STATUS_IS_OK(status)) {
2914 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
2918 status = cli_unlink(cli, fname,
2919 FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2920 if (NT_STATUS_IS_OK(status)) {
2921 printf("error: server allowed unlink on an open file\n");
2924 correct = check_error(__LINE__, status, ERRDOS, ERRbadshare,
2925 NT_STATUS_SHARING_VIOLATION);
2928 cli_close(cli, fnum);
2929 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2931 if (!torture_close_connection(cli)) {
2935 printf("unlink test finished\n");
2942 test how many open files this server supports on the one socket
2944 static bool run_maxfidtest(int dummy)
2946 struct cli_state *cli;
2948 uint16_t fnums[0x11000];
2951 bool correct = True;
2957 printf("failed to connect\n");
2961 cli_sockopt(cli, sockops);
2963 for (i=0; i<0x11000; i++) {
2964 slprintf(fname,sizeof(fname)-1,"\\maxfid.%d.%d", i,(int)getpid());
2965 status = cli_open(cli, fname, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE,
2967 if (!NT_STATUS_IS_OK(status)) {
2968 printf("open of %s failed (%s)\n",
2969 fname, nt_errstr(status));
2970 printf("maximum fnum is %d\n", i);
2978 printf("cleaning up\n");
2980 slprintf(fname,sizeof(fname)-1,"\\maxfid.%d.%d", i,(int)getpid());
2981 cli_close(cli, fnums[i]);
2983 status = cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2984 if (!NT_STATUS_IS_OK(status)) {
2985 printf("unlink of %s failed (%s)\n",
2986 fname, nt_errstr(status));
2993 printf("maxfid test finished\n");
2994 if (!torture_close_connection(cli)) {
3000 /* generate a random buffer */
3001 static void rand_buf(char *buf, int len)
3004 *buf = (char)sys_random();
3009 /* send smb negprot commands, not reading the response */
3010 static bool run_negprot_nowait(int dummy)
3012 struct tevent_context *ev;
3014 struct cli_state *cli;
3015 bool correct = True;
3017 printf("starting negprot nowait test\n");
3019 ev = tevent_context_init(talloc_tos());
3024 if (!(cli = open_nbt_connection())) {
3029 for (i=0;i<50000;i++) {
3030 struct tevent_req *req;
3032 req = cli_negprot_send(ev, ev, cli);
3037 if (!tevent_req_poll(req, ev)) {
3038 d_fprintf(stderr, "tevent_req_poll failed: %s\n",
3046 if (torture_close_connection(cli)) {
3050 printf("finished negprot nowait test\n");
3055 /* send smb negprot commands, not reading the response */
3056 static bool run_bad_nbt_session(int dummy)
3058 struct nmb_name called, calling;
3059 struct sockaddr_storage ss;
3064 printf("starting bad nbt session test\n");
3066 make_nmb_name(&calling, myname, 0x0);
3067 make_nmb_name(&called , host, 0x20);
3069 if (!resolve_name(host, &ss, 0x20, true)) {
3070 d_fprintf(stderr, "Could not resolve name %s\n", host);
3074 status = open_socket_out(&ss, 139, 10000, &fd);
3075 if (!NT_STATUS_IS_OK(status)) {
3076 d_fprintf(stderr, "open_socket_out failed: %s\n",
3081 ret = cli_bad_session_request(fd, &calling, &called);
3084 d_fprintf(stderr, "open_socket_out failed: %s\n",
3089 printf("finished bad nbt session test\n");
3093 /* send random IPC commands */
3094 static bool run_randomipc(int dummy)
3096 char *rparam = NULL;
3098 unsigned int rdrcnt,rprcnt;
3100 int api, param_len, i;
3101 struct cli_state *cli;
3102 bool correct = True;
3105 printf("starting random ipc test\n");
3107 if (!torture_open_connection(&cli, 0)) {
3111 for (i=0;i<count;i++) {
3112 api = sys_random() % 500;
3113 param_len = (sys_random() % 64);
3115 rand_buf(param, param_len);
3120 param, param_len, 8,
3121 NULL, 0, BUFFER_SIZE,
3125 printf("%d/%d\r", i,count);
3128 printf("%d/%d\n", i, count);
3130 if (!torture_close_connection(cli)) {
3134 printf("finished random ipc test\n");
3141 static void browse_callback(const char *sname, uint32 stype,
3142 const char *comment, void *state)
3144 printf("\t%20.20s %08x %s\n", sname, stype, comment);
3150 This test checks the browse list code
3153 static bool run_browsetest(int dummy)
3155 static struct cli_state *cli;
3156 bool correct = True;
3158 printf("starting browse test\n");
3160 if (!torture_open_connection(&cli, 0)) {
3164 printf("domain list:\n");
3165 cli_NetServerEnum(cli, cli->server_domain,
3166 SV_TYPE_DOMAIN_ENUM,
3167 browse_callback, NULL);
3169 printf("machine list:\n");
3170 cli_NetServerEnum(cli, cli->server_domain,
3172 browse_callback, NULL);
3174 if (!torture_close_connection(cli)) {
3178 printf("browse test finished\n");
3186 This checks how the getatr calls works
3188 static bool run_attrtest(int dummy)
3190 struct cli_state *cli;
3193 const char *fname = "\\attrib123456789.tst";
3194 bool correct = True;
3197 printf("starting attrib test\n");
3199 if (!torture_open_connection(&cli, 0)) {
3203 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3204 cli_open(cli, fname,
3205 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
3206 cli_close(cli, fnum);
3208 status = cli_getatr(cli, fname, NULL, NULL, &t);
3209 if (!NT_STATUS_IS_OK(status)) {
3210 printf("getatr failed (%s)\n", nt_errstr(status));
3214 if (abs(t - time(NULL)) > 60*60*24*10) {
3215 printf("ERROR: SMBgetatr bug. time is %s",
3221 t2 = t-60*60*24; /* 1 day ago */
3223 status = cli_setatr(cli, fname, 0, t2);
3224 if (!NT_STATUS_IS_OK(status)) {
3225 printf("setatr failed (%s)\n", nt_errstr(status));
3229 status = cli_getatr(cli, fname, NULL, NULL, &t);
3230 if (!NT_STATUS_IS_OK(status)) {
3231 printf("getatr failed (%s)\n", nt_errstr(status));
3236 printf("ERROR: getatr/setatr bug. times are\n%s",
3238 printf("%s", ctime(&t2));
3242 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3244 if (!torture_close_connection(cli)) {
3248 printf("attrib test finished\n");
3255 This checks a couple of trans2 calls
3257 static bool run_trans2test(int dummy)
3259 struct cli_state *cli;
3262 time_t c_time, a_time, m_time;
3263 struct timespec c_time_ts, a_time_ts, m_time_ts, w_time_ts, m_time2_ts;
3264 const char *fname = "\\trans2.tst";
3265 const char *dname = "\\trans2";
3266 const char *fname2 = "\\trans2\\trans2.tst";
3268 bool correct = True;
3272 printf("starting trans2 test\n");
3274 if (!torture_open_connection(&cli, 0)) {
3278 status = cli_get_fs_attr_info(cli, &fs_attr);
3279 if (!NT_STATUS_IS_OK(status)) {
3280 printf("ERROR: cli_get_fs_attr_info returned %s\n",
3285 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3286 cli_open(cli, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
3287 status = cli_qfileinfo_basic(cli, fnum, NULL, &size, &c_time_ts,
3288 &a_time_ts, &w_time_ts, &m_time_ts, NULL);
3289 if (!NT_STATUS_IS_OK(status)) {
3290 printf("ERROR: qfileinfo failed (%s)\n", nt_errstr(status));
3294 status = cli_qfilename(cli, fnum, talloc_tos(), &pname);
3295 if (!NT_STATUS_IS_OK(status)) {
3296 printf("ERROR: qfilename failed (%s)\n", nt_errstr(status));
3300 if (strcmp(pname, fname)) {
3301 printf("qfilename gave different name? [%s] [%s]\n",
3306 cli_close(cli, fnum);
3310 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3311 status = cli_open(cli, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE,
3313 if (!NT_STATUS_IS_OK(status)) {
3314 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
3317 cli_close(cli, fnum);
3319 status = cli_qpathinfo1(cli, fname, &c_time, &a_time, &m_time, &size,
3321 if (!NT_STATUS_IS_OK(status)) {
3322 printf("ERROR: qpathinfo failed (%s)\n", nt_errstr(status));
3325 if (c_time != m_time) {
3326 printf("create time=%s", ctime(&c_time));
3327 printf("modify time=%s", ctime(&m_time));
3328 printf("This system appears to have sticky create times\n");
3330 if (a_time % (60*60) == 0) {
3331 printf("access time=%s", ctime(&a_time));
3332 printf("This system appears to set a midnight access time\n");
3336 if (abs(m_time - time(NULL)) > 60*60*24*7) {
3337 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
3343 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3344 cli_open(cli, fname,
3345 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
3346 cli_close(cli, fnum);
3347 status = cli_qpathinfo2(cli, fname, &c_time_ts, &a_time_ts, &w_time_ts,
3348 &m_time_ts, &size, NULL, NULL);
3349 if (!NT_STATUS_IS_OK(status)) {
3350 printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status));
3353 if (w_time_ts.tv_sec < 60*60*24*2) {
3354 printf("write time=%s", ctime(&w_time_ts.tv_sec));
3355 printf("This system appears to set a initial 0 write time\n");
3360 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3363 /* check if the server updates the directory modification time
3364 when creating a new file */
3365 status = cli_mkdir(cli, dname);
3366 if (!NT_STATUS_IS_OK(status)) {
3367 printf("ERROR: mkdir failed (%s)\n", nt_errstr(status));
3371 status = cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts,
3372 &w_time_ts, &m_time_ts, &size, NULL, NULL);
3373 if (!NT_STATUS_IS_OK(status)) {
3374 printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status));
3378 cli_open(cli, fname2,
3379 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
3380 cli_writeall(cli, fnum, 0, (uint8_t *)&fnum, 0, sizeof(fnum), NULL);
3381 cli_close(cli, fnum);
3382 status = cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts,
3383 &w_time_ts, &m_time2_ts, &size, NULL, NULL);
3384 if (!NT_STATUS_IS_OK(status)) {
3385 printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status));
3388 if (memcmp(&m_time_ts, &m_time2_ts, sizeof(struct timespec))
3390 printf("This system does not update directory modification times\n");
3394 cli_unlink(cli, fname2, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3395 cli_rmdir(cli, dname);
3397 if (!torture_close_connection(cli)) {
3401 printf("trans2 test finished\n");
3407 This checks new W2K calls.
3410 static NTSTATUS new_trans(struct cli_state *pcli, int fnum, int level)
3412 uint8_t *buf = NULL;
3416 status = cli_qfileinfo(talloc_tos(), pcli, fnum, level, 0,
3417 pcli->max_xmit, NULL, &buf, &len);
3418 if (!NT_STATUS_IS_OK(status)) {
3419 printf("ERROR: qfileinfo (%d) failed (%s)\n", level,
3422 printf("qfileinfo: level %d, len = %u\n", level, len);
3423 dump_data(0, (uint8 *)buf, len);
3430 static bool run_w2ktest(int dummy)
3432 struct cli_state *cli;
3434 const char *fname = "\\w2ktest\\w2k.tst";
3436 bool correct = True;
3438 printf("starting w2k test\n");
3440 if (!torture_open_connection(&cli, 0)) {
3444 cli_open(cli, fname,
3445 O_RDWR | O_CREAT , DENY_NONE, &fnum);
3447 for (level = 1004; level < 1040; level++) {
3448 new_trans(cli, fnum, level);
3451 cli_close(cli, fnum);
3453 if (!torture_close_connection(cli)) {
3457 printf("w2k test finished\n");
3464 this is a harness for some oplock tests
3466 static bool run_oplock1(int dummy)
3468 struct cli_state *cli1;
3469 const char *fname = "\\lockt1.lck";
3471 bool correct = True;
3474 printf("starting oplock test 1\n");
3476 if (!torture_open_connection(&cli1, 0)) {
3480 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3482 cli_sockopt(cli1, sockops);
3484 cli1->use_oplocks = True;
3486 status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
3488 if (!NT_STATUS_IS_OK(status)) {
3489 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
3493 cli1->use_oplocks = False;
3495 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3496 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3498 status = cli_close(cli1, fnum1);
3499 if (!NT_STATUS_IS_OK(status)) {
3500 printf("close2 failed (%s)\n", nt_errstr(status));
3504 status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3505 if (!NT_STATUS_IS_OK(status)) {
3506 printf("unlink failed (%s)\n", nt_errstr(status));
3510 if (!torture_close_connection(cli1)) {
3514 printf("finished oplock test 1\n");
3519 static bool run_oplock2(int dummy)
3521 struct cli_state *cli1, *cli2;
3522 const char *fname = "\\lockt2.lck";
3523 uint16_t fnum1, fnum2;
3524 int saved_use_oplocks = use_oplocks;
3526 bool correct = True;
3527 volatile bool *shared_correct;
3531 shared_correct = (volatile bool *)shm_setup(sizeof(bool));
3532 *shared_correct = True;
3534 use_level_II_oplocks = True;
3537 printf("starting oplock test 2\n");
3539 if (!torture_open_connection(&cli1, 0)) {
3540 use_level_II_oplocks = False;
3541 use_oplocks = saved_use_oplocks;
3545 cli1->use_oplocks = True;
3546 cli1->use_level_II_oplocks = True;
3548 if (!torture_open_connection(&cli2, 1)) {
3549 use_level_II_oplocks = False;
3550 use_oplocks = saved_use_oplocks;
3554 cli2->use_oplocks = True;
3555 cli2->use_level_II_oplocks = True;
3557 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3559 cli_sockopt(cli1, sockops);
3560 cli_sockopt(cli2, sockops);
3562 status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
3564 if (!NT_STATUS_IS_OK(status)) {
3565 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
3569 /* Don't need the globals any more. */
3570 use_level_II_oplocks = False;
3571 use_oplocks = saved_use_oplocks;
3575 status = cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
3576 if (!NT_STATUS_IS_OK(status)) {
3577 printf("second open of %s failed (%s)\n", fname, nt_errstr(status));
3578 *shared_correct = False;
3584 status = cli_close(cli2, fnum2);
3585 if (!NT_STATUS_IS_OK(status)) {
3586 printf("close2 failed (%s)\n", nt_errstr(status));
3587 *shared_correct = False;
3595 /* Ensure cli1 processes the break. Empty file should always return 0
3597 status = cli_read(cli1, fnum1, buf, 0, 4, &nread);
3598 if (!NT_STATUS_IS_OK(status)) {
3599 printf("read on fnum1 failed (%s)\n", nt_errstr(status));
3601 } else if (nread != 0) {
3602 printf("read on empty fnum1 failed. recv %ld expected %d\n",
3603 (unsigned long)nread, 0);
3607 /* Should now be at level II. */
3608 /* Test if sending a write locks causes a break to none. */
3609 status = cli_lock32(cli1, fnum1, 0, 4, 0, READ_LOCK);
3610 if (!NT_STATUS_IS_OK(status)) {
3611 printf("lock failed (%s)\n", nt_errstr(status));
3615 cli_unlock(cli1, fnum1, 0, 4);
3619 status = cli_lock32(cli1, fnum1, 0, 4, 0, WRITE_LOCK);
3620 if (!NT_STATUS_IS_OK(status)) {
3621 printf("lock failed (%s)\n", nt_errstr(status));
3625 cli_unlock(cli1, fnum1, 0, 4);
3629 cli_read(cli1, fnum1, buf, 0, 4, NULL);
3631 status = cli_close(cli1, fnum1);
3632 if (!NT_STATUS_IS_OK(status)) {
3633 printf("close1 failed (%s)\n", nt_errstr(status));
3639 status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3640 if (!NT_STATUS_IS_OK(status)) {
3641 printf("unlink failed (%s)\n", nt_errstr(status));
3645 if (!torture_close_connection(cli1)) {
3649 if (!*shared_correct) {
3653 printf("finished oplock test 2\n");
3658 struct oplock4_state {
3659 struct tevent_context *ev;
3660 struct cli_state *cli;
3665 static void oplock4_got_break(struct tevent_req *req);
3666 static void oplock4_got_open(struct tevent_req *req);
3668 static bool run_oplock4(int dummy)
3670 struct tevent_context *ev;
3671 struct cli_state *cli1, *cli2;
3672 struct tevent_req *oplock_req, *open_req;
3673 const char *fname = "\\lockt4.lck";
3674 const char *fname_ln = "\\lockt4_ln.lck";
3675 uint16_t fnum1, fnum2;
3676 int saved_use_oplocks = use_oplocks;
3678 bool correct = true;
3682 struct oplock4_state *state;
3684 printf("starting oplock test 4\n");
3686 if (!torture_open_connection(&cli1, 0)) {
3687 use_level_II_oplocks = false;
3688 use_oplocks = saved_use_oplocks;
3692 if (!torture_open_connection(&cli2, 1)) {
3693 use_level_II_oplocks = false;
3694 use_oplocks = saved_use_oplocks;
3698 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3699 cli_unlink(cli1, fname_ln, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3701 cli_sockopt(cli1, sockops);
3702 cli_sockopt(cli2, sockops);
3704 /* Create the file. */
3705 status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
3707 if (!NT_STATUS_IS_OK(status)) {
3708 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
3712 status = cli_close(cli1, fnum1);
3713 if (!NT_STATUS_IS_OK(status)) {
3714 printf("close1 failed (%s)\n", nt_errstr(status));
3718 /* Now create a hardlink. */
3719 status = cli_nt_hardlink(cli1, fname, fname_ln);
3720 if (!NT_STATUS_IS_OK(status)) {
3721 printf("nt hardlink failed (%s)\n", nt_errstr(status));
3725 /* Prove that opening hardlinks cause deny modes to conflict. */
3726 status = cli_open(cli1, fname, O_RDWR, DENY_ALL, &fnum1);
3727 if (!NT_STATUS_IS_OK(status)) {
3728 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
3732 status = cli_open(cli1, fname_ln, O_RDWR, DENY_NONE, &fnum2);
3733 if (NT_STATUS_IS_OK(status)) {
3734 printf("open of %s succeeded - should fail with sharing violation.\n",
3739 if (!NT_STATUS_EQUAL(status, NT_STATUS_SHARING_VIOLATION)) {
3740 printf("open of %s should fail with sharing violation. Got %s\n",
3741 fname_ln, nt_errstr(status));
3745 status = cli_close(cli1, fnum1);
3746 if (!NT_STATUS_IS_OK(status)) {
3747 printf("close1 failed (%s)\n", nt_errstr(status));
3751 cli1->use_oplocks = true;
3752 cli1->use_level_II_oplocks = true;
3754 cli2->use_oplocks = true;
3755 cli2->use_level_II_oplocks = true;
3757 status = cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
3758 if (!NT_STATUS_IS_OK(status)) {
3759 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
3763 ev = tevent_context_init(talloc_tos());
3765 printf("tevent_req_create failed\n");
3769 state = talloc(ev, struct oplock4_state);
3770 if (state == NULL) {
3771 printf("talloc failed\n");
3776 state->got_break = &got_break;
3777 state->fnum2 = &fnum2;
3779 oplock_req = cli_smb_oplock_break_waiter_send(
3780 talloc_tos(), ev, cli1);
3781 if (oplock_req == NULL) {
3782 printf("cli_smb_oplock_break_waiter_send failed\n");
3785 tevent_req_set_callback(oplock_req, oplock4_got_break, state);
3787 open_req = cli_open_send(
3788 talloc_tos(), ev, cli2, fname_ln, O_RDWR, DENY_NONE);
3789 if (oplock_req == NULL) {
3790 printf("cli_open_send failed\n");
3793 tevent_req_set_callback(open_req, oplock4_got_open, state);
3798 while (!got_break || fnum2 == 0xffff) {
3800 ret = tevent_loop_once(ev);
3802 printf("tevent_loop_once failed: %s\n",
3808 status = cli_close(cli2, fnum2);
3809 if (!NT_STATUS_IS_OK(status)) {
3810 printf("close2 failed (%s)\n", nt_errstr(status));
3814 status = cli_close(cli1, fnum1);
3815 if (!NT_STATUS_IS_OK(status)) {
3816 printf("close1 failed (%s)\n", nt_errstr(status));
3820 status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3821 if (!NT_STATUS_IS_OK(status)) {
3822 printf("unlink failed (%s)\n", nt_errstr(status));
3826 status = cli_unlink(cli1, fname_ln, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3827 if (!NT_STATUS_IS_OK(status)) {
3828 printf("unlink failed (%s)\n", nt_errstr(status));
3832 if (!torture_close_connection(cli1)) {
3840 printf("finished oplock test 4\n");
3845 static void oplock4_got_break(struct tevent_req *req)
3847 struct oplock4_state *state = tevent_req_callback_data(
3848 req, struct oplock4_state);
3853 status = cli_smb_oplock_break_waiter_recv(req, &fnum, &level);
3855 if (!NT_STATUS_IS_OK(status)) {
3856 printf("cli_smb_oplock_break_waiter_recv returned %s\n",
3860 *state->got_break = true;
3862 req = cli_oplock_ack_send(state, state->ev, state->cli, fnum,
3865 printf("cli_oplock_ack_send failed\n");
3870 static void oplock4_got_open(struct tevent_req *req)
3872 struct oplock4_state *state = tevent_req_callback_data(
3873 req, struct oplock4_state);
3876 status = cli_open_recv(req, state->fnum2);
3877 if (!NT_STATUS_IS_OK(status)) {
3878 printf("cli_open_recv returned %s\n", nt_errstr(status));
3879 *state->fnum2 = 0xffff;
3884 Test delete on close semantics.
3886 static bool run_deletetest(int dummy)
3888 struct cli_state *cli1 = NULL;
3889 struct cli_state *cli2 = NULL;
3890 const char *fname = "\\delete.file";
3891 uint16_t fnum1 = (uint16_t)-1;
3892 uint16_t fnum2 = (uint16_t)-1;
3893 bool correct = True;
3896 printf("starting delete test\n");
3898 if (!torture_open_connection(&cli1, 0)) {
3902 cli_sockopt(cli1, sockops);
3904 /* Test 1 - this should delete the file on close. */
3906 cli_setatr(cli1, fname, 0, 0);
3907 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3909 status = cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
3910 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
3911 FILE_DELETE_ON_CLOSE, 0, &fnum1);
3912 if (!NT_STATUS_IS_OK(status)) {
3913 printf("[1] open of %s failed (%s)\n", fname, nt_errstr(status));
3918 status = cli_close(cli1, fnum1);
3919 if (!NT_STATUS_IS_OK(status)) {
3920 printf("[1] close failed (%s)\n", nt_errstr(status));
3925 if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1))) {
3926 printf("[1] open of %s succeeded (should fail)\n", fname);
3931 printf("first delete on close test succeeded.\n");
3933 /* Test 2 - this should delete the file on close. */
3935 cli_setatr(cli1, fname, 0, 0);
3936 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3938 status = cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS,
3939 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
3940 FILE_OVERWRITE_IF, 0, 0, &fnum1);
3941 if (!NT_STATUS_IS_OK(status)) {
3942 printf("[2] open of %s failed (%s)\n", fname, nt_errstr(status));
3947 status = cli_nt_delete_on_close(cli1, fnum1, true);
3948 if (!NT_STATUS_IS_OK(status)) {
3949 printf("[2] setting delete_on_close failed (%s)\n", nt_errstr(status));
3954 status = cli_close(cli1, fnum1);
3955 if (!NT_STATUS_IS_OK(status)) {
3956 printf("[2] close failed (%s)\n", nt_errstr(status));
3961 if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
3962 printf("[2] open of %s succeeded should have been deleted on close !\n", fname);
3963 status = cli_close(cli1, fnum1);
3964 if (!NT_STATUS_IS_OK(status)) {
3965 printf("[2] close failed (%s)\n", nt_errstr(status));
3969 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3971 printf("second delete on close test succeeded.\n");
3974 cli_setatr(cli1, fname, 0, 0);
3975 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3977 status = cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS,
3978 FILE_ATTRIBUTE_NORMAL,
3979 FILE_SHARE_READ|FILE_SHARE_WRITE,
3980 FILE_OVERWRITE_IF, 0, 0, &fnum1);
3981 if (!NT_STATUS_IS_OK(status)) {
3982 printf("[3] open - 1 of %s failed (%s)\n", fname, nt_errstr(status));
3987 /* This should fail with a sharing violation - open for delete is only compatible
3988 with SHARE_DELETE. */
3990 if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3991 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0, 0, &fnum2))) {
3992 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname);
3997 /* This should succeed. */
3998 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
3999 FILE_ATTRIBUTE_NORMAL,
4000 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4001 FILE_OPEN, 0, 0, &fnum2);
4002 if (!NT_STATUS_IS_OK(status)) {
4003 printf("[3] open - 2 of %s failed (%s)\n", fname, nt_errstr(status));
4008 status = cli_nt_delete_on_close(cli1, fnum1, true);
4009 if (!NT_STATUS_IS_OK(status)) {
4010 printf("[3] setting delete_on_close failed (%s)\n", nt_errstr(status));
4015 status = cli_close(cli1, fnum1);
4016 if (!NT_STATUS_IS_OK(status)) {
4017 printf("[3] close 1 failed (%s)\n", nt_errstr(status));
4022 status = cli_close(cli1, fnum2);
4023 if (!NT_STATUS_IS_OK(status)) {
4024 printf("[3] close 2 failed (%s)\n", nt_errstr(status));
4029 /* This should fail - file should no longer be there. */
4031 if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
4032 printf("[3] open of %s succeeded should have been deleted on close !\n", fname);
4033 status = cli_close(cli1, fnum1);
4034 if (!NT_STATUS_IS_OK(status)) {
4035 printf("[3] close failed (%s)\n", nt_errstr(status));
4037 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4041 printf("third delete on close test succeeded.\n");
4044 cli_setatr(cli1, fname, 0, 0);
4045 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4047 status = cli_ntcreate(cli1, fname, 0,
4048 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
4049 FILE_ATTRIBUTE_NORMAL,
4050 FILE_SHARE_READ|FILE_SHARE_WRITE,
4051 FILE_OVERWRITE_IF, 0, 0, &fnum1);
4052 if (!NT_STATUS_IS_OK(status)) {
4053 printf("[4] open of %s failed (%s)\n", fname, nt_errstr(status));
4058 /* This should succeed. */
4059 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
4060 FILE_ATTRIBUTE_NORMAL,
4061 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4062 FILE_OPEN, 0, 0, &fnum2);
4063 if (!NT_STATUS_IS_OK(status)) {
4064 printf("[4] open - 2 of %s failed (%s)\n", fname, nt_errstr(status));
4069 status = cli_close(cli1, fnum2);
4070 if (!NT_STATUS_IS_OK(status)) {
4071 printf("[4] close - 1 failed (%s)\n", nt_errstr(status));
4076 status = cli_nt_delete_on_close(cli1, fnum1, true);
4077 if (!NT_STATUS_IS_OK(status)) {
4078 printf("[4] setting delete_on_close failed (%s)\n", nt_errstr(status));
4083 /* This should fail - no more opens once delete on close set. */
4084 if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
4085 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4086 FILE_OPEN, 0, 0, &fnum2))) {
4087 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname );
4091 printf("fourth delete on close test succeeded.\n");
4093 status = cli_close(cli1, fnum1);
4094 if (!NT_STATUS_IS_OK(status)) {
4095 printf("[4] close - 2 failed (%s)\n", nt_errstr(status));
4101 cli_setatr(cli1, fname, 0, 0);
4102 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4104 status = cli_open(cli1, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum1);
4105 if (!NT_STATUS_IS_OK(status)) {
4106 printf("[5] open of %s failed (%s)\n", fname, nt_errstr(status));
4111 /* This should fail - only allowed on NT opens with DELETE access. */
4113 if (NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
4114 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
4119 status = cli_close(cli1, fnum1);
4120 if (!NT_STATUS_IS_OK(status)) {
4121 printf("[5] close - 2 failed (%s)\n", nt_errstr(status));
4126 printf("fifth delete on close test succeeded.\n");
4129 cli_setatr(cli1, fname, 0, 0);
4130 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4132 status = cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
4133 FILE_ATTRIBUTE_NORMAL,
4134 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4135 FILE_OVERWRITE_IF, 0, 0, &fnum1);
4136 if (!NT_STATUS_IS_OK(status)) {
4137 printf("[6] open of %s failed (%s)\n", fname,
4143 /* This should fail - only allowed on NT opens with DELETE access. */
4145 if (NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
4146 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
4151 status = cli_close(cli1, fnum1);
4152 if (!NT_STATUS_IS_OK(status)) {
4153 printf("[6] close - 2 failed (%s)\n", nt_errstr(status));
4158 printf("sixth delete on close test succeeded.\n");
4161 cli_setatr(cli1, fname, 0, 0);
4162 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4164 status = cli_ntcreate(cli1, fname, 0,
4165 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
4166 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
4168 if (!NT_STATUS_IS_OK(status)) {
4169 printf("[7] open of %s failed (%s)\n", fname, nt_errstr(status));
4174 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
4175 printf("[7] setting delete_on_close on file failed !\n");
4180 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, false))) {
4181 printf("[7] unsetting delete_on_close on file failed !\n");
4186 status = cli_close(cli1, fnum1);
4187 if (!NT_STATUS_IS_OK(status)) {
4188 printf("[7] close - 2 failed (%s)\n", nt_errstr(status));
4193 /* This next open should succeed - we reset the flag. */
4194 status = cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1);
4195 if (!NT_STATUS_IS_OK(status)) {
4196 printf("[5] open of %s failed (%s)\n", fname, nt_errstr(status));
4201 status = cli_close(cli1, fnum1);
4202 if (!NT_STATUS_IS_OK(status)) {
4203 printf("[7] close - 2 failed (%s)\n", nt_errstr(status));
4208 printf("seventh delete on close test succeeded.\n");
4211 cli_setatr(cli1, fname, 0, 0);
4212 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4214 if (!torture_open_connection(&cli2, 1)) {
4215 printf("[8] failed to open second connection.\n");
4220 cli_sockopt(cli1, sockops);
4222 status = cli_ntcreate(cli1, fname, 0,
4223 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
4224 FILE_ATTRIBUTE_NORMAL,
4225 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4226 FILE_OVERWRITE_IF, 0, 0, &fnum1);
4227 if (!NT_STATUS_IS_OK(status)) {
4228 printf("[8] open 1 of %s failed (%s)\n", fname, nt_errstr(status));
4233 status = cli_ntcreate(cli2, fname, 0,
4234 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
4235 FILE_ATTRIBUTE_NORMAL,
4236 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4237 FILE_OPEN, 0, 0, &fnum2);
4238 if (!NT_STATUS_IS_OK(status)) {
4239 printf("[8] open 2 of %s failed (%s)\n", fname, nt_errstr(status));
4244 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
4245 printf("[8] setting delete_on_close on file failed !\n");
4250 status = cli_close(cli1, fnum1);
4251 if (!NT_STATUS_IS_OK(status)) {
4252 printf("[8] close - 1 failed (%s)\n", nt_errstr(status));
4257 status = cli_close(cli2, fnum2);
4258 if (!NT_STATUS_IS_OK(status)) {
4259 printf("[8] close - 2 failed (%s)\n", nt_errstr(status));
4264 /* This should fail.. */
4265 status = cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1);
4266 if (NT_STATUS_IS_OK(status)) {
4267 printf("[8] open of %s succeeded should have been deleted on close !\n", fname);
4271 printf("eighth delete on close test succeeded.\n");
4273 /* This should fail - we need to set DELETE_ACCESS. */
4274 if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0,FILE_READ_DATA|FILE_WRITE_DATA,
4275 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, 0, &fnum1))) {
4276 printf("[9] open of %s succeeded should have failed!\n", fname);
4281 printf("ninth delete on close test succeeded.\n");
4283 status = cli_ntcreate(cli1, fname, 0,
4284 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
4285 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
4286 FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE,
4288 if (!NT_STATUS_IS_OK(status)) {
4289 printf("[10] open of %s failed (%s)\n", fname, nt_errstr(status));
4294 /* This should delete the file. */
4295 status = cli_close(cli1, fnum1);
4296 if (!NT_STATUS_IS_OK(status)) {
4297 printf("[10] close failed (%s)\n", nt_errstr(status));
4302 /* This should fail.. */
4303 if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
4304 printf("[10] open of %s succeeded should have been deleted on close !\n", fname);
4308 printf("tenth delete on close test succeeded.\n");
4310 cli_setatr(cli1, fname, 0, 0);
4311 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4313 /* What error do we get when attempting to open a read-only file with
4316 /* Create a readonly file. */
4317 status = cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
4318 FILE_ATTRIBUTE_READONLY, FILE_SHARE_NONE,
4319 FILE_OVERWRITE_IF, 0, 0, &fnum1);
4320 if (!NT_STATUS_IS_OK(status)) {
4321 printf("[11] open of %s failed (%s)\n", fname, nt_errstr(status));
4326 status = cli_close(cli1, fnum1);
4327 if (!NT_STATUS_IS_OK(status)) {
4328 printf("[11] close failed (%s)\n", nt_errstr(status));
4333 /* Now try open for delete access. */
4334 if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES|DELETE_ACCESS,
4335 0, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4336 FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
4337 printf("[11] open of %s succeeded should have been denied with ACCESS_DENIED!\n", fname);
4338 cli_close(cli1, fnum1);
4342 NTSTATUS nterr = cli_nt_error(cli1);
4343 if (!NT_STATUS_EQUAL(nterr,NT_STATUS_ACCESS_DENIED)) {
4344 printf("[11] open of %s should have been denied with ACCESS_DENIED! Got error %s\n", fname, nt_errstr(nterr));
4348 printf("eleventh delete on close test succeeded.\n");
4352 printf("finished delete test\n");
4355 /* FIXME: This will crash if we aborted before cli2 got
4356 * intialized, because these functions don't handle
4357 * uninitialized connections. */
4359 if (fnum1 != (uint16_t)-1) cli_close(cli1, fnum1);
4360 if (fnum2 != (uint16_t)-1) cli_close(cli1, fnum2);
4361 cli_setatr(cli1, fname, 0, 0);
4362 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4364 if (cli1 && !torture_close_connection(cli1)) {
4367 if (cli2 && !torture_close_connection(cli2)) {
4373 static bool run_deletetest_ln(int dummy)
4375 struct cli_state *cli;
4376 const char *fname = "\\delete1";
4377 const char *fname_ln = "\\delete1_ln";
4381 bool correct = true;
4384 printf("starting deletetest-ln\n");
4386 if (!torture_open_connection(&cli, 0)) {
4390 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4391 cli_unlink(cli, fname_ln, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4393 cli_sockopt(cli, sockops);
4395 /* Create the file. */
4396 status = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
4397 if (!NT_STATUS_IS_OK(status)) {
4398 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
4402 status = cli_close(cli, fnum);
4403 if (!NT_STATUS_IS_OK(status)) {
4404 printf("close1 failed (%s)\n", nt_errstr(status));
4408 /* Now create a hardlink. */
4409 status = cli_nt_hardlink(cli, fname, fname_ln);
4410 if (!NT_STATUS_IS_OK(status)) {
4411 printf("nt hardlink failed (%s)\n", nt_errstr(status));
4415 /* Open the original file. */
4416 status = cli_ntcreate(cli, fname, 0, FILE_READ_DATA,
4417 FILE_ATTRIBUTE_NORMAL,
4418 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4419 FILE_OPEN_IF, 0, 0, &fnum);
4420 if (!NT_STATUS_IS_OK(status)) {
4421 printf("ntcreate of %s failed (%s)\n", fname, nt_errstr(status));
4425 /* Unlink the hard link path. */
4426 status = cli_ntcreate(cli, fname_ln, 0, DELETE_ACCESS,
4427 FILE_ATTRIBUTE_NORMAL,
4428 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4429 FILE_OPEN_IF, 0, 0, &fnum1);
4430 if (!NT_STATUS_IS_OK(status)) {
4431 printf("ntcreate of %s failed (%s)\n", fname_ln, nt_errstr(status));
4434 status = cli_nt_delete_on_close(cli, fnum1, true);
4435 if (!NT_STATUS_IS_OK(status)) {
4436 d_printf("(%s) failed to set delete_on_close %s: %s\n",
4437 __location__, fname_ln, nt_errstr(status));
4441 status = cli_close(cli, fnum1);
4442 if (!NT_STATUS_IS_OK(status)) {
4443 printf("close %s failed (%s)\n",
4444 fname_ln, nt_errstr(status));
4448 status = cli_close(cli, fnum);
4449 if (!NT_STATUS_IS_OK(status)) {
4450 printf("close %s failed (%s)\n",
4451 fname, nt_errstr(status));
4455 /* Ensure the original file is still there. */
4456 status = cli_getatr(cli, fname, NULL, NULL, &t);
4457 if (!NT_STATUS_IS_OK(status)) {
4458 printf("%s getatr on file %s failed (%s)\n",
4465 /* Ensure the link path is gone. */
4466 status = cli_getatr(cli, fname_ln, NULL, NULL, &t);
4467 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
4468 printf("%s, getatr for file %s returned wrong error code %s "
4469 "- should have been deleted\n",
4471 fname_ln, nt_errstr(status));
4475 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4476 cli_unlink(cli, fname_ln, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4478 if (!torture_close_connection(cli)) {
4482 printf("finished deletetest-ln\n");
4488 print out server properties
4490 static bool run_properties(int dummy)
4492 struct cli_state *cli;
4493 bool correct = True;
4495 printf("starting properties test\n");
4499 if (!torture_open_connection(&cli, 0)) {
4503 cli_sockopt(cli, sockops);
4505 d_printf("Capabilities 0x%08x\n", cli->capabilities);
4507 if (!torture_close_connection(cli)) {
4516 /* FIRST_DESIRED_ACCESS 0xf019f */
4517 #define FIRST_DESIRED_ACCESS FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|\
4518 FILE_READ_EA| /* 0xf */ \
4519 FILE_WRITE_EA|FILE_READ_ATTRIBUTES| /* 0x90 */ \
4520 FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
4521 DELETE_ACCESS|READ_CONTROL_ACCESS|\
4522 WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS /* 0xf0000 */
4523 /* SECOND_DESIRED_ACCESS 0xe0080 */
4524 #define SECOND_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
4525 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
4526 WRITE_OWNER_ACCESS /* 0xe0000 */
4529 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
4530 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
4532 WRITE_OWNER_ACCESS /* */
4536 Test ntcreate calls made by xcopy
4538 static bool run_xcopy(int dummy)
4540 static struct cli_state *cli1;
4541 const char *fname = "\\test.txt";
4542 bool correct = True;
4543 uint16_t fnum1, fnum2;
4546 printf("starting xcopy test\n");
4548 if (!torture_open_connection(&cli1, 0)) {
4552 status = cli_ntcreate(cli1, fname, 0, FIRST_DESIRED_ACCESS,
4553 FILE_ATTRIBUTE_ARCHIVE, FILE_SHARE_NONE,
4554 FILE_OVERWRITE_IF, 0x4044, 0, &fnum1);
4555 if (!NT_STATUS_IS_OK(status)) {
4556 printf("First open failed - %s\n", nt_errstr(status));
4560 status = cli_ntcreate(cli1, fname, 0, SECOND_DESIRED_ACCESS, 0,
4561 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4562 FILE_OPEN, 0x200000, 0, &fnum2);
4563 if (!NT_STATUS_IS_OK(status)) {
4564 printf("second open failed - %s\n", nt_errstr(status));
4568 if (!torture_close_connection(cli1)) {
4576 Test rename on files open with share delete and no share delete.
4578 static bool run_rename(int dummy)
4580 static struct cli_state *cli1;
4581 const char *fname = "\\test.txt";
4582 const char *fname1 = "\\test1.txt";
4583 bool correct = True;
4588 printf("starting rename test\n");
4590 if (!torture_open_connection(&cli1, 0)) {
4594 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4595 cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4597 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
4598 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ,
4599 FILE_OVERWRITE_IF, 0, 0, &fnum1);
4600 if (!NT_STATUS_IS_OK(status)) {
4601 printf("First open failed - %s\n", nt_errstr(status));
4605 status = cli_rename(cli1, fname, fname1);
4606 if (!NT_STATUS_IS_OK(status)) {
4607 printf("First rename failed (SHARE_READ) (this is correct) - %s\n", nt_errstr(status));
4609 printf("First rename succeeded (SHARE_READ) - this should have failed !\n");
4613 status = cli_close(cli1, fnum1);
4614 if (!NT_STATUS_IS_OK(status)) {
4615 printf("close - 1 failed (%s)\n", nt_errstr(status));
4619 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4620 cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4621 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
4623 FILE_SHARE_DELETE|FILE_SHARE_NONE,
4625 FILE_SHARE_DELETE|FILE_SHARE_READ,
4627 FILE_OVERWRITE_IF, 0, 0, &fnum1);
4628 if (!NT_STATUS_IS_OK(status)) {
4629 printf("Second open failed - %s\n", nt_errstr(status));
4633 status = cli_rename(cli1, fname, fname1);
4634 if (!NT_STATUS_IS_OK(status)) {
4635 printf("Second rename failed (SHARE_DELETE | SHARE_READ) - this should have succeeded - %s\n", nt_errstr(status));
4638 printf("Second rename succeeded (SHARE_DELETE | SHARE_READ)\n");
4641 status = cli_close(cli1, fnum1);
4642 if (!NT_STATUS_IS_OK(status)) {
4643 printf("close - 2 failed (%s)\n", nt_errstr(status));
4647 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4648 cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4650 status = cli_ntcreate(cli1, fname, 0, READ_CONTROL_ACCESS,
4651 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
4652 FILE_OVERWRITE_IF, 0, 0, &fnum1);
4653 if (!NT_STATUS_IS_OK(status)) {
4654 printf("Third open failed - %s\n", nt_errstr(status));
4663 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
4664 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum2))) {
4665 printf("Fourth open failed - %s\n", cli_errstr(cli1));
4668 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum2, true))) {
4669 printf("[8] setting delete_on_close on file failed !\n");
4673 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum2))) {
4674 printf("close - 4 failed (%s)\n", cli_errstr(cli1));
4680 status = cli_rename(cli1, fname, fname1);
4681 if (!NT_STATUS_IS_OK(status)) {
4682 printf("Third rename failed (SHARE_NONE) - this should have succeeded - %s\n", nt_errstr(status));
4685 printf("Third rename succeeded (SHARE_NONE)\n");
4688 status = cli_close(cli1, fnum1);
4689 if (!NT_STATUS_IS_OK(status)) {
4690 printf("close - 3 failed (%s)\n", nt_errstr(status));
4694 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4695 cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4699 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
4700 FILE_ATTRIBUTE_NORMAL,
4701 FILE_SHARE_READ | FILE_SHARE_WRITE,
4702 FILE_OVERWRITE_IF, 0, 0, &fnum1);
4703 if (!NT_STATUS_IS_OK(status)) {
4704 printf("Fourth open failed - %s\n", nt_errstr(status));
4708 status = cli_rename(cli1, fname, fname1);
4709 if (!NT_STATUS_IS_OK(status)) {
4710 printf("Fourth rename failed (SHARE_READ | SHARE_WRITE) (this is correct) - %s\n", nt_errstr(status));
4712 printf("Fourth rename succeeded (SHARE_READ | SHARE_WRITE) - this should have failed !\n");
4716 status = cli_close(cli1, fnum1);
4717 if (!NT_STATUS_IS_OK(status)) {
4718 printf("close - 4 failed (%s)\n", nt_errstr(status));
4722 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4723 cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4727 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
4728 FILE_ATTRIBUTE_NORMAL,
4729 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
4730 FILE_OVERWRITE_IF, 0, 0, &fnum1);
4731 if (!NT_STATUS_IS_OK(status)) {
4732 printf("Fifth open failed - %s\n", nt_errstr(status));
4736 status = cli_rename(cli1, fname, fname1);
4737 if (!NT_STATUS_IS_OK(status)) {
4738 printf("Fifth rename failed (SHARE_READ | SHARE_WRITE | SHARE_DELETE) - this should have succeeded - %s ! \n", nt_errstr(status));
4741 printf("Fifth rename succeeded (SHARE_READ | SHARE_WRITE | SHARE_DELETE) (this is correct) - %s\n", nt_errstr(status));
4745 * Now check if the first name still exists ...
4748 /* if (!NT_STATUS_OP(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
4749 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0, &fnum2))) {
4750 printf("Opening original file after rename of open file fails: %s\n",
4754 printf("Opening original file after rename of open file works ...\n");
4755 (void)cli_close(cli1, fnum2);
4759 status = cli_close(cli1, fnum1);
4760 if (!NT_STATUS_IS_OK(status)) {
4761 printf("close - 5 failed (%s)\n", nt_errstr(status));
4765 /* Check that the renamed file has FILE_ATTRIBUTE_ARCHIVE. */
4766 status = cli_getatr(cli1, fname1, &attr, NULL, NULL);
4767 if (!NT_STATUS_IS_OK(status)) {
4768 printf("getatr on file %s failed - %s ! \n",
4769 fname1, nt_errstr(status));
4772 if (attr != FILE_ATTRIBUTE_ARCHIVE) {
4773 printf("Renamed file %s has wrong attr 0x%x "
4774 "(should be 0x%x)\n",
4777 (unsigned int)FILE_ATTRIBUTE_ARCHIVE);
4780 printf("Renamed file %s has archive bit set\n", fname1);
4784 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4785 cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4787 if (!torture_close_connection(cli1)) {
4794 static bool run_pipe_number(int dummy)
4796 struct cli_state *cli1;
4797 const char *pipe_name = "\\SPOOLSS";
4802 printf("starting pipenumber test\n");
4803 if (!torture_open_connection(&cli1, 0)) {
4807 cli_sockopt(cli1, sockops);
4809 status = cli_ntcreate(cli1, pipe_name, 0, FILE_READ_DATA,
4810 FILE_ATTRIBUTE_NORMAL,
4811 FILE_SHARE_READ|FILE_SHARE_WRITE,
4812 FILE_OPEN_IF, 0, 0, &fnum);
4813 if (!NT_STATUS_IS_OK(status)) {
4814 printf("Open of pipe %s failed with error (%s)\n", pipe_name, nt_errstr(status));
4818 printf("\r%6d", num_pipes);
4821 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes, pipe_name );
4822 torture_close_connection(cli1);
4827 Test open mode returns on read-only files.
4829 static bool run_opentest(int dummy)
4831 static struct cli_state *cli1;
4832 static struct cli_state *cli2;
4833 const char *fname = "\\readonly.file";
4834 uint16_t fnum1, fnum2;
4837 bool correct = True;
4841 printf("starting open test\n");
4843 if (!torture_open_connection(&cli1, 0)) {
4847 cli_setatr(cli1, fname, 0, 0);
4848 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4850 cli_sockopt(cli1, sockops);
4852 status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
4853 if (!NT_STATUS_IS_OK(status)) {
4854 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
4858 status = cli_close(cli1, fnum1);
4859 if (!NT_STATUS_IS_OK(status)) {
4860 printf("close2 failed (%s)\n", nt_errstr(status));
4864 status = cli_setatr(cli1, fname, FILE_ATTRIBUTE_READONLY, 0);
4865 if (!NT_STATUS_IS_OK(status)) {
4866 printf("cli_setatr failed (%s)\n", nt_errstr(status));
4870 status = cli_open(cli1, fname, O_RDONLY, DENY_WRITE, &fnum1);
4871 if (!NT_STATUS_IS_OK(status)) {
4872 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
4876 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
4877 status = cli_open(cli1, fname, O_RDWR, DENY_ALL, &fnum2);
4879 if (check_error(__LINE__, status, ERRDOS, ERRnoaccess,
4880 NT_STATUS_ACCESS_DENIED)) {
4881 printf("correct error code ERRDOS/ERRnoaccess returned\n");
4884 printf("finished open test 1\n");
4886 cli_close(cli1, fnum1);
4888 /* Now try not readonly and ensure ERRbadshare is returned. */
4890 cli_setatr(cli1, fname, 0, 0);
4892 status = cli_open(cli1, fname, O_RDONLY, DENY_WRITE, &fnum1);
4893 if (!NT_STATUS_IS_OK(status)) {
4894 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
4898 /* This will fail - but the error should be ERRshare. */
4899 status = cli_open(cli1, fname, O_RDWR, DENY_ALL, &fnum2);
4901 if (check_error(__LINE__, status, ERRDOS, ERRbadshare,
4902 NT_STATUS_SHARING_VIOLATION)) {
4903 printf("correct error code ERRDOS/ERRbadshare returned\n");
4906 status = cli_close(cli1, fnum1);
4907 if (!NT_STATUS_IS_OK(status)) {
4908 printf("close2 failed (%s)\n", nt_errstr(status));
4912 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4914 printf("finished open test 2\n");
4916 /* Test truncate open disposition on file opened for read. */
4917 status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
4918 if (!NT_STATUS_IS_OK(status)) {
4919 printf("(3) open (1) of %s failed (%s)\n", fname, nt_errstr(status));
4923 /* write 20 bytes. */
4925 memset(buf, '\0', 20);
4927 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 0, 20, NULL);
4928 if (!NT_STATUS_IS_OK(status)) {
4929 printf("write failed (%s)\n", nt_errstr(status));
4933 status = cli_close(cli1, fnum1);
4934 if (!NT_STATUS_IS_OK(status)) {
4935 printf("(3) close1 failed (%s)\n", nt_errstr(status));
4939 /* Ensure size == 20. */
4940 status = cli_getatr(cli1, fname, NULL, &fsize, NULL);
4941 if (!NT_STATUS_IS_OK(status)) {
4942 printf("(3) getatr failed (%s)\n", nt_errstr(status));
4947 printf("(3) file size != 20\n");
4951 /* Now test if we can truncate a file opened for readonly. */
4952 status = cli_open(cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE, &fnum1);
4953 if (!NT_STATUS_IS_OK(status)) {
4954 printf("(3) open (2) of %s failed (%s)\n", fname, nt_errstr(status));
4958 status = cli_close(cli1, fnum1);
4959 if (!NT_STATUS_IS_OK(status)) {
4960 printf("close2 failed (%s)\n", nt_errstr(status));
4964 /* Ensure size == 0. */
4965 status = cli_getatr(cli1, fname, NULL, &fsize, NULL);
4966 if (!NT_STATUS_IS_OK(status)) {
4967 printf("(3) getatr failed (%s)\n", nt_errstr(status));
4972 printf("(3) file size != 0\n");
4975 printf("finished open test 3\n");
4977 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4979 printf("Do ctemp tests\n");
4980 status = cli_ctemp(cli1, talloc_tos(), "\\", &fnum1, &tmp_path);
4981 if (!NT_STATUS_IS_OK(status)) {
4982 printf("ctemp failed (%s)\n", nt_errstr(status));
4986 printf("ctemp gave path %s\n", tmp_path);
4987 status = cli_close(cli1, fnum1);
4988 if (!NT_STATUS_IS_OK(status)) {
4989 printf("close of temp failed (%s)\n", nt_errstr(status));
4992 status = cli_unlink(cli1, tmp_path, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4993 if (!NT_STATUS_IS_OK(status)) {
4994 printf("unlink of temp failed (%s)\n", nt_errstr(status));
4997 /* Test the non-io opens... */
4999 if (!torture_open_connection(&cli2, 1)) {
5003 cli_setatr(cli2, fname, 0, 0);
5004 cli_unlink(cli2, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5006 cli_sockopt(cli2, sockops);
5008 printf("TEST #1 testing 2 non-io opens (no delete)\n");
5009 status = cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES,
5010 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5011 FILE_OVERWRITE_IF, 0, 0, &fnum1);
5012 if (!NT_STATUS_IS_OK(status)) {
5013 printf("TEST #1 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
5017 status = cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES,
5018 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5019 FILE_OPEN_IF, 0, 0, &fnum2);
5020 if (!NT_STATUS_IS_OK(status)) {
5021 printf("TEST #1 open 2 of %s failed (%s)\n", fname, nt_errstr(status));
5025 status = cli_close(cli1, fnum1);
5026 if (!NT_STATUS_IS_OK(status)) {
5027 printf("TEST #1 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
5031 status = cli_close(cli2, fnum2);
5032 if (!NT_STATUS_IS_OK(status)) {
5033 printf("TEST #1 close 2 of %s failed (%s)\n", fname, nt_errstr(status));
5037 printf("non-io open test #1 passed.\n");
5039 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5041 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
5043 status = cli_ntcreate(cli1, fname, 0,
5044 DELETE_ACCESS|FILE_READ_ATTRIBUTES,
5045 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5046 FILE_OVERWRITE_IF, 0, 0, &fnum1);
5047 if (!NT_STATUS_IS_OK(status)) {
5048 printf("TEST #2 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
5052 status = cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES,
5053 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5054 FILE_OPEN_IF, 0, 0, &fnum2);
5055 if (!NT_STATUS_IS_OK(status)) {
5056 printf("TEST #2 open 2 of %s failed (%s)\n", fname, nt_errstr(status));
5060 status = cli_close(cli1, fnum1);
5061 if (!NT_STATUS_IS_OK(status)) {
5062 printf("TEST #2 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
5066 status = cli_close(cli2, fnum2);
5067 if (!NT_STATUS_IS_OK(status)) {
5068 printf("TEST #2 close 2 of %s failed (%s)\n", fname, nt_errstr(status));
5072 printf("non-io open test #2 passed.\n");
5074 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5076 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
5078 status = cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES,
5079 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5080 FILE_OVERWRITE_IF, 0, 0, &fnum1);
5081 if (!NT_STATUS_IS_OK(status)) {
5082 printf("TEST #3 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
5086 status = cli_ntcreate(cli2, fname, 0,
5087 DELETE_ACCESS|FILE_READ_ATTRIBUTES,
5088 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5089 FILE_OPEN_IF, 0, 0, &fnum2);
5090 if (!NT_STATUS_IS_OK(status)) {
5091 printf("TEST #3 open 2 of %s failed (%s)\n", fname, nt_errstr(status));
5095 status = cli_close(cli1, fnum1);
5096 if (!NT_STATUS_IS_OK(status)) {
5097 printf("TEST #3 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
5101 status = cli_close(cli2, fnum2);
5102 if (!NT_STATUS_IS_OK(status)) {
5103 printf("TEST #3 close 2 of %s failed (%s)\n", fname, nt_errstr(status));
5107 printf("non-io open test #3 passed.\n");
5109 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5111 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
5113 status = cli_ntcreate(cli1, fname, 0,
5114 DELETE_ACCESS|FILE_READ_ATTRIBUTES,
5115 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5116 FILE_OVERWRITE_IF, 0, 0, &fnum1);
5117 if (!NT_STATUS_IS_OK(status)) {
5118 printf("TEST #4 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
5122 status = cli_ntcreate(cli2, fname, 0,
5123 DELETE_ACCESS|FILE_READ_ATTRIBUTES,
5124 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5125 FILE_OPEN_IF, 0, 0, &fnum2);
5126 if (NT_STATUS_IS_OK(status)) {
5127 printf("TEST #4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, nt_errstr(status));
5131 printf("TEST #4 open 2 of %s gave %s (correct error should be %s)\n", fname, nt_errstr(status), "sharing violation");
5133 status = cli_close(cli1, fnum1);
5134 if (!NT_STATUS_IS_OK(status)) {
5135 printf("TEST #4 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
5139 printf("non-io open test #4 passed.\n");
5141 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5143 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
5145 status = cli_ntcreate(cli1, fname, 0,
5146 DELETE_ACCESS|FILE_READ_ATTRIBUTES,
5147 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_DELETE,
5148 FILE_OVERWRITE_IF, 0, 0, &fnum1);
5149 if (!NT_STATUS_IS_OK(status)) {
5150 printf("TEST #5 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
5154 status = cli_ntcreate(cli2, fname, 0,
5155 DELETE_ACCESS|FILE_READ_ATTRIBUTES,
5156 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_DELETE,
5157 FILE_OPEN_IF, 0, 0, &fnum2);
5158 if (!NT_STATUS_IS_OK(status)) {
5159 printf("TEST #5 open 2 of %s failed (%s)\n", fname, nt_errstr(status));
5163 status = cli_close(cli1, fnum1);
5164 if (!NT_STATUS_IS_OK(status)) {
5165 printf("TEST #5 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
5169 status = cli_close(cli2, fnum2);
5170 if (!NT_STATUS_IS_OK(status)) {
5171 printf("TEST #5 close 2 of %s failed (%s)\n", fname, nt_errstr(status));
5175 printf("non-io open test #5 passed.\n");
5177 printf("TEST #6 testing 1 non-io open, one io open\n");
5179 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5181 status = cli_ntcreate(cli1, fname, 0, FILE_READ_DATA,
5182 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5183 FILE_OVERWRITE_IF, 0, 0, &fnum1);
5184 if (!NT_STATUS_IS_OK(status)) {
5185 printf("TEST #6 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
5189 status = cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES,
5190 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ,
5191 FILE_OPEN_IF, 0, 0, &fnum2);
5192 if (!NT_STATUS_IS_OK(status)) {
5193 printf("TEST #6 open 2 of %s failed (%s)\n", fname, nt_errstr(status));
5197 status = cli_close(cli1, fnum1);
5198 if (!NT_STATUS_IS_OK(status)) {
5199 printf("TEST #6 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
5203 status = cli_close(cli2, fnum2);
5204 if (!NT_STATUS_IS_OK(status)) {
5205 printf("TEST #6 close 2 of %s failed (%s)\n", fname, nt_errstr(status));
5209 printf("non-io open test #6 passed.\n");
5211 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
5213 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5215 status = cli_ntcreate(cli1, fname, 0, FILE_READ_DATA,
5216 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5217 FILE_OVERWRITE_IF, 0, 0, &fnum1);
5218 if (!NT_STATUS_IS_OK(status)) {
5219 printf("TEST #7 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
5223 status = cli_ntcreate(cli2, fname, 0,
5224 DELETE_ACCESS|FILE_READ_ATTRIBUTES,
5225 FILE_ATTRIBUTE_NORMAL,
5226 FILE_SHARE_READ|FILE_SHARE_DELETE,
5227 FILE_OPEN_IF, 0, 0, &fnum2);
5228 if (NT_STATUS_IS_OK(status)) {
5229 printf("TEST #7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, nt_errstr(status));
5233 printf("TEST #7 open 2 of %s gave %s (correct error should be %s)\n", fname, nt_errstr(status), "sharing violation");
5235 status = cli_close(cli1, fnum1);
5236 if (!NT_STATUS_IS_OK(status)) {
5237 printf("TEST #7 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
5241 printf("non-io open test #7 passed.\n");
5243 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5245 printf("TEST #8 testing open without WRITE_ATTRIBUTES, updating close write time.\n");
5246 status = cli_ntcreate(cli1, fname, 0, FILE_WRITE_DATA, FILE_ATTRIBUTE_NORMAL,
5247 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
5248 FILE_OVERWRITE_IF, 0, 0, &fnum1);
5249 if (!NT_STATUS_IS_OK(status)) {
5250 printf("TEST #8 open of %s failed (%s)\n", fname, nt_errstr(status));
5255 /* Write to ensure we have to update the file time. */
5256 status = cli_writeall(cli1, fnum1, 0, (const uint8_t *)"TEST DATA\n", 0, 10,
5258 if (!NT_STATUS_IS_OK(status)) {
5259 printf("TEST #8 cli_write failed: %s\n", nt_errstr(status));
5264 status = cli_close(cli1, fnum1);
5265 if (!NT_STATUS_IS_OK(status)) {
5266 printf("TEST #8 close of %s failed (%s)\n", fname, nt_errstr(status));
5272 if (!torture_close_connection(cli1)) {
5275 if (!torture_close_connection(cli2)) {
5282 NTSTATUS torture_setup_unix_extensions(struct cli_state *cli)
5284 uint16 major, minor;
5285 uint32 caplow, caphigh;
5288 if (!SERVER_HAS_UNIX_CIFS(cli)) {
5289 printf("Server doesn't support UNIX CIFS extensions.\n");
5290 return NT_STATUS_NOT_SUPPORTED;
5293 status = cli_unix_extensions_version(cli, &major, &minor, &caplow,
5295 if (!NT_STATUS_IS_OK(status)) {
5296 printf("Server didn't return UNIX CIFS extensions: %s\n",
5301 status = cli_set_unix_extensions_capabilities(cli, major, minor,
5303 if (!NT_STATUS_IS_OK(status)) {
5304 printf("Server doesn't support setting UNIX CIFS extensions: "
5305 "%s.\n", nt_errstr(status));
5309 return NT_STATUS_OK;
5313 Test POSIX open /mkdir calls.
5315 static bool run_simple_posix_open_test(int dummy)
5317 static struct cli_state *cli1;
5318 const char *fname = "posix:file";
5319 const char *hname = "posix:hlink";
5320 const char *sname = "posix:symlink";
5321 const char *dname = "posix:dir";
5324 uint16_t fnum1 = (uint16_t)-1;
5325 SMB_STRUCT_STAT sbuf;
5326 bool correct = false;
5330 printf("Starting simple POSIX open test\n");
5332 if (!torture_open_connection(&cli1, 0)) {
5336 cli_sockopt(cli1, sockops);
5338 status = torture_setup_unix_extensions(cli1);
5339 if (!NT_STATUS_IS_OK(status)) {
5343 cli_setatr(cli1, fname, 0, 0);
5344 cli_posix_unlink(cli1, fname);
5345 cli_setatr(cli1, dname, 0, 0);
5346 cli_posix_rmdir(cli1, dname);
5347 cli_setatr(cli1, hname, 0, 0);
5348 cli_posix_unlink(cli1, hname);
5349 cli_setatr(cli1, sname, 0, 0);
5350 cli_posix_unlink(cli1, sname);
5352 /* Create a directory. */
5353 status = cli_posix_mkdir(cli1, dname, 0777);
5354 if (!NT_STATUS_IS_OK(status)) {
5355 printf("POSIX mkdir of %s failed (%s)\n", dname, nt_errstr(status));
5359 status = cli_posix_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL,
5361 if (!NT_STATUS_IS_OK(status)) {
5362 printf("POSIX create of %s failed (%s)\n", fname, nt_errstr(status));
5366 /* Test ftruncate - set file size. */
5367 status = cli_ftruncate(cli1, fnum1, 1000);
5368 if (!NT_STATUS_IS_OK(status)) {
5369 printf("ftruncate failed (%s)\n", nt_errstr(status));
5373 /* Ensure st_size == 1000 */
5374 status = cli_posix_stat(cli1, fname, &sbuf);
5375 if (!NT_STATUS_IS_OK(status)) {
5376 printf("stat failed (%s)\n", nt_errstr(status));
5380 if (sbuf.st_ex_size != 1000) {
5381 printf("ftruncate - stat size (%u) != 1000\n", (unsigned int)sbuf.st_ex_size);
5385 /* Test ftruncate - set file size back to zero. */
5386 status = cli_ftruncate(cli1, fnum1, 0);
5387 if (!NT_STATUS_IS_OK(status)) {
5388 printf("ftruncate failed (%s)\n", nt_errstr(status));
5392 status = cli_close(cli1, fnum1);
5393 if (!NT_STATUS_IS_OK(status)) {
5394 printf("close failed (%s)\n", nt_errstr(status));
5398 /* Now open the file again for read only. */
5399 status = cli_posix_open(cli1, fname, O_RDONLY, 0, &fnum1);
5400 if (!NT_STATUS_IS_OK(status)) {
5401 printf("POSIX open of %s failed (%s)\n", fname, nt_errstr(status));
5405 /* Now unlink while open. */
5406 status = cli_posix_unlink(cli1, fname);
5407 if (!NT_STATUS_IS_OK(status)) {
5408 printf("POSIX unlink of %s failed (%s)\n", fname, nt_errstr(status));
5412 status = cli_close(cli1, fnum1);
5413 if (!NT_STATUS_IS_OK(status)) {
5414 printf("close(2) failed (%s)\n", nt_errstr(status));
5418 /* Ensure the file has gone. */
5419 status = cli_posix_open(cli1, fname, O_RDONLY, 0, &fnum1);
5420 if (NT_STATUS_IS_OK(status)) {
5421 printf("POSIX open of %s succeeded, should have been deleted.\n", fname);
5425 /* Create again to test open with O_TRUNC. */
5426 status = cli_posix_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, 0600, &fnum1);
5427 if (!NT_STATUS_IS_OK(status)) {
5428 printf("POSIX create of %s failed (%s)\n", fname, nt_errstr(status));
5432 /* Test ftruncate - set file size. */
5433 status = cli_ftruncate(cli1, fnum1, 1000);
5434 if (!NT_STATUS_IS_OK(status)) {
5435 printf("ftruncate failed (%s)\n", nt_errstr(status));
5439 /* Ensure st_size == 1000 */
5440 status = cli_posix_stat(cli1, fname, &sbuf);
5441 if (!NT_STATUS_IS_OK(status)) {
5442 printf("stat failed (%s)\n", nt_errstr(status));
5446 if (sbuf.st_ex_size != 1000) {
5447 printf("ftruncate - stat size (%u) != 1000\n", (unsigned int)sbuf.st_ex_size);
5451 status = cli_close(cli1, fnum1);
5452 if (!NT_STATUS_IS_OK(status)) {
5453 printf("close(2) failed (%s)\n", nt_errstr(status));
5457 /* Re-open with O_TRUNC. */
5458 status = cli_posix_open(cli1, fname, O_WRONLY|O_TRUNC, 0600, &fnum1);
5459 if (!NT_STATUS_IS_OK(status)) {
5460 printf("POSIX create of %s failed (%s)\n", fname, nt_errstr(status));
5464 /* Ensure st_size == 0 */
5465 status = cli_posix_stat(cli1, fname, &sbuf);
5466 if (!NT_STATUS_IS_OK(status)) {
5467 printf("stat failed (%s)\n", nt_errstr(status));
5471 if (sbuf.st_ex_size != 0) {
5472 printf("O_TRUNC - stat size (%u) != 0\n", (unsigned int)sbuf.st_ex_size);
5476 status = cli_close(cli1, fnum1);
5477 if (!NT_STATUS_IS_OK(status)) {
5478 printf("close failed (%s)\n", nt_errstr(status));
5482 status = cli_posix_unlink(cli1, fname);
5483 if (!NT_STATUS_IS_OK(status)) {
5484 printf("POSIX unlink of %s failed (%s)\n", fname, nt_errstr(status));
5488 status = cli_posix_open(cli1, dname, O_RDONLY, 0, &fnum1);
5489 if (!NT_STATUS_IS_OK(status)) {
5490 printf("POSIX open directory O_RDONLY of %s failed (%s)\n",
5491 dname, nt_errstr(status));
5495 cli_close(cli1, fnum1);
5497 /* What happens when we try and POSIX open a directory for write ? */
5498 status = cli_posix_open(cli1, dname, O_RDWR, 0, &fnum1);
5499 if (NT_STATUS_IS_OK(status)) {
5500 printf("POSIX open of directory %s succeeded, should have failed.\n", fname);
5503 if (!check_both_error(__LINE__, status, ERRDOS, EISDIR,
5504 NT_STATUS_FILE_IS_A_DIRECTORY)) {
5509 /* Create the file. */
5510 status = cli_posix_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL,
5512 if (!NT_STATUS_IS_OK(status)) {
5513 printf("POSIX create of %s failed (%s)\n", fname, nt_errstr(status));
5517 /* Write some data into it. */
5518 status = cli_writeall(cli1, fnum1, 0, (const uint8_t *)"TEST DATA\n", 0, 10,
5520 if (!NT_STATUS_IS_OK(status)) {
5521 printf("cli_write failed: %s\n", nt_errstr(status));
5525 cli_close(cli1, fnum1);
5527 /* Now create a hardlink. */
5528 status = cli_posix_hardlink(cli1, fname, hname);
5529 if (!NT_STATUS_IS_OK(status)) {
5530 printf("POSIX hardlink of %s failed (%s)\n", hname, nt_errstr(status));
5534 /* Now create a symlink. */
5535 status = cli_posix_symlink(cli1, fname, sname);
5536 if (!NT_STATUS_IS_OK(status)) {
5537 printf("POSIX symlink of %s failed (%s)\n", sname, nt_errstr(status));
5541 /* Open the hardlink for read. */
5542 status = cli_posix_open(cli1, hname, O_RDONLY, 0, &fnum1);
5543 if (!NT_STATUS_IS_OK(status)) {
5544 printf("POSIX open of %s failed (%s)\n", hname, nt_errstr(status));
5548 status = cli_read(cli1, fnum1, buf, 0, 10, &nread);
5549 if (!NT_STATUS_IS_OK(status)) {
5550 printf("POSIX read of %s failed (%s)\n", hname,
5553 } else if (nread != 10) {
5554 printf("POSIX read of %s failed. Received %ld, expected %d\n",
5555 hname, (unsigned long)nread, 10);
5559 if (memcmp(buf, "TEST DATA\n", 10)) {
5560 printf("invalid data read from hardlink\n");
5564 /* Do a POSIX lock/unlock. */
5565 status = cli_posix_lock(cli1, fnum1, 0, 100, true, READ_LOCK);
5566 if (!NT_STATUS_IS_OK(status)) {
5567 printf("POSIX lock failed %s\n", nt_errstr(status));
5571 /* Punch a hole in the locked area. */
5572 status = cli_posix_unlock(cli1, fnum1, 10, 80);
5573 if (!NT_STATUS_IS_OK(status)) {
5574 printf("POSIX unlock failed %s\n", nt_errstr(status));
5578 cli_close(cli1, fnum1);
5580 /* Open the symlink for read - this should fail. A POSIX
5581 client should not be doing opens on a symlink. */
5582 status = cli_posix_open(cli1, sname, O_RDONLY, 0, &fnum1);
5583 if (NT_STATUS_IS_OK(status)) {
5584 printf("POSIX open of %s succeeded (should have failed)\n", sname);
5587 if (!check_both_error(__LINE__, status, ERRDOS, ERRbadpath,
5588 NT_STATUS_OBJECT_PATH_NOT_FOUND)) {
5589 printf("POSIX open of %s should have failed "
5590 "with NT_STATUS_OBJECT_PATH_NOT_FOUND, "
5591 "failed with %s instead.\n",
5592 sname, nt_errstr(status));
5597 status = cli_posix_readlink(cli1, sname, namebuf, sizeof(namebuf));
5598 if (!NT_STATUS_IS_OK(status)) {
5599 printf("POSIX readlink on %s failed (%s)\n", sname, nt_errstr(status));
5603 if (strcmp(namebuf, fname) != 0) {
5604 printf("POSIX readlink on %s failed to match name %s (read %s)\n",
5605 sname, fname, namebuf);
5609 status = cli_posix_rmdir(cli1, dname);
5610 if (!NT_STATUS_IS_OK(status)) {
5611 printf("POSIX rmdir failed (%s)\n", nt_errstr(status));
5615 printf("Simple POSIX open test passed\n");
5620 if (fnum1 != (uint16_t)-1) {
5621 cli_close(cli1, fnum1);
5622 fnum1 = (uint16_t)-1;
5625 cli_setatr(cli1, sname, 0, 0);
5626 cli_posix_unlink(cli1, sname);
5627 cli_setatr(cli1, hname, 0, 0);
5628 cli_posix_unlink(cli1, hname);
5629 cli_setatr(cli1, fname, 0, 0);
5630 cli_posix_unlink(cli1, fname);
5631 cli_setatr(cli1, dname, 0, 0);
5632 cli_posix_rmdir(cli1, dname);
5634 if (!torture_close_connection(cli1)) {
5642 static uint32 open_attrs_table[] = {
5643 FILE_ATTRIBUTE_NORMAL,
5644 FILE_ATTRIBUTE_ARCHIVE,
5645 FILE_ATTRIBUTE_READONLY,
5646 FILE_ATTRIBUTE_HIDDEN,
5647 FILE_ATTRIBUTE_SYSTEM,
5649 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY,
5650 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN,
5651 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM,
5652 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
5653 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
5654 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
5656 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
5657 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
5658 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
5659 FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_SYSTEM,
5662 struct trunc_open_results {
5669 static struct trunc_open_results attr_results[] = {
5670 { 0, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
5671 { 1, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
5672 { 2, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
5673 { 16, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
5674 { 17, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
5675 { 18, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
5676 { 51, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
5677 { 54, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
5678 { 56, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
5679 { 68, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
5680 { 71, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
5681 { 73, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM },
5682 { 99, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
5683 { 102, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
5684 { 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 },
5685 { 116, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
5686 { 119, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
5687 { 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 },
5688 { 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 },
5689 { 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 },
5690 { 227, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
5691 { 230, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
5692 { 232, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
5693 { 244, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
5694 { 247, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
5695 { 249, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM }
5698 static bool run_openattrtest(int dummy)
5700 static struct cli_state *cli1;
5701 const char *fname = "\\openattr.file";
5703 bool correct = True;
5705 unsigned int i, j, k, l;
5708 printf("starting open attr test\n");
5710 if (!torture_open_connection(&cli1, 0)) {
5714 cli_sockopt(cli1, sockops);
5716 for (k = 0, i = 0; i < sizeof(open_attrs_table)/sizeof(uint32); i++) {
5717 cli_setatr(cli1, fname, 0, 0);
5718 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5720 status = cli_ntcreate(cli1, fname, 0, FILE_WRITE_DATA,
5721 open_attrs_table[i], FILE_SHARE_NONE,
5722 FILE_OVERWRITE_IF, 0, 0, &fnum1);
5723 if (!NT_STATUS_IS_OK(status)) {
5724 printf("open %d (1) of %s failed (%s)\n", i, fname, nt_errstr(status));
5728 status = cli_close(cli1, fnum1);
5729 if (!NT_STATUS_IS_OK(status)) {
5730 printf("close %d (1) of %s failed (%s)\n", i, fname, nt_errstr(status));
5734 for (j = 0; j < sizeof(open_attrs_table)/sizeof(uint32); j++) {
5735 status = cli_ntcreate(cli1, fname, 0,
5736 FILE_READ_DATA|FILE_WRITE_DATA,
5737 open_attrs_table[j],
5738 FILE_SHARE_NONE, FILE_OVERWRITE,
5740 if (!NT_STATUS_IS_OK(status)) {
5741 for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
5742 if (attr_results[l].num == k) {
5743 printf("[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(0x%x:%s)\n",
5744 k, open_attrs_table[i],
5745 open_attrs_table[j],
5746 fname, NT_STATUS_V(status), nt_errstr(status));
5751 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
5752 printf("[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s\n",
5753 k, open_attrs_table[i], open_attrs_table[j],
5758 printf("[%d] trunc open 0x%x -> 0x%x failed\n", k, open_attrs_table[i], open_attrs_table[j]);
5764 status = cli_close(cli1, fnum1);
5765 if (!NT_STATUS_IS_OK(status)) {
5766 printf("close %d (2) of %s failed (%s)\n", j, fname, nt_errstr(status));
5770 status = cli_getatr(cli1, fname, &attr, NULL, NULL);
5771 if (!NT_STATUS_IS_OK(status)) {
5772 printf("getatr(2) failed (%s)\n", nt_errstr(status));
5777 printf("[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n",
5778 k, open_attrs_table[i], open_attrs_table[j], attr );
5781 for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
5782 if (attr_results[l].num == k) {
5783 if (attr != attr_results[l].result_attr ||
5784 open_attrs_table[i] != attr_results[l].init_attr ||
5785 open_attrs_table[j] != attr_results[l].trunc_attr) {
5786 printf("getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x\n",
5787 open_attrs_table[i],
5788 open_attrs_table[j],
5790 attr_results[l].result_attr);
5800 cli_setatr(cli1, fname, 0, 0);
5801 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5803 printf("open attr test %s.\n", correct ? "passed" : "failed");
5805 if (!torture_close_connection(cli1)) {
5811 static NTSTATUS list_fn(const char *mnt, struct file_info *finfo,
5812 const char *name, void *state)
5814 int *matched = (int *)state;
5815 if (matched != NULL) {
5818 return NT_STATUS_OK;
5822 test directory listing speed
5824 static bool run_dirtest(int dummy)
5827 static struct cli_state *cli;
5829 struct timeval core_start;
5830 bool correct = True;
5833 printf("starting directory test\n");
5835 if (!torture_open_connection(&cli, 0)) {
5839 cli_sockopt(cli, sockops);
5842 for (i=0;i<torture_numops;i++) {
5844 slprintf(fname, sizeof(fname), "\\%x", (int)random());
5845 if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum))) {
5846 fprintf(stderr,"Failed to open %s\n", fname);
5849 cli_close(cli, fnum);
5852 core_start = timeval_current();
5855 cli_list(cli, "a*.*", 0, list_fn, &matched);
5856 printf("Matched %d\n", matched);
5859 cli_list(cli, "b*.*", 0, list_fn, &matched);
5860 printf("Matched %d\n", matched);
5863 cli_list(cli, "xyzabc", 0, list_fn, &matched);
5864 printf("Matched %d\n", matched);
5866 printf("dirtest core %g seconds\n", timeval_elapsed(&core_start));
5869 for (i=0;i<torture_numops;i++) {
5871 slprintf(fname, sizeof(fname), "\\%x", (int)random());
5872 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5875 if (!torture_close_connection(cli)) {
5879 printf("finished dirtest\n");
5884 static NTSTATUS del_fn(const char *mnt, struct file_info *finfo, const char *mask,
5887 struct cli_state *pcli = (struct cli_state *)state;
5889 slprintf(fname, sizeof(fname), "\\LISTDIR\\%s", finfo->name);
5891 if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
5892 return NT_STATUS_OK;
5894 if (finfo->mode & FILE_ATTRIBUTE_DIRECTORY) {
5895 if (!NT_STATUS_IS_OK(cli_rmdir(pcli, fname)))
5896 printf("del_fn: failed to rmdir %s\n,", fname );
5898 if (!NT_STATUS_IS_OK(cli_unlink(pcli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN)))
5899 printf("del_fn: failed to unlink %s\n,", fname );
5901 return NT_STATUS_OK;
5906 sees what IOCTLs are supported
5908 bool torture_ioctl_test(int dummy)
5910 static struct cli_state *cli;
5911 uint16_t device, function;
5913 const char *fname = "\\ioctl.dat";
5917 if (!torture_open_connection(&cli, 0)) {
5921 printf("starting ioctl test\n");
5923 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5925 status = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
5926 if (!NT_STATUS_IS_OK(status)) {
5927 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
5931 status = cli_raw_ioctl(cli, fnum, 0x2d0000 | (0x0420<<2), &blob);
5932 printf("ioctl device info: %s\n", nt_errstr(status));
5934 status = cli_raw_ioctl(cli, fnum, IOCTL_QUERY_JOB_INFO, &blob);
5935 printf("ioctl job info: %s\n", nt_errstr(status));
5937 for (device=0;device<0x100;device++) {
5938 printf("ioctl test with device = 0x%x\n", device);
5939 for (function=0;function<0x100;function++) {
5940 uint32 code = (device<<16) | function;
5942 status = cli_raw_ioctl(cli, fnum, code, &blob);
5944 if (NT_STATUS_IS_OK(status)) {
5945 printf("ioctl 0x%x OK : %d bytes\n", (int)code,
5947 data_blob_free(&blob);
5952 if (!torture_close_connection(cli)) {
5961 tries varients of chkpath
5963 bool torture_chkpath_test(int dummy)
5965 static struct cli_state *cli;
5970 if (!torture_open_connection(&cli, 0)) {
5974 printf("starting chkpath test\n");
5976 /* cleanup from an old run */
5977 cli_rmdir(cli, "\\chkpath.dir\\dir2");
5978 cli_unlink(cli, "\\chkpath.dir\\*", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5979 cli_rmdir(cli, "\\chkpath.dir");
5981 status = cli_mkdir(cli, "\\chkpath.dir");
5982 if (!NT_STATUS_IS_OK(status)) {
5983 printf("mkdir1 failed : %s\n", nt_errstr(status));
5987 status = cli_mkdir(cli, "\\chkpath.dir\\dir2");
5988 if (!NT_STATUS_IS_OK(status)) {
5989 printf("mkdir2 failed : %s\n", nt_errstr(status));
5993 status = cli_open(cli, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL,
5995 if (!NT_STATUS_IS_OK(status)) {
5996 printf("open1 failed (%s)\n", nt_errstr(status));
5999 cli_close(cli, fnum);
6001 status = cli_chkpath(cli, "\\chkpath.dir");
6002 if (!NT_STATUS_IS_OK(status)) {
6003 printf("chkpath1 failed: %s\n", nt_errstr(status));
6007 status = cli_chkpath(cli, "\\chkpath.dir\\dir2");
6008 if (!NT_STATUS_IS_OK(status)) {
6009 printf("chkpath2 failed: %s\n", nt_errstr(status));
6013 status = cli_chkpath(cli, "\\chkpath.dir\\foo.txt");
6014 if (!NT_STATUS_IS_OK(status)) {
6015 ret = check_error(__LINE__, status, ERRDOS, ERRbadpath,
6016 NT_STATUS_NOT_A_DIRECTORY);
6018 printf("* chkpath on a file should fail\n");
6022 status = cli_chkpath(cli, "\\chkpath.dir\\bar.txt");
6023 if (!NT_STATUS_IS_OK(status)) {
6024 ret = check_error(__LINE__, status, ERRDOS, ERRbadfile,
6025 NT_STATUS_OBJECT_NAME_NOT_FOUND);
6027 printf("* chkpath on a non existant file should fail\n");
6031 status = cli_chkpath(cli, "\\chkpath.dir\\dirxx\\bar.txt");
6032 if (!NT_STATUS_IS_OK(status)) {
6033 ret = check_error(__LINE__, status, ERRDOS, ERRbadpath,
6034 NT_STATUS_OBJECT_PATH_NOT_FOUND);
6036 printf("* chkpath on a non existent component should fail\n");
6040 cli_rmdir(cli, "\\chkpath.dir\\dir2");
6041 cli_unlink(cli, "\\chkpath.dir\\*", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
6042 cli_rmdir(cli, "\\chkpath.dir");
6044 if (!torture_close_connection(cli)) {
6051 static bool run_eatest(int dummy)
6053 static struct cli_state *cli;
6054 const char *fname = "\\eatest.txt";
6055 bool correct = True;
6059 struct ea_struct *ea_list = NULL;
6060 TALLOC_CTX *mem_ctx = talloc_init("eatest");
6063 printf("starting eatest\n");
6065 if (!torture_open_connection(&cli, 0)) {
6066 talloc_destroy(mem_ctx);
6070 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
6072 status = cli_ntcreate(cli, fname, 0,
6073 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
6074 FILE_SHARE_NONE, FILE_OVERWRITE_IF,
6076 if (!NT_STATUS_IS_OK(status)) {
6077 printf("open failed - %s\n", nt_errstr(status));
6078 talloc_destroy(mem_ctx);
6082 for (i = 0; i < 10; i++) {
6083 fstring ea_name, ea_val;
6085 slprintf(ea_name, sizeof(ea_name), "EA_%d", i);
6086 memset(ea_val, (char)i+1, i+1);
6087 status = cli_set_ea_fnum(cli, fnum, ea_name, ea_val, i+1);
6088 if (!NT_STATUS_IS_OK(status)) {
6089 printf("ea_set of name %s failed - %s\n", ea_name,
6091 talloc_destroy(mem_ctx);
6096 cli_close(cli, fnum);
6097 for (i = 0; i < 10; i++) {
6098 fstring ea_name, ea_val;
6100 slprintf(ea_name, sizeof(ea_name), "EA_%d", i+10);
6101 memset(ea_val, (char)i+1, i+1);
6102 status = cli_set_ea_path(cli, fname, ea_name, ea_val, i+1);
6103 if (!NT_STATUS_IS_OK(status)) {
6104 printf("ea_set of name %s failed - %s\n", ea_name,
6106 talloc_destroy(mem_ctx);
6111 status = cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list);
6112 if (!NT_STATUS_IS_OK(status)) {
6113 printf("ea_get list failed - %s\n", nt_errstr(status));
6117 printf("num_eas = %d\n", (int)num_eas);
6119 if (num_eas != 20) {
6120 printf("Should be 20 EA's stored... failing.\n");
6124 for (i = 0; i < num_eas; i++) {
6125 printf("%d: ea_name = %s. Val = ", i, ea_list[i].name);
6126 dump_data(0, ea_list[i].value.data,
6127 ea_list[i].value.length);
6130 /* Setting EA's to zero length deletes them. Test this */
6131 printf("Now deleting all EA's - case indepenent....\n");
6134 cli_set_ea_path(cli, fname, "", "", 0);
6136 for (i = 0; i < 20; i++) {
6138 slprintf(ea_name, sizeof(ea_name), "ea_%d", i);
6139 status = cli_set_ea_path(cli, fname, ea_name, "", 0);
6140 if (!NT_STATUS_IS_OK(status)) {
6141 printf("ea_set of name %s failed - %s\n", ea_name,
6143 talloc_destroy(mem_ctx);
6149 status = cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list);
6150 if (!NT_STATUS_IS_OK(status)) {
6151 printf("ea_get list failed - %s\n", nt_errstr(status));
6155 printf("num_eas = %d\n", (int)num_eas);
6156 for (i = 0; i < num_eas; i++) {
6157 printf("%d: ea_name = %s. Val = ", i, ea_list[i].name);
6158 dump_data(0, ea_list[i].value.data,
6159 ea_list[i].value.length);
6163 printf("deleting EA's failed.\n");
6167 /* Try and delete a non existant EA. */
6168 status = cli_set_ea_path(cli, fname, "foo", "", 0);
6169 if (!NT_STATUS_IS_OK(status)) {
6170 printf("deleting non-existant EA 'foo' should succeed. %s\n",
6175 talloc_destroy(mem_ctx);
6176 if (!torture_close_connection(cli)) {
6183 static bool run_dirtest1(int dummy)
6186 static struct cli_state *cli;
6189 bool correct = True;
6191 printf("starting directory test\n");
6193 if (!torture_open_connection(&cli, 0)) {
6197 cli_sockopt(cli, sockops);
6199 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
6200 cli_list(cli, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, del_fn, cli);
6201 cli_rmdir(cli, "\\LISTDIR");
6202 cli_mkdir(cli, "\\LISTDIR");
6204 /* Create 1000 files and 1000 directories. */
6205 for (i=0;i<1000;i++) {
6207 slprintf(fname, sizeof(fname), "\\LISTDIR\\f%d", i);
6208 if (!NT_STATUS_IS_OK(cli_ntcreate(cli, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
6209 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum))) {
6210 fprintf(stderr,"Failed to open %s\n", fname);
6213 cli_close(cli, fnum);
6215 for (i=0;i<1000;i++) {
6217 slprintf(fname, sizeof(fname), "\\LISTDIR\\d%d", i);
6218 if (!NT_STATUS_IS_OK(cli_mkdir(cli, fname))) {
6219 fprintf(stderr,"Failed to open %s\n", fname);
6224 /* Now ensure that doing an old list sees both files and directories. */
6226 cli_list_old(cli, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, list_fn, &num_seen);
6227 printf("num_seen = %d\n", num_seen );
6228 /* We should see 100 files + 1000 directories + . and .. */
6229 if (num_seen != 2002)
6232 /* Ensure if we have the "must have" bits we only see the
6236 cli_list_old(cli, "\\LISTDIR\\*", (FILE_ATTRIBUTE_DIRECTORY<<8)|FILE_ATTRIBUTE_DIRECTORY, list_fn, &num_seen);
6237 printf("num_seen = %d\n", num_seen );
6238 if (num_seen != 1002)
6242 cli_list_old(cli, "\\LISTDIR\\*", (FILE_ATTRIBUTE_ARCHIVE<<8)|FILE_ATTRIBUTE_DIRECTORY, list_fn, &num_seen);
6243 printf("num_seen = %d\n", num_seen );
6244 if (num_seen != 1000)
6247 /* Delete everything. */
6248 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
6249 cli_list(cli, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, del_fn, cli);
6250 cli_rmdir(cli, "\\LISTDIR");
6253 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
6254 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
6255 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
6258 if (!torture_close_connection(cli)) {
6262 printf("finished dirtest1\n");
6267 static bool run_error_map_extract(int dummy) {
6269 static struct cli_state *c_dos;
6270 static struct cli_state *c_nt;
6282 /* NT-Error connection */
6284 if (!(c_nt = open_nbt_connection())) {
6288 c_nt->use_spnego = False;
6290 status = cli_negprot(c_nt);
6292 if (!NT_STATUS_IS_OK(status)) {
6293 printf("%s rejected the NT-error negprot (%s)\n", host,
6299 status = cli_session_setup(c_nt, "", "", 0, "", 0, workgroup);
6300 if (!NT_STATUS_IS_OK(status)) {
6301 printf("%s rejected the NT-error initial session setup (%s)\n",host, nt_errstr(status));
6305 /* DOS-Error connection */
6307 if (!(c_dos = open_nbt_connection())) {
6311 c_dos->use_spnego = False;
6312 c_dos->force_dos_errors = True;
6314 status = cli_negprot(c_dos);
6315 if (!NT_STATUS_IS_OK(status)) {
6316 printf("%s rejected the DOS-error negprot (%s)\n", host,
6318 cli_shutdown(c_dos);
6322 status = cli_session_setup(c_dos, "", "", 0, "", 0, workgroup);
6323 if (!NT_STATUS_IS_OK(status)) {
6324 printf("%s rejected the DOS-error initial session setup (%s)\n",
6325 host, nt_errstr(status));
6329 for (error=(0xc0000000 | 0x1); error < (0xc0000000| 0xFFF); error++) {
6330 fstr_sprintf(user, "%X", error);
6332 status = cli_session_setup(c_nt, user,
6333 password, strlen(password),
6334 password, strlen(password),
6336 if (NT_STATUS_IS_OK(status)) {
6337 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
6340 /* Case #1: 32-bit NT errors */
6341 if (cli_is_nt_error(c_nt)) {
6342 nt_status = cli_nt_error(c_nt);
6344 printf("/** Dos error on NT connection! (%s) */\n",
6346 nt_status = NT_STATUS(0xc0000000);
6349 status = cli_session_setup(c_dos, user,
6350 password, strlen(password),
6351 password, strlen(password),
6353 if (NT_STATUS_IS_OK(status)) {
6354 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
6357 /* Case #1: 32-bit NT errors */
6358 if (!cli_is_dos_error(c_dos)) {
6359 printf("/** NT error on DOS connection! (%s) */\n",
6361 errnum = errclass = 0;
6363 cli_dos_error(c_dos, &errclass, &errnum);
6366 if (NT_STATUS_V(nt_status) != error) {
6367 printf("/*\t{ This NT error code was 'sqashed'\n\t from %s to %s \n\t during the session setup }\n*/\n",
6368 get_nt_error_c_code(talloc_tos(), NT_STATUS(error)),
6369 get_nt_error_c_code(talloc_tos(), nt_status));
6372 printf("\t{%s,\t%s,\t%s},\n",
6373 smb_dos_err_class(errclass),
6374 smb_dos_err_name(errclass, errnum),
6375 get_nt_error_c_code(talloc_tos(), NT_STATUS(error)));
6380 static bool run_sesssetup_bench(int dummy)
6382 static struct cli_state *c;
6383 const char *fname = "\\file.dat";
6388 if (!torture_open_connection(&c, 0)) {
6392 status = cli_ntcreate(c, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
6393 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
6394 FILE_DELETE_ON_CLOSE, 0, &fnum);
6395 if (!NT_STATUS_IS_OK(status)) {
6396 d_printf("open %s failed: %s\n", fname, nt_errstr(status));
6400 for (i=0; i<torture_numops; i++) {
6401 status = cli_session_setup(
6403 password, strlen(password),
6404 password, strlen(password),
6406 if (!NT_STATUS_IS_OK(status)) {
6407 d_printf("(%s) cli_session_setup failed: %s\n",
6408 __location__, nt_errstr(status));
6412 d_printf("\r%d ", (int)cli_state_get_uid(c));
6414 status = cli_ulogoff(c);
6415 if (!NT_STATUS_IS_OK(status)) {
6416 d_printf("(%s) cli_ulogoff failed: %s\n",
6417 __location__, nt_errstr(status));
6425 static bool subst_test(const char *str, const char *user, const char *domain,
6426 uid_t uid, gid_t gid, const char *expected)
6431 subst = talloc_sub_specified(talloc_tos(), str, user, domain, uid, gid);
6433 if (strcmp(subst, expected) != 0) {
6434 printf("sub_specified(%s, %s, %s, %d, %d) returned [%s], expected "
6435 "[%s]\n", str, user, domain, (int)uid, (int)gid, subst,
6444 static void chain1_open_completion(struct tevent_req *req)
6448 status = cli_open_recv(req, &fnum);
6451 d_printf("cli_open_recv returned %s: %d\n",
6453 NT_STATUS_IS_OK(status) ? fnum : -1);
6456 static void chain1_write_completion(struct tevent_req *req)
6460 status = cli_write_andx_recv(req, &written);
6463 d_printf("cli_write_andx_recv returned %s: %d\n",
6465 NT_STATUS_IS_OK(status) ? (int)written : -1);
6468 static void chain1_close_completion(struct tevent_req *req)
6471 bool *done = (bool *)tevent_req_callback_data_void(req);
6473 status = cli_close_recv(req);
6478 d_printf("cli_close returned %s\n", nt_errstr(status));
6481 static bool run_chain1(int dummy)
6483 struct cli_state *cli1;
6484 struct event_context *evt = event_context_init(NULL);
6485 struct tevent_req *reqs[3], *smbreqs[3];
6487 const char *str = "foobar";
6490 printf("starting chain1 test\n");
6491 if (!torture_open_connection(&cli1, 0)) {
6495 cli_sockopt(cli1, sockops);
6497 reqs[0] = cli_open_create(talloc_tos(), evt, cli1, "\\test",
6498 O_CREAT|O_RDWR, 0, &smbreqs[0]);
6499 if (reqs[0] == NULL) return false;
6500 tevent_req_set_callback(reqs[0], chain1_open_completion, NULL);
6503 reqs[1] = cli_write_andx_create(talloc_tos(), evt, cli1, 0, 0,
6504 (const uint8_t *)str, 0, strlen(str)+1,
6505 smbreqs, 1, &smbreqs[1]);
6506 if (reqs[1] == NULL) return false;
6507 tevent_req_set_callback(reqs[1], chain1_write_completion, NULL);
6509 reqs[2] = cli_close_create(talloc_tos(), evt, cli1, 0, &smbreqs[2]);
6510 if (reqs[2] == NULL) return false;
6511 tevent_req_set_callback(reqs[2], chain1_close_completion, &done);
6513 status = cli_smb_chain_send(smbreqs, ARRAY_SIZE(smbreqs));
6514 if (!NT_STATUS_IS_OK(status)) {
6519 event_loop_once(evt);
6522 torture_close_connection(cli1);
6526 static void chain2_sesssetup_completion(struct tevent_req *req)
6529 status = cli_session_setup_guest_recv(req);
6530 d_printf("sesssetup returned %s\n", nt_errstr(status));
6533 static void chain2_tcon_completion(struct tevent_req *req)
6535 bool *done = (bool *)tevent_req_callback_data_void(req);
6537 status = cli_tcon_andx_recv(req);
6538 d_printf("tcon_and_x returned %s\n", nt_errstr(status));
6542 static bool run_chain2(int dummy)
6544 struct cli_state *cli1;
6545 struct event_context *evt = event_context_init(NULL);
6546 struct tevent_req *reqs[2], *smbreqs[2];
6550 printf("starting chain2 test\n");
6551 status = cli_start_connection(&cli1, lp_netbios_name(), host, NULL,
6552 port_to_use, Undefined, 0);
6553 if (!NT_STATUS_IS_OK(status)) {
6557 cli_sockopt(cli1, sockops);
6559 reqs[0] = cli_session_setup_guest_create(talloc_tos(), evt, cli1,
6561 if (reqs[0] == NULL) return false;
6562 tevent_req_set_callback(reqs[0], chain2_sesssetup_completion, NULL);
6564 reqs[1] = cli_tcon_andx_create(talloc_tos(), evt, cli1, "IPC$",
6565 "?????", NULL, 0, &smbreqs[1]);
6566 if (reqs[1] == NULL) return false;
6567 tevent_req_set_callback(reqs[1], chain2_tcon_completion, &done);
6569 status = cli_smb_chain_send(smbreqs, ARRAY_SIZE(smbreqs));
6570 if (!NT_STATUS_IS_OK(status)) {
6575 event_loop_once(evt);
6578 torture_close_connection(cli1);
6583 struct torture_createdel_state {
6584 struct tevent_context *ev;
6585 struct cli_state *cli;
6588 static void torture_createdel_created(struct tevent_req *subreq);
6589 static void torture_createdel_closed(struct tevent_req *subreq);
6591 static struct tevent_req *torture_createdel_send(TALLOC_CTX *mem_ctx,
6592 struct tevent_context *ev,
6593 struct cli_state *cli,
6596 struct tevent_req *req, *subreq;
6597 struct torture_createdel_state *state;
6599 req = tevent_req_create(mem_ctx, &state,
6600 struct torture_createdel_state);
6607 subreq = cli_ntcreate_send(
6608 state, ev, cli, name, 0,
6609 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
6610 FILE_ATTRIBUTE_NORMAL,
6611 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
6612 FILE_OPEN_IF, FILE_DELETE_ON_CLOSE, 0);
6614 if (tevent_req_nomem(subreq, req)) {
6615 return tevent_req_post(req, ev);
6617 tevent_req_set_callback(subreq, torture_createdel_created, req);
6621 static void torture_createdel_created(struct tevent_req *subreq)
6623 struct tevent_req *req = tevent_req_callback_data(
6624 subreq, struct tevent_req);
6625 struct torture_createdel_state *state = tevent_req_data(
6626 req, struct torture_createdel_state);
6630 status = cli_ntcreate_recv(subreq, &fnum);
6631 TALLOC_FREE(subreq);
6632 if (!NT_STATUS_IS_OK(status)) {
6633 DEBUG(10, ("cli_ntcreate_recv returned %s\n",
6634 nt_errstr(status)));
6635 tevent_req_nterror(req, status);
6639 subreq = cli_close_send(state, state->ev, state->cli, fnum);
6640 if (tevent_req_nomem(subreq, req)) {
6643 tevent_req_set_callback(subreq, torture_createdel_closed, req);
6646 static void torture_createdel_closed(struct tevent_req *subreq)
6648 struct tevent_req *req = tevent_req_callback_data(
6649 subreq, struct tevent_req);
6652 status = cli_close_recv(subreq);
6653 if (!NT_STATUS_IS_OK(status)) {
6654 DEBUG(10, ("cli_close_recv returned %s\n", nt_errstr(status)));
6655 tevent_req_nterror(req, status);
6658 tevent_req_done(req);
6661 static NTSTATUS torture_createdel_recv(struct tevent_req *req)
6663 return tevent_req_simple_recv_ntstatus(req);
6666 struct torture_createdels_state {
6667 struct tevent_context *ev;
6668 struct cli_state *cli;
6669 const char *base_name;
6673 struct tevent_req **reqs;
6676 static void torture_createdels_done(struct tevent_req *subreq);
6678 static struct tevent_req *torture_createdels_send(TALLOC_CTX *mem_ctx,
6679 struct tevent_context *ev,
6680 struct cli_state *cli,
6681 const char *base_name,
6685 struct tevent_req *req;
6686 struct torture_createdels_state *state;
6689 req = tevent_req_create(mem_ctx, &state,
6690 struct torture_createdels_state);
6696 state->base_name = talloc_strdup(state, base_name);
6697 if (tevent_req_nomem(state->base_name, req)) {
6698 return tevent_req_post(req, ev);
6700 state->num_files = MAX(num_parallel, num_files);
6702 state->received = 0;
6704 state->reqs = talloc_array(state, struct tevent_req *, num_parallel);
6705 if (tevent_req_nomem(state->reqs, req)) {
6706 return tevent_req_post(req, ev);
6709 for (i=0; i<num_parallel; i++) {
6712 name = talloc_asprintf(state, "%s%8.8d", state->base_name,
6714 if (tevent_req_nomem(name, req)) {
6715 return tevent_req_post(req, ev);
6717 state->reqs[i] = torture_createdel_send(
6718 state->reqs, state->ev, state->cli, name);
6719 if (tevent_req_nomem(state->reqs[i], req)) {
6720 return tevent_req_post(req, ev);
6722 name = talloc_move(state->reqs[i], &name);
6723 tevent_req_set_callback(state->reqs[i],
6724 torture_createdels_done, req);
6730 static void torture_createdels_done(struct tevent_req *subreq)
6732 struct tevent_req *req = tevent_req_callback_data(
6733 subreq, struct tevent_req);
6734 struct torture_createdels_state *state = tevent_req_data(
6735 req, struct torture_createdels_state);
6736 size_t num_parallel = talloc_array_length(state->reqs);
6741 status = torture_createdel_recv(subreq);
6742 if (!NT_STATUS_IS_OK(status)){
6743 DEBUG(10, ("torture_createdel_recv returned %s\n",
6744 nt_errstr(status)));
6745 TALLOC_FREE(subreq);
6746 tevent_req_nterror(req, status);
6750 for (i=0; i<num_parallel; i++) {
6751 if (subreq == state->reqs[i]) {
6755 if (i == num_parallel) {
6756 DEBUG(10, ("received something we did not send\n"));
6757 tevent_req_nterror(req, NT_STATUS_INTERNAL_ERROR);
6760 TALLOC_FREE(state->reqs[i]);
6762 if (state->sent >= state->num_files) {
6763 tevent_req_done(req);
6767 name = talloc_asprintf(state, "%s%8.8d", state->base_name,
6769 if (tevent_req_nomem(name, req)) {
6772 state->reqs[i] = torture_createdel_send(state->reqs, state->ev,
6774 if (tevent_req_nomem(state->reqs[i], req)) {
6777 name = talloc_move(state->reqs[i], &name);
6778 tevent_req_set_callback(state->reqs[i], torture_createdels_done, req);
6782 static NTSTATUS torture_createdels_recv(struct tevent_req *req)
6784 return tevent_req_simple_recv_ntstatus(req);
6787 struct swallow_notify_state {
6788 struct tevent_context *ev;
6789 struct cli_state *cli;
6791 uint32_t completion_filter;
6793 bool (*fn)(uint32_t action, const char *name, void *priv);
6797 static void swallow_notify_done(struct tevent_req *subreq);
6799 static struct tevent_req *swallow_notify_send(TALLOC_CTX *mem_ctx,
6800 struct tevent_context *ev,
6801 struct cli_state *cli,
6803 uint32_t completion_filter,
6805 bool (*fn)(uint32_t action,
6810 struct tevent_req *req, *subreq;
6811 struct swallow_notify_state *state;
6813 req = tevent_req_create(mem_ctx, &state,
6814 struct swallow_notify_state);
6821 state->completion_filter = completion_filter;
6822 state->recursive = recursive;
6826 subreq = cli_notify_send(state, state->ev, state->cli, state->fnum,
6827 0xffff, state->completion_filter,
6829 if (tevent_req_nomem(subreq, req)) {
6830 return tevent_req_post(req, ev);
6832 tevent_req_set_callback(subreq, swallow_notify_done, req);
6836 static void swallow_notify_done(struct tevent_req *subreq)
6838 struct tevent_req *req = tevent_req_callback_data(
6839 subreq, struct tevent_req);
6840 struct swallow_notify_state *state = tevent_req_data(
6841 req, struct swallow_notify_state);
6843 uint32_t i, num_changes;
6844 struct notify_change *changes;
6846 status = cli_notify_recv(subreq, state, &num_changes, &changes);
6847 TALLOC_FREE(subreq);
6848 if (!NT_STATUS_IS_OK(status)) {
6849 DEBUG(10, ("cli_notify_recv returned %s\n",
6850 nt_errstr(status)));
6851 tevent_req_nterror(req, status);
6855 for (i=0; i<num_changes; i++) {
6856 state->fn(changes[i].action, changes[i].name, state->priv);
6858 TALLOC_FREE(changes);
6860 subreq = cli_notify_send(state, state->ev, state->cli, state->fnum,
6861 0xffff, state->completion_filter,
6863 if (tevent_req_nomem(subreq, req)) {
6866 tevent_req_set_callback(subreq, swallow_notify_done, req);
6869 static bool print_notifies(uint32_t action, const char *name, void *priv)
6871 if (DEBUGLEVEL > 5) {
6872 d_printf("%d %s\n", (int)action, name);
6877 static void notify_bench_done(struct tevent_req *req)
6879 int *num_finished = (int *)tevent_req_callback_data_void(req);
6883 static bool run_notify_bench(int dummy)
6885 const char *dname = "\\notify-bench";
6886 struct tevent_context *ev;
6889 struct tevent_req *req1;
6890 struct tevent_req *req2 = NULL;
6891 int i, num_unc_names;
6892 int num_finished = 0;
6894 printf("starting notify-bench test\n");
6896 if (use_multishare_conn) {
6898 unc_list = file_lines_load(multishare_conn_fname,
6899 &num_unc_names, 0, NULL);
6900 if (!unc_list || num_unc_names <= 0) {
6901 d_printf("Failed to load unc names list from '%s'\n",
6902 multishare_conn_fname);
6905 TALLOC_FREE(unc_list);
6910 ev = tevent_context_init(talloc_tos());
6912 d_printf("tevent_context_init failed\n");
6916 for (i=0; i<num_unc_names; i++) {
6917 struct cli_state *cli;
6920 base_fname = talloc_asprintf(talloc_tos(), "%s\\file%3.3d.",
6922 if (base_fname == NULL) {
6926 if (!torture_open_connection(&cli, i)) {
6930 status = cli_ntcreate(cli, dname, 0,
6931 MAXIMUM_ALLOWED_ACCESS,
6932 0, FILE_SHARE_READ|FILE_SHARE_WRITE|
6934 FILE_OPEN_IF, FILE_DIRECTORY_FILE, 0,
6937 if (!NT_STATUS_IS_OK(status)) {
6938 d_printf("Could not create %s: %s\n", dname,
6943 req1 = swallow_notify_send(talloc_tos(), ev, cli, dnum,
6944 FILE_NOTIFY_CHANGE_FILE_NAME |
6945 FILE_NOTIFY_CHANGE_DIR_NAME |
6946 FILE_NOTIFY_CHANGE_ATTRIBUTES |
6947 FILE_NOTIFY_CHANGE_LAST_WRITE,
6948 false, print_notifies, NULL);
6950 d_printf("Could not create notify request\n");
6954 req2 = torture_createdels_send(talloc_tos(), ev, cli,
6955 base_fname, 10, torture_numops);
6957 d_printf("Could not create createdels request\n");
6960 TALLOC_FREE(base_fname);
6962 tevent_req_set_callback(req2, notify_bench_done,
6966 while (num_finished < num_unc_names) {
6968 ret = tevent_loop_once(ev);
6970 d_printf("tevent_loop_once failed\n");
6975 if (!tevent_req_poll(req2, ev)) {
6976 d_printf("tevent_req_poll failed\n");
6979 status = torture_createdels_recv(req2);
6980 d_printf("torture_createdels_recv returned %s\n", nt_errstr(status));
6985 static bool run_mangle1(int dummy)
6987 struct cli_state *cli;
6988 const char *fname = "this_is_a_long_fname_to_be_mangled.txt";
6992 time_t change_time, access_time, write_time;
6996 printf("starting mangle1 test\n");
6997 if (!torture_open_connection(&cli, 0)) {
7001 cli_sockopt(cli, sockops);
7003 status = cli_ntcreate(cli, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
7004 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
7006 if (!NT_STATUS_IS_OK(status)) {
7007 d_printf("open %s failed: %s\n", fname, nt_errstr(status));
7010 cli_close(cli, fnum);
7012 status = cli_qpathinfo_alt_name(cli, fname, alt_name);
7013 if (!NT_STATUS_IS_OK(status)) {
7014 d_printf("cli_qpathinfo_alt_name failed: %s\n",
7018 d_printf("alt_name: %s\n", alt_name);
7020 status = cli_open(cli, alt_name, O_RDONLY, DENY_NONE, &fnum);
7021 if (!NT_STATUS_IS_OK(status)) {
7022 d_printf("cli_open(%s) failed: %s\n", alt_name,
7026 cli_close(cli, fnum);
7028 status = cli_qpathinfo1(cli, alt_name, &change_time, &access_time,
7029 &write_time, &size, &mode);
7030 if (!NT_STATUS_IS_OK(status)) {
7031 d_printf("cli_qpathinfo1(%s) failed: %s\n", alt_name,
7039 static size_t null_source(uint8_t *buf, size_t n, void *priv)
7041 size_t *to_pull = (size_t *)priv;
7042 size_t thistime = *to_pull;
7044 thistime = MIN(thistime, n);
7045 if (thistime == 0) {
7049 memset(buf, 0, thistime);
7050 *to_pull -= thistime;
7054 static bool run_windows_write(int dummy)
7056 struct cli_state *cli1;
7060 const char *fname = "\\writetest.txt";
7061 struct timeval start_time;
7066 printf("starting windows_write test\n");
7067 if (!torture_open_connection(&cli1, 0)) {
7071 status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
7072 if (!NT_STATUS_IS_OK(status)) {
7073 printf("open failed (%s)\n", nt_errstr(status));
7077 cli_sockopt(cli1, sockops);
7079 start_time = timeval_current();
7081 for (i=0; i<torture_numops; i++) {
7083 off_t start = i * torture_blocksize;
7084 size_t to_pull = torture_blocksize - 1;
7086 status = cli_writeall(cli1, fnum, 0, &c,
7087 start + torture_blocksize - 1, 1, NULL);
7088 if (!NT_STATUS_IS_OK(status)) {
7089 printf("cli_write failed: %s\n", nt_errstr(status));
7093 status = cli_push(cli1, fnum, 0, i * torture_blocksize, torture_blocksize,
7094 null_source, &to_pull);
7095 if (!NT_STATUS_IS_OK(status)) {
7096 printf("cli_push returned: %s\n", nt_errstr(status));
7101 seconds = timeval_elapsed(&start_time);
7102 kbytes = (double)torture_blocksize * torture_numops;
7105 printf("Wrote %d kbytes in %.2f seconds: %d kb/sec\n", (int)kbytes,
7106 (double)seconds, (int)(kbytes/seconds));
7110 cli_close(cli1, fnum);
7111 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7112 torture_close_connection(cli1);
7116 static bool run_cli_echo(int dummy)
7118 struct cli_state *cli;
7121 printf("starting cli_echo test\n");
7122 if (!torture_open_connection(&cli, 0)) {
7125 cli_sockopt(cli, sockops);
7127 status = cli_echo(cli, 5, data_blob_const("hello", 5));
7129 d_printf("cli_echo returned %s\n", nt_errstr(status));
7131 torture_close_connection(cli);
7132 return NT_STATUS_IS_OK(status);
7135 static bool run_uid_regression_test(int dummy)
7137 static struct cli_state *cli;
7140 bool correct = True;
7143 printf("starting uid regression test\n");
7145 if (!torture_open_connection(&cli, 0)) {
7149 cli_sockopt(cli, sockops);
7151 /* Ok - now save then logoff our current user. */
7152 old_vuid = cli_state_get_uid(cli);
7154 status = cli_ulogoff(cli);
7155 if (!NT_STATUS_IS_OK(status)) {
7156 d_printf("(%s) cli_ulogoff failed: %s\n",
7157 __location__, nt_errstr(status));
7162 cli_state_set_uid(cli, old_vuid);
7164 /* Try an operation. */
7165 status = cli_mkdir(cli, "\\uid_reg_test");
7166 if (NT_STATUS_IS_OK(status)) {
7167 d_printf("(%s) cli_mkdir succeeded\n",
7172 /* Should be bad uid. */
7173 if (!check_error(__LINE__, status, ERRSRV, ERRbaduid,
7174 NT_STATUS_USER_SESSION_DELETED)) {
7180 old_cnum = cli_state_get_tid(cli);
7182 /* Now try a SMBtdis with the invald vuid set to zero. */
7183 cli_state_set_uid(cli, 0);
7185 /* This should succeed. */
7186 status = cli_tdis(cli);
7188 if (NT_STATUS_IS_OK(status)) {
7189 d_printf("First tdis with invalid vuid should succeed.\n");
7191 d_printf("First tdis failed (%s)\n", nt_errstr(status));
7196 cli_state_set_uid(cli, old_vuid);
7197 cli_state_set_tid(cli, old_cnum);
7199 /* This should fail. */
7200 status = cli_tdis(cli);
7201 if (NT_STATUS_IS_OK(status)) {
7202 d_printf("Second tdis with invalid vuid should fail - succeeded instead !.\n");
7206 /* Should be bad tid. */
7207 if (!check_error(__LINE__, status, ERRSRV, ERRinvnid,
7208 NT_STATUS_NETWORK_NAME_DELETED)) {
7214 cli_rmdir(cli, "\\uid_reg_test");
7223 static const char *illegal_chars = "*\\/?<>|\":";
7224 static char force_shortname_chars[] = " +,.[];=\177";
7226 static NTSTATUS shortname_del_fn(const char *mnt, struct file_info *finfo,
7227 const char *mask, void *state)
7229 struct cli_state *pcli = (struct cli_state *)state;
7231 NTSTATUS status = NT_STATUS_OK;
7233 slprintf(fname, sizeof(fname), "\\shortname\\%s", finfo->name);
7235 if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
7236 return NT_STATUS_OK;
7238 if (finfo->mode & FILE_ATTRIBUTE_DIRECTORY) {
7239 status = cli_rmdir(pcli, fname);
7240 if (!NT_STATUS_IS_OK(status)) {
7241 printf("del_fn: failed to rmdir %s\n,", fname );
7244 status = cli_unlink(pcli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7245 if (!NT_STATUS_IS_OK(status)) {
7246 printf("del_fn: failed to unlink %s\n,", fname );
7258 static NTSTATUS shortname_list_fn(const char *mnt, struct file_info *finfo,
7259 const char *name, void *state)
7261 struct sn_state *s = (struct sn_state *)state;
7265 printf("shortname list: i = %d, name = |%s|, shortname = |%s|\n",
7266 i, finfo->name, finfo->short_name);
7269 if (strchr(force_shortname_chars, i)) {
7270 if (!finfo->short_name) {
7271 /* Shortname not created when it should be. */
7272 d_printf("(%s) ERROR: Shortname was not created for file %s containing %d\n",
7273 __location__, finfo->name, i);
7276 } else if (finfo->short_name){
7277 /* Shortname created when it should not be. */
7278 d_printf("(%s) ERROR: Shortname %s was created for file %s\n",
7279 __location__, finfo->short_name, finfo->name);
7283 return NT_STATUS_OK;
7286 static bool run_shortname_test(int dummy)
7288 static struct cli_state *cli;
7289 bool correct = True;
7295 printf("starting shortname test\n");
7297 if (!torture_open_connection(&cli, 0)) {
7301 cli_sockopt(cli, sockops);
7303 cli_list(cli, "\\shortname\\*", 0, shortname_del_fn, cli);
7304 cli_list(cli, "\\shortname\\*", FILE_ATTRIBUTE_DIRECTORY, shortname_del_fn, cli);
7305 cli_rmdir(cli, "\\shortname");
7307 status = cli_mkdir(cli, "\\shortname");
7308 if (!NT_STATUS_IS_OK(status)) {
7309 d_printf("(%s) cli_mkdir of \\shortname failed: %s\n",
7310 __location__, nt_errstr(status));
7315 strlcpy(fname, "\\shortname\\", sizeof(fname));
7316 strlcat(fname, "test .txt", sizeof(fname));
7320 for (i = 32; i < 128; i++) {
7321 uint16_t fnum = (uint16_t)-1;
7325 if (strchr(illegal_chars, i)) {
7330 status = cli_ntcreate(cli, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
7331 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum);
7332 if (!NT_STATUS_IS_OK(status)) {
7333 d_printf("(%s) cli_nt_create of %s failed: %s\n",
7334 __location__, fname, nt_errstr(status));
7338 cli_close(cli, fnum);
7341 status = cli_list(cli, "\\shortname\\test*.*", 0,
7342 shortname_list_fn, &s);
7343 if (s.matched != 1) {
7344 d_printf("(%s) failed to list %s: %s\n",
7345 __location__, fname, nt_errstr(status));
7350 status = cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7351 if (!NT_STATUS_IS_OK(status)) {
7352 d_printf("(%s) failed to delete %s: %s\n",
7353 __location__, fname, nt_errstr(status));
7366 cli_list(cli, "\\shortname\\*", 0, shortname_del_fn, cli);
7367 cli_list(cli, "\\shortname\\*", FILE_ATTRIBUTE_DIRECTORY, shortname_del_fn, cli);
7368 cli_rmdir(cli, "\\shortname");
7369 torture_close_connection(cli);
7373 static void pagedsearch_cb(struct tevent_req *req)
7376 struct tldap_message *msg;
7379 rc = tldap_search_paged_recv(req, talloc_tos(), &msg);
7380 if (rc != TLDAP_SUCCESS) {
7381 d_printf("tldap_search_paged_recv failed: %s\n",
7382 tldap_err2string(rc));
7385 if (tldap_msg_type(msg) != TLDAP_RES_SEARCH_ENTRY) {
7389 if (!tldap_entry_dn(msg, &dn)) {
7390 d_printf("tldap_entry_dn failed\n");
7393 d_printf("%s\n", dn);
7397 static bool run_tldap(int dummy)
7399 struct tldap_context *ld;
7402 struct sockaddr_storage addr;
7403 struct tevent_context *ev;
7404 struct tevent_req *req;
7408 if (!resolve_name(host, &addr, 0, false)) {
7409 d_printf("could not find host %s\n", host);
7412 status = open_socket_out(&addr, 389, 9999, &fd);
7413 if (!NT_STATUS_IS_OK(status)) {
7414 d_printf("open_socket_out failed: %s\n", nt_errstr(status));
7418 ld = tldap_context_create(talloc_tos(), fd);
7421 d_printf("tldap_context_create failed\n");
7425 rc = tldap_fetch_rootdse(ld);
7426 if (rc != TLDAP_SUCCESS) {
7427 d_printf("tldap_fetch_rootdse failed: %s\n",
7428 tldap_errstr(talloc_tos(), ld, rc));
7432 basedn = tldap_talloc_single_attribute(
7433 tldap_rootdse(ld), "defaultNamingContext", talloc_tos());
7434 if (basedn == NULL) {
7435 d_printf("no defaultNamingContext\n");
7438 d_printf("defaultNamingContext: %s\n", basedn);
7440 ev = tevent_context_init(talloc_tos());
7442 d_printf("tevent_context_init failed\n");
7446 req = tldap_search_paged_send(talloc_tos(), ev, ld, basedn,
7447 TLDAP_SCOPE_SUB, "(objectclass=*)",
7449 NULL, 0, NULL, 0, 0, 0, 0, 5);
7451 d_printf("tldap_search_paged_send failed\n");
7454 tevent_req_set_callback(req, pagedsearch_cb, NULL);
7456 tevent_req_poll(req, ev);
7460 /* test search filters against rootDSE */
7461 filter = "(&(|(name=samba)(nextRid<=10000000)(usnChanged>=10)(samba~=ambas)(!(name=s*m*a)))"
7462 "(|(name:=samba)(name:dn:2.5.13.5:=samba)(:dn:2.5.13.5:=samba)(!(name=*samba))))";
7464 rc = tldap_search(ld, "", TLDAP_SCOPE_BASE, filter,
7465 NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0,
7466 talloc_tos(), NULL, NULL);
7467 if (rc != TLDAP_SUCCESS) {
7468 d_printf("tldap_search with complex filter failed: %s\n",
7469 tldap_errstr(talloc_tos(), ld, rc));
7477 /* Torture test to ensure no regression of :
7478 https://bugzilla.samba.org/show_bug.cgi?id=7084
7481 static bool run_dir_createtime(int dummy)
7483 struct cli_state *cli;
7484 const char *dname = "\\testdir";
7485 const char *fname = "\\testdir\\testfile";
7487 struct timespec create_time;
7488 struct timespec create_time1;
7492 if (!torture_open_connection(&cli, 0)) {
7496 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7497 cli_rmdir(cli, dname);
7499 status = cli_mkdir(cli, dname);
7500 if (!NT_STATUS_IS_OK(status)) {
7501 printf("mkdir failed: %s\n", nt_errstr(status));
7505 status = cli_qpathinfo2(cli, dname, &create_time, NULL, NULL, NULL,
7507 if (!NT_STATUS_IS_OK(status)) {
7508 printf("cli_qpathinfo2 returned %s\n",
7513 /* Sleep 3 seconds, then create a file. */
7516 status = cli_open(cli, fname, O_RDWR | O_CREAT | O_EXCL,
7518 if (!NT_STATUS_IS_OK(status)) {
7519 printf("cli_open failed: %s\n", nt_errstr(status));
7523 status = cli_qpathinfo2(cli, dname, &create_time1, NULL, NULL, NULL,
7525 if (!NT_STATUS_IS_OK(status)) {
7526 printf("cli_qpathinfo2 (2) returned %s\n",
7531 if (timespec_compare(&create_time1, &create_time)) {
7532 printf("run_dir_createtime: create time was updated (error)\n");
7534 printf("run_dir_createtime: create time was not updated (correct)\n");
7540 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7541 cli_rmdir(cli, dname);
7542 if (!torture_close_connection(cli)) {
7549 static bool run_streamerror(int dummy)
7551 struct cli_state *cli;
7552 const char *dname = "\\testdir";
7553 const char *streamname =
7554 "testdir:{4c8cc155-6c1e-11d1-8e41-00c04fb9386d}:$DATA";
7556 time_t change_time, access_time, write_time;
7558 uint16_t mode, fnum;
7561 if (!torture_open_connection(&cli, 0)) {
7565 cli_unlink(cli, "\\testdir\\*", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7566 cli_rmdir(cli, dname);
7568 status = cli_mkdir(cli, dname);
7569 if (!NT_STATUS_IS_OK(status)) {
7570 printf("mkdir failed: %s\n", nt_errstr(status));
7574 cli_qpathinfo1(cli, streamname, &change_time, &access_time, &write_time,
7576 status = cli_nt_error(cli);
7578 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
7579 printf("pathinfo returned %s, expected "
7580 "NT_STATUS_OBJECT_NAME_NOT_FOUND\n",
7585 status = cli_ntcreate(cli, streamname, 0x16,
7586 FILE_READ_DATA|FILE_READ_EA|
7587 FILE_READ_ATTRIBUTES|READ_CONTROL_ACCESS,
7588 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ,
7589 FILE_OPEN, 0, 0, &fnum);
7591 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
7592 printf("ntcreate returned %s, expected "
7593 "NT_STATUS_OBJECT_NAME_NOT_FOUND\n",
7599 cli_rmdir(cli, dname);
7603 static bool run_local_substitute(int dummy)
7607 ok &= subst_test("%U", "bla", "", -1, -1, "bla");
7608 ok &= subst_test("%u%U", "bla", "", -1, -1, "blabla");
7609 ok &= subst_test("%g", "", "", -1, -1, "NO_GROUP");
7610 ok &= subst_test("%G", "", "", -1, -1, "NO_GROUP");
7611 ok &= subst_test("%g", "", "", -1, 0, gidtoname(0));
7612 ok &= subst_test("%G", "", "", -1, 0, gidtoname(0));
7613 ok &= subst_test("%D%u", "u", "dom", -1, 0, "domu");
7614 ok &= subst_test("%i %I", "", "", -1, -1, "0.0.0.0 0.0.0.0");
7616 /* Different captialization rules in sub_basic... */
7618 ok &= (strcmp(talloc_sub_basic(talloc_tos(), "BLA", "dom", "%U%D"),
7624 static bool run_local_base64(int dummy)
7629 for (i=1; i<2000; i++) {
7630 DATA_BLOB blob1, blob2;
7633 blob1.data = talloc_array(talloc_tos(), uint8_t, i);
7635 generate_random_buffer(blob1.data, blob1.length);
7637 b64 = base64_encode_data_blob(talloc_tos(), blob1);
7639 d_fprintf(stderr, "base64_encode_data_blob failed "
7640 "for %d bytes\n", i);
7643 blob2 = base64_decode_data_blob(b64);
7646 if (data_blob_cmp(&blob1, &blob2)) {
7647 d_fprintf(stderr, "data_blob_cmp failed for %d "
7651 TALLOC_FREE(blob1.data);
7652 data_blob_free(&blob2);
7657 static bool run_local_gencache(int dummy)
7663 if (!gencache_set("foo", "bar", time(NULL) + 1000)) {
7664 d_printf("%s: gencache_set() failed\n", __location__);
7668 if (!gencache_get("foo", NULL, NULL)) {
7669 d_printf("%s: gencache_get() failed\n", __location__);
7673 if (!gencache_get("foo", &val, &tm)) {
7674 d_printf("%s: gencache_get() failed\n", __location__);
7678 if (strcmp(val, "bar") != 0) {
7679 d_printf("%s: gencache_get() returned %s, expected %s\n",
7680 __location__, val, "bar");
7687 if (!gencache_del("foo")) {
7688 d_printf("%s: gencache_del() failed\n", __location__);
7691 if (gencache_del("foo")) {
7692 d_printf("%s: second gencache_del() succeeded\n",
7697 if (gencache_get("foo", &val, &tm)) {
7698 d_printf("%s: gencache_get() on deleted entry "
7699 "succeeded\n", __location__);
7703 blob = data_blob_string_const_null("bar");
7704 tm = time(NULL) + 60;
7706 if (!gencache_set_data_blob("foo", &blob, tm)) {
7707 d_printf("%s: gencache_set_data_blob() failed\n", __location__);
7711 if (!gencache_get_data_blob("foo", &blob, NULL, NULL)) {
7712 d_printf("%s: gencache_get_data_blob() failed\n", __location__);
7716 if (strcmp((const char *)blob.data, "bar") != 0) {
7717 d_printf("%s: gencache_get_data_blob() returned %s, expected %s\n",
7718 __location__, (const char *)blob.data, "bar");
7719 data_blob_free(&blob);
7723 data_blob_free(&blob);
7725 if (!gencache_del("foo")) {
7726 d_printf("%s: gencache_del() failed\n", __location__);
7729 if (gencache_del("foo")) {
7730 d_printf("%s: second gencache_del() succeeded\n",
7735 if (gencache_get_data_blob("foo", &blob, NULL, NULL)) {
7736 d_printf("%s: gencache_get_data_blob() on deleted entry "
7737 "succeeded\n", __location__);
7744 static bool rbt_testval(struct db_context *db, const char *key,
7747 struct db_record *rec;
7748 TDB_DATA data = string_tdb_data(value);
7752 rec = db->fetch_locked(db, db, string_tdb_data(key));
7754 d_fprintf(stderr, "fetch_locked failed\n");
7757 status = rec->store(rec, data, 0);
7758 if (!NT_STATUS_IS_OK(status)) {
7759 d_fprintf(stderr, "store failed: %s\n", nt_errstr(status));
7764 rec = db->fetch_locked(db, db, string_tdb_data(key));
7766 d_fprintf(stderr, "second fetch_locked failed\n");
7769 if ((rec->value.dsize != data.dsize)
7770 || (memcmp(rec->value.dptr, data.dptr, data.dsize) != 0)) {
7771 d_fprintf(stderr, "Got wrong data back\n");
7781 static bool run_local_rbtree(int dummy)
7783 struct db_context *db;
7787 db = db_open_rbt(NULL);
7790 d_fprintf(stderr, "db_open_rbt failed\n");
7794 for (i=0; i<1000; i++) {
7797 if (asprintf(&key, "key%ld", random()) == -1) {
7800 if (asprintf(&value, "value%ld", random()) == -1) {
7805 if (!rbt_testval(db, key, value)) {
7812 if (asprintf(&value, "value%ld", random()) == -1) {
7817 if (!rbt_testval(db, key, value)) {
7836 local test for character set functions
7838 This is a very simple test for the functionality in convert_string_error()
7840 static bool run_local_convert_string(int dummy)
7842 TALLOC_CTX *tmp_ctx = talloc_new(NULL);
7843 const char *test_strings[2] = { "March", "M\303\244rz" };
7847 for (i=0; i<2; i++) {
7848 const char *str = test_strings[i];
7849 int len = strlen(str);
7850 size_t converted_size;
7853 memset(dst, 'X', sizeof(dst));
7855 /* first try with real source length */
7856 ret = convert_string_error(CH_UNIX, CH_UTF8,
7861 d_fprintf(stderr, "Failed to convert '%s' to CH_DISPLAY\n", str);
7865 if (converted_size != len) {
7866 d_fprintf(stderr, "Converted size of '%s' should be %d - got %d\n",
7867 str, len, (int)converted_size);
7871 if (strncmp(str, dst, converted_size) != 0) {
7872 d_fprintf(stderr, "Expected '%s' to match '%s'\n", str, dst);
7876 if (strlen(str) != converted_size) {
7877 d_fprintf(stderr, "Expected '%s' length %d - got %d\n", str,
7878 (int)strlen(str), (int)converted_size);
7882 if (dst[converted_size] != 'X') {
7883 d_fprintf(stderr, "Expected no termination of '%s'\n", dst);
7887 /* now with srclen==-1, this causes the nul to be
7889 ret = convert_string_error(CH_UNIX, CH_UTF8,
7894 d_fprintf(stderr, "Failed to convert '%s' to CH_DISPLAY\n", str);
7898 if (converted_size != len+1) {
7899 d_fprintf(stderr, "Converted size of '%s' should be %d - got %d\n",
7900 str, len, (int)converted_size);
7904 if (strncmp(str, dst, converted_size) != 0) {
7905 d_fprintf(stderr, "Expected '%s' to match '%s'\n", str, dst);
7909 if (len+1 != converted_size) {
7910 d_fprintf(stderr, "Expected '%s' length %d - got %d\n", str,
7911 len+1, (int)converted_size);
7915 if (dst[converted_size] != 'X') {
7916 d_fprintf(stderr, "Expected no termination of '%s'\n", dst);
7923 TALLOC_FREE(tmp_ctx);
7926 TALLOC_FREE(tmp_ctx);
7931 struct talloc_dict_test {
7935 static int talloc_dict_traverse_fn(DATA_BLOB key, void *data, void *priv)
7937 int *count = (int *)priv;
7942 static bool run_local_talloc_dict(int dummy)
7944 struct talloc_dict *dict;
7945 struct talloc_dict_test *t;
7948 dict = talloc_dict_init(talloc_tos());
7953 t = talloc(talloc_tos(), struct talloc_dict_test);
7960 if (!talloc_dict_set(dict, data_blob_const(&key, sizeof(key)), t)) {
7965 if (talloc_dict_traverse(dict, talloc_dict_traverse_fn, &count) != 0) {
7978 static bool run_local_string_to_sid(int dummy) {
7981 if (string_to_sid(&sid, "S--1-5-32-545")) {
7982 printf("allowing S--1-5-32-545\n");
7985 if (string_to_sid(&sid, "S-1-5-32-+545")) {
7986 printf("allowing S-1-5-32-+545\n");
7989 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")) {
7990 printf("allowing S-1-2-3-4-5-6-7-8-9-0-1-2-3-4-5-6-7-8-9-0\n");
7993 if (string_to_sid(&sid, "S-1-5-32-545-abc")) {
7994 printf("allowing S-1-5-32-545-abc\n");
7997 if (!string_to_sid(&sid, "S-1-5-32-545")) {
7998 printf("could not parse S-1-5-32-545\n");
8001 if (!dom_sid_equal(&sid, &global_sid_Builtin_Users)) {
8002 printf("mis-parsed S-1-5-32-545 as %s\n",
8003 sid_string_tos(&sid));
8009 static bool run_local_binary_to_sid(int dummy) {
8010 struct dom_sid *sid = talloc(NULL, struct dom_sid);
8011 static const char good_binary_sid[] = {
8012 0x1, /* revision number */
8014 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, /* id_auth */
8015 0x1, 0x1, 0x1, 0x1, /* auth[0] */
8016 0x1, 0x1, 0x1, 0x1, /* auth[1] */
8017 0x1, 0x1, 0x1, 0x1, /* auth[2] */
8018 0x1, 0x1, 0x1, 0x1, /* auth[3] */
8019 0x1, 0x1, 0x1, 0x1, /* auth[4] */
8020 0x1, 0x1, 0x1, 0x1, /* auth[5] */
8021 0x1, 0x1, 0x1, 0x1, /* auth[6] */
8022 0x1, 0x1, 0x1, 0x1, /* auth[7] */
8023 0x1, 0x1, 0x1, 0x1, /* auth[8] */
8024 0x1, 0x1, 0x1, 0x1, /* auth[9] */
8025 0x1, 0x1, 0x1, 0x1, /* auth[10] */
8026 0x1, 0x1, 0x1, 0x1, /* auth[11] */
8027 0x1, 0x1, 0x1, 0x1, /* auth[12] */
8028 0x1, 0x1, 0x1, 0x1, /* auth[13] */
8029 0x1, 0x1, 0x1, 0x1, /* auth[14] */
8032 static const char long_binary_sid[] = {
8033 0x1, /* revision number */
8035 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, /* id_auth */
8036 0x1, 0x1, 0x1, 0x1, /* auth[0] */
8037 0x1, 0x1, 0x1, 0x1, /* auth[1] */
8038 0x1, 0x1, 0x1, 0x1, /* auth[2] */
8039 0x1, 0x1, 0x1, 0x1, /* auth[3] */
8040 0x1, 0x1, 0x1, 0x1, /* auth[4] */
8041 0x1, 0x1, 0x1, 0x1, /* auth[5] */
8042 0x1, 0x1, 0x1, 0x1, /* auth[6] */
8043 0x1, 0x1, 0x1, 0x1, /* auth[7] */
8044 0x1, 0x1, 0x1, 0x1, /* auth[8] */
8045 0x1, 0x1, 0x1, 0x1, /* auth[9] */
8046 0x1, 0x1, 0x1, 0x1, /* auth[10] */
8047 0x1, 0x1, 0x1, 0x1, /* auth[11] */
8048 0x1, 0x1, 0x1, 0x1, /* auth[12] */
8049 0x1, 0x1, 0x1, 0x1, /* auth[13] */
8050 0x1, 0x1, 0x1, 0x1, /* auth[14] */
8051 0x1, 0x1, 0x1, 0x1, /* auth[15] */
8052 0x1, 0x1, 0x1, 0x1, /* auth[16] */
8053 0x1, 0x1, 0x1, 0x1, /* auth[17] */
8056 static const char long_binary_sid2[] = {
8057 0x1, /* revision number */
8059 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, /* id_auth */
8060 0x1, 0x1, 0x1, 0x1, /* auth[0] */
8061 0x1, 0x1, 0x1, 0x1, /* auth[1] */
8062 0x1, 0x1, 0x1, 0x1, /* auth[2] */
8063 0x1, 0x1, 0x1, 0x1, /* auth[3] */
8064 0x1, 0x1, 0x1, 0x1, /* auth[4] */
8065 0x1, 0x1, 0x1, 0x1, /* auth[5] */
8066 0x1, 0x1, 0x1, 0x1, /* auth[6] */
8067 0x1, 0x1, 0x1, 0x1, /* auth[7] */
8068 0x1, 0x1, 0x1, 0x1, /* auth[8] */
8069 0x1, 0x1, 0x1, 0x1, /* auth[9] */
8070 0x1, 0x1, 0x1, 0x1, /* auth[10] */
8071 0x1, 0x1, 0x1, 0x1, /* auth[11] */
8072 0x1, 0x1, 0x1, 0x1, /* auth[12] */
8073 0x1, 0x1, 0x1, 0x1, /* auth[13] */
8074 0x1, 0x1, 0x1, 0x1, /* auth[14] */
8075 0x1, 0x1, 0x1, 0x1, /* auth[15] */
8076 0x1, 0x1, 0x1, 0x1, /* auth[16] */
8077 0x1, 0x1, 0x1, 0x1, /* auth[17] */
8078 0x1, 0x1, 0x1, 0x1, /* auth[18] */
8079 0x1, 0x1, 0x1, 0x1, /* auth[19] */
8080 0x1, 0x1, 0x1, 0x1, /* auth[20] */
8081 0x1, 0x1, 0x1, 0x1, /* auth[21] */
8082 0x1, 0x1, 0x1, 0x1, /* auth[22] */
8083 0x1, 0x1, 0x1, 0x1, /* auth[23] */
8084 0x1, 0x1, 0x1, 0x1, /* auth[24] */
8085 0x1, 0x1, 0x1, 0x1, /* auth[25] */
8086 0x1, 0x1, 0x1, 0x1, /* auth[26] */
8087 0x1, 0x1, 0x1, 0x1, /* auth[27] */
8088 0x1, 0x1, 0x1, 0x1, /* auth[28] */
8089 0x1, 0x1, 0x1, 0x1, /* auth[29] */
8090 0x1, 0x1, 0x1, 0x1, /* auth[30] */
8091 0x1, 0x1, 0x1, 0x1, /* auth[31] */
8094 if (!sid_parse(good_binary_sid, sizeof(good_binary_sid), sid)) {
8097 if (sid_parse(long_binary_sid2, sizeof(long_binary_sid2), sid)) {
8100 if (sid_parse(long_binary_sid, sizeof(long_binary_sid), sid)) {
8106 /* Split a path name into filename and stream name components. Canonicalise
8107 * such that an implicit $DATA token is always explicit.
8109 * The "specification" of this function can be found in the
8110 * run_local_stream_name() function in torture.c, I've tried those
8111 * combinations against a W2k3 server.
8114 static NTSTATUS split_ntfs_stream_name(TALLOC_CTX *mem_ctx, const char *fname,
8115 char **pbase, char **pstream)
8118 char *stream = NULL;
8119 char *sname; /* stream name */
8120 const char *stype; /* stream type */
8122 DEBUG(10, ("split_ntfs_stream_name called for [%s]\n", fname));
8124 sname = strchr_m(fname, ':');
8126 if (lp_posix_pathnames() || (sname == NULL)) {
8127 if (pbase != NULL) {
8128 base = talloc_strdup(mem_ctx, fname);
8129 NT_STATUS_HAVE_NO_MEMORY(base);
8134 if (pbase != NULL) {
8135 base = talloc_strndup(mem_ctx, fname, PTR_DIFF(sname, fname));
8136 NT_STATUS_HAVE_NO_MEMORY(base);
8141 stype = strchr_m(sname, ':');
8143 if (stype == NULL) {
8144 sname = talloc_strdup(mem_ctx, sname);
8148 if (strcasecmp_m(stype, ":$DATA") != 0) {
8150 * If there is an explicit stream type, so far we only
8151 * allow $DATA. Is there anything else allowed? -- vl
8153 DEBUG(10, ("[%s] is an invalid stream type\n", stype));
8155 return NT_STATUS_OBJECT_NAME_INVALID;
8157 sname = talloc_strndup(mem_ctx, sname, PTR_DIFF(stype, sname));
8161 if (sname == NULL) {
8163 return NT_STATUS_NO_MEMORY;
8166 if (sname[0] == '\0') {
8168 * no stream name, so no stream
8173 if (pstream != NULL) {
8174 stream = talloc_asprintf(mem_ctx, "%s:%s", sname, stype);
8175 if (stream == NULL) {
8178 return NT_STATUS_NO_MEMORY;
8181 * upper-case the type field
8183 strupper_m(strchr_m(stream, ':')+1);
8187 if (pbase != NULL) {
8190 if (pstream != NULL) {
8193 return NT_STATUS_OK;
8196 static bool test_stream_name(const char *fname, const char *expected_base,
8197 const char *expected_stream,
8198 NTSTATUS expected_status)
8202 char *stream = NULL;
8204 status = split_ntfs_stream_name(talloc_tos(), fname, &base, &stream);
8205 if (!NT_STATUS_EQUAL(status, expected_status)) {
8209 if (!NT_STATUS_IS_OK(status)) {
8213 if (base == NULL) goto error;
8215 if (strcmp(expected_base, base) != 0) goto error;
8217 if ((expected_stream != NULL) && (stream == NULL)) goto error;
8218 if ((expected_stream == NULL) && (stream != NULL)) goto error;
8220 if ((stream != NULL) && (strcmp(expected_stream, stream) != 0))
8224 TALLOC_FREE(stream);
8228 d_fprintf(stderr, "Do test_stream(%s, %s, %s, %s)\n",
8229 fname, expected_base ? expected_base : "<NULL>",
8230 expected_stream ? expected_stream : "<NULL>",
8231 nt_errstr(expected_status));
8232 d_fprintf(stderr, "-> base=%s, stream=%s, status=%s\n",
8233 base ? base : "<NULL>", stream ? stream : "<NULL>",
8236 TALLOC_FREE(stream);
8240 static bool run_local_stream_name(int dummy)
8244 ret &= test_stream_name(
8245 "bla", "bla", NULL, NT_STATUS_OK);
8246 ret &= test_stream_name(
8247 "bla::$DATA", "bla", NULL, NT_STATUS_OK);
8248 ret &= test_stream_name(
8249 "bla:blub:", "bla", NULL, NT_STATUS_OBJECT_NAME_INVALID);
8250 ret &= test_stream_name(
8251 "bla::", NULL, NULL, NT_STATUS_OBJECT_NAME_INVALID);
8252 ret &= test_stream_name(
8253 "bla::123", "bla", NULL, NT_STATUS_OBJECT_NAME_INVALID);
8254 ret &= test_stream_name(
8255 "bla:$DATA", "bla", "$DATA:$DATA", NT_STATUS_OK);
8256 ret &= test_stream_name(
8257 "bla:x:$DATA", "bla", "x:$DATA", NT_STATUS_OK);
8258 ret &= test_stream_name(
8259 "bla:x", "bla", "x:$DATA", NT_STATUS_OK);
8264 static bool data_blob_equal(DATA_BLOB a, DATA_BLOB b)
8266 if (a.length != b.length) {
8267 printf("a.length=%d != b.length=%d\n",
8268 (int)a.length, (int)b.length);
8271 if (memcmp(a.data, b.data, a.length) != 0) {
8272 printf("a.data and b.data differ\n");
8278 static bool run_local_memcache(int dummy)
8280 struct memcache *cache;
8282 DATA_BLOB d1, d2, d3;
8283 DATA_BLOB v1, v2, v3;
8285 TALLOC_CTX *mem_ctx;
8287 size_t size1, size2;
8290 cache = memcache_init(NULL, 100);
8292 if (cache == NULL) {
8293 printf("memcache_init failed\n");
8297 d1 = data_blob_const("d1", 2);
8298 d2 = data_blob_const("d2", 2);
8299 d3 = data_blob_const("d3", 2);
8301 k1 = data_blob_const("d1", 2);
8302 k2 = data_blob_const("d2", 2);
8304 memcache_add(cache, STAT_CACHE, k1, d1);
8305 memcache_add(cache, GETWD_CACHE, k2, d2);
8307 if (!memcache_lookup(cache, STAT_CACHE, k1, &v1)) {
8308 printf("could not find k1\n");
8311 if (!data_blob_equal(d1, v1)) {
8315 if (!memcache_lookup(cache, GETWD_CACHE, k2, &v2)) {
8316 printf("could not find k2\n");
8319 if (!data_blob_equal(d2, v2)) {
8323 memcache_add(cache, STAT_CACHE, k1, d3);
8325 if (!memcache_lookup(cache, STAT_CACHE, k1, &v3)) {
8326 printf("could not find replaced k1\n");
8329 if (!data_blob_equal(d3, v3)) {
8333 memcache_add(cache, GETWD_CACHE, k1, d1);
8335 if (memcache_lookup(cache, GETWD_CACHE, k2, &v2)) {
8336 printf("Did find k2, should have been purged\n");
8342 cache = memcache_init(NULL, 0);
8344 mem_ctx = talloc_init("foo");
8346 str1 = talloc_strdup(mem_ctx, "string1");
8347 str2 = talloc_strdup(mem_ctx, "string2");
8349 memcache_add_talloc(cache, SINGLETON_CACHE_TALLOC,
8350 data_blob_string_const("torture"), &str1);
8351 size1 = talloc_total_size(cache);
8353 memcache_add_talloc(cache, SINGLETON_CACHE_TALLOC,
8354 data_blob_string_const("torture"), &str2);
8355 size2 = talloc_total_size(cache);
8357 printf("size1=%d, size2=%d\n", (int)size1, (int)size2);
8359 if (size2 > size1) {
8360 printf("memcache leaks memory!\n");
8370 static void wbclient_done(struct tevent_req *req)
8373 struct winbindd_response *wb_resp;
8374 int *i = (int *)tevent_req_callback_data_void(req);
8376 wbc_err = wb_trans_recv(req, req, &wb_resp);
8379 d_printf("wb_trans_recv %d returned %s\n", *i, wbcErrorString(wbc_err));
8382 static bool run_local_wbclient(int dummy)
8384 struct event_context *ev;
8385 struct wb_context **wb_ctx;
8386 struct winbindd_request wb_req;
8387 bool result = false;
8390 BlockSignals(True, SIGPIPE);
8392 ev = tevent_context_init_byname(talloc_tos(), "epoll");
8397 wb_ctx = talloc_array(ev, struct wb_context *, nprocs);
8398 if (wb_ctx == NULL) {
8402 ZERO_STRUCT(wb_req);
8403 wb_req.cmd = WINBINDD_PING;
8405 d_printf("nprocs=%d, numops=%d\n", (int)nprocs, (int)torture_numops);
8407 for (i=0; i<nprocs; i++) {
8408 wb_ctx[i] = wb_context_init(ev, NULL);
8409 if (wb_ctx[i] == NULL) {
8412 for (j=0; j<torture_numops; j++) {
8413 struct tevent_req *req;
8414 req = wb_trans_send(ev, ev, wb_ctx[i],
8415 (j % 2) == 0, &wb_req);
8419 tevent_req_set_callback(req, wbclient_done, &i);
8425 while (i < nprocs * torture_numops) {
8426 event_loop_once(ev);
8435 static void getaddrinfo_finished(struct tevent_req *req)
8437 char *name = (char *)tevent_req_callback_data_void(req);
8438 struct addrinfo *ainfo;
8441 res = getaddrinfo_recv(req, &ainfo);
8443 d_printf("gai(%s) returned %s\n", name, gai_strerror(res));
8446 d_printf("gai(%s) succeeded\n", name);
8447 freeaddrinfo(ainfo);
8450 static bool run_getaddrinfo_send(int dummy)
8452 TALLOC_CTX *frame = talloc_stackframe();
8453 struct fncall_context *ctx;
8454 struct tevent_context *ev;
8455 bool result = false;
8456 const char *names[4] = { "www.samba.org", "notfound.samba.org",
8457 "www.slashdot.org", "heise.de" };
8458 struct tevent_req *reqs[4];
8461 ev = event_context_init(frame);
8466 ctx = fncall_context_init(frame, 4);
8468 for (i=0; i<ARRAY_SIZE(names); i++) {
8469 reqs[i] = getaddrinfo_send(frame, ev, ctx, names[i], NULL,
8471 if (reqs[i] == NULL) {
8474 tevent_req_set_callback(reqs[i], getaddrinfo_finished,
8475 discard_const_p(void, names[i]));
8478 for (i=0; i<ARRAY_SIZE(reqs); i++) {
8479 tevent_loop_once(ev);
8488 static bool dbtrans_inc(struct db_context *db)
8490 struct db_record *rec;
8495 rec = db->fetch_locked(db, db, string_term_tdb_data("transtest"));
8497 printf(__location__ "fetch_lock failed\n");
8501 if (rec->value.dsize != sizeof(uint32_t)) {
8502 printf(__location__ "value.dsize = %d\n",
8503 (int)rec->value.dsize);
8507 val = (uint32_t *)rec->value.dptr;
8510 status = rec->store(rec, make_tdb_data((uint8_t *)val,
8513 if (!NT_STATUS_IS_OK(status)) {
8514 printf(__location__ "store failed: %s\n",
8525 static bool run_local_dbtrans(int dummy)
8527 struct db_context *db;
8528 struct db_record *rec;
8533 db = db_open(talloc_tos(), "transtest.tdb", 0, TDB_DEFAULT,
8534 O_RDWR|O_CREAT, 0600);
8536 printf("Could not open transtest.db\n");
8540 res = db->transaction_start(db);
8542 printf(__location__ "transaction_start failed\n");
8546 rec = db->fetch_locked(db, db, string_term_tdb_data("transtest"));
8548 printf(__location__ "fetch_lock failed\n");
8552 if (rec->value.dptr == NULL) {
8554 status = rec->store(
8555 rec, make_tdb_data((uint8_t *)&initial,
8558 if (!NT_STATUS_IS_OK(status)) {
8559 printf(__location__ "store returned %s\n",
8567 res = db->transaction_commit(db);
8569 printf(__location__ "transaction_commit failed\n");
8577 res = db->transaction_start(db);
8579 printf(__location__ "transaction_start failed\n");
8583 if (!dbwrap_fetch_uint32(db, "transtest", &val)) {
8584 printf(__location__ "dbwrap_fetch_uint32 failed\n");
8588 for (i=0; i<10; i++) {
8589 if (!dbtrans_inc(db)) {
8594 if (!dbwrap_fetch_uint32(db, "transtest", &val2)) {
8595 printf(__location__ "dbwrap_fetch_uint32 failed\n");
8599 if (val2 != val + 10) {
8600 printf(__location__ "val=%d, val2=%d\n",
8601 (int)val, (int)val2);
8605 printf("val2=%d\r", val2);
8607 res = db->transaction_commit(db);
8609 printf(__location__ "transaction_commit failed\n");
8619 * Just a dummy test to be run under a debugger. There's no real way
8620 * to inspect the tevent_select specific function from outside of
8624 static bool run_local_tevent_select(int dummy)
8626 struct tevent_context *ev;
8627 struct tevent_fd *fd1, *fd2;
8628 bool result = false;
8630 ev = tevent_context_init_byname(NULL, "select");
8632 d_fprintf(stderr, "tevent_context_init_byname failed\n");
8636 fd1 = tevent_add_fd(ev, ev, 2, 0, NULL, NULL);
8638 d_fprintf(stderr, "tevent_add_fd failed\n");
8641 fd2 = tevent_add_fd(ev, ev, 3, 0, NULL, NULL);
8643 d_fprintf(stderr, "tevent_add_fd failed\n");
8648 fd2 = tevent_add_fd(ev, ev, 1, 0, NULL, NULL);
8650 d_fprintf(stderr, "tevent_add_fd failed\n");
8660 static double create_procs(bool (*fn)(int), bool *result)
8663 volatile pid_t *child_status;
8664 volatile bool *child_status_out;
8667 struct timeval start;
8671 child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*nprocs);
8672 if (!child_status) {
8673 printf("Failed to setup shared memory\n");
8677 child_status_out = (volatile bool *)shm_setup(sizeof(bool)*nprocs);
8678 if (!child_status_out) {
8679 printf("Failed to setup result status shared memory\n");
8683 for (i = 0; i < nprocs; i++) {
8684 child_status[i] = 0;
8685 child_status_out[i] = True;
8688 start = timeval_current();
8690 for (i=0;i<nprocs;i++) {
8693 pid_t mypid = getpid();
8694 sys_srandom(((int)mypid) ^ ((int)time(NULL)));
8696 slprintf(myname,sizeof(myname),"CLIENT%d", i);
8699 if (torture_open_connection(¤t_cli, i)) break;
8701 printf("pid %d failed to start\n", (int)getpid());
8707 child_status[i] = getpid();
8709 while (child_status[i] && timeval_elapsed(&start) < 5) smb_msleep(2);
8711 child_status_out[i] = fn(i);
8718 for (i=0;i<nprocs;i++) {
8719 if (child_status[i]) synccount++;
8721 if (synccount == nprocs) break;
8723 } while (timeval_elapsed(&start) < 30);
8725 if (synccount != nprocs) {
8726 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs, synccount);
8728 return timeval_elapsed(&start);
8731 /* start the client load */
8732 start = timeval_current();
8734 for (i=0;i<nprocs;i++) {
8735 child_status[i] = 0;
8738 printf("%d clients started\n", nprocs);
8740 for (i=0;i<nprocs;i++) {
8741 while (waitpid(0, &status, 0) == -1 && errno == EINTR) /* noop */ ;
8746 for (i=0;i<nprocs;i++) {
8747 if (!child_status_out[i]) {
8751 return timeval_elapsed(&start);
8754 #define FLAG_MULTIPROC 1
8761 {"FDPASS", run_fdpasstest, 0},
8762 {"LOCK1", run_locktest1, 0},
8763 {"LOCK2", run_locktest2, 0},
8764 {"LOCK3", run_locktest3, 0},
8765 {"LOCK4", run_locktest4, 0},
8766 {"LOCK5", run_locktest5, 0},
8767 {"LOCK6", run_locktest6, 0},
8768 {"LOCK7", run_locktest7, 0},
8769 {"LOCK8", run_locktest8, 0},
8770 {"LOCK9", run_locktest9, 0},
8771 {"UNLINK", run_unlinktest, 0},
8772 {"BROWSE", run_browsetest, 0},
8773 {"ATTR", run_attrtest, 0},
8774 {"TRANS2", run_trans2test, 0},
8775 {"MAXFID", run_maxfidtest, FLAG_MULTIPROC},
8776 {"TORTURE",run_torture, FLAG_MULTIPROC},
8777 {"RANDOMIPC", run_randomipc, 0},
8778 {"NEGNOWAIT", run_negprot_nowait, 0},
8779 {"NBENCH", run_nbench, 0},
8780 {"NBENCH2", run_nbench2, 0},
8781 {"OPLOCK1", run_oplock1, 0},
8782 {"OPLOCK2", run_oplock2, 0},
8783 {"OPLOCK4", run_oplock4, 0},
8784 {"DIR", run_dirtest, 0},
8785 {"DIR1", run_dirtest1, 0},
8786 {"DIR-CREATETIME", run_dir_createtime, 0},
8787 {"DENY1", torture_denytest1, 0},
8788 {"DENY2", torture_denytest2, 0},
8789 {"TCON", run_tcon_test, 0},
8790 {"TCONDEV", run_tcon_devtype_test, 0},
8791 {"RW1", run_readwritetest, 0},
8792 {"RW2", run_readwritemulti, FLAG_MULTIPROC},
8793 {"RW3", run_readwritelarge, 0},
8794 {"RW-SIGNING", run_readwritelarge_signtest, 0},
8795 {"OPEN", run_opentest, 0},
8796 {"POSIX", run_simple_posix_open_test, 0},
8797 {"POSIX-APPEND", run_posix_append, 0},
8798 {"CASE-INSENSITIVE-CREATE", run_case_insensitive_create, 0},
8799 {"ASYNC-ECHO", run_async_echo, 0},
8800 { "UID-REGRESSION-TEST", run_uid_regression_test, 0},
8801 { "SHORTNAME-TEST", run_shortname_test, 0},
8802 { "ADDRCHANGE", run_addrchange, 0},
8804 {"OPENATTR", run_openattrtest, 0},
8806 {"XCOPY", run_xcopy, 0},
8807 {"RENAME", run_rename, 0},
8808 {"DELETE", run_deletetest, 0},
8809 {"DELETE-LN", run_deletetest_ln, 0},
8810 {"PROPERTIES", run_properties, 0},
8811 {"MANGLE", torture_mangle, 0},
8812 {"MANGLE1", run_mangle1, 0},
8813 {"W2K", run_w2ktest, 0},
8814 {"TRANS2SCAN", torture_trans2_scan, 0},
8815 {"NTTRANSSCAN", torture_nttrans_scan, 0},
8816 {"UTABLE", torture_utable, 0},
8817 {"CASETABLE", torture_casetable, 0},
8818 {"ERRMAPEXTRACT", run_error_map_extract, 0},
8819 {"PIPE_NUMBER", run_pipe_number, 0},
8820 {"TCON2", run_tcon2_test, 0},
8821 {"IOCTL", torture_ioctl_test, 0},
8822 {"CHKPATH", torture_chkpath_test, 0},
8823 {"FDSESS", run_fdsesstest, 0},
8824 { "EATEST", run_eatest, 0},
8825 { "SESSSETUP_BENCH", run_sesssetup_bench, 0},
8826 { "CHAIN1", run_chain1, 0},
8827 { "CHAIN2", run_chain2, 0},
8828 { "WINDOWS-WRITE", run_windows_write, 0},
8829 { "NTTRANS-CREATE", run_nttrans_create, 0},
8830 { "CLI_ECHO", run_cli_echo, 0},
8831 { "GETADDRINFO", run_getaddrinfo_send, 0},
8832 { "TLDAP", run_tldap },
8833 { "STREAMERROR", run_streamerror },
8834 { "NOTIFY-BENCH", run_notify_bench },
8835 { "BAD-NBT-SESSION", run_bad_nbt_session },
8836 { "SMB-ANY-CONNECT", run_smb_any_connect },
8837 { "NOTIFY-ONLINE", run_notify_online },
8838 { "SMB2-BASIC", run_smb2_basic },
8839 { "LOCAL-SUBSTITUTE", run_local_substitute, 0},
8840 { "LOCAL-GENCACHE", run_local_gencache, 0},
8841 { "LOCAL-TALLOC-DICT", run_local_talloc_dict, 0},
8842 { "LOCAL-BASE64", run_local_base64, 0},
8843 { "LOCAL-RBTREE", run_local_rbtree, 0},
8844 { "LOCAL-MEMCACHE", run_local_memcache, 0},
8845 { "LOCAL-STREAM-NAME", run_local_stream_name, 0},
8846 { "LOCAL-WBCLIENT", run_local_wbclient, 0},
8847 { "LOCAL-string_to_sid", run_local_string_to_sid, 0},
8848 { "LOCAL-binary_to_sid", run_local_binary_to_sid, 0},
8849 { "LOCAL-DBTRANS", run_local_dbtrans, 0},
8850 { "LOCAL-TEVENT-SELECT", run_local_tevent_select, 0},
8851 { "LOCAL-CONVERT-STRING", run_local_convert_string, 0},
8856 /****************************************************************************
8857 run a specified test or "ALL"
8858 ****************************************************************************/
8859 static bool run_test(const char *name)
8866 if (strequal(name,"ALL")) {
8867 for (i=0;torture_ops[i].name;i++) {
8868 run_test(torture_ops[i].name);
8873 for (i=0;torture_ops[i].name;i++) {
8874 fstr_sprintf(randomfname, "\\XX%x",
8875 (unsigned)random());
8877 if (strequal(name, torture_ops[i].name)) {
8879 printf("Running %s\n", name);
8880 if (torture_ops[i].flags & FLAG_MULTIPROC) {
8881 t = create_procs(torture_ops[i].fn, &result);
8884 printf("TEST %s FAILED!\n", name);
8887 struct timeval start;
8888 start = timeval_current();
8889 if (!torture_ops[i].fn(0)) {
8891 printf("TEST %s FAILED!\n", name);
8893 t = timeval_elapsed(&start);
8895 printf("%s took %g secs\n\n", name, t);
8900 printf("Did not find a test named %s\n", name);
8908 static void usage(void)
8912 printf("WARNING samba4 test suite is much more complete nowadays.\n");
8913 printf("Please use samba4 torture.\n\n");
8915 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
8917 printf("\t-d debuglevel\n");
8918 printf("\t-U user%%pass\n");
8919 printf("\t-k use kerberos\n");
8920 printf("\t-N numprocs\n");
8921 printf("\t-n my_netbios_name\n");
8922 printf("\t-W workgroup\n");
8923 printf("\t-o num_operations\n");
8924 printf("\t-O socket_options\n");
8925 printf("\t-m maximum protocol\n");
8926 printf("\t-L use oplocks\n");
8927 printf("\t-c CLIENT.TXT specify client load file for NBENCH\n");
8928 printf("\t-A showall\n");
8929 printf("\t-p port\n");
8930 printf("\t-s seed\n");
8931 printf("\t-b unclist_filename specify multiple shares for multiple connections\n");
8932 printf("\t-f filename filename to test\n");
8935 printf("tests are:");
8936 for (i=0;torture_ops[i].name;i++) {
8937 printf(" %s", torture_ops[i].name);
8941 printf("default test is ALL\n");
8946 /****************************************************************************
8948 ****************************************************************************/
8949 int main(int argc,char *argv[])
8955 bool correct = True;
8956 TALLOC_CTX *frame = talloc_stackframe();
8957 int seed = time(NULL);
8959 #ifdef HAVE_SETBUFFER
8960 setbuffer(stdout, NULL, 0);
8963 setup_logging("smbtorture", DEBUG_STDOUT);
8967 if (is_default_dyn_CONFIGFILE()) {
8968 if(getenv("SMB_CONF_PATH")) {
8969 set_dyn_CONFIGFILE(getenv("SMB_CONF_PATH"));
8972 lp_load(get_dyn_CONFIGFILE(),True,False,False,True);
8979 for(p = argv[1]; *p; p++)
8983 if (strncmp(argv[1], "//", 2)) {
8987 fstrcpy(host, &argv[1][2]);
8988 p = strchr_m(&host[2],'/');
8993 fstrcpy(share, p+1);
8995 fstrcpy(myname, get_myname(talloc_tos()));
8997 fprintf(stderr, "Failed to get my hostname.\n");
9001 if (*username == 0 && getenv("LOGNAME")) {
9002 fstrcpy(username,getenv("LOGNAME"));
9008 fstrcpy(workgroup, lp_workgroup());
9010 while ((opt = getopt(argc, argv, "p:hW:U:n:N:O:o:m:Ll:d:Aec:ks:b:B:f:"))
9014 port_to_use = atoi(optarg);
9017 seed = atoi(optarg);
9020 fstrcpy(workgroup,optarg);
9023 max_protocol = interpret_protocol(optarg, max_protocol);
9026 nprocs = atoi(optarg);
9029 torture_numops = atoi(optarg);
9032 lp_set_cmdline("log level", optarg);
9041 local_path = optarg;
9044 torture_showall = True;
9047 fstrcpy(myname, optarg);
9050 client_txt = optarg;
9057 use_kerberos = True;
9059 d_printf("No kerberos support compiled in\n");
9065 fstrcpy(username,optarg);
9066 p = strchr_m(username,'%');
9069 fstrcpy(password, p+1);
9074 fstrcpy(multishare_conn_fname, optarg);
9075 use_multishare_conn = True;
9078 torture_blocksize = atoi(optarg);
9081 test_filename = SMB_STRDUP(optarg);
9084 printf("Unknown option %c (%d)\n", (char)opt, opt);
9089 d_printf("using seed %d\n", seed);
9093 if(use_kerberos && !gotuser) gotpass = True;
9096 p = getpass("Password:");
9098 fstrcpy(password, p);
9103 printf("host=%s share=%s user=%s myname=%s\n",
9104 host, share, username, myname);
9106 if (argc == optind) {
9107 correct = run_test("ALL");
9109 for (i=optind;i<argc;i++) {
9110 if (!run_test(argv[i])) {