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"
31 #include "dbwrap/dbwrap.h"
32 #include "dbwrap/dbwrap_open.h"
33 #include "dbwrap/dbwrap_rbt.h"
34 #include "talloc_dict.h"
35 #include "async_smb.h"
36 #include "libsmb/libsmb.h"
37 #include "libsmb/clirap.h"
39 #include "libsmb/nmblib.h"
40 #include "../lib/util/tevent_ntstatus.h"
42 #include "libsmb/read_smb.h"
47 fstring host, workgroup, share, password, username, myname;
48 static int max_protocol = PROTOCOL_NT1;
49 static const char *sockops="TCP_NODELAY";
51 static int port_to_use=0;
52 int torture_numops=100;
53 int torture_blocksize=1024*1024;
54 static int procnum; /* records process count number when forking */
55 static struct cli_state *current_cli;
56 static fstring randomfname;
57 static bool use_oplocks;
58 static bool use_level_II_oplocks;
59 static const char *client_txt = "client_oplocks.txt";
60 static bool disable_spnego;
61 static bool use_kerberos;
62 static bool force_dos_errors;
63 static fstring multishare_conn_fname;
64 static bool use_multishare_conn = False;
65 static bool do_encrypt;
66 static const char *local_path = NULL;
67 static int signing_state = Undefined;
70 bool torture_showall = False;
72 static double create_procs(bool (*fn)(int), bool *result);
75 /* return a pointer to a anonymous shared memory segment of size "size"
76 which will persist across fork() but will disappear when all processes
79 The memory is not zeroed
81 This function uses system5 shared memory. It takes advantage of a property
82 that the memory is not destroyed if it is attached when the id is removed
84 void *shm_setup(int size)
90 shmid = shm_open("private", O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
92 printf("can't get shared memory\n");
95 shm_unlink("private");
96 if (ftruncate(shmid, size) == -1) {
97 printf("can't set shared memory size\n");
100 ret = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, shmid, 0);
101 if (ret == MAP_FAILED) {
102 printf("can't map shared memory\n");
106 shmid = shmget(IPC_PRIVATE, size, S_IRUSR | S_IWUSR);
108 printf("can't get shared memory\n");
111 ret = (void *)shmat(shmid, 0, 0);
112 if (!ret || ret == (void *)-1) {
113 printf("can't attach to shared memory\n");
116 /* the following releases the ipc, but note that this process
117 and all its children will still have access to the memory, its
118 just that the shmid is no longer valid for other shm calls. This
119 means we don't leave behind lots of shm segments after we exit
121 See Stevens "advanced programming in unix env" for details
123 shmctl(shmid, IPC_RMID, 0);
129 /********************************************************************
130 Ensure a connection is encrypted.
131 ********************************************************************/
133 static bool force_cli_encryption(struct cli_state *c,
134 const char *sharename)
137 uint32 caplow, caphigh;
140 if (!SERVER_HAS_UNIX_CIFS(c)) {
141 d_printf("Encryption required and "
142 "server that doesn't support "
143 "UNIX extensions - failing connect\n");
147 status = cli_unix_extensions_version(c, &major, &minor, &caplow,
149 if (!NT_STATUS_IS_OK(status)) {
150 d_printf("Encryption required and "
151 "can't get UNIX CIFS extensions "
152 "version from server: %s\n", nt_errstr(status));
156 if (!(caplow & CIFS_UNIX_TRANSPORT_ENCRYPTION_CAP)) {
157 d_printf("Encryption required and "
158 "share %s doesn't support "
159 "encryption.\n", sharename);
163 if (c->use_kerberos) {
164 status = cli_gss_smb_encryption_start(c);
166 status = cli_raw_ntlm_smb_encryption_start(c,
172 if (!NT_STATUS_IS_OK(status)) {
173 d_printf("Encryption required and "
174 "setup failed with error %s.\n",
183 static struct cli_state *open_nbt_connection(void)
189 if (disable_spnego) {
190 flags |= CLI_FULL_CONNECTION_DONT_SPNEGO;
194 flags |= CLI_FULL_CONNECTION_OPLOCKS;
197 if (use_level_II_oplocks) {
198 flags |= CLI_FULL_CONNECTION_LEVEL_II_OPLOCKS;
202 flags |= CLI_FULL_CONNECTION_USE_KERBEROS;
205 if (force_dos_errors) {
206 flags |= CLI_FULL_CONNECTION_FORCE_DOS_ERRORS;
209 status = cli_connect_nb(host, NULL, port_to_use, 0x20, myname,
210 signing_state, flags, &c);
211 if (!NT_STATUS_IS_OK(status)) {
212 printf("Failed to connect with %s. Error %s\n", host, nt_errstr(status) );
216 cli_set_timeout(c, 120000); /* set a really long timeout (2 minutes) */
221 /****************************************************************************
222 Send a corrupt session request. See rfc1002.txt 4.3 and 4.3.2.
223 ****************************************************************************/
225 static bool cli_bad_session_request(int fd,
226 struct nmb_name *calling, struct nmb_name *called)
235 uint8_t message_type;
238 frame = talloc_stackframe();
240 iov[0].iov_base = len_buf;
241 iov[0].iov_len = sizeof(len_buf);
243 /* put in the destination name */
245 iov[1].iov_base = name_mangle(talloc_tos(), called->name,
247 if (iov[1].iov_base == NULL) {
250 iov[1].iov_len = name_len((unsigned char *)iov[1].iov_base,
251 talloc_get_size(iov[1].iov_base));
255 iov[2].iov_base = name_mangle(talloc_tos(), calling->name,
257 if (iov[2].iov_base == NULL) {
260 iov[2].iov_len = name_len((unsigned char *)iov[2].iov_base,
261 talloc_get_size(iov[2].iov_base));
263 /* Deliberately corrupt the name len (first byte) */
264 *((uint8_t *)iov[2].iov_base) = 100;
266 /* send a session request (RFC 1002) */
267 /* setup the packet length
268 * Remove four bytes from the length count, since the length
269 * field in the NBT Session Service header counts the number
270 * of bytes which follow. The cli_send_smb() function knows
271 * about this and accounts for those four bytes.
275 _smb_setlen(len_buf, iov[1].iov_len + iov[2].iov_len);
276 SCVAL(len_buf,0,0x81);
278 len = write_data_iov(fd, iov, 3);
282 len = read_smb(fd, talloc_tos(), &inbuf, &err);
288 message_type = CVAL(inbuf, 0);
289 if (message_type != 0x83) {
290 d_fprintf(stderr, "Expected msg type 0x83, got 0x%2.2x\n",
295 if (smb_len(inbuf) != 1) {
296 d_fprintf(stderr, "Expected smb_len 1, got %d\n",
297 (int)smb_len(inbuf));
301 error = CVAL(inbuf, 4);
303 d_fprintf(stderr, "Expected error 0x82, got %d\n",
314 /* Insert a NULL at the first separator of the given path and return a pointer
315 * to the remainder of the string.
318 terminate_path_at_separator(char * path)
326 if ((p = strchr_m(path, '/'))) {
331 if ((p = strchr_m(path, '\\'))) {
341 parse a //server/share type UNC name
343 bool smbcli_parse_unc(const char *unc_name, TALLOC_CTX *mem_ctx,
344 char **hostname, char **sharename)
348 *hostname = *sharename = NULL;
350 if (strncmp(unc_name, "\\\\", 2) &&
351 strncmp(unc_name, "//", 2)) {
355 *hostname = talloc_strdup(mem_ctx, &unc_name[2]);
356 p = terminate_path_at_separator(*hostname);
359 *sharename = talloc_strdup(mem_ctx, p);
360 terminate_path_at_separator(*sharename);
363 if (*hostname && *sharename) {
367 TALLOC_FREE(*hostname);
368 TALLOC_FREE(*sharename);
372 static bool torture_open_connection_share(struct cli_state **c,
373 const char *hostname,
374 const char *sharename)
380 flags |= CLI_FULL_CONNECTION_USE_KERBEROS;
382 flags |= CLI_FULL_CONNECTION_OPLOCKS;
383 if (use_level_II_oplocks)
384 flags |= CLI_FULL_CONNECTION_LEVEL_II_OPLOCKS;
386 status = cli_full_connection(c, myname,
387 hostname, NULL, port_to_use,
390 password, flags, signing_state);
391 if (!NT_STATUS_IS_OK(status)) {
392 printf("failed to open share connection: //%s/%s port:%d - %s\n",
393 hostname, sharename, port_to_use, nt_errstr(status));
397 cli_set_timeout(*c, 120000); /* set a really long timeout (2 minutes) */
400 return force_cli_encryption(*c,
406 bool torture_open_connection(struct cli_state **c, int conn_index)
408 char **unc_list = NULL;
409 int num_unc_names = 0;
412 if (use_multishare_conn==True) {
414 unc_list = file_lines_load(multishare_conn_fname, &num_unc_names, 0, NULL);
415 if (!unc_list || num_unc_names <= 0) {
416 printf("Failed to load unc names list from '%s'\n", multishare_conn_fname);
420 if (!smbcli_parse_unc(unc_list[conn_index % num_unc_names],
422 printf("Failed to parse UNC name %s\n",
423 unc_list[conn_index % num_unc_names]);
424 TALLOC_FREE(unc_list);
428 result = torture_open_connection_share(c, h, s);
430 /* h, s were copied earlier */
431 TALLOC_FREE(unc_list);
435 return torture_open_connection_share(c, host, share);
438 bool torture_init_connection(struct cli_state **pcli)
440 struct cli_state *cli;
442 cli = open_nbt_connection();
451 bool torture_cli_session_setup2(struct cli_state *cli, uint16 *new_vuid)
453 uint16_t old_vuid = cli_state_get_uid(cli);
454 fstring old_user_name;
455 size_t passlen = strlen(password);
459 fstrcpy(old_user_name, cli->user_name);
460 cli_state_set_uid(cli, 0);
461 ret = NT_STATUS_IS_OK(cli_session_setup(cli, username,
465 *new_vuid = cli_state_get_uid(cli);
466 cli_state_set_uid(cli, old_vuid);
467 status = cli_set_username(cli, old_user_name);
468 if (!NT_STATUS_IS_OK(status)) {
475 bool torture_close_connection(struct cli_state *c)
480 status = cli_tdis(c);
481 if (!NT_STATUS_IS_OK(status)) {
482 printf("tdis failed (%s)\n", nt_errstr(status));
492 /* check if the server produced the expected dos or nt error code */
493 static bool check_both_error(int line, NTSTATUS status,
494 uint8 eclass, uint32 ecode, NTSTATUS nterr)
496 if (NT_STATUS_IS_DOS(status)) {
500 /* Check DOS error */
501 cclass = NT_STATUS_DOS_CLASS(status);
502 num = NT_STATUS_DOS_CODE(status);
504 if (eclass != cclass || ecode != num) {
505 printf("unexpected error code class=%d code=%d\n",
506 (int)cclass, (int)num);
507 printf(" expected %d/%d %s (line=%d)\n",
508 (int)eclass, (int)ecode, nt_errstr(nterr), line);
513 if (!NT_STATUS_EQUAL(nterr, status)) {
514 printf("unexpected error code %s\n",
516 printf(" expected %s (line=%d)\n",
517 nt_errstr(nterr), line);
526 /* check if the server produced the expected error code */
527 static bool check_error(int line, NTSTATUS status,
528 uint8 eclass, uint32 ecode, NTSTATUS nterr)
530 if (NT_STATUS_IS_DOS(status)) {
534 /* Check DOS error */
536 cclass = NT_STATUS_DOS_CLASS(status);
537 num = NT_STATUS_DOS_CODE(status);
539 if (eclass != cclass || ecode != num) {
540 printf("unexpected error code class=%d code=%d\n",
541 (int)cclass, (int)num);
542 printf(" expected %d/%d %s (line=%d)\n",
543 (int)eclass, (int)ecode, nt_errstr(nterr),
551 if (NT_STATUS_V(nterr) != NT_STATUS_V(status)) {
552 printf("unexpected error code %s\n",
554 printf(" expected %s (line=%d)\n", nt_errstr(nterr),
564 static bool wait_lock(struct cli_state *c, int fnum, uint32 offset, uint32 len)
568 status = cli_lock32(c, fnum, offset, len, -1, WRITE_LOCK);
570 while (!NT_STATUS_IS_OK(status)) {
571 if (!check_both_error(__LINE__, status, ERRDOS,
572 ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) {
576 status = cli_lock32(c, fnum, offset, len, -1, WRITE_LOCK);
583 static bool rw_torture(struct cli_state *c)
585 const char *lockfname = "\\torture.lck";
589 pid_t pid2, pid = getpid();
596 memset(buf, '\0', sizeof(buf));
598 status = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
600 if (!NT_STATUS_IS_OK(status)) {
601 status = cli_open(c, lockfname, O_RDWR, DENY_NONE, &fnum2);
603 if (!NT_STATUS_IS_OK(status)) {
604 printf("open of %s failed (%s)\n",
605 lockfname, nt_errstr(status));
609 for (i=0;i<torture_numops;i++) {
610 unsigned n = (unsigned)sys_random()%10;
613 printf("%d\r", i); fflush(stdout);
615 slprintf(fname, sizeof(fstring) - 1, "\\torture.%u", n);
617 if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) {
621 status = cli_open(c, fname, O_RDWR | O_CREAT | O_TRUNC,
623 if (!NT_STATUS_IS_OK(status)) {
624 printf("open failed (%s)\n", nt_errstr(status));
629 status = cli_writeall(c, fnum, 0, (uint8_t *)&pid, 0,
631 if (!NT_STATUS_IS_OK(status)) {
632 printf("write failed (%s)\n", nt_errstr(status));
637 status = cli_writeall(c, fnum, 0, (uint8_t *)buf,
638 sizeof(pid)+(j*sizeof(buf)),
640 if (!NT_STATUS_IS_OK(status)) {
641 printf("write failed (%s)\n",
649 status = cli_read(c, fnum, (char *)&pid2, 0, sizeof(pid),
651 if (!NT_STATUS_IS_OK(status)) {
652 printf("read failed (%s)\n", nt_errstr(status));
654 } else if (nread != sizeof(pid)) {
655 printf("read/write compare failed: "
656 "recv %ld req %ld\n", (unsigned long)nread,
657 (unsigned long)sizeof(pid));
662 printf("data corruption!\n");
666 status = cli_close(c, fnum);
667 if (!NT_STATUS_IS_OK(status)) {
668 printf("close failed (%s)\n", nt_errstr(status));
672 status = cli_unlink(c, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
673 if (!NT_STATUS_IS_OK(status)) {
674 printf("unlink failed (%s)\n", nt_errstr(status));
678 status = cli_unlock(c, fnum2, n*sizeof(int), sizeof(int));
679 if (!NT_STATUS_IS_OK(status)) {
680 printf("unlock failed (%s)\n", nt_errstr(status));
686 cli_unlink(c, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
693 static bool run_torture(int dummy)
695 struct cli_state *cli;
700 cli_sockopt(cli, sockops);
702 ret = rw_torture(cli);
704 if (!torture_close_connection(cli)) {
711 static bool rw_torture3(struct cli_state *c, char *lockfname)
713 uint16_t fnum = (uint16_t)-1;
718 unsigned countprev = 0;
721 NTSTATUS status = NT_STATUS_OK;
724 for (i = 0; i < sizeof(buf); i += sizeof(uint32))
726 SIVAL(buf, i, sys_random());
733 FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
734 if (!NT_STATUS_IS_OK(status)) {
735 printf("unlink failed (%s) (normal, this file should "
736 "not exist)\n", nt_errstr(status));
739 status = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
741 if (!NT_STATUS_IS_OK(status)) {
742 printf("first open read/write of %s failed (%s)\n",
743 lockfname, nt_errstr(status));
749 for (i = 0; i < 500 && fnum == (uint16_t)-1; i++)
751 status = cli_open(c, lockfname, O_RDONLY,
753 if (!NT_STATUS_IS_OK(status)) {
758 if (!NT_STATUS_IS_OK(status)) {
759 printf("second open read-only of %s failed (%s)\n",
760 lockfname, nt_errstr(status));
766 for (count = 0; count < sizeof(buf); count += sent)
768 if (count >= countprev) {
769 printf("%d %8d\r", i, count);
772 countprev += (sizeof(buf) / 20);
777 sent = ((unsigned)sys_random()%(20))+ 1;
778 if (sent > sizeof(buf) - count)
780 sent = sizeof(buf) - count;
783 status = cli_writeall(c, fnum, 0, (uint8_t *)buf+count,
785 if (!NT_STATUS_IS_OK(status)) {
786 printf("write failed (%s)\n",
793 status = cli_read(c, fnum, buf_rd+count, count,
794 sizeof(buf)-count, &sent);
795 if(!NT_STATUS_IS_OK(status)) {
796 printf("read failed offset:%d size:%ld (%s)\n",
797 count, (unsigned long)sizeof(buf)-count,
801 } else if (sent > 0) {
802 if (memcmp(buf_rd+count, buf+count, sent) != 0)
804 printf("read/write compare failed\n");
805 printf("offset: %d req %ld recvd %ld\n", count, (unsigned long)sizeof(buf)-count, (unsigned long)sent);
814 status = cli_close(c, fnum);
815 if (!NT_STATUS_IS_OK(status)) {
816 printf("close failed (%s)\n", nt_errstr(status));
823 static bool rw_torture2(struct cli_state *c1, struct cli_state *c2)
825 const char *lockfname = "\\torture2.lck";
835 status = cli_unlink(c1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
836 if (!NT_STATUS_IS_OK(status)) {
837 printf("unlink failed (%s) (normal, this file should not exist)\n", nt_errstr(status));
840 status = cli_open(c1, lockfname, O_RDWR | O_CREAT | O_EXCL,
842 if (!NT_STATUS_IS_OK(status)) {
843 printf("first open read/write of %s failed (%s)\n",
844 lockfname, nt_errstr(status));
848 status = cli_open(c2, lockfname, O_RDONLY, DENY_NONE, &fnum2);
849 if (!NT_STATUS_IS_OK(status)) {
850 printf("second open read-only of %s failed (%s)\n",
851 lockfname, nt_errstr(status));
852 cli_close(c1, fnum1);
856 for (i = 0; i < torture_numops; i++)
858 size_t buf_size = ((unsigned)sys_random()%(sizeof(buf)-1))+ 1;
860 printf("%d\r", i); fflush(stdout);
863 generate_random_buffer((unsigned char *)buf, buf_size);
865 status = cli_writeall(c1, fnum1, 0, (uint8_t *)buf, 0,
867 if (!NT_STATUS_IS_OK(status)) {
868 printf("write failed (%s)\n", nt_errstr(status));
873 status = cli_read(c2, fnum2, buf_rd, 0, buf_size, &bytes_read);
874 if(!NT_STATUS_IS_OK(status)) {
875 printf("read failed (%s)\n", nt_errstr(status));
878 } else if (bytes_read != buf_size) {
879 printf("read failed\n");
880 printf("read %ld, expected %ld\n",
881 (unsigned long)bytes_read,
882 (unsigned long)buf_size);
887 if (memcmp(buf_rd, buf, buf_size) != 0)
889 printf("read/write compare failed\n");
895 status = cli_close(c2, fnum2);
896 if (!NT_STATUS_IS_OK(status)) {
897 printf("close failed (%s)\n", nt_errstr(status));
901 status = cli_close(c1, fnum1);
902 if (!NT_STATUS_IS_OK(status)) {
903 printf("close failed (%s)\n", nt_errstr(status));
907 status = cli_unlink(c1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
908 if (!NT_STATUS_IS_OK(status)) {
909 printf("unlink failed (%s)\n", nt_errstr(status));
916 static bool run_readwritetest(int dummy)
918 struct cli_state *cli1, *cli2;
919 bool test1, test2 = False;
921 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
924 cli_sockopt(cli1, sockops);
925 cli_sockopt(cli2, sockops);
927 printf("starting readwritetest\n");
929 test1 = rw_torture2(cli1, cli2);
930 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1));
933 test2 = rw_torture2(cli1, cli1);
934 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2));
937 if (!torture_close_connection(cli1)) {
941 if (!torture_close_connection(cli2)) {
945 return (test1 && test2);
948 static bool run_readwritemulti(int dummy)
950 struct cli_state *cli;
955 cli_sockopt(cli, sockops);
957 printf("run_readwritemulti: fname %s\n", randomfname);
958 test = rw_torture3(cli, randomfname);
960 if (!torture_close_connection(cli)) {
967 static bool run_readwritelarge_internal(void)
969 static struct cli_state *cli1;
971 const char *lockfname = "\\large.dat";
977 if (!torture_open_connection(&cli1, 0)) {
980 cli_sockopt(cli1, sockops);
981 memset(buf,'\0',sizeof(buf));
983 printf("starting readwritelarge_internal\n");
985 cli_unlink(cli1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
987 status = cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL,
989 if (!NT_STATUS_IS_OK(status)) {
990 printf("open read/write of %s failed (%s)\n", lockfname, nt_errstr(status));
994 cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 0, sizeof(buf), NULL);
996 status = cli_qfileinfo_basic(cli1, fnum1, NULL, &fsize, NULL, NULL,
998 if (!NT_STATUS_IS_OK(status)) {
999 printf("qfileinfo failed (%s)\n", nt_errstr(status));
1003 if (fsize == sizeof(buf))
1004 printf("readwritelarge_internal test 1 succeeded (size = %lx)\n",
1005 (unsigned long)fsize);
1007 printf("readwritelarge_internal test 1 failed (size = %lx)\n",
1008 (unsigned long)fsize);
1012 status = cli_close(cli1, fnum1);
1013 if (!NT_STATUS_IS_OK(status)) {
1014 printf("close failed (%s)\n", nt_errstr(status));
1018 status = cli_unlink(cli1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1019 if (!NT_STATUS_IS_OK(status)) {
1020 printf("unlink failed (%s)\n", nt_errstr(status));
1024 status = cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL,
1026 if (!NT_STATUS_IS_OK(status)) {
1027 printf("open read/write of %s failed (%s)\n", lockfname, nt_errstr(status));
1031 cli_smbwrite(cli1, fnum1, buf, 0, sizeof(buf), NULL);
1033 status = cli_qfileinfo_basic(cli1, fnum1, NULL, &fsize, NULL, NULL,
1035 if (!NT_STATUS_IS_OK(status)) {
1036 printf("qfileinfo failed (%s)\n", nt_errstr(status));
1040 if (fsize == sizeof(buf))
1041 printf("readwritelarge_internal test 2 succeeded (size = %lx)\n",
1042 (unsigned long)fsize);
1044 printf("readwritelarge_internal test 2 failed (size = %lx)\n",
1045 (unsigned long)fsize);
1050 /* ToDo - set allocation. JRA */
1051 if(!cli_set_allocation_size(cli1, fnum1, 0)) {
1052 printf("set allocation size to zero failed (%s)\n", cli_errstr(&cli1));
1055 if (!cli_qfileinfo_basic(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL,
1057 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
1061 printf("readwritelarge test 3 (truncate test) succeeded (size = %x)\n", fsize);
1064 status = cli_close(cli1, fnum1);
1065 if (!NT_STATUS_IS_OK(status)) {
1066 printf("close failed (%s)\n", nt_errstr(status));
1070 if (!torture_close_connection(cli1)) {
1076 static bool run_readwritelarge(int dummy)
1078 return run_readwritelarge_internal();
1081 static bool run_readwritelarge_signtest(int dummy)
1084 signing_state = Required;
1085 ret = run_readwritelarge_internal();
1086 signing_state = Undefined;
1093 #define ival(s) strtol(s, NULL, 0)
1095 /* run a test that simulates an approximate netbench client load */
1096 static bool run_netbench(int client)
1098 struct cli_state *cli;
1103 const char *params[20];
1104 bool correct = True;
1110 cli_sockopt(cli, sockops);
1114 slprintf(cname,sizeof(cname)-1, "client%d", client);
1116 f = fopen(client_txt, "r");
1123 while (fgets(line, sizeof(line)-1, f)) {
1127 line[strlen(line)-1] = 0;
1129 /* printf("[%d] %s\n", line_count, line); */
1131 all_string_sub(line,"client1", cname, sizeof(line));
1133 /* parse the command parameters */
1134 params[0] = strtok_r(line, " ", &saveptr);
1136 while (params[i]) params[++i] = strtok_r(NULL, " ", &saveptr);
1140 if (i < 2) continue;
1142 if (!strncmp(params[0],"SMB", 3)) {
1143 printf("ERROR: You are using a dbench 1 load file\n");
1147 if (!strcmp(params[0],"NTCreateX")) {
1148 nb_createx(params[1], ival(params[2]), ival(params[3]),
1150 } else if (!strcmp(params[0],"Close")) {
1151 nb_close(ival(params[1]));
1152 } else if (!strcmp(params[0],"Rename")) {
1153 nb_rename(params[1], params[2]);
1154 } else if (!strcmp(params[0],"Unlink")) {
1155 nb_unlink(params[1]);
1156 } else if (!strcmp(params[0],"Deltree")) {
1157 nb_deltree(params[1]);
1158 } else if (!strcmp(params[0],"Rmdir")) {
1159 nb_rmdir(params[1]);
1160 } else if (!strcmp(params[0],"QUERY_PATH_INFORMATION")) {
1161 nb_qpathinfo(params[1]);
1162 } else if (!strcmp(params[0],"QUERY_FILE_INFORMATION")) {
1163 nb_qfileinfo(ival(params[1]));
1164 } else if (!strcmp(params[0],"QUERY_FS_INFORMATION")) {
1165 nb_qfsinfo(ival(params[1]));
1166 } else if (!strcmp(params[0],"FIND_FIRST")) {
1167 nb_findfirst(params[1]);
1168 } else if (!strcmp(params[0],"WriteX")) {
1169 nb_writex(ival(params[1]),
1170 ival(params[2]), ival(params[3]), ival(params[4]));
1171 } else if (!strcmp(params[0],"ReadX")) {
1172 nb_readx(ival(params[1]),
1173 ival(params[2]), ival(params[3]), ival(params[4]));
1174 } else if (!strcmp(params[0],"Flush")) {
1175 nb_flush(ival(params[1]));
1177 printf("Unknown operation %s\n", params[0]);
1185 if (!torture_close_connection(cli)) {
1193 /* run a test that simulates an approximate netbench client load */
1194 static bool run_nbench(int dummy)
1197 bool correct = True;
1203 signal(SIGALRM, nb_alarm);
1205 t = create_procs(run_netbench, &correct);
1208 printf("\nThroughput %g MB/sec\n",
1209 1.0e-6 * nbio_total() / t);
1215 This test checks for two things:
1217 1) correct support for retaining locks over a close (ie. the server
1218 must not use posix semantics)
1219 2) support for lock timeouts
1221 static bool run_locktest1(int dummy)
1223 struct cli_state *cli1, *cli2;
1224 const char *fname = "\\lockt1.lck";
1225 uint16_t fnum1, fnum2, fnum3;
1227 unsigned lock_timeout;
1230 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1233 cli_sockopt(cli1, sockops);
1234 cli_sockopt(cli2, sockops);
1236 printf("starting locktest1\n");
1238 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1240 status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
1242 if (!NT_STATUS_IS_OK(status)) {
1243 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
1247 status = cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum2);
1248 if (!NT_STATUS_IS_OK(status)) {
1249 printf("open2 of %s failed (%s)\n", fname, nt_errstr(status));
1253 status = cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum3);
1254 if (!NT_STATUS_IS_OK(status)) {
1255 printf("open3 of %s failed (%s)\n", fname, nt_errstr(status));
1259 status = cli_lock32(cli1, fnum1, 0, 4, 0, WRITE_LOCK);
1260 if (!NT_STATUS_IS_OK(status)) {
1261 printf("lock1 failed (%s)\n", nt_errstr(status));
1265 status = cli_lock32(cli2, fnum3, 0, 4, 0, WRITE_LOCK);
1266 if (NT_STATUS_IS_OK(status)) {
1267 printf("lock2 succeeded! This is a locking bug\n");
1270 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1271 NT_STATUS_LOCK_NOT_GRANTED)) {
1276 lock_timeout = (1 + (random() % 20));
1277 printf("Testing lock timeout with timeout=%u\n", lock_timeout);
1279 status = cli_lock32(cli2, fnum3, 0, 4, lock_timeout * 1000, WRITE_LOCK);
1280 if (NT_STATUS_IS_OK(status)) {
1281 printf("lock3 succeeded! This is a locking bug\n");
1284 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1285 NT_STATUS_FILE_LOCK_CONFLICT)) {
1291 if (ABS(t2 - t1) < lock_timeout-1) {
1292 printf("error: This server appears not to support timed lock requests\n");
1295 printf("server slept for %u seconds for a %u second timeout\n",
1296 (unsigned int)(t2-t1), lock_timeout);
1298 status = cli_close(cli1, fnum2);
1299 if (!NT_STATUS_IS_OK(status)) {
1300 printf("close1 failed (%s)\n", nt_errstr(status));
1304 status = cli_lock32(cli2, fnum3, 0, 4, 0, WRITE_LOCK);
1305 if (NT_STATUS_IS_OK(status)) {
1306 printf("lock4 succeeded! This is a locking bug\n");
1309 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1310 NT_STATUS_FILE_LOCK_CONFLICT)) {
1315 status = cli_close(cli1, fnum1);
1316 if (!NT_STATUS_IS_OK(status)) {
1317 printf("close2 failed (%s)\n", nt_errstr(status));
1321 status = cli_close(cli2, fnum3);
1322 if (!NT_STATUS_IS_OK(status)) {
1323 printf("close3 failed (%s)\n", nt_errstr(status));
1327 status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1328 if (!NT_STATUS_IS_OK(status)) {
1329 printf("unlink failed (%s)\n", nt_errstr(status));
1334 if (!torture_close_connection(cli1)) {
1338 if (!torture_close_connection(cli2)) {
1342 printf("Passed locktest1\n");
1347 this checks to see if a secondary tconx can use open files from an
1350 static bool run_tcon_test(int dummy)
1352 static struct cli_state *cli;
1353 const char *fname = "\\tcontest.tmp";
1355 uint16 cnum1, cnum2, cnum3;
1356 uint16 vuid1, vuid2;
1361 memset(buf, '\0', sizeof(buf));
1363 if (!torture_open_connection(&cli, 0)) {
1366 cli_sockopt(cli, sockops);
1368 printf("starting tcontest\n");
1370 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1372 status = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
1373 if (!NT_STATUS_IS_OK(status)) {
1374 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
1378 cnum1 = cli_state_get_tid(cli);
1379 vuid1 = cli_state_get_uid(cli);
1381 status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
1382 if (!NT_STATUS_IS_OK(status)) {
1383 printf("initial write failed (%s)", nt_errstr(status));
1387 status = cli_tcon_andx(cli, share, "?????",
1388 password, strlen(password)+1);
1389 if (!NT_STATUS_IS_OK(status)) {
1390 printf("%s refused 2nd tree connect (%s)\n", host,
1396 cnum2 = cli_state_get_tid(cli);
1397 cnum3 = MAX(cnum1, cnum2) + 1; /* any invalid number */
1398 vuid2 = cli_state_get_uid(cli) + 1;
1400 /* try a write with the wrong tid */
1401 cli_state_set_tid(cli, cnum2);
1403 status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
1404 if (NT_STATUS_IS_OK(status)) {
1405 printf("* server allows write with wrong TID\n");
1408 printf("server fails write with wrong TID : %s\n",
1413 /* try a write with an invalid tid */
1414 cli_state_set_tid(cli, cnum3);
1416 status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
1417 if (NT_STATUS_IS_OK(status)) {
1418 printf("* server allows write with invalid TID\n");
1421 printf("server fails write with invalid TID : %s\n",
1425 /* try a write with an invalid vuid */
1426 cli_state_set_uid(cli, vuid2);
1427 cli_state_set_tid(cli, cnum1);
1429 status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
1430 if (NT_STATUS_IS_OK(status)) {
1431 printf("* server allows write with invalid VUID\n");
1434 printf("server fails write with invalid VUID : %s\n",
1438 cli_state_set_tid(cli, cnum1);
1439 cli_state_set_uid(cli, vuid1);
1441 status = cli_close(cli, fnum1);
1442 if (!NT_STATUS_IS_OK(status)) {
1443 printf("close failed (%s)\n", nt_errstr(status));
1447 cli_state_set_tid(cli, cnum2);
1449 status = cli_tdis(cli);
1450 if (!NT_STATUS_IS_OK(status)) {
1451 printf("secondary tdis failed (%s)\n", nt_errstr(status));
1455 cli_state_set_tid(cli, cnum1);
1457 if (!torture_close_connection(cli)) {
1466 checks for old style tcon support
1468 static bool run_tcon2_test(int dummy)
1470 static struct cli_state *cli;
1471 uint16 cnum, max_xmit;
1475 if (!torture_open_connection(&cli, 0)) {
1478 cli_sockopt(cli, sockops);
1480 printf("starting tcon2 test\n");
1482 if (asprintf(&service, "\\\\%s\\%s", host, share) == -1) {
1486 status = cli_raw_tcon(cli, service, password, "?????", &max_xmit, &cnum);
1490 if (!NT_STATUS_IS_OK(status)) {
1491 printf("tcon2 failed : %s\n", nt_errstr(status));
1493 printf("tcon OK : max_xmit=%d cnum=%d\n",
1494 (int)max_xmit, (int)cnum);
1497 if (!torture_close_connection(cli)) {
1501 printf("Passed tcon2 test\n");
1505 static bool tcon_devtest(struct cli_state *cli,
1506 const char *myshare, const char *devtype,
1507 const char *return_devtype,
1508 NTSTATUS expected_error)
1513 status = cli_tcon_andx(cli, myshare, devtype,
1514 password, strlen(password)+1);
1516 if (NT_STATUS_IS_OK(expected_error)) {
1517 if (NT_STATUS_IS_OK(status)) {
1518 if (strcmp(cli->dev, return_devtype) == 0) {
1521 printf("tconX to share %s with type %s "
1522 "succeeded but returned the wrong "
1523 "device type (got [%s] but should have got [%s])\n",
1524 myshare, devtype, cli->dev, return_devtype);
1528 printf("tconX to share %s with type %s "
1529 "should have succeeded but failed\n",
1535 if (NT_STATUS_IS_OK(status)) {
1536 printf("tconx to share %s with type %s "
1537 "should have failed but succeeded\n",
1541 if (NT_STATUS_EQUAL(cli_nt_error(cli),
1545 printf("Returned unexpected error\n");
1554 checks for correct tconX support
1556 static bool run_tcon_devtype_test(int dummy)
1558 static struct cli_state *cli1 = NULL;
1563 status = cli_full_connection(&cli1, myname,
1564 host, NULL, port_to_use,
1566 username, workgroup,
1567 password, flags, signing_state);
1569 if (!NT_STATUS_IS_OK(status)) {
1570 printf("could not open connection\n");
1574 if (!tcon_devtest(cli1, "IPC$", "A:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1577 if (!tcon_devtest(cli1, "IPC$", "?????", "IPC", NT_STATUS_OK))
1580 if (!tcon_devtest(cli1, "IPC$", "LPT:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1583 if (!tcon_devtest(cli1, "IPC$", "IPC", "IPC", NT_STATUS_OK))
1586 if (!tcon_devtest(cli1, "IPC$", "FOOBA", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1589 if (!tcon_devtest(cli1, share, "A:", "A:", NT_STATUS_OK))
1592 if (!tcon_devtest(cli1, share, "?????", "A:", NT_STATUS_OK))
1595 if (!tcon_devtest(cli1, share, "LPT:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1598 if (!tcon_devtest(cli1, share, "IPC", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1601 if (!tcon_devtest(cli1, share, "FOOBA", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1607 printf("Passed tcondevtest\n");
1614 This test checks that
1616 1) the server supports multiple locking contexts on the one SMB
1617 connection, distinguished by PID.
1619 2) the server correctly fails overlapping locks made by the same PID (this
1620 goes against POSIX behaviour, which is why it is tricky to implement)
1622 3) the server denies unlock requests by an incorrect client PID
1624 static bool run_locktest2(int dummy)
1626 static struct cli_state *cli;
1627 const char *fname = "\\lockt2.lck";
1628 uint16_t fnum1, fnum2, fnum3;
1629 bool correct = True;
1632 if (!torture_open_connection(&cli, 0)) {
1636 cli_sockopt(cli, sockops);
1638 printf("starting locktest2\n");
1640 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1644 status = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
1645 if (!NT_STATUS_IS_OK(status)) {
1646 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
1650 status = cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum2);
1651 if (!NT_STATUS_IS_OK(status)) {
1652 printf("open2 of %s failed (%s)\n", fname, nt_errstr(status));
1658 status = cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum3);
1659 if (!NT_STATUS_IS_OK(status)) {
1660 printf("open3 of %s failed (%s)\n", fname, nt_errstr(status));
1666 status = cli_lock32(cli, fnum1, 0, 4, 0, WRITE_LOCK);
1667 if (!NT_STATUS_IS_OK(status)) {
1668 printf("lock1 failed (%s)\n", nt_errstr(status));
1672 status = cli_lock32(cli, fnum1, 0, 4, 0, WRITE_LOCK);
1673 if (NT_STATUS_IS_OK(status)) {
1674 printf("WRITE lock1 succeeded! This is a locking bug\n");
1677 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1678 NT_STATUS_LOCK_NOT_GRANTED)) {
1683 status = cli_lock32(cli, fnum2, 0, 4, 0, WRITE_LOCK);
1684 if (NT_STATUS_IS_OK(status)) {
1685 printf("WRITE lock2 succeeded! This is a locking bug\n");
1688 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1689 NT_STATUS_LOCK_NOT_GRANTED)) {
1694 status = cli_lock32(cli, fnum2, 0, 4, 0, READ_LOCK);
1695 if (NT_STATUS_IS_OK(status)) {
1696 printf("READ lock2 succeeded! This is a locking bug\n");
1699 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1700 NT_STATUS_FILE_LOCK_CONFLICT)) {
1705 status = cli_lock32(cli, fnum1, 100, 4, 0, WRITE_LOCK);
1706 if (!NT_STATUS_IS_OK(status)) {
1707 printf("lock at 100 failed (%s)\n", nt_errstr(status));
1710 if (NT_STATUS_IS_OK(cli_unlock(cli, fnum1, 100, 4))) {
1711 printf("unlock at 100 succeeded! This is a locking bug\n");
1715 status = cli_unlock(cli, fnum1, 0, 4);
1716 if (NT_STATUS_IS_OK(status)) {
1717 printf("unlock1 succeeded! This is a locking bug\n");
1720 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1721 NT_STATUS_RANGE_NOT_LOCKED)) {
1726 status = cli_unlock(cli, fnum1, 0, 8);
1727 if (NT_STATUS_IS_OK(status)) {
1728 printf("unlock2 succeeded! This is a locking bug\n");
1731 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1732 NT_STATUS_RANGE_NOT_LOCKED)) {
1737 status = cli_lock32(cli, fnum3, 0, 4, 0, WRITE_LOCK);
1738 if (NT_STATUS_IS_OK(status)) {
1739 printf("lock3 succeeded! This is a locking bug\n");
1742 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1743 NT_STATUS_LOCK_NOT_GRANTED)) {
1750 status = cli_close(cli, fnum1);
1751 if (!NT_STATUS_IS_OK(status)) {
1752 printf("close1 failed (%s)\n", nt_errstr(status));
1756 status = cli_close(cli, fnum2);
1757 if (!NT_STATUS_IS_OK(status)) {
1758 printf("close2 failed (%s)\n", nt_errstr(status));
1762 status = cli_close(cli, fnum3);
1763 if (!NT_STATUS_IS_OK(status)) {
1764 printf("close3 failed (%s)\n", nt_errstr(status));
1768 if (!torture_close_connection(cli)) {
1772 printf("locktest2 finished\n");
1779 This test checks that
1781 1) the server supports the full offset range in lock requests
1783 static bool run_locktest3(int dummy)
1785 static struct cli_state *cli1, *cli2;
1786 const char *fname = "\\lockt3.lck";
1787 uint16_t fnum1, fnum2;
1790 bool correct = True;
1793 #define NEXT_OFFSET offset += (~(uint32)0) / torture_numops
1795 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1798 cli_sockopt(cli1, sockops);
1799 cli_sockopt(cli2, sockops);
1801 printf("starting locktest3\n");
1803 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1805 status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
1807 if (!NT_STATUS_IS_OK(status)) {
1808 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
1812 status = cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
1813 if (!NT_STATUS_IS_OK(status)) {
1814 printf("open2 of %s failed (%s)\n", fname, nt_errstr(status));
1818 for (offset=i=0;i<torture_numops;i++) {
1821 status = cli_lock32(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK);
1822 if (!NT_STATUS_IS_OK(status)) {
1823 printf("lock1 %d failed (%s)\n",
1829 status = cli_lock32(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK);
1830 if (!NT_STATUS_IS_OK(status)) {
1831 printf("lock2 %d failed (%s)\n",
1838 for (offset=i=0;i<torture_numops;i++) {
1841 status = cli_lock32(cli1, fnum1, offset-2, 1, 0, WRITE_LOCK);
1842 if (NT_STATUS_IS_OK(status)) {
1843 printf("error: lock1 %d succeeded!\n", i);
1847 status = cli_lock32(cli2, fnum2, offset-1, 1, 0, WRITE_LOCK);
1848 if (NT_STATUS_IS_OK(status)) {
1849 printf("error: lock2 %d succeeded!\n", i);
1853 status = cli_lock32(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK);
1854 if (NT_STATUS_IS_OK(status)) {
1855 printf("error: lock3 %d succeeded!\n", i);
1859 status = cli_lock32(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK);
1860 if (NT_STATUS_IS_OK(status)) {
1861 printf("error: lock4 %d succeeded!\n", i);
1866 for (offset=i=0;i<torture_numops;i++) {
1869 status = cli_unlock(cli1, fnum1, offset-1, 1);
1870 if (!NT_STATUS_IS_OK(status)) {
1871 printf("unlock1 %d failed (%s)\n",
1877 status = cli_unlock(cli2, fnum2, offset-2, 1);
1878 if (!NT_STATUS_IS_OK(status)) {
1879 printf("unlock2 %d failed (%s)\n",
1886 status = cli_close(cli1, fnum1);
1887 if (!NT_STATUS_IS_OK(status)) {
1888 printf("close1 failed (%s)\n", nt_errstr(status));
1892 status = cli_close(cli2, fnum2);
1893 if (!NT_STATUS_IS_OK(status)) {
1894 printf("close2 failed (%s)\n", nt_errstr(status));
1898 status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1899 if (!NT_STATUS_IS_OK(status)) {
1900 printf("unlink failed (%s)\n", nt_errstr(status));
1904 if (!torture_close_connection(cli1)) {
1908 if (!torture_close_connection(cli2)) {
1912 printf("finished locktest3\n");
1917 static bool test_cli_read(struct cli_state *cli, uint16_t fnum,
1918 char *buf, off_t offset, size_t size,
1919 size_t *nread, size_t expect)
1924 status = cli_read(cli, fnum, buf, offset, size, &l_nread);
1926 if(!NT_STATUS_IS_OK(status)) {
1928 } else if (l_nread != expect) {
1939 #define EXPECTED(ret, v) if ((ret) != (v)) { \
1940 printf("** "); correct = False; \
1944 looks at overlapping locks
1946 static bool run_locktest4(int dummy)
1948 static struct cli_state *cli1, *cli2;
1949 const char *fname = "\\lockt4.lck";
1950 uint16_t fnum1, fnum2, f;
1953 bool correct = True;
1956 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1960 cli_sockopt(cli1, sockops);
1961 cli_sockopt(cli2, sockops);
1963 printf("starting locktest4\n");
1965 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1967 cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
1968 cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
1970 memset(buf, 0, sizeof(buf));
1972 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 0, sizeof(buf),
1974 if (!NT_STATUS_IS_OK(status)) {
1975 printf("Failed to create file: %s\n", nt_errstr(status));
1980 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) &&
1981 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 2, 4, 0, WRITE_LOCK));
1982 EXPECTED(ret, False);
1983 printf("the same process %s set overlapping write locks\n", ret?"can":"cannot");
1985 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 10, 4, 0, READ_LOCK)) &&
1986 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 12, 4, 0, READ_LOCK));
1987 EXPECTED(ret, True);
1988 printf("the same process %s set overlapping read locks\n", ret?"can":"cannot");
1990 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 20, 4, 0, WRITE_LOCK)) &&
1991 NT_STATUS_IS_OK(cli_lock32(cli2, fnum2, 22, 4, 0, WRITE_LOCK));
1992 EXPECTED(ret, False);
1993 printf("a different connection %s set overlapping write locks\n", ret?"can":"cannot");
1995 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 30, 4, 0, READ_LOCK)) &&
1996 NT_STATUS_IS_OK(cli_lock32(cli2, fnum2, 32, 4, 0, READ_LOCK));
1997 EXPECTED(ret, True);
1998 printf("a different connection %s set overlapping read locks\n", ret?"can":"cannot");
2000 ret = (cli_setpid(cli1, 1),
2001 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 40, 4, 0, WRITE_LOCK))) &&
2002 (cli_setpid(cli1, 2),
2003 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 42, 4, 0, WRITE_LOCK)));
2004 EXPECTED(ret, False);
2005 printf("a different pid %s set overlapping write locks\n", ret?"can":"cannot");
2007 ret = (cli_setpid(cli1, 1),
2008 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 50, 4, 0, READ_LOCK))) &&
2009 (cli_setpid(cli1, 2),
2010 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 52, 4, 0, READ_LOCK)));
2011 EXPECTED(ret, True);
2012 printf("a different pid %s set overlapping read locks\n", ret?"can":"cannot");
2014 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 60, 4, 0, READ_LOCK)) &&
2015 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 60, 4, 0, READ_LOCK));
2016 EXPECTED(ret, True);
2017 printf("the same process %s set the same read lock twice\n", ret?"can":"cannot");
2019 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 70, 4, 0, WRITE_LOCK)) &&
2020 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 70, 4, 0, WRITE_LOCK));
2021 EXPECTED(ret, False);
2022 printf("the same process %s set the same write lock twice\n", ret?"can":"cannot");
2024 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 80, 4, 0, READ_LOCK)) &&
2025 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 80, 4, 0, WRITE_LOCK));
2026 EXPECTED(ret, False);
2027 printf("the same process %s overlay a read lock with a write lock\n", ret?"can":"cannot");
2029 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 90, 4, 0, WRITE_LOCK)) &&
2030 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 90, 4, 0, READ_LOCK));
2031 EXPECTED(ret, True);
2032 printf("the same process %s overlay a write lock with a read lock\n", ret?"can":"cannot");
2034 ret = (cli_setpid(cli1, 1),
2035 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 100, 4, 0, WRITE_LOCK))) &&
2036 (cli_setpid(cli1, 2),
2037 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 100, 4, 0, READ_LOCK)));
2038 EXPECTED(ret, False);
2039 printf("a different pid %s overlay a write lock with a read lock\n", ret?"can":"cannot");
2041 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 110, 4, 0, READ_LOCK)) &&
2042 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 112, 4, 0, READ_LOCK)) &&
2043 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 110, 6));
2044 EXPECTED(ret, False);
2045 printf("the same process %s coalesce read locks\n", ret?"can":"cannot");
2048 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 120, 4, 0, WRITE_LOCK)) &&
2049 test_cli_read(cli2, fnum2, buf, 120, 4, NULL, 4);
2050 EXPECTED(ret, False);
2051 printf("this server %s strict write locking\n", ret?"doesn't do":"does");
2053 status = cli_lock32(cli1, fnum1, 130, 4, 0, READ_LOCK);
2054 ret = NT_STATUS_IS_OK(status);
2056 status = cli_writeall(cli2, fnum2, 0, (uint8_t *)buf, 130, 4,
2058 ret = NT_STATUS_IS_OK(status);
2060 EXPECTED(ret, False);
2061 printf("this server %s strict read locking\n", ret?"doesn't do":"does");
2064 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 140, 4, 0, READ_LOCK)) &&
2065 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 140, 4, 0, READ_LOCK)) &&
2066 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 140, 4)) &&
2067 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 140, 4));
2068 EXPECTED(ret, True);
2069 printf("this server %s do recursive read locking\n", ret?"does":"doesn't");
2072 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 150, 4, 0, WRITE_LOCK)) &&
2073 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 150, 4, 0, READ_LOCK)) &&
2074 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 150, 4)) &&
2075 test_cli_read(cli2, fnum2, buf, 150, 4, NULL, 4) &&
2076 !(NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf,
2078 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 150, 4));
2079 EXPECTED(ret, True);
2080 printf("this server %s do recursive lock overlays\n", ret?"does":"doesn't");
2082 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 160, 4, 0, READ_LOCK)) &&
2083 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 160, 4)) &&
2084 NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf,
2086 test_cli_read(cli2, fnum2, buf, 160, 4, NULL, 4);
2087 EXPECTED(ret, True);
2088 printf("the same process %s remove a read lock using write locking\n", ret?"can":"cannot");
2090 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 170, 4, 0, WRITE_LOCK)) &&
2091 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 170, 4)) &&
2092 NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf,
2094 test_cli_read(cli2, fnum2, buf, 170, 4, NULL, 4);
2095 EXPECTED(ret, True);
2096 printf("the same process %s remove a write lock using read locking\n", ret?"can":"cannot");
2098 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 190, 4, 0, WRITE_LOCK)) &&
2099 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 190, 4, 0, READ_LOCK)) &&
2100 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 190, 4)) &&
2101 !NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf,
2103 test_cli_read(cli2, fnum2, buf, 190, 4, NULL, 4);
2104 EXPECTED(ret, True);
2105 printf("the same process %s remove the first lock first\n", ret?"does":"doesn't");
2107 cli_close(cli1, fnum1);
2108 cli_close(cli2, fnum2);
2109 cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
2110 cli_open(cli1, fname, O_RDWR, DENY_NONE, &f);
2111 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 8, 0, READ_LOCK)) &&
2112 NT_STATUS_IS_OK(cli_lock32(cli1, f, 0, 1, 0, READ_LOCK)) &&
2113 NT_STATUS_IS_OK(cli_close(cli1, fnum1)) &&
2114 NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1)) &&
2115 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 7, 1, 0, WRITE_LOCK));
2117 cli_close(cli1, fnum1);
2118 EXPECTED(ret, True);
2119 printf("the server %s have the NT byte range lock bug\n", !ret?"does":"doesn't");
2122 cli_close(cli1, fnum1);
2123 cli_close(cli2, fnum2);
2124 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2125 torture_close_connection(cli1);
2126 torture_close_connection(cli2);
2128 printf("finished locktest4\n");
2133 looks at lock upgrade/downgrade.
2135 static bool run_locktest5(int dummy)
2137 static struct cli_state *cli1, *cli2;
2138 const char *fname = "\\lockt5.lck";
2139 uint16_t fnum1, fnum2, fnum3;
2142 bool correct = True;
2145 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
2149 cli_sockopt(cli1, sockops);
2150 cli_sockopt(cli2, sockops);
2152 printf("starting locktest5\n");
2154 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2156 cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
2157 cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
2158 cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum3);
2160 memset(buf, 0, sizeof(buf));
2162 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 0, sizeof(buf),
2164 if (!NT_STATUS_IS_OK(status)) {
2165 printf("Failed to create file: %s\n", nt_errstr(status));
2170 /* Check for NT bug... */
2171 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 8, 0, READ_LOCK)) &&
2172 NT_STATUS_IS_OK(cli_lock32(cli1, fnum3, 0, 1, 0, READ_LOCK));
2173 cli_close(cli1, fnum1);
2174 cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
2175 status = cli_lock32(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
2176 ret = NT_STATUS_IS_OK(status);
2177 EXPECTED(ret, True);
2178 printf("this server %s the NT locking bug\n", ret ? "doesn't have" : "has");
2179 cli_close(cli1, fnum1);
2180 cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
2181 cli_unlock(cli1, fnum3, 0, 1);
2183 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) &&
2184 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 1, 1, 0, READ_LOCK));
2185 EXPECTED(ret, True);
2186 printf("the same process %s overlay a write with a read lock\n", ret?"can":"cannot");
2188 status = cli_lock32(cli2, fnum2, 0, 4, 0, READ_LOCK);
2189 ret = NT_STATUS_IS_OK(status);
2190 EXPECTED(ret, False);
2192 printf("a different processs %s get a read lock on the first process lock stack\n", ret?"can":"cannot");
2194 /* Unlock the process 2 lock. */
2195 cli_unlock(cli2, fnum2, 0, 4);
2197 status = cli_lock32(cli1, fnum3, 0, 4, 0, READ_LOCK);
2198 ret = NT_STATUS_IS_OK(status);
2199 EXPECTED(ret, False);
2201 printf("the same processs on a different fnum %s get a read lock\n", ret?"can":"cannot");
2203 /* Unlock the process 1 fnum3 lock. */
2204 cli_unlock(cli1, fnum3, 0, 4);
2206 /* Stack 2 more locks here. */
2207 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 4, 0, READ_LOCK)) &&
2208 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 4, 0, READ_LOCK));
2210 EXPECTED(ret, True);
2211 printf("the same process %s stack read locks\n", ret?"can":"cannot");
2213 /* Unlock the first process lock, then check this was the WRITE lock that was
2216 ret = NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 0, 4)) &&
2217 NT_STATUS_IS_OK(cli_lock32(cli2, fnum2, 0, 4, 0, READ_LOCK));
2219 EXPECTED(ret, True);
2220 printf("the first unlock removes the %s lock\n", ret?"WRITE":"READ");
2222 /* Unlock the process 2 lock. */
2223 cli_unlock(cli2, fnum2, 0, 4);
2225 /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */
2227 ret = NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 1, 1)) &&
2228 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 0, 4)) &&
2229 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 0, 4));
2231 EXPECTED(ret, True);
2232 printf("the same process %s unlock the stack of 4 locks\n", ret?"can":"cannot");
2234 /* Ensure the next unlock fails. */
2235 ret = NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 0, 4));
2236 EXPECTED(ret, False);
2237 printf("the same process %s count the lock stack\n", !ret?"can":"cannot");
2239 /* Ensure connection 2 can get a write lock. */
2240 status = cli_lock32(cli2, fnum2, 0, 4, 0, WRITE_LOCK);
2241 ret = NT_STATUS_IS_OK(status);
2242 EXPECTED(ret, True);
2244 printf("a different processs %s get a write lock on the unlocked stack\n", ret?"can":"cannot");
2248 cli_close(cli1, fnum1);
2249 cli_close(cli2, fnum2);
2250 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2251 if (!torture_close_connection(cli1)) {
2254 if (!torture_close_connection(cli2)) {
2258 printf("finished locktest5\n");
2264 tries the unusual lockingX locktype bits
2266 static bool run_locktest6(int dummy)
2268 static struct cli_state *cli;
2269 const char *fname[1] = { "\\lock6.txt" };
2274 if (!torture_open_connection(&cli, 0)) {
2278 cli_sockopt(cli, sockops);
2280 printf("starting locktest6\n");
2283 printf("Testing %s\n", fname[i]);
2285 cli_unlink(cli, fname[i], FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2287 cli_open(cli, fname[i], O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
2288 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE);
2289 cli_close(cli, fnum);
2290 printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status));
2292 cli_open(cli, fname[i], O_RDWR, DENY_NONE, &fnum);
2293 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK);
2294 cli_close(cli, fnum);
2295 printf("CANCEL_LOCK gave %s\n", nt_errstr(status));
2297 cli_unlink(cli, fname[i], FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2300 torture_close_connection(cli);
2302 printf("finished locktest6\n");
2306 static bool run_locktest7(int dummy)
2308 struct cli_state *cli1;
2309 const char *fname = "\\lockt7.lck";
2312 bool correct = False;
2316 if (!torture_open_connection(&cli1, 0)) {
2320 cli_sockopt(cli1, sockops);
2322 printf("starting locktest7\n");
2324 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2326 cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
2328 memset(buf, 0, sizeof(buf));
2330 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 0, sizeof(buf),
2332 if (!NT_STATUS_IS_OK(status)) {
2333 printf("Failed to create file: %s\n", nt_errstr(status));
2337 cli_setpid(cli1, 1);
2339 status = cli_lock32(cli1, fnum1, 130, 4, 0, READ_LOCK);
2340 if (!NT_STATUS_IS_OK(status)) {
2341 printf("Unable to apply read lock on range 130:4, "
2342 "error was %s\n", nt_errstr(status));
2345 printf("pid1 successfully locked range 130:4 for READ\n");
2348 status = cli_read(cli1, fnum1, buf, 130, 4, &nread);
2349 if (!NT_STATUS_IS_OK(status)) {
2350 printf("pid1 unable to read the range 130:4, error was %s\n",
2353 } else if (nread != 4) {
2354 printf("pid1 unable to read the range 130:4, "
2355 "recv %ld req %d\n", (unsigned long)nread, 4);
2358 printf("pid1 successfully read the range 130:4\n");
2361 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
2362 if (!NT_STATUS_IS_OK(status)) {
2363 printf("pid1 unable to write to the range 130:4, error was "
2364 "%s\n", nt_errstr(status));
2365 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_LOCK_CONFLICT)) {
2366 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2370 printf("pid1 successfully wrote to the range 130:4 (should be denied)\n");
2374 cli_setpid(cli1, 2);
2376 status = cli_read(cli1, fnum1, buf, 130, 4, &nread);
2377 if (!NT_STATUS_IS_OK(status)) {
2378 printf("pid2 unable to read the range 130:4, error was %s\n",
2381 } else if (nread != 4) {
2382 printf("pid2 unable to read the range 130:4, "
2383 "recv %ld req %d\n", (unsigned long)nread, 4);
2386 printf("pid2 successfully read the range 130:4\n");
2389 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
2390 if (!NT_STATUS_IS_OK(status)) {
2391 printf("pid2 unable to write to the range 130:4, error was "
2392 "%s\n", nt_errstr(status));
2393 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_LOCK_CONFLICT)) {
2394 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2398 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
2402 cli_setpid(cli1, 1);
2403 cli_unlock(cli1, fnum1, 130, 4);
2405 status = cli_lock32(cli1, fnum1, 130, 4, 0, WRITE_LOCK);
2406 if (!NT_STATUS_IS_OK(status)) {
2407 printf("Unable to apply write lock on range 130:4, error was %s\n", nt_errstr(status));
2410 printf("pid1 successfully locked range 130:4 for WRITE\n");
2413 status = cli_read(cli1, fnum1, buf, 130, 4, &nread);
2414 if (!NT_STATUS_IS_OK(status)) {
2415 printf("pid1 unable to read the range 130:4, error was %s\n",
2418 } else if (nread != 4) {
2419 printf("pid1 unable to read the range 130:4, "
2420 "recv %ld req %d\n", (unsigned long)nread, 4);
2423 printf("pid1 successfully read the range 130:4\n");
2426 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
2427 if (!NT_STATUS_IS_OK(status)) {
2428 printf("pid1 unable to write to the range 130:4, error was "
2429 "%s\n", nt_errstr(status));
2432 printf("pid1 successfully wrote to the range 130:4\n");
2435 cli_setpid(cli1, 2);
2437 status = cli_read(cli1, fnum1, buf, 130, 4, &nread);
2438 if (!NT_STATUS_IS_OK(status)) {
2439 printf("pid2 unable to read the range 130:4, error was "
2440 "%s\n", nt_errstr(status));
2441 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_LOCK_CONFLICT)) {
2442 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2446 printf("pid2 successfully read the range 130:4 (should be denied) recv %ld\n",
2447 (unsigned long)nread);
2451 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
2452 if (!NT_STATUS_IS_OK(status)) {
2453 printf("pid2 unable to write to the range 130:4, error was "
2454 "%s\n", nt_errstr(status));
2455 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_LOCK_CONFLICT)) {
2456 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2460 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
2464 cli_unlock(cli1, fnum1, 130, 0);
2468 cli_close(cli1, fnum1);
2469 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2470 torture_close_connection(cli1);
2472 printf("finished locktest7\n");
2477 * This demonstrates a problem with our use of GPFS share modes: A file
2478 * descriptor sitting in the pending close queue holding a GPFS share mode
2479 * blocks opening a file another time. Happens with Word 2007 temp files.
2480 * With "posix locking = yes" and "gpfs:sharemodes = yes" enabled, the third
2481 * open is denied with NT_STATUS_SHARING_VIOLATION.
2484 static bool run_locktest8(int dummy)
2486 struct cli_state *cli1;
2487 const char *fname = "\\lockt8.lck";
2488 uint16_t fnum1, fnum2;
2490 bool correct = False;
2493 if (!torture_open_connection(&cli1, 0)) {
2497 cli_sockopt(cli1, sockops);
2499 printf("starting locktest8\n");
2501 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2503 status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_WRITE,
2505 if (!NT_STATUS_IS_OK(status)) {
2506 d_fprintf(stderr, "cli_open returned %s\n", nt_errstr(status));
2510 memset(buf, 0, sizeof(buf));
2512 status = cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum2);
2513 if (!NT_STATUS_IS_OK(status)) {
2514 d_fprintf(stderr, "cli_open second time returned %s\n",
2519 status = cli_lock32(cli1, fnum2, 1, 1, 0, READ_LOCK);
2520 if (!NT_STATUS_IS_OK(status)) {
2521 printf("Unable to apply read lock on range 1:1, error was "
2522 "%s\n", nt_errstr(status));
2526 status = cli_close(cli1, fnum1);
2527 if (!NT_STATUS_IS_OK(status)) {
2528 d_fprintf(stderr, "cli_close(fnum1) %s\n", nt_errstr(status));
2532 status = cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
2533 if (!NT_STATUS_IS_OK(status)) {
2534 d_fprintf(stderr, "cli_open third time returned %s\n",
2542 cli_close(cli1, fnum1);
2543 cli_close(cli1, fnum2);
2544 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2545 torture_close_connection(cli1);
2547 printf("finished locktest8\n");
2552 * This test is designed to be run in conjunction with
2553 * external NFS or POSIX locks taken in the filesystem.
2554 * It checks that the smbd server will block until the
2555 * lock is released and then acquire it. JRA.
2558 static bool got_alarm;
2559 static struct cli_state *alarm_cli;
2561 static void alarm_handler(int dummy)
2566 static void alarm_handler_parent(int dummy)
2568 cli_state_disconnect(alarm_cli);
2571 static void do_local_lock(int read_fd, int write_fd)
2576 const char *local_pathname = NULL;
2579 local_pathname = talloc_asprintf(talloc_tos(),
2580 "%s/lockt9.lck", local_path);
2581 if (!local_pathname) {
2582 printf("child: alloc fail\n");
2586 unlink(local_pathname);
2587 fd = open(local_pathname, O_RDWR|O_CREAT, 0666);
2589 printf("child: open of %s failed %s.\n",
2590 local_pathname, strerror(errno));
2594 /* Now take a fcntl lock. */
2595 lock.l_type = F_WRLCK;
2596 lock.l_whence = SEEK_SET;
2599 lock.l_pid = getpid();
2601 ret = fcntl(fd,F_SETLK,&lock);
2603 printf("child: failed to get lock 0:4 on file %s. Error %s\n",
2604 local_pathname, strerror(errno));
2607 printf("child: got lock 0:4 on file %s.\n",
2612 CatchSignal(SIGALRM, alarm_handler);
2614 /* Signal the parent. */
2615 if (write(write_fd, &c, 1) != 1) {
2616 printf("child: start signal fail %s.\n",
2623 /* Wait for the parent to be ready. */
2624 if (read(read_fd, &c, 1) != 1) {
2625 printf("child: reply signal fail %s.\n",
2633 printf("child: released lock 0:4 on file %s.\n",
2639 static bool run_locktest9(int dummy)
2641 struct cli_state *cli1;
2642 const char *fname = "\\lockt9.lck";
2644 bool correct = False;
2645 int pipe_in[2], pipe_out[2];
2649 struct timeval start;
2653 printf("starting locktest9\n");
2655 if (local_path == NULL) {
2656 d_fprintf(stderr, "locktest9 must be given a local path via -l <localpath>\n");
2660 if (pipe(pipe_in) == -1 || pipe(pipe_out) == -1) {
2665 if (child_pid == -1) {
2669 if (child_pid == 0) {
2671 do_local_lock(pipe_out[0], pipe_in[1]);
2681 ret = read(pipe_in[0], &c, 1);
2683 d_fprintf(stderr, "failed to read start signal from child. %s\n",
2688 if (!torture_open_connection(&cli1, 0)) {
2692 cli_sockopt(cli1, sockops);
2694 status = cli_open(cli1, fname, O_RDWR, DENY_NONE,
2696 if (!NT_STATUS_IS_OK(status)) {
2697 d_fprintf(stderr, "cli_open returned %s\n", nt_errstr(status));
2701 /* Ensure the child has the lock. */
2702 status = cli_lock32(cli1, fnum, 0, 4, 0, WRITE_LOCK);
2703 if (NT_STATUS_IS_OK(status)) {
2704 d_fprintf(stderr, "Got the lock on range 0:4 - this should not happen !\n");
2707 d_printf("Child has the lock.\n");
2710 /* Tell the child to wait 5 seconds then exit. */
2711 ret = write(pipe_out[1], &c, 1);
2713 d_fprintf(stderr, "failed to send exit signal to child. %s\n",
2718 /* Wait 20 seconds for the lock. */
2720 CatchSignal(SIGALRM, alarm_handler_parent);
2723 start = timeval_current();
2725 status = cli_lock32(cli1, fnum, 0, 4, -1, WRITE_LOCK);
2726 if (!NT_STATUS_IS_OK(status)) {
2727 d_fprintf(stderr, "Unable to apply write lock on range 0:4, error was "
2728 "%s\n", nt_errstr(status));
2733 seconds = timeval_elapsed(&start);
2735 printf("Parent got the lock after %.2f seconds.\n",
2738 status = cli_close(cli1, fnum);
2739 if (!NT_STATUS_IS_OK(status)) {
2740 d_fprintf(stderr, "cli_close(fnum1) %s\n", nt_errstr(status));
2747 cli_close(cli1, fnum);
2748 torture_close_connection(cli1);
2752 printf("finished locktest9\n");
2757 test whether fnums and tids open on one VC are available on another (a major
2760 static bool run_fdpasstest(int dummy)
2762 struct cli_state *cli1, *cli2;
2763 const char *fname = "\\fdpass.tst";
2768 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
2771 cli_sockopt(cli1, sockops);
2772 cli_sockopt(cli2, sockops);
2774 printf("starting fdpasstest\n");
2776 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2778 status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
2780 if (!NT_STATUS_IS_OK(status)) {
2781 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
2785 status = cli_writeall(cli1, fnum1, 0, (const uint8_t *)"hello world\n", 0,
2787 if (!NT_STATUS_IS_OK(status)) {
2788 printf("write failed (%s)\n", nt_errstr(status));
2792 cli_state_set_uid(cli2, cli_state_get_uid(cli1));
2793 cli_state_set_tid(cli2, cli_state_get_tid(cli1));
2794 cli_setpid(cli2, cli_getpid(cli1));
2796 if (test_cli_read(cli2, fnum1, buf, 0, 13, NULL, 13)) {
2797 printf("read succeeded! nasty security hole [%s]\n", buf);
2801 cli_close(cli1, fnum1);
2802 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2804 torture_close_connection(cli1);
2805 torture_close_connection(cli2);
2807 printf("finished fdpasstest\n");
2811 static bool run_fdsesstest(int dummy)
2813 struct cli_state *cli;
2818 const char *fname = "\\fdsess.tst";
2819 const char *fname1 = "\\fdsess1.tst";
2826 if (!torture_open_connection(&cli, 0))
2828 cli_sockopt(cli, sockops);
2830 if (!torture_cli_session_setup2(cli, &new_vuid))
2833 saved_cnum = cli_state_get_tid(cli);
2834 if (!NT_STATUS_IS_OK(cli_tcon_andx(cli, share, "?????", "", 1)))
2836 new_cnum = cli_state_get_tid(cli);
2837 cli_state_set_tid(cli, saved_cnum);
2839 printf("starting fdsesstest\n");
2841 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2842 cli_unlink(cli, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2844 status = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
2845 if (!NT_STATUS_IS_OK(status)) {
2846 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
2850 status = cli_writeall(cli, fnum1, 0, (const uint8_t *)"hello world\n", 0, 13,
2852 if (!NT_STATUS_IS_OK(status)) {
2853 printf("write failed (%s)\n", nt_errstr(status));
2857 saved_vuid = cli_state_get_uid(cli);
2858 cli_state_set_uid(cli, new_vuid);
2860 if (test_cli_read(cli, fnum1, buf, 0, 13, NULL, 13)) {
2861 printf("read succeeded with different vuid! "
2862 "nasty security hole [%s]\n", buf);
2865 /* Try to open a file with different vuid, samba cnum. */
2866 if (NT_STATUS_IS_OK(cli_open(cli, fname1, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum2))) {
2867 printf("create with different vuid, same cnum succeeded.\n");
2868 cli_close(cli, fnum2);
2869 cli_unlink(cli, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2871 printf("create with different vuid, same cnum failed.\n");
2872 printf("This will cause problems with service clients.\n");
2876 cli_state_set_uid(cli, saved_vuid);
2878 /* Try with same vuid, different cnum. */
2879 cli_state_set_tid(cli, new_cnum);
2881 if (test_cli_read(cli, fnum1, buf, 0, 13, NULL, 13)) {
2882 printf("read succeeded with different cnum![%s]\n", buf);
2886 cli_state_set_tid(cli, saved_cnum);
2887 cli_close(cli, fnum1);
2888 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2890 torture_close_connection(cli);
2892 printf("finished fdsesstest\n");
2897 This test checks that
2899 1) the server does not allow an unlink on a file that is open
2901 static bool run_unlinktest(int dummy)
2903 struct cli_state *cli;
2904 const char *fname = "\\unlink.tst";
2906 bool correct = True;
2909 if (!torture_open_connection(&cli, 0)) {
2913 cli_sockopt(cli, sockops);
2915 printf("starting unlink test\n");
2917 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2921 status = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
2922 if (!NT_STATUS_IS_OK(status)) {
2923 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
2927 status = cli_unlink(cli, fname,
2928 FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2929 if (NT_STATUS_IS_OK(status)) {
2930 printf("error: server allowed unlink on an open file\n");
2933 correct = check_error(__LINE__, status, ERRDOS, ERRbadshare,
2934 NT_STATUS_SHARING_VIOLATION);
2937 cli_close(cli, fnum);
2938 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2940 if (!torture_close_connection(cli)) {
2944 printf("unlink test finished\n");
2951 test how many open files this server supports on the one socket
2953 static bool run_maxfidtest(int dummy)
2955 struct cli_state *cli;
2957 uint16_t fnums[0x11000];
2960 bool correct = True;
2966 printf("failed to connect\n");
2970 cli_sockopt(cli, sockops);
2972 for (i=0; i<0x11000; i++) {
2973 slprintf(fname,sizeof(fname)-1,"\\maxfid.%d.%d", i,(int)getpid());
2974 status = cli_open(cli, fname, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE,
2976 if (!NT_STATUS_IS_OK(status)) {
2977 printf("open of %s failed (%s)\n",
2978 fname, nt_errstr(status));
2979 printf("maximum fnum is %d\n", i);
2987 printf("cleaning up\n");
2989 slprintf(fname,sizeof(fname)-1,"\\maxfid.%d.%d", i,(int)getpid());
2990 cli_close(cli, fnums[i]);
2992 status = cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2993 if (!NT_STATUS_IS_OK(status)) {
2994 printf("unlink of %s failed (%s)\n",
2995 fname, nt_errstr(status));
3002 printf("maxfid test finished\n");
3003 if (!torture_close_connection(cli)) {
3009 /* generate a random buffer */
3010 static void rand_buf(char *buf, int len)
3013 *buf = (char)sys_random();
3018 /* send smb negprot commands, not reading the response */
3019 static bool run_negprot_nowait(int dummy)
3021 struct tevent_context *ev;
3023 struct cli_state *cli;
3024 bool correct = True;
3026 printf("starting negprot nowait test\n");
3028 ev = tevent_context_init(talloc_tos());
3033 if (!(cli = open_nbt_connection())) {
3038 for (i=0;i<50000;i++) {
3039 struct tevent_req *req;
3041 req = cli_negprot_send(ev, ev, cli, PROTOCOL_NT1);
3046 if (!tevent_req_poll(req, ev)) {
3047 d_fprintf(stderr, "tevent_req_poll failed: %s\n",
3055 if (torture_close_connection(cli)) {
3059 printf("finished negprot nowait test\n");
3064 /* send smb negprot commands, not reading the response */
3065 static bool run_bad_nbt_session(int dummy)
3067 struct nmb_name called, calling;
3068 struct sockaddr_storage ss;
3073 printf("starting bad nbt session test\n");
3075 make_nmb_name(&calling, myname, 0x0);
3076 make_nmb_name(&called , host, 0x20);
3078 if (!resolve_name(host, &ss, 0x20, true)) {
3079 d_fprintf(stderr, "Could not resolve name %s\n", host);
3083 status = open_socket_out(&ss, 139, 10000, &fd);
3084 if (!NT_STATUS_IS_OK(status)) {
3085 d_fprintf(stderr, "open_socket_out failed: %s\n",
3090 ret = cli_bad_session_request(fd, &calling, &called);
3093 d_fprintf(stderr, "open_socket_out failed: %s\n",
3098 printf("finished bad nbt session test\n");
3102 /* send random IPC commands */
3103 static bool run_randomipc(int dummy)
3105 char *rparam = NULL;
3107 unsigned int rdrcnt,rprcnt;
3109 int api, param_len, i;
3110 struct cli_state *cli;
3111 bool correct = True;
3114 printf("starting random ipc test\n");
3116 if (!torture_open_connection(&cli, 0)) {
3120 for (i=0;i<count;i++) {
3121 api = sys_random() % 500;
3122 param_len = (sys_random() % 64);
3124 rand_buf(param, param_len);
3129 param, param_len, 8,
3130 NULL, 0, BUFFER_SIZE,
3134 printf("%d/%d\r", i,count);
3137 printf("%d/%d\n", i, count);
3139 if (!torture_close_connection(cli)) {
3143 printf("finished random ipc test\n");
3150 static void browse_callback(const char *sname, uint32 stype,
3151 const char *comment, void *state)
3153 printf("\t%20.20s %08x %s\n", sname, stype, comment);
3159 This test checks the browse list code
3162 static bool run_browsetest(int dummy)
3164 static struct cli_state *cli;
3165 bool correct = True;
3167 printf("starting browse test\n");
3169 if (!torture_open_connection(&cli, 0)) {
3173 printf("domain list:\n");
3174 cli_NetServerEnum(cli, cli->server_domain,
3175 SV_TYPE_DOMAIN_ENUM,
3176 browse_callback, NULL);
3178 printf("machine list:\n");
3179 cli_NetServerEnum(cli, cli->server_domain,
3181 browse_callback, NULL);
3183 if (!torture_close_connection(cli)) {
3187 printf("browse test finished\n");
3195 This checks how the getatr calls works
3197 static bool run_attrtest(int dummy)
3199 struct cli_state *cli;
3202 const char *fname = "\\attrib123456789.tst";
3203 bool correct = True;
3206 printf("starting attrib test\n");
3208 if (!torture_open_connection(&cli, 0)) {
3212 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3213 cli_open(cli, fname,
3214 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
3215 cli_close(cli, fnum);
3217 status = cli_getatr(cli, fname, NULL, NULL, &t);
3218 if (!NT_STATUS_IS_OK(status)) {
3219 printf("getatr failed (%s)\n", nt_errstr(status));
3223 if (abs(t - time(NULL)) > 60*60*24*10) {
3224 printf("ERROR: SMBgetatr bug. time is %s",
3230 t2 = t-60*60*24; /* 1 day ago */
3232 status = cli_setatr(cli, fname, 0, t2);
3233 if (!NT_STATUS_IS_OK(status)) {
3234 printf("setatr failed (%s)\n", nt_errstr(status));
3238 status = cli_getatr(cli, fname, NULL, NULL, &t);
3239 if (!NT_STATUS_IS_OK(status)) {
3240 printf("getatr failed (%s)\n", nt_errstr(status));
3245 printf("ERROR: getatr/setatr bug. times are\n%s",
3247 printf("%s", ctime(&t2));
3251 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3253 if (!torture_close_connection(cli)) {
3257 printf("attrib test finished\n");
3264 This checks a couple of trans2 calls
3266 static bool run_trans2test(int dummy)
3268 struct cli_state *cli;
3271 time_t c_time, a_time, m_time;
3272 struct timespec c_time_ts, a_time_ts, m_time_ts, w_time_ts, m_time2_ts;
3273 const char *fname = "\\trans2.tst";
3274 const char *dname = "\\trans2";
3275 const char *fname2 = "\\trans2\\trans2.tst";
3277 bool correct = True;
3281 printf("starting trans2 test\n");
3283 if (!torture_open_connection(&cli, 0)) {
3287 status = cli_get_fs_attr_info(cli, &fs_attr);
3288 if (!NT_STATUS_IS_OK(status)) {
3289 printf("ERROR: cli_get_fs_attr_info returned %s\n",
3294 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3295 cli_open(cli, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
3296 status = cli_qfileinfo_basic(cli, fnum, NULL, &size, &c_time_ts,
3297 &a_time_ts, &w_time_ts, &m_time_ts, NULL);
3298 if (!NT_STATUS_IS_OK(status)) {
3299 printf("ERROR: qfileinfo failed (%s)\n", nt_errstr(status));
3303 status = cli_qfilename(cli, fnum, talloc_tos(), &pname);
3304 if (!NT_STATUS_IS_OK(status)) {
3305 printf("ERROR: qfilename failed (%s)\n", nt_errstr(status));
3309 if (strcmp(pname, fname)) {
3310 printf("qfilename gave different name? [%s] [%s]\n",
3315 cli_close(cli, fnum);
3319 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3320 status = cli_open(cli, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE,
3322 if (!NT_STATUS_IS_OK(status)) {
3323 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
3326 cli_close(cli, fnum);
3328 status = cli_qpathinfo1(cli, fname, &c_time, &a_time, &m_time, &size,
3330 if (!NT_STATUS_IS_OK(status)) {
3331 printf("ERROR: qpathinfo failed (%s)\n", nt_errstr(status));
3334 time_t t = time(NULL);
3336 if (c_time != m_time) {
3337 printf("create time=%s", ctime(&c_time));
3338 printf("modify time=%s", ctime(&m_time));
3339 printf("This system appears to have sticky create times\n");
3341 if ((abs(a_time - t) > 60) && (a_time % (60*60) == 0)) {
3342 printf("access time=%s", ctime(&a_time));
3343 printf("This system appears to set a midnight access time\n");
3347 if (abs(m_time - t) > 60*60*24*7) {
3348 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
3354 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3355 cli_open(cli, fname,
3356 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
3357 cli_close(cli, fnum);
3358 status = cli_qpathinfo2(cli, fname, &c_time_ts, &a_time_ts, &w_time_ts,
3359 &m_time_ts, &size, NULL, NULL);
3360 if (!NT_STATUS_IS_OK(status)) {
3361 printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status));
3364 if (w_time_ts.tv_sec < 60*60*24*2) {
3365 printf("write time=%s", ctime(&w_time_ts.tv_sec));
3366 printf("This system appears to set a initial 0 write time\n");
3371 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3374 /* check if the server updates the directory modification time
3375 when creating a new file */
3376 status = cli_mkdir(cli, dname);
3377 if (!NT_STATUS_IS_OK(status)) {
3378 printf("ERROR: mkdir failed (%s)\n", nt_errstr(status));
3382 status = cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts,
3383 &w_time_ts, &m_time_ts, &size, NULL, NULL);
3384 if (!NT_STATUS_IS_OK(status)) {
3385 printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status));
3389 cli_open(cli, fname2,
3390 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
3391 cli_writeall(cli, fnum, 0, (uint8_t *)&fnum, 0, sizeof(fnum), NULL);
3392 cli_close(cli, fnum);
3393 status = cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts,
3394 &w_time_ts, &m_time2_ts, &size, NULL, NULL);
3395 if (!NT_STATUS_IS_OK(status)) {
3396 printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status));
3399 if (memcmp(&m_time_ts, &m_time2_ts, sizeof(struct timespec))
3401 printf("This system does not update directory modification times\n");
3405 cli_unlink(cli, fname2, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3406 cli_rmdir(cli, dname);
3408 if (!torture_close_connection(cli)) {
3412 printf("trans2 test finished\n");
3418 This checks new W2K calls.
3421 static NTSTATUS new_trans(struct cli_state *pcli, int fnum, int level)
3423 uint8_t *buf = NULL;
3427 status = cli_qfileinfo(talloc_tos(), pcli, fnum, level, 0,
3428 CLI_BUFFER_SIZE, NULL, &buf, &len);
3429 if (!NT_STATUS_IS_OK(status)) {
3430 printf("ERROR: qfileinfo (%d) failed (%s)\n", level,
3433 printf("qfileinfo: level %d, len = %u\n", level, len);
3434 dump_data(0, (uint8 *)buf, len);
3441 static bool run_w2ktest(int dummy)
3443 struct cli_state *cli;
3445 const char *fname = "\\w2ktest\\w2k.tst";
3447 bool correct = True;
3449 printf("starting w2k test\n");
3451 if (!torture_open_connection(&cli, 0)) {
3455 cli_open(cli, fname,
3456 O_RDWR | O_CREAT , DENY_NONE, &fnum);
3458 for (level = 1004; level < 1040; level++) {
3459 new_trans(cli, fnum, level);
3462 cli_close(cli, fnum);
3464 if (!torture_close_connection(cli)) {
3468 printf("w2k test finished\n");
3475 this is a harness for some oplock tests
3477 static bool run_oplock1(int dummy)
3479 struct cli_state *cli1;
3480 const char *fname = "\\lockt1.lck";
3482 bool correct = True;
3485 printf("starting oplock test 1\n");
3487 if (!torture_open_connection(&cli1, 0)) {
3491 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3493 cli_sockopt(cli1, sockops);
3495 cli1->use_oplocks = True;
3497 status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
3499 if (!NT_STATUS_IS_OK(status)) {
3500 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
3504 cli1->use_oplocks = False;
3506 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3507 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3509 status = cli_close(cli1, fnum1);
3510 if (!NT_STATUS_IS_OK(status)) {
3511 printf("close2 failed (%s)\n", nt_errstr(status));
3515 status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3516 if (!NT_STATUS_IS_OK(status)) {
3517 printf("unlink failed (%s)\n", nt_errstr(status));
3521 if (!torture_close_connection(cli1)) {
3525 printf("finished oplock test 1\n");
3530 static bool run_oplock2(int dummy)
3532 struct cli_state *cli1, *cli2;
3533 const char *fname = "\\lockt2.lck";
3534 uint16_t fnum1, fnum2;
3535 int saved_use_oplocks = use_oplocks;
3537 bool correct = True;
3538 volatile bool *shared_correct;
3542 shared_correct = (volatile bool *)shm_setup(sizeof(bool));
3543 *shared_correct = True;
3545 use_level_II_oplocks = True;
3548 printf("starting oplock test 2\n");
3550 if (!torture_open_connection(&cli1, 0)) {
3551 use_level_II_oplocks = False;
3552 use_oplocks = saved_use_oplocks;
3556 if (!torture_open_connection(&cli2, 1)) {
3557 use_level_II_oplocks = False;
3558 use_oplocks = saved_use_oplocks;
3562 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3564 cli_sockopt(cli1, sockops);
3565 cli_sockopt(cli2, sockops);
3567 status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
3569 if (!NT_STATUS_IS_OK(status)) {
3570 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
3574 /* Don't need the globals any more. */
3575 use_level_II_oplocks = False;
3576 use_oplocks = saved_use_oplocks;
3580 status = cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
3581 if (!NT_STATUS_IS_OK(status)) {
3582 printf("second open of %s failed (%s)\n", fname, nt_errstr(status));
3583 *shared_correct = False;
3589 status = cli_close(cli2, fnum2);
3590 if (!NT_STATUS_IS_OK(status)) {
3591 printf("close2 failed (%s)\n", nt_errstr(status));
3592 *shared_correct = False;
3600 /* Ensure cli1 processes the break. Empty file should always return 0
3602 status = cli_read(cli1, fnum1, buf, 0, 4, &nread);
3603 if (!NT_STATUS_IS_OK(status)) {
3604 printf("read on fnum1 failed (%s)\n", nt_errstr(status));
3606 } else if (nread != 0) {
3607 printf("read on empty fnum1 failed. recv %ld expected %d\n",
3608 (unsigned long)nread, 0);
3612 /* Should now be at level II. */
3613 /* Test if sending a write locks causes a break to none. */
3614 status = cli_lock32(cli1, fnum1, 0, 4, 0, READ_LOCK);
3615 if (!NT_STATUS_IS_OK(status)) {
3616 printf("lock failed (%s)\n", nt_errstr(status));
3620 cli_unlock(cli1, fnum1, 0, 4);
3624 status = cli_lock32(cli1, fnum1, 0, 4, 0, WRITE_LOCK);
3625 if (!NT_STATUS_IS_OK(status)) {
3626 printf("lock failed (%s)\n", nt_errstr(status));
3630 cli_unlock(cli1, fnum1, 0, 4);
3634 cli_read(cli1, fnum1, buf, 0, 4, NULL);
3636 status = cli_close(cli1, fnum1);
3637 if (!NT_STATUS_IS_OK(status)) {
3638 printf("close1 failed (%s)\n", nt_errstr(status));
3644 status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3645 if (!NT_STATUS_IS_OK(status)) {
3646 printf("unlink failed (%s)\n", nt_errstr(status));
3650 if (!torture_close_connection(cli1)) {
3654 if (!*shared_correct) {
3658 printf("finished oplock test 2\n");
3663 struct oplock4_state {
3664 struct tevent_context *ev;
3665 struct cli_state *cli;
3670 static void oplock4_got_break(struct tevent_req *req);
3671 static void oplock4_got_open(struct tevent_req *req);
3673 static bool run_oplock4(int dummy)
3675 struct tevent_context *ev;
3676 struct cli_state *cli1, *cli2;
3677 struct tevent_req *oplock_req, *open_req;
3678 const char *fname = "\\lockt4.lck";
3679 const char *fname_ln = "\\lockt4_ln.lck";
3680 uint16_t fnum1, fnum2;
3681 int saved_use_oplocks = use_oplocks;
3683 bool correct = true;
3687 struct oplock4_state *state;
3689 printf("starting oplock test 4\n");
3691 if (!torture_open_connection(&cli1, 0)) {
3692 use_level_II_oplocks = false;
3693 use_oplocks = saved_use_oplocks;
3697 if (!torture_open_connection(&cli2, 1)) {
3698 use_level_II_oplocks = false;
3699 use_oplocks = saved_use_oplocks;
3703 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3704 cli_unlink(cli1, fname_ln, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3706 cli_sockopt(cli1, sockops);
3707 cli_sockopt(cli2, sockops);
3709 /* Create the file. */
3710 status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
3712 if (!NT_STATUS_IS_OK(status)) {
3713 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
3717 status = cli_close(cli1, fnum1);
3718 if (!NT_STATUS_IS_OK(status)) {
3719 printf("close1 failed (%s)\n", nt_errstr(status));
3723 /* Now create a hardlink. */
3724 status = cli_nt_hardlink(cli1, fname, fname_ln);
3725 if (!NT_STATUS_IS_OK(status)) {
3726 printf("nt hardlink failed (%s)\n", nt_errstr(status));
3730 /* Prove that opening hardlinks cause deny modes to conflict. */
3731 status = cli_open(cli1, fname, O_RDWR, DENY_ALL, &fnum1);
3732 if (!NT_STATUS_IS_OK(status)) {
3733 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
3737 status = cli_open(cli1, fname_ln, O_RDWR, DENY_NONE, &fnum2);
3738 if (NT_STATUS_IS_OK(status)) {
3739 printf("open of %s succeeded - should fail with sharing violation.\n",
3744 if (!NT_STATUS_EQUAL(status, NT_STATUS_SHARING_VIOLATION)) {
3745 printf("open of %s should fail with sharing violation. Got %s\n",
3746 fname_ln, nt_errstr(status));
3750 status = cli_close(cli1, fnum1);
3751 if (!NT_STATUS_IS_OK(status)) {
3752 printf("close1 failed (%s)\n", nt_errstr(status));
3756 cli1->use_oplocks = true;
3757 cli2->use_oplocks = true;
3759 status = cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
3760 if (!NT_STATUS_IS_OK(status)) {
3761 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
3765 ev = tevent_context_init(talloc_tos());
3767 printf("tevent_req_create failed\n");
3771 state = talloc(ev, struct oplock4_state);
3772 if (state == NULL) {
3773 printf("talloc failed\n");
3778 state->got_break = &got_break;
3779 state->fnum2 = &fnum2;
3781 oplock_req = cli_smb_oplock_break_waiter_send(
3782 talloc_tos(), ev, cli1);
3783 if (oplock_req == NULL) {
3784 printf("cli_smb_oplock_break_waiter_send failed\n");
3787 tevent_req_set_callback(oplock_req, oplock4_got_break, state);
3789 open_req = cli_open_send(
3790 talloc_tos(), ev, cli2, fname_ln, O_RDWR, DENY_NONE);
3791 if (oplock_req == NULL) {
3792 printf("cli_open_send failed\n");
3795 tevent_req_set_callback(open_req, oplock4_got_open, state);
3800 while (!got_break || fnum2 == 0xffff) {
3802 ret = tevent_loop_once(ev);
3804 printf("tevent_loop_once failed: %s\n",
3810 status = cli_close(cli2, fnum2);
3811 if (!NT_STATUS_IS_OK(status)) {
3812 printf("close2 failed (%s)\n", nt_errstr(status));
3816 status = cli_close(cli1, fnum1);
3817 if (!NT_STATUS_IS_OK(status)) {
3818 printf("close1 failed (%s)\n", nt_errstr(status));
3822 status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3823 if (!NT_STATUS_IS_OK(status)) {
3824 printf("unlink failed (%s)\n", nt_errstr(status));
3828 status = cli_unlink(cli1, fname_ln, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3829 if (!NT_STATUS_IS_OK(status)) {
3830 printf("unlink failed (%s)\n", nt_errstr(status));
3834 if (!torture_close_connection(cli1)) {
3842 printf("finished oplock test 4\n");
3847 static void oplock4_got_break(struct tevent_req *req)
3849 struct oplock4_state *state = tevent_req_callback_data(
3850 req, struct oplock4_state);
3855 status = cli_smb_oplock_break_waiter_recv(req, &fnum, &level);
3857 if (!NT_STATUS_IS_OK(status)) {
3858 printf("cli_smb_oplock_break_waiter_recv returned %s\n",
3862 *state->got_break = true;
3864 req = cli_oplock_ack_send(state, state->ev, state->cli, fnum,
3867 printf("cli_oplock_ack_send failed\n");
3872 static void oplock4_got_open(struct tevent_req *req)
3874 struct oplock4_state *state = tevent_req_callback_data(
3875 req, struct oplock4_state);
3878 status = cli_open_recv(req, state->fnum2);
3879 if (!NT_STATUS_IS_OK(status)) {
3880 printf("cli_open_recv returned %s\n", nt_errstr(status));
3881 *state->fnum2 = 0xffff;
3886 Test delete on close semantics.
3888 static bool run_deletetest(int dummy)
3890 struct cli_state *cli1 = NULL;
3891 struct cli_state *cli2 = NULL;
3892 const char *fname = "\\delete.file";
3893 uint16_t fnum1 = (uint16_t)-1;
3894 uint16_t fnum2 = (uint16_t)-1;
3895 bool correct = True;
3898 printf("starting delete test\n");
3900 if (!torture_open_connection(&cli1, 0)) {
3904 cli_sockopt(cli1, sockops);
3906 /* Test 1 - this should delete the file on close. */
3908 cli_setatr(cli1, fname, 0, 0);
3909 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3911 status = cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
3912 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
3913 FILE_DELETE_ON_CLOSE, 0, &fnum1);
3914 if (!NT_STATUS_IS_OK(status)) {
3915 printf("[1] open of %s failed (%s)\n", fname, nt_errstr(status));
3920 status = cli_close(cli1, fnum1);
3921 if (!NT_STATUS_IS_OK(status)) {
3922 printf("[1] close failed (%s)\n", nt_errstr(status));
3927 if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1))) {
3928 printf("[1] open of %s succeeded (should fail)\n", fname);
3933 printf("first delete on close test succeeded.\n");
3935 /* Test 2 - this should delete the file on close. */
3937 cli_setatr(cli1, fname, 0, 0);
3938 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3940 status = cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS,
3941 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
3942 FILE_OVERWRITE_IF, 0, 0, &fnum1);
3943 if (!NT_STATUS_IS_OK(status)) {
3944 printf("[2] open of %s failed (%s)\n", fname, nt_errstr(status));
3949 status = cli_nt_delete_on_close(cli1, fnum1, true);
3950 if (!NT_STATUS_IS_OK(status)) {
3951 printf("[2] setting delete_on_close failed (%s)\n", nt_errstr(status));
3956 status = cli_close(cli1, fnum1);
3957 if (!NT_STATUS_IS_OK(status)) {
3958 printf("[2] close failed (%s)\n", nt_errstr(status));
3963 if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
3964 printf("[2] open of %s succeeded should have been deleted on close !\n", fname);
3965 status = cli_close(cli1, fnum1);
3966 if (!NT_STATUS_IS_OK(status)) {
3967 printf("[2] close failed (%s)\n", nt_errstr(status));
3971 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3973 printf("second delete on close test succeeded.\n");
3976 cli_setatr(cli1, fname, 0, 0);
3977 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3979 status = cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS,
3980 FILE_ATTRIBUTE_NORMAL,
3981 FILE_SHARE_READ|FILE_SHARE_WRITE,
3982 FILE_OVERWRITE_IF, 0, 0, &fnum1);
3983 if (!NT_STATUS_IS_OK(status)) {
3984 printf("[3] open - 1 of %s failed (%s)\n", fname, nt_errstr(status));
3989 /* This should fail with a sharing violation - open for delete is only compatible
3990 with SHARE_DELETE. */
3992 if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3993 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0, 0, &fnum2))) {
3994 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname);
3999 /* This should succeed. */
4000 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
4001 FILE_ATTRIBUTE_NORMAL,
4002 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4003 FILE_OPEN, 0, 0, &fnum2);
4004 if (!NT_STATUS_IS_OK(status)) {
4005 printf("[3] open - 2 of %s failed (%s)\n", fname, nt_errstr(status));
4010 status = cli_nt_delete_on_close(cli1, fnum1, true);
4011 if (!NT_STATUS_IS_OK(status)) {
4012 printf("[3] setting delete_on_close failed (%s)\n", nt_errstr(status));
4017 status = cli_close(cli1, fnum1);
4018 if (!NT_STATUS_IS_OK(status)) {
4019 printf("[3] close 1 failed (%s)\n", nt_errstr(status));
4024 status = cli_close(cli1, fnum2);
4025 if (!NT_STATUS_IS_OK(status)) {
4026 printf("[3] close 2 failed (%s)\n", nt_errstr(status));
4031 /* This should fail - file should no longer be there. */
4033 if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
4034 printf("[3] open of %s succeeded should have been deleted on close !\n", fname);
4035 status = cli_close(cli1, fnum1);
4036 if (!NT_STATUS_IS_OK(status)) {
4037 printf("[3] close failed (%s)\n", nt_errstr(status));
4039 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4043 printf("third delete on close test succeeded.\n");
4046 cli_setatr(cli1, fname, 0, 0);
4047 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4049 status = cli_ntcreate(cli1, fname, 0,
4050 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
4051 FILE_ATTRIBUTE_NORMAL,
4052 FILE_SHARE_READ|FILE_SHARE_WRITE,
4053 FILE_OVERWRITE_IF, 0, 0, &fnum1);
4054 if (!NT_STATUS_IS_OK(status)) {
4055 printf("[4] open of %s failed (%s)\n", fname, nt_errstr(status));
4060 /* This should succeed. */
4061 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
4062 FILE_ATTRIBUTE_NORMAL,
4063 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4064 FILE_OPEN, 0, 0, &fnum2);
4065 if (!NT_STATUS_IS_OK(status)) {
4066 printf("[4] open - 2 of %s failed (%s)\n", fname, nt_errstr(status));
4071 status = cli_close(cli1, fnum2);
4072 if (!NT_STATUS_IS_OK(status)) {
4073 printf("[4] close - 1 failed (%s)\n", nt_errstr(status));
4078 status = cli_nt_delete_on_close(cli1, fnum1, true);
4079 if (!NT_STATUS_IS_OK(status)) {
4080 printf("[4] setting delete_on_close failed (%s)\n", nt_errstr(status));
4085 /* This should fail - no more opens once delete on close set. */
4086 if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
4087 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4088 FILE_OPEN, 0, 0, &fnum2))) {
4089 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname );
4093 printf("fourth delete on close test succeeded.\n");
4095 status = cli_close(cli1, fnum1);
4096 if (!NT_STATUS_IS_OK(status)) {
4097 printf("[4] close - 2 failed (%s)\n", nt_errstr(status));
4103 cli_setatr(cli1, fname, 0, 0);
4104 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4106 status = cli_open(cli1, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum1);
4107 if (!NT_STATUS_IS_OK(status)) {
4108 printf("[5] open of %s failed (%s)\n", fname, nt_errstr(status));
4113 /* This should fail - only allowed on NT opens with DELETE access. */
4115 if (NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
4116 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
4121 status = cli_close(cli1, fnum1);
4122 if (!NT_STATUS_IS_OK(status)) {
4123 printf("[5] close - 2 failed (%s)\n", nt_errstr(status));
4128 printf("fifth delete on close test succeeded.\n");
4131 cli_setatr(cli1, fname, 0, 0);
4132 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4134 status = cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
4135 FILE_ATTRIBUTE_NORMAL,
4136 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4137 FILE_OVERWRITE_IF, 0, 0, &fnum1);
4138 if (!NT_STATUS_IS_OK(status)) {
4139 printf("[6] open of %s failed (%s)\n", fname,
4145 /* This should fail - only allowed on NT opens with DELETE access. */
4147 if (NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
4148 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
4153 status = cli_close(cli1, fnum1);
4154 if (!NT_STATUS_IS_OK(status)) {
4155 printf("[6] close - 2 failed (%s)\n", nt_errstr(status));
4160 printf("sixth delete on close test succeeded.\n");
4163 cli_setatr(cli1, fname, 0, 0);
4164 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4166 status = cli_ntcreate(cli1, fname, 0,
4167 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
4168 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
4170 if (!NT_STATUS_IS_OK(status)) {
4171 printf("[7] open of %s failed (%s)\n", fname, nt_errstr(status));
4176 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
4177 printf("[7] setting delete_on_close on file failed !\n");
4182 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, false))) {
4183 printf("[7] unsetting delete_on_close on file failed !\n");
4188 status = cli_close(cli1, fnum1);
4189 if (!NT_STATUS_IS_OK(status)) {
4190 printf("[7] close - 2 failed (%s)\n", nt_errstr(status));
4195 /* This next open should succeed - we reset the flag. */
4196 status = cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1);
4197 if (!NT_STATUS_IS_OK(status)) {
4198 printf("[5] open of %s failed (%s)\n", fname, nt_errstr(status));
4203 status = cli_close(cli1, fnum1);
4204 if (!NT_STATUS_IS_OK(status)) {
4205 printf("[7] close - 2 failed (%s)\n", nt_errstr(status));
4210 printf("seventh delete on close test succeeded.\n");
4213 cli_setatr(cli1, fname, 0, 0);
4214 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4216 if (!torture_open_connection(&cli2, 1)) {
4217 printf("[8] failed to open second connection.\n");
4222 cli_sockopt(cli1, sockops);
4224 status = cli_ntcreate(cli1, fname, 0,
4225 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
4226 FILE_ATTRIBUTE_NORMAL,
4227 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4228 FILE_OVERWRITE_IF, 0, 0, &fnum1);
4229 if (!NT_STATUS_IS_OK(status)) {
4230 printf("[8] open 1 of %s failed (%s)\n", fname, nt_errstr(status));
4235 status = cli_ntcreate(cli2, fname, 0,
4236 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
4237 FILE_ATTRIBUTE_NORMAL,
4238 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4239 FILE_OPEN, 0, 0, &fnum2);
4240 if (!NT_STATUS_IS_OK(status)) {
4241 printf("[8] open 2 of %s failed (%s)\n", fname, nt_errstr(status));
4246 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
4247 printf("[8] setting delete_on_close on file failed !\n");
4252 status = cli_close(cli1, fnum1);
4253 if (!NT_STATUS_IS_OK(status)) {
4254 printf("[8] close - 1 failed (%s)\n", nt_errstr(status));
4259 status = cli_close(cli2, fnum2);
4260 if (!NT_STATUS_IS_OK(status)) {
4261 printf("[8] close - 2 failed (%s)\n", nt_errstr(status));
4266 /* This should fail.. */
4267 status = cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1);
4268 if (NT_STATUS_IS_OK(status)) {
4269 printf("[8] open of %s succeeded should have been deleted on close !\n", fname);
4273 printf("eighth delete on close test succeeded.\n");
4275 /* This should fail - we need to set DELETE_ACCESS. */
4276 if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0,FILE_READ_DATA|FILE_WRITE_DATA,
4277 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, 0, &fnum1))) {
4278 printf("[9] open of %s succeeded should have failed!\n", fname);
4283 printf("ninth delete on close test succeeded.\n");
4285 status = cli_ntcreate(cli1, fname, 0,
4286 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
4287 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
4288 FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE,
4290 if (!NT_STATUS_IS_OK(status)) {
4291 printf("[10] open of %s failed (%s)\n", fname, nt_errstr(status));
4296 /* This should delete the file. */
4297 status = cli_close(cli1, fnum1);
4298 if (!NT_STATUS_IS_OK(status)) {
4299 printf("[10] close failed (%s)\n", nt_errstr(status));
4304 /* This should fail.. */
4305 if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
4306 printf("[10] open of %s succeeded should have been deleted on close !\n", fname);
4310 printf("tenth delete on close test succeeded.\n");
4312 cli_setatr(cli1, fname, 0, 0);
4313 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4315 /* What error do we get when attempting to open a read-only file with
4318 /* Create a readonly file. */
4319 status = cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
4320 FILE_ATTRIBUTE_READONLY, FILE_SHARE_NONE,
4321 FILE_OVERWRITE_IF, 0, 0, &fnum1);
4322 if (!NT_STATUS_IS_OK(status)) {
4323 printf("[11] open of %s failed (%s)\n", fname, nt_errstr(status));
4328 status = cli_close(cli1, fnum1);
4329 if (!NT_STATUS_IS_OK(status)) {
4330 printf("[11] close failed (%s)\n", nt_errstr(status));
4335 /* Now try open for delete access. */
4336 if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES|DELETE_ACCESS,
4337 0, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4338 FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
4339 printf("[11] open of %s succeeded should have been denied with ACCESS_DENIED!\n", fname);
4340 cli_close(cli1, fnum1);
4344 NTSTATUS nterr = cli_nt_error(cli1);
4345 if (!NT_STATUS_EQUAL(nterr,NT_STATUS_ACCESS_DENIED)) {
4346 printf("[11] open of %s should have been denied with ACCESS_DENIED! Got error %s\n", fname, nt_errstr(nterr));
4350 printf("eleventh delete on close test succeeded.\n");
4354 printf("finished delete test\n");
4357 /* FIXME: This will crash if we aborted before cli2 got
4358 * intialized, because these functions don't handle
4359 * uninitialized connections. */
4361 if (fnum1 != (uint16_t)-1) cli_close(cli1, fnum1);
4362 if (fnum2 != (uint16_t)-1) cli_close(cli1, fnum2);
4363 cli_setatr(cli1, fname, 0, 0);
4364 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4366 if (cli1 && !torture_close_connection(cli1)) {
4369 if (cli2 && !torture_close_connection(cli2)) {
4375 static bool run_deletetest_ln(int dummy)
4377 struct cli_state *cli;
4378 const char *fname = "\\delete1";
4379 const char *fname_ln = "\\delete1_ln";
4383 bool correct = true;
4386 printf("starting deletetest-ln\n");
4388 if (!torture_open_connection(&cli, 0)) {
4392 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4393 cli_unlink(cli, fname_ln, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4395 cli_sockopt(cli, sockops);
4397 /* Create the file. */
4398 status = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
4399 if (!NT_STATUS_IS_OK(status)) {
4400 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
4404 status = cli_close(cli, fnum);
4405 if (!NT_STATUS_IS_OK(status)) {
4406 printf("close1 failed (%s)\n", nt_errstr(status));
4410 /* Now create a hardlink. */
4411 status = cli_nt_hardlink(cli, fname, fname_ln);
4412 if (!NT_STATUS_IS_OK(status)) {
4413 printf("nt hardlink failed (%s)\n", nt_errstr(status));
4417 /* Open the original file. */
4418 status = cli_ntcreate(cli, fname, 0, FILE_READ_DATA,
4419 FILE_ATTRIBUTE_NORMAL,
4420 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4421 FILE_OPEN_IF, 0, 0, &fnum);
4422 if (!NT_STATUS_IS_OK(status)) {
4423 printf("ntcreate of %s failed (%s)\n", fname, nt_errstr(status));
4427 /* Unlink the hard link path. */
4428 status = cli_ntcreate(cli, fname_ln, 0, DELETE_ACCESS,
4429 FILE_ATTRIBUTE_NORMAL,
4430 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4431 FILE_OPEN_IF, 0, 0, &fnum1);
4432 if (!NT_STATUS_IS_OK(status)) {
4433 printf("ntcreate of %s failed (%s)\n", fname_ln, nt_errstr(status));
4436 status = cli_nt_delete_on_close(cli, fnum1, true);
4437 if (!NT_STATUS_IS_OK(status)) {
4438 d_printf("(%s) failed to set delete_on_close %s: %s\n",
4439 __location__, fname_ln, nt_errstr(status));
4443 status = cli_close(cli, fnum1);
4444 if (!NT_STATUS_IS_OK(status)) {
4445 printf("close %s failed (%s)\n",
4446 fname_ln, nt_errstr(status));
4450 status = cli_close(cli, fnum);
4451 if (!NT_STATUS_IS_OK(status)) {
4452 printf("close %s failed (%s)\n",
4453 fname, nt_errstr(status));
4457 /* Ensure the original file is still there. */
4458 status = cli_getatr(cli, fname, NULL, NULL, &t);
4459 if (!NT_STATUS_IS_OK(status)) {
4460 printf("%s getatr on file %s failed (%s)\n",
4467 /* Ensure the link path is gone. */
4468 status = cli_getatr(cli, fname_ln, NULL, NULL, &t);
4469 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
4470 printf("%s, getatr for file %s returned wrong error code %s "
4471 "- should have been deleted\n",
4473 fname_ln, nt_errstr(status));
4477 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4478 cli_unlink(cli, fname_ln, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4480 if (!torture_close_connection(cli)) {
4484 printf("finished deletetest-ln\n");
4490 print out server properties
4492 static bool run_properties(int dummy)
4494 struct cli_state *cli;
4495 bool correct = True;
4497 printf("starting properties test\n");
4501 if (!torture_open_connection(&cli, 0)) {
4505 cli_sockopt(cli, sockops);
4507 d_printf("Capabilities 0x%08x\n", cli_state_capabilities(cli));
4509 if (!torture_close_connection(cli)) {
4518 /* FIRST_DESIRED_ACCESS 0xf019f */
4519 #define FIRST_DESIRED_ACCESS FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|\
4520 FILE_READ_EA| /* 0xf */ \
4521 FILE_WRITE_EA|FILE_READ_ATTRIBUTES| /* 0x90 */ \
4522 FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
4523 DELETE_ACCESS|READ_CONTROL_ACCESS|\
4524 WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS /* 0xf0000 */
4525 /* SECOND_DESIRED_ACCESS 0xe0080 */
4526 #define SECOND_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
4527 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
4528 WRITE_OWNER_ACCESS /* 0xe0000 */
4531 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
4532 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
4534 WRITE_OWNER_ACCESS /* */
4538 Test ntcreate calls made by xcopy
4540 static bool run_xcopy(int dummy)
4542 static struct cli_state *cli1;
4543 const char *fname = "\\test.txt";
4544 bool correct = True;
4545 uint16_t fnum1, fnum2;
4548 printf("starting xcopy test\n");
4550 if (!torture_open_connection(&cli1, 0)) {
4554 status = cli_ntcreate(cli1, fname, 0, FIRST_DESIRED_ACCESS,
4555 FILE_ATTRIBUTE_ARCHIVE, FILE_SHARE_NONE,
4556 FILE_OVERWRITE_IF, 0x4044, 0, &fnum1);
4557 if (!NT_STATUS_IS_OK(status)) {
4558 printf("First open failed - %s\n", nt_errstr(status));
4562 status = cli_ntcreate(cli1, fname, 0, SECOND_DESIRED_ACCESS, 0,
4563 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4564 FILE_OPEN, 0x200000, 0, &fnum2);
4565 if (!NT_STATUS_IS_OK(status)) {
4566 printf("second open failed - %s\n", nt_errstr(status));
4570 if (!torture_close_connection(cli1)) {
4578 Test rename on files open with share delete and no share delete.
4580 static bool run_rename(int dummy)
4582 static struct cli_state *cli1;
4583 const char *fname = "\\test.txt";
4584 const char *fname1 = "\\test1.txt";
4585 bool correct = True;
4590 printf("starting rename test\n");
4592 if (!torture_open_connection(&cli1, 0)) {
4596 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4597 cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4599 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
4600 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ,
4601 FILE_OVERWRITE_IF, 0, 0, &fnum1);
4602 if (!NT_STATUS_IS_OK(status)) {
4603 printf("First open failed - %s\n", nt_errstr(status));
4607 status = cli_rename(cli1, fname, fname1);
4608 if (!NT_STATUS_IS_OK(status)) {
4609 printf("First rename failed (SHARE_READ) (this is correct) - %s\n", nt_errstr(status));
4611 printf("First rename succeeded (SHARE_READ) - this should have failed !\n");
4615 status = cli_close(cli1, fnum1);
4616 if (!NT_STATUS_IS_OK(status)) {
4617 printf("close - 1 failed (%s)\n", nt_errstr(status));
4621 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4622 cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4623 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
4625 FILE_SHARE_DELETE|FILE_SHARE_NONE,
4627 FILE_SHARE_DELETE|FILE_SHARE_READ,
4629 FILE_OVERWRITE_IF, 0, 0, &fnum1);
4630 if (!NT_STATUS_IS_OK(status)) {
4631 printf("Second open failed - %s\n", nt_errstr(status));
4635 status = cli_rename(cli1, fname, fname1);
4636 if (!NT_STATUS_IS_OK(status)) {
4637 printf("Second rename failed (SHARE_DELETE | SHARE_READ) - this should have succeeded - %s\n", nt_errstr(status));
4640 printf("Second rename succeeded (SHARE_DELETE | SHARE_READ)\n");
4643 status = cli_close(cli1, fnum1);
4644 if (!NT_STATUS_IS_OK(status)) {
4645 printf("close - 2 failed (%s)\n", nt_errstr(status));
4649 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4650 cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4652 status = cli_ntcreate(cli1, fname, 0, READ_CONTROL_ACCESS,
4653 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
4654 FILE_OVERWRITE_IF, 0, 0, &fnum1);
4655 if (!NT_STATUS_IS_OK(status)) {
4656 printf("Third open failed - %s\n", nt_errstr(status));
4665 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
4666 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum2))) {
4667 printf("Fourth open failed - %s\n", cli_errstr(cli1));
4670 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum2, true))) {
4671 printf("[8] setting delete_on_close on file failed !\n");
4675 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum2))) {
4676 printf("close - 4 failed (%s)\n", cli_errstr(cli1));
4682 status = cli_rename(cli1, fname, fname1);
4683 if (!NT_STATUS_IS_OK(status)) {
4684 printf("Third rename failed (SHARE_NONE) - this should have succeeded - %s\n", nt_errstr(status));
4687 printf("Third rename succeeded (SHARE_NONE)\n");
4690 status = cli_close(cli1, fnum1);
4691 if (!NT_STATUS_IS_OK(status)) {
4692 printf("close - 3 failed (%s)\n", nt_errstr(status));
4696 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4697 cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4701 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
4702 FILE_ATTRIBUTE_NORMAL,
4703 FILE_SHARE_READ | FILE_SHARE_WRITE,
4704 FILE_OVERWRITE_IF, 0, 0, &fnum1);
4705 if (!NT_STATUS_IS_OK(status)) {
4706 printf("Fourth open failed - %s\n", nt_errstr(status));
4710 status = cli_rename(cli1, fname, fname1);
4711 if (!NT_STATUS_IS_OK(status)) {
4712 printf("Fourth rename failed (SHARE_READ | SHARE_WRITE) (this is correct) - %s\n", nt_errstr(status));
4714 printf("Fourth rename succeeded (SHARE_READ | SHARE_WRITE) - this should have failed !\n");
4718 status = cli_close(cli1, fnum1);
4719 if (!NT_STATUS_IS_OK(status)) {
4720 printf("close - 4 failed (%s)\n", nt_errstr(status));
4724 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4725 cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4729 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
4730 FILE_ATTRIBUTE_NORMAL,
4731 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
4732 FILE_OVERWRITE_IF, 0, 0, &fnum1);
4733 if (!NT_STATUS_IS_OK(status)) {
4734 printf("Fifth open failed - %s\n", nt_errstr(status));
4738 status = cli_rename(cli1, fname, fname1);
4739 if (!NT_STATUS_IS_OK(status)) {
4740 printf("Fifth rename failed (SHARE_READ | SHARE_WRITE | SHARE_DELETE) - this should have succeeded - %s ! \n", nt_errstr(status));
4743 printf("Fifth rename succeeded (SHARE_READ | SHARE_WRITE | SHARE_DELETE) (this is correct) - %s\n", nt_errstr(status));
4747 * Now check if the first name still exists ...
4750 /* if (!NT_STATUS_OP(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
4751 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0, &fnum2))) {
4752 printf("Opening original file after rename of open file fails: %s\n",
4756 printf("Opening original file after rename of open file works ...\n");
4757 (void)cli_close(cli1, fnum2);
4761 status = cli_close(cli1, fnum1);
4762 if (!NT_STATUS_IS_OK(status)) {
4763 printf("close - 5 failed (%s)\n", nt_errstr(status));
4767 /* Check that the renamed file has FILE_ATTRIBUTE_ARCHIVE. */
4768 status = cli_getatr(cli1, fname1, &attr, NULL, NULL);
4769 if (!NT_STATUS_IS_OK(status)) {
4770 printf("getatr on file %s failed - %s ! \n",
4771 fname1, nt_errstr(status));
4774 if (attr != FILE_ATTRIBUTE_ARCHIVE) {
4775 printf("Renamed file %s has wrong attr 0x%x "
4776 "(should be 0x%x)\n",
4779 (unsigned int)FILE_ATTRIBUTE_ARCHIVE);
4782 printf("Renamed file %s has archive bit set\n", fname1);
4786 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4787 cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4789 if (!torture_close_connection(cli1)) {
4796 static bool run_pipe_number(int dummy)
4798 struct cli_state *cli1;
4799 const char *pipe_name = "\\SPOOLSS";
4804 printf("starting pipenumber test\n");
4805 if (!torture_open_connection(&cli1, 0)) {
4809 cli_sockopt(cli1, sockops);
4811 status = cli_ntcreate(cli1, pipe_name, 0, FILE_READ_DATA,
4812 FILE_ATTRIBUTE_NORMAL,
4813 FILE_SHARE_READ|FILE_SHARE_WRITE,
4814 FILE_OPEN_IF, 0, 0, &fnum);
4815 if (!NT_STATUS_IS_OK(status)) {
4816 printf("Open of pipe %s failed with error (%s)\n", pipe_name, nt_errstr(status));
4820 printf("\r%6d", num_pipes);
4823 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes, pipe_name );
4824 torture_close_connection(cli1);
4829 Test open mode returns on read-only files.
4831 static bool run_opentest(int dummy)
4833 static struct cli_state *cli1;
4834 static struct cli_state *cli2;
4835 const char *fname = "\\readonly.file";
4836 uint16_t fnum1, fnum2;
4839 bool correct = True;
4843 printf("starting open test\n");
4845 if (!torture_open_connection(&cli1, 0)) {
4849 cli_setatr(cli1, fname, 0, 0);
4850 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4852 cli_sockopt(cli1, sockops);
4854 status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
4855 if (!NT_STATUS_IS_OK(status)) {
4856 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
4860 status = cli_close(cli1, fnum1);
4861 if (!NT_STATUS_IS_OK(status)) {
4862 printf("close2 failed (%s)\n", nt_errstr(status));
4866 status = cli_setatr(cli1, fname, FILE_ATTRIBUTE_READONLY, 0);
4867 if (!NT_STATUS_IS_OK(status)) {
4868 printf("cli_setatr failed (%s)\n", nt_errstr(status));
4872 status = cli_open(cli1, fname, O_RDONLY, DENY_WRITE, &fnum1);
4873 if (!NT_STATUS_IS_OK(status)) {
4874 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
4878 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
4879 status = cli_open(cli1, fname, O_RDWR, DENY_ALL, &fnum2);
4881 if (check_error(__LINE__, status, ERRDOS, ERRnoaccess,
4882 NT_STATUS_ACCESS_DENIED)) {
4883 printf("correct error code ERRDOS/ERRnoaccess returned\n");
4886 printf("finished open test 1\n");
4888 cli_close(cli1, fnum1);
4890 /* Now try not readonly and ensure ERRbadshare is returned. */
4892 cli_setatr(cli1, fname, 0, 0);
4894 status = cli_open(cli1, fname, O_RDONLY, DENY_WRITE, &fnum1);
4895 if (!NT_STATUS_IS_OK(status)) {
4896 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
4900 /* This will fail - but the error should be ERRshare. */
4901 status = cli_open(cli1, fname, O_RDWR, DENY_ALL, &fnum2);
4903 if (check_error(__LINE__, status, ERRDOS, ERRbadshare,
4904 NT_STATUS_SHARING_VIOLATION)) {
4905 printf("correct error code ERRDOS/ERRbadshare returned\n");
4908 status = cli_close(cli1, fnum1);
4909 if (!NT_STATUS_IS_OK(status)) {
4910 printf("close2 failed (%s)\n", nt_errstr(status));
4914 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4916 printf("finished open test 2\n");
4918 /* Test truncate open disposition on file opened for read. */
4919 status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
4920 if (!NT_STATUS_IS_OK(status)) {
4921 printf("(3) open (1) of %s failed (%s)\n", fname, nt_errstr(status));
4925 /* write 20 bytes. */
4927 memset(buf, '\0', 20);
4929 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 0, 20, NULL);
4930 if (!NT_STATUS_IS_OK(status)) {
4931 printf("write failed (%s)\n", nt_errstr(status));
4935 status = cli_close(cli1, fnum1);
4936 if (!NT_STATUS_IS_OK(status)) {
4937 printf("(3) close1 failed (%s)\n", nt_errstr(status));
4941 /* Ensure size == 20. */
4942 status = cli_getatr(cli1, fname, NULL, &fsize, NULL);
4943 if (!NT_STATUS_IS_OK(status)) {
4944 printf("(3) getatr failed (%s)\n", nt_errstr(status));
4949 printf("(3) file size != 20\n");
4953 /* Now test if we can truncate a file opened for readonly. */
4954 status = cli_open(cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE, &fnum1);
4955 if (!NT_STATUS_IS_OK(status)) {
4956 printf("(3) open (2) of %s failed (%s)\n", fname, nt_errstr(status));
4960 status = cli_close(cli1, fnum1);
4961 if (!NT_STATUS_IS_OK(status)) {
4962 printf("close2 failed (%s)\n", nt_errstr(status));
4966 /* Ensure size == 0. */
4967 status = cli_getatr(cli1, fname, NULL, &fsize, NULL);
4968 if (!NT_STATUS_IS_OK(status)) {
4969 printf("(3) getatr failed (%s)\n", nt_errstr(status));
4974 printf("(3) file size != 0\n");
4977 printf("finished open test 3\n");
4979 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4981 printf("Do ctemp tests\n");
4982 status = cli_ctemp(cli1, talloc_tos(), "\\", &fnum1, &tmp_path);
4983 if (!NT_STATUS_IS_OK(status)) {
4984 printf("ctemp failed (%s)\n", nt_errstr(status));
4988 printf("ctemp gave path %s\n", tmp_path);
4989 status = cli_close(cli1, fnum1);
4990 if (!NT_STATUS_IS_OK(status)) {
4991 printf("close of temp failed (%s)\n", nt_errstr(status));
4994 status = cli_unlink(cli1, tmp_path, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4995 if (!NT_STATUS_IS_OK(status)) {
4996 printf("unlink of temp failed (%s)\n", nt_errstr(status));
4999 /* Test the non-io opens... */
5001 if (!torture_open_connection(&cli2, 1)) {
5005 cli_setatr(cli2, fname, 0, 0);
5006 cli_unlink(cli2, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5008 cli_sockopt(cli2, sockops);
5010 printf("TEST #1 testing 2 non-io opens (no delete)\n");
5011 status = cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES,
5012 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5013 FILE_OVERWRITE_IF, 0, 0, &fnum1);
5014 if (!NT_STATUS_IS_OK(status)) {
5015 printf("TEST #1 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
5019 status = cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES,
5020 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5021 FILE_OPEN_IF, 0, 0, &fnum2);
5022 if (!NT_STATUS_IS_OK(status)) {
5023 printf("TEST #1 open 2 of %s failed (%s)\n", fname, nt_errstr(status));
5027 status = cli_close(cli1, fnum1);
5028 if (!NT_STATUS_IS_OK(status)) {
5029 printf("TEST #1 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
5033 status = cli_close(cli2, fnum2);
5034 if (!NT_STATUS_IS_OK(status)) {
5035 printf("TEST #1 close 2 of %s failed (%s)\n", fname, nt_errstr(status));
5039 printf("non-io open test #1 passed.\n");
5041 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5043 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
5045 status = cli_ntcreate(cli1, fname, 0,
5046 DELETE_ACCESS|FILE_READ_ATTRIBUTES,
5047 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5048 FILE_OVERWRITE_IF, 0, 0, &fnum1);
5049 if (!NT_STATUS_IS_OK(status)) {
5050 printf("TEST #2 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
5054 status = cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES,
5055 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5056 FILE_OPEN_IF, 0, 0, &fnum2);
5057 if (!NT_STATUS_IS_OK(status)) {
5058 printf("TEST #2 open 2 of %s failed (%s)\n", fname, nt_errstr(status));
5062 status = cli_close(cli1, fnum1);
5063 if (!NT_STATUS_IS_OK(status)) {
5064 printf("TEST #2 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
5068 status = cli_close(cli2, fnum2);
5069 if (!NT_STATUS_IS_OK(status)) {
5070 printf("TEST #2 close 2 of %s failed (%s)\n", fname, nt_errstr(status));
5074 printf("non-io open test #2 passed.\n");
5076 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5078 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
5080 status = cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES,
5081 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5082 FILE_OVERWRITE_IF, 0, 0, &fnum1);
5083 if (!NT_STATUS_IS_OK(status)) {
5084 printf("TEST #3 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
5088 status = cli_ntcreate(cli2, fname, 0,
5089 DELETE_ACCESS|FILE_READ_ATTRIBUTES,
5090 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5091 FILE_OPEN_IF, 0, 0, &fnum2);
5092 if (!NT_STATUS_IS_OK(status)) {
5093 printf("TEST #3 open 2 of %s failed (%s)\n", fname, nt_errstr(status));
5097 status = cli_close(cli1, fnum1);
5098 if (!NT_STATUS_IS_OK(status)) {
5099 printf("TEST #3 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
5103 status = cli_close(cli2, fnum2);
5104 if (!NT_STATUS_IS_OK(status)) {
5105 printf("TEST #3 close 2 of %s failed (%s)\n", fname, nt_errstr(status));
5109 printf("non-io open test #3 passed.\n");
5111 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5113 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
5115 status = cli_ntcreate(cli1, fname, 0,
5116 DELETE_ACCESS|FILE_READ_ATTRIBUTES,
5117 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5118 FILE_OVERWRITE_IF, 0, 0, &fnum1);
5119 if (!NT_STATUS_IS_OK(status)) {
5120 printf("TEST #4 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
5124 status = cli_ntcreate(cli2, fname, 0,
5125 DELETE_ACCESS|FILE_READ_ATTRIBUTES,
5126 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5127 FILE_OPEN_IF, 0, 0, &fnum2);
5128 if (NT_STATUS_IS_OK(status)) {
5129 printf("TEST #4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, nt_errstr(status));
5133 printf("TEST #4 open 2 of %s gave %s (correct error should be %s)\n", fname, nt_errstr(status), "sharing violation");
5135 status = cli_close(cli1, fnum1);
5136 if (!NT_STATUS_IS_OK(status)) {
5137 printf("TEST #4 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
5141 printf("non-io open test #4 passed.\n");
5143 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5145 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
5147 status = cli_ntcreate(cli1, fname, 0,
5148 DELETE_ACCESS|FILE_READ_ATTRIBUTES,
5149 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_DELETE,
5150 FILE_OVERWRITE_IF, 0, 0, &fnum1);
5151 if (!NT_STATUS_IS_OK(status)) {
5152 printf("TEST #5 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
5156 status = cli_ntcreate(cli2, fname, 0,
5157 DELETE_ACCESS|FILE_READ_ATTRIBUTES,
5158 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_DELETE,
5159 FILE_OPEN_IF, 0, 0, &fnum2);
5160 if (!NT_STATUS_IS_OK(status)) {
5161 printf("TEST #5 open 2 of %s failed (%s)\n", fname, nt_errstr(status));
5165 status = cli_close(cli1, fnum1);
5166 if (!NT_STATUS_IS_OK(status)) {
5167 printf("TEST #5 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
5171 status = cli_close(cli2, fnum2);
5172 if (!NT_STATUS_IS_OK(status)) {
5173 printf("TEST #5 close 2 of %s failed (%s)\n", fname, nt_errstr(status));
5177 printf("non-io open test #5 passed.\n");
5179 printf("TEST #6 testing 1 non-io open, one io open\n");
5181 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5183 status = cli_ntcreate(cli1, fname, 0, FILE_READ_DATA,
5184 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5185 FILE_OVERWRITE_IF, 0, 0, &fnum1);
5186 if (!NT_STATUS_IS_OK(status)) {
5187 printf("TEST #6 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
5191 status = cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES,
5192 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ,
5193 FILE_OPEN_IF, 0, 0, &fnum2);
5194 if (!NT_STATUS_IS_OK(status)) {
5195 printf("TEST #6 open 2 of %s failed (%s)\n", fname, nt_errstr(status));
5199 status = cli_close(cli1, fnum1);
5200 if (!NT_STATUS_IS_OK(status)) {
5201 printf("TEST #6 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
5205 status = cli_close(cli2, fnum2);
5206 if (!NT_STATUS_IS_OK(status)) {
5207 printf("TEST #6 close 2 of %s failed (%s)\n", fname, nt_errstr(status));
5211 printf("non-io open test #6 passed.\n");
5213 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
5215 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5217 status = cli_ntcreate(cli1, fname, 0, FILE_READ_DATA,
5218 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5219 FILE_OVERWRITE_IF, 0, 0, &fnum1);
5220 if (!NT_STATUS_IS_OK(status)) {
5221 printf("TEST #7 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
5225 status = cli_ntcreate(cli2, fname, 0,
5226 DELETE_ACCESS|FILE_READ_ATTRIBUTES,
5227 FILE_ATTRIBUTE_NORMAL,
5228 FILE_SHARE_READ|FILE_SHARE_DELETE,
5229 FILE_OPEN_IF, 0, 0, &fnum2);
5230 if (NT_STATUS_IS_OK(status)) {
5231 printf("TEST #7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, nt_errstr(status));
5235 printf("TEST #7 open 2 of %s gave %s (correct error should be %s)\n", fname, nt_errstr(status), "sharing violation");
5237 status = cli_close(cli1, fnum1);
5238 if (!NT_STATUS_IS_OK(status)) {
5239 printf("TEST #7 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
5243 printf("non-io open test #7 passed.\n");
5245 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5247 printf("TEST #8 testing open without WRITE_ATTRIBUTES, updating close write time.\n");
5248 status = cli_ntcreate(cli1, fname, 0, FILE_WRITE_DATA, FILE_ATTRIBUTE_NORMAL,
5249 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
5250 FILE_OVERWRITE_IF, 0, 0, &fnum1);
5251 if (!NT_STATUS_IS_OK(status)) {
5252 printf("TEST #8 open of %s failed (%s)\n", fname, nt_errstr(status));
5257 /* Write to ensure we have to update the file time. */
5258 status = cli_writeall(cli1, fnum1, 0, (const uint8_t *)"TEST DATA\n", 0, 10,
5260 if (!NT_STATUS_IS_OK(status)) {
5261 printf("TEST #8 cli_write failed: %s\n", nt_errstr(status));
5266 status = cli_close(cli1, fnum1);
5267 if (!NT_STATUS_IS_OK(status)) {
5268 printf("TEST #8 close of %s failed (%s)\n", fname, nt_errstr(status));
5274 if (!torture_close_connection(cli1)) {
5277 if (!torture_close_connection(cli2)) {
5284 NTSTATUS torture_setup_unix_extensions(struct cli_state *cli)
5286 uint16 major, minor;
5287 uint32 caplow, caphigh;
5290 if (!SERVER_HAS_UNIX_CIFS(cli)) {
5291 printf("Server doesn't support UNIX CIFS extensions.\n");
5292 return NT_STATUS_NOT_SUPPORTED;
5295 status = cli_unix_extensions_version(cli, &major, &minor, &caplow,
5297 if (!NT_STATUS_IS_OK(status)) {
5298 printf("Server didn't return UNIX CIFS extensions: %s\n",
5303 status = cli_set_unix_extensions_capabilities(cli, major, minor,
5305 if (!NT_STATUS_IS_OK(status)) {
5306 printf("Server doesn't support setting UNIX CIFS extensions: "
5307 "%s.\n", nt_errstr(status));
5311 return NT_STATUS_OK;
5315 Test POSIX open /mkdir calls.
5317 static bool run_simple_posix_open_test(int dummy)
5319 static struct cli_state *cli1;
5320 const char *fname = "posix:file";
5321 const char *hname = "posix:hlink";
5322 const char *sname = "posix:symlink";
5323 const char *dname = "posix:dir";
5326 uint16_t fnum1 = (uint16_t)-1;
5327 SMB_STRUCT_STAT sbuf;
5328 bool correct = false;
5332 printf("Starting simple POSIX open test\n");
5334 if (!torture_open_connection(&cli1, 0)) {
5338 cli_sockopt(cli1, sockops);
5340 status = torture_setup_unix_extensions(cli1);
5341 if (!NT_STATUS_IS_OK(status)) {
5345 cli_setatr(cli1, fname, 0, 0);
5346 cli_posix_unlink(cli1, fname);
5347 cli_setatr(cli1, dname, 0, 0);
5348 cli_posix_rmdir(cli1, dname);
5349 cli_setatr(cli1, hname, 0, 0);
5350 cli_posix_unlink(cli1, hname);
5351 cli_setatr(cli1, sname, 0, 0);
5352 cli_posix_unlink(cli1, sname);
5354 /* Create a directory. */
5355 status = cli_posix_mkdir(cli1, dname, 0777);
5356 if (!NT_STATUS_IS_OK(status)) {
5357 printf("POSIX mkdir of %s failed (%s)\n", dname, nt_errstr(status));
5361 status = cli_posix_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL,
5363 if (!NT_STATUS_IS_OK(status)) {
5364 printf("POSIX create of %s failed (%s)\n", fname, nt_errstr(status));
5368 /* Test ftruncate - set file size. */
5369 status = cli_ftruncate(cli1, fnum1, 1000);
5370 if (!NT_STATUS_IS_OK(status)) {
5371 printf("ftruncate failed (%s)\n", nt_errstr(status));
5375 /* Ensure st_size == 1000 */
5376 status = cli_posix_stat(cli1, fname, &sbuf);
5377 if (!NT_STATUS_IS_OK(status)) {
5378 printf("stat failed (%s)\n", nt_errstr(status));
5382 if (sbuf.st_ex_size != 1000) {
5383 printf("ftruncate - stat size (%u) != 1000\n", (unsigned int)sbuf.st_ex_size);
5387 /* Test ftruncate - set file size back to zero. */
5388 status = cli_ftruncate(cli1, fnum1, 0);
5389 if (!NT_STATUS_IS_OK(status)) {
5390 printf("ftruncate failed (%s)\n", nt_errstr(status));
5394 status = cli_close(cli1, fnum1);
5395 if (!NT_STATUS_IS_OK(status)) {
5396 printf("close failed (%s)\n", nt_errstr(status));
5400 /* Now open the file again for read only. */
5401 status = cli_posix_open(cli1, fname, O_RDONLY, 0, &fnum1);
5402 if (!NT_STATUS_IS_OK(status)) {
5403 printf("POSIX open of %s failed (%s)\n", fname, nt_errstr(status));
5407 /* Now unlink while open. */
5408 status = cli_posix_unlink(cli1, fname);
5409 if (!NT_STATUS_IS_OK(status)) {
5410 printf("POSIX unlink of %s failed (%s)\n", fname, nt_errstr(status));
5414 status = cli_close(cli1, fnum1);
5415 if (!NT_STATUS_IS_OK(status)) {
5416 printf("close(2) failed (%s)\n", nt_errstr(status));
5420 /* Ensure the file has gone. */
5421 status = cli_posix_open(cli1, fname, O_RDONLY, 0, &fnum1);
5422 if (NT_STATUS_IS_OK(status)) {
5423 printf("POSIX open of %s succeeded, should have been deleted.\n", fname);
5427 /* Create again to test open with O_TRUNC. */
5428 status = cli_posix_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, 0600, &fnum1);
5429 if (!NT_STATUS_IS_OK(status)) {
5430 printf("POSIX create of %s failed (%s)\n", fname, nt_errstr(status));
5434 /* Test ftruncate - set file size. */
5435 status = cli_ftruncate(cli1, fnum1, 1000);
5436 if (!NT_STATUS_IS_OK(status)) {
5437 printf("ftruncate failed (%s)\n", nt_errstr(status));
5441 /* Ensure st_size == 1000 */
5442 status = cli_posix_stat(cli1, fname, &sbuf);
5443 if (!NT_STATUS_IS_OK(status)) {
5444 printf("stat failed (%s)\n", nt_errstr(status));
5448 if (sbuf.st_ex_size != 1000) {
5449 printf("ftruncate - stat size (%u) != 1000\n", (unsigned int)sbuf.st_ex_size);
5453 status = cli_close(cli1, fnum1);
5454 if (!NT_STATUS_IS_OK(status)) {
5455 printf("close(2) failed (%s)\n", nt_errstr(status));
5459 /* Re-open with O_TRUNC. */
5460 status = cli_posix_open(cli1, fname, O_WRONLY|O_TRUNC, 0600, &fnum1);
5461 if (!NT_STATUS_IS_OK(status)) {
5462 printf("POSIX create of %s failed (%s)\n", fname, nt_errstr(status));
5466 /* Ensure st_size == 0 */
5467 status = cli_posix_stat(cli1, fname, &sbuf);
5468 if (!NT_STATUS_IS_OK(status)) {
5469 printf("stat failed (%s)\n", nt_errstr(status));
5473 if (sbuf.st_ex_size != 0) {
5474 printf("O_TRUNC - stat size (%u) != 0\n", (unsigned int)sbuf.st_ex_size);
5478 status = cli_close(cli1, fnum1);
5479 if (!NT_STATUS_IS_OK(status)) {
5480 printf("close failed (%s)\n", nt_errstr(status));
5484 status = cli_posix_unlink(cli1, fname);
5485 if (!NT_STATUS_IS_OK(status)) {
5486 printf("POSIX unlink of %s failed (%s)\n", fname, nt_errstr(status));
5490 status = cli_posix_open(cli1, dname, O_RDONLY, 0, &fnum1);
5491 if (!NT_STATUS_IS_OK(status)) {
5492 printf("POSIX open directory O_RDONLY of %s failed (%s)\n",
5493 dname, nt_errstr(status));
5497 cli_close(cli1, fnum1);
5499 /* What happens when we try and POSIX open a directory for write ? */
5500 status = cli_posix_open(cli1, dname, O_RDWR, 0, &fnum1);
5501 if (NT_STATUS_IS_OK(status)) {
5502 printf("POSIX open of directory %s succeeded, should have failed.\n", fname);
5505 if (!check_both_error(__LINE__, status, ERRDOS, EISDIR,
5506 NT_STATUS_FILE_IS_A_DIRECTORY)) {
5511 /* Create the file. */
5512 status = cli_posix_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL,
5514 if (!NT_STATUS_IS_OK(status)) {
5515 printf("POSIX create of %s failed (%s)\n", fname, nt_errstr(status));
5519 /* Write some data into it. */
5520 status = cli_writeall(cli1, fnum1, 0, (const uint8_t *)"TEST DATA\n", 0, 10,
5522 if (!NT_STATUS_IS_OK(status)) {
5523 printf("cli_write failed: %s\n", nt_errstr(status));
5527 cli_close(cli1, fnum1);
5529 /* Now create a hardlink. */
5530 status = cli_posix_hardlink(cli1, fname, hname);
5531 if (!NT_STATUS_IS_OK(status)) {
5532 printf("POSIX hardlink of %s failed (%s)\n", hname, nt_errstr(status));
5536 /* Now create a symlink. */
5537 status = cli_posix_symlink(cli1, fname, sname);
5538 if (!NT_STATUS_IS_OK(status)) {
5539 printf("POSIX symlink of %s failed (%s)\n", sname, nt_errstr(status));
5543 /* Open the hardlink for read. */
5544 status = cli_posix_open(cli1, hname, O_RDONLY, 0, &fnum1);
5545 if (!NT_STATUS_IS_OK(status)) {
5546 printf("POSIX open of %s failed (%s)\n", hname, nt_errstr(status));
5550 status = cli_read(cli1, fnum1, buf, 0, 10, &nread);
5551 if (!NT_STATUS_IS_OK(status)) {
5552 printf("POSIX read of %s failed (%s)\n", hname,
5555 } else if (nread != 10) {
5556 printf("POSIX read of %s failed. Received %ld, expected %d\n",
5557 hname, (unsigned long)nread, 10);
5561 if (memcmp(buf, "TEST DATA\n", 10)) {
5562 printf("invalid data read from hardlink\n");
5566 /* Do a POSIX lock/unlock. */
5567 status = cli_posix_lock(cli1, fnum1, 0, 100, true, READ_LOCK);
5568 if (!NT_STATUS_IS_OK(status)) {
5569 printf("POSIX lock failed %s\n", nt_errstr(status));
5573 /* Punch a hole in the locked area. */
5574 status = cli_posix_unlock(cli1, fnum1, 10, 80);
5575 if (!NT_STATUS_IS_OK(status)) {
5576 printf("POSIX unlock failed %s\n", nt_errstr(status));
5580 cli_close(cli1, fnum1);
5582 /* Open the symlink for read - this should fail. A POSIX
5583 client should not be doing opens on a symlink. */
5584 status = cli_posix_open(cli1, sname, O_RDONLY, 0, &fnum1);
5585 if (NT_STATUS_IS_OK(status)) {
5586 printf("POSIX open of %s succeeded (should have failed)\n", sname);
5589 if (!check_both_error(__LINE__, status, ERRDOS, ERRbadpath,
5590 NT_STATUS_OBJECT_PATH_NOT_FOUND)) {
5591 printf("POSIX open of %s should have failed "
5592 "with NT_STATUS_OBJECT_PATH_NOT_FOUND, "
5593 "failed with %s instead.\n",
5594 sname, nt_errstr(status));
5599 status = cli_posix_readlink(cli1, sname, namebuf, sizeof(namebuf));
5600 if (!NT_STATUS_IS_OK(status)) {
5601 printf("POSIX readlink on %s failed (%s)\n", sname, nt_errstr(status));
5605 if (strcmp(namebuf, fname) != 0) {
5606 printf("POSIX readlink on %s failed to match name %s (read %s)\n",
5607 sname, fname, namebuf);
5611 status = cli_posix_rmdir(cli1, dname);
5612 if (!NT_STATUS_IS_OK(status)) {
5613 printf("POSIX rmdir failed (%s)\n", nt_errstr(status));
5617 printf("Simple POSIX open test passed\n");
5622 if (fnum1 != (uint16_t)-1) {
5623 cli_close(cli1, fnum1);
5624 fnum1 = (uint16_t)-1;
5627 cli_setatr(cli1, sname, 0, 0);
5628 cli_posix_unlink(cli1, sname);
5629 cli_setatr(cli1, hname, 0, 0);
5630 cli_posix_unlink(cli1, hname);
5631 cli_setatr(cli1, fname, 0, 0);
5632 cli_posix_unlink(cli1, fname);
5633 cli_setatr(cli1, dname, 0, 0);
5634 cli_posix_rmdir(cli1, dname);
5636 if (!torture_close_connection(cli1)) {
5644 static uint32 open_attrs_table[] = {
5645 FILE_ATTRIBUTE_NORMAL,
5646 FILE_ATTRIBUTE_ARCHIVE,
5647 FILE_ATTRIBUTE_READONLY,
5648 FILE_ATTRIBUTE_HIDDEN,
5649 FILE_ATTRIBUTE_SYSTEM,
5651 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY,
5652 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN,
5653 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM,
5654 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
5655 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
5656 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
5658 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
5659 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
5660 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
5661 FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_SYSTEM,
5664 struct trunc_open_results {
5671 static struct trunc_open_results attr_results[] = {
5672 { 0, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
5673 { 1, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
5674 { 2, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
5675 { 16, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
5676 { 17, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
5677 { 18, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
5678 { 51, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
5679 { 54, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
5680 { 56, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
5681 { 68, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
5682 { 71, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
5683 { 73, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM },
5684 { 99, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
5685 { 102, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
5686 { 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 },
5687 { 116, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
5688 { 119, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
5689 { 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 },
5690 { 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 },
5691 { 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 },
5692 { 227, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
5693 { 230, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
5694 { 232, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
5695 { 244, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
5696 { 247, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
5697 { 249, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM }
5700 static bool run_openattrtest(int dummy)
5702 static struct cli_state *cli1;
5703 const char *fname = "\\openattr.file";
5705 bool correct = True;
5707 unsigned int i, j, k, l;
5710 printf("starting open attr test\n");
5712 if (!torture_open_connection(&cli1, 0)) {
5716 cli_sockopt(cli1, sockops);
5718 for (k = 0, i = 0; i < sizeof(open_attrs_table)/sizeof(uint32); i++) {
5719 cli_setatr(cli1, fname, 0, 0);
5720 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5722 status = cli_ntcreate(cli1, fname, 0, FILE_WRITE_DATA,
5723 open_attrs_table[i], FILE_SHARE_NONE,
5724 FILE_OVERWRITE_IF, 0, 0, &fnum1);
5725 if (!NT_STATUS_IS_OK(status)) {
5726 printf("open %d (1) of %s failed (%s)\n", i, fname, nt_errstr(status));
5730 status = cli_close(cli1, fnum1);
5731 if (!NT_STATUS_IS_OK(status)) {
5732 printf("close %d (1) of %s failed (%s)\n", i, fname, nt_errstr(status));
5736 for (j = 0; j < sizeof(open_attrs_table)/sizeof(uint32); j++) {
5737 status = cli_ntcreate(cli1, fname, 0,
5738 FILE_READ_DATA|FILE_WRITE_DATA,
5739 open_attrs_table[j],
5740 FILE_SHARE_NONE, FILE_OVERWRITE,
5742 if (!NT_STATUS_IS_OK(status)) {
5743 for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
5744 if (attr_results[l].num == k) {
5745 printf("[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(0x%x:%s)\n",
5746 k, open_attrs_table[i],
5747 open_attrs_table[j],
5748 fname, NT_STATUS_V(status), nt_errstr(status));
5753 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
5754 printf("[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s\n",
5755 k, open_attrs_table[i], open_attrs_table[j],
5760 printf("[%d] trunc open 0x%x -> 0x%x failed\n", k, open_attrs_table[i], open_attrs_table[j]);
5766 status = cli_close(cli1, fnum1);
5767 if (!NT_STATUS_IS_OK(status)) {
5768 printf("close %d (2) of %s failed (%s)\n", j, fname, nt_errstr(status));
5772 status = cli_getatr(cli1, fname, &attr, NULL, NULL);
5773 if (!NT_STATUS_IS_OK(status)) {
5774 printf("getatr(2) failed (%s)\n", nt_errstr(status));
5779 printf("[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n",
5780 k, open_attrs_table[i], open_attrs_table[j], attr );
5783 for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
5784 if (attr_results[l].num == k) {
5785 if (attr != attr_results[l].result_attr ||
5786 open_attrs_table[i] != attr_results[l].init_attr ||
5787 open_attrs_table[j] != attr_results[l].trunc_attr) {
5788 printf("getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x\n",
5789 open_attrs_table[i],
5790 open_attrs_table[j],
5792 attr_results[l].result_attr);
5802 cli_setatr(cli1, fname, 0, 0);
5803 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5805 printf("open attr test %s.\n", correct ? "passed" : "failed");
5807 if (!torture_close_connection(cli1)) {
5813 static NTSTATUS list_fn(const char *mnt, struct file_info *finfo,
5814 const char *name, void *state)
5816 int *matched = (int *)state;
5817 if (matched != NULL) {
5820 return NT_STATUS_OK;
5824 test directory listing speed
5826 static bool run_dirtest(int dummy)
5829 static struct cli_state *cli;
5831 struct timeval core_start;
5832 bool correct = True;
5835 printf("starting directory test\n");
5837 if (!torture_open_connection(&cli, 0)) {
5841 cli_sockopt(cli, sockops);
5844 for (i=0;i<torture_numops;i++) {
5846 slprintf(fname, sizeof(fname), "\\%x", (int)random());
5847 if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum))) {
5848 fprintf(stderr,"Failed to open %s\n", fname);
5851 cli_close(cli, fnum);
5854 core_start = timeval_current();
5857 cli_list(cli, "a*.*", 0, list_fn, &matched);
5858 printf("Matched %d\n", matched);
5861 cli_list(cli, "b*.*", 0, list_fn, &matched);
5862 printf("Matched %d\n", matched);
5865 cli_list(cli, "xyzabc", 0, list_fn, &matched);
5866 printf("Matched %d\n", matched);
5868 printf("dirtest core %g seconds\n", timeval_elapsed(&core_start));
5871 for (i=0;i<torture_numops;i++) {
5873 slprintf(fname, sizeof(fname), "\\%x", (int)random());
5874 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5877 if (!torture_close_connection(cli)) {
5881 printf("finished dirtest\n");
5886 static NTSTATUS del_fn(const char *mnt, struct file_info *finfo, const char *mask,
5889 struct cli_state *pcli = (struct cli_state *)state;
5891 slprintf(fname, sizeof(fname), "\\LISTDIR\\%s", finfo->name);
5893 if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
5894 return NT_STATUS_OK;
5896 if (finfo->mode & FILE_ATTRIBUTE_DIRECTORY) {
5897 if (!NT_STATUS_IS_OK(cli_rmdir(pcli, fname)))
5898 printf("del_fn: failed to rmdir %s\n,", fname );
5900 if (!NT_STATUS_IS_OK(cli_unlink(pcli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN)))
5901 printf("del_fn: failed to unlink %s\n,", fname );
5903 return NT_STATUS_OK;
5908 sees what IOCTLs are supported
5910 bool torture_ioctl_test(int dummy)
5912 static struct cli_state *cli;
5913 uint16_t device, function;
5915 const char *fname = "\\ioctl.dat";
5919 if (!torture_open_connection(&cli, 0)) {
5923 printf("starting ioctl test\n");
5925 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5927 status = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
5928 if (!NT_STATUS_IS_OK(status)) {
5929 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
5933 status = cli_raw_ioctl(cli, fnum, 0x2d0000 | (0x0420<<2), &blob);
5934 printf("ioctl device info: %s\n", nt_errstr(status));
5936 status = cli_raw_ioctl(cli, fnum, IOCTL_QUERY_JOB_INFO, &blob);
5937 printf("ioctl job info: %s\n", nt_errstr(status));
5939 for (device=0;device<0x100;device++) {
5940 printf("ioctl test with device = 0x%x\n", device);
5941 for (function=0;function<0x100;function++) {
5942 uint32 code = (device<<16) | function;
5944 status = cli_raw_ioctl(cli, fnum, code, &blob);
5946 if (NT_STATUS_IS_OK(status)) {
5947 printf("ioctl 0x%x OK : %d bytes\n", (int)code,
5949 data_blob_free(&blob);
5954 if (!torture_close_connection(cli)) {
5963 tries varients of chkpath
5965 bool torture_chkpath_test(int dummy)
5967 static struct cli_state *cli;
5972 if (!torture_open_connection(&cli, 0)) {
5976 printf("starting chkpath test\n");
5978 /* cleanup from an old run */
5979 cli_rmdir(cli, "\\chkpath.dir\\dir2");
5980 cli_unlink(cli, "\\chkpath.dir\\*", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5981 cli_rmdir(cli, "\\chkpath.dir");
5983 status = cli_mkdir(cli, "\\chkpath.dir");
5984 if (!NT_STATUS_IS_OK(status)) {
5985 printf("mkdir1 failed : %s\n", nt_errstr(status));
5989 status = cli_mkdir(cli, "\\chkpath.dir\\dir2");
5990 if (!NT_STATUS_IS_OK(status)) {
5991 printf("mkdir2 failed : %s\n", nt_errstr(status));
5995 status = cli_open(cli, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL,
5997 if (!NT_STATUS_IS_OK(status)) {
5998 printf("open1 failed (%s)\n", nt_errstr(status));
6001 cli_close(cli, fnum);
6003 status = cli_chkpath(cli, "\\chkpath.dir");
6004 if (!NT_STATUS_IS_OK(status)) {
6005 printf("chkpath1 failed: %s\n", nt_errstr(status));
6009 status = cli_chkpath(cli, "\\chkpath.dir\\dir2");
6010 if (!NT_STATUS_IS_OK(status)) {
6011 printf("chkpath2 failed: %s\n", nt_errstr(status));
6015 status = cli_chkpath(cli, "\\chkpath.dir\\foo.txt");
6016 if (!NT_STATUS_IS_OK(status)) {
6017 ret = check_error(__LINE__, status, ERRDOS, ERRbadpath,
6018 NT_STATUS_NOT_A_DIRECTORY);
6020 printf("* chkpath on a file should fail\n");
6024 status = cli_chkpath(cli, "\\chkpath.dir\\bar.txt");
6025 if (!NT_STATUS_IS_OK(status)) {
6026 ret = check_error(__LINE__, status, ERRDOS, ERRbadfile,
6027 NT_STATUS_OBJECT_NAME_NOT_FOUND);
6029 printf("* chkpath on a non existant file should fail\n");
6033 status = cli_chkpath(cli, "\\chkpath.dir\\dirxx\\bar.txt");
6034 if (!NT_STATUS_IS_OK(status)) {
6035 ret = check_error(__LINE__, status, ERRDOS, ERRbadpath,
6036 NT_STATUS_OBJECT_PATH_NOT_FOUND);
6038 printf("* chkpath on a non existent component should fail\n");
6042 cli_rmdir(cli, "\\chkpath.dir\\dir2");
6043 cli_unlink(cli, "\\chkpath.dir\\*", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
6044 cli_rmdir(cli, "\\chkpath.dir");
6046 if (!torture_close_connection(cli)) {
6053 static bool run_eatest(int dummy)
6055 static struct cli_state *cli;
6056 const char *fname = "\\eatest.txt";
6057 bool correct = True;
6061 struct ea_struct *ea_list = NULL;
6062 TALLOC_CTX *mem_ctx = talloc_init("eatest");
6065 printf("starting eatest\n");
6067 if (!torture_open_connection(&cli, 0)) {
6068 talloc_destroy(mem_ctx);
6072 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
6074 status = cli_ntcreate(cli, fname, 0,
6075 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
6076 FILE_SHARE_NONE, FILE_OVERWRITE_IF,
6078 if (!NT_STATUS_IS_OK(status)) {
6079 printf("open failed - %s\n", nt_errstr(status));
6080 talloc_destroy(mem_ctx);
6084 for (i = 0; i < 10; i++) {
6085 fstring ea_name, ea_val;
6087 slprintf(ea_name, sizeof(ea_name), "EA_%d", i);
6088 memset(ea_val, (char)i+1, i+1);
6089 status = cli_set_ea_fnum(cli, fnum, ea_name, ea_val, i+1);
6090 if (!NT_STATUS_IS_OK(status)) {
6091 printf("ea_set of name %s failed - %s\n", ea_name,
6093 talloc_destroy(mem_ctx);
6098 cli_close(cli, fnum);
6099 for (i = 0; i < 10; i++) {
6100 fstring ea_name, ea_val;
6102 slprintf(ea_name, sizeof(ea_name), "EA_%d", i+10);
6103 memset(ea_val, (char)i+1, i+1);
6104 status = cli_set_ea_path(cli, fname, ea_name, ea_val, i+1);
6105 if (!NT_STATUS_IS_OK(status)) {
6106 printf("ea_set of name %s failed - %s\n", ea_name,
6108 talloc_destroy(mem_ctx);
6113 status = cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list);
6114 if (!NT_STATUS_IS_OK(status)) {
6115 printf("ea_get list failed - %s\n", nt_errstr(status));
6119 printf("num_eas = %d\n", (int)num_eas);
6121 if (num_eas != 20) {
6122 printf("Should be 20 EA's stored... failing.\n");
6126 for (i = 0; i < num_eas; i++) {
6127 printf("%d: ea_name = %s. Val = ", i, ea_list[i].name);
6128 dump_data(0, ea_list[i].value.data,
6129 ea_list[i].value.length);
6132 /* Setting EA's to zero length deletes them. Test this */
6133 printf("Now deleting all EA's - case indepenent....\n");
6136 cli_set_ea_path(cli, fname, "", "", 0);
6138 for (i = 0; i < 20; i++) {
6140 slprintf(ea_name, sizeof(ea_name), "ea_%d", i);
6141 status = cli_set_ea_path(cli, fname, ea_name, "", 0);
6142 if (!NT_STATUS_IS_OK(status)) {
6143 printf("ea_set of name %s failed - %s\n", ea_name,
6145 talloc_destroy(mem_ctx);
6151 status = cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list);
6152 if (!NT_STATUS_IS_OK(status)) {
6153 printf("ea_get list failed - %s\n", nt_errstr(status));
6157 printf("num_eas = %d\n", (int)num_eas);
6158 for (i = 0; i < num_eas; i++) {
6159 printf("%d: ea_name = %s. Val = ", i, ea_list[i].name);
6160 dump_data(0, ea_list[i].value.data,
6161 ea_list[i].value.length);
6165 printf("deleting EA's failed.\n");
6169 /* Try and delete a non existant EA. */
6170 status = cli_set_ea_path(cli, fname, "foo", "", 0);
6171 if (!NT_STATUS_IS_OK(status)) {
6172 printf("deleting non-existant EA 'foo' should succeed. %s\n",
6177 talloc_destroy(mem_ctx);
6178 if (!torture_close_connection(cli)) {
6185 static bool run_dirtest1(int dummy)
6188 static struct cli_state *cli;
6191 bool correct = True;
6193 printf("starting directory test\n");
6195 if (!torture_open_connection(&cli, 0)) {
6199 cli_sockopt(cli, sockops);
6201 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
6202 cli_list(cli, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, del_fn, cli);
6203 cli_rmdir(cli, "\\LISTDIR");
6204 cli_mkdir(cli, "\\LISTDIR");
6206 /* Create 1000 files and 1000 directories. */
6207 for (i=0;i<1000;i++) {
6209 slprintf(fname, sizeof(fname), "\\LISTDIR\\f%d", i);
6210 if (!NT_STATUS_IS_OK(cli_ntcreate(cli, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
6211 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum))) {
6212 fprintf(stderr,"Failed to open %s\n", fname);
6215 cli_close(cli, fnum);
6217 for (i=0;i<1000;i++) {
6219 slprintf(fname, sizeof(fname), "\\LISTDIR\\d%d", i);
6220 if (!NT_STATUS_IS_OK(cli_mkdir(cli, fname))) {
6221 fprintf(stderr,"Failed to open %s\n", fname);
6226 /* Now ensure that doing an old list sees both files and directories. */
6228 cli_list_old(cli, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, list_fn, &num_seen);
6229 printf("num_seen = %d\n", num_seen );
6230 /* We should see 100 files + 1000 directories + . and .. */
6231 if (num_seen != 2002)
6234 /* Ensure if we have the "must have" bits we only see the
6238 cli_list_old(cli, "\\LISTDIR\\*", (FILE_ATTRIBUTE_DIRECTORY<<8)|FILE_ATTRIBUTE_DIRECTORY, list_fn, &num_seen);
6239 printf("num_seen = %d\n", num_seen );
6240 if (num_seen != 1002)
6244 cli_list_old(cli, "\\LISTDIR\\*", (FILE_ATTRIBUTE_ARCHIVE<<8)|FILE_ATTRIBUTE_DIRECTORY, list_fn, &num_seen);
6245 printf("num_seen = %d\n", num_seen );
6246 if (num_seen != 1000)
6249 /* Delete everything. */
6250 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
6251 cli_list(cli, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, del_fn, cli);
6252 cli_rmdir(cli, "\\LISTDIR");
6255 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
6256 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
6257 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
6260 if (!torture_close_connection(cli)) {
6264 printf("finished dirtest1\n");
6269 static bool run_error_map_extract(int dummy) {
6271 static struct cli_state *c_dos;
6272 static struct cli_state *c_nt;
6284 /* NT-Error connection */
6286 disable_spnego = true;
6287 if (!(c_nt = open_nbt_connection())) {
6288 disable_spnego = false;
6291 disable_spnego = false;
6293 status = cli_negprot(c_nt, PROTOCOL_NT1);
6295 if (!NT_STATUS_IS_OK(status)) {
6296 printf("%s rejected the NT-error negprot (%s)\n", host,
6302 status = cli_session_setup(c_nt, "", "", 0, "", 0, workgroup);
6303 if (!NT_STATUS_IS_OK(status)) {
6304 printf("%s rejected the NT-error initial session setup (%s)\n",host, nt_errstr(status));
6308 /* DOS-Error connection */
6310 disable_spnego = true;
6311 force_dos_errors = true;
6312 if (!(c_dos = open_nbt_connection())) {
6313 disable_spnego = false;
6314 force_dos_errors = false;
6317 disable_spnego = false;
6318 force_dos_errors = false;
6320 status = cli_negprot(c_dos, PROTOCOL_NT1);
6321 if (!NT_STATUS_IS_OK(status)) {
6322 printf("%s rejected the DOS-error negprot (%s)\n", host,
6324 cli_shutdown(c_dos);
6328 status = cli_session_setup(c_dos, "", "", 0, "", 0, workgroup);
6329 if (!NT_STATUS_IS_OK(status)) {
6330 printf("%s rejected the DOS-error initial session setup (%s)\n",
6331 host, nt_errstr(status));
6335 for (error=(0xc0000000 | 0x1); error < (0xc0000000| 0xFFF); error++) {
6336 fstr_sprintf(user, "%X", error);
6338 status = cli_session_setup(c_nt, user,
6339 password, strlen(password),
6340 password, strlen(password),
6342 if (NT_STATUS_IS_OK(status)) {
6343 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
6346 /* Case #1: 32-bit NT errors */
6347 if (cli_is_nt_error(c_nt)) {
6348 nt_status = cli_nt_error(c_nt);
6350 printf("/** Dos error on NT connection! (%s) */\n",
6352 nt_status = NT_STATUS(0xc0000000);
6355 status = cli_session_setup(c_dos, user,
6356 password, strlen(password),
6357 password, strlen(password),
6359 if (NT_STATUS_IS_OK(status)) {
6360 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
6363 /* Case #1: 32-bit NT errors */
6364 if (!cli_is_dos_error(c_dos)) {
6365 printf("/** NT error on DOS connection! (%s) */\n",
6367 errnum = errclass = 0;
6369 cli_dos_error(c_dos, &errclass, &errnum);
6372 if (NT_STATUS_V(nt_status) != error) {
6373 printf("/*\t{ This NT error code was 'sqashed'\n\t from %s to %s \n\t during the session setup }\n*/\n",
6374 get_nt_error_c_code(talloc_tos(), NT_STATUS(error)),
6375 get_nt_error_c_code(talloc_tos(), nt_status));
6378 printf("\t{%s,\t%s,\t%s},\n",
6379 smb_dos_err_class(errclass),
6380 smb_dos_err_name(errclass, errnum),
6381 get_nt_error_c_code(talloc_tos(), NT_STATUS(error)));
6386 static bool run_sesssetup_bench(int dummy)
6388 static struct cli_state *c;
6389 const char *fname = "\\file.dat";
6394 if (!torture_open_connection(&c, 0)) {
6398 status = cli_ntcreate(c, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
6399 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
6400 FILE_DELETE_ON_CLOSE, 0, &fnum);
6401 if (!NT_STATUS_IS_OK(status)) {
6402 d_printf("open %s failed: %s\n", fname, nt_errstr(status));
6406 for (i=0; i<torture_numops; i++) {
6407 status = cli_session_setup(
6409 password, strlen(password),
6410 password, strlen(password),
6412 if (!NT_STATUS_IS_OK(status)) {
6413 d_printf("(%s) cli_session_setup failed: %s\n",
6414 __location__, nt_errstr(status));
6418 d_printf("\r%d ", (int)cli_state_get_uid(c));
6420 status = cli_ulogoff(c);
6421 if (!NT_STATUS_IS_OK(status)) {
6422 d_printf("(%s) cli_ulogoff failed: %s\n",
6423 __location__, nt_errstr(status));
6431 static bool subst_test(const char *str, const char *user, const char *domain,
6432 uid_t uid, gid_t gid, const char *expected)
6437 subst = talloc_sub_specified(talloc_tos(), str, user, domain, uid, gid);
6439 if (strcmp(subst, expected) != 0) {
6440 printf("sub_specified(%s, %s, %s, %d, %d) returned [%s], expected "
6441 "[%s]\n", str, user, domain, (int)uid, (int)gid, subst,
6450 static void chain1_open_completion(struct tevent_req *req)
6454 status = cli_open_recv(req, &fnum);
6457 d_printf("cli_open_recv returned %s: %d\n",
6459 NT_STATUS_IS_OK(status) ? fnum : -1);
6462 static void chain1_write_completion(struct tevent_req *req)
6466 status = cli_write_andx_recv(req, &written);
6469 d_printf("cli_write_andx_recv returned %s: %d\n",
6471 NT_STATUS_IS_OK(status) ? (int)written : -1);
6474 static void chain1_close_completion(struct tevent_req *req)
6477 bool *done = (bool *)tevent_req_callback_data_void(req);
6479 status = cli_close_recv(req);
6484 d_printf("cli_close returned %s\n", nt_errstr(status));
6487 static bool run_chain1(int dummy)
6489 struct cli_state *cli1;
6490 struct event_context *evt = event_context_init(NULL);
6491 struct tevent_req *reqs[3], *smbreqs[3];
6493 const char *str = "foobar";
6496 printf("starting chain1 test\n");
6497 if (!torture_open_connection(&cli1, 0)) {
6501 cli_sockopt(cli1, sockops);
6503 reqs[0] = cli_open_create(talloc_tos(), evt, cli1, "\\test",
6504 O_CREAT|O_RDWR, 0, &smbreqs[0]);
6505 if (reqs[0] == NULL) return false;
6506 tevent_req_set_callback(reqs[0], chain1_open_completion, NULL);
6509 reqs[1] = cli_write_andx_create(talloc_tos(), evt, cli1, 0, 0,
6510 (const uint8_t *)str, 0, strlen(str)+1,
6511 smbreqs, 1, &smbreqs[1]);
6512 if (reqs[1] == NULL) return false;
6513 tevent_req_set_callback(reqs[1], chain1_write_completion, NULL);
6515 reqs[2] = cli_close_create(talloc_tos(), evt, cli1, 0, &smbreqs[2]);
6516 if (reqs[2] == NULL) return false;
6517 tevent_req_set_callback(reqs[2], chain1_close_completion, &done);
6519 status = cli_smb_chain_send(smbreqs, ARRAY_SIZE(smbreqs));
6520 if (!NT_STATUS_IS_OK(status)) {
6525 tevent_loop_once(evt);
6528 torture_close_connection(cli1);
6532 static void chain2_sesssetup_completion(struct tevent_req *req)
6535 status = cli_session_setup_guest_recv(req);
6536 d_printf("sesssetup returned %s\n", nt_errstr(status));
6539 static void chain2_tcon_completion(struct tevent_req *req)
6541 bool *done = (bool *)tevent_req_callback_data_void(req);
6543 status = cli_tcon_andx_recv(req);
6544 d_printf("tcon_and_x returned %s\n", nt_errstr(status));
6548 static bool run_chain2(int dummy)
6550 struct cli_state *cli1;
6551 struct event_context *evt = event_context_init(NULL);
6552 struct tevent_req *reqs[2], *smbreqs[2];
6556 printf("starting chain2 test\n");
6557 status = cli_start_connection(&cli1, lp_netbios_name(), host, NULL,
6558 port_to_use, Undefined, 0);
6559 if (!NT_STATUS_IS_OK(status)) {
6563 cli_sockopt(cli1, sockops);
6565 reqs[0] = cli_session_setup_guest_create(talloc_tos(), evt, cli1,
6567 if (reqs[0] == NULL) return false;
6568 tevent_req_set_callback(reqs[0], chain2_sesssetup_completion, NULL);
6570 reqs[1] = cli_tcon_andx_create(talloc_tos(), evt, cli1, "IPC$",
6571 "?????", NULL, 0, &smbreqs[1]);
6572 if (reqs[1] == NULL) return false;
6573 tevent_req_set_callback(reqs[1], chain2_tcon_completion, &done);
6575 status = cli_smb_chain_send(smbreqs, ARRAY_SIZE(smbreqs));
6576 if (!NT_STATUS_IS_OK(status)) {
6581 tevent_loop_once(evt);
6584 torture_close_connection(cli1);
6589 struct torture_createdel_state {
6590 struct tevent_context *ev;
6591 struct cli_state *cli;
6594 static void torture_createdel_created(struct tevent_req *subreq);
6595 static void torture_createdel_closed(struct tevent_req *subreq);
6597 static struct tevent_req *torture_createdel_send(TALLOC_CTX *mem_ctx,
6598 struct tevent_context *ev,
6599 struct cli_state *cli,
6602 struct tevent_req *req, *subreq;
6603 struct torture_createdel_state *state;
6605 req = tevent_req_create(mem_ctx, &state,
6606 struct torture_createdel_state);
6613 subreq = cli_ntcreate_send(
6614 state, ev, cli, name, 0,
6615 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
6616 FILE_ATTRIBUTE_NORMAL,
6617 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
6618 FILE_OPEN_IF, FILE_DELETE_ON_CLOSE, 0);
6620 if (tevent_req_nomem(subreq, req)) {
6621 return tevent_req_post(req, ev);
6623 tevent_req_set_callback(subreq, torture_createdel_created, req);
6627 static void torture_createdel_created(struct tevent_req *subreq)
6629 struct tevent_req *req = tevent_req_callback_data(
6630 subreq, struct tevent_req);
6631 struct torture_createdel_state *state = tevent_req_data(
6632 req, struct torture_createdel_state);
6636 status = cli_ntcreate_recv(subreq, &fnum);
6637 TALLOC_FREE(subreq);
6638 if (!NT_STATUS_IS_OK(status)) {
6639 DEBUG(10, ("cli_ntcreate_recv returned %s\n",
6640 nt_errstr(status)));
6641 tevent_req_nterror(req, status);
6645 subreq = cli_close_send(state, state->ev, state->cli, fnum);
6646 if (tevent_req_nomem(subreq, req)) {
6649 tevent_req_set_callback(subreq, torture_createdel_closed, req);
6652 static void torture_createdel_closed(struct tevent_req *subreq)
6654 struct tevent_req *req = tevent_req_callback_data(
6655 subreq, struct tevent_req);
6658 status = cli_close_recv(subreq);
6659 if (!NT_STATUS_IS_OK(status)) {
6660 DEBUG(10, ("cli_close_recv returned %s\n", nt_errstr(status)));
6661 tevent_req_nterror(req, status);
6664 tevent_req_done(req);
6667 static NTSTATUS torture_createdel_recv(struct tevent_req *req)
6669 return tevent_req_simple_recv_ntstatus(req);
6672 struct torture_createdels_state {
6673 struct tevent_context *ev;
6674 struct cli_state *cli;
6675 const char *base_name;
6679 struct tevent_req **reqs;
6682 static void torture_createdels_done(struct tevent_req *subreq);
6684 static struct tevent_req *torture_createdels_send(TALLOC_CTX *mem_ctx,
6685 struct tevent_context *ev,
6686 struct cli_state *cli,
6687 const char *base_name,
6691 struct tevent_req *req;
6692 struct torture_createdels_state *state;
6695 req = tevent_req_create(mem_ctx, &state,
6696 struct torture_createdels_state);
6702 state->base_name = talloc_strdup(state, base_name);
6703 if (tevent_req_nomem(state->base_name, req)) {
6704 return tevent_req_post(req, ev);
6706 state->num_files = MAX(num_parallel, num_files);
6708 state->received = 0;
6710 state->reqs = talloc_array(state, struct tevent_req *, num_parallel);
6711 if (tevent_req_nomem(state->reqs, req)) {
6712 return tevent_req_post(req, ev);
6715 for (i=0; i<num_parallel; i++) {
6718 name = talloc_asprintf(state, "%s%8.8d", state->base_name,
6720 if (tevent_req_nomem(name, req)) {
6721 return tevent_req_post(req, ev);
6723 state->reqs[i] = torture_createdel_send(
6724 state->reqs, state->ev, state->cli, name);
6725 if (tevent_req_nomem(state->reqs[i], req)) {
6726 return tevent_req_post(req, ev);
6728 name = talloc_move(state->reqs[i], &name);
6729 tevent_req_set_callback(state->reqs[i],
6730 torture_createdels_done, req);
6736 static void torture_createdels_done(struct tevent_req *subreq)
6738 struct tevent_req *req = tevent_req_callback_data(
6739 subreq, struct tevent_req);
6740 struct torture_createdels_state *state = tevent_req_data(
6741 req, struct torture_createdels_state);
6742 size_t num_parallel = talloc_array_length(state->reqs);
6747 status = torture_createdel_recv(subreq);
6748 if (!NT_STATUS_IS_OK(status)){
6749 DEBUG(10, ("torture_createdel_recv returned %s\n",
6750 nt_errstr(status)));
6751 TALLOC_FREE(subreq);
6752 tevent_req_nterror(req, status);
6756 for (i=0; i<num_parallel; i++) {
6757 if (subreq == state->reqs[i]) {
6761 if (i == num_parallel) {
6762 DEBUG(10, ("received something we did not send\n"));
6763 tevent_req_nterror(req, NT_STATUS_INTERNAL_ERROR);
6766 TALLOC_FREE(state->reqs[i]);
6768 if (state->sent >= state->num_files) {
6769 tevent_req_done(req);
6773 name = talloc_asprintf(state, "%s%8.8d", state->base_name,
6775 if (tevent_req_nomem(name, req)) {
6778 state->reqs[i] = torture_createdel_send(state->reqs, state->ev,
6780 if (tevent_req_nomem(state->reqs[i], req)) {
6783 name = talloc_move(state->reqs[i], &name);
6784 tevent_req_set_callback(state->reqs[i], torture_createdels_done, req);
6788 static NTSTATUS torture_createdels_recv(struct tevent_req *req)
6790 return tevent_req_simple_recv_ntstatus(req);
6793 struct swallow_notify_state {
6794 struct tevent_context *ev;
6795 struct cli_state *cli;
6797 uint32_t completion_filter;
6799 bool (*fn)(uint32_t action, const char *name, void *priv);
6803 static void swallow_notify_done(struct tevent_req *subreq);
6805 static struct tevent_req *swallow_notify_send(TALLOC_CTX *mem_ctx,
6806 struct tevent_context *ev,
6807 struct cli_state *cli,
6809 uint32_t completion_filter,
6811 bool (*fn)(uint32_t action,
6816 struct tevent_req *req, *subreq;
6817 struct swallow_notify_state *state;
6819 req = tevent_req_create(mem_ctx, &state,
6820 struct swallow_notify_state);
6827 state->completion_filter = completion_filter;
6828 state->recursive = recursive;
6832 subreq = cli_notify_send(state, state->ev, state->cli, state->fnum,
6833 0xffff, state->completion_filter,
6835 if (tevent_req_nomem(subreq, req)) {
6836 return tevent_req_post(req, ev);
6838 tevent_req_set_callback(subreq, swallow_notify_done, req);
6842 static void swallow_notify_done(struct tevent_req *subreq)
6844 struct tevent_req *req = tevent_req_callback_data(
6845 subreq, struct tevent_req);
6846 struct swallow_notify_state *state = tevent_req_data(
6847 req, struct swallow_notify_state);
6849 uint32_t i, num_changes;
6850 struct notify_change *changes;
6852 status = cli_notify_recv(subreq, state, &num_changes, &changes);
6853 TALLOC_FREE(subreq);
6854 if (!NT_STATUS_IS_OK(status)) {
6855 DEBUG(10, ("cli_notify_recv returned %s\n",
6856 nt_errstr(status)));
6857 tevent_req_nterror(req, status);
6861 for (i=0; i<num_changes; i++) {
6862 state->fn(changes[i].action, changes[i].name, state->priv);
6864 TALLOC_FREE(changes);
6866 subreq = cli_notify_send(state, state->ev, state->cli, state->fnum,
6867 0xffff, state->completion_filter,
6869 if (tevent_req_nomem(subreq, req)) {
6872 tevent_req_set_callback(subreq, swallow_notify_done, req);
6875 static bool print_notifies(uint32_t action, const char *name, void *priv)
6877 if (DEBUGLEVEL > 5) {
6878 d_printf("%d %s\n", (int)action, name);
6883 static void notify_bench_done(struct tevent_req *req)
6885 int *num_finished = (int *)tevent_req_callback_data_void(req);
6889 static bool run_notify_bench(int dummy)
6891 const char *dname = "\\notify-bench";
6892 struct tevent_context *ev;
6895 struct tevent_req *req1;
6896 struct tevent_req *req2 = NULL;
6897 int i, num_unc_names;
6898 int num_finished = 0;
6900 printf("starting notify-bench test\n");
6902 if (use_multishare_conn) {
6904 unc_list = file_lines_load(multishare_conn_fname,
6905 &num_unc_names, 0, NULL);
6906 if (!unc_list || num_unc_names <= 0) {
6907 d_printf("Failed to load unc names list from '%s'\n",
6908 multishare_conn_fname);
6911 TALLOC_FREE(unc_list);
6916 ev = tevent_context_init(talloc_tos());
6918 d_printf("tevent_context_init failed\n");
6922 for (i=0; i<num_unc_names; i++) {
6923 struct cli_state *cli;
6926 base_fname = talloc_asprintf(talloc_tos(), "%s\\file%3.3d.",
6928 if (base_fname == NULL) {
6932 if (!torture_open_connection(&cli, i)) {
6936 status = cli_ntcreate(cli, dname, 0,
6937 MAXIMUM_ALLOWED_ACCESS,
6938 0, FILE_SHARE_READ|FILE_SHARE_WRITE|
6940 FILE_OPEN_IF, FILE_DIRECTORY_FILE, 0,
6943 if (!NT_STATUS_IS_OK(status)) {
6944 d_printf("Could not create %s: %s\n", dname,
6949 req1 = swallow_notify_send(talloc_tos(), ev, cli, dnum,
6950 FILE_NOTIFY_CHANGE_FILE_NAME |
6951 FILE_NOTIFY_CHANGE_DIR_NAME |
6952 FILE_NOTIFY_CHANGE_ATTRIBUTES |
6953 FILE_NOTIFY_CHANGE_LAST_WRITE,
6954 false, print_notifies, NULL);
6956 d_printf("Could not create notify request\n");
6960 req2 = torture_createdels_send(talloc_tos(), ev, cli,
6961 base_fname, 10, torture_numops);
6963 d_printf("Could not create createdels request\n");
6966 TALLOC_FREE(base_fname);
6968 tevent_req_set_callback(req2, notify_bench_done,
6972 while (num_finished < num_unc_names) {
6974 ret = tevent_loop_once(ev);
6976 d_printf("tevent_loop_once failed\n");
6981 if (!tevent_req_poll(req2, ev)) {
6982 d_printf("tevent_req_poll failed\n");
6985 status = torture_createdels_recv(req2);
6986 d_printf("torture_createdels_recv returned %s\n", nt_errstr(status));
6991 static bool run_mangle1(int dummy)
6993 struct cli_state *cli;
6994 const char *fname = "this_is_a_long_fname_to_be_mangled.txt";
6998 time_t change_time, access_time, write_time;
7002 printf("starting mangle1 test\n");
7003 if (!torture_open_connection(&cli, 0)) {
7007 cli_sockopt(cli, sockops);
7009 status = cli_ntcreate(cli, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
7010 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
7012 if (!NT_STATUS_IS_OK(status)) {
7013 d_printf("open %s failed: %s\n", fname, nt_errstr(status));
7016 cli_close(cli, fnum);
7018 status = cli_qpathinfo_alt_name(cli, fname, alt_name);
7019 if (!NT_STATUS_IS_OK(status)) {
7020 d_printf("cli_qpathinfo_alt_name failed: %s\n",
7024 d_printf("alt_name: %s\n", alt_name);
7026 status = cli_open(cli, alt_name, O_RDONLY, DENY_NONE, &fnum);
7027 if (!NT_STATUS_IS_OK(status)) {
7028 d_printf("cli_open(%s) failed: %s\n", alt_name,
7032 cli_close(cli, fnum);
7034 status = cli_qpathinfo1(cli, alt_name, &change_time, &access_time,
7035 &write_time, &size, &mode);
7036 if (!NT_STATUS_IS_OK(status)) {
7037 d_printf("cli_qpathinfo1(%s) failed: %s\n", alt_name,
7045 static size_t null_source(uint8_t *buf, size_t n, void *priv)
7047 size_t *to_pull = (size_t *)priv;
7048 size_t thistime = *to_pull;
7050 thistime = MIN(thistime, n);
7051 if (thistime == 0) {
7055 memset(buf, 0, thistime);
7056 *to_pull -= thistime;
7060 static bool run_windows_write(int dummy)
7062 struct cli_state *cli1;
7066 const char *fname = "\\writetest.txt";
7067 struct timeval start_time;
7072 printf("starting windows_write test\n");
7073 if (!torture_open_connection(&cli1, 0)) {
7077 status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
7078 if (!NT_STATUS_IS_OK(status)) {
7079 printf("open failed (%s)\n", nt_errstr(status));
7083 cli_sockopt(cli1, sockops);
7085 start_time = timeval_current();
7087 for (i=0; i<torture_numops; i++) {
7089 off_t start = i * torture_blocksize;
7090 size_t to_pull = torture_blocksize - 1;
7092 status = cli_writeall(cli1, fnum, 0, &c,
7093 start + torture_blocksize - 1, 1, NULL);
7094 if (!NT_STATUS_IS_OK(status)) {
7095 printf("cli_write failed: %s\n", nt_errstr(status));
7099 status = cli_push(cli1, fnum, 0, i * torture_blocksize, torture_blocksize,
7100 null_source, &to_pull);
7101 if (!NT_STATUS_IS_OK(status)) {
7102 printf("cli_push returned: %s\n", nt_errstr(status));
7107 seconds = timeval_elapsed(&start_time);
7108 kbytes = (double)torture_blocksize * torture_numops;
7111 printf("Wrote %d kbytes in %.2f seconds: %d kb/sec\n", (int)kbytes,
7112 (double)seconds, (int)(kbytes/seconds));
7116 cli_close(cli1, fnum);
7117 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7118 torture_close_connection(cli1);
7122 static bool run_cli_echo(int dummy)
7124 struct cli_state *cli;
7127 printf("starting cli_echo test\n");
7128 if (!torture_open_connection(&cli, 0)) {
7131 cli_sockopt(cli, sockops);
7133 status = cli_echo(cli, 5, data_blob_const("hello", 5));
7135 d_printf("cli_echo returned %s\n", nt_errstr(status));
7137 torture_close_connection(cli);
7138 return NT_STATUS_IS_OK(status);
7141 static bool run_uid_regression_test(int dummy)
7143 static struct cli_state *cli;
7146 bool correct = True;
7149 printf("starting uid regression test\n");
7151 if (!torture_open_connection(&cli, 0)) {
7155 cli_sockopt(cli, sockops);
7157 /* Ok - now save then logoff our current user. */
7158 old_vuid = cli_state_get_uid(cli);
7160 status = cli_ulogoff(cli);
7161 if (!NT_STATUS_IS_OK(status)) {
7162 d_printf("(%s) cli_ulogoff failed: %s\n",
7163 __location__, nt_errstr(status));
7168 cli_state_set_uid(cli, old_vuid);
7170 /* Try an operation. */
7171 status = cli_mkdir(cli, "\\uid_reg_test");
7172 if (NT_STATUS_IS_OK(status)) {
7173 d_printf("(%s) cli_mkdir succeeded\n",
7178 /* Should be bad uid. */
7179 if (!check_error(__LINE__, status, ERRSRV, ERRbaduid,
7180 NT_STATUS_USER_SESSION_DELETED)) {
7186 old_cnum = cli_state_get_tid(cli);
7188 /* Now try a SMBtdis with the invald vuid set to zero. */
7189 cli_state_set_uid(cli, 0);
7191 /* This should succeed. */
7192 status = cli_tdis(cli);
7194 if (NT_STATUS_IS_OK(status)) {
7195 d_printf("First tdis with invalid vuid should succeed.\n");
7197 d_printf("First tdis failed (%s)\n", nt_errstr(status));
7202 cli_state_set_uid(cli, old_vuid);
7203 cli_state_set_tid(cli, old_cnum);
7205 /* This should fail. */
7206 status = cli_tdis(cli);
7207 if (NT_STATUS_IS_OK(status)) {
7208 d_printf("Second tdis with invalid vuid should fail - succeeded instead !.\n");
7212 /* Should be bad tid. */
7213 if (!check_error(__LINE__, status, ERRSRV, ERRinvnid,
7214 NT_STATUS_NETWORK_NAME_DELETED)) {
7220 cli_rmdir(cli, "\\uid_reg_test");
7229 static const char *illegal_chars = "*\\/?<>|\":";
7230 static char force_shortname_chars[] = " +,.[];=\177";
7232 static NTSTATUS shortname_del_fn(const char *mnt, struct file_info *finfo,
7233 const char *mask, void *state)
7235 struct cli_state *pcli = (struct cli_state *)state;
7237 NTSTATUS status = NT_STATUS_OK;
7239 slprintf(fname, sizeof(fname), "\\shortname\\%s", finfo->name);
7241 if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
7242 return NT_STATUS_OK;
7244 if (finfo->mode & FILE_ATTRIBUTE_DIRECTORY) {
7245 status = cli_rmdir(pcli, fname);
7246 if (!NT_STATUS_IS_OK(status)) {
7247 printf("del_fn: failed to rmdir %s\n,", fname );
7250 status = cli_unlink(pcli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7251 if (!NT_STATUS_IS_OK(status)) {
7252 printf("del_fn: failed to unlink %s\n,", fname );
7264 static NTSTATUS shortname_list_fn(const char *mnt, struct file_info *finfo,
7265 const char *name, void *state)
7267 struct sn_state *s = (struct sn_state *)state;
7271 printf("shortname list: i = %d, name = |%s|, shortname = |%s|\n",
7272 i, finfo->name, finfo->short_name);
7275 if (strchr(force_shortname_chars, i)) {
7276 if (!finfo->short_name) {
7277 /* Shortname not created when it should be. */
7278 d_printf("(%s) ERROR: Shortname was not created for file %s containing %d\n",
7279 __location__, finfo->name, i);
7282 } else if (finfo->short_name){
7283 /* Shortname created when it should not be. */
7284 d_printf("(%s) ERROR: Shortname %s was created for file %s\n",
7285 __location__, finfo->short_name, finfo->name);
7289 return NT_STATUS_OK;
7292 static bool run_shortname_test(int dummy)
7294 static struct cli_state *cli;
7295 bool correct = True;
7301 printf("starting shortname test\n");
7303 if (!torture_open_connection(&cli, 0)) {
7307 cli_sockopt(cli, sockops);
7309 cli_list(cli, "\\shortname\\*", 0, shortname_del_fn, cli);
7310 cli_list(cli, "\\shortname\\*", FILE_ATTRIBUTE_DIRECTORY, shortname_del_fn, cli);
7311 cli_rmdir(cli, "\\shortname");
7313 status = cli_mkdir(cli, "\\shortname");
7314 if (!NT_STATUS_IS_OK(status)) {
7315 d_printf("(%s) cli_mkdir of \\shortname failed: %s\n",
7316 __location__, nt_errstr(status));
7321 strlcpy(fname, "\\shortname\\", sizeof(fname));
7322 strlcat(fname, "test .txt", sizeof(fname));
7326 for (i = 32; i < 128; i++) {
7327 uint16_t fnum = (uint16_t)-1;
7331 if (strchr(illegal_chars, i)) {
7336 status = cli_ntcreate(cli, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
7337 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum);
7338 if (!NT_STATUS_IS_OK(status)) {
7339 d_printf("(%s) cli_nt_create of %s failed: %s\n",
7340 __location__, fname, nt_errstr(status));
7344 cli_close(cli, fnum);
7347 status = cli_list(cli, "\\shortname\\test*.*", 0,
7348 shortname_list_fn, &s);
7349 if (s.matched != 1) {
7350 d_printf("(%s) failed to list %s: %s\n",
7351 __location__, fname, nt_errstr(status));
7356 status = cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7357 if (!NT_STATUS_IS_OK(status)) {
7358 d_printf("(%s) failed to delete %s: %s\n",
7359 __location__, fname, nt_errstr(status));
7372 cli_list(cli, "\\shortname\\*", 0, shortname_del_fn, cli);
7373 cli_list(cli, "\\shortname\\*", FILE_ATTRIBUTE_DIRECTORY, shortname_del_fn, cli);
7374 cli_rmdir(cli, "\\shortname");
7375 torture_close_connection(cli);
7379 static void pagedsearch_cb(struct tevent_req *req)
7382 struct tldap_message *msg;
7385 rc = tldap_search_paged_recv(req, talloc_tos(), &msg);
7386 if (rc != TLDAP_SUCCESS) {
7387 d_printf("tldap_search_paged_recv failed: %s\n",
7388 tldap_err2string(rc));
7391 if (tldap_msg_type(msg) != TLDAP_RES_SEARCH_ENTRY) {
7395 if (!tldap_entry_dn(msg, &dn)) {
7396 d_printf("tldap_entry_dn failed\n");
7399 d_printf("%s\n", dn);
7403 static bool run_tldap(int dummy)
7405 struct tldap_context *ld;
7408 struct sockaddr_storage addr;
7409 struct tevent_context *ev;
7410 struct tevent_req *req;
7414 if (!resolve_name(host, &addr, 0, false)) {
7415 d_printf("could not find host %s\n", host);
7418 status = open_socket_out(&addr, 389, 9999, &fd);
7419 if (!NT_STATUS_IS_OK(status)) {
7420 d_printf("open_socket_out failed: %s\n", nt_errstr(status));
7424 ld = tldap_context_create(talloc_tos(), fd);
7427 d_printf("tldap_context_create failed\n");
7431 rc = tldap_fetch_rootdse(ld);
7432 if (rc != TLDAP_SUCCESS) {
7433 d_printf("tldap_fetch_rootdse failed: %s\n",
7434 tldap_errstr(talloc_tos(), ld, rc));
7438 basedn = tldap_talloc_single_attribute(
7439 tldap_rootdse(ld), "defaultNamingContext", talloc_tos());
7440 if (basedn == NULL) {
7441 d_printf("no defaultNamingContext\n");
7444 d_printf("defaultNamingContext: %s\n", basedn);
7446 ev = tevent_context_init(talloc_tos());
7448 d_printf("tevent_context_init failed\n");
7452 req = tldap_search_paged_send(talloc_tos(), ev, ld, basedn,
7453 TLDAP_SCOPE_SUB, "(objectclass=*)",
7455 NULL, 0, NULL, 0, 0, 0, 0, 5);
7457 d_printf("tldap_search_paged_send failed\n");
7460 tevent_req_set_callback(req, pagedsearch_cb, NULL);
7462 tevent_req_poll(req, ev);
7466 /* test search filters against rootDSE */
7467 filter = "(&(|(name=samba)(nextRid<=10000000)(usnChanged>=10)(samba~=ambas)(!(name=s*m*a)))"
7468 "(|(name:=samba)(name:dn:2.5.13.5:=samba)(:dn:2.5.13.5:=samba)(!(name=*samba))))";
7470 rc = tldap_search(ld, "", TLDAP_SCOPE_BASE, filter,
7471 NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0,
7472 talloc_tos(), NULL, NULL);
7473 if (rc != TLDAP_SUCCESS) {
7474 d_printf("tldap_search with complex filter failed: %s\n",
7475 tldap_errstr(talloc_tos(), ld, rc));
7483 /* Torture test to ensure no regression of :
7484 https://bugzilla.samba.org/show_bug.cgi?id=7084
7487 static bool run_dir_createtime(int dummy)
7489 struct cli_state *cli;
7490 const char *dname = "\\testdir";
7491 const char *fname = "\\testdir\\testfile";
7493 struct timespec create_time;
7494 struct timespec create_time1;
7498 if (!torture_open_connection(&cli, 0)) {
7502 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7503 cli_rmdir(cli, dname);
7505 status = cli_mkdir(cli, dname);
7506 if (!NT_STATUS_IS_OK(status)) {
7507 printf("mkdir failed: %s\n", nt_errstr(status));
7511 status = cli_qpathinfo2(cli, dname, &create_time, NULL, NULL, NULL,
7513 if (!NT_STATUS_IS_OK(status)) {
7514 printf("cli_qpathinfo2 returned %s\n",
7519 /* Sleep 3 seconds, then create a file. */
7522 status = cli_open(cli, fname, O_RDWR | O_CREAT | O_EXCL,
7524 if (!NT_STATUS_IS_OK(status)) {
7525 printf("cli_open failed: %s\n", nt_errstr(status));
7529 status = cli_qpathinfo2(cli, dname, &create_time1, NULL, NULL, NULL,
7531 if (!NT_STATUS_IS_OK(status)) {
7532 printf("cli_qpathinfo2 (2) returned %s\n",
7537 if (timespec_compare(&create_time1, &create_time)) {
7538 printf("run_dir_createtime: create time was updated (error)\n");
7540 printf("run_dir_createtime: create time was not updated (correct)\n");
7546 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7547 cli_rmdir(cli, dname);
7548 if (!torture_close_connection(cli)) {
7555 static bool run_streamerror(int dummy)
7557 struct cli_state *cli;
7558 const char *dname = "\\testdir";
7559 const char *streamname =
7560 "testdir:{4c8cc155-6c1e-11d1-8e41-00c04fb9386d}:$DATA";
7562 time_t change_time, access_time, write_time;
7564 uint16_t mode, fnum;
7567 if (!torture_open_connection(&cli, 0)) {
7571 cli_unlink(cli, "\\testdir\\*", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7572 cli_rmdir(cli, dname);
7574 status = cli_mkdir(cli, dname);
7575 if (!NT_STATUS_IS_OK(status)) {
7576 printf("mkdir failed: %s\n", nt_errstr(status));
7580 cli_qpathinfo1(cli, streamname, &change_time, &access_time, &write_time,
7582 status = cli_nt_error(cli);
7584 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
7585 printf("pathinfo returned %s, expected "
7586 "NT_STATUS_OBJECT_NAME_NOT_FOUND\n",
7591 status = cli_ntcreate(cli, streamname, 0x16,
7592 FILE_READ_DATA|FILE_READ_EA|
7593 FILE_READ_ATTRIBUTES|READ_CONTROL_ACCESS,
7594 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ,
7595 FILE_OPEN, 0, 0, &fnum);
7597 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
7598 printf("ntcreate returned %s, expected "
7599 "NT_STATUS_OBJECT_NAME_NOT_FOUND\n",
7605 cli_rmdir(cli, dname);
7609 static bool run_local_substitute(int dummy)
7613 ok &= subst_test("%U", "bla", "", -1, -1, "bla");
7614 ok &= subst_test("%u%U", "bla", "", -1, -1, "blabla");
7615 ok &= subst_test("%g", "", "", -1, -1, "NO_GROUP");
7616 ok &= subst_test("%G", "", "", -1, -1, "NO_GROUP");
7617 ok &= subst_test("%g", "", "", -1, 0, gidtoname(0));
7618 ok &= subst_test("%G", "", "", -1, 0, gidtoname(0));
7619 ok &= subst_test("%D%u", "u", "dom", -1, 0, "domu");
7620 ok &= subst_test("%i %I", "", "", -1, -1, "0.0.0.0 0.0.0.0");
7622 /* Different captialization rules in sub_basic... */
7624 ok &= (strcmp(talloc_sub_basic(talloc_tos(), "BLA", "dom", "%U%D"),
7630 static bool run_local_base64(int dummy)
7635 for (i=1; i<2000; i++) {
7636 DATA_BLOB blob1, blob2;
7639 blob1.data = talloc_array(talloc_tos(), uint8_t, i);
7641 generate_random_buffer(blob1.data, blob1.length);
7643 b64 = base64_encode_data_blob(talloc_tos(), blob1);
7645 d_fprintf(stderr, "base64_encode_data_blob failed "
7646 "for %d bytes\n", i);
7649 blob2 = base64_decode_data_blob(b64);
7652 if (data_blob_cmp(&blob1, &blob2)) {
7653 d_fprintf(stderr, "data_blob_cmp failed for %d "
7657 TALLOC_FREE(blob1.data);
7658 data_blob_free(&blob2);
7663 static bool run_local_gencache(int dummy)
7669 if (!gencache_set("foo", "bar", time(NULL) + 1000)) {
7670 d_printf("%s: gencache_set() failed\n", __location__);
7674 if (!gencache_get("foo", NULL, NULL)) {
7675 d_printf("%s: gencache_get() failed\n", __location__);
7679 if (!gencache_get("foo", &val, &tm)) {
7680 d_printf("%s: gencache_get() failed\n", __location__);
7684 if (strcmp(val, "bar") != 0) {
7685 d_printf("%s: gencache_get() returned %s, expected %s\n",
7686 __location__, val, "bar");
7693 if (!gencache_del("foo")) {
7694 d_printf("%s: gencache_del() failed\n", __location__);
7697 if (gencache_del("foo")) {
7698 d_printf("%s: second gencache_del() succeeded\n",
7703 if (gencache_get("foo", &val, &tm)) {
7704 d_printf("%s: gencache_get() on deleted entry "
7705 "succeeded\n", __location__);
7709 blob = data_blob_string_const_null("bar");
7710 tm = time(NULL) + 60;
7712 if (!gencache_set_data_blob("foo", &blob, tm)) {
7713 d_printf("%s: gencache_set_data_blob() failed\n", __location__);
7717 if (!gencache_get_data_blob("foo", &blob, NULL, NULL)) {
7718 d_printf("%s: gencache_get_data_blob() failed\n", __location__);
7722 if (strcmp((const char *)blob.data, "bar") != 0) {
7723 d_printf("%s: gencache_get_data_blob() returned %s, expected %s\n",
7724 __location__, (const char *)blob.data, "bar");
7725 data_blob_free(&blob);
7729 data_blob_free(&blob);
7731 if (!gencache_del("foo")) {
7732 d_printf("%s: gencache_del() failed\n", __location__);
7735 if (gencache_del("foo")) {
7736 d_printf("%s: second gencache_del() succeeded\n",
7741 if (gencache_get_data_blob("foo", &blob, NULL, NULL)) {
7742 d_printf("%s: gencache_get_data_blob() on deleted entry "
7743 "succeeded\n", __location__);
7750 static bool rbt_testval(struct db_context *db, const char *key,
7753 struct db_record *rec;
7754 TDB_DATA data = string_tdb_data(value);
7759 rec = dbwrap_fetch_locked(db, db, string_tdb_data(key));
7761 d_fprintf(stderr, "fetch_locked failed\n");
7764 status = dbwrap_record_store(rec, data, 0);
7765 if (!NT_STATUS_IS_OK(status)) {
7766 d_fprintf(stderr, "store failed: %s\n", nt_errstr(status));
7771 rec = dbwrap_fetch_locked(db, db, string_tdb_data(key));
7773 d_fprintf(stderr, "second fetch_locked failed\n");
7777 dbvalue = dbwrap_record_get_value(rec);
7778 if ((dbvalue.dsize != data.dsize)
7779 || (memcmp(dbvalue.dptr, data.dptr, data.dsize) != 0)) {
7780 d_fprintf(stderr, "Got wrong data back\n");
7790 static bool run_local_rbtree(int dummy)
7792 struct db_context *db;
7796 db = db_open_rbt(NULL);
7799 d_fprintf(stderr, "db_open_rbt failed\n");
7803 for (i=0; i<1000; i++) {
7806 if (asprintf(&key, "key%ld", random()) == -1) {
7809 if (asprintf(&value, "value%ld", random()) == -1) {
7814 if (!rbt_testval(db, key, value)) {
7821 if (asprintf(&value, "value%ld", random()) == -1) {
7826 if (!rbt_testval(db, key, value)) {
7845 local test for character set functions
7847 This is a very simple test for the functionality in convert_string_error()
7849 static bool run_local_convert_string(int dummy)
7851 TALLOC_CTX *tmp_ctx = talloc_new(NULL);
7852 const char *test_strings[2] = { "March", "M\303\244rz" };
7856 for (i=0; i<2; i++) {
7857 const char *str = test_strings[i];
7858 int len = strlen(str);
7859 size_t converted_size;
7862 memset(dst, 'X', sizeof(dst));
7864 /* first try with real source length */
7865 ret = convert_string_error(CH_UNIX, CH_UTF8,
7870 d_fprintf(stderr, "Failed to convert '%s' to CH_DISPLAY\n", str);
7874 if (converted_size != len) {
7875 d_fprintf(stderr, "Converted size of '%s' should be %d - got %d\n",
7876 str, len, (int)converted_size);
7880 if (strncmp(str, dst, converted_size) != 0) {
7881 d_fprintf(stderr, "Expected '%s' to match '%s'\n", str, dst);
7885 if (strlen(str) != converted_size) {
7886 d_fprintf(stderr, "Expected '%s' length %d - got %d\n", str,
7887 (int)strlen(str), (int)converted_size);
7891 if (dst[converted_size] != 'X') {
7892 d_fprintf(stderr, "Expected no termination of '%s'\n", dst);
7896 /* now with srclen==-1, this causes the nul to be
7898 ret = convert_string_error(CH_UNIX, CH_UTF8,
7903 d_fprintf(stderr, "Failed to convert '%s' to CH_DISPLAY\n", str);
7907 if (converted_size != len+1) {
7908 d_fprintf(stderr, "Converted size of '%s' should be %d - got %d\n",
7909 str, len, (int)converted_size);
7913 if (strncmp(str, dst, converted_size) != 0) {
7914 d_fprintf(stderr, "Expected '%s' to match '%s'\n", str, dst);
7918 if (len+1 != converted_size) {
7919 d_fprintf(stderr, "Expected '%s' length %d - got %d\n", str,
7920 len+1, (int)converted_size);
7924 if (dst[converted_size] != 'X') {
7925 d_fprintf(stderr, "Expected no termination of '%s'\n", dst);
7932 TALLOC_FREE(tmp_ctx);
7935 TALLOC_FREE(tmp_ctx);
7940 struct talloc_dict_test {
7944 static int talloc_dict_traverse_fn(DATA_BLOB key, void *data, void *priv)
7946 int *count = (int *)priv;
7951 static bool run_local_talloc_dict(int dummy)
7953 struct talloc_dict *dict;
7954 struct talloc_dict_test *t;
7957 dict = talloc_dict_init(talloc_tos());
7962 t = talloc(talloc_tos(), struct talloc_dict_test);
7969 if (!talloc_dict_set(dict, data_blob_const(&key, sizeof(key)), t)) {
7974 if (talloc_dict_traverse(dict, talloc_dict_traverse_fn, &count) != 0) {
7987 static bool run_local_string_to_sid(int dummy) {
7990 if (string_to_sid(&sid, "S--1-5-32-545")) {
7991 printf("allowing S--1-5-32-545\n");
7994 if (string_to_sid(&sid, "S-1-5-32-+545")) {
7995 printf("allowing S-1-5-32-+545\n");
7998 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")) {
7999 printf("allowing S-1-2-3-4-5-6-7-8-9-0-1-2-3-4-5-6-7-8-9-0\n");
8002 if (string_to_sid(&sid, "S-1-5-32-545-abc")) {
8003 printf("allowing S-1-5-32-545-abc\n");
8006 if (!string_to_sid(&sid, "S-1-5-32-545")) {
8007 printf("could not parse S-1-5-32-545\n");
8010 if (!dom_sid_equal(&sid, &global_sid_Builtin_Users)) {
8011 printf("mis-parsed S-1-5-32-545 as %s\n",
8012 sid_string_tos(&sid));
8018 static bool run_local_binary_to_sid(int dummy) {
8019 struct dom_sid *sid = talloc(NULL, struct dom_sid);
8020 static const char good_binary_sid[] = {
8021 0x1, /* revision number */
8023 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, /* id_auth */
8024 0x1, 0x1, 0x1, 0x1, /* auth[0] */
8025 0x1, 0x1, 0x1, 0x1, /* auth[1] */
8026 0x1, 0x1, 0x1, 0x1, /* auth[2] */
8027 0x1, 0x1, 0x1, 0x1, /* auth[3] */
8028 0x1, 0x1, 0x1, 0x1, /* auth[4] */
8029 0x1, 0x1, 0x1, 0x1, /* auth[5] */
8030 0x1, 0x1, 0x1, 0x1, /* auth[6] */
8031 0x1, 0x1, 0x1, 0x1, /* auth[7] */
8032 0x1, 0x1, 0x1, 0x1, /* auth[8] */
8033 0x1, 0x1, 0x1, 0x1, /* auth[9] */
8034 0x1, 0x1, 0x1, 0x1, /* auth[10] */
8035 0x1, 0x1, 0x1, 0x1, /* auth[11] */
8036 0x1, 0x1, 0x1, 0x1, /* auth[12] */
8037 0x1, 0x1, 0x1, 0x1, /* auth[13] */
8038 0x1, 0x1, 0x1, 0x1, /* auth[14] */
8041 static const char long_binary_sid[] = {
8042 0x1, /* revision number */
8044 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, /* id_auth */
8045 0x1, 0x1, 0x1, 0x1, /* auth[0] */
8046 0x1, 0x1, 0x1, 0x1, /* auth[1] */
8047 0x1, 0x1, 0x1, 0x1, /* auth[2] */
8048 0x1, 0x1, 0x1, 0x1, /* auth[3] */
8049 0x1, 0x1, 0x1, 0x1, /* auth[4] */
8050 0x1, 0x1, 0x1, 0x1, /* auth[5] */
8051 0x1, 0x1, 0x1, 0x1, /* auth[6] */
8052 0x1, 0x1, 0x1, 0x1, /* auth[7] */
8053 0x1, 0x1, 0x1, 0x1, /* auth[8] */
8054 0x1, 0x1, 0x1, 0x1, /* auth[9] */
8055 0x1, 0x1, 0x1, 0x1, /* auth[10] */
8056 0x1, 0x1, 0x1, 0x1, /* auth[11] */
8057 0x1, 0x1, 0x1, 0x1, /* auth[12] */
8058 0x1, 0x1, 0x1, 0x1, /* auth[13] */
8059 0x1, 0x1, 0x1, 0x1, /* auth[14] */
8060 0x1, 0x1, 0x1, 0x1, /* auth[15] */
8061 0x1, 0x1, 0x1, 0x1, /* auth[16] */
8062 0x1, 0x1, 0x1, 0x1, /* auth[17] */
8065 static const char long_binary_sid2[] = {
8066 0x1, /* revision number */
8068 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, /* id_auth */
8069 0x1, 0x1, 0x1, 0x1, /* auth[0] */
8070 0x1, 0x1, 0x1, 0x1, /* auth[1] */
8071 0x1, 0x1, 0x1, 0x1, /* auth[2] */
8072 0x1, 0x1, 0x1, 0x1, /* auth[3] */
8073 0x1, 0x1, 0x1, 0x1, /* auth[4] */
8074 0x1, 0x1, 0x1, 0x1, /* auth[5] */
8075 0x1, 0x1, 0x1, 0x1, /* auth[6] */
8076 0x1, 0x1, 0x1, 0x1, /* auth[7] */
8077 0x1, 0x1, 0x1, 0x1, /* auth[8] */
8078 0x1, 0x1, 0x1, 0x1, /* auth[9] */
8079 0x1, 0x1, 0x1, 0x1, /* auth[10] */
8080 0x1, 0x1, 0x1, 0x1, /* auth[11] */
8081 0x1, 0x1, 0x1, 0x1, /* auth[12] */
8082 0x1, 0x1, 0x1, 0x1, /* auth[13] */
8083 0x1, 0x1, 0x1, 0x1, /* auth[14] */
8084 0x1, 0x1, 0x1, 0x1, /* auth[15] */
8085 0x1, 0x1, 0x1, 0x1, /* auth[16] */
8086 0x1, 0x1, 0x1, 0x1, /* auth[17] */
8087 0x1, 0x1, 0x1, 0x1, /* auth[18] */
8088 0x1, 0x1, 0x1, 0x1, /* auth[19] */
8089 0x1, 0x1, 0x1, 0x1, /* auth[20] */
8090 0x1, 0x1, 0x1, 0x1, /* auth[21] */
8091 0x1, 0x1, 0x1, 0x1, /* auth[22] */
8092 0x1, 0x1, 0x1, 0x1, /* auth[23] */
8093 0x1, 0x1, 0x1, 0x1, /* auth[24] */
8094 0x1, 0x1, 0x1, 0x1, /* auth[25] */
8095 0x1, 0x1, 0x1, 0x1, /* auth[26] */
8096 0x1, 0x1, 0x1, 0x1, /* auth[27] */
8097 0x1, 0x1, 0x1, 0x1, /* auth[28] */
8098 0x1, 0x1, 0x1, 0x1, /* auth[29] */
8099 0x1, 0x1, 0x1, 0x1, /* auth[30] */
8100 0x1, 0x1, 0x1, 0x1, /* auth[31] */
8103 if (!sid_parse(good_binary_sid, sizeof(good_binary_sid), sid)) {
8106 if (sid_parse(long_binary_sid2, sizeof(long_binary_sid2), sid)) {
8109 if (sid_parse(long_binary_sid, sizeof(long_binary_sid), sid)) {
8115 /* Split a path name into filename and stream name components. Canonicalise
8116 * such that an implicit $DATA token is always explicit.
8118 * The "specification" of this function can be found in the
8119 * run_local_stream_name() function in torture.c, I've tried those
8120 * combinations against a W2k3 server.
8123 static NTSTATUS split_ntfs_stream_name(TALLOC_CTX *mem_ctx, const char *fname,
8124 char **pbase, char **pstream)
8127 char *stream = NULL;
8128 char *sname; /* stream name */
8129 const char *stype; /* stream type */
8131 DEBUG(10, ("split_ntfs_stream_name called for [%s]\n", fname));
8133 sname = strchr_m(fname, ':');
8135 if (lp_posix_pathnames() || (sname == NULL)) {
8136 if (pbase != NULL) {
8137 base = talloc_strdup(mem_ctx, fname);
8138 NT_STATUS_HAVE_NO_MEMORY(base);
8143 if (pbase != NULL) {
8144 base = talloc_strndup(mem_ctx, fname, PTR_DIFF(sname, fname));
8145 NT_STATUS_HAVE_NO_MEMORY(base);
8150 stype = strchr_m(sname, ':');
8152 if (stype == NULL) {
8153 sname = talloc_strdup(mem_ctx, sname);
8157 if (strcasecmp_m(stype, ":$DATA") != 0) {
8159 * If there is an explicit stream type, so far we only
8160 * allow $DATA. Is there anything else allowed? -- vl
8162 DEBUG(10, ("[%s] is an invalid stream type\n", stype));
8164 return NT_STATUS_OBJECT_NAME_INVALID;
8166 sname = talloc_strndup(mem_ctx, sname, PTR_DIFF(stype, sname));
8170 if (sname == NULL) {
8172 return NT_STATUS_NO_MEMORY;
8175 if (sname[0] == '\0') {
8177 * no stream name, so no stream
8182 if (pstream != NULL) {
8183 stream = talloc_asprintf(mem_ctx, "%s:%s", sname, stype);
8184 if (stream == NULL) {
8187 return NT_STATUS_NO_MEMORY;
8190 * upper-case the type field
8192 strupper_m(strchr_m(stream, ':')+1);
8196 if (pbase != NULL) {
8199 if (pstream != NULL) {
8202 return NT_STATUS_OK;
8205 static bool test_stream_name(const char *fname, const char *expected_base,
8206 const char *expected_stream,
8207 NTSTATUS expected_status)
8211 char *stream = NULL;
8213 status = split_ntfs_stream_name(talloc_tos(), fname, &base, &stream);
8214 if (!NT_STATUS_EQUAL(status, expected_status)) {
8218 if (!NT_STATUS_IS_OK(status)) {
8222 if (base == NULL) goto error;
8224 if (strcmp(expected_base, base) != 0) goto error;
8226 if ((expected_stream != NULL) && (stream == NULL)) goto error;
8227 if ((expected_stream == NULL) && (stream != NULL)) goto error;
8229 if ((stream != NULL) && (strcmp(expected_stream, stream) != 0))
8233 TALLOC_FREE(stream);
8237 d_fprintf(stderr, "Do test_stream(%s, %s, %s, %s)\n",
8238 fname, expected_base ? expected_base : "<NULL>",
8239 expected_stream ? expected_stream : "<NULL>",
8240 nt_errstr(expected_status));
8241 d_fprintf(stderr, "-> base=%s, stream=%s, status=%s\n",
8242 base ? base : "<NULL>", stream ? stream : "<NULL>",
8245 TALLOC_FREE(stream);
8249 static bool run_local_stream_name(int dummy)
8253 ret &= test_stream_name(
8254 "bla", "bla", NULL, NT_STATUS_OK);
8255 ret &= test_stream_name(
8256 "bla::$DATA", "bla", NULL, NT_STATUS_OK);
8257 ret &= test_stream_name(
8258 "bla:blub:", "bla", NULL, NT_STATUS_OBJECT_NAME_INVALID);
8259 ret &= test_stream_name(
8260 "bla::", NULL, NULL, NT_STATUS_OBJECT_NAME_INVALID);
8261 ret &= test_stream_name(
8262 "bla::123", "bla", NULL, NT_STATUS_OBJECT_NAME_INVALID);
8263 ret &= test_stream_name(
8264 "bla:$DATA", "bla", "$DATA:$DATA", NT_STATUS_OK);
8265 ret &= test_stream_name(
8266 "bla:x:$DATA", "bla", "x:$DATA", NT_STATUS_OK);
8267 ret &= test_stream_name(
8268 "bla:x", "bla", "x:$DATA", NT_STATUS_OK);
8273 static bool data_blob_equal(DATA_BLOB a, DATA_BLOB b)
8275 if (a.length != b.length) {
8276 printf("a.length=%d != b.length=%d\n",
8277 (int)a.length, (int)b.length);
8280 if (memcmp(a.data, b.data, a.length) != 0) {
8281 printf("a.data and b.data differ\n");
8287 static bool run_local_memcache(int dummy)
8289 struct memcache *cache;
8291 DATA_BLOB d1, d2, d3;
8292 DATA_BLOB v1, v2, v3;
8294 TALLOC_CTX *mem_ctx;
8296 size_t size1, size2;
8299 cache = memcache_init(NULL, 100);
8301 if (cache == NULL) {
8302 printf("memcache_init failed\n");
8306 d1 = data_blob_const("d1", 2);
8307 d2 = data_blob_const("d2", 2);
8308 d3 = data_blob_const("d3", 2);
8310 k1 = data_blob_const("d1", 2);
8311 k2 = data_blob_const("d2", 2);
8313 memcache_add(cache, STAT_CACHE, k1, d1);
8314 memcache_add(cache, GETWD_CACHE, k2, d2);
8316 if (!memcache_lookup(cache, STAT_CACHE, k1, &v1)) {
8317 printf("could not find k1\n");
8320 if (!data_blob_equal(d1, v1)) {
8324 if (!memcache_lookup(cache, GETWD_CACHE, k2, &v2)) {
8325 printf("could not find k2\n");
8328 if (!data_blob_equal(d2, v2)) {
8332 memcache_add(cache, STAT_CACHE, k1, d3);
8334 if (!memcache_lookup(cache, STAT_CACHE, k1, &v3)) {
8335 printf("could not find replaced k1\n");
8338 if (!data_blob_equal(d3, v3)) {
8342 memcache_add(cache, GETWD_CACHE, k1, d1);
8344 if (memcache_lookup(cache, GETWD_CACHE, k2, &v2)) {
8345 printf("Did find k2, should have been purged\n");
8351 cache = memcache_init(NULL, 0);
8353 mem_ctx = talloc_init("foo");
8355 str1 = talloc_strdup(mem_ctx, "string1");
8356 str2 = talloc_strdup(mem_ctx, "string2");
8358 memcache_add_talloc(cache, SINGLETON_CACHE_TALLOC,
8359 data_blob_string_const("torture"), &str1);
8360 size1 = talloc_total_size(cache);
8362 memcache_add_talloc(cache, SINGLETON_CACHE_TALLOC,
8363 data_blob_string_const("torture"), &str2);
8364 size2 = talloc_total_size(cache);
8366 printf("size1=%d, size2=%d\n", (int)size1, (int)size2);
8368 if (size2 > size1) {
8369 printf("memcache leaks memory!\n");
8379 static void wbclient_done(struct tevent_req *req)
8382 struct winbindd_response *wb_resp;
8383 int *i = (int *)tevent_req_callback_data_void(req);
8385 wbc_err = wb_trans_recv(req, req, &wb_resp);
8388 d_printf("wb_trans_recv %d returned %s\n", *i, wbcErrorString(wbc_err));
8391 static bool run_local_wbclient(int dummy)
8393 struct event_context *ev;
8394 struct wb_context **wb_ctx;
8395 struct winbindd_request wb_req;
8396 bool result = false;
8399 BlockSignals(True, SIGPIPE);
8401 ev = tevent_context_init_byname(talloc_tos(), "epoll");
8406 wb_ctx = talloc_array(ev, struct wb_context *, nprocs);
8407 if (wb_ctx == NULL) {
8411 ZERO_STRUCT(wb_req);
8412 wb_req.cmd = WINBINDD_PING;
8414 d_printf("nprocs=%d, numops=%d\n", (int)nprocs, (int)torture_numops);
8416 for (i=0; i<nprocs; i++) {
8417 wb_ctx[i] = wb_context_init(ev, NULL);
8418 if (wb_ctx[i] == NULL) {
8421 for (j=0; j<torture_numops; j++) {
8422 struct tevent_req *req;
8423 req = wb_trans_send(ev, ev, wb_ctx[i],
8424 (j % 2) == 0, &wb_req);
8428 tevent_req_set_callback(req, wbclient_done, &i);
8434 while (i < nprocs * torture_numops) {
8435 tevent_loop_once(ev);
8444 static void getaddrinfo_finished(struct tevent_req *req)
8446 char *name = (char *)tevent_req_callback_data_void(req);
8447 struct addrinfo *ainfo;
8450 res = getaddrinfo_recv(req, &ainfo);
8452 d_printf("gai(%s) returned %s\n", name, gai_strerror(res));
8455 d_printf("gai(%s) succeeded\n", name);
8456 freeaddrinfo(ainfo);
8459 static bool run_getaddrinfo_send(int dummy)
8461 TALLOC_CTX *frame = talloc_stackframe();
8462 struct fncall_context *ctx;
8463 struct tevent_context *ev;
8464 bool result = false;
8465 const char *names[4] = { "www.samba.org", "notfound.samba.org",
8466 "www.slashdot.org", "heise.de" };
8467 struct tevent_req *reqs[4];
8470 ev = event_context_init(frame);
8475 ctx = fncall_context_init(frame, 4);
8477 for (i=0; i<ARRAY_SIZE(names); i++) {
8478 reqs[i] = getaddrinfo_send(frame, ev, ctx, names[i], NULL,
8480 if (reqs[i] == NULL) {
8483 tevent_req_set_callback(reqs[i], getaddrinfo_finished,
8484 discard_const_p(void, names[i]));
8487 for (i=0; i<ARRAY_SIZE(reqs); i++) {
8488 tevent_loop_once(ev);
8497 static bool dbtrans_inc(struct db_context *db)
8499 struct db_record *rec;
8505 rec = dbwrap_fetch_locked(db, db, string_term_tdb_data("transtest"));
8507 printf(__location__ "fetch_lock failed\n");
8511 value = dbwrap_record_get_value(rec);
8513 if (value.dsize != sizeof(uint32_t)) {
8514 printf(__location__ "value.dsize = %d\n",
8519 val = (uint32_t *)value.dptr;
8522 status = dbwrap_record_store(rec, make_tdb_data((uint8_t *)val,
8525 if (!NT_STATUS_IS_OK(status)) {
8526 printf(__location__ "store failed: %s\n",
8537 static bool run_local_dbtrans(int dummy)
8539 struct db_context *db;
8540 struct db_record *rec;
8546 db = db_open(talloc_tos(), "transtest.tdb", 0, TDB_DEFAULT,
8547 O_RDWR|O_CREAT, 0600);
8549 printf("Could not open transtest.db\n");
8553 res = dbwrap_transaction_start(db);
8555 printf(__location__ "transaction_start failed\n");
8559 rec = dbwrap_fetch_locked(db, db, string_term_tdb_data("transtest"));
8561 printf(__location__ "fetch_lock failed\n");
8565 value = dbwrap_record_get_value(rec);
8567 if (value.dptr == NULL) {
8569 status = dbwrap_record_store(
8570 rec, make_tdb_data((uint8_t *)&initial,
8573 if (!NT_STATUS_IS_OK(status)) {
8574 printf(__location__ "store returned %s\n",
8582 res = dbwrap_transaction_commit(db);
8584 printf(__location__ "transaction_commit failed\n");
8592 res = dbwrap_transaction_start(db);
8594 printf(__location__ "transaction_start failed\n");
8598 status = dbwrap_fetch_uint32(db, "transtest", &val);
8599 if (!NT_STATUS_IS_OK(status)) {
8600 printf(__location__ "dbwrap_fetch_uint32 failed: %s\n",
8605 for (i=0; i<10; i++) {
8606 if (!dbtrans_inc(db)) {
8611 status = dbwrap_fetch_uint32(db, "transtest", &val2);
8612 if (!NT_STATUS_IS_OK(status)) {
8613 printf(__location__ "dbwrap_fetch_uint32 failed: %s\n",
8618 if (val2 != val + 10) {
8619 printf(__location__ "val=%d, val2=%d\n",
8620 (int)val, (int)val2);
8624 printf("val2=%d\r", val2);
8626 res = dbwrap_transaction_commit(db);
8628 printf(__location__ "transaction_commit failed\n");
8638 * Just a dummy test to be run under a debugger. There's no real way
8639 * to inspect the tevent_select specific function from outside of
8643 static bool run_local_tevent_select(int dummy)
8645 struct tevent_context *ev;
8646 struct tevent_fd *fd1, *fd2;
8647 bool result = false;
8649 ev = tevent_context_init_byname(NULL, "select");
8651 d_fprintf(stderr, "tevent_context_init_byname failed\n");
8655 fd1 = tevent_add_fd(ev, ev, 2, 0, NULL, NULL);
8657 d_fprintf(stderr, "tevent_add_fd failed\n");
8660 fd2 = tevent_add_fd(ev, ev, 3, 0, NULL, NULL);
8662 d_fprintf(stderr, "tevent_add_fd failed\n");
8667 fd2 = tevent_add_fd(ev, ev, 1, 0, NULL, NULL);
8669 d_fprintf(stderr, "tevent_add_fd failed\n");
8679 static double create_procs(bool (*fn)(int), bool *result)
8682 volatile pid_t *child_status;
8683 volatile bool *child_status_out;
8686 struct timeval start;
8690 child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*nprocs);
8691 if (!child_status) {
8692 printf("Failed to setup shared memory\n");
8696 child_status_out = (volatile bool *)shm_setup(sizeof(bool)*nprocs);
8697 if (!child_status_out) {
8698 printf("Failed to setup result status shared memory\n");
8702 for (i = 0; i < nprocs; i++) {
8703 child_status[i] = 0;
8704 child_status_out[i] = True;
8707 start = timeval_current();
8709 for (i=0;i<nprocs;i++) {
8712 pid_t mypid = getpid();
8713 sys_srandom(((int)mypid) ^ ((int)time(NULL)));
8715 slprintf(myname,sizeof(myname),"CLIENT%d", i);
8718 if (torture_open_connection(¤t_cli, i)) break;
8720 printf("pid %d failed to start\n", (int)getpid());
8726 child_status[i] = getpid();
8728 while (child_status[i] && timeval_elapsed(&start) < 5) smb_msleep(2);
8730 child_status_out[i] = fn(i);
8737 for (i=0;i<nprocs;i++) {
8738 if (child_status[i]) synccount++;
8740 if (synccount == nprocs) break;
8742 } while (timeval_elapsed(&start) < 30);
8744 if (synccount != nprocs) {
8745 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs, synccount);
8747 return timeval_elapsed(&start);
8750 /* start the client load */
8751 start = timeval_current();
8753 for (i=0;i<nprocs;i++) {
8754 child_status[i] = 0;
8757 printf("%d clients started\n", nprocs);
8759 for (i=0;i<nprocs;i++) {
8760 while (waitpid(0, &status, 0) == -1 && errno == EINTR) /* noop */ ;
8765 for (i=0;i<nprocs;i++) {
8766 if (!child_status_out[i]) {
8770 return timeval_elapsed(&start);
8773 #define FLAG_MULTIPROC 1
8780 {"FDPASS", run_fdpasstest, 0},
8781 {"LOCK1", run_locktest1, 0},
8782 {"LOCK2", run_locktest2, 0},
8783 {"LOCK3", run_locktest3, 0},
8784 {"LOCK4", run_locktest4, 0},
8785 {"LOCK5", run_locktest5, 0},
8786 {"LOCK6", run_locktest6, 0},
8787 {"LOCK7", run_locktest7, 0},
8788 {"LOCK8", run_locktest8, 0},
8789 {"LOCK9", run_locktest9, 0},
8790 {"UNLINK", run_unlinktest, 0},
8791 {"BROWSE", run_browsetest, 0},
8792 {"ATTR", run_attrtest, 0},
8793 {"TRANS2", run_trans2test, 0},
8794 {"MAXFID", run_maxfidtest, FLAG_MULTIPROC},
8795 {"TORTURE",run_torture, FLAG_MULTIPROC},
8796 {"RANDOMIPC", run_randomipc, 0},
8797 {"NEGNOWAIT", run_negprot_nowait, 0},
8798 {"NBENCH", run_nbench, 0},
8799 {"NBENCH2", run_nbench2, 0},
8800 {"OPLOCK1", run_oplock1, 0},
8801 {"OPLOCK2", run_oplock2, 0},
8802 {"OPLOCK4", run_oplock4, 0},
8803 {"DIR", run_dirtest, 0},
8804 {"DIR1", run_dirtest1, 0},
8805 {"DIR-CREATETIME", run_dir_createtime, 0},
8806 {"DENY1", torture_denytest1, 0},
8807 {"DENY2", torture_denytest2, 0},
8808 {"TCON", run_tcon_test, 0},
8809 {"TCONDEV", run_tcon_devtype_test, 0},
8810 {"RW1", run_readwritetest, 0},
8811 {"RW2", run_readwritemulti, FLAG_MULTIPROC},
8812 {"RW3", run_readwritelarge, 0},
8813 {"RW-SIGNING", run_readwritelarge_signtest, 0},
8814 {"OPEN", run_opentest, 0},
8815 {"POSIX", run_simple_posix_open_test, 0},
8816 {"POSIX-APPEND", run_posix_append, 0},
8817 {"CASE-INSENSITIVE-CREATE", run_case_insensitive_create, 0},
8818 {"ASYNC-ECHO", run_async_echo, 0},
8819 { "UID-REGRESSION-TEST", run_uid_regression_test, 0},
8820 { "SHORTNAME-TEST", run_shortname_test, 0},
8821 { "ADDRCHANGE", run_addrchange, 0},
8823 {"OPENATTR", run_openattrtest, 0},
8825 {"XCOPY", run_xcopy, 0},
8826 {"RENAME", run_rename, 0},
8827 {"DELETE", run_deletetest, 0},
8828 {"DELETE-LN", run_deletetest_ln, 0},
8829 {"PROPERTIES", run_properties, 0},
8830 {"MANGLE", torture_mangle, 0},
8831 {"MANGLE1", run_mangle1, 0},
8832 {"W2K", run_w2ktest, 0},
8833 {"TRANS2SCAN", torture_trans2_scan, 0},
8834 {"NTTRANSSCAN", torture_nttrans_scan, 0},
8835 {"UTABLE", torture_utable, 0},
8836 {"CASETABLE", torture_casetable, 0},
8837 {"ERRMAPEXTRACT", run_error_map_extract, 0},
8838 {"PIPE_NUMBER", run_pipe_number, 0},
8839 {"TCON2", run_tcon2_test, 0},
8840 {"IOCTL", torture_ioctl_test, 0},
8841 {"CHKPATH", torture_chkpath_test, 0},
8842 {"FDSESS", run_fdsesstest, 0},
8843 { "EATEST", run_eatest, 0},
8844 { "SESSSETUP_BENCH", run_sesssetup_bench, 0},
8845 { "CHAIN1", run_chain1, 0},
8846 { "CHAIN2", run_chain2, 0},
8847 { "WINDOWS-WRITE", run_windows_write, 0},
8848 { "NTTRANS-CREATE", run_nttrans_create, 0},
8849 { "NTTRANS-FSCTL", run_nttrans_fsctl, 0},
8850 { "CLI_ECHO", run_cli_echo, 0},
8851 { "GETADDRINFO", run_getaddrinfo_send, 0},
8852 { "TLDAP", run_tldap },
8853 { "STREAMERROR", run_streamerror },
8854 { "NOTIFY-BENCH", run_notify_bench },
8855 { "BAD-NBT-SESSION", run_bad_nbt_session },
8856 { "SMB-ANY-CONNECT", run_smb_any_connect },
8857 { "NOTIFY-ONLINE", run_notify_online },
8858 { "SMB2-BASIC", run_smb2_basic },
8859 { "LOCAL-SUBSTITUTE", run_local_substitute, 0},
8860 { "LOCAL-GENCACHE", run_local_gencache, 0},
8861 { "LOCAL-TALLOC-DICT", run_local_talloc_dict, 0},
8862 { "LOCAL-BASE64", run_local_base64, 0},
8863 { "LOCAL-RBTREE", run_local_rbtree, 0},
8864 { "LOCAL-MEMCACHE", run_local_memcache, 0},
8865 { "LOCAL-STREAM-NAME", run_local_stream_name, 0},
8866 { "LOCAL-WBCLIENT", run_local_wbclient, 0},
8867 { "LOCAL-string_to_sid", run_local_string_to_sid, 0},
8868 { "LOCAL-binary_to_sid", run_local_binary_to_sid, 0},
8869 { "LOCAL-DBTRANS", run_local_dbtrans, 0},
8870 { "LOCAL-TEVENT-SELECT", run_local_tevent_select, 0},
8871 { "LOCAL-CONVERT-STRING", run_local_convert_string, 0},
8872 { "LOCAL-CONV-AUTH-INFO", run_local_conv_auth_info, 0},
8877 /****************************************************************************
8878 run a specified test or "ALL"
8879 ****************************************************************************/
8880 static bool run_test(const char *name)
8887 if (strequal(name,"ALL")) {
8888 for (i=0;torture_ops[i].name;i++) {
8889 run_test(torture_ops[i].name);
8894 for (i=0;torture_ops[i].name;i++) {
8895 fstr_sprintf(randomfname, "\\XX%x",
8896 (unsigned)random());
8898 if (strequal(name, torture_ops[i].name)) {
8900 printf("Running %s\n", name);
8901 if (torture_ops[i].flags & FLAG_MULTIPROC) {
8902 t = create_procs(torture_ops[i].fn, &result);
8905 printf("TEST %s FAILED!\n", name);
8908 struct timeval start;
8909 start = timeval_current();
8910 if (!torture_ops[i].fn(0)) {
8912 printf("TEST %s FAILED!\n", name);
8914 t = timeval_elapsed(&start);
8916 printf("%s took %g secs\n\n", name, t);
8921 printf("Did not find a test named %s\n", name);
8929 static void usage(void)
8933 printf("WARNING samba4 test suite is much more complete nowadays.\n");
8934 printf("Please use samba4 torture.\n\n");
8936 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
8938 printf("\t-d debuglevel\n");
8939 printf("\t-U user%%pass\n");
8940 printf("\t-k use kerberos\n");
8941 printf("\t-N numprocs\n");
8942 printf("\t-n my_netbios_name\n");
8943 printf("\t-W workgroup\n");
8944 printf("\t-o num_operations\n");
8945 printf("\t-O socket_options\n");
8946 printf("\t-m maximum protocol\n");
8947 printf("\t-L use oplocks\n");
8948 printf("\t-c CLIENT.TXT specify client load file for NBENCH\n");
8949 printf("\t-A showall\n");
8950 printf("\t-p port\n");
8951 printf("\t-s seed\n");
8952 printf("\t-b unclist_filename specify multiple shares for multiple connections\n");
8953 printf("\t-f filename filename to test\n");
8956 printf("tests are:");
8957 for (i=0;torture_ops[i].name;i++) {
8958 printf(" %s", torture_ops[i].name);
8962 printf("default test is ALL\n");
8967 /****************************************************************************
8969 ****************************************************************************/
8970 int main(int argc,char *argv[])
8976 bool correct = True;
8977 TALLOC_CTX *frame = talloc_stackframe();
8978 int seed = time(NULL);
8980 #ifdef HAVE_SETBUFFER
8981 setbuffer(stdout, NULL, 0);
8984 setup_logging("smbtorture", DEBUG_STDOUT);
8988 if (is_default_dyn_CONFIGFILE()) {
8989 if(getenv("SMB_CONF_PATH")) {
8990 set_dyn_CONFIGFILE(getenv("SMB_CONF_PATH"));
8993 lp_load_global(get_dyn_CONFIGFILE());
9000 for(p = argv[1]; *p; p++)
9004 if (strncmp(argv[1], "//", 2)) {
9008 fstrcpy(host, &argv[1][2]);
9009 p = strchr_m(&host[2],'/');
9014 fstrcpy(share, p+1);
9016 fstrcpy(myname, get_myname(talloc_tos()));
9018 fprintf(stderr, "Failed to get my hostname.\n");
9022 if (*username == 0 && getenv("LOGNAME")) {
9023 fstrcpy(username,getenv("LOGNAME"));
9029 fstrcpy(workgroup, lp_workgroup());
9031 while ((opt = getopt(argc, argv, "p:hW:U:n:N:O:o:m:Ll:d:Aec:ks:b:B:f:"))
9035 port_to_use = atoi(optarg);
9038 seed = atoi(optarg);
9041 fstrcpy(workgroup,optarg);
9044 max_protocol = interpret_protocol(optarg, max_protocol);
9047 nprocs = atoi(optarg);
9050 torture_numops = atoi(optarg);
9053 lp_set_cmdline("log level", optarg);
9062 local_path = optarg;
9065 torture_showall = True;
9068 fstrcpy(myname, optarg);
9071 client_txt = optarg;
9078 use_kerberos = True;
9080 d_printf("No kerberos support compiled in\n");
9086 fstrcpy(username,optarg);
9087 p = strchr_m(username,'%');
9090 fstrcpy(password, p+1);
9095 fstrcpy(multishare_conn_fname, optarg);
9096 use_multishare_conn = True;
9099 torture_blocksize = atoi(optarg);
9102 test_filename = SMB_STRDUP(optarg);
9105 printf("Unknown option %c (%d)\n", (char)opt, opt);
9110 d_printf("using seed %d\n", seed);
9114 if(use_kerberos && !gotuser) gotpass = True;
9117 p = getpass("Password:");
9119 fstrcpy(password, p);
9124 printf("host=%s share=%s user=%s myname=%s\n",
9125 host, share, username, myname);
9127 if (argc == optind) {
9128 correct = run_test("ALL");
9130 for (i=optind;i<argc;i++) {
9131 if (!run_test(argv[i])) {