Debian Codegraph @

source4/torture/smb2/rename.c

raw
1 /*
2 Unix SMB/CIFS implementation.
3
4 SMB2 rename test suite
5
6 Copyright (C) Christian Ambach 2012
7
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.
12
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.
17
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/>.
20 */
21
22 #include "includes.h"
23 #include "libcli/smb2/smb2.h"
24 #include "libcli/smb2/smb2_calls.h"
25 #include <tevent.h>
26 #include "lib/util/tevent_ntstatus.h"
27
28 #include "torture/torture.h"
29 #include "torture/util.h"
30 #include "torture/smb2/proto.h"
31
32 #include "librpc/gen_ndr/security.h"
33
34 #define CHECK_VAL(v, correct) \
35 do { \
36 if ((v) != (correct)) { \
37 torture_result(torture, \
38 TORTURE_FAIL, \
39 "(%s): wrong value for %s got " \
40 "0x%llx - should be 0x%llx\n", \
41 __location__, #v, \
42 (unsigned long long)v, \
43 (unsigned long long)correct); \
44 ret = false; \
45 goto done; \
46 }} while (0)
47
48 #define CHECK_CREATED(__io, __created, __attribute) \
49 do { \
50 CHECK_VAL((__io)->out.create_action, NTCREATEX_ACTION_ ## __created); \
51 CHECK_VAL((__io)->out.size, 0); \
52 CHECK_VAL((__io)->out.file_attr, (__attribute)); \
53 CHECK_VAL((__io)->out.reserved2, 0); \
54 } while(0)
55
56 #define CHECK_STATUS(status, correct) do { \
57 if (!NT_STATUS_EQUAL(status, correct)) { \
58 torture_result(torture, TORTURE_FAIL, \
59 "(%s) Incorrect status %s - should be %s\n", \
60 __location__, nt_errstr(status), nt_errstr(correct)); \
61 ret = false; \
62 goto done; \
63 }} while (0)
64
65 #define BASEDIR "test_rename"
66
67 /*
68 * basic testing of rename: open file with DELETE access
69 * this should pass
70 */
71
72 static bool torture_smb2_rename_simple(struct torture_context *torture,
73 struct smb2_tree *tree1)
74 {
75 bool ret = true;
76 NTSTATUS status;
77 union smb_open io;
78 union smb_close cl;
79 union smb_setfileinfo sinfo;
80 union smb_fileinfo fi;
81 struct smb2_handle h1;
82
83 ZERO_STRUCT(h1);
84
85 smb2_deltree(tree1, BASEDIR);
86 smb2_util_rmdir(tree1, BASEDIR);
87
88 torture_comment(torture, "Creating base directory\n");
89
90 smb2_util_mkdir(tree1, BASEDIR);
91
92
93 torture_comment(torture, "Creating test file\n");
94
95 ZERO_STRUCT(io.smb2);
96 io.generic.level = RAW_OPEN_SMB2;
97 io.smb2.in.create_flags = 0;
98 io.smb2.in.desired_access = SEC_FILE_ALL|SEC_STD_DELETE;
99 io.smb2.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
100 io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
101 io.smb2.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
102 NTCREATEX_SHARE_ACCESS_WRITE | NTCREATEX_SHARE_ACCESS_DELETE;
103 io.smb2.in.alloc_size = 0;
104 io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
105 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
106 io.smb2.in.security_flags = 0;
107 io.smb2.in.fname = BASEDIR "\\file.txt";
108
109 status = smb2_create(tree1, torture, &(io.smb2));
110 CHECK_STATUS(status, NT_STATUS_OK);
111 h1 = io.smb2.out.file.handle;
112
113 torture_comment(torture, "Renaming test file\n");
114
115 ZERO_STRUCT(sinfo);
116 sinfo.rename_information.level = RAW_SFILEINFO_RENAME_INFORMATION;
117 sinfo.rename_information.in.file.handle = io.smb2.out.file.handle;
118 sinfo.rename_information.in.overwrite = 0;
119 sinfo.rename_information.in.root_fid = 0;
120 sinfo.rename_information.in.new_name =
121 BASEDIR "\\newname.txt";
122 status = smb2_setinfo_file(tree1, &sinfo);
123 CHECK_STATUS(status, NT_STATUS_OK);
124
125 torture_comment(torture, "Checking for new filename\n");
126
127 ZERO_STRUCT(fi);
128 fi.generic.level = RAW_FILEINFO_SMB2_ALL_INFORMATION;
129 fi.generic.in.file.handle = h1;
130 status = smb2_getinfo_file(tree1, torture, &fi);
131 CHECK_STATUS(status, NT_STATUS_OK);
132
133
134 torture_comment(torture, "Closing test file\n");
135
136 ZERO_STRUCT(cl.smb2);
137 cl.smb2.level = RAW_CLOSE_SMB2;
138 cl.smb2.in.file.handle = h1;
139 status = smb2_close(tree1, &(cl.smb2));
140 CHECK_STATUS(status, NT_STATUS_OK);
141
142 ZERO_STRUCT(h1);
143
144 done:
145
146 torture_comment(torture, "Cleaning up\n");
147
148 if (h1.data[0] || h1.data[1]) {
149 ZERO_STRUCT(cl.smb2);
150 cl.smb2.level = RAW_CLOSE_SMB2;
151 cl.smb2.in.file.handle = h1;
152 status = smb2_close(tree1, &(cl.smb2));
153 }
154 smb2_deltree(tree1, BASEDIR);
155 return ret;
156 }
157
158 /*
159 * basic testing of rename, this time do not request DELETE access
160 * for the file, this should fail
161 */
162
163 static bool torture_smb2_rename_simple2(struct torture_context *torture,
164 struct smb2_tree *tree1)
165 {
166 bool ret = true;
167 NTSTATUS status;
168 union smb_open io;
169 union smb_close cl;
170 union smb_setfileinfo sinfo;
171 struct smb2_handle h1;
172
173 ZERO_STRUCT(h1);
174
175 smb2_deltree(tree1, BASEDIR);
176 smb2_util_rmdir(tree1, BASEDIR);
177
178 torture_comment(torture, "Creating base directory\n");
179
180 smb2_util_mkdir(tree1, BASEDIR);
181
182
183 torture_comment(torture, "Creating test file\n");
184
185 ZERO_STRUCT(io.smb2);
186 io.generic.level = RAW_OPEN_SMB2;
187 io.smb2.in.create_flags = 0;
188 io.smb2.in.desired_access = SEC_FILE_ALL;
189 io.smb2.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
190 io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
191 io.smb2.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
192 NTCREATEX_SHARE_ACCESS_WRITE | NTCREATEX_SHARE_ACCESS_DELETE;
193 io.smb2.in.alloc_size = 0;
194 io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
195 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
196 io.smb2.in.security_flags = 0;
197 io.smb2.in.fname = BASEDIR "\\file.txt";
198
199 status = smb2_create(tree1, torture, &(io.smb2));
200 CHECK_STATUS(status, NT_STATUS_OK);
201 h1 = io.smb2.out.file.handle;
202
203 torture_comment(torture, "Renaming test file\n");
204
205 ZERO_STRUCT(sinfo);
206 sinfo.rename_information.level = RAW_SFILEINFO_RENAME_INFORMATION;
207 sinfo.rename_information.in.file.handle = io.smb2.out.file.handle;
208 sinfo.rename_information.in.overwrite = 0;
209 sinfo.rename_information.in.root_fid = 0;
210 sinfo.rename_information.in.new_name =
211 BASEDIR "\\newname.txt";
212 status = smb2_setinfo_file(tree1, &sinfo);
213 CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
214
215 torture_comment(torture, "Closing test file\n");
216
217 ZERO_STRUCT(cl.smb2);
218 cl.smb2.level = RAW_CLOSE_SMB2;
219 cl.smb2.in.file.handle = h1;
220 status = smb2_close(tree1, &(cl.smb2));
221 CHECK_STATUS(status, NT_STATUS_OK);
222
223 ZERO_STRUCT(h1);
224
225 done:
226
227 torture_comment(torture, "Cleaning up\n");
228
229 if (h1.data[0] || h1.data[1]) {
230 ZERO_STRUCT(cl.smb2);
231 cl.smb2.level = RAW_CLOSE_SMB2;
232 cl.smb2.in.file.handle = h1;
233 status = smb2_close(tree1, &(cl.smb2));
234 }
235 smb2_deltree(tree1, BASEDIR);
236 return ret;
237 }
238
239
240 /*
241 * testing of rename with no sharing allowed on file
242 * this should work
243 */
244
245 static bool torture_smb2_rename_no_sharemode(struct torture_context *torture,
246 struct smb2_tree *tree1)
247 {
248 bool ret = true;
249 NTSTATUS status;
250 union smb_open io;
251 union smb_close cl;
252 union smb_setfileinfo sinfo;
253 union smb_fileinfo fi;
254 struct smb2_handle h1;
255
256 ZERO_STRUCT(h1);
257
258 smb2_deltree(tree1, BASEDIR);
259 smb2_util_rmdir(tree1, BASEDIR);
260
261 torture_comment(torture, "Creating base directory\n");
262
263 smb2_util_mkdir(tree1, BASEDIR);
264
265
266 torture_comment(torture, "Creating test file\n");
267
268 ZERO_STRUCT(io.smb2);
269 io.generic.level = RAW_OPEN_SMB2;
270 io.smb2.in.create_flags = 0;
271 io.smb2.in.desired_access = 0x0017019f;
272 io.smb2.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
273 io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
274 io.smb2.in.share_access = 0;
275 io.smb2.in.alloc_size = 0;
276 io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
277 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
278 io.smb2.in.security_flags = 0;
279 io.smb2.in.fname = BASEDIR "\\file.txt";
280
281 status = smb2_create(tree1, torture, &(io.smb2));
282 CHECK_STATUS(status, NT_STATUS_OK);
283 h1 = io.smb2.out.file.handle;
284
285 torture_comment(torture, "Renaming test file\n");
286
287 ZERO_STRUCT(sinfo);
288 sinfo.rename_information.level = RAW_SFILEINFO_RENAME_INFORMATION;
289 sinfo.rename_information.in.file.handle = io.smb2.out.file.handle;
290 sinfo.rename_information.in.overwrite = 0;
291 sinfo.rename_information.in.root_fid = 0;
292 sinfo.rename_information.in.new_name =
293 BASEDIR "\\newname.txt";
294 status = smb2_setinfo_file(tree1, &sinfo);
295 CHECK_STATUS(status, NT_STATUS_OK);
296
297 torture_comment(torture, "Checking for new filename\n");
298
299 ZERO_STRUCT(fi);
300 fi.generic.level = RAW_FILEINFO_SMB2_ALL_INFORMATION;
301 fi.generic.in.file.handle = h1;
302 status = smb2_getinfo_file(tree1, torture, &fi);
303 CHECK_STATUS(status, NT_STATUS_OK);
304
305
306 torture_comment(torture, "Closing test file\n");
307
308 ZERO_STRUCT(cl.smb2);
309 cl.smb2.level = RAW_CLOSE_SMB2;
310 cl.smb2.in.file.handle = h1;
311 status = smb2_close(tree1, &(cl.smb2));
312 CHECK_STATUS(status, NT_STATUS_OK);
313
314 ZERO_STRUCT(h1);
315
316 done:
317
318 torture_comment(torture, "Cleaning up\n");
319
320 if (h1.data[0] || h1.data[1]) {
321 ZERO_STRUCT(cl.smb2);
322 cl.smb2.level = RAW_CLOSE_SMB2;
323 cl.smb2.in.file.handle = h1;
324 status = smb2_close(tree1, &(cl.smb2));
325 }
326 smb2_deltree(tree1, BASEDIR);
327 return ret;
328 }
329
330 /*
331 * testing of rename when opening parent dir with delete access and delete
332 * sharing allowed
333 * should result in sharing violation
334 */
335
336 static bool torture_smb2_rename_with_delete_access(struct torture_context *torture,
337 struct smb2_tree *tree1)
338 {
339 bool ret = true;
340 NTSTATUS status;
341 union smb_open io;
342 union smb_close cl;
343 union smb_setfileinfo sinfo;
344 struct smb2_handle fh, dh;
345
346 ZERO_STRUCT(fh);
347 ZERO_STRUCT(dh);
348
349 smb2_deltree(tree1, BASEDIR);
350 smb2_util_rmdir(tree1, BASEDIR);
351
352 torture_comment(torture, "Creating base directory\n");
353
354 smb2_util_mkdir(tree1, BASEDIR);
355
356 torture_comment(torture, "Opening parent directory\n");
357
358 ZERO_STRUCT(io.smb2);
359 io.generic.level = RAW_OPEN_SMB2;
360 io.smb2.in.create_flags = 0;
361 io.smb2.in.desired_access = SEC_STD_SYNCHRONIZE | SEC_STD_WRITE_DAC |
362 SEC_STD_READ_CONTROL | SEC_STD_DELETE | SEC_FILE_WRITE_ATTRIBUTE |
363 SEC_FILE_READ_ATTRIBUTE | SEC_FILE_EXECUTE | SEC_FILE_WRITE_EA |
364 SEC_FILE_READ_EA | SEC_FILE_APPEND_DATA | SEC_FILE_READ_DATA |
365 SEC_FILE_WRITE_DATA;
366 io.smb2.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
367 io.smb2.in.file_attributes = FILE_ATTRIBUTE_DIRECTORY;
368 io.smb2.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
369 NTCREATEX_SHARE_ACCESS_WRITE | NTCREATEX_SHARE_ACCESS_DELETE;
370 io.smb2.in.alloc_size = 0;
371 io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN;
372 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
373 io.smb2.in.security_flags = 0;
374 io.smb2.in.fname = BASEDIR;
375
376 status = smb2_create(tree1, torture, &(io.smb2));
377 CHECK_STATUS(status, NT_STATUS_OK);
378 dh = io.smb2.out.file.handle;
379
380
381 torture_comment(torture, "Creating test file\n");
382
383 ZERO_STRUCT(io.smb2);
384 io.generic.level = RAW_OPEN_SMB2;
385 io.smb2.in.create_flags = 0;
386 io.smb2.in.desired_access = SEC_STD_SYNCHRONIZE | SEC_STD_WRITE_DAC |
387 SEC_STD_READ_CONTROL | SEC_STD_DELETE | SEC_FILE_WRITE_ATTRIBUTE |
388 SEC_FILE_READ_ATTRIBUTE | SEC_FILE_WRITE_EA | SEC_FILE_READ_EA |
389 SEC_FILE_APPEND_DATA | SEC_FILE_READ_DATA | SEC_FILE_WRITE_DATA;
390 io.smb2.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
391 io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
392 io.smb2.in.share_access = 0;
393 io.smb2.in.alloc_size = 0;
394 io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
395 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
396 io.smb2.in.security_flags = 0;
397 io.smb2.in.fname = BASEDIR "\\file.txt";
398
399 status = smb2_create(tree1, torture, &(io.smb2));
400 CHECK_STATUS(status, NT_STATUS_OK);
401 fh = io.smb2.out.file.handle;
402
403 torture_comment(torture, "Renaming test file\n");
404
405 ZERO_STRUCT(sinfo);
406 sinfo.rename_information.level = RAW_SFILEINFO_RENAME_INFORMATION;
407 sinfo.rename_information.in.file.handle = fh;
408 sinfo.rename_information.in.overwrite = 0;
409 sinfo.rename_information.in.root_fid = 0;
410 sinfo.rename_information.in.new_name =
411 BASEDIR "\\newname.txt";
412 status = smb2_setinfo_file(tree1, &sinfo);
413 CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
414
415 torture_comment(torture, "Closing test file\n");
416
417 ZERO_STRUCT(cl.smb2);
418 cl.smb2.level = RAW_CLOSE_SMB2;
419 cl.smb2.in.file.handle = fh;
420 status = smb2_close(tree1, &(cl.smb2));
421 CHECK_STATUS(status, NT_STATUS_OK);
422
423 ZERO_STRUCT(fh);
424
425 torture_comment(torture, "Closing directory\n");
426
427 ZERO_STRUCT(cl.smb2);
428 cl.smb2.level = RAW_CLOSE_SMB2;
429 cl.smb2.in.file.handle = dh;
430 status = smb2_close(tree1, &(cl.smb2));
431 CHECK_STATUS(status, NT_STATUS_OK);
432
433 ZERO_STRUCT(dh);
434
435
436 done:
437
438 torture_comment(torture, "Cleaning up\n");
439
440 if (fh.data[0] || fh.data[1]) {
441 ZERO_STRUCT(cl.smb2);
442 cl.smb2.level = RAW_CLOSE_SMB2;
443 cl.smb2.in.file.handle = fh;
444 status = smb2_close(tree1, &(cl.smb2));
445 }
446 if (dh.data[0] || dh.data[1]) {
447 ZERO_STRUCT(cl.smb2);
448 cl.smb2.level = RAW_CLOSE_SMB2;
449 cl.smb2.in.file.handle = dh;
450 status = smb2_close(tree1, &(cl.smb2));
451 }
452
453 smb2_deltree(tree1, BASEDIR);
454 return ret;
455 }
456
457
458 /*
459 * testing of rename with delete access on parent dir
460 * this is a variation of the test above: parent dir is opened
461 * without share_delete, so rename must fail
462 */
463
464 static bool torture_smb2_rename_with_delete_access2(struct torture_context *torture,
465 struct smb2_tree *tree1)
466 {
467 bool ret = true;
468 NTSTATUS status;
469 union smb_open io;
470 union smb_close cl;
471 union smb_setfileinfo sinfo;
472 struct smb2_handle fh, dh;
473
474 ZERO_STRUCT(fh);
475 ZERO_STRUCT(dh);
476
477 smb2_deltree(tree1, BASEDIR);
478 smb2_util_rmdir(tree1, BASEDIR);
479
480 torture_comment(torture, "Creating base directory\n");
481
482 smb2_util_mkdir(tree1, BASEDIR);
483
484 torture_comment(torture, "Opening parent directory\n");
485
486 ZERO_STRUCT(io.smb2);
487 io.generic.level = RAW_OPEN_SMB2;
488 io.smb2.in.create_flags = 0;
489 io.smb2.in.desired_access = SEC_STD_SYNCHRONIZE | SEC_STD_WRITE_DAC |
490 SEC_STD_READ_CONTROL | SEC_STD_DELETE | SEC_FILE_WRITE_ATTRIBUTE |
491 SEC_FILE_READ_ATTRIBUTE | SEC_FILE_EXECUTE | SEC_FILE_WRITE_EA |
492 SEC_FILE_READ_EA | SEC_FILE_APPEND_DATA | SEC_FILE_READ_DATA |
493 SEC_FILE_WRITE_DATA;
494 io.smb2.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
495 io.smb2.in.file_attributes = FILE_ATTRIBUTE_DIRECTORY;
496 io.smb2.in.share_access = 0;
497 io.smb2.in.alloc_size = 0;
498 io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN;
499 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
500 io.smb2.in.security_flags = 0;
501 io.smb2.in.fname = BASEDIR;
502
503 status = smb2_create(tree1, torture, &(io.smb2));
504 CHECK_STATUS(status, NT_STATUS_OK);
505 dh = io.smb2.out.file.handle;
506
507
508 torture_comment(torture, "Creating test file\n");
509
510 ZERO_STRUCT(io.smb2);
511 io.generic.level = RAW_OPEN_SMB2;
512 io.smb2.in.create_flags = 0;
513 io.smb2.in.desired_access = SEC_STD_SYNCHRONIZE | SEC_STD_WRITE_DAC |
514 SEC_STD_READ_CONTROL | SEC_STD_DELETE | SEC_FILE_WRITE_ATTRIBUTE |
515 SEC_FILE_READ_ATTRIBUTE | SEC_FILE_WRITE_EA | SEC_FILE_READ_EA |
516 SEC_FILE_APPEND_DATA | SEC_FILE_READ_DATA | SEC_FILE_WRITE_DATA;
517 io.smb2.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
518 io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
519 io.smb2.in.share_access = 0;
520 io.smb2.in.alloc_size = 0;
521 io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
522 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
523 io.smb2.in.security_flags = 0;
524 io.smb2.in.fname = BASEDIR "\\file.txt";
525
526 status = smb2_create(tree1, torture, &(io.smb2));
527 CHECK_STATUS(status, NT_STATUS_OK);
528 fh = io.smb2.out.file.handle;
529
530 torture_comment(torture, "Renaming test file\n");
531
532 ZERO_STRUCT(sinfo);
533 sinfo.rename_information.level = RAW_SFILEINFO_RENAME_INFORMATION;
534 sinfo.rename_information.in.file.handle = fh;
535 sinfo.rename_information.in.overwrite = 0;
536 sinfo.rename_information.in.root_fid = 0;
537 sinfo.rename_information.in.new_name =
538 BASEDIR "\\newname.txt";
539 status = smb2_setinfo_file(tree1, &sinfo);
540 CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
541
542 torture_comment(torture, "Closing test file\n");
543
544 ZERO_STRUCT(cl.smb2);
545 cl.smb2.level = RAW_CLOSE_SMB2;
546 cl.smb2.in.file.handle = fh;
547 status = smb2_close(tree1, &(cl.smb2));
548 CHECK_STATUS(status, NT_STATUS_OK);
549
550 ZERO_STRUCT(fh);
551
552 torture_comment(torture, "Closing directory\n");
553
554 ZERO_STRUCT(cl.smb2);
555 cl.smb2.level = RAW_CLOSE_SMB2;
556 cl.smb2.in.file.handle = dh;
557 status = smb2_close(tree1, &(cl.smb2));
558 CHECK_STATUS(status, NT_STATUS_OK);
559
560 ZERO_STRUCT(dh);
561
562
563 done:
564
565 torture_comment(torture, "Cleaning up\n");
566
567 if (fh.data[0] || fh.data[1]) {
568 ZERO_STRUCT(cl.smb2);
569 cl.smb2.level = RAW_CLOSE_SMB2;
570 cl.smb2.in.file.handle = fh;
571 status = smb2_close(tree1, &(cl.smb2));
572 }
573 if (dh.data[0] || dh.data[1]) {
574 ZERO_STRUCT(cl.smb2);
575 cl.smb2.level = RAW_CLOSE_SMB2;
576 cl.smb2.in.file.handle = dh;
577 status = smb2_close(tree1, &(cl.smb2));
578 }
579
580 smb2_deltree(tree1, BASEDIR);
581 return ret;
582 }
583
584 /*
585 * testing of rename when opening parent dir with no delete access and delete
586 * sharing allowed
587 * this should pass
588 */
589
590 static bool torture_smb2_rename_no_delete_access(struct torture_context *torture,
591 struct smb2_tree *tree1)
592 {
593 bool ret = true;
594 NTSTATUS status;
595 union smb_open io;
596 union smb_close cl;
597 union smb_setfileinfo sinfo;
598 union smb_fileinfo fi;
599 struct smb2_handle fh, dh;
600
601 ZERO_STRUCT(fh);
602 ZERO_STRUCT(dh);
603
604 smb2_deltree(tree1, BASEDIR);
605 smb2_util_rmdir(tree1, BASEDIR);
606
607 torture_comment(torture, "Creating base directory\n");
608
609 smb2_util_mkdir(tree1, BASEDIR);
610
611 torture_comment(torture, "Opening parent directory\n");
612
613 ZERO_STRUCT(io.smb2);
614 io.generic.level = RAW_OPEN_SMB2;
615 io.smb2.in.create_flags = 0;
616 io.smb2.in.desired_access = SEC_STD_SYNCHRONIZE | SEC_STD_WRITE_DAC |
617 SEC_STD_READ_CONTROL | SEC_FILE_WRITE_ATTRIBUTE |
618 SEC_FILE_READ_ATTRIBUTE | SEC_FILE_EXECUTE | SEC_FILE_WRITE_EA |
619 SEC_FILE_READ_EA | SEC_FILE_APPEND_DATA | SEC_FILE_READ_DATA |
620 SEC_FILE_WRITE_DATA;
621 io.smb2.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
622 io.smb2.in.file_attributes = FILE_ATTRIBUTE_DIRECTORY;
623 io.smb2.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
624 NTCREATEX_SHARE_ACCESS_WRITE | NTCREATEX_SHARE_ACCESS_DELETE;
625 io.smb2.in.alloc_size = 0;
626 io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN;
627 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
628 io.smb2.in.security_flags = 0;
629 io.smb2.in.fname = BASEDIR;
630
631 status = smb2_create(tree1, torture, &(io.smb2));
632 CHECK_STATUS(status, NT_STATUS_OK);
633 dh = io.smb2.out.file.handle;
634
635
636 torture_comment(torture, "Creating test file\n");
637
638 ZERO_STRUCT(io.smb2);
639 io.generic.level = RAW_OPEN_SMB2;
640 io.smb2.in.create_flags = 0;
641 io.smb2.in.desired_access = SEC_STD_SYNCHRONIZE | SEC_STD_WRITE_DAC |
642 SEC_STD_READ_CONTROL | SEC_STD_DELETE | SEC_FILE_WRITE_ATTRIBUTE |
643 SEC_FILE_READ_ATTRIBUTE | SEC_FILE_WRITE_EA | SEC_FILE_READ_EA |
644 SEC_FILE_APPEND_DATA | SEC_FILE_READ_DATA | SEC_FILE_WRITE_DATA;
645 io.smb2.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
646 io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
647 io.smb2.in.share_access = 0;
648 io.smb2.in.alloc_size = 0;
649 io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
650 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
651 io.smb2.in.security_flags = 0;
652 io.smb2.in.fname = BASEDIR "\\file.txt";
653
654 status = smb2_create(tree1, torture, &(io.smb2));
655 CHECK_STATUS(status, NT_STATUS_OK);
656 fh = io.smb2.out.file.handle;
657
658 torture_comment(torture, "Renaming test file\n");
659
660 ZERO_STRUCT(sinfo);
661 sinfo.rename_information.level = RAW_SFILEINFO_RENAME_INFORMATION;
662 sinfo.rename_information.in.file.handle = fh;
663 sinfo.rename_information.in.overwrite = 0;
664 sinfo.rename_information.in.root_fid = 0;
665 sinfo.rename_information.in.new_name =
666 BASEDIR "\\newname.txt";
667 status = smb2_setinfo_file(tree1, &sinfo);
668 CHECK_STATUS(status, NT_STATUS_OK);
669
670 torture_comment(torture, "Checking for new filename\n");
671
672 ZERO_STRUCT(fi);
673 fi.generic.level = RAW_FILEINFO_SMB2_ALL_INFORMATION;
674 fi.generic.in.file.handle = fh;
675 status = smb2_getinfo_file(tree1, torture, &fi);
676 CHECK_STATUS(status, NT_STATUS_OK);
677
678
679 torture_comment(torture, "Closing test file\n");
680
681 ZERO_STRUCT(cl.smb2);
682 cl.smb2.level = RAW_CLOSE_SMB2;
683 cl.smb2.in.file.handle = fh;
684 status = smb2_close(tree1, &(cl.smb2));
685 CHECK_STATUS(status, NT_STATUS_OK);
686
687 ZERO_STRUCT(fh);
688
689 torture_comment(torture, "Closing directory\n");
690
691 ZERO_STRUCT(cl.smb2);
692 cl.smb2.level = RAW_CLOSE_SMB2;
693 cl.smb2.in.file.handle = dh;
694 status = smb2_close(tree1, &(cl.smb2));
695 CHECK_STATUS(status, NT_STATUS_OK);
696
697 ZERO_STRUCT(dh);
698
699
700 done:
701
702 torture_comment(torture, "Cleaning up\n");
703
704 if (fh.data[0] || fh.data[1]) {
705 ZERO_STRUCT(cl.smb2);
706 cl.smb2.level = RAW_CLOSE_SMB2;
707 cl.smb2.in.file.handle = fh;
708 status = smb2_close(tree1, &(cl.smb2));
709 }
710 if (dh.data[0] || dh.data[1]) {
711 ZERO_STRUCT(cl.smb2);
712 cl.smb2.level = RAW_CLOSE_SMB2;
713 cl.smb2.in.file.handle = dh;
714 status = smb2_close(tree1, &(cl.smb2));
715 }
716
717 smb2_deltree(tree1, BASEDIR);
718 return ret;
719 }
720
721
722 /*
723 * testing of rename with no delete access on parent dir
724 * this is the negative case of the test above: parent dir is opened
725 * without share_delete, so rename must fail
726 */
727
728 static bool torture_smb2_rename_no_delete_access2(struct torture_context *torture,
729 struct smb2_tree *tree1)
730 {
731 bool ret = true;
732 NTSTATUS status;
733 union smb_open io;
734 union smb_close cl;
735 union smb_setfileinfo sinfo;
736 struct smb2_handle fh, dh;
737
738 ZERO_STRUCT(fh);
739 ZERO_STRUCT(dh);
740
741 smb2_deltree(tree1, BASEDIR);
742 smb2_util_rmdir(tree1, BASEDIR);
743
744 torture_comment(torture, "Creating base directory\n");
745
746 smb2_util_mkdir(tree1, BASEDIR);
747
748 torture_comment(torture, "Opening parent directory\n");
749
750 ZERO_STRUCT(io.smb2);
751 io.generic.level = RAW_OPEN_SMB2;
752 io.smb2.in.create_flags = 0;
753 io.smb2.in.desired_access = SEC_STD_SYNCHRONIZE | SEC_STD_WRITE_DAC |
754 SEC_STD_READ_CONTROL | SEC_FILE_WRITE_ATTRIBUTE |
755 SEC_FILE_READ_ATTRIBUTE | SEC_FILE_EXECUTE | SEC_FILE_WRITE_EA |
756 SEC_FILE_READ_EA | SEC_FILE_APPEND_DATA | SEC_FILE_READ_DATA |
757 SEC_FILE_WRITE_DATA;
758 io.smb2.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
759 io.smb2.in.file_attributes = FILE_ATTRIBUTE_DIRECTORY;
760 io.smb2.in.share_access = 0;
761 io.smb2.in.alloc_size = 0;
762 io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN;
763 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
764 io.smb2.in.security_flags = 0;
765 io.smb2.in.fname = BASEDIR;
766
767 status = smb2_create(tree1, torture, &(io.smb2));
768 CHECK_STATUS(status, NT_STATUS_OK);
769 dh = io.smb2.out.file.handle;
770
771
772 torture_comment(torture, "Creating test file\n");
773
774 ZERO_STRUCT(io.smb2);
775 io.generic.level = RAW_OPEN_SMB2;
776 io.smb2.in.create_flags = 0;
777 io.smb2.in.desired_access = SEC_STD_SYNCHRONIZE | SEC_STD_WRITE_DAC |
778 SEC_STD_READ_CONTROL | SEC_STD_DELETE | SEC_FILE_WRITE_ATTRIBUTE |
779 SEC_FILE_READ_ATTRIBUTE | SEC_FILE_WRITE_EA | SEC_FILE_READ_EA |
780 SEC_FILE_APPEND_DATA | SEC_FILE_READ_DATA | SEC_FILE_WRITE_DATA;
781 io.smb2.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
782 io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
783 io.smb2.in.share_access = 0;
784 io.smb2.in.alloc_size = 0;
785 io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
786 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
787 io.smb2.in.security_flags = 0;
788 io.smb2.in.fname = BASEDIR "\\file.txt";
789
790 status = smb2_create(tree1, torture, &(io.smb2));
791 CHECK_STATUS(status, NT_STATUS_OK);
792 fh = io.smb2.out.file.handle;
793
794 torture_comment(torture, "Renaming test file\n");
795
796 ZERO_STRUCT(sinfo);
797 sinfo.rename_information.level = RAW_SFILEINFO_RENAME_INFORMATION;
798 sinfo.rename_information.in.file.handle = fh;
799 sinfo.rename_information.in.overwrite = 0;
800 sinfo.rename_information.in.root_fid = 0;
801 sinfo.rename_information.in.new_name =
802 BASEDIR "\\newname.txt";
803 status = smb2_setinfo_file(tree1, &sinfo);
804 CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
805
806 torture_comment(torture, "Closing test file\n");
807
808 ZERO_STRUCT(cl.smb2);
809 cl.smb2.level = RAW_CLOSE_SMB2;
810 cl.smb2.in.file.handle = fh;
811 status = smb2_close(tree1, &(cl.smb2));
812 CHECK_STATUS(status, NT_STATUS_OK);
813
814 ZERO_STRUCT(fh);
815
816 torture_comment(torture, "Closing directory\n");
817
818 ZERO_STRUCT(cl.smb2);
819 cl.smb2.level = RAW_CLOSE_SMB2;
820 cl.smb2.in.file.handle = dh;
821 status = smb2_close(tree1, &(cl.smb2));
822 CHECK_STATUS(status, NT_STATUS_OK);
823
824 ZERO_STRUCT(dh);
825
826
827 done:
828
829 torture_comment(torture, "Cleaning up\n");
830
831 if (fh.data[0] || fh.data[1]) {
832 ZERO_STRUCT(cl.smb2);
833 cl.smb2.level = RAW_CLOSE_SMB2;
834 cl.smb2.in.file.handle = fh;
835 status = smb2_close(tree1, &(cl.smb2));
836 }
837 if (dh.data[0] || dh.data[1]) {
838 ZERO_STRUCT(cl.smb2);
839 cl.smb2.level = RAW_CLOSE_SMB2;
840 cl.smb2.in.file.handle = dh;
841 status = smb2_close(tree1, &(cl.smb2));
842 }
843
844 smb2_deltree(tree1, BASEDIR);
845 return ret;
846 }
847
848 /*
849 * this is a replay of how Word 2010 saves a file
850 * this should pass
851 */
852
853 static bool torture_smb2_rename_msword(struct torture_context *torture,
854 struct smb2_tree *tree1)
855 {
856 bool ret = true;
857 NTSTATUS status;
858 union smb_open io;
859 union smb_close cl;
860 union smb_setfileinfo sinfo;
861 union smb_fileinfo fi;
862 struct smb2_handle fh, dh;
863
864 ZERO_STRUCT(fh);
865 ZERO_STRUCT(dh);
866
867 smb2_deltree(tree1, BASEDIR);
868 smb2_util_rmdir(tree1, BASEDIR);
869
870 torture_comment(torture, "Creating base directory\n");
871
872 smb2_util_mkdir(tree1, BASEDIR);
873
874 torture_comment(torture, "Creating test file\n");
875
876 ZERO_STRUCT(io.smb2);
877 io.generic.level = RAW_OPEN_SMB2;
878 io.smb2.in.create_flags = 0;
879 io.smb2.in.desired_access = 0x0017019f;
880 io.smb2.in.create_options = 0x60;
881 io.smb2.in.file_attributes = 0;
882 io.smb2.in.share_access = 0;
883 io.smb2.in.alloc_size = 0;
884 io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
885 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
886 io.smb2.in.security_flags = 0;
887 io.smb2.in.fname = BASEDIR "\\file.txt";
888
889 status = smb2_create(tree1, torture, &(io.smb2));
890 CHECK_STATUS(status, NT_STATUS_OK);
891 fh = io.smb2.out.file.handle;
892
893 torture_comment(torture, "Opening parent directory\n");
894
895 ZERO_STRUCT(io.smb2);
896 io.generic.level = RAW_OPEN_SMB2;
897 io.smb2.in.create_flags = 0;
898 io.smb2.in.desired_access = 0x00100080;
899 io.smb2.in.create_options = 0x00800021;
900 io.smb2.in.file_attributes = 0;
901 io.smb2.in.share_access = 0;
902 io.smb2.in.alloc_size = 0;
903 io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN;
904 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
905 io.smb2.in.security_flags = 0;
906 io.smb2.in.fname = BASEDIR;
907
908 status = smb2_create(tree1, torture, &(io.smb2));
909 CHECK_STATUS(status, NT_STATUS_OK);
910 dh = io.smb2.out.file.handle;
911
912 torture_comment(torture, "Renaming test file\n");
913
914 ZERO_STRUCT(sinfo);
915 sinfo.rename_information.level = RAW_SFILEINFO_RENAME_INFORMATION;
916 sinfo.rename_information.in.file.handle = fh;
917 sinfo.rename_information.in.overwrite = 0;
918 sinfo.rename_information.in.root_fid = 0;
919 sinfo.rename_information.in.new_name =
920 BASEDIR "\\newname.txt";
921 status = smb2_setinfo_file(tree1, &sinfo);
922 CHECK_STATUS(status, NT_STATUS_OK);
923
924 torture_comment(torture, "Checking for new filename\n");
925
926 ZERO_STRUCT(fi);
927 fi.generic.level = RAW_FILEINFO_SMB2_ALL_INFORMATION;
928 fi.generic.in.file.handle = fh;
929 status = smb2_getinfo_file(tree1, torture, &fi);
930 CHECK_STATUS(status, NT_STATUS_OK);
931
932
933 torture_comment(torture, "Closing test file\n");
934
935 ZERO_STRUCT(cl.smb2);
936 cl.smb2.level = RAW_CLOSE_SMB2;
937 cl.smb2.in.file.handle = fh;
938 status = smb2_close(tree1, &(cl.smb2));
939 CHECK_STATUS(status, NT_STATUS_OK);
940
941 ZERO_STRUCT(fh);
942
943 torture_comment(torture, "Closing directory\n");
944
945 ZERO_STRUCT(cl.smb2);
946 cl.smb2.level = RAW_CLOSE_SMB2;
947 cl.smb2.in.file.handle = dh;
948 status = smb2_close(tree1, &(cl.smb2));
949 CHECK_STATUS(status, NT_STATUS_OK);
950
951 ZERO_STRUCT(dh);
952
953
954 done:
955
956 torture_comment(torture, "Cleaning up\n");
957
958 if (fh.data[0] || fh.data[1]) {
959 ZERO_STRUCT(cl.smb2);
960 cl.smb2.level = RAW_CLOSE_SMB2;
961 cl.smb2.in.file.handle = fh;
962 status = smb2_close(tree1, &(cl.smb2));
963 }
964 if (dh.data[0] || dh.data[1]) {
965 ZERO_STRUCT(cl.smb2);
966 cl.smb2.level = RAW_CLOSE_SMB2;
967 cl.smb2.in.file.handle = dh;
968 status = smb2_close(tree1, &(cl.smb2));
969 }
970
971 smb2_deltree(tree1, BASEDIR);
972 return ret;
973 }
974
975 static bool torture_smb2_rename_dir_openfile(struct torture_context *torture,
976 struct smb2_tree *tree1)
977 {
978 bool ret = true;
979 NTSTATUS status;
980 union smb_open io;
981 union smb_close cl;
982 union smb_setfileinfo sinfo;
983 struct smb2_handle d1, h1;
984
985 ZERO_STRUCT(d1);
986 ZERO_STRUCT(h1);
987
988 smb2_deltree(tree1, BASEDIR);
989 smb2_util_rmdir(tree1, BASEDIR);
990
991 torture_comment(torture, "Creating base directory\n");
992
993 ZERO_STRUCT(io.smb2);
994 io.generic.level = RAW_OPEN_SMB2;
995 io.smb2.in.create_flags = 0;
996 io.smb2.in.desired_access = 0x0017019f;
997 io.smb2.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
998 io.smb2.in.file_attributes = FILE_ATTRIBUTE_DIRECTORY;
999 io.smb2.in.share_access = 0;
1000 io.smb2.in.alloc_size = 0;
1001 io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
1002 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
1003 io.smb2.in.security_flags = 0;
1004 io.smb2.in.fname = BASEDIR;
1005
1006 status = smb2_create(tree1, torture, &(io.smb2));
1007 CHECK_STATUS(status, NT_STATUS_OK);
1008 d1 = io.smb2.out.file.handle;
1009
1010 torture_comment(torture, "Creating test file\n");
1011
1012 ZERO_STRUCT(io.smb2);
1013 io.generic.level = RAW_OPEN_SMB2;
1014 io.smb2.in.create_flags = 0;
1015 io.smb2.in.desired_access = 0x0017019f;
1016 io.smb2.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
1017 io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
1018 io.smb2.in.share_access = 0;
1019 io.smb2.in.alloc_size = 0;
1020 io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
1021 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
1022 io.smb2.in.security_flags = 0;
1023 io.smb2.in.fname = BASEDIR "\\file.txt";
1024
1025 status = smb2_create(tree1, torture, &(io.smb2));
1026 CHECK_STATUS(status, NT_STATUS_OK);
1027 h1 = io.smb2.out.file.handle;
1028
1029 torture_comment(torture, "Renaming directory\n");
1030
1031 ZERO_STRUCT(sinfo);
1032 sinfo.rename_information.level = RAW_SFILEINFO_RENAME_INFORMATION;
1033 sinfo.rename_information.in.file.handle = d1;
1034 sinfo.rename_information.in.overwrite = 0;
1035 sinfo.rename_information.in.root_fid = 0;
1036 sinfo.rename_information.in.new_name =
1037 BASEDIR "-new";
1038 status = smb2_setinfo_file(tree1, &sinfo);
1039 CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
1040
1041 torture_comment(torture, "Closing directory\n");
1042
1043 ZERO_STRUCT(cl.smb2);
1044 cl.smb2.level = RAW_CLOSE_SMB2;
1045 cl.smb2.in.file.handle = d1;
1046 status = smb2_close(tree1, &(cl.smb2));
1047 CHECK_STATUS(status, NT_STATUS_OK);
1048 ZERO_STRUCT(d1);
1049
1050 torture_comment(torture, "Closing test file\n");
1051
1052 cl.smb2.in.file.handle = h1;
1053 status = smb2_close(tree1, &(cl.smb2));
1054 CHECK_STATUS(status, NT_STATUS_OK);
1055 ZERO_STRUCT(h1);
1056
1057 done:
1058
1059 torture_comment(torture, "Cleaning up\n");
1060
1061 if (h1.data[0] || h1.data[1]) {
1062 ZERO_STRUCT(cl.smb2);
1063 cl.smb2.level = RAW_CLOSE_SMB2;
1064 cl.smb2.in.file.handle = h1;
1065 status = smb2_close(tree1, &(cl.smb2));
1066 }
1067 smb2_deltree(tree1, BASEDIR);
1068 return ret;
1069 }
1070
1071 struct rename_one_dir_cycle_state {
1072 struct tevent_context *ev;
1073 struct smb2_tree *tree;
1074 struct smb2_handle file;
1075 const char *base_name;
1076 char *new_name;
1077 unsigned *rename_counter;
1078
1079 unsigned current;
1080 unsigned max;
1081 union smb_setfileinfo sinfo;
1082 };
1083
1084 static void rename_one_dir_cycle_done(struct smb2_request *subreq);
1085
1086 static struct tevent_req *rename_one_dir_cycle_send(TALLOC_CTX *mem_ctx,
1087 struct tevent_context *ev,
1088 struct smb2_tree *tree,
1089 struct smb2_handle file,
1090 unsigned max_renames,
1091 const char *base_name,
1092 unsigned *rename_counter)
1093 {
1094 struct tevent_req *req;
1095 struct rename_one_dir_cycle_state *state;
1096 struct smb2_request *subreq;
1097
1098 req = tevent_req_create(mem_ctx, &state,
1099 struct rename_one_dir_cycle_state);
1100 if (req == NULL) {
1101 return NULL;
1102 }
1103 state->ev = ev;
1104 state->tree = tree;
1105 state->file = file;
1106 state->base_name = base_name;
1107 state->rename_counter = rename_counter;
1108 state->current = 0;
1109 state->max = max_renames;
1110
1111 ZERO_STRUCT(state->sinfo);
1112 state->sinfo.rename_information.level =
1113 RAW_SFILEINFO_RENAME_INFORMATION;
1114 state->sinfo.rename_information.in.file.handle = state->file;
1115 state->sinfo.rename_information.in.overwrite = 0;
1116 state->sinfo.rename_information.in.root_fid = 0;
1117
1118 state->new_name = talloc_asprintf(
1119 state, "%s-%u", state->base_name, state->current);
1120 if (tevent_req_nomem(state->new_name, req)) {
1121 return tevent_req_post(req, ev);
1122 }
1123 state->sinfo.rename_information.in.new_name = state->new_name;
1124
1125 subreq = smb2_setinfo_file_send(state->tree, &state->sinfo);
1126 if (tevent_req_nomem(subreq, req)) {
1127 return tevent_req_post(req, ev);
1128 }
1129 subreq->async.fn = rename_one_dir_cycle_done;
1130 subreq->async.private_data = req;
1131 return req;
1132 }
1133
1134 static void rename_one_dir_cycle_done(struct smb2_request *subreq)
1135 {
1136 struct tevent_req *req = talloc_get_type_abort(
1137 subreq->async.private_data, struct tevent_req);
1138 struct rename_one_dir_cycle_state *state = tevent_req_data(
1139 req, struct rename_one_dir_cycle_state);
1140 NTSTATUS status;
1141
1142 status = smb2_setinfo_recv(subreq);
1143 if (tevent_req_nterror(req, status)) {
1144 return;
1145 }
1146 TALLOC_FREE(state->new_name);
1147
1148 *state->rename_counter += 1;
1149
1150 state->current += 1;
1151 if (state->current >= state->max) {
1152 tevent_req_done(req);
1153 return;
1154 }
1155
1156 ZERO_STRUCT(state->sinfo);
1157 state->sinfo.rename_information.level =
1158 RAW_SFILEINFO_RENAME_INFORMATION;
1159 state->sinfo.rename_information.in.file.handle = state->file;
1160 state->sinfo.rename_information.in.overwrite = 0;
1161 state->sinfo.rename_information.in.root_fid = 0;
1162
1163 state->new_name = talloc_asprintf(
1164 state, "%s-%u", state->base_name, state->current);
1165 if (tevent_req_nomem(state->new_name, req)) {
1166 return;
1167 }
1168 state->sinfo.rename_information.in.new_name = state->new_name;
1169
1170 subreq = smb2_setinfo_file_send(state->tree, &state->sinfo);
1171 if (tevent_req_nomem(subreq, req)) {
1172 return;
1173 }
1174 subreq->async.fn = rename_one_dir_cycle_done;
1175 subreq->async.private_data = req;
1176 }
1177
1178 static NTSTATUS rename_one_dir_cycle_recv(struct tevent_req *req)
1179 {
1180 return tevent_req_simple_recv_ntstatus(req);
1181 }
1182
1183 struct rename_dir_bench_state {
1184 struct tevent_context *ev;
1185 struct smb2_tree *tree;
1186 const char *base_name;
1187 unsigned max_renames;
1188 unsigned *rename_counter;
1189
1190 struct smb2_create io;
1191 union smb_setfileinfo sinfo;
1192 struct smb2_close cl;
1193
1194 struct smb2_handle file;
1195 };
1196
1197 static void rename_dir_bench_opened(struct smb2_request *subreq);
1198 static void rename_dir_bench_renamed(struct tevent_req *subreq);
1199 static void rename_dir_bench_set_doc(struct smb2_request *subreq);
1200 static void rename_dir_bench_closed(struct smb2_request *subreq);
1201
1202 static struct tevent_req *rename_dir_bench_send(TALLOC_CTX *mem_ctx,
1203 struct tevent_context *ev,
1204 struct smb2_tree *tree,
1205 const char *base_name,
1206 unsigned max_renames,
1207 unsigned *rename_counter)
1208 {
1209 struct tevent_req *req;
1210 struct rename_dir_bench_state *state;
1211 struct smb2_request *subreq;
1212
1213 req = tevent_req_create(mem_ctx, &state,
1214 struct rename_dir_bench_state);
1215 if (req == NULL) {
1216 return NULL;
1217 }
1218 state->ev = ev;
1219 state->tree = tree;
1220 state->base_name = base_name;
1221 state->max_renames = max_renames;
1222 state->rename_counter = rename_counter;
1223
1224 ZERO_STRUCT(state->io);
1225 state->io.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED;
1226 state->io.in.share_access =
1227 NTCREATEX_SHARE_ACCESS_READ|
1228 NTCREATEX_SHARE_ACCESS_WRITE;
1229 state->io.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1230 state->io.in.file_attributes = FILE_ATTRIBUTE_DIRECTORY;
1231 state->io.in.create_disposition = NTCREATEX_DISP_OPEN_IF;
1232 state->io.in.fname = state->base_name;
1233
1234 subreq = smb2_create_send(state->tree, &state->io);
1235 if (tevent_req_nomem(subreq, req)) {
1236 return tevent_req_post(req, ev);
1237 }
1238 subreq->async.fn = rename_dir_bench_opened;
1239 subreq->async.private_data = req;
1240 return req;
1241 }
1242
1243 static void rename_dir_bench_opened(struct smb2_request *subreq)
1244 {
1245 struct tevent_req *req = talloc_get_type_abort(
1246 subreq->async.private_data, struct tevent_req);
1247 struct rename_dir_bench_state *state = tevent_req_data(
1248 req, struct rename_dir_bench_state);
1249 struct smb2_create *io;
1250 struct tevent_req *subreq2;
1251 NTSTATUS status;
1252
1253 io = talloc(state, struct smb2_create);
1254 if (tevent_req_nomem(io, req)) {
1255 return;
1256 }
1257
1258 status = smb2_create_recv(subreq, io, io);
1259 if (tevent_req_nterror(req, status)) {
1260 return;
1261 }
1262 state->file = io->out.file.handle;
1263 TALLOC_FREE(io);
1264
1265 subreq2 = rename_one_dir_cycle_send(
1266 state, state->ev, state->tree, state->file,
1267 state->max_renames, state->base_name,
1268 state->rename_counter);
1269 if (tevent_req_nomem(subreq2, req)) {
1270 return;
1271 }
1272 tevent_req_set_callback(subreq2, rename_dir_bench_renamed, req);
1273 }
1274
1275 static void rename_dir_bench_renamed(struct tevent_req *subreq)
1276 {
1277 struct tevent_req *req = tevent_req_callback_data(
1278 subreq, struct tevent_req);
1279 struct rename_dir_bench_state *state = tevent_req_data(
1280 req, struct rename_dir_bench_state);
1281 struct smb2_request *subreq2;
1282 NTSTATUS status;
1283
1284 status = rename_one_dir_cycle_recv(subreq);
1285 TALLOC_FREE(subreq);
1286 if (tevent_req_nterror(req, status)) {
1287 return;
1288 }
1289
1290 ZERO_STRUCT(state->sinfo);
1291 state->sinfo.disposition_info.level =
1292 RAW_SFILEINFO_DISPOSITION_INFORMATION;
1293 state->sinfo.disposition_info.in.file.handle = state->file;
1294 state->sinfo.disposition_info.in.delete_on_close = true;
1295
1296 subreq2 = smb2_setinfo_file_send(state->tree, &state->sinfo);
1297 if (tevent_req_nomem(subreq2, req)) {
1298 return;
1299 }
1300 subreq2->async.fn = rename_dir_bench_set_doc;
1301 subreq2->async.private_data = req;
1302 }
1303
1304 static void rename_dir_bench_set_doc(struct smb2_request *subreq)
1305 {
1306 struct tevent_req *req = talloc_get_type_abort(
1307 subreq->async.private_data, struct tevent_req);
1308 struct rename_dir_bench_state *state = tevent_req_data(
1309 req, struct rename_dir_bench_state);
1310 NTSTATUS status;
1311
1312 status = smb2_setinfo_recv(subreq);
1313 if (tevent_req_nterror(req, status)) {
1314 return;
1315 }
1316
1317 ZERO_STRUCT(state->cl);
1318 state->cl.in.file.handle = state->file;
1319
1320 subreq = smb2_close_send(state->tree, &state->cl);
1321 if (tevent_req_nomem(subreq, req)) {
1322 return;
1323 }
1324 subreq->async.fn = rename_dir_bench_closed;
1325 subreq->async.private_data = req;
1326 }
1327
1328 static void rename_dir_bench_closed(struct smb2_request *subreq)
1329 {
1330 struct tevent_req *req = talloc_get_type_abort(
1331 subreq->async.private_data, struct tevent_req);
1332 struct smb2_close cl;
1333 NTSTATUS status;
1334
1335 status = smb2_close_recv(subreq, &cl);
1336 if (tevent_req_nterror(req, status)) {
1337 return;
1338 }
1339 tevent_req_done(req);
1340 }
1341
1342 static NTSTATUS rename_dir_bench_recv(struct tevent_req *req)
1343 {
1344 return tevent_req_simple_recv_ntstatus(req);
1345 }
1346
1347 struct rename_dirs_bench_state {
1348 unsigned num_reqs;
1349 unsigned num_done;
1350 };
1351
1352 static void rename_dirs_bench_done(struct tevent_req *subreq);
1353
1354 static struct tevent_req *rename_dirs_bench_send(TALLOC_CTX *mem_ctx,
1355 struct tevent_context *ev,
1356 struct smb2_tree *tree,
1357 const char *base_name,
1358 unsigned num_parallel,
1359 unsigned max_renames,
1360 unsigned *rename_counter)
1361 {
1362 struct tevent_req *req;
1363 struct rename_dirs_bench_state *state;
1364 unsigned i;
1365
1366 req = tevent_req_create(mem_ctx, &state,
1367 struct rename_dirs_bench_state);
1368 if (req == NULL) {
1369 return NULL;
1370 }
1371 state->num_reqs = num_parallel;
1372 state->num_done = 0;
1373
1374 for (i=0; i<num_parallel; i++) {
1375 struct tevent_req *subreq;
1376 char *sub_base;
1377
1378 sub_base = talloc_asprintf(state, "%s-%u", base_name, i);
1379 if (tevent_req_nomem(sub_base, req)) {
1380 return tevent_req_post(req, ev);
1381 }
1382
1383 subreq = rename_dir_bench_send(state, ev, tree, sub_base,
1384 max_renames, rename_counter);
1385 if (tevent_req_nomem(subreq, req)) {
1386 return tevent_req_post(req, ev);
1387 }
1388 tevent_req_set_callback(subreq, rename_dirs_bench_done, req);
1389 }
1390 return req;
1391 }
1392
1393 static void rename_dirs_bench_done(struct tevent_req *subreq)
1394 {
1395 struct tevent_req *req = tevent_req_callback_data(
1396 subreq, struct tevent_req);
1397 struct rename_dirs_bench_state *state = tevent_req_data(
1398 req, struct rename_dirs_bench_state);
1399 NTSTATUS status;
1400
1401 status = rename_dir_bench_recv(subreq);
1402 TALLOC_FREE(subreq);
1403 if (tevent_req_nterror(req, status)) {
1404 return;
1405 }
1406
1407 state->num_done += 1;
1408 if (state->num_done >= state->num_reqs) {
1409 tevent_req_done(req);
1410 }
1411 }
1412
1413 static NTSTATUS rename_dirs_bench_recv(struct tevent_req *req)
1414 {
1415 return tevent_req_simple_recv_ntstatus(req);
1416 }
1417
1418 static bool torture_smb2_rename_dir_bench(struct torture_context *tctx,
1419 struct smb2_tree *tree)
1420 {
1421 struct tevent_req *req;
1422 NTSTATUS status;
1423 unsigned counter = 0;
1424 bool ret;
1425
1426 req = rename_dirs_bench_send(tctx, tctx->ev, tree, "dir", 3, 10,
1427 &counter);
1428 torture_assert(tctx, req != NULL, "rename_dirs_bench_send failed");
1429
1430 ret = tevent_req_poll(req, tctx->ev);
1431 torture_assert(tctx, ret, "tevent_req_poll failed");
1432
1433 status = rename_dirs_bench_recv(req);
1434 torture_comment(tctx, "rename_dirs_bench returned %s\n",
1435 nt_errstr(status));
1436 TALLOC_FREE(req);
1437 torture_assert_ntstatus_ok(tctx, status, "bench failed");
1438 return true;
1439 }
1440
1441 /*
1442 * This test basically verifies that modify and change timestamps are preserved
1443 * after file rename with outstanding open file handles.
1444 */
1445
1446 static bool torture_smb2_rename_simple_modtime(
1447 struct torture_context *torture,
1448 struct smb2_tree *tree1)
1449 {
1450 struct smb2_create c1, c2;
1451 union smb_fileinfo gi;
1452 union smb_setfileinfo si;
1453 struct smb2_handle h1 = {{0}};
1454 struct smb2_handle h2 = {{0}};
1455 NTSTATUS status;
1456 bool ret = true;
1457
1458 smb2_deltree(tree1, BASEDIR);
1459 smb2_util_mkdir(tree1, BASEDIR);
1460
1461 torture_comment(torture, "Creating test file: file1.txt\n");
1462
1463 c1 = (struct smb2_create) {
1464 .in.desired_access = SEC_FILE_ALL|SEC_STD_DELETE,
1465 .in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE,
1466 .in.file_attributes = FILE_ATTRIBUTE_NORMAL,
1467 .in.share_access = NTCREATEX_SHARE_ACCESS_MASK,
1468 .in.create_disposition = NTCREATEX_DISP_CREATE,
1469 .in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS,
1470 .in.fname = BASEDIR "\\file1.txt",
1471 };
1472
1473 status = smb2_create(tree1, torture, &c1);
1474 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
1475 "smb2_create failed\n");
1476 h1 = c1.out.file.handle;
1477
1478 torture_comment(torture, "Waitig for 5 secs..\n");
1479 sleep(5);
1480
1481 torture_comment(torture, "Creating test file: file2.txt\n");
1482
1483 c2 = (struct smb2_create) {
1484 .in.desired_access = SEC_FILE_ALL|SEC_STD_DELETE,
1485 .in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE,
1486 .in.file_attributes = FILE_ATTRIBUTE_NORMAL,
1487 .in.share_access = NTCREATEX_SHARE_ACCESS_MASK,
1488 .in.create_disposition = NTCREATEX_DISP_CREATE,
1489 .in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS,
1490 .in.fname = BASEDIR "\\file2.txt",
1491 };
1492
1493 status = smb2_create(tree1, torture, &c2);
1494 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
1495 "smb2_create failed\n");
1496 h2 = c2.out.file.handle;
1497
1498 torture_comment(torture, "Renaming file1.txt --> tmp1.txt\n");
1499
1500 si = (union smb_setfileinfo) {
1501 .rename_information.level = RAW_SFILEINFO_RENAME_INFORMATION,
1502 .rename_information.in.file.handle = h1,
1503 .rename_information.in.new_name =
1504 BASEDIR "\\tmp1.txt",
1505 };
1506
1507 status = smb2_setinfo_file(tree1, &si);
1508 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
1509 "smb2_setinfo_file failed\n");
1510
1511 torture_comment(torture, "GetInfo of tmp1.txt\n");
1512
1513 gi = (union smb_fileinfo) {
1514 .generic.level = RAW_FILEINFO_SMB2_ALL_INFORMATION,
1515 .generic.in.file.handle = h1,
1516 };
1517
1518 status = smb2_getinfo_file(tree1, torture, &gi);
1519 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
1520 "smb2_getinfo_file failed\n");
1521
1522 torture_comment(torture, "Check if timestamps are good after rename(file1.txt --> tmp1.txt).\n");
1523
1524 torture_assert_nttime_equal(
1525 torture, c1.out.write_time, gi.all_info.out.write_time,
1526 "Bad timestamp\n");
1527
1528 torture_comment(torture, "Renaming file2.txt --> file1.txt\n");
1529
1530 si = (union smb_setfileinfo) {
1531 .rename_information.level = RAW_SFILEINFO_RENAME_INFORMATION,
1532 .rename_information.in.file.handle = h2,
1533 .rename_information.in.new_name =
1534 BASEDIR "\\file1.txt",
1535 };
1536 status = smb2_setinfo_file(tree1, &si);
1537 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
1538 "smb2_setinfo_file failed\n");
1539
1540 torture_comment(torture, "GetInfo of file1.txt\n");
1541
1542 gi = (union smb_fileinfo) {
1543 .generic.level = RAW_FILEINFO_SMB2_ALL_INFORMATION,
1544 .generic.in.file.handle = h2,
1545 };
1546
1547 status = smb2_getinfo_file(tree1, torture, &gi);
1548 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
1549 "smb2_getinfo_file failed\n");
1550
1551 torture_comment(torture, "Check if timestamps are good after rename(file2.txt --> file1.txt).\n");
1552
1553 torture_assert_nttime_equal(
1554 torture, c2.out.write_time, gi.all_info.out.write_time,
1555 "Bad timestamp\n");
1556
1557 done:
1558 if (!smb2_util_handle_empty(h1)) {
1559 smb2_util_close(tree1, h1);
1560 }
1561 if (!smb2_util_handle_empty(h2)) {
1562 smb2_util_close(tree1, h2);
1563 }
1564 smb2_deltree(tree1, BASEDIR);
1565 return ret;
1566 }
1567
1568 static bool test_smb2_close_full_information(struct torture_context *torture,
1569 struct smb2_tree *tree1,
1570 struct smb2_tree *tree2)
1571 {
1572 union smb_close cl;
1573 struct smb2_create io = {0};
1574 struct smb2_handle h1 = {{0}};
1575 struct smb2_handle h2 = {{0}};
1576 struct smb2_handle h3 = {{0}};
1577 union smb_setfileinfo sinfo;
1578 NTSTATUS status;
1579 const char *fname_src = "request.dat";
1580 const char *fname_dst = "renamed.dat";
1581 bool ret = true;
1582
1583 /* Start with a tidy share. */
1584 smb2_util_unlink(tree1, fname_src);
1585 smb2_util_unlink(tree1, fname_dst);
1586
1587 /* Create the test file, and leave it open. */
1588 io.in.fname = fname_src;
1589 io.in.desired_access = SEC_FILE_READ_DATA | SEC_FILE_READ_ATTRIBUTE;
1590 io.in.create_disposition = NTCREATEX_DISP_CREATE;
1591 io.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
1592 NTCREATEX_SHARE_ACCESS_WRITE |
1593 NTCREATEX_SHARE_ACCESS_DELETE;
1594 status = smb2_create(tree1, tree1, &io);
1595 CHECK_STATUS(status, NT_STATUS_OK);
1596 h1 = io.out.file.handle;
1597 CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE);
1598
1599 /* Open the test file on the second connection. */
1600 ZERO_STRUCT(io);
1601 io.in.fname = fname_src;
1602 io.in.desired_access = SEC_FILE_READ_DATA | SEC_FILE_READ_ATTRIBUTE;
1603 io.in.create_disposition = NTCREATEX_DISP_OPEN;
1604 io.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
1605 NTCREATEX_SHARE_ACCESS_WRITE |
1606 NTCREATEX_SHARE_ACCESS_DELETE;
1607 status = smb2_create(tree2, tree2, &io);
1608 CHECK_STATUS(status, NT_STATUS_OK);
1609 h2 = io.out.file.handle;
1610
1611 /* Now open for rename on the first connection. */
1612 ZERO_STRUCT(io);
1613 io.in.fname = fname_src;
1614 io.in.desired_access = SEC_STD_DELETE | SEC_FILE_READ_ATTRIBUTE;
1615 io.in.create_disposition = NTCREATEX_DISP_OPEN;
1616 io.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
1617 NTCREATEX_SHARE_ACCESS_WRITE |
1618 NTCREATEX_SHARE_ACCESS_DELETE;
1619 status = smb2_create(tree1, tree1, &io);
1620 CHECK_STATUS(status, NT_STATUS_OK);
1621 h3 = io.out.file.handle;
1622
1623 /* Do the rename. */
1624 ZERO_STRUCT(sinfo);
1625 sinfo.rename_information.level = RAW_SFILEINFO_RENAME_INFORMATION;
1626 sinfo.rename_information.in.file.handle = h3;
1627 sinfo.rename_information.in.new_name = fname_dst;
1628 status = smb2_setinfo_file(tree1, &sinfo);
1629 CHECK_STATUS(status, NT_STATUS_OK);
1630
1631 /* And close h3. */
1632 ZERO_STRUCT(cl.smb2);
1633 cl.smb2.level = RAW_CLOSE_SMB2;
1634 cl.smb2.in.file.handle = h3;
1635 status = smb2_close(tree1, &cl.smb2);
1636 CHECK_STATUS(status, NT_STATUS_OK);
1637 ZERO_STRUCT(h3);
1638
1639 /*
1640 * Close h1 with SMB2_CLOSE_FLAGS_FULL_INFORMATION.
1641 * Ensure we get data.
1642 */
1643 ZERO_STRUCT(cl.smb2);
1644 cl.smb2.level = RAW_CLOSE_SMB2;
1645 cl.smb2.in.file.handle = h1;
1646 cl.smb2.in.flags = SMB2_CLOSE_FLAGS_FULL_INFORMATION;
1647 status = smb2_close(tree1, &cl.smb2);
1648 CHECK_STATUS(status, NT_STATUS_OK);
1649 ZERO_STRUCT(h1);
1650 CHECK_VAL(cl.smb2.out.file_attr, 0x20);
1651
1652 /*
1653 * Wait 3 seconds for name change to propagate
1654 * to the other connection.
1655 */
1656 sleep(3);
1657
1658 /*
1659 * Close h2 with SMB2_CLOSE_FLAGS_FULL_INFORMATION.
1660 * This is on connection2.
1661 * Ensure we get data.
1662 */
1663 ZERO_STRUCT(cl.smb2);
1664 cl.smb2.level = RAW_CLOSE_SMB2;
1665 cl.smb2.in.file.handle = h2;
1666 cl.smb2.in.flags = SMB2_CLOSE_FLAGS_FULL_INFORMATION;
1667 status = smb2_close(tree2, &cl.smb2);
1668 CHECK_STATUS(status, NT_STATUS_OK);
1669 ZERO_STRUCT(h2);
1670 CHECK_VAL(cl.smb2.out.file_attr, 0x20);
1671
1672 done:
1673
1674 if (h1.data[0] != 0 || h1.data[1] != 0) {
1675 smb2_util_close(tree1, h1);
1676 }
1677 if (h2.data[0] != 0 || h2.data[1] != 0) {
1678 smb2_util_close(tree2, h2);
1679 }
1680 if (h3.data[0] != 0 || h3.data[1] != 0) {
1681 smb2_util_close(tree1, h3);
1682 }
1683
1684 smb2_util_unlink(tree1, fname_src);
1685 smb2_util_unlink(tree1, fname_dst);
1686
1687 return ret;
1688 }
1689
1690 static bool torture_smb2_rename_open(struct torture_context *torture,
1691 struct smb2_tree *tree1,
1692 struct smb2_tree *tree2)
1693 {
1694 struct smb2_create c1 = {};
1695 struct smb2_create c2 = {};
1696 union smb_setfileinfo sinfo = {};
1697 struct smb2_handle h1 = {};
1698 struct smb2_handle h2 = {};
1699 NTSTATUS status;
1700 bool ret = true;
1701
1702 smb2_deltree(tree1, BASEDIR);
1703 smb2_util_mkdir(tree1, BASEDIR);
1704
1705 /* Create testfile */
1706
1707 c1.in.desired_access = SEC_STD_DELETE;
1708 c1.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
1709 c1.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
1710 c1.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
1711 NTCREATEX_SHARE_ACCESS_WRITE | NTCREATEX_SHARE_ACCESS_DELETE;
1712 c1.in.create_disposition = NTCREATEX_DISP_CREATE;
1713 c1.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
1714 c1.in.fname = BASEDIR "\\file.txt";
1715
1716 status = smb2_create(tree1, torture, &c1);
1717 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
1718 "smb2_create failed\n");
1719 h1 = c1.out.file.handle;
1720
1721 /* 2nd open on testfile */
1722
1723 c2.in.desired_access = SEC_FILE_READ_DATA;
1724 c2.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
1725 c2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
1726 c2.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
1727 NTCREATEX_SHARE_ACCESS_WRITE | NTCREATEX_SHARE_ACCESS_DELETE;
1728 c2.in.create_disposition = NTCREATEX_DISP_OPEN;
1729 c2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
1730 c2.in.fname = BASEDIR "\\file.txt";
1731
1732 status = smb2_create(tree2, torture, &c2);
1733 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
1734 "smb2_create failed\n");
1735 h2 = c2.out.file.handle;
1736
1737 torture_comment(torture, "Renaming test file\n");
1738
1739 sinfo.rename_information.level = RAW_SFILEINFO_RENAME_INFORMATION;
1740 sinfo.rename_information.in.file.handle = h1;
1741 sinfo.rename_information.in.new_name =
1742 BASEDIR "\\newname.txt";
1743 status = smb2_setinfo_file(tree1, &sinfo);
1744 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
1745 "Rename failed\n");
1746
1747 done:
1748 if (!smb2_util_handle_empty(h1)) {
1749 smb2_util_close(tree1, h1);
1750 }
1751 if (!smb2_util_handle_empty(h2)) {
1752 smb2_util_close(tree2, h2);
1753 }
1754 smb2_deltree(tree1, BASEDIR);
1755 return ret;
1756 }
1757
1758 /*
1759 basic testing of SMB2 rename
1760 */
1761 struct torture_suite *torture_smb2_rename_init(TALLOC_CTX *ctx)
1762 {
1763 struct torture_suite *suite =
1764 torture_suite_create(ctx, "rename");
1765
1766 torture_suite_add_1smb2_test(suite, "simple",
1767 torture_smb2_rename_simple);
1768
1769 torture_suite_add_1smb2_test(suite, "simple_modtime",
1770 torture_smb2_rename_simple_modtime);
1771
1772 torture_suite_add_1smb2_test(suite, "simple_nodelete",
1773 torture_smb2_rename_simple2);
1774
1775 torture_suite_add_1smb2_test(suite, "no_sharing",
1776 torture_smb2_rename_no_sharemode);
1777
1778 torture_suite_add_1smb2_test(suite,
1779 "share_delete_and_delete_access",
1780 torture_smb2_rename_with_delete_access);
1781
1782 torture_suite_add_1smb2_test(suite,
1783 "no_share_delete_but_delete_access",
1784 torture_smb2_rename_with_delete_access2);
1785
1786 torture_suite_add_1smb2_test(suite,
1787 "share_delete_no_delete_access",
1788 torture_smb2_rename_no_delete_access);
1789
1790 torture_suite_add_1smb2_test(suite,
1791 "no_share_delete_no_delete_access",
1792 torture_smb2_rename_no_delete_access2);
1793
1794 torture_suite_add_1smb2_test(suite,
1795 "msword",
1796 torture_smb2_rename_msword);
1797
1798 torture_suite_add_1smb2_test(
1799 suite, "rename_dir_openfile",
1800 torture_smb2_rename_dir_openfile);
1801
1802 torture_suite_add_1smb2_test(suite,
1803 "rename_dir_bench",
1804 torture_smb2_rename_dir_bench);
1805
1806 torture_suite_add_2smb2_test(suite,
1807 "close-full-information",
1808 test_smb2_close_full_information);
1809
1810 torture_suite_add_2smb2_test(suite,
1811 "rename-open",
1812 torture_smb2_rename_open);
1813
1814 suite->description = talloc_strdup(suite, "smb2.rename tests");
1815
1816 return suite;
1817 }