2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1997-1998
5 Copyright (C) Jeremy Allison 2009
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "system/shmem.h"
23 #include "wbc_async.h"
24 #include "torture/proto.h"
25 #include "libcli/security/security.h"
27 #include "tldap_util.h"
28 #include "../librpc/gen_ndr/svcctl.h"
30 #include "nsswitch/winbind_client.h"
31 #include "dbwrap/dbwrap.h"
32 #include "dbwrap/dbwrap_open.h"
33 #include "talloc_dict.h"
34 #include "async_smb.h"
35 #include "libsmb/libsmb.h"
36 #include "libsmb/clirap.h"
38 #include "libsmb/nmblib.h"
39 #include "../lib/util/tevent_ntstatus.h"
41 #include "libsmb/read_smb.h"
46 fstring host, workgroup, share, password, username, myname;
47 static int max_protocol = PROTOCOL_NT1;
48 static const char *sockops="TCP_NODELAY";
50 static int port_to_use=0;
51 int torture_numops=100;
52 int torture_blocksize=1024*1024;
53 static int procnum; /* records process count number when forking */
54 static struct cli_state *current_cli;
55 static fstring randomfname;
56 static bool use_oplocks;
57 static bool use_level_II_oplocks;
58 static const char *client_txt = "client_oplocks.txt";
59 static bool disable_spnego;
60 static bool use_kerberos;
61 static bool force_dos_errors;
62 static fstring multishare_conn_fname;
63 static bool use_multishare_conn = False;
64 static bool do_encrypt;
65 static const char *local_path = NULL;
66 static int signing_state = Undefined;
69 bool torture_showall = False;
71 static double create_procs(bool (*fn)(int), bool *result);
74 /* return a pointer to a anonymous shared memory segment of size "size"
75 which will persist across fork() but will disappear when all processes
78 The memory is not zeroed
80 This function uses system5 shared memory. It takes advantage of a property
81 that the memory is not destroyed if it is attached when the id is removed
83 void *shm_setup(int size)
89 shmid = shm_open("private", O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
91 printf("can't get shared memory\n");
94 shm_unlink("private");
95 if (ftruncate(shmid, size) == -1) {
96 printf("can't set shared memory size\n");
99 ret = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, shmid, 0);
100 if (ret == MAP_FAILED) {
101 printf("can't map shared memory\n");
105 shmid = shmget(IPC_PRIVATE, size, S_IRUSR | S_IWUSR);
107 printf("can't get shared memory\n");
110 ret = (void *)shmat(shmid, 0, 0);
111 if (!ret || ret == (void *)-1) {
112 printf("can't attach to shared memory\n");
115 /* the following releases the ipc, but note that this process
116 and all its children will still have access to the memory, its
117 just that the shmid is no longer valid for other shm calls. This
118 means we don't leave behind lots of shm segments after we exit
120 See Stevens "advanced programming in unix env" for details
122 shmctl(shmid, IPC_RMID, 0);
128 /********************************************************************
129 Ensure a connection is encrypted.
130 ********************************************************************/
132 static bool force_cli_encryption(struct cli_state *c,
133 const char *sharename)
136 uint32 caplow, caphigh;
139 if (!SERVER_HAS_UNIX_CIFS(c)) {
140 d_printf("Encryption required and "
141 "server that doesn't support "
142 "UNIX extensions - failing connect\n");
146 status = cli_unix_extensions_version(c, &major, &minor, &caplow,
148 if (!NT_STATUS_IS_OK(status)) {
149 d_printf("Encryption required and "
150 "can't get UNIX CIFS extensions "
151 "version from server: %s\n", nt_errstr(status));
155 if (!(caplow & CIFS_UNIX_TRANSPORT_ENCRYPTION_CAP)) {
156 d_printf("Encryption required and "
157 "share %s doesn't support "
158 "encryption.\n", sharename);
162 if (c->use_kerberos) {
163 status = cli_gss_smb_encryption_start(c);
165 status = cli_raw_ntlm_smb_encryption_start(c,
171 if (!NT_STATUS_IS_OK(status)) {
172 d_printf("Encryption required and "
173 "setup failed with error %s.\n",
182 static struct cli_state *open_nbt_connection(void)
188 if (disable_spnego) {
189 flags |= CLI_FULL_CONNECTION_DONT_SPNEGO;
193 flags |= CLI_FULL_CONNECTION_OPLOCKS;
196 if (use_level_II_oplocks) {
197 flags |= CLI_FULL_CONNECTION_LEVEL_II_OPLOCKS;
201 flags |= CLI_FULL_CONNECTION_USE_KERBEROS;
204 if (force_dos_errors) {
205 flags |= CLI_FULL_CONNECTION_FORCE_DOS_ERRORS;
208 status = cli_connect_nb(host, NULL, port_to_use, 0x20, myname,
209 signing_state, flags, &c);
210 if (!NT_STATUS_IS_OK(status)) {
211 printf("Failed to connect with %s. Error %s\n", host, nt_errstr(status) );
215 cli_set_timeout(c, 120000); /* set a really long timeout (2 minutes) */
220 /****************************************************************************
221 Send a corrupt session request. See rfc1002.txt 4.3 and 4.3.2.
222 ****************************************************************************/
224 static bool cli_bad_session_request(int fd,
225 struct nmb_name *calling, struct nmb_name *called)
234 uint8_t message_type;
237 frame = talloc_stackframe();
239 iov[0].iov_base = len_buf;
240 iov[0].iov_len = sizeof(len_buf);
242 /* put in the destination name */
244 iov[1].iov_base = name_mangle(talloc_tos(), called->name,
246 if (iov[1].iov_base == NULL) {
249 iov[1].iov_len = name_len((unsigned char *)iov[1].iov_base,
250 talloc_get_size(iov[1].iov_base));
254 iov[2].iov_base = name_mangle(talloc_tos(), calling->name,
256 if (iov[2].iov_base == NULL) {
259 iov[2].iov_len = name_len((unsigned char *)iov[2].iov_base,
260 talloc_get_size(iov[2].iov_base));
262 /* Deliberately corrupt the name len (first byte) */
263 *((uint8_t *)iov[2].iov_base) = 100;
265 /* send a session request (RFC 1002) */
266 /* setup the packet length
267 * Remove four bytes from the length count, since the length
268 * field in the NBT Session Service header counts the number
269 * of bytes which follow. The cli_send_smb() function knows
270 * about this and accounts for those four bytes.
274 _smb_setlen(len_buf, iov[1].iov_len + iov[2].iov_len);
275 SCVAL(len_buf,0,0x81);
277 len = write_data_iov(fd, iov, 3);
281 len = read_smb(fd, talloc_tos(), &inbuf, &err);
287 message_type = CVAL(inbuf, 0);
288 if (message_type != 0x83) {
289 d_fprintf(stderr, "Expected msg type 0x83, got 0x%2.2x\n",
294 if (smb_len(inbuf) != 1) {
295 d_fprintf(stderr, "Expected smb_len 1, got %d\n",
296 (int)smb_len(inbuf));
300 error = CVAL(inbuf, 4);
302 d_fprintf(stderr, "Expected error 0x82, got %d\n",
313 /* Insert a NULL at the first separator of the given path and return a pointer
314 * to the remainder of the string.
317 terminate_path_at_separator(char * path)
325 if ((p = strchr_m(path, '/'))) {
330 if ((p = strchr_m(path, '\\'))) {
340 parse a //server/share type UNC name
342 bool smbcli_parse_unc(const char *unc_name, TALLOC_CTX *mem_ctx,
343 char **hostname, char **sharename)
347 *hostname = *sharename = NULL;
349 if (strncmp(unc_name, "\\\\", 2) &&
350 strncmp(unc_name, "//", 2)) {
354 *hostname = talloc_strdup(mem_ctx, &unc_name[2]);
355 p = terminate_path_at_separator(*hostname);
358 *sharename = talloc_strdup(mem_ctx, p);
359 terminate_path_at_separator(*sharename);
362 if (*hostname && *sharename) {
366 TALLOC_FREE(*hostname);
367 TALLOC_FREE(*sharename);
371 static bool torture_open_connection_share(struct cli_state **c,
372 const char *hostname,
373 const char *sharename)
379 flags |= CLI_FULL_CONNECTION_USE_KERBEROS;
381 flags |= CLI_FULL_CONNECTION_OPLOCKS;
382 if (use_level_II_oplocks)
383 flags |= CLI_FULL_CONNECTION_LEVEL_II_OPLOCKS;
385 status = cli_full_connection(c, myname,
386 hostname, NULL, port_to_use,
389 password, flags, signing_state);
390 if (!NT_STATUS_IS_OK(status)) {
391 printf("failed to open share connection: //%s/%s port:%d - %s\n",
392 hostname, sharename, port_to_use, nt_errstr(status));
396 cli_set_timeout(*c, 120000); /* set a really long timeout (2 minutes) */
399 return force_cli_encryption(*c,
405 bool torture_open_connection(struct cli_state **c, int conn_index)
407 char **unc_list = NULL;
408 int num_unc_names = 0;
411 if (use_multishare_conn==True) {
413 unc_list = file_lines_load(multishare_conn_fname, &num_unc_names, 0, NULL);
414 if (!unc_list || num_unc_names <= 0) {
415 printf("Failed to load unc names list from '%s'\n", multishare_conn_fname);
419 if (!smbcli_parse_unc(unc_list[conn_index % num_unc_names],
421 printf("Failed to parse UNC name %s\n",
422 unc_list[conn_index % num_unc_names]);
423 TALLOC_FREE(unc_list);
427 result = torture_open_connection_share(c, h, s);
429 /* h, s were copied earlier */
430 TALLOC_FREE(unc_list);
434 return torture_open_connection_share(c, host, share);
437 bool torture_init_connection(struct cli_state **pcli)
439 struct cli_state *cli;
441 cli = open_nbt_connection();
450 bool torture_cli_session_setup2(struct cli_state *cli, uint16 *new_vuid)
452 uint16_t old_vuid = cli_state_get_uid(cli);
453 fstring old_user_name;
454 size_t passlen = strlen(password);
458 fstrcpy(old_user_name, cli->user_name);
459 cli_state_set_uid(cli, 0);
460 ret = NT_STATUS_IS_OK(cli_session_setup(cli, username,
464 *new_vuid = cli_state_get_uid(cli);
465 cli_state_set_uid(cli, old_vuid);
466 status = cli_set_username(cli, old_user_name);
467 if (!NT_STATUS_IS_OK(status)) {
474 bool torture_close_connection(struct cli_state *c)
479 status = cli_tdis(c);
480 if (!NT_STATUS_IS_OK(status)) {
481 printf("tdis failed (%s)\n", nt_errstr(status));
491 /* check if the server produced the expected dos or nt error code */
492 static bool check_both_error(int line, NTSTATUS status,
493 uint8 eclass, uint32 ecode, NTSTATUS nterr)
495 if (NT_STATUS_IS_DOS(status)) {
499 /* Check DOS error */
500 cclass = NT_STATUS_DOS_CLASS(status);
501 num = NT_STATUS_DOS_CODE(status);
503 if (eclass != cclass || ecode != num) {
504 printf("unexpected error code class=%d code=%d\n",
505 (int)cclass, (int)num);
506 printf(" expected %d/%d %s (line=%d)\n",
507 (int)eclass, (int)ecode, nt_errstr(nterr), line);
512 if (!NT_STATUS_EQUAL(nterr, status)) {
513 printf("unexpected error code %s\n",
515 printf(" expected %s (line=%d)\n",
516 nt_errstr(nterr), line);
525 /* check if the server produced the expected error code */
526 static bool check_error(int line, NTSTATUS status,
527 uint8 eclass, uint32 ecode, NTSTATUS nterr)
529 if (NT_STATUS_IS_DOS(status)) {
533 /* Check DOS error */
535 cclass = NT_STATUS_DOS_CLASS(status);
536 num = NT_STATUS_DOS_CODE(status);
538 if (eclass != cclass || ecode != num) {
539 printf("unexpected error code class=%d code=%d\n",
540 (int)cclass, (int)num);
541 printf(" expected %d/%d %s (line=%d)\n",
542 (int)eclass, (int)ecode, nt_errstr(nterr),
550 if (NT_STATUS_V(nterr) != NT_STATUS_V(status)) {
551 printf("unexpected error code %s\n",
553 printf(" expected %s (line=%d)\n", nt_errstr(nterr),
563 static bool wait_lock(struct cli_state *c, int fnum, uint32 offset, uint32 len)
567 status = cli_lock32(c, fnum, offset, len, -1, WRITE_LOCK);
569 while (!NT_STATUS_IS_OK(status)) {
570 if (!check_both_error(__LINE__, status, ERRDOS,
571 ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) {
575 status = cli_lock32(c, fnum, offset, len, -1, WRITE_LOCK);
582 static bool rw_torture(struct cli_state *c)
584 const char *lockfname = "\\torture.lck";
588 pid_t pid2, pid = getpid();
595 memset(buf, '\0', sizeof(buf));
597 status = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
599 if (!NT_STATUS_IS_OK(status)) {
600 status = cli_open(c, lockfname, O_RDWR, DENY_NONE, &fnum2);
602 if (!NT_STATUS_IS_OK(status)) {
603 printf("open of %s failed (%s)\n",
604 lockfname, nt_errstr(status));
608 for (i=0;i<torture_numops;i++) {
609 unsigned n = (unsigned)sys_random()%10;
612 printf("%d\r", i); fflush(stdout);
614 slprintf(fname, sizeof(fstring) - 1, "\\torture.%u", n);
616 if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) {
620 status = cli_open(c, fname, O_RDWR | O_CREAT | O_TRUNC,
622 if (!NT_STATUS_IS_OK(status)) {
623 printf("open failed (%s)\n", nt_errstr(status));
628 status = cli_writeall(c, fnum, 0, (uint8_t *)&pid, 0,
630 if (!NT_STATUS_IS_OK(status)) {
631 printf("write failed (%s)\n", nt_errstr(status));
636 status = cli_writeall(c, fnum, 0, (uint8_t *)buf,
637 sizeof(pid)+(j*sizeof(buf)),
639 if (!NT_STATUS_IS_OK(status)) {
640 printf("write failed (%s)\n",
648 status = cli_read(c, fnum, (char *)&pid2, 0, sizeof(pid),
650 if (!NT_STATUS_IS_OK(status)) {
651 printf("read failed (%s)\n", nt_errstr(status));
653 } else if (nread != sizeof(pid)) {
654 printf("read/write compare failed: "
655 "recv %ld req %ld\n", (unsigned long)nread,
656 (unsigned long)sizeof(pid));
661 printf("data corruption!\n");
665 status = cli_close(c, fnum);
666 if (!NT_STATUS_IS_OK(status)) {
667 printf("close failed (%s)\n", nt_errstr(status));
671 status = cli_unlink(c, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
672 if (!NT_STATUS_IS_OK(status)) {
673 printf("unlink failed (%s)\n", nt_errstr(status));
677 status = cli_unlock(c, fnum2, n*sizeof(int), sizeof(int));
678 if (!NT_STATUS_IS_OK(status)) {
679 printf("unlock failed (%s)\n", nt_errstr(status));
685 cli_unlink(c, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
692 static bool run_torture(int dummy)
694 struct cli_state *cli;
699 cli_sockopt(cli, sockops);
701 ret = rw_torture(cli);
703 if (!torture_close_connection(cli)) {
710 static bool rw_torture3(struct cli_state *c, char *lockfname)
712 uint16_t fnum = (uint16_t)-1;
717 unsigned countprev = 0;
720 NTSTATUS status = NT_STATUS_OK;
723 for (i = 0; i < sizeof(buf); i += sizeof(uint32))
725 SIVAL(buf, i, sys_random());
732 FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
733 if (!NT_STATUS_IS_OK(status)) {
734 printf("unlink failed (%s) (normal, this file should "
735 "not exist)\n", nt_errstr(status));
738 status = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
740 if (!NT_STATUS_IS_OK(status)) {
741 printf("first open read/write of %s failed (%s)\n",
742 lockfname, nt_errstr(status));
748 for (i = 0; i < 500 && fnum == (uint16_t)-1; i++)
750 status = cli_open(c, lockfname, O_RDONLY,
752 if (!NT_STATUS_IS_OK(status)) {
757 if (!NT_STATUS_IS_OK(status)) {
758 printf("second open read-only of %s failed (%s)\n",
759 lockfname, nt_errstr(status));
765 for (count = 0; count < sizeof(buf); count += sent)
767 if (count >= countprev) {
768 printf("%d %8d\r", i, count);
771 countprev += (sizeof(buf) / 20);
776 sent = ((unsigned)sys_random()%(20))+ 1;
777 if (sent > sizeof(buf) - count)
779 sent = sizeof(buf) - count;
782 status = cli_writeall(c, fnum, 0, (uint8_t *)buf+count,
784 if (!NT_STATUS_IS_OK(status)) {
785 printf("write failed (%s)\n",
792 status = cli_read(c, fnum, buf_rd+count, count,
793 sizeof(buf)-count, &sent);
794 if(!NT_STATUS_IS_OK(status)) {
795 printf("read failed offset:%d size:%ld (%s)\n",
796 count, (unsigned long)sizeof(buf)-count,
800 } else if (sent > 0) {
801 if (memcmp(buf_rd+count, buf+count, sent) != 0)
803 printf("read/write compare failed\n");
804 printf("offset: %d req %ld recvd %ld\n", count, (unsigned long)sizeof(buf)-count, (unsigned long)sent);
813 status = cli_close(c, fnum);
814 if (!NT_STATUS_IS_OK(status)) {
815 printf("close failed (%s)\n", nt_errstr(status));
822 static bool rw_torture2(struct cli_state *c1, struct cli_state *c2)
824 const char *lockfname = "\\torture2.lck";
834 status = cli_unlink(c1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
835 if (!NT_STATUS_IS_OK(status)) {
836 printf("unlink failed (%s) (normal, this file should not exist)\n", nt_errstr(status));
839 status = cli_open(c1, lockfname, O_RDWR | O_CREAT | O_EXCL,
841 if (!NT_STATUS_IS_OK(status)) {
842 printf("first open read/write of %s failed (%s)\n",
843 lockfname, nt_errstr(status));
847 status = cli_open(c2, lockfname, O_RDONLY, DENY_NONE, &fnum2);
848 if (!NT_STATUS_IS_OK(status)) {
849 printf("second open read-only of %s failed (%s)\n",
850 lockfname, nt_errstr(status));
851 cli_close(c1, fnum1);
855 for (i = 0; i < torture_numops; i++)
857 size_t buf_size = ((unsigned)sys_random()%(sizeof(buf)-1))+ 1;
859 printf("%d\r", i); fflush(stdout);
862 generate_random_buffer((unsigned char *)buf, buf_size);
864 status = cli_writeall(c1, fnum1, 0, (uint8_t *)buf, 0,
866 if (!NT_STATUS_IS_OK(status)) {
867 printf("write failed (%s)\n", nt_errstr(status));
872 status = cli_read(c2, fnum2, buf_rd, 0, buf_size, &bytes_read);
873 if(!NT_STATUS_IS_OK(status)) {
874 printf("read failed (%s)\n", nt_errstr(status));
877 } else if (bytes_read != buf_size) {
878 printf("read failed\n");
879 printf("read %ld, expected %ld\n",
880 (unsigned long)bytes_read,
881 (unsigned long)buf_size);
886 if (memcmp(buf_rd, buf, buf_size) != 0)
888 printf("read/write compare failed\n");
894 status = cli_close(c2, fnum2);
895 if (!NT_STATUS_IS_OK(status)) {
896 printf("close failed (%s)\n", nt_errstr(status));
900 status = cli_close(c1, fnum1);
901 if (!NT_STATUS_IS_OK(status)) {
902 printf("close failed (%s)\n", nt_errstr(status));
906 status = cli_unlink(c1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
907 if (!NT_STATUS_IS_OK(status)) {
908 printf("unlink failed (%s)\n", nt_errstr(status));
915 static bool run_readwritetest(int dummy)
917 struct cli_state *cli1, *cli2;
918 bool test1, test2 = False;
920 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
923 cli_sockopt(cli1, sockops);
924 cli_sockopt(cli2, sockops);
926 printf("starting readwritetest\n");
928 test1 = rw_torture2(cli1, cli2);
929 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1));
932 test2 = rw_torture2(cli1, cli1);
933 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2));
936 if (!torture_close_connection(cli1)) {
940 if (!torture_close_connection(cli2)) {
944 return (test1 && test2);
947 static bool run_readwritemulti(int dummy)
949 struct cli_state *cli;
954 cli_sockopt(cli, sockops);
956 printf("run_readwritemulti: fname %s\n", randomfname);
957 test = rw_torture3(cli, randomfname);
959 if (!torture_close_connection(cli)) {
966 static bool run_readwritelarge_internal(int max_xmit_k)
968 static struct cli_state *cli1;
970 const char *lockfname = "\\large.dat";
976 if (!torture_open_connection(&cli1, 0)) {
979 cli_sockopt(cli1, sockops);
980 memset(buf,'\0',sizeof(buf));
982 cli1->max_xmit = max_xmit_k*1024;
984 if (signing_state == Required) {
985 /* Horrible cheat to force
986 multiple signed outstanding
987 packets against a Samba server.
989 cli1->is_samba = false;
992 printf("starting readwritelarge_internal\n");
994 cli_unlink(cli1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
996 status = cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL,
998 if (!NT_STATUS_IS_OK(status)) {
999 printf("open read/write of %s failed (%s)\n", lockfname, nt_errstr(status));
1003 cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 0, sizeof(buf), NULL);
1005 status = cli_qfileinfo_basic(cli1, fnum1, NULL, &fsize, NULL, NULL,
1007 if (!NT_STATUS_IS_OK(status)) {
1008 printf("qfileinfo failed (%s)\n", nt_errstr(status));
1012 if (fsize == sizeof(buf))
1013 printf("readwritelarge_internal test 1 succeeded (size = %lx)\n",
1014 (unsigned long)fsize);
1016 printf("readwritelarge_internal test 1 failed (size = %lx)\n",
1017 (unsigned long)fsize);
1021 status = cli_close(cli1, fnum1);
1022 if (!NT_STATUS_IS_OK(status)) {
1023 printf("close failed (%s)\n", nt_errstr(status));
1027 status = cli_unlink(cli1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1028 if (!NT_STATUS_IS_OK(status)) {
1029 printf("unlink failed (%s)\n", nt_errstr(status));
1033 status = cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL,
1035 if (!NT_STATUS_IS_OK(status)) {
1036 printf("open read/write of %s failed (%s)\n", lockfname, nt_errstr(status));
1040 cli1->max_xmit = 4*1024;
1042 cli_smbwrite(cli1, fnum1, buf, 0, sizeof(buf), NULL);
1044 status = cli_qfileinfo_basic(cli1, fnum1, NULL, &fsize, NULL, NULL,
1046 if (!NT_STATUS_IS_OK(status)) {
1047 printf("qfileinfo failed (%s)\n", nt_errstr(status));
1051 if (fsize == sizeof(buf))
1052 printf("readwritelarge_internal test 2 succeeded (size = %lx)\n",
1053 (unsigned long)fsize);
1055 printf("readwritelarge_internal test 2 failed (size = %lx)\n",
1056 (unsigned long)fsize);
1061 /* ToDo - set allocation. JRA */
1062 if(!cli_set_allocation_size(cli1, fnum1, 0)) {
1063 printf("set allocation size to zero failed (%s)\n", cli_errstr(&cli1));
1066 if (!cli_qfileinfo_basic(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL,
1068 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
1072 printf("readwritelarge test 3 (truncate test) succeeded (size = %x)\n", fsize);
1075 status = cli_close(cli1, fnum1);
1076 if (!NT_STATUS_IS_OK(status)) {
1077 printf("close failed (%s)\n", nt_errstr(status));
1081 if (!torture_close_connection(cli1)) {
1087 static bool run_readwritelarge(int dummy)
1089 return run_readwritelarge_internal(128);
1092 static bool run_readwritelarge_signtest(int dummy)
1095 signing_state = Required;
1096 ret = run_readwritelarge_internal(2);
1097 signing_state = Undefined;
1104 #define ival(s) strtol(s, NULL, 0)
1106 /* run a test that simulates an approximate netbench client load */
1107 static bool run_netbench(int client)
1109 struct cli_state *cli;
1114 const char *params[20];
1115 bool correct = True;
1121 cli_sockopt(cli, sockops);
1125 slprintf(cname,sizeof(cname)-1, "client%d", client);
1127 f = fopen(client_txt, "r");
1134 while (fgets(line, sizeof(line)-1, f)) {
1138 line[strlen(line)-1] = 0;
1140 /* printf("[%d] %s\n", line_count, line); */
1142 all_string_sub(line,"client1", cname, sizeof(line));
1144 /* parse the command parameters */
1145 params[0] = strtok_r(line, " ", &saveptr);
1147 while (params[i]) params[++i] = strtok_r(NULL, " ", &saveptr);
1151 if (i < 2) continue;
1153 if (!strncmp(params[0],"SMB", 3)) {
1154 printf("ERROR: You are using a dbench 1 load file\n");
1158 if (!strcmp(params[0],"NTCreateX")) {
1159 nb_createx(params[1], ival(params[2]), ival(params[3]),
1161 } else if (!strcmp(params[0],"Close")) {
1162 nb_close(ival(params[1]));
1163 } else if (!strcmp(params[0],"Rename")) {
1164 nb_rename(params[1], params[2]);
1165 } else if (!strcmp(params[0],"Unlink")) {
1166 nb_unlink(params[1]);
1167 } else if (!strcmp(params[0],"Deltree")) {
1168 nb_deltree(params[1]);
1169 } else if (!strcmp(params[0],"Rmdir")) {
1170 nb_rmdir(params[1]);
1171 } else if (!strcmp(params[0],"QUERY_PATH_INFORMATION")) {
1172 nb_qpathinfo(params[1]);
1173 } else if (!strcmp(params[0],"QUERY_FILE_INFORMATION")) {
1174 nb_qfileinfo(ival(params[1]));
1175 } else if (!strcmp(params[0],"QUERY_FS_INFORMATION")) {
1176 nb_qfsinfo(ival(params[1]));
1177 } else if (!strcmp(params[0],"FIND_FIRST")) {
1178 nb_findfirst(params[1]);
1179 } else if (!strcmp(params[0],"WriteX")) {
1180 nb_writex(ival(params[1]),
1181 ival(params[2]), ival(params[3]), ival(params[4]));
1182 } else if (!strcmp(params[0],"ReadX")) {
1183 nb_readx(ival(params[1]),
1184 ival(params[2]), ival(params[3]), ival(params[4]));
1185 } else if (!strcmp(params[0],"Flush")) {
1186 nb_flush(ival(params[1]));
1188 printf("Unknown operation %s\n", params[0]);
1196 if (!torture_close_connection(cli)) {
1204 /* run a test that simulates an approximate netbench client load */
1205 static bool run_nbench(int dummy)
1208 bool correct = True;
1214 signal(SIGALRM, nb_alarm);
1216 t = create_procs(run_netbench, &correct);
1219 printf("\nThroughput %g MB/sec\n",
1220 1.0e-6 * nbio_total() / t);
1226 This test checks for two things:
1228 1) correct support for retaining locks over a close (ie. the server
1229 must not use posix semantics)
1230 2) support for lock timeouts
1232 static bool run_locktest1(int dummy)
1234 struct cli_state *cli1, *cli2;
1235 const char *fname = "\\lockt1.lck";
1236 uint16_t fnum1, fnum2, fnum3;
1238 unsigned lock_timeout;
1241 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1244 cli_sockopt(cli1, sockops);
1245 cli_sockopt(cli2, sockops);
1247 printf("starting locktest1\n");
1249 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1251 status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
1253 if (!NT_STATUS_IS_OK(status)) {
1254 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
1258 status = cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum2);
1259 if (!NT_STATUS_IS_OK(status)) {
1260 printf("open2 of %s failed (%s)\n", fname, nt_errstr(status));
1264 status = cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum3);
1265 if (!NT_STATUS_IS_OK(status)) {
1266 printf("open3 of %s failed (%s)\n", fname, nt_errstr(status));
1270 status = cli_lock32(cli1, fnum1, 0, 4, 0, WRITE_LOCK);
1271 if (!NT_STATUS_IS_OK(status)) {
1272 printf("lock1 failed (%s)\n", nt_errstr(status));
1276 status = cli_lock32(cli2, fnum3, 0, 4, 0, WRITE_LOCK);
1277 if (NT_STATUS_IS_OK(status)) {
1278 printf("lock2 succeeded! This is a locking bug\n");
1281 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1282 NT_STATUS_LOCK_NOT_GRANTED)) {
1287 lock_timeout = (1 + (random() % 20));
1288 printf("Testing lock timeout with timeout=%u\n", lock_timeout);
1290 status = cli_lock32(cli2, fnum3, 0, 4, lock_timeout * 1000, WRITE_LOCK);
1291 if (NT_STATUS_IS_OK(status)) {
1292 printf("lock3 succeeded! This is a locking bug\n");
1295 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1296 NT_STATUS_FILE_LOCK_CONFLICT)) {
1302 if (ABS(t2 - t1) < lock_timeout-1) {
1303 printf("error: This server appears not to support timed lock requests\n");
1306 printf("server slept for %u seconds for a %u second timeout\n",
1307 (unsigned int)(t2-t1), lock_timeout);
1309 status = cli_close(cli1, fnum2);
1310 if (!NT_STATUS_IS_OK(status)) {
1311 printf("close1 failed (%s)\n", nt_errstr(status));
1315 status = cli_lock32(cli2, fnum3, 0, 4, 0, WRITE_LOCK);
1316 if (NT_STATUS_IS_OK(status)) {
1317 printf("lock4 succeeded! This is a locking bug\n");
1320 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1321 NT_STATUS_FILE_LOCK_CONFLICT)) {
1326 status = cli_close(cli1, fnum1);
1327 if (!NT_STATUS_IS_OK(status)) {
1328 printf("close2 failed (%s)\n", nt_errstr(status));
1332 status = cli_close(cli2, fnum3);
1333 if (!NT_STATUS_IS_OK(status)) {
1334 printf("close3 failed (%s)\n", nt_errstr(status));
1338 status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1339 if (!NT_STATUS_IS_OK(status)) {
1340 printf("unlink failed (%s)\n", nt_errstr(status));
1345 if (!torture_close_connection(cli1)) {
1349 if (!torture_close_connection(cli2)) {
1353 printf("Passed locktest1\n");
1358 this checks to see if a secondary tconx can use open files from an
1361 static bool run_tcon_test(int dummy)
1363 static struct cli_state *cli;
1364 const char *fname = "\\tcontest.tmp";
1366 uint16 cnum1, cnum2, cnum3;
1367 uint16 vuid1, vuid2;
1372 memset(buf, '\0', sizeof(buf));
1374 if (!torture_open_connection(&cli, 0)) {
1377 cli_sockopt(cli, sockops);
1379 printf("starting tcontest\n");
1381 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1383 status = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
1384 if (!NT_STATUS_IS_OK(status)) {
1385 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
1389 cnum1 = cli_state_get_tid(cli);
1390 vuid1 = cli_state_get_uid(cli);
1392 status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
1393 if (!NT_STATUS_IS_OK(status)) {
1394 printf("initial write failed (%s)", nt_errstr(status));
1398 status = cli_tcon_andx(cli, share, "?????",
1399 password, strlen(password)+1);
1400 if (!NT_STATUS_IS_OK(status)) {
1401 printf("%s refused 2nd tree connect (%s)\n", host,
1407 cnum2 = cli_state_get_tid(cli);
1408 cnum3 = MAX(cnum1, cnum2) + 1; /* any invalid number */
1409 vuid2 = cli_state_get_uid(cli) + 1;
1411 /* try a write with the wrong tid */
1412 cli_state_set_tid(cli, cnum2);
1414 status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
1415 if (NT_STATUS_IS_OK(status)) {
1416 printf("* server allows write with wrong TID\n");
1419 printf("server fails write with wrong TID : %s\n",
1424 /* try a write with an invalid tid */
1425 cli_state_set_tid(cli, cnum3);
1427 status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
1428 if (NT_STATUS_IS_OK(status)) {
1429 printf("* server allows write with invalid TID\n");
1432 printf("server fails write with invalid TID : %s\n",
1436 /* try a write with an invalid vuid */
1437 cli_state_set_uid(cli, vuid2);
1438 cli_state_set_tid(cli, cnum1);
1440 status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
1441 if (NT_STATUS_IS_OK(status)) {
1442 printf("* server allows write with invalid VUID\n");
1445 printf("server fails write with invalid VUID : %s\n",
1449 cli_state_set_tid(cli, cnum1);
1450 cli_state_set_uid(cli, vuid1);
1452 status = cli_close(cli, fnum1);
1453 if (!NT_STATUS_IS_OK(status)) {
1454 printf("close failed (%s)\n", nt_errstr(status));
1458 cli_state_set_tid(cli, cnum2);
1460 status = cli_tdis(cli);
1461 if (!NT_STATUS_IS_OK(status)) {
1462 printf("secondary tdis failed (%s)\n", nt_errstr(status));
1466 cli_state_set_tid(cli, cnum1);
1468 if (!torture_close_connection(cli)) {
1477 checks for old style tcon support
1479 static bool run_tcon2_test(int dummy)
1481 static struct cli_state *cli;
1482 uint16 cnum, max_xmit;
1486 if (!torture_open_connection(&cli, 0)) {
1489 cli_sockopt(cli, sockops);
1491 printf("starting tcon2 test\n");
1493 if (asprintf(&service, "\\\\%s\\%s", host, share) == -1) {
1497 status = cli_raw_tcon(cli, service, password, "?????", &max_xmit, &cnum);
1501 if (!NT_STATUS_IS_OK(status)) {
1502 printf("tcon2 failed : %s\n", nt_errstr(status));
1504 printf("tcon OK : max_xmit=%d cnum=%d\n",
1505 (int)max_xmit, (int)cnum);
1508 if (!torture_close_connection(cli)) {
1512 printf("Passed tcon2 test\n");
1516 static bool tcon_devtest(struct cli_state *cli,
1517 const char *myshare, const char *devtype,
1518 const char *return_devtype,
1519 NTSTATUS expected_error)
1524 status = cli_tcon_andx(cli, myshare, devtype,
1525 password, strlen(password)+1);
1527 if (NT_STATUS_IS_OK(expected_error)) {
1528 if (NT_STATUS_IS_OK(status)) {
1529 if (strcmp(cli->dev, return_devtype) == 0) {
1532 printf("tconX to share %s with type %s "
1533 "succeeded but returned the wrong "
1534 "device type (got [%s] but should have got [%s])\n",
1535 myshare, devtype, cli->dev, return_devtype);
1539 printf("tconX to share %s with type %s "
1540 "should have succeeded but failed\n",
1546 if (NT_STATUS_IS_OK(status)) {
1547 printf("tconx to share %s with type %s "
1548 "should have failed but succeeded\n",
1552 if (NT_STATUS_EQUAL(cli_nt_error(cli),
1556 printf("Returned unexpected error\n");
1565 checks for correct tconX support
1567 static bool run_tcon_devtype_test(int dummy)
1569 static struct cli_state *cli1 = NULL;
1574 status = cli_full_connection(&cli1, myname,
1575 host, NULL, port_to_use,
1577 username, workgroup,
1578 password, flags, signing_state);
1580 if (!NT_STATUS_IS_OK(status)) {
1581 printf("could not open connection\n");
1585 if (!tcon_devtest(cli1, "IPC$", "A:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1588 if (!tcon_devtest(cli1, "IPC$", "?????", "IPC", NT_STATUS_OK))
1591 if (!tcon_devtest(cli1, "IPC$", "LPT:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1594 if (!tcon_devtest(cli1, "IPC$", "IPC", "IPC", NT_STATUS_OK))
1597 if (!tcon_devtest(cli1, "IPC$", "FOOBA", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1600 if (!tcon_devtest(cli1, share, "A:", "A:", NT_STATUS_OK))
1603 if (!tcon_devtest(cli1, share, "?????", "A:", NT_STATUS_OK))
1606 if (!tcon_devtest(cli1, share, "LPT:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1609 if (!tcon_devtest(cli1, share, "IPC", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1612 if (!tcon_devtest(cli1, share, "FOOBA", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1618 printf("Passed tcondevtest\n");
1625 This test checks that
1627 1) the server supports multiple locking contexts on the one SMB
1628 connection, distinguished by PID.
1630 2) the server correctly fails overlapping locks made by the same PID (this
1631 goes against POSIX behaviour, which is why it is tricky to implement)
1633 3) the server denies unlock requests by an incorrect client PID
1635 static bool run_locktest2(int dummy)
1637 static struct cli_state *cli;
1638 const char *fname = "\\lockt2.lck";
1639 uint16_t fnum1, fnum2, fnum3;
1640 bool correct = True;
1643 if (!torture_open_connection(&cli, 0)) {
1647 cli_sockopt(cli, sockops);
1649 printf("starting locktest2\n");
1651 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1655 status = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
1656 if (!NT_STATUS_IS_OK(status)) {
1657 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
1661 status = cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum2);
1662 if (!NT_STATUS_IS_OK(status)) {
1663 printf("open2 of %s failed (%s)\n", fname, nt_errstr(status));
1669 status = cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum3);
1670 if (!NT_STATUS_IS_OK(status)) {
1671 printf("open3 of %s failed (%s)\n", fname, nt_errstr(status));
1677 status = cli_lock32(cli, fnum1, 0, 4, 0, WRITE_LOCK);
1678 if (!NT_STATUS_IS_OK(status)) {
1679 printf("lock1 failed (%s)\n", nt_errstr(status));
1683 status = cli_lock32(cli, fnum1, 0, 4, 0, WRITE_LOCK);
1684 if (NT_STATUS_IS_OK(status)) {
1685 printf("WRITE lock1 succeeded! This is a locking bug\n");
1688 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1689 NT_STATUS_LOCK_NOT_GRANTED)) {
1694 status = cli_lock32(cli, fnum2, 0, 4, 0, WRITE_LOCK);
1695 if (NT_STATUS_IS_OK(status)) {
1696 printf("WRITE lock2 succeeded! This is a locking bug\n");
1699 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1700 NT_STATUS_LOCK_NOT_GRANTED)) {
1705 status = cli_lock32(cli, fnum2, 0, 4, 0, READ_LOCK);
1706 if (NT_STATUS_IS_OK(status)) {
1707 printf("READ lock2 succeeded! This is a locking bug\n");
1710 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1711 NT_STATUS_FILE_LOCK_CONFLICT)) {
1716 status = cli_lock32(cli, fnum1, 100, 4, 0, WRITE_LOCK);
1717 if (!NT_STATUS_IS_OK(status)) {
1718 printf("lock at 100 failed (%s)\n", nt_errstr(status));
1721 if (NT_STATUS_IS_OK(cli_unlock(cli, fnum1, 100, 4))) {
1722 printf("unlock at 100 succeeded! This is a locking bug\n");
1726 status = cli_unlock(cli, fnum1, 0, 4);
1727 if (NT_STATUS_IS_OK(status)) {
1728 printf("unlock1 succeeded! This is a locking bug\n");
1731 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1732 NT_STATUS_RANGE_NOT_LOCKED)) {
1737 status = cli_unlock(cli, fnum1, 0, 8);
1738 if (NT_STATUS_IS_OK(status)) {
1739 printf("unlock2 succeeded! This is a locking bug\n");
1742 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1743 NT_STATUS_RANGE_NOT_LOCKED)) {
1748 status = cli_lock32(cli, fnum3, 0, 4, 0, WRITE_LOCK);
1749 if (NT_STATUS_IS_OK(status)) {
1750 printf("lock3 succeeded! This is a locking bug\n");
1753 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
1754 NT_STATUS_LOCK_NOT_GRANTED)) {
1761 status = cli_close(cli, fnum1);
1762 if (!NT_STATUS_IS_OK(status)) {
1763 printf("close1 failed (%s)\n", nt_errstr(status));
1767 status = cli_close(cli, fnum2);
1768 if (!NT_STATUS_IS_OK(status)) {
1769 printf("close2 failed (%s)\n", nt_errstr(status));
1773 status = cli_close(cli, fnum3);
1774 if (!NT_STATUS_IS_OK(status)) {
1775 printf("close3 failed (%s)\n", nt_errstr(status));
1779 if (!torture_close_connection(cli)) {
1783 printf("locktest2 finished\n");
1790 This test checks that
1792 1) the server supports the full offset range in lock requests
1794 static bool run_locktest3(int dummy)
1796 static struct cli_state *cli1, *cli2;
1797 const char *fname = "\\lockt3.lck";
1798 uint16_t fnum1, fnum2;
1801 bool correct = True;
1804 #define NEXT_OFFSET offset += (~(uint32)0) / torture_numops
1806 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1809 cli_sockopt(cli1, sockops);
1810 cli_sockopt(cli2, sockops);
1812 printf("starting locktest3\n");
1814 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1816 status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
1818 if (!NT_STATUS_IS_OK(status)) {
1819 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
1823 status = cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
1824 if (!NT_STATUS_IS_OK(status)) {
1825 printf("open2 of %s failed (%s)\n", fname, nt_errstr(status));
1829 for (offset=i=0;i<torture_numops;i++) {
1832 status = cli_lock32(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK);
1833 if (!NT_STATUS_IS_OK(status)) {
1834 printf("lock1 %d failed (%s)\n",
1840 status = cli_lock32(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK);
1841 if (!NT_STATUS_IS_OK(status)) {
1842 printf("lock2 %d failed (%s)\n",
1849 for (offset=i=0;i<torture_numops;i++) {
1852 status = cli_lock32(cli1, fnum1, offset-2, 1, 0, WRITE_LOCK);
1853 if (NT_STATUS_IS_OK(status)) {
1854 printf("error: lock1 %d succeeded!\n", i);
1858 status = cli_lock32(cli2, fnum2, offset-1, 1, 0, WRITE_LOCK);
1859 if (NT_STATUS_IS_OK(status)) {
1860 printf("error: lock2 %d succeeded!\n", i);
1864 status = cli_lock32(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK);
1865 if (NT_STATUS_IS_OK(status)) {
1866 printf("error: lock3 %d succeeded!\n", i);
1870 status = cli_lock32(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK);
1871 if (NT_STATUS_IS_OK(status)) {
1872 printf("error: lock4 %d succeeded!\n", i);
1877 for (offset=i=0;i<torture_numops;i++) {
1880 status = cli_unlock(cli1, fnum1, offset-1, 1);
1881 if (!NT_STATUS_IS_OK(status)) {
1882 printf("unlock1 %d failed (%s)\n",
1888 status = cli_unlock(cli2, fnum2, offset-2, 1);
1889 if (!NT_STATUS_IS_OK(status)) {
1890 printf("unlock2 %d failed (%s)\n",
1897 status = cli_close(cli1, fnum1);
1898 if (!NT_STATUS_IS_OK(status)) {
1899 printf("close1 failed (%s)\n", nt_errstr(status));
1903 status = cli_close(cli2, fnum2);
1904 if (!NT_STATUS_IS_OK(status)) {
1905 printf("close2 failed (%s)\n", nt_errstr(status));
1909 status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1910 if (!NT_STATUS_IS_OK(status)) {
1911 printf("unlink failed (%s)\n", nt_errstr(status));
1915 if (!torture_close_connection(cli1)) {
1919 if (!torture_close_connection(cli2)) {
1923 printf("finished locktest3\n");
1928 static bool test_cli_read(struct cli_state *cli, uint16_t fnum,
1929 char *buf, off_t offset, size_t size,
1930 size_t *nread, size_t expect)
1935 status = cli_read(cli, fnum, buf, offset, size, &l_nread);
1937 if(!NT_STATUS_IS_OK(status)) {
1939 } else if (l_nread != expect) {
1950 #define EXPECTED(ret, v) if ((ret) != (v)) { \
1951 printf("** "); correct = False; \
1955 looks at overlapping locks
1957 static bool run_locktest4(int dummy)
1959 static struct cli_state *cli1, *cli2;
1960 const char *fname = "\\lockt4.lck";
1961 uint16_t fnum1, fnum2, f;
1964 bool correct = True;
1967 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1971 cli_sockopt(cli1, sockops);
1972 cli_sockopt(cli2, sockops);
1974 printf("starting locktest4\n");
1976 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
1978 cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
1979 cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
1981 memset(buf, 0, sizeof(buf));
1983 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 0, sizeof(buf),
1985 if (!NT_STATUS_IS_OK(status)) {
1986 printf("Failed to create file: %s\n", nt_errstr(status));
1991 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) &&
1992 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 2, 4, 0, WRITE_LOCK));
1993 EXPECTED(ret, False);
1994 printf("the same process %s set overlapping write locks\n", ret?"can":"cannot");
1996 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 10, 4, 0, READ_LOCK)) &&
1997 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 12, 4, 0, READ_LOCK));
1998 EXPECTED(ret, True);
1999 printf("the same process %s set overlapping read locks\n", ret?"can":"cannot");
2001 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 20, 4, 0, WRITE_LOCK)) &&
2002 NT_STATUS_IS_OK(cli_lock32(cli2, fnum2, 22, 4, 0, WRITE_LOCK));
2003 EXPECTED(ret, False);
2004 printf("a different connection %s set overlapping write locks\n", ret?"can":"cannot");
2006 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 30, 4, 0, READ_LOCK)) &&
2007 NT_STATUS_IS_OK(cli_lock32(cli2, fnum2, 32, 4, 0, READ_LOCK));
2008 EXPECTED(ret, True);
2009 printf("a different connection %s set overlapping read locks\n", ret?"can":"cannot");
2011 ret = (cli_setpid(cli1, 1),
2012 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 40, 4, 0, WRITE_LOCK))) &&
2013 (cli_setpid(cli1, 2),
2014 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 42, 4, 0, WRITE_LOCK)));
2015 EXPECTED(ret, False);
2016 printf("a different pid %s set overlapping write locks\n", ret?"can":"cannot");
2018 ret = (cli_setpid(cli1, 1),
2019 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 50, 4, 0, READ_LOCK))) &&
2020 (cli_setpid(cli1, 2),
2021 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 52, 4, 0, READ_LOCK)));
2022 EXPECTED(ret, True);
2023 printf("a different pid %s set overlapping read locks\n", ret?"can":"cannot");
2025 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 60, 4, 0, READ_LOCK)) &&
2026 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 60, 4, 0, READ_LOCK));
2027 EXPECTED(ret, True);
2028 printf("the same process %s set the same read lock twice\n", ret?"can":"cannot");
2030 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 70, 4, 0, WRITE_LOCK)) &&
2031 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 70, 4, 0, WRITE_LOCK));
2032 EXPECTED(ret, False);
2033 printf("the same process %s set the same write lock twice\n", ret?"can":"cannot");
2035 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 80, 4, 0, READ_LOCK)) &&
2036 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 80, 4, 0, WRITE_LOCK));
2037 EXPECTED(ret, False);
2038 printf("the same process %s overlay a read lock with a write lock\n", ret?"can":"cannot");
2040 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 90, 4, 0, WRITE_LOCK)) &&
2041 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 90, 4, 0, READ_LOCK));
2042 EXPECTED(ret, True);
2043 printf("the same process %s overlay a write lock with a read lock\n", ret?"can":"cannot");
2045 ret = (cli_setpid(cli1, 1),
2046 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 100, 4, 0, WRITE_LOCK))) &&
2047 (cli_setpid(cli1, 2),
2048 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 100, 4, 0, READ_LOCK)));
2049 EXPECTED(ret, False);
2050 printf("a different pid %s overlay a write lock with a read lock\n", ret?"can":"cannot");
2052 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 110, 4, 0, READ_LOCK)) &&
2053 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 112, 4, 0, READ_LOCK)) &&
2054 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 110, 6));
2055 EXPECTED(ret, False);
2056 printf("the same process %s coalesce read locks\n", ret?"can":"cannot");
2059 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 120, 4, 0, WRITE_LOCK)) &&
2060 test_cli_read(cli2, fnum2, buf, 120, 4, NULL, 4);
2061 EXPECTED(ret, False);
2062 printf("this server %s strict write locking\n", ret?"doesn't do":"does");
2064 status = cli_lock32(cli1, fnum1, 130, 4, 0, READ_LOCK);
2065 ret = NT_STATUS_IS_OK(status);
2067 status = cli_writeall(cli2, fnum2, 0, (uint8_t *)buf, 130, 4,
2069 ret = NT_STATUS_IS_OK(status);
2071 EXPECTED(ret, False);
2072 printf("this server %s strict read locking\n", ret?"doesn't do":"does");
2075 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 140, 4, 0, READ_LOCK)) &&
2076 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 140, 4, 0, READ_LOCK)) &&
2077 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 140, 4)) &&
2078 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 140, 4));
2079 EXPECTED(ret, True);
2080 printf("this server %s do recursive read locking\n", ret?"does":"doesn't");
2083 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 150, 4, 0, WRITE_LOCK)) &&
2084 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 150, 4, 0, READ_LOCK)) &&
2085 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 150, 4)) &&
2086 test_cli_read(cli2, fnum2, buf, 150, 4, NULL, 4) &&
2087 !(NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf,
2089 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 150, 4));
2090 EXPECTED(ret, True);
2091 printf("this server %s do recursive lock overlays\n", ret?"does":"doesn't");
2093 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 160, 4, 0, READ_LOCK)) &&
2094 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 160, 4)) &&
2095 NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf,
2097 test_cli_read(cli2, fnum2, buf, 160, 4, NULL, 4);
2098 EXPECTED(ret, True);
2099 printf("the same process %s remove a read lock using write locking\n", ret?"can":"cannot");
2101 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 170, 4, 0, WRITE_LOCK)) &&
2102 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 170, 4)) &&
2103 NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf,
2105 test_cli_read(cli2, fnum2, buf, 170, 4, NULL, 4);
2106 EXPECTED(ret, True);
2107 printf("the same process %s remove a write lock using read locking\n", ret?"can":"cannot");
2109 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 190, 4, 0, WRITE_LOCK)) &&
2110 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 190, 4, 0, READ_LOCK)) &&
2111 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 190, 4)) &&
2112 !NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf,
2114 test_cli_read(cli2, fnum2, buf, 190, 4, NULL, 4);
2115 EXPECTED(ret, True);
2116 printf("the same process %s remove the first lock first\n", ret?"does":"doesn't");
2118 cli_close(cli1, fnum1);
2119 cli_close(cli2, fnum2);
2120 cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
2121 cli_open(cli1, fname, O_RDWR, DENY_NONE, &f);
2122 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 8, 0, READ_LOCK)) &&
2123 NT_STATUS_IS_OK(cli_lock32(cli1, f, 0, 1, 0, READ_LOCK)) &&
2124 NT_STATUS_IS_OK(cli_close(cli1, fnum1)) &&
2125 NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1)) &&
2126 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 7, 1, 0, WRITE_LOCK));
2128 cli_close(cli1, fnum1);
2129 EXPECTED(ret, True);
2130 printf("the server %s have the NT byte range lock bug\n", !ret?"does":"doesn't");
2133 cli_close(cli1, fnum1);
2134 cli_close(cli2, fnum2);
2135 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2136 torture_close_connection(cli1);
2137 torture_close_connection(cli2);
2139 printf("finished locktest4\n");
2144 looks at lock upgrade/downgrade.
2146 static bool run_locktest5(int dummy)
2148 static struct cli_state *cli1, *cli2;
2149 const char *fname = "\\lockt5.lck";
2150 uint16_t fnum1, fnum2, fnum3;
2153 bool correct = True;
2156 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
2160 cli_sockopt(cli1, sockops);
2161 cli_sockopt(cli2, sockops);
2163 printf("starting locktest5\n");
2165 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2167 cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
2168 cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
2169 cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum3);
2171 memset(buf, 0, sizeof(buf));
2173 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 0, sizeof(buf),
2175 if (!NT_STATUS_IS_OK(status)) {
2176 printf("Failed to create file: %s\n", nt_errstr(status));
2181 /* Check for NT bug... */
2182 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 8, 0, READ_LOCK)) &&
2183 NT_STATUS_IS_OK(cli_lock32(cli1, fnum3, 0, 1, 0, READ_LOCK));
2184 cli_close(cli1, fnum1);
2185 cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
2186 status = cli_lock32(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
2187 ret = NT_STATUS_IS_OK(status);
2188 EXPECTED(ret, True);
2189 printf("this server %s the NT locking bug\n", ret ? "doesn't have" : "has");
2190 cli_close(cli1, fnum1);
2191 cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
2192 cli_unlock(cli1, fnum3, 0, 1);
2194 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) &&
2195 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 1, 1, 0, READ_LOCK));
2196 EXPECTED(ret, True);
2197 printf("the same process %s overlay a write with a read lock\n", ret?"can":"cannot");
2199 status = cli_lock32(cli2, fnum2, 0, 4, 0, READ_LOCK);
2200 ret = NT_STATUS_IS_OK(status);
2201 EXPECTED(ret, False);
2203 printf("a different processs %s get a read lock on the first process lock stack\n", ret?"can":"cannot");
2205 /* Unlock the process 2 lock. */
2206 cli_unlock(cli2, fnum2, 0, 4);
2208 status = cli_lock32(cli1, fnum3, 0, 4, 0, READ_LOCK);
2209 ret = NT_STATUS_IS_OK(status);
2210 EXPECTED(ret, False);
2212 printf("the same processs on a different fnum %s get a read lock\n", ret?"can":"cannot");
2214 /* Unlock the process 1 fnum3 lock. */
2215 cli_unlock(cli1, fnum3, 0, 4);
2217 /* Stack 2 more locks here. */
2218 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 4, 0, READ_LOCK)) &&
2219 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 4, 0, READ_LOCK));
2221 EXPECTED(ret, True);
2222 printf("the same process %s stack read locks\n", ret?"can":"cannot");
2224 /* Unlock the first process lock, then check this was the WRITE lock that was
2227 ret = NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 0, 4)) &&
2228 NT_STATUS_IS_OK(cli_lock32(cli2, fnum2, 0, 4, 0, READ_LOCK));
2230 EXPECTED(ret, True);
2231 printf("the first unlock removes the %s lock\n", ret?"WRITE":"READ");
2233 /* Unlock the process 2 lock. */
2234 cli_unlock(cli2, fnum2, 0, 4);
2236 /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */
2238 ret = NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 1, 1)) &&
2239 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 0, 4)) &&
2240 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 0, 4));
2242 EXPECTED(ret, True);
2243 printf("the same process %s unlock the stack of 4 locks\n", ret?"can":"cannot");
2245 /* Ensure the next unlock fails. */
2246 ret = NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 0, 4));
2247 EXPECTED(ret, False);
2248 printf("the same process %s count the lock stack\n", !ret?"can":"cannot");
2250 /* Ensure connection 2 can get a write lock. */
2251 status = cli_lock32(cli2, fnum2, 0, 4, 0, WRITE_LOCK);
2252 ret = NT_STATUS_IS_OK(status);
2253 EXPECTED(ret, True);
2255 printf("a different processs %s get a write lock on the unlocked stack\n", ret?"can":"cannot");
2259 cli_close(cli1, fnum1);
2260 cli_close(cli2, fnum2);
2261 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2262 if (!torture_close_connection(cli1)) {
2265 if (!torture_close_connection(cli2)) {
2269 printf("finished locktest5\n");
2275 tries the unusual lockingX locktype bits
2277 static bool run_locktest6(int dummy)
2279 static struct cli_state *cli;
2280 const char *fname[1] = { "\\lock6.txt" };
2285 if (!torture_open_connection(&cli, 0)) {
2289 cli_sockopt(cli, sockops);
2291 printf("starting locktest6\n");
2294 printf("Testing %s\n", fname[i]);
2296 cli_unlink(cli, fname[i], FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2298 cli_open(cli, fname[i], O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
2299 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE);
2300 cli_close(cli, fnum);
2301 printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status));
2303 cli_open(cli, fname[i], O_RDWR, DENY_NONE, &fnum);
2304 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK);
2305 cli_close(cli, fnum);
2306 printf("CANCEL_LOCK gave %s\n", nt_errstr(status));
2308 cli_unlink(cli, fname[i], FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2311 torture_close_connection(cli);
2313 printf("finished locktest6\n");
2317 static bool run_locktest7(int dummy)
2319 struct cli_state *cli1;
2320 const char *fname = "\\lockt7.lck";
2323 bool correct = False;
2327 if (!torture_open_connection(&cli1, 0)) {
2331 cli_sockopt(cli1, sockops);
2333 printf("starting locktest7\n");
2335 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2337 cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
2339 memset(buf, 0, sizeof(buf));
2341 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 0, sizeof(buf),
2343 if (!NT_STATUS_IS_OK(status)) {
2344 printf("Failed to create file: %s\n", nt_errstr(status));
2348 cli_setpid(cli1, 1);
2350 status = cli_lock32(cli1, fnum1, 130, 4, 0, READ_LOCK);
2351 if (!NT_STATUS_IS_OK(status)) {
2352 printf("Unable to apply read lock on range 130:4, "
2353 "error was %s\n", nt_errstr(status));
2356 printf("pid1 successfully locked range 130:4 for READ\n");
2359 status = cli_read(cli1, fnum1, buf, 130, 4, &nread);
2360 if (!NT_STATUS_IS_OK(status)) {
2361 printf("pid1 unable to read the range 130:4, error was %s\n",
2364 } else if (nread != 4) {
2365 printf("pid1 unable to read the range 130:4, "
2366 "recv %ld req %d\n", (unsigned long)nread, 4);
2369 printf("pid1 successfully read the range 130:4\n");
2372 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
2373 if (!NT_STATUS_IS_OK(status)) {
2374 printf("pid1 unable to write to the range 130:4, error was "
2375 "%s\n", nt_errstr(status));
2376 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_LOCK_CONFLICT)) {
2377 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2381 printf("pid1 successfully wrote to the range 130:4 (should be denied)\n");
2385 cli_setpid(cli1, 2);
2387 status = cli_read(cli1, fnum1, buf, 130, 4, &nread);
2388 if (!NT_STATUS_IS_OK(status)) {
2389 printf("pid2 unable to read the range 130:4, error was %s\n",
2392 } else if (nread != 4) {
2393 printf("pid2 unable to read the range 130:4, "
2394 "recv %ld req %d\n", (unsigned long)nread, 4);
2397 printf("pid2 successfully read the range 130:4\n");
2400 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
2401 if (!NT_STATUS_IS_OK(status)) {
2402 printf("pid2 unable to write to the range 130:4, error was "
2403 "%s\n", nt_errstr(status));
2404 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_LOCK_CONFLICT)) {
2405 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2409 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
2413 cli_setpid(cli1, 1);
2414 cli_unlock(cli1, fnum1, 130, 4);
2416 status = cli_lock32(cli1, fnum1, 130, 4, 0, WRITE_LOCK);
2417 if (!NT_STATUS_IS_OK(status)) {
2418 printf("Unable to apply write lock on range 130:4, error was %s\n", nt_errstr(status));
2421 printf("pid1 successfully locked range 130:4 for WRITE\n");
2424 status = cli_read(cli1, fnum1, buf, 130, 4, &nread);
2425 if (!NT_STATUS_IS_OK(status)) {
2426 printf("pid1 unable to read the range 130:4, error was %s\n",
2429 } else if (nread != 4) {
2430 printf("pid1 unable to read the range 130:4, "
2431 "recv %ld req %d\n", (unsigned long)nread, 4);
2434 printf("pid1 successfully read the range 130:4\n");
2437 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
2438 if (!NT_STATUS_IS_OK(status)) {
2439 printf("pid1 unable to write to the range 130:4, error was "
2440 "%s\n", nt_errstr(status));
2443 printf("pid1 successfully wrote to the range 130:4\n");
2446 cli_setpid(cli1, 2);
2448 status = cli_read(cli1, fnum1, buf, 130, 4, &nread);
2449 if (!NT_STATUS_IS_OK(status)) {
2450 printf("pid2 unable to read the range 130:4, error was "
2451 "%s\n", nt_errstr(status));
2452 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_LOCK_CONFLICT)) {
2453 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2457 printf("pid2 successfully read the range 130:4 (should be denied) recv %ld\n",
2458 (unsigned long)nread);
2462 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
2463 if (!NT_STATUS_IS_OK(status)) {
2464 printf("pid2 unable to write to the range 130:4, error was "
2465 "%s\n", nt_errstr(status));
2466 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_LOCK_CONFLICT)) {
2467 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2471 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
2475 cli_unlock(cli1, fnum1, 130, 0);
2479 cli_close(cli1, fnum1);
2480 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2481 torture_close_connection(cli1);
2483 printf("finished locktest7\n");
2488 * This demonstrates a problem with our use of GPFS share modes: A file
2489 * descriptor sitting in the pending close queue holding a GPFS share mode
2490 * blocks opening a file another time. Happens with Word 2007 temp files.
2491 * With "posix locking = yes" and "gpfs:sharemodes = yes" enabled, the third
2492 * open is denied with NT_STATUS_SHARING_VIOLATION.
2495 static bool run_locktest8(int dummy)
2497 struct cli_state *cli1;
2498 const char *fname = "\\lockt8.lck";
2499 uint16_t fnum1, fnum2;
2501 bool correct = False;
2504 if (!torture_open_connection(&cli1, 0)) {
2508 cli_sockopt(cli1, sockops);
2510 printf("starting locktest8\n");
2512 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2514 status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_WRITE,
2516 if (!NT_STATUS_IS_OK(status)) {
2517 d_fprintf(stderr, "cli_open returned %s\n", nt_errstr(status));
2521 memset(buf, 0, sizeof(buf));
2523 status = cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum2);
2524 if (!NT_STATUS_IS_OK(status)) {
2525 d_fprintf(stderr, "cli_open second time returned %s\n",
2530 status = cli_lock32(cli1, fnum2, 1, 1, 0, READ_LOCK);
2531 if (!NT_STATUS_IS_OK(status)) {
2532 printf("Unable to apply read lock on range 1:1, error was "
2533 "%s\n", nt_errstr(status));
2537 status = cli_close(cli1, fnum1);
2538 if (!NT_STATUS_IS_OK(status)) {
2539 d_fprintf(stderr, "cli_close(fnum1) %s\n", nt_errstr(status));
2543 status = cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
2544 if (!NT_STATUS_IS_OK(status)) {
2545 d_fprintf(stderr, "cli_open third time returned %s\n",
2553 cli_close(cli1, fnum1);
2554 cli_close(cli1, fnum2);
2555 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2556 torture_close_connection(cli1);
2558 printf("finished locktest8\n");
2563 * This test is designed to be run in conjunction with
2564 * external NFS or POSIX locks taken in the filesystem.
2565 * It checks that the smbd server will block until the
2566 * lock is released and then acquire it. JRA.
2569 static bool got_alarm;
2570 static struct cli_state *alarm_cli;
2572 static void alarm_handler(int dummy)
2577 static void alarm_handler_parent(int dummy)
2579 cli_state_disconnect(alarm_cli);
2582 static void do_local_lock(int read_fd, int write_fd)
2587 const char *local_pathname = NULL;
2590 local_pathname = talloc_asprintf(talloc_tos(),
2591 "%s/lockt9.lck", local_path);
2592 if (!local_pathname) {
2593 printf("child: alloc fail\n");
2597 unlink(local_pathname);
2598 fd = open(local_pathname, O_RDWR|O_CREAT, 0666);
2600 printf("child: open of %s failed %s.\n",
2601 local_pathname, strerror(errno));
2605 /* Now take a fcntl lock. */
2606 lock.l_type = F_WRLCK;
2607 lock.l_whence = SEEK_SET;
2610 lock.l_pid = getpid();
2612 ret = fcntl(fd,F_SETLK,&lock);
2614 printf("child: failed to get lock 0:4 on file %s. Error %s\n",
2615 local_pathname, strerror(errno));
2618 printf("child: got lock 0:4 on file %s.\n",
2623 CatchSignal(SIGALRM, alarm_handler);
2625 /* Signal the parent. */
2626 if (write(write_fd, &c, 1) != 1) {
2627 printf("child: start signal fail %s.\n",
2634 /* Wait for the parent to be ready. */
2635 if (read(read_fd, &c, 1) != 1) {
2636 printf("child: reply signal fail %s.\n",
2644 printf("child: released lock 0:4 on file %s.\n",
2650 static bool run_locktest9(int dummy)
2652 struct cli_state *cli1;
2653 const char *fname = "\\lockt9.lck";
2655 bool correct = False;
2656 int pipe_in[2], pipe_out[2];
2660 struct timeval start;
2664 printf("starting locktest9\n");
2666 if (local_path == NULL) {
2667 d_fprintf(stderr, "locktest9 must be given a local path via -l <localpath>\n");
2671 if (pipe(pipe_in) == -1 || pipe(pipe_out) == -1) {
2676 if (child_pid == -1) {
2680 if (child_pid == 0) {
2682 do_local_lock(pipe_out[0], pipe_in[1]);
2692 ret = read(pipe_in[0], &c, 1);
2694 d_fprintf(stderr, "failed to read start signal from child. %s\n",
2699 if (!torture_open_connection(&cli1, 0)) {
2703 cli_sockopt(cli1, sockops);
2705 status = cli_open(cli1, fname, O_RDWR, DENY_NONE,
2707 if (!NT_STATUS_IS_OK(status)) {
2708 d_fprintf(stderr, "cli_open returned %s\n", nt_errstr(status));
2712 /* Ensure the child has the lock. */
2713 status = cli_lock32(cli1, fnum, 0, 4, 0, WRITE_LOCK);
2714 if (NT_STATUS_IS_OK(status)) {
2715 d_fprintf(stderr, "Got the lock on range 0:4 - this should not happen !\n");
2718 d_printf("Child has the lock.\n");
2721 /* Tell the child to wait 5 seconds then exit. */
2722 ret = write(pipe_out[1], &c, 1);
2724 d_fprintf(stderr, "failed to send exit signal to child. %s\n",
2729 /* Wait 20 seconds for the lock. */
2731 CatchSignal(SIGALRM, alarm_handler_parent);
2734 start = timeval_current();
2736 status = cli_lock32(cli1, fnum, 0, 4, -1, WRITE_LOCK);
2737 if (!NT_STATUS_IS_OK(status)) {
2738 d_fprintf(stderr, "Unable to apply write lock on range 0:4, error was "
2739 "%s\n", nt_errstr(status));
2744 seconds = timeval_elapsed(&start);
2746 printf("Parent got the lock after %.2f seconds.\n",
2749 status = cli_close(cli1, fnum);
2750 if (!NT_STATUS_IS_OK(status)) {
2751 d_fprintf(stderr, "cli_close(fnum1) %s\n", nt_errstr(status));
2758 cli_close(cli1, fnum);
2759 torture_close_connection(cli1);
2763 printf("finished locktest9\n");
2768 test whether fnums and tids open on one VC are available on another (a major
2771 static bool run_fdpasstest(int dummy)
2773 struct cli_state *cli1, *cli2;
2774 const char *fname = "\\fdpass.tst";
2779 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
2782 cli_sockopt(cli1, sockops);
2783 cli_sockopt(cli2, sockops);
2785 printf("starting fdpasstest\n");
2787 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2789 status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
2791 if (!NT_STATUS_IS_OK(status)) {
2792 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
2796 status = cli_writeall(cli1, fnum1, 0, (const uint8_t *)"hello world\n", 0,
2798 if (!NT_STATUS_IS_OK(status)) {
2799 printf("write failed (%s)\n", nt_errstr(status));
2803 cli_state_set_uid(cli2, cli_state_get_uid(cli1));
2804 cli_state_set_tid(cli2, cli_state_get_tid(cli1));
2805 cli_setpid(cli2, cli_getpid(cli1));
2807 if (test_cli_read(cli2, fnum1, buf, 0, 13, NULL, 13)) {
2808 printf("read succeeded! nasty security hole [%s]\n", buf);
2812 cli_close(cli1, fnum1);
2813 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2815 torture_close_connection(cli1);
2816 torture_close_connection(cli2);
2818 printf("finished fdpasstest\n");
2822 static bool run_fdsesstest(int dummy)
2824 struct cli_state *cli;
2829 const char *fname = "\\fdsess.tst";
2830 const char *fname1 = "\\fdsess1.tst";
2837 if (!torture_open_connection(&cli, 0))
2839 cli_sockopt(cli, sockops);
2841 if (!torture_cli_session_setup2(cli, &new_vuid))
2844 saved_cnum = cli_state_get_tid(cli);
2845 if (!NT_STATUS_IS_OK(cli_tcon_andx(cli, share, "?????", "", 1)))
2847 new_cnum = cli_state_get_tid(cli);
2848 cli_state_set_tid(cli, saved_cnum);
2850 printf("starting fdsesstest\n");
2852 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2853 cli_unlink(cli, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2855 status = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
2856 if (!NT_STATUS_IS_OK(status)) {
2857 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
2861 status = cli_writeall(cli, fnum1, 0, (const uint8_t *)"hello world\n", 0, 13,
2863 if (!NT_STATUS_IS_OK(status)) {
2864 printf("write failed (%s)\n", nt_errstr(status));
2868 saved_vuid = cli_state_get_uid(cli);
2869 cli_state_set_uid(cli, new_vuid);
2871 if (test_cli_read(cli, fnum1, buf, 0, 13, NULL, 13)) {
2872 printf("read succeeded with different vuid! "
2873 "nasty security hole [%s]\n", buf);
2876 /* Try to open a file with different vuid, samba cnum. */
2877 if (NT_STATUS_IS_OK(cli_open(cli, fname1, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum2))) {
2878 printf("create with different vuid, same cnum succeeded.\n");
2879 cli_close(cli, fnum2);
2880 cli_unlink(cli, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2882 printf("create with different vuid, same cnum failed.\n");
2883 printf("This will cause problems with service clients.\n");
2887 cli_state_set_uid(cli, saved_vuid);
2889 /* Try with same vuid, different cnum. */
2890 cli_state_set_tid(cli, new_cnum);
2892 if (test_cli_read(cli, fnum1, buf, 0, 13, NULL, 13)) {
2893 printf("read succeeded with different cnum![%s]\n", buf);
2897 cli_state_set_tid(cli, saved_cnum);
2898 cli_close(cli, fnum1);
2899 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2901 torture_close_connection(cli);
2903 printf("finished fdsesstest\n");
2908 This test checks that
2910 1) the server does not allow an unlink on a file that is open
2912 static bool run_unlinktest(int dummy)
2914 struct cli_state *cli;
2915 const char *fname = "\\unlink.tst";
2917 bool correct = True;
2920 if (!torture_open_connection(&cli, 0)) {
2924 cli_sockopt(cli, sockops);
2926 printf("starting unlink test\n");
2928 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2932 status = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
2933 if (!NT_STATUS_IS_OK(status)) {
2934 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
2938 status = cli_unlink(cli, fname,
2939 FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2940 if (NT_STATUS_IS_OK(status)) {
2941 printf("error: server allowed unlink on an open file\n");
2944 correct = check_error(__LINE__, status, ERRDOS, ERRbadshare,
2945 NT_STATUS_SHARING_VIOLATION);
2948 cli_close(cli, fnum);
2949 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
2951 if (!torture_close_connection(cli)) {
2955 printf("unlink test finished\n");
2962 test how many open files this server supports on the one socket
2964 static bool run_maxfidtest(int dummy)
2966 struct cli_state *cli;
2968 uint16_t fnums[0x11000];
2971 bool correct = True;
2977 printf("failed to connect\n");
2981 cli_sockopt(cli, sockops);
2983 for (i=0; i<0x11000; i++) {
2984 slprintf(fname,sizeof(fname)-1,"\\maxfid.%d.%d", i,(int)getpid());
2985 status = cli_open(cli, fname, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE,
2987 if (!NT_STATUS_IS_OK(status)) {
2988 printf("open of %s failed (%s)\n",
2989 fname, nt_errstr(status));
2990 printf("maximum fnum is %d\n", i);
2998 printf("cleaning up\n");
3000 slprintf(fname,sizeof(fname)-1,"\\maxfid.%d.%d", i,(int)getpid());
3001 cli_close(cli, fnums[i]);
3003 status = cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3004 if (!NT_STATUS_IS_OK(status)) {
3005 printf("unlink of %s failed (%s)\n",
3006 fname, nt_errstr(status));
3013 printf("maxfid test finished\n");
3014 if (!torture_close_connection(cli)) {
3020 /* generate a random buffer */
3021 static void rand_buf(char *buf, int len)
3024 *buf = (char)sys_random();
3029 /* send smb negprot commands, not reading the response */
3030 static bool run_negprot_nowait(int dummy)
3032 struct tevent_context *ev;
3034 struct cli_state *cli;
3035 bool correct = True;
3037 printf("starting negprot nowait test\n");
3039 ev = tevent_context_init(talloc_tos());
3044 if (!(cli = open_nbt_connection())) {
3049 for (i=0;i<50000;i++) {
3050 struct tevent_req *req;
3052 req = cli_negprot_send(ev, ev, cli);
3057 if (!tevent_req_poll(req, ev)) {
3058 d_fprintf(stderr, "tevent_req_poll failed: %s\n",
3066 if (torture_close_connection(cli)) {
3070 printf("finished negprot nowait test\n");
3075 /* send smb negprot commands, not reading the response */
3076 static bool run_bad_nbt_session(int dummy)
3078 struct nmb_name called, calling;
3079 struct sockaddr_storage ss;
3084 printf("starting bad nbt session test\n");
3086 make_nmb_name(&calling, myname, 0x0);
3087 make_nmb_name(&called , host, 0x20);
3089 if (!resolve_name(host, &ss, 0x20, true)) {
3090 d_fprintf(stderr, "Could not resolve name %s\n", host);
3094 status = open_socket_out(&ss, 139, 10000, &fd);
3095 if (!NT_STATUS_IS_OK(status)) {
3096 d_fprintf(stderr, "open_socket_out failed: %s\n",
3101 ret = cli_bad_session_request(fd, &calling, &called);
3104 d_fprintf(stderr, "open_socket_out failed: %s\n",
3109 printf("finished bad nbt session test\n");
3113 /* send random IPC commands */
3114 static bool run_randomipc(int dummy)
3116 char *rparam = NULL;
3118 unsigned int rdrcnt,rprcnt;
3120 int api, param_len, i;
3121 struct cli_state *cli;
3122 bool correct = True;
3125 printf("starting random ipc test\n");
3127 if (!torture_open_connection(&cli, 0)) {
3131 for (i=0;i<count;i++) {
3132 api = sys_random() % 500;
3133 param_len = (sys_random() % 64);
3135 rand_buf(param, param_len);
3140 param, param_len, 8,
3141 NULL, 0, BUFFER_SIZE,
3145 printf("%d/%d\r", i,count);
3148 printf("%d/%d\n", i, count);
3150 if (!torture_close_connection(cli)) {
3154 printf("finished random ipc test\n");
3161 static void browse_callback(const char *sname, uint32 stype,
3162 const char *comment, void *state)
3164 printf("\t%20.20s %08x %s\n", sname, stype, comment);
3170 This test checks the browse list code
3173 static bool run_browsetest(int dummy)
3175 static struct cli_state *cli;
3176 bool correct = True;
3178 printf("starting browse test\n");
3180 if (!torture_open_connection(&cli, 0)) {
3184 printf("domain list:\n");
3185 cli_NetServerEnum(cli, cli->server_domain,
3186 SV_TYPE_DOMAIN_ENUM,
3187 browse_callback, NULL);
3189 printf("machine list:\n");
3190 cli_NetServerEnum(cli, cli->server_domain,
3192 browse_callback, NULL);
3194 if (!torture_close_connection(cli)) {
3198 printf("browse test finished\n");
3206 This checks how the getatr calls works
3208 static bool run_attrtest(int dummy)
3210 struct cli_state *cli;
3213 const char *fname = "\\attrib123456789.tst";
3214 bool correct = True;
3217 printf("starting attrib test\n");
3219 if (!torture_open_connection(&cli, 0)) {
3223 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3224 cli_open(cli, fname,
3225 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
3226 cli_close(cli, fnum);
3228 status = cli_getatr(cli, fname, NULL, NULL, &t);
3229 if (!NT_STATUS_IS_OK(status)) {
3230 printf("getatr failed (%s)\n", nt_errstr(status));
3234 if (abs(t - time(NULL)) > 60*60*24*10) {
3235 printf("ERROR: SMBgetatr bug. time is %s",
3241 t2 = t-60*60*24; /* 1 day ago */
3243 status = cli_setatr(cli, fname, 0, t2);
3244 if (!NT_STATUS_IS_OK(status)) {
3245 printf("setatr failed (%s)\n", nt_errstr(status));
3249 status = cli_getatr(cli, fname, NULL, NULL, &t);
3250 if (!NT_STATUS_IS_OK(status)) {
3251 printf("getatr failed (%s)\n", nt_errstr(status));
3256 printf("ERROR: getatr/setatr bug. times are\n%s",
3258 printf("%s", ctime(&t2));
3262 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3264 if (!torture_close_connection(cli)) {
3268 printf("attrib test finished\n");
3275 This checks a couple of trans2 calls
3277 static bool run_trans2test(int dummy)
3279 struct cli_state *cli;
3282 time_t c_time, a_time, m_time;
3283 struct timespec c_time_ts, a_time_ts, m_time_ts, w_time_ts, m_time2_ts;
3284 const char *fname = "\\trans2.tst";
3285 const char *dname = "\\trans2";
3286 const char *fname2 = "\\trans2\\trans2.tst";
3288 bool correct = True;
3292 printf("starting trans2 test\n");
3294 if (!torture_open_connection(&cli, 0)) {
3298 status = cli_get_fs_attr_info(cli, &fs_attr);
3299 if (!NT_STATUS_IS_OK(status)) {
3300 printf("ERROR: cli_get_fs_attr_info returned %s\n",
3305 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3306 cli_open(cli, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
3307 status = cli_qfileinfo_basic(cli, fnum, NULL, &size, &c_time_ts,
3308 &a_time_ts, &w_time_ts, &m_time_ts, NULL);
3309 if (!NT_STATUS_IS_OK(status)) {
3310 printf("ERROR: qfileinfo failed (%s)\n", nt_errstr(status));
3314 status = cli_qfilename(cli, fnum, talloc_tos(), &pname);
3315 if (!NT_STATUS_IS_OK(status)) {
3316 printf("ERROR: qfilename failed (%s)\n", nt_errstr(status));
3320 if (strcmp(pname, fname)) {
3321 printf("qfilename gave different name? [%s] [%s]\n",
3326 cli_close(cli, fnum);
3330 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3331 status = cli_open(cli, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE,
3333 if (!NT_STATUS_IS_OK(status)) {
3334 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
3337 cli_close(cli, fnum);
3339 status = cli_qpathinfo1(cli, fname, &c_time, &a_time, &m_time, &size,
3341 if (!NT_STATUS_IS_OK(status)) {
3342 printf("ERROR: qpathinfo failed (%s)\n", nt_errstr(status));
3345 time_t t = time(NULL);
3347 if (c_time != m_time) {
3348 printf("create time=%s", ctime(&c_time));
3349 printf("modify time=%s", ctime(&m_time));
3350 printf("This system appears to have sticky create times\n");
3352 if ((abs(a_time - t) > 60) && (a_time % (60*60) == 0)) {
3353 printf("access time=%s", ctime(&a_time));
3354 printf("This system appears to set a midnight access time\n");
3358 if (abs(m_time - t) > 60*60*24*7) {
3359 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
3365 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3366 cli_open(cli, fname,
3367 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
3368 cli_close(cli, fnum);
3369 status = cli_qpathinfo2(cli, fname, &c_time_ts, &a_time_ts, &w_time_ts,
3370 &m_time_ts, &size, NULL, NULL);
3371 if (!NT_STATUS_IS_OK(status)) {
3372 printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status));
3375 if (w_time_ts.tv_sec < 60*60*24*2) {
3376 printf("write time=%s", ctime(&w_time_ts.tv_sec));
3377 printf("This system appears to set a initial 0 write time\n");
3382 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3385 /* check if the server updates the directory modification time
3386 when creating a new file */
3387 status = cli_mkdir(cli, dname);
3388 if (!NT_STATUS_IS_OK(status)) {
3389 printf("ERROR: mkdir failed (%s)\n", nt_errstr(status));
3393 status = cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts,
3394 &w_time_ts, &m_time_ts, &size, NULL, NULL);
3395 if (!NT_STATUS_IS_OK(status)) {
3396 printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status));
3400 cli_open(cli, fname2,
3401 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
3402 cli_writeall(cli, fnum, 0, (uint8_t *)&fnum, 0, sizeof(fnum), NULL);
3403 cli_close(cli, fnum);
3404 status = cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts,
3405 &w_time_ts, &m_time2_ts, &size, NULL, NULL);
3406 if (!NT_STATUS_IS_OK(status)) {
3407 printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status));
3410 if (memcmp(&m_time_ts, &m_time2_ts, sizeof(struct timespec))
3412 printf("This system does not update directory modification times\n");
3416 cli_unlink(cli, fname2, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3417 cli_rmdir(cli, dname);
3419 if (!torture_close_connection(cli)) {
3423 printf("trans2 test finished\n");
3429 This checks new W2K calls.
3432 static NTSTATUS new_trans(struct cli_state *pcli, int fnum, int level)
3434 uint8_t *buf = NULL;
3438 status = cli_qfileinfo(talloc_tos(), pcli, fnum, level, 0,
3439 pcli->max_xmit, NULL, &buf, &len);
3440 if (!NT_STATUS_IS_OK(status)) {
3441 printf("ERROR: qfileinfo (%d) failed (%s)\n", level,
3444 printf("qfileinfo: level %d, len = %u\n", level, len);
3445 dump_data(0, (uint8 *)buf, len);
3452 static bool run_w2ktest(int dummy)
3454 struct cli_state *cli;
3456 const char *fname = "\\w2ktest\\w2k.tst";
3458 bool correct = True;
3460 printf("starting w2k test\n");
3462 if (!torture_open_connection(&cli, 0)) {
3466 cli_open(cli, fname,
3467 O_RDWR | O_CREAT , DENY_NONE, &fnum);
3469 for (level = 1004; level < 1040; level++) {
3470 new_trans(cli, fnum, level);
3473 cli_close(cli, fnum);
3475 if (!torture_close_connection(cli)) {
3479 printf("w2k test finished\n");
3486 this is a harness for some oplock tests
3488 static bool run_oplock1(int dummy)
3490 struct cli_state *cli1;
3491 const char *fname = "\\lockt1.lck";
3493 bool correct = True;
3496 printf("starting oplock test 1\n");
3498 if (!torture_open_connection(&cli1, 0)) {
3502 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3504 cli_sockopt(cli1, sockops);
3506 cli1->use_oplocks = True;
3508 status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
3510 if (!NT_STATUS_IS_OK(status)) {
3511 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
3515 cli1->use_oplocks = False;
3517 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3518 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3520 status = cli_close(cli1, fnum1);
3521 if (!NT_STATUS_IS_OK(status)) {
3522 printf("close2 failed (%s)\n", nt_errstr(status));
3526 status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3527 if (!NT_STATUS_IS_OK(status)) {
3528 printf("unlink failed (%s)\n", nt_errstr(status));
3532 if (!torture_close_connection(cli1)) {
3536 printf("finished oplock test 1\n");
3541 static bool run_oplock2(int dummy)
3543 struct cli_state *cli1, *cli2;
3544 const char *fname = "\\lockt2.lck";
3545 uint16_t fnum1, fnum2;
3546 int saved_use_oplocks = use_oplocks;
3548 bool correct = True;
3549 volatile bool *shared_correct;
3553 shared_correct = (volatile bool *)shm_setup(sizeof(bool));
3554 *shared_correct = True;
3556 use_level_II_oplocks = True;
3559 printf("starting oplock test 2\n");
3561 if (!torture_open_connection(&cli1, 0)) {
3562 use_level_II_oplocks = False;
3563 use_oplocks = saved_use_oplocks;
3567 if (!torture_open_connection(&cli2, 1)) {
3568 use_level_II_oplocks = False;
3569 use_oplocks = saved_use_oplocks;
3573 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3575 cli_sockopt(cli1, sockops);
3576 cli_sockopt(cli2, sockops);
3578 status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
3580 if (!NT_STATUS_IS_OK(status)) {
3581 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
3585 /* Don't need the globals any more. */
3586 use_level_II_oplocks = False;
3587 use_oplocks = saved_use_oplocks;
3591 status = cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
3592 if (!NT_STATUS_IS_OK(status)) {
3593 printf("second open of %s failed (%s)\n", fname, nt_errstr(status));
3594 *shared_correct = False;
3600 status = cli_close(cli2, fnum2);
3601 if (!NT_STATUS_IS_OK(status)) {
3602 printf("close2 failed (%s)\n", nt_errstr(status));
3603 *shared_correct = False;
3611 /* Ensure cli1 processes the break. Empty file should always return 0
3613 status = cli_read(cli1, fnum1, buf, 0, 4, &nread);
3614 if (!NT_STATUS_IS_OK(status)) {
3615 printf("read on fnum1 failed (%s)\n", nt_errstr(status));
3617 } else if (nread != 0) {
3618 printf("read on empty fnum1 failed. recv %ld expected %d\n",
3619 (unsigned long)nread, 0);
3623 /* Should now be at level II. */
3624 /* Test if sending a write locks causes a break to none. */
3625 status = cli_lock32(cli1, fnum1, 0, 4, 0, READ_LOCK);
3626 if (!NT_STATUS_IS_OK(status)) {
3627 printf("lock failed (%s)\n", nt_errstr(status));
3631 cli_unlock(cli1, fnum1, 0, 4);
3635 status = cli_lock32(cli1, fnum1, 0, 4, 0, WRITE_LOCK);
3636 if (!NT_STATUS_IS_OK(status)) {
3637 printf("lock failed (%s)\n", nt_errstr(status));
3641 cli_unlock(cli1, fnum1, 0, 4);
3645 cli_read(cli1, fnum1, buf, 0, 4, NULL);
3647 status = cli_close(cli1, fnum1);
3648 if (!NT_STATUS_IS_OK(status)) {
3649 printf("close1 failed (%s)\n", nt_errstr(status));
3655 status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3656 if (!NT_STATUS_IS_OK(status)) {
3657 printf("unlink failed (%s)\n", nt_errstr(status));
3661 if (!torture_close_connection(cli1)) {
3665 if (!*shared_correct) {
3669 printf("finished oplock test 2\n");
3674 struct oplock4_state {
3675 struct tevent_context *ev;
3676 struct cli_state *cli;
3681 static void oplock4_got_break(struct tevent_req *req);
3682 static void oplock4_got_open(struct tevent_req *req);
3684 static bool run_oplock4(int dummy)
3686 struct tevent_context *ev;
3687 struct cli_state *cli1, *cli2;
3688 struct tevent_req *oplock_req, *open_req;
3689 const char *fname = "\\lockt4.lck";
3690 const char *fname_ln = "\\lockt4_ln.lck";
3691 uint16_t fnum1, fnum2;
3692 int saved_use_oplocks = use_oplocks;
3694 bool correct = true;
3698 struct oplock4_state *state;
3700 printf("starting oplock test 4\n");
3702 if (!torture_open_connection(&cli1, 0)) {
3703 use_level_II_oplocks = false;
3704 use_oplocks = saved_use_oplocks;
3708 if (!torture_open_connection(&cli2, 1)) {
3709 use_level_II_oplocks = false;
3710 use_oplocks = saved_use_oplocks;
3714 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3715 cli_unlink(cli1, fname_ln, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3717 cli_sockopt(cli1, sockops);
3718 cli_sockopt(cli2, sockops);
3720 /* Create the file. */
3721 status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
3723 if (!NT_STATUS_IS_OK(status)) {
3724 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
3728 status = cli_close(cli1, fnum1);
3729 if (!NT_STATUS_IS_OK(status)) {
3730 printf("close1 failed (%s)\n", nt_errstr(status));
3734 /* Now create a hardlink. */
3735 status = cli_nt_hardlink(cli1, fname, fname_ln);
3736 if (!NT_STATUS_IS_OK(status)) {
3737 printf("nt hardlink failed (%s)\n", nt_errstr(status));
3741 /* Prove that opening hardlinks cause deny modes to conflict. */
3742 status = cli_open(cli1, fname, O_RDWR, DENY_ALL, &fnum1);
3743 if (!NT_STATUS_IS_OK(status)) {
3744 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
3748 status = cli_open(cli1, fname_ln, O_RDWR, DENY_NONE, &fnum2);
3749 if (NT_STATUS_IS_OK(status)) {
3750 printf("open of %s succeeded - should fail with sharing violation.\n",
3755 if (!NT_STATUS_EQUAL(status, NT_STATUS_SHARING_VIOLATION)) {
3756 printf("open of %s should fail with sharing violation. Got %s\n",
3757 fname_ln, nt_errstr(status));
3761 status = cli_close(cli1, fnum1);
3762 if (!NT_STATUS_IS_OK(status)) {
3763 printf("close1 failed (%s)\n", nt_errstr(status));
3767 cli1->use_oplocks = true;
3768 cli1->use_level_II_oplocks = true;
3770 cli2->use_oplocks = true;
3771 cli2->use_level_II_oplocks = true;
3773 status = cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
3774 if (!NT_STATUS_IS_OK(status)) {
3775 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
3779 ev = tevent_context_init(talloc_tos());
3781 printf("tevent_req_create failed\n");
3785 state = talloc(ev, struct oplock4_state);
3786 if (state == NULL) {
3787 printf("talloc failed\n");
3792 state->got_break = &got_break;
3793 state->fnum2 = &fnum2;
3795 oplock_req = cli_smb_oplock_break_waiter_send(
3796 talloc_tos(), ev, cli1);
3797 if (oplock_req == NULL) {
3798 printf("cli_smb_oplock_break_waiter_send failed\n");
3801 tevent_req_set_callback(oplock_req, oplock4_got_break, state);
3803 open_req = cli_open_send(
3804 talloc_tos(), ev, cli2, fname_ln, O_RDWR, DENY_NONE);
3805 if (oplock_req == NULL) {
3806 printf("cli_open_send failed\n");
3809 tevent_req_set_callback(open_req, oplock4_got_open, state);
3814 while (!got_break || fnum2 == 0xffff) {
3816 ret = tevent_loop_once(ev);
3818 printf("tevent_loop_once failed: %s\n",
3824 status = cli_close(cli2, fnum2);
3825 if (!NT_STATUS_IS_OK(status)) {
3826 printf("close2 failed (%s)\n", nt_errstr(status));
3830 status = cli_close(cli1, fnum1);
3831 if (!NT_STATUS_IS_OK(status)) {
3832 printf("close1 failed (%s)\n", nt_errstr(status));
3836 status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3837 if (!NT_STATUS_IS_OK(status)) {
3838 printf("unlink failed (%s)\n", nt_errstr(status));
3842 status = cli_unlink(cli1, fname_ln, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3843 if (!NT_STATUS_IS_OK(status)) {
3844 printf("unlink failed (%s)\n", nt_errstr(status));
3848 if (!torture_close_connection(cli1)) {
3856 printf("finished oplock test 4\n");
3861 static void oplock4_got_break(struct tevent_req *req)
3863 struct oplock4_state *state = tevent_req_callback_data(
3864 req, struct oplock4_state);
3869 status = cli_smb_oplock_break_waiter_recv(req, &fnum, &level);
3871 if (!NT_STATUS_IS_OK(status)) {
3872 printf("cli_smb_oplock_break_waiter_recv returned %s\n",
3876 *state->got_break = true;
3878 req = cli_oplock_ack_send(state, state->ev, state->cli, fnum,
3881 printf("cli_oplock_ack_send failed\n");
3886 static void oplock4_got_open(struct tevent_req *req)
3888 struct oplock4_state *state = tevent_req_callback_data(
3889 req, struct oplock4_state);
3892 status = cli_open_recv(req, state->fnum2);
3893 if (!NT_STATUS_IS_OK(status)) {
3894 printf("cli_open_recv returned %s\n", nt_errstr(status));
3895 *state->fnum2 = 0xffff;
3900 Test delete on close semantics.
3902 static bool run_deletetest(int dummy)
3904 struct cli_state *cli1 = NULL;
3905 struct cli_state *cli2 = NULL;
3906 const char *fname = "\\delete.file";
3907 uint16_t fnum1 = (uint16_t)-1;
3908 uint16_t fnum2 = (uint16_t)-1;
3909 bool correct = True;
3912 printf("starting delete test\n");
3914 if (!torture_open_connection(&cli1, 0)) {
3918 cli_sockopt(cli1, sockops);
3920 /* Test 1 - this should delete the file on close. */
3922 cli_setatr(cli1, fname, 0, 0);
3923 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3925 status = cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
3926 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
3927 FILE_DELETE_ON_CLOSE, 0, &fnum1);
3928 if (!NT_STATUS_IS_OK(status)) {
3929 printf("[1] open of %s failed (%s)\n", fname, nt_errstr(status));
3934 status = cli_close(cli1, fnum1);
3935 if (!NT_STATUS_IS_OK(status)) {
3936 printf("[1] close failed (%s)\n", nt_errstr(status));
3941 if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1))) {
3942 printf("[1] open of %s succeeded (should fail)\n", fname);
3947 printf("first delete on close test succeeded.\n");
3949 /* Test 2 - this should delete the file on close. */
3951 cli_setatr(cli1, fname, 0, 0);
3952 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3954 status = cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS,
3955 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
3956 FILE_OVERWRITE_IF, 0, 0, &fnum1);
3957 if (!NT_STATUS_IS_OK(status)) {
3958 printf("[2] open of %s failed (%s)\n", fname, nt_errstr(status));
3963 status = cli_nt_delete_on_close(cli1, fnum1, true);
3964 if (!NT_STATUS_IS_OK(status)) {
3965 printf("[2] setting delete_on_close failed (%s)\n", nt_errstr(status));
3970 status = cli_close(cli1, fnum1);
3971 if (!NT_STATUS_IS_OK(status)) {
3972 printf("[2] close failed (%s)\n", nt_errstr(status));
3977 if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
3978 printf("[2] open of %s succeeded should have been deleted on close !\n", fname);
3979 status = cli_close(cli1, fnum1);
3980 if (!NT_STATUS_IS_OK(status)) {
3981 printf("[2] close failed (%s)\n", nt_errstr(status));
3985 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3987 printf("second delete on close test succeeded.\n");
3990 cli_setatr(cli1, fname, 0, 0);
3991 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
3993 status = cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS,
3994 FILE_ATTRIBUTE_NORMAL,
3995 FILE_SHARE_READ|FILE_SHARE_WRITE,
3996 FILE_OVERWRITE_IF, 0, 0, &fnum1);
3997 if (!NT_STATUS_IS_OK(status)) {
3998 printf("[3] open - 1 of %s failed (%s)\n", fname, nt_errstr(status));
4003 /* This should fail with a sharing violation - open for delete is only compatible
4004 with SHARE_DELETE. */
4006 if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
4007 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0, 0, &fnum2))) {
4008 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname);
4013 /* This should succeed. */
4014 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
4015 FILE_ATTRIBUTE_NORMAL,
4016 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4017 FILE_OPEN, 0, 0, &fnum2);
4018 if (!NT_STATUS_IS_OK(status)) {
4019 printf("[3] open - 2 of %s failed (%s)\n", fname, nt_errstr(status));
4024 status = cli_nt_delete_on_close(cli1, fnum1, true);
4025 if (!NT_STATUS_IS_OK(status)) {
4026 printf("[3] setting delete_on_close failed (%s)\n", nt_errstr(status));
4031 status = cli_close(cli1, fnum1);
4032 if (!NT_STATUS_IS_OK(status)) {
4033 printf("[3] close 1 failed (%s)\n", nt_errstr(status));
4038 status = cli_close(cli1, fnum2);
4039 if (!NT_STATUS_IS_OK(status)) {
4040 printf("[3] close 2 failed (%s)\n", nt_errstr(status));
4045 /* This should fail - file should no longer be there. */
4047 if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
4048 printf("[3] open of %s succeeded should have been deleted on close !\n", fname);
4049 status = cli_close(cli1, fnum1);
4050 if (!NT_STATUS_IS_OK(status)) {
4051 printf("[3] close failed (%s)\n", nt_errstr(status));
4053 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4057 printf("third delete on close test succeeded.\n");
4060 cli_setatr(cli1, fname, 0, 0);
4061 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4063 status = cli_ntcreate(cli1, fname, 0,
4064 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
4065 FILE_ATTRIBUTE_NORMAL,
4066 FILE_SHARE_READ|FILE_SHARE_WRITE,
4067 FILE_OVERWRITE_IF, 0, 0, &fnum1);
4068 if (!NT_STATUS_IS_OK(status)) {
4069 printf("[4] open of %s failed (%s)\n", fname, nt_errstr(status));
4074 /* This should succeed. */
4075 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
4076 FILE_ATTRIBUTE_NORMAL,
4077 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4078 FILE_OPEN, 0, 0, &fnum2);
4079 if (!NT_STATUS_IS_OK(status)) {
4080 printf("[4] open - 2 of %s failed (%s)\n", fname, nt_errstr(status));
4085 status = cli_close(cli1, fnum2);
4086 if (!NT_STATUS_IS_OK(status)) {
4087 printf("[4] close - 1 failed (%s)\n", nt_errstr(status));
4092 status = cli_nt_delete_on_close(cli1, fnum1, true);
4093 if (!NT_STATUS_IS_OK(status)) {
4094 printf("[4] setting delete_on_close failed (%s)\n", nt_errstr(status));
4099 /* This should fail - no more opens once delete on close set. */
4100 if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
4101 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4102 FILE_OPEN, 0, 0, &fnum2))) {
4103 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname );
4107 printf("fourth delete on close test succeeded.\n");
4109 status = cli_close(cli1, fnum1);
4110 if (!NT_STATUS_IS_OK(status)) {
4111 printf("[4] close - 2 failed (%s)\n", nt_errstr(status));
4117 cli_setatr(cli1, fname, 0, 0);
4118 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4120 status = cli_open(cli1, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum1);
4121 if (!NT_STATUS_IS_OK(status)) {
4122 printf("[5] open of %s failed (%s)\n", fname, nt_errstr(status));
4127 /* This should fail - only allowed on NT opens with DELETE access. */
4129 if (NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
4130 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
4135 status = cli_close(cli1, fnum1);
4136 if (!NT_STATUS_IS_OK(status)) {
4137 printf("[5] close - 2 failed (%s)\n", nt_errstr(status));
4142 printf("fifth delete on close test succeeded.\n");
4145 cli_setatr(cli1, fname, 0, 0);
4146 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4148 status = cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
4149 FILE_ATTRIBUTE_NORMAL,
4150 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4151 FILE_OVERWRITE_IF, 0, 0, &fnum1);
4152 if (!NT_STATUS_IS_OK(status)) {
4153 printf("[6] open of %s failed (%s)\n", fname,
4159 /* This should fail - only allowed on NT opens with DELETE access. */
4161 if (NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
4162 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
4167 status = cli_close(cli1, fnum1);
4168 if (!NT_STATUS_IS_OK(status)) {
4169 printf("[6] close - 2 failed (%s)\n", nt_errstr(status));
4174 printf("sixth delete on close test succeeded.\n");
4177 cli_setatr(cli1, fname, 0, 0);
4178 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4180 status = cli_ntcreate(cli1, fname, 0,
4181 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
4182 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
4184 if (!NT_STATUS_IS_OK(status)) {
4185 printf("[7] open of %s failed (%s)\n", fname, nt_errstr(status));
4190 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
4191 printf("[7] setting delete_on_close on file failed !\n");
4196 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, false))) {
4197 printf("[7] unsetting delete_on_close on file failed !\n");
4202 status = cli_close(cli1, fnum1);
4203 if (!NT_STATUS_IS_OK(status)) {
4204 printf("[7] close - 2 failed (%s)\n", nt_errstr(status));
4209 /* This next open should succeed - we reset the flag. */
4210 status = cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1);
4211 if (!NT_STATUS_IS_OK(status)) {
4212 printf("[5] open of %s failed (%s)\n", fname, nt_errstr(status));
4217 status = cli_close(cli1, fnum1);
4218 if (!NT_STATUS_IS_OK(status)) {
4219 printf("[7] close - 2 failed (%s)\n", nt_errstr(status));
4224 printf("seventh delete on close test succeeded.\n");
4227 cli_setatr(cli1, fname, 0, 0);
4228 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4230 if (!torture_open_connection(&cli2, 1)) {
4231 printf("[8] failed to open second connection.\n");
4236 cli_sockopt(cli1, sockops);
4238 status = cli_ntcreate(cli1, fname, 0,
4239 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
4240 FILE_ATTRIBUTE_NORMAL,
4241 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4242 FILE_OVERWRITE_IF, 0, 0, &fnum1);
4243 if (!NT_STATUS_IS_OK(status)) {
4244 printf("[8] open 1 of %s failed (%s)\n", fname, nt_errstr(status));
4249 status = cli_ntcreate(cli2, fname, 0,
4250 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
4251 FILE_ATTRIBUTE_NORMAL,
4252 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4253 FILE_OPEN, 0, 0, &fnum2);
4254 if (!NT_STATUS_IS_OK(status)) {
4255 printf("[8] open 2 of %s failed (%s)\n", fname, nt_errstr(status));
4260 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
4261 printf("[8] setting delete_on_close on file failed !\n");
4266 status = cli_close(cli1, fnum1);
4267 if (!NT_STATUS_IS_OK(status)) {
4268 printf("[8] close - 1 failed (%s)\n", nt_errstr(status));
4273 status = cli_close(cli2, fnum2);
4274 if (!NT_STATUS_IS_OK(status)) {
4275 printf("[8] close - 2 failed (%s)\n", nt_errstr(status));
4280 /* This should fail.. */
4281 status = cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1);
4282 if (NT_STATUS_IS_OK(status)) {
4283 printf("[8] open of %s succeeded should have been deleted on close !\n", fname);
4287 printf("eighth delete on close test succeeded.\n");
4289 /* This should fail - we need to set DELETE_ACCESS. */
4290 if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0,FILE_READ_DATA|FILE_WRITE_DATA,
4291 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, 0, &fnum1))) {
4292 printf("[9] open of %s succeeded should have failed!\n", fname);
4297 printf("ninth delete on close test succeeded.\n");
4299 status = cli_ntcreate(cli1, fname, 0,
4300 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
4301 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
4302 FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE,
4304 if (!NT_STATUS_IS_OK(status)) {
4305 printf("[10] open of %s failed (%s)\n", fname, nt_errstr(status));
4310 /* This should delete the file. */
4311 status = cli_close(cli1, fnum1);
4312 if (!NT_STATUS_IS_OK(status)) {
4313 printf("[10] close failed (%s)\n", nt_errstr(status));
4318 /* This should fail.. */
4319 if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
4320 printf("[10] open of %s succeeded should have been deleted on close !\n", fname);
4324 printf("tenth delete on close test succeeded.\n");
4326 cli_setatr(cli1, fname, 0, 0);
4327 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4329 /* What error do we get when attempting to open a read-only file with
4332 /* Create a readonly file. */
4333 status = cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
4334 FILE_ATTRIBUTE_READONLY, FILE_SHARE_NONE,
4335 FILE_OVERWRITE_IF, 0, 0, &fnum1);
4336 if (!NT_STATUS_IS_OK(status)) {
4337 printf("[11] open of %s failed (%s)\n", fname, nt_errstr(status));
4342 status = cli_close(cli1, fnum1);
4343 if (!NT_STATUS_IS_OK(status)) {
4344 printf("[11] close failed (%s)\n", nt_errstr(status));
4349 /* Now try open for delete access. */
4350 if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES|DELETE_ACCESS,
4351 0, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4352 FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
4353 printf("[11] open of %s succeeded should have been denied with ACCESS_DENIED!\n", fname);
4354 cli_close(cli1, fnum1);
4358 NTSTATUS nterr = cli_nt_error(cli1);
4359 if (!NT_STATUS_EQUAL(nterr,NT_STATUS_ACCESS_DENIED)) {
4360 printf("[11] open of %s should have been denied with ACCESS_DENIED! Got error %s\n", fname, nt_errstr(nterr));
4364 printf("eleventh delete on close test succeeded.\n");
4368 printf("finished delete test\n");
4371 /* FIXME: This will crash if we aborted before cli2 got
4372 * intialized, because these functions don't handle
4373 * uninitialized connections. */
4375 if (fnum1 != (uint16_t)-1) cli_close(cli1, fnum1);
4376 if (fnum2 != (uint16_t)-1) cli_close(cli1, fnum2);
4377 cli_setatr(cli1, fname, 0, 0);
4378 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4380 if (cli1 && !torture_close_connection(cli1)) {
4383 if (cli2 && !torture_close_connection(cli2)) {
4389 static bool run_deletetest_ln(int dummy)
4391 struct cli_state *cli;
4392 const char *fname = "\\delete1";
4393 const char *fname_ln = "\\delete1_ln";
4397 bool correct = true;
4400 printf("starting deletetest-ln\n");
4402 if (!torture_open_connection(&cli, 0)) {
4406 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4407 cli_unlink(cli, fname_ln, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4409 cli_sockopt(cli, sockops);
4411 /* Create the file. */
4412 status = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
4413 if (!NT_STATUS_IS_OK(status)) {
4414 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
4418 status = cli_close(cli, fnum);
4419 if (!NT_STATUS_IS_OK(status)) {
4420 printf("close1 failed (%s)\n", nt_errstr(status));
4424 /* Now create a hardlink. */
4425 status = cli_nt_hardlink(cli, fname, fname_ln);
4426 if (!NT_STATUS_IS_OK(status)) {
4427 printf("nt hardlink failed (%s)\n", nt_errstr(status));
4431 /* Open the original file. */
4432 status = cli_ntcreate(cli, fname, 0, FILE_READ_DATA,
4433 FILE_ATTRIBUTE_NORMAL,
4434 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4435 FILE_OPEN_IF, 0, 0, &fnum);
4436 if (!NT_STATUS_IS_OK(status)) {
4437 printf("ntcreate of %s failed (%s)\n", fname, nt_errstr(status));
4441 /* Unlink the hard link path. */
4442 status = cli_ntcreate(cli, fname_ln, 0, DELETE_ACCESS,
4443 FILE_ATTRIBUTE_NORMAL,
4444 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4445 FILE_OPEN_IF, 0, 0, &fnum1);
4446 if (!NT_STATUS_IS_OK(status)) {
4447 printf("ntcreate of %s failed (%s)\n", fname_ln, nt_errstr(status));
4450 status = cli_nt_delete_on_close(cli, fnum1, true);
4451 if (!NT_STATUS_IS_OK(status)) {
4452 d_printf("(%s) failed to set delete_on_close %s: %s\n",
4453 __location__, fname_ln, nt_errstr(status));
4457 status = cli_close(cli, fnum1);
4458 if (!NT_STATUS_IS_OK(status)) {
4459 printf("close %s failed (%s)\n",
4460 fname_ln, nt_errstr(status));
4464 status = cli_close(cli, fnum);
4465 if (!NT_STATUS_IS_OK(status)) {
4466 printf("close %s failed (%s)\n",
4467 fname, nt_errstr(status));
4471 /* Ensure the original file is still there. */
4472 status = cli_getatr(cli, fname, NULL, NULL, &t);
4473 if (!NT_STATUS_IS_OK(status)) {
4474 printf("%s getatr on file %s failed (%s)\n",
4481 /* Ensure the link path is gone. */
4482 status = cli_getatr(cli, fname_ln, NULL, NULL, &t);
4483 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
4484 printf("%s, getatr for file %s returned wrong error code %s "
4485 "- should have been deleted\n",
4487 fname_ln, nt_errstr(status));
4491 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4492 cli_unlink(cli, fname_ln, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4494 if (!torture_close_connection(cli)) {
4498 printf("finished deletetest-ln\n");
4504 print out server properties
4506 static bool run_properties(int dummy)
4508 struct cli_state *cli;
4509 bool correct = True;
4511 printf("starting properties test\n");
4515 if (!torture_open_connection(&cli, 0)) {
4519 cli_sockopt(cli, sockops);
4521 d_printf("Capabilities 0x%08x\n", cli_state_capabilities(cli));
4523 if (!torture_close_connection(cli)) {
4532 /* FIRST_DESIRED_ACCESS 0xf019f */
4533 #define FIRST_DESIRED_ACCESS FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|\
4534 FILE_READ_EA| /* 0xf */ \
4535 FILE_WRITE_EA|FILE_READ_ATTRIBUTES| /* 0x90 */ \
4536 FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
4537 DELETE_ACCESS|READ_CONTROL_ACCESS|\
4538 WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS /* 0xf0000 */
4539 /* SECOND_DESIRED_ACCESS 0xe0080 */
4540 #define SECOND_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
4541 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
4542 WRITE_OWNER_ACCESS /* 0xe0000 */
4545 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
4546 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
4548 WRITE_OWNER_ACCESS /* */
4552 Test ntcreate calls made by xcopy
4554 static bool run_xcopy(int dummy)
4556 static struct cli_state *cli1;
4557 const char *fname = "\\test.txt";
4558 bool correct = True;
4559 uint16_t fnum1, fnum2;
4562 printf("starting xcopy test\n");
4564 if (!torture_open_connection(&cli1, 0)) {
4568 status = cli_ntcreate(cli1, fname, 0, FIRST_DESIRED_ACCESS,
4569 FILE_ATTRIBUTE_ARCHIVE, FILE_SHARE_NONE,
4570 FILE_OVERWRITE_IF, 0x4044, 0, &fnum1);
4571 if (!NT_STATUS_IS_OK(status)) {
4572 printf("First open failed - %s\n", nt_errstr(status));
4576 status = cli_ntcreate(cli1, fname, 0, SECOND_DESIRED_ACCESS, 0,
4577 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
4578 FILE_OPEN, 0x200000, 0, &fnum2);
4579 if (!NT_STATUS_IS_OK(status)) {
4580 printf("second open failed - %s\n", nt_errstr(status));
4584 if (!torture_close_connection(cli1)) {
4592 Test rename on files open with share delete and no share delete.
4594 static bool run_rename(int dummy)
4596 static struct cli_state *cli1;
4597 const char *fname = "\\test.txt";
4598 const char *fname1 = "\\test1.txt";
4599 bool correct = True;
4604 printf("starting rename test\n");
4606 if (!torture_open_connection(&cli1, 0)) {
4610 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4611 cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4613 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
4614 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ,
4615 FILE_OVERWRITE_IF, 0, 0, &fnum1);
4616 if (!NT_STATUS_IS_OK(status)) {
4617 printf("First open failed - %s\n", nt_errstr(status));
4621 status = cli_rename(cli1, fname, fname1);
4622 if (!NT_STATUS_IS_OK(status)) {
4623 printf("First rename failed (SHARE_READ) (this is correct) - %s\n", nt_errstr(status));
4625 printf("First rename succeeded (SHARE_READ) - this should have failed !\n");
4629 status = cli_close(cli1, fnum1);
4630 if (!NT_STATUS_IS_OK(status)) {
4631 printf("close - 1 failed (%s)\n", nt_errstr(status));
4635 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4636 cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4637 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
4639 FILE_SHARE_DELETE|FILE_SHARE_NONE,
4641 FILE_SHARE_DELETE|FILE_SHARE_READ,
4643 FILE_OVERWRITE_IF, 0, 0, &fnum1);
4644 if (!NT_STATUS_IS_OK(status)) {
4645 printf("Second open failed - %s\n", nt_errstr(status));
4649 status = cli_rename(cli1, fname, fname1);
4650 if (!NT_STATUS_IS_OK(status)) {
4651 printf("Second rename failed (SHARE_DELETE | SHARE_READ) - this should have succeeded - %s\n", nt_errstr(status));
4654 printf("Second rename succeeded (SHARE_DELETE | SHARE_READ)\n");
4657 status = cli_close(cli1, fnum1);
4658 if (!NT_STATUS_IS_OK(status)) {
4659 printf("close - 2 failed (%s)\n", nt_errstr(status));
4663 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4664 cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4666 status = cli_ntcreate(cli1, fname, 0, READ_CONTROL_ACCESS,
4667 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
4668 FILE_OVERWRITE_IF, 0, 0, &fnum1);
4669 if (!NT_STATUS_IS_OK(status)) {
4670 printf("Third open failed - %s\n", nt_errstr(status));
4679 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
4680 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum2))) {
4681 printf("Fourth open failed - %s\n", cli_errstr(cli1));
4684 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum2, true))) {
4685 printf("[8] setting delete_on_close on file failed !\n");
4689 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum2))) {
4690 printf("close - 4 failed (%s)\n", cli_errstr(cli1));
4696 status = cli_rename(cli1, fname, fname1);
4697 if (!NT_STATUS_IS_OK(status)) {
4698 printf("Third rename failed (SHARE_NONE) - this should have succeeded - %s\n", nt_errstr(status));
4701 printf("Third rename succeeded (SHARE_NONE)\n");
4704 status = cli_close(cli1, fnum1);
4705 if (!NT_STATUS_IS_OK(status)) {
4706 printf("close - 3 failed (%s)\n", nt_errstr(status));
4710 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4711 cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4715 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
4716 FILE_ATTRIBUTE_NORMAL,
4717 FILE_SHARE_READ | FILE_SHARE_WRITE,
4718 FILE_OVERWRITE_IF, 0, 0, &fnum1);
4719 if (!NT_STATUS_IS_OK(status)) {
4720 printf("Fourth open failed - %s\n", nt_errstr(status));
4724 status = cli_rename(cli1, fname, fname1);
4725 if (!NT_STATUS_IS_OK(status)) {
4726 printf("Fourth rename failed (SHARE_READ | SHARE_WRITE) (this is correct) - %s\n", nt_errstr(status));
4728 printf("Fourth rename succeeded (SHARE_READ | SHARE_WRITE) - this should have failed !\n");
4732 status = cli_close(cli1, fnum1);
4733 if (!NT_STATUS_IS_OK(status)) {
4734 printf("close - 4 failed (%s)\n", nt_errstr(status));
4738 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4739 cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4743 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
4744 FILE_ATTRIBUTE_NORMAL,
4745 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
4746 FILE_OVERWRITE_IF, 0, 0, &fnum1);
4747 if (!NT_STATUS_IS_OK(status)) {
4748 printf("Fifth open failed - %s\n", nt_errstr(status));
4752 status = cli_rename(cli1, fname, fname1);
4753 if (!NT_STATUS_IS_OK(status)) {
4754 printf("Fifth rename failed (SHARE_READ | SHARE_WRITE | SHARE_DELETE) - this should have succeeded - %s ! \n", nt_errstr(status));
4757 printf("Fifth rename succeeded (SHARE_READ | SHARE_WRITE | SHARE_DELETE) (this is correct) - %s\n", nt_errstr(status));
4761 * Now check if the first name still exists ...
4764 /* if (!NT_STATUS_OP(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
4765 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0, &fnum2))) {
4766 printf("Opening original file after rename of open file fails: %s\n",
4770 printf("Opening original file after rename of open file works ...\n");
4771 (void)cli_close(cli1, fnum2);
4775 status = cli_close(cli1, fnum1);
4776 if (!NT_STATUS_IS_OK(status)) {
4777 printf("close - 5 failed (%s)\n", nt_errstr(status));
4781 /* Check that the renamed file has FILE_ATTRIBUTE_ARCHIVE. */
4782 status = cli_getatr(cli1, fname1, &attr, NULL, NULL);
4783 if (!NT_STATUS_IS_OK(status)) {
4784 printf("getatr on file %s failed - %s ! \n",
4785 fname1, nt_errstr(status));
4788 if (attr != FILE_ATTRIBUTE_ARCHIVE) {
4789 printf("Renamed file %s has wrong attr 0x%x "
4790 "(should be 0x%x)\n",
4793 (unsigned int)FILE_ATTRIBUTE_ARCHIVE);
4796 printf("Renamed file %s has archive bit set\n", fname1);
4800 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4801 cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4803 if (!torture_close_connection(cli1)) {
4810 static bool run_pipe_number(int dummy)
4812 struct cli_state *cli1;
4813 const char *pipe_name = "\\SPOOLSS";
4818 printf("starting pipenumber test\n");
4819 if (!torture_open_connection(&cli1, 0)) {
4823 cli_sockopt(cli1, sockops);
4825 status = cli_ntcreate(cli1, pipe_name, 0, FILE_READ_DATA,
4826 FILE_ATTRIBUTE_NORMAL,
4827 FILE_SHARE_READ|FILE_SHARE_WRITE,
4828 FILE_OPEN_IF, 0, 0, &fnum);
4829 if (!NT_STATUS_IS_OK(status)) {
4830 printf("Open of pipe %s failed with error (%s)\n", pipe_name, nt_errstr(status));
4834 printf("\r%6d", num_pipes);
4837 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes, pipe_name );
4838 torture_close_connection(cli1);
4843 Test open mode returns on read-only files.
4845 static bool run_opentest(int dummy)
4847 static struct cli_state *cli1;
4848 static struct cli_state *cli2;
4849 const char *fname = "\\readonly.file";
4850 uint16_t fnum1, fnum2;
4853 bool correct = True;
4857 printf("starting open test\n");
4859 if (!torture_open_connection(&cli1, 0)) {
4863 cli_setatr(cli1, fname, 0, 0);
4864 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4866 cli_sockopt(cli1, sockops);
4868 status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
4869 if (!NT_STATUS_IS_OK(status)) {
4870 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
4874 status = cli_close(cli1, fnum1);
4875 if (!NT_STATUS_IS_OK(status)) {
4876 printf("close2 failed (%s)\n", nt_errstr(status));
4880 status = cli_setatr(cli1, fname, FILE_ATTRIBUTE_READONLY, 0);
4881 if (!NT_STATUS_IS_OK(status)) {
4882 printf("cli_setatr failed (%s)\n", nt_errstr(status));
4886 status = cli_open(cli1, fname, O_RDONLY, DENY_WRITE, &fnum1);
4887 if (!NT_STATUS_IS_OK(status)) {
4888 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
4892 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
4893 status = cli_open(cli1, fname, O_RDWR, DENY_ALL, &fnum2);
4895 if (check_error(__LINE__, status, ERRDOS, ERRnoaccess,
4896 NT_STATUS_ACCESS_DENIED)) {
4897 printf("correct error code ERRDOS/ERRnoaccess returned\n");
4900 printf("finished open test 1\n");
4902 cli_close(cli1, fnum1);
4904 /* Now try not readonly and ensure ERRbadshare is returned. */
4906 cli_setatr(cli1, fname, 0, 0);
4908 status = cli_open(cli1, fname, O_RDONLY, DENY_WRITE, &fnum1);
4909 if (!NT_STATUS_IS_OK(status)) {
4910 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
4914 /* This will fail - but the error should be ERRshare. */
4915 status = cli_open(cli1, fname, O_RDWR, DENY_ALL, &fnum2);
4917 if (check_error(__LINE__, status, ERRDOS, ERRbadshare,
4918 NT_STATUS_SHARING_VIOLATION)) {
4919 printf("correct error code ERRDOS/ERRbadshare returned\n");
4922 status = cli_close(cli1, fnum1);
4923 if (!NT_STATUS_IS_OK(status)) {
4924 printf("close2 failed (%s)\n", nt_errstr(status));
4928 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4930 printf("finished open test 2\n");
4932 /* Test truncate open disposition on file opened for read. */
4933 status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
4934 if (!NT_STATUS_IS_OK(status)) {
4935 printf("(3) open (1) of %s failed (%s)\n", fname, nt_errstr(status));
4939 /* write 20 bytes. */
4941 memset(buf, '\0', 20);
4943 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 0, 20, NULL);
4944 if (!NT_STATUS_IS_OK(status)) {
4945 printf("write failed (%s)\n", nt_errstr(status));
4949 status = cli_close(cli1, fnum1);
4950 if (!NT_STATUS_IS_OK(status)) {
4951 printf("(3) close1 failed (%s)\n", nt_errstr(status));
4955 /* Ensure size == 20. */
4956 status = cli_getatr(cli1, fname, NULL, &fsize, NULL);
4957 if (!NT_STATUS_IS_OK(status)) {
4958 printf("(3) getatr failed (%s)\n", nt_errstr(status));
4963 printf("(3) file size != 20\n");
4967 /* Now test if we can truncate a file opened for readonly. */
4968 status = cli_open(cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE, &fnum1);
4969 if (!NT_STATUS_IS_OK(status)) {
4970 printf("(3) open (2) of %s failed (%s)\n", fname, nt_errstr(status));
4974 status = cli_close(cli1, fnum1);
4975 if (!NT_STATUS_IS_OK(status)) {
4976 printf("close2 failed (%s)\n", nt_errstr(status));
4980 /* Ensure size == 0. */
4981 status = cli_getatr(cli1, fname, NULL, &fsize, NULL);
4982 if (!NT_STATUS_IS_OK(status)) {
4983 printf("(3) getatr failed (%s)\n", nt_errstr(status));
4988 printf("(3) file size != 0\n");
4991 printf("finished open test 3\n");
4993 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
4995 printf("Do ctemp tests\n");
4996 status = cli_ctemp(cli1, talloc_tos(), "\\", &fnum1, &tmp_path);
4997 if (!NT_STATUS_IS_OK(status)) {
4998 printf("ctemp failed (%s)\n", nt_errstr(status));
5002 printf("ctemp gave path %s\n", tmp_path);
5003 status = cli_close(cli1, fnum1);
5004 if (!NT_STATUS_IS_OK(status)) {
5005 printf("close of temp failed (%s)\n", nt_errstr(status));
5008 status = cli_unlink(cli1, tmp_path, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5009 if (!NT_STATUS_IS_OK(status)) {
5010 printf("unlink of temp failed (%s)\n", nt_errstr(status));
5013 /* Test the non-io opens... */
5015 if (!torture_open_connection(&cli2, 1)) {
5019 cli_setatr(cli2, fname, 0, 0);
5020 cli_unlink(cli2, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5022 cli_sockopt(cli2, sockops);
5024 printf("TEST #1 testing 2 non-io opens (no delete)\n");
5025 status = cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES,
5026 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5027 FILE_OVERWRITE_IF, 0, 0, &fnum1);
5028 if (!NT_STATUS_IS_OK(status)) {
5029 printf("TEST #1 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
5033 status = cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES,
5034 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5035 FILE_OPEN_IF, 0, 0, &fnum2);
5036 if (!NT_STATUS_IS_OK(status)) {
5037 printf("TEST #1 open 2 of %s failed (%s)\n", fname, nt_errstr(status));
5041 status = cli_close(cli1, fnum1);
5042 if (!NT_STATUS_IS_OK(status)) {
5043 printf("TEST #1 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
5047 status = cli_close(cli2, fnum2);
5048 if (!NT_STATUS_IS_OK(status)) {
5049 printf("TEST #1 close 2 of %s failed (%s)\n", fname, nt_errstr(status));
5053 printf("non-io open test #1 passed.\n");
5055 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5057 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
5059 status = cli_ntcreate(cli1, fname, 0,
5060 DELETE_ACCESS|FILE_READ_ATTRIBUTES,
5061 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5062 FILE_OVERWRITE_IF, 0, 0, &fnum1);
5063 if (!NT_STATUS_IS_OK(status)) {
5064 printf("TEST #2 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
5068 status = cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES,
5069 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5070 FILE_OPEN_IF, 0, 0, &fnum2);
5071 if (!NT_STATUS_IS_OK(status)) {
5072 printf("TEST #2 open 2 of %s failed (%s)\n", fname, nt_errstr(status));
5076 status = cli_close(cli1, fnum1);
5077 if (!NT_STATUS_IS_OK(status)) {
5078 printf("TEST #2 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
5082 status = cli_close(cli2, fnum2);
5083 if (!NT_STATUS_IS_OK(status)) {
5084 printf("TEST #2 close 2 of %s failed (%s)\n", fname, nt_errstr(status));
5088 printf("non-io open test #2 passed.\n");
5090 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5092 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
5094 status = cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES,
5095 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5096 FILE_OVERWRITE_IF, 0, 0, &fnum1);
5097 if (!NT_STATUS_IS_OK(status)) {
5098 printf("TEST #3 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
5102 status = cli_ntcreate(cli2, fname, 0,
5103 DELETE_ACCESS|FILE_READ_ATTRIBUTES,
5104 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5105 FILE_OPEN_IF, 0, 0, &fnum2);
5106 if (!NT_STATUS_IS_OK(status)) {
5107 printf("TEST #3 open 2 of %s failed (%s)\n", fname, nt_errstr(status));
5111 status = cli_close(cli1, fnum1);
5112 if (!NT_STATUS_IS_OK(status)) {
5113 printf("TEST #3 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
5117 status = cli_close(cli2, fnum2);
5118 if (!NT_STATUS_IS_OK(status)) {
5119 printf("TEST #3 close 2 of %s failed (%s)\n", fname, nt_errstr(status));
5123 printf("non-io open test #3 passed.\n");
5125 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5127 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
5129 status = cli_ntcreate(cli1, fname, 0,
5130 DELETE_ACCESS|FILE_READ_ATTRIBUTES,
5131 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5132 FILE_OVERWRITE_IF, 0, 0, &fnum1);
5133 if (!NT_STATUS_IS_OK(status)) {
5134 printf("TEST #4 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
5138 status = cli_ntcreate(cli2, fname, 0,
5139 DELETE_ACCESS|FILE_READ_ATTRIBUTES,
5140 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5141 FILE_OPEN_IF, 0, 0, &fnum2);
5142 if (NT_STATUS_IS_OK(status)) {
5143 printf("TEST #4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, nt_errstr(status));
5147 printf("TEST #4 open 2 of %s gave %s (correct error should be %s)\n", fname, nt_errstr(status), "sharing violation");
5149 status = cli_close(cli1, fnum1);
5150 if (!NT_STATUS_IS_OK(status)) {
5151 printf("TEST #4 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
5155 printf("non-io open test #4 passed.\n");
5157 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5159 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
5161 status = cli_ntcreate(cli1, fname, 0,
5162 DELETE_ACCESS|FILE_READ_ATTRIBUTES,
5163 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_DELETE,
5164 FILE_OVERWRITE_IF, 0, 0, &fnum1);
5165 if (!NT_STATUS_IS_OK(status)) {
5166 printf("TEST #5 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
5170 status = cli_ntcreate(cli2, fname, 0,
5171 DELETE_ACCESS|FILE_READ_ATTRIBUTES,
5172 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_DELETE,
5173 FILE_OPEN_IF, 0, 0, &fnum2);
5174 if (!NT_STATUS_IS_OK(status)) {
5175 printf("TEST #5 open 2 of %s failed (%s)\n", fname, nt_errstr(status));
5179 status = cli_close(cli1, fnum1);
5180 if (!NT_STATUS_IS_OK(status)) {
5181 printf("TEST #5 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
5185 status = cli_close(cli2, fnum2);
5186 if (!NT_STATUS_IS_OK(status)) {
5187 printf("TEST #5 close 2 of %s failed (%s)\n", fname, nt_errstr(status));
5191 printf("non-io open test #5 passed.\n");
5193 printf("TEST #6 testing 1 non-io open, one io open\n");
5195 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5197 status = cli_ntcreate(cli1, fname, 0, FILE_READ_DATA,
5198 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5199 FILE_OVERWRITE_IF, 0, 0, &fnum1);
5200 if (!NT_STATUS_IS_OK(status)) {
5201 printf("TEST #6 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
5205 status = cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES,
5206 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ,
5207 FILE_OPEN_IF, 0, 0, &fnum2);
5208 if (!NT_STATUS_IS_OK(status)) {
5209 printf("TEST #6 open 2 of %s failed (%s)\n", fname, nt_errstr(status));
5213 status = cli_close(cli1, fnum1);
5214 if (!NT_STATUS_IS_OK(status)) {
5215 printf("TEST #6 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
5219 status = cli_close(cli2, fnum2);
5220 if (!NT_STATUS_IS_OK(status)) {
5221 printf("TEST #6 close 2 of %s failed (%s)\n", fname, nt_errstr(status));
5225 printf("non-io open test #6 passed.\n");
5227 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
5229 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5231 status = cli_ntcreate(cli1, fname, 0, FILE_READ_DATA,
5232 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
5233 FILE_OVERWRITE_IF, 0, 0, &fnum1);
5234 if (!NT_STATUS_IS_OK(status)) {
5235 printf("TEST #7 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
5239 status = cli_ntcreate(cli2, fname, 0,
5240 DELETE_ACCESS|FILE_READ_ATTRIBUTES,
5241 FILE_ATTRIBUTE_NORMAL,
5242 FILE_SHARE_READ|FILE_SHARE_DELETE,
5243 FILE_OPEN_IF, 0, 0, &fnum2);
5244 if (NT_STATUS_IS_OK(status)) {
5245 printf("TEST #7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, nt_errstr(status));
5249 printf("TEST #7 open 2 of %s gave %s (correct error should be %s)\n", fname, nt_errstr(status), "sharing violation");
5251 status = cli_close(cli1, fnum1);
5252 if (!NT_STATUS_IS_OK(status)) {
5253 printf("TEST #7 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
5257 printf("non-io open test #7 passed.\n");
5259 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5261 printf("TEST #8 testing open without WRITE_ATTRIBUTES, updating close write time.\n");
5262 status = cli_ntcreate(cli1, fname, 0, FILE_WRITE_DATA, FILE_ATTRIBUTE_NORMAL,
5263 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
5264 FILE_OVERWRITE_IF, 0, 0, &fnum1);
5265 if (!NT_STATUS_IS_OK(status)) {
5266 printf("TEST #8 open of %s failed (%s)\n", fname, nt_errstr(status));
5271 /* Write to ensure we have to update the file time. */
5272 status = cli_writeall(cli1, fnum1, 0, (const uint8_t *)"TEST DATA\n", 0, 10,
5274 if (!NT_STATUS_IS_OK(status)) {
5275 printf("TEST #8 cli_write failed: %s\n", nt_errstr(status));
5280 status = cli_close(cli1, fnum1);
5281 if (!NT_STATUS_IS_OK(status)) {
5282 printf("TEST #8 close of %s failed (%s)\n", fname, nt_errstr(status));
5288 if (!torture_close_connection(cli1)) {
5291 if (!torture_close_connection(cli2)) {
5298 NTSTATUS torture_setup_unix_extensions(struct cli_state *cli)
5300 uint16 major, minor;
5301 uint32 caplow, caphigh;
5304 if (!SERVER_HAS_UNIX_CIFS(cli)) {
5305 printf("Server doesn't support UNIX CIFS extensions.\n");
5306 return NT_STATUS_NOT_SUPPORTED;
5309 status = cli_unix_extensions_version(cli, &major, &minor, &caplow,
5311 if (!NT_STATUS_IS_OK(status)) {
5312 printf("Server didn't return UNIX CIFS extensions: %s\n",
5317 status = cli_set_unix_extensions_capabilities(cli, major, minor,
5319 if (!NT_STATUS_IS_OK(status)) {
5320 printf("Server doesn't support setting UNIX CIFS extensions: "
5321 "%s.\n", nt_errstr(status));
5325 return NT_STATUS_OK;
5329 Test POSIX open /mkdir calls.
5331 static bool run_simple_posix_open_test(int dummy)
5333 static struct cli_state *cli1;
5334 const char *fname = "posix:file";
5335 const char *hname = "posix:hlink";
5336 const char *sname = "posix:symlink";
5337 const char *dname = "posix:dir";
5340 uint16_t fnum1 = (uint16_t)-1;
5341 SMB_STRUCT_STAT sbuf;
5342 bool correct = false;
5346 printf("Starting simple POSIX open test\n");
5348 if (!torture_open_connection(&cli1, 0)) {
5352 cli_sockopt(cli1, sockops);
5354 status = torture_setup_unix_extensions(cli1);
5355 if (!NT_STATUS_IS_OK(status)) {
5359 cli_setatr(cli1, fname, 0, 0);
5360 cli_posix_unlink(cli1, fname);
5361 cli_setatr(cli1, dname, 0, 0);
5362 cli_posix_rmdir(cli1, dname);
5363 cli_setatr(cli1, hname, 0, 0);
5364 cli_posix_unlink(cli1, hname);
5365 cli_setatr(cli1, sname, 0, 0);
5366 cli_posix_unlink(cli1, sname);
5368 /* Create a directory. */
5369 status = cli_posix_mkdir(cli1, dname, 0777);
5370 if (!NT_STATUS_IS_OK(status)) {
5371 printf("POSIX mkdir of %s failed (%s)\n", dname, nt_errstr(status));
5375 status = cli_posix_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL,
5377 if (!NT_STATUS_IS_OK(status)) {
5378 printf("POSIX create of %s failed (%s)\n", fname, nt_errstr(status));
5382 /* Test ftruncate - set file size. */
5383 status = cli_ftruncate(cli1, fnum1, 1000);
5384 if (!NT_STATUS_IS_OK(status)) {
5385 printf("ftruncate failed (%s)\n", nt_errstr(status));
5389 /* Ensure st_size == 1000 */
5390 status = cli_posix_stat(cli1, fname, &sbuf);
5391 if (!NT_STATUS_IS_OK(status)) {
5392 printf("stat failed (%s)\n", nt_errstr(status));
5396 if (sbuf.st_ex_size != 1000) {
5397 printf("ftruncate - stat size (%u) != 1000\n", (unsigned int)sbuf.st_ex_size);
5401 /* Test ftruncate - set file size back to zero. */
5402 status = cli_ftruncate(cli1, fnum1, 0);
5403 if (!NT_STATUS_IS_OK(status)) {
5404 printf("ftruncate failed (%s)\n", nt_errstr(status));
5408 status = cli_close(cli1, fnum1);
5409 if (!NT_STATUS_IS_OK(status)) {
5410 printf("close failed (%s)\n", nt_errstr(status));
5414 /* Now open the file again for read only. */
5415 status = cli_posix_open(cli1, fname, O_RDONLY, 0, &fnum1);
5416 if (!NT_STATUS_IS_OK(status)) {
5417 printf("POSIX open of %s failed (%s)\n", fname, nt_errstr(status));
5421 /* Now unlink while open. */
5422 status = cli_posix_unlink(cli1, fname);
5423 if (!NT_STATUS_IS_OK(status)) {
5424 printf("POSIX unlink of %s failed (%s)\n", fname, nt_errstr(status));
5428 status = cli_close(cli1, fnum1);
5429 if (!NT_STATUS_IS_OK(status)) {
5430 printf("close(2) failed (%s)\n", nt_errstr(status));
5434 /* Ensure the file has gone. */
5435 status = cli_posix_open(cli1, fname, O_RDONLY, 0, &fnum1);
5436 if (NT_STATUS_IS_OK(status)) {
5437 printf("POSIX open of %s succeeded, should have been deleted.\n", fname);
5441 /* Create again to test open with O_TRUNC. */
5442 status = cli_posix_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, 0600, &fnum1);
5443 if (!NT_STATUS_IS_OK(status)) {
5444 printf("POSIX create of %s failed (%s)\n", fname, nt_errstr(status));
5448 /* Test ftruncate - set file size. */
5449 status = cli_ftruncate(cli1, fnum1, 1000);
5450 if (!NT_STATUS_IS_OK(status)) {
5451 printf("ftruncate failed (%s)\n", nt_errstr(status));
5455 /* Ensure st_size == 1000 */
5456 status = cli_posix_stat(cli1, fname, &sbuf);
5457 if (!NT_STATUS_IS_OK(status)) {
5458 printf("stat failed (%s)\n", nt_errstr(status));
5462 if (sbuf.st_ex_size != 1000) {
5463 printf("ftruncate - stat size (%u) != 1000\n", (unsigned int)sbuf.st_ex_size);
5467 status = cli_close(cli1, fnum1);
5468 if (!NT_STATUS_IS_OK(status)) {
5469 printf("close(2) failed (%s)\n", nt_errstr(status));
5473 /* Re-open with O_TRUNC. */
5474 status = cli_posix_open(cli1, fname, O_WRONLY|O_TRUNC, 0600, &fnum1);
5475 if (!NT_STATUS_IS_OK(status)) {
5476 printf("POSIX create of %s failed (%s)\n", fname, nt_errstr(status));
5480 /* Ensure st_size == 0 */
5481 status = cli_posix_stat(cli1, fname, &sbuf);
5482 if (!NT_STATUS_IS_OK(status)) {
5483 printf("stat failed (%s)\n", nt_errstr(status));
5487 if (sbuf.st_ex_size != 0) {
5488 printf("O_TRUNC - stat size (%u) != 0\n", (unsigned int)sbuf.st_ex_size);
5492 status = cli_close(cli1, fnum1);
5493 if (!NT_STATUS_IS_OK(status)) {
5494 printf("close failed (%s)\n", nt_errstr(status));
5498 status = cli_posix_unlink(cli1, fname);
5499 if (!NT_STATUS_IS_OK(status)) {
5500 printf("POSIX unlink of %s failed (%s)\n", fname, nt_errstr(status));
5504 status = cli_posix_open(cli1, dname, O_RDONLY, 0, &fnum1);
5505 if (!NT_STATUS_IS_OK(status)) {
5506 printf("POSIX open directory O_RDONLY of %s failed (%s)\n",
5507 dname, nt_errstr(status));
5511 cli_close(cli1, fnum1);
5513 /* What happens when we try and POSIX open a directory for write ? */
5514 status = cli_posix_open(cli1, dname, O_RDWR, 0, &fnum1);
5515 if (NT_STATUS_IS_OK(status)) {
5516 printf("POSIX open of directory %s succeeded, should have failed.\n", fname);
5519 if (!check_both_error(__LINE__, status, ERRDOS, EISDIR,
5520 NT_STATUS_FILE_IS_A_DIRECTORY)) {
5525 /* Create the file. */
5526 status = cli_posix_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL,
5528 if (!NT_STATUS_IS_OK(status)) {
5529 printf("POSIX create of %s failed (%s)\n", fname, nt_errstr(status));
5533 /* Write some data into it. */
5534 status = cli_writeall(cli1, fnum1, 0, (const uint8_t *)"TEST DATA\n", 0, 10,
5536 if (!NT_STATUS_IS_OK(status)) {
5537 printf("cli_write failed: %s\n", nt_errstr(status));
5541 cli_close(cli1, fnum1);
5543 /* Now create a hardlink. */
5544 status = cli_posix_hardlink(cli1, fname, hname);
5545 if (!NT_STATUS_IS_OK(status)) {
5546 printf("POSIX hardlink of %s failed (%s)\n", hname, nt_errstr(status));
5550 /* Now create a symlink. */
5551 status = cli_posix_symlink(cli1, fname, sname);
5552 if (!NT_STATUS_IS_OK(status)) {
5553 printf("POSIX symlink of %s failed (%s)\n", sname, nt_errstr(status));
5557 /* Open the hardlink for read. */
5558 status = cli_posix_open(cli1, hname, O_RDONLY, 0, &fnum1);
5559 if (!NT_STATUS_IS_OK(status)) {
5560 printf("POSIX open of %s failed (%s)\n", hname, nt_errstr(status));
5564 status = cli_read(cli1, fnum1, buf, 0, 10, &nread);
5565 if (!NT_STATUS_IS_OK(status)) {
5566 printf("POSIX read of %s failed (%s)\n", hname,
5569 } else if (nread != 10) {
5570 printf("POSIX read of %s failed. Received %ld, expected %d\n",
5571 hname, (unsigned long)nread, 10);
5575 if (memcmp(buf, "TEST DATA\n", 10)) {
5576 printf("invalid data read from hardlink\n");
5580 /* Do a POSIX lock/unlock. */
5581 status = cli_posix_lock(cli1, fnum1, 0, 100, true, READ_LOCK);
5582 if (!NT_STATUS_IS_OK(status)) {
5583 printf("POSIX lock failed %s\n", nt_errstr(status));
5587 /* Punch a hole in the locked area. */
5588 status = cli_posix_unlock(cli1, fnum1, 10, 80);
5589 if (!NT_STATUS_IS_OK(status)) {
5590 printf("POSIX unlock failed %s\n", nt_errstr(status));
5594 cli_close(cli1, fnum1);
5596 /* Open the symlink for read - this should fail. A POSIX
5597 client should not be doing opens on a symlink. */
5598 status = cli_posix_open(cli1, sname, O_RDONLY, 0, &fnum1);
5599 if (NT_STATUS_IS_OK(status)) {
5600 printf("POSIX open of %s succeeded (should have failed)\n", sname);
5603 if (!check_both_error(__LINE__, status, ERRDOS, ERRbadpath,
5604 NT_STATUS_OBJECT_PATH_NOT_FOUND)) {
5605 printf("POSIX open of %s should have failed "
5606 "with NT_STATUS_OBJECT_PATH_NOT_FOUND, "
5607 "failed with %s instead.\n",
5608 sname, nt_errstr(status));
5613 status = cli_posix_readlink(cli1, sname, namebuf, sizeof(namebuf));
5614 if (!NT_STATUS_IS_OK(status)) {
5615 printf("POSIX readlink on %s failed (%s)\n", sname, nt_errstr(status));
5619 if (strcmp(namebuf, fname) != 0) {
5620 printf("POSIX readlink on %s failed to match name %s (read %s)\n",
5621 sname, fname, namebuf);
5625 status = cli_posix_rmdir(cli1, dname);
5626 if (!NT_STATUS_IS_OK(status)) {
5627 printf("POSIX rmdir failed (%s)\n", nt_errstr(status));
5631 printf("Simple POSIX open test passed\n");
5636 if (fnum1 != (uint16_t)-1) {
5637 cli_close(cli1, fnum1);
5638 fnum1 = (uint16_t)-1;
5641 cli_setatr(cli1, sname, 0, 0);
5642 cli_posix_unlink(cli1, sname);
5643 cli_setatr(cli1, hname, 0, 0);
5644 cli_posix_unlink(cli1, hname);
5645 cli_setatr(cli1, fname, 0, 0);
5646 cli_posix_unlink(cli1, fname);
5647 cli_setatr(cli1, dname, 0, 0);
5648 cli_posix_rmdir(cli1, dname);
5650 if (!torture_close_connection(cli1)) {
5658 static uint32 open_attrs_table[] = {
5659 FILE_ATTRIBUTE_NORMAL,
5660 FILE_ATTRIBUTE_ARCHIVE,
5661 FILE_ATTRIBUTE_READONLY,
5662 FILE_ATTRIBUTE_HIDDEN,
5663 FILE_ATTRIBUTE_SYSTEM,
5665 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY,
5666 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN,
5667 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM,
5668 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
5669 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
5670 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
5672 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
5673 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
5674 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
5675 FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_SYSTEM,
5678 struct trunc_open_results {
5685 static struct trunc_open_results attr_results[] = {
5686 { 0, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
5687 { 1, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
5688 { 2, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
5689 { 16, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
5690 { 17, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
5691 { 18, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
5692 { 51, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
5693 { 54, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
5694 { 56, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
5695 { 68, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
5696 { 71, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
5697 { 73, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM },
5698 { 99, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
5699 { 102, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
5700 { 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 },
5701 { 116, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
5702 { 119, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
5703 { 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 },
5704 { 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 },
5705 { 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 },
5706 { 227, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
5707 { 230, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
5708 { 232, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
5709 { 244, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
5710 { 247, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
5711 { 249, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM }
5714 static bool run_openattrtest(int dummy)
5716 static struct cli_state *cli1;
5717 const char *fname = "\\openattr.file";
5719 bool correct = True;
5721 unsigned int i, j, k, l;
5724 printf("starting open attr test\n");
5726 if (!torture_open_connection(&cli1, 0)) {
5730 cli_sockopt(cli1, sockops);
5732 for (k = 0, i = 0; i < sizeof(open_attrs_table)/sizeof(uint32); i++) {
5733 cli_setatr(cli1, fname, 0, 0);
5734 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5736 status = cli_ntcreate(cli1, fname, 0, FILE_WRITE_DATA,
5737 open_attrs_table[i], FILE_SHARE_NONE,
5738 FILE_OVERWRITE_IF, 0, 0, &fnum1);
5739 if (!NT_STATUS_IS_OK(status)) {
5740 printf("open %d (1) of %s failed (%s)\n", i, fname, nt_errstr(status));
5744 status = cli_close(cli1, fnum1);
5745 if (!NT_STATUS_IS_OK(status)) {
5746 printf("close %d (1) of %s failed (%s)\n", i, fname, nt_errstr(status));
5750 for (j = 0; j < sizeof(open_attrs_table)/sizeof(uint32); j++) {
5751 status = cli_ntcreate(cli1, fname, 0,
5752 FILE_READ_DATA|FILE_WRITE_DATA,
5753 open_attrs_table[j],
5754 FILE_SHARE_NONE, FILE_OVERWRITE,
5756 if (!NT_STATUS_IS_OK(status)) {
5757 for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
5758 if (attr_results[l].num == k) {
5759 printf("[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(0x%x:%s)\n",
5760 k, open_attrs_table[i],
5761 open_attrs_table[j],
5762 fname, NT_STATUS_V(status), nt_errstr(status));
5767 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
5768 printf("[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s\n",
5769 k, open_attrs_table[i], open_attrs_table[j],
5774 printf("[%d] trunc open 0x%x -> 0x%x failed\n", k, open_attrs_table[i], open_attrs_table[j]);
5780 status = cli_close(cli1, fnum1);
5781 if (!NT_STATUS_IS_OK(status)) {
5782 printf("close %d (2) of %s failed (%s)\n", j, fname, nt_errstr(status));
5786 status = cli_getatr(cli1, fname, &attr, NULL, NULL);
5787 if (!NT_STATUS_IS_OK(status)) {
5788 printf("getatr(2) failed (%s)\n", nt_errstr(status));
5793 printf("[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n",
5794 k, open_attrs_table[i], open_attrs_table[j], attr );
5797 for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
5798 if (attr_results[l].num == k) {
5799 if (attr != attr_results[l].result_attr ||
5800 open_attrs_table[i] != attr_results[l].init_attr ||
5801 open_attrs_table[j] != attr_results[l].trunc_attr) {
5802 printf("getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x\n",
5803 open_attrs_table[i],
5804 open_attrs_table[j],
5806 attr_results[l].result_attr);
5816 cli_setatr(cli1, fname, 0, 0);
5817 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5819 printf("open attr test %s.\n", correct ? "passed" : "failed");
5821 if (!torture_close_connection(cli1)) {
5827 static NTSTATUS list_fn(const char *mnt, struct file_info *finfo,
5828 const char *name, void *state)
5830 int *matched = (int *)state;
5831 if (matched != NULL) {
5834 return NT_STATUS_OK;
5838 test directory listing speed
5840 static bool run_dirtest(int dummy)
5843 static struct cli_state *cli;
5845 struct timeval core_start;
5846 bool correct = True;
5849 printf("starting directory test\n");
5851 if (!torture_open_connection(&cli, 0)) {
5855 cli_sockopt(cli, sockops);
5858 for (i=0;i<torture_numops;i++) {
5860 slprintf(fname, sizeof(fname), "\\%x", (int)random());
5861 if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum))) {
5862 fprintf(stderr,"Failed to open %s\n", fname);
5865 cli_close(cli, fnum);
5868 core_start = timeval_current();
5871 cli_list(cli, "a*.*", 0, list_fn, &matched);
5872 printf("Matched %d\n", matched);
5875 cli_list(cli, "b*.*", 0, list_fn, &matched);
5876 printf("Matched %d\n", matched);
5879 cli_list(cli, "xyzabc", 0, list_fn, &matched);
5880 printf("Matched %d\n", matched);
5882 printf("dirtest core %g seconds\n", timeval_elapsed(&core_start));
5885 for (i=0;i<torture_numops;i++) {
5887 slprintf(fname, sizeof(fname), "\\%x", (int)random());
5888 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5891 if (!torture_close_connection(cli)) {
5895 printf("finished dirtest\n");
5900 static NTSTATUS del_fn(const char *mnt, struct file_info *finfo, const char *mask,
5903 struct cli_state *pcli = (struct cli_state *)state;
5905 slprintf(fname, sizeof(fname), "\\LISTDIR\\%s", finfo->name);
5907 if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
5908 return NT_STATUS_OK;
5910 if (finfo->mode & FILE_ATTRIBUTE_DIRECTORY) {
5911 if (!NT_STATUS_IS_OK(cli_rmdir(pcli, fname)))
5912 printf("del_fn: failed to rmdir %s\n,", fname );
5914 if (!NT_STATUS_IS_OK(cli_unlink(pcli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN)))
5915 printf("del_fn: failed to unlink %s\n,", fname );
5917 return NT_STATUS_OK;
5922 sees what IOCTLs are supported
5924 bool torture_ioctl_test(int dummy)
5926 static struct cli_state *cli;
5927 uint16_t device, function;
5929 const char *fname = "\\ioctl.dat";
5933 if (!torture_open_connection(&cli, 0)) {
5937 printf("starting ioctl test\n");
5939 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5941 status = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
5942 if (!NT_STATUS_IS_OK(status)) {
5943 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
5947 status = cli_raw_ioctl(cli, fnum, 0x2d0000 | (0x0420<<2), &blob);
5948 printf("ioctl device info: %s\n", nt_errstr(status));
5950 status = cli_raw_ioctl(cli, fnum, IOCTL_QUERY_JOB_INFO, &blob);
5951 printf("ioctl job info: %s\n", nt_errstr(status));
5953 for (device=0;device<0x100;device++) {
5954 printf("ioctl test with device = 0x%x\n", device);
5955 for (function=0;function<0x100;function++) {
5956 uint32 code = (device<<16) | function;
5958 status = cli_raw_ioctl(cli, fnum, code, &blob);
5960 if (NT_STATUS_IS_OK(status)) {
5961 printf("ioctl 0x%x OK : %d bytes\n", (int)code,
5963 data_blob_free(&blob);
5968 if (!torture_close_connection(cli)) {
5977 tries varients of chkpath
5979 bool torture_chkpath_test(int dummy)
5981 static struct cli_state *cli;
5986 if (!torture_open_connection(&cli, 0)) {
5990 printf("starting chkpath test\n");
5992 /* cleanup from an old run */
5993 cli_rmdir(cli, "\\chkpath.dir\\dir2");
5994 cli_unlink(cli, "\\chkpath.dir\\*", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
5995 cli_rmdir(cli, "\\chkpath.dir");
5997 status = cli_mkdir(cli, "\\chkpath.dir");
5998 if (!NT_STATUS_IS_OK(status)) {
5999 printf("mkdir1 failed : %s\n", nt_errstr(status));
6003 status = cli_mkdir(cli, "\\chkpath.dir\\dir2");
6004 if (!NT_STATUS_IS_OK(status)) {
6005 printf("mkdir2 failed : %s\n", nt_errstr(status));
6009 status = cli_open(cli, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL,
6011 if (!NT_STATUS_IS_OK(status)) {
6012 printf("open1 failed (%s)\n", nt_errstr(status));
6015 cli_close(cli, fnum);
6017 status = cli_chkpath(cli, "\\chkpath.dir");
6018 if (!NT_STATUS_IS_OK(status)) {
6019 printf("chkpath1 failed: %s\n", nt_errstr(status));
6023 status = cli_chkpath(cli, "\\chkpath.dir\\dir2");
6024 if (!NT_STATUS_IS_OK(status)) {
6025 printf("chkpath2 failed: %s\n", nt_errstr(status));
6029 status = cli_chkpath(cli, "\\chkpath.dir\\foo.txt");
6030 if (!NT_STATUS_IS_OK(status)) {
6031 ret = check_error(__LINE__, status, ERRDOS, ERRbadpath,
6032 NT_STATUS_NOT_A_DIRECTORY);
6034 printf("* chkpath on a file should fail\n");
6038 status = cli_chkpath(cli, "\\chkpath.dir\\bar.txt");
6039 if (!NT_STATUS_IS_OK(status)) {
6040 ret = check_error(__LINE__, status, ERRDOS, ERRbadfile,
6041 NT_STATUS_OBJECT_NAME_NOT_FOUND);
6043 printf("* chkpath on a non existant file should fail\n");
6047 status = cli_chkpath(cli, "\\chkpath.dir\\dirxx\\bar.txt");
6048 if (!NT_STATUS_IS_OK(status)) {
6049 ret = check_error(__LINE__, status, ERRDOS, ERRbadpath,
6050 NT_STATUS_OBJECT_PATH_NOT_FOUND);
6052 printf("* chkpath on a non existent component should fail\n");
6056 cli_rmdir(cli, "\\chkpath.dir\\dir2");
6057 cli_unlink(cli, "\\chkpath.dir\\*", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
6058 cli_rmdir(cli, "\\chkpath.dir");
6060 if (!torture_close_connection(cli)) {
6067 static bool run_eatest(int dummy)
6069 static struct cli_state *cli;
6070 const char *fname = "\\eatest.txt";
6071 bool correct = True;
6075 struct ea_struct *ea_list = NULL;
6076 TALLOC_CTX *mem_ctx = talloc_init("eatest");
6079 printf("starting eatest\n");
6081 if (!torture_open_connection(&cli, 0)) {
6082 talloc_destroy(mem_ctx);
6086 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
6088 status = cli_ntcreate(cli, fname, 0,
6089 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
6090 FILE_SHARE_NONE, FILE_OVERWRITE_IF,
6092 if (!NT_STATUS_IS_OK(status)) {
6093 printf("open failed - %s\n", nt_errstr(status));
6094 talloc_destroy(mem_ctx);
6098 for (i = 0; i < 10; i++) {
6099 fstring ea_name, ea_val;
6101 slprintf(ea_name, sizeof(ea_name), "EA_%d", i);
6102 memset(ea_val, (char)i+1, i+1);
6103 status = cli_set_ea_fnum(cli, fnum, ea_name, ea_val, i+1);
6104 if (!NT_STATUS_IS_OK(status)) {
6105 printf("ea_set of name %s failed - %s\n", ea_name,
6107 talloc_destroy(mem_ctx);
6112 cli_close(cli, fnum);
6113 for (i = 0; i < 10; i++) {
6114 fstring ea_name, ea_val;
6116 slprintf(ea_name, sizeof(ea_name), "EA_%d", i+10);
6117 memset(ea_val, (char)i+1, i+1);
6118 status = cli_set_ea_path(cli, fname, ea_name, ea_val, i+1);
6119 if (!NT_STATUS_IS_OK(status)) {
6120 printf("ea_set of name %s failed - %s\n", ea_name,
6122 talloc_destroy(mem_ctx);
6127 status = cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list);
6128 if (!NT_STATUS_IS_OK(status)) {
6129 printf("ea_get list failed - %s\n", nt_errstr(status));
6133 printf("num_eas = %d\n", (int)num_eas);
6135 if (num_eas != 20) {
6136 printf("Should be 20 EA's stored... failing.\n");
6140 for (i = 0; i < num_eas; i++) {
6141 printf("%d: ea_name = %s. Val = ", i, ea_list[i].name);
6142 dump_data(0, ea_list[i].value.data,
6143 ea_list[i].value.length);
6146 /* Setting EA's to zero length deletes them. Test this */
6147 printf("Now deleting all EA's - case indepenent....\n");
6150 cli_set_ea_path(cli, fname, "", "", 0);
6152 for (i = 0; i < 20; i++) {
6154 slprintf(ea_name, sizeof(ea_name), "ea_%d", i);
6155 status = cli_set_ea_path(cli, fname, ea_name, "", 0);
6156 if (!NT_STATUS_IS_OK(status)) {
6157 printf("ea_set of name %s failed - %s\n", ea_name,
6159 talloc_destroy(mem_ctx);
6165 status = cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list);
6166 if (!NT_STATUS_IS_OK(status)) {
6167 printf("ea_get list failed - %s\n", nt_errstr(status));
6171 printf("num_eas = %d\n", (int)num_eas);
6172 for (i = 0; i < num_eas; i++) {
6173 printf("%d: ea_name = %s. Val = ", i, ea_list[i].name);
6174 dump_data(0, ea_list[i].value.data,
6175 ea_list[i].value.length);
6179 printf("deleting EA's failed.\n");
6183 /* Try and delete a non existant EA. */
6184 status = cli_set_ea_path(cli, fname, "foo", "", 0);
6185 if (!NT_STATUS_IS_OK(status)) {
6186 printf("deleting non-existant EA 'foo' should succeed. %s\n",
6191 talloc_destroy(mem_ctx);
6192 if (!torture_close_connection(cli)) {
6199 static bool run_dirtest1(int dummy)
6202 static struct cli_state *cli;
6205 bool correct = True;
6207 printf("starting directory test\n");
6209 if (!torture_open_connection(&cli, 0)) {
6213 cli_sockopt(cli, sockops);
6215 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
6216 cli_list(cli, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, del_fn, cli);
6217 cli_rmdir(cli, "\\LISTDIR");
6218 cli_mkdir(cli, "\\LISTDIR");
6220 /* Create 1000 files and 1000 directories. */
6221 for (i=0;i<1000;i++) {
6223 slprintf(fname, sizeof(fname), "\\LISTDIR\\f%d", i);
6224 if (!NT_STATUS_IS_OK(cli_ntcreate(cli, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
6225 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum))) {
6226 fprintf(stderr,"Failed to open %s\n", fname);
6229 cli_close(cli, fnum);
6231 for (i=0;i<1000;i++) {
6233 slprintf(fname, sizeof(fname), "\\LISTDIR\\d%d", i);
6234 if (!NT_STATUS_IS_OK(cli_mkdir(cli, fname))) {
6235 fprintf(stderr,"Failed to open %s\n", fname);
6240 /* Now ensure that doing an old list sees both files and directories. */
6242 cli_list_old(cli, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, list_fn, &num_seen);
6243 printf("num_seen = %d\n", num_seen );
6244 /* We should see 100 files + 1000 directories + . and .. */
6245 if (num_seen != 2002)
6248 /* Ensure if we have the "must have" bits we only see the
6252 cli_list_old(cli, "\\LISTDIR\\*", (FILE_ATTRIBUTE_DIRECTORY<<8)|FILE_ATTRIBUTE_DIRECTORY, list_fn, &num_seen);
6253 printf("num_seen = %d\n", num_seen );
6254 if (num_seen != 1002)
6258 cli_list_old(cli, "\\LISTDIR\\*", (FILE_ATTRIBUTE_ARCHIVE<<8)|FILE_ATTRIBUTE_DIRECTORY, list_fn, &num_seen);
6259 printf("num_seen = %d\n", num_seen );
6260 if (num_seen != 1000)
6263 /* Delete everything. */
6264 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
6265 cli_list(cli, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, del_fn, cli);
6266 cli_rmdir(cli, "\\LISTDIR");
6269 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
6270 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
6271 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
6274 if (!torture_close_connection(cli)) {
6278 printf("finished dirtest1\n");
6283 static bool run_error_map_extract(int dummy) {
6285 static struct cli_state *c_dos;
6286 static struct cli_state *c_nt;
6298 /* NT-Error connection */
6300 disable_spnego = true;
6301 if (!(c_nt = open_nbt_connection())) {
6302 disable_spnego = false;
6305 disable_spnego = false;
6307 status = cli_negprot(c_nt);
6309 if (!NT_STATUS_IS_OK(status)) {
6310 printf("%s rejected the NT-error negprot (%s)\n", host,
6316 status = cli_session_setup(c_nt, "", "", 0, "", 0, workgroup);
6317 if (!NT_STATUS_IS_OK(status)) {
6318 printf("%s rejected the NT-error initial session setup (%s)\n",host, nt_errstr(status));
6322 /* DOS-Error connection */
6324 disable_spnego = true;
6325 force_dos_errors = true;
6326 if (!(c_dos = open_nbt_connection())) {
6327 disable_spnego = false;
6328 force_dos_errors = false;
6331 disable_spnego = false;
6332 force_dos_errors = false;
6334 status = cli_negprot(c_dos);
6335 if (!NT_STATUS_IS_OK(status)) {
6336 printf("%s rejected the DOS-error negprot (%s)\n", host,
6338 cli_shutdown(c_dos);
6342 status = cli_session_setup(c_dos, "", "", 0, "", 0, workgroup);
6343 if (!NT_STATUS_IS_OK(status)) {
6344 printf("%s rejected the DOS-error initial session setup (%s)\n",
6345 host, nt_errstr(status));
6349 for (error=(0xc0000000 | 0x1); error < (0xc0000000| 0xFFF); error++) {
6350 fstr_sprintf(user, "%X", error);
6352 status = cli_session_setup(c_nt, user,
6353 password, strlen(password),
6354 password, strlen(password),
6356 if (NT_STATUS_IS_OK(status)) {
6357 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
6360 /* Case #1: 32-bit NT errors */
6361 if (cli_is_nt_error(c_nt)) {
6362 nt_status = cli_nt_error(c_nt);
6364 printf("/** Dos error on NT connection! (%s) */\n",
6366 nt_status = NT_STATUS(0xc0000000);
6369 status = cli_session_setup(c_dos, user,
6370 password, strlen(password),
6371 password, strlen(password),
6373 if (NT_STATUS_IS_OK(status)) {
6374 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
6377 /* Case #1: 32-bit NT errors */
6378 if (!cli_is_dos_error(c_dos)) {
6379 printf("/** NT error on DOS connection! (%s) */\n",
6381 errnum = errclass = 0;
6383 cli_dos_error(c_dos, &errclass, &errnum);
6386 if (NT_STATUS_V(nt_status) != error) {
6387 printf("/*\t{ This NT error code was 'sqashed'\n\t from %s to %s \n\t during the session setup }\n*/\n",
6388 get_nt_error_c_code(talloc_tos(), NT_STATUS(error)),
6389 get_nt_error_c_code(talloc_tos(), nt_status));
6392 printf("\t{%s,\t%s,\t%s},\n",
6393 smb_dos_err_class(errclass),
6394 smb_dos_err_name(errclass, errnum),
6395 get_nt_error_c_code(talloc_tos(), NT_STATUS(error)));
6400 static bool run_sesssetup_bench(int dummy)
6402 static struct cli_state *c;
6403 const char *fname = "\\file.dat";
6408 if (!torture_open_connection(&c, 0)) {
6412 status = cli_ntcreate(c, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
6413 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
6414 FILE_DELETE_ON_CLOSE, 0, &fnum);
6415 if (!NT_STATUS_IS_OK(status)) {
6416 d_printf("open %s failed: %s\n", fname, nt_errstr(status));
6420 for (i=0; i<torture_numops; i++) {
6421 status = cli_session_setup(
6423 password, strlen(password),
6424 password, strlen(password),
6426 if (!NT_STATUS_IS_OK(status)) {
6427 d_printf("(%s) cli_session_setup failed: %s\n",
6428 __location__, nt_errstr(status));
6432 d_printf("\r%d ", (int)cli_state_get_uid(c));
6434 status = cli_ulogoff(c);
6435 if (!NT_STATUS_IS_OK(status)) {
6436 d_printf("(%s) cli_ulogoff failed: %s\n",
6437 __location__, nt_errstr(status));
6445 static bool subst_test(const char *str, const char *user, const char *domain,
6446 uid_t uid, gid_t gid, const char *expected)
6451 subst = talloc_sub_specified(talloc_tos(), str, user, domain, uid, gid);
6453 if (strcmp(subst, expected) != 0) {
6454 printf("sub_specified(%s, %s, %s, %d, %d) returned [%s], expected "
6455 "[%s]\n", str, user, domain, (int)uid, (int)gid, subst,
6464 static void chain1_open_completion(struct tevent_req *req)
6468 status = cli_open_recv(req, &fnum);
6471 d_printf("cli_open_recv returned %s: %d\n",
6473 NT_STATUS_IS_OK(status) ? fnum : -1);
6476 static void chain1_write_completion(struct tevent_req *req)
6480 status = cli_write_andx_recv(req, &written);
6483 d_printf("cli_write_andx_recv returned %s: %d\n",
6485 NT_STATUS_IS_OK(status) ? (int)written : -1);
6488 static void chain1_close_completion(struct tevent_req *req)
6491 bool *done = (bool *)tevent_req_callback_data_void(req);
6493 status = cli_close_recv(req);
6498 d_printf("cli_close returned %s\n", nt_errstr(status));
6501 static bool run_chain1(int dummy)
6503 struct cli_state *cli1;
6504 struct event_context *evt = event_context_init(NULL);
6505 struct tevent_req *reqs[3], *smbreqs[3];
6507 const char *str = "foobar";
6510 printf("starting chain1 test\n");
6511 if (!torture_open_connection(&cli1, 0)) {
6515 cli_sockopt(cli1, sockops);
6517 reqs[0] = cli_open_create(talloc_tos(), evt, cli1, "\\test",
6518 O_CREAT|O_RDWR, 0, &smbreqs[0]);
6519 if (reqs[0] == NULL) return false;
6520 tevent_req_set_callback(reqs[0], chain1_open_completion, NULL);
6523 reqs[1] = cli_write_andx_create(talloc_tos(), evt, cli1, 0, 0,
6524 (const uint8_t *)str, 0, strlen(str)+1,
6525 smbreqs, 1, &smbreqs[1]);
6526 if (reqs[1] == NULL) return false;
6527 tevent_req_set_callback(reqs[1], chain1_write_completion, NULL);
6529 reqs[2] = cli_close_create(talloc_tos(), evt, cli1, 0, &smbreqs[2]);
6530 if (reqs[2] == NULL) return false;
6531 tevent_req_set_callback(reqs[2], chain1_close_completion, &done);
6533 status = cli_smb_chain_send(smbreqs, ARRAY_SIZE(smbreqs));
6534 if (!NT_STATUS_IS_OK(status)) {
6539 tevent_loop_once(evt);
6542 torture_close_connection(cli1);
6546 static void chain2_sesssetup_completion(struct tevent_req *req)
6549 status = cli_session_setup_guest_recv(req);
6550 d_printf("sesssetup returned %s\n", nt_errstr(status));
6553 static void chain2_tcon_completion(struct tevent_req *req)
6555 bool *done = (bool *)tevent_req_callback_data_void(req);
6557 status = cli_tcon_andx_recv(req);
6558 d_printf("tcon_and_x returned %s\n", nt_errstr(status));
6562 static bool run_chain2(int dummy)
6564 struct cli_state *cli1;
6565 struct event_context *evt = event_context_init(NULL);
6566 struct tevent_req *reqs[2], *smbreqs[2];
6570 printf("starting chain2 test\n");
6571 status = cli_start_connection(&cli1, lp_netbios_name(), host, NULL,
6572 port_to_use, Undefined, 0);
6573 if (!NT_STATUS_IS_OK(status)) {
6577 cli_sockopt(cli1, sockops);
6579 reqs[0] = cli_session_setup_guest_create(talloc_tos(), evt, cli1,
6581 if (reqs[0] == NULL) return false;
6582 tevent_req_set_callback(reqs[0], chain2_sesssetup_completion, NULL);
6584 reqs[1] = cli_tcon_andx_create(talloc_tos(), evt, cli1, "IPC$",
6585 "?????", NULL, 0, &smbreqs[1]);
6586 if (reqs[1] == NULL) return false;
6587 tevent_req_set_callback(reqs[1], chain2_tcon_completion, &done);
6589 status = cli_smb_chain_send(smbreqs, ARRAY_SIZE(smbreqs));
6590 if (!NT_STATUS_IS_OK(status)) {
6595 tevent_loop_once(evt);
6598 torture_close_connection(cli1);
6603 struct torture_createdel_state {
6604 struct tevent_context *ev;
6605 struct cli_state *cli;
6608 static void torture_createdel_created(struct tevent_req *subreq);
6609 static void torture_createdel_closed(struct tevent_req *subreq);
6611 static struct tevent_req *torture_createdel_send(TALLOC_CTX *mem_ctx,
6612 struct tevent_context *ev,
6613 struct cli_state *cli,
6616 struct tevent_req *req, *subreq;
6617 struct torture_createdel_state *state;
6619 req = tevent_req_create(mem_ctx, &state,
6620 struct torture_createdel_state);
6627 subreq = cli_ntcreate_send(
6628 state, ev, cli, name, 0,
6629 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
6630 FILE_ATTRIBUTE_NORMAL,
6631 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
6632 FILE_OPEN_IF, FILE_DELETE_ON_CLOSE, 0);
6634 if (tevent_req_nomem(subreq, req)) {
6635 return tevent_req_post(req, ev);
6637 tevent_req_set_callback(subreq, torture_createdel_created, req);
6641 static void torture_createdel_created(struct tevent_req *subreq)
6643 struct tevent_req *req = tevent_req_callback_data(
6644 subreq, struct tevent_req);
6645 struct torture_createdel_state *state = tevent_req_data(
6646 req, struct torture_createdel_state);
6650 status = cli_ntcreate_recv(subreq, &fnum);
6651 TALLOC_FREE(subreq);
6652 if (!NT_STATUS_IS_OK(status)) {
6653 DEBUG(10, ("cli_ntcreate_recv returned %s\n",
6654 nt_errstr(status)));
6655 tevent_req_nterror(req, status);
6659 subreq = cli_close_send(state, state->ev, state->cli, fnum);
6660 if (tevent_req_nomem(subreq, req)) {
6663 tevent_req_set_callback(subreq, torture_createdel_closed, req);
6666 static void torture_createdel_closed(struct tevent_req *subreq)
6668 struct tevent_req *req = tevent_req_callback_data(
6669 subreq, struct tevent_req);
6672 status = cli_close_recv(subreq);
6673 if (!NT_STATUS_IS_OK(status)) {
6674 DEBUG(10, ("cli_close_recv returned %s\n", nt_errstr(status)));
6675 tevent_req_nterror(req, status);
6678 tevent_req_done(req);
6681 static NTSTATUS torture_createdel_recv(struct tevent_req *req)
6683 return tevent_req_simple_recv_ntstatus(req);
6686 struct torture_createdels_state {
6687 struct tevent_context *ev;
6688 struct cli_state *cli;
6689 const char *base_name;
6693 struct tevent_req **reqs;
6696 static void torture_createdels_done(struct tevent_req *subreq);
6698 static struct tevent_req *torture_createdels_send(TALLOC_CTX *mem_ctx,
6699 struct tevent_context *ev,
6700 struct cli_state *cli,
6701 const char *base_name,
6705 struct tevent_req *req;
6706 struct torture_createdels_state *state;
6709 req = tevent_req_create(mem_ctx, &state,
6710 struct torture_createdels_state);
6716 state->base_name = talloc_strdup(state, base_name);
6717 if (tevent_req_nomem(state->base_name, req)) {
6718 return tevent_req_post(req, ev);
6720 state->num_files = MAX(num_parallel, num_files);
6722 state->received = 0;
6724 state->reqs = talloc_array(state, struct tevent_req *, num_parallel);
6725 if (tevent_req_nomem(state->reqs, req)) {
6726 return tevent_req_post(req, ev);
6729 for (i=0; i<num_parallel; i++) {
6732 name = talloc_asprintf(state, "%s%8.8d", state->base_name,
6734 if (tevent_req_nomem(name, req)) {
6735 return tevent_req_post(req, ev);
6737 state->reqs[i] = torture_createdel_send(
6738 state->reqs, state->ev, state->cli, name);
6739 if (tevent_req_nomem(state->reqs[i], req)) {
6740 return tevent_req_post(req, ev);
6742 name = talloc_move(state->reqs[i], &name);
6743 tevent_req_set_callback(state->reqs[i],
6744 torture_createdels_done, req);
6750 static void torture_createdels_done(struct tevent_req *subreq)
6752 struct tevent_req *req = tevent_req_callback_data(
6753 subreq, struct tevent_req);
6754 struct torture_createdels_state *state = tevent_req_data(
6755 req, struct torture_createdels_state);
6756 size_t num_parallel = talloc_array_length(state->reqs);
6761 status = torture_createdel_recv(subreq);
6762 if (!NT_STATUS_IS_OK(status)){
6763 DEBUG(10, ("torture_createdel_recv returned %s\n",
6764 nt_errstr(status)));
6765 TALLOC_FREE(subreq);
6766 tevent_req_nterror(req, status);
6770 for (i=0; i<num_parallel; i++) {
6771 if (subreq == state->reqs[i]) {
6775 if (i == num_parallel) {
6776 DEBUG(10, ("received something we did not send\n"));
6777 tevent_req_nterror(req, NT_STATUS_INTERNAL_ERROR);
6780 TALLOC_FREE(state->reqs[i]);
6782 if (state->sent >= state->num_files) {
6783 tevent_req_done(req);
6787 name = talloc_asprintf(state, "%s%8.8d", state->base_name,
6789 if (tevent_req_nomem(name, req)) {
6792 state->reqs[i] = torture_createdel_send(state->reqs, state->ev,
6794 if (tevent_req_nomem(state->reqs[i], req)) {
6797 name = talloc_move(state->reqs[i], &name);
6798 tevent_req_set_callback(state->reqs[i], torture_createdels_done, req);
6802 static NTSTATUS torture_createdels_recv(struct tevent_req *req)
6804 return tevent_req_simple_recv_ntstatus(req);
6807 struct swallow_notify_state {
6808 struct tevent_context *ev;
6809 struct cli_state *cli;
6811 uint32_t completion_filter;
6813 bool (*fn)(uint32_t action, const char *name, void *priv);
6817 static void swallow_notify_done(struct tevent_req *subreq);
6819 static struct tevent_req *swallow_notify_send(TALLOC_CTX *mem_ctx,
6820 struct tevent_context *ev,
6821 struct cli_state *cli,
6823 uint32_t completion_filter,
6825 bool (*fn)(uint32_t action,
6830 struct tevent_req *req, *subreq;
6831 struct swallow_notify_state *state;
6833 req = tevent_req_create(mem_ctx, &state,
6834 struct swallow_notify_state);
6841 state->completion_filter = completion_filter;
6842 state->recursive = recursive;
6846 subreq = cli_notify_send(state, state->ev, state->cli, state->fnum,
6847 0xffff, state->completion_filter,
6849 if (tevent_req_nomem(subreq, req)) {
6850 return tevent_req_post(req, ev);
6852 tevent_req_set_callback(subreq, swallow_notify_done, req);
6856 static void swallow_notify_done(struct tevent_req *subreq)
6858 struct tevent_req *req = tevent_req_callback_data(
6859 subreq, struct tevent_req);
6860 struct swallow_notify_state *state = tevent_req_data(
6861 req, struct swallow_notify_state);
6863 uint32_t i, num_changes;
6864 struct notify_change *changes;
6866 status = cli_notify_recv(subreq, state, &num_changes, &changes);
6867 TALLOC_FREE(subreq);
6868 if (!NT_STATUS_IS_OK(status)) {
6869 DEBUG(10, ("cli_notify_recv returned %s\n",
6870 nt_errstr(status)));
6871 tevent_req_nterror(req, status);
6875 for (i=0; i<num_changes; i++) {
6876 state->fn(changes[i].action, changes[i].name, state->priv);
6878 TALLOC_FREE(changes);
6880 subreq = cli_notify_send(state, state->ev, state->cli, state->fnum,
6881 0xffff, state->completion_filter,
6883 if (tevent_req_nomem(subreq, req)) {
6886 tevent_req_set_callback(subreq, swallow_notify_done, req);
6889 static bool print_notifies(uint32_t action, const char *name, void *priv)
6891 if (DEBUGLEVEL > 5) {
6892 d_printf("%d %s\n", (int)action, name);
6897 static void notify_bench_done(struct tevent_req *req)
6899 int *num_finished = (int *)tevent_req_callback_data_void(req);
6903 static bool run_notify_bench(int dummy)
6905 const char *dname = "\\notify-bench";
6906 struct tevent_context *ev;
6909 struct tevent_req *req1;
6910 struct tevent_req *req2 = NULL;
6911 int i, num_unc_names;
6912 int num_finished = 0;
6914 printf("starting notify-bench test\n");
6916 if (use_multishare_conn) {
6918 unc_list = file_lines_load(multishare_conn_fname,
6919 &num_unc_names, 0, NULL);
6920 if (!unc_list || num_unc_names <= 0) {
6921 d_printf("Failed to load unc names list from '%s'\n",
6922 multishare_conn_fname);
6925 TALLOC_FREE(unc_list);
6930 ev = tevent_context_init(talloc_tos());
6932 d_printf("tevent_context_init failed\n");
6936 for (i=0; i<num_unc_names; i++) {
6937 struct cli_state *cli;
6940 base_fname = talloc_asprintf(talloc_tos(), "%s\\file%3.3d.",
6942 if (base_fname == NULL) {
6946 if (!torture_open_connection(&cli, i)) {
6950 status = cli_ntcreate(cli, dname, 0,
6951 MAXIMUM_ALLOWED_ACCESS,
6952 0, FILE_SHARE_READ|FILE_SHARE_WRITE|
6954 FILE_OPEN_IF, FILE_DIRECTORY_FILE, 0,
6957 if (!NT_STATUS_IS_OK(status)) {
6958 d_printf("Could not create %s: %s\n", dname,
6963 req1 = swallow_notify_send(talloc_tos(), ev, cli, dnum,
6964 FILE_NOTIFY_CHANGE_FILE_NAME |
6965 FILE_NOTIFY_CHANGE_DIR_NAME |
6966 FILE_NOTIFY_CHANGE_ATTRIBUTES |
6967 FILE_NOTIFY_CHANGE_LAST_WRITE,
6968 false, print_notifies, NULL);
6970 d_printf("Could not create notify request\n");
6974 req2 = torture_createdels_send(talloc_tos(), ev, cli,
6975 base_fname, 10, torture_numops);
6977 d_printf("Could not create createdels request\n");
6980 TALLOC_FREE(base_fname);
6982 tevent_req_set_callback(req2, notify_bench_done,
6986 while (num_finished < num_unc_names) {
6988 ret = tevent_loop_once(ev);
6990 d_printf("tevent_loop_once failed\n");
6995 if (!tevent_req_poll(req2, ev)) {
6996 d_printf("tevent_req_poll failed\n");
6999 status = torture_createdels_recv(req2);
7000 d_printf("torture_createdels_recv returned %s\n", nt_errstr(status));
7005 static bool run_mangle1(int dummy)
7007 struct cli_state *cli;
7008 const char *fname = "this_is_a_long_fname_to_be_mangled.txt";
7012 time_t change_time, access_time, write_time;
7016 printf("starting mangle1 test\n");
7017 if (!torture_open_connection(&cli, 0)) {
7021 cli_sockopt(cli, sockops);
7023 status = cli_ntcreate(cli, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
7024 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
7026 if (!NT_STATUS_IS_OK(status)) {
7027 d_printf("open %s failed: %s\n", fname, nt_errstr(status));
7030 cli_close(cli, fnum);
7032 status = cli_qpathinfo_alt_name(cli, fname, alt_name);
7033 if (!NT_STATUS_IS_OK(status)) {
7034 d_printf("cli_qpathinfo_alt_name failed: %s\n",
7038 d_printf("alt_name: %s\n", alt_name);
7040 status = cli_open(cli, alt_name, O_RDONLY, DENY_NONE, &fnum);
7041 if (!NT_STATUS_IS_OK(status)) {
7042 d_printf("cli_open(%s) failed: %s\n", alt_name,
7046 cli_close(cli, fnum);
7048 status = cli_qpathinfo1(cli, alt_name, &change_time, &access_time,
7049 &write_time, &size, &mode);
7050 if (!NT_STATUS_IS_OK(status)) {
7051 d_printf("cli_qpathinfo1(%s) failed: %s\n", alt_name,
7059 static size_t null_source(uint8_t *buf, size_t n, void *priv)
7061 size_t *to_pull = (size_t *)priv;
7062 size_t thistime = *to_pull;
7064 thistime = MIN(thistime, n);
7065 if (thistime == 0) {
7069 memset(buf, 0, thistime);
7070 *to_pull -= thistime;
7074 static bool run_windows_write(int dummy)
7076 struct cli_state *cli1;
7080 const char *fname = "\\writetest.txt";
7081 struct timeval start_time;
7086 printf("starting windows_write test\n");
7087 if (!torture_open_connection(&cli1, 0)) {
7091 status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
7092 if (!NT_STATUS_IS_OK(status)) {
7093 printf("open failed (%s)\n", nt_errstr(status));
7097 cli_sockopt(cli1, sockops);
7099 start_time = timeval_current();
7101 for (i=0; i<torture_numops; i++) {
7103 off_t start = i * torture_blocksize;
7104 size_t to_pull = torture_blocksize - 1;
7106 status = cli_writeall(cli1, fnum, 0, &c,
7107 start + torture_blocksize - 1, 1, NULL);
7108 if (!NT_STATUS_IS_OK(status)) {
7109 printf("cli_write failed: %s\n", nt_errstr(status));
7113 status = cli_push(cli1, fnum, 0, i * torture_blocksize, torture_blocksize,
7114 null_source, &to_pull);
7115 if (!NT_STATUS_IS_OK(status)) {
7116 printf("cli_push returned: %s\n", nt_errstr(status));
7121 seconds = timeval_elapsed(&start_time);
7122 kbytes = (double)torture_blocksize * torture_numops;
7125 printf("Wrote %d kbytes in %.2f seconds: %d kb/sec\n", (int)kbytes,
7126 (double)seconds, (int)(kbytes/seconds));
7130 cli_close(cli1, fnum);
7131 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7132 torture_close_connection(cli1);
7136 static bool run_cli_echo(int dummy)
7138 struct cli_state *cli;
7141 printf("starting cli_echo test\n");
7142 if (!torture_open_connection(&cli, 0)) {
7145 cli_sockopt(cli, sockops);
7147 status = cli_echo(cli, 5, data_blob_const("hello", 5));
7149 d_printf("cli_echo returned %s\n", nt_errstr(status));
7151 torture_close_connection(cli);
7152 return NT_STATUS_IS_OK(status);
7155 static bool run_uid_regression_test(int dummy)
7157 static struct cli_state *cli;
7160 bool correct = True;
7163 printf("starting uid regression test\n");
7165 if (!torture_open_connection(&cli, 0)) {
7169 cli_sockopt(cli, sockops);
7171 /* Ok - now save then logoff our current user. */
7172 old_vuid = cli_state_get_uid(cli);
7174 status = cli_ulogoff(cli);
7175 if (!NT_STATUS_IS_OK(status)) {
7176 d_printf("(%s) cli_ulogoff failed: %s\n",
7177 __location__, nt_errstr(status));
7182 cli_state_set_uid(cli, old_vuid);
7184 /* Try an operation. */
7185 status = cli_mkdir(cli, "\\uid_reg_test");
7186 if (NT_STATUS_IS_OK(status)) {
7187 d_printf("(%s) cli_mkdir succeeded\n",
7192 /* Should be bad uid. */
7193 if (!check_error(__LINE__, status, ERRSRV, ERRbaduid,
7194 NT_STATUS_USER_SESSION_DELETED)) {
7200 old_cnum = cli_state_get_tid(cli);
7202 /* Now try a SMBtdis with the invald vuid set to zero. */
7203 cli_state_set_uid(cli, 0);
7205 /* This should succeed. */
7206 status = cli_tdis(cli);
7208 if (NT_STATUS_IS_OK(status)) {
7209 d_printf("First tdis with invalid vuid should succeed.\n");
7211 d_printf("First tdis failed (%s)\n", nt_errstr(status));
7216 cli_state_set_uid(cli, old_vuid);
7217 cli_state_set_tid(cli, old_cnum);
7219 /* This should fail. */
7220 status = cli_tdis(cli);
7221 if (NT_STATUS_IS_OK(status)) {
7222 d_printf("Second tdis with invalid vuid should fail - succeeded instead !.\n");
7226 /* Should be bad tid. */
7227 if (!check_error(__LINE__, status, ERRSRV, ERRinvnid,
7228 NT_STATUS_NETWORK_NAME_DELETED)) {
7234 cli_rmdir(cli, "\\uid_reg_test");
7243 static const char *illegal_chars = "*\\/?<>|\":";
7244 static char force_shortname_chars[] = " +,.[];=\177";
7246 static NTSTATUS shortname_del_fn(const char *mnt, struct file_info *finfo,
7247 const char *mask, void *state)
7249 struct cli_state *pcli = (struct cli_state *)state;
7251 NTSTATUS status = NT_STATUS_OK;
7253 slprintf(fname, sizeof(fname), "\\shortname\\%s", finfo->name);
7255 if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
7256 return NT_STATUS_OK;
7258 if (finfo->mode & FILE_ATTRIBUTE_DIRECTORY) {
7259 status = cli_rmdir(pcli, fname);
7260 if (!NT_STATUS_IS_OK(status)) {
7261 printf("del_fn: failed to rmdir %s\n,", fname );
7264 status = cli_unlink(pcli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7265 if (!NT_STATUS_IS_OK(status)) {
7266 printf("del_fn: failed to unlink %s\n,", fname );
7278 static NTSTATUS shortname_list_fn(const char *mnt, struct file_info *finfo,
7279 const char *name, void *state)
7281 struct sn_state *s = (struct sn_state *)state;
7285 printf("shortname list: i = %d, name = |%s|, shortname = |%s|\n",
7286 i, finfo->name, finfo->short_name);
7289 if (strchr(force_shortname_chars, i)) {
7290 if (!finfo->short_name) {
7291 /* Shortname not created when it should be. */
7292 d_printf("(%s) ERROR: Shortname was not created for file %s containing %d\n",
7293 __location__, finfo->name, i);
7296 } else if (finfo->short_name){
7297 /* Shortname created when it should not be. */
7298 d_printf("(%s) ERROR: Shortname %s was created for file %s\n",
7299 __location__, finfo->short_name, finfo->name);
7303 return NT_STATUS_OK;
7306 static bool run_shortname_test(int dummy)
7308 static struct cli_state *cli;
7309 bool correct = True;
7315 printf("starting shortname test\n");
7317 if (!torture_open_connection(&cli, 0)) {
7321 cli_sockopt(cli, sockops);
7323 cli_list(cli, "\\shortname\\*", 0, shortname_del_fn, cli);
7324 cli_list(cli, "\\shortname\\*", FILE_ATTRIBUTE_DIRECTORY, shortname_del_fn, cli);
7325 cli_rmdir(cli, "\\shortname");
7327 status = cli_mkdir(cli, "\\shortname");
7328 if (!NT_STATUS_IS_OK(status)) {
7329 d_printf("(%s) cli_mkdir of \\shortname failed: %s\n",
7330 __location__, nt_errstr(status));
7335 strlcpy(fname, "\\shortname\\", sizeof(fname));
7336 strlcat(fname, "test .txt", sizeof(fname));
7340 for (i = 32; i < 128; i++) {
7341 uint16_t fnum = (uint16_t)-1;
7345 if (strchr(illegal_chars, i)) {
7350 status = cli_ntcreate(cli, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
7351 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum);
7352 if (!NT_STATUS_IS_OK(status)) {
7353 d_printf("(%s) cli_nt_create of %s failed: %s\n",
7354 __location__, fname, nt_errstr(status));
7358 cli_close(cli, fnum);
7361 status = cli_list(cli, "\\shortname\\test*.*", 0,
7362 shortname_list_fn, &s);
7363 if (s.matched != 1) {
7364 d_printf("(%s) failed to list %s: %s\n",
7365 __location__, fname, nt_errstr(status));
7370 status = cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7371 if (!NT_STATUS_IS_OK(status)) {
7372 d_printf("(%s) failed to delete %s: %s\n",
7373 __location__, fname, nt_errstr(status));
7386 cli_list(cli, "\\shortname\\*", 0, shortname_del_fn, cli);
7387 cli_list(cli, "\\shortname\\*", FILE_ATTRIBUTE_DIRECTORY, shortname_del_fn, cli);
7388 cli_rmdir(cli, "\\shortname");
7389 torture_close_connection(cli);
7393 static void pagedsearch_cb(struct tevent_req *req)
7396 struct tldap_message *msg;
7399 rc = tldap_search_paged_recv(req, talloc_tos(), &msg);
7400 if (rc != TLDAP_SUCCESS) {
7401 d_printf("tldap_search_paged_recv failed: %s\n",
7402 tldap_err2string(rc));
7405 if (tldap_msg_type(msg) != TLDAP_RES_SEARCH_ENTRY) {
7409 if (!tldap_entry_dn(msg, &dn)) {
7410 d_printf("tldap_entry_dn failed\n");
7413 d_printf("%s\n", dn);
7417 static bool run_tldap(int dummy)
7419 struct tldap_context *ld;
7422 struct sockaddr_storage addr;
7423 struct tevent_context *ev;
7424 struct tevent_req *req;
7428 if (!resolve_name(host, &addr, 0, false)) {
7429 d_printf("could not find host %s\n", host);
7432 status = open_socket_out(&addr, 389, 9999, &fd);
7433 if (!NT_STATUS_IS_OK(status)) {
7434 d_printf("open_socket_out failed: %s\n", nt_errstr(status));
7438 ld = tldap_context_create(talloc_tos(), fd);
7441 d_printf("tldap_context_create failed\n");
7445 rc = tldap_fetch_rootdse(ld);
7446 if (rc != TLDAP_SUCCESS) {
7447 d_printf("tldap_fetch_rootdse failed: %s\n",
7448 tldap_errstr(talloc_tos(), ld, rc));
7452 basedn = tldap_talloc_single_attribute(
7453 tldap_rootdse(ld), "defaultNamingContext", talloc_tos());
7454 if (basedn == NULL) {
7455 d_printf("no defaultNamingContext\n");
7458 d_printf("defaultNamingContext: %s\n", basedn);
7460 ev = tevent_context_init(talloc_tos());
7462 d_printf("tevent_context_init failed\n");
7466 req = tldap_search_paged_send(talloc_tos(), ev, ld, basedn,
7467 TLDAP_SCOPE_SUB, "(objectclass=*)",
7469 NULL, 0, NULL, 0, 0, 0, 0, 5);
7471 d_printf("tldap_search_paged_send failed\n");
7474 tevent_req_set_callback(req, pagedsearch_cb, NULL);
7476 tevent_req_poll(req, ev);
7480 /* test search filters against rootDSE */
7481 filter = "(&(|(name=samba)(nextRid<=10000000)(usnChanged>=10)(samba~=ambas)(!(name=s*m*a)))"
7482 "(|(name:=samba)(name:dn:2.5.13.5:=samba)(:dn:2.5.13.5:=samba)(!(name=*samba))))";
7484 rc = tldap_search(ld, "", TLDAP_SCOPE_BASE, filter,
7485 NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0,
7486 talloc_tos(), NULL, NULL);
7487 if (rc != TLDAP_SUCCESS) {
7488 d_printf("tldap_search with complex filter failed: %s\n",
7489 tldap_errstr(talloc_tos(), ld, rc));
7497 /* Torture test to ensure no regression of :
7498 https://bugzilla.samba.org/show_bug.cgi?id=7084
7501 static bool run_dir_createtime(int dummy)
7503 struct cli_state *cli;
7504 const char *dname = "\\testdir";
7505 const char *fname = "\\testdir\\testfile";
7507 struct timespec create_time;
7508 struct timespec create_time1;
7512 if (!torture_open_connection(&cli, 0)) {
7516 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7517 cli_rmdir(cli, dname);
7519 status = cli_mkdir(cli, dname);
7520 if (!NT_STATUS_IS_OK(status)) {
7521 printf("mkdir failed: %s\n", nt_errstr(status));
7525 status = cli_qpathinfo2(cli, dname, &create_time, NULL, NULL, NULL,
7527 if (!NT_STATUS_IS_OK(status)) {
7528 printf("cli_qpathinfo2 returned %s\n",
7533 /* Sleep 3 seconds, then create a file. */
7536 status = cli_open(cli, fname, O_RDWR | O_CREAT | O_EXCL,
7538 if (!NT_STATUS_IS_OK(status)) {
7539 printf("cli_open failed: %s\n", nt_errstr(status));
7543 status = cli_qpathinfo2(cli, dname, &create_time1, NULL, NULL, NULL,
7545 if (!NT_STATUS_IS_OK(status)) {
7546 printf("cli_qpathinfo2 (2) returned %s\n",
7551 if (timespec_compare(&create_time1, &create_time)) {
7552 printf("run_dir_createtime: create time was updated (error)\n");
7554 printf("run_dir_createtime: create time was not updated (correct)\n");
7560 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7561 cli_rmdir(cli, dname);
7562 if (!torture_close_connection(cli)) {
7569 static bool run_streamerror(int dummy)
7571 struct cli_state *cli;
7572 const char *dname = "\\testdir";
7573 const char *streamname =
7574 "testdir:{4c8cc155-6c1e-11d1-8e41-00c04fb9386d}:$DATA";
7576 time_t change_time, access_time, write_time;
7578 uint16_t mode, fnum;
7581 if (!torture_open_connection(&cli, 0)) {
7585 cli_unlink(cli, "\\testdir\\*", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
7586 cli_rmdir(cli, dname);
7588 status = cli_mkdir(cli, dname);
7589 if (!NT_STATUS_IS_OK(status)) {
7590 printf("mkdir failed: %s\n", nt_errstr(status));
7594 cli_qpathinfo1(cli, streamname, &change_time, &access_time, &write_time,
7596 status = cli_nt_error(cli);
7598 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
7599 printf("pathinfo returned %s, expected "
7600 "NT_STATUS_OBJECT_NAME_NOT_FOUND\n",
7605 status = cli_ntcreate(cli, streamname, 0x16,
7606 FILE_READ_DATA|FILE_READ_EA|
7607 FILE_READ_ATTRIBUTES|READ_CONTROL_ACCESS,
7608 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ,
7609 FILE_OPEN, 0, 0, &fnum);
7611 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
7612 printf("ntcreate returned %s, expected "
7613 "NT_STATUS_OBJECT_NAME_NOT_FOUND\n",
7619 cli_rmdir(cli, dname);
7623 static bool run_local_substitute(int dummy)
7627 ok &= subst_test("%U", "bla", "", -1, -1, "bla");
7628 ok &= subst_test("%u%U", "bla", "", -1, -1, "blabla");
7629 ok &= subst_test("%g", "", "", -1, -1, "NO_GROUP");
7630 ok &= subst_test("%G", "", "", -1, -1, "NO_GROUP");
7631 ok &= subst_test("%g", "", "", -1, 0, gidtoname(0));
7632 ok &= subst_test("%G", "", "", -1, 0, gidtoname(0));
7633 ok &= subst_test("%D%u", "u", "dom", -1, 0, "domu");
7634 ok &= subst_test("%i %I", "", "", -1, -1, "0.0.0.0 0.0.0.0");
7636 /* Different captialization rules in sub_basic... */
7638 ok &= (strcmp(talloc_sub_basic(talloc_tos(), "BLA", "dom", "%U%D"),
7644 static bool run_local_base64(int dummy)
7649 for (i=1; i<2000; i++) {
7650 DATA_BLOB blob1, blob2;
7653 blob1.data = talloc_array(talloc_tos(), uint8_t, i);
7655 generate_random_buffer(blob1.data, blob1.length);
7657 b64 = base64_encode_data_blob(talloc_tos(), blob1);
7659 d_fprintf(stderr, "base64_encode_data_blob failed "
7660 "for %d bytes\n", i);
7663 blob2 = base64_decode_data_blob(b64);
7666 if (data_blob_cmp(&blob1, &blob2)) {
7667 d_fprintf(stderr, "data_blob_cmp failed for %d "
7671 TALLOC_FREE(blob1.data);
7672 data_blob_free(&blob2);
7677 static bool run_local_gencache(int dummy)
7683 if (!gencache_set("foo", "bar", time(NULL) + 1000)) {
7684 d_printf("%s: gencache_set() failed\n", __location__);
7688 if (!gencache_get("foo", NULL, NULL)) {
7689 d_printf("%s: gencache_get() failed\n", __location__);
7693 if (!gencache_get("foo", &val, &tm)) {
7694 d_printf("%s: gencache_get() failed\n", __location__);
7698 if (strcmp(val, "bar") != 0) {
7699 d_printf("%s: gencache_get() returned %s, expected %s\n",
7700 __location__, val, "bar");
7707 if (!gencache_del("foo")) {
7708 d_printf("%s: gencache_del() failed\n", __location__);
7711 if (gencache_del("foo")) {
7712 d_printf("%s: second gencache_del() succeeded\n",
7717 if (gencache_get("foo", &val, &tm)) {
7718 d_printf("%s: gencache_get() on deleted entry "
7719 "succeeded\n", __location__);
7723 blob = data_blob_string_const_null("bar");
7724 tm = time(NULL) + 60;
7726 if (!gencache_set_data_blob("foo", &blob, tm)) {
7727 d_printf("%s: gencache_set_data_blob() failed\n", __location__);
7731 if (!gencache_get_data_blob("foo", &blob, NULL, NULL)) {
7732 d_printf("%s: gencache_get_data_blob() failed\n", __location__);
7736 if (strcmp((const char *)blob.data, "bar") != 0) {
7737 d_printf("%s: gencache_get_data_blob() returned %s, expected %s\n",
7738 __location__, (const char *)blob.data, "bar");
7739 data_blob_free(&blob);
7743 data_blob_free(&blob);
7745 if (!gencache_del("foo")) {
7746 d_printf("%s: gencache_del() failed\n", __location__);
7749 if (gencache_del("foo")) {
7750 d_printf("%s: second gencache_del() succeeded\n",
7755 if (gencache_get_data_blob("foo", &blob, NULL, NULL)) {
7756 d_printf("%s: gencache_get_data_blob() on deleted entry "
7757 "succeeded\n", __location__);
7764 static bool rbt_testval(struct db_context *db, const char *key,
7767 struct db_record *rec;
7768 TDB_DATA data = string_tdb_data(value);
7772 rec = db->fetch_locked(db, db, string_tdb_data(key));
7774 d_fprintf(stderr, "fetch_locked failed\n");
7777 status = rec->store(rec, data, 0);
7778 if (!NT_STATUS_IS_OK(status)) {
7779 d_fprintf(stderr, "store failed: %s\n", nt_errstr(status));
7784 rec = db->fetch_locked(db, db, string_tdb_data(key));
7786 d_fprintf(stderr, "second fetch_locked failed\n");
7789 if ((rec->value.dsize != data.dsize)
7790 || (memcmp(rec->value.dptr, data.dptr, data.dsize) != 0)) {
7791 d_fprintf(stderr, "Got wrong data back\n");
7801 static bool run_local_rbtree(int dummy)
7803 struct db_context *db;
7807 db = db_open_rbt(NULL);
7810 d_fprintf(stderr, "db_open_rbt failed\n");
7814 for (i=0; i<1000; i++) {
7817 if (asprintf(&key, "key%ld", random()) == -1) {
7820 if (asprintf(&value, "value%ld", random()) == -1) {
7825 if (!rbt_testval(db, key, value)) {
7832 if (asprintf(&value, "value%ld", random()) == -1) {
7837 if (!rbt_testval(db, key, value)) {
7856 local test for character set functions
7858 This is a very simple test for the functionality in convert_string_error()
7860 static bool run_local_convert_string(int dummy)
7862 TALLOC_CTX *tmp_ctx = talloc_new(NULL);
7863 const char *test_strings[2] = { "March", "M\303\244rz" };
7867 for (i=0; i<2; i++) {
7868 const char *str = test_strings[i];
7869 int len = strlen(str);
7870 size_t converted_size;
7873 memset(dst, 'X', sizeof(dst));
7875 /* first try with real source length */
7876 ret = convert_string_error(CH_UNIX, CH_UTF8,
7881 d_fprintf(stderr, "Failed to convert '%s' to CH_DISPLAY\n", str);
7885 if (converted_size != len) {
7886 d_fprintf(stderr, "Converted size of '%s' should be %d - got %d\n",
7887 str, len, (int)converted_size);
7891 if (strncmp(str, dst, converted_size) != 0) {
7892 d_fprintf(stderr, "Expected '%s' to match '%s'\n", str, dst);
7896 if (strlen(str) != converted_size) {
7897 d_fprintf(stderr, "Expected '%s' length %d - got %d\n", str,
7898 (int)strlen(str), (int)converted_size);
7902 if (dst[converted_size] != 'X') {
7903 d_fprintf(stderr, "Expected no termination of '%s'\n", dst);
7907 /* now with srclen==-1, this causes the nul to be
7909 ret = convert_string_error(CH_UNIX, CH_UTF8,
7914 d_fprintf(stderr, "Failed to convert '%s' to CH_DISPLAY\n", str);
7918 if (converted_size != len+1) {
7919 d_fprintf(stderr, "Converted size of '%s' should be %d - got %d\n",
7920 str, len, (int)converted_size);
7924 if (strncmp(str, dst, converted_size) != 0) {
7925 d_fprintf(stderr, "Expected '%s' to match '%s'\n", str, dst);
7929 if (len+1 != converted_size) {
7930 d_fprintf(stderr, "Expected '%s' length %d - got %d\n", str,
7931 len+1, (int)converted_size);
7935 if (dst[converted_size] != 'X') {
7936 d_fprintf(stderr, "Expected no termination of '%s'\n", dst);
7943 TALLOC_FREE(tmp_ctx);
7946 TALLOC_FREE(tmp_ctx);
7951 struct talloc_dict_test {
7955 static int talloc_dict_traverse_fn(DATA_BLOB key, void *data, void *priv)
7957 int *count = (int *)priv;
7962 static bool run_local_talloc_dict(int dummy)
7964 struct talloc_dict *dict;
7965 struct talloc_dict_test *t;
7968 dict = talloc_dict_init(talloc_tos());
7973 t = talloc(talloc_tos(), struct talloc_dict_test);
7980 if (!talloc_dict_set(dict, data_blob_const(&key, sizeof(key)), t)) {
7985 if (talloc_dict_traverse(dict, talloc_dict_traverse_fn, &count) != 0) {
7998 static bool run_local_string_to_sid(int dummy) {
8001 if (string_to_sid(&sid, "S--1-5-32-545")) {
8002 printf("allowing S--1-5-32-545\n");
8005 if (string_to_sid(&sid, "S-1-5-32-+545")) {
8006 printf("allowing S-1-5-32-+545\n");
8009 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")) {
8010 printf("allowing S-1-2-3-4-5-6-7-8-9-0-1-2-3-4-5-6-7-8-9-0\n");
8013 if (string_to_sid(&sid, "S-1-5-32-545-abc")) {
8014 printf("allowing S-1-5-32-545-abc\n");
8017 if (!string_to_sid(&sid, "S-1-5-32-545")) {
8018 printf("could not parse S-1-5-32-545\n");
8021 if (!dom_sid_equal(&sid, &global_sid_Builtin_Users)) {
8022 printf("mis-parsed S-1-5-32-545 as %s\n",
8023 sid_string_tos(&sid));
8029 static bool run_local_binary_to_sid(int dummy) {
8030 struct dom_sid *sid = talloc(NULL, struct dom_sid);
8031 static const char good_binary_sid[] = {
8032 0x1, /* revision number */
8034 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, /* id_auth */
8035 0x1, 0x1, 0x1, 0x1, /* auth[0] */
8036 0x1, 0x1, 0x1, 0x1, /* auth[1] */
8037 0x1, 0x1, 0x1, 0x1, /* auth[2] */
8038 0x1, 0x1, 0x1, 0x1, /* auth[3] */
8039 0x1, 0x1, 0x1, 0x1, /* auth[4] */
8040 0x1, 0x1, 0x1, 0x1, /* auth[5] */
8041 0x1, 0x1, 0x1, 0x1, /* auth[6] */
8042 0x1, 0x1, 0x1, 0x1, /* auth[7] */
8043 0x1, 0x1, 0x1, 0x1, /* auth[8] */
8044 0x1, 0x1, 0x1, 0x1, /* auth[9] */
8045 0x1, 0x1, 0x1, 0x1, /* auth[10] */
8046 0x1, 0x1, 0x1, 0x1, /* auth[11] */
8047 0x1, 0x1, 0x1, 0x1, /* auth[12] */
8048 0x1, 0x1, 0x1, 0x1, /* auth[13] */
8049 0x1, 0x1, 0x1, 0x1, /* auth[14] */
8052 static const char long_binary_sid[] = {
8053 0x1, /* revision number */
8055 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, /* id_auth */
8056 0x1, 0x1, 0x1, 0x1, /* auth[0] */
8057 0x1, 0x1, 0x1, 0x1, /* auth[1] */
8058 0x1, 0x1, 0x1, 0x1, /* auth[2] */
8059 0x1, 0x1, 0x1, 0x1, /* auth[3] */
8060 0x1, 0x1, 0x1, 0x1, /* auth[4] */
8061 0x1, 0x1, 0x1, 0x1, /* auth[5] */
8062 0x1, 0x1, 0x1, 0x1, /* auth[6] */
8063 0x1, 0x1, 0x1, 0x1, /* auth[7] */
8064 0x1, 0x1, 0x1, 0x1, /* auth[8] */
8065 0x1, 0x1, 0x1, 0x1, /* auth[9] */
8066 0x1, 0x1, 0x1, 0x1, /* auth[10] */
8067 0x1, 0x1, 0x1, 0x1, /* auth[11] */
8068 0x1, 0x1, 0x1, 0x1, /* auth[12] */
8069 0x1, 0x1, 0x1, 0x1, /* auth[13] */
8070 0x1, 0x1, 0x1, 0x1, /* auth[14] */
8071 0x1, 0x1, 0x1, 0x1, /* auth[15] */
8072 0x1, 0x1, 0x1, 0x1, /* auth[16] */
8073 0x1, 0x1, 0x1, 0x1, /* auth[17] */
8076 static const char long_binary_sid2[] = {
8077 0x1, /* revision number */
8079 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, /* id_auth */
8080 0x1, 0x1, 0x1, 0x1, /* auth[0] */
8081 0x1, 0x1, 0x1, 0x1, /* auth[1] */
8082 0x1, 0x1, 0x1, 0x1, /* auth[2] */
8083 0x1, 0x1, 0x1, 0x1, /* auth[3] */
8084 0x1, 0x1, 0x1, 0x1, /* auth[4] */
8085 0x1, 0x1, 0x1, 0x1, /* auth[5] */
8086 0x1, 0x1, 0x1, 0x1, /* auth[6] */
8087 0x1, 0x1, 0x1, 0x1, /* auth[7] */
8088 0x1, 0x1, 0x1, 0x1, /* auth[8] */
8089 0x1, 0x1, 0x1, 0x1, /* auth[9] */
8090 0x1, 0x1, 0x1, 0x1, /* auth[10] */
8091 0x1, 0x1, 0x1, 0x1, /* auth[11] */
8092 0x1, 0x1, 0x1, 0x1, /* auth[12] */
8093 0x1, 0x1, 0x1, 0x1, /* auth[13] */
8094 0x1, 0x1, 0x1, 0x1, /* auth[14] */
8095 0x1, 0x1, 0x1, 0x1, /* auth[15] */
8096 0x1, 0x1, 0x1, 0x1, /* auth[16] */
8097 0x1, 0x1, 0x1, 0x1, /* auth[17] */
8098 0x1, 0x1, 0x1, 0x1, /* auth[18] */
8099 0x1, 0x1, 0x1, 0x1, /* auth[19] */
8100 0x1, 0x1, 0x1, 0x1, /* auth[20] */
8101 0x1, 0x1, 0x1, 0x1, /* auth[21] */
8102 0x1, 0x1, 0x1, 0x1, /* auth[22] */
8103 0x1, 0x1, 0x1, 0x1, /* auth[23] */
8104 0x1, 0x1, 0x1, 0x1, /* auth[24] */
8105 0x1, 0x1, 0x1, 0x1, /* auth[25] */
8106 0x1, 0x1, 0x1, 0x1, /* auth[26] */
8107 0x1, 0x1, 0x1, 0x1, /* auth[27] */
8108 0x1, 0x1, 0x1, 0x1, /* auth[28] */
8109 0x1, 0x1, 0x1, 0x1, /* auth[29] */
8110 0x1, 0x1, 0x1, 0x1, /* auth[30] */
8111 0x1, 0x1, 0x1, 0x1, /* auth[31] */
8114 if (!sid_parse(good_binary_sid, sizeof(good_binary_sid), sid)) {
8117 if (sid_parse(long_binary_sid2, sizeof(long_binary_sid2), sid)) {
8120 if (sid_parse(long_binary_sid, sizeof(long_binary_sid), sid)) {
8126 /* Split a path name into filename and stream name components. Canonicalise
8127 * such that an implicit $DATA token is always explicit.
8129 * The "specification" of this function can be found in the
8130 * run_local_stream_name() function in torture.c, I've tried those
8131 * combinations against a W2k3 server.
8134 static NTSTATUS split_ntfs_stream_name(TALLOC_CTX *mem_ctx, const char *fname,
8135 char **pbase, char **pstream)
8138 char *stream = NULL;
8139 char *sname; /* stream name */
8140 const char *stype; /* stream type */
8142 DEBUG(10, ("split_ntfs_stream_name called for [%s]\n", fname));
8144 sname = strchr_m(fname, ':');
8146 if (lp_posix_pathnames() || (sname == NULL)) {
8147 if (pbase != NULL) {
8148 base = talloc_strdup(mem_ctx, fname);
8149 NT_STATUS_HAVE_NO_MEMORY(base);
8154 if (pbase != NULL) {
8155 base = talloc_strndup(mem_ctx, fname, PTR_DIFF(sname, fname));
8156 NT_STATUS_HAVE_NO_MEMORY(base);
8161 stype = strchr_m(sname, ':');
8163 if (stype == NULL) {
8164 sname = talloc_strdup(mem_ctx, sname);
8168 if (strcasecmp_m(stype, ":$DATA") != 0) {
8170 * If there is an explicit stream type, so far we only
8171 * allow $DATA. Is there anything else allowed? -- vl
8173 DEBUG(10, ("[%s] is an invalid stream type\n", stype));
8175 return NT_STATUS_OBJECT_NAME_INVALID;
8177 sname = talloc_strndup(mem_ctx, sname, PTR_DIFF(stype, sname));
8181 if (sname == NULL) {
8183 return NT_STATUS_NO_MEMORY;
8186 if (sname[0] == '\0') {
8188 * no stream name, so no stream
8193 if (pstream != NULL) {
8194 stream = talloc_asprintf(mem_ctx, "%s:%s", sname, stype);
8195 if (stream == NULL) {
8198 return NT_STATUS_NO_MEMORY;
8201 * upper-case the type field
8203 strupper_m(strchr_m(stream, ':')+1);
8207 if (pbase != NULL) {
8210 if (pstream != NULL) {
8213 return NT_STATUS_OK;
8216 static bool test_stream_name(const char *fname, const char *expected_base,
8217 const char *expected_stream,
8218 NTSTATUS expected_status)
8222 char *stream = NULL;
8224 status = split_ntfs_stream_name(talloc_tos(), fname, &base, &stream);
8225 if (!NT_STATUS_EQUAL(status, expected_status)) {
8229 if (!NT_STATUS_IS_OK(status)) {
8233 if (base == NULL) goto error;
8235 if (strcmp(expected_base, base) != 0) goto error;
8237 if ((expected_stream != NULL) && (stream == NULL)) goto error;
8238 if ((expected_stream == NULL) && (stream != NULL)) goto error;
8240 if ((stream != NULL) && (strcmp(expected_stream, stream) != 0))
8244 TALLOC_FREE(stream);
8248 d_fprintf(stderr, "Do test_stream(%s, %s, %s, %s)\n",
8249 fname, expected_base ? expected_base : "<NULL>",
8250 expected_stream ? expected_stream : "<NULL>",
8251 nt_errstr(expected_status));
8252 d_fprintf(stderr, "-> base=%s, stream=%s, status=%s\n",
8253 base ? base : "<NULL>", stream ? stream : "<NULL>",
8256 TALLOC_FREE(stream);
8260 static bool run_local_stream_name(int dummy)
8264 ret &= test_stream_name(
8265 "bla", "bla", NULL, NT_STATUS_OK);
8266 ret &= test_stream_name(
8267 "bla::$DATA", "bla", NULL, NT_STATUS_OK);
8268 ret &= test_stream_name(
8269 "bla:blub:", "bla", NULL, NT_STATUS_OBJECT_NAME_INVALID);
8270 ret &= test_stream_name(
8271 "bla::", NULL, NULL, NT_STATUS_OBJECT_NAME_INVALID);
8272 ret &= test_stream_name(
8273 "bla::123", "bla", NULL, NT_STATUS_OBJECT_NAME_INVALID);
8274 ret &= test_stream_name(
8275 "bla:$DATA", "bla", "$DATA:$DATA", NT_STATUS_OK);
8276 ret &= test_stream_name(
8277 "bla:x:$DATA", "bla", "x:$DATA", NT_STATUS_OK);
8278 ret &= test_stream_name(
8279 "bla:x", "bla", "x:$DATA", NT_STATUS_OK);
8284 static bool data_blob_equal(DATA_BLOB a, DATA_BLOB b)
8286 if (a.length != b.length) {
8287 printf("a.length=%d != b.length=%d\n",
8288 (int)a.length, (int)b.length);
8291 if (memcmp(a.data, b.data, a.length) != 0) {
8292 printf("a.data and b.data differ\n");
8298 static bool run_local_memcache(int dummy)
8300 struct memcache *cache;
8302 DATA_BLOB d1, d2, d3;
8303 DATA_BLOB v1, v2, v3;
8305 TALLOC_CTX *mem_ctx;
8307 size_t size1, size2;
8310 cache = memcache_init(NULL, 100);
8312 if (cache == NULL) {
8313 printf("memcache_init failed\n");
8317 d1 = data_blob_const("d1", 2);
8318 d2 = data_blob_const("d2", 2);
8319 d3 = data_blob_const("d3", 2);
8321 k1 = data_blob_const("d1", 2);
8322 k2 = data_blob_const("d2", 2);
8324 memcache_add(cache, STAT_CACHE, k1, d1);
8325 memcache_add(cache, GETWD_CACHE, k2, d2);
8327 if (!memcache_lookup(cache, STAT_CACHE, k1, &v1)) {
8328 printf("could not find k1\n");
8331 if (!data_blob_equal(d1, v1)) {
8335 if (!memcache_lookup(cache, GETWD_CACHE, k2, &v2)) {
8336 printf("could not find k2\n");
8339 if (!data_blob_equal(d2, v2)) {
8343 memcache_add(cache, STAT_CACHE, k1, d3);
8345 if (!memcache_lookup(cache, STAT_CACHE, k1, &v3)) {
8346 printf("could not find replaced k1\n");
8349 if (!data_blob_equal(d3, v3)) {
8353 memcache_add(cache, GETWD_CACHE, k1, d1);
8355 if (memcache_lookup(cache, GETWD_CACHE, k2, &v2)) {
8356 printf("Did find k2, should have been purged\n");
8362 cache = memcache_init(NULL, 0);
8364 mem_ctx = talloc_init("foo");
8366 str1 = talloc_strdup(mem_ctx, "string1");
8367 str2 = talloc_strdup(mem_ctx, "string2");
8369 memcache_add_talloc(cache, SINGLETON_CACHE_TALLOC,
8370 data_blob_string_const("torture"), &str1);
8371 size1 = talloc_total_size(cache);
8373 memcache_add_talloc(cache, SINGLETON_CACHE_TALLOC,
8374 data_blob_string_const("torture"), &str2);
8375 size2 = talloc_total_size(cache);
8377 printf("size1=%d, size2=%d\n", (int)size1, (int)size2);
8379 if (size2 > size1) {
8380 printf("memcache leaks memory!\n");
8390 static void wbclient_done(struct tevent_req *req)
8393 struct winbindd_response *wb_resp;
8394 int *i = (int *)tevent_req_callback_data_void(req);
8396 wbc_err = wb_trans_recv(req, req, &wb_resp);
8399 d_printf("wb_trans_recv %d returned %s\n", *i, wbcErrorString(wbc_err));
8402 static bool run_local_wbclient(int dummy)
8404 struct event_context *ev;
8405 struct wb_context **wb_ctx;
8406 struct winbindd_request wb_req;
8407 bool result = false;
8410 BlockSignals(True, SIGPIPE);
8412 ev = tevent_context_init_byname(talloc_tos(), "epoll");
8417 wb_ctx = talloc_array(ev, struct wb_context *, nprocs);
8418 if (wb_ctx == NULL) {
8422 ZERO_STRUCT(wb_req);
8423 wb_req.cmd = WINBINDD_PING;
8425 d_printf("nprocs=%d, numops=%d\n", (int)nprocs, (int)torture_numops);
8427 for (i=0; i<nprocs; i++) {
8428 wb_ctx[i] = wb_context_init(ev, NULL);
8429 if (wb_ctx[i] == NULL) {
8432 for (j=0; j<torture_numops; j++) {
8433 struct tevent_req *req;
8434 req = wb_trans_send(ev, ev, wb_ctx[i],
8435 (j % 2) == 0, &wb_req);
8439 tevent_req_set_callback(req, wbclient_done, &i);
8445 while (i < nprocs * torture_numops) {
8446 tevent_loop_once(ev);
8455 static void getaddrinfo_finished(struct tevent_req *req)
8457 char *name = (char *)tevent_req_callback_data_void(req);
8458 struct addrinfo *ainfo;
8461 res = getaddrinfo_recv(req, &ainfo);
8463 d_printf("gai(%s) returned %s\n", name, gai_strerror(res));
8466 d_printf("gai(%s) succeeded\n", name);
8467 freeaddrinfo(ainfo);
8470 static bool run_getaddrinfo_send(int dummy)
8472 TALLOC_CTX *frame = talloc_stackframe();
8473 struct fncall_context *ctx;
8474 struct tevent_context *ev;
8475 bool result = false;
8476 const char *names[4] = { "www.samba.org", "notfound.samba.org",
8477 "www.slashdot.org", "heise.de" };
8478 struct tevent_req *reqs[4];
8481 ev = event_context_init(frame);
8486 ctx = fncall_context_init(frame, 4);
8488 for (i=0; i<ARRAY_SIZE(names); i++) {
8489 reqs[i] = getaddrinfo_send(frame, ev, ctx, names[i], NULL,
8491 if (reqs[i] == NULL) {
8494 tevent_req_set_callback(reqs[i], getaddrinfo_finished,
8495 discard_const_p(void, names[i]));
8498 for (i=0; i<ARRAY_SIZE(reqs); i++) {
8499 tevent_loop_once(ev);
8508 static bool dbtrans_inc(struct db_context *db)
8510 struct db_record *rec;
8515 rec = db->fetch_locked(db, db, string_term_tdb_data("transtest"));
8517 printf(__location__ "fetch_lock failed\n");
8521 if (rec->value.dsize != sizeof(uint32_t)) {
8522 printf(__location__ "value.dsize = %d\n",
8523 (int)rec->value.dsize);
8527 val = (uint32_t *)rec->value.dptr;
8530 status = rec->store(rec, make_tdb_data((uint8_t *)val,
8533 if (!NT_STATUS_IS_OK(status)) {
8534 printf(__location__ "store failed: %s\n",
8545 static bool run_local_dbtrans(int dummy)
8547 struct db_context *db;
8548 struct db_record *rec;
8553 db = db_open(talloc_tos(), "transtest.tdb", 0, TDB_DEFAULT,
8554 O_RDWR|O_CREAT, 0600);
8556 printf("Could not open transtest.db\n");
8560 res = db->transaction_start(db);
8562 printf(__location__ "transaction_start failed\n");
8566 rec = db->fetch_locked(db, db, string_term_tdb_data("transtest"));
8568 printf(__location__ "fetch_lock failed\n");
8572 if (rec->value.dptr == NULL) {
8574 status = rec->store(
8575 rec, make_tdb_data((uint8_t *)&initial,
8578 if (!NT_STATUS_IS_OK(status)) {
8579 printf(__location__ "store returned %s\n",
8587 res = db->transaction_commit(db);
8589 printf(__location__ "transaction_commit failed\n");
8597 res = db->transaction_start(db);
8599 printf(__location__ "transaction_start failed\n");
8603 if (!dbwrap_fetch_uint32(db, "transtest", &val)) {
8604 printf(__location__ "dbwrap_fetch_uint32 failed\n");
8608 for (i=0; i<10; i++) {
8609 if (!dbtrans_inc(db)) {
8614 if (!dbwrap_fetch_uint32(db, "transtest", &val2)) {
8615 printf(__location__ "dbwrap_fetch_uint32 failed\n");
8619 if (val2 != val + 10) {
8620 printf(__location__ "val=%d, val2=%d\n",
8621 (int)val, (int)val2);
8625 printf("val2=%d\r", val2);
8627 res = db->transaction_commit(db);
8629 printf(__location__ "transaction_commit failed\n");
8639 * Just a dummy test to be run under a debugger. There's no real way
8640 * to inspect the tevent_select specific function from outside of
8644 static bool run_local_tevent_select(int dummy)
8646 struct tevent_context *ev;
8647 struct tevent_fd *fd1, *fd2;
8648 bool result = false;
8650 ev = tevent_context_init_byname(NULL, "select");
8652 d_fprintf(stderr, "tevent_context_init_byname failed\n");
8656 fd1 = tevent_add_fd(ev, ev, 2, 0, NULL, NULL);
8658 d_fprintf(stderr, "tevent_add_fd failed\n");
8661 fd2 = tevent_add_fd(ev, ev, 3, 0, NULL, NULL);
8663 d_fprintf(stderr, "tevent_add_fd failed\n");
8668 fd2 = tevent_add_fd(ev, ev, 1, 0, NULL, NULL);
8670 d_fprintf(stderr, "tevent_add_fd failed\n");
8680 static double create_procs(bool (*fn)(int), bool *result)
8683 volatile pid_t *child_status;
8684 volatile bool *child_status_out;
8687 struct timeval start;
8691 child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*nprocs);
8692 if (!child_status) {
8693 printf("Failed to setup shared memory\n");
8697 child_status_out = (volatile bool *)shm_setup(sizeof(bool)*nprocs);
8698 if (!child_status_out) {
8699 printf("Failed to setup result status shared memory\n");
8703 for (i = 0; i < nprocs; i++) {
8704 child_status[i] = 0;
8705 child_status_out[i] = True;
8708 start = timeval_current();
8710 for (i=0;i<nprocs;i++) {
8713 pid_t mypid = getpid();
8714 sys_srandom(((int)mypid) ^ ((int)time(NULL)));
8716 slprintf(myname,sizeof(myname),"CLIENT%d", i);
8719 if (torture_open_connection(¤t_cli, i)) break;
8721 printf("pid %d failed to start\n", (int)getpid());
8727 child_status[i] = getpid();
8729 while (child_status[i] && timeval_elapsed(&start) < 5) smb_msleep(2);
8731 child_status_out[i] = fn(i);
8738 for (i=0;i<nprocs;i++) {
8739 if (child_status[i]) synccount++;
8741 if (synccount == nprocs) break;
8743 } while (timeval_elapsed(&start) < 30);
8745 if (synccount != nprocs) {
8746 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs, synccount);
8748 return timeval_elapsed(&start);
8751 /* start the client load */
8752 start = timeval_current();
8754 for (i=0;i<nprocs;i++) {
8755 child_status[i] = 0;
8758 printf("%d clients started\n", nprocs);
8760 for (i=0;i<nprocs;i++) {
8761 while (waitpid(0, &status, 0) == -1 && errno == EINTR) /* noop */ ;
8766 for (i=0;i<nprocs;i++) {
8767 if (!child_status_out[i]) {
8771 return timeval_elapsed(&start);
8774 #define FLAG_MULTIPROC 1
8781 {"FDPASS", run_fdpasstest, 0},
8782 {"LOCK1", run_locktest1, 0},
8783 {"LOCK2", run_locktest2, 0},
8784 {"LOCK3", run_locktest3, 0},
8785 {"LOCK4", run_locktest4, 0},
8786 {"LOCK5", run_locktest5, 0},
8787 {"LOCK6", run_locktest6, 0},
8788 {"LOCK7", run_locktest7, 0},
8789 {"LOCK8", run_locktest8, 0},
8790 {"LOCK9", run_locktest9, 0},
8791 {"UNLINK", run_unlinktest, 0},
8792 {"BROWSE", run_browsetest, 0},
8793 {"ATTR", run_attrtest, 0},
8794 {"TRANS2", run_trans2test, 0},
8795 {"MAXFID", run_maxfidtest, FLAG_MULTIPROC},
8796 {"TORTURE",run_torture, FLAG_MULTIPROC},
8797 {"RANDOMIPC", run_randomipc, 0},
8798 {"NEGNOWAIT", run_negprot_nowait, 0},
8799 {"NBENCH", run_nbench, 0},
8800 {"NBENCH2", run_nbench2, 0},
8801 {"OPLOCK1", run_oplock1, 0},
8802 {"OPLOCK2", run_oplock2, 0},
8803 {"OPLOCK4", run_oplock4, 0},
8804 {"DIR", run_dirtest, 0},
8805 {"DIR1", run_dirtest1, 0},
8806 {"DIR-CREATETIME", run_dir_createtime, 0},
8807 {"DENY1", torture_denytest1, 0},
8808 {"DENY2", torture_denytest2, 0},
8809 {"TCON", run_tcon_test, 0},
8810 {"TCONDEV", run_tcon_devtype_test, 0},
8811 {"RW1", run_readwritetest, 0},
8812 {"RW2", run_readwritemulti, FLAG_MULTIPROC},
8813 {"RW3", run_readwritelarge, 0},
8814 {"RW-SIGNING", run_readwritelarge_signtest, 0},
8815 {"OPEN", run_opentest, 0},
8816 {"POSIX", run_simple_posix_open_test, 0},
8817 {"POSIX-APPEND", run_posix_append, 0},
8818 {"CASE-INSENSITIVE-CREATE", run_case_insensitive_create, 0},
8819 {"ASYNC-ECHO", run_async_echo, 0},
8820 { "UID-REGRESSION-TEST", run_uid_regression_test, 0},
8821 { "SHORTNAME-TEST", run_shortname_test, 0},
8822 { "ADDRCHANGE", run_addrchange, 0},
8824 {"OPENATTR", run_openattrtest, 0},
8826 {"XCOPY", run_xcopy, 0},
8827 {"RENAME", run_rename, 0},
8828 {"DELETE", run_deletetest, 0},
8829 {"DELETE-LN", run_deletetest_ln, 0},
8830 {"PROPERTIES", run_properties, 0},
8831 {"MANGLE", torture_mangle, 0},
8832 {"MANGLE1", run_mangle1, 0},
8833 {"W2K", run_w2ktest, 0},
8834 {"TRANS2SCAN", torture_trans2_scan, 0},
8835 {"NTTRANSSCAN", torture_nttrans_scan, 0},
8836 {"UTABLE", torture_utable, 0},
8837 {"CASETABLE", torture_casetable, 0},
8838 {"ERRMAPEXTRACT", run_error_map_extract, 0},
8839 {"PIPE_NUMBER", run_pipe_number, 0},
8840 {"TCON2", run_tcon2_test, 0},
8841 {"IOCTL", torture_ioctl_test, 0},
8842 {"CHKPATH", torture_chkpath_test, 0},
8843 {"FDSESS", run_fdsesstest, 0},
8844 { "EATEST", run_eatest, 0},
8845 { "SESSSETUP_BENCH", run_sesssetup_bench, 0},
8846 { "CHAIN1", run_chain1, 0},
8847 { "CHAIN2", run_chain2, 0},
8848 { "WINDOWS-WRITE", run_windows_write, 0},
8849 { "NTTRANS-CREATE", run_nttrans_create, 0},
8850 { "CLI_ECHO", run_cli_echo, 0},
8851 { "GETADDRINFO", run_getaddrinfo_send, 0},
8852 { "TLDAP", run_tldap },
8853 { "STREAMERROR", run_streamerror },
8854 { "NOTIFY-BENCH", run_notify_bench },
8855 { "BAD-NBT-SESSION", run_bad_nbt_session },
8856 { "SMB-ANY-CONNECT", run_smb_any_connect },
8857 { "NOTIFY-ONLINE", run_notify_online },
8858 { "SMB2-BASIC", run_smb2_basic },
8859 { "LOCAL-SUBSTITUTE", run_local_substitute, 0},
8860 { "LOCAL-GENCACHE", run_local_gencache, 0},
8861 { "LOCAL-TALLOC-DICT", run_local_talloc_dict, 0},
8862 { "LOCAL-BASE64", run_local_base64, 0},
8863 { "LOCAL-RBTREE", run_local_rbtree, 0},
8864 { "LOCAL-MEMCACHE", run_local_memcache, 0},
8865 { "LOCAL-STREAM-NAME", run_local_stream_name, 0},
8866 { "LOCAL-WBCLIENT", run_local_wbclient, 0},
8867 { "LOCAL-string_to_sid", run_local_string_to_sid, 0},
8868 { "LOCAL-binary_to_sid", run_local_binary_to_sid, 0},
8869 { "LOCAL-DBTRANS", run_local_dbtrans, 0},
8870 { "LOCAL-TEVENT-SELECT", run_local_tevent_select, 0},
8871 { "LOCAL-CONVERT-STRING", run_local_convert_string, 0},
8872 { "LOCAL-CONV-AUTH-INFO", run_local_conv_auth_info, 0},
8877 /****************************************************************************
8878 run a specified test or "ALL"
8879 ****************************************************************************/
8880 static bool run_test(const char *name)
8887 if (strequal(name,"ALL")) {
8888 for (i=0;torture_ops[i].name;i++) {
8889 run_test(torture_ops[i].name);
8894 for (i=0;torture_ops[i].name;i++) {
8895 fstr_sprintf(randomfname, "\\XX%x",
8896 (unsigned)random());
8898 if (strequal(name, torture_ops[i].name)) {
8900 printf("Running %s\n", name);
8901 if (torture_ops[i].flags & FLAG_MULTIPROC) {
8902 t = create_procs(torture_ops[i].fn, &result);
8905 printf("TEST %s FAILED!\n", name);
8908 struct timeval start;
8909 start = timeval_current();
8910 if (!torture_ops[i].fn(0)) {
8912 printf("TEST %s FAILED!\n", name);
8914 t = timeval_elapsed(&start);
8916 printf("%s took %g secs\n\n", name, t);
8921 printf("Did not find a test named %s\n", name);
8929 static void usage(void)
8933 printf("WARNING samba4 test suite is much more complete nowadays.\n");
8934 printf("Please use samba4 torture.\n\n");
8936 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
8938 printf("\t-d debuglevel\n");
8939 printf("\t-U user%%pass\n");
8940 printf("\t-k use kerberos\n");
8941 printf("\t-N numprocs\n");
8942 printf("\t-n my_netbios_name\n");
8943 printf("\t-W workgroup\n");
8944 printf("\t-o num_operations\n");
8945 printf("\t-O socket_options\n");
8946 printf("\t-m maximum protocol\n");
8947 printf("\t-L use oplocks\n");
8948 printf("\t-c CLIENT.TXT specify client load file for NBENCH\n");
8949 printf("\t-A showall\n");
8950 printf("\t-p port\n");
8951 printf("\t-s seed\n");
8952 printf("\t-b unclist_filename specify multiple shares for multiple connections\n");
8953 printf("\t-f filename filename to test\n");
8956 printf("tests are:");
8957 for (i=0;torture_ops[i].name;i++) {
8958 printf(" %s", torture_ops[i].name);
8962 printf("default test is ALL\n");
8967 /****************************************************************************
8969 ****************************************************************************/
8970 int main(int argc,char *argv[])
8976 bool correct = True;
8977 TALLOC_CTX *frame = talloc_stackframe();
8978 int seed = time(NULL);
8980 #ifdef HAVE_SETBUFFER
8981 setbuffer(stdout, NULL, 0);
8984 setup_logging("smbtorture", DEBUG_STDOUT);
8988 if (is_default_dyn_CONFIGFILE()) {
8989 if(getenv("SMB_CONF_PATH")) {
8990 set_dyn_CONFIGFILE(getenv("SMB_CONF_PATH"));
8993 lp_load_global(get_dyn_CONFIGFILE());
9000 for(p = argv[1]; *p; p++)
9004 if (strncmp(argv[1], "//", 2)) {
9008 fstrcpy(host, &argv[1][2]);
9009 p = strchr_m(&host[2],'/');
9014 fstrcpy(share, p+1);
9016 fstrcpy(myname, get_myname(talloc_tos()));
9018 fprintf(stderr, "Failed to get my hostname.\n");
9022 if (*username == 0 && getenv("LOGNAME")) {
9023 fstrcpy(username,getenv("LOGNAME"));
9029 fstrcpy(workgroup, lp_workgroup());
9031 while ((opt = getopt(argc, argv, "p:hW:U:n:N:O:o:m:Ll:d:Aec:ks:b:B:f:"))
9035 port_to_use = atoi(optarg);
9038 seed = atoi(optarg);
9041 fstrcpy(workgroup,optarg);
9044 max_protocol = interpret_protocol(optarg, max_protocol);
9047 nprocs = atoi(optarg);
9050 torture_numops = atoi(optarg);
9053 lp_set_cmdline("log level", optarg);
9062 local_path = optarg;
9065 torture_showall = True;
9068 fstrcpy(myname, optarg);
9071 client_txt = optarg;
9078 use_kerberos = True;
9080 d_printf("No kerberos support compiled in\n");
9086 fstrcpy(username,optarg);
9087 p = strchr_m(username,'%');
9090 fstrcpy(password, p+1);
9095 fstrcpy(multishare_conn_fname, optarg);
9096 use_multishare_conn = True;
9099 torture_blocksize = atoi(optarg);
9102 test_filename = SMB_STRDUP(optarg);
9105 printf("Unknown option %c (%d)\n", (char)opt, opt);
9110 d_printf("using seed %d\n", seed);
9114 if(use_kerberos && !gotuser) gotpass = True;
9117 p = getpass("Password:");
9119 fstrcpy(password, p);
9124 printf("host=%s share=%s user=%s myname=%s\n",
9125 host, share, username, myname);
9127 if (argc == optind) {
9128 correct = run_test("ALL");
9130 for (i=optind;i<argc;i++) {
9131 if (!run_test(argv[i])) {