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 == (uint16_t)-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 * This demonstrates a problem with our use of GPFS share modes: A file
2088 * descriptor sitting in the pending close queue holding a GPFS share mode
2089 * blocks opening a file another time. Happens with Word 2007 temp files.
2090 * With "posix locking = yes" and "gpfs:sharemodes = yes" enabled, the third
2091 * open is denied with NT_STATUS_SHARING_VIOLATION.
2094 static bool run_locktest8(int dummy)
2096 struct cli_state *cli1;
2097 const char *fname = "\\lockt8.lck";
2098 uint16_t fnum1, fnum2;
2100 bool correct = False;
2103 if (!torture_open_connection(&cli1, 0)) {
2107 cli_sockopt(cli1, sockops);
2109 printf("starting locktest8\n");
2111 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
2113 status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_WRITE,
2115 if (!NT_STATUS_IS_OK(status)) {
2116 d_fprintf(stderr, "cli_open returned %s\n", cli_errstr(cli1));
2120 memset(buf, 0, sizeof(buf));
2122 status = cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum2);
2123 if (!NT_STATUS_IS_OK(status)) {
2124 d_fprintf(stderr, "cli_open second time returned %s\n",
2129 if (!cli_lock(cli1, fnum2, 1, 1, 0, READ_LOCK)) {
2130 printf("Unable to apply read lock on range 1:1, error was "
2131 "%s\n", cli_errstr(cli1));
2135 status = cli_close(cli1, fnum1);
2136 if (!NT_STATUS_IS_OK(status)) {
2137 d_fprintf(stderr, "cli_close(fnum1) %s\n", cli_errstr(cli1));
2141 status = cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
2142 if (!NT_STATUS_IS_OK(status)) {
2143 d_fprintf(stderr, "cli_open third time returned %s\n",
2151 cli_close(cli1, fnum1);
2152 cli_close(cli1, fnum2);
2153 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
2154 torture_close_connection(cli1);
2156 printf("finished locktest8\n");
2161 test whether fnums and tids open on one VC are available on another (a major
2164 static bool run_fdpasstest(int dummy)
2166 struct cli_state *cli1, *cli2;
2167 const char *fname = "\\fdpass.tst";
2171 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
2174 cli_sockopt(cli1, sockops);
2175 cli_sockopt(cli2, sockops);
2177 printf("starting fdpasstest\n");
2179 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
2181 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
2182 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2186 if (cli_write(cli1, fnum1, 0, "hello world\n", 0, 13) != 13) {
2187 printf("write failed (%s)\n", cli_errstr(cli1));
2191 cli2->vuid = cli1->vuid;
2192 cli2->cnum = cli1->cnum;
2193 cli2->pid = cli1->pid;
2195 if (cli_read(cli2, fnum1, buf, 0, 13) == 13) {
2196 printf("read succeeded! nasty security hole [%s]\n",
2201 cli_close(cli1, fnum1);
2202 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
2204 torture_close_connection(cli1);
2205 torture_close_connection(cli2);
2207 printf("finished fdpasstest\n");
2211 static bool run_fdsesstest(int dummy)
2213 struct cli_state *cli;
2218 const char *fname = "\\fdsess.tst";
2219 const char *fname1 = "\\fdsess1.tst";
2225 if (!torture_open_connection(&cli, 0))
2227 cli_sockopt(cli, sockops);
2229 if (!torture_cli_session_setup2(cli, &new_vuid))
2232 saved_cnum = cli->cnum;
2233 if (!NT_STATUS_IS_OK(cli_tcon_andx(cli, share, "?????", "", 1)))
2235 new_cnum = cli->cnum;
2236 cli->cnum = saved_cnum;
2238 printf("starting fdsesstest\n");
2240 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
2241 cli_unlink(cli, fname1, aSYSTEM | aHIDDEN);
2243 if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
2244 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
2248 if (cli_write(cli, fnum1, 0, "hello world\n", 0, 13) != 13) {
2249 printf("write failed (%s)\n", cli_errstr(cli));
2253 saved_vuid = cli->vuid;
2254 cli->vuid = new_vuid;
2256 if (cli_read(cli, fnum1, buf, 0, 13) == 13) {
2257 printf("read succeeded with different vuid! nasty security hole [%s]\n",
2261 /* Try to open a file with different vuid, samba cnum. */
2262 if (NT_STATUS_IS_OK(cli_open(cli, fname1, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum2))) {
2263 printf("create with different vuid, same cnum succeeded.\n");
2264 cli_close(cli, fnum2);
2265 cli_unlink(cli, fname1, aSYSTEM | aHIDDEN);
2267 printf("create with different vuid, same cnum failed.\n");
2268 printf("This will cause problems with service clients.\n");
2272 cli->vuid = saved_vuid;
2274 /* Try with same vuid, different cnum. */
2275 cli->cnum = new_cnum;
2277 if (cli_read(cli, fnum1, buf, 0, 13) == 13) {
2278 printf("read succeeded with different cnum![%s]\n",
2283 cli->cnum = saved_cnum;
2284 cli_close(cli, fnum1);
2285 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
2287 torture_close_connection(cli);
2289 printf("finished fdsesstest\n");
2294 This test checks that
2296 1) the server does not allow an unlink on a file that is open
2298 static bool run_unlinktest(int dummy)
2300 struct cli_state *cli;
2301 const char *fname = "\\unlink.tst";
2303 bool correct = True;
2305 if (!torture_open_connection(&cli, 0)) {
2309 cli_sockopt(cli, sockops);
2311 printf("starting unlink test\n");
2313 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
2317 if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum))) {
2318 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
2322 if (NT_STATUS_IS_OK(cli_unlink(cli, fname, aSYSTEM | aHIDDEN))) {
2323 printf("error: server allowed unlink on an open file\n");
2326 correct = check_error(__LINE__, cli, ERRDOS, ERRbadshare,
2327 NT_STATUS_SHARING_VIOLATION);
2330 cli_close(cli, fnum);
2331 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
2333 if (!torture_close_connection(cli)) {
2337 printf("unlink test finished\n");
2344 test how many open files this server supports on the one socket
2346 static bool run_maxfidtest(int dummy)
2348 struct cli_state *cli;
2349 const char *ftemplate = "\\maxfid.%d.%d";
2351 uint16_t fnums[0x11000];
2354 bool correct = True;
2359 printf("failed to connect\n");
2363 cli_sockopt(cli, sockops);
2365 for (i=0; i<0x11000; i++) {
2366 slprintf(fname,sizeof(fname)-1,ftemplate, i,(int)getpid());
2367 if (!NT_STATUS_IS_OK(cli_open(cli, fname,
2368 O_RDWR|O_CREAT|O_TRUNC, DENY_NONE, &fnums[i]))) {
2369 printf("open of %s failed (%s)\n",
2370 fname, cli_errstr(cli));
2371 printf("maximum fnum is %d\n", i);
2379 printf("cleaning up\n");
2381 slprintf(fname,sizeof(fname)-1,ftemplate, i,(int)getpid());
2382 cli_close(cli, fnums[i]);
2383 if (!NT_STATUS_IS_OK(cli_unlink(cli, fname, aSYSTEM | aHIDDEN))) {
2384 printf("unlink of %s failed (%s)\n",
2385 fname, cli_errstr(cli));
2392 printf("maxfid test finished\n");
2393 if (!torture_close_connection(cli)) {
2399 /* generate a random buffer */
2400 static void rand_buf(char *buf, int len)
2403 *buf = (char)sys_random();
2408 /* send smb negprot commands, not reading the response */
2409 static bool run_negprot_nowait(int dummy)
2412 static struct cli_state *cli;
2413 bool correct = True;
2415 printf("starting negprot nowait test\n");
2417 if (!(cli = open_nbt_connection())) {
2421 for (i=0;i<50000;i++) {
2422 cli_negprot_sendsync(cli);
2425 if (!torture_close_connection(cli)) {
2429 printf("finished negprot nowait test\n");
2435 /* send random IPC commands */
2436 static bool run_randomipc(int dummy)
2438 char *rparam = NULL;
2440 unsigned int rdrcnt,rprcnt;
2442 int api, param_len, i;
2443 struct cli_state *cli;
2444 bool correct = True;
2447 printf("starting random ipc test\n");
2449 if (!torture_open_connection(&cli, 0)) {
2453 for (i=0;i<count;i++) {
2454 api = sys_random() % 500;
2455 param_len = (sys_random() % 64);
2457 rand_buf(param, param_len);
2462 param, param_len, 8,
2463 NULL, 0, BUFFER_SIZE,
2467 printf("%d/%d\r", i,count);
2470 printf("%d/%d\n", i, count);
2472 if (!torture_close_connection(cli)) {
2476 printf("finished random ipc test\n");
2483 static void browse_callback(const char *sname, uint32 stype,
2484 const char *comment, void *state)
2486 printf("\t%20.20s %08x %s\n", sname, stype, comment);
2492 This test checks the browse list code
2495 static bool run_browsetest(int dummy)
2497 static struct cli_state *cli;
2498 bool correct = True;
2500 printf("starting browse test\n");
2502 if (!torture_open_connection(&cli, 0)) {
2506 printf("domain list:\n");
2507 cli_NetServerEnum(cli, cli->server_domain,
2508 SV_TYPE_DOMAIN_ENUM,
2509 browse_callback, NULL);
2511 printf("machine list:\n");
2512 cli_NetServerEnum(cli, cli->server_domain,
2514 browse_callback, NULL);
2516 if (!torture_close_connection(cli)) {
2520 printf("browse test finished\n");
2528 This checks how the getatr calls works
2530 static bool run_attrtest(int dummy)
2532 struct cli_state *cli;
2535 const char *fname = "\\attrib123456789.tst";
2536 bool correct = True;
2538 printf("starting attrib test\n");
2540 if (!torture_open_connection(&cli, 0)) {
2544 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
2545 cli_open(cli, fname,
2546 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
2547 cli_close(cli, fnum);
2548 if (!NT_STATUS_IS_OK(cli_getatr(cli, fname, NULL, NULL, &t))) {
2549 printf("getatr failed (%s)\n", cli_errstr(cli));
2553 if (abs(t - time(NULL)) > 60*60*24*10) {
2554 printf("ERROR: SMBgetatr bug. time is %s",
2560 t2 = t-60*60*24; /* 1 day ago */
2562 if (!NT_STATUS_IS_OK(cli_setatr(cli, fname, 0, t2))) {
2563 printf("setatr failed (%s)\n", cli_errstr(cli));
2567 if (!NT_STATUS_IS_OK(cli_getatr(cli, fname, NULL, NULL, &t))) {
2568 printf("getatr failed (%s)\n", cli_errstr(cli));
2573 printf("ERROR: getatr/setatr bug. times are\n%s",
2575 printf("%s", ctime(&t2));
2579 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
2581 if (!torture_close_connection(cli)) {
2585 printf("attrib test finished\n");
2592 This checks a couple of trans2 calls
2594 static bool run_trans2test(int dummy)
2596 struct cli_state *cli;
2599 time_t c_time, a_time, m_time;
2600 struct timespec c_time_ts, a_time_ts, m_time_ts, w_time_ts, m_time2_ts;
2601 const char *fname = "\\trans2.tst";
2602 const char *dname = "\\trans2";
2603 const char *fname2 = "\\trans2\\trans2.tst";
2605 bool correct = True;
2607 printf("starting trans2 test\n");
2609 if (!torture_open_connection(&cli, 0)) {
2613 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
2614 cli_open(cli, fname,
2615 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
2616 if (!cli_qfileinfo(cli, fnum, NULL, &size, &c_time_ts, &a_time_ts, &w_time_ts,
2617 &m_time_ts, NULL)) {
2618 printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(cli));
2622 if (!cli_qfilename(cli, fnum, pname, sizeof(pname))) {
2623 printf("ERROR: qfilename failed (%s)\n", cli_errstr(cli));
2627 if (strcmp(pname, fname)) {
2628 printf("qfilename gave different name? [%s] [%s]\n",
2633 cli_close(cli, fnum);
2637 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
2638 if (!NT_STATUS_IS_OK(cli_open(cli, fname,
2639 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum))) {
2640 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
2643 cli_close(cli, fnum);
2645 if (!cli_qpathinfo(cli, fname, &c_time, &a_time, &m_time, &size, NULL)) {
2646 printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(cli));
2649 if (c_time != m_time) {
2650 printf("create time=%s", ctime(&c_time));
2651 printf("modify time=%s", ctime(&m_time));
2652 printf("This system appears to have sticky create times\n");
2654 if (a_time % (60*60) == 0) {
2655 printf("access time=%s", ctime(&a_time));
2656 printf("This system appears to set a midnight access time\n");
2660 if (abs(m_time - time(NULL)) > 60*60*24*7) {
2661 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
2667 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
2668 cli_open(cli, fname,
2669 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
2670 cli_close(cli, fnum);
2671 if (!cli_qpathinfo2(cli, fname, &c_time_ts, &a_time_ts, &w_time_ts,
2672 &m_time_ts, &size, NULL, NULL)) {
2673 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2676 if (w_time_ts.tv_sec < 60*60*24*2) {
2677 printf("write time=%s", ctime(&w_time_ts.tv_sec));
2678 printf("This system appears to set a initial 0 write time\n");
2683 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
2686 /* check if the server updates the directory modification time
2687 when creating a new file */
2688 if (!NT_STATUS_IS_OK(cli_mkdir(cli, dname))) {
2689 printf("ERROR: mkdir failed (%s)\n", cli_errstr(cli));
2693 if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts, &w_time_ts,
2694 &m_time_ts, &size, NULL, NULL)) {
2695 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2699 cli_open(cli, fname2,
2700 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
2701 cli_write(cli, fnum, 0, (char *)&fnum, 0, sizeof(fnum));
2702 cli_close(cli, fnum);
2703 if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts, &w_time_ts,
2704 &m_time2_ts, &size, NULL, NULL)) {
2705 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2708 if (memcmp(&m_time_ts, &m_time2_ts, sizeof(struct timespec))
2710 printf("This system does not update directory modification times\n");
2714 cli_unlink(cli, fname2, aSYSTEM | aHIDDEN);
2715 cli_rmdir(cli, dname);
2717 if (!torture_close_connection(cli)) {
2721 printf("trans2 test finished\n");
2727 This checks new W2K calls.
2730 static bool new_trans(struct cli_state *pcli, int fnum, int level)
2734 bool correct = True;
2736 if (!cli_qfileinfo_test(pcli, fnum, level, &buf, &len)) {
2737 printf("ERROR: qfileinfo (%d) failed (%s)\n", level, cli_errstr(pcli));
2740 printf("qfileinfo: level %d, len = %u\n", level, len);
2741 dump_data(0, (uint8 *)buf, len);
2748 static bool run_w2ktest(int dummy)
2750 struct cli_state *cli;
2752 const char *fname = "\\w2ktest\\w2k.tst";
2754 bool correct = True;
2756 printf("starting w2k test\n");
2758 if (!torture_open_connection(&cli, 0)) {
2762 cli_open(cli, fname,
2763 O_RDWR | O_CREAT , DENY_NONE, &fnum);
2765 for (level = 1004; level < 1040; level++) {
2766 new_trans(cli, fnum, level);
2769 cli_close(cli, fnum);
2771 if (!torture_close_connection(cli)) {
2775 printf("w2k test finished\n");
2782 this is a harness for some oplock tests
2784 static bool run_oplock1(int dummy)
2786 struct cli_state *cli1;
2787 const char *fname = "\\lockt1.lck";
2789 bool correct = True;
2791 printf("starting oplock test 1\n");
2793 if (!torture_open_connection(&cli1, 0)) {
2797 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
2799 cli_sockopt(cli1, sockops);
2801 cli1->use_oplocks = True;
2803 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
2804 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2808 cli1->use_oplocks = False;
2810 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
2811 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
2813 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
2814 printf("close2 failed (%s)\n", cli_errstr(cli1));
2818 if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname, aSYSTEM | aHIDDEN))) {
2819 printf("unlink failed (%s)\n", cli_errstr(cli1));
2823 if (!torture_close_connection(cli1)) {
2827 printf("finished oplock test 1\n");
2832 static bool run_oplock2(int dummy)
2834 struct cli_state *cli1, *cli2;
2835 const char *fname = "\\lockt2.lck";
2836 uint16_t fnum1, fnum2;
2837 int saved_use_oplocks = use_oplocks;
2839 bool correct = True;
2840 volatile bool *shared_correct;
2842 shared_correct = (volatile bool *)shm_setup(sizeof(bool));
2843 *shared_correct = True;
2845 use_level_II_oplocks = True;
2848 printf("starting oplock test 2\n");
2850 if (!torture_open_connection(&cli1, 0)) {
2851 use_level_II_oplocks = False;
2852 use_oplocks = saved_use_oplocks;
2856 cli1->use_oplocks = True;
2857 cli1->use_level_II_oplocks = True;
2859 if (!torture_open_connection(&cli2, 1)) {
2860 use_level_II_oplocks = False;
2861 use_oplocks = saved_use_oplocks;
2865 cli2->use_oplocks = True;
2866 cli2->use_level_II_oplocks = True;
2868 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
2870 cli_sockopt(cli1, sockops);
2871 cli_sockopt(cli2, sockops);
2873 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
2874 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2878 /* Don't need the globals any more. */
2879 use_level_II_oplocks = False;
2880 use_oplocks = saved_use_oplocks;
2884 if (!NT_STATUS_IS_OK(cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2))) {
2885 printf("second open of %s failed (%s)\n", fname, cli_errstr(cli1));
2886 *shared_correct = False;
2892 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
2893 printf("close2 failed (%s)\n", cli_errstr(cli1));
2894 *shared_correct = False;
2902 /* Ensure cli1 processes the break. Empty file should always return 0
2905 if (cli_read(cli1, fnum1, buf, 0, 4) != 0) {
2906 printf("read on fnum1 failed (%s)\n", cli_errstr(cli1));
2910 /* Should now be at level II. */
2911 /* Test if sending a write locks causes a break to none. */
2913 if (!cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK)) {
2914 printf("lock failed (%s)\n", cli_errstr(cli1));
2918 cli_unlock(cli1, fnum1, 0, 4);
2922 if (!cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
2923 printf("lock failed (%s)\n", cli_errstr(cli1));
2927 cli_unlock(cli1, fnum1, 0, 4);
2931 cli_read(cli1, fnum1, buf, 0, 4);
2934 if (cli_write(cli1, fnum1, 0, buf, 0, 4) != 4) {
2935 printf("write on fnum1 failed (%s)\n", cli_errstr(cli1));
2940 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
2941 printf("close1 failed (%s)\n", cli_errstr(cli1));
2947 if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname, aSYSTEM | aHIDDEN))) {
2948 printf("unlink failed (%s)\n", cli_errstr(cli1));
2952 if (!torture_close_connection(cli1)) {
2956 if (!*shared_correct) {
2960 printf("finished oplock test 2\n");
2965 /* handler for oplock 3 tests */
2966 static NTSTATUS oplock3_handler(struct cli_state *cli, uint16_t fnum, unsigned char level)
2968 printf("got oplock break fnum=%d level=%d\n",
2970 return cli_oplock_ack(cli, fnum, level);
2973 static bool run_oplock3(int dummy)
2975 struct cli_state *cli;
2976 const char *fname = "\\oplockt3.dat";
2978 char buf[4] = "abcd";
2979 bool correct = True;
2980 volatile bool *shared_correct;
2982 shared_correct = (volatile bool *)shm_setup(sizeof(bool));
2983 *shared_correct = True;
2985 printf("starting oplock test 3\n");
2990 use_level_II_oplocks = True;
2991 if (!torture_open_connection(&cli, 0)) {
2992 *shared_correct = False;
2996 /* try to trigger a oplock break in parent */
2997 cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum);
2998 cli_write(cli, fnum, 0, buf, 0, 4);
3004 use_level_II_oplocks = True;
3005 if (!torture_open_connection(&cli, 1)) { /* other is forked */
3008 cli_oplock_handler(cli, oplock3_handler);
3009 cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum);
3010 cli_write(cli, fnum, 0, buf, 0, 4);
3011 cli_close(cli, fnum);
3012 cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum);
3013 cli->timeout = 20000;
3014 cli_receive_smb(cli);
3015 printf("finished oplock test 3\n");
3017 return (correct && *shared_correct);
3019 /* What are we looking for here? What's sucess and what's FAILURE? */
3025 Test delete on close semantics.
3027 static bool run_deletetest(int dummy)
3029 struct cli_state *cli1 = NULL;
3030 struct cli_state *cli2 = NULL;
3031 const char *fname = "\\delete.file";
3032 uint16_t fnum1 = (uint16_t)-1;
3033 uint16_t fnum2 = (uint16_t)-1;
3034 bool correct = True;
3036 printf("starting delete test\n");
3038 if (!torture_open_connection(&cli1, 0)) {
3042 cli_sockopt(cli1, sockops);
3044 /* Test 1 - this should delete the file on close. */
3046 cli_setatr(cli1, fname, 0, 0);
3047 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3049 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
3050 0, FILE_OVERWRITE_IF,
3051 FILE_DELETE_ON_CLOSE, 0, &fnum1))) {
3052 printf("[1] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3059 uint32 *accinfo = NULL;
3061 cli_qfileinfo_test(cli1, fnum1, SMB_FILE_ACCESS_INFORMATION, (char **)&accinfo, &len);
3063 printf("access mode = 0x%lx\n", *accinfo);
3068 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3069 printf("[1] close failed (%s)\n", cli_errstr(cli1));
3074 if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1))) {
3075 printf("[1] open of %s succeeded (should fail)\n", fname);
3080 printf("first delete on close test succeeded.\n");
3082 /* Test 2 - this should delete the file on close. */
3084 cli_setatr(cli1, fname, 0, 0);
3085 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3087 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS,
3088 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
3089 FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3090 printf("[2] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3095 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
3096 printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
3101 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3102 printf("[2] close failed (%s)\n", cli_errstr(cli1));
3107 if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
3108 printf("[2] open of %s succeeded should have been deleted on close !\n", fname);
3109 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3110 printf("[2] close failed (%s)\n", cli_errstr(cli1));
3114 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3116 printf("second delete on close test succeeded.\n");
3119 cli_setatr(cli1, fname, 0, 0);
3120 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3122 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
3123 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3124 printf("[3] open - 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3129 /* This should fail with a sharing violation - open for delete is only compatible
3130 with SHARE_DELETE. */
3132 if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3133 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0, 0, &fnum2))) {
3134 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname);
3139 /* This should succeed. */
3141 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3142 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0, 0, &fnum2))) {
3143 printf("[3] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
3148 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
3149 printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
3154 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3155 printf("[3] close 1 failed (%s)\n", cli_errstr(cli1));
3160 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum2))) {
3161 printf("[3] close 2 failed (%s)\n", cli_errstr(cli1));
3166 /* This should fail - file should no longer be there. */
3168 if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
3169 printf("[3] open of %s succeeded should have been deleted on close !\n", fname);
3170 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3171 printf("[3] close failed (%s)\n", cli_errstr(cli1));
3173 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3177 printf("third delete on close test succeeded.\n");
3180 cli_setatr(cli1, fname, 0, 0);
3181 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3183 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3184 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3185 printf("[4] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3190 /* This should succeed. */
3191 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
3192 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0, 0, &fnum2))) {
3193 printf("[4] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
3198 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum2))) {
3199 printf("[4] close - 1 failed (%s)\n", cli_errstr(cli1));
3204 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
3205 printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
3210 /* This should fail - no more opens once delete on close set. */
3211 if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
3212 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3213 FILE_OPEN, 0, 0, &fnum2))) {
3214 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname );
3218 printf("fourth delete on close test succeeded.\n");
3220 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3221 printf("[4] close - 2 failed (%s)\n", cli_errstr(cli1));
3227 cli_setatr(cli1, fname, 0, 0);
3228 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3230 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum1))) {
3231 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3236 /* This should fail - only allowed on NT opens with DELETE access. */
3238 if (cli_nt_delete_on_close(cli1, fnum1, True)) {
3239 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
3244 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3245 printf("[5] close - 2 failed (%s)\n", cli_errstr(cli1));
3250 printf("fifth delete on close test succeeded.\n");
3253 cli_setatr(cli1, fname, 0, 0);
3254 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3256 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
3257 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3258 FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3259 printf("[6] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3264 /* This should fail - only allowed on NT opens with DELETE access. */
3266 if (cli_nt_delete_on_close(cli1, fnum1, True)) {
3267 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
3272 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3273 printf("[6] close - 2 failed (%s)\n", cli_errstr(cli1));
3278 printf("sixth delete on close test succeeded.\n");
3281 cli_setatr(cli1, fname, 0, 0);
3282 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3284 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3285 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3286 printf("[7] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3291 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
3292 printf("[7] setting delete_on_close on file failed !\n");
3297 if (!cli_nt_delete_on_close(cli1, fnum1, False)) {
3298 printf("[7] unsetting delete_on_close on file failed !\n");
3303 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3304 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
3309 /* This next open should succeed - we reset the flag. */
3311 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
3312 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3317 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3318 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
3323 printf("seventh delete on close test succeeded.\n");
3326 cli_setatr(cli1, fname, 0, 0);
3327 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3329 if (!torture_open_connection(&cli2, 1)) {
3330 printf("[8] failed to open second connection.\n");
3335 cli_sockopt(cli1, sockops);
3337 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3338 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3339 FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3340 printf("[8] open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3345 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3346 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3347 FILE_OPEN, 0, 0, &fnum2))) {
3348 printf("[8] open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3353 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
3354 printf("[8] setting delete_on_close on file failed !\n");
3359 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3360 printf("[8] close - 1 failed (%s)\n", cli_errstr(cli1));
3365 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
3366 printf("[8] close - 2 failed (%s)\n", cli_errstr(cli2));
3371 /* This should fail.. */
3372 if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
3373 printf("[8] open of %s succeeded should have been deleted on close !\n", fname);
3377 printf("eighth delete on close test succeeded.\n");
3379 /* This should fail - we need to set DELETE_ACCESS. */
3380 if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0,FILE_READ_DATA|FILE_WRITE_DATA,
3381 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, 0, &fnum1))) {
3382 printf("[9] open of %s succeeded should have failed!\n", fname);
3387 printf("ninth delete on close test succeeded.\n");
3389 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3390 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, 0, &fnum1))) {
3391 printf("[10] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3396 /* This should delete the file. */
3397 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3398 printf("[10] close failed (%s)\n", cli_errstr(cli1));
3403 /* This should fail.. */
3404 if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
3405 printf("[10] open of %s succeeded should have been deleted on close !\n", fname);
3409 printf("tenth delete on close test succeeded.\n");
3411 cli_setatr(cli1, fname, 0, 0);
3412 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3414 /* What error do we get when attempting to open a read-only file with
3417 /* Create a readonly file. */
3418 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
3419 FILE_ATTRIBUTE_READONLY, FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3420 printf("[11] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3425 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3426 printf("[11] close failed (%s)\n", cli_errstr(cli1));
3431 /* Now try open for delete access. */
3432 if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES|DELETE_ACCESS,
3433 0, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3434 FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3435 printf("[11] open of %s succeeded should have been denied with ACCESS_DENIED!\n", fname);
3436 cli_close(cli1, fnum1);
3440 NTSTATUS nterr = cli_nt_error(cli1);
3441 if (!NT_STATUS_EQUAL(nterr,NT_STATUS_ACCESS_DENIED)) {
3442 printf("[11] open of %s should have been denied with ACCESS_DENIED! Got error %s\n", fname, nt_errstr(nterr));
3446 printf("eleventh delete on close test succeeded.\n");
3450 printf("finished delete test\n");
3453 /* FIXME: This will crash if we aborted before cli2 got
3454 * intialized, because these functions don't handle
3455 * uninitialized connections. */
3457 if (fnum1 != (uint16_t)-1) cli_close(cli1, fnum1);
3458 if (fnum2 != (uint16_t)-1) cli_close(cli1, fnum2);
3459 cli_setatr(cli1, fname, 0, 0);
3460 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3462 if (cli1 && !torture_close_connection(cli1)) {
3465 if (cli2 && !torture_close_connection(cli2)) {
3473 print out server properties
3475 static bool run_properties(int dummy)
3477 struct cli_state *cli;
3478 bool correct = True;
3480 printf("starting properties test\n");
3484 if (!torture_open_connection(&cli, 0)) {
3488 cli_sockopt(cli, sockops);
3490 d_printf("Capabilities 0x%08x\n", cli->capabilities);
3492 if (!torture_close_connection(cli)) {
3501 /* FIRST_DESIRED_ACCESS 0xf019f */
3502 #define FIRST_DESIRED_ACCESS FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|\
3503 FILE_READ_EA| /* 0xf */ \
3504 FILE_WRITE_EA|FILE_READ_ATTRIBUTES| /* 0x90 */ \
3505 FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
3506 DELETE_ACCESS|READ_CONTROL_ACCESS|\
3507 WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS /* 0xf0000 */
3508 /* SECOND_DESIRED_ACCESS 0xe0080 */
3509 #define SECOND_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
3510 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
3511 WRITE_OWNER_ACCESS /* 0xe0000 */
3514 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
3515 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
3517 WRITE_OWNER_ACCESS /* */
3521 Test ntcreate calls made by xcopy
3523 static bool run_xcopy(int dummy)
3525 static struct cli_state *cli1;
3526 const char *fname = "\\test.txt";
3527 bool correct = True;
3528 uint16_t fnum1, fnum2;
3530 printf("starting xcopy test\n");
3532 if (!torture_open_connection(&cli1, 0)) {
3536 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0,
3537 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
3538 FILE_SHARE_NONE, FILE_OVERWRITE_IF,
3539 0x4044, 0, &fnum1))) {
3540 printf("First open failed - %s\n", cli_errstr(cli1));
3544 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0,
3545 SECOND_DESIRED_ACCESS, 0,
3546 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN,
3547 0x200000, 0, &fnum2))) {
3548 printf("second open failed - %s\n", cli_errstr(cli1));
3552 if (!torture_close_connection(cli1)) {
3560 Test rename on files open with share delete and no share delete.
3562 static bool run_rename(int dummy)
3564 static struct cli_state *cli1;
3565 const char *fname = "\\test.txt";
3566 const char *fname1 = "\\test1.txt";
3567 bool correct = True;
3571 printf("starting rename test\n");
3573 if (!torture_open_connection(&cli1, 0)) {
3577 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3578 cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
3579 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3580 FILE_SHARE_READ, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3581 printf("First open failed - %s\n", cli_errstr(cli1));
3585 if (!NT_STATUS_IS_OK(cli_rename(cli1, fname, fname1))) {
3586 printf("First rename failed (SHARE_READ) (this is correct) - %s\n", cli_errstr(cli1));
3588 printf("First rename succeeded (SHARE_READ) - this should have failed !\n");
3592 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3593 printf("close - 1 failed (%s)\n", cli_errstr(cli1));
3597 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3598 cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
3599 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3601 FILE_SHARE_DELETE|FILE_SHARE_NONE,
3603 FILE_SHARE_DELETE|FILE_SHARE_READ,
3605 FILE_OVERWRITE_IF, 0, 0, &fnum1);
3606 if (!NT_STATUS_IS_OK(status)) {
3607 printf("Second open failed - %s\n", cli_errstr(cli1));
3611 if (!NT_STATUS_IS_OK(cli_rename(cli1, fname, fname1))) {
3612 printf("Second rename failed (SHARE_DELETE | SHARE_READ) - this should have succeeded - %s\n", cli_errstr(cli1));
3615 printf("Second rename succeeded (SHARE_DELETE | SHARE_READ)\n");
3618 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3619 printf("close - 2 failed (%s)\n", cli_errstr(cli1));
3623 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3624 cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
3626 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, READ_CONTROL_ACCESS, FILE_ATTRIBUTE_NORMAL,
3627 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3628 printf("Third open failed - %s\n", cli_errstr(cli1));
3637 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
3638 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum2))) {
3639 printf("Fourth open failed - %s\n", cli_errstr(cli1));
3642 if (!cli_nt_delete_on_close(cli1, fnum2, True)) {
3643 printf("[8] setting delete_on_close on file failed !\n");
3647 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum2))) {
3648 printf("close - 4 failed (%s)\n", cli_errstr(cli1));
3654 if (!NT_STATUS_IS_OK(cli_rename(cli1, fname, fname1))) {
3655 printf("Third rename failed (SHARE_NONE) - this should have succeeded - %s\n", cli_errstr(cli1));
3658 printf("Third rename succeeded (SHARE_NONE)\n");
3661 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3662 printf("close - 3 failed (%s)\n", cli_errstr(cli1));
3666 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3667 cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
3671 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3672 FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3673 printf("Fourth open failed - %s\n", cli_errstr(cli1));
3677 if (!NT_STATUS_IS_OK(cli_rename(cli1, fname, fname1))) {
3678 printf("Fourth rename failed (SHARE_READ | SHARE_WRITE) (this is correct) - %s\n", cli_errstr(cli1));
3680 printf("Fourth rename succeeded (SHARE_READ | SHARE_WRITE) - this should have failed !\n");
3684 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3685 printf("close - 4 failed (%s)\n", cli_errstr(cli1));
3689 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3690 cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
3694 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3695 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3696 printf("Fifth open failed - %s\n", cli_errstr(cli1));
3700 if (!NT_STATUS_IS_OK(cli_rename(cli1, fname, fname1))) {
3701 printf("Fifth rename failed (SHARE_READ | SHARE_WRITE | SHARE_DELETE) - this should have succeeded - %s ! \n",
3705 printf("Fifth rename succeeded (SHARE_READ | SHARE_WRITE | SHARE_DELETE) (this is correct) - %s\n", cli_errstr(cli1));
3709 * Now check if the first name still exists ...
3712 /* if (!NT_STATUS_OP(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3713 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0, &fnum2))) {
3714 printf("Opening original file after rename of open file fails: %s\n",
3718 printf("Opening original file after rename of open file works ...\n");
3719 (void)cli_close(cli1, fnum2);
3725 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3726 printf("close - 5 failed (%s)\n", cli_errstr(cli1));
3730 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3731 cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
3733 if (!torture_close_connection(cli1)) {
3740 static bool run_pipe_number(int dummy)
3742 struct cli_state *cli1;
3743 const char *pipe_name = "\\SPOOLSS";
3747 printf("starting pipenumber test\n");
3748 if (!torture_open_connection(&cli1, 0)) {
3752 cli_sockopt(cli1, sockops);
3754 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, pipe_name, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
3755 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN_IF, 0, 0, &fnum))) {
3756 printf("Open of pipe %s failed with error (%s)\n", pipe_name, cli_errstr(cli1));
3760 printf("\r%6d", num_pipes);
3763 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes, pipe_name );
3764 torture_close_connection(cli1);
3769 Test open mode returns on read-only files.
3771 static bool run_opentest(int dummy)
3773 static struct cli_state *cli1;
3774 static struct cli_state *cli2;
3775 const char *fname = "\\readonly.file";
3776 uint16_t fnum1, fnum2;
3779 bool correct = True;
3782 printf("starting open test\n");
3784 if (!torture_open_connection(&cli1, 0)) {
3788 cli_setatr(cli1, fname, 0, 0);
3789 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3791 cli_sockopt(cli1, sockops);
3793 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
3794 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
3798 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3799 printf("close2 failed (%s)\n", cli_errstr(cli1));
3803 if (!NT_STATUS_IS_OK(cli_setatr(cli1, fname, aRONLY, 0))) {
3804 printf("cli_setatr failed (%s)\n", cli_errstr(cli1));
3808 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_WRITE, &fnum1))) {
3809 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
3813 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
3814 cli_open(cli1, fname, O_RDWR, DENY_ALL, &fnum2);
3816 if (check_error(__LINE__, cli1, ERRDOS, ERRnoaccess,
3817 NT_STATUS_ACCESS_DENIED)) {
3818 printf("correct error code ERRDOS/ERRnoaccess returned\n");
3821 printf("finished open test 1\n");
3823 cli_close(cli1, fnum1);
3825 /* Now try not readonly and ensure ERRbadshare is returned. */
3827 cli_setatr(cli1, fname, 0, 0);
3829 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_WRITE, &fnum1))) {
3830 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
3834 /* This will fail - but the error should be ERRshare. */
3835 cli_open(cli1, fname, O_RDWR, DENY_ALL, &fnum2);
3837 if (check_error(__LINE__, cli1, ERRDOS, ERRbadshare,
3838 NT_STATUS_SHARING_VIOLATION)) {
3839 printf("correct error code ERRDOS/ERRbadshare returned\n");
3842 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3843 printf("close2 failed (%s)\n", cli_errstr(cli1));
3847 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3849 printf("finished open test 2\n");
3851 /* Test truncate open disposition on file opened for read. */
3853 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
3854 printf("(3) open (1) of %s failed (%s)\n", fname, cli_errstr(cli1));
3858 /* write 20 bytes. */
3860 memset(buf, '\0', 20);
3862 if (cli_write(cli1, fnum1, 0, buf, 0, 20) != 20) {
3863 printf("write failed (%s)\n", cli_errstr(cli1));
3867 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3868 printf("(3) close1 failed (%s)\n", cli_errstr(cli1));
3872 /* Ensure size == 20. */
3873 if (!NT_STATUS_IS_OK(cli_getatr(cli1, fname, NULL, &fsize, NULL))) {
3874 printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
3879 printf("(3) file size != 20\n");
3883 /* Now test if we can truncate a file opened for readonly. */
3885 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE, &fnum1))) {
3886 printf("(3) open (2) of %s failed (%s)\n", fname, cli_errstr(cli1));
3890 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3891 printf("close2 failed (%s)\n", cli_errstr(cli1));
3895 /* Ensure size == 0. */
3896 if (!NT_STATUS_IS_OK(cli_getatr(cli1, fname, NULL, &fsize, NULL))) {
3897 printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
3902 printf("(3) file size != 0\n");
3905 printf("finished open test 3\n");
3907 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3910 printf("testing ctemp\n");
3911 fnum1 = cli_ctemp(cli1, "\\", &tmp_path);
3912 if (fnum1 == (uint16_t)-1) {
3913 printf("ctemp failed (%s)\n", cli_errstr(cli1));
3916 printf("ctemp gave path %s\n", tmp_path);
3917 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3918 printf("close of temp failed (%s)\n", cli_errstr(cli1));
3920 if (!NT_STATUS_IS_OK(cli_unlink(cli1, tmp_path, aSYSTEM | aHIDDEN))) {
3921 printf("unlink of temp failed (%s)\n", cli_errstr(cli1));
3924 /* Test the non-io opens... */
3926 if (!torture_open_connection(&cli2, 1)) {
3930 cli_setatr(cli2, fname, 0, 0);
3931 cli_unlink(cli2, fname, aSYSTEM | aHIDDEN);
3933 cli_sockopt(cli2, sockops);
3935 printf("TEST #1 testing 2 non-io opens (no delete)\n");
3937 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3938 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3939 printf("test 1 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3943 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3944 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0, &fnum2))) {
3945 printf("test 1 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3949 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3950 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3953 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
3954 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3958 printf("non-io open test #1 passed.\n");
3960 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3962 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
3964 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3965 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3966 printf("test 2 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3970 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3971 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0, &fnum2))) {
3972 printf("test 2 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3976 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3977 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3980 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
3981 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
3985 printf("non-io open test #2 passed.\n");
3987 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3989 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
3991 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3992 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3993 printf("test 3 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3997 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3998 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0, &fnum2))) {
3999 printf("test 3 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4003 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4004 printf("test 3 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4007 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
4008 printf("test 3 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4012 printf("non-io open test #3 passed.\n");
4014 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
4016 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
4018 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4019 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
4020 printf("test 4 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4024 if (NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4025 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0, &fnum2))) {
4026 printf("test 4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
4030 printf("test 3 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
4032 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4033 printf("test 4 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4037 printf("non-io open test #4 passed.\n");
4039 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
4041 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
4043 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4044 FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
4045 printf("test 5 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4049 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4050 FILE_SHARE_DELETE, FILE_OPEN_IF, 0, 0, &fnum2))) {
4051 printf("test 5 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4055 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4056 printf("test 5 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4060 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
4061 printf("test 5 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4065 printf("non-io open test #5 passed.\n");
4067 printf("TEST #6 testing 1 non-io open, one io open\n");
4069 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
4071 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
4072 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
4073 printf("test 6 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4077 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4078 FILE_SHARE_READ, FILE_OPEN_IF, 0, 0, &fnum2))) {
4079 printf("test 6 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4083 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4084 printf("test 6 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4088 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
4089 printf("test 6 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4093 printf("non-io open test #6 passed.\n");
4095 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
4097 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
4099 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
4100 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
4101 printf("test 7 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4105 if (NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4106 FILE_SHARE_READ|FILE_SHARE_DELETE, FILE_OPEN_IF, 0, 0, &fnum2))) {
4107 printf("test 7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
4111 printf("test 7 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
4113 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4114 printf("test 7 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4118 printf("non-io open test #7 passed.\n");
4120 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
4122 if (!torture_close_connection(cli1)) {
4125 if (!torture_close_connection(cli2)) {
4133 Test POSIX open /mkdir calls.
4135 static bool run_simple_posix_open_test(int dummy)
4137 static struct cli_state *cli1;
4138 const char *fname = "posix:file";
4139 const char *hname = "posix:hlink";
4140 const char *sname = "posix:symlink";
4141 const char *dname = "posix:dir";
4143 uint16 major, minor;
4144 uint32 caplow, caphigh;
4145 uint16_t fnum1 = (uint16_t)-1;
4146 bool correct = false;
4148 printf("Starting simple POSIX open test\n");
4150 if (!torture_open_connection(&cli1, 0)) {
4154 cli_sockopt(cli1, sockops);
4156 if (!SERVER_HAS_UNIX_CIFS(cli1)) {
4157 printf("Server doesn't support UNIX CIFS extensions.\n");
4161 if (!cli_unix_extensions_version(cli1, &major,
4162 &minor, &caplow, &caphigh)) {
4163 printf("Server didn't return UNIX CIFS extensions.\n");
4167 if (!cli_set_unix_extensions_capabilities(cli1,
4168 major, minor, caplow, caphigh)) {
4169 printf("Server doesn't support setting UNIX CIFS extensions.\n");
4173 cli_setatr(cli1, fname, 0, 0);
4174 cli_posix_unlink(cli1, fname);
4175 cli_setatr(cli1, dname, 0, 0);
4176 cli_posix_rmdir(cli1, dname);
4177 cli_setatr(cli1, hname, 0, 0);
4178 cli_posix_unlink(cli1, hname);
4179 cli_setatr(cli1, sname, 0, 0);
4180 cli_posix_unlink(cli1, sname);
4182 /* Create a directory. */
4183 if (!NT_STATUS_IS_OK(cli_posix_mkdir(cli1, dname, 0777))) {
4184 printf("POSIX mkdir of %s failed (%s)\n", dname, cli_errstr(cli1));
4188 if (!NT_STATUS_IS_OK(cli_posix_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, 0600, &fnum1))) {
4189 printf("POSIX create of %s failed (%s)\n", fname, cli_errstr(cli1));
4193 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4194 printf("close failed (%s)\n", cli_errstr(cli1));
4198 /* Now open the file again for read only. */
4199 if (!NT_STATUS_IS_OK(cli_posix_open(cli1, fname, O_RDONLY, 0, &fnum1))) {
4200 printf("POSIX open of %s failed (%s)\n", fname, cli_errstr(cli1));
4204 /* Now unlink while open. */
4205 if (!NT_STATUS_IS_OK(cli_posix_unlink(cli1, fname))) {
4206 printf("POSIX unlink of %s failed (%s)\n", fname, cli_errstr(cli1));
4210 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4211 printf("close(2) failed (%s)\n", cli_errstr(cli1));
4215 /* Ensure the file has gone. */
4216 if (NT_STATUS_IS_OK(cli_posix_open(cli1, fname, O_RDONLY, 0, &fnum1))) {
4217 printf("POSIX open of %s succeeded, should have been deleted.\n", fname);
4221 /* What happens when we try and POSIX open a directory ? */
4222 if (NT_STATUS_IS_OK(cli_posix_open(cli1, dname, O_RDONLY, 0, &fnum1))) {
4223 printf("POSIX open of directory %s succeeded, should have failed.\n", fname);
4226 if (!check_error(__LINE__, cli1, ERRDOS, EISDIR,
4227 NT_STATUS_FILE_IS_A_DIRECTORY)) {
4232 /* Create the file. */
4233 if (!NT_STATUS_IS_OK(cli_posix_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, 0600, &fnum1))) {
4234 printf("POSIX create of %s failed (%s)\n", fname, cli_errstr(cli1));
4238 /* Write some data into it. */
4239 if (cli_write(cli1, fnum1, 0, "TEST DATA\n", 0, 10) != 10) {
4240 printf("cli_write failed: %s\n", cli_errstr(cli1));
4244 cli_close(cli1, fnum1);
4246 /* Now create a hardlink. */
4247 if (!NT_STATUS_IS_OK(cli_posix_hardlink(cli1, fname, hname))) {
4248 printf("POSIX hardlink of %s failed (%s)\n", hname, cli_errstr(cli1));
4252 /* Now create a symlink. */
4253 if (!NT_STATUS_IS_OK(cli_posix_symlink(cli1, fname, sname))) {
4254 printf("POSIX symlink of %s failed (%s)\n", sname, cli_errstr(cli1));
4258 /* Open the hardlink for read. */
4259 if (!NT_STATUS_IS_OK(cli_posix_open(cli1, hname, O_RDONLY, 0, &fnum1))) {
4260 printf("POSIX open of %s failed (%s)\n", hname, cli_errstr(cli1));
4264 if (cli_read(cli1, fnum1, buf, 0, 10) != 10) {
4265 printf("POSIX read of %s failed (%s)\n", hname, cli_errstr(cli1));
4269 if (memcmp(buf, "TEST DATA\n", 10)) {
4270 printf("invalid data read from hardlink\n");
4274 cli_close(cli1, fnum1);
4276 /* Open the symlink for read - this should fail. A POSIX
4277 client should not be doing opens on a symlink. */
4278 if (NT_STATUS_IS_OK(cli_posix_open(cli1, sname, O_RDONLY, 0, &fnum1))) {
4279 printf("POSIX open of %s succeeded (should have failed)\n", sname);
4282 if (!check_error(__LINE__, cli1, ERRDOS, ERRbadpath,
4283 NT_STATUS_OBJECT_PATH_NOT_FOUND)) {
4288 /* TODO. Add and test cli_posix_readlink() call. */
4290 if (!NT_STATUS_IS_OK(cli_posix_rmdir(cli1, dname))) {
4291 printf("POSIX rmdir failed (%s)\n", cli_errstr(cli1));
4295 printf("Simple POSIX open test passed\n");
4300 if (fnum1 != (uint16_t)-1) {
4301 cli_close(cli1, fnum1);
4302 fnum1 = (uint16_t)-1;
4305 cli_setatr(cli1, sname, 0, 0);
4306 cli_posix_unlink(cli1, sname);
4307 cli_setatr(cli1, hname, 0, 0);
4308 cli_posix_unlink(cli1, hname);
4309 cli_setatr(cli1, fname, 0, 0);
4310 cli_posix_unlink(cli1, fname);
4311 cli_setatr(cli1, dname, 0, 0);
4312 cli_posix_rmdir(cli1, dname);
4314 if (!torture_close_connection(cli1)) {
4322 static uint32 open_attrs_table[] = {
4323 FILE_ATTRIBUTE_NORMAL,
4324 FILE_ATTRIBUTE_ARCHIVE,
4325 FILE_ATTRIBUTE_READONLY,
4326 FILE_ATTRIBUTE_HIDDEN,
4327 FILE_ATTRIBUTE_SYSTEM,
4329 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY,
4330 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN,
4331 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM,
4332 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
4333 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
4334 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
4336 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
4337 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
4338 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
4339 FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_SYSTEM,
4342 struct trunc_open_results {
4349 static struct trunc_open_results attr_results[] = {
4350 { 0, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
4351 { 1, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
4352 { 2, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
4353 { 16, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
4354 { 17, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
4355 { 18, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
4356 { 51, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4357 { 54, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4358 { 56, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
4359 { 68, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4360 { 71, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4361 { 73, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM },
4362 { 99, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4363 { 102, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4364 { 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 },
4365 { 116, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4366 { 119, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4367 { 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 },
4368 { 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 },
4369 { 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 },
4370 { 227, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4371 { 230, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4372 { 232, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
4373 { 244, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4374 { 247, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4375 { 249, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM }
4378 static bool run_openattrtest(int dummy)
4380 static struct cli_state *cli1;
4381 const char *fname = "\\openattr.file";
4383 bool correct = True;
4385 unsigned int i, j, k, l;
4387 printf("starting open attr test\n");
4389 if (!torture_open_connection(&cli1, 0)) {
4393 cli_sockopt(cli1, sockops);
4395 for (k = 0, i = 0; i < sizeof(open_attrs_table)/sizeof(uint32); i++) {
4396 cli_setatr(cli1, fname, 0, 0);
4397 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
4398 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_WRITE_DATA, open_attrs_table[i],
4399 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
4400 printf("open %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
4404 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4405 printf("close %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
4409 for (j = 0; j < sizeof(open_attrs_table)/sizeof(uint32); j++) {
4410 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA, open_attrs_table[j],
4411 FILE_SHARE_NONE, FILE_OVERWRITE, 0, 0, &fnum1))) {
4412 for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
4413 if (attr_results[l].num == k) {
4414 printf("[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(0x%x:%s)\n",
4415 k, open_attrs_table[i],
4416 open_attrs_table[j],
4417 fname, NT_STATUS_V(cli_nt_error(cli1)), cli_errstr(cli1));
4421 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_ACCESS_DENIED)) {
4422 printf("[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s\n",
4423 k, open_attrs_table[i], open_attrs_table[j],
4428 printf("[%d] trunc open 0x%x -> 0x%x failed\n", k, open_attrs_table[i], open_attrs_table[j]);
4434 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4435 printf("close %d (2) of %s failed (%s)\n", j, fname, cli_errstr(cli1));
4439 if (!NT_STATUS_IS_OK(cli_getatr(cli1, fname, &attr, NULL, NULL))) {
4440 printf("getatr(2) failed (%s)\n", cli_errstr(cli1));
4445 printf("[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n",
4446 k, open_attrs_table[i], open_attrs_table[j], attr );
4449 for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
4450 if (attr_results[l].num == k) {
4451 if (attr != attr_results[l].result_attr ||
4452 open_attrs_table[i] != attr_results[l].init_attr ||
4453 open_attrs_table[j] != attr_results[l].trunc_attr) {
4454 printf("getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x\n",
4455 open_attrs_table[i],
4456 open_attrs_table[j],
4458 attr_results[l].result_attr);
4468 cli_setatr(cli1, fname, 0, 0);
4469 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
4471 printf("open attr test %s.\n", correct ? "passed" : "failed");
4473 if (!torture_close_connection(cli1)) {
4479 static void list_fn(const char *mnt, file_info *finfo, const char *name, void *state)
4485 test directory listing speed
4487 static bool run_dirtest(int dummy)
4490 static struct cli_state *cli;
4493 bool correct = True;
4495 printf("starting directory test\n");
4497 if (!torture_open_connection(&cli, 0)) {
4501 cli_sockopt(cli, sockops);
4504 for (i=0;i<torture_numops;i++) {
4506 slprintf(fname, sizeof(fname), "\\%x", (int)random());
4507 if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum))) {
4508 fprintf(stderr,"Failed to open %s\n", fname);
4511 cli_close(cli, fnum);
4516 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
4517 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
4518 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
4520 printf("dirtest core %g seconds\n", end_timer() - t1);
4523 for (i=0;i<torture_numops;i++) {
4525 slprintf(fname, sizeof(fname), "\\%x", (int)random());
4526 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
4529 if (!torture_close_connection(cli)) {
4533 printf("finished dirtest\n");
4538 static void del_fn(const char *mnt, file_info *finfo, const char *mask, void *state)
4540 struct cli_state *pcli = (struct cli_state *)state;
4542 slprintf(fname, sizeof(fname), "\\LISTDIR\\%s", finfo->name);
4544 if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
4547 if (finfo->mode & aDIR) {
4548 if (!NT_STATUS_IS_OK(cli_rmdir(pcli, fname)))
4549 printf("del_fn: failed to rmdir %s\n,", fname );
4551 if (!NT_STATUS_IS_OK(cli_unlink(pcli, fname, aSYSTEM | aHIDDEN)))
4552 printf("del_fn: failed to unlink %s\n,", fname );
4558 sees what IOCTLs are supported
4560 bool torture_ioctl_test(int dummy)
4562 static struct cli_state *cli;
4563 uint16_t device, function;
4565 const char *fname = "\\ioctl.dat";
4569 if (!torture_open_connection(&cli, 0)) {
4573 printf("starting ioctl test\n");
4575 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
4577 if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum))) {
4578 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
4582 status = cli_raw_ioctl(cli, fnum, 0x2d0000 | (0x0420<<2), &blob);
4583 printf("ioctl device info: %s\n", cli_errstr(cli));
4585 status = cli_raw_ioctl(cli, fnum, IOCTL_QUERY_JOB_INFO, &blob);
4586 printf("ioctl job info: %s\n", cli_errstr(cli));
4588 for (device=0;device<0x100;device++) {
4589 printf("testing device=0x%x\n", device);
4590 for (function=0;function<0x100;function++) {
4591 uint32 code = (device<<16) | function;
4593 status = cli_raw_ioctl(cli, fnum, code, &blob);
4595 if (NT_STATUS_IS_OK(status)) {
4596 printf("ioctl 0x%x OK : %d bytes\n", (int)code,
4598 data_blob_free(&blob);
4603 if (!torture_close_connection(cli)) {
4612 tries varients of chkpath
4614 bool torture_chkpath_test(int dummy)
4616 static struct cli_state *cli;
4620 if (!torture_open_connection(&cli, 0)) {
4624 printf("starting chkpath test\n");
4626 /* cleanup from an old run */
4627 cli_rmdir(cli, "\\chkpath.dir\\dir2");
4628 cli_unlink(cli, "\\chkpath.dir\\*", aSYSTEM | aHIDDEN);
4629 cli_rmdir(cli, "\\chkpath.dir");
4631 if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\chkpath.dir"))) {
4632 printf("mkdir1 failed : %s\n", cli_errstr(cli));
4636 if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\chkpath.dir\\dir2"))) {
4637 printf("mkdir2 failed : %s\n", cli_errstr(cli));
4641 if (!NT_STATUS_IS_OK(cli_open(cli, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum))) {
4642 printf("open1 failed (%s)\n", cli_errstr(cli));
4645 cli_close(cli, fnum);
4647 if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir"))) {
4648 printf("chkpath1 failed: %s\n", cli_errstr(cli));
4652 if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir\\dir2"))) {
4653 printf("chkpath2 failed: %s\n", cli_errstr(cli));
4657 if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir\\foo.txt"))) {
4658 ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath,
4659 NT_STATUS_NOT_A_DIRECTORY);
4661 printf("* chkpath on a file should fail\n");
4665 if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir\\bar.txt"))) {
4666 ret = check_error(__LINE__, cli, ERRDOS, ERRbadfile,
4667 NT_STATUS_OBJECT_NAME_NOT_FOUND);
4669 printf("* chkpath on a non existant file should fail\n");
4673 if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir\\dirxx\\bar.txt"))) {
4674 ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath,
4675 NT_STATUS_OBJECT_PATH_NOT_FOUND);
4677 printf("* chkpath on a non existent component should fail\n");
4681 cli_rmdir(cli, "\\chkpath.dir\\dir2");
4682 cli_unlink(cli, "\\chkpath.dir\\*", aSYSTEM | aHIDDEN);
4683 cli_rmdir(cli, "\\chkpath.dir");
4685 if (!torture_close_connection(cli)) {
4692 static bool run_eatest(int dummy)
4694 static struct cli_state *cli;
4695 const char *fname = "\\eatest.txt";
4696 bool correct = True;
4700 struct ea_struct *ea_list = NULL;
4701 TALLOC_CTX *mem_ctx = talloc_init("eatest");
4703 printf("starting eatest\n");
4705 if (!torture_open_connection(&cli, 0)) {
4706 talloc_destroy(mem_ctx);
4710 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
4711 if (!NT_STATUS_IS_OK(cli_ntcreate(cli, fname, 0,
4712 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
4713 FILE_SHARE_NONE, FILE_OVERWRITE_IF,
4714 0x4044, 0, &fnum))) {
4715 printf("open failed - %s\n", cli_errstr(cli));
4716 talloc_destroy(mem_ctx);
4720 for (i = 0; i < 10; i++) {
4721 fstring ea_name, ea_val;
4723 slprintf(ea_name, sizeof(ea_name), "EA_%d", i);
4724 memset(ea_val, (char)i+1, i+1);
4725 if (!cli_set_ea_fnum(cli, fnum, ea_name, ea_val, i+1)) {
4726 printf("ea_set of name %s failed - %s\n", ea_name, cli_errstr(cli));
4727 talloc_destroy(mem_ctx);
4732 cli_close(cli, fnum);
4733 for (i = 0; i < 10; i++) {
4734 fstring ea_name, ea_val;
4736 slprintf(ea_name, sizeof(ea_name), "EA_%d", i+10);
4737 memset(ea_val, (char)i+1, i+1);
4738 if (!cli_set_ea_path(cli, fname, ea_name, ea_val, i+1)) {
4739 printf("ea_set of name %s failed - %s\n", ea_name, cli_errstr(cli));
4740 talloc_destroy(mem_ctx);
4745 if (!cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list)) {
4746 printf("ea_get list failed - %s\n", cli_errstr(cli));
4750 printf("num_eas = %d\n", (int)num_eas);
4752 if (num_eas != 20) {
4753 printf("Should be 20 EA's stored... failing.\n");
4757 for (i = 0; i < num_eas; i++) {
4758 printf("%d: ea_name = %s. Val = ", i, ea_list[i].name);
4759 dump_data(0, ea_list[i].value.data,
4760 ea_list[i].value.length);
4763 /* Setting EA's to zero length deletes them. Test this */
4764 printf("Now deleting all EA's - case indepenent....\n");
4767 cli_set_ea_path(cli, fname, "", "", 0);
4769 for (i = 0; i < 20; i++) {
4771 slprintf(ea_name, sizeof(ea_name), "ea_%d", i);
4772 if (!cli_set_ea_path(cli, fname, ea_name, "", 0)) {
4773 printf("ea_set of name %s failed - %s\n", ea_name, cli_errstr(cli));
4774 talloc_destroy(mem_ctx);
4780 if (!cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list)) {
4781 printf("ea_get list failed - %s\n", cli_errstr(cli));
4785 printf("num_eas = %d\n", (int)num_eas);
4786 for (i = 0; i < num_eas; i++) {
4787 printf("%d: ea_name = %s. Val = ", i, ea_list[i].name);
4788 dump_data(0, ea_list[i].value.data,
4789 ea_list[i].value.length);
4793 printf("deleting EA's failed.\n");
4797 /* Try and delete a non existant EA. */
4798 if (!cli_set_ea_path(cli, fname, "foo", "", 0)) {
4799 printf("deleting non-existant EA 'foo' should succeed. %s\n", cli_errstr(cli));
4803 talloc_destroy(mem_ctx);
4804 if (!torture_close_connection(cli)) {
4811 static bool run_dirtest1(int dummy)
4814 static struct cli_state *cli;
4817 bool correct = True;
4819 printf("starting directory test\n");
4821 if (!torture_open_connection(&cli, 0)) {
4825 cli_sockopt(cli, sockops);
4827 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
4828 cli_list(cli, "\\LISTDIR\\*", aDIR, del_fn, cli);
4829 cli_rmdir(cli, "\\LISTDIR");
4830 cli_mkdir(cli, "\\LISTDIR");
4832 /* Create 1000 files and 1000 directories. */
4833 for (i=0;i<1000;i++) {
4835 slprintf(fname, sizeof(fname), "\\LISTDIR\\f%d", i);
4836 if (!NT_STATUS_IS_OK(cli_ntcreate(cli, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
4837 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum))) {
4838 fprintf(stderr,"Failed to open %s\n", fname);
4841 cli_close(cli, fnum);
4843 for (i=0;i<1000;i++) {
4845 slprintf(fname, sizeof(fname), "\\LISTDIR\\d%d", i);
4846 if (!NT_STATUS_IS_OK(cli_mkdir(cli, fname))) {
4847 fprintf(stderr,"Failed to open %s\n", fname);
4852 /* Now ensure that doing an old list sees both files and directories. */
4853 num_seen = cli_list_old(cli, "\\LISTDIR\\*", aDIR, list_fn, NULL);
4854 printf("num_seen = %d\n", num_seen );
4855 /* We should see 100 files + 1000 directories + . and .. */
4856 if (num_seen != 2002)
4859 /* Ensure if we have the "must have" bits we only see the
4862 num_seen = cli_list_old(cli, "\\LISTDIR\\*", (aDIR<<8)|aDIR, list_fn, NULL);
4863 printf("num_seen = %d\n", num_seen );
4864 if (num_seen != 1002)
4867 num_seen = cli_list_old(cli, "\\LISTDIR\\*", (aARCH<<8)|aDIR, list_fn, NULL);
4868 printf("num_seen = %d\n", num_seen );
4869 if (num_seen != 1000)
4872 /* Delete everything. */
4873 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
4874 cli_list(cli, "\\LISTDIR\\*", aDIR, del_fn, cli);
4875 cli_rmdir(cli, "\\LISTDIR");
4878 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
4879 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
4880 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
4883 if (!torture_close_connection(cli)) {
4887 printf("finished dirtest1\n");
4892 static bool run_error_map_extract(int dummy) {
4894 static struct cli_state *c_dos;
4895 static struct cli_state *c_nt;
4900 uint32 flgs2, errnum;
4907 /* NT-Error connection */
4909 if (!(c_nt = open_nbt_connection())) {
4913 c_nt->use_spnego = False;
4915 status = cli_negprot(c_nt);
4917 if (!NT_STATUS_IS_OK(status)) {
4918 printf("%s rejected the NT-error negprot (%s)\n", host,
4924 if (!NT_STATUS_IS_OK(cli_session_setup(c_nt, "", "", 0, "", 0,
4926 printf("%s rejected the NT-error initial session setup (%s)\n",host, cli_errstr(c_nt));
4930 /* DOS-Error connection */
4932 if (!(c_dos = open_nbt_connection())) {
4936 c_dos->use_spnego = False;
4937 c_dos->force_dos_errors = True;
4939 status = cli_negprot(c_dos);
4940 if (!NT_STATUS_IS_OK(status)) {
4941 printf("%s rejected the DOS-error negprot (%s)\n", host,
4943 cli_shutdown(c_dos);
4947 if (!NT_STATUS_IS_OK(cli_session_setup(c_dos, "", "", 0, "", 0,
4949 printf("%s rejected the DOS-error initial session setup (%s)\n",host, cli_errstr(c_dos));
4953 for (error=(0xc0000000 | 0x1); error < (0xc0000000| 0xFFF); error++) {
4954 fstr_sprintf(user, "%X", error);
4956 if (NT_STATUS_IS_OK(cli_session_setup(c_nt, user,
4957 password, strlen(password),
4958 password, strlen(password),
4960 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
4963 flgs2 = SVAL(c_nt->inbuf,smb_flg2);
4965 /* Case #1: 32-bit NT errors */
4966 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
4967 nt_status = NT_STATUS(IVAL(c_nt->inbuf,smb_rcls));
4969 printf("/** Dos error on NT connection! (%s) */\n",
4971 nt_status = NT_STATUS(0xc0000000);
4974 if (NT_STATUS_IS_OK(cli_session_setup(c_dos, user,
4975 password, strlen(password),
4976 password, strlen(password),
4978 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
4980 flgs2 = SVAL(c_dos->inbuf,smb_flg2), errnum;
4982 /* Case #1: 32-bit NT errors */
4983 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
4984 printf("/** NT error on DOS connection! (%s) */\n",
4986 errnum = errclass = 0;
4988 cli_dos_error(c_dos, &errclass, &errnum);
4991 if (NT_STATUS_V(nt_status) != error) {
4992 printf("/*\t{ This NT error code was 'sqashed'\n\t from %s to %s \n\t during the session setup }\n*/\n",
4993 get_nt_error_c_code(NT_STATUS(error)),
4994 get_nt_error_c_code(nt_status));
4997 printf("\t{%s,\t%s,\t%s},\n",
4998 smb_dos_err_class(errclass),
4999 smb_dos_err_name(errclass, errnum),
5000 get_nt_error_c_code(NT_STATUS(error)));
5005 static bool run_sesssetup_bench(int dummy)
5007 static struct cli_state *c;
5008 const char *fname = "\\file.dat";
5013 if (!torture_open_connection(&c, 0)) {
5017 if (!NT_STATUS_IS_OK(cli_ntcreate(
5018 c, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
5019 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
5020 FILE_DELETE_ON_CLOSE, 0, &fnum))) {
5021 d_printf("open %s failed: %s\n", fname, cli_errstr(c));
5025 for (i=0; i<torture_numops; i++) {
5026 status = cli_session_setup(
5028 password, strlen(password),
5029 password, strlen(password),
5031 if (!NT_STATUS_IS_OK(status)) {
5032 d_printf("(%s) cli_session_setup failed: %s\n",
5033 __location__, nt_errstr(status));
5037 d_printf("\r%d ", (int)c->vuid);
5039 if (!cli_ulogoff(c)) {
5040 d_printf("(%s) cli_ulogoff failed: %s\n",
5041 __location__, cli_errstr(c));
5050 static bool subst_test(const char *str, const char *user, const char *domain,
5051 uid_t uid, gid_t gid, const char *expected)
5056 subst = talloc_sub_specified(talloc_tos(), str, user, domain, uid, gid);
5058 if (strcmp(subst, expected) != 0) {
5059 printf("sub_specified(%s, %s, %s, %d, %d) returned [%s], expected "
5060 "[%s]\n", str, user, domain, (int)uid, (int)gid, subst,
5069 static void chain1_open_completion(struct tevent_req *req)
5073 status = cli_open_recv(req, &fnum);
5076 d_printf("cli_open_recv returned %s: %d\n",
5078 NT_STATUS_IS_OK(status) ? fnum : -1);
5081 static void chain1_write_completion(struct tevent_req *req)
5085 status = cli_write_andx_recv(req, &written);
5088 d_printf("cli_write_andx_recv returned %s: %d\n",
5090 NT_STATUS_IS_OK(status) ? (int)written : -1);
5093 static void chain1_close_completion(struct tevent_req *req)
5096 bool *done = (bool *)tevent_req_callback_data_void(req);
5098 status = cli_close_recv(req);
5103 d_printf("cli_close returned %s\n", nt_errstr(status));
5106 static bool run_chain1(int dummy)
5108 struct cli_state *cli1;
5109 struct event_context *evt = event_context_init(NULL);
5110 struct tevent_req *reqs[3], *smbreqs[3];
5112 const char *str = "foobar";
5115 printf("starting chain1 test\n");
5116 if (!torture_open_connection(&cli1, 0)) {
5120 cli_sockopt(cli1, sockops);
5122 reqs[0] = cli_open_create(talloc_tos(), evt, cli1, "\\test",
5123 O_CREAT|O_RDWR, 0, &smbreqs[0]);
5124 if (reqs[0] == NULL) return false;
5125 tevent_req_set_callback(reqs[0], chain1_open_completion, NULL);
5128 reqs[1] = cli_write_andx_create(talloc_tos(), evt, cli1, 0, 0,
5129 (uint8_t *)str, 0, strlen(str)+1,
5130 smbreqs, 1, &smbreqs[1]);
5131 if (reqs[1] == NULL) return false;
5132 tevent_req_set_callback(reqs[1], chain1_write_completion, NULL);
5134 reqs[2] = cli_close_create(talloc_tos(), evt, cli1, 0, &smbreqs[2]);
5135 if (reqs[2] == NULL) return false;
5136 tevent_req_set_callback(reqs[2], chain1_close_completion, &done);
5138 status = cli_smb_chain_send(smbreqs, ARRAY_SIZE(smbreqs));
5139 if (!NT_STATUS_IS_OK(status)) {
5144 event_loop_once(evt);
5147 torture_close_connection(cli1);
5151 static void chain2_sesssetup_completion(struct tevent_req *req)
5154 status = cli_session_setup_guest_recv(req);
5155 d_printf("sesssetup returned %s\n", nt_errstr(status));
5158 static void chain2_tcon_completion(struct tevent_req *req)
5160 bool *done = (bool *)tevent_req_callback_data_void(req);
5162 status = cli_tcon_andx_recv(req);
5163 d_printf("tcon_and_x returned %s\n", nt_errstr(status));
5167 static bool run_chain2(int dummy)
5169 struct cli_state *cli1;
5170 struct event_context *evt = event_context_init(NULL);
5171 struct tevent_req *reqs[2], *smbreqs[2];
5175 printf("starting chain2 test\n");
5176 if (!torture_open_connection(&cli1, 0)) {
5180 cli_sockopt(cli1, sockops);
5182 reqs[0] = cli_session_setup_guest_create(talloc_tos(), evt, cli1,
5184 if (reqs[0] == NULL) return false;
5185 tevent_req_set_callback(reqs[0], chain2_sesssetup_completion, NULL);
5187 reqs[1] = cli_tcon_andx_create(talloc_tos(), evt, cli1, "IPC$",
5188 "?????", NULL, 0, &smbreqs[1]);
5189 if (reqs[1] == NULL) return false;
5190 tevent_req_set_callback(reqs[1], chain2_tcon_completion, &done);
5192 status = cli_smb_chain_send(smbreqs, ARRAY_SIZE(smbreqs));
5193 if (!NT_STATUS_IS_OK(status)) {
5198 event_loop_once(evt);
5201 torture_close_connection(cli1);
5205 static bool run_mangle1(int dummy)
5207 struct cli_state *cli;
5208 const char *fname = "this_is_a_long_fname_to_be_mangled.txt";
5212 time_t change_time, access_time, write_time;
5216 printf("starting mangle1 test\n");
5217 if (!torture_open_connection(&cli, 0)) {
5221 cli_sockopt(cli, sockops);
5223 if (!NT_STATUS_IS_OK(cli_ntcreate(
5224 cli, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
5225 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0, 0, &fnum))) {
5226 d_printf("open %s failed: %s\n", fname, cli_errstr(cli));
5229 cli_close(cli, fnum);
5231 status = cli_qpathinfo_alt_name(cli, fname, alt_name);
5232 if (!NT_STATUS_IS_OK(status)) {
5233 d_printf("cli_qpathinfo_alt_name failed: %s\n",
5237 d_printf("alt_name: %s\n", alt_name);
5239 if (!NT_STATUS_IS_OK(cli_open(cli, alt_name, O_RDONLY, DENY_NONE, &fnum))) {
5240 d_printf("cli_open(%s) failed: %s\n", alt_name,
5244 cli_close(cli, fnum);
5246 if (!cli_qpathinfo(cli, alt_name, &change_time, &access_time,
5247 &write_time, &size, &mode)) {
5248 d_printf("cli_qpathinfo(%s) failed: %s\n", alt_name,
5256 static size_t null_source(uint8_t *buf, size_t n, void *priv)
5258 size_t *to_pull = (size_t *)priv;
5259 size_t thistime = *to_pull;
5261 thistime = MIN(thistime, n);
5262 if (thistime == 0) {
5266 memset(buf, 0, thistime);
5267 *to_pull -= thistime;
5271 static bool run_windows_write(int dummy)
5273 struct cli_state *cli1;
5277 const char *fname = "\\writetest.txt";
5281 printf("starting windows_write test\n");
5282 if (!torture_open_connection(&cli1, 0)) {
5286 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum))) {
5287 printf("open failed (%s)\n", cli_errstr(cli1));
5291 cli_sockopt(cli1, sockops);
5295 for (i=0; i<torture_numops; i++) {
5297 off_t start = i * torture_blocksize;
5299 size_t to_pull = torture_blocksize - 1;
5301 if (cli_write(cli1, fnum, 0, &c,
5302 start + torture_blocksize - 1, 1) != 1) {
5303 printf("cli_write failed: %s\n", cli_errstr(cli1));
5307 status = cli_push(cli1, fnum, 0, i * torture_blocksize, torture_blocksize,
5308 null_source, &to_pull);
5309 if (!NT_STATUS_IS_OK(status)) {
5310 printf("cli_push returned: %s\n", nt_errstr(status));
5315 seconds = end_timer();
5316 kbytes = (double)torture_blocksize * torture_numops;
5319 printf("Wrote %d kbytes in %.2f seconds: %d kb/sec\n", (int)kbytes,
5320 (double)seconds, (int)(kbytes/seconds));
5324 cli_close(cli1, fnum);
5325 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
5326 torture_close_connection(cli1);
5330 static bool run_cli_echo(int dummy)
5332 struct cli_state *cli;
5335 printf("starting cli_echo test\n");
5336 if (!torture_open_connection(&cli, 0)) {
5339 cli_sockopt(cli, sockops);
5341 status = cli_echo(cli, 5, data_blob_const("hello", 5));
5343 d_printf("cli_echo returned %s\n", nt_errstr(status));
5345 torture_close_connection(cli);
5346 return NT_STATUS_IS_OK(status);
5349 static bool run_uid_regression_test(int dummy)
5351 static struct cli_state *cli;
5354 bool correct = True;
5356 printf("starting uid regression test\n");
5358 if (!torture_open_connection(&cli, 0)) {
5362 cli_sockopt(cli, sockops);
5364 /* Ok - now save then logoff our current user. */
5365 old_vuid = cli->vuid;
5367 if (!cli_ulogoff(cli)) {
5368 d_printf("(%s) cli_ulogoff failed: %s\n",
5369 __location__, cli_errstr(cli));
5374 cli->vuid = old_vuid;
5376 /* Try an operation. */
5377 if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\uid_reg_test"))) {
5378 /* We expect bad uid. */
5379 if (!check_error(__LINE__, cli, ERRSRV, ERRbaduid,
5380 NT_STATUS_NO_SUCH_USER)) {
5385 old_cnum = cli->cnum;
5387 /* Now try a SMBtdis with the invald vuid set to zero. */
5390 /* This should succeed. */
5391 if (cli_tdis(cli)) {
5392 printf("First tdis with invalid vuid should succeed.\n");
5394 printf("First tdis failed (%s)\n", cli_errstr(cli));
5397 cli->vuid = old_vuid;
5398 cli->cnum = old_cnum;
5400 /* This should fail. */
5401 if (cli_tdis(cli)) {
5402 printf("Second tdis with invalid vuid should fail - succeeded instead !.\n");
5404 /* Should be bad tid. */
5405 if (!check_error(__LINE__, cli, ERRSRV, ERRinvnid,
5406 NT_STATUS_NETWORK_NAME_DELETED)) {
5411 cli_rmdir(cli, "\\uid_reg_test");
5420 static const char *illegal_chars = "*\\/?<>|\":";
5421 static char force_shortname_chars[] = " +,.[];=\177";
5423 static void shortname_del_fn(const char *mnt, file_info *finfo, const char *mask, void *state)
5425 struct cli_state *pcli = (struct cli_state *)state;
5427 slprintf(fname, sizeof(fname), "\\shortname\\%s", finfo->name);
5429 if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
5432 if (finfo->mode & aDIR) {
5433 if (!NT_STATUS_IS_OK(cli_rmdir(pcli, fname)))
5434 printf("del_fn: failed to rmdir %s\n,", fname );
5436 if (!NT_STATUS_IS_OK(cli_unlink(pcli, fname, aSYSTEM | aHIDDEN)))
5437 printf("del_fn: failed to unlink %s\n,", fname );
5446 static void shortname_list_fn(const char *mnt, file_info *finfo, const char *name, void *state)
5448 struct sn_state *s = (struct sn_state *)state;
5452 printf("shortname list: i = %d, name = |%s|, shortname = |%s|\n",
5453 i, finfo->name, finfo->short_name);
5456 if (strchr(force_shortname_chars, i)) {
5457 if (!finfo->short_name[0]) {
5458 /* Shortname not created when it should be. */
5459 d_printf("(%s) ERROR: Shortname was not created for file %s containing %d\n",
5460 __location__, finfo->name, i);
5463 } else if (finfo->short_name[0]){
5464 /* Shortname created when it should not be. */
5465 d_printf("(%s) ERROR: Shortname %s was created for file %s\n",
5466 __location__, finfo->short_name, finfo->name);
5471 static bool run_shortname_test(int dummy)
5473 static struct cli_state *cli;
5474 bool correct = True;
5479 printf("starting shortname test\n");
5481 if (!torture_open_connection(&cli, 0)) {
5485 cli_sockopt(cli, sockops);
5487 cli_list(cli, "\\shortname\\*", 0, shortname_del_fn, cli);
5488 cli_list(cli, "\\shortname\\*", aDIR, shortname_del_fn, cli);
5489 cli_rmdir(cli, "\\shortname");
5491 if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\shortname"))) {
5492 d_printf("(%s) cli_mkdir of \\shortname failed: %s\n",
5493 __location__, cli_errstr(cli));
5498 strlcpy(fname, "\\shortname\\", sizeof(fname));
5499 strlcat(fname, "test .txt", sizeof(fname));
5503 for (i = 32; i < 128; i++) {
5505 uint16_t fnum = (uint16_t)-1;
5509 if (strchr(illegal_chars, i)) {
5514 status = cli_ntcreate(cli, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
5515 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum);
5516 if (!NT_STATUS_IS_OK(status)) {
5517 d_printf("(%s) cli_nt_create of %s failed: %s\n",
5518 __location__, fname, cli_errstr(cli));
5522 cli_close(cli, fnum);
5523 if (cli_list(cli, "\\shortname\\test*.*", 0, shortname_list_fn, &s) != 1) {
5524 d_printf("(%s) failed to list %s: %s\n",
5525 __location__, fname, cli_errstr(cli));
5529 if (!NT_STATUS_IS_OK(cli_unlink(cli, fname, aSYSTEM | aHIDDEN))) {
5530 d_printf("(%s) failed to delete %s: %s\n",
5531 __location__, fname, cli_errstr(cli));
5544 cli_list(cli, "\\shortname\\*", 0, shortname_del_fn, cli);
5545 cli_list(cli, "\\shortname\\*", aDIR, shortname_del_fn, cli);
5546 cli_rmdir(cli, "\\shortname");
5547 torture_close_connection(cli);
5551 static bool run_local_substitute(int dummy)
5555 ok &= subst_test("%U", "bla", "", -1, -1, "bla");
5556 ok &= subst_test("%u%U", "bla", "", -1, -1, "blabla");
5557 ok &= subst_test("%g", "", "", -1, -1, "NO_GROUP");
5558 ok &= subst_test("%G", "", "", -1, -1, "NO_GROUP");
5559 ok &= subst_test("%g", "", "", -1, 0, gidtoname(0));
5560 ok &= subst_test("%G", "", "", -1, 0, gidtoname(0));
5561 ok &= subst_test("%D%u", "u", "dom", -1, 0, "domu");
5562 ok &= subst_test("%i %I", "", "", -1, -1, "0.0.0.0 0.0.0.0");
5564 /* Different captialization rules in sub_basic... */
5566 ok &= (strcmp(talloc_sub_basic(talloc_tos(), "BLA", "dom", "%U%D"),
5572 static bool run_local_gencache(int dummy)
5578 if (!gencache_init()) {
5579 d_printf("%s: gencache_init() failed\n", __location__);
5583 if (!gencache_set("foo", "bar", time(NULL) + 1000)) {
5584 d_printf("%s: gencache_set() failed\n", __location__);
5588 if (!gencache_get("foo", &val, &tm)) {
5589 d_printf("%s: gencache_get() failed\n", __location__);
5593 if (strcmp(val, "bar") != 0) {
5594 d_printf("%s: gencache_get() returned %s, expected %s\n",
5595 __location__, val, "bar");
5602 if (!gencache_del("foo")) {
5603 d_printf("%s: gencache_del() failed\n", __location__);
5606 if (gencache_del("foo")) {
5607 d_printf("%s: second gencache_del() succeeded\n",
5612 if (gencache_get("foo", &val, &tm)) {
5613 d_printf("%s: gencache_get() on deleted entry "
5614 "succeeded\n", __location__);
5618 blob = data_blob_string_const_null("bar");
5621 if (!gencache_set_data_blob("foo", &blob, tm)) {
5622 d_printf("%s: gencache_set_data_blob() failed\n", __location__);
5626 data_blob_free(&blob);
5628 if (!gencache_get_data_blob("foo", &blob, NULL)) {
5629 d_printf("%s: gencache_get_data_blob() failed\n", __location__);
5633 if (strcmp((const char *)blob.data, "bar") != 0) {
5634 d_printf("%s: gencache_get_data_blob() returned %s, expected %s\n",
5635 __location__, (const char *)blob.data, "bar");
5636 data_blob_free(&blob);
5640 data_blob_free(&blob);
5642 if (!gencache_del("foo")) {
5643 d_printf("%s: gencache_del() failed\n", __location__);
5646 if (gencache_del("foo")) {
5647 d_printf("%s: second gencache_del() succeeded\n",
5652 if (gencache_get_data_blob("foo", &blob, NULL)) {
5653 d_printf("%s: gencache_get_data_blob() on deleted entry "
5654 "succeeded\n", __location__);
5658 if (!gencache_shutdown()) {
5659 d_printf("%s: gencache_shutdown() failed\n", __location__);
5663 if (gencache_shutdown()) {
5664 d_printf("%s: second gencache_shutdown() succeeded\n",
5672 static bool rbt_testval(struct db_context *db, const char *key,
5675 struct db_record *rec;
5676 TDB_DATA data = string_tdb_data(value);
5680 rec = db->fetch_locked(db, db, string_tdb_data(key));
5682 d_fprintf(stderr, "fetch_locked failed\n");
5685 status = rec->store(rec, data, 0);
5686 if (!NT_STATUS_IS_OK(status)) {
5687 d_fprintf(stderr, "store failed: %s\n", nt_errstr(status));
5692 rec = db->fetch_locked(db, db, string_tdb_data(key));
5694 d_fprintf(stderr, "second fetch_locked failed\n");
5697 if ((rec->value.dsize != data.dsize)
5698 || (memcmp(rec->value.dptr, data.dptr, data.dsize) != 0)) {
5699 d_fprintf(stderr, "Got wrong data back\n");
5709 static bool run_local_rbtree(int dummy)
5711 struct db_context *db;
5715 db = db_open_rbt(NULL);
5718 d_fprintf(stderr, "db_open_rbt failed\n");
5722 for (i=0; i<1000; i++) {
5725 if (asprintf(&key, "key%ld", random()) == -1) {
5728 if (asprintf(&value, "value%ld", random()) == -1) {
5733 if (!rbt_testval(db, key, value)) {
5740 if (asprintf(&value, "value%ld", random()) == -1) {
5745 if (!rbt_testval(db, key, value)) {
5762 static bool test_stream_name(const char *fname, const char *expected_base,
5763 const char *expected_stream,
5764 NTSTATUS expected_status)
5768 char *stream = NULL;
5770 status = split_ntfs_stream_name(talloc_tos(), fname, &base, &stream);
5771 if (!NT_STATUS_EQUAL(status, expected_status)) {
5775 if (!NT_STATUS_IS_OK(status)) {
5779 if (base == NULL) goto error;
5781 if (strcmp(expected_base, base) != 0) goto error;
5783 if ((expected_stream != NULL) && (stream == NULL)) goto error;
5784 if ((expected_stream == NULL) && (stream != NULL)) goto error;
5786 if ((stream != NULL) && (strcmp(expected_stream, stream) != 0))
5790 TALLOC_FREE(stream);
5794 d_fprintf(stderr, "test_stream(%s, %s, %s, %s)\n",
5795 fname, expected_base ? expected_base : "<NULL>",
5796 expected_stream ? expected_stream : "<NULL>",
5797 nt_errstr(expected_status));
5798 d_fprintf(stderr, "-> base=%s, stream=%s, status=%s\n",
5799 base ? base : "<NULL>", stream ? stream : "<NULL>",
5802 TALLOC_FREE(stream);
5806 static bool run_local_stream_name(int dummy)
5810 ret &= test_stream_name(
5811 "bla", "bla", NULL, NT_STATUS_OK);
5812 ret &= test_stream_name(
5813 "bla::$DATA", "bla", NULL, NT_STATUS_OK);
5814 ret &= test_stream_name(
5815 "bla:blub:", "bla", NULL, NT_STATUS_OBJECT_NAME_INVALID);
5816 ret &= test_stream_name(
5817 "bla::", NULL, NULL, NT_STATUS_OBJECT_NAME_INVALID);
5818 ret &= test_stream_name(
5819 "bla::123", "bla", NULL, NT_STATUS_OBJECT_NAME_INVALID);
5820 ret &= test_stream_name(
5821 "bla:$DATA", "bla", "$DATA:$DATA", NT_STATUS_OK);
5822 ret &= test_stream_name(
5823 "bla:x:$DATA", "bla", "x:$DATA", NT_STATUS_OK);
5824 ret &= test_stream_name(
5825 "bla:x", "bla", "x:$DATA", NT_STATUS_OK);
5830 static bool data_blob_equal(DATA_BLOB a, DATA_BLOB b)
5832 if (a.length != b.length) {
5833 printf("a.length=%d != b.length=%d\n",
5834 (int)a.length, (int)b.length);
5837 if (memcmp(a.data, b.data, a.length) != 0) {
5838 printf("a.data and b.data differ\n");
5844 static bool run_local_memcache(int dummy)
5846 struct memcache *cache;
5848 DATA_BLOB d1, d2, d3;
5849 DATA_BLOB v1, v2, v3;
5851 TALLOC_CTX *mem_ctx;
5853 size_t size1, size2;
5856 cache = memcache_init(NULL, 100);
5858 if (cache == NULL) {
5859 printf("memcache_init failed\n");
5863 d1 = data_blob_const("d1", 2);
5864 d2 = data_blob_const("d2", 2);
5865 d3 = data_blob_const("d3", 2);
5867 k1 = data_blob_const("d1", 2);
5868 k2 = data_blob_const("d2", 2);
5870 memcache_add(cache, STAT_CACHE, k1, d1);
5871 memcache_add(cache, GETWD_CACHE, k2, d2);
5873 if (!memcache_lookup(cache, STAT_CACHE, k1, &v1)) {
5874 printf("could not find k1\n");
5877 if (!data_blob_equal(d1, v1)) {
5881 if (!memcache_lookup(cache, GETWD_CACHE, k2, &v2)) {
5882 printf("could not find k2\n");
5885 if (!data_blob_equal(d2, v2)) {
5889 memcache_add(cache, STAT_CACHE, k1, d3);
5891 if (!memcache_lookup(cache, STAT_CACHE, k1, &v3)) {
5892 printf("could not find replaced k1\n");
5895 if (!data_blob_equal(d3, v3)) {
5899 memcache_add(cache, GETWD_CACHE, k1, d1);
5901 if (memcache_lookup(cache, GETWD_CACHE, k2, &v2)) {
5902 printf("Did find k2, should have been purged\n");
5908 cache = memcache_init(NULL, 0);
5910 mem_ctx = talloc_init("foo");
5912 str1 = talloc_strdup(mem_ctx, "string1");
5913 str2 = talloc_strdup(mem_ctx, "string2");
5915 memcache_add_talloc(cache, SINGLETON_CACHE_TALLOC,
5916 data_blob_string_const("torture"), &str1);
5917 size1 = talloc_total_size(cache);
5919 memcache_add_talloc(cache, SINGLETON_CACHE_TALLOC,
5920 data_blob_string_const("torture"), &str2);
5921 size2 = talloc_total_size(cache);
5923 printf("size1=%d, size2=%d\n", (int)size1, (int)size2);
5925 if (size2 > size1) {
5926 printf("memcache leaks memory!\n");
5936 static void wbclient_done(struct tevent_req *req)
5939 struct winbindd_response *wb_resp;
5940 int *i = (int *)tevent_req_callback_data_void(req);
5942 wbc_err = wb_trans_recv(req, req, &wb_resp);
5945 d_printf("wb_trans_recv %d returned %s\n", *i, wbcErrorString(wbc_err));
5948 static bool run_local_wbclient(int dummy)
5950 struct event_context *ev;
5951 struct wb_context **wb_ctx;
5952 struct winbindd_request wb_req;
5953 bool result = false;
5956 BlockSignals(True, SIGPIPE);
5958 ev = tevent_context_init_byname(talloc_tos(), "epoll");
5963 wb_ctx = TALLOC_ARRAY(ev, struct wb_context *, nprocs);
5964 if (wb_ctx == NULL) {
5968 ZERO_STRUCT(wb_req);
5969 wb_req.cmd = WINBINDD_PING;
5971 d_printf("nprocs=%d, numops=%d\n", (int)nprocs, (int)torture_numops);
5973 for (i=0; i<nprocs; i++) {
5974 wb_ctx[i] = wb_context_init(ev);
5975 if (wb_ctx[i] == NULL) {
5978 for (j=0; j<torture_numops; j++) {
5979 struct tevent_req *req;
5980 req = wb_trans_send(ev, ev, wb_ctx[i],
5981 (j % 2) == 0, &wb_req);
5985 tevent_req_set_callback(req, wbclient_done, &i);
5991 while (i < nprocs * torture_numops) {
5992 event_loop_once(ev);
6001 static void getaddrinfo_finished(struct tevent_req *req)
6003 char *name = (char *)tevent_req_callback_data_void(req);
6004 struct addrinfo *ainfo;
6007 res = getaddrinfo_recv(req, &ainfo);
6009 d_printf("gai(%s) returned %s\n", name, gai_strerror(res));
6012 d_printf("gai(%s) succeeded\n", name);
6013 freeaddrinfo(ainfo);
6016 static bool run_getaddrinfo_send(int dummy)
6018 TALLOC_CTX *frame = talloc_stackframe();
6019 struct fncall_context *ctx;
6020 struct tevent_context *ev;
6021 bool result = false;
6022 const char *names[4] = { "www.samba.org", "notfound.samba.org",
6023 "www.slashdot.org", "heise.de" };
6024 struct tevent_req *reqs[4];
6027 ev = event_context_init(frame);
6032 ctx = fncall_context_init(frame, 4);
6034 for (i=0; i<ARRAY_SIZE(names); i++) {
6035 reqs[i] = getaddrinfo_send(frame, ev, ctx, names[i], NULL,
6037 if (reqs[i] == NULL) {
6040 tevent_req_set_callback(reqs[i], getaddrinfo_finished,
6044 for (i=0; i<ARRAY_SIZE(reqs); i++) {
6045 tevent_loop_once(ev);
6055 static double create_procs(bool (*fn)(int), bool *result)
6058 volatile pid_t *child_status;
6059 volatile bool *child_status_out;
6065 child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*nprocs);
6066 if (!child_status) {
6067 printf("Failed to setup shared memory\n");
6071 child_status_out = (volatile bool *)shm_setup(sizeof(bool)*nprocs);
6072 if (!child_status_out) {
6073 printf("Failed to setup result status shared memory\n");
6077 for (i = 0; i < nprocs; i++) {
6078 child_status[i] = 0;
6079 child_status_out[i] = True;
6084 for (i=0;i<nprocs;i++) {
6087 pid_t mypid = getpid();
6088 sys_srandom(((int)mypid) ^ ((int)time(NULL)));
6090 slprintf(myname,sizeof(myname),"CLIENT%d", i);
6093 if (torture_open_connection(¤t_cli, i)) break;
6095 printf("pid %d failed to start\n", (int)getpid());
6101 child_status[i] = getpid();
6103 while (child_status[i] && end_timer() < 5) smb_msleep(2);
6105 child_status_out[i] = fn(i);
6112 for (i=0;i<nprocs;i++) {
6113 if (child_status[i]) synccount++;
6115 if (synccount == nprocs) break;
6117 } while (end_timer() < 30);
6119 if (synccount != nprocs) {
6120 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs, synccount);
6125 /* start the client load */
6128 for (i=0;i<nprocs;i++) {
6129 child_status[i] = 0;
6132 printf("%d clients started\n", nprocs);
6134 for (i=0;i<nprocs;i++) {
6135 while (waitpid(0, &status, 0) == -1 && errno == EINTR) /* noop */ ;
6140 for (i=0;i<nprocs;i++) {
6141 if (!child_status_out[i]) {
6148 #define FLAG_MULTIPROC 1
6155 {"FDPASS", run_fdpasstest, 0},
6156 {"LOCK1", run_locktest1, 0},
6157 {"LOCK2", run_locktest2, 0},
6158 {"LOCK3", run_locktest3, 0},
6159 {"LOCK4", run_locktest4, 0},
6160 {"LOCK5", run_locktest5, 0},
6161 {"LOCK6", run_locktest6, 0},
6162 {"LOCK7", run_locktest7, 0},
6163 {"LOCK8", run_locktest8, 0},
6164 {"UNLINK", run_unlinktest, 0},
6165 {"BROWSE", run_browsetest, 0},
6166 {"ATTR", run_attrtest, 0},
6167 {"TRANS2", run_trans2test, 0},
6168 {"MAXFID", run_maxfidtest, FLAG_MULTIPROC},
6169 {"TORTURE",run_torture, FLAG_MULTIPROC},
6170 {"RANDOMIPC", run_randomipc, 0},
6171 {"NEGNOWAIT", run_negprot_nowait, 0},
6172 {"NBENCH", run_nbench, 0},
6173 {"OPLOCK1", run_oplock1, 0},
6174 {"OPLOCK2", run_oplock2, 0},
6175 {"OPLOCK3", run_oplock3, 0},
6176 {"DIR", run_dirtest, 0},
6177 {"DIR1", run_dirtest1, 0},
6178 {"DENY1", torture_denytest1, 0},
6179 {"DENY2", torture_denytest2, 0},
6180 {"TCON", run_tcon_test, 0},
6181 {"TCONDEV", run_tcon_devtype_test, 0},
6182 {"RW1", run_readwritetest, 0},
6183 {"RW2", run_readwritemulti, FLAG_MULTIPROC},
6184 {"RW3", run_readwritelarge, 0},
6185 {"OPEN", run_opentest, 0},
6186 {"POSIX", run_simple_posix_open_test, 0},
6187 { "UID-REGRESSION-TEST", run_uid_regression_test, 0},
6188 { "SHORTNAME-TEST", run_shortname_test, 0},
6190 {"OPENATTR", run_openattrtest, 0},
6192 {"XCOPY", run_xcopy, 0},
6193 {"RENAME", run_rename, 0},
6194 {"DELETE", run_deletetest, 0},
6195 {"PROPERTIES", run_properties, 0},
6196 {"MANGLE", torture_mangle, 0},
6197 {"MANGLE1", run_mangle1, 0},
6198 {"W2K", run_w2ktest, 0},
6199 {"TRANS2SCAN", torture_trans2_scan, 0},
6200 {"NTTRANSSCAN", torture_nttrans_scan, 0},
6201 {"UTABLE", torture_utable, 0},
6202 {"CASETABLE", torture_casetable, 0},
6203 {"ERRMAPEXTRACT", run_error_map_extract, 0},
6204 {"PIPE_NUMBER", run_pipe_number, 0},
6205 {"TCON2", run_tcon2_test, 0},
6206 {"IOCTL", torture_ioctl_test, 0},
6207 {"CHKPATH", torture_chkpath_test, 0},
6208 {"FDSESS", run_fdsesstest, 0},
6209 { "EATEST", run_eatest, 0},
6210 { "SESSSETUP_BENCH", run_sesssetup_bench, 0},
6211 { "CHAIN1", run_chain1, 0},
6212 { "CHAIN2", run_chain2, 0},
6213 { "WINDOWS-WRITE", run_windows_write, 0},
6214 { "CLI_ECHO", run_cli_echo, 0},
6215 { "GETADDRINFO", run_getaddrinfo_send, 0},
6216 { "LOCAL-SUBSTITUTE", run_local_substitute, 0},
6217 { "LOCAL-GENCACHE", run_local_gencache, 0},
6218 { "LOCAL-RBTREE", run_local_rbtree, 0},
6219 { "LOCAL-MEMCACHE", run_local_memcache, 0},
6220 { "LOCAL-STREAM-NAME", run_local_stream_name, 0},
6221 { "LOCAL-WBCLIENT", run_local_wbclient, 0},
6226 /****************************************************************************
6227 run a specified test or "ALL"
6228 ****************************************************************************/
6229 static bool run_test(const char *name)
6236 if (strequal(name,"ALL")) {
6237 for (i=0;torture_ops[i].name;i++) {
6238 run_test(torture_ops[i].name);
6243 for (i=0;torture_ops[i].name;i++) {
6244 fstr_sprintf(randomfname, "\\XX%x",
6245 (unsigned)random());
6247 if (strequal(name, torture_ops[i].name)) {
6249 printf("Running %s\n", name);
6250 if (torture_ops[i].flags & FLAG_MULTIPROC) {
6251 t = create_procs(torture_ops[i].fn, &result);
6254 printf("TEST %s FAILED!\n", name);
6258 if (!torture_ops[i].fn(0)) {
6260 printf("TEST %s FAILED!\n", name);
6264 printf("%s took %g secs\n\n", name, t);
6269 printf("Did not find a test named %s\n", name);
6277 static void usage(void)
6281 printf("WARNING samba4 test suite is much more complete nowadays.\n");
6282 printf("Please use samba4 torture.\n\n");
6284 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
6286 printf("\t-d debuglevel\n");
6287 printf("\t-U user%%pass\n");
6288 printf("\t-k use kerberos\n");
6289 printf("\t-N numprocs\n");
6290 printf("\t-n my_netbios_name\n");
6291 printf("\t-W workgroup\n");
6292 printf("\t-o num_operations\n");
6293 printf("\t-O socket_options\n");
6294 printf("\t-m maximum protocol\n");
6295 printf("\t-L use oplocks\n");
6296 printf("\t-c CLIENT.TXT specify client load file for NBENCH\n");
6297 printf("\t-A showall\n");
6298 printf("\t-p port\n");
6299 printf("\t-s seed\n");
6300 printf("\t-b unclist_filename specify multiple shares for multiple connections\n");
6303 printf("tests are:");
6304 for (i=0;torture_ops[i].name;i++) {
6305 printf(" %s", torture_ops[i].name);
6309 printf("default test is ALL\n");
6314 /****************************************************************************
6316 ****************************************************************************/
6317 int main(int argc,char *argv[])
6323 bool correct = True;
6324 TALLOC_CTX *frame = talloc_stackframe();
6325 int seed = time(NULL);
6329 #ifdef HAVE_SETBUFFER
6330 setbuffer(stdout, NULL, 0);
6335 if (is_default_dyn_CONFIGFILE()) {
6336 if(getenv("SMB_CONF_PATH")) {
6337 set_dyn_CONFIGFILE(getenv("SMB_CONF_PATH"));
6340 lp_load(get_dyn_CONFIGFILE(),True,False,False,True);
6347 for(p = argv[1]; *p; p++)
6351 if (strncmp(argv[1], "//", 2)) {
6355 fstrcpy(host, &argv[1][2]);
6356 p = strchr_m(&host[2],'/');
6361 fstrcpy(share, p+1);
6363 fstrcpy(myname, get_myname(talloc_tos()));
6365 fprintf(stderr, "Failed to get my hostname.\n");
6369 if (*username == 0 && getenv("LOGNAME")) {
6370 fstrcpy(username,getenv("LOGNAME"));
6376 fstrcpy(workgroup, lp_workgroup());
6378 while ((opt = getopt(argc, argv, "p:hW:U:n:N:O:o:m:Ld:Aec:ks:b:B:")) != EOF) {
6381 port_to_use = atoi(optarg);
6384 seed = atoi(optarg);
6387 fstrcpy(workgroup,optarg);
6390 max_protocol = interpret_protocol(optarg, max_protocol);
6393 nprocs = atoi(optarg);
6396 torture_numops = atoi(optarg);
6399 DEBUGLEVEL = atoi(optarg);
6408 torture_showall = True;
6411 fstrcpy(myname, optarg);
6414 client_txt = optarg;
6421 use_kerberos = True;
6423 d_printf("No kerberos support compiled in\n");
6429 fstrcpy(username,optarg);
6430 p = strchr_m(username,'%');
6433 fstrcpy(password, p+1);
6438 fstrcpy(multishare_conn_fname, optarg);
6439 use_multishare_conn = True;
6442 torture_blocksize = atoi(optarg);
6445 printf("Unknown option %c (%d)\n", (char)opt, opt);
6450 d_printf("using seed %d\n", seed);
6454 if(use_kerberos && !gotuser) gotpass = True;
6457 p = getpass("Password:");
6459 fstrcpy(password, p);
6464 printf("host=%s share=%s user=%s myname=%s\n",
6465 host, share, username, myname);
6467 if (argc == optind) {
6468 correct = run_test("ALL");
6470 for (i=optind;i<argc;i++) {
6471 if (!run_test(argv[i])) {