2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 2003
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "torture/torture.h"
22 #include "libcli/raw/libcliraw.h"
23 #include "libcli/libcli.h"
24 #include "torture/util.h"
26 #define CHECK_STATUS(status, correct) do { \
27 if (!NT_STATUS_EQUAL(status, correct)) { \
28 printf("(%s) Incorrect status %s - should be %s\n", \
29 __location__, nt_errstr(status), nt_errstr(correct)); \
34 #define CHECK_VALUE(v, correct) do { \
35 if ((v) != (correct)) { \
36 printf("(%s) Incorrect %s %d - should be %d\n", \
37 __location__, #v, (int)v, (int)correct); \
41 #define BASEDIR "\\testrename"
46 static bool test_mv(struct torture_context
*tctx
,
47 struct smbcli_state
*cli
)
53 const char *fname1
= BASEDIR
"\\test1.txt";
54 const char *fname2
= BASEDIR
"\\test2.txt";
55 const char *Fname1
= BASEDIR
"\\Test1.txt";
56 union smb_fileinfo finfo
;
59 printf("Testing SMBmv\n");
61 if (!torture_setup_dir(cli
, BASEDIR
)) {
65 printf("Trying simple rename\n");
67 op
.generic
.level
= RAW_OPEN_NTCREATEX
;
68 op
.ntcreatex
.in
.root_fid
= 0;
69 op
.ntcreatex
.in
.flags
= 0;
70 op
.ntcreatex
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
71 op
.ntcreatex
.in
.create_options
= 0;
72 op
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
73 op
.ntcreatex
.in
.share_access
=
74 NTCREATEX_SHARE_ACCESS_READ
|
75 NTCREATEX_SHARE_ACCESS_WRITE
;
76 op
.ntcreatex
.in
.alloc_size
= 0;
77 op
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN_IF
;
78 op
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
79 op
.ntcreatex
.in
.security_flags
= 0;
80 op
.ntcreatex
.in
.fname
= fname1
;
82 status
= smb_raw_open(cli
->tree
, tctx
, &op
);
83 CHECK_STATUS(status
, NT_STATUS_OK
);
84 fnum
= op
.ntcreatex
.out
.file
.fnum
;
86 io
.generic
.level
= RAW_RENAME_RENAME
;
87 io
.rename
.in
.pattern1
= fname1
;
88 io
.rename
.in
.pattern2
= fname2
;
89 io
.rename
.in
.attrib
= 0;
91 printf("trying rename while first file open\n");
92 status
= smb_raw_rename(cli
->tree
, &io
);
93 CHECK_STATUS(status
, NT_STATUS_SHARING_VIOLATION
);
95 smbcli_close(cli
->tree
, fnum
);
97 op
.ntcreatex
.in
.access_mask
= SEC_FILE_READ_DATA
;
98 op
.ntcreatex
.in
.share_access
=
99 NTCREATEX_SHARE_ACCESS_DELETE
|
100 NTCREATEX_SHARE_ACCESS_READ
|
101 NTCREATEX_SHARE_ACCESS_WRITE
;
102 status
= smb_raw_open(cli
->tree
, tctx
, &op
);
103 CHECK_STATUS(status
, NT_STATUS_OK
);
104 fnum
= op
.ntcreatex
.out
.file
.fnum
;
106 printf("trying rename while first file open with SHARE_ACCESS_DELETE\n");
107 status
= smb_raw_rename(cli
->tree
, &io
);
108 CHECK_STATUS(status
, NT_STATUS_OK
);
110 io
.rename
.in
.pattern1
= fname2
;
111 io
.rename
.in
.pattern2
= fname1
;
112 status
= smb_raw_rename(cli
->tree
, &io
);
113 CHECK_STATUS(status
, NT_STATUS_OK
);
115 printf("Trying case-changing rename\n");
116 io
.rename
.in
.pattern1
= fname1
;
117 io
.rename
.in
.pattern2
= Fname1
;
118 status
= smb_raw_rename(cli
->tree
, &io
);
119 CHECK_STATUS(status
, NT_STATUS_OK
);
121 finfo
.generic
.level
= RAW_FILEINFO_ALL_INFO
;
122 finfo
.all_info
.in
.file
.path
= fname1
;
123 status
= smb_raw_pathinfo(cli
->tree
, tctx
, &finfo
);
124 CHECK_STATUS(status
, NT_STATUS_OK
);
125 if (strcmp(finfo
.all_info
.out
.fname
.s
, Fname1
) != 0) {
126 printf("(%s) Incorrect filename [%s] after case-changing "
127 "rename, should be [%s]\n", __location__
,
128 finfo
.all_info
.out
.fname
.s
, Fname1
);
131 io
.rename
.in
.pattern1
= fname1
;
132 io
.rename
.in
.pattern2
= fname2
;
134 printf("trying rename while not open\n");
135 smb_raw_exit(cli
->session
);
136 status
= smb_raw_rename(cli
->tree
, &io
);
137 CHECK_STATUS(status
, NT_STATUS_OK
);
139 printf("Trying self rename\n");
140 io
.rename
.in
.pattern1
= fname2
;
141 io
.rename
.in
.pattern2
= fname2
;
142 status
= smb_raw_rename(cli
->tree
, &io
);
143 CHECK_STATUS(status
, NT_STATUS_OK
);
145 io
.rename
.in
.pattern1
= fname1
;
146 io
.rename
.in
.pattern2
= fname1
;
147 status
= smb_raw_rename(cli
->tree
, &io
);
148 CHECK_STATUS(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
);
151 printf("trying wildcard rename\n");
152 io
.rename
.in
.pattern1
= BASEDIR
"\\*.txt";
153 io
.rename
.in
.pattern2
= fname1
;
155 status
= smb_raw_rename(cli
->tree
, &io
);
156 CHECK_STATUS(status
, NT_STATUS_OK
);
158 printf("and again\n");
159 status
= smb_raw_rename(cli
->tree
, &io
);
160 CHECK_STATUS(status
, NT_STATUS_OK
);
162 printf("Trying extension change\n");
163 io
.rename
.in
.pattern1
= BASEDIR
"\\*.txt";
164 io
.rename
.in
.pattern2
= BASEDIR
"\\*.bak";
165 status
= smb_raw_rename(cli
->tree
, &io
);
166 CHECK_STATUS(status
, NT_STATUS_OK
);
168 status
= smb_raw_rename(cli
->tree
, &io
);
169 CHECK_STATUS(status
, NT_STATUS_NO_SUCH_FILE
);
171 printf("Checking attrib handling\n");
172 torture_set_file_attribute(cli
->tree
, BASEDIR
"\\test1.bak", FILE_ATTRIBUTE_HIDDEN
);
173 io
.rename
.in
.pattern1
= BASEDIR
"\\test1.bak";
174 io
.rename
.in
.pattern2
= BASEDIR
"\\*.txt";
175 io
.rename
.in
.attrib
= 0;
176 status
= smb_raw_rename(cli
->tree
, &io
);
177 CHECK_STATUS(status
, NT_STATUS_NO_SUCH_FILE
);
179 io
.rename
.in
.attrib
= FILE_ATTRIBUTE_HIDDEN
;
180 status
= smb_raw_rename(cli
->tree
, &io
);
181 CHECK_STATUS(status
, NT_STATUS_OK
);
184 smbcli_close(cli
->tree
, fnum
);
185 smb_raw_exit(cli
->session
);
186 smbcli_deltree(cli
->tree
, BASEDIR
);
191 static bool test_osxrename(struct torture_context
*tctx
,
192 struct smbcli_state
*cli
)
195 union smb_unlink io_un
;
199 const char *fname1
= BASEDIR
"\\test1";
200 const char *FNAME1
= BASEDIR
"\\TEST1";
201 union smb_fileinfo finfo
;
204 printf("\nTesting OSX Rename\n");
205 if (!torture_setup_dir(cli
, BASEDIR
)) {
208 op
.generic
.level
= RAW_OPEN_NTCREATEX
;
209 op
.ntcreatex
.in
.root_fid
= 0;
210 op
.ntcreatex
.in
.flags
= 0;
211 op
.ntcreatex
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
212 op
.ntcreatex
.in
.create_options
= 0;
213 op
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
214 op
.ntcreatex
.in
.share_access
=
215 NTCREATEX_SHARE_ACCESS_READ
|
216 NTCREATEX_SHARE_ACCESS_WRITE
;
217 op
.ntcreatex
.in
.alloc_size
= 0;
218 op
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN_IF
;
219 op
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
220 op
.ntcreatex
.in
.security_flags
= 0;
221 op
.ntcreatex
.in
.fname
= fname1
;
223 status
= smb_raw_open(cli
->tree
, tctx
, &op
);
224 CHECK_STATUS(status
, NT_STATUS_OK
);
225 fnum
= op
.ntcreatex
.out
.file
.fnum
;
227 io
.generic
.level
= RAW_RENAME_RENAME
;
228 io
.rename
.in
.attrib
= 0;
230 smbcli_close(cli
->tree
, fnum
);
232 /* Rename by changing case. First check for the
233 * existence of the file with the "newname".
234 * If we find one and both the output and input are same case,
237 printf("Checking os X rename (case changing)\n");
239 finfo
.generic
.level
= RAW_FILEINFO_ALL_INFO
;
240 finfo
.all_info
.in
.file
.path
= FNAME1
;
241 printf("Looking for file %s \n",FNAME1
);
242 status
= smb_raw_pathinfo(cli
->tree
, tctx
, &finfo
);
244 if (NT_STATUS_EQUAL(status
, NT_STATUS_OK
)) {
245 printf("Name of the file found %s \n", finfo
.all_info
.out
.fname
.s
);
246 if (strcmp(finfo
.all_info
.out
.fname
.s
, finfo
.all_info
.in
.file
.path
) == 0) {
247 /* If file is found with the same case delete it */
248 printf("Deleting File %s \n", finfo
.all_info
.out
.fname
.s
);
249 io_un
.unlink
.in
.pattern
= finfo
.all_info
.out
.fname
.s
;
250 io_un
.unlink
.in
.attrib
= 0;
251 status
= smb_raw_unlink(cli
->tree
, &io_un
);
252 CHECK_STATUS(status
, NT_STATUS_OK
);
256 io
.rename
.in
.pattern1
= fname1
;
257 io
.rename
.in
.pattern2
= FNAME1
;
258 status
= smb_raw_rename(cli
->tree
, &io
);
259 CHECK_STATUS(status
, NT_STATUS_OK
);
261 finfo
.generic
.level
= RAW_FILEINFO_ALL_INFO
;
262 finfo
.all_info
.in
.file
.path
= fname1
;
263 status
= smb_raw_pathinfo(cli
->tree
, tctx
, &finfo
);
264 CHECK_STATUS(status
, NT_STATUS_OK
);
265 printf("File name after rename %s \n",finfo
.all_info
.out
.fname
.s
);
268 smbcli_close(cli
->tree
, fnum
);
269 smb_raw_exit(cli
->session
);
270 smbcli_deltree(cli
->tree
, BASEDIR
);
277 static bool test_ntrename(struct torture_context
*tctx
,
278 struct smbcli_state
*cli
)
284 const char *fname1
= BASEDIR
"\\test1.txt";
285 const char *fname2
= BASEDIR
"\\test2.txt";
286 union smb_fileinfo finfo
;
288 printf("Testing SMBntrename\n");
290 if (!torture_setup_dir(cli
, BASEDIR
)) {
294 printf("Trying simple rename\n");
296 fnum
= create_complex_file(cli
, tctx
, fname1
);
298 io
.generic
.level
= RAW_RENAME_NTRENAME
;
299 io
.ntrename
.in
.old_name
= fname1
;
300 io
.ntrename
.in
.new_name
= fname2
;
301 io
.ntrename
.in
.attrib
= 0;
302 io
.ntrename
.in
.cluster_size
= 0;
303 io
.ntrename
.in
.flags
= RENAME_FLAG_RENAME
;
305 status
= smb_raw_rename(cli
->tree
, &io
);
306 CHECK_STATUS(status
, NT_STATUS_SHARING_VIOLATION
);
308 smb_raw_exit(cli
->session
);
309 status
= smb_raw_rename(cli
->tree
, &io
);
310 CHECK_STATUS(status
, NT_STATUS_OK
);
312 printf("Trying self rename\n");
313 io
.ntrename
.in
.old_name
= fname2
;
314 io
.ntrename
.in
.new_name
= fname2
;
315 status
= smb_raw_rename(cli
->tree
, &io
);
316 CHECK_STATUS(status
, NT_STATUS_OK
);
318 io
.ntrename
.in
.old_name
= fname1
;
319 io
.ntrename
.in
.new_name
= fname1
;
320 status
= smb_raw_rename(cli
->tree
, &io
);
321 CHECK_STATUS(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
);
323 printf("trying wildcard rename\n");
324 io
.ntrename
.in
.old_name
= BASEDIR
"\\*.txt";
325 io
.ntrename
.in
.new_name
= fname1
;
327 status
= smb_raw_rename(cli
->tree
, &io
);
328 CHECK_STATUS(status
, NT_STATUS_OBJECT_PATH_SYNTAX_BAD
);
330 printf("Checking attrib handling\n");
331 torture_set_file_attribute(cli
->tree
, fname2
, FILE_ATTRIBUTE_HIDDEN
);
332 io
.ntrename
.in
.old_name
= fname2
;
333 io
.ntrename
.in
.new_name
= fname1
;
334 io
.ntrename
.in
.attrib
= 0;
335 status
= smb_raw_rename(cli
->tree
, &io
);
336 CHECK_STATUS(status
, NT_STATUS_NO_SUCH_FILE
);
338 io
.ntrename
.in
.attrib
= FILE_ATTRIBUTE_HIDDEN
;
339 status
= smb_raw_rename(cli
->tree
, &io
);
340 CHECK_STATUS(status
, NT_STATUS_OK
);
342 torture_set_file_attribute(cli
->tree
, fname1
, FILE_ATTRIBUTE_NORMAL
);
344 printf("Checking hard link\n");
345 io
.ntrename
.in
.old_name
= fname1
;
346 io
.ntrename
.in
.new_name
= fname2
;
347 io
.ntrename
.in
.attrib
= 0;
348 io
.ntrename
.in
.flags
= RENAME_FLAG_HARD_LINK
;
349 status
= smb_raw_rename(cli
->tree
, &io
);
350 CHECK_STATUS(status
, NT_STATUS_OK
);
352 torture_set_file_attribute(cli
->tree
, fname1
, FILE_ATTRIBUTE_SYSTEM
);
354 finfo
.generic
.level
= RAW_FILEINFO_ALL_INFO
;
355 finfo
.generic
.in
.file
.path
= fname2
;
356 status
= smb_raw_pathinfo(cli
->tree
, tctx
, &finfo
);
357 CHECK_STATUS(status
, NT_STATUS_OK
);
358 CHECK_VALUE(finfo
.all_info
.out
.nlink
, 2);
359 CHECK_VALUE(finfo
.all_info
.out
.attrib
, FILE_ATTRIBUTE_SYSTEM
);
361 finfo
.generic
.in
.file
.path
= fname1
;
362 status
= smb_raw_pathinfo(cli
->tree
, tctx
, &finfo
);
363 CHECK_STATUS(status
, NT_STATUS_OK
);
364 CHECK_VALUE(finfo
.all_info
.out
.nlink
, 2);
365 CHECK_VALUE(finfo
.all_info
.out
.attrib
, FILE_ATTRIBUTE_SYSTEM
);
367 torture_set_file_attribute(cli
->tree
, fname1
, FILE_ATTRIBUTE_NORMAL
);
369 smbcli_unlink(cli
->tree
, fname2
);
371 finfo
.generic
.in
.file
.path
= fname1
;
372 status
= smb_raw_pathinfo(cli
->tree
, tctx
, &finfo
);
373 CHECK_STATUS(status
, NT_STATUS_OK
);
374 CHECK_VALUE(finfo
.all_info
.out
.nlink
, 1);
375 CHECK_VALUE(finfo
.all_info
.out
.attrib
, FILE_ATTRIBUTE_NORMAL
);
377 printf("Checking copy\n");
378 io
.ntrename
.in
.old_name
= fname1
;
379 io
.ntrename
.in
.new_name
= fname2
;
380 io
.ntrename
.in
.attrib
= 0;
381 io
.ntrename
.in
.flags
= RENAME_FLAG_COPY
;
382 status
= smb_raw_rename(cli
->tree
, &io
);
383 CHECK_STATUS(status
, NT_STATUS_OK
);
385 finfo
.generic
.level
= RAW_FILEINFO_ALL_INFO
;
386 finfo
.generic
.in
.file
.path
= fname1
;
387 status
= smb_raw_pathinfo(cli
->tree
, tctx
, &finfo
);
388 CHECK_STATUS(status
, NT_STATUS_OK
);
389 CHECK_VALUE(finfo
.all_info
.out
.nlink
, 1);
390 CHECK_VALUE(finfo
.all_info
.out
.attrib
, FILE_ATTRIBUTE_NORMAL
);
392 finfo
.generic
.level
= RAW_FILEINFO_ALL_INFO
;
393 finfo
.generic
.in
.file
.path
= fname2
;
394 status
= smb_raw_pathinfo(cli
->tree
, tctx
, &finfo
);
395 CHECK_STATUS(status
, NT_STATUS_OK
);
396 CHECK_VALUE(finfo
.all_info
.out
.nlink
, 1);
397 CHECK_VALUE(finfo
.all_info
.out
.attrib
, FILE_ATTRIBUTE_NORMAL
);
399 torture_set_file_attribute(cli
->tree
, fname1
, FILE_ATTRIBUTE_SYSTEM
);
401 finfo
.generic
.level
= RAW_FILEINFO_ALL_INFO
;
402 finfo
.generic
.in
.file
.path
= fname2
;
403 status
= smb_raw_pathinfo(cli
->tree
, tctx
, &finfo
);
404 CHECK_STATUS(status
, NT_STATUS_OK
);
405 CHECK_VALUE(finfo
.all_info
.out
.nlink
, 1);
406 CHECK_VALUE(finfo
.all_info
.out
.attrib
, FILE_ATTRIBUTE_NORMAL
);
408 finfo
.generic
.in
.file
.path
= fname1
;
409 status
= smb_raw_pathinfo(cli
->tree
, tctx
, &finfo
);
410 CHECK_STATUS(status
, NT_STATUS_OK
);
411 CHECK_VALUE(finfo
.all_info
.out
.nlink
, 1);
412 CHECK_VALUE(finfo
.all_info
.out
.attrib
, FILE_ATTRIBUTE_SYSTEM
);
414 torture_set_file_attribute(cli
->tree
, fname1
, FILE_ATTRIBUTE_NORMAL
);
416 smbcli_unlink(cli
->tree
, fname2
);
418 finfo
.generic
.in
.file
.path
= fname1
;
419 status
= smb_raw_pathinfo(cli
->tree
, tctx
, &finfo
);
420 CHECK_STATUS(status
, NT_STATUS_OK
);
421 CHECK_VALUE(finfo
.all_info
.out
.nlink
, 1);
423 printf("Checking invalid flags\n");
424 io
.ntrename
.in
.old_name
= fname1
;
425 io
.ntrename
.in
.new_name
= fname2
;
426 io
.ntrename
.in
.attrib
= 0;
427 io
.ntrename
.in
.flags
= 0;
428 status
= smb_raw_rename(cli
->tree
, &io
);
429 CHECK_STATUS(status
, NT_STATUS_ACCESS_DENIED
);
431 io
.ntrename
.in
.flags
= 300;
432 status
= smb_raw_rename(cli
->tree
, &io
);
433 CHECK_STATUS(status
, NT_STATUS_ACCESS_DENIED
);
435 io
.ntrename
.in
.flags
= 0x106;
436 status
= smb_raw_rename(cli
->tree
, &io
);
437 CHECK_STATUS(status
, NT_STATUS_ACCESS_DENIED
);
439 printf("Checking unknown field\n");
440 io
.ntrename
.in
.old_name
= fname1
;
441 io
.ntrename
.in
.new_name
= fname2
;
442 io
.ntrename
.in
.attrib
= 0;
443 io
.ntrename
.in
.flags
= RENAME_FLAG_RENAME
;
444 io
.ntrename
.in
.cluster_size
= 0xff;
445 status
= smb_raw_rename(cli
->tree
, &io
);
446 CHECK_STATUS(status
, NT_STATUS_OK
);
448 printf("Trying RENAME_FLAG_MOVE_CLUSTER_INFORMATION\n");
450 io
.ntrename
.in
.old_name
= fname2
;
451 io
.ntrename
.in
.new_name
= fname1
;
452 io
.ntrename
.in
.attrib
= 0;
453 io
.ntrename
.in
.flags
= RENAME_FLAG_MOVE_CLUSTER_INFORMATION
;
454 io
.ntrename
.in
.cluster_size
= 1;
455 status
= smb_raw_rename(cli
->tree
, &io
);
456 CHECK_STATUS(status
, NT_STATUS_INVALID_PARAMETER
);
458 io
.ntrename
.in
.flags
= RENAME_FLAG_COPY
;
459 status
= smb_raw_rename(cli
->tree
, &io
);
460 CHECK_STATUS(status
, NT_STATUS_OK
);
465 fnum
= smbcli_open(cli
->tree
, fname1
, O_RDWR
, DENY_NONE
);
466 memset(buf
, 1, sizeof(buf
));
467 smbcli_write(cli
->tree
, fnum
, 0, buf
, 0, sizeof(buf
));
468 smbcli_close(cli
->tree
, fnum
);
470 fnum
= smbcli_open(cli
->tree
, fname2
, O_RDWR
, DENY_NONE
);
471 memset(buf
, 1, sizeof(buf
));
472 smbcli_write(cli
->tree
, fnum
, 0, buf
, 0, sizeof(buf
)-1);
473 smbcli_close(cli
->tree
, fnum
);
475 torture_all_info(cli
->tree
, fname1
);
476 torture_all_info(cli
->tree
, fname2
);
480 io
.ntrename
.in
.flags
= RENAME_FLAG_MOVE_CLUSTER_INFORMATION
;
481 status
= smb_raw_rename(cli
->tree
, &io
);
482 CHECK_STATUS(status
, NT_STATUS_INVALID_PARAMETER
);
484 for (i
=0;i
<20000;i
++) {
485 io
.ntrename
.in
.cluster_size
= i
;
486 status
= smb_raw_rename(cli
->tree
, &io
);
487 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_PARAMETER
)) {
488 printf("i=%d status=%s\n", i
, nt_errstr(status
));
493 printf("Checking other flags\n");
495 for (i
=0;i
<0xFFF;i
++) {
496 if (i
== RENAME_FLAG_RENAME
||
497 i
== RENAME_FLAG_HARD_LINK
||
498 i
== RENAME_FLAG_COPY
) {
502 io
.ntrename
.in
.old_name
= fname2
;
503 io
.ntrename
.in
.new_name
= fname1
;
504 io
.ntrename
.in
.flags
= i
;
505 io
.ntrename
.in
.attrib
= 0;
506 io
.ntrename
.in
.cluster_size
= 0;
507 status
= smb_raw_rename(cli
->tree
, &io
);
508 if (!NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
)) {
509 printf("flags=0x%x status=%s\n", i
, nt_errstr(status
));
514 smb_raw_exit(cli
->session
);
515 smbcli_deltree(cli
->tree
, BASEDIR
);
522 static bool test_dir_rename(struct torture_context
*tctx
, struct smbcli_state
*cli
)
525 union smb_rename ren_io
;
527 const char *dname1
= BASEDIR
"\\dir_for_rename";
528 const char *dname2
= BASEDIR
"\\renamed_dir";
529 const char *fname
= BASEDIR
"\\dir_for_rename\\file.txt";
533 printf("Checking rename on a directory containing an open file.\n");
535 if (!torture_setup_dir(cli
, BASEDIR
)) {
539 /* create a directory */
540 smbcli_rmdir(cli
->tree
, dname1
);
541 smbcli_rmdir(cli
->tree
, dname2
);
542 smbcli_unlink(cli
->tree
, dname1
);
543 smbcli_unlink(cli
->tree
, dname2
);
546 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
547 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_CREATE
;
548 io
.ntcreatex
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
549 io
.ntcreatex
.in
.alloc_size
= 0;
550 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
551 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
| NTCREATEX_SHARE_ACCESS_WRITE
;
552 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_CREATE
;
553 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
554 io
.ntcreatex
.in
.fname
= dname1
;
555 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
556 CHECK_STATUS(status
, NT_STATUS_OK
);
558 fnum
= io
.ntcreatex
.out
.file
.fnum
;
559 smbcli_close(cli
->tree
, fnum
);
561 /* Now create and hold open a file. */
564 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
565 io
.ntcreatex
.in
.flags
= NTCREATEX_FLAGS_EXTENDED
;
566 io
.ntcreatex
.in
.root_fid
= 0;
567 io
.ntcreatex
.in
.alloc_size
= 0;
568 io
.ntcreatex
.in
.access_mask
= SEC_RIGHTS_FILE_ALL
;
569 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
570 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
| NTCREATEX_SHARE_ACCESS_WRITE
| NTCREATEX_SHARE_ACCESS_DELETE
;
571 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_CREATE
;
572 io
.ntcreatex
.in
.create_options
= 0;
573 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
574 io
.ntcreatex
.in
.security_flags
= 0;
575 io
.ntcreatex
.in
.fname
= fname
;
577 /* Create the file. */
579 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
580 CHECK_STATUS(status
, NT_STATUS_OK
);
581 fnum
= io
.ntcreatex
.out
.file
.fnum
;
583 /* Now try and rename the directory. */
586 ren_io
.generic
.level
= RAW_RENAME_RENAME
;
587 ren_io
.rename
.in
.pattern1
= dname1
;
588 ren_io
.rename
.in
.pattern2
= dname2
;
589 ren_io
.rename
.in
.attrib
= 0;
591 status
= smb_raw_rename(cli
->tree
, &ren_io
);
592 CHECK_STATUS(status
, NT_STATUS_ACCESS_DENIED
);
597 smbcli_close(cli
->tree
, fnum
);
599 smb_raw_exit(cli
->session
);
600 smbcli_deltree(cli
->tree
, BASEDIR
);
604 extern bool test_trans2rename(struct torture_context
*tctx
, struct smbcli_state
*cli1
, struct smbcli_state
*cli2
);
605 extern bool test_nttransrename(struct torture_context
*tctx
, struct smbcli_state
*cli1
);
608 basic testing of rename calls
610 struct torture_suite
*torture_raw_rename(TALLOC_CTX
*mem_ctx
)
612 struct torture_suite
*suite
= torture_suite_create(mem_ctx
, "RENAME");
614 torture_suite_add_1smb_test(suite
, "mv", test_mv
);
615 /* test_trans2rename and test_nttransrename are actually in torture/raw/oplock.c to
616 use the handlers and macros there. */
617 torture_suite_add_2smb_test(suite
, "trans2rename", test_trans2rename
);
618 torture_suite_add_1smb_test(suite
, "nttransrename", test_nttransrename
);
619 torture_suite_add_1smb_test(suite
, "ntrename", test_ntrename
);
620 torture_suite_add_1smb_test(suite
, "osxrename", test_osxrename
);
621 torture_suite_add_1smb_test(suite
, "directory rename", test_dir_rename
);