2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1997-1998
5 Copyright (C) Jeremy Allison 2009
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "system/shmem.h"
23 #include "wbc_async.h"
24 #include "torture/proto.h"
25 #include "libcli/security/security.h"
27 #include "tldap_util.h"
28 #include "../librpc/gen_ndr/svcctl.h"
29 #include "../lib/util/memcache.h"
30 #include "nsswitch/winbind_client.h"
31 #include "dbwrap/dbwrap.h"
32 #include "dbwrap/dbwrap_open.h"
33 #include "dbwrap/dbwrap_rbt.h"
34 #include "talloc_dict.h"
35 #include "async_smb.h"
36 #include "libsmb/libsmb.h"
37 #include "libsmb/clirap.h"
39 #include "libsmb/nmblib.h"
40 #include "../lib/util/tevent_ntstatus.h"
42 #include "../libcli/smb/read_smb.h"
43 #include "../libcli/smb/smbXcli_base.h"
44 #include "lib/util/sys_rw_data.h"
45 #include "lib/util/base64.h"
50 fstring host, workgroup, share, password, username, myname;
51 struct cli_credentials *torture_creds;
52 static const char *sockops="TCP_NODELAY";
54 static int port_to_use=0;
55 int torture_numops=100;
56 int torture_blocksize=1024*1024;
57 static int procnum; /* records process count number when forking */
58 static struct cli_state *current_cli;
59 static fstring randomfname;
60 static bool use_oplocks;
61 static bool use_level_II_oplocks;
62 static const char *client_txt = "client_oplocks.txt";
63 static bool disable_spnego;
64 static bool use_kerberos;
65 static bool force_dos_errors;
66 static fstring multishare_conn_fname;
67 static bool use_multishare_conn = False;
68 static bool do_encrypt;
69 static const char *local_path = NULL;
70 static enum smb_signing_setting signing_state = SMB_SIGNING_DEFAULT;
73 bool torture_showall = False;
75 static double create_procs(bool (*fn)(int), bool *result);
77 /********************************************************************
78 Ensure a connection is encrypted.
79 ********************************************************************/
81 static bool force_cli_encryption(struct cli_state *c,
82 const char *sharename)
84 uint16_t major, minor;
85 uint32_t caplow, caphigh;
88 if (!SERVER_HAS_UNIX_CIFS(c)) {
89 d_printf("Encryption required and "
90 "server that doesn't support "
91 "UNIX extensions - failing connect\n");
95 status = cli_unix_extensions_version(c, &major, &minor, &caplow,
97 if (!NT_STATUS_IS_OK(status)) {
98 d_printf("Encryption required and "
99 "can't get UNIX CIFS extensions "
100 "version from server: %s\n", nt_errstr(status));
104 if (!(caplow & CIFS_UNIX_TRANSPORT_ENCRYPTION_CAP)) {
105 d_printf("Encryption required and "
106 "share %s doesn't support "
107 "encryption.\n", sharename);
111 status = cli_smb1_setup_encryption(c, torture_creds);
112 if (!NT_STATUS_IS_OK(status)) {
113 d_printf("Encryption required and "
114 "setup failed with error %s.\n",
123 static struct cli_state *open_nbt_connection(void)
129 if (disable_spnego) {
130 flags |= CLI_FULL_CONNECTION_DONT_SPNEGO;
134 flags |= CLI_FULL_CONNECTION_OPLOCKS;
137 if (use_level_II_oplocks) {
138 flags |= CLI_FULL_CONNECTION_LEVEL_II_OPLOCKS;
142 flags |= CLI_FULL_CONNECTION_USE_KERBEROS;
145 if (force_dos_errors) {
146 flags |= CLI_FULL_CONNECTION_FORCE_DOS_ERRORS;
149 status = cli_connect_nb(host, NULL, port_to_use, 0x20, myname,
150 signing_state, flags, &c);
151 if (!NT_STATUS_IS_OK(status)) {
152 printf("Failed to connect with %s. Error %s\n", host, nt_errstr(status) );
156 cli_set_timeout(c, 120000); /* set a really long timeout (2 minutes) */
161 /****************************************************************************
162 Send a corrupt session request. See rfc1002.txt 4.3 and 4.3.2.
163 ****************************************************************************/
165 static bool cli_bad_session_request(int fd,
166 struct nmb_name *calling, struct nmb_name *called)
175 uint8_t message_type;
177 struct tevent_context *ev;
178 struct tevent_req *req;
180 frame = talloc_stackframe();
182 iov[0].iov_base = len_buf;
183 iov[0].iov_len = sizeof(len_buf);
185 /* put in the destination name */
187 iov[1].iov_base = name_mangle(talloc_tos(), called->name,
189 if (iov[1].iov_base == NULL) {
192 iov[1].iov_len = name_len((unsigned char *)iov[1].iov_base,
193 talloc_get_size(iov[1].iov_base));
197 iov[2].iov_base = name_mangle(talloc_tos(), calling->name,
199 if (iov[2].iov_base == NULL) {
202 iov[2].iov_len = name_len((unsigned char *)iov[2].iov_base,
203 talloc_get_size(iov[2].iov_base));
205 /* Deliberately corrupt the name len (first byte) */
206 *((uint8_t *)iov[2].iov_base) = 100;
208 /* send a session request (RFC 1002) */
209 /* setup the packet length
210 * Remove four bytes from the length count, since the length
211 * field in the NBT Session Service header counts the number
212 * of bytes which follow. The cli_send_smb() function knows
213 * about this and accounts for those four bytes.
217 _smb_setlen(len_buf, iov[1].iov_len + iov[2].iov_len);
218 SCVAL(len_buf,0,0x81);
220 len = write_data_iov(fd, iov, 3);
225 ev = samba_tevent_context_init(frame);
229 req = read_smb_send(frame, ev, fd);
233 if (!tevent_req_poll(req, ev)) {
236 len = read_smb_recv(req, talloc_tos(), &inbuf, &err);
243 message_type = CVAL(inbuf, 0);
244 if (message_type != 0x83) {
245 d_fprintf(stderr, "Expected msg type 0x83, got 0x%2.2x\n",
250 if (smb_len(inbuf) != 1) {
251 d_fprintf(stderr, "Expected smb_len 1, got %d\n",
252 (int)smb_len(inbuf));
256 error = CVAL(inbuf, 4);
258 d_fprintf(stderr, "Expected error 0x82, got %d\n",
269 /* Insert a NULL at the first separator of the given path and return a pointer
270 * to the remainder of the string.
273 terminate_path_at_separator(char * path)
281 if ((p = strchr_m(path, '/'))) {
286 if ((p = strchr_m(path, '\\'))) {
296 parse a //server/share type UNC name
298 bool smbcli_parse_unc(const char *unc_name, TALLOC_CTX *mem_ctx,
299 char **hostname, char **sharename)
303 *hostname = *sharename = NULL;
305 if (strncmp(unc_name, "\\\\", 2) &&
306 strncmp(unc_name, "//", 2)) {
310 *hostname = talloc_strdup(mem_ctx, &unc_name[2]);
311 p = terminate_path_at_separator(*hostname);
314 *sharename = talloc_strdup(mem_ctx, p);
315 terminate_path_at_separator(*sharename);
318 if (*hostname && *sharename) {
322 TALLOC_FREE(*hostname);
323 TALLOC_FREE(*sharename);
327 static bool torture_open_connection_share(struct cli_state **c,
328 const char *hostname,
329 const char *sharename,
334 status = cli_full_connection_creds(c,
344 if (!NT_STATUS_IS_OK(status)) {
345 printf("failed to open share connection: //%s/%s port:%d - %s\n",
346 hostname, sharename, port_to_use, nt_errstr(status));
350 cli_set_timeout(*c, 120000); /* set a really long timeout (2 minutes) */
353 return force_cli_encryption(*c,
359 bool torture_open_connection(struct cli_state **c, int conn_index)
361 char **unc_list = NULL;
362 int num_unc_names = 0;
364 int flags = CLI_FULL_CONNECTION_FORCE_SMB1;
367 flags |= CLI_FULL_CONNECTION_OPLOCKS;
369 if (use_level_II_oplocks) {
370 flags |= CLI_FULL_CONNECTION_LEVEL_II_OPLOCKS;
373 if (use_multishare_conn==True) {
375 unc_list = file_lines_load(multishare_conn_fname, &num_unc_names, 0, NULL);
376 if (!unc_list || num_unc_names <= 0) {
377 printf("Failed to load unc names list from '%s'\n", multishare_conn_fname);
381 if (!smbcli_parse_unc(unc_list[conn_index % num_unc_names],
383 printf("Failed to parse UNC name %s\n",
384 unc_list[conn_index % num_unc_names]);
385 TALLOC_FREE(unc_list);
389 result = torture_open_connection_share(c, h, s, flags);
391 /* h, s were copied earlier */
392 TALLOC_FREE(unc_list);
396 return torture_open_connection_share(c, host, share, flags);
399 bool torture_init_connection(struct cli_state **pcli)
401 struct cli_state *cli;
403 cli = open_nbt_connection();
412 bool torture_cli_session_setup2(struct cli_state *cli, uint16_t *new_vuid)
414 uint16_t old_vuid = cli_state_get_uid(cli);
418 cli_state_set_uid(cli, 0);
419 status = cli_session_setup_creds(cli, torture_creds);
420 ret = NT_STATUS_IS_OK(status);
421 *new_vuid = cli_state_get_uid(cli);
422 cli_state_set_uid(cli, old_vuid);
427 bool torture_close_connection(struct cli_state *c)
432 status = cli_tdis(c);
433 if (!NT_STATUS_IS_OK(status)) {
434 printf("tdis failed (%s)\n", nt_errstr(status));
444 /* check if the server produced the expected dos or nt error code */
445 static bool check_both_error(int line, NTSTATUS status,
446 uint8_t eclass, uint32_t ecode, NTSTATUS nterr)
448 if (NT_STATUS_IS_DOS(status)) {
452 /* Check DOS error */
453 cclass = NT_STATUS_DOS_CLASS(status);
454 num = NT_STATUS_DOS_CODE(status);
456 if (eclass != cclass || ecode != num) {
457 printf("unexpected error code class=%d code=%d\n",
458 (int)cclass, (int)num);
459 printf(" expected %d/%d %s (line=%d)\n",
460 (int)eclass, (int)ecode, nt_errstr(nterr), line);
465 if (!NT_STATUS_EQUAL(nterr, status)) {
466 printf("unexpected error code %s\n",
468 printf(" expected %s (line=%d)\n",
469 nt_errstr(nterr), line);
478 /* check if the server produced the expected error code */
479 static bool check_error(int line, NTSTATUS status,
480 uint8_t eclass, uint32_t ecode, NTSTATUS nterr)
482 if (NT_STATUS_IS_DOS(status)) {
486 /* Check DOS error */
488 cclass = NT_STATUS_DOS_CLASS(status);
489 num = NT_STATUS_DOS_CODE(status);
491 if (eclass != cclass || ecode != num) {
492 printf("unexpected error code class=%d code=%d\n",
493 (int)cclass, (int)num);
494 printf(" expected %d/%d %s (line=%d)\n",
495 (int)eclass, (int)ecode, nt_errstr(nterr),
503 if (NT_STATUS_V(nterr) != NT_STATUS_V(status)) {
504 printf("unexpected error code %s\n",
506 printf(" expected %s (line=%d)\n", nt_errstr(nterr),
516 static bool wait_lock(struct cli_state *c, int fnum, uint32_t offset, uint32_t len)
520 status = cli_lock32(c, fnum, offset, len, -1, WRITE_LOCK);
522 while (!NT_STATUS_IS_OK(status)) {
523 if (!check_both_error(__LINE__, status, ERRDOS,
524 ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) {
528 status = cli_lock32(c, fnum, offset, len, -1, WRITE_LOCK);
535 static bool rw_torture(struct cli_state *c)
537 const char *lockfname = "\\torture.lck";
541 pid_t pid2, pid = getpid();
548 memset(buf, '\0', sizeof(buf));
550 status = cli_openx(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
552 if (!NT_STATUS_IS_OK(status)) {
553 status = cli_openx(c, lockfname, O_RDWR, DENY_NONE, &fnum2);
555 if (!NT_STATUS_IS_OK(status)) {
556 printf("open of %s failed (%s)\n",
557 lockfname, nt_errstr(status));
561 for (i=0;i<torture_numops;i++) {
562 unsigned n = (unsigned)sys_random()%10;
565 printf("%d\r", i); fflush(stdout);
567 slprintf(fname, sizeof(fstring) - 1, "\\torture.%u", n);
569 if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) {
573 status = cli_openx(c, fname, O_RDWR | O_CREAT | O_TRUNC,
575 if (!NT_STATUS_IS_OK(status)) {
576 printf("open failed (%s)\n", nt_errstr(status));
581 status = cli_writeall(c, fnum, 0, (uint8_t *)&pid, 0,
583 if (!NT_STATUS_IS_OK(status)) {
584 printf("write failed (%s)\n", nt_errstr(status));
589 status = cli_writeall(c, fnum, 0, (uint8_t *)buf,
590 sizeof(pid)+(j*sizeof(buf)),
592 if (!NT_STATUS_IS_OK(status)) {
593 printf("write failed (%s)\n",
601 status = cli_read(c, fnum, (char *)&pid2, 0, sizeof(pid),
603 if (!NT_STATUS_IS_OK(status)) {
604 printf("read failed (%s)\n", nt_errstr(status));
606 } else if (nread != sizeof(pid)) {
607 printf("read/write compare failed: "
608 "recv %ld req %ld\n", (unsigned long)nread,
609 (unsigned long)sizeof(pid));
614 printf("data corruption!\n");
618 status = cli_close(c, fnum);
619 if (!NT_STATUS_IS_OK(status)) {
620 printf("close failed (%s)\n", nt_errstr(status));
624 status = cli_unlink(c, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
625 if (!NT_STATUS_IS_OK(status)) {
626 printf("unlink failed (%s)\n", nt_errstr(status));
630 status = cli_unlock(c, fnum2, n*sizeof(int), sizeof(int));
631 if (!NT_STATUS_IS_OK(status)) {
632 printf("unlock failed (%s)\n", nt_errstr(status));
638 cli_unlink(c, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
645 static bool run_torture(int dummy)
647 struct cli_state *cli;
652 smbXcli_conn_set_sockopt(cli->conn, sockops);
654 ret = rw_torture(cli);
656 if (!torture_close_connection(cli)) {
663 static bool rw_torture3(struct cli_state *c, char *lockfname)
665 uint16_t fnum = (uint16_t)-1;
670 unsigned countprev = 0;
673 NTSTATUS status = NT_STATUS_OK;
676 for (i = 0; i < sizeof(buf); i += sizeof(uint32_t))
678 SIVAL(buf, i, sys_random());
685 FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
686 if (!NT_STATUS_IS_OK(status)) {
687 printf("unlink failed (%s) (normal, this file should "
688 "not exist)\n", nt_errstr(status));
691 status = cli_openx(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
693 if (!NT_STATUS_IS_OK(status)) {
694 printf("first open read/write of %s failed (%s)\n",
695 lockfname, nt_errstr(status));
701 for (i = 0; i < 500 && fnum == (uint16_t)-1; i++)
703 status = cli_openx(c, lockfname, O_RDONLY,
705 if (NT_STATUS_IS_OK(status)) {
710 if (!NT_STATUS_IS_OK(status)) {
711 printf("second open read-only of %s failed (%s)\n",
712 lockfname, nt_errstr(status));
718 for (count = 0; count < sizeof(buf); count += sent)
720 if (count >= countprev) {
721 printf("%d %8d\r", i, count);
724 countprev += (sizeof(buf) / 20);
729 sent = ((unsigned)sys_random()%(20))+ 1;
730 if (sent > sizeof(buf) - count)
732 sent = sizeof(buf) - count;
735 status = cli_writeall(c, fnum, 0, (uint8_t *)buf+count,
737 if (!NT_STATUS_IS_OK(status)) {
738 printf("write failed (%s)\n",
745 status = cli_read(c, fnum, buf_rd+count, count,
746 sizeof(buf)-count, &sent);
747 if(!NT_STATUS_IS_OK(status)) {
748 printf("read failed offset:%d size:%ld (%s)\n",
749 count, (unsigned long)sizeof(buf)-count,
753 } else if (sent > 0) {
754 if (memcmp(buf_rd+count, buf+count, sent) != 0)
756 printf("read/write compare failed\n");
757 printf("offset: %d req %ld recvd %ld\n", count, (unsigned long)sizeof(buf)-count, (unsigned long)sent);
766 status = cli_close(c, fnum);
767 if (!NT_STATUS_IS_OK(status)) {
768 printf("close failed (%s)\n", nt_errstr(status));
775 static bool rw_torture2(struct cli_state *c1, struct cli_state *c2)
777 const char *lockfname = "\\torture2.lck";
787 status = cli_unlink(c1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
788 if (!NT_STATUS_IS_OK(status)) {
789 printf("unlink failed (%s) (normal, this file should not exist)\n", nt_errstr(status));
792 status = cli_openx(c1, lockfname, O_RDWR | O_CREAT | O_EXCL,
794 if (!NT_STATUS_IS_OK(status)) {
795 printf("first open read/write of %s failed (%s)\n",
796 lockfname, nt_errstr(status));
800 status = cli_openx(c2, lockfname, O_RDONLY, DENY_NONE, &fnum2);
801 if (!NT_STATUS_IS_OK(status)) {
802 printf("second open read-only of %s failed (%s)\n",
803 lockfname, nt_errstr(status));
804 cli_close(c1, fnum1);
808 for (i = 0; i < torture_numops; i++)
810 size_t buf_size = ((unsigned)sys_random()%(sizeof(buf)-1))+ 1;
812 printf("%d\r", i); fflush(stdout);
815 generate_random_buffer((unsigned char *)buf, buf_size);
817 status = cli_writeall(c1, fnum1, 0, (uint8_t *)buf, 0,
819 if (!NT_STATUS_IS_OK(status)) {
820 printf("write failed (%s)\n", nt_errstr(status));
825 status = cli_read(c2, fnum2, buf_rd, 0, buf_size, &bytes_read);
826 if(!NT_STATUS_IS_OK(status)) {
827 printf("read failed (%s)\n", nt_errstr(status));
830 } else if (bytes_read != buf_size) {
831 printf("read failed\n");
832 printf("read %ld, expected %ld\n",
833 (unsigned long)bytes_read,
834 (unsigned long)buf_size);
839 if (memcmp(buf_rd, buf, buf_size) != 0)
841 printf("read/write compare failed\n");
847 status = cli_close(c2, fnum2);
848 if (!NT_STATUS_IS_OK(status)) {
849 printf("close failed (%s)\n", nt_errstr(status));
853 status = cli_close(c1, fnum1);
854 if (!NT_STATUS_IS_OK(status)) {
855 printf("close failed (%s)\n", nt_errstr(status));
859 status = cli_unlink(c1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
860 if (!NT_STATUS_IS_OK(status)) {
861 printf("unlink failed (%s)\n", nt_errstr(status));
868 static bool run_readwritetest(int dummy)
870 struct cli_state *cli1, *cli2;
871 bool test1, test2 = False;
873 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
876 smbXcli_conn_set_sockopt(cli1->conn, sockops);
877 smbXcli_conn_set_sockopt(cli2->conn, sockops);
879 printf("starting readwritetest\n");
881 test1 = rw_torture2(cli1, cli2);
882 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1));
885 test2 = rw_torture2(cli1, cli1);
886 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2));
889 if (!torture_close_connection(cli1)) {
893 if (!torture_close_connection(cli2)) {
897 return (test1 && test2);
900 static bool run_readwritemulti(int dummy)
902 struct cli_state *cli;
907 smbXcli_conn_set_sockopt(cli->conn, sockops);
909 printf("run_readwritemulti: fname %s\n", randomfname);
910 test = rw_torture3(cli, randomfname);
912 if (!torture_close_connection(cli)) {
919 static bool run_readwritelarge_internal(void)
921 static struct cli_state *cli1;
923 const char *lockfname = "\\large.dat";
929 if (!torture_open_connection(&cli1, 0)) {
932 smbXcli_conn_set_sockopt(cli1->conn, sockops);
933 memset(buf,'\0',sizeof(buf));
935 printf("starting readwritelarge_internal\n");
937 cli_unlink(cli1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
939 status = cli_openx(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL,
941 if (!NT_STATUS_IS_OK(status)) {
942 printf("open read/write of %s failed (%s)\n", lockfname, nt_errstr(status));
946 cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 0, sizeof(buf), NULL);
948 status = cli_qfileinfo_basic(cli1, fnum1, NULL, &fsize, NULL, NULL,
950 if (!NT_STATUS_IS_OK(status)) {
951 printf("qfileinfo failed (%s)\n", nt_errstr(status));
955 if (fsize == sizeof(buf))
956 printf("readwritelarge_internal test 1 succeeded (size = %lx)\n",
957 (unsigned long)fsize);
959 printf("readwritelarge_internal test 1 failed (size = %lx)\n",
960 (unsigned long)fsize);
964 status = cli_close(cli1, fnum1);
965 if (!NT_STATUS_IS_OK(status)) {
966 printf("close failed (%s)\n", nt_errstr(status));
970 status = cli_unlink(cli1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
971 if (!NT_STATUS_IS_OK(status)) {
972 printf("unlink failed (%s)\n", nt_errstr(status));
976 status = cli_openx(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL,
978 if (!NT_STATUS_IS_OK(status)) {
979 printf("open read/write of %s failed (%s)\n", lockfname, nt_errstr(status));
983 cli_smbwrite(cli1, fnum1, buf, 0, sizeof(buf), NULL);
985 status = cli_qfileinfo_basic(cli1, fnum1, NULL, &fsize, NULL, NULL,
987 if (!NT_STATUS_IS_OK(status)) {
988 printf("qfileinfo failed (%s)\n", nt_errstr(status));
992 if (fsize == sizeof(buf))
993 printf("readwritelarge_internal test 2 succeeded (size = %lx)\n",
994 (unsigned long)fsize);
996 printf("readwritelarge_internal test 2 failed (size = %lx)\n",
997 (unsigned long)fsize);
1002 /* ToDo - set allocation. JRA */
1003 if(!cli_set_allocation_size(cli1, fnum1, 0)) {
1004 printf("set allocation size to zero failed (%s)\n", cli_errstr(&cli1));
1007 if (!cli_qfileinfo_basic(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL,
1009 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
1013 printf("readwritelarge test 3 (truncate test) succeeded (size = %x)\n", fsize);
1016 status = cli_close(cli1, fnum1);
1017 if (!NT_STATUS_IS_OK(status)) {
1018 printf("close failed (%s)\n", nt_errstr(status));
1022 if (!torture_close_connection(cli1)) {
1028 static bool run_readwritelarge(int dummy)
1030 return run_readwritelarge_internal();
1033 static bool run_readwritelarge_signtest(int dummy)
1036 signing_state = SMB_SIGNING_REQUIRED;
1037 ret = run_readwritelarge_internal();
1038 signing_state = SMB_SIGNING_DEFAULT;
1045 #define ival(s) strtol(s, NULL, 0)
1047 /* run a test that simulates an approximate netbench client load */
1048 static bool run_netbench(int client)
1050 struct cli_state *cli;
1055 const char *params[20];
1056 bool correct = True;
1062 smbXcli_conn_set_sockopt(cli->conn, sockops);
1066 slprintf(cname,sizeof(cname)-1, "client%d", client);
1068 f = fopen(client_txt, "r");
1075 while (fgets(line, sizeof(line)-1, f)) {
1079 line[strlen(line)-1] = 0;
1081 /* printf("[%d] %s\n", line_count, line); */
1083 all_string_sub(line,"client1", cname, sizeof(line));
1085 /* parse the command parameters */
1086 params[0] = strtok_r(line, " ", &saveptr);
1088 while (params[i]) params[++i] = strtok_r(NULL, " ", &saveptr);
1092 if (i < 2) continue;
1094 if (!strncmp(params[0],"SMB", 3)) {
1095 printf("ERROR: You are using a dbench 1 load file\n");
1099 if (!strcmp(params[0],"NTCreateX")) {
1100 nb_createx(params[1], ival(params[2]), ival(params[3]),
1102 } else if (!strcmp(params[0],"Close")) {
1103 nb_close(ival(params[1]));
1104 } else if (!strcmp(params[0],"Rename")) {
1105 nb_rename(params[1], params[2]);
1106 } else if (!strcmp(params[0],"Unlink")) {
1107 nb_unlink(params[1]);
1108 } else if (!strcmp(params[0],"Deltree")) {
1109 nb_deltree(params[1]);
1110 } else if (!strcmp(params[0],"Rmdir")) {
1111 nb_rmdir(params[1]);
1112 } else if (!strcmp(params[0],"QUERY_PATH_INFORMATION")) {
1113 nb_qpathinfo(params[1]);
1114 } else if (!strcmp(params[0],"QUERY_FILE_INFORMATION")) {
1115 nb_qfileinfo(ival(params[1]));
1116 } else if (!strcmp(params[0],"QUERY_FS_INFORMATION")) {
1117 nb_qfsinfo(ival(params[1]));
1118 } else if (!strcmp(params[0],"FIND_FIRST")) {
1119 nb_findfirst(params[1]);
1120 } else if (!strcmp(params[0],"WriteX")) {
1121 nb_writex(ival(params[1]),
1122 ival(params[2]), ival(params[3]), ival(params[4]));
1123 } else if (!strcmp(params[0],"ReadX")) {
1124 nb_readx(ival(params[1]),
1125 ival(params[2]), ival(params[3]), ival(params[4]));
1126 } else if (!strcmp(params[0],"Flush")) {
1127 nb_flush(ival(params[1]));
1129 printf("Unknown operation %s\n", params[0]);
1137 if (!torture_close_connection(cli)) {
1145 /* run a test that simulates an approximate netbench client load */
1146 static bool run_nbench(int dummy)
1149 bool correct = True;
1151 nbio_shmem(torture_nprocs);
1155 signal(SIGALRM, nb_alarm);
1157 t = create_procs(run_netbench, &correct);
1160 printf("\nThroughput %g MB/sec\n",
1161 1.0e-6 * nbio_total() / t);
1167 This test checks for two things:
1169 1) correct support for retaining locks over a close (ie. the server
1170 must not use posix semantics)
1171 2) support for lock timeouts
1173 static bool run_locktest1(int dummy)
1175 struct cli_state *cli1, *cli2;
1176 const char *fname = "\\lockt1.lck";
1177 uint16_t fnum1, fnum2, fnum3;
1179 unsigned lock_timeout;
1182 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1185 smbXcli_conn_set_sockopt(cli1->conn, sockops);
1186 smbXcli_conn_set_sockopt(cli2->conn, sockops);
1188 printf("starting locktest1\n");
1190 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1192 status = cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
1194 if (!NT_STATUS_IS_OK(status)) {
1195 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
1199 status = cli_openx(cli1, fname, O_RDWR, DENY_NONE, &fnum2);
1200 if (!NT_STATUS_IS_OK(status)) {
1201 printf("open2 of %s failed (%s)\n", fname, nt_errstr(status));
1205 status = cli_openx(cli2, fname, O_RDWR, DENY_NONE, &fnum3);
1206 if (!NT_STATUS_IS_OK(status)) {
1207 printf("open3 of %s failed (%s)\n", fname, nt_errstr(status));
1211 status = cli_lock32(cli1, fnum1, 0, 4, 0, WRITE_LOCK);
1212 if (!NT_STATUS_IS_OK(status)) {
1213 printf("lock1 failed (%s)\n", nt_errstr(status));
1217 status = cli_lock32(cli2, fnum3, 0, 4, 0, WRITE_LOCK);
1218 if (NT_STATUS_IS_OK(status)) {
1219 printf("lock2 succeeded! This is a locking bug\n");
1222 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1223 NT_STATUS_LOCK_NOT_GRANTED)) {
1228 lock_timeout = (1 + (random() % 20));
1229 printf("Testing lock timeout with timeout=%u\n", lock_timeout);
1231 status = cli_lock32(cli2, fnum3, 0, 4, lock_timeout * 1000, WRITE_LOCK);
1232 if (NT_STATUS_IS_OK(status)) {
1233 printf("lock3 succeeded! This is a locking bug\n");
1236 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1237 NT_STATUS_FILE_LOCK_CONFLICT)) {
1243 if (ABS(t2 - t1) < lock_timeout-1) {
1244 printf("error: This server appears not to support timed lock requests\n");
1247 printf("server slept for %u seconds for a %u second timeout\n",
1248 (unsigned int)(t2-t1), lock_timeout);
1250 status = cli_close(cli1, fnum2);
1251 if (!NT_STATUS_IS_OK(status)) {
1252 printf("close1 failed (%s)\n", nt_errstr(status));
1256 status = cli_lock32(cli2, fnum3, 0, 4, 0, WRITE_LOCK);
1257 if (NT_STATUS_IS_OK(status)) {
1258 printf("lock4 succeeded! This is a locking bug\n");
1261 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1262 NT_STATUS_FILE_LOCK_CONFLICT)) {
1267 status = cli_close(cli1, fnum1);
1268 if (!NT_STATUS_IS_OK(status)) {
1269 printf("close2 failed (%s)\n", nt_errstr(status));
1273 status = cli_close(cli2, fnum3);
1274 if (!NT_STATUS_IS_OK(status)) {
1275 printf("close3 failed (%s)\n", nt_errstr(status));
1279 status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1280 if (!NT_STATUS_IS_OK(status)) {
1281 printf("unlink failed (%s)\n", nt_errstr(status));
1286 if (!torture_close_connection(cli1)) {
1290 if (!torture_close_connection(cli2)) {
1294 printf("Passed locktest1\n");
1299 this checks to see if a secondary tconx can use open files from an
1302 static bool run_tcon_test(int dummy)
1304 static struct cli_state *cli;
1305 const char *fname = "\\tcontest.tmp";
1307 uint32_t cnum1, cnum2, cnum3;
1308 struct smbXcli_tcon *orig_tcon = NULL;
1309 uint16_t vuid1, vuid2;
1314 memset(buf, '\0', sizeof(buf));
1316 if (!torture_open_connection(&cli, 0)) {
1319 smbXcli_conn_set_sockopt(cli->conn, sockops);
1321 printf("starting tcontest\n");
1323 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1325 status = cli_openx(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
1326 if (!NT_STATUS_IS_OK(status)) {
1327 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
1331 cnum1 = cli_state_get_tid(cli);
1332 vuid1 = cli_state_get_uid(cli);
1334 status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
1335 if (!NT_STATUS_IS_OK(status)) {
1336 printf("initial write failed (%s)", nt_errstr(status));
1340 orig_tcon = cli_state_save_tcon(cli);
1341 if (orig_tcon == NULL) {
1345 status = cli_tree_connect_creds(cli, share, "?????", torture_creds);
1346 if (!NT_STATUS_IS_OK(status)) {
1347 printf("%s refused 2nd tree connect (%s)\n", host,
1353 cnum2 = cli_state_get_tid(cli);
1354 cnum3 = MAX(cnum1, cnum2) + 1; /* any invalid number */
1355 vuid2 = cli_state_get_uid(cli) + 1;
1357 /* try a write with the wrong tid */
1358 cli_state_set_tid(cli, cnum2);
1360 status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
1361 if (NT_STATUS_IS_OK(status)) {
1362 printf("* server allows write with wrong TID\n");
1365 printf("server fails write with wrong TID : %s\n",
1370 /* try a write with an invalid tid */
1371 cli_state_set_tid(cli, cnum3);
1373 status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
1374 if (NT_STATUS_IS_OK(status)) {
1375 printf("* server allows write with invalid TID\n");
1378 printf("server fails write with invalid TID : %s\n",
1382 /* try a write with an invalid vuid */
1383 cli_state_set_uid(cli, vuid2);
1384 cli_state_set_tid(cli, cnum1);
1386 status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
1387 if (NT_STATUS_IS_OK(status)) {
1388 printf("* server allows write with invalid VUID\n");
1391 printf("server fails write with invalid VUID : %s\n",
1395 cli_state_set_tid(cli, cnum1);
1396 cli_state_set_uid(cli, vuid1);
1398 status = cli_close(cli, fnum1);
1399 if (!NT_STATUS_IS_OK(status)) {
1400 printf("close failed (%s)\n", nt_errstr(status));
1404 cli_state_set_tid(cli, cnum2);
1406 status = cli_tdis(cli);
1407 if (!NT_STATUS_IS_OK(status)) {
1408 printf("secondary tdis failed (%s)\n", nt_errstr(status));
1412 cli_state_restore_tcon(cli, orig_tcon);
1414 cli_state_set_tid(cli, cnum1);
1416 if (!torture_close_connection(cli)) {
1425 checks for old style tcon support
1427 static bool run_tcon2_test(int dummy)
1429 static struct cli_state *cli;
1430 uint16_t cnum, max_xmit;
1434 if (!torture_open_connection(&cli, 0)) {
1437 smbXcli_conn_set_sockopt(cli->conn, sockops);
1439 printf("starting tcon2 test\n");
1441 if (asprintf(&service, "\\\\%s\\%s", host, share) == -1) {
1445 status = cli_raw_tcon(cli, service, password, "?????", &max_xmit, &cnum);
1449 if (!NT_STATUS_IS_OK(status)) {
1450 printf("tcon2 failed : %s\n", nt_errstr(status));
1452 printf("tcon OK : max_xmit=%d cnum=%d\n",
1453 (int)max_xmit, (int)cnum);
1456 if (!torture_close_connection(cli)) {
1460 printf("Passed tcon2 test\n");
1464 static bool tcon_devtest(struct cli_state *cli,
1465 const char *myshare, const char *devtype,
1466 const char *return_devtype,
1467 NTSTATUS expected_error)
1472 status = cli_tree_connect_creds(cli, myshare, devtype, torture_creds);
1474 if (NT_STATUS_IS_OK(expected_error)) {
1475 if (NT_STATUS_IS_OK(status)) {
1476 if (strcmp(cli->dev, return_devtype) == 0) {
1479 printf("tconX to share %s with type %s "
1480 "succeeded but returned the wrong "
1481 "device type (got [%s] but should have got [%s])\n",
1482 myshare, devtype, cli->dev, return_devtype);
1486 printf("tconX to share %s with type %s "
1487 "should have succeeded but failed\n",
1493 if (NT_STATUS_IS_OK(status)) {
1494 printf("tconx to share %s with type %s "
1495 "should have failed but succeeded\n",
1499 if (NT_STATUS_EQUAL(status, expected_error)) {
1502 printf("Returned unexpected error\n");
1511 checks for correct tconX support
1513 static bool run_tcon_devtype_test(int dummy)
1515 static struct cli_state *cli1 = NULL;
1516 int flags = CLI_FULL_CONNECTION_FORCE_SMB1;
1520 status = cli_full_connection_creds(&cli1,
1526 NULL, /* service_type */
1531 if (!NT_STATUS_IS_OK(status)) {
1532 printf("could not open connection\n");
1536 if (!tcon_devtest(cli1, "IPC$", "A:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1539 if (!tcon_devtest(cli1, "IPC$", "?????", "IPC", NT_STATUS_OK))
1542 if (!tcon_devtest(cli1, "IPC$", "LPT:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1545 if (!tcon_devtest(cli1, "IPC$", "IPC", "IPC", NT_STATUS_OK))
1548 if (!tcon_devtest(cli1, "IPC$", "FOOBA", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1551 if (!tcon_devtest(cli1, share, "A:", "A:", NT_STATUS_OK))
1554 if (!tcon_devtest(cli1, share, "?????", "A:", NT_STATUS_OK))
1557 if (!tcon_devtest(cli1, share, "LPT:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1560 if (!tcon_devtest(cli1, share, "IPC", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1563 if (!tcon_devtest(cli1, share, "FOOBA", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1569 printf("Passed tcondevtest\n");
1576 This test checks that
1578 1) the server supports multiple locking contexts on the one SMB
1579 connection, distinguished by PID.
1581 2) the server correctly fails overlapping locks made by the same PID (this
1582 goes against POSIX behaviour, which is why it is tricky to implement)
1584 3) the server denies unlock requests by an incorrect client PID
1586 static bool run_locktest2(int dummy)
1588 static struct cli_state *cli;
1589 const char *fname = "\\lockt2.lck";
1590 uint16_t fnum1, fnum2, fnum3;
1591 bool correct = True;
1594 if (!torture_open_connection(&cli, 0)) {
1598 smbXcli_conn_set_sockopt(cli->conn, sockops);
1600 printf("starting locktest2\n");
1602 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1606 status = cli_openx(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
1607 if (!NT_STATUS_IS_OK(status)) {
1608 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
1612 status = cli_openx(cli, fname, O_RDWR, DENY_NONE, &fnum2);
1613 if (!NT_STATUS_IS_OK(status)) {
1614 printf("open2 of %s failed (%s)\n", fname, nt_errstr(status));
1620 status = cli_openx(cli, fname, O_RDWR, DENY_NONE, &fnum3);
1621 if (!NT_STATUS_IS_OK(status)) {
1622 printf("open3 of %s failed (%s)\n", fname, nt_errstr(status));
1628 status = cli_lock32(cli, fnum1, 0, 4, 0, WRITE_LOCK);
1629 if (!NT_STATUS_IS_OK(status)) {
1630 printf("lock1 failed (%s)\n", nt_errstr(status));
1634 status = cli_lock32(cli, fnum1, 0, 4, 0, WRITE_LOCK);
1635 if (NT_STATUS_IS_OK(status)) {
1636 printf("WRITE lock1 succeeded! This is a locking bug\n");
1639 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1640 NT_STATUS_LOCK_NOT_GRANTED)) {
1645 status = cli_lock32(cli, fnum2, 0, 4, 0, WRITE_LOCK);
1646 if (NT_STATUS_IS_OK(status)) {
1647 printf("WRITE lock2 succeeded! This is a locking bug\n");
1650 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1651 NT_STATUS_LOCK_NOT_GRANTED)) {
1656 status = cli_lock32(cli, fnum2, 0, 4, 0, READ_LOCK);
1657 if (NT_STATUS_IS_OK(status)) {
1658 printf("READ lock2 succeeded! This is a locking bug\n");
1661 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1662 NT_STATUS_FILE_LOCK_CONFLICT)) {
1667 status = cli_lock32(cli, fnum1, 100, 4, 0, WRITE_LOCK);
1668 if (!NT_STATUS_IS_OK(status)) {
1669 printf("lock at 100 failed (%s)\n", nt_errstr(status));
1672 if (NT_STATUS_IS_OK(cli_unlock(cli, fnum1, 100, 4))) {
1673 printf("unlock at 100 succeeded! This is a locking bug\n");
1677 status = cli_unlock(cli, fnum1, 0, 4);
1678 if (NT_STATUS_IS_OK(status)) {
1679 printf("unlock1 succeeded! This is a locking bug\n");
1682 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1683 NT_STATUS_RANGE_NOT_LOCKED)) {
1688 status = cli_unlock(cli, fnum1, 0, 8);
1689 if (NT_STATUS_IS_OK(status)) {
1690 printf("unlock2 succeeded! This is a locking bug\n");
1693 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1694 NT_STATUS_RANGE_NOT_LOCKED)) {
1699 status = cli_lock32(cli, fnum3, 0, 4, 0, WRITE_LOCK);
1700 if (NT_STATUS_IS_OK(status)) {
1701 printf("lock3 succeeded! This is a locking bug\n");
1704 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1705 NT_STATUS_LOCK_NOT_GRANTED)) {
1712 status = cli_close(cli, fnum1);
1713 if (!NT_STATUS_IS_OK(status)) {
1714 printf("close1 failed (%s)\n", nt_errstr(status));
1718 status = cli_close(cli, fnum2);
1719 if (!NT_STATUS_IS_OK(status)) {
1720 printf("close2 failed (%s)\n", nt_errstr(status));
1724 status = cli_close(cli, fnum3);
1725 if (!NT_STATUS_IS_OK(status)) {
1726 printf("close3 failed (%s)\n", nt_errstr(status));
1730 if (!torture_close_connection(cli)) {
1734 printf("locktest2 finished\n");
1741 This test checks that
1743 1) the server supports the full offset range in lock requests
1745 static bool run_locktest3(int dummy)
1747 static struct cli_state *cli1, *cli2;
1748 const char *fname = "\\lockt3.lck";
1749 uint16_t fnum1, fnum2;
1752 bool correct = True;
1755 #define NEXT_OFFSET offset += (~(uint32_t)0) / torture_numops
1757 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1760 smbXcli_conn_set_sockopt(cli1->conn, sockops);
1761 smbXcli_conn_set_sockopt(cli2->conn, sockops);
1763 printf("starting locktest3\n");
1765 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1767 status = cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
1769 if (!NT_STATUS_IS_OK(status)) {
1770 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
1774 status = cli_openx(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
1775 if (!NT_STATUS_IS_OK(status)) {
1776 printf("open2 of %s failed (%s)\n", fname, nt_errstr(status));
1780 for (offset=i=0;i<torture_numops;i++) {
1783 status = cli_lock32(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK);
1784 if (!NT_STATUS_IS_OK(status)) {
1785 printf("lock1 %d failed (%s)\n",
1791 status = cli_lock32(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK);
1792 if (!NT_STATUS_IS_OK(status)) {
1793 printf("lock2 %d failed (%s)\n",
1800 for (offset=i=0;i<torture_numops;i++) {
1803 status = cli_lock32(cli1, fnum1, offset-2, 1, 0, WRITE_LOCK);
1804 if (NT_STATUS_IS_OK(status)) {
1805 printf("error: lock1 %d succeeded!\n", i);
1809 status = cli_lock32(cli2, fnum2, offset-1, 1, 0, WRITE_LOCK);
1810 if (NT_STATUS_IS_OK(status)) {
1811 printf("error: lock2 %d succeeded!\n", i);
1815 status = cli_lock32(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK);
1816 if (NT_STATUS_IS_OK(status)) {
1817 printf("error: lock3 %d succeeded!\n", i);
1821 status = cli_lock32(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK);
1822 if (NT_STATUS_IS_OK(status)) {
1823 printf("error: lock4 %d succeeded!\n", i);
1828 for (offset=i=0;i<torture_numops;i++) {
1831 status = cli_unlock(cli1, fnum1, offset-1, 1);
1832 if (!NT_STATUS_IS_OK(status)) {
1833 printf("unlock1 %d failed (%s)\n",
1839 status = cli_unlock(cli2, fnum2, offset-2, 1);
1840 if (!NT_STATUS_IS_OK(status)) {
1841 printf("unlock2 %d failed (%s)\n",
1848 status = cli_close(cli1, fnum1);
1849 if (!NT_STATUS_IS_OK(status)) {
1850 printf("close1 failed (%s)\n", nt_errstr(status));
1854 status = cli_close(cli2, fnum2);
1855 if (!NT_STATUS_IS_OK(status)) {
1856 printf("close2 failed (%s)\n", nt_errstr(status));
1860 status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1861 if (!NT_STATUS_IS_OK(status)) {
1862 printf("unlink failed (%s)\n", nt_errstr(status));
1866 if (!torture_close_connection(cli1)) {
1870 if (!torture_close_connection(cli2)) {
1874 printf("finished locktest3\n");
1879 static bool test_cli_read(struct cli_state *cli, uint16_t fnum,
1880 char *buf, off_t offset, size_t size,
1881 size_t *nread, size_t expect)
1886 status = cli_read(cli, fnum, buf, offset, size, &l_nread);
1888 if(!NT_STATUS_IS_OK(status)) {
1890 } else if (l_nread != expect) {
1901 #define EXPECTED(ret, v) if ((ret) != (v)) { \
1902 printf("** "); correct = False; \
1906 looks at overlapping locks
1908 static bool run_locktest4(int dummy)
1910 static struct cli_state *cli1, *cli2;
1911 const char *fname = "\\lockt4.lck";
1912 uint16_t fnum1, fnum2, f;
1915 bool correct = True;
1918 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1922 smbXcli_conn_set_sockopt(cli1->conn, sockops);
1923 smbXcli_conn_set_sockopt(cli2->conn, sockops);
1925 printf("starting locktest4\n");
1927 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1929 cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
1930 cli_openx(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
1932 memset(buf, 0, sizeof(buf));
1934 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 0, sizeof(buf),
1936 if (!NT_STATUS_IS_OK(status)) {
1937 printf("Failed to create file: %s\n", nt_errstr(status));
1942 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) &&
1943 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 2, 4, 0, WRITE_LOCK));
1944 EXPECTED(ret, False);
1945 printf("the same process %s set overlapping write locks\n", ret?"can":"cannot");
1947 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 10, 4, 0, READ_LOCK)) &&
1948 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 12, 4, 0, READ_LOCK));
1949 EXPECTED(ret, True);
1950 printf("the same process %s set overlapping read locks\n", ret?"can":"cannot");
1952 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 20, 4, 0, WRITE_LOCK)) &&
1953 NT_STATUS_IS_OK(cli_lock32(cli2, fnum2, 22, 4, 0, WRITE_LOCK));
1954 EXPECTED(ret, False);
1955 printf("a different connection %s set overlapping write locks\n", ret?"can":"cannot");
1957 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 30, 4, 0, READ_LOCK)) &&
1958 NT_STATUS_IS_OK(cli_lock32(cli2, fnum2, 32, 4, 0, READ_LOCK));
1959 EXPECTED(ret, True);
1960 printf("a different connection %s set overlapping read locks\n", ret?"can":"cannot");
1962 ret = (cli_setpid(cli1, 1),
1963 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 40, 4, 0, WRITE_LOCK))) &&
1964 (cli_setpid(cli1, 2),
1965 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 42, 4, 0, WRITE_LOCK)));
1966 EXPECTED(ret, False);
1967 printf("a different pid %s set overlapping write locks\n", ret?"can":"cannot");
1969 ret = (cli_setpid(cli1, 1),
1970 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 50, 4, 0, READ_LOCK))) &&
1971 (cli_setpid(cli1, 2),
1972 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 52, 4, 0, READ_LOCK)));
1973 EXPECTED(ret, True);
1974 printf("a different pid %s set overlapping read locks\n", ret?"can":"cannot");
1976 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 60, 4, 0, READ_LOCK)) &&
1977 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 60, 4, 0, READ_LOCK));
1978 EXPECTED(ret, True);
1979 printf("the same process %s set the same read lock twice\n", ret?"can":"cannot");
1981 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 70, 4, 0, WRITE_LOCK)) &&
1982 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 70, 4, 0, WRITE_LOCK));
1983 EXPECTED(ret, False);
1984 printf("the same process %s set the same write lock twice\n", ret?"can":"cannot");
1986 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 80, 4, 0, READ_LOCK)) &&
1987 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 80, 4, 0, WRITE_LOCK));
1988 EXPECTED(ret, False);
1989 printf("the same process %s overlay a read lock with a write lock\n", ret?"can":"cannot");
1991 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 90, 4, 0, WRITE_LOCK)) &&
1992 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 90, 4, 0, READ_LOCK));
1993 EXPECTED(ret, True);
1994 printf("the same process %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1996 ret = (cli_setpid(cli1, 1),
1997 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 100, 4, 0, WRITE_LOCK))) &&
1998 (cli_setpid(cli1, 2),
1999 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 100, 4, 0, READ_LOCK)));
2000 EXPECTED(ret, False);
2001 printf("a different pid %s overlay a write lock with a read lock\n", ret?"can":"cannot");
2003 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 110, 4, 0, READ_LOCK)) &&
2004 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 112, 4, 0, READ_LOCK)) &&
2005 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 110, 6));
2006 EXPECTED(ret, False);
2007 printf("the same process %s coalesce read locks\n", ret?"can":"cannot");
2010 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 120, 4, 0, WRITE_LOCK)) &&
2011 test_cli_read(cli2, fnum2, buf, 120, 4, NULL, 4);
2012 EXPECTED(ret, False);
2013 printf("this server %s strict write locking\n", ret?"doesn't do":"does");
2015 status = cli_lock32(cli1, fnum1, 130, 4, 0, READ_LOCK);
2016 ret = NT_STATUS_IS_OK(status);
2018 status = cli_writeall(cli2, fnum2, 0, (uint8_t *)buf, 130, 4,
2020 ret = NT_STATUS_IS_OK(status);
2022 EXPECTED(ret, False);
2023 printf("this server %s strict read locking\n", ret?"doesn't do":"does");
2026 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 140, 4, 0, READ_LOCK)) &&
2027 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 140, 4, 0, READ_LOCK)) &&
2028 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 140, 4)) &&
2029 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 140, 4));
2030 EXPECTED(ret, True);
2031 printf("this server %s do recursive read locking\n", ret?"does":"doesn't");
2034 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 150, 4, 0, WRITE_LOCK)) &&
2035 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 150, 4, 0, READ_LOCK)) &&
2036 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 150, 4)) &&
2037 test_cli_read(cli2, fnum2, buf, 150, 4, NULL, 4) &&
2038 !(NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf,
2040 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 150, 4));
2041 EXPECTED(ret, True);
2042 printf("this server %s do recursive lock overlays\n", ret?"does":"doesn't");
2044 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 160, 4, 0, READ_LOCK)) &&
2045 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 160, 4)) &&
2046 NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf,
2048 test_cli_read(cli2, fnum2, buf, 160, 4, NULL, 4);
2049 EXPECTED(ret, True);
2050 printf("the same process %s remove a read lock using write locking\n", ret?"can":"cannot");
2052 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 170, 4, 0, WRITE_LOCK)) &&
2053 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 170, 4)) &&
2054 NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf,
2056 test_cli_read(cli2, fnum2, buf, 170, 4, NULL, 4);
2057 EXPECTED(ret, True);
2058 printf("the same process %s remove a write lock using read locking\n", ret?"can":"cannot");
2060 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 190, 4, 0, WRITE_LOCK)) &&
2061 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 190, 4, 0, READ_LOCK)) &&
2062 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 190, 4)) &&
2063 !NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf,
2065 test_cli_read(cli2, fnum2, buf, 190, 4, NULL, 4);
2066 EXPECTED(ret, True);
2067 printf("the same process %s remove the first lock first\n", ret?"does":"doesn't");
2069 cli_close(cli1, fnum1);
2070 cli_close(cli2, fnum2);
2071 cli_openx(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
2072 cli_openx(cli1, fname, O_RDWR, DENY_NONE, &f);
2073 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 8, 0, READ_LOCK)) &&
2074 NT_STATUS_IS_OK(cli_lock32(cli1, f, 0, 1, 0, READ_LOCK)) &&
2075 NT_STATUS_IS_OK(cli_close(cli1, fnum1)) &&
2076 NT_STATUS_IS_OK(cli_openx(cli1, fname, O_RDWR, DENY_NONE, &fnum1)) &&
2077 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 7, 1, 0, WRITE_LOCK));
2079 cli_close(cli1, fnum1);
2080 EXPECTED(ret, True);
2081 printf("the server %s have the NT byte range lock bug\n", !ret?"does":"doesn't");
2084 cli_close(cli1, fnum1);
2085 cli_close(cli2, fnum2);
2086 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2087 torture_close_connection(cli1);
2088 torture_close_connection(cli2);
2090 printf("finished locktest4\n");
2095 looks at lock upgrade/downgrade.
2097 static bool run_locktest5(int dummy)
2099 static struct cli_state *cli1, *cli2;
2100 const char *fname = "\\lockt5.lck";
2101 uint16_t fnum1, fnum2, fnum3;
2104 bool correct = True;
2107 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
2111 smbXcli_conn_set_sockopt(cli1->conn, sockops);
2112 smbXcli_conn_set_sockopt(cli2->conn, sockops);
2114 printf("starting locktest5\n");
2116 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2118 cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
2119 cli_openx(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
2120 cli_openx(cli1, fname, O_RDWR, DENY_NONE, &fnum3);
2122 memset(buf, 0, sizeof(buf));
2124 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 0, sizeof(buf),
2126 if (!NT_STATUS_IS_OK(status)) {
2127 printf("Failed to create file: %s\n", nt_errstr(status));
2132 /* Check for NT bug... */
2133 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 8, 0, READ_LOCK)) &&
2134 NT_STATUS_IS_OK(cli_lock32(cli1, fnum3, 0, 1, 0, READ_LOCK));
2135 cli_close(cli1, fnum1);
2136 cli_openx(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
2137 status = cli_lock32(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
2138 ret = NT_STATUS_IS_OK(status);
2139 EXPECTED(ret, True);
2140 printf("this server %s the NT locking bug\n", ret ? "doesn't have" : "has");
2141 cli_close(cli1, fnum1);
2142 cli_openx(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
2143 cli_unlock(cli1, fnum3, 0, 1);
2145 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) &&
2146 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 1, 1, 0, READ_LOCK));
2147 EXPECTED(ret, True);
2148 printf("the same process %s overlay a write with a read lock\n", ret?"can":"cannot");
2150 status = cli_lock32(cli2, fnum2, 0, 4, 0, READ_LOCK);
2151 ret = NT_STATUS_IS_OK(status);
2152 EXPECTED(ret, False);
2154 printf("a different processs %s get a read lock on the first process lock stack\n", ret?"can":"cannot");
2156 /* Unlock the process 2 lock. */
2157 cli_unlock(cli2, fnum2, 0, 4);
2159 status = cli_lock32(cli1, fnum3, 0, 4, 0, READ_LOCK);
2160 ret = NT_STATUS_IS_OK(status);
2161 EXPECTED(ret, False);
2163 printf("the same processs on a different fnum %s get a read lock\n", ret?"can":"cannot");
2165 /* Unlock the process 1 fnum3 lock. */
2166 cli_unlock(cli1, fnum3, 0, 4);
2168 /* Stack 2 more locks here. */
2169 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 4, 0, READ_LOCK)) &&
2170 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 4, 0, READ_LOCK));
2172 EXPECTED(ret, True);
2173 printf("the same process %s stack read locks\n", ret?"can":"cannot");
2175 /* Unlock the first process lock, then check this was the WRITE lock that was
2178 ret = NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 0, 4)) &&
2179 NT_STATUS_IS_OK(cli_lock32(cli2, fnum2, 0, 4, 0, READ_LOCK));
2181 EXPECTED(ret, True);
2182 printf("the first unlock removes the %s lock\n", ret?"WRITE":"READ");
2184 /* Unlock the process 2 lock. */
2185 cli_unlock(cli2, fnum2, 0, 4);
2187 /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */
2189 ret = NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 1, 1)) &&
2190 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 0, 4)) &&
2191 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 0, 4));
2193 EXPECTED(ret, True);
2194 printf("the same process %s unlock the stack of 4 locks\n", ret?"can":"cannot");
2196 /* Ensure the next unlock fails. */
2197 ret = NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 0, 4));
2198 EXPECTED(ret, False);
2199 printf("the same process %s count the lock stack\n", !ret?"can":"cannot");
2201 /* Ensure connection 2 can get a write lock. */
2202 status = cli_lock32(cli2, fnum2, 0, 4, 0, WRITE_LOCK);
2203 ret = NT_STATUS_IS_OK(status);
2204 EXPECTED(ret, True);
2206 printf("a different processs %s get a write lock on the unlocked stack\n", ret?"can":"cannot");
2210 cli_close(cli1, fnum1);
2211 cli_close(cli2, fnum2);
2212 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2213 if (!torture_close_connection(cli1)) {
2216 if (!torture_close_connection(cli2)) {
2220 printf("finished locktest5\n");
2226 tries the unusual lockingX locktype bits
2228 static bool run_locktest6(int dummy)
2230 static struct cli_state *cli;
2231 const char *fname[1] = { "\\lock6.txt" };
2236 if (!torture_open_connection(&cli, 0)) {
2240 smbXcli_conn_set_sockopt(cli->conn, sockops);
2242 printf("starting locktest6\n");
2245 printf("Testing %s\n", fname[i]);
2247 cli_unlink(cli, fname[i], FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2249 cli_openx(cli, fname[i], O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
2250 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE);
2251 cli_close(cli, fnum);
2252 printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status));
2254 cli_openx(cli, fname[i], O_RDWR, DENY_NONE, &fnum);
2255 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK);
2256 cli_close(cli, fnum);
2257 printf("CANCEL_LOCK gave %s\n", nt_errstr(status));
2259 cli_unlink(cli, fname[i], FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2262 torture_close_connection(cli);
2264 printf("finished locktest6\n");
2268 static bool run_locktest7(int dummy)
2270 struct cli_state *cli1;
2271 const char *fname = "\\lockt7.lck";
2274 bool correct = False;
2278 if (!torture_open_connection(&cli1, 0)) {
2282 smbXcli_conn_set_sockopt(cli1->conn, sockops);
2284 printf("starting locktest7\n");
2286 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2288 cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
2290 memset(buf, 0, sizeof(buf));
2292 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 0, sizeof(buf),
2294 if (!NT_STATUS_IS_OK(status)) {
2295 printf("Failed to create file: %s\n", nt_errstr(status));
2299 cli_setpid(cli1, 1);
2301 status = cli_lock32(cli1, fnum1, 130, 4, 0, READ_LOCK);
2302 if (!NT_STATUS_IS_OK(status)) {
2303 printf("Unable to apply read lock on range 130:4, "
2304 "error was %s\n", nt_errstr(status));
2307 printf("pid1 successfully locked range 130:4 for READ\n");
2310 status = cli_read(cli1, fnum1, buf, 130, 4, &nread);
2311 if (!NT_STATUS_IS_OK(status)) {
2312 printf("pid1 unable to read the range 130:4, error was %s\n",
2315 } else if (nread != 4) {
2316 printf("pid1 unable to read the range 130:4, "
2317 "recv %ld req %d\n", (unsigned long)nread, 4);
2320 printf("pid1 successfully read the range 130:4\n");
2323 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
2324 if (!NT_STATUS_IS_OK(status)) {
2325 printf("pid1 unable to write to the range 130:4, error was "
2326 "%s\n", nt_errstr(status));
2327 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_LOCK_CONFLICT)) {
2328 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2332 printf("pid1 successfully wrote to the range 130:4 (should be denied)\n");
2336 cli_setpid(cli1, 2);
2338 status = cli_read(cli1, fnum1, buf, 130, 4, &nread);
2339 if (!NT_STATUS_IS_OK(status)) {
2340 printf("pid2 unable to read the range 130:4, error was %s\n",
2343 } else if (nread != 4) {
2344 printf("pid2 unable to read the range 130:4, "
2345 "recv %ld req %d\n", (unsigned long)nread, 4);
2348 printf("pid2 successfully read the range 130:4\n");
2351 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
2352 if (!NT_STATUS_IS_OK(status)) {
2353 printf("pid2 unable to write to the range 130:4, error was "
2354 "%s\n", nt_errstr(status));
2355 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_LOCK_CONFLICT)) {
2356 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2360 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
2364 cli_setpid(cli1, 1);
2365 cli_unlock(cli1, fnum1, 130, 4);
2367 status = cli_lock32(cli1, fnum1, 130, 4, 0, WRITE_LOCK);
2368 if (!NT_STATUS_IS_OK(status)) {
2369 printf("Unable to apply write lock on range 130:4, error was %s\n", nt_errstr(status));
2372 printf("pid1 successfully locked range 130:4 for WRITE\n");
2375 status = cli_read(cli1, fnum1, buf, 130, 4, &nread);
2376 if (!NT_STATUS_IS_OK(status)) {
2377 printf("pid1 unable to read the range 130:4, error was %s\n",
2380 } else if (nread != 4) {
2381 printf("pid1 unable to read the range 130:4, "
2382 "recv %ld req %d\n", (unsigned long)nread, 4);
2385 printf("pid1 successfully read the range 130:4\n");
2388 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
2389 if (!NT_STATUS_IS_OK(status)) {
2390 printf("pid1 unable to write to the range 130:4, error was "
2391 "%s\n", nt_errstr(status));
2394 printf("pid1 successfully wrote to the range 130:4\n");
2397 cli_setpid(cli1, 2);
2399 status = cli_read(cli1, fnum1, buf, 130, 4, &nread);
2400 if (!NT_STATUS_IS_OK(status)) {
2401 printf("pid2 unable to read the range 130:4, error was "
2402 "%s\n", nt_errstr(status));
2403 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_LOCK_CONFLICT)) {
2404 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2408 printf("pid2 successfully read the range 130:4 (should be denied) recv %ld\n",
2409 (unsigned long)nread);
2413 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
2414 if (!NT_STATUS_IS_OK(status)) {
2415 printf("pid2 unable to write to the range 130:4, error was "
2416 "%s\n", nt_errstr(status));
2417 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_LOCK_CONFLICT)) {
2418 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2422 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
2426 cli_unlock(cli1, fnum1, 130, 0);
2430 cli_close(cli1, fnum1);
2431 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2432 torture_close_connection(cli1);
2434 printf("finished locktest7\n");
2439 * This demonstrates a problem with our use of GPFS share modes: A file
2440 * descriptor sitting in the pending close queue holding a GPFS share mode
2441 * blocks opening a file another time. Happens with Word 2007 temp files.
2442 * With "posix locking = yes" and "gpfs:sharemodes = yes" enabled, the third
2443 * open is denied with NT_STATUS_SHARING_VIOLATION.
2446 static bool run_locktest8(int dummy)
2448 struct cli_state *cli1;
2449 const char *fname = "\\lockt8.lck";
2450 uint16_t fnum1, fnum2;
2452 bool correct = False;
2455 if (!torture_open_connection(&cli1, 0)) {
2459 smbXcli_conn_set_sockopt(cli1->conn, sockops);
2461 printf("starting locktest8\n");
2463 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2465 status = cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_WRITE,
2467 if (!NT_STATUS_IS_OK(status)) {
2468 d_fprintf(stderr, "cli_openx returned %s\n", nt_errstr(status));
2472 memset(buf, 0, sizeof(buf));
2474 status = cli_openx(cli1, fname, O_RDONLY, DENY_NONE, &fnum2);
2475 if (!NT_STATUS_IS_OK(status)) {
2476 d_fprintf(stderr, "cli_openx second time returned %s\n",
2481 status = cli_lock32(cli1, fnum2, 1, 1, 0, READ_LOCK);
2482 if (!NT_STATUS_IS_OK(status)) {
2483 printf("Unable to apply read lock on range 1:1, error was "
2484 "%s\n", nt_errstr(status));
2488 status = cli_close(cli1, fnum1);
2489 if (!NT_STATUS_IS_OK(status)) {
2490 d_fprintf(stderr, "cli_close(fnum1) %s\n", nt_errstr(status));
2494 status = cli_openx(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
2495 if (!NT_STATUS_IS_OK(status)) {
2496 d_fprintf(stderr, "cli_openx third time returned %s\n",
2504 cli_close(cli1, fnum1);
2505 cli_close(cli1, fnum2);
2506 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2507 torture_close_connection(cli1);
2509 printf("finished locktest8\n");
2514 * This test is designed to be run in conjunction with
2515 * external NFS or POSIX locks taken in the filesystem.
2516 * It checks that the smbd server will block until the
2517 * lock is released and then acquire it. JRA.
2520 static bool got_alarm;
2521 static struct cli_state *alarm_cli;
2523 static void alarm_handler(int dummy)
2528 static void alarm_handler_parent(int dummy)
2530 smbXcli_conn_disconnect(alarm_cli->conn, NT_STATUS_OK);
2533 static void do_local_lock(int read_fd, int write_fd)
2538 const char *local_pathname = NULL;
2541 local_pathname = talloc_asprintf(talloc_tos(),
2542 "%s/lockt9.lck", local_path);
2543 if (!local_pathname) {
2544 printf("child: alloc fail\n");
2548 unlink(local_pathname);
2549 fd = open(local_pathname, O_RDWR|O_CREAT, 0666);
2551 printf("child: open of %s failed %s.\n",
2552 local_pathname, strerror(errno));
2556 /* Now take a fcntl lock. */
2557 lock.l_type = F_WRLCK;
2558 lock.l_whence = SEEK_SET;
2561 lock.l_pid = getpid();
2563 ret = fcntl(fd,F_SETLK,&lock);
2565 printf("child: failed to get lock 0:4 on file %s. Error %s\n",
2566 local_pathname, strerror(errno));
2569 printf("child: got lock 0:4 on file %s.\n",
2574 CatchSignal(SIGALRM, alarm_handler);
2576 /* Signal the parent. */
2577 if (write(write_fd, &c, 1) != 1) {
2578 printf("child: start signal fail %s.\n",
2585 /* Wait for the parent to be ready. */
2586 if (read(read_fd, &c, 1) != 1) {
2587 printf("child: reply signal fail %s.\n",
2595 printf("child: released lock 0:4 on file %s.\n",
2601 static bool run_locktest9(int dummy)
2603 struct cli_state *cli1;
2604 const char *fname = "\\lockt9.lck";
2606 bool correct = False;
2607 int pipe_in[2], pipe_out[2];
2611 struct timeval start;
2615 printf("starting locktest9\n");
2617 if (local_path == NULL) {
2618 d_fprintf(stderr, "locktest9 must be given a local path via -l <localpath>\n");
2622 if (pipe(pipe_in) == -1 || pipe(pipe_out) == -1) {
2627 if (child_pid == -1) {
2631 if (child_pid == 0) {
2633 do_local_lock(pipe_out[0], pipe_in[1]);
2643 ret = read(pipe_in[0], &c, 1);
2645 d_fprintf(stderr, "failed to read start signal from child. %s\n",
2650 if (!torture_open_connection(&cli1, 0)) {
2654 smbXcli_conn_set_sockopt(cli1->conn, sockops);
2656 status = cli_openx(cli1, fname, O_RDWR, DENY_NONE,
2658 if (!NT_STATUS_IS_OK(status)) {
2659 d_fprintf(stderr, "cli_openx returned %s\n", nt_errstr(status));
2663 /* Ensure the child has the lock. */
2664 status = cli_lock32(cli1, fnum, 0, 4, 0, WRITE_LOCK);
2665 if (NT_STATUS_IS_OK(status)) {
2666 d_fprintf(stderr, "Got the lock on range 0:4 - this should not happen !\n");
2669 d_printf("Child has the lock.\n");
2672 /* Tell the child to wait 5 seconds then exit. */
2673 ret = write(pipe_out[1], &c, 1);
2675 d_fprintf(stderr, "failed to send exit signal to child. %s\n",
2680 /* Wait 20 seconds for the lock. */
2682 CatchSignal(SIGALRM, alarm_handler_parent);
2685 start = timeval_current();
2687 status = cli_lock32(cli1, fnum, 0, 4, -1, WRITE_LOCK);
2688 if (!NT_STATUS_IS_OK(status)) {
2689 d_fprintf(stderr, "Unable to apply write lock on range 0:4, error was "
2690 "%s\n", nt_errstr(status));
2695 seconds = timeval_elapsed(&start);
2697 printf("Parent got the lock after %.2f seconds.\n",
2700 status = cli_close(cli1, fnum);
2701 if (!NT_STATUS_IS_OK(status)) {
2702 d_fprintf(stderr, "cli_close(fnum1) %s\n", nt_errstr(status));
2709 cli_close(cli1, fnum);
2710 torture_close_connection(cli1);
2714 printf("finished locktest9\n");
2719 test whether fnums and tids open on one VC are available on another (a major
2722 static bool run_fdpasstest(int dummy)
2724 struct cli_state *cli1, *cli2;
2725 const char *fname = "\\fdpass.tst";
2730 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
2733 smbXcli_conn_set_sockopt(cli1->conn, sockops);
2734 smbXcli_conn_set_sockopt(cli2->conn, sockops);
2736 printf("starting fdpasstest\n");
2738 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2740 status = cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
2742 if (!NT_STATUS_IS_OK(status)) {
2743 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
2747 status = cli_writeall(cli1, fnum1, 0, (const uint8_t *)"hello world\n", 0,
2749 if (!NT_STATUS_IS_OK(status)) {
2750 printf("write failed (%s)\n", nt_errstr(status));
2754 cli_state_set_uid(cli2, cli_state_get_uid(cli1));
2755 cli_state_set_tid(cli2, cli_state_get_tid(cli1));
2756 cli_setpid(cli2, cli_getpid(cli1));
2758 if (test_cli_read(cli2, fnum1, buf, 0, 13, NULL, 13)) {
2759 printf("read succeeded! nasty security hole [%s]\n", buf);
2763 cli_close(cli1, fnum1);
2764 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2766 torture_close_connection(cli1);
2767 torture_close_connection(cli2);
2769 printf("finished fdpasstest\n");
2773 static bool run_fdsesstest(int dummy)
2775 struct cli_state *cli;
2777 uint16_t saved_vuid;
2779 uint32_t saved_cnum;
2780 const char *fname = "\\fdsess.tst";
2781 const char *fname1 = "\\fdsess1.tst";
2788 if (!torture_open_connection(&cli, 0))
2790 smbXcli_conn_set_sockopt(cli->conn, sockops);
2792 if (!torture_cli_session_setup2(cli, &new_vuid))
2795 saved_cnum = cli_state_get_tid(cli);
2796 if (!NT_STATUS_IS_OK(cli_tree_connect(cli, share, "?????", NULL)))
2798 new_cnum = cli_state_get_tid(cli);
2799 cli_state_set_tid(cli, saved_cnum);
2801 printf("starting fdsesstest\n");
2803 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2804 cli_unlink(cli, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2806 status = cli_openx(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
2807 if (!NT_STATUS_IS_OK(status)) {
2808 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
2812 status = cli_writeall(cli, fnum1, 0, (const uint8_t *)"hello world\n", 0, 13,
2814 if (!NT_STATUS_IS_OK(status)) {
2815 printf("write failed (%s)\n", nt_errstr(status));
2819 saved_vuid = cli_state_get_uid(cli);
2820 cli_state_set_uid(cli, new_vuid);
2822 if (test_cli_read(cli, fnum1, buf, 0, 13, NULL, 13)) {
2823 printf("read succeeded with different vuid! "
2824 "nasty security hole [%s]\n", buf);
2827 /* Try to open a file with different vuid, samba cnum. */
2828 if (NT_STATUS_IS_OK(cli_openx(cli, fname1, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum2))) {
2829 printf("create with different vuid, same cnum succeeded.\n");
2830 cli_close(cli, fnum2);
2831 cli_unlink(cli, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2833 printf("create with different vuid, same cnum failed.\n");
2834 printf("This will cause problems with service clients.\n");
2838 cli_state_set_uid(cli, saved_vuid);
2840 /* Try with same vuid, different cnum. */
2841 cli_state_set_tid(cli, new_cnum);
2843 if (test_cli_read(cli, fnum1, buf, 0, 13, NULL, 13)) {
2844 printf("read succeeded with different cnum![%s]\n", buf);
2848 cli_state_set_tid(cli, saved_cnum);
2849 cli_close(cli, fnum1);
2850 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2852 torture_close_connection(cli);
2854 printf("finished fdsesstest\n");
2859 This test checks that
2861 1) the server does not allow an unlink on a file that is open
2863 static bool run_unlinktest(int dummy)
2865 struct cli_state *cli;
2866 const char *fname = "\\unlink.tst";
2868 bool correct = True;
2871 if (!torture_open_connection(&cli, 0)) {
2875 smbXcli_conn_set_sockopt(cli->conn, sockops);
2877 printf("starting unlink test\n");
2879 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2883 status = cli_openx(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
2884 if (!NT_STATUS_IS_OK(status)) {
2885 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
2889 status = cli_unlink(cli, fname,
2890 FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2891 if (NT_STATUS_IS_OK(status)) {
2892 printf("error: server allowed unlink on an open file\n");
2895 correct = check_error(__LINE__, status, ERRDOS, ERRbadshare,
2896 NT_STATUS_SHARING_VIOLATION);
2899 cli_close(cli, fnum);
2900 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2902 if (!torture_close_connection(cli)) {
2906 printf("unlink test finished\n");
2913 test how many open files this server supports on the one socket
2915 static bool run_maxfidtest(int dummy)
2917 struct cli_state *cli;
2919 uint16_t fnums[0x11000];
2922 bool correct = True;
2928 printf("failed to connect\n");
2932 smbXcli_conn_set_sockopt(cli->conn, sockops);
2934 for (i=0; i<0x11000; i++) {
2935 slprintf(fname,sizeof(fname)-1,"\\maxfid.%d.%d", i,(int)getpid());
2936 status = cli_openx(cli, fname, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE,
2938 if (!NT_STATUS_IS_OK(status)) {
2939 printf("open of %s failed (%s)\n",
2940 fname, nt_errstr(status));
2941 printf("maximum fnum is %d\n", i);
2949 printf("cleaning up\n");
2951 slprintf(fname,sizeof(fname)-1,"\\maxfid.%d.%d", i,(int)getpid());
2952 cli_close(cli, fnums[i]);
2954 status = cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2955 if (!NT_STATUS_IS_OK(status)) {
2956 printf("unlink of %s failed (%s)\n",
2957 fname, nt_errstr(status));
2964 printf("maxfid test finished\n");
2965 if (!torture_close_connection(cli)) {
2971 /* generate a random buffer */
2972 static void rand_buf(char *buf, int len)
2975 *buf = (char)sys_random();
2980 /* send smb negprot commands, not reading the response */
2981 static bool run_negprot_nowait(int dummy)
2983 struct tevent_context *ev;
2985 struct cli_state *cli;
2986 bool correct = True;
2988 printf("starting negprot nowait test\n");
2990 ev = samba_tevent_context_init(talloc_tos());
2995 if (!(cli = open_nbt_connection())) {
3000 for (i=0;i<50000;i++) {
3001 struct tevent_req *req;
3003 req = smbXcli_negprot_send(ev, ev, cli->conn, cli->timeout,
3004 PROTOCOL_CORE, PROTOCOL_NT1, 0);
3009 if (!tevent_req_poll(req, ev)) {
3010 d_fprintf(stderr, "tevent_req_poll failed: %s\n",
3018 if (torture_close_connection(cli)) {
3022 printf("finished negprot nowait test\n");
3027 /* send smb negprot commands, not reading the response */
3028 static bool run_bad_nbt_session(int dummy)
3030 struct nmb_name called, calling;
3031 struct sockaddr_storage ss;
3036 printf("starting bad nbt session test\n");
3038 make_nmb_name(&calling, myname, 0x0);
3039 make_nmb_name(&called , host, 0x20);
3041 if (!resolve_name(host, &ss, 0x20, true)) {
3042 d_fprintf(stderr, "Could not resolve name %s\n", host);
3046 status = open_socket_out(&ss, NBT_SMB_PORT, 10000, &fd);
3047 if (!NT_STATUS_IS_OK(status)) {
3048 d_fprintf(stderr, "open_socket_out failed: %s\n",
3053 ret = cli_bad_session_request(fd, &calling, &called);
3056 d_fprintf(stderr, "open_socket_out failed: %s\n",
3061 printf("finished bad nbt session test\n");
3065 /* send random IPC commands */
3066 static bool run_randomipc(int dummy)
3068 char *rparam = NULL;
3070 unsigned int rdrcnt,rprcnt;
3072 int api, param_len, i;
3073 struct cli_state *cli;
3074 bool correct = True;
3077 printf("starting random ipc test\n");
3079 if (!torture_open_connection(&cli, 0)) {
3083 for (i=0;i<count;i++) {
3084 api = sys_random() % 500;
3085 param_len = (sys_random() % 64);
3087 rand_buf(param, param_len);
3092 param, param_len, 8,
3093 NULL, 0, CLI_BUFFER_SIZE,
3097 printf("%d/%d\r", i,count);
3100 printf("%d/%d\n", i, count);
3102 if (!torture_close_connection(cli)) {
3109 printf("finished random ipc test\n");
3116 static void browse_callback(const char *sname, uint32_t stype,
3117 const char *comment, void *state)
3119 printf("\t%20.20s %08x %s\n", sname, stype, comment);
3125 This test checks the browse list code
3128 static bool run_browsetest(int dummy)
3130 static struct cli_state *cli;
3131 bool correct = True;
3133 printf("starting browse test\n");
3135 if (!torture_open_connection(&cli, 0)) {
3139 printf("domain list:\n");
3140 cli_NetServerEnum(cli, cli->server_domain,
3141 SV_TYPE_DOMAIN_ENUM,
3142 browse_callback, NULL);
3144 printf("machine list:\n");
3145 cli_NetServerEnum(cli, cli->server_domain,
3147 browse_callback, NULL);
3149 if (!torture_close_connection(cli)) {
3153 printf("browse test finished\n");
3161 This checks how the getatr calls works
3163 static bool run_attrtest(int dummy)
3165 struct cli_state *cli;
3168 const char *fname = "\\attrib123456789.tst";
3169 bool correct = True;
3172 printf("starting attrib test\n");
3174 if (!torture_open_connection(&cli, 0)) {
3178 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3179 cli_openx(cli, fname,
3180 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
3181 cli_close(cli, fnum);
3183 status = cli_getatr(cli, fname, NULL, NULL, &t);
3184 if (!NT_STATUS_IS_OK(status)) {
3185 printf("getatr failed (%s)\n", nt_errstr(status));
3189 if (abs(t - time(NULL)) > 60*60*24*10) {
3190 printf("ERROR: SMBgetatr bug. time is %s",
3196 t2 = t-60*60*24; /* 1 day ago */
3198 status = cli_setatr(cli, fname, 0, t2);
3199 if (!NT_STATUS_IS_OK(status)) {
3200 printf("setatr failed (%s)\n", nt_errstr(status));
3204 status = cli_getatr(cli, fname, NULL, NULL, &t);
3205 if (!NT_STATUS_IS_OK(status)) {
3206 printf("getatr failed (%s)\n", nt_errstr(status));
3211 printf("ERROR: getatr/setatr bug. times are\n%s",
3213 printf("%s", ctime(&t2));
3217 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3219 if (!torture_close_connection(cli)) {
3223 printf("attrib test finished\n");
3230 This checks a couple of trans2 calls
3232 static bool run_trans2test(int dummy)
3234 struct cli_state *cli;
3237 time_t c_time, a_time, m_time;
3238 struct timespec c_time_ts, a_time_ts, m_time_ts, w_time_ts, m_time2_ts;
3239 const char *fname = "\\trans2.tst";
3240 const char *dname = "\\trans2";
3241 const char *fname2 = "\\trans2\\trans2.tst";
3243 bool correct = True;
3247 printf("starting trans2 test\n");
3249 if (!torture_open_connection(&cli, 0)) {
3253 status = cli_get_fs_attr_info(cli, &fs_attr);
3254 if (!NT_STATUS_IS_OK(status)) {
3255 printf("ERROR: cli_get_fs_attr_info returned %s\n",
3260 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3261 cli_openx(cli, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
3262 status = cli_qfileinfo_basic(cli, fnum, NULL, &size, &c_time_ts,
3263 &a_time_ts, &w_time_ts, &m_time_ts, NULL);
3264 if (!NT_STATUS_IS_OK(status)) {
3265 printf("ERROR: qfileinfo failed (%s)\n", nt_errstr(status));
3269 status = cli_qfilename(cli, fnum, talloc_tos(), &pname);
3270 if (!NT_STATUS_IS_OK(status)) {
3271 printf("ERROR: qfilename failed (%s)\n", nt_errstr(status));
3274 else if (strcmp(pname, fname)) {
3275 printf("qfilename gave different name? [%s] [%s]\n",
3280 cli_close(cli, fnum);
3284 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3285 status = cli_openx(cli, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE,
3287 if (!NT_STATUS_IS_OK(status)) {
3288 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
3291 cli_close(cli, fnum);
3293 status = cli_qpathinfo1(cli, fname, &c_time, &a_time, &m_time, &size,
3295 if (!NT_STATUS_IS_OK(status)) {
3296 printf("ERROR: qpathinfo failed (%s)\n", nt_errstr(status));
3299 time_t t = time(NULL);
3301 if (c_time != m_time) {
3302 printf("create time=%s", ctime(&c_time));
3303 printf("modify time=%s", ctime(&m_time));
3304 printf("This system appears to have sticky create times\n");
3306 if ((abs(a_time - t) > 60) && (a_time % (60*60) == 0)) {
3307 printf("access time=%s", ctime(&a_time));
3308 printf("This system appears to set a midnight access time\n");
3312 if (abs(m_time - t) > 60*60*24*7) {
3313 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
3319 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3320 cli_openx(cli, fname,
3321 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
3322 cli_close(cli, fnum);
3323 status = cli_qpathinfo2(cli, fname, &c_time_ts, &a_time_ts, &w_time_ts,
3324 &m_time_ts, &size, NULL, NULL);
3325 if (!NT_STATUS_IS_OK(status)) {
3326 printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status));
3329 if (w_time_ts.tv_sec < 60*60*24*2) {
3330 printf("write time=%s", ctime(&w_time_ts.tv_sec));
3331 printf("This system appears to set a initial 0 write time\n");
3336 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3339 /* check if the server updates the directory modification time
3340 when creating a new file */
3341 status = cli_mkdir(cli, dname);
3342 if (!NT_STATUS_IS_OK(status)) {
3343 printf("ERROR: mkdir failed (%s)\n", nt_errstr(status));
3347 status = cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts,
3348 &w_time_ts, &m_time_ts, &size, NULL, NULL);
3349 if (!NT_STATUS_IS_OK(status)) {
3350 printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status));
3354 cli_openx(cli, fname2,
3355 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
3356 cli_writeall(cli, fnum, 0, (uint8_t *)&fnum, 0, sizeof(fnum), NULL);
3357 cli_close(cli, fnum);
3358 status = cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts,
3359 &w_time_ts, &m_time2_ts, &size, NULL, NULL);
3360 if (!NT_STATUS_IS_OK(status)) {
3361 printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status));
3364 if (memcmp(&m_time_ts, &m_time2_ts, sizeof(struct timespec))
3366 printf("This system does not update directory modification times\n");
3370 cli_unlink(cli, fname2, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3371 cli_rmdir(cli, dname);
3373 if (!torture_close_connection(cli)) {
3377 printf("trans2 test finished\n");
3383 This checks new W2K calls.
3386 static NTSTATUS new_trans(struct cli_state *pcli, int fnum, int level)
3388 uint8_t *buf = NULL;
3392 status = cli_qfileinfo(talloc_tos(), pcli, fnum, level, 0,
3393 CLI_BUFFER_SIZE, NULL, &buf, &len);
3394 if (!NT_STATUS_IS_OK(status)) {
3395 printf("ERROR: qfileinfo (%d) failed (%s)\n", level,
3398 printf("qfileinfo: level %d, len = %u\n", level, len);
3399 dump_data(0, (uint8_t *)buf, len);
3406 static bool run_w2ktest(int dummy)
3408 struct cli_state *cli;
3410 const char *fname = "\\w2ktest\\w2k.tst";
3412 bool correct = True;
3414 printf("starting w2k test\n");
3416 if (!torture_open_connection(&cli, 0)) {
3420 cli_openx(cli, fname,
3421 O_RDWR | O_CREAT , DENY_NONE, &fnum);
3423 for (level = 1004; level < 1040; level++) {
3424 new_trans(cli, fnum, level);
3427 cli_close(cli, fnum);
3429 if (!torture_close_connection(cli)) {
3433 printf("w2k test finished\n");
3440 this is a harness for some oplock tests
3442 static bool run_oplock1(int dummy)
3444 struct cli_state *cli1;
3445 const char *fname = "\\lockt1.lck";
3447 bool correct = True;
3450 printf("starting oplock test 1\n");
3452 if (!torture_open_connection(&cli1, 0)) {
3456 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3458 smbXcli_conn_set_sockopt(cli1->conn, sockops);
3460 cli1->use_oplocks = True;
3462 status = cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
3464 if (!NT_STATUS_IS_OK(status)) {
3465 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
3469 cli1->use_oplocks = False;
3471 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3472 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3474 status = cli_close(cli1, fnum1);
3475 if (!NT_STATUS_IS_OK(status)) {
3476 printf("close2 failed (%s)\n", nt_errstr(status));
3480 status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3481 if (!NT_STATUS_IS_OK(status)) {
3482 printf("unlink failed (%s)\n", nt_errstr(status));
3486 if (!torture_close_connection(cli1)) {
3490 printf("finished oplock test 1\n");
3495 static bool run_oplock2(int dummy)
3497 struct cli_state *cli1, *cli2;
3498 const char *fname = "\\lockt2.lck";
3499 uint16_t fnum1, fnum2;
3500 int saved_use_oplocks = use_oplocks;
3502 bool correct = True;
3503 volatile bool *shared_correct;
3507 shared_correct = (volatile bool *)anonymous_shared_allocate(sizeof(bool));
3508 *shared_correct = True;
3510 use_level_II_oplocks = True;
3513 printf("starting oplock test 2\n");
3515 if (!torture_open_connection(&cli1, 0)) {
3516 use_level_II_oplocks = False;
3517 use_oplocks = saved_use_oplocks;
3521 if (!torture_open_connection(&cli2, 1)) {
3522 use_level_II_oplocks = False;
3523 use_oplocks = saved_use_oplocks;
3527 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3529 smbXcli_conn_set_sockopt(cli1->conn, sockops);
3530 smbXcli_conn_set_sockopt(cli2->conn, sockops);
3532 status = cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
3534 if (!NT_STATUS_IS_OK(status)) {
3535 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
3539 /* Don't need the globals any more. */
3540 use_level_II_oplocks = False;
3541 use_oplocks = saved_use_oplocks;
3545 status = cli_openx(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
3546 if (!NT_STATUS_IS_OK(status)) {
3547 printf("second open of %s failed (%s)\n", fname, nt_errstr(status));
3548 *shared_correct = False;
3554 status = cli_close(cli2, fnum2);
3555 if (!NT_STATUS_IS_OK(status)) {
3556 printf("close2 failed (%s)\n", nt_errstr(status));
3557 *shared_correct = False;
3565 /* Ensure cli1 processes the break. Empty file should always return 0
3567 status = cli_read(cli1, fnum1, buf, 0, 4, &nread);
3568 if (!NT_STATUS_IS_OK(status)) {
3569 printf("read on fnum1 failed (%s)\n", nt_errstr(status));
3571 } else if (nread != 0) {
3572 printf("read on empty fnum1 failed. recv %ld expected %d\n",
3573 (unsigned long)nread, 0);
3577 /* Should now be at level II. */
3578 /* Test if sending a write locks causes a break to none. */
3579 status = cli_lock32(cli1, fnum1, 0, 4, 0, READ_LOCK);
3580 if (!NT_STATUS_IS_OK(status)) {
3581 printf("lock failed (%s)\n", nt_errstr(status));
3585 cli_unlock(cli1, fnum1, 0, 4);
3589 status = cli_lock32(cli1, fnum1, 0, 4, 0, WRITE_LOCK);
3590 if (!NT_STATUS_IS_OK(status)) {
3591 printf("lock failed (%s)\n", nt_errstr(status));
3595 cli_unlock(cli1, fnum1, 0, 4);
3599 cli_read(cli1, fnum1, buf, 0, 4, NULL);
3601 status = cli_close(cli1, fnum1);
3602 if (!NT_STATUS_IS_OK(status)) {
3603 printf("close1 failed (%s)\n", nt_errstr(status));
3609 status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3610 if (!NT_STATUS_IS_OK(status)) {
3611 printf("unlink failed (%s)\n", nt_errstr(status));
3615 if (!torture_close_connection(cli1)) {
3619 if (!*shared_correct) {
3623 printf("finished oplock test 2\n");
3628 struct oplock4_state {
3629 struct tevent_context *ev;
3630 struct cli_state *cli;
3635 static void oplock4_got_break(struct tevent_req *req);
3636 static void oplock4_got_open(struct tevent_req *req);
3638 static bool run_oplock4(int dummy)
3640 struct tevent_context *ev;
3641 struct cli_state *cli1, *cli2;
3642 struct tevent_req *oplock_req, *open_req;
3643 const char *fname = "\\lockt4.lck";
3644 const char *fname_ln = "\\lockt4_ln.lck";
3645 uint16_t fnum1, fnum2;
3646 int saved_use_oplocks = use_oplocks;
3648 bool correct = true;
3652 struct oplock4_state *state;
3654 printf("starting oplock test 4\n");
3656 if (!torture_open_connection(&cli1, 0)) {
3657 use_level_II_oplocks = false;
3658 use_oplocks = saved_use_oplocks;
3662 if (!torture_open_connection(&cli2, 1)) {
3663 use_level_II_oplocks = false;
3664 use_oplocks = saved_use_oplocks;
3668 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3669 cli_unlink(cli1, fname_ln, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3671 smbXcli_conn_set_sockopt(cli1->conn, sockops);
3672 smbXcli_conn_set_sockopt(cli2->conn, sockops);
3674 /* Create the file. */
3675 status = cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
3677 if (!NT_STATUS_IS_OK(status)) {
3678 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
3682 status = cli_close(cli1, fnum1);
3683 if (!NT_STATUS_IS_OK(status)) {
3684 printf("close1 failed (%s)\n", nt_errstr(status));
3688 /* Now create a hardlink. */
3689 status = cli_nt_hardlink(cli1, fname, fname_ln);
3690 if (!NT_STATUS_IS_OK(status)) {
3691 printf("nt hardlink failed (%s)\n", nt_errstr(status));
3695 /* Prove that opening hardlinks cause deny modes to conflict. */
3696 status = cli_openx(cli1, fname, O_RDWR, DENY_ALL, &fnum1);
3697 if (!NT_STATUS_IS_OK(status)) {
3698 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
3702 status = cli_openx(cli1, fname_ln, O_RDWR, DENY_NONE, &fnum2);
3703 if (NT_STATUS_IS_OK(status)) {
3704 printf("open of %s succeeded - should fail with sharing violation.\n",
3709 if (!NT_STATUS_EQUAL(status, NT_STATUS_SHARING_VIOLATION)) {
3710 printf("open of %s should fail with sharing violation. Got %s\n",
3711 fname_ln, nt_errstr(status));
3715 status = cli_close(cli1, fnum1);
3716 if (!NT_STATUS_IS_OK(status)) {
3717 printf("close1 failed (%s)\n", nt_errstr(status));
3721 cli1->use_oplocks = true;
3722 cli2->use_oplocks = true;
3724 status = cli_openx(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
3725 if (!NT_STATUS_IS_OK(status)) {
3726 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
3730 ev = samba_tevent_context_init(talloc_tos());
3732 printf("tevent_context_init failed\n");
3736 state = talloc(ev, struct oplock4_state);
3737 if (state == NULL) {
3738 printf("talloc failed\n");
3743 state->got_break = &got_break;
3744 state->fnum2 = &fnum2;
3746 oplock_req = cli_smb_oplock_break_waiter_send(
3747 talloc_tos(), ev, cli1);
3748 if (oplock_req == NULL) {
3749 printf("cli_smb_oplock_break_waiter_send failed\n");
3752 tevent_req_set_callback(oplock_req, oplock4_got_break, state);
3754 open_req = cli_openx_send(
3755 talloc_tos(), ev, cli2, fname_ln, O_RDWR, DENY_NONE);
3756 if (open_req == NULL) {
3757 printf("cli_openx_send failed\n");
3760 tevent_req_set_callback(open_req, oplock4_got_open, state);
3765 while (!got_break || fnum2 == 0xffff) {
3767 ret = tevent_loop_once(ev);
3769 printf("tevent_loop_once failed: %s\n",
3775 status = cli_close(cli2, fnum2);
3776 if (!NT_STATUS_IS_OK(status)) {
3777 printf("close2 failed (%s)\n", nt_errstr(status));
3781 status = cli_close(cli1, fnum1);
3782 if (!NT_STATUS_IS_OK(status)) {
3783 printf("close1 failed (%s)\n", nt_errstr(status));
3787 status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3788 if (!NT_STATUS_IS_OK(status)) {
3789 printf("unlink failed (%s)\n", nt_errstr(status));
3793 status = cli_unlink(cli1, fname_ln, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3794 if (!NT_STATUS_IS_OK(status)) {
3795 printf("unlink failed (%s)\n", nt_errstr(status));
3799 if (!torture_close_connection(cli1)) {
3807 printf("finished oplock test 4\n");
3812 static void oplock4_got_break(struct tevent_req *req)
3814 struct oplock4_state *state = tevent_req_callback_data(
3815 req, struct oplock4_state);
3820 status = cli_smb_oplock_break_waiter_recv(req, &fnum, &level);
3822 if (!NT_STATUS_IS_OK(status)) {
3823 printf("cli_smb_oplock_break_waiter_recv returned %s\n",
3827 *state->got_break = true;
3829 req = cli_oplock_ack_send(state, state->ev, state->cli, fnum,
3832 printf("cli_oplock_ack_send failed\n");
3837 static void oplock4_got_open(struct tevent_req *req)
3839 struct oplock4_state *state = tevent_req_callback_data(
3840 req, struct oplock4_state);
3843 status = cli_openx_recv(req, state->fnum2);
3844 if (!NT_STATUS_IS_OK(status)) {
3845 printf("cli_openx_recv returned %s\n", nt_errstr(status));
3846 *state->fnum2 = 0xffff;
3851 Test delete on close semantics.
3853 static bool run_deletetest(int dummy)
3855 struct cli_state *cli1 = NULL;
3856 struct cli_state *cli2 = NULL;
3857 const char *fname = "\\delete.file";
3858 uint16_t fnum1 = (uint16_t)-1;
3859 uint16_t fnum2 = (uint16_t)-1;
3860 bool correct = false;
3863 printf("starting delete test\n");
3865 if (!torture_open_connection(&cli1, 0)) {
3869 smbXcli_conn_set_sockopt(cli1->conn, sockops);
3871 /* Test 1 - this should delete the file on close. */
3873 cli_setatr(cli1, fname, 0, 0);
3874 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3876 status = cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
3877 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
3878 FILE_DELETE_ON_CLOSE, 0, &fnum1, NULL);
3879 if (!NT_STATUS_IS_OK(status)) {
3880 printf("[1] open of %s failed (%s)\n", fname, nt_errstr(status));
3884 status = cli_close(cli1, fnum1);
3885 if (!NT_STATUS_IS_OK(status)) {
3886 printf("[1] close failed (%s)\n", nt_errstr(status));
3890 status = cli_openx(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
3891 if (NT_STATUS_IS_OK(status)) {
3892 printf("[1] open of %s succeeded (should fail)\n", fname);
3896 printf("first delete on close test succeeded.\n");
3898 /* Test 2 - this should delete the file on close. */
3900 cli_setatr(cli1, fname, 0, 0);
3901 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3903 status = cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS,
3904 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
3905 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
3906 if (!NT_STATUS_IS_OK(status)) {
3907 printf("[2] open of %s failed (%s)\n", fname, nt_errstr(status));
3911 status = cli_nt_delete_on_close(cli1, fnum1, true);
3912 if (!NT_STATUS_IS_OK(status)) {
3913 printf("[2] setting delete_on_close failed (%s)\n", nt_errstr(status));
3917 status = cli_close(cli1, fnum1);
3918 if (!NT_STATUS_IS_OK(status)) {
3919 printf("[2] close failed (%s)\n", nt_errstr(status));
3923 status = cli_openx(cli1, fname, O_RDONLY, DENY_NONE, &fnum1);
3924 if (NT_STATUS_IS_OK(status)) {
3925 printf("[2] open of %s succeeded should have been deleted on close !\n", fname);
3926 status = cli_close(cli1, fnum1);
3927 if (!NT_STATUS_IS_OK(status)) {
3928 printf("[2] close failed (%s)\n", nt_errstr(status));
3930 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3934 printf("second delete on close test succeeded.\n");
3937 cli_setatr(cli1, fname, 0, 0);
3938 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3940 status = cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS,
3941 FILE_ATTRIBUTE_NORMAL,
3942 FILE_SHARE_READ|FILE_SHARE_WRITE,
3943 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
3944 if (!NT_STATUS_IS_OK(status)) {
3945 printf("[3] open - 1 of %s failed (%s)\n", fname, nt_errstr(status));
3949 /* This should fail with a sharing violation - open for delete is only compatible
3950 with SHARE_DELETE. */
3952 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
3953 FILE_ATTRIBUTE_NORMAL,
3954 FILE_SHARE_READ|FILE_SHARE_WRITE,
3955 FILE_OPEN, 0, 0, &fnum2, NULL);
3956 if (NT_STATUS_IS_OK(status)) {
3957 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname);
3961 /* This should succeed. */
3962 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
3963 FILE_ATTRIBUTE_NORMAL,
3964 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3965 FILE_OPEN, 0, 0, &fnum2, NULL);
3966 if (!NT_STATUS_IS_OK(status)) {
3967 printf("[3] open - 3 of %s failed (%s)\n", fname, nt_errstr(status));
3971 status = cli_nt_delete_on_close(cli1, fnum1, true);
3972 if (!NT_STATUS_IS_OK(status)) {
3973 printf("[3] setting delete_on_close failed (%s)\n", nt_errstr(status));
3977 status = cli_close(cli1, fnum1);
3978 if (!NT_STATUS_IS_OK(status)) {
3979 printf("[3] close 1 failed (%s)\n", nt_errstr(status));
3983 status = cli_close(cli1, fnum2);
3984 if (!NT_STATUS_IS_OK(status)) {
3985 printf("[3] close 2 failed (%s)\n", nt_errstr(status));
3989 /* This should fail - file should no longer be there. */
3991 status = cli_openx(cli1, fname, O_RDONLY, DENY_NONE, &fnum1);
3992 if (NT_STATUS_IS_OK(status)) {
3993 printf("[3] open of %s succeeded should have been deleted on close !\n", fname);
3994 status = cli_close(cli1, fnum1);
3995 if (!NT_STATUS_IS_OK(status)) {
3996 printf("[3] close failed (%s)\n", nt_errstr(status));
3998 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4002 printf("third delete on close test succeeded.\n");
4005 cli_setatr(cli1, fname, 0, 0);
4006 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4008 status = cli_ntcreate(cli1, fname, 0,
4009 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
4010 FILE_ATTRIBUTE_NORMAL,
4011 FILE_SHARE_READ|FILE_SHARE_WRITE,
4012 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
4013 if (!NT_STATUS_IS_OK(status)) {
4014 printf("[4] open of %s failed (%s)\n", fname, nt_errstr(status));
4018 /* This should succeed. */
4019 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
4020 FILE_ATTRIBUTE_NORMAL,
4021 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4022 FILE_OPEN, 0, 0, &fnum2, NULL);
4023 if (!NT_STATUS_IS_OK(status)) {
4024 printf("[4] open - 2 of %s failed (%s)\n", fname, nt_errstr(status));
4028 status = cli_close(cli1, fnum2);
4029 if (!NT_STATUS_IS_OK(status)) {
4030 printf("[4] close - 1 failed (%s)\n", nt_errstr(status));
4034 status = cli_nt_delete_on_close(cli1, fnum1, true);
4035 if (!NT_STATUS_IS_OK(status)) {
4036 printf("[4] setting delete_on_close failed (%s)\n", nt_errstr(status));
4040 /* This should fail - no more opens once delete on close set. */
4041 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
4042 FILE_ATTRIBUTE_NORMAL,
4043 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4044 FILE_OPEN, 0, 0, &fnum2, NULL);
4045 if (NT_STATUS_IS_OK(status)) {
4046 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname );
4050 status = cli_close(cli1, fnum1);
4051 if (!NT_STATUS_IS_OK(status)) {
4052 printf("[4] close - 2 failed (%s)\n", nt_errstr(status));
4056 printf("fourth delete on close test succeeded.\n");
4059 cli_setatr(cli1, fname, 0, 0);
4060 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4062 status = cli_openx(cli1, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum1);
4063 if (!NT_STATUS_IS_OK(status)) {
4064 printf("[5] open of %s failed (%s)\n", fname, nt_errstr(status));
4068 /* This should fail - only allowed on NT opens with DELETE access. */
4070 status = cli_nt_delete_on_close(cli1, fnum1, true);
4071 if (NT_STATUS_IS_OK(status)) {
4072 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
4076 status = cli_close(cli1, fnum1);
4077 if (!NT_STATUS_IS_OK(status)) {
4078 printf("[5] close failed (%s)\n", nt_errstr(status));
4082 printf("fifth delete on close test succeeded.\n");
4085 cli_setatr(cli1, fname, 0, 0);
4086 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4088 status = cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
4089 FILE_ATTRIBUTE_NORMAL,
4090 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4091 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
4092 if (!NT_STATUS_IS_OK(status)) {
4093 printf("[6] open of %s failed (%s)\n", fname,
4098 /* This should fail - only allowed on NT opens with DELETE access. */
4100 status = cli_nt_delete_on_close(cli1, fnum1, true);
4101 if (NT_STATUS_IS_OK(status)) {
4102 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
4106 status = cli_close(cli1, fnum1);
4107 if (!NT_STATUS_IS_OK(status)) {
4108 printf("[6] close failed (%s)\n", nt_errstr(status));
4112 printf("sixth delete on close test succeeded.\n");
4115 cli_setatr(cli1, fname, 0, 0);
4116 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4118 status = cli_ntcreate(cli1, fname, 0,
4119 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
4120 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
4121 0, 0, &fnum1, NULL);
4122 if (!NT_STATUS_IS_OK(status)) {
4123 printf("[7] open of %s failed (%s)\n", fname, nt_errstr(status));
4127 status = cli_nt_delete_on_close(cli1, fnum1, true);
4128 if (!NT_STATUS_IS_OK(status)) {
4129 printf("[7] setting delete_on_close on file failed !\n");
4133 status = cli_nt_delete_on_close(cli1, fnum1, false);
4134 if (!NT_STATUS_IS_OK(status)) {
4135 printf("[7] unsetting delete_on_close on file failed !\n");
4139 status = cli_close(cli1, fnum1);
4140 if (!NT_STATUS_IS_OK(status)) {
4141 printf("[7] close - 1 failed (%s)\n", nt_errstr(status));
4145 /* This next open should succeed - we reset the flag. */
4146 status = cli_openx(cli1, fname, O_RDONLY, DENY_NONE, &fnum1);
4147 if (!NT_STATUS_IS_OK(status)) {
4148 printf("[7] open of %s failed (%s)\n", fname, nt_errstr(status));
4152 status = cli_close(cli1, fnum1);
4153 if (!NT_STATUS_IS_OK(status)) {
4154 printf("[7] close - 2 failed (%s)\n", nt_errstr(status));
4158 printf("seventh delete on close test succeeded.\n");
4161 cli_setatr(cli1, fname, 0, 0);
4162 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4164 if (!torture_open_connection(&cli2, 1)) {
4165 printf("[8] failed to open second connection.\n");
4169 smbXcli_conn_set_sockopt(cli1->conn, sockops);
4171 status = cli_ntcreate(cli1, fname, 0,
4172 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
4173 FILE_ATTRIBUTE_NORMAL,
4174 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4175 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
4176 if (!NT_STATUS_IS_OK(status)) {
4177 printf("[8] open 1 of %s failed (%s)\n", fname, nt_errstr(status));
4181 status = cli_ntcreate(cli2, fname, 0,
4182 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
4183 FILE_ATTRIBUTE_NORMAL,
4184 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4185 FILE_OPEN, 0, 0, &fnum2, NULL);
4186 if (!NT_STATUS_IS_OK(status)) {
4187 printf("[8] open 2 of %s failed (%s)\n", fname, nt_errstr(status));
4191 status = cli_nt_delete_on_close(cli1, fnum1, true);
4192 if (!NT_STATUS_IS_OK(status)) {
4193 printf("[8] setting delete_on_close on file failed !\n");
4197 status = cli_close(cli1, fnum1);
4198 if (!NT_STATUS_IS_OK(status)) {
4199 printf("[8] close - 1 failed (%s)\n", nt_errstr(status));
4203 status = cli_close(cli2, fnum2);
4204 if (!NT_STATUS_IS_OK(status)) {
4205 printf("[8] close - 2 failed (%s)\n", nt_errstr(status));
4209 /* This should fail.. */
4210 status = cli_openx(cli1, fname, O_RDONLY, DENY_NONE, &fnum1);
4211 if (NT_STATUS_IS_OK(status)) {
4212 printf("[8] open of %s succeeded should have been deleted on close !\n", fname);
4216 printf("eighth delete on close test succeeded.\n");
4220 /* This should fail - we need to set DELETE_ACCESS. */
4221 status = cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
4222 FILE_ATTRIBUTE_NORMAL,
4225 FILE_DELETE_ON_CLOSE, 0, &fnum1, NULL);
4226 if (NT_STATUS_IS_OK(status)) {
4227 printf("[9] open of %s succeeded should have failed!\n", fname);
4231 printf("ninth delete on close test succeeded.\n");
4235 status = cli_ntcreate(cli1, fname, 0,
4236 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
4237 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
4238 FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE,
4240 if (!NT_STATUS_IS_OK(status)) {
4241 printf("[10] open of %s failed (%s)\n", fname, nt_errstr(status));
4245 /* This should delete the file. */
4246 status = cli_close(cli1, fnum1);
4247 if (!NT_STATUS_IS_OK(status)) {
4248 printf("[10] close failed (%s)\n", nt_errstr(status));
4252 /* This should fail.. */
4253 status = cli_openx(cli1, fname, O_RDONLY, DENY_NONE, &fnum1);
4254 if (NT_STATUS_IS_OK(status)) {
4255 printf("[10] open of %s succeeded should have been deleted on close !\n", fname);
4259 printf("tenth delete on close test succeeded.\n");
4263 cli_setatr(cli1, fname, 0, 0);
4264 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4266 /* Can we open a read-only file with delete access? */
4268 /* Create a readonly file. */
4269 status = cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
4270 FILE_ATTRIBUTE_READONLY, FILE_SHARE_NONE,
4271 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
4272 if (!NT_STATUS_IS_OK(status)) {
4273 printf("[11] open of %s failed (%s)\n", fname, nt_errstr(status));
4277 status = cli_close(cli1, fnum1);
4278 if (!NT_STATUS_IS_OK(status)) {
4279 printf("[11] close failed (%s)\n", nt_errstr(status));
4283 /* Now try open for delete access. */
4284 status = cli_ntcreate(cli1, fname, 0,
4285 FILE_READ_ATTRIBUTES|DELETE_ACCESS,
4287 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4288 FILE_OPEN, 0, 0, &fnum1, NULL);
4289 if (!NT_STATUS_IS_OK(status)) {
4290 printf("[11] open of %s failed: %s\n", fname, nt_errstr(status));
4294 cli_close(cli1, fnum1);
4296 printf("eleventh delete on close test succeeded.\n");
4300 * like test 4 but with initial delete on close
4303 cli_setatr(cli1, fname, 0, 0);
4304 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4306 status = cli_ntcreate(cli1, fname, 0,
4307 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
4308 FILE_ATTRIBUTE_NORMAL,
4309 FILE_SHARE_READ|FILE_SHARE_WRITE,
4311 FILE_DELETE_ON_CLOSE, 0, &fnum1, NULL);
4312 if (!NT_STATUS_IS_OK(status)) {
4313 printf("[12] open 1 of %s failed (%s)\n", fname, nt_errstr(status));
4317 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
4318 FILE_ATTRIBUTE_NORMAL,
4319 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4320 FILE_OPEN, 0, 0, &fnum2, NULL);
4321 if (!NT_STATUS_IS_OK(status)) {
4322 printf("[12] open 2 of %s failed(%s).\n", fname, nt_errstr(status));
4326 status = cli_close(cli1, fnum2);
4327 if (!NT_STATUS_IS_OK(status)) {
4328 printf("[12] close 1 failed (%s)\n", nt_errstr(status));
4332 status = cli_nt_delete_on_close(cli1, fnum1, true);
4333 if (!NT_STATUS_IS_OK(status)) {
4334 printf("[12] setting delete_on_close failed (%s)\n", nt_errstr(status));
4338 /* This should fail - no more opens once delete on close set. */
4339 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
4340 FILE_ATTRIBUTE_NORMAL,
4341 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4342 FILE_OPEN, 0, 0, &fnum2, NULL);
4343 if (NT_STATUS_IS_OK(status)) {
4344 printf("[12] open 3 of %s succeeded - should fail).\n", fname);
4348 status = cli_nt_delete_on_close(cli1, fnum1, false);
4349 if (!NT_STATUS_IS_OK(status)) {
4350 printf("[12] unsetting delete_on_close failed (%s)\n", nt_errstr(status));
4354 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
4355 FILE_ATTRIBUTE_NORMAL,
4356 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4357 FILE_OPEN, 0, 0, &fnum2, NULL);
4358 if (!NT_STATUS_IS_OK(status)) {
4359 printf("[12] open 4 of %s failed (%s)\n", fname, nt_errstr(status));
4363 status = cli_close(cli1, fnum2);
4364 if (!NT_STATUS_IS_OK(status)) {
4365 printf("[12] close 2 failed (%s)\n", nt_errstr(status));
4369 status = cli_close(cli1, fnum1);
4370 if (!NT_STATUS_IS_OK(status)) {
4371 printf("[12] close 3 failed (%s)\n", nt_errstr(status));
4376 * setting delete on close on the handle does
4377 * not unset the initial delete on close...
4379 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
4380 FILE_ATTRIBUTE_NORMAL,
4381 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4382 FILE_OPEN, 0, 0, &fnum2, NULL);
4383 if (NT_STATUS_IS_OK(status)) {
4384 printf("[12] open 5 of %s succeeded - should fail).\n", fname);
4386 } else if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
4387 printf("ntcreate returned %s, expected "
4388 "NT_STATUS_OBJECT_NAME_NOT_FOUND\n",
4393 printf("twelfth delete on close test succeeded.\n");
4396 printf("finished delete test\n");
4401 /* FIXME: This will crash if we aborted before cli2 got
4402 * intialized, because these functions don't handle
4403 * uninitialized connections. */
4405 if (fnum1 != (uint16_t)-1) cli_close(cli1, fnum1);
4406 if (fnum2 != (uint16_t)-1) cli_close(cli1, fnum2);
4407 cli_setatr(cli1, fname, 0, 0);
4408 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4410 if (cli1 && !torture_close_connection(cli1)) {
4413 if (cli2 && !torture_close_connection(cli2)) {
4421 Test wildcard delete.
4423 static bool run_wild_deletetest(int dummy)
4425 struct cli_state *cli = NULL;
4426 const char *dname = "\\WTEST";
4427 const char *fname = "\\WTEST\\A";
4428 const char *wunlink_name = "\\WTEST\\*";
4429 uint16_t fnum1 = (uint16_t)-1;
4430 bool correct = false;
4433 printf("starting wildcard delete test\n");
4435 if (!torture_open_connection(&cli, 0)) {
4439 smbXcli_conn_set_sockopt(cli->conn, sockops);
4441 cli_unlink(cli, fname, 0);
4442 cli_rmdir(cli, dname);
4443 status = cli_mkdir(cli, dname);
4444 if (!NT_STATUS_IS_OK(status)) {
4445 printf("mkdir of %s failed %s!\n", dname, nt_errstr(status));
4448 status = cli_openx(cli, fname, O_CREAT|O_RDONLY, DENY_NONE, &fnum1);
4449 if (!NT_STATUS_IS_OK(status)) {
4450 printf("open of %s failed %s!\n", fname, nt_errstr(status));
4453 status = cli_close(cli, fnum1);
4457 * Note the unlink attribute-type of zero. This should
4458 * map into FILE_ATTRIBUTE_NORMAL at the server even
4459 * on a wildcard delete.
4462 status = cli_unlink(cli, wunlink_name, 0);
4463 if (!NT_STATUS_IS_OK(status)) {
4464 printf("unlink of %s failed %s!\n",
4465 wunlink_name, nt_errstr(status));
4469 printf("finished wildcard delete test\n");
4475 if (fnum1 != (uint16_t)-1) cli_close(cli, fnum1);
4476 cli_unlink(cli, fname, 0);
4477 cli_rmdir(cli, dname);
4479 if (cli && !torture_close_connection(cli)) {
4485 static bool run_deletetest_ln(int dummy)
4487 struct cli_state *cli;
4488 const char *fname = "\\delete1";
4489 const char *fname_ln = "\\delete1_ln";
4493 bool correct = true;
4496 printf("starting deletetest-ln\n");
4498 if (!torture_open_connection(&cli, 0)) {
4502 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4503 cli_unlink(cli, fname_ln, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4505 smbXcli_conn_set_sockopt(cli->conn, sockops);
4507 /* Create the file. */
4508 status = cli_openx(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
4509 if (!NT_STATUS_IS_OK(status)) {
4510 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
4514 status = cli_close(cli, fnum);
4515 if (!NT_STATUS_IS_OK(status)) {
4516 printf("close1 failed (%s)\n", nt_errstr(status));
4520 /* Now create a hardlink. */
4521 status = cli_nt_hardlink(cli, fname, fname_ln);
4522 if (!NT_STATUS_IS_OK(status)) {
4523 printf("nt hardlink failed (%s)\n", nt_errstr(status));
4527 /* Open the original file. */
4528 status = cli_ntcreate(cli, fname, 0, FILE_READ_DATA,
4529 FILE_ATTRIBUTE_NORMAL,
4530 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4531 FILE_OPEN_IF, 0, 0, &fnum, NULL);
4532 if (!NT_STATUS_IS_OK(status)) {
4533 printf("ntcreate of %s failed (%s)\n", fname, nt_errstr(status));
4537 /* Unlink the hard link path. */
4538 status = cli_ntcreate(cli, fname_ln, 0, DELETE_ACCESS,
4539 FILE_ATTRIBUTE_NORMAL,
4540 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4541 FILE_OPEN_IF, 0, 0, &fnum1, NULL);
4542 if (!NT_STATUS_IS_OK(status)) {
4543 printf("ntcreate of %s failed (%s)\n", fname_ln, nt_errstr(status));
4546 status = cli_nt_delete_on_close(cli, fnum1, true);
4547 if (!NT_STATUS_IS_OK(status)) {
4548 d_printf("(%s) failed to set delete_on_close %s: %s\n",
4549 __location__, fname_ln, nt_errstr(status));
4553 status = cli_close(cli, fnum1);
4554 if (!NT_STATUS_IS_OK(status)) {
4555 printf("close %s failed (%s)\n",
4556 fname_ln, nt_errstr(status));
4560 status = cli_close(cli, fnum);
4561 if (!NT_STATUS_IS_OK(status)) {
4562 printf("close %s failed (%s)\n",
4563 fname, nt_errstr(status));
4567 /* Ensure the original file is still there. */
4568 status = cli_getatr(cli, fname, NULL, NULL, &t);
4569 if (!NT_STATUS_IS_OK(status)) {
4570 printf("%s getatr on file %s failed (%s)\n",
4577 /* Ensure the link path is gone. */
4578 status = cli_getatr(cli, fname_ln, NULL, NULL, &t);
4579 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
4580 printf("%s, getatr for file %s returned wrong error code %s "
4581 "- should have been deleted\n",
4583 fname_ln, nt_errstr(status));
4587 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4588 cli_unlink(cli, fname_ln, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4590 if (!torture_close_connection(cli)) {
4594 printf("finished deletetest-ln\n");
4600 print out server properties
4602 static bool run_properties(int dummy)
4604 struct cli_state *cli;
4605 bool correct = True;
4607 printf("starting properties test\n");
4611 if (!torture_open_connection(&cli, 0)) {
4615 smbXcli_conn_set_sockopt(cli->conn, sockops);
4617 d_printf("Capabilities 0x%08x\n", smb1cli_conn_capabilities(cli->conn));
4619 if (!torture_close_connection(cli)) {
4628 /* FIRST_DESIRED_ACCESS 0xf019f */
4629 #define FIRST_DESIRED_ACCESS FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|\
4630 FILE_READ_EA| /* 0xf */ \
4631 FILE_WRITE_EA|FILE_READ_ATTRIBUTES| /* 0x90 */ \
4632 FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
4633 DELETE_ACCESS|READ_CONTROL_ACCESS|\
4634 WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS /* 0xf0000 */
4635 /* SECOND_DESIRED_ACCESS 0xe0080 */
4636 #define SECOND_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
4637 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
4638 WRITE_OWNER_ACCESS /* 0xe0000 */
4641 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
4642 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
4644 WRITE_OWNER_ACCESS /* */
4648 Test ntcreate calls made by xcopy
4650 static bool run_xcopy(int dummy)
4652 static struct cli_state *cli1;
4653 const char *fname = "\\test.txt";
4654 bool correct = True;
4655 uint16_t fnum1, fnum2;
4658 printf("starting xcopy test\n");
4660 if (!torture_open_connection(&cli1, 0)) {
4664 status = cli_ntcreate(cli1, fname, 0, FIRST_DESIRED_ACCESS,
4665 FILE_ATTRIBUTE_ARCHIVE, FILE_SHARE_NONE,
4666 FILE_OVERWRITE_IF, 0x4044, 0, &fnum1, NULL);
4667 if (!NT_STATUS_IS_OK(status)) {
4668 printf("First open failed - %s\n", nt_errstr(status));
4672 status = cli_ntcreate(cli1, fname, 0, SECOND_DESIRED_ACCESS, 0,
4673 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4674 FILE_OPEN, 0x200000, 0, &fnum2, NULL);
4675 if (!NT_STATUS_IS_OK(status)) {
4676 printf("second open failed - %s\n", nt_errstr(status));
4680 if (!torture_close_connection(cli1)) {
4688 Test rename on files open with share delete and no share delete.
4690 static bool run_rename(int dummy)
4692 static struct cli_state *cli1;
4693 const char *fname = "\\test.txt";
4694 const char *fname1 = "\\test1.txt";
4695 bool correct = True;
4700 printf("starting rename test\n");
4702 if (!torture_open_connection(&cli1, 0)) {
4706 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4707 cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4709 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
4710 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ,
4711 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
4712 if (!NT_STATUS_IS_OK(status)) {
4713 printf("First open failed - %s\n", nt_errstr(status));
4717 status = cli_rename(cli1, fname, fname1, false);
4718 if (!NT_STATUS_IS_OK(status)) {
4719 printf("First rename failed (SHARE_READ) (this is correct) - %s\n", nt_errstr(status));
4721 printf("First rename succeeded (SHARE_READ) - this should have failed !\n");
4725 status = cli_close(cli1, fnum1);
4726 if (!NT_STATUS_IS_OK(status)) {
4727 printf("close - 1 failed (%s)\n", nt_errstr(status));
4731 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4732 cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4733 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
4735 FILE_SHARE_DELETE|FILE_SHARE_NONE,
4737 FILE_SHARE_DELETE|FILE_SHARE_READ,
4739 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
4740 if (!NT_STATUS_IS_OK(status)) {
4741 printf("Second open failed - %s\n", nt_errstr(status));
4745 status = cli_rename(cli1, fname, fname1, false);
4746 if (!NT_STATUS_IS_OK(status)) {
4747 printf("Second rename failed (SHARE_DELETE | SHARE_READ) - this should have succeeded - %s\n", nt_errstr(status));
4750 printf("Second rename succeeded (SHARE_DELETE | SHARE_READ)\n");
4753 status = cli_close(cli1, fnum1);
4754 if (!NT_STATUS_IS_OK(status)) {
4755 printf("close - 2 failed (%s)\n", nt_errstr(status));
4759 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4760 cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4762 status = cli_ntcreate(cli1, fname, 0, READ_CONTROL_ACCESS,
4763 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
4764 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
4765 if (!NT_STATUS_IS_OK(status)) {
4766 printf("Third open failed - %s\n", nt_errstr(status));
4775 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
4776 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum2, NULL))) {
4777 printf("Fourth open failed - %s\n", cli_errstr(cli1));
4780 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum2, true))) {
4781 printf("[8] setting delete_on_close on file failed !\n");
4785 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum2))) {
4786 printf("close - 4 failed (%s)\n", cli_errstr(cli1));
4792 status = cli_rename(cli1, fname, fname1, false);
4793 if (!NT_STATUS_IS_OK(status)) {
4794 printf("Third rename failed (SHARE_NONE) - this should have succeeded - %s\n", nt_errstr(status));
4797 printf("Third rename succeeded (SHARE_NONE)\n");
4800 status = cli_close(cli1, fnum1);
4801 if (!NT_STATUS_IS_OK(status)) {
4802 printf("close - 3 failed (%s)\n", nt_errstr(status));
4806 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4807 cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4811 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
4812 FILE_ATTRIBUTE_NORMAL,
4813 FILE_SHARE_READ | FILE_SHARE_WRITE,
4814 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
4815 if (!NT_STATUS_IS_OK(status)) {
4816 printf("Fourth open failed - %s\n", nt_errstr(status));
4820 status = cli_rename(cli1, fname, fname1, false);
4821 if (!NT_STATUS_IS_OK(status)) {
4822 printf("Fourth rename failed (SHARE_READ | SHARE_WRITE) (this is correct) - %s\n", nt_errstr(status));
4824 printf("Fourth rename succeeded (SHARE_READ | SHARE_WRITE) - this should have failed !\n");
4828 status = cli_close(cli1, fnum1);
4829 if (!NT_STATUS_IS_OK(status)) {
4830 printf("close - 4 failed (%s)\n", nt_errstr(status));
4834 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4835 cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4839 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
4840 FILE_ATTRIBUTE_NORMAL,
4841 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
4842 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
4843 if (!NT_STATUS_IS_OK(status)) {
4844 printf("Fifth open failed - %s\n", nt_errstr(status));
4848 status = cli_rename(cli1, fname, fname1, false);
4849 if (!NT_STATUS_IS_OK(status)) {
4850 printf("Fifth rename failed (SHARE_READ | SHARE_WRITE | SHARE_DELETE) - this should have succeeded - %s ! \n", nt_errstr(status));
4853 printf("Fifth rename succeeded (SHARE_READ | SHARE_WRITE | SHARE_DELETE) (this is correct) - %s\n", nt_errstr(status));
4857 * Now check if the first name still exists ...
4860 /* if (!NT_STATUS_OP(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
4861 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
4862 FILE_OVERWRITE_IF, 0, 0, &fnum2, NULL))) {
4863 printf("Opening original file after rename of open file fails: %s\n",
4867 printf("Opening original file after rename of open file works ...\n");
4868 (void)cli_close(cli1, fnum2);
4872 status = cli_close(cli1, fnum1);
4873 if (!NT_STATUS_IS_OK(status)) {
4874 printf("close - 5 failed (%s)\n", nt_errstr(status));
4878 /* Check that the renamed file has FILE_ATTRIBUTE_ARCHIVE. */
4879 status = cli_getatr(cli1, fname1, &attr, NULL, NULL);
4880 if (!NT_STATUS_IS_OK(status)) {
4881 printf("getatr on file %s failed - %s ! \n",
4882 fname1, nt_errstr(status));
4885 if (attr != FILE_ATTRIBUTE_ARCHIVE) {
4886 printf("Renamed file %s has wrong attr 0x%x "
4887 "(should be 0x%x)\n",
4890 (unsigned int)FILE_ATTRIBUTE_ARCHIVE);
4893 printf("Renamed file %s has archive bit set\n", fname1);
4897 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4898 cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4900 if (!torture_close_connection(cli1)) {
4908 Test rename into a directory with an ACL denying it.
4910 static bool run_rename_access(int dummy)
4912 static struct cli_state *cli = NULL;
4913 static struct cli_state *posix_cli = NULL;
4914 const char *src = "test.txt";
4915 const char *dname = "dir";
4916 const char *dst = "dir\\test.txt";
4917 const char *dsrc = "test.dir";
4918 const char *ddst = "dir\\test.dir";
4919 uint16_t fnum = (uint16_t)-1;
4920 struct security_descriptor *sd = NULL;
4921 struct security_descriptor *newsd = NULL;
4923 TALLOC_CTX *frame = NULL;
4925 frame = talloc_stackframe();
4926 printf("starting rename access test\n");
4928 /* Windows connection. */
4929 if (!torture_open_connection(&cli, 0)) {
4933 smbXcli_conn_set_sockopt(cli->conn, sockops);
4935 /* Posix connection. */
4936 if (!torture_open_connection(&posix_cli, 0)) {
4940 smbXcli_conn_set_sockopt(posix_cli->conn, sockops);
4942 status = torture_setup_unix_extensions(posix_cli);
4943 if (!NT_STATUS_IS_OK(status)) {
4947 /* Start with a clean slate. */
4948 cli_unlink(cli, src, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4949 cli_unlink(cli, dst, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4950 cli_rmdir(cli, dsrc);
4951 cli_rmdir(cli, ddst);
4952 cli_rmdir(cli, dname);
4955 * Setup the destination directory with a DENY ACE to
4956 * prevent new files within it.
4958 status = cli_ntcreate(cli,
4961 FILE_READ_ATTRIBUTES|READ_CONTROL_ACCESS|
4962 WRITE_DAC_ACCESS|FILE_READ_DATA|
4964 FILE_ATTRIBUTE_DIRECTORY,
4965 FILE_SHARE_READ|FILE_SHARE_WRITE,
4967 FILE_DIRECTORY_FILE,
4971 if (!NT_STATUS_IS_OK(status)) {
4972 printf("Create of %s - %s\n", dname, nt_errstr(status));
4976 status = cli_query_secdesc(cli,
4980 if (!NT_STATUS_IS_OK(status)) {
4981 printf("cli_query_secdesc failed for %s (%s)\n",
4982 dname, nt_errstr(status));
4986 newsd = security_descriptor_dacl_create(frame,
4991 SEC_ACE_TYPE_ACCESS_DENIED,
4992 SEC_DIR_ADD_FILE|SEC_DIR_ADD_SUBDIR,
4995 if (newsd == NULL) {
4998 sd->dacl = security_acl_concatenate(frame,
5001 if (sd->dacl == NULL) {
5004 status = cli_set_secdesc(cli, fnum, sd);
5005 if (!NT_STATUS_IS_OK(status)) {
5006 printf("cli_set_secdesc failed for %s (%s)\n",
5007 dname, nt_errstr(status));
5010 status = cli_close(cli, fnum);
5011 if (!NT_STATUS_IS_OK(status)) {
5012 printf("close failed for %s (%s)\n",
5013 dname, nt_errstr(status));
5016 /* Now go around the back and chmod to 777 via POSIX. */
5017 status = cli_posix_chmod(posix_cli, dname, 0777);
5018 if (!NT_STATUS_IS_OK(status)) {
5019 printf("cli_posix_chmod failed for %s (%s)\n",
5020 dname, nt_errstr(status));
5024 /* Check we can't create a file within dname via Windows. */
5025 status = cli_openx(cli, dst, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
5026 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
5027 cli_close(posix_cli, fnum);
5028 printf("Create of %s should be ACCESS denied, was %s\n",
5029 dst, nt_errstr(status));
5033 /* Make the sample file/directory. */
5034 status = cli_openx(cli, src, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
5035 if (!NT_STATUS_IS_OK(status)) {
5036 printf("open of %s failed (%s)\n", src, nt_errstr(status));
5039 status = cli_close(cli, fnum);
5040 if (!NT_STATUS_IS_OK(status)) {
5041 printf("cli_close failed (%s)\n", nt_errstr(status));
5045 status = cli_mkdir(cli, dsrc);
5046 if (!NT_STATUS_IS_OK(status)) {
5047 printf("cli_mkdir of %s failed (%s)\n",
5048 dsrc, nt_errstr(status));
5053 * OK - renames of the new file and directory into the
5054 * dst directory should fail.
5057 status = cli_rename(cli, src, dst, false);
5058 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
5059 printf("rename of %s -> %s should be ACCESS denied, was %s\n",
5060 src, dst, nt_errstr(status));
5063 status = cli_rename(cli, dsrc, ddst, false);
5064 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
5065 printf("rename of %s -> %s should be ACCESS denied, was %s\n",
5066 src, dst, nt_errstr(status));
5076 torture_close_connection(posix_cli);
5080 if (fnum != (uint64_t)-1) {
5081 cli_close(cli, fnum);
5083 cli_unlink(cli, src,
5084 FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5085 cli_unlink(cli, dst,
5086 FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5087 cli_rmdir(cli, dsrc);
5088 cli_rmdir(cli, ddst);
5089 cli_rmdir(cli, dname);
5091 torture_close_connection(cli);
5099 Test owner rights ACE.
5101 static bool run_owner_rights(int dummy)
5103 static struct cli_state *cli = NULL;
5104 const char *fname = "owner_rights.txt";
5105 uint16_t fnum = (uint16_t)-1;
5106 struct security_descriptor *sd = NULL;
5107 struct security_descriptor *newsd = NULL;
5109 TALLOC_CTX *frame = NULL;
5111 frame = talloc_stackframe();
5112 printf("starting owner rights test\n");
5114 /* Windows connection. */
5115 if (!torture_open_connection(&cli, 0)) {
5119 smbXcli_conn_set_sockopt(cli->conn, sockops);
5121 /* Start with a clean slate. */
5122 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5124 /* Create the test file. */
5125 /* Now try and open for read and write-dac. */
5126 status = cli_ntcreate(cli,
5130 FILE_ATTRIBUTE_NORMAL,
5131 FILE_SHARE_READ|FILE_SHARE_WRITE|
5138 if (!NT_STATUS_IS_OK(status)) {
5139 printf("Create of %s - %s\n", fname, nt_errstr(status));
5143 /* Get the original SD. */
5144 status = cli_query_secdesc(cli,
5148 if (!NT_STATUS_IS_OK(status)) {
5149 printf("cli_query_secdesc failed for %s (%s)\n",
5150 fname, nt_errstr(status));
5155 * Add an "owner-rights" ACE denying WRITE_DATA,
5156 * and an "owner-rights" ACE allowing READ_DATA.
5159 newsd = security_descriptor_dacl_create(frame,
5164 SEC_ACE_TYPE_ACCESS_DENIED,
5168 SEC_ACE_TYPE_ACCESS_ALLOWED,
5172 if (newsd == NULL) {
5175 sd->dacl = security_acl_concatenate(frame,
5178 if (sd->dacl == NULL) {
5181 status = cli_set_secdesc(cli, fnum, sd);
5182 if (!NT_STATUS_IS_OK(status)) {
5183 printf("cli_set_secdesc failed for %s (%s)\n",
5184 fname, nt_errstr(status));
5187 status = cli_close(cli, fnum);
5188 if (!NT_STATUS_IS_OK(status)) {
5189 printf("close failed for %s (%s)\n",
5190 fname, nt_errstr(status));
5193 fnum = (uint16_t)-1;
5195 /* Try and open for FILE_WRITE_DATA */
5196 status = cli_ntcreate(cli,
5200 FILE_ATTRIBUTE_NORMAL,
5201 FILE_SHARE_READ|FILE_SHARE_WRITE|
5208 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
5209 printf("Open of %s - %s\n", fname, nt_errstr(status));
5213 /* Now try and open for FILE_READ_DATA */
5214 status = cli_ntcreate(cli,
5218 FILE_ATTRIBUTE_NORMAL,
5219 FILE_SHARE_READ|FILE_SHARE_WRITE|
5226 if (!NT_STATUS_IS_OK(status)) {
5227 printf("Open of %s - %s\n", fname, nt_errstr(status));
5231 status = cli_close(cli, fnum);
5232 if (!NT_STATUS_IS_OK(status)) {
5233 printf("close failed for %s (%s)\n",
5234 fname, nt_errstr(status));
5238 /* Restore clean slate. */
5240 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5242 /* Create the test file. */
5243 status = cli_ntcreate(cli,
5247 FILE_ATTRIBUTE_NORMAL,
5248 FILE_SHARE_READ|FILE_SHARE_WRITE|
5255 if (!NT_STATUS_IS_OK(status)) {
5256 printf("Create of %s - %s\n", fname, nt_errstr(status));
5260 /* Get the original SD. */
5261 status = cli_query_secdesc(cli,
5265 if (!NT_STATUS_IS_OK(status)) {
5266 printf("cli_query_secdesc failed for %s (%s)\n",
5267 fname, nt_errstr(status));
5272 * Add an "owner-rights ACE denying WRITE_DATA,
5273 * and an "owner-rights ACE allowing READ_DATA|WRITE_DATA.
5276 newsd = security_descriptor_dacl_create(frame,
5281 SEC_ACE_TYPE_ACCESS_DENIED,
5285 SEC_ACE_TYPE_ACCESS_ALLOWED,
5286 FILE_READ_DATA|FILE_WRITE_DATA,
5289 if (newsd == NULL) {
5292 sd->dacl = security_acl_concatenate(frame,
5295 if (sd->dacl == NULL) {
5298 status = cli_set_secdesc(cli, fnum, sd);
5299 if (!NT_STATUS_IS_OK(status)) {
5300 printf("cli_set_secdesc failed for %s (%s)\n",
5301 fname, nt_errstr(status));
5304 status = cli_close(cli, fnum);
5305 if (!NT_STATUS_IS_OK(status)) {
5306 printf("close failed for %s (%s)\n",
5307 fname, nt_errstr(status));
5310 fnum = (uint16_t)-1;
5312 /* Try and open for FILE_WRITE_DATA */
5313 status = cli_ntcreate(cli,
5317 FILE_ATTRIBUTE_NORMAL,
5318 FILE_SHARE_READ|FILE_SHARE_WRITE|
5325 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
5326 printf("Open of %s - %s\n", fname, nt_errstr(status));
5330 /* Now try and open for FILE_READ_DATA */
5331 status = cli_ntcreate(cli,
5335 FILE_ATTRIBUTE_NORMAL,
5336 FILE_SHARE_READ|FILE_SHARE_WRITE|
5343 if (!NT_STATUS_IS_OK(status)) {
5344 printf("Open of %s - %s\n", fname, nt_errstr(status));
5348 status = cli_close(cli, fnum);
5349 if (!NT_STATUS_IS_OK(status)) {
5350 printf("close failed for %s (%s)\n",
5351 fname, nt_errstr(status));
5355 /* Restore clean slate. */
5357 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5360 /* Create the test file. */
5361 status = cli_ntcreate(cli,
5365 FILE_ATTRIBUTE_NORMAL,
5366 FILE_SHARE_READ|FILE_SHARE_WRITE|
5373 if (!NT_STATUS_IS_OK(status)) {
5374 printf("Create of %s - %s\n", fname, nt_errstr(status));
5378 /* Get the original SD. */
5379 status = cli_query_secdesc(cli,
5383 if (!NT_STATUS_IS_OK(status)) {
5384 printf("cli_query_secdesc failed for %s (%s)\n",
5385 fname, nt_errstr(status));
5390 * Add an "authenticated users" ACE allowing READ_DATA,
5391 * add an "owner-rights" denying READ_DATA,
5392 * and an "authenticated users" ACE allowing WRITE_DATA.
5395 newsd = security_descriptor_dacl_create(frame,
5399 SID_NT_AUTHENTICATED_USERS,
5400 SEC_ACE_TYPE_ACCESS_ALLOWED,
5404 SEC_ACE_TYPE_ACCESS_DENIED,
5407 SID_NT_AUTHENTICATED_USERS,
5408 SEC_ACE_TYPE_ACCESS_ALLOWED,
5412 if (newsd == NULL) {
5413 printf("newsd == NULL\n");
5416 sd->dacl = security_acl_concatenate(frame,
5419 if (sd->dacl == NULL) {
5420 printf("sd->dacl == NULL\n");
5423 status = cli_set_secdesc(cli, fnum, sd);
5424 if (!NT_STATUS_IS_OK(status)) {
5425 printf("cli_set_secdesc failed for %s (%s)\n",
5426 fname, nt_errstr(status));
5429 status = cli_close(cli, fnum);
5430 if (!NT_STATUS_IS_OK(status)) {
5431 printf("close failed for %s (%s)\n",
5432 fname, nt_errstr(status));
5435 fnum = (uint16_t)-1;
5437 /* Now try and open for FILE_READ_DATA|FILE_WRITE_DATA */
5438 status = cli_ntcreate(cli,
5441 FILE_READ_DATA|FILE_WRITE_DATA,
5442 FILE_ATTRIBUTE_NORMAL,
5443 FILE_SHARE_READ|FILE_SHARE_WRITE|
5450 if (!NT_STATUS_IS_OK(status)) {
5451 printf("Open of %s - %s\n", fname, nt_errstr(status));
5455 status = cli_close(cli, fnum);
5456 if (!NT_STATUS_IS_OK(status)) {
5457 printf("close failed for %s (%s)\n",
5458 fname, nt_errstr(status));
5462 cli_unlink(cli, fname,
5463 FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5471 if (fnum != (uint16_t)-1) {
5472 cli_close(cli, fnum);
5474 cli_unlink(cli, fname,
5475 FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5476 torture_close_connection(cli);
5483 static bool run_pipe_number(int dummy)
5485 struct cli_state *cli1;
5486 const char *pipe_name = "\\SPOOLSS";
5491 printf("starting pipenumber test\n");
5492 if (!torture_open_connection(&cli1, 0)) {
5496 smbXcli_conn_set_sockopt(cli1->conn, sockops);
5498 status = cli_ntcreate(cli1, pipe_name, 0, FILE_READ_DATA,
5499 FILE_ATTRIBUTE_NORMAL,
5500 FILE_SHARE_READ|FILE_SHARE_WRITE,
5501 FILE_OPEN_IF, 0, 0, &fnum, NULL);
5502 if (!NT_STATUS_IS_OK(status)) {
5503 printf("Open of pipe %s failed with error (%s)\n", pipe_name, nt_errstr(status));
5507 printf("\r%6d", num_pipes);
5510 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes, pipe_name );
5511 torture_close_connection(cli1);
5516 Test open mode returns on read-only files.
5518 static bool run_opentest(int dummy)
5520 static struct cli_state *cli1;
5521 static struct cli_state *cli2;
5522 const char *fname = "\\readonly.file";
5523 uint16_t fnum1, fnum2;
5526 bool correct = True;
5530 printf("starting open test\n");
5532 if (!torture_open_connection(&cli1, 0)) {
5536 cli_setatr(cli1, fname, 0, 0);
5537 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5539 smbXcli_conn_set_sockopt(cli1->conn, sockops);
5541 status = cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
5542 if (!NT_STATUS_IS_OK(status)) {
5543 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
5547 status = cli_close(cli1, fnum1);
5548 if (!NT_STATUS_IS_OK(status)) {
5549 printf("close2 failed (%s)\n", nt_errstr(status));
5553 status = cli_setatr(cli1, fname, FILE_ATTRIBUTE_READONLY, 0);
5554 if (!NT_STATUS_IS_OK(status)) {
5555 printf("cli_setatr failed (%s)\n", nt_errstr(status));
5559 status = cli_openx(cli1, fname, O_RDONLY, DENY_WRITE, &fnum1);
5560 if (!NT_STATUS_IS_OK(status)) {
5561 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
5565 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
5566 status = cli_openx(cli1, fname, O_RDWR, DENY_ALL, &fnum2);
5568 if (check_error(__LINE__, status, ERRDOS, ERRnoaccess,
5569 NT_STATUS_ACCESS_DENIED)) {
5570 printf("correct error code ERRDOS/ERRnoaccess returned\n");
5573 printf("finished open test 1\n");
5575 cli_close(cli1, fnum1);
5577 /* Now try not readonly and ensure ERRbadshare is returned. */
5579 cli_setatr(cli1, fname, 0, 0);
5581 status = cli_openx(cli1, fname, O_RDONLY, DENY_WRITE, &fnum1);
5582 if (!NT_STATUS_IS_OK(status)) {
5583 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
5587 /* This will fail - but the error should be ERRshare. */
5588 status = cli_openx(cli1, fname, O_RDWR, DENY_ALL, &fnum2);
5590 if (check_error(__LINE__, status, ERRDOS, ERRbadshare,
5591 NT_STATUS_SHARING_VIOLATION)) {
5592 printf("correct error code ERRDOS/ERRbadshare returned\n");
5595 status = cli_close(cli1, fnum1);
5596 if (!NT_STATUS_IS_OK(status)) {
5597 printf("close2 failed (%s)\n", nt_errstr(status));
5601 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5603 printf("finished open test 2\n");
5605 /* Test truncate open disposition on file opened for read. */
5606 status = cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
5607 if (!NT_STATUS_IS_OK(status)) {
5608 printf("(3) open (1) of %s failed (%s)\n", fname, nt_errstr(status));
5612 /* write 20 bytes. */
5614 memset(buf, '\0', 20);
5616 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 0, 20, NULL);
5617 if (!NT_STATUS_IS_OK(status)) {
5618 printf("write failed (%s)\n", nt_errstr(status));
5622 status = cli_close(cli1, fnum1);
5623 if (!NT_STATUS_IS_OK(status)) {
5624 printf("(3) close1 failed (%s)\n", nt_errstr(status));
5628 /* Ensure size == 20. */
5629 status = cli_getatr(cli1, fname, NULL, &fsize, NULL);
5630 if (!NT_STATUS_IS_OK(status)) {
5631 printf("(3) getatr failed (%s)\n", nt_errstr(status));
5636 printf("(3) file size != 20\n");
5640 /* Now test if we can truncate a file opened for readonly. */
5641 status = cli_openx(cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE, &fnum1);
5642 if (!NT_STATUS_IS_OK(status)) {
5643 printf("(3) open (2) of %s failed (%s)\n", fname, nt_errstr(status));
5647 status = cli_close(cli1, fnum1);
5648 if (!NT_STATUS_IS_OK(status)) {
5649 printf("close2 failed (%s)\n", nt_errstr(status));
5653 /* Ensure size == 0. */
5654 status = cli_getatr(cli1, fname, NULL, &fsize, NULL);
5655 if (!NT_STATUS_IS_OK(status)) {
5656 printf("(3) getatr failed (%s)\n", nt_errstr(status));
5661 printf("(3) file size != 0\n");
5664 printf("finished open test 3\n");
5666 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5668 printf("Do ctemp tests\n");
5669 status = cli_ctemp(cli1, talloc_tos(), "\\", &fnum1, &tmp_path);
5670 if (!NT_STATUS_IS_OK(status)) {
5671 printf("ctemp failed (%s)\n", nt_errstr(status));
5675 printf("ctemp gave path %s\n", tmp_path);
5676 status = cli_close(cli1, fnum1);
5677 if (!NT_STATUS_IS_OK(status)) {
5678 printf("close of temp failed (%s)\n", nt_errstr(status));
5681 status = cli_unlink(cli1, tmp_path, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5682 if (!NT_STATUS_IS_OK(status)) {
5683 printf("unlink of temp failed (%s)\n", nt_errstr(status));
5686 /* Test the non-io opens... */
5688 if (!torture_open_connection(&cli2, 1)) {
5692 cli_setatr(cli2, fname, 0, 0);
5693 cli_unlink(cli2, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5695 smbXcli_conn_set_sockopt(cli2->conn, sockops);
5697 printf("TEST #1 testing 2 non-io opens (no delete)\n");
5698 status = cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES,
5699 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5700 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
5701 if (!NT_STATUS_IS_OK(status)) {
5702 printf("TEST #1 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
5706 status = cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES,
5707 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5708 FILE_OPEN_IF, 0, 0, &fnum2, NULL);
5709 if (!NT_STATUS_IS_OK(status)) {
5710 printf("TEST #1 open 2 of %s failed (%s)\n", fname, nt_errstr(status));
5714 status = cli_close(cli1, fnum1);
5715 if (!NT_STATUS_IS_OK(status)) {
5716 printf("TEST #1 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
5720 status = cli_close(cli2, fnum2);
5721 if (!NT_STATUS_IS_OK(status)) {
5722 printf("TEST #1 close 2 of %s failed (%s)\n", fname, nt_errstr(status));
5726 printf("non-io open test #1 passed.\n");
5728 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5730 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
5732 status = cli_ntcreate(cli1, fname, 0,
5733 DELETE_ACCESS|FILE_READ_ATTRIBUTES,
5734 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5735 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
5736 if (!NT_STATUS_IS_OK(status)) {
5737 printf("TEST #2 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
5741 status = cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES,
5742 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5743 FILE_OPEN_IF, 0, 0, &fnum2, NULL);
5744 if (!NT_STATUS_IS_OK(status)) {
5745 printf("TEST #2 open 2 of %s failed (%s)\n", fname, nt_errstr(status));
5749 status = cli_close(cli1, fnum1);
5750 if (!NT_STATUS_IS_OK(status)) {
5751 printf("TEST #2 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
5755 status = cli_close(cli2, fnum2);
5756 if (!NT_STATUS_IS_OK(status)) {
5757 printf("TEST #2 close 2 of %s failed (%s)\n", fname, nt_errstr(status));
5761 printf("non-io open test #2 passed.\n");
5763 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5765 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
5767 status = cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES,
5768 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5769 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
5770 if (!NT_STATUS_IS_OK(status)) {
5771 printf("TEST #3 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
5775 status = cli_ntcreate(cli2, fname, 0,
5776 DELETE_ACCESS|FILE_READ_ATTRIBUTES,
5777 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5778 FILE_OPEN_IF, 0, 0, &fnum2, NULL);
5779 if (!NT_STATUS_IS_OK(status)) {
5780 printf("TEST #3 open 2 of %s failed (%s)\n", fname, nt_errstr(status));
5784 status = cli_close(cli1, fnum1);
5785 if (!NT_STATUS_IS_OK(status)) {
5786 printf("TEST #3 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
5790 status = cli_close(cli2, fnum2);
5791 if (!NT_STATUS_IS_OK(status)) {
5792 printf("TEST #3 close 2 of %s failed (%s)\n", fname, nt_errstr(status));
5796 printf("non-io open test #3 passed.\n");
5798 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5800 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
5802 status = cli_ntcreate(cli1, fname, 0,
5803 DELETE_ACCESS|FILE_READ_ATTRIBUTES,
5804 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5805 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
5806 if (!NT_STATUS_IS_OK(status)) {
5807 printf("TEST #4 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
5811 status = cli_ntcreate(cli2, fname, 0,
5812 DELETE_ACCESS|FILE_READ_ATTRIBUTES,
5813 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5814 FILE_OPEN_IF, 0, 0, &fnum2, NULL);
5815 if (NT_STATUS_IS_OK(status)) {
5816 printf("TEST #4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, nt_errstr(status));
5820 printf("TEST #4 open 2 of %s gave %s (correct error should be %s)\n", fname, nt_errstr(status), "sharing violation");
5822 status = cli_close(cli1, fnum1);
5823 if (!NT_STATUS_IS_OK(status)) {
5824 printf("TEST #4 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
5828 printf("non-io open test #4 passed.\n");
5830 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5832 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
5834 status = cli_ntcreate(cli1, fname, 0,
5835 DELETE_ACCESS|FILE_READ_ATTRIBUTES,
5836 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_DELETE,
5837 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
5838 if (!NT_STATUS_IS_OK(status)) {
5839 printf("TEST #5 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
5843 status = cli_ntcreate(cli2, fname, 0,
5844 DELETE_ACCESS|FILE_READ_ATTRIBUTES,
5845 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_DELETE,
5846 FILE_OPEN_IF, 0, 0, &fnum2, NULL);
5847 if (!NT_STATUS_IS_OK(status)) {
5848 printf("TEST #5 open 2 of %s failed (%s)\n", fname, nt_errstr(status));
5852 status = cli_close(cli1, fnum1);
5853 if (!NT_STATUS_IS_OK(status)) {
5854 printf("TEST #5 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
5858 status = cli_close(cli2, fnum2);
5859 if (!NT_STATUS_IS_OK(status)) {
5860 printf("TEST #5 close 2 of %s failed (%s)\n", fname, nt_errstr(status));
5864 printf("non-io open test #5 passed.\n");
5866 printf("TEST #6 testing 1 non-io open, one io open\n");
5868 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5870 status = cli_ntcreate(cli1, fname, 0, FILE_READ_DATA,
5871 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5872 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
5873 if (!NT_STATUS_IS_OK(status)) {
5874 printf("TEST #6 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
5878 status = cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES,
5879 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ,
5880 FILE_OPEN_IF, 0, 0, &fnum2, NULL);
5881 if (!NT_STATUS_IS_OK(status)) {
5882 printf("TEST #6 open 2 of %s failed (%s)\n", fname, nt_errstr(status));
5886 status = cli_close(cli1, fnum1);
5887 if (!NT_STATUS_IS_OK(status)) {
5888 printf("TEST #6 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
5892 status = cli_close(cli2, fnum2);
5893 if (!NT_STATUS_IS_OK(status)) {
5894 printf("TEST #6 close 2 of %s failed (%s)\n", fname, nt_errstr(status));
5898 printf("non-io open test #6 passed.\n");
5900 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
5902 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5904 status = cli_ntcreate(cli1, fname, 0, FILE_READ_DATA,
5905 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5906 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
5907 if (!NT_STATUS_IS_OK(status)) {
5908 printf("TEST #7 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
5912 status = cli_ntcreate(cli2, fname, 0,
5913 DELETE_ACCESS|FILE_READ_ATTRIBUTES,
5914 FILE_ATTRIBUTE_NORMAL,
5915 FILE_SHARE_READ|FILE_SHARE_DELETE,
5916 FILE_OPEN_IF, 0, 0, &fnum2, NULL);
5917 if (NT_STATUS_IS_OK(status)) {
5918 printf("TEST #7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, nt_errstr(status));
5922 printf("TEST #7 open 2 of %s gave %s (correct error should be %s)\n", fname, nt_errstr(status), "sharing violation");
5924 status = cli_close(cli1, fnum1);
5925 if (!NT_STATUS_IS_OK(status)) {
5926 printf("TEST #7 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
5930 printf("non-io open test #7 passed.\n");
5932 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5934 printf("TEST #8 testing open without WRITE_ATTRIBUTES, updating close write time.\n");
5935 status = cli_ntcreate(cli1, fname, 0, FILE_WRITE_DATA, FILE_ATTRIBUTE_NORMAL,
5936 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
5937 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
5938 if (!NT_STATUS_IS_OK(status)) {
5939 printf("TEST #8 open of %s failed (%s)\n", fname, nt_errstr(status));
5944 /* Write to ensure we have to update the file time. */
5945 status = cli_writeall(cli1, fnum1, 0, (const uint8_t *)"TEST DATA\n", 0, 10,
5947 if (!NT_STATUS_IS_OK(status)) {
5948 printf("TEST #8 cli_write failed: %s\n", nt_errstr(status));
5953 status = cli_close(cli1, fnum1);
5954 if (!NT_STATUS_IS_OK(status)) {
5955 printf("TEST #8 close of %s failed (%s)\n", fname, nt_errstr(status));
5961 if (!torture_close_connection(cli1)) {
5964 if (!torture_close_connection(cli2)) {
5971 NTSTATUS torture_setup_unix_extensions(struct cli_state *cli)
5973 uint16_t major, minor;
5974 uint32_t caplow, caphigh;
5977 if (!SERVER_HAS_UNIX_CIFS(cli)) {
5978 printf("Server doesn't support UNIX CIFS extensions.\n");
5979 return NT_STATUS_NOT_SUPPORTED;
5982 status = cli_unix_extensions_version(cli, &major, &minor, &caplow,
5984 if (!NT_STATUS_IS_OK(status)) {
5985 printf("Server didn't return UNIX CIFS extensions: %s\n",
5990 status = cli_set_unix_extensions_capabilities(cli, major, minor,
5992 if (!NT_STATUS_IS_OK(status)) {
5993 printf("Server doesn't support setting UNIX CIFS extensions: "
5994 "%s.\n", nt_errstr(status));
5998 return NT_STATUS_OK;
6002 Test POSIX open /mkdir calls.
6004 static bool run_simple_posix_open_test(int dummy)
6006 static struct cli_state *cli1;
6007 const char *fname = "posix:file";
6008 const char *hname = "posix:hlink";
6009 const char *sname = "posix:symlink";
6010 const char *dname = "posix:dir";
6013 uint16_t fnum1 = (uint16_t)-1;
6014 SMB_STRUCT_STAT sbuf;
6015 bool correct = false;
6018 const char *fname_windows = "windows_file";
6019 uint16_t fnum2 = (uint16_t)-1;
6021 printf("Starting simple POSIX open test\n");
6023 if (!torture_open_connection(&cli1, 0)) {
6027 smbXcli_conn_set_sockopt(cli1->conn, sockops);
6029 status = torture_setup_unix_extensions(cli1);
6030 if (!NT_STATUS_IS_OK(status)) {
6034 cli_setatr(cli1, fname, 0, 0);
6035 cli_posix_unlink(cli1, fname);
6036 cli_setatr(cli1, dname, 0, 0);
6037 cli_posix_rmdir(cli1, dname);
6038 cli_setatr(cli1, hname, 0, 0);
6039 cli_posix_unlink(cli1, hname);
6040 cli_setatr(cli1, sname, 0, 0);
6041 cli_posix_unlink(cli1, sname);
6042 cli_setatr(cli1, fname_windows, 0, 0);
6043 cli_posix_unlink(cli1, fname_windows);
6045 /* Create a directory. */
6046 status = cli_posix_mkdir(cli1, dname, 0777);
6047 if (!NT_STATUS_IS_OK(status)) {
6048 printf("POSIX mkdir of %s failed (%s)\n", dname, nt_errstr(status));
6052 status = cli_posix_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL,
6054 if (!NT_STATUS_IS_OK(status)) {
6055 printf("POSIX create of %s failed (%s)\n", fname, nt_errstr(status));
6059 /* Test ftruncate - set file size. */
6060 status = cli_ftruncate(cli1, fnum1, 1000);
6061 if (!NT_STATUS_IS_OK(status)) {
6062 printf("ftruncate failed (%s)\n", nt_errstr(status));
6066 /* Ensure st_size == 1000 */
6067 status = cli_posix_stat(cli1, fname, &sbuf);
6068 if (!NT_STATUS_IS_OK(status)) {
6069 printf("stat failed (%s)\n", nt_errstr(status));
6073 if (sbuf.st_ex_size != 1000) {
6074 printf("ftruncate - stat size (%u) != 1000\n", (unsigned int)sbuf.st_ex_size);
6078 /* Ensure st_mode == 0600 */
6079 if ((sbuf.st_ex_mode & 07777) != 0600) {
6080 printf("posix_open - bad permissions 0%o != 0600\n",
6081 (unsigned int)(sbuf.st_ex_mode & 07777));
6085 /* Test ftruncate - set file size back to zero. */
6086 status = cli_ftruncate(cli1, fnum1, 0);
6087 if (!NT_STATUS_IS_OK(status)) {
6088 printf("ftruncate failed (%s)\n", nt_errstr(status));
6092 status = cli_close(cli1, fnum1);
6093 if (!NT_STATUS_IS_OK(status)) {
6094 printf("close failed (%s)\n", nt_errstr(status));
6098 /* Now open the file again for read only. */
6099 status = cli_posix_open(cli1, fname, O_RDONLY, 0, &fnum1);
6100 if (!NT_STATUS_IS_OK(status)) {
6101 printf("POSIX open of %s failed (%s)\n", fname, nt_errstr(status));
6105 /* Now unlink while open. */
6106 status = cli_posix_unlink(cli1, fname);
6107 if (!NT_STATUS_IS_OK(status)) {
6108 printf("POSIX unlink of %s failed (%s)\n", fname, nt_errstr(status));
6112 status = cli_close(cli1, fnum1);
6113 if (!NT_STATUS_IS_OK(status)) {
6114 printf("close(2) failed (%s)\n", nt_errstr(status));
6118 /* Ensure the file has gone. */
6119 status = cli_posix_open(cli1, fname, O_RDONLY, 0, &fnum1);
6120 if (NT_STATUS_IS_OK(status)) {
6121 printf("POSIX open of %s succeeded, should have been deleted.\n", fname);
6125 /* Create again to test open with O_TRUNC. */
6126 status = cli_posix_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, 0600, &fnum1);
6127 if (!NT_STATUS_IS_OK(status)) {
6128 printf("POSIX create of %s failed (%s)\n", fname, nt_errstr(status));
6132 /* Test ftruncate - set file size. */
6133 status = cli_ftruncate(cli1, fnum1, 1000);
6134 if (!NT_STATUS_IS_OK(status)) {
6135 printf("ftruncate failed (%s)\n", nt_errstr(status));
6139 /* Ensure st_size == 1000 */
6140 status = cli_posix_stat(cli1, fname, &sbuf);
6141 if (!NT_STATUS_IS_OK(status)) {
6142 printf("stat failed (%s)\n", nt_errstr(status));
6146 if (sbuf.st_ex_size != 1000) {
6147 printf("ftruncate - stat size (%u) != 1000\n", (unsigned int)sbuf.st_ex_size);
6151 status = cli_close(cli1, fnum1);
6152 if (!NT_STATUS_IS_OK(status)) {
6153 printf("close(2) failed (%s)\n", nt_errstr(status));
6157 /* Re-open with O_TRUNC. */
6158 status = cli_posix_open(cli1, fname, O_WRONLY|O_TRUNC, 0600, &fnum1);
6159 if (!NT_STATUS_IS_OK(status)) {
6160 printf("POSIX create of %s failed (%s)\n", fname, nt_errstr(status));
6164 /* Ensure st_size == 0 */
6165 status = cli_posix_stat(cli1, fname, &sbuf);
6166 if (!NT_STATUS_IS_OK(status)) {
6167 printf("stat failed (%s)\n", nt_errstr(status));
6171 if (sbuf.st_ex_size != 0) {
6172 printf("O_TRUNC - stat size (%u) != 0\n", (unsigned int)sbuf.st_ex_size);
6176 status = cli_close(cli1, fnum1);
6177 if (!NT_STATUS_IS_OK(status)) {
6178 printf("close failed (%s)\n", nt_errstr(status));
6182 status = cli_posix_unlink(cli1, fname);
6183 if (!NT_STATUS_IS_OK(status)) {
6184 printf("POSIX unlink of %s failed (%s)\n", fname, nt_errstr(status));
6188 status = cli_posix_open(cli1, dname, O_RDONLY, 0, &fnum1);
6189 if (!NT_STATUS_IS_OK(status)) {
6190 printf("POSIX open directory O_RDONLY of %s failed (%s)\n",
6191 dname, nt_errstr(status));
6195 cli_close(cli1, fnum1);
6197 /* What happens when we try and POSIX open a directory for write ? */
6198 status = cli_posix_open(cli1, dname, O_RDWR, 0, &fnum1);
6199 if (NT_STATUS_IS_OK(status)) {
6200 printf("POSIX open of directory %s succeeded, should have failed.\n", fname);
6203 if (!check_both_error(__LINE__, status, ERRDOS, EISDIR,
6204 NT_STATUS_FILE_IS_A_DIRECTORY)) {
6209 /* Create the file. */
6210 status = cli_posix_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL,
6212 if (!NT_STATUS_IS_OK(status)) {
6213 printf("POSIX create of %s failed (%s)\n", fname, nt_errstr(status));
6217 /* Write some data into it. */
6218 status = cli_writeall(cli1, fnum1, 0, (const uint8_t *)"TEST DATA\n", 0, 10,
6220 if (!NT_STATUS_IS_OK(status)) {
6221 printf("cli_write failed: %s\n", nt_errstr(status));
6225 cli_close(cli1, fnum1);
6227 /* Now create a hardlink. */
6228 status = cli_posix_hardlink(cli1, fname, hname);
6229 if (!NT_STATUS_IS_OK(status)) {
6230 printf("POSIX hardlink of %s failed (%s)\n", hname, nt_errstr(status));
6234 /* Now create a symlink. */
6235 status = cli_posix_symlink(cli1, fname, sname);
6236 if (!NT_STATUS_IS_OK(status)) {
6237 printf("POSIX symlink of %s failed (%s)\n", sname, nt_errstr(status));
6241 /* Open the hardlink for read. */
6242 status = cli_posix_open(cli1, hname, O_RDONLY, 0, &fnum1);
6243 if (!NT_STATUS_IS_OK(status)) {
6244 printf("POSIX open of %s failed (%s)\n", hname, nt_errstr(status));
6248 status = cli_read(cli1, fnum1, buf, 0, 10, &nread);
6249 if (!NT_STATUS_IS_OK(status)) {
6250 printf("POSIX read of %s failed (%s)\n", hname,
6253 } else if (nread != 10) {
6254 printf("POSIX read of %s failed. Received %ld, expected %d\n",
6255 hname, (unsigned long)nread, 10);
6259 if (memcmp(buf, "TEST DATA\n", 10)) {
6260 printf("invalid data read from hardlink\n");
6264 /* Do a POSIX lock/unlock. */
6265 status = cli_posix_lock(cli1, fnum1, 0, 100, true, READ_LOCK);
6266 if (!NT_STATUS_IS_OK(status)) {
6267 printf("POSIX lock failed %s\n", nt_errstr(status));
6271 /* Punch a hole in the locked area. */
6272 status = cli_posix_unlock(cli1, fnum1, 10, 80);
6273 if (!NT_STATUS_IS_OK(status)) {
6274 printf("POSIX unlock failed %s\n", nt_errstr(status));
6278 cli_close(cli1, fnum1);
6280 /* Open the symlink for read - this should fail. A POSIX
6281 client should not be doing opens on a symlink. */
6282 status = cli_posix_open(cli1, sname, O_RDONLY, 0, &fnum1);
6283 if (NT_STATUS_IS_OK(status)) {
6284 printf("POSIX open of %s succeeded (should have failed)\n", sname);
6287 if (!check_both_error(__LINE__, status, ERRDOS, ERRbadpath,
6288 NT_STATUS_OBJECT_PATH_NOT_FOUND)) {
6289 printf("POSIX open of %s should have failed "
6290 "with NT_STATUS_OBJECT_PATH_NOT_FOUND, "
6291 "failed with %s instead.\n",
6292 sname, nt_errstr(status));
6297 status = cli_posix_readlink(cli1, sname, namebuf, sizeof(namebuf));
6298 if (!NT_STATUS_IS_OK(status)) {
6299 printf("POSIX readlink on %s failed (%s)\n", sname, nt_errstr(status));
6303 if (strcmp(namebuf, fname) != 0) {
6304 printf("POSIX readlink on %s failed to match name %s (read %s)\n",
6305 sname, fname, namebuf);
6309 status = cli_posix_rmdir(cli1, dname);
6310 if (!NT_STATUS_IS_OK(status)) {
6311 printf("POSIX rmdir failed (%s)\n", nt_errstr(status));
6315 /* Check directory opens with a specific permission. */
6316 status = cli_posix_mkdir(cli1, dname, 0700);
6317 if (!NT_STATUS_IS_OK(status)) {
6318 printf("POSIX mkdir of %s failed (%s)\n", dname, nt_errstr(status));
6322 /* Ensure st_mode == 0700 */
6323 status = cli_posix_stat(cli1, dname, &sbuf);
6324 if (!NT_STATUS_IS_OK(status)) {
6325 printf("stat failed (%s)\n", nt_errstr(status));
6329 if ((sbuf.st_ex_mode & 07777) != 0700) {
6330 printf("posix_mkdir - bad permissions 0%o != 0700\n",
6331 (unsigned int)(sbuf.st_ex_mode & 07777));
6336 * Now create a Windows file, and attempt a POSIX unlink.
6337 * This should fail with a sharing violation but due to:
6339 * [Bug 9571] Unlink after open causes smbd to panic
6341 * ensure we've fixed the lock ordering violation.
6344 status = cli_ntcreate(cli1, fname_windows, 0,
6345 FILE_READ_DATA|FILE_WRITE_DATA, 0,
6346 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
6348 0x0, 0x0, &fnum2, NULL);
6349 if (!NT_STATUS_IS_OK(status)) {
6350 printf("Windows create of %s failed (%s)\n", fname_windows,
6355 /* Now try posix_unlink. */
6356 status = cli_posix_unlink(cli1, fname_windows);
6357 if (!NT_STATUS_EQUAL(status, NT_STATUS_SHARING_VIOLATION)) {
6358 printf("POSIX unlink of %s should fail "
6359 "with NT_STATUS_SHARING_VIOLATION "
6360 "got %s instead !\n",
6366 cli_close(cli1, fnum2);
6368 printf("Simple POSIX open test passed\n");
6373 if (fnum1 != (uint16_t)-1) {
6374 cli_close(cli1, fnum1);
6375 fnum1 = (uint16_t)-1;
6378 if (fnum2 != (uint16_t)-1) {
6379 cli_close(cli1, fnum2);
6380 fnum2 = (uint16_t)-1;
6383 cli_setatr(cli1, sname, 0, 0);
6384 cli_posix_unlink(cli1, sname);
6385 cli_setatr(cli1, hname, 0, 0);
6386 cli_posix_unlink(cli1, hname);
6387 cli_setatr(cli1, fname, 0, 0);
6388 cli_posix_unlink(cli1, fname);
6389 cli_setatr(cli1, dname, 0, 0);
6390 cli_posix_rmdir(cli1, dname);
6391 cli_setatr(cli1, fname_windows, 0, 0);
6392 cli_posix_unlink(cli1, fname_windows);
6394 if (!torture_close_connection(cli1)) {
6402 Test POSIX and Windows ACLs are rejected on symlinks.
6404 static bool run_acl_symlink_test(int dummy)
6406 static struct cli_state *cli;
6407 const char *fname = "posix_file";
6408 const char *sname = "posix_symlink";
6409 uint16_t fnum = (uint16_t)-1;
6410 bool correct = false;
6412 char *posix_acl = NULL;
6413 size_t posix_acl_len = 0;
6414 char *posix_acl_sym = NULL;
6415 size_t posix_acl_len_sym = 0;
6416 struct security_descriptor *sd = NULL;
6417 struct security_descriptor *sd_sym = NULL;
6418 TALLOC_CTX *frame = NULL;
6420 frame = talloc_stackframe();
6422 printf("Starting acl symlink test\n");
6424 if (!torture_open_connection(&cli, 0)) {
6429 smbXcli_conn_set_sockopt(cli->conn, sockops);
6431 status = torture_setup_unix_extensions(cli);
6432 if (!NT_STATUS_IS_OK(status)) {
6437 cli_setatr(cli, fname, 0, 0);
6438 cli_posix_unlink(cli, fname);
6439 cli_setatr(cli, sname, 0, 0);
6440 cli_posix_unlink(cli, sname);
6442 status = cli_ntcreate(cli,
6445 READ_CONTROL_ACCESS,
6447 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
6454 if (!NT_STATUS_IS_OK(status)) {
6455 printf("cli_ntcreate of %s failed (%s)\n",
6461 /* Get the Windows ACL on the file. */
6462 status = cli_query_secdesc(cli,
6466 if (!NT_STATUS_IS_OK(status)) {
6467 printf("cli_query_secdesc failed (%s)\n",
6472 /* Get the POSIX ACL on the file. */
6473 status = cli_posix_getacl(cli,
6479 if (!NT_STATUS_IS_OK(status)) {
6480 printf("cli_posix_getacl failed (%s)\n",
6485 status = cli_close(cli, fnum);
6486 if (!NT_STATUS_IS_OK(status)) {
6487 printf("close failed (%s)\n", nt_errstr(status));
6490 fnum = (uint16_t)-1;
6492 /* Now create a symlink. */
6493 status = cli_posix_symlink(cli, fname, sname);
6494 if (!NT_STATUS_IS_OK(status)) {
6495 printf("cli_posix_symlink of %s -> %s failed (%s)\n",
6502 /* Open a handle on the symlink. */
6503 status = cli_ntcreate(cli,
6506 READ_CONTROL_ACCESS|SEC_STD_WRITE_DAC,
6508 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
6515 if (!NT_STATUS_IS_OK(status)) {
6516 printf("cli_posix_open of %s failed (%s)\n",
6522 /* Get the Windows ACL on the symlink handle. Should fail */
6523 status = cli_query_secdesc(cli,
6528 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
6529 printf("cli_query_secdesc on a symlink gave %s. "
6530 "Should be NT_STATUS_ACCESS_DENIED.\n",
6535 /* Get the POSIX ACL on the symlink pathname. Should fail. */
6536 status = cli_posix_getacl(cli,
6542 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
6543 printf("cli_posix_getacl on a symlink gave %s. "
6544 "Should be NT_STATUS_ACCESS_DENIED.\n",
6549 /* Set the Windows ACL on the symlink handle. Should fail */
6550 status = cli_set_security_descriptor(cli,
6555 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
6556 printf("cli_query_secdesc on a symlink gave %s. "
6557 "Should be NT_STATUS_ACCESS_DENIED.\n",
6562 /* Set the POSIX ACL on the symlink pathname. Should fail. */
6563 status = cli_posix_setacl(cli,
6568 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
6569 printf("cli_posix_getacl on a symlink gave %s. "
6570 "Should be NT_STATUS_ACCESS_DENIED.\n",
6575 printf("ACL symlink test passed\n");
6580 if (fnum != (uint16_t)-1) {
6581 cli_close(cli, fnum);
6582 fnum = (uint16_t)-1;
6585 cli_setatr(cli, sname, 0, 0);
6586 cli_posix_unlink(cli, sname);
6587 cli_setatr(cli, fname, 0, 0);
6588 cli_posix_unlink(cli, fname);
6590 if (!torture_close_connection(cli)) {
6599 Test POSIX can delete a file containing streams.
6601 static bool run_posix_stream_delete(int dummy)
6603 struct cli_state *cli1 = NULL;
6604 struct cli_state *cli2 = NULL;
6605 const char *fname = "streamfile";
6606 const char *stream_fname = "streamfile:Zone.Identifier:$DATA";
6607 uint16_t fnum1 = (uint16_t)-1;
6608 bool correct = false;
6610 TALLOC_CTX *frame = NULL;
6612 frame = talloc_stackframe();
6614 printf("Starting POSIX stream delete test\n");
6616 if (!torture_open_connection(&cli1, 0) ||
6617 !torture_open_connection(&cli2, 1)) {
6622 smbXcli_conn_set_sockopt(cli1->conn, sockops);
6623 smbXcli_conn_set_sockopt(cli2->conn, sockops);
6625 status = torture_setup_unix_extensions(cli2);
6626 if (!NT_STATUS_IS_OK(status)) {
6630 cli_setatr(cli1, fname, 0, 0);
6631 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
6633 /* Create the file. */
6634 status = cli_ntcreate(cli1,
6637 READ_CONTROL_ACCESS,
6639 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
6646 if (!NT_STATUS_IS_OK(status)) {
6647 printf("cli_ntcreate of %s failed (%s)\n",
6653 status = cli_close(cli1, fnum1);
6654 if (!NT_STATUS_IS_OK(status)) {
6655 printf("cli_close of %s failed (%s)\n",
6660 fnum1 = (uint16_t)-1;
6662 /* Now create the stream. */
6663 status = cli_ntcreate(cli1,
6668 FILE_SHARE_READ|FILE_SHARE_WRITE,
6675 if (!NT_STATUS_IS_OK(status)) {
6676 printf("cli_ntcreate of %s failed (%s)\n",
6682 /* Leave the stream handle open... */
6684 /* POSIX unlink should fail. */
6685 status = cli_posix_unlink(cli2, fname);
6686 if (NT_STATUS_IS_OK(status)) {
6687 printf("cli_posix_unlink of %s succeeded, should have failed\n",
6692 if (!NT_STATUS_EQUAL(status, NT_STATUS_SHARING_VIOLATION)) {
6693 printf("cli_posix_unlink of %s failed with (%s) "
6694 "should have been NT_STATUS_SHARING_VIOLATION\n",
6700 /* Close the stream handle. */
6701 status = cli_close(cli1, fnum1);
6702 if (!NT_STATUS_IS_OK(status)) {
6703 printf("cli_close of %s failed (%s)\n",
6708 fnum1 = (uint16_t)-1;
6710 /* POSIX unlink after stream handle closed should succeed. */
6711 status = cli_posix_unlink(cli2, fname);
6712 if (!NT_STATUS_IS_OK(status)) {
6713 printf("cli_posix_unlink of %s failed (%s)\n",
6719 printf("POSIX stream delete test passed\n");
6724 if (fnum1 != (uint16_t)-1) {
6725 cli_close(cli1, fnum1);
6726 fnum1 = (uint16_t)-1;
6729 cli_setatr(cli1, fname, 0, 0);
6730 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
6732 if (!torture_close_connection(cli1)) {
6735 if (!torture_close_connection(cli2)) {
6744 Test setting EA's are rejected on symlinks.
6746 static bool run_ea_symlink_test(int dummy)
6748 static struct cli_state *cli;
6749 const char *fname = "posix_file_ea";
6750 const char *sname = "posix_symlink_ea";
6751 const char *ea_name = "testea_name";
6752 const char *ea_value = "testea_value";
6753 uint16_t fnum = (uint16_t)-1;
6754 bool correct = false;
6757 struct ea_struct *eas = NULL;
6758 TALLOC_CTX *frame = NULL;
6760 frame = talloc_stackframe();
6762 printf("Starting EA symlink test\n");
6764 if (!torture_open_connection(&cli, 0)) {
6769 smbXcli_conn_set_sockopt(cli->conn, sockops);
6771 status = torture_setup_unix_extensions(cli);
6772 if (!NT_STATUS_IS_OK(status)) {
6777 cli_setatr(cli, fname, 0, 0);
6778 cli_posix_unlink(cli, fname);
6779 cli_setatr(cli, sname, 0, 0);
6780 cli_posix_unlink(cli, sname);
6782 status = cli_ntcreate(cli,
6785 READ_CONTROL_ACCESS,
6787 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
6794 if (!NT_STATUS_IS_OK(status)) {
6795 printf("cli_ntcreate of %s failed (%s)\n",
6801 status = cli_close(cli, fnum);
6802 if (!NT_STATUS_IS_OK(status)) {
6803 printf("close failed (%s)\n",
6807 fnum = (uint16_t)-1;
6809 /* Set an EA on the path. */
6810 status = cli_set_ea_path(cli,
6814 strlen(ea_value)+1);
6816 if (!NT_STATUS_IS_OK(status)) {
6817 printf("cli_set_ea_path failed (%s)\n",
6822 /* Now create a symlink. */
6823 status = cli_posix_symlink(cli, fname, sname);
6824 if (!NT_STATUS_IS_OK(status)) {
6825 printf("cli_posix_symlink of %s -> %s failed (%s)\n",
6832 /* Get the EA list on the path. Should return value set. */
6833 status = cli_get_ea_list_path(cli,
6839 if (!NT_STATUS_IS_OK(status)) {
6840 printf("cli_get_ea_list_path failed (%s)\n",
6845 /* Ensure the EA we set is there. */
6846 for (i=0; i<num_eas; i++) {
6847 if (strcmp(eas[i].name, ea_name) == 0 &&
6848 eas[i].value.length == strlen(ea_value)+1 &&
6849 memcmp(eas[i].value.data,
6851 eas[i].value.length) == 0) {
6857 printf("Didn't find EA on pathname %s\n",
6865 /* Get the EA list on the symlink. Should return empty list. */
6866 status = cli_get_ea_list_path(cli,
6872 if (!NT_STATUS_IS_OK(status)) {
6873 printf("cli_get_ea_list_path failed (%s)\n",
6879 printf("cli_get_ea_list_path failed (%s)\n",
6884 /* Set an EA on the symlink. Should fail. */
6885 status = cli_set_ea_path(cli,
6889 strlen(ea_value)+1);
6891 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
6892 printf("cli_set_ea_path on a symlink gave %s. "
6893 "Should be NT_STATUS_ACCESS_DENIED.\n",
6898 printf("EA symlink test passed\n");
6903 if (fnum != (uint16_t)-1) {
6904 cli_close(cli, fnum);
6905 fnum = (uint16_t)-1;
6908 cli_setatr(cli, sname, 0, 0);
6909 cli_posix_unlink(cli, sname);
6910 cli_setatr(cli, fname, 0, 0);
6911 cli_posix_unlink(cli, fname);
6913 if (!torture_close_connection(cli)) {
6922 Test POSIX locks are OFD-locks.
6924 static bool run_posix_ofd_lock_test(int dummy)
6926 static struct cli_state *cli;
6927 const char *fname = "posix_file";
6928 uint16_t fnum1 = (uint16_t)-1;
6929 uint16_t fnum2 = (uint16_t)-1;
6930 bool correct = false;
6932 TALLOC_CTX *frame = NULL;
6934 frame = talloc_stackframe();
6936 printf("Starting POSIX ofd-lock test\n");
6938 if (!torture_open_connection(&cli, 0)) {
6943 smbXcli_conn_set_sockopt(cli->conn, sockops);
6945 status = torture_setup_unix_extensions(cli);
6946 if (!NT_STATUS_IS_OK(status)) {
6951 cli_setatr(cli, fname, 0, 0);
6952 cli_posix_unlink(cli, fname);
6954 /* Open the file twice. */
6955 status = cli_posix_open(cli, fname, O_RDWR|O_CREAT|O_EXCL,
6957 if (!NT_STATUS_IS_OK(status)) {
6958 printf("First POSIX open of %s failed\n", fname);
6962 status = cli_posix_open(cli, fname, O_RDWR, 0, &fnum2);
6963 if (!NT_STATUS_IS_OK(status)) {
6964 printf("First POSIX open of %s failed\n", fname);
6968 /* Set a 0-50 lock on fnum1. */
6969 status = cli_posix_lock(cli, fnum1, 0, 50, false, WRITE_LOCK);
6970 if (!NT_STATUS_IS_OK(status)) {
6971 printf("POSIX lock (1) failed %s\n", nt_errstr(status));
6975 /* Set a 60-100 lock on fnum2. */
6976 status = cli_posix_lock(cli, fnum2, 60, 100, false, WRITE_LOCK);
6977 if (!NT_STATUS_IS_OK(status)) {
6978 printf("POSIX lock (2) failed %s\n", nt_errstr(status));
6982 /* close fnum1 - 0-50 lock should go away. */
6983 status = cli_close(cli, fnum1);
6984 if (!NT_STATUS_IS_OK(status)) {
6985 printf("close failed (%s)\n",
6989 fnum1 = (uint16_t)-1;
6991 /* Change the lock context. */
6992 cli_setpid(cli, cli_getpid(cli) + 1);
6994 /* Re-open fnum1. */
6995 status = cli_posix_open(cli, fname, O_RDWR, 0, &fnum1);
6996 if (!NT_STATUS_IS_OK(status)) {
6997 printf("Third POSIX open of %s failed\n", fname);
7001 /* 60-100 lock should still be there. */
7002 status = cli_posix_lock(cli, fnum1, 60, 100, false, WRITE_LOCK);
7003 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_LOCK_CONFLICT)) {
7004 printf("POSIX lock 60-100 not there %s\n", nt_errstr(status));
7008 /* 0-50 lock should be gone. */
7009 status = cli_posix_lock(cli, fnum1, 0, 50, false, WRITE_LOCK);
7010 if (!NT_STATUS_IS_OK(status)) {
7011 printf("POSIX lock 0-50 failed %s\n", nt_errstr(status));
7015 printf("POSIX OFD lock test passed\n");
7020 if (fnum1 != (uint16_t)-1) {
7021 cli_close(cli, fnum1);
7022 fnum1 = (uint16_t)-1;
7024 if (fnum2 != (uint16_t)-1) {
7025 cli_close(cli, fnum2);
7026 fnum2 = (uint16_t)-1;
7029 cli_setatr(cli, fname, 0, 0);
7030 cli_posix_unlink(cli, fname);
7032 if (!torture_close_connection(cli)) {
7040 static uint32_t open_attrs_table[] = {
7041 FILE_ATTRIBUTE_NORMAL,
7042 FILE_ATTRIBUTE_ARCHIVE,
7043 FILE_ATTRIBUTE_READONLY,
7044 FILE_ATTRIBUTE_HIDDEN,
7045 FILE_ATTRIBUTE_SYSTEM,
7047 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY,
7048 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN,
7049 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM,
7050 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
7051 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
7052 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
7054 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
7055 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
7056 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
7057 FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_SYSTEM,
7060 struct trunc_open_results {
7063 uint32_t trunc_attr;
7064 uint32_t result_attr;
7067 static struct trunc_open_results attr_results[] = {
7068 { 0, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
7069 { 1, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
7070 { 2, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
7071 { 16, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
7072 { 17, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
7073 { 18, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
7074 { 51, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
7075 { 54, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
7076 { 56, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
7077 { 68, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
7078 { 71, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
7079 { 73, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM },
7080 { 99, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
7081 { 102, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
7082 { 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 },
7083 { 116, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
7084 { 119, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
7085 { 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 },
7086 { 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 },
7087 { 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 },
7088 { 227, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
7089 { 230, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
7090 { 232, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
7091 { 244, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
7092 { 247, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
7093 { 249, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM }
7096 static bool run_openattrtest(int dummy)
7098 static struct cli_state *cli1;
7099 const char *fname = "\\openattr.file";
7101 bool correct = True;
7103 unsigned int i, j, k, l;
7106 printf("starting open attr test\n");
7108 if (!torture_open_connection(&cli1, 0)) {
7112 smbXcli_conn_set_sockopt(cli1->conn, sockops);
7114 for (k = 0, i = 0; i < sizeof(open_attrs_table)/sizeof(uint32_t); i++) {
7115 cli_setatr(cli1, fname, 0, 0);
7116 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7118 status = cli_ntcreate(cli1, fname, 0, FILE_WRITE_DATA,
7119 open_attrs_table[i], FILE_SHARE_NONE,
7120 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
7121 if (!NT_STATUS_IS_OK(status)) {
7122 printf("open %d (1) of %s failed (%s)\n", i, fname, nt_errstr(status));
7126 status = cli_close(cli1, fnum1);
7127 if (!NT_STATUS_IS_OK(status)) {
7128 printf("close %d (1) of %s failed (%s)\n", i, fname, nt_errstr(status));
7132 for (j = 0; j < sizeof(open_attrs_table)/sizeof(uint32_t); j++) {
7133 status = cli_ntcreate(cli1, fname, 0,
7134 FILE_READ_DATA|FILE_WRITE_DATA,
7135 open_attrs_table[j],
7136 FILE_SHARE_NONE, FILE_OVERWRITE,
7137 0, 0, &fnum1, NULL);
7138 if (!NT_STATUS_IS_OK(status)) {
7139 for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
7140 if (attr_results[l].num == k) {
7141 printf("[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(0x%x:%s)\n",
7142 k, open_attrs_table[i],
7143 open_attrs_table[j],
7144 fname, NT_STATUS_V(status), nt_errstr(status));
7149 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
7150 printf("[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s\n",
7151 k, open_attrs_table[i], open_attrs_table[j],
7156 printf("[%d] trunc open 0x%x -> 0x%x failed\n", k, open_attrs_table[i], open_attrs_table[j]);
7162 status = cli_close(cli1, fnum1);
7163 if (!NT_STATUS_IS_OK(status)) {
7164 printf("close %d (2) of %s failed (%s)\n", j, fname, nt_errstr(status));
7168 status = cli_getatr(cli1, fname, &attr, NULL, NULL);
7169 if (!NT_STATUS_IS_OK(status)) {
7170 printf("getatr(2) failed (%s)\n", nt_errstr(status));
7175 printf("[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n",
7176 k, open_attrs_table[i], open_attrs_table[j], attr );
7179 for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
7180 if (attr_results[l].num == k) {
7181 if (attr != attr_results[l].result_attr ||
7182 open_attrs_table[i] != attr_results[l].init_attr ||
7183 open_attrs_table[j] != attr_results[l].trunc_attr) {
7184 printf("getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x\n",
7185 open_attrs_table[i],
7186 open_attrs_table[j],
7188 attr_results[l].result_attr);
7198 cli_setatr(cli1, fname, 0, 0);
7199 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7201 printf("open attr test %s.\n", correct ? "passed" : "failed");
7203 if (!torture_close_connection(cli1)) {
7209 static NTSTATUS list_fn(const char *mnt, struct file_info *finfo,
7210 const char *name, void *state)
7212 int *matched = (int *)state;
7213 if (matched != NULL) {
7216 return NT_STATUS_OK;
7220 test directory listing speed
7222 static bool run_dirtest(int dummy)
7225 static struct cli_state *cli;
7227 struct timeval core_start;
7228 bool correct = True;
7231 printf("starting directory test\n");
7233 if (!torture_open_connection(&cli, 0)) {
7237 smbXcli_conn_set_sockopt(cli->conn, sockops);
7240 for (i=0;i<torture_numops;i++) {
7242 slprintf(fname, sizeof(fname), "\\%x", (int)random());
7243 if (!NT_STATUS_IS_OK(cli_openx(cli, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum))) {
7244 fprintf(stderr,"Failed to open %s\n", fname);
7247 cli_close(cli, fnum);
7250 core_start = timeval_current();
7253 cli_list(cli, "a*.*", 0, list_fn, &matched);
7254 printf("Matched %d\n", matched);
7257 cli_list(cli, "b*.*", 0, list_fn, &matched);
7258 printf("Matched %d\n", matched);
7261 cli_list(cli, "xyzabc", 0, list_fn, &matched);
7262 printf("Matched %d\n", matched);
7264 printf("dirtest core %g seconds\n", timeval_elapsed(&core_start));
7267 for (i=0;i<torture_numops;i++) {
7269 slprintf(fname, sizeof(fname), "\\%x", (int)random());
7270 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7273 if (!torture_close_connection(cli)) {
7277 printf("finished dirtest\n");
7282 static NTSTATUS del_fn(const char *mnt, struct file_info *finfo, const char *mask,
7285 struct cli_state *pcli = (struct cli_state *)state;
7287 slprintf(fname, sizeof(fname), "\\LISTDIR\\%s", finfo->name);
7289 if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
7290 return NT_STATUS_OK;
7292 if (finfo->mode & FILE_ATTRIBUTE_DIRECTORY) {
7293 if (!NT_STATUS_IS_OK(cli_rmdir(pcli, fname)))
7294 printf("del_fn: failed to rmdir %s\n,", fname );
7296 if (!NT_STATUS_IS_OK(cli_unlink(pcli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN)))
7297 printf("del_fn: failed to unlink %s\n,", fname );
7299 return NT_STATUS_OK;
7304 sees what IOCTLs are supported
7306 bool torture_ioctl_test(int dummy)
7308 static struct cli_state *cli;
7309 uint16_t device, function;
7311 const char *fname = "\\ioctl.dat";
7315 if (!torture_open_connection(&cli, 0)) {
7319 printf("starting ioctl test\n");
7321 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7323 status = cli_openx(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
7324 if (!NT_STATUS_IS_OK(status)) {
7325 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
7329 status = cli_raw_ioctl(cli, fnum, 0x2d0000 | (0x0420<<2), &blob);
7330 printf("ioctl device info: %s\n", nt_errstr(status));
7332 status = cli_raw_ioctl(cli, fnum, IOCTL_QUERY_JOB_INFO, &blob);
7333 printf("ioctl job info: %s\n", nt_errstr(status));
7335 for (device=0;device<0x100;device++) {
7336 printf("ioctl test with device = 0x%x\n", device);
7337 for (function=0;function<0x100;function++) {
7338 uint32_t code = (device<<16) | function;
7340 status = cli_raw_ioctl(cli, fnum, code, &blob);
7342 if (NT_STATUS_IS_OK(status)) {
7343 printf("ioctl 0x%x OK : %d bytes\n", (int)code,
7345 data_blob_free(&blob);
7350 if (!torture_close_connection(cli)) {
7359 tries varients of chkpath
7361 bool torture_chkpath_test(int dummy)
7363 static struct cli_state *cli;
7368 if (!torture_open_connection(&cli, 0)) {
7372 printf("starting chkpath test\n");
7374 /* cleanup from an old run */
7375 cli_rmdir(cli, "\\chkpath.dir\\dir2");
7376 cli_unlink(cli, "\\chkpath.dir\\*", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7377 cli_rmdir(cli, "\\chkpath.dir");
7379 status = cli_mkdir(cli, "\\chkpath.dir");
7380 if (!NT_STATUS_IS_OK(status)) {
7381 printf("mkdir1 failed : %s\n", nt_errstr(status));
7385 status = cli_mkdir(cli, "\\chkpath.dir\\dir2");
7386 if (!NT_STATUS_IS_OK(status)) {
7387 printf("mkdir2 failed : %s\n", nt_errstr(status));
7391 status = cli_openx(cli, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL,
7393 if (!NT_STATUS_IS_OK(status)) {
7394 printf("open1 failed (%s)\n", nt_errstr(status));
7397 cli_close(cli, fnum);
7399 status = cli_chkpath(cli, "\\chkpath.dir");
7400 if (!NT_STATUS_IS_OK(status)) {
7401 printf("chkpath1 failed: %s\n", nt_errstr(status));
7405 status = cli_chkpath(cli, "\\chkpath.dir\\dir2");
7406 if (!NT_STATUS_IS_OK(status)) {
7407 printf("chkpath2 failed: %s\n", nt_errstr(status));
7411 status = cli_chkpath(cli, "\\chkpath.dir\\foo.txt");
7412 if (!NT_STATUS_IS_OK(status)) {
7413 ret = check_error(__LINE__, status, ERRDOS, ERRbadpath,
7414 NT_STATUS_NOT_A_DIRECTORY);
7416 printf("* chkpath on a file should fail\n");
7420 status = cli_chkpath(cli, "\\chkpath.dir\\bar.txt");
7421 if (!NT_STATUS_IS_OK(status)) {
7422 ret = check_error(__LINE__, status, ERRDOS, ERRbadfile,
7423 NT_STATUS_OBJECT_NAME_NOT_FOUND);
7425 printf("* chkpath on a non existent file should fail\n");
7429 status = cli_chkpath(cli, "\\chkpath.dir\\dirxx\\bar.txt");
7430 if (!NT_STATUS_IS_OK(status)) {
7431 ret = check_error(__LINE__, status, ERRDOS, ERRbadpath,
7432 NT_STATUS_OBJECT_PATH_NOT_FOUND);
7434 printf("* chkpath on a non existent component should fail\n");
7438 cli_rmdir(cli, "\\chkpath.dir\\dir2");
7439 cli_unlink(cli, "\\chkpath.dir\\*", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7440 cli_rmdir(cli, "\\chkpath.dir");
7442 if (!torture_close_connection(cli)) {
7449 static bool run_eatest(int dummy)
7451 static struct cli_state *cli;
7452 const char *fname = "\\eatest.txt";
7453 bool correct = True;
7457 struct ea_struct *ea_list = NULL;
7458 TALLOC_CTX *mem_ctx = talloc_init("eatest");
7461 printf("starting eatest\n");
7463 if (!torture_open_connection(&cli, 0)) {
7464 talloc_destroy(mem_ctx);
7468 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7470 status = cli_ntcreate(cli, fname, 0,
7471 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
7472 FILE_SHARE_NONE, FILE_OVERWRITE_IF,
7473 0x4044, 0, &fnum, NULL);
7474 if (!NT_STATUS_IS_OK(status)) {
7475 printf("open failed - %s\n", nt_errstr(status));
7476 talloc_destroy(mem_ctx);
7480 for (i = 0; i < 10; i++) {
7481 fstring ea_name, ea_val;
7483 slprintf(ea_name, sizeof(ea_name), "EA_%d", i);
7484 memset(ea_val, (char)i+1, i+1);
7485 status = cli_set_ea_fnum(cli, fnum, ea_name, ea_val, i+1);
7486 if (!NT_STATUS_IS_OK(status)) {
7487 printf("ea_set of name %s failed - %s\n", ea_name,
7489 talloc_destroy(mem_ctx);
7494 cli_close(cli, fnum);
7495 for (i = 0; i < 10; i++) {
7496 fstring ea_name, ea_val;
7498 slprintf(ea_name, sizeof(ea_name), "EA_%d", i+10);
7499 memset(ea_val, (char)i+1, i+1);
7500 status = cli_set_ea_path(cli, fname, ea_name, ea_val, i+1);
7501 if (!NT_STATUS_IS_OK(status)) {
7502 printf("ea_set of name %s failed - %s\n", ea_name,
7504 talloc_destroy(mem_ctx);
7509 status = cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list);
7510 if (!NT_STATUS_IS_OK(status)) {
7511 printf("ea_get list failed - %s\n", nt_errstr(status));
7515 printf("num_eas = %d\n", (int)num_eas);
7517 if (num_eas != 20) {
7518 printf("Should be 20 EA's stored... failing.\n");
7522 for (i = 0; i < num_eas; i++) {
7523 printf("%d: ea_name = %s. Val = ", i, ea_list[i].name);
7524 dump_data(0, ea_list[i].value.data,
7525 ea_list[i].value.length);
7528 /* Setting EA's to zero length deletes them. Test this */
7529 printf("Now deleting all EA's - case indepenent....\n");
7532 cli_set_ea_path(cli, fname, "", "", 0);
7534 for (i = 0; i < 20; i++) {
7536 slprintf(ea_name, sizeof(ea_name), "ea_%d", i);
7537 status = cli_set_ea_path(cli, fname, ea_name, "", 0);
7538 if (!NT_STATUS_IS_OK(status)) {
7539 printf("ea_set of name %s failed - %s\n", ea_name,
7541 talloc_destroy(mem_ctx);
7547 status = cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list);
7548 if (!NT_STATUS_IS_OK(status)) {
7549 printf("ea_get list failed - %s\n", nt_errstr(status));
7553 printf("num_eas = %d\n", (int)num_eas);
7554 for (i = 0; i < num_eas; i++) {
7555 printf("%d: ea_name = %s. Val = ", i, ea_list[i].name);
7556 dump_data(0, ea_list[i].value.data,
7557 ea_list[i].value.length);
7561 printf("deleting EA's failed.\n");
7565 /* Try and delete a non existent EA. */
7566 status = cli_set_ea_path(cli, fname, "foo", "", 0);
7567 if (!NT_STATUS_IS_OK(status)) {
7568 printf("deleting non-existent EA 'foo' should succeed. %s\n",
7573 talloc_destroy(mem_ctx);
7574 if (!torture_close_connection(cli)) {
7581 static bool run_dirtest1(int dummy)
7584 static struct cli_state *cli;
7587 bool correct = True;
7589 printf("starting directory test\n");
7591 if (!torture_open_connection(&cli, 0)) {
7595 smbXcli_conn_set_sockopt(cli->conn, sockops);
7597 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
7598 cli_list(cli, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, del_fn, cli);
7599 cli_rmdir(cli, "\\LISTDIR");
7600 cli_mkdir(cli, "\\LISTDIR");
7602 /* Create 1000 files and 1000 directories. */
7603 for (i=0;i<1000;i++) {
7605 slprintf(fname, sizeof(fname), "\\LISTDIR\\f%d", i);
7606 if (!NT_STATUS_IS_OK(cli_ntcreate(cli, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
7607 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF,
7608 0, 0, &fnum, NULL))) {
7609 fprintf(stderr,"Failed to open %s\n", fname);
7612 cli_close(cli, fnum);
7614 for (i=0;i<1000;i++) {
7616 slprintf(fname, sizeof(fname), "\\LISTDIR\\d%d", i);
7617 if (!NT_STATUS_IS_OK(cli_mkdir(cli, fname))) {
7618 fprintf(stderr,"Failed to open %s\n", fname);
7623 /* Now ensure that doing an old list sees both files and directories. */
7625 cli_list_old(cli, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, list_fn, &num_seen);
7626 printf("num_seen = %d\n", num_seen );
7627 /* We should see 100 files + 1000 directories + . and .. */
7628 if (num_seen != 2002)
7631 /* Ensure if we have the "must have" bits we only see the
7635 cli_list_old(cli, "\\LISTDIR\\*", (FILE_ATTRIBUTE_DIRECTORY<<8)|FILE_ATTRIBUTE_DIRECTORY, list_fn, &num_seen);
7636 printf("num_seen = %d\n", num_seen );
7637 if (num_seen != 1002)
7641 cli_list_old(cli, "\\LISTDIR\\*", (FILE_ATTRIBUTE_ARCHIVE<<8)|FILE_ATTRIBUTE_DIRECTORY, list_fn, &num_seen);
7642 printf("num_seen = %d\n", num_seen );
7643 if (num_seen != 1000)
7646 /* Delete everything. */
7647 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
7648 cli_list(cli, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, del_fn, cli);
7649 cli_rmdir(cli, "\\LISTDIR");
7652 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
7653 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
7654 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
7657 if (!torture_close_connection(cli)) {
7661 printf("finished dirtest1\n");
7666 static bool run_error_map_extract(int dummy) {
7668 static struct cli_state *c_dos;
7669 static struct cli_state *c_nt;
7681 /* NT-Error connection */
7683 disable_spnego = true;
7684 if (!(c_nt = open_nbt_connection())) {
7685 disable_spnego = false;
7688 disable_spnego = false;
7690 status = smbXcli_negprot(c_nt->conn, c_nt->timeout, PROTOCOL_CORE,
7693 if (!NT_STATUS_IS_OK(status)) {
7694 printf("%s rejected the NT-error negprot (%s)\n", host,
7700 status = cli_session_setup_anon(c_nt);
7701 if (!NT_STATUS_IS_OK(status)) {
7702 printf("%s rejected the NT-error initial session setup (%s)\n",host, nt_errstr(status));
7706 /* DOS-Error connection */
7708 disable_spnego = true;
7709 force_dos_errors = true;
7710 if (!(c_dos = open_nbt_connection())) {
7711 disable_spnego = false;
7712 force_dos_errors = false;
7715 disable_spnego = false;
7716 force_dos_errors = false;
7718 status = smbXcli_negprot(c_dos->conn, c_dos->timeout, PROTOCOL_CORE,
7720 if (!NT_STATUS_IS_OK(status)) {
7721 printf("%s rejected the DOS-error negprot (%s)\n", host,
7723 cli_shutdown(c_dos);
7727 status = cli_session_setup_anon(c_dos);
7728 if (!NT_STATUS_IS_OK(status)) {
7729 printf("%s rejected the DOS-error initial session setup (%s)\n",
7730 host, nt_errstr(status));
7734 c_nt->map_dos_errors = false;
7735 c_dos->map_dos_errors = false;
7737 for (error=(0xc0000000 | 0x1); error < (0xc0000000| 0xFFF); error++) {
7738 struct cli_credentials *user_creds = NULL;
7740 fstr_sprintf(user, "%X", error);
7742 user_creds = cli_session_creds_init(talloc_tos(),
7747 false, /* use_kerberos */
7748 false, /* fallback_after_kerberos */
7749 false, /* use_ccache */
7750 false); /* password_is_nt_hash */
7751 if (user_creds == NULL) {
7752 printf("cli_session_creds_init(%s) failed\n", user);
7756 status = cli_session_setup_creds(c_nt, user_creds);
7757 if (NT_STATUS_IS_OK(status)) {
7758 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
7761 /* Case #1: 32-bit NT errors */
7762 if (!NT_STATUS_IS_DOS(status)) {
7765 printf("/** Dos error on NT connection! (%s) */\n",
7767 nt_status = NT_STATUS(0xc0000000);
7770 status = cli_session_setup_creds(c_dos, user_creds);
7771 if (NT_STATUS_IS_OK(status)) {
7772 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
7775 /* Case #1: 32-bit NT errors */
7776 if (NT_STATUS_IS_DOS(status)) {
7777 printf("/** NT error on DOS connection! (%s) */\n",
7779 errnum = errclass = 0;
7781 errclass = NT_STATUS_DOS_CLASS(status);
7782 errnum = NT_STATUS_DOS_CODE(status);
7785 if (NT_STATUS_V(nt_status) != error) {
7786 printf("/*\t{ This NT error code was 'sqashed'\n\t from %s to %s \n\t during the session setup }\n*/\n",
7787 get_nt_error_c_code(talloc_tos(), NT_STATUS(error)),
7788 get_nt_error_c_code(talloc_tos(), nt_status));
7791 printf("\t{%s,\t%s,\t%s},\n",
7792 smb_dos_err_class(errclass),
7793 smb_dos_err_name(errclass, errnum),
7794 get_nt_error_c_code(talloc_tos(), NT_STATUS(error)));
7796 TALLOC_FREE(user_creds);
7801 static bool run_sesssetup_bench(int dummy)
7803 static struct cli_state *c;
7804 const char *fname = "\\file.dat";
7809 if (!torture_open_connection(&c, 0)) {
7813 status = cli_ntcreate(c, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
7814 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
7815 FILE_DELETE_ON_CLOSE, 0, &fnum, NULL);
7816 if (!NT_STATUS_IS_OK(status)) {
7817 d_printf("open %s failed: %s\n", fname, nt_errstr(status));
7821 for (i=0; i<torture_numops; i++) {
7822 status = cli_session_setup_creds(c, torture_creds);
7823 if (!NT_STATUS_IS_OK(status)) {
7824 d_printf("(%s) cli_session_setup_creds failed: %s\n",
7825 __location__, nt_errstr(status));
7829 d_printf("\r%d ", (int)cli_state_get_uid(c));
7831 status = cli_ulogoff(c);
7832 if (!NT_STATUS_IS_OK(status)) {
7833 d_printf("(%s) cli_ulogoff failed: %s\n",
7834 __location__, nt_errstr(status));
7842 static bool subst_test(const char *str, const char *user, const char *domain,
7843 uid_t uid, gid_t gid, const char *expected)
7848 subst = talloc_sub_specified(talloc_tos(), str, user, NULL, domain, uid, gid);
7850 if (strcmp(subst, expected) != 0) {
7851 printf("sub_specified(%s, %s, %s, %d, %d) returned [%s], expected "
7852 "[%s]\n", str, user, domain, (int)uid, (int)gid, subst,
7861 static void chain1_open_completion(struct tevent_req *req)
7865 status = cli_openx_recv(req, &fnum);
7868 d_printf("cli_openx_recv returned %s: %d\n",
7870 NT_STATUS_IS_OK(status) ? fnum : -1);
7873 static void chain1_write_completion(struct tevent_req *req)
7877 status = cli_write_andx_recv(req, &written);
7880 d_printf("cli_write_andx_recv returned %s: %d\n",
7882 NT_STATUS_IS_OK(status) ? (int)written : -1);
7885 static void chain1_close_completion(struct tevent_req *req)
7888 bool *done = (bool *)tevent_req_callback_data_void(req);
7890 status = cli_close_recv(req);
7895 d_printf("cli_close returned %s\n", nt_errstr(status));
7898 static bool run_chain1(int dummy)
7900 struct cli_state *cli1;
7901 struct tevent_context *evt = samba_tevent_context_init(NULL);
7902 struct tevent_req *reqs[3], *smbreqs[3];
7904 const char *str = "foobar";
7907 printf("starting chain1 test\n");
7908 if (!torture_open_connection(&cli1, 0)) {
7912 smbXcli_conn_set_sockopt(cli1->conn, sockops);
7914 reqs[0] = cli_openx_create(talloc_tos(), evt, cli1, "\\test",
7915 O_CREAT|O_RDWR, 0, &smbreqs[0]);
7916 if (reqs[0] == NULL) return false;
7917 tevent_req_set_callback(reqs[0], chain1_open_completion, NULL);
7920 reqs[1] = cli_write_andx_create(talloc_tos(), evt, cli1, 0, 0,
7921 (const uint8_t *)str, 0, strlen(str)+1,
7922 smbreqs, 1, &smbreqs[1]);
7923 if (reqs[1] == NULL) return false;
7924 tevent_req_set_callback(reqs[1], chain1_write_completion, NULL);
7926 reqs[2] = cli_close_create(talloc_tos(), evt, cli1, 0, &smbreqs[2]);
7927 if (reqs[2] == NULL) return false;
7928 tevent_req_set_callback(reqs[2], chain1_close_completion, &done);
7930 status = smb1cli_req_chain_submit(smbreqs, ARRAY_SIZE(smbreqs));
7931 if (!NT_STATUS_IS_OK(status)) {
7936 tevent_loop_once(evt);
7939 torture_close_connection(cli1);
7943 static void chain2_sesssetup_completion(struct tevent_req *req)
7946 status = cli_session_setup_guest_recv(req);
7947 d_printf("sesssetup returned %s\n", nt_errstr(status));
7950 static void chain2_tcon_completion(struct tevent_req *req)
7952 bool *done = (bool *)tevent_req_callback_data_void(req);
7954 status = cli_tcon_andx_recv(req);
7955 d_printf("tcon_and_x returned %s\n", nt_errstr(status));
7959 static bool run_chain2(int dummy)
7961 struct cli_state *cli1;
7962 struct tevent_context *evt = samba_tevent_context_init(NULL);
7963 struct tevent_req *reqs[2], *smbreqs[2];
7967 printf("starting chain2 test\n");
7968 status = cli_start_connection(&cli1, lp_netbios_name(), host, NULL,
7969 port_to_use, SMB_SIGNING_DEFAULT, 0);
7970 if (!NT_STATUS_IS_OK(status)) {
7974 smbXcli_conn_set_sockopt(cli1->conn, sockops);
7976 reqs[0] = cli_session_setup_guest_create(talloc_tos(), evt, cli1,
7978 if (reqs[0] == NULL) return false;
7979 tevent_req_set_callback(reqs[0], chain2_sesssetup_completion, NULL);
7981 reqs[1] = cli_tcon_andx_create(talloc_tos(), evt, cli1, "IPC$",
7982 "?????", NULL, 0, &smbreqs[1]);
7983 if (reqs[1] == NULL) return false;
7984 tevent_req_set_callback(reqs[1], chain2_tcon_completion, &done);
7986 status = smb1cli_req_chain_submit(smbreqs, ARRAY_SIZE(smbreqs));
7987 if (!NT_STATUS_IS_OK(status)) {
7992 tevent_loop_once(evt);
7995 torture_close_connection(cli1);
8000 struct torture_createdel_state {
8001 struct tevent_context *ev;
8002 struct cli_state *cli;
8005 static void torture_createdel_created(struct tevent_req *subreq);
8006 static void torture_createdel_closed(struct tevent_req *subreq);
8008 static struct tevent_req *torture_createdel_send(TALLOC_CTX *mem_ctx,
8009 struct tevent_context *ev,
8010 struct cli_state *cli,
8013 struct tevent_req *req, *subreq;
8014 struct torture_createdel_state *state;
8016 req = tevent_req_create(mem_ctx, &state,
8017 struct torture_createdel_state);
8024 subreq = cli_ntcreate_send(
8025 state, ev, cli, name, 0,
8026 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
8027 FILE_ATTRIBUTE_NORMAL,
8028 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
8029 FILE_OPEN_IF, FILE_DELETE_ON_CLOSE, 0);
8031 if (tevent_req_nomem(subreq, req)) {
8032 return tevent_req_post(req, ev);
8034 tevent_req_set_callback(subreq, torture_createdel_created, req);
8038 static void torture_createdel_created(struct tevent_req *subreq)
8040 struct tevent_req *req = tevent_req_callback_data(
8041 subreq, struct tevent_req);
8042 struct torture_createdel_state *state = tevent_req_data(
8043 req, struct torture_createdel_state);
8047 status = cli_ntcreate_recv(subreq, &fnum, NULL);
8048 TALLOC_FREE(subreq);
8049 if (tevent_req_nterror(req, status)) {
8050 DEBUG(10, ("cli_ntcreate_recv returned %s\n",
8051 nt_errstr(status)));
8055 subreq = cli_close_send(state, state->ev, state->cli, fnum);
8056 if (tevent_req_nomem(subreq, req)) {
8059 tevent_req_set_callback(subreq, torture_createdel_closed, req);
8062 static void torture_createdel_closed(struct tevent_req *subreq)
8064 struct tevent_req *req = tevent_req_callback_data(
8065 subreq, struct tevent_req);
8068 status = cli_close_recv(subreq);
8069 if (tevent_req_nterror(req, status)) {
8070 DEBUG(10, ("cli_close_recv returned %s\n", nt_errstr(status)));
8073 tevent_req_done(req);
8076 static NTSTATUS torture_createdel_recv(struct tevent_req *req)
8078 return tevent_req_simple_recv_ntstatus(req);
8081 struct torture_createdels_state {
8082 struct tevent_context *ev;
8083 struct cli_state *cli;
8084 const char *base_name;
8088 struct tevent_req **reqs;
8091 static void torture_createdels_done(struct tevent_req *subreq);
8093 static struct tevent_req *torture_createdels_send(TALLOC_CTX *mem_ctx,
8094 struct tevent_context *ev,
8095 struct cli_state *cli,
8096 const char *base_name,
8100 struct tevent_req *req;
8101 struct torture_createdels_state *state;
8104 req = tevent_req_create(mem_ctx, &state,
8105 struct torture_createdels_state);
8111 state->base_name = talloc_strdup(state, base_name);
8112 if (tevent_req_nomem(state->base_name, req)) {
8113 return tevent_req_post(req, ev);
8115 state->num_files = MAX(num_parallel, num_files);
8117 state->received = 0;
8119 state->reqs = talloc_array(state, struct tevent_req *, num_parallel);
8120 if (tevent_req_nomem(state->reqs, req)) {
8121 return tevent_req_post(req, ev);
8124 for (i=0; i<num_parallel; i++) {
8127 name = talloc_asprintf(state, "%s%8.8d", state->base_name,
8129 if (tevent_req_nomem(name, req)) {
8130 return tevent_req_post(req, ev);
8132 state->reqs[i] = torture_createdel_send(
8133 state->reqs, state->ev, state->cli, name);
8134 if (tevent_req_nomem(state->reqs[i], req)) {
8135 return tevent_req_post(req, ev);
8137 name = talloc_move(state->reqs[i], &name);
8138 tevent_req_set_callback(state->reqs[i],
8139 torture_createdels_done, req);
8145 static void torture_createdels_done(struct tevent_req *subreq)
8147 struct tevent_req *req = tevent_req_callback_data(
8148 subreq, struct tevent_req);
8149 struct torture_createdels_state *state = tevent_req_data(
8150 req, struct torture_createdels_state);
8151 size_t num_parallel = talloc_array_length(state->reqs);
8156 status = torture_createdel_recv(subreq);
8157 if (!NT_STATUS_IS_OK(status)){
8158 DEBUG(10, ("torture_createdel_recv returned %s\n",
8159 nt_errstr(status)));
8160 TALLOC_FREE(subreq);
8161 tevent_req_nterror(req, status);
8165 for (i=0; i<num_parallel; i++) {
8166 if (subreq == state->reqs[i]) {
8170 if (i == num_parallel) {
8171 DEBUG(10, ("received something we did not send\n"));
8172 tevent_req_nterror(req, NT_STATUS_INTERNAL_ERROR);
8175 TALLOC_FREE(state->reqs[i]);
8177 if (state->sent >= state->num_files) {
8178 tevent_req_done(req);
8182 name = talloc_asprintf(state, "%s%8.8d", state->base_name,
8184 if (tevent_req_nomem(name, req)) {
8187 state->reqs[i] = torture_createdel_send(state->reqs, state->ev,
8189 if (tevent_req_nomem(state->reqs[i], req)) {
8192 name = talloc_move(state->reqs[i], &name);
8193 tevent_req_set_callback(state->reqs[i], torture_createdels_done, req);
8197 static NTSTATUS torture_createdels_recv(struct tevent_req *req)
8199 return tevent_req_simple_recv_ntstatus(req);
8202 struct swallow_notify_state {
8203 struct tevent_context *ev;
8204 struct cli_state *cli;
8206 uint32_t completion_filter;
8208 bool (*fn)(uint32_t action, const char *name, void *priv);
8212 static void swallow_notify_done(struct tevent_req *subreq);
8214 static struct tevent_req *swallow_notify_send(TALLOC_CTX *mem_ctx,
8215 struct tevent_context *ev,
8216 struct cli_state *cli,
8218 uint32_t completion_filter,
8220 bool (*fn)(uint32_t action,
8225 struct tevent_req *req, *subreq;
8226 struct swallow_notify_state *state;
8228 req = tevent_req_create(mem_ctx, &state,
8229 struct swallow_notify_state);
8236 state->completion_filter = completion_filter;
8237 state->recursive = recursive;
8241 subreq = cli_notify_send(state, state->ev, state->cli, state->fnum,
8242 0xffff, state->completion_filter,
8244 if (tevent_req_nomem(subreq, req)) {
8245 return tevent_req_post(req, ev);
8247 tevent_req_set_callback(subreq, swallow_notify_done, req);
8251 static void swallow_notify_done(struct tevent_req *subreq)
8253 struct tevent_req *req = tevent_req_callback_data(
8254 subreq, struct tevent_req);
8255 struct swallow_notify_state *state = tevent_req_data(
8256 req, struct swallow_notify_state);
8258 uint32_t i, num_changes;
8259 struct notify_change *changes;
8261 status = cli_notify_recv(subreq, state, &num_changes, &changes);
8262 TALLOC_FREE(subreq);
8263 if (!NT_STATUS_IS_OK(status)) {
8264 DEBUG(10, ("cli_notify_recv returned %s\n",
8265 nt_errstr(status)));
8266 tevent_req_nterror(req, status);
8270 for (i=0; i<num_changes; i++) {
8271 state->fn(changes[i].action, changes[i].name, state->priv);
8273 TALLOC_FREE(changes);
8275 subreq = cli_notify_send(state, state->ev, state->cli, state->fnum,
8276 0xffff, state->completion_filter,
8278 if (tevent_req_nomem(subreq, req)) {
8281 tevent_req_set_callback(subreq, swallow_notify_done, req);
8284 static bool print_notifies(uint32_t action, const char *name, void *priv)
8286 if (DEBUGLEVEL > 5) {
8287 d_printf("%d %s\n", (int)action, name);
8292 static void notify_bench_done(struct tevent_req *req)
8294 int *num_finished = (int *)tevent_req_callback_data_void(req);
8298 static bool run_notify_bench(int dummy)
8300 const char *dname = "\\notify-bench";
8301 struct tevent_context *ev;
8304 struct tevent_req *req1;
8305 struct tevent_req *req2 = NULL;
8306 int i, num_unc_names;
8307 int num_finished = 0;
8309 printf("starting notify-bench test\n");
8311 if (use_multishare_conn) {
8313 unc_list = file_lines_load(multishare_conn_fname,
8314 &num_unc_names, 0, NULL);
8315 if (!unc_list || num_unc_names <= 0) {
8316 d_printf("Failed to load unc names list from '%s'\n",
8317 multishare_conn_fname);
8320 TALLOC_FREE(unc_list);
8325 ev = samba_tevent_context_init(talloc_tos());
8327 d_printf("tevent_context_init failed\n");
8331 for (i=0; i<num_unc_names; i++) {
8332 struct cli_state *cli;
8335 base_fname = talloc_asprintf(talloc_tos(), "%s\\file%3.3d.",
8337 if (base_fname == NULL) {
8341 if (!torture_open_connection(&cli, i)) {
8345 status = cli_ntcreate(cli, dname, 0,
8346 MAXIMUM_ALLOWED_ACCESS,
8347 0, FILE_SHARE_READ|FILE_SHARE_WRITE|
8349 FILE_OPEN_IF, FILE_DIRECTORY_FILE, 0,
8352 if (!NT_STATUS_IS_OK(status)) {
8353 d_printf("Could not create %s: %s\n", dname,
8358 req1 = swallow_notify_send(talloc_tos(), ev, cli, dnum,
8359 FILE_NOTIFY_CHANGE_FILE_NAME |
8360 FILE_NOTIFY_CHANGE_DIR_NAME |
8361 FILE_NOTIFY_CHANGE_ATTRIBUTES |
8362 FILE_NOTIFY_CHANGE_LAST_WRITE,
8363 false, print_notifies, NULL);
8365 d_printf("Could not create notify request\n");
8369 req2 = torture_createdels_send(talloc_tos(), ev, cli,
8370 base_fname, 10, torture_numops);
8372 d_printf("Could not create createdels request\n");
8375 TALLOC_FREE(base_fname);
8377 tevent_req_set_callback(req2, notify_bench_done,
8381 while (num_finished < num_unc_names) {
8383 ret = tevent_loop_once(ev);
8385 d_printf("tevent_loop_once failed\n");
8390 if (!tevent_req_poll(req2, ev)) {
8391 d_printf("tevent_req_poll failed\n");
8394 status = torture_createdels_recv(req2);
8395 d_printf("torture_createdels_recv returned %s\n", nt_errstr(status));
8400 static bool run_mangle1(int dummy)
8402 struct cli_state *cli;
8403 const char *fname = "this_is_a_long_fname_to_be_mangled.txt";
8407 time_t change_time, access_time, write_time;
8411 printf("starting mangle1 test\n");
8412 if (!torture_open_connection(&cli, 0)) {
8416 smbXcli_conn_set_sockopt(cli->conn, sockops);
8418 status = cli_ntcreate(cli, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
8419 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
8421 if (!NT_STATUS_IS_OK(status)) {
8422 d_printf("open %s failed: %s\n", fname, nt_errstr(status));
8425 cli_close(cli, fnum);
8427 status = cli_qpathinfo_alt_name(cli, fname, alt_name);
8428 if (!NT_STATUS_IS_OK(status)) {
8429 d_printf("cli_qpathinfo_alt_name failed: %s\n",
8433 d_printf("alt_name: %s\n", alt_name);
8435 status = cli_openx(cli, alt_name, O_RDONLY, DENY_NONE, &fnum);
8436 if (!NT_STATUS_IS_OK(status)) {
8437 d_printf("cli_openx(%s) failed: %s\n", alt_name,
8441 cli_close(cli, fnum);
8443 status = cli_qpathinfo1(cli, alt_name, &change_time, &access_time,
8444 &write_time, &size, &mode);
8445 if (!NT_STATUS_IS_OK(status)) {
8446 d_printf("cli_qpathinfo1(%s) failed: %s\n", alt_name,
8454 static NTSTATUS mangle_illegal_list_shortname_fn(const char *mntpoint,
8455 struct file_info *f,
8459 if (f->short_name == NULL) {
8460 return NT_STATUS_OK;
8463 if (strlen(f->short_name) == 0) {
8464 return NT_STATUS_OK;
8467 printf("unexpected shortname: %s\n", f->short_name);
8469 return NT_STATUS_OBJECT_NAME_INVALID;
8472 static NTSTATUS mangle_illegal_list_name_fn(const char *mntpoint,
8473 struct file_info *f,
8479 printf("name: %s\n", f->name);
8480 fstrcpy(name, f->name);
8481 return NT_STATUS_OK;
8484 static bool run_mangle_illegal(int dummy)
8486 struct cli_state *cli = NULL;
8487 struct cli_state *cli_posix = NULL;
8488 const char *fname = "\\MANGLE_ILLEGAL\\this_is_a_long_fname_to_be_mangled.txt";
8489 const char *illegal_fname = "MANGLE_ILLEGAL/foo:bar";
8490 char *mangled_path = NULL;
8496 printf("starting mangle-illegal test\n");
8498 if (!torture_open_connection(&cli, 0)) {
8502 smbXcli_conn_set_sockopt(cli->conn, sockops);
8504 if (!torture_open_connection(&cli_posix, 0)) {
8508 smbXcli_conn_set_sockopt(cli_posix->conn, sockops);
8510 status = torture_setup_unix_extensions(cli_posix);
8511 if (!NT_STATUS_IS_OK(status)) {
8515 cli_rmdir(cli, "\\MANGLE_ILLEGAL");
8516 status = cli_mkdir(cli, "\\MANGLE_ILLEGAL");
8517 if (!NT_STATUS_IS_OK(status)) {
8518 printf("mkdir1 failed : %s\n", nt_errstr(status));
8523 * Create a file with illegal NTFS characters and test that we
8524 * get a usable mangled name
8527 cli_setatr(cli_posix, illegal_fname, 0, 0);
8528 cli_posix_unlink(cli_posix, illegal_fname);
8530 status = cli_posix_open(cli_posix, illegal_fname, O_RDWR|O_CREAT|O_EXCL,
8532 if (!NT_STATUS_IS_OK(status)) {
8533 printf("POSIX create of %s failed (%s)\n",
8534 illegal_fname, nt_errstr(status));
8538 status = cli_close(cli_posix, fnum);
8539 if (!NT_STATUS_IS_OK(status)) {
8540 printf("close failed (%s)\n", nt_errstr(status));
8544 status = cli_list(cli, "\\MANGLE_ILLEGAL\\*", 0, mangle_illegal_list_name_fn, &name);
8545 if (!NT_STATUS_IS_OK(status)) {
8546 d_printf("cli_list failed: %s\n", nt_errstr(status));
8550 mangled_path = talloc_asprintf(talloc_tos(), "\\MANGLE_ILLEGAL\\%s", name);
8551 if (mangled_path == NULL) {
8555 status = cli_openx(cli, mangled_path, O_RDONLY, DENY_NONE, &fnum);
8556 if (!NT_STATUS_IS_OK(status)) {
8557 d_printf("cli_openx(%s) failed: %s\n", mangled_path, nt_errstr(status));
8558 TALLOC_FREE(mangled_path);
8561 TALLOC_FREE(mangled_path);
8562 cli_close(cli, fnum);
8564 cli_setatr(cli_posix, illegal_fname, 0, 0);
8565 cli_posix_unlink(cli_posix, illegal_fname);
8568 * Create a file with a long name and check that we got *no* short name.
8571 status = cli_ntcreate(cli, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
8572 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
8574 if (!NT_STATUS_IS_OK(status)) {
8575 d_printf("open %s failed: %s\n", fname, nt_errstr(status));
8578 cli_close(cli, fnum);
8580 status = cli_list(cli, fname, 0, mangle_illegal_list_shortname_fn, &alt_name);
8581 if (!NT_STATUS_IS_OK(status)) {
8582 d_printf("cli_list failed\n");
8586 cli_unlink(cli, fname, 0);
8587 cli_rmdir(cli, "\\MANGLE_ILLEGAL");
8589 if (!torture_close_connection(cli_posix)) {
8593 if (!torture_close_connection(cli)) {
8600 static size_t null_source(uint8_t *buf, size_t n, void *priv)
8602 size_t *to_pull = (size_t *)priv;
8603 size_t thistime = *to_pull;
8605 thistime = MIN(thistime, n);
8606 if (thistime == 0) {
8610 memset(buf, 0, thistime);
8611 *to_pull -= thistime;
8615 static bool run_windows_write(int dummy)
8617 struct cli_state *cli1;
8621 const char *fname = "\\writetest.txt";
8622 struct timeval start_time;
8627 printf("starting windows_write test\n");
8628 if (!torture_open_connection(&cli1, 0)) {
8632 status = cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
8633 if (!NT_STATUS_IS_OK(status)) {
8634 printf("open failed (%s)\n", nt_errstr(status));
8638 smbXcli_conn_set_sockopt(cli1->conn, sockops);
8640 start_time = timeval_current();
8642 for (i=0; i<torture_numops; i++) {
8644 off_t start = i * torture_blocksize;
8645 size_t to_pull = torture_blocksize - 1;
8647 status = cli_writeall(cli1, fnum, 0, &c,
8648 start + torture_blocksize - 1, 1, NULL);
8649 if (!NT_STATUS_IS_OK(status)) {
8650 printf("cli_write failed: %s\n", nt_errstr(status));
8654 status = cli_push(cli1, fnum, 0, i * torture_blocksize, torture_blocksize,
8655 null_source, &to_pull);
8656 if (!NT_STATUS_IS_OK(status)) {
8657 printf("cli_push returned: %s\n", nt_errstr(status));
8662 seconds = timeval_elapsed(&start_time);
8663 kbytes = (double)torture_blocksize * torture_numops;
8666 printf("Wrote %d kbytes in %.2f seconds: %d kb/sec\n", (int)kbytes,
8667 (double)seconds, (int)(kbytes/seconds));
8671 cli_close(cli1, fnum);
8672 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
8673 torture_close_connection(cli1);
8677 static size_t calc_expected_return(struct cli_state *cli, size_t len_requested)
8679 size_t max_pdu = 0x1FFFF;
8681 if (cli->server_posix_capabilities & CIFS_UNIX_LARGE_READ_CAP) {
8685 if (smb1cli_conn_signing_is_active(cli->conn)) {
8689 if (smb1cli_conn_encryption_on(cli->conn)) {
8690 max_pdu = CLI_BUFFER_SIZE;
8693 if ((len_requested & 0xFFFF0000) == 0xFFFF0000) {
8694 len_requested &= 0xFFFF;
8697 return MIN(len_requested,
8698 max_pdu - (MIN_SMB_SIZE + VWV(12) + 1 /* padding byte */));
8701 static bool check_read_call(struct cli_state *cli,
8704 size_t len_requested)
8707 struct tevent_req *subreq = NULL;
8708 ssize_t len_read = 0;
8709 size_t len_expected = 0;
8710 struct tevent_context *ev = NULL;
8712 ev = samba_tevent_context_init(talloc_tos());
8717 subreq = cli_read_andx_send(talloc_tos(),
8724 if (!tevent_req_poll_ntstatus(subreq, ev, &status)) {
8728 status = cli_read_andx_recv(subreq, &len_read, &buf);
8729 if (!NT_STATUS_IS_OK(status)) {
8730 d_printf("cli_read_andx_recv failed: %s\n", nt_errstr(status));
8734 TALLOC_FREE(subreq);
8737 len_expected = calc_expected_return(cli, len_requested);
8739 if (len_expected > 0x10000 && len_read == 0x10000) {
8740 /* Windows servers only return a max of 0x10000,
8741 doesn't matter if you set CAP_LARGE_READX in
8742 the client sessionsetupX call or not. */
8743 d_printf("Windows server - returned 0x10000 on a read of 0x%x\n",
8744 (unsigned int)len_requested);
8745 } else if (len_read != len_expected) {
8746 d_printf("read of 0x%x failed: got 0x%x, expected 0x%x\n",
8747 (unsigned int)len_requested,
8748 (unsigned int)len_read,
8749 (unsigned int)len_expected);
8752 d_printf("Correct read reply.\n");
8758 /* Test large readX variants. */
8759 static bool large_readx_tests(struct cli_state *cli,
8763 /* A read of 0xFFFF0001 should *always* return 1 byte. */
8764 if (check_read_call(cli, fnum, buf, 0xFFFF0001) == false) {
8767 /* A read of 0x10000 should return 0x10000 bytes. */
8768 if (check_read_call(cli, fnum, buf, 0x10000) == false) {
8771 /* A read of 0x10000 should return 0x10001 bytes. */
8772 if (check_read_call(cli, fnum, buf, 0x10001) == false) {
8775 /* A read of 0x1FFFF - (MIN_SMB_SIZE + VWV(12) should return
8776 the requested number of bytes. */
8777 if (check_read_call(cli, fnum, buf, 0x1FFFF - (MIN_SMB_SIZE + VWV(12))) == false) {
8780 /* A read of 1MB should return 1MB bytes (on Samba). */
8781 if (check_read_call(cli, fnum, buf, 0x100000) == false) {
8785 if (check_read_call(cli, fnum, buf, 0x20001) == false) {
8788 if (check_read_call(cli, fnum, buf, 0x22000001) == false) {
8791 if (check_read_call(cli, fnum, buf, 0xFFFE0001) == false) {
8797 static bool run_large_readx(int dummy)
8799 uint8_t *buf = NULL;
8800 struct cli_state *cli1 = NULL;
8801 struct cli_state *cli2 = NULL;
8802 bool correct = false;
8803 const char *fname = "\\large_readx.dat";
8805 uint16_t fnum1 = UINT16_MAX;
8806 uint32_t normal_caps = 0;
8807 size_t file_size = 20*1024*1024;
8808 TALLOC_CTX *frame = talloc_stackframe();
8812 enum smb_signing_setting signing_setting;
8813 enum protocol_types protocol;
8817 .signing_setting = SMB_SIGNING_IF_REQUIRED,
8818 .protocol = PROTOCOL_NT1,
8820 .name = "NT1 - SIGNING_REQUIRED",
8821 .signing_setting = SMB_SIGNING_REQUIRED,
8822 .protocol = PROTOCOL_NT1,
8826 printf("starting large_readx test\n");
8828 if (!torture_open_connection(&cli1, 0)) {
8832 normal_caps = smb1cli_conn_capabilities(cli1->conn);
8834 if (!(normal_caps & CAP_LARGE_READX)) {
8835 d_printf("Server doesn't have CAP_LARGE_READX 0x%x\n",
8836 (unsigned int)normal_caps);
8840 /* Create a file of size 4MB. */
8841 status = cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS,
8842 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
8843 0, 0, &fnum1, NULL);
8845 if (!NT_STATUS_IS_OK(status)) {
8846 d_printf("open %s failed: %s\n", fname, nt_errstr(status));
8850 /* Write file_size bytes. */
8851 buf = talloc_zero_array(frame, uint8_t, file_size);
8856 status = cli_writeall(cli1,
8863 if (!NT_STATUS_IS_OK(status)) {
8864 d_printf("cli_writeall failed: %s\n", nt_errstr(status));
8868 status = cli_close(cli1, fnum1);
8869 if (!NT_STATUS_IS_OK(status)) {
8870 d_printf("cli_close failed: %s\n", nt_errstr(status));
8876 for (i=0; i < ARRAY_SIZE(runs); i++) {
8877 enum smb_signing_setting saved_signing_setting = signing_state;
8878 uint16_t fnum2 = -1;
8881 (runs[i].signing_setting == SMB_SIGNING_REQUIRED))
8883 d_printf("skip[%u] - %s\n", (unsigned)i, runs[i].name);
8887 d_printf("run[%u] - %s\n", (unsigned)i, runs[i].name);
8889 signing_state = runs[i].signing_setting;
8890 cli2 = open_nbt_connection();
8891 signing_state = saved_signing_setting;
8896 status = smbXcli_negprot(cli2->conn,
8900 if (!NT_STATUS_IS_OK(status)) {
8904 status = cli_session_setup_creds(cli2, torture_creds);
8905 if (!NT_STATUS_IS_OK(status)) {
8909 status = cli_tree_connect(cli2,
8913 if (!NT_STATUS_IS_OK(status)) {
8917 cli_set_timeout(cli2, 120000); /* set a really long timeout (2 minutes) */
8919 normal_caps = smb1cli_conn_capabilities(cli2->conn);
8921 if (!(normal_caps & CAP_LARGE_READX)) {
8922 d_printf("Server doesn't have CAP_LARGE_READX 0x%x\n",
8923 (unsigned int)normal_caps);
8928 if (force_cli_encryption(cli2, share) == false) {
8931 } else if (SERVER_HAS_UNIX_CIFS(cli2)) {
8932 uint16_t major, minor;
8933 uint32_t caplow, caphigh;
8935 status = cli_unix_extensions_version(cli2,
8938 if (!NT_STATUS_IS_OK(status)) {
8943 status = cli_ntcreate(cli2, fname, 0, FILE_READ_DATA,
8944 FILE_ATTRIBUTE_NORMAL, 0, FILE_OPEN,
8945 0, 0, &fnum2, NULL);
8946 if (!NT_STATUS_IS_OK(status)) {
8947 d_printf("Second open %s failed: %s\n", fname, nt_errstr(status));
8951 /* All reads must return less than file_size bytes. */
8952 if (!large_readx_tests(cli2, fnum2, buf)) {
8956 status = cli_close(cli2, fnum2);
8957 if (!NT_STATUS_IS_OK(status)) {
8958 d_printf("cli_close failed: %s\n", nt_errstr(status));
8963 if (!torture_close_connection(cli2)) {
8970 printf("Success on large_readx test\n");
8975 if (!torture_close_connection(cli2)) {
8981 if (fnum1 != UINT16_MAX) {
8982 status = cli_close(cli1, fnum1);
8983 if (!NT_STATUS_IS_OK(status)) {
8984 d_printf("cli_close failed: %s\n", nt_errstr(status));
8989 status = cli_unlink(cli1, fname,
8990 FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
8991 if (!NT_STATUS_IS_OK(status)) {
8992 printf("unlink failed (%s)\n", nt_errstr(status));
8995 if (!torture_close_connection(cli1)) {
9002 printf("finished large_readx test\n");
9006 static bool run_cli_echo(int dummy)
9008 struct cli_state *cli;
9011 printf("starting cli_echo test\n");
9012 if (!torture_open_connection(&cli, 0)) {
9015 smbXcli_conn_set_sockopt(cli->conn, sockops);
9017 status = cli_echo(cli, 5, data_blob_const("hello", 5));
9019 d_printf("cli_echo returned %s\n", nt_errstr(status));
9021 torture_close_connection(cli);
9022 return NT_STATUS_IS_OK(status);
9025 static bool run_uid_regression_test(int dummy)
9027 static struct cli_state *cli;
9030 bool correct = True;
9031 struct smbXcli_tcon *orig_tcon = NULL;
9034 printf("starting uid regression test\n");
9036 if (!torture_open_connection(&cli, 0)) {
9040 smbXcli_conn_set_sockopt(cli->conn, sockops);
9042 /* Ok - now save then logoff our current user. */
9043 old_vuid = cli_state_get_uid(cli);
9045 status = cli_ulogoff(cli);
9046 if (!NT_STATUS_IS_OK(status)) {
9047 d_printf("(%s) cli_ulogoff failed: %s\n",
9048 __location__, nt_errstr(status));
9053 cli_state_set_uid(cli, old_vuid);
9055 /* Try an operation. */
9056 status = cli_mkdir(cli, "\\uid_reg_test");
9057 if (NT_STATUS_IS_OK(status)) {
9058 d_printf("(%s) cli_mkdir succeeded\n",
9063 /* Should be bad uid. */
9064 if (!check_error(__LINE__, status, ERRSRV, ERRbaduid,
9065 NT_STATUS_USER_SESSION_DELETED)) {
9071 old_cnum = cli_state_get_tid(cli);
9072 orig_tcon = cli_state_save_tcon(cli);
9073 if (orig_tcon == NULL) {
9078 /* Now try a SMBtdis with the invald vuid set to zero. */
9079 cli_state_set_uid(cli, 0);
9081 /* This should succeed. */
9082 status = cli_tdis(cli);
9084 if (NT_STATUS_IS_OK(status)) {
9085 d_printf("First tdis with invalid vuid should succeed.\n");
9087 d_printf("First tdis failed (%s)\n", nt_errstr(status));
9089 cli_state_restore_tcon(cli, orig_tcon);
9093 cli_state_restore_tcon(cli, orig_tcon);
9094 cli_state_set_uid(cli, old_vuid);
9095 cli_state_set_tid(cli, old_cnum);
9097 /* This should fail. */
9098 status = cli_tdis(cli);
9099 if (NT_STATUS_IS_OK(status)) {
9100 d_printf("Second tdis with invalid vuid should fail - succeeded instead !.\n");
9104 /* Should be bad tid. */
9105 if (!check_error(__LINE__, status, ERRSRV, ERRinvnid,
9106 NT_STATUS_NETWORK_NAME_DELETED)) {
9112 cli_rmdir(cli, "\\uid_reg_test");
9121 static const char *illegal_chars = "*\\/?<>|\":";
9122 static char force_shortname_chars[] = " +,.[];=\177";
9124 static NTSTATUS shortname_del_fn(const char *mnt, struct file_info *finfo,
9125 const char *mask, void *state)
9127 struct cli_state *pcli = (struct cli_state *)state;
9129 NTSTATUS status = NT_STATUS_OK;
9131 slprintf(fname, sizeof(fname), "\\shortname\\%s", finfo->name);
9133 if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
9134 return NT_STATUS_OK;
9136 if (finfo->mode & FILE_ATTRIBUTE_DIRECTORY) {
9137 status = cli_rmdir(pcli, fname);
9138 if (!NT_STATUS_IS_OK(status)) {
9139 printf("del_fn: failed to rmdir %s\n,", fname );
9142 status = cli_unlink(pcli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
9143 if (!NT_STATUS_IS_OK(status)) {
9144 printf("del_fn: failed to unlink %s\n,", fname );
9156 static NTSTATUS shortname_list_fn(const char *mnt, struct file_info *finfo,
9157 const char *name, void *state)
9159 struct sn_state *s = (struct sn_state *)state;
9163 printf("shortname list: i = %d, name = |%s|, shortname = |%s|\n",
9164 i, finfo->name, finfo->short_name);
9167 if (strchr(force_shortname_chars, i)) {
9168 if (!finfo->short_name) {
9169 /* Shortname not created when it should be. */
9170 d_printf("(%s) ERROR: Shortname was not created for file %s containing %d\n",
9171 __location__, finfo->name, i);
9174 } else if (finfo->short_name){
9175 /* Shortname created when it should not be. */
9176 d_printf("(%s) ERROR: Shortname %s was created for file %s\n",
9177 __location__, finfo->short_name, finfo->name);
9181 return NT_STATUS_OK;
9184 static bool run_shortname_test(int dummy)
9186 static struct cli_state *cli;
9187 bool correct = True;
9193 printf("starting shortname test\n");
9195 if (!torture_open_connection(&cli, 0)) {
9199 smbXcli_conn_set_sockopt(cli->conn, sockops);
9201 cli_list(cli, "\\shortname\\*", 0, shortname_del_fn, cli);
9202 cli_list(cli, "\\shortname\\*", FILE_ATTRIBUTE_DIRECTORY, shortname_del_fn, cli);
9203 cli_rmdir(cli, "\\shortname");
9205 status = cli_mkdir(cli, "\\shortname");
9206 if (!NT_STATUS_IS_OK(status)) {
9207 d_printf("(%s) cli_mkdir of \\shortname failed: %s\n",
9208 __location__, nt_errstr(status));
9213 if (strlcpy(fname, "\\shortname\\", sizeof(fname)) >= sizeof(fname)) {
9217 if (strlcat(fname, "test .txt", sizeof(fname)) >= sizeof(fname)) {
9224 for (i = 32; i < 128; i++) {
9225 uint16_t fnum = (uint16_t)-1;
9229 if (strchr(illegal_chars, i)) {
9234 status = cli_ntcreate(cli, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
9235 FILE_SHARE_READ|FILE_SHARE_WRITE,
9236 FILE_OVERWRITE_IF, 0, 0, &fnum, NULL);
9237 if (!NT_STATUS_IS_OK(status)) {
9238 d_printf("(%s) cli_nt_create of %s failed: %s\n",
9239 __location__, fname, nt_errstr(status));
9243 cli_close(cli, fnum);
9246 status = cli_list(cli, "\\shortname\\test*.*", 0,
9247 shortname_list_fn, &s);
9248 if (s.matched != 1) {
9249 d_printf("(%s) failed to list %s: %s\n",
9250 __location__, fname, nt_errstr(status));
9255 status = cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
9256 if (!NT_STATUS_IS_OK(status)) {
9257 d_printf("(%s) failed to delete %s: %s\n",
9258 __location__, fname, nt_errstr(status));
9271 cli_list(cli, "\\shortname\\*", 0, shortname_del_fn, cli);
9272 cli_list(cli, "\\shortname\\*", FILE_ATTRIBUTE_DIRECTORY, shortname_del_fn, cli);
9273 cli_rmdir(cli, "\\shortname");
9274 torture_close_connection(cli);
9278 static void pagedsearch_cb(struct tevent_req *req)
9281 struct tldap_message *msg;
9284 rc = tldap_search_paged_recv(req, talloc_tos(), &msg);
9285 if (!TLDAP_RC_IS_SUCCESS(rc)) {
9286 d_printf("tldap_search_paged_recv failed: %s\n",
9287 tldap_rc2string(rc));
9290 if (tldap_msg_type(msg) != TLDAP_RES_SEARCH_ENTRY) {
9294 if (!tldap_entry_dn(msg, &dn)) {
9295 d_printf("tldap_entry_dn failed\n");
9298 d_printf("%s\n", dn);
9302 static bool run_tldap(int dummy)
9304 struct tldap_context *ld;
9308 struct sockaddr_storage addr;
9309 struct tevent_context *ev;
9310 struct tevent_req *req;
9314 if (!resolve_name(host, &addr, 0, false)) {
9315 d_printf("could not find host %s\n", host);
9318 status = open_socket_out(&addr, 389, 9999, &fd);
9319 if (!NT_STATUS_IS_OK(status)) {
9320 d_printf("open_socket_out failed: %s\n", nt_errstr(status));
9324 ld = tldap_context_create(talloc_tos(), fd);
9327 d_printf("tldap_context_create failed\n");
9331 rc = tldap_fetch_rootdse(ld);
9332 if (!TLDAP_RC_IS_SUCCESS(rc)) {
9333 d_printf("tldap_fetch_rootdse failed: %s\n",
9334 tldap_errstr(talloc_tos(), ld, rc));
9338 basedn = tldap_talloc_single_attribute(
9339 tldap_rootdse(ld), "defaultNamingContext", talloc_tos());
9340 if (basedn == NULL) {
9341 d_printf("no defaultNamingContext\n");
9344 d_printf("defaultNamingContext: %s\n", basedn);
9346 ev = samba_tevent_context_init(talloc_tos());
9348 d_printf("tevent_context_init failed\n");
9352 req = tldap_search_paged_send(talloc_tos(), ev, ld, basedn,
9353 TLDAP_SCOPE_SUB, "(objectclass=*)",
9355 NULL, 0, NULL, 0, 0, 0, 0, 5);
9357 d_printf("tldap_search_paged_send failed\n");
9360 tevent_req_set_callback(req, pagedsearch_cb, NULL);
9362 tevent_req_poll(req, ev);
9366 /* test search filters against rootDSE */
9367 filter = "(&(|(name=samba)(nextRid<=10000000)(usnChanged>=10)(samba~=ambas)(!(name=s*m*a)))"
9368 "(|(name:=samba)(name:dn:2.5.13.5:=samba)(:dn:2.5.13.5:=samba)(!(name=*samba))))";
9370 rc = tldap_search(ld, "", TLDAP_SCOPE_BASE, filter,
9371 NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0,
9372 talloc_tos(), NULL);
9373 if (!TLDAP_RC_IS_SUCCESS(rc)) {
9374 d_printf("tldap_search with complex filter failed: %s\n",
9375 tldap_errstr(talloc_tos(), ld, rc));
9383 /* Torture test to ensure no regression of :
9384 https://bugzilla.samba.org/show_bug.cgi?id=7084
9387 static bool run_dir_createtime(int dummy)
9389 struct cli_state *cli;
9390 const char *dname = "\\testdir";
9391 const char *fname = "\\testdir\\testfile";
9393 struct timespec create_time;
9394 struct timespec create_time1;
9398 if (!torture_open_connection(&cli, 0)) {
9402 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
9403 cli_rmdir(cli, dname);
9405 status = cli_mkdir(cli, dname);
9406 if (!NT_STATUS_IS_OK(status)) {
9407 printf("mkdir failed: %s\n", nt_errstr(status));
9411 status = cli_qpathinfo2(cli, dname, &create_time, NULL, NULL, NULL,
9413 if (!NT_STATUS_IS_OK(status)) {
9414 printf("cli_qpathinfo2 returned %s\n",
9419 /* Sleep 3 seconds, then create a file. */
9422 status = cli_openx(cli, fname, O_RDWR | O_CREAT | O_EXCL,
9424 if (!NT_STATUS_IS_OK(status)) {
9425 printf("cli_openx failed: %s\n", nt_errstr(status));
9429 status = cli_qpathinfo2(cli, dname, &create_time1, NULL, NULL, NULL,
9431 if (!NT_STATUS_IS_OK(status)) {
9432 printf("cli_qpathinfo2 (2) returned %s\n",
9437 if (timespec_compare(&create_time1, &create_time)) {
9438 printf("run_dir_createtime: create time was updated (error)\n");
9440 printf("run_dir_createtime: create time was not updated (correct)\n");
9446 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
9447 cli_rmdir(cli, dname);
9448 if (!torture_close_connection(cli)) {
9455 static bool run_streamerror(int dummy)
9457 struct cli_state *cli;
9458 const char *dname = "\\testdir";
9459 const char *streamname =
9460 "testdir:{4c8cc155-6c1e-11d1-8e41-00c04fb9386d}:$DATA";
9462 time_t change_time, access_time, write_time;
9464 uint16_t mode, fnum;
9467 if (!torture_open_connection(&cli, 0)) {
9471 cli_unlink(cli, "\\testdir\\*", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
9472 cli_rmdir(cli, dname);
9474 status = cli_mkdir(cli, dname);
9475 if (!NT_STATUS_IS_OK(status)) {
9476 printf("mkdir failed: %s\n", nt_errstr(status));
9480 status = cli_qpathinfo1(cli, streamname, &change_time, &access_time,
9481 &write_time, &size, &mode);
9482 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
9483 printf("pathinfo returned %s, expected "
9484 "NT_STATUS_OBJECT_NAME_NOT_FOUND\n",
9489 status = cli_ntcreate(cli, streamname, 0x16,
9490 FILE_READ_DATA|FILE_READ_EA|
9491 FILE_READ_ATTRIBUTES|READ_CONTROL_ACCESS,
9492 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ,
9493 FILE_OPEN, 0, 0, &fnum, NULL);
9495 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
9496 printf("ntcreate returned %s, expected "
9497 "NT_STATUS_OBJECT_NAME_NOT_FOUND\n",
9503 cli_rmdir(cli, dname);
9507 struct pidtest_state {
9513 static void pid_echo_done(struct tevent_req *subreq);
9515 static struct tevent_req *pid_echo_send(TALLOC_CTX *mem_ctx,
9516 struct tevent_context *ev,
9517 struct cli_state *cli)
9519 struct tevent_req *req, *subreq;
9520 struct pidtest_state *state;
9522 req = tevent_req_create(mem_ctx, &state, struct pidtest_state);
9527 SSVAL(state->vwv, 0, 1);
9528 state->data = data_blob_const("hello", 5);
9530 subreq = smb1cli_req_send(state,
9535 0, 0, /* *_flags2 */
9537 0xDEADBEEF, /* pid */
9540 ARRAY_SIZE(state->vwv), state->vwv,
9541 state->data.length, state->data.data);
9543 if (tevent_req_nomem(subreq, req)) {
9544 return tevent_req_post(req, ev);
9546 tevent_req_set_callback(subreq, pid_echo_done, req);
9550 static void pid_echo_done(struct tevent_req *subreq)
9552 struct tevent_req *req = tevent_req_callback_data(
9553 subreq, struct tevent_req);
9554 struct pidtest_state *state = tevent_req_data(
9555 req, struct pidtest_state);
9558 uint8_t *bytes = NULL;
9559 struct iovec *recv_iov = NULL;
9560 uint8_t *phdr = NULL;
9561 uint16_t pidlow = 0;
9562 uint16_t pidhigh = 0;
9563 struct smb1cli_req_expected_response expected[] = {
9565 .status = NT_STATUS_OK,
9570 status = smb1cli_req_recv(subreq, state,
9575 NULL, /* pvwv_offset */
9578 NULL, /* pbytes_offset */
9580 expected, ARRAY_SIZE(expected));
9582 TALLOC_FREE(subreq);
9584 if (!NT_STATUS_IS_OK(status)) {
9585 tevent_req_nterror(req, status);
9589 if (num_bytes != state->data.length) {
9590 tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
9594 if (memcmp(bytes, state->data.data, num_bytes) != 0) {
9595 tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
9599 /* Check pid low/high == DEADBEEF */
9600 pidlow = SVAL(phdr, HDR_PID);
9601 if (pidlow != 0xBEEF){
9602 printf("Incorrect pidlow 0x%x, should be 0xBEEF\n",
9603 (unsigned int)pidlow);
9604 tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
9607 pidhigh = SVAL(phdr, HDR_PIDHIGH);
9608 if (pidhigh != 0xDEAD){
9609 printf("Incorrect pidhigh 0x%x, should be 0xDEAD\n",
9610 (unsigned int)pidhigh);
9611 tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
9615 tevent_req_done(req);
9618 static NTSTATUS pid_echo_recv(struct tevent_req *req)
9620 return tevent_req_simple_recv_ntstatus(req);
9623 static bool run_pidhigh(int dummy)
9625 bool success = false;
9626 struct cli_state *cli = NULL;
9628 struct tevent_context *ev = NULL;
9629 struct tevent_req *req = NULL;
9630 TALLOC_CTX *frame = talloc_stackframe();
9632 printf("starting pid high test\n");
9633 if (!torture_open_connection(&cli, 0)) {
9636 smbXcli_conn_set_sockopt(cli->conn, sockops);
9638 ev = samba_tevent_context_init(frame);
9643 req = pid_echo_send(frame, ev, cli);
9648 if (!tevent_req_poll_ntstatus(req, ev, &status)) {
9652 status = pid_echo_recv(req);
9653 if (NT_STATUS_IS_OK(status)) {
9654 printf("pid high test ok\n");
9661 torture_close_connection(cli);
9666 Test Windows open on a bad POSIX symlink.
9668 static bool run_symlink_open_test(int dummy)
9670 static struct cli_state *cli;
9671 const char *fname = "non_existant_file";
9672 const char *sname = "dangling_symlink";
9673 uint16_t fnum = (uint16_t)-1;
9674 bool correct = false;
9676 TALLOC_CTX *frame = NULL;
9678 frame = talloc_stackframe();
9680 printf("Starting Windows bad symlink open test\n");
9682 if (!torture_open_connection(&cli, 0)) {
9687 smbXcli_conn_set_sockopt(cli->conn, sockops);
9689 status = torture_setup_unix_extensions(cli);
9690 if (!NT_STATUS_IS_OK(status)) {
9695 /* Ensure nothing exists. */
9696 cli_setatr(cli, fname, 0, 0);
9697 cli_posix_unlink(cli, fname);
9698 cli_setatr(cli, sname, 0, 0);
9699 cli_posix_unlink(cli, sname);
9701 /* Create a symlink pointing nowhere. */
9702 status = cli_posix_symlink(cli, fname, sname);
9703 if (!NT_STATUS_IS_OK(status)) {
9704 printf("cli_posix_symlink of %s -> %s failed (%s)\n",
9711 /* Now ensure that a Windows open doesn't hang. */
9712 status = cli_ntcreate(cli,
9715 FILE_READ_DATA|FILE_WRITE_DATA,
9717 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
9725 * We get either NT_STATUS_OBJECT_NAME_NOT_FOUND or
9726 * NT_STATUS_OBJECT_PATH_NOT_FOUND depending on if
9727 * we use O_NOFOLLOW on the server or not.
9729 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND) ||
9730 NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_PATH_NOT_FOUND))
9734 printf("cli_ntcreate of %s returned %s - should return"
9735 " either (%s) or (%s)\n",
9738 nt_errstr(NT_STATUS_OBJECT_NAME_NOT_FOUND),
9739 nt_errstr(NT_STATUS_OBJECT_PATH_NOT_FOUND));
9747 if (fnum != (uint16_t)-1) {
9748 cli_close(cli, fnum);
9749 fnum = (uint16_t)-1;
9752 cli_setatr(cli, sname, 0, 0);
9753 cli_posix_unlink(cli, sname);
9754 cli_setatr(cli, fname, 0, 0);
9755 cli_posix_unlink(cli, fname);
9757 if (!torture_close_connection(cli)) {
9765 static bool run_local_substitute(int dummy)
9769 ok &= subst_test("%U", "bla", "", -1, -1, "bla");
9770 ok &= subst_test("%u%U", "bla", "", -1, -1, "blabla");
9771 ok &= subst_test("%g", "", "", -1, -1, "NO_GROUP");
9772 ok &= subst_test("%G", "", "", -1, -1, "NO_GROUP");
9773 ok &= subst_test("%g", "", "", -1, 0, gidtoname(0));
9774 ok &= subst_test("%G", "", "", -1, 0, gidtoname(0));
9775 ok &= subst_test("%D%u", "u", "dom", -1, 0, "domu");
9776 ok &= subst_test("%i %I", "", "", -1, -1, "0.0.0.0 0.0.0.0");
9778 /* Different captialization rules in sub_basic... */
9780 ok &= (strcmp(talloc_sub_basic(talloc_tos(), "BLA", "dom", "%U%D"),
9786 static bool run_local_base64(int dummy)
9791 for (i=1; i<2000; i++) {
9792 DATA_BLOB blob1, blob2;
9795 blob1.data = talloc_array(talloc_tos(), uint8_t, i);
9797 generate_random_buffer(blob1.data, blob1.length);
9799 b64 = base64_encode_data_blob(talloc_tos(), blob1);
9801 d_fprintf(stderr, "base64_encode_data_blob failed "
9802 "for %d bytes\n", i);
9805 blob2 = base64_decode_data_blob(b64);
9808 if (data_blob_cmp(&blob1, &blob2)) {
9809 d_fprintf(stderr, "data_blob_cmp failed for %d "
9813 TALLOC_FREE(blob1.data);
9814 data_blob_free(&blob2);
9819 static void parse_fn(time_t timeout, DATA_BLOB blob, void *private_data)
9824 static bool run_local_gencache(int dummy)
9830 struct memcache *mem;
9833 mem = memcache_init(NULL, 0);
9835 d_printf("%s: memcache_init failed\n", __location__);
9838 memcache_set_global(mem);
9840 if (!gencache_set("foo", "bar", time(NULL) + 1000)) {
9841 d_printf("%s: gencache_set() failed\n", __location__);
9845 if (!gencache_get("foo", NULL, NULL, NULL)) {
9846 d_printf("%s: gencache_get() failed\n", __location__);
9850 for (i=0; i<1000000; i++) {
9851 gencache_parse("foo", parse_fn, NULL);
9854 if (!gencache_get("foo", talloc_tos(), &val, &tm)) {
9855 d_printf("%s: gencache_get() failed\n", __location__);
9860 if (!gencache_get("foo", talloc_tos(), &val, &tm)) {
9861 d_printf("%s: gencache_get() failed\n", __location__);
9865 if (strcmp(val, "bar") != 0) {
9866 d_printf("%s: gencache_get() returned %s, expected %s\n",
9867 __location__, val, "bar");
9874 if (!gencache_del("foo")) {
9875 d_printf("%s: gencache_del() failed\n", __location__);
9878 if (gencache_del("foo")) {
9879 d_printf("%s: second gencache_del() succeeded\n",
9884 if (gencache_get("foo", talloc_tos(), &val, &tm)) {
9885 d_printf("%s: gencache_get() on deleted entry "
9886 "succeeded\n", __location__);
9890 blob = data_blob_string_const_null("bar");
9891 tm = time(NULL) + 60;
9893 if (!gencache_set_data_blob("foo", &blob, tm)) {
9894 d_printf("%s: gencache_set_data_blob() failed\n", __location__);
9898 if (!gencache_get_data_blob("foo", talloc_tos(), &blob, NULL, NULL)) {
9899 d_printf("%s: gencache_get_data_blob() failed\n", __location__);
9903 if (strcmp((const char *)blob.data, "bar") != 0) {
9904 d_printf("%s: gencache_get_data_blob() returned %s, expected %s\n",
9905 __location__, (const char *)blob.data, "bar");
9906 data_blob_free(&blob);
9910 data_blob_free(&blob);
9912 if (!gencache_del("foo")) {
9913 d_printf("%s: gencache_del() failed\n", __location__);
9916 if (gencache_del("foo")) {
9917 d_printf("%s: second gencache_del() succeeded\n",
9922 if (gencache_get_data_blob("foo", talloc_tos(), &blob, NULL, NULL)) {
9923 d_printf("%s: gencache_get_data_blob() on deleted entry "
9924 "succeeded\n", __location__);
9929 blob.data = (uint8_t *)&v;
9930 blob.length = sizeof(v);
9932 if (!gencache_set_data_blob("blob", &blob, tm)) {
9933 d_printf("%s: gencache_set_data_blob() failed\n",
9937 if (gencache_get("blob", talloc_tos(), &val, &tm)) {
9938 d_printf("%s: gencache_get succeeded\n", __location__);
9945 static bool rbt_testval(struct db_context *db, const char *key,
9948 struct db_record *rec;
9949 TDB_DATA data = string_tdb_data(value);
9954 rec = dbwrap_fetch_locked(db, db, string_tdb_data(key));
9956 d_fprintf(stderr, "fetch_locked failed\n");
9959 status = dbwrap_record_store(rec, data, 0);
9960 if (!NT_STATUS_IS_OK(status)) {
9961 d_fprintf(stderr, "store failed: %s\n", nt_errstr(status));
9966 rec = dbwrap_fetch_locked(db, db, string_tdb_data(key));
9968 d_fprintf(stderr, "second fetch_locked failed\n");
9972 dbvalue = dbwrap_record_get_value(rec);
9973 if ((dbvalue.dsize != data.dsize)
9974 || (memcmp(dbvalue.dptr, data.dptr, data.dsize) != 0)) {
9975 d_fprintf(stderr, "Got wrong data back\n");
9985 static int local_rbtree_traverse_read(struct db_record *rec, void *private_data)
9987 int *count2 = (int *)private_data;
9992 static int local_rbtree_traverse_delete(struct db_record *rec, void *private_data)
9994 int *count2 = (int *)private_data;
9996 dbwrap_record_delete(rec);
10000 static bool run_local_rbtree(int dummy)
10002 struct db_context *db;
10009 db = db_open_rbt(NULL);
10012 d_fprintf(stderr, "db_open_rbt failed\n");
10016 for (i=0; i<1000; i++) {
10019 if (asprintf(&key, "key%ld", random()) == -1) {
10022 if (asprintf(&value, "value%ld", random()) == -1) {
10027 if (!rbt_testval(db, key, value)) {
10034 if (asprintf(&value, "value%ld", random()) == -1) {
10039 if (!rbt_testval(db, key, value)) {
10050 count = 0; count2 = 0;
10051 status = dbwrap_traverse_read(db, local_rbtree_traverse_read,
10053 printf("%s: read1: %d %d, %s\n", __func__, count, count2, nt_errstr(status));
10054 if ((count != count2) || (count != 1000)) {
10057 count = 0; count2 = 0;
10058 status = dbwrap_traverse(db, local_rbtree_traverse_delete,
10060 printf("%s: delete: %d %d, %s\n", __func__, count, count2, nt_errstr(status));
10061 if ((count != count2) || (count != 1000)) {
10064 count = 0; count2 = 0;
10065 status = dbwrap_traverse_read(db, local_rbtree_traverse_read,
10067 printf("%s: read2: %d %d, %s\n", __func__, count, count2, nt_errstr(status));
10068 if ((count != count2) || (count != 0)) {
10079 local test for character set functions
10081 This is a very simple test for the functionality in convert_string_error()
10083 static bool run_local_convert_string(int dummy)
10085 TALLOC_CTX *tmp_ctx = talloc_new(NULL);
10086 const char *test_strings[2] = { "March", "M\303\244rz" };
10090 for (i=0; i<2; i++) {
10091 const char *str = test_strings[i];
10092 int len = strlen(str);
10093 size_t converted_size;
10096 memset(dst, 'X', sizeof(dst));
10098 /* first try with real source length */
10099 ret = convert_string_error(CH_UNIX, CH_UTF8,
10104 d_fprintf(stderr, "Failed to convert '%s' to CH_DISPLAY\n", str);
10108 if (converted_size != len) {
10109 d_fprintf(stderr, "Converted size of '%s' should be %d - got %d\n",
10110 str, len, (int)converted_size);
10114 if (strncmp(str, dst, converted_size) != 0) {
10115 d_fprintf(stderr, "Expected '%s' to match '%s'\n", str, dst);
10119 if (strlen(str) != converted_size) {
10120 d_fprintf(stderr, "Expected '%s' length %d - got %d\n", str,
10121 (int)strlen(str), (int)converted_size);
10125 if (dst[converted_size] != 'X') {
10126 d_fprintf(stderr, "Expected no termination of '%s'\n", dst);
10130 /* now with srclen==-1, this causes the nul to be
10132 ret = convert_string_error(CH_UNIX, CH_UTF8,
10137 d_fprintf(stderr, "Failed to convert '%s' to CH_DISPLAY\n", str);
10141 if (converted_size != len+1) {
10142 d_fprintf(stderr, "Converted size of '%s' should be %d - got %d\n",
10143 str, len, (int)converted_size);
10147 if (strncmp(str, dst, converted_size) != 0) {
10148 d_fprintf(stderr, "Expected '%s' to match '%s'\n", str, dst);
10152 if (len+1 != converted_size) {
10153 d_fprintf(stderr, "Expected '%s' length %d - got %d\n", str,
10154 len+1, (int)converted_size);
10158 if (dst[converted_size] != 'X') {
10159 d_fprintf(stderr, "Expected no termination of '%s'\n", dst);
10166 TALLOC_FREE(tmp_ctx);
10169 TALLOC_FREE(tmp_ctx);
10174 struct talloc_dict_test {
10178 static int talloc_dict_traverse_fn(DATA_BLOB key, void *data, void *priv)
10180 int *count = (int *)priv;
10185 static bool run_local_talloc_dict(int dummy)
10187 struct talloc_dict *dict;
10188 struct talloc_dict_test *t;
10189 int key, count, res;
10192 dict = talloc_dict_init(talloc_tos());
10193 if (dict == NULL) {
10197 t = talloc(talloc_tos(), struct talloc_dict_test);
10204 ok = talloc_dict_set(dict, data_blob_const(&key, sizeof(key)), &t);
10210 res = talloc_dict_traverse(dict, talloc_dict_traverse_fn, &count);
10219 if (count != res) {
10228 static bool run_local_string_to_sid(int dummy) {
10229 struct dom_sid sid;
10231 if (string_to_sid(&sid, "S--1-5-32-545")) {
10232 printf("allowing S--1-5-32-545\n");
10235 if (string_to_sid(&sid, "S-1-5-32-+545")) {
10236 printf("allowing S-1-5-32-+545\n");
10239 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")) {
10240 printf("allowing S-1-2-3-4-5-6-7-8-9-0-1-2-3-4-5-6-7-8-9-0\n");
10243 if (string_to_sid(&sid, "S-1-5-32-545-abc")) {
10244 printf("allowing S-1-5-32-545-abc\n");
10247 if (string_to_sid(&sid, "S-300-5-32-545")) {
10248 printf("allowing S-300-5-32-545\n");
10251 if (string_to_sid(&sid, "S-1-0xfffffffffffffe-32-545")) {
10252 printf("allowing S-1-0xfffffffffffffe-32-545\n");
10255 if (string_to_sid(&sid, "S-1-0xffffffffffff-5294967297-545")) {
10256 printf("allowing S-1-0xffffffffffff-5294967297-545\n");
10259 if (!string_to_sid(&sid, "S-1-0xfffffffffffe-32-545")) {
10260 printf("could not parse S-1-0xfffffffffffe-32-545\n");
10263 if (!string_to_sid(&sid, "S-1-5-32-545")) {
10264 printf("could not parse S-1-5-32-545\n");
10267 if (!dom_sid_equal(&sid, &global_sid_Builtin_Users)) {
10268 printf("mis-parsed S-1-5-32-545 as %s\n",
10269 sid_string_tos(&sid));
10275 static bool sid_to_string_test(const char *expected) {
10278 struct dom_sid sid;
10280 if (!string_to_sid(&sid, expected)) {
10281 printf("could not parse %s\n", expected);
10285 str = dom_sid_string(NULL, &sid);
10286 if (strcmp(str, expected)) {
10287 printf("Comparison failed (%s != %s)\n", str, expected);
10294 static bool run_local_sid_to_string(int dummy) {
10295 if (!sid_to_string_test("S-1-0xffffffffffff-1-1-1-1-1-1-1-1-1-1-1-1"))
10297 if (!sid_to_string_test("S-1-545"))
10299 if (!sid_to_string_test("S-255-3840-1-1-1-1"))
10304 static bool run_local_binary_to_sid(int dummy) {
10305 struct dom_sid *sid = talloc(NULL, struct dom_sid);
10306 static const uint8_t good_binary_sid[] = {
10307 0x1, /* revision number */
10308 15, /* num auths */
10309 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, /* id_auth */
10310 0x1, 0x1, 0x1, 0x1, /* auth[0] */
10311 0x1, 0x1, 0x1, 0x1, /* auth[1] */
10312 0x1, 0x1, 0x1, 0x1, /* auth[2] */
10313 0x1, 0x1, 0x1, 0x1, /* auth[3] */
10314 0x1, 0x1, 0x1, 0x1, /* auth[4] */
10315 0x1, 0x1, 0x1, 0x1, /* auth[5] */
10316 0x1, 0x1, 0x1, 0x1, /* auth[6] */
10317 0x1, 0x1, 0x1, 0x1, /* auth[7] */
10318 0x1, 0x1, 0x1, 0x1, /* auth[8] */
10319 0x1, 0x1, 0x1, 0x1, /* auth[9] */
10320 0x1, 0x1, 0x1, 0x1, /* auth[10] */
10321 0x1, 0x1, 0x1, 0x1, /* auth[11] */
10322 0x1, 0x1, 0x1, 0x1, /* auth[12] */
10323 0x1, 0x1, 0x1, 0x1, /* auth[13] */
10324 0x1, 0x1, 0x1, 0x1, /* auth[14] */
10327 static const uint8_t long_binary_sid[] = {
10328 0x1, /* revision number */
10329 15, /* num auths */
10330 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, /* id_auth */
10331 0x1, 0x1, 0x1, 0x1, /* auth[0] */
10332 0x1, 0x1, 0x1, 0x1, /* auth[1] */
10333 0x1, 0x1, 0x1, 0x1, /* auth[2] */
10334 0x1, 0x1, 0x1, 0x1, /* auth[3] */
10335 0x1, 0x1, 0x1, 0x1, /* auth[4] */
10336 0x1, 0x1, 0x1, 0x1, /* auth[5] */
10337 0x1, 0x1, 0x1, 0x1, /* auth[6] */
10338 0x1, 0x1, 0x1, 0x1, /* auth[7] */
10339 0x1, 0x1, 0x1, 0x1, /* auth[8] */
10340 0x1, 0x1, 0x1, 0x1, /* auth[9] */
10341 0x1, 0x1, 0x1, 0x1, /* auth[10] */
10342 0x1, 0x1, 0x1, 0x1, /* auth[11] */
10343 0x1, 0x1, 0x1, 0x1, /* auth[12] */
10344 0x1, 0x1, 0x1, 0x1, /* auth[13] */
10345 0x1, 0x1, 0x1, 0x1, /* auth[14] */
10346 0x1, 0x1, 0x1, 0x1, /* auth[15] */
10347 0x1, 0x1, 0x1, 0x1, /* auth[16] */
10348 0x1, 0x1, 0x1, 0x1, /* auth[17] */
10351 static const uint8_t long_binary_sid2[] = {
10352 0x1, /* revision number */
10353 32, /* num auths */
10354 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, /* id_auth */
10355 0x1, 0x1, 0x1, 0x1, /* auth[0] */
10356 0x1, 0x1, 0x1, 0x1, /* auth[1] */
10357 0x1, 0x1, 0x1, 0x1, /* auth[2] */
10358 0x1, 0x1, 0x1, 0x1, /* auth[3] */
10359 0x1, 0x1, 0x1, 0x1, /* auth[4] */
10360 0x1, 0x1, 0x1, 0x1, /* auth[5] */
10361 0x1, 0x1, 0x1, 0x1, /* auth[6] */
10362 0x1, 0x1, 0x1, 0x1, /* auth[7] */
10363 0x1, 0x1, 0x1, 0x1, /* auth[8] */
10364 0x1, 0x1, 0x1, 0x1, /* auth[9] */
10365 0x1, 0x1, 0x1, 0x1, /* auth[10] */
10366 0x1, 0x1, 0x1, 0x1, /* auth[11] */
10367 0x1, 0x1, 0x1, 0x1, /* auth[12] */
10368 0x1, 0x1, 0x1, 0x1, /* auth[13] */
10369 0x1, 0x1, 0x1, 0x1, /* auth[14] */
10370 0x1, 0x1, 0x1, 0x1, /* auth[15] */
10371 0x1, 0x1, 0x1, 0x1, /* auth[16] */
10372 0x1, 0x1, 0x1, 0x1, /* auth[17] */
10373 0x1, 0x1, 0x1, 0x1, /* auth[18] */
10374 0x1, 0x1, 0x1, 0x1, /* auth[19] */
10375 0x1, 0x1, 0x1, 0x1, /* auth[20] */
10376 0x1, 0x1, 0x1, 0x1, /* auth[21] */
10377 0x1, 0x1, 0x1, 0x1, /* auth[22] */
10378 0x1, 0x1, 0x1, 0x1, /* auth[23] */
10379 0x1, 0x1, 0x1, 0x1, /* auth[24] */
10380 0x1, 0x1, 0x1, 0x1, /* auth[25] */
10381 0x1, 0x1, 0x1, 0x1, /* auth[26] */
10382 0x1, 0x1, 0x1, 0x1, /* auth[27] */
10383 0x1, 0x1, 0x1, 0x1, /* auth[28] */
10384 0x1, 0x1, 0x1, 0x1, /* auth[29] */
10385 0x1, 0x1, 0x1, 0x1, /* auth[30] */
10386 0x1, 0x1, 0x1, 0x1, /* auth[31] */
10389 if (!sid_parse(good_binary_sid, sizeof(good_binary_sid), sid)) {
10392 if (sid_parse(long_binary_sid2, sizeof(long_binary_sid2), sid)) {
10395 if (sid_parse(long_binary_sid, sizeof(long_binary_sid), sid)) {
10401 /* Split a path name into filename and stream name components. Canonicalise
10402 * such that an implicit $DATA token is always explicit.
10404 * The "specification" of this function can be found in the
10405 * run_local_stream_name() function in torture.c, I've tried those
10406 * combinations against a W2k3 server.
10409 static NTSTATUS split_ntfs_stream_name(TALLOC_CTX *mem_ctx, const char *fname,
10410 char **pbase, char **pstream)
10413 char *stream = NULL;
10414 char *sname; /* stream name */
10415 const char *stype; /* stream type */
10417 DEBUG(10, ("split_ntfs_stream_name called for [%s]\n", fname));
10419 sname = strchr_m(fname, ':');
10421 if (sname == NULL) {
10422 if (pbase != NULL) {
10423 base = talloc_strdup(mem_ctx, fname);
10424 NT_STATUS_HAVE_NO_MEMORY(base);
10429 if (pbase != NULL) {
10430 base = talloc_strndup(mem_ctx, fname, PTR_DIFF(sname, fname));
10431 NT_STATUS_HAVE_NO_MEMORY(base);
10436 stype = strchr_m(sname, ':');
10438 if (stype == NULL) {
10439 sname = talloc_strdup(mem_ctx, sname);
10443 if (strcasecmp_m(stype, ":$DATA") != 0) {
10445 * If there is an explicit stream type, so far we only
10446 * allow $DATA. Is there anything else allowed? -- vl
10448 DEBUG(10, ("[%s] is an invalid stream type\n", stype));
10450 return NT_STATUS_OBJECT_NAME_INVALID;
10452 sname = talloc_strndup(mem_ctx, sname, PTR_DIFF(stype, sname));
10456 if (sname == NULL) {
10458 return NT_STATUS_NO_MEMORY;
10461 if (sname[0] == '\0') {
10463 * no stream name, so no stream
10468 if (pstream != NULL) {
10469 stream = talloc_asprintf(mem_ctx, "%s:%s", sname, stype);
10470 if (stream == NULL) {
10471 TALLOC_FREE(sname);
10473 return NT_STATUS_NO_MEMORY;
10476 * upper-case the type field
10478 (void)strupper_m(strchr_m(stream, ':')+1);
10482 if (pbase != NULL) {
10485 if (pstream != NULL) {
10488 return NT_STATUS_OK;
10491 static bool test_stream_name(const char *fname, const char *expected_base,
10492 const char *expected_stream,
10493 NTSTATUS expected_status)
10497 char *stream = NULL;
10499 status = split_ntfs_stream_name(talloc_tos(), fname, &base, &stream);
10500 if (!NT_STATUS_EQUAL(status, expected_status)) {
10504 if (!NT_STATUS_IS_OK(status)) {
10508 if (base == NULL) goto error;
10510 if (strcmp(expected_base, base) != 0) goto error;
10512 if ((expected_stream != NULL) && (stream == NULL)) goto error;
10513 if ((expected_stream == NULL) && (stream != NULL)) goto error;
10515 if ((stream != NULL) && (strcmp(expected_stream, stream) != 0))
10519 TALLOC_FREE(stream);
10523 d_fprintf(stderr, "Do test_stream(%s, %s, %s, %s)\n",
10524 fname, expected_base ? expected_base : "<NULL>",
10525 expected_stream ? expected_stream : "<NULL>",
10526 nt_errstr(expected_status));
10527 d_fprintf(stderr, "-> base=%s, stream=%s, status=%s\n",
10528 base ? base : "<NULL>", stream ? stream : "<NULL>",
10529 nt_errstr(status));
10531 TALLOC_FREE(stream);
10535 static bool run_local_stream_name(int dummy)
10539 ret &= test_stream_name(
10540 "bla", "bla", NULL, NT_STATUS_OK);
10541 ret &= test_stream_name(
10542 "bla::$DATA", "bla", NULL, NT_STATUS_OK);
10543 ret &= test_stream_name(
10544 "bla:blub:", "bla", NULL, NT_STATUS_OBJECT_NAME_INVALID);
10545 ret &= test_stream_name(
10546 "bla::", NULL, NULL, NT_STATUS_OBJECT_NAME_INVALID);
10547 ret &= test_stream_name(
10548 "bla::123", "bla", NULL, NT_STATUS_OBJECT_NAME_INVALID);
10549 ret &= test_stream_name(
10550 "bla:$DATA", "bla", "$DATA:$DATA", NT_STATUS_OK);
10551 ret &= test_stream_name(
10552 "bla:x:$DATA", "bla", "x:$DATA", NT_STATUS_OK);
10553 ret &= test_stream_name(
10554 "bla:x", "bla", "x:$DATA", NT_STATUS_OK);
10559 static bool data_blob_equal(DATA_BLOB a, DATA_BLOB b)
10561 if (a.length != b.length) {
10562 printf("a.length=%d != b.length=%d\n",
10563 (int)a.length, (int)b.length);
10566 if (memcmp(a.data, b.data, a.length) != 0) {
10567 printf("a.data and b.data differ\n");
10573 static bool run_local_memcache(int dummy)
10575 struct memcache *cache;
10577 DATA_BLOB d1, d2, d3;
10578 DATA_BLOB v1, v2, v3;
10580 TALLOC_CTX *mem_ctx;
10582 size_t size1, size2;
10585 cache = memcache_init(NULL, sizeof(void *) == 8 ? 200 : 100);
10587 if (cache == NULL) {
10588 printf("memcache_init failed\n");
10592 d1 = data_blob_const("d1", 2);
10593 d2 = data_blob_const("d2", 2);
10594 d3 = data_blob_const("d3", 2);
10596 k1 = data_blob_const("d1", 2);
10597 k2 = data_blob_const("d2", 2);
10599 memcache_add(cache, STAT_CACHE, k1, d1);
10600 memcache_add(cache, GETWD_CACHE, k2, d2);
10602 if (!memcache_lookup(cache, STAT_CACHE, k1, &v1)) {
10603 printf("could not find k1\n");
10606 if (!data_blob_equal(d1, v1)) {
10610 if (!memcache_lookup(cache, GETWD_CACHE, k2, &v2)) {
10611 printf("could not find k2\n");
10614 if (!data_blob_equal(d2, v2)) {
10618 memcache_add(cache, STAT_CACHE, k1, d3);
10620 if (!memcache_lookup(cache, STAT_CACHE, k1, &v3)) {
10621 printf("could not find replaced k1\n");
10624 if (!data_blob_equal(d3, v3)) {
10628 memcache_add(cache, GETWD_CACHE, k1, d1);
10630 if (memcache_lookup(cache, GETWD_CACHE, k2, &v2)) {
10631 printf("Did find k2, should have been purged\n");
10635 TALLOC_FREE(cache);
10637 cache = memcache_init(NULL, 0);
10639 mem_ctx = talloc_init("foo");
10641 str1 = talloc_strdup(mem_ctx, "string1");
10642 str2 = talloc_strdup(mem_ctx, "string2");
10644 memcache_add_talloc(cache, SINGLETON_CACHE_TALLOC,
10645 data_blob_string_const("torture"), &str1);
10646 size1 = talloc_total_size(cache);
10648 memcache_add_talloc(cache, SINGLETON_CACHE_TALLOC,
10649 data_blob_string_const("torture"), &str2);
10650 size2 = talloc_total_size(cache);
10652 printf("size1=%d, size2=%d\n", (int)size1, (int)size2);
10654 if (size2 > size1) {
10655 printf("memcache leaks memory!\n");
10661 TALLOC_FREE(cache);
10665 static void wbclient_done(struct tevent_req *req)
10668 struct winbindd_response *wb_resp;
10669 int *i = (int *)tevent_req_callback_data_void(req);
10671 wbc_err = wb_trans_recv(req, req, &wb_resp);
10674 d_printf("wb_trans_recv %d returned %s\n", *i, wbcErrorString(wbc_err));
10677 static bool run_wbclient_multi_ping(int dummy)
10679 struct tevent_context *ev;
10680 struct wb_context **wb_ctx;
10681 struct winbindd_request wb_req;
10682 bool result = false;
10685 BlockSignals(True, SIGPIPE);
10687 ev = tevent_context_init(talloc_tos());
10692 wb_ctx = talloc_array(ev, struct wb_context *, torture_nprocs);
10693 if (wb_ctx == NULL) {
10697 ZERO_STRUCT(wb_req);
10698 wb_req.cmd = WINBINDD_PING;
10700 d_printf("torture_nprocs=%d, numops=%d\n", (int)torture_nprocs, (int)torture_numops);
10702 for (i=0; i<torture_nprocs; i++) {
10703 wb_ctx[i] = wb_context_init(ev, NULL);
10704 if (wb_ctx[i] == NULL) {
10707 for (j=0; j<torture_numops; j++) {
10708 struct tevent_req *req;
10709 req = wb_trans_send(ev, ev, wb_ctx[i],
10710 (j % 2) == 0, &wb_req);
10714 tevent_req_set_callback(req, wbclient_done, &i);
10720 while (i < torture_nprocs * torture_numops) {
10721 tevent_loop_once(ev);
10730 static void getaddrinfo_finished(struct tevent_req *req)
10732 char *name = (char *)tevent_req_callback_data_void(req);
10733 struct addrinfo *ainfo;
10736 res = getaddrinfo_recv(req, &ainfo);
10738 d_printf("gai(%s) returned %s\n", name, gai_strerror(res));
10741 d_printf("gai(%s) succeeded\n", name);
10742 freeaddrinfo(ainfo);
10745 static bool run_getaddrinfo_send(int dummy)
10747 TALLOC_CTX *frame = talloc_stackframe();
10748 struct fncall_context *ctx;
10749 struct tevent_context *ev;
10750 bool result = false;
10751 const char *names[4] = { "www.samba.org", "notfound.samba.org",
10752 "www.slashdot.org", "heise.de" };
10753 struct tevent_req *reqs[4];
10756 ev = samba_tevent_context_init(frame);
10761 ctx = fncall_context_init(frame, 4);
10763 for (i=0; i<ARRAY_SIZE(names); i++) {
10764 reqs[i] = getaddrinfo_send(frame, ev, ctx, names[i], NULL,
10766 if (reqs[i] == NULL) {
10769 tevent_req_set_callback(reqs[i], getaddrinfo_finished,
10770 discard_const_p(void, names[i]));
10773 for (i=0; i<ARRAY_SIZE(reqs); i++) {
10774 tevent_loop_once(ev);
10779 TALLOC_FREE(frame);
10783 static bool dbtrans_inc(struct db_context *db)
10785 struct db_record *rec;
10791 rec = dbwrap_fetch_locked(db, db, string_term_tdb_data("transtest"));
10793 printf(__location__ "fetch_lock failed\n");
10797 value = dbwrap_record_get_value(rec);
10799 if (value.dsize != sizeof(uint32_t)) {
10800 printf(__location__ "value.dsize = %d\n",
10805 memcpy(&val, value.dptr, sizeof(val));
10808 status = dbwrap_record_store(
10809 rec, make_tdb_data((uint8_t *)&val, sizeof(val)), 0);
10810 if (!NT_STATUS_IS_OK(status)) {
10811 printf(__location__ "store failed: %s\n",
10812 nt_errstr(status));
10822 static bool run_local_dbtrans(int dummy)
10824 struct db_context *db;
10825 struct db_record *rec;
10831 db = db_open(talloc_tos(), "transtest.tdb", 0, TDB_DEFAULT,
10832 O_RDWR|O_CREAT, 0600, DBWRAP_LOCK_ORDER_1,
10835 printf("Could not open transtest.db\n");
10839 res = dbwrap_transaction_start(db);
10841 printf(__location__ "transaction_start failed\n");
10845 rec = dbwrap_fetch_locked(db, db, string_term_tdb_data("transtest"));
10847 printf(__location__ "fetch_lock failed\n");
10851 value = dbwrap_record_get_value(rec);
10853 if (value.dptr == NULL) {
10855 status = dbwrap_record_store(
10856 rec, make_tdb_data((uint8_t *)&initial,
10859 if (!NT_STATUS_IS_OK(status)) {
10860 printf(__location__ "store returned %s\n",
10861 nt_errstr(status));
10868 res = dbwrap_transaction_commit(db);
10870 printf(__location__ "transaction_commit failed\n");
10875 uint32_t val, val2;
10878 res = dbwrap_transaction_start(db);
10880 printf(__location__ "transaction_start failed\n");
10884 status = dbwrap_fetch_uint32_bystring(db, "transtest", &val);
10885 if (!NT_STATUS_IS_OK(status)) {
10886 printf(__location__ "dbwrap_fetch_uint32 failed: %s\n",
10887 nt_errstr(status));
10891 for (i=0; i<10; i++) {
10892 if (!dbtrans_inc(db)) {
10897 status = dbwrap_fetch_uint32_bystring(db, "transtest", &val2);
10898 if (!NT_STATUS_IS_OK(status)) {
10899 printf(__location__ "dbwrap_fetch_uint32 failed: %s\n",
10900 nt_errstr(status));
10904 if (val2 != val + 10) {
10905 printf(__location__ "val=%d, val2=%d\n",
10906 (int)val, (int)val2);
10910 printf("val2=%d\r", val2);
10912 res = dbwrap_transaction_commit(db);
10914 printf(__location__ "transaction_commit failed\n");
10924 * Just a dummy test to be run under a debugger. There's no real way
10925 * to inspect the tevent_select specific function from outside of
10929 static bool run_local_tevent_select(int dummy)
10931 struct tevent_context *ev;
10932 struct tevent_fd *fd1, *fd2;
10933 bool result = false;
10935 ev = tevent_context_init_byname(NULL, "select");
10937 d_fprintf(stderr, "tevent_context_init_byname failed\n");
10941 fd1 = tevent_add_fd(ev, ev, 2, 0, NULL, NULL);
10943 d_fprintf(stderr, "tevent_add_fd failed\n");
10946 fd2 = tevent_add_fd(ev, ev, 3, 0, NULL, NULL);
10948 d_fprintf(stderr, "tevent_add_fd failed\n");
10953 fd2 = tevent_add_fd(ev, ev, 1, 0, NULL, NULL);
10955 d_fprintf(stderr, "tevent_add_fd failed\n");
10965 static bool run_local_hex_encode_buf(int dummy)
10971 for (i=0; i<sizeof(src); i++) {
10974 hex_encode_buf(buf, src, sizeof(src));
10975 if (strcmp(buf, "0001020304050607") != 0) {
10978 hex_encode_buf(buf, NULL, 0);
10979 if (buf[0] != '\0') {
10985 static const char *remove_duplicate_addrs2_test_strings_vector[] = {
11007 "1001:1111:1111:1000:0:1111:1111:1111",
11016 static const char *remove_duplicate_addrs2_test_strings_result[] = {
11030 "1001:1111:1111:1000:0:1111:1111:1111"
11033 static bool run_local_remove_duplicate_addrs2(int dummy)
11035 struct ip_service test_vector[28];
11038 /* Construct the sockaddr_storage test vector. */
11039 for (i = 0; i < 28; i++) {
11040 struct addrinfo hints;
11041 struct addrinfo *res = NULL;
11044 memset(&hints, '\0', sizeof(hints));
11045 hints.ai_flags = AI_NUMERICHOST;
11046 ret = getaddrinfo(remove_duplicate_addrs2_test_strings_vector[i],
11051 fprintf(stderr, "getaddrinfo failed on [%s]\n",
11052 remove_duplicate_addrs2_test_strings_vector[i]);
11055 memset(&test_vector[i], '\0', sizeof(test_vector[i]));
11056 memcpy(&test_vector[i].ss,
11062 count = remove_duplicate_addrs2(test_vector, i);
11065 fprintf(stderr, "count wrong (%d) should be 14\n",
11070 for (i = 0; i < count; i++) {
11071 char addr[INET6_ADDRSTRLEN];
11073 print_sockaddr(addr, sizeof(addr), &test_vector[i].ss);
11075 if (strcmp(addr, remove_duplicate_addrs2_test_strings_result[i]) != 0) {
11076 fprintf(stderr, "mismatch on [%d] [%s] [%s]\n",
11079 remove_duplicate_addrs2_test_strings_result[i]);
11084 printf("run_local_remove_duplicate_addrs2: success\n");
11088 static bool run_local_tdb_opener(int dummy)
11094 t = tdb_open("test.tdb", 1000, TDB_CLEAR_IF_FIRST,
11095 O_RDWR|O_CREAT, 0755);
11097 perror("tdb_open failed");
11108 static bool run_local_tdb_writer(int dummy)
11114 t = tdb_open("test.tdb", 1000, 0, O_RDWR|O_CREAT, 0755);
11116 perror("tdb_open failed");
11120 val.dptr = (uint8_t *)&v;
11121 val.dsize = sizeof(v);
11127 ret = tdb_store(t, val, val, 0);
11129 printf("%s\n", tdb_errorstr(t));
11134 data = tdb_fetch(t, val);
11135 if (data.dptr != NULL) {
11136 SAFE_FREE(data.dptr);
11142 static bool run_local_canonicalize_path(int dummy)
11144 const char *src[] = {
11151 ".././././../../../boo",
11155 const char *dst[] = {
11168 for (i = 0; src[i] != NULL; i++) {
11169 char *d = canonicalize_absolute_path(talloc_tos(), src[i]);
11171 perror("talloc fail\n");
11174 if (strcmp(d, dst[i]) != 0) {
11176 "canonicalize missmatch %s -> %s != %s",
11177 src[i], d, dst[i]);
11185 static bool run_ign_bad_negprot(int dummy)
11187 struct tevent_context *ev;
11188 struct tevent_req *req;
11189 struct smbXcli_conn *conn;
11190 struct sockaddr_storage ss;
11195 printf("starting ignore bad negprot\n");
11197 ok = resolve_name(host, &ss, 0x20, true);
11199 d_fprintf(stderr, "Could not resolve name %s\n", host);
11203 status = open_socket_out(&ss, 445, 10000, &fd);
11204 if (!NT_STATUS_IS_OK(status)) {
11205 d_fprintf(stderr, "open_socket_out failed: %s\n",
11206 nt_errstr(status));
11210 conn = smbXcli_conn_create(talloc_tos(), fd, host, SMB_SIGNING_OFF, 0,
11212 if (conn == NULL) {
11213 d_fprintf(stderr, "smbXcli_conn_create failed\n");
11217 status = smbXcli_negprot(conn, 0, PROTOCOL_CORE, PROTOCOL_CORE);
11218 if (NT_STATUS_IS_OK(status)) {
11219 d_fprintf(stderr, "smbXcli_negprot succeeded!\n");
11223 ev = samba_tevent_context_init(talloc_tos());
11225 d_fprintf(stderr, "samba_tevent_context_init failed\n");
11229 req = smb1cli_session_setup_nt1_send(
11230 ev, ev, conn, 0, getpid(), NULL, 65503, 2, 1, 0, "", "",
11231 data_blob_null, data_blob_null, 0x40,
11232 "Windows 2000 2195", "Windows 2000 5.0");
11234 d_fprintf(stderr, "smb1cli_session_setup_nt1_send failed\n");
11238 ok = tevent_req_poll_ntstatus(req, ev, &status);
11240 d_fprintf(stderr, "tevent_req_poll failed\n");
11244 status = smb1cli_session_setup_nt1_recv(req, NULL, NULL, NULL, NULL,
11246 if (!NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_RESET)) {
11247 d_fprintf(stderr, "smb1cli_session_setup_nt1_recv returned "
11248 "%s, expected NT_STATUS_CONNECTION_RESET\n",
11249 nt_errstr(status));
11255 printf("starting ignore bad negprot\n");
11260 static double create_procs(bool (*fn)(int), bool *result)
11263 volatile pid_t *child_status;
11264 volatile bool *child_status_out;
11267 struct timeval start;
11271 child_status = (volatile pid_t *)anonymous_shared_allocate(sizeof(pid_t)*torture_nprocs);
11272 if (!child_status) {
11273 printf("Failed to setup shared memory\n");
11277 child_status_out = (volatile bool *)anonymous_shared_allocate(sizeof(bool)*torture_nprocs);
11278 if (!child_status_out) {
11279 printf("Failed to setup result status shared memory\n");
11283 for (i = 0; i < torture_nprocs; i++) {
11284 child_status[i] = 0;
11285 child_status_out[i] = True;
11288 start = timeval_current();
11290 for (i=0;i<torture_nprocs;i++) {
11293 pid_t mypid = getpid();
11294 sys_srandom(((int)mypid) ^ ((int)time(NULL)));
11296 slprintf(myname,sizeof(myname),"CLIENT%d", i);
11299 if (torture_open_connection(¤t_cli, i)) break;
11300 if (tries-- == 0) {
11301 printf("pid %d failed to start\n", (int)getpid());
11307 child_status[i] = getpid();
11309 while (child_status[i] && timeval_elapsed(&start) < 5) smb_msleep(2);
11311 child_status_out[i] = fn(i);
11318 for (i=0;i<torture_nprocs;i++) {
11319 if (child_status[i]) synccount++;
11321 if (synccount == torture_nprocs) break;
11323 } while (timeval_elapsed(&start) < 30);
11325 if (synccount != torture_nprocs) {
11326 printf("FAILED TO START %d CLIENTS (started %d)\n", torture_nprocs, synccount);
11328 return timeval_elapsed(&start);
11331 /* start the client load */
11332 start = timeval_current();
11334 for (i=0;i<torture_nprocs;i++) {
11335 child_status[i] = 0;
11338 printf("%d clients started\n", torture_nprocs);
11340 for (i=0;i<torture_nprocs;i++) {
11341 while (waitpid(0, &status, 0) == -1 && errno == EINTR) /* noop */ ;
11346 for (i=0;i<torture_nprocs;i++) {
11347 if (!child_status_out[i]) {
11351 return timeval_elapsed(&start);
11354 #define FLAG_MULTIPROC 1
11360 } torture_ops[] = {
11361 {"FDPASS", run_fdpasstest, 0},
11362 {"LOCK1", run_locktest1, 0},
11363 {"LOCK2", run_locktest2, 0},
11364 {"LOCK3", run_locktest3, 0},
11365 {"LOCK4", run_locktest4, 0},
11366 {"LOCK5", run_locktest5, 0},
11367 {"LOCK6", run_locktest6, 0},
11368 {"LOCK7", run_locktest7, 0},
11369 {"LOCK8", run_locktest8, 0},
11370 {"LOCK9", run_locktest9, 0},
11371 {"UNLINK", run_unlinktest, 0},
11372 {"BROWSE", run_browsetest, 0},
11373 {"ATTR", run_attrtest, 0},
11374 {"TRANS2", run_trans2test, 0},
11375 {"MAXFID", run_maxfidtest, FLAG_MULTIPROC},
11376 {"TORTURE",run_torture, FLAG_MULTIPROC},
11377 {"RANDOMIPC", run_randomipc, 0},
11378 {"NEGNOWAIT", run_negprot_nowait, 0},
11379 {"NBENCH", run_nbench, 0},
11380 {"NBENCH2", run_nbench2, 0},
11381 {"OPLOCK1", run_oplock1, 0},
11382 {"OPLOCK2", run_oplock2, 0},
11383 {"OPLOCK4", run_oplock4, 0},
11384 {"DIR", run_dirtest, 0},
11385 {"DIR1", run_dirtest1, 0},
11386 {"DIR-CREATETIME", run_dir_createtime, 0},
11387 {"DENY1", torture_denytest1, 0},
11388 {"DENY2", torture_denytest2, 0},
11389 {"TCON", run_tcon_test, 0},
11390 {"TCONDEV", run_tcon_devtype_test, 0},
11391 {"RW1", run_readwritetest, 0},
11392 {"RW2", run_readwritemulti, FLAG_MULTIPROC},
11393 {"RW3", run_readwritelarge, 0},
11394 {"RW-SIGNING", run_readwritelarge_signtest, 0},
11395 {"OPEN", run_opentest, 0},
11396 {"POSIX", run_simple_posix_open_test, 0},
11397 {"POSIX-APPEND", run_posix_append, 0},
11398 {"POSIX-SYMLINK-ACL", run_acl_symlink_test, 0},
11399 {"POSIX-SYMLINK-EA", run_ea_symlink_test, 0},
11400 {"POSIX-STREAM-DELETE", run_posix_stream_delete, 0},
11401 {"POSIX-OFD-LOCK", run_posix_ofd_lock_test, 0},
11402 {"WINDOWS-BAD-SYMLINK", run_symlink_open_test, 0},
11403 {"CASE-INSENSITIVE-CREATE", run_case_insensitive_create, 0},
11404 {"ASYNC-ECHO", run_async_echo, 0},
11405 { "UID-REGRESSION-TEST", run_uid_regression_test, 0},
11406 { "SHORTNAME-TEST", run_shortname_test, 0},
11407 { "ADDRCHANGE", run_addrchange, 0},
11409 {"OPENATTR", run_openattrtest, 0},
11411 {"XCOPY", run_xcopy, 0},
11412 {"RENAME", run_rename, 0},
11413 {"RENAME-ACCESS", run_rename_access, 0},
11414 {"OWNER-RIGHTS", run_owner_rights, 0},
11415 {"DELETE", run_deletetest, 0},
11416 {"WILDDELETE", run_wild_deletetest, 0},
11417 {"DELETE-LN", run_deletetest_ln, 0},
11418 {"PROPERTIES", run_properties, 0},
11419 {"MANGLE", torture_mangle, 0},
11420 {"MANGLE1", run_mangle1, 0},
11421 {"MANGLE-ILLEGAL", run_mangle_illegal, 0},
11422 {"W2K", run_w2ktest, 0},
11423 {"TRANS2SCAN", torture_trans2_scan, 0},
11424 {"NTTRANSSCAN", torture_nttrans_scan, 0},
11425 {"UTABLE", torture_utable, 0},
11426 {"CASETABLE", torture_casetable, 0},
11427 {"ERRMAPEXTRACT", run_error_map_extract, 0},
11428 {"PIPE_NUMBER", run_pipe_number, 0},
11429 {"TCON2", run_tcon2_test, 0},
11430 {"IOCTL", torture_ioctl_test, 0},
11431 {"CHKPATH", torture_chkpath_test, 0},
11432 {"FDSESS", run_fdsesstest, 0},
11433 { "EATEST", run_eatest, 0},
11434 { "SESSSETUP_BENCH", run_sesssetup_bench, 0},
11435 { "CHAIN1", run_chain1, 0},
11436 { "CHAIN2", run_chain2, 0},
11437 { "CHAIN3", run_chain3, 0},
11438 { "WINDOWS-WRITE", run_windows_write, 0},
11439 { "LARGE_READX", run_large_readx, 0},
11440 { "NTTRANS-CREATE", run_nttrans_create, 0},
11441 { "NTTRANS-FSCTL", run_nttrans_fsctl, 0},
11442 { "CLI_ECHO", run_cli_echo, 0},
11443 { "GETADDRINFO", run_getaddrinfo_send, 0},
11444 { "TLDAP", run_tldap },
11445 { "STREAMERROR", run_streamerror },
11446 { "NOTIFY-BENCH", run_notify_bench },
11447 { "NOTIFY-BENCH2", run_notify_bench2 },
11448 { "NOTIFY-BENCH3", run_notify_bench3 },
11449 { "BAD-NBT-SESSION", run_bad_nbt_session },
11450 { "IGN-BAD-NEGPROT", run_ign_bad_negprot },
11451 { "SMB-ANY-CONNECT", run_smb_any_connect },
11452 { "NOTIFY-ONLINE", run_notify_online },
11453 { "SMB2-BASIC", run_smb2_basic },
11454 { "SMB2-NEGPROT", run_smb2_negprot },
11455 { "SMB2-SESSION-RECONNECT", run_smb2_session_reconnect },
11456 { "SMB2-TCON-DEPENDENCE", run_smb2_tcon_dependence },
11457 { "SMB2-MULTI-CHANNEL", run_smb2_multi_channel },
11458 { "SMB2-SESSION-REAUTH", run_smb2_session_reauth },
11459 { "SMB2-FTRUNCATE", run_smb2_ftruncate },
11460 { "CLEANUP1", run_cleanup1 },
11461 { "CLEANUP2", run_cleanup2 },
11462 { "CLEANUP3", run_cleanup3 },
11463 { "CLEANUP4", run_cleanup4 },
11464 { "OPLOCK-CANCEL", run_oplock_cancel },
11465 { "PIDHIGH", run_pidhigh },
11466 { "LOCAL-SUBSTITUTE", run_local_substitute, 0},
11467 { "LOCAL-GENCACHE", run_local_gencache, 0},
11468 { "LOCAL-TALLOC-DICT", run_local_talloc_dict, 0},
11469 { "LOCAL-DBWRAP-WATCH1", run_dbwrap_watch1, 0 },
11470 { "LOCAL-DBWRAP-WATCH2", run_dbwrap_watch2, 0 },
11471 { "LOCAL-MESSAGING-READ1", run_messaging_read1, 0 },
11472 { "LOCAL-MESSAGING-READ2", run_messaging_read2, 0 },
11473 { "LOCAL-MESSAGING-READ3", run_messaging_read3, 0 },
11474 { "LOCAL-MESSAGING-READ4", run_messaging_read4, 0 },
11475 { "LOCAL-MESSAGING-FDPASS1", run_messaging_fdpass1, 0 },
11476 { "LOCAL-MESSAGING-FDPASS2", run_messaging_fdpass2, 0 },
11477 { "LOCAL-MESSAGING-FDPASS2a", run_messaging_fdpass2a, 0 },
11478 { "LOCAL-MESSAGING-FDPASS2b", run_messaging_fdpass2b, 0 },
11479 { "LOCAL-BASE64", run_local_base64, 0},
11480 { "LOCAL-RBTREE", run_local_rbtree, 0},
11481 { "LOCAL-MEMCACHE", run_local_memcache, 0},
11482 { "LOCAL-STREAM-NAME", run_local_stream_name, 0},
11483 { "WBCLIENT-MULTI-PING", run_wbclient_multi_ping, 0},
11484 { "LOCAL-string_to_sid", run_local_string_to_sid, 0},
11485 { "LOCAL-sid_to_string", run_local_sid_to_string, 0},
11486 { "LOCAL-binary_to_sid", run_local_binary_to_sid, 0},
11487 { "LOCAL-DBTRANS", run_local_dbtrans, 0},
11488 { "LOCAL-TEVENT-SELECT", run_local_tevent_select, 0},
11489 { "LOCAL-CONVERT-STRING", run_local_convert_string, 0},
11490 { "LOCAL-CONV-AUTH-INFO", run_local_conv_auth_info, 0},
11491 { "LOCAL-hex_encode_buf", run_local_hex_encode_buf, 0},
11492 { "LOCAL-IDMAP-TDB-COMMON", run_idmap_tdb_common_test, 0},
11493 { "LOCAL-remove_duplicate_addrs2", run_local_remove_duplicate_addrs2, 0},
11494 { "local-tdb-opener", run_local_tdb_opener, 0 },
11495 { "local-tdb-writer", run_local_tdb_writer, 0 },
11496 { "LOCAL-DBWRAP-CTDB", run_local_dbwrap_ctdb, 0 },
11497 { "LOCAL-BENCH-PTHREADPOOL", run_bench_pthreadpool, 0 },
11498 { "LOCAL-PTHREADPOOL-TEVENT", run_pthreadpool_tevent, 0 },
11499 { "LOCAL-G-LOCK1", run_g_lock1, 0 },
11500 { "LOCAL-G-LOCK2", run_g_lock2, 0 },
11501 { "LOCAL-G-LOCK3", run_g_lock3, 0 },
11502 { "LOCAL-G-LOCK4", run_g_lock4, 0 },
11503 { "LOCAL-G-LOCK5", run_g_lock5, 0 },
11504 { "LOCAL-CANONICALIZE-PATH", run_local_canonicalize_path, 0 },
11505 { "qpathinfo-bufsize", run_qpathinfo_bufsize, 0 },
11509 * dummy function to satisfy linker dependency
11511 struct tevent_context *winbind_event_context(void);
11512 struct tevent_context *winbind_event_context(void)
11517 /****************************************************************************
11518 run a specified test or "ALL"
11519 ****************************************************************************/
11520 static bool run_test(const char *name)
11523 bool result = True;
11524 bool found = False;
11527 if (strequal(name,"ALL")) {
11528 for (i=0;torture_ops[i].name;i++) {
11529 run_test(torture_ops[i].name);
11534 for (i=0;torture_ops[i].name;i++) {
11535 fstr_sprintf(randomfname, "\\XX%x",
11536 (unsigned)random());
11538 if (strequal(name, torture_ops[i].name)) {
11540 printf("Running %s\n", name);
11541 if (torture_ops[i].flags & FLAG_MULTIPROC) {
11542 t = create_procs(torture_ops[i].fn, &result);
11545 printf("TEST %s FAILED!\n", name);
11548 struct timeval start;
11549 start = timeval_current();
11550 if (!torture_ops[i].fn(0)) {
11552 printf("TEST %s FAILED!\n", name);
11554 t = timeval_elapsed(&start);
11556 printf("%s took %g secs\n\n", name, t);
11561 printf("Did not find a test named %s\n", name);
11569 static void usage(void)
11573 printf("WARNING samba4 test suite is much more complete nowadays.\n");
11574 printf("Please use samba4 torture.\n\n");
11576 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
11578 printf("\t-d debuglevel\n");
11579 printf("\t-U user%%pass\n");
11580 printf("\t-k use kerberos\n");
11581 printf("\t-N numprocs\n");
11582 printf("\t-n my_netbios_name\n");
11583 printf("\t-W workgroup\n");
11584 printf("\t-o num_operations\n");
11585 printf("\t-O socket_options\n");
11586 printf("\t-m maximum protocol\n");
11587 printf("\t-L use oplocks\n");
11588 printf("\t-c CLIENT.TXT specify client load file for NBENCH\n");
11589 printf("\t-A showall\n");
11590 printf("\t-p port\n");
11591 printf("\t-s seed\n");
11592 printf("\t-b unclist_filename specify multiple shares for multiple connections\n");
11593 printf("\t-f filename filename to test\n");
11594 printf("\t-e encrypt\n");
11597 printf("tests are:");
11598 for (i=0;torture_ops[i].name;i++) {
11599 printf(" %s", torture_ops[i].name);
11603 printf("default test is ALL\n");
11608 /****************************************************************************
11610 ****************************************************************************/
11611 int main(int argc,char *argv[])
11617 bool correct = True;
11618 TALLOC_CTX *frame = talloc_stackframe();
11619 int seed = time(NULL);
11621 #ifdef HAVE_SETBUFFER
11622 setbuffer(stdout, NULL, 0);
11625 setup_logging("smbtorture", DEBUG_STDOUT);
11630 if (is_default_dyn_CONFIGFILE()) {
11631 if(getenv("SMB_CONF_PATH")) {
11632 set_dyn_CONFIGFILE(getenv("SMB_CONF_PATH"));
11635 lp_load_global(get_dyn_CONFIGFILE());
11642 for(p = argv[1]; *p; p++)
11646 if (strncmp(argv[1], "//", 2)) {
11650 fstrcpy(host, &argv[1][2]);
11651 p = strchr_m(&host[2],'/');
11656 fstrcpy(share, p+1);
11658 fstrcpy(myname, get_myname(talloc_tos()));
11660 fprintf(stderr, "Failed to get my hostname.\n");
11664 if (*username == 0 && getenv("LOGNAME")) {
11665 fstrcpy(username,getenv("LOGNAME"));
11671 fstrcpy(workgroup, lp_workgroup());
11673 while ((opt = getopt(argc, argv, "p:hW:U:n:N:O:o:m:Ll:d:Aec:ks:b:B:f:"))
11677 port_to_use = atoi(optarg);
11680 seed = atoi(optarg);
11683 fstrcpy(workgroup,optarg);
11686 lp_set_cmdline("client max protocol", optarg);
11689 torture_nprocs = atoi(optarg);
11692 torture_numops = atoi(optarg);
11695 lp_set_cmdline("log level", optarg);
11701 use_oplocks = True;
11704 local_path = optarg;
11707 torture_showall = True;
11710 fstrcpy(myname, optarg);
11713 client_txt = optarg;
11720 use_kerberos = True;
11722 d_printf("No kerberos support compiled in\n");
11728 fstrcpy(username,optarg);
11729 p = strchr_m(username,'%');
11732 fstrcpy(password, p+1);
11737 fstrcpy(multishare_conn_fname, optarg);
11738 use_multishare_conn = True;
11741 torture_blocksize = atoi(optarg);
11744 test_filename = SMB_STRDUP(optarg);
11747 printf("Unknown option %c (%d)\n", (char)opt, opt);
11752 d_printf("using seed %d\n", seed);
11756 if(use_kerberos && !gotuser) gotpass = True;
11759 char pwd[256] = {0};
11762 rc = samba_getpass("Password:", pwd, sizeof(pwd), false, false);
11764 fstrcpy(password, pwd);
11769 printf("host=%s share=%s user=%s myname=%s\n",
11770 host, share, username, myname);
11772 torture_creds = cli_session_creds_init(frame,
11778 false, /* fallback_after_kerberos */
11779 false, /* use_ccache */
11780 false); /* password_is_nt_hash */
11781 if (torture_creds == NULL) {
11782 d_printf("cli_session_creds_init() failed.\n");
11786 if (argc == optind) {
11787 correct = run_test("ALL");
11789 for (i=optind;i<argc;i++) {
11790 if (!run_test(argv[i])) {
11796 TALLOC_FREE(frame);