2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1997-1998
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "wbc_async.h"
26 static fstring host, workgroup, share, password, username, myname;
27 static int max_protocol = PROTOCOL_NT1;
28 static const char *sockops="TCP_NODELAY";
30 static int port_to_use=0;
31 int torture_numops=100;
32 int torture_blocksize=1024*1024;
33 static int procnum; /* records process count number when forking */
34 static struct cli_state *current_cli;
35 static fstring randomfname;
36 static bool use_oplocks;
37 static bool use_level_II_oplocks;
38 static const char *client_txt = "client_oplocks.txt";
39 static bool use_kerberos;
40 static fstring multishare_conn_fname;
41 static bool use_multishare_conn = False;
42 static bool do_encrypt;
44 bool torture_showall = False;
46 static double create_procs(bool (*fn)(int), bool *result);
49 static struct timeval tp1,tp2;
52 void start_timer(void)
57 double end_timer(void)
60 return((tp2.tv_sec - tp1.tv_sec) +
61 (tp2.tv_usec - tp1.tv_usec)*1.0e-6);
65 /* return a pointer to a anonymous shared memory segment of size "size"
66 which will persist across fork() but will disappear when all processes
69 The memory is not zeroed
71 This function uses system5 shared memory. It takes advantage of a property
72 that the memory is not destroyed if it is attached when the id is removed
74 void *shm_setup(int size)
79 shmid = shmget(IPC_PRIVATE, size, S_IRUSR | S_IWUSR);
81 printf("can't get shared memory\n");
84 ret = (void *)shmat(shmid, 0, 0);
85 if (!ret || ret == (void *)-1) {
86 printf("can't attach to shared memory\n");
89 /* the following releases the ipc, but note that this process
90 and all its children will still have access to the memory, its
91 just that the shmid is no longer valid for other shm calls. This
92 means we don't leave behind lots of shm segments after we exit
94 See Stevens "advanced programming in unix env" for details
96 shmctl(shmid, IPC_RMID, 0);
101 /********************************************************************
102 Ensure a connection is encrypted.
103 ********************************************************************/
105 static bool force_cli_encryption(struct cli_state *c,
106 const char *sharename)
109 uint32 caplow, caphigh;
112 if (!SERVER_HAS_UNIX_CIFS(c)) {
113 d_printf("Encryption required and "
114 "server that doesn't support "
115 "UNIX extensions - failing connect\n");
119 if (!cli_unix_extensions_version(c, &major, &minor, &caplow, &caphigh)) {
120 d_printf("Encryption required and "
121 "can't get UNIX CIFS extensions "
122 "version from server.\n");
126 if (!(caplow & CIFS_UNIX_TRANSPORT_ENCRYPTION_CAP)) {
127 d_printf("Encryption required and "
128 "share %s doesn't support "
129 "encryption.\n", sharename);
133 if (c->use_kerberos) {
134 status = cli_gss_smb_encryption_start(c);
136 status = cli_raw_ntlm_smb_encryption_start(c,
142 if (!NT_STATUS_IS_OK(status)) {
143 d_printf("Encryption required and "
144 "setup failed with error %s.\n",
153 static struct cli_state *open_nbt_connection(void)
155 struct nmb_name called, calling;
156 struct sockaddr_storage ss;
160 make_nmb_name(&calling, myname, 0x0);
161 make_nmb_name(&called , host, 0x20);
165 if (!(c = cli_initialise())) {
166 printf("Failed initialize cli_struct to connect with %s\n", host);
170 c->port = port_to_use;
172 status = cli_connect(c, host, &ss);
173 if (!NT_STATUS_IS_OK(status)) {
174 printf("Failed to connect with %s. Error %s\n", host, nt_errstr(status) );
178 c->use_kerberos = use_kerberos;
180 c->timeout = 120000; /* set a really long timeout (2 minutes) */
181 if (use_oplocks) c->use_oplocks = True;
182 if (use_level_II_oplocks) c->use_level_II_oplocks = True;
184 if (!cli_session_request(c, &calling, &called)) {
186 * Well, that failed, try *SMBSERVER ...
187 * However, we must reconnect as well ...
189 status = cli_connect(c, host, &ss);
190 if (!NT_STATUS_IS_OK(status)) {
191 printf("Failed to connect with %s. Error %s\n", host, nt_errstr(status) );
195 make_nmb_name(&called, "*SMBSERVER", 0x20);
196 if (!cli_session_request(c, &calling, &called)) {
197 printf("%s rejected the session\n",host);
198 printf("We tried with a called name of %s & %s\n",
208 /* Insert a NULL at the first separator of the given path and return a pointer
209 * to the remainder of the string.
212 terminate_path_at_separator(char * path)
220 if ((p = strchr_m(path, '/'))) {
225 if ((p = strchr_m(path, '\\'))) {
235 parse a //server/share type UNC name
237 bool smbcli_parse_unc(const char *unc_name, TALLOC_CTX *mem_ctx,
238 char **hostname, char **sharename)
242 *hostname = *sharename = NULL;
244 if (strncmp(unc_name, "\\\\", 2) &&
245 strncmp(unc_name, "//", 2)) {
249 *hostname = talloc_strdup(mem_ctx, &unc_name[2]);
250 p = terminate_path_at_separator(*hostname);
253 *sharename = talloc_strdup(mem_ctx, p);
254 terminate_path_at_separator(*sharename);
257 if (*hostname && *sharename) {
261 TALLOC_FREE(*hostname);
262 TALLOC_FREE(*sharename);
266 static bool torture_open_connection_share(struct cli_state **c,
267 const char *hostname,
268 const char *sharename)
275 flags |= CLI_FULL_CONNECTION_USE_KERBEROS;
277 flags |= CLI_FULL_CONNECTION_OPLOCKS;
278 if (use_level_II_oplocks)
279 flags |= CLI_FULL_CONNECTION_LEVEL_II_OPLOCKS;
281 status = cli_full_connection(c, myname,
282 hostname, NULL, port_to_use,
285 password, flags, Undefined, &retry);
286 if (!NT_STATUS_IS_OK(status)) {
287 printf("failed to open share connection: //%s/%s port:%d - %s\n",
288 hostname, sharename, port_to_use, nt_errstr(status));
292 (*c)->timeout = 120000; /* set a really long timeout (2 minutes) */
295 return force_cli_encryption(*c,
301 bool torture_open_connection(struct cli_state **c, int conn_index)
303 char **unc_list = NULL;
304 int num_unc_names = 0;
307 if (use_multishare_conn==True) {
309 unc_list = file_lines_load(multishare_conn_fname, &num_unc_names, 0, NULL);
310 if (!unc_list || num_unc_names <= 0) {
311 printf("Failed to load unc names list from '%s'\n", multishare_conn_fname);
315 if (!smbcli_parse_unc(unc_list[conn_index % num_unc_names],
317 printf("Failed to parse UNC name %s\n",
318 unc_list[conn_index % num_unc_names]);
319 TALLOC_FREE(unc_list);
323 result = torture_open_connection_share(c, h, s);
325 /* h, s were copied earlier */
326 TALLOC_FREE(unc_list);
330 return torture_open_connection_share(c, host, share);
333 bool torture_cli_session_setup2(struct cli_state *cli, uint16 *new_vuid)
335 uint16 old_vuid = cli->vuid;
336 fstring old_user_name;
337 size_t passlen = strlen(password);
341 fstrcpy(old_user_name, cli->user_name);
343 ret = NT_STATUS_IS_OK(cli_session_setup(cli, username,
347 *new_vuid = cli->vuid;
348 cli->vuid = old_vuid;
349 status = cli_set_username(cli, old_user_name);
350 if (!NT_STATUS_IS_OK(status)) {
357 bool torture_close_connection(struct cli_state *c)
361 printf("tdis failed (%s)\n", cli_errstr(c));
371 /* check if the server produced the expected error code */
372 static bool check_error(int line, struct cli_state *c,
373 uint8 eclass, uint32 ecode, NTSTATUS nterr)
375 if (cli_is_dos_error(c)) {
379 /* Check DOS error */
381 cli_dos_error(c, &cclass, &num);
383 if (eclass != cclass || ecode != num) {
384 printf("unexpected error code class=%d code=%d\n",
385 (int)cclass, (int)num);
386 printf(" expected %d/%d %s (line=%d)\n",
387 (int)eclass, (int)ecode, nt_errstr(nterr), line);
396 status = cli_nt_error(c);
398 if (NT_STATUS_V(nterr) != NT_STATUS_V(status)) {
399 printf("unexpected error code %s\n", nt_errstr(status));
400 printf(" expected %s (line=%d)\n", nt_errstr(nterr), line);
409 static bool wait_lock(struct cli_state *c, int fnum, uint32 offset, uint32 len)
411 while (!cli_lock(c, fnum, offset, len, -1, WRITE_LOCK)) {
412 if (!check_error(__LINE__, c, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
418 static bool rw_torture(struct cli_state *c)
420 const char *lockfname = "\\torture.lck";
424 pid_t pid2, pid = getpid();
430 memset(buf, '\0', sizeof(buf));
432 status = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
434 if (!NT_STATUS_IS_OK(status)) {
435 status = cli_open(c, lockfname, O_RDWR, DENY_NONE, &fnum2);
437 if (!NT_STATUS_IS_OK(status)) {
438 printf("open of %s failed (%s)\n", lockfname, cli_errstr(c));
442 for (i=0;i<torture_numops;i++) {
443 unsigned n = (unsigned)sys_random()%10;
445 printf("%d\r", i); fflush(stdout);
447 slprintf(fname, sizeof(fstring) - 1, "\\torture.%u", n);
449 if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) {
453 if (!NT_STATUS_IS_OK(cli_open(c, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL, &fnum))) {
454 printf("open failed (%s)\n", cli_errstr(c));
459 if (cli_write(c, fnum, 0, (char *)&pid, 0, sizeof(pid)) != sizeof(pid)) {
460 printf("write failed (%s)\n", cli_errstr(c));
465 if (cli_write(c, fnum, 0, (char *)buf,
466 sizeof(pid)+(j*sizeof(buf)),
467 sizeof(buf)) != sizeof(buf)) {
468 printf("write failed (%s)\n", cli_errstr(c));
475 if (cli_read(c, fnum, (char *)&pid2, 0, sizeof(pid)) != sizeof(pid)) {
476 printf("read failed (%s)\n", cli_errstr(c));
481 printf("data corruption!\n");
485 if (!NT_STATUS_IS_OK(cli_close(c, fnum))) {
486 printf("close failed (%s)\n", cli_errstr(c));
490 if (!NT_STATUS_IS_OK(cli_unlink(c, fname, aSYSTEM | aHIDDEN))) {
491 printf("unlink failed (%s)\n", cli_errstr(c));
495 if (!cli_unlock(c, fnum2, n*sizeof(int), sizeof(int))) {
496 printf("unlock failed (%s)\n", cli_errstr(c));
502 cli_unlink(c, lockfname, aSYSTEM | aHIDDEN);
509 static bool run_torture(int dummy)
511 struct cli_state *cli;
516 cli_sockopt(cli, sockops);
518 ret = rw_torture(cli);
520 if (!torture_close_connection(cli)) {
527 static bool rw_torture3(struct cli_state *c, char *lockfname)
529 uint16_t fnum = (uint16_t)-1;
534 unsigned countprev = 0;
540 for (i = 0; i < sizeof(buf); i += sizeof(uint32))
542 SIVAL(buf, i, sys_random());
547 if (!NT_STATUS_IS_OK(cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
548 DENY_NONE, &fnum))) {
549 printf("first open read/write of %s failed (%s)\n",
550 lockfname, cli_errstr(c));
556 for (i = 0; i < 500 && fnum == -1; i++)
558 status = cli_open(c, lockfname, O_RDONLY,
560 if (!NT_STATUS_IS_OK(status)) {
565 if (!NT_STATUS_IS_OK(status)) {
566 printf("second open read-only of %s failed (%s)\n",
567 lockfname, cli_errstr(c));
573 for (count = 0; count < sizeof(buf); count += sent)
575 if (count >= countprev) {
576 printf("%d %8d\r", i, count);
579 countprev += (sizeof(buf) / 20);
584 sent = ((unsigned)sys_random()%(20))+ 1;
585 if (sent > sizeof(buf) - count)
587 sent = sizeof(buf) - count;
590 if (cli_write(c, fnum, 0, buf+count, count, (size_t)sent) != sent) {
591 printf("write failed (%s)\n", cli_errstr(c));
597 sent = cli_read(c, fnum, buf_rd+count, count,
601 printf("read failed offset:%d size:%ld (%s)\n",
602 count, (unsigned long)sizeof(buf)-count,
609 if (memcmp(buf_rd+count, buf+count, sent) != 0)
611 printf("read/write compare failed\n");
612 printf("offset: %d req %ld recvd %ld\n", count, (unsigned long)sizeof(buf)-count, (unsigned long)sent);
621 if (!NT_STATUS_IS_OK(cli_close(c, fnum))) {
622 printf("close failed (%s)\n", cli_errstr(c));
629 static bool rw_torture2(struct cli_state *c1, struct cli_state *c2)
631 const char *lockfname = "\\torture2.lck";
640 if (!NT_STATUS_IS_OK(cli_unlink(c1, lockfname, aSYSTEM | aHIDDEN))) {
641 printf("unlink failed (%s) (normal, this file should not exist)\n", cli_errstr(c1));
644 if (!NT_STATUS_IS_OK(cli_open(c1, lockfname, O_RDWR | O_CREAT | O_EXCL,
645 DENY_NONE, &fnum1))) {
646 printf("first open read/write of %s failed (%s)\n",
647 lockfname, cli_errstr(c1));
650 if (!NT_STATUS_IS_OK(cli_open(c2, lockfname, O_RDONLY,
651 DENY_NONE, &fnum2))) {
652 printf("second open read-only of %s failed (%s)\n",
653 lockfname, cli_errstr(c2));
654 cli_close(c1, fnum1);
658 for (i=0;i<torture_numops;i++)
660 size_t buf_size = ((unsigned)sys_random()%(sizeof(buf)-1))+ 1;
662 printf("%d\r", i); fflush(stdout);
665 generate_random_buffer((unsigned char *)buf, buf_size);
667 if (cli_write(c1, fnum1, 0, buf, 0, buf_size) != buf_size) {
668 printf("write failed (%s)\n", cli_errstr(c1));
673 if ((bytes_read = cli_read(c2, fnum2, buf_rd, 0, buf_size)) != buf_size) {
674 printf("read failed (%s)\n", cli_errstr(c2));
675 printf("read %d, expected %ld\n", (int)bytes_read,
676 (unsigned long)buf_size);
681 if (memcmp(buf_rd, buf, buf_size) != 0)
683 printf("read/write compare failed\n");
689 if (!NT_STATUS_IS_OK(cli_close(c2, fnum2))) {
690 printf("close failed (%s)\n", cli_errstr(c2));
693 if (!NT_STATUS_IS_OK(cli_close(c1, fnum1))) {
694 printf("close failed (%s)\n", cli_errstr(c1));
698 if (!NT_STATUS_IS_OK(cli_unlink(c1, lockfname, aSYSTEM | aHIDDEN))) {
699 printf("unlink failed (%s)\n", cli_errstr(c1));
706 static bool run_readwritetest(int dummy)
708 static struct cli_state *cli1, *cli2;
709 bool test1, test2 = False;
711 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
714 cli_sockopt(cli1, sockops);
715 cli_sockopt(cli2, sockops);
717 printf("starting readwritetest\n");
719 test1 = rw_torture2(cli1, cli2);
720 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1));
723 test2 = rw_torture2(cli1, cli1);
724 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2));
727 if (!torture_close_connection(cli1)) {
731 if (!torture_close_connection(cli2)) {
735 return (test1 && test2);
738 static bool run_readwritemulti(int dummy)
740 struct cli_state *cli;
745 cli_sockopt(cli, sockops);
747 printf("run_readwritemulti: fname %s\n", randomfname);
748 test = rw_torture3(cli, randomfname);
750 if (!torture_close_connection(cli)) {
757 static bool run_readwritelarge(int dummy)
759 static struct cli_state *cli1;
761 const char *lockfname = "\\large.dat";
766 if (!torture_open_connection(&cli1, 0)) {
769 cli_sockopt(cli1, sockops);
770 memset(buf,'\0',sizeof(buf));
772 cli1->max_xmit = 128*1024;
774 printf("starting readwritelarge\n");
776 cli_unlink(cli1, lockfname, aSYSTEM | aHIDDEN);
778 if (!NT_STATUS_IS_OK(cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE, &fnum1))) {
779 printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(cli1));
783 cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf));
785 if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
786 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
790 if (fsize == sizeof(buf))
791 printf("readwritelarge test 1 succeeded (size = %lx)\n",
792 (unsigned long)fsize);
794 printf("readwritelarge test 1 failed (size = %lx)\n",
795 (unsigned long)fsize);
799 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
800 printf("close failed (%s)\n", cli_errstr(cli1));
804 if (!NT_STATUS_IS_OK(cli_unlink(cli1, lockfname, aSYSTEM | aHIDDEN))) {
805 printf("unlink failed (%s)\n", cli_errstr(cli1));
809 if (!NT_STATUS_IS_OK(cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE, &fnum1))) {
810 printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(cli1));
814 cli1->max_xmit = 4*1024;
816 cli_smbwrite(cli1, fnum1, buf, 0, sizeof(buf));
818 if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
819 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
823 if (fsize == sizeof(buf))
824 printf("readwritelarge test 2 succeeded (size = %lx)\n",
825 (unsigned long)fsize);
827 printf("readwritelarge test 2 failed (size = %lx)\n",
828 (unsigned long)fsize);
833 /* ToDo - set allocation. JRA */
834 if(!cli_set_allocation_size(cli1, fnum1, 0)) {
835 printf("set allocation size to zero failed (%s)\n", cli_errstr(&cli1));
838 if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
839 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
843 printf("readwritelarge test 3 (truncate test) succeeded (size = %x)\n", fsize);
846 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
847 printf("close failed (%s)\n", cli_errstr(cli1));
851 if (!torture_close_connection(cli1)) {
860 #define ival(s) strtol(s, NULL, 0)
862 /* run a test that simulates an approximate netbench client load */
863 static bool run_netbench(int client)
865 struct cli_state *cli;
870 const char *params[20];
877 cli_sockopt(cli, sockops);
881 slprintf(cname,sizeof(cname)-1, "client%d", client);
883 f = fopen(client_txt, "r");
890 while (fgets(line, sizeof(line)-1, f)) {
894 line[strlen(line)-1] = 0;
896 /* printf("[%d] %s\n", line_count, line); */
898 all_string_sub(line,"client1", cname, sizeof(line));
900 /* parse the command parameters */
901 params[0] = strtok_r(line, " ", &saveptr);
903 while (params[i]) params[++i] = strtok_r(NULL, " ", &saveptr);
909 if (!strncmp(params[0],"SMB", 3)) {
910 printf("ERROR: You are using a dbench 1 load file\n");
914 if (!strcmp(params[0],"NTCreateX")) {
915 nb_createx(params[1], ival(params[2]), ival(params[3]),
917 } else if (!strcmp(params[0],"Close")) {
918 nb_close(ival(params[1]));
919 } else if (!strcmp(params[0],"Rename")) {
920 nb_rename(params[1], params[2]);
921 } else if (!strcmp(params[0],"Unlink")) {
922 nb_unlink(params[1]);
923 } else if (!strcmp(params[0],"Deltree")) {
924 nb_deltree(params[1]);
925 } else if (!strcmp(params[0],"Rmdir")) {
927 } else if (!strcmp(params[0],"QUERY_PATH_INFORMATION")) {
928 nb_qpathinfo(params[1]);
929 } else if (!strcmp(params[0],"QUERY_FILE_INFORMATION")) {
930 nb_qfileinfo(ival(params[1]));
931 } else if (!strcmp(params[0],"QUERY_FS_INFORMATION")) {
932 nb_qfsinfo(ival(params[1]));
933 } else if (!strcmp(params[0],"FIND_FIRST")) {
934 nb_findfirst(params[1]);
935 } else if (!strcmp(params[0],"WriteX")) {
936 nb_writex(ival(params[1]),
937 ival(params[2]), ival(params[3]), ival(params[4]));
938 } else if (!strcmp(params[0],"ReadX")) {
939 nb_readx(ival(params[1]),
940 ival(params[2]), ival(params[3]), ival(params[4]));
941 } else if (!strcmp(params[0],"Flush")) {
942 nb_flush(ival(params[1]));
944 printf("Unknown operation %s\n", params[0]);
952 if (!torture_close_connection(cli)) {
960 /* run a test that simulates an approximate netbench client load */
961 static bool run_nbench(int dummy)
970 signal(SIGALRM, nb_alarm);
972 t = create_procs(run_netbench, &correct);
975 printf("\nThroughput %g MB/sec\n",
976 1.0e-6 * nbio_total() / t);
982 This test checks for two things:
984 1) correct support for retaining locks over a close (ie. the server
985 must not use posix semantics)
986 2) support for lock timeouts
988 static bool run_locktest1(int dummy)
990 struct cli_state *cli1, *cli2;
991 const char *fname = "\\lockt1.lck";
992 uint16_t fnum1, fnum2, fnum3;
994 unsigned lock_timeout;
996 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
999 cli_sockopt(cli1, sockops);
1000 cli_sockopt(cli2, sockops);
1002 printf("starting locktest1\n");
1004 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
1006 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
1007 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
1010 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum2))) {
1011 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli1));
1014 if (!NT_STATUS_IS_OK(cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum3))) {
1015 printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli2));
1019 if (!cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
1020 printf("lock1 failed (%s)\n", cli_errstr(cli1));
1025 if (cli_lock(cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
1026 printf("lock2 succeeded! This is a locking bug\n");
1029 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
1030 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1034 lock_timeout = (1 + (random() % 20));
1035 printf("Testing lock timeout with timeout=%u\n", lock_timeout);
1037 if (cli_lock(cli2, fnum3, 0, 4, lock_timeout * 1000, WRITE_LOCK)) {
1038 printf("lock3 succeeded! This is a locking bug\n");
1041 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
1042 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
1046 if (ABS(t2 - t1) < lock_timeout-1) {
1047 printf("error: This server appears not to support timed lock requests\n");
1050 printf("server slept for %u seconds for a %u second timeout\n",
1051 (unsigned int)(t2-t1), lock_timeout);
1053 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum2))) {
1054 printf("close1 failed (%s)\n", cli_errstr(cli1));
1058 if (cli_lock(cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
1059 printf("lock4 succeeded! This is a locking bug\n");
1062 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
1063 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
1066 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
1067 printf("close2 failed (%s)\n", cli_errstr(cli1));
1071 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum3))) {
1072 printf("close3 failed (%s)\n", cli_errstr(cli2));
1076 if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname, aSYSTEM | aHIDDEN))) {
1077 printf("unlink failed (%s)\n", cli_errstr(cli1));
1082 if (!torture_close_connection(cli1)) {
1086 if (!torture_close_connection(cli2)) {
1090 printf("Passed locktest1\n");
1095 this checks to see if a secondary tconx can use open files from an
1098 static bool run_tcon_test(int dummy)
1100 static struct cli_state *cli;
1101 const char *fname = "\\tcontest.tmp";
1103 uint16 cnum1, cnum2, cnum3;
1104 uint16 vuid1, vuid2;
1109 memset(buf, '\0', sizeof(buf));
1111 if (!torture_open_connection(&cli, 0)) {
1114 cli_sockopt(cli, sockops);
1116 printf("starting tcontest\n");
1118 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
1120 if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
1121 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
1128 if (cli_write(cli, fnum1, 0, buf, 130, 4) != 4) {
1129 printf("initial write failed (%s)", cli_errstr(cli));
1133 status = cli_tcon_andx(cli, share, "?????",
1134 password, strlen(password)+1);
1135 if (!NT_STATUS_IS_OK(status)) {
1136 printf("%s refused 2nd tree connect (%s)\n", host,
1143 cnum3 = MAX(cnum1, cnum2) + 1; /* any invalid number */
1144 vuid2 = cli->vuid + 1;
1146 /* try a write with the wrong tid */
1149 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
1150 printf("* server allows write with wrong TID\n");
1153 printf("server fails write with wrong TID : %s\n", cli_errstr(cli));
1157 /* try a write with an invalid tid */
1160 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
1161 printf("* server allows write with invalid TID\n");
1164 printf("server fails write with invalid TID : %s\n", cli_errstr(cli));
1167 /* try a write with an invalid vuid */
1171 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
1172 printf("* server allows write with invalid VUID\n");
1175 printf("server fails write with invalid VUID : %s\n", cli_errstr(cli));
1181 if (!NT_STATUS_IS_OK(cli_close(cli, fnum1))) {
1182 printf("close failed (%s)\n", cli_errstr(cli));
1188 if (!cli_tdis(cli)) {
1189 printf("secondary tdis failed (%s)\n", cli_errstr(cli));
1195 if (!torture_close_connection(cli)) {
1204 checks for old style tcon support
1206 static bool run_tcon2_test(int dummy)
1208 static struct cli_state *cli;
1209 uint16 cnum, max_xmit;
1213 if (!torture_open_connection(&cli, 0)) {
1216 cli_sockopt(cli, sockops);
1218 printf("starting tcon2 test\n");
1220 if (asprintf(&service, "\\\\%s\\%s", host, share) == -1) {
1224 status = cli_raw_tcon(cli, service, password, "?????", &max_xmit, &cnum);
1226 if (!NT_STATUS_IS_OK(status)) {
1227 printf("tcon2 failed : %s\n", cli_errstr(cli));
1229 printf("tcon OK : max_xmit=%d cnum=%d tid=%d\n",
1230 (int)max_xmit, (int)cnum, SVAL(cli->inbuf, smb_tid));
1233 if (!torture_close_connection(cli)) {
1237 printf("Passed tcon2 test\n");
1241 static bool tcon_devtest(struct cli_state *cli,
1242 const char *myshare, const char *devtype,
1243 const char *return_devtype,
1244 NTSTATUS expected_error)
1249 status = cli_tcon_andx(cli, myshare, devtype,
1250 password, strlen(password)+1);
1252 if (NT_STATUS_IS_OK(expected_error)) {
1253 if (NT_STATUS_IS_OK(status)) {
1254 if (strcmp(cli->dev, return_devtype) == 0) {
1257 printf("tconX to share %s with type %s "
1258 "succeeded but returned the wrong "
1259 "device type (got [%s] but should have got [%s])\n",
1260 myshare, devtype, cli->dev, return_devtype);
1264 printf("tconX to share %s with type %s "
1265 "should have succeeded but failed\n",
1271 if (NT_STATUS_IS_OK(status)) {
1272 printf("tconx to share %s with type %s "
1273 "should have failed but succeeded\n",
1277 if (NT_STATUS_EQUAL(cli_nt_error(cli),
1281 printf("Returned unexpected error\n");
1290 checks for correct tconX support
1292 static bool run_tcon_devtype_test(int dummy)
1294 static struct cli_state *cli1 = NULL;
1300 status = cli_full_connection(&cli1, myname,
1301 host, NULL, port_to_use,
1303 username, workgroup,
1304 password, flags, Undefined, &retry);
1306 if (!NT_STATUS_IS_OK(status)) {
1307 printf("could not open connection\n");
1311 if (!tcon_devtest(cli1, "IPC$", "A:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1314 if (!tcon_devtest(cli1, "IPC$", "?????", "IPC", NT_STATUS_OK))
1317 if (!tcon_devtest(cli1, "IPC$", "LPT:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1320 if (!tcon_devtest(cli1, "IPC$", "IPC", "IPC", NT_STATUS_OK))
1323 if (!tcon_devtest(cli1, "IPC$", "FOOBA", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1326 if (!tcon_devtest(cli1, share, "A:", "A:", NT_STATUS_OK))
1329 if (!tcon_devtest(cli1, share, "?????", "A:", NT_STATUS_OK))
1332 if (!tcon_devtest(cli1, share, "LPT:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1335 if (!tcon_devtest(cli1, share, "IPC", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1338 if (!tcon_devtest(cli1, share, "FOOBA", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1344 printf("Passed tcondevtest\n");
1351 This test checks that
1353 1) the server supports multiple locking contexts on the one SMB
1354 connection, distinguished by PID.
1356 2) the server correctly fails overlapping locks made by the same PID (this
1357 goes against POSIX behaviour, which is why it is tricky to implement)
1359 3) the server denies unlock requests by an incorrect client PID
1361 static bool run_locktest2(int dummy)
1363 static struct cli_state *cli;
1364 const char *fname = "\\lockt2.lck";
1365 uint16_t fnum1, fnum2, fnum3;
1366 bool correct = True;
1368 if (!torture_open_connection(&cli, 0)) {
1372 cli_sockopt(cli, sockops);
1374 printf("starting locktest2\n");
1376 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
1380 if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
1381 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
1385 if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum2))) {
1386 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli));
1392 if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum3))) {
1393 printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli));
1399 if (!cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
1400 printf("lock1 failed (%s)\n", cli_errstr(cli));
1404 if (cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
1405 printf("WRITE lock1 succeeded! This is a locking bug\n");
1408 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1409 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1412 if (cli_lock(cli, fnum2, 0, 4, 0, WRITE_LOCK)) {
1413 printf("WRITE lock2 succeeded! This is a locking bug\n");
1416 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1417 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1420 if (cli_lock(cli, fnum2, 0, 4, 0, READ_LOCK)) {
1421 printf("READ lock2 succeeded! This is a locking bug\n");
1424 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1425 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
1428 if (!cli_lock(cli, fnum1, 100, 4, 0, WRITE_LOCK)) {
1429 printf("lock at 100 failed (%s)\n", cli_errstr(cli));
1432 if (cli_unlock(cli, fnum1, 100, 4)) {
1433 printf("unlock at 100 succeeded! This is a locking bug\n");
1437 if (cli_unlock(cli, fnum1, 0, 4)) {
1438 printf("unlock1 succeeded! This is a locking bug\n");
1441 if (!check_error(__LINE__, cli,
1443 NT_STATUS_RANGE_NOT_LOCKED)) return False;
1446 if (cli_unlock(cli, fnum1, 0, 8)) {
1447 printf("unlock2 succeeded! This is a locking bug\n");
1450 if (!check_error(__LINE__, cli,
1452 NT_STATUS_RANGE_NOT_LOCKED)) return False;
1455 if (cli_lock(cli, fnum3, 0, 4, 0, WRITE_LOCK)) {
1456 printf("lock3 succeeded! This is a locking bug\n");
1459 if (!check_error(__LINE__, cli, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
1464 if (!NT_STATUS_IS_OK(cli_close(cli, fnum1))) {
1465 printf("close1 failed (%s)\n", cli_errstr(cli));
1469 if (!NT_STATUS_IS_OK(cli_close(cli, fnum2))) {
1470 printf("close2 failed (%s)\n", cli_errstr(cli));
1474 if (!NT_STATUS_IS_OK(cli_close(cli, fnum3))) {
1475 printf("close3 failed (%s)\n", cli_errstr(cli));
1479 if (!torture_close_connection(cli)) {
1483 printf("locktest2 finished\n");
1490 This test checks that
1492 1) the server supports the full offset range in lock requests
1494 static bool run_locktest3(int dummy)
1496 static struct cli_state *cli1, *cli2;
1497 const char *fname = "\\lockt3.lck";
1498 uint16_t fnum1, fnum2;
1501 bool correct = True;
1503 #define NEXT_OFFSET offset += (~(uint32)0) / torture_numops
1505 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1508 cli_sockopt(cli1, sockops);
1509 cli_sockopt(cli2, sockops);
1511 printf("starting locktest3\n");
1513 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
1515 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
1516 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
1519 if (!NT_STATUS_IS_OK(cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2))) {
1520 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli2));
1524 for (offset=i=0;i<torture_numops;i++) {
1526 if (!cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1527 printf("lock1 %d failed (%s)\n",
1533 if (!cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1534 printf("lock2 %d failed (%s)\n",
1541 for (offset=i=0;i<torture_numops;i++) {
1544 if (cli_lock(cli1, fnum1, offset-2, 1, 0, WRITE_LOCK)) {
1545 printf("error: lock1 %d succeeded!\n", i);
1549 if (cli_lock(cli2, fnum2, offset-1, 1, 0, WRITE_LOCK)) {
1550 printf("error: lock2 %d succeeded!\n", i);
1554 if (cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1555 printf("error: lock3 %d succeeded!\n", i);
1559 if (cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1560 printf("error: lock4 %d succeeded!\n", i);
1565 for (offset=i=0;i<torture_numops;i++) {
1568 if (!cli_unlock(cli1, fnum1, offset-1, 1)) {
1569 printf("unlock1 %d failed (%s)\n",
1575 if (!cli_unlock(cli2, fnum2, offset-2, 1)) {
1576 printf("unlock2 %d failed (%s)\n",
1583 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
1584 printf("close1 failed (%s)\n", cli_errstr(cli1));
1588 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
1589 printf("close2 failed (%s)\n", cli_errstr(cli2));
1593 if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname, aSYSTEM | aHIDDEN))) {
1594 printf("unlink failed (%s)\n", cli_errstr(cli1));
1598 if (!torture_close_connection(cli1)) {
1602 if (!torture_close_connection(cli2)) {
1606 printf("finished locktest3\n");
1611 #define EXPECTED(ret, v) if ((ret) != (v)) { \
1612 printf("** "); correct = False; \
1616 looks at overlapping locks
1618 static bool run_locktest4(int dummy)
1620 static struct cli_state *cli1, *cli2;
1621 const char *fname = "\\lockt4.lck";
1622 uint16_t fnum1, fnum2, f;
1625 bool correct = True;
1627 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1631 cli_sockopt(cli1, sockops);
1632 cli_sockopt(cli2, sockops);
1634 printf("starting locktest4\n");
1636 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
1638 cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
1639 cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
1641 memset(buf, 0, sizeof(buf));
1643 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1644 printf("Failed to create file\n");
1649 ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1650 cli_lock(cli1, fnum1, 2, 4, 0, WRITE_LOCK);
1651 EXPECTED(ret, False);
1652 printf("the same process %s set overlapping write locks\n", ret?"can":"cannot");
1654 ret = cli_lock(cli1, fnum1, 10, 4, 0, READ_LOCK) &&
1655 cli_lock(cli1, fnum1, 12, 4, 0, READ_LOCK);
1656 EXPECTED(ret, True);
1657 printf("the same process %s set overlapping read locks\n", ret?"can":"cannot");
1659 ret = cli_lock(cli1, fnum1, 20, 4, 0, WRITE_LOCK) &&
1660 cli_lock(cli2, fnum2, 22, 4, 0, WRITE_LOCK);
1661 EXPECTED(ret, False);
1662 printf("a different connection %s set overlapping write locks\n", ret?"can":"cannot");
1664 ret = cli_lock(cli1, fnum1, 30, 4, 0, READ_LOCK) &&
1665 cli_lock(cli2, fnum2, 32, 4, 0, READ_LOCK);
1666 EXPECTED(ret, True);
1667 printf("a different connection %s set overlapping read locks\n", ret?"can":"cannot");
1669 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 40, 4, 0, WRITE_LOCK)) &&
1670 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 42, 4, 0, WRITE_LOCK));
1671 EXPECTED(ret, False);
1672 printf("a different pid %s set overlapping write locks\n", ret?"can":"cannot");
1674 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 50, 4, 0, READ_LOCK)) &&
1675 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 52, 4, 0, READ_LOCK));
1676 EXPECTED(ret, True);
1677 printf("a different pid %s set overlapping read locks\n", ret?"can":"cannot");
1679 ret = cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK) &&
1680 cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK);
1681 EXPECTED(ret, True);
1682 printf("the same process %s set the same read lock twice\n", ret?"can":"cannot");
1684 ret = cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK) &&
1685 cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK);
1686 EXPECTED(ret, False);
1687 printf("the same process %s set the same write lock twice\n", ret?"can":"cannot");
1689 ret = cli_lock(cli1, fnum1, 80, 4, 0, READ_LOCK) &&
1690 cli_lock(cli1, fnum1, 80, 4, 0, WRITE_LOCK);
1691 EXPECTED(ret, False);
1692 printf("the same process %s overlay a read lock with a write lock\n", ret?"can":"cannot");
1694 ret = cli_lock(cli1, fnum1, 90, 4, 0, WRITE_LOCK) &&
1695 cli_lock(cli1, fnum1, 90, 4, 0, READ_LOCK);
1696 EXPECTED(ret, True);
1697 printf("the same process %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1699 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 100, 4, 0, WRITE_LOCK)) &&
1700 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 100, 4, 0, READ_LOCK));
1701 EXPECTED(ret, False);
1702 printf("a different pid %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1704 ret = cli_lock(cli1, fnum1, 110, 4, 0, READ_LOCK) &&
1705 cli_lock(cli1, fnum1, 112, 4, 0, READ_LOCK) &&
1706 cli_unlock(cli1, fnum1, 110, 6);
1707 EXPECTED(ret, False);
1708 printf("the same process %s coalesce read locks\n", ret?"can":"cannot");
1711 ret = cli_lock(cli1, fnum1, 120, 4, 0, WRITE_LOCK) &&
1712 (cli_read(cli2, fnum2, buf, 120, 4) == 4);
1713 EXPECTED(ret, False);
1714 printf("this server %s strict write locking\n", ret?"doesn't do":"does");
1716 ret = cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK) &&
1717 (cli_write(cli2, fnum2, 0, buf, 130, 4) == 4);
1718 EXPECTED(ret, False);
1719 printf("this server %s strict read locking\n", ret?"doesn't do":"does");
1722 ret = cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1723 cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1724 cli_unlock(cli1, fnum1, 140, 4) &&
1725 cli_unlock(cli1, fnum1, 140, 4);
1726 EXPECTED(ret, True);
1727 printf("this server %s do recursive read locking\n", ret?"does":"doesn't");
1730 ret = cli_lock(cli1, fnum1, 150, 4, 0, WRITE_LOCK) &&
1731 cli_lock(cli1, fnum1, 150, 4, 0, READ_LOCK) &&
1732 cli_unlock(cli1, fnum1, 150, 4) &&
1733 (cli_read(cli2, fnum2, buf, 150, 4) == 4) &&
1734 !(cli_write(cli2, fnum2, 0, buf, 150, 4) == 4) &&
1735 cli_unlock(cli1, fnum1, 150, 4);
1736 EXPECTED(ret, True);
1737 printf("this server %s do recursive lock overlays\n", ret?"does":"doesn't");
1739 ret = cli_lock(cli1, fnum1, 160, 4, 0, READ_LOCK) &&
1740 cli_unlock(cli1, fnum1, 160, 4) &&
1741 (cli_write(cli2, fnum2, 0, buf, 160, 4) == 4) &&
1742 (cli_read(cli2, fnum2, buf, 160, 4) == 4);
1743 EXPECTED(ret, True);
1744 printf("the same process %s remove a read lock using write locking\n", ret?"can":"cannot");
1746 ret = cli_lock(cli1, fnum1, 170, 4, 0, WRITE_LOCK) &&
1747 cli_unlock(cli1, fnum1, 170, 4) &&
1748 (cli_write(cli2, fnum2, 0, buf, 170, 4) == 4) &&
1749 (cli_read(cli2, fnum2, buf, 170, 4) == 4);
1750 EXPECTED(ret, True);
1751 printf("the same process %s remove a write lock using read locking\n", ret?"can":"cannot");
1753 ret = cli_lock(cli1, fnum1, 190, 4, 0, WRITE_LOCK) &&
1754 cli_lock(cli1, fnum1, 190, 4, 0, READ_LOCK) &&
1755 cli_unlock(cli1, fnum1, 190, 4) &&
1756 !(cli_write(cli2, fnum2, 0, buf, 190, 4) == 4) &&
1757 (cli_read(cli2, fnum2, buf, 190, 4) == 4);
1758 EXPECTED(ret, True);
1759 printf("the same process %s remove the first lock first\n", ret?"does":"doesn't");
1761 cli_close(cli1, fnum1);
1762 cli_close(cli2, fnum2);
1763 cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
1764 cli_open(cli1, fname, O_RDWR, DENY_NONE, &f);
1765 ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1766 cli_lock(cli1, f, 0, 1, 0, READ_LOCK) &&
1767 NT_STATUS_IS_OK(cli_close(cli1, fnum1)) &&
1768 NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1)) &&
1769 cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1771 cli_close(cli1, fnum1);
1772 EXPECTED(ret, True);
1773 printf("the server %s have the NT byte range lock bug\n", !ret?"does":"doesn't");
1776 cli_close(cli1, fnum1);
1777 cli_close(cli2, fnum2);
1778 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
1779 torture_close_connection(cli1);
1780 torture_close_connection(cli2);
1782 printf("finished locktest4\n");
1787 looks at lock upgrade/downgrade.
1789 static bool run_locktest5(int dummy)
1791 static struct cli_state *cli1, *cli2;
1792 const char *fname = "\\lockt5.lck";
1793 uint16_t fnum1, fnum2, fnum3;
1796 bool correct = True;
1798 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1802 cli_sockopt(cli1, sockops);
1803 cli_sockopt(cli2, sockops);
1805 printf("starting locktest5\n");
1807 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
1809 cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
1810 cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
1811 cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum3);
1813 memset(buf, 0, sizeof(buf));
1815 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1816 printf("Failed to create file\n");
1821 /* Check for NT bug... */
1822 ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1823 cli_lock(cli1, fnum3, 0, 1, 0, READ_LOCK);
1824 cli_close(cli1, fnum1);
1825 cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
1826 ret = cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1827 EXPECTED(ret, True);
1828 printf("this server %s the NT locking bug\n", ret ? "doesn't have" : "has");
1829 cli_close(cli1, fnum1);
1830 cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
1831 cli_unlock(cli1, fnum3, 0, 1);
1833 ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1834 cli_lock(cli1, fnum1, 1, 1, 0, READ_LOCK);
1835 EXPECTED(ret, True);
1836 printf("the same process %s overlay a write with a read lock\n", ret?"can":"cannot");
1838 ret = cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK);
1839 EXPECTED(ret, False);
1841 printf("a different processs %s get a read lock on the first process lock stack\n", ret?"can":"cannot");
1843 /* Unlock the process 2 lock. */
1844 cli_unlock(cli2, fnum2, 0, 4);
1846 ret = cli_lock(cli1, fnum3, 0, 4, 0, READ_LOCK);
1847 EXPECTED(ret, False);
1849 printf("the same processs on a different fnum %s get a read lock\n", ret?"can":"cannot");
1851 /* Unlock the process 1 fnum3 lock. */
1852 cli_unlock(cli1, fnum3, 0, 4);
1854 /* Stack 2 more locks here. */
1855 ret = cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK) &&
1856 cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK);
1858 EXPECTED(ret, True);
1859 printf("the same process %s stack read locks\n", ret?"can":"cannot");
1861 /* Unlock the first process lock, then check this was the WRITE lock that was
1864 ret = cli_unlock(cli1, fnum1, 0, 4) &&
1865 cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK);
1867 EXPECTED(ret, True);
1868 printf("the first unlock removes the %s lock\n", ret?"WRITE":"READ");
1870 /* Unlock the process 2 lock. */
1871 cli_unlock(cli2, fnum2, 0, 4);
1873 /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */
1875 ret = cli_unlock(cli1, fnum1, 1, 1) &&
1876 cli_unlock(cli1, fnum1, 0, 4) &&
1877 cli_unlock(cli1, fnum1, 0, 4);
1879 EXPECTED(ret, True);
1880 printf("the same process %s unlock the stack of 4 locks\n", ret?"can":"cannot");
1882 /* Ensure the next unlock fails. */
1883 ret = cli_unlock(cli1, fnum1, 0, 4);
1884 EXPECTED(ret, False);
1885 printf("the same process %s count the lock stack\n", !ret?"can":"cannot");
1887 /* Ensure connection 2 can get a write lock. */
1888 ret = cli_lock(cli2, fnum2, 0, 4, 0, WRITE_LOCK);
1889 EXPECTED(ret, True);
1891 printf("a different processs %s get a write lock on the unlocked stack\n", ret?"can":"cannot");
1895 cli_close(cli1, fnum1);
1896 cli_close(cli2, fnum2);
1897 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
1898 if (!torture_close_connection(cli1)) {
1901 if (!torture_close_connection(cli2)) {
1905 printf("finished locktest5\n");
1911 tries the unusual lockingX locktype bits
1913 static bool run_locktest6(int dummy)
1915 static struct cli_state *cli;
1916 const char *fname[1] = { "\\lock6.txt" };
1921 if (!torture_open_connection(&cli, 0)) {
1925 cli_sockopt(cli, sockops);
1927 printf("starting locktest6\n");
1930 printf("Testing %s\n", fname[i]);
1932 cli_unlink(cli, fname[i], aSYSTEM | aHIDDEN);
1934 cli_open(cli, fname[i], O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
1935 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE);
1936 cli_close(cli, fnum);
1937 printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status));
1939 cli_open(cli, fname[i], O_RDWR, DENY_NONE, &fnum);
1940 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK);
1941 cli_close(cli, fnum);
1942 printf("CANCEL_LOCK gave %s\n", nt_errstr(status));
1944 cli_unlink(cli, fname[i], aSYSTEM | aHIDDEN);
1947 torture_close_connection(cli);
1949 printf("finished locktest6\n");
1953 static bool run_locktest7(int dummy)
1955 struct cli_state *cli1;
1956 const char *fname = "\\lockt7.lck";
1959 bool correct = False;
1961 if (!torture_open_connection(&cli1, 0)) {
1965 cli_sockopt(cli1, sockops);
1967 printf("starting locktest7\n");
1969 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
1971 cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
1973 memset(buf, 0, sizeof(buf));
1975 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1976 printf("Failed to create file\n");
1980 cli_setpid(cli1, 1);
1982 if (!cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK)) {
1983 printf("Unable to apply read lock on range 130:4, error was %s\n", cli_errstr(cli1));
1986 printf("pid1 successfully locked range 130:4 for READ\n");
1989 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1990 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1993 printf("pid1 successfully read the range 130:4\n");
1996 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1997 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1998 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1999 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2003 printf("pid1 successfully wrote to the range 130:4 (should be denied)\n");
2007 cli_setpid(cli1, 2);
2009 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
2010 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
2012 printf("pid2 successfully read the range 130:4\n");
2015 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
2016 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
2017 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
2018 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2022 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
2026 cli_setpid(cli1, 1);
2027 cli_unlock(cli1, fnum1, 130, 4);
2029 if (!cli_lock(cli1, fnum1, 130, 4, 0, WRITE_LOCK)) {
2030 printf("Unable to apply write lock on range 130:4, error was %s\n", cli_errstr(cli1));
2033 printf("pid1 successfully locked range 130:4 for WRITE\n");
2036 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
2037 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
2040 printf("pid1 successfully read the range 130:4\n");
2043 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
2044 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
2047 printf("pid1 successfully wrote to the range 130:4\n");
2050 cli_setpid(cli1, 2);
2052 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
2053 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
2054 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
2055 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2059 printf("pid2 successfully read the range 130:4 (should be denied)\n");
2063 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
2064 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
2065 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
2066 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2070 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
2074 cli_unlock(cli1, fnum1, 130, 0);
2078 cli_close(cli1, fnum1);
2079 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
2080 torture_close_connection(cli1);
2082 printf("finished locktest7\n");
2087 test whether fnums and tids open on one VC are available on another (a major
2090 static bool run_fdpasstest(int dummy)
2092 struct cli_state *cli1, *cli2;
2093 const char *fname = "\\fdpass.tst";
2097 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
2100 cli_sockopt(cli1, sockops);
2101 cli_sockopt(cli2, sockops);
2103 printf("starting fdpasstest\n");
2105 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
2107 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
2108 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2112 if (cli_write(cli1, fnum1, 0, "hello world\n", 0, 13) != 13) {
2113 printf("write failed (%s)\n", cli_errstr(cli1));
2117 cli2->vuid = cli1->vuid;
2118 cli2->cnum = cli1->cnum;
2119 cli2->pid = cli1->pid;
2121 if (cli_read(cli2, fnum1, buf, 0, 13) == 13) {
2122 printf("read succeeded! nasty security hole [%s]\n",
2127 cli_close(cli1, fnum1);
2128 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
2130 torture_close_connection(cli1);
2131 torture_close_connection(cli2);
2133 printf("finished fdpasstest\n");
2137 static bool run_fdsesstest(int dummy)
2139 struct cli_state *cli;
2144 const char *fname = "\\fdsess.tst";
2145 const char *fname1 = "\\fdsess1.tst";
2151 if (!torture_open_connection(&cli, 0))
2153 cli_sockopt(cli, sockops);
2155 if (!torture_cli_session_setup2(cli, &new_vuid))
2158 saved_cnum = cli->cnum;
2159 if (!NT_STATUS_IS_OK(cli_tcon_andx(cli, share, "?????", "", 1)))
2161 new_cnum = cli->cnum;
2162 cli->cnum = saved_cnum;
2164 printf("starting fdsesstest\n");
2166 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
2167 cli_unlink(cli, fname1, aSYSTEM | aHIDDEN);
2169 if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
2170 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
2174 if (cli_write(cli, fnum1, 0, "hello world\n", 0, 13) != 13) {
2175 printf("write failed (%s)\n", cli_errstr(cli));
2179 saved_vuid = cli->vuid;
2180 cli->vuid = new_vuid;
2182 if (cli_read(cli, fnum1, buf, 0, 13) == 13) {
2183 printf("read succeeded with different vuid! nasty security hole [%s]\n",
2187 /* Try to open a file with different vuid, samba cnum. */
2188 if (NT_STATUS_IS_OK(cli_open(cli, fname1, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum2))) {
2189 printf("create with different vuid, same cnum succeeded.\n");
2190 cli_close(cli, fnum2);
2191 cli_unlink(cli, fname1, aSYSTEM | aHIDDEN);
2193 printf("create with different vuid, same cnum failed.\n");
2194 printf("This will cause problems with service clients.\n");
2198 cli->vuid = saved_vuid;
2200 /* Try with same vuid, different cnum. */
2201 cli->cnum = new_cnum;
2203 if (cli_read(cli, fnum1, buf, 0, 13) == 13) {
2204 printf("read succeeded with different cnum![%s]\n",
2209 cli->cnum = saved_cnum;
2210 cli_close(cli, fnum1);
2211 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
2213 torture_close_connection(cli);
2215 printf("finished fdsesstest\n");
2220 This test checks that
2222 1) the server does not allow an unlink on a file that is open
2224 static bool run_unlinktest(int dummy)
2226 struct cli_state *cli;
2227 const char *fname = "\\unlink.tst";
2229 bool correct = True;
2231 if (!torture_open_connection(&cli, 0)) {
2235 cli_sockopt(cli, sockops);
2237 printf("starting unlink test\n");
2239 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
2243 if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum))) {
2244 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
2248 if (NT_STATUS_IS_OK(cli_unlink(cli, fname, aSYSTEM | aHIDDEN))) {
2249 printf("error: server allowed unlink on an open file\n");
2252 correct = check_error(__LINE__, cli, ERRDOS, ERRbadshare,
2253 NT_STATUS_SHARING_VIOLATION);
2256 cli_close(cli, fnum);
2257 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
2259 if (!torture_close_connection(cli)) {
2263 printf("unlink test finished\n");
2270 test how many open files this server supports on the one socket
2272 static bool run_maxfidtest(int dummy)
2274 struct cli_state *cli;
2275 const char *ftemplate = "\\maxfid.%d.%d";
2277 uint16_t fnums[0x11000];
2280 bool correct = True;
2285 printf("failed to connect\n");
2289 cli_sockopt(cli, sockops);
2291 for (i=0; i<0x11000; i++) {
2292 slprintf(fname,sizeof(fname)-1,ftemplate, i,(int)getpid());
2293 if (!NT_STATUS_IS_OK(cli_open(cli, fname,
2294 O_RDWR|O_CREAT|O_TRUNC, DENY_NONE, &fnums[i]))) {
2295 printf("open of %s failed (%s)\n",
2296 fname, cli_errstr(cli));
2297 printf("maximum fnum is %d\n", i);
2305 printf("cleaning up\n");
2307 slprintf(fname,sizeof(fname)-1,ftemplate, i,(int)getpid());
2308 cli_close(cli, fnums[i]);
2309 if (!NT_STATUS_IS_OK(cli_unlink(cli, fname, aSYSTEM | aHIDDEN))) {
2310 printf("unlink of %s failed (%s)\n",
2311 fname, cli_errstr(cli));
2318 printf("maxfid test finished\n");
2319 if (!torture_close_connection(cli)) {
2325 /* generate a random buffer */
2326 static void rand_buf(char *buf, int len)
2329 *buf = (char)sys_random();
2334 /* send smb negprot commands, not reading the response */
2335 static bool run_negprot_nowait(int dummy)
2338 static struct cli_state *cli;
2339 bool correct = True;
2341 printf("starting negprot nowait test\n");
2343 if (!(cli = open_nbt_connection())) {
2347 for (i=0;i<50000;i++) {
2348 cli_negprot_sendsync(cli);
2351 if (!torture_close_connection(cli)) {
2355 printf("finished negprot nowait test\n");
2361 /* send random IPC commands */
2362 static bool run_randomipc(int dummy)
2364 char *rparam = NULL;
2366 unsigned int rdrcnt,rprcnt;
2368 int api, param_len, i;
2369 struct cli_state *cli;
2370 bool correct = True;
2373 printf("starting random ipc test\n");
2375 if (!torture_open_connection(&cli, 0)) {
2379 for (i=0;i<count;i++) {
2380 api = sys_random() % 500;
2381 param_len = (sys_random() % 64);
2383 rand_buf(param, param_len);
2388 param, param_len, 8,
2389 NULL, 0, BUFFER_SIZE,
2393 printf("%d/%d\r", i,count);
2396 printf("%d/%d\n", i, count);
2398 if (!torture_close_connection(cli)) {
2402 printf("finished random ipc test\n");
2409 static void browse_callback(const char *sname, uint32 stype,
2410 const char *comment, void *state)
2412 printf("\t%20.20s %08x %s\n", sname, stype, comment);
2418 This test checks the browse list code
2421 static bool run_browsetest(int dummy)
2423 static struct cli_state *cli;
2424 bool correct = True;
2426 printf("starting browse test\n");
2428 if (!torture_open_connection(&cli, 0)) {
2432 printf("domain list:\n");
2433 cli_NetServerEnum(cli, cli->server_domain,
2434 SV_TYPE_DOMAIN_ENUM,
2435 browse_callback, NULL);
2437 printf("machine list:\n");
2438 cli_NetServerEnum(cli, cli->server_domain,
2440 browse_callback, NULL);
2442 if (!torture_close_connection(cli)) {
2446 printf("browse test finished\n");
2454 This checks how the getatr calls works
2456 static bool run_attrtest(int dummy)
2458 struct cli_state *cli;
2461 const char *fname = "\\attrib123456789.tst";
2462 bool correct = True;
2464 printf("starting attrib test\n");
2466 if (!torture_open_connection(&cli, 0)) {
2470 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
2471 cli_open(cli, fname,
2472 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
2473 cli_close(cli, fnum);
2474 if (!cli_getatr(cli, fname, NULL, NULL, &t)) {
2475 printf("getatr failed (%s)\n", cli_errstr(cli));
2479 if (abs(t - time(NULL)) > 60*60*24*10) {
2480 printf("ERROR: SMBgetatr bug. time is %s",
2486 t2 = t-60*60*24; /* 1 day ago */
2488 if (!cli_setatr(cli, fname, 0, t2)) {
2489 printf("setatr failed (%s)\n", cli_errstr(cli));
2493 if (!cli_getatr(cli, fname, NULL, NULL, &t)) {
2494 printf("getatr failed (%s)\n", cli_errstr(cli));
2499 printf("ERROR: getatr/setatr bug. times are\n%s",
2501 printf("%s", ctime(&t2));
2505 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
2507 if (!torture_close_connection(cli)) {
2511 printf("attrib test finished\n");
2518 This checks a couple of trans2 calls
2520 static bool run_trans2test(int dummy)
2522 struct cli_state *cli;
2525 time_t c_time, a_time, m_time;
2526 struct timespec c_time_ts, a_time_ts, m_time_ts, w_time_ts, m_time2_ts;
2527 const char *fname = "\\trans2.tst";
2528 const char *dname = "\\trans2";
2529 const char *fname2 = "\\trans2\\trans2.tst";
2531 bool correct = True;
2533 printf("starting trans2 test\n");
2535 if (!torture_open_connection(&cli, 0)) {
2539 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
2540 cli_open(cli, fname,
2541 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
2542 if (!cli_qfileinfo(cli, fnum, NULL, &size, &c_time_ts, &a_time_ts, &w_time_ts,
2543 &m_time_ts, NULL)) {
2544 printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(cli));
2548 if (!cli_qfilename(cli, fnum, pname, sizeof(pname))) {
2549 printf("ERROR: qfilename failed (%s)\n", cli_errstr(cli));
2553 if (strcmp(pname, fname)) {
2554 printf("qfilename gave different name? [%s] [%s]\n",
2559 cli_close(cli, fnum);
2563 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
2564 if (!NT_STATUS_IS_OK(cli_open(cli, fname,
2565 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum))) {
2566 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
2569 cli_close(cli, fnum);
2571 if (!cli_qpathinfo(cli, fname, &c_time, &a_time, &m_time, &size, NULL)) {
2572 printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(cli));
2575 if (c_time != m_time) {
2576 printf("create time=%s", ctime(&c_time));
2577 printf("modify time=%s", ctime(&m_time));
2578 printf("This system appears to have sticky create times\n");
2580 if (a_time % (60*60) == 0) {
2581 printf("access time=%s", ctime(&a_time));
2582 printf("This system appears to set a midnight access time\n");
2586 if (abs(m_time - time(NULL)) > 60*60*24*7) {
2587 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
2593 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
2594 cli_open(cli, fname,
2595 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
2596 cli_close(cli, fnum);
2597 if (!cli_qpathinfo2(cli, fname, &c_time_ts, &a_time_ts, &w_time_ts,
2598 &m_time_ts, &size, NULL, NULL)) {
2599 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2602 if (w_time_ts.tv_sec < 60*60*24*2) {
2603 printf("write time=%s", ctime(&w_time_ts.tv_sec));
2604 printf("This system appears to set a initial 0 write time\n");
2609 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
2612 /* check if the server updates the directory modification time
2613 when creating a new file */
2614 if (!NT_STATUS_IS_OK(cli_mkdir(cli, dname))) {
2615 printf("ERROR: mkdir failed (%s)\n", cli_errstr(cli));
2619 if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts, &w_time_ts,
2620 &m_time_ts, &size, NULL, NULL)) {
2621 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2625 cli_open(cli, fname2,
2626 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
2627 cli_write(cli, fnum, 0, (char *)&fnum, 0, sizeof(fnum));
2628 cli_close(cli, fnum);
2629 if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts, &w_time_ts,
2630 &m_time2_ts, &size, NULL, NULL)) {
2631 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2634 if (memcmp(&m_time_ts, &m_time2_ts, sizeof(struct timespec))
2636 printf("This system does not update directory modification times\n");
2640 cli_unlink(cli, fname2, aSYSTEM | aHIDDEN);
2641 cli_rmdir(cli, dname);
2643 if (!torture_close_connection(cli)) {
2647 printf("trans2 test finished\n");
2653 This checks new W2K calls.
2656 static bool new_trans(struct cli_state *pcli, int fnum, int level)
2660 bool correct = True;
2662 if (!cli_qfileinfo_test(pcli, fnum, level, &buf, &len)) {
2663 printf("ERROR: qfileinfo (%d) failed (%s)\n", level, cli_errstr(pcli));
2666 printf("qfileinfo: level %d, len = %u\n", level, len);
2667 dump_data(0, (uint8 *)buf, len);
2674 static bool run_w2ktest(int dummy)
2676 struct cli_state *cli;
2678 const char *fname = "\\w2ktest\\w2k.tst";
2680 bool correct = True;
2682 printf("starting w2k test\n");
2684 if (!torture_open_connection(&cli, 0)) {
2688 cli_open(cli, fname,
2689 O_RDWR | O_CREAT , DENY_NONE, &fnum);
2691 for (level = 1004; level < 1040; level++) {
2692 new_trans(cli, fnum, level);
2695 cli_close(cli, fnum);
2697 if (!torture_close_connection(cli)) {
2701 printf("w2k test finished\n");
2708 this is a harness for some oplock tests
2710 static bool run_oplock1(int dummy)
2712 struct cli_state *cli1;
2713 const char *fname = "\\lockt1.lck";
2715 bool correct = True;
2717 printf("starting oplock test 1\n");
2719 if (!torture_open_connection(&cli1, 0)) {
2723 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
2725 cli_sockopt(cli1, sockops);
2727 cli1->use_oplocks = True;
2729 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
2730 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2734 cli1->use_oplocks = False;
2736 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
2737 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
2739 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
2740 printf("close2 failed (%s)\n", cli_errstr(cli1));
2744 if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname, aSYSTEM | aHIDDEN))) {
2745 printf("unlink failed (%s)\n", cli_errstr(cli1));
2749 if (!torture_close_connection(cli1)) {
2753 printf("finished oplock test 1\n");
2758 static bool run_oplock2(int dummy)
2760 struct cli_state *cli1, *cli2;
2761 const char *fname = "\\lockt2.lck";
2762 uint16_t fnum1, fnum2;
2763 int saved_use_oplocks = use_oplocks;
2765 bool correct = True;
2766 volatile bool *shared_correct;
2768 shared_correct = (volatile bool *)shm_setup(sizeof(bool));
2769 *shared_correct = True;
2771 use_level_II_oplocks = True;
2774 printf("starting oplock test 2\n");
2776 if (!torture_open_connection(&cli1, 0)) {
2777 use_level_II_oplocks = False;
2778 use_oplocks = saved_use_oplocks;
2782 cli1->use_oplocks = True;
2783 cli1->use_level_II_oplocks = True;
2785 if (!torture_open_connection(&cli2, 1)) {
2786 use_level_II_oplocks = False;
2787 use_oplocks = saved_use_oplocks;
2791 cli2->use_oplocks = True;
2792 cli2->use_level_II_oplocks = True;
2794 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
2796 cli_sockopt(cli1, sockops);
2797 cli_sockopt(cli2, sockops);
2799 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
2800 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2804 /* Don't need the globals any more. */
2805 use_level_II_oplocks = False;
2806 use_oplocks = saved_use_oplocks;
2810 if (!NT_STATUS_IS_OK(cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2))) {
2811 printf("second open of %s failed (%s)\n", fname, cli_errstr(cli1));
2812 *shared_correct = False;
2818 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
2819 printf("close2 failed (%s)\n", cli_errstr(cli1));
2820 *shared_correct = False;
2828 /* Ensure cli1 processes the break. Empty file should always return 0
2831 if (cli_read(cli1, fnum1, buf, 0, 4) != 0) {
2832 printf("read on fnum1 failed (%s)\n", cli_errstr(cli1));
2836 /* Should now be at level II. */
2837 /* Test if sending a write locks causes a break to none. */
2839 if (!cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK)) {
2840 printf("lock failed (%s)\n", cli_errstr(cli1));
2844 cli_unlock(cli1, fnum1, 0, 4);
2848 if (!cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
2849 printf("lock failed (%s)\n", cli_errstr(cli1));
2853 cli_unlock(cli1, fnum1, 0, 4);
2857 cli_read(cli1, fnum1, buf, 0, 4);
2860 if (cli_write(cli1, fnum1, 0, buf, 0, 4) != 4) {
2861 printf("write on fnum1 failed (%s)\n", cli_errstr(cli1));
2866 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
2867 printf("close1 failed (%s)\n", cli_errstr(cli1));
2873 if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname, aSYSTEM | aHIDDEN))) {
2874 printf("unlink failed (%s)\n", cli_errstr(cli1));
2878 if (!torture_close_connection(cli1)) {
2882 if (!*shared_correct) {
2886 printf("finished oplock test 2\n");
2891 /* handler for oplock 3 tests */
2892 static NTSTATUS oplock3_handler(struct cli_state *cli, uint16_t fnum, unsigned char level)
2894 printf("got oplock break fnum=%d level=%d\n",
2896 return cli_oplock_ack(cli, fnum, level);
2899 static bool run_oplock3(int dummy)
2901 struct cli_state *cli;
2902 const char *fname = "\\oplockt3.dat";
2904 char buf[4] = "abcd";
2905 bool correct = True;
2906 volatile bool *shared_correct;
2908 shared_correct = (volatile bool *)shm_setup(sizeof(bool));
2909 *shared_correct = True;
2911 printf("starting oplock test 3\n");
2916 use_level_II_oplocks = True;
2917 if (!torture_open_connection(&cli, 0)) {
2918 *shared_correct = False;
2922 /* try to trigger a oplock break in parent */
2923 cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum);
2924 cli_write(cli, fnum, 0, buf, 0, 4);
2930 use_level_II_oplocks = True;
2931 if (!torture_open_connection(&cli, 1)) { /* other is forked */
2934 cli_oplock_handler(cli, oplock3_handler);
2935 cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum);
2936 cli_write(cli, fnum, 0, buf, 0, 4);
2937 cli_close(cli, fnum);
2938 cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum);
2939 cli->timeout = 20000;
2940 cli_receive_smb(cli);
2941 printf("finished oplock test 3\n");
2943 return (correct && *shared_correct);
2945 /* What are we looking for here? What's sucess and what's FAILURE? */
2951 Test delete on close semantics.
2953 static bool run_deletetest(int dummy)
2955 struct cli_state *cli1 = NULL;
2956 struct cli_state *cli2 = NULL;
2957 const char *fname = "\\delete.file";
2958 uint16_t fnum1 = (uint16_t)-1;
2959 uint16_t fnum2 = (uint16_t)-1;
2960 bool correct = True;
2962 printf("starting delete test\n");
2964 if (!torture_open_connection(&cli1, 0)) {
2968 cli_sockopt(cli1, sockops);
2970 /* Test 1 - this should delete the file on close. */
2972 cli_setatr(cli1, fname, 0, 0);
2973 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
2975 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
2976 0, FILE_OVERWRITE_IF,
2977 FILE_DELETE_ON_CLOSE, 0, &fnum1))) {
2978 printf("[1] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2985 uint32 *accinfo = NULL;
2987 cli_qfileinfo_test(cli1, fnum1, SMB_FILE_ACCESS_INFORMATION, (char **)&accinfo, &len);
2989 printf("access mode = 0x%lx\n", *accinfo);
2994 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
2995 printf("[1] close failed (%s)\n", cli_errstr(cli1));
3000 if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1))) {
3001 printf("[1] open of %s succeeded (should fail)\n", fname);
3006 printf("first delete on close test succeeded.\n");
3008 /* Test 2 - this should delete the file on close. */
3010 cli_setatr(cli1, fname, 0, 0);
3011 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3013 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS,
3014 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
3015 FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3016 printf("[2] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3021 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
3022 printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
3027 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3028 printf("[2] close failed (%s)\n", cli_errstr(cli1));
3033 if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
3034 printf("[2] open of %s succeeded should have been deleted on close !\n", fname);
3035 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3036 printf("[2] close failed (%s)\n", cli_errstr(cli1));
3040 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3042 printf("second delete on close test succeeded.\n");
3045 cli_setatr(cli1, fname, 0, 0);
3046 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3048 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
3049 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3050 printf("[3] open - 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3055 /* This should fail with a sharing violation - open for delete is only compatible
3056 with SHARE_DELETE. */
3058 if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3059 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0, 0, &fnum2))) {
3060 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname);
3065 /* This should succeed. */
3067 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3068 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0, 0, &fnum2))) {
3069 printf("[3] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
3074 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
3075 printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
3080 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3081 printf("[3] close 1 failed (%s)\n", cli_errstr(cli1));
3086 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum2))) {
3087 printf("[3] close 2 failed (%s)\n", cli_errstr(cli1));
3092 /* This should fail - file should no longer be there. */
3094 if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
3095 printf("[3] open of %s succeeded should have been deleted on close !\n", fname);
3096 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3097 printf("[3] close failed (%s)\n", cli_errstr(cli1));
3099 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3103 printf("third delete on close test succeeded.\n");
3106 cli_setatr(cli1, fname, 0, 0);
3107 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3109 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3110 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3111 printf("[4] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3116 /* This should succeed. */
3117 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
3118 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0, 0, &fnum2))) {
3119 printf("[4] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
3124 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum2))) {
3125 printf("[4] close - 1 failed (%s)\n", cli_errstr(cli1));
3130 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
3131 printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
3136 /* This should fail - no more opens once delete on close set. */
3137 if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
3138 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3139 FILE_OPEN, 0, 0, &fnum2))) {
3140 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname );
3144 printf("fourth delete on close test succeeded.\n");
3146 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3147 printf("[4] close - 2 failed (%s)\n", cli_errstr(cli1));
3153 cli_setatr(cli1, fname, 0, 0);
3154 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3156 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum1))) {
3157 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3162 /* This should fail - only allowed on NT opens with DELETE access. */
3164 if (cli_nt_delete_on_close(cli1, fnum1, True)) {
3165 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
3170 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3171 printf("[5] close - 2 failed (%s)\n", cli_errstr(cli1));
3176 printf("fifth delete on close test succeeded.\n");
3179 cli_setatr(cli1, fname, 0, 0);
3180 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3182 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
3183 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3184 FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3185 printf("[6] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3190 /* This should fail - only allowed on NT opens with DELETE access. */
3192 if (cli_nt_delete_on_close(cli1, fnum1, True)) {
3193 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
3198 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3199 printf("[6] close - 2 failed (%s)\n", cli_errstr(cli1));
3204 printf("sixth delete on close test succeeded.\n");
3207 cli_setatr(cli1, fname, 0, 0);
3208 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3210 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3211 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3212 printf("[7] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3217 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
3218 printf("[7] setting delete_on_close on file failed !\n");
3223 if (!cli_nt_delete_on_close(cli1, fnum1, False)) {
3224 printf("[7] unsetting delete_on_close on file failed !\n");
3229 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3230 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
3235 /* This next open should succeed - we reset the flag. */
3237 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
3238 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3243 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3244 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
3249 printf("seventh delete on close test succeeded.\n");
3252 cli_setatr(cli1, fname, 0, 0);
3253 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3255 if (!torture_open_connection(&cli2, 1)) {
3256 printf("[8] failed to open second connection.\n");
3261 cli_sockopt(cli1, sockops);
3263 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3264 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3265 FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3266 printf("[8] open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3271 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3272 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3273 FILE_OPEN, 0, 0, &fnum2))) {
3274 printf("[8] open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3279 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
3280 printf("[8] setting delete_on_close on file failed !\n");
3285 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3286 printf("[8] close - 1 failed (%s)\n", cli_errstr(cli1));
3291 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
3292 printf("[8] close - 2 failed (%s)\n", cli_errstr(cli2));
3297 /* This should fail.. */
3298 if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
3299 printf("[8] open of %s succeeded should have been deleted on close !\n", fname);
3303 printf("eighth delete on close test succeeded.\n");
3305 /* This should fail - we need to set DELETE_ACCESS. */
3306 if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0,FILE_READ_DATA|FILE_WRITE_DATA,
3307 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, 0, &fnum1))) {
3308 printf("[9] open of %s succeeded should have failed!\n", fname);
3313 printf("ninth delete on close test succeeded.\n");
3315 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3316 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, 0, &fnum1))) {
3317 printf("[10] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3322 /* This should delete the file. */
3323 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3324 printf("[10] close failed (%s)\n", cli_errstr(cli1));
3329 /* This should fail.. */
3330 if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
3331 printf("[10] open of %s succeeded should have been deleted on close !\n", fname);
3335 printf("tenth delete on close test succeeded.\n");
3337 cli_setatr(cli1, fname, 0, 0);
3338 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3340 /* What error do we get when attempting to open a read-only file with
3343 /* Create a readonly file. */
3344 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
3345 FILE_ATTRIBUTE_READONLY, FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3346 printf("[11] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3351 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3352 printf("[11] close failed (%s)\n", cli_errstr(cli1));
3357 /* Now try open for delete access. */
3358 if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES|DELETE_ACCESS,
3359 0, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3360 FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3361 printf("[11] open of %s succeeded should have been denied with ACCESS_DENIED!\n", fname);
3362 cli_close(cli1, fnum1);
3366 NTSTATUS nterr = cli_nt_error(cli1);
3367 if (!NT_STATUS_EQUAL(nterr,NT_STATUS_ACCESS_DENIED)) {
3368 printf("[11] open of %s should have been denied with ACCESS_DENIED! Got error %s\n", fname, nt_errstr(nterr));
3372 printf("eleventh delete on close test succeeded.\n");
3376 printf("finished delete test\n");
3379 /* FIXME: This will crash if we aborted before cli2 got
3380 * intialized, because these functions don't handle
3381 * uninitialized connections. */
3383 if (fnum1 != -1) cli_close(cli1, fnum1);
3384 if (fnum2 != -1) cli_close(cli1, fnum2);
3385 cli_setatr(cli1, fname, 0, 0);
3386 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3388 if (cli1 && !torture_close_connection(cli1)) {
3391 if (cli2 && !torture_close_connection(cli2)) {
3399 print out server properties
3401 static bool run_properties(int dummy)
3403 struct cli_state *cli;
3404 bool correct = True;
3406 printf("starting properties test\n");
3410 if (!torture_open_connection(&cli, 0)) {
3414 cli_sockopt(cli, sockops);
3416 d_printf("Capabilities 0x%08x\n", cli->capabilities);
3418 if (!torture_close_connection(cli)) {
3427 /* FIRST_DESIRED_ACCESS 0xf019f */
3428 #define FIRST_DESIRED_ACCESS FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|\
3429 FILE_READ_EA| /* 0xf */ \
3430 FILE_WRITE_EA|FILE_READ_ATTRIBUTES| /* 0x90 */ \
3431 FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
3432 DELETE_ACCESS|READ_CONTROL_ACCESS|\
3433 WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS /* 0xf0000 */
3434 /* SECOND_DESIRED_ACCESS 0xe0080 */
3435 #define SECOND_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
3436 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
3437 WRITE_OWNER_ACCESS /* 0xe0000 */
3440 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
3441 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
3443 WRITE_OWNER_ACCESS /* */
3447 Test ntcreate calls made by xcopy
3449 static bool run_xcopy(int dummy)
3451 static struct cli_state *cli1;
3452 const char *fname = "\\test.txt";
3453 bool correct = True;
3454 uint16_t fnum1, fnum2;
3456 printf("starting xcopy test\n");
3458 if (!torture_open_connection(&cli1, 0)) {
3462 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0,
3463 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
3464 FILE_SHARE_NONE, FILE_OVERWRITE_IF,
3465 0x4044, 0, &fnum1))) {
3466 printf("First open failed - %s\n", cli_errstr(cli1));
3470 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0,
3471 SECOND_DESIRED_ACCESS, 0,
3472 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN,
3473 0x200000, 0, &fnum2))) {
3474 printf("second open failed - %s\n", cli_errstr(cli1));
3478 if (!torture_close_connection(cli1)) {
3486 Test rename on files open with share delete and no share delete.
3488 static bool run_rename(int dummy)
3490 static struct cli_state *cli1;
3491 const char *fname = "\\test.txt";
3492 const char *fname1 = "\\test1.txt";
3493 bool correct = True;
3496 printf("starting rename test\n");
3498 if (!torture_open_connection(&cli1, 0)) {
3502 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3503 cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
3504 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3505 FILE_SHARE_READ, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3506 printf("First open failed - %s\n", cli_errstr(cli1));
3510 if (!NT_STATUS_IS_OK(cli_rename(cli1, fname, fname1))) {
3511 printf("First rename failed (SHARE_READ) (this is correct) - %s\n", cli_errstr(cli1));
3513 printf("First rename succeeded (SHARE_READ) - this should have failed !\n");
3517 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3518 printf("close - 1 failed (%s)\n", cli_errstr(cli1));
3522 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3523 cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
3524 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3526 FILE_SHARE_DELETE|FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3528 FILE_SHARE_DELETE|FILE_SHARE_READ, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3530 printf("Second open failed - %s\n", cli_errstr(cli1));
3534 if (!NT_STATUS_IS_OK(cli_rename(cli1, fname, fname1))) {
3535 printf("Second rename failed (SHARE_DELETE | SHARE_READ) - this should have succeeded - %s\n", cli_errstr(cli1));
3538 printf("Second rename succeeded (SHARE_DELETE | SHARE_READ)\n");
3541 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3542 printf("close - 2 failed (%s)\n", cli_errstr(cli1));
3546 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3547 cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
3549 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, READ_CONTROL_ACCESS, FILE_ATTRIBUTE_NORMAL,
3550 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3551 printf("Third open failed - %s\n", cli_errstr(cli1));
3560 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
3561 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum2))) {
3562 printf("Fourth open failed - %s\n", cli_errstr(cli1));
3565 if (!cli_nt_delete_on_close(cli1, fnum2, True)) {
3566 printf("[8] setting delete_on_close on file failed !\n");
3570 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum2))) {
3571 printf("close - 4 failed (%s)\n", cli_errstr(cli1));
3577 if (!NT_STATUS_IS_OK(cli_rename(cli1, fname, fname1))) {
3578 printf("Third rename failed (SHARE_NONE) - this should have succeeded - %s\n", cli_errstr(cli1));
3581 printf("Third rename succeeded (SHARE_NONE)\n");
3584 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3585 printf("close - 3 failed (%s)\n", cli_errstr(cli1));
3589 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3590 cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
3594 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3595 FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3596 printf("Fourth open failed - %s\n", cli_errstr(cli1));
3600 if (!NT_STATUS_IS_OK(cli_rename(cli1, fname, fname1))) {
3601 printf("Fourth rename failed (SHARE_READ | SHARE_WRITE) (this is correct) - %s\n", cli_errstr(cli1));
3603 printf("Fourth rename succeeded (SHARE_READ | SHARE_WRITE) - this should have failed !\n");
3607 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3608 printf("close - 4 failed (%s)\n", cli_errstr(cli1));
3612 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3613 cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
3617 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3618 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3619 printf("Fifth open failed - %s\n", cli_errstr(cli1));
3623 if (!NT_STATUS_IS_OK(cli_rename(cli1, fname, fname1))) {
3624 printf("Fifth rename failed (SHARE_READ | SHARE_WRITE | SHARE_DELETE) - this should have succeeded - %s ! \n",
3628 printf("Fifth rename succeeded (SHARE_READ | SHARE_WRITE | SHARE_DELETE) (this is correct) - %s\n", cli_errstr(cli1));
3632 * Now check if the first name still exists ...
3635 /* if (!NT_STATUS_OP(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3636 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0, &fnum2))) {
3637 printf("Opening original file after rename of open file fails: %s\n",
3641 printf("Opening original file after rename of open file works ...\n");
3642 (void)cli_close(cli1, fnum2);
3648 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3649 printf("close - 5 failed (%s)\n", cli_errstr(cli1));
3653 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3654 cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
3656 if (!torture_close_connection(cli1)) {
3663 static bool run_pipe_number(int dummy)
3665 struct cli_state *cli1;
3666 const char *pipe_name = "\\SPOOLSS";
3670 printf("starting pipenumber test\n");
3671 if (!torture_open_connection(&cli1, 0)) {
3675 cli_sockopt(cli1, sockops);
3677 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, pipe_name, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
3678 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN_IF, 0, 0, &fnum))) {
3679 printf("Open of pipe %s failed with error (%s)\n", pipe_name, cli_errstr(cli1));
3683 printf("\r%6d", num_pipes);
3686 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes, pipe_name );
3687 torture_close_connection(cli1);
3692 Test open mode returns on read-only files.
3694 static bool run_opentest(int dummy)
3696 static struct cli_state *cli1;
3697 static struct cli_state *cli2;
3698 const char *fname = "\\readonly.file";
3699 uint16_t fnum1, fnum2;
3702 bool correct = True;
3705 printf("starting open test\n");
3707 if (!torture_open_connection(&cli1, 0)) {
3711 cli_setatr(cli1, fname, 0, 0);
3712 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3714 cli_sockopt(cli1, sockops);
3716 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
3717 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
3721 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3722 printf("close2 failed (%s)\n", cli_errstr(cli1));
3726 if (!cli_setatr(cli1, fname, aRONLY, 0)) {
3727 printf("cli_setatr failed (%s)\n", cli_errstr(cli1));
3731 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_WRITE, &fnum1))) {
3732 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
3736 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
3737 cli_open(cli1, fname, O_RDWR, DENY_ALL, &fnum2);
3739 if (check_error(__LINE__, cli1, ERRDOS, ERRnoaccess,
3740 NT_STATUS_ACCESS_DENIED)) {
3741 printf("correct error code ERRDOS/ERRnoaccess returned\n");
3744 printf("finished open test 1\n");
3746 cli_close(cli1, fnum1);
3748 /* Now try not readonly and ensure ERRbadshare is returned. */
3750 cli_setatr(cli1, fname, 0, 0);
3752 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_WRITE, &fnum1))) {
3753 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
3757 /* This will fail - but the error should be ERRshare. */
3758 cli_open(cli1, fname, O_RDWR, DENY_ALL, &fnum2);
3760 if (check_error(__LINE__, cli1, ERRDOS, ERRbadshare,
3761 NT_STATUS_SHARING_VIOLATION)) {
3762 printf("correct error code ERRDOS/ERRbadshare returned\n");
3765 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3766 printf("close2 failed (%s)\n", cli_errstr(cli1));
3770 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3772 printf("finished open test 2\n");
3774 /* Test truncate open disposition on file opened for read. */
3776 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
3777 printf("(3) open (1) of %s failed (%s)\n", fname, cli_errstr(cli1));
3781 /* write 20 bytes. */
3783 memset(buf, '\0', 20);
3785 if (cli_write(cli1, fnum1, 0, buf, 0, 20) != 20) {
3786 printf("write failed (%s)\n", cli_errstr(cli1));
3790 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3791 printf("(3) close1 failed (%s)\n", cli_errstr(cli1));
3795 /* Ensure size == 20. */
3796 if (!cli_getatr(cli1, fname, NULL, &fsize, NULL)) {
3797 printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
3802 printf("(3) file size != 20\n");
3806 /* Now test if we can truncate a file opened for readonly. */
3808 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE, &fnum1))) {
3809 printf("(3) open (2) of %s failed (%s)\n", fname, cli_errstr(cli1));
3813 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3814 printf("close2 failed (%s)\n", cli_errstr(cli1));
3818 /* Ensure size == 0. */
3819 if (!cli_getatr(cli1, fname, NULL, &fsize, NULL)) {
3820 printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
3825 printf("(3) file size != 0\n");
3828 printf("finished open test 3\n");
3830 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3833 printf("testing ctemp\n");
3834 fnum1 = cli_ctemp(cli1, "\\", &tmp_path);
3836 printf("ctemp failed (%s)\n", cli_errstr(cli1));
3839 printf("ctemp gave path %s\n", tmp_path);
3840 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3841 printf("close of temp failed (%s)\n", cli_errstr(cli1));
3843 if (!NT_STATUS_IS_OK(cli_unlink(cli1, tmp_path, aSYSTEM | aHIDDEN))) {
3844 printf("unlink of temp failed (%s)\n", cli_errstr(cli1));
3847 /* Test the non-io opens... */
3849 if (!torture_open_connection(&cli2, 1)) {
3853 cli_setatr(cli2, fname, 0, 0);
3854 cli_unlink(cli2, fname, aSYSTEM | aHIDDEN);
3856 cli_sockopt(cli2, sockops);
3858 printf("TEST #1 testing 2 non-io opens (no delete)\n");
3860 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3861 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3862 printf("test 1 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3866 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3867 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0, &fnum2))) {
3868 printf("test 1 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3872 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3873 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3876 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
3877 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3881 printf("non-io open test #1 passed.\n");
3883 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3885 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
3887 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3888 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3889 printf("test 2 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3893 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3894 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0, &fnum2))) {
3895 printf("test 2 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3899 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3900 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3903 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
3904 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
3908 printf("non-io open test #2 passed.\n");
3910 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3912 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
3914 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3915 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3916 printf("test 3 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3920 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3921 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0, &fnum2))) {
3922 printf("test 3 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3926 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3927 printf("test 3 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3930 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
3931 printf("test 3 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3935 printf("non-io open test #3 passed.\n");
3937 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3939 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
3941 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3942 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3943 printf("test 4 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3947 if (NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3948 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0, &fnum2))) {
3949 printf("test 4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
3953 printf("test 3 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
3955 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3956 printf("test 4 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3960 printf("non-io open test #4 passed.\n");
3962 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3964 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
3966 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3967 FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3968 printf("test 5 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3972 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3973 FILE_SHARE_DELETE, FILE_OPEN_IF, 0, 0, &fnum2))) {
3974 printf("test 5 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3978 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3979 printf("test 5 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3983 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
3984 printf("test 5 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3988 printf("non-io open test #5 passed.\n");
3990 printf("TEST #6 testing 1 non-io open, one io open\n");
3992 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3994 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
3995 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3996 printf("test 6 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4000 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4001 FILE_SHARE_READ, FILE_OPEN_IF, 0, 0, &fnum2))) {
4002 printf("test 6 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4006 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4007 printf("test 6 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4011 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
4012 printf("test 6 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4016 printf("non-io open test #6 passed.\n");
4018 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
4020 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
4022 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
4023 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
4024 printf("test 7 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4028 if (NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4029 FILE_SHARE_READ|FILE_SHARE_DELETE, FILE_OPEN_IF, 0, 0, &fnum2))) {
4030 printf("test 7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
4034 printf("test 7 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
4036 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4037 printf("test 7 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4041 printf("non-io open test #7 passed.\n");
4043 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
4045 if (!torture_close_connection(cli1)) {
4048 if (!torture_close_connection(cli2)) {
4056 Test POSIX open /mkdir calls.
4058 static bool run_simple_posix_open_test(int dummy)
4060 static struct cli_state *cli1;
4061 const char *fname = "\\posix:file";
4062 const char *dname = "\\posix:dir";
4063 uint16 major, minor;
4064 uint32 caplow, caphigh;
4066 bool correct = false;
4068 printf("Starting simple POSIX open test\n");
4070 if (!torture_open_connection(&cli1, 0)) {
4074 cli_sockopt(cli1, sockops);
4076 if (!SERVER_HAS_UNIX_CIFS(cli1)) {
4077 printf("Server doesn't support UNIX CIFS extensions.\n");
4081 if (!cli_unix_extensions_version(cli1, &major,
4082 &minor, &caplow, &caphigh)) {
4083 printf("Server didn't return UNIX CIFS extensions.\n");
4087 if (!cli_set_unix_extensions_capabilities(cli1,
4088 major, minor, caplow, caphigh)) {
4089 printf("Server doesn't support setting UNIX CIFS extensions.\n");
4093 cli_setatr(cli1, fname, 0, 0);
4094 cli_posix_unlink(cli1, fname);
4095 cli_setatr(cli1, dname, 0, 0);
4096 cli_posix_rmdir(cli1, dname);
4098 /* Create a directory. */
4099 if (cli_posix_mkdir(cli1, dname, 0777) == -1) {
4100 printf("Server doesn't support setting UNIX CIFS extensions.\n");
4104 fnum1 = cli_posix_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, 0600);
4106 printf("POSIX create of %s failed (%s)\n", fname, cli_errstr(cli1));
4110 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4111 printf("close failed (%s)\n", cli_errstr(cli1));
4115 /* Now open the file again for read only. */
4116 fnum1 = cli_posix_open(cli1, fname, O_RDONLY, 0);
4118 printf("POSIX open of %s failed (%s)\n", fname, cli_errstr(cli1));
4122 /* Now unlink while open. */
4123 if (!NT_STATUS_IS_OK(cli_posix_unlink(cli1, fname))) {
4124 printf("POSIX unlink of %s failed (%s)\n", fname, cli_errstr(cli1));
4128 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4129 printf("close(2) failed (%s)\n", cli_errstr(cli1));
4133 /* Ensure the file has gone. */
4134 fnum1 = cli_posix_open(cli1, fname, O_RDONLY, 0);
4136 printf("POSIX open of %s succeeded, should have been deleted.\n", fname);
4140 if (!NT_STATUS_IS_OK(cli_posix_rmdir(cli1, dname))) {
4141 printf("POSIX rmdir failed (%s)\n", cli_errstr(cli1));
4145 printf("Simple POSIX open test passed\n");
4151 cli_close(cli1, fnum1);
4155 cli_setatr(cli1, fname, 0, 0);
4156 cli_posix_unlink(cli1, fname);
4157 cli_setatr(cli1, dname, 0, 0);
4158 cli_posix_rmdir(cli1, dname);
4160 if (!torture_close_connection(cli1)) {
4168 static uint32 open_attrs_table[] = {
4169 FILE_ATTRIBUTE_NORMAL,
4170 FILE_ATTRIBUTE_ARCHIVE,
4171 FILE_ATTRIBUTE_READONLY,
4172 FILE_ATTRIBUTE_HIDDEN,
4173 FILE_ATTRIBUTE_SYSTEM,
4175 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY,
4176 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN,
4177 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM,
4178 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
4179 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
4180 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
4182 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
4183 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
4184 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
4185 FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_SYSTEM,
4188 struct trunc_open_results {
4195 static struct trunc_open_results attr_results[] = {
4196 { 0, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
4197 { 1, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
4198 { 2, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
4199 { 16, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
4200 { 17, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
4201 { 18, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
4202 { 51, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4203 { 54, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4204 { 56, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
4205 { 68, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4206 { 71, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4207 { 73, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM },
4208 { 99, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4209 { 102, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4210 { 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 },
4211 { 116, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4212 { 119, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4213 { 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 },
4214 { 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 },
4215 { 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 },
4216 { 227, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4217 { 230, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4218 { 232, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
4219 { 244, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4220 { 247, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4221 { 249, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM }
4224 static bool run_openattrtest(int dummy)
4226 static struct cli_state *cli1;
4227 const char *fname = "\\openattr.file";
4229 bool correct = True;
4231 unsigned int i, j, k, l;
4233 printf("starting open attr test\n");
4235 if (!torture_open_connection(&cli1, 0)) {
4239 cli_sockopt(cli1, sockops);
4241 for (k = 0, i = 0; i < sizeof(open_attrs_table)/sizeof(uint32); i++) {
4242 cli_setatr(cli1, fname, 0, 0);
4243 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
4244 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_WRITE_DATA, open_attrs_table[i],
4245 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
4246 printf("open %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
4250 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4251 printf("close %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
4255 for (j = 0; j < sizeof(open_attrs_table)/sizeof(uint32); j++) {
4256 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA, open_attrs_table[j],
4257 FILE_SHARE_NONE, FILE_OVERWRITE, 0, 0, &fnum1))) {
4258 for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
4259 if (attr_results[l].num == k) {
4260 printf("[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(0x%x:%s)\n",
4261 k, open_attrs_table[i],
4262 open_attrs_table[j],
4263 fname, NT_STATUS_V(cli_nt_error(cli1)), cli_errstr(cli1));
4267 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_ACCESS_DENIED)) {
4268 printf("[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s\n",
4269 k, open_attrs_table[i], open_attrs_table[j],
4274 printf("[%d] trunc open 0x%x -> 0x%x failed\n", k, open_attrs_table[i], open_attrs_table[j]);
4280 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4281 printf("close %d (2) of %s failed (%s)\n", j, fname, cli_errstr(cli1));
4285 if (!cli_getatr(cli1, fname, &attr, NULL, NULL)) {
4286 printf("getatr(2) failed (%s)\n", cli_errstr(cli1));
4291 printf("[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n",
4292 k, open_attrs_table[i], open_attrs_table[j], attr );
4295 for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
4296 if (attr_results[l].num == k) {
4297 if (attr != attr_results[l].result_attr ||
4298 open_attrs_table[i] != attr_results[l].init_attr ||
4299 open_attrs_table[j] != attr_results[l].trunc_attr) {
4300 printf("getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x\n",
4301 open_attrs_table[i],
4302 open_attrs_table[j],
4304 attr_results[l].result_attr);
4314 cli_setatr(cli1, fname, 0, 0);
4315 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
4317 printf("open attr test %s.\n", correct ? "passed" : "failed");
4319 if (!torture_close_connection(cli1)) {
4325 static void list_fn(const char *mnt, file_info *finfo, const char *name, void *state)
4331 test directory listing speed
4333 static bool run_dirtest(int dummy)
4336 static struct cli_state *cli;
4339 bool correct = True;
4341 printf("starting directory test\n");
4343 if (!torture_open_connection(&cli, 0)) {
4347 cli_sockopt(cli, sockops);
4350 for (i=0;i<torture_numops;i++) {
4352 slprintf(fname, sizeof(fname), "\\%x", (int)random());
4353 if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum))) {
4354 fprintf(stderr,"Failed to open %s\n", fname);
4357 cli_close(cli, fnum);
4362 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
4363 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
4364 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
4366 printf("dirtest core %g seconds\n", end_timer() - t1);
4369 for (i=0;i<torture_numops;i++) {
4371 slprintf(fname, sizeof(fname), "\\%x", (int)random());
4372 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
4375 if (!torture_close_connection(cli)) {
4379 printf("finished dirtest\n");
4384 static void del_fn(const char *mnt, file_info *finfo, const char *mask, void *state)
4386 struct cli_state *pcli = (struct cli_state *)state;
4388 slprintf(fname, sizeof(fname), "\\LISTDIR\\%s", finfo->name);
4390 if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
4393 if (finfo->mode & aDIR) {
4394 if (!NT_STATUS_IS_OK(cli_rmdir(pcli, fname)))
4395 printf("del_fn: failed to rmdir %s\n,", fname );
4397 if (!NT_STATUS_IS_OK(cli_unlink(pcli, fname, aSYSTEM | aHIDDEN)))
4398 printf("del_fn: failed to unlink %s\n,", fname );
4404 sees what IOCTLs are supported
4406 bool torture_ioctl_test(int dummy)
4408 static struct cli_state *cli;
4409 uint16_t device, function;
4411 const char *fname = "\\ioctl.dat";
4415 if (!torture_open_connection(&cli, 0)) {
4419 printf("starting ioctl test\n");
4421 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
4423 if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum))) {
4424 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
4428 status = cli_raw_ioctl(cli, fnum, 0x2d0000 | (0x0420<<2), &blob);
4429 printf("ioctl device info: %s\n", cli_errstr(cli));
4431 status = cli_raw_ioctl(cli, fnum, IOCTL_QUERY_JOB_INFO, &blob);
4432 printf("ioctl job info: %s\n", cli_errstr(cli));
4434 for (device=0;device<0x100;device++) {
4435 printf("testing device=0x%x\n", device);
4436 for (function=0;function<0x100;function++) {
4437 uint32 code = (device<<16) | function;
4439 status = cli_raw_ioctl(cli, fnum, code, &blob);
4441 if (NT_STATUS_IS_OK(status)) {
4442 printf("ioctl 0x%x OK : %d bytes\n", (int)code,
4444 data_blob_free(&blob);
4449 if (!torture_close_connection(cli)) {
4458 tries varients of chkpath
4460 bool torture_chkpath_test(int dummy)
4462 static struct cli_state *cli;
4466 if (!torture_open_connection(&cli, 0)) {
4470 printf("starting chkpath test\n");
4472 /* cleanup from an old run */
4473 cli_rmdir(cli, "\\chkpath.dir\\dir2");
4474 cli_unlink(cli, "\\chkpath.dir\\*", aSYSTEM | aHIDDEN);
4475 cli_rmdir(cli, "\\chkpath.dir");
4477 if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\chkpath.dir"))) {
4478 printf("mkdir1 failed : %s\n", cli_errstr(cli));
4482 if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\chkpath.dir\\dir2"))) {
4483 printf("mkdir2 failed : %s\n", cli_errstr(cli));
4487 if (!NT_STATUS_IS_OK(cli_open(cli, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum))) {
4488 printf("open1 failed (%s)\n", cli_errstr(cli));
4491 cli_close(cli, fnum);
4493 if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir"))) {
4494 printf("chkpath1 failed: %s\n", cli_errstr(cli));
4498 if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir\\dir2"))) {
4499 printf("chkpath2 failed: %s\n", cli_errstr(cli));
4503 if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir\\foo.txt"))) {
4504 ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath,
4505 NT_STATUS_NOT_A_DIRECTORY);
4507 printf("* chkpath on a file should fail\n");
4511 if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir\\bar.txt"))) {
4512 ret = check_error(__LINE__, cli, ERRDOS, ERRbadfile,
4513 NT_STATUS_OBJECT_NAME_NOT_FOUND);
4515 printf("* chkpath on a non existant file should fail\n");
4519 if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir\\dirxx\\bar.txt"))) {
4520 ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath,
4521 NT_STATUS_OBJECT_PATH_NOT_FOUND);
4523 printf("* chkpath on a non existent component should fail\n");
4527 cli_rmdir(cli, "\\chkpath.dir\\dir2");
4528 cli_unlink(cli, "\\chkpath.dir\\*", aSYSTEM | aHIDDEN);
4529 cli_rmdir(cli, "\\chkpath.dir");
4531 if (!torture_close_connection(cli)) {
4538 static bool run_eatest(int dummy)
4540 static struct cli_state *cli;
4541 const char *fname = "\\eatest.txt";
4542 bool correct = True;
4546 struct ea_struct *ea_list = NULL;
4547 TALLOC_CTX *mem_ctx = talloc_init("eatest");
4549 printf("starting eatest\n");
4551 if (!torture_open_connection(&cli, 0)) {
4552 talloc_destroy(mem_ctx);
4556 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
4557 if (!NT_STATUS_IS_OK(cli_ntcreate(cli, fname, 0,
4558 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
4559 FILE_SHARE_NONE, FILE_OVERWRITE_IF,
4560 0x4044, 0, &fnum))) {
4561 printf("open failed - %s\n", cli_errstr(cli));
4562 talloc_destroy(mem_ctx);
4566 for (i = 0; i < 10; i++) {
4567 fstring ea_name, ea_val;
4569 slprintf(ea_name, sizeof(ea_name), "EA_%d", i);
4570 memset(ea_val, (char)i+1, i+1);
4571 if (!cli_set_ea_fnum(cli, fnum, ea_name, ea_val, i+1)) {
4572 printf("ea_set of name %s failed - %s\n", ea_name, cli_errstr(cli));
4573 talloc_destroy(mem_ctx);
4578 cli_close(cli, fnum);
4579 for (i = 0; i < 10; i++) {
4580 fstring ea_name, ea_val;
4582 slprintf(ea_name, sizeof(ea_name), "EA_%d", i+10);
4583 memset(ea_val, (char)i+1, i+1);
4584 if (!cli_set_ea_path(cli, fname, ea_name, ea_val, i+1)) {
4585 printf("ea_set of name %s failed - %s\n", ea_name, cli_errstr(cli));
4586 talloc_destroy(mem_ctx);
4591 if (!cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list)) {
4592 printf("ea_get list failed - %s\n", cli_errstr(cli));
4596 printf("num_eas = %d\n", (int)num_eas);
4598 if (num_eas != 20) {
4599 printf("Should be 20 EA's stored... failing.\n");
4603 for (i = 0; i < num_eas; i++) {
4604 printf("%d: ea_name = %s. Val = ", i, ea_list[i].name);
4605 dump_data(0, ea_list[i].value.data,
4606 ea_list[i].value.length);
4609 /* Setting EA's to zero length deletes them. Test this */
4610 printf("Now deleting all EA's - case indepenent....\n");
4613 cli_set_ea_path(cli, fname, "", "", 0);
4615 for (i = 0; i < 20; i++) {
4617 slprintf(ea_name, sizeof(ea_name), "ea_%d", i);
4618 if (!cli_set_ea_path(cli, fname, ea_name, "", 0)) {
4619 printf("ea_set of name %s failed - %s\n", ea_name, cli_errstr(cli));
4620 talloc_destroy(mem_ctx);
4626 if (!cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list)) {
4627 printf("ea_get list failed - %s\n", cli_errstr(cli));
4631 printf("num_eas = %d\n", (int)num_eas);
4632 for (i = 0; i < num_eas; i++) {
4633 printf("%d: ea_name = %s. Val = ", i, ea_list[i].name);
4634 dump_data(0, ea_list[i].value.data,
4635 ea_list[i].value.length);
4639 printf("deleting EA's failed.\n");
4643 /* Try and delete a non existant EA. */
4644 if (!cli_set_ea_path(cli, fname, "foo", "", 0)) {
4645 printf("deleting non-existant EA 'foo' should succeed. %s\n", cli_errstr(cli));
4649 talloc_destroy(mem_ctx);
4650 if (!torture_close_connection(cli)) {
4657 static bool run_dirtest1(int dummy)
4660 static struct cli_state *cli;
4663 bool correct = True;
4665 printf("starting directory test\n");
4667 if (!torture_open_connection(&cli, 0)) {
4671 cli_sockopt(cli, sockops);
4673 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
4674 cli_list(cli, "\\LISTDIR\\*", aDIR, del_fn, cli);
4675 cli_rmdir(cli, "\\LISTDIR");
4676 cli_mkdir(cli, "\\LISTDIR");
4678 /* Create 1000 files and 1000 directories. */
4679 for (i=0;i<1000;i++) {
4681 slprintf(fname, sizeof(fname), "\\LISTDIR\\f%d", i);
4682 if (!NT_STATUS_IS_OK(cli_ntcreate(cli, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
4683 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum))) {
4684 fprintf(stderr,"Failed to open %s\n", fname);
4687 cli_close(cli, fnum);
4689 for (i=0;i<1000;i++) {
4691 slprintf(fname, sizeof(fname), "\\LISTDIR\\d%d", i);
4692 if (!NT_STATUS_IS_OK(cli_mkdir(cli, fname))) {
4693 fprintf(stderr,"Failed to open %s\n", fname);
4698 /* Now ensure that doing an old list sees both files and directories. */
4699 num_seen = cli_list_old(cli, "\\LISTDIR\\*", aDIR, list_fn, NULL);
4700 printf("num_seen = %d\n", num_seen );
4701 /* We should see 100 files + 1000 directories + . and .. */
4702 if (num_seen != 2002)
4705 /* Ensure if we have the "must have" bits we only see the
4708 num_seen = cli_list_old(cli, "\\LISTDIR\\*", (aDIR<<8)|aDIR, list_fn, NULL);
4709 printf("num_seen = %d\n", num_seen );
4710 if (num_seen != 1002)
4713 num_seen = cli_list_old(cli, "\\LISTDIR\\*", (aARCH<<8)|aDIR, list_fn, NULL);
4714 printf("num_seen = %d\n", num_seen );
4715 if (num_seen != 1000)
4718 /* Delete everything. */
4719 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
4720 cli_list(cli, "\\LISTDIR\\*", aDIR, del_fn, cli);
4721 cli_rmdir(cli, "\\LISTDIR");
4724 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
4725 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
4726 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
4729 if (!torture_close_connection(cli)) {
4733 printf("finished dirtest1\n");
4738 static bool run_error_map_extract(int dummy) {
4740 static struct cli_state *c_dos;
4741 static struct cli_state *c_nt;
4746 uint32 flgs2, errnum;
4753 /* NT-Error connection */
4755 if (!(c_nt = open_nbt_connection())) {
4759 c_nt->use_spnego = False;
4761 status = cli_negprot(c_nt);
4763 if (!NT_STATUS_IS_OK(status)) {
4764 printf("%s rejected the NT-error negprot (%s)\n", host,
4770 if (!NT_STATUS_IS_OK(cli_session_setup(c_nt, "", "", 0, "", 0,
4772 printf("%s rejected the NT-error initial session setup (%s)\n",host, cli_errstr(c_nt));
4776 /* DOS-Error connection */
4778 if (!(c_dos = open_nbt_connection())) {
4782 c_dos->use_spnego = False;
4783 c_dos->force_dos_errors = True;
4785 status = cli_negprot(c_dos);
4786 if (!NT_STATUS_IS_OK(status)) {
4787 printf("%s rejected the DOS-error negprot (%s)\n", host,
4789 cli_shutdown(c_dos);
4793 if (!NT_STATUS_IS_OK(cli_session_setup(c_dos, "", "", 0, "", 0,
4795 printf("%s rejected the DOS-error initial session setup (%s)\n",host, cli_errstr(c_dos));
4799 for (error=(0xc0000000 | 0x1); error < (0xc0000000| 0xFFF); error++) {
4800 fstr_sprintf(user, "%X", error);
4802 if (NT_STATUS_IS_OK(cli_session_setup(c_nt, user,
4803 password, strlen(password),
4804 password, strlen(password),
4806 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
4809 flgs2 = SVAL(c_nt->inbuf,smb_flg2);
4811 /* Case #1: 32-bit NT errors */
4812 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
4813 nt_status = NT_STATUS(IVAL(c_nt->inbuf,smb_rcls));
4815 printf("/** Dos error on NT connection! (%s) */\n",
4817 nt_status = NT_STATUS(0xc0000000);
4820 if (NT_STATUS_IS_OK(cli_session_setup(c_dos, user,
4821 password, strlen(password),
4822 password, strlen(password),
4824 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
4826 flgs2 = SVAL(c_dos->inbuf,smb_flg2), errnum;
4828 /* Case #1: 32-bit NT errors */
4829 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
4830 printf("/** NT error on DOS connection! (%s) */\n",
4832 errnum = errclass = 0;
4834 cli_dos_error(c_dos, &errclass, &errnum);
4837 if (NT_STATUS_V(nt_status) != error) {
4838 printf("/*\t{ This NT error code was 'sqashed'\n\t from %s to %s \n\t during the session setup }\n*/\n",
4839 get_nt_error_c_code(NT_STATUS(error)),
4840 get_nt_error_c_code(nt_status));
4843 printf("\t{%s,\t%s,\t%s},\n",
4844 smb_dos_err_class(errclass),
4845 smb_dos_err_name(errclass, errnum),
4846 get_nt_error_c_code(NT_STATUS(error)));
4851 static bool run_sesssetup_bench(int dummy)
4853 static struct cli_state *c;
4854 const char *fname = "\\file.dat";
4859 if (!torture_open_connection(&c, 0)) {
4863 if (!NT_STATUS_IS_OK(cli_ntcreate(
4864 c, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
4865 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
4866 FILE_DELETE_ON_CLOSE, 0, &fnum))) {
4867 d_printf("open %s failed: %s\n", fname, cli_errstr(c));
4871 for (i=0; i<torture_numops; i++) {
4872 status = cli_session_setup(
4874 password, strlen(password),
4875 password, strlen(password),
4877 if (!NT_STATUS_IS_OK(status)) {
4878 d_printf("(%s) cli_session_setup failed: %s\n",
4879 __location__, nt_errstr(status));
4883 d_printf("\r%d ", (int)c->vuid);
4885 if (!cli_ulogoff(c)) {
4886 d_printf("(%s) cli_ulogoff failed: %s\n",
4887 __location__, cli_errstr(c));
4896 static bool subst_test(const char *str, const char *user, const char *domain,
4897 uid_t uid, gid_t gid, const char *expected)
4902 subst = talloc_sub_specified(talloc_tos(), str, user, domain, uid, gid);
4904 if (strcmp(subst, expected) != 0) {
4905 printf("sub_specified(%s, %s, %s, %d, %d) returned [%s], expected "
4906 "[%s]\n", str, user, domain, (int)uid, (int)gid, subst,
4915 static void chain1_open_completion(struct tevent_req *req)
4919 status = cli_open_recv(req, &fnum);
4922 d_printf("cli_open_recv returned %s: %d\n",
4924 NT_STATUS_IS_OK(status) ? fnum : -1);
4927 static void chain1_write_completion(struct tevent_req *req)
4931 status = cli_write_andx_recv(req, &written);
4934 d_printf("cli_write_andx_recv returned %s: %d\n",
4936 NT_STATUS_IS_OK(status) ? (int)written : -1);
4939 static void chain1_close_completion(struct tevent_req *req)
4942 bool *done = (bool *)tevent_req_callback_data_void(req);
4944 status = cli_close_recv(req);
4949 d_printf("cli_close returned %s\n", nt_errstr(status));
4952 static bool run_chain1(int dummy)
4954 struct cli_state *cli1;
4955 struct event_context *evt = event_context_init(NULL);
4956 struct tevent_req *reqs[3], *smbreqs[3];
4958 const char *str = "foobar";
4960 printf("starting chain1 test\n");
4961 if (!torture_open_connection(&cli1, 0)) {
4965 cli_sockopt(cli1, sockops);
4967 reqs[0] = cli_open_create(talloc_tos(), evt, cli1, "\\test",
4968 O_CREAT|O_RDWR, 0, &smbreqs[0]);
4969 if (reqs[0] == NULL) return false;
4970 tevent_req_set_callback(reqs[0], chain1_open_completion, NULL);
4973 reqs[1] = cli_write_andx_create(talloc_tos(), evt, cli1, 0, 0,
4974 (uint8_t *)str, 0, strlen(str)+1,
4975 smbreqs, 1, &smbreqs[1]);
4976 if (reqs[1] == NULL) return false;
4977 tevent_req_set_callback(reqs[1], chain1_write_completion, NULL);
4979 reqs[2] = cli_close_create(talloc_tos(), evt, cli1, 0, &smbreqs[2]);
4980 if (reqs[2] == NULL) return false;
4981 tevent_req_set_callback(reqs[2], chain1_close_completion, &done);
4983 if (!cli_smb_chain_send(smbreqs, ARRAY_SIZE(smbreqs))) {
4988 event_loop_once(evt);
4991 torture_close_connection(cli1);
4995 static bool run_mangle1(int dummy)
4997 struct cli_state *cli;
4998 const char *fname = "this_is_a_long_fname_to_be_mangled.txt";
5002 time_t change_time, access_time, write_time;
5006 printf("starting chain1 test\n");
5007 if (!torture_open_connection(&cli, 0)) {
5011 cli_sockopt(cli, sockops);
5013 if (NT_STATUS_IS_OK(cli_ntcreate(
5014 cli, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
5015 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0, 0, &fnum))) {
5016 d_printf("open %s failed: %s\n", fname, cli_errstr(cli));
5019 cli_close(cli, fnum);
5021 status = cli_qpathinfo_alt_name(cli, fname, alt_name);
5022 if (!NT_STATUS_IS_OK(status)) {
5023 d_printf("cli_qpathinfo_alt_name failed: %s\n",
5027 d_printf("alt_name: %s\n", alt_name);
5029 if (!NT_STATUS_IS_OK(cli_open(cli, alt_name, O_RDONLY, DENY_NONE, &fnum))) {
5030 d_printf("cli_open(%s) failed: %s\n", alt_name,
5034 cli_close(cli, fnum);
5036 if (!cli_qpathinfo(cli, alt_name, &change_time, &access_time,
5037 &write_time, &size, &mode)) {
5038 d_printf("cli_qpathinfo(%s) failed: %s\n", alt_name,
5046 static size_t null_source(uint8_t *buf, size_t n, void *priv)
5048 size_t *to_pull = (size_t *)priv;
5049 size_t thistime = *to_pull;
5051 thistime = MIN(thistime, n);
5052 if (thistime == 0) {
5056 memset(buf, 0, thistime);
5057 *to_pull -= thistime;
5061 static bool run_windows_write(int dummy)
5063 struct cli_state *cli1;
5067 const char *fname = "\\writetest.txt";
5071 printf("starting windows_write test\n");
5072 if (!torture_open_connection(&cli1, 0)) {
5076 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum))) {
5077 printf("open failed (%s)\n", cli_errstr(cli1));
5081 cli_sockopt(cli1, sockops);
5085 for (i=0; i<torture_numops; i++) {
5087 off_t start = i * torture_blocksize;
5089 size_t to_pull = torture_blocksize - 1;
5091 if (cli_write(cli1, fnum, 0, &c,
5092 start + torture_blocksize - 1, 1) != 1) {
5093 printf("cli_write failed: %s\n", cli_errstr(cli1));
5097 status = cli_push(cli1, fnum, 0, i * torture_blocksize, torture_blocksize,
5098 null_source, &to_pull);
5099 if (!NT_STATUS_IS_OK(status)) {
5100 printf("cli_push returned: %s\n", nt_errstr(status));
5105 seconds = end_timer();
5106 kbytes = (double)torture_blocksize * torture_numops;
5109 printf("Wrote %d kbytes in %.2f seconds: %d kb/sec\n", (int)kbytes,
5110 (double)seconds, (int)(kbytes/seconds));
5114 cli_close(cli1, fnum);
5115 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
5116 torture_close_connection(cli1);
5120 static bool run_cli_echo(int dummy)
5122 struct cli_state *cli;
5125 printf("starting cli_echo test\n");
5126 if (!torture_open_connection(&cli, 0)) {
5129 cli_sockopt(cli, sockops);
5131 status = cli_echo(cli, 5, data_blob_const("hello", 5));
5133 d_printf("cli_echo returned %s\n", nt_errstr(status));
5135 torture_close_connection(cli);
5136 return NT_STATUS_IS_OK(status);
5139 static bool run_uid_regression_test(int dummy)
5141 static struct cli_state *cli;
5143 bool correct = True;
5145 printf("starting uid regression test\n");
5147 if (!torture_open_connection(&cli, 0)) {
5151 cli_sockopt(cli, sockops);
5153 /* Ok - now save then logoff our current user. */
5154 old_vuid = cli->vuid;
5156 if (!cli_ulogoff(cli)) {
5157 d_printf("(%s) cli_ulogoff failed: %s\n",
5158 __location__, cli_errstr(cli));
5163 cli->vuid = old_vuid;
5165 /* Try an operation. */
5166 if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\uid_reg_test"))) {
5167 /* We expect bad uid. */
5168 if (!check_error(__LINE__, cli, ERRSRV, ERRbaduid,
5169 NT_STATUS_NO_SUCH_USER)) {
5175 cli_rmdir(cli, "\\uid_reg_test");
5179 torture_close_connection(cli);
5183 static bool run_local_substitute(int dummy)
5187 ok &= subst_test("%U", "bla", "", -1, -1, "bla");
5188 ok &= subst_test("%u%U", "bla", "", -1, -1, "blabla");
5189 ok &= subst_test("%g", "", "", -1, -1, "NO_GROUP");
5190 ok &= subst_test("%G", "", "", -1, -1, "NO_GROUP");
5191 ok &= subst_test("%g", "", "", -1, 0, gidtoname(0));
5192 ok &= subst_test("%G", "", "", -1, 0, gidtoname(0));
5193 ok &= subst_test("%D%u", "u", "dom", -1, 0, "domu");
5194 ok &= subst_test("%i %I", "", "", -1, -1, "0.0.0.0 0.0.0.0");
5196 /* Different captialization rules in sub_basic... */
5198 ok &= (strcmp(talloc_sub_basic(talloc_tos(), "BLA", "dom", "%U%D"),
5204 static bool run_local_gencache(int dummy)
5210 if (!gencache_init()) {
5211 d_printf("%s: gencache_init() failed\n", __location__);
5215 if (!gencache_set("foo", "bar", time(NULL) + 1000)) {
5216 d_printf("%s: gencache_set() failed\n", __location__);
5220 if (!gencache_get("foo", &val, &tm)) {
5221 d_printf("%s: gencache_get() failed\n", __location__);
5225 if (strcmp(val, "bar") != 0) {
5226 d_printf("%s: gencache_get() returned %s, expected %s\n",
5227 __location__, val, "bar");
5234 if (!gencache_del("foo")) {
5235 d_printf("%s: gencache_del() failed\n", __location__);
5238 if (gencache_del("foo")) {
5239 d_printf("%s: second gencache_del() succeeded\n",
5244 if (gencache_get("foo", &val, &tm)) {
5245 d_printf("%s: gencache_get() on deleted entry "
5246 "succeeded\n", __location__);
5250 blob = data_blob_string_const_null("bar");
5253 if (!gencache_set_data_blob("foo", &blob, tm)) {
5254 d_printf("%s: gencache_set_data_blob() failed\n", __location__);
5258 data_blob_free(&blob);
5260 if (!gencache_get_data_blob("foo", &blob, NULL)) {
5261 d_printf("%s: gencache_get_data_blob() failed\n", __location__);
5265 if (strcmp((const char *)blob.data, "bar") != 0) {
5266 d_printf("%s: gencache_get_data_blob() returned %s, expected %s\n",
5267 __location__, (const char *)blob.data, "bar");
5268 data_blob_free(&blob);
5272 data_blob_free(&blob);
5274 if (!gencache_del("foo")) {
5275 d_printf("%s: gencache_del() failed\n", __location__);
5278 if (gencache_del("foo")) {
5279 d_printf("%s: second gencache_del() succeeded\n",
5284 if (gencache_get_data_blob("foo", &blob, NULL)) {
5285 d_printf("%s: gencache_get_data_blob() on deleted entry "
5286 "succeeded\n", __location__);
5290 if (!gencache_shutdown()) {
5291 d_printf("%s: gencache_shutdown() failed\n", __location__);
5295 if (gencache_shutdown()) {
5296 d_printf("%s: second gencache_shutdown() succeeded\n",
5304 static bool rbt_testval(struct db_context *db, const char *key,
5307 struct db_record *rec;
5308 TDB_DATA data = string_tdb_data(value);
5312 rec = db->fetch_locked(db, db, string_tdb_data(key));
5314 d_fprintf(stderr, "fetch_locked failed\n");
5317 status = rec->store(rec, data, 0);
5318 if (!NT_STATUS_IS_OK(status)) {
5319 d_fprintf(stderr, "store failed: %s\n", nt_errstr(status));
5324 rec = db->fetch_locked(db, db, string_tdb_data(key));
5326 d_fprintf(stderr, "second fetch_locked failed\n");
5329 if ((rec->value.dsize != data.dsize)
5330 || (memcmp(rec->value.dptr, data.dptr, data.dsize) != 0)) {
5331 d_fprintf(stderr, "Got wrong data back\n");
5341 static bool run_local_rbtree(int dummy)
5343 struct db_context *db;
5347 db = db_open_rbt(NULL);
5350 d_fprintf(stderr, "db_open_rbt failed\n");
5354 for (i=0; i<1000; i++) {
5357 if (asprintf(&key, "key%ld", random()) == -1) {
5360 if (asprintf(&value, "value%ld", random()) == -1) {
5365 if (!rbt_testval(db, key, value)) {
5372 if (asprintf(&value, "value%ld", random()) == -1) {
5377 if (!rbt_testval(db, key, value)) {
5394 static bool test_stream_name(const char *fname, const char *expected_base,
5395 const char *expected_stream,
5396 NTSTATUS expected_status)
5400 char *stream = NULL;
5402 status = split_ntfs_stream_name(talloc_tos(), fname, &base, &stream);
5403 if (!NT_STATUS_EQUAL(status, expected_status)) {
5407 if (!NT_STATUS_IS_OK(status)) {
5411 if (base == NULL) goto error;
5413 if (strcmp(expected_base, base) != 0) goto error;
5415 if ((expected_stream != NULL) && (stream == NULL)) goto error;
5416 if ((expected_stream == NULL) && (stream != NULL)) goto error;
5418 if ((stream != NULL) && (strcmp(expected_stream, stream) != 0))
5422 TALLOC_FREE(stream);
5426 d_fprintf(stderr, "test_stream(%s, %s, %s, %s)\n",
5427 fname, expected_base ? expected_base : "<NULL>",
5428 expected_stream ? expected_stream : "<NULL>",
5429 nt_errstr(expected_status));
5430 d_fprintf(stderr, "-> base=%s, stream=%s, status=%s\n",
5431 base ? base : "<NULL>", stream ? stream : "<NULL>",
5434 TALLOC_FREE(stream);
5438 static bool run_local_stream_name(int dummy)
5442 ret &= test_stream_name(
5443 "bla", "bla", NULL, NT_STATUS_OK);
5444 ret &= test_stream_name(
5445 "bla::$DATA", "bla", NULL, NT_STATUS_OK);
5446 ret &= test_stream_name(
5447 "bla:blub:", "bla", NULL, NT_STATUS_OBJECT_NAME_INVALID);
5448 ret &= test_stream_name(
5449 "bla::", NULL, NULL, NT_STATUS_OBJECT_NAME_INVALID);
5450 ret &= test_stream_name(
5451 "bla::123", "bla", NULL, NT_STATUS_OBJECT_NAME_INVALID);
5452 ret &= test_stream_name(
5453 "bla:$DATA", "bla", "$DATA:$DATA", NT_STATUS_OK);
5454 ret &= test_stream_name(
5455 "bla:x:$DATA", "bla", "x:$DATA", NT_STATUS_OK);
5456 ret &= test_stream_name(
5457 "bla:x", "bla", "x:$DATA", NT_STATUS_OK);
5462 static bool data_blob_equal(DATA_BLOB a, DATA_BLOB b)
5464 if (a.length != b.length) {
5465 printf("a.length=%d != b.length=%d\n",
5466 (int)a.length, (int)b.length);
5469 if (memcmp(a.data, b.data, a.length) != 0) {
5470 printf("a.data and b.data differ\n");
5476 static bool run_local_memcache(int dummy)
5478 struct memcache *cache;
5480 DATA_BLOB d1, d2, d3;
5481 DATA_BLOB v1, v2, v3;
5483 TALLOC_CTX *mem_ctx;
5485 size_t size1, size2;
5488 cache = memcache_init(NULL, 100);
5490 if (cache == NULL) {
5491 printf("memcache_init failed\n");
5495 d1 = data_blob_const("d1", 2);
5496 d2 = data_blob_const("d2", 2);
5497 d3 = data_blob_const("d3", 2);
5499 k1 = data_blob_const("d1", 2);
5500 k2 = data_blob_const("d2", 2);
5502 memcache_add(cache, STAT_CACHE, k1, d1);
5503 memcache_add(cache, GETWD_CACHE, k2, d2);
5505 if (!memcache_lookup(cache, STAT_CACHE, k1, &v1)) {
5506 printf("could not find k1\n");
5509 if (!data_blob_equal(d1, v1)) {
5513 if (!memcache_lookup(cache, GETWD_CACHE, k2, &v2)) {
5514 printf("could not find k2\n");
5517 if (!data_blob_equal(d2, v2)) {
5521 memcache_add(cache, STAT_CACHE, k1, d3);
5523 if (!memcache_lookup(cache, STAT_CACHE, k1, &v3)) {
5524 printf("could not find replaced k1\n");
5527 if (!data_blob_equal(d3, v3)) {
5531 memcache_add(cache, GETWD_CACHE, k1, d1);
5533 if (memcache_lookup(cache, GETWD_CACHE, k2, &v2)) {
5534 printf("Did find k2, should have been purged\n");
5540 cache = memcache_init(NULL, 0);
5542 mem_ctx = talloc_init("foo");
5544 str1 = talloc_strdup(mem_ctx, "string1");
5545 str2 = talloc_strdup(mem_ctx, "string2");
5547 memcache_add_talloc(cache, SINGLETON_CACHE_TALLOC,
5548 data_blob_string_const("torture"), &str1);
5549 size1 = talloc_total_size(cache);
5551 memcache_add_talloc(cache, SINGLETON_CACHE_TALLOC,
5552 data_blob_string_const("torture"), &str2);
5553 size2 = talloc_total_size(cache);
5555 printf("size1=%d, size2=%d\n", (int)size1, (int)size2);
5557 if (size2 > size1) {
5558 printf("memcache leaks memory!\n");
5568 static void wbclient_done(struct tevent_req *req)
5571 struct winbindd_response *wb_resp;
5572 int *i = (int *)tevent_req_callback_data_void(req);
5574 wbc_err = wb_trans_recv(req, req, &wb_resp);
5577 d_printf("wb_trans_recv %d returned %s\n", *i, wbcErrorString(wbc_err));
5580 static bool run_local_wbclient(int dummy)
5582 struct event_context *ev;
5583 struct wb_context **wb_ctx;
5584 struct winbindd_request wb_req;
5585 bool result = false;
5588 BlockSignals(True, SIGPIPE);
5590 ev = event_context_init(talloc_tos());
5595 wb_ctx = TALLOC_ARRAY(ev, struct wb_context *, torture_numops);
5596 if (wb_ctx == NULL) {
5600 ZERO_STRUCT(wb_req);
5601 wb_req.cmd = WINBINDD_PING;
5603 for (i=0; i<torture_numops; i++) {
5604 wb_ctx[i] = wb_context_init(ev);
5605 if (wb_ctx[i] == NULL) {
5608 for (j=0; j<5; j++) {
5609 struct tevent_req *req;
5610 req = wb_trans_send(ev, ev, wb_ctx[i],
5611 (j % 2) == 0, &wb_req);
5615 tevent_req_set_callback(req, wbclient_done, &i);
5621 while (i < 5 * torture_numops) {
5622 event_loop_once(ev);
5631 static double create_procs(bool (*fn)(int), bool *result)
5634 volatile pid_t *child_status;
5635 volatile bool *child_status_out;
5641 child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*nprocs);
5642 if (!child_status) {
5643 printf("Failed to setup shared memory\n");
5647 child_status_out = (volatile bool *)shm_setup(sizeof(bool)*nprocs);
5648 if (!child_status_out) {
5649 printf("Failed to setup result status shared memory\n");
5653 for (i = 0; i < nprocs; i++) {
5654 child_status[i] = 0;
5655 child_status_out[i] = True;
5660 for (i=0;i<nprocs;i++) {
5663 pid_t mypid = getpid();
5664 sys_srandom(((int)mypid) ^ ((int)time(NULL)));
5666 slprintf(myname,sizeof(myname),"CLIENT%d", i);
5669 if (torture_open_connection(¤t_cli, i)) break;
5671 printf("pid %d failed to start\n", (int)getpid());
5677 child_status[i] = getpid();
5679 while (child_status[i] && end_timer() < 5) smb_msleep(2);
5681 child_status_out[i] = fn(i);
5688 for (i=0;i<nprocs;i++) {
5689 if (child_status[i]) synccount++;
5691 if (synccount == nprocs) break;
5693 } while (end_timer() < 30);
5695 if (synccount != nprocs) {
5696 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs, synccount);
5701 /* start the client load */
5704 for (i=0;i<nprocs;i++) {
5705 child_status[i] = 0;
5708 printf("%d clients started\n", nprocs);
5710 for (i=0;i<nprocs;i++) {
5711 while (waitpid(0, &status, 0) == -1 && errno == EINTR) /* noop */ ;
5716 for (i=0;i<nprocs;i++) {
5717 if (!child_status_out[i]) {
5724 #define FLAG_MULTIPROC 1
5731 {"FDPASS", run_fdpasstest, 0},
5732 {"LOCK1", run_locktest1, 0},
5733 {"LOCK2", run_locktest2, 0},
5734 {"LOCK3", run_locktest3, 0},
5735 {"LOCK4", run_locktest4, 0},
5736 {"LOCK5", run_locktest5, 0},
5737 {"LOCK6", run_locktest6, 0},
5738 {"LOCK7", run_locktest7, 0},
5739 {"UNLINK", run_unlinktest, 0},
5740 {"BROWSE", run_browsetest, 0},
5741 {"ATTR", run_attrtest, 0},
5742 {"TRANS2", run_trans2test, 0},
5743 {"MAXFID", run_maxfidtest, FLAG_MULTIPROC},
5744 {"TORTURE",run_torture, FLAG_MULTIPROC},
5745 {"RANDOMIPC", run_randomipc, 0},
5746 {"NEGNOWAIT", run_negprot_nowait, 0},
5747 {"NBENCH", run_nbench, 0},
5748 {"OPLOCK1", run_oplock1, 0},
5749 {"OPLOCK2", run_oplock2, 0},
5750 {"OPLOCK3", run_oplock3, 0},
5751 {"DIR", run_dirtest, 0},
5752 {"DIR1", run_dirtest1, 0},
5753 {"DENY1", torture_denytest1, 0},
5754 {"DENY2", torture_denytest2, 0},
5755 {"TCON", run_tcon_test, 0},
5756 {"TCONDEV", run_tcon_devtype_test, 0},
5757 {"RW1", run_readwritetest, 0},
5758 {"RW2", run_readwritemulti, FLAG_MULTIPROC},
5759 {"RW3", run_readwritelarge, 0},
5760 {"OPEN", run_opentest, 0},
5761 {"POSIX", run_simple_posix_open_test, 0},
5762 { "UID-REGRESSION-TEST", run_uid_regression_test, 0},
5764 {"OPENATTR", run_openattrtest, 0},
5766 {"XCOPY", run_xcopy, 0},
5767 {"RENAME", run_rename, 0},
5768 {"DELETE", run_deletetest, 0},
5769 {"PROPERTIES", run_properties, 0},
5770 {"MANGLE", torture_mangle, 0},
5771 {"MANGLE1", run_mangle1, 0},
5772 {"W2K", run_w2ktest, 0},
5773 {"TRANS2SCAN", torture_trans2_scan, 0},
5774 {"NTTRANSSCAN", torture_nttrans_scan, 0},
5775 {"UTABLE", torture_utable, 0},
5776 {"CASETABLE", torture_casetable, 0},
5777 {"ERRMAPEXTRACT", run_error_map_extract, 0},
5778 {"PIPE_NUMBER", run_pipe_number, 0},
5779 {"TCON2", run_tcon2_test, 0},
5780 {"IOCTL", torture_ioctl_test, 0},
5781 {"CHKPATH", torture_chkpath_test, 0},
5782 {"FDSESS", run_fdsesstest, 0},
5783 { "EATEST", run_eatest, 0},
5784 { "SESSSETUP_BENCH", run_sesssetup_bench, 0},
5785 { "CHAIN1", run_chain1, 0},
5786 { "WINDOWS-WRITE", run_windows_write, 0},
5787 { "CLI_ECHO", run_cli_echo, 0},
5788 { "LOCAL-SUBSTITUTE", run_local_substitute, 0},
5789 { "LOCAL-GENCACHE", run_local_gencache, 0},
5790 { "LOCAL-RBTREE", run_local_rbtree, 0},
5791 { "LOCAL-MEMCACHE", run_local_memcache, 0},
5792 { "LOCAL-STREAM-NAME", run_local_stream_name, 0},
5793 { "LOCAL-WBCLIENT", run_local_wbclient, 0},
5798 /****************************************************************************
5799 run a specified test or "ALL"
5800 ****************************************************************************/
5801 static bool run_test(const char *name)
5808 if (strequal(name,"ALL")) {
5809 for (i=0;torture_ops[i].name;i++) {
5810 run_test(torture_ops[i].name);
5815 for (i=0;torture_ops[i].name;i++) {
5816 fstr_sprintf(randomfname, "\\XX%x",
5817 (unsigned)random());
5819 if (strequal(name, torture_ops[i].name)) {
5821 printf("Running %s\n", name);
5822 if (torture_ops[i].flags & FLAG_MULTIPROC) {
5823 t = create_procs(torture_ops[i].fn, &result);
5826 printf("TEST %s FAILED!\n", name);
5830 if (!torture_ops[i].fn(0)) {
5832 printf("TEST %s FAILED!\n", name);
5836 printf("%s took %g secs\n\n", name, t);
5841 printf("Did not find a test named %s\n", name);
5849 static void usage(void)
5853 printf("WARNING samba4 test suite is much more complete nowadays.\n");
5854 printf("Please use samba4 torture.\n\n");
5856 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
5858 printf("\t-d debuglevel\n");
5859 printf("\t-U user%%pass\n");
5860 printf("\t-k use kerberos\n");
5861 printf("\t-N numprocs\n");
5862 printf("\t-n my_netbios_name\n");
5863 printf("\t-W workgroup\n");
5864 printf("\t-o num_operations\n");
5865 printf("\t-O socket_options\n");
5866 printf("\t-m maximum protocol\n");
5867 printf("\t-L use oplocks\n");
5868 printf("\t-c CLIENT.TXT specify client load file for NBENCH\n");
5869 printf("\t-A showall\n");
5870 printf("\t-p port\n");
5871 printf("\t-s seed\n");
5872 printf("\t-b unclist_filename specify multiple shares for multiple connections\n");
5875 printf("tests are:");
5876 for (i=0;torture_ops[i].name;i++) {
5877 printf(" %s", torture_ops[i].name);
5881 printf("default test is ALL\n");
5886 /****************************************************************************
5888 ****************************************************************************/
5889 int main(int argc,char *argv[])
5895 bool correct = True;
5896 TALLOC_CTX *frame = talloc_stackframe();
5897 int seed = time(NULL);
5901 #ifdef HAVE_SETBUFFER
5902 setbuffer(stdout, NULL, 0);
5907 if (is_default_dyn_CONFIGFILE()) {
5908 if(getenv("SMB_CONF_PATH")) {
5909 set_dyn_CONFIGFILE(getenv("SMB_CONF_PATH"));
5912 lp_load(get_dyn_CONFIGFILE(),True,False,False,True);
5919 for(p = argv[1]; *p; p++)
5923 if (strncmp(argv[1], "//", 2)) {
5927 fstrcpy(host, &argv[1][2]);
5928 p = strchr_m(&host[2],'/');
5933 fstrcpy(share, p+1);
5935 fstrcpy(myname, get_myname(talloc_tos()));
5937 fprintf(stderr, "Failed to get my hostname.\n");
5941 if (*username == 0 && getenv("LOGNAME")) {
5942 fstrcpy(username,getenv("LOGNAME"));
5948 fstrcpy(workgroup, lp_workgroup());
5950 while ((opt = getopt(argc, argv, "p:hW:U:n:N:O:o:m:Ld:Aec:ks:b:B:")) != EOF) {
5953 port_to_use = atoi(optarg);
5956 seed = atoi(optarg);
5959 fstrcpy(workgroup,optarg);
5962 max_protocol = interpret_protocol(optarg, max_protocol);
5965 nprocs = atoi(optarg);
5968 torture_numops = atoi(optarg);
5971 DEBUGLEVEL = atoi(optarg);
5980 torture_showall = True;
5983 fstrcpy(myname, optarg);
5986 client_txt = optarg;
5993 use_kerberos = True;
5995 d_printf("No kerberos support compiled in\n");
6001 fstrcpy(username,optarg);
6002 p = strchr_m(username,'%');
6005 fstrcpy(password, p+1);
6010 fstrcpy(multishare_conn_fname, optarg);
6011 use_multishare_conn = True;
6014 torture_blocksize = atoi(optarg);
6017 printf("Unknown option %c (%d)\n", (char)opt, opt);
6022 d_printf("using seed %d\n", seed);
6026 if(use_kerberos && !gotuser) gotpass = True;
6029 p = getpass("Password:");
6031 fstrcpy(password, p);
6036 printf("host=%s share=%s user=%s myname=%s\n",
6037 host, share, username, myname);
6039 if (argc == optind) {
6040 correct = run_test("ALL");
6042 for (i=optind;i<argc;i++) {
6043 if (!run_test(argv[i])) {