2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1997-1998
5 Copyright (C) Jeremy Allison 2009
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "nsswitch/libwbclient/wbc_async.h"
27 static fstring host, workgroup, share, password, username, myname;
28 static int max_protocol = PROTOCOL_NT1;
29 static const char *sockops="TCP_NODELAY";
31 static int port_to_use=0;
32 int torture_numops=100;
33 int torture_blocksize=1024*1024;
34 static int procnum; /* records process count number when forking */
35 static struct cli_state *current_cli;
36 static fstring randomfname;
37 static bool use_oplocks;
38 static bool use_level_II_oplocks;
39 static const char *client_txt = "client_oplocks.txt";
40 static bool use_kerberos;
41 static fstring multishare_conn_fname;
42 static bool use_multishare_conn = False;
43 static bool do_encrypt;
44 static const char *local_path = NULL;
46 bool torture_showall = False;
48 static double create_procs(bool (*fn)(int), bool *result);
51 static struct timeval tp1,tp2;
54 void start_timer(void)
59 double end_timer(void)
62 return((tp2.tv_sec - tp1.tv_sec) +
63 (tp2.tv_usec - tp1.tv_usec)*1.0e-6);
67 /* return a pointer to a anonymous shared memory segment of size "size"
68 which will persist across fork() but will disappear when all processes
71 The memory is not zeroed
73 This function uses system5 shared memory. It takes advantage of a property
74 that the memory is not destroyed if it is attached when the id is removed
76 void *shm_setup(int size)
82 shmid = shm_open("private", O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
84 printf("can't get shared memory\n");
87 shm_unlink("private");
88 if (ftruncate(shmid, size) == -1) {
89 printf("can't set shared memory size\n");
92 ret = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, shmid, 0);
93 if (ret == MAP_FAILED) {
94 printf("can't map shared memory\n");
98 shmid = shmget(IPC_PRIVATE, size, S_IRUSR | S_IWUSR);
100 printf("can't get shared memory\n");
103 ret = (void *)shmat(shmid, 0, 0);
104 if (!ret || ret == (void *)-1) {
105 printf("can't attach to shared memory\n");
108 /* the following releases the ipc, but note that this process
109 and all its children will still have access to the memory, its
110 just that the shmid is no longer valid for other shm calls. This
111 means we don't leave behind lots of shm segments after we exit
113 See Stevens "advanced programming in unix env" for details
115 shmctl(shmid, IPC_RMID, 0);
121 /********************************************************************
122 Ensure a connection is encrypted.
123 ********************************************************************/
125 static bool force_cli_encryption(struct cli_state *c,
126 const char *sharename)
129 uint32 caplow, caphigh;
132 if (!SERVER_HAS_UNIX_CIFS(c)) {
133 d_printf("Encryption required and "
134 "server that doesn't support "
135 "UNIX extensions - failing connect\n");
139 status = cli_unix_extensions_version(c, &major, &minor, &caplow,
141 if (!NT_STATUS_IS_OK(status)) {
142 d_printf("Encryption required and "
143 "can't get UNIX CIFS extensions "
144 "version from server: %s\n", nt_errstr(status));
148 if (!(caplow & CIFS_UNIX_TRANSPORT_ENCRYPTION_CAP)) {
149 d_printf("Encryption required and "
150 "share %s doesn't support "
151 "encryption.\n", sharename);
155 if (c->use_kerberos) {
156 status = cli_gss_smb_encryption_start(c);
158 status = cli_raw_ntlm_smb_encryption_start(c,
164 if (!NT_STATUS_IS_OK(status)) {
165 d_printf("Encryption required and "
166 "setup failed with error %s.\n",
175 static struct cli_state *open_nbt_connection(void)
177 struct nmb_name called, calling;
178 struct sockaddr_storage ss;
182 make_nmb_name(&calling, myname, 0x0);
183 make_nmb_name(&called , host, 0x20);
187 if (!(c = cli_initialise())) {
188 printf("Failed initialize cli_struct to connect with %s\n", host);
192 c->port = port_to_use;
194 status = cli_connect(c, host, &ss);
195 if (!NT_STATUS_IS_OK(status)) {
196 printf("Failed to connect with %s. Error %s\n", host, nt_errstr(status) );
200 c->use_kerberos = use_kerberos;
202 c->timeout = 120000; /* set a really long timeout (2 minutes) */
203 if (use_oplocks) c->use_oplocks = True;
204 if (use_level_II_oplocks) c->use_level_II_oplocks = True;
206 if (!cli_session_request(c, &calling, &called)) {
208 * Well, that failed, try *SMBSERVER ...
209 * However, we must reconnect as well ...
211 status = cli_connect(c, host, &ss);
212 if (!NT_STATUS_IS_OK(status)) {
213 printf("Failed to connect with %s. Error %s\n", host, nt_errstr(status) );
217 make_nmb_name(&called, "*SMBSERVER", 0x20);
218 if (!cli_session_request(c, &calling, &called)) {
219 printf("%s rejected the session\n",host);
220 printf("We tried with a called name of %s & %s\n",
230 /* Insert a NULL at the first separator of the given path and return a pointer
231 * to the remainder of the string.
234 terminate_path_at_separator(char * path)
242 if ((p = strchr_m(path, '/'))) {
247 if ((p = strchr_m(path, '\\'))) {
257 parse a //server/share type UNC name
259 bool smbcli_parse_unc(const char *unc_name, TALLOC_CTX *mem_ctx,
260 char **hostname, char **sharename)
264 *hostname = *sharename = NULL;
266 if (strncmp(unc_name, "\\\\", 2) &&
267 strncmp(unc_name, "//", 2)) {
271 *hostname = talloc_strdup(mem_ctx, &unc_name[2]);
272 p = terminate_path_at_separator(*hostname);
275 *sharename = talloc_strdup(mem_ctx, p);
276 terminate_path_at_separator(*sharename);
279 if (*hostname && *sharename) {
283 TALLOC_FREE(*hostname);
284 TALLOC_FREE(*sharename);
288 static bool torture_open_connection_share(struct cli_state **c,
289 const char *hostname,
290 const char *sharename)
297 flags |= CLI_FULL_CONNECTION_USE_KERBEROS;
299 flags |= CLI_FULL_CONNECTION_OPLOCKS;
300 if (use_level_II_oplocks)
301 flags |= CLI_FULL_CONNECTION_LEVEL_II_OPLOCKS;
303 status = cli_full_connection(c, myname,
304 hostname, NULL, port_to_use,
307 password, flags, Undefined, &retry);
308 if (!NT_STATUS_IS_OK(status)) {
309 printf("failed to open share connection: //%s/%s port:%d - %s\n",
310 hostname, sharename, port_to_use, nt_errstr(status));
314 (*c)->timeout = 120000; /* set a really long timeout (2 minutes) */
317 return force_cli_encryption(*c,
323 bool torture_open_connection(struct cli_state **c, int conn_index)
325 char **unc_list = NULL;
326 int num_unc_names = 0;
329 if (use_multishare_conn==True) {
331 unc_list = file_lines_load(multishare_conn_fname, &num_unc_names, 0, NULL);
332 if (!unc_list || num_unc_names <= 0) {
333 printf("Failed to load unc names list from '%s'\n", multishare_conn_fname);
337 if (!smbcli_parse_unc(unc_list[conn_index % num_unc_names],
339 printf("Failed to parse UNC name %s\n",
340 unc_list[conn_index % num_unc_names]);
341 TALLOC_FREE(unc_list);
345 result = torture_open_connection_share(c, h, s);
347 /* h, s were copied earlier */
348 TALLOC_FREE(unc_list);
352 return torture_open_connection_share(c, host, share);
355 bool torture_cli_session_setup2(struct cli_state *cli, uint16 *new_vuid)
357 uint16 old_vuid = cli->vuid;
358 fstring old_user_name;
359 size_t passlen = strlen(password);
363 fstrcpy(old_user_name, cli->user_name);
365 ret = NT_STATUS_IS_OK(cli_session_setup(cli, username,
369 *new_vuid = cli->vuid;
370 cli->vuid = old_vuid;
371 status = cli_set_username(cli, old_user_name);
372 if (!NT_STATUS_IS_OK(status)) {
379 bool torture_close_connection(struct cli_state *c)
383 printf("tdis failed (%s)\n", cli_errstr(c));
393 /* check if the server produced the expected error code */
394 static bool check_error(int line, struct cli_state *c,
395 uint8 eclass, uint32 ecode, NTSTATUS nterr)
397 if (cli_is_dos_error(c)) {
401 /* Check DOS error */
403 cli_dos_error(c, &cclass, &num);
405 if (eclass != cclass || ecode != num) {
406 printf("unexpected error code class=%d code=%d\n",
407 (int)cclass, (int)num);
408 printf(" expected %d/%d %s (line=%d)\n",
409 (int)eclass, (int)ecode, nt_errstr(nterr), line);
418 status = cli_nt_error(c);
420 if (NT_STATUS_V(nterr) != NT_STATUS_V(status)) {
421 printf("unexpected error code %s\n", nt_errstr(status));
422 printf(" expected %s (line=%d)\n", nt_errstr(nterr), line);
431 static bool wait_lock(struct cli_state *c, int fnum, uint32 offset, uint32 len)
433 while (!cli_lock(c, fnum, offset, len, -1, WRITE_LOCK)) {
434 if (!check_error(__LINE__, c, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
440 static bool rw_torture(struct cli_state *c)
442 const char *lockfname = "\\torture.lck";
446 pid_t pid2, pid = getpid();
452 memset(buf, '\0', sizeof(buf));
454 status = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
456 if (!NT_STATUS_IS_OK(status)) {
457 status = cli_open(c, lockfname, O_RDWR, DENY_NONE, &fnum2);
459 if (!NT_STATUS_IS_OK(status)) {
460 printf("open of %s failed (%s)\n", lockfname, cli_errstr(c));
464 for (i=0;i<torture_numops;i++) {
465 unsigned n = (unsigned)sys_random()%10;
467 printf("%d\r", i); fflush(stdout);
469 slprintf(fname, sizeof(fstring) - 1, "\\torture.%u", n);
471 if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) {
475 if (!NT_STATUS_IS_OK(cli_open(c, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL, &fnum))) {
476 printf("open failed (%s)\n", cli_errstr(c));
481 if (cli_write(c, fnum, 0, (char *)&pid, 0, sizeof(pid)) != sizeof(pid)) {
482 printf("write failed (%s)\n", cli_errstr(c));
487 if (cli_write(c, fnum, 0, (char *)buf,
488 sizeof(pid)+(j*sizeof(buf)),
489 sizeof(buf)) != sizeof(buf)) {
490 printf("write failed (%s)\n", cli_errstr(c));
497 if (cli_read(c, fnum, (char *)&pid2, 0, sizeof(pid)) != sizeof(pid)) {
498 printf("read failed (%s)\n", cli_errstr(c));
503 printf("data corruption!\n");
507 if (!NT_STATUS_IS_OK(cli_close(c, fnum))) {
508 printf("close failed (%s)\n", cli_errstr(c));
512 if (!NT_STATUS_IS_OK(cli_unlink(c, fname, aSYSTEM | aHIDDEN))) {
513 printf("unlink failed (%s)\n", cli_errstr(c));
517 if (!NT_STATUS_IS_OK(cli_unlock(c, fnum2, n*sizeof(int), sizeof(int)))) {
518 printf("unlock failed (%s)\n", cli_errstr(c));
524 cli_unlink(c, lockfname, aSYSTEM | aHIDDEN);
531 static bool run_torture(int dummy)
533 struct cli_state *cli;
538 cli_sockopt(cli, sockops);
540 ret = rw_torture(cli);
542 if (!torture_close_connection(cli)) {
549 static bool rw_torture3(struct cli_state *c, char *lockfname)
551 uint16_t fnum = (uint16_t)-1;
556 unsigned countprev = 0;
562 for (i = 0; i < sizeof(buf); i += sizeof(uint32))
564 SIVAL(buf, i, sys_random());
569 if (!NT_STATUS_IS_OK(cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
570 DENY_NONE, &fnum))) {
571 printf("first open read/write of %s failed (%s)\n",
572 lockfname, cli_errstr(c));
578 for (i = 0; i < 500 && fnum == (uint16_t)-1; i++)
580 status = cli_open(c, lockfname, O_RDONLY,
582 if (!NT_STATUS_IS_OK(status)) {
587 if (!NT_STATUS_IS_OK(status)) {
588 printf("second open read-only of %s failed (%s)\n",
589 lockfname, cli_errstr(c));
595 for (count = 0; count < sizeof(buf); count += sent)
597 if (count >= countprev) {
598 printf("%d %8d\r", i, count);
601 countprev += (sizeof(buf) / 20);
606 sent = ((unsigned)sys_random()%(20))+ 1;
607 if (sent > sizeof(buf) - count)
609 sent = sizeof(buf) - count;
612 if (cli_write(c, fnum, 0, buf+count, count, (size_t)sent) != sent) {
613 printf("write failed (%s)\n", cli_errstr(c));
619 sent = cli_read(c, fnum, buf_rd+count, count,
623 printf("read failed offset:%d size:%ld (%s)\n",
624 count, (unsigned long)sizeof(buf)-count,
631 if (memcmp(buf_rd+count, buf+count, sent) != 0)
633 printf("read/write compare failed\n");
634 printf("offset: %d req %ld recvd %ld\n", count, (unsigned long)sizeof(buf)-count, (unsigned long)sent);
643 if (!NT_STATUS_IS_OK(cli_close(c, fnum))) {
644 printf("close failed (%s)\n", cli_errstr(c));
651 static bool rw_torture2(struct cli_state *c1, struct cli_state *c2)
653 const char *lockfname = "\\torture2.lck";
662 if (!NT_STATUS_IS_OK(cli_unlink(c1, lockfname, aSYSTEM | aHIDDEN))) {
663 printf("unlink failed (%s) (normal, this file should not exist)\n", cli_errstr(c1));
666 if (!NT_STATUS_IS_OK(cli_open(c1, lockfname, O_RDWR | O_CREAT | O_EXCL,
667 DENY_NONE, &fnum1))) {
668 printf("first open read/write of %s failed (%s)\n",
669 lockfname, cli_errstr(c1));
672 if (!NT_STATUS_IS_OK(cli_open(c2, lockfname, O_RDONLY,
673 DENY_NONE, &fnum2))) {
674 printf("second open read-only of %s failed (%s)\n",
675 lockfname, cli_errstr(c2));
676 cli_close(c1, fnum1);
680 for (i=0;i<torture_numops;i++)
682 size_t buf_size = ((unsigned)sys_random()%(sizeof(buf)-1))+ 1;
684 printf("%d\r", i); fflush(stdout);
687 generate_random_buffer((unsigned char *)buf, buf_size);
689 if (cli_write(c1, fnum1, 0, buf, 0, buf_size) != buf_size) {
690 printf("write failed (%s)\n", cli_errstr(c1));
695 if ((bytes_read = cli_read(c2, fnum2, buf_rd, 0, buf_size)) != buf_size) {
696 printf("read failed (%s)\n", cli_errstr(c2));
697 printf("read %d, expected %ld\n", (int)bytes_read,
698 (unsigned long)buf_size);
703 if (memcmp(buf_rd, buf, buf_size) != 0)
705 printf("read/write compare failed\n");
711 if (!NT_STATUS_IS_OK(cli_close(c2, fnum2))) {
712 printf("close failed (%s)\n", cli_errstr(c2));
715 if (!NT_STATUS_IS_OK(cli_close(c1, fnum1))) {
716 printf("close failed (%s)\n", cli_errstr(c1));
720 if (!NT_STATUS_IS_OK(cli_unlink(c1, lockfname, aSYSTEM | aHIDDEN))) {
721 printf("unlink failed (%s)\n", cli_errstr(c1));
728 static bool run_readwritetest(int dummy)
730 struct cli_state *cli1, *cli2;
731 bool test1, test2 = False;
733 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
736 cli_sockopt(cli1, sockops);
737 cli_sockopt(cli2, sockops);
739 printf("starting readwritetest\n");
741 test1 = rw_torture2(cli1, cli2);
742 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1));
745 test2 = rw_torture2(cli1, cli1);
746 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2));
749 if (!torture_close_connection(cli1)) {
753 if (!torture_close_connection(cli2)) {
757 return (test1 && test2);
760 static bool run_readwritemulti(int dummy)
762 struct cli_state *cli;
767 cli_sockopt(cli, sockops);
769 printf("run_readwritemulti: fname %s\n", randomfname);
770 test = rw_torture3(cli, randomfname);
772 if (!torture_close_connection(cli)) {
779 static bool run_readwritelarge(int dummy)
781 static struct cli_state *cli1;
783 const char *lockfname = "\\large.dat";
788 if (!torture_open_connection(&cli1, 0)) {
791 cli_sockopt(cli1, sockops);
792 memset(buf,'\0',sizeof(buf));
794 cli1->max_xmit = 128*1024;
796 printf("starting readwritelarge\n");
798 cli_unlink(cli1, lockfname, aSYSTEM | aHIDDEN);
800 if (!NT_STATUS_IS_OK(cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE, &fnum1))) {
801 printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(cli1));
805 cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf));
807 if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
808 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
812 if (fsize == sizeof(buf))
813 printf("readwritelarge test 1 succeeded (size = %lx)\n",
814 (unsigned long)fsize);
816 printf("readwritelarge test 1 failed (size = %lx)\n",
817 (unsigned long)fsize);
821 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
822 printf("close failed (%s)\n", cli_errstr(cli1));
826 if (!NT_STATUS_IS_OK(cli_unlink(cli1, lockfname, aSYSTEM | aHIDDEN))) {
827 printf("unlink failed (%s)\n", cli_errstr(cli1));
831 if (!NT_STATUS_IS_OK(cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE, &fnum1))) {
832 printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(cli1));
836 cli1->max_xmit = 4*1024;
838 cli_smbwrite(cli1, fnum1, buf, 0, sizeof(buf));
840 if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
841 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
845 if (fsize == sizeof(buf))
846 printf("readwritelarge test 2 succeeded (size = %lx)\n",
847 (unsigned long)fsize);
849 printf("readwritelarge test 2 failed (size = %lx)\n",
850 (unsigned long)fsize);
855 /* ToDo - set allocation. JRA */
856 if(!cli_set_allocation_size(cli1, fnum1, 0)) {
857 printf("set allocation size to zero failed (%s)\n", cli_errstr(&cli1));
860 if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
861 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
865 printf("readwritelarge test 3 (truncate test) succeeded (size = %x)\n", fsize);
868 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
869 printf("close failed (%s)\n", cli_errstr(cli1));
873 if (!torture_close_connection(cli1)) {
882 #define ival(s) strtol(s, NULL, 0)
884 /* run a test that simulates an approximate netbench client load */
885 static bool run_netbench(int client)
887 struct cli_state *cli;
892 const char *params[20];
899 cli_sockopt(cli, sockops);
903 slprintf(cname,sizeof(cname)-1, "client%d", client);
905 f = fopen(client_txt, "r");
912 while (fgets(line, sizeof(line)-1, f)) {
916 line[strlen(line)-1] = 0;
918 /* printf("[%d] %s\n", line_count, line); */
920 all_string_sub(line,"client1", cname, sizeof(line));
922 /* parse the command parameters */
923 params[0] = strtok_r(line, " ", &saveptr);
925 while (params[i]) params[++i] = strtok_r(NULL, " ", &saveptr);
931 if (!strncmp(params[0],"SMB", 3)) {
932 printf("ERROR: You are using a dbench 1 load file\n");
936 if (!strcmp(params[0],"NTCreateX")) {
937 nb_createx(params[1], ival(params[2]), ival(params[3]),
939 } else if (!strcmp(params[0],"Close")) {
940 nb_close(ival(params[1]));
941 } else if (!strcmp(params[0],"Rename")) {
942 nb_rename(params[1], params[2]);
943 } else if (!strcmp(params[0],"Unlink")) {
944 nb_unlink(params[1]);
945 } else if (!strcmp(params[0],"Deltree")) {
946 nb_deltree(params[1]);
947 } else if (!strcmp(params[0],"Rmdir")) {
949 } else if (!strcmp(params[0],"QUERY_PATH_INFORMATION")) {
950 nb_qpathinfo(params[1]);
951 } else if (!strcmp(params[0],"QUERY_FILE_INFORMATION")) {
952 nb_qfileinfo(ival(params[1]));
953 } else if (!strcmp(params[0],"QUERY_FS_INFORMATION")) {
954 nb_qfsinfo(ival(params[1]));
955 } else if (!strcmp(params[0],"FIND_FIRST")) {
956 nb_findfirst(params[1]);
957 } else if (!strcmp(params[0],"WriteX")) {
958 nb_writex(ival(params[1]),
959 ival(params[2]), ival(params[3]), ival(params[4]));
960 } else if (!strcmp(params[0],"ReadX")) {
961 nb_readx(ival(params[1]),
962 ival(params[2]), ival(params[3]), ival(params[4]));
963 } else if (!strcmp(params[0],"Flush")) {
964 nb_flush(ival(params[1]));
966 printf("Unknown operation %s\n", params[0]);
974 if (!torture_close_connection(cli)) {
982 /* run a test that simulates an approximate netbench client load */
983 static bool run_nbench(int dummy)
992 signal(SIGALRM, nb_alarm);
994 t = create_procs(run_netbench, &correct);
997 printf("\nThroughput %g MB/sec\n",
998 1.0e-6 * nbio_total() / t);
1004 This test checks for two things:
1006 1) correct support for retaining locks over a close (ie. the server
1007 must not use posix semantics)
1008 2) support for lock timeouts
1010 static bool run_locktest1(int dummy)
1012 struct cli_state *cli1, *cli2;
1013 const char *fname = "\\lockt1.lck";
1014 uint16_t fnum1, fnum2, fnum3;
1016 unsigned lock_timeout;
1018 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1021 cli_sockopt(cli1, sockops);
1022 cli_sockopt(cli2, sockops);
1024 printf("starting locktest1\n");
1026 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
1028 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
1029 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
1032 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum2))) {
1033 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli1));
1036 if (!NT_STATUS_IS_OK(cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum3))) {
1037 printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli2));
1041 if (!cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
1042 printf("lock1 failed (%s)\n", cli_errstr(cli1));
1047 if (cli_lock(cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
1048 printf("lock2 succeeded! This is a locking bug\n");
1051 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
1052 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1056 lock_timeout = (1 + (random() % 20));
1057 printf("Testing lock timeout with timeout=%u\n", lock_timeout);
1059 if (cli_lock(cli2, fnum3, 0, 4, lock_timeout * 1000, WRITE_LOCK)) {
1060 printf("lock3 succeeded! This is a locking bug\n");
1063 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
1064 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
1068 if (ABS(t2 - t1) < lock_timeout-1) {
1069 printf("error: This server appears not to support timed lock requests\n");
1072 printf("server slept for %u seconds for a %u second timeout\n",
1073 (unsigned int)(t2-t1), lock_timeout);
1075 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum2))) {
1076 printf("close1 failed (%s)\n", cli_errstr(cli1));
1080 if (cli_lock(cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
1081 printf("lock4 succeeded! This is a locking bug\n");
1084 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
1085 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
1088 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
1089 printf("close2 failed (%s)\n", cli_errstr(cli1));
1093 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum3))) {
1094 printf("close3 failed (%s)\n", cli_errstr(cli2));
1098 if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname, aSYSTEM | aHIDDEN))) {
1099 printf("unlink failed (%s)\n", cli_errstr(cli1));
1104 if (!torture_close_connection(cli1)) {
1108 if (!torture_close_connection(cli2)) {
1112 printf("Passed locktest1\n");
1117 this checks to see if a secondary tconx can use open files from an
1120 static bool run_tcon_test(int dummy)
1122 static struct cli_state *cli;
1123 const char *fname = "\\tcontest.tmp";
1125 uint16 cnum1, cnum2, cnum3;
1126 uint16 vuid1, vuid2;
1131 memset(buf, '\0', sizeof(buf));
1133 if (!torture_open_connection(&cli, 0)) {
1136 cli_sockopt(cli, sockops);
1138 printf("starting tcontest\n");
1140 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
1142 if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
1143 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
1150 if (cli_write(cli, fnum1, 0, buf, 130, 4) != 4) {
1151 printf("initial write failed (%s)", cli_errstr(cli));
1155 status = cli_tcon_andx(cli, share, "?????",
1156 password, strlen(password)+1);
1157 if (!NT_STATUS_IS_OK(status)) {
1158 printf("%s refused 2nd tree connect (%s)\n", host,
1165 cnum3 = MAX(cnum1, cnum2) + 1; /* any invalid number */
1166 vuid2 = cli->vuid + 1;
1168 /* try a write with the wrong tid */
1171 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
1172 printf("* server allows write with wrong TID\n");
1175 printf("server fails write with wrong TID : %s\n", cli_errstr(cli));
1179 /* try a write with an invalid tid */
1182 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
1183 printf("* server allows write with invalid TID\n");
1186 printf("server fails write with invalid TID : %s\n", cli_errstr(cli));
1189 /* try a write with an invalid vuid */
1193 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
1194 printf("* server allows write with invalid VUID\n");
1197 printf("server fails write with invalid VUID : %s\n", cli_errstr(cli));
1203 if (!NT_STATUS_IS_OK(cli_close(cli, fnum1))) {
1204 printf("close failed (%s)\n", cli_errstr(cli));
1210 if (!cli_tdis(cli)) {
1211 printf("secondary tdis failed (%s)\n", cli_errstr(cli));
1217 if (!torture_close_connection(cli)) {
1226 checks for old style tcon support
1228 static bool run_tcon2_test(int dummy)
1230 static struct cli_state *cli;
1231 uint16 cnum, max_xmit;
1235 if (!torture_open_connection(&cli, 0)) {
1238 cli_sockopt(cli, sockops);
1240 printf("starting tcon2 test\n");
1242 if (asprintf(&service, "\\\\%s\\%s", host, share) == -1) {
1246 status = cli_raw_tcon(cli, service, password, "?????", &max_xmit, &cnum);
1248 if (!NT_STATUS_IS_OK(status)) {
1249 printf("tcon2 failed : %s\n", cli_errstr(cli));
1251 printf("tcon OK : max_xmit=%d cnum=%d tid=%d\n",
1252 (int)max_xmit, (int)cnum, SVAL(cli->inbuf, smb_tid));
1255 if (!torture_close_connection(cli)) {
1259 printf("Passed tcon2 test\n");
1263 static bool tcon_devtest(struct cli_state *cli,
1264 const char *myshare, const char *devtype,
1265 const char *return_devtype,
1266 NTSTATUS expected_error)
1271 status = cli_tcon_andx(cli, myshare, devtype,
1272 password, strlen(password)+1);
1274 if (NT_STATUS_IS_OK(expected_error)) {
1275 if (NT_STATUS_IS_OK(status)) {
1276 if (strcmp(cli->dev, return_devtype) == 0) {
1279 printf("tconX to share %s with type %s "
1280 "succeeded but returned the wrong "
1281 "device type (got [%s] but should have got [%s])\n",
1282 myshare, devtype, cli->dev, return_devtype);
1286 printf("tconX to share %s with type %s "
1287 "should have succeeded but failed\n",
1293 if (NT_STATUS_IS_OK(status)) {
1294 printf("tconx to share %s with type %s "
1295 "should have failed but succeeded\n",
1299 if (NT_STATUS_EQUAL(cli_nt_error(cli),
1303 printf("Returned unexpected error\n");
1312 checks for correct tconX support
1314 static bool run_tcon_devtype_test(int dummy)
1316 static struct cli_state *cli1 = NULL;
1322 status = cli_full_connection(&cli1, myname,
1323 host, NULL, port_to_use,
1325 username, workgroup,
1326 password, flags, Undefined, &retry);
1328 if (!NT_STATUS_IS_OK(status)) {
1329 printf("could not open connection\n");
1333 if (!tcon_devtest(cli1, "IPC$", "A:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1336 if (!tcon_devtest(cli1, "IPC$", "?????", "IPC", NT_STATUS_OK))
1339 if (!tcon_devtest(cli1, "IPC$", "LPT:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1342 if (!tcon_devtest(cli1, "IPC$", "IPC", "IPC", NT_STATUS_OK))
1345 if (!tcon_devtest(cli1, "IPC$", "FOOBA", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1348 if (!tcon_devtest(cli1, share, "A:", "A:", NT_STATUS_OK))
1351 if (!tcon_devtest(cli1, share, "?????", "A:", NT_STATUS_OK))
1354 if (!tcon_devtest(cli1, share, "LPT:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1357 if (!tcon_devtest(cli1, share, "IPC", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1360 if (!tcon_devtest(cli1, share, "FOOBA", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1366 printf("Passed tcondevtest\n");
1373 This test checks that
1375 1) the server supports multiple locking contexts on the one SMB
1376 connection, distinguished by PID.
1378 2) the server correctly fails overlapping locks made by the same PID (this
1379 goes against POSIX behaviour, which is why it is tricky to implement)
1381 3) the server denies unlock requests by an incorrect client PID
1383 static bool run_locktest2(int dummy)
1385 static struct cli_state *cli;
1386 const char *fname = "\\lockt2.lck";
1387 uint16_t fnum1, fnum2, fnum3;
1388 bool correct = True;
1390 if (!torture_open_connection(&cli, 0)) {
1394 cli_sockopt(cli, sockops);
1396 printf("starting locktest2\n");
1398 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
1402 if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
1403 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
1407 if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum2))) {
1408 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli));
1414 if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum3))) {
1415 printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli));
1421 if (!cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
1422 printf("lock1 failed (%s)\n", cli_errstr(cli));
1426 if (cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
1427 printf("WRITE lock1 succeeded! This is a locking bug\n");
1430 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1431 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1434 if (cli_lock(cli, fnum2, 0, 4, 0, WRITE_LOCK)) {
1435 printf("WRITE lock2 succeeded! This is a locking bug\n");
1438 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1439 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1442 if (cli_lock(cli, fnum2, 0, 4, 0, READ_LOCK)) {
1443 printf("READ lock2 succeeded! This is a locking bug\n");
1446 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1447 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
1450 if (!cli_lock(cli, fnum1, 100, 4, 0, WRITE_LOCK)) {
1451 printf("lock at 100 failed (%s)\n", cli_errstr(cli));
1454 if (NT_STATUS_IS_OK(cli_unlock(cli, fnum1, 100, 4))) {
1455 printf("unlock at 100 succeeded! This is a locking bug\n");
1459 if (NT_STATUS_IS_OK(cli_unlock(cli, fnum1, 0, 4))) {
1460 printf("unlock1 succeeded! This is a locking bug\n");
1463 if (!check_error(__LINE__, cli,
1465 NT_STATUS_RANGE_NOT_LOCKED)) return False;
1468 if (NT_STATUS_IS_OK(cli_unlock(cli, fnum1, 0, 8))) {
1469 printf("unlock2 succeeded! This is a locking bug\n");
1472 if (!check_error(__LINE__, cli,
1474 NT_STATUS_RANGE_NOT_LOCKED)) return False;
1477 if (cli_lock(cli, fnum3, 0, 4, 0, WRITE_LOCK)) {
1478 printf("lock3 succeeded! This is a locking bug\n");
1481 if (!check_error(__LINE__, cli, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
1486 if (!NT_STATUS_IS_OK(cli_close(cli, fnum1))) {
1487 printf("close1 failed (%s)\n", cli_errstr(cli));
1491 if (!NT_STATUS_IS_OK(cli_close(cli, fnum2))) {
1492 printf("close2 failed (%s)\n", cli_errstr(cli));
1496 if (!NT_STATUS_IS_OK(cli_close(cli, fnum3))) {
1497 printf("close3 failed (%s)\n", cli_errstr(cli));
1501 if (!torture_close_connection(cli)) {
1505 printf("locktest2 finished\n");
1512 This test checks that
1514 1) the server supports the full offset range in lock requests
1516 static bool run_locktest3(int dummy)
1518 static struct cli_state *cli1, *cli2;
1519 const char *fname = "\\lockt3.lck";
1520 uint16_t fnum1, fnum2;
1523 bool correct = True;
1525 #define NEXT_OFFSET offset += (~(uint32)0) / torture_numops
1527 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1530 cli_sockopt(cli1, sockops);
1531 cli_sockopt(cli2, sockops);
1533 printf("starting locktest3\n");
1535 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
1537 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
1538 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
1541 if (!NT_STATUS_IS_OK(cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2))) {
1542 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli2));
1546 for (offset=i=0;i<torture_numops;i++) {
1548 if (!cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1549 printf("lock1 %d failed (%s)\n",
1555 if (!cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1556 printf("lock2 %d failed (%s)\n",
1563 for (offset=i=0;i<torture_numops;i++) {
1566 if (cli_lock(cli1, fnum1, offset-2, 1, 0, WRITE_LOCK)) {
1567 printf("error: lock1 %d succeeded!\n", i);
1571 if (cli_lock(cli2, fnum2, offset-1, 1, 0, WRITE_LOCK)) {
1572 printf("error: lock2 %d succeeded!\n", i);
1576 if (cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1577 printf("error: lock3 %d succeeded!\n", i);
1581 if (cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1582 printf("error: lock4 %d succeeded!\n", i);
1587 for (offset=i=0;i<torture_numops;i++) {
1590 if (!NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, offset-1, 1))) {
1591 printf("unlock1 %d failed (%s)\n",
1597 if (!NT_STATUS_IS_OK(cli_unlock(cli2, fnum2, offset-2, 1))) {
1598 printf("unlock2 %d failed (%s)\n",
1605 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
1606 printf("close1 failed (%s)\n", cli_errstr(cli1));
1610 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
1611 printf("close2 failed (%s)\n", cli_errstr(cli2));
1615 if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname, aSYSTEM | aHIDDEN))) {
1616 printf("unlink failed (%s)\n", cli_errstr(cli1));
1620 if (!torture_close_connection(cli1)) {
1624 if (!torture_close_connection(cli2)) {
1628 printf("finished locktest3\n");
1633 #define EXPECTED(ret, v) if ((ret) != (v)) { \
1634 printf("** "); correct = False; \
1638 looks at overlapping locks
1640 static bool run_locktest4(int dummy)
1642 static struct cli_state *cli1, *cli2;
1643 const char *fname = "\\lockt4.lck";
1644 uint16_t fnum1, fnum2, f;
1647 bool correct = True;
1649 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1653 cli_sockopt(cli1, sockops);
1654 cli_sockopt(cli2, sockops);
1656 printf("starting locktest4\n");
1658 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
1660 cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
1661 cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
1663 memset(buf, 0, sizeof(buf));
1665 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1666 printf("Failed to create file\n");
1671 ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1672 cli_lock(cli1, fnum1, 2, 4, 0, WRITE_LOCK);
1673 EXPECTED(ret, False);
1674 printf("the same process %s set overlapping write locks\n", ret?"can":"cannot");
1676 ret = cli_lock(cli1, fnum1, 10, 4, 0, READ_LOCK) &&
1677 cli_lock(cli1, fnum1, 12, 4, 0, READ_LOCK);
1678 EXPECTED(ret, True);
1679 printf("the same process %s set overlapping read locks\n", ret?"can":"cannot");
1681 ret = cli_lock(cli1, fnum1, 20, 4, 0, WRITE_LOCK) &&
1682 cli_lock(cli2, fnum2, 22, 4, 0, WRITE_LOCK);
1683 EXPECTED(ret, False);
1684 printf("a different connection %s set overlapping write locks\n", ret?"can":"cannot");
1686 ret = cli_lock(cli1, fnum1, 30, 4, 0, READ_LOCK) &&
1687 cli_lock(cli2, fnum2, 32, 4, 0, READ_LOCK);
1688 EXPECTED(ret, True);
1689 printf("a different connection %s set overlapping read locks\n", ret?"can":"cannot");
1691 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 40, 4, 0, WRITE_LOCK)) &&
1692 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 42, 4, 0, WRITE_LOCK));
1693 EXPECTED(ret, False);
1694 printf("a different pid %s set overlapping write locks\n", ret?"can":"cannot");
1696 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 50, 4, 0, READ_LOCK)) &&
1697 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 52, 4, 0, READ_LOCK));
1698 EXPECTED(ret, True);
1699 printf("a different pid %s set overlapping read locks\n", ret?"can":"cannot");
1701 ret = cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK) &&
1702 cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK);
1703 EXPECTED(ret, True);
1704 printf("the same process %s set the same read lock twice\n", ret?"can":"cannot");
1706 ret = cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK) &&
1707 cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK);
1708 EXPECTED(ret, False);
1709 printf("the same process %s set the same write lock twice\n", ret?"can":"cannot");
1711 ret = cli_lock(cli1, fnum1, 80, 4, 0, READ_LOCK) &&
1712 cli_lock(cli1, fnum1, 80, 4, 0, WRITE_LOCK);
1713 EXPECTED(ret, False);
1714 printf("the same process %s overlay a read lock with a write lock\n", ret?"can":"cannot");
1716 ret = cli_lock(cli1, fnum1, 90, 4, 0, WRITE_LOCK) &&
1717 cli_lock(cli1, fnum1, 90, 4, 0, READ_LOCK);
1718 EXPECTED(ret, True);
1719 printf("the same process %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1721 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 100, 4, 0, WRITE_LOCK)) &&
1722 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 100, 4, 0, READ_LOCK));
1723 EXPECTED(ret, False);
1724 printf("a different pid %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1726 ret = cli_lock(cli1, fnum1, 110, 4, 0, READ_LOCK) &&
1727 cli_lock(cli1, fnum1, 112, 4, 0, READ_LOCK) &&
1728 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 110, 6));
1729 EXPECTED(ret, False);
1730 printf("the same process %s coalesce read locks\n", ret?"can":"cannot");
1733 ret = cli_lock(cli1, fnum1, 120, 4, 0, WRITE_LOCK) &&
1734 (cli_read(cli2, fnum2, buf, 120, 4) == 4);
1735 EXPECTED(ret, False);
1736 printf("this server %s strict write locking\n", ret?"doesn't do":"does");
1738 ret = cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK) &&
1739 (cli_write(cli2, fnum2, 0, buf, 130, 4) == 4);
1740 EXPECTED(ret, False);
1741 printf("this server %s strict read locking\n", ret?"doesn't do":"does");
1744 ret = cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1745 cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1746 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 140, 4)) &&
1747 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 140, 4));
1748 EXPECTED(ret, True);
1749 printf("this server %s do recursive read locking\n", ret?"does":"doesn't");
1752 ret = cli_lock(cli1, fnum1, 150, 4, 0, WRITE_LOCK) &&
1753 cli_lock(cli1, fnum1, 150, 4, 0, READ_LOCK) &&
1754 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 150, 4)) &&
1755 (cli_read(cli2, fnum2, buf, 150, 4) == 4) &&
1756 !(cli_write(cli2, fnum2, 0, buf, 150, 4) == 4) &&
1757 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 150, 4));
1758 EXPECTED(ret, True);
1759 printf("this server %s do recursive lock overlays\n", ret?"does":"doesn't");
1761 ret = cli_lock(cli1, fnum1, 160, 4, 0, READ_LOCK) &&
1762 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 160, 4)) &&
1763 (cli_write(cli2, fnum2, 0, buf, 160, 4) == 4) &&
1764 (cli_read(cli2, fnum2, buf, 160, 4) == 4);
1765 EXPECTED(ret, True);
1766 printf("the same process %s remove a read lock using write locking\n", ret?"can":"cannot");
1768 ret = cli_lock(cli1, fnum1, 170, 4, 0, WRITE_LOCK) &&
1769 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 170, 4)) &&
1770 (cli_write(cli2, fnum2, 0, buf, 170, 4) == 4) &&
1771 (cli_read(cli2, fnum2, buf, 170, 4) == 4);
1772 EXPECTED(ret, True);
1773 printf("the same process %s remove a write lock using read locking\n", ret?"can":"cannot");
1775 ret = cli_lock(cli1, fnum1, 190, 4, 0, WRITE_LOCK) &&
1776 cli_lock(cli1, fnum1, 190, 4, 0, READ_LOCK) &&
1777 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 190, 4)) &&
1778 !(cli_write(cli2, fnum2, 0, buf, 190, 4) == 4) &&
1779 (cli_read(cli2, fnum2, buf, 190, 4) == 4);
1780 EXPECTED(ret, True);
1781 printf("the same process %s remove the first lock first\n", ret?"does":"doesn't");
1783 cli_close(cli1, fnum1);
1784 cli_close(cli2, fnum2);
1785 cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
1786 cli_open(cli1, fname, O_RDWR, DENY_NONE, &f);
1787 ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1788 cli_lock(cli1, f, 0, 1, 0, READ_LOCK) &&
1789 NT_STATUS_IS_OK(cli_close(cli1, fnum1)) &&
1790 NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1)) &&
1791 cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1793 cli_close(cli1, fnum1);
1794 EXPECTED(ret, True);
1795 printf("the server %s have the NT byte range lock bug\n", !ret?"does":"doesn't");
1798 cli_close(cli1, fnum1);
1799 cli_close(cli2, fnum2);
1800 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
1801 torture_close_connection(cli1);
1802 torture_close_connection(cli2);
1804 printf("finished locktest4\n");
1809 looks at lock upgrade/downgrade.
1811 static bool run_locktest5(int dummy)
1813 static struct cli_state *cli1, *cli2;
1814 const char *fname = "\\lockt5.lck";
1815 uint16_t fnum1, fnum2, fnum3;
1818 bool correct = True;
1820 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1824 cli_sockopt(cli1, sockops);
1825 cli_sockopt(cli2, sockops);
1827 printf("starting locktest5\n");
1829 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
1831 cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
1832 cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
1833 cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum3);
1835 memset(buf, 0, sizeof(buf));
1837 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1838 printf("Failed to create file\n");
1843 /* Check for NT bug... */
1844 ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1845 cli_lock(cli1, fnum3, 0, 1, 0, READ_LOCK);
1846 cli_close(cli1, fnum1);
1847 cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
1848 ret = cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1849 EXPECTED(ret, True);
1850 printf("this server %s the NT locking bug\n", ret ? "doesn't have" : "has");
1851 cli_close(cli1, fnum1);
1852 cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
1853 cli_unlock(cli1, fnum3, 0, 1);
1855 ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1856 cli_lock(cli1, fnum1, 1, 1, 0, READ_LOCK);
1857 EXPECTED(ret, True);
1858 printf("the same process %s overlay a write with a read lock\n", ret?"can":"cannot");
1860 ret = cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK);
1861 EXPECTED(ret, False);
1863 printf("a different processs %s get a read lock on the first process lock stack\n", ret?"can":"cannot");
1865 /* Unlock the process 2 lock. */
1866 cli_unlock(cli2, fnum2, 0, 4);
1868 ret = cli_lock(cli1, fnum3, 0, 4, 0, READ_LOCK);
1869 EXPECTED(ret, False);
1871 printf("the same processs on a different fnum %s get a read lock\n", ret?"can":"cannot");
1873 /* Unlock the process 1 fnum3 lock. */
1874 cli_unlock(cli1, fnum3, 0, 4);
1876 /* Stack 2 more locks here. */
1877 ret = cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK) &&
1878 cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK);
1880 EXPECTED(ret, True);
1881 printf("the same process %s stack read locks\n", ret?"can":"cannot");
1883 /* Unlock the first process lock, then check this was the WRITE lock that was
1886 ret = NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 0, 4)) &&
1887 cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK);
1889 EXPECTED(ret, True);
1890 printf("the first unlock removes the %s lock\n", ret?"WRITE":"READ");
1892 /* Unlock the process 2 lock. */
1893 cli_unlock(cli2, fnum2, 0, 4);
1895 /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */
1897 ret = NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 1, 1)) &&
1898 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 0, 4)) &&
1899 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 0, 4));
1901 EXPECTED(ret, True);
1902 printf("the same process %s unlock the stack of 4 locks\n", ret?"can":"cannot");
1904 /* Ensure the next unlock fails. */
1905 ret = NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 0, 4));
1906 EXPECTED(ret, False);
1907 printf("the same process %s count the lock stack\n", !ret?"can":"cannot");
1909 /* Ensure connection 2 can get a write lock. */
1910 ret = cli_lock(cli2, fnum2, 0, 4, 0, WRITE_LOCK);
1911 EXPECTED(ret, True);
1913 printf("a different processs %s get a write lock on the unlocked stack\n", ret?"can":"cannot");
1917 cli_close(cli1, fnum1);
1918 cli_close(cli2, fnum2);
1919 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
1920 if (!torture_close_connection(cli1)) {
1923 if (!torture_close_connection(cli2)) {
1927 printf("finished locktest5\n");
1933 tries the unusual lockingX locktype bits
1935 static bool run_locktest6(int dummy)
1937 static struct cli_state *cli;
1938 const char *fname[1] = { "\\lock6.txt" };
1943 if (!torture_open_connection(&cli, 0)) {
1947 cli_sockopt(cli, sockops);
1949 printf("starting locktest6\n");
1952 printf("Testing %s\n", fname[i]);
1954 cli_unlink(cli, fname[i], aSYSTEM | aHIDDEN);
1956 cli_open(cli, fname[i], O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
1957 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE);
1958 cli_close(cli, fnum);
1959 printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status));
1961 cli_open(cli, fname[i], O_RDWR, DENY_NONE, &fnum);
1962 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK);
1963 cli_close(cli, fnum);
1964 printf("CANCEL_LOCK gave %s\n", nt_errstr(status));
1966 cli_unlink(cli, fname[i], aSYSTEM | aHIDDEN);
1969 torture_close_connection(cli);
1971 printf("finished locktest6\n");
1975 static bool run_locktest7(int dummy)
1977 struct cli_state *cli1;
1978 const char *fname = "\\lockt7.lck";
1981 bool correct = False;
1983 if (!torture_open_connection(&cli1, 0)) {
1987 cli_sockopt(cli1, sockops);
1989 printf("starting locktest7\n");
1991 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
1993 cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
1995 memset(buf, 0, sizeof(buf));
1997 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1998 printf("Failed to create file\n");
2002 cli_setpid(cli1, 1);
2004 if (!cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK)) {
2005 printf("Unable to apply read lock on range 130:4, error was %s\n", cli_errstr(cli1));
2008 printf("pid1 successfully locked range 130:4 for READ\n");
2011 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
2012 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
2015 printf("pid1 successfully read the range 130:4\n");
2018 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
2019 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
2020 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
2021 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2025 printf("pid1 successfully wrote to the range 130:4 (should be denied)\n");
2029 cli_setpid(cli1, 2);
2031 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
2032 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
2034 printf("pid2 successfully read the range 130:4\n");
2037 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
2038 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
2039 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
2040 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2044 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
2048 cli_setpid(cli1, 1);
2049 cli_unlock(cli1, fnum1, 130, 4);
2051 if (!cli_lock(cli1, fnum1, 130, 4, 0, WRITE_LOCK)) {
2052 printf("Unable to apply write lock on range 130:4, error was %s\n", cli_errstr(cli1));
2055 printf("pid1 successfully locked range 130:4 for WRITE\n");
2058 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
2059 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
2062 printf("pid1 successfully read the range 130:4\n");
2065 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
2066 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
2069 printf("pid1 successfully wrote to the range 130:4\n");
2072 cli_setpid(cli1, 2);
2074 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
2075 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
2076 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
2077 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2081 printf("pid2 successfully read the range 130:4 (should be denied)\n");
2085 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
2086 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
2087 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
2088 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2092 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
2096 cli_unlock(cli1, fnum1, 130, 0);
2100 cli_close(cli1, fnum1);
2101 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
2102 torture_close_connection(cli1);
2104 printf("finished locktest7\n");
2109 * This demonstrates a problem with our use of GPFS share modes: A file
2110 * descriptor sitting in the pending close queue holding a GPFS share mode
2111 * blocks opening a file another time. Happens with Word 2007 temp files.
2112 * With "posix locking = yes" and "gpfs:sharemodes = yes" enabled, the third
2113 * open is denied with NT_STATUS_SHARING_VIOLATION.
2116 static bool run_locktest8(int dummy)
2118 struct cli_state *cli1;
2119 const char *fname = "\\lockt8.lck";
2120 uint16_t fnum1, fnum2;
2122 bool correct = False;
2125 if (!torture_open_connection(&cli1, 0)) {
2129 cli_sockopt(cli1, sockops);
2131 printf("starting locktest8\n");
2133 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
2135 status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_WRITE,
2137 if (!NT_STATUS_IS_OK(status)) {
2138 d_fprintf(stderr, "cli_open returned %s\n", cli_errstr(cli1));
2142 memset(buf, 0, sizeof(buf));
2144 status = cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum2);
2145 if (!NT_STATUS_IS_OK(status)) {
2146 d_fprintf(stderr, "cli_open second time returned %s\n",
2151 if (!cli_lock(cli1, fnum2, 1, 1, 0, READ_LOCK)) {
2152 printf("Unable to apply read lock on range 1:1, error was "
2153 "%s\n", cli_errstr(cli1));
2157 status = cli_close(cli1, fnum1);
2158 if (!NT_STATUS_IS_OK(status)) {
2159 d_fprintf(stderr, "cli_close(fnum1) %s\n", cli_errstr(cli1));
2163 status = cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
2164 if (!NT_STATUS_IS_OK(status)) {
2165 d_fprintf(stderr, "cli_open third time returned %s\n",
2173 cli_close(cli1, fnum1);
2174 cli_close(cli1, fnum2);
2175 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
2176 torture_close_connection(cli1);
2178 printf("finished locktest8\n");
2183 * This test is designed to be run in conjunction with
2184 * external NFS or POSIX locks taken in the filesystem.
2185 * It checks that the smbd server will block until the
2186 * lock is released and then acquire it. JRA.
2189 static bool got_alarm;
2190 static int alarm_fd;
2192 static void alarm_handler(int dummy)
2197 static void alarm_handler_parent(int dummy)
2202 static void do_local_lock(int read_fd, int write_fd)
2207 const char *local_pathname = NULL;
2210 local_pathname = talloc_asprintf(talloc_tos(),
2211 "%s/lockt9.lck", local_path);
2212 if (!local_pathname) {
2213 printf("child: alloc fail\n");
2217 unlink(local_pathname);
2218 fd = open(local_pathname, O_RDWR|O_CREAT, 0666);
2220 printf("child: open of %s failed %s.\n",
2221 local_pathname, strerror(errno));
2225 /* Now take a fcntl lock. */
2226 lock.l_type = F_WRLCK;
2227 lock.l_whence = SEEK_SET;
2230 lock.l_pid = getpid();
2232 ret = fcntl(fd,F_SETLK,&lock);
2234 printf("child: failed to get lock 0:4 on file %s. Error %s\n",
2235 local_pathname, strerror(errno));
2238 printf("child: got lock 0:4 on file %s.\n",
2243 CatchSignal(SIGALRM, alarm_handler);
2245 /* Signal the parent. */
2246 if (write(write_fd, &c, 1) != 1) {
2247 printf("child: start signal fail %s.\n",
2254 /* Wait for the parent to be ready. */
2255 if (read(read_fd, &c, 1) != 1) {
2256 printf("child: reply signal fail %s.\n",
2264 printf("child: released lock 0:4 on file %s.\n",
2270 static bool run_locktest9(int dummy)
2272 struct cli_state *cli1;
2273 const char *fname = "\\lockt9.lck";
2275 bool correct = False;
2276 int pipe_in[2], pipe_out[2];
2283 printf("starting locktest9\n");
2285 if (local_path == NULL) {
2286 d_fprintf(stderr, "locktest9 must be given a local path via -l <localpath>\n");
2290 if (pipe(pipe_in) == -1 || pipe(pipe_out) == -1) {
2295 if (child_pid == -1) {
2299 if (child_pid == 0) {
2301 do_local_lock(pipe_out[0], pipe_in[1]);
2311 ret = read(pipe_in[0], &c, 1);
2313 d_fprintf(stderr, "failed to read start signal from child. %s\n",
2318 if (!torture_open_connection(&cli1, 0)) {
2322 cli_sockopt(cli1, sockops);
2324 status = cli_open(cli1, fname, O_RDWR, DENY_NONE,
2326 if (!NT_STATUS_IS_OK(status)) {
2327 d_fprintf(stderr, "cli_open returned %s\n", cli_errstr(cli1));
2331 /* Ensure the child has the lock. */
2332 if (cli_lock(cli1, fnum, 0, 4, 0, WRITE_LOCK)) {
2333 d_fprintf(stderr, "Got the lock on range 0:4 - this should not happen !\n");
2336 d_printf("Child has the lock.\n");
2339 /* Tell the child to wait 5 seconds then exit. */
2340 ret = write(pipe_out[1], &c, 1);
2342 d_fprintf(stderr, "failed to send exit signal to child. %s\n",
2347 /* Wait 20 seconds for the lock. */
2348 alarm_fd = cli1->fd;
2349 CatchSignal(SIGALRM, alarm_handler_parent);
2354 if (!cli_lock(cli1, fnum, 0, 4, -1, WRITE_LOCK)) {
2355 d_fprintf(stderr, "Unable to apply write lock on range 0:4, error was "
2356 "%s\n", cli_errstr(cli1));
2361 seconds = end_timer();
2363 printf("Parent got the lock after %.2f seconds.\n",
2366 status = cli_close(cli1, fnum);
2367 if (!NT_STATUS_IS_OK(status)) {
2368 d_fprintf(stderr, "cli_close(fnum1) %s\n", cli_errstr(cli1));
2375 cli_close(cli1, fnum);
2376 torture_close_connection(cli1);
2380 printf("finished locktest9\n");
2385 test whether fnums and tids open on one VC are available on another (a major
2388 static bool run_fdpasstest(int dummy)
2390 struct cli_state *cli1, *cli2;
2391 const char *fname = "\\fdpass.tst";
2395 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
2398 cli_sockopt(cli1, sockops);
2399 cli_sockopt(cli2, sockops);
2401 printf("starting fdpasstest\n");
2403 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
2405 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
2406 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2410 if (cli_write(cli1, fnum1, 0, "hello world\n", 0, 13) != 13) {
2411 printf("write failed (%s)\n", cli_errstr(cli1));
2415 cli2->vuid = cli1->vuid;
2416 cli2->cnum = cli1->cnum;
2417 cli2->pid = cli1->pid;
2419 if (cli_read(cli2, fnum1, buf, 0, 13) == 13) {
2420 printf("read succeeded! nasty security hole [%s]\n",
2425 cli_close(cli1, fnum1);
2426 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
2428 torture_close_connection(cli1);
2429 torture_close_connection(cli2);
2431 printf("finished fdpasstest\n");
2435 static bool run_fdsesstest(int dummy)
2437 struct cli_state *cli;
2442 const char *fname = "\\fdsess.tst";
2443 const char *fname1 = "\\fdsess1.tst";
2449 if (!torture_open_connection(&cli, 0))
2451 cli_sockopt(cli, sockops);
2453 if (!torture_cli_session_setup2(cli, &new_vuid))
2456 saved_cnum = cli->cnum;
2457 if (!NT_STATUS_IS_OK(cli_tcon_andx(cli, share, "?????", "", 1)))
2459 new_cnum = cli->cnum;
2460 cli->cnum = saved_cnum;
2462 printf("starting fdsesstest\n");
2464 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
2465 cli_unlink(cli, fname1, aSYSTEM | aHIDDEN);
2467 if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
2468 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
2472 if (cli_write(cli, fnum1, 0, "hello world\n", 0, 13) != 13) {
2473 printf("write failed (%s)\n", cli_errstr(cli));
2477 saved_vuid = cli->vuid;
2478 cli->vuid = new_vuid;
2480 if (cli_read(cli, fnum1, buf, 0, 13) == 13) {
2481 printf("read succeeded with different vuid! nasty security hole [%s]\n",
2485 /* Try to open a file with different vuid, samba cnum. */
2486 if (NT_STATUS_IS_OK(cli_open(cli, fname1, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum2))) {
2487 printf("create with different vuid, same cnum succeeded.\n");
2488 cli_close(cli, fnum2);
2489 cli_unlink(cli, fname1, aSYSTEM | aHIDDEN);
2491 printf("create with different vuid, same cnum failed.\n");
2492 printf("This will cause problems with service clients.\n");
2496 cli->vuid = saved_vuid;
2498 /* Try with same vuid, different cnum. */
2499 cli->cnum = new_cnum;
2501 if (cli_read(cli, fnum1, buf, 0, 13) == 13) {
2502 printf("read succeeded with different cnum![%s]\n",
2507 cli->cnum = saved_cnum;
2508 cli_close(cli, fnum1);
2509 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
2511 torture_close_connection(cli);
2513 printf("finished fdsesstest\n");
2518 This test checks that
2520 1) the server does not allow an unlink on a file that is open
2522 static bool run_unlinktest(int dummy)
2524 struct cli_state *cli;
2525 const char *fname = "\\unlink.tst";
2527 bool correct = True;
2529 if (!torture_open_connection(&cli, 0)) {
2533 cli_sockopt(cli, sockops);
2535 printf("starting unlink test\n");
2537 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
2541 if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum))) {
2542 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
2546 if (NT_STATUS_IS_OK(cli_unlink(cli, fname, aSYSTEM | aHIDDEN))) {
2547 printf("error: server allowed unlink on an open file\n");
2550 correct = check_error(__LINE__, cli, ERRDOS, ERRbadshare,
2551 NT_STATUS_SHARING_VIOLATION);
2554 cli_close(cli, fnum);
2555 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
2557 if (!torture_close_connection(cli)) {
2561 printf("unlink test finished\n");
2568 test how many open files this server supports on the one socket
2570 static bool run_maxfidtest(int dummy)
2572 struct cli_state *cli;
2573 const char *ftemplate = "\\maxfid.%d.%d";
2575 uint16_t fnums[0x11000];
2578 bool correct = True;
2583 printf("failed to connect\n");
2587 cli_sockopt(cli, sockops);
2589 for (i=0; i<0x11000; i++) {
2590 slprintf(fname,sizeof(fname)-1,ftemplate, i,(int)getpid());
2591 if (!NT_STATUS_IS_OK(cli_open(cli, fname,
2592 O_RDWR|O_CREAT|O_TRUNC, DENY_NONE, &fnums[i]))) {
2593 printf("open of %s failed (%s)\n",
2594 fname, cli_errstr(cli));
2595 printf("maximum fnum is %d\n", i);
2603 printf("cleaning up\n");
2605 slprintf(fname,sizeof(fname)-1,ftemplate, i,(int)getpid());
2606 cli_close(cli, fnums[i]);
2607 if (!NT_STATUS_IS_OK(cli_unlink(cli, fname, aSYSTEM | aHIDDEN))) {
2608 printf("unlink of %s failed (%s)\n",
2609 fname, cli_errstr(cli));
2616 printf("maxfid test finished\n");
2617 if (!torture_close_connection(cli)) {
2623 /* generate a random buffer */
2624 static void rand_buf(char *buf, int len)
2627 *buf = (char)sys_random();
2632 /* send smb negprot commands, not reading the response */
2633 static bool run_negprot_nowait(int dummy)
2636 static struct cli_state *cli;
2637 bool correct = True;
2639 printf("starting negprot nowait test\n");
2641 if (!(cli = open_nbt_connection())) {
2645 for (i=0;i<50000;i++) {
2646 cli_negprot_sendsync(cli);
2649 if (!torture_close_connection(cli)) {
2653 printf("finished negprot nowait test\n");
2659 /* send random IPC commands */
2660 static bool run_randomipc(int dummy)
2662 char *rparam = NULL;
2664 unsigned int rdrcnt,rprcnt;
2666 int api, param_len, i;
2667 struct cli_state *cli;
2668 bool correct = True;
2671 printf("starting random ipc test\n");
2673 if (!torture_open_connection(&cli, 0)) {
2677 for (i=0;i<count;i++) {
2678 api = sys_random() % 500;
2679 param_len = (sys_random() % 64);
2681 rand_buf(param, param_len);
2686 param, param_len, 8,
2687 NULL, 0, BUFFER_SIZE,
2691 printf("%d/%d\r", i,count);
2694 printf("%d/%d\n", i, count);
2696 if (!torture_close_connection(cli)) {
2700 printf("finished random ipc test\n");
2707 static void browse_callback(const char *sname, uint32 stype,
2708 const char *comment, void *state)
2710 printf("\t%20.20s %08x %s\n", sname, stype, comment);
2716 This test checks the browse list code
2719 static bool run_browsetest(int dummy)
2721 static struct cli_state *cli;
2722 bool correct = True;
2724 printf("starting browse test\n");
2726 if (!torture_open_connection(&cli, 0)) {
2730 printf("domain list:\n");
2731 cli_NetServerEnum(cli, cli->server_domain,
2732 SV_TYPE_DOMAIN_ENUM,
2733 browse_callback, NULL);
2735 printf("machine list:\n");
2736 cli_NetServerEnum(cli, cli->server_domain,
2738 browse_callback, NULL);
2740 if (!torture_close_connection(cli)) {
2744 printf("browse test finished\n");
2752 This checks how the getatr calls works
2754 static bool run_attrtest(int dummy)
2756 struct cli_state *cli;
2759 const char *fname = "\\attrib123456789.tst";
2760 bool correct = True;
2762 printf("starting attrib test\n");
2764 if (!torture_open_connection(&cli, 0)) {
2768 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
2769 cli_open(cli, fname,
2770 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
2771 cli_close(cli, fnum);
2772 if (!NT_STATUS_IS_OK(cli_getatr(cli, fname, NULL, NULL, &t))) {
2773 printf("getatr failed (%s)\n", cli_errstr(cli));
2777 if (abs(t - time(NULL)) > 60*60*24*10) {
2778 printf("ERROR: SMBgetatr bug. time is %s",
2784 t2 = t-60*60*24; /* 1 day ago */
2786 if (!NT_STATUS_IS_OK(cli_setatr(cli, fname, 0, t2))) {
2787 printf("setatr failed (%s)\n", cli_errstr(cli));
2791 if (!NT_STATUS_IS_OK(cli_getatr(cli, fname, NULL, NULL, &t))) {
2792 printf("getatr failed (%s)\n", cli_errstr(cli));
2797 printf("ERROR: getatr/setatr bug. times are\n%s",
2799 printf("%s", ctime(&t2));
2803 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
2805 if (!torture_close_connection(cli)) {
2809 printf("attrib test finished\n");
2816 This checks a couple of trans2 calls
2818 static bool run_trans2test(int dummy)
2820 struct cli_state *cli;
2823 time_t c_time, a_time, m_time;
2824 struct timespec c_time_ts, a_time_ts, m_time_ts, w_time_ts, m_time2_ts;
2825 const char *fname = "\\trans2.tst";
2826 const char *dname = "\\trans2";
2827 const char *fname2 = "\\trans2\\trans2.tst";
2829 bool correct = True;
2833 printf("starting trans2 test\n");
2835 if (!torture_open_connection(&cli, 0)) {
2839 status = cli_get_fs_attr_info(cli, &fs_attr);
2840 if (!NT_STATUS_IS_OK(status)) {
2841 printf("ERROR: cli_get_fs_attr_info returned %s\n",
2846 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
2847 cli_open(cli, fname,
2848 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
2849 if (!cli_qfileinfo(cli, fnum, NULL, &size, &c_time_ts, &a_time_ts, &w_time_ts,
2850 &m_time_ts, NULL)) {
2851 printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(cli));
2855 if (!cli_qfilename(cli, fnum, pname, sizeof(pname))) {
2856 printf("ERROR: qfilename failed (%s)\n", cli_errstr(cli));
2860 if (strcmp(pname, fname)) {
2861 printf("qfilename gave different name? [%s] [%s]\n",
2866 cli_close(cli, fnum);
2870 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
2871 if (!NT_STATUS_IS_OK(cli_open(cli, fname,
2872 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum))) {
2873 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
2876 cli_close(cli, fnum);
2878 if (!cli_qpathinfo(cli, fname, &c_time, &a_time, &m_time, &size, NULL)) {
2879 printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(cli));
2882 if (c_time != m_time) {
2883 printf("create time=%s", ctime(&c_time));
2884 printf("modify time=%s", ctime(&m_time));
2885 printf("This system appears to have sticky create times\n");
2887 if (a_time % (60*60) == 0) {
2888 printf("access time=%s", ctime(&a_time));
2889 printf("This system appears to set a midnight access time\n");
2893 if (abs(m_time - time(NULL)) > 60*60*24*7) {
2894 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
2900 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
2901 cli_open(cli, fname,
2902 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
2903 cli_close(cli, fnum);
2904 if (!cli_qpathinfo2(cli, fname, &c_time_ts, &a_time_ts, &w_time_ts,
2905 &m_time_ts, &size, NULL, NULL)) {
2906 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2909 if (w_time_ts.tv_sec < 60*60*24*2) {
2910 printf("write time=%s", ctime(&w_time_ts.tv_sec));
2911 printf("This system appears to set a initial 0 write time\n");
2916 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
2919 /* check if the server updates the directory modification time
2920 when creating a new file */
2921 if (!NT_STATUS_IS_OK(cli_mkdir(cli, dname))) {
2922 printf("ERROR: mkdir failed (%s)\n", cli_errstr(cli));
2926 if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts, &w_time_ts,
2927 &m_time_ts, &size, NULL, NULL)) {
2928 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2932 cli_open(cli, fname2,
2933 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
2934 cli_write(cli, fnum, 0, (char *)&fnum, 0, sizeof(fnum));
2935 cli_close(cli, fnum);
2936 if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts, &w_time_ts,
2937 &m_time2_ts, &size, NULL, NULL)) {
2938 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2941 if (memcmp(&m_time_ts, &m_time2_ts, sizeof(struct timespec))
2943 printf("This system does not update directory modification times\n");
2947 cli_unlink(cli, fname2, aSYSTEM | aHIDDEN);
2948 cli_rmdir(cli, dname);
2950 if (!torture_close_connection(cli)) {
2954 printf("trans2 test finished\n");
2960 This checks new W2K calls.
2963 static bool new_trans(struct cli_state *pcli, int fnum, int level)
2967 bool correct = True;
2969 if (!cli_qfileinfo_test(pcli, fnum, level, &buf, &len)) {
2970 printf("ERROR: qfileinfo (%d) failed (%s)\n", level, cli_errstr(pcli));
2973 printf("qfileinfo: level %d, len = %u\n", level, len);
2974 dump_data(0, (uint8 *)buf, len);
2981 static bool run_w2ktest(int dummy)
2983 struct cli_state *cli;
2985 const char *fname = "\\w2ktest\\w2k.tst";
2987 bool correct = True;
2989 printf("starting w2k test\n");
2991 if (!torture_open_connection(&cli, 0)) {
2995 cli_open(cli, fname,
2996 O_RDWR | O_CREAT , DENY_NONE, &fnum);
2998 for (level = 1004; level < 1040; level++) {
2999 new_trans(cli, fnum, level);
3002 cli_close(cli, fnum);
3004 if (!torture_close_connection(cli)) {
3008 printf("w2k test finished\n");
3015 this is a harness for some oplock tests
3017 static bool run_oplock1(int dummy)
3019 struct cli_state *cli1;
3020 const char *fname = "\\lockt1.lck";
3022 bool correct = True;
3024 printf("starting oplock test 1\n");
3026 if (!torture_open_connection(&cli1, 0)) {
3030 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3032 cli_sockopt(cli1, sockops);
3034 cli1->use_oplocks = True;
3036 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
3037 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
3041 cli1->use_oplocks = False;
3043 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3044 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3046 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3047 printf("close2 failed (%s)\n", cli_errstr(cli1));
3051 if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname, aSYSTEM | aHIDDEN))) {
3052 printf("unlink failed (%s)\n", cli_errstr(cli1));
3056 if (!torture_close_connection(cli1)) {
3060 printf("finished oplock test 1\n");
3065 static bool run_oplock2(int dummy)
3067 struct cli_state *cli1, *cli2;
3068 const char *fname = "\\lockt2.lck";
3069 uint16_t fnum1, fnum2;
3070 int saved_use_oplocks = use_oplocks;
3072 bool correct = True;
3073 volatile bool *shared_correct;
3075 shared_correct = (volatile bool *)shm_setup(sizeof(bool));
3076 *shared_correct = True;
3078 use_level_II_oplocks = True;
3081 printf("starting oplock test 2\n");
3083 if (!torture_open_connection(&cli1, 0)) {
3084 use_level_II_oplocks = False;
3085 use_oplocks = saved_use_oplocks;
3089 cli1->use_oplocks = True;
3090 cli1->use_level_II_oplocks = True;
3092 if (!torture_open_connection(&cli2, 1)) {
3093 use_level_II_oplocks = False;
3094 use_oplocks = saved_use_oplocks;
3098 cli2->use_oplocks = True;
3099 cli2->use_level_II_oplocks = True;
3101 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3103 cli_sockopt(cli1, sockops);
3104 cli_sockopt(cli2, sockops);
3106 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
3107 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
3111 /* Don't need the globals any more. */
3112 use_level_II_oplocks = False;
3113 use_oplocks = saved_use_oplocks;
3117 if (!NT_STATUS_IS_OK(cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2))) {
3118 printf("second open of %s failed (%s)\n", fname, cli_errstr(cli1));
3119 *shared_correct = False;
3125 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
3126 printf("close2 failed (%s)\n", cli_errstr(cli1));
3127 *shared_correct = False;
3135 /* Ensure cli1 processes the break. Empty file should always return 0
3138 if (cli_read(cli1, fnum1, buf, 0, 4) != 0) {
3139 printf("read on fnum1 failed (%s)\n", cli_errstr(cli1));
3143 /* Should now be at level II. */
3144 /* Test if sending a write locks causes a break to none. */
3146 if (!cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK)) {
3147 printf("lock failed (%s)\n", cli_errstr(cli1));
3151 cli_unlock(cli1, fnum1, 0, 4);
3155 if (!cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
3156 printf("lock failed (%s)\n", cli_errstr(cli1));
3160 cli_unlock(cli1, fnum1, 0, 4);
3164 cli_read(cli1, fnum1, buf, 0, 4);
3167 if (cli_write(cli1, fnum1, 0, buf, 0, 4) != 4) {
3168 printf("write on fnum1 failed (%s)\n", cli_errstr(cli1));
3173 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3174 printf("close1 failed (%s)\n", cli_errstr(cli1));
3180 if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname, aSYSTEM | aHIDDEN))) {
3181 printf("unlink failed (%s)\n", cli_errstr(cli1));
3185 if (!torture_close_connection(cli1)) {
3189 if (!*shared_correct) {
3193 printf("finished oplock test 2\n");
3198 /* handler for oplock 3 tests */
3199 static NTSTATUS oplock3_handler(struct cli_state *cli, uint16_t fnum, unsigned char level)
3201 printf("got oplock break fnum=%d level=%d\n",
3203 return cli_oplock_ack(cli, fnum, level);
3206 static bool run_oplock3(int dummy)
3208 struct cli_state *cli;
3209 const char *fname = "\\oplockt3.dat";
3211 char buf[4] = "abcd";
3212 bool correct = True;
3213 volatile bool *shared_correct;
3215 shared_correct = (volatile bool *)shm_setup(sizeof(bool));
3216 *shared_correct = True;
3218 printf("starting oplock test 3\n");
3223 use_level_II_oplocks = True;
3224 if (!torture_open_connection(&cli, 0)) {
3225 *shared_correct = False;
3229 /* try to trigger a oplock break in parent */
3230 cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum);
3231 cli_write(cli, fnum, 0, buf, 0, 4);
3237 use_level_II_oplocks = True;
3238 if (!torture_open_connection(&cli, 1)) { /* other is forked */
3241 cli_oplock_handler(cli, oplock3_handler);
3242 cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum);
3243 cli_write(cli, fnum, 0, buf, 0, 4);
3244 cli_close(cli, fnum);
3245 cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum);
3246 cli->timeout = 20000;
3247 cli_receive_smb(cli);
3248 printf("finished oplock test 3\n");
3250 return (correct && *shared_correct);
3252 /* What are we looking for here? What's sucess and what's FAILURE? */
3258 Test delete on close semantics.
3260 static bool run_deletetest(int dummy)
3262 struct cli_state *cli1 = NULL;
3263 struct cli_state *cli2 = NULL;
3264 const char *fname = "\\delete.file";
3265 uint16_t fnum1 = (uint16_t)-1;
3266 uint16_t fnum2 = (uint16_t)-1;
3267 bool correct = True;
3269 printf("starting delete test\n");
3271 if (!torture_open_connection(&cli1, 0)) {
3275 cli_sockopt(cli1, sockops);
3277 /* Test 1 - this should delete the file on close. */
3279 cli_setatr(cli1, fname, 0, 0);
3280 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3282 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
3283 0, FILE_OVERWRITE_IF,
3284 FILE_DELETE_ON_CLOSE, 0, &fnum1))) {
3285 printf("[1] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3292 uint32 *accinfo = NULL;
3294 cli_qfileinfo_test(cli1, fnum1, SMB_FILE_ACCESS_INFORMATION, (char **)&accinfo, &len);
3296 printf("access mode = 0x%lx\n", *accinfo);
3301 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3302 printf("[1] close failed (%s)\n", cli_errstr(cli1));
3307 if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1))) {
3308 printf("[1] open of %s succeeded (should fail)\n", fname);
3313 printf("first delete on close test succeeded.\n");
3315 /* Test 2 - this should delete the file on close. */
3317 cli_setatr(cli1, fname, 0, 0);
3318 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3320 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS,
3321 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
3322 FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3323 printf("[2] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3328 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
3329 printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
3334 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3335 printf("[2] close failed (%s)\n", cli_errstr(cli1));
3340 if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
3341 printf("[2] open of %s succeeded should have been deleted on close !\n", fname);
3342 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3343 printf("[2] close failed (%s)\n", cli_errstr(cli1));
3347 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3349 printf("second delete on close test succeeded.\n");
3352 cli_setatr(cli1, fname, 0, 0);
3353 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3355 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
3356 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3357 printf("[3] open - 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3362 /* This should fail with a sharing violation - open for delete is only compatible
3363 with SHARE_DELETE. */
3365 if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3366 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0, 0, &fnum2))) {
3367 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname);
3372 /* This should succeed. */
3374 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3375 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0, 0, &fnum2))) {
3376 printf("[3] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
3381 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
3382 printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
3387 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3388 printf("[3] close 1 failed (%s)\n", cli_errstr(cli1));
3393 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum2))) {
3394 printf("[3] close 2 failed (%s)\n", cli_errstr(cli1));
3399 /* This should fail - file should no longer be there. */
3401 if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
3402 printf("[3] open of %s succeeded should have been deleted on close !\n", fname);
3403 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3404 printf("[3] close failed (%s)\n", cli_errstr(cli1));
3406 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3410 printf("third delete on close test succeeded.\n");
3413 cli_setatr(cli1, fname, 0, 0);
3414 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3416 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3417 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3418 printf("[4] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3423 /* This should succeed. */
3424 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
3425 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0, 0, &fnum2))) {
3426 printf("[4] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
3431 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum2))) {
3432 printf("[4] close - 1 failed (%s)\n", cli_errstr(cli1));
3437 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
3438 printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
3443 /* This should fail - no more opens once delete on close set. */
3444 if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
3445 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3446 FILE_OPEN, 0, 0, &fnum2))) {
3447 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname );
3451 printf("fourth delete on close test succeeded.\n");
3453 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3454 printf("[4] close - 2 failed (%s)\n", cli_errstr(cli1));
3460 cli_setatr(cli1, fname, 0, 0);
3461 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3463 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum1))) {
3464 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3469 /* This should fail - only allowed on NT opens with DELETE access. */
3471 if (NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
3472 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
3477 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3478 printf("[5] close - 2 failed (%s)\n", cli_errstr(cli1));
3483 printf("fifth delete on close test succeeded.\n");
3486 cli_setatr(cli1, fname, 0, 0);
3487 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3489 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
3490 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3491 FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3492 printf("[6] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3497 /* This should fail - only allowed on NT opens with DELETE access. */
3499 if (NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
3500 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
3505 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3506 printf("[6] close - 2 failed (%s)\n", cli_errstr(cli1));
3511 printf("sixth delete on close test succeeded.\n");
3514 cli_setatr(cli1, fname, 0, 0);
3515 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3517 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3518 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3519 printf("[7] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3524 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
3525 printf("[7] setting delete_on_close on file failed !\n");
3530 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, false))) {
3531 printf("[7] unsetting delete_on_close on file failed !\n");
3536 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3537 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
3542 /* This next open should succeed - we reset the flag. */
3544 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
3545 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3550 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3551 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
3556 printf("seventh delete on close test succeeded.\n");
3559 cli_setatr(cli1, fname, 0, 0);
3560 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3562 if (!torture_open_connection(&cli2, 1)) {
3563 printf("[8] failed to open second connection.\n");
3568 cli_sockopt(cli1, sockops);
3570 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3571 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3572 FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3573 printf("[8] open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3578 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3579 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3580 FILE_OPEN, 0, 0, &fnum2))) {
3581 printf("[8] open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3586 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
3587 printf("[8] setting delete_on_close on file failed !\n");
3592 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3593 printf("[8] close - 1 failed (%s)\n", cli_errstr(cli1));
3598 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
3599 printf("[8] close - 2 failed (%s)\n", cli_errstr(cli2));
3604 /* This should fail.. */
3605 if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
3606 printf("[8] open of %s succeeded should have been deleted on close !\n", fname);
3610 printf("eighth delete on close test succeeded.\n");
3612 /* This should fail - we need to set DELETE_ACCESS. */
3613 if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0,FILE_READ_DATA|FILE_WRITE_DATA,
3614 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, 0, &fnum1))) {
3615 printf("[9] open of %s succeeded should have failed!\n", fname);
3620 printf("ninth delete on close test succeeded.\n");
3622 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3623 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, 0, &fnum1))) {
3624 printf("[10] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3629 /* This should delete the file. */
3630 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3631 printf("[10] close failed (%s)\n", cli_errstr(cli1));
3636 /* This should fail.. */
3637 if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
3638 printf("[10] open of %s succeeded should have been deleted on close !\n", fname);
3642 printf("tenth delete on close test succeeded.\n");
3644 cli_setatr(cli1, fname, 0, 0);
3645 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3647 /* What error do we get when attempting to open a read-only file with
3650 /* Create a readonly file. */
3651 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
3652 FILE_ATTRIBUTE_READONLY, FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3653 printf("[11] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3658 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3659 printf("[11] close failed (%s)\n", cli_errstr(cli1));
3664 /* Now try open for delete access. */
3665 if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES|DELETE_ACCESS,
3666 0, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3667 FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3668 printf("[11] open of %s succeeded should have been denied with ACCESS_DENIED!\n", fname);
3669 cli_close(cli1, fnum1);
3673 NTSTATUS nterr = cli_nt_error(cli1);
3674 if (!NT_STATUS_EQUAL(nterr,NT_STATUS_ACCESS_DENIED)) {
3675 printf("[11] open of %s should have been denied with ACCESS_DENIED! Got error %s\n", fname, nt_errstr(nterr));
3679 printf("eleventh delete on close test succeeded.\n");
3683 printf("finished delete test\n");
3686 /* FIXME: This will crash if we aborted before cli2 got
3687 * intialized, because these functions don't handle
3688 * uninitialized connections. */
3690 if (fnum1 != (uint16_t)-1) cli_close(cli1, fnum1);
3691 if (fnum2 != (uint16_t)-1) cli_close(cli1, fnum2);
3692 cli_setatr(cli1, fname, 0, 0);
3693 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3695 if (cli1 && !torture_close_connection(cli1)) {
3698 if (cli2 && !torture_close_connection(cli2)) {
3706 print out server properties
3708 static bool run_properties(int dummy)
3710 struct cli_state *cli;
3711 bool correct = True;
3713 printf("starting properties test\n");
3717 if (!torture_open_connection(&cli, 0)) {
3721 cli_sockopt(cli, sockops);
3723 d_printf("Capabilities 0x%08x\n", cli->capabilities);
3725 if (!torture_close_connection(cli)) {
3734 /* FIRST_DESIRED_ACCESS 0xf019f */
3735 #define FIRST_DESIRED_ACCESS FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|\
3736 FILE_READ_EA| /* 0xf */ \
3737 FILE_WRITE_EA|FILE_READ_ATTRIBUTES| /* 0x90 */ \
3738 FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
3739 DELETE_ACCESS|READ_CONTROL_ACCESS|\
3740 WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS /* 0xf0000 */
3741 /* SECOND_DESIRED_ACCESS 0xe0080 */
3742 #define SECOND_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
3743 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
3744 WRITE_OWNER_ACCESS /* 0xe0000 */
3747 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
3748 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
3750 WRITE_OWNER_ACCESS /* */
3754 Test ntcreate calls made by xcopy
3756 static bool run_xcopy(int dummy)
3758 static struct cli_state *cli1;
3759 const char *fname = "\\test.txt";
3760 bool correct = True;
3761 uint16_t fnum1, fnum2;
3763 printf("starting xcopy test\n");
3765 if (!torture_open_connection(&cli1, 0)) {
3769 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0,
3770 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
3771 FILE_SHARE_NONE, FILE_OVERWRITE_IF,
3772 0x4044, 0, &fnum1))) {
3773 printf("First open failed - %s\n", cli_errstr(cli1));
3777 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0,
3778 SECOND_DESIRED_ACCESS, 0,
3779 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN,
3780 0x200000, 0, &fnum2))) {
3781 printf("second open failed - %s\n", cli_errstr(cli1));
3785 if (!torture_close_connection(cli1)) {
3793 Test rename on files open with share delete and no share delete.
3795 static bool run_rename(int dummy)
3797 static struct cli_state *cli1;
3798 const char *fname = "\\test.txt";
3799 const char *fname1 = "\\test1.txt";
3800 bool correct = True;
3804 printf("starting rename test\n");
3806 if (!torture_open_connection(&cli1, 0)) {
3810 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3811 cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
3812 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3813 FILE_SHARE_READ, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3814 printf("First open failed - %s\n", cli_errstr(cli1));
3818 if (!NT_STATUS_IS_OK(cli_rename(cli1, fname, fname1))) {
3819 printf("First rename failed (SHARE_READ) (this is correct) - %s\n", cli_errstr(cli1));
3821 printf("First rename succeeded (SHARE_READ) - this should have failed !\n");
3825 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3826 printf("close - 1 failed (%s)\n", cli_errstr(cli1));
3830 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3831 cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
3832 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3834 FILE_SHARE_DELETE|FILE_SHARE_NONE,
3836 FILE_SHARE_DELETE|FILE_SHARE_READ,
3838 FILE_OVERWRITE_IF, 0, 0, &fnum1);
3839 if (!NT_STATUS_IS_OK(status)) {
3840 printf("Second open failed - %s\n", cli_errstr(cli1));
3844 if (!NT_STATUS_IS_OK(cli_rename(cli1, fname, fname1))) {
3845 printf("Second rename failed (SHARE_DELETE | SHARE_READ) - this should have succeeded - %s\n", cli_errstr(cli1));
3848 printf("Second rename succeeded (SHARE_DELETE | SHARE_READ)\n");
3851 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3852 printf("close - 2 failed (%s)\n", cli_errstr(cli1));
3856 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3857 cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
3859 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, READ_CONTROL_ACCESS, FILE_ATTRIBUTE_NORMAL,
3860 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3861 printf("Third open failed - %s\n", cli_errstr(cli1));
3870 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
3871 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum2))) {
3872 printf("Fourth open failed - %s\n", cli_errstr(cli1));
3875 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum2, true))) {
3876 printf("[8] setting delete_on_close on file failed !\n");
3880 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum2))) {
3881 printf("close - 4 failed (%s)\n", cli_errstr(cli1));
3887 if (!NT_STATUS_IS_OK(cli_rename(cli1, fname, fname1))) {
3888 printf("Third rename failed (SHARE_NONE) - this should have succeeded - %s\n", cli_errstr(cli1));
3891 printf("Third rename succeeded (SHARE_NONE)\n");
3894 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3895 printf("close - 3 failed (%s)\n", cli_errstr(cli1));
3899 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3900 cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
3904 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3905 FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3906 printf("Fourth open failed - %s\n", cli_errstr(cli1));
3910 if (!NT_STATUS_IS_OK(cli_rename(cli1, fname, fname1))) {
3911 printf("Fourth rename failed (SHARE_READ | SHARE_WRITE) (this is correct) - %s\n", cli_errstr(cli1));
3913 printf("Fourth rename succeeded (SHARE_READ | SHARE_WRITE) - this should have failed !\n");
3917 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3918 printf("close - 4 failed (%s)\n", cli_errstr(cli1));
3922 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3923 cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
3927 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3928 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3929 printf("Fifth open failed - %s\n", cli_errstr(cli1));
3933 if (!NT_STATUS_IS_OK(cli_rename(cli1, fname, fname1))) {
3934 printf("Fifth rename failed (SHARE_READ | SHARE_WRITE | SHARE_DELETE) - this should have succeeded - %s ! \n",
3938 printf("Fifth rename succeeded (SHARE_READ | SHARE_WRITE | SHARE_DELETE) (this is correct) - %s\n", cli_errstr(cli1));
3942 * Now check if the first name still exists ...
3945 /* if (!NT_STATUS_OP(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3946 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0, &fnum2))) {
3947 printf("Opening original file after rename of open file fails: %s\n",
3951 printf("Opening original file after rename of open file works ...\n");
3952 (void)cli_close(cli1, fnum2);
3958 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3959 printf("close - 5 failed (%s)\n", cli_errstr(cli1));
3963 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3964 cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
3966 if (!torture_close_connection(cli1)) {
3973 static bool run_pipe_number(int dummy)
3975 struct cli_state *cli1;
3976 const char *pipe_name = "\\SPOOLSS";
3980 printf("starting pipenumber test\n");
3981 if (!torture_open_connection(&cli1, 0)) {
3985 cli_sockopt(cli1, sockops);
3987 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, pipe_name, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
3988 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN_IF, 0, 0, &fnum))) {
3989 printf("Open of pipe %s failed with error (%s)\n", pipe_name, cli_errstr(cli1));
3993 printf("\r%6d", num_pipes);
3996 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes, pipe_name );
3997 torture_close_connection(cli1);
4002 Test open mode returns on read-only files.
4004 static bool run_opentest(int dummy)
4006 static struct cli_state *cli1;
4007 static struct cli_state *cli2;
4008 const char *fname = "\\readonly.file";
4009 uint16_t fnum1, fnum2;
4012 bool correct = True;
4015 printf("starting open test\n");
4017 if (!torture_open_connection(&cli1, 0)) {
4021 cli_setatr(cli1, fname, 0, 0);
4022 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
4024 cli_sockopt(cli1, sockops);
4026 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
4027 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
4031 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4032 printf("close2 failed (%s)\n", cli_errstr(cli1));
4036 if (!NT_STATUS_IS_OK(cli_setatr(cli1, fname, aRONLY, 0))) {
4037 printf("cli_setatr failed (%s)\n", cli_errstr(cli1));
4041 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_WRITE, &fnum1))) {
4042 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
4046 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
4047 cli_open(cli1, fname, O_RDWR, DENY_ALL, &fnum2);
4049 if (check_error(__LINE__, cli1, ERRDOS, ERRnoaccess,
4050 NT_STATUS_ACCESS_DENIED)) {
4051 printf("correct error code ERRDOS/ERRnoaccess returned\n");
4054 printf("finished open test 1\n");
4056 cli_close(cli1, fnum1);
4058 /* Now try not readonly and ensure ERRbadshare is returned. */
4060 cli_setatr(cli1, fname, 0, 0);
4062 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_WRITE, &fnum1))) {
4063 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
4067 /* This will fail - but the error should be ERRshare. */
4068 cli_open(cli1, fname, O_RDWR, DENY_ALL, &fnum2);
4070 if (check_error(__LINE__, cli1, ERRDOS, ERRbadshare,
4071 NT_STATUS_SHARING_VIOLATION)) {
4072 printf("correct error code ERRDOS/ERRbadshare returned\n");
4075 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4076 printf("close2 failed (%s)\n", cli_errstr(cli1));
4080 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
4082 printf("finished open test 2\n");
4084 /* Test truncate open disposition on file opened for read. */
4086 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
4087 printf("(3) open (1) of %s failed (%s)\n", fname, cli_errstr(cli1));
4091 /* write 20 bytes. */
4093 memset(buf, '\0', 20);
4095 if (cli_write(cli1, fnum1, 0, buf, 0, 20) != 20) {
4096 printf("write failed (%s)\n", cli_errstr(cli1));
4100 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4101 printf("(3) close1 failed (%s)\n", cli_errstr(cli1));
4105 /* Ensure size == 20. */
4106 if (!NT_STATUS_IS_OK(cli_getatr(cli1, fname, NULL, &fsize, NULL))) {
4107 printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
4112 printf("(3) file size != 20\n");
4116 /* Now test if we can truncate a file opened for readonly. */
4118 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE, &fnum1))) {
4119 printf("(3) open (2) of %s failed (%s)\n", fname, cli_errstr(cli1));
4123 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4124 printf("close2 failed (%s)\n", cli_errstr(cli1));
4128 /* Ensure size == 0. */
4129 if (!NT_STATUS_IS_OK(cli_getatr(cli1, fname, NULL, &fsize, NULL))) {
4130 printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
4135 printf("(3) file size != 0\n");
4138 printf("finished open test 3\n");
4140 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
4143 printf("testing ctemp\n");
4144 if (!NT_STATUS_IS_OK(cli_ctemp(cli1, talloc_tos(), "\\", &fnum1, &tmp_path))) {
4145 printf("ctemp failed (%s)\n", cli_errstr(cli1));
4148 printf("ctemp gave path %s\n", tmp_path);
4149 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4150 printf("close of temp failed (%s)\n", cli_errstr(cli1));
4152 if (!NT_STATUS_IS_OK(cli_unlink(cli1, tmp_path, aSYSTEM | aHIDDEN))) {
4153 printf("unlink of temp failed (%s)\n", cli_errstr(cli1));
4156 /* Test the non-io opens... */
4158 if (!torture_open_connection(&cli2, 1)) {
4162 cli_setatr(cli2, fname, 0, 0);
4163 cli_unlink(cli2, fname, aSYSTEM | aHIDDEN);
4165 cli_sockopt(cli2, sockops);
4167 printf("TEST #1 testing 2 non-io opens (no delete)\n");
4169 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4170 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
4171 printf("test 1 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4175 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4176 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0, &fnum2))) {
4177 printf("test 1 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4181 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4182 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4185 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
4186 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4190 printf("non-io open test #1 passed.\n");
4192 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
4194 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
4196 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4197 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
4198 printf("test 2 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4202 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4203 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0, &fnum2))) {
4204 printf("test 2 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4208 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4209 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4212 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
4213 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
4217 printf("non-io open test #2 passed.\n");
4219 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
4221 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
4223 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4224 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
4225 printf("test 3 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4229 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4230 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0, &fnum2))) {
4231 printf("test 3 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4235 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4236 printf("test 3 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4239 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
4240 printf("test 3 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4244 printf("non-io open test #3 passed.\n");
4246 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
4248 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
4250 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4251 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
4252 printf("test 4 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4256 if (NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4257 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0, &fnum2))) {
4258 printf("test 4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
4262 printf("test 3 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
4264 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4265 printf("test 4 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4269 printf("non-io open test #4 passed.\n");
4271 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
4273 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
4275 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4276 FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
4277 printf("test 5 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4281 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4282 FILE_SHARE_DELETE, FILE_OPEN_IF, 0, 0, &fnum2))) {
4283 printf("test 5 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4287 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4288 printf("test 5 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4292 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
4293 printf("test 5 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4297 printf("non-io open test #5 passed.\n");
4299 printf("TEST #6 testing 1 non-io open, one io open\n");
4301 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
4303 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
4304 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
4305 printf("test 6 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4309 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4310 FILE_SHARE_READ, FILE_OPEN_IF, 0, 0, &fnum2))) {
4311 printf("test 6 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4315 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4316 printf("test 6 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4320 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
4321 printf("test 6 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4325 printf("non-io open test #6 passed.\n");
4327 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
4329 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
4331 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
4332 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
4333 printf("test 7 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4337 if (NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4338 FILE_SHARE_READ|FILE_SHARE_DELETE, FILE_OPEN_IF, 0, 0, &fnum2))) {
4339 printf("test 7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
4343 printf("test 7 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
4345 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4346 printf("test 7 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4350 printf("non-io open test #7 passed.\n");
4352 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
4354 if (!torture_close_connection(cli1)) {
4357 if (!torture_close_connection(cli2)) {
4365 Test POSIX open /mkdir calls.
4367 static bool run_simple_posix_open_test(int dummy)
4369 static struct cli_state *cli1;
4370 const char *fname = "posix:file";
4371 const char *hname = "posix:hlink";
4372 const char *sname = "posix:symlink";
4373 const char *dname = "posix:dir";
4376 uint16 major, minor;
4377 uint32 caplow, caphigh;
4378 uint16_t fnum1 = (uint16_t)-1;
4379 SMB_STRUCT_STAT sbuf;
4380 bool correct = false;
4383 printf("Starting simple POSIX open test\n");
4385 if (!torture_open_connection(&cli1, 0)) {
4389 cli_sockopt(cli1, sockops);
4391 if (!SERVER_HAS_UNIX_CIFS(cli1)) {
4392 printf("Server doesn't support UNIX CIFS extensions.\n");
4396 status = cli_unix_extensions_version(cli1, &major, &minor, &caplow,
4398 if (!NT_STATUS_IS_OK(status)) {
4399 printf("Server didn't return UNIX CIFS extensions: %s\n",
4404 status = cli_set_unix_extensions_capabilities(cli1, major, minor,
4406 if (!NT_STATUS_IS_OK(status)) {
4407 printf("Server doesn't support setting UNIX CIFS extensions: "
4408 "%s.\n", nt_errstr(status));
4412 cli_setatr(cli1, fname, 0, 0);
4413 cli_posix_unlink(cli1, fname);
4414 cli_setatr(cli1, dname, 0, 0);
4415 cli_posix_rmdir(cli1, dname);
4416 cli_setatr(cli1, hname, 0, 0);
4417 cli_posix_unlink(cli1, hname);
4418 cli_setatr(cli1, sname, 0, 0);
4419 cli_posix_unlink(cli1, sname);
4421 /* Create a directory. */
4422 if (!NT_STATUS_IS_OK(cli_posix_mkdir(cli1, dname, 0777))) {
4423 printf("POSIX mkdir of %s failed (%s)\n", dname, cli_errstr(cli1));
4427 if (!NT_STATUS_IS_OK(cli_posix_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, 0600, &fnum1))) {
4428 printf("POSIX create of %s failed (%s)\n", fname, cli_errstr(cli1));
4432 /* Test ftruncate - set file size. */
4433 if (!NT_STATUS_IS_OK(cli_ftruncate(cli1, fnum1, 1000))) {
4434 printf("ftruncate failed (%s)\n", cli_errstr(cli1));
4438 /* Ensure st_size == 1000 */
4439 if (!NT_STATUS_IS_OK(cli_posix_stat(cli1, fname, &sbuf))) {
4440 printf("stat failed (%s)\n", cli_errstr(cli1));
4444 if (sbuf.st_ex_size != 1000) {
4445 printf("ftruncate - stat size (%u) != 1000\n", (unsigned int)sbuf.st_ex_size);
4449 /* Test ftruncate - set file size back to zero. */
4450 if (!NT_STATUS_IS_OK(cli_ftruncate(cli1, fnum1, 0))) {
4451 printf("ftruncate failed (%s)\n", cli_errstr(cli1));
4455 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4456 printf("close failed (%s)\n", cli_errstr(cli1));
4460 /* Now open the file again for read only. */
4461 if (!NT_STATUS_IS_OK(cli_posix_open(cli1, fname, O_RDONLY, 0, &fnum1))) {
4462 printf("POSIX open of %s failed (%s)\n", fname, cli_errstr(cli1));
4466 /* Now unlink while open. */
4467 if (!NT_STATUS_IS_OK(cli_posix_unlink(cli1, fname))) {
4468 printf("POSIX unlink of %s failed (%s)\n", fname, cli_errstr(cli1));
4472 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4473 printf("close(2) failed (%s)\n", cli_errstr(cli1));
4477 /* Ensure the file has gone. */
4478 if (NT_STATUS_IS_OK(cli_posix_open(cli1, fname, O_RDONLY, 0, &fnum1))) {
4479 printf("POSIX open of %s succeeded, should have been deleted.\n", fname);
4483 /* What happens when we try and POSIX open a directory ? */
4484 if (NT_STATUS_IS_OK(cli_posix_open(cli1, dname, O_RDONLY, 0, &fnum1))) {
4485 printf("POSIX open of directory %s succeeded, should have failed.\n", fname);
4488 if (!check_error(__LINE__, cli1, ERRDOS, EISDIR,
4489 NT_STATUS_FILE_IS_A_DIRECTORY)) {
4494 /* Create the file. */
4495 if (!NT_STATUS_IS_OK(cli_posix_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, 0600, &fnum1))) {
4496 printf("POSIX create of %s failed (%s)\n", fname, cli_errstr(cli1));
4500 /* Write some data into it. */
4501 if (cli_write(cli1, fnum1, 0, "TEST DATA\n", 0, 10) != 10) {
4502 printf("cli_write failed: %s\n", cli_errstr(cli1));
4506 cli_close(cli1, fnum1);
4508 /* Now create a hardlink. */
4509 if (!NT_STATUS_IS_OK(cli_posix_hardlink(cli1, fname, hname))) {
4510 printf("POSIX hardlink of %s failed (%s)\n", hname, cli_errstr(cli1));
4514 /* Now create a symlink. */
4515 if (!NT_STATUS_IS_OK(cli_posix_symlink(cli1, fname, sname))) {
4516 printf("POSIX symlink of %s failed (%s)\n", sname, cli_errstr(cli1));
4520 /* Open the hardlink for read. */
4521 if (!NT_STATUS_IS_OK(cli_posix_open(cli1, hname, O_RDONLY, 0, &fnum1))) {
4522 printf("POSIX open of %s failed (%s)\n", hname, cli_errstr(cli1));
4526 if (cli_read(cli1, fnum1, buf, 0, 10) != 10) {
4527 printf("POSIX read of %s failed (%s)\n", hname, cli_errstr(cli1));
4531 if (memcmp(buf, "TEST DATA\n", 10)) {
4532 printf("invalid data read from hardlink\n");
4536 /* Do a POSIX lock/unlock. */
4537 if (!NT_STATUS_IS_OK(cli_posix_lock(cli1, fnum1, 0, 100, true, READ_LOCK))) {
4538 printf("POSIX lock failed %s\n", cli_errstr(cli1));
4542 /* Punch a hole in the locked area. */
4543 if (!NT_STATUS_IS_OK(cli_posix_unlock(cli1, fnum1, 10, 80))) {
4544 printf("POSIX unlock failed %s\n", cli_errstr(cli1));
4548 cli_close(cli1, fnum1);
4550 /* Open the symlink for read - this should fail. A POSIX
4551 client should not be doing opens on a symlink. */
4552 if (NT_STATUS_IS_OK(cli_posix_open(cli1, sname, O_RDONLY, 0, &fnum1))) {
4553 printf("POSIX open of %s succeeded (should have failed)\n", sname);
4556 if (!check_error(__LINE__, cli1, ERRDOS, ERRbadpath,
4557 NT_STATUS_OBJECT_PATH_NOT_FOUND)) {
4558 printf("POSIX open of %s should have failed "
4559 "with NT_STATUS_OBJECT_PATH_NOT_FOUND, "
4560 "failed with %s instead.\n",
4561 sname, cli_errstr(cli1));
4566 if (!NT_STATUS_IS_OK(cli_posix_readlink(cli1, sname, namebuf, sizeof(namebuf)))) {
4567 printf("POSIX readlink on %s failed (%s)\n", sname, cli_errstr(cli1));
4571 if (strcmp(namebuf, fname) != 0) {
4572 printf("POSIX readlink on %s failed to match name %s (read %s)\n",
4573 sname, fname, namebuf);
4577 if (!NT_STATUS_IS_OK(cli_posix_rmdir(cli1, dname))) {
4578 printf("POSIX rmdir failed (%s)\n", cli_errstr(cli1));
4582 printf("Simple POSIX open test passed\n");
4587 if (fnum1 != (uint16_t)-1) {
4588 cli_close(cli1, fnum1);
4589 fnum1 = (uint16_t)-1;
4592 cli_setatr(cli1, sname, 0, 0);
4593 cli_posix_unlink(cli1, sname);
4594 cli_setatr(cli1, hname, 0, 0);
4595 cli_posix_unlink(cli1, hname);
4596 cli_setatr(cli1, fname, 0, 0);
4597 cli_posix_unlink(cli1, fname);
4598 cli_setatr(cli1, dname, 0, 0);
4599 cli_posix_rmdir(cli1, dname);
4601 if (!torture_close_connection(cli1)) {
4609 static uint32 open_attrs_table[] = {
4610 FILE_ATTRIBUTE_NORMAL,
4611 FILE_ATTRIBUTE_ARCHIVE,
4612 FILE_ATTRIBUTE_READONLY,
4613 FILE_ATTRIBUTE_HIDDEN,
4614 FILE_ATTRIBUTE_SYSTEM,
4616 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY,
4617 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN,
4618 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM,
4619 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
4620 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
4621 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
4623 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
4624 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
4625 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
4626 FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_SYSTEM,
4629 struct trunc_open_results {
4636 static struct trunc_open_results attr_results[] = {
4637 { 0, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
4638 { 1, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
4639 { 2, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
4640 { 16, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
4641 { 17, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
4642 { 18, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
4643 { 51, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4644 { 54, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4645 { 56, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
4646 { 68, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4647 { 71, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4648 { 73, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM },
4649 { 99, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4650 { 102, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4651 { 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 },
4652 { 116, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4653 { 119, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4654 { 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 },
4655 { 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 },
4656 { 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 },
4657 { 227, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4658 { 230, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4659 { 232, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
4660 { 244, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4661 { 247, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4662 { 249, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM }
4665 static bool run_openattrtest(int dummy)
4667 static struct cli_state *cli1;
4668 const char *fname = "\\openattr.file";
4670 bool correct = True;
4672 unsigned int i, j, k, l;
4674 printf("starting open attr test\n");
4676 if (!torture_open_connection(&cli1, 0)) {
4680 cli_sockopt(cli1, sockops);
4682 for (k = 0, i = 0; i < sizeof(open_attrs_table)/sizeof(uint32); i++) {
4683 cli_setatr(cli1, fname, 0, 0);
4684 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
4685 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_WRITE_DATA, open_attrs_table[i],
4686 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
4687 printf("open %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
4691 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4692 printf("close %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
4696 for (j = 0; j < sizeof(open_attrs_table)/sizeof(uint32); j++) {
4697 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA, open_attrs_table[j],
4698 FILE_SHARE_NONE, FILE_OVERWRITE, 0, 0, &fnum1))) {
4699 for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
4700 if (attr_results[l].num == k) {
4701 printf("[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(0x%x:%s)\n",
4702 k, open_attrs_table[i],
4703 open_attrs_table[j],
4704 fname, NT_STATUS_V(cli_nt_error(cli1)), cli_errstr(cli1));
4708 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_ACCESS_DENIED)) {
4709 printf("[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s\n",
4710 k, open_attrs_table[i], open_attrs_table[j],
4715 printf("[%d] trunc open 0x%x -> 0x%x failed\n", k, open_attrs_table[i], open_attrs_table[j]);
4721 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4722 printf("close %d (2) of %s failed (%s)\n", j, fname, cli_errstr(cli1));
4726 if (!NT_STATUS_IS_OK(cli_getatr(cli1, fname, &attr, NULL, NULL))) {
4727 printf("getatr(2) failed (%s)\n", cli_errstr(cli1));
4732 printf("[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n",
4733 k, open_attrs_table[i], open_attrs_table[j], attr );
4736 for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
4737 if (attr_results[l].num == k) {
4738 if (attr != attr_results[l].result_attr ||
4739 open_attrs_table[i] != attr_results[l].init_attr ||
4740 open_attrs_table[j] != attr_results[l].trunc_attr) {
4741 printf("getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x\n",
4742 open_attrs_table[i],
4743 open_attrs_table[j],
4745 attr_results[l].result_attr);
4755 cli_setatr(cli1, fname, 0, 0);
4756 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
4758 printf("open attr test %s.\n", correct ? "passed" : "failed");
4760 if (!torture_close_connection(cli1)) {
4766 static void list_fn(const char *mnt, file_info *finfo, const char *name, void *state)
4772 test directory listing speed
4774 static bool run_dirtest(int dummy)
4777 static struct cli_state *cli;
4780 bool correct = True;
4782 printf("starting directory test\n");
4784 if (!torture_open_connection(&cli, 0)) {
4788 cli_sockopt(cli, sockops);
4791 for (i=0;i<torture_numops;i++) {
4793 slprintf(fname, sizeof(fname), "\\%x", (int)random());
4794 if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum))) {
4795 fprintf(stderr,"Failed to open %s\n", fname);
4798 cli_close(cli, fnum);
4803 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
4804 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
4805 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
4807 printf("dirtest core %g seconds\n", end_timer() - t1);
4810 for (i=0;i<torture_numops;i++) {
4812 slprintf(fname, sizeof(fname), "\\%x", (int)random());
4813 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
4816 if (!torture_close_connection(cli)) {
4820 printf("finished dirtest\n");
4825 static void del_fn(const char *mnt, file_info *finfo, const char *mask, void *state)
4827 struct cli_state *pcli = (struct cli_state *)state;
4829 slprintf(fname, sizeof(fname), "\\LISTDIR\\%s", finfo->name);
4831 if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
4834 if (finfo->mode & aDIR) {
4835 if (!NT_STATUS_IS_OK(cli_rmdir(pcli, fname)))
4836 printf("del_fn: failed to rmdir %s\n,", fname );
4838 if (!NT_STATUS_IS_OK(cli_unlink(pcli, fname, aSYSTEM | aHIDDEN)))
4839 printf("del_fn: failed to unlink %s\n,", fname );
4845 sees what IOCTLs are supported
4847 bool torture_ioctl_test(int dummy)
4849 static struct cli_state *cli;
4850 uint16_t device, function;
4852 const char *fname = "\\ioctl.dat";
4856 if (!torture_open_connection(&cli, 0)) {
4860 printf("starting ioctl test\n");
4862 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
4864 if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum))) {
4865 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
4869 status = cli_raw_ioctl(cli, fnum, 0x2d0000 | (0x0420<<2), &blob);
4870 printf("ioctl device info: %s\n", cli_errstr(cli));
4872 status = cli_raw_ioctl(cli, fnum, IOCTL_QUERY_JOB_INFO, &blob);
4873 printf("ioctl job info: %s\n", cli_errstr(cli));
4875 for (device=0;device<0x100;device++) {
4876 printf("testing device=0x%x\n", device);
4877 for (function=0;function<0x100;function++) {
4878 uint32 code = (device<<16) | function;
4880 status = cli_raw_ioctl(cli, fnum, code, &blob);
4882 if (NT_STATUS_IS_OK(status)) {
4883 printf("ioctl 0x%x OK : %d bytes\n", (int)code,
4885 data_blob_free(&blob);
4890 if (!torture_close_connection(cli)) {
4899 tries varients of chkpath
4901 bool torture_chkpath_test(int dummy)
4903 static struct cli_state *cli;
4907 if (!torture_open_connection(&cli, 0)) {
4911 printf("starting chkpath test\n");
4913 /* cleanup from an old run */
4914 cli_rmdir(cli, "\\chkpath.dir\\dir2");
4915 cli_unlink(cli, "\\chkpath.dir\\*", aSYSTEM | aHIDDEN);
4916 cli_rmdir(cli, "\\chkpath.dir");
4918 if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\chkpath.dir"))) {
4919 printf("mkdir1 failed : %s\n", cli_errstr(cli));
4923 if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\chkpath.dir\\dir2"))) {
4924 printf("mkdir2 failed : %s\n", cli_errstr(cli));
4928 if (!NT_STATUS_IS_OK(cli_open(cli, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum))) {
4929 printf("open1 failed (%s)\n", cli_errstr(cli));
4932 cli_close(cli, fnum);
4934 if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir"))) {
4935 printf("chkpath1 failed: %s\n", cli_errstr(cli));
4939 if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir\\dir2"))) {
4940 printf("chkpath2 failed: %s\n", cli_errstr(cli));
4944 if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir\\foo.txt"))) {
4945 ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath,
4946 NT_STATUS_NOT_A_DIRECTORY);
4948 printf("* chkpath on a file should fail\n");
4952 if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir\\bar.txt"))) {
4953 ret = check_error(__LINE__, cli, ERRDOS, ERRbadfile,
4954 NT_STATUS_OBJECT_NAME_NOT_FOUND);
4956 printf("* chkpath on a non existant file should fail\n");
4960 if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir\\dirxx\\bar.txt"))) {
4961 ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath,
4962 NT_STATUS_OBJECT_PATH_NOT_FOUND);
4964 printf("* chkpath on a non existent component should fail\n");
4968 cli_rmdir(cli, "\\chkpath.dir\\dir2");
4969 cli_unlink(cli, "\\chkpath.dir\\*", aSYSTEM | aHIDDEN);
4970 cli_rmdir(cli, "\\chkpath.dir");
4972 if (!torture_close_connection(cli)) {
4979 static bool run_eatest(int dummy)
4981 static struct cli_state *cli;
4982 const char *fname = "\\eatest.txt";
4983 bool correct = True;
4987 struct ea_struct *ea_list = NULL;
4988 TALLOC_CTX *mem_ctx = talloc_init("eatest");
4990 printf("starting eatest\n");
4992 if (!torture_open_connection(&cli, 0)) {
4993 talloc_destroy(mem_ctx);
4997 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
4998 if (!NT_STATUS_IS_OK(cli_ntcreate(cli, fname, 0,
4999 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
5000 FILE_SHARE_NONE, FILE_OVERWRITE_IF,
5001 0x4044, 0, &fnum))) {
5002 printf("open failed - %s\n", cli_errstr(cli));
5003 talloc_destroy(mem_ctx);
5007 for (i = 0; i < 10; i++) {
5008 fstring ea_name, ea_val;
5010 slprintf(ea_name, sizeof(ea_name), "EA_%d", i);
5011 memset(ea_val, (char)i+1, i+1);
5012 if (!cli_set_ea_fnum(cli, fnum, ea_name, ea_val, i+1)) {
5013 printf("ea_set of name %s failed - %s\n", ea_name, cli_errstr(cli));
5014 talloc_destroy(mem_ctx);
5019 cli_close(cli, fnum);
5020 for (i = 0; i < 10; i++) {
5021 fstring ea_name, ea_val;
5023 slprintf(ea_name, sizeof(ea_name), "EA_%d", i+10);
5024 memset(ea_val, (char)i+1, i+1);
5025 if (!cli_set_ea_path(cli, fname, ea_name, ea_val, i+1)) {
5026 printf("ea_set of name %s failed - %s\n", ea_name, cli_errstr(cli));
5027 talloc_destroy(mem_ctx);
5032 if (!cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list)) {
5033 printf("ea_get list failed - %s\n", cli_errstr(cli));
5037 printf("num_eas = %d\n", (int)num_eas);
5039 if (num_eas != 20) {
5040 printf("Should be 20 EA's stored... failing.\n");
5044 for (i = 0; i < num_eas; i++) {
5045 printf("%d: ea_name = %s. Val = ", i, ea_list[i].name);
5046 dump_data(0, ea_list[i].value.data,
5047 ea_list[i].value.length);
5050 /* Setting EA's to zero length deletes them. Test this */
5051 printf("Now deleting all EA's - case indepenent....\n");
5054 cli_set_ea_path(cli, fname, "", "", 0);
5056 for (i = 0; i < 20; i++) {
5058 slprintf(ea_name, sizeof(ea_name), "ea_%d", i);
5059 if (!cli_set_ea_path(cli, fname, ea_name, "", 0)) {
5060 printf("ea_set of name %s failed - %s\n", ea_name, cli_errstr(cli));
5061 talloc_destroy(mem_ctx);
5067 if (!cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list)) {
5068 printf("ea_get list failed - %s\n", cli_errstr(cli));
5072 printf("num_eas = %d\n", (int)num_eas);
5073 for (i = 0; i < num_eas; i++) {
5074 printf("%d: ea_name = %s. Val = ", i, ea_list[i].name);
5075 dump_data(0, ea_list[i].value.data,
5076 ea_list[i].value.length);
5080 printf("deleting EA's failed.\n");
5084 /* Try and delete a non existant EA. */
5085 if (!cli_set_ea_path(cli, fname, "foo", "", 0)) {
5086 printf("deleting non-existant EA 'foo' should succeed. %s\n", cli_errstr(cli));
5090 talloc_destroy(mem_ctx);
5091 if (!torture_close_connection(cli)) {
5098 static bool run_dirtest1(int dummy)
5101 static struct cli_state *cli;
5104 bool correct = True;
5106 printf("starting directory test\n");
5108 if (!torture_open_connection(&cli, 0)) {
5112 cli_sockopt(cli, sockops);
5114 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
5115 cli_list(cli, "\\LISTDIR\\*", aDIR, del_fn, cli);
5116 cli_rmdir(cli, "\\LISTDIR");
5117 cli_mkdir(cli, "\\LISTDIR");
5119 /* Create 1000 files and 1000 directories. */
5120 for (i=0;i<1000;i++) {
5122 slprintf(fname, sizeof(fname), "\\LISTDIR\\f%d", i);
5123 if (!NT_STATUS_IS_OK(cli_ntcreate(cli, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
5124 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum))) {
5125 fprintf(stderr,"Failed to open %s\n", fname);
5128 cli_close(cli, fnum);
5130 for (i=0;i<1000;i++) {
5132 slprintf(fname, sizeof(fname), "\\LISTDIR\\d%d", i);
5133 if (!NT_STATUS_IS_OK(cli_mkdir(cli, fname))) {
5134 fprintf(stderr,"Failed to open %s\n", fname);
5139 /* Now ensure that doing an old list sees both files and directories. */
5140 num_seen = cli_list_old(cli, "\\LISTDIR\\*", aDIR, list_fn, NULL);
5141 printf("num_seen = %d\n", num_seen );
5142 /* We should see 100 files + 1000 directories + . and .. */
5143 if (num_seen != 2002)
5146 /* Ensure if we have the "must have" bits we only see the
5149 num_seen = cli_list_old(cli, "\\LISTDIR\\*", (aDIR<<8)|aDIR, list_fn, NULL);
5150 printf("num_seen = %d\n", num_seen );
5151 if (num_seen != 1002)
5154 num_seen = cli_list_old(cli, "\\LISTDIR\\*", (aARCH<<8)|aDIR, list_fn, NULL);
5155 printf("num_seen = %d\n", num_seen );
5156 if (num_seen != 1000)
5159 /* Delete everything. */
5160 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
5161 cli_list(cli, "\\LISTDIR\\*", aDIR, del_fn, cli);
5162 cli_rmdir(cli, "\\LISTDIR");
5165 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
5166 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
5167 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
5170 if (!torture_close_connection(cli)) {
5174 printf("finished dirtest1\n");
5179 static bool run_error_map_extract(int dummy) {
5181 static struct cli_state *c_dos;
5182 static struct cli_state *c_nt;
5187 uint32 flgs2, errnum;
5194 /* NT-Error connection */
5196 if (!(c_nt = open_nbt_connection())) {
5200 c_nt->use_spnego = False;
5202 status = cli_negprot(c_nt);
5204 if (!NT_STATUS_IS_OK(status)) {
5205 printf("%s rejected the NT-error negprot (%s)\n", host,
5211 if (!NT_STATUS_IS_OK(cli_session_setup(c_nt, "", "", 0, "", 0,
5213 printf("%s rejected the NT-error initial session setup (%s)\n",host, cli_errstr(c_nt));
5217 /* DOS-Error connection */
5219 if (!(c_dos = open_nbt_connection())) {
5223 c_dos->use_spnego = False;
5224 c_dos->force_dos_errors = True;
5226 status = cli_negprot(c_dos);
5227 if (!NT_STATUS_IS_OK(status)) {
5228 printf("%s rejected the DOS-error negprot (%s)\n", host,
5230 cli_shutdown(c_dos);
5234 if (!NT_STATUS_IS_OK(cli_session_setup(c_dos, "", "", 0, "", 0,
5236 printf("%s rejected the DOS-error initial session setup (%s)\n",host, cli_errstr(c_dos));
5240 for (error=(0xc0000000 | 0x1); error < (0xc0000000| 0xFFF); error++) {
5241 fstr_sprintf(user, "%X", error);
5243 if (NT_STATUS_IS_OK(cli_session_setup(c_nt, user,
5244 password, strlen(password),
5245 password, strlen(password),
5247 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
5250 flgs2 = SVAL(c_nt->inbuf,smb_flg2);
5252 /* Case #1: 32-bit NT errors */
5253 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
5254 nt_status = NT_STATUS(IVAL(c_nt->inbuf,smb_rcls));
5256 printf("/** Dos error on NT connection! (%s) */\n",
5258 nt_status = NT_STATUS(0xc0000000);
5261 if (NT_STATUS_IS_OK(cli_session_setup(c_dos, user,
5262 password, strlen(password),
5263 password, strlen(password),
5265 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
5267 flgs2 = SVAL(c_dos->inbuf,smb_flg2), errnum;
5269 /* Case #1: 32-bit NT errors */
5270 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
5271 printf("/** NT error on DOS connection! (%s) */\n",
5273 errnum = errclass = 0;
5275 cli_dos_error(c_dos, &errclass, &errnum);
5278 if (NT_STATUS_V(nt_status) != error) {
5279 printf("/*\t{ This NT error code was 'sqashed'\n\t from %s to %s \n\t during the session setup }\n*/\n",
5280 get_nt_error_c_code(NT_STATUS(error)),
5281 get_nt_error_c_code(nt_status));
5284 printf("\t{%s,\t%s,\t%s},\n",
5285 smb_dos_err_class(errclass),
5286 smb_dos_err_name(errclass, errnum),
5287 get_nt_error_c_code(NT_STATUS(error)));
5292 static bool run_sesssetup_bench(int dummy)
5294 static struct cli_state *c;
5295 const char *fname = "\\file.dat";
5300 if (!torture_open_connection(&c, 0)) {
5304 if (!NT_STATUS_IS_OK(cli_ntcreate(
5305 c, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
5306 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
5307 FILE_DELETE_ON_CLOSE, 0, &fnum))) {
5308 d_printf("open %s failed: %s\n", fname, cli_errstr(c));
5312 for (i=0; i<torture_numops; i++) {
5313 status = cli_session_setup(
5315 password, strlen(password),
5316 password, strlen(password),
5318 if (!NT_STATUS_IS_OK(status)) {
5319 d_printf("(%s) cli_session_setup failed: %s\n",
5320 __location__, nt_errstr(status));
5324 d_printf("\r%d ", (int)c->vuid);
5326 if (!cli_ulogoff(c)) {
5327 d_printf("(%s) cli_ulogoff failed: %s\n",
5328 __location__, cli_errstr(c));
5337 static bool subst_test(const char *str, const char *user, const char *domain,
5338 uid_t uid, gid_t gid, const char *expected)
5343 subst = talloc_sub_specified(talloc_tos(), str, user, domain, uid, gid);
5345 if (strcmp(subst, expected) != 0) {
5346 printf("sub_specified(%s, %s, %s, %d, %d) returned [%s], expected "
5347 "[%s]\n", str, user, domain, (int)uid, (int)gid, subst,
5356 static void chain1_open_completion(struct tevent_req *req)
5360 status = cli_open_recv(req, &fnum);
5363 d_printf("cli_open_recv returned %s: %d\n",
5365 NT_STATUS_IS_OK(status) ? fnum : -1);
5368 static void chain1_write_completion(struct tevent_req *req)
5372 status = cli_write_andx_recv(req, &written);
5375 d_printf("cli_write_andx_recv returned %s: %d\n",
5377 NT_STATUS_IS_OK(status) ? (int)written : -1);
5380 static void chain1_close_completion(struct tevent_req *req)
5383 bool *done = (bool *)tevent_req_callback_data_void(req);
5385 status = cli_close_recv(req);
5390 d_printf("cli_close returned %s\n", nt_errstr(status));
5393 static bool run_chain1(int dummy)
5395 struct cli_state *cli1;
5396 struct event_context *evt = event_context_init(NULL);
5397 struct tevent_req *reqs[3], *smbreqs[3];
5399 const char *str = "foobar";
5402 printf("starting chain1 test\n");
5403 if (!torture_open_connection(&cli1, 0)) {
5407 cli_sockopt(cli1, sockops);
5409 reqs[0] = cli_open_create(talloc_tos(), evt, cli1, "\\test",
5410 O_CREAT|O_RDWR, 0, &smbreqs[0]);
5411 if (reqs[0] == NULL) return false;
5412 tevent_req_set_callback(reqs[0], chain1_open_completion, NULL);
5415 reqs[1] = cli_write_andx_create(talloc_tos(), evt, cli1, 0, 0,
5416 (uint8_t *)str, 0, strlen(str)+1,
5417 smbreqs, 1, &smbreqs[1]);
5418 if (reqs[1] == NULL) return false;
5419 tevent_req_set_callback(reqs[1], chain1_write_completion, NULL);
5421 reqs[2] = cli_close_create(talloc_tos(), evt, cli1, 0, &smbreqs[2]);
5422 if (reqs[2] == NULL) return false;
5423 tevent_req_set_callback(reqs[2], chain1_close_completion, &done);
5425 status = cli_smb_chain_send(smbreqs, ARRAY_SIZE(smbreqs));
5426 if (!NT_STATUS_IS_OK(status)) {
5431 event_loop_once(evt);
5434 torture_close_connection(cli1);
5438 static void chain2_sesssetup_completion(struct tevent_req *req)
5441 status = cli_session_setup_guest_recv(req);
5442 d_printf("sesssetup returned %s\n", nt_errstr(status));
5445 static void chain2_tcon_completion(struct tevent_req *req)
5447 bool *done = (bool *)tevent_req_callback_data_void(req);
5449 status = cli_tcon_andx_recv(req);
5450 d_printf("tcon_and_x returned %s\n", nt_errstr(status));
5454 static bool run_chain2(int dummy)
5456 struct cli_state *cli1;
5457 struct event_context *evt = event_context_init(NULL);
5458 struct tevent_req *reqs[2], *smbreqs[2];
5462 printf("starting chain2 test\n");
5463 status = cli_start_connection(&cli1, global_myname(), host, NULL,
5464 port_to_use, Undefined, 0, NULL);
5465 if (!NT_STATUS_IS_OK(status)) {
5469 cli_sockopt(cli1, sockops);
5471 reqs[0] = cli_session_setup_guest_create(talloc_tos(), evt, cli1,
5473 if (reqs[0] == NULL) return false;
5474 tevent_req_set_callback(reqs[0], chain2_sesssetup_completion, NULL);
5476 reqs[1] = cli_tcon_andx_create(talloc_tos(), evt, cli1, "IPC$",
5477 "?????", NULL, 0, &smbreqs[1]);
5478 if (reqs[1] == NULL) return false;
5479 tevent_req_set_callback(reqs[1], chain2_tcon_completion, &done);
5481 status = cli_smb_chain_send(smbreqs, ARRAY_SIZE(smbreqs));
5482 if (!NT_STATUS_IS_OK(status)) {
5487 event_loop_once(evt);
5490 torture_close_connection(cli1);
5495 struct torture_createdel_state {
5496 struct tevent_context *ev;
5497 struct cli_state *cli;
5500 static void torture_createdel_created(struct tevent_req *subreq);
5501 static void torture_createdel_closed(struct tevent_req *subreq);
5503 static struct tevent_req *torture_createdel_send(TALLOC_CTX *mem_ctx,
5504 struct tevent_context *ev,
5505 struct cli_state *cli,
5508 struct tevent_req *req, *subreq;
5509 struct torture_createdel_state *state;
5511 req = tevent_req_create(mem_ctx, &state,
5512 struct torture_createdel_state);
5519 subreq = cli_ntcreate_send(
5520 state, ev, cli, name, 0,
5521 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
5522 FILE_ATTRIBUTE_NORMAL,
5523 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
5524 FILE_OPEN_IF, FILE_DELETE_ON_CLOSE, 0);
5526 if (tevent_req_nomem(subreq, req)) {
5527 return tevent_req_post(req, ev);
5529 tevent_req_set_callback(subreq, torture_createdel_created, req);
5533 static void torture_createdel_created(struct tevent_req *subreq)
5535 struct tevent_req *req = tevent_req_callback_data(
5536 subreq, struct tevent_req);
5537 struct torture_createdel_state *state = tevent_req_data(
5538 req, struct torture_createdel_state);
5542 status = cli_ntcreate_recv(subreq, &fnum);
5543 TALLOC_FREE(subreq);
5544 if (!NT_STATUS_IS_OK(status)) {
5545 DEBUG(10, ("cli_ntcreate_recv returned %s\n",
5546 nt_errstr(status)));
5547 tevent_req_nterror(req, status);
5551 subreq = cli_close_send(state, state->ev, state->cli, fnum);
5552 if (tevent_req_nomem(subreq, req)) {
5555 tevent_req_set_callback(subreq, torture_createdel_closed, req);
5558 static void torture_createdel_closed(struct tevent_req *subreq)
5560 struct tevent_req *req = tevent_req_callback_data(
5561 subreq, struct tevent_req);
5564 status = cli_close_recv(subreq);
5565 if (!NT_STATUS_IS_OK(status)) {
5566 DEBUG(10, ("cli_close_recv returned %s\n", nt_errstr(status)));
5567 tevent_req_nterror(req, status);
5570 tevent_req_done(req);
5573 static NTSTATUS torture_createdel_recv(struct tevent_req *req)
5575 return tevent_req_simple_recv_ntstatus(req);
5578 struct torture_createdels_state {
5579 struct tevent_context *ev;
5580 struct cli_state *cli;
5581 const char *base_name;
5585 struct tevent_req **reqs;
5588 static void torture_createdels_done(struct tevent_req *subreq);
5590 static struct tevent_req *torture_createdels_send(TALLOC_CTX *mem_ctx,
5591 struct tevent_context *ev,
5592 struct cli_state *cli,
5593 const char *base_name,
5597 struct tevent_req *req;
5598 struct torture_createdels_state *state;
5601 req = tevent_req_create(mem_ctx, &state,
5602 struct torture_createdels_state);
5608 state->base_name = talloc_strdup(state, base_name);
5609 if (tevent_req_nomem(state->base_name, req)) {
5610 return tevent_req_post(req, ev);
5612 state->num_files = MAX(num_parallel, num_files);
5614 state->received = 0;
5616 state->reqs = talloc_array(state, struct tevent_req *, num_parallel);
5617 if (tevent_req_nomem(state->reqs, req)) {
5618 return tevent_req_post(req, ev);
5621 for (i=0; i<num_parallel; i++) {
5624 name = talloc_asprintf(state, "%s%8.8d", state->base_name,
5626 if (tevent_req_nomem(name, req)) {
5627 return tevent_req_post(req, ev);
5629 state->reqs[i] = torture_createdel_send(
5630 state->reqs, state->ev, state->cli, name);
5631 if (tevent_req_nomem(state->reqs[i], req)) {
5632 return tevent_req_post(req, ev);
5634 name = talloc_move(state->reqs[i], &name);
5635 tevent_req_set_callback(state->reqs[i],
5636 torture_createdels_done, req);
5642 static void torture_createdels_done(struct tevent_req *subreq)
5644 struct tevent_req *req = tevent_req_callback_data(
5645 subreq, struct tevent_req);
5646 struct torture_createdels_state *state = tevent_req_data(
5647 req, struct torture_createdels_state);
5648 size_t num_parallel = talloc_array_length(state->reqs);
5653 status = torture_createdel_recv(subreq);
5654 if (!NT_STATUS_IS_OK(status)){
5655 DEBUG(10, ("torture_createdel_recv returned %s\n",
5656 nt_errstr(status)));
5657 TALLOC_FREE(subreq);
5658 tevent_req_nterror(req, status);
5662 for (i=0; i<num_parallel; i++) {
5663 if (subreq == state->reqs[i]) {
5667 if (i == num_parallel) {
5668 DEBUG(10, ("received something we did not send\n"));
5669 tevent_req_nterror(req, NT_STATUS_INTERNAL_ERROR);
5672 TALLOC_FREE(state->reqs[i]);
5674 if (state->sent >= state->num_files) {
5675 tevent_req_done(req);
5679 name = talloc_asprintf(state, "%s%8.8d", state->base_name,
5681 if (tevent_req_nomem(name, req)) {
5684 state->reqs[i] = torture_createdel_send(state->reqs, state->ev,
5686 if (tevent_req_nomem(state->reqs[i], req)) {
5689 name = talloc_move(state->reqs[i], &name);
5690 tevent_req_set_callback(state->reqs[i], torture_createdels_done, req);
5694 static NTSTATUS torture_createdels_recv(struct tevent_req *req)
5696 return tevent_req_simple_recv_ntstatus(req);
5699 struct swallow_notify_state {
5700 struct tevent_context *ev;
5701 struct cli_state *cli;
5703 uint32_t completion_filter;
5705 bool (*fn)(uint32_t action, const char *name, void *priv);
5709 static void swallow_notify_done(struct tevent_req *subreq);
5711 static struct tevent_req *swallow_notify_send(TALLOC_CTX *mem_ctx,
5712 struct tevent_context *ev,
5713 struct cli_state *cli,
5715 uint32_t completion_filter,
5717 bool (*fn)(uint32_t action,
5722 struct tevent_req *req, *subreq;
5723 struct swallow_notify_state *state;
5725 req = tevent_req_create(mem_ctx, &state,
5726 struct swallow_notify_state);
5733 state->completion_filter = completion_filter;
5734 state->recursive = recursive;
5738 subreq = cli_notify_send(state, state->ev, state->cli, state->fnum,
5739 0xffff, state->completion_filter,
5741 if (tevent_req_nomem(subreq, req)) {
5742 return tevent_req_post(req, ev);
5744 tevent_req_set_callback(subreq, swallow_notify_done, req);
5748 static void swallow_notify_done(struct tevent_req *subreq)
5750 struct tevent_req *req = tevent_req_callback_data(
5751 subreq, struct tevent_req);
5752 struct swallow_notify_state *state = tevent_req_data(
5753 req, struct swallow_notify_state);
5755 uint32_t i, num_changes;
5756 struct notify_change *changes;
5758 status = cli_notify_recv(subreq, state, &num_changes, &changes);
5759 TALLOC_FREE(subreq);
5760 if (!NT_STATUS_IS_OK(status)) {
5761 DEBUG(10, ("cli_notify_recv returned %s\n",
5762 nt_errstr(status)));
5763 tevent_req_nterror(req, status);
5767 for (i=0; i<num_changes; i++) {
5768 state->fn(changes[i].action, changes[i].name, state->priv);
5770 TALLOC_FREE(changes);
5772 subreq = cli_notify_send(state, state->ev, state->cli, state->fnum,
5773 0xffff, state->completion_filter,
5775 if (tevent_req_nomem(subreq, req)) {
5778 tevent_req_set_callback(subreq, swallow_notify_done, req);
5781 static bool print_notifies(uint32_t action, const char *name, void *priv)
5783 if (DEBUGLEVEL > 5) {
5784 d_printf("%d %s\n", (int)action, name);
5789 static void notify_bench_done(struct tevent_req *req)
5791 int *num_finished = (int *)tevent_req_callback_data_void(req);
5795 static bool run_notify_bench(int dummy)
5797 const char *dname = "\\notify-bench";
5798 struct tevent_context *ev;
5801 struct tevent_req *req1, *req2;
5802 int i, num_unc_names;
5803 int num_finished = 0;
5805 printf("starting notify-bench test\n");
5807 if (use_multishare_conn) {
5809 unc_list = file_lines_load(multishare_conn_fname,
5810 &num_unc_names, 0, NULL);
5811 if (!unc_list || num_unc_names <= 0) {
5812 d_printf("Failed to load unc names list from '%s'\n",
5813 multishare_conn_fname);
5816 TALLOC_FREE(unc_list);
5821 ev = tevent_context_init(talloc_tos());
5823 d_printf("tevent_context_init failed\n");
5827 for (i=0; i<num_unc_names; i++) {
5828 struct cli_state *cli;
5831 base_fname = talloc_asprintf(talloc_tos(), "%s\\file%3.3d.",
5833 if (base_fname == NULL) {
5837 if (!torture_open_connection(&cli, i)) {
5841 status = cli_ntcreate(cli, dname, 0,
5842 MAXIMUM_ALLOWED_ACCESS,
5843 0, FILE_SHARE_READ|FILE_SHARE_WRITE|
5845 FILE_OPEN_IF, FILE_DIRECTORY_FILE, 0,
5848 if (!NT_STATUS_IS_OK(status)) {
5849 d_printf("Could not create %s: %s\n", dname,
5854 req1 = swallow_notify_send(talloc_tos(), ev, cli, dnum,
5855 FILE_NOTIFY_CHANGE_FILE_NAME |
5856 FILE_NOTIFY_CHANGE_DIR_NAME |
5857 FILE_NOTIFY_CHANGE_ATTRIBUTES |
5858 FILE_NOTIFY_CHANGE_LAST_WRITE,
5859 false, print_notifies, NULL);
5861 d_printf("Could not create notify request\n");
5865 req2 = torture_createdels_send(talloc_tos(), ev, cli,
5866 base_fname, 10, torture_numops);
5868 d_printf("Could not create createdels request\n");
5871 TALLOC_FREE(base_fname);
5873 tevent_req_set_callback(req2, notify_bench_done,
5877 while (num_finished < num_unc_names) {
5879 ret = tevent_loop_once(ev);
5881 d_printf("tevent_loop_once failed\n");
5886 if (!tevent_req_poll(req2, ev)) {
5887 d_printf("tevent_req_poll failed\n");
5890 status = torture_createdels_recv(req2);
5891 d_printf("torture_createdels_recv returned %s\n", nt_errstr(status));
5896 static bool run_mangle1(int dummy)
5898 struct cli_state *cli;
5899 const char *fname = "this_is_a_long_fname_to_be_mangled.txt";
5903 time_t change_time, access_time, write_time;
5907 printf("starting mangle1 test\n");
5908 if (!torture_open_connection(&cli, 0)) {
5912 cli_sockopt(cli, sockops);
5914 if (!NT_STATUS_IS_OK(cli_ntcreate(
5915 cli, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
5916 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0, 0, &fnum))) {
5917 d_printf("open %s failed: %s\n", fname, cli_errstr(cli));
5920 cli_close(cli, fnum);
5922 status = cli_qpathinfo_alt_name(cli, fname, alt_name);
5923 if (!NT_STATUS_IS_OK(status)) {
5924 d_printf("cli_qpathinfo_alt_name failed: %s\n",
5928 d_printf("alt_name: %s\n", alt_name);
5930 if (!NT_STATUS_IS_OK(cli_open(cli, alt_name, O_RDONLY, DENY_NONE, &fnum))) {
5931 d_printf("cli_open(%s) failed: %s\n", alt_name,
5935 cli_close(cli, fnum);
5937 if (!cli_qpathinfo(cli, alt_name, &change_time, &access_time,
5938 &write_time, &size, &mode)) {
5939 d_printf("cli_qpathinfo(%s) failed: %s\n", alt_name,
5947 static size_t null_source(uint8_t *buf, size_t n, void *priv)
5949 size_t *to_pull = (size_t *)priv;
5950 size_t thistime = *to_pull;
5952 thistime = MIN(thistime, n);
5953 if (thistime == 0) {
5957 memset(buf, 0, thistime);
5958 *to_pull -= thistime;
5962 static bool run_windows_write(int dummy)
5964 struct cli_state *cli1;
5968 const char *fname = "\\writetest.txt";
5972 printf("starting windows_write test\n");
5973 if (!torture_open_connection(&cli1, 0)) {
5977 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum))) {
5978 printf("open failed (%s)\n", cli_errstr(cli1));
5982 cli_sockopt(cli1, sockops);
5986 for (i=0; i<torture_numops; i++) {
5988 off_t start = i * torture_blocksize;
5990 size_t to_pull = torture_blocksize - 1;
5992 if (cli_write(cli1, fnum, 0, &c,
5993 start + torture_blocksize - 1, 1) != 1) {
5994 printf("cli_write failed: %s\n", cli_errstr(cli1));
5998 status = cli_push(cli1, fnum, 0, i * torture_blocksize, torture_blocksize,
5999 null_source, &to_pull);
6000 if (!NT_STATUS_IS_OK(status)) {
6001 printf("cli_push returned: %s\n", nt_errstr(status));
6006 seconds = end_timer();
6007 kbytes = (double)torture_blocksize * torture_numops;
6010 printf("Wrote %d kbytes in %.2f seconds: %d kb/sec\n", (int)kbytes,
6011 (double)seconds, (int)(kbytes/seconds));
6015 cli_close(cli1, fnum);
6016 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
6017 torture_close_connection(cli1);
6021 static bool run_cli_echo(int dummy)
6023 struct cli_state *cli;
6026 printf("starting cli_echo test\n");
6027 if (!torture_open_connection(&cli, 0)) {
6030 cli_sockopt(cli, sockops);
6032 status = cli_echo(cli, 5, data_blob_const("hello", 5));
6034 d_printf("cli_echo returned %s\n", nt_errstr(status));
6036 torture_close_connection(cli);
6037 return NT_STATUS_IS_OK(status);
6040 static bool run_uid_regression_test(int dummy)
6042 static struct cli_state *cli;
6045 bool correct = True;
6047 printf("starting uid regression test\n");
6049 if (!torture_open_connection(&cli, 0)) {
6053 cli_sockopt(cli, sockops);
6055 /* Ok - now save then logoff our current user. */
6056 old_vuid = cli->vuid;
6058 if (!cli_ulogoff(cli)) {
6059 d_printf("(%s) cli_ulogoff failed: %s\n",
6060 __location__, cli_errstr(cli));
6065 cli->vuid = old_vuid;
6067 /* Try an operation. */
6068 if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\uid_reg_test"))) {
6069 /* We expect bad uid. */
6070 if (!check_error(__LINE__, cli, ERRSRV, ERRbaduid,
6071 NT_STATUS_NO_SUCH_USER)) {
6076 old_cnum = cli->cnum;
6078 /* Now try a SMBtdis with the invald vuid set to zero. */
6081 /* This should succeed. */
6082 if (cli_tdis(cli)) {
6083 printf("First tdis with invalid vuid should succeed.\n");
6085 printf("First tdis failed (%s)\n", cli_errstr(cli));
6088 cli->vuid = old_vuid;
6089 cli->cnum = old_cnum;
6091 /* This should fail. */
6092 if (cli_tdis(cli)) {
6093 printf("Second tdis with invalid vuid should fail - succeeded instead !.\n");
6095 /* Should be bad tid. */
6096 if (!check_error(__LINE__, cli, ERRSRV, ERRinvnid,
6097 NT_STATUS_NETWORK_NAME_DELETED)) {
6102 cli_rmdir(cli, "\\uid_reg_test");
6111 static const char *illegal_chars = "*\\/?<>|\":";
6112 static char force_shortname_chars[] = " +,.[];=\177";
6114 static void shortname_del_fn(const char *mnt, file_info *finfo, const char *mask, void *state)
6116 struct cli_state *pcli = (struct cli_state *)state;
6118 slprintf(fname, sizeof(fname), "\\shortname\\%s", finfo->name);
6120 if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
6123 if (finfo->mode & aDIR) {
6124 if (!NT_STATUS_IS_OK(cli_rmdir(pcli, fname)))
6125 printf("del_fn: failed to rmdir %s\n,", fname );
6127 if (!NT_STATUS_IS_OK(cli_unlink(pcli, fname, aSYSTEM | aHIDDEN)))
6128 printf("del_fn: failed to unlink %s\n,", fname );
6137 static void shortname_list_fn(const char *mnt, file_info *finfo, const char *name, void *state)
6139 struct sn_state *s = (struct sn_state *)state;
6143 printf("shortname list: i = %d, name = |%s|, shortname = |%s|\n",
6144 i, finfo->name, finfo->short_name);
6147 if (strchr(force_shortname_chars, i)) {
6148 if (!finfo->short_name[0]) {
6149 /* Shortname not created when it should be. */
6150 d_printf("(%s) ERROR: Shortname was not created for file %s containing %d\n",
6151 __location__, finfo->name, i);
6154 } else if (finfo->short_name[0]){
6155 /* Shortname created when it should not be. */
6156 d_printf("(%s) ERROR: Shortname %s was created for file %s\n",
6157 __location__, finfo->short_name, finfo->name);
6162 static bool run_shortname_test(int dummy)
6164 static struct cli_state *cli;
6165 bool correct = True;
6170 printf("starting shortname test\n");
6172 if (!torture_open_connection(&cli, 0)) {
6176 cli_sockopt(cli, sockops);
6178 cli_list(cli, "\\shortname\\*", 0, shortname_del_fn, cli);
6179 cli_list(cli, "\\shortname\\*", aDIR, shortname_del_fn, cli);
6180 cli_rmdir(cli, "\\shortname");
6182 if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\shortname"))) {
6183 d_printf("(%s) cli_mkdir of \\shortname failed: %s\n",
6184 __location__, cli_errstr(cli));
6189 strlcpy(fname, "\\shortname\\", sizeof(fname));
6190 strlcat(fname, "test .txt", sizeof(fname));
6194 for (i = 32; i < 128; i++) {
6196 uint16_t fnum = (uint16_t)-1;
6200 if (strchr(illegal_chars, i)) {
6205 status = cli_ntcreate(cli, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
6206 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum);
6207 if (!NT_STATUS_IS_OK(status)) {
6208 d_printf("(%s) cli_nt_create of %s failed: %s\n",
6209 __location__, fname, cli_errstr(cli));
6213 cli_close(cli, fnum);
6214 if (cli_list(cli, "\\shortname\\test*.*", 0, shortname_list_fn, &s) != 1) {
6215 d_printf("(%s) failed to list %s: %s\n",
6216 __location__, fname, cli_errstr(cli));
6220 if (!NT_STATUS_IS_OK(cli_unlink(cli, fname, aSYSTEM | aHIDDEN))) {
6221 d_printf("(%s) failed to delete %s: %s\n",
6222 __location__, fname, cli_errstr(cli));
6235 cli_list(cli, "\\shortname\\*", 0, shortname_del_fn, cli);
6236 cli_list(cli, "\\shortname\\*", aDIR, shortname_del_fn, cli);
6237 cli_rmdir(cli, "\\shortname");
6238 torture_close_connection(cli);
6242 static void pagedsearch_cb(struct tevent_req *req)
6245 struct tldap_message *msg;
6248 rc = tldap_search_paged_recv(req, talloc_tos(), &msg);
6249 if (rc != TLDAP_SUCCESS) {
6250 d_printf("tldap_search_paged_recv failed: %s\n",
6251 tldap_err2string(rc));
6254 if (tldap_msg_type(msg) != TLDAP_RES_SEARCH_ENTRY) {
6258 if (!tldap_entry_dn(msg, &dn)) {
6259 d_printf("tldap_entry_dn failed\n");
6262 d_printf("%s\n", dn);
6266 static bool run_tldap(int dummy)
6268 struct tldap_context *ld;
6271 struct sockaddr_storage addr;
6272 struct tevent_context *ev;
6273 struct tevent_req *req;
6276 if (!resolve_name(host, &addr, 0, false)) {
6277 d_printf("could not find host %s\n", host);
6280 status = open_socket_out(&addr, 389, 9999, &fd);
6281 if (!NT_STATUS_IS_OK(status)) {
6282 d_printf("open_socket_out failed: %s\n", nt_errstr(status));
6286 ld = tldap_context_create(talloc_tos(), fd);
6289 d_printf("tldap_context_create failed\n");
6293 rc = tldap_fetch_rootdse(ld);
6294 if (rc != TLDAP_SUCCESS) {
6295 d_printf("tldap_fetch_rootdse failed: %s\n",
6296 tldap_errstr(talloc_tos(), ld, rc));
6300 basedn = tldap_talloc_single_attribute(
6301 tldap_rootdse(ld), "defaultNamingContext", talloc_tos());
6302 if (basedn == NULL) {
6303 d_printf("no defaultNamingContext\n");
6306 d_printf("defaultNamingContext: %s\n", basedn);
6308 ev = tevent_context_init(talloc_tos());
6310 d_printf("tevent_context_init failed\n");
6314 req = tldap_search_paged_send(talloc_tos(), ev, ld, basedn,
6315 TLDAP_SCOPE_SUB, "(objectclass=*)",
6317 NULL, 0, NULL, 0, 0, 0, 0, 5);
6319 d_printf("tldap_search_paged_send failed\n");
6322 tevent_req_set_callback(req, pagedsearch_cb, NULL);
6324 tevent_req_poll(req, ev);
6332 static bool run_streamerror(int dummy)
6334 struct cli_state *cli;
6335 const char *dname = "\\testdir";
6336 const char *streamname =
6337 "testdir:{4c8cc155-6c1e-11d1-8e41-00c04fb9386d}:$DATA";
6339 time_t change_time, access_time, write_time;
6341 uint16_t mode, fnum;
6344 if (!torture_open_connection(&cli, 0)) {
6348 cli_rmdir(cli, dname);
6350 status = cli_mkdir(cli, dname);
6351 if (!NT_STATUS_IS_OK(status)) {
6352 printf("mkdir failed: %s\n", nt_errstr(status));
6356 cli_qpathinfo(cli, streamname, &change_time, &access_time, &write_time,
6358 status = cli_nt_error(cli);
6360 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
6361 printf("pathinfo returned %s, expected "
6362 "NT_STATUS_OBJECT_NAME_NOT_FOUND\n",
6367 status = cli_ntcreate(cli, streamname, 0x16,
6368 FILE_READ_DATA|FILE_READ_EA|
6369 FILE_READ_ATTRIBUTES|READ_CONTROL_ACCESS,
6370 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ,
6371 FILE_OPEN, 0, 0, &fnum);
6373 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
6374 printf("ntcreate returned %s, expected "
6375 "NT_STATUS_OBJECT_NAME_NOT_FOUND\n",
6381 cli_rmdir(cli, dname);
6385 static bool run_local_substitute(int dummy)
6389 ok &= subst_test("%U", "bla", "", -1, -1, "bla");
6390 ok &= subst_test("%u%U", "bla", "", -1, -1, "blabla");
6391 ok &= subst_test("%g", "", "", -1, -1, "NO_GROUP");
6392 ok &= subst_test("%G", "", "", -1, -1, "NO_GROUP");
6393 ok &= subst_test("%g", "", "", -1, 0, gidtoname(0));
6394 ok &= subst_test("%G", "", "", -1, 0, gidtoname(0));
6395 ok &= subst_test("%D%u", "u", "dom", -1, 0, "domu");
6396 ok &= subst_test("%i %I", "", "", -1, -1, "0.0.0.0 0.0.0.0");
6398 /* Different captialization rules in sub_basic... */
6400 ok &= (strcmp(talloc_sub_basic(talloc_tos(), "BLA", "dom", "%U%D"),
6406 static bool run_local_base64(int dummy)
6411 for (i=1; i<2000; i++) {
6412 DATA_BLOB blob1, blob2;
6415 blob1.data = talloc_array(talloc_tos(), uint8_t, i);
6417 generate_random_buffer(blob1.data, blob1.length);
6419 b64 = base64_encode_data_blob(talloc_tos(), blob1);
6421 d_fprintf(stderr, "base64_encode_data_blob failed "
6422 "for %d bytes\n", i);
6425 blob2 = base64_decode_data_blob(b64);
6428 if (data_blob_cmp(&blob1, &blob2)) {
6429 d_fprintf(stderr, "data_blob_cmp failed for %d "
6433 TALLOC_FREE(blob1.data);
6434 data_blob_free(&blob2);
6439 static bool run_local_gencache(int dummy)
6445 if (!gencache_set("foo", "bar", time(NULL) + 1000)) {
6446 d_printf("%s: gencache_set() failed\n", __location__);
6450 if (!gencache_get("foo", NULL, NULL)) {
6451 d_printf("%s: gencache_get() failed\n", __location__);
6455 if (!gencache_get("foo", &val, &tm)) {
6456 d_printf("%s: gencache_get() failed\n", __location__);
6460 if (strcmp(val, "bar") != 0) {
6461 d_printf("%s: gencache_get() returned %s, expected %s\n",
6462 __location__, val, "bar");
6469 if (!gencache_del("foo")) {
6470 d_printf("%s: gencache_del() failed\n", __location__);
6473 if (gencache_del("foo")) {
6474 d_printf("%s: second gencache_del() succeeded\n",
6479 if (gencache_get("foo", &val, &tm)) {
6480 d_printf("%s: gencache_get() on deleted entry "
6481 "succeeded\n", __location__);
6485 blob = data_blob_string_const_null("bar");
6486 tm = time(NULL) + 60;
6488 if (!gencache_set_data_blob("foo", &blob, tm)) {
6489 d_printf("%s: gencache_set_data_blob() failed\n", __location__);
6493 if (!gencache_get_data_blob("foo", &blob, NULL, NULL)) {
6494 d_printf("%s: gencache_get_data_blob() failed\n", __location__);
6498 if (strcmp((const char *)blob.data, "bar") != 0) {
6499 d_printf("%s: gencache_get_data_blob() returned %s, expected %s\n",
6500 __location__, (const char *)blob.data, "bar");
6501 data_blob_free(&blob);
6505 data_blob_free(&blob);
6507 if (!gencache_del("foo")) {
6508 d_printf("%s: gencache_del() failed\n", __location__);
6511 if (gencache_del("foo")) {
6512 d_printf("%s: second gencache_del() succeeded\n",
6517 if (gencache_get_data_blob("foo", &blob, NULL, NULL)) {
6518 d_printf("%s: gencache_get_data_blob() on deleted entry "
6519 "succeeded\n", __location__);
6526 static bool rbt_testval(struct db_context *db, const char *key,
6529 struct db_record *rec;
6530 TDB_DATA data = string_tdb_data(value);
6534 rec = db->fetch_locked(db, db, string_tdb_data(key));
6536 d_fprintf(stderr, "fetch_locked failed\n");
6539 status = rec->store(rec, data, 0);
6540 if (!NT_STATUS_IS_OK(status)) {
6541 d_fprintf(stderr, "store failed: %s\n", nt_errstr(status));
6546 rec = db->fetch_locked(db, db, string_tdb_data(key));
6548 d_fprintf(stderr, "second fetch_locked failed\n");
6551 if ((rec->value.dsize != data.dsize)
6552 || (memcmp(rec->value.dptr, data.dptr, data.dsize) != 0)) {
6553 d_fprintf(stderr, "Got wrong data back\n");
6563 static bool run_local_rbtree(int dummy)
6565 struct db_context *db;
6569 db = db_open_rbt(NULL);
6572 d_fprintf(stderr, "db_open_rbt failed\n");
6576 for (i=0; i<1000; i++) {
6579 if (asprintf(&key, "key%ld", random()) == -1) {
6582 if (asprintf(&value, "value%ld", random()) == -1) {
6587 if (!rbt_testval(db, key, value)) {
6594 if (asprintf(&value, "value%ld", random()) == -1) {
6599 if (!rbt_testval(db, key, value)) {
6616 struct talloc_dict_test {
6620 static int talloc_dict_traverse_fn(DATA_BLOB key, void *data, void *priv)
6622 int *count = (int *)priv;
6627 static bool run_local_talloc_dict(int dummy)
6629 struct talloc_dict *dict;
6630 struct talloc_dict_test *t;
6633 dict = talloc_dict_init(talloc_tos());
6638 t = talloc(talloc_tos(), struct talloc_dict_test);
6645 if (!talloc_dict_set(dict, data_blob_const(&key, sizeof(key)), t)) {
6650 if (talloc_dict_traverse(dict, talloc_dict_traverse_fn, &count) != 0) {
6663 /* Split a path name into filename and stream name components. Canonicalise
6664 * such that an implicit $DATA token is always explicit.
6666 * The "specification" of this function can be found in the
6667 * run_local_stream_name() function in torture.c, I've tried those
6668 * combinations against a W2k3 server.
6671 static NTSTATUS split_ntfs_stream_name(TALLOC_CTX *mem_ctx, const char *fname,
6672 char **pbase, char **pstream)
6675 char *stream = NULL;
6676 char *sname; /* stream name */
6677 const char *stype; /* stream type */
6679 DEBUG(10, ("split_ntfs_stream_name called for [%s]\n", fname));
6681 sname = strchr_m(fname, ':');
6683 if (lp_posix_pathnames() || (sname == NULL)) {
6684 if (pbase != NULL) {
6685 base = talloc_strdup(mem_ctx, fname);
6686 NT_STATUS_HAVE_NO_MEMORY(base);
6691 if (pbase != NULL) {
6692 base = talloc_strndup(mem_ctx, fname, PTR_DIFF(sname, fname));
6693 NT_STATUS_HAVE_NO_MEMORY(base);
6698 stype = strchr_m(sname, ':');
6700 if (stype == NULL) {
6701 sname = talloc_strdup(mem_ctx, sname);
6705 if (StrCaseCmp(stype, ":$DATA") != 0) {
6707 * If there is an explicit stream type, so far we only
6708 * allow $DATA. Is there anything else allowed? -- vl
6710 DEBUG(10, ("[%s] is an invalid stream type\n", stype));
6712 return NT_STATUS_OBJECT_NAME_INVALID;
6714 sname = talloc_strndup(mem_ctx, sname, PTR_DIFF(stype, sname));
6718 if (sname == NULL) {
6720 return NT_STATUS_NO_MEMORY;
6723 if (sname[0] == '\0') {
6725 * no stream name, so no stream
6730 if (pstream != NULL) {
6731 stream = talloc_asprintf(mem_ctx, "%s:%s", sname, stype);
6732 if (stream == NULL) {
6735 return NT_STATUS_NO_MEMORY;
6738 * upper-case the type field
6740 strupper_m(strchr_m(stream, ':')+1);
6744 if (pbase != NULL) {
6747 if (pstream != NULL) {
6750 return NT_STATUS_OK;
6753 static bool test_stream_name(const char *fname, const char *expected_base,
6754 const char *expected_stream,
6755 NTSTATUS expected_status)
6759 char *stream = NULL;
6761 status = split_ntfs_stream_name(talloc_tos(), fname, &base, &stream);
6762 if (!NT_STATUS_EQUAL(status, expected_status)) {
6766 if (!NT_STATUS_IS_OK(status)) {
6770 if (base == NULL) goto error;
6772 if (strcmp(expected_base, base) != 0) goto error;
6774 if ((expected_stream != NULL) && (stream == NULL)) goto error;
6775 if ((expected_stream == NULL) && (stream != NULL)) goto error;
6777 if ((stream != NULL) && (strcmp(expected_stream, stream) != 0))
6781 TALLOC_FREE(stream);
6785 d_fprintf(stderr, "test_stream(%s, %s, %s, %s)\n",
6786 fname, expected_base ? expected_base : "<NULL>",
6787 expected_stream ? expected_stream : "<NULL>",
6788 nt_errstr(expected_status));
6789 d_fprintf(stderr, "-> base=%s, stream=%s, status=%s\n",
6790 base ? base : "<NULL>", stream ? stream : "<NULL>",
6793 TALLOC_FREE(stream);
6797 static bool run_local_stream_name(int dummy)
6801 ret &= test_stream_name(
6802 "bla", "bla", NULL, NT_STATUS_OK);
6803 ret &= test_stream_name(
6804 "bla::$DATA", "bla", NULL, NT_STATUS_OK);
6805 ret &= test_stream_name(
6806 "bla:blub:", "bla", NULL, NT_STATUS_OBJECT_NAME_INVALID);
6807 ret &= test_stream_name(
6808 "bla::", NULL, NULL, NT_STATUS_OBJECT_NAME_INVALID);
6809 ret &= test_stream_name(
6810 "bla::123", "bla", NULL, NT_STATUS_OBJECT_NAME_INVALID);
6811 ret &= test_stream_name(
6812 "bla:$DATA", "bla", "$DATA:$DATA", NT_STATUS_OK);
6813 ret &= test_stream_name(
6814 "bla:x:$DATA", "bla", "x:$DATA", NT_STATUS_OK);
6815 ret &= test_stream_name(
6816 "bla:x", "bla", "x:$DATA", NT_STATUS_OK);
6821 static bool data_blob_equal(DATA_BLOB a, DATA_BLOB b)
6823 if (a.length != b.length) {
6824 printf("a.length=%d != b.length=%d\n",
6825 (int)a.length, (int)b.length);
6828 if (memcmp(a.data, b.data, a.length) != 0) {
6829 printf("a.data and b.data differ\n");
6835 static bool run_local_memcache(int dummy)
6837 struct memcache *cache;
6839 DATA_BLOB d1, d2, d3;
6840 DATA_BLOB v1, v2, v3;
6842 TALLOC_CTX *mem_ctx;
6844 size_t size1, size2;
6847 cache = memcache_init(NULL, 100);
6849 if (cache == NULL) {
6850 printf("memcache_init failed\n");
6854 d1 = data_blob_const("d1", 2);
6855 d2 = data_blob_const("d2", 2);
6856 d3 = data_blob_const("d3", 2);
6858 k1 = data_blob_const("d1", 2);
6859 k2 = data_blob_const("d2", 2);
6861 memcache_add(cache, STAT_CACHE, k1, d1);
6862 memcache_add(cache, GETWD_CACHE, k2, d2);
6864 if (!memcache_lookup(cache, STAT_CACHE, k1, &v1)) {
6865 printf("could not find k1\n");
6868 if (!data_blob_equal(d1, v1)) {
6872 if (!memcache_lookup(cache, GETWD_CACHE, k2, &v2)) {
6873 printf("could not find k2\n");
6876 if (!data_blob_equal(d2, v2)) {
6880 memcache_add(cache, STAT_CACHE, k1, d3);
6882 if (!memcache_lookup(cache, STAT_CACHE, k1, &v3)) {
6883 printf("could not find replaced k1\n");
6886 if (!data_blob_equal(d3, v3)) {
6890 memcache_add(cache, GETWD_CACHE, k1, d1);
6892 if (memcache_lookup(cache, GETWD_CACHE, k2, &v2)) {
6893 printf("Did find k2, should have been purged\n");
6899 cache = memcache_init(NULL, 0);
6901 mem_ctx = talloc_init("foo");
6903 str1 = talloc_strdup(mem_ctx, "string1");
6904 str2 = talloc_strdup(mem_ctx, "string2");
6906 memcache_add_talloc(cache, SINGLETON_CACHE_TALLOC,
6907 data_blob_string_const("torture"), &str1);
6908 size1 = talloc_total_size(cache);
6910 memcache_add_talloc(cache, SINGLETON_CACHE_TALLOC,
6911 data_blob_string_const("torture"), &str2);
6912 size2 = talloc_total_size(cache);
6914 printf("size1=%d, size2=%d\n", (int)size1, (int)size2);
6916 if (size2 > size1) {
6917 printf("memcache leaks memory!\n");
6927 static void wbclient_done(struct tevent_req *req)
6930 struct winbindd_response *wb_resp;
6931 int *i = (int *)tevent_req_callback_data_void(req);
6933 wbc_err = wb_trans_recv(req, req, &wb_resp);
6936 d_printf("wb_trans_recv %d returned %s\n", *i, wbcErrorString(wbc_err));
6939 static bool run_local_wbclient(int dummy)
6941 struct event_context *ev;
6942 struct wb_context **wb_ctx;
6943 struct winbindd_request wb_req;
6944 bool result = false;
6947 BlockSignals(True, SIGPIPE);
6949 ev = tevent_context_init_byname(talloc_tos(), "epoll");
6954 wb_ctx = TALLOC_ARRAY(ev, struct wb_context *, nprocs);
6955 if (wb_ctx == NULL) {
6959 ZERO_STRUCT(wb_req);
6960 wb_req.cmd = WINBINDD_PING;
6962 d_printf("nprocs=%d, numops=%d\n", (int)nprocs, (int)torture_numops);
6964 for (i=0; i<nprocs; i++) {
6965 wb_ctx[i] = wb_context_init(ev, NULL);
6966 if (wb_ctx[i] == NULL) {
6969 for (j=0; j<torture_numops; j++) {
6970 struct tevent_req *req;
6971 req = wb_trans_send(ev, ev, wb_ctx[i],
6972 (j % 2) == 0, &wb_req);
6976 tevent_req_set_callback(req, wbclient_done, &i);
6982 while (i < nprocs * torture_numops) {
6983 event_loop_once(ev);
6992 static void getaddrinfo_finished(struct tevent_req *req)
6994 char *name = (char *)tevent_req_callback_data_void(req);
6995 struct addrinfo *ainfo;
6998 res = getaddrinfo_recv(req, &ainfo);
7000 d_printf("gai(%s) returned %s\n", name, gai_strerror(res));
7003 d_printf("gai(%s) succeeded\n", name);
7004 freeaddrinfo(ainfo);
7007 static bool run_getaddrinfo_send(int dummy)
7009 TALLOC_CTX *frame = talloc_stackframe();
7010 struct fncall_context *ctx;
7011 struct tevent_context *ev;
7012 bool result = false;
7013 const char *names[4] = { "www.samba.org", "notfound.samba.org",
7014 "www.slashdot.org", "heise.de" };
7015 struct tevent_req *reqs[4];
7018 ev = event_context_init(frame);
7023 ctx = fncall_context_init(frame, 4);
7025 for (i=0; i<ARRAY_SIZE(names); i++) {
7026 reqs[i] = getaddrinfo_send(frame, ev, ctx, names[i], NULL,
7028 if (reqs[i] == NULL) {
7031 tevent_req_set_callback(reqs[i], getaddrinfo_finished,
7035 for (i=0; i<ARRAY_SIZE(reqs); i++) {
7036 tevent_loop_once(ev);
7046 static double create_procs(bool (*fn)(int), bool *result)
7049 volatile pid_t *child_status;
7050 volatile bool *child_status_out;
7056 child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*nprocs);
7057 if (!child_status) {
7058 printf("Failed to setup shared memory\n");
7062 child_status_out = (volatile bool *)shm_setup(sizeof(bool)*nprocs);
7063 if (!child_status_out) {
7064 printf("Failed to setup result status shared memory\n");
7068 for (i = 0; i < nprocs; i++) {
7069 child_status[i] = 0;
7070 child_status_out[i] = True;
7075 for (i=0;i<nprocs;i++) {
7078 pid_t mypid = getpid();
7079 sys_srandom(((int)mypid) ^ ((int)time(NULL)));
7081 slprintf(myname,sizeof(myname),"CLIENT%d", i);
7084 if (torture_open_connection(¤t_cli, i)) break;
7086 printf("pid %d failed to start\n", (int)getpid());
7092 child_status[i] = getpid();
7094 while (child_status[i] && end_timer() < 5) smb_msleep(2);
7096 child_status_out[i] = fn(i);
7103 for (i=0;i<nprocs;i++) {
7104 if (child_status[i]) synccount++;
7106 if (synccount == nprocs) break;
7108 } while (end_timer() < 30);
7110 if (synccount != nprocs) {
7111 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs, synccount);
7116 /* start the client load */
7119 for (i=0;i<nprocs;i++) {
7120 child_status[i] = 0;
7123 printf("%d clients started\n", nprocs);
7125 for (i=0;i<nprocs;i++) {
7126 while (waitpid(0, &status, 0) == -1 && errno == EINTR) /* noop */ ;
7131 for (i=0;i<nprocs;i++) {
7132 if (!child_status_out[i]) {
7139 #define FLAG_MULTIPROC 1
7146 {"FDPASS", run_fdpasstest, 0},
7147 {"LOCK1", run_locktest1, 0},
7148 {"LOCK2", run_locktest2, 0},
7149 {"LOCK3", run_locktest3, 0},
7150 {"LOCK4", run_locktest4, 0},
7151 {"LOCK5", run_locktest5, 0},
7152 {"LOCK6", run_locktest6, 0},
7153 {"LOCK7", run_locktest7, 0},
7154 {"LOCK8", run_locktest8, 0},
7155 {"LOCK9", run_locktest9, 0},
7156 {"UNLINK", run_unlinktest, 0},
7157 {"BROWSE", run_browsetest, 0},
7158 {"ATTR", run_attrtest, 0},
7159 {"TRANS2", run_trans2test, 0},
7160 {"MAXFID", run_maxfidtest, FLAG_MULTIPROC},
7161 {"TORTURE",run_torture, FLAG_MULTIPROC},
7162 {"RANDOMIPC", run_randomipc, 0},
7163 {"NEGNOWAIT", run_negprot_nowait, 0},
7164 {"NBENCH", run_nbench, 0},
7165 {"OPLOCK1", run_oplock1, 0},
7166 {"OPLOCK2", run_oplock2, 0},
7167 {"OPLOCK3", run_oplock3, 0},
7168 {"DIR", run_dirtest, 0},
7169 {"DIR1", run_dirtest1, 0},
7170 {"DENY1", torture_denytest1, 0},
7171 {"DENY2", torture_denytest2, 0},
7172 {"TCON", run_tcon_test, 0},
7173 {"TCONDEV", run_tcon_devtype_test, 0},
7174 {"RW1", run_readwritetest, 0},
7175 {"RW2", run_readwritemulti, FLAG_MULTIPROC},
7176 {"RW3", run_readwritelarge, 0},
7177 {"OPEN", run_opentest, 0},
7178 {"POSIX", run_simple_posix_open_test, 0},
7179 { "UID-REGRESSION-TEST", run_uid_regression_test, 0},
7180 { "SHORTNAME-TEST", run_shortname_test, 0},
7182 {"OPENATTR", run_openattrtest, 0},
7184 {"XCOPY", run_xcopy, 0},
7185 {"RENAME", run_rename, 0},
7186 {"DELETE", run_deletetest, 0},
7187 {"PROPERTIES", run_properties, 0},
7188 {"MANGLE", torture_mangle, 0},
7189 {"MANGLE1", run_mangle1, 0},
7190 {"W2K", run_w2ktest, 0},
7191 {"TRANS2SCAN", torture_trans2_scan, 0},
7192 {"NTTRANSSCAN", torture_nttrans_scan, 0},
7193 {"UTABLE", torture_utable, 0},
7194 {"CASETABLE", torture_casetable, 0},
7195 {"ERRMAPEXTRACT", run_error_map_extract, 0},
7196 {"PIPE_NUMBER", run_pipe_number, 0},
7197 {"TCON2", run_tcon2_test, 0},
7198 {"IOCTL", torture_ioctl_test, 0},
7199 {"CHKPATH", torture_chkpath_test, 0},
7200 {"FDSESS", run_fdsesstest, 0},
7201 { "EATEST", run_eatest, 0},
7202 { "SESSSETUP_BENCH", run_sesssetup_bench, 0},
7203 { "CHAIN1", run_chain1, 0},
7204 { "CHAIN2", run_chain2, 0},
7205 { "WINDOWS-WRITE", run_windows_write, 0},
7206 { "CLI_ECHO", run_cli_echo, 0},
7207 { "GETADDRINFO", run_getaddrinfo_send, 0},
7208 { "TLDAP", run_tldap },
7209 { "STREAMERROR", run_streamerror },
7210 { "NOTIFY-BENCH", run_notify_bench },
7211 { "LOCAL-SUBSTITUTE", run_local_substitute, 0},
7212 { "LOCAL-GENCACHE", run_local_gencache, 0},
7213 { "LOCAL-TALLOC-DICT", run_local_talloc_dict, 0},
7214 { "LOCAL-BASE64", run_local_base64, 0},
7215 { "LOCAL-RBTREE", run_local_rbtree, 0},
7216 { "LOCAL-MEMCACHE", run_local_memcache, 0},
7217 { "LOCAL-STREAM-NAME", run_local_stream_name, 0},
7218 { "LOCAL-WBCLIENT", run_local_wbclient, 0},
7223 /****************************************************************************
7224 run a specified test or "ALL"
7225 ****************************************************************************/
7226 static bool run_test(const char *name)
7233 if (strequal(name,"ALL")) {
7234 for (i=0;torture_ops[i].name;i++) {
7235 run_test(torture_ops[i].name);
7240 for (i=0;torture_ops[i].name;i++) {
7241 fstr_sprintf(randomfname, "\\XX%x",
7242 (unsigned)random());
7244 if (strequal(name, torture_ops[i].name)) {
7246 printf("Running %s\n", name);
7247 if (torture_ops[i].flags & FLAG_MULTIPROC) {
7248 t = create_procs(torture_ops[i].fn, &result);
7251 printf("TEST %s FAILED!\n", name);
7255 if (!torture_ops[i].fn(0)) {
7257 printf("TEST %s FAILED!\n", name);
7261 printf("%s took %g secs\n\n", name, t);
7266 printf("Did not find a test named %s\n", name);
7274 static void usage(void)
7278 printf("WARNING samba4 test suite is much more complete nowadays.\n");
7279 printf("Please use samba4 torture.\n\n");
7281 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
7283 printf("\t-d debuglevel\n");
7284 printf("\t-U user%%pass\n");
7285 printf("\t-k use kerberos\n");
7286 printf("\t-N numprocs\n");
7287 printf("\t-n my_netbios_name\n");
7288 printf("\t-W workgroup\n");
7289 printf("\t-o num_operations\n");
7290 printf("\t-O socket_options\n");
7291 printf("\t-m maximum protocol\n");
7292 printf("\t-L use oplocks\n");
7293 printf("\t-c CLIENT.TXT specify client load file for NBENCH\n");
7294 printf("\t-A showall\n");
7295 printf("\t-p port\n");
7296 printf("\t-s seed\n");
7297 printf("\t-b unclist_filename specify multiple shares for multiple connections\n");
7300 printf("tests are:");
7301 for (i=0;torture_ops[i].name;i++) {
7302 printf(" %s", torture_ops[i].name);
7306 printf("default test is ALL\n");
7311 /****************************************************************************
7313 ****************************************************************************/
7314 int main(int argc,char *argv[])
7320 bool correct = True;
7321 TALLOC_CTX *frame = talloc_stackframe();
7322 int seed = time(NULL);
7326 #ifdef HAVE_SETBUFFER
7327 setbuffer(stdout, NULL, 0);
7332 if (is_default_dyn_CONFIGFILE()) {
7333 if(getenv("SMB_CONF_PATH")) {
7334 set_dyn_CONFIGFILE(getenv("SMB_CONF_PATH"));
7337 lp_load(get_dyn_CONFIGFILE(),True,False,False,True);
7344 for(p = argv[1]; *p; p++)
7348 if (strncmp(argv[1], "//", 2)) {
7352 fstrcpy(host, &argv[1][2]);
7353 p = strchr_m(&host[2],'/');
7358 fstrcpy(share, p+1);
7360 fstrcpy(myname, get_myname(talloc_tos()));
7362 fprintf(stderr, "Failed to get my hostname.\n");
7366 if (*username == 0 && getenv("LOGNAME")) {
7367 fstrcpy(username,getenv("LOGNAME"));
7373 fstrcpy(workgroup, lp_workgroup());
7375 while ((opt = getopt(argc, argv, "p:hW:U:n:N:O:o:m:Ll:d:Aec:ks:b:B:")) != EOF) {
7378 port_to_use = atoi(optarg);
7381 seed = atoi(optarg);
7384 fstrcpy(workgroup,optarg);
7387 max_protocol = interpret_protocol(optarg, max_protocol);
7390 nprocs = atoi(optarg);
7393 torture_numops = atoi(optarg);
7396 DEBUGLEVEL = atoi(optarg);
7405 local_path = optarg;
7408 torture_showall = True;
7411 fstrcpy(myname, optarg);
7414 client_txt = optarg;
7421 use_kerberos = True;
7423 d_printf("No kerberos support compiled in\n");
7429 fstrcpy(username,optarg);
7430 p = strchr_m(username,'%');
7433 fstrcpy(password, p+1);
7438 fstrcpy(multishare_conn_fname, optarg);
7439 use_multishare_conn = True;
7442 torture_blocksize = atoi(optarg);
7445 printf("Unknown option %c (%d)\n", (char)opt, opt);
7450 d_printf("using seed %d\n", seed);
7454 if(use_kerberos && !gotuser) gotpass = True;
7457 p = getpass("Password:");
7459 fstrcpy(password, p);
7464 printf("host=%s share=%s user=%s myname=%s\n",
7465 host, share, username, myname);
7467 if (argc == optind) {
7468 correct = run_test("ALL");
7470 for (i=optind;i<argc;i++) {
7471 if (!run_test(argv[i])) {