s4:torture:smb2: extend the compound.invalid1 test
[Samba.git] / source4 / torture / smb2 / compound.c
blob596702bd99b739d6676677e84701054d89badae2
1 /*
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/>.
22 #include "includes.h"
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)); \
33 ret = false; \
34 goto done; \
35 }} while (0)
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;
45 NTSTATUS status;
46 const char *fname = "compound_related1.dat";
47 struct smb2_close cl;
48 bool ret = true;
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);
59 ZERO_STRUCT(cr);
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 |
74 0x00200000;
75 cr.in.fname = fname;
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;
86 ZERO_STRUCT(cl);
87 cl.in.file.handle = hd;
89 tree->smbXcli = smbXcli_tcon_create(tree);
90 smb2cli_tcon_set_values(tree->smbXcli,
91 NULL, /* session */
92 0xFFFFFFFF, /* tcon_id */
93 0, /* type */
94 0, /* flags */
95 0, /* capabilities */
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);
115 done:
116 return ret;
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;
124 NTSTATUS status;
125 const char *fname = "compound_related2.dat";
126 struct smb2_close cl;
127 bool ret = true;
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);
138 ZERO_STRUCT(cr);
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 |
153 0x00200000;
154 cr.in.fname = fname;
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);
165 ZERO_STRUCT(cl);
166 cl.in.file.handle = hd;
168 tree->smbXcli = smbXcli_tcon_create(tree);
169 smb2cli_tcon_set_values(tree->smbXcli,
170 NULL, /* session */
171 0xFFFFFFFF, /* tcon_id */
172 0, /* type */
173 0, /* flags */
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_FILE_CLOSED);
194 status = smb2_close_recv(req[4], &cl);
195 CHECK_STATUS(status, NT_STATUS_FILE_CLOSED);
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);
203 done:
204 return ret;
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];
216 NTSTATUS status;
217 bool ret = false;
219 smb2_util_unlink(tree, fname);
221 ZERO_STRUCT(cr);
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 |
236 0x00200000;
237 cr.in.fname = fname;
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);
248 ZERO_STRUCT(io);
249 io.in.function = FSCTL_CREATE_OR_GET_OBJECT_ID;
250 io.in.file.handle = hd;
251 io.in.unknown2 = 0;
252 io.in.max_response_size = 64;
253 io.in.flags = 1;
255 req[1] = smb2_ioctl_send(tree, &io);
257 ZERO_STRUCT(cl);
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);
272 ret = true;
273 done:
274 return ret;
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;
282 NTSTATUS status;
283 const char *fname = "compound_unrelated1.dat";
284 struct smb2_close cl;
285 bool ret = true;
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);
294 ZERO_STRUCT(cr);
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 |
309 0x00200000;
310 cr.in.fname = fname;
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;
319 ZERO_STRUCT(cl);
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);
338 done:
339 return ret;
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;
347 NTSTATUS status;
348 const char *fname = "compound_invalid1.dat";
349 struct smb2_close cl;
350 bool ret = true;
351 struct smb2_request *req[3];
353 smb2_transport_credits_ask_num(tree->session->transport, 3);
355 smb2_util_unlink(tree, fname);
357 smb2_transport_credits_ask_num(tree->session->transport, 1);
359 ZERO_STRUCT(cr);
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 |
374 0x00200000;
375 cr.in.fname = fname;
377 smb2_transport_compound_start(tree->session->transport, 3);
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;
387 ZERO_STRUCT(cl);
388 cl.in.file.handle = hd;
389 req[1] = smb2_close_send(tree, &cl);
391 smb2_transport_compound_set_related(tree->session->transport, false);
392 req[2] = smb2_close_send(tree, &cl);
394 status = smb2_create_recv(req[0], tree, &cr);
395 /* TODO: check why this fails with --signing=required */
396 CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);
397 status = smb2_close_recv(req[1], &cl);
398 CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);
399 status = smb2_close_recv(req[2], &cl);
400 CHECK_STATUS(status, NT_STATUS_FILE_CLOSED);
402 smb2_util_unlink(tree, fname);
403 done:
404 return ret;
407 static bool test_compound_invalid2(struct torture_context *tctx,
408 struct smb2_tree *tree)
410 struct smb2_handle hd;
411 struct smb2_create cr;
412 NTSTATUS status;
413 const char *fname = "compound_invalid2.dat";
414 struct smb2_close cl;
415 bool ret = true;
416 struct smb2_request *req[5];
417 struct smbXcli_tcon *saved_tcon = tree->smbXcli;
418 struct smbXcli_session *saved_session = tree->session->smbXcli;
420 smb2_transport_credits_ask_num(tree->session->transport, 5);
422 smb2_util_unlink(tree, fname);
424 smb2_transport_credits_ask_num(tree->session->transport, 1);
426 ZERO_STRUCT(cr);
427 cr.in.security_flags = 0x00;
428 cr.in.oplock_level = 0;
429 cr.in.impersonation_level = NTCREATEX_IMPERSONATION_IMPERSONATION;
430 cr.in.create_flags = 0x00000000;
431 cr.in.reserved = 0x00000000;
432 cr.in.desired_access = SEC_RIGHTS_FILE_ALL;
433 cr.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
434 cr.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
435 NTCREATEX_SHARE_ACCESS_WRITE |
436 NTCREATEX_SHARE_ACCESS_DELETE;
437 cr.in.create_disposition = NTCREATEX_DISP_OPEN_IF;
438 cr.in.create_options = NTCREATEX_OPTIONS_SEQUENTIAL_ONLY |
439 NTCREATEX_OPTIONS_ASYNC_ALERT |
440 NTCREATEX_OPTIONS_NON_DIRECTORY_FILE |
441 0x00200000;
442 cr.in.fname = fname;
444 smb2_transport_compound_start(tree->session->transport, 5);
446 req[0] = smb2_create_send(tree, &cr);
448 hd.data[0] = UINT64_MAX;
449 hd.data[1] = UINT64_MAX;
451 smb2_transport_compound_set_related(tree->session->transport, true);
453 ZERO_STRUCT(cl);
454 cl.in.file.handle = hd;
456 tree->smbXcli = smbXcli_tcon_create(tree);
457 smb2cli_tcon_set_values(tree->smbXcli,
458 NULL, /* session */
459 0xFFFFFFFF, /* tcon_id */
460 0, /* type */
461 0, /* flags */
462 0, /* capabilities */
463 0 /* maximal_access */);
465 tree->session->smbXcli = smbXcli_session_create(tree->session,
466 tree->session->transport->conn);
467 smb2cli_session_set_id_and_flags(tree->session->smbXcli, UINT64_MAX, 0);
469 req[1] = smb2_close_send(tree, &cl);
470 /* strange that this is not generating invalid parameter */
471 smb2_transport_compound_set_related(tree->session->transport, false);
472 req[2] = smb2_close_send(tree, &cl);
473 req[3] = smb2_close_send(tree, &cl);
474 smb2_transport_compound_set_related(tree->session->transport, true);
475 req[4] = smb2_close_send(tree, &cl);
477 status = smb2_create_recv(req[0], tree, &cr);
478 CHECK_STATUS(status, NT_STATUS_OK);
479 status = smb2_close_recv(req[1], &cl);
480 CHECK_STATUS(status, NT_STATUS_OK);
481 status = smb2_close_recv(req[2], &cl);
482 CHECK_STATUS(status, NT_STATUS_USER_SESSION_DELETED);
483 status = smb2_close_recv(req[3], &cl);
484 CHECK_STATUS(status, NT_STATUS_USER_SESSION_DELETED);
485 status = smb2_close_recv(req[4], &cl);
486 CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);
488 TALLOC_FREE(tree->smbXcli);
489 tree->smbXcli = saved_tcon;
490 TALLOC_FREE(tree->session->smbXcli);
491 tree->session->smbXcli = saved_session;
493 smb2_util_unlink(tree, fname);
494 done:
495 return ret;
498 static bool test_compound_invalid3(struct torture_context *tctx,
499 struct smb2_tree *tree)
501 struct smb2_handle hd;
502 struct smb2_create cr;
503 NTSTATUS status;
504 const char *fname = "compound_invalid3.dat";
505 struct smb2_close cl;
506 bool ret = true;
507 struct smb2_request *req[5];
509 smb2_transport_credits_ask_num(tree->session->transport, 5);
511 smb2_util_unlink(tree, fname);
513 smb2_transport_credits_ask_num(tree->session->transport, 1);
515 ZERO_STRUCT(cr);
516 cr.in.security_flags = 0x00;
517 cr.in.oplock_level = 0;
518 cr.in.impersonation_level = NTCREATEX_IMPERSONATION_IMPERSONATION;
519 cr.in.create_flags = 0x00000000;
520 cr.in.reserved = 0x00000000;
521 cr.in.desired_access = SEC_RIGHTS_FILE_ALL;
522 cr.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
523 cr.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
524 NTCREATEX_SHARE_ACCESS_WRITE |
525 NTCREATEX_SHARE_ACCESS_DELETE;
526 cr.in.create_disposition = NTCREATEX_DISP_OPEN_IF;
527 cr.in.create_options = NTCREATEX_OPTIONS_SEQUENTIAL_ONLY |
528 NTCREATEX_OPTIONS_ASYNC_ALERT |
529 NTCREATEX_OPTIONS_NON_DIRECTORY_FILE |
530 0x00200000;
531 cr.in.fname = fname;
533 smb2_transport_compound_start(tree->session->transport, 5);
535 req[0] = smb2_create_send(tree, &cr);
537 hd.data[0] = UINT64_MAX;
538 hd.data[1] = UINT64_MAX;
540 ZERO_STRUCT(cl);
541 cl.in.file.handle = hd;
542 req[1] = smb2_close_send(tree, &cl);
543 req[2] = smb2_close_send(tree, &cl);
544 /* flipping the related flag is invalid */
545 smb2_transport_compound_set_related(tree->session->transport, true);
546 req[3] = smb2_close_send(tree, &cl);
547 req[4] = smb2_close_send(tree, &cl);
549 status = smb2_create_recv(req[0], tree, &cr);
550 CHECK_STATUS(status, NT_STATUS_OK);
551 status = smb2_close_recv(req[1], &cl);
552 CHECK_STATUS(status, NT_STATUS_FILE_CLOSED);
553 status = smb2_close_recv(req[2], &cl);
554 CHECK_STATUS(status, NT_STATUS_FILE_CLOSED);
555 status = smb2_close_recv(req[3], &cl);
556 CHECK_STATUS(status, NT_STATUS_FILE_CLOSED);
557 status = smb2_close_recv(req[4], &cl);
558 CHECK_STATUS(status, NT_STATUS_FILE_CLOSED);
560 smb2_util_unlink(tree, fname);
561 done:
562 return ret;
565 /* Send a compound request where we expect the last request (Create, Notify)
566 * to go asynchronous. This works against a Win7 server and the reply is
567 * sent in two different packets. */
568 static bool test_compound_interim1(struct torture_context *tctx,
569 struct smb2_tree *tree)
571 struct smb2_handle hd;
572 struct smb2_create cr;
573 NTSTATUS status = NT_STATUS_OK;
574 const char *dname = "compound_interim_dir";
575 struct smb2_notify nt;
576 bool ret = true;
577 struct smb2_request *req[2];
579 /* Win7 compound request implementation deviates substantially from the
580 * SMB2 spec as noted in MS-SMB2 <159>, <162>. This, test currently
581 * verifies the Windows behavior, not the general spec behavior. */
582 if (!TARGET_IS_WIN7(tctx) && !TARGET_IS_W2K8(tctx)) {
583 torture_skip(tctx, "Interim test is specific to Windows server "
584 "behavior.\n");
587 smb2_transport_credits_ask_num(tree->session->transport, 5);
589 smb2_deltree(tree, dname);
591 smb2_transport_credits_ask_num(tree->session->transport, 1);
593 ZERO_STRUCT(cr);
594 cr.in.desired_access = SEC_RIGHTS_FILE_ALL;
595 cr.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
596 cr.in.file_attributes = FILE_ATTRIBUTE_DIRECTORY;
597 cr.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
598 NTCREATEX_SHARE_ACCESS_WRITE |
599 NTCREATEX_SHARE_ACCESS_DELETE;
600 cr.in.create_disposition = NTCREATEX_DISP_CREATE;
601 cr.in.fname = dname;
603 smb2_transport_compound_start(tree->session->transport, 2);
605 req[0] = smb2_create_send(tree, &cr);
607 smb2_transport_compound_set_related(tree->session->transport, true);
609 hd.data[0] = UINT64_MAX;
610 hd.data[1] = UINT64_MAX;
612 ZERO_STRUCT(nt);
613 nt.in.recursive = true;
614 nt.in.buffer_size = 0x1000;
615 nt.in.file.handle = hd;
616 nt.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
617 nt.in.unknown = 0x00000000;
619 req[1] = smb2_notify_send(tree, &nt);
621 status = smb2_create_recv(req[0], tree, &cr);
622 CHECK_STATUS(status, NT_STATUS_OK);
624 smb2_cancel(req[1]);
625 status = smb2_notify_recv(req[1], tree, &nt);
626 CHECK_STATUS(status, NT_STATUS_CANCELLED);
628 smb2_util_close(tree, cr.out.file.handle);
630 smb2_deltree(tree, dname);
631 done:
632 return ret;
635 /* Send a compound request where we expect the middle request (Create, Notify,
636 * GetInfo) to go asynchronous. Against Win7 the sync request succeed while
637 * the async fails. All are returned in the same compound response. */
638 static bool test_compound_interim2(struct torture_context *tctx,
639 struct smb2_tree *tree)
641 struct smb2_handle hd;
642 struct smb2_create cr;
643 NTSTATUS status = NT_STATUS_OK;
644 const char *dname = "compound_interim_dir";
645 struct smb2_getinfo gf;
646 struct smb2_notify nt;
647 bool ret = true;
648 struct smb2_request *req[3];
650 /* Win7 compound request implementation deviates substantially from the
651 * SMB2 spec as noted in MS-SMB2 <159>, <162>. This, test currently
652 * verifies the Windows behavior, not the general spec behavior. */
653 if (!TARGET_IS_WIN7(tctx) && !TARGET_IS_W2K8(tctx)) {
654 torture_skip(tctx, "Interim test is specific to Windows server "
655 "behavior.\n");
658 smb2_transport_credits_ask_num(tree->session->transport, 5);
660 smb2_deltree(tree, dname);
662 smb2_transport_credits_ask_num(tree->session->transport, 1);
664 ZERO_STRUCT(cr);
665 cr.in.desired_access = SEC_RIGHTS_FILE_ALL;
666 cr.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
667 cr.in.file_attributes = FILE_ATTRIBUTE_DIRECTORY;
668 cr.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
669 NTCREATEX_SHARE_ACCESS_WRITE |
670 NTCREATEX_SHARE_ACCESS_DELETE;
671 cr.in.create_disposition = NTCREATEX_DISP_CREATE;
672 cr.in.fname = dname;
674 smb2_transport_compound_start(tree->session->transport, 3);
676 req[0] = smb2_create_send(tree, &cr);
678 smb2_transport_compound_set_related(tree->session->transport, true);
680 hd.data[0] = UINT64_MAX;
681 hd.data[1] = UINT64_MAX;
683 ZERO_STRUCT(nt);
684 nt.in.recursive = true;
685 nt.in.buffer_size = 0x1000;
686 nt.in.file.handle = hd;
687 nt.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
688 nt.in.unknown = 0x00000000;
690 req[1] = smb2_notify_send(tree, &nt);
692 ZERO_STRUCT(gf);
693 gf.in.file.handle = hd;
694 gf.in.info_type = SMB2_GETINFO_FILE;
695 gf.in.info_class = 0x04; /* FILE_BASIC_INFORMATION */
696 gf.in.output_buffer_length = 0x1000;
697 gf.in.input_buffer_length = 0;
699 req[2] = smb2_getinfo_send(tree, &gf);
701 status = smb2_create_recv(req[0], tree, &cr);
702 CHECK_STATUS(status, NT_STATUS_OK);
704 status = smb2_notify_recv(req[1], tree, &nt);
705 CHECK_STATUS(status, NT_STATUS_INTERNAL_ERROR);
707 status = smb2_getinfo_recv(req[2], tree, &gf);
708 CHECK_STATUS(status, NT_STATUS_OK);
710 smb2_util_close(tree, cr.out.file.handle);
712 smb2_deltree(tree, dname);
713 done:
714 return ret;
717 struct torture_suite *torture_smb2_compound_init(void)
719 struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "compound");
721 torture_suite_add_1smb2_test(suite, "related1", test_compound_related1);
722 torture_suite_add_1smb2_test(suite, "related2", test_compound_related2);
723 torture_suite_add_1smb2_test(suite, "related3",
724 test_compound_related3);
725 torture_suite_add_1smb2_test(suite, "unrelated1", test_compound_unrelated1);
726 torture_suite_add_1smb2_test(suite, "invalid1", test_compound_invalid1);
727 torture_suite_add_1smb2_test(suite, "invalid2", test_compound_invalid2);
728 torture_suite_add_1smb2_test(suite, "invalid3", test_compound_invalid3);
729 torture_suite_add_1smb2_test(suite, "interim1", test_compound_interim1);
730 torture_suite_add_1smb2_test(suite, "interim2", test_compound_interim2);
732 suite->description = talloc_strdup(suite, "SMB2-COMPOUND tests");
734 return suite;