s4-torture: Test for #9058
[Samba/gebeck_regimport.git] / source4 / torture / smb2 / compound.c
blob0eef3695bdbb12d8380641d24bb400e553157c73
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_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);
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[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);
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, 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;
387 ZERO_STRUCT(cl);
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);
398 done:
399 return ret;
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;
407 NTSTATUS status;
408 const char *fname = "compound_invalid2.dat";
409 struct smb2_close cl;
410 bool ret = true;
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);
421 ZERO_STRUCT(cr);
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 |
436 0x00200000;
437 cr.in.fname = fname;
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);
448 ZERO_STRUCT(cl);
449 cl.in.file.handle = hd;
451 tree->smbXcli = smbXcli_tcon_create(tree);
452 smb2cli_tcon_set_values(tree->smbXcli,
453 NULL, /* session */
454 0xFFFFFFFF, /* tcon_id */
455 0, /* type */
456 0, /* flags */
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);
489 done:
490 return ret;
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;
498 NTSTATUS status;
499 const char *fname = "compound_invalid3.dat";
500 struct smb2_close cl;
501 bool ret = true;
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);
510 ZERO_STRUCT(cr);
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 |
525 0x00200000;
526 cr.in.fname = fname;
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;
535 ZERO_STRUCT(cl);
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);
556 done:
557 return ret;
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;
571 bool ret = true;
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 "
579 "behavior.\n");
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);
588 ZERO_STRUCT(cr);
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;
596 cr.in.fname = dname;
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;
607 ZERO_STRUCT(nt);
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);
619 smb2_cancel(req[1]);
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);
626 done:
627 return ret;
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;
642 bool ret = true;
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 "
650 "behavior.\n");
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);
659 ZERO_STRUCT(cr);
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;
667 cr.in.fname = dname;
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;
678 ZERO_STRUCT(nt);
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);
687 ZERO_STRUCT(gf);
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);
708 done:
709 return ret;
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");
729 return suite;