2 Unix SMB/CIFS implementation.
4 test suite for SMB2 compounded requests
6 Copyright (C) Stefan Metzmacher 2009
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "libcli/smb2/smb2.h"
24 #include "libcli/smb2/smb2_calls.h"
25 #include "torture/torture.h"
26 #include "torture/smb2/proto.h"
27 #include "../libcli/smb/smbXcli_base.h"
29 #define CHECK_STATUS(status, correct) do { \
30 if (!NT_STATUS_EQUAL(status, correct)) { \
31 torture_result(tctx, TORTURE_FAIL, __location__": Incorrect status %s - should be %s", \
32 nt_errstr(status), nt_errstr(correct)); \
37 #define TARGET_IS_W2K8(_tctx) (torture_setting_bool(_tctx, "w2k8", false))
38 #define TARGET_IS_WIN7(_tctx) (torture_setting_bool(_tctx, "win7", false))
40 static bool test_compound_related1(struct torture_context
*tctx
,
41 struct smb2_tree
*tree
)
43 struct smb2_handle hd
;
44 struct smb2_create cr
;
46 const char *fname
= "compound_related1.dat";
49 struct smb2_request
*req
[2];
50 struct smbXcli_tcon
*saved_tcon
= tree
->smbXcli
;
51 struct smbXcli_session
*saved_session
= tree
->session
->smbXcli
;
53 smb2_transport_credits_ask_num(tree
->session
->transport
, 2);
55 smb2_util_unlink(tree
, fname
);
57 smb2_transport_credits_ask_num(tree
->session
->transport
, 1);
60 cr
.in
.security_flags
= 0x00;
61 cr
.in
.oplock_level
= 0;
62 cr
.in
.impersonation_level
= NTCREATEX_IMPERSONATION_IMPERSONATION
;
63 cr
.in
.create_flags
= 0x00000000;
64 cr
.in
.reserved
= 0x00000000;
65 cr
.in
.desired_access
= SEC_RIGHTS_FILE_ALL
;
66 cr
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
67 cr
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
68 NTCREATEX_SHARE_ACCESS_WRITE
|
69 NTCREATEX_SHARE_ACCESS_DELETE
;
70 cr
.in
.create_disposition
= NTCREATEX_DISP_OPEN_IF
;
71 cr
.in
.create_options
= NTCREATEX_OPTIONS_SEQUENTIAL_ONLY
|
72 NTCREATEX_OPTIONS_ASYNC_ALERT
|
73 NTCREATEX_OPTIONS_NON_DIRECTORY_FILE
|
77 smb2_transport_compound_start(tree
->session
->transport
, 2);
79 req
[0] = smb2_create_send(tree
, &cr
);
81 smb2_transport_compound_set_related(tree
->session
->transport
, true);
83 hd
.data
[0] = UINT64_MAX
;
84 hd
.data
[1] = UINT64_MAX
;
87 cl
.in
.file
.handle
= hd
;
89 tree
->smbXcli
= smbXcli_tcon_create(tree
);
90 smb2cli_tcon_set_values(tree
->smbXcli
,
92 0xFFFFFFFF, /* tcon_id */
96 0 /* maximal_access */);
98 tree
->session
->smbXcli
= smbXcli_session_create(tree
->session
,
99 tree
->session
->transport
->conn
);
100 smb2cli_session_set_id_and_flags(tree
->session
->smbXcli
, UINT64_MAX
, 0);
102 req
[1] = smb2_close_send(tree
, &cl
);
104 status
= smb2_create_recv(req
[0], tree
, &cr
);
105 CHECK_STATUS(status
, NT_STATUS_OK
);
106 status
= smb2_close_recv(req
[1], &cl
);
107 CHECK_STATUS(status
, NT_STATUS_OK
);
109 TALLOC_FREE(tree
->smbXcli
);
110 tree
->smbXcli
= saved_tcon
;
111 TALLOC_FREE(tree
->session
->smbXcli
);
112 tree
->session
->smbXcli
= saved_session
;
114 smb2_util_unlink(tree
, fname
);
119 static bool test_compound_related2(struct torture_context
*tctx
,
120 struct smb2_tree
*tree
)
122 struct smb2_handle hd
;
123 struct smb2_create cr
;
125 const char *fname
= "compound_related2.dat";
126 struct smb2_close cl
;
128 struct smb2_request
*req
[5];
129 struct smbXcli_tcon
*saved_tcon
= tree
->smbXcli
;
130 struct smbXcli_session
*saved_session
= tree
->session
->smbXcli
;
132 smb2_transport_credits_ask_num(tree
->session
->transport
, 5);
134 smb2_util_unlink(tree
, fname
);
136 smb2_transport_credits_ask_num(tree
->session
->transport
, 1);
139 cr
.in
.security_flags
= 0x00;
140 cr
.in
.oplock_level
= 0;
141 cr
.in
.impersonation_level
= NTCREATEX_IMPERSONATION_IMPERSONATION
;
142 cr
.in
.create_flags
= 0x00000000;
143 cr
.in
.reserved
= 0x00000000;
144 cr
.in
.desired_access
= SEC_RIGHTS_FILE_ALL
;
145 cr
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
146 cr
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
147 NTCREATEX_SHARE_ACCESS_WRITE
|
148 NTCREATEX_SHARE_ACCESS_DELETE
;
149 cr
.in
.create_disposition
= NTCREATEX_DISP_OPEN_IF
;
150 cr
.in
.create_options
= NTCREATEX_OPTIONS_SEQUENTIAL_ONLY
|
151 NTCREATEX_OPTIONS_ASYNC_ALERT
|
152 NTCREATEX_OPTIONS_NON_DIRECTORY_FILE
|
156 smb2_transport_compound_start(tree
->session
->transport
, 5);
158 req
[0] = smb2_create_send(tree
, &cr
);
160 hd
.data
[0] = UINT64_MAX
;
161 hd
.data
[1] = UINT64_MAX
;
163 smb2_transport_compound_set_related(tree
->session
->transport
, true);
166 cl
.in
.file
.handle
= hd
;
168 tree
->smbXcli
= smbXcli_tcon_create(tree
);
169 smb2cli_tcon_set_values(tree
->smbXcli
,
171 0xFFFFFFFF, /* tcon_id */
174 0, /* capabilities */
175 0 /* maximal_access */);
177 tree
->session
->smbXcli
= smbXcli_session_create(tree
->session
,
178 tree
->session
->transport
->conn
);
179 smb2cli_session_set_id_and_flags(tree
->session
->smbXcli
, UINT64_MAX
, 0);
181 req
[1] = smb2_close_send(tree
, &cl
);
182 req
[2] = smb2_close_send(tree
, &cl
);
183 req
[3] = smb2_close_send(tree
, &cl
);
184 req
[4] = smb2_close_send(tree
, &cl
);
186 status
= smb2_create_recv(req
[0], tree
, &cr
);
187 CHECK_STATUS(status
, NT_STATUS_OK
);
188 status
= smb2_close_recv(req
[1], &cl
);
189 CHECK_STATUS(status
, NT_STATUS_OK
);
190 status
= smb2_close_recv(req
[2], &cl
);
191 CHECK_STATUS(status
, NT_STATUS_FILE_CLOSED
);
192 status
= smb2_close_recv(req
[3], &cl
);
193 CHECK_STATUS(status
, NT_STATUS_INVALID_PARAMETER
);
194 status
= smb2_close_recv(req
[4], &cl
);
195 CHECK_STATUS(status
, NT_STATUS_INVALID_PARAMETER
);
197 TALLOC_FREE(tree
->smbXcli
);
198 tree
->smbXcli
= saved_tcon
;
199 TALLOC_FREE(tree
->session
->smbXcli
);
200 tree
->session
->smbXcli
= saved_session
;
202 smb2_util_unlink(tree
, fname
);
207 static bool test_compound_related3(struct torture_context
*tctx
,
208 struct smb2_tree
*tree
)
210 struct smb2_handle hd
;
211 struct smb2_ioctl io
;
212 struct smb2_create cr
;
213 struct smb2_close cl
;
214 const char *fname
= "compound_related3.dat";
215 struct smb2_request
*req
[3];
219 smb2_util_unlink(tree
, fname
);
222 cr
.in
.security_flags
= 0x00;
223 cr
.in
.oplock_level
= 0;
224 cr
.in
.impersonation_level
= NTCREATEX_IMPERSONATION_IMPERSONATION
;
225 cr
.in
.create_flags
= 0x00000000;
226 cr
.in
.reserved
= 0x00000000;
227 cr
.in
.desired_access
= SEC_RIGHTS_FILE_ALL
;
228 cr
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
229 cr
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
230 NTCREATEX_SHARE_ACCESS_WRITE
|
231 NTCREATEX_SHARE_ACCESS_DELETE
;
232 cr
.in
.create_disposition
= NTCREATEX_DISP_OPEN_IF
;
233 cr
.in
.create_options
= NTCREATEX_OPTIONS_SEQUENTIAL_ONLY
|
234 NTCREATEX_OPTIONS_ASYNC_ALERT
|
235 NTCREATEX_OPTIONS_NON_DIRECTORY_FILE
|
239 smb2_transport_compound_start(tree
->session
->transport
, 3);
241 req
[0] = smb2_create_send(tree
, &cr
);
243 hd
.data
[0] = UINT64_MAX
;
244 hd
.data
[1] = UINT64_MAX
;
246 smb2_transport_compound_set_related(tree
->session
->transport
, true);
249 io
.in
.function
= FSCTL_CREATE_OR_GET_OBJECT_ID
;
250 io
.in
.file
.handle
= hd
;
252 io
.in
.max_response_size
= 64;
255 req
[1] = smb2_ioctl_send(tree
, &io
);
258 cl
.in
.file
.handle
= hd
;
260 req
[2] = smb2_close_send(tree
, &cl
);
262 status
= smb2_create_recv(req
[0], tree
, &cr
);
263 CHECK_STATUS(status
, NT_STATUS_OK
);
264 status
= smb2_ioctl_recv(req
[1], tree
, &io
);
265 CHECK_STATUS(status
, NT_STATUS_OK
);
266 status
= smb2_close_recv(req
[2], &cl
);
267 CHECK_STATUS(status
, NT_STATUS_OK
);
269 status
= smb2_util_unlink(tree
, fname
);
270 CHECK_STATUS(status
, NT_STATUS_OK
);
277 static bool test_compound_unrelated1(struct torture_context
*tctx
,
278 struct smb2_tree
*tree
)
280 struct smb2_handle hd
;
281 struct smb2_create cr
;
283 const char *fname
= "compound_unrelated1.dat";
284 struct smb2_close cl
;
286 struct smb2_request
*req
[5];
288 smb2_transport_credits_ask_num(tree
->session
->transport
, 5);
290 smb2_util_unlink(tree
, fname
);
292 smb2_transport_credits_ask_num(tree
->session
->transport
, 1);
295 cr
.in
.security_flags
= 0x00;
296 cr
.in
.oplock_level
= 0;
297 cr
.in
.impersonation_level
= NTCREATEX_IMPERSONATION_IMPERSONATION
;
298 cr
.in
.create_flags
= 0x00000000;
299 cr
.in
.reserved
= 0x00000000;
300 cr
.in
.desired_access
= SEC_RIGHTS_FILE_ALL
;
301 cr
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
302 cr
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
303 NTCREATEX_SHARE_ACCESS_WRITE
|
304 NTCREATEX_SHARE_ACCESS_DELETE
;
305 cr
.in
.create_disposition
= NTCREATEX_DISP_OPEN_IF
;
306 cr
.in
.create_options
= NTCREATEX_OPTIONS_SEQUENTIAL_ONLY
|
307 NTCREATEX_OPTIONS_ASYNC_ALERT
|
308 NTCREATEX_OPTIONS_NON_DIRECTORY_FILE
|
312 smb2_transport_compound_start(tree
->session
->transport
, 5);
314 req
[0] = smb2_create_send(tree
, &cr
);
316 hd
.data
[0] = UINT64_MAX
;
317 hd
.data
[1] = UINT64_MAX
;
320 cl
.in
.file
.handle
= hd
;
321 req
[1] = smb2_close_send(tree
, &cl
);
322 req
[2] = smb2_close_send(tree
, &cl
);
323 req
[3] = smb2_close_send(tree
, &cl
);
324 req
[4] = smb2_close_send(tree
, &cl
);
326 status
= smb2_create_recv(req
[0], tree
, &cr
);
327 CHECK_STATUS(status
, NT_STATUS_OK
);
328 status
= smb2_close_recv(req
[1], &cl
);
329 CHECK_STATUS(status
, NT_STATUS_FILE_CLOSED
);
330 status
= smb2_close_recv(req
[2], &cl
);
331 CHECK_STATUS(status
, NT_STATUS_FILE_CLOSED
);
332 status
= smb2_close_recv(req
[3], &cl
);
333 CHECK_STATUS(status
, NT_STATUS_FILE_CLOSED
);
334 status
= smb2_close_recv(req
[4], &cl
);
335 CHECK_STATUS(status
, NT_STATUS_FILE_CLOSED
);
337 smb2_util_unlink(tree
, fname
);
342 static bool test_compound_invalid1(struct torture_context
*tctx
,
343 struct smb2_tree
*tree
)
345 struct smb2_handle hd
;
346 struct smb2_create cr
;
348 const char *fname
= "compound_invalid1.dat";
349 struct smb2_close cl
;
351 struct smb2_request
*req
[2];
353 smb2_transport_credits_ask_num(tree
->session
->transport
, 2);
355 smb2_util_unlink(tree
, fname
);
357 smb2_transport_credits_ask_num(tree
->session
->transport
, 1);
360 cr
.in
.security_flags
= 0x00;
361 cr
.in
.oplock_level
= 0;
362 cr
.in
.impersonation_level
= NTCREATEX_IMPERSONATION_IMPERSONATION
;
363 cr
.in
.create_flags
= 0x00000000;
364 cr
.in
.reserved
= 0x00000000;
365 cr
.in
.desired_access
= SEC_RIGHTS_FILE_ALL
;
366 cr
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
367 cr
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
368 NTCREATEX_SHARE_ACCESS_WRITE
|
369 NTCREATEX_SHARE_ACCESS_DELETE
;
370 cr
.in
.create_disposition
= NTCREATEX_DISP_OPEN_IF
;
371 cr
.in
.create_options
= NTCREATEX_OPTIONS_SEQUENTIAL_ONLY
|
372 NTCREATEX_OPTIONS_ASYNC_ALERT
|
373 NTCREATEX_OPTIONS_NON_DIRECTORY_FILE
|
377 smb2_transport_compound_start(tree
->session
->transport
, 2);
379 /* passing the first request with the related flag is invalid */
380 smb2_transport_compound_set_related(tree
->session
->transport
, true);
382 req
[0] = smb2_create_send(tree
, &cr
);
384 hd
.data
[0] = UINT64_MAX
;
385 hd
.data
[1] = UINT64_MAX
;
388 cl
.in
.file
.handle
= hd
;
389 req
[1] = smb2_close_send(tree
, &cl
);
391 status
= smb2_create_recv(req
[0], tree
, &cr
);
392 /* TODO: check why this fails with --signing=required */
393 CHECK_STATUS(status
, NT_STATUS_INVALID_PARAMETER
);
394 status
= smb2_close_recv(req
[1], &cl
);
395 CHECK_STATUS(status
, NT_STATUS_INVALID_PARAMETER
);
397 smb2_util_unlink(tree
, fname
);
402 static bool test_compound_invalid2(struct torture_context
*tctx
,
403 struct smb2_tree
*tree
)
405 struct smb2_handle hd
;
406 struct smb2_create cr
;
408 const char *fname
= "compound_invalid2.dat";
409 struct smb2_close cl
;
411 struct smb2_request
*req
[5];
412 struct smbXcli_tcon
*saved_tcon
= tree
->smbXcli
;
413 struct smbXcli_session
*saved_session
= tree
->session
->smbXcli
;
415 smb2_transport_credits_ask_num(tree
->session
->transport
, 5);
417 smb2_util_unlink(tree
, fname
);
419 smb2_transport_credits_ask_num(tree
->session
->transport
, 1);
422 cr
.in
.security_flags
= 0x00;
423 cr
.in
.oplock_level
= 0;
424 cr
.in
.impersonation_level
= NTCREATEX_IMPERSONATION_IMPERSONATION
;
425 cr
.in
.create_flags
= 0x00000000;
426 cr
.in
.reserved
= 0x00000000;
427 cr
.in
.desired_access
= SEC_RIGHTS_FILE_ALL
;
428 cr
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
429 cr
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
430 NTCREATEX_SHARE_ACCESS_WRITE
|
431 NTCREATEX_SHARE_ACCESS_DELETE
;
432 cr
.in
.create_disposition
= NTCREATEX_DISP_OPEN_IF
;
433 cr
.in
.create_options
= NTCREATEX_OPTIONS_SEQUENTIAL_ONLY
|
434 NTCREATEX_OPTIONS_ASYNC_ALERT
|
435 NTCREATEX_OPTIONS_NON_DIRECTORY_FILE
|
439 smb2_transport_compound_start(tree
->session
->transport
, 5);
441 req
[0] = smb2_create_send(tree
, &cr
);
443 hd
.data
[0] = UINT64_MAX
;
444 hd
.data
[1] = UINT64_MAX
;
446 smb2_transport_compound_set_related(tree
->session
->transport
, true);
449 cl
.in
.file
.handle
= hd
;
451 tree
->smbXcli
= smbXcli_tcon_create(tree
);
452 smb2cli_tcon_set_values(tree
->smbXcli
,
454 0xFFFFFFFF, /* tcon_id */
457 0, /* capabilities */
458 0 /* maximal_access */);
460 tree
->session
->smbXcli
= smbXcli_session_create(tree
->session
,
461 tree
->session
->transport
->conn
);
462 smb2cli_session_set_id_and_flags(tree
->session
->smbXcli
, UINT64_MAX
, 0);
464 req
[1] = smb2_close_send(tree
, &cl
);
465 /* strange that this is not generating invalid parameter */
466 smb2_transport_compound_set_related(tree
->session
->transport
, false);
467 req
[2] = smb2_close_send(tree
, &cl
);
468 req
[3] = smb2_close_send(tree
, &cl
);
469 smb2_transport_compound_set_related(tree
->session
->transport
, true);
470 req
[4] = smb2_close_send(tree
, &cl
);
472 status
= smb2_create_recv(req
[0], tree
, &cr
);
473 CHECK_STATUS(status
, NT_STATUS_OK
);
474 status
= smb2_close_recv(req
[1], &cl
);
475 CHECK_STATUS(status
, NT_STATUS_OK
);
476 status
= smb2_close_recv(req
[2], &cl
);
477 CHECK_STATUS(status
, NT_STATUS_USER_SESSION_DELETED
);
478 status
= smb2_close_recv(req
[3], &cl
);
479 CHECK_STATUS(status
, NT_STATUS_USER_SESSION_DELETED
);
480 status
= smb2_close_recv(req
[4], &cl
);
481 CHECK_STATUS(status
, NT_STATUS_INVALID_PARAMETER
);
483 TALLOC_FREE(tree
->smbXcli
);
484 tree
->smbXcli
= saved_tcon
;
485 TALLOC_FREE(tree
->session
->smbXcli
);
486 tree
->session
->smbXcli
= saved_session
;
488 smb2_util_unlink(tree
, fname
);
493 static bool test_compound_invalid3(struct torture_context
*tctx
,
494 struct smb2_tree
*tree
)
496 struct smb2_handle hd
;
497 struct smb2_create cr
;
499 const char *fname
= "compound_invalid3.dat";
500 struct smb2_close cl
;
502 struct smb2_request
*req
[5];
504 smb2_transport_credits_ask_num(tree
->session
->transport
, 5);
506 smb2_util_unlink(tree
, fname
);
508 smb2_transport_credits_ask_num(tree
->session
->transport
, 1);
511 cr
.in
.security_flags
= 0x00;
512 cr
.in
.oplock_level
= 0;
513 cr
.in
.impersonation_level
= NTCREATEX_IMPERSONATION_IMPERSONATION
;
514 cr
.in
.create_flags
= 0x00000000;
515 cr
.in
.reserved
= 0x00000000;
516 cr
.in
.desired_access
= SEC_RIGHTS_FILE_ALL
;
517 cr
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
518 cr
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
519 NTCREATEX_SHARE_ACCESS_WRITE
|
520 NTCREATEX_SHARE_ACCESS_DELETE
;
521 cr
.in
.create_disposition
= NTCREATEX_DISP_OPEN_IF
;
522 cr
.in
.create_options
= NTCREATEX_OPTIONS_SEQUENTIAL_ONLY
|
523 NTCREATEX_OPTIONS_ASYNC_ALERT
|
524 NTCREATEX_OPTIONS_NON_DIRECTORY_FILE
|
528 smb2_transport_compound_start(tree
->session
->transport
, 5);
530 req
[0] = smb2_create_send(tree
, &cr
);
532 hd
.data
[0] = UINT64_MAX
;
533 hd
.data
[1] = UINT64_MAX
;
536 cl
.in
.file
.handle
= hd
;
537 req
[1] = smb2_close_send(tree
, &cl
);
538 req
[2] = smb2_close_send(tree
, &cl
);
539 /* flipping the related flag is invalid */
540 smb2_transport_compound_set_related(tree
->session
->transport
, true);
541 req
[3] = smb2_close_send(tree
, &cl
);
542 req
[4] = smb2_close_send(tree
, &cl
);
544 status
= smb2_create_recv(req
[0], tree
, &cr
);
545 CHECK_STATUS(status
, NT_STATUS_OK
);
546 status
= smb2_close_recv(req
[1], &cl
);
547 CHECK_STATUS(status
, NT_STATUS_FILE_CLOSED
);
548 status
= smb2_close_recv(req
[2], &cl
);
549 CHECK_STATUS(status
, NT_STATUS_FILE_CLOSED
);
550 status
= smb2_close_recv(req
[3], &cl
);
551 CHECK_STATUS(status
, NT_STATUS_INVALID_PARAMETER
);
552 status
= smb2_close_recv(req
[4], &cl
);
553 CHECK_STATUS(status
, NT_STATUS_INVALID_PARAMETER
);
555 smb2_util_unlink(tree
, fname
);
560 /* Send a compound request where we expect the last request (Create, Notify)
561 * to go asynchronous. This works against a Win7 server and the reply is
562 * sent in two different packets. */
563 static bool test_compound_interim1(struct torture_context
*tctx
,
564 struct smb2_tree
*tree
)
566 struct smb2_handle hd
;
567 struct smb2_create cr
;
568 NTSTATUS status
= NT_STATUS_OK
;
569 const char *dname
= "compound_interim_dir";
570 struct smb2_notify nt
;
572 struct smb2_request
*req
[2];
574 /* Win7 compound request implementation deviates substantially from the
575 * SMB2 spec as noted in MS-SMB2 <159>, <162>. This, test currently
576 * verifies the Windows behavior, not the general spec behavior. */
577 if (!TARGET_IS_WIN7(tctx
) && !TARGET_IS_W2K8(tctx
)) {
578 torture_skip(tctx
, "Interim test is specific to Windows server "
582 smb2_transport_credits_ask_num(tree
->session
->transport
, 5);
584 smb2_deltree(tree
, dname
);
586 smb2_transport_credits_ask_num(tree
->session
->transport
, 1);
589 cr
.in
.desired_access
= SEC_RIGHTS_FILE_ALL
;
590 cr
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
591 cr
.in
.file_attributes
= FILE_ATTRIBUTE_DIRECTORY
;
592 cr
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
593 NTCREATEX_SHARE_ACCESS_WRITE
|
594 NTCREATEX_SHARE_ACCESS_DELETE
;
595 cr
.in
.create_disposition
= NTCREATEX_DISP_CREATE
;
598 smb2_transport_compound_start(tree
->session
->transport
, 2);
600 req
[0] = smb2_create_send(tree
, &cr
);
602 smb2_transport_compound_set_related(tree
->session
->transport
, true);
604 hd
.data
[0] = UINT64_MAX
;
605 hd
.data
[1] = UINT64_MAX
;
608 nt
.in
.recursive
= true;
609 nt
.in
.buffer_size
= 0x1000;
610 nt
.in
.file
.handle
= hd
;
611 nt
.in
.completion_filter
= FILE_NOTIFY_CHANGE_NAME
;
612 nt
.in
.unknown
= 0x00000000;
614 req
[1] = smb2_notify_send(tree
, &nt
);
616 status
= smb2_create_recv(req
[0], tree
, &cr
);
617 CHECK_STATUS(status
, NT_STATUS_OK
);
620 status
= smb2_notify_recv(req
[1], tree
, &nt
);
621 CHECK_STATUS(status
, NT_STATUS_CANCELLED
);
623 smb2_util_close(tree
, cr
.out
.file
.handle
);
625 smb2_deltree(tree
, dname
);
630 /* Send a compound request where we expect the middle request (Create, Notify,
631 * GetInfo) to go asynchronous. Against Win7 the sync request succeed while
632 * the async fails. All are returned in the same compound response. */
633 static bool test_compound_interim2(struct torture_context
*tctx
,
634 struct smb2_tree
*tree
)
636 struct smb2_handle hd
;
637 struct smb2_create cr
;
638 NTSTATUS status
= NT_STATUS_OK
;
639 const char *dname
= "compound_interim_dir";
640 struct smb2_getinfo gf
;
641 struct smb2_notify nt
;
643 struct smb2_request
*req
[3];
645 /* Win7 compound request implementation deviates substantially from the
646 * SMB2 spec as noted in MS-SMB2 <159>, <162>. This, test currently
647 * verifies the Windows behavior, not the general spec behavior. */
648 if (!TARGET_IS_WIN7(tctx
) && !TARGET_IS_W2K8(tctx
)) {
649 torture_skip(tctx
, "Interim test is specific to Windows server "
653 smb2_transport_credits_ask_num(tree
->session
->transport
, 5);
655 smb2_deltree(tree
, dname
);
657 smb2_transport_credits_ask_num(tree
->session
->transport
, 1);
660 cr
.in
.desired_access
= SEC_RIGHTS_FILE_ALL
;
661 cr
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
662 cr
.in
.file_attributes
= FILE_ATTRIBUTE_DIRECTORY
;
663 cr
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
664 NTCREATEX_SHARE_ACCESS_WRITE
|
665 NTCREATEX_SHARE_ACCESS_DELETE
;
666 cr
.in
.create_disposition
= NTCREATEX_DISP_CREATE
;
669 smb2_transport_compound_start(tree
->session
->transport
, 3);
671 req
[0] = smb2_create_send(tree
, &cr
);
673 smb2_transport_compound_set_related(tree
->session
->transport
, true);
675 hd
.data
[0] = UINT64_MAX
;
676 hd
.data
[1] = UINT64_MAX
;
679 nt
.in
.recursive
= true;
680 nt
.in
.buffer_size
= 0x1000;
681 nt
.in
.file
.handle
= hd
;
682 nt
.in
.completion_filter
= FILE_NOTIFY_CHANGE_NAME
;
683 nt
.in
.unknown
= 0x00000000;
685 req
[1] = smb2_notify_send(tree
, &nt
);
688 gf
.in
.file
.handle
= hd
;
689 gf
.in
.info_type
= SMB2_GETINFO_FILE
;
690 gf
.in
.info_class
= 0x04; /* FILE_BASIC_INFORMATION */
691 gf
.in
.output_buffer_length
= 0x1000;
692 gf
.in
.input_buffer_length
= 0;
694 req
[2] = smb2_getinfo_send(tree
, &gf
);
696 status
= smb2_create_recv(req
[0], tree
, &cr
);
697 CHECK_STATUS(status
, NT_STATUS_OK
);
699 status
= smb2_notify_recv(req
[1], tree
, &nt
);
700 CHECK_STATUS(status
, NT_STATUS_INTERNAL_ERROR
);
702 status
= smb2_getinfo_recv(req
[2], tree
, &gf
);
703 CHECK_STATUS(status
, NT_STATUS_OK
);
705 smb2_util_close(tree
, cr
.out
.file
.handle
);
707 smb2_deltree(tree
, dname
);
712 struct torture_suite
*torture_smb2_compound_init(void)
714 struct torture_suite
*suite
= torture_suite_create(talloc_autofree_context(), "compound");
716 torture_suite_add_1smb2_test(suite
, "related1", test_compound_related1
);
717 torture_suite_add_1smb2_test(suite
, "related2", test_compound_related2
);
718 torture_suite_add_1smb2_test(suite
, "related3",
719 test_compound_related3
);
720 torture_suite_add_1smb2_test(suite
, "unrelated1", test_compound_unrelated1
);
721 torture_suite_add_1smb2_test(suite
, "invalid1", test_compound_invalid1
);
722 torture_suite_add_1smb2_test(suite
, "invalid2", test_compound_invalid2
);
723 torture_suite_add_1smb2_test(suite
, "invalid3", test_compound_invalid3
);
724 torture_suite_add_1smb2_test(suite
, "interim1", test_compound_interim1
);
725 torture_suite_add_1smb2_test(suite
, "interim2", test_compound_interim2
);
727 suite
->description
= talloc_strdup(suite
, "SMB2-COMPOUND tests");