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"
28 static fstring host, workgroup, share, password, username, myname;
29 static int max_protocol = PROTOCOL_NT1;
30 static const char *sockops="TCP_NODELAY";
32 static int port_to_use=0;
33 int torture_numops=100;
34 int torture_blocksize=1024*1024;
35 static int procnum; /* records process count number when forking */
36 static struct cli_state *current_cli;
37 static fstring randomfname;
38 static bool use_oplocks;
39 static bool use_level_II_oplocks;
40 static const char *client_txt = "client_oplocks.txt";
41 static bool use_kerberos;
42 static fstring multishare_conn_fname;
43 static bool use_multishare_conn = False;
44 static bool do_encrypt;
45 static const char *local_path = NULL;
47 bool torture_showall = False;
49 static double create_procs(bool (*fn)(int), bool *result);
52 static struct timeval tp1,tp2;
55 void start_timer(void)
60 double end_timer(void)
63 return((tp2.tv_sec - tp1.tv_sec) +
64 (tp2.tv_usec - tp1.tv_usec)*1.0e-6);
68 /* return a pointer to a anonymous shared memory segment of size "size"
69 which will persist across fork() but will disappear when all processes
72 The memory is not zeroed
74 This function uses system5 shared memory. It takes advantage of a property
75 that the memory is not destroyed if it is attached when the id is removed
77 void *shm_setup(int size)
83 shmid = shm_open("private", O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
85 printf("can't get shared memory\n");
88 shm_unlink("private");
89 if (ftruncate(shmid, size) == -1) {
90 printf("can't set shared memory size\n");
93 ret = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, shmid, 0);
94 if (ret == MAP_FAILED) {
95 printf("can't map shared memory\n");
99 shmid = shmget(IPC_PRIVATE, size, S_IRUSR | S_IWUSR);
101 printf("can't get shared memory\n");
104 ret = (void *)shmat(shmid, 0, 0);
105 if (!ret || ret == (void *)-1) {
106 printf("can't attach to shared memory\n");
109 /* the following releases the ipc, but note that this process
110 and all its children will still have access to the memory, its
111 just that the shmid is no longer valid for other shm calls. This
112 means we don't leave behind lots of shm segments after we exit
114 See Stevens "advanced programming in unix env" for details
116 shmctl(shmid, IPC_RMID, 0);
122 /********************************************************************
123 Ensure a connection is encrypted.
124 ********************************************************************/
126 static bool force_cli_encryption(struct cli_state *c,
127 const char *sharename)
130 uint32 caplow, caphigh;
133 if (!SERVER_HAS_UNIX_CIFS(c)) {
134 d_printf("Encryption required and "
135 "server that doesn't support "
136 "UNIX extensions - failing connect\n");
140 status = cli_unix_extensions_version(c, &major, &minor, &caplow,
142 if (!NT_STATUS_IS_OK(status)) {
143 d_printf("Encryption required and "
144 "can't get UNIX CIFS extensions "
145 "version from server: %s\n", nt_errstr(status));
149 if (!(caplow & CIFS_UNIX_TRANSPORT_ENCRYPTION_CAP)) {
150 d_printf("Encryption required and "
151 "share %s doesn't support "
152 "encryption.\n", sharename);
156 if (c->use_kerberos) {
157 status = cli_gss_smb_encryption_start(c);
159 status = cli_raw_ntlm_smb_encryption_start(c,
165 if (!NT_STATUS_IS_OK(status)) {
166 d_printf("Encryption required and "
167 "setup failed with error %s.\n",
176 static struct cli_state *open_nbt_connection(void)
178 struct nmb_name called, calling;
179 struct sockaddr_storage ss;
183 make_nmb_name(&calling, myname, 0x0);
184 make_nmb_name(&called , host, 0x20);
188 if (!(c = cli_initialise())) {
189 printf("Failed initialize cli_struct to connect with %s\n", host);
193 c->port = port_to_use;
195 status = cli_connect(c, host, &ss);
196 if (!NT_STATUS_IS_OK(status)) {
197 printf("Failed to connect with %s. Error %s\n", host, nt_errstr(status) );
201 c->use_kerberos = use_kerberos;
203 c->timeout = 120000; /* set a really long timeout (2 minutes) */
204 if (use_oplocks) c->use_oplocks = True;
205 if (use_level_II_oplocks) c->use_level_II_oplocks = True;
207 if (!cli_session_request(c, &calling, &called)) {
209 * Well, that failed, try *SMBSERVER ...
210 * However, we must reconnect as well ...
212 status = cli_connect(c, host, &ss);
213 if (!NT_STATUS_IS_OK(status)) {
214 printf("Failed to connect with %s. Error %s\n", host, nt_errstr(status) );
218 make_nmb_name(&called, "*SMBSERVER", 0x20);
219 if (!cli_session_request(c, &calling, &called)) {
220 printf("%s rejected the session\n",host);
221 printf("We tried with a called name of %s & %s\n",
231 /* Insert a NULL at the first separator of the given path and return a pointer
232 * to the remainder of the string.
235 terminate_path_at_separator(char * path)
243 if ((p = strchr_m(path, '/'))) {
248 if ((p = strchr_m(path, '\\'))) {
258 parse a //server/share type UNC name
260 bool smbcli_parse_unc(const char *unc_name, TALLOC_CTX *mem_ctx,
261 char **hostname, char **sharename)
265 *hostname = *sharename = NULL;
267 if (strncmp(unc_name, "\\\\", 2) &&
268 strncmp(unc_name, "//", 2)) {
272 *hostname = talloc_strdup(mem_ctx, &unc_name[2]);
273 p = terminate_path_at_separator(*hostname);
276 *sharename = talloc_strdup(mem_ctx, p);
277 terminate_path_at_separator(*sharename);
280 if (*hostname && *sharename) {
284 TALLOC_FREE(*hostname);
285 TALLOC_FREE(*sharename);
289 static bool torture_open_connection_share(struct cli_state **c,
290 const char *hostname,
291 const char *sharename)
298 flags |= CLI_FULL_CONNECTION_USE_KERBEROS;
300 flags |= CLI_FULL_CONNECTION_OPLOCKS;
301 if (use_level_II_oplocks)
302 flags |= CLI_FULL_CONNECTION_LEVEL_II_OPLOCKS;
304 status = cli_full_connection(c, myname,
305 hostname, NULL, port_to_use,
308 password, flags, Undefined, &retry);
309 if (!NT_STATUS_IS_OK(status)) {
310 printf("failed to open share connection: //%s/%s port:%d - %s\n",
311 hostname, sharename, port_to_use, nt_errstr(status));
315 (*c)->timeout = 120000; /* set a really long timeout (2 minutes) */
318 return force_cli_encryption(*c,
324 bool torture_open_connection(struct cli_state **c, int conn_index)
326 char **unc_list = NULL;
327 int num_unc_names = 0;
330 if (use_multishare_conn==True) {
332 unc_list = file_lines_load(multishare_conn_fname, &num_unc_names, 0, NULL);
333 if (!unc_list || num_unc_names <= 0) {
334 printf("Failed to load unc names list from '%s'\n", multishare_conn_fname);
338 if (!smbcli_parse_unc(unc_list[conn_index % num_unc_names],
340 printf("Failed to parse UNC name %s\n",
341 unc_list[conn_index % num_unc_names]);
342 TALLOC_FREE(unc_list);
346 result = torture_open_connection_share(c, h, s);
348 /* h, s were copied earlier */
349 TALLOC_FREE(unc_list);
353 return torture_open_connection_share(c, host, share);
356 bool torture_cli_session_setup2(struct cli_state *cli, uint16 *new_vuid)
358 uint16 old_vuid = cli->vuid;
359 fstring old_user_name;
360 size_t passlen = strlen(password);
364 fstrcpy(old_user_name, cli->user_name);
366 ret = NT_STATUS_IS_OK(cli_session_setup(cli, username,
370 *new_vuid = cli->vuid;
371 cli->vuid = old_vuid;
372 status = cli_set_username(cli, old_user_name);
373 if (!NT_STATUS_IS_OK(status)) {
380 bool torture_close_connection(struct cli_state *c)
384 printf("tdis failed (%s)\n", cli_errstr(c));
394 /* check if the server produced the expected error code */
395 static bool check_error(int line, struct cli_state *c,
396 uint8 eclass, uint32 ecode, NTSTATUS nterr)
398 if (cli_is_dos_error(c)) {
402 /* Check DOS error */
404 cli_dos_error(c, &cclass, &num);
406 if (eclass != cclass || ecode != num) {
407 printf("unexpected error code class=%d code=%d\n",
408 (int)cclass, (int)num);
409 printf(" expected %d/%d %s (line=%d)\n",
410 (int)eclass, (int)ecode, nt_errstr(nterr), line);
419 status = cli_nt_error(c);
421 if (NT_STATUS_V(nterr) != NT_STATUS_V(status)) {
422 printf("unexpected error code %s\n", nt_errstr(status));
423 printf(" expected %s (line=%d)\n", nt_errstr(nterr), line);
432 static bool wait_lock(struct cli_state *c, int fnum, uint32 offset, uint32 len)
434 while (!cli_lock(c, fnum, offset, len, -1, WRITE_LOCK)) {
435 if (!check_error(__LINE__, c, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
441 static bool rw_torture(struct cli_state *c)
443 const char *lockfname = "\\torture.lck";
447 pid_t pid2, pid = getpid();
453 memset(buf, '\0', sizeof(buf));
455 status = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
457 if (!NT_STATUS_IS_OK(status)) {
458 status = cli_open(c, lockfname, O_RDWR, DENY_NONE, &fnum2);
460 if (!NT_STATUS_IS_OK(status)) {
461 printf("open of %s failed (%s)\n", lockfname, cli_errstr(c));
465 for (i=0;i<torture_numops;i++) {
466 unsigned n = (unsigned)sys_random()%10;
468 printf("%d\r", i); fflush(stdout);
470 slprintf(fname, sizeof(fstring) - 1, "\\torture.%u", n);
472 if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) {
476 if (!NT_STATUS_IS_OK(cli_open(c, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL, &fnum))) {
477 printf("open failed (%s)\n", cli_errstr(c));
482 if (cli_write(c, fnum, 0, (char *)&pid, 0, sizeof(pid)) != sizeof(pid)) {
483 printf("write failed (%s)\n", cli_errstr(c));
488 if (cli_write(c, fnum, 0, (char *)buf,
489 sizeof(pid)+(j*sizeof(buf)),
490 sizeof(buf)) != sizeof(buf)) {
491 printf("write failed (%s)\n", cli_errstr(c));
498 if (cli_read(c, fnum, (char *)&pid2, 0, sizeof(pid)) != sizeof(pid)) {
499 printf("read failed (%s)\n", cli_errstr(c));
504 printf("data corruption!\n");
508 if (!NT_STATUS_IS_OK(cli_close(c, fnum))) {
509 printf("close failed (%s)\n", cli_errstr(c));
513 if (!NT_STATUS_IS_OK(cli_unlink(c, fname, aSYSTEM | aHIDDEN))) {
514 printf("unlink failed (%s)\n", cli_errstr(c));
518 if (!NT_STATUS_IS_OK(cli_unlock(c, fnum2, n*sizeof(int), sizeof(int)))) {
519 printf("unlock failed (%s)\n", cli_errstr(c));
525 cli_unlink(c, lockfname, aSYSTEM | aHIDDEN);
532 static bool run_torture(int dummy)
534 struct cli_state *cli;
539 cli_sockopt(cli, sockops);
541 ret = rw_torture(cli);
543 if (!torture_close_connection(cli)) {
550 static bool rw_torture3(struct cli_state *c, char *lockfname)
552 uint16_t fnum = (uint16_t)-1;
557 unsigned countprev = 0;
563 for (i = 0; i < sizeof(buf); i += sizeof(uint32))
565 SIVAL(buf, i, sys_random());
570 if (!NT_STATUS_IS_OK(cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
571 DENY_NONE, &fnum))) {
572 printf("first open read/write of %s failed (%s)\n",
573 lockfname, cli_errstr(c));
579 for (i = 0; i < 500 && fnum == (uint16_t)-1; i++)
581 status = cli_open(c, lockfname, O_RDONLY,
583 if (!NT_STATUS_IS_OK(status)) {
588 if (!NT_STATUS_IS_OK(status)) {
589 printf("second open read-only of %s failed (%s)\n",
590 lockfname, cli_errstr(c));
596 for (count = 0; count < sizeof(buf); count += sent)
598 if (count >= countprev) {
599 printf("%d %8d\r", i, count);
602 countprev += (sizeof(buf) / 20);
607 sent = ((unsigned)sys_random()%(20))+ 1;
608 if (sent > sizeof(buf) - count)
610 sent = sizeof(buf) - count;
613 if (cli_write(c, fnum, 0, buf+count, count, (size_t)sent) != sent) {
614 printf("write failed (%s)\n", cli_errstr(c));
620 sent = cli_read(c, fnum, buf_rd+count, count,
624 printf("read failed offset:%d size:%ld (%s)\n",
625 count, (unsigned long)sizeof(buf)-count,
632 if (memcmp(buf_rd+count, buf+count, sent) != 0)
634 printf("read/write compare failed\n");
635 printf("offset: %d req %ld recvd %ld\n", count, (unsigned long)sizeof(buf)-count, (unsigned long)sent);
644 if (!NT_STATUS_IS_OK(cli_close(c, fnum))) {
645 printf("close failed (%s)\n", cli_errstr(c));
652 static bool rw_torture2(struct cli_state *c1, struct cli_state *c2)
654 const char *lockfname = "\\torture2.lck";
663 if (!NT_STATUS_IS_OK(cli_unlink(c1, lockfname, aSYSTEM | aHIDDEN))) {
664 printf("unlink failed (%s) (normal, this file should not exist)\n", cli_errstr(c1));
667 if (!NT_STATUS_IS_OK(cli_open(c1, lockfname, O_RDWR | O_CREAT | O_EXCL,
668 DENY_NONE, &fnum1))) {
669 printf("first open read/write of %s failed (%s)\n",
670 lockfname, cli_errstr(c1));
673 if (!NT_STATUS_IS_OK(cli_open(c2, lockfname, O_RDONLY,
674 DENY_NONE, &fnum2))) {
675 printf("second open read-only of %s failed (%s)\n",
676 lockfname, cli_errstr(c2));
677 cli_close(c1, fnum1);
681 for (i=0;i<torture_numops;i++)
683 size_t buf_size = ((unsigned)sys_random()%(sizeof(buf)-1))+ 1;
685 printf("%d\r", i); fflush(stdout);
688 generate_random_buffer((unsigned char *)buf, buf_size);
690 if (cli_write(c1, fnum1, 0, buf, 0, buf_size) != buf_size) {
691 printf("write failed (%s)\n", cli_errstr(c1));
696 if ((bytes_read = cli_read(c2, fnum2, buf_rd, 0, buf_size)) != buf_size) {
697 printf("read failed (%s)\n", cli_errstr(c2));
698 printf("read %d, expected %ld\n", (int)bytes_read,
699 (unsigned long)buf_size);
704 if (memcmp(buf_rd, buf, buf_size) != 0)
706 printf("read/write compare failed\n");
712 if (!NT_STATUS_IS_OK(cli_close(c2, fnum2))) {
713 printf("close failed (%s)\n", cli_errstr(c2));
716 if (!NT_STATUS_IS_OK(cli_close(c1, fnum1))) {
717 printf("close failed (%s)\n", cli_errstr(c1));
721 if (!NT_STATUS_IS_OK(cli_unlink(c1, lockfname, aSYSTEM | aHIDDEN))) {
722 printf("unlink failed (%s)\n", cli_errstr(c1));
729 static bool run_readwritetest(int dummy)
731 struct cli_state *cli1, *cli2;
732 bool test1, test2 = False;
734 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
737 cli_sockopt(cli1, sockops);
738 cli_sockopt(cli2, sockops);
740 printf("starting readwritetest\n");
742 test1 = rw_torture2(cli1, cli2);
743 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1));
746 test2 = rw_torture2(cli1, cli1);
747 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2));
750 if (!torture_close_connection(cli1)) {
754 if (!torture_close_connection(cli2)) {
758 return (test1 && test2);
761 static bool run_readwritemulti(int dummy)
763 struct cli_state *cli;
768 cli_sockopt(cli, sockops);
770 printf("run_readwritemulti: fname %s\n", randomfname);
771 test = rw_torture3(cli, randomfname);
773 if (!torture_close_connection(cli)) {
780 static bool run_readwritelarge(int dummy)
782 static struct cli_state *cli1;
784 const char *lockfname = "\\large.dat";
789 if (!torture_open_connection(&cli1, 0)) {
792 cli_sockopt(cli1, sockops);
793 memset(buf,'\0',sizeof(buf));
795 cli1->max_xmit = 128*1024;
797 printf("starting readwritelarge\n");
799 cli_unlink(cli1, lockfname, aSYSTEM | aHIDDEN);
801 if (!NT_STATUS_IS_OK(cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE, &fnum1))) {
802 printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(cli1));
806 cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf));
808 if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
809 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
813 if (fsize == sizeof(buf))
814 printf("readwritelarge test 1 succeeded (size = %lx)\n",
815 (unsigned long)fsize);
817 printf("readwritelarge test 1 failed (size = %lx)\n",
818 (unsigned long)fsize);
822 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
823 printf("close failed (%s)\n", cli_errstr(cli1));
827 if (!NT_STATUS_IS_OK(cli_unlink(cli1, lockfname, aSYSTEM | aHIDDEN))) {
828 printf("unlink failed (%s)\n", cli_errstr(cli1));
832 if (!NT_STATUS_IS_OK(cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE, &fnum1))) {
833 printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(cli1));
837 cli1->max_xmit = 4*1024;
839 cli_smbwrite(cli1, fnum1, buf, 0, sizeof(buf));
841 if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
842 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
846 if (fsize == sizeof(buf))
847 printf("readwritelarge test 2 succeeded (size = %lx)\n",
848 (unsigned long)fsize);
850 printf("readwritelarge test 2 failed (size = %lx)\n",
851 (unsigned long)fsize);
856 /* ToDo - set allocation. JRA */
857 if(!cli_set_allocation_size(cli1, fnum1, 0)) {
858 printf("set allocation size to zero failed (%s)\n", cli_errstr(&cli1));
861 if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
862 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
866 printf("readwritelarge test 3 (truncate test) succeeded (size = %x)\n", fsize);
869 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
870 printf("close failed (%s)\n", cli_errstr(cli1));
874 if (!torture_close_connection(cli1)) {
883 #define ival(s) strtol(s, NULL, 0)
885 /* run a test that simulates an approximate netbench client load */
886 static bool run_netbench(int client)
888 struct cli_state *cli;
893 const char *params[20];
900 cli_sockopt(cli, sockops);
904 slprintf(cname,sizeof(cname)-1, "client%d", client);
906 f = fopen(client_txt, "r");
913 while (fgets(line, sizeof(line)-1, f)) {
917 line[strlen(line)-1] = 0;
919 /* printf("[%d] %s\n", line_count, line); */
921 all_string_sub(line,"client1", cname, sizeof(line));
923 /* parse the command parameters */
924 params[0] = strtok_r(line, " ", &saveptr);
926 while (params[i]) params[++i] = strtok_r(NULL, " ", &saveptr);
932 if (!strncmp(params[0],"SMB", 3)) {
933 printf("ERROR: You are using a dbench 1 load file\n");
937 if (!strcmp(params[0],"NTCreateX")) {
938 nb_createx(params[1], ival(params[2]), ival(params[3]),
940 } else if (!strcmp(params[0],"Close")) {
941 nb_close(ival(params[1]));
942 } else if (!strcmp(params[0],"Rename")) {
943 nb_rename(params[1], params[2]);
944 } else if (!strcmp(params[0],"Unlink")) {
945 nb_unlink(params[1]);
946 } else if (!strcmp(params[0],"Deltree")) {
947 nb_deltree(params[1]);
948 } else if (!strcmp(params[0],"Rmdir")) {
950 } else if (!strcmp(params[0],"QUERY_PATH_INFORMATION")) {
951 nb_qpathinfo(params[1]);
952 } else if (!strcmp(params[0],"QUERY_FILE_INFORMATION")) {
953 nb_qfileinfo(ival(params[1]));
954 } else if (!strcmp(params[0],"QUERY_FS_INFORMATION")) {
955 nb_qfsinfo(ival(params[1]));
956 } else if (!strcmp(params[0],"FIND_FIRST")) {
957 nb_findfirst(params[1]);
958 } else if (!strcmp(params[0],"WriteX")) {
959 nb_writex(ival(params[1]),
960 ival(params[2]), ival(params[3]), ival(params[4]));
961 } else if (!strcmp(params[0],"ReadX")) {
962 nb_readx(ival(params[1]),
963 ival(params[2]), ival(params[3]), ival(params[4]));
964 } else if (!strcmp(params[0],"Flush")) {
965 nb_flush(ival(params[1]));
967 printf("Unknown operation %s\n", params[0]);
975 if (!torture_close_connection(cli)) {
983 /* run a test that simulates an approximate netbench client load */
984 static bool run_nbench(int dummy)
993 signal(SIGALRM, nb_alarm);
995 t = create_procs(run_netbench, &correct);
998 printf("\nThroughput %g MB/sec\n",
999 1.0e-6 * nbio_total() / t);
1005 This test checks for two things:
1007 1) correct support for retaining locks over a close (ie. the server
1008 must not use posix semantics)
1009 2) support for lock timeouts
1011 static bool run_locktest1(int dummy)
1013 struct cli_state *cli1, *cli2;
1014 const char *fname = "\\lockt1.lck";
1015 uint16_t fnum1, fnum2, fnum3;
1017 unsigned lock_timeout;
1019 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1022 cli_sockopt(cli1, sockops);
1023 cli_sockopt(cli2, sockops);
1025 printf("starting locktest1\n");
1027 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
1029 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
1030 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
1033 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum2))) {
1034 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli1));
1037 if (!NT_STATUS_IS_OK(cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum3))) {
1038 printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli2));
1042 if (!cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
1043 printf("lock1 failed (%s)\n", cli_errstr(cli1));
1048 if (cli_lock(cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
1049 printf("lock2 succeeded! This is a locking bug\n");
1052 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
1053 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1057 lock_timeout = (1 + (random() % 20));
1058 printf("Testing lock timeout with timeout=%u\n", lock_timeout);
1060 if (cli_lock(cli2, fnum3, 0, 4, lock_timeout * 1000, WRITE_LOCK)) {
1061 printf("lock3 succeeded! This is a locking bug\n");
1064 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
1065 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
1069 if (ABS(t2 - t1) < lock_timeout-1) {
1070 printf("error: This server appears not to support timed lock requests\n");
1073 printf("server slept for %u seconds for a %u second timeout\n",
1074 (unsigned int)(t2-t1), lock_timeout);
1076 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum2))) {
1077 printf("close1 failed (%s)\n", cli_errstr(cli1));
1081 if (cli_lock(cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
1082 printf("lock4 succeeded! This is a locking bug\n");
1085 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
1086 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
1089 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
1090 printf("close2 failed (%s)\n", cli_errstr(cli1));
1094 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum3))) {
1095 printf("close3 failed (%s)\n", cli_errstr(cli2));
1099 if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname, aSYSTEM | aHIDDEN))) {
1100 printf("unlink failed (%s)\n", cli_errstr(cli1));
1105 if (!torture_close_connection(cli1)) {
1109 if (!torture_close_connection(cli2)) {
1113 printf("Passed locktest1\n");
1118 this checks to see if a secondary tconx can use open files from an
1121 static bool run_tcon_test(int dummy)
1123 static struct cli_state *cli;
1124 const char *fname = "\\tcontest.tmp";
1126 uint16 cnum1, cnum2, cnum3;
1127 uint16 vuid1, vuid2;
1132 memset(buf, '\0', sizeof(buf));
1134 if (!torture_open_connection(&cli, 0)) {
1137 cli_sockopt(cli, sockops);
1139 printf("starting tcontest\n");
1141 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
1143 if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
1144 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
1151 if (cli_write(cli, fnum1, 0, buf, 130, 4) != 4) {
1152 printf("initial write failed (%s)", cli_errstr(cli));
1156 status = cli_tcon_andx(cli, share, "?????",
1157 password, strlen(password)+1);
1158 if (!NT_STATUS_IS_OK(status)) {
1159 printf("%s refused 2nd tree connect (%s)\n", host,
1166 cnum3 = MAX(cnum1, cnum2) + 1; /* any invalid number */
1167 vuid2 = cli->vuid + 1;
1169 /* try a write with the wrong tid */
1172 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
1173 printf("* server allows write with wrong TID\n");
1176 printf("server fails write with wrong TID : %s\n", cli_errstr(cli));
1180 /* try a write with an invalid tid */
1183 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
1184 printf("* server allows write with invalid TID\n");
1187 printf("server fails write with invalid TID : %s\n", cli_errstr(cli));
1190 /* try a write with an invalid vuid */
1194 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
1195 printf("* server allows write with invalid VUID\n");
1198 printf("server fails write with invalid VUID : %s\n", cli_errstr(cli));
1204 if (!NT_STATUS_IS_OK(cli_close(cli, fnum1))) {
1205 printf("close failed (%s)\n", cli_errstr(cli));
1211 if (!cli_tdis(cli)) {
1212 printf("secondary tdis failed (%s)\n", cli_errstr(cli));
1218 if (!torture_close_connection(cli)) {
1227 checks for old style tcon support
1229 static bool run_tcon2_test(int dummy)
1231 static struct cli_state *cli;
1232 uint16 cnum, max_xmit;
1236 if (!torture_open_connection(&cli, 0)) {
1239 cli_sockopt(cli, sockops);
1241 printf("starting tcon2 test\n");
1243 if (asprintf(&service, "\\\\%s\\%s", host, share) == -1) {
1247 status = cli_raw_tcon(cli, service, password, "?????", &max_xmit, &cnum);
1249 if (!NT_STATUS_IS_OK(status)) {
1250 printf("tcon2 failed : %s\n", cli_errstr(cli));
1252 printf("tcon OK : max_xmit=%d cnum=%d tid=%d\n",
1253 (int)max_xmit, (int)cnum, SVAL(cli->inbuf, smb_tid));
1256 if (!torture_close_connection(cli)) {
1260 printf("Passed tcon2 test\n");
1264 static bool tcon_devtest(struct cli_state *cli,
1265 const char *myshare, const char *devtype,
1266 const char *return_devtype,
1267 NTSTATUS expected_error)
1272 status = cli_tcon_andx(cli, myshare, devtype,
1273 password, strlen(password)+1);
1275 if (NT_STATUS_IS_OK(expected_error)) {
1276 if (NT_STATUS_IS_OK(status)) {
1277 if (strcmp(cli->dev, return_devtype) == 0) {
1280 printf("tconX to share %s with type %s "
1281 "succeeded but returned the wrong "
1282 "device type (got [%s] but should have got [%s])\n",
1283 myshare, devtype, cli->dev, return_devtype);
1287 printf("tconX to share %s with type %s "
1288 "should have succeeded but failed\n",
1294 if (NT_STATUS_IS_OK(status)) {
1295 printf("tconx to share %s with type %s "
1296 "should have failed but succeeded\n",
1300 if (NT_STATUS_EQUAL(cli_nt_error(cli),
1304 printf("Returned unexpected error\n");
1313 checks for correct tconX support
1315 static bool run_tcon_devtype_test(int dummy)
1317 static struct cli_state *cli1 = NULL;
1323 status = cli_full_connection(&cli1, myname,
1324 host, NULL, port_to_use,
1326 username, workgroup,
1327 password, flags, Undefined, &retry);
1329 if (!NT_STATUS_IS_OK(status)) {
1330 printf("could not open connection\n");
1334 if (!tcon_devtest(cli1, "IPC$", "A:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1337 if (!tcon_devtest(cli1, "IPC$", "?????", "IPC", NT_STATUS_OK))
1340 if (!tcon_devtest(cli1, "IPC$", "LPT:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1343 if (!tcon_devtest(cli1, "IPC$", "IPC", "IPC", NT_STATUS_OK))
1346 if (!tcon_devtest(cli1, "IPC$", "FOOBA", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1349 if (!tcon_devtest(cli1, share, "A:", "A:", NT_STATUS_OK))
1352 if (!tcon_devtest(cli1, share, "?????", "A:", NT_STATUS_OK))
1355 if (!tcon_devtest(cli1, share, "LPT:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1358 if (!tcon_devtest(cli1, share, "IPC", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1361 if (!tcon_devtest(cli1, share, "FOOBA", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1367 printf("Passed tcondevtest\n");
1374 This test checks that
1376 1) the server supports multiple locking contexts on the one SMB
1377 connection, distinguished by PID.
1379 2) the server correctly fails overlapping locks made by the same PID (this
1380 goes against POSIX behaviour, which is why it is tricky to implement)
1382 3) the server denies unlock requests by an incorrect client PID
1384 static bool run_locktest2(int dummy)
1386 static struct cli_state *cli;
1387 const char *fname = "\\lockt2.lck";
1388 uint16_t fnum1, fnum2, fnum3;
1389 bool correct = True;
1391 if (!torture_open_connection(&cli, 0)) {
1395 cli_sockopt(cli, sockops);
1397 printf("starting locktest2\n");
1399 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
1403 if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
1404 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
1408 if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum2))) {
1409 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli));
1415 if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum3))) {
1416 printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli));
1422 if (!cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
1423 printf("lock1 failed (%s)\n", cli_errstr(cli));
1427 if (cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
1428 printf("WRITE lock1 succeeded! This is a locking bug\n");
1431 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1432 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1435 if (cli_lock(cli, fnum2, 0, 4, 0, WRITE_LOCK)) {
1436 printf("WRITE lock2 succeeded! This is a locking bug\n");
1439 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1440 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1443 if (cli_lock(cli, fnum2, 0, 4, 0, READ_LOCK)) {
1444 printf("READ lock2 succeeded! This is a locking bug\n");
1447 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1448 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
1451 if (!cli_lock(cli, fnum1, 100, 4, 0, WRITE_LOCK)) {
1452 printf("lock at 100 failed (%s)\n", cli_errstr(cli));
1455 if (NT_STATUS_IS_OK(cli_unlock(cli, fnum1, 100, 4))) {
1456 printf("unlock at 100 succeeded! This is a locking bug\n");
1460 if (NT_STATUS_IS_OK(cli_unlock(cli, fnum1, 0, 4))) {
1461 printf("unlock1 succeeded! This is a locking bug\n");
1464 if (!check_error(__LINE__, cli,
1466 NT_STATUS_RANGE_NOT_LOCKED)) return False;
1469 if (NT_STATUS_IS_OK(cli_unlock(cli, fnum1, 0, 8))) {
1470 printf("unlock2 succeeded! This is a locking bug\n");
1473 if (!check_error(__LINE__, cli,
1475 NT_STATUS_RANGE_NOT_LOCKED)) return False;
1478 if (cli_lock(cli, fnum3, 0, 4, 0, WRITE_LOCK)) {
1479 printf("lock3 succeeded! This is a locking bug\n");
1482 if (!check_error(__LINE__, cli, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
1487 if (!NT_STATUS_IS_OK(cli_close(cli, fnum1))) {
1488 printf("close1 failed (%s)\n", cli_errstr(cli));
1492 if (!NT_STATUS_IS_OK(cli_close(cli, fnum2))) {
1493 printf("close2 failed (%s)\n", cli_errstr(cli));
1497 if (!NT_STATUS_IS_OK(cli_close(cli, fnum3))) {
1498 printf("close3 failed (%s)\n", cli_errstr(cli));
1502 if (!torture_close_connection(cli)) {
1506 printf("locktest2 finished\n");
1513 This test checks that
1515 1) the server supports the full offset range in lock requests
1517 static bool run_locktest3(int dummy)
1519 static struct cli_state *cli1, *cli2;
1520 const char *fname = "\\lockt3.lck";
1521 uint16_t fnum1, fnum2;
1524 bool correct = True;
1526 #define NEXT_OFFSET offset += (~(uint32)0) / torture_numops
1528 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1531 cli_sockopt(cli1, sockops);
1532 cli_sockopt(cli2, sockops);
1534 printf("starting locktest3\n");
1536 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
1538 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
1539 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
1542 if (!NT_STATUS_IS_OK(cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2))) {
1543 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli2));
1547 for (offset=i=0;i<torture_numops;i++) {
1549 if (!cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1550 printf("lock1 %d failed (%s)\n",
1556 if (!cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1557 printf("lock2 %d failed (%s)\n",
1564 for (offset=i=0;i<torture_numops;i++) {
1567 if (cli_lock(cli1, fnum1, offset-2, 1, 0, WRITE_LOCK)) {
1568 printf("error: lock1 %d succeeded!\n", i);
1572 if (cli_lock(cli2, fnum2, offset-1, 1, 0, WRITE_LOCK)) {
1573 printf("error: lock2 %d succeeded!\n", i);
1577 if (cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1578 printf("error: lock3 %d succeeded!\n", i);
1582 if (cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1583 printf("error: lock4 %d succeeded!\n", i);
1588 for (offset=i=0;i<torture_numops;i++) {
1591 if (!NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, offset-1, 1))) {
1592 printf("unlock1 %d failed (%s)\n",
1598 if (!NT_STATUS_IS_OK(cli_unlock(cli2, fnum2, offset-2, 1))) {
1599 printf("unlock2 %d failed (%s)\n",
1606 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
1607 printf("close1 failed (%s)\n", cli_errstr(cli1));
1611 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
1612 printf("close2 failed (%s)\n", cli_errstr(cli2));
1616 if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname, aSYSTEM | aHIDDEN))) {
1617 printf("unlink failed (%s)\n", cli_errstr(cli1));
1621 if (!torture_close_connection(cli1)) {
1625 if (!torture_close_connection(cli2)) {
1629 printf("finished locktest3\n");
1634 #define EXPECTED(ret, v) if ((ret) != (v)) { \
1635 printf("** "); correct = False; \
1639 looks at overlapping locks
1641 static bool run_locktest4(int dummy)
1643 static struct cli_state *cli1, *cli2;
1644 const char *fname = "\\lockt4.lck";
1645 uint16_t fnum1, fnum2, f;
1648 bool correct = True;
1650 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1654 cli_sockopt(cli1, sockops);
1655 cli_sockopt(cli2, sockops);
1657 printf("starting locktest4\n");
1659 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
1661 cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
1662 cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
1664 memset(buf, 0, sizeof(buf));
1666 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1667 printf("Failed to create file\n");
1672 ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1673 cli_lock(cli1, fnum1, 2, 4, 0, WRITE_LOCK);
1674 EXPECTED(ret, False);
1675 printf("the same process %s set overlapping write locks\n", ret?"can":"cannot");
1677 ret = cli_lock(cli1, fnum1, 10, 4, 0, READ_LOCK) &&
1678 cli_lock(cli1, fnum1, 12, 4, 0, READ_LOCK);
1679 EXPECTED(ret, True);
1680 printf("the same process %s set overlapping read locks\n", ret?"can":"cannot");
1682 ret = cli_lock(cli1, fnum1, 20, 4, 0, WRITE_LOCK) &&
1683 cli_lock(cli2, fnum2, 22, 4, 0, WRITE_LOCK);
1684 EXPECTED(ret, False);
1685 printf("a different connection %s set overlapping write locks\n", ret?"can":"cannot");
1687 ret = cli_lock(cli1, fnum1, 30, 4, 0, READ_LOCK) &&
1688 cli_lock(cli2, fnum2, 32, 4, 0, READ_LOCK);
1689 EXPECTED(ret, True);
1690 printf("a different connection %s set overlapping read locks\n", ret?"can":"cannot");
1692 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 40, 4, 0, WRITE_LOCK)) &&
1693 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 42, 4, 0, WRITE_LOCK));
1694 EXPECTED(ret, False);
1695 printf("a different pid %s set overlapping write locks\n", ret?"can":"cannot");
1697 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 50, 4, 0, READ_LOCK)) &&
1698 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 52, 4, 0, READ_LOCK));
1699 EXPECTED(ret, True);
1700 printf("a different pid %s set overlapping read locks\n", ret?"can":"cannot");
1702 ret = cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK) &&
1703 cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK);
1704 EXPECTED(ret, True);
1705 printf("the same process %s set the same read lock twice\n", ret?"can":"cannot");
1707 ret = cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK) &&
1708 cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK);
1709 EXPECTED(ret, False);
1710 printf("the same process %s set the same write lock twice\n", ret?"can":"cannot");
1712 ret = cli_lock(cli1, fnum1, 80, 4, 0, READ_LOCK) &&
1713 cli_lock(cli1, fnum1, 80, 4, 0, WRITE_LOCK);
1714 EXPECTED(ret, False);
1715 printf("the same process %s overlay a read lock with a write lock\n", ret?"can":"cannot");
1717 ret = cli_lock(cli1, fnum1, 90, 4, 0, WRITE_LOCK) &&
1718 cli_lock(cli1, fnum1, 90, 4, 0, READ_LOCK);
1719 EXPECTED(ret, True);
1720 printf("the same process %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1722 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 100, 4, 0, WRITE_LOCK)) &&
1723 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 100, 4, 0, READ_LOCK));
1724 EXPECTED(ret, False);
1725 printf("a different pid %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1727 ret = cli_lock(cli1, fnum1, 110, 4, 0, READ_LOCK) &&
1728 cli_lock(cli1, fnum1, 112, 4, 0, READ_LOCK) &&
1729 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 110, 6));
1730 EXPECTED(ret, False);
1731 printf("the same process %s coalesce read locks\n", ret?"can":"cannot");
1734 ret = cli_lock(cli1, fnum1, 120, 4, 0, WRITE_LOCK) &&
1735 (cli_read(cli2, fnum2, buf, 120, 4) == 4);
1736 EXPECTED(ret, False);
1737 printf("this server %s strict write locking\n", ret?"doesn't do":"does");
1739 ret = cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK) &&
1740 (cli_write(cli2, fnum2, 0, buf, 130, 4) == 4);
1741 EXPECTED(ret, False);
1742 printf("this server %s strict read locking\n", ret?"doesn't do":"does");
1745 ret = cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1746 cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1747 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 140, 4)) &&
1748 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 140, 4));
1749 EXPECTED(ret, True);
1750 printf("this server %s do recursive read locking\n", ret?"does":"doesn't");
1753 ret = cli_lock(cli1, fnum1, 150, 4, 0, WRITE_LOCK) &&
1754 cli_lock(cli1, fnum1, 150, 4, 0, READ_LOCK) &&
1755 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 150, 4)) &&
1756 (cli_read(cli2, fnum2, buf, 150, 4) == 4) &&
1757 !(cli_write(cli2, fnum2, 0, buf, 150, 4) == 4) &&
1758 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 150, 4));
1759 EXPECTED(ret, True);
1760 printf("this server %s do recursive lock overlays\n", ret?"does":"doesn't");
1762 ret = cli_lock(cli1, fnum1, 160, 4, 0, READ_LOCK) &&
1763 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 160, 4)) &&
1764 (cli_write(cli2, fnum2, 0, buf, 160, 4) == 4) &&
1765 (cli_read(cli2, fnum2, buf, 160, 4) == 4);
1766 EXPECTED(ret, True);
1767 printf("the same process %s remove a read lock using write locking\n", ret?"can":"cannot");
1769 ret = cli_lock(cli1, fnum1, 170, 4, 0, WRITE_LOCK) &&
1770 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 170, 4)) &&
1771 (cli_write(cli2, fnum2, 0, buf, 170, 4) == 4) &&
1772 (cli_read(cli2, fnum2, buf, 170, 4) == 4);
1773 EXPECTED(ret, True);
1774 printf("the same process %s remove a write lock using read locking\n", ret?"can":"cannot");
1776 ret = cli_lock(cli1, fnum1, 190, 4, 0, WRITE_LOCK) &&
1777 cli_lock(cli1, fnum1, 190, 4, 0, READ_LOCK) &&
1778 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 190, 4)) &&
1779 !(cli_write(cli2, fnum2, 0, buf, 190, 4) == 4) &&
1780 (cli_read(cli2, fnum2, buf, 190, 4) == 4);
1781 EXPECTED(ret, True);
1782 printf("the same process %s remove the first lock first\n", ret?"does":"doesn't");
1784 cli_close(cli1, fnum1);
1785 cli_close(cli2, fnum2);
1786 cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
1787 cli_open(cli1, fname, O_RDWR, DENY_NONE, &f);
1788 ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1789 cli_lock(cli1, f, 0, 1, 0, READ_LOCK) &&
1790 NT_STATUS_IS_OK(cli_close(cli1, fnum1)) &&
1791 NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1)) &&
1792 cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1794 cli_close(cli1, fnum1);
1795 EXPECTED(ret, True);
1796 printf("the server %s have the NT byte range lock bug\n", !ret?"does":"doesn't");
1799 cli_close(cli1, fnum1);
1800 cli_close(cli2, fnum2);
1801 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
1802 torture_close_connection(cli1);
1803 torture_close_connection(cli2);
1805 printf("finished locktest4\n");
1810 looks at lock upgrade/downgrade.
1812 static bool run_locktest5(int dummy)
1814 static struct cli_state *cli1, *cli2;
1815 const char *fname = "\\lockt5.lck";
1816 uint16_t fnum1, fnum2, fnum3;
1819 bool correct = True;
1821 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
1825 cli_sockopt(cli1, sockops);
1826 cli_sockopt(cli2, sockops);
1828 printf("starting locktest5\n");
1830 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
1832 cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
1833 cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
1834 cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum3);
1836 memset(buf, 0, sizeof(buf));
1838 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1839 printf("Failed to create file\n");
1844 /* Check for NT bug... */
1845 ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1846 cli_lock(cli1, fnum3, 0, 1, 0, READ_LOCK);
1847 cli_close(cli1, fnum1);
1848 cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
1849 ret = cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1850 EXPECTED(ret, True);
1851 printf("this server %s the NT locking bug\n", ret ? "doesn't have" : "has");
1852 cli_close(cli1, fnum1);
1853 cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
1854 cli_unlock(cli1, fnum3, 0, 1);
1856 ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1857 cli_lock(cli1, fnum1, 1, 1, 0, READ_LOCK);
1858 EXPECTED(ret, True);
1859 printf("the same process %s overlay a write with a read lock\n", ret?"can":"cannot");
1861 ret = cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK);
1862 EXPECTED(ret, False);
1864 printf("a different processs %s get a read lock on the first process lock stack\n", ret?"can":"cannot");
1866 /* Unlock the process 2 lock. */
1867 cli_unlock(cli2, fnum2, 0, 4);
1869 ret = cli_lock(cli1, fnum3, 0, 4, 0, READ_LOCK);
1870 EXPECTED(ret, False);
1872 printf("the same processs on a different fnum %s get a read lock\n", ret?"can":"cannot");
1874 /* Unlock the process 1 fnum3 lock. */
1875 cli_unlock(cli1, fnum3, 0, 4);
1877 /* Stack 2 more locks here. */
1878 ret = cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK) &&
1879 cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK);
1881 EXPECTED(ret, True);
1882 printf("the same process %s stack read locks\n", ret?"can":"cannot");
1884 /* Unlock the first process lock, then check this was the WRITE lock that was
1887 ret = NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 0, 4)) &&
1888 cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK);
1890 EXPECTED(ret, True);
1891 printf("the first unlock removes the %s lock\n", ret?"WRITE":"READ");
1893 /* Unlock the process 2 lock. */
1894 cli_unlock(cli2, fnum2, 0, 4);
1896 /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */
1898 ret = NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 1, 1)) &&
1899 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 0, 4)) &&
1900 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 0, 4));
1902 EXPECTED(ret, True);
1903 printf("the same process %s unlock the stack of 4 locks\n", ret?"can":"cannot");
1905 /* Ensure the next unlock fails. */
1906 ret = NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 0, 4));
1907 EXPECTED(ret, False);
1908 printf("the same process %s count the lock stack\n", !ret?"can":"cannot");
1910 /* Ensure connection 2 can get a write lock. */
1911 ret = cli_lock(cli2, fnum2, 0, 4, 0, WRITE_LOCK);
1912 EXPECTED(ret, True);
1914 printf("a different processs %s get a write lock on the unlocked stack\n", ret?"can":"cannot");
1918 cli_close(cli1, fnum1);
1919 cli_close(cli2, fnum2);
1920 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
1921 if (!torture_close_connection(cli1)) {
1924 if (!torture_close_connection(cli2)) {
1928 printf("finished locktest5\n");
1934 tries the unusual lockingX locktype bits
1936 static bool run_locktest6(int dummy)
1938 static struct cli_state *cli;
1939 const char *fname[1] = { "\\lock6.txt" };
1944 if (!torture_open_connection(&cli, 0)) {
1948 cli_sockopt(cli, sockops);
1950 printf("starting locktest6\n");
1953 printf("Testing %s\n", fname[i]);
1955 cli_unlink(cli, fname[i], aSYSTEM | aHIDDEN);
1957 cli_open(cli, fname[i], O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
1958 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE);
1959 cli_close(cli, fnum);
1960 printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status));
1962 cli_open(cli, fname[i], O_RDWR, DENY_NONE, &fnum);
1963 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK);
1964 cli_close(cli, fnum);
1965 printf("CANCEL_LOCK gave %s\n", nt_errstr(status));
1967 cli_unlink(cli, fname[i], aSYSTEM | aHIDDEN);
1970 torture_close_connection(cli);
1972 printf("finished locktest6\n");
1976 static bool run_locktest7(int dummy)
1978 struct cli_state *cli1;
1979 const char *fname = "\\lockt7.lck";
1982 bool correct = False;
1984 if (!torture_open_connection(&cli1, 0)) {
1988 cli_sockopt(cli1, sockops);
1990 printf("starting locktest7\n");
1992 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
1994 cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
1996 memset(buf, 0, sizeof(buf));
1998 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1999 printf("Failed to create file\n");
2003 cli_setpid(cli1, 1);
2005 if (!cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK)) {
2006 printf("Unable to apply read lock on range 130:4, error was %s\n", cli_errstr(cli1));
2009 printf("pid1 successfully locked range 130:4 for READ\n");
2012 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
2013 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
2016 printf("pid1 successfully read the range 130:4\n");
2019 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
2020 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
2021 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
2022 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2026 printf("pid1 successfully wrote to the range 130:4 (should be denied)\n");
2030 cli_setpid(cli1, 2);
2032 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
2033 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
2035 printf("pid2 successfully read the range 130:4\n");
2038 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
2039 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
2040 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
2041 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2045 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
2049 cli_setpid(cli1, 1);
2050 cli_unlock(cli1, fnum1, 130, 4);
2052 if (!cli_lock(cli1, fnum1, 130, 4, 0, WRITE_LOCK)) {
2053 printf("Unable to apply write lock on range 130:4, error was %s\n", cli_errstr(cli1));
2056 printf("pid1 successfully locked range 130:4 for WRITE\n");
2059 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
2060 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
2063 printf("pid1 successfully read the range 130:4\n");
2066 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
2067 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
2070 printf("pid1 successfully wrote to the range 130:4\n");
2073 cli_setpid(cli1, 2);
2075 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
2076 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
2077 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
2078 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2082 printf("pid2 successfully read the range 130:4 (should be denied)\n");
2086 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
2087 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
2088 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
2089 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2093 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
2097 cli_unlock(cli1, fnum1, 130, 0);
2101 cli_close(cli1, fnum1);
2102 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
2103 torture_close_connection(cli1);
2105 printf("finished locktest7\n");
2110 * This demonstrates a problem with our use of GPFS share modes: A file
2111 * descriptor sitting in the pending close queue holding a GPFS share mode
2112 * blocks opening a file another time. Happens with Word 2007 temp files.
2113 * With "posix locking = yes" and "gpfs:sharemodes = yes" enabled, the third
2114 * open is denied with NT_STATUS_SHARING_VIOLATION.
2117 static bool run_locktest8(int dummy)
2119 struct cli_state *cli1;
2120 const char *fname = "\\lockt8.lck";
2121 uint16_t fnum1, fnum2;
2123 bool correct = False;
2126 if (!torture_open_connection(&cli1, 0)) {
2130 cli_sockopt(cli1, sockops);
2132 printf("starting locktest8\n");
2134 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
2136 status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_WRITE,
2138 if (!NT_STATUS_IS_OK(status)) {
2139 d_fprintf(stderr, "cli_open returned %s\n", cli_errstr(cli1));
2143 memset(buf, 0, sizeof(buf));
2145 status = cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum2);
2146 if (!NT_STATUS_IS_OK(status)) {
2147 d_fprintf(stderr, "cli_open second time returned %s\n",
2152 if (!cli_lock(cli1, fnum2, 1, 1, 0, READ_LOCK)) {
2153 printf("Unable to apply read lock on range 1:1, error was "
2154 "%s\n", cli_errstr(cli1));
2158 status = cli_close(cli1, fnum1);
2159 if (!NT_STATUS_IS_OK(status)) {
2160 d_fprintf(stderr, "cli_close(fnum1) %s\n", cli_errstr(cli1));
2164 status = cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
2165 if (!NT_STATUS_IS_OK(status)) {
2166 d_fprintf(stderr, "cli_open third time returned %s\n",
2174 cli_close(cli1, fnum1);
2175 cli_close(cli1, fnum2);
2176 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
2177 torture_close_connection(cli1);
2179 printf("finished locktest8\n");
2184 * This test is designed to be run in conjunction with
2185 * external NFS or POSIX locks taken in the filesystem.
2186 * It checks that the smbd server will block until the
2187 * lock is released and then acquire it. JRA.
2190 static bool got_alarm;
2191 static int alarm_fd;
2193 static void alarm_handler(int dummy)
2198 static void alarm_handler_parent(int dummy)
2203 static void do_local_lock(int read_fd, int write_fd)
2208 const char *local_pathname = NULL;
2211 local_pathname = talloc_asprintf(talloc_tos(),
2212 "%s/lockt9.lck", local_path);
2213 if (!local_pathname) {
2214 printf("child: alloc fail\n");
2218 unlink(local_pathname);
2219 fd = open(local_pathname, O_RDWR|O_CREAT, 0666);
2221 printf("child: open of %s failed %s.\n",
2222 local_pathname, strerror(errno));
2226 /* Now take a fcntl lock. */
2227 lock.l_type = F_WRLCK;
2228 lock.l_whence = SEEK_SET;
2231 lock.l_pid = getpid();
2233 ret = fcntl(fd,F_SETLK,&lock);
2235 printf("child: failed to get lock 0:4 on file %s. Error %s\n",
2236 local_pathname, strerror(errno));
2239 printf("child: got lock 0:4 on file %s.\n",
2244 CatchSignal(SIGALRM, alarm_handler);
2246 /* Signal the parent. */
2247 if (write(write_fd, &c, 1) != 1) {
2248 printf("child: start signal fail %s.\n",
2255 /* Wait for the parent to be ready. */
2256 if (read(read_fd, &c, 1) != 1) {
2257 printf("child: reply signal fail %s.\n",
2265 printf("child: released lock 0:4 on file %s.\n",
2271 static bool run_locktest9(int dummy)
2273 struct cli_state *cli1;
2274 const char *fname = "\\lockt9.lck";
2276 bool correct = False;
2277 int pipe_in[2], pipe_out[2];
2284 printf("starting locktest9\n");
2286 if (local_path == NULL) {
2287 d_fprintf(stderr, "locktest9 must be given a local path via -l <localpath>\n");
2291 if (pipe(pipe_in) == -1 || pipe(pipe_out) == -1) {
2296 if (child_pid == -1) {
2300 if (child_pid == 0) {
2302 do_local_lock(pipe_out[0], pipe_in[1]);
2312 ret = read(pipe_in[0], &c, 1);
2314 d_fprintf(stderr, "failed to read start signal from child. %s\n",
2319 if (!torture_open_connection(&cli1, 0)) {
2323 cli_sockopt(cli1, sockops);
2325 status = cli_open(cli1, fname, O_RDWR, DENY_NONE,
2327 if (!NT_STATUS_IS_OK(status)) {
2328 d_fprintf(stderr, "cli_open returned %s\n", cli_errstr(cli1));
2332 /* Ensure the child has the lock. */
2333 if (cli_lock(cli1, fnum, 0, 4, 0, WRITE_LOCK)) {
2334 d_fprintf(stderr, "Got the lock on range 0:4 - this should not happen !\n");
2337 d_printf("Child has the lock.\n");
2340 /* Tell the child to wait 5 seconds then exit. */
2341 ret = write(pipe_out[1], &c, 1);
2343 d_fprintf(stderr, "failed to send exit signal to child. %s\n",
2348 /* Wait 20 seconds for the lock. */
2349 alarm_fd = cli1->fd;
2350 CatchSignal(SIGALRM, alarm_handler_parent);
2355 if (!cli_lock(cli1, fnum, 0, 4, -1, WRITE_LOCK)) {
2356 d_fprintf(stderr, "Unable to apply write lock on range 0:4, error was "
2357 "%s\n", cli_errstr(cli1));
2362 seconds = end_timer();
2364 printf("Parent got the lock after %.2f seconds.\n",
2367 status = cli_close(cli1, fnum);
2368 if (!NT_STATUS_IS_OK(status)) {
2369 d_fprintf(stderr, "cli_close(fnum1) %s\n", cli_errstr(cli1));
2376 cli_close(cli1, fnum);
2377 torture_close_connection(cli1);
2381 printf("finished locktest9\n");
2386 test whether fnums and tids open on one VC are available on another (a major
2389 static bool run_fdpasstest(int dummy)
2391 struct cli_state *cli1, *cli2;
2392 const char *fname = "\\fdpass.tst";
2396 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
2399 cli_sockopt(cli1, sockops);
2400 cli_sockopt(cli2, sockops);
2402 printf("starting fdpasstest\n");
2404 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
2406 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
2407 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2411 if (cli_write(cli1, fnum1, 0, "hello world\n", 0, 13) != 13) {
2412 printf("write failed (%s)\n", cli_errstr(cli1));
2416 cli2->vuid = cli1->vuid;
2417 cli2->cnum = cli1->cnum;
2418 cli2->pid = cli1->pid;
2420 if (cli_read(cli2, fnum1, buf, 0, 13) == 13) {
2421 printf("read succeeded! nasty security hole [%s]\n",
2426 cli_close(cli1, fnum1);
2427 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
2429 torture_close_connection(cli1);
2430 torture_close_connection(cli2);
2432 printf("finished fdpasstest\n");
2436 static bool run_fdsesstest(int dummy)
2438 struct cli_state *cli;
2443 const char *fname = "\\fdsess.tst";
2444 const char *fname1 = "\\fdsess1.tst";
2450 if (!torture_open_connection(&cli, 0))
2452 cli_sockopt(cli, sockops);
2454 if (!torture_cli_session_setup2(cli, &new_vuid))
2457 saved_cnum = cli->cnum;
2458 if (!NT_STATUS_IS_OK(cli_tcon_andx(cli, share, "?????", "", 1)))
2460 new_cnum = cli->cnum;
2461 cli->cnum = saved_cnum;
2463 printf("starting fdsesstest\n");
2465 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
2466 cli_unlink(cli, fname1, aSYSTEM | aHIDDEN);
2468 if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
2469 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
2473 if (cli_write(cli, fnum1, 0, "hello world\n", 0, 13) != 13) {
2474 printf("write failed (%s)\n", cli_errstr(cli));
2478 saved_vuid = cli->vuid;
2479 cli->vuid = new_vuid;
2481 if (cli_read(cli, fnum1, buf, 0, 13) == 13) {
2482 printf("read succeeded with different vuid! nasty security hole [%s]\n",
2486 /* Try to open a file with different vuid, samba cnum. */
2487 if (NT_STATUS_IS_OK(cli_open(cli, fname1, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum2))) {
2488 printf("create with different vuid, same cnum succeeded.\n");
2489 cli_close(cli, fnum2);
2490 cli_unlink(cli, fname1, aSYSTEM | aHIDDEN);
2492 printf("create with different vuid, same cnum failed.\n");
2493 printf("This will cause problems with service clients.\n");
2497 cli->vuid = saved_vuid;
2499 /* Try with same vuid, different cnum. */
2500 cli->cnum = new_cnum;
2502 if (cli_read(cli, fnum1, buf, 0, 13) == 13) {
2503 printf("read succeeded with different cnum![%s]\n",
2508 cli->cnum = saved_cnum;
2509 cli_close(cli, fnum1);
2510 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
2512 torture_close_connection(cli);
2514 printf("finished fdsesstest\n");
2519 This test checks that
2521 1) the server does not allow an unlink on a file that is open
2523 static bool run_unlinktest(int dummy)
2525 struct cli_state *cli;
2526 const char *fname = "\\unlink.tst";
2528 bool correct = True;
2530 if (!torture_open_connection(&cli, 0)) {
2534 cli_sockopt(cli, sockops);
2536 printf("starting unlink test\n");
2538 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
2542 if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum))) {
2543 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
2547 if (NT_STATUS_IS_OK(cli_unlink(cli, fname, aSYSTEM | aHIDDEN))) {
2548 printf("error: server allowed unlink on an open file\n");
2551 correct = check_error(__LINE__, cli, ERRDOS, ERRbadshare,
2552 NT_STATUS_SHARING_VIOLATION);
2555 cli_close(cli, fnum);
2556 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
2558 if (!torture_close_connection(cli)) {
2562 printf("unlink test finished\n");
2569 test how many open files this server supports on the one socket
2571 static bool run_maxfidtest(int dummy)
2573 struct cli_state *cli;
2574 const char *ftemplate = "\\maxfid.%d.%d";
2576 uint16_t fnums[0x11000];
2579 bool correct = True;
2584 printf("failed to connect\n");
2588 cli_sockopt(cli, sockops);
2590 for (i=0; i<0x11000; i++) {
2591 slprintf(fname,sizeof(fname)-1,ftemplate, i,(int)getpid());
2592 if (!NT_STATUS_IS_OK(cli_open(cli, fname,
2593 O_RDWR|O_CREAT|O_TRUNC, DENY_NONE, &fnums[i]))) {
2594 printf("open of %s failed (%s)\n",
2595 fname, cli_errstr(cli));
2596 printf("maximum fnum is %d\n", i);
2604 printf("cleaning up\n");
2606 slprintf(fname,sizeof(fname)-1,ftemplate, i,(int)getpid());
2607 cli_close(cli, fnums[i]);
2608 if (!NT_STATUS_IS_OK(cli_unlink(cli, fname, aSYSTEM | aHIDDEN))) {
2609 printf("unlink of %s failed (%s)\n",
2610 fname, cli_errstr(cli));
2617 printf("maxfid test finished\n");
2618 if (!torture_close_connection(cli)) {
2624 /* generate a random buffer */
2625 static void rand_buf(char *buf, int len)
2628 *buf = (char)sys_random();
2633 /* send smb negprot commands, not reading the response */
2634 static bool run_negprot_nowait(int dummy)
2637 static struct cli_state *cli;
2638 bool correct = True;
2640 printf("starting negprot nowait test\n");
2642 if (!(cli = open_nbt_connection())) {
2646 for (i=0;i<50000;i++) {
2647 cli_negprot_sendsync(cli);
2650 if (!torture_close_connection(cli)) {
2654 printf("finished negprot nowait test\n");
2660 /* send random IPC commands */
2661 static bool run_randomipc(int dummy)
2663 char *rparam = NULL;
2665 unsigned int rdrcnt,rprcnt;
2667 int api, param_len, i;
2668 struct cli_state *cli;
2669 bool correct = True;
2672 printf("starting random ipc test\n");
2674 if (!torture_open_connection(&cli, 0)) {
2678 for (i=0;i<count;i++) {
2679 api = sys_random() % 500;
2680 param_len = (sys_random() % 64);
2682 rand_buf(param, param_len);
2687 param, param_len, 8,
2688 NULL, 0, BUFFER_SIZE,
2692 printf("%d/%d\r", i,count);
2695 printf("%d/%d\n", i, count);
2697 if (!torture_close_connection(cli)) {
2701 printf("finished random ipc test\n");
2708 static void browse_callback(const char *sname, uint32 stype,
2709 const char *comment, void *state)
2711 printf("\t%20.20s %08x %s\n", sname, stype, comment);
2717 This test checks the browse list code
2720 static bool run_browsetest(int dummy)
2722 static struct cli_state *cli;
2723 bool correct = True;
2725 printf("starting browse test\n");
2727 if (!torture_open_connection(&cli, 0)) {
2731 printf("domain list:\n");
2732 cli_NetServerEnum(cli, cli->server_domain,
2733 SV_TYPE_DOMAIN_ENUM,
2734 browse_callback, NULL);
2736 printf("machine list:\n");
2737 cli_NetServerEnum(cli, cli->server_domain,
2739 browse_callback, NULL);
2741 if (!torture_close_connection(cli)) {
2745 printf("browse test finished\n");
2753 This checks how the getatr calls works
2755 static bool run_attrtest(int dummy)
2757 struct cli_state *cli;
2760 const char *fname = "\\attrib123456789.tst";
2761 bool correct = True;
2763 printf("starting attrib test\n");
2765 if (!torture_open_connection(&cli, 0)) {
2769 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
2770 cli_open(cli, fname,
2771 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
2772 cli_close(cli, fnum);
2773 if (!NT_STATUS_IS_OK(cli_getatr(cli, fname, NULL, NULL, &t))) {
2774 printf("getatr failed (%s)\n", cli_errstr(cli));
2778 if (abs(t - time(NULL)) > 60*60*24*10) {
2779 printf("ERROR: SMBgetatr bug. time is %s",
2785 t2 = t-60*60*24; /* 1 day ago */
2787 if (!NT_STATUS_IS_OK(cli_setatr(cli, fname, 0, t2))) {
2788 printf("setatr failed (%s)\n", cli_errstr(cli));
2792 if (!NT_STATUS_IS_OK(cli_getatr(cli, fname, NULL, NULL, &t))) {
2793 printf("getatr failed (%s)\n", cli_errstr(cli));
2798 printf("ERROR: getatr/setatr bug. times are\n%s",
2800 printf("%s", ctime(&t2));
2804 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
2806 if (!torture_close_connection(cli)) {
2810 printf("attrib test finished\n");
2817 This checks a couple of trans2 calls
2819 static bool run_trans2test(int dummy)
2821 struct cli_state *cli;
2824 time_t c_time, a_time, m_time;
2825 struct timespec c_time_ts, a_time_ts, m_time_ts, w_time_ts, m_time2_ts;
2826 const char *fname = "\\trans2.tst";
2827 const char *dname = "\\trans2";
2828 const char *fname2 = "\\trans2\\trans2.tst";
2830 bool correct = True;
2834 printf("starting trans2 test\n");
2836 if (!torture_open_connection(&cli, 0)) {
2840 status = cli_get_fs_attr_info(cli, &fs_attr);
2841 if (!NT_STATUS_IS_OK(status)) {
2842 printf("ERROR: cli_get_fs_attr_info returned %s\n",
2847 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
2848 cli_open(cli, fname,
2849 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
2850 if (!cli_qfileinfo(cli, fnum, NULL, &size, &c_time_ts, &a_time_ts, &w_time_ts,
2851 &m_time_ts, NULL)) {
2852 printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(cli));
2856 if (!cli_qfilename(cli, fnum, pname, sizeof(pname))) {
2857 printf("ERROR: qfilename failed (%s)\n", cli_errstr(cli));
2861 if (strcmp(pname, fname)) {
2862 printf("qfilename gave different name? [%s] [%s]\n",
2867 cli_close(cli, fnum);
2871 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
2872 if (!NT_STATUS_IS_OK(cli_open(cli, fname,
2873 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum))) {
2874 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
2877 cli_close(cli, fnum);
2879 if (!cli_qpathinfo(cli, fname, &c_time, &a_time, &m_time, &size, NULL)) {
2880 printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(cli));
2883 if (c_time != m_time) {
2884 printf("create time=%s", ctime(&c_time));
2885 printf("modify time=%s", ctime(&m_time));
2886 printf("This system appears to have sticky create times\n");
2888 if (a_time % (60*60) == 0) {
2889 printf("access time=%s", ctime(&a_time));
2890 printf("This system appears to set a midnight access time\n");
2894 if (abs(m_time - time(NULL)) > 60*60*24*7) {
2895 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
2901 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
2902 cli_open(cli, fname,
2903 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
2904 cli_close(cli, fnum);
2905 if (!cli_qpathinfo2(cli, fname, &c_time_ts, &a_time_ts, &w_time_ts,
2906 &m_time_ts, &size, NULL, NULL)) {
2907 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2910 if (w_time_ts.tv_sec < 60*60*24*2) {
2911 printf("write time=%s", ctime(&w_time_ts.tv_sec));
2912 printf("This system appears to set a initial 0 write time\n");
2917 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
2920 /* check if the server updates the directory modification time
2921 when creating a new file */
2922 if (!NT_STATUS_IS_OK(cli_mkdir(cli, dname))) {
2923 printf("ERROR: mkdir failed (%s)\n", cli_errstr(cli));
2927 if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts, &w_time_ts,
2928 &m_time_ts, &size, NULL, NULL)) {
2929 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2933 cli_open(cli, fname2,
2934 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
2935 cli_write(cli, fnum, 0, (char *)&fnum, 0, sizeof(fnum));
2936 cli_close(cli, fnum);
2937 if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts, &w_time_ts,
2938 &m_time2_ts, &size, NULL, NULL)) {
2939 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2942 if (memcmp(&m_time_ts, &m_time2_ts, sizeof(struct timespec))
2944 printf("This system does not update directory modification times\n");
2948 cli_unlink(cli, fname2, aSYSTEM | aHIDDEN);
2949 cli_rmdir(cli, dname);
2951 if (!torture_close_connection(cli)) {
2955 printf("trans2 test finished\n");
2961 This checks new W2K calls.
2964 static bool new_trans(struct cli_state *pcli, int fnum, int level)
2968 bool correct = True;
2970 if (!cli_qfileinfo_test(pcli, fnum, level, &buf, &len)) {
2971 printf("ERROR: qfileinfo (%d) failed (%s)\n", level, cli_errstr(pcli));
2974 printf("qfileinfo: level %d, len = %u\n", level, len);
2975 dump_data(0, (uint8 *)buf, len);
2982 static bool run_w2ktest(int dummy)
2984 struct cli_state *cli;
2986 const char *fname = "\\w2ktest\\w2k.tst";
2988 bool correct = True;
2990 printf("starting w2k test\n");
2992 if (!torture_open_connection(&cli, 0)) {
2996 cli_open(cli, fname,
2997 O_RDWR | O_CREAT , DENY_NONE, &fnum);
2999 for (level = 1004; level < 1040; level++) {
3000 new_trans(cli, fnum, level);
3003 cli_close(cli, fnum);
3005 if (!torture_close_connection(cli)) {
3009 printf("w2k test finished\n");
3016 this is a harness for some oplock tests
3018 static bool run_oplock1(int dummy)
3020 struct cli_state *cli1;
3021 const char *fname = "\\lockt1.lck";
3023 bool correct = True;
3025 printf("starting oplock test 1\n");
3027 if (!torture_open_connection(&cli1, 0)) {
3031 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3033 cli_sockopt(cli1, sockops);
3035 cli1->use_oplocks = True;
3037 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
3038 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
3042 cli1->use_oplocks = False;
3044 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3045 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3047 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3048 printf("close2 failed (%s)\n", cli_errstr(cli1));
3052 if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname, aSYSTEM | aHIDDEN))) {
3053 printf("unlink failed (%s)\n", cli_errstr(cli1));
3057 if (!torture_close_connection(cli1)) {
3061 printf("finished oplock test 1\n");
3066 static bool run_oplock2(int dummy)
3068 struct cli_state *cli1, *cli2;
3069 const char *fname = "\\lockt2.lck";
3070 uint16_t fnum1, fnum2;
3071 int saved_use_oplocks = use_oplocks;
3073 bool correct = True;
3074 volatile bool *shared_correct;
3076 shared_correct = (volatile bool *)shm_setup(sizeof(bool));
3077 *shared_correct = True;
3079 use_level_II_oplocks = True;
3082 printf("starting oplock test 2\n");
3084 if (!torture_open_connection(&cli1, 0)) {
3085 use_level_II_oplocks = False;
3086 use_oplocks = saved_use_oplocks;
3090 cli1->use_oplocks = True;
3091 cli1->use_level_II_oplocks = True;
3093 if (!torture_open_connection(&cli2, 1)) {
3094 use_level_II_oplocks = False;
3095 use_oplocks = saved_use_oplocks;
3099 cli2->use_oplocks = True;
3100 cli2->use_level_II_oplocks = True;
3102 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3104 cli_sockopt(cli1, sockops);
3105 cli_sockopt(cli2, sockops);
3107 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
3108 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
3112 /* Don't need the globals any more. */
3113 use_level_II_oplocks = False;
3114 use_oplocks = saved_use_oplocks;
3118 if (!NT_STATUS_IS_OK(cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2))) {
3119 printf("second open of %s failed (%s)\n", fname, cli_errstr(cli1));
3120 *shared_correct = False;
3126 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
3127 printf("close2 failed (%s)\n", cli_errstr(cli1));
3128 *shared_correct = False;
3136 /* Ensure cli1 processes the break. Empty file should always return 0
3139 if (cli_read(cli1, fnum1, buf, 0, 4) != 0) {
3140 printf("read on fnum1 failed (%s)\n", cli_errstr(cli1));
3144 /* Should now be at level II. */
3145 /* Test if sending a write locks causes a break to none. */
3147 if (!cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK)) {
3148 printf("lock failed (%s)\n", cli_errstr(cli1));
3152 cli_unlock(cli1, fnum1, 0, 4);
3156 if (!cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
3157 printf("lock failed (%s)\n", cli_errstr(cli1));
3161 cli_unlock(cli1, fnum1, 0, 4);
3165 cli_read(cli1, fnum1, buf, 0, 4);
3168 if (cli_write(cli1, fnum1, 0, buf, 0, 4) != 4) {
3169 printf("write on fnum1 failed (%s)\n", cli_errstr(cli1));
3174 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3175 printf("close1 failed (%s)\n", cli_errstr(cli1));
3181 if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname, aSYSTEM | aHIDDEN))) {
3182 printf("unlink failed (%s)\n", cli_errstr(cli1));
3186 if (!torture_close_connection(cli1)) {
3190 if (!*shared_correct) {
3194 printf("finished oplock test 2\n");
3199 /* handler for oplock 3 tests */
3200 static NTSTATUS oplock3_handler(struct cli_state *cli, uint16_t fnum, unsigned char level)
3202 printf("got oplock break fnum=%d level=%d\n",
3204 return cli_oplock_ack(cli, fnum, level);
3207 static bool run_oplock3(int dummy)
3209 struct cli_state *cli;
3210 const char *fname = "\\oplockt3.dat";
3212 char buf[4] = "abcd";
3213 bool correct = True;
3214 volatile bool *shared_correct;
3216 shared_correct = (volatile bool *)shm_setup(sizeof(bool));
3217 *shared_correct = True;
3219 printf("starting oplock test 3\n");
3224 use_level_II_oplocks = True;
3225 if (!torture_open_connection(&cli, 0)) {
3226 *shared_correct = False;
3230 /* try to trigger a oplock break in parent */
3231 cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum);
3232 cli_write(cli, fnum, 0, buf, 0, 4);
3238 use_level_II_oplocks = True;
3239 if (!torture_open_connection(&cli, 1)) { /* other is forked */
3242 cli_oplock_handler(cli, oplock3_handler);
3243 cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum);
3244 cli_write(cli, fnum, 0, buf, 0, 4);
3245 cli_close(cli, fnum);
3246 cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum);
3247 cli->timeout = 20000;
3248 cli_receive_smb(cli);
3249 printf("finished oplock test 3\n");
3251 return (correct && *shared_correct);
3253 /* What are we looking for here? What's sucess and what's FAILURE? */
3259 Test delete on close semantics.
3261 static bool run_deletetest(int dummy)
3263 struct cli_state *cli1 = NULL;
3264 struct cli_state *cli2 = NULL;
3265 const char *fname = "\\delete.file";
3266 uint16_t fnum1 = (uint16_t)-1;
3267 uint16_t fnum2 = (uint16_t)-1;
3268 bool correct = True;
3270 printf("starting delete test\n");
3272 if (!torture_open_connection(&cli1, 0)) {
3276 cli_sockopt(cli1, sockops);
3278 /* Test 1 - this should delete the file on close. */
3280 cli_setatr(cli1, fname, 0, 0);
3281 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3283 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
3284 0, FILE_OVERWRITE_IF,
3285 FILE_DELETE_ON_CLOSE, 0, &fnum1))) {
3286 printf("[1] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3293 uint32 *accinfo = NULL;
3295 cli_qfileinfo_test(cli1, fnum1, SMB_FILE_ACCESS_INFORMATION, (char **)&accinfo, &len);
3297 printf("access mode = 0x%lx\n", *accinfo);
3302 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3303 printf("[1] close failed (%s)\n", cli_errstr(cli1));
3308 if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1))) {
3309 printf("[1] open of %s succeeded (should fail)\n", fname);
3314 printf("first delete on close test succeeded.\n");
3316 /* Test 2 - this should delete the file on close. */
3318 cli_setatr(cli1, fname, 0, 0);
3319 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3321 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS,
3322 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
3323 FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3324 printf("[2] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3329 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
3330 printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
3335 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3336 printf("[2] close failed (%s)\n", cli_errstr(cli1));
3341 if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
3342 printf("[2] open of %s succeeded should have been deleted on close !\n", fname);
3343 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3344 printf("[2] close failed (%s)\n", cli_errstr(cli1));
3348 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3350 printf("second delete on close test succeeded.\n");
3353 cli_setatr(cli1, fname, 0, 0);
3354 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3356 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
3357 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3358 printf("[3] open - 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3363 /* This should fail with a sharing violation - open for delete is only compatible
3364 with SHARE_DELETE. */
3366 if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3367 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0, 0, &fnum2))) {
3368 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname);
3373 /* This should succeed. */
3375 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3376 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0, 0, &fnum2))) {
3377 printf("[3] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
3382 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
3383 printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
3388 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3389 printf("[3] close 1 failed (%s)\n", cli_errstr(cli1));
3394 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum2))) {
3395 printf("[3] close 2 failed (%s)\n", cli_errstr(cli1));
3400 /* This should fail - file should no longer be there. */
3402 if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
3403 printf("[3] open of %s succeeded should have been deleted on close !\n", fname);
3404 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3405 printf("[3] close failed (%s)\n", cli_errstr(cli1));
3407 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3411 printf("third delete on close test succeeded.\n");
3414 cli_setatr(cli1, fname, 0, 0);
3415 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3417 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3418 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3419 printf("[4] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3424 /* This should succeed. */
3425 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
3426 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0, 0, &fnum2))) {
3427 printf("[4] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
3432 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum2))) {
3433 printf("[4] close - 1 failed (%s)\n", cli_errstr(cli1));
3438 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
3439 printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
3444 /* This should fail - no more opens once delete on close set. */
3445 if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
3446 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3447 FILE_OPEN, 0, 0, &fnum2))) {
3448 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname );
3452 printf("fourth delete on close test succeeded.\n");
3454 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3455 printf("[4] close - 2 failed (%s)\n", cli_errstr(cli1));
3461 cli_setatr(cli1, fname, 0, 0);
3462 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3464 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum1))) {
3465 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3470 /* This should fail - only allowed on NT opens with DELETE access. */
3472 if (NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
3473 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
3478 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3479 printf("[5] close - 2 failed (%s)\n", cli_errstr(cli1));
3484 printf("fifth delete on close test succeeded.\n");
3487 cli_setatr(cli1, fname, 0, 0);
3488 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3490 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
3491 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3492 FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3493 printf("[6] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3498 /* This should fail - only allowed on NT opens with DELETE access. */
3500 if (NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
3501 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
3506 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3507 printf("[6] close - 2 failed (%s)\n", cli_errstr(cli1));
3512 printf("sixth delete on close test succeeded.\n");
3515 cli_setatr(cli1, fname, 0, 0);
3516 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3518 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3519 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3520 printf("[7] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3525 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
3526 printf("[7] setting delete_on_close on file failed !\n");
3531 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, false))) {
3532 printf("[7] unsetting delete_on_close on file failed !\n");
3537 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3538 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
3543 /* This next open should succeed - we reset the flag. */
3545 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
3546 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3551 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3552 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
3557 printf("seventh delete on close test succeeded.\n");
3560 cli_setatr(cli1, fname, 0, 0);
3561 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3563 if (!torture_open_connection(&cli2, 1)) {
3564 printf("[8] failed to open second connection.\n");
3569 cli_sockopt(cli1, sockops);
3571 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3572 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3573 FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3574 printf("[8] open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3579 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3580 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3581 FILE_OPEN, 0, 0, &fnum2))) {
3582 printf("[8] open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3587 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
3588 printf("[8] setting delete_on_close on file failed !\n");
3593 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3594 printf("[8] close - 1 failed (%s)\n", cli_errstr(cli1));
3599 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
3600 printf("[8] close - 2 failed (%s)\n", cli_errstr(cli2));
3605 /* This should fail.. */
3606 if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
3607 printf("[8] open of %s succeeded should have been deleted on close !\n", fname);
3611 printf("eighth delete on close test succeeded.\n");
3613 /* This should fail - we need to set DELETE_ACCESS. */
3614 if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0,FILE_READ_DATA|FILE_WRITE_DATA,
3615 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, 0, &fnum1))) {
3616 printf("[9] open of %s succeeded should have failed!\n", fname);
3621 printf("ninth delete on close test succeeded.\n");
3623 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3624 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, 0, &fnum1))) {
3625 printf("[10] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3630 /* This should delete the file. */
3631 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3632 printf("[10] close failed (%s)\n", cli_errstr(cli1));
3637 /* This should fail.. */
3638 if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
3639 printf("[10] open of %s succeeded should have been deleted on close !\n", fname);
3643 printf("tenth delete on close test succeeded.\n");
3645 cli_setatr(cli1, fname, 0, 0);
3646 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3648 /* What error do we get when attempting to open a read-only file with
3651 /* Create a readonly file. */
3652 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
3653 FILE_ATTRIBUTE_READONLY, FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3654 printf("[11] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3659 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3660 printf("[11] close failed (%s)\n", cli_errstr(cli1));
3665 /* Now try open for delete access. */
3666 if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES|DELETE_ACCESS,
3667 0, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3668 FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3669 printf("[11] open of %s succeeded should have been denied with ACCESS_DENIED!\n", fname);
3670 cli_close(cli1, fnum1);
3674 NTSTATUS nterr = cli_nt_error(cli1);
3675 if (!NT_STATUS_EQUAL(nterr,NT_STATUS_ACCESS_DENIED)) {
3676 printf("[11] open of %s should have been denied with ACCESS_DENIED! Got error %s\n", fname, nt_errstr(nterr));
3680 printf("eleventh delete on close test succeeded.\n");
3684 printf("finished delete test\n");
3687 /* FIXME: This will crash if we aborted before cli2 got
3688 * intialized, because these functions don't handle
3689 * uninitialized connections. */
3691 if (fnum1 != (uint16_t)-1) cli_close(cli1, fnum1);
3692 if (fnum2 != (uint16_t)-1) cli_close(cli1, fnum2);
3693 cli_setatr(cli1, fname, 0, 0);
3694 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3696 if (cli1 && !torture_close_connection(cli1)) {
3699 if (cli2 && !torture_close_connection(cli2)) {
3707 print out server properties
3709 static bool run_properties(int dummy)
3711 struct cli_state *cli;
3712 bool correct = True;
3714 printf("starting properties test\n");
3718 if (!torture_open_connection(&cli, 0)) {
3722 cli_sockopt(cli, sockops);
3724 d_printf("Capabilities 0x%08x\n", cli->capabilities);
3726 if (!torture_close_connection(cli)) {
3735 /* FIRST_DESIRED_ACCESS 0xf019f */
3736 #define FIRST_DESIRED_ACCESS FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|\
3737 FILE_READ_EA| /* 0xf */ \
3738 FILE_WRITE_EA|FILE_READ_ATTRIBUTES| /* 0x90 */ \
3739 FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
3740 DELETE_ACCESS|READ_CONTROL_ACCESS|\
3741 WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS /* 0xf0000 */
3742 /* SECOND_DESIRED_ACCESS 0xe0080 */
3743 #define SECOND_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
3744 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
3745 WRITE_OWNER_ACCESS /* 0xe0000 */
3748 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
3749 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
3751 WRITE_OWNER_ACCESS /* */
3755 Test ntcreate calls made by xcopy
3757 static bool run_xcopy(int dummy)
3759 static struct cli_state *cli1;
3760 const char *fname = "\\test.txt";
3761 bool correct = True;
3762 uint16_t fnum1, fnum2;
3764 printf("starting xcopy test\n");
3766 if (!torture_open_connection(&cli1, 0)) {
3770 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0,
3771 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
3772 FILE_SHARE_NONE, FILE_OVERWRITE_IF,
3773 0x4044, 0, &fnum1))) {
3774 printf("First open failed - %s\n", cli_errstr(cli1));
3778 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0,
3779 SECOND_DESIRED_ACCESS, 0,
3780 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN,
3781 0x200000, 0, &fnum2))) {
3782 printf("second open failed - %s\n", cli_errstr(cli1));
3786 if (!torture_close_connection(cli1)) {
3794 Test rename on files open with share delete and no share delete.
3796 static bool run_rename(int dummy)
3798 static struct cli_state *cli1;
3799 const char *fname = "\\test.txt";
3800 const char *fname1 = "\\test1.txt";
3801 bool correct = True;
3805 printf("starting rename test\n");
3807 if (!torture_open_connection(&cli1, 0)) {
3811 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3812 cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
3813 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3814 FILE_SHARE_READ, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3815 printf("First open failed - %s\n", cli_errstr(cli1));
3819 if (!NT_STATUS_IS_OK(cli_rename(cli1, fname, fname1))) {
3820 printf("First rename failed (SHARE_READ) (this is correct) - %s\n", cli_errstr(cli1));
3822 printf("First rename succeeded (SHARE_READ) - this should have failed !\n");
3826 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3827 printf("close - 1 failed (%s)\n", cli_errstr(cli1));
3831 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3832 cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
3833 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3835 FILE_SHARE_DELETE|FILE_SHARE_NONE,
3837 FILE_SHARE_DELETE|FILE_SHARE_READ,
3839 FILE_OVERWRITE_IF, 0, 0, &fnum1);
3840 if (!NT_STATUS_IS_OK(status)) {
3841 printf("Second open failed - %s\n", cli_errstr(cli1));
3845 if (!NT_STATUS_IS_OK(cli_rename(cli1, fname, fname1))) {
3846 printf("Second rename failed (SHARE_DELETE | SHARE_READ) - this should have succeeded - %s\n", cli_errstr(cli1));
3849 printf("Second rename succeeded (SHARE_DELETE | SHARE_READ)\n");
3852 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3853 printf("close - 2 failed (%s)\n", cli_errstr(cli1));
3857 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3858 cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
3860 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, READ_CONTROL_ACCESS, FILE_ATTRIBUTE_NORMAL,
3861 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3862 printf("Third open failed - %s\n", cli_errstr(cli1));
3871 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
3872 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum2))) {
3873 printf("Fourth open failed - %s\n", cli_errstr(cli1));
3876 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum2, true))) {
3877 printf("[8] setting delete_on_close on file failed !\n");
3881 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum2))) {
3882 printf("close - 4 failed (%s)\n", cli_errstr(cli1));
3888 if (!NT_STATUS_IS_OK(cli_rename(cli1, fname, fname1))) {
3889 printf("Third rename failed (SHARE_NONE) - this should have succeeded - %s\n", cli_errstr(cli1));
3892 printf("Third rename succeeded (SHARE_NONE)\n");
3895 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3896 printf("close - 3 failed (%s)\n", cli_errstr(cli1));
3900 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3901 cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
3905 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3906 FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3907 printf("Fourth open failed - %s\n", cli_errstr(cli1));
3911 if (!NT_STATUS_IS_OK(cli_rename(cli1, fname, fname1))) {
3912 printf("Fourth rename failed (SHARE_READ | SHARE_WRITE) (this is correct) - %s\n", cli_errstr(cli1));
3914 printf("Fourth rename succeeded (SHARE_READ | SHARE_WRITE) - this should have failed !\n");
3918 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3919 printf("close - 4 failed (%s)\n", cli_errstr(cli1));
3923 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3924 cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
3928 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3929 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
3930 printf("Fifth open failed - %s\n", cli_errstr(cli1));
3934 if (!NT_STATUS_IS_OK(cli_rename(cli1, fname, fname1))) {
3935 printf("Fifth rename failed (SHARE_READ | SHARE_WRITE | SHARE_DELETE) - this should have succeeded - %s ! \n",
3939 printf("Fifth rename succeeded (SHARE_READ | SHARE_WRITE | SHARE_DELETE) (this is correct) - %s\n", cli_errstr(cli1));
3943 * Now check if the first name still exists ...
3946 /* if (!NT_STATUS_OP(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3947 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0, &fnum2))) {
3948 printf("Opening original file after rename of open file fails: %s\n",
3952 printf("Opening original file after rename of open file works ...\n");
3953 (void)cli_close(cli1, fnum2);
3959 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
3960 printf("close - 5 failed (%s)\n", cli_errstr(cli1));
3964 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
3965 cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
3967 if (!torture_close_connection(cli1)) {
3974 static bool run_pipe_number(int dummy)
3976 struct cli_state *cli1;
3977 const char *pipe_name = "\\SPOOLSS";
3981 printf("starting pipenumber test\n");
3982 if (!torture_open_connection(&cli1, 0)) {
3986 cli_sockopt(cli1, sockops);
3988 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, pipe_name, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
3989 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN_IF, 0, 0, &fnum))) {
3990 printf("Open of pipe %s failed with error (%s)\n", pipe_name, cli_errstr(cli1));
3994 printf("\r%6d", num_pipes);
3997 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes, pipe_name );
3998 torture_close_connection(cli1);
4003 Test open mode returns on read-only files.
4005 static bool run_opentest(int dummy)
4007 static struct cli_state *cli1;
4008 static struct cli_state *cli2;
4009 const char *fname = "\\readonly.file";
4010 uint16_t fnum1, fnum2;
4013 bool correct = True;
4016 printf("starting open test\n");
4018 if (!torture_open_connection(&cli1, 0)) {
4022 cli_setatr(cli1, fname, 0, 0);
4023 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
4025 cli_sockopt(cli1, sockops);
4027 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
4028 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
4032 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4033 printf("close2 failed (%s)\n", cli_errstr(cli1));
4037 if (!NT_STATUS_IS_OK(cli_setatr(cli1, fname, aRONLY, 0))) {
4038 printf("cli_setatr failed (%s)\n", cli_errstr(cli1));
4042 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_WRITE, &fnum1))) {
4043 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
4047 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
4048 cli_open(cli1, fname, O_RDWR, DENY_ALL, &fnum2);
4050 if (check_error(__LINE__, cli1, ERRDOS, ERRnoaccess,
4051 NT_STATUS_ACCESS_DENIED)) {
4052 printf("correct error code ERRDOS/ERRnoaccess returned\n");
4055 printf("finished open test 1\n");
4057 cli_close(cli1, fnum1);
4059 /* Now try not readonly and ensure ERRbadshare is returned. */
4061 cli_setatr(cli1, fname, 0, 0);
4063 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_WRITE, &fnum1))) {
4064 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
4068 /* This will fail - but the error should be ERRshare. */
4069 cli_open(cli1, fname, O_RDWR, DENY_ALL, &fnum2);
4071 if (check_error(__LINE__, cli1, ERRDOS, ERRbadshare,
4072 NT_STATUS_SHARING_VIOLATION)) {
4073 printf("correct error code ERRDOS/ERRbadshare returned\n");
4076 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4077 printf("close2 failed (%s)\n", cli_errstr(cli1));
4081 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
4083 printf("finished open test 2\n");
4085 /* Test truncate open disposition on file opened for read. */
4087 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
4088 printf("(3) open (1) of %s failed (%s)\n", fname, cli_errstr(cli1));
4092 /* write 20 bytes. */
4094 memset(buf, '\0', 20);
4096 if (cli_write(cli1, fnum1, 0, buf, 0, 20) != 20) {
4097 printf("write failed (%s)\n", cli_errstr(cli1));
4101 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4102 printf("(3) close1 failed (%s)\n", cli_errstr(cli1));
4106 /* Ensure size == 20. */
4107 if (!NT_STATUS_IS_OK(cli_getatr(cli1, fname, NULL, &fsize, NULL))) {
4108 printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
4113 printf("(3) file size != 20\n");
4117 /* Now test if we can truncate a file opened for readonly. */
4119 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE, &fnum1))) {
4120 printf("(3) open (2) of %s failed (%s)\n", fname, cli_errstr(cli1));
4124 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4125 printf("close2 failed (%s)\n", cli_errstr(cli1));
4129 /* Ensure size == 0. */
4130 if (!NT_STATUS_IS_OK(cli_getatr(cli1, fname, NULL, &fsize, NULL))) {
4131 printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
4136 printf("(3) file size != 0\n");
4139 printf("finished open test 3\n");
4141 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
4144 printf("testing ctemp\n");
4145 if (!NT_STATUS_IS_OK(cli_ctemp(cli1, talloc_tos(), "\\", &fnum1, &tmp_path))) {
4146 printf("ctemp failed (%s)\n", cli_errstr(cli1));
4149 printf("ctemp gave path %s\n", tmp_path);
4150 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4151 printf("close of temp failed (%s)\n", cli_errstr(cli1));
4153 if (!NT_STATUS_IS_OK(cli_unlink(cli1, tmp_path, aSYSTEM | aHIDDEN))) {
4154 printf("unlink of temp failed (%s)\n", cli_errstr(cli1));
4157 /* Test the non-io opens... */
4159 if (!torture_open_connection(&cli2, 1)) {
4163 cli_setatr(cli2, fname, 0, 0);
4164 cli_unlink(cli2, fname, aSYSTEM | aHIDDEN);
4166 cli_sockopt(cli2, sockops);
4168 printf("TEST #1 testing 2 non-io opens (no delete)\n");
4170 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4171 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
4172 printf("test 1 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4176 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4177 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0, &fnum2))) {
4178 printf("test 1 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4182 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4183 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4186 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
4187 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4191 printf("non-io open test #1 passed.\n");
4193 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
4195 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
4197 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4198 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
4199 printf("test 2 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4203 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4204 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0, &fnum2))) {
4205 printf("test 2 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4209 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4210 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4213 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
4214 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
4218 printf("non-io open test #2 passed.\n");
4220 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
4222 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
4224 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4225 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
4226 printf("test 3 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4230 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4231 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0, &fnum2))) {
4232 printf("test 3 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4236 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4237 printf("test 3 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4240 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
4241 printf("test 3 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4245 printf("non-io open test #3 passed.\n");
4247 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
4249 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
4251 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4252 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
4253 printf("test 4 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4257 if (NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4258 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0, &fnum2))) {
4259 printf("test 4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
4263 printf("test 3 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
4265 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4266 printf("test 4 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4270 printf("non-io open test #4 passed.\n");
4272 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
4274 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
4276 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4277 FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
4278 printf("test 5 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4282 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4283 FILE_SHARE_DELETE, FILE_OPEN_IF, 0, 0, &fnum2))) {
4284 printf("test 5 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4288 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4289 printf("test 5 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4293 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
4294 printf("test 5 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4298 printf("non-io open test #5 passed.\n");
4300 printf("TEST #6 testing 1 non-io open, one io open\n");
4302 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
4304 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
4305 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
4306 printf("test 6 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4310 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4311 FILE_SHARE_READ, FILE_OPEN_IF, 0, 0, &fnum2))) {
4312 printf("test 6 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4316 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4317 printf("test 6 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4321 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
4322 printf("test 6 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
4326 printf("non-io open test #6 passed.\n");
4328 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
4330 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
4332 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
4333 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
4334 printf("test 7 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4338 if (NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
4339 FILE_SHARE_READ|FILE_SHARE_DELETE, FILE_OPEN_IF, 0, 0, &fnum2))) {
4340 printf("test 7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
4344 printf("test 7 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
4346 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4347 printf("test 7 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
4351 printf("non-io open test #7 passed.\n");
4353 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
4355 if (!torture_close_connection(cli1)) {
4358 if (!torture_close_connection(cli2)) {
4366 Test POSIX open /mkdir calls.
4368 static bool run_simple_posix_open_test(int dummy)
4370 static struct cli_state *cli1;
4371 const char *fname = "posix:file";
4372 const char *hname = "posix:hlink";
4373 const char *sname = "posix:symlink";
4374 const char *dname = "posix:dir";
4377 uint16 major, minor;
4378 uint32 caplow, caphigh;
4379 uint16_t fnum1 = (uint16_t)-1;
4380 SMB_STRUCT_STAT sbuf;
4381 bool correct = false;
4384 printf("Starting simple POSIX open test\n");
4386 if (!torture_open_connection(&cli1, 0)) {
4390 cli_sockopt(cli1, sockops);
4392 if (!SERVER_HAS_UNIX_CIFS(cli1)) {
4393 printf("Server doesn't support UNIX CIFS extensions.\n");
4397 status = cli_unix_extensions_version(cli1, &major, &minor, &caplow,
4399 if (!NT_STATUS_IS_OK(status)) {
4400 printf("Server didn't return UNIX CIFS extensions: %s\n",
4405 status = cli_set_unix_extensions_capabilities(cli1, major, minor,
4407 if (!NT_STATUS_IS_OK(status)) {
4408 printf("Server doesn't support setting UNIX CIFS extensions: "
4409 "%s.\n", nt_errstr(status));
4413 cli_setatr(cli1, fname, 0, 0);
4414 cli_posix_unlink(cli1, fname);
4415 cli_setatr(cli1, dname, 0, 0);
4416 cli_posix_rmdir(cli1, dname);
4417 cli_setatr(cli1, hname, 0, 0);
4418 cli_posix_unlink(cli1, hname);
4419 cli_setatr(cli1, sname, 0, 0);
4420 cli_posix_unlink(cli1, sname);
4422 /* Create a directory. */
4423 if (!NT_STATUS_IS_OK(cli_posix_mkdir(cli1, dname, 0777))) {
4424 printf("POSIX mkdir of %s failed (%s)\n", dname, cli_errstr(cli1));
4428 if (!NT_STATUS_IS_OK(cli_posix_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, 0600, &fnum1))) {
4429 printf("POSIX create of %s failed (%s)\n", fname, cli_errstr(cli1));
4433 /* Test ftruncate - set file size. */
4434 if (!NT_STATUS_IS_OK(cli_ftruncate(cli1, fnum1, 1000))) {
4435 printf("ftruncate failed (%s)\n", cli_errstr(cli1));
4439 /* Ensure st_size == 1000 */
4440 if (!NT_STATUS_IS_OK(cli_posix_stat(cli1, fname, &sbuf))) {
4441 printf("stat failed (%s)\n", cli_errstr(cli1));
4445 if (sbuf.st_ex_size != 1000) {
4446 printf("ftruncate - stat size (%u) != 1000\n", (unsigned int)sbuf.st_ex_size);
4450 /* Test ftruncate - set file size back to zero. */
4451 if (!NT_STATUS_IS_OK(cli_ftruncate(cli1, fnum1, 0))) {
4452 printf("ftruncate failed (%s)\n", cli_errstr(cli1));
4456 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4457 printf("close failed (%s)\n", cli_errstr(cli1));
4461 /* Now open the file again for read only. */
4462 if (!NT_STATUS_IS_OK(cli_posix_open(cli1, fname, O_RDONLY, 0, &fnum1))) {
4463 printf("POSIX open of %s failed (%s)\n", fname, cli_errstr(cli1));
4467 /* Now unlink while open. */
4468 if (!NT_STATUS_IS_OK(cli_posix_unlink(cli1, fname))) {
4469 printf("POSIX unlink of %s failed (%s)\n", fname, cli_errstr(cli1));
4473 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4474 printf("close(2) failed (%s)\n", cli_errstr(cli1));
4478 /* Ensure the file has gone. */
4479 if (NT_STATUS_IS_OK(cli_posix_open(cli1, fname, O_RDONLY, 0, &fnum1))) {
4480 printf("POSIX open of %s succeeded, should have been deleted.\n", fname);
4484 /* What happens when we try and POSIX open a directory ? */
4485 if (NT_STATUS_IS_OK(cli_posix_open(cli1, dname, O_RDONLY, 0, &fnum1))) {
4486 printf("POSIX open of directory %s succeeded, should have failed.\n", fname);
4489 if (!check_error(__LINE__, cli1, ERRDOS, EISDIR,
4490 NT_STATUS_FILE_IS_A_DIRECTORY)) {
4495 /* Create the file. */
4496 if (!NT_STATUS_IS_OK(cli_posix_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, 0600, &fnum1))) {
4497 printf("POSIX create of %s failed (%s)\n", fname, cli_errstr(cli1));
4501 /* Write some data into it. */
4502 if (cli_write(cli1, fnum1, 0, "TEST DATA\n", 0, 10) != 10) {
4503 printf("cli_write failed: %s\n", cli_errstr(cli1));
4507 cli_close(cli1, fnum1);
4509 /* Now create a hardlink. */
4510 if (!NT_STATUS_IS_OK(cli_posix_hardlink(cli1, fname, hname))) {
4511 printf("POSIX hardlink of %s failed (%s)\n", hname, cli_errstr(cli1));
4515 /* Now create a symlink. */
4516 if (!NT_STATUS_IS_OK(cli_posix_symlink(cli1, fname, sname))) {
4517 printf("POSIX symlink of %s failed (%s)\n", sname, cli_errstr(cli1));
4521 /* Open the hardlink for read. */
4522 if (!NT_STATUS_IS_OK(cli_posix_open(cli1, hname, O_RDONLY, 0, &fnum1))) {
4523 printf("POSIX open of %s failed (%s)\n", hname, cli_errstr(cli1));
4527 if (cli_read(cli1, fnum1, buf, 0, 10) != 10) {
4528 printf("POSIX read of %s failed (%s)\n", hname, cli_errstr(cli1));
4532 if (memcmp(buf, "TEST DATA\n", 10)) {
4533 printf("invalid data read from hardlink\n");
4537 /* Do a POSIX lock/unlock. */
4538 if (!NT_STATUS_IS_OK(cli_posix_lock(cli1, fnum1, 0, 100, true, READ_LOCK))) {
4539 printf("POSIX lock failed %s\n", cli_errstr(cli1));
4543 /* Punch a hole in the locked area. */
4544 if (!NT_STATUS_IS_OK(cli_posix_unlock(cli1, fnum1, 10, 80))) {
4545 printf("POSIX unlock failed %s\n", cli_errstr(cli1));
4549 cli_close(cli1, fnum1);
4551 /* Open the symlink for read - this should fail. A POSIX
4552 client should not be doing opens on a symlink. */
4553 if (NT_STATUS_IS_OK(cli_posix_open(cli1, sname, O_RDONLY, 0, &fnum1))) {
4554 printf("POSIX open of %s succeeded (should have failed)\n", sname);
4557 if (!check_error(__LINE__, cli1, ERRDOS, ERRbadpath,
4558 NT_STATUS_OBJECT_PATH_NOT_FOUND)) {
4559 printf("POSIX open of %s should have failed "
4560 "with NT_STATUS_OBJECT_PATH_NOT_FOUND, "
4561 "failed with %s instead.\n",
4562 sname, cli_errstr(cli1));
4567 if (!NT_STATUS_IS_OK(cli_posix_readlink(cli1, sname, namebuf, sizeof(namebuf)))) {
4568 printf("POSIX readlink on %s failed (%s)\n", sname, cli_errstr(cli1));
4572 if (strcmp(namebuf, fname) != 0) {
4573 printf("POSIX readlink on %s failed to match name %s (read %s)\n",
4574 sname, fname, namebuf);
4578 if (!NT_STATUS_IS_OK(cli_posix_rmdir(cli1, dname))) {
4579 printf("POSIX rmdir failed (%s)\n", cli_errstr(cli1));
4583 printf("Simple POSIX open test passed\n");
4588 if (fnum1 != (uint16_t)-1) {
4589 cli_close(cli1, fnum1);
4590 fnum1 = (uint16_t)-1;
4593 cli_setatr(cli1, sname, 0, 0);
4594 cli_posix_unlink(cli1, sname);
4595 cli_setatr(cli1, hname, 0, 0);
4596 cli_posix_unlink(cli1, hname);
4597 cli_setatr(cli1, fname, 0, 0);
4598 cli_posix_unlink(cli1, fname);
4599 cli_setatr(cli1, dname, 0, 0);
4600 cli_posix_rmdir(cli1, dname);
4602 if (!torture_close_connection(cli1)) {
4610 static uint32 open_attrs_table[] = {
4611 FILE_ATTRIBUTE_NORMAL,
4612 FILE_ATTRIBUTE_ARCHIVE,
4613 FILE_ATTRIBUTE_READONLY,
4614 FILE_ATTRIBUTE_HIDDEN,
4615 FILE_ATTRIBUTE_SYSTEM,
4617 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY,
4618 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN,
4619 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM,
4620 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
4621 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
4622 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
4624 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
4625 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
4626 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
4627 FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_SYSTEM,
4630 struct trunc_open_results {
4637 static struct trunc_open_results attr_results[] = {
4638 { 0, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
4639 { 1, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
4640 { 2, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
4641 { 16, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
4642 { 17, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
4643 { 18, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
4644 { 51, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4645 { 54, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4646 { 56, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
4647 { 68, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4648 { 71, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4649 { 73, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM },
4650 { 99, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4651 { 102, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4652 { 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 },
4653 { 116, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4654 { 119, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4655 { 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 },
4656 { 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 },
4657 { 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 },
4658 { 227, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4659 { 230, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
4660 { 232, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
4661 { 244, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4662 { 247, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
4663 { 249, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM }
4666 static bool run_openattrtest(int dummy)
4668 static struct cli_state *cli1;
4669 const char *fname = "\\openattr.file";
4671 bool correct = True;
4673 unsigned int i, j, k, l;
4675 printf("starting open attr test\n");
4677 if (!torture_open_connection(&cli1, 0)) {
4681 cli_sockopt(cli1, sockops);
4683 for (k = 0, i = 0; i < sizeof(open_attrs_table)/sizeof(uint32); i++) {
4684 cli_setatr(cli1, fname, 0, 0);
4685 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
4686 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_WRITE_DATA, open_attrs_table[i],
4687 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
4688 printf("open %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
4692 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4693 printf("close %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
4697 for (j = 0; j < sizeof(open_attrs_table)/sizeof(uint32); j++) {
4698 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA, open_attrs_table[j],
4699 FILE_SHARE_NONE, FILE_OVERWRITE, 0, 0, &fnum1))) {
4700 for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
4701 if (attr_results[l].num == k) {
4702 printf("[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(0x%x:%s)\n",
4703 k, open_attrs_table[i],
4704 open_attrs_table[j],
4705 fname, NT_STATUS_V(cli_nt_error(cli1)), cli_errstr(cli1));
4709 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_ACCESS_DENIED)) {
4710 printf("[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s\n",
4711 k, open_attrs_table[i], open_attrs_table[j],
4716 printf("[%d] trunc open 0x%x -> 0x%x failed\n", k, open_attrs_table[i], open_attrs_table[j]);
4722 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
4723 printf("close %d (2) of %s failed (%s)\n", j, fname, cli_errstr(cli1));
4727 if (!NT_STATUS_IS_OK(cli_getatr(cli1, fname, &attr, NULL, NULL))) {
4728 printf("getatr(2) failed (%s)\n", cli_errstr(cli1));
4733 printf("[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n",
4734 k, open_attrs_table[i], open_attrs_table[j], attr );
4737 for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
4738 if (attr_results[l].num == k) {
4739 if (attr != attr_results[l].result_attr ||
4740 open_attrs_table[i] != attr_results[l].init_attr ||
4741 open_attrs_table[j] != attr_results[l].trunc_attr) {
4742 printf("getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x\n",
4743 open_attrs_table[i],
4744 open_attrs_table[j],
4746 attr_results[l].result_attr);
4756 cli_setatr(cli1, fname, 0, 0);
4757 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
4759 printf("open attr test %s.\n", correct ? "passed" : "failed");
4761 if (!torture_close_connection(cli1)) {
4767 static void list_fn(const char *mnt, file_info *finfo, const char *name, void *state)
4773 test directory listing speed
4775 static bool run_dirtest(int dummy)
4778 static struct cli_state *cli;
4781 bool correct = True;
4783 printf("starting directory test\n");
4785 if (!torture_open_connection(&cli, 0)) {
4789 cli_sockopt(cli, sockops);
4792 for (i=0;i<torture_numops;i++) {
4794 slprintf(fname, sizeof(fname), "\\%x", (int)random());
4795 if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum))) {
4796 fprintf(stderr,"Failed to open %s\n", fname);
4799 cli_close(cli, fnum);
4804 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
4805 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
4806 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
4808 printf("dirtest core %g seconds\n", end_timer() - t1);
4811 for (i=0;i<torture_numops;i++) {
4813 slprintf(fname, sizeof(fname), "\\%x", (int)random());
4814 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
4817 if (!torture_close_connection(cli)) {
4821 printf("finished dirtest\n");
4826 static void del_fn(const char *mnt, file_info *finfo, const char *mask, void *state)
4828 struct cli_state *pcli = (struct cli_state *)state;
4830 slprintf(fname, sizeof(fname), "\\LISTDIR\\%s", finfo->name);
4832 if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
4835 if (finfo->mode & aDIR) {
4836 if (!NT_STATUS_IS_OK(cli_rmdir(pcli, fname)))
4837 printf("del_fn: failed to rmdir %s\n,", fname );
4839 if (!NT_STATUS_IS_OK(cli_unlink(pcli, fname, aSYSTEM | aHIDDEN)))
4840 printf("del_fn: failed to unlink %s\n,", fname );
4846 sees what IOCTLs are supported
4848 bool torture_ioctl_test(int dummy)
4850 static struct cli_state *cli;
4851 uint16_t device, function;
4853 const char *fname = "\\ioctl.dat";
4857 if (!torture_open_connection(&cli, 0)) {
4861 printf("starting ioctl test\n");
4863 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
4865 if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum))) {
4866 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
4870 status = cli_raw_ioctl(cli, fnum, 0x2d0000 | (0x0420<<2), &blob);
4871 printf("ioctl device info: %s\n", cli_errstr(cli));
4873 status = cli_raw_ioctl(cli, fnum, IOCTL_QUERY_JOB_INFO, &blob);
4874 printf("ioctl job info: %s\n", cli_errstr(cli));
4876 for (device=0;device<0x100;device++) {
4877 printf("testing device=0x%x\n", device);
4878 for (function=0;function<0x100;function++) {
4879 uint32 code = (device<<16) | function;
4881 status = cli_raw_ioctl(cli, fnum, code, &blob);
4883 if (NT_STATUS_IS_OK(status)) {
4884 printf("ioctl 0x%x OK : %d bytes\n", (int)code,
4886 data_blob_free(&blob);
4891 if (!torture_close_connection(cli)) {
4900 tries varients of chkpath
4902 bool torture_chkpath_test(int dummy)
4904 static struct cli_state *cli;
4908 if (!torture_open_connection(&cli, 0)) {
4912 printf("starting chkpath test\n");
4914 /* cleanup from an old run */
4915 cli_rmdir(cli, "\\chkpath.dir\\dir2");
4916 cli_unlink(cli, "\\chkpath.dir\\*", aSYSTEM | aHIDDEN);
4917 cli_rmdir(cli, "\\chkpath.dir");
4919 if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\chkpath.dir"))) {
4920 printf("mkdir1 failed : %s\n", cli_errstr(cli));
4924 if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\chkpath.dir\\dir2"))) {
4925 printf("mkdir2 failed : %s\n", cli_errstr(cli));
4929 if (!NT_STATUS_IS_OK(cli_open(cli, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum))) {
4930 printf("open1 failed (%s)\n", cli_errstr(cli));
4933 cli_close(cli, fnum);
4935 if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir"))) {
4936 printf("chkpath1 failed: %s\n", cli_errstr(cli));
4940 if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir\\dir2"))) {
4941 printf("chkpath2 failed: %s\n", cli_errstr(cli));
4945 if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir\\foo.txt"))) {
4946 ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath,
4947 NT_STATUS_NOT_A_DIRECTORY);
4949 printf("* chkpath on a file should fail\n");
4953 if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir\\bar.txt"))) {
4954 ret = check_error(__LINE__, cli, ERRDOS, ERRbadfile,
4955 NT_STATUS_OBJECT_NAME_NOT_FOUND);
4957 printf("* chkpath on a non existant file should fail\n");
4961 if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir\\dirxx\\bar.txt"))) {
4962 ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath,
4963 NT_STATUS_OBJECT_PATH_NOT_FOUND);
4965 printf("* chkpath on a non existent component should fail\n");
4969 cli_rmdir(cli, "\\chkpath.dir\\dir2");
4970 cli_unlink(cli, "\\chkpath.dir\\*", aSYSTEM | aHIDDEN);
4971 cli_rmdir(cli, "\\chkpath.dir");
4973 if (!torture_close_connection(cli)) {
4980 static bool run_eatest(int dummy)
4982 static struct cli_state *cli;
4983 const char *fname = "\\eatest.txt";
4984 bool correct = True;
4988 struct ea_struct *ea_list = NULL;
4989 TALLOC_CTX *mem_ctx = talloc_init("eatest");
4991 printf("starting eatest\n");
4993 if (!torture_open_connection(&cli, 0)) {
4994 talloc_destroy(mem_ctx);
4998 cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
4999 if (!NT_STATUS_IS_OK(cli_ntcreate(cli, fname, 0,
5000 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
5001 FILE_SHARE_NONE, FILE_OVERWRITE_IF,
5002 0x4044, 0, &fnum))) {
5003 printf("open failed - %s\n", cli_errstr(cli));
5004 talloc_destroy(mem_ctx);
5008 for (i = 0; i < 10; i++) {
5009 fstring ea_name, ea_val;
5011 slprintf(ea_name, sizeof(ea_name), "EA_%d", i);
5012 memset(ea_val, (char)i+1, i+1);
5013 if (!cli_set_ea_fnum(cli, fnum, ea_name, ea_val, i+1)) {
5014 printf("ea_set of name %s failed - %s\n", ea_name, cli_errstr(cli));
5015 talloc_destroy(mem_ctx);
5020 cli_close(cli, fnum);
5021 for (i = 0; i < 10; i++) {
5022 fstring ea_name, ea_val;
5024 slprintf(ea_name, sizeof(ea_name), "EA_%d", i+10);
5025 memset(ea_val, (char)i+1, i+1);
5026 if (!cli_set_ea_path(cli, fname, ea_name, ea_val, i+1)) {
5027 printf("ea_set of name %s failed - %s\n", ea_name, cli_errstr(cli));
5028 talloc_destroy(mem_ctx);
5033 if (!cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list)) {
5034 printf("ea_get list failed - %s\n", cli_errstr(cli));
5038 printf("num_eas = %d\n", (int)num_eas);
5040 if (num_eas != 20) {
5041 printf("Should be 20 EA's stored... failing.\n");
5045 for (i = 0; i < num_eas; i++) {
5046 printf("%d: ea_name = %s. Val = ", i, ea_list[i].name);
5047 dump_data(0, ea_list[i].value.data,
5048 ea_list[i].value.length);
5051 /* Setting EA's to zero length deletes them. Test this */
5052 printf("Now deleting all EA's - case indepenent....\n");
5055 cli_set_ea_path(cli, fname, "", "", 0);
5057 for (i = 0; i < 20; i++) {
5059 slprintf(ea_name, sizeof(ea_name), "ea_%d", i);
5060 if (!cli_set_ea_path(cli, fname, ea_name, "", 0)) {
5061 printf("ea_set of name %s failed - %s\n", ea_name, cli_errstr(cli));
5062 talloc_destroy(mem_ctx);
5068 if (!cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list)) {
5069 printf("ea_get list failed - %s\n", cli_errstr(cli));
5073 printf("num_eas = %d\n", (int)num_eas);
5074 for (i = 0; i < num_eas; i++) {
5075 printf("%d: ea_name = %s. Val = ", i, ea_list[i].name);
5076 dump_data(0, ea_list[i].value.data,
5077 ea_list[i].value.length);
5081 printf("deleting EA's failed.\n");
5085 /* Try and delete a non existant EA. */
5086 if (!cli_set_ea_path(cli, fname, "foo", "", 0)) {
5087 printf("deleting non-existant EA 'foo' should succeed. %s\n", cli_errstr(cli));
5091 talloc_destroy(mem_ctx);
5092 if (!torture_close_connection(cli)) {
5099 static bool run_dirtest1(int dummy)
5102 static struct cli_state *cli;
5105 bool correct = True;
5107 printf("starting directory test\n");
5109 if (!torture_open_connection(&cli, 0)) {
5113 cli_sockopt(cli, sockops);
5115 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
5116 cli_list(cli, "\\LISTDIR\\*", aDIR, del_fn, cli);
5117 cli_rmdir(cli, "\\LISTDIR");
5118 cli_mkdir(cli, "\\LISTDIR");
5120 /* Create 1000 files and 1000 directories. */
5121 for (i=0;i<1000;i++) {
5123 slprintf(fname, sizeof(fname), "\\LISTDIR\\f%d", i);
5124 if (!NT_STATUS_IS_OK(cli_ntcreate(cli, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
5125 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum))) {
5126 fprintf(stderr,"Failed to open %s\n", fname);
5129 cli_close(cli, fnum);
5131 for (i=0;i<1000;i++) {
5133 slprintf(fname, sizeof(fname), "\\LISTDIR\\d%d", i);
5134 if (!NT_STATUS_IS_OK(cli_mkdir(cli, fname))) {
5135 fprintf(stderr,"Failed to open %s\n", fname);
5140 /* Now ensure that doing an old list sees both files and directories. */
5141 num_seen = cli_list_old(cli, "\\LISTDIR\\*", aDIR, list_fn, NULL);
5142 printf("num_seen = %d\n", num_seen );
5143 /* We should see 100 files + 1000 directories + . and .. */
5144 if (num_seen != 2002)
5147 /* Ensure if we have the "must have" bits we only see the
5150 num_seen = cli_list_old(cli, "\\LISTDIR\\*", (aDIR<<8)|aDIR, list_fn, NULL);
5151 printf("num_seen = %d\n", num_seen );
5152 if (num_seen != 1002)
5155 num_seen = cli_list_old(cli, "\\LISTDIR\\*", (aARCH<<8)|aDIR, list_fn, NULL);
5156 printf("num_seen = %d\n", num_seen );
5157 if (num_seen != 1000)
5160 /* Delete everything. */
5161 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
5162 cli_list(cli, "\\LISTDIR\\*", aDIR, del_fn, cli);
5163 cli_rmdir(cli, "\\LISTDIR");
5166 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
5167 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
5168 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
5171 if (!torture_close_connection(cli)) {
5175 printf("finished dirtest1\n");
5180 static bool run_error_map_extract(int dummy) {
5182 static struct cli_state *c_dos;
5183 static struct cli_state *c_nt;
5188 uint32 flgs2, errnum;
5195 /* NT-Error connection */
5197 if (!(c_nt = open_nbt_connection())) {
5201 c_nt->use_spnego = False;
5203 status = cli_negprot(c_nt);
5205 if (!NT_STATUS_IS_OK(status)) {
5206 printf("%s rejected the NT-error negprot (%s)\n", host,
5212 if (!NT_STATUS_IS_OK(cli_session_setup(c_nt, "", "", 0, "", 0,
5214 printf("%s rejected the NT-error initial session setup (%s)\n",host, cli_errstr(c_nt));
5218 /* DOS-Error connection */
5220 if (!(c_dos = open_nbt_connection())) {
5224 c_dos->use_spnego = False;
5225 c_dos->force_dos_errors = True;
5227 status = cli_negprot(c_dos);
5228 if (!NT_STATUS_IS_OK(status)) {
5229 printf("%s rejected the DOS-error negprot (%s)\n", host,
5231 cli_shutdown(c_dos);
5235 if (!NT_STATUS_IS_OK(cli_session_setup(c_dos, "", "", 0, "", 0,
5237 printf("%s rejected the DOS-error initial session setup (%s)\n",host, cli_errstr(c_dos));
5241 for (error=(0xc0000000 | 0x1); error < (0xc0000000| 0xFFF); error++) {
5242 fstr_sprintf(user, "%X", error);
5244 if (NT_STATUS_IS_OK(cli_session_setup(c_nt, user,
5245 password, strlen(password),
5246 password, strlen(password),
5248 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
5251 flgs2 = SVAL(c_nt->inbuf,smb_flg2);
5253 /* Case #1: 32-bit NT errors */
5254 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
5255 nt_status = NT_STATUS(IVAL(c_nt->inbuf,smb_rcls));
5257 printf("/** Dos error on NT connection! (%s) */\n",
5259 nt_status = NT_STATUS(0xc0000000);
5262 if (NT_STATUS_IS_OK(cli_session_setup(c_dos, user,
5263 password, strlen(password),
5264 password, strlen(password),
5266 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
5268 flgs2 = SVAL(c_dos->inbuf,smb_flg2), errnum;
5270 /* Case #1: 32-bit NT errors */
5271 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
5272 printf("/** NT error on DOS connection! (%s) */\n",
5274 errnum = errclass = 0;
5276 cli_dos_error(c_dos, &errclass, &errnum);
5279 if (NT_STATUS_V(nt_status) != error) {
5280 printf("/*\t{ This NT error code was 'sqashed'\n\t from %s to %s \n\t during the session setup }\n*/\n",
5281 get_nt_error_c_code(NT_STATUS(error)),
5282 get_nt_error_c_code(nt_status));
5285 printf("\t{%s,\t%s,\t%s},\n",
5286 smb_dos_err_class(errclass),
5287 smb_dos_err_name(errclass, errnum),
5288 get_nt_error_c_code(NT_STATUS(error)));
5293 static bool run_sesssetup_bench(int dummy)
5295 static struct cli_state *c;
5296 const char *fname = "\\file.dat";
5301 if (!torture_open_connection(&c, 0)) {
5305 if (!NT_STATUS_IS_OK(cli_ntcreate(
5306 c, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
5307 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
5308 FILE_DELETE_ON_CLOSE, 0, &fnum))) {
5309 d_printf("open %s failed: %s\n", fname, cli_errstr(c));
5313 for (i=0; i<torture_numops; i++) {
5314 status = cli_session_setup(
5316 password, strlen(password),
5317 password, strlen(password),
5319 if (!NT_STATUS_IS_OK(status)) {
5320 d_printf("(%s) cli_session_setup failed: %s\n",
5321 __location__, nt_errstr(status));
5325 d_printf("\r%d ", (int)c->vuid);
5327 if (!cli_ulogoff(c)) {
5328 d_printf("(%s) cli_ulogoff failed: %s\n",
5329 __location__, cli_errstr(c));
5338 static bool subst_test(const char *str, const char *user, const char *domain,
5339 uid_t uid, gid_t gid, const char *expected)
5344 subst = talloc_sub_specified(talloc_tos(), str, user, domain, uid, gid);
5346 if (strcmp(subst, expected) != 0) {
5347 printf("sub_specified(%s, %s, %s, %d, %d) returned [%s], expected "
5348 "[%s]\n", str, user, domain, (int)uid, (int)gid, subst,
5357 static void chain1_open_completion(struct tevent_req *req)
5361 status = cli_open_recv(req, &fnum);
5364 d_printf("cli_open_recv returned %s: %d\n",
5366 NT_STATUS_IS_OK(status) ? fnum : -1);
5369 static void chain1_write_completion(struct tevent_req *req)
5373 status = cli_write_andx_recv(req, &written);
5376 d_printf("cli_write_andx_recv returned %s: %d\n",
5378 NT_STATUS_IS_OK(status) ? (int)written : -1);
5381 static void chain1_close_completion(struct tevent_req *req)
5384 bool *done = (bool *)tevent_req_callback_data_void(req);
5386 status = cli_close_recv(req);
5391 d_printf("cli_close returned %s\n", nt_errstr(status));
5394 static bool run_chain1(int dummy)
5396 struct cli_state *cli1;
5397 struct event_context *evt = event_context_init(NULL);
5398 struct tevent_req *reqs[3], *smbreqs[3];
5400 const char *str = "foobar";
5403 printf("starting chain1 test\n");
5404 if (!torture_open_connection(&cli1, 0)) {
5408 cli_sockopt(cli1, sockops);
5410 reqs[0] = cli_open_create(talloc_tos(), evt, cli1, "\\test",
5411 O_CREAT|O_RDWR, 0, &smbreqs[0]);
5412 if (reqs[0] == NULL) return false;
5413 tevent_req_set_callback(reqs[0], chain1_open_completion, NULL);
5416 reqs[1] = cli_write_andx_create(talloc_tos(), evt, cli1, 0, 0,
5417 (uint8_t *)str, 0, strlen(str)+1,
5418 smbreqs, 1, &smbreqs[1]);
5419 if (reqs[1] == NULL) return false;
5420 tevent_req_set_callback(reqs[1], chain1_write_completion, NULL);
5422 reqs[2] = cli_close_create(talloc_tos(), evt, cli1, 0, &smbreqs[2]);
5423 if (reqs[2] == NULL) return false;
5424 tevent_req_set_callback(reqs[2], chain1_close_completion, &done);
5426 status = cli_smb_chain_send(smbreqs, ARRAY_SIZE(smbreqs));
5427 if (!NT_STATUS_IS_OK(status)) {
5432 event_loop_once(evt);
5435 torture_close_connection(cli1);
5439 static void chain2_sesssetup_completion(struct tevent_req *req)
5442 status = cli_session_setup_guest_recv(req);
5443 d_printf("sesssetup returned %s\n", nt_errstr(status));
5446 static void chain2_tcon_completion(struct tevent_req *req)
5448 bool *done = (bool *)tevent_req_callback_data_void(req);
5450 status = cli_tcon_andx_recv(req);
5451 d_printf("tcon_and_x returned %s\n", nt_errstr(status));
5455 static bool run_chain2(int dummy)
5457 struct cli_state *cli1;
5458 struct event_context *evt = event_context_init(NULL);
5459 struct tevent_req *reqs[2], *smbreqs[2];
5463 printf("starting chain2 test\n");
5464 status = cli_start_connection(&cli1, global_myname(), host, NULL,
5465 port_to_use, Undefined, 0, NULL);
5466 if (!NT_STATUS_IS_OK(status)) {
5470 cli_sockopt(cli1, sockops);
5472 reqs[0] = cli_session_setup_guest_create(talloc_tos(), evt, cli1,
5474 if (reqs[0] == NULL) return false;
5475 tevent_req_set_callback(reqs[0], chain2_sesssetup_completion, NULL);
5477 reqs[1] = cli_tcon_andx_create(talloc_tos(), evt, cli1, "IPC$",
5478 "?????", NULL, 0, &smbreqs[1]);
5479 if (reqs[1] == NULL) return false;
5480 tevent_req_set_callback(reqs[1], chain2_tcon_completion, &done);
5482 status = cli_smb_chain_send(smbreqs, ARRAY_SIZE(smbreqs));
5483 if (!NT_STATUS_IS_OK(status)) {
5488 event_loop_once(evt);
5491 torture_close_connection(cli1);
5496 struct torture_createdel_state {
5497 struct tevent_context *ev;
5498 struct cli_state *cli;
5501 static void torture_createdel_created(struct tevent_req *subreq);
5502 static void torture_createdel_closed(struct tevent_req *subreq);
5504 static struct tevent_req *torture_createdel_send(TALLOC_CTX *mem_ctx,
5505 struct tevent_context *ev,
5506 struct cli_state *cli,
5509 struct tevent_req *req, *subreq;
5510 struct torture_createdel_state *state;
5512 req = tevent_req_create(mem_ctx, &state,
5513 struct torture_createdel_state);
5520 subreq = cli_ntcreate_send(
5521 state, ev, cli, name, 0,
5522 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
5523 FILE_ATTRIBUTE_NORMAL,
5524 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
5525 FILE_OPEN_IF, FILE_DELETE_ON_CLOSE, 0);
5527 if (tevent_req_nomem(subreq, req)) {
5528 return tevent_req_post(req, ev);
5530 tevent_req_set_callback(subreq, torture_createdel_created, req);
5534 static void torture_createdel_created(struct tevent_req *subreq)
5536 struct tevent_req *req = tevent_req_callback_data(
5537 subreq, struct tevent_req);
5538 struct torture_createdel_state *state = tevent_req_data(
5539 req, struct torture_createdel_state);
5543 status = cli_ntcreate_recv(subreq, &fnum);
5544 TALLOC_FREE(subreq);
5545 if (!NT_STATUS_IS_OK(status)) {
5546 DEBUG(10, ("cli_ntcreate_recv returned %s\n",
5547 nt_errstr(status)));
5548 tevent_req_nterror(req, status);
5552 subreq = cli_close_send(state, state->ev, state->cli, fnum);
5553 if (tevent_req_nomem(subreq, req)) {
5556 tevent_req_set_callback(subreq, torture_createdel_closed, req);
5559 static void torture_createdel_closed(struct tevent_req *subreq)
5561 struct tevent_req *req = tevent_req_callback_data(
5562 subreq, struct tevent_req);
5565 status = cli_close_recv(subreq);
5566 if (!NT_STATUS_IS_OK(status)) {
5567 DEBUG(10, ("cli_close_recv returned %s\n", nt_errstr(status)));
5568 tevent_req_nterror(req, status);
5571 tevent_req_done(req);
5574 static NTSTATUS torture_createdel_recv(struct tevent_req *req)
5576 return tevent_req_simple_recv_ntstatus(req);
5579 struct torture_createdels_state {
5580 struct tevent_context *ev;
5581 struct cli_state *cli;
5582 const char *base_name;
5586 struct tevent_req **reqs;
5589 static void torture_createdels_done(struct tevent_req *subreq);
5591 static struct tevent_req *torture_createdels_send(TALLOC_CTX *mem_ctx,
5592 struct tevent_context *ev,
5593 struct cli_state *cli,
5594 const char *base_name,
5598 struct tevent_req *req;
5599 struct torture_createdels_state *state;
5602 req = tevent_req_create(mem_ctx, &state,
5603 struct torture_createdels_state);
5609 state->base_name = talloc_strdup(state, base_name);
5610 if (tevent_req_nomem(state->base_name, req)) {
5611 return tevent_req_post(req, ev);
5613 state->num_files = MAX(num_parallel, num_files);
5615 state->received = 0;
5617 state->reqs = talloc_array(state, struct tevent_req *, num_parallel);
5618 if (tevent_req_nomem(state->reqs, req)) {
5619 return tevent_req_post(req, ev);
5622 for (i=0; i<num_parallel; i++) {
5625 name = talloc_asprintf(state, "%s%8.8d", state->base_name,
5627 if (tevent_req_nomem(name, req)) {
5628 return tevent_req_post(req, ev);
5630 state->reqs[i] = torture_createdel_send(
5631 state->reqs, state->ev, state->cli, name);
5632 if (tevent_req_nomem(state->reqs[i], req)) {
5633 return tevent_req_post(req, ev);
5635 name = talloc_move(state->reqs[i], &name);
5636 tevent_req_set_callback(state->reqs[i],
5637 torture_createdels_done, req);
5643 static void torture_createdels_done(struct tevent_req *subreq)
5645 struct tevent_req *req = tevent_req_callback_data(
5646 subreq, struct tevent_req);
5647 struct torture_createdels_state *state = tevent_req_data(
5648 req, struct torture_createdels_state);
5649 size_t num_parallel = talloc_array_length(state->reqs);
5654 status = torture_createdel_recv(subreq);
5655 if (!NT_STATUS_IS_OK(status)){
5656 DEBUG(10, ("torture_createdel_recv returned %s\n",
5657 nt_errstr(status)));
5658 TALLOC_FREE(subreq);
5659 tevent_req_nterror(req, status);
5663 for (i=0; i<num_parallel; i++) {
5664 if (subreq == state->reqs[i]) {
5668 if (i == num_parallel) {
5669 DEBUG(10, ("received something we did not send\n"));
5670 tevent_req_nterror(req, NT_STATUS_INTERNAL_ERROR);
5673 TALLOC_FREE(state->reqs[i]);
5675 if (state->sent >= state->num_files) {
5676 tevent_req_done(req);
5680 name = talloc_asprintf(state, "%s%8.8d", state->base_name,
5682 if (tevent_req_nomem(name, req)) {
5685 state->reqs[i] = torture_createdel_send(state->reqs, state->ev,
5687 if (tevent_req_nomem(state->reqs[i], req)) {
5690 name = talloc_move(state->reqs[i], &name);
5691 tevent_req_set_callback(state->reqs[i], torture_createdels_done, req);
5695 static NTSTATUS torture_createdels_recv(struct tevent_req *req)
5697 return tevent_req_simple_recv_ntstatus(req);
5700 struct swallow_notify_state {
5701 struct tevent_context *ev;
5702 struct cli_state *cli;
5704 uint32_t completion_filter;
5706 bool (*fn)(uint32_t action, const char *name, void *priv);
5710 static void swallow_notify_done(struct tevent_req *subreq);
5712 static struct tevent_req *swallow_notify_send(TALLOC_CTX *mem_ctx,
5713 struct tevent_context *ev,
5714 struct cli_state *cli,
5716 uint32_t completion_filter,
5718 bool (*fn)(uint32_t action,
5723 struct tevent_req *req, *subreq;
5724 struct swallow_notify_state *state;
5726 req = tevent_req_create(mem_ctx, &state,
5727 struct swallow_notify_state);
5734 state->completion_filter = completion_filter;
5735 state->recursive = recursive;
5739 subreq = cli_notify_send(state, state->ev, state->cli, state->fnum,
5740 0xffff, state->completion_filter,
5742 if (tevent_req_nomem(subreq, req)) {
5743 return tevent_req_post(req, ev);
5745 tevent_req_set_callback(subreq, swallow_notify_done, req);
5749 static void swallow_notify_done(struct tevent_req *subreq)
5751 struct tevent_req *req = tevent_req_callback_data(
5752 subreq, struct tevent_req);
5753 struct swallow_notify_state *state = tevent_req_data(
5754 req, struct swallow_notify_state);
5756 uint32_t i, num_changes;
5757 struct notify_change *changes;
5759 status = cli_notify_recv(subreq, state, &num_changes, &changes);
5760 TALLOC_FREE(subreq);
5761 if (!NT_STATUS_IS_OK(status)) {
5762 DEBUG(10, ("cli_notify_recv returned %s\n",
5763 nt_errstr(status)));
5764 tevent_req_nterror(req, status);
5768 for (i=0; i<num_changes; i++) {
5769 state->fn(changes[i].action, changes[i].name, state->priv);
5771 TALLOC_FREE(changes);
5773 subreq = cli_notify_send(state, state->ev, state->cli, state->fnum,
5774 0xffff, state->completion_filter,
5776 if (tevent_req_nomem(subreq, req)) {
5779 tevent_req_set_callback(subreq, swallow_notify_done, req);
5782 static bool print_notifies(uint32_t action, const char *name, void *priv)
5784 if (DEBUGLEVEL > 5) {
5785 d_printf("%d %s\n", (int)action, name);
5790 static void notify_bench_done(struct tevent_req *req)
5792 int *num_finished = (int *)tevent_req_callback_data_void(req);
5796 static bool run_notify_bench(int dummy)
5798 const char *dname = "\\notify-bench";
5799 struct tevent_context *ev;
5802 struct tevent_req *req1, *req2;
5803 int i, num_unc_names;
5804 int num_finished = 0;
5806 printf("starting notify-bench test\n");
5808 if (use_multishare_conn) {
5810 unc_list = file_lines_load(multishare_conn_fname,
5811 &num_unc_names, 0, NULL);
5812 if (!unc_list || num_unc_names <= 0) {
5813 d_printf("Failed to load unc names list from '%s'\n",
5814 multishare_conn_fname);
5817 TALLOC_FREE(unc_list);
5822 ev = tevent_context_init(talloc_tos());
5824 d_printf("tevent_context_init failed\n");
5828 for (i=0; i<num_unc_names; i++) {
5829 struct cli_state *cli;
5832 base_fname = talloc_asprintf(talloc_tos(), "%s\\file%3.3d.",
5834 if (base_fname == NULL) {
5838 if (!torture_open_connection(&cli, i)) {
5842 status = cli_ntcreate(cli, dname, 0,
5843 MAXIMUM_ALLOWED_ACCESS,
5844 0, FILE_SHARE_READ|FILE_SHARE_WRITE|
5846 FILE_OPEN_IF, FILE_DIRECTORY_FILE, 0,
5849 if (!NT_STATUS_IS_OK(status)) {
5850 d_printf("Could not create %s: %s\n", dname,
5855 req1 = swallow_notify_send(talloc_tos(), ev, cli, dnum,
5856 FILE_NOTIFY_CHANGE_FILE_NAME |
5857 FILE_NOTIFY_CHANGE_DIR_NAME |
5858 FILE_NOTIFY_CHANGE_ATTRIBUTES |
5859 FILE_NOTIFY_CHANGE_LAST_WRITE,
5860 false, print_notifies, NULL);
5862 d_printf("Could not create notify request\n");
5866 req2 = torture_createdels_send(talloc_tos(), ev, cli,
5867 base_fname, 10, torture_numops);
5869 d_printf("Could not create createdels request\n");
5872 TALLOC_FREE(base_fname);
5874 tevent_req_set_callback(req2, notify_bench_done,
5878 while (num_finished < num_unc_names) {
5880 ret = tevent_loop_once(ev);
5882 d_printf("tevent_loop_once failed\n");
5887 if (!tevent_req_poll(req2, ev)) {
5888 d_printf("tevent_req_poll failed\n");
5891 status = torture_createdels_recv(req2);
5892 d_printf("torture_createdels_recv returned %s\n", nt_errstr(status));
5897 static bool run_mangle1(int dummy)
5899 struct cli_state *cli;
5900 const char *fname = "this_is_a_long_fname_to_be_mangled.txt";
5904 time_t change_time, access_time, write_time;
5908 printf("starting mangle1 test\n");
5909 if (!torture_open_connection(&cli, 0)) {
5913 cli_sockopt(cli, sockops);
5915 if (!NT_STATUS_IS_OK(cli_ntcreate(
5916 cli, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
5917 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0, 0, &fnum))) {
5918 d_printf("open %s failed: %s\n", fname, cli_errstr(cli));
5921 cli_close(cli, fnum);
5923 status = cli_qpathinfo_alt_name(cli, fname, alt_name);
5924 if (!NT_STATUS_IS_OK(status)) {
5925 d_printf("cli_qpathinfo_alt_name failed: %s\n",
5929 d_printf("alt_name: %s\n", alt_name);
5931 if (!NT_STATUS_IS_OK(cli_open(cli, alt_name, O_RDONLY, DENY_NONE, &fnum))) {
5932 d_printf("cli_open(%s) failed: %s\n", alt_name,
5936 cli_close(cli, fnum);
5938 if (!cli_qpathinfo(cli, alt_name, &change_time, &access_time,
5939 &write_time, &size, &mode)) {
5940 d_printf("cli_qpathinfo(%s) failed: %s\n", alt_name,
5948 static size_t null_source(uint8_t *buf, size_t n, void *priv)
5950 size_t *to_pull = (size_t *)priv;
5951 size_t thistime = *to_pull;
5953 thistime = MIN(thistime, n);
5954 if (thistime == 0) {
5958 memset(buf, 0, thistime);
5959 *to_pull -= thistime;
5963 static bool run_windows_write(int dummy)
5965 struct cli_state *cli1;
5969 const char *fname = "\\writetest.txt";
5973 printf("starting windows_write test\n");
5974 if (!torture_open_connection(&cli1, 0)) {
5978 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum))) {
5979 printf("open failed (%s)\n", cli_errstr(cli1));
5983 cli_sockopt(cli1, sockops);
5987 for (i=0; i<torture_numops; i++) {
5989 off_t start = i * torture_blocksize;
5991 size_t to_pull = torture_blocksize - 1;
5993 if (cli_write(cli1, fnum, 0, &c,
5994 start + torture_blocksize - 1, 1) != 1) {
5995 printf("cli_write failed: %s\n", cli_errstr(cli1));
5999 status = cli_push(cli1, fnum, 0, i * torture_blocksize, torture_blocksize,
6000 null_source, &to_pull);
6001 if (!NT_STATUS_IS_OK(status)) {
6002 printf("cli_push returned: %s\n", nt_errstr(status));
6007 seconds = end_timer();
6008 kbytes = (double)torture_blocksize * torture_numops;
6011 printf("Wrote %d kbytes in %.2f seconds: %d kb/sec\n", (int)kbytes,
6012 (double)seconds, (int)(kbytes/seconds));
6016 cli_close(cli1, fnum);
6017 cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
6018 torture_close_connection(cli1);
6022 static bool run_cli_echo(int dummy)
6024 struct cli_state *cli;
6027 printf("starting cli_echo test\n");
6028 if (!torture_open_connection(&cli, 0)) {
6031 cli_sockopt(cli, sockops);
6033 status = cli_echo(cli, 5, data_blob_const("hello", 5));
6035 d_printf("cli_echo returned %s\n", nt_errstr(status));
6037 torture_close_connection(cli);
6038 return NT_STATUS_IS_OK(status);
6041 static bool run_uid_regression_test(int dummy)
6043 static struct cli_state *cli;
6046 bool correct = True;
6048 printf("starting uid regression test\n");
6050 if (!torture_open_connection(&cli, 0)) {
6054 cli_sockopt(cli, sockops);
6056 /* Ok - now save then logoff our current user. */
6057 old_vuid = cli->vuid;
6059 if (!cli_ulogoff(cli)) {
6060 d_printf("(%s) cli_ulogoff failed: %s\n",
6061 __location__, cli_errstr(cli));
6066 cli->vuid = old_vuid;
6068 /* Try an operation. */
6069 if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\uid_reg_test"))) {
6070 /* We expect bad uid. */
6071 if (!check_error(__LINE__, cli, ERRSRV, ERRbaduid,
6072 NT_STATUS_NO_SUCH_USER)) {
6077 old_cnum = cli->cnum;
6079 /* Now try a SMBtdis with the invald vuid set to zero. */
6082 /* This should succeed. */
6083 if (cli_tdis(cli)) {
6084 printf("First tdis with invalid vuid should succeed.\n");
6086 printf("First tdis failed (%s)\n", cli_errstr(cli));
6089 cli->vuid = old_vuid;
6090 cli->cnum = old_cnum;
6092 /* This should fail. */
6093 if (cli_tdis(cli)) {
6094 printf("Second tdis with invalid vuid should fail - succeeded instead !.\n");
6096 /* Should be bad tid. */
6097 if (!check_error(__LINE__, cli, ERRSRV, ERRinvnid,
6098 NT_STATUS_NETWORK_NAME_DELETED)) {
6103 cli_rmdir(cli, "\\uid_reg_test");
6112 static const char *illegal_chars = "*\\/?<>|\":";
6113 static char force_shortname_chars[] = " +,.[];=\177";
6115 static void shortname_del_fn(const char *mnt, file_info *finfo, const char *mask, void *state)
6117 struct cli_state *pcli = (struct cli_state *)state;
6119 slprintf(fname, sizeof(fname), "\\shortname\\%s", finfo->name);
6121 if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
6124 if (finfo->mode & aDIR) {
6125 if (!NT_STATUS_IS_OK(cli_rmdir(pcli, fname)))
6126 printf("del_fn: failed to rmdir %s\n,", fname );
6128 if (!NT_STATUS_IS_OK(cli_unlink(pcli, fname, aSYSTEM | aHIDDEN)))
6129 printf("del_fn: failed to unlink %s\n,", fname );
6138 static void shortname_list_fn(const char *mnt, file_info *finfo, const char *name, void *state)
6140 struct sn_state *s = (struct sn_state *)state;
6144 printf("shortname list: i = %d, name = |%s|, shortname = |%s|\n",
6145 i, finfo->name, finfo->short_name);
6148 if (strchr(force_shortname_chars, i)) {
6149 if (!finfo->short_name[0]) {
6150 /* Shortname not created when it should be. */
6151 d_printf("(%s) ERROR: Shortname was not created for file %s containing %d\n",
6152 __location__, finfo->name, i);
6155 } else if (finfo->short_name[0]){
6156 /* Shortname created when it should not be. */
6157 d_printf("(%s) ERROR: Shortname %s was created for file %s\n",
6158 __location__, finfo->short_name, finfo->name);
6163 static bool run_shortname_test(int dummy)
6165 static struct cli_state *cli;
6166 bool correct = True;
6171 printf("starting shortname test\n");
6173 if (!torture_open_connection(&cli, 0)) {
6177 cli_sockopt(cli, sockops);
6179 cli_list(cli, "\\shortname\\*", 0, shortname_del_fn, cli);
6180 cli_list(cli, "\\shortname\\*", aDIR, shortname_del_fn, cli);
6181 cli_rmdir(cli, "\\shortname");
6183 if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\shortname"))) {
6184 d_printf("(%s) cli_mkdir of \\shortname failed: %s\n",
6185 __location__, cli_errstr(cli));
6190 strlcpy(fname, "\\shortname\\", sizeof(fname));
6191 strlcat(fname, "test .txt", sizeof(fname));
6195 for (i = 32; i < 128; i++) {
6197 uint16_t fnum = (uint16_t)-1;
6201 if (strchr(illegal_chars, i)) {
6206 status = cli_ntcreate(cli, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
6207 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum);
6208 if (!NT_STATUS_IS_OK(status)) {
6209 d_printf("(%s) cli_nt_create of %s failed: %s\n",
6210 __location__, fname, cli_errstr(cli));
6214 cli_close(cli, fnum);
6215 if (cli_list(cli, "\\shortname\\test*.*", 0, shortname_list_fn, &s) != 1) {
6216 d_printf("(%s) failed to list %s: %s\n",
6217 __location__, fname, cli_errstr(cli));
6221 if (!NT_STATUS_IS_OK(cli_unlink(cli, fname, aSYSTEM | aHIDDEN))) {
6222 d_printf("(%s) failed to delete %s: %s\n",
6223 __location__, fname, cli_errstr(cli));
6236 cli_list(cli, "\\shortname\\*", 0, shortname_del_fn, cli);
6237 cli_list(cli, "\\shortname\\*", aDIR, shortname_del_fn, cli);
6238 cli_rmdir(cli, "\\shortname");
6239 torture_close_connection(cli);
6243 static void pagedsearch_cb(struct tevent_req *req)
6246 struct tldap_message *msg;
6249 rc = tldap_search_paged_recv(req, talloc_tos(), &msg);
6250 if (rc != TLDAP_SUCCESS) {
6251 d_printf("tldap_search_paged_recv failed: %s\n",
6252 tldap_err2string(rc));
6255 if (tldap_msg_type(msg) != TLDAP_RES_SEARCH_ENTRY) {
6259 if (!tldap_entry_dn(msg, &dn)) {
6260 d_printf("tldap_entry_dn failed\n");
6263 d_printf("%s\n", dn);
6267 static bool run_tldap(int dummy)
6269 struct tldap_context *ld;
6272 struct sockaddr_storage addr;
6273 struct tevent_context *ev;
6274 struct tevent_req *req;
6277 if (!resolve_name(host, &addr, 0, false)) {
6278 d_printf("could not find host %s\n", host);
6281 status = open_socket_out(&addr, 389, 9999, &fd);
6282 if (!NT_STATUS_IS_OK(status)) {
6283 d_printf("open_socket_out failed: %s\n", nt_errstr(status));
6287 ld = tldap_context_create(talloc_tos(), fd);
6290 d_printf("tldap_context_create failed\n");
6294 rc = tldap_fetch_rootdse(ld);
6295 if (rc != TLDAP_SUCCESS) {
6296 d_printf("tldap_fetch_rootdse failed: %s\n",
6297 tldap_errstr(talloc_tos(), ld, rc));
6301 basedn = tldap_talloc_single_attribute(
6302 tldap_rootdse(ld), "defaultNamingContext", talloc_tos());
6303 if (basedn == NULL) {
6304 d_printf("no defaultNamingContext\n");
6307 d_printf("defaultNamingContext: %s\n", basedn);
6309 ev = tevent_context_init(talloc_tos());
6311 d_printf("tevent_context_init failed\n");
6315 req = tldap_search_paged_send(talloc_tos(), ev, ld, basedn,
6316 TLDAP_SCOPE_SUB, "(objectclass=*)",
6318 NULL, 0, NULL, 0, 0, 0, 0, 5);
6320 d_printf("tldap_search_paged_send failed\n");
6323 tevent_req_set_callback(req, pagedsearch_cb, NULL);
6325 tevent_req_poll(req, ev);
6333 static bool run_streamerror(int dummy)
6335 struct cli_state *cli;
6336 const char *dname = "\\testdir";
6337 const char *streamname =
6338 "testdir:{4c8cc155-6c1e-11d1-8e41-00c04fb9386d}:$DATA";
6340 time_t change_time, access_time, write_time;
6342 uint16_t mode, fnum;
6345 if (!torture_open_connection(&cli, 0)) {
6349 cli_rmdir(cli, dname);
6351 status = cli_mkdir(cli, dname);
6352 if (!NT_STATUS_IS_OK(status)) {
6353 printf("mkdir failed: %s\n", nt_errstr(status));
6357 cli_qpathinfo(cli, streamname, &change_time, &access_time, &write_time,
6359 status = cli_nt_error(cli);
6361 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
6362 printf("pathinfo returned %s, expected "
6363 "NT_STATUS_OBJECT_NAME_NOT_FOUND\n",
6368 status = cli_ntcreate(cli, streamname, 0x16,
6369 FILE_READ_DATA|FILE_READ_EA|
6370 FILE_READ_ATTRIBUTES|READ_CONTROL_ACCESS,
6371 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ,
6372 FILE_OPEN, 0, 0, &fnum);
6374 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
6375 printf("ntcreate returned %s, expected "
6376 "NT_STATUS_OBJECT_NAME_NOT_FOUND\n",
6382 cli_rmdir(cli, dname);
6386 static bool run_local_substitute(int dummy)
6390 ok &= subst_test("%U", "bla", "", -1, -1, "bla");
6391 ok &= subst_test("%u%U", "bla", "", -1, -1, "blabla");
6392 ok &= subst_test("%g", "", "", -1, -1, "NO_GROUP");
6393 ok &= subst_test("%G", "", "", -1, -1, "NO_GROUP");
6394 ok &= subst_test("%g", "", "", -1, 0, gidtoname(0));
6395 ok &= subst_test("%G", "", "", -1, 0, gidtoname(0));
6396 ok &= subst_test("%D%u", "u", "dom", -1, 0, "domu");
6397 ok &= subst_test("%i %I", "", "", -1, -1, "0.0.0.0 0.0.0.0");
6399 /* Different captialization rules in sub_basic... */
6401 ok &= (strcmp(talloc_sub_basic(talloc_tos(), "BLA", "dom", "%U%D"),
6407 static bool run_local_base64(int dummy)
6412 for (i=1; i<2000; i++) {
6413 DATA_BLOB blob1, blob2;
6416 blob1.data = talloc_array(talloc_tos(), uint8_t, i);
6418 generate_random_buffer(blob1.data, blob1.length);
6420 b64 = base64_encode_data_blob(talloc_tos(), blob1);
6422 d_fprintf(stderr, "base64_encode_data_blob failed "
6423 "for %d bytes\n", i);
6426 blob2 = base64_decode_data_blob(b64);
6429 if (data_blob_cmp(&blob1, &blob2)) {
6430 d_fprintf(stderr, "data_blob_cmp failed for %d "
6434 TALLOC_FREE(blob1.data);
6435 data_blob_free(&blob2);
6440 static bool run_local_gencache(int dummy)
6446 if (!gencache_set("foo", "bar", time(NULL) + 1000)) {
6447 d_printf("%s: gencache_set() failed\n", __location__);
6451 if (!gencache_get("foo", NULL, NULL)) {
6452 d_printf("%s: gencache_get() failed\n", __location__);
6456 if (!gencache_get("foo", &val, &tm)) {
6457 d_printf("%s: gencache_get() failed\n", __location__);
6461 if (strcmp(val, "bar") != 0) {
6462 d_printf("%s: gencache_get() returned %s, expected %s\n",
6463 __location__, val, "bar");
6470 if (!gencache_del("foo")) {
6471 d_printf("%s: gencache_del() failed\n", __location__);
6474 if (gencache_del("foo")) {
6475 d_printf("%s: second gencache_del() succeeded\n",
6480 if (gencache_get("foo", &val, &tm)) {
6481 d_printf("%s: gencache_get() on deleted entry "
6482 "succeeded\n", __location__);
6486 blob = data_blob_string_const_null("bar");
6487 tm = time(NULL) + 60;
6489 if (!gencache_set_data_blob("foo", &blob, tm)) {
6490 d_printf("%s: gencache_set_data_blob() failed\n", __location__);
6494 if (!gencache_get_data_blob("foo", &blob, NULL, NULL)) {
6495 d_printf("%s: gencache_get_data_blob() failed\n", __location__);
6499 if (strcmp((const char *)blob.data, "bar") != 0) {
6500 d_printf("%s: gencache_get_data_blob() returned %s, expected %s\n",
6501 __location__, (const char *)blob.data, "bar");
6502 data_blob_free(&blob);
6506 data_blob_free(&blob);
6508 if (!gencache_del("foo")) {
6509 d_printf("%s: gencache_del() failed\n", __location__);
6512 if (gencache_del("foo")) {
6513 d_printf("%s: second gencache_del() succeeded\n",
6518 if (gencache_get_data_blob("foo", &blob, NULL, NULL)) {
6519 d_printf("%s: gencache_get_data_blob() on deleted entry "
6520 "succeeded\n", __location__);
6527 static bool rbt_testval(struct db_context *db, const char *key,
6530 struct db_record *rec;
6531 TDB_DATA data = string_tdb_data(value);
6535 rec = db->fetch_locked(db, db, string_tdb_data(key));
6537 d_fprintf(stderr, "fetch_locked failed\n");
6540 status = rec->store(rec, data, 0);
6541 if (!NT_STATUS_IS_OK(status)) {
6542 d_fprintf(stderr, "store failed: %s\n", nt_errstr(status));
6547 rec = db->fetch_locked(db, db, string_tdb_data(key));
6549 d_fprintf(stderr, "second fetch_locked failed\n");
6552 if ((rec->value.dsize != data.dsize)
6553 || (memcmp(rec->value.dptr, data.dptr, data.dsize) != 0)) {
6554 d_fprintf(stderr, "Got wrong data back\n");
6564 static bool run_local_rbtree(int dummy)
6566 struct db_context *db;
6570 db = db_open_rbt(NULL);
6573 d_fprintf(stderr, "db_open_rbt failed\n");
6577 for (i=0; i<1000; i++) {
6580 if (asprintf(&key, "key%ld", random()) == -1) {
6583 if (asprintf(&value, "value%ld", random()) == -1) {
6588 if (!rbt_testval(db, key, value)) {
6595 if (asprintf(&value, "value%ld", random()) == -1) {
6600 if (!rbt_testval(db, key, value)) {
6617 struct talloc_dict_test {
6621 static int talloc_dict_traverse_fn(DATA_BLOB key, void *data, void *priv)
6623 int *count = (int *)priv;
6628 static bool run_local_talloc_dict(int dummy)
6630 struct talloc_dict *dict;
6631 struct talloc_dict_test *t;
6634 dict = talloc_dict_init(talloc_tos());
6639 t = talloc(talloc_tos(), struct talloc_dict_test);
6646 if (!talloc_dict_set(dict, data_blob_const(&key, sizeof(key)), t)) {
6651 if (talloc_dict_traverse(dict, talloc_dict_traverse_fn, &count) != 0) {
6664 /* Split a path name into filename and stream name components. Canonicalise
6665 * such that an implicit $DATA token is always explicit.
6667 * The "specification" of this function can be found in the
6668 * run_local_stream_name() function in torture.c, I've tried those
6669 * combinations against a W2k3 server.
6672 static NTSTATUS split_ntfs_stream_name(TALLOC_CTX *mem_ctx, const char *fname,
6673 char **pbase, char **pstream)
6676 char *stream = NULL;
6677 char *sname; /* stream name */
6678 const char *stype; /* stream type */
6680 DEBUG(10, ("split_ntfs_stream_name called for [%s]\n", fname));
6682 sname = strchr_m(fname, ':');
6684 if (lp_posix_pathnames() || (sname == NULL)) {
6685 if (pbase != NULL) {
6686 base = talloc_strdup(mem_ctx, fname);
6687 NT_STATUS_HAVE_NO_MEMORY(base);
6692 if (pbase != NULL) {
6693 base = talloc_strndup(mem_ctx, fname, PTR_DIFF(sname, fname));
6694 NT_STATUS_HAVE_NO_MEMORY(base);
6699 stype = strchr_m(sname, ':');
6701 if (stype == NULL) {
6702 sname = talloc_strdup(mem_ctx, sname);
6706 if (StrCaseCmp(stype, ":$DATA") != 0) {
6708 * If there is an explicit stream type, so far we only
6709 * allow $DATA. Is there anything else allowed? -- vl
6711 DEBUG(10, ("[%s] is an invalid stream type\n", stype));
6713 return NT_STATUS_OBJECT_NAME_INVALID;
6715 sname = talloc_strndup(mem_ctx, sname, PTR_DIFF(stype, sname));
6719 if (sname == NULL) {
6721 return NT_STATUS_NO_MEMORY;
6724 if (sname[0] == '\0') {
6726 * no stream name, so no stream
6731 if (pstream != NULL) {
6732 stream = talloc_asprintf(mem_ctx, "%s:%s", sname, stype);
6733 if (stream == NULL) {
6736 return NT_STATUS_NO_MEMORY;
6739 * upper-case the type field
6741 strupper_m(strchr_m(stream, ':')+1);
6745 if (pbase != NULL) {
6748 if (pstream != NULL) {
6751 return NT_STATUS_OK;
6754 static bool test_stream_name(const char *fname, const char *expected_base,
6755 const char *expected_stream,
6756 NTSTATUS expected_status)
6760 char *stream = NULL;
6762 status = split_ntfs_stream_name(talloc_tos(), fname, &base, &stream);
6763 if (!NT_STATUS_EQUAL(status, expected_status)) {
6767 if (!NT_STATUS_IS_OK(status)) {
6771 if (base == NULL) goto error;
6773 if (strcmp(expected_base, base) != 0) goto error;
6775 if ((expected_stream != NULL) && (stream == NULL)) goto error;
6776 if ((expected_stream == NULL) && (stream != NULL)) goto error;
6778 if ((stream != NULL) && (strcmp(expected_stream, stream) != 0))
6782 TALLOC_FREE(stream);
6786 d_fprintf(stderr, "test_stream(%s, %s, %s, %s)\n",
6787 fname, expected_base ? expected_base : "<NULL>",
6788 expected_stream ? expected_stream : "<NULL>",
6789 nt_errstr(expected_status));
6790 d_fprintf(stderr, "-> base=%s, stream=%s, status=%s\n",
6791 base ? base : "<NULL>", stream ? stream : "<NULL>",
6794 TALLOC_FREE(stream);
6798 static bool run_local_stream_name(int dummy)
6802 ret &= test_stream_name(
6803 "bla", "bla", NULL, NT_STATUS_OK);
6804 ret &= test_stream_name(
6805 "bla::$DATA", "bla", NULL, NT_STATUS_OK);
6806 ret &= test_stream_name(
6807 "bla:blub:", "bla", NULL, NT_STATUS_OBJECT_NAME_INVALID);
6808 ret &= test_stream_name(
6809 "bla::", NULL, NULL, NT_STATUS_OBJECT_NAME_INVALID);
6810 ret &= test_stream_name(
6811 "bla::123", "bla", NULL, NT_STATUS_OBJECT_NAME_INVALID);
6812 ret &= test_stream_name(
6813 "bla:$DATA", "bla", "$DATA:$DATA", NT_STATUS_OK);
6814 ret &= test_stream_name(
6815 "bla:x:$DATA", "bla", "x:$DATA", NT_STATUS_OK);
6816 ret &= test_stream_name(
6817 "bla:x", "bla", "x:$DATA", NT_STATUS_OK);
6822 static bool data_blob_equal(DATA_BLOB a, DATA_BLOB b)
6824 if (a.length != b.length) {
6825 printf("a.length=%d != b.length=%d\n",
6826 (int)a.length, (int)b.length);
6829 if (memcmp(a.data, b.data, a.length) != 0) {
6830 printf("a.data and b.data differ\n");
6836 static bool run_local_memcache(int dummy)
6838 struct memcache *cache;
6840 DATA_BLOB d1, d2, d3;
6841 DATA_BLOB v1, v2, v3;
6843 TALLOC_CTX *mem_ctx;
6845 size_t size1, size2;
6848 cache = memcache_init(NULL, 100);
6850 if (cache == NULL) {
6851 printf("memcache_init failed\n");
6855 d1 = data_blob_const("d1", 2);
6856 d2 = data_blob_const("d2", 2);
6857 d3 = data_blob_const("d3", 2);
6859 k1 = data_blob_const("d1", 2);
6860 k2 = data_blob_const("d2", 2);
6862 memcache_add(cache, STAT_CACHE, k1, d1);
6863 memcache_add(cache, GETWD_CACHE, k2, d2);
6865 if (!memcache_lookup(cache, STAT_CACHE, k1, &v1)) {
6866 printf("could not find k1\n");
6869 if (!data_blob_equal(d1, v1)) {
6873 if (!memcache_lookup(cache, GETWD_CACHE, k2, &v2)) {
6874 printf("could not find k2\n");
6877 if (!data_blob_equal(d2, v2)) {
6881 memcache_add(cache, STAT_CACHE, k1, d3);
6883 if (!memcache_lookup(cache, STAT_CACHE, k1, &v3)) {
6884 printf("could not find replaced k1\n");
6887 if (!data_blob_equal(d3, v3)) {
6891 memcache_add(cache, GETWD_CACHE, k1, d1);
6893 if (memcache_lookup(cache, GETWD_CACHE, k2, &v2)) {
6894 printf("Did find k2, should have been purged\n");
6900 cache = memcache_init(NULL, 0);
6902 mem_ctx = talloc_init("foo");
6904 str1 = talloc_strdup(mem_ctx, "string1");
6905 str2 = talloc_strdup(mem_ctx, "string2");
6907 memcache_add_talloc(cache, SINGLETON_CACHE_TALLOC,
6908 data_blob_string_const("torture"), &str1);
6909 size1 = talloc_total_size(cache);
6911 memcache_add_talloc(cache, SINGLETON_CACHE_TALLOC,
6912 data_blob_string_const("torture"), &str2);
6913 size2 = talloc_total_size(cache);
6915 printf("size1=%d, size2=%d\n", (int)size1, (int)size2);
6917 if (size2 > size1) {
6918 printf("memcache leaks memory!\n");
6928 static void wbclient_done(struct tevent_req *req)
6931 struct winbindd_response *wb_resp;
6932 int *i = (int *)tevent_req_callback_data_void(req);
6934 wbc_err = wb_trans_recv(req, req, &wb_resp);
6937 d_printf("wb_trans_recv %d returned %s\n", *i, wbcErrorString(wbc_err));
6940 static bool run_local_wbclient(int dummy)
6942 struct event_context *ev;
6943 struct wb_context **wb_ctx;
6944 struct winbindd_request wb_req;
6945 bool result = false;
6948 BlockSignals(True, SIGPIPE);
6950 ev = tevent_context_init_byname(talloc_tos(), "epoll");
6955 wb_ctx = TALLOC_ARRAY(ev, struct wb_context *, nprocs);
6956 if (wb_ctx == NULL) {
6960 ZERO_STRUCT(wb_req);
6961 wb_req.cmd = WINBINDD_PING;
6963 d_printf("nprocs=%d, numops=%d\n", (int)nprocs, (int)torture_numops);
6965 for (i=0; i<nprocs; i++) {
6966 wb_ctx[i] = wb_context_init(ev, NULL);
6967 if (wb_ctx[i] == NULL) {
6970 for (j=0; j<torture_numops; j++) {
6971 struct tevent_req *req;
6972 req = wb_trans_send(ev, ev, wb_ctx[i],
6973 (j % 2) == 0, &wb_req);
6977 tevent_req_set_callback(req, wbclient_done, &i);
6983 while (i < nprocs * torture_numops) {
6984 event_loop_once(ev);
6993 static void getaddrinfo_finished(struct tevent_req *req)
6995 char *name = (char *)tevent_req_callback_data_void(req);
6996 struct addrinfo *ainfo;
6999 res = getaddrinfo_recv(req, &ainfo);
7001 d_printf("gai(%s) returned %s\n", name, gai_strerror(res));
7004 d_printf("gai(%s) succeeded\n", name);
7005 freeaddrinfo(ainfo);
7008 static bool run_getaddrinfo_send(int dummy)
7010 TALLOC_CTX *frame = talloc_stackframe();
7011 struct fncall_context *ctx;
7012 struct tevent_context *ev;
7013 bool result = false;
7014 const char *names[4] = { "www.samba.org", "notfound.samba.org",
7015 "www.slashdot.org", "heise.de" };
7016 struct tevent_req *reqs[4];
7019 ev = event_context_init(frame);
7024 ctx = fncall_context_init(frame, 4);
7026 for (i=0; i<ARRAY_SIZE(names); i++) {
7027 reqs[i] = getaddrinfo_send(frame, ev, ctx, names[i], NULL,
7029 if (reqs[i] == NULL) {
7032 tevent_req_set_callback(reqs[i], getaddrinfo_finished,
7036 for (i=0; i<ARRAY_SIZE(reqs); i++) {
7037 tevent_loop_once(ev);
7047 static double create_procs(bool (*fn)(int), bool *result)
7050 volatile pid_t *child_status;
7051 volatile bool *child_status_out;
7057 child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*nprocs);
7058 if (!child_status) {
7059 printf("Failed to setup shared memory\n");
7063 child_status_out = (volatile bool *)shm_setup(sizeof(bool)*nprocs);
7064 if (!child_status_out) {
7065 printf("Failed to setup result status shared memory\n");
7069 for (i = 0; i < nprocs; i++) {
7070 child_status[i] = 0;
7071 child_status_out[i] = True;
7076 for (i=0;i<nprocs;i++) {
7079 pid_t mypid = getpid();
7080 sys_srandom(((int)mypid) ^ ((int)time(NULL)));
7082 slprintf(myname,sizeof(myname),"CLIENT%d", i);
7085 if (torture_open_connection(¤t_cli, i)) break;
7087 printf("pid %d failed to start\n", (int)getpid());
7093 child_status[i] = getpid();
7095 while (child_status[i] && end_timer() < 5) smb_msleep(2);
7097 child_status_out[i] = fn(i);
7104 for (i=0;i<nprocs;i++) {
7105 if (child_status[i]) synccount++;
7107 if (synccount == nprocs) break;
7109 } while (end_timer() < 30);
7111 if (synccount != nprocs) {
7112 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs, synccount);
7117 /* start the client load */
7120 for (i=0;i<nprocs;i++) {
7121 child_status[i] = 0;
7124 printf("%d clients started\n", nprocs);
7126 for (i=0;i<nprocs;i++) {
7127 while (waitpid(0, &status, 0) == -1 && errno == EINTR) /* noop */ ;
7132 for (i=0;i<nprocs;i++) {
7133 if (!child_status_out[i]) {
7140 #define FLAG_MULTIPROC 1
7147 {"FDPASS", run_fdpasstest, 0},
7148 {"LOCK1", run_locktest1, 0},
7149 {"LOCK2", run_locktest2, 0},
7150 {"LOCK3", run_locktest3, 0},
7151 {"LOCK4", run_locktest4, 0},
7152 {"LOCK5", run_locktest5, 0},
7153 {"LOCK6", run_locktest6, 0},
7154 {"LOCK7", run_locktest7, 0},
7155 {"LOCK8", run_locktest8, 0},
7156 {"LOCK9", run_locktest9, 0},
7157 {"UNLINK", run_unlinktest, 0},
7158 {"BROWSE", run_browsetest, 0},
7159 {"ATTR", run_attrtest, 0},
7160 {"TRANS2", run_trans2test, 0},
7161 {"MAXFID", run_maxfidtest, FLAG_MULTIPROC},
7162 {"TORTURE",run_torture, FLAG_MULTIPROC},
7163 {"RANDOMIPC", run_randomipc, 0},
7164 {"NEGNOWAIT", run_negprot_nowait, 0},
7165 {"NBENCH", run_nbench, 0},
7166 {"OPLOCK1", run_oplock1, 0},
7167 {"OPLOCK2", run_oplock2, 0},
7168 {"OPLOCK3", run_oplock3, 0},
7169 {"DIR", run_dirtest, 0},
7170 {"DIR1", run_dirtest1, 0},
7171 {"DENY1", torture_denytest1, 0},
7172 {"DENY2", torture_denytest2, 0},
7173 {"TCON", run_tcon_test, 0},
7174 {"TCONDEV", run_tcon_devtype_test, 0},
7175 {"RW1", run_readwritetest, 0},
7176 {"RW2", run_readwritemulti, FLAG_MULTIPROC},
7177 {"RW3", run_readwritelarge, 0},
7178 {"OPEN", run_opentest, 0},
7179 {"POSIX", run_simple_posix_open_test, 0},
7180 { "UID-REGRESSION-TEST", run_uid_regression_test, 0},
7181 { "SHORTNAME-TEST", run_shortname_test, 0},
7183 {"OPENATTR", run_openattrtest, 0},
7185 {"XCOPY", run_xcopy, 0},
7186 {"RENAME", run_rename, 0},
7187 {"DELETE", run_deletetest, 0},
7188 {"PROPERTIES", run_properties, 0},
7189 {"MANGLE", torture_mangle, 0},
7190 {"MANGLE1", run_mangle1, 0},
7191 {"W2K", run_w2ktest, 0},
7192 {"TRANS2SCAN", torture_trans2_scan, 0},
7193 {"NTTRANSSCAN", torture_nttrans_scan, 0},
7194 {"UTABLE", torture_utable, 0},
7195 {"CASETABLE", torture_casetable, 0},
7196 {"ERRMAPEXTRACT", run_error_map_extract, 0},
7197 {"PIPE_NUMBER", run_pipe_number, 0},
7198 {"TCON2", run_tcon2_test, 0},
7199 {"IOCTL", torture_ioctl_test, 0},
7200 {"CHKPATH", torture_chkpath_test, 0},
7201 {"FDSESS", run_fdsesstest, 0},
7202 { "EATEST", run_eatest, 0},
7203 { "SESSSETUP_BENCH", run_sesssetup_bench, 0},
7204 { "CHAIN1", run_chain1, 0},
7205 { "CHAIN2", run_chain2, 0},
7206 { "WINDOWS-WRITE", run_windows_write, 0},
7207 { "CLI_ECHO", run_cli_echo, 0},
7208 { "GETADDRINFO", run_getaddrinfo_send, 0},
7209 { "TLDAP", run_tldap },
7210 { "STREAMERROR", run_streamerror },
7211 { "NOTIFY-BENCH", run_notify_bench },
7212 { "LOCAL-SUBSTITUTE", run_local_substitute, 0},
7213 { "LOCAL-GENCACHE", run_local_gencache, 0},
7214 { "LOCAL-TALLOC-DICT", run_local_talloc_dict, 0},
7215 { "LOCAL-BASE64", run_local_base64, 0},
7216 { "LOCAL-RBTREE", run_local_rbtree, 0},
7217 { "LOCAL-MEMCACHE", run_local_memcache, 0},
7218 { "LOCAL-STREAM-NAME", run_local_stream_name, 0},
7219 { "LOCAL-WBCLIENT", run_local_wbclient, 0},
7224 /****************************************************************************
7225 run a specified test or "ALL"
7226 ****************************************************************************/
7227 static bool run_test(const char *name)
7234 if (strequal(name,"ALL")) {
7235 for (i=0;torture_ops[i].name;i++) {
7236 run_test(torture_ops[i].name);
7241 for (i=0;torture_ops[i].name;i++) {
7242 fstr_sprintf(randomfname, "\\XX%x",
7243 (unsigned)random());
7245 if (strequal(name, torture_ops[i].name)) {
7247 printf("Running %s\n", name);
7248 if (torture_ops[i].flags & FLAG_MULTIPROC) {
7249 t = create_procs(torture_ops[i].fn, &result);
7252 printf("TEST %s FAILED!\n", name);
7256 if (!torture_ops[i].fn(0)) {
7258 printf("TEST %s FAILED!\n", name);
7262 printf("%s took %g secs\n\n", name, t);
7267 printf("Did not find a test named %s\n", name);
7275 static void usage(void)
7279 printf("WARNING samba4 test suite is much more complete nowadays.\n");
7280 printf("Please use samba4 torture.\n\n");
7282 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
7284 printf("\t-d debuglevel\n");
7285 printf("\t-U user%%pass\n");
7286 printf("\t-k use kerberos\n");
7287 printf("\t-N numprocs\n");
7288 printf("\t-n my_netbios_name\n");
7289 printf("\t-W workgroup\n");
7290 printf("\t-o num_operations\n");
7291 printf("\t-O socket_options\n");
7292 printf("\t-m maximum protocol\n");
7293 printf("\t-L use oplocks\n");
7294 printf("\t-c CLIENT.TXT specify client load file for NBENCH\n");
7295 printf("\t-A showall\n");
7296 printf("\t-p port\n");
7297 printf("\t-s seed\n");
7298 printf("\t-b unclist_filename specify multiple shares for multiple connections\n");
7301 printf("tests are:");
7302 for (i=0;torture_ops[i].name;i++) {
7303 printf(" %s", torture_ops[i].name);
7307 printf("default test is ALL\n");
7312 /****************************************************************************
7314 ****************************************************************************/
7315 int main(int argc,char *argv[])
7321 bool correct = True;
7322 TALLOC_CTX *frame = talloc_stackframe();
7323 int seed = time(NULL);
7327 #ifdef HAVE_SETBUFFER
7328 setbuffer(stdout, NULL, 0);
7333 if (is_default_dyn_CONFIGFILE()) {
7334 if(getenv("SMB_CONF_PATH")) {
7335 set_dyn_CONFIGFILE(getenv("SMB_CONF_PATH"));
7338 lp_load(get_dyn_CONFIGFILE(),True,False,False,True);
7345 for(p = argv[1]; *p; p++)
7349 if (strncmp(argv[1], "//", 2)) {
7353 fstrcpy(host, &argv[1][2]);
7354 p = strchr_m(&host[2],'/');
7359 fstrcpy(share, p+1);
7361 fstrcpy(myname, get_myname(talloc_tos()));
7363 fprintf(stderr, "Failed to get my hostname.\n");
7367 if (*username == 0 && getenv("LOGNAME")) {
7368 fstrcpy(username,getenv("LOGNAME"));
7374 fstrcpy(workgroup, lp_workgroup());
7376 while ((opt = getopt(argc, argv, "p:hW:U:n:N:O:o:m:Ll:d:Aec:ks:b:B:")) != EOF) {
7379 port_to_use = atoi(optarg);
7382 seed = atoi(optarg);
7385 fstrcpy(workgroup,optarg);
7388 max_protocol = interpret_protocol(optarg, max_protocol);
7391 nprocs = atoi(optarg);
7394 torture_numops = atoi(optarg);
7397 DEBUGLEVEL = atoi(optarg);
7406 local_path = optarg;
7409 torture_showall = True;
7412 fstrcpy(myname, optarg);
7415 client_txt = optarg;
7422 use_kerberos = True;
7424 d_printf("No kerberos support compiled in\n");
7430 fstrcpy(username,optarg);
7431 p = strchr_m(username,'%');
7434 fstrcpy(password, p+1);
7439 fstrcpy(multishare_conn_fname, optarg);
7440 use_multishare_conn = True;
7443 torture_blocksize = atoi(optarg);
7446 printf("Unknown option %c (%d)\n", (char)opt, opt);
7451 d_printf("using seed %d\n", seed);
7455 if(use_kerberos && !gotuser) gotpass = True;
7458 p = getpass("Password:");
7460 fstrcpy(password, p);
7465 printf("host=%s share=%s user=%s myname=%s\n",
7466 host, share, username, myname);
7468 if (argc == optind) {
7469 correct = run_test("ALL");
7471 for (i=optind;i<argc;i++) {
7472 if (!run_test(argv[i])) {