2 Unix SMB/CIFS implementation.
4 test suite for SMB2 session setups
6 Copyright (C) Michael Adam 2012
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/util.h"
27 #include "torture/smb2/proto.h"
28 #include "../libcli/smb/smbXcli_base.h"
29 #include "lib/cmdline/cmdline.h"
30 #include "auth/credentials/credentials.h"
31 #include "auth/credentials/credentials_krb5.h"
32 #include "libcli/security/security.h"
33 #include "libcli/resolve/resolve.h"
34 #include "lib/param/param.h"
35 #include "lib/util/tevent_ntstatus.h"
37 /* Ticket lifetime we want to request in seconds */
38 #define KRB5_TICKET_LIFETIME 5
39 /* Allowed clock skew in seconds */
40 #define KRB5_CLOCKSKEW 5
41 /* Time till ticket fully expired in seconds */
42 #define KRB5_TICKET_EXPIRETIME KRB5_TICKET_LIFETIME + KRB5_CLOCKSKEW
45 #define GENSEC_GSSAPI_REQUESTED_LIFETIME(x) \
46 "gensec_gssapi:requested_life_time=" texpand(x)
48 #define CHECK_CREATED(tctx, __io, __created, __attribute) \
50 torture_assert_int_equal(tctx, (__io)->out.create_action, \
51 NTCREATEX_ACTION_ ## __created, \
52 "out.create_action incorrect"); \
53 torture_assert_int_equal(tctx, (__io)->out.size, 0, \
54 "out.size incorrect"); \
55 torture_assert_int_equal(tctx, (__io)->out.file_attr, \
57 "out.file_attr incorrect"); \
58 torture_assert_int_equal(tctx, (__io)->out.reserved2, 0, \
59 "out.reserverd2 incorrect"); \
62 #define WAIT_FOR_ASYNC_RESPONSE(req) \
63 while (!req->cancel.can_cancel && req->state <= SMB2_REQUEST_RECV) { \
64 if (tevent_loop_once(tctx->ev) != 0) { \
69 static void sleep_remaining(struct torture_context
*tctx
,
70 const struct timeval
*endtime
)
72 struct timeval current
= tevent_timeval_current();
73 double remaining_secs
= timeval_elapsed2(¤t
, endtime
);
75 remaining_secs
= remaining_secs
< 1.0 ? 1.0 : remaining_secs
;
78 "sleep for %2.f second(s) that the krb5 ticket expires",
80 smb_msleep((int)(remaining_secs
* 1000));
84 * basic test for doing a session reconnect
86 bool test_session_reconnect1(struct torture_context
*tctx
, struct smb2_tree
*tree
)
89 TALLOC_CTX
*mem_ctx
= talloc_new(tctx
);
91 struct smb2_handle _h1
;
92 struct smb2_handle
*h1
= NULL
;
93 struct smb2_handle _h2
;
94 struct smb2_handle
*h2
= NULL
;
95 struct smb2_create io1
, io2
;
96 uint64_t previous_session_id
;
98 struct smb2_tree
*tree2
= NULL
;
99 union smb_fileinfo qfinfo
;
101 /* Add some random component to the file name. */
102 snprintf(fname
, sizeof(fname
), "session_reconnect_%s.dat",
103 generate_random_str(tctx
, 8));
105 smb2_util_unlink(tree
, fname
);
107 smb2_oplock_create_share(&io1
, fname
,
108 smb2_util_share_access(""),
109 smb2_util_oplock_level("b"));
111 status
= smb2_create(tree
, mem_ctx
, &io1
);
112 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
113 "smb2_create failed");
114 _h1
= io1
.out
.file
.handle
;
116 CHECK_CREATED(tctx
, &io1
, CREATED
, FILE_ATTRIBUTE_ARCHIVE
);
117 torture_assert_int_equal(tctx
, io1
.out
.oplock_level
,
118 smb2_util_oplock_level("b"),
119 "oplock_level incorrect");
121 /* disconnect, reconnect and then do durable reopen */
122 previous_session_id
= smb2cli_session_current_id(tree
->session
->smbXcli
);
124 torture_assert_goto(tctx
, torture_smb2_connection_ext(tctx
, previous_session_id
,
125 &tree
->session
->transport
->options
, &tree2
),
127 "session reconnect failed\n");
129 /* try to access the file via the old handle */
132 qfinfo
.generic
.level
= RAW_FILEINFO_POSITION_INFORMATION
;
133 qfinfo
.generic
.in
.file
.handle
= _h1
;
134 status
= smb2_getinfo_file(tree
, mem_ctx
, &qfinfo
);
135 torture_assert_ntstatus_equal_goto(tctx
, status
,
136 NT_STATUS_USER_SESSION_DELETED
,
137 ret
, done
, "smb2_getinfo_file "
138 "returned unexpected status");
141 smb2_oplock_create_share(&io2
, fname
,
142 smb2_util_share_access(""),
143 smb2_util_oplock_level("b"));
145 status
= smb2_create(tree2
, mem_ctx
, &io2
);
146 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
147 "smb2_create failed");
149 CHECK_CREATED(tctx
, &io2
, EXISTED
, FILE_ATTRIBUTE_ARCHIVE
);
150 torture_assert_int_equal(tctx
, io1
.out
.oplock_level
,
151 smb2_util_oplock_level("b"),
152 "oplock_level incorrect");
153 _h2
= io2
.out
.file
.handle
;
158 smb2_util_close(tree
, *h1
);
161 smb2_util_close(tree2
, *h2
);
165 smb2_util_unlink(tree2
, fname
);
167 smb2_util_unlink(tree
, fname
);
172 talloc_free(mem_ctx
);
178 * basic test for doing a session reconnect on one connection
180 bool test_session_reconnect2(struct torture_context
*tctx
, struct smb2_tree
*tree
)
183 TALLOC_CTX
*mem_ctx
= talloc_new(tctx
);
185 struct smb2_handle _h1
;
186 struct smb2_handle
*h1
= NULL
;
187 struct smb2_create io1
;
188 uint64_t previous_session_id
;
190 struct smb2_session
*session2
= NULL
;
191 union smb_fileinfo qfinfo
;
193 /* Add some random component to the file name. */
194 snprintf(fname
, sizeof(fname
), "session_reconnect_%s.dat",
195 generate_random_str(tctx
, 8));
197 smb2_util_unlink(tree
, fname
);
199 smb2_oplock_create_share(&io1
, fname
,
200 smb2_util_share_access(""),
201 smb2_util_oplock_level("b"));
202 io1
.in
.create_options
|= NTCREATEX_OPTIONS_DELETE_ON_CLOSE
;
204 status
= smb2_create(tree
, mem_ctx
, &io1
);
205 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
206 "smb2_create failed");
207 _h1
= io1
.out
.file
.handle
;
209 CHECK_CREATED(tctx
, &io1
, CREATED
, FILE_ATTRIBUTE_ARCHIVE
);
210 torture_assert_int_equal(tctx
, io1
.out
.oplock_level
,
211 smb2_util_oplock_level("b"),
212 "oplock_level incorrect");
214 /* disconnect, reconnect and then do durable reopen */
215 previous_session_id
= smb2cli_session_current_id(tree
->session
->smbXcli
);
217 torture_assert(tctx
, torture_smb2_session_setup(tctx
, tree
->session
->transport
,
218 previous_session_id
, tctx
, &session2
),
219 "session reconnect (on the same connection) failed");
221 /* try to access the file via the old handle */
224 qfinfo
.generic
.level
= RAW_FILEINFO_POSITION_INFORMATION
;
225 qfinfo
.generic
.in
.file
.handle
= _h1
;
226 status
= smb2_getinfo_file(tree
, mem_ctx
, &qfinfo
);
227 torture_assert_ntstatus_equal_goto(tctx
, status
,
228 NT_STATUS_USER_SESSION_DELETED
,
229 ret
, done
, "smb2_getinfo_file "
230 "returned unexpected status");
235 smb2_util_close(tree
, *h1
);
239 talloc_free(session2
);
241 talloc_free(mem_ctx
);
246 bool test_session_reauth1(struct torture_context
*tctx
, struct smb2_tree
*tree
)
249 TALLOC_CTX
*mem_ctx
= talloc_new(tctx
);
251 struct smb2_handle _h1
;
252 struct smb2_handle
*h1
= NULL
;
253 struct smb2_create io1
;
255 union smb_fileinfo qfinfo
;
257 /* Add some random component to the file name. */
258 snprintf(fname
, sizeof(fname
), "session_reauth1_%s.dat",
259 generate_random_str(tctx
, 8));
261 smb2_util_unlink(tree
, fname
);
263 smb2_oplock_create_share(&io1
, fname
,
264 smb2_util_share_access(""),
265 smb2_util_oplock_level("b"));
267 status
= smb2_create(tree
, mem_ctx
, &io1
);
268 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
269 "smb2_create failed");
270 _h1
= io1
.out
.file
.handle
;
272 CHECK_CREATED(tctx
, &io1
, CREATED
, FILE_ATTRIBUTE_ARCHIVE
);
273 torture_assert_int_equal(tctx
, io1
.out
.oplock_level
,
274 smb2_util_oplock_level("b"),
275 "oplock_level incorrect");
277 status
= smb2_session_setup_spnego(tree
->session
,
278 samba_cmdline_get_creds(),
279 0 /* previous_session_id */);
280 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
281 "smb2_session_setup_spnego failed");
283 /* try to access the file via the old handle */
286 qfinfo
.generic
.level
= RAW_FILEINFO_POSITION_INFORMATION
;
287 qfinfo
.generic
.in
.file
.handle
= _h1
;
288 status
= smb2_getinfo_file(tree
, mem_ctx
, &qfinfo
);
289 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
290 "smb2_getinfo_file failed");
292 status
= smb2_session_setup_spnego(tree
->session
,
293 samba_cmdline_get_creds(),
294 0 /* previous_session_id */);
295 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
296 "smb2_session_setup_spnego failed");
298 /* try to access the file via the old handle */
301 qfinfo
.generic
.level
= RAW_FILEINFO_POSITION_INFORMATION
;
302 qfinfo
.generic
.in
.file
.handle
= _h1
;
303 status
= smb2_getinfo_file(tree
, mem_ctx
, &qfinfo
);
304 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
305 "smb2_getinfo_file failed");
309 smb2_util_close(tree
, *h1
);
312 smb2_util_unlink(tree
, fname
);
316 talloc_free(mem_ctx
);
321 bool test_session_reauth2(struct torture_context
*tctx
, struct smb2_tree
*tree
)
324 TALLOC_CTX
*mem_ctx
= talloc_new(tctx
);
326 struct smb2_handle _h1
;
327 struct smb2_handle
*h1
= NULL
;
328 struct smb2_create io1
;
330 union smb_fileinfo qfinfo
;
331 struct cli_credentials
*anon_creds
= NULL
;
333 /* Add some random component to the file name. */
334 snprintf(fname
, sizeof(fname
), "session_reauth2_%s.dat",
335 generate_random_str(tctx
, 8));
337 smb2_util_unlink(tree
, fname
);
339 smb2_oplock_create_share(&io1
, fname
,
340 smb2_util_share_access(""),
341 smb2_util_oplock_level("b"));
343 status
= smb2_create(tree
, mem_ctx
, &io1
);
344 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
345 "smb2_create failed");
346 _h1
= io1
.out
.file
.handle
;
348 CHECK_CREATED(tctx
, &io1
, CREATED
, FILE_ATTRIBUTE_ARCHIVE
);
349 torture_assert_int_equal(tctx
, io1
.out
.oplock_level
,
350 smb2_util_oplock_level("b"),
351 "oplock_level incorrect");
353 /* re-authenticate as anonymous */
355 anon_creds
= cli_credentials_init_anon(mem_ctx
);
356 torture_assert(tctx
, (anon_creds
!= NULL
), "talloc error");
358 status
= smb2_session_setup_spnego(tree
->session
,
360 0 /* previous_session_id */);
361 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
362 "smb2_session_setup_spnego failed");
364 /* try to access the file via the old handle */
367 qfinfo
.generic
.level
= RAW_FILEINFO_POSITION_INFORMATION
;
368 qfinfo
.generic
.in
.file
.handle
= _h1
;
369 status
= smb2_getinfo_file(tree
, mem_ctx
, &qfinfo
);
370 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
371 "smb2_getinfo_file failed");
373 /* re-authenticate as original user again */
375 status
= smb2_session_setup_spnego(tree
->session
,
376 samba_cmdline_get_creds(),
377 0 /* previous_session_id */);
378 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
379 "smb2_session_setup_spnego failed");
381 /* try to access the file via the old handle */
384 qfinfo
.generic
.level
= RAW_FILEINFO_POSITION_INFORMATION
;
385 qfinfo
.generic
.in
.file
.handle
= _h1
;
386 status
= smb2_getinfo_file(tree
, mem_ctx
, &qfinfo
);
387 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
388 "smb2_getinfo_file failed");
392 smb2_util_close(tree
, *h1
);
395 smb2_util_unlink(tree
, fname
);
399 talloc_free(mem_ctx
);
405 * test getting security descriptor after reauth
407 bool test_session_reauth3(struct torture_context
*tctx
, struct smb2_tree
*tree
)
410 TALLOC_CTX
*mem_ctx
= talloc_new(tctx
);
412 struct smb2_handle _h1
;
413 struct smb2_handle
*h1
= NULL
;
414 struct smb2_create io1
;
416 union smb_fileinfo qfinfo
;
417 struct cli_credentials
*anon_creds
= NULL
;
418 uint32_t secinfo_flags
= SECINFO_OWNER
421 | SECINFO_PROTECTED_DACL
422 | SECINFO_UNPROTECTED_DACL
;
424 /* Add some random component to the file name. */
425 snprintf(fname
, sizeof(fname
), "session_reauth3_%s.dat",
426 generate_random_str(tctx
, 8));
428 smb2_util_unlink(tree
, fname
);
430 smb2_oplock_create_share(&io1
, fname
,
431 smb2_util_share_access(""),
432 smb2_util_oplock_level("b"));
434 status
= smb2_create(tree
, mem_ctx
, &io1
);
435 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
436 "smb2_create failed");
437 _h1
= io1
.out
.file
.handle
;
439 CHECK_CREATED(tctx
, &io1
, CREATED
, FILE_ATTRIBUTE_ARCHIVE
);
440 torture_assert_int_equal(tctx
, io1
.out
.oplock_level
,
441 smb2_util_oplock_level("b"),
442 "oplock_level incorrect");
444 /* get the security descriptor */
448 qfinfo
.query_secdesc
.level
= RAW_FILEINFO_SEC_DESC
;
449 qfinfo
.query_secdesc
.in
.file
.handle
= _h1
;
450 qfinfo
.query_secdesc
.in
.secinfo_flags
= secinfo_flags
;
452 status
= smb2_getinfo_file(tree
, mem_ctx
, &qfinfo
);
453 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
454 "smb2_getinfo_file failed");
456 /* re-authenticate as anonymous */
458 anon_creds
= cli_credentials_init_anon(mem_ctx
);
459 torture_assert(tctx
, (anon_creds
!= NULL
), "talloc error");
461 status
= smb2_session_setup_spnego(tree
->session
,
463 0 /* previous_session_id */);
464 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
465 "smb2_session_setup_spnego failed");
467 /* try to access the file via the old handle */
471 qfinfo
.query_secdesc
.level
= RAW_FILEINFO_SEC_DESC
;
472 qfinfo
.query_secdesc
.in
.file
.handle
= _h1
;
473 qfinfo
.query_secdesc
.in
.secinfo_flags
= secinfo_flags
;
475 status
= smb2_getinfo_file(tree
, mem_ctx
, &qfinfo
);
476 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
477 "smb2_getinfo_file failed");
479 /* re-authenticate as original user again */
481 status
= smb2_session_setup_spnego(tree
->session
,
482 samba_cmdline_get_creds(),
483 0 /* previous_session_id */);
484 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
485 "smb2_session_setup_spnego failed");
487 /* try to access the file via the old handle */
491 qfinfo
.query_secdesc
.level
= RAW_FILEINFO_SEC_DESC
;
492 qfinfo
.query_secdesc
.in
.file
.handle
= _h1
;
493 qfinfo
.query_secdesc
.in
.secinfo_flags
= secinfo_flags
;
495 status
= smb2_getinfo_file(tree
, mem_ctx
, &qfinfo
);
496 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
497 "smb2_getinfo_file failed");
501 smb2_util_close(tree
, *h1
);
504 smb2_util_unlink(tree
, fname
);
508 talloc_free(mem_ctx
);
514 * test setting security descriptor after reauth.
516 bool test_session_reauth4(struct torture_context
*tctx
, struct smb2_tree
*tree
)
519 TALLOC_CTX
*mem_ctx
= talloc_new(tctx
);
521 struct smb2_handle _h1
;
522 struct smb2_handle
*h1
= NULL
;
523 struct smb2_create io1
;
525 union smb_fileinfo qfinfo
;
526 union smb_setfileinfo sfinfo
;
527 struct cli_credentials
*anon_creds
= NULL
;
528 uint32_t secinfo_flags
= SECINFO_OWNER
531 | SECINFO_PROTECTED_DACL
532 | SECINFO_UNPROTECTED_DACL
;
533 struct security_descriptor
*sd1
;
534 struct security_ace ace
;
535 struct dom_sid
*extra_sid
;
537 /* Add some random component to the file name. */
538 snprintf(fname
, sizeof(fname
), "session_reauth4_%s.dat",
539 generate_random_str(tctx
, 8));
541 smb2_util_unlink(tree
, fname
);
543 smb2_oplock_create_share(&io1
, fname
,
544 smb2_util_share_access(""),
545 smb2_util_oplock_level("b"));
547 status
= smb2_create(tree
, mem_ctx
, &io1
);
548 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
549 "smb2_create failed");
550 _h1
= io1
.out
.file
.handle
;
552 CHECK_CREATED(tctx
, &io1
, CREATED
, FILE_ATTRIBUTE_ARCHIVE
);
553 torture_assert_int_equal(tctx
, io1
.out
.oplock_level
,
554 smb2_util_oplock_level("b"),
555 "oplock_level incorrect");
557 /* get the security descriptor */
561 qfinfo
.query_secdesc
.level
= RAW_FILEINFO_SEC_DESC
;
562 qfinfo
.query_secdesc
.in
.file
.handle
= _h1
;
563 qfinfo
.query_secdesc
.in
.secinfo_flags
= secinfo_flags
;
565 status
= smb2_getinfo_file(tree
, mem_ctx
, &qfinfo
);
566 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
567 "smb2_getinfo_file failed");
569 sd1
= qfinfo
.query_secdesc
.out
.sd
;
571 /* re-authenticate as anonymous */
573 anon_creds
= cli_credentials_init_anon(mem_ctx
);
574 torture_assert(tctx
, (anon_creds
!= NULL
), "talloc error");
576 status
= smb2_session_setup_spnego(tree
->session
,
578 0 /* previous_session_id */);
579 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
580 "smb2_session_setup_spnego failed");
582 /* give full access on the file to anonymous */
584 extra_sid
= dom_sid_parse_talloc(tctx
, SID_NT_ANONYMOUS
);
587 ace
.type
= SEC_ACE_TYPE_ACCESS_ALLOWED
;
589 ace
.access_mask
= SEC_STD_ALL
| SEC_FILE_ALL
;
590 ace
.trustee
= *extra_sid
;
592 status
= security_descriptor_dacl_add(sd1
, &ace
);
593 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
594 "security_descriptor_dacl_add failed");
597 sfinfo
.set_secdesc
.level
= RAW_SFILEINFO_SEC_DESC
;
598 sfinfo
.set_secdesc
.in
.file
.handle
= _h1
;
599 sfinfo
.set_secdesc
.in
.secinfo_flags
= SECINFO_DACL
;
600 sfinfo
.set_secdesc
.in
.sd
= sd1
;
602 status
= smb2_setinfo_file(tree
, &sfinfo
);
603 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
604 "smb2_setinfo_file failed");
606 /* re-authenticate as original user again */
608 status
= smb2_session_setup_spnego(tree
->session
,
609 samba_cmdline_get_creds(),
610 0 /* previous_session_id */);
611 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
612 "smb2_session_setup_spnego failed");
614 /* re-get the security descriptor */
618 qfinfo
.query_secdesc
.level
= RAW_FILEINFO_SEC_DESC
;
619 qfinfo
.query_secdesc
.in
.file
.handle
= _h1
;
620 qfinfo
.query_secdesc
.in
.secinfo_flags
= secinfo_flags
;
622 status
= smb2_getinfo_file(tree
, mem_ctx
, &qfinfo
);
623 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
624 "smb2_getinfo_file failed");
630 smb2_util_close(tree
, *h1
);
633 smb2_util_unlink(tree
, fname
);
637 talloc_free(mem_ctx
);
643 * test renaming after reauth.
644 * compare security descriptors before and after rename/reauth
646 bool test_session_reauth5(struct torture_context
*tctx
, struct smb2_tree
*tree
)
649 TALLOC_CTX
*mem_ctx
= talloc_new(tctx
);
653 struct smb2_handle _dh1
;
654 struct smb2_handle
*dh1
= NULL
;
655 struct smb2_handle _h1
;
656 struct smb2_handle
*h1
= NULL
;
657 struct smb2_create io1
;
660 union smb_fileinfo qfinfo
;
661 union smb_setfileinfo sfinfo
;
662 struct cli_credentials
*anon_creds
= NULL
;
663 uint32_t secinfo_flags
= SECINFO_OWNER
666 | SECINFO_PROTECTED_DACL
667 | SECINFO_UNPROTECTED_DACL
;
668 struct security_descriptor
*f_sd1
;
669 struct security_descriptor
*d_sd1
= NULL
;
670 struct security_ace ace
;
671 struct dom_sid
*extra_sid
;
673 /* Add some random component to the file name. */
674 snprintf(dname
, sizeof(dname
), "session_reauth5_%s.d",
675 generate_random_str(tctx
, 8));
676 snprintf(fname
, sizeof(fname
), "%s\\file.dat", dname
);
678 ok
= smb2_util_setup_dir(tctx
, tree
, dname
);
679 torture_assert(tctx
, ok
, "smb2_util_setup_dir not ok");
681 status
= torture_smb2_testdir(tree
, dname
, &_dh1
);
682 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
683 "torture_smb2_testdir failed");
686 smb2_oplock_create_share(&io1
, fname
,
687 smb2_util_share_access(""),
688 smb2_util_oplock_level("b"));
690 status
= smb2_create(tree
, mem_ctx
, &io1
);
691 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
692 "smb2_create failed");
693 _h1
= io1
.out
.file
.handle
;
695 CHECK_CREATED(tctx
, &io1
, CREATED
, FILE_ATTRIBUTE_ARCHIVE
);
696 torture_assert_int_equal(tctx
, io1
.out
.oplock_level
,
697 smb2_util_oplock_level("b"),
698 "oplock_level incorrect");
700 /* get the security descriptor */
704 qfinfo
.query_secdesc
.level
= RAW_FILEINFO_SEC_DESC
;
705 qfinfo
.query_secdesc
.in
.file
.handle
= _h1
;
706 qfinfo
.query_secdesc
.in
.secinfo_flags
= secinfo_flags
;
708 status
= smb2_getinfo_file(tree
, mem_ctx
, &qfinfo
);
709 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
710 "smb2_getinfo_file failed");
712 f_sd1
= qfinfo
.query_secdesc
.out
.sd
;
714 /* re-authenticate as anonymous */
716 anon_creds
= cli_credentials_init_anon(mem_ctx
);
717 torture_assert(tctx
, (anon_creds
!= NULL
), "talloc error");
719 status
= smb2_session_setup_spnego(tree
->session
,
721 0 /* previous_session_id */);
722 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
723 "smb2_session_setup_spnego failed");
725 /* try to rename the file: fails */
727 snprintf(fname2
, sizeof(fname2
), "%s\\file2.dat", dname
);
729 status
= smb2_util_unlink(tree
, fname2
);
730 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
731 "smb2_util_unlink failed");
735 sfinfo
.rename_information
.level
= RAW_SFILEINFO_RENAME_INFORMATION
;
736 sfinfo
.rename_information
.in
.file
.handle
= _h1
;
737 sfinfo
.rename_information
.in
.overwrite
= true;
738 sfinfo
.rename_information
.in
.new_name
= fname2
;
740 status
= smb2_setinfo_file(tree
, &sfinfo
);
741 torture_assert_ntstatus_equal_goto(tctx
, status
,
742 NT_STATUS_ACCESS_DENIED
,
743 ret
, done
, "smb2_setinfo_file "
744 "returned unexpected status");
746 /* re-authenticate as original user again */
748 status
= smb2_session_setup_spnego(tree
->session
,
749 samba_cmdline_get_creds(),
750 0 /* previous_session_id */);
751 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
752 "smb2_session_setup_spnego failed");
754 /* give full access on the file to anonymous */
756 extra_sid
= dom_sid_parse_talloc(tctx
, SID_NT_ANONYMOUS
);
759 ace
.type
= SEC_ACE_TYPE_ACCESS_ALLOWED
;
761 ace
.access_mask
= SEC_RIGHTS_FILE_ALL
;
762 ace
.trustee
= *extra_sid
;
764 status
= security_descriptor_dacl_add(f_sd1
, &ace
);
765 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
766 "security_descriptor_dacl_add failed");
769 sfinfo
.set_secdesc
.level
= RAW_SFILEINFO_SEC_DESC
;
770 sfinfo
.set_secdesc
.in
.file
.handle
= _h1
;
771 sfinfo
.set_secdesc
.in
.secinfo_flags
= secinfo_flags
;
772 sfinfo
.set_secdesc
.in
.sd
= f_sd1
;
774 status
= smb2_setinfo_file(tree
, &sfinfo
);
775 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
776 "smb2_setinfo_file failed");
778 /* re-get the security descriptor */
782 qfinfo
.query_secdesc
.level
= RAW_FILEINFO_SEC_DESC
;
783 qfinfo
.query_secdesc
.in
.file
.handle
= _h1
;
784 qfinfo
.query_secdesc
.in
.secinfo_flags
= secinfo_flags
;
786 status
= smb2_getinfo_file(tree
, mem_ctx
, &qfinfo
);
787 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
788 "smb2_getinfo_file failed");
790 /* re-authenticate as anonymous - again */
792 anon_creds
= cli_credentials_init_anon(mem_ctx
);
793 torture_assert(tctx
, (anon_creds
!= NULL
), "talloc error");
795 status
= smb2_session_setup_spnego(tree
->session
,
797 0 /* previous_session_id */);
798 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
799 "smb2_session_setup_spnego failed");
801 /* try to rename the file: fails */
804 sfinfo
.rename_information
.level
= RAW_SFILEINFO_RENAME_INFORMATION
;
805 sfinfo
.rename_information
.in
.file
.handle
= _h1
;
806 sfinfo
.rename_information
.in
.overwrite
= true;
807 sfinfo
.rename_information
.in
.new_name
= fname2
;
809 status
= smb2_setinfo_file(tree
, &sfinfo
);
810 torture_assert_ntstatus_equal_goto(tctx
, status
,
811 NT_STATUS_ACCESS_DENIED
,
812 ret
, done
, "smb2_setinfo_file "
813 "returned unexpected status");
815 /* give full access on the parent dir to anonymous */
819 qfinfo
.query_secdesc
.level
= RAW_FILEINFO_SEC_DESC
;
820 qfinfo
.query_secdesc
.in
.file
.handle
= _dh1
;
821 qfinfo
.query_secdesc
.in
.secinfo_flags
= secinfo_flags
;
823 status
= smb2_getinfo_file(tree
, mem_ctx
, &qfinfo
);
824 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
825 "smb2_getinfo_file failed");
827 d_sd1
= qfinfo
.query_secdesc
.out
.sd
;
830 ace
.type
= SEC_ACE_TYPE_ACCESS_ALLOWED
;
832 ace
.access_mask
= SEC_RIGHTS_FILE_ALL
;
833 ace
.trustee
= *extra_sid
;
835 status
= security_descriptor_dacl_add(d_sd1
, &ace
);
836 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
837 "security_descriptor_dacl_add failed");
840 sfinfo
.set_secdesc
.level
= RAW_SFILEINFO_SEC_DESC
;
841 sfinfo
.set_secdesc
.in
.file
.handle
= _dh1
;
842 sfinfo
.set_secdesc
.in
.secinfo_flags
= secinfo_flags
;
843 sfinfo
.set_secdesc
.in
.secinfo_flags
= SECINFO_DACL
;
844 sfinfo
.set_secdesc
.in
.sd
= d_sd1
;
846 status
= smb2_setinfo_file(tree
, &sfinfo
);
847 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
848 "smb2_setinfo_file failed");
852 qfinfo
.query_secdesc
.level
= RAW_FILEINFO_SEC_DESC
;
853 qfinfo
.query_secdesc
.in
.file
.handle
= _dh1
;
854 qfinfo
.query_secdesc
.in
.secinfo_flags
= secinfo_flags
;
856 status
= smb2_getinfo_file(tree
, mem_ctx
, &qfinfo
);
857 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
858 "smb2_getinfo_file failed");
860 status
= smb2_util_close(tree
, _dh1
);
861 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
862 "smb2_util_close failed");
865 /* try to rename the file: still fails */
868 sfinfo
.rename_information
.level
= RAW_SFILEINFO_RENAME_INFORMATION
;
869 sfinfo
.rename_information
.in
.file
.handle
= _h1
;
870 sfinfo
.rename_information
.in
.overwrite
= true;
871 sfinfo
.rename_information
.in
.new_name
= fname2
;
873 status
= smb2_setinfo_file(tree
, &sfinfo
);
874 torture_assert_ntstatus_equal_goto(tctx
, status
,
875 NT_STATUS_ACCESS_DENIED
,
876 ret
, done
, "smb2_setinfo_file "
877 "returned unexpected status");
879 /* re-authenticate as original user - again */
881 status
= smb2_session_setup_spnego(tree
->session
,
882 samba_cmdline_get_creds(),
883 0 /* previous_session_id */);
884 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
885 "smb2_session_setup_spnego failed");
887 /* rename the file - for verification that it works */
890 sfinfo
.rename_information
.level
= RAW_SFILEINFO_RENAME_INFORMATION
;
891 sfinfo
.rename_information
.in
.file
.handle
= _h1
;
892 sfinfo
.rename_information
.in
.overwrite
= true;
893 sfinfo
.rename_information
.in
.new_name
= fname2
;
895 status
= smb2_setinfo_file(tree
, &sfinfo
);
896 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
897 "smb2_setinfo_file failed");
899 /* closs the file, check it is gone and reopen under the new name */
901 status
= smb2_util_close(tree
, _h1
);
902 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
903 "smb2_util_close failed");
906 smb2_generic_create_share(&io1
,
907 NULL
/* lease */, false /* dir */,
910 smb2_util_share_access(""),
911 smb2_util_oplock_level("b"),
912 0 /* leasekey */, 0 /* leasestate */);
914 status
= smb2_create(tree
, mem_ctx
, &io1
);
915 torture_assert_ntstatus_equal_goto(tctx
, status
,
916 NT_STATUS_OBJECT_NAME_NOT_FOUND
,
917 ret
, done
, "smb2_create "
918 "returned unexpected status");
922 smb2_generic_create_share(&io1
,
923 NULL
/* lease */, false /* dir */,
926 smb2_util_share_access(""),
927 smb2_util_oplock_level("b"),
928 0 /* leasekey */, 0 /* leasestate */);
930 status
= smb2_create(tree
, mem_ctx
, &io1
);
931 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
932 "smb2_create failed");
933 _h1
= io1
.out
.file
.handle
;
935 CHECK_CREATED(tctx
, &io1
, EXISTED
, FILE_ATTRIBUTE_ARCHIVE
);
936 torture_assert_int_equal(tctx
, io1
.out
.oplock_level
,
937 smb2_util_oplock_level("b"),
938 "oplock_level incorrect");
940 /* try to access the file via the old handle */
944 qfinfo
.query_secdesc
.level
= RAW_FILEINFO_SEC_DESC
;
945 qfinfo
.query_secdesc
.in
.file
.handle
= _h1
;
946 qfinfo
.query_secdesc
.in
.secinfo_flags
= secinfo_flags
;
948 status
= smb2_getinfo_file(tree
, mem_ctx
, &qfinfo
);
949 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
950 "smb2_getinfo_file failed");
954 smb2_util_close(tree
, *dh1
);
957 smb2_util_close(tree
, *h1
);
960 smb2_deltree(tree
, dname
);
964 talloc_free(mem_ctx
);
970 * do reauth with wrong credentials,
971 * hence triggering the error path in reauth.
972 * The invalid reauth deletes the session.
974 bool test_session_reauth6(struct torture_context
*tctx
, struct smb2_tree
*tree
)
977 TALLOC_CTX
*mem_ctx
= talloc_new(tctx
);
979 struct smb2_handle _h1
;
980 struct smb2_handle
*h1
= NULL
;
981 struct smb2_create io1
;
983 char *corrupted_password
;
984 struct cli_credentials
*broken_creds
;
988 enum credentials_use_kerberos krb_state
;
990 krb_state
= cli_credentials_get_kerberos_state(
991 samba_cmdline_get_creds());
992 if (krb_state
== CRED_USE_KERBEROS_REQUIRED
) {
994 "Can't test failing session setup with kerberos.");
997 encrypted
= smb2cli_tcon_is_encryption_on(tree
->smbXcli
);
999 /* Add some random component to the file name. */
1000 snprintf(fname
, sizeof(fname
), "session_reauth1_%s.dat",
1001 generate_random_str(tctx
, 8));
1003 smb2_util_unlink(tree
, fname
);
1005 smb2_oplock_create_share(&io1
, fname
,
1006 smb2_util_share_access(""),
1007 smb2_util_oplock_level("b"));
1008 io1
.in
.create_options
|= NTCREATEX_OPTIONS_DELETE_ON_CLOSE
;
1010 status
= smb2_create(tree
, mem_ctx
, &io1
);
1011 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
1012 "smb2_create failed");
1013 _h1
= io1
.out
.file
.handle
;
1015 CHECK_CREATED(tctx
, &io1
, CREATED
, FILE_ATTRIBUTE_ARCHIVE
);
1016 torture_assert_int_equal(tctx
, io1
.out
.oplock_level
,
1017 smb2_util_oplock_level("b"),
1018 "oplock_level incorrect");
1021 * reauthentication with invalid credentials:
1024 broken_creds
= cli_credentials_shallow_copy(mem_ctx
,
1025 samba_cmdline_get_creds());
1026 torture_assert(tctx
, (broken_creds
!= NULL
), "talloc error");
1028 corrupted_password
= talloc_asprintf(mem_ctx
, "%s%s",
1029 cli_credentials_get_password(broken_creds
),
1031 torture_assert(tctx
, (corrupted_password
!= NULL
), "talloc error");
1033 ok
= cli_credentials_set_password(broken_creds
, corrupted_password
,
1035 torture_assert(tctx
, ok
, "cli_credentials_set_password not ok");
1037 status
= smb2_session_setup_spnego(tree
->session
,
1039 0 /* previous_session_id */);
1040 torture_assert_ntstatus_equal_goto(tctx
, status
,
1041 NT_STATUS_LOGON_FAILURE
, ret
, done
,
1042 "smb2_session_setup_spnego "
1043 "returned unexpected status");
1045 torture_comment(tctx
, "did failed reauth\n");
1047 * now verify that the invalid session reauth has closed our session
1051 expected
= NT_STATUS_CONNECTION_DISCONNECTED
;
1053 expected
= NT_STATUS_USER_SESSION_DELETED
;
1056 smb2_oplock_create_share(&io1
, fname
,
1057 smb2_util_share_access(""),
1058 smb2_util_oplock_level("b"));
1060 status
= smb2_create(tree
, mem_ctx
, &io1
);
1061 torture_assert_ntstatus_equal_goto(tctx
, status
, expected
,
1062 ret
, done
, "smb2_create "
1063 "returned unexpected status");
1067 smb2_util_close(tree
, *h1
);
1070 smb2_util_unlink(tree
, fname
);
1074 talloc_free(mem_ctx
);
1080 static bool test_session_expire1i(struct torture_context
*tctx
,
1082 bool force_encryption
)
1086 struct smbcli_options options
;
1087 const char *host
= torture_setting_string(tctx
, "host", NULL
);
1088 const char *share
= torture_setting_string(tctx
, "share", NULL
);
1089 struct cli_credentials
*credentials
= samba_cmdline_get_creds();
1090 struct smb2_tree
*tree
= NULL
;
1091 enum credentials_use_kerberos use_kerberos
;
1093 struct smb2_handle _h1
;
1094 struct smb2_handle
*h1
= NULL
;
1095 struct smb2_create io1
;
1096 union smb_fileinfo qfinfo
;
1098 struct timeval endtime
;
1099 bool ticket_expired
= false;
1101 use_kerberos
= cli_credentials_get_kerberos_state(credentials
);
1102 if (use_kerberos
!= CRED_USE_KERBEROS_REQUIRED
) {
1103 torture_warning(tctx
,
1104 "smb2.session.expire1 requires "
1105 "--use-kerberos=required!");
1107 "smb2.session.expire1 requires "
1108 "--use-kerberos=required!");
1111 torture_assert_int_equal(tctx
,
1113 CRED_USE_KERBEROS_REQUIRED
,
1114 "please use --use-kerberos=required");
1116 cli_credentials_invalidate_ccache(credentials
, CRED_SPECIFIED
);
1120 GENSEC_GSSAPI_REQUESTED_LIFETIME(KRB5_TICKET_LIFETIME
));
1122 lpcfg_smbcli_options(tctx
->lp_ctx
, &options
);
1123 if (force_signing
) {
1124 options
.signing
= SMB_SIGNING_REQUIRED
;
1127 status
= smb2_connect(tctx
,
1129 lpcfg_smb_ports(tctx
->lp_ctx
),
1131 lpcfg_resolve_context(tctx
->lp_ctx
),
1136 lpcfg_socket_options(tctx
->lp_ctx
),
1137 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
)
1140 * We request a ticket lifetime of KRB5_TICKET_LIFETIME seconds.
1141 * Give the server at least KRB5_TICKET_LIFETIME + KRB5_CLOCKSKEW + a
1142 * few more milliseconds for this to kick in.
1144 endtime
= timeval_current_ofs(KRB5_TICKET_EXPIRETIME
, 500 * 1000);
1145 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
1146 "smb2_connect failed");
1148 if (force_encryption
) {
1149 status
= smb2cli_session_encryption_on(tree
->session
->smbXcli
);
1150 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
1151 "smb2cli_session_encryption_on failed");
1154 /* Add some random component to the file name. */
1155 snprintf(fname
, sizeof(fname
), "session_expire1_%s.dat",
1156 generate_random_str(tctx
, 8));
1158 smb2_util_unlink(tree
, fname
);
1160 smb2_oplock_create_share(&io1
, fname
,
1161 smb2_util_share_access(""),
1162 smb2_util_oplock_level("b"));
1163 io1
.in
.create_options
|= NTCREATEX_OPTIONS_DELETE_ON_CLOSE
;
1165 status
= smb2_create(tree
, tctx
, &io1
);
1166 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
1167 "smb2_create failed");
1168 _h1
= io1
.out
.file
.handle
;
1170 CHECK_CREATED(tctx
, &io1
, CREATED
, FILE_ATTRIBUTE_ARCHIVE
);
1171 torture_assert_int_equal(tctx
, io1
.out
.oplock_level
,
1172 smb2_util_oplock_level("b"),
1173 "oplock_level incorrect");
1175 /* get the security descriptor */
1177 ZERO_STRUCT(qfinfo
);
1179 qfinfo
.access_information
.level
= RAW_FILEINFO_ACCESS_INFORMATION
;
1180 qfinfo
.access_information
.in
.file
.handle
= _h1
;
1182 for (i
=0; i
< 2; i
++) {
1183 torture_comment(tctx
, "%s: query info => OK\n",
1184 current_timestring(tctx
, true));
1186 ZERO_STRUCT(qfinfo
.access_information
.out
);
1187 status
= smb2_getinfo_file(tree
, tctx
, &qfinfo
);
1188 torture_comment(tctx
, "%s: %s:%s: after smb2_getinfo_file() => %s\n",
1189 current_timestring(tctx
, true),
1190 __location__
, __func__
,
1192 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
1193 "smb2_getinfo_file failed");
1195 sleep_remaining(tctx
, &endtime
);
1197 torture_comment(tctx
, "%s: query info => EXPIRED\n",
1198 current_timestring(tctx
, true));
1199 ZERO_STRUCT(qfinfo
.access_information
.out
);
1200 status
= smb2_getinfo_file(tree
, tctx
, &qfinfo
);
1201 torture_comment(tctx
, "%s: %s:%s: after smb2_getinfo_file() => %s\n",
1202 current_timestring(tctx
, true),
1203 __location__
, __func__
,
1205 torture_assert_ntstatus_equal_goto(tctx
, status
,
1206 NT_STATUS_NETWORK_SESSION_EXPIRED
,
1207 ret
, done
, "smb2_getinfo_file "
1208 "returned unexpected status");
1211 * the krb5 library may not handle expired creds
1212 * well, lets start with an empty ccache.
1214 cli_credentials_invalidate_ccache(credentials
, CRED_SPECIFIED
);
1216 if (!force_encryption
) {
1217 smb2cli_session_require_signed_response(
1218 tree
->session
->smbXcli
, true);
1221 torture_comment(tctx
, "%s: reauth => OK\n",
1222 current_timestring(tctx
, true));
1223 status
= smb2_session_setup_spnego(tree
->session
,
1225 0 /* previous_session_id */);
1227 * We request a ticket lifetime of KRB5_TICKET_LIFETIME seconds.
1228 * Give the server at least KRB5_TICKET_LIFETIME +
1229 * KRB5_CLOCKSKEW + a few more milliseconds for this to kick in.
1231 endtime
= timeval_current_ofs(KRB5_TICKET_EXPIRETIME
,
1233 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
1234 "smb2_session_setup_spnego failed");
1236 smb2cli_session_require_signed_response(
1237 tree
->session
->smbXcli
, false);
1240 ticket_expired
= timeval_expired(&endtime
);
1241 if (ticket_expired
) {
1242 struct timeval current
= timeval_current();
1243 double remaining_secs
= timeval_elapsed2(¤t
, &endtime
);
1244 remaining_secs
= remaining_secs
< 0.0 ? remaining_secs
* -1.0
1248 "The ticket already expired %.2f seconds ago. "
1249 "You might want to increase KRB5_TICKET_LIFETIME.",
1252 torture_assert(tctx
,
1253 ticket_expired
== false,
1254 "The kerberos ticket already expired");
1255 ZERO_STRUCT(qfinfo
.access_information
.out
);
1256 torture_comment(tctx
, "%s: %s:%s: before smb2_getinfo_file()\n",
1257 current_timestring(tctx
, true),
1258 __location__
, __func__
);
1259 status
= smb2_getinfo_file(tree
, tctx
, &qfinfo
);
1260 torture_comment(tctx
, "%s: %s:%s: after smb2_getinfo_file() => %s\n",
1261 current_timestring(tctx
, true),
1262 __location__
, __func__
,
1264 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
1265 "smb2_getinfo_file failed");
1269 cli_credentials_invalidate_ccache(credentials
, CRED_SPECIFIED
);
1272 smb2_util_close(tree
, *h1
);
1276 lpcfg_set_option(tctx
->lp_ctx
, GENSEC_GSSAPI_REQUESTED_LIFETIME(0));
1280 static bool test_session_expire1n(struct torture_context
*tctx
)
1282 return test_session_expire1i(tctx
,
1283 false, /* force_signing */
1284 false); /* force_encryption */
1287 static bool test_session_expire1s(struct torture_context
*tctx
)
1289 return test_session_expire1i(tctx
,
1290 true, /* force_signing */
1291 false); /* force_encryption */
1294 static bool test_session_expire1e(struct torture_context
*tctx
)
1296 return test_session_expire1i(tctx
,
1297 true, /* force_signing */
1298 true); /* force_encryption */
1301 static bool test_session_expire2i(struct torture_context
*tctx
,
1302 bool force_encryption
)
1306 struct smbcli_options options
;
1307 const char *host
= torture_setting_string(tctx
, "host", NULL
);
1308 const char *share
= torture_setting_string(tctx
, "share", NULL
);
1309 struct cli_credentials
*credentials
= samba_cmdline_get_creds();
1310 struct smb2_tree
*tree
= NULL
;
1311 const char *unc
= NULL
;
1312 struct smb2_tree
*tree2
= NULL
;
1313 struct tevent_req
*subreq
= NULL
;
1314 uint32_t timeout_msec
;
1315 enum credentials_use_kerberos use_kerberos
;
1318 struct smb2_handle dh
;
1319 struct smb2_handle dh2
;
1320 struct smb2_handle relhandle
= { .data
= { UINT64_MAX
, UINT64_MAX
} };
1321 struct smb2_handle _h1
;
1322 struct smb2_handle
*h1
= NULL
;
1323 struct smb2_create io1
;
1324 union smb_fileinfo qfinfo
;
1325 union smb_setfileinfo sfinfo
;
1326 struct smb2_flush flsh
;
1327 struct smb2_read rd
;
1328 const uint8_t wd
= 0;
1329 struct smb2_lock lck
;
1330 struct smb2_lock_element el
;
1331 struct smb2_ioctl ctl
;
1332 struct smb2_break oack
;
1333 struct smb2_lease_break_ack lack
;
1334 struct smb2_create cio
;
1335 struct smb2_find fnd
;
1336 struct smb2_close cl
;
1337 struct smb2_request
*reqs
[3] = { NULL
, };
1338 union smb_search_data
*d
= NULL
;
1340 struct smb2_request
*req
= NULL
;
1341 struct smb2_notify ntf1
;
1342 struct smb2_notify ntf2
;
1343 struct timeval endtime
;
1345 use_kerberos
= cli_credentials_get_kerberos_state(credentials
);
1346 if (use_kerberos
!= CRED_USE_KERBEROS_REQUIRED
) {
1347 torture_warning(tctx
,
1348 "smb2.session.expire1 requires "
1349 "--use-kerberos=required!");
1351 "smb2.session.expire1 requires "
1352 "--use-kerberos=required!");
1355 torture_assert_int_equal(tctx
,
1357 CRED_USE_KERBEROS_REQUIRED
,
1358 "please use --use-kerberos=required");
1360 cli_credentials_invalidate_ccache(credentials
, CRED_SPECIFIED
);
1364 GENSEC_GSSAPI_REQUESTED_LIFETIME(KRB5_TICKET_LIFETIME
));
1366 lpcfg_smbcli_options(tctx
->lp_ctx
, &options
);
1367 options
.signing
= SMB_SIGNING_REQUIRED
;
1369 unc
= talloc_asprintf(tctx
, "\\\\%s\\%s", host
, share
);
1370 torture_assert(tctx
, unc
!= NULL
, "talloc_asprintf");
1372 status
= smb2_connect(tctx
,
1374 lpcfg_smb_ports(tctx
->lp_ctx
),
1376 lpcfg_resolve_context(tctx
->lp_ctx
),
1381 lpcfg_socket_options(tctx
->lp_ctx
),
1382 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
)
1385 * We request a ticket lifetime of KRB5_TICKET_LIFETIME seconds.
1386 * Give the server at least KRB5_TICKET_LIFETIME + KRB5_CLOCKSKEW + a
1387 * few more milliseconds for this to kick in.
1389 endtime
= timeval_current_ofs(KRB5_TICKET_EXPIRETIME
, 500 * 1000);
1390 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
1391 "smb2_connect failed");
1393 if (force_encryption
) {
1394 status
= smb2cli_session_encryption_on(tree
->session
->smbXcli
);
1395 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
1396 "smb2cli_session_encryption_on failed");
1399 caps
= smb2cli_conn_server_capabilities(tree
->session
->transport
->conn
);
1401 /* Add some random component to the file name. */
1402 snprintf(fname
, sizeof(fname
), "session_expire2_%s.dat",
1403 generate_random_str(tctx
, 8));
1405 smb2_util_unlink(tree
, fname
);
1407 status
= smb2_util_roothandle(tree
, &dh
);
1408 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
1409 "smb2_util_roothandle failed");
1411 smb2_oplock_create_share(&io1
, fname
,
1412 smb2_util_share_access(""),
1413 smb2_util_oplock_level("b"));
1414 io1
.in
.create_options
|= NTCREATEX_OPTIONS_DELETE_ON_CLOSE
;
1416 status
= smb2_create(tree
, tctx
, &io1
);
1417 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
1418 "smb2_create failed");
1419 _h1
= io1
.out
.file
.handle
;
1421 CHECK_CREATED(tctx
, &io1
, CREATED
, FILE_ATTRIBUTE_ARCHIVE
);
1422 torture_assert_int_equal(tctx
, io1
.out
.oplock_level
,
1423 smb2_util_oplock_level("b"),
1424 "oplock_level incorrect");
1426 /* get the security descriptor */
1428 ZERO_STRUCT(qfinfo
);
1430 qfinfo
.access_information
.level
= RAW_FILEINFO_ACCESS_INFORMATION
;
1431 qfinfo
.access_information
.in
.file
.handle
= _h1
;
1433 torture_comment(tctx
, "query info => OK\n");
1435 ZERO_STRUCT(qfinfo
.access_information
.out
);
1436 status
= smb2_getinfo_file(tree
, tctx
, &qfinfo
);
1437 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
1438 "smb2_getinfo_file failed");
1440 torture_comment(tctx
, "lock => OK\n");
1443 lck
.in
.lock_count
= 0x0001;
1444 lck
.in
.lock_sequence
= 0x00000000;
1445 lck
.in
.file
.handle
= *h1
;
1447 el
.flags
= SMB2_LOCK_FLAG_EXCLUSIVE
|
1448 SMB2_LOCK_FLAG_FAIL_IMMEDIATELY
;
1449 el
.offset
= 0x0000000000000000;
1450 el
.length
= 0x0000000000000001;
1451 status
= smb2_lock(tree
, &lck
);
1452 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
1453 "smb2_lock lock failed");
1455 torture_comment(tctx
, "1st notify => PENDING\n");
1457 ntf1
.in
.file
.handle
= dh
;
1458 ntf1
.in
.recursive
= 0x0000;
1459 ntf1
.in
.buffer_size
= 128;
1460 ntf1
.in
.completion_filter
= FILE_NOTIFY_CHANGE_ATTRIBUTES
;
1461 ntf1
.in
.unknown
= 0x00000000;
1462 req
= smb2_notify_send(tree
, &ntf1
);
1464 while (!req
->cancel
.can_cancel
&& req
->state
<= SMB2_REQUEST_RECV
) {
1465 if (tevent_loop_once(tctx
->ev
) != 0) {
1470 torture_assert_goto(tctx
, req
->state
<= SMB2_REQUEST_RECV
, ret
, done
,
1471 "smb2_notify finished");
1473 sleep_remaining(tctx
, &endtime
);
1475 torture_comment(tctx
, "query info => EXPIRED\n");
1476 ZERO_STRUCT(qfinfo
.access_information
.out
);
1477 status
= smb2_getinfo_file(tree
, tctx
, &qfinfo
);
1478 torture_assert_ntstatus_equal_goto(tctx
, status
,
1479 NT_STATUS_NETWORK_SESSION_EXPIRED
,
1480 ret
, done
, "smb2_getinfo_file "
1481 "returned unexpected status");
1484 torture_comment(tctx
, "set info => EXPIRED\n");
1485 ZERO_STRUCT(sfinfo
);
1486 sfinfo
.end_of_file_info
.level
= RAW_SFILEINFO_END_OF_FILE_INFORMATION
;
1487 sfinfo
.end_of_file_info
.in
.file
.handle
= *h1
;
1488 sfinfo
.end_of_file_info
.in
.size
= 1;
1489 status
= smb2_setinfo_file(tree
, &sfinfo
);
1490 torture_assert_ntstatus_equal_goto(tctx
, status
,
1491 NT_STATUS_NETWORK_SESSION_EXPIRED
,
1492 ret
, done
, "smb2_setinfo_file "
1493 "returned unexpected status");
1495 torture_comment(tctx
, "flush => EXPIRED\n");
1497 flsh
.in
.file
.handle
= *h1
;
1498 status
= smb2_flush(tree
, &flsh
);
1499 torture_assert_ntstatus_equal_goto(tctx
, status
,
1500 NT_STATUS_NETWORK_SESSION_EXPIRED
,
1501 ret
, done
, "smb2_flush "
1502 "returned unexpected status");
1504 torture_comment(tctx
, "read => EXPIRED\n");
1506 rd
.in
.file
.handle
= *h1
;
1509 status
= smb2_read(tree
, tctx
, &rd
);
1510 torture_assert_ntstatus_equal_goto(tctx
, status
,
1511 NT_STATUS_NETWORK_SESSION_EXPIRED
,
1512 ret
, done
, "smb2_read "
1513 "returned unexpected status");
1515 torture_comment(tctx
, "write => EXPIRED\n");
1516 status
= smb2_util_write(tree
, *h1
, &wd
, 0, 1);
1517 torture_assert_ntstatus_equal_goto(tctx
, status
,
1518 NT_STATUS_NETWORK_SESSION_EXPIRED
,
1519 ret
, done
, "smb2_util_write "
1520 "returned unexpected status");
1522 torture_comment(tctx
, "ioctl => EXPIRED\n");
1524 ctl
.in
.file
.handle
= *h1
;
1525 ctl
.in
.function
= FSCTL_SRV_ENUM_SNAPS
;
1526 ctl
.in
.max_output_response
= 16;
1527 ctl
.in
.flags
= SMB2_IOCTL_FLAG_IS_FSCTL
;
1528 status
= smb2_ioctl(tree
, tctx
, &ctl
);
1529 torture_assert_ntstatus_equal_goto(tctx
, status
,
1530 NT_STATUS_NETWORK_SESSION_EXPIRED
,
1531 ret
, done
, "smb2_ioctl "
1532 "returned unexpected status");
1534 torture_comment(tctx
, "oplock ack => EXPIRED\n");
1536 oack
.in
.file
.handle
= *h1
;
1537 status
= smb2_break(tree
, &oack
);
1538 torture_assert_ntstatus_equal_goto(tctx
, status
,
1539 NT_STATUS_NETWORK_SESSION_EXPIRED
,
1540 ret
, done
, "smb2_break "
1541 "returned unexpected status");
1543 if (caps
& SMB2_CAP_LEASING
) {
1544 torture_comment(tctx
, "lease ack => EXPIRED\n");
1546 lack
.in
.lease
.lease_version
= 1;
1547 lack
.in
.lease
.lease_key
.data
[0] = 1;
1548 lack
.in
.lease
.lease_key
.data
[1] = 2;
1549 status
= smb2_lease_break_ack(tree
, &lack
);
1550 torture_assert_ntstatus_equal_goto(tctx
, status
,
1551 NT_STATUS_NETWORK_SESSION_EXPIRED
,
1552 ret
, done
, "smb2_break "
1553 "returned unexpected status");
1556 torture_comment(tctx
, "query directory => EXPIRED\n");
1558 fnd
.in
.file
.handle
= dh
;
1559 fnd
.in
.pattern
= "*";
1560 fnd
.in
.continue_flags
= SMB2_CONTINUE_FLAG_SINGLE
;
1561 fnd
.in
.max_response_size
= 0x100;
1562 fnd
.in
.level
= SMB2_FIND_BOTH_DIRECTORY_INFO
;
1563 status
= smb2_find_level(tree
, tree
, &fnd
, &count
, &d
);
1564 torture_assert_ntstatus_equal_goto(tctx
, status
,
1565 NT_STATUS_NETWORK_SESSION_EXPIRED
,
1566 ret
, done
, "smb2_find_level "
1567 "returned unexpected status");
1569 /* Now do a compound open + query directory + close handle. */
1570 smb2_transport_compound_start(tree
->session
->transport
, 3);
1571 torture_comment(tctx
, "Compound: Open+QueryDirectory+Close => EXPIRED\n");
1574 cio
.in
.oplock_level
= 0;
1575 cio
.in
.desired_access
= SEC_STD_SYNCHRONIZE
| SEC_DIR_READ_ATTRIBUTE
| SEC_DIR_LIST
;
1576 cio
.in
.file_attributes
= 0;
1577 cio
.in
.create_disposition
= NTCREATEX_DISP_OPEN
;
1578 cio
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|NTCREATEX_SHARE_ACCESS_DELETE
;
1579 cio
.in
.create_options
= NTCREATEX_OPTIONS_ASYNC_ALERT
;
1582 reqs
[0] = smb2_create_send(tree
, &cio
);
1583 torture_assert_not_null_goto(tctx
, reqs
[0], ret
, done
,
1584 "smb2_create_send failed\n");
1586 smb2_transport_compound_set_related(tree
->session
->transport
, true);
1589 fnd
.in
.file
.handle
= relhandle
;
1590 fnd
.in
.pattern
= "*";
1591 fnd
.in
.continue_flags
= SMB2_CONTINUE_FLAG_SINGLE
;
1592 fnd
.in
.max_response_size
= 0x100;
1593 fnd
.in
.level
= SMB2_FIND_BOTH_DIRECTORY_INFO
;
1595 reqs
[1] = smb2_find_send(tree
, &fnd
);
1596 torture_assert_not_null_goto(tctx
, reqs
[1], ret
, done
,
1597 "smb2_find_send failed\n");
1600 cl
.in
.file
.handle
= relhandle
;
1601 reqs
[2] = smb2_close_send(tree
, &cl
);
1602 torture_assert_not_null_goto(tctx
, reqs
[2], ret
, done
,
1603 "smb2_close_send failed\n");
1605 status
= smb2_create_recv(reqs
[0], tree
, &cio
);
1606 torture_assert_ntstatus_equal_goto(tctx
, status
,
1607 NT_STATUS_NETWORK_SESSION_EXPIRED
,
1608 ret
, done
, "smb2_create "
1609 "returned unexpected status");
1610 status
= smb2_find_recv(reqs
[1], tree
, &fnd
);
1611 torture_assert_ntstatus_equal_goto(tctx
, status
,
1612 NT_STATUS_NETWORK_SESSION_EXPIRED
,
1613 ret
, done
, "smb2_find "
1614 "returned unexpected status");
1615 status
= smb2_close_recv(reqs
[2], &cl
);
1616 torture_assert_ntstatus_equal_goto(tctx
, status
,
1617 NT_STATUS_NETWORK_SESSION_EXPIRED
,
1618 ret
, done
, "smb2_close "
1619 "returned unexpected status");
1621 torture_comment(tctx
, "1st notify => CANCEL\n");
1624 torture_comment(tctx
, "2nd notify => EXPIRED\n");
1626 ntf2
.in
.file
.handle
= dh
;
1627 ntf2
.in
.recursive
= 0x0000;
1628 ntf2
.in
.buffer_size
= 128;
1629 ntf2
.in
.completion_filter
= FILE_NOTIFY_CHANGE_ATTRIBUTES
;
1630 ntf2
.in
.unknown
= 0x00000000;
1631 status
= smb2_notify(tree
, tctx
, &ntf2
);
1632 torture_assert_ntstatus_equal_goto(tctx
, status
,
1633 NT_STATUS_NETWORK_SESSION_EXPIRED
,
1634 ret
, done
, "smb2_notify "
1635 "returned unexpected status");
1637 torture_assert_goto(tctx
, req
->state
> SMB2_REQUEST_RECV
, ret
, done
,
1638 "smb2_notify (1st) not finished");
1640 status
= smb2_notify_recv(req
, tctx
, &ntf1
);
1641 torture_assert_ntstatus_equal_goto(tctx
, status
,
1642 NT_STATUS_CANCELLED
,
1643 ret
, done
, "smb2_notify cancelled"
1644 "returned unexpected status");
1646 torture_comment(tctx
, "tcon => EXPIRED\n");
1647 tree2
= smb2_tree_init(tree
->session
, tctx
, false);
1648 torture_assert(tctx
, tree2
!= NULL
, "smb2_tree_init");
1649 timeout_msec
= tree
->session
->transport
->options
.request_timeout
* 1000;
1650 subreq
= smb2cli_tcon_send(tree2
, tctx
->ev
,
1651 tree2
->session
->transport
->conn
,
1653 tree2
->session
->smbXcli
,
1657 torture_assert(tctx
, subreq
!= NULL
, "smb2cli_tcon_send");
1658 torture_assert(tctx
,
1659 tevent_req_poll_ntstatus(subreq
, tctx
->ev
, &status
),
1660 "tevent_req_poll_ntstatus");
1661 status
= smb2cli_tcon_recv(subreq
);
1662 TALLOC_FREE(subreq
);
1663 torture_assert_ntstatus_equal_goto(tctx
, status
,
1664 NT_STATUS_NETWORK_SESSION_EXPIRED
,
1665 ret
, done
, "smb2cli_tcon"
1666 "returned unexpected status");
1668 torture_comment(tctx
, "create => EXPIRED\n");
1669 status
= smb2_util_roothandle(tree
, &dh2
);
1670 torture_assert_ntstatus_equal_goto(tctx
, status
,
1671 NT_STATUS_NETWORK_SESSION_EXPIRED
,
1672 ret
, done
, "smb2_util_roothandle"
1673 "returned unexpected status");
1675 torture_comment(tctx
, "tdis => EXPIRED\n");
1676 status
= smb2_tdis(tree
);
1677 torture_assert_ntstatus_equal_goto(tctx
, status
,
1678 NT_STATUS_NETWORK_SESSION_EXPIRED
,
1679 ret
, done
, "smb2cli_tdis"
1680 "returned unexpected status");
1683 * (Un)Lock, Close and Logoff are still possible
1686 torture_comment(tctx
, "1st unlock => OK\n");
1687 el
.flags
= SMB2_LOCK_FLAG_UNLOCK
;
1688 status
= smb2_lock(tree
, &lck
);
1689 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
1690 "smb2_lock unlock failed");
1692 torture_comment(tctx
, "2nd unlock => RANGE_NOT_LOCKED\n");
1693 status
= smb2_lock(tree
, &lck
);
1694 torture_assert_ntstatus_equal_goto(tctx
, status
,
1695 NT_STATUS_RANGE_NOT_LOCKED
,
1696 ret
, done
, "smb2_lock 2nd unlock"
1697 "returned unexpected status");
1699 torture_comment(tctx
, "lock => EXPIRED\n");
1700 el
.flags
= SMB2_LOCK_FLAG_EXCLUSIVE
|
1701 SMB2_LOCK_FLAG_FAIL_IMMEDIATELY
;
1702 status
= smb2_lock(tree
, &lck
);
1703 torture_assert_ntstatus_equal_goto(tctx
, status
,
1704 NT_STATUS_NETWORK_SESSION_EXPIRED
,
1705 ret
, done
, "smb2_util_roothandle"
1706 "returned unexpected status");
1708 torture_comment(tctx
, "close => OK\n");
1709 status
= smb2_util_close(tree
, *h1
);
1711 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
1712 "smb2_close failed");
1714 torture_comment(tctx
, "echo without session => OK\n");
1715 status
= smb2_keepalive(tree
->session
->transport
);
1716 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
1717 "smb2_keepalive without session failed");
1719 torture_comment(tctx
, "echo with session => OK\n");
1720 req
= smb2_keepalive_send(tree
->session
->transport
, tree
->session
);
1721 status
= smb2_keepalive_recv(req
);
1722 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
1723 "smb2_keepalive with session failed");
1725 torture_comment(tctx
, "logoff => OK\n");
1726 status
= smb2_logoff(tree
->session
);
1727 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
1728 "smb2_logoff failed");
1732 cli_credentials_invalidate_ccache(credentials
, CRED_SPECIFIED
);
1735 smb2_util_close(tree
, *h1
);
1739 lpcfg_set_option(tctx
->lp_ctx
, GENSEC_GSSAPI_REQUESTED_LIFETIME(0));
1743 static bool test_session_expire2s(struct torture_context
*tctx
)
1745 return test_session_expire2i(tctx
,
1746 false); /* force_encryption */
1749 static bool test_session_expire2e(struct torture_context
*tctx
)
1751 return test_session_expire2i(tctx
,
1752 true); /* force_encryption */
1755 static bool test_session_expire_disconnect(struct torture_context
*tctx
)
1759 struct smbcli_options options
;
1760 const char *host
= torture_setting_string(tctx
, "host", NULL
);
1761 const char *share
= torture_setting_string(tctx
, "share", NULL
);
1762 struct cli_credentials
*credentials
= samba_cmdline_get_creds();
1763 struct smb2_tree
*tree
= NULL
;
1764 enum credentials_use_kerberos use_kerberos
;
1766 struct smb2_handle _h1
;
1767 struct smb2_handle
*h1
= NULL
;
1768 struct smb2_create io1
;
1769 union smb_fileinfo qfinfo
;
1771 struct timeval endtime
;
1773 use_kerberos
= cli_credentials_get_kerberos_state(credentials
);
1774 if (use_kerberos
!= CRED_USE_KERBEROS_REQUIRED
) {
1775 torture_warning(tctx
,
1776 "smb2.session.expire1 requires "
1777 "--use-kerberos=required!");
1779 "smb2.session.expire1 requires "
1780 "--use-kerberos=required!");
1783 cli_credentials_invalidate_ccache(credentials
, CRED_SPECIFIED
);
1787 GENSEC_GSSAPI_REQUESTED_LIFETIME(KRB5_TICKET_LIFETIME
));
1788 lpcfg_smbcli_options(tctx
->lp_ctx
, &options
);
1789 options
.signing
= SMB_SIGNING_REQUIRED
;
1791 status
= smb2_connect(tctx
,
1793 lpcfg_smb_ports(tctx
->lp_ctx
),
1795 lpcfg_resolve_context(tctx
->lp_ctx
),
1800 lpcfg_socket_options(tctx
->lp_ctx
),
1801 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
)
1804 * We request a ticket lifetime of KRB5_TICKET_LIFETIME seconds.
1805 * Give the server at least KRB5_TICKET_LIFETIME + KRB5_CLOCKSKEW + a
1806 * few more milliseconds for this to kick in.
1808 endtime
= timeval_current_ofs(KRB5_TICKET_EXPIRETIME
, 500 * 1000);
1809 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
1810 "smb2_connect failed");
1812 smbXcli_session_set_disconnect_expired(tree
->session
->smbXcli
);
1814 /* Add some random component to the file name. */
1815 snprintf(fname
, sizeof(fname
), "session_expire1_%s.dat",
1816 generate_random_str(tctx
, 8));
1818 smb2_util_unlink(tree
, fname
);
1820 smb2_oplock_create_share(&io1
, fname
,
1821 smb2_util_share_access(""),
1822 smb2_util_oplock_level("b"));
1823 io1
.in
.create_options
|= NTCREATEX_OPTIONS_DELETE_ON_CLOSE
;
1825 status
= smb2_create(tree
, tctx
, &io1
);
1826 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
1827 "smb2_create failed");
1828 _h1
= io1
.out
.file
.handle
;
1830 CHECK_CREATED(tctx
, &io1
, CREATED
, FILE_ATTRIBUTE_ARCHIVE
);
1831 torture_assert_int_equal(tctx
, io1
.out
.oplock_level
,
1832 smb2_util_oplock_level("b"),
1833 "oplock_level incorrect");
1835 /* get the security descriptor */
1837 ZERO_STRUCT(qfinfo
);
1839 qfinfo
.access_information
.level
= RAW_FILEINFO_ACCESS_INFORMATION
;
1840 qfinfo
.access_information
.in
.file
.handle
= _h1
;
1842 torture_comment(tctx
, "query info => OK\n");
1844 ZERO_STRUCT(qfinfo
.access_information
.out
);
1845 status
= smb2_getinfo_file(tree
, tctx
, &qfinfo
);
1846 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
1847 "smb2_getinfo_file failed");
1849 sleep_remaining(tctx
, &endtime
);
1851 torture_comment(tctx
, "query info => EXPIRED\n");
1852 ZERO_STRUCT(qfinfo
.access_information
.out
);
1853 status
= smb2_getinfo_file(tree
, tctx
, &qfinfo
);
1854 torture_assert_ntstatus_equal_goto(tctx
, status
,
1855 NT_STATUS_NETWORK_SESSION_EXPIRED
,
1856 ret
, done
, "smb2_getinfo_file "
1857 "returned unexpected status");
1859 connected
= smbXcli_conn_is_connected(tree
->session
->transport
->conn
);
1860 torture_assert_goto(tctx
, !connected
, ret
, done
, "connected\n");
1864 cli_credentials_invalidate_ccache(credentials
, CRED_SPECIFIED
);
1867 smb2_util_close(tree
, *h1
);
1871 lpcfg_set_option(tctx
->lp_ctx
, GENSEC_GSSAPI_REQUESTED_LIFETIME(0));
1875 bool test_session_bind1(struct torture_context
*tctx
, struct smb2_tree
*tree1
)
1877 const char *host
= torture_setting_string(tctx
, "host", NULL
);
1878 const char *share
= torture_setting_string(tctx
, "share", NULL
);
1879 struct cli_credentials
*credentials
= samba_cmdline_get_creds();
1881 TALLOC_CTX
*mem_ctx
= talloc_new(tctx
);
1883 struct smb2_handle _h1
;
1884 struct smb2_handle
*h1
= NULL
;
1885 struct smb2_create io1
;
1886 union smb_fileinfo qfinfo
;
1888 struct smb2_tree
*tree2
= NULL
;
1889 struct smb2_transport
*transport1
= tree1
->session
->transport
;
1890 struct smbcli_options options2
;
1891 struct smb2_transport
*transport2
= NULL
;
1892 struct smb2_session
*session1_1
= tree1
->session
;
1893 struct smb2_session
*session1_2
= NULL
;
1894 struct smb2_session
*session2_1
= NULL
;
1895 struct smb2_session
*session2_2
= NULL
;
1898 caps
= smb2cli_conn_server_capabilities(transport1
->conn
);
1899 if (!(caps
& SMB2_CAP_MULTI_CHANNEL
)) {
1900 torture_skip(tctx
, "server doesn't support SMB2_CAP_MULTI_CHANNEL\n");
1904 * We always want signing for this test!
1906 smb2cli_tcon_should_sign(tree1
->smbXcli
, true);
1907 options2
= transport1
->options
;
1908 options2
.signing
= SMB_SIGNING_REQUIRED
;
1910 /* Add some random component to the file name. */
1911 snprintf(fname
, sizeof(fname
), "session_bind1_%s.dat",
1912 generate_random_str(tctx
, 8));
1914 smb2_util_unlink(tree1
, fname
);
1916 smb2_oplock_create_share(&io1
, fname
,
1917 smb2_util_share_access(""),
1918 smb2_util_oplock_level("b"));
1920 status
= smb2_create(tree1
, mem_ctx
, &io1
);
1921 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
1922 "smb2_create failed");
1923 _h1
= io1
.out
.file
.handle
;
1925 CHECK_CREATED(tctx
, &io1
, CREATED
, FILE_ATTRIBUTE_ARCHIVE
);
1926 torture_assert_int_equal(tctx
, io1
.out
.oplock_level
,
1927 smb2_util_oplock_level("b"),
1928 "oplock_level incorrect");
1930 status
= smb2_connect(tctx
,
1932 lpcfg_smb_ports(tctx
->lp_ctx
),
1934 lpcfg_resolve_context(tctx
->lp_ctx
),
1939 lpcfg_socket_options(tctx
->lp_ctx
),
1940 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
)
1942 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
1943 "smb2_connect failed");
1944 session2_2
= tree2
->session
;
1945 transport2
= tree2
->session
->transport
;
1948 * Now bind the 2nd transport connection to the 1st session
1950 session1_2
= smb2_session_channel(transport2
,
1951 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
),
1954 torture_assert(tctx
, session1_2
!= NULL
, "smb2_session_channel failed");
1956 status
= smb2_session_setup_spnego(session1_2
,
1957 samba_cmdline_get_creds(),
1958 0 /* previous_session_id */);
1959 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
1960 "smb2_session_setup_spnego failed");
1962 /* use the 1st connection, 1st session */
1963 ZERO_STRUCT(qfinfo
);
1964 qfinfo
.generic
.level
= RAW_FILEINFO_POSITION_INFORMATION
;
1965 qfinfo
.generic
.in
.file
.handle
= _h1
;
1966 tree1
->session
= session1_1
;
1967 status
= smb2_getinfo_file(tree1
, mem_ctx
, &qfinfo
);
1968 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
1969 "smb2_getinfo_file failed");
1971 /* use the 2nd connection, 1st session */
1972 ZERO_STRUCT(qfinfo
);
1973 qfinfo
.generic
.level
= RAW_FILEINFO_POSITION_INFORMATION
;
1974 qfinfo
.generic
.in
.file
.handle
= _h1
;
1975 tree1
->session
= session1_2
;
1976 status
= smb2_getinfo_file(tree1
, mem_ctx
, &qfinfo
);
1977 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
1978 "smb2_getinfo_file failed");
1980 tree1
->session
= session1_1
;
1981 status
= smb2_util_close(tree1
, *h1
);
1982 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
1983 "smb2_util_close failed");
1987 * Now bind the 1st transport connection to the 2nd session
1989 session2_1
= smb2_session_channel(transport1
,
1990 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
),
1993 torture_assert(tctx
, session2_1
!= NULL
, "smb2_session_channel failed");
1995 status
= smb2_session_setup_spnego(session2_1
,
1996 samba_cmdline_get_creds(),
1997 0 /* previous_session_id */);
1998 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
1999 "smb2_session_setup_spnego failed");
2001 tree2
->session
= session2_1
;
2002 status
= smb2_util_unlink(tree2
, fname
);
2003 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
2004 "smb2_util_unlink failed");
2008 tree1
->session
= session1_1
;
2011 smb2_util_close(tree1
, *h1
);
2014 smb2_util_unlink(tree1
, fname
);
2018 talloc_free(mem_ctx
);
2023 static bool test_session_bind2(struct torture_context
*tctx
, struct smb2_tree
*tree1
)
2025 const char *host
= torture_setting_string(tctx
, "host", NULL
);
2026 const char *share
= torture_setting_string(tctx
, "share", NULL
);
2027 struct cli_credentials
*credentials
= samba_cmdline_get_creds();
2029 TALLOC_CTX
*mem_ctx
= talloc_new(tctx
);
2032 struct smb2_handle _h1f1
;
2033 struct smb2_handle
*h1f1
= NULL
;
2034 struct smb2_handle _h1f2
;
2035 struct smb2_handle
*h1f2
= NULL
;
2036 struct smb2_handle _h2f2
;
2037 struct smb2_handle
*h2f2
= NULL
;
2038 struct smb2_create io1f1
;
2039 struct smb2_create io1f2
;
2040 struct smb2_create io2f1
;
2041 struct smb2_create io2f2
;
2042 union smb_fileinfo qfinfo
;
2044 struct smb2_transport
*transport1
= tree1
->session
->transport
;
2045 struct smbcli_options options2
;
2046 struct smb2_tree
*tree2
= NULL
;
2047 struct smb2_transport
*transport2
= NULL
;
2048 struct smbcli_options options3
;
2049 struct smb2_tree
*tree3
= NULL
;
2050 struct smb2_transport
*transport3
= NULL
;
2051 struct smb2_session
*session1_1
= tree1
->session
;
2052 struct smb2_session
*session1_2
= NULL
;
2053 struct smb2_session
*session1_3
= NULL
;
2054 struct smb2_session
*session2_1
= NULL
;
2055 struct smb2_session
*session2_2
= NULL
;
2056 struct smb2_session
*session2_3
= NULL
;
2059 caps
= smb2cli_conn_server_capabilities(transport1
->conn
);
2060 if (!(caps
& SMB2_CAP_MULTI_CHANNEL
)) {
2061 torture_skip(tctx
, "server doesn't support SMB2_CAP_MULTI_CHANNEL\n");
2065 * We always want signing for this test!
2067 smb2cli_tcon_should_sign(tree1
->smbXcli
, true);
2068 options2
= transport1
->options
;
2069 options2
.signing
= SMB_SIGNING_REQUIRED
;
2071 /* Add some random component to the file name. */
2072 snprintf(fname1
, sizeof(fname1
), "session_bind2_1_%s.dat",
2073 generate_random_str(tctx
, 8));
2074 snprintf(fname2
, sizeof(fname2
), "session_bind2_2_%s.dat",
2075 generate_random_str(tctx
, 8));
2077 smb2_util_unlink(tree1
, fname1
);
2078 smb2_util_unlink(tree1
, fname2
);
2080 smb2_oplock_create_share(&io1f1
, fname1
,
2081 smb2_util_share_access(""),
2082 smb2_util_oplock_level(""));
2083 smb2_oplock_create_share(&io1f2
, fname2
,
2084 smb2_util_share_access(""),
2085 smb2_util_oplock_level(""));
2087 status
= smb2_create(tree1
, mem_ctx
, &io1f1
);
2088 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
2089 "smb2_create failed");
2090 _h1f1
= io1f1
.out
.file
.handle
;
2092 CHECK_CREATED(tctx
, &io1f1
, CREATED
, FILE_ATTRIBUTE_ARCHIVE
);
2093 torture_assert_int_equal(tctx
, io1f1
.out
.oplock_level
,
2094 smb2_util_oplock_level(""),
2095 "oplock_level incorrect");
2097 status
= smb2_connect(tctx
,
2099 lpcfg_smb_ports(tctx
->lp_ctx
),
2101 lpcfg_resolve_context(tctx
->lp_ctx
),
2106 lpcfg_socket_options(tctx
->lp_ctx
),
2107 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
)
2109 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
2110 "smb2_connect failed");
2111 session2_2
= tree2
->session
;
2112 transport2
= tree2
->session
->transport
;
2113 smb2cli_tcon_should_sign(tree2
->smbXcli
, true);
2115 smb2_oplock_create_share(&io2f1
, fname1
,
2116 smb2_util_share_access(""),
2117 smb2_util_oplock_level(""));
2118 smb2_oplock_create_share(&io2f2
, fname2
,
2119 smb2_util_share_access(""),
2120 smb2_util_oplock_level(""));
2122 status
= smb2_create(tree2
, mem_ctx
, &io2f2
);
2123 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
2124 "smb2_create failed");
2125 _h2f2
= io2f2
.out
.file
.handle
;
2127 CHECK_CREATED(tctx
, &io2f2
, CREATED
, FILE_ATTRIBUTE_ARCHIVE
);
2128 torture_assert_int_equal(tctx
, io2f2
.out
.oplock_level
,
2129 smb2_util_oplock_level(""),
2130 "oplock_level incorrect");
2132 options3
= transport1
->options
;
2133 options3
.signing
= SMB_SIGNING_REQUIRED
;
2134 options3
.only_negprot
= true;
2136 status
= smb2_connect(tctx
,
2138 lpcfg_smb_ports(tctx
->lp_ctx
),
2140 lpcfg_resolve_context(tctx
->lp_ctx
),
2145 lpcfg_socket_options(tctx
->lp_ctx
),
2146 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
)
2148 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
2149 "smb2_connect failed");
2150 transport3
= tree3
->session
->transport
;
2153 * Create a fake session for the 2nd transport connection to the 1st session
2155 session1_2
= smb2_session_channel(transport2
,
2156 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
),
2159 torture_assert(tctx
, session1_2
!= NULL
, "smb2_session_channel failed");
2162 * Now bind the 3rd transport connection to the 1st session
2164 session1_3
= smb2_session_channel(transport3
,
2165 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
),
2168 torture_assert(tctx
, session1_3
!= NULL
, "smb2_session_channel failed");
2170 status
= smb2_session_setup_spnego(session1_3
,
2172 0 /* previous_session_id */);
2173 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
2174 "smb2_session_setup_spnego failed");
2177 * Create a fake session for the 1st transport connection to the 2nd session
2179 session2_1
= smb2_session_channel(transport1
,
2180 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
),
2183 torture_assert(tctx
, session2_1
!= NULL
, "smb2_session_channel failed");
2186 * Now bind the 3rd transport connection to the 2nd session
2188 session2_3
= smb2_session_channel(transport3
,
2189 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
),
2192 torture_assert(tctx
, session2_3
!= NULL
, "smb2_session_channel failed");
2194 status
= smb2_session_setup_spnego(session2_3
,
2196 0 /* previous_session_id */);
2197 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
2198 "smb2_session_setup_spnego failed");
2200 ZERO_STRUCT(qfinfo
);
2201 qfinfo
.generic
.level
= RAW_FILEINFO_POSITION_INFORMATION
;
2202 qfinfo
.generic
.in
.file
.handle
= _h1f1
;
2203 tree1
->session
= session1_1
;
2204 status
= smb2_getinfo_file(tree1
, mem_ctx
, &qfinfo
);
2205 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
2206 "smb2_getinfo_file failed");
2207 tree1
->session
= session1_2
;
2208 status
= smb2_getinfo_file(tree1
, mem_ctx
, &qfinfo
);
2209 torture_assert_ntstatus_equal_goto(tctx
, status
, NT_STATUS_USER_SESSION_DELETED
, ret
, done
,
2210 "smb2_getinfo_file failed");
2211 tree1
->session
= session1_3
;
2212 status
= smb2_getinfo_file(tree1
, mem_ctx
, &qfinfo
);
2213 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
2214 "smb2_getinfo_file failed");
2216 ZERO_STRUCT(qfinfo
);
2217 qfinfo
.generic
.level
= RAW_FILEINFO_POSITION_INFORMATION
;
2218 qfinfo
.generic
.in
.file
.handle
= _h2f2
;
2219 tree2
->session
= session2_1
;
2220 status
= smb2_getinfo_file(tree2
, mem_ctx
, &qfinfo
);
2221 torture_assert_ntstatus_equal_goto(tctx
, status
, NT_STATUS_USER_SESSION_DELETED
, ret
, done
,
2222 "smb2_getinfo_file failed");
2223 tree2
->session
= session2_2
;
2224 status
= smb2_getinfo_file(tree2
, mem_ctx
, &qfinfo
);
2225 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
2226 "smb2_getinfo_file failed");
2227 tree2
->session
= session2_3
;
2228 status
= smb2_getinfo_file(tree2
, mem_ctx
, &qfinfo
);
2229 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
2230 "smb2_getinfo_file failed");
2232 tree1
->session
= session1_1
;
2233 status
= smb2_create(tree1
, mem_ctx
, &io1f2
);
2234 torture_assert_ntstatus_equal_goto(tctx
, status
, NT_STATUS_SHARING_VIOLATION
, ret
, done
,
2235 "smb2_create failed");
2236 tree1
->session
= session1_2
;
2237 status
= smb2_create(tree1
, mem_ctx
, &io1f2
);
2238 torture_assert_ntstatus_equal_goto(tctx
, status
, NT_STATUS_USER_SESSION_DELETED
, ret
, done
,
2239 "smb2_create failed");
2240 tree1
->session
= session1_3
;
2241 status
= smb2_create(tree1
, mem_ctx
, &io1f2
);
2242 torture_assert_ntstatus_equal_goto(tctx
, status
, NT_STATUS_SHARING_VIOLATION
, ret
, done
,
2243 "smb2_create failed");
2245 tree2
->session
= session2_1
;
2246 status
= smb2_create(tree2
, mem_ctx
, &io2f1
);
2247 torture_assert_ntstatus_equal_goto(tctx
, status
, NT_STATUS_USER_SESSION_DELETED
, ret
, done
,
2248 "smb2_create failed");
2249 tree2
->session
= session2_2
;
2250 status
= smb2_create(tree2
, mem_ctx
, &io2f1
);
2251 torture_assert_ntstatus_equal_goto(tctx
, status
, NT_STATUS_SHARING_VIOLATION
, ret
, done
,
2252 "smb2_create failed");
2253 tree2
->session
= session2_3
;
2254 status
= smb2_create(tree2
, mem_ctx
, &io2f1
);
2255 torture_assert_ntstatus_equal_goto(tctx
, status
, NT_STATUS_SHARING_VIOLATION
, ret
, done
,
2256 "smb2_create failed");
2258 smbXcli_conn_disconnect(transport3
->conn
, NT_STATUS_LOCAL_DISCONNECT
);
2261 tree1
->session
= session1_1
;
2262 status
= smb2_create(tree1
, mem_ctx
, &io1f2
);
2263 torture_assert_ntstatus_equal_goto(tctx
, status
, NT_STATUS_SHARING_VIOLATION
, ret
, done
,
2264 "smb2_create failed");
2265 tree1
->session
= session1_2
;
2266 status
= smb2_create(tree1
, mem_ctx
, &io1f2
);
2267 torture_assert_ntstatus_equal_goto(tctx
, status
, NT_STATUS_USER_SESSION_DELETED
, ret
, done
,
2268 "smb2_create failed");
2270 tree2
->session
= session2_1
;
2271 status
= smb2_create(tree2
, mem_ctx
, &io2f1
);
2272 torture_assert_ntstatus_equal_goto(tctx
, status
, NT_STATUS_USER_SESSION_DELETED
, ret
, done
,
2273 "smb2_create failed");
2274 tree2
->session
= session2_2
;
2275 status
= smb2_create(tree2
, mem_ctx
, &io2f1
);
2276 torture_assert_ntstatus_equal_goto(tctx
, status
, NT_STATUS_SHARING_VIOLATION
, ret
, done
,
2277 "smb2_create failed");
2279 smbXcli_conn_disconnect(transport2
->conn
, NT_STATUS_LOCAL_DISCONNECT
);
2283 tree1
->session
= session1_1
;
2284 status
= smb2_create(tree1
, mem_ctx
, &io1f2
);
2285 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
2286 "smb2_create failed");
2287 _h1f2
= io1f2
.out
.file
.handle
;
2289 CHECK_CREATED(tctx
, &io1f2
, EXISTED
, FILE_ATTRIBUTE_ARCHIVE
);
2290 torture_assert_int_equal(tctx
, io1f2
.out
.oplock_level
,
2291 smb2_util_oplock_level(""),
2292 "oplock_level incorrect");
2294 tree1
->session
= session1_1
;
2295 status
= smb2_util_close(tree1
, *h1f1
);
2296 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
2297 "smb2_util_close failed");
2303 smbXcli_conn_disconnect(transport3
->conn
, NT_STATUS_LOCAL_DISCONNECT
);
2304 smbXcli_conn_disconnect(transport2
->conn
, NT_STATUS_LOCAL_DISCONNECT
);
2306 tree1
->session
= session1_1
;
2307 tree2
->session
= session2_2
;
2310 smb2_util_close(tree1
, *h1f1
);
2313 smb2_util_close(tree1
, *h1f2
);
2316 smb2_util_close(tree2
, *h2f2
);
2319 smb2_util_unlink(tree1
, fname1
);
2320 smb2_util_unlink(tree1
, fname2
);
2324 talloc_free(mem_ctx
);
2329 static bool test_session_bind_auth_mismatch(struct torture_context
*tctx
,
2330 struct smb2_tree
*tree1
,
2331 const char *testname
,
2332 struct cli_credentials
*creds1
,
2333 struct cli_credentials
*creds2
,
2334 bool creds2_require_ok
)
2336 const char *host
= torture_setting_string(tctx
, "host", NULL
);
2337 const char *share
= torture_setting_string(tctx
, "share", NULL
);
2339 TALLOC_CTX
*mem_ctx
= talloc_new(tctx
);
2341 struct smb2_handle _h1
;
2342 struct smb2_handle
*h1
= NULL
;
2343 struct smb2_create io1
;
2344 union smb_fileinfo qfinfo
;
2346 struct smb2_tree
*tree2
= NULL
;
2347 struct smb2_transport
*transport1
= tree1
->session
->transport
;
2348 struct smbcli_options options2
;
2349 struct smb2_transport
*transport2
= NULL
;
2350 struct smb2_session
*session1_1
= tree1
->session
;
2351 struct smb2_session
*session1_2
= NULL
;
2352 struct smb2_session
*session2_1
= NULL
;
2353 struct smb2_session
*session2_2
= NULL
;
2354 struct smb2_session
*session3_1
= NULL
;
2357 bool creds2_got_ok
= false;
2359 encrypted
= smb2cli_tcon_is_encryption_on(tree1
->smbXcli
);
2361 caps
= smb2cli_conn_server_capabilities(transport1
->conn
);
2362 if (!(caps
& SMB2_CAP_MULTI_CHANNEL
)) {
2363 torture_skip(tctx
, "server doesn't support SMB2_CAP_MULTI_CHANNEL\n");
2367 * We always want signing for this test!
2369 smb2cli_tcon_should_sign(tree1
->smbXcli
, true);
2370 options2
= transport1
->options
;
2371 options2
.signing
= SMB_SIGNING_REQUIRED
;
2373 /* Add some random component to the file name. */
2374 snprintf(fname
, sizeof(fname
), "%s_%s.dat", testname
,
2375 generate_random_str(tctx
, 8));
2377 smb2_util_unlink(tree1
, fname
);
2379 smb2_oplock_create_share(&io1
, fname
,
2380 smb2_util_share_access(""),
2381 smb2_util_oplock_level("b"));
2383 status
= smb2_create(tree1
, mem_ctx
, &io1
);
2384 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
2385 "smb2_create failed");
2386 _h1
= io1
.out
.file
.handle
;
2388 CHECK_CREATED(tctx
, &io1
, CREATED
, FILE_ATTRIBUTE_ARCHIVE
);
2389 torture_assert_int_equal(tctx
, io1
.out
.oplock_level
,
2390 smb2_util_oplock_level("b"),
2391 "oplock_level incorrect");
2393 status
= smb2_connect(tctx
,
2395 lpcfg_smb_ports(tctx
->lp_ctx
),
2397 lpcfg_resolve_context(tctx
->lp_ctx
),
2402 lpcfg_socket_options(tctx
->lp_ctx
),
2403 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
)
2405 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
2406 "smb2_connect failed");
2407 session2_2
= tree2
->session
;
2408 transport2
= tree2
->session
->transport
;
2411 * Now bind the 2nd transport connection to the 1st session
2413 session1_2
= smb2_session_channel(transport2
,
2414 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
),
2417 torture_assert(tctx
, session1_2
!= NULL
, "smb2_session_channel failed");
2419 status
= smb2_session_setup_spnego(session1_2
,
2421 0 /* previous_session_id */);
2422 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
2423 "smb2_session_setup_spnego failed");
2425 /* use the 1st connection, 1st session */
2426 ZERO_STRUCT(qfinfo
);
2427 qfinfo
.generic
.level
= RAW_FILEINFO_POSITION_INFORMATION
;
2428 qfinfo
.generic
.in
.file
.handle
= _h1
;
2429 tree1
->session
= session1_1
;
2430 status
= smb2_getinfo_file(tree1
, mem_ctx
, &qfinfo
);
2431 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
2432 "smb2_getinfo_file failed");
2434 /* use the 2nd connection, 1st session */
2435 ZERO_STRUCT(qfinfo
);
2436 qfinfo
.generic
.level
= RAW_FILEINFO_POSITION_INFORMATION
;
2437 qfinfo
.generic
.in
.file
.handle
= _h1
;
2438 tree1
->session
= session1_2
;
2439 status
= smb2_getinfo_file(tree1
, mem_ctx
, &qfinfo
);
2440 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
2441 "smb2_getinfo_file failed");
2443 tree1
->session
= session1_1
;
2444 status
= smb2_util_close(tree1
, *h1
);
2445 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
2446 "smb2_util_close failed");
2450 * Create a 3rd session in order to check if the invalid (creds2)
2451 * are mapped to guest.
2453 session3_1
= smb2_session_init(transport1
,
2454 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
),
2456 torture_assert(tctx
, session3_1
!= NULL
, "smb2_session_channel failed");
2458 status
= smb2_session_setup_spnego(session3_1
,
2460 0 /* previous_session_id */);
2461 if (creds2_require_ok
) {
2462 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
2463 "smb2_session_setup_spnego worked");
2464 creds2_got_ok
= true;
2465 } else if (NT_STATUS_IS_OK(status
)) {
2466 bool authentiated
= smbXcli_session_is_authenticated(session3_1
->smbXcli
);
2467 torture_assert(tctx
, !authentiated
, "Invalid credentials allowed!");
2468 creds2_got_ok
= true;
2470 torture_assert_ntstatus_equal_goto(tctx
, status
, NT_STATUS_LOGON_FAILURE
, ret
, done
,
2471 "smb2_session_setup_spnego worked");
2475 * Now bind the 1st transport connection to the 2nd session
2477 session2_1
= smb2_session_channel(transport1
,
2478 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
),
2481 torture_assert(tctx
, session2_1
!= NULL
, "smb2_session_channel failed");
2483 tree2
->session
= session2_1
;
2484 status
= smb2_util_unlink(tree2
, fname
);
2485 torture_assert_ntstatus_equal_goto(tctx
, status
, NT_STATUS_USER_SESSION_DELETED
, ret
, done
,
2486 "smb2_util_unlink worked on invalid channel");
2488 status
= smb2_session_setup_spnego(session2_1
,
2490 0 /* previous_session_id */);
2491 if (creds2_got_ok
) {
2493 * attaching with a different user (guest or anonymous) results
2496 torture_assert_ntstatus_equal_goto(tctx
, status
, NT_STATUS_ACCESS_DENIED
, ret
, done
,
2497 "smb2_session_setup_spnego worked");
2499 torture_assert_ntstatus_equal_goto(tctx
, status
, NT_STATUS_LOGON_FAILURE
, ret
, done
,
2500 "smb2_session_setup_spnego worked");
2503 tree2
->session
= session2_1
;
2504 status
= smb2_util_unlink(tree2
, fname
);
2505 torture_assert_ntstatus_equal_goto(tctx
, status
, NT_STATUS_USER_SESSION_DELETED
, ret
, done
,
2506 "smb2_util_unlink worked on invalid channel");
2508 tree2
->session
= session2_2
;
2509 status
= smb2_util_unlink(tree2
, fname
);
2510 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
2511 "smb2_util_unlink failed");
2512 status
= smb2_util_unlink(tree2
, fname
);
2513 torture_assert_ntstatus_equal_goto(tctx
, status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
, ret
, done
,
2514 "smb2_util_unlink worked");
2515 if (creds2_got_ok
) {
2517 * We got ACCESS_DENIED on the session bind
2518 * with a different user, now check that
2519 * the correct user can actually bind on
2520 * the same connection.
2522 TALLOC_FREE(session2_1
);
2523 session2_1
= smb2_session_channel(transport1
,
2524 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
),
2527 torture_assert(tctx
, session2_1
!= NULL
, "smb2_session_channel failed");
2529 status
= smb2_session_setup_spnego(session2_1
,
2531 0 /* previous_session_id */);
2532 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
2533 "smb2_session_setup_spnego failed");
2534 tree2
->session
= session2_1
;
2535 status
= smb2_util_unlink(tree2
, fname
);
2536 torture_assert_ntstatus_equal_goto(tctx
, status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
, ret
, done
,
2537 "smb2_util_unlink worked");
2538 tree2
->session
= session2_2
;
2541 tree1
->session
= session1_1
;
2542 status
= smb2_util_unlink(tree1
, fname
);
2543 torture_assert_ntstatus_equal_goto(tctx
, status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
, ret
, done
,
2544 "smb2_util_unlink worked");
2546 tree1
->session
= session1_2
;
2547 status
= smb2_util_unlink(tree1
, fname
);
2548 torture_assert_ntstatus_equal_goto(tctx
, status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
, ret
, done
,
2549 "smb2_util_unlink worked");
2551 if (creds2_got_ok
) {
2553 * With valid credentials, there's no point to test a failing
2561 * Do a failing reauth the 2nd channel
2563 status
= smb2_session_setup_spnego(session1_2
,
2565 0 /* previous_session_id */);
2566 torture_assert_ntstatus_equal_goto(tctx
, status
, NT_STATUS_LOGON_FAILURE
, ret
, done
,
2567 "smb2_session_setup_spnego worked");
2569 tree1
->session
= session1_1
;
2570 status
= smb2_util_unlink(tree1
, fname
);
2572 torture_assert_goto(tctx
, !smbXcli_conn_is_connected(transport1
->conn
), ret
, done
,
2573 "smb2_util_unlink worked");
2575 torture_assert_ntstatus_equal_goto(tctx
, status
, NT_STATUS_USER_SESSION_DELETED
, ret
, done
,
2576 "smb2_util_unlink worked");
2579 tree1
->session
= session1_2
;
2580 status
= smb2_util_unlink(tree1
, fname
);
2582 torture_assert_goto(tctx
, !smbXcli_conn_is_connected(transport2
->conn
), ret
, done
,
2583 "smb2_util_unlink worked");
2585 torture_assert_ntstatus_equal_goto(tctx
, status
, NT_STATUS_USER_SESSION_DELETED
, ret
, done
,
2586 "smb2_util_unlink worked");
2589 status
= smb2_util_unlink(tree2
, fname
);
2591 torture_assert_goto(tctx
, !smbXcli_conn_is_connected(transport1
->conn
), ret
, done
,
2592 "smb2_util_unlink worked");
2593 torture_assert_goto(tctx
, !smbXcli_conn_is_connected(transport2
->conn
), ret
, done
,
2594 "smb2_util_unlink worked");
2596 torture_assert_ntstatus_equal_goto(tctx
, status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
, ret
, done
,
2597 "smb2_util_unlink worked");
2603 tree1
->session
= session1_1
;
2606 smb2_util_close(tree1
, *h1
);
2609 smb2_util_unlink(tree1
, fname
);
2613 talloc_free(mem_ctx
);
2618 static bool test_session_bind_invalid_auth(struct torture_context
*tctx
, struct smb2_tree
*tree1
)
2620 struct cli_credentials
*credentials
= samba_cmdline_get_creds();
2621 struct cli_credentials
*invalid_credentials
= NULL
;
2624 invalid_credentials
= cli_credentials_init(tctx
);
2625 torture_assert(tctx
, (invalid_credentials
!= NULL
), "talloc error");
2626 cli_credentials_set_username(invalid_credentials
, "__none__invalid__none__", CRED_SPECIFIED
);
2627 cli_credentials_set_domain(invalid_credentials
, "__none__invalid__none__", CRED_SPECIFIED
);
2628 cli_credentials_set_password(invalid_credentials
, "__none__invalid__none__", CRED_SPECIFIED
);
2629 cli_credentials_set_realm(invalid_credentials
, NULL
, CRED_SPECIFIED
);
2630 cli_credentials_set_workstation(invalid_credentials
, "", CRED_UNINITIALISED
);
2632 ret
= test_session_bind_auth_mismatch(tctx
, tree1
, __func__
,
2634 invalid_credentials
,
2639 static bool test_session_bind_different_user(struct torture_context
*tctx
, struct smb2_tree
*tree1
)
2641 struct cli_credentials
*credentials1
= samba_cmdline_get_creds();
2642 struct cli_credentials
*credentials2
= torture_user2_credentials(tctx
, tctx
);
2643 char *u1
= cli_credentials_get_unparsed_name(credentials1
, tctx
);
2644 char *u2
= cli_credentials_get_unparsed_name(credentials2
, tctx
);
2648 torture_assert(tctx
, (credentials2
!= NULL
), "talloc error");
2649 bval
= cli_credentials_is_anonymous(credentials2
);
2651 torture_skip(tctx
, "valid user2 credentials are required");
2653 bval
= strequal(u1
, u2
);
2655 torture_skip(tctx
, "different user2 credentials are required");
2658 ret
= test_session_bind_auth_mismatch(tctx
, tree1
, __func__
,
2665 static bool test_session_bind_negative_smbXtoX(struct torture_context
*tctx
,
2666 const char *testname
,
2667 struct cli_credentials
*credentials
,
2668 const struct smbcli_options
*options1
,
2669 const struct smbcli_options
*options2
,
2670 NTSTATUS bind_reject_status
)
2672 const char *host
= torture_setting_string(tctx
, "host", NULL
);
2673 const char *share
= torture_setting_string(tctx
, "share", NULL
);
2676 struct smb2_tree
*tree1
= NULL
;
2677 struct smb2_session
*session1_1
= NULL
;
2679 struct smb2_handle _h1
;
2680 struct smb2_handle
*h1
= NULL
;
2681 struct smb2_create io1
;
2682 union smb_fileinfo qfinfo1
;
2683 struct smb2_tree
*tree2_0
= NULL
;
2684 struct smb2_transport
*transport2
= NULL
;
2685 struct smb2_session
*session1_2
= NULL
;
2686 uint64_t session1_id
= 0;
2687 uint16_t session1_flags
= 0;
2688 NTSTATUS deleted_status
= NT_STATUS_USER_SESSION_DELETED
;
2690 status
= smb2_connect(tctx
,
2692 lpcfg_smb_ports(tctx
->lp_ctx
),
2694 lpcfg_resolve_context(tctx
->lp_ctx
),
2699 lpcfg_socket_options(tctx
->lp_ctx
),
2700 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
)
2702 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
2703 "smb2_connect options1 failed");
2704 session1_1
= tree1
->session
;
2705 session1_id
= smb2cli_session_current_id(session1_1
->smbXcli
);
2706 session1_flags
= smb2cli_session_get_flags(session1_1
->smbXcli
);
2708 /* Add some random component to the file name. */
2709 snprintf(fname
, sizeof(fname
), "%s_%s.dat",
2710 testname
, generate_random_str(tctx
, 8));
2712 smb2_util_unlink(tree1
, fname
);
2714 smb2_oplock_create_share(&io1
, fname
,
2715 smb2_util_share_access(""),
2716 smb2_util_oplock_level("b"));
2718 io1
.in
.create_options
|= NTCREATEX_OPTIONS_DELETE_ON_CLOSE
;
2719 status
= smb2_create(tree1
, tctx
, &io1
);
2720 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
2721 "smb2_create failed");
2722 _h1
= io1
.out
.file
.handle
;
2724 CHECK_CREATED(tctx
, &io1
, CREATED
, FILE_ATTRIBUTE_ARCHIVE
);
2725 torture_assert_int_equal(tctx
, io1
.out
.oplock_level
,
2726 smb2_util_oplock_level("b"),
2727 "oplock_level incorrect");
2729 status
= smb2_connect(tctx
,
2731 lpcfg_smb_ports(tctx
->lp_ctx
),
2733 lpcfg_resolve_context(tctx
->lp_ctx
),
2738 lpcfg_socket_options(tctx
->lp_ctx
),
2739 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
)
2741 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
2742 "smb2_connect options2 failed");
2743 transport2
= tree2_0
->session
->transport
;
2746 * Now bind the 2nd transport connection to the 1st session
2748 session1_2
= smb2_session_channel(transport2
,
2749 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
),
2752 torture_assert(tctx
, session1_2
!= NULL
, "smb2_session_channel failed");
2754 status
= smb2_session_setup_spnego(session1_2
,
2756 0 /* previous_session_id */);
2757 torture_assert_ntstatus_equal_goto(tctx
, status
, bind_reject_status
, ret
, done
,
2758 "smb2_session_setup_spnego failed");
2759 if (NT_STATUS_IS_OK(bind_reject_status
)) {
2760 ZERO_STRUCT(qfinfo1
);
2761 qfinfo1
.generic
.level
= RAW_FILEINFO_POSITION_INFORMATION
;
2762 qfinfo1
.generic
.in
.file
.handle
= _h1
;
2763 tree1
->session
= session1_2
;
2764 status
= smb2_getinfo_file(tree1
, tctx
, &qfinfo1
);
2765 tree1
->session
= session1_1
;
2766 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
2767 "smb2_getinfo_file failed");
2769 TALLOC_FREE(session1_2
);
2771 /* Check the initial session is still alive */
2772 ZERO_STRUCT(qfinfo1
);
2773 qfinfo1
.generic
.level
= RAW_FILEINFO_POSITION_INFORMATION
;
2774 qfinfo1
.generic
.in
.file
.handle
= _h1
;
2775 status
= smb2_getinfo_file(tree1
, tctx
, &qfinfo1
);
2776 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
2777 "smb2_getinfo_file failed");
2779 if (NT_STATUS_IS_OK(bind_reject_status
)) {
2780 deleted_status
= NT_STATUS_ACCESS_DENIED
;
2781 bind_reject_status
= NT_STATUS_ACCESS_DENIED
;
2785 * I guess this is not part of MultipleChannel_Negative_SMB2002,
2786 * but we should also check the status without
2787 * SMB2_SESSION_FLAG_BINDING.
2789 session1_2
= smb2_session_channel(transport2
,
2790 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
),
2793 torture_assert(tctx
, session1_2
!= NULL
, "smb2_session_channel failed");
2794 session1_2
->needs_bind
= false;
2796 status
= smb2_session_setup_spnego(session1_2
,
2798 0 /* previous_session_id */);
2799 torture_assert_ntstatus_equal_goto(tctx
, status
, deleted_status
, ret
, done
,
2800 "smb2_session_setup_spnego failed");
2801 TALLOC_FREE(session1_2
);
2804 * ... and we should also check the status without any existing
2807 session1_2
= smb2_session_init(transport2
,
2808 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
),
2810 torture_assert(tctx
, session1_2
!= NULL
, "smb2_session_channel failed");
2811 talloc_steal(tree2_0
->session
, transport2
);
2812 smb2cli_session_set_id_and_flags(session1_2
->smbXcli
,
2813 session1_id
, session1_flags
);
2815 status
= smb2_session_setup_spnego(session1_2
,
2817 0 /* previous_session_id */);
2818 torture_assert_ntstatus_equal_goto(tctx
, status
, deleted_status
, ret
, done
,
2819 "smb2_session_setup_spnego failed");
2820 TALLOC_FREE(session1_2
);
2822 /* Check the initial session is still alive */
2823 ZERO_STRUCT(qfinfo1
);
2824 qfinfo1
.generic
.level
= RAW_FILEINFO_POSITION_INFORMATION
;
2825 qfinfo1
.generic
.in
.file
.handle
= _h1
;
2826 status
= smb2_getinfo_file(tree1
, tctx
, &qfinfo1
);
2827 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
2828 "smb2_getinfo_file failed");
2831 * Now bind the 2nd transport connection to the 1st session (again)
2833 session1_2
= smb2_session_channel(transport2
,
2834 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
),
2837 torture_assert(tctx
, session1_2
!= NULL
, "smb2_session_channel failed");
2839 status
= smb2_session_setup_spnego(session1_2
,
2841 0 /* previous_session_id */);
2842 torture_assert_ntstatus_equal_goto(tctx
, status
, bind_reject_status
, ret
, done
,
2843 "smb2_session_setup_spnego failed");
2844 TALLOC_FREE(session1_2
);
2846 /* Check the initial session is still alive */
2847 ZERO_STRUCT(qfinfo1
);
2848 qfinfo1
.generic
.level
= RAW_FILEINFO_POSITION_INFORMATION
;
2849 qfinfo1
.generic
.in
.file
.handle
= _h1
;
2850 status
= smb2_getinfo_file(tree1
, tctx
, &qfinfo1
);
2851 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
2852 "smb2_getinfo_file failed");
2856 talloc_free(tree2_0
);
2858 smb2_util_close(tree1
, *h1
);
2866 * This is similar to the MultipleChannel_Negative_SMB2002 test
2867 * from the Windows Protocol Test Suite.
2869 * It demonstrates that the server needs to do lookup
2870 * in the global session table in order to get the signing
2871 * and error code of invalid session setups correct.
2873 * See: https://bugzilla.samba.org/show_bug.cgi?id=14512
2875 * Note you can ignore tree0...
2877 static bool test_session_bind_negative_smb202(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
2879 struct cli_credentials
*credentials
= samba_cmdline_get_creds();
2881 struct smb2_transport
*transport0
= tree0
->session
->transport
;
2882 struct smbcli_options options1
;
2883 struct smbcli_options options2
;
2886 encrypted
= smb2cli_tcon_is_encryption_on(tree0
->smbXcli
);
2889 "Can't test SMB 2.02 if encryption is required");
2892 options1
= transport0
->options
;
2893 options1
.client_guid
= GUID_zero();
2894 options1
.max_protocol
= PROTOCOL_SMB2_02
;
2896 options2
= options1
;
2897 options2
.only_negprot
= true;
2899 ret
= test_session_bind_negative_smbXtoX(tctx
, __func__
,
2901 &options1
, &options2
,
2902 NT_STATUS_REQUEST_NOT_ACCEPTED
);
2907 static bool test_session_bind_negative_smb210s(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
2909 struct cli_credentials
*credentials
= samba_cmdline_get_creds();
2911 struct smb2_transport
*transport0
= tree0
->session
->transport
;
2912 struct smbcli_options options1
;
2913 struct smbcli_options options2
;
2916 encrypted
= smb2cli_tcon_is_encryption_on(tree0
->smbXcli
);
2919 "Can't test SMB 2.10 if encryption is required");
2922 options1
= transport0
->options
;
2923 options1
.client_guid
= GUID_random();
2924 options1
.max_protocol
= PROTOCOL_SMB2_10
;
2926 /* same client guid */
2927 options2
= options1
;
2928 options2
.only_negprot
= true;
2930 ret
= test_session_bind_negative_smbXtoX(tctx
, __func__
,
2932 &options1
, &options2
,
2933 NT_STATUS_REQUEST_NOT_ACCEPTED
);
2938 static bool test_session_bind_negative_smb210d(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
2940 struct cli_credentials
*credentials
= samba_cmdline_get_creds();
2942 struct smb2_transport
*transport0
= tree0
->session
->transport
;
2943 struct smbcli_options options1
;
2944 struct smbcli_options options2
;
2947 encrypted
= smb2cli_tcon_is_encryption_on(tree0
->smbXcli
);
2950 "Can't test SMB 2.10 if encryption is required");
2953 options1
= transport0
->options
;
2954 options1
.client_guid
= GUID_random();
2955 options1
.max_protocol
= PROTOCOL_SMB2_10
;
2957 /* different client guid */
2958 options2
= options1
;
2959 options2
.client_guid
= GUID_random();
2960 options2
.only_negprot
= true;
2962 ret
= test_session_bind_negative_smbXtoX(tctx
, __func__
,
2964 &options1
, &options2
,
2965 NT_STATUS_REQUEST_NOT_ACCEPTED
);
2970 static bool test_session_bind_negative_smb2to3s(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
2972 struct cli_credentials
*credentials
= samba_cmdline_get_creds();
2974 struct smb2_transport
*transport0
= tree0
->session
->transport
;
2975 struct smbcli_options options1
;
2976 struct smbcli_options options2
;
2979 encrypted
= smb2cli_tcon_is_encryption_on(tree0
->smbXcli
);
2982 "Can't test SMB 2.10 if encryption is required");
2985 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_00
) {
2987 "Can't test without SMB3 support");
2990 options1
= transport0
->options
;
2991 options1
.client_guid
= GUID_random();
2992 options1
.min_protocol
= PROTOCOL_SMB2_02
;
2993 options1
.max_protocol
= PROTOCOL_SMB2_10
;
2995 /* same client guid */
2996 options2
= options1
;
2997 options2
.only_negprot
= true;
2998 options2
.min_protocol
= PROTOCOL_SMB3_00
;
2999 options2
.max_protocol
= PROTOCOL_SMB3_11
;
3000 options2
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
3003 SMB2_SIGNING_AES128_CMAC
,
3007 ret
= test_session_bind_negative_smbXtoX(tctx
, __func__
,
3009 &options1
, &options2
,
3010 NT_STATUS_INVALID_PARAMETER
);
3015 static bool test_session_bind_negative_smb2to3d(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
3017 struct cli_credentials
*credentials
= samba_cmdline_get_creds();
3019 struct smb2_transport
*transport0
= tree0
->session
->transport
;
3020 struct smbcli_options options1
;
3021 struct smbcli_options options2
;
3024 encrypted
= smb2cli_tcon_is_encryption_on(tree0
->smbXcli
);
3027 "Can't test SMB 2.10 if encryption is required");
3030 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_00
) {
3032 "Can't test without SMB3 support");
3035 options1
= transport0
->options
;
3036 options1
.client_guid
= GUID_random();
3037 options1
.min_protocol
= PROTOCOL_SMB2_02
;
3038 options1
.max_protocol
= PROTOCOL_SMB2_10
;
3040 /* different client guid */
3041 options2
= options1
;
3042 options2
.client_guid
= GUID_random();
3043 options2
.only_negprot
= true;
3044 options2
.min_protocol
= PROTOCOL_SMB3_00
;
3045 options2
.max_protocol
= PROTOCOL_SMB3_11
;
3046 options2
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
3049 SMB2_SIGNING_AES128_CMAC
,
3053 ret
= test_session_bind_negative_smbXtoX(tctx
, __func__
,
3055 &options1
, &options2
,
3056 NT_STATUS_INVALID_PARAMETER
);
3061 static bool test_session_bind_negative_smb3to2s(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
3063 struct cli_credentials
*credentials
= samba_cmdline_get_creds();
3065 struct smb2_transport
*transport0
= tree0
->session
->transport
;
3066 struct smbcli_options options1
;
3067 struct smbcli_options options2
;
3070 encrypted
= smb2cli_tcon_is_encryption_on(tree0
->smbXcli
);
3073 "Can't test SMB 2.10 if encryption is required");
3076 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_00
) {
3078 "Can't test without SMB3 support");
3081 options1
= transport0
->options
;
3082 options1
.client_guid
= GUID_random();
3083 options1
.min_protocol
= PROTOCOL_SMB3_00
;
3084 options1
.max_protocol
= PROTOCOL_SMB3_11
;
3085 options1
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
3088 SMB2_SIGNING_AES128_CMAC
,
3092 /* same client guid */
3093 options2
= options1
;
3094 options2
.only_negprot
= true;
3095 options2
.min_protocol
= PROTOCOL_SMB2_02
;
3096 options2
.max_protocol
= PROTOCOL_SMB2_10
;
3097 options2
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
3100 SMB2_SIGNING_HMAC_SHA256
,
3104 ret
= test_session_bind_negative_smbXtoX(tctx
, __func__
,
3106 &options1
, &options2
,
3107 NT_STATUS_REQUEST_NOT_ACCEPTED
);
3112 static bool test_session_bind_negative_smb3to2d(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
3114 struct cli_credentials
*credentials
= samba_cmdline_get_creds();
3116 struct smb2_transport
*transport0
= tree0
->session
->transport
;
3117 struct smbcli_options options1
;
3118 struct smbcli_options options2
;
3121 encrypted
= smb2cli_tcon_is_encryption_on(tree0
->smbXcli
);
3124 "Can't test SMB 2.10 if encryption is required");
3127 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_00
) {
3129 "Can't test without SMB3 support");
3132 options1
= transport0
->options
;
3133 options1
.client_guid
= GUID_random();
3134 options1
.min_protocol
= PROTOCOL_SMB3_00
;
3135 options1
.max_protocol
= PROTOCOL_SMB3_11
;
3136 options1
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
3139 SMB2_SIGNING_AES128_CMAC
,
3143 /* different client guid */
3144 options2
= options1
;
3145 options2
.client_guid
= GUID_random();
3146 options2
.only_negprot
= true;
3147 options2
.min_protocol
= PROTOCOL_SMB2_02
;
3148 options2
.max_protocol
= PROTOCOL_SMB2_10
;
3149 options2
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
3152 SMB2_SIGNING_HMAC_SHA256
,
3156 ret
= test_session_bind_negative_smbXtoX(tctx
, __func__
,
3158 &options1
, &options2
,
3159 NT_STATUS_REQUEST_NOT_ACCEPTED
);
3164 static bool test_session_bind_negative_smb3to3s(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
3166 struct cli_credentials
*credentials
= samba_cmdline_get_creds();
3168 struct smb2_transport
*transport0
= tree0
->session
->transport
;
3169 struct smbcli_options options1
;
3170 struct smbcli_options options2
;
3172 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_11
) {
3174 "Can't test without SMB 3.1.1 support");
3177 options1
= transport0
->options
;
3178 options1
.client_guid
= GUID_random();
3179 options1
.min_protocol
= PROTOCOL_SMB3_02
;
3180 options1
.max_protocol
= PROTOCOL_SMB3_02
;
3182 /* same client guid */
3183 options2
= options1
;
3184 options2
.only_negprot
= true;
3185 options2
.min_protocol
= PROTOCOL_SMB3_11
;
3186 options2
.max_protocol
= PROTOCOL_SMB3_11
;
3187 options2
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
3190 SMB2_SIGNING_AES128_CMAC
,
3194 ret
= test_session_bind_negative_smbXtoX(tctx
, __func__
,
3196 &options1
, &options2
,
3197 NT_STATUS_INVALID_PARAMETER
);
3202 static bool test_session_bind_negative_smb3to3d(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
3204 struct cli_credentials
*credentials
= samba_cmdline_get_creds();
3206 struct smb2_transport
*transport0
= tree0
->session
->transport
;
3207 struct smbcli_options options1
;
3208 struct smbcli_options options2
;
3210 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_11
) {
3212 "Can't test without SMB 3.1.1 support");
3215 options1
= transport0
->options
;
3216 options1
.client_guid
= GUID_random();
3217 options1
.min_protocol
= PROTOCOL_SMB3_02
;
3218 options1
.max_protocol
= PROTOCOL_SMB3_02
;
3220 /* different client guid */
3221 options2
= options1
;
3222 options2
.client_guid
= GUID_random();
3223 options2
.only_negprot
= true;
3224 options2
.min_protocol
= PROTOCOL_SMB3_11
;
3225 options2
.max_protocol
= PROTOCOL_SMB3_11
;
3226 options2
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
3229 SMB2_SIGNING_AES128_CMAC
,
3233 ret
= test_session_bind_negative_smbXtoX(tctx
, __func__
,
3235 &options1
, &options2
,
3236 NT_STATUS_INVALID_PARAMETER
);
3241 static bool test_session_bind_negative_smb3encGtoCs(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
3243 struct cli_credentials
*credentials0
= samba_cmdline_get_creds();
3244 struct cli_credentials
*credentials
= NULL
;
3246 struct smb2_transport
*transport0
= tree0
->session
->transport
;
3247 struct smbcli_options options1
;
3248 struct smbcli_options options2
;
3251 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_11
) {
3253 "Can't test without SMB 3.1.1 support");
3256 credentials
= cli_credentials_shallow_copy(tctx
, credentials0
);
3257 torture_assert(tctx
, credentials
!= NULL
, "cli_credentials_shallow_copy");
3258 ok
= cli_credentials_set_smb_encryption(credentials
,
3259 SMB_ENCRYPTION_REQUIRED
,
3261 torture_assert(tctx
, ok
, "cli_credentials_set_smb_encryption");
3263 options1
= transport0
->options
;
3264 options1
.client_guid
= GUID_random();
3265 options1
.min_protocol
= PROTOCOL_SMB3_11
;
3266 options1
.max_protocol
= PROTOCOL_SMB3_11
;
3267 options1
.signing
= SMB_SIGNING_REQUIRED
;
3268 options1
.smb3_capabilities
.encryption
= (struct smb3_encryption_capabilities
) {
3271 SMB2_ENCRYPTION_AES128_GCM
,
3275 /* same client guid */
3276 options2
= options1
;
3277 options2
.only_negprot
= true;
3278 options2
.smb3_capabilities
.encryption
= (struct smb3_encryption_capabilities
) {
3281 SMB2_ENCRYPTION_AES128_CCM
,
3285 ret
= test_session_bind_negative_smbXtoX(tctx
, __func__
,
3287 &options1
, &options2
,
3288 NT_STATUS_INVALID_PARAMETER
);
3293 static bool test_session_bind_negative_smb3encGtoCd(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
3295 struct cli_credentials
*credentials0
= samba_cmdline_get_creds();
3296 struct cli_credentials
*credentials
= NULL
;
3298 struct smb2_transport
*transport0
= tree0
->session
->transport
;
3299 struct smbcli_options options1
;
3300 struct smbcli_options options2
;
3303 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_11
) {
3305 "Can't test without SMB 3.1.1 support");
3308 credentials
= cli_credentials_shallow_copy(tctx
, credentials0
);
3309 torture_assert(tctx
, credentials
!= NULL
, "cli_credentials_shallow_copy");
3310 ok
= cli_credentials_set_smb_encryption(credentials
,
3311 SMB_ENCRYPTION_REQUIRED
,
3313 torture_assert(tctx
, ok
, "cli_credentials_set_smb_encryption");
3315 options1
= transport0
->options
;
3316 options1
.client_guid
= GUID_random();
3317 options1
.min_protocol
= PROTOCOL_SMB3_11
;
3318 options1
.max_protocol
= PROTOCOL_SMB3_11
;
3319 options1
.signing
= SMB_SIGNING_REQUIRED
;
3320 options1
.smb3_capabilities
.encryption
= (struct smb3_encryption_capabilities
) {
3323 SMB2_ENCRYPTION_AES128_GCM
,
3327 /* different client guid */
3328 options2
= options1
;
3329 options2
.client_guid
= GUID_random();
3330 options2
.only_negprot
= true;
3331 options2
.smb3_capabilities
.encryption
= (struct smb3_encryption_capabilities
) {
3334 SMB2_ENCRYPTION_AES128_CCM
,
3338 ret
= test_session_bind_negative_smbXtoX(tctx
, __func__
,
3340 &options1
, &options2
,
3341 NT_STATUS_INVALID_PARAMETER
);
3346 static bool test_session_bind_negative_smb3signCtoHs(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
3348 struct cli_credentials
*credentials0
= samba_cmdline_get_creds();
3349 struct cli_credentials
*credentials
= NULL
;
3351 struct smb2_transport
*transport0
= tree0
->session
->transport
;
3352 struct smbcli_options options1
;
3353 struct smbcli_options options2
;
3356 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_11
) {
3358 "Can't test without SMB 3.1.1 support");
3361 if (smb2cli_conn_server_signing_algo(transport0
->conn
) < SMB2_SIGNING_AES128_GMAC
) {
3363 "Can't test without SMB 3.1.1 signing negotiation support");
3366 credentials
= cli_credentials_shallow_copy(tctx
, credentials0
);
3367 torture_assert(tctx
, credentials
!= NULL
, "cli_credentials_shallow_copy");
3368 ok
= cli_credentials_set_smb_encryption(credentials
,
3369 SMB_ENCRYPTION_REQUIRED
,
3371 torture_assert(tctx
, ok
, "cli_credentials_set_smb_encryption");
3373 options1
= transport0
->options
;
3374 options1
.client_guid
= GUID_random();
3375 options1
.min_protocol
= PROTOCOL_SMB3_11
;
3376 options1
.max_protocol
= PROTOCOL_SMB3_11
;
3377 options1
.signing
= SMB_SIGNING_REQUIRED
;
3378 options1
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
3381 SMB2_SIGNING_AES128_CMAC
,
3385 /* same client guid */
3386 options2
= options1
;
3387 options2
.only_negprot
= true;
3388 options2
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
3391 SMB2_SIGNING_HMAC_SHA256
,
3395 ret
= test_session_bind_negative_smbXtoX(tctx
, __func__
,
3397 &options1
, &options2
,
3403 static bool test_session_bind_negative_smb3signCtoHd(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
3405 struct cli_credentials
*credentials0
= samba_cmdline_get_creds();
3406 struct cli_credentials
*credentials
= NULL
;
3408 struct smb2_transport
*transport0
= tree0
->session
->transport
;
3409 struct smbcli_options options1
;
3410 struct smbcli_options options2
;
3413 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_11
) {
3415 "Can't test without SMB 3.1.1 support");
3418 if (smb2cli_conn_server_signing_algo(transport0
->conn
) < SMB2_SIGNING_AES128_GMAC
) {
3420 "Can't test without SMB 3.1.1 signing negotiation support");
3423 credentials
= cli_credentials_shallow_copy(tctx
, credentials0
);
3424 torture_assert(tctx
, credentials
!= NULL
, "cli_credentials_shallow_copy");
3425 ok
= cli_credentials_set_smb_encryption(credentials
,
3426 SMB_ENCRYPTION_REQUIRED
,
3428 torture_assert(tctx
, ok
, "cli_credentials_set_smb_encryption");
3430 options1
= transport0
->options
;
3431 options1
.client_guid
= GUID_random();
3432 options1
.min_protocol
= PROTOCOL_SMB3_11
;
3433 options1
.max_protocol
= PROTOCOL_SMB3_11
;
3434 options1
.signing
= SMB_SIGNING_REQUIRED
;
3435 options1
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
3438 SMB2_SIGNING_AES128_CMAC
,
3442 /* different client guid */
3443 options2
= options1
;
3444 options2
.client_guid
= GUID_random();
3445 options2
.only_negprot
= true;
3446 options2
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
3449 SMB2_SIGNING_HMAC_SHA256
,
3453 ret
= test_session_bind_negative_smbXtoX(tctx
, __func__
,
3455 &options1
, &options2
,
3461 static bool test_session_bind_negative_smb3signHtoCs(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
3463 struct cli_credentials
*credentials0
= samba_cmdline_get_creds();
3464 struct cli_credentials
*credentials
= NULL
;
3466 struct smb2_transport
*transport0
= tree0
->session
->transport
;
3467 struct smbcli_options options1
;
3468 struct smbcli_options options2
;
3471 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_11
) {
3473 "Can't test without SMB 3.1.1 support");
3476 if (smb2cli_conn_server_signing_algo(transport0
->conn
) < SMB2_SIGNING_AES128_GMAC
) {
3478 "Can't test without SMB 3.1.1 signing negotiation support");
3481 credentials
= cli_credentials_shallow_copy(tctx
, credentials0
);
3482 torture_assert(tctx
, credentials
!= NULL
, "cli_credentials_shallow_copy");
3483 ok
= cli_credentials_set_smb_encryption(credentials
,
3484 SMB_ENCRYPTION_REQUIRED
,
3486 torture_assert(tctx
, ok
, "cli_credentials_set_smb_encryption");
3488 options1
= transport0
->options
;
3489 options1
.client_guid
= GUID_random();
3490 options1
.min_protocol
= PROTOCOL_SMB3_11
;
3491 options1
.max_protocol
= PROTOCOL_SMB3_11
;
3492 options1
.signing
= SMB_SIGNING_REQUIRED
;
3493 options1
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
3496 SMB2_SIGNING_HMAC_SHA256
,
3500 /* same client guid */
3501 options2
= options1
;
3502 options2
.only_negprot
= true;
3503 options2
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
3506 SMB2_SIGNING_AES128_CMAC
,
3510 ret
= test_session_bind_negative_smbXtoX(tctx
, __func__
,
3512 &options1
, &options2
,
3518 static bool test_session_bind_negative_smb3signHtoCd(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
3520 struct cli_credentials
*credentials0
= samba_cmdline_get_creds();
3521 struct cli_credentials
*credentials
= NULL
;
3523 struct smb2_transport
*transport0
= tree0
->session
->transport
;
3524 struct smbcli_options options1
;
3525 struct smbcli_options options2
;
3528 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_11
) {
3530 "Can't test without SMB 3.1.1 support");
3533 if (smb2cli_conn_server_signing_algo(transport0
->conn
) < SMB2_SIGNING_AES128_GMAC
) {
3535 "Can't test without SMB 3.1.1 signing negotiation support");
3538 credentials
= cli_credentials_shallow_copy(tctx
, credentials0
);
3539 torture_assert(tctx
, credentials
!= NULL
, "cli_credentials_shallow_copy");
3540 ok
= cli_credentials_set_smb_encryption(credentials
,
3541 SMB_ENCRYPTION_REQUIRED
,
3543 torture_assert(tctx
, ok
, "cli_credentials_set_smb_encryption");
3545 options1
= transport0
->options
;
3546 options1
.client_guid
= GUID_random();
3547 options1
.min_protocol
= PROTOCOL_SMB3_11
;
3548 options1
.max_protocol
= PROTOCOL_SMB3_11
;
3549 options1
.signing
= SMB_SIGNING_REQUIRED
;
3550 options1
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
3553 SMB2_SIGNING_HMAC_SHA256
,
3557 /* different client guid */
3558 options2
= options1
;
3559 options2
.client_guid
= GUID_random();
3560 options2
.only_negprot
= true;
3561 options2
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
3564 SMB2_SIGNING_AES128_CMAC
,
3568 ret
= test_session_bind_negative_smbXtoX(tctx
, __func__
,
3570 &options1
, &options2
,
3576 static bool test_session_bind_negative_smb3signHtoGs(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
3578 struct cli_credentials
*credentials0
= samba_cmdline_get_creds();
3579 struct cli_credentials
*credentials
= NULL
;
3581 struct smb2_transport
*transport0
= tree0
->session
->transport
;
3582 struct smbcli_options options1
;
3583 struct smbcli_options options2
;
3586 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_11
) {
3588 "Can't test without SMB 3.1.1 support");
3591 if (smb2cli_conn_server_signing_algo(transport0
->conn
) < SMB2_SIGNING_AES128_GMAC
) {
3593 "Can't test without SMB 3.1.1 signing negotiation support");
3596 credentials
= cli_credentials_shallow_copy(tctx
, credentials0
);
3597 torture_assert(tctx
, credentials
!= NULL
, "cli_credentials_shallow_copy");
3598 ok
= cli_credentials_set_smb_encryption(credentials
,
3599 SMB_ENCRYPTION_REQUIRED
,
3601 torture_assert(tctx
, ok
, "cli_credentials_set_smb_encryption");
3603 options1
= transport0
->options
;
3604 options1
.client_guid
= GUID_random();
3605 options1
.min_protocol
= PROTOCOL_SMB3_11
;
3606 options1
.max_protocol
= PROTOCOL_SMB3_11
;
3607 options1
.signing
= SMB_SIGNING_REQUIRED
;
3608 options1
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
3611 SMB2_SIGNING_HMAC_SHA256
,
3615 /* same client guid */
3616 options2
= options1
;
3617 options2
.only_negprot
= true;
3618 options2
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
3621 SMB2_SIGNING_AES128_GMAC
,
3625 ret
= test_session_bind_negative_smbXtoX(tctx
, __func__
,
3627 &options1
, &options2
,
3628 NT_STATUS_NOT_SUPPORTED
);
3633 static bool test_session_bind_negative_smb3signHtoGd(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
3635 struct cli_credentials
*credentials0
= samba_cmdline_get_creds();
3636 struct cli_credentials
*credentials
= NULL
;
3638 struct smb2_transport
*transport0
= tree0
->session
->transport
;
3639 struct smbcli_options options1
;
3640 struct smbcli_options options2
;
3643 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_11
) {
3645 "Can't test without SMB 3.1.1 support");
3648 if (smb2cli_conn_server_signing_algo(transport0
->conn
) < SMB2_SIGNING_AES128_GMAC
) {
3650 "Can't test without SMB 3.1.1 signing negotiation support");
3653 credentials
= cli_credentials_shallow_copy(tctx
, credentials0
);
3654 torture_assert(tctx
, credentials
!= NULL
, "cli_credentials_shallow_copy");
3655 ok
= cli_credentials_set_smb_encryption(credentials
,
3656 SMB_ENCRYPTION_REQUIRED
,
3658 torture_assert(tctx
, ok
, "cli_credentials_set_smb_encryption");
3660 options1
= transport0
->options
;
3661 options1
.client_guid
= GUID_random();
3662 options1
.min_protocol
= PROTOCOL_SMB3_11
;
3663 options1
.max_protocol
= PROTOCOL_SMB3_11
;
3664 options1
.signing
= SMB_SIGNING_REQUIRED
;
3665 options1
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
3668 SMB2_SIGNING_HMAC_SHA256
,
3672 /* different client guid */
3673 options2
= options1
;
3674 options2
.client_guid
= GUID_random();
3675 options2
.only_negprot
= true;
3676 options2
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
3679 SMB2_SIGNING_AES128_GMAC
,
3683 ret
= test_session_bind_negative_smbXtoX(tctx
, __func__
,
3685 &options1
, &options2
,
3686 NT_STATUS_NOT_SUPPORTED
);
3691 static bool test_session_bind_negative_smb3signCtoGs(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
3693 struct cli_credentials
*credentials0
= samba_cmdline_get_creds();
3694 struct cli_credentials
*credentials
= NULL
;
3696 struct smb2_transport
*transport0
= tree0
->session
->transport
;
3697 struct smbcli_options options1
;
3698 struct smbcli_options options2
;
3701 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_11
) {
3703 "Can't test without SMB 3.1.1 support");
3706 if (smb2cli_conn_server_signing_algo(transport0
->conn
) < SMB2_SIGNING_AES128_GMAC
) {
3708 "Can't test without SMB 3.1.1 signing negotiation support");
3711 credentials
= cli_credentials_shallow_copy(tctx
, credentials0
);
3712 torture_assert(tctx
, credentials
!= NULL
, "cli_credentials_shallow_copy");
3713 ok
= cli_credentials_set_smb_encryption(credentials
,
3714 SMB_ENCRYPTION_REQUIRED
,
3716 torture_assert(tctx
, ok
, "cli_credentials_set_smb_encryption");
3718 options1
= transport0
->options
;
3719 options1
.client_guid
= GUID_random();
3720 options1
.min_protocol
= PROTOCOL_SMB3_11
;
3721 options1
.max_protocol
= PROTOCOL_SMB3_11
;
3722 options1
.signing
= SMB_SIGNING_REQUIRED
;
3723 options1
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
3726 SMB2_SIGNING_AES128_CMAC
,
3730 /* same client guid */
3731 options2
= options1
;
3732 options2
.only_negprot
= true;
3733 options2
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
3736 SMB2_SIGNING_AES128_GMAC
,
3740 ret
= test_session_bind_negative_smbXtoX(tctx
, __func__
,
3742 &options1
, &options2
,
3743 NT_STATUS_NOT_SUPPORTED
);
3748 static bool test_session_bind_negative_smb3signCtoGd(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
3750 struct cli_credentials
*credentials0
= samba_cmdline_get_creds();
3751 struct cli_credentials
*credentials
= NULL
;
3753 struct smb2_transport
*transport0
= tree0
->session
->transport
;
3754 struct smbcli_options options1
;
3755 struct smbcli_options options2
;
3758 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_11
) {
3760 "Can't test without SMB 3.1.1 support");
3763 if (smb2cli_conn_server_signing_algo(transport0
->conn
) < SMB2_SIGNING_AES128_GMAC
) {
3765 "Can't test without SMB 3.1.1 signing negotiation support");
3768 credentials
= cli_credentials_shallow_copy(tctx
, credentials0
);
3769 torture_assert(tctx
, credentials
!= NULL
, "cli_credentials_shallow_copy");
3770 ok
= cli_credentials_set_smb_encryption(credentials
,
3771 SMB_ENCRYPTION_REQUIRED
,
3773 torture_assert(tctx
, ok
, "cli_credentials_set_smb_encryption");
3775 options1
= transport0
->options
;
3776 options1
.client_guid
= GUID_random();
3777 options1
.min_protocol
= PROTOCOL_SMB3_11
;
3778 options1
.max_protocol
= PROTOCOL_SMB3_11
;
3779 options1
.signing
= SMB_SIGNING_REQUIRED
;
3780 options1
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
3783 SMB2_SIGNING_AES128_CMAC
,
3787 /* different client guid */
3788 options2
= options1
;
3789 options2
.client_guid
= GUID_random();
3790 options2
.only_negprot
= true;
3791 options2
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
3794 SMB2_SIGNING_AES128_GMAC
,
3798 ret
= test_session_bind_negative_smbXtoX(tctx
, __func__
,
3800 &options1
, &options2
,
3801 NT_STATUS_NOT_SUPPORTED
);
3806 static bool test_session_bind_negative_smb3signGtoCs(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
3808 struct cli_credentials
*credentials0
= samba_cmdline_get_creds();
3809 struct cli_credentials
*credentials
= NULL
;
3811 struct smb2_transport
*transport0
= tree0
->session
->transport
;
3812 struct smbcli_options options1
;
3813 struct smbcli_options options2
;
3816 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_11
) {
3818 "Can't test without SMB 3.1.1 support");
3821 if (smb2cli_conn_server_signing_algo(transport0
->conn
) < SMB2_SIGNING_AES128_GMAC
) {
3823 "Can't test without SMB 3.1.1 signing negotiation support");
3826 credentials
= cli_credentials_shallow_copy(tctx
, credentials0
);
3827 torture_assert(tctx
, credentials
!= NULL
, "cli_credentials_shallow_copy");
3828 ok
= cli_credentials_set_smb_encryption(credentials
,
3829 SMB_ENCRYPTION_REQUIRED
,
3831 torture_assert(tctx
, ok
, "cli_credentials_set_smb_encryption");
3833 options1
= transport0
->options
;
3834 options1
.client_guid
= GUID_random();
3835 options1
.min_protocol
= PROTOCOL_SMB3_11
;
3836 options1
.max_protocol
= PROTOCOL_SMB3_11
;
3837 options1
.signing
= SMB_SIGNING_REQUIRED
;
3838 options1
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
3841 SMB2_SIGNING_AES128_GMAC
,
3845 /* same client guid */
3846 options2
= options1
;
3847 options2
.only_negprot
= true;
3848 options2
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
3851 SMB2_SIGNING_AES128_CMAC
,
3855 ret
= test_session_bind_negative_smbXtoX(tctx
, __func__
,
3857 &options1
, &options2
,
3858 NT_STATUS_REQUEST_OUT_OF_SEQUENCE
);
3863 static bool test_session_bind_negative_smb3signGtoCd(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
3865 struct cli_credentials
*credentials0
= samba_cmdline_get_creds();
3866 struct cli_credentials
*credentials
= NULL
;
3868 struct smb2_transport
*transport0
= tree0
->session
->transport
;
3869 struct smbcli_options options1
;
3870 struct smbcli_options options2
;
3873 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_11
) {
3875 "Can't test without SMB 3.1.1 support");
3878 if (smb2cli_conn_server_signing_algo(transport0
->conn
) < SMB2_SIGNING_AES128_GMAC
) {
3880 "Can't test without SMB 3.1.1 signing negotiation support");
3883 credentials
= cli_credentials_shallow_copy(tctx
, credentials0
);
3884 torture_assert(tctx
, credentials
!= NULL
, "cli_credentials_shallow_copy");
3885 ok
= cli_credentials_set_smb_encryption(credentials
,
3886 SMB_ENCRYPTION_REQUIRED
,
3888 torture_assert(tctx
, ok
, "cli_credentials_set_smb_encryption");
3890 options1
= transport0
->options
;
3891 options1
.client_guid
= GUID_random();
3892 options1
.min_protocol
= PROTOCOL_SMB3_11
;
3893 options1
.max_protocol
= PROTOCOL_SMB3_11
;
3894 options1
.signing
= SMB_SIGNING_REQUIRED
;
3895 options1
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
3898 SMB2_SIGNING_AES128_GMAC
,
3902 /* different client guid */
3903 options2
= options1
;
3904 options2
.client_guid
= GUID_random();
3905 options2
.only_negprot
= true;
3906 options2
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
3909 SMB2_SIGNING_AES128_CMAC
,
3913 ret
= test_session_bind_negative_smbXtoX(tctx
, __func__
,
3915 &options1
, &options2
,
3916 NT_STATUS_REQUEST_OUT_OF_SEQUENCE
);
3921 static bool test_session_bind_negative_smb3signGtoHs(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
3923 struct cli_credentials
*credentials0
= samba_cmdline_get_creds();
3924 struct cli_credentials
*credentials
= NULL
;
3926 struct smb2_transport
*transport0
= tree0
->session
->transport
;
3927 struct smbcli_options options1
;
3928 struct smbcli_options options2
;
3931 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_11
) {
3933 "Can't test without SMB 3.1.1 support");
3936 if (smb2cli_conn_server_signing_algo(transport0
->conn
) < SMB2_SIGNING_AES128_GMAC
) {
3938 "Can't test without SMB 3.1.1 signing negotiation support");
3941 credentials
= cli_credentials_shallow_copy(tctx
, credentials0
);
3942 torture_assert(tctx
, credentials
!= NULL
, "cli_credentials_shallow_copy");
3943 ok
= cli_credentials_set_smb_encryption(credentials
,
3944 SMB_ENCRYPTION_REQUIRED
,
3946 torture_assert(tctx
, ok
, "cli_credentials_set_smb_encryption");
3948 options1
= transport0
->options
;
3949 options1
.client_guid
= GUID_random();
3950 options1
.min_protocol
= PROTOCOL_SMB3_11
;
3951 options1
.max_protocol
= PROTOCOL_SMB3_11
;
3952 options1
.signing
= SMB_SIGNING_REQUIRED
;
3953 options1
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
3956 SMB2_SIGNING_AES128_GMAC
,
3960 /* same client guid */
3961 options2
= options1
;
3962 options2
.only_negprot
= true;
3963 options2
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
3966 SMB2_SIGNING_HMAC_SHA256
,
3970 ret
= test_session_bind_negative_smbXtoX(tctx
, __func__
,
3972 &options1
, &options2
,
3973 NT_STATUS_REQUEST_OUT_OF_SEQUENCE
);
3978 static bool test_session_bind_negative_smb3signGtoHd(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
3980 struct cli_credentials
*credentials0
= samba_cmdline_get_creds();
3981 struct cli_credentials
*credentials
= NULL
;
3983 struct smb2_transport
*transport0
= tree0
->session
->transport
;
3984 struct smbcli_options options1
;
3985 struct smbcli_options options2
;
3988 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_11
) {
3990 "Can't test without SMB 3.1.1 support");
3993 if (smb2cli_conn_server_signing_algo(transport0
->conn
) < SMB2_SIGNING_AES128_GMAC
) {
3995 "Can't test without SMB 3.1.1 signing negotiation support");
3998 credentials
= cli_credentials_shallow_copy(tctx
, credentials0
);
3999 torture_assert(tctx
, credentials
!= NULL
, "cli_credentials_shallow_copy");
4000 ok
= cli_credentials_set_smb_encryption(credentials
,
4001 SMB_ENCRYPTION_REQUIRED
,
4003 torture_assert(tctx
, ok
, "cli_credentials_set_smb_encryption");
4005 options1
= transport0
->options
;
4006 options1
.client_guid
= GUID_random();
4007 options1
.min_protocol
= PROTOCOL_SMB3_11
;
4008 options1
.max_protocol
= PROTOCOL_SMB3_11
;
4009 options1
.signing
= SMB_SIGNING_REQUIRED
;
4010 options1
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
4013 SMB2_SIGNING_AES128_GMAC
,
4017 /* different client guid */
4018 options2
= options1
;
4019 options2
.client_guid
= GUID_random();
4020 options2
.only_negprot
= true;
4021 options2
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
4024 SMB2_SIGNING_HMAC_SHA256
,
4028 ret
= test_session_bind_negative_smbXtoX(tctx
, __func__
,
4030 &options1
, &options2
,
4031 NT_STATUS_REQUEST_OUT_OF_SEQUENCE
);
4036 static bool test_session_bind_negative_smb3sneGtoCs(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
4038 struct cli_credentials
*credentials0
= samba_cmdline_get_creds();
4039 struct cli_credentials
*credentials
= NULL
;
4041 struct smb2_transport
*transport0
= tree0
->session
->transport
;
4042 struct smbcli_options options1
;
4043 struct smbcli_options options2
;
4046 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_11
) {
4048 "Can't test without SMB 3.1.1 support");
4051 if (smb2cli_conn_server_signing_algo(transport0
->conn
) < SMB2_SIGNING_AES128_GMAC
) {
4053 "Can't test without SMB 3.1.1 signing negotiation support");
4056 credentials
= cli_credentials_shallow_copy(tctx
, credentials0
);
4057 torture_assert(tctx
, credentials
!= NULL
, "cli_credentials_shallow_copy");
4058 ok
= cli_credentials_set_smb_encryption(credentials
,
4059 SMB_ENCRYPTION_REQUIRED
,
4061 torture_assert(tctx
, ok
, "cli_credentials_set_smb_encryption");
4063 options1
= transport0
->options
;
4064 options1
.client_guid
= GUID_random();
4065 options1
.min_protocol
= PROTOCOL_SMB3_11
;
4066 options1
.max_protocol
= PROTOCOL_SMB3_11
;
4067 options1
.signing
= SMB_SIGNING_REQUIRED
;
4068 options1
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
4071 SMB2_SIGNING_AES128_GMAC
,
4074 options1
.smb3_capabilities
.encryption
= (struct smb3_encryption_capabilities
) {
4077 SMB2_ENCRYPTION_AES128_GCM
,
4081 /* same client guid */
4082 options2
= options1
;
4083 options2
.only_negprot
= true;
4084 options2
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
4087 SMB2_SIGNING_AES128_CMAC
,
4090 options2
.smb3_capabilities
.encryption
= (struct smb3_encryption_capabilities
) {
4093 SMB2_ENCRYPTION_AES128_CCM
,
4097 ret
= test_session_bind_negative_smbXtoX(tctx
, __func__
,
4099 &options1
, &options2
,
4100 NT_STATUS_REQUEST_OUT_OF_SEQUENCE
);
4105 static bool test_session_bind_negative_smb3sneGtoCd(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
4107 struct cli_credentials
*credentials0
= samba_cmdline_get_creds();
4108 struct cli_credentials
*credentials
= NULL
;
4110 struct smb2_transport
*transport0
= tree0
->session
->transport
;
4111 struct smbcli_options options1
;
4112 struct smbcli_options options2
;
4115 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_11
) {
4117 "Can't test without SMB 3.1.1 support");
4120 if (smb2cli_conn_server_signing_algo(transport0
->conn
) < SMB2_SIGNING_AES128_GMAC
) {
4122 "Can't test without SMB 3.1.1 signing negotiation support");
4125 credentials
= cli_credentials_shallow_copy(tctx
, credentials0
);
4126 torture_assert(tctx
, credentials
!= NULL
, "cli_credentials_shallow_copy");
4127 ok
= cli_credentials_set_smb_encryption(credentials
,
4128 SMB_ENCRYPTION_REQUIRED
,
4130 torture_assert(tctx
, ok
, "cli_credentials_set_smb_encryption");
4132 options1
= transport0
->options
;
4133 options1
.client_guid
= GUID_random();
4134 options1
.min_protocol
= PROTOCOL_SMB3_11
;
4135 options1
.max_protocol
= PROTOCOL_SMB3_11
;
4136 options1
.signing
= SMB_SIGNING_REQUIRED
;
4137 options1
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
4140 SMB2_SIGNING_AES128_GMAC
,
4143 options1
.smb3_capabilities
.encryption
= (struct smb3_encryption_capabilities
) {
4146 SMB2_ENCRYPTION_AES128_GCM
,
4150 /* different client guid */
4151 options2
= options1
;
4152 options2
.client_guid
= GUID_random();
4153 options2
.only_negprot
= true;
4154 options2
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
4157 SMB2_SIGNING_AES128_CMAC
,
4160 options2
.smb3_capabilities
.encryption
= (struct smb3_encryption_capabilities
) {
4163 SMB2_ENCRYPTION_AES128_CCM
,
4167 ret
= test_session_bind_negative_smbXtoX(tctx
, __func__
,
4169 &options1
, &options2
,
4170 NT_STATUS_REQUEST_OUT_OF_SEQUENCE
);
4175 static bool test_session_bind_negative_smb3sneGtoHs(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
4177 struct cli_credentials
*credentials0
= samba_cmdline_get_creds();
4178 struct cli_credentials
*credentials
= NULL
;
4180 struct smb2_transport
*transport0
= tree0
->session
->transport
;
4181 struct smbcli_options options1
;
4182 struct smbcli_options options2
;
4185 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_11
) {
4187 "Can't test without SMB 3.1.1 support");
4190 if (smb2cli_conn_server_signing_algo(transport0
->conn
) < SMB2_SIGNING_AES128_GMAC
) {
4192 "Can't test without SMB 3.1.1 signing negotiation support");
4195 credentials
= cli_credentials_shallow_copy(tctx
, credentials0
);
4196 torture_assert(tctx
, credentials
!= NULL
, "cli_credentials_shallow_copy");
4197 ok
= cli_credentials_set_smb_encryption(credentials
,
4198 SMB_ENCRYPTION_REQUIRED
,
4200 torture_assert(tctx
, ok
, "cli_credentials_set_smb_encryption");
4202 options1
= transport0
->options
;
4203 options1
.client_guid
= GUID_random();
4204 options1
.min_protocol
= PROTOCOL_SMB3_11
;
4205 options1
.max_protocol
= PROTOCOL_SMB3_11
;
4206 options1
.signing
= SMB_SIGNING_REQUIRED
;
4207 options1
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
4210 SMB2_SIGNING_AES128_GMAC
,
4213 options1
.smb3_capabilities
.encryption
= (struct smb3_encryption_capabilities
) {
4216 SMB2_ENCRYPTION_AES128_GCM
,
4220 /* same client guid */
4221 options2
= options1
;
4222 options2
.only_negprot
= true;
4223 options2
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
4226 SMB2_SIGNING_HMAC_SHA256
,
4229 options2
.smb3_capabilities
.encryption
= (struct smb3_encryption_capabilities
) {
4232 SMB2_ENCRYPTION_AES128_CCM
,
4236 ret
= test_session_bind_negative_smbXtoX(tctx
, __func__
,
4238 &options1
, &options2
,
4239 NT_STATUS_REQUEST_OUT_OF_SEQUENCE
);
4244 static bool test_session_bind_negative_smb3sneGtoHd(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
4246 struct cli_credentials
*credentials0
= samba_cmdline_get_creds();
4247 struct cli_credentials
*credentials
= NULL
;
4249 struct smb2_transport
*transport0
= tree0
->session
->transport
;
4250 struct smbcli_options options1
;
4251 struct smbcli_options options2
;
4254 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_11
) {
4256 "Can't test without SMB 3.1.1 support");
4259 if (smb2cli_conn_server_signing_algo(transport0
->conn
) < SMB2_SIGNING_AES128_GMAC
) {
4261 "Can't test without SMB 3.1.1 signing negotiation support");
4264 credentials
= cli_credentials_shallow_copy(tctx
, credentials0
);
4265 torture_assert(tctx
, credentials
!= NULL
, "cli_credentials_shallow_copy");
4266 ok
= cli_credentials_set_smb_encryption(credentials
,
4267 SMB_ENCRYPTION_REQUIRED
,
4269 torture_assert(tctx
, ok
, "cli_credentials_set_smb_encryption");
4271 options1
= transport0
->options
;
4272 options1
.client_guid
= GUID_random();
4273 options1
.min_protocol
= PROTOCOL_SMB3_11
;
4274 options1
.max_protocol
= PROTOCOL_SMB3_11
;
4275 options1
.signing
= SMB_SIGNING_REQUIRED
;
4276 options1
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
4279 SMB2_SIGNING_AES128_GMAC
,
4282 options1
.smb3_capabilities
.encryption
= (struct smb3_encryption_capabilities
) {
4285 SMB2_ENCRYPTION_AES128_GCM
,
4289 /* different client guid */
4290 options2
= options1
;
4291 options2
.client_guid
= GUID_random();
4292 options2
.only_negprot
= true;
4293 options2
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
4296 SMB2_SIGNING_HMAC_SHA256
,
4299 options2
.smb3_capabilities
.encryption
= (struct smb3_encryption_capabilities
) {
4302 SMB2_ENCRYPTION_AES128_CCM
,
4306 ret
= test_session_bind_negative_smbXtoX(tctx
, __func__
,
4308 &options1
, &options2
,
4309 NT_STATUS_REQUEST_OUT_OF_SEQUENCE
);
4314 static bool test_session_bind_negative_smb3sneCtoGs(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
4316 struct cli_credentials
*credentials0
= samba_cmdline_get_creds();
4317 struct cli_credentials
*credentials
= NULL
;
4319 struct smb2_transport
*transport0
= tree0
->session
->transport
;
4320 struct smbcli_options options1
;
4321 struct smbcli_options options2
;
4324 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_11
) {
4326 "Can't test without SMB 3.1.1 support");
4329 if (smb2cli_conn_server_signing_algo(transport0
->conn
) < SMB2_SIGNING_AES128_GMAC
) {
4331 "Can't test without SMB 3.1.1 signing negotiation support");
4334 credentials
= cli_credentials_shallow_copy(tctx
, credentials0
);
4335 torture_assert(tctx
, credentials
!= NULL
, "cli_credentials_shallow_copy");
4336 ok
= cli_credentials_set_smb_encryption(credentials
,
4337 SMB_ENCRYPTION_REQUIRED
,
4339 torture_assert(tctx
, ok
, "cli_credentials_set_smb_encryption");
4341 options1
= transport0
->options
;
4342 options1
.client_guid
= GUID_random();
4343 options1
.min_protocol
= PROTOCOL_SMB3_11
;
4344 options1
.max_protocol
= PROTOCOL_SMB3_11
;
4345 options1
.signing
= SMB_SIGNING_REQUIRED
;
4346 options1
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
4349 SMB2_SIGNING_AES128_CMAC
,
4352 options1
.smb3_capabilities
.encryption
= (struct smb3_encryption_capabilities
) {
4355 SMB2_ENCRYPTION_AES128_CCM
,
4359 /* same client guid */
4360 options2
= options1
;
4361 options2
.only_negprot
= true;
4362 options2
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
4365 SMB2_SIGNING_AES128_GMAC
,
4368 options2
.smb3_capabilities
.encryption
= (struct smb3_encryption_capabilities
) {
4371 SMB2_ENCRYPTION_AES128_GCM
,
4375 ret
= test_session_bind_negative_smbXtoX(tctx
, __func__
,
4377 &options1
, &options2
,
4378 NT_STATUS_NOT_SUPPORTED
);
4383 static bool test_session_bind_negative_smb3sneCtoGd(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
4385 struct cli_credentials
*credentials0
= samba_cmdline_get_creds();
4386 struct cli_credentials
*credentials
= NULL
;
4388 struct smb2_transport
*transport0
= tree0
->session
->transport
;
4389 struct smbcli_options options1
;
4390 struct smbcli_options options2
;
4393 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_11
) {
4395 "Can't test without SMB 3.1.1 support");
4398 if (smb2cli_conn_server_signing_algo(transport0
->conn
) < SMB2_SIGNING_AES128_GMAC
) {
4400 "Can't test without SMB 3.1.1 signing negotiation support");
4403 credentials
= cli_credentials_shallow_copy(tctx
, credentials0
);
4404 torture_assert(tctx
, credentials
!= NULL
, "cli_credentials_shallow_copy");
4405 ok
= cli_credentials_set_smb_encryption(credentials
,
4406 SMB_ENCRYPTION_REQUIRED
,
4408 torture_assert(tctx
, ok
, "cli_credentials_set_smb_encryption");
4410 options1
= transport0
->options
;
4411 options1
.client_guid
= GUID_random();
4412 options1
.min_protocol
= PROTOCOL_SMB3_11
;
4413 options1
.max_protocol
= PROTOCOL_SMB3_11
;
4414 options1
.signing
= SMB_SIGNING_REQUIRED
;
4415 options1
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
4418 SMB2_SIGNING_AES128_CMAC
,
4421 options1
.smb3_capabilities
.encryption
= (struct smb3_encryption_capabilities
) {
4424 SMB2_ENCRYPTION_AES128_CCM
,
4428 /* different client guid */
4429 options2
= options1
;
4430 options2
.client_guid
= GUID_random();
4431 options2
.only_negprot
= true;
4432 options2
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
4435 SMB2_SIGNING_AES128_GMAC
,
4438 options2
.smb3_capabilities
.encryption
= (struct smb3_encryption_capabilities
) {
4441 SMB2_ENCRYPTION_AES128_GCM
,
4445 ret
= test_session_bind_negative_smbXtoX(tctx
, __func__
,
4447 &options1
, &options2
,
4448 NT_STATUS_NOT_SUPPORTED
);
4453 static bool test_session_bind_negative_smb3sneHtoGs(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
4455 struct cli_credentials
*credentials0
= samba_cmdline_get_creds();
4456 struct cli_credentials
*credentials
= NULL
;
4458 struct smb2_transport
*transport0
= tree0
->session
->transport
;
4459 struct smbcli_options options1
;
4460 struct smbcli_options options2
;
4463 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_11
) {
4465 "Can't test without SMB 3.1.1 support");
4468 if (smb2cli_conn_server_signing_algo(transport0
->conn
) < SMB2_SIGNING_AES128_GMAC
) {
4470 "Can't test without SMB 3.1.1 signing negotiation support");
4473 credentials
= cli_credentials_shallow_copy(tctx
, credentials0
);
4474 torture_assert(tctx
, credentials
!= NULL
, "cli_credentials_shallow_copy");
4475 ok
= cli_credentials_set_smb_encryption(credentials
,
4476 SMB_ENCRYPTION_REQUIRED
,
4478 torture_assert(tctx
, ok
, "cli_credentials_set_smb_encryption");
4480 options1
= transport0
->options
;
4481 options1
.client_guid
= GUID_random();
4482 options1
.min_protocol
= PROTOCOL_SMB3_11
;
4483 options1
.max_protocol
= PROTOCOL_SMB3_11
;
4484 options1
.signing
= SMB_SIGNING_REQUIRED
;
4485 options1
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
4488 SMB2_SIGNING_HMAC_SHA256
,
4491 options1
.smb3_capabilities
.encryption
= (struct smb3_encryption_capabilities
) {
4494 SMB2_ENCRYPTION_AES128_CCM
,
4498 /* same client guid */
4499 options2
= options1
;
4500 options2
.only_negprot
= true;
4501 options2
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
4504 SMB2_SIGNING_AES128_GMAC
,
4507 options2
.smb3_capabilities
.encryption
= (struct smb3_encryption_capabilities
) {
4510 SMB2_ENCRYPTION_AES128_GCM
,
4514 ret
= test_session_bind_negative_smbXtoX(tctx
, __func__
,
4516 &options1
, &options2
,
4517 NT_STATUS_NOT_SUPPORTED
);
4522 static bool test_session_bind_negative_smb3sneHtoGd(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
4524 struct cli_credentials
*credentials0
= samba_cmdline_get_creds();
4525 struct cli_credentials
*credentials
= NULL
;
4527 struct smb2_transport
*transport0
= tree0
->session
->transport
;
4528 struct smbcli_options options1
;
4529 struct smbcli_options options2
;
4532 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_11
) {
4534 "Can't test without SMB 3.1.1 support");
4537 if (smb2cli_conn_server_signing_algo(transport0
->conn
) < SMB2_SIGNING_AES128_GMAC
) {
4539 "Can't test without SMB 3.1.1 signing negotiation support");
4542 credentials
= cli_credentials_shallow_copy(tctx
, credentials0
);
4543 torture_assert(tctx
, credentials
!= NULL
, "cli_credentials_shallow_copy");
4544 ok
= cli_credentials_set_smb_encryption(credentials
,
4545 SMB_ENCRYPTION_REQUIRED
,
4547 torture_assert(tctx
, ok
, "cli_credentials_set_smb_encryption");
4549 options1
= transport0
->options
;
4550 options1
.client_guid
= GUID_random();
4551 options1
.min_protocol
= PROTOCOL_SMB3_11
;
4552 options1
.max_protocol
= PROTOCOL_SMB3_11
;
4553 options1
.signing
= SMB_SIGNING_REQUIRED
;
4554 options1
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
4557 SMB2_SIGNING_HMAC_SHA256
,
4560 options1
.smb3_capabilities
.encryption
= (struct smb3_encryption_capabilities
) {
4563 SMB2_ENCRYPTION_AES128_CCM
,
4567 /* different client guid */
4568 options2
= options1
;
4569 options2
.client_guid
= GUID_random();
4570 options2
.only_negprot
= true;
4571 options2
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
4574 SMB2_SIGNING_AES128_GMAC
,
4577 options2
.smb3_capabilities
.encryption
= (struct smb3_encryption_capabilities
) {
4580 SMB2_ENCRYPTION_AES128_GCM
,
4584 ret
= test_session_bind_negative_smbXtoX(tctx
, __func__
,
4586 &options1
, &options2
,
4587 NT_STATUS_NOT_SUPPORTED
);
4592 static bool test_session_bind_negative_smb3signC30toGs(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
4594 struct cli_credentials
*credentials0
= samba_cmdline_get_creds();
4595 struct cli_credentials
*credentials
= NULL
;
4597 struct smb2_transport
*transport0
= tree0
->session
->transport
;
4598 struct smbcli_options options1
;
4599 struct smbcli_options options2
;
4602 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_11
) {
4604 "Can't test without SMB 3.1.1 support");
4607 if (smb2cli_conn_server_signing_algo(transport0
->conn
) < SMB2_SIGNING_AES128_GMAC
) {
4609 "Can't test without SMB 3.1.1 signing negotiation support");
4612 credentials
= cli_credentials_shallow_copy(tctx
, credentials0
);
4613 torture_assert(tctx
, credentials
!= NULL
, "cli_credentials_shallow_copy");
4614 ok
= cli_credentials_set_smb_encryption(credentials
,
4615 SMB_ENCRYPTION_REQUIRED
,
4617 torture_assert(tctx
, ok
, "cli_credentials_set_smb_encryption");
4619 options1
= transport0
->options
;
4620 options1
.client_guid
= GUID_random();
4621 options1
.min_protocol
= PROTOCOL_SMB3_00
;
4622 options1
.max_protocol
= PROTOCOL_SMB3_02
;
4623 options1
.signing
= SMB_SIGNING_REQUIRED
;
4625 /* same client guid */
4626 options2
= options1
;
4627 options2
.only_negprot
= true;
4628 options2
.min_protocol
= PROTOCOL_SMB3_11
;
4629 options2
.max_protocol
= PROTOCOL_SMB3_11
;
4630 options2
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
4633 SMB2_SIGNING_AES128_GMAC
,
4637 ret
= test_session_bind_negative_smbXtoX(tctx
, __func__
,
4639 &options1
, &options2
,
4640 NT_STATUS_NOT_SUPPORTED
);
4645 static bool test_session_bind_negative_smb3signC30toGd(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
4647 struct cli_credentials
*credentials0
= samba_cmdline_get_creds();
4648 struct cli_credentials
*credentials
= NULL
;
4650 struct smb2_transport
*transport0
= tree0
->session
->transport
;
4651 struct smbcli_options options1
;
4652 struct smbcli_options options2
;
4655 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_11
) {
4657 "Can't test without SMB 3.1.1 support");
4660 if (smb2cli_conn_server_signing_algo(transport0
->conn
) < SMB2_SIGNING_AES128_GMAC
) {
4662 "Can't test without SMB 3.1.1 signing negotiation support");
4665 credentials
= cli_credentials_shallow_copy(tctx
, credentials0
);
4666 torture_assert(tctx
, credentials
!= NULL
, "cli_credentials_shallow_copy");
4667 ok
= cli_credentials_set_smb_encryption(credentials
,
4668 SMB_ENCRYPTION_REQUIRED
,
4670 torture_assert(tctx
, ok
, "cli_credentials_set_smb_encryption");
4672 options1
= transport0
->options
;
4673 options1
.client_guid
= GUID_random();
4674 options1
.min_protocol
= PROTOCOL_SMB3_00
;
4675 options1
.max_protocol
= PROTOCOL_SMB3_02
;
4676 options1
.signing
= SMB_SIGNING_REQUIRED
;
4678 /* different client guid */
4679 options2
= options1
;
4680 options2
.client_guid
= GUID_random();
4681 options2
.only_negprot
= true;
4682 options2
.min_protocol
= PROTOCOL_SMB3_11
;
4683 options2
.max_protocol
= PROTOCOL_SMB3_11
;
4684 options2
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
4687 SMB2_SIGNING_AES128_GMAC
,
4691 ret
= test_session_bind_negative_smbXtoX(tctx
, __func__
,
4693 &options1
, &options2
,
4694 NT_STATUS_NOT_SUPPORTED
);
4699 static bool test_session_bind_negative_smb3signH2XtoGs(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
4701 struct cli_credentials
*credentials0
= samba_cmdline_get_creds();
4702 struct cli_credentials
*credentials
= NULL
;
4704 struct smb2_transport
*transport0
= tree0
->session
->transport
;
4705 struct smbcli_options options1
;
4706 struct smbcli_options options2
;
4710 encrypted
= smb2cli_tcon_is_encryption_on(tree0
->smbXcli
);
4713 "Can't test SMB 2.10 if encryption is required");
4716 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_11
) {
4718 "Can't test without SMB 3.1.1 support");
4721 if (smb2cli_conn_server_signing_algo(transport0
->conn
) < SMB2_SIGNING_AES128_GMAC
) {
4723 "Can't test without SMB 3.1.1 signing negotiation support");
4726 credentials
= cli_credentials_shallow_copy(tctx
, credentials0
);
4727 torture_assert(tctx
, credentials
!= NULL
, "cli_credentials_shallow_copy");
4728 ok
= cli_credentials_set_smb_encryption(credentials
,
4731 torture_assert(tctx
, ok
, "cli_credentials_set_smb_encryption");
4733 options1
= transport0
->options
;
4734 options1
.client_guid
= GUID_random();
4735 options1
.min_protocol
= PROTOCOL_SMB2_02
;
4736 options1
.max_protocol
= PROTOCOL_SMB2_10
;
4737 options1
.signing
= SMB_SIGNING_REQUIRED
;
4739 /* same client guid */
4740 options2
= options1
;
4741 options2
.only_negprot
= true;
4742 options2
.min_protocol
= PROTOCOL_SMB3_11
;
4743 options2
.max_protocol
= PROTOCOL_SMB3_11
;
4744 options2
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
4747 SMB2_SIGNING_AES128_GMAC
,
4751 ret
= test_session_bind_negative_smbXtoX(tctx
, __func__
,
4753 &options1
, &options2
,
4754 NT_STATUS_NOT_SUPPORTED
);
4759 static bool test_session_bind_negative_smb3signH2XtoGd(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
4761 struct cli_credentials
*credentials0
= samba_cmdline_get_creds();
4762 struct cli_credentials
*credentials
= NULL
;
4764 struct smb2_transport
*transport0
= tree0
->session
->transport
;
4765 struct smbcli_options options1
;
4766 struct smbcli_options options2
;
4770 encrypted
= smb2cli_tcon_is_encryption_on(tree0
->smbXcli
);
4773 "Can't test SMB 2.10 if encryption is required");
4776 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_11
) {
4778 "Can't test without SMB 3.1.1 support");
4781 if (smb2cli_conn_server_signing_algo(transport0
->conn
) < SMB2_SIGNING_AES128_GMAC
) {
4783 "Can't test without SMB 3.1.1 signing negotiation support");
4786 credentials
= cli_credentials_shallow_copy(tctx
, credentials0
);
4787 torture_assert(tctx
, credentials
!= NULL
, "cli_credentials_shallow_copy");
4788 ok
= cli_credentials_set_smb_encryption(credentials
,
4791 torture_assert(tctx
, ok
, "cli_credentials_set_smb_encryption");
4793 options1
= transport0
->options
;
4794 options1
.client_guid
= GUID_random();
4795 options1
.min_protocol
= PROTOCOL_SMB2_02
;
4796 options1
.max_protocol
= PROTOCOL_SMB2_10
;
4797 options1
.signing
= SMB_SIGNING_REQUIRED
;
4799 /* different client guid */
4800 options2
= options1
;
4801 options2
.client_guid
= GUID_random();
4802 options2
.only_negprot
= true;
4803 options2
.min_protocol
= PROTOCOL_SMB3_11
;
4804 options2
.max_protocol
= PROTOCOL_SMB3_11
;
4805 options2
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
4808 SMB2_SIGNING_AES128_GMAC
,
4812 ret
= test_session_bind_negative_smbXtoX(tctx
, __func__
,
4814 &options1
, &options2
,
4815 NT_STATUS_NOT_SUPPORTED
);
4820 static bool test_session_bind_negative_smb3signGtoC30s(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
4822 struct cli_credentials
*credentials0
= samba_cmdline_get_creds();
4823 struct cli_credentials
*credentials
= NULL
;
4825 struct smb2_transport
*transport0
= tree0
->session
->transport
;
4826 struct smbcli_options options1
;
4827 struct smbcli_options options2
;
4830 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_11
) {
4832 "Can't test without SMB 3.1.1 support");
4835 if (smb2cli_conn_server_signing_algo(transport0
->conn
) < SMB2_SIGNING_AES128_GMAC
) {
4837 "Can't test without SMB 3.1.1 signing negotiation support");
4840 credentials
= cli_credentials_shallow_copy(tctx
, credentials0
);
4841 torture_assert(tctx
, credentials
!= NULL
, "cli_credentials_shallow_copy");
4842 ok
= cli_credentials_set_smb_encryption(credentials
,
4843 SMB_ENCRYPTION_REQUIRED
,
4845 torture_assert(tctx
, ok
, "cli_credentials_set_smb_encryption");
4847 options1
= transport0
->options
;
4848 options1
.client_guid
= GUID_random();
4849 options1
.min_protocol
= PROTOCOL_SMB3_11
;
4850 options1
.max_protocol
= PROTOCOL_SMB3_11
;
4851 options1
.signing
= SMB_SIGNING_REQUIRED
;
4852 options1
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
4855 SMB2_SIGNING_AES128_GMAC
,
4859 /* same client guid */
4860 options2
= options1
;
4861 options2
.only_negprot
= true;
4862 options2
.min_protocol
= PROTOCOL_SMB3_00
;
4863 options2
.max_protocol
= PROTOCOL_SMB3_02
;
4864 options2
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
4867 SMB2_SIGNING_AES128_CMAC
,
4871 ret
= test_session_bind_negative_smbXtoX(tctx
, __func__
,
4873 &options1
, &options2
,
4874 NT_STATUS_REQUEST_OUT_OF_SEQUENCE
);
4879 static bool test_session_bind_negative_smb3signGtoC30d(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
4881 struct cli_credentials
*credentials0
= samba_cmdline_get_creds();
4882 struct cli_credentials
*credentials
= NULL
;
4884 struct smb2_transport
*transport0
= tree0
->session
->transport
;
4885 struct smbcli_options options1
;
4886 struct smbcli_options options2
;
4889 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_11
) {
4891 "Can't test without SMB 3.1.1 support");
4894 if (smb2cli_conn_server_signing_algo(transport0
->conn
) < SMB2_SIGNING_AES128_GMAC
) {
4896 "Can't test without SMB 3.1.1 signing negotiation support");
4899 credentials
= cli_credentials_shallow_copy(tctx
, credentials0
);
4900 torture_assert(tctx
, credentials
!= NULL
, "cli_credentials_shallow_copy");
4901 ok
= cli_credentials_set_smb_encryption(credentials
,
4902 SMB_ENCRYPTION_REQUIRED
,
4904 torture_assert(tctx
, ok
, "cli_credentials_set_smb_encryption");
4906 options1
= transport0
->options
;
4907 options1
.client_guid
= GUID_random();
4908 options1
.min_protocol
= PROTOCOL_SMB3_11
;
4909 options1
.max_protocol
= PROTOCOL_SMB3_11
;
4910 options1
.signing
= SMB_SIGNING_REQUIRED
;
4911 options1
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
4914 SMB2_SIGNING_AES128_GMAC
,
4918 /* different client guid */
4919 options2
= options1
;
4920 options2
.client_guid
= GUID_random();
4921 options2
.only_negprot
= true;
4922 options2
.min_protocol
= PROTOCOL_SMB3_00
;
4923 options2
.max_protocol
= PROTOCOL_SMB3_02
;
4924 options2
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
4927 SMB2_SIGNING_AES128_CMAC
,
4931 ret
= test_session_bind_negative_smbXtoX(tctx
, __func__
,
4933 &options1
, &options2
,
4934 NT_STATUS_REQUEST_OUT_OF_SEQUENCE
);
4939 static bool test_session_bind_negative_smb3signGtoH2Xs(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
4941 struct cli_credentials
*credentials0
= samba_cmdline_get_creds();
4942 struct cli_credentials
*credentials
= NULL
;
4944 struct smb2_transport
*transport0
= tree0
->session
->transport
;
4945 struct smbcli_options options1
;
4946 struct smbcli_options options2
;
4950 encrypted
= smb2cli_tcon_is_encryption_on(tree0
->smbXcli
);
4953 "Can't test SMB 2.10 if encryption is required");
4956 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_11
) {
4958 "Can't test without SMB 3.1.1 support");
4961 if (smb2cli_conn_server_signing_algo(transport0
->conn
) < SMB2_SIGNING_AES128_GMAC
) {
4963 "Can't test without SMB 3.1.1 signing negotiation support");
4966 credentials
= cli_credentials_shallow_copy(tctx
, credentials0
);
4967 torture_assert(tctx
, credentials
!= NULL
, "cli_credentials_shallow_copy");
4968 ok
= cli_credentials_set_smb_encryption(credentials
,
4969 SMB_ENCRYPTION_REQUIRED
,
4971 torture_assert(tctx
, ok
, "cli_credentials_set_smb_encryption");
4973 options1
= transport0
->options
;
4974 options1
.client_guid
= GUID_random();
4975 options1
.min_protocol
= PROTOCOL_SMB3_11
;
4976 options1
.max_protocol
= PROTOCOL_SMB3_11
;
4977 options1
.signing
= SMB_SIGNING_REQUIRED
;
4978 options1
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
4981 SMB2_SIGNING_AES128_GMAC
,
4985 /* same client guid */
4986 options2
= options1
;
4987 options2
.only_negprot
= true;
4988 options2
.min_protocol
= PROTOCOL_SMB2_02
;
4989 options2
.max_protocol
= PROTOCOL_SMB2_10
;
4990 options2
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
4993 SMB2_SIGNING_HMAC_SHA256
,
4997 ret
= test_session_bind_negative_smbXtoX(tctx
, __func__
,
4999 &options1
, &options2
,
5000 NT_STATUS_REQUEST_OUT_OF_SEQUENCE
);
5005 static bool test_session_bind_negative_smb3signGtoH2Xd(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
5007 struct cli_credentials
*credentials0
= samba_cmdline_get_creds();
5008 struct cli_credentials
*credentials
= NULL
;
5010 struct smb2_transport
*transport0
= tree0
->session
->transport
;
5011 struct smbcli_options options1
;
5012 struct smbcli_options options2
;
5016 encrypted
= smb2cli_tcon_is_encryption_on(tree0
->smbXcli
);
5019 "Can't test SMB 2.10 if encryption is required");
5022 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_11
) {
5024 "Can't test without SMB 3.1.1 support");
5027 if (smb2cli_conn_server_signing_algo(transport0
->conn
) < SMB2_SIGNING_AES128_GMAC
) {
5029 "Can't test without SMB 3.1.1 signing negotiation support");
5032 credentials
= cli_credentials_shallow_copy(tctx
, credentials0
);
5033 torture_assert(tctx
, credentials
!= NULL
, "cli_credentials_shallow_copy");
5034 ok
= cli_credentials_set_smb_encryption(credentials
,
5035 SMB_ENCRYPTION_REQUIRED
,
5037 torture_assert(tctx
, ok
, "cli_credentials_set_smb_encryption");
5039 options1
= transport0
->options
;
5040 options1
.client_guid
= GUID_random();
5041 options1
.min_protocol
= PROTOCOL_SMB3_11
;
5042 options1
.max_protocol
= PROTOCOL_SMB3_11
;
5043 options1
.signing
= SMB_SIGNING_REQUIRED
;
5044 options1
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
5047 SMB2_SIGNING_AES128_GMAC
,
5051 /* different client guid */
5052 options2
= options1
;
5053 options2
.client_guid
= GUID_random();
5054 options2
.only_negprot
= true;
5055 options2
.min_protocol
= PROTOCOL_SMB2_02
;
5056 options2
.max_protocol
= PROTOCOL_SMB2_10
;
5057 options2
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
5060 SMB2_SIGNING_HMAC_SHA256
,
5064 ret
= test_session_bind_negative_smbXtoX(tctx
, __func__
,
5066 &options1
, &options2
,
5067 NT_STATUS_REQUEST_OUT_OF_SEQUENCE
);
5072 static bool test_session_two_logoff(struct torture_context
*tctx
,
5073 struct smb2_tree
*tree1
)
5077 struct smbcli_options transport2_options
;
5078 struct smb2_tree
*tree2
= NULL
;
5079 struct smb2_session
*session2
= NULL
;
5080 struct smb2_session
*session1
= tree1
->session
;
5081 struct smb2_transport
*transport1
= tree1
->session
->transport
;
5082 struct smb2_transport
*transport2
;
5085 /* Connect 2nd connection */
5086 torture_comment(tctx
, "connect tree2 with the same client_guid\n");
5087 transport2_options
= transport1
->options
;
5088 ok
= torture_smb2_connection_ext(tctx
, 0, &transport2_options
, &tree2
);
5089 torture_assert(tctx
, ok
, "couldn't connect tree2\n");
5090 transport2
= tree2
->session
->transport
;
5091 session2
= tree2
->session
;
5093 torture_comment(tctx
, "session2: logoff\n");
5094 status
= smb2_logoff(session2
);
5095 torture_assert_ntstatus_ok(tctx
, status
, "session2: logoff");
5096 torture_comment(tctx
, "transport2: keepalive\n");
5097 status
= smb2_keepalive(transport2
);
5098 torture_assert_ntstatus_ok(tctx
, status
, "transport2: keepalive");
5099 torture_comment(tctx
, "transport2: disconnect\n");
5102 torture_comment(tctx
, "session1: logoff\n");
5103 status
= smb2_logoff(session1
);
5104 torture_assert_ntstatus_ok(tctx
, status
, "session1: logoff");
5105 torture_comment(tctx
, "transport1: keepalive\n");
5106 status
= smb2_keepalive(transport1
);
5107 torture_assert_ntstatus_ok(tctx
, status
, "transport1: keepalive");
5108 torture_comment(tctx
, "transport1: disconnect\n");
5114 static bool test_session_sign_enc(struct torture_context
*tctx
,
5115 const char *testname
,
5116 struct cli_credentials
*credentials1
,
5117 const struct smbcli_options
*options1
)
5119 const char *host
= torture_setting_string(tctx
, "host", NULL
);
5120 const char *share
= torture_setting_string(tctx
, "share", NULL
);
5123 struct smb2_tree
*tree1
= NULL
;
5125 struct smb2_handle rh
= {{0}};
5126 struct smb2_handle _h1
;
5127 struct smb2_handle
*h1
= NULL
;
5128 struct smb2_create io1
;
5129 union smb_fileinfo qfinfo1
;
5130 union smb_notify notify
;
5131 struct smb2_request
*req
= NULL
;
5133 status
= smb2_connect(tctx
,
5135 lpcfg_smb_ports(tctx
->lp_ctx
),
5137 lpcfg_resolve_context(tctx
->lp_ctx
),
5142 lpcfg_socket_options(tctx
->lp_ctx
),
5143 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
)
5145 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
5146 "smb2_connect options1 failed");
5148 status
= smb2_util_roothandle(tree1
, &rh
);
5149 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
5150 "smb2_util_roothandle failed");
5152 /* Add some random component to the file name. */
5153 snprintf(fname
, sizeof(fname
), "%s_%s.dat",
5154 testname
, generate_random_str(tctx
, 8));
5156 smb2_util_unlink(tree1
, fname
);
5158 smb2_oplock_create_share(&io1
, fname
,
5159 smb2_util_share_access(""),
5160 smb2_util_oplock_level("b"));
5162 io1
.in
.create_options
|= NTCREATEX_OPTIONS_DELETE_ON_CLOSE
;
5163 status
= smb2_create(tree1
, tctx
, &io1
);
5164 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
5165 "smb2_create failed");
5166 _h1
= io1
.out
.file
.handle
;
5168 CHECK_CREATED(tctx
, &io1
, CREATED
, FILE_ATTRIBUTE_ARCHIVE
);
5169 torture_assert_int_equal(tctx
, io1
.out
.oplock_level
,
5170 smb2_util_oplock_level("b"),
5171 "oplock_level incorrect");
5173 /* Check the initial session is still alive */
5174 ZERO_STRUCT(qfinfo1
);
5175 qfinfo1
.generic
.level
= RAW_FILEINFO_POSITION_INFORMATION
;
5176 qfinfo1
.generic
.in
.file
.handle
= _h1
;
5177 status
= smb2_getinfo_file(tree1
, tctx
, &qfinfo1
);
5178 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
5179 "smb2_getinfo_file failed");
5181 /* ask for a change notify,
5182 on file or directory name changes */
5183 ZERO_STRUCT(notify
);
5184 notify
.smb2
.level
= RAW_NOTIFY_SMB2
;
5185 notify
.smb2
.in
.buffer_size
= 1000;
5186 notify
.smb2
.in
.completion_filter
= FILE_NOTIFY_CHANGE_NAME
;
5187 notify
.smb2
.in
.file
.handle
= rh
;
5188 notify
.smb2
.in
.recursive
= true;
5190 req
= smb2_notify_send(tree1
, &(notify
.smb2
));
5191 WAIT_FOR_ASYNC_RESPONSE(req
);
5193 status
= smb2_cancel(req
);
5194 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
5195 "smb2_cancel failed");
5197 status
= smb2_notify_recv(req
, tctx
, &(notify
.smb2
));
5198 torture_assert_ntstatus_equal_goto(tctx
, status
, NT_STATUS_CANCELLED
,
5200 "smb2_notify_recv failed");
5202 /* Check the initial session is still alive */
5203 ZERO_STRUCT(qfinfo1
);
5204 qfinfo1
.generic
.level
= RAW_FILEINFO_POSITION_INFORMATION
;
5205 qfinfo1
.generic
.in
.file
.handle
= _h1
;
5206 status
= smb2_getinfo_file(tree1
, tctx
, &qfinfo1
);
5207 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
5208 "smb2_getinfo_file failed");
5213 smb2_util_close(tree1
, *h1
);
5220 static bool test_session_signing_hmac_sha_256(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
5222 struct cli_credentials
*credentials
= samba_cmdline_get_creds();
5224 struct smb2_transport
*transport0
= tree0
->session
->transport
;
5225 struct smbcli_options options1
;
5228 encrypted
= smb2cli_tcon_is_encryption_on(tree0
->smbXcli
);
5231 "Can't test signing only if encryption is required");
5234 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_11
) {
5236 "Can't test without SMB 3.1.1 support");
5239 if (smb2cli_conn_server_signing_algo(transport0
->conn
) < SMB2_SIGNING_AES128_GMAC
) {
5241 "Can't test without SMB 3.1.1 signing negotiation support");
5244 options1
= transport0
->options
;
5245 options1
.client_guid
= GUID_random();
5246 options1
.min_protocol
= PROTOCOL_SMB3_11
;
5247 options1
.max_protocol
= PROTOCOL_SMB3_11
;
5248 options1
.signing
= SMB_SIGNING_REQUIRED
;
5249 options1
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
5252 SMB2_SIGNING_HMAC_SHA256
,
5256 ret
= test_session_sign_enc(tctx
,
5264 static bool test_session_signing_aes_128_cmac(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
5266 struct cli_credentials
*credentials
= samba_cmdline_get_creds();
5268 struct smb2_transport
*transport0
= tree0
->session
->transport
;
5269 struct smbcli_options options1
;
5272 encrypted
= smb2cli_tcon_is_encryption_on(tree0
->smbXcli
);
5275 "Can't test signing only if encryption is required");
5278 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_11
) {
5280 "Can't test without SMB 3.1.1 support");
5283 if (smb2cli_conn_server_signing_algo(transport0
->conn
) < SMB2_SIGNING_AES128_GMAC
) {
5285 "Can't test without SMB 3.1.1 signing negotiation support");
5288 options1
= transport0
->options
;
5289 options1
.client_guid
= GUID_random();
5290 options1
.min_protocol
= PROTOCOL_SMB3_11
;
5291 options1
.max_protocol
= PROTOCOL_SMB3_11
;
5292 options1
.signing
= SMB_SIGNING_REQUIRED
;
5293 options1
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
5296 SMB2_SIGNING_AES128_CMAC
,
5300 ret
= test_session_sign_enc(tctx
,
5308 static bool test_session_signing_aes_128_gmac(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
5310 struct cli_credentials
*credentials
= samba_cmdline_get_creds();
5312 struct smb2_transport
*transport0
= tree0
->session
->transport
;
5313 struct smbcli_options options1
;
5316 encrypted
= smb2cli_tcon_is_encryption_on(tree0
->smbXcli
);
5319 "Can't test signing only if encryption is required");
5322 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_11
) {
5324 "Can't test without SMB 3.1.1 support");
5327 if (smb2cli_conn_server_signing_algo(transport0
->conn
) < SMB2_SIGNING_AES128_GMAC
) {
5329 "Can't test without SMB 3.1.1 signing negotiation support");
5332 options1
= transport0
->options
;
5333 options1
.client_guid
= GUID_random();
5334 options1
.min_protocol
= PROTOCOL_SMB3_11
;
5335 options1
.max_protocol
= PROTOCOL_SMB3_11
;
5336 options1
.signing
= SMB_SIGNING_REQUIRED
;
5337 options1
.smb3_capabilities
.signing
= (struct smb3_signing_capabilities
) {
5340 SMB2_SIGNING_AES128_GMAC
,
5344 ret
= test_session_sign_enc(tctx
,
5352 static bool test_session_encryption_aes_128_ccm(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
5354 struct cli_credentials
*credentials0
= samba_cmdline_get_creds();
5355 struct cli_credentials
*credentials
= NULL
;
5357 struct smb2_transport
*transport0
= tree0
->session
->transport
;
5358 struct smbcli_options options1
;
5361 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_11
) {
5363 "Can't test without SMB 3.1.1 support");
5366 if (smb2cli_conn_server_signing_algo(transport0
->conn
) < SMB2_SIGNING_AES128_GMAC
) {
5368 "Can't test without SMB 3.1.1 signing negotiation support");
5371 credentials
= cli_credentials_shallow_copy(tctx
, credentials0
);
5372 torture_assert(tctx
, credentials
!= NULL
, "cli_credentials_shallow_copy");
5373 ok
= cli_credentials_set_smb_encryption(credentials
,
5374 SMB_ENCRYPTION_REQUIRED
,
5376 torture_assert(tctx
, ok
, "cli_credentials_set_smb_encryption");
5378 options1
= transport0
->options
;
5379 options1
.client_guid
= GUID_random();
5380 options1
.min_protocol
= PROTOCOL_SMB3_11
;
5381 options1
.max_protocol
= PROTOCOL_SMB3_11
;
5382 options1
.signing
= SMB_SIGNING_REQUIRED
;
5383 options1
.smb3_capabilities
.encryption
= (struct smb3_encryption_capabilities
) {
5386 SMB2_ENCRYPTION_AES128_CCM
,
5390 ret
= test_session_sign_enc(tctx
,
5398 static bool test_session_encryption_aes_128_gcm(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
5400 struct cli_credentials
*credentials0
= samba_cmdline_get_creds();
5401 struct cli_credentials
*credentials
= NULL
;
5403 struct smb2_transport
*transport0
= tree0
->session
->transport
;
5404 struct smbcli_options options1
;
5407 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_11
) {
5409 "Can't test without SMB 3.1.1 support");
5412 if (smb2cli_conn_server_signing_algo(transport0
->conn
) < SMB2_SIGNING_AES128_GMAC
) {
5414 "Can't test without SMB 3.1.1 signing negotiation support");
5417 credentials
= cli_credentials_shallow_copy(tctx
, credentials0
);
5418 torture_assert(tctx
, credentials
!= NULL
, "cli_credentials_shallow_copy");
5419 ok
= cli_credentials_set_smb_encryption(credentials
,
5420 SMB_ENCRYPTION_REQUIRED
,
5422 torture_assert(tctx
, ok
, "cli_credentials_set_smb_encryption");
5424 options1
= transport0
->options
;
5425 options1
.client_guid
= GUID_random();
5426 options1
.min_protocol
= PROTOCOL_SMB3_11
;
5427 options1
.max_protocol
= PROTOCOL_SMB3_11
;
5428 options1
.signing
= SMB_SIGNING_REQUIRED
;
5429 options1
.smb3_capabilities
.encryption
= (struct smb3_encryption_capabilities
) {
5432 SMB2_ENCRYPTION_AES128_GCM
,
5436 ret
= test_session_sign_enc(tctx
,
5444 static bool test_session_encryption_aes_256_ccm(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
5446 struct cli_credentials
*credentials0
= samba_cmdline_get_creds();
5447 struct cli_credentials
*credentials
= NULL
;
5449 struct smb2_transport
*transport0
= tree0
->session
->transport
;
5450 struct smbcli_options options1
;
5453 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_11
) {
5455 "Can't test without SMB 3.1.1 support");
5458 if (smb2cli_conn_server_signing_algo(transport0
->conn
) < SMB2_SIGNING_AES128_GMAC
) {
5460 "Can't test without SMB 3.1.1 signing negotiation support");
5463 credentials
= cli_credentials_shallow_copy(tctx
, credentials0
);
5464 torture_assert(tctx
, credentials
!= NULL
, "cli_credentials_shallow_copy");
5465 ok
= cli_credentials_set_smb_encryption(credentials
,
5466 SMB_ENCRYPTION_REQUIRED
,
5468 torture_assert(tctx
, ok
, "cli_credentials_set_smb_encryption");
5470 options1
= transport0
->options
;
5471 options1
.client_guid
= GUID_random();
5472 options1
.min_protocol
= PROTOCOL_SMB3_11
;
5473 options1
.max_protocol
= PROTOCOL_SMB3_11
;
5474 options1
.signing
= SMB_SIGNING_REQUIRED
;
5475 options1
.smb3_capabilities
.encryption
= (struct smb3_encryption_capabilities
) {
5478 SMB2_ENCRYPTION_AES256_CCM
,
5482 ret
= test_session_sign_enc(tctx
,
5490 static bool test_session_encryption_aes_256_gcm(struct torture_context
*tctx
, struct smb2_tree
*tree0
)
5492 struct cli_credentials
*credentials0
= samba_cmdline_get_creds();
5493 struct cli_credentials
*credentials
= NULL
;
5495 struct smb2_transport
*transport0
= tree0
->session
->transport
;
5496 struct smbcli_options options1
;
5499 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_11
) {
5501 "Can't test without SMB 3.1.1 support");
5504 if (smb2cli_conn_server_signing_algo(transport0
->conn
) < SMB2_SIGNING_AES128_GMAC
) {
5506 "Can't test without SMB 3.1.1 signing negotiation support");
5509 credentials
= cli_credentials_shallow_copy(tctx
, credentials0
);
5510 torture_assert(tctx
, credentials
!= NULL
, "cli_credentials_shallow_copy");
5511 ok
= cli_credentials_set_smb_encryption(credentials
,
5512 SMB_ENCRYPTION_REQUIRED
,
5514 torture_assert(tctx
, ok
, "cli_credentials_set_smb_encryption");
5516 options1
= transport0
->options
;
5517 options1
.client_guid
= GUID_random();
5518 options1
.min_protocol
= PROTOCOL_SMB3_11
;
5519 options1
.max_protocol
= PROTOCOL_SMB3_11
;
5520 options1
.signing
= SMB_SIGNING_REQUIRED
;
5521 options1
.smb3_capabilities
.encryption
= (struct smb3_encryption_capabilities
) {
5524 SMB2_ENCRYPTION_AES256_GCM
,
5528 ret
= test_session_sign_enc(tctx
,
5536 static bool test_session_ntlmssp_bug14932(struct torture_context
*tctx
, struct smb2_tree
*tree
)
5538 struct cli_credentials
*ntlm_creds
=
5539 cli_credentials_shallow_copy(tctx
, samba_cmdline_get_creds());
5543 * This is a NTLMv2_RESPONSE with the strange
5544 * NTLMv2_CLIENT_CHALLENGE used by the net diag
5547 * As we expect an error anyway we fill the
5548 * Response part with 0xab...
5550 static const char *netapp_magic
=
5551 "\xab\xab\xab\xab\xab\xab\xab\xab"
5552 "\xab\xab\xab\xab\xab\xab\xab\xab"
5553 "\x01\x01\x00\x00\x00\x00\x00\x00"
5554 "\x3f\x3f\x3f\x3f\x3f\x3f\x3f\x3f"
5555 "\xb8\x82\x3a\xf1\xb3\xdd\x08\x15"
5556 "\x00\x00\x00\x00\x11\xa2\x08\x81"
5557 "\x50\x38\x22\x78\x2b\x94\x47\xfe"
5558 "\x54\x94\x7b\xff\x17\x27\x5a\xb4"
5559 "\xf4\x18\xba\xdc\x2c\x38\xfd\x5b"
5560 "\xfb\x0e\xc1\x85\x1e\xcc\x92\xbb"
5561 "\x9b\xb1\xc4\xd5\x53\x14\xff\x8c"
5562 "\x76\x49\xf5\x45\x90\x19\xa2";
5563 DATA_BLOB lm_response
= data_blob_talloc_zero(tctx
, 24);
5564 DATA_BLOB lm_session_key
= data_blob_talloc_zero(tctx
, 16);
5565 DATA_BLOB nt_response
= data_blob_const(netapp_magic
, 95);
5566 DATA_BLOB nt_session_key
= data_blob_talloc_zero(tctx
, 16);
5568 cli_credentials_set_kerberos_state(ntlm_creds
,
5569 CRED_USE_KERBEROS_DISABLED
,
5571 cli_credentials_set_ntlm_response(ntlm_creds
,
5577 status
= smb2_session_setup_spnego(tree
->session
,
5579 0 /* previous_session_id */);
5580 torture_assert_ntstatus_equal(tctx
, status
, NT_STATUS_INVALID_PARAMETER
,
5581 "smb2_session_setup_spnego failed");
5586 static bool test_session_anon_encryption1(struct torture_context
*tctx
,
5587 struct smb2_tree
*tree0
)
5589 const char *host
= torture_setting_string(tctx
, "host", NULL
);
5590 const char *share
= "IPC$";
5592 struct smb2_transport
*transport0
= tree0
->session
->transport
;
5593 struct cli_credentials
*anon_creds
= NULL
;
5594 struct smbcli_options options
;
5595 struct smb2_transport
*transport
= NULL
;
5596 struct smb2_session
*anon_session
= NULL
;
5597 struct smb2_tree
*anon_tree
= NULL
;
5600 struct tevent_req
*subreq
= NULL
;
5601 uint32_t timeout_msec
;
5603 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_00
) {
5605 "Can't test without SMB3 support");
5608 unc
= talloc_asprintf(tctx
, "\\\\%s\\%s", host
, share
);
5609 torture_assert(tctx
, unc
!= NULL
, "talloc_asprintf");
5611 anon_creds
= cli_credentials_init_anon(tctx
);
5612 torture_assert(tctx
, anon_creds
!= NULL
, "cli_credentials_init_anon");
5613 ok
= cli_credentials_set_smb_encryption(anon_creds
,
5614 SMB_ENCRYPTION_REQUIRED
,
5616 torture_assert(tctx
, ok
, "cli_credentials_set_smb_encryption");
5618 options
= transport0
->options
;
5619 options
.client_guid
= GUID_random();
5620 options
.only_negprot
= true;
5622 status
= smb2_connect(tctx
,
5624 lpcfg_smb_ports(tctx
->lp_ctx
),
5626 lpcfg_resolve_context(tctx
->lp_ctx
),
5631 lpcfg_socket_options(tctx
->lp_ctx
),
5632 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
));
5633 torture_assert_ntstatus_ok(tctx
, status
, "smb2_connect failed");
5634 anon_session
= anon_tree
->session
;
5635 transport
= anon_session
->transport
;
5637 anon_session
->anonymous_session_key
= true;
5638 smb2cli_session_torture_anonymous_encryption(anon_session
->smbXcli
, true);
5640 status
= smb2_session_setup_spnego(anon_session
,
5642 0 /* previous_session_id */);
5643 torture_assert_ntstatus_ok(tctx
, status
,
5644 "smb2_session_setup_spnego failed");
5646 ok
= smbXcli_session_is_authenticated(anon_session
->smbXcli
);
5647 torture_assert(tctx
, !ok
, "smbXcli_session_is_authenticated(anon) wrong");
5650 * The connection is still in ConstrainedConnection state...
5652 * This will use encryption and causes a connection reset
5654 timeout_msec
= transport
->options
.request_timeout
* 1000;
5655 subreq
= smb2cli_tcon_send(tctx
,
5659 anon_session
->smbXcli
,
5663 torture_assert(tctx
, subreq
!= NULL
, "smb2cli_tcon_send");
5665 torture_assert(tctx
,
5666 tevent_req_poll_ntstatus(subreq
, tctx
->ev
, &status
),
5667 "tevent_req_poll_ntstatus");
5669 status
= smb2cli_tcon_recv(subreq
);
5670 TALLOC_FREE(subreq
);
5671 if (NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_DISCONNECTED
)) {
5672 status
= NT_STATUS_CONNECTION_RESET
;
5674 torture_assert_ntstatus_equal(tctx
, status
,
5675 NT_STATUS_CONNECTION_RESET
,
5676 "smb2cli_tcon_recv");
5678 ok
= smbXcli_conn_is_connected(transport
->conn
);
5679 torture_assert(tctx
, !ok
, "smbXcli_conn_is_connected still connected");
5684 static bool test_session_anon_encryption2(struct torture_context
*tctx
,
5685 struct smb2_tree
*tree0
)
5687 const char *host
= torture_setting_string(tctx
, "host", NULL
);
5688 const char *share
= "IPC$";
5690 struct smb2_transport
*transport0
= tree0
->session
->transport
;
5691 struct cli_credentials
*_creds
= samba_cmdline_get_creds();
5692 struct cli_credentials
*user_creds
= NULL
;
5693 struct cli_credentials
*anon_creds
= NULL
;
5694 struct smbcli_options options
;
5695 struct smb2_transport
*transport
= NULL
;
5696 struct smb2_session
*user_session
= NULL
;
5697 struct smb2_tree
*user_tree
= NULL
;
5698 struct smb2_session
*anon_session
= NULL
;
5699 struct smb2_tree
*anon_tree
= NULL
;
5700 struct smb2_ioctl ioctl
= {
5701 .level
= RAW_IOCTL_SMB2
,
5711 .function
= FSCTL_QUERY_NETWORK_INTERFACE_INFO
,
5712 /* Windows client sets this to 64KiB */
5713 .max_output_response
= 0x10000,
5714 .flags
= SMB2_IOCTL_FLAG_IS_FSCTL
,
5719 struct tevent_req
*subreq
= NULL
;
5720 uint32_t timeout_msec
;
5721 uint32_t caps
= smb2cli_conn_server_capabilities(transport0
->conn
);
5722 NTSTATUS expected_mc_status
;
5724 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_00
) {
5726 "Can't test without SMB3 support");
5729 if (caps
& SMB2_CAP_MULTI_CHANNEL
) {
5730 expected_mc_status
= NT_STATUS_OK
;
5732 expected_mc_status
= NT_STATUS_FS_DRIVER_REQUIRED
;
5735 unc
= talloc_asprintf(tctx
, "\\\\%s\\%s", host
, share
);
5736 torture_assert(tctx
, unc
!= NULL
, "talloc_asprintf");
5738 user_creds
= cli_credentials_shallow_copy(tctx
, _creds
);
5739 torture_assert(tctx
, user_creds
!= NULL
, "cli_credentials_shallow_copy");
5740 ok
= cli_credentials_set_smb_encryption(user_creds
,
5741 SMB_ENCRYPTION_REQUIRED
,
5743 torture_assert(tctx
, ok
, "cli_credentials_set_smb_encryption");
5745 anon_creds
= cli_credentials_init_anon(tctx
);
5746 torture_assert(tctx
, anon_creds
!= NULL
, "cli_credentials_init_anon");
5747 ok
= cli_credentials_set_smb_encryption(anon_creds
,
5748 SMB_ENCRYPTION_REQUIRED
,
5750 torture_assert(tctx
, ok
, "cli_credentials_set_smb_encryption");
5752 options
= transport0
->options
;
5753 options
.client_guid
= GUID_random();
5755 status
= smb2_connect(tctx
,
5757 lpcfg_smb_ports(tctx
->lp_ctx
),
5759 lpcfg_resolve_context(tctx
->lp_ctx
),
5764 lpcfg_socket_options(tctx
->lp_ctx
),
5765 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
));
5766 torture_assert_ntstatus_ok(tctx
, status
, "smb2_connect failed");
5767 user_session
= user_tree
->session
;
5768 transport
= user_session
->transport
;
5769 ok
= smb2cli_tcon_is_encryption_on(user_tree
->smbXcli
);
5770 torture_assert(tctx
, ok
, "smb2cli_tcon_is_encryption_on(user)");
5771 ok
= smbXcli_session_is_authenticated(user_session
->smbXcli
);
5772 torture_assert(tctx
, ok
, "smbXcli_session_is_authenticated(user)");
5774 anon_session
= smb2_session_init(transport
,
5775 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
),
5777 torture_assert(tctx
, anon_session
!= NULL
, "smb2_session_init(anon)");
5779 anon_session
->anonymous_session_key
= true;
5780 smb2cli_session_torture_anonymous_encryption(anon_session
->smbXcli
, true);
5782 status
= smb2_session_setup_spnego(anon_session
,
5784 0 /* previous_session_id */);
5785 torture_assert_ntstatus_ok(tctx
, status
,
5786 "smb2_session_setup_spnego failed");
5788 ok
= smb2cli_tcon_is_encryption_on(user_tree
->smbXcli
);
5789 torture_assert(tctx
, ok
, "smb2cli_tcon_is_encryption_on(anon)");
5790 ok
= smbXcli_session_is_authenticated(anon_session
->smbXcli
);
5791 torture_assert(tctx
, !ok
, "smbXcli_session_is_authenticated(anon) wrong");
5793 anon_tree
= smb2_tree_init(anon_session
, tctx
, false);
5794 torture_assert(tctx
, anon_tree
!= NULL
, "smb2_tree_init");
5796 timeout_msec
= transport
->options
.request_timeout
* 1000;
5797 subreq
= smb2cli_tcon_send(tctx
,
5801 anon_session
->smbXcli
,
5805 torture_assert(tctx
, subreq
!= NULL
, "smb2cli_tcon_send");
5807 torture_assert(tctx
,
5808 tevent_req_poll_ntstatus(subreq
, tctx
->ev
, &status
),
5809 "tevent_req_poll_ntstatus");
5811 status
= smb2cli_tcon_recv(subreq
);
5812 TALLOC_FREE(subreq
);
5813 torture_assert_ntstatus_ok(tctx
, status
,
5814 "smb2cli_tcon_recv(anon)");
5816 ok
= smbXcli_conn_is_connected(transport
->conn
);
5817 torture_assert(tctx
, ok
, "smbXcli_conn_is_connected");
5819 ok
= smb2cli_tcon_is_encryption_on(anon_tree
->smbXcli
);
5820 torture_assert(tctx
, ok
, "smb2cli_tcon_is_encryption_on(anon)");
5821 ok
= smbXcli_session_is_authenticated(anon_session
->smbXcli
);
5822 torture_assert(tctx
, !ok
, "smbXcli_session_is_authenticated(anon) wrong");
5824 status
= smb2_ioctl(user_tree
, tctx
, &ioctl
);
5825 torture_assert_ntstatus_equal(tctx
, status
, expected_mc_status
,
5826 "FSCTL_QUERY_NETWORK_INTERFACE_INFO user");
5828 ok
= smbXcli_conn_is_connected(transport
->conn
);
5829 torture_assert(tctx
, ok
, "smbXcli_conn_is_connected");
5831 status
= smb2_ioctl(anon_tree
, tctx
, &ioctl
);
5832 torture_assert_ntstatus_equal(tctx
, status
, expected_mc_status
,
5833 "FSCTL_QUERY_NETWORK_INTERFACE_INFO anonymous");
5835 ok
= smbXcli_conn_is_connected(transport
->conn
);
5836 torture_assert(tctx
, ok
, "smbXcli_conn_is_connected");
5838 status
= smb2_ioctl(user_tree
, tctx
, &ioctl
);
5839 torture_assert_ntstatus_equal(tctx
, status
, expected_mc_status
,
5840 "FSCTL_QUERY_NETWORK_INTERFACE_INFO user");
5842 ok
= smbXcli_conn_is_connected(transport
->conn
);
5843 torture_assert(tctx
, ok
, "smbXcli_conn_is_connected");
5845 status
= smb2_ioctl(anon_tree
, tctx
, &ioctl
);
5846 torture_assert_ntstatus_equal(tctx
, status
, expected_mc_status
,
5847 "FSCTL_QUERY_NETWORK_INTERFACE_INFO anonymous");
5849 ok
= smbXcli_conn_is_connected(transport
->conn
);
5850 torture_assert(tctx
, ok
, "smbXcli_conn_is_connected");
5855 static bool test_session_anon_encryption3(struct torture_context
*tctx
,
5856 struct smb2_tree
*tree0
)
5858 const char *host
= torture_setting_string(tctx
, "host", NULL
);
5859 const char *share
= "IPC$";
5861 struct smb2_transport
*transport0
= tree0
->session
->transport
;
5862 struct cli_credentials
*_creds
= samba_cmdline_get_creds();
5863 struct cli_credentials
*user_creds
= NULL
;
5864 struct cli_credentials
*anon_creds
= NULL
;
5865 struct smbcli_options options
;
5866 struct smb2_transport
*transport
= NULL
;
5867 struct smb2_session
*user_session
= NULL
;
5868 struct smb2_tree
*user_tree
= NULL
;
5869 struct smb2_session
*anon_session
= NULL
;
5870 struct smb2_tree
*anon_tree
= NULL
;
5873 struct tevent_req
*subreq
= NULL
;
5874 uint32_t timeout_msec
;
5875 uint8_t wrong_session_key
[16] = { 0x1f, 0x2f, 0x3f, };
5877 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_00
) {
5879 "Can't test without SMB3 support");
5882 unc
= talloc_asprintf(tctx
, "\\\\%s\\%s", host
, share
);
5883 torture_assert(tctx
, unc
!= NULL
, "talloc_asprintf");
5885 user_creds
= cli_credentials_shallow_copy(tctx
, _creds
);
5886 torture_assert(tctx
, user_creds
!= NULL
, "cli_credentials_shallow_copy");
5887 ok
= cli_credentials_set_smb_encryption(user_creds
,
5888 SMB_ENCRYPTION_REQUIRED
,
5890 torture_assert(tctx
, ok
, "cli_credentials_set_smb_encryption");
5892 anon_creds
= cli_credentials_init_anon(tctx
);
5893 torture_assert(tctx
, anon_creds
!= NULL
, "cli_credentials_init_anon");
5894 ok
= cli_credentials_set_smb_encryption(anon_creds
,
5895 SMB_ENCRYPTION_REQUIRED
,
5897 torture_assert(tctx
, ok
, "cli_credentials_set_smb_encryption");
5899 options
= transport0
->options
;
5900 options
.client_guid
= GUID_random();
5902 status
= smb2_connect(tctx
,
5904 lpcfg_smb_ports(tctx
->lp_ctx
),
5906 lpcfg_resolve_context(tctx
->lp_ctx
),
5911 lpcfg_socket_options(tctx
->lp_ctx
),
5912 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
));
5913 torture_assert_ntstatus_ok(tctx
, status
, "smb2_connect failed");
5914 user_session
= user_tree
->session
;
5915 transport
= user_session
->transport
;
5916 ok
= smb2cli_tcon_is_encryption_on(user_tree
->smbXcli
);
5917 torture_assert(tctx
, ok
, "smb2cli_tcon_is_encryption_on(user)");
5918 ok
= smbXcli_session_is_authenticated(user_session
->smbXcli
);
5919 torture_assert(tctx
, ok
, "smbXcli_session_is_authenticated(user)");
5921 anon_session
= smb2_session_init(transport
,
5922 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
),
5924 torture_assert(tctx
, anon_session
!= NULL
, "smb2_session_init(anon)");
5926 anon_session
->anonymous_session_key
= true;
5927 anon_session
->forced_session_key
= data_blob_const(wrong_session_key
,
5928 ARRAY_SIZE(wrong_session_key
));
5929 smb2cli_session_torture_anonymous_encryption(anon_session
->smbXcli
, true);
5931 status
= smb2_session_setup_spnego(anon_session
,
5933 0 /* previous_session_id */);
5934 torture_assert_ntstatus_ok(tctx
, status
,
5935 "smb2_session_setup_spnego failed");
5937 ok
= smb2cli_tcon_is_encryption_on(user_tree
->smbXcli
);
5938 torture_assert(tctx
, ok
, "smb2cli_tcon_is_encryption_on(anon)");
5939 ok
= smbXcli_session_is_authenticated(anon_session
->smbXcli
);
5940 torture_assert(tctx
, !ok
, "smbXcli_session_is_authenticated(anon) wrong");
5942 anon_tree
= smb2_tree_init(anon_session
, tctx
, false);
5943 torture_assert(tctx
, anon_tree
!= NULL
, "smb2_tree_init");
5945 timeout_msec
= transport
->options
.request_timeout
* 1000;
5946 subreq
= smb2cli_tcon_send(tctx
,
5950 anon_session
->smbXcli
,
5954 torture_assert(tctx
, subreq
!= NULL
, "smb2cli_tcon_send");
5956 torture_assert(tctx
,
5957 tevent_req_poll_ntstatus(subreq
, tctx
->ev
, &status
),
5958 "tevent_req_poll_ntstatus");
5960 status
= smb2cli_tcon_recv(subreq
);
5961 TALLOC_FREE(subreq
);
5962 if (NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_DISCONNECTED
)) {
5963 status
= NT_STATUS_CONNECTION_RESET
;
5965 torture_assert_ntstatus_equal(tctx
, status
,
5966 NT_STATUS_CONNECTION_RESET
,
5967 "smb2cli_tcon_recv");
5969 ok
= smbXcli_conn_is_connected(transport
->conn
);
5970 torture_assert(tctx
, !ok
, "smbXcli_conn_is_connected still connected");
5975 static bool test_session_anon_signing1(struct torture_context
*tctx
,
5976 struct smb2_tree
*tree0
)
5978 const char *host
= torture_setting_string(tctx
, "host", NULL
);
5979 const char *share
= "IPC$";
5981 struct smb2_transport
*transport0
= tree0
->session
->transport
;
5982 struct cli_credentials
*anon_creds
= NULL
;
5983 struct smbcli_options options
;
5984 struct smb2_transport
*transport
= NULL
;
5985 struct smb2_session
*anon_session
= NULL
;
5986 struct smb2_tree
*anon_tree
= NULL
;
5989 struct tevent_req
*subreq
= NULL
;
5990 uint32_t timeout_msec
;
5992 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_00
) {
5994 "Can't test without SMB3 support");
5997 unc
= talloc_asprintf(tctx
, "\\\\%s\\%s", host
, share
);
5998 torture_assert(tctx
, unc
!= NULL
, "talloc_asprintf");
6000 anon_creds
= cli_credentials_init_anon(tctx
);
6001 torture_assert(tctx
, anon_creds
!= NULL
, "cli_credentials_init_anon");
6002 ok
= cli_credentials_set_smb_signing(anon_creds
,
6003 SMB_SIGNING_REQUIRED
,
6005 torture_assert(tctx
, ok
, "cli_credentials_set_smb_signing");
6006 ok
= cli_credentials_set_smb_ipc_signing(anon_creds
,
6007 SMB_SIGNING_REQUIRED
,
6009 torture_assert(tctx
, ok
, "cli_credentials_set_smb_ipc_signing");
6010 ok
= cli_credentials_set_smb_encryption(anon_creds
,
6013 torture_assert(tctx
, ok
, "cli_credentials_set_smb_encryption");
6015 options
= transport0
->options
;
6016 options
.client_guid
= GUID_random();
6017 options
.only_negprot
= true;
6018 options
.signing
= SMB_SIGNING_REQUIRED
;
6020 status
= smb2_connect(tctx
,
6022 lpcfg_smb_ports(tctx
->lp_ctx
),
6024 lpcfg_resolve_context(tctx
->lp_ctx
),
6029 lpcfg_socket_options(tctx
->lp_ctx
),
6030 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
));
6031 torture_assert_ntstatus_ok(tctx
, status
, "smb2_connect failed");
6032 anon_session
= anon_tree
->session
;
6033 transport
= anon_session
->transport
;
6035 anon_session
->anonymous_session_key
= true;
6036 smb2cli_session_torture_anonymous_signing(anon_session
->smbXcli
, true);
6038 status
= smb2_session_setup_spnego(anon_session
,
6040 0 /* previous_session_id */);
6041 torture_assert_ntstatus_ok(tctx
, status
,
6042 "smb2_session_setup_spnego failed");
6044 ok
= smbXcli_session_is_authenticated(anon_session
->smbXcli
);
6045 torture_assert(tctx
, !ok
, "smbXcli_session_is_authenticated(anon) wrong");
6047 timeout_msec
= transport
->options
.request_timeout
* 1000;
6048 subreq
= smb2cli_tcon_send(tctx
,
6052 anon_session
->smbXcli
,
6056 torture_assert(tctx
, subreq
!= NULL
, "smb2cli_tcon_send");
6058 torture_assert(tctx
,
6059 tevent_req_poll_ntstatus(subreq
, tctx
->ev
, &status
),
6060 "tevent_req_poll_ntstatus");
6062 status
= smb2cli_tcon_recv(subreq
);
6063 TALLOC_FREE(subreq
);
6064 torture_assert_ntstatus_ok(tctx
, status
, "smb2cli_tcon_recv");
6066 ok
= smbXcli_conn_is_connected(transport
->conn
);
6067 torture_assert(tctx
, ok
, "smbXcli_conn_is_connected");
6072 static bool test_session_anon_signing2(struct torture_context
*tctx
,
6073 struct smb2_tree
*tree0
)
6075 const char *host
= torture_setting_string(tctx
, "host", NULL
);
6076 const char *share
= "IPC$";
6078 struct smb2_transport
*transport0
= tree0
->session
->transport
;
6079 struct cli_credentials
*anon_creds
= NULL
;
6080 struct smbcli_options options
;
6081 struct smb2_transport
*transport
= NULL
;
6082 struct smb2_session
*anon_session
= NULL
;
6083 struct smb2_session
*anon_session_nosign
= NULL
;
6084 struct smb2_tree
*anon_tree
= NULL
;
6087 struct tevent_req
*subreq
= NULL
;
6088 uint32_t timeout_msec
;
6089 uint8_t wrong_session_key
[16] = { 0x1f, 0x2f, 0x3f, };
6090 uint64_t session_id
;
6092 if (smbXcli_conn_protocol(transport0
->conn
) < PROTOCOL_SMB3_00
) {
6094 "Can't test without SMB3 support");
6097 unc
= talloc_asprintf(tctx
, "\\\\%s\\%s", host
, share
);
6098 torture_assert(tctx
, unc
!= NULL
, "talloc_asprintf");
6100 anon_creds
= cli_credentials_init_anon(tctx
);
6101 torture_assert(tctx
, anon_creds
!= NULL
, "cli_credentials_init_anon");
6102 ok
= cli_credentials_set_smb_signing(anon_creds
,
6103 SMB_SIGNING_REQUIRED
,
6105 torture_assert(tctx
, ok
, "cli_credentials_set_smb_signing");
6106 ok
= cli_credentials_set_smb_ipc_signing(anon_creds
,
6107 SMB_SIGNING_REQUIRED
,
6109 torture_assert(tctx
, ok
, "cli_credentials_set_smb_ipc_signing");
6110 ok
= cli_credentials_set_smb_encryption(anon_creds
,
6113 torture_assert(tctx
, ok
, "cli_credentials_set_smb_encryption");
6115 options
= transport0
->options
;
6116 options
.client_guid
= GUID_random();
6117 options
.only_negprot
= true;
6118 options
.signing
= SMB_SIGNING_REQUIRED
;
6120 status
= smb2_connect(tctx
,
6122 lpcfg_smb_ports(tctx
->lp_ctx
),
6124 lpcfg_resolve_context(tctx
->lp_ctx
),
6129 lpcfg_socket_options(tctx
->lp_ctx
),
6130 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
));
6131 torture_assert_ntstatus_ok(tctx
, status
, "smb2_connect failed");
6132 anon_session
= anon_tree
->session
;
6133 transport
= anon_session
->transport
;
6135 anon_session
->anonymous_session_key
= true;
6136 anon_session
->forced_session_key
= data_blob_const(wrong_session_key
,
6137 ARRAY_SIZE(wrong_session_key
));
6138 smb2cli_session_torture_anonymous_signing(anon_session
->smbXcli
, true);
6139 smb2cli_session_torture_no_signing_disconnect(anon_session
->smbXcli
);
6141 status
= smb2_session_setup_spnego(anon_session
,
6143 0 /* previous_session_id */);
6144 torture_assert_ntstatus_ok(tctx
, status
,
6145 "smb2_session_setup_spnego failed");
6147 ok
= smbXcli_session_is_authenticated(anon_session
->smbXcli
);
6148 torture_assert(tctx
, !ok
, "smbXcli_session_is_authenticated(anon) wrong");
6151 * create a new structure for the same session id,
6152 * but without smb2.should_sign set.
6154 session_id
= smb2cli_session_current_id(anon_session
->smbXcli
);
6155 anon_session_nosign
= smb2_session_init(transport
,
6156 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
),
6158 torture_assert(tctx
, anon_session_nosign
!= NULL
, "smb2_session_init(anon_nosign)");
6159 smb2cli_session_set_id_and_flags(anon_session_nosign
->smbXcli
, session_id
, 0);
6160 smb2cli_session_torture_no_signing_disconnect(anon_session_nosign
->smbXcli
);
6162 timeout_msec
= transport
->options
.request_timeout
* 1000;
6163 subreq
= smb2cli_tcon_send(tctx
,
6167 anon_session
->smbXcli
,
6171 torture_assert(tctx
, subreq
!= NULL
, "smb2cli_tcon_send");
6173 torture_assert(tctx
,
6174 tevent_req_poll_ntstatus(subreq
, tctx
->ev
, &status
),
6175 "tevent_req_poll_ntstatus");
6177 status
= smb2cli_tcon_recv(subreq
);
6178 TALLOC_FREE(subreq
);
6179 torture_assert_ntstatus_equal(tctx
, status
,
6180 NT_STATUS_ACCESS_DENIED
,
6181 "smb2cli_tcon_recv");
6183 ok
= smbXcli_conn_is_connected(transport
->conn
);
6184 torture_assert(tctx
, ok
, "smbXcli_conn_is_connected");
6186 subreq
= smb2cli_tcon_send(tctx
,
6190 anon_session_nosign
->smbXcli
,
6194 torture_assert(tctx
, subreq
!= NULL
, "smb2cli_tcon_send");
6196 torture_assert(tctx
,
6197 tevent_req_poll_ntstatus(subreq
, tctx
->ev
, &status
),
6198 "tevent_req_poll_ntstatus");
6200 status
= smb2cli_tcon_recv(subreq
);
6201 TALLOC_FREE(subreq
);
6202 torture_assert_ntstatus_ok(tctx
, status
, "smb2cli_tcon_recv");
6204 ok
= smbXcli_conn_is_connected(transport
->conn
);
6205 torture_assert(tctx
, ok
, "smbXcli_conn_is_connected");
6210 struct torture_suite
*torture_smb2_session_init(TALLOC_CTX
*ctx
)
6212 struct torture_suite
*suite
=
6213 torture_suite_create(ctx
, "session");
6215 torture_suite_add_1smb2_test(suite
, "reconnect1", test_session_reconnect1
);
6216 torture_suite_add_1smb2_test(suite
, "reconnect2", test_session_reconnect2
);
6217 torture_suite_add_1smb2_test(suite
, "reauth1", test_session_reauth1
);
6218 torture_suite_add_1smb2_test(suite
, "reauth2", test_session_reauth2
);
6219 torture_suite_add_1smb2_test(suite
, "reauth3", test_session_reauth3
);
6220 torture_suite_add_1smb2_test(suite
, "reauth4", test_session_reauth4
);
6221 torture_suite_add_1smb2_test(suite
, "reauth5", test_session_reauth5
);
6222 torture_suite_add_1smb2_test(suite
, "reauth6", test_session_reauth6
);
6223 torture_suite_add_simple_test(suite
, "expire1n", test_session_expire1n
);
6224 torture_suite_add_simple_test(suite
, "expire1s", test_session_expire1s
);
6225 torture_suite_add_simple_test(suite
, "expire1e", test_session_expire1e
);
6226 torture_suite_add_simple_test(suite
, "expire2s", test_session_expire2s
);
6227 torture_suite_add_simple_test(suite
, "expire2e", test_session_expire2e
);
6228 torture_suite_add_simple_test(suite
, "expire_disconnect",
6229 test_session_expire_disconnect
);
6230 torture_suite_add_1smb2_test(suite
, "bind1", test_session_bind1
);
6231 torture_suite_add_1smb2_test(suite
, "bind2", test_session_bind2
);
6232 torture_suite_add_1smb2_test(suite
, "bind_invalid_auth", test_session_bind_invalid_auth
);
6233 torture_suite_add_1smb2_test(suite
, "bind_different_user", test_session_bind_different_user
);
6234 torture_suite_add_1smb2_test(suite
, "bind_negative_smb202", test_session_bind_negative_smb202
);
6235 torture_suite_add_1smb2_test(suite
, "bind_negative_smb210s", test_session_bind_negative_smb210s
);
6236 torture_suite_add_1smb2_test(suite
, "bind_negative_smb210d", test_session_bind_negative_smb210d
);
6237 torture_suite_add_1smb2_test(suite
, "bind_negative_smb2to3s", test_session_bind_negative_smb2to3s
);
6238 torture_suite_add_1smb2_test(suite
, "bind_negative_smb2to3d", test_session_bind_negative_smb2to3d
);
6239 torture_suite_add_1smb2_test(suite
, "bind_negative_smb3to2s", test_session_bind_negative_smb3to2s
);
6240 torture_suite_add_1smb2_test(suite
, "bind_negative_smb3to2d", test_session_bind_negative_smb3to2d
);
6241 torture_suite_add_1smb2_test(suite
, "bind_negative_smb3to3s", test_session_bind_negative_smb3to3s
);
6242 torture_suite_add_1smb2_test(suite
, "bind_negative_smb3to3d", test_session_bind_negative_smb3to3d
);
6243 torture_suite_add_1smb2_test(suite
, "bind_negative_smb3encGtoCs", test_session_bind_negative_smb3encGtoCs
);
6244 torture_suite_add_1smb2_test(suite
, "bind_negative_smb3encGtoCd", test_session_bind_negative_smb3encGtoCd
);
6245 torture_suite_add_1smb2_test(suite
, "bind_negative_smb3signCtoHs", test_session_bind_negative_smb3signCtoHs
);
6246 torture_suite_add_1smb2_test(suite
, "bind_negative_smb3signCtoHd", test_session_bind_negative_smb3signCtoHd
);
6247 torture_suite_add_1smb2_test(suite
, "bind_negative_smb3signCtoGs", test_session_bind_negative_smb3signCtoGs
);
6248 torture_suite_add_1smb2_test(suite
, "bind_negative_smb3signCtoGd", test_session_bind_negative_smb3signCtoGd
);
6249 torture_suite_add_1smb2_test(suite
, "bind_negative_smb3signHtoCs", test_session_bind_negative_smb3signHtoCs
);
6250 torture_suite_add_1smb2_test(suite
, "bind_negative_smb3signHtoCd", test_session_bind_negative_smb3signHtoCd
);
6251 torture_suite_add_1smb2_test(suite
, "bind_negative_smb3signHtoGs", test_session_bind_negative_smb3signHtoGs
);
6252 torture_suite_add_1smb2_test(suite
, "bind_negative_smb3signHtoGd", test_session_bind_negative_smb3signHtoGd
);
6253 torture_suite_add_1smb2_test(suite
, "bind_negative_smb3signGtoCs", test_session_bind_negative_smb3signGtoCs
);
6254 torture_suite_add_1smb2_test(suite
, "bind_negative_smb3signGtoCd", test_session_bind_negative_smb3signGtoCd
);
6255 torture_suite_add_1smb2_test(suite
, "bind_negative_smb3signGtoHs", test_session_bind_negative_smb3signGtoHs
);
6256 torture_suite_add_1smb2_test(suite
, "bind_negative_smb3signGtoHd", test_session_bind_negative_smb3signGtoHd
);
6257 torture_suite_add_1smb2_test(suite
, "bind_negative_smb3sneGtoCs", test_session_bind_negative_smb3sneGtoCs
);
6258 torture_suite_add_1smb2_test(suite
, "bind_negative_smb3sneGtoCd", test_session_bind_negative_smb3sneGtoCd
);
6259 torture_suite_add_1smb2_test(suite
, "bind_negative_smb3sneGtoHs", test_session_bind_negative_smb3sneGtoHs
);
6260 torture_suite_add_1smb2_test(suite
, "bind_negative_smb3sneGtoHd", test_session_bind_negative_smb3sneGtoHd
);
6261 torture_suite_add_1smb2_test(suite
, "bind_negative_smb3sneCtoGs", test_session_bind_negative_smb3sneCtoGs
);
6262 torture_suite_add_1smb2_test(suite
, "bind_negative_smb3sneCtoGd", test_session_bind_negative_smb3sneCtoGd
);
6263 torture_suite_add_1smb2_test(suite
, "bind_negative_smb3sneHtoGs", test_session_bind_negative_smb3sneHtoGs
);
6264 torture_suite_add_1smb2_test(suite
, "bind_negative_smb3sneHtoGd", test_session_bind_negative_smb3sneHtoGd
);
6265 torture_suite_add_1smb2_test(suite
, "bind_negative_smb3signC30toGs", test_session_bind_negative_smb3signC30toGs
);
6266 torture_suite_add_1smb2_test(suite
, "bind_negative_smb3signC30toGd", test_session_bind_negative_smb3signC30toGd
);
6267 torture_suite_add_1smb2_test(suite
, "bind_negative_smb3signH2XtoGs", test_session_bind_negative_smb3signH2XtoGs
);
6268 torture_suite_add_1smb2_test(suite
, "bind_negative_smb3signH2XtoGd", test_session_bind_negative_smb3signH2XtoGd
);
6269 torture_suite_add_1smb2_test(suite
, "bind_negative_smb3signGtoC30s", test_session_bind_negative_smb3signGtoC30s
);
6270 torture_suite_add_1smb2_test(suite
, "bind_negative_smb3signGtoC30d", test_session_bind_negative_smb3signGtoC30d
);
6271 torture_suite_add_1smb2_test(suite
, "bind_negative_smb3signGtoH2Xs", test_session_bind_negative_smb3signGtoH2Xs
);
6272 torture_suite_add_1smb2_test(suite
, "bind_negative_smb3signGtoH2Xd", test_session_bind_negative_smb3signGtoH2Xd
);
6273 torture_suite_add_1smb2_test(suite
, "two_logoff", test_session_two_logoff
);
6274 torture_suite_add_1smb2_test(suite
, "signing-hmac-sha-256", test_session_signing_hmac_sha_256
);
6275 torture_suite_add_1smb2_test(suite
, "signing-aes-128-cmac", test_session_signing_aes_128_cmac
);
6276 torture_suite_add_1smb2_test(suite
, "signing-aes-128-gmac", test_session_signing_aes_128_gmac
);
6277 torture_suite_add_1smb2_test(suite
, "encryption-aes-128-ccm", test_session_encryption_aes_128_ccm
);
6278 torture_suite_add_1smb2_test(suite
, "encryption-aes-128-gcm", test_session_encryption_aes_128_gcm
);
6279 torture_suite_add_1smb2_test(suite
, "encryption-aes-256-ccm", test_session_encryption_aes_256_ccm
);
6280 torture_suite_add_1smb2_test(suite
, "encryption-aes-256-gcm", test_session_encryption_aes_256_gcm
);
6281 torture_suite_add_1smb2_test(suite
, "ntlmssp_bug14932", test_session_ntlmssp_bug14932
);
6282 torture_suite_add_1smb2_test(suite
, "anon-encryption1", test_session_anon_encryption1
);
6283 torture_suite_add_1smb2_test(suite
, "anon-encryption2", test_session_anon_encryption2
);
6284 torture_suite_add_1smb2_test(suite
, "anon-encryption3", test_session_anon_encryption3
);
6285 torture_suite_add_1smb2_test(suite
, "anon-signing1", test_session_anon_signing1
);
6286 torture_suite_add_1smb2_test(suite
, "anon-signing2", test_session_anon_signing2
);
6288 suite
->description
= talloc_strdup(suite
, "SMB2-SESSION tests");
6293 static bool test_session_require_sign_bug15397(struct torture_context
*tctx
,
6294 struct smb2_tree
*_tree
)
6296 const char *host
= torture_setting_string(tctx
, "host", NULL
);
6297 const char *share
= torture_setting_string(tctx
, "share", NULL
);
6298 struct cli_credentials
*_creds
= samba_cmdline_get_creds();
6299 struct cli_credentials
*creds
= NULL
;
6300 struct smbcli_options options
;
6301 struct smb2_tree
*tree
= NULL
;
6302 uint8_t security_mode
;
6307 * Setup our own connection so we can control the signing flags
6310 creds
= cli_credentials_shallow_copy(tctx
, _creds
);
6311 torture_assert(tctx
, creds
!= NULL
, "cli_credentials_shallow_copy");
6313 options
= _tree
->session
->transport
->options
;
6314 options
.client_guid
= GUID_random();
6315 options
.signing
= SMB_SIGNING_IF_REQUIRED
;
6317 status
= smb2_connect(tctx
,
6319 lpcfg_smb_ports(tctx
->lp_ctx
),
6321 lpcfg_resolve_context(tctx
->lp_ctx
),
6326 lpcfg_socket_options(tctx
->lp_ctx
),
6327 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
));
6328 torture_assert_ntstatus_ok_goto(tctx
, status
, ok
, done
,
6329 "smb2_connect failed");
6331 security_mode
= smb2cli_session_security_mode(tree
->session
->smbXcli
);
6333 torture_assert_int_equal_goto(
6336 SMB2_NEGOTIATE_SIGNING_REQUIRED
| SMB2_NEGOTIATE_SIGNING_ENABLED
,
6339 "Signing not required");
6345 struct torture_suite
*torture_smb2_session_req_sign_init(TALLOC_CTX
*ctx
)
6347 struct torture_suite
*suite
=
6348 torture_suite_create(ctx
, "session-require-signing");
6350 torture_suite_add_1smb2_test(suite
, "bug15397",
6351 test_session_require_sign_bug15397
);
6353 suite
->description
= talloc_strdup(suite
, "SMB2-SESSION require signing tests");