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 "libsmb/namequery.h"
24 #include "wbc_async.h"
25 #include "torture/proto.h"
26 #include "libcli/security/security.h"
28 #include "tldap_util.h"
29 #include "tldap_gensec_bind.h"
30 #include "../librpc/gen_ndr/svcctl.h"
31 #include "../lib/util/memcache.h"
32 #include "nsswitch/winbind_client.h"
33 #include "dbwrap/dbwrap.h"
34 #include "dbwrap/dbwrap_open.h"
35 #include "dbwrap/dbwrap_rbt.h"
36 #include "async_smb.h"
37 #include "libsmb/libsmb.h"
38 #include "libsmb/clirap.h"
40 #include "libsmb/nmblib.h"
41 #include "../lib/util/tevent_ntstatus.h"
43 #include "../libcli/smb/read_smb.h"
44 #include "../libcli/smb/smbXcli_base.h"
45 #include "lib/util/sys_rw_data.h"
46 #include "lib/util/base64.h"
47 #include "lib/util/time.h"
48 #include "lib/gencache.h"
49 #include "lib/util/sys_rw.h"
50 #include "lib/util/asn1.h"
51 #include "lib/param/param.h"
52 #include "auth/gensec/gensec.h"
54 #include <gnutls/gnutls.h>
55 #include <gnutls/crypto.h>
60 fstring host, workgroup, share, password, username, myname;
61 struct cli_credentials *torture_creds;
62 static const char *sockops="TCP_NODELAY";
64 static int port_to_use=0;
65 int torture_numops=100;
66 int torture_blocksize=1024*1024;
67 static int procnum; /* records process count number when forking */
68 static struct cli_state *current_cli;
69 static fstring randomfname;
70 static bool use_oplocks;
71 static bool use_level_II_oplocks;
72 static const char *client_txt = "client_oplocks.txt";
73 static bool disable_spnego;
74 static bool use_kerberos;
75 static bool force_dos_errors;
76 static fstring multishare_conn_fname;
77 static bool use_multishare_conn = False;
78 static bool do_encrypt;
79 static const char *local_path = NULL;
80 static enum smb_signing_setting signing_state = SMB_SIGNING_DEFAULT;
83 bool torture_showall = False;
85 static double create_procs(bool (*fn)(int), bool *result);
87 /********************************************************************
88 Ensure a connection is encrypted.
89 ********************************************************************/
91 static bool force_cli_encryption(struct cli_state *c,
92 const char *sharename)
94 uint16_t major, minor;
95 uint32_t caplow, caphigh;
98 if (!SERVER_HAS_UNIX_CIFS(c)) {
99 d_printf("Encryption required and "
100 "server that doesn't support "
101 "UNIX extensions - failing connect\n");
105 status = cli_unix_extensions_version(c, &major, &minor, &caplow,
107 if (!NT_STATUS_IS_OK(status)) {
108 d_printf("Encryption required and "
109 "can't get UNIX CIFS extensions "
110 "version from server: %s\n", nt_errstr(status));
114 if (!(caplow & CIFS_UNIX_TRANSPORT_ENCRYPTION_CAP)) {
115 d_printf("Encryption required and "
116 "share %s doesn't support "
117 "encryption.\n", sharename);
121 status = cli_smb1_setup_encryption(c, torture_creds);
122 if (!NT_STATUS_IS_OK(status)) {
123 d_printf("Encryption required and "
124 "setup failed with error %s.\n",
133 static struct cli_state *open_nbt_connection(void)
139 if (disable_spnego) {
140 flags |= CLI_FULL_CONNECTION_DONT_SPNEGO;
144 flags |= CLI_FULL_CONNECTION_OPLOCKS;
147 if (use_level_II_oplocks) {
148 flags |= CLI_FULL_CONNECTION_LEVEL_II_OPLOCKS;
152 flags |= CLI_FULL_CONNECTION_USE_KERBEROS;
155 if (force_dos_errors) {
156 flags |= CLI_FULL_CONNECTION_FORCE_DOS_ERRORS;
159 status = cli_connect_nb(host, NULL, port_to_use, 0x20, myname,
160 signing_state, flags, &c);
161 if (!NT_STATUS_IS_OK(status)) {
162 printf("Failed to connect with %s. Error %s\n", host, nt_errstr(status) );
166 cli_set_timeout(c, 120000); /* set a really long timeout (2 minutes) */
171 /****************************************************************************
172 Send a corrupt session request. See rfc1002.txt 4.3 and 4.3.2.
173 ****************************************************************************/
175 static bool cli_bad_session_request(int fd,
176 struct nmb_name *calling, struct nmb_name *called)
185 uint8_t message_type;
187 struct tevent_context *ev;
188 struct tevent_req *req;
190 frame = talloc_stackframe();
192 iov[0].iov_base = len_buf;
193 iov[0].iov_len = sizeof(len_buf);
195 /* put in the destination name */
197 iov[1].iov_base = name_mangle(talloc_tos(), called->name,
199 if (iov[1].iov_base == NULL) {
202 iov[1].iov_len = name_len((unsigned char *)iov[1].iov_base,
203 talloc_get_size(iov[1].iov_base));
207 iov[2].iov_base = name_mangle(talloc_tos(), calling->name,
209 if (iov[2].iov_base == NULL) {
212 iov[2].iov_len = name_len((unsigned char *)iov[2].iov_base,
213 talloc_get_size(iov[2].iov_base));
215 /* Deliberately corrupt the name len (first byte) */
216 *((uint8_t *)iov[2].iov_base) = 100;
218 /* send a session request (RFC 1002) */
219 /* setup the packet length
220 * Remove four bytes from the length count, since the length
221 * field in the NBT Session Service header counts the number
222 * of bytes which follow. The cli_send_smb() function knows
223 * about this and accounts for those four bytes.
227 _smb_setlen(len_buf, iov[1].iov_len + iov[2].iov_len);
228 SCVAL(len_buf,0,0x81);
230 len = write_data_iov(fd, iov, 3);
235 ev = samba_tevent_context_init(frame);
239 req = read_smb_send(frame, ev, fd);
243 if (!tevent_req_poll(req, ev)) {
246 len = read_smb_recv(req, talloc_tos(), &inbuf, &err);
253 message_type = CVAL(inbuf, 0);
254 if (message_type != 0x83) {
255 d_fprintf(stderr, "Expected msg type 0x83, got 0x%2.2x\n",
260 if (smb_len(inbuf) != 1) {
261 d_fprintf(stderr, "Expected smb_len 1, got %d\n",
262 (int)smb_len(inbuf));
266 error = CVAL(inbuf, 4);
268 d_fprintf(stderr, "Expected error 0x82, got %d\n",
279 /* Insert a NULL at the first separator of the given path and return a pointer
280 * to the remainder of the string.
283 terminate_path_at_separator(char * path)
291 if ((p = strchr_m(path, '/'))) {
296 if ((p = strchr_m(path, '\\'))) {
306 parse a //server/share type UNC name
308 bool smbcli_parse_unc(const char *unc_name, TALLOC_CTX *mem_ctx,
309 char **hostname, char **sharename)
313 *hostname = *sharename = NULL;
315 if (strncmp(unc_name, "\\\\", 2) &&
316 strncmp(unc_name, "//", 2)) {
320 *hostname = talloc_strdup(mem_ctx, &unc_name[2]);
321 p = terminate_path_at_separator(*hostname);
324 *sharename = talloc_strdup(mem_ctx, p);
325 terminate_path_at_separator(*sharename);
328 if (*hostname && *sharename) {
332 TALLOC_FREE(*hostname);
333 TALLOC_FREE(*sharename);
337 static bool torture_open_connection_share(struct cli_state **c,
338 const char *hostname,
339 const char *sharename,
344 status = cli_full_connection_creds(c,
354 if (!NT_STATUS_IS_OK(status)) {
355 printf("failed to open share connection: //%s/%s port:%d - %s\n",
356 hostname, sharename, port_to_use, nt_errstr(status));
360 cli_set_timeout(*c, 120000); /* set a really long timeout (2 minutes) */
363 return force_cli_encryption(*c,
369 bool torture_open_connection_flags(struct cli_state **c, int conn_index, int flags)
371 char **unc_list = NULL;
372 int num_unc_names = 0;
375 if (use_multishare_conn==True) {
377 unc_list = file_lines_load(multishare_conn_fname, &num_unc_names, 0, NULL);
378 if (!unc_list || num_unc_names <= 0) {
379 printf("Failed to load unc names list from '%s'\n", multishare_conn_fname);
383 if (!smbcli_parse_unc(unc_list[conn_index % num_unc_names],
385 printf("Failed to parse UNC name %s\n",
386 unc_list[conn_index % num_unc_names]);
387 TALLOC_FREE(unc_list);
391 result = torture_open_connection_share(c, h, s, flags);
393 /* h, s were copied earlier */
394 TALLOC_FREE(unc_list);
398 return torture_open_connection_share(c, host, share, flags);
401 bool torture_open_connection(struct cli_state **c, int conn_index)
403 int flags = CLI_FULL_CONNECTION_FORCE_SMB1;
406 flags |= CLI_FULL_CONNECTION_OPLOCKS;
408 if (use_level_II_oplocks) {
409 flags |= CLI_FULL_CONNECTION_LEVEL_II_OPLOCKS;
412 return torture_open_connection_flags(c, conn_index, flags);
415 bool torture_init_connection(struct cli_state **pcli)
417 struct cli_state *cli;
419 cli = open_nbt_connection();
428 bool torture_cli_session_setup2(struct cli_state *cli, uint16_t *new_vuid)
430 uint16_t old_vuid = cli_state_get_uid(cli);
434 cli_state_set_uid(cli, 0);
435 status = cli_session_setup_creds(cli, torture_creds);
436 ret = NT_STATUS_IS_OK(status);
437 *new_vuid = cli_state_get_uid(cli);
438 cli_state_set_uid(cli, old_vuid);
443 bool torture_close_connection(struct cli_state *c)
448 status = cli_tdis(c);
449 if (!NT_STATUS_IS_OK(status)) {
450 printf("tdis failed (%s)\n", nt_errstr(status));
460 /* check if the server produced the expected dos or nt error code */
461 static bool check_both_error(int line, NTSTATUS status,
462 uint8_t eclass, uint32_t ecode, NTSTATUS nterr)
464 if (NT_STATUS_IS_DOS(status)) {
468 /* Check DOS error */
469 cclass = NT_STATUS_DOS_CLASS(status);
470 num = NT_STATUS_DOS_CODE(status);
472 if (eclass != cclass || ecode != num) {
473 printf("unexpected error code class=%d code=%d\n",
474 (int)cclass, (int)num);
475 printf(" expected %d/%d %s (line=%d)\n",
476 (int)eclass, (int)ecode, nt_errstr(nterr), line);
481 if (!NT_STATUS_EQUAL(nterr, status)) {
482 printf("unexpected error code %s\n",
484 printf(" expected %s (line=%d)\n",
485 nt_errstr(nterr), line);
494 /* check if the server produced the expected error code */
495 static bool check_error(int line, NTSTATUS status,
496 uint8_t eclass, uint32_t ecode, NTSTATUS nterr)
498 if (NT_STATUS_IS_DOS(status)) {
502 /* Check DOS error */
504 cclass = NT_STATUS_DOS_CLASS(status);
505 num = NT_STATUS_DOS_CODE(status);
507 if (eclass != cclass || ecode != num) {
508 printf("unexpected error code class=%d code=%d\n",
509 (int)cclass, (int)num);
510 printf(" expected %d/%d %s (line=%d)\n",
511 (int)eclass, (int)ecode, nt_errstr(nterr),
519 if (NT_STATUS_V(nterr) != NT_STATUS_V(status)) {
520 printf("unexpected error code %s\n",
522 printf(" expected %s (line=%d)\n", nt_errstr(nterr),
532 static bool wait_lock(struct cli_state *c, int fnum, uint32_t offset, uint32_t len)
536 status = cli_lock32(c, fnum, offset, len, -1, WRITE_LOCK);
538 while (!NT_STATUS_IS_OK(status)) {
539 if (!check_both_error(__LINE__, status, ERRDOS,
540 ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) {
544 status = cli_lock32(c, fnum, offset, len, -1, WRITE_LOCK);
551 static bool rw_torture(struct cli_state *c)
553 const char *lockfname = "\\torture.lck";
557 pid_t pid2, pid = getpid();
564 memset(buf, '\0', sizeof(buf));
566 status = cli_openx(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
568 if (!NT_STATUS_IS_OK(status)) {
569 status = cli_openx(c, lockfname, O_RDWR, DENY_NONE, &fnum2);
571 if (!NT_STATUS_IS_OK(status)) {
572 printf("open of %s failed (%s)\n",
573 lockfname, nt_errstr(status));
577 for (i=0;i<torture_numops;i++) {
578 unsigned n = (unsigned)sys_random()%10;
581 printf("%d\r", i); fflush(stdout);
583 slprintf(fname, sizeof(fstring) - 1, "\\torture.%u", n);
585 if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) {
589 status = cli_openx(c, fname, O_RDWR | O_CREAT | O_TRUNC,
591 if (!NT_STATUS_IS_OK(status)) {
592 printf("open failed (%s)\n", nt_errstr(status));
597 status = cli_writeall(c, fnum, 0, (uint8_t *)&pid, 0,
599 if (!NT_STATUS_IS_OK(status)) {
600 printf("write failed (%s)\n", nt_errstr(status));
605 status = cli_writeall(c, fnum, 0, (uint8_t *)buf,
606 sizeof(pid)+(j*sizeof(buf)),
608 if (!NT_STATUS_IS_OK(status)) {
609 printf("write failed (%s)\n",
617 status = cli_read(c, fnum, (char *)&pid2, 0, sizeof(pid),
619 if (!NT_STATUS_IS_OK(status)) {
620 printf("read failed (%s)\n", nt_errstr(status));
622 } else if (nread != sizeof(pid)) {
623 printf("read/write compare failed: "
624 "recv %ld req %ld\n", (unsigned long)nread,
625 (unsigned long)sizeof(pid));
630 printf("data corruption!\n");
634 status = cli_close(c, fnum);
635 if (!NT_STATUS_IS_OK(status)) {
636 printf("close failed (%s)\n", nt_errstr(status));
640 status = cli_unlink(c, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
641 if (!NT_STATUS_IS_OK(status)) {
642 printf("unlink failed (%s)\n", nt_errstr(status));
646 status = cli_unlock(c, fnum2, n*sizeof(int), sizeof(int));
647 if (!NT_STATUS_IS_OK(status)) {
648 printf("unlock failed (%s)\n", nt_errstr(status));
654 cli_unlink(c, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
661 static bool run_torture(int dummy)
663 struct cli_state *cli;
668 smbXcli_conn_set_sockopt(cli->conn, sockops);
670 ret = rw_torture(cli);
672 if (!torture_close_connection(cli)) {
679 static bool rw_torture3(struct cli_state *c, char *lockfname)
681 uint16_t fnum = (uint16_t)-1;
686 unsigned countprev = 0;
689 NTSTATUS status = NT_STATUS_OK;
692 for (i = 0; i < sizeof(buf); i += sizeof(uint32_t))
694 SIVAL(buf, i, sys_random());
701 FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
702 if (!NT_STATUS_IS_OK(status)) {
703 printf("unlink failed (%s) (normal, this file should "
704 "not exist)\n", nt_errstr(status));
707 status = cli_openx(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
709 if (!NT_STATUS_IS_OK(status)) {
710 printf("first open read/write of %s failed (%s)\n",
711 lockfname, nt_errstr(status));
717 for (i = 0; i < 500 && fnum == (uint16_t)-1; i++)
719 status = cli_openx(c, lockfname, O_RDONLY,
721 if (NT_STATUS_IS_OK(status)) {
726 if (!NT_STATUS_IS_OK(status)) {
727 printf("second open read-only of %s failed (%s)\n",
728 lockfname, nt_errstr(status));
734 for (count = 0; count < sizeof(buf); count += sent)
736 if (count >= countprev) {
737 printf("%d %8d\r", i, count);
740 countprev += (sizeof(buf) / 20);
745 sent = ((unsigned)sys_random()%(20))+ 1;
746 if (sent > sizeof(buf) - count)
748 sent = sizeof(buf) - count;
751 status = cli_writeall(c, fnum, 0, (uint8_t *)buf+count,
753 if (!NT_STATUS_IS_OK(status)) {
754 printf("write failed (%s)\n",
761 status = cli_read(c, fnum, buf_rd+count, count,
762 sizeof(buf)-count, &sent);
763 if(!NT_STATUS_IS_OK(status)) {
764 printf("read failed offset:%d size:%ld (%s)\n",
765 count, (unsigned long)sizeof(buf)-count,
769 } else if (sent > 0) {
770 if (memcmp(buf_rd+count, buf+count, sent) != 0)
772 printf("read/write compare failed\n");
773 printf("offset: %d req %ld recvd %ld\n", count, (unsigned long)sizeof(buf)-count, (unsigned long)sent);
782 status = cli_close(c, fnum);
783 if (!NT_STATUS_IS_OK(status)) {
784 printf("close failed (%s)\n", nt_errstr(status));
791 static bool rw_torture2(struct cli_state *c1, struct cli_state *c2)
793 const char *lockfname = "\\torture2.lck";
803 status = cli_unlink(c1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
804 if (!NT_STATUS_IS_OK(status)) {
805 printf("unlink failed (%s) (normal, this file should not exist)\n", nt_errstr(status));
808 status = cli_openx(c1, lockfname, O_RDWR | O_CREAT | O_EXCL,
810 if (!NT_STATUS_IS_OK(status)) {
811 printf("first open read/write of %s failed (%s)\n",
812 lockfname, nt_errstr(status));
816 status = cli_openx(c2, lockfname, O_RDONLY, DENY_NONE, &fnum2);
817 if (!NT_STATUS_IS_OK(status)) {
818 printf("second open read-only of %s failed (%s)\n",
819 lockfname, nt_errstr(status));
820 cli_close(c1, fnum1);
824 for (i = 0; i < torture_numops; i++)
826 size_t buf_size = ((unsigned)sys_random()%(sizeof(buf)-1))+ 1;
828 printf("%d\r", i); fflush(stdout);
831 generate_random_buffer((unsigned char *)buf, buf_size);
833 status = cli_writeall(c1, fnum1, 0, (uint8_t *)buf, 0,
835 if (!NT_STATUS_IS_OK(status)) {
836 printf("write failed (%s)\n", nt_errstr(status));
841 status = cli_read(c2, fnum2, buf_rd, 0, buf_size, &bytes_read);
842 if(!NT_STATUS_IS_OK(status)) {
843 printf("read failed (%s)\n", nt_errstr(status));
846 } else if (bytes_read != buf_size) {
847 printf("read failed\n");
848 printf("read %ld, expected %ld\n",
849 (unsigned long)bytes_read,
850 (unsigned long)buf_size);
855 if (memcmp(buf_rd, buf, buf_size) != 0)
857 printf("read/write compare failed\n");
863 status = cli_close(c2, fnum2);
864 if (!NT_STATUS_IS_OK(status)) {
865 printf("close failed (%s)\n", nt_errstr(status));
869 status = cli_close(c1, fnum1);
870 if (!NT_STATUS_IS_OK(status)) {
871 printf("close failed (%s)\n", nt_errstr(status));
875 status = cli_unlink(c1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
876 if (!NT_STATUS_IS_OK(status)) {
877 printf("unlink failed (%s)\n", nt_errstr(status));
884 static bool run_readwritetest(int dummy)
886 struct cli_state *cli1, *cli2;
887 bool test1, test2 = False;
889 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
892 smbXcli_conn_set_sockopt(cli1->conn, sockops);
893 smbXcli_conn_set_sockopt(cli2->conn, sockops);
895 printf("starting readwritetest\n");
897 test1 = rw_torture2(cli1, cli2);
898 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1));
901 test2 = rw_torture2(cli1, cli1);
902 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2));
905 if (!torture_close_connection(cli1)) {
909 if (!torture_close_connection(cli2)) {
913 return (test1 && test2);
916 static bool run_readwritemulti(int dummy)
918 struct cli_state *cli;
923 smbXcli_conn_set_sockopt(cli->conn, sockops);
925 printf("run_readwritemulti: fname %s\n", randomfname);
926 test = rw_torture3(cli, randomfname);
928 if (!torture_close_connection(cli)) {
935 static bool run_readwritelarge_internal(void)
937 static struct cli_state *cli1;
939 const char *lockfname = "\\large.dat";
945 if (!torture_open_connection(&cli1, 0)) {
948 smbXcli_conn_set_sockopt(cli1->conn, sockops);
949 memset(buf,'\0',sizeof(buf));
951 printf("starting readwritelarge_internal\n");
953 cli_unlink(cli1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
955 status = cli_openx(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL,
957 if (!NT_STATUS_IS_OK(status)) {
958 printf("open read/write of %s failed (%s)\n", lockfname, nt_errstr(status));
962 cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 0, sizeof(buf), NULL);
964 status = cli_qfileinfo_basic(cli1, fnum1, NULL, &fsize, NULL, NULL,
966 if (!NT_STATUS_IS_OK(status)) {
967 printf("qfileinfo failed (%s)\n", nt_errstr(status));
971 if (fsize == sizeof(buf))
972 printf("readwritelarge_internal test 1 succeeded (size = %lx)\n",
973 (unsigned long)fsize);
975 printf("readwritelarge_internal test 1 failed (size = %lx)\n",
976 (unsigned long)fsize);
980 status = cli_close(cli1, fnum1);
981 if (!NT_STATUS_IS_OK(status)) {
982 printf("close failed (%s)\n", nt_errstr(status));
986 status = cli_unlink(cli1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
987 if (!NT_STATUS_IS_OK(status)) {
988 printf("unlink failed (%s)\n", nt_errstr(status));
992 status = cli_openx(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL,
994 if (!NT_STATUS_IS_OK(status)) {
995 printf("open read/write of %s failed (%s)\n", lockfname, nt_errstr(status));
999 cli_smbwrite(cli1, fnum1, buf, 0, sizeof(buf), NULL);
1001 status = cli_qfileinfo_basic(cli1, fnum1, NULL, &fsize, NULL, NULL,
1003 if (!NT_STATUS_IS_OK(status)) {
1004 printf("qfileinfo failed (%s)\n", nt_errstr(status));
1008 if (fsize == sizeof(buf))
1009 printf("readwritelarge_internal test 2 succeeded (size = %lx)\n",
1010 (unsigned long)fsize);
1012 printf("readwritelarge_internal test 2 failed (size = %lx)\n",
1013 (unsigned long)fsize);
1018 /* ToDo - set allocation. JRA */
1019 if(!cli_set_allocation_size(cli1, fnum1, 0)) {
1020 printf("set allocation size to zero failed (%s)\n", cli_errstr(&cli1));
1023 if (!cli_qfileinfo_basic(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL,
1025 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
1029 printf("readwritelarge test 3 (truncate test) succeeded (size = %x)\n", fsize);
1032 status = cli_close(cli1, fnum1);
1033 if (!NT_STATUS_IS_OK(status)) {
1034 printf("close failed (%s)\n", nt_errstr(status));
1038 if (!torture_close_connection(cli1)) {
1044 static bool run_readwritelarge(int dummy)
1046 return run_readwritelarge_internal();
1049 static bool run_readwritelarge_signtest(int dummy)
1052 signing_state = SMB_SIGNING_REQUIRED;
1053 ret = run_readwritelarge_internal();
1054 signing_state = SMB_SIGNING_DEFAULT;
1061 #define ival(s) strtol(s, NULL, 0)
1063 /* run a test that simulates an approximate netbench client load */
1064 static bool run_netbench(int client)
1066 struct cli_state *cli;
1071 const char *params[20];
1072 bool correct = True;
1078 smbXcli_conn_set_sockopt(cli->conn, sockops);
1082 slprintf(cname,sizeof(cname)-1, "client%d", client);
1084 f = fopen(client_txt, "r");
1091 while (fgets(line, sizeof(line)-1, f)) {
1095 line[strlen(line)-1] = 0;
1097 /* printf("[%d] %s\n", line_count, line); */
1099 all_string_sub(line,"client1", cname, sizeof(line));
1101 /* parse the command parameters */
1102 params[0] = strtok_r(line, " ", &saveptr);
1104 while (params[i]) params[++i] = strtok_r(NULL, " ", &saveptr);
1108 if (i < 2) continue;
1110 if (!strncmp(params[0],"SMB", 3)) {
1111 printf("ERROR: You are using a dbench 1 load file\n");
1115 if (!strcmp(params[0],"NTCreateX")) {
1116 nb_createx(params[1], ival(params[2]), ival(params[3]),
1118 } else if (!strcmp(params[0],"Close")) {
1119 nb_close(ival(params[1]));
1120 } else if (!strcmp(params[0],"Rename")) {
1121 nb_rename(params[1], params[2]);
1122 } else if (!strcmp(params[0],"Unlink")) {
1123 nb_unlink(params[1]);
1124 } else if (!strcmp(params[0],"Deltree")) {
1125 nb_deltree(params[1]);
1126 } else if (!strcmp(params[0],"Rmdir")) {
1127 nb_rmdir(params[1]);
1128 } else if (!strcmp(params[0],"QUERY_PATH_INFORMATION")) {
1129 nb_qpathinfo(params[1]);
1130 } else if (!strcmp(params[0],"QUERY_FILE_INFORMATION")) {
1131 nb_qfileinfo(ival(params[1]));
1132 } else if (!strcmp(params[0],"QUERY_FS_INFORMATION")) {
1133 nb_qfsinfo(ival(params[1]));
1134 } else if (!strcmp(params[0],"FIND_FIRST")) {
1135 nb_findfirst(params[1]);
1136 } else if (!strcmp(params[0],"WriteX")) {
1137 nb_writex(ival(params[1]),
1138 ival(params[2]), ival(params[3]), ival(params[4]));
1139 } else if (!strcmp(params[0],"ReadX")) {
1140 nb_readx(ival(params[1]),
1141 ival(params[2]), ival(params[3]), ival(params[4]));
1142 } else if (!strcmp(params[0],"Flush")) {
1143 nb_flush(ival(params[1]));
1145 printf("Unknown operation %s\n", params[0]);
1153 if (!torture_close_connection(cli)) {
1161 /* run a test that simulates an approximate netbench client load */
1162 static bool run_nbench(int dummy)
1165 bool correct = True;
1167 nbio_shmem(torture_nprocs);
1171 signal(SIGALRM, nb_alarm);
1173 t = create_procs(run_netbench, &correct);
1176 printf("\nThroughput %g MB/sec\n",
1177 1.0e-6 * nbio_total() / t);
1183 This test checks for two things:
1185 1) correct support for retaining locks over a close (ie. the server
1186 must not use posix semantics)
1187 2) support for lock timeouts
1189 static bool run_locktest1(int dummy)
1191 struct cli_state *cli1, *cli2;
1192 const char *fname = "\\lockt1.lck";
1193 uint16_t fnum1, fnum2, fnum3;
1195 unsigned lock_timeout;
1198 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1201 smbXcli_conn_set_sockopt(cli1->conn, sockops);
1202 smbXcli_conn_set_sockopt(cli2->conn, sockops);
1204 printf("starting locktest1\n");
1206 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1208 status = cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
1210 if (!NT_STATUS_IS_OK(status)) {
1211 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
1215 status = cli_openx(cli1, fname, O_RDWR, DENY_NONE, &fnum2);
1216 if (!NT_STATUS_IS_OK(status)) {
1217 printf("open2 of %s failed (%s)\n", fname, nt_errstr(status));
1221 status = cli_openx(cli2, fname, O_RDWR, DENY_NONE, &fnum3);
1222 if (!NT_STATUS_IS_OK(status)) {
1223 printf("open3 of %s failed (%s)\n", fname, nt_errstr(status));
1227 status = cli_lock32(cli1, fnum1, 0, 4, 0, WRITE_LOCK);
1228 if (!NT_STATUS_IS_OK(status)) {
1229 printf("lock1 failed (%s)\n", nt_errstr(status));
1233 status = cli_lock32(cli2, fnum3, 0, 4, 0, WRITE_LOCK);
1234 if (NT_STATUS_IS_OK(status)) {
1235 printf("lock2 succeeded! This is a locking bug\n");
1238 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1239 NT_STATUS_LOCK_NOT_GRANTED)) {
1244 lock_timeout = (1 + (random() % 20));
1245 printf("Testing lock timeout with timeout=%u\n", lock_timeout);
1247 status = cli_lock32(cli2, fnum3, 0, 4, lock_timeout * 1000, WRITE_LOCK);
1248 if (NT_STATUS_IS_OK(status)) {
1249 printf("lock3 succeeded! This is a locking bug\n");
1252 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1253 NT_STATUS_FILE_LOCK_CONFLICT)) {
1259 if (ABS(t2 - t1) < lock_timeout-1) {
1260 printf("error: This server appears not to support timed lock requests\n");
1263 printf("server slept for %u seconds for a %u second timeout\n",
1264 (unsigned int)(t2-t1), lock_timeout);
1266 status = cli_close(cli1, fnum2);
1267 if (!NT_STATUS_IS_OK(status)) {
1268 printf("close1 failed (%s)\n", nt_errstr(status));
1272 status = cli_lock32(cli2, fnum3, 0, 4, 0, WRITE_LOCK);
1273 if (NT_STATUS_IS_OK(status)) {
1274 printf("lock4 succeeded! This is a locking bug\n");
1277 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1278 NT_STATUS_FILE_LOCK_CONFLICT)) {
1283 status = cli_close(cli1, fnum1);
1284 if (!NT_STATUS_IS_OK(status)) {
1285 printf("close2 failed (%s)\n", nt_errstr(status));
1289 status = cli_close(cli2, fnum3);
1290 if (!NT_STATUS_IS_OK(status)) {
1291 printf("close3 failed (%s)\n", nt_errstr(status));
1295 status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1296 if (!NT_STATUS_IS_OK(status)) {
1297 printf("unlink failed (%s)\n", nt_errstr(status));
1302 if (!torture_close_connection(cli1)) {
1306 if (!torture_close_connection(cli2)) {
1310 printf("Passed locktest1\n");
1315 this checks to see if a secondary tconx can use open files from an
1318 static bool run_tcon_test(int dummy)
1320 static struct cli_state *cli;
1321 const char *fname = "\\tcontest.tmp";
1323 uint32_t cnum1, cnum2, cnum3;
1324 struct smbXcli_tcon *orig_tcon = NULL;
1325 uint16_t vuid1, vuid2;
1330 memset(buf, '\0', sizeof(buf));
1332 if (!torture_open_connection(&cli, 0)) {
1335 smbXcli_conn_set_sockopt(cli->conn, sockops);
1337 printf("starting tcontest\n");
1339 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1341 status = cli_openx(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
1342 if (!NT_STATUS_IS_OK(status)) {
1343 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
1347 cnum1 = cli_state_get_tid(cli);
1348 vuid1 = cli_state_get_uid(cli);
1350 status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
1351 if (!NT_STATUS_IS_OK(status)) {
1352 printf("initial write failed (%s)", nt_errstr(status));
1356 orig_tcon = cli_state_save_tcon(cli);
1357 if (orig_tcon == NULL) {
1361 status = cli_tree_connect_creds(cli, share, "?????", torture_creds);
1362 if (!NT_STATUS_IS_OK(status)) {
1363 printf("%s refused 2nd tree connect (%s)\n", host,
1369 cnum2 = cli_state_get_tid(cli);
1370 cnum3 = MAX(cnum1, cnum2) + 1; /* any invalid number */
1371 vuid2 = cli_state_get_uid(cli) + 1;
1373 /* try a write with the wrong tid */
1374 cli_state_set_tid(cli, cnum2);
1376 status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
1377 if (NT_STATUS_IS_OK(status)) {
1378 printf("* server allows write with wrong TID\n");
1381 printf("server fails write with wrong TID : %s\n",
1386 /* try a write with an invalid tid */
1387 cli_state_set_tid(cli, cnum3);
1389 status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
1390 if (NT_STATUS_IS_OK(status)) {
1391 printf("* server allows write with invalid TID\n");
1394 printf("server fails write with invalid TID : %s\n",
1398 /* try a write with an invalid vuid */
1399 cli_state_set_uid(cli, vuid2);
1400 cli_state_set_tid(cli, cnum1);
1402 status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
1403 if (NT_STATUS_IS_OK(status)) {
1404 printf("* server allows write with invalid VUID\n");
1407 printf("server fails write with invalid VUID : %s\n",
1411 cli_state_set_tid(cli, cnum1);
1412 cli_state_set_uid(cli, vuid1);
1414 status = cli_close(cli, fnum1);
1415 if (!NT_STATUS_IS_OK(status)) {
1416 printf("close failed (%s)\n", nt_errstr(status));
1420 cli_state_set_tid(cli, cnum2);
1422 status = cli_tdis(cli);
1423 if (!NT_STATUS_IS_OK(status)) {
1424 printf("secondary tdis failed (%s)\n", nt_errstr(status));
1428 cli_state_restore_tcon(cli, orig_tcon);
1430 cli_state_set_tid(cli, cnum1);
1432 if (!torture_close_connection(cli)) {
1441 checks for old style tcon support
1443 static bool run_tcon2_test(int dummy)
1445 static struct cli_state *cli;
1446 uint16_t cnum, max_xmit;
1450 if (!torture_open_connection(&cli, 0)) {
1453 smbXcli_conn_set_sockopt(cli->conn, sockops);
1455 printf("starting tcon2 test\n");
1457 if (asprintf(&service, "\\\\%s\\%s", host, share) == -1) {
1461 status = cli_raw_tcon(cli, service, password, "?????", &max_xmit, &cnum);
1465 if (!NT_STATUS_IS_OK(status)) {
1466 printf("tcon2 failed : %s\n", nt_errstr(status));
1468 printf("tcon OK : max_xmit=%d cnum=%d\n",
1469 (int)max_xmit, (int)cnum);
1472 if (!torture_close_connection(cli)) {
1476 printf("Passed tcon2 test\n");
1480 static bool tcon_devtest(struct cli_state *cli,
1481 const char *myshare, const char *devtype,
1482 const char *return_devtype,
1483 NTSTATUS expected_error)
1488 status = cli_tree_connect_creds(cli, myshare, devtype, torture_creds);
1490 if (NT_STATUS_IS_OK(expected_error)) {
1491 if (NT_STATUS_IS_OK(status)) {
1492 if (return_devtype != NULL &&
1493 strequal(cli->dev, return_devtype)) {
1496 printf("tconX to share %s with type %s "
1497 "succeeded but returned the wrong "
1498 "device type (got [%s] but should have got [%s])\n",
1499 myshare, devtype, cli->dev, return_devtype);
1503 printf("tconX to share %s with type %s "
1504 "should have succeeded but failed\n",
1510 if (NT_STATUS_IS_OK(status)) {
1511 printf("tconx to share %s with type %s "
1512 "should have failed but succeeded\n",
1516 if (NT_STATUS_EQUAL(status, expected_error)) {
1519 printf("Returned unexpected error\n");
1528 checks for correct tconX support
1530 static bool run_tcon_devtype_test(int dummy)
1532 static struct cli_state *cli1 = NULL;
1533 int flags = CLI_FULL_CONNECTION_FORCE_SMB1;
1537 status = cli_full_connection_creds(&cli1,
1543 NULL, /* service_type */
1548 if (!NT_STATUS_IS_OK(status)) {
1549 printf("could not open connection\n");
1553 if (!tcon_devtest(cli1, "IPC$", "A:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1556 if (!tcon_devtest(cli1, "IPC$", "?????", "IPC", NT_STATUS_OK))
1559 if (!tcon_devtest(cli1, "IPC$", "LPT:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1562 if (!tcon_devtest(cli1, "IPC$", "IPC", "IPC", NT_STATUS_OK))
1565 if (!tcon_devtest(cli1, "IPC$", "FOOBA", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1568 if (!tcon_devtest(cli1, share, "A:", "A:", NT_STATUS_OK))
1571 if (!tcon_devtest(cli1, share, "?????", "A:", NT_STATUS_OK))
1574 if (!tcon_devtest(cli1, share, "LPT:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1577 if (!tcon_devtest(cli1, share, "IPC", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1580 if (!tcon_devtest(cli1, share, "FOOBA", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1586 printf("Passed tcondevtest\n");
1593 This test checks that
1595 1) the server supports multiple locking contexts on the one SMB
1596 connection, distinguished by PID.
1598 2) the server correctly fails overlapping locks made by the same PID (this
1599 goes against POSIX behaviour, which is why it is tricky to implement)
1601 3) the server denies unlock requests by an incorrect client PID
1603 static bool run_locktest2(int dummy)
1605 static struct cli_state *cli;
1606 const char *fname = "\\lockt2.lck";
1607 uint16_t fnum1, fnum2, fnum3;
1608 bool correct = True;
1611 if (!torture_open_connection(&cli, 0)) {
1615 smbXcli_conn_set_sockopt(cli->conn, sockops);
1617 printf("starting locktest2\n");
1619 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1623 status = cli_openx(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
1624 if (!NT_STATUS_IS_OK(status)) {
1625 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
1629 status = cli_openx(cli, fname, O_RDWR, DENY_NONE, &fnum2);
1630 if (!NT_STATUS_IS_OK(status)) {
1631 printf("open2 of %s failed (%s)\n", fname, nt_errstr(status));
1637 status = cli_openx(cli, fname, O_RDWR, DENY_NONE, &fnum3);
1638 if (!NT_STATUS_IS_OK(status)) {
1639 printf("open3 of %s failed (%s)\n", fname, nt_errstr(status));
1645 status = cli_lock32(cli, fnum1, 0, 4, 0, WRITE_LOCK);
1646 if (!NT_STATUS_IS_OK(status)) {
1647 printf("lock1 failed (%s)\n", nt_errstr(status));
1651 status = cli_lock32(cli, fnum1, 0, 4, 0, WRITE_LOCK);
1652 if (NT_STATUS_IS_OK(status)) {
1653 printf("WRITE lock1 succeeded! This is a locking bug\n");
1656 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1657 NT_STATUS_LOCK_NOT_GRANTED)) {
1662 status = cli_lock32(cli, fnum2, 0, 4, 0, WRITE_LOCK);
1663 if (NT_STATUS_IS_OK(status)) {
1664 printf("WRITE lock2 succeeded! This is a locking bug\n");
1667 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1668 NT_STATUS_LOCK_NOT_GRANTED)) {
1673 status = cli_lock32(cli, fnum2, 0, 4, 0, READ_LOCK);
1674 if (NT_STATUS_IS_OK(status)) {
1675 printf("READ lock2 succeeded! This is a locking bug\n");
1678 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1679 NT_STATUS_FILE_LOCK_CONFLICT)) {
1684 status = cli_lock32(cli, fnum1, 100, 4, 0, WRITE_LOCK);
1685 if (!NT_STATUS_IS_OK(status)) {
1686 printf("lock at 100 failed (%s)\n", nt_errstr(status));
1689 if (NT_STATUS_IS_OK(cli_unlock(cli, fnum1, 100, 4))) {
1690 printf("unlock at 100 succeeded! This is a locking bug\n");
1694 status = cli_unlock(cli, fnum1, 0, 4);
1695 if (NT_STATUS_IS_OK(status)) {
1696 printf("unlock1 succeeded! This is a locking bug\n");
1699 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1700 NT_STATUS_RANGE_NOT_LOCKED)) {
1705 status = cli_unlock(cli, fnum1, 0, 8);
1706 if (NT_STATUS_IS_OK(status)) {
1707 printf("unlock2 succeeded! This is a locking bug\n");
1710 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1711 NT_STATUS_RANGE_NOT_LOCKED)) {
1716 status = cli_lock32(cli, fnum3, 0, 4, 0, WRITE_LOCK);
1717 if (NT_STATUS_IS_OK(status)) {
1718 printf("lock3 succeeded! This is a locking bug\n");
1721 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1722 NT_STATUS_LOCK_NOT_GRANTED)) {
1729 status = cli_close(cli, fnum1);
1730 if (!NT_STATUS_IS_OK(status)) {
1731 printf("close1 failed (%s)\n", nt_errstr(status));
1735 status = cli_close(cli, fnum2);
1736 if (!NT_STATUS_IS_OK(status)) {
1737 printf("close2 failed (%s)\n", nt_errstr(status));
1741 status = cli_close(cli, fnum3);
1742 if (!NT_STATUS_IS_OK(status)) {
1743 printf("close3 failed (%s)\n", nt_errstr(status));
1747 if (!torture_close_connection(cli)) {
1751 printf("locktest2 finished\n");
1758 This test checks that
1760 1) the server supports the full offset range in lock requests
1762 static bool run_locktest3(int dummy)
1764 static struct cli_state *cli1, *cli2;
1765 const char *fname = "\\lockt3.lck";
1766 uint16_t fnum1, fnum2;
1769 bool correct = True;
1772 #define NEXT_OFFSET offset += (~(uint32_t)0) / torture_numops
1774 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1777 smbXcli_conn_set_sockopt(cli1->conn, sockops);
1778 smbXcli_conn_set_sockopt(cli2->conn, sockops);
1780 printf("starting locktest3\n");
1782 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1784 status = cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
1786 if (!NT_STATUS_IS_OK(status)) {
1787 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
1791 status = cli_openx(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
1792 if (!NT_STATUS_IS_OK(status)) {
1793 printf("open2 of %s failed (%s)\n", fname, nt_errstr(status));
1797 for (offset=i=0;i<torture_numops;i++) {
1800 status = cli_lock32(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK);
1801 if (!NT_STATUS_IS_OK(status)) {
1802 printf("lock1 %d failed (%s)\n",
1808 status = cli_lock32(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK);
1809 if (!NT_STATUS_IS_OK(status)) {
1810 printf("lock2 %d failed (%s)\n",
1817 for (offset=i=0;i<torture_numops;i++) {
1820 status = cli_lock32(cli1, fnum1, offset-2, 1, 0, WRITE_LOCK);
1821 if (NT_STATUS_IS_OK(status)) {
1822 printf("error: lock1 %d succeeded!\n", i);
1826 status = cli_lock32(cli2, fnum2, offset-1, 1, 0, WRITE_LOCK);
1827 if (NT_STATUS_IS_OK(status)) {
1828 printf("error: lock2 %d succeeded!\n", i);
1832 status = cli_lock32(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK);
1833 if (NT_STATUS_IS_OK(status)) {
1834 printf("error: lock3 %d succeeded!\n", i);
1838 status = cli_lock32(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK);
1839 if (NT_STATUS_IS_OK(status)) {
1840 printf("error: lock4 %d succeeded!\n", i);
1845 for (offset=i=0;i<torture_numops;i++) {
1848 status = cli_unlock(cli1, fnum1, offset-1, 1);
1849 if (!NT_STATUS_IS_OK(status)) {
1850 printf("unlock1 %d failed (%s)\n",
1856 status = cli_unlock(cli2, fnum2, offset-2, 1);
1857 if (!NT_STATUS_IS_OK(status)) {
1858 printf("unlock2 %d failed (%s)\n",
1865 status = cli_close(cli1, fnum1);
1866 if (!NT_STATUS_IS_OK(status)) {
1867 printf("close1 failed (%s)\n", nt_errstr(status));
1871 status = cli_close(cli2, fnum2);
1872 if (!NT_STATUS_IS_OK(status)) {
1873 printf("close2 failed (%s)\n", nt_errstr(status));
1877 status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1878 if (!NT_STATUS_IS_OK(status)) {
1879 printf("unlink failed (%s)\n", nt_errstr(status));
1883 if (!torture_close_connection(cli1)) {
1887 if (!torture_close_connection(cli2)) {
1891 printf("finished locktest3\n");
1896 static bool test_cli_read(struct cli_state *cli, uint16_t fnum,
1897 char *buf, off_t offset, size_t size,
1898 size_t *nread, size_t expect)
1903 status = cli_read(cli, fnum, buf, offset, size, &l_nread);
1905 if(!NT_STATUS_IS_OK(status)) {
1907 } else if (l_nread != expect) {
1918 #define EXPECTED(ret, v) if ((ret) != (v)) { \
1919 printf("** "); correct = False; \
1923 looks at overlapping locks
1925 static bool run_locktest4(int dummy)
1927 static struct cli_state *cli1, *cli2;
1928 const char *fname = "\\lockt4.lck";
1929 uint16_t fnum1, fnum2, f;
1932 bool correct = True;
1935 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1939 smbXcli_conn_set_sockopt(cli1->conn, sockops);
1940 smbXcli_conn_set_sockopt(cli2->conn, sockops);
1942 printf("starting locktest4\n");
1944 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1946 cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
1947 cli_openx(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
1949 memset(buf, 0, sizeof(buf));
1951 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 0, sizeof(buf),
1953 if (!NT_STATUS_IS_OK(status)) {
1954 printf("Failed to create file: %s\n", nt_errstr(status));
1959 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) &&
1960 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 2, 4, 0, WRITE_LOCK));
1961 EXPECTED(ret, False);
1962 printf("the same process %s set overlapping write locks\n", ret?"can":"cannot");
1964 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 10, 4, 0, READ_LOCK)) &&
1965 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 12, 4, 0, READ_LOCK));
1966 EXPECTED(ret, True);
1967 printf("the same process %s set overlapping read locks\n", ret?"can":"cannot");
1969 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 20, 4, 0, WRITE_LOCK)) &&
1970 NT_STATUS_IS_OK(cli_lock32(cli2, fnum2, 22, 4, 0, WRITE_LOCK));
1971 EXPECTED(ret, False);
1972 printf("a different connection %s set overlapping write locks\n", ret?"can":"cannot");
1974 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 30, 4, 0, READ_LOCK)) &&
1975 NT_STATUS_IS_OK(cli_lock32(cli2, fnum2, 32, 4, 0, READ_LOCK));
1976 EXPECTED(ret, True);
1977 printf("a different connection %s set overlapping read locks\n", ret?"can":"cannot");
1979 ret = (cli_setpid(cli1, 1),
1980 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 40, 4, 0, WRITE_LOCK))) &&
1981 (cli_setpid(cli1, 2),
1982 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 42, 4, 0, WRITE_LOCK)));
1983 EXPECTED(ret, False);
1984 printf("a different pid %s set overlapping write locks\n", ret?"can":"cannot");
1986 ret = (cli_setpid(cli1, 1),
1987 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 50, 4, 0, READ_LOCK))) &&
1988 (cli_setpid(cli1, 2),
1989 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 52, 4, 0, READ_LOCK)));
1990 EXPECTED(ret, True);
1991 printf("a different pid %s set overlapping read locks\n", ret?"can":"cannot");
1993 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 60, 4, 0, READ_LOCK)) &&
1994 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 60, 4, 0, READ_LOCK));
1995 EXPECTED(ret, True);
1996 printf("the same process %s set the same read lock twice\n", ret?"can":"cannot");
1998 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 70, 4, 0, WRITE_LOCK)) &&
1999 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 70, 4, 0, WRITE_LOCK));
2000 EXPECTED(ret, False);
2001 printf("the same process %s set the same write lock twice\n", ret?"can":"cannot");
2003 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 80, 4, 0, READ_LOCK)) &&
2004 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 80, 4, 0, WRITE_LOCK));
2005 EXPECTED(ret, False);
2006 printf("the same process %s overlay a read lock with a write lock\n", ret?"can":"cannot");
2008 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 90, 4, 0, WRITE_LOCK)) &&
2009 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 90, 4, 0, READ_LOCK));
2010 EXPECTED(ret, True);
2011 printf("the same process %s overlay a write lock with a read lock\n", ret?"can":"cannot");
2013 ret = (cli_setpid(cli1, 1),
2014 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 100, 4, 0, WRITE_LOCK))) &&
2015 (cli_setpid(cli1, 2),
2016 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 100, 4, 0, READ_LOCK)));
2017 EXPECTED(ret, False);
2018 printf("a different pid %s overlay a write lock with a read lock\n", ret?"can":"cannot");
2020 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 110, 4, 0, READ_LOCK)) &&
2021 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 112, 4, 0, READ_LOCK)) &&
2022 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 110, 6));
2023 EXPECTED(ret, False);
2024 printf("the same process %s coalesce read locks\n", ret?"can":"cannot");
2027 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 120, 4, 0, WRITE_LOCK)) &&
2028 test_cli_read(cli2, fnum2, buf, 120, 4, NULL, 4);
2029 EXPECTED(ret, False);
2030 printf("this server %s strict write locking\n", ret?"doesn't do":"does");
2032 status = cli_lock32(cli1, fnum1, 130, 4, 0, READ_LOCK);
2033 ret = NT_STATUS_IS_OK(status);
2035 status = cli_writeall(cli2, fnum2, 0, (uint8_t *)buf, 130, 4,
2037 ret = NT_STATUS_IS_OK(status);
2039 EXPECTED(ret, False);
2040 printf("this server %s strict read locking\n", ret?"doesn't do":"does");
2043 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 140, 4, 0, READ_LOCK)) &&
2044 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 140, 4, 0, READ_LOCK)) &&
2045 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 140, 4)) &&
2046 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 140, 4));
2047 EXPECTED(ret, True);
2048 printf("this server %s do recursive read locking\n", ret?"does":"doesn't");
2051 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 150, 4, 0, WRITE_LOCK)) &&
2052 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 150, 4, 0, READ_LOCK)) &&
2053 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 150, 4)) &&
2054 test_cli_read(cli2, fnum2, buf, 150, 4, NULL, 4) &&
2055 !(NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf,
2057 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 150, 4));
2058 EXPECTED(ret, True);
2059 printf("this server %s do recursive lock overlays\n", ret?"does":"doesn't");
2061 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 160, 4, 0, READ_LOCK)) &&
2062 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 160, 4)) &&
2063 NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf,
2065 test_cli_read(cli2, fnum2, buf, 160, 4, NULL, 4);
2066 EXPECTED(ret, True);
2067 printf("the same process %s remove a read lock using write locking\n", ret?"can":"cannot");
2069 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 170, 4, 0, WRITE_LOCK)) &&
2070 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 170, 4)) &&
2071 NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf,
2073 test_cli_read(cli2, fnum2, buf, 170, 4, NULL, 4);
2074 EXPECTED(ret, True);
2075 printf("the same process %s remove a write lock using read locking\n", ret?"can":"cannot");
2077 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 190, 4, 0, WRITE_LOCK)) &&
2078 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 190, 4, 0, READ_LOCK)) &&
2079 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 190, 4)) &&
2080 !NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf,
2082 test_cli_read(cli2, fnum2, buf, 190, 4, NULL, 4);
2083 EXPECTED(ret, True);
2084 printf("the same process %s remove the first lock first\n", ret?"does":"doesn't");
2086 cli_close(cli1, fnum1);
2087 cli_close(cli2, fnum2);
2088 cli_openx(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
2089 cli_openx(cli1, fname, O_RDWR, DENY_NONE, &f);
2090 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 8, 0, READ_LOCK)) &&
2091 NT_STATUS_IS_OK(cli_lock32(cli1, f, 0, 1, 0, READ_LOCK)) &&
2092 NT_STATUS_IS_OK(cli_close(cli1, fnum1)) &&
2093 NT_STATUS_IS_OK(cli_openx(cli1, fname, O_RDWR, DENY_NONE, &fnum1)) &&
2094 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 7, 1, 0, WRITE_LOCK));
2096 cli_close(cli1, fnum1);
2097 EXPECTED(ret, True);
2098 printf("the server %s have the NT byte range lock bug\n", !ret?"does":"doesn't");
2101 cli_close(cli1, fnum1);
2102 cli_close(cli2, fnum2);
2103 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2104 torture_close_connection(cli1);
2105 torture_close_connection(cli2);
2107 printf("finished locktest4\n");
2112 looks at lock upgrade/downgrade.
2114 static bool run_locktest5(int dummy)
2116 static struct cli_state *cli1, *cli2;
2117 const char *fname = "\\lockt5.lck";
2118 uint16_t fnum1, fnum2, fnum3;
2121 bool correct = True;
2124 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
2128 smbXcli_conn_set_sockopt(cli1->conn, sockops);
2129 smbXcli_conn_set_sockopt(cli2->conn, sockops);
2131 printf("starting locktest5\n");
2133 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2135 cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
2136 cli_openx(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
2137 cli_openx(cli1, fname, O_RDWR, DENY_NONE, &fnum3);
2139 memset(buf, 0, sizeof(buf));
2141 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 0, sizeof(buf),
2143 if (!NT_STATUS_IS_OK(status)) {
2144 printf("Failed to create file: %s\n", nt_errstr(status));
2149 /* Check for NT bug... */
2150 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 8, 0, READ_LOCK)) &&
2151 NT_STATUS_IS_OK(cli_lock32(cli1, fnum3, 0, 1, 0, READ_LOCK));
2152 cli_close(cli1, fnum1);
2153 cli_openx(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
2154 status = cli_lock32(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
2155 ret = NT_STATUS_IS_OK(status);
2156 EXPECTED(ret, True);
2157 printf("this server %s the NT locking bug\n", ret ? "doesn't have" : "has");
2158 cli_close(cli1, fnum1);
2159 cli_openx(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
2160 cli_unlock(cli1, fnum3, 0, 1);
2162 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) &&
2163 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 1, 1, 0, READ_LOCK));
2164 EXPECTED(ret, True);
2165 printf("the same process %s overlay a write with a read lock\n", ret?"can":"cannot");
2167 status = cli_lock32(cli2, fnum2, 0, 4, 0, READ_LOCK);
2168 ret = NT_STATUS_IS_OK(status);
2169 EXPECTED(ret, False);
2171 printf("a different process %s get a read lock on the first process lock stack\n", ret?"can":"cannot");
2173 /* Unlock the process 2 lock. */
2174 cli_unlock(cli2, fnum2, 0, 4);
2176 status = cli_lock32(cli1, fnum3, 0, 4, 0, READ_LOCK);
2177 ret = NT_STATUS_IS_OK(status);
2178 EXPECTED(ret, False);
2180 printf("the same process on a different fnum %s get a read lock\n", ret?"can":"cannot");
2182 /* Unlock the process 1 fnum3 lock. */
2183 cli_unlock(cli1, fnum3, 0, 4);
2185 /* Stack 2 more locks here. */
2186 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 4, 0, READ_LOCK)) &&
2187 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 4, 0, READ_LOCK));
2189 EXPECTED(ret, True);
2190 printf("the same process %s stack read locks\n", ret?"can":"cannot");
2192 /* Unlock the first process lock, then check this was the WRITE lock that was
2195 ret = NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 0, 4)) &&
2196 NT_STATUS_IS_OK(cli_lock32(cli2, fnum2, 0, 4, 0, READ_LOCK));
2198 EXPECTED(ret, True);
2199 printf("the first unlock removes the %s lock\n", ret?"WRITE":"READ");
2201 /* Unlock the process 2 lock. */
2202 cli_unlock(cli2, fnum2, 0, 4);
2204 /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */
2206 ret = NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 1, 1)) &&
2207 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 0, 4)) &&
2208 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 0, 4));
2210 EXPECTED(ret, True);
2211 printf("the same process %s unlock the stack of 4 locks\n", ret?"can":"cannot");
2213 /* Ensure the next unlock fails. */
2214 ret = NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 0, 4));
2215 EXPECTED(ret, False);
2216 printf("the same process %s count the lock stack\n", !ret?"can":"cannot");
2218 /* Ensure connection 2 can get a write lock. */
2219 status = cli_lock32(cli2, fnum2, 0, 4, 0, WRITE_LOCK);
2220 ret = NT_STATUS_IS_OK(status);
2221 EXPECTED(ret, True);
2223 printf("a different process %s get a write lock on the unlocked stack\n", ret?"can":"cannot");
2227 cli_close(cli1, fnum1);
2228 cli_close(cli2, fnum2);
2229 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2230 if (!torture_close_connection(cli1)) {
2233 if (!torture_close_connection(cli2)) {
2237 printf("finished locktest5\n");
2243 tries the unusual lockingX locktype bits
2245 static bool run_locktest6(int dummy)
2247 static struct cli_state *cli;
2248 const char *fname[1] = { "\\lock6.txt" };
2253 if (!torture_open_connection(&cli, 0)) {
2257 smbXcli_conn_set_sockopt(cli->conn, sockops);
2259 printf("starting locktest6\n");
2262 printf("Testing %s\n", fname[i]);
2264 cli_unlink(cli, fname[i], FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2266 cli_openx(cli, fname[i], O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
2267 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE);
2268 cli_close(cli, fnum);
2269 printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status));
2271 cli_openx(cli, fname[i], O_RDWR, DENY_NONE, &fnum);
2272 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK);
2273 cli_close(cli, fnum);
2274 printf("CANCEL_LOCK gave %s\n", nt_errstr(status));
2276 cli_unlink(cli, fname[i], FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2279 torture_close_connection(cli);
2281 printf("finished locktest6\n");
2285 static bool run_locktest7(int dummy)
2287 struct cli_state *cli1;
2288 const char *fname = "\\lockt7.lck";
2291 bool correct = False;
2295 if (!torture_open_connection(&cli1, 0)) {
2299 smbXcli_conn_set_sockopt(cli1->conn, sockops);
2301 printf("starting locktest7\n");
2303 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2305 cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
2307 memset(buf, 0, sizeof(buf));
2309 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 0, sizeof(buf),
2311 if (!NT_STATUS_IS_OK(status)) {
2312 printf("Failed to create file: %s\n", nt_errstr(status));
2316 cli_setpid(cli1, 1);
2318 status = cli_lock32(cli1, fnum1, 130, 4, 0, READ_LOCK);
2319 if (!NT_STATUS_IS_OK(status)) {
2320 printf("Unable to apply read lock on range 130:4, "
2321 "error was %s\n", nt_errstr(status));
2324 printf("pid1 successfully locked range 130:4 for READ\n");
2327 status = cli_read(cli1, fnum1, buf, 130, 4, &nread);
2328 if (!NT_STATUS_IS_OK(status)) {
2329 printf("pid1 unable to read the range 130:4, error was %s\n",
2332 } else if (nread != 4) {
2333 printf("pid1 unable to read the range 130:4, "
2334 "recv %ld req %d\n", (unsigned long)nread, 4);
2337 printf("pid1 successfully read the range 130:4\n");
2340 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
2341 if (!NT_STATUS_IS_OK(status)) {
2342 printf("pid1 unable to write to the range 130:4, error was "
2343 "%s\n", nt_errstr(status));
2344 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_LOCK_CONFLICT)) {
2345 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2349 printf("pid1 successfully wrote to the range 130:4 (should be denied)\n");
2353 cli_setpid(cli1, 2);
2355 status = cli_read(cli1, fnum1, buf, 130, 4, &nread);
2356 if (!NT_STATUS_IS_OK(status)) {
2357 printf("pid2 unable to read the range 130:4, error was %s\n",
2360 } else if (nread != 4) {
2361 printf("pid2 unable to read the range 130:4, "
2362 "recv %ld req %d\n", (unsigned long)nread, 4);
2365 printf("pid2 successfully read the range 130:4\n");
2368 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
2369 if (!NT_STATUS_IS_OK(status)) {
2370 printf("pid2 unable to write to the range 130:4, error was "
2371 "%s\n", nt_errstr(status));
2372 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_LOCK_CONFLICT)) {
2373 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2377 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
2381 cli_setpid(cli1, 1);
2382 cli_unlock(cli1, fnum1, 130, 4);
2384 status = cli_lock32(cli1, fnum1, 130, 4, 0, WRITE_LOCK);
2385 if (!NT_STATUS_IS_OK(status)) {
2386 printf("Unable to apply write lock on range 130:4, error was %s\n", nt_errstr(status));
2389 printf("pid1 successfully locked range 130:4 for WRITE\n");
2392 status = cli_read(cli1, fnum1, buf, 130, 4, &nread);
2393 if (!NT_STATUS_IS_OK(status)) {
2394 printf("pid1 unable to read the range 130:4, error was %s\n",
2397 } else if (nread != 4) {
2398 printf("pid1 unable to read the range 130:4, "
2399 "recv %ld req %d\n", (unsigned long)nread, 4);
2402 printf("pid1 successfully read the range 130:4\n");
2405 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
2406 if (!NT_STATUS_IS_OK(status)) {
2407 printf("pid1 unable to write to the range 130:4, error was "
2408 "%s\n", nt_errstr(status));
2411 printf("pid1 successfully wrote to the range 130:4\n");
2414 cli_setpid(cli1, 2);
2416 status = cli_read(cli1, fnum1, buf, 130, 4, &nread);
2417 if (!NT_STATUS_IS_OK(status)) {
2418 printf("pid2 unable to read the range 130:4, error was "
2419 "%s\n", nt_errstr(status));
2420 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_LOCK_CONFLICT)) {
2421 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2425 printf("pid2 successfully read the range 130:4 (should be denied) recv %ld\n",
2426 (unsigned long)nread);
2430 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
2431 if (!NT_STATUS_IS_OK(status)) {
2432 printf("pid2 unable to write to the range 130:4, error was "
2433 "%s\n", nt_errstr(status));
2434 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_LOCK_CONFLICT)) {
2435 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2439 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
2443 cli_unlock(cli1, fnum1, 130, 0);
2447 cli_close(cli1, fnum1);
2448 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2449 torture_close_connection(cli1);
2451 printf("finished locktest7\n");
2456 * This demonstrates a problem with our use of GPFS share modes: A file
2457 * descriptor sitting in the pending close queue holding a GPFS share mode
2458 * blocks opening a file another time. Happens with Word 2007 temp files.
2459 * With "posix locking = yes" and "gpfs:sharemodes = yes" enabled, the third
2460 * open is denied with NT_STATUS_SHARING_VIOLATION.
2463 static bool run_locktest8(int dummy)
2465 struct cli_state *cli1;
2466 const char *fname = "\\lockt8.lck";
2467 uint16_t fnum1, fnum2;
2469 bool correct = False;
2472 if (!torture_open_connection(&cli1, 0)) {
2476 smbXcli_conn_set_sockopt(cli1->conn, sockops);
2478 printf("starting locktest8\n");
2480 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2482 status = cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_WRITE,
2484 if (!NT_STATUS_IS_OK(status)) {
2485 d_fprintf(stderr, "cli_openx returned %s\n", nt_errstr(status));
2489 memset(buf, 0, sizeof(buf));
2491 status = cli_openx(cli1, fname, O_RDONLY, DENY_NONE, &fnum2);
2492 if (!NT_STATUS_IS_OK(status)) {
2493 d_fprintf(stderr, "cli_openx second time returned %s\n",
2498 status = cli_lock32(cli1, fnum2, 1, 1, 0, READ_LOCK);
2499 if (!NT_STATUS_IS_OK(status)) {
2500 printf("Unable to apply read lock on range 1:1, error was "
2501 "%s\n", nt_errstr(status));
2505 status = cli_close(cli1, fnum1);
2506 if (!NT_STATUS_IS_OK(status)) {
2507 d_fprintf(stderr, "cli_close(fnum1) %s\n", nt_errstr(status));
2511 status = cli_openx(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
2512 if (!NT_STATUS_IS_OK(status)) {
2513 d_fprintf(stderr, "cli_openx third time returned %s\n",
2521 cli_close(cli1, fnum1);
2522 cli_close(cli1, fnum2);
2523 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2524 torture_close_connection(cli1);
2526 printf("finished locktest8\n");
2531 * This test is designed to be run in conjunction with
2532 * external NFS or POSIX locks taken in the filesystem.
2533 * It checks that the smbd server will block until the
2534 * lock is released and then acquire it. JRA.
2537 static bool got_alarm;
2538 static struct cli_state *alarm_cli;
2540 static void alarm_handler(int dummy)
2545 static void alarm_handler_parent(int dummy)
2547 smbXcli_conn_disconnect(alarm_cli->conn, NT_STATUS_LOCAL_DISCONNECT);
2550 static void do_local_lock(const char *fname, int read_fd, int write_fd)
2555 const char *local_pathname = NULL;
2558 local_pathname = talloc_asprintf(talloc_tos(),
2559 "%s/%s", local_path, fname);
2560 if (!local_pathname) {
2561 printf("child: alloc fail\n");
2565 unlink(local_pathname);
2566 fd = open(local_pathname, O_RDWR|O_CREAT, 0666);
2568 printf("child: open of %s failed %s.\n",
2569 local_pathname, strerror(errno));
2573 /* Now take a fcntl lock. */
2574 lock.l_type = F_WRLCK;
2575 lock.l_whence = SEEK_SET;
2578 lock.l_pid = getpid();
2580 ret = fcntl(fd,F_SETLK,&lock);
2582 printf("child: failed to get lock 0:4 on file %s. Error %s\n",
2583 local_pathname, strerror(errno));
2586 printf("child: got lock 0:4 on file %s.\n",
2591 CatchSignal(SIGALRM, alarm_handler);
2593 /* Signal the parent. */
2594 if (write(write_fd, &c, 1) != 1) {
2595 printf("child: start signal fail %s.\n",
2602 /* Wait for the parent to be ready. */
2603 if (read(read_fd, &c, 1) != 1) {
2604 printf("child: reply signal fail %s.\n",
2612 printf("child: released lock 0:4 on file %s.\n",
2618 static bool _run_locktest9X(const char *fname, int timeout)
2620 struct cli_state *cli1;
2621 char *fpath = talloc_asprintf(talloc_tos(), "\\%s", fname);
2623 bool correct = False;
2624 int pipe_in[2], pipe_out[2];
2628 struct timeval start;
2632 printf("starting locktest9X: %s\n", fname);
2634 if (local_path == NULL) {
2635 d_fprintf(stderr, "locktest9X must be given a local path via -l <localpath>\n");
2639 if (pipe(pipe_in) == -1 || pipe(pipe_out) == -1) {
2644 if (child_pid == -1) {
2648 if (child_pid == 0) {
2650 do_local_lock(fname, pipe_out[0], pipe_in[1]);
2660 ret = read(pipe_in[0], &c, 1);
2662 d_fprintf(stderr, "failed to read start signal from child. %s\n",
2667 if (!torture_open_connection(&cli1, 0)) {
2671 smbXcli_conn_set_sockopt(cli1->conn, sockops);
2673 status = cli_openx(cli1, fpath, O_RDWR, DENY_NONE,
2675 if (!NT_STATUS_IS_OK(status)) {
2676 d_fprintf(stderr, "cli_openx returned %s\n", nt_errstr(status));
2680 /* Ensure the child has the lock. */
2681 status = cli_lock32(cli1, fnum, 0, 4, 0, WRITE_LOCK);
2682 if (NT_STATUS_IS_OK(status)) {
2683 d_fprintf(stderr, "Got the lock on range 0:4 - this should not happen !\n");
2686 d_printf("Child has the lock.\n");
2689 /* Tell the child to wait 5 seconds then exit. */
2690 ret = write(pipe_out[1], &c, 1);
2692 d_fprintf(stderr, "failed to send exit signal to child. %s\n",
2697 /* Wait 20 seconds for the lock. */
2699 CatchSignal(SIGALRM, alarm_handler_parent);
2702 start = timeval_current();
2704 status = cli_lock32(cli1, fnum, 0, 4, timeout, WRITE_LOCK);
2705 if (!NT_STATUS_IS_OK(status)) {
2706 d_fprintf(stderr, "Unable to apply write lock on range 0:4, error was "
2707 "%s\n", nt_errstr(status));
2712 seconds = timeval_elapsed(&start);
2714 printf("Parent got the lock after %.2f seconds.\n",
2717 status = cli_close(cli1, fnum);
2718 if (!NT_STATUS_IS_OK(status)) {
2719 d_fprintf(stderr, "cli_close(fnum1) %s\n", nt_errstr(status));
2726 cli_close(cli1, fnum);
2727 torture_close_connection(cli1);
2731 printf("finished locktest9X: %s\n", fname);
2735 static bool run_locktest9a(int dummy)
2737 return _run_locktest9X("lock9a.dat", -1);
2740 static bool run_locktest9b(int dummy)
2742 return _run_locktest9X("lock9b.dat", 10000);
2745 struct locktest10_state {
2750 static void locktest10_lockingx_done(struct tevent_req *subreq);
2751 static void locktest10_read_andx_done(struct tevent_req *subreq);
2753 static bool run_locktest10(int dummy)
2755 struct tevent_context *ev = NULL;
2756 struct cli_state *cli1 = NULL;
2757 struct cli_state *cli2 = NULL;
2758 struct smb1_lock_element lck = { 0 };
2759 struct tevent_req *reqs[2] = { NULL };
2760 struct tevent_req *smbreqs[2] = { NULL };
2761 const char fname[] = "\\lockt10.lck";
2762 uint16_t fnum1, fnum2;
2766 struct locktest10_state state = { .ok = true };
2769 printf("starting locktest10\n");
2771 ev = samba_tevent_context_init(NULL);
2773 d_fprintf(stderr, "samba_tevent_context_init failed\n");
2777 ok = torture_open_connection(&cli1, 0);
2781 smbXcli_conn_set_sockopt(cli1->conn, sockops);
2783 ok = torture_open_connection(&cli2, 1);
2787 smbXcli_conn_set_sockopt(cli2->conn, sockops);
2789 status = cli_openx(cli1, fname, O_CREAT|O_RDWR, DENY_NONE, &fnum1);
2790 if (!NT_STATUS_IS_OK(status)) {
2792 "cli_openx failed: %s\n",
2797 status = cli_writeall(cli1, fnum1, 0, &data, 0, sizeof(data), NULL);
2798 if (!NT_STATUS_IS_OK(status)) {
2800 "cli_writeall failed: %s\n",
2805 status = cli_openx(cli2, fname, O_CREAT|O_RDWR, DENY_NONE, &fnum2);
2806 if (!NT_STATUS_IS_OK(status)) {
2808 "cli_openx failed: %s\n",
2813 status = cli_locktype(
2814 cli2, fnum2, 0, 1, 0, LOCKING_ANDX_EXCLUSIVE_LOCK);
2815 if (!NT_STATUS_IS_OK(status)) {
2817 "cli_locktype failed: %s\n",
2822 lck = (struct smb1_lock_element) {
2823 .pid = cli_getpid(cli1), .offset = 0, .length = 1,
2826 reqs[0] = cli_lockingx_create(
2828 ev, /* tevent_context */
2831 LOCKING_ANDX_EXCLUSIVE_LOCK, /* typeoflock */
2832 0, /* newoplocklevel */
2834 0, /* num_unlocks */
2838 &smbreqs[0]); /* psmbreq */
2839 if (reqs[0] == NULL) {
2840 d_fprintf(stderr, "cli_lockingx_create failed\n");
2843 tevent_req_set_callback(reqs[0], locktest10_lockingx_done, &state);
2845 reqs[1] = cli_read_andx_create(
2852 &smbreqs[1]); /* psmbreq */
2853 if (reqs[1] == NULL) {
2854 d_fprintf(stderr, "cli_read_andx_create failed\n");
2857 tevent_req_set_callback(reqs[1], locktest10_read_andx_done, &state);
2859 status = smb1cli_req_chain_submit(smbreqs, ARRAY_SIZE(smbreqs));
2860 if (!NT_STATUS_IS_OK(status)) {
2862 "smb1cli_req_chain_submit failed: %s\n",
2867 while (!state.done) {
2868 tevent_loop_once(ev);
2871 torture_close_connection(cli1);
2880 static void locktest10_lockingx_done(struct tevent_req *subreq)
2882 struct locktest10_state *state = tevent_req_callback_data_void(subreq);
2885 status = cli_lockingx_recv(subreq);
2886 TALLOC_FREE(subreq);
2888 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_LOCK_CONFLICT)) {
2889 d_printf("cli_lockingx returned %s\n", nt_errstr(status));
2894 static void locktest10_read_andx_done(struct tevent_req *subreq)
2896 struct locktest10_state *state = tevent_req_callback_data_void(subreq);
2897 ssize_t received = -1;
2898 uint8_t *rcvbuf = NULL;
2901 status = cli_read_andx_recv(subreq, &received, &rcvbuf);
2903 if (!NT_STATUS_EQUAL(status, NT_STATUS_REQUEST_ABORTED)) {
2904 d_printf("cli_read_andx returned %s\n", nt_errstr(status));
2909 TALLOC_FREE(subreq);
2912 static bool run_locktest11(int dummy)
2914 struct cli_state *cli1;
2915 const char *fname = "\\lockt11.lck";
2920 if (!torture_open_connection(&cli1, 0)) {
2924 smbXcli_conn_set_sockopt(cli1->conn, sockops);
2926 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2928 status = cli_openx(cli1, fname, O_CREAT|O_RDWR, DENY_NONE, &fnum);
2929 if (!NT_STATUS_IS_OK(status)) {
2931 "cli_openx returned %s\n",
2937 * Test that LOCKING_ANDX_CANCEL_LOCK without any locks
2938 * returns NT_STATUS_OK
2941 status = cli_lockingx(
2944 LOCKING_ANDX_CANCEL_LOCK, /* typeoflock */
2945 0, /* newoplocklevel */
2947 0, /* num_unlocks */
2952 if (!NT_STATUS_IS_OK(status)) {
2953 d_printf("cli_lockingX returned %s\n", nt_errstr(status));
2959 cli_close(cli1, fnum);
2960 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2965 struct deferred_close_state {
2966 struct tevent_context *ev;
2967 struct cli_state *cli;
2971 static void deferred_close_waited(struct tevent_req *subreq);
2972 static void deferred_close_done(struct tevent_req *subreq);
2974 static struct tevent_req *deferred_close_send(
2975 TALLOC_CTX *mem_ctx,
2976 struct tevent_context *ev,
2978 struct cli_state *cli,
2981 struct tevent_req *req = NULL, *subreq = NULL;
2982 struct deferred_close_state *state = NULL;
2983 struct timeval wakeup_time = timeval_current_ofs(wait_secs, 0);
2985 req = tevent_req_create(
2986 mem_ctx, &state, struct deferred_close_state);
2994 subreq = tevent_wakeup_send(state, state->ev, wakeup_time);
2995 if (tevent_req_nomem(subreq, req)) {
2996 return tevent_req_post(req, ev);
2998 tevent_req_set_callback(subreq, deferred_close_waited, req);
3002 static void deferred_close_waited(struct tevent_req *subreq)
3004 struct tevent_req *req = tevent_req_callback_data(
3005 subreq, struct tevent_req);
3006 struct deferred_close_state *state = tevent_req_data(
3007 req, struct deferred_close_state);
3010 ok = tevent_wakeup_recv(subreq);
3011 TALLOC_FREE(subreq);
3013 tevent_req_oom(req);
3017 subreq = cli_close_send(state, state->ev, state->cli, state->fnum);
3018 if (tevent_req_nomem(subreq, req)) {
3021 tevent_req_set_callback(subreq, deferred_close_done, req);
3024 static void deferred_close_done(struct tevent_req *subreq)
3026 NTSTATUS status = cli_close_recv(subreq);
3027 tevent_req_simple_finish_ntstatus(subreq, status);
3030 static NTSTATUS deferred_close_recv(struct tevent_req *req)
3032 return tevent_req_simple_recv_ntstatus(req);
3035 struct lockread_state {
3036 struct smb1_lock_element lck;
3037 struct tevent_req *reqs[2];
3038 struct tevent_req *smbreqs[2];
3039 NTSTATUS lock_status;
3040 NTSTATUS read_status;
3044 static void lockread_lockingx_done(struct tevent_req *subreq);
3045 static void lockread_read_andx_done(struct tevent_req *subreq);
3047 static struct tevent_req *lockread_send(
3048 TALLOC_CTX *mem_ctx,
3049 struct tevent_context *ev,
3050 struct cli_state *cli,
3053 struct tevent_req *req = NULL;
3054 struct lockread_state *state = NULL;
3057 req = tevent_req_create(mem_ctx, &state, struct lockread_state);
3062 state->lck = (struct smb1_lock_element) {
3063 .pid = cli_getpid(cli), .offset = 0, .length = 1,
3066 state->reqs[0] = cli_lockingx_create(
3068 ev, /* tevent_context */
3071 LOCKING_ANDX_EXCLUSIVE_LOCK, /* typeoflock */
3072 0, /* newoplocklevel */
3073 10000, /* timeout */
3074 0, /* num_unlocks */
3077 &state->lck, /* locks */
3078 &state->smbreqs[0]); /* psmbreq */
3079 if (tevent_req_nomem(state->reqs[0], req)) {
3080 return tevent_req_post(req, ev);
3082 tevent_req_set_callback(
3083 state->reqs[0], lockread_lockingx_done, req);
3085 state->reqs[1] = cli_read_andx_create(
3092 &state->smbreqs[1]); /* psmbreq */
3093 if (tevent_req_nomem(state->reqs[1], req)) {
3094 return tevent_req_post(req, ev);
3096 tevent_req_set_callback(
3097 state->reqs[1], lockread_read_andx_done, req);
3099 status = smb1cli_req_chain_submit(state->smbreqs, 2);
3100 if (tevent_req_nterror(req, status)) {
3101 return tevent_req_post(req, ev);
3106 static void lockread_lockingx_done(struct tevent_req *subreq)
3108 struct tevent_req *req = tevent_req_callback_data(
3109 subreq, struct tevent_req);
3110 struct lockread_state *state = tevent_req_data(
3111 req, struct lockread_state);
3112 state->lock_status = cli_lockingx_recv(subreq);
3113 TALLOC_FREE(subreq);
3115 "lockingx returned %s\n",
3116 nt_errstr(state->lock_status));
3119 static void lockread_read_andx_done(struct tevent_req *subreq)
3121 struct tevent_req *req = tevent_req_callback_data(
3122 subreq, struct tevent_req);
3123 struct lockread_state *state = tevent_req_data(
3124 req, struct lockread_state);
3125 ssize_t received = -1;
3126 uint8_t *rcvbuf = NULL;
3128 state->read_status = cli_read_andx_recv(subreq, &received, &rcvbuf);
3131 "read returned %s\n",
3132 nt_errstr(state->read_status));
3134 if (!NT_STATUS_IS_OK(state->read_status)) {
3135 TALLOC_FREE(subreq);
3136 tevent_req_done(req);
3141 state->readbuf = talloc_memdup(state, rcvbuf, received);
3142 TALLOC_FREE(subreq);
3143 if (tevent_req_nomem(state->readbuf, req)) {
3147 TALLOC_FREE(subreq);
3148 tevent_req_done(req);
3151 static NTSTATUS lockread_recv(
3152 struct tevent_req *req,
3153 NTSTATUS *lock_status,
3154 NTSTATUS *read_status,
3155 TALLOC_CTX *mem_ctx,
3158 struct lockread_state *state = tevent_req_data(
3159 req, struct lockread_state);
3162 if (tevent_req_is_nterror(req, &status)) {
3166 *lock_status = state->lock_status;
3167 *read_status = state->read_status;
3168 if (state->readbuf != NULL) {
3169 *read_buf = talloc_move(mem_ctx, &state->readbuf);
3174 return NT_STATUS_OK;
3177 struct lock12_state {
3181 static void lock12_closed(struct tevent_req *subreq);
3182 static void lock12_read(struct tevent_req *subreq);
3184 static struct tevent_req *lock12_send(
3185 TALLOC_CTX *mem_ctx,
3186 struct tevent_context *ev,
3187 struct cli_state *cli,
3191 struct tevent_req *req = NULL, *subreq = NULL;
3192 struct lock12_state *state = NULL;
3194 req = tevent_req_create(mem_ctx, &state, struct lock12_state);
3199 subreq = deferred_close_send(state, ev, 1, cli, fnum1);
3200 if (tevent_req_nomem(subreq, req)) {
3201 return tevent_req_post(req, ev);
3203 tevent_req_set_callback(subreq, lock12_closed, req);
3205 subreq = lockread_send(state, ev, cli, fnum2);
3206 if (tevent_req_nomem(subreq, req)) {
3207 return tevent_req_post(req, ev);
3209 tevent_req_set_callback(subreq, lock12_read, req);
3214 static void lock12_closed(struct tevent_req *subreq)
3216 struct tevent_req *req = tevent_req_callback_data(
3217 subreq, struct tevent_req);
3220 status = deferred_close_recv(subreq);
3221 TALLOC_FREE(subreq);
3222 DBG_DEBUG("close returned %s\n", nt_errstr(status));
3223 if (tevent_req_nterror(req, status)) {
3228 static void lock12_read(struct tevent_req *subreq)
3230 struct tevent_req *req = tevent_req_callback_data(
3231 subreq, struct tevent_req);
3232 struct lock12_state *state = tevent_req_data(
3233 req, struct lock12_state);
3234 NTSTATUS status, lock_status, read_status;
3235 uint8_t *buf = NULL;
3237 status = lockread_recv(
3238 subreq, &lock_status, &read_status, state, &buf);
3239 TALLOC_FREE(subreq);
3240 if (tevent_req_nterror(req, status) ||
3241 tevent_req_nterror(req, lock_status) ||
3242 tevent_req_nterror(req, read_status)) {
3245 tevent_req_done(req);
3248 static NTSTATUS lock12_recv(struct tevent_req *req)
3253 if (tevent_req_is_nterror(req, &status)) {
3256 return NT_STATUS_OK;
3259 static bool run_locktest12(int dummy)
3261 struct tevent_context *ev = NULL;
3262 struct tevent_req *req = NULL;
3263 struct cli_state *cli = NULL;
3264 const char fname[] = "\\lockt12.lck";
3265 uint16_t fnum1, fnum2;
3271 printf("starting locktest12\n");
3273 ev = samba_tevent_context_init(NULL);
3275 d_fprintf(stderr, "samba_tevent_context_init failed\n");
3279 ok = torture_open_connection(&cli, 0);
3283 smbXcli_conn_set_sockopt(cli->conn, sockops);
3285 status = cli_openx(cli, fname, O_CREAT|O_RDWR, DENY_NONE, &fnum1);
3286 if (!NT_STATUS_IS_OK(status)) {
3288 "cli_openx failed: %s\n",
3293 status = cli_openx(cli, fname, O_CREAT|O_RDWR, DENY_NONE, &fnum2);
3294 if (!NT_STATUS_IS_OK(status)) {
3296 "cli_openx failed: %s\n",
3301 status = cli_writeall(cli, fnum1, 0, &data, 0, sizeof(data), NULL);
3302 if (!NT_STATUS_IS_OK(status)) {
3304 "cli_writeall failed: %s\n",
3309 status = cli_locktype(
3310 cli, fnum1, 0, 1, 0, LOCKING_ANDX_EXCLUSIVE_LOCK);
3311 if (!NT_STATUS_IS_OK(status)) {
3313 "cli_locktype failed: %s\n",
3318 req = lock12_send(ev, ev, cli, fnum1, fnum2);
3320 d_fprintf(stderr, "lock12_send failed\n");
3324 ok = tevent_req_poll_ntstatus(req, ev, &status);
3326 d_fprintf(stderr, "tevent_req_poll_ntstatus failed\n");
3330 if (!NT_STATUS_IS_OK(status)) {
3332 "tevent_req_poll_ntstatus returned %s\n",
3337 status = lock12_recv(req);
3338 if (!NT_STATUS_IS_OK(status)) {
3339 d_fprintf(stderr, "lock12 returned %s\n", nt_errstr(status));
3345 torture_close_connection(cli);
3349 struct lock_ntcancel_state {
3350 struct timeval start;
3351 struct smb1_lock_element lck;
3352 struct tevent_req *subreq;
3355 static void lock_ntcancel_waited(struct tevent_req *subreq);
3356 static void lock_ntcancel_done(struct tevent_req *subreq);
3358 static struct tevent_req *lock_ntcancel_send(
3359 TALLOC_CTX *mem_ctx,
3360 struct tevent_context *ev,
3361 struct cli_state *cli,
3364 struct tevent_req *req = NULL, *subreq = NULL;
3365 struct lock_ntcancel_state *state = NULL;
3367 req = tevent_req_create(mem_ctx, &state, struct lock_ntcancel_state);
3371 state->lck = (struct smb1_lock_element) {
3372 .pid = cli_getpid(cli), .offset = 0, .length = 1,
3374 state->start = timeval_current();
3376 state->subreq = cli_lockingx_send(
3377 state, /* mem_ctx */
3378 ev, /* tevent_context */
3381 LOCKING_ANDX_EXCLUSIVE_LOCK, /* typeoflock */
3382 0, /* newoplocklevel */
3383 10000, /* timeout */
3384 0, /* num_unlocks */
3387 &state->lck); /* locks */
3388 if (tevent_req_nomem(state->subreq, req)) {
3389 return tevent_req_post(req, ev);
3391 tevent_req_set_callback(state->subreq, lock_ntcancel_done, req);
3393 subreq = tevent_wakeup_send(state, ev, timeval_current_ofs(1, 0));
3394 if (tevent_req_nomem(subreq, req)) {
3395 return tevent_req_post(req, ev);
3397 tevent_req_set_callback(subreq, lock_ntcancel_waited, req);
3401 static void lock_ntcancel_waited(struct tevent_req *subreq)
3403 struct tevent_req *req = tevent_req_callback_data(
3404 subreq, struct tevent_req);
3405 struct lock_ntcancel_state *state = tevent_req_data(
3406 req, struct lock_ntcancel_state);
3409 ok = tevent_wakeup_recv(subreq);
3410 TALLOC_FREE(subreq);
3412 tevent_req_oom(req);
3416 ok = tevent_req_cancel(state->subreq);
3418 d_fprintf(stderr, "Could not cancel subreq\n");
3419 tevent_req_oom(req);
3424 static void lock_ntcancel_done(struct tevent_req *subreq)
3426 struct tevent_req *req = tevent_req_callback_data(
3427 subreq, struct tevent_req);
3428 struct lock_ntcancel_state *state = tevent_req_data(
3429 req, struct lock_ntcancel_state);
3433 status = cli_lockingx_recv(subreq);
3434 TALLOC_FREE(subreq);
3436 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_LOCK_CONFLICT)) {
3437 d_printf("cli_lockingx returned %s\n", nt_errstr(status));
3438 tevent_req_nterror(req, NT_STATUS_UNSUCCESSFUL);
3442 elapsed = timeval_elapsed(&state->start);
3445 d_printf("cli_lockingx was too slow, cancel did not work\n");
3446 tevent_req_nterror(req, NT_STATUS_UNSUCCESSFUL);
3450 tevent_req_done(req);
3453 static NTSTATUS lock_ntcancel_recv(struct tevent_req *req)
3455 return tevent_req_simple_recv_ntstatus(req);
3458 static bool run_locktest13(int dummy)
3460 struct tevent_context *ev = NULL;
3461 struct tevent_req *req = NULL;
3462 struct cli_state *cli = NULL;
3463 const char fname[] = "\\lockt13.lck";
3464 uint16_t fnum1, fnum2;
3470 printf("starting locktest13\n");
3472 ev = samba_tevent_context_init(NULL);
3474 d_fprintf(stderr, "samba_tevent_context_init failed\n");
3478 ok = torture_open_connection(&cli, 0);
3482 smbXcli_conn_set_sockopt(cli->conn, sockops);
3484 status = cli_openx(cli, fname, O_CREAT|O_RDWR, DENY_NONE, &fnum1);
3485 if (!NT_STATUS_IS_OK(status)) {
3487 "cli_openx failed: %s\n",
3492 status = cli_openx(cli, fname, O_CREAT|O_RDWR, DENY_NONE, &fnum2);
3493 if (!NT_STATUS_IS_OK(status)) {
3495 "cli_openx failed: %s\n",
3500 status = cli_writeall(cli, fnum1, 0, &data, 0, sizeof(data), NULL);
3501 if (!NT_STATUS_IS_OK(status)) {
3503 "cli_writeall failed: %s\n",
3508 status = cli_locktype(
3509 cli, fnum1, 0, 1, 0, LOCKING_ANDX_EXCLUSIVE_LOCK);
3510 if (!NT_STATUS_IS_OK(status)) {
3512 "cli_locktype failed: %s\n",
3517 req = lock_ntcancel_send(ev, ev, cli, fnum2);
3519 d_fprintf(stderr, "lock_ntcancel_send failed\n");
3523 ok = tevent_req_poll_ntstatus(req, ev, &status);
3525 d_fprintf(stderr, "tevent_req_poll_ntstatus failed\n");
3529 if (!NT_STATUS_IS_OK(status)) {
3531 "tevent_req_poll_ntstatus returned %s\n",
3536 status = lock_ntcancel_recv(req);
3537 if (!NT_STATUS_IS_OK(status)) {
3539 "lock_ntcancel returned %s\n",
3546 torture_close_connection(cli);
3551 test whether fnums and tids open on one VC are available on another (a major
3554 static bool run_fdpasstest(int dummy)
3556 struct cli_state *cli1, *cli2;
3557 const char *fname = "\\fdpass.tst";
3562 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
3565 smbXcli_conn_set_sockopt(cli1->conn, sockops);
3566 smbXcli_conn_set_sockopt(cli2->conn, sockops);
3568 printf("starting fdpasstest\n");
3570 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3572 status = cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
3574 if (!NT_STATUS_IS_OK(status)) {
3575 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
3579 status = cli_writeall(cli1, fnum1, 0, (const uint8_t *)"hello world\n", 0,
3581 if (!NT_STATUS_IS_OK(status)) {
3582 printf("write failed (%s)\n", nt_errstr(status));
3586 cli_state_set_uid(cli2, cli_state_get_uid(cli1));
3587 cli_state_set_tid(cli2, cli_state_get_tid(cli1));
3588 cli_setpid(cli2, cli_getpid(cli1));
3590 if (test_cli_read(cli2, fnum1, buf, 0, 13, NULL, 13)) {
3591 printf("read succeeded! nasty security hole [%s]\n", buf);
3595 cli_close(cli1, fnum1);
3596 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3598 torture_close_connection(cli1);
3599 torture_close_connection(cli2);
3601 printf("finished fdpasstest\n");
3605 static bool run_fdsesstest(int dummy)
3607 struct cli_state *cli;
3609 uint16_t saved_vuid;
3611 uint32_t saved_cnum;
3612 const char *fname = "\\fdsess.tst";
3613 const char *fname1 = "\\fdsess1.tst";
3620 if (!torture_open_connection(&cli, 0))
3622 smbXcli_conn_set_sockopt(cli->conn, sockops);
3624 if (!torture_cli_session_setup2(cli, &new_vuid))
3627 saved_cnum = cli_state_get_tid(cli);
3628 if (!NT_STATUS_IS_OK(cli_tree_connect(cli, share, "?????", NULL)))
3630 new_cnum = cli_state_get_tid(cli);
3631 cli_state_set_tid(cli, saved_cnum);
3633 printf("starting fdsesstest\n");
3635 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3636 cli_unlink(cli, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3638 status = cli_openx(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
3639 if (!NT_STATUS_IS_OK(status)) {
3640 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
3644 status = cli_writeall(cli, fnum1, 0, (const uint8_t *)"hello world\n", 0, 13,
3646 if (!NT_STATUS_IS_OK(status)) {
3647 printf("write failed (%s)\n", nt_errstr(status));
3651 saved_vuid = cli_state_get_uid(cli);
3652 cli_state_set_uid(cli, new_vuid);
3654 if (test_cli_read(cli, fnum1, buf, 0, 13, NULL, 13)) {
3655 printf("read succeeded with different vuid! "
3656 "nasty security hole [%s]\n", buf);
3659 /* Try to open a file with different vuid, samba cnum. */
3660 if (NT_STATUS_IS_OK(cli_openx(cli, fname1, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum2))) {
3661 printf("create with different vuid, same cnum succeeded.\n");
3662 cli_close(cli, fnum2);
3663 cli_unlink(cli, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3665 printf("create with different vuid, same cnum failed.\n");
3666 printf("This will cause problems with service clients.\n");
3670 cli_state_set_uid(cli, saved_vuid);
3672 /* Try with same vuid, different cnum. */
3673 cli_state_set_tid(cli, new_cnum);
3675 if (test_cli_read(cli, fnum1, buf, 0, 13, NULL, 13)) {
3676 printf("read succeeded with different cnum![%s]\n", buf);
3680 cli_state_set_tid(cli, saved_cnum);
3681 cli_close(cli, fnum1);
3682 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3684 torture_close_connection(cli);
3686 printf("finished fdsesstest\n");
3691 This test checks that
3693 1) the server does not allow an unlink on a file that is open
3695 static bool run_unlinktest(int dummy)
3697 struct cli_state *cli;
3698 const char *fname = "\\unlink.tst";
3700 bool correct = True;
3703 if (!torture_open_connection(&cli, 0)) {
3707 smbXcli_conn_set_sockopt(cli->conn, sockops);
3709 printf("starting unlink test\n");
3711 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3715 status = cli_openx(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
3716 if (!NT_STATUS_IS_OK(status)) {
3717 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
3721 status = cli_unlink(cli, fname,
3722 FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3723 if (NT_STATUS_IS_OK(status)) {
3724 printf("error: server allowed unlink on an open file\n");
3727 correct = check_error(__LINE__, status, ERRDOS, ERRbadshare,
3728 NT_STATUS_SHARING_VIOLATION);
3731 cli_close(cli, fnum);
3732 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3734 if (!torture_close_connection(cli)) {
3738 printf("unlink test finished\n");
3745 test how many open files this server supports on the one socket
3747 static bool run_maxfidtest(int dummy)
3749 struct cli_state *cli;
3751 uint16_t fnums[0x11000];
3754 bool correct = True;
3760 printf("failed to connect\n");
3764 smbXcli_conn_set_sockopt(cli->conn, sockops);
3766 for (i=0; i<0x11000; i++) {
3767 slprintf(fname,sizeof(fname)-1,"\\maxfid.%d.%d", i,(int)getpid());
3768 status = cli_openx(cli, fname, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE,
3770 if (!NT_STATUS_IS_OK(status)) {
3771 printf("open of %s failed (%s)\n",
3772 fname, nt_errstr(status));
3773 printf("maximum fnum is %d\n", i);
3781 printf("cleaning up\n");
3783 slprintf(fname,sizeof(fname)-1,"\\maxfid.%d.%d", i,(int)getpid());
3784 cli_close(cli, fnums[i]);
3786 status = cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3787 if (!NT_STATUS_IS_OK(status)) {
3788 printf("unlink of %s failed (%s)\n",
3789 fname, nt_errstr(status));
3796 printf("maxfid test finished\n");
3797 if (!torture_close_connection(cli)) {
3803 /* generate a random buffer */
3804 static void rand_buf(char *buf, int len)
3807 *buf = (char)sys_random();
3812 /* send smb negprot commands, not reading the response */
3813 static bool run_negprot_nowait(int dummy)
3815 struct tevent_context *ev;
3817 struct cli_state *cli;
3818 bool correct = True;
3820 printf("starting negprot nowait test\n");
3822 ev = samba_tevent_context_init(talloc_tos());
3827 if (!(cli = open_nbt_connection())) {
3832 for (i=0;i<50000;i++) {
3833 struct tevent_req *req;
3835 req = smbXcli_negprot_send(ev, ev, cli->conn, cli->timeout,
3836 PROTOCOL_CORE, PROTOCOL_NT1, 0);
3841 if (!tevent_req_poll(req, ev)) {
3842 d_fprintf(stderr, "tevent_req_poll failed: %s\n",
3850 if (torture_close_connection(cli)) {
3854 printf("finished negprot nowait test\n");
3859 /* send smb negprot commands, not reading the response */
3860 static bool run_bad_nbt_session(int dummy)
3862 struct nmb_name called, calling;
3863 struct sockaddr_storage ss;
3868 printf("starting bad nbt session test\n");
3870 make_nmb_name(&calling, myname, 0x0);
3871 make_nmb_name(&called , host, 0x20);
3873 if (!resolve_name(host, &ss, 0x20, true)) {
3874 d_fprintf(stderr, "Could not resolve name %s\n", host);
3878 status = open_socket_out(&ss, NBT_SMB_PORT, 10000, &fd);
3879 if (!NT_STATUS_IS_OK(status)) {
3880 d_fprintf(stderr, "open_socket_out failed: %s\n",
3885 ret = cli_bad_session_request(fd, &calling, &called);
3888 d_fprintf(stderr, "open_socket_out failed: %s\n",
3893 printf("finished bad nbt session test\n");
3897 /* send random IPC commands */
3898 static bool run_randomipc(int dummy)
3900 char *rparam = NULL;
3902 unsigned int rdrcnt,rprcnt;
3904 int api, param_len, i;
3905 struct cli_state *cli;
3906 bool correct = True;
3909 printf("starting random ipc test\n");
3911 if (!torture_open_connection(&cli, 0)) {
3915 for (i=0;i<count;i++) {
3916 api = sys_random() % 500;
3917 param_len = (sys_random() % 64);
3919 rand_buf(param, param_len);
3924 param, param_len, 8,
3925 NULL, 0, CLI_BUFFER_SIZE,
3929 printf("%d/%d\r", i,count);
3932 printf("%d/%d\n", i, count);
3934 if (!torture_close_connection(cli)) {
3941 printf("finished random ipc test\n");
3948 static void browse_callback(const char *sname, uint32_t stype,
3949 const char *comment, void *state)
3951 printf("\t%20.20s %08x %s\n", sname, stype, comment);
3957 This test checks the browse list code
3960 static bool run_browsetest(int dummy)
3962 static struct cli_state *cli;
3963 bool correct = True;
3965 printf("starting browse test\n");
3967 if (!torture_open_connection(&cli, 0)) {
3971 printf("domain list:\n");
3972 cli_NetServerEnum(cli, cli->server_domain,
3973 SV_TYPE_DOMAIN_ENUM,
3974 browse_callback, NULL);
3976 printf("machine list:\n");
3977 cli_NetServerEnum(cli, cli->server_domain,
3979 browse_callback, NULL);
3981 if (!torture_close_connection(cli)) {
3985 printf("browse test finished\n");
3991 static bool check_attributes(struct cli_state *cli,
3993 uint16_t expected_attrs)
3996 NTSTATUS status = cli_getatr(cli,
4001 if (!NT_STATUS_IS_OK(status)) {
4002 printf("cli_getatr failed with %s\n",
4006 if (attrs != expected_attrs) {
4007 printf("Attributes incorrect 0x%x, should be 0x%x\n",
4008 (unsigned int)attrs,
4009 (unsigned int)expected_attrs);
4016 This checks how the getatr calls works
4018 static bool run_attrtest(int dummy)
4020 struct cli_state *cli;
4023 const char *fname = "\\attrib123456789.tst";
4024 bool correct = True;
4027 printf("starting attrib test\n");
4029 if (!torture_open_connection(&cli, 0)) {
4033 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4034 cli_openx(cli, fname,
4035 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
4036 cli_close(cli, fnum);
4038 status = cli_getatr(cli, fname, NULL, NULL, &t);
4039 if (!NT_STATUS_IS_OK(status)) {
4040 printf("getatr failed (%s)\n", nt_errstr(status));
4044 if (labs(t - time(NULL)) > 60*60*24*10) {
4045 printf("ERROR: SMBgetatr bug. time is %s",
4051 t2 = t-60*60*24; /* 1 day ago */
4053 status = cli_setatr(cli, fname, 0, t2);
4054 if (!NT_STATUS_IS_OK(status)) {
4055 printf("setatr failed (%s)\n", nt_errstr(status));
4059 status = cli_getatr(cli, fname, NULL, NULL, &t);
4060 if (!NT_STATUS_IS_OK(status)) {
4061 printf("getatr failed (%s)\n", nt_errstr(status));
4066 printf("ERROR: getatr/setatr bug. times are\n%s",
4068 printf("%s", ctime(&t2));
4072 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4074 /* Check cli_setpathinfo_basic() */
4075 /* Re-create the file. */
4076 status = cli_openx(cli, fname,
4077 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
4078 if (!NT_STATUS_IS_OK(status)) {
4079 printf("Failed to recreate %s (%s)\n",
4080 fname, nt_errstr(status));
4083 cli_close(cli, fnum);
4085 status = cli_setpathinfo_basic(cli,
4091 FILE_ATTRIBUTE_SYSTEM |
4092 FILE_ATTRIBUTE_HIDDEN |
4093 FILE_ATTRIBUTE_READONLY);
4094 if (!NT_STATUS_IS_OK(status)) {
4095 printf("cli_setpathinfo_basic failed with %s\n",
4100 /* Check attributes are correct. */
4101 correct = check_attributes(cli,
4103 FILE_ATTRIBUTE_SYSTEM |
4104 FILE_ATTRIBUTE_HIDDEN |
4105 FILE_ATTRIBUTE_READONLY);
4106 if (correct == false) {
4110 /* Setting to FILE_ATTRIBUTE_NORMAL should be ignored. */
4111 status = cli_setpathinfo_basic(cli,
4117 FILE_ATTRIBUTE_NORMAL);
4118 if (!NT_STATUS_IS_OK(status)) {
4119 printf("cli_setpathinfo_basic failed with %s\n",
4124 /* Check attributes are correct. */
4125 correct = check_attributes(cli,
4127 FILE_ATTRIBUTE_SYSTEM |
4128 FILE_ATTRIBUTE_HIDDEN |
4129 FILE_ATTRIBUTE_READONLY);
4130 if (correct == false) {
4134 /* Setting to (uint16_t)-1 should also be ignored. */
4135 status = cli_setpathinfo_basic(cli,
4142 if (!NT_STATUS_IS_OK(status)) {
4143 printf("cli_setpathinfo_basic failed with %s\n",
4148 /* Check attributes are correct. */
4149 correct = check_attributes(cli,
4151 FILE_ATTRIBUTE_SYSTEM |
4152 FILE_ATTRIBUTE_HIDDEN |
4153 FILE_ATTRIBUTE_READONLY);
4154 if (correct == false) {
4158 /* Setting to 0 should clear them all. */
4159 status = cli_setpathinfo_basic(cli,
4166 if (!NT_STATUS_IS_OK(status)) {
4167 printf("cli_setpathinfo_basic failed with %s\n",
4172 /* Check attributes are correct. */
4173 correct = check_attributes(cli,
4175 FILE_ATTRIBUTE_NORMAL);
4176 if (correct == false) {
4184 FILE_ATTRIBUTE_SYSTEM |
4185 FILE_ATTRIBUTE_HIDDEN|
4186 FILE_ATTRIBUTE_READONLY);
4188 if (!torture_close_connection(cli)) {
4192 printf("attrib test finished\n");
4199 This checks a couple of trans2 calls
4201 static bool run_trans2test(int dummy)
4203 struct cli_state *cli;
4206 time_t c_time, a_time, m_time;
4207 struct timespec c_time_ts, a_time_ts, m_time_ts, w_time_ts, m_time2_ts;
4208 const char *fname = "\\trans2.tst";
4209 const char *dname = "\\trans2";
4210 const char *fname2 = "\\trans2\\trans2.tst";
4212 bool correct = True;
4217 printf("starting trans2 test\n");
4219 if (!torture_open_connection(&cli, 0)) {
4223 if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
4224 /* Ensure ino is zero, SMB2 gets a real one. */
4227 /* Ensure ino is -1, SMB1 never gets a real one. */
4231 status = cli_get_fs_attr_info(cli, &fs_attr);
4232 if (!NT_STATUS_IS_OK(status)) {
4233 printf("ERROR: cli_get_fs_attr_info returned %s\n",
4238 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4239 cli_openx(cli, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
4240 status = cli_qfileinfo_basic(cli, fnum, NULL, &size, &c_time_ts,
4241 &a_time_ts, &w_time_ts, &m_time_ts, NULL);
4242 if (!NT_STATUS_IS_OK(status)) {
4243 printf("ERROR: qfileinfo failed (%s)\n", nt_errstr(status));
4247 status = cli_qfilename(cli, fnum, talloc_tos(), &pname);
4248 if (!NT_STATUS_IS_OK(status)) {
4249 printf("ERROR: qfilename failed (%s)\n", nt_errstr(status));
4252 else if (strcmp(pname, fname)) {
4253 printf("qfilename gave different name? [%s] [%s]\n",
4258 cli_close(cli, fnum);
4262 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4263 status = cli_openx(cli, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE,
4265 if (!NT_STATUS_IS_OK(status)) {
4266 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
4269 cli_close(cli, fnum);
4271 status = cli_qpathinfo1(cli, fname, &c_time, &a_time, &m_time, &size,
4273 if (!NT_STATUS_IS_OK(status)) {
4274 printf("ERROR: qpathinfo failed (%s)\n", nt_errstr(status));
4277 time_t t = time(NULL);
4279 if (c_time != m_time) {
4280 printf("create time=%s", ctime(&c_time));
4281 printf("modify time=%s", ctime(&m_time));
4282 printf("This system appears to have sticky create times\n");
4284 if ((labs(a_time - t) > 60) && (a_time % (60*60) == 0)) {
4285 printf("access time=%s", ctime(&a_time));
4286 printf("This system appears to set a midnight access time\n");
4290 if (labs(m_time - t) > 60*60*24*7) {
4291 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
4297 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4298 cli_openx(cli, fname,
4299 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
4300 cli_close(cli, fnum);
4301 status = cli_qpathinfo2(cli, fname, &c_time_ts, &a_time_ts, &w_time_ts,
4302 &m_time_ts, &size, NULL, &ino);
4303 if (!NT_STATUS_IS_OK(status)) {
4304 printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status));
4307 if (w_time_ts.tv_sec < 60*60*24*2) {
4308 printf("write time=%s", ctime(&w_time_ts.tv_sec));
4309 printf("This system appears to set a initial 0 write time\n");
4312 if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
4313 /* SMB2 should always return an inode. */
4315 printf("SMB2 bad inode (0)\n");
4319 /* SMB1 must always return zero here. */
4321 printf("SMB1 bad inode (!0)\n");
4327 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4330 /* check if the server updates the directory modification time
4331 when creating a new file */
4332 status = cli_mkdir(cli, dname);
4333 if (!NT_STATUS_IS_OK(status)) {
4334 printf("ERROR: mkdir failed (%s)\n", nt_errstr(status));
4338 status = cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts,
4339 &w_time_ts, &m_time_ts, &size, NULL, NULL);
4340 if (!NT_STATUS_IS_OK(status)) {
4341 printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status));
4345 cli_openx(cli, fname2,
4346 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
4347 cli_writeall(cli, fnum, 0, (uint8_t *)&fnum, 0, sizeof(fnum), NULL);
4348 cli_close(cli, fnum);
4349 status = cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts,
4350 &w_time_ts, &m_time2_ts, &size, NULL, NULL);
4351 if (!NT_STATUS_IS_OK(status)) {
4352 printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status));
4355 if (memcmp(&m_time_ts, &m_time2_ts, sizeof(struct timespec))
4357 printf("This system does not update directory modification times\n");
4361 cli_unlink(cli, fname2, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4362 cli_rmdir(cli, dname);
4364 if (!torture_close_connection(cli)) {
4368 printf("trans2 test finished\n");
4374 This checks new W2K calls.
4377 static NTSTATUS new_trans(struct cli_state *pcli, int fnum, int level)
4379 uint8_t *buf = NULL;
4383 status = cli_qfileinfo(talloc_tos(), pcli, fnum, level, 0,
4384 CLI_BUFFER_SIZE, NULL, &buf, &len);
4385 if (!NT_STATUS_IS_OK(status)) {
4386 printf("ERROR: qfileinfo (%d) failed (%s)\n", level,
4389 printf("qfileinfo: level %d, len = %u\n", level, len);
4390 dump_data(0, (uint8_t *)buf, len);
4397 static bool run_w2ktest(int dummy)
4399 struct cli_state *cli;
4401 const char *fname = "\\w2ktest\\w2k.tst";
4403 bool correct = True;
4405 printf("starting w2k test\n");
4407 if (!torture_open_connection(&cli, 0)) {
4411 cli_openx(cli, fname,
4412 O_RDWR | O_CREAT , DENY_NONE, &fnum);
4414 for (level = 1004; level < 1040; level++) {
4415 new_trans(cli, fnum, level);
4418 cli_close(cli, fnum);
4420 if (!torture_close_connection(cli)) {
4424 printf("w2k test finished\n");
4431 this is a harness for some oplock tests
4433 static bool run_oplock1(int dummy)
4435 struct cli_state *cli1;
4436 const char *fname = "\\lockt1.lck";
4438 bool correct = True;
4441 printf("starting oplock test 1\n");
4443 if (!torture_open_connection(&cli1, 0)) {
4447 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4449 smbXcli_conn_set_sockopt(cli1->conn, sockops);
4451 cli1->use_oplocks = True;
4453 status = cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
4455 if (!NT_STATUS_IS_OK(status)) {
4456 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
4460 cli1->use_oplocks = False;
4462 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4463 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4465 status = cli_close(cli1, fnum1);
4466 if (!NT_STATUS_IS_OK(status)) {
4467 printf("close2 failed (%s)\n", nt_errstr(status));
4471 status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4472 if (!NT_STATUS_IS_OK(status)) {
4473 printf("unlink failed (%s)\n", nt_errstr(status));
4477 if (!torture_close_connection(cli1)) {
4481 printf("finished oplock test 1\n");
4486 static bool run_oplock2(int dummy)
4488 struct cli_state *cli1, *cli2;
4489 const char *fname = "\\lockt2.lck";
4490 uint16_t fnum1, fnum2;
4491 int saved_use_oplocks = use_oplocks;
4493 bool correct = True;
4494 volatile bool *shared_correct;
4498 shared_correct = (volatile bool *)anonymous_shared_allocate(sizeof(bool));
4499 *shared_correct = True;
4501 use_level_II_oplocks = True;
4504 printf("starting oplock test 2\n");
4506 if (!torture_open_connection(&cli1, 0)) {
4507 use_level_II_oplocks = False;
4508 use_oplocks = saved_use_oplocks;
4512 if (!torture_open_connection(&cli2, 1)) {
4513 use_level_II_oplocks = False;
4514 use_oplocks = saved_use_oplocks;
4518 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4520 smbXcli_conn_set_sockopt(cli1->conn, sockops);
4521 smbXcli_conn_set_sockopt(cli2->conn, sockops);
4523 status = cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
4525 if (!NT_STATUS_IS_OK(status)) {
4526 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
4530 /* Don't need the globals any more. */
4531 use_level_II_oplocks = False;
4532 use_oplocks = saved_use_oplocks;
4536 status = cli_openx(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
4537 if (!NT_STATUS_IS_OK(status)) {
4538 printf("second open of %s failed (%s)\n", fname, nt_errstr(status));
4539 *shared_correct = False;
4545 status = cli_close(cli2, fnum2);
4546 if (!NT_STATUS_IS_OK(status)) {
4547 printf("close2 failed (%s)\n", nt_errstr(status));
4548 *shared_correct = False;
4556 /* Ensure cli1 processes the break. Empty file should always return 0
4558 status = cli_read(cli1, fnum1, buf, 0, 4, &nread);
4559 if (!NT_STATUS_IS_OK(status)) {
4560 printf("read on fnum1 failed (%s)\n", nt_errstr(status));
4562 } else if (nread != 0) {
4563 printf("read on empty fnum1 failed. recv %ld expected %d\n",
4564 (unsigned long)nread, 0);
4568 /* Should now be at level II. */
4569 /* Test if sending a write locks causes a break to none. */
4570 status = cli_lock32(cli1, fnum1, 0, 4, 0, READ_LOCK);
4571 if (!NT_STATUS_IS_OK(status)) {
4572 printf("lock failed (%s)\n", nt_errstr(status));
4576 cli_unlock(cli1, fnum1, 0, 4);
4580 status = cli_lock32(cli1, fnum1, 0, 4, 0, WRITE_LOCK);
4581 if (!NT_STATUS_IS_OK(status)) {
4582 printf("lock failed (%s)\n", nt_errstr(status));
4586 cli_unlock(cli1, fnum1, 0, 4);
4590 cli_read(cli1, fnum1, buf, 0, 4, NULL);
4592 status = cli_close(cli1, fnum1);
4593 if (!NT_STATUS_IS_OK(status)) {
4594 printf("close1 failed (%s)\n", nt_errstr(status));
4600 status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4601 if (!NT_STATUS_IS_OK(status)) {
4602 printf("unlink failed (%s)\n", nt_errstr(status));
4606 if (!torture_close_connection(cli1)) {
4610 if (!*shared_correct) {
4614 printf("finished oplock test 2\n");
4619 struct oplock4_state {
4620 struct tevent_context *ev;
4621 struct cli_state *cli;
4626 static void oplock4_got_break(struct tevent_req *req);
4627 static void oplock4_got_open(struct tevent_req *req);
4629 static bool run_oplock4(int dummy)
4631 struct tevent_context *ev;
4632 struct cli_state *cli1, *cli2;
4633 struct tevent_req *oplock_req, *open_req;
4634 const char *fname = "\\lockt4.lck";
4635 const char *fname_ln = "\\lockt4_ln.lck";
4636 uint16_t fnum1, fnum2;
4637 int saved_use_oplocks = use_oplocks;
4639 bool correct = true;
4643 struct oplock4_state *state;
4645 printf("starting oplock test 4\n");
4647 if (!torture_open_connection(&cli1, 0)) {
4648 use_level_II_oplocks = false;
4649 use_oplocks = saved_use_oplocks;
4653 if (!torture_open_connection(&cli2, 1)) {
4654 use_level_II_oplocks = false;
4655 use_oplocks = saved_use_oplocks;
4659 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4660 cli_unlink(cli1, fname_ln, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4662 smbXcli_conn_set_sockopt(cli1->conn, sockops);
4663 smbXcli_conn_set_sockopt(cli2->conn, sockops);
4665 /* Create the file. */
4666 status = cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
4668 if (!NT_STATUS_IS_OK(status)) {
4669 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
4673 status = cli_close(cli1, fnum1);
4674 if (!NT_STATUS_IS_OK(status)) {
4675 printf("close1 failed (%s)\n", nt_errstr(status));
4679 /* Now create a hardlink. */
4680 status = cli_hardlink(cli1, fname, fname_ln);
4681 if (!NT_STATUS_IS_OK(status)) {
4682 printf("nt hardlink failed (%s)\n", nt_errstr(status));
4686 /* Prove that opening hardlinks cause deny modes to conflict. */
4687 status = cli_openx(cli1, fname, O_RDWR, DENY_ALL, &fnum1);
4688 if (!NT_STATUS_IS_OK(status)) {
4689 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
4693 status = cli_openx(cli1, fname_ln, O_RDWR, DENY_NONE, &fnum2);
4694 if (NT_STATUS_IS_OK(status)) {
4695 printf("open of %s succeeded - should fail with sharing violation.\n",
4700 if (!NT_STATUS_EQUAL(status, NT_STATUS_SHARING_VIOLATION)) {
4701 printf("open of %s should fail with sharing violation. Got %s\n",
4702 fname_ln, nt_errstr(status));
4706 status = cli_close(cli1, fnum1);
4707 if (!NT_STATUS_IS_OK(status)) {
4708 printf("close1 failed (%s)\n", nt_errstr(status));
4712 cli1->use_oplocks = true;
4713 cli2->use_oplocks = true;
4715 status = cli_openx(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
4716 if (!NT_STATUS_IS_OK(status)) {
4717 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
4721 ev = samba_tevent_context_init(talloc_tos());
4723 printf("tevent_context_init failed\n");
4727 state = talloc(ev, struct oplock4_state);
4728 if (state == NULL) {
4729 printf("talloc failed\n");
4734 state->got_break = &got_break;
4735 state->fnum2 = &fnum2;
4737 oplock_req = cli_smb_oplock_break_waiter_send(
4738 talloc_tos(), ev, cli1);
4739 if (oplock_req == NULL) {
4740 printf("cli_smb_oplock_break_waiter_send failed\n");
4743 tevent_req_set_callback(oplock_req, oplock4_got_break, state);
4745 open_req = cli_openx_send(
4746 talloc_tos(), ev, cli2, fname_ln, O_RDWR, DENY_NONE);
4747 if (open_req == NULL) {
4748 printf("cli_openx_send failed\n");
4751 tevent_req_set_callback(open_req, oplock4_got_open, state);
4756 while (!got_break || fnum2 == 0xffff) {
4758 ret = tevent_loop_once(ev);
4760 printf("tevent_loop_once failed: %s\n",
4766 status = cli_close(cli2, fnum2);
4767 if (!NT_STATUS_IS_OK(status)) {
4768 printf("close2 failed (%s)\n", nt_errstr(status));
4772 status = cli_close(cli1, fnum1);
4773 if (!NT_STATUS_IS_OK(status)) {
4774 printf("close1 failed (%s)\n", nt_errstr(status));
4778 status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4779 if (!NT_STATUS_IS_OK(status)) {
4780 printf("unlink failed (%s)\n", nt_errstr(status));
4784 status = cli_unlink(cli1, fname_ln, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4785 if (!NT_STATUS_IS_OK(status)) {
4786 printf("unlink failed (%s)\n", nt_errstr(status));
4790 if (!torture_close_connection(cli1)) {
4798 printf("finished oplock test 4\n");
4803 static void oplock4_got_break(struct tevent_req *req)
4805 struct oplock4_state *state = tevent_req_callback_data(
4806 req, struct oplock4_state);
4811 status = cli_smb_oplock_break_waiter_recv(req, &fnum, &level);
4813 if (!NT_STATUS_IS_OK(status)) {
4814 printf("cli_smb_oplock_break_waiter_recv returned %s\n",
4818 *state->got_break = true;
4820 req = cli_oplock_ack_send(state, state->ev, state->cli, fnum,
4823 printf("cli_oplock_ack_send failed\n");
4828 static void oplock4_got_open(struct tevent_req *req)
4830 struct oplock4_state *state = tevent_req_callback_data(
4831 req, struct oplock4_state);
4834 status = cli_openx_recv(req, state->fnum2);
4835 if (!NT_STATUS_IS_OK(status)) {
4836 printf("cli_openx_recv returned %s\n", nt_errstr(status));
4837 *state->fnum2 = 0xffff;
4841 #ifdef HAVE_KERNEL_OPLOCKS_LINUX
4843 struct oplock5_state {
4848 * Async open the file that has a kernel oplock, do an echo to get
4849 * that 100% across, close the file to signal to the child fd that the
4850 * oplock can be dropped, wait for the open reply.
4853 static void oplock5_opened(struct tevent_req *subreq);
4854 static void oplock5_pong(struct tevent_req *subreq);
4855 static void oplock5_timedout(struct tevent_req *subreq);
4857 static struct tevent_req *oplock5_send(
4858 TALLOC_CTX *mem_ctx,
4859 struct tevent_context *ev,
4860 struct cli_state *cli,
4864 struct tevent_req *req = NULL, *subreq = NULL;
4865 struct oplock5_state *state = NULL;
4866 static uint8_t data = 0;
4868 req = tevent_req_create(mem_ctx, &state, struct oplock5_state);
4872 state->pipe_down_fd = pipe_down_fd;
4874 subreq = cli_ntcreate_send(
4880 SEC_FILE_READ_DATA, /* DesiredAccess */
4881 FILE_ATTRIBUTE_NORMAL, /* FileAttributes */
4882 FILE_SHARE_WRITE|FILE_SHARE_READ, /* ShareAccess */
4883 FILE_OPEN, /* CreateDisposition */
4884 FILE_NON_DIRECTORY_FILE, /* CreateOptions */
4885 0, /* Impersonation */
4886 0); /* SecurityFlags */
4887 if (tevent_req_nomem(subreq, req)) {
4888 return tevent_req_post(req, ev);
4890 tevent_req_set_callback(subreq, oplock5_opened, req);
4892 subreq = cli_echo_send(
4897 (DATA_BLOB) { .data = &data, .length = sizeof(data) });
4898 if (tevent_req_nomem(subreq, req)) {
4899 return tevent_req_post(req, ev);
4901 tevent_req_set_callback(subreq, oplock5_pong, req);
4903 subreq = tevent_wakeup_send(state, ev, timeval_current_ofs(20, 0));
4904 if (tevent_req_nomem(subreq, req)) {
4905 return tevent_req_post(req, ev);
4907 tevent_req_set_callback(subreq, oplock5_timedout, req);
4912 static void oplock5_opened(struct tevent_req *subreq)
4914 struct tevent_req *req = tevent_req_callback_data(
4915 subreq, struct tevent_req);
4919 status = cli_ntcreate_recv(subreq, &fnum, NULL);
4920 TALLOC_FREE(subreq);
4921 if (tevent_req_nterror(req, status)) {
4924 tevent_req_done(req);
4927 static void oplock5_pong(struct tevent_req *subreq)
4929 struct tevent_req *req = tevent_req_callback_data(
4930 subreq, struct tevent_req);
4931 struct oplock5_state *state = tevent_req_data(
4932 req, struct oplock5_state);
4935 status = cli_echo_recv(subreq);
4936 TALLOC_FREE(subreq);
4937 if (tevent_req_nterror(req, status)) {
4941 close(state->pipe_down_fd);
4944 static void oplock5_timedout(struct tevent_req *subreq)
4946 struct tevent_req *req = tevent_req_callback_data(
4947 subreq, struct tevent_req);
4950 ok = tevent_wakeup_recv(subreq);
4951 TALLOC_FREE(subreq);
4953 tevent_req_oom(req);
4956 tevent_req_nterror(req, NT_STATUS_TIMEOUT);
4959 static NTSTATUS oplock5_recv(struct tevent_req *req)
4961 return tevent_req_simple_recv_ntstatus(req);
4964 static bool run_oplock5(int dummy)
4966 struct tevent_context *ev = NULL;
4967 struct tevent_req *req = NULL;
4968 struct cli_state *cli = NULL;
4969 const char *fname = "oplock5.txt";
4970 int pipe_down[2], pipe_up[2];
4977 printf("starting oplock5\n");
4979 if (local_path == NULL) {
4980 d_fprintf(stderr, "oplock5 must be given a local path via "
4981 "-l <localpath>\n");
4985 ret = pipe(pipe_down);
4987 d_fprintf(stderr, "pipe() failed: %s\n", strerror(errno));
4990 ret = pipe(pipe_up);
4992 d_fprintf(stderr, "pipe() failed: %s\n", strerror(errno));
4997 if (child_pid == -1) {
4998 d_fprintf(stderr, "fork() failed: %s\n", strerror(errno));
5002 if (child_pid == 0) {
5003 char *local_file = NULL;
5006 close(pipe_down[1]);
5009 local_file = talloc_asprintf(
5010 talloc_tos(), "%s/%s", local_path, fname);
5011 if (local_file == 0) {
5015 fd = open(local_file, O_RDWR|O_CREAT, 0644);
5018 "open(%s) in child failed: %s\n",
5025 signal(SIGIO, SIG_IGN);
5027 ret = fcntl(fd, F_SETLEASE, F_WRLCK);
5030 "SETLEASE in child failed: %s\n",
5037 ret = sys_write(pipe_up[1], &c, sizeof(c));
5040 "sys_write failed: %s\n",
5044 ret = sys_read(pipe_down[0], &c, sizeof(c));
5047 "sys_read failed: %s\n",
5055 close(pipe_down[0]);
5057 ret = sys_read(pipe_up[0], &c, sizeof(c));
5060 "sys_read failed: %s\n",
5065 d_fprintf(stderr, "got error code %"PRIu8"\n", c);
5069 ok = torture_open_connection(&cli, 0);
5071 d_fprintf(stderr, "torture_open_connection failed\n");
5075 ev = samba_tevent_context_init(talloc_tos());
5077 d_fprintf(stderr, "samba_tevent_context_init failed\n");
5081 req = oplock5_send(ev, ev, cli, fname, pipe_down[1]);
5083 d_fprintf(stderr, "oplock5_send failed\n");
5087 ok = tevent_req_poll_ntstatus(req, ev, &status);
5090 "tevent_req_poll_ntstatus failed: %s\n",
5095 status = oplock5_recv(req);
5097 if (!NT_STATUS_IS_OK(status)) {
5099 "oplock5 failed: %s\n",
5107 #endif /* HAVE_KERNEL_OPLOCKS_LINUX */
5110 Test delete on close semantics.
5112 static bool run_deletetest(int dummy)
5114 struct cli_state *cli1 = NULL;
5115 struct cli_state *cli2 = NULL;
5116 const char *fname = "\\delete.file";
5117 uint16_t fnum1 = (uint16_t)-1;
5118 uint16_t fnum2 = (uint16_t)-1;
5119 bool correct = false;
5122 printf("starting delete test\n");
5124 if (!torture_open_connection(&cli1, 0)) {
5128 smbXcli_conn_set_sockopt(cli1->conn, sockops);
5130 /* Test 1 - this should delete the file on close. */
5132 cli_setatr(cli1, fname, 0, 0);
5133 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5135 status = cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
5136 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
5137 FILE_DELETE_ON_CLOSE, 0, &fnum1, NULL);
5138 if (!NT_STATUS_IS_OK(status)) {
5139 printf("[1] open of %s failed (%s)\n", fname, nt_errstr(status));
5143 status = cli_close(cli1, fnum1);
5144 if (!NT_STATUS_IS_OK(status)) {
5145 printf("[1] close failed (%s)\n", nt_errstr(status));
5149 status = cli_openx(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
5150 if (NT_STATUS_IS_OK(status)) {
5151 printf("[1] open of %s succeeded (should fail)\n", fname);
5155 printf("first delete on close test succeeded.\n");
5157 /* Test 2 - this should delete the file on close. */
5159 cli_setatr(cli1, fname, 0, 0);
5160 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5162 status = cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS,
5163 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5164 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
5165 if (!NT_STATUS_IS_OK(status)) {
5166 printf("[2] open of %s failed (%s)\n", fname, nt_errstr(status));
5170 status = cli_nt_delete_on_close(cli1, fnum1, true);
5171 if (!NT_STATUS_IS_OK(status)) {
5172 printf("[2] setting delete_on_close failed (%s)\n", nt_errstr(status));
5176 status = cli_close(cli1, fnum1);
5177 if (!NT_STATUS_IS_OK(status)) {
5178 printf("[2] close failed (%s)\n", nt_errstr(status));
5182 status = cli_openx(cli1, fname, O_RDONLY, DENY_NONE, &fnum1);
5183 if (NT_STATUS_IS_OK(status)) {
5184 printf("[2] open of %s succeeded should have been deleted on close !\n", fname);
5185 status = cli_close(cli1, fnum1);
5186 if (!NT_STATUS_IS_OK(status)) {
5187 printf("[2] close failed (%s)\n", nt_errstr(status));
5189 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5193 printf("second delete on close test succeeded.\n");
5196 cli_setatr(cli1, fname, 0, 0);
5197 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5199 status = cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS,
5200 FILE_ATTRIBUTE_NORMAL,
5201 FILE_SHARE_READ|FILE_SHARE_WRITE,
5202 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
5203 if (!NT_STATUS_IS_OK(status)) {
5204 printf("[3] open - 1 of %s failed (%s)\n", fname, nt_errstr(status));
5208 /* This should fail with a sharing violation - open for delete is only compatible
5209 with SHARE_DELETE. */
5211 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
5212 FILE_ATTRIBUTE_NORMAL,
5213 FILE_SHARE_READ|FILE_SHARE_WRITE,
5214 FILE_OPEN, 0, 0, &fnum2, NULL);
5215 if (NT_STATUS_IS_OK(status)) {
5216 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname);
5220 /* This should succeed. */
5221 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
5222 FILE_ATTRIBUTE_NORMAL,
5223 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
5224 FILE_OPEN, 0, 0, &fnum2, NULL);
5225 if (!NT_STATUS_IS_OK(status)) {
5226 printf("[3] open - 3 of %s failed (%s)\n", fname, nt_errstr(status));
5230 status = cli_nt_delete_on_close(cli1, fnum1, true);
5231 if (!NT_STATUS_IS_OK(status)) {
5232 printf("[3] setting delete_on_close failed (%s)\n", nt_errstr(status));
5236 status = cli_close(cli1, fnum1);
5237 if (!NT_STATUS_IS_OK(status)) {
5238 printf("[3] close 1 failed (%s)\n", nt_errstr(status));
5242 status = cli_close(cli1, fnum2);
5243 if (!NT_STATUS_IS_OK(status)) {
5244 printf("[3] close 2 failed (%s)\n", nt_errstr(status));
5248 /* This should fail - file should no longer be there. */
5250 status = cli_openx(cli1, fname, O_RDONLY, DENY_NONE, &fnum1);
5251 if (NT_STATUS_IS_OK(status)) {
5252 printf("[3] open of %s succeeded should have been deleted on close !\n", fname);
5253 status = cli_close(cli1, fnum1);
5254 if (!NT_STATUS_IS_OK(status)) {
5255 printf("[3] close failed (%s)\n", nt_errstr(status));
5257 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5261 printf("third delete on close test succeeded.\n");
5264 cli_setatr(cli1, fname, 0, 0);
5265 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5267 status = cli_ntcreate(cli1, fname, 0,
5268 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
5269 FILE_ATTRIBUTE_NORMAL,
5270 FILE_SHARE_READ|FILE_SHARE_WRITE,
5271 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
5272 if (!NT_STATUS_IS_OK(status)) {
5273 printf("[4] open of %s failed (%s)\n", fname, nt_errstr(status));
5277 /* This should succeed. */
5278 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
5279 FILE_ATTRIBUTE_NORMAL,
5280 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
5281 FILE_OPEN, 0, 0, &fnum2, NULL);
5282 if (!NT_STATUS_IS_OK(status)) {
5283 printf("[4] open - 2 of %s failed (%s)\n", fname, nt_errstr(status));
5287 status = cli_close(cli1, fnum2);
5288 if (!NT_STATUS_IS_OK(status)) {
5289 printf("[4] close - 1 failed (%s)\n", nt_errstr(status));
5293 status = cli_nt_delete_on_close(cli1, fnum1, true);
5294 if (!NT_STATUS_IS_OK(status)) {
5295 printf("[4] setting delete_on_close failed (%s)\n", nt_errstr(status));
5299 /* This should fail - no more opens once delete on close set. */
5300 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
5301 FILE_ATTRIBUTE_NORMAL,
5302 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
5303 FILE_OPEN, 0, 0, &fnum2, NULL);
5304 if (NT_STATUS_IS_OK(status)) {
5305 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname );
5309 status = cli_close(cli1, fnum1);
5310 if (!NT_STATUS_IS_OK(status)) {
5311 printf("[4] close - 2 failed (%s)\n", nt_errstr(status));
5315 printf("fourth delete on close test succeeded.\n");
5318 cli_setatr(cli1, fname, 0, 0);
5319 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5321 status = cli_openx(cli1, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum1);
5322 if (!NT_STATUS_IS_OK(status)) {
5323 printf("[5] open of %s failed (%s)\n", fname, nt_errstr(status));
5327 /* This should fail - only allowed on NT opens with DELETE access. */
5329 status = cli_nt_delete_on_close(cli1, fnum1, true);
5330 if (NT_STATUS_IS_OK(status)) {
5331 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
5335 status = cli_close(cli1, fnum1);
5336 if (!NT_STATUS_IS_OK(status)) {
5337 printf("[5] close failed (%s)\n", nt_errstr(status));
5341 printf("fifth delete on close test succeeded.\n");
5344 cli_setatr(cli1, fname, 0, 0);
5345 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5347 status = cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
5348 FILE_ATTRIBUTE_NORMAL,
5349 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
5350 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
5351 if (!NT_STATUS_IS_OK(status)) {
5352 printf("[6] open of %s failed (%s)\n", fname,
5357 /* This should fail - only allowed on NT opens with DELETE access. */
5359 status = cli_nt_delete_on_close(cli1, fnum1, true);
5360 if (NT_STATUS_IS_OK(status)) {
5361 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
5365 status = cli_close(cli1, fnum1);
5366 if (!NT_STATUS_IS_OK(status)) {
5367 printf("[6] close failed (%s)\n", nt_errstr(status));
5371 printf("sixth delete on close test succeeded.\n");
5374 cli_setatr(cli1, fname, 0, 0);
5375 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5377 status = cli_ntcreate(cli1, fname, 0,
5378 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
5379 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
5380 0, 0, &fnum1, NULL);
5381 if (!NT_STATUS_IS_OK(status)) {
5382 printf("[7] open of %s failed (%s)\n", fname, nt_errstr(status));
5386 status = cli_nt_delete_on_close(cli1, fnum1, true);
5387 if (!NT_STATUS_IS_OK(status)) {
5388 printf("[7] setting delete_on_close on file failed !\n");
5392 status = cli_nt_delete_on_close(cli1, fnum1, false);
5393 if (!NT_STATUS_IS_OK(status)) {
5394 printf("[7] unsetting delete_on_close on file failed !\n");
5398 status = cli_close(cli1, fnum1);
5399 if (!NT_STATUS_IS_OK(status)) {
5400 printf("[7] close - 1 failed (%s)\n", nt_errstr(status));
5404 /* This next open should succeed - we reset the flag. */
5405 status = cli_openx(cli1, fname, O_RDONLY, DENY_NONE, &fnum1);
5406 if (!NT_STATUS_IS_OK(status)) {
5407 printf("[7] open of %s failed (%s)\n", fname, nt_errstr(status));
5411 status = cli_close(cli1, fnum1);
5412 if (!NT_STATUS_IS_OK(status)) {
5413 printf("[7] close - 2 failed (%s)\n", nt_errstr(status));
5417 printf("seventh delete on close test succeeded.\n");
5420 cli_setatr(cli1, fname, 0, 0);
5421 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5423 if (!torture_open_connection(&cli2, 1)) {
5424 printf("[8] failed to open second connection.\n");
5428 smbXcli_conn_set_sockopt(cli1->conn, sockops);
5430 status = cli_ntcreate(cli1, fname, 0,
5431 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
5432 FILE_ATTRIBUTE_NORMAL,
5433 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
5434 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
5435 if (!NT_STATUS_IS_OK(status)) {
5436 printf("[8] open 1 of %s failed (%s)\n", fname, nt_errstr(status));
5440 status = cli_ntcreate(cli2, fname, 0,
5441 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
5442 FILE_ATTRIBUTE_NORMAL,
5443 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
5444 FILE_OPEN, 0, 0, &fnum2, NULL);
5445 if (!NT_STATUS_IS_OK(status)) {
5446 printf("[8] open 2 of %s failed (%s)\n", fname, nt_errstr(status));
5450 status = cli_nt_delete_on_close(cli1, fnum1, true);
5451 if (!NT_STATUS_IS_OK(status)) {
5452 printf("[8] setting delete_on_close on file failed !\n");
5456 status = cli_close(cli1, fnum1);
5457 if (!NT_STATUS_IS_OK(status)) {
5458 printf("[8] close - 1 failed (%s)\n", nt_errstr(status));
5462 status = cli_close(cli2, fnum2);
5463 if (!NT_STATUS_IS_OK(status)) {
5464 printf("[8] close - 2 failed (%s)\n", nt_errstr(status));
5468 /* This should fail.. */
5469 status = cli_openx(cli1, fname, O_RDONLY, DENY_NONE, &fnum1);
5470 if (NT_STATUS_IS_OK(status)) {
5471 printf("[8] open of %s succeeded should have been deleted on close !\n", fname);
5475 printf("eighth delete on close test succeeded.\n");
5479 /* This should fail - we need to set DELETE_ACCESS. */
5480 status = cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
5481 FILE_ATTRIBUTE_NORMAL,
5484 FILE_DELETE_ON_CLOSE, 0, &fnum1, NULL);
5485 if (NT_STATUS_IS_OK(status)) {
5486 printf("[9] open of %s succeeded should have failed!\n", fname);
5490 printf("ninth delete on close test succeeded.\n");
5494 status = cli_ntcreate(cli1, fname, 0,
5495 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
5496 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5497 FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE,
5499 if (!NT_STATUS_IS_OK(status)) {
5500 printf("[10] open of %s failed (%s)\n", fname, nt_errstr(status));
5504 /* This should delete the file. */
5505 status = cli_close(cli1, fnum1);
5506 if (!NT_STATUS_IS_OK(status)) {
5507 printf("[10] close failed (%s)\n", nt_errstr(status));
5511 /* This should fail.. */
5512 status = cli_openx(cli1, fname, O_RDONLY, DENY_NONE, &fnum1);
5513 if (NT_STATUS_IS_OK(status)) {
5514 printf("[10] open of %s succeeded should have been deleted on close !\n", fname);
5518 printf("tenth delete on close test succeeded.\n");
5522 cli_setatr(cli1, fname, 0, 0);
5523 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5525 /* Can we open a read-only file with delete access? */
5527 /* Create a readonly file. */
5528 status = cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
5529 FILE_ATTRIBUTE_READONLY, FILE_SHARE_NONE,
5530 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
5531 if (!NT_STATUS_IS_OK(status)) {
5532 printf("[11] open of %s failed (%s)\n", fname, nt_errstr(status));
5536 status = cli_close(cli1, fnum1);
5537 if (!NT_STATUS_IS_OK(status)) {
5538 printf("[11] close failed (%s)\n", nt_errstr(status));
5542 /* Now try open for delete access. */
5543 status = cli_ntcreate(cli1, fname, 0,
5544 FILE_READ_ATTRIBUTES|DELETE_ACCESS,
5546 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
5547 FILE_OPEN, 0, 0, &fnum1, NULL);
5548 if (!NT_STATUS_IS_OK(status)) {
5549 printf("[11] open of %s failed: %s\n", fname, nt_errstr(status));
5553 cli_close(cli1, fnum1);
5555 printf("eleventh delete on close test succeeded.\n");
5559 * like test 4 but with initial delete on close
5562 cli_setatr(cli1, fname, 0, 0);
5563 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5565 status = cli_ntcreate(cli1, fname, 0,
5566 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
5567 FILE_ATTRIBUTE_NORMAL,
5568 FILE_SHARE_READ|FILE_SHARE_WRITE,
5570 FILE_DELETE_ON_CLOSE, 0, &fnum1, NULL);
5571 if (!NT_STATUS_IS_OK(status)) {
5572 printf("[12] open 1 of %s failed (%s)\n", fname, nt_errstr(status));
5576 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
5577 FILE_ATTRIBUTE_NORMAL,
5578 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
5579 FILE_OPEN, 0, 0, &fnum2, NULL);
5580 if (!NT_STATUS_IS_OK(status)) {
5581 printf("[12] open 2 of %s failed(%s).\n", fname, nt_errstr(status));
5585 status = cli_close(cli1, fnum2);
5586 if (!NT_STATUS_IS_OK(status)) {
5587 printf("[12] close 1 failed (%s)\n", nt_errstr(status));
5591 status = cli_nt_delete_on_close(cli1, fnum1, true);
5592 if (!NT_STATUS_IS_OK(status)) {
5593 printf("[12] setting delete_on_close failed (%s)\n", nt_errstr(status));
5597 /* This should fail - no more opens once delete on close set. */
5598 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
5599 FILE_ATTRIBUTE_NORMAL,
5600 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
5601 FILE_OPEN, 0, 0, &fnum2, NULL);
5602 if (NT_STATUS_IS_OK(status)) {
5603 printf("[12] open 3 of %s succeeded - should fail).\n", fname);
5607 status = cli_nt_delete_on_close(cli1, fnum1, false);
5608 if (!NT_STATUS_IS_OK(status)) {
5609 printf("[12] unsetting delete_on_close failed (%s)\n", nt_errstr(status));
5613 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
5614 FILE_ATTRIBUTE_NORMAL,
5615 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
5616 FILE_OPEN, 0, 0, &fnum2, NULL);
5617 if (!NT_STATUS_IS_OK(status)) {
5618 printf("[12] open 4 of %s failed (%s)\n", fname, nt_errstr(status));
5622 status = cli_close(cli1, fnum2);
5623 if (!NT_STATUS_IS_OK(status)) {
5624 printf("[12] close 2 failed (%s)\n", nt_errstr(status));
5628 status = cli_close(cli1, fnum1);
5629 if (!NT_STATUS_IS_OK(status)) {
5630 printf("[12] close 3 failed (%s)\n", nt_errstr(status));
5635 * setting delete on close on the handle does
5636 * not unset the initial delete on close...
5638 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
5639 FILE_ATTRIBUTE_NORMAL,
5640 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
5641 FILE_OPEN, 0, 0, &fnum2, NULL);
5642 if (NT_STATUS_IS_OK(status)) {
5643 printf("[12] open 5 of %s succeeded - should fail).\n", fname);
5645 } else if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
5646 printf("ntcreate returned %s, expected "
5647 "NT_STATUS_OBJECT_NAME_NOT_FOUND\n",
5652 printf("twelfth delete on close test succeeded.\n");
5655 printf("finished delete test\n");
5660 /* FIXME: This will crash if we aborted before cli2 got
5661 * intialized, because these functions don't handle
5662 * uninitialized connections. */
5664 if (fnum1 != (uint16_t)-1) cli_close(cli1, fnum1);
5665 if (fnum2 != (uint16_t)-1) cli_close(cli1, fnum2);
5666 cli_setatr(cli1, fname, 0, 0);
5667 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5669 if (cli1 && !torture_close_connection(cli1)) {
5672 if (cli2 && !torture_close_connection(cli2)) {
5678 struct delete_stream_state {
5682 static void delete_stream_unlinked(struct tevent_req *subreq);
5683 static void delete_stream_closed(struct tevent_req *subreq);
5685 static struct tevent_req *delete_stream_send(
5686 TALLOC_CTX *mem_ctx,
5687 struct tevent_context *ev,
5688 struct cli_state *cli,
5689 const char *base_fname,
5690 uint16_t stream_fnum)
5692 struct tevent_req *req = NULL, *subreq = NULL;
5693 struct delete_stream_state *state = NULL;
5695 req = tevent_req_create(
5696 mem_ctx, &state, struct delete_stream_state);
5701 subreq = cli_unlink_send(
5706 FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5707 if (tevent_req_nomem(subreq, req)) {
5708 return tevent_req_post(req, ev);
5710 tevent_req_set_callback(subreq, delete_stream_unlinked, req);
5712 subreq = cli_close_send(state, ev, cli, stream_fnum);
5713 if (tevent_req_nomem(subreq, req)) {
5714 return tevent_req_post(req, ev);
5716 tevent_req_set_callback(subreq, delete_stream_closed, req);
5721 static void delete_stream_unlinked(struct tevent_req *subreq)
5723 struct tevent_req *req = tevent_req_callback_data(
5724 subreq, struct tevent_req);
5725 struct delete_stream_state *state = tevent_req_data(
5726 req, struct delete_stream_state);
5729 status = cli_unlink_recv(subreq);
5730 TALLOC_FREE(subreq);
5731 if (!NT_STATUS_EQUAL(status, NT_STATUS_SHARING_VIOLATION)) {
5732 printf("cli_unlink returned %s\n",
5734 tevent_req_nterror(req, NT_STATUS_UNSUCCESSFUL);
5737 if (!state->closed) {
5738 /* close reply should have come in first */
5739 printf("Not closed\n");
5740 tevent_req_nterror(req, NT_STATUS_UNSUCCESSFUL);
5743 tevent_req_done(req);
5746 static void delete_stream_closed(struct tevent_req *subreq)
5748 struct tevent_req *req = tevent_req_callback_data(
5749 subreq, struct tevent_req);
5750 struct delete_stream_state *state = tevent_req_data(
5751 req, struct delete_stream_state);
5754 status = cli_close_recv(subreq);
5755 TALLOC_FREE(subreq);
5756 if (tevent_req_nterror(req, status)) {
5759 /* also waiting for the unlink to come back */
5760 state->closed = true;
5763 static NTSTATUS delete_stream_recv(struct tevent_req *req)
5765 return tevent_req_simple_recv_ntstatus(req);
5768 static bool run_delete_stream(int dummy)
5770 struct tevent_context *ev = NULL;
5771 struct tevent_req *req = NULL;
5772 struct cli_state *cli = NULL;
5773 const char fname[] = "delete_stream";
5774 const char fname_stream[] = "delete_stream:Zone.Identifier:$DATA";
5775 uint16_t fnum1, fnum2;
5779 printf("Starting stream delete test\n");
5781 ok = torture_open_connection(&cli, 0);
5786 cli_setatr(cli, fname, 0, 0);
5787 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5789 /* Create the file. */
5790 status = cli_ntcreate(
5794 READ_CONTROL_ACCESS,
5796 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
5802 if (!NT_STATUS_IS_OK(status)) {
5804 "cli_ntcreate of %s failed (%s)\n",
5809 status = cli_close(cli, fnum1);
5810 if (!NT_STATUS_IS_OK(status)) {
5812 "cli_close of %s failed (%s)\n",
5818 /* Now create the stream. */
5819 status = cli_ntcreate(
5825 FILE_SHARE_READ|FILE_SHARE_WRITE,
5832 if (!NT_STATUS_IS_OK(status)) {
5834 "cli_ntcreate of %s failed (%s)\n",
5840 /* open it a second time */
5842 status = cli_ntcreate(
5848 FILE_SHARE_READ|FILE_SHARE_WRITE,
5855 if (!NT_STATUS_IS_OK(status)) {
5857 "2nd cli_ntcreate of %s failed (%s)\n",
5863 ev = samba_tevent_context_init(talloc_tos());
5865 d_fprintf(stderr, "samba_tevent_context_init failed\n");
5869 req = delete_stream_send(ev, ev, cli, fname, fnum1);
5871 d_fprintf(stderr, "delete_stream_send failed\n");
5875 ok = tevent_req_poll_ntstatus(req, ev, &status);
5878 "tevent_req_poll_ntstatus failed: %s\n",
5883 status = delete_stream_recv(req);
5885 if (!NT_STATUS_IS_OK(status)) {
5887 "delete_stream failed: %s\n",
5892 status = cli_close(cli, fnum2);
5893 if (!NT_STATUS_IS_OK(status)) {
5895 "close failed: %s\n",
5900 status = cli_unlink(
5901 cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5902 if (!NT_STATUS_IS_OK(status)) {
5904 "unlink failed: %s\n",
5913 Exercise delete on close semantics - use on the PRINT1 share in torture
5916 static bool run_delete_print_test(int dummy)
5918 struct cli_state *cli1 = NULL;
5919 const char *fname = "print_delete.file";
5920 uint16_t fnum1 = (uint16_t)-1;
5921 bool correct = false;
5922 const char *buf = "print file data\n";
5925 printf("starting print delete test\n");
5927 if (!torture_open_connection(&cli1, 0)) {
5931 smbXcli_conn_set_sockopt(cli1->conn, sockops);
5933 status = cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
5934 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
5935 0, 0, &fnum1, NULL);
5936 if (!NT_STATUS_IS_OK(status)) {
5937 printf("open of %s failed (%s)\n",
5943 status = cli_writeall(cli1,
5946 (const uint8_t *)buf,
5948 strlen(buf), /* size */
5950 if (!NT_STATUS_IS_OK(status)) {
5951 printf("writing print file data failed (%s)\n",
5956 status = cli_nt_delete_on_close(cli1, fnum1, true);
5957 if (!NT_STATUS_IS_OK(status)) {
5958 printf("setting delete_on_close failed (%s)\n",
5963 status = cli_close(cli1, fnum1);
5964 if (!NT_STATUS_IS_OK(status)) {
5965 printf("close failed (%s)\n", nt_errstr(status));
5969 printf("finished print delete test\n");
5975 if (fnum1 != (uint16_t)-1) {
5976 cli_close(cli1, fnum1);
5979 if (cli1 && !torture_close_connection(cli1)) {
5986 Test wildcard delete.
5988 static bool run_wild_deletetest(int dummy)
5990 struct cli_state *cli = NULL;
5991 const char *dname = "\\WTEST";
5992 const char *fname = "\\WTEST\\A";
5993 const char *wunlink_name = "\\WTEST\\*";
5994 uint16_t fnum1 = (uint16_t)-1;
5995 bool correct = false;
5998 printf("starting wildcard delete test\n");
6000 if (!torture_open_connection(&cli, 0)) {
6004 smbXcli_conn_set_sockopt(cli->conn, sockops);
6006 cli_unlink(cli, fname, 0);
6007 cli_rmdir(cli, dname);
6008 status = cli_mkdir(cli, dname);
6009 if (!NT_STATUS_IS_OK(status)) {
6010 printf("mkdir of %s failed %s!\n", dname, nt_errstr(status));
6013 status = cli_openx(cli, fname, O_CREAT|O_RDONLY, DENY_NONE, &fnum1);
6014 if (!NT_STATUS_IS_OK(status)) {
6015 printf("open of %s failed %s!\n", fname, nt_errstr(status));
6018 status = cli_close(cli, fnum1);
6022 * Note the unlink attribute-type of zero. This should
6023 * map into FILE_ATTRIBUTE_NORMAL at the server even
6024 * on a wildcard delete.
6027 status = cli_unlink(cli, wunlink_name, 0);
6028 if (!NT_STATUS_IS_OK(status)) {
6029 printf("unlink of %s failed %s!\n",
6030 wunlink_name, nt_errstr(status));
6034 printf("finished wildcard delete test\n");
6040 if (fnum1 != (uint16_t)-1) cli_close(cli, fnum1);
6041 cli_unlink(cli, fname, 0);
6042 cli_rmdir(cli, dname);
6044 if (cli && !torture_close_connection(cli)) {
6050 static bool run_deletetest_ln(int dummy)
6052 struct cli_state *cli;
6053 const char *fname = "\\delete1";
6054 const char *fname_ln = "\\delete1_ln";
6058 bool correct = true;
6061 printf("starting deletetest-ln\n");
6063 if (!torture_open_connection(&cli, 0)) {
6067 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
6068 cli_unlink(cli, fname_ln, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
6070 smbXcli_conn_set_sockopt(cli->conn, sockops);
6072 /* Create the file. */
6073 status = cli_openx(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
6074 if (!NT_STATUS_IS_OK(status)) {
6075 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
6079 status = cli_close(cli, fnum);
6080 if (!NT_STATUS_IS_OK(status)) {
6081 printf("close1 failed (%s)\n", nt_errstr(status));
6085 /* Now create a hardlink. */
6086 status = cli_hardlink(cli, fname, fname_ln);
6087 if (!NT_STATUS_IS_OK(status)) {
6088 printf("nt hardlink failed (%s)\n", nt_errstr(status));
6092 /* Open the original file. */
6093 status = cli_ntcreate(cli, fname, 0, FILE_READ_DATA,
6094 FILE_ATTRIBUTE_NORMAL,
6095 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
6096 FILE_OPEN_IF, 0, 0, &fnum, NULL);
6097 if (!NT_STATUS_IS_OK(status)) {
6098 printf("ntcreate of %s failed (%s)\n", fname, nt_errstr(status));
6102 /* Unlink the hard link path. */
6103 status = cli_ntcreate(cli, fname_ln, 0, DELETE_ACCESS,
6104 FILE_ATTRIBUTE_NORMAL,
6105 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
6106 FILE_OPEN_IF, 0, 0, &fnum1, NULL);
6107 if (!NT_STATUS_IS_OK(status)) {
6108 printf("ntcreate of %s failed (%s)\n", fname_ln, nt_errstr(status));
6111 status = cli_nt_delete_on_close(cli, fnum1, true);
6112 if (!NT_STATUS_IS_OK(status)) {
6113 d_printf("(%s) failed to set delete_on_close %s: %s\n",
6114 __location__, fname_ln, nt_errstr(status));
6118 status = cli_close(cli, fnum1);
6119 if (!NT_STATUS_IS_OK(status)) {
6120 printf("close %s failed (%s)\n",
6121 fname_ln, nt_errstr(status));
6125 status = cli_close(cli, fnum);
6126 if (!NT_STATUS_IS_OK(status)) {
6127 printf("close %s failed (%s)\n",
6128 fname, nt_errstr(status));
6132 /* Ensure the original file is still there. */
6133 status = cli_getatr(cli, fname, NULL, NULL, &t);
6134 if (!NT_STATUS_IS_OK(status)) {
6135 printf("%s getatr on file %s failed (%s)\n",
6142 /* Ensure the link path is gone. */
6143 status = cli_getatr(cli, fname_ln, NULL, NULL, &t);
6144 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
6145 printf("%s, getatr for file %s returned wrong error code %s "
6146 "- should have been deleted\n",
6148 fname_ln, nt_errstr(status));
6152 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
6153 cli_unlink(cli, fname_ln, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
6155 if (!torture_close_connection(cli)) {
6159 printf("finished deletetest-ln\n");
6165 print out server properties
6167 static bool run_properties(int dummy)
6169 struct cli_state *cli;
6170 bool correct = True;
6172 printf("starting properties test\n");
6176 if (!torture_open_connection(&cli, 0)) {
6180 smbXcli_conn_set_sockopt(cli->conn, sockops);
6182 d_printf("Capabilities 0x%08x\n", smb1cli_conn_capabilities(cli->conn));
6184 if (!torture_close_connection(cli)) {
6193 /* FIRST_DESIRED_ACCESS 0xf019f */
6194 #define FIRST_DESIRED_ACCESS FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|\
6195 FILE_READ_EA| /* 0xf */ \
6196 FILE_WRITE_EA|FILE_READ_ATTRIBUTES| /* 0x90 */ \
6197 FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
6198 DELETE_ACCESS|READ_CONTROL_ACCESS|\
6199 WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS /* 0xf0000 */
6200 /* SECOND_DESIRED_ACCESS 0xe0080 */
6201 #define SECOND_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
6202 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
6203 WRITE_OWNER_ACCESS /* 0xe0000 */
6206 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
6207 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
6209 WRITE_OWNER_ACCESS /* */
6213 Test ntcreate calls made by xcopy
6215 static bool run_xcopy(int dummy)
6217 static struct cli_state *cli1;
6218 const char *fname = "\\test.txt";
6219 bool correct = True;
6220 uint16_t fnum1, fnum2;
6223 printf("starting xcopy test\n");
6225 if (!torture_open_connection(&cli1, 0)) {
6229 status = cli_ntcreate(cli1, fname, 0, FIRST_DESIRED_ACCESS,
6230 FILE_ATTRIBUTE_ARCHIVE, FILE_SHARE_NONE,
6231 FILE_OVERWRITE_IF, 0x4044, 0, &fnum1, NULL);
6232 if (!NT_STATUS_IS_OK(status)) {
6233 printf("First open failed - %s\n", nt_errstr(status));
6237 status = cli_ntcreate(cli1, fname, 0, SECOND_DESIRED_ACCESS, 0,
6238 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
6239 FILE_OPEN, 0x200000, 0, &fnum2, NULL);
6240 if (!NT_STATUS_IS_OK(status)) {
6241 printf("second open failed - %s\n", nt_errstr(status));
6245 if (!torture_close_connection(cli1)) {
6253 Test rename on files open with share delete and no share delete.
6255 static bool run_rename(int dummy)
6257 static struct cli_state *cli1;
6258 const char *fname = "\\test.txt";
6259 const char *fname1 = "\\test1.txt";
6260 bool correct = True;
6265 printf("starting rename test\n");
6267 if (!torture_open_connection(&cli1, 0)) {
6271 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
6272 cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
6274 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
6275 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ,
6276 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
6277 if (!NT_STATUS_IS_OK(status)) {
6278 printf("First open failed - %s\n", nt_errstr(status));
6282 status = cli_rename(cli1, fname, fname1, false);
6283 if (!NT_STATUS_IS_OK(status)) {
6284 printf("First rename failed (SHARE_READ) (this is correct) - %s\n", nt_errstr(status));
6286 printf("First rename succeeded (SHARE_READ) - this should have failed !\n");
6290 status = cli_close(cli1, fnum1);
6291 if (!NT_STATUS_IS_OK(status)) {
6292 printf("close - 1 failed (%s)\n", nt_errstr(status));
6296 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
6297 cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
6298 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
6300 FILE_SHARE_DELETE|FILE_SHARE_NONE,
6302 FILE_SHARE_DELETE|FILE_SHARE_READ,
6304 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
6305 if (!NT_STATUS_IS_OK(status)) {
6306 printf("Second open failed - %s\n", nt_errstr(status));
6310 status = cli_rename(cli1, fname, fname1, false);
6311 if (!NT_STATUS_IS_OK(status)) {
6312 printf("Second rename failed (SHARE_DELETE | SHARE_READ) - this should have succeeded - %s\n", nt_errstr(status));
6315 printf("Second rename succeeded (SHARE_DELETE | SHARE_READ)\n");
6318 status = cli_close(cli1, fnum1);
6319 if (!NT_STATUS_IS_OK(status)) {
6320 printf("close - 2 failed (%s)\n", nt_errstr(status));
6324 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
6325 cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
6327 status = cli_ntcreate(cli1, fname, 0, READ_CONTROL_ACCESS,
6328 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
6329 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
6330 if (!NT_STATUS_IS_OK(status)) {
6331 printf("Third open failed - %s\n", nt_errstr(status));
6340 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
6341 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum2, NULL))) {
6342 printf("Fourth open failed - %s\n", cli_errstr(cli1));
6345 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum2, true))) {
6346 printf("[8] setting delete_on_close on file failed !\n");
6350 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum2))) {
6351 printf("close - 4 failed (%s)\n", cli_errstr(cli1));
6357 status = cli_rename(cli1, fname, fname1, false);
6358 if (!NT_STATUS_IS_OK(status)) {
6359 printf("Third rename failed (SHARE_NONE) - this should have succeeded - %s\n", nt_errstr(status));
6362 printf("Third rename succeeded (SHARE_NONE)\n");
6365 status = cli_close(cli1, fnum1);
6366 if (!NT_STATUS_IS_OK(status)) {
6367 printf("close - 3 failed (%s)\n", nt_errstr(status));
6371 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
6372 cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
6376 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
6377 FILE_ATTRIBUTE_NORMAL,
6378 FILE_SHARE_READ | FILE_SHARE_WRITE,
6379 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
6380 if (!NT_STATUS_IS_OK(status)) {
6381 printf("Fourth open failed - %s\n", nt_errstr(status));
6385 status = cli_rename(cli1, fname, fname1, false);
6386 if (!NT_STATUS_IS_OK(status)) {
6387 printf("Fourth rename failed (SHARE_READ | SHARE_WRITE) (this is correct) - %s\n", nt_errstr(status));
6389 printf("Fourth rename succeeded (SHARE_READ | SHARE_WRITE) - this should have failed !\n");
6393 status = cli_close(cli1, fnum1);
6394 if (!NT_STATUS_IS_OK(status)) {
6395 printf("close - 4 failed (%s)\n", nt_errstr(status));
6399 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
6400 cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
6404 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
6405 FILE_ATTRIBUTE_NORMAL,
6406 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
6407 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
6408 if (!NT_STATUS_IS_OK(status)) {
6409 printf("Fifth open failed - %s\n", nt_errstr(status));
6413 status = cli_rename(cli1, fname, fname1, false);
6414 if (!NT_STATUS_IS_OK(status)) {
6415 printf("Fifth rename failed (SHARE_READ | SHARE_WRITE | SHARE_DELETE) - this should have succeeded - %s ! \n", nt_errstr(status));
6418 printf("Fifth rename succeeded (SHARE_READ | SHARE_WRITE | SHARE_DELETE) (this is correct) - %s\n", nt_errstr(status));
6422 * Now check if the first name still exists ...
6425 /* if (!NT_STATUS_OP(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
6426 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
6427 FILE_OVERWRITE_IF, 0, 0, &fnum2, NULL))) {
6428 printf("Opening original file after rename of open file fails: %s\n",
6432 printf("Opening original file after rename of open file works ...\n");
6433 (void)cli_close(cli1, fnum2);
6437 status = cli_close(cli1, fnum1);
6438 if (!NT_STATUS_IS_OK(status)) {
6439 printf("close - 5 failed (%s)\n", nt_errstr(status));
6443 /* Check that the renamed file has FILE_ATTRIBUTE_ARCHIVE. */
6444 status = cli_getatr(cli1, fname1, &attr, NULL, NULL);
6445 if (!NT_STATUS_IS_OK(status)) {
6446 printf("getatr on file %s failed - %s ! \n",
6447 fname1, nt_errstr(status));
6450 if (attr != FILE_ATTRIBUTE_ARCHIVE) {
6451 printf("Renamed file %s has wrong attr 0x%x "
6452 "(should be 0x%x)\n",
6455 (unsigned int)FILE_ATTRIBUTE_ARCHIVE);
6458 printf("Renamed file %s has archive bit set\n", fname1);
6462 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
6463 cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
6465 if (!torture_close_connection(cli1)) {
6473 Test rename into a directory with an ACL denying it.
6475 static bool run_rename_access(int dummy)
6477 static struct cli_state *cli = NULL;
6478 static struct cli_state *posix_cli = NULL;
6479 const char *src = "test.txt";
6480 const char *dname = "dir";
6481 const char *dst = "dir\\test.txt";
6482 const char *dsrc = "test.dir";
6483 const char *ddst = "dir\\test.dir";
6484 uint16_t fnum = (uint16_t)-1;
6485 struct security_descriptor *sd = NULL;
6486 struct security_descriptor *newsd = NULL;
6488 TALLOC_CTX *frame = NULL;
6490 frame = talloc_stackframe();
6491 printf("starting rename access test\n");
6493 /* Windows connection. */
6494 if (!torture_open_connection(&cli, 0)) {
6498 smbXcli_conn_set_sockopt(cli->conn, sockops);
6500 /* Posix connection. */
6501 if (!torture_open_connection(&posix_cli, 0)) {
6505 smbXcli_conn_set_sockopt(posix_cli->conn, sockops);
6507 status = torture_setup_unix_extensions(posix_cli);
6508 if (!NT_STATUS_IS_OK(status)) {
6512 /* Start with a clean slate. */
6513 cli_unlink(cli, src, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
6514 cli_unlink(cli, dst, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
6515 cli_rmdir(cli, dsrc);
6516 cli_rmdir(cli, ddst);
6517 cli_rmdir(cli, dname);
6520 * Setup the destination directory with a DENY ACE to
6521 * prevent new files within it.
6523 status = cli_ntcreate(cli,
6526 FILE_READ_ATTRIBUTES|READ_CONTROL_ACCESS|
6527 WRITE_DAC_ACCESS|FILE_READ_DATA|
6529 FILE_ATTRIBUTE_DIRECTORY,
6530 FILE_SHARE_READ|FILE_SHARE_WRITE,
6532 FILE_DIRECTORY_FILE,
6536 if (!NT_STATUS_IS_OK(status)) {
6537 printf("Create of %s - %s\n", dname, nt_errstr(status));
6541 status = cli_query_secdesc(cli,
6545 if (!NT_STATUS_IS_OK(status)) {
6546 printf("cli_query_secdesc failed for %s (%s)\n",
6547 dname, nt_errstr(status));
6551 newsd = security_descriptor_dacl_create(frame,
6556 SEC_ACE_TYPE_ACCESS_DENIED,
6557 SEC_DIR_ADD_FILE|SEC_DIR_ADD_SUBDIR,
6560 if (newsd == NULL) {
6563 sd->dacl = security_acl_concatenate(frame,
6566 if (sd->dacl == NULL) {
6569 status = cli_set_secdesc(cli, fnum, sd);
6570 if (!NT_STATUS_IS_OK(status)) {
6571 printf("cli_set_secdesc failed for %s (%s)\n",
6572 dname, nt_errstr(status));
6575 status = cli_close(cli, fnum);
6576 if (!NT_STATUS_IS_OK(status)) {
6577 printf("close failed for %s (%s)\n",
6578 dname, nt_errstr(status));
6581 /* Now go around the back and chmod to 777 via POSIX. */
6582 status = cli_posix_chmod(posix_cli, dname, 0777);
6583 if (!NT_STATUS_IS_OK(status)) {
6584 printf("cli_posix_chmod failed for %s (%s)\n",
6585 dname, nt_errstr(status));
6589 /* Check we can't create a file within dname via Windows. */
6590 status = cli_openx(cli, dst, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
6591 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
6592 cli_close(posix_cli, fnum);
6593 printf("Create of %s should be ACCESS denied, was %s\n",
6594 dst, nt_errstr(status));
6598 /* Make the sample file/directory. */
6599 status = cli_openx(cli, src, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
6600 if (!NT_STATUS_IS_OK(status)) {
6601 printf("open of %s failed (%s)\n", src, nt_errstr(status));
6604 status = cli_close(cli, fnum);
6605 if (!NT_STATUS_IS_OK(status)) {
6606 printf("cli_close failed (%s)\n", nt_errstr(status));
6610 status = cli_mkdir(cli, dsrc);
6611 if (!NT_STATUS_IS_OK(status)) {
6612 printf("cli_mkdir of %s failed (%s)\n",
6613 dsrc, nt_errstr(status));
6618 * OK - renames of the new file and directory into the
6619 * dst directory should fail.
6622 status = cli_rename(cli, src, dst, false);
6623 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
6624 printf("rename of %s -> %s should be ACCESS denied, was %s\n",
6625 src, dst, nt_errstr(status));
6628 status = cli_rename(cli, dsrc, ddst, false);
6629 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
6630 printf("rename of %s -> %s should be ACCESS denied, was %s\n",
6631 src, dst, nt_errstr(status));
6641 torture_close_connection(posix_cli);
6645 if (fnum != (uint16_t)-1) {
6646 cli_close(cli, fnum);
6648 cli_unlink(cli, src,
6649 FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
6650 cli_unlink(cli, dst,
6651 FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
6652 cli_rmdir(cli, dsrc);
6653 cli_rmdir(cli, ddst);
6654 cli_rmdir(cli, dname);
6656 torture_close_connection(cli);
6664 Test owner rights ACE.
6666 static bool run_owner_rights(int dummy)
6668 static struct cli_state *cli = NULL;
6669 const char *fname = "owner_rights.txt";
6670 uint16_t fnum = (uint16_t)-1;
6671 struct security_descriptor *sd = NULL;
6672 struct security_descriptor *newsd = NULL;
6674 TALLOC_CTX *frame = NULL;
6676 frame = talloc_stackframe();
6677 printf("starting owner rights test\n");
6679 /* Windows connection. */
6680 if (!torture_open_connection(&cli, 0)) {
6684 smbXcli_conn_set_sockopt(cli->conn, sockops);
6686 /* Start with a clean slate. */
6687 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
6689 /* Create the test file. */
6690 /* Now try and open for read and write-dac. */
6691 status = cli_ntcreate(cli,
6695 FILE_ATTRIBUTE_NORMAL,
6696 FILE_SHARE_READ|FILE_SHARE_WRITE|
6703 if (!NT_STATUS_IS_OK(status)) {
6704 printf("Create of %s - %s\n", fname, nt_errstr(status));
6708 /* Get the original SD. */
6709 status = cli_query_secdesc(cli,
6713 if (!NT_STATUS_IS_OK(status)) {
6714 printf("cli_query_secdesc failed for %s (%s)\n",
6715 fname, nt_errstr(status));
6720 * Add an "owner-rights" ACE denying WRITE_DATA,
6721 * and an "owner-rights" ACE allowing READ_DATA.
6724 newsd = security_descriptor_dacl_create(frame,
6729 SEC_ACE_TYPE_ACCESS_DENIED,
6733 SEC_ACE_TYPE_ACCESS_ALLOWED,
6737 if (newsd == NULL) {
6740 sd->dacl = security_acl_concatenate(frame,
6743 if (sd->dacl == NULL) {
6746 status = cli_set_secdesc(cli, fnum, sd);
6747 if (!NT_STATUS_IS_OK(status)) {
6748 printf("cli_set_secdesc failed for %s (%s)\n",
6749 fname, nt_errstr(status));
6752 status = cli_close(cli, fnum);
6753 if (!NT_STATUS_IS_OK(status)) {
6754 printf("close failed for %s (%s)\n",
6755 fname, nt_errstr(status));
6758 fnum = (uint16_t)-1;
6760 /* Try and open for FILE_WRITE_DATA */
6761 status = cli_ntcreate(cli,
6765 FILE_ATTRIBUTE_NORMAL,
6766 FILE_SHARE_READ|FILE_SHARE_WRITE|
6773 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
6774 printf("Open of %s - %s\n", fname, nt_errstr(status));
6778 /* Now try and open for FILE_READ_DATA */
6779 status = cli_ntcreate(cli,
6783 FILE_ATTRIBUTE_NORMAL,
6784 FILE_SHARE_READ|FILE_SHARE_WRITE|
6791 if (!NT_STATUS_IS_OK(status)) {
6792 printf("Open of %s - %s\n", fname, nt_errstr(status));
6796 status = cli_close(cli, fnum);
6797 if (!NT_STATUS_IS_OK(status)) {
6798 printf("close failed for %s (%s)\n",
6799 fname, nt_errstr(status));
6803 /* Restore clean slate. */
6805 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
6807 /* Create the test file. */
6808 status = cli_ntcreate(cli,
6812 FILE_ATTRIBUTE_NORMAL,
6813 FILE_SHARE_READ|FILE_SHARE_WRITE|
6820 if (!NT_STATUS_IS_OK(status)) {
6821 printf("Create of %s - %s\n", fname, nt_errstr(status));
6825 /* Get the original SD. */
6826 status = cli_query_secdesc(cli,
6830 if (!NT_STATUS_IS_OK(status)) {
6831 printf("cli_query_secdesc failed for %s (%s)\n",
6832 fname, nt_errstr(status));
6837 * Add an "owner-rights ACE denying WRITE_DATA,
6838 * and an "owner-rights ACE allowing READ_DATA|WRITE_DATA.
6841 newsd = security_descriptor_dacl_create(frame,
6846 SEC_ACE_TYPE_ACCESS_DENIED,
6850 SEC_ACE_TYPE_ACCESS_ALLOWED,
6851 FILE_READ_DATA|FILE_WRITE_DATA,
6854 if (newsd == NULL) {
6857 sd->dacl = security_acl_concatenate(frame,
6860 if (sd->dacl == NULL) {
6863 status = cli_set_secdesc(cli, fnum, sd);
6864 if (!NT_STATUS_IS_OK(status)) {
6865 printf("cli_set_secdesc failed for %s (%s)\n",
6866 fname, nt_errstr(status));
6869 status = cli_close(cli, fnum);
6870 if (!NT_STATUS_IS_OK(status)) {
6871 printf("close failed for %s (%s)\n",
6872 fname, nt_errstr(status));
6875 fnum = (uint16_t)-1;
6877 /* Try and open for FILE_WRITE_DATA */
6878 status = cli_ntcreate(cli,
6882 FILE_ATTRIBUTE_NORMAL,
6883 FILE_SHARE_READ|FILE_SHARE_WRITE|
6890 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
6891 printf("Open of %s - %s\n", fname, nt_errstr(status));
6895 /* Now try and open for FILE_READ_DATA */
6896 status = cli_ntcreate(cli,
6900 FILE_ATTRIBUTE_NORMAL,
6901 FILE_SHARE_READ|FILE_SHARE_WRITE|
6908 if (!NT_STATUS_IS_OK(status)) {
6909 printf("Open of %s - %s\n", fname, nt_errstr(status));
6913 status = cli_close(cli, fnum);
6914 if (!NT_STATUS_IS_OK(status)) {
6915 printf("close failed for %s (%s)\n",
6916 fname, nt_errstr(status));
6920 /* Restore clean slate. */
6922 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
6925 /* Create the test file. */
6926 status = cli_ntcreate(cli,
6930 FILE_ATTRIBUTE_NORMAL,
6931 FILE_SHARE_READ|FILE_SHARE_WRITE|
6938 if (!NT_STATUS_IS_OK(status)) {
6939 printf("Create of %s - %s\n", fname, nt_errstr(status));
6943 /* Get the original SD. */
6944 status = cli_query_secdesc(cli,
6948 if (!NT_STATUS_IS_OK(status)) {
6949 printf("cli_query_secdesc failed for %s (%s)\n",
6950 fname, nt_errstr(status));
6955 * Add an "authenticated users" ACE allowing READ_DATA,
6956 * add an "owner-rights" denying READ_DATA,
6957 * and an "authenticated users" ACE allowing WRITE_DATA.
6960 newsd = security_descriptor_dacl_create(frame,
6964 SID_NT_AUTHENTICATED_USERS,
6965 SEC_ACE_TYPE_ACCESS_ALLOWED,
6969 SEC_ACE_TYPE_ACCESS_DENIED,
6972 SID_NT_AUTHENTICATED_USERS,
6973 SEC_ACE_TYPE_ACCESS_ALLOWED,
6977 if (newsd == NULL) {
6978 printf("newsd == NULL\n");
6981 sd->dacl = security_acl_concatenate(frame,
6984 if (sd->dacl == NULL) {
6985 printf("sd->dacl == NULL\n");
6988 status = cli_set_secdesc(cli, fnum, sd);
6989 if (!NT_STATUS_IS_OK(status)) {
6990 printf("cli_set_secdesc failed for %s (%s)\n",
6991 fname, nt_errstr(status));
6994 status = cli_close(cli, fnum);
6995 if (!NT_STATUS_IS_OK(status)) {
6996 printf("close failed for %s (%s)\n",
6997 fname, nt_errstr(status));
7000 fnum = (uint16_t)-1;
7002 /* Now try and open for FILE_READ_DATA|FILE_WRITE_DATA */
7003 status = cli_ntcreate(cli,
7006 FILE_READ_DATA|FILE_WRITE_DATA,
7007 FILE_ATTRIBUTE_NORMAL,
7008 FILE_SHARE_READ|FILE_SHARE_WRITE|
7015 if (!NT_STATUS_IS_OK(status)) {
7016 printf("Open of %s - %s\n", fname, nt_errstr(status));
7020 status = cli_close(cli, fnum);
7021 if (!NT_STATUS_IS_OK(status)) {
7022 printf("close failed for %s (%s)\n",
7023 fname, nt_errstr(status));
7027 cli_unlink(cli, fname,
7028 FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7036 if (fnum != (uint16_t)-1) {
7037 cli_close(cli, fnum);
7039 cli_unlink(cli, fname,
7040 FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7041 torture_close_connection(cli);
7048 static bool run_pipe_number(int dummy)
7050 struct cli_state *cli1;
7051 const char *pipe_name = "\\SPOOLSS";
7056 printf("starting pipenumber test\n");
7057 if (!torture_open_connection(&cli1, 0)) {
7061 smbXcli_conn_set_sockopt(cli1->conn, sockops);
7063 status = cli_ntcreate(cli1, pipe_name, 0, FILE_READ_DATA,
7064 FILE_ATTRIBUTE_NORMAL,
7065 FILE_SHARE_READ|FILE_SHARE_WRITE,
7066 FILE_OPEN_IF, 0, 0, &fnum, NULL);
7067 if (!NT_STATUS_IS_OK(status)) {
7068 printf("Open of pipe %s failed with error (%s)\n", pipe_name, nt_errstr(status));
7072 printf("\r%6d", num_pipes);
7075 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes, pipe_name );
7076 torture_close_connection(cli1);
7081 Test open mode returns on read-only files.
7083 static bool run_opentest(int dummy)
7085 static struct cli_state *cli1;
7086 static struct cli_state *cli2;
7087 const char *fname = "\\readonly.file";
7088 uint16_t fnum1, fnum2;
7091 bool correct = True;
7095 printf("starting open test\n");
7097 if (!torture_open_connection(&cli1, 0)) {
7101 cli_setatr(cli1, fname, 0, 0);
7102 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7104 smbXcli_conn_set_sockopt(cli1->conn, sockops);
7106 status = cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
7107 if (!NT_STATUS_IS_OK(status)) {
7108 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
7112 status = cli_close(cli1, fnum1);
7113 if (!NT_STATUS_IS_OK(status)) {
7114 printf("close2 failed (%s)\n", nt_errstr(status));
7118 status = cli_setatr(cli1, fname, FILE_ATTRIBUTE_READONLY, 0);
7119 if (!NT_STATUS_IS_OK(status)) {
7120 printf("cli_setatr failed (%s)\n", nt_errstr(status));
7124 status = cli_openx(cli1, fname, O_RDONLY, DENY_WRITE, &fnum1);
7125 if (!NT_STATUS_IS_OK(status)) {
7126 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
7130 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
7131 status = cli_openx(cli1, fname, O_RDWR, DENY_ALL, &fnum2);
7133 if (check_error(__LINE__, status, ERRDOS, ERRnoaccess,
7134 NT_STATUS_ACCESS_DENIED)) {
7135 printf("correct error code ERRDOS/ERRnoaccess returned\n");
7138 printf("finished open test 1\n");
7140 cli_close(cli1, fnum1);
7142 /* Now try not readonly and ensure ERRbadshare is returned. */
7144 cli_setatr(cli1, fname, 0, 0);
7146 status = cli_openx(cli1, fname, O_RDONLY, DENY_WRITE, &fnum1);
7147 if (!NT_STATUS_IS_OK(status)) {
7148 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
7152 /* This will fail - but the error should be ERRshare. */
7153 status = cli_openx(cli1, fname, O_RDWR, DENY_ALL, &fnum2);
7155 if (check_error(__LINE__, status, ERRDOS, ERRbadshare,
7156 NT_STATUS_SHARING_VIOLATION)) {
7157 printf("correct error code ERRDOS/ERRbadshare returned\n");
7160 status = cli_close(cli1, fnum1);
7161 if (!NT_STATUS_IS_OK(status)) {
7162 printf("close2 failed (%s)\n", nt_errstr(status));
7166 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7168 printf("finished open test 2\n");
7170 /* Test truncate open disposition on file opened for read. */
7171 status = cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
7172 if (!NT_STATUS_IS_OK(status)) {
7173 printf("(3) open (1) of %s failed (%s)\n", fname, nt_errstr(status));
7177 /* write 20 bytes. */
7179 memset(buf, '\0', 20);
7181 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 0, 20, NULL);
7182 if (!NT_STATUS_IS_OK(status)) {
7183 printf("write failed (%s)\n", nt_errstr(status));
7187 status = cli_close(cli1, fnum1);
7188 if (!NT_STATUS_IS_OK(status)) {
7189 printf("(3) close1 failed (%s)\n", nt_errstr(status));
7193 /* Ensure size == 20. */
7194 status = cli_getatr(cli1, fname, NULL, &fsize, NULL);
7195 if (!NT_STATUS_IS_OK(status)) {
7196 printf("(3) getatr failed (%s)\n", nt_errstr(status));
7201 printf("(3) file size != 20\n");
7205 /* Now test if we can truncate a file opened for readonly. */
7206 status = cli_openx(cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE, &fnum1);
7207 if (!NT_STATUS_IS_OK(status)) {
7208 printf("(3) open (2) of %s failed (%s)\n", fname, nt_errstr(status));
7212 status = cli_close(cli1, fnum1);
7213 if (!NT_STATUS_IS_OK(status)) {
7214 printf("close2 failed (%s)\n", nt_errstr(status));
7218 /* Ensure size == 0. */
7219 status = cli_getatr(cli1, fname, NULL, &fsize, NULL);
7220 if (!NT_STATUS_IS_OK(status)) {
7221 printf("(3) getatr failed (%s)\n", nt_errstr(status));
7226 printf("(3) file size != 0\n");
7229 printf("finished open test 3\n");
7231 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7233 printf("Do ctemp tests\n");
7234 status = cli_ctemp(cli1, talloc_tos(), "\\", &fnum1, &tmp_path);
7235 if (!NT_STATUS_IS_OK(status)) {
7236 printf("ctemp failed (%s)\n", nt_errstr(status));
7240 printf("ctemp gave path %s\n", tmp_path);
7241 status = cli_close(cli1, fnum1);
7242 if (!NT_STATUS_IS_OK(status)) {
7243 printf("close of temp failed (%s)\n", nt_errstr(status));
7246 status = cli_unlink(cli1, tmp_path, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7247 if (!NT_STATUS_IS_OK(status)) {
7248 printf("unlink of temp failed (%s)\n", nt_errstr(status));
7251 /* Test the non-io opens... */
7253 if (!torture_open_connection(&cli2, 1)) {
7257 cli_setatr(cli2, fname, 0, 0);
7258 cli_unlink(cli2, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7260 smbXcli_conn_set_sockopt(cli2->conn, sockops);
7262 printf("TEST #1 testing 2 non-io opens (no delete)\n");
7263 status = cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES,
7264 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
7265 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
7266 if (!NT_STATUS_IS_OK(status)) {
7267 printf("TEST #1 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
7271 status = cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES,
7272 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
7273 FILE_OPEN_IF, 0, 0, &fnum2, NULL);
7274 if (!NT_STATUS_IS_OK(status)) {
7275 printf("TEST #1 open 2 of %s failed (%s)\n", fname, nt_errstr(status));
7279 status = cli_close(cli1, fnum1);
7280 if (!NT_STATUS_IS_OK(status)) {
7281 printf("TEST #1 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
7285 status = cli_close(cli2, fnum2);
7286 if (!NT_STATUS_IS_OK(status)) {
7287 printf("TEST #1 close 2 of %s failed (%s)\n", fname, nt_errstr(status));
7291 printf("non-io open test #1 passed.\n");
7293 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7295 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
7297 status = cli_ntcreate(cli1, fname, 0,
7298 DELETE_ACCESS|FILE_READ_ATTRIBUTES,
7299 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
7300 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
7301 if (!NT_STATUS_IS_OK(status)) {
7302 printf("TEST #2 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
7306 status = cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES,
7307 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
7308 FILE_OPEN_IF, 0, 0, &fnum2, NULL);
7309 if (!NT_STATUS_IS_OK(status)) {
7310 printf("TEST #2 open 2 of %s failed (%s)\n", fname, nt_errstr(status));
7314 status = cli_close(cli1, fnum1);
7315 if (!NT_STATUS_IS_OK(status)) {
7316 printf("TEST #2 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
7320 status = cli_close(cli2, fnum2);
7321 if (!NT_STATUS_IS_OK(status)) {
7322 printf("TEST #2 close 2 of %s failed (%s)\n", fname, nt_errstr(status));
7326 printf("non-io open test #2 passed.\n");
7328 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7330 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
7332 status = cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES,
7333 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
7334 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
7335 if (!NT_STATUS_IS_OK(status)) {
7336 printf("TEST #3 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
7340 status = cli_ntcreate(cli2, fname, 0,
7341 DELETE_ACCESS|FILE_READ_ATTRIBUTES,
7342 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
7343 FILE_OPEN_IF, 0, 0, &fnum2, NULL);
7344 if (!NT_STATUS_IS_OK(status)) {
7345 printf("TEST #3 open 2 of %s failed (%s)\n", fname, nt_errstr(status));
7349 status = cli_close(cli1, fnum1);
7350 if (!NT_STATUS_IS_OK(status)) {
7351 printf("TEST #3 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
7355 status = cli_close(cli2, fnum2);
7356 if (!NT_STATUS_IS_OK(status)) {
7357 printf("TEST #3 close 2 of %s failed (%s)\n", fname, nt_errstr(status));
7361 printf("non-io open test #3 passed.\n");
7363 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7365 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
7367 status = cli_ntcreate(cli1, fname, 0,
7368 DELETE_ACCESS|FILE_READ_ATTRIBUTES,
7369 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
7370 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
7371 if (!NT_STATUS_IS_OK(status)) {
7372 printf("TEST #4 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
7376 status = cli_ntcreate(cli2, fname, 0,
7377 DELETE_ACCESS|FILE_READ_ATTRIBUTES,
7378 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
7379 FILE_OPEN_IF, 0, 0, &fnum2, NULL);
7380 if (NT_STATUS_IS_OK(status)) {
7381 printf("TEST #4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, nt_errstr(status));
7385 printf("TEST #4 open 2 of %s gave %s (correct error should be %s)\n", fname, nt_errstr(status), "sharing violation");
7387 status = cli_close(cli1, fnum1);
7388 if (!NT_STATUS_IS_OK(status)) {
7389 printf("TEST #4 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
7393 printf("non-io open test #4 passed.\n");
7395 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7397 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
7399 status = cli_ntcreate(cli1, fname, 0,
7400 DELETE_ACCESS|FILE_READ_ATTRIBUTES,
7401 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_DELETE,
7402 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
7403 if (!NT_STATUS_IS_OK(status)) {
7404 printf("TEST #5 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
7408 status = cli_ntcreate(cli2, fname, 0,
7409 DELETE_ACCESS|FILE_READ_ATTRIBUTES,
7410 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_DELETE,
7411 FILE_OPEN_IF, 0, 0, &fnum2, NULL);
7412 if (!NT_STATUS_IS_OK(status)) {
7413 printf("TEST #5 open 2 of %s failed (%s)\n", fname, nt_errstr(status));
7417 status = cli_close(cli1, fnum1);
7418 if (!NT_STATUS_IS_OK(status)) {
7419 printf("TEST #5 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
7423 status = cli_close(cli2, fnum2);
7424 if (!NT_STATUS_IS_OK(status)) {
7425 printf("TEST #5 close 2 of %s failed (%s)\n", fname, nt_errstr(status));
7429 printf("non-io open test #5 passed.\n");
7431 printf("TEST #6 testing 1 non-io open, one io open\n");
7433 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7435 status = cli_ntcreate(cli1, fname, 0, FILE_READ_DATA,
7436 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
7437 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
7438 if (!NT_STATUS_IS_OK(status)) {
7439 printf("TEST #6 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
7443 status = cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES,
7444 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ,
7445 FILE_OPEN_IF, 0, 0, &fnum2, NULL);
7446 if (!NT_STATUS_IS_OK(status)) {
7447 printf("TEST #6 open 2 of %s failed (%s)\n", fname, nt_errstr(status));
7451 status = cli_close(cli1, fnum1);
7452 if (!NT_STATUS_IS_OK(status)) {
7453 printf("TEST #6 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
7457 status = cli_close(cli2, fnum2);
7458 if (!NT_STATUS_IS_OK(status)) {
7459 printf("TEST #6 close 2 of %s failed (%s)\n", fname, nt_errstr(status));
7463 printf("non-io open test #6 passed.\n");
7465 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
7467 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7469 status = cli_ntcreate(cli1, fname, 0, FILE_READ_DATA,
7470 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
7471 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
7472 if (!NT_STATUS_IS_OK(status)) {
7473 printf("TEST #7 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
7477 status = cli_ntcreate(cli2, fname, 0,
7478 DELETE_ACCESS|FILE_READ_ATTRIBUTES,
7479 FILE_ATTRIBUTE_NORMAL,
7480 FILE_SHARE_READ|FILE_SHARE_DELETE,
7481 FILE_OPEN_IF, 0, 0, &fnum2, NULL);
7482 if (NT_STATUS_IS_OK(status)) {
7483 printf("TEST #7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, nt_errstr(status));
7487 printf("TEST #7 open 2 of %s gave %s (correct error should be %s)\n", fname, nt_errstr(status), "sharing violation");
7489 status = cli_close(cli1, fnum1);
7490 if (!NT_STATUS_IS_OK(status)) {
7491 printf("TEST #7 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
7495 printf("non-io open test #7 passed.\n");
7497 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7499 printf("TEST #8 testing open without WRITE_ATTRIBUTES, updating close write time.\n");
7500 status = cli_ntcreate(cli1, fname, 0, FILE_WRITE_DATA, FILE_ATTRIBUTE_NORMAL,
7501 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
7502 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
7503 if (!NT_STATUS_IS_OK(status)) {
7504 printf("TEST #8 open of %s failed (%s)\n", fname, nt_errstr(status));
7509 /* Write to ensure we have to update the file time. */
7510 status = cli_writeall(cli1, fnum1, 0, (const uint8_t *)"TEST DATA\n", 0, 10,
7512 if (!NT_STATUS_IS_OK(status)) {
7513 printf("TEST #8 cli_write failed: %s\n", nt_errstr(status));
7518 status = cli_close(cli1, fnum1);
7519 if (!NT_STATUS_IS_OK(status)) {
7520 printf("TEST #8 close of %s failed (%s)\n", fname, nt_errstr(status));
7526 if (!torture_close_connection(cli1)) {
7529 if (!torture_close_connection(cli2)) {
7536 NTSTATUS torture_setup_unix_extensions(struct cli_state *cli)
7538 uint16_t major, minor;
7539 uint32_t caplow, caphigh;
7542 if (!SERVER_HAS_UNIX_CIFS(cli)) {
7543 printf("Server doesn't support UNIX CIFS extensions.\n");
7544 return NT_STATUS_NOT_SUPPORTED;
7547 status = cli_unix_extensions_version(cli, &major, &minor, &caplow,
7549 if (!NT_STATUS_IS_OK(status)) {
7550 printf("Server didn't return UNIX CIFS extensions: %s\n",
7555 status = cli_set_unix_extensions_capabilities(cli, major, minor,
7557 if (!NT_STATUS_IS_OK(status)) {
7558 printf("Server doesn't support setting UNIX CIFS extensions: "
7559 "%s.\n", nt_errstr(status));
7563 return NT_STATUS_OK;
7567 Test POSIX open /mkdir calls.
7569 static bool run_simple_posix_open_test(int dummy)
7571 static struct cli_state *cli1;
7572 const char *fname = "posix:file";
7573 const char *hname = "posix:hlink";
7574 const char *sname = "posix:symlink";
7575 const char *dname = "posix:dir";
7577 char *target = NULL;
7578 uint16_t fnum1 = (uint16_t)-1;
7579 SMB_STRUCT_STAT sbuf;
7580 bool correct = false;
7583 const char *fname_windows = "windows_file";
7584 uint16_t fnum2 = (uint16_t)-1;
7586 printf("Starting simple POSIX open test\n");
7588 if (!torture_open_connection(&cli1, 0)) {
7592 smbXcli_conn_set_sockopt(cli1->conn, sockops);
7594 status = torture_setup_unix_extensions(cli1);
7595 if (!NT_STATUS_IS_OK(status)) {
7599 cli_setatr(cli1, fname, 0, 0);
7600 cli_posix_unlink(cli1, fname);
7601 cli_setatr(cli1, dname, 0, 0);
7602 cli_posix_rmdir(cli1, dname);
7603 cli_setatr(cli1, hname, 0, 0);
7604 cli_posix_unlink(cli1, hname);
7605 cli_setatr(cli1, sname, 0, 0);
7606 cli_posix_unlink(cli1, sname);
7607 cli_setatr(cli1, fname_windows, 0, 0);
7608 cli_posix_unlink(cli1, fname_windows);
7610 /* Create a directory. */
7611 status = cli_posix_mkdir(cli1, dname, 0777);
7612 if (!NT_STATUS_IS_OK(status)) {
7613 printf("POSIX mkdir of %s failed (%s)\n", dname, nt_errstr(status));
7617 status = cli_posix_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL,
7619 if (!NT_STATUS_IS_OK(status)) {
7620 printf("POSIX create of %s failed (%s)\n", fname, nt_errstr(status));
7624 /* Test ftruncate - set file size. */
7625 status = cli_ftruncate(cli1, fnum1, 1000);
7626 if (!NT_STATUS_IS_OK(status)) {
7627 printf("ftruncate failed (%s)\n", nt_errstr(status));
7631 /* Ensure st_size == 1000 */
7632 status = cli_posix_stat(cli1, fname, &sbuf);
7633 if (!NT_STATUS_IS_OK(status)) {
7634 printf("stat failed (%s)\n", nt_errstr(status));
7638 if (sbuf.st_ex_size != 1000) {
7639 printf("ftruncate - stat size (%u) != 1000\n", (unsigned int)sbuf.st_ex_size);
7643 /* Ensure st_mode == 0600 */
7644 if ((sbuf.st_ex_mode & 07777) != 0600) {
7645 printf("posix_open - bad permissions 0%o != 0600\n",
7646 (unsigned int)(sbuf.st_ex_mode & 07777));
7650 /* Test ftruncate - set file size back to zero. */
7651 status = cli_ftruncate(cli1, fnum1, 0);
7652 if (!NT_STATUS_IS_OK(status)) {
7653 printf("ftruncate failed (%s)\n", nt_errstr(status));
7657 status = cli_close(cli1, fnum1);
7658 if (!NT_STATUS_IS_OK(status)) {
7659 printf("close failed (%s)\n", nt_errstr(status));
7663 /* Now open the file again for read only. */
7664 status = cli_posix_open(cli1, fname, O_RDONLY, 0, &fnum1);
7665 if (!NT_STATUS_IS_OK(status)) {
7666 printf("POSIX open of %s failed (%s)\n", fname, nt_errstr(status));
7670 /* Now unlink while open. */
7671 status = cli_posix_unlink(cli1, fname);
7672 if (!NT_STATUS_IS_OK(status)) {
7673 printf("POSIX unlink of %s failed (%s)\n", fname, nt_errstr(status));
7677 status = cli_close(cli1, fnum1);
7678 if (!NT_STATUS_IS_OK(status)) {
7679 printf("close(2) failed (%s)\n", nt_errstr(status));
7683 /* Ensure the file has gone. */
7684 status = cli_posix_open(cli1, fname, O_RDONLY, 0, &fnum1);
7685 if (NT_STATUS_IS_OK(status)) {
7686 printf("POSIX open of %s succeeded, should have been deleted.\n", fname);
7690 /* Create again to test open with O_TRUNC. */
7691 status = cli_posix_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, 0600, &fnum1);
7692 if (!NT_STATUS_IS_OK(status)) {
7693 printf("POSIX create of %s failed (%s)\n", fname, nt_errstr(status));
7697 /* Test ftruncate - set file size. */
7698 status = cli_ftruncate(cli1, fnum1, 1000);
7699 if (!NT_STATUS_IS_OK(status)) {
7700 printf("ftruncate failed (%s)\n", nt_errstr(status));
7704 /* Ensure st_size == 1000 */
7705 status = cli_posix_stat(cli1, fname, &sbuf);
7706 if (!NT_STATUS_IS_OK(status)) {
7707 printf("stat failed (%s)\n", nt_errstr(status));
7711 if (sbuf.st_ex_size != 1000) {
7712 printf("ftruncate - stat size (%u) != 1000\n", (unsigned int)sbuf.st_ex_size);
7716 status = cli_close(cli1, fnum1);
7717 if (!NT_STATUS_IS_OK(status)) {
7718 printf("close(2) failed (%s)\n", nt_errstr(status));
7722 /* Re-open with O_TRUNC. */
7723 status = cli_posix_open(cli1, fname, O_WRONLY|O_TRUNC, 0600, &fnum1);
7724 if (!NT_STATUS_IS_OK(status)) {
7725 printf("POSIX create of %s failed (%s)\n", fname, nt_errstr(status));
7729 /* Ensure st_size == 0 */
7730 status = cli_posix_stat(cli1, fname, &sbuf);
7731 if (!NT_STATUS_IS_OK(status)) {
7732 printf("stat failed (%s)\n", nt_errstr(status));
7736 if (sbuf.st_ex_size != 0) {
7737 printf("O_TRUNC - stat size (%u) != 0\n", (unsigned int)sbuf.st_ex_size);
7741 status = cli_close(cli1, fnum1);
7742 if (!NT_STATUS_IS_OK(status)) {
7743 printf("close failed (%s)\n", nt_errstr(status));
7747 status = cli_posix_unlink(cli1, fname);
7748 if (!NT_STATUS_IS_OK(status)) {
7749 printf("POSIX unlink of %s failed (%s)\n", fname, nt_errstr(status));
7753 status = cli_posix_open(cli1, dname, O_RDONLY, 0, &fnum1);
7754 if (!NT_STATUS_IS_OK(status)) {
7755 printf("POSIX open directory O_RDONLY of %s failed (%s)\n",
7756 dname, nt_errstr(status));
7760 cli_close(cli1, fnum1);
7762 /* What happens when we try and POSIX open a directory for write ? */
7763 status = cli_posix_open(cli1, dname, O_RDWR, 0, &fnum1);
7764 if (NT_STATUS_IS_OK(status)) {
7765 printf("POSIX open of directory %s succeeded, "
7766 "should have failed.\n",
7770 if (!check_both_error(__LINE__, status, ERRDOS, EISDIR,
7771 NT_STATUS_FILE_IS_A_DIRECTORY)) {
7776 /* Create the file. */
7777 status = cli_posix_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL,
7779 if (!NT_STATUS_IS_OK(status)) {
7780 printf("POSIX create of %s failed (%s)\n", fname, nt_errstr(status));
7784 /* Write some data into it. */
7785 status = cli_writeall(cli1, fnum1, 0, (const uint8_t *)"TEST DATA\n", 0, 10,
7787 if (!NT_STATUS_IS_OK(status)) {
7788 printf("cli_write failed: %s\n", nt_errstr(status));
7792 cli_close(cli1, fnum1);
7794 /* Now create a hardlink. */
7795 status = cli_posix_hardlink(cli1, fname, hname);
7796 if (!NT_STATUS_IS_OK(status)) {
7797 printf("POSIX hardlink of %s failed (%s)\n", hname, nt_errstr(status));
7801 /* Now create a symlink. */
7802 status = cli_posix_symlink(cli1, fname, sname);
7803 if (!NT_STATUS_IS_OK(status)) {
7804 printf("POSIX symlink of %s failed (%s)\n", sname, nt_errstr(status));
7808 /* Open the hardlink for read. */
7809 status = cli_posix_open(cli1, hname, O_RDONLY, 0, &fnum1);
7810 if (!NT_STATUS_IS_OK(status)) {
7811 printf("POSIX open of %s failed (%s)\n", hname, nt_errstr(status));
7815 status = cli_read(cli1, fnum1, buf, 0, 10, &nread);
7816 if (!NT_STATUS_IS_OK(status)) {
7817 printf("POSIX read of %s failed (%s)\n", hname,
7820 } else if (nread != 10) {
7821 printf("POSIX read of %s failed. Received %ld, expected %d\n",
7822 hname, (unsigned long)nread, 10);
7826 if (memcmp(buf, "TEST DATA\n", 10)) {
7827 printf("invalid data read from hardlink\n");
7831 /* Do a POSIX lock/unlock. */
7832 status = cli_posix_lock(cli1, fnum1, 0, 100, true, READ_LOCK);
7833 if (!NT_STATUS_IS_OK(status)) {
7834 printf("POSIX lock failed %s\n", nt_errstr(status));
7838 /* Punch a hole in the locked area. */
7839 status = cli_posix_unlock(cli1, fnum1, 10, 80);
7840 if (!NT_STATUS_IS_OK(status)) {
7841 printf("POSIX unlock failed %s\n", nt_errstr(status));
7845 cli_close(cli1, fnum1);
7847 /* Open the symlink for read - this should fail. A POSIX
7848 client should not be doing opens on a symlink. */
7849 status = cli_posix_open(cli1, sname, O_RDONLY, 0, &fnum1);
7850 if (NT_STATUS_IS_OK(status)) {
7851 printf("POSIX open of %s succeeded (should have failed)\n", sname);
7854 if (!check_both_error(__LINE__, status, ERRDOS, ERRbadpath,
7855 NT_STATUS_OBJECT_PATH_NOT_FOUND)) {
7856 printf("POSIX open of %s should have failed "
7857 "with NT_STATUS_OBJECT_PATH_NOT_FOUND, "
7858 "failed with %s instead.\n",
7859 sname, nt_errstr(status));
7864 status = cli_posix_readlink(cli1, sname, talloc_tos(), &target);
7865 if (!NT_STATUS_IS_OK(status)) {
7866 printf("POSIX readlink on %s failed (%s)\n", sname, nt_errstr(status));
7870 if (strcmp(target, fname) != 0) {
7871 printf("POSIX readlink on %s failed to match name %s (read %s)\n",
7872 sname, fname, target);
7876 status = cli_posix_rmdir(cli1, dname);
7877 if (!NT_STATUS_IS_OK(status)) {
7878 printf("POSIX rmdir failed (%s)\n", nt_errstr(status));
7882 /* Check directory opens with a specific permission. */
7883 status = cli_posix_mkdir(cli1, dname, 0700);
7884 if (!NT_STATUS_IS_OK(status)) {
7885 printf("POSIX mkdir of %s failed (%s)\n", dname, nt_errstr(status));
7889 /* Ensure st_mode == 0700 */
7890 status = cli_posix_stat(cli1, dname, &sbuf);
7891 if (!NT_STATUS_IS_OK(status)) {
7892 printf("stat failed (%s)\n", nt_errstr(status));
7896 if ((sbuf.st_ex_mode & 07777) != 0700) {
7897 printf("posix_mkdir - bad permissions 0%o != 0700\n",
7898 (unsigned int)(sbuf.st_ex_mode & 07777));
7903 * Now create a Windows file, and attempt a POSIX unlink.
7904 * This should fail with a sharing violation but due to:
7906 * [Bug 9571] Unlink after open causes smbd to panic
7908 * ensure we've fixed the lock ordering violation.
7911 status = cli_ntcreate(cli1, fname_windows, 0,
7912 FILE_READ_DATA|FILE_WRITE_DATA, 0,
7913 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
7915 0x0, 0x0, &fnum2, NULL);
7916 if (!NT_STATUS_IS_OK(status)) {
7917 printf("Windows create of %s failed (%s)\n", fname_windows,
7922 /* Now try posix_unlink. */
7923 status = cli_posix_unlink(cli1, fname_windows);
7924 if (!NT_STATUS_EQUAL(status, NT_STATUS_SHARING_VIOLATION)) {
7925 printf("POSIX unlink of %s should fail "
7926 "with NT_STATUS_SHARING_VIOLATION "
7927 "got %s instead !\n",
7933 cli_close(cli1, fnum2);
7935 printf("Simple POSIX open test passed\n");
7940 if (fnum1 != (uint16_t)-1) {
7941 cli_close(cli1, fnum1);
7942 fnum1 = (uint16_t)-1;
7945 if (fnum2 != (uint16_t)-1) {
7946 cli_close(cli1, fnum2);
7947 fnum2 = (uint16_t)-1;
7950 cli_setatr(cli1, sname, 0, 0);
7951 cli_posix_unlink(cli1, sname);
7952 cli_setatr(cli1, hname, 0, 0);
7953 cli_posix_unlink(cli1, hname);
7954 cli_setatr(cli1, fname, 0, 0);
7955 cli_posix_unlink(cli1, fname);
7956 cli_setatr(cli1, dname, 0, 0);
7957 cli_posix_rmdir(cli1, dname);
7958 cli_setatr(cli1, fname_windows, 0, 0);
7959 cli_posix_unlink(cli1, fname_windows);
7961 if (!torture_close_connection(cli1)) {
7969 Test POSIX and Windows ACLs are rejected on symlinks.
7971 static bool run_acl_symlink_test(int dummy)
7973 static struct cli_state *cli;
7974 const char *fname = "posix_file";
7975 const char *sname = "posix_symlink";
7976 uint16_t fnum = (uint16_t)-1;
7977 bool correct = false;
7979 char *posix_acl = NULL;
7980 size_t posix_acl_len = 0;
7981 char *posix_acl_sym = NULL;
7982 size_t posix_acl_len_sym = 0;
7983 struct security_descriptor *sd = NULL;
7984 struct security_descriptor *sd_sym = NULL;
7985 TALLOC_CTX *frame = NULL;
7987 frame = talloc_stackframe();
7989 printf("Starting acl symlink test\n");
7991 if (!torture_open_connection(&cli, 0)) {
7996 smbXcli_conn_set_sockopt(cli->conn, sockops);
7998 status = torture_setup_unix_extensions(cli);
7999 if (!NT_STATUS_IS_OK(status)) {
8004 cli_setatr(cli, fname, 0, 0);
8005 cli_posix_unlink(cli, fname);
8006 cli_setatr(cli, sname, 0, 0);
8007 cli_posix_unlink(cli, sname);
8009 status = cli_ntcreate(cli,
8012 READ_CONTROL_ACCESS,
8014 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
8021 if (!NT_STATUS_IS_OK(status)) {
8022 printf("cli_ntcreate of %s failed (%s)\n",
8028 /* Get the Windows ACL on the file. */
8029 status = cli_query_secdesc(cli,
8033 if (!NT_STATUS_IS_OK(status)) {
8034 printf("cli_query_secdesc failed (%s)\n",
8039 /* Get the POSIX ACL on the file. */
8040 status = cli_posix_getacl(cli,
8046 if (!NT_STATUS_IS_OK(status)) {
8047 printf("cli_posix_getacl failed (%s)\n",
8052 status = cli_close(cli, fnum);
8053 if (!NT_STATUS_IS_OK(status)) {
8054 printf("close failed (%s)\n", nt_errstr(status));
8057 fnum = (uint16_t)-1;
8059 /* Now create a symlink. */
8060 status = cli_posix_symlink(cli, fname, sname);
8061 if (!NT_STATUS_IS_OK(status)) {
8062 printf("cli_posix_symlink of %s -> %s failed (%s)\n",
8069 /* Open a handle on the symlink for SD set/get should fail. */
8070 status = cli_ntcreate(cli,
8073 READ_CONTROL_ACCESS|SEC_STD_WRITE_DAC,
8075 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
8082 if (NT_STATUS_IS_OK(status)) {
8083 printf("Symlink open for getsd/setsd of %s "
8084 "succeeded (should fail)\n",
8089 /* Open a handle on the symlink. */
8090 status = cli_ntcreate(cli,
8093 FILE_READ_ATTRIBUTES|FILE_WRITE_ATTRIBUTES,
8095 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
8102 if (!NT_STATUS_IS_OK(status)) {
8103 printf("cli_posix_open of %s failed (%s)\n",
8109 /* Get the Windows ACL on the symlink handle. Should fail */
8110 status = cli_query_secdesc(cli,
8115 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
8116 printf("cli_query_secdesc on a symlink gave %s. "
8117 "Should be NT_STATUS_ACCESS_DENIED.\n",
8122 /* Get the POSIX ACL on the symlink pathname. Should fail. */
8123 status = cli_posix_getacl(cli,
8129 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
8130 printf("cli_posix_getacl on a symlink gave %s. "
8131 "Should be NT_STATUS_ACCESS_DENIED.\n",
8136 /* Set the Windows ACL on the symlink handle. Should fail */
8137 status = cli_set_security_descriptor(cli,
8142 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
8143 printf("cli_query_secdesc on a symlink gave %s. "
8144 "Should be NT_STATUS_ACCESS_DENIED.\n",
8149 /* Set the POSIX ACL on the symlink pathname. Should fail. */
8150 status = cli_posix_setacl(cli,
8155 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
8156 printf("cli_posix_setacl on a symlink gave %s. "
8157 "Should be NT_STATUS_ACCESS_DENIED.\n",
8162 printf("ACL symlink test passed\n");
8167 if (fnum != (uint16_t)-1) {
8168 cli_close(cli, fnum);
8169 fnum = (uint16_t)-1;
8172 cli_setatr(cli, sname, 0, 0);
8173 cli_posix_unlink(cli, sname);
8174 cli_setatr(cli, fname, 0, 0);
8175 cli_posix_unlink(cli, fname);
8177 if (!torture_close_connection(cli)) {
8186 Test POSIX can delete a file containing streams.
8188 static bool run_posix_stream_delete(int dummy)
8190 struct cli_state *cli1 = NULL;
8191 struct cli_state *cli2 = NULL;
8192 const char *fname = "streamfile";
8193 const char *stream_fname = "streamfile:Zone.Identifier:$DATA";
8194 uint16_t fnum1 = (uint16_t)-1;
8195 bool correct = false;
8197 TALLOC_CTX *frame = NULL;
8199 frame = talloc_stackframe();
8201 printf("Starting POSIX stream delete test\n");
8203 if (!torture_open_connection(&cli1, 0) ||
8204 !torture_open_connection(&cli2, 1)) {
8209 smbXcli_conn_set_sockopt(cli1->conn, sockops);
8210 smbXcli_conn_set_sockopt(cli2->conn, sockops);
8212 status = torture_setup_unix_extensions(cli2);
8213 if (!NT_STATUS_IS_OK(status)) {
8217 cli_setatr(cli1, fname, 0, 0);
8218 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
8220 /* Create the file. */
8221 status = cli_ntcreate(cli1,
8224 READ_CONTROL_ACCESS,
8226 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
8233 if (!NT_STATUS_IS_OK(status)) {
8234 printf("cli_ntcreate of %s failed (%s)\n",
8240 status = cli_close(cli1, fnum1);
8241 if (!NT_STATUS_IS_OK(status)) {
8242 printf("cli_close of %s failed (%s)\n",
8247 fnum1 = (uint16_t)-1;
8249 /* Now create the stream. */
8250 status = cli_ntcreate(cli1,
8255 FILE_SHARE_READ|FILE_SHARE_WRITE,
8262 if (!NT_STATUS_IS_OK(status)) {
8263 printf("cli_ntcreate of %s failed (%s)\n",
8269 /* Leave the stream handle open... */
8271 /* POSIX unlink should fail. */
8272 status = cli_posix_unlink(cli2, fname);
8273 if (NT_STATUS_IS_OK(status)) {
8274 printf("cli_posix_unlink of %s succeeded, should have failed\n",
8279 if (!NT_STATUS_EQUAL(status, NT_STATUS_SHARING_VIOLATION)) {
8280 printf("cli_posix_unlink of %s failed with (%s) "
8281 "should have been NT_STATUS_SHARING_VIOLATION\n",
8287 /* Close the stream handle. */
8288 status = cli_close(cli1, fnum1);
8289 if (!NT_STATUS_IS_OK(status)) {
8290 printf("cli_close of %s failed (%s)\n",
8295 fnum1 = (uint16_t)-1;
8297 /* POSIX unlink after stream handle closed should succeed. */
8298 status = cli_posix_unlink(cli2, fname);
8299 if (!NT_STATUS_IS_OK(status)) {
8300 printf("cli_posix_unlink of %s failed (%s)\n",
8306 printf("POSIX stream delete test passed\n");
8311 if (fnum1 != (uint16_t)-1) {
8312 cli_close(cli1, fnum1);
8313 fnum1 = (uint16_t)-1;
8316 cli_setatr(cli1, fname, 0, 0);
8317 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
8319 if (!torture_close_connection(cli1)) {
8322 if (!torture_close_connection(cli2)) {
8331 Test setting EA's are rejected on symlinks.
8333 static bool run_ea_symlink_test(int dummy)
8335 static struct cli_state *cli;
8336 const char *fname = "posix_file_ea";
8337 const char *sname = "posix_symlink_ea";
8338 const char *ea_name = "testea_name";
8339 const char *ea_value = "testea_value";
8340 uint16_t fnum = (uint16_t)-1;
8341 bool correct = false;
8344 struct ea_struct *eas = NULL;
8345 TALLOC_CTX *frame = NULL;
8347 frame = talloc_stackframe();
8349 printf("Starting EA symlink test\n");
8351 if (!torture_open_connection(&cli, 0)) {
8356 smbXcli_conn_set_sockopt(cli->conn, sockops);
8358 status = torture_setup_unix_extensions(cli);
8359 if (!NT_STATUS_IS_OK(status)) {
8364 cli_setatr(cli, fname, 0, 0);
8365 cli_posix_unlink(cli, fname);
8366 cli_setatr(cli, sname, 0, 0);
8367 cli_posix_unlink(cli, sname);
8369 status = cli_ntcreate(cli,
8372 READ_CONTROL_ACCESS,
8374 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
8381 if (!NT_STATUS_IS_OK(status)) {
8382 printf("cli_ntcreate of %s failed (%s)\n",
8388 status = cli_close(cli, fnum);
8389 if (!NT_STATUS_IS_OK(status)) {
8390 printf("close failed (%s)\n",
8394 fnum = (uint16_t)-1;
8396 /* Set an EA on the path. */
8397 status = cli_set_ea_path(cli,
8401 strlen(ea_value)+1);
8403 if (!NT_STATUS_IS_OK(status)) {
8404 printf("cli_set_ea_path failed (%s)\n",
8409 /* Now create a symlink. */
8410 status = cli_posix_symlink(cli, fname, sname);
8411 if (!NT_STATUS_IS_OK(status)) {
8412 printf("cli_posix_symlink of %s -> %s failed (%s)\n",
8419 /* Get the EA list on the path. Should return value set. */
8420 status = cli_get_ea_list_path(cli,
8426 if (!NT_STATUS_IS_OK(status)) {
8427 printf("cli_get_ea_list_path failed (%s)\n",
8432 /* Ensure the EA we set is there. */
8433 for (i=0; i<num_eas; i++) {
8434 if (strcmp(eas[i].name, ea_name) == 0 &&
8435 eas[i].value.length == strlen(ea_value)+1 &&
8436 memcmp(eas[i].value.data,
8438 eas[i].value.length) == 0) {
8444 printf("Didn't find EA on pathname %s\n",
8452 /* Get the EA list on the symlink. Should return empty list. */
8453 status = cli_get_ea_list_path(cli,
8459 if (!NT_STATUS_IS_OK(status)) {
8460 printf("cli_get_ea_list_path failed (%s)\n",
8466 printf("cli_get_ea_list_path failed (%s)\n",
8471 /* Set an EA on the symlink. Should fail. */
8472 status = cli_set_ea_path(cli,
8476 strlen(ea_value)+1);
8478 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
8479 printf("cli_set_ea_path on a symlink gave %s. "
8480 "Should be NT_STATUS_ACCESS_DENIED.\n",
8485 printf("EA symlink test passed\n");
8490 if (fnum != (uint16_t)-1) {
8491 cli_close(cli, fnum);
8492 fnum = (uint16_t)-1;
8495 cli_setatr(cli, sname, 0, 0);
8496 cli_posix_unlink(cli, sname);
8497 cli_setatr(cli, fname, 0, 0);
8498 cli_posix_unlink(cli, fname);
8500 if (!torture_close_connection(cli)) {
8509 Test POSIX locks are OFD-locks.
8511 static bool run_posix_ofd_lock_test(int dummy)
8513 static struct cli_state *cli;
8514 const char *fname = "posix_file";
8515 uint16_t fnum1 = (uint16_t)-1;
8516 uint16_t fnum2 = (uint16_t)-1;
8517 bool correct = false;
8519 TALLOC_CTX *frame = NULL;
8521 frame = talloc_stackframe();
8523 printf("Starting POSIX ofd-lock test\n");
8525 if (!torture_open_connection(&cli, 0)) {
8530 smbXcli_conn_set_sockopt(cli->conn, sockops);
8532 status = torture_setup_unix_extensions(cli);
8533 if (!NT_STATUS_IS_OK(status)) {
8538 cli_setatr(cli, fname, 0, 0);
8539 cli_posix_unlink(cli, fname);
8541 /* Open the file twice. */
8542 status = cli_posix_open(cli, fname, O_RDWR|O_CREAT|O_EXCL,
8544 if (!NT_STATUS_IS_OK(status)) {
8545 printf("First POSIX open of %s failed\n", fname);
8549 status = cli_posix_open(cli, fname, O_RDWR, 0, &fnum2);
8550 if (!NT_STATUS_IS_OK(status)) {
8551 printf("First POSIX open of %s failed\n", fname);
8555 /* Set a 0-50 lock on fnum1. */
8556 status = cli_posix_lock(cli, fnum1, 0, 50, false, WRITE_LOCK);
8557 if (!NT_STATUS_IS_OK(status)) {
8558 printf("POSIX lock (1) failed %s\n", nt_errstr(status));
8562 /* Set a 60-100 lock on fnum2. */
8563 status = cli_posix_lock(cli, fnum2, 60, 100, false, WRITE_LOCK);
8564 if (!NT_STATUS_IS_OK(status)) {
8565 printf("POSIX lock (2) failed %s\n", nt_errstr(status));
8569 /* close fnum1 - 0-50 lock should go away. */
8570 status = cli_close(cli, fnum1);
8571 if (!NT_STATUS_IS_OK(status)) {
8572 printf("close failed (%s)\n",
8576 fnum1 = (uint16_t)-1;
8578 /* Change the lock context. */
8579 cli_setpid(cli, cli_getpid(cli) + 1);
8581 /* Re-open fnum1. */
8582 status = cli_posix_open(cli, fname, O_RDWR, 0, &fnum1);
8583 if (!NT_STATUS_IS_OK(status)) {
8584 printf("Third POSIX open of %s failed\n", fname);
8588 /* 60-100 lock should still be there. */
8589 status = cli_posix_lock(cli, fnum1, 60, 100, false, WRITE_LOCK);
8590 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_LOCK_CONFLICT)) {
8591 printf("POSIX lock 60-100 not there %s\n", nt_errstr(status));
8595 /* 0-50 lock should be gone. */
8596 status = cli_posix_lock(cli, fnum1, 0, 50, false, WRITE_LOCK);
8597 if (!NT_STATUS_IS_OK(status)) {
8598 printf("POSIX lock 0-50 failed %s\n", nt_errstr(status));
8602 printf("POSIX OFD lock test passed\n");
8607 if (fnum1 != (uint16_t)-1) {
8608 cli_close(cli, fnum1);
8609 fnum1 = (uint16_t)-1;
8611 if (fnum2 != (uint16_t)-1) {
8612 cli_close(cli, fnum2);
8613 fnum2 = (uint16_t)-1;
8616 cli_setatr(cli, fname, 0, 0);
8617 cli_posix_unlink(cli, fname);
8619 if (!torture_close_connection(cli)) {
8627 struct posix_blocking_state {
8628 struct tevent_context *ev;
8629 struct cli_state *cli1;
8631 struct cli_state *cli2;
8637 static void posix_blocking_locked(struct tevent_req *subreq);
8638 static void posix_blocking_gotblocked(struct tevent_req *subreq);
8639 static void posix_blocking_gotecho(struct tevent_req *subreq);
8640 static void posix_blocking_unlocked(struct tevent_req *subreq);
8642 static struct tevent_req *posix_blocking_send(
8643 TALLOC_CTX *mem_ctx,
8644 struct tevent_context *ev,
8645 struct cli_state *cli1,
8647 struct cli_state *cli2,
8650 struct tevent_req *req = NULL, *subreq = NULL;
8651 struct posix_blocking_state *state = NULL;
8653 req = tevent_req_create(mem_ctx, &state, struct posix_blocking_state);
8659 state->fnum1 = fnum1;
8661 state->fnum2 = fnum2;
8663 subreq = cli_posix_lock_send(
8672 if (tevent_req_nomem(subreq, req)) {
8673 return tevent_req_post(req, ev);
8675 tevent_req_set_callback(subreq, posix_blocking_locked, req);
8679 static void posix_blocking_locked(struct tevent_req *subreq)
8681 struct tevent_req *req = tevent_req_callback_data(
8682 subreq, struct tevent_req);
8683 struct posix_blocking_state *state = tevent_req_data(
8684 req, struct posix_blocking_state);
8687 status = cli_posix_lock_recv(subreq);
8688 TALLOC_FREE(subreq);
8689 if (tevent_req_nterror(req, status)) {
8693 subreq = cli_posix_lock_send(
8702 if (tevent_req_nomem(subreq, req)) {
8705 tevent_req_set_callback(subreq, posix_blocking_gotblocked, req);
8707 /* Make sure the blocking request is delivered */
8708 subreq = cli_echo_send(
8713 (DATA_BLOB) { .data = (uint8_t *)state, .length = 1 });
8714 if (tevent_req_nomem(subreq, req)) {
8717 tevent_req_set_callback(subreq, posix_blocking_gotecho, req);
8720 static void posix_blocking_gotblocked(struct tevent_req *subreq)
8722 struct tevent_req *req = tevent_req_callback_data(
8723 subreq, struct tevent_req);
8724 struct posix_blocking_state *state = tevent_req_data(
8725 req, struct posix_blocking_state);
8728 status = cli_posix_lock_recv(subreq);
8729 TALLOC_FREE(subreq);
8730 if (tevent_req_nterror(req, status)) {
8733 if (!state->gotecho) {
8734 printf("blocked req got through before echo\n");
8735 tevent_req_nterror(req, NT_STATUS_INVALID_LOCK_SEQUENCE);
8738 tevent_req_done(req);
8741 static void posix_blocking_gotecho(struct tevent_req *subreq)
8743 struct tevent_req *req = tevent_req_callback_data(
8744 subreq, struct tevent_req);
8745 struct posix_blocking_state *state = tevent_req_data(
8746 req, struct posix_blocking_state);
8749 status = cli_echo_recv(subreq);
8750 TALLOC_FREE(subreq);
8751 if (tevent_req_nterror(req, status)) {
8754 if (state->gotblocked) {
8755 printf("blocked req got through before echo\n");
8756 tevent_req_nterror(req, NT_STATUS_INVALID_LOCK_SEQUENCE);
8759 state->gotecho = true;
8761 subreq = cli_posix_lock_send(
8770 if (tevent_req_nomem(subreq, req)) {
8773 tevent_req_set_callback(subreq, posix_blocking_unlocked, req);
8776 static void posix_blocking_unlocked(struct tevent_req *subreq)
8778 struct tevent_req *req = tevent_req_callback_data(
8779 subreq, struct tevent_req);
8782 status = cli_posix_lock_recv(subreq);
8783 TALLOC_FREE(subreq);
8784 if (tevent_req_nterror(req, status)) {
8787 /* tevent_req_done in posix_blocking_gotlocked */
8790 static NTSTATUS posix_blocking_recv(struct tevent_req *req)
8792 return tevent_req_simple_recv_ntstatus(req);
8795 static bool run_posix_blocking_lock(int dummy)
8797 struct tevent_context *ev = NULL;
8798 struct cli_state *cli1 = NULL, *cli2 = NULL;
8799 const char *fname = "posix_blocking";
8800 uint16_t fnum1 = UINT16_MAX, fnum2 = UINT16_MAX;
8801 struct tevent_req *req = NULL;
8806 printf("Starting posix blocking lock test\n");
8808 ev = samba_tevent_context_init(NULL);
8813 ok = torture_open_connection(&cli1, 0);
8817 ok = torture_open_connection(&cli2, 0);
8822 smbXcli_conn_set_sockopt(cli1->conn, sockops);
8824 status = torture_setup_unix_extensions(cli1);
8825 if (!NT_STATUS_IS_OK(status)) {
8829 cli_setatr(cli1, fname, 0, 0);
8830 cli_posix_unlink(cli1, fname);
8832 status = cli_posix_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL,
8834 if (!NT_STATUS_IS_OK(status)) {
8835 printf("First POSIX open of %s failed: %s\n",
8841 status = cli_posix_open(cli2, fname, O_RDWR, 0600, &fnum2);
8842 if (!NT_STATUS_IS_OK(status)) {
8843 printf("Second POSIX open of %s failed: %s\n",
8849 req = posix_blocking_send(ev, ev, cli1, fnum1, cli2, fnum2);
8851 printf("cli_posix_blocking failed\n");
8855 ok = tevent_req_poll_ntstatus(req, ev, &status);
8857 printf("tevent_req_poll_ntstatus failed: %s\n",
8861 status = posix_blocking_recv(req);
8863 if (!NT_STATUS_IS_OK(status)) {
8864 printf("posix_blocking_recv returned %s\n",
8872 if (fnum1 != UINT16_MAX) {
8873 cli_close(cli1, fnum1);
8876 if (fnum2 != UINT16_MAX) {
8877 cli_close(cli2, fnum2);
8882 cli_setatr(cli1, fname, 0, 0);
8883 cli_posix_unlink(cli1, fname);
8889 ok &= torture_close_connection(cli1);
8893 ok &= torture_close_connection(cli2);
8905 Test POSIX mkdir is case-sensitive.
8907 static bool run_posix_mkdir_test(int dummy)
8909 static struct cli_state *cli;
8910 const char *fname_foo = "POSIX_foo";
8911 const char *fname_foo_Foo = "POSIX_foo/Foo";
8912 const char *fname_foo_foo = "POSIX_foo/foo";
8913 const char *fname_Foo = "POSIX_Foo";
8914 const char *fname_Foo_Foo = "POSIX_Foo/Foo";
8915 const char *fname_Foo_foo = "POSIX_Foo/foo";
8916 bool correct = false;
8918 TALLOC_CTX *frame = NULL;
8919 uint16_t fnum = (uint16_t)-1;
8921 frame = talloc_stackframe();
8923 printf("Starting POSIX mkdir test\n");
8925 if (!torture_open_connection(&cli, 0)) {
8930 smbXcli_conn_set_sockopt(cli->conn, sockops);
8932 status = torture_setup_unix_extensions(cli);
8933 if (!NT_STATUS_IS_OK(status)) {
8938 cli_posix_rmdir(cli, fname_foo_foo);
8939 cli_posix_rmdir(cli, fname_foo_Foo);
8940 cli_posix_rmdir(cli, fname_foo);
8942 cli_posix_rmdir(cli, fname_Foo_foo);
8943 cli_posix_rmdir(cli, fname_Foo_Foo);
8944 cli_posix_rmdir(cli, fname_Foo);
8947 * Create a file POSIX_foo then try
8948 * and use it in a directory path by
8949 * doing mkdir POSIX_foo/bar.
8950 * The mkdir should fail with
8951 * NT_STATUS_OBJECT_PATH_NOT_FOUND
8954 status = cli_posix_open(cli,
8959 if (!NT_STATUS_IS_OK(status)) {
8960 printf("cli_posix_open of %s failed error %s\n",
8966 status = cli_posix_mkdir(cli, fname_foo_foo, 0777);
8967 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_PATH_NOT_FOUND)) {
8968 printf("cli_posix_mkdir of %s should fail with "
8969 "NT_STATUS_OBJECT_PATH_NOT_FOUND got "
8976 status = cli_close(cli, fnum);
8977 if (!NT_STATUS_IS_OK(status)) {
8978 printf("cli_close failed %s\n", nt_errstr(status));
8981 fnum = (uint16_t)-1;
8983 status = cli_posix_unlink(cli, fname_foo);
8984 if (!NT_STATUS_IS_OK(status)) {
8985 printf("cli_posix_unlink of %s failed error %s\n",
8992 * Now we've deleted everything, posix_mkdir, posix_rmdir,
8993 * posix_open, posix_unlink, on
8994 * POSIX_foo/foo should return NT_STATUS_OBJECT_PATH_NOT_FOUND
8995 * not silently create POSIX_foo/foo.
8998 status = cli_posix_mkdir(cli, fname_foo_foo, 0777);
8999 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_PATH_NOT_FOUND)) {
9000 printf("cli_posix_mkdir of %s should fail with "
9001 "NT_STATUS_OBJECT_PATH_NOT_FOUND got "
9008 status = cli_posix_rmdir(cli, fname_foo_foo);
9009 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_PATH_NOT_FOUND)) {
9010 printf("cli_posix_rmdir of %s should fail with "
9011 "NT_STATUS_OBJECT_PATH_NOT_FOUND got "
9018 status = cli_posix_open(cli,
9023 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_PATH_NOT_FOUND)) {
9024 printf("cli_posix_open of %s should fail with "
9025 "NT_STATUS_OBJECT_PATH_NOT_FOUND got "
9032 status = cli_posix_unlink(cli, fname_foo_foo);
9033 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_PATH_NOT_FOUND)) {
9034 printf("cli_posix_unlink of %s should fail with "
9035 "NT_STATUS_OBJECT_PATH_NOT_FOUND got "
9042 status = cli_posix_mkdir(cli, fname_foo, 0777);
9043 if (!NT_STATUS_IS_OK(status)) {
9044 printf("cli_posix_mkdir of %s failed\n", fname_foo);
9048 status = cli_posix_mkdir(cli, fname_Foo, 0777);
9049 if (!NT_STATUS_IS_OK(status)) {
9050 printf("cli_posix_mkdir of %s failed\n", fname_Foo);
9054 status = cli_posix_mkdir(cli, fname_foo_foo, 0777);
9055 if (!NT_STATUS_IS_OK(status)) {
9056 printf("cli_posix_mkdir of %s failed\n", fname_foo_foo);
9060 status = cli_posix_mkdir(cli, fname_foo_Foo, 0777);
9061 if (!NT_STATUS_IS_OK(status)) {
9062 printf("cli_posix_mkdir of %s failed\n", fname_foo_Foo);
9066 status = cli_posix_mkdir(cli, fname_Foo_foo, 0777);
9067 if (!NT_STATUS_IS_OK(status)) {
9068 printf("cli_posix_mkdir of %s failed\n", fname_Foo_foo);
9072 status = cli_posix_mkdir(cli, fname_Foo_Foo, 0777);
9073 if (!NT_STATUS_IS_OK(status)) {
9074 printf("cli_posix_mkdir of %s failed\n", fname_Foo_Foo);
9078 printf("POSIX mkdir test passed\n");
9083 if (fnum != (uint16_t)-1) {
9084 cli_close(cli, fnum);
9085 fnum = (uint16_t)-1;
9088 cli_posix_rmdir(cli, fname_foo_foo);
9089 cli_posix_rmdir(cli, fname_foo_Foo);
9090 cli_posix_rmdir(cli, fname_foo);
9092 cli_posix_rmdir(cli, fname_Foo_foo);
9093 cli_posix_rmdir(cli, fname_Foo_Foo);
9094 cli_posix_rmdir(cli, fname_Foo);
9096 if (!torture_close_connection(cli)) {
9104 struct posix_acl_oplock_state {
9105 struct tevent_context *ev;
9106 struct cli_state *cli;
9112 static void posix_acl_oplock_got_break(struct tevent_req *req)
9114 struct posix_acl_oplock_state *state = tevent_req_callback_data(
9115 req, struct posix_acl_oplock_state);
9120 status = cli_smb_oplock_break_waiter_recv(req, &fnum, &level);
9122 if (!NT_STATUS_IS_OK(status)) {
9123 printf("cli_smb_oplock_break_waiter_recv returned %s\n",
9127 *state->got_break = true;
9129 req = cli_oplock_ack_send(state, state->ev, state->cli, fnum,
9132 printf("cli_oplock_ack_send failed\n");
9137 static void posix_acl_oplock_got_acl(struct tevent_req *req)
9139 struct posix_acl_oplock_state *state = tevent_req_callback_data(
9140 req, struct posix_acl_oplock_state);
9141 size_t ret_size = 0;
9142 char *ret_data = NULL;
9144 state->status = cli_posix_getacl_recv(req,
9149 if (!NT_STATUS_IS_OK(state->status)) {
9150 printf("cli_posix_getacl_recv returned %s\n",
9151 nt_errstr(state->status));
9153 *state->acl_ret = true;
9156 static bool run_posix_acl_oplock_test(int dummy)
9158 struct tevent_context *ev;
9159 struct cli_state *cli1, *cli2;
9160 struct tevent_req *oplock_req, *getacl_req;
9161 const char *fname = "posix_acl_oplock";
9163 int saved_use_oplocks = use_oplocks;
9165 bool correct = true;
9166 bool got_break = false;
9167 bool acl_ret = false;
9169 struct posix_acl_oplock_state *state;
9171 printf("starting posix_acl_oplock test\n");
9173 if (!torture_open_connection(&cli1, 0)) {
9174 use_level_II_oplocks = false;
9175 use_oplocks = saved_use_oplocks;
9179 if (!torture_open_connection(&cli2, 1)) {
9180 use_level_II_oplocks = false;
9181 use_oplocks = saved_use_oplocks;
9185 /* Setup posix on cli2 only. */
9186 status = torture_setup_unix_extensions(cli2);
9187 if (!NT_STATUS_IS_OK(status)) {
9191 smbXcli_conn_set_sockopt(cli1->conn, sockops);
9192 smbXcli_conn_set_sockopt(cli2->conn, sockops);
9194 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
9196 /* Create the file on the Windows connection. */
9197 status = cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
9199 if (!NT_STATUS_IS_OK(status)) {
9200 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
9204 status = cli_close(cli1, fnum);
9205 if (!NT_STATUS_IS_OK(status)) {
9206 printf("close1 failed (%s)\n", nt_errstr(status));
9210 cli1->use_oplocks = true;
9212 /* Open with oplock. */
9213 status = cli_ntcreate(cli1,
9217 FILE_ATTRIBUTE_NORMAL,
9218 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
9225 if (!NT_STATUS_IS_OK(status)) {
9226 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
9230 ev = samba_tevent_context_init(talloc_tos());
9232 printf("tevent_context_init failed\n");
9236 state = talloc_zero(ev, struct posix_acl_oplock_state);
9237 if (state == NULL) {
9238 printf("talloc failed\n");
9243 state->got_break = &got_break;
9244 state->acl_ret = &acl_ret;
9246 oplock_req = cli_smb_oplock_break_waiter_send(
9247 talloc_tos(), ev, cli1);
9248 if (oplock_req == NULL) {
9249 printf("cli_smb_oplock_break_waiter_send failed\n");
9252 tevent_req_set_callback(oplock_req, posix_acl_oplock_got_break, state);
9254 /* Get ACL on POSIX connection - should break oplock. */
9255 getacl_req = cli_posix_getacl_send(talloc_tos(),
9259 if (getacl_req == NULL) {
9260 printf("cli_posix_getacl_send failed\n");
9263 tevent_req_set_callback(getacl_req, posix_acl_oplock_got_acl, state);
9265 while (!got_break || !acl_ret) {
9267 ret = tevent_loop_once(ev);
9269 printf("tevent_loop_once failed: %s\n",
9275 if (!NT_STATUS_IS_OK(state->status)) {
9276 printf("getacl failed (%s)\n", nt_errstr(state->status));
9280 status = cli_close(cli1, fnum);
9281 if (!NT_STATUS_IS_OK(status)) {
9282 printf("close2 failed (%s)\n", nt_errstr(status));
9286 status = cli_unlink(cli1,
9288 FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
9289 if (!NT_STATUS_IS_OK(status)) {
9290 printf("unlink failed (%s)\n", nt_errstr(status));
9294 if (!torture_close_connection(cli1)) {
9297 if (!torture_close_connection(cli2)) {
9305 printf("finished posix acl oplock test\n");
9310 static bool run_posix_acl_shareroot_test(int dummy)
9312 struct cli_state *cli;
9314 bool correct = false;
9315 char *posix_acl = NULL;
9316 size_t posix_acl_len = 0;
9317 uint16_t num_file_acls = 0;
9318 uint16_t num_dir_acls = 0;
9320 uint32_t expected_size = 0;
9321 bool got_user = false;
9322 bool got_group = false;
9323 bool got_other = false;
9324 TALLOC_CTX *frame = NULL;
9326 frame = talloc_stackframe();
9328 printf("starting posix_acl_shareroot test\n");
9330 if (!torture_open_connection(&cli, 0)) {
9335 smbXcli_conn_set_sockopt(cli->conn, sockops);
9337 status = torture_setup_unix_extensions(cli);
9338 if (!NT_STATUS_IS_OK(status)) {
9339 printf("Failed to setup unix extensions\n");
9343 /* Get the POSIX ACL on the root of the share. */
9344 status = cli_posix_getacl(cli,
9350 if (!NT_STATUS_IS_OK(status)) {
9351 printf("cli_posix_getacl of '.' failed (%s)\n",
9356 if (posix_acl_len < 6 ||
9357 SVAL(posix_acl,0) != SMB_POSIX_ACL_VERSION) {
9358 printf("getfacl ., unknown POSIX acl version %u.\n",
9359 (unsigned int)CVAL(posix_acl,0) );
9363 num_file_acls = SVAL(posix_acl,2);
9364 num_dir_acls = SVAL(posix_acl,4);
9365 expected_size = SMB_POSIX_ACL_HEADER_SIZE +
9366 SMB_POSIX_ACL_ENTRY_SIZE*
9367 (num_file_acls+num_dir_acls);
9369 if (posix_acl_len != expected_size) {
9370 printf("incorrect POSIX acl buffer size "
9371 "(should be %u, was %u).\n",
9372 (unsigned int)expected_size,
9373 (unsigned int)posix_acl_len);
9378 * We don't need to know what the ACL's are
9379 * we just need to know we have at least 3
9380 * file entries (u,g,o).
9383 for (i = 0; i < num_file_acls; i++) {
9384 unsigned char tagtype =
9386 SMB_POSIX_ACL_HEADER_SIZE+
9387 (i*SMB_POSIX_ACL_ENTRY_SIZE));
9390 case SMB_POSIX_ACL_USER_OBJ:
9393 case SMB_POSIX_ACL_GROUP_OBJ:
9396 case SMB_POSIX_ACL_OTHER:
9405 printf("Missing user entry\n");
9410 printf("Missing group entry\n");
9415 printf("Missing other entry\n");
9423 if (!torture_close_connection(cli)) {
9427 printf("finished posix acl shareroot test\n");
9433 static uint32_t open_attrs_table[] = {
9434 FILE_ATTRIBUTE_NORMAL,
9435 FILE_ATTRIBUTE_ARCHIVE,
9436 FILE_ATTRIBUTE_READONLY,
9437 FILE_ATTRIBUTE_HIDDEN,
9438 FILE_ATTRIBUTE_SYSTEM,
9440 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY,
9441 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN,
9442 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM,
9443 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
9444 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
9445 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
9447 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
9448 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
9449 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
9450 FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_SYSTEM,
9453 struct trunc_open_results {
9456 uint32_t trunc_attr;
9457 uint32_t result_attr;
9460 static struct trunc_open_results attr_results[] = {
9461 { 0, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
9462 { 1, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
9463 { 2, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
9464 { 16, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
9465 { 17, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
9466 { 18, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
9467 { 51, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
9468 { 54, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
9469 { 56, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
9470 { 68, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
9471 { 71, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
9472 { 73, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM },
9473 { 99, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
9474 { 102, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
9475 { 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 },
9476 { 116, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
9477 { 119, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
9478 { 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 },
9479 { 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 },
9480 { 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 },
9481 { 227, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
9482 { 230, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
9483 { 232, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
9484 { 244, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
9485 { 247, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
9486 { 249, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM }
9489 static bool run_openattrtest(int dummy)
9491 static struct cli_state *cli1;
9492 const char *fname = "\\openattr.file";
9494 bool correct = True;
9496 unsigned int i, j, k, l;
9499 printf("starting open attr test\n");
9501 if (!torture_open_connection(&cli1, 0)) {
9505 smbXcli_conn_set_sockopt(cli1->conn, sockops);
9507 for (k = 0, i = 0; i < sizeof(open_attrs_table)/sizeof(uint32_t); i++) {
9508 cli_setatr(cli1, fname, 0, 0);
9509 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
9511 status = cli_ntcreate(cli1, fname, 0, FILE_WRITE_DATA,
9512 open_attrs_table[i], FILE_SHARE_NONE,
9513 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
9514 if (!NT_STATUS_IS_OK(status)) {
9515 printf("open %d (1) of %s failed (%s)\n", i, fname, nt_errstr(status));
9519 status = cli_close(cli1, fnum1);
9520 if (!NT_STATUS_IS_OK(status)) {
9521 printf("close %d (1) of %s failed (%s)\n", i, fname, nt_errstr(status));
9525 for (j = 0; j < sizeof(open_attrs_table)/sizeof(uint32_t); j++) {
9526 status = cli_ntcreate(cli1, fname, 0,
9527 FILE_READ_DATA|FILE_WRITE_DATA,
9528 open_attrs_table[j],
9529 FILE_SHARE_NONE, FILE_OVERWRITE,
9530 0, 0, &fnum1, NULL);
9531 if (!NT_STATUS_IS_OK(status)) {
9532 for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
9533 if (attr_results[l].num == k) {
9534 printf("[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(0x%x:%s)\n",
9535 k, open_attrs_table[i],
9536 open_attrs_table[j],
9537 fname, NT_STATUS_V(status), nt_errstr(status));
9542 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
9543 printf("[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s\n",
9544 k, open_attrs_table[i], open_attrs_table[j],
9549 printf("[%d] trunc open 0x%x -> 0x%x failed\n", k, open_attrs_table[i], open_attrs_table[j]);
9555 status = cli_close(cli1, fnum1);
9556 if (!NT_STATUS_IS_OK(status)) {
9557 printf("close %d (2) of %s failed (%s)\n", j, fname, nt_errstr(status));
9561 status = cli_getatr(cli1, fname, &attr, NULL, NULL);
9562 if (!NT_STATUS_IS_OK(status)) {
9563 printf("getatr(2) failed (%s)\n", nt_errstr(status));
9568 printf("[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n",
9569 k, open_attrs_table[i], open_attrs_table[j], attr );
9572 for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
9573 if (attr_results[l].num == k) {
9574 if (attr != attr_results[l].result_attr ||
9575 open_attrs_table[i] != attr_results[l].init_attr ||
9576 open_attrs_table[j] != attr_results[l].trunc_attr) {
9577 printf("getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x\n",
9578 open_attrs_table[i],
9579 open_attrs_table[j],
9581 attr_results[l].result_attr);
9591 cli_setatr(cli1, fname, 0, 0);
9592 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
9594 printf("open attr test %s.\n", correct ? "passed" : "failed");
9596 if (!torture_close_connection(cli1)) {
9602 static NTSTATUS list_fn(const char *mnt, struct file_info *finfo,
9603 const char *name, void *state)
9605 int *matched = (int *)state;
9606 if (matched != NULL) {
9609 return NT_STATUS_OK;
9613 test directory listing speed
9615 static bool run_dirtest(int dummy)
9618 static struct cli_state *cli;
9620 struct timeval core_start;
9621 bool correct = True;
9624 printf("starting directory test\n");
9626 if (!torture_open_connection(&cli, 0)) {
9630 smbXcli_conn_set_sockopt(cli->conn, sockops);
9633 for (i=0;i<torture_numops;i++) {
9635 slprintf(fname, sizeof(fname), "\\%x", (int)random());
9636 if (!NT_STATUS_IS_OK(cli_openx(cli, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum))) {
9637 fprintf(stderr,"Failed to open %s\n", fname);
9640 cli_close(cli, fnum);
9643 core_start = timeval_current();
9646 cli_list(cli, "a*.*", 0, list_fn, &matched);
9647 printf("Matched %d\n", matched);
9650 cli_list(cli, "b*.*", 0, list_fn, &matched);
9651 printf("Matched %d\n", matched);
9654 cli_list(cli, "xyzabc", 0, list_fn, &matched);
9655 printf("Matched %d\n", matched);
9657 printf("dirtest core %g seconds\n", timeval_elapsed(&core_start));
9660 for (i=0;i<torture_numops;i++) {
9662 slprintf(fname, sizeof(fname), "\\%x", (int)random());
9663 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
9666 if (!torture_close_connection(cli)) {
9670 printf("finished dirtest\n");
9675 static NTSTATUS del_fn(const char *mnt, struct file_info *finfo, const char *mask,
9678 struct cli_state *pcli = (struct cli_state *)state;
9680 slprintf(fname, sizeof(fname), "\\LISTDIR\\%s", finfo->name);
9682 if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
9683 return NT_STATUS_OK;
9685 if (finfo->mode & FILE_ATTRIBUTE_DIRECTORY) {
9686 if (!NT_STATUS_IS_OK(cli_rmdir(pcli, fname)))
9687 printf("del_fn: failed to rmdir %s\n,", fname );
9689 if (!NT_STATUS_IS_OK(cli_unlink(pcli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN)))
9690 printf("del_fn: failed to unlink %s\n,", fname );
9692 return NT_STATUS_OK;
9697 sees what IOCTLs are supported
9699 bool torture_ioctl_test(int dummy)
9701 static struct cli_state *cli;
9702 uint16_t device, function;
9704 const char *fname = "\\ioctl.dat";
9708 if (!torture_open_connection(&cli, 0)) {
9712 printf("starting ioctl test\n");
9714 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
9716 status = cli_openx(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
9717 if (!NT_STATUS_IS_OK(status)) {
9718 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
9722 status = cli_raw_ioctl(cli, fnum, 0x2d0000 | (0x0420<<2), &blob);
9723 printf("ioctl device info: %s\n", nt_errstr(status));
9725 status = cli_raw_ioctl(cli, fnum, IOCTL_QUERY_JOB_INFO, &blob);
9726 printf("ioctl job info: %s\n", nt_errstr(status));
9728 for (device=0;device<0x100;device++) {
9729 printf("ioctl test with device = 0x%x\n", device);
9730 for (function=0;function<0x100;function++) {
9731 uint32_t code = (device<<16) | function;
9733 status = cli_raw_ioctl(cli, fnum, code, &blob);
9735 if (NT_STATUS_IS_OK(status)) {
9736 printf("ioctl 0x%x OK : %d bytes\n", (int)code,
9738 data_blob_free(&blob);
9743 if (!torture_close_connection(cli)) {
9752 tries varients of chkpath
9754 bool torture_chkpath_test(int dummy)
9756 static struct cli_state *cli;
9761 if (!torture_open_connection(&cli, 0)) {
9765 printf("starting chkpath test\n");
9767 /* cleanup from an old run */
9768 cli_rmdir(cli, "\\chkpath.dir\\dir2");
9769 cli_unlink(cli, "\\chkpath.dir\\*", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
9770 cli_rmdir(cli, "\\chkpath.dir");
9772 status = cli_mkdir(cli, "\\chkpath.dir");
9773 if (!NT_STATUS_IS_OK(status)) {
9774 printf("mkdir1 failed : %s\n", nt_errstr(status));
9778 status = cli_mkdir(cli, "\\chkpath.dir\\dir2");
9779 if (!NT_STATUS_IS_OK(status)) {
9780 printf("mkdir2 failed : %s\n", nt_errstr(status));
9784 status = cli_openx(cli, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL,
9786 if (!NT_STATUS_IS_OK(status)) {
9787 printf("open1 failed (%s)\n", nt_errstr(status));
9790 cli_close(cli, fnum);
9792 status = cli_chkpath(cli, "\\chkpath.dir");
9793 if (!NT_STATUS_IS_OK(status)) {
9794 printf("chkpath1 failed: %s\n", nt_errstr(status));
9798 status = cli_chkpath(cli, "\\chkpath.dir\\dir2");
9799 if (!NT_STATUS_IS_OK(status)) {
9800 printf("chkpath2 failed: %s\n", nt_errstr(status));
9804 status = cli_chkpath(cli, "\\chkpath.dir\\foo.txt");
9805 if (!NT_STATUS_IS_OK(status)) {
9806 ret = check_error(__LINE__, status, ERRDOS, ERRbadpath,
9807 NT_STATUS_NOT_A_DIRECTORY);
9809 printf("* chkpath on a file should fail\n");
9813 status = cli_chkpath(cli, "\\chkpath.dir\\bar.txt");
9814 if (!NT_STATUS_IS_OK(status)) {
9815 ret = check_error(__LINE__, status, ERRDOS, ERRbadfile,
9816 NT_STATUS_OBJECT_NAME_NOT_FOUND);
9818 printf("* chkpath on a non existent file should fail\n");
9822 status = cli_chkpath(cli, "\\chkpath.dir\\dirxx\\bar.txt");
9823 if (!NT_STATUS_IS_OK(status)) {
9824 ret = check_error(__LINE__, status, ERRDOS, ERRbadpath,
9825 NT_STATUS_OBJECT_PATH_NOT_FOUND);
9827 printf("* chkpath on a non existent component should fail\n");
9831 cli_rmdir(cli, "\\chkpath.dir\\dir2");
9832 cli_unlink(cli, "\\chkpath.dir\\*", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
9833 cli_rmdir(cli, "\\chkpath.dir");
9835 if (!torture_close_connection(cli)) {
9842 static bool run_eatest(int dummy)
9844 static struct cli_state *cli;
9845 const char *fname = "\\eatest.txt";
9846 bool correct = True;
9850 struct ea_struct *ea_list = NULL;
9851 TALLOC_CTX *mem_ctx = talloc_init("eatest");
9854 printf("starting eatest\n");
9856 if (!torture_open_connection(&cli, 0)) {
9857 talloc_destroy(mem_ctx);
9861 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
9863 status = cli_ntcreate(cli, fname, 0,
9864 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
9865 FILE_SHARE_NONE, FILE_OVERWRITE_IF,
9866 0x4044, 0, &fnum, NULL);
9867 if (!NT_STATUS_IS_OK(status)) {
9868 printf("open failed - %s\n", nt_errstr(status));
9869 talloc_destroy(mem_ctx);
9873 for (i = 0; i < 10; i++) {
9874 fstring ea_name, ea_val;
9876 slprintf(ea_name, sizeof(ea_name), "EA_%d", i);
9877 memset(ea_val, (char)i+1, i+1);
9878 status = cli_set_ea_fnum(cli, fnum, ea_name, ea_val, i+1);
9879 if (!NT_STATUS_IS_OK(status)) {
9880 printf("ea_set of name %s failed - %s\n", ea_name,
9882 talloc_destroy(mem_ctx);
9887 cli_close(cli, fnum);
9888 for (i = 0; i < 10; i++) {
9889 fstring ea_name, ea_val;
9891 slprintf(ea_name, sizeof(ea_name), "EA_%d", i+10);
9892 memset(ea_val, (char)i+1, i+1);
9893 status = cli_set_ea_path(cli, fname, ea_name, ea_val, i+1);
9894 if (!NT_STATUS_IS_OK(status)) {
9895 printf("ea_set of name %s failed - %s\n", ea_name,
9897 talloc_destroy(mem_ctx);
9902 status = cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list);
9903 if (!NT_STATUS_IS_OK(status)) {
9904 printf("ea_get list failed - %s\n", nt_errstr(status));
9908 printf("num_eas = %d\n", (int)num_eas);
9910 if (num_eas != 20) {
9911 printf("Should be 20 EA's stored... failing.\n");
9915 for (i = 0; i < num_eas; i++) {
9916 printf("%d: ea_name = %s. Val = ", i, ea_list[i].name);
9917 dump_data(0, ea_list[i].value.data,
9918 ea_list[i].value.length);
9921 /* Setting EA's to zero length deletes them. Test this */
9922 printf("Now deleting all EA's - case indepenent....\n");
9925 cli_set_ea_path(cli, fname, "", "", 0);
9927 for (i = 0; i < 20; i++) {
9929 slprintf(ea_name, sizeof(ea_name), "ea_%d", i);
9930 status = cli_set_ea_path(cli, fname, ea_name, "", 0);
9931 if (!NT_STATUS_IS_OK(status)) {
9932 printf("ea_set of name %s failed - %s\n", ea_name,
9934 talloc_destroy(mem_ctx);
9940 status = cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list);
9941 if (!NT_STATUS_IS_OK(status)) {
9942 printf("ea_get list failed - %s\n", nt_errstr(status));
9946 printf("num_eas = %d\n", (int)num_eas);
9947 for (i = 0; i < num_eas; i++) {
9948 printf("%d: ea_name = %s. Val = ", i, ea_list[i].name);
9949 dump_data(0, ea_list[i].value.data,
9950 ea_list[i].value.length);
9954 printf("deleting EA's failed.\n");
9958 /* Try and delete a non existent EA. */
9959 status = cli_set_ea_path(cli, fname, "foo", "", 0);
9960 if (!NT_STATUS_IS_OK(status)) {
9961 printf("deleting non-existent EA 'foo' should succeed. %s\n",
9966 talloc_destroy(mem_ctx);
9967 if (!torture_close_connection(cli)) {
9974 static bool run_dirtest1(int dummy)
9977 static struct cli_state *cli;
9980 bool correct = True;
9982 printf("starting directory test\n");
9984 if (!torture_open_connection(&cli, 0)) {
9988 smbXcli_conn_set_sockopt(cli->conn, sockops);
9990 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
9991 cli_list(cli, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, del_fn, cli);
9992 cli_rmdir(cli, "\\LISTDIR");
9993 cli_mkdir(cli, "\\LISTDIR");
9995 /* Create 1000 files and 1000 directories. */
9996 for (i=0;i<1000;i++) {
9998 slprintf(fname, sizeof(fname), "\\LISTDIR\\f%d", i);
9999 if (!NT_STATUS_IS_OK(cli_ntcreate(cli, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
10000 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF,
10001 0, 0, &fnum, NULL))) {
10002 fprintf(stderr,"Failed to open %s\n", fname);
10005 cli_close(cli, fnum);
10007 for (i=0;i<1000;i++) {
10009 slprintf(fname, sizeof(fname), "\\LISTDIR\\d%d", i);
10010 if (!NT_STATUS_IS_OK(cli_mkdir(cli, fname))) {
10011 fprintf(stderr,"Failed to open %s\n", fname);
10016 /* Now ensure that doing an old list sees both files and directories. */
10018 cli_list_old(cli, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, list_fn, &num_seen);
10019 printf("num_seen = %d\n", num_seen );
10020 /* We should see 100 files + 1000 directories + . and .. */
10021 if (num_seen != 2002)
10024 /* Ensure if we have the "must have" bits we only see the
10025 * relevent entries.
10028 cli_list_old(cli, "\\LISTDIR\\*", (FILE_ATTRIBUTE_DIRECTORY<<8)|FILE_ATTRIBUTE_DIRECTORY, list_fn, &num_seen);
10029 printf("num_seen = %d\n", num_seen );
10030 if (num_seen != 1002)
10034 cli_list_old(cli, "\\LISTDIR\\*", (FILE_ATTRIBUTE_ARCHIVE<<8)|FILE_ATTRIBUTE_DIRECTORY, list_fn, &num_seen);
10035 printf("num_seen = %d\n", num_seen );
10036 if (num_seen != 1000)
10039 /* Delete everything. */
10040 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
10041 cli_list(cli, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, del_fn, cli);
10042 cli_rmdir(cli, "\\LISTDIR");
10045 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
10046 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
10047 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
10050 if (!torture_close_connection(cli)) {
10054 printf("finished dirtest1\n");
10059 static bool run_error_map_extract(int dummy) {
10061 static struct cli_state *c_dos;
10062 static struct cli_state *c_nt;
10070 NTSTATUS nt_status;
10074 /* NT-Error connection */
10076 disable_spnego = true;
10077 if (!(c_nt = open_nbt_connection())) {
10078 disable_spnego = false;
10081 disable_spnego = false;
10083 status = smbXcli_negprot(c_nt->conn, c_nt->timeout, PROTOCOL_CORE,
10086 if (!NT_STATUS_IS_OK(status)) {
10087 printf("%s rejected the NT-error negprot (%s)\n", host,
10088 nt_errstr(status));
10089 cli_shutdown(c_nt);
10093 status = cli_session_setup_anon(c_nt);
10094 if (!NT_STATUS_IS_OK(status)) {
10095 printf("%s rejected the NT-error initial session setup (%s)\n",host, nt_errstr(status));
10099 /* DOS-Error connection */
10101 disable_spnego = true;
10102 force_dos_errors = true;
10103 if (!(c_dos = open_nbt_connection())) {
10104 disable_spnego = false;
10105 force_dos_errors = false;
10108 disable_spnego = false;
10109 force_dos_errors = false;
10111 status = smbXcli_negprot(c_dos->conn, c_dos->timeout, PROTOCOL_CORE,
10113 if (!NT_STATUS_IS_OK(status)) {
10114 printf("%s rejected the DOS-error negprot (%s)\n", host,
10115 nt_errstr(status));
10116 cli_shutdown(c_dos);
10120 status = cli_session_setup_anon(c_dos);
10121 if (!NT_STATUS_IS_OK(status)) {
10122 printf("%s rejected the DOS-error initial session setup (%s)\n",
10123 host, nt_errstr(status));
10127 c_nt->map_dos_errors = false;
10128 c_dos->map_dos_errors = false;
10130 for (error=(0xc0000000 | 0x1); error < (0xc0000000| 0xFFF); error++) {
10131 struct cli_credentials *user_creds = NULL;
10133 fstr_sprintf(user, "%X", error);
10135 user_creds = cli_session_creds_init(talloc_tos(),
10140 false, /* use_kerberos */
10141 false, /* fallback_after_kerberos */
10142 false, /* use_ccache */
10143 false); /* password_is_nt_hash */
10144 if (user_creds == NULL) {
10145 printf("cli_session_creds_init(%s) failed\n", user);
10149 status = cli_session_setup_creds(c_nt, user_creds);
10150 if (NT_STATUS_IS_OK(status)) {
10151 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
10154 /* Case #1: 32-bit NT errors */
10155 if (!NT_STATUS_IS_DOS(status)) {
10156 nt_status = status;
10158 printf("/** Dos error on NT connection! (%s) */\n",
10159 nt_errstr(status));
10160 nt_status = NT_STATUS(0xc0000000);
10163 status = cli_session_setup_creds(c_dos, user_creds);
10164 if (NT_STATUS_IS_OK(status)) {
10165 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
10168 /* Case #1: 32-bit NT errors */
10169 if (NT_STATUS_IS_DOS(status)) {
10170 printf("/** NT error on DOS connection! (%s) */\n",
10171 nt_errstr(status));
10172 errnum = errclass = 0;
10174 errclass = NT_STATUS_DOS_CLASS(status);
10175 errnum = NT_STATUS_DOS_CODE(status);
10178 if (NT_STATUS_V(nt_status) != error) {
10179 printf("/*\t{ This NT error code was 'sqashed'\n\t from %s to %s \n\t during the session setup }\n*/\n",
10180 get_nt_error_c_code(talloc_tos(), NT_STATUS(error)),
10181 get_nt_error_c_code(talloc_tos(), nt_status));
10184 printf("\t{%s,\t%s,\t%s},\n",
10185 smb_dos_err_class(errclass),
10186 smb_dos_err_name(errclass, errnum),
10187 get_nt_error_c_code(talloc_tos(), NT_STATUS(error)));
10189 TALLOC_FREE(user_creds);
10194 static bool run_sesssetup_bench(int dummy)
10196 static struct cli_state *c;
10197 const char *fname = "\\file.dat";
10202 if (!torture_open_connection(&c, 0)) {
10206 status = cli_ntcreate(c, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
10207 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
10208 FILE_DELETE_ON_CLOSE, 0, &fnum, NULL);
10209 if (!NT_STATUS_IS_OK(status)) {
10210 d_printf("open %s failed: %s\n", fname, nt_errstr(status));
10214 for (i=0; i<torture_numops; i++) {
10215 status = cli_session_setup_creds(c, torture_creds);
10216 if (!NT_STATUS_IS_OK(status)) {
10217 d_printf("(%s) cli_session_setup_creds failed: %s\n",
10218 __location__, nt_errstr(status));
10222 d_printf("\r%d ", (int)cli_state_get_uid(c));
10224 status = cli_ulogoff(c);
10225 if (!NT_STATUS_IS_OK(status)) {
10226 d_printf("(%s) cli_ulogoff failed: %s\n",
10227 __location__, nt_errstr(status));
10235 static bool subst_test(const char *str, const char *user, const char *domain,
10236 uid_t uid, gid_t gid, const char *expected)
10239 bool result = true;
10241 subst = talloc_sub_specified(talloc_tos(), str, user, NULL, domain, uid, gid);
10243 if (strcmp(subst, expected) != 0) {
10244 printf("sub_specified(%s, %s, %s, %d, %d) returned [%s], expected "
10245 "[%s]\n", str, user, domain, (int)uid, (int)gid, subst,
10250 TALLOC_FREE(subst);
10254 static void chain1_open_completion(struct tevent_req *req)
10258 status = cli_openx_recv(req, &fnum);
10261 d_printf("cli_openx_recv returned %s: %d\n",
10263 NT_STATUS_IS_OK(status) ? fnum : -1);
10266 static void chain1_write_completion(struct tevent_req *req)
10270 status = cli_write_andx_recv(req, &written);
10273 d_printf("cli_write_andx_recv returned %s: %d\n",
10275 NT_STATUS_IS_OK(status) ? (int)written : -1);
10278 static void chain1_close_completion(struct tevent_req *req)
10281 bool *done = (bool *)tevent_req_callback_data_void(req);
10283 status = cli_close_recv(req);
10288 d_printf("cli_close returned %s\n", nt_errstr(status));
10291 static bool run_chain1(int dummy)
10293 struct cli_state *cli1;
10294 struct tevent_context *evt = samba_tevent_context_init(NULL);
10295 struct tevent_req *reqs[3], *smbreqs[3];
10297 const char *str = "foobar";
10298 const char *fname = "\\test_chain";
10301 printf("starting chain1 test\n");
10302 if (!torture_open_connection(&cli1, 0)) {
10306 smbXcli_conn_set_sockopt(cli1->conn, sockops);
10308 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
10310 reqs[0] = cli_openx_create(talloc_tos(), evt, cli1, fname,
10311 O_CREAT|O_RDWR, 0, &smbreqs[0]);
10312 if (reqs[0] == NULL) return false;
10313 tevent_req_set_callback(reqs[0], chain1_open_completion, NULL);
10316 reqs[1] = cli_write_andx_create(talloc_tos(), evt, cli1, 0, 0,
10317 (const uint8_t *)str, 0, strlen(str)+1,
10318 smbreqs, 1, &smbreqs[1]);
10319 if (reqs[1] == NULL) return false;
10320 tevent_req_set_callback(reqs[1], chain1_write_completion, NULL);
10322 reqs[2] = cli_smb1_close_create(talloc_tos(), evt, cli1, 0, &smbreqs[2]);
10323 if (reqs[2] == NULL) return false;
10324 tevent_req_set_callback(reqs[2], chain1_close_completion, &done);
10326 status = smb1cli_req_chain_submit(smbreqs, ARRAY_SIZE(smbreqs));
10327 if (!NT_STATUS_IS_OK(status)) {
10332 tevent_loop_once(evt);
10335 torture_close_connection(cli1);
10339 static void chain2_sesssetup_completion(struct tevent_req *req)
10342 status = cli_session_setup_guest_recv(req);
10343 d_printf("sesssetup returned %s\n", nt_errstr(status));
10346 static void chain2_tcon_completion(struct tevent_req *req)
10348 bool *done = (bool *)tevent_req_callback_data_void(req);
10350 status = cli_tcon_andx_recv(req);
10351 d_printf("tcon_and_x returned %s\n", nt_errstr(status));
10355 static bool run_chain2(int dummy)
10357 struct cli_state *cli1;
10358 struct tevent_context *evt = samba_tevent_context_init(NULL);
10359 struct tevent_req *reqs[2], *smbreqs[2];
10362 int flags = CLI_FULL_CONNECTION_FORCE_SMB1;
10364 printf("starting chain2 test\n");
10365 status = cli_start_connection(&cli1, lp_netbios_name(), host, NULL,
10366 port_to_use, SMB_SIGNING_DEFAULT, flags);
10367 if (!NT_STATUS_IS_OK(status)) {
10371 smbXcli_conn_set_sockopt(cli1->conn, sockops);
10373 reqs[0] = cli_session_setup_guest_create(talloc_tos(), evt, cli1,
10375 if (reqs[0] == NULL) return false;
10376 tevent_req_set_callback(reqs[0], chain2_sesssetup_completion, NULL);
10378 reqs[1] = cli_tcon_andx_create(talloc_tos(), evt, cli1, "IPC$",
10379 "?????", NULL, 0, &smbreqs[1]);
10380 if (reqs[1] == NULL) return false;
10381 tevent_req_set_callback(reqs[1], chain2_tcon_completion, &done);
10383 status = smb1cli_req_chain_submit(smbreqs, ARRAY_SIZE(smbreqs));
10384 if (!NT_STATUS_IS_OK(status)) {
10389 tevent_loop_once(evt);
10392 torture_close_connection(cli1);
10397 struct torture_createdel_state {
10398 struct tevent_context *ev;
10399 struct cli_state *cli;
10402 static void torture_createdel_created(struct tevent_req *subreq);
10403 static void torture_createdel_closed(struct tevent_req *subreq);
10405 static struct tevent_req *torture_createdel_send(TALLOC_CTX *mem_ctx,
10406 struct tevent_context *ev,
10407 struct cli_state *cli,
10410 struct tevent_req *req, *subreq;
10411 struct torture_createdel_state *state;
10413 req = tevent_req_create(mem_ctx, &state,
10414 struct torture_createdel_state);
10421 subreq = cli_ntcreate_send(
10422 state, ev, cli, name, 0,
10423 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
10424 FILE_ATTRIBUTE_NORMAL,
10425 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
10426 FILE_OPEN_IF, FILE_DELETE_ON_CLOSE,
10427 SMB2_IMPERSONATION_IMPERSONATION, 0);
10429 if (tevent_req_nomem(subreq, req)) {
10430 return tevent_req_post(req, ev);
10432 tevent_req_set_callback(subreq, torture_createdel_created, req);
10436 static void torture_createdel_created(struct tevent_req *subreq)
10438 struct tevent_req *req = tevent_req_callback_data(
10439 subreq, struct tevent_req);
10440 struct torture_createdel_state *state = tevent_req_data(
10441 req, struct torture_createdel_state);
10445 status = cli_ntcreate_recv(subreq, &fnum, NULL);
10446 TALLOC_FREE(subreq);
10447 if (tevent_req_nterror(req, status)) {
10448 DEBUG(10, ("cli_ntcreate_recv returned %s\n",
10449 nt_errstr(status)));
10453 subreq = cli_close_send(state, state->ev, state->cli, fnum);
10454 if (tevent_req_nomem(subreq, req)) {
10457 tevent_req_set_callback(subreq, torture_createdel_closed, req);
10460 static void torture_createdel_closed(struct tevent_req *subreq)
10462 struct tevent_req *req = tevent_req_callback_data(
10463 subreq, struct tevent_req);
10466 status = cli_close_recv(subreq);
10467 if (tevent_req_nterror(req, status)) {
10468 DEBUG(10, ("cli_close_recv returned %s\n", nt_errstr(status)));
10471 tevent_req_done(req);
10474 static NTSTATUS torture_createdel_recv(struct tevent_req *req)
10476 return tevent_req_simple_recv_ntstatus(req);
10479 struct torture_createdels_state {
10480 struct tevent_context *ev;
10481 struct cli_state *cli;
10482 const char *base_name;
10486 struct tevent_req **reqs;
10489 static void torture_createdels_done(struct tevent_req *subreq);
10491 static struct tevent_req *torture_createdels_send(TALLOC_CTX *mem_ctx,
10492 struct tevent_context *ev,
10493 struct cli_state *cli,
10494 const char *base_name,
10498 struct tevent_req *req;
10499 struct torture_createdels_state *state;
10502 req = tevent_req_create(mem_ctx, &state,
10503 struct torture_createdels_state);
10509 state->base_name = talloc_strdup(state, base_name);
10510 if (tevent_req_nomem(state->base_name, req)) {
10511 return tevent_req_post(req, ev);
10513 state->num_files = MAX(num_parallel, num_files);
10515 state->received = 0;
10517 state->reqs = talloc_array(state, struct tevent_req *, num_parallel);
10518 if (tevent_req_nomem(state->reqs, req)) {
10519 return tevent_req_post(req, ev);
10522 for (i=0; i<num_parallel; i++) {
10525 name = talloc_asprintf(state, "%s%8.8d", state->base_name,
10527 if (tevent_req_nomem(name, req)) {
10528 return tevent_req_post(req, ev);
10530 state->reqs[i] = torture_createdel_send(
10531 state->reqs, state->ev, state->cli, name);
10532 if (tevent_req_nomem(state->reqs[i], req)) {
10533 return tevent_req_post(req, ev);
10535 name = talloc_move(state->reqs[i], &name);
10536 tevent_req_set_callback(state->reqs[i],
10537 torture_createdels_done, req);
10543 static void torture_createdels_done(struct tevent_req *subreq)
10545 struct tevent_req *req = tevent_req_callback_data(
10546 subreq, struct tevent_req);
10547 struct torture_createdels_state *state = tevent_req_data(
10548 req, struct torture_createdels_state);
10549 size_t num_parallel = talloc_array_length(state->reqs);
10554 status = torture_createdel_recv(subreq);
10555 if (!NT_STATUS_IS_OK(status)){
10556 DEBUG(10, ("torture_createdel_recv returned %s\n",
10557 nt_errstr(status)));
10558 TALLOC_FREE(subreq);
10559 tevent_req_nterror(req, status);
10563 for (i=0; i<num_parallel; i++) {
10564 if (subreq == state->reqs[i]) {
10568 if (i == num_parallel) {
10569 DEBUG(10, ("received something we did not send\n"));
10570 tevent_req_nterror(req, NT_STATUS_INTERNAL_ERROR);
10573 TALLOC_FREE(state->reqs[i]);
10575 if (state->sent >= state->num_files) {
10576 tevent_req_done(req);
10580 name = talloc_asprintf(state, "%s%8.8d", state->base_name,
10582 if (tevent_req_nomem(name, req)) {
10585 state->reqs[i] = torture_createdel_send(state->reqs, state->ev,
10587 if (tevent_req_nomem(state->reqs[i], req)) {
10590 name = talloc_move(state->reqs[i], &name);
10591 tevent_req_set_callback(state->reqs[i], torture_createdels_done, req);
10595 static NTSTATUS torture_createdels_recv(struct tevent_req *req)
10597 return tevent_req_simple_recv_ntstatus(req);
10600 struct swallow_notify_state {
10601 struct tevent_context *ev;
10602 struct cli_state *cli;
10604 uint32_t completion_filter;
10606 bool (*fn)(uint32_t action, const char *name, void *priv);
10610 static void swallow_notify_done(struct tevent_req *subreq);
10612 static struct tevent_req *swallow_notify_send(TALLOC_CTX *mem_ctx,
10613 struct tevent_context *ev,
10614 struct cli_state *cli,
10616 uint32_t completion_filter,
10618 bool (*fn)(uint32_t action,
10623 struct tevent_req *req, *subreq;
10624 struct swallow_notify_state *state;
10626 req = tevent_req_create(mem_ctx, &state,
10627 struct swallow_notify_state);
10633 state->fnum = fnum;
10634 state->completion_filter = completion_filter;
10635 state->recursive = recursive;
10637 state->priv = priv;
10639 subreq = cli_notify_send(state, state->ev, state->cli, state->fnum,
10640 0xffff, state->completion_filter,
10642 if (tevent_req_nomem(subreq, req)) {
10643 return tevent_req_post(req, ev);
10645 tevent_req_set_callback(subreq, swallow_notify_done, req);
10649 static void swallow_notify_done(struct tevent_req *subreq)
10651 struct tevent_req *req = tevent_req_callback_data(
10652 subreq, struct tevent_req);
10653 struct swallow_notify_state *state = tevent_req_data(
10654 req, struct swallow_notify_state);
10656 uint32_t i, num_changes;
10657 struct notify_change *changes;
10659 status = cli_notify_recv(subreq, state, &num_changes, &changes);
10660 TALLOC_FREE(subreq);
10661 if (!NT_STATUS_IS_OK(status)) {
10662 DEBUG(10, ("cli_notify_recv returned %s\n",
10663 nt_errstr(status)));
10664 tevent_req_nterror(req, status);
10668 for (i=0; i<num_changes; i++) {
10669 state->fn(changes[i].action, changes[i].name, state->priv);
10671 TALLOC_FREE(changes);
10673 subreq = cli_notify_send(state, state->ev, state->cli, state->fnum,
10674 0xffff, state->completion_filter,
10676 if (tevent_req_nomem(subreq, req)) {
10679 tevent_req_set_callback(subreq, swallow_notify_done, req);
10682 static bool print_notifies(uint32_t action, const char *name, void *priv)
10684 if (DEBUGLEVEL > 5) {
10685 d_printf("%d %s\n", (int)action, name);
10690 static void notify_bench_done(struct tevent_req *req)
10692 int *num_finished = (int *)tevent_req_callback_data_void(req);
10693 *num_finished += 1;
10696 static bool run_notify_bench(int dummy)
10698 const char *dname = "\\notify-bench";
10699 struct tevent_context *ev;
10702 struct tevent_req *req1;
10703 struct tevent_req *req2 = NULL;
10704 int i, num_unc_names;
10705 int num_finished = 0;
10707 printf("starting notify-bench test\n");
10709 if (use_multishare_conn) {
10711 unc_list = file_lines_load(multishare_conn_fname,
10712 &num_unc_names, 0, NULL);
10713 if (!unc_list || num_unc_names <= 0) {
10714 d_printf("Failed to load unc names list from '%s'\n",
10715 multishare_conn_fname);
10718 TALLOC_FREE(unc_list);
10723 ev = samba_tevent_context_init(talloc_tos());
10725 d_printf("tevent_context_init failed\n");
10729 for (i=0; i<num_unc_names; i++) {
10730 struct cli_state *cli;
10733 base_fname = talloc_asprintf(talloc_tos(), "%s\\file%3.3d.",
10735 if (base_fname == NULL) {
10739 if (!torture_open_connection(&cli, i)) {
10743 status = cli_ntcreate(cli, dname, 0,
10744 MAXIMUM_ALLOWED_ACCESS,
10745 0, FILE_SHARE_READ|FILE_SHARE_WRITE|
10747 FILE_OPEN_IF, FILE_DIRECTORY_FILE, 0,
10750 if (!NT_STATUS_IS_OK(status)) {
10751 d_printf("Could not create %s: %s\n", dname,
10752 nt_errstr(status));
10756 req1 = swallow_notify_send(talloc_tos(), ev, cli, dnum,
10757 FILE_NOTIFY_CHANGE_FILE_NAME |
10758 FILE_NOTIFY_CHANGE_DIR_NAME |
10759 FILE_NOTIFY_CHANGE_ATTRIBUTES |
10760 FILE_NOTIFY_CHANGE_LAST_WRITE,
10761 false, print_notifies, NULL);
10762 if (req1 == NULL) {
10763 d_printf("Could not create notify request\n");
10767 req2 = torture_createdels_send(talloc_tos(), ev, cli,
10768 base_fname, 10, torture_numops);
10769 if (req2 == NULL) {
10770 d_printf("Could not create createdels request\n");
10773 TALLOC_FREE(base_fname);
10775 tevent_req_set_callback(req2, notify_bench_done,
10779 while (num_finished < num_unc_names) {
10781 ret = tevent_loop_once(ev);
10783 d_printf("tevent_loop_once failed\n");
10788 if (!tevent_req_poll(req2, ev)) {
10789 d_printf("tevent_req_poll failed\n");
10792 status = torture_createdels_recv(req2);
10793 d_printf("torture_createdels_recv returned %s\n", nt_errstr(status));
10798 static bool run_mangle1(int dummy)
10800 struct cli_state *cli;
10801 const char *fname = "this_is_a_long_fname_to_be_mangled.txt";
10805 time_t change_time, access_time, write_time;
10809 printf("starting mangle1 test\n");
10810 if (!torture_open_connection(&cli, 0)) {
10814 smbXcli_conn_set_sockopt(cli->conn, sockops);
10816 status = cli_ntcreate(cli, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
10817 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
10818 0, 0, &fnum, NULL);
10819 if (!NT_STATUS_IS_OK(status)) {
10820 d_printf("open %s failed: %s\n", fname, nt_errstr(status));
10823 cli_close(cli, fnum);
10825 status = cli_qpathinfo_alt_name(cli, fname, alt_name);
10826 if (!NT_STATUS_IS_OK(status)) {
10827 d_printf("cli_qpathinfo_alt_name failed: %s\n",
10828 nt_errstr(status));
10831 d_printf("alt_name: %s\n", alt_name);
10833 status = cli_openx(cli, alt_name, O_RDONLY, DENY_NONE, &fnum);
10834 if (!NT_STATUS_IS_OK(status)) {
10835 d_printf("cli_openx(%s) failed: %s\n", alt_name,
10836 nt_errstr(status));
10839 cli_close(cli, fnum);
10841 status = cli_qpathinfo1(cli, alt_name, &change_time, &access_time,
10842 &write_time, &size, &mode);
10843 if (!NT_STATUS_IS_OK(status)) {
10844 d_printf("cli_qpathinfo1(%s) failed: %s\n", alt_name,
10845 nt_errstr(status));
10852 static NTSTATUS mangle_illegal_list_shortname_fn(const char *mntpoint,
10853 struct file_info *f,
10857 if (f->short_name == NULL) {
10858 return NT_STATUS_OK;
10861 if (strlen(f->short_name) == 0) {
10862 return NT_STATUS_OK;
10865 printf("unexpected shortname: %s\n", f->short_name);
10867 return NT_STATUS_OBJECT_NAME_INVALID;
10870 static NTSTATUS mangle_illegal_list_name_fn(const char *mntpoint,
10871 struct file_info *f,
10875 char *name = state;
10877 printf("name: %s\n", f->name);
10878 fstrcpy(name, f->name);
10879 return NT_STATUS_OK;
10882 static bool run_mangle_illegal(int dummy)
10884 struct cli_state *cli = NULL;
10885 struct cli_state *cli_posix = NULL;
10886 const char *fname = "\\MANGLE_ILLEGAL\\this_is_a_long_fname_to_be_mangled.txt";
10887 const char *illegal_fname = "MANGLE_ILLEGAL/foo:bar";
10888 char *mangled_path = NULL;
10894 printf("starting mangle-illegal test\n");
10896 if (!torture_open_connection(&cli, 0)) {
10900 smbXcli_conn_set_sockopt(cli->conn, sockops);
10902 if (!torture_open_connection(&cli_posix, 0)) {
10906 smbXcli_conn_set_sockopt(cli_posix->conn, sockops);
10908 status = torture_setup_unix_extensions(cli_posix);
10909 if (!NT_STATUS_IS_OK(status)) {
10913 cli_rmdir(cli, "\\MANGLE_ILLEGAL");
10914 status = cli_mkdir(cli, "\\MANGLE_ILLEGAL");
10915 if (!NT_STATUS_IS_OK(status)) {
10916 printf("mkdir1 failed : %s\n", nt_errstr(status));
10921 * Create a file with illegal NTFS characters and test that we
10922 * get a usable mangled name
10925 cli_setatr(cli_posix, illegal_fname, 0, 0);
10926 cli_posix_unlink(cli_posix, illegal_fname);
10928 status = cli_posix_open(cli_posix, illegal_fname, O_RDWR|O_CREAT|O_EXCL,
10930 if (!NT_STATUS_IS_OK(status)) {
10931 printf("POSIX create of %s failed (%s)\n",
10932 illegal_fname, nt_errstr(status));
10936 status = cli_close(cli_posix, fnum);
10937 if (!NT_STATUS_IS_OK(status)) {
10938 printf("close failed (%s)\n", nt_errstr(status));
10942 status = cli_list(cli, "\\MANGLE_ILLEGAL\\*", 0, mangle_illegal_list_name_fn, &name);
10943 if (!NT_STATUS_IS_OK(status)) {
10944 d_printf("cli_list failed: %s\n", nt_errstr(status));
10948 mangled_path = talloc_asprintf(talloc_tos(), "\\MANGLE_ILLEGAL\\%s", name);
10949 if (mangled_path == NULL) {
10953 status = cli_openx(cli, mangled_path, O_RDONLY, DENY_NONE, &fnum);
10954 if (!NT_STATUS_IS_OK(status)) {
10955 d_printf("cli_openx(%s) failed: %s\n", mangled_path, nt_errstr(status));
10956 TALLOC_FREE(mangled_path);
10959 TALLOC_FREE(mangled_path);
10960 cli_close(cli, fnum);
10962 cli_setatr(cli_posix, illegal_fname, 0, 0);
10963 cli_posix_unlink(cli_posix, illegal_fname);
10966 * Create a file with a long name and check that we got *no* short name.
10969 status = cli_ntcreate(cli, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
10970 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
10971 0, 0, &fnum, NULL);
10972 if (!NT_STATUS_IS_OK(status)) {
10973 d_printf("open %s failed: %s\n", fname, nt_errstr(status));
10976 cli_close(cli, fnum);
10978 status = cli_list(cli, fname, 0, mangle_illegal_list_shortname_fn, &alt_name);
10979 if (!NT_STATUS_IS_OK(status)) {
10980 d_printf("cli_list failed\n");
10984 cli_unlink(cli, fname, 0);
10985 cli_rmdir(cli, "\\MANGLE_ILLEGAL");
10987 if (!torture_close_connection(cli_posix)) {
10991 if (!torture_close_connection(cli)) {
10998 static size_t null_source(uint8_t *buf, size_t n, void *priv)
11000 size_t *to_pull = (size_t *)priv;
11001 size_t thistime = *to_pull;
11003 thistime = MIN(thistime, n);
11004 if (thistime == 0) {
11008 memset(buf, 0, thistime);
11009 *to_pull -= thistime;
11013 static bool run_windows_write(int dummy)
11015 struct cli_state *cli1;
11019 const char *fname = "\\writetest.txt";
11020 struct timeval start_time;
11025 printf("starting windows_write test\n");
11026 if (!torture_open_connection(&cli1, 0)) {
11030 status = cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
11031 if (!NT_STATUS_IS_OK(status)) {
11032 printf("open failed (%s)\n", nt_errstr(status));
11036 smbXcli_conn_set_sockopt(cli1->conn, sockops);
11038 start_time = timeval_current();
11040 for (i=0; i<torture_numops; i++) {
11042 off_t start = i * torture_blocksize;
11043 size_t to_pull = torture_blocksize - 1;
11045 status = cli_writeall(cli1, fnum, 0, &c,
11046 start + torture_blocksize - 1, 1, NULL);
11047 if (!NT_STATUS_IS_OK(status)) {
11048 printf("cli_write failed: %s\n", nt_errstr(status));
11052 status = cli_push(cli1, fnum, 0, i * torture_blocksize, torture_blocksize,
11053 null_source, &to_pull);
11054 if (!NT_STATUS_IS_OK(status)) {
11055 printf("cli_push returned: %s\n", nt_errstr(status));
11060 seconds = timeval_elapsed(&start_time);
11061 kbytes = (double)torture_blocksize * torture_numops;
11064 printf("Wrote %d kbytes in %.2f seconds: %d kb/sec\n", (int)kbytes,
11065 (double)seconds, (int)(kbytes/seconds));
11069 cli_close(cli1, fnum);
11070 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
11071 torture_close_connection(cli1);
11075 static size_t calc_expected_return(struct cli_state *cli, size_t len_requested)
11077 size_t max_pdu = 0x1FFFF;
11079 if (cli->server_posix_capabilities & CIFS_UNIX_LARGE_READ_CAP) {
11080 max_pdu = 0xFFFFFF;
11083 if (smb1cli_conn_signing_is_active(cli->conn)) {
11087 if (smb1cli_conn_encryption_on(cli->conn)) {
11088 max_pdu = CLI_BUFFER_SIZE;
11091 if ((len_requested & 0xFFFF0000) == 0xFFFF0000) {
11092 len_requested &= 0xFFFF;
11095 return MIN(len_requested,
11096 max_pdu - (MIN_SMB_SIZE + VWV(12) + 1 /* padding byte */));
11099 static bool check_read_call(struct cli_state *cli,
11102 size_t len_requested)
11105 struct tevent_req *subreq = NULL;
11106 ssize_t len_read = 0;
11107 size_t len_expected = 0;
11108 struct tevent_context *ev = NULL;
11110 ev = samba_tevent_context_init(talloc_tos());
11115 subreq = cli_read_andx_send(talloc_tos(),
11122 if (!tevent_req_poll_ntstatus(subreq, ev, &status)) {
11126 status = cli_read_andx_recv(subreq, &len_read, &buf);
11127 if (!NT_STATUS_IS_OK(status)) {
11128 d_printf("cli_read_andx_recv failed: %s\n", nt_errstr(status));
11132 TALLOC_FREE(subreq);
11135 len_expected = calc_expected_return(cli, len_requested);
11137 if (len_expected > 0x10000 && len_read == 0x10000) {
11138 /* Windows servers only return a max of 0x10000,
11139 doesn't matter if you set CAP_LARGE_READX in
11140 the client sessionsetupX call or not. */
11141 d_printf("Windows server - returned 0x10000 on a read of 0x%x\n",
11142 (unsigned int)len_requested);
11143 } else if (len_read != len_expected) {
11144 d_printf("read of 0x%x failed: got 0x%x, expected 0x%x\n",
11145 (unsigned int)len_requested,
11146 (unsigned int)len_read,
11147 (unsigned int)len_expected);
11150 d_printf("Correct read reply.\n");
11156 /* Test large readX variants. */
11157 static bool large_readx_tests(struct cli_state *cli,
11161 /* A read of 0xFFFF0001 should *always* return 1 byte. */
11162 if (check_read_call(cli, fnum, buf, 0xFFFF0001) == false) {
11165 /* A read of 0x10000 should return 0x10000 bytes. */
11166 if (check_read_call(cli, fnum, buf, 0x10000) == false) {
11169 /* A read of 0x10000 should return 0x10001 bytes. */
11170 if (check_read_call(cli, fnum, buf, 0x10001) == false) {
11173 /* A read of 0x1FFFF - (MIN_SMB_SIZE + VWV(12) should return
11174 the requested number of bytes. */
11175 if (check_read_call(cli, fnum, buf, 0x1FFFF - (MIN_SMB_SIZE + VWV(12))) == false) {
11178 /* A read of 1MB should return 1MB bytes (on Samba). */
11179 if (check_read_call(cli, fnum, buf, 0x100000) == false) {
11183 if (check_read_call(cli, fnum, buf, 0x20001) == false) {
11186 if (check_read_call(cli, fnum, buf, 0x22000001) == false) {
11189 if (check_read_call(cli, fnum, buf, 0xFFFE0001) == false) {
11195 static bool run_large_readx(int dummy)
11197 uint8_t *buf = NULL;
11198 struct cli_state *cli1 = NULL;
11199 struct cli_state *cli2 = NULL;
11200 bool correct = false;
11201 const char *fname = "\\large_readx.dat";
11203 uint16_t fnum1 = UINT16_MAX;
11204 uint32_t normal_caps = 0;
11205 size_t file_size = 20*1024*1024;
11206 TALLOC_CTX *frame = talloc_stackframe();
11210 enum smb_signing_setting signing_setting;
11211 enum protocol_types protocol;
11215 .signing_setting = SMB_SIGNING_IF_REQUIRED,
11216 .protocol = PROTOCOL_NT1,
11218 .name = "NT1 - SIGNING_REQUIRED",
11219 .signing_setting = SMB_SIGNING_REQUIRED,
11220 .protocol = PROTOCOL_NT1,
11224 printf("starting large_readx test\n");
11226 if (!torture_open_connection(&cli1, 0)) {
11230 normal_caps = smb1cli_conn_capabilities(cli1->conn);
11232 if (!(normal_caps & CAP_LARGE_READX)) {
11233 d_printf("Server doesn't have CAP_LARGE_READX 0x%x\n",
11234 (unsigned int)normal_caps);
11238 /* Create a file of size 4MB. */
11239 status = cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS,
11240 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
11241 0, 0, &fnum1, NULL);
11243 if (!NT_STATUS_IS_OK(status)) {
11244 d_printf("open %s failed: %s\n", fname, nt_errstr(status));
11248 /* Write file_size bytes. */
11249 buf = talloc_zero_array(frame, uint8_t, file_size);
11254 status = cli_writeall(cli1,
11261 if (!NT_STATUS_IS_OK(status)) {
11262 d_printf("cli_writeall failed: %s\n", nt_errstr(status));
11266 status = cli_close(cli1, fnum1);
11267 if (!NT_STATUS_IS_OK(status)) {
11268 d_printf("cli_close failed: %s\n", nt_errstr(status));
11272 fnum1 = UINT16_MAX;
11274 for (i=0; i < ARRAY_SIZE(runs); i++) {
11275 enum smb_signing_setting saved_signing_setting = signing_state;
11276 uint16_t fnum2 = -1;
11279 (runs[i].signing_setting == SMB_SIGNING_REQUIRED))
11281 d_printf("skip[%u] - %s\n", (unsigned)i, runs[i].name);
11285 d_printf("run[%u] - %s\n", (unsigned)i, runs[i].name);
11287 signing_state = runs[i].signing_setting;
11288 cli2 = open_nbt_connection();
11289 signing_state = saved_signing_setting;
11290 if (cli2 == NULL) {
11294 status = smbXcli_negprot(cli2->conn,
11298 if (!NT_STATUS_IS_OK(status)) {
11302 status = cli_session_setup_creds(cli2, torture_creds);
11303 if (!NT_STATUS_IS_OK(status)) {
11307 status = cli_tree_connect(cli2,
11311 if (!NT_STATUS_IS_OK(status)) {
11315 cli_set_timeout(cli2, 120000); /* set a really long timeout (2 minutes) */
11317 normal_caps = smb1cli_conn_capabilities(cli2->conn);
11319 if (!(normal_caps & CAP_LARGE_READX)) {
11320 d_printf("Server doesn't have CAP_LARGE_READX 0x%x\n",
11321 (unsigned int)normal_caps);
11326 if (force_cli_encryption(cli2, share) == false) {
11329 } else if (SERVER_HAS_UNIX_CIFS(cli2)) {
11330 uint16_t major, minor;
11331 uint32_t caplow, caphigh;
11333 status = cli_unix_extensions_version(cli2,
11335 &caplow, &caphigh);
11336 if (!NT_STATUS_IS_OK(status)) {
11341 status = cli_ntcreate(cli2, fname, 0, FILE_READ_DATA,
11342 FILE_ATTRIBUTE_NORMAL, 0, FILE_OPEN,
11343 0, 0, &fnum2, NULL);
11344 if (!NT_STATUS_IS_OK(status)) {
11345 d_printf("Second open %s failed: %s\n", fname, nt_errstr(status));
11349 /* All reads must return less than file_size bytes. */
11350 if (!large_readx_tests(cli2, fnum2, buf)) {
11354 status = cli_close(cli2, fnum2);
11355 if (!NT_STATUS_IS_OK(status)) {
11356 d_printf("cli_close failed: %s\n", nt_errstr(status));
11361 if (!torture_close_connection(cli2)) {
11368 printf("Success on large_readx test\n");
11373 if (!torture_close_connection(cli2)) {
11379 if (fnum1 != UINT16_MAX) {
11380 status = cli_close(cli1, fnum1);
11381 if (!NT_STATUS_IS_OK(status)) {
11382 d_printf("cli_close failed: %s\n", nt_errstr(status));
11384 fnum1 = UINT16_MAX;
11387 status = cli_unlink(cli1, fname,
11388 FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
11389 if (!NT_STATUS_IS_OK(status)) {
11390 printf("unlink failed (%s)\n", nt_errstr(status));
11393 if (!torture_close_connection(cli1)) {
11398 TALLOC_FREE(frame);
11400 printf("finished large_readx test\n");
11404 static bool run_cli_echo(int dummy)
11406 struct cli_state *cli;
11409 printf("starting cli_echo test\n");
11410 if (!torture_open_connection(&cli, 0)) {
11413 smbXcli_conn_set_sockopt(cli->conn, sockops);
11415 status = cli_echo(cli, 5, data_blob_const("hello", 5));
11417 d_printf("cli_echo returned %s\n", nt_errstr(status));
11419 torture_close_connection(cli);
11420 return NT_STATUS_IS_OK(status);
11423 static int splice_status(off_t written, void *priv)
11428 static bool run_cli_splice(int dummy)
11430 uint8_t *buf = NULL;
11431 struct cli_state *cli1 = NULL;
11432 bool correct = false;
11433 const char *fname_src = "\\splice_src.dat";
11434 const char *fname_dst = "\\splice_dst.dat";
11436 uint16_t fnum1 = UINT16_MAX;
11437 uint16_t fnum2 = UINT16_MAX;
11438 size_t file_size = 2*1024*1024;
11439 size_t splice_size = 1*1024*1024 + 713;
11440 uint8_t digest1[16], digest2[16];
11443 TALLOC_CTX *frame = talloc_stackframe();
11445 printf("starting cli_splice test\n");
11447 if (!torture_open_connection(&cli1, 0)) {
11451 cli_unlink(cli1, fname_src,
11452 FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
11453 cli_unlink(cli1, fname_dst,
11454 FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
11456 /* Create a file */
11457 status = cli_ntcreate(cli1, fname_src, 0, GENERIC_ALL_ACCESS,
11458 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
11459 0, 0, &fnum1, NULL);
11461 if (!NT_STATUS_IS_OK(status)) {
11462 d_printf("open %s failed: %s\n", fname_src, nt_errstr(status));
11466 /* Write file_size bytes - must be bigger than splice_size. */
11467 buf = talloc_zero_array(frame, uint8_t, file_size);
11469 d_printf("talloc_fail\n");
11473 /* Fill it with random numbers. */
11474 generate_random_buffer(buf, file_size);
11476 /* MD5 the first 1MB + 713 bytes. */
11477 gnutls_hash_fast(GNUTLS_DIG_MD5,
11482 status = cli_writeall(cli1,
11489 if (!NT_STATUS_IS_OK(status)) {
11490 d_printf("cli_writeall failed: %s\n", nt_errstr(status));
11494 status = cli_ntcreate(cli1, fname_dst, 0, GENERIC_ALL_ACCESS,
11495 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
11496 0, 0, &fnum2, NULL);
11498 if (!NT_STATUS_IS_OK(status)) {
11499 d_printf("open %s failed: %s\n", fname_dst, nt_errstr(status));
11503 /* Now splice 1MB + 713 bytes. */
11504 status = cli_splice(cli1,
11515 if (!NT_STATUS_IS_OK(status)) {
11516 d_printf("cli_splice failed: %s\n", nt_errstr(status));
11520 /* Clear the old buffer. */
11521 memset(buf, '\0', file_size);
11523 /* Read the new file. */
11524 status = cli_read(cli1, fnum2, (char *)buf, 0, splice_size, &nread);
11525 if (!NT_STATUS_IS_OK(status)) {
11526 d_printf("cli_read failed: %s\n", nt_errstr(status));
11529 if (nread != splice_size) {
11530 d_printf("bad read of 0x%x, should be 0x%x\n",
11531 (unsigned int)nread,
11532 (unsigned int)splice_size);
11536 /* MD5 the first 1MB + 713 bytes. */
11537 gnutls_hash_fast(GNUTLS_DIG_MD5,
11542 /* Must be the same. */
11543 if (memcmp(digest1, digest2, 16) != 0) {
11544 d_printf("bad MD5 compare\n");
11549 printf("Success on cli_splice test\n");
11554 if (fnum1 != UINT16_MAX) {
11555 cli_close(cli1, fnum1);
11557 if (fnum2 != UINT16_MAX) {
11558 cli_close(cli1, fnum2);
11561 cli_unlink(cli1, fname_src,
11562 FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
11563 cli_unlink(cli1, fname_dst,
11564 FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
11566 if (!torture_close_connection(cli1)) {
11571 TALLOC_FREE(frame);
11575 static bool run_uid_regression_test(int dummy)
11577 static struct cli_state *cli;
11580 bool correct = True;
11581 struct smbXcli_tcon *orig_tcon = NULL;
11584 printf("starting uid regression test\n");
11586 if (!torture_open_connection(&cli, 0)) {
11590 smbXcli_conn_set_sockopt(cli->conn, sockops);
11592 /* Ok - now save then logoff our current user. */
11593 old_vuid = cli_state_get_uid(cli);
11595 status = cli_ulogoff(cli);
11596 if (!NT_STATUS_IS_OK(status)) {
11597 d_printf("(%s) cli_ulogoff failed: %s\n",
11598 __location__, nt_errstr(status));
11603 cli_state_set_uid(cli, old_vuid);
11605 /* Try an operation. */
11606 status = cli_mkdir(cli, "\\uid_reg_test");
11607 if (NT_STATUS_IS_OK(status)) {
11608 d_printf("(%s) cli_mkdir succeeded\n",
11613 /* Should be bad uid. */
11614 if (!check_error(__LINE__, status, ERRSRV, ERRbaduid,
11615 NT_STATUS_USER_SESSION_DELETED)) {
11621 old_cnum = cli_state_get_tid(cli);
11622 orig_tcon = cli_state_save_tcon(cli);
11623 if (orig_tcon == NULL) {
11628 /* Now try a SMBtdis with the invalid vuid set to zero. */
11629 cli_state_set_uid(cli, 0);
11631 /* This should succeed. */
11632 status = cli_tdis(cli);
11634 if (NT_STATUS_IS_OK(status)) {
11635 d_printf("First tdis with invalid vuid should succeed.\n");
11637 d_printf("First tdis failed (%s)\n", nt_errstr(status));
11639 cli_state_restore_tcon(cli, orig_tcon);
11643 cli_state_restore_tcon(cli, orig_tcon);
11644 cli_state_set_uid(cli, old_vuid);
11645 cli_state_set_tid(cli, old_cnum);
11647 /* This should fail. */
11648 status = cli_tdis(cli);
11649 if (NT_STATUS_IS_OK(status)) {
11650 d_printf("Second tdis with invalid vuid should fail - succeeded instead !.\n");
11654 /* Should be bad tid. */
11655 if (!check_error(__LINE__, status, ERRSRV, ERRinvnid,
11656 NT_STATUS_NETWORK_NAME_DELETED)) {
11662 cli_rmdir(cli, "\\uid_reg_test");
11671 static const char *illegal_chars = "*\\/?<>|\":";
11672 static char force_shortname_chars[] = " +,.[];=\177";
11674 static NTSTATUS shortname_del_fn(const char *mnt, struct file_info *finfo,
11675 const char *mask, void *state)
11677 struct cli_state *pcli = (struct cli_state *)state;
11679 NTSTATUS status = NT_STATUS_OK;
11681 slprintf(fname, sizeof(fname), "\\shortname\\%s", finfo->name);
11683 if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
11684 return NT_STATUS_OK;
11686 if (finfo->mode & FILE_ATTRIBUTE_DIRECTORY) {
11687 status = cli_rmdir(pcli, fname);
11688 if (!NT_STATUS_IS_OK(status)) {
11689 printf("del_fn: failed to rmdir %s\n,", fname );
11692 status = cli_unlink(pcli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
11693 if (!NT_STATUS_IS_OK(status)) {
11694 printf("del_fn: failed to unlink %s\n,", fname );
11706 static NTSTATUS shortname_list_fn(const char *mnt, struct file_info *finfo,
11707 const char *name, void *state)
11709 struct sn_state *s = (struct sn_state *)state;
11713 printf("shortname list: i = %d, name = |%s|, shortname = |%s|\n",
11714 i, finfo->name, finfo->short_name);
11717 if (strchr(force_shortname_chars, i)) {
11718 if (!finfo->short_name) {
11719 /* Shortname not created when it should be. */
11720 d_printf("(%s) ERROR: Shortname was not created for file %s containing %d\n",
11721 __location__, finfo->name, i);
11724 } else if (finfo->short_name){
11725 /* Shortname created when it should not be. */
11726 d_printf("(%s) ERROR: Shortname %s was created for file %s\n",
11727 __location__, finfo->short_name, finfo->name);
11731 return NT_STATUS_OK;
11734 static bool run_shortname_test(int dummy)
11736 static struct cli_state *cli;
11737 bool correct = True;
11743 printf("starting shortname test\n");
11745 if (!torture_open_connection(&cli, 0)) {
11749 smbXcli_conn_set_sockopt(cli->conn, sockops);
11751 cli_list(cli, "\\shortname\\*", 0, shortname_del_fn, cli);
11752 cli_list(cli, "\\shortname\\*", FILE_ATTRIBUTE_DIRECTORY, shortname_del_fn, cli);
11753 cli_rmdir(cli, "\\shortname");
11755 status = cli_mkdir(cli, "\\shortname");
11756 if (!NT_STATUS_IS_OK(status)) {
11757 d_printf("(%s) cli_mkdir of \\shortname failed: %s\n",
11758 __location__, nt_errstr(status));
11763 if (strlcpy(fname, "\\shortname\\", sizeof(fname)) >= sizeof(fname)) {
11767 if (strlcat(fname, "test .txt", sizeof(fname)) >= sizeof(fname)) {
11774 for (i = 32; i < 128; i++) {
11775 uint16_t fnum = (uint16_t)-1;
11779 if (strchr(illegal_chars, i)) {
11784 status = cli_ntcreate(cli, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
11785 FILE_SHARE_READ|FILE_SHARE_WRITE,
11786 FILE_OVERWRITE_IF, 0, 0, &fnum, NULL);
11787 if (!NT_STATUS_IS_OK(status)) {
11788 d_printf("(%s) cli_nt_create of %s failed: %s\n",
11789 __location__, fname, nt_errstr(status));
11793 cli_close(cli, fnum);
11796 status = cli_list(cli, "\\shortname\\test*.*", 0,
11797 shortname_list_fn, &s);
11798 if (s.matched != 1) {
11799 d_printf("(%s) failed to list %s: %s\n",
11800 __location__, fname, nt_errstr(status));
11805 status = cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
11806 if (!NT_STATUS_IS_OK(status)) {
11807 d_printf("(%s) failed to delete %s: %s\n",
11808 __location__, fname, nt_errstr(status));
11821 cli_list(cli, "\\shortname\\*", 0, shortname_del_fn, cli);
11822 cli_list(cli, "\\shortname\\*", FILE_ATTRIBUTE_DIRECTORY, shortname_del_fn, cli);
11823 cli_rmdir(cli, "\\shortname");
11824 torture_close_connection(cli);
11828 TLDAPRC callback_code;
11830 static void pagedsearch_cb(struct tevent_req *req)
11833 struct tldap_message *msg;
11836 rc = tldap_search_paged_recv(req, talloc_tos(), &msg);
11837 if (!TLDAP_RC_IS_SUCCESS(rc)) {
11838 d_printf("tldap_search_paged_recv failed: %s\n",
11839 tldap_rc2string(rc));
11840 callback_code = rc;
11843 if (tldap_msg_type(msg) != TLDAP_RES_SEARCH_ENTRY) {
11847 if (!tldap_entry_dn(msg, &dn)) {
11848 d_printf("tldap_entry_dn failed\n");
11851 d_printf("%s\n", dn);
11855 enum tldap_extended_val {
11862 * Construct an extended dn control with either no value, 0 or 1
11864 * No value and 0 are equivalent (non-hyphenated GUID)
11865 * 1 has the hyphenated GUID
11867 static struct tldap_control *
11868 tldap_build_extended_control(enum tldap_extended_val val)
11870 struct tldap_control empty_control;
11871 struct asn1_data *data;
11873 ZERO_STRUCT(empty_control);
11875 if (val != EXTENDED_NONE) {
11876 data = asn1_init(talloc_tos());
11882 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
11886 if (!asn1_write_Integer(data, (int)val)) {
11890 if (!asn1_pop_tag(data)) {
11894 if (!asn1_blob(data, &empty_control.value)) {
11899 empty_control.oid = "1.2.840.113556.1.4.529";
11900 empty_control.critical = true;
11902 return tldap_add_control(talloc_tos(), NULL, 0, &empty_control);
11906 static bool tldap_test_dn_guid_format(struct tldap_context *ld, const char *basedn,
11907 enum tldap_extended_val control_val)
11909 struct tldap_control *control = tldap_build_extended_control(control_val);
11911 struct tldap_message **msg;
11914 rc = tldap_search(ld, basedn, TLDAP_SCOPE_BASE,
11915 "(objectClass=*)", NULL, 0, 0,
11917 0, 0, 0, 0, talloc_tos(), &msg);
11918 if (!TLDAP_RC_IS_SUCCESS(rc)) {
11919 d_printf("tldap_search for domain DN failed: %s\n",
11920 tldap_errstr(talloc_tos(), ld, rc));
11924 if (!tldap_entry_dn(msg[0], &dn)) {
11925 d_printf("tldap_search domain DN fetch failed: %s\n",
11926 tldap_errstr(talloc_tos(), ld, rc));
11930 d_printf("%s\n", dn);
11933 uint32_t time_mid, time_hi_and_version;
11934 uint32_t clock_seq[2];
11938 switch (control_val) {
11939 case EXTENDED_NONE:
11940 case EXTENDED_ZERO:
11942 * When reading GUIDs with hyphens, scanf will treat
11943 * hyphen as a hex character (and counts as part of the
11944 * width). This creates leftover GUID string which we
11945 * check will for with 'next' and closing '>'.
11947 if (12 == sscanf(dn, "<GUID=%08x%04x%04x%02x%02x%02x%02x%02x%02x%02x%02x>%c",
11948 &time_low, &time_mid,
11949 &time_hi_and_version, &clock_seq[0],
11950 &clock_seq[1], &node[0], &node[1],
11951 &node[2], &node[3], &node[4],
11952 &node[5], &next)) {
11953 /* This GUID is good */
11955 d_printf("GUID format in control (no hyphens) doesn't match output\n");
11961 if (12 == sscanf(dn,
11962 "<GUID=%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x>%c",
11963 &time_low, &time_mid,
11964 &time_hi_and_version, &clock_seq[0],
11965 &clock_seq[1], &node[0], &node[1],
11966 &node[2], &node[3], &node[4],
11967 &node[5], &next)) {
11968 /* This GUID is good */
11970 d_printf("GUID format in control (with hyphens) doesn't match output\n");
11983 static bool run_tldap(int dummy)
11985 struct tldap_context *ld;
11989 struct sockaddr_storage addr;
11990 struct tevent_context *ev;
11991 struct tevent_req *req;
11993 const char *filter;
11995 if (!resolve_name(host, &addr, 0, false)) {
11996 d_printf("could not find host %s\n", host);
11999 status = open_socket_out(&addr, 389, 9999, &fd);
12000 if (!NT_STATUS_IS_OK(status)) {
12001 d_printf("open_socket_out failed: %s\n", nt_errstr(status));
12005 ld = tldap_context_create(talloc_tos(), fd);
12008 d_printf("tldap_context_create failed\n");
12012 rc = tldap_fetch_rootdse(ld);
12013 if (!TLDAP_RC_IS_SUCCESS(rc)) {
12014 d_printf("tldap_fetch_rootdse failed: %s\n",
12015 tldap_errstr(talloc_tos(), ld, rc));
12019 basedn = tldap_talloc_single_attribute(
12020 tldap_rootdse(ld), "defaultNamingContext", talloc_tos());
12021 if (basedn == NULL) {
12022 d_printf("no defaultNamingContext\n");
12025 d_printf("defaultNamingContext: %s\n", basedn);
12027 ev = samba_tevent_context_init(talloc_tos());
12029 d_printf("tevent_context_init failed\n");
12033 rc = tldap_gensec_bind(ld, torture_creds, "ldap", host, NULL,
12034 loadparm_init_s3(talloc_tos(),
12035 loadparm_s3_helpers()),
12036 GENSEC_FEATURE_SIGN | GENSEC_FEATURE_SEAL);
12038 if (!TLDAP_RC_IS_SUCCESS(rc)) {
12039 d_printf("tldap_gensec_bind failed\n");
12043 callback_code = TLDAP_SUCCESS;
12045 req = tldap_search_paged_send(talloc_tos(), ev, ld, basedn,
12046 TLDAP_SCOPE_SUB, "(objectclass=*)",
12048 NULL, 0, NULL, 0, 0, 0, 0, 5);
12050 d_printf("tldap_search_paged_send failed\n");
12053 tevent_req_set_callback(req, pagedsearch_cb, NULL);
12055 tevent_req_poll(req, ev);
12059 rc = callback_code;
12061 if (!TLDAP_RC_IS_SUCCESS(rc)) {
12062 d_printf("tldap_search with paging failed: %s\n",
12063 tldap_errstr(talloc_tos(), ld, rc));
12067 /* test search filters against rootDSE */
12068 filter = "(&(|(name=samba)(nextRid<=10000000)(usnChanged>=10)(samba~=ambas)(!(name=s*m*a)))"
12069 "(|(name:=samba)(name:dn:2.5.13.5:=samba)(:dn:2.5.13.5:=samba)(!(name=*samba))))";
12071 rc = tldap_search(ld, "", TLDAP_SCOPE_BASE, filter,
12072 NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0,
12073 talloc_tos(), NULL);
12074 if (!TLDAP_RC_IS_SUCCESS(rc)) {
12075 d_printf("tldap_search with complex filter failed: %s\n",
12076 tldap_errstr(talloc_tos(), ld, rc));
12081 * Tests to check for regression of:
12083 * https://bugzilla.samba.org/show_bug.cgi?id=14029
12085 * TLDAP used here to pick apart the original string DN (with GUID)
12087 if (!tldap_test_dn_guid_format(ld, basedn, EXTENDED_NONE)) {
12088 d_printf("tldap_search with extended dn (no val) failed: %s\n",
12089 tldap_errstr(talloc_tos(), ld, rc));
12092 if (!tldap_test_dn_guid_format(ld, basedn, EXTENDED_ZERO)) {
12093 d_printf("tldap_search with extended dn (0) failed: %s\n",
12094 tldap_errstr(talloc_tos(), ld, rc));
12097 if (!tldap_test_dn_guid_format(ld, basedn, EXTENDED_ONE)) {
12098 d_printf("tldap_search with extended dn (1) failed: %s\n",
12099 tldap_errstr(talloc_tos(), ld, rc));
12107 /* Torture test to ensure no regression of :
12108 https://bugzilla.samba.org/show_bug.cgi?id=7084
12111 static bool run_dir_createtime(int dummy)
12113 struct cli_state *cli;
12114 const char *dname = "\\testdir_createtime";
12115 const char *fname = "\\testdir_createtime\\testfile";
12117 struct timespec create_time;
12118 struct timespec create_time1;
12123 if (!torture_open_connection(&cli, 0)) {
12127 if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
12128 /* Ensure ino is zero, SMB2 gets a real one. */
12131 /* Ensure ino is -1, SMB1 never gets a real one. */
12132 ino = (uint64_t)-1;
12135 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
12136 cli_rmdir(cli, dname);
12138 status = cli_mkdir(cli, dname);
12139 if (!NT_STATUS_IS_OK(status)) {
12140 printf("mkdir failed: %s\n", nt_errstr(status));
12144 status = cli_qpathinfo2(cli, dname, &create_time, NULL, NULL, NULL,
12146 if (!NT_STATUS_IS_OK(status)) {
12147 printf("cli_qpathinfo2 returned %s\n",
12148 nt_errstr(status));
12152 if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
12153 /* SMB2 should always return an inode. */
12155 printf("SMB2 bad inode (0)\n");
12159 /* SMB1 must always return zero here. */
12161 printf("SMB1 bad inode (!0)\n");
12166 /* Sleep 3 seconds, then create a file. */
12169 status = cli_openx(cli, fname, O_RDWR | O_CREAT | O_EXCL,
12171 if (!NT_STATUS_IS_OK(status)) {
12172 printf("cli_openx failed: %s\n", nt_errstr(status));
12176 status = cli_qpathinfo2(cli, dname, &create_time1, NULL, NULL, NULL,
12178 if (!NT_STATUS_IS_OK(status)) {
12179 printf("cli_qpathinfo2 (2) returned %s\n",
12180 nt_errstr(status));
12184 if (timespec_compare(&create_time1, &create_time)) {
12185 printf("run_dir_createtime: create time was updated (error)\n");
12187 printf("run_dir_createtime: create time was not updated (correct)\n");
12193 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
12194 cli_rmdir(cli, dname);
12195 if (!torture_close_connection(cli)) {
12202 static bool run_streamerror(int dummy)
12204 struct cli_state *cli;
12205 const char *dname = "\\testdir_streamerror";
12206 const char *streamname =
12207 "testdir_streamerror:{4c8cc155-6c1e-11d1-8e41-00c04fb9386d}:$DATA";
12209 time_t change_time, access_time, write_time;
12211 uint16_t mode, fnum;
12214 if (!torture_open_connection(&cli, 0)) {
12218 cli_unlink(cli, "\\testdir_streamerror\\*", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
12219 cli_rmdir(cli, dname);
12221 status = cli_mkdir(cli, dname);
12222 if (!NT_STATUS_IS_OK(status)) {
12223 printf("mkdir failed: %s\n", nt_errstr(status));
12227 status = cli_qpathinfo1(cli, streamname, &change_time, &access_time,
12228 &write_time, &size, &mode);
12229 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
12230 printf("pathinfo returned %s, expected "
12231 "NT_STATUS_OBJECT_NAME_NOT_FOUND\n",
12232 nt_errstr(status));
12236 status = cli_ntcreate(cli, streamname, 0x16,
12237 FILE_READ_DATA|FILE_READ_EA|
12238 FILE_READ_ATTRIBUTES|READ_CONTROL_ACCESS,
12239 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ,
12240 FILE_OPEN, 0, 0, &fnum, NULL);
12242 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
12243 printf("ntcreate returned %s, expected "
12244 "NT_STATUS_OBJECT_NAME_NOT_FOUND\n",
12245 nt_errstr(status));
12250 cli_rmdir(cli, dname);
12254 struct pidtest_state {
12260 static void pid_echo_done(struct tevent_req *subreq);
12262 static struct tevent_req *pid_echo_send(TALLOC_CTX *mem_ctx,
12263 struct tevent_context *ev,
12264 struct cli_state *cli)
12266 struct tevent_req *req, *subreq;
12267 struct pidtest_state *state;
12269 req = tevent_req_create(mem_ctx, &state, struct pidtest_state);
12274 SSVAL(state->vwv, 0, 1);
12275 state->data = data_blob_const("hello", 5);
12277 subreq = smb1cli_req_send(state,
12281 0, 0, /* *_flags */
12282 0, 0, /* *_flags2 */
12284 0xDEADBEEF, /* pid */
12286 NULL, /* session */
12287 ARRAY_SIZE(state->vwv), state->vwv,
12288 state->data.length, state->data.data);
12290 if (tevent_req_nomem(subreq, req)) {
12291 return tevent_req_post(req, ev);
12293 tevent_req_set_callback(subreq, pid_echo_done, req);
12297 static void pid_echo_done(struct tevent_req *subreq)
12299 struct tevent_req *req = tevent_req_callback_data(
12300 subreq, struct tevent_req);
12301 struct pidtest_state *state = tevent_req_data(
12302 req, struct pidtest_state);
12304 uint32_t num_bytes;
12305 uint8_t *bytes = NULL;
12306 struct iovec *recv_iov = NULL;
12307 uint8_t *phdr = NULL;
12308 uint16_t pidlow = 0;
12309 uint16_t pidhigh = 0;
12310 struct smb1cli_req_expected_response expected[] = {
12312 .status = NT_STATUS_OK,
12317 status = smb1cli_req_recv(subreq, state,
12322 NULL, /* pvwv_offset */
12325 NULL, /* pbytes_offset */
12327 expected, ARRAY_SIZE(expected));
12329 TALLOC_FREE(subreq);
12331 if (!NT_STATUS_IS_OK(status)) {
12332 tevent_req_nterror(req, status);
12336 if (num_bytes != state->data.length) {
12337 tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
12341 if (memcmp(bytes, state->data.data, num_bytes) != 0) {
12342 tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
12346 /* Check pid low/high == DEADBEEF */
12347 pidlow = SVAL(phdr, HDR_PID);
12348 if (pidlow != 0xBEEF){
12349 printf("Incorrect pidlow 0x%x, should be 0xBEEF\n",
12350 (unsigned int)pidlow);
12351 tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
12354 pidhigh = SVAL(phdr, HDR_PIDHIGH);
12355 if (pidhigh != 0xDEAD){
12356 printf("Incorrect pidhigh 0x%x, should be 0xDEAD\n",
12357 (unsigned int)pidhigh);
12358 tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
12362 tevent_req_done(req);
12365 static NTSTATUS pid_echo_recv(struct tevent_req *req)
12367 return tevent_req_simple_recv_ntstatus(req);
12370 static bool run_pidhigh(int dummy)
12372 bool success = false;
12373 struct cli_state *cli = NULL;
12375 struct tevent_context *ev = NULL;
12376 struct tevent_req *req = NULL;
12377 TALLOC_CTX *frame = talloc_stackframe();
12379 printf("starting pid high test\n");
12380 if (!torture_open_connection(&cli, 0)) {
12383 smbXcli_conn_set_sockopt(cli->conn, sockops);
12385 ev = samba_tevent_context_init(frame);
12390 req = pid_echo_send(frame, ev, cli);
12395 if (!tevent_req_poll_ntstatus(req, ev, &status)) {
12399 status = pid_echo_recv(req);
12400 if (NT_STATUS_IS_OK(status)) {
12401 printf("pid high test ok\n");
12407 TALLOC_FREE(frame);
12408 torture_close_connection(cli);
12413 Test Windows open on a bad POSIX symlink.
12415 static bool run_symlink_open_test(int dummy)
12417 static struct cli_state *cli;
12418 const char *fname = "non_existant_file";
12419 const char *sname = "dangling_symlink";
12420 uint16_t fnum = (uint16_t)-1;
12421 bool correct = false;
12423 TALLOC_CTX *frame = NULL;
12425 frame = talloc_stackframe();
12427 printf("Starting Windows bad symlink open test\n");
12429 if (!torture_open_connection(&cli, 0)) {
12430 TALLOC_FREE(frame);
12434 smbXcli_conn_set_sockopt(cli->conn, sockops);
12436 status = torture_setup_unix_extensions(cli);
12437 if (!NT_STATUS_IS_OK(status)) {
12438 TALLOC_FREE(frame);
12442 /* Ensure nothing exists. */
12443 cli_setatr(cli, fname, 0, 0);
12444 cli_posix_unlink(cli, fname);
12445 cli_setatr(cli, sname, 0, 0);
12446 cli_posix_unlink(cli, sname);
12448 /* Create a symlink pointing nowhere. */
12449 status = cli_posix_symlink(cli, fname, sname);
12450 if (!NT_STATUS_IS_OK(status)) {
12451 printf("cli_posix_symlink of %s -> %s failed (%s)\n",
12454 nt_errstr(status));
12458 /* Now ensure that a Windows open doesn't hang. */
12459 status = cli_ntcreate(cli,
12462 FILE_READ_DATA|FILE_WRITE_DATA,
12464 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
12472 * We get either NT_STATUS_OBJECT_NAME_NOT_FOUND or
12473 * NT_STATUS_OBJECT_PATH_NOT_FOUND depending on if
12474 * we use O_NOFOLLOW on the server or not.
12476 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND) ||
12477 NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_PATH_NOT_FOUND))
12481 printf("cli_ntcreate of %s returned %s - should return"
12482 " either (%s) or (%s)\n",
12485 nt_errstr(NT_STATUS_OBJECT_NAME_NOT_FOUND),
12486 nt_errstr(NT_STATUS_OBJECT_PATH_NOT_FOUND));
12494 if (fnum != (uint16_t)-1) {
12495 cli_close(cli, fnum);
12496 fnum = (uint16_t)-1;
12499 cli_setatr(cli, sname, 0, 0);
12500 cli_posix_unlink(cli, sname);
12501 cli_setatr(cli, fname, 0, 0);
12502 cli_posix_unlink(cli, fname);
12504 if (!torture_close_connection(cli)) {
12508 TALLOC_FREE(frame);
12513 * Only testing minimal time strings, as the others
12514 * need (locale-dependent) guessing at what strftime does and
12515 * even may differ in builds.
12517 static bool timesubst_test(void)
12519 TALLOC_CTX *ctx = NULL;
12520 /* Sa 23. Dez 04:33:20 CET 2017 */
12521 const struct timeval tv = { 1514000000, 123 };
12522 const char* expect_minimal = "20171223_033320";
12523 const char* expect_minus = "20171223_033320_000123";
12525 char *env_tz, *orig_tz = NULL;
12526 bool result = true;
12528 ctx = talloc_new(NULL);
12530 env_tz = getenv("TZ");
12532 orig_tz = talloc_strdup(ctx, env_tz);
12534 setenv("TZ", "UTC", 1);
12536 s = minimal_timeval_string(ctx, &tv, false);
12538 if(!s || strcmp(s, expect_minimal)) {
12539 printf("minimal_timeval_string(ctx, tv, false) returned [%s], expected "
12540 "[%s]\n", s ? s : "<nil>", expect_minimal);
12544 s = minimal_timeval_string(ctx, &tv, true);
12545 if(!s || strcmp(s, expect_minus)) {
12546 printf("minimal_timeval_string(ctx, tv, true) returned [%s], expected "
12547 "[%s]\n", s ? s : "<nil>", expect_minus);
12553 setenv("TZ", orig_tz, 1);
12560 static bool run_local_substitute(int dummy)
12564 ok &= subst_test("%U", "bla", "", -1, -1, "bla");
12565 ok &= subst_test("%u%U", "bla", "", -1, -1, "blabla");
12566 ok &= subst_test("%g", "", "", -1, -1, "NO_GROUP");
12567 ok &= subst_test("%G", "", "", -1, -1, "NO_GROUP");
12568 ok &= subst_test("%g", "", "", -1, 0, gidtoname(0));
12569 ok &= subst_test("%G", "", "", -1, 0, gidtoname(0));
12570 ok &= subst_test("%D%u", "u", "dom", -1, 0, "domu");
12571 ok &= subst_test("%i %I", "", "", -1, -1, "0.0.0.0 0.0.0.0");
12572 ok &= subst_test("%j %J", "", "", -1, -1, "0_0_0_0 0_0_0_0");
12573 /* Substitution depends on current time, so better test the underlying
12574 formatting function. At least covers %t. */
12575 ok &= timesubst_test();
12577 /* Different captialization rules in sub_basic... */
12579 ok &= (strcmp(talloc_sub_basic(talloc_tos(), "BLA", "dom", "%U%D"),
12585 static bool run_local_base64(int dummy)
12590 for (i=1; i<2000; i++) {
12591 DATA_BLOB blob1, blob2;
12594 blob1.data = talloc_array(talloc_tos(), uint8_t, i);
12596 generate_random_buffer(blob1.data, blob1.length);
12598 b64 = base64_encode_data_blob(talloc_tos(), blob1);
12600 d_fprintf(stderr, "base64_encode_data_blob failed "
12601 "for %d bytes\n", i);
12604 blob2 = base64_decode_data_blob(b64);
12607 if (data_blob_cmp(&blob1, &blob2)) {
12608 d_fprintf(stderr, "data_blob_cmp failed for %d "
12612 TALLOC_FREE(blob1.data);
12613 data_blob_free(&blob2);
12618 static void parse_fn(const struct gencache_timeout *t,
12620 void *private_data)
12625 static bool run_local_gencache(int dummy)
12631 struct memcache *mem;
12634 mem = memcache_init(NULL, 0);
12636 d_printf("%s: memcache_init failed\n", __location__);
12639 memcache_set_global(mem);
12641 if (!gencache_set("foo", "bar", time(NULL) + 1000)) {
12642 d_printf("%s: gencache_set() failed\n", __location__);
12646 if (!gencache_get("foo", NULL, NULL, NULL)) {
12647 d_printf("%s: gencache_get() failed\n", __location__);
12651 for (i=0; i<1000000; i++) {
12652 gencache_parse("foo", parse_fn, NULL);
12655 if (!gencache_get("foo", talloc_tos(), &val, &tm)) {
12656 d_printf("%s: gencache_get() failed\n", __location__);
12661 if (!gencache_get("foo", talloc_tos(), &val, &tm)) {
12662 d_printf("%s: gencache_get() failed\n", __location__);
12666 if (strcmp(val, "bar") != 0) {
12667 d_printf("%s: gencache_get() returned %s, expected %s\n",
12668 __location__, val, "bar");
12675 if (!gencache_del("foo")) {
12676 d_printf("%s: gencache_del() failed\n", __location__);
12679 if (gencache_del("foo")) {
12680 d_printf("%s: second gencache_del() succeeded\n",
12685 if (gencache_get("foo", talloc_tos(), &val, &tm)) {
12686 d_printf("%s: gencache_get() on deleted entry "
12687 "succeeded\n", __location__);
12691 blob = data_blob_string_const_null("bar");
12692 tm = time(NULL) + 60;
12694 if (!gencache_set_data_blob("foo", blob, tm)) {
12695 d_printf("%s: gencache_set_data_blob() failed\n", __location__);
12699 if (!gencache_get_data_blob("foo", talloc_tos(), &blob, NULL, NULL)) {
12700 d_printf("%s: gencache_get_data_blob() failed\n", __location__);
12704 if (strcmp((const char *)blob.data, "bar") != 0) {
12705 d_printf("%s: gencache_get_data_blob() returned %s, expected %s\n",
12706 __location__, (const char *)blob.data, "bar");
12707 data_blob_free(&blob);
12711 data_blob_free(&blob);
12713 if (!gencache_del("foo")) {
12714 d_printf("%s: gencache_del() failed\n", __location__);
12717 if (gencache_del("foo")) {
12718 d_printf("%s: second gencache_del() succeeded\n",
12723 if (gencache_get_data_blob("foo", talloc_tos(), &blob, NULL, NULL)) {
12724 d_printf("%s: gencache_get_data_blob() on deleted entry "
12725 "succeeded\n", __location__);
12730 blob.data = (uint8_t *)&v;
12731 blob.length = sizeof(v);
12733 if (!gencache_set_data_blob("blob", blob, tm)) {
12734 d_printf("%s: gencache_set_data_blob() failed\n",
12738 if (gencache_get("blob", talloc_tos(), &val, &tm)) {
12739 d_printf("%s: gencache_get succeeded\n", __location__);
12746 static bool rbt_testval(struct db_context *db, const char *key,
12749 struct db_record *rec;
12750 TDB_DATA data = string_tdb_data(value);
12755 rec = dbwrap_fetch_locked(db, db, string_tdb_data(key));
12757 d_fprintf(stderr, "fetch_locked failed\n");
12760 status = dbwrap_record_store(rec, data, 0);
12761 if (!NT_STATUS_IS_OK(status)) {
12762 d_fprintf(stderr, "store failed: %s\n", nt_errstr(status));
12767 rec = dbwrap_fetch_locked(db, db, string_tdb_data(key));
12769 d_fprintf(stderr, "second fetch_locked failed\n");
12773 dbvalue = dbwrap_record_get_value(rec);
12774 if ((dbvalue.dsize != data.dsize)
12775 || (memcmp(dbvalue.dptr, data.dptr, data.dsize) != 0)) {
12776 d_fprintf(stderr, "Got wrong data back\n");
12786 static int local_rbtree_traverse_read(struct db_record *rec, void *private_data)
12788 int *count2 = (int *)private_data;
12793 static int local_rbtree_traverse_delete(struct db_record *rec, void *private_data)
12795 int *count2 = (int *)private_data;
12797 dbwrap_record_delete(rec);
12801 static bool run_local_rbtree(int dummy)
12803 struct db_context *db;
12810 db = db_open_rbt(NULL);
12813 d_fprintf(stderr, "db_open_rbt failed\n");
12817 for (i=0; i<1000; i++) {
12820 if (asprintf(&key, "key%ld", random()) == -1) {
12823 if (asprintf(&value, "value%ld", random()) == -1) {
12828 if (!rbt_testval(db, key, value)) {
12835 if (asprintf(&value, "value%ld", random()) == -1) {
12840 if (!rbt_testval(db, key, value)) {
12851 count = 0; count2 = 0;
12852 status = dbwrap_traverse_read(db, local_rbtree_traverse_read,
12854 printf("%s: read1: %d %d, %s\n", __func__, count, count2, nt_errstr(status));
12855 if ((count != count2) || (count != 1000)) {
12858 count = 0; count2 = 0;
12859 status = dbwrap_traverse(db, local_rbtree_traverse_delete,
12861 printf("%s: delete: %d %d, %s\n", __func__, count, count2, nt_errstr(status));
12862 if ((count != count2) || (count != 1000)) {
12865 count = 0; count2 = 0;
12866 status = dbwrap_traverse_read(db, local_rbtree_traverse_read,
12868 printf("%s: read2: %d %d, %s\n", __func__, count, count2, nt_errstr(status));
12869 if ((count != count2) || (count != 0)) {
12880 local test for character set functions
12882 This is a very simple test for the functionality in convert_string_error()
12884 static bool run_local_convert_string(int dummy)
12886 TALLOC_CTX *tmp_ctx = talloc_new(NULL);
12887 const char *test_strings[2] = { "March", "M\303\244rz" };
12891 for (i=0; i<2; i++) {
12892 const char *str = test_strings[i];
12893 int len = strlen(str);
12894 size_t converted_size;
12897 memset(dst, 'X', sizeof(dst));
12899 /* first try with real source length */
12900 ret = convert_string_error(CH_UNIX, CH_UTF8,
12905 d_fprintf(stderr, "Failed to convert '%s' to CH_DISPLAY\n", str);
12909 if (converted_size != len) {
12910 d_fprintf(stderr, "Converted size of '%s' should be %d - got %d\n",
12911 str, len, (int)converted_size);
12915 if (strncmp(str, dst, converted_size) != 0) {
12916 d_fprintf(stderr, "Expected '%s' to match '%s'\n", str, dst);
12920 if (strlen(str) != converted_size) {
12921 d_fprintf(stderr, "Expected '%s' length %d - got %d\n", str,
12922 (int)strlen(str), (int)converted_size);
12926 if (dst[converted_size] != 'X') {
12927 d_fprintf(stderr, "Expected no termination of '%s'\n", dst);
12931 /* now with srclen==-1, this causes the nul to be
12933 ret = convert_string_error(CH_UNIX, CH_UTF8,
12938 d_fprintf(stderr, "Failed to convert '%s' to CH_DISPLAY\n", str);
12942 if (converted_size != len+1) {
12943 d_fprintf(stderr, "Converted size of '%s' should be %d - got %d\n",
12944 str, len, (int)converted_size);
12948 if (strncmp(str, dst, converted_size) != 0) {
12949 d_fprintf(stderr, "Expected '%s' to match '%s'\n", str, dst);
12953 if (len+1 != converted_size) {
12954 d_fprintf(stderr, "Expected '%s' length %d - got %d\n", str,
12955 len+1, (int)converted_size);
12959 if (dst[converted_size] != 'X') {
12960 d_fprintf(stderr, "Expected no termination of '%s'\n", dst);
12967 TALLOC_FREE(tmp_ctx);
12970 TALLOC_FREE(tmp_ctx);
12974 static bool run_local_string_to_sid(int dummy) {
12975 struct dom_sid sid;
12977 if (string_to_sid(&sid, "S--1-5-32-545")) {
12978 printf("allowing S--1-5-32-545\n");
12981 if (string_to_sid(&sid, "S-1-5-32-+545")) {
12982 printf("allowing S-1-5-32-+545\n");
12985 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")) {
12986 printf("allowing S-1-2-3-4-5-6-7-8-9-0-1-2-3-4-5-6-7-8-9-0\n");
12989 if (string_to_sid(&sid, "S-1-5-32-545-abc")) {
12990 printf("allowing S-1-5-32-545-abc\n");
12993 if (string_to_sid(&sid, "S-300-5-32-545")) {
12994 printf("allowing S-300-5-32-545\n");
12997 if (string_to_sid(&sid, "S-1-0xfffffffffffffe-32-545")) {
12998 printf("allowing S-1-0xfffffffffffffe-32-545\n");
13001 if (string_to_sid(&sid, "S-1-0xffffffffffff-5294967297-545")) {
13002 printf("allowing S-1-0xffffffffffff-5294967297-545\n");
13005 if (!string_to_sid(&sid, "S-1-0xfffffffffffe-32-545")) {
13006 printf("could not parse S-1-0xfffffffffffe-32-545\n");
13009 if (!string_to_sid(&sid, "S-1-5-32-545")) {
13010 printf("could not parse S-1-5-32-545\n");
13013 if (!dom_sid_equal(&sid, &global_sid_Builtin_Users)) {
13014 struct dom_sid_buf buf;
13015 printf("mis-parsed S-1-5-32-545 as %s\n",
13016 dom_sid_str_buf(&sid, &buf));
13022 static bool sid_to_string_test(const char *expected) {
13025 struct dom_sid sid;
13027 if (!string_to_sid(&sid, expected)) {
13028 printf("could not parse %s\n", expected);
13032 str = dom_sid_string(NULL, &sid);
13033 if (strcmp(str, expected)) {
13034 printf("Comparison failed (%s != %s)\n", str, expected);
13041 static bool run_local_sid_to_string(int dummy) {
13042 if (!sid_to_string_test("S-1-0xffffffffffff-1-1-1-1-1-1-1-1-1-1-1-1"))
13044 if (!sid_to_string_test("S-1-545"))
13046 if (!sid_to_string_test("S-255-3840-1-1-1-1"))
13051 static bool run_local_binary_to_sid(int dummy) {
13053 struct dom_sid *sid = talloc(NULL, struct dom_sid);
13054 static const uint8_t good_binary_sid[] = {
13055 0x1, /* revision number */
13056 15, /* num auths */
13057 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, /* id_auth */
13058 0x1, 0x1, 0x1, 0x1, /* auth[0] */
13059 0x1, 0x1, 0x1, 0x1, /* auth[1] */
13060 0x1, 0x1, 0x1, 0x1, /* auth[2] */
13061 0x1, 0x1, 0x1, 0x1, /* auth[3] */
13062 0x1, 0x1, 0x1, 0x1, /* auth[4] */
13063 0x1, 0x1, 0x1, 0x1, /* auth[5] */
13064 0x1, 0x1, 0x1, 0x1, /* auth[6] */
13065 0x1, 0x1, 0x1, 0x1, /* auth[7] */
13066 0x1, 0x1, 0x1, 0x1, /* auth[8] */
13067 0x1, 0x1, 0x1, 0x1, /* auth[9] */
13068 0x1, 0x1, 0x1, 0x1, /* auth[10] */
13069 0x1, 0x1, 0x1, 0x1, /* auth[11] */
13070 0x1, 0x1, 0x1, 0x1, /* auth[12] */
13071 0x1, 0x1, 0x1, 0x1, /* auth[13] */
13072 0x1, 0x1, 0x1, 0x1, /* auth[14] */
13075 static const uint8_t long_binary_sid[] = {
13076 0x1, /* revision number */
13077 15, /* num auths */
13078 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, /* id_auth */
13079 0x1, 0x1, 0x1, 0x1, /* auth[0] */
13080 0x1, 0x1, 0x1, 0x1, /* auth[1] */
13081 0x1, 0x1, 0x1, 0x1, /* auth[2] */
13082 0x1, 0x1, 0x1, 0x1, /* auth[3] */
13083 0x1, 0x1, 0x1, 0x1, /* auth[4] */
13084 0x1, 0x1, 0x1, 0x1, /* auth[5] */
13085 0x1, 0x1, 0x1, 0x1, /* auth[6] */
13086 0x1, 0x1, 0x1, 0x1, /* auth[7] */
13087 0x1, 0x1, 0x1, 0x1, /* auth[8] */
13088 0x1, 0x1, 0x1, 0x1, /* auth[9] */
13089 0x1, 0x1, 0x1, 0x1, /* auth[10] */
13090 0x1, 0x1, 0x1, 0x1, /* auth[11] */
13091 0x1, 0x1, 0x1, 0x1, /* auth[12] */
13092 0x1, 0x1, 0x1, 0x1, /* auth[13] */
13093 0x1, 0x1, 0x1, 0x1, /* auth[14] */
13094 0x1, 0x1, 0x1, 0x1, /* auth[15] */
13095 0x1, 0x1, 0x1, 0x1, /* auth[16] */
13096 0x1, 0x1, 0x1, 0x1, /* auth[17] */
13099 static const uint8_t long_binary_sid2[] = {
13100 0x1, /* revision number */
13101 32, /* num auths */
13102 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, /* id_auth */
13103 0x1, 0x1, 0x1, 0x1, /* auth[0] */
13104 0x1, 0x1, 0x1, 0x1, /* auth[1] */
13105 0x1, 0x1, 0x1, 0x1, /* auth[2] */
13106 0x1, 0x1, 0x1, 0x1, /* auth[3] */
13107 0x1, 0x1, 0x1, 0x1, /* auth[4] */
13108 0x1, 0x1, 0x1, 0x1, /* auth[5] */
13109 0x1, 0x1, 0x1, 0x1, /* auth[6] */
13110 0x1, 0x1, 0x1, 0x1, /* auth[7] */
13111 0x1, 0x1, 0x1, 0x1, /* auth[8] */
13112 0x1, 0x1, 0x1, 0x1, /* auth[9] */
13113 0x1, 0x1, 0x1, 0x1, /* auth[10] */
13114 0x1, 0x1, 0x1, 0x1, /* auth[11] */
13115 0x1, 0x1, 0x1, 0x1, /* auth[12] */
13116 0x1, 0x1, 0x1, 0x1, /* auth[13] */
13117 0x1, 0x1, 0x1, 0x1, /* auth[14] */
13118 0x1, 0x1, 0x1, 0x1, /* auth[15] */
13119 0x1, 0x1, 0x1, 0x1, /* auth[16] */
13120 0x1, 0x1, 0x1, 0x1, /* auth[17] */
13121 0x1, 0x1, 0x1, 0x1, /* auth[18] */
13122 0x1, 0x1, 0x1, 0x1, /* auth[19] */
13123 0x1, 0x1, 0x1, 0x1, /* auth[20] */
13124 0x1, 0x1, 0x1, 0x1, /* auth[21] */
13125 0x1, 0x1, 0x1, 0x1, /* auth[22] */
13126 0x1, 0x1, 0x1, 0x1, /* auth[23] */
13127 0x1, 0x1, 0x1, 0x1, /* auth[24] */
13128 0x1, 0x1, 0x1, 0x1, /* auth[25] */
13129 0x1, 0x1, 0x1, 0x1, /* auth[26] */
13130 0x1, 0x1, 0x1, 0x1, /* auth[27] */
13131 0x1, 0x1, 0x1, 0x1, /* auth[28] */
13132 0x1, 0x1, 0x1, 0x1, /* auth[29] */
13133 0x1, 0x1, 0x1, 0x1, /* auth[30] */
13134 0x1, 0x1, 0x1, 0x1, /* auth[31] */
13137 ret = sid_parse(good_binary_sid, sizeof(good_binary_sid), sid);
13141 ret = sid_parse(long_binary_sid2, sizeof(long_binary_sid2), sid);
13145 ret = sid_parse(long_binary_sid, sizeof(long_binary_sid), sid);
13152 /* Split a path name into filename and stream name components. Canonicalise
13153 * such that an implicit $DATA token is always explicit.
13155 * The "specification" of this function can be found in the
13156 * run_local_stream_name() function in torture.c, I've tried those
13157 * combinations against a W2k3 server.
13160 static NTSTATUS split_ntfs_stream_name(TALLOC_CTX *mem_ctx, const char *fname,
13161 char **pbase, char **pstream)
13164 char *stream = NULL;
13165 char *sname; /* stream name */
13166 const char *stype; /* stream type */
13168 DEBUG(10, ("split_ntfs_stream_name called for [%s]\n", fname));
13170 sname = strchr_m(fname, ':');
13172 if (sname == NULL) {
13173 if (pbase != NULL) {
13174 base = talloc_strdup(mem_ctx, fname);
13175 NT_STATUS_HAVE_NO_MEMORY(base);
13180 if (pbase != NULL) {
13181 base = talloc_strndup(mem_ctx, fname, PTR_DIFF(sname, fname));
13182 NT_STATUS_HAVE_NO_MEMORY(base);
13187 stype = strchr_m(sname, ':');
13189 if (stype == NULL) {
13190 sname = talloc_strdup(mem_ctx, sname);
13194 if (strcasecmp_m(stype, ":$DATA") != 0) {
13196 * If there is an explicit stream type, so far we only
13197 * allow $DATA. Is there anything else allowed? -- vl
13199 DEBUG(10, ("[%s] is an invalid stream type\n", stype));
13201 return NT_STATUS_OBJECT_NAME_INVALID;
13203 sname = talloc_strndup(mem_ctx, sname, PTR_DIFF(stype, sname));
13207 if (sname == NULL) {
13209 return NT_STATUS_NO_MEMORY;
13212 if (sname[0] == '\0') {
13214 * no stream name, so no stream
13219 if (pstream != NULL) {
13220 stream = talloc_asprintf(mem_ctx, "%s:%s", sname, stype);
13221 if (stream == NULL) {
13222 TALLOC_FREE(sname);
13224 return NT_STATUS_NO_MEMORY;
13227 * upper-case the type field
13229 (void)strupper_m(strchr_m(stream, ':')+1);
13233 if (pbase != NULL) {
13236 if (pstream != NULL) {
13239 return NT_STATUS_OK;
13242 static bool test_stream_name(const char *fname, const char *expected_base,
13243 const char *expected_stream,
13244 NTSTATUS expected_status)
13248 char *stream = NULL;
13250 status = split_ntfs_stream_name(talloc_tos(), fname, &base, &stream);
13251 if (!NT_STATUS_EQUAL(status, expected_status)) {
13255 if (!NT_STATUS_IS_OK(status)) {
13259 if (base == NULL) goto error;
13261 if (strcmp(expected_base, base) != 0) goto error;
13263 if ((expected_stream != NULL) && (stream == NULL)) goto error;
13264 if ((expected_stream == NULL) && (stream != NULL)) goto error;
13266 if ((stream != NULL) && (strcmp(expected_stream, stream) != 0))
13270 TALLOC_FREE(stream);
13274 d_fprintf(stderr, "Do test_stream(%s, %s, %s, %s)\n",
13275 fname, expected_base ? expected_base : "<NULL>",
13276 expected_stream ? expected_stream : "<NULL>",
13277 nt_errstr(expected_status));
13278 d_fprintf(stderr, "-> base=%s, stream=%s, status=%s\n",
13279 base ? base : "<NULL>", stream ? stream : "<NULL>",
13280 nt_errstr(status));
13282 TALLOC_FREE(stream);
13286 static bool run_local_stream_name(int dummy)
13290 ret &= test_stream_name(
13291 "bla", "bla", NULL, NT_STATUS_OK);
13292 ret &= test_stream_name(
13293 "bla::$DATA", "bla", NULL, NT_STATUS_OK);
13294 ret &= test_stream_name(
13295 "bla:blub:", "bla", NULL, NT_STATUS_OBJECT_NAME_INVALID);
13296 ret &= test_stream_name(
13297 "bla::", NULL, NULL, NT_STATUS_OBJECT_NAME_INVALID);
13298 ret &= test_stream_name(
13299 "bla::123", "bla", NULL, NT_STATUS_OBJECT_NAME_INVALID);
13300 ret &= test_stream_name(
13301 "bla:$DATA", "bla", "$DATA:$DATA", NT_STATUS_OK);
13302 ret &= test_stream_name(
13303 "bla:x:$DATA", "bla", "x:$DATA", NT_STATUS_OK);
13304 ret &= test_stream_name(
13305 "bla:x", "bla", "x:$DATA", NT_STATUS_OK);
13310 static bool data_blob_equal(DATA_BLOB a, DATA_BLOB b)
13312 if (a.length != b.length) {
13313 printf("a.length=%d != b.length=%d\n",
13314 (int)a.length, (int)b.length);
13317 if (memcmp(a.data, b.data, a.length) != 0) {
13318 printf("a.data and b.data differ\n");
13324 static bool run_local_memcache(int dummy)
13326 struct memcache *cache;
13327 DATA_BLOB k1, k2, k3, k4, k5;
13331 TALLOC_CTX *mem_ctx;
13337 size_t size1, size2;
13340 mem_ctx = talloc_init("foo");
13341 if (mem_ctx == NULL) {
13345 /* STAT_CACHE TESTS */
13347 cache = memcache_init(NULL, sizeof(void *) == 8 ? 200 : 100);
13349 if (cache == NULL) {
13350 printf("memcache_init failed\n");
13354 d1 = data_blob_const("d1", 2);
13355 d3 = data_blob_const("d3", 2);
13357 k1 = data_blob_const("d1", 2);
13358 k2 = data_blob_const("d2", 2);
13359 k3 = data_blob_const("d3", 2);
13360 k4 = data_blob_const("d4", 2);
13361 k5 = data_blob_const("d5", 2);
13363 memcache_add(cache, STAT_CACHE, k1, d1);
13365 if (!memcache_lookup(cache, STAT_CACHE, k1, &v1)) {
13366 printf("could not find k1\n");
13369 if (!data_blob_equal(d1, v1)) {
13373 memcache_add(cache, STAT_CACHE, k1, d3);
13375 if (!memcache_lookup(cache, STAT_CACHE, k1, &v3)) {
13376 printf("could not find replaced k1\n");
13379 if (!data_blob_equal(d3, v3)) {
13383 TALLOC_FREE(cache);
13385 /* GETWD_CACHE TESTS */
13386 str1 = talloc_strdup(mem_ctx, "string1");
13387 if (str1 == NULL) {
13390 ptr2 = str1; /* Keep an alias for comparison. */
13392 str2 = talloc_strdup(mem_ctx, "string2");
13393 if (str2 == NULL) {
13397 cache = memcache_init(NULL, sizeof(void *) == 8 ? 200 : 100);
13398 if (cache == NULL) {
13399 printf("memcache_init failed\n");
13403 memcache_add_talloc(cache, GETWD_CACHE, k2, &str1);
13404 /* str1 == NULL now. */
13405 ptr1 = memcache_lookup_talloc(cache, GETWD_CACHE, k2);
13406 if (ptr1 == NULL) {
13407 printf("could not find k2\n");
13410 if (ptr1 != ptr2) {
13411 printf("fetch of k2 got wrong string\n");
13415 /* Add a blob to ensure k2 gets purged. */
13416 d3 = data_blob_talloc_zero(mem_ctx, 180);
13417 memcache_add(cache, STAT_CACHE, k3, d3);
13419 ptr2 = memcache_lookup_talloc(cache, GETWD_CACHE, k2);
13420 if (ptr2 != NULL) {
13421 printf("Did find k2, should have been purged\n");
13426 * Test that talloc size also is accounted in memcache and
13427 * causes purge of other object.
13430 str1 = talloc_zero_size(mem_ctx, 100);
13431 str2 = talloc_zero_size(mem_ctx, 100);
13433 memcache_add_talloc(cache, GETWD_CACHE, k4, &str1);
13434 memcache_add_talloc(cache, GETWD_CACHE, k5, &str1);
13436 ptr3 = memcache_lookup_talloc(cache, GETWD_CACHE, k4);
13437 if (ptr3 != NULL) {
13438 printf("Did find k4, should have been purged\n");
13443 * Test that adding a duplicate non-talloced
13444 * key/value on top of a talloced key/value takes account
13445 * of the talloc_freed value size.
13447 TALLOC_FREE(cache);
13448 TALLOC_FREE(mem_ctx);
13450 mem_ctx = talloc_init("key_replace");
13451 if (mem_ctx == NULL) {
13455 cache = memcache_init(NULL, sizeof(void *) == 8 ? 200 : 100);
13456 if (cache == NULL) {
13461 * Add a 100 byte talloced string. This will
13462 * store a (4 or 8 byte) pointer and record the
13463 * total talloced size.
13465 str1 = talloc_zero_size(mem_ctx, 100);
13466 memcache_add_talloc(cache, GETWD_CACHE, k4, &str1);
13468 * Now overwrite with a small talloced
13469 * value. This should fit in the existing size
13470 * and the total talloced size should be removed
13471 * from the cache size.
13473 str1 = talloc_zero_size(mem_ctx, 2);
13474 memcache_add_talloc(cache, GETWD_CACHE, k4, &str1);
13476 * Now store a 20 byte string. If the
13477 * total talloced size wasn't accounted for
13478 * and removed in the overwrite, then this
13481 str2 = talloc_zero_size(mem_ctx, 20);
13482 memcache_add_talloc(cache, GETWD_CACHE, k5, &str2);
13484 ptr3 = memcache_lookup_talloc(cache, GETWD_CACHE, k4);
13485 if (ptr3 == NULL) {
13486 printf("Did not find k4, should not have been purged\n");
13490 TALLOC_FREE(cache);
13491 TALLOC_FREE(mem_ctx);
13493 mem_ctx = talloc_init("foo");
13494 if (mem_ctx == NULL) {
13498 cache = memcache_init(NULL, 0);
13499 if (cache == NULL) {
13503 str1 = talloc_strdup(mem_ctx, "string1");
13504 if (str1 == NULL) {
13507 str2 = talloc_strdup(mem_ctx, "string2");
13508 if (str2 == NULL) {
13511 memcache_add_talloc(cache, SINGLETON_CACHE_TALLOC,
13512 data_blob_string_const("torture"), &str1);
13513 size1 = talloc_total_size(cache);
13515 memcache_add_talloc(cache, SINGLETON_CACHE_TALLOC,
13516 data_blob_string_const("torture"), &str2);
13517 size2 = talloc_total_size(cache);
13519 printf("size1=%d, size2=%d\n", (int)size1, (int)size2);
13521 if (size2 > size1) {
13522 printf("memcache leaks memory!\n");
13528 TALLOC_FREE(cache);
13532 static void wbclient_done(struct tevent_req *req)
13535 struct winbindd_response *wb_resp;
13536 int *i = (int *)tevent_req_callback_data_void(req);
13538 wbc_err = wb_trans_recv(req, req, &wb_resp);
13541 d_printf("wb_trans_recv %d returned %s\n", *i, wbcErrorString(wbc_err));
13544 static bool run_wbclient_multi_ping(int dummy)
13546 struct tevent_context *ev;
13547 struct wb_context **wb_ctx;
13548 struct winbindd_request wb_req;
13549 bool result = false;
13552 BlockSignals(True, SIGPIPE);
13554 ev = tevent_context_init(talloc_tos());
13559 wb_ctx = talloc_array(ev, struct wb_context *, torture_nprocs);
13560 if (wb_ctx == NULL) {
13564 ZERO_STRUCT(wb_req);
13565 wb_req.cmd = WINBINDD_PING;
13567 d_printf("torture_nprocs=%d, numops=%d\n", (int)torture_nprocs, (int)torture_numops);
13569 for (i=0; i<torture_nprocs; i++) {
13570 wb_ctx[i] = wb_context_init(ev, NULL);
13571 if (wb_ctx[i] == NULL) {
13574 for (j=0; j<torture_numops; j++) {
13575 struct tevent_req *req;
13576 req = wb_trans_send(ev, ev, wb_ctx[i],
13577 (j % 2) == 0, &wb_req);
13581 tevent_req_set_callback(req, wbclient_done, &i);
13587 while (i < torture_nprocs * torture_numops) {
13588 tevent_loop_once(ev);
13597 static bool dbtrans_inc(struct db_context *db)
13599 struct db_record *rec;
13605 rec = dbwrap_fetch_locked(db, db, string_term_tdb_data("transtest"));
13607 printf(__location__ "fetch_lock failed\n");
13611 value = dbwrap_record_get_value(rec);
13613 if (value.dsize != sizeof(uint32_t)) {
13614 printf(__location__ "value.dsize = %d\n",
13619 memcpy(&val, value.dptr, sizeof(val));
13622 status = dbwrap_record_store(
13623 rec, make_tdb_data((uint8_t *)&val, sizeof(val)), 0);
13624 if (!NT_STATUS_IS_OK(status)) {
13625 printf(__location__ "store failed: %s\n",
13626 nt_errstr(status));
13636 static bool run_local_dbtrans(int dummy)
13638 struct db_context *db;
13639 struct db_record *rec;
13645 db = db_open(talloc_tos(), "transtest.tdb", 0, TDB_DEFAULT,
13646 O_RDWR|O_CREAT, 0600, DBWRAP_LOCK_ORDER_1,
13649 printf("Could not open transtest.db\n");
13653 res = dbwrap_transaction_start(db);
13655 printf(__location__ "transaction_start failed\n");
13659 rec = dbwrap_fetch_locked(db, db, string_term_tdb_data("transtest"));
13661 printf(__location__ "fetch_lock failed\n");
13665 value = dbwrap_record_get_value(rec);
13667 if (value.dptr == NULL) {
13669 status = dbwrap_record_store(
13670 rec, make_tdb_data((uint8_t *)&initial,
13673 if (!NT_STATUS_IS_OK(status)) {
13674 printf(__location__ "store returned %s\n",
13675 nt_errstr(status));
13682 res = dbwrap_transaction_commit(db);
13684 printf(__location__ "transaction_commit failed\n");
13689 uint32_t val, val2;
13692 res = dbwrap_transaction_start(db);
13694 printf(__location__ "transaction_start failed\n");
13698 status = dbwrap_fetch_uint32_bystring(db, "transtest", &val);
13699 if (!NT_STATUS_IS_OK(status)) {
13700 printf(__location__ "dbwrap_fetch_uint32 failed: %s\n",
13701 nt_errstr(status));
13705 for (i=0; i<10; i++) {
13706 if (!dbtrans_inc(db)) {
13711 status = dbwrap_fetch_uint32_bystring(db, "transtest", &val2);
13712 if (!NT_STATUS_IS_OK(status)) {
13713 printf(__location__ "dbwrap_fetch_uint32 failed: %s\n",
13714 nt_errstr(status));
13718 if (val2 != val + 10) {
13719 printf(__location__ "val=%d, val2=%d\n",
13720 (int)val, (int)val2);
13724 printf("val2=%d\r", val2);
13726 res = dbwrap_transaction_commit(db);
13728 printf(__location__ "transaction_commit failed\n");
13738 * Just a dummy test to be run under a debugger. There's no real way
13739 * to inspect the tevent_poll specific function from outside of
13743 static bool run_local_tevent_poll(int dummy)
13745 struct tevent_context *ev;
13746 struct tevent_fd *fd1, *fd2;
13747 bool result = false;
13749 ev = tevent_context_init_byname(NULL, "poll");
13751 d_fprintf(stderr, "tevent_context_init_byname failed\n");
13755 fd1 = tevent_add_fd(ev, ev, 2, 0, NULL, NULL);
13757 d_fprintf(stderr, "tevent_add_fd failed\n");
13760 fd2 = tevent_add_fd(ev, ev, 3, 0, NULL, NULL);
13762 d_fprintf(stderr, "tevent_add_fd failed\n");
13767 fd2 = tevent_add_fd(ev, ev, 1, 0, NULL, NULL);
13769 d_fprintf(stderr, "tevent_add_fd failed\n");
13779 static bool run_local_hex_encode_buf(int dummy)
13785 for (i=0; i<sizeof(src); i++) {
13788 hex_encode_buf(buf, src, sizeof(src));
13789 if (strcmp(buf, "0001020304050607") != 0) {
13792 hex_encode_buf(buf, NULL, 0);
13793 if (buf[0] != '\0') {
13799 static const char *remove_duplicate_addrs2_test_strings_vector[] = {
13821 "1001:1111:1111:1000:0:1111:1111:1111",
13830 static const char *remove_duplicate_addrs2_test_strings_result[] = {
13844 "1001:1111:1111:1000:0:1111:1111:1111"
13847 static bool run_local_remove_duplicate_addrs2(int dummy)
13849 struct ip_service test_vector[28];
13852 /* Construct the sockaddr_storage test vector. */
13853 for (i = 0; i < 28; i++) {
13854 struct addrinfo hints;
13855 struct addrinfo *res = NULL;
13858 memset(&hints, '\0', sizeof(hints));
13859 hints.ai_flags = AI_NUMERICHOST;
13860 ret = getaddrinfo(remove_duplicate_addrs2_test_strings_vector[i],
13865 fprintf(stderr, "getaddrinfo failed on [%s]\n",
13866 remove_duplicate_addrs2_test_strings_vector[i]);
13869 memset(&test_vector[i], '\0', sizeof(test_vector[i]));
13870 memcpy(&test_vector[i].ss,
13876 count = remove_duplicate_addrs2(test_vector, i);
13879 fprintf(stderr, "count wrong (%d) should be 14\n",
13884 for (i = 0; i < count; i++) {
13885 char addr[INET6_ADDRSTRLEN];
13887 print_sockaddr(addr, sizeof(addr), &test_vector[i].ss);
13889 if (strcmp(addr, remove_duplicate_addrs2_test_strings_result[i]) != 0) {
13890 fprintf(stderr, "mismatch on [%d] [%s] [%s]\n",
13893 remove_duplicate_addrs2_test_strings_result[i]);
13898 printf("run_local_remove_duplicate_addrs2: success\n");
13902 static bool run_local_tdb_opener(int dummy)
13908 t = tdb_open("test.tdb", 1000, TDB_CLEAR_IF_FIRST,
13909 O_RDWR|O_CREAT, 0755);
13911 perror("tdb_open failed");
13922 static bool run_local_tdb_writer(int dummy)
13928 t = tdb_open("test.tdb", 1000, 0, O_RDWR|O_CREAT, 0755);
13930 perror("tdb_open failed");
13934 val.dptr = (uint8_t *)&v;
13935 val.dsize = sizeof(v);
13941 ret = tdb_store(t, val, val, 0);
13943 printf("%s\n", tdb_errorstr(t));
13948 data = tdb_fetch(t, val);
13949 if (data.dptr != NULL) {
13950 SAFE_FREE(data.dptr);
13956 static bool run_local_canonicalize_path(int dummy)
13958 const char *src[] = {
13965 ".././././../../../boo",
13969 const char *dst[] = {
13982 for (i = 0; src[i] != NULL; i++) {
13983 char *d = canonicalize_absolute_path(talloc_tos(), src[i]);
13985 perror("talloc fail\n");
13988 if (strcmp(d, dst[i]) != 0) {
13990 "canonicalize mismatch %s -> %s != %s",
13991 src[i], d, dst[i]);
13999 static bool run_ign_bad_negprot(int dummy)
14001 struct tevent_context *ev;
14002 struct tevent_req *req;
14003 struct smbXcli_conn *conn;
14004 struct sockaddr_storage ss;
14009 printf("starting ignore bad negprot\n");
14011 ok = resolve_name(host, &ss, 0x20, true);
14013 d_fprintf(stderr, "Could not resolve name %s\n", host);
14017 status = open_socket_out(&ss, 445, 10000, &fd);
14018 if (!NT_STATUS_IS_OK(status)) {
14019 d_fprintf(stderr, "open_socket_out failed: %s\n",
14020 nt_errstr(status));
14024 conn = smbXcli_conn_create(talloc_tos(), fd, host, SMB_SIGNING_OFF, 0,
14026 if (conn == NULL) {
14027 d_fprintf(stderr, "smbXcli_conn_create failed\n");
14031 status = smbXcli_negprot(conn, 0, PROTOCOL_CORE, PROTOCOL_CORE);
14032 if (NT_STATUS_IS_OK(status)) {
14033 d_fprintf(stderr, "smbXcli_negprot succeeded!\n");
14037 ev = samba_tevent_context_init(talloc_tos());
14039 d_fprintf(stderr, "samba_tevent_context_init failed\n");
14043 req = smb1cli_session_setup_nt1_send(
14044 ev, ev, conn, 0, getpid(), NULL, 65503, 2, 1, 0, "", "",
14045 data_blob_null, data_blob_null, 0x40,
14046 "Windows 2000 2195", "Windows 2000 5.0");
14048 d_fprintf(stderr, "smb1cli_session_setup_nt1_send failed\n");
14052 ok = tevent_req_poll_ntstatus(req, ev, &status);
14054 d_fprintf(stderr, "tevent_req_poll failed\n");
14058 status = smb1cli_session_setup_nt1_recv(req, NULL, NULL, NULL, NULL,
14060 if (!NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_RESET)) {
14061 d_fprintf(stderr, "smb1cli_session_setup_nt1_recv returned "
14062 "%s, expected NT_STATUS_CONNECTION_RESET\n",
14063 nt_errstr(status));
14069 printf("starting ignore bad negprot\n");
14074 static double create_procs(bool (*fn)(int), bool *result)
14077 volatile pid_t *child_status;
14078 volatile bool *child_status_out;
14081 struct timeval start;
14085 child_status = (volatile pid_t *)anonymous_shared_allocate(sizeof(pid_t)*torture_nprocs);
14086 if (!child_status) {
14087 printf("Failed to setup shared memory\n");
14091 child_status_out = (volatile bool *)anonymous_shared_allocate(sizeof(bool)*torture_nprocs);
14092 if (!child_status_out) {
14093 printf("Failed to setup result status shared memory\n");
14097 for (i = 0; i < torture_nprocs; i++) {
14098 child_status[i] = 0;
14099 child_status_out[i] = True;
14102 start = timeval_current();
14104 for (i=0;i<torture_nprocs;i++) {
14107 pid_t mypid = getpid();
14108 sys_srandom(((int)mypid) ^ ((int)time(NULL)));
14110 slprintf(myname,sizeof(myname),"CLIENT%d", i);
14113 if (torture_open_connection(¤t_cli, i)) break;
14114 if (tries-- == 0) {
14115 printf("pid %d failed to start\n", (int)getpid());
14121 child_status[i] = getpid();
14123 while (child_status[i] && timeval_elapsed(&start) < 5) smb_msleep(2);
14125 child_status_out[i] = fn(i);
14132 for (i=0;i<torture_nprocs;i++) {
14133 if (child_status[i]) synccount++;
14135 if (synccount == torture_nprocs) break;
14137 } while (timeval_elapsed(&start) < 30);
14139 if (synccount != torture_nprocs) {
14140 printf("FAILED TO START %d CLIENTS (started %d)\n", torture_nprocs, synccount);
14142 return timeval_elapsed(&start);
14145 /* start the client load */
14146 start = timeval_current();
14148 for (i=0;i<torture_nprocs;i++) {
14149 child_status[i] = 0;
14152 printf("%d clients started\n", torture_nprocs);
14154 for (i=0;i<torture_nprocs;i++) {
14155 while (waitpid(0, &status, 0) == -1 && errno == EINTR) /* noop */ ;
14160 for (i=0;i<torture_nprocs;i++) {
14161 if (!child_status_out[i]) {
14165 return timeval_elapsed(&start);
14168 #define FLAG_MULTIPROC 1
14174 } torture_ops[] = {
14177 .fn = run_fdpasstest,
14181 .fn = run_locktest1,
14185 .fn = run_locktest2,
14189 .fn = run_locktest3,
14193 .fn = run_locktest4,
14197 .fn = run_locktest5,
14201 .fn = run_locktest6,
14205 .fn = run_locktest7,
14209 .fn = run_locktest8,
14213 .fn = run_locktest9a,
14217 .fn = run_locktest9b,
14221 .fn = run_locktest10,
14225 .fn = run_locktest11,
14229 .fn = run_locktest12,
14233 .fn = run_locktest13,
14237 .fn = run_unlinktest,
14241 .fn = run_browsetest,
14245 .fn = run_attrtest,
14249 .fn = run_trans2test,
14253 .fn = run_maxfidtest,
14254 .flags = FLAG_MULTIPROC,
14259 .flags = FLAG_MULTIPROC,
14262 .name = "RANDOMIPC",
14263 .fn = run_randomipc,
14266 .name = "NEGNOWAIT",
14267 .fn = run_negprot_nowait,
14289 #ifdef HAVE_KERNEL_OPLOCKS_LINUX
14301 .fn = run_dirtest1,
14304 .name = "DIR-CREATETIME",
14305 .fn = run_dir_createtime,
14309 .fn = torture_denytest1,
14313 .fn = torture_denytest2,
14317 .fn = run_tcon_test,
14321 .fn = run_tcon_devtype_test,
14325 .fn = run_readwritetest,
14329 .fn = run_readwritemulti,
14330 .flags = FLAG_MULTIPROC
14334 .fn = run_readwritelarge,
14337 .name = "RW-SIGNING",
14338 .fn = run_readwritelarge_signtest,
14342 .fn = run_opentest,
14346 .fn = run_simple_posix_open_test,
14349 .name = "POSIX-APPEND",
14350 .fn = run_posix_append,
14353 .name = "POSIX-SYMLINK-ACL",
14354 .fn = run_acl_symlink_test,
14357 .name = "POSIX-SYMLINK-EA",
14358 .fn = run_ea_symlink_test,
14361 .name = "POSIX-STREAM-DELETE",
14362 .fn = run_posix_stream_delete,
14365 .name = "POSIX-OFD-LOCK",
14366 .fn = run_posix_ofd_lock_test,
14369 .name = "POSIX-BLOCKING-LOCK",
14370 .fn = run_posix_blocking_lock,
14373 .name = "POSIX-MKDIR",
14374 .fn = run_posix_mkdir_test,
14377 .name = "POSIX-ACL-OPLOCK",
14378 .fn = run_posix_acl_oplock_test,
14381 .name = "POSIX-ACL-SHAREROOT",
14382 .fn = run_posix_acl_shareroot_test,
14385 .name = "WINDOWS-BAD-SYMLINK",
14386 .fn = run_symlink_open_test,
14389 .name = "CASE-INSENSITIVE-CREATE",
14390 .fn = run_case_insensitive_create,
14393 .name = "ASYNC-ECHO",
14394 .fn = run_async_echo,
14397 .name = "UID-REGRESSION-TEST",
14398 .fn = run_uid_regression_test,
14401 .name = "SHORTNAME-TEST",
14402 .fn = run_shortname_test,
14405 .name = "ADDRCHANGE",
14406 .fn = run_addrchange,
14410 .name = "OPENATTR",
14411 .fn = run_openattrtest,
14423 .name = "RENAME-ACCESS",
14424 .fn = run_rename_access,
14427 .name = "OWNER-RIGHTS",
14428 .fn = run_owner_rights,
14432 .fn = run_deletetest,
14435 .name = "DELETE-STREAM",
14436 .fn = run_delete_stream,
14439 .name = "DELETE-PRINT",
14440 .fn = run_delete_print_test,
14443 .name = "WILDDELETE",
14444 .fn = run_wild_deletetest,
14447 .name = "DELETE-LN",
14448 .fn = run_deletetest_ln,
14451 .name = "PROPERTIES",
14452 .fn = run_properties,
14456 .fn = torture_mangle,
14463 .name = "MANGLE-ILLEGAL",
14464 .fn = run_mangle_illegal,
14471 .name = "TRANS2SCAN",
14472 .fn = torture_trans2_scan,
14475 .name = "NTTRANSSCAN",
14476 .fn = torture_nttrans_scan,
14480 .fn = torture_utable,
14483 .name = "CASETABLE",
14484 .fn = torture_casetable,
14487 .name = "ERRMAPEXTRACT",
14488 .fn = run_error_map_extract,
14491 .name = "PIPE_NUMBER",
14492 .fn = run_pipe_number,
14496 .fn = run_tcon2_test,
14500 .fn = torture_ioctl_test,
14504 .fn = torture_chkpath_test,
14508 .fn = run_fdsesstest,
14515 .name = "SESSSETUP_BENCH",
14516 .fn = run_sesssetup_bench,
14531 .name = "WINDOWS-WRITE",
14532 .fn = run_windows_write,
14535 .name = "LARGE_READX",
14536 .fn = run_large_readx,
14539 .name = "NTTRANS-CREATE",
14540 .fn = run_nttrans_create,
14543 .name = "NTTRANS-FSCTL",
14544 .fn = run_nttrans_fsctl,
14547 .name = "CLI_ECHO",
14548 .fn = run_cli_echo,
14551 .name = "CLI_SPLICE",
14552 .fn = run_cli_splice,
14559 .name = "STREAMERROR",
14560 .fn = run_streamerror,
14563 .name = "NOTIFY-BENCH",
14564 .fn = run_notify_bench,
14567 .name = "NOTIFY-BENCH2",
14568 .fn = run_notify_bench2,
14571 .name = "NOTIFY-BENCH3",
14572 .fn = run_notify_bench3,
14575 .name = "BAD-NBT-SESSION",
14576 .fn = run_bad_nbt_session,
14579 .name = "IGN-BAD-NEGPROT",
14580 .fn = run_ign_bad_negprot,
14583 .name = "SMB-ANY-CONNECT",
14584 .fn = run_smb_any_connect,
14587 .name = "NOTIFY-ONLINE",
14588 .fn = run_notify_online,
14591 .name = "SMB2-BASIC",
14592 .fn = run_smb2_basic,
14595 .name = "SMB2-NEGPROT",
14596 .fn = run_smb2_negprot,
14599 .name = "SMB2-ANONYMOUS",
14600 .fn = run_smb2_anonymous,
14603 .name = "SMB2-SESSION-RECONNECT",
14604 .fn = run_smb2_session_reconnect,
14607 .name = "SMB2-TCON-DEPENDENCE",
14608 .fn = run_smb2_tcon_dependence,
14611 .name = "SMB2-MULTI-CHANNEL",
14612 .fn = run_smb2_multi_channel,
14615 .name = "SMB2-SESSION-REAUTH",
14616 .fn = run_smb2_session_reauth,
14619 .name = "SMB2-FTRUNCATE",
14620 .fn = run_smb2_ftruncate,
14623 .name = "SMB2-DIR-FSYNC",
14624 .fn = run_smb2_dir_fsync,
14627 .name = "SMB2-PATH-SLASH",
14628 .fn = run_smb2_path_slash,
14631 .name = "CLEANUP1",
14632 .fn = run_cleanup1,
14635 .name = "CLEANUP2",
14636 .fn = run_cleanup2,
14639 .name = "CLEANUP4",
14640 .fn = run_cleanup4,
14643 .name = "OPLOCK-CANCEL",
14644 .fn = run_oplock_cancel,
14651 .name = "LOCAL-SUBSTITUTE",
14652 .fn = run_local_substitute,
14655 .name = "LOCAL-GENCACHE",
14656 .fn = run_local_gencache,
14659 .name = "LOCAL-DBWRAP-WATCH1",
14660 .fn = run_dbwrap_watch1,
14663 .name = "LOCAL-DBWRAP-WATCH2",
14664 .fn = run_dbwrap_watch2,
14667 .name = "LOCAL-DBWRAP-DO-LOCKED1",
14668 .fn = run_dbwrap_do_locked1,
14671 .name = "LOCAL-MESSAGING-READ1",
14672 .fn = run_messaging_read1,
14675 .name = "LOCAL-MESSAGING-READ2",
14676 .fn = run_messaging_read2,
14679 .name = "LOCAL-MESSAGING-READ3",
14680 .fn = run_messaging_read3,
14683 .name = "LOCAL-MESSAGING-READ4",
14684 .fn = run_messaging_read4,
14687 .name = "LOCAL-MESSAGING-FDPASS1",
14688 .fn = run_messaging_fdpass1,
14691 .name = "LOCAL-MESSAGING-FDPASS2",
14692 .fn = run_messaging_fdpass2,
14695 .name = "LOCAL-MESSAGING-FDPASS2a",
14696 .fn = run_messaging_fdpass2a,
14699 .name = "LOCAL-MESSAGING-FDPASS2b",
14700 .fn = run_messaging_fdpass2b,
14703 .name = "LOCAL-MESSAGING-SEND-ALL",
14704 .fn = run_messaging_send_all,
14707 .name = "LOCAL-BASE64",
14708 .fn = run_local_base64,
14711 .name = "LOCAL-RBTREE",
14712 .fn = run_local_rbtree,
14715 .name = "LOCAL-MEMCACHE",
14716 .fn = run_local_memcache,
14719 .name = "LOCAL-STREAM-NAME",
14720 .fn = run_local_stream_name,
14723 .name = "WBCLIENT-MULTI-PING",
14724 .fn = run_wbclient_multi_ping,
14727 .name = "LOCAL-string_to_sid",
14728 .fn = run_local_string_to_sid,
14731 .name = "LOCAL-sid_to_string",
14732 .fn = run_local_sid_to_string,
14735 .name = "LOCAL-binary_to_sid",
14736 .fn = run_local_binary_to_sid,
14739 .name = "LOCAL-DBTRANS",
14740 .fn = run_local_dbtrans,
14743 .name = "LOCAL-TEVENT-POLL",
14744 .fn = run_local_tevent_poll,
14747 .name = "LOCAL-CONVERT-STRING",
14748 .fn = run_local_convert_string,
14751 .name = "LOCAL-CONV-AUTH-INFO",
14752 .fn = run_local_conv_auth_info,
14755 .name = "LOCAL-hex_encode_buf",
14756 .fn = run_local_hex_encode_buf,
14759 .name = "LOCAL-IDMAP-TDB-COMMON",
14760 .fn = run_idmap_tdb_common_test,
14763 .name = "LOCAL-remove_duplicate_addrs2",
14764 .fn = run_local_remove_duplicate_addrs2,
14767 .name = "local-tdb-opener",
14768 .fn = run_local_tdb_opener,
14771 .name = "local-tdb-writer",
14772 .fn = run_local_tdb_writer,
14775 .name = "LOCAL-DBWRAP-CTDB",
14776 .fn = run_local_dbwrap_ctdb,
14779 .name = "LOCAL-BENCH-PTHREADPOOL",
14780 .fn = run_bench_pthreadpool,
14783 .name = "LOCAL-PTHREADPOOL-TEVENT",
14784 .fn = run_pthreadpool_tevent,
14787 .name = "LOCAL-G-LOCK1",
14791 .name = "LOCAL-G-LOCK2",
14795 .name = "LOCAL-G-LOCK3",
14799 .name = "LOCAL-G-LOCK4",
14803 .name = "LOCAL-G-LOCK5",
14807 .name = "LOCAL-G-LOCK6",
14811 .name = "LOCAL-G-LOCK-PING-PONG",
14812 .fn = run_g_lock_ping_pong,
14815 .name = "LOCAL-CANONICALIZE-PATH",
14816 .fn = run_local_canonicalize_path,
14819 .name = "LOCAL-NAMEMAP-CACHE1",
14820 .fn = run_local_namemap_cache1,
14823 .name = "LOCAL-IDMAP-CACHE1",
14824 .fn = run_local_idmap_cache1,
14827 .name = "qpathinfo-bufsize",
14828 .fn = run_qpathinfo_bufsize,
14831 .name = "hide-new-files-timeout",
14832 .fn = run_hidenewfiles,
14839 /****************************************************************************
14840 run a specified test or "ALL"
14841 ****************************************************************************/
14842 static bool run_test(const char *name)
14845 bool result = True;
14846 bool found = False;
14849 if (strequal(name,"ALL")) {
14850 for (i=0;torture_ops[i].name;i++) {
14851 run_test(torture_ops[i].name);
14856 for (i=0;torture_ops[i].name;i++) {
14857 fstr_sprintf(randomfname, "\\XX%x",
14858 (unsigned)random());
14860 if (strequal(name, torture_ops[i].name)) {
14862 printf("Running %s\n", name);
14863 if (torture_ops[i].flags & FLAG_MULTIPROC) {
14864 t = create_procs(torture_ops[i].fn, &result);
14867 printf("TEST %s FAILED!\n", name);
14870 struct timeval start;
14871 start = timeval_current();
14872 if (!torture_ops[i].fn(0)) {
14874 printf("TEST %s FAILED!\n", name);
14876 t = timeval_elapsed(&start);
14878 printf("%s took %g secs\n\n", name, t);
14883 printf("Did not find a test named %s\n", name);
14891 static void usage(void)
14895 printf("WARNING samba4 test suite is much more complete nowadays.\n");
14896 printf("Please use samba4 torture.\n\n");
14898 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
14900 printf("\t-d debuglevel\n");
14901 printf("\t-U user%%pass\n");
14902 printf("\t-k use kerberos\n");
14903 printf("\t-N numprocs\n");
14904 printf("\t-n my_netbios_name\n");
14905 printf("\t-W workgroup\n");
14906 printf("\t-o num_operations\n");
14907 printf("\t-O socket_options\n");
14908 printf("\t-m maximum protocol\n");
14909 printf("\t-L use oplocks\n");
14910 printf("\t-c CLIENT.TXT specify client load file for NBENCH\n");
14911 printf("\t-A showall\n");
14912 printf("\t-p port\n");
14913 printf("\t-s seed\n");
14914 printf("\t-b unclist_filename specify multiple shares for multiple connections\n");
14915 printf("\t-f filename filename to test\n");
14916 printf("\t-e encrypt\n");
14919 printf("tests are:");
14920 for (i=0;torture_ops[i].name;i++) {
14921 printf(" %s", torture_ops[i].name);
14925 printf("default test is ALL\n");
14930 /****************************************************************************
14932 ****************************************************************************/
14933 int main(int argc,char *argv[])
14939 bool correct = True;
14940 TALLOC_CTX *frame = talloc_stackframe();
14941 int seed = time(NULL);
14943 #ifdef HAVE_SETBUFFER
14944 setbuffer(stdout, NULL, 0);
14947 setup_logging("smbtorture", DEBUG_STDOUT);
14952 if (is_default_dyn_CONFIGFILE()) {
14953 if(getenv("SMB_CONF_PATH")) {
14954 set_dyn_CONFIGFILE(getenv("SMB_CONF_PATH"));
14957 lp_load_global(get_dyn_CONFIGFILE());
14964 for(p = argv[1]; *p; p++)
14968 if (strncmp(argv[1], "//", 2)) {
14972 fstrcpy(host, &argv[1][2]);
14973 p = strchr_m(&host[2],'/');
14978 fstrcpy(share, p+1);
14980 fstrcpy(myname, get_myname(talloc_tos()));
14982 fprintf(stderr, "Failed to get my hostname.\n");
14986 if (*username == 0 && getenv("LOGNAME")) {
14987 fstrcpy(username,getenv("LOGNAME"));
14993 fstrcpy(workgroup, lp_workgroup());
14995 while ((opt = getopt(argc, argv, "p:hW:U:n:N:O:o:m:Ll:d:Aec:ks:b:B:f:"))
14999 port_to_use = atoi(optarg);
15002 seed = atoi(optarg);
15005 fstrcpy(workgroup,optarg);
15008 lp_set_cmdline("client max protocol", optarg);
15011 torture_nprocs = atoi(optarg);
15014 torture_numops = atoi(optarg);
15017 lp_set_cmdline("log level", optarg);
15023 use_oplocks = True;
15026 local_path = optarg;
15029 torture_showall = True;
15032 fstrcpy(myname, optarg);
15035 client_txt = optarg;
15042 use_kerberos = True;
15044 d_printf("No kerberos support compiled in\n");
15050 fstrcpy(username,optarg);
15051 p = strchr_m(username,'%');
15054 fstrcpy(password, p+1);
15059 fstrcpy(multishare_conn_fname, optarg);
15060 use_multishare_conn = True;
15063 torture_blocksize = atoi(optarg);
15066 test_filename = SMB_STRDUP(optarg);
15069 printf("Unknown option %c (%d)\n", (char)opt, opt);
15074 d_printf("using seed %d\n", seed);
15078 if(use_kerberos && !gotuser) gotpass = True;
15081 char pwd[256] = {0};
15084 rc = samba_getpass("Password:", pwd, sizeof(pwd), false, false);
15086 fstrcpy(password, pwd);
15091 printf("host=%s share=%s user=%s myname=%s\n",
15092 host, share, username, myname);
15094 torture_creds = cli_session_creds_init(frame,
15100 false, /* fallback_after_kerberos */
15101 false, /* use_ccache */
15102 false); /* password_is_nt_hash */
15103 if (torture_creds == NULL) {
15104 d_printf("cli_session_creds_init() failed.\n");
15108 if (argc == optind) {
15109 correct = run_test("ALL");
15111 for (i=optind;i<argc;i++) {
15112 if (!run_test(argv[i])) {
15118 TALLOC_FREE(frame);