ctdb-scripts: Support storing statd-callout state in cluster filesystem
[samba4-gss.git] / source4 / torture / smb2 / session.c
blobecaac76e6c3bfee4f1408e2d4b579ca3c2afd7dc
1 /*
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/>.
22 #include "includes.h"
23 #include "libcli/smb2/smb2.h"
24 #include "libcli/smb2/smb2_calls.h"
25 #include "torture/torture.h"
26 #include "torture/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
44 #define texpand(x) #x
45 #define GENSEC_GSSAPI_REQUESTED_LIFETIME(x) \
46 "gensec_gssapi:requested_life_time=" texpand(x)
48 #define CHECK_CREATED(tctx, __io, __created, __attribute) \
49 do { \
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, \
56 (__attribute), \
57 "out.file_attr incorrect"); \
58 torture_assert_int_equal(tctx, (__io)->out.reserved2, 0, \
59 "out.reserverd2 incorrect"); \
60 } while(0)
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) { \
65 break; \
66 } \
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(&current, endtime);
75 remaining_secs = remaining_secs < 1.0 ? 1.0 : remaining_secs;
76 torture_comment(
77 tctx,
78 "sleep for %2.f second(s) that the krb5 ticket expires",
79 remaining_secs);
80 smb_msleep((int)(remaining_secs * 1000));
83 /**
84 * basic test for doing a session reconnect
86 bool test_session_reconnect1(struct torture_context *tctx, struct smb2_tree *tree)
88 NTSTATUS status;
89 TALLOC_CTX *mem_ctx = talloc_new(tctx);
90 char fname[256];
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;
97 bool ret = true;
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;
115 h1 = &_h1;
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),
126 ret, done,
127 "session reconnect failed\n");
129 /* try to access the file via the old handle */
131 ZERO_STRUCT(qfinfo);
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");
139 h1 = NULL;
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;
154 h2 = &_h2;
156 done:
157 if (h1 != NULL) {
158 smb2_util_close(tree, *h1);
160 if (h2 != NULL) {
161 smb2_util_close(tree2, *h2);
164 if (tree2 != NULL) {
165 smb2_util_unlink(tree2, fname);
167 smb2_util_unlink(tree, fname);
169 talloc_free(tree);
170 talloc_free(tree2);
172 talloc_free(mem_ctx);
174 return ret;
178 * basic test for doing a session reconnect on one connection
180 bool test_session_reconnect2(struct torture_context *tctx, struct smb2_tree *tree)
182 NTSTATUS status;
183 TALLOC_CTX *mem_ctx = talloc_new(tctx);
184 char fname[256];
185 struct smb2_handle _h1;
186 struct smb2_handle *h1 = NULL;
187 struct smb2_create io1;
188 uint64_t previous_session_id;
189 bool ret = true;
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;
208 h1 = &_h1;
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 */
223 ZERO_STRUCT(qfinfo);
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");
231 h1 = NULL;
233 done:
234 if (h1 != NULL) {
235 smb2_util_close(tree, *h1);
238 talloc_free(tree);
239 talloc_free(session2);
241 talloc_free(mem_ctx);
243 return ret;
246 bool test_session_reauth1(struct torture_context *tctx, struct smb2_tree *tree)
248 NTSTATUS status;
249 TALLOC_CTX *mem_ctx = talloc_new(tctx);
250 char fname[256];
251 struct smb2_handle _h1;
252 struct smb2_handle *h1 = NULL;
253 struct smb2_create io1;
254 bool ret = true;
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;
271 h1 = &_h1;
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 */
285 ZERO_STRUCT(qfinfo);
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 */
300 ZERO_STRUCT(qfinfo);
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");
307 done:
308 if (h1 != NULL) {
309 smb2_util_close(tree, *h1);
312 smb2_util_unlink(tree, fname);
314 talloc_free(tree);
316 talloc_free(mem_ctx);
318 return ret;
321 bool test_session_reauth2(struct torture_context *tctx, struct smb2_tree *tree)
323 NTSTATUS status;
324 TALLOC_CTX *mem_ctx = talloc_new(tctx);
325 char fname[256];
326 struct smb2_handle _h1;
327 struct smb2_handle *h1 = NULL;
328 struct smb2_create io1;
329 bool ret = true;
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;
347 h1 = &_h1;
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,
359 anon_creds,
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 */
366 ZERO_STRUCT(qfinfo);
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 */
383 ZERO_STRUCT(qfinfo);
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");
390 done:
391 if (h1 != NULL) {
392 smb2_util_close(tree, *h1);
395 smb2_util_unlink(tree, fname);
397 talloc_free(tree);
399 talloc_free(mem_ctx);
401 return ret;
405 * test getting security descriptor after reauth
407 bool test_session_reauth3(struct torture_context *tctx, struct smb2_tree *tree)
409 NTSTATUS status;
410 TALLOC_CTX *mem_ctx = talloc_new(tctx);
411 char fname[256];
412 struct smb2_handle _h1;
413 struct smb2_handle *h1 = NULL;
414 struct smb2_create io1;
415 bool ret = true;
416 union smb_fileinfo qfinfo;
417 struct cli_credentials *anon_creds = NULL;
418 uint32_t secinfo_flags = SECINFO_OWNER
419 | SECINFO_GROUP
420 | SECINFO_DACL
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;
438 h1 = &_h1;
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 */
446 ZERO_STRUCT(qfinfo);
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,
462 anon_creds,
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 */
469 ZERO_STRUCT(qfinfo);
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 */
489 ZERO_STRUCT(qfinfo);
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");
499 done:
500 if (h1 != NULL) {
501 smb2_util_close(tree, *h1);
504 smb2_util_unlink(tree, fname);
506 talloc_free(tree);
508 talloc_free(mem_ctx);
510 return ret;
514 * test setting security descriptor after reauth.
516 bool test_session_reauth4(struct torture_context *tctx, struct smb2_tree *tree)
518 NTSTATUS status;
519 TALLOC_CTX *mem_ctx = talloc_new(tctx);
520 char fname[256];
521 struct smb2_handle _h1;
522 struct smb2_handle *h1 = NULL;
523 struct smb2_create io1;
524 bool ret = true;
525 union smb_fileinfo qfinfo;
526 union smb_setfileinfo sfinfo;
527 struct cli_credentials *anon_creds = NULL;
528 uint32_t secinfo_flags = SECINFO_OWNER
529 | SECINFO_GROUP
530 | SECINFO_DACL
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;
551 h1 = &_h1;
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 */
559 ZERO_STRUCT(qfinfo);
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,
577 anon_creds,
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);
586 ZERO_STRUCT(ace);
587 ace.type = SEC_ACE_TYPE_ACCESS_ALLOWED;
588 ace.flags = 0;
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");
596 ZERO_STRUCT(sfinfo);
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 */
616 ZERO_STRUCT(qfinfo);
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");
626 ret = true;
628 done:
629 if (h1 != NULL) {
630 smb2_util_close(tree, *h1);
633 smb2_util_unlink(tree, fname);
635 talloc_free(tree);
637 talloc_free(mem_ctx);
639 return ret;
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)
648 NTSTATUS status;
649 TALLOC_CTX *mem_ctx = talloc_new(tctx);
650 char dname[128];
651 char fname[256];
652 char fname2[256];
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;
658 bool ret = true;
659 bool ok;
660 union smb_fileinfo qfinfo;
661 union smb_setfileinfo sfinfo;
662 struct cli_credentials *anon_creds = NULL;
663 uint32_t secinfo_flags = SECINFO_OWNER
664 | SECINFO_GROUP
665 | SECINFO_DACL
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");
684 dh1 = &_dh1;
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;
694 h1 = &_h1;
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 */
702 ZERO_STRUCT(qfinfo);
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,
720 anon_creds,
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");
734 ZERO_STRUCT(sfinfo);
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);
758 ZERO_STRUCT(ace);
759 ace.type = SEC_ACE_TYPE_ACCESS_ALLOWED;
760 ace.flags = 0;
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");
768 ZERO_STRUCT(sfinfo);
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 */
780 ZERO_STRUCT(qfinfo);
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,
796 anon_creds,
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 */
803 ZERO_STRUCT(sfinfo);
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 */
817 ZERO_STRUCT(qfinfo);
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;
829 ZERO_STRUCT(ace);
830 ace.type = SEC_ACE_TYPE_ACCESS_ALLOWED;
831 ace.flags = 0;
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");
839 ZERO_STRUCT(sfinfo);
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");
850 ZERO_STRUCT(qfinfo);
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");
863 dh1 = NULL;
865 /* try to rename the file: still fails */
867 ZERO_STRUCT(sfinfo);
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 */
889 ZERO_STRUCT(sfinfo);
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");
904 ZERO_STRUCT(io1);
906 smb2_generic_create_share(&io1,
907 NULL /* lease */, false /* dir */,
908 fname,
909 NTCREATEX_DISP_OPEN,
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");
920 ZERO_STRUCT(io1);
922 smb2_generic_create_share(&io1,
923 NULL /* lease */, false /* dir */,
924 fname2,
925 NTCREATEX_DISP_OPEN,
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;
934 h1 = &_h1;
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 */
942 ZERO_STRUCT(qfinfo);
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");
952 done:
953 if (dh1 != NULL) {
954 smb2_util_close(tree, *dh1);
956 if (h1 != NULL) {
957 smb2_util_close(tree, *h1);
960 smb2_deltree(tree, dname);
962 talloc_free(tree);
964 talloc_free(mem_ctx);
966 return ret;
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)
976 NTSTATUS status;
977 TALLOC_CTX *mem_ctx = talloc_new(tctx);
978 char fname[256];
979 struct smb2_handle _h1;
980 struct smb2_handle *h1 = NULL;
981 struct smb2_create io1;
982 bool ret = true;
983 char *corrupted_password;
984 struct cli_credentials *broken_creds;
985 bool ok;
986 bool encrypted;
987 NTSTATUS expected;
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) {
993 torture_skip(tctx,
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;
1014 h1 = &_h1;
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),
1030 "corrupt");
1031 torture_assert(tctx, (corrupted_password != NULL), "talloc error");
1033 ok = cli_credentials_set_password(broken_creds, corrupted_password,
1034 CRED_SPECIFIED);
1035 torture_assert(tctx, ok, "cli_credentials_set_password not ok");
1037 status = smb2_session_setup_spnego(tree->session,
1038 broken_creds,
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
1050 if (encrypted) {
1051 expected = NT_STATUS_CONNECTION_DISCONNECTED;
1052 } else {
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");
1065 done:
1066 if (h1 != NULL) {
1067 smb2_util_close(tree, *h1);
1070 smb2_util_unlink(tree, fname);
1072 talloc_free(tree);
1074 talloc_free(mem_ctx);
1076 return ret;
1080 static bool test_session_expire1i(struct torture_context *tctx,
1081 bool force_signing,
1082 bool force_encryption)
1084 NTSTATUS status;
1085 bool ret = false;
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;
1092 char fname[256];
1093 struct smb2_handle _h1;
1094 struct smb2_handle *h1 = NULL;
1095 struct smb2_create io1;
1096 union smb_fileinfo qfinfo;
1097 size_t i;
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!");
1106 torture_skip(tctx,
1107 "smb2.session.expire1 requires "
1108 "--use-kerberos=required!");
1111 torture_assert_int_equal(tctx,
1112 use_kerberos,
1113 CRED_USE_KERBEROS_REQUIRED,
1114 "please use --use-kerberos=required");
1116 cli_credentials_invalidate_ccache(credentials, CRED_SPECIFIED);
1118 lpcfg_set_option(
1119 tctx->lp_ctx,
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,
1128 host,
1129 lpcfg_smb_ports(tctx->lp_ctx),
1130 share,
1131 lpcfg_resolve_context(tctx->lp_ctx),
1132 credentials,
1133 &tree,
1134 tctx->ev,
1135 &options,
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;
1169 h1 = &_h1;
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__,
1191 nt_errstr(status));
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__,
1204 nt_errstr(status));
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,
1224 credentials,
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,
1232 500 * 1000);
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(&current, &endtime);
1244 remaining_secs = remaining_secs < 0.0 ? remaining_secs * -1.0
1245 : remaining_secs;
1246 torture_warning(
1247 tctx,
1248 "The ticket already expired %.2f seconds ago. "
1249 "You might want to increase KRB5_TICKET_LIFETIME.",
1250 remaining_secs);
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__,
1263 nt_errstr(status));
1264 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
1265 "smb2_getinfo_file failed");
1267 ret = true;
1268 done:
1269 cli_credentials_invalidate_ccache(credentials, CRED_SPECIFIED);
1271 if (h1 != NULL) {
1272 smb2_util_close(tree, *h1);
1275 talloc_free(tree);
1276 lpcfg_set_option(tctx->lp_ctx, GENSEC_GSSAPI_REQUESTED_LIFETIME(0));
1277 return ret;
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)
1304 NTSTATUS status;
1305 bool ret = false;
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;
1316 uint32_t caps;
1317 char fname[256];
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;
1339 unsigned int count;
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!");
1350 torture_skip(tctx,
1351 "smb2.session.expire1 requires "
1352 "--use-kerberos=required!");
1355 torture_assert_int_equal(tctx,
1356 use_kerberos,
1357 CRED_USE_KERBEROS_REQUIRED,
1358 "please use --use-kerberos=required");
1360 cli_credentials_invalidate_ccache(credentials, CRED_SPECIFIED);
1362 lpcfg_set_option(
1363 tctx->lp_ctx,
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,
1373 host,
1374 lpcfg_smb_ports(tctx->lp_ctx),
1375 share,
1376 lpcfg_resolve_context(tctx->lp_ctx),
1377 credentials,
1378 &tree,
1379 tctx->ev,
1380 &options,
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;
1420 h1 = &_h1;
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");
1441 ZERO_STRUCT(lck);
1442 lck.in.locks = &el;
1443 lck.in.lock_count = 0x0001;
1444 lck.in.lock_sequence = 0x00000000;
1445 lck.in.file.handle = *h1;
1446 ZERO_STRUCT(el);
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");
1456 ZERO_STRUCT(ntf1);
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) {
1466 break;
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");
1496 ZERO_STRUCT(flsh);
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");
1505 ZERO_STRUCT(rd);
1506 rd.in.file.handle = *h1;
1507 rd.in.length = 5;
1508 rd.in.offset = 0;
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");
1523 ZERO_STRUCT(ctl);
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");
1535 ZERO_STRUCT(oack);
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");
1545 ZERO_STRUCT(lack);
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");
1557 ZERO_STRUCT(fnd);
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");
1573 ZERO_STRUCT(cio);
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;
1580 cio.in.fname = "";
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);
1588 ZERO_STRUCT(fnd);
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");
1599 ZERO_STRUCT(cl);
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");
1622 smb2_cancel(req);
1624 torture_comment(tctx, "2nd notify => EXPIRED\n");
1625 ZERO_STRUCT(ntf2);
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,
1652 timeout_msec,
1653 tree2->session->smbXcli,
1654 tree2->smbXcli,
1655 0, /* flags */
1656 unc);
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);
1710 h1 = NULL;
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");
1730 ret = true;
1731 done:
1732 cli_credentials_invalidate_ccache(credentials, CRED_SPECIFIED);
1734 if (h1 != NULL) {
1735 smb2_util_close(tree, *h1);
1738 talloc_free(tree);
1739 lpcfg_set_option(tctx->lp_ctx, GENSEC_GSSAPI_REQUESTED_LIFETIME(0));
1740 return ret;
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)
1757 NTSTATUS status;
1758 bool ret = false;
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;
1765 char fname[256];
1766 struct smb2_handle _h1;
1767 struct smb2_handle *h1 = NULL;
1768 struct smb2_create io1;
1769 union smb_fileinfo qfinfo;
1770 bool connected;
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!");
1778 torture_skip(tctx,
1779 "smb2.session.expire1 requires "
1780 "--use-kerberos=required!");
1783 cli_credentials_invalidate_ccache(credentials, CRED_SPECIFIED);
1785 lpcfg_set_option(
1786 tctx->lp_ctx,
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,
1792 host,
1793 lpcfg_smb_ports(tctx->lp_ctx),
1794 share,
1795 lpcfg_resolve_context(tctx->lp_ctx),
1796 credentials,
1797 &tree,
1798 tctx->ev,
1799 &options,
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;
1829 h1 = &_h1;
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");
1862 ret = true;
1863 done:
1864 cli_credentials_invalidate_ccache(credentials, CRED_SPECIFIED);
1866 if (h1 != NULL) {
1867 smb2_util_close(tree, *h1);
1870 talloc_free(tree);
1871 lpcfg_set_option(tctx->lp_ctx, GENSEC_GSSAPI_REQUESTED_LIFETIME(0));
1872 return ret;
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();
1880 NTSTATUS status;
1881 TALLOC_CTX *mem_ctx = talloc_new(tctx);
1882 char fname[256];
1883 struct smb2_handle _h1;
1884 struct smb2_handle *h1 = NULL;
1885 struct smb2_create io1;
1886 union smb_fileinfo qfinfo;
1887 bool ret = false;
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;
1896 uint32_t caps;
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;
1924 h1 = &_h1;
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,
1931 host,
1932 lpcfg_smb_ports(tctx->lp_ctx),
1933 share,
1934 lpcfg_resolve_context(tctx->lp_ctx),
1935 credentials,
1936 &tree2,
1937 tctx->ev,
1938 &options2,
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),
1952 tree2,
1953 session1_1);
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");
1984 h1 = NULL;
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),
1991 tree1,
1992 session2_2);
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");
2005 ret = true;
2006 done:
2007 talloc_free(tree2);
2008 tree1->session = session1_1;
2010 if (h1 != NULL) {
2011 smb2_util_close(tree1, *h1);
2014 smb2_util_unlink(tree1, fname);
2016 talloc_free(tree1);
2018 talloc_free(mem_ctx);
2020 return ret;
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();
2028 NTSTATUS status;
2029 TALLOC_CTX *mem_ctx = talloc_new(tctx);
2030 char fname1[256];
2031 char fname2[256];
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;
2043 bool ret = false;
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;
2057 uint32_t caps;
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;
2091 h1f1 = &_h1f1;
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,
2098 host,
2099 lpcfg_smb_ports(tctx->lp_ctx),
2100 share,
2101 lpcfg_resolve_context(tctx->lp_ctx),
2102 credentials,
2103 &tree2,
2104 tctx->ev,
2105 &options2,
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;
2126 h2f2 = &_h2f2;
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,
2137 host,
2138 lpcfg_smb_ports(tctx->lp_ctx),
2139 share,
2140 lpcfg_resolve_context(tctx->lp_ctx),
2141 credentials,
2142 &tree3,
2143 tctx->ev,
2144 &options3,
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),
2157 tree1,
2158 session1_1);
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),
2166 tree1,
2167 session1_1);
2168 torture_assert(tctx, session1_3 != NULL, "smb2_session_channel failed");
2170 status = smb2_session_setup_spnego(session1_3,
2171 credentials,
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),
2181 tree2,
2182 session2_2);
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),
2190 tree2,
2191 session2_2);
2192 torture_assert(tctx, session2_3 != NULL, "smb2_session_channel failed");
2194 status = smb2_session_setup_spnego(session2_3,
2195 credentials,
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);
2259 smb_msleep(500);
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);
2280 smb_msleep(500);
2281 h2f2 = NULL;
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;
2288 h1f2 = &_h1f2;
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");
2298 h1f1 = NULL;
2300 ret = true;
2301 done:
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;
2309 if (h1f1 != NULL) {
2310 smb2_util_close(tree1, *h1f1);
2312 if (h1f2 != NULL) {
2313 smb2_util_close(tree1, *h1f2);
2315 if (h2f2 != NULL) {
2316 smb2_util_close(tree2, *h2f2);
2319 smb2_util_unlink(tree1, fname1);
2320 smb2_util_unlink(tree1, fname2);
2322 talloc_free(tree1);
2324 talloc_free(mem_ctx);
2326 return ret;
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);
2338 NTSTATUS status;
2339 TALLOC_CTX *mem_ctx = talloc_new(tctx);
2340 char fname[256];
2341 struct smb2_handle _h1;
2342 struct smb2_handle *h1 = NULL;
2343 struct smb2_create io1;
2344 union smb_fileinfo qfinfo;
2345 bool ret = false;
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;
2355 uint32_t caps;
2356 bool encrypted;
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;
2387 h1 = &_h1;
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,
2394 host,
2395 lpcfg_smb_ports(tctx->lp_ctx),
2396 share,
2397 lpcfg_resolve_context(tctx->lp_ctx),
2398 creds1,
2399 &tree2,
2400 tctx->ev,
2401 &options2,
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),
2415 tree2,
2416 session1_1);
2417 torture_assert(tctx, session1_2 != NULL, "smb2_session_channel failed");
2419 status = smb2_session_setup_spnego(session1_2,
2420 creds1,
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");
2447 h1 = NULL;
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),
2455 tctx);
2456 torture_assert(tctx, session3_1 != NULL, "smb2_session_channel failed");
2458 status = smb2_session_setup_spnego(session3_1,
2459 creds2,
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;
2469 } else {
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),
2479 tree1,
2480 session2_2);
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,
2489 creds2,
2490 0 /* previous_session_id */);
2491 if (creds2_got_ok) {
2493 * attaching with a different user (guest or anonymous) results
2494 * in ACCESS_DENIED.
2496 torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_ACCESS_DENIED, ret, done,
2497 "smb2_session_setup_spnego worked");
2498 } else {
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),
2525 tree1,
2526 session2_2);
2527 torture_assert(tctx, session2_1 != NULL, "smb2_session_channel failed");
2529 status = smb2_session_setup_spnego(session2_1,
2530 creds1,
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
2554 * reauth.
2556 ret = true;
2557 goto done;
2561 * Do a failing reauth the 2nd channel
2563 status = smb2_session_setup_spnego(session1_2,
2564 creds2,
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);
2571 if (encrypted) {
2572 torture_assert_goto(tctx, !smbXcli_conn_is_connected(transport1->conn), ret, done,
2573 "smb2_util_unlink worked");
2574 } else {
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);
2581 if (encrypted) {
2582 torture_assert_goto(tctx, !smbXcli_conn_is_connected(transport2->conn), ret, done,
2583 "smb2_util_unlink worked");
2584 } else {
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);
2590 if (encrypted) {
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");
2595 } else {
2596 torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_OBJECT_NAME_NOT_FOUND, ret, done,
2597 "smb2_util_unlink worked");
2600 ret = true;
2601 done:
2602 talloc_free(tree2);
2603 tree1->session = session1_1;
2605 if (h1 != NULL) {
2606 smb2_util_close(tree1, *h1);
2609 smb2_util_unlink(tree1, fname);
2611 talloc_free(tree1);
2613 talloc_free(mem_ctx);
2615 return ret;
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;
2622 bool ret = false;
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__,
2633 credentials,
2634 invalid_credentials,
2635 false);
2636 return ret;
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);
2645 bool ret = false;
2646 bool bval;
2648 torture_assert(tctx, (credentials2 != NULL), "talloc error");
2649 bval = cli_credentials_is_anonymous(credentials2);
2650 if (bval) {
2651 torture_skip(tctx, "valid user2 credentials are required");
2653 bval = strequal(u1, u2);
2654 if (bval) {
2655 torture_skip(tctx, "different user2 credentials are required");
2658 ret = test_session_bind_auth_mismatch(tctx, tree1, __func__,
2659 credentials1,
2660 credentials2,
2661 true);
2662 return ret;
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);
2674 NTSTATUS status;
2675 bool ret = false;
2676 struct smb2_tree *tree1 = NULL;
2677 struct smb2_session *session1_1 = NULL;
2678 char fname[256];
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,
2691 host,
2692 lpcfg_smb_ports(tctx->lp_ctx),
2693 share,
2694 lpcfg_resolve_context(tctx->lp_ctx),
2695 credentials,
2696 &tree1,
2697 tctx->ev,
2698 options1,
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;
2723 h1 = &_h1;
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,
2730 host,
2731 lpcfg_smb_ports(tctx->lp_ctx),
2732 share,
2733 lpcfg_resolve_context(tctx->lp_ctx),
2734 credentials,
2735 &tree2_0,
2736 tctx->ev,
2737 options2,
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),
2750 tree2_0,
2751 session1_1);
2752 torture_assert(tctx, session1_2 != NULL, "smb2_session_channel failed");
2754 status = smb2_session_setup_spnego(session1_2,
2755 credentials,
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),
2791 tree2_0,
2792 session1_1);
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,
2797 credentials,
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
2805 * session keys.
2807 session1_2 = smb2_session_init(transport2,
2808 lpcfg_gensec_settings(tctx, tctx->lp_ctx),
2809 tree2_0);
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,
2816 credentials,
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),
2835 tree2_0,
2836 session1_1);
2837 torture_assert(tctx, session1_2 != NULL, "smb2_session_channel failed");
2839 status = smb2_session_setup_spnego(session1_2,
2840 credentials,
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");
2854 ret = true;
2855 done:
2856 talloc_free(tree2_0);
2857 if (h1 != NULL) {
2858 smb2_util_close(tree1, *h1);
2860 talloc_free(tree1);
2862 return ret;
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();
2880 bool ret = false;
2881 struct smb2_transport *transport0 = tree0->session->transport;
2882 struct smbcli_options options1;
2883 struct smbcli_options options2;
2884 bool encrypted;
2886 encrypted = smb2cli_tcon_is_encryption_on(tree0->smbXcli);
2887 if (encrypted) {
2888 torture_skip(tctx,
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__,
2900 credentials,
2901 &options1, &options2,
2902 NT_STATUS_REQUEST_NOT_ACCEPTED);
2903 talloc_free(tree0);
2904 return ret;
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();
2910 bool ret = false;
2911 struct smb2_transport *transport0 = tree0->session->transport;
2912 struct smbcli_options options1;
2913 struct smbcli_options options2;
2914 bool encrypted;
2916 encrypted = smb2cli_tcon_is_encryption_on(tree0->smbXcli);
2917 if (encrypted) {
2918 torture_skip(tctx,
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__,
2931 credentials,
2932 &options1, &options2,
2933 NT_STATUS_REQUEST_NOT_ACCEPTED);
2934 talloc_free(tree0);
2935 return ret;
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();
2941 bool ret = false;
2942 struct smb2_transport *transport0 = tree0->session->transport;
2943 struct smbcli_options options1;
2944 struct smbcli_options options2;
2945 bool encrypted;
2947 encrypted = smb2cli_tcon_is_encryption_on(tree0->smbXcli);
2948 if (encrypted) {
2949 torture_skip(tctx,
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__,
2963 credentials,
2964 &options1, &options2,
2965 NT_STATUS_REQUEST_NOT_ACCEPTED);
2966 talloc_free(tree0);
2967 return ret;
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();
2973 bool ret = false;
2974 struct smb2_transport *transport0 = tree0->session->transport;
2975 struct smbcli_options options1;
2976 struct smbcli_options options2;
2977 bool encrypted;
2979 encrypted = smb2cli_tcon_is_encryption_on(tree0->smbXcli);
2980 if (encrypted) {
2981 torture_skip(tctx,
2982 "Can't test SMB 2.10 if encryption is required");
2985 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_00) {
2986 torture_skip(tctx,
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) {
3001 .num_algos = 1,
3002 .algos = {
3003 SMB2_SIGNING_AES128_CMAC,
3007 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
3008 credentials,
3009 &options1, &options2,
3010 NT_STATUS_INVALID_PARAMETER);
3011 talloc_free(tree0);
3012 return ret;
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();
3018 bool ret = false;
3019 struct smb2_transport *transport0 = tree0->session->transport;
3020 struct smbcli_options options1;
3021 struct smbcli_options options2;
3022 bool encrypted;
3024 encrypted = smb2cli_tcon_is_encryption_on(tree0->smbXcli);
3025 if (encrypted) {
3026 torture_skip(tctx,
3027 "Can't test SMB 2.10 if encryption is required");
3030 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_00) {
3031 torture_skip(tctx,
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) {
3047 .num_algos = 1,
3048 .algos = {
3049 SMB2_SIGNING_AES128_CMAC,
3053 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
3054 credentials,
3055 &options1, &options2,
3056 NT_STATUS_INVALID_PARAMETER);
3057 talloc_free(tree0);
3058 return ret;
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();
3064 bool ret = false;
3065 struct smb2_transport *transport0 = tree0->session->transport;
3066 struct smbcli_options options1;
3067 struct smbcli_options options2;
3068 bool encrypted;
3070 encrypted = smb2cli_tcon_is_encryption_on(tree0->smbXcli);
3071 if (encrypted) {
3072 torture_skip(tctx,
3073 "Can't test SMB 2.10 if encryption is required");
3076 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_00) {
3077 torture_skip(tctx,
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) {
3086 .num_algos = 1,
3087 .algos = {
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) {
3098 .num_algos = 1,
3099 .algos = {
3100 SMB2_SIGNING_HMAC_SHA256,
3104 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
3105 credentials,
3106 &options1, &options2,
3107 NT_STATUS_REQUEST_NOT_ACCEPTED);
3108 talloc_free(tree0);
3109 return ret;
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();
3115 bool ret = false;
3116 struct smb2_transport *transport0 = tree0->session->transport;
3117 struct smbcli_options options1;
3118 struct smbcli_options options2;
3119 bool encrypted;
3121 encrypted = smb2cli_tcon_is_encryption_on(tree0->smbXcli);
3122 if (encrypted) {
3123 torture_skip(tctx,
3124 "Can't test SMB 2.10 if encryption is required");
3127 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_00) {
3128 torture_skip(tctx,
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) {
3137 .num_algos = 1,
3138 .algos = {
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) {
3150 .num_algos = 1,
3151 .algos = {
3152 SMB2_SIGNING_HMAC_SHA256,
3156 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
3157 credentials,
3158 &options1, &options2,
3159 NT_STATUS_REQUEST_NOT_ACCEPTED);
3160 talloc_free(tree0);
3161 return ret;
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();
3167 bool ret = false;
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) {
3173 torture_skip(tctx,
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) {
3188 .num_algos = 1,
3189 .algos = {
3190 SMB2_SIGNING_AES128_CMAC,
3194 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
3195 credentials,
3196 &options1, &options2,
3197 NT_STATUS_INVALID_PARAMETER);
3198 talloc_free(tree0);
3199 return ret;
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();
3205 bool ret = false;
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) {
3211 torture_skip(tctx,
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) {
3227 .num_algos = 1,
3228 .algos = {
3229 SMB2_SIGNING_AES128_CMAC,
3233 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
3234 credentials,
3235 &options1, &options2,
3236 NT_STATUS_INVALID_PARAMETER);
3237 talloc_free(tree0);
3238 return ret;
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;
3245 bool ret = false;
3246 struct smb2_transport *transport0 = tree0->session->transport;
3247 struct smbcli_options options1;
3248 struct smbcli_options options2;
3249 bool ok;
3251 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
3252 torture_skip(tctx,
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,
3260 CRED_SPECIFIED);
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) {
3269 .num_algos = 1,
3270 .algos = {
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) {
3279 .num_algos = 1,
3280 .algos = {
3281 SMB2_ENCRYPTION_AES128_CCM,
3285 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
3286 credentials,
3287 &options1, &options2,
3288 NT_STATUS_INVALID_PARAMETER);
3289 talloc_free(tree0);
3290 return ret;
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;
3297 bool ret = false;
3298 struct smb2_transport *transport0 = tree0->session->transport;
3299 struct smbcli_options options1;
3300 struct smbcli_options options2;
3301 bool ok;
3303 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
3304 torture_skip(tctx,
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,
3312 CRED_SPECIFIED);
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) {
3321 .num_algos = 1,
3322 .algos = {
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) {
3332 .num_algos = 1,
3333 .algos = {
3334 SMB2_ENCRYPTION_AES128_CCM,
3338 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
3339 credentials,
3340 &options1, &options2,
3341 NT_STATUS_INVALID_PARAMETER);
3342 talloc_free(tree0);
3343 return ret;
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;
3350 bool ret = false;
3351 struct smb2_transport *transport0 = tree0->session->transport;
3352 struct smbcli_options options1;
3353 struct smbcli_options options2;
3354 bool ok;
3356 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
3357 torture_skip(tctx,
3358 "Can't test without SMB 3.1.1 support");
3361 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
3362 torture_skip(tctx,
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,
3370 CRED_SPECIFIED);
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) {
3379 .num_algos = 1,
3380 .algos = {
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) {
3389 .num_algos = 1,
3390 .algos = {
3391 SMB2_SIGNING_HMAC_SHA256,
3395 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
3396 credentials,
3397 &options1, &options2,
3398 NT_STATUS_OK);
3399 talloc_free(tree0);
3400 return ret;
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;
3407 bool ret = false;
3408 struct smb2_transport *transport0 = tree0->session->transport;
3409 struct smbcli_options options1;
3410 struct smbcli_options options2;
3411 bool ok;
3413 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
3414 torture_skip(tctx,
3415 "Can't test without SMB 3.1.1 support");
3418 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
3419 torture_skip(tctx,
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,
3427 CRED_SPECIFIED);
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) {
3436 .num_algos = 1,
3437 .algos = {
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) {
3447 .num_algos = 1,
3448 .algos = {
3449 SMB2_SIGNING_HMAC_SHA256,
3453 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
3454 credentials,
3455 &options1, &options2,
3456 NT_STATUS_OK);
3457 talloc_free(tree0);
3458 return ret;
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;
3465 bool ret = false;
3466 struct smb2_transport *transport0 = tree0->session->transport;
3467 struct smbcli_options options1;
3468 struct smbcli_options options2;
3469 bool ok;
3471 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
3472 torture_skip(tctx,
3473 "Can't test without SMB 3.1.1 support");
3476 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
3477 torture_skip(tctx,
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,
3485 CRED_SPECIFIED);
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) {
3494 .num_algos = 1,
3495 .algos = {
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) {
3504 .num_algos = 1,
3505 .algos = {
3506 SMB2_SIGNING_AES128_CMAC,
3510 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
3511 credentials,
3512 &options1, &options2,
3513 NT_STATUS_OK);
3514 talloc_free(tree0);
3515 return ret;
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;
3522 bool ret = false;
3523 struct smb2_transport *transport0 = tree0->session->transport;
3524 struct smbcli_options options1;
3525 struct smbcli_options options2;
3526 bool ok;
3528 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
3529 torture_skip(tctx,
3530 "Can't test without SMB 3.1.1 support");
3533 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
3534 torture_skip(tctx,
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,
3542 CRED_SPECIFIED);
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) {
3551 .num_algos = 1,
3552 .algos = {
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) {
3562 .num_algos = 1,
3563 .algos = {
3564 SMB2_SIGNING_AES128_CMAC,
3568 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
3569 credentials,
3570 &options1, &options2,
3571 NT_STATUS_OK);
3572 talloc_free(tree0);
3573 return ret;
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;
3580 bool ret = false;
3581 struct smb2_transport *transport0 = tree0->session->transport;
3582 struct smbcli_options options1;
3583 struct smbcli_options options2;
3584 bool ok;
3586 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
3587 torture_skip(tctx,
3588 "Can't test without SMB 3.1.1 support");
3591 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
3592 torture_skip(tctx,
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,
3600 CRED_SPECIFIED);
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) {
3609 .num_algos = 1,
3610 .algos = {
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) {
3619 .num_algos = 1,
3620 .algos = {
3621 SMB2_SIGNING_AES128_GMAC,
3625 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
3626 credentials,
3627 &options1, &options2,
3628 NT_STATUS_NOT_SUPPORTED);
3629 talloc_free(tree0);
3630 return ret;
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;
3637 bool ret = false;
3638 struct smb2_transport *transport0 = tree0->session->transport;
3639 struct smbcli_options options1;
3640 struct smbcli_options options2;
3641 bool ok;
3643 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
3644 torture_skip(tctx,
3645 "Can't test without SMB 3.1.1 support");
3648 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
3649 torture_skip(tctx,
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,
3657 CRED_SPECIFIED);
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) {
3666 .num_algos = 1,
3667 .algos = {
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) {
3677 .num_algos = 1,
3678 .algos = {
3679 SMB2_SIGNING_AES128_GMAC,
3683 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
3684 credentials,
3685 &options1, &options2,
3686 NT_STATUS_NOT_SUPPORTED);
3687 talloc_free(tree0);
3688 return ret;
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;
3695 bool ret = false;
3696 struct smb2_transport *transport0 = tree0->session->transport;
3697 struct smbcli_options options1;
3698 struct smbcli_options options2;
3699 bool ok;
3701 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
3702 torture_skip(tctx,
3703 "Can't test without SMB 3.1.1 support");
3706 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
3707 torture_skip(tctx,
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,
3715 CRED_SPECIFIED);
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) {
3724 .num_algos = 1,
3725 .algos = {
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) {
3734 .num_algos = 1,
3735 .algos = {
3736 SMB2_SIGNING_AES128_GMAC,
3740 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
3741 credentials,
3742 &options1, &options2,
3743 NT_STATUS_NOT_SUPPORTED);
3744 talloc_free(tree0);
3745 return ret;
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;
3752 bool ret = false;
3753 struct smb2_transport *transport0 = tree0->session->transport;
3754 struct smbcli_options options1;
3755 struct smbcli_options options2;
3756 bool ok;
3758 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
3759 torture_skip(tctx,
3760 "Can't test without SMB 3.1.1 support");
3763 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
3764 torture_skip(tctx,
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,
3772 CRED_SPECIFIED);
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) {
3781 .num_algos = 1,
3782 .algos = {
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) {
3792 .num_algos = 1,
3793 .algos = {
3794 SMB2_SIGNING_AES128_GMAC,
3798 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
3799 credentials,
3800 &options1, &options2,
3801 NT_STATUS_NOT_SUPPORTED);
3802 talloc_free(tree0);
3803 return ret;
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;
3810 bool ret = false;
3811 struct smb2_transport *transport0 = tree0->session->transport;
3812 struct smbcli_options options1;
3813 struct smbcli_options options2;
3814 bool ok;
3816 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
3817 torture_skip(tctx,
3818 "Can't test without SMB 3.1.1 support");
3821 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
3822 torture_skip(tctx,
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,
3830 CRED_SPECIFIED);
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) {
3839 .num_algos = 1,
3840 .algos = {
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) {
3849 .num_algos = 1,
3850 .algos = {
3851 SMB2_SIGNING_AES128_CMAC,
3855 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
3856 credentials,
3857 &options1, &options2,
3858 NT_STATUS_REQUEST_OUT_OF_SEQUENCE);
3859 talloc_free(tree0);
3860 return ret;
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;
3867 bool ret = false;
3868 struct smb2_transport *transport0 = tree0->session->transport;
3869 struct smbcli_options options1;
3870 struct smbcli_options options2;
3871 bool ok;
3873 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
3874 torture_skip(tctx,
3875 "Can't test without SMB 3.1.1 support");
3878 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
3879 torture_skip(tctx,
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,
3887 CRED_SPECIFIED);
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) {
3896 .num_algos = 1,
3897 .algos = {
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) {
3907 .num_algos = 1,
3908 .algos = {
3909 SMB2_SIGNING_AES128_CMAC,
3913 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
3914 credentials,
3915 &options1, &options2,
3916 NT_STATUS_REQUEST_OUT_OF_SEQUENCE);
3917 talloc_free(tree0);
3918 return ret;
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;
3925 bool ret = false;
3926 struct smb2_transport *transport0 = tree0->session->transport;
3927 struct smbcli_options options1;
3928 struct smbcli_options options2;
3929 bool ok;
3931 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
3932 torture_skip(tctx,
3933 "Can't test without SMB 3.1.1 support");
3936 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
3937 torture_skip(tctx,
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,
3945 CRED_SPECIFIED);
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) {
3954 .num_algos = 1,
3955 .algos = {
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) {
3964 .num_algos = 1,
3965 .algos = {
3966 SMB2_SIGNING_HMAC_SHA256,
3970 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
3971 credentials,
3972 &options1, &options2,
3973 NT_STATUS_REQUEST_OUT_OF_SEQUENCE);
3974 talloc_free(tree0);
3975 return ret;
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;
3982 bool ret = false;
3983 struct smb2_transport *transport0 = tree0->session->transport;
3984 struct smbcli_options options1;
3985 struct smbcli_options options2;
3986 bool ok;
3988 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
3989 torture_skip(tctx,
3990 "Can't test without SMB 3.1.1 support");
3993 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
3994 torture_skip(tctx,
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,
4002 CRED_SPECIFIED);
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) {
4011 .num_algos = 1,
4012 .algos = {
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) {
4022 .num_algos = 1,
4023 .algos = {
4024 SMB2_SIGNING_HMAC_SHA256,
4028 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
4029 credentials,
4030 &options1, &options2,
4031 NT_STATUS_REQUEST_OUT_OF_SEQUENCE);
4032 talloc_free(tree0);
4033 return ret;
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;
4040 bool ret = false;
4041 struct smb2_transport *transport0 = tree0->session->transport;
4042 struct smbcli_options options1;
4043 struct smbcli_options options2;
4044 bool ok;
4046 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
4047 torture_skip(tctx,
4048 "Can't test without SMB 3.1.1 support");
4051 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
4052 torture_skip(tctx,
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,
4060 CRED_SPECIFIED);
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) {
4069 .num_algos = 1,
4070 .algos = {
4071 SMB2_SIGNING_AES128_GMAC,
4074 options1.smb3_capabilities.encryption = (struct smb3_encryption_capabilities) {
4075 .num_algos = 1,
4076 .algos = {
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) {
4085 .num_algos = 1,
4086 .algos = {
4087 SMB2_SIGNING_AES128_CMAC,
4090 options2.smb3_capabilities.encryption = (struct smb3_encryption_capabilities) {
4091 .num_algos = 1,
4092 .algos = {
4093 SMB2_ENCRYPTION_AES128_CCM,
4097 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
4098 credentials,
4099 &options1, &options2,
4100 NT_STATUS_REQUEST_OUT_OF_SEQUENCE);
4101 talloc_free(tree0);
4102 return ret;
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;
4109 bool ret = false;
4110 struct smb2_transport *transport0 = tree0->session->transport;
4111 struct smbcli_options options1;
4112 struct smbcli_options options2;
4113 bool ok;
4115 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
4116 torture_skip(tctx,
4117 "Can't test without SMB 3.1.1 support");
4120 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
4121 torture_skip(tctx,
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,
4129 CRED_SPECIFIED);
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) {
4138 .num_algos = 1,
4139 .algos = {
4140 SMB2_SIGNING_AES128_GMAC,
4143 options1.smb3_capabilities.encryption = (struct smb3_encryption_capabilities) {
4144 .num_algos = 1,
4145 .algos = {
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) {
4155 .num_algos = 1,
4156 .algos = {
4157 SMB2_SIGNING_AES128_CMAC,
4160 options2.smb3_capabilities.encryption = (struct smb3_encryption_capabilities) {
4161 .num_algos = 1,
4162 .algos = {
4163 SMB2_ENCRYPTION_AES128_CCM,
4167 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
4168 credentials,
4169 &options1, &options2,
4170 NT_STATUS_REQUEST_OUT_OF_SEQUENCE);
4171 talloc_free(tree0);
4172 return ret;
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;
4179 bool ret = false;
4180 struct smb2_transport *transport0 = tree0->session->transport;
4181 struct smbcli_options options1;
4182 struct smbcli_options options2;
4183 bool ok;
4185 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
4186 torture_skip(tctx,
4187 "Can't test without SMB 3.1.1 support");
4190 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
4191 torture_skip(tctx,
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,
4199 CRED_SPECIFIED);
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) {
4208 .num_algos = 1,
4209 .algos = {
4210 SMB2_SIGNING_AES128_GMAC,
4213 options1.smb3_capabilities.encryption = (struct smb3_encryption_capabilities) {
4214 .num_algos = 1,
4215 .algos = {
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) {
4224 .num_algos = 1,
4225 .algos = {
4226 SMB2_SIGNING_HMAC_SHA256,
4229 options2.smb3_capabilities.encryption = (struct smb3_encryption_capabilities) {
4230 .num_algos = 1,
4231 .algos = {
4232 SMB2_ENCRYPTION_AES128_CCM,
4236 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
4237 credentials,
4238 &options1, &options2,
4239 NT_STATUS_REQUEST_OUT_OF_SEQUENCE);
4240 talloc_free(tree0);
4241 return ret;
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;
4248 bool ret = false;
4249 struct smb2_transport *transport0 = tree0->session->transport;
4250 struct smbcli_options options1;
4251 struct smbcli_options options2;
4252 bool ok;
4254 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
4255 torture_skip(tctx,
4256 "Can't test without SMB 3.1.1 support");
4259 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
4260 torture_skip(tctx,
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,
4268 CRED_SPECIFIED);
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) {
4277 .num_algos = 1,
4278 .algos = {
4279 SMB2_SIGNING_AES128_GMAC,
4282 options1.smb3_capabilities.encryption = (struct smb3_encryption_capabilities) {
4283 .num_algos = 1,
4284 .algos = {
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) {
4294 .num_algos = 1,
4295 .algos = {
4296 SMB2_SIGNING_HMAC_SHA256,
4299 options2.smb3_capabilities.encryption = (struct smb3_encryption_capabilities) {
4300 .num_algos = 1,
4301 .algos = {
4302 SMB2_ENCRYPTION_AES128_CCM,
4306 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
4307 credentials,
4308 &options1, &options2,
4309 NT_STATUS_REQUEST_OUT_OF_SEQUENCE);
4310 talloc_free(tree0);
4311 return ret;
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;
4318 bool ret = false;
4319 struct smb2_transport *transport0 = tree0->session->transport;
4320 struct smbcli_options options1;
4321 struct smbcli_options options2;
4322 bool ok;
4324 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
4325 torture_skip(tctx,
4326 "Can't test without SMB 3.1.1 support");
4329 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
4330 torture_skip(tctx,
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,
4338 CRED_SPECIFIED);
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) {
4347 .num_algos = 1,
4348 .algos = {
4349 SMB2_SIGNING_AES128_CMAC,
4352 options1.smb3_capabilities.encryption = (struct smb3_encryption_capabilities) {
4353 .num_algos = 1,
4354 .algos = {
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) {
4363 .num_algos = 1,
4364 .algos = {
4365 SMB2_SIGNING_AES128_GMAC,
4368 options2.smb3_capabilities.encryption = (struct smb3_encryption_capabilities) {
4369 .num_algos = 1,
4370 .algos = {
4371 SMB2_ENCRYPTION_AES128_GCM,
4375 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
4376 credentials,
4377 &options1, &options2,
4378 NT_STATUS_NOT_SUPPORTED);
4379 talloc_free(tree0);
4380 return ret;
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;
4387 bool ret = false;
4388 struct smb2_transport *transport0 = tree0->session->transport;
4389 struct smbcli_options options1;
4390 struct smbcli_options options2;
4391 bool ok;
4393 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
4394 torture_skip(tctx,
4395 "Can't test without SMB 3.1.1 support");
4398 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
4399 torture_skip(tctx,
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,
4407 CRED_SPECIFIED);
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) {
4416 .num_algos = 1,
4417 .algos = {
4418 SMB2_SIGNING_AES128_CMAC,
4421 options1.smb3_capabilities.encryption = (struct smb3_encryption_capabilities) {
4422 .num_algos = 1,
4423 .algos = {
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) {
4433 .num_algos = 1,
4434 .algos = {
4435 SMB2_SIGNING_AES128_GMAC,
4438 options2.smb3_capabilities.encryption = (struct smb3_encryption_capabilities) {
4439 .num_algos = 1,
4440 .algos = {
4441 SMB2_ENCRYPTION_AES128_GCM,
4445 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
4446 credentials,
4447 &options1, &options2,
4448 NT_STATUS_NOT_SUPPORTED);
4449 talloc_free(tree0);
4450 return ret;
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;
4457 bool ret = false;
4458 struct smb2_transport *transport0 = tree0->session->transport;
4459 struct smbcli_options options1;
4460 struct smbcli_options options2;
4461 bool ok;
4463 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
4464 torture_skip(tctx,
4465 "Can't test without SMB 3.1.1 support");
4468 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
4469 torture_skip(tctx,
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,
4477 CRED_SPECIFIED);
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) {
4486 .num_algos = 1,
4487 .algos = {
4488 SMB2_SIGNING_HMAC_SHA256,
4491 options1.smb3_capabilities.encryption = (struct smb3_encryption_capabilities) {
4492 .num_algos = 1,
4493 .algos = {
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) {
4502 .num_algos = 1,
4503 .algos = {
4504 SMB2_SIGNING_AES128_GMAC,
4507 options2.smb3_capabilities.encryption = (struct smb3_encryption_capabilities) {
4508 .num_algos = 1,
4509 .algos = {
4510 SMB2_ENCRYPTION_AES128_GCM,
4514 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
4515 credentials,
4516 &options1, &options2,
4517 NT_STATUS_NOT_SUPPORTED);
4518 talloc_free(tree0);
4519 return ret;
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;
4526 bool ret = false;
4527 struct smb2_transport *transport0 = tree0->session->transport;
4528 struct smbcli_options options1;
4529 struct smbcli_options options2;
4530 bool ok;
4532 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
4533 torture_skip(tctx,
4534 "Can't test without SMB 3.1.1 support");
4537 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
4538 torture_skip(tctx,
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,
4546 CRED_SPECIFIED);
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) {
4555 .num_algos = 1,
4556 .algos = {
4557 SMB2_SIGNING_HMAC_SHA256,
4560 options1.smb3_capabilities.encryption = (struct smb3_encryption_capabilities) {
4561 .num_algos = 1,
4562 .algos = {
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) {
4572 .num_algos = 1,
4573 .algos = {
4574 SMB2_SIGNING_AES128_GMAC,
4577 options2.smb3_capabilities.encryption = (struct smb3_encryption_capabilities) {
4578 .num_algos = 1,
4579 .algos = {
4580 SMB2_ENCRYPTION_AES128_GCM,
4584 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
4585 credentials,
4586 &options1, &options2,
4587 NT_STATUS_NOT_SUPPORTED);
4588 talloc_free(tree0);
4589 return ret;
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;
4596 bool ret = false;
4597 struct smb2_transport *transport0 = tree0->session->transport;
4598 struct smbcli_options options1;
4599 struct smbcli_options options2;
4600 bool ok;
4602 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
4603 torture_skip(tctx,
4604 "Can't test without SMB 3.1.1 support");
4607 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
4608 torture_skip(tctx,
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,
4616 CRED_SPECIFIED);
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) {
4631 .num_algos = 1,
4632 .algos = {
4633 SMB2_SIGNING_AES128_GMAC,
4637 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
4638 credentials,
4639 &options1, &options2,
4640 NT_STATUS_NOT_SUPPORTED);
4641 talloc_free(tree0);
4642 return ret;
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;
4649 bool ret = false;
4650 struct smb2_transport *transport0 = tree0->session->transport;
4651 struct smbcli_options options1;
4652 struct smbcli_options options2;
4653 bool ok;
4655 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
4656 torture_skip(tctx,
4657 "Can't test without SMB 3.1.1 support");
4660 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
4661 torture_skip(tctx,
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,
4669 CRED_SPECIFIED);
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) {
4685 .num_algos = 1,
4686 .algos = {
4687 SMB2_SIGNING_AES128_GMAC,
4691 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
4692 credentials,
4693 &options1, &options2,
4694 NT_STATUS_NOT_SUPPORTED);
4695 talloc_free(tree0);
4696 return ret;
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;
4703 bool ret = false;
4704 struct smb2_transport *transport0 = tree0->session->transport;
4705 struct smbcli_options options1;
4706 struct smbcli_options options2;
4707 bool ok;
4708 bool encrypted;
4710 encrypted = smb2cli_tcon_is_encryption_on(tree0->smbXcli);
4711 if (encrypted) {
4712 torture_skip(tctx,
4713 "Can't test SMB 2.10 if encryption is required");
4716 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
4717 torture_skip(tctx,
4718 "Can't test without SMB 3.1.1 support");
4721 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
4722 torture_skip(tctx,
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,
4729 SMB_ENCRYPTION_OFF,
4730 CRED_SPECIFIED);
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) {
4745 .num_algos = 1,
4746 .algos = {
4747 SMB2_SIGNING_AES128_GMAC,
4751 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
4752 credentials,
4753 &options1, &options2,
4754 NT_STATUS_NOT_SUPPORTED);
4755 talloc_free(tree0);
4756 return ret;
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;
4763 bool ret = false;
4764 struct smb2_transport *transport0 = tree0->session->transport;
4765 struct smbcli_options options1;
4766 struct smbcli_options options2;
4767 bool ok;
4768 bool encrypted;
4770 encrypted = smb2cli_tcon_is_encryption_on(tree0->smbXcli);
4771 if (encrypted) {
4772 torture_skip(tctx,
4773 "Can't test SMB 2.10 if encryption is required");
4776 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
4777 torture_skip(tctx,
4778 "Can't test without SMB 3.1.1 support");
4781 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
4782 torture_skip(tctx,
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,
4789 SMB_ENCRYPTION_OFF,
4790 CRED_SPECIFIED);
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) {
4806 .num_algos = 1,
4807 .algos = {
4808 SMB2_SIGNING_AES128_GMAC,
4812 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
4813 credentials,
4814 &options1, &options2,
4815 NT_STATUS_NOT_SUPPORTED);
4816 talloc_free(tree0);
4817 return ret;
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;
4824 bool ret = false;
4825 struct smb2_transport *transport0 = tree0->session->transport;
4826 struct smbcli_options options1;
4827 struct smbcli_options options2;
4828 bool ok;
4830 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
4831 torture_skip(tctx,
4832 "Can't test without SMB 3.1.1 support");
4835 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
4836 torture_skip(tctx,
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,
4844 CRED_SPECIFIED);
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) {
4853 .num_algos = 1,
4854 .algos = {
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) {
4865 .num_algos = 1,
4866 .algos = {
4867 SMB2_SIGNING_AES128_CMAC,
4871 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
4872 credentials,
4873 &options1, &options2,
4874 NT_STATUS_REQUEST_OUT_OF_SEQUENCE);
4875 talloc_free(tree0);
4876 return ret;
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;
4883 bool ret = false;
4884 struct smb2_transport *transport0 = tree0->session->transport;
4885 struct smbcli_options options1;
4886 struct smbcli_options options2;
4887 bool ok;
4889 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
4890 torture_skip(tctx,
4891 "Can't test without SMB 3.1.1 support");
4894 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
4895 torture_skip(tctx,
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,
4903 CRED_SPECIFIED);
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) {
4912 .num_algos = 1,
4913 .algos = {
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) {
4925 .num_algos = 1,
4926 .algos = {
4927 SMB2_SIGNING_AES128_CMAC,
4931 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
4932 credentials,
4933 &options1, &options2,
4934 NT_STATUS_REQUEST_OUT_OF_SEQUENCE);
4935 talloc_free(tree0);
4936 return ret;
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;
4943 bool ret = false;
4944 struct smb2_transport *transport0 = tree0->session->transport;
4945 struct smbcli_options options1;
4946 struct smbcli_options options2;
4947 bool ok;
4948 bool encrypted;
4950 encrypted = smb2cli_tcon_is_encryption_on(tree0->smbXcli);
4951 if (encrypted) {
4952 torture_skip(tctx,
4953 "Can't test SMB 2.10 if encryption is required");
4956 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
4957 torture_skip(tctx,
4958 "Can't test without SMB 3.1.1 support");
4961 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
4962 torture_skip(tctx,
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,
4970 CRED_SPECIFIED);
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) {
4979 .num_algos = 1,
4980 .algos = {
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) {
4991 .num_algos = 1,
4992 .algos = {
4993 SMB2_SIGNING_HMAC_SHA256,
4997 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
4998 credentials,
4999 &options1, &options2,
5000 NT_STATUS_REQUEST_OUT_OF_SEQUENCE);
5001 talloc_free(tree0);
5002 return ret;
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;
5009 bool ret = false;
5010 struct smb2_transport *transport0 = tree0->session->transport;
5011 struct smbcli_options options1;
5012 struct smbcli_options options2;
5013 bool ok;
5014 bool encrypted;
5016 encrypted = smb2cli_tcon_is_encryption_on(tree0->smbXcli);
5017 if (encrypted) {
5018 torture_skip(tctx,
5019 "Can't test SMB 2.10 if encryption is required");
5022 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
5023 torture_skip(tctx,
5024 "Can't test without SMB 3.1.1 support");
5027 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
5028 torture_skip(tctx,
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,
5036 CRED_SPECIFIED);
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) {
5045 .num_algos = 1,
5046 .algos = {
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) {
5058 .num_algos = 1,
5059 .algos = {
5060 SMB2_SIGNING_HMAC_SHA256,
5064 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
5065 credentials,
5066 &options1, &options2,
5067 NT_STATUS_REQUEST_OUT_OF_SEQUENCE);
5068 talloc_free(tree0);
5069 return ret;
5072 static bool test_session_two_logoff(struct torture_context *tctx,
5073 struct smb2_tree *tree1)
5075 NTSTATUS status;
5076 bool ret = true;
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;
5083 bool ok;
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");
5100 TALLOC_FREE(tree2);
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");
5109 TALLOC_FREE(tree1);
5111 return ret;
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);
5121 NTSTATUS status;
5122 bool ret = false;
5123 struct smb2_tree *tree1 = NULL;
5124 char fname[256];
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,
5134 host,
5135 lpcfg_smb_ports(tctx->lp_ctx),
5136 share,
5137 lpcfg_resolve_context(tctx->lp_ctx),
5138 credentials1,
5139 &tree1,
5140 tctx->ev,
5141 options1,
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;
5167 h1 = &_h1;
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,
5199 ret, done,
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");
5210 ret = true;
5211 done:
5212 if (h1 != NULL) {
5213 smb2_util_close(tree1, *h1);
5215 TALLOC_FREE(tree1);
5217 return ret;
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();
5223 bool ret = false;
5224 struct smb2_transport *transport0 = tree0->session->transport;
5225 struct smbcli_options options1;
5226 bool encrypted;
5228 encrypted = smb2cli_tcon_is_encryption_on(tree0->smbXcli);
5229 if (encrypted) {
5230 torture_skip(tctx,
5231 "Can't test signing only if encryption is required");
5234 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
5235 torture_skip(tctx,
5236 "Can't test without SMB 3.1.1 support");
5239 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
5240 torture_skip(tctx,
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) {
5250 .num_algos = 1,
5251 .algos = {
5252 SMB2_SIGNING_HMAC_SHA256,
5256 ret = test_session_sign_enc(tctx,
5257 __func__,
5258 credentials,
5259 &options1);
5260 TALLOC_FREE(tree0);
5261 return ret;
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();
5267 bool ret = false;
5268 struct smb2_transport *transport0 = tree0->session->transport;
5269 struct smbcli_options options1;
5270 bool encrypted;
5272 encrypted = smb2cli_tcon_is_encryption_on(tree0->smbXcli);
5273 if (encrypted) {
5274 torture_skip(tctx,
5275 "Can't test signing only if encryption is required");
5278 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
5279 torture_skip(tctx,
5280 "Can't test without SMB 3.1.1 support");
5283 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
5284 torture_skip(tctx,
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) {
5294 .num_algos = 1,
5295 .algos = {
5296 SMB2_SIGNING_AES128_CMAC,
5300 ret = test_session_sign_enc(tctx,
5301 __func__,
5302 credentials,
5303 &options1);
5304 TALLOC_FREE(tree0);
5305 return ret;
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();
5311 bool ret = false;
5312 struct smb2_transport *transport0 = tree0->session->transport;
5313 struct smbcli_options options1;
5314 bool encrypted;
5316 encrypted = smb2cli_tcon_is_encryption_on(tree0->smbXcli);
5317 if (encrypted) {
5318 torture_skip(tctx,
5319 "Can't test signing only if encryption is required");
5322 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
5323 torture_skip(tctx,
5324 "Can't test without SMB 3.1.1 support");
5327 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
5328 torture_skip(tctx,
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) {
5338 .num_algos = 1,
5339 .algos = {
5340 SMB2_SIGNING_AES128_GMAC,
5344 ret = test_session_sign_enc(tctx,
5345 __func__,
5346 credentials,
5347 &options1);
5348 TALLOC_FREE(tree0);
5349 return ret;
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;
5356 bool ret = false;
5357 struct smb2_transport *transport0 = tree0->session->transport;
5358 struct smbcli_options options1;
5359 bool ok;
5361 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
5362 torture_skip(tctx,
5363 "Can't test without SMB 3.1.1 support");
5366 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
5367 torture_skip(tctx,
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,
5375 CRED_SPECIFIED);
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) {
5384 .num_algos = 1,
5385 .algos = {
5386 SMB2_ENCRYPTION_AES128_CCM,
5390 ret = test_session_sign_enc(tctx,
5391 __func__,
5392 credentials,
5393 &options1);
5394 TALLOC_FREE(tree0);
5395 return ret;
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;
5402 bool ret = false;
5403 struct smb2_transport *transport0 = tree0->session->transport;
5404 struct smbcli_options options1;
5405 bool ok;
5407 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
5408 torture_skip(tctx,
5409 "Can't test without SMB 3.1.1 support");
5412 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
5413 torture_skip(tctx,
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,
5421 CRED_SPECIFIED);
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) {
5430 .num_algos = 1,
5431 .algos = {
5432 SMB2_ENCRYPTION_AES128_GCM,
5436 ret = test_session_sign_enc(tctx,
5437 __func__,
5438 credentials,
5439 &options1);
5440 TALLOC_FREE(tree0);
5441 return ret;
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;
5448 bool ret = false;
5449 struct smb2_transport *transport0 = tree0->session->transport;
5450 struct smbcli_options options1;
5451 bool ok;
5453 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
5454 torture_skip(tctx,
5455 "Can't test without SMB 3.1.1 support");
5458 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
5459 torture_skip(tctx,
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,
5467 CRED_SPECIFIED);
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) {
5476 .num_algos = 1,
5477 .algos = {
5478 SMB2_ENCRYPTION_AES256_CCM,
5482 ret = test_session_sign_enc(tctx,
5483 __func__,
5484 credentials,
5485 &options1);
5486 TALLOC_FREE(tree0);
5487 return ret;
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;
5494 bool ret = false;
5495 struct smb2_transport *transport0 = tree0->session->transport;
5496 struct smbcli_options options1;
5497 bool ok;
5499 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
5500 torture_skip(tctx,
5501 "Can't test without SMB 3.1.1 support");
5504 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
5505 torture_skip(tctx,
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,
5513 CRED_SPECIFIED);
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) {
5522 .num_algos = 1,
5523 .algos = {
5524 SMB2_ENCRYPTION_AES256_GCM,
5528 ret = test_session_sign_enc(tctx,
5529 __func__,
5530 credentials,
5531 &options1);
5532 TALLOC_FREE(tree0);
5533 return ret;
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());
5540 NTSTATUS status;
5541 bool ret = true;
5543 * This is a NTLMv2_RESPONSE with the strange
5544 * NTLMv2_CLIENT_CHALLENGE used by the net diag
5545 * tool.
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,
5570 CRED_SPECIFIED);
5571 cli_credentials_set_ntlm_response(ntlm_creds,
5572 &lm_response,
5573 &lm_session_key,
5574 &nt_response,
5575 &nt_session_key,
5576 CRED_SPECIFIED);
5577 status = smb2_session_setup_spnego(tree->session,
5578 ntlm_creds,
5579 0 /* previous_session_id */);
5580 torture_assert_ntstatus_equal(tctx, status, NT_STATUS_INVALID_PARAMETER,
5581 "smb2_session_setup_spnego failed");
5583 return ret;
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$";
5591 char *unc = NULL;
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;
5598 NTSTATUS status;
5599 bool ok = true;
5600 struct tevent_req *subreq = NULL;
5601 uint32_t timeout_msec;
5603 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_00) {
5604 torture_skip(tctx,
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,
5615 CRED_SPECIFIED);
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,
5623 host,
5624 lpcfg_smb_ports(tctx->lp_ctx),
5625 share,
5626 lpcfg_resolve_context(tctx->lp_ctx),
5627 anon_creds,
5628 &anon_tree,
5629 tctx->ev,
5630 &options,
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,
5641 anon_creds,
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,
5656 tctx->ev,
5657 transport->conn,
5658 timeout_msec,
5659 anon_session->smbXcli,
5660 anon_tree->smbXcli,
5661 0, /* flags */
5662 unc);
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");
5681 return true;
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$";
5689 char *unc = NULL;
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,
5702 .in = {
5703 .file = {
5704 .handle = {
5705 .data = {
5706 [0] = UINT64_MAX,
5707 [1] = UINT64_MAX,
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,
5717 NTSTATUS status;
5718 bool ok = true;
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) {
5725 torture_skip(tctx,
5726 "Can't test without SMB3 support");
5729 if (caps & SMB2_CAP_MULTI_CHANNEL) {
5730 expected_mc_status = NT_STATUS_OK;
5731 } else {
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,
5742 CRED_SPECIFIED);
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,
5749 CRED_SPECIFIED);
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,
5756 host,
5757 lpcfg_smb_ports(tctx->lp_ctx),
5758 share,
5759 lpcfg_resolve_context(tctx->lp_ctx),
5760 user_creds,
5761 &user_tree,
5762 tctx->ev,
5763 &options,
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),
5776 tctx);
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,
5783 anon_creds,
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,
5798 tctx->ev,
5799 transport->conn,
5800 timeout_msec,
5801 anon_session->smbXcli,
5802 anon_tree->smbXcli,
5803 0, /* flags */
5804 unc);
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");
5852 return true;
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$";
5860 char *unc = NULL;
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;
5871 NTSTATUS status;
5872 bool ok = true;
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) {
5878 torture_skip(tctx,
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,
5889 CRED_SPECIFIED);
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,
5896 CRED_SPECIFIED);
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,
5903 host,
5904 lpcfg_smb_ports(tctx->lp_ctx),
5905 share,
5906 lpcfg_resolve_context(tctx->lp_ctx),
5907 user_creds,
5908 &user_tree,
5909 tctx->ev,
5910 &options,
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),
5923 tctx);
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,
5932 anon_creds,
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,
5947 tctx->ev,
5948 transport->conn,
5949 timeout_msec,
5950 anon_session->smbXcli,
5951 anon_tree->smbXcli,
5952 0, /* flags */
5953 unc);
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");
5972 return true;
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$";
5980 char *unc = NULL;
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;
5987 NTSTATUS status;
5988 bool ok = true;
5989 struct tevent_req *subreq = NULL;
5990 uint32_t timeout_msec;
5992 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_00) {
5993 torture_skip(tctx,
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,
6004 CRED_SPECIFIED);
6005 torture_assert(tctx, ok, "cli_credentials_set_smb_signing");
6006 ok = cli_credentials_set_smb_ipc_signing(anon_creds,
6007 SMB_SIGNING_REQUIRED,
6008 CRED_SPECIFIED);
6009 torture_assert(tctx, ok, "cli_credentials_set_smb_ipc_signing");
6010 ok = cli_credentials_set_smb_encryption(anon_creds,
6011 SMB_ENCRYPTION_OFF,
6012 CRED_SPECIFIED);
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,
6021 host,
6022 lpcfg_smb_ports(tctx->lp_ctx),
6023 share,
6024 lpcfg_resolve_context(tctx->lp_ctx),
6025 anon_creds,
6026 &anon_tree,
6027 tctx->ev,
6028 &options,
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,
6039 anon_creds,
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,
6049 tctx->ev,
6050 transport->conn,
6051 timeout_msec,
6052 anon_session->smbXcli,
6053 anon_tree->smbXcli,
6054 0, /* flags */
6055 unc);
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");
6069 return true;
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$";
6077 char *unc = NULL;
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;
6085 NTSTATUS status;
6086 bool ok = true;
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) {
6093 torture_skip(tctx,
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,
6104 CRED_SPECIFIED);
6105 torture_assert(tctx, ok, "cli_credentials_set_smb_signing");
6106 ok = cli_credentials_set_smb_ipc_signing(anon_creds,
6107 SMB_SIGNING_REQUIRED,
6108 CRED_SPECIFIED);
6109 torture_assert(tctx, ok, "cli_credentials_set_smb_ipc_signing");
6110 ok = cli_credentials_set_smb_encryption(anon_creds,
6111 SMB_ENCRYPTION_OFF,
6112 CRED_SPECIFIED);
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,
6121 host,
6122 lpcfg_smb_ports(tctx->lp_ctx),
6123 share,
6124 lpcfg_resolve_context(tctx->lp_ctx),
6125 anon_creds,
6126 &anon_tree,
6127 tctx->ev,
6128 &options,
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,
6142 anon_creds,
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),
6157 tctx);
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,
6164 tctx->ev,
6165 transport->conn,
6166 timeout_msec,
6167 anon_session->smbXcli,
6168 anon_tree->smbXcli,
6169 0, /* flags */
6170 unc);
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,
6187 tctx->ev,
6188 transport->conn,
6189 timeout_msec,
6190 anon_session_nosign->smbXcli,
6191 anon_tree->smbXcli,
6192 0, /* flags */
6193 unc);
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");
6207 return true;
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");
6290 return suite;
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;
6303 NTSTATUS status;
6304 bool ok = true;
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,
6318 host,
6319 lpcfg_smb_ports(tctx->lp_ctx),
6320 share,
6321 lpcfg_resolve_context(tctx->lp_ctx),
6322 creds,
6323 &tree,
6324 tctx->ev,
6325 &options,
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(
6334 tctx,
6335 security_mode,
6336 SMB2_NEGOTIATE_SIGNING_REQUIRED | SMB2_NEGOTIATE_SIGNING_ENABLED,
6338 done,
6339 "Signing not required");
6341 done:
6342 return ok;
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");
6354 return suite;