2 Unix SMB/CIFS implementation.
6 Copyright (C) Christian Ambach 2012
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "libcli/smb2/smb2.h"
24 #include "libcli/smb2/smb2_calls.h"
26 #include "torture/torture.h"
27 #include "torture/smb2/proto.h"
29 #include "librpc/gen_ndr/security.h"
31 #define CHECK_STATUS(status, correct) do { \
32 if (!NT_STATUS_EQUAL(status, correct)) { \
33 torture_result(torture, TORTURE_FAIL, \
34 "(%s) Incorrect status %s - should be %s\n", \
35 __location__, nt_errstr(status), nt_errstr(correct)); \
40 #define BASEDIR "test_rename"
43 * basic testing of rename: open file with DELETE access
47 static bool torture_smb2_rename_simple(struct torture_context *torture,
48 struct smb2_tree *tree1)
54 union smb_setfileinfo sinfo;
55 union smb_fileinfo fi;
56 struct smb2_handle h1;
58 smb2_deltree(tree1, BASEDIR);
59 smb2_util_rmdir(tree1, BASEDIR);
61 torture_comment(torture, "Creating base directory\n");
63 smb2_util_mkdir(tree1, BASEDIR);
66 torture_comment(torture, "Creating test file\n");
69 io.generic.level = RAW_OPEN_SMB2;
70 io.smb2.in.create_flags = 0;
71 io.smb2.in.desired_access = SEC_FILE_ALL|SEC_STD_DELETE;
72 io.smb2.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
73 io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
74 io.smb2.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
75 NTCREATEX_SHARE_ACCESS_WRITE | NTCREATEX_SHARE_ACCESS_DELETE;
76 io.smb2.in.alloc_size = 0;
77 io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
78 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
79 io.smb2.in.security_flags = 0;
80 io.smb2.in.fname = BASEDIR "\\file.txt";
82 status = smb2_create(tree1, torture, &(io.smb2));
83 CHECK_STATUS(status, NT_STATUS_OK);
84 h1 = io.smb2.out.file.handle;
86 torture_comment(torture, "Renaming test file\n");
89 sinfo.rename_information.level = RAW_SFILEINFO_RENAME_INFORMATION;
90 sinfo.rename_information.in.file.handle = io.smb2.out.file.handle;
91 sinfo.rename_information.in.overwrite = 0;
92 sinfo.rename_information.in.root_fid = 0;
93 sinfo.rename_information.in.new_name =
94 BASEDIR "\\newname.txt";
95 status = smb2_setinfo_file(tree1, &sinfo);
96 CHECK_STATUS(status, NT_STATUS_OK);
98 torture_comment(torture, "Checking for new filename\n");
101 fi.generic.level = RAW_FILEINFO_SMB2_ALL_INFORMATION;
102 fi.generic.in.file.handle = h1;
103 status = smb2_getinfo_file(tree1, torture, &fi);
104 CHECK_STATUS(status, NT_STATUS_OK);
107 torture_comment(torture, "Closing test file\n");
109 ZERO_STRUCT(cl.smb2);
110 cl.smb2.level = RAW_CLOSE_SMB2;
111 cl.smb2.in.file.handle = h1;
112 status = smb2_close(tree1, &(cl.smb2));
113 CHECK_STATUS(status, NT_STATUS_OK);
119 torture_comment(torture, "Cleaning up\n");
122 ZERO_STRUCT(cl.smb2);
123 cl.smb2.level = RAW_CLOSE_SMB2;
124 cl.smb2.in.file.handle = h1;
125 status = smb2_close(tree1, &(cl.smb2));
127 smb2_deltree(tree1, BASEDIR);
132 * basic testing of rename, this time do not request DELETE access
133 * for the file, this should fail
136 static bool torture_smb2_rename_simple2(struct torture_context *torture,
137 struct smb2_tree *tree1)
143 union smb_setfileinfo sinfo;
144 struct smb2_handle h1;
146 smb2_deltree(tree1, BASEDIR);
147 smb2_util_rmdir(tree1, BASEDIR);
149 torture_comment(torture, "Creating base directory\n");
151 smb2_util_mkdir(tree1, BASEDIR);
154 torture_comment(torture, "Creating test file\n");
156 ZERO_STRUCT(io.smb2);
157 io.generic.level = RAW_OPEN_SMB2;
158 io.smb2.in.create_flags = 0;
159 io.smb2.in.desired_access = SEC_FILE_ALL;
160 io.smb2.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
161 io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
162 io.smb2.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
163 NTCREATEX_SHARE_ACCESS_WRITE | NTCREATEX_SHARE_ACCESS_DELETE;
164 io.smb2.in.alloc_size = 0;
165 io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
166 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
167 io.smb2.in.security_flags = 0;
168 io.smb2.in.fname = BASEDIR "\\file.txt";
170 status = smb2_create(tree1, torture, &(io.smb2));
171 CHECK_STATUS(status, NT_STATUS_OK);
172 h1 = io.smb2.out.file.handle;
174 torture_comment(torture, "Renaming test file\n");
177 sinfo.rename_information.level = RAW_SFILEINFO_RENAME_INFORMATION;
178 sinfo.rename_information.in.file.handle = io.smb2.out.file.handle;
179 sinfo.rename_information.in.overwrite = 0;
180 sinfo.rename_information.in.root_fid = 0;
181 sinfo.rename_information.in.new_name =
182 BASEDIR "\\newname.txt";
183 status = smb2_setinfo_file(tree1, &sinfo);
184 CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
186 torture_comment(torture, "Closing test file\n");
188 ZERO_STRUCT(cl.smb2);
189 cl.smb2.level = RAW_CLOSE_SMB2;
190 cl.smb2.in.file.handle = h1;
191 status = smb2_close(tree1, &(cl.smb2));
192 CHECK_STATUS(status, NT_STATUS_OK);
198 torture_comment(torture, "Cleaning up\n");
201 ZERO_STRUCT(cl.smb2);
202 cl.smb2.level = RAW_CLOSE_SMB2;
203 cl.smb2.in.file.handle = h1;
204 status = smb2_close(tree1, &(cl.smb2));
206 smb2_deltree(tree1, BASEDIR);
212 * testing of rename with no sharing allowed on file
216 static bool torture_smb2_rename_no_sharemode(struct torture_context *torture,
217 struct smb2_tree *tree1)
223 union smb_setfileinfo sinfo;
224 union smb_fileinfo fi;
225 struct smb2_handle h1;
227 smb2_deltree(tree1, BASEDIR);
228 smb2_util_rmdir(tree1, BASEDIR);
230 torture_comment(torture, "Creating base directory\n");
232 smb2_util_mkdir(tree1, BASEDIR);
235 torture_comment(torture, "Creating test file\n");
237 ZERO_STRUCT(io.smb2);
238 io.generic.level = RAW_OPEN_SMB2;
239 io.smb2.in.create_flags = 0;
240 io.smb2.in.desired_access = 0x0017019f;
241 io.smb2.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
242 io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
243 io.smb2.in.share_access = 0;
244 io.smb2.in.alloc_size = 0;
245 io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
246 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
247 io.smb2.in.security_flags = 0;
248 io.smb2.in.fname = BASEDIR "\\file.txt";
250 status = smb2_create(tree1, torture, &(io.smb2));
251 CHECK_STATUS(status, NT_STATUS_OK);
252 h1 = io.smb2.out.file.handle;
254 torture_comment(torture, "Renaming test file\n");
257 sinfo.rename_information.level = RAW_SFILEINFO_RENAME_INFORMATION;
258 sinfo.rename_information.in.file.handle = io.smb2.out.file.handle;
259 sinfo.rename_information.in.overwrite = 0;
260 sinfo.rename_information.in.root_fid = 0;
261 sinfo.rename_information.in.new_name =
262 BASEDIR "\\newname.txt";
263 status = smb2_setinfo_file(tree1, &sinfo);
264 CHECK_STATUS(status, NT_STATUS_OK);
266 torture_comment(torture, "Checking for new filename\n");
269 fi.generic.level = RAW_FILEINFO_SMB2_ALL_INFORMATION;
270 fi.generic.in.file.handle = h1;
271 status = smb2_getinfo_file(tree1, torture, &fi);
272 CHECK_STATUS(status, NT_STATUS_OK);
275 torture_comment(torture, "Closing test file\n");
277 ZERO_STRUCT(cl.smb2);
278 cl.smb2.level = RAW_CLOSE_SMB2;
279 cl.smb2.in.file.handle = h1;
280 status = smb2_close(tree1, &(cl.smb2));
281 CHECK_STATUS(status, NT_STATUS_OK);
287 torture_comment(torture, "Cleaning up\n");
290 ZERO_STRUCT(cl.smb2);
291 cl.smb2.level = RAW_CLOSE_SMB2;
292 cl.smb2.in.file.handle = h1;
293 status = smb2_close(tree1, &(cl.smb2));
295 smb2_deltree(tree1, BASEDIR);
300 * testing of rename when opening parent dir with delete access and delete
302 * should result in sharing violation
305 static bool torture_smb2_rename_with_delete_access(struct torture_context *torture,
306 struct smb2_tree *tree1)
312 union smb_setfileinfo sinfo;
313 struct smb2_handle fh, dh;
315 smb2_deltree(tree1, BASEDIR);
316 smb2_util_rmdir(tree1, BASEDIR);
318 torture_comment(torture, "Creating base directory\n");
320 smb2_util_mkdir(tree1, BASEDIR);
322 torture_comment(torture, "Opening parent directory\n");
324 ZERO_STRUCT(io.smb2);
325 io.generic.level = RAW_OPEN_SMB2;
326 io.smb2.in.create_flags = 0;
327 io.smb2.in.desired_access = SEC_STD_SYNCHRONIZE | SEC_STD_WRITE_DAC |
328 SEC_STD_READ_CONTROL | SEC_STD_DELETE | SEC_FILE_WRITE_ATTRIBUTE |
329 SEC_FILE_READ_ATTRIBUTE | SEC_FILE_EXECUTE | SEC_FILE_WRITE_EA |
330 SEC_FILE_READ_EA | SEC_FILE_APPEND_DATA | SEC_FILE_READ_DATA |
332 io.smb2.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
333 io.smb2.in.file_attributes = FILE_ATTRIBUTE_DIRECTORY;
334 io.smb2.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
335 NTCREATEX_SHARE_ACCESS_WRITE | NTCREATEX_SHARE_ACCESS_DELETE;
336 io.smb2.in.alloc_size = 0;
337 io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN;
338 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
339 io.smb2.in.security_flags = 0;
340 io.smb2.in.fname = BASEDIR;
342 status = smb2_create(tree1, torture, &(io.smb2));
343 CHECK_STATUS(status, NT_STATUS_OK);
344 dh = io.smb2.out.file.handle;
347 torture_comment(torture, "Creating test file\n");
349 ZERO_STRUCT(io.smb2);
350 io.generic.level = RAW_OPEN_SMB2;
351 io.smb2.in.create_flags = 0;
352 io.smb2.in.desired_access = SEC_STD_SYNCHRONIZE | SEC_STD_WRITE_DAC |
353 SEC_STD_READ_CONTROL | SEC_STD_DELETE | SEC_FILE_WRITE_ATTRIBUTE |
354 SEC_FILE_READ_ATTRIBUTE | SEC_FILE_WRITE_EA | SEC_FILE_READ_EA |
355 SEC_FILE_APPEND_DATA | SEC_FILE_READ_DATA | SEC_FILE_WRITE_DATA;
356 io.smb2.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
357 io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
358 io.smb2.in.share_access = 0;
359 io.smb2.in.alloc_size = 0;
360 io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
361 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
362 io.smb2.in.security_flags = 0;
363 io.smb2.in.fname = BASEDIR "\\file.txt";
365 status = smb2_create(tree1, torture, &(io.smb2));
366 CHECK_STATUS(status, NT_STATUS_OK);
367 fh = io.smb2.out.file.handle;
369 torture_comment(torture, "Renaming test file\n");
372 sinfo.rename_information.level = RAW_SFILEINFO_RENAME_INFORMATION;
373 sinfo.rename_information.in.file.handle = fh;
374 sinfo.rename_information.in.overwrite = 0;
375 sinfo.rename_information.in.root_fid = 0;
376 sinfo.rename_information.in.new_name =
377 BASEDIR "\\newname.txt";
378 status = smb2_setinfo_file(tree1, &sinfo);
379 CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
381 torture_comment(torture, "Closing test file\n");
383 ZERO_STRUCT(cl.smb2);
384 cl.smb2.level = RAW_CLOSE_SMB2;
385 cl.smb2.in.file.handle = fh;
386 status = smb2_close(tree1, &(cl.smb2));
387 CHECK_STATUS(status, NT_STATUS_OK);
391 torture_comment(torture, "Closing directory\n");
393 ZERO_STRUCT(cl.smb2);
394 cl.smb2.level = RAW_CLOSE_SMB2;
395 cl.smb2.in.file.handle = dh;
396 status = smb2_close(tree1, &(cl.smb2));
397 CHECK_STATUS(status, NT_STATUS_OK);
404 torture_comment(torture, "Cleaning up\n");
407 ZERO_STRUCT(cl.smb2);
408 cl.smb2.level = RAW_CLOSE_SMB2;
409 cl.smb2.in.file.handle = fh;
410 status = smb2_close(tree1, &(cl.smb2));
413 ZERO_STRUCT(cl.smb2);
414 cl.smb2.level = RAW_CLOSE_SMB2;
415 cl.smb2.in.file.handle = dh;
416 status = smb2_close(tree1, &(cl.smb2));
419 smb2_deltree(tree1, BASEDIR);
425 * testing of rename with delete access on parent dir
426 * this is a variation of the test above: parent dir is opened
427 * without share_delete, so rename must fail
430 static bool torture_smb2_rename_with_delete_access2(struct torture_context *torture,
431 struct smb2_tree *tree1)
437 union smb_setfileinfo sinfo;
438 struct smb2_handle fh, dh;
440 smb2_deltree(tree1, BASEDIR);
441 smb2_util_rmdir(tree1, BASEDIR);
443 torture_comment(torture, "Creating base directory\n");
445 smb2_util_mkdir(tree1, BASEDIR);
447 torture_comment(torture, "Opening parent directory\n");
449 ZERO_STRUCT(io.smb2);
450 io.generic.level = RAW_OPEN_SMB2;
451 io.smb2.in.create_flags = 0;
452 io.smb2.in.desired_access = SEC_STD_SYNCHRONIZE | SEC_STD_WRITE_DAC |
453 SEC_STD_READ_CONTROL | SEC_STD_DELETE | SEC_FILE_WRITE_ATTRIBUTE |
454 SEC_FILE_READ_ATTRIBUTE | SEC_FILE_EXECUTE | SEC_FILE_WRITE_EA |
455 SEC_FILE_READ_EA | SEC_FILE_APPEND_DATA | SEC_FILE_READ_DATA |
457 io.smb2.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
458 io.smb2.in.file_attributes = FILE_ATTRIBUTE_DIRECTORY;
459 io.smb2.in.share_access = 0;
460 io.smb2.in.alloc_size = 0;
461 io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN;
462 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
463 io.smb2.in.security_flags = 0;
464 io.smb2.in.fname = BASEDIR;
466 status = smb2_create(tree1, torture, &(io.smb2));
467 CHECK_STATUS(status, NT_STATUS_OK);
468 dh = io.smb2.out.file.handle;
471 torture_comment(torture, "Creating test file\n");
473 ZERO_STRUCT(io.smb2);
474 io.generic.level = RAW_OPEN_SMB2;
475 io.smb2.in.create_flags = 0;
476 io.smb2.in.desired_access = SEC_STD_SYNCHRONIZE | SEC_STD_WRITE_DAC |
477 SEC_STD_READ_CONTROL | SEC_STD_DELETE | SEC_FILE_WRITE_ATTRIBUTE |
478 SEC_FILE_READ_ATTRIBUTE | SEC_FILE_WRITE_EA | SEC_FILE_READ_EA |
479 SEC_FILE_APPEND_DATA | SEC_FILE_READ_DATA | SEC_FILE_WRITE_DATA;
480 io.smb2.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
481 io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
482 io.smb2.in.share_access = 0;
483 io.smb2.in.alloc_size = 0;
484 io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
485 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
486 io.smb2.in.security_flags = 0;
487 io.smb2.in.fname = BASEDIR "\\file.txt";
489 status = smb2_create(tree1, torture, &(io.smb2));
490 CHECK_STATUS(status, NT_STATUS_OK);
491 fh = io.smb2.out.file.handle;
493 torture_comment(torture, "Renaming test file\n");
496 sinfo.rename_information.level = RAW_SFILEINFO_RENAME_INFORMATION;
497 sinfo.rename_information.in.file.handle = fh;
498 sinfo.rename_information.in.overwrite = 0;
499 sinfo.rename_information.in.root_fid = 0;
500 sinfo.rename_information.in.new_name =
501 BASEDIR "\\newname.txt";
502 status = smb2_setinfo_file(tree1, &sinfo);
503 CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
505 torture_comment(torture, "Closing test file\n");
507 ZERO_STRUCT(cl.smb2);
508 cl.smb2.level = RAW_CLOSE_SMB2;
509 cl.smb2.in.file.handle = fh;
510 status = smb2_close(tree1, &(cl.smb2));
511 CHECK_STATUS(status, NT_STATUS_OK);
515 torture_comment(torture, "Closing directory\n");
517 ZERO_STRUCT(cl.smb2);
518 cl.smb2.level = RAW_CLOSE_SMB2;
519 cl.smb2.in.file.handle = dh;
520 status = smb2_close(tree1, &(cl.smb2));
521 CHECK_STATUS(status, NT_STATUS_OK);
528 torture_comment(torture, "Cleaning up\n");
531 ZERO_STRUCT(cl.smb2);
532 cl.smb2.level = RAW_CLOSE_SMB2;
533 cl.smb2.in.file.handle = fh;
534 status = smb2_close(tree1, &(cl.smb2));
537 ZERO_STRUCT(cl.smb2);
538 cl.smb2.level = RAW_CLOSE_SMB2;
539 cl.smb2.in.file.handle = dh;
540 status = smb2_close(tree1, &(cl.smb2));
543 smb2_deltree(tree1, BASEDIR);
548 * testing of rename when opening parent dir with no delete access and delete
553 static bool torture_smb2_rename_no_delete_access(struct torture_context *torture,
554 struct smb2_tree *tree1)
560 union smb_setfileinfo sinfo;
561 union smb_fileinfo fi;
562 struct smb2_handle fh, dh;
564 smb2_deltree(tree1, BASEDIR);
565 smb2_util_rmdir(tree1, BASEDIR);
567 torture_comment(torture, "Creating base directory\n");
569 smb2_util_mkdir(tree1, BASEDIR);
571 torture_comment(torture, "Opening parent directory\n");
573 ZERO_STRUCT(io.smb2);
574 io.generic.level = RAW_OPEN_SMB2;
575 io.smb2.in.create_flags = 0;
576 io.smb2.in.desired_access = SEC_STD_SYNCHRONIZE | SEC_STD_WRITE_DAC |
577 SEC_STD_READ_CONTROL | SEC_FILE_WRITE_ATTRIBUTE |
578 SEC_FILE_READ_ATTRIBUTE | SEC_FILE_EXECUTE | SEC_FILE_WRITE_EA |
579 SEC_FILE_READ_EA | SEC_FILE_APPEND_DATA | SEC_FILE_READ_DATA |
581 io.smb2.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
582 io.smb2.in.file_attributes = FILE_ATTRIBUTE_DIRECTORY;
583 io.smb2.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
584 NTCREATEX_SHARE_ACCESS_WRITE | NTCREATEX_SHARE_ACCESS_DELETE;
585 io.smb2.in.alloc_size = 0;
586 io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN;
587 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
588 io.smb2.in.security_flags = 0;
589 io.smb2.in.fname = BASEDIR;
591 status = smb2_create(tree1, torture, &(io.smb2));
592 CHECK_STATUS(status, NT_STATUS_OK);
593 dh = io.smb2.out.file.handle;
596 torture_comment(torture, "Creating test file\n");
598 ZERO_STRUCT(io.smb2);
599 io.generic.level = RAW_OPEN_SMB2;
600 io.smb2.in.create_flags = 0;
601 io.smb2.in.desired_access = SEC_STD_SYNCHRONIZE | SEC_STD_WRITE_DAC |
602 SEC_STD_READ_CONTROL | SEC_STD_DELETE | SEC_FILE_WRITE_ATTRIBUTE |
603 SEC_FILE_READ_ATTRIBUTE | SEC_FILE_WRITE_EA | SEC_FILE_READ_EA |
604 SEC_FILE_APPEND_DATA | SEC_FILE_READ_DATA | SEC_FILE_WRITE_DATA;
605 io.smb2.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
606 io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
607 io.smb2.in.share_access = 0;
608 io.smb2.in.alloc_size = 0;
609 io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
610 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
611 io.smb2.in.security_flags = 0;
612 io.smb2.in.fname = BASEDIR "\\file.txt";
614 status = smb2_create(tree1, torture, &(io.smb2));
615 CHECK_STATUS(status, NT_STATUS_OK);
616 fh = io.smb2.out.file.handle;
618 torture_comment(torture, "Renaming test file\n");
621 sinfo.rename_information.level = RAW_SFILEINFO_RENAME_INFORMATION;
622 sinfo.rename_information.in.file.handle = fh;
623 sinfo.rename_information.in.overwrite = 0;
624 sinfo.rename_information.in.root_fid = 0;
625 sinfo.rename_information.in.new_name =
626 BASEDIR "\\newname.txt";
627 status = smb2_setinfo_file(tree1, &sinfo);
628 CHECK_STATUS(status, NT_STATUS_OK);
630 torture_comment(torture, "Checking for new filename\n");
633 fi.generic.level = RAW_FILEINFO_SMB2_ALL_INFORMATION;
634 fi.generic.in.file.handle = fh;
635 status = smb2_getinfo_file(tree1, torture, &fi);
636 CHECK_STATUS(status, NT_STATUS_OK);
639 torture_comment(torture, "Closing test file\n");
641 ZERO_STRUCT(cl.smb2);
642 cl.smb2.level = RAW_CLOSE_SMB2;
643 cl.smb2.in.file.handle = fh;
644 status = smb2_close(tree1, &(cl.smb2));
645 CHECK_STATUS(status, NT_STATUS_OK);
649 torture_comment(torture, "Closing directory\n");
651 ZERO_STRUCT(cl.smb2);
652 cl.smb2.level = RAW_CLOSE_SMB2;
653 cl.smb2.in.file.handle = dh;
654 status = smb2_close(tree1, &(cl.smb2));
655 CHECK_STATUS(status, NT_STATUS_OK);
662 torture_comment(torture, "Cleaning up\n");
665 ZERO_STRUCT(cl.smb2);
666 cl.smb2.level = RAW_CLOSE_SMB2;
667 cl.smb2.in.file.handle = fh;
668 status = smb2_close(tree1, &(cl.smb2));
671 ZERO_STRUCT(cl.smb2);
672 cl.smb2.level = RAW_CLOSE_SMB2;
673 cl.smb2.in.file.handle = dh;
674 status = smb2_close(tree1, &(cl.smb2));
677 smb2_deltree(tree1, BASEDIR);
683 * testing of rename with no delete access on parent dir
684 * this is the negative case of the test above: parent dir is opened
685 * without share_delete, so rename must fail
688 static bool torture_smb2_rename_no_delete_access2(struct torture_context *torture,
689 struct smb2_tree *tree1)
695 union smb_setfileinfo sinfo;
696 struct smb2_handle fh, dh;
698 smb2_deltree(tree1, BASEDIR);
699 smb2_util_rmdir(tree1, BASEDIR);
701 torture_comment(torture, "Creating base directory\n");
703 smb2_util_mkdir(tree1, BASEDIR);
705 torture_comment(torture, "Opening parent directory\n");
707 ZERO_STRUCT(io.smb2);
708 io.generic.level = RAW_OPEN_SMB2;
709 io.smb2.in.create_flags = 0;
710 io.smb2.in.desired_access = SEC_STD_SYNCHRONIZE | SEC_STD_WRITE_DAC |
711 SEC_STD_READ_CONTROL | SEC_FILE_WRITE_ATTRIBUTE |
712 SEC_FILE_READ_ATTRIBUTE | SEC_FILE_EXECUTE | SEC_FILE_WRITE_EA |
713 SEC_FILE_READ_EA | SEC_FILE_APPEND_DATA | SEC_FILE_READ_DATA |
715 io.smb2.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
716 io.smb2.in.file_attributes = FILE_ATTRIBUTE_DIRECTORY;
717 io.smb2.in.share_access = 0;
718 io.smb2.in.alloc_size = 0;
719 io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN;
720 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
721 io.smb2.in.security_flags = 0;
722 io.smb2.in.fname = BASEDIR;
724 status = smb2_create(tree1, torture, &(io.smb2));
725 CHECK_STATUS(status, NT_STATUS_OK);
726 dh = io.smb2.out.file.handle;
729 torture_comment(torture, "Creating test file\n");
731 ZERO_STRUCT(io.smb2);
732 io.generic.level = RAW_OPEN_SMB2;
733 io.smb2.in.create_flags = 0;
734 io.smb2.in.desired_access = SEC_STD_SYNCHRONIZE | SEC_STD_WRITE_DAC |
735 SEC_STD_READ_CONTROL | SEC_STD_DELETE | SEC_FILE_WRITE_ATTRIBUTE |
736 SEC_FILE_READ_ATTRIBUTE | SEC_FILE_WRITE_EA | SEC_FILE_READ_EA |
737 SEC_FILE_APPEND_DATA | SEC_FILE_READ_DATA | SEC_FILE_WRITE_DATA;
738 io.smb2.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
739 io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
740 io.smb2.in.share_access = 0;
741 io.smb2.in.alloc_size = 0;
742 io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
743 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
744 io.smb2.in.security_flags = 0;
745 io.smb2.in.fname = BASEDIR "\\file.txt";
747 status = smb2_create(tree1, torture, &(io.smb2));
748 CHECK_STATUS(status, NT_STATUS_OK);
749 fh = io.smb2.out.file.handle;
751 torture_comment(torture, "Renaming test file\n");
754 sinfo.rename_information.level = RAW_SFILEINFO_RENAME_INFORMATION;
755 sinfo.rename_information.in.file.handle = fh;
756 sinfo.rename_information.in.overwrite = 0;
757 sinfo.rename_information.in.root_fid = 0;
758 sinfo.rename_information.in.new_name =
759 BASEDIR "\\newname.txt";
760 status = smb2_setinfo_file(tree1, &sinfo);
761 CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
763 torture_comment(torture, "Closing test file\n");
765 ZERO_STRUCT(cl.smb2);
766 cl.smb2.level = RAW_CLOSE_SMB2;
767 cl.smb2.in.file.handle = fh;
768 status = smb2_close(tree1, &(cl.smb2));
769 CHECK_STATUS(status, NT_STATUS_OK);
773 torture_comment(torture, "Closing directory\n");
775 ZERO_STRUCT(cl.smb2);
776 cl.smb2.level = RAW_CLOSE_SMB2;
777 cl.smb2.in.file.handle = dh;
778 status = smb2_close(tree1, &(cl.smb2));
779 CHECK_STATUS(status, NT_STATUS_OK);
786 torture_comment(torture, "Cleaning up\n");
789 ZERO_STRUCT(cl.smb2);
790 cl.smb2.level = RAW_CLOSE_SMB2;
791 cl.smb2.in.file.handle = fh;
792 status = smb2_close(tree1, &(cl.smb2));
795 ZERO_STRUCT(cl.smb2);
796 cl.smb2.level = RAW_CLOSE_SMB2;
797 cl.smb2.in.file.handle = dh;
798 status = smb2_close(tree1, &(cl.smb2));
801 smb2_deltree(tree1, BASEDIR);
806 basic testing of SMB2 rename
808 struct torture_suite *torture_smb2_rename_init(void)
810 struct torture_suite *suite =
811 torture_suite_create(talloc_autofree_context(), "rename");
813 torture_suite_add_1smb2_test(suite, "simple",
814 torture_smb2_rename_simple);
816 torture_suite_add_1smb2_test(suite, "simple_nodelete)",
817 torture_smb2_rename_simple2);
819 torture_suite_add_1smb2_test(suite, "no_sharing",
820 torture_smb2_rename_no_sharemode);
822 torture_suite_add_1smb2_test(suite,
823 "share_delete_and_delete_access",
824 torture_smb2_rename_with_delete_access);
826 torture_suite_add_1smb2_test(suite,
827 "no_share_delete_but_delete_access",
828 torture_smb2_rename_with_delete_access2);
830 torture_suite_add_1smb2_test(suite,
831 "share_delete_no_delete_access",
832 torture_smb2_rename_no_delete_access);
834 torture_suite_add_1smb2_test(suite,
835 "no_share_delete_no_delete_access",
836 torture_smb2_rename_no_delete_access2);
838 suite->description = talloc_strdup(suite, "smb2.rename tests");