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