Debian Codegraph @

source4/torture/smb2/session.c

raw
1 /*
2 Unix SMB/CIFS implementation.
3
4 test suite for SMB2 session setups
5
6 Copyright (C) Michael Adam 2012
7
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.
12
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.
17
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/>.
20 */
21
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"
36
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
43
44 #define texpand(x) #x
45 #define GENSEC_GSSAPI_REQUESTED_LIFETIME(x) \
46 "gensec_gssapi:requested_life_time=" texpand(x)
47
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)
61
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 } \
67 }
68
69 static void sleep_remaining(struct torture_context *tctx,
70 const struct timeval *endtime)
71 {
72 struct timeval current = tevent_timeval_current();
73 double remaining_secs = timeval_elapsed2(&current, endtime);
74
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));
81 }
82
83 /**
84 * basic test for doing a session reconnect
85 */
86 bool test_session_reconnect1(struct torture_context *tctx, struct smb2_tree *tree)
87 {
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;
100
101 /* Add some random component to the file name. */
102 snprintf(fname, sizeof(fname), "session_reconnect_%s.dat",
103 generate_random_str(tctx, 8));
104
105 smb2_util_unlink(tree, fname);
106
107 smb2_oplock_create_share(&io1, fname,
108 smb2_util_share_access(""),
109 smb2_util_oplock_level("b"));
110
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");
120
121 /* disconnect, reconnect and then do durable reopen */
122 previous_session_id = smb2cli_session_current_id(tree->session->smbXcli);
123
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");
128
129 /* try to access the file via the old handle */
130
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;
140
141 smb2_oplock_create_share(&io2, fname,
142 smb2_util_share_access(""),
143 smb2_util_oplock_level("b"));
144
145 status = smb2_create(tree2, mem_ctx, &io2);
146 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
147 "smb2_create failed");
148
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;
155
156 done:
157 if (h1 != NULL) {
158 smb2_util_close(tree, *h1);
159 }
160 if (h2 != NULL) {
161 smb2_util_close(tree2, *h2);
162 }
163
164 if (tree2 != NULL) {
165 smb2_util_unlink(tree2, fname);
166 }
167 smb2_util_unlink(tree, fname);
168
169 talloc_free(tree);
170 talloc_free(tree2);
171
172 talloc_free(mem_ctx);
173
174 return ret;
175 }
176
177 /**
178 * basic test for doing a session reconnect on one connection
179 */
180 bool test_session_reconnect2(struct torture_context *tctx, struct smb2_tree *tree)
181 {
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;
192
193 /* Add some random component to the file name. */
194 snprintf(fname, sizeof(fname), "session_reconnect_%s.dat",
195 generate_random_str(tctx, 8));
196
197 smb2_util_unlink(tree, fname);
198
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;
203
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");
213
214 /* disconnect, reconnect and then do durable reopen */
215 previous_session_id = smb2cli_session_current_id(tree->session->smbXcli);
216
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");
220
221 /* try to access the file via the old handle */
222
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;
232
233 done:
234 if (h1 != NULL) {
235 smb2_util_close(tree, *h1);
236 }
237
238 talloc_free(tree);
239 talloc_free(session2);
240
241 talloc_free(mem_ctx);
242
243 return ret;
244 }
245
246 bool test_session_reauth1(struct torture_context *tctx, struct smb2_tree *tree)
247 {
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;
256
257 /* Add some random component to the file name. */
258 snprintf(fname, sizeof(fname), "session_reauth1_%s.dat",
259 generate_random_str(tctx, 8));
260
261 smb2_util_unlink(tree, fname);
262
263 smb2_oplock_create_share(&io1, fname,
264 smb2_util_share_access(""),
265 smb2_util_oplock_level("b"));
266
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");
276
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");
282
283 /* try to access the file via the old handle */
284
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");
291
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");
297
298 /* try to access the file via the old handle */
299
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");
306
307 done:
308 if (h1 != NULL) {
309 smb2_util_close(tree, *h1);
310 }
311
312 smb2_util_unlink(tree, fname);
313
314 talloc_free(tree);
315
316 talloc_free(mem_ctx);
317
318 return ret;
319 }
320
321 bool test_session_reauth2(struct torture_context *tctx, struct smb2_tree *tree)
322 {
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;
332
333 /* Add some random component to the file name. */
334 snprintf(fname, sizeof(fname), "session_reauth2_%s.dat",
335 generate_random_str(tctx, 8));
336
337 smb2_util_unlink(tree, fname);
338
339 smb2_oplock_create_share(&io1, fname,
340 smb2_util_share_access(""),
341 smb2_util_oplock_level("b"));
342
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");
352
353 /* re-authenticate as anonymous */
354
355 anon_creds = cli_credentials_init_anon(mem_ctx);
356 torture_assert(tctx, (anon_creds != NULL), "talloc error");
357
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");
363
364 /* try to access the file via the old handle */
365
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");
372
373 /* re-authenticate as original user again */
374
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");
380
381 /* try to access the file via the old handle */
382
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");
389
390 done:
391 if (h1 != NULL) {
392 smb2_util_close(tree, *h1);
393 }
394
395 smb2_util_unlink(tree, fname);
396
397 talloc_free(tree);
398
399 talloc_free(mem_ctx);
400
401 return ret;
402 }
403
404 /**
405 * test getting security descriptor after reauth
406 */
407 bool test_session_reauth3(struct torture_context *tctx, struct smb2_tree *tree)
408 {
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;
423
424 /* Add some random component to the file name. */
425 snprintf(fname, sizeof(fname), "session_reauth3_%s.dat",
426 generate_random_str(tctx, 8));
427
428 smb2_util_unlink(tree, fname);
429
430 smb2_oplock_create_share(&io1, fname,
431 smb2_util_share_access(""),
432 smb2_util_oplock_level("b"));
433
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");
443
444 /* get the security descriptor */
445
446 ZERO_STRUCT(qfinfo);
447
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;
451
452 status = smb2_getinfo_file(tree, mem_ctx, &qfinfo);
453 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
454 "smb2_getinfo_file failed");
455
456 /* re-authenticate as anonymous */
457
458 anon_creds = cli_credentials_init_anon(mem_ctx);
459 torture_assert(tctx, (anon_creds != NULL), "talloc error");
460
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");
466
467 /* try to access the file via the old handle */
468
469 ZERO_STRUCT(qfinfo);
470
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;
474
475 status = smb2_getinfo_file(tree, mem_ctx, &qfinfo);
476 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
477 "smb2_getinfo_file failed");
478
479 /* re-authenticate as original user again */
480
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");
486
487 /* try to access the file via the old handle */
488
489 ZERO_STRUCT(qfinfo);
490
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;
494
495 status = smb2_getinfo_file(tree, mem_ctx, &qfinfo);
496 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
497 "smb2_getinfo_file failed");
498
499 done:
500 if (h1 != NULL) {
501 smb2_util_close(tree, *h1);
502 }
503
504 smb2_util_unlink(tree, fname);
505
506 talloc_free(tree);
507
508 talloc_free(mem_ctx);
509
510 return ret;
511 }
512
513 /**
514 * test setting security descriptor after reauth.
515 */
516 bool test_session_reauth4(struct torture_context *tctx, struct smb2_tree *tree)
517 {
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;
536
537 /* Add some random component to the file name. */
538 snprintf(fname, sizeof(fname), "session_reauth4_%s.dat",
539 generate_random_str(tctx, 8));
540
541 smb2_util_unlink(tree, fname);
542
543 smb2_oplock_create_share(&io1, fname,
544 smb2_util_share_access(""),
545 smb2_util_oplock_level("b"));
546
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");
556
557 /* get the security descriptor */
558
559 ZERO_STRUCT(qfinfo);
560
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;
564
565 status = smb2_getinfo_file(tree, mem_ctx, &qfinfo);
566 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
567 "smb2_getinfo_file failed");
568
569 sd1 = qfinfo.query_secdesc.out.sd;
570
571 /* re-authenticate as anonymous */
572
573 anon_creds = cli_credentials_init_anon(mem_ctx);
574 torture_assert(tctx, (anon_creds != NULL), "talloc error");
575
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");
581
582 /* give full access on the file to anonymous */
583
584 extra_sid = dom_sid_parse_talloc(tctx, SID_NT_ANONYMOUS);
585
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;
591
592 status = security_descriptor_dacl_add(sd1, &ace);
593 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
594 "security_descriptor_dacl_add failed");
595
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;
601
602 status = smb2_setinfo_file(tree, &sfinfo);
603 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
604 "smb2_setinfo_file failed");
605
606 /* re-authenticate as original user again */
607
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");
613
614 /* re-get the security descriptor */
615
616 ZERO_STRUCT(qfinfo);
617
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;
621
622 status = smb2_getinfo_file(tree, mem_ctx, &qfinfo);
623 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
624 "smb2_getinfo_file failed");
625
626 ret = true;
627
628 done:
629 if (h1 != NULL) {
630 smb2_util_close(tree, *h1);
631 }
632
633 smb2_util_unlink(tree, fname);
634
635 talloc_free(tree);
636
637 talloc_free(mem_ctx);
638
639 return ret;
640 }
641
642 /**
643 * test renaming after reauth.
644 * compare security descriptors before and after rename/reauth
645 */
646 bool test_session_reauth5(struct torture_context *tctx, struct smb2_tree *tree)
647 {
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;
672
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);
677
678 ok = smb2_util_setup_dir(tctx, tree, dname);
679 torture_assert(tctx, ok, "smb2_util_setup_dir not ok");
680
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;
685
686 smb2_oplock_create_share(&io1, fname,
687 smb2_util_share_access(""),
688 smb2_util_oplock_level("b"));
689
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");
699
700 /* get the security descriptor */
701
702 ZERO_STRUCT(qfinfo);
703
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;
707
708 status = smb2_getinfo_file(tree, mem_ctx, &qfinfo);
709 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
710 "smb2_getinfo_file failed");
711
712 f_sd1 = qfinfo.query_secdesc.out.sd;
713
714 /* re-authenticate as anonymous */
715
716 anon_creds = cli_credentials_init_anon(mem_ctx);
717 torture_assert(tctx, (anon_creds != NULL), "talloc error");
718
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");
724
725 /* try to rename the file: fails */
726
727 snprintf(fname2, sizeof(fname2), "%s\\file2.dat", dname);
728
729 status = smb2_util_unlink(tree, fname2);
730 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
731 "smb2_util_unlink failed");
732
733
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;
739
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");
745
746 /* re-authenticate as original user again */
747
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");
753
754 /* give full access on the file to anonymous */
755
756 extra_sid = dom_sid_parse_talloc(tctx, SID_NT_ANONYMOUS);
757
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;
763
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");
767
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;
773
774 status = smb2_setinfo_file(tree, &sfinfo);
775 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
776 "smb2_setinfo_file failed");
777
778 /* re-get the security descriptor */
779
780 ZERO_STRUCT(qfinfo);
781
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;
785
786 status = smb2_getinfo_file(tree, mem_ctx, &qfinfo);
787 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
788 "smb2_getinfo_file failed");
789
790 /* re-authenticate as anonymous - again */
791
792 anon_creds = cli_credentials_init_anon(mem_ctx);
793 torture_assert(tctx, (anon_creds != NULL), "talloc error");
794
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");
800
801 /* try to rename the file: fails */
802
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;
808
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");
814
815 /* give full access on the parent dir to anonymous */
816
817 ZERO_STRUCT(qfinfo);
818
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;
822
823 status = smb2_getinfo_file(tree, mem_ctx, &qfinfo);
824 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
825 "smb2_getinfo_file failed");
826
827 d_sd1 = qfinfo.query_secdesc.out.sd;
828
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;
834
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");
838
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;
845
846 status = smb2_setinfo_file(tree, &sfinfo);
847 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
848 "smb2_setinfo_file failed");
849
850 ZERO_STRUCT(qfinfo);
851
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;
855
856 status = smb2_getinfo_file(tree, mem_ctx, &qfinfo);
857 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
858 "smb2_getinfo_file failed");
859
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;
864
865 /* try to rename the file: still fails */
866
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;
872
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");
878
879 /* re-authenticate as original user - again */
880
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");
886
887 /* rename the file - for verification that it works */
888
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;
894
895 status = smb2_setinfo_file(tree, &sfinfo);
896 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
897 "smb2_setinfo_file failed");
898
899 /* closs the file, check it is gone and reopen under the new name */
900
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);
905
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 */);
913
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");
919
920 ZERO_STRUCT(io1);
921
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 */);
929
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");
939
940 /* try to access the file via the old handle */
941
942 ZERO_STRUCT(qfinfo);
943
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;
947
948 status = smb2_getinfo_file(tree, mem_ctx, &qfinfo);
949 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
950 "smb2_getinfo_file failed");
951
952 done:
953 if (dh1 != NULL) {
954 smb2_util_close(tree, *dh1);
955 }
956 if (h1 != NULL) {
957 smb2_util_close(tree, *h1);
958 }
959
960 smb2_deltree(tree, dname);
961
962 talloc_free(tree);
963
964 talloc_free(mem_ctx);
965
966 return ret;
967 }
968
969 /**
970 * do reauth with wrong credentials,
971 * hence triggering the error path in reauth.
972 * The invalid reauth deletes the session.
973 */
974 bool test_session_reauth6(struct torture_context *tctx, struct smb2_tree *tree)
975 {
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;
989
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.");
995 }
996
997 encrypted = smb2cli_tcon_is_encryption_on(tree->smbXcli);
998
999 /* Add some random component to the file name. */
1000 snprintf(fname, sizeof(fname), "session_reauth1_%s.dat",
1001 generate_random_str(tctx, 8));
1002
1003 smb2_util_unlink(tree, fname);
1004
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;
1009
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");
1019
1020 /*
1021 * reauthentication with invalid credentials:
1022 */
1023
1024 broken_creds = cli_credentials_shallow_copy(mem_ctx,
1025 samba_cmdline_get_creds());
1026 torture_assert(tctx, (broken_creds != NULL), "talloc error");
1027
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");
1032
1033 ok = cli_credentials_set_password(broken_creds, corrupted_password,
1034 CRED_SPECIFIED);
1035 torture_assert(tctx, ok, "cli_credentials_set_password not ok");
1036
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");
1044
1045 torture_comment(tctx, "did failed reauth\n");
1046 /*
1047 * now verify that the invalid session reauth has closed our session
1048 */
1049
1050 if (encrypted) {
1051 expected = NT_STATUS_CONNECTION_DISCONNECTED;
1052 } else {
1053 expected = NT_STATUS_USER_SESSION_DELETED;
1054 }
1055
1056 smb2_oplock_create_share(&io1, fname,
1057 smb2_util_share_access(""),
1058 smb2_util_oplock_level("b"));
1059
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");
1064
1065 done:
1066 if (h1 != NULL) {
1067 smb2_util_close(tree, *h1);
1068 }
1069
1070 smb2_util_unlink(tree, fname);
1071
1072 talloc_free(tree);
1073
1074 talloc_free(mem_ctx);
1075
1076 return ret;
1077 }
1078
1079
1080 static bool test_session_expire1i(struct torture_context *tctx,
1081 bool force_signing,
1082 bool force_encryption)
1083 {
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;
1100
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!");
1109 }
1110
1111 torture_assert_int_equal(tctx,
1112 use_kerberos,
1113 CRED_USE_KERBEROS_REQUIRED,
1114 "please use --use-kerberos=required");
1115
1116 cli_credentials_invalidate_ccache(credentials, CRED_SPECIFIED);
1117
1118 lpcfg_set_option(
1119 tctx->lp_ctx,
1120 GENSEC_GSSAPI_REQUESTED_LIFETIME(KRB5_TICKET_LIFETIME));
1121
1122 lpcfg_smbcli_options(tctx->lp_ctx, &options);
1123 if (force_signing) {
1124 options.signing = SMB_SIGNING_REQUIRED;
1125 }
1126
1127 status = smb2_connect(tctx,
1128 host,
1129 share,
1130 tctx->lp_ctx,
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)
1138 );
1139 /*
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.
1143 */
1144 endtime = timeval_current_ofs(KRB5_TICKET_EXPIRETIME, 500 * 1000);
1145 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
1146 "smb2_connect failed");
1147
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");
1152 }
1153
1154 /* Add some random component to the file name. */
1155 snprintf(fname, sizeof(fname), "session_expire1_%s.dat",
1156 generate_random_str(tctx, 8));
1157
1158 smb2_util_unlink(tree, fname);
1159
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;
1164
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");
1174
1175 /* get the security descriptor */
1176
1177 ZERO_STRUCT(qfinfo);
1178
1179 qfinfo.access_information.level = RAW_FILEINFO_ACCESS_INFORMATION;
1180 qfinfo.access_information.in.file.handle = _h1;
1181
1182 for (i=0; i < 2; i++) {
1183 torture_comment(tctx, "%s: query info => OK\n",
1184 current_timestring(tctx, true));
1185
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");
1194
1195 sleep_remaining(tctx, &endtime);
1196
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");
1209
1210 /*
1211 * the krb5 library may not handle expired creds
1212 * well, lets start with an empty ccache.
1213 */
1214 cli_credentials_invalidate_ccache(credentials, CRED_SPECIFIED);
1215
1216 if (!force_encryption) {
1217 smb2cli_session_require_signed_response(
1218 tree->session->smbXcli, true);
1219 }
1220
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 */);
1226 /*
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.
1230 */
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");
1235
1236 smb2cli_session_require_signed_response(
1237 tree->session->smbXcli, false);
1238 }
1239
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);
1251 }
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");
1266
1267 ret = true;
1268 done:
1269 cli_credentials_invalidate_ccache(credentials, CRED_SPECIFIED);
1270
1271 if (h1 != NULL) {
1272 smb2_util_close(tree, *h1);
1273 }
1274
1275 talloc_free(tree);
1276 lpcfg_set_option(tctx->lp_ctx, GENSEC_GSSAPI_REQUESTED_LIFETIME(0));
1277 return ret;
1278 }
1279
1280 static bool test_session_expire1n(struct torture_context *tctx)
1281 {
1282 return test_session_expire1i(tctx,
1283 false, /* force_signing */
1284 false); /* force_encryption */
1285 }
1286
1287 static bool test_session_expire1s(struct torture_context *tctx)
1288 {
1289 return test_session_expire1i(tctx,
1290 true, /* force_signing */
1291 false); /* force_encryption */
1292 }
1293
1294 static bool test_session_expire1e(struct torture_context *tctx)
1295 {
1296 return test_session_expire1i(tctx,
1297 true, /* force_signing */
1298 true); /* force_encryption */
1299 }
1300
1301 static bool test_session_expire2i(struct torture_context *tctx,
1302 bool force_encryption)
1303 {
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;
1344
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!");
1353 }
1354
1355 torture_assert_int_equal(tctx,
1356 use_kerberos,
1357 CRED_USE_KERBEROS_REQUIRED,
1358 "please use --use-kerberos=required");
1359
1360 cli_credentials_invalidate_ccache(credentials, CRED_SPECIFIED);
1361
1362 lpcfg_set_option(
1363 tctx->lp_ctx,
1364 GENSEC_GSSAPI_REQUESTED_LIFETIME(KRB5_TICKET_LIFETIME));
1365
1366 lpcfg_smbcli_options(tctx->lp_ctx, &options);
1367 options.signing = SMB_SIGNING_REQUIRED;
1368
1369 unc = talloc_asprintf(tctx, "\\\\%s\\%s", host, share);
1370 torture_assert(tctx, unc != NULL, "talloc_asprintf");
1371
1372 status = smb2_connect(tctx,
1373 host,
1374 share,
1375 tctx->lp_ctx,
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)
1383 );
1384 /*
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.
1388 */
1389 endtime = timeval_current_ofs(KRB5_TICKET_EXPIRETIME, 500 * 1000);
1390 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
1391 "smb2_connect failed");
1392
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");
1397 }
1398
1399 caps = smb2cli_conn_server_capabilities(tree->session->transport->conn);
1400
1401 /* Add some random component to the file name. */
1402 snprintf(fname, sizeof(fname), "session_expire2_%s.dat",
1403 generate_random_str(tctx, 8));
1404
1405 smb2_util_unlink(tree, fname);
1406
1407 status = smb2_util_roothandle(tree, &dh);
1408 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
1409 "smb2_util_roothandle failed");
1410
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;
1415
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");
1425
1426 /* get the security descriptor */
1427
1428 ZERO_STRUCT(qfinfo);
1429
1430 qfinfo.access_information.level = RAW_FILEINFO_ACCESS_INFORMATION;
1431 qfinfo.access_information.in.file.handle = _h1;
1432
1433 torture_comment(tctx, "query info => OK\n");
1434
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");
1439
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");
1454
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);
1463
1464 while (!req->cancel.can_cancel && req->state <= SMB2_REQUEST_RECV) {
1465 if (tevent_loop_once(tctx->ev) != 0) {
1466 break;
1467 }
1468 }
1469
1470 torture_assert_goto(tctx, req->state <= SMB2_REQUEST_RECV, ret, done,
1471 "smb2_notify finished");
1472
1473 sleep_remaining(tctx, &endtime);
1474
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");
1482
1483
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");
1494
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");
1503
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");
1514
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");
1521
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");
1533
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");
1542
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");
1554 }
1555
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");
1568
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");
1572
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 = "";
1581
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");
1585
1586 smb2_transport_compound_set_related(tree->session->transport, true);
1587
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;
1594
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");
1598
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");
1604
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");
1620
1621 torture_comment(tctx, "1st notify => CANCEL\n");
1622 smb2_cancel(req);
1623
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");
1636
1637 torture_assert_goto(tctx, req->state > SMB2_REQUEST_RECV, ret, done,
1638 "smb2_notify (1st) not finished");
1639
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");
1645
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");
1667
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");
1674
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");
1681
1682 /*
1683 * (Un)Lock, Close and Logoff are still possible
1684 */
1685
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");
1691
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");
1698
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");
1707
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");
1713
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");
1718
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");
1724
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");
1729
1730 ret = true;
1731 done:
1732 cli_credentials_invalidate_ccache(credentials, CRED_SPECIFIED);
1733
1734 if (h1 != NULL) {
1735 smb2_util_close(tree, *h1);
1736 }
1737
1738 talloc_free(tree);
1739 lpcfg_set_option(tctx->lp_ctx, GENSEC_GSSAPI_REQUESTED_LIFETIME(0));
1740 return ret;
1741 }
1742
1743 static bool test_session_expire2s(struct torture_context *tctx)
1744 {
1745 return test_session_expire2i(tctx,
1746 false); /* force_encryption */
1747 }
1748
1749 static bool test_session_expire2e(struct torture_context *tctx)
1750 {
1751 return test_session_expire2i(tctx,
1752 true); /* force_encryption */
1753 }
1754
1755 static bool test_session_expire_disconnect(struct torture_context *tctx)
1756 {
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;
1772
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!");
1781 }
1782
1783 cli_credentials_invalidate_ccache(credentials, CRED_SPECIFIED);
1784
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;
1790
1791 status = smb2_connect(tctx,
1792 host,
1793 share,
1794 tctx->lp_ctx,
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)
1802 );
1803 /*
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.
1807 */
1808 endtime = timeval_current_ofs(KRB5_TICKET_EXPIRETIME, 500 * 1000);
1809 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
1810 "smb2_connect failed");
1811
1812 smbXcli_session_set_disconnect_expired(tree->session->smbXcli);
1813
1814 /* Add some random component to the file name. */
1815 snprintf(fname, sizeof(fname), "session_expire1_%s.dat",
1816 generate_random_str(tctx, 8));
1817
1818 smb2_util_unlink(tree, fname);
1819
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;
1824
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");
1834
1835 /* get the security descriptor */
1836
1837 ZERO_STRUCT(qfinfo);
1838
1839 qfinfo.access_information.level = RAW_FILEINFO_ACCESS_INFORMATION;
1840 qfinfo.access_information.in.file.handle = _h1;
1841
1842 torture_comment(tctx, "query info => OK\n");
1843
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");
1848
1849 sleep_remaining(tctx, &endtime);
1850
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");
1858
1859 connected = smbXcli_conn_is_connected(tree->session->transport->conn);
1860 torture_assert_goto(tctx, !connected, ret, done, "connected\n");
1861
1862 ret = true;
1863 done:
1864 cli_credentials_invalidate_ccache(credentials, CRED_SPECIFIED);
1865
1866 if (h1 != NULL) {
1867 smb2_util_close(tree, *h1);
1868 }
1869
1870 talloc_free(tree);
1871 lpcfg_set_option(tctx->lp_ctx, GENSEC_GSSAPI_REQUESTED_LIFETIME(0));
1872 return ret;
1873 }
1874
1875 bool test_session_bind1(struct torture_context *tctx, struct smb2_tree *tree1)
1876 {
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;
1897
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");
1901 }
1902
1903 /*
1904 * We always want signing for this test!
1905 */
1906 smb2cli_tcon_should_sign(tree1->smbXcli, true);
1907 options2 = transport1->options;
1908 options2.signing = SMB_SIGNING_REQUIRED;
1909
1910 /* Add some random component to the file name. */
1911 snprintf(fname, sizeof(fname), "session_bind1_%s.dat",
1912 generate_random_str(tctx, 8));
1913
1914 smb2_util_unlink(tree1, fname);
1915
1916 smb2_oplock_create_share(&io1, fname,
1917 smb2_util_share_access(""),
1918 smb2_util_oplock_level("b"));
1919
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");
1929
1930 status = smb2_connect(tctx,
1931 host,
1932 share,
1933 tctx->lp_ctx,
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)
1941 );
1942 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
1943 "smb2_connect failed");
1944 session2_2 = tree2->session;
1945 transport2 = tree2->session->transport;
1946
1947 /*
1948 * Now bind the 2nd transport connection to the 1st session
1949 */
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");
1955
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");
1961
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");
1970
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");
1979
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;
1985
1986 /*
1987 * Now bind the 1st transport connection to the 2nd session
1988 */
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");
1994
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");
2000
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;
2009
2010 if (h1 != NULL) {
2011 smb2_util_close(tree1, *h1);
2012 }
2013
2014 smb2_util_unlink(tree1, fname);
2015
2016 talloc_free(tree1);
2017
2018 talloc_free(mem_ctx);
2019
2020 return ret;
2021 }
2022
2023 static bool test_session_bind2(struct torture_context *tctx, struct smb2_tree *tree1)
2024 {
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;
2058
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");
2062 }
2063
2064 /*
2065 * We always want signing for this test!
2066 */
2067 smb2cli_tcon_should_sign(tree1->smbXcli, true);
2068 options2 = transport1->options;
2069 options2.signing = SMB_SIGNING_REQUIRED;
2070
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));
2076
2077 smb2_util_unlink(tree1, fname1);
2078 smb2_util_unlink(tree1, fname2);
2079
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(""));
2086
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");
2096
2097 status = smb2_connect(tctx,
2098 host,
2099 share,
2100 tctx->lp_ctx,
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)
2108 );
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);
2114
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(""));
2121
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");
2131
2132 options3 = transport1->options;
2133 options3.signing = SMB_SIGNING_REQUIRED;
2134 options3.only_negprot = true;
2135
2136 status = smb2_connect(tctx,
2137 host,
2138 share,
2139 tctx->lp_ctx,
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)
2147 );
2148 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
2149 "smb2_connect failed");
2150 transport3 = tree3->session->transport;
2151
2152 /*
2153 * Create a fake session for the 2nd transport connection to the 1st session
2154 */
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");
2160
2161 /*
2162 * Now bind the 3rd transport connection to the 1st session
2163 */
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");
2169
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");
2175
2176 /*
2177 * Create a fake session for the 1st transport connection to the 2nd session
2178 */
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");
2184
2185 /*
2186 * Now bind the 3rd transport connection to the 2nd session
2187 */
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");
2193
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");
2199
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");
2215
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");
2231
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");
2244
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");
2257
2258 smbXcli_conn_disconnect(transport3->conn, NT_STATUS_LOCAL_DISCONNECT);
2259 smb_msleep(500);
2260
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");
2269
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");
2278
2279 smbXcli_conn_disconnect(transport2->conn, NT_STATUS_LOCAL_DISCONNECT);
2280 smb_msleep(500);
2281 h2f2 = NULL;
2282
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");
2293
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;
2299
2300 ret = true;
2301 done:
2302
2303 smbXcli_conn_disconnect(transport3->conn, NT_STATUS_LOCAL_DISCONNECT);
2304 smbXcli_conn_disconnect(transport2->conn, NT_STATUS_LOCAL_DISCONNECT);
2305
2306 tree1->session = session1_1;
2307 tree2->session = session2_2;
2308
2309 if (h1f1 != NULL) {
2310 smb2_util_close(tree1, *h1f1);
2311 }
2312 if (h1f2 != NULL) {
2313 smb2_util_close(tree1, *h1f2);
2314 }
2315 if (h2f2 != NULL) {
2316 smb2_util_close(tree2, *h2f2);
2317 }
2318
2319 smb2_util_unlink(tree1, fname1);
2320 smb2_util_unlink(tree1, fname2);
2321
2322 talloc_free(tree1);
2323
2324 talloc_free(mem_ctx);
2325
2326 return ret;
2327 }
2328
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)
2335 {
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;
2358
2359 encrypted = smb2cli_tcon_is_encryption_on(tree1->smbXcli);
2360
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");
2364 }
2365
2366 /*
2367 * We always want signing for this test!
2368 */
2369 smb2cli_tcon_should_sign(tree1->smbXcli, true);
2370 options2 = transport1->options;
2371 options2.signing = SMB_SIGNING_REQUIRED;
2372
2373 /* Add some random component to the file name. */
2374 snprintf(fname, sizeof(fname), "%s_%s.dat", testname,
2375 generate_random_str(tctx, 8));
2376
2377 smb2_util_unlink(tree1, fname);
2378
2379 smb2_oplock_create_share(&io1, fname,
2380 smb2_util_share_access(""),
2381 smb2_util_oplock_level("b"));
2382
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");
2392
2393 status = smb2_connect(tctx,
2394 host,
2395 share,
2396 tctx->lp_ctx,
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)
2404 );
2405 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
2406 "smb2_connect failed");
2407 session2_2 = tree2->session;
2408 transport2 = tree2->session->transport;
2409
2410 /*
2411 * Now bind the 2nd transport connection to the 1st session
2412 */
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");
2418
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");
2424
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");
2433
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");
2442
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;
2448
2449 /*
2450 * Create a 3rd session in order to check if the invalid (creds2)
2451 * are mapped to guest.
2452 */
2453 session3_1 = smb2_session_init(transport1,
2454 tctx->lp_ctx,
2455 lpcfg_gensec_settings(tctx, tctx->lp_ctx),
2456 tctx);
2457 torture_assert(tctx, session3_1 != NULL, "smb2_session_channel failed");
2458
2459 status = smb2_session_setup_spnego(session3_1,
2460 creds2,
2461 0 /* previous_session_id */);
2462 if (creds2_require_ok) {
2463 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
2464 "smb2_session_setup_spnego worked");
2465 creds2_got_ok = true;
2466 } else if (NT_STATUS_IS_OK(status)) {
2467 bool authentiated = smbXcli_session_is_authenticated(session3_1->smbXcli);
2468 torture_assert(tctx, !authentiated, "Invalid credentials allowed!");
2469 creds2_got_ok = true;
2470 } else {
2471 torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_LOGON_FAILURE, ret, done,
2472 "smb2_session_setup_spnego worked");
2473 }
2474
2475 /*
2476 * Now bind the 1st transport connection to the 2nd session
2477 */
2478 session2_1 = smb2_session_channel(transport1,
2479 lpcfg_gensec_settings(tctx, tctx->lp_ctx),
2480 tree1,
2481 session2_2);
2482 torture_assert(tctx, session2_1 != NULL, "smb2_session_channel failed");
2483
2484 tree2->session = session2_1;
2485 status = smb2_util_unlink(tree2, fname);
2486 torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_USER_SESSION_DELETED, ret, done,
2487 "smb2_util_unlink worked on invalid channel");
2488
2489 status = smb2_session_setup_spnego(session2_1,
2490 creds2,
2491 0 /* previous_session_id */);
2492 if (creds2_got_ok) {
2493 /*
2494 * attaching with a different user (guest or anonymous) results
2495 * in ACCESS_DENIED.
2496 */
2497 torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_ACCESS_DENIED, ret, done,
2498 "smb2_session_setup_spnego worked");
2499 } else {
2500 torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_LOGON_FAILURE, ret, done,
2501 "smb2_session_setup_spnego worked");
2502 }
2503
2504 tree2->session = session2_1;
2505 status = smb2_util_unlink(tree2, fname);
2506 torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_USER_SESSION_DELETED, ret, done,
2507 "smb2_util_unlink worked on invalid channel");
2508
2509 tree2->session = session2_2;
2510 status = smb2_util_unlink(tree2, fname);
2511 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
2512 "smb2_util_unlink failed");
2513 status = smb2_util_unlink(tree2, fname);
2514 torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_OBJECT_NAME_NOT_FOUND, ret, done,
2515 "smb2_util_unlink worked");
2516 if (creds2_got_ok) {
2517 /*
2518 * We got ACCESS_DENIED on the session bind
2519 * with a different user, now check that
2520 * the correct user can actually bind on
2521 * the same connection.
2522 */
2523 TALLOC_FREE(session2_1);
2524 session2_1 = smb2_session_channel(transport1,
2525 lpcfg_gensec_settings(tctx, tctx->lp_ctx),
2526 tree1,
2527 session2_2);
2528 torture_assert(tctx, session2_1 != NULL, "smb2_session_channel failed");
2529
2530 status = smb2_session_setup_spnego(session2_1,
2531 creds1,
2532 0 /* previous_session_id */);
2533 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
2534 "smb2_session_setup_spnego failed");
2535 tree2->session = session2_1;
2536 status = smb2_util_unlink(tree2, fname);
2537 torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_OBJECT_NAME_NOT_FOUND, ret, done,
2538 "smb2_util_unlink worked");
2539 tree2->session = session2_2;
2540 }
2541
2542 tree1->session = session1_1;
2543 status = smb2_util_unlink(tree1, fname);
2544 torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_OBJECT_NAME_NOT_FOUND, ret, done,
2545 "smb2_util_unlink worked");
2546
2547 tree1->session = session1_2;
2548 status = smb2_util_unlink(tree1, fname);
2549 torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_OBJECT_NAME_NOT_FOUND, ret, done,
2550 "smb2_util_unlink worked");
2551
2552 if (creds2_got_ok) {
2553 /*
2554 * With valid credentials, there's no point to test a failing
2555 * reauth.
2556 */
2557 ret = true;
2558 goto done;
2559 }
2560
2561 /*
2562 * Do a failing reauth the 2nd channel
2563 */
2564 status = smb2_session_setup_spnego(session1_2,
2565 creds2,
2566 0 /* previous_session_id */);
2567 torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_LOGON_FAILURE, ret, done,
2568 "smb2_session_setup_spnego worked");
2569
2570 tree1->session = session1_1;
2571 status = smb2_util_unlink(tree1, fname);
2572 if (encrypted) {
2573 torture_assert_goto(tctx, !smbXcli_conn_is_connected(transport1->conn), ret, done,
2574 "smb2_util_unlink worked");
2575 } else {
2576 torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_USER_SESSION_DELETED, ret, done,
2577 "smb2_util_unlink worked");
2578 }
2579
2580 tree1->session = session1_2;
2581 status = smb2_util_unlink(tree1, fname);
2582 if (encrypted) {
2583 torture_assert_goto(tctx, !smbXcli_conn_is_connected(transport2->conn), ret, done,
2584 "smb2_util_unlink worked");
2585 } else {
2586 torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_USER_SESSION_DELETED, ret, done,
2587 "smb2_util_unlink worked");
2588 }
2589
2590 status = smb2_util_unlink(tree2, fname);
2591 if (encrypted) {
2592 torture_assert_goto(tctx, !smbXcli_conn_is_connected(transport1->conn), ret, done,
2593 "smb2_util_unlink worked");
2594 torture_assert_goto(tctx, !smbXcli_conn_is_connected(transport2->conn), ret, done,
2595 "smb2_util_unlink worked");
2596 } else {
2597 torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_OBJECT_NAME_NOT_FOUND, ret, done,
2598 "smb2_util_unlink worked");
2599 }
2600
2601 ret = true;
2602 done:
2603 talloc_free(tree2);
2604 tree1->session = session1_1;
2605
2606 if (h1 != NULL) {
2607 smb2_util_close(tree1, *h1);
2608 }
2609
2610 smb2_util_unlink(tree1, fname);
2611
2612 talloc_free(tree1);
2613
2614 talloc_free(mem_ctx);
2615
2616 return ret;
2617 }
2618
2619 static bool test_session_bind_invalid_auth(struct torture_context *tctx, struct smb2_tree *tree1)
2620 {
2621 struct cli_credentials *credentials = samba_cmdline_get_creds();
2622 struct cli_credentials *invalid_credentials = NULL;
2623 bool ret = false;
2624
2625 invalid_credentials = cli_credentials_init(tctx);
2626 torture_assert(tctx, (invalid_credentials != NULL), "talloc error");
2627 cli_credentials_set_username(invalid_credentials, "__none__invalid__none__", CRED_SPECIFIED);
2628 cli_credentials_set_domain(invalid_credentials, "__none__invalid__none__", CRED_SPECIFIED);
2629 cli_credentials_set_password(invalid_credentials, "__none__invalid__none__", CRED_SPECIFIED);
2630 cli_credentials_set_realm(invalid_credentials, NULL, CRED_SPECIFIED);
2631 cli_credentials_set_workstation(invalid_credentials, "", CRED_UNINITIALISED);
2632
2633 ret = test_session_bind_auth_mismatch(tctx, tree1, __func__,
2634 credentials,
2635 invalid_credentials,
2636 false);
2637 return ret;
2638 }
2639
2640 static bool test_session_bind_different_user(struct torture_context *tctx, struct smb2_tree *tree1)
2641 {
2642 struct cli_credentials *credentials1 = samba_cmdline_get_creds();
2643 struct cli_credentials *credentials2 = torture_user2_credentials(tctx, tctx);
2644 char *u1 = cli_credentials_get_unparsed_name(credentials1, tctx);
2645 char *u2 = cli_credentials_get_unparsed_name(credentials2, tctx);
2646 bool ret = false;
2647 bool bval;
2648
2649 torture_assert(tctx, (credentials2 != NULL), "talloc error");
2650 bval = cli_credentials_is_anonymous(credentials2);
2651 if (bval) {
2652 torture_skip(tctx, "valid user2 credentials are required");
2653 }
2654 bval = strequal(u1, u2);
2655 if (bval) {
2656 torture_skip(tctx, "different user2 credentials are required");
2657 }
2658
2659 ret = test_session_bind_auth_mismatch(tctx, tree1, __func__,
2660 credentials1,
2661 credentials2,
2662 true);
2663 return ret;
2664 }
2665
2666 static bool test_session_bind_negative_smbXtoX(struct torture_context *tctx,
2667 const char *testname,
2668 struct cli_credentials *credentials,
2669 const struct smbcli_options *options1,
2670 const struct smbcli_options *options2,
2671 NTSTATUS bind_reject_status)
2672 {
2673 const char *host = torture_setting_string(tctx, "host", NULL);
2674 const char *share = torture_setting_string(tctx, "share", NULL);
2675 NTSTATUS status;
2676 bool ret = false;
2677 struct smb2_tree *tree1 = NULL;
2678 struct smb2_session *session1_1 = NULL;
2679 char fname[256];
2680 struct smb2_handle _h1;
2681 struct smb2_handle *h1 = NULL;
2682 struct smb2_create io1;
2683 union smb_fileinfo qfinfo1;
2684 struct smb2_tree *tree2_0 = NULL;
2685 struct smb2_transport *transport2 = NULL;
2686 struct smb2_session *session1_2 = NULL;
2687 uint64_t session1_id = 0;
2688 uint16_t session1_flags = 0;
2689 NTSTATUS deleted_status = NT_STATUS_USER_SESSION_DELETED;
2690
2691 status = smb2_connect(tctx,
2692 host,
2693 share,
2694 tctx->lp_ctx,
2695 lpcfg_resolve_context(tctx->lp_ctx),
2696 credentials,
2697 &tree1,
2698 tctx->ev,
2699 options1,
2700 lpcfg_socket_options(tctx->lp_ctx),
2701 lpcfg_gensec_settings(tctx, tctx->lp_ctx)
2702 );
2703 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
2704 "smb2_connect options1 failed");
2705 session1_1 = tree1->session;
2706 session1_id = smb2cli_session_current_id(session1_1->smbXcli);
2707 session1_flags = smb2cli_session_get_flags(session1_1->smbXcli);
2708
2709 /* Add some random component to the file name. */
2710 snprintf(fname, sizeof(fname), "%s_%s.dat",
2711 testname, generate_random_str(tctx, 8));
2712
2713 smb2_util_unlink(tree1, fname);
2714
2715 smb2_oplock_create_share(&io1, fname,
2716 smb2_util_share_access(""),
2717 smb2_util_oplock_level("b"));
2718
2719 io1.in.create_options |= NTCREATEX_OPTIONS_DELETE_ON_CLOSE;
2720 status = smb2_create(tree1, tctx, &io1);
2721 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
2722 "smb2_create failed");
2723 _h1 = io1.out.file.handle;
2724 h1 = &_h1;
2725 CHECK_CREATED(tctx, &io1, CREATED, FILE_ATTRIBUTE_ARCHIVE);
2726 torture_assert_int_equal(tctx, io1.out.oplock_level,
2727 smb2_util_oplock_level("b"),
2728 "oplock_level incorrect");
2729
2730 status = smb2_connect(tctx,
2731 host,
2732 share,
2733 tctx->lp_ctx,
2734 lpcfg_resolve_context(tctx->lp_ctx),
2735 credentials,
2736 &tree2_0,
2737 tctx->ev,
2738 options2,
2739 lpcfg_socket_options(tctx->lp_ctx),
2740 lpcfg_gensec_settings(tctx, tctx->lp_ctx)
2741 );
2742 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
2743 "smb2_connect options2 failed");
2744 transport2 = tree2_0->session->transport;
2745
2746 /*
2747 * Now bind the 2nd transport connection to the 1st session
2748 */
2749 session1_2 = smb2_session_channel(transport2,
2750 lpcfg_gensec_settings(tctx, tctx->lp_ctx),
2751 tree2_0,
2752 session1_1);
2753 torture_assert(tctx, session1_2 != NULL, "smb2_session_channel failed");
2754
2755 status = smb2_session_setup_spnego(session1_2,
2756 credentials,
2757 0 /* previous_session_id */);
2758 torture_assert_ntstatus_equal_goto(tctx, status, bind_reject_status, ret, done,
2759 "smb2_session_setup_spnego failed");
2760 if (NT_STATUS_IS_OK(bind_reject_status)) {
2761 ZERO_STRUCT(qfinfo1);
2762 qfinfo1.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
2763 qfinfo1.generic.in.file.handle = _h1;
2764 tree1->session = session1_2;
2765 status = smb2_getinfo_file(tree1, tctx, &qfinfo1);
2766 tree1->session = session1_1;
2767 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
2768 "smb2_getinfo_file failed");
2769 }
2770 TALLOC_FREE(session1_2);
2771
2772 /* Check the initial session is still alive */
2773 ZERO_STRUCT(qfinfo1);
2774 qfinfo1.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
2775 qfinfo1.generic.in.file.handle = _h1;
2776 status = smb2_getinfo_file(tree1, tctx, &qfinfo1);
2777 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
2778 "smb2_getinfo_file failed");
2779
2780 if (NT_STATUS_IS_OK(bind_reject_status)) {
2781 deleted_status = NT_STATUS_ACCESS_DENIED;
2782 bind_reject_status = NT_STATUS_ACCESS_DENIED;
2783 }
2784
2785 /*
2786 * I guess this is not part of MultipleChannel_Negative_SMB2002,
2787 * but we should also check the status without
2788 * SMB2_SESSION_FLAG_BINDING.
2789 */
2790 session1_2 = smb2_session_channel(transport2,
2791 lpcfg_gensec_settings(tctx, tctx->lp_ctx),
2792 tree2_0,
2793 session1_1);
2794 torture_assert(tctx, session1_2 != NULL, "smb2_session_channel failed");
2795 session1_2->needs_bind = false;
2796
2797 status = smb2_session_setup_spnego(session1_2,
2798 credentials,
2799 0 /* previous_session_id */);
2800 torture_assert_ntstatus_equal_goto(tctx, status, deleted_status, ret, done,
2801 "smb2_session_setup_spnego failed");
2802 TALLOC_FREE(session1_2);
2803
2804 /*
2805 * ... and we should also check the status without any existing
2806 * session keys.
2807 */
2808 session1_2 = smb2_session_init(transport2,
2809 tctx->lp_ctx,
2810 lpcfg_gensec_settings(tctx, tctx->lp_ctx),
2811 tree2_0);
2812 torture_assert(tctx, session1_2 != NULL, "smb2_session_channel failed");
2813 talloc_steal(tree2_0->session, transport2);
2814 smb2cli_session_set_id_and_flags(session1_2->smbXcli,
2815 session1_id, session1_flags);
2816
2817 status = smb2_session_setup_spnego(session1_2,
2818 credentials,
2819 0 /* previous_session_id */);
2820 torture_assert_ntstatus_equal_goto(tctx, status, deleted_status, ret, done,
2821 "smb2_session_setup_spnego failed");
2822 TALLOC_FREE(session1_2);
2823
2824 /* Check the initial session is still alive */
2825 ZERO_STRUCT(qfinfo1);
2826 qfinfo1.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
2827 qfinfo1.generic.in.file.handle = _h1;
2828 status = smb2_getinfo_file(tree1, tctx, &qfinfo1);
2829 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
2830 "smb2_getinfo_file failed");
2831
2832 /*
2833 * Now bind the 2nd transport connection to the 1st session (again)
2834 */
2835 session1_2 = smb2_session_channel(transport2,
2836 lpcfg_gensec_settings(tctx, tctx->lp_ctx),
2837 tree2_0,
2838 session1_1);
2839 torture_assert(tctx, session1_2 != NULL, "smb2_session_channel failed");
2840
2841 status = smb2_session_setup_spnego(session1_2,
2842 credentials,
2843 0 /* previous_session_id */);
2844 torture_assert_ntstatus_equal_goto(tctx, status, bind_reject_status, ret, done,
2845 "smb2_session_setup_spnego failed");
2846 TALLOC_FREE(session1_2);
2847
2848 /* Check the initial session is still alive */
2849 ZERO_STRUCT(qfinfo1);
2850 qfinfo1.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
2851 qfinfo1.generic.in.file.handle = _h1;
2852 status = smb2_getinfo_file(tree1, tctx, &qfinfo1);
2853 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
2854 "smb2_getinfo_file failed");
2855
2856 ret = true;
2857 done:
2858 talloc_free(tree2_0);
2859 if (h1 != NULL) {
2860 smb2_util_close(tree1, *h1);
2861 }
2862 talloc_free(tree1);
2863
2864 return ret;
2865 }
2866
2867 /*
2868 * This is similar to the MultipleChannel_Negative_SMB2002 test
2869 * from the Windows Protocol Test Suite.
2870 *
2871 * It demonstrates that the server needs to do lookup
2872 * in the global session table in order to get the signing
2873 * and error code of invalid session setups correct.
2874 *
2875 * See: https://bugzilla.samba.org/show_bug.cgi?id=14512
2876 *
2877 * Note you can ignore tree0...
2878 */
2879 static bool test_session_bind_negative_smb202(struct torture_context *tctx, struct smb2_tree *tree0)
2880 {
2881 struct cli_credentials *credentials = samba_cmdline_get_creds();
2882 bool ret = false;
2883 struct smb2_transport *transport0 = tree0->session->transport;
2884 struct smbcli_options options1;
2885 struct smbcli_options options2;
2886 bool encrypted;
2887
2888 encrypted = smb2cli_tcon_is_encryption_on(tree0->smbXcli);
2889 if (encrypted) {
2890 torture_skip(tctx,
2891 "Can't test SMB 2.02 if encryption is required");
2892 }
2893
2894 options1 = transport0->options;
2895 options1.client_guid = GUID_zero();
2896 options1.max_protocol = PROTOCOL_SMB2_02;
2897
2898 options2 = options1;
2899 options2.only_negprot = true;
2900
2901 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
2902 credentials,
2903 &options1, &options2,
2904 NT_STATUS_REQUEST_NOT_ACCEPTED);
2905 talloc_free(tree0);
2906 return ret;
2907 }
2908
2909 static bool test_session_bind_negative_smb210s(struct torture_context *tctx, struct smb2_tree *tree0)
2910 {
2911 struct cli_credentials *credentials = samba_cmdline_get_creds();
2912 bool ret = false;
2913 struct smb2_transport *transport0 = tree0->session->transport;
2914 struct smbcli_options options1;
2915 struct smbcli_options options2;
2916 bool encrypted;
2917
2918 encrypted = smb2cli_tcon_is_encryption_on(tree0->smbXcli);
2919 if (encrypted) {
2920 torture_skip(tctx,
2921 "Can't test SMB 2.10 if encryption is required");
2922 }
2923
2924 options1 = transport0->options;
2925 options1.client_guid = GUID_random();
2926 options1.max_protocol = PROTOCOL_SMB2_10;
2927
2928 /* same client guid */
2929 options2 = options1;
2930 options2.only_negprot = true;
2931
2932 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
2933 credentials,
2934 &options1, &options2,
2935 NT_STATUS_REQUEST_NOT_ACCEPTED);
2936 talloc_free(tree0);
2937 return ret;
2938 }
2939
2940 static bool test_session_bind_negative_smb210d(struct torture_context *tctx, struct smb2_tree *tree0)
2941 {
2942 struct cli_credentials *credentials = samba_cmdline_get_creds();
2943 bool ret = false;
2944 struct smb2_transport *transport0 = tree0->session->transport;
2945 struct smbcli_options options1;
2946 struct smbcli_options options2;
2947 bool encrypted;
2948
2949 encrypted = smb2cli_tcon_is_encryption_on(tree0->smbXcli);
2950 if (encrypted) {
2951 torture_skip(tctx,
2952 "Can't test SMB 2.10 if encryption is required");
2953 }
2954
2955 options1 = transport0->options;
2956 options1.client_guid = GUID_random();
2957 options1.max_protocol = PROTOCOL_SMB2_10;
2958
2959 /* different client guid */
2960 options2 = options1;
2961 options2.client_guid = GUID_random();
2962 options2.only_negprot = true;
2963
2964 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
2965 credentials,
2966 &options1, &options2,
2967 NT_STATUS_REQUEST_NOT_ACCEPTED);
2968 talloc_free(tree0);
2969 return ret;
2970 }
2971
2972 static bool test_session_bind_negative_smb2to3s(struct torture_context *tctx, struct smb2_tree *tree0)
2973 {
2974 struct cli_credentials *credentials = samba_cmdline_get_creds();
2975 bool ret = false;
2976 struct smb2_transport *transport0 = tree0->session->transport;
2977 struct smbcli_options options1;
2978 struct smbcli_options options2;
2979 bool encrypted;
2980
2981 encrypted = smb2cli_tcon_is_encryption_on(tree0->smbXcli);
2982 if (encrypted) {
2983 torture_skip(tctx,
2984 "Can't test SMB 2.10 if encryption is required");
2985 }
2986
2987 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_00) {
2988 torture_skip(tctx,
2989 "Can't test without SMB3 support");
2990 }
2991
2992 options1 = transport0->options;
2993 options1.client_guid = GUID_random();
2994 options1.min_protocol = PROTOCOL_SMB2_02;
2995 options1.max_protocol = PROTOCOL_SMB2_10;
2996
2997 /* same client guid */
2998 options2 = options1;
2999 options2.only_negprot = true;
3000 options2.min_protocol = PROTOCOL_SMB3_00;
3001 options2.max_protocol = PROTOCOL_SMB3_11;
3002 options2.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
3003 .num_algos = 1,
3004 .algos = {
3005 SMB2_SIGNING_AES128_CMAC,
3006 },
3007 };
3008
3009 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
3010 credentials,
3011 &options1, &options2,
3012 NT_STATUS_INVALID_PARAMETER);
3013 talloc_free(tree0);
3014 return ret;
3015 }
3016
3017 static bool test_session_bind_negative_smb2to3d(struct torture_context *tctx, struct smb2_tree *tree0)
3018 {
3019 struct cli_credentials *credentials = samba_cmdline_get_creds();
3020 bool ret = false;
3021 struct smb2_transport *transport0 = tree0->session->transport;
3022 struct smbcli_options options1;
3023 struct smbcli_options options2;
3024 bool encrypted;
3025
3026 encrypted = smb2cli_tcon_is_encryption_on(tree0->smbXcli);
3027 if (encrypted) {
3028 torture_skip(tctx,
3029 "Can't test SMB 2.10 if encryption is required");
3030 }
3031
3032 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_00) {
3033 torture_skip(tctx,
3034 "Can't test without SMB3 support");
3035 }
3036
3037 options1 = transport0->options;
3038 options1.client_guid = GUID_random();
3039 options1.min_protocol = PROTOCOL_SMB2_02;
3040 options1.max_protocol = PROTOCOL_SMB2_10;
3041
3042 /* different client guid */
3043 options2 = options1;
3044 options2.client_guid = GUID_random();
3045 options2.only_negprot = true;
3046 options2.min_protocol = PROTOCOL_SMB3_00;
3047 options2.max_protocol = PROTOCOL_SMB3_11;
3048 options2.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
3049 .num_algos = 1,
3050 .algos = {
3051 SMB2_SIGNING_AES128_CMAC,
3052 },
3053 };
3054
3055 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
3056 credentials,
3057 &options1, &options2,
3058 NT_STATUS_INVALID_PARAMETER);
3059 talloc_free(tree0);
3060 return ret;
3061 }
3062
3063 static bool test_session_bind_negative_smb3to2s(struct torture_context *tctx, struct smb2_tree *tree0)
3064 {
3065 struct cli_credentials *credentials = samba_cmdline_get_creds();
3066 bool ret = false;
3067 struct smb2_transport *transport0 = tree0->session->transport;
3068 struct smbcli_options options1;
3069 struct smbcli_options options2;
3070 bool encrypted;
3071
3072 encrypted = smb2cli_tcon_is_encryption_on(tree0->smbXcli);
3073 if (encrypted) {
3074 torture_skip(tctx,
3075 "Can't test SMB 2.10 if encryption is required");
3076 }
3077
3078 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_00) {
3079 torture_skip(tctx,
3080 "Can't test without SMB3 support");
3081 }
3082
3083 options1 = transport0->options;
3084 options1.client_guid = GUID_random();
3085 options1.min_protocol = PROTOCOL_SMB3_00;
3086 options1.max_protocol = PROTOCOL_SMB3_11;
3087 options1.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
3088 .num_algos = 1,
3089 .algos = {
3090 SMB2_SIGNING_AES128_CMAC,
3091 },
3092 };
3093
3094 /* same client guid */
3095 options2 = options1;
3096 options2.only_negprot = true;
3097 options2.min_protocol = PROTOCOL_SMB2_02;
3098 options2.max_protocol = PROTOCOL_SMB2_10;
3099 options2.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
3100 .num_algos = 1,
3101 .algos = {
3102 SMB2_SIGNING_HMAC_SHA256,
3103 },
3104 };
3105
3106 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
3107 credentials,
3108 &options1, &options2,
3109 NT_STATUS_REQUEST_NOT_ACCEPTED);
3110 talloc_free(tree0);
3111 return ret;
3112 }
3113
3114 static bool test_session_bind_negative_smb3to2d(struct torture_context *tctx, struct smb2_tree *tree0)
3115 {
3116 struct cli_credentials *credentials = samba_cmdline_get_creds();
3117 bool ret = false;
3118 struct smb2_transport *transport0 = tree0->session->transport;
3119 struct smbcli_options options1;
3120 struct smbcli_options options2;
3121 bool encrypted;
3122
3123 encrypted = smb2cli_tcon_is_encryption_on(tree0->smbXcli);
3124 if (encrypted) {
3125 torture_skip(tctx,
3126 "Can't test SMB 2.10 if encryption is required");
3127 }
3128
3129 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_00) {
3130 torture_skip(tctx,
3131 "Can't test without SMB3 support");
3132 }
3133
3134 options1 = transport0->options;
3135 options1.client_guid = GUID_random();
3136 options1.min_protocol = PROTOCOL_SMB3_00;
3137 options1.max_protocol = PROTOCOL_SMB3_11;
3138 options1.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
3139 .num_algos = 1,
3140 .algos = {
3141 SMB2_SIGNING_AES128_CMAC,
3142 },
3143 };
3144
3145 /* different client guid */
3146 options2 = options1;
3147 options2.client_guid = GUID_random();
3148 options2.only_negprot = true;
3149 options2.min_protocol = PROTOCOL_SMB2_02;
3150 options2.max_protocol = PROTOCOL_SMB2_10;
3151 options2.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
3152 .num_algos = 1,
3153 .algos = {
3154 SMB2_SIGNING_HMAC_SHA256,
3155 },
3156 };
3157
3158 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
3159 credentials,
3160 &options1, &options2,
3161 NT_STATUS_REQUEST_NOT_ACCEPTED);
3162 talloc_free(tree0);
3163 return ret;
3164 }
3165
3166 static bool test_session_bind_negative_smb3to3s(struct torture_context *tctx, struct smb2_tree *tree0)
3167 {
3168 struct cli_credentials *credentials = samba_cmdline_get_creds();
3169 bool ret = false;
3170 struct smb2_transport *transport0 = tree0->session->transport;
3171 struct smbcli_options options1;
3172 struct smbcli_options options2;
3173
3174 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
3175 torture_skip(tctx,
3176 "Can't test without SMB 3.1.1 support");
3177 }
3178
3179 options1 = transport0->options;
3180 options1.client_guid = GUID_random();
3181 options1.min_protocol = PROTOCOL_SMB3_02;
3182 options1.max_protocol = PROTOCOL_SMB3_02;
3183
3184 /* same client guid */
3185 options2 = options1;
3186 options2.only_negprot = true;
3187 options2.min_protocol = PROTOCOL_SMB3_11;
3188 options2.max_protocol = PROTOCOL_SMB3_11;
3189 options2.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
3190 .num_algos = 1,
3191 .algos = {
3192 SMB2_SIGNING_AES128_CMAC,
3193 },
3194 };
3195
3196 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
3197 credentials,
3198 &options1, &options2,
3199 NT_STATUS_INVALID_PARAMETER);
3200 talloc_free(tree0);
3201 return ret;
3202 }
3203
3204 static bool test_session_bind_negative_smb3to3d(struct torture_context *tctx, struct smb2_tree *tree0)
3205 {
3206 struct cli_credentials *credentials = samba_cmdline_get_creds();
3207 bool ret = false;
3208 struct smb2_transport *transport0 = tree0->session->transport;
3209 struct smbcli_options options1;
3210 struct smbcli_options options2;
3211
3212 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
3213 torture_skip(tctx,
3214 "Can't test without SMB 3.1.1 support");
3215 }
3216
3217 options1 = transport0->options;
3218 options1.client_guid = GUID_random();
3219 options1.min_protocol = PROTOCOL_SMB3_02;
3220 options1.max_protocol = PROTOCOL_SMB3_02;
3221
3222 /* different client guid */
3223 options2 = options1;
3224 options2.client_guid = GUID_random();
3225 options2.only_negprot = true;
3226 options2.min_protocol = PROTOCOL_SMB3_11;
3227 options2.max_protocol = PROTOCOL_SMB3_11;
3228 options2.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
3229 .num_algos = 1,
3230 .algos = {
3231 SMB2_SIGNING_AES128_CMAC,
3232 },
3233 };
3234
3235 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
3236 credentials,
3237 &options1, &options2,
3238 NT_STATUS_INVALID_PARAMETER);
3239 talloc_free(tree0);
3240 return ret;
3241 }
3242
3243 static bool test_session_bind_negative_smb3encGtoCs(struct torture_context *tctx, struct smb2_tree *tree0)
3244 {
3245 struct cli_credentials *credentials0 = samba_cmdline_get_creds();
3246 struct cli_credentials *credentials = NULL;
3247 bool ret = false;
3248 struct smb2_transport *transport0 = tree0->session->transport;
3249 struct smbcli_options options1;
3250 struct smbcli_options options2;
3251 bool ok;
3252
3253 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
3254 torture_skip(tctx,
3255 "Can't test without SMB 3.1.1 support");
3256 }
3257
3258 credentials = cli_credentials_shallow_copy(tctx, credentials0);
3259 torture_assert(tctx, credentials != NULL, "cli_credentials_shallow_copy");
3260 ok = cli_credentials_set_smb_encryption(credentials,
3261 SMB_ENCRYPTION_REQUIRED,
3262 CRED_SPECIFIED);
3263 torture_assert(tctx, ok, "cli_credentials_set_smb_encryption");
3264
3265 options1 = transport0->options;
3266 options1.client_guid = GUID_random();
3267 options1.min_protocol = PROTOCOL_SMB3_11;
3268 options1.max_protocol = PROTOCOL_SMB3_11;
3269 options1.signing = SMB_SIGNING_REQUIRED;
3270 options1.smb3_capabilities.encryption = (struct smb3_encryption_capabilities) {
3271 .num_algos = 1,
3272 .algos = {
3273 SMB2_ENCRYPTION_AES128_GCM,
3274 },
3275 };
3276
3277 /* same client guid */
3278 options2 = options1;
3279 options2.only_negprot = true;
3280 options2.smb3_capabilities.encryption = (struct smb3_encryption_capabilities) {
3281 .num_algos = 1,
3282 .algos = {
3283 SMB2_ENCRYPTION_AES128_CCM,
3284 },
3285 };
3286
3287 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
3288 credentials,
3289 &options1, &options2,
3290 NT_STATUS_INVALID_PARAMETER);
3291 talloc_free(tree0);
3292 return ret;
3293 }
3294
3295 static bool test_session_bind_negative_smb3encGtoCd(struct torture_context *tctx, struct smb2_tree *tree0)
3296 {
3297 struct cli_credentials *credentials0 = samba_cmdline_get_creds();
3298 struct cli_credentials *credentials = NULL;
3299 bool ret = false;
3300 struct smb2_transport *transport0 = tree0->session->transport;
3301 struct smbcli_options options1;
3302 struct smbcli_options options2;
3303 bool ok;
3304
3305 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
3306 torture_skip(tctx,
3307 "Can't test without SMB 3.1.1 support");
3308 }
3309
3310 credentials = cli_credentials_shallow_copy(tctx, credentials0);
3311 torture_assert(tctx, credentials != NULL, "cli_credentials_shallow_copy");
3312 ok = cli_credentials_set_smb_encryption(credentials,
3313 SMB_ENCRYPTION_REQUIRED,
3314 CRED_SPECIFIED);
3315 torture_assert(tctx, ok, "cli_credentials_set_smb_encryption");
3316
3317 options1 = transport0->options;
3318 options1.client_guid = GUID_random();
3319 options1.min_protocol = PROTOCOL_SMB3_11;
3320 options1.max_protocol = PROTOCOL_SMB3_11;
3321 options1.signing = SMB_SIGNING_REQUIRED;
3322 options1.smb3_capabilities.encryption = (struct smb3_encryption_capabilities) {
3323 .num_algos = 1,
3324 .algos = {
3325 SMB2_ENCRYPTION_AES128_GCM,
3326 },
3327 };
3328
3329 /* different client guid */
3330 options2 = options1;
3331 options2.client_guid = GUID_random();
3332 options2.only_negprot = true;
3333 options2.smb3_capabilities.encryption = (struct smb3_encryption_capabilities) {
3334 .num_algos = 1,
3335 .algos = {
3336 SMB2_ENCRYPTION_AES128_CCM,
3337 },
3338 };
3339
3340 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
3341 credentials,
3342 &options1, &options2,
3343 NT_STATUS_INVALID_PARAMETER);
3344 talloc_free(tree0);
3345 return ret;
3346 }
3347
3348 static bool test_session_bind_negative_smb3signCtoHs(struct torture_context *tctx, struct smb2_tree *tree0)
3349 {
3350 struct cli_credentials *credentials0 = samba_cmdline_get_creds();
3351 struct cli_credentials *credentials = NULL;
3352 bool ret = false;
3353 struct smb2_transport *transport0 = tree0->session->transport;
3354 struct smbcli_options options1;
3355 struct smbcli_options options2;
3356 bool ok;
3357
3358 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
3359 torture_skip(tctx,
3360 "Can't test without SMB 3.1.1 support");
3361 }
3362
3363 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
3364 torture_skip(tctx,
3365 "Can't test without SMB 3.1.1 signing negotiation support");
3366 }
3367
3368 credentials = cli_credentials_shallow_copy(tctx, credentials0);
3369 torture_assert(tctx, credentials != NULL, "cli_credentials_shallow_copy");
3370 ok = cli_credentials_set_smb_encryption(credentials,
3371 SMB_ENCRYPTION_REQUIRED,
3372 CRED_SPECIFIED);
3373 torture_assert(tctx, ok, "cli_credentials_set_smb_encryption");
3374
3375 options1 = transport0->options;
3376 options1.client_guid = GUID_random();
3377 options1.min_protocol = PROTOCOL_SMB3_11;
3378 options1.max_protocol = PROTOCOL_SMB3_11;
3379 options1.signing = SMB_SIGNING_REQUIRED;
3380 options1.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
3381 .num_algos = 1,
3382 .algos = {
3383 SMB2_SIGNING_AES128_CMAC,
3384 },
3385 };
3386
3387 /* same client guid */
3388 options2 = options1;
3389 options2.only_negprot = true;
3390 options2.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
3391 .num_algos = 1,
3392 .algos = {
3393 SMB2_SIGNING_HMAC_SHA256,
3394 },
3395 };
3396
3397 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
3398 credentials,
3399 &options1, &options2,
3400 NT_STATUS_OK);
3401 talloc_free(tree0);
3402 return ret;
3403 }
3404
3405 static bool test_session_bind_negative_smb3signCtoHd(struct torture_context *tctx, struct smb2_tree *tree0)
3406 {
3407 struct cli_credentials *credentials0 = samba_cmdline_get_creds();
3408 struct cli_credentials *credentials = NULL;
3409 bool ret = false;
3410 struct smb2_transport *transport0 = tree0->session->transport;
3411 struct smbcli_options options1;
3412 struct smbcli_options options2;
3413 bool ok;
3414
3415 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
3416 torture_skip(tctx,
3417 "Can't test without SMB 3.1.1 support");
3418 }
3419
3420 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
3421 torture_skip(tctx,
3422 "Can't test without SMB 3.1.1 signing negotiation support");
3423 }
3424
3425 credentials = cli_credentials_shallow_copy(tctx, credentials0);
3426 torture_assert(tctx, credentials != NULL, "cli_credentials_shallow_copy");
3427 ok = cli_credentials_set_smb_encryption(credentials,
3428 SMB_ENCRYPTION_REQUIRED,
3429 CRED_SPECIFIED);
3430 torture_assert(tctx, ok, "cli_credentials_set_smb_encryption");
3431
3432 options1 = transport0->options;
3433 options1.client_guid = GUID_random();
3434 options1.min_protocol = PROTOCOL_SMB3_11;
3435 options1.max_protocol = PROTOCOL_SMB3_11;
3436 options1.signing = SMB_SIGNING_REQUIRED;
3437 options1.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
3438 .num_algos = 1,
3439 .algos = {
3440 SMB2_SIGNING_AES128_CMAC,
3441 },
3442 };
3443
3444 /* different client guid */
3445 options2 = options1;
3446 options2.client_guid = GUID_random();
3447 options2.only_negprot = true;
3448 options2.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
3449 .num_algos = 1,
3450 .algos = {
3451 SMB2_SIGNING_HMAC_SHA256,
3452 },
3453 };
3454
3455 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
3456 credentials,
3457 &options1, &options2,
3458 NT_STATUS_OK);
3459 talloc_free(tree0);
3460 return ret;
3461 }
3462
3463 static bool test_session_bind_negative_smb3signHtoCs(struct torture_context *tctx, struct smb2_tree *tree0)
3464 {
3465 struct cli_credentials *credentials0 = samba_cmdline_get_creds();
3466 struct cli_credentials *credentials = NULL;
3467 bool ret = false;
3468 struct smb2_transport *transport0 = tree0->session->transport;
3469 struct smbcli_options options1;
3470 struct smbcli_options options2;
3471 bool ok;
3472
3473 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
3474 torture_skip(tctx,
3475 "Can't test without SMB 3.1.1 support");
3476 }
3477
3478 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
3479 torture_skip(tctx,
3480 "Can't test without SMB 3.1.1 signing negotiation support");
3481 }
3482
3483 credentials = cli_credentials_shallow_copy(tctx, credentials0);
3484 torture_assert(tctx, credentials != NULL, "cli_credentials_shallow_copy");
3485 ok = cli_credentials_set_smb_encryption(credentials,
3486 SMB_ENCRYPTION_REQUIRED,
3487 CRED_SPECIFIED);
3488 torture_assert(tctx, ok, "cli_credentials_set_smb_encryption");
3489
3490 options1 = transport0->options;
3491 options1.client_guid = GUID_random();
3492 options1.min_protocol = PROTOCOL_SMB3_11;
3493 options1.max_protocol = PROTOCOL_SMB3_11;
3494 options1.signing = SMB_SIGNING_REQUIRED;
3495 options1.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
3496 .num_algos = 1,
3497 .algos = {
3498 SMB2_SIGNING_HMAC_SHA256,
3499 },
3500 };
3501
3502 /* same client guid */
3503 options2 = options1;
3504 options2.only_negprot = true;
3505 options2.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
3506 .num_algos = 1,
3507 .algos = {
3508 SMB2_SIGNING_AES128_CMAC,
3509 },
3510 };
3511
3512 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
3513 credentials,
3514 &options1, &options2,
3515 NT_STATUS_OK);
3516 talloc_free(tree0);
3517 return ret;
3518 }
3519
3520 static bool test_session_bind_negative_smb3signHtoCd(struct torture_context *tctx, struct smb2_tree *tree0)
3521 {
3522 struct cli_credentials *credentials0 = samba_cmdline_get_creds();
3523 struct cli_credentials *credentials = NULL;
3524 bool ret = false;
3525 struct smb2_transport *transport0 = tree0->session->transport;
3526 struct smbcli_options options1;
3527 struct smbcli_options options2;
3528 bool ok;
3529
3530 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
3531 torture_skip(tctx,
3532 "Can't test without SMB 3.1.1 support");
3533 }
3534
3535 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
3536 torture_skip(tctx,
3537 "Can't test without SMB 3.1.1 signing negotiation support");
3538 }
3539
3540 credentials = cli_credentials_shallow_copy(tctx, credentials0);
3541 torture_assert(tctx, credentials != NULL, "cli_credentials_shallow_copy");
3542 ok = cli_credentials_set_smb_encryption(credentials,
3543 SMB_ENCRYPTION_REQUIRED,
3544 CRED_SPECIFIED);
3545 torture_assert(tctx, ok, "cli_credentials_set_smb_encryption");
3546
3547 options1 = transport0->options;
3548 options1.client_guid = GUID_random();
3549 options1.min_protocol = PROTOCOL_SMB3_11;
3550 options1.max_protocol = PROTOCOL_SMB3_11;
3551 options1.signing = SMB_SIGNING_REQUIRED;
3552 options1.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
3553 .num_algos = 1,
3554 .algos = {
3555 SMB2_SIGNING_HMAC_SHA256,
3556 },
3557 };
3558
3559 /* different client guid */
3560 options2 = options1;
3561 options2.client_guid = GUID_random();
3562 options2.only_negprot = true;
3563 options2.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
3564 .num_algos = 1,
3565 .algos = {
3566 SMB2_SIGNING_AES128_CMAC,
3567 },
3568 };
3569
3570 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
3571 credentials,
3572 &options1, &options2,
3573 NT_STATUS_OK);
3574 talloc_free(tree0);
3575 return ret;
3576 }
3577
3578 static bool test_session_bind_negative_smb3signHtoGs(struct torture_context *tctx, struct smb2_tree *tree0)
3579 {
3580 struct cli_credentials *credentials0 = samba_cmdline_get_creds();
3581 struct cli_credentials *credentials = NULL;
3582 bool ret = false;
3583 struct smb2_transport *transport0 = tree0->session->transport;
3584 struct smbcli_options options1;
3585 struct smbcli_options options2;
3586 bool ok;
3587
3588 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
3589 torture_skip(tctx,
3590 "Can't test without SMB 3.1.1 support");
3591 }
3592
3593 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
3594 torture_skip(tctx,
3595 "Can't test without SMB 3.1.1 signing negotiation support");
3596 }
3597
3598 credentials = cli_credentials_shallow_copy(tctx, credentials0);
3599 torture_assert(tctx, credentials != NULL, "cli_credentials_shallow_copy");
3600 ok = cli_credentials_set_smb_encryption(credentials,
3601 SMB_ENCRYPTION_REQUIRED,
3602 CRED_SPECIFIED);
3603 torture_assert(tctx, ok, "cli_credentials_set_smb_encryption");
3604
3605 options1 = transport0->options;
3606 options1.client_guid = GUID_random();
3607 options1.min_protocol = PROTOCOL_SMB3_11;
3608 options1.max_protocol = PROTOCOL_SMB3_11;
3609 options1.signing = SMB_SIGNING_REQUIRED;
3610 options1.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
3611 .num_algos = 1,
3612 .algos = {
3613 SMB2_SIGNING_HMAC_SHA256,
3614 },
3615 };
3616
3617 /* same client guid */
3618 options2 = options1;
3619 options2.only_negprot = true;
3620 options2.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
3621 .num_algos = 1,
3622 .algos = {
3623 SMB2_SIGNING_AES128_GMAC,
3624 },
3625 };
3626
3627 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
3628 credentials,
3629 &options1, &options2,
3630 NT_STATUS_NOT_SUPPORTED);
3631 talloc_free(tree0);
3632 return ret;
3633 }
3634
3635 static bool test_session_bind_negative_smb3signHtoGd(struct torture_context *tctx, struct smb2_tree *tree0)
3636 {
3637 struct cli_credentials *credentials0 = samba_cmdline_get_creds();
3638 struct cli_credentials *credentials = NULL;
3639 bool ret = false;
3640 struct smb2_transport *transport0 = tree0->session->transport;
3641 struct smbcli_options options1;
3642 struct smbcli_options options2;
3643 bool ok;
3644
3645 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
3646 torture_skip(tctx,
3647 "Can't test without SMB 3.1.1 support");
3648 }
3649
3650 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
3651 torture_skip(tctx,
3652 "Can't test without SMB 3.1.1 signing negotiation support");
3653 }
3654
3655 credentials = cli_credentials_shallow_copy(tctx, credentials0);
3656 torture_assert(tctx, credentials != NULL, "cli_credentials_shallow_copy");
3657 ok = cli_credentials_set_smb_encryption(credentials,
3658 SMB_ENCRYPTION_REQUIRED,
3659 CRED_SPECIFIED);
3660 torture_assert(tctx, ok, "cli_credentials_set_smb_encryption");
3661
3662 options1 = transport0->options;
3663 options1.client_guid = GUID_random();
3664 options1.min_protocol = PROTOCOL_SMB3_11;
3665 options1.max_protocol = PROTOCOL_SMB3_11;
3666 options1.signing = SMB_SIGNING_REQUIRED;
3667 options1.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
3668 .num_algos = 1,
3669 .algos = {
3670 SMB2_SIGNING_HMAC_SHA256,
3671 },
3672 };
3673
3674 /* different client guid */
3675 options2 = options1;
3676 options2.client_guid = GUID_random();
3677 options2.only_negprot = true;
3678 options2.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
3679 .num_algos = 1,
3680 .algos = {
3681 SMB2_SIGNING_AES128_GMAC,
3682 },
3683 };
3684
3685 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
3686 credentials,
3687 &options1, &options2,
3688 NT_STATUS_NOT_SUPPORTED);
3689 talloc_free(tree0);
3690 return ret;
3691 }
3692
3693 static bool test_session_bind_negative_smb3signCtoGs(struct torture_context *tctx, struct smb2_tree *tree0)
3694 {
3695 struct cli_credentials *credentials0 = samba_cmdline_get_creds();
3696 struct cli_credentials *credentials = NULL;
3697 bool ret = false;
3698 struct smb2_transport *transport0 = tree0->session->transport;
3699 struct smbcli_options options1;
3700 struct smbcli_options options2;
3701 bool ok;
3702
3703 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
3704 torture_skip(tctx,
3705 "Can't test without SMB 3.1.1 support");
3706 }
3707
3708 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
3709 torture_skip(tctx,
3710 "Can't test without SMB 3.1.1 signing negotiation support");
3711 }
3712
3713 credentials = cli_credentials_shallow_copy(tctx, credentials0);
3714 torture_assert(tctx, credentials != NULL, "cli_credentials_shallow_copy");
3715 ok = cli_credentials_set_smb_encryption(credentials,
3716 SMB_ENCRYPTION_REQUIRED,
3717 CRED_SPECIFIED);
3718 torture_assert(tctx, ok, "cli_credentials_set_smb_encryption");
3719
3720 options1 = transport0->options;
3721 options1.client_guid = GUID_random();
3722 options1.min_protocol = PROTOCOL_SMB3_11;
3723 options1.max_protocol = PROTOCOL_SMB3_11;
3724 options1.signing = SMB_SIGNING_REQUIRED;
3725 options1.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
3726 .num_algos = 1,
3727 .algos = {
3728 SMB2_SIGNING_AES128_CMAC,
3729 },
3730 };
3731
3732 /* same client guid */
3733 options2 = options1;
3734 options2.only_negprot = true;
3735 options2.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
3736 .num_algos = 1,
3737 .algos = {
3738 SMB2_SIGNING_AES128_GMAC,
3739 },
3740 };
3741
3742 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
3743 credentials,
3744 &options1, &options2,
3745 NT_STATUS_NOT_SUPPORTED);
3746 talloc_free(tree0);
3747 return ret;
3748 }
3749
3750 static bool test_session_bind_negative_smb3signCtoGd(struct torture_context *tctx, struct smb2_tree *tree0)
3751 {
3752 struct cli_credentials *credentials0 = samba_cmdline_get_creds();
3753 struct cli_credentials *credentials = NULL;
3754 bool ret = false;
3755 struct smb2_transport *transport0 = tree0->session->transport;
3756 struct smbcli_options options1;
3757 struct smbcli_options options2;
3758 bool ok;
3759
3760 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
3761 torture_skip(tctx,
3762 "Can't test without SMB 3.1.1 support");
3763 }
3764
3765 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
3766 torture_skip(tctx,
3767 "Can't test without SMB 3.1.1 signing negotiation support");
3768 }
3769
3770 credentials = cli_credentials_shallow_copy(tctx, credentials0);
3771 torture_assert(tctx, credentials != NULL, "cli_credentials_shallow_copy");
3772 ok = cli_credentials_set_smb_encryption(credentials,
3773 SMB_ENCRYPTION_REQUIRED,
3774 CRED_SPECIFIED);
3775 torture_assert(tctx, ok, "cli_credentials_set_smb_encryption");
3776
3777 options1 = transport0->options;
3778 options1.client_guid = GUID_random();
3779 options1.min_protocol = PROTOCOL_SMB3_11;
3780 options1.max_protocol = PROTOCOL_SMB3_11;
3781 options1.signing = SMB_SIGNING_REQUIRED;
3782 options1.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
3783 .num_algos = 1,
3784 .algos = {
3785 SMB2_SIGNING_AES128_CMAC,
3786 },
3787 };
3788
3789 /* different client guid */
3790 options2 = options1;
3791 options2.client_guid = GUID_random();
3792 options2.only_negprot = true;
3793 options2.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
3794 .num_algos = 1,
3795 .algos = {
3796 SMB2_SIGNING_AES128_GMAC,
3797 },
3798 };
3799
3800 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
3801 credentials,
3802 &options1, &options2,
3803 NT_STATUS_NOT_SUPPORTED);
3804 talloc_free(tree0);
3805 return ret;
3806 }
3807
3808 static bool test_session_bind_negative_smb3signGtoCs(struct torture_context *tctx, struct smb2_tree *tree0)
3809 {
3810 struct cli_credentials *credentials0 = samba_cmdline_get_creds();
3811 struct cli_credentials *credentials = NULL;
3812 bool ret = false;
3813 struct smb2_transport *transport0 = tree0->session->transport;
3814 struct smbcli_options options1;
3815 struct smbcli_options options2;
3816 bool ok;
3817
3818 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
3819 torture_skip(tctx,
3820 "Can't test without SMB 3.1.1 support");
3821 }
3822
3823 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
3824 torture_skip(tctx,
3825 "Can't test without SMB 3.1.1 signing negotiation support");
3826 }
3827
3828 credentials = cli_credentials_shallow_copy(tctx, credentials0);
3829 torture_assert(tctx, credentials != NULL, "cli_credentials_shallow_copy");
3830 ok = cli_credentials_set_smb_encryption(credentials,
3831 SMB_ENCRYPTION_REQUIRED,
3832 CRED_SPECIFIED);
3833 torture_assert(tctx, ok, "cli_credentials_set_smb_encryption");
3834
3835 options1 = transport0->options;
3836 options1.client_guid = GUID_random();
3837 options1.min_protocol = PROTOCOL_SMB3_11;
3838 options1.max_protocol = PROTOCOL_SMB3_11;
3839 options1.signing = SMB_SIGNING_REQUIRED;
3840 options1.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
3841 .num_algos = 1,
3842 .algos = {
3843 SMB2_SIGNING_AES128_GMAC,
3844 },
3845 };
3846
3847 /* same client guid */
3848 options2 = options1;
3849 options2.only_negprot = true;
3850 options2.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
3851 .num_algos = 1,
3852 .algos = {
3853 SMB2_SIGNING_AES128_CMAC,
3854 },
3855 };
3856
3857 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
3858 credentials,
3859 &options1, &options2,
3860 NT_STATUS_REQUEST_OUT_OF_SEQUENCE);
3861 talloc_free(tree0);
3862 return ret;
3863 }
3864
3865 static bool test_session_bind_negative_smb3signGtoCd(struct torture_context *tctx, struct smb2_tree *tree0)
3866 {
3867 struct cli_credentials *credentials0 = samba_cmdline_get_creds();
3868 struct cli_credentials *credentials = NULL;
3869 bool ret = false;
3870 struct smb2_transport *transport0 = tree0->session->transport;
3871 struct smbcli_options options1;
3872 struct smbcli_options options2;
3873 bool ok;
3874
3875 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
3876 torture_skip(tctx,
3877 "Can't test without SMB 3.1.1 support");
3878 }
3879
3880 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
3881 torture_skip(tctx,
3882 "Can't test without SMB 3.1.1 signing negotiation support");
3883 }
3884
3885 credentials = cli_credentials_shallow_copy(tctx, credentials0);
3886 torture_assert(tctx, credentials != NULL, "cli_credentials_shallow_copy");
3887 ok = cli_credentials_set_smb_encryption(credentials,
3888 SMB_ENCRYPTION_REQUIRED,
3889 CRED_SPECIFIED);
3890 torture_assert(tctx, ok, "cli_credentials_set_smb_encryption");
3891
3892 options1 = transport0->options;
3893 options1.client_guid = GUID_random();
3894 options1.min_protocol = PROTOCOL_SMB3_11;
3895 options1.max_protocol = PROTOCOL_SMB3_11;
3896 options1.signing = SMB_SIGNING_REQUIRED;
3897 options1.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
3898 .num_algos = 1,
3899 .algos = {
3900 SMB2_SIGNING_AES128_GMAC,
3901 },
3902 };
3903
3904 /* different client guid */
3905 options2 = options1;
3906 options2.client_guid = GUID_random();
3907 options2.only_negprot = true;
3908 options2.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
3909 .num_algos = 1,
3910 .algos = {
3911 SMB2_SIGNING_AES128_CMAC,
3912 },
3913 };
3914
3915 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
3916 credentials,
3917 &options1, &options2,
3918 NT_STATUS_REQUEST_OUT_OF_SEQUENCE);
3919 talloc_free(tree0);
3920 return ret;
3921 }
3922
3923 static bool test_session_bind_negative_smb3signGtoHs(struct torture_context *tctx, struct smb2_tree *tree0)
3924 {
3925 struct cli_credentials *credentials0 = samba_cmdline_get_creds();
3926 struct cli_credentials *credentials = NULL;
3927 bool ret = false;
3928 struct smb2_transport *transport0 = tree0->session->transport;
3929 struct smbcli_options options1;
3930 struct smbcli_options options2;
3931 bool ok;
3932
3933 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
3934 torture_skip(tctx,
3935 "Can't test without SMB 3.1.1 support");
3936 }
3937
3938 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
3939 torture_skip(tctx,
3940 "Can't test without SMB 3.1.1 signing negotiation support");
3941 }
3942
3943 credentials = cli_credentials_shallow_copy(tctx, credentials0);
3944 torture_assert(tctx, credentials != NULL, "cli_credentials_shallow_copy");
3945 ok = cli_credentials_set_smb_encryption(credentials,
3946 SMB_ENCRYPTION_REQUIRED,
3947 CRED_SPECIFIED);
3948 torture_assert(tctx, ok, "cli_credentials_set_smb_encryption");
3949
3950 options1 = transport0->options;
3951 options1.client_guid = GUID_random();
3952 options1.min_protocol = PROTOCOL_SMB3_11;
3953 options1.max_protocol = PROTOCOL_SMB3_11;
3954 options1.signing = SMB_SIGNING_REQUIRED;
3955 options1.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
3956 .num_algos = 1,
3957 .algos = {
3958 SMB2_SIGNING_AES128_GMAC,
3959 },
3960 };
3961
3962 /* same client guid */
3963 options2 = options1;
3964 options2.only_negprot = true;
3965 options2.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
3966 .num_algos = 1,
3967 .algos = {
3968 SMB2_SIGNING_HMAC_SHA256,
3969 },
3970 };
3971
3972 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
3973 credentials,
3974 &options1, &options2,
3975 NT_STATUS_REQUEST_OUT_OF_SEQUENCE);
3976 talloc_free(tree0);
3977 return ret;
3978 }
3979
3980 static bool test_session_bind_negative_smb3signGtoHd(struct torture_context *tctx, struct smb2_tree *tree0)
3981 {
3982 struct cli_credentials *credentials0 = samba_cmdline_get_creds();
3983 struct cli_credentials *credentials = NULL;
3984 bool ret = false;
3985 struct smb2_transport *transport0 = tree0->session->transport;
3986 struct smbcli_options options1;
3987 struct smbcli_options options2;
3988 bool ok;
3989
3990 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
3991 torture_skip(tctx,
3992 "Can't test without SMB 3.1.1 support");
3993 }
3994
3995 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
3996 torture_skip(tctx,
3997 "Can't test without SMB 3.1.1 signing negotiation support");
3998 }
3999
4000 credentials = cli_credentials_shallow_copy(tctx, credentials0);
4001 torture_assert(tctx, credentials != NULL, "cli_credentials_shallow_copy");
4002 ok = cli_credentials_set_smb_encryption(credentials,
4003 SMB_ENCRYPTION_REQUIRED,
4004 CRED_SPECIFIED);
4005 torture_assert(tctx, ok, "cli_credentials_set_smb_encryption");
4006
4007 options1 = transport0->options;
4008 options1.client_guid = GUID_random();
4009 options1.min_protocol = PROTOCOL_SMB3_11;
4010 options1.max_protocol = PROTOCOL_SMB3_11;
4011 options1.signing = SMB_SIGNING_REQUIRED;
4012 options1.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
4013 .num_algos = 1,
4014 .algos = {
4015 SMB2_SIGNING_AES128_GMAC,
4016 },
4017 };
4018
4019 /* different client guid */
4020 options2 = options1;
4021 options2.client_guid = GUID_random();
4022 options2.only_negprot = true;
4023 options2.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
4024 .num_algos = 1,
4025 .algos = {
4026 SMB2_SIGNING_HMAC_SHA256,
4027 },
4028 };
4029
4030 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
4031 credentials,
4032 &options1, &options2,
4033 NT_STATUS_REQUEST_OUT_OF_SEQUENCE);
4034 talloc_free(tree0);
4035 return ret;
4036 }
4037
4038 static bool test_session_bind_negative_smb3sneGtoCs(struct torture_context *tctx, struct smb2_tree *tree0)
4039 {
4040 struct cli_credentials *credentials0 = samba_cmdline_get_creds();
4041 struct cli_credentials *credentials = NULL;
4042 bool ret = false;
4043 struct smb2_transport *transport0 = tree0->session->transport;
4044 struct smbcli_options options1;
4045 struct smbcli_options options2;
4046 bool ok;
4047
4048 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
4049 torture_skip(tctx,
4050 "Can't test without SMB 3.1.1 support");
4051 }
4052
4053 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
4054 torture_skip(tctx,
4055 "Can't test without SMB 3.1.1 signing negotiation support");
4056 }
4057
4058 credentials = cli_credentials_shallow_copy(tctx, credentials0);
4059 torture_assert(tctx, credentials != NULL, "cli_credentials_shallow_copy");
4060 ok = cli_credentials_set_smb_encryption(credentials,
4061 SMB_ENCRYPTION_REQUIRED,
4062 CRED_SPECIFIED);
4063 torture_assert(tctx, ok, "cli_credentials_set_smb_encryption");
4064
4065 options1 = transport0->options;
4066 options1.client_guid = GUID_random();
4067 options1.min_protocol = PROTOCOL_SMB3_11;
4068 options1.max_protocol = PROTOCOL_SMB3_11;
4069 options1.signing = SMB_SIGNING_REQUIRED;
4070 options1.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
4071 .num_algos = 1,
4072 .algos = {
4073 SMB2_SIGNING_AES128_GMAC,
4074 },
4075 };
4076 options1.smb3_capabilities.encryption = (struct smb3_encryption_capabilities) {
4077 .num_algos = 1,
4078 .algos = {
4079 SMB2_ENCRYPTION_AES128_GCM,
4080 },
4081 };
4082
4083 /* same client guid */
4084 options2 = options1;
4085 options2.only_negprot = true;
4086 options2.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
4087 .num_algos = 1,
4088 .algos = {
4089 SMB2_SIGNING_AES128_CMAC,
4090 },
4091 };
4092 options2.smb3_capabilities.encryption = (struct smb3_encryption_capabilities) {
4093 .num_algos = 1,
4094 .algos = {
4095 SMB2_ENCRYPTION_AES128_CCM,
4096 },
4097 };
4098
4099 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
4100 credentials,
4101 &options1, &options2,
4102 NT_STATUS_REQUEST_OUT_OF_SEQUENCE);
4103 talloc_free(tree0);
4104 return ret;
4105 }
4106
4107 static bool test_session_bind_negative_smb3sneGtoCd(struct torture_context *tctx, struct smb2_tree *tree0)
4108 {
4109 struct cli_credentials *credentials0 = samba_cmdline_get_creds();
4110 struct cli_credentials *credentials = NULL;
4111 bool ret = false;
4112 struct smb2_transport *transport0 = tree0->session->transport;
4113 struct smbcli_options options1;
4114 struct smbcli_options options2;
4115 bool ok;
4116
4117 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
4118 torture_skip(tctx,
4119 "Can't test without SMB 3.1.1 support");
4120 }
4121
4122 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
4123 torture_skip(tctx,
4124 "Can't test without SMB 3.1.1 signing negotiation support");
4125 }
4126
4127 credentials = cli_credentials_shallow_copy(tctx, credentials0);
4128 torture_assert(tctx, credentials != NULL, "cli_credentials_shallow_copy");
4129 ok = cli_credentials_set_smb_encryption(credentials,
4130 SMB_ENCRYPTION_REQUIRED,
4131 CRED_SPECIFIED);
4132 torture_assert(tctx, ok, "cli_credentials_set_smb_encryption");
4133
4134 options1 = transport0->options;
4135 options1.client_guid = GUID_random();
4136 options1.min_protocol = PROTOCOL_SMB3_11;
4137 options1.max_protocol = PROTOCOL_SMB3_11;
4138 options1.signing = SMB_SIGNING_REQUIRED;
4139 options1.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
4140 .num_algos = 1,
4141 .algos = {
4142 SMB2_SIGNING_AES128_GMAC,
4143 },
4144 };
4145 options1.smb3_capabilities.encryption = (struct smb3_encryption_capabilities) {
4146 .num_algos = 1,
4147 .algos = {
4148 SMB2_ENCRYPTION_AES128_GCM,
4149 },
4150 };
4151
4152 /* different client guid */
4153 options2 = options1;
4154 options2.client_guid = GUID_random();
4155 options2.only_negprot = true;
4156 options2.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
4157 .num_algos = 1,
4158 .algos = {
4159 SMB2_SIGNING_AES128_CMAC,
4160 },
4161 };
4162 options2.smb3_capabilities.encryption = (struct smb3_encryption_capabilities) {
4163 .num_algos = 1,
4164 .algos = {
4165 SMB2_ENCRYPTION_AES128_CCM,
4166 },
4167 };
4168
4169 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
4170 credentials,
4171 &options1, &options2,
4172 NT_STATUS_REQUEST_OUT_OF_SEQUENCE);
4173 talloc_free(tree0);
4174 return ret;
4175 }
4176
4177 static bool test_session_bind_negative_smb3sneGtoHs(struct torture_context *tctx, struct smb2_tree *tree0)
4178 {
4179 struct cli_credentials *credentials0 = samba_cmdline_get_creds();
4180 struct cli_credentials *credentials = NULL;
4181 bool ret = false;
4182 struct smb2_transport *transport0 = tree0->session->transport;
4183 struct smbcli_options options1;
4184 struct smbcli_options options2;
4185 bool ok;
4186
4187 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
4188 torture_skip(tctx,
4189 "Can't test without SMB 3.1.1 support");
4190 }
4191
4192 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
4193 torture_skip(tctx,
4194 "Can't test without SMB 3.1.1 signing negotiation support");
4195 }
4196
4197 credentials = cli_credentials_shallow_copy(tctx, credentials0);
4198 torture_assert(tctx, credentials != NULL, "cli_credentials_shallow_copy");
4199 ok = cli_credentials_set_smb_encryption(credentials,
4200 SMB_ENCRYPTION_REQUIRED,
4201 CRED_SPECIFIED);
4202 torture_assert(tctx, ok, "cli_credentials_set_smb_encryption");
4203
4204 options1 = transport0->options;
4205 options1.client_guid = GUID_random();
4206 options1.min_protocol = PROTOCOL_SMB3_11;
4207 options1.max_protocol = PROTOCOL_SMB3_11;
4208 options1.signing = SMB_SIGNING_REQUIRED;
4209 options1.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
4210 .num_algos = 1,
4211 .algos = {
4212 SMB2_SIGNING_AES128_GMAC,
4213 },
4214 };
4215 options1.smb3_capabilities.encryption = (struct smb3_encryption_capabilities) {
4216 .num_algos = 1,
4217 .algos = {
4218 SMB2_ENCRYPTION_AES128_GCM,
4219 },
4220 };
4221
4222 /* same client guid */
4223 options2 = options1;
4224 options2.only_negprot = true;
4225 options2.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
4226 .num_algos = 1,
4227 .algos = {
4228 SMB2_SIGNING_HMAC_SHA256,
4229 },
4230 };
4231 options2.smb3_capabilities.encryption = (struct smb3_encryption_capabilities) {
4232 .num_algos = 1,
4233 .algos = {
4234 SMB2_ENCRYPTION_AES128_CCM,
4235 },
4236 };
4237
4238 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
4239 credentials,
4240 &options1, &options2,
4241 NT_STATUS_REQUEST_OUT_OF_SEQUENCE);
4242 talloc_free(tree0);
4243 return ret;
4244 }
4245
4246 static bool test_session_bind_negative_smb3sneGtoHd(struct torture_context *tctx, struct smb2_tree *tree0)
4247 {
4248 struct cli_credentials *credentials0 = samba_cmdline_get_creds();
4249 struct cli_credentials *credentials = NULL;
4250 bool ret = false;
4251 struct smb2_transport *transport0 = tree0->session->transport;
4252 struct smbcli_options options1;
4253 struct smbcli_options options2;
4254 bool ok;
4255
4256 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
4257 torture_skip(tctx,
4258 "Can't test without SMB 3.1.1 support");
4259 }
4260
4261 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
4262 torture_skip(tctx,
4263 "Can't test without SMB 3.1.1 signing negotiation support");
4264 }
4265
4266 credentials = cli_credentials_shallow_copy(tctx, credentials0);
4267 torture_assert(tctx, credentials != NULL, "cli_credentials_shallow_copy");
4268 ok = cli_credentials_set_smb_encryption(credentials,
4269 SMB_ENCRYPTION_REQUIRED,
4270 CRED_SPECIFIED);
4271 torture_assert(tctx, ok, "cli_credentials_set_smb_encryption");
4272
4273 options1 = transport0->options;
4274 options1.client_guid = GUID_random();
4275 options1.min_protocol = PROTOCOL_SMB3_11;
4276 options1.max_protocol = PROTOCOL_SMB3_11;
4277 options1.signing = SMB_SIGNING_REQUIRED;
4278 options1.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
4279 .num_algos = 1,
4280 .algos = {
4281 SMB2_SIGNING_AES128_GMAC,
4282 },
4283 };
4284 options1.smb3_capabilities.encryption = (struct smb3_encryption_capabilities) {
4285 .num_algos = 1,
4286 .algos = {
4287 SMB2_ENCRYPTION_AES128_GCM,
4288 },
4289 };
4290
4291 /* different client guid */
4292 options2 = options1;
4293 options2.client_guid = GUID_random();
4294 options2.only_negprot = true;
4295 options2.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
4296 .num_algos = 1,
4297 .algos = {
4298 SMB2_SIGNING_HMAC_SHA256,
4299 },
4300 };
4301 options2.smb3_capabilities.encryption = (struct smb3_encryption_capabilities) {
4302 .num_algos = 1,
4303 .algos = {
4304 SMB2_ENCRYPTION_AES128_CCM,
4305 },
4306 };
4307
4308 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
4309 credentials,
4310 &options1, &options2,
4311 NT_STATUS_REQUEST_OUT_OF_SEQUENCE);
4312 talloc_free(tree0);
4313 return ret;
4314 }
4315
4316 static bool test_session_bind_negative_smb3sneCtoGs(struct torture_context *tctx, struct smb2_tree *tree0)
4317 {
4318 struct cli_credentials *credentials0 = samba_cmdline_get_creds();
4319 struct cli_credentials *credentials = NULL;
4320 bool ret = false;
4321 struct smb2_transport *transport0 = tree0->session->transport;
4322 struct smbcli_options options1;
4323 struct smbcli_options options2;
4324 bool ok;
4325
4326 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
4327 torture_skip(tctx,
4328 "Can't test without SMB 3.1.1 support");
4329 }
4330
4331 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
4332 torture_skip(tctx,
4333 "Can't test without SMB 3.1.1 signing negotiation support");
4334 }
4335
4336 credentials = cli_credentials_shallow_copy(tctx, credentials0);
4337 torture_assert(tctx, credentials != NULL, "cli_credentials_shallow_copy");
4338 ok = cli_credentials_set_smb_encryption(credentials,
4339 SMB_ENCRYPTION_REQUIRED,
4340 CRED_SPECIFIED);
4341 torture_assert(tctx, ok, "cli_credentials_set_smb_encryption");
4342
4343 options1 = transport0->options;
4344 options1.client_guid = GUID_random();
4345 options1.min_protocol = PROTOCOL_SMB3_11;
4346 options1.max_protocol = PROTOCOL_SMB3_11;
4347 options1.signing = SMB_SIGNING_REQUIRED;
4348 options1.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
4349 .num_algos = 1,
4350 .algos = {
4351 SMB2_SIGNING_AES128_CMAC,
4352 },
4353 };
4354 options1.smb3_capabilities.encryption = (struct smb3_encryption_capabilities) {
4355 .num_algos = 1,
4356 .algos = {
4357 SMB2_ENCRYPTION_AES128_CCM,
4358 },
4359 };
4360
4361 /* same client guid */
4362 options2 = options1;
4363 options2.only_negprot = true;
4364 options2.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
4365 .num_algos = 1,
4366 .algos = {
4367 SMB2_SIGNING_AES128_GMAC,
4368 },
4369 };
4370 options2.smb3_capabilities.encryption = (struct smb3_encryption_capabilities) {
4371 .num_algos = 1,
4372 .algos = {
4373 SMB2_ENCRYPTION_AES128_GCM,
4374 },
4375 };
4376
4377 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
4378 credentials,
4379 &options1, &options2,
4380 NT_STATUS_NOT_SUPPORTED);
4381 talloc_free(tree0);
4382 return ret;
4383 }
4384
4385 static bool test_session_bind_negative_smb3sneCtoGd(struct torture_context *tctx, struct smb2_tree *tree0)
4386 {
4387 struct cli_credentials *credentials0 = samba_cmdline_get_creds();
4388 struct cli_credentials *credentials = NULL;
4389 bool ret = false;
4390 struct smb2_transport *transport0 = tree0->session->transport;
4391 struct smbcli_options options1;
4392 struct smbcli_options options2;
4393 bool ok;
4394
4395 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
4396 torture_skip(tctx,
4397 "Can't test without SMB 3.1.1 support");
4398 }
4399
4400 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
4401 torture_skip(tctx,
4402 "Can't test without SMB 3.1.1 signing negotiation support");
4403 }
4404
4405 credentials = cli_credentials_shallow_copy(tctx, credentials0);
4406 torture_assert(tctx, credentials != NULL, "cli_credentials_shallow_copy");
4407 ok = cli_credentials_set_smb_encryption(credentials,
4408 SMB_ENCRYPTION_REQUIRED,
4409 CRED_SPECIFIED);
4410 torture_assert(tctx, ok, "cli_credentials_set_smb_encryption");
4411
4412 options1 = transport0->options;
4413 options1.client_guid = GUID_random();
4414 options1.min_protocol = PROTOCOL_SMB3_11;
4415 options1.max_protocol = PROTOCOL_SMB3_11;
4416 options1.signing = SMB_SIGNING_REQUIRED;
4417 options1.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
4418 .num_algos = 1,
4419 .algos = {
4420 SMB2_SIGNING_AES128_CMAC,
4421 },
4422 };
4423 options1.smb3_capabilities.encryption = (struct smb3_encryption_capabilities) {
4424 .num_algos = 1,
4425 .algos = {
4426 SMB2_ENCRYPTION_AES128_CCM,
4427 },
4428 };
4429
4430 /* different client guid */
4431 options2 = options1;
4432 options2.client_guid = GUID_random();
4433 options2.only_negprot = true;
4434 options2.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
4435 .num_algos = 1,
4436 .algos = {
4437 SMB2_SIGNING_AES128_GMAC,
4438 },
4439 };
4440 options2.smb3_capabilities.encryption = (struct smb3_encryption_capabilities) {
4441 .num_algos = 1,
4442 .algos = {
4443 SMB2_ENCRYPTION_AES128_GCM,
4444 },
4445 };
4446
4447 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
4448 credentials,
4449 &options1, &options2,
4450 NT_STATUS_NOT_SUPPORTED);
4451 talloc_free(tree0);
4452 return ret;
4453 }
4454
4455 static bool test_session_bind_negative_smb3sneHtoGs(struct torture_context *tctx, struct smb2_tree *tree0)
4456 {
4457 struct cli_credentials *credentials0 = samba_cmdline_get_creds();
4458 struct cli_credentials *credentials = NULL;
4459 bool ret = false;
4460 struct smb2_transport *transport0 = tree0->session->transport;
4461 struct smbcli_options options1;
4462 struct smbcli_options options2;
4463 bool ok;
4464
4465 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
4466 torture_skip(tctx,
4467 "Can't test without SMB 3.1.1 support");
4468 }
4469
4470 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
4471 torture_skip(tctx,
4472 "Can't test without SMB 3.1.1 signing negotiation support");
4473 }
4474
4475 credentials = cli_credentials_shallow_copy(tctx, credentials0);
4476 torture_assert(tctx, credentials != NULL, "cli_credentials_shallow_copy");
4477 ok = cli_credentials_set_smb_encryption(credentials,
4478 SMB_ENCRYPTION_REQUIRED,
4479 CRED_SPECIFIED);
4480 torture_assert(tctx, ok, "cli_credentials_set_smb_encryption");
4481
4482 options1 = transport0->options;
4483 options1.client_guid = GUID_random();
4484 options1.min_protocol = PROTOCOL_SMB3_11;
4485 options1.max_protocol = PROTOCOL_SMB3_11;
4486 options1.signing = SMB_SIGNING_REQUIRED;
4487 options1.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
4488 .num_algos = 1,
4489 .algos = {
4490 SMB2_SIGNING_HMAC_SHA256,
4491 },
4492 };
4493 options1.smb3_capabilities.encryption = (struct smb3_encryption_capabilities) {
4494 .num_algos = 1,
4495 .algos = {
4496 SMB2_ENCRYPTION_AES128_CCM,
4497 },
4498 };
4499
4500 /* same client guid */
4501 options2 = options1;
4502 options2.only_negprot = true;
4503 options2.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
4504 .num_algos = 1,
4505 .algos = {
4506 SMB2_SIGNING_AES128_GMAC,
4507 },
4508 };
4509 options2.smb3_capabilities.encryption = (struct smb3_encryption_capabilities) {
4510 .num_algos = 1,
4511 .algos = {
4512 SMB2_ENCRYPTION_AES128_GCM,
4513 },
4514 };
4515
4516 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
4517 credentials,
4518 &options1, &options2,
4519 NT_STATUS_NOT_SUPPORTED);
4520 talloc_free(tree0);
4521 return ret;
4522 }
4523
4524 static bool test_session_bind_negative_smb3sneHtoGd(struct torture_context *tctx, struct smb2_tree *tree0)
4525 {
4526 struct cli_credentials *credentials0 = samba_cmdline_get_creds();
4527 struct cli_credentials *credentials = NULL;
4528 bool ret = false;
4529 struct smb2_transport *transport0 = tree0->session->transport;
4530 struct smbcli_options options1;
4531 struct smbcli_options options2;
4532 bool ok;
4533
4534 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
4535 torture_skip(tctx,
4536 "Can't test without SMB 3.1.1 support");
4537 }
4538
4539 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
4540 torture_skip(tctx,
4541 "Can't test without SMB 3.1.1 signing negotiation support");
4542 }
4543
4544 credentials = cli_credentials_shallow_copy(tctx, credentials0);
4545 torture_assert(tctx, credentials != NULL, "cli_credentials_shallow_copy");
4546 ok = cli_credentials_set_smb_encryption(credentials,
4547 SMB_ENCRYPTION_REQUIRED,
4548 CRED_SPECIFIED);
4549 torture_assert(tctx, ok, "cli_credentials_set_smb_encryption");
4550
4551 options1 = transport0->options;
4552 options1.client_guid = GUID_random();
4553 options1.min_protocol = PROTOCOL_SMB3_11;
4554 options1.max_protocol = PROTOCOL_SMB3_11;
4555 options1.signing = SMB_SIGNING_REQUIRED;
4556 options1.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
4557 .num_algos = 1,
4558 .algos = {
4559 SMB2_SIGNING_HMAC_SHA256,
4560 },
4561 };
4562 options1.smb3_capabilities.encryption = (struct smb3_encryption_capabilities) {
4563 .num_algos = 1,
4564 .algos = {
4565 SMB2_ENCRYPTION_AES128_CCM,
4566 },
4567 };
4568
4569 /* different client guid */
4570 options2 = options1;
4571 options2.client_guid = GUID_random();
4572 options2.only_negprot = true;
4573 options2.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
4574 .num_algos = 1,
4575 .algos = {
4576 SMB2_SIGNING_AES128_GMAC,
4577 },
4578 };
4579 options2.smb3_capabilities.encryption = (struct smb3_encryption_capabilities) {
4580 .num_algos = 1,
4581 .algos = {
4582 SMB2_ENCRYPTION_AES128_GCM,
4583 },
4584 };
4585
4586 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
4587 credentials,
4588 &options1, &options2,
4589 NT_STATUS_NOT_SUPPORTED);
4590 talloc_free(tree0);
4591 return ret;
4592 }
4593
4594 static bool test_session_bind_negative_smb3signC30toGs(struct torture_context *tctx, struct smb2_tree *tree0)
4595 {
4596 struct cli_credentials *credentials0 = samba_cmdline_get_creds();
4597 struct cli_credentials *credentials = NULL;
4598 bool ret = false;
4599 struct smb2_transport *transport0 = tree0->session->transport;
4600 struct smbcli_options options1;
4601 struct smbcli_options options2;
4602 bool ok;
4603
4604 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
4605 torture_skip(tctx,
4606 "Can't test without SMB 3.1.1 support");
4607 }
4608
4609 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
4610 torture_skip(tctx,
4611 "Can't test without SMB 3.1.1 signing negotiation support");
4612 }
4613
4614 credentials = cli_credentials_shallow_copy(tctx, credentials0);
4615 torture_assert(tctx, credentials != NULL, "cli_credentials_shallow_copy");
4616 ok = cli_credentials_set_smb_encryption(credentials,
4617 SMB_ENCRYPTION_REQUIRED,
4618 CRED_SPECIFIED);
4619 torture_assert(tctx, ok, "cli_credentials_set_smb_encryption");
4620
4621 options1 = transport0->options;
4622 options1.client_guid = GUID_random();
4623 options1.min_protocol = PROTOCOL_SMB3_00;
4624 options1.max_protocol = PROTOCOL_SMB3_02;
4625 options1.signing = SMB_SIGNING_REQUIRED;
4626
4627 /* same client guid */
4628 options2 = options1;
4629 options2.only_negprot = true;
4630 options2.min_protocol = PROTOCOL_SMB3_11;
4631 options2.max_protocol = PROTOCOL_SMB3_11;
4632 options2.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
4633 .num_algos = 1,
4634 .algos = {
4635 SMB2_SIGNING_AES128_GMAC,
4636 },
4637 };
4638
4639 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
4640 credentials,
4641 &options1, &options2,
4642 NT_STATUS_NOT_SUPPORTED);
4643 talloc_free(tree0);
4644 return ret;
4645 }
4646
4647 static bool test_session_bind_negative_smb3signC30toGd(struct torture_context *tctx, struct smb2_tree *tree0)
4648 {
4649 struct cli_credentials *credentials0 = samba_cmdline_get_creds();
4650 struct cli_credentials *credentials = NULL;
4651 bool ret = false;
4652 struct smb2_transport *transport0 = tree0->session->transport;
4653 struct smbcli_options options1;
4654 struct smbcli_options options2;
4655 bool ok;
4656
4657 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
4658 torture_skip(tctx,
4659 "Can't test without SMB 3.1.1 support");
4660 }
4661
4662 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
4663 torture_skip(tctx,
4664 "Can't test without SMB 3.1.1 signing negotiation support");
4665 }
4666
4667 credentials = cli_credentials_shallow_copy(tctx, credentials0);
4668 torture_assert(tctx, credentials != NULL, "cli_credentials_shallow_copy");
4669 ok = cli_credentials_set_smb_encryption(credentials,
4670 SMB_ENCRYPTION_REQUIRED,
4671 CRED_SPECIFIED);
4672 torture_assert(tctx, ok, "cli_credentials_set_smb_encryption");
4673
4674 options1 = transport0->options;
4675 options1.client_guid = GUID_random();
4676 options1.min_protocol = PROTOCOL_SMB3_00;
4677 options1.max_protocol = PROTOCOL_SMB3_02;
4678 options1.signing = SMB_SIGNING_REQUIRED;
4679
4680 /* different client guid */
4681 options2 = options1;
4682 options2.client_guid = GUID_random();
4683 options2.only_negprot = true;
4684 options2.min_protocol = PROTOCOL_SMB3_11;
4685 options2.max_protocol = PROTOCOL_SMB3_11;
4686 options2.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
4687 .num_algos = 1,
4688 .algos = {
4689 SMB2_SIGNING_AES128_GMAC,
4690 },
4691 };
4692
4693 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
4694 credentials,
4695 &options1, &options2,
4696 NT_STATUS_NOT_SUPPORTED);
4697 talloc_free(tree0);
4698 return ret;
4699 }
4700
4701 static bool test_session_bind_negative_smb3signH2XtoGs(struct torture_context *tctx, struct smb2_tree *tree0)
4702 {
4703 struct cli_credentials *credentials0 = samba_cmdline_get_creds();
4704 struct cli_credentials *credentials = NULL;
4705 bool ret = false;
4706 struct smb2_transport *transport0 = tree0->session->transport;
4707 struct smbcli_options options1;
4708 struct smbcli_options options2;
4709 bool ok;
4710 bool encrypted;
4711
4712 encrypted = smb2cli_tcon_is_encryption_on(tree0->smbXcli);
4713 if (encrypted) {
4714 torture_skip(tctx,
4715 "Can't test SMB 2.10 if encryption is required");
4716 }
4717
4718 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
4719 torture_skip(tctx,
4720 "Can't test without SMB 3.1.1 support");
4721 }
4722
4723 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
4724 torture_skip(tctx,
4725 "Can't test without SMB 3.1.1 signing negotiation support");
4726 }
4727
4728 credentials = cli_credentials_shallow_copy(tctx, credentials0);
4729 torture_assert(tctx, credentials != NULL, "cli_credentials_shallow_copy");
4730 ok = cli_credentials_set_smb_encryption(credentials,
4731 SMB_ENCRYPTION_OFF,
4732 CRED_SPECIFIED);
4733 torture_assert(tctx, ok, "cli_credentials_set_smb_encryption");
4734
4735 options1 = transport0->options;
4736 options1.client_guid = GUID_random();
4737 options1.min_protocol = PROTOCOL_SMB2_02;
4738 options1.max_protocol = PROTOCOL_SMB2_10;
4739 options1.signing = SMB_SIGNING_REQUIRED;
4740
4741 /* same client guid */
4742 options2 = options1;
4743 options2.only_negprot = true;
4744 options2.min_protocol = PROTOCOL_SMB3_11;
4745 options2.max_protocol = PROTOCOL_SMB3_11;
4746 options2.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
4747 .num_algos = 1,
4748 .algos = {
4749 SMB2_SIGNING_AES128_GMAC,
4750 },
4751 };
4752
4753 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
4754 credentials,
4755 &options1, &options2,
4756 NT_STATUS_NOT_SUPPORTED);
4757 talloc_free(tree0);
4758 return ret;
4759 }
4760
4761 static bool test_session_bind_negative_smb3signH2XtoGd(struct torture_context *tctx, struct smb2_tree *tree0)
4762 {
4763 struct cli_credentials *credentials0 = samba_cmdline_get_creds();
4764 struct cli_credentials *credentials = NULL;
4765 bool ret = false;
4766 struct smb2_transport *transport0 = tree0->session->transport;
4767 struct smbcli_options options1;
4768 struct smbcli_options options2;
4769 bool ok;
4770 bool encrypted;
4771
4772 encrypted = smb2cli_tcon_is_encryption_on(tree0->smbXcli);
4773 if (encrypted) {
4774 torture_skip(tctx,
4775 "Can't test SMB 2.10 if encryption is required");
4776 }
4777
4778 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
4779 torture_skip(tctx,
4780 "Can't test without SMB 3.1.1 support");
4781 }
4782
4783 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
4784 torture_skip(tctx,
4785 "Can't test without SMB 3.1.1 signing negotiation support");
4786 }
4787
4788 credentials = cli_credentials_shallow_copy(tctx, credentials0);
4789 torture_assert(tctx, credentials != NULL, "cli_credentials_shallow_copy");
4790 ok = cli_credentials_set_smb_encryption(credentials,
4791 SMB_ENCRYPTION_OFF,
4792 CRED_SPECIFIED);
4793 torture_assert(tctx, ok, "cli_credentials_set_smb_encryption");
4794
4795 options1 = transport0->options;
4796 options1.client_guid = GUID_random();
4797 options1.min_protocol = PROTOCOL_SMB2_02;
4798 options1.max_protocol = PROTOCOL_SMB2_10;
4799 options1.signing = SMB_SIGNING_REQUIRED;
4800
4801 /* different client guid */
4802 options2 = options1;
4803 options2.client_guid = GUID_random();
4804 options2.only_negprot = true;
4805 options2.min_protocol = PROTOCOL_SMB3_11;
4806 options2.max_protocol = PROTOCOL_SMB3_11;
4807 options2.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
4808 .num_algos = 1,
4809 .algos = {
4810 SMB2_SIGNING_AES128_GMAC,
4811 },
4812 };
4813
4814 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
4815 credentials,
4816 &options1, &options2,
4817 NT_STATUS_NOT_SUPPORTED);
4818 talloc_free(tree0);
4819 return ret;
4820 }
4821
4822 static bool test_session_bind_negative_smb3signGtoC30s(struct torture_context *tctx, struct smb2_tree *tree0)
4823 {
4824 struct cli_credentials *credentials0 = samba_cmdline_get_creds();
4825 struct cli_credentials *credentials = NULL;
4826 bool ret = false;
4827 struct smb2_transport *transport0 = tree0->session->transport;
4828 struct smbcli_options options1;
4829 struct smbcli_options options2;
4830 bool ok;
4831
4832 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
4833 torture_skip(tctx,
4834 "Can't test without SMB 3.1.1 support");
4835 }
4836
4837 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
4838 torture_skip(tctx,
4839 "Can't test without SMB 3.1.1 signing negotiation support");
4840 }
4841
4842 credentials = cli_credentials_shallow_copy(tctx, credentials0);
4843 torture_assert(tctx, credentials != NULL, "cli_credentials_shallow_copy");
4844 ok = cli_credentials_set_smb_encryption(credentials,
4845 SMB_ENCRYPTION_REQUIRED,
4846 CRED_SPECIFIED);
4847 torture_assert(tctx, ok, "cli_credentials_set_smb_encryption");
4848
4849 options1 = transport0->options;
4850 options1.client_guid = GUID_random();
4851 options1.min_protocol = PROTOCOL_SMB3_11;
4852 options1.max_protocol = PROTOCOL_SMB3_11;
4853 options1.signing = SMB_SIGNING_REQUIRED;
4854 options1.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
4855 .num_algos = 1,
4856 .algos = {
4857 SMB2_SIGNING_AES128_GMAC,
4858 },
4859 };
4860
4861 /* same client guid */
4862 options2 = options1;
4863 options2.only_negprot = true;
4864 options2.min_protocol = PROTOCOL_SMB3_00;
4865 options2.max_protocol = PROTOCOL_SMB3_02;
4866 options2.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
4867 .num_algos = 1,
4868 .algos = {
4869 SMB2_SIGNING_AES128_CMAC,
4870 },
4871 };
4872
4873 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
4874 credentials,
4875 &options1, &options2,
4876 NT_STATUS_REQUEST_OUT_OF_SEQUENCE);
4877 talloc_free(tree0);
4878 return ret;
4879 }
4880
4881 static bool test_session_bind_negative_smb3signGtoC30d(struct torture_context *tctx, struct smb2_tree *tree0)
4882 {
4883 struct cli_credentials *credentials0 = samba_cmdline_get_creds();
4884 struct cli_credentials *credentials = NULL;
4885 bool ret = false;
4886 struct smb2_transport *transport0 = tree0->session->transport;
4887 struct smbcli_options options1;
4888 struct smbcli_options options2;
4889 bool ok;
4890
4891 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
4892 torture_skip(tctx,
4893 "Can't test without SMB 3.1.1 support");
4894 }
4895
4896 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
4897 torture_skip(tctx,
4898 "Can't test without SMB 3.1.1 signing negotiation support");
4899 }
4900
4901 credentials = cli_credentials_shallow_copy(tctx, credentials0);
4902 torture_assert(tctx, credentials != NULL, "cli_credentials_shallow_copy");
4903 ok = cli_credentials_set_smb_encryption(credentials,
4904 SMB_ENCRYPTION_REQUIRED,
4905 CRED_SPECIFIED);
4906 torture_assert(tctx, ok, "cli_credentials_set_smb_encryption");
4907
4908 options1 = transport0->options;
4909 options1.client_guid = GUID_random();
4910 options1.min_protocol = PROTOCOL_SMB3_11;
4911 options1.max_protocol = PROTOCOL_SMB3_11;
4912 options1.signing = SMB_SIGNING_REQUIRED;
4913 options1.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
4914 .num_algos = 1,
4915 .algos = {
4916 SMB2_SIGNING_AES128_GMAC,
4917 },
4918 };
4919
4920 /* different client guid */
4921 options2 = options1;
4922 options2.client_guid = GUID_random();
4923 options2.only_negprot = true;
4924 options2.min_protocol = PROTOCOL_SMB3_00;
4925 options2.max_protocol = PROTOCOL_SMB3_02;
4926 options2.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
4927 .num_algos = 1,
4928 .algos = {
4929 SMB2_SIGNING_AES128_CMAC,
4930 },
4931 };
4932
4933 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
4934 credentials,
4935 &options1, &options2,
4936 NT_STATUS_REQUEST_OUT_OF_SEQUENCE);
4937 talloc_free(tree0);
4938 return ret;
4939 }
4940
4941 static bool test_session_bind_negative_smb3signGtoH2Xs(struct torture_context *tctx, struct smb2_tree *tree0)
4942 {
4943 struct cli_credentials *credentials0 = samba_cmdline_get_creds();
4944 struct cli_credentials *credentials = NULL;
4945 bool ret = false;
4946 struct smb2_transport *transport0 = tree0->session->transport;
4947 struct smbcli_options options1;
4948 struct smbcli_options options2;
4949 bool ok;
4950 bool encrypted;
4951
4952 encrypted = smb2cli_tcon_is_encryption_on(tree0->smbXcli);
4953 if (encrypted) {
4954 torture_skip(tctx,
4955 "Can't test SMB 2.10 if encryption is required");
4956 }
4957
4958 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
4959 torture_skip(tctx,
4960 "Can't test without SMB 3.1.1 support");
4961 }
4962
4963 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
4964 torture_skip(tctx,
4965 "Can't test without SMB 3.1.1 signing negotiation support");
4966 }
4967
4968 credentials = cli_credentials_shallow_copy(tctx, credentials0);
4969 torture_assert(tctx, credentials != NULL, "cli_credentials_shallow_copy");
4970 ok = cli_credentials_set_smb_encryption(credentials,
4971 SMB_ENCRYPTION_REQUIRED,
4972 CRED_SPECIFIED);
4973 torture_assert(tctx, ok, "cli_credentials_set_smb_encryption");
4974
4975 options1 = transport0->options;
4976 options1.client_guid = GUID_random();
4977 options1.min_protocol = PROTOCOL_SMB3_11;
4978 options1.max_protocol = PROTOCOL_SMB3_11;
4979 options1.signing = SMB_SIGNING_REQUIRED;
4980 options1.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
4981 .num_algos = 1,
4982 .algos = {
4983 SMB2_SIGNING_AES128_GMAC,
4984 },
4985 };
4986
4987 /* same client guid */
4988 options2 = options1;
4989 options2.only_negprot = true;
4990 options2.min_protocol = PROTOCOL_SMB2_02;
4991 options2.max_protocol = PROTOCOL_SMB2_10;
4992 options2.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
4993 .num_algos = 1,
4994 .algos = {
4995 SMB2_SIGNING_HMAC_SHA256,
4996 },
4997 };
4998
4999 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
5000 credentials,
5001 &options1, &options2,
5002 NT_STATUS_REQUEST_OUT_OF_SEQUENCE);
5003 talloc_free(tree0);
5004 return ret;
5005 }
5006
5007 static bool test_session_bind_negative_smb3signGtoH2Xd(struct torture_context *tctx, struct smb2_tree *tree0)
5008 {
5009 struct cli_credentials *credentials0 = samba_cmdline_get_creds();
5010 struct cli_credentials *credentials = NULL;
5011 bool ret = false;
5012 struct smb2_transport *transport0 = tree0->session->transport;
5013 struct smbcli_options options1;
5014 struct smbcli_options options2;
5015 bool ok;
5016 bool encrypted;
5017
5018 encrypted = smb2cli_tcon_is_encryption_on(tree0->smbXcli);
5019 if (encrypted) {
5020 torture_skip(tctx,
5021 "Can't test SMB 2.10 if encryption is required");
5022 }
5023
5024 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
5025 torture_skip(tctx,
5026 "Can't test without SMB 3.1.1 support");
5027 }
5028
5029 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
5030 torture_skip(tctx,
5031 "Can't test without SMB 3.1.1 signing negotiation support");
5032 }
5033
5034 credentials = cli_credentials_shallow_copy(tctx, credentials0);
5035 torture_assert(tctx, credentials != NULL, "cli_credentials_shallow_copy");
5036 ok = cli_credentials_set_smb_encryption(credentials,
5037 SMB_ENCRYPTION_REQUIRED,
5038 CRED_SPECIFIED);
5039 torture_assert(tctx, ok, "cli_credentials_set_smb_encryption");
5040
5041 options1 = transport0->options;
5042 options1.client_guid = GUID_random();
5043 options1.min_protocol = PROTOCOL_SMB3_11;
5044 options1.max_protocol = PROTOCOL_SMB3_11;
5045 options1.signing = SMB_SIGNING_REQUIRED;
5046 options1.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
5047 .num_algos = 1,
5048 .algos = {
5049 SMB2_SIGNING_AES128_GMAC,
5050 },
5051 };
5052
5053 /* different client guid */
5054 options2 = options1;
5055 options2.client_guid = GUID_random();
5056 options2.only_negprot = true;
5057 options2.min_protocol = PROTOCOL_SMB2_02;
5058 options2.max_protocol = PROTOCOL_SMB2_10;
5059 options2.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
5060 .num_algos = 1,
5061 .algos = {
5062 SMB2_SIGNING_HMAC_SHA256,
5063 },
5064 };
5065
5066 ret = test_session_bind_negative_smbXtoX(tctx, __func__,
5067 credentials,
5068 &options1, &options2,
5069 NT_STATUS_REQUEST_OUT_OF_SEQUENCE);
5070 talloc_free(tree0);
5071 return ret;
5072 }
5073
5074 static bool test_session_two_logoff(struct torture_context *tctx,
5075 struct smb2_tree *tree1)
5076 {
5077 NTSTATUS status;
5078 bool ret = true;
5079 struct smbcli_options transport2_options;
5080 struct smb2_tree *tree2 = NULL;
5081 struct smb2_session *session2 = NULL;
5082 struct smb2_session *session1 = tree1->session;
5083 struct smb2_transport *transport1 = tree1->session->transport;
5084 struct smb2_transport *transport2;
5085 bool ok;
5086
5087 /* Connect 2nd connection */
5088 torture_comment(tctx, "connect tree2 with the same client_guid\n");
5089 transport2_options = transport1->options;
5090 ok = torture_smb2_connection_ext(tctx, 0, &transport2_options, &tree2);
5091 torture_assert(tctx, ok, "couldn't connect tree2\n");
5092 transport2 = tree2->session->transport;
5093 session2 = tree2->session;
5094
5095 torture_comment(tctx, "session2: logoff\n");
5096 status = smb2_logoff(session2);
5097 torture_assert_ntstatus_ok(tctx, status, "session2: logoff");
5098 torture_comment(tctx, "transport2: keepalive\n");
5099 status = smb2_keepalive(transport2);
5100 torture_assert_ntstatus_ok(tctx, status, "transport2: keepalive");
5101 torture_comment(tctx, "transport2: disconnect\n");
5102 TALLOC_FREE(tree2);
5103
5104 torture_comment(tctx, "session1: logoff\n");
5105 status = smb2_logoff(session1);
5106 torture_assert_ntstatus_ok(tctx, status, "session1: logoff");
5107 torture_comment(tctx, "transport1: keepalive\n");
5108 status = smb2_keepalive(transport1);
5109 torture_assert_ntstatus_ok(tctx, status, "transport1: keepalive");
5110 torture_comment(tctx, "transport1: disconnect\n");
5111 TALLOC_FREE(tree1);
5112
5113 return ret;
5114 }
5115
5116 static bool test_session_sign_enc(struct torture_context *tctx,
5117 const char *testname,
5118 struct cli_credentials *credentials1,
5119 const struct smbcli_options *options1)
5120 {
5121 const char *host = torture_setting_string(tctx, "host", NULL);
5122 const char *share = torture_setting_string(tctx, "share", NULL);
5123 NTSTATUS status;
5124 bool ret = false;
5125 struct smb2_tree *tree1 = NULL;
5126 char fname[256];
5127 struct smb2_handle rh = {{0}};
5128 struct smb2_handle _h1;
5129 struct smb2_handle *h1 = NULL;
5130 struct smb2_create io1;
5131 union smb_fileinfo qfinfo1;
5132 union smb_notify notify;
5133 struct smb2_request *req = NULL;
5134
5135 status = smb2_connect(tctx,
5136 host,
5137 share,
5138 tctx->lp_ctx,
5139 lpcfg_resolve_context(tctx->lp_ctx),
5140 credentials1,
5141 &tree1,
5142 tctx->ev,
5143 options1,
5144 lpcfg_socket_options(tctx->lp_ctx),
5145 lpcfg_gensec_settings(tctx, tctx->lp_ctx)
5146 );
5147 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
5148 "smb2_connect options1 failed");
5149
5150 status = smb2_util_roothandle(tree1, &rh);
5151 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
5152 "smb2_util_roothandle failed");
5153
5154 /* Add some random component to the file name. */
5155 snprintf(fname, sizeof(fname), "%s_%s.dat",
5156 testname, generate_random_str(tctx, 8));
5157
5158 smb2_util_unlink(tree1, fname);
5159
5160 smb2_oplock_create_share(&io1, fname,
5161 smb2_util_share_access(""),
5162 smb2_util_oplock_level("b"));
5163
5164 io1.in.create_options |= NTCREATEX_OPTIONS_DELETE_ON_CLOSE;
5165 status = smb2_create(tree1, tctx, &io1);
5166 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
5167 "smb2_create failed");
5168 _h1 = io1.out.file.handle;
5169 h1 = &_h1;
5170 CHECK_CREATED(tctx, &io1, CREATED, FILE_ATTRIBUTE_ARCHIVE);
5171 torture_assert_int_equal(tctx, io1.out.oplock_level,
5172 smb2_util_oplock_level("b"),
5173 "oplock_level incorrect");
5174
5175 /* Check the initial session is still alive */
5176 ZERO_STRUCT(qfinfo1);
5177 qfinfo1.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
5178 qfinfo1.generic.in.file.handle = _h1;
5179 status = smb2_getinfo_file(tree1, tctx, &qfinfo1);
5180 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
5181 "smb2_getinfo_file failed");
5182
5183 /* ask for a change notify,
5184 on file or directory name changes */
5185 ZERO_STRUCT(notify);
5186 notify.smb2.level = RAW_NOTIFY_SMB2;
5187 notify.smb2.in.buffer_size = 1000;
5188 notify.smb2.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
5189 notify.smb2.in.file.handle = rh;
5190 notify.smb2.in.recursive = true;
5191
5192 req = smb2_notify_send(tree1, &(notify.smb2));
5193 WAIT_FOR_ASYNC_RESPONSE(req);
5194
5195 status = smb2_cancel(req);
5196 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
5197 "smb2_cancel failed");
5198
5199 status = smb2_notify_recv(req, tctx, &(notify.smb2));
5200 torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_CANCELLED,
5201 ret, done,
5202 "smb2_notify_recv failed");
5203
5204 /* Check the initial session is still alive */
5205 ZERO_STRUCT(qfinfo1);
5206 qfinfo1.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
5207 qfinfo1.generic.in.file.handle = _h1;
5208 status = smb2_getinfo_file(tree1, tctx, &qfinfo1);
5209 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
5210 "smb2_getinfo_file failed");
5211
5212 ret = true;
5213 done:
5214 if (h1 != NULL) {
5215 smb2_util_close(tree1, *h1);
5216 }
5217 TALLOC_FREE(tree1);
5218
5219 return ret;
5220 }
5221
5222 static bool test_session_signing_hmac_sha_256(struct torture_context *tctx, struct smb2_tree *tree0)
5223 {
5224 struct cli_credentials *credentials = samba_cmdline_get_creds();
5225 bool ret = false;
5226 struct smb2_transport *transport0 = tree0->session->transport;
5227 struct smbcli_options options1;
5228 bool encrypted;
5229
5230 encrypted = smb2cli_tcon_is_encryption_on(tree0->smbXcli);
5231 if (encrypted) {
5232 torture_skip(tctx,
5233 "Can't test signing only if encryption is required");
5234 }
5235
5236 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
5237 torture_skip(tctx,
5238 "Can't test without SMB 3.1.1 support");
5239 }
5240
5241 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
5242 torture_skip(tctx,
5243 "Can't test without SMB 3.1.1 signing negotiation support");
5244 }
5245
5246 options1 = transport0->options;
5247 options1.client_guid = GUID_random();
5248 options1.min_protocol = PROTOCOL_SMB3_11;
5249 options1.max_protocol = PROTOCOL_SMB3_11;
5250 options1.signing = SMB_SIGNING_REQUIRED;
5251 options1.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
5252 .num_algos = 1,
5253 .algos = {
5254 SMB2_SIGNING_HMAC_SHA256,
5255 },
5256 };
5257
5258 ret = test_session_sign_enc(tctx,
5259 __func__,
5260 credentials,
5261 &options1);
5262 TALLOC_FREE(tree0);
5263 return ret;
5264 }
5265
5266 static bool test_session_signing_aes_128_cmac(struct torture_context *tctx, struct smb2_tree *tree0)
5267 {
5268 struct cli_credentials *credentials = samba_cmdline_get_creds();
5269 bool ret = false;
5270 struct smb2_transport *transport0 = tree0->session->transport;
5271 struct smbcli_options options1;
5272 bool encrypted;
5273
5274 encrypted = smb2cli_tcon_is_encryption_on(tree0->smbXcli);
5275 if (encrypted) {
5276 torture_skip(tctx,
5277 "Can't test signing only if encryption is required");
5278 }
5279
5280 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
5281 torture_skip(tctx,
5282 "Can't test without SMB 3.1.1 support");
5283 }
5284
5285 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
5286 torture_skip(tctx,
5287 "Can't test without SMB 3.1.1 signing negotiation support");
5288 }
5289
5290 options1 = transport0->options;
5291 options1.client_guid = GUID_random();
5292 options1.min_protocol = PROTOCOL_SMB3_11;
5293 options1.max_protocol = PROTOCOL_SMB3_11;
5294 options1.signing = SMB_SIGNING_REQUIRED;
5295 options1.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
5296 .num_algos = 1,
5297 .algos = {
5298 SMB2_SIGNING_AES128_CMAC,
5299 },
5300 };
5301
5302 ret = test_session_sign_enc(tctx,
5303 __func__,
5304 credentials,
5305 &options1);
5306 TALLOC_FREE(tree0);
5307 return ret;
5308 }
5309
5310 static bool test_session_signing_aes_128_gmac(struct torture_context *tctx, struct smb2_tree *tree0)
5311 {
5312 struct cli_credentials *credentials = samba_cmdline_get_creds();
5313 bool ret = false;
5314 struct smb2_transport *transport0 = tree0->session->transport;
5315 struct smbcli_options options1;
5316 bool encrypted;
5317
5318 encrypted = smb2cli_tcon_is_encryption_on(tree0->smbXcli);
5319 if (encrypted) {
5320 torture_skip(tctx,
5321 "Can't test signing only if encryption is required");
5322 }
5323
5324 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
5325 torture_skip(tctx,
5326 "Can't test without SMB 3.1.1 support");
5327 }
5328
5329 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
5330 torture_skip(tctx,
5331 "Can't test without SMB 3.1.1 signing negotiation support");
5332 }
5333
5334 options1 = transport0->options;
5335 options1.client_guid = GUID_random();
5336 options1.min_protocol = PROTOCOL_SMB3_11;
5337 options1.max_protocol = PROTOCOL_SMB3_11;
5338 options1.signing = SMB_SIGNING_REQUIRED;
5339 options1.smb3_capabilities.signing = (struct smb3_signing_capabilities) {
5340 .num_algos = 1,
5341 .algos = {
5342 SMB2_SIGNING_AES128_GMAC,
5343 },
5344 };
5345
5346 ret = test_session_sign_enc(tctx,
5347 __func__,
5348 credentials,
5349 &options1);
5350 TALLOC_FREE(tree0);
5351 return ret;
5352 }
5353
5354 static bool test_session_encryption_aes_128_ccm(struct torture_context *tctx, struct smb2_tree *tree0)
5355 {
5356 struct cli_credentials *credentials0 = samba_cmdline_get_creds();
5357 struct cli_credentials *credentials = NULL;
5358 bool ret = false;
5359 struct smb2_transport *transport0 = tree0->session->transport;
5360 struct smbcli_options options1;
5361 bool ok;
5362
5363 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
5364 torture_skip(tctx,
5365 "Can't test without SMB 3.1.1 support");
5366 }
5367
5368 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
5369 torture_skip(tctx,
5370 "Can't test without SMB 3.1.1 signing negotiation support");
5371 }
5372
5373 credentials = cli_credentials_shallow_copy(tctx, credentials0);
5374 torture_assert(tctx, credentials != NULL, "cli_credentials_shallow_copy");
5375 ok = cli_credentials_set_smb_encryption(credentials,
5376 SMB_ENCRYPTION_REQUIRED,
5377 CRED_SPECIFIED);
5378 torture_assert(tctx, ok, "cli_credentials_set_smb_encryption");
5379
5380 options1 = transport0->options;
5381 options1.client_guid = GUID_random();
5382 options1.min_protocol = PROTOCOL_SMB3_11;
5383 options1.max_protocol = PROTOCOL_SMB3_11;
5384 options1.signing = SMB_SIGNING_REQUIRED;
5385 options1.smb3_capabilities.encryption = (struct smb3_encryption_capabilities) {
5386 .num_algos = 1,
5387 .algos = {
5388 SMB2_ENCRYPTION_AES128_CCM,
5389 },
5390 };
5391
5392 ret = test_session_sign_enc(tctx,
5393 __func__,
5394 credentials,
5395 &options1);
5396 TALLOC_FREE(tree0);
5397 return ret;
5398 }
5399
5400 static bool test_session_encryption_aes_128_gcm(struct torture_context *tctx, struct smb2_tree *tree0)
5401 {
5402 struct cli_credentials *credentials0 = samba_cmdline_get_creds();
5403 struct cli_credentials *credentials = NULL;
5404 bool ret = false;
5405 struct smb2_transport *transport0 = tree0->session->transport;
5406 struct smbcli_options options1;
5407 bool ok;
5408
5409 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
5410 torture_skip(tctx,
5411 "Can't test without SMB 3.1.1 support");
5412 }
5413
5414 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
5415 torture_skip(tctx,
5416 "Can't test without SMB 3.1.1 signing negotiation support");
5417 }
5418
5419 credentials = cli_credentials_shallow_copy(tctx, credentials0);
5420 torture_assert(tctx, credentials != NULL, "cli_credentials_shallow_copy");
5421 ok = cli_credentials_set_smb_encryption(credentials,
5422 SMB_ENCRYPTION_REQUIRED,
5423 CRED_SPECIFIED);
5424 torture_assert(tctx, ok, "cli_credentials_set_smb_encryption");
5425
5426 options1 = transport0->options;
5427 options1.client_guid = GUID_random();
5428 options1.min_protocol = PROTOCOL_SMB3_11;
5429 options1.max_protocol = PROTOCOL_SMB3_11;
5430 options1.signing = SMB_SIGNING_REQUIRED;
5431 options1.smb3_capabilities.encryption = (struct smb3_encryption_capabilities) {
5432 .num_algos = 1,
5433 .algos = {
5434 SMB2_ENCRYPTION_AES128_GCM,
5435 },
5436 };
5437
5438 ret = test_session_sign_enc(tctx,
5439 __func__,
5440 credentials,
5441 &options1);
5442 TALLOC_FREE(tree0);
5443 return ret;
5444 }
5445
5446 static bool test_session_encryption_aes_256_ccm(struct torture_context *tctx, struct smb2_tree *tree0)
5447 {
5448 struct cli_credentials *credentials0 = samba_cmdline_get_creds();
5449 struct cli_credentials *credentials = NULL;
5450 bool ret = false;
5451 struct smb2_transport *transport0 = tree0->session->transport;
5452 struct smbcli_options options1;
5453 bool ok;
5454
5455 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
5456 torture_skip(tctx,
5457 "Can't test without SMB 3.1.1 support");
5458 }
5459
5460 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
5461 torture_skip(tctx,
5462 "Can't test without SMB 3.1.1 signing negotiation support");
5463 }
5464
5465 credentials = cli_credentials_shallow_copy(tctx, credentials0);
5466 torture_assert(tctx, credentials != NULL, "cli_credentials_shallow_copy");
5467 ok = cli_credentials_set_smb_encryption(credentials,
5468 SMB_ENCRYPTION_REQUIRED,
5469 CRED_SPECIFIED);
5470 torture_assert(tctx, ok, "cli_credentials_set_smb_encryption");
5471
5472 options1 = transport0->options;
5473 options1.client_guid = GUID_random();
5474 options1.min_protocol = PROTOCOL_SMB3_11;
5475 options1.max_protocol = PROTOCOL_SMB3_11;
5476 options1.signing = SMB_SIGNING_REQUIRED;
5477 options1.smb3_capabilities.encryption = (struct smb3_encryption_capabilities) {
5478 .num_algos = 1,
5479 .algos = {
5480 SMB2_ENCRYPTION_AES256_CCM,
5481 },
5482 };
5483
5484 ret = test_session_sign_enc(tctx,
5485 __func__,
5486 credentials,
5487 &options1);
5488 TALLOC_FREE(tree0);
5489 return ret;
5490 }
5491
5492 static bool test_session_encryption_aes_256_gcm(struct torture_context *tctx, struct smb2_tree *tree0)
5493 {
5494 struct cli_credentials *credentials0 = samba_cmdline_get_creds();
5495 struct cli_credentials *credentials = NULL;
5496 bool ret = false;
5497 struct smb2_transport *transport0 = tree0->session->transport;
5498 struct smbcli_options options1;
5499 bool ok;
5500
5501 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_11) {
5502 torture_skip(tctx,
5503 "Can't test without SMB 3.1.1 support");
5504 }
5505
5506 if (smb2cli_conn_server_signing_algo(transport0->conn) < SMB2_SIGNING_AES128_GMAC) {
5507 torture_skip(tctx,
5508 "Can't test without SMB 3.1.1 signing negotiation support");
5509 }
5510
5511 credentials = cli_credentials_shallow_copy(tctx, credentials0);
5512 torture_assert(tctx, credentials != NULL, "cli_credentials_shallow_copy");
5513 ok = cli_credentials_set_smb_encryption(credentials,
5514 SMB_ENCRYPTION_REQUIRED,
5515 CRED_SPECIFIED);
5516 torture_assert(tctx, ok, "cli_credentials_set_smb_encryption");
5517
5518 options1 = transport0->options;
5519 options1.client_guid = GUID_random();
5520 options1.min_protocol = PROTOCOL_SMB3_11;
5521 options1.max_protocol = PROTOCOL_SMB3_11;
5522 options1.signing = SMB_SIGNING_REQUIRED;
5523 options1.smb3_capabilities.encryption = (struct smb3_encryption_capabilities) {
5524 .num_algos = 1,
5525 .algos = {
5526 SMB2_ENCRYPTION_AES256_GCM,
5527 },
5528 };
5529
5530 ret = test_session_sign_enc(tctx,
5531 __func__,
5532 credentials,
5533 &options1);
5534 TALLOC_FREE(tree0);
5535 return ret;
5536 }
5537
5538 static bool test_session_ntlmssp_bug14932(struct torture_context *tctx, struct smb2_tree *tree)
5539 {
5540 struct cli_credentials *ntlm_creds =
5541 cli_credentials_shallow_copy(tctx, samba_cmdline_get_creds());
5542 NTSTATUS status;
5543 bool ret = true;
5544 /*
5545 * This is a NTLMv2_RESPONSE with the strange
5546 * NTLMv2_CLIENT_CHALLENGE used by the net diag
5547 * tool.
5548 *
5549 * As we expect an error anyway we fill the
5550 * Response part with 0xab...
5551 */
5552 static const char *netapp_magic =
5553 "\xab\xab\xab\xab\xab\xab\xab\xab"
5554 "\xab\xab\xab\xab\xab\xab\xab\xab"
5555 "\x01\x01\x00\x00\x00\x00\x00\x00"
5556 "\x3f\x3f\x3f\x3f\x3f\x3f\x3f\x3f"
5557 "\xb8\x82\x3a\xf1\xb3\xdd\x08\x15"
5558 "\x00\x00\x00\x00\x11\xa2\x08\x81"
5559 "\x50\x38\x22\x78\x2b\x94\x47\xfe"
5560 "\x54\x94\x7b\xff\x17\x27\x5a\xb4"
5561 "\xf4\x18\xba\xdc\x2c\x38\xfd\x5b"
5562 "\xfb\x0e\xc1\x85\x1e\xcc\x92\xbb"
5563 "\x9b\xb1\xc4\xd5\x53\x14\xff\x8c"
5564 "\x76\x49\xf5\x45\x90\x19\xa2";
5565 DATA_BLOB lm_response = data_blob_talloc_zero(tctx, 24);
5566 DATA_BLOB lm_session_key = data_blob_talloc_zero(tctx, 16);
5567 DATA_BLOB nt_response = data_blob_const(netapp_magic, 95);
5568 DATA_BLOB nt_session_key = data_blob_talloc_zero(tctx, 16);
5569
5570 cli_credentials_set_kerberos_state(ntlm_creds,
5571 CRED_USE_KERBEROS_DISABLED,
5572 CRED_SPECIFIED);
5573 cli_credentials_set_ntlm_response(ntlm_creds,
5574 &lm_response,
5575 &lm_session_key,
5576 &nt_response,
5577 &nt_session_key,
5578 CRED_SPECIFIED);
5579 status = smb2_session_setup_spnego(tree->session,
5580 ntlm_creds,
5581 0 /* previous_session_id */);
5582 torture_assert_ntstatus_equal(tctx, status, NT_STATUS_INVALID_PARAMETER,
5583 "smb2_session_setup_spnego failed");
5584
5585 return ret;
5586 }
5587
5588 static bool test_session_anon_encryption1(struct torture_context *tctx,
5589 struct smb2_tree *tree0)
5590 {
5591 const char *host = torture_setting_string(tctx, "host", NULL);
5592 const char *share = "IPC$";
5593 char *unc = NULL;
5594 struct smb2_transport *transport0 = tree0->session->transport;
5595 struct cli_credentials *anon_creds = NULL;
5596 struct smbcli_options options;
5597 struct smb2_transport *transport = NULL;
5598 struct smb2_session *anon_session = NULL;
5599 struct smb2_tree *anon_tree = NULL;
5600 NTSTATUS status;
5601 bool ok = true;
5602 struct tevent_req *subreq = NULL;
5603 uint32_t timeout_msec;
5604
5605 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_00) {
5606 torture_skip(tctx,
5607 "Can't test without SMB3 support");
5608 }
5609
5610 unc = talloc_asprintf(tctx, "\\\\%s\\%s", host, share);
5611 torture_assert(tctx, unc != NULL, "talloc_asprintf");
5612
5613 anon_creds = cli_credentials_init_anon(tctx);
5614 torture_assert(tctx, anon_creds != NULL, "cli_credentials_init_anon");
5615 ok = cli_credentials_set_smb_encryption(anon_creds,
5616 SMB_ENCRYPTION_REQUIRED,
5617 CRED_SPECIFIED);
5618 torture_assert(tctx, ok, "cli_credentials_set_smb_encryption");
5619
5620 options = transport0->options;
5621 options.client_guid = GUID_random();
5622 options.only_negprot = true;
5623
5624 status = smb2_connect(tctx,
5625 host,
5626 share,
5627 tctx->lp_ctx,
5628 lpcfg_resolve_context(tctx->lp_ctx),
5629 anon_creds,
5630 &anon_tree,
5631 tctx->ev,
5632 &options,
5633 lpcfg_socket_options(tctx->lp_ctx),
5634 lpcfg_gensec_settings(tctx, tctx->lp_ctx));
5635 torture_assert_ntstatus_ok(tctx, status, "smb2_connect failed");
5636 anon_session = anon_tree->session;
5637 transport = anon_session->transport;
5638
5639 anon_session->anonymous_session_key = true;
5640 smb2cli_session_torture_anonymous_encryption(anon_session->smbXcli, true);
5641
5642 status = smb2_session_setup_spnego(anon_session,
5643 anon_creds,
5644 0 /* previous_session_id */);
5645 torture_assert_ntstatus_ok(tctx, status,
5646 "smb2_session_setup_spnego failed");
5647
5648 ok = smbXcli_session_is_authenticated(anon_session->smbXcli);
5649 torture_assert(tctx, !ok, "smbXcli_session_is_authenticated(anon) wrong");
5650
5651 /*
5652 * The connection is still in ConstrainedConnection state...
5653 *
5654 * This will use encryption and causes a connection reset
5655 */
5656 timeout_msec = transport->options.request_timeout * 1000;
5657 subreq = smb2cli_tcon_send(tctx,
5658 tctx->ev,
5659 transport->conn,
5660 timeout_msec,
5661 anon_session->smbXcli,
5662 anon_tree->smbXcli,
5663 0, /* flags */
5664 unc);
5665 torture_assert(tctx, subreq != NULL, "smb2cli_tcon_send");
5666
5667 torture_assert(tctx,
5668 tevent_req_poll_ntstatus(subreq, tctx->ev, &status),
5669 "tevent_req_poll_ntstatus");
5670
5671 status = smb2cli_tcon_recv(subreq);
5672 TALLOC_FREE(subreq);
5673 if (NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_DISCONNECTED)) {
5674 status = NT_STATUS_CONNECTION_RESET;
5675 }
5676 torture_assert_ntstatus_equal(tctx, status,
5677 NT_STATUS_CONNECTION_RESET,
5678 "smb2cli_tcon_recv");
5679
5680 ok = smbXcli_conn_is_connected(transport->conn);
5681 torture_assert(tctx, !ok, "smbXcli_conn_is_connected still connected");
5682
5683 return true;
5684 }
5685
5686 static bool test_session_anon_encryption2(struct torture_context *tctx,
5687 struct smb2_tree *tree0)
5688 {
5689 const char *host = torture_setting_string(tctx, "host", NULL);
5690 const char *share = "IPC$";
5691 char *unc = NULL;
5692 struct smb2_transport *transport0 = tree0->session->transport;
5693 struct cli_credentials *_creds = samba_cmdline_get_creds();
5694 struct cli_credentials *user_creds = NULL;
5695 struct cli_credentials *anon_creds = NULL;
5696 struct smbcli_options options;
5697 struct smb2_transport *transport = NULL;
5698 struct smb2_session *user_session = NULL;
5699 struct smb2_tree *user_tree = NULL;
5700 struct smb2_session *anon_session = NULL;
5701 struct smb2_tree *anon_tree = NULL;
5702 struct smb2_ioctl ioctl = {
5703 .level = RAW_IOCTL_SMB2,
5704 .in = {
5705 .file = {
5706 .handle = {
5707 .data = {
5708 [0] = UINT64_MAX,
5709 [1] = UINT64_MAX,
5710 },
5711 },
5712 },
5713 .function = FSCTL_QUERY_NETWORK_INTERFACE_INFO,
5714 /* Windows client sets this to 64KiB */
5715 .max_output_response = 0x10000,
5716 .flags = SMB2_IOCTL_FLAG_IS_FSCTL,
5717 },
5718 };
5719 NTSTATUS status;
5720 bool ok = true;
5721 struct tevent_req *subreq = NULL;
5722 uint32_t timeout_msec;
5723 uint32_t caps = smb2cli_conn_server_capabilities(transport0->conn);
5724 NTSTATUS expected_mc_status;
5725
5726 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_00) {
5727 torture_skip(tctx,
5728 "Can't test without SMB3 support");
5729 }
5730
5731 if (caps & SMB2_CAP_MULTI_CHANNEL) {
5732 expected_mc_status = NT_STATUS_OK;
5733 } else {
5734 expected_mc_status = NT_STATUS_FS_DRIVER_REQUIRED;
5735 }
5736
5737 unc = talloc_asprintf(tctx, "\\\\%s\\%s", host, share);
5738 torture_assert(tctx, unc != NULL, "talloc_asprintf");
5739
5740 user_creds = cli_credentials_shallow_copy(tctx, _creds);
5741 torture_assert(tctx, user_creds != NULL, "cli_credentials_shallow_copy");
5742 ok = cli_credentials_set_smb_encryption(user_creds,
5743 SMB_ENCRYPTION_REQUIRED,
5744 CRED_SPECIFIED);
5745 torture_assert(tctx, ok, "cli_credentials_set_smb_encryption");
5746
5747 anon_creds = cli_credentials_init_anon(tctx);
5748 torture_assert(tctx, anon_creds != NULL, "cli_credentials_init_anon");
5749 ok = cli_credentials_set_smb_encryption(anon_creds,
5750 SMB_ENCRYPTION_REQUIRED,
5751 CRED_SPECIFIED);
5752 torture_assert(tctx, ok, "cli_credentials_set_smb_encryption");
5753
5754 options = transport0->options;
5755 options.client_guid = GUID_random();
5756
5757 status = smb2_connect(tctx,
5758 host,
5759 share,
5760 tctx->lp_ctx,
5761 lpcfg_resolve_context(tctx->lp_ctx),
5762 user_creds,
5763 &user_tree,
5764 tctx->ev,
5765 &options,
5766 lpcfg_socket_options(tctx->lp_ctx),
5767 lpcfg_gensec_settings(tctx, tctx->lp_ctx));
5768 torture_assert_ntstatus_ok(tctx, status, "smb2_connect failed");
5769 user_session = user_tree->session;
5770 transport = user_session->transport;
5771 ok = smb2cli_tcon_is_encryption_on(user_tree->smbXcli);
5772 torture_assert(tctx, ok, "smb2cli_tcon_is_encryption_on(user)");
5773 ok = smbXcli_session_is_authenticated(user_session->smbXcli);
5774 torture_assert(tctx, ok, "smbXcli_session_is_authenticated(user)");
5775
5776 anon_session = smb2_session_init(transport,
5777 tctx->lp_ctx,
5778 lpcfg_gensec_settings(tctx, tctx->lp_ctx),
5779 tctx);
5780 torture_assert(tctx, anon_session != NULL, "smb2_session_init(anon)");
5781
5782 anon_session->anonymous_session_key = true;
5783 smb2cli_session_torture_anonymous_encryption(anon_session->smbXcli, true);
5784
5785 status = smb2_session_setup_spnego(anon_session,
5786 anon_creds,
5787 0 /* previous_session_id */);
5788 torture_assert_ntstatus_ok(tctx, status,
5789 "smb2_session_setup_spnego failed");
5790
5791 ok = smb2cli_tcon_is_encryption_on(user_tree->smbXcli);
5792 torture_assert(tctx, ok, "smb2cli_tcon_is_encryption_on(anon)");
5793 ok = smbXcli_session_is_authenticated(anon_session->smbXcli);
5794 torture_assert(tctx, !ok, "smbXcli_session_is_authenticated(anon) wrong");
5795
5796 anon_tree = smb2_tree_init(anon_session, tctx, false);
5797 torture_assert(tctx, anon_tree != NULL, "smb2_tree_init");
5798
5799 timeout_msec = transport->options.request_timeout * 1000;
5800 subreq = smb2cli_tcon_send(tctx,
5801 tctx->ev,
5802 transport->conn,
5803 timeout_msec,
5804 anon_session->smbXcli,
5805 anon_tree->smbXcli,
5806 0, /* flags */
5807 unc);
5808 torture_assert(tctx, subreq != NULL, "smb2cli_tcon_send");
5809
5810 torture_assert(tctx,
5811 tevent_req_poll_ntstatus(subreq, tctx->ev, &status),
5812 "tevent_req_poll_ntstatus");
5813
5814 status = smb2cli_tcon_recv(subreq);
5815 TALLOC_FREE(subreq);
5816 torture_assert_ntstatus_ok(tctx, status,
5817 "smb2cli_tcon_recv(anon)");
5818
5819 ok = smbXcli_conn_is_connected(transport->conn);
5820 torture_assert(tctx, ok, "smbXcli_conn_is_connected");
5821
5822 ok = smb2cli_tcon_is_encryption_on(anon_tree->smbXcli);
5823 torture_assert(tctx, ok, "smb2cli_tcon_is_encryption_on(anon)");
5824 ok = smbXcli_session_is_authenticated(anon_session->smbXcli);
5825 torture_assert(tctx, !ok, "smbXcli_session_is_authenticated(anon) wrong");
5826
5827 status = smb2_ioctl(user_tree, tctx, &ioctl);
5828 torture_assert_ntstatus_equal(tctx, status, expected_mc_status,
5829 "FSCTL_QUERY_NETWORK_INTERFACE_INFO user");
5830
5831 ok = smbXcli_conn_is_connected(transport->conn);
5832 torture_assert(tctx, ok, "smbXcli_conn_is_connected");
5833
5834 status = smb2_ioctl(anon_tree, tctx, &ioctl);
5835 torture_assert_ntstatus_equal(tctx, status, expected_mc_status,
5836 "FSCTL_QUERY_NETWORK_INTERFACE_INFO anonymous");
5837
5838 ok = smbXcli_conn_is_connected(transport->conn);
5839 torture_assert(tctx, ok, "smbXcli_conn_is_connected");
5840
5841 status = smb2_ioctl(user_tree, tctx, &ioctl);
5842 torture_assert_ntstatus_equal(tctx, status, expected_mc_status,
5843 "FSCTL_QUERY_NETWORK_INTERFACE_INFO user");
5844
5845 ok = smbXcli_conn_is_connected(transport->conn);
5846 torture_assert(tctx, ok, "smbXcli_conn_is_connected");
5847
5848 status = smb2_ioctl(anon_tree, tctx, &ioctl);
5849 torture_assert_ntstatus_equal(tctx, status, expected_mc_status,
5850 "FSCTL_QUERY_NETWORK_INTERFACE_INFO anonymous");
5851
5852 ok = smbXcli_conn_is_connected(transport->conn);
5853 torture_assert(tctx, ok, "smbXcli_conn_is_connected");
5854
5855 return true;
5856 }
5857
5858 static bool test_session_anon_encryption3(struct torture_context *tctx,
5859 struct smb2_tree *tree0)
5860 {
5861 const char *host = torture_setting_string(tctx, "host", NULL);
5862 const char *share = "IPC$";
5863 char *unc = NULL;
5864 struct smb2_transport *transport0 = tree0->session->transport;
5865 struct cli_credentials *_creds = samba_cmdline_get_creds();
5866 struct cli_credentials *user_creds = NULL;
5867 struct cli_credentials *anon_creds = NULL;
5868 struct smbcli_options options;
5869 struct smb2_transport *transport = NULL;
5870 struct smb2_session *user_session = NULL;
5871 struct smb2_tree *user_tree = NULL;
5872 struct smb2_session *anon_session = NULL;
5873 struct smb2_tree *anon_tree = NULL;
5874 NTSTATUS status;
5875 bool ok = true;
5876 struct tevent_req *subreq = NULL;
5877 uint32_t timeout_msec;
5878 uint8_t wrong_session_key[16] = { 0x1f, 0x2f, 0x3f, };
5879
5880 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_00) {
5881 torture_skip(tctx,
5882 "Can't test without SMB3 support");
5883 }
5884
5885 unc = talloc_asprintf(tctx, "\\\\%s\\%s", host, share);
5886 torture_assert(tctx, unc != NULL, "talloc_asprintf");
5887
5888 user_creds = cli_credentials_shallow_copy(tctx, _creds);
5889 torture_assert(tctx, user_creds != NULL, "cli_credentials_shallow_copy");
5890 ok = cli_credentials_set_smb_encryption(user_creds,
5891 SMB_ENCRYPTION_REQUIRED,
5892 CRED_SPECIFIED);
5893 torture_assert(tctx, ok, "cli_credentials_set_smb_encryption");
5894
5895 anon_creds = cli_credentials_init_anon(tctx);
5896 torture_assert(tctx, anon_creds != NULL, "cli_credentials_init_anon");
5897 ok = cli_credentials_set_smb_encryption(anon_creds,
5898 SMB_ENCRYPTION_REQUIRED,
5899 CRED_SPECIFIED);
5900 torture_assert(tctx, ok, "cli_credentials_set_smb_encryption");
5901
5902 options = transport0->options;
5903 options.client_guid = GUID_random();
5904
5905 status = smb2_connect(tctx,
5906 host,
5907 share,
5908 tctx->lp_ctx,
5909 lpcfg_resolve_context(tctx->lp_ctx),
5910 user_creds,
5911 &user_tree,
5912 tctx->ev,
5913 &options,
5914 lpcfg_socket_options(tctx->lp_ctx),
5915 lpcfg_gensec_settings(tctx, tctx->lp_ctx));
5916 torture_assert_ntstatus_ok(tctx, status, "smb2_connect failed");
5917 user_session = user_tree->session;
5918 transport = user_session->transport;
5919 ok = smb2cli_tcon_is_encryption_on(user_tree->smbXcli);
5920 torture_assert(tctx, ok, "smb2cli_tcon_is_encryption_on(user)");
5921 ok = smbXcli_session_is_authenticated(user_session->smbXcli);
5922 torture_assert(tctx, ok, "smbXcli_session_is_authenticated(user)");
5923
5924 anon_session = smb2_session_init(transport,
5925 tctx->lp_ctx,
5926 lpcfg_gensec_settings(tctx, tctx->lp_ctx),
5927 tctx);
5928 torture_assert(tctx, anon_session != NULL, "smb2_session_init(anon)");
5929
5930 anon_session->anonymous_session_key = true;
5931 anon_session->forced_session_key = data_blob_const(wrong_session_key,
5932 ARRAY_SIZE(wrong_session_key));
5933 smb2cli_session_torture_anonymous_encryption(anon_session->smbXcli, true);
5934
5935 status = smb2_session_setup_spnego(anon_session,
5936 anon_creds,
5937 0 /* previous_session_id */);
5938 torture_assert_ntstatus_ok(tctx, status,
5939 "smb2_session_setup_spnego failed");
5940
5941 ok = smb2cli_tcon_is_encryption_on(user_tree->smbXcli);
5942 torture_assert(tctx, ok, "smb2cli_tcon_is_encryption_on(anon)");
5943 ok = smbXcli_session_is_authenticated(anon_session->smbXcli);
5944 torture_assert(tctx, !ok, "smbXcli_session_is_authenticated(anon) wrong");
5945
5946 anon_tree = smb2_tree_init(anon_session, tctx, false);
5947 torture_assert(tctx, anon_tree != NULL, "smb2_tree_init");
5948
5949 timeout_msec = transport->options.request_timeout * 1000;
5950 subreq = smb2cli_tcon_send(tctx,
5951 tctx->ev,
5952 transport->conn,
5953 timeout_msec,
5954 anon_session->smbXcli,
5955 anon_tree->smbXcli,
5956 0, /* flags */
5957 unc);
5958 torture_assert(tctx, subreq != NULL, "smb2cli_tcon_send");
5959
5960 torture_assert(tctx,
5961 tevent_req_poll_ntstatus(subreq, tctx->ev, &status),
5962 "tevent_req_poll_ntstatus");
5963
5964 status = smb2cli_tcon_recv(subreq);
5965 TALLOC_FREE(subreq);
5966 if (NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_DISCONNECTED)) {
5967 status = NT_STATUS_CONNECTION_RESET;
5968 }
5969 torture_assert_ntstatus_equal(tctx, status,
5970 NT_STATUS_CONNECTION_RESET,
5971 "smb2cli_tcon_recv");
5972
5973 ok = smbXcli_conn_is_connected(transport->conn);
5974 torture_assert(tctx, !ok, "smbXcli_conn_is_connected still connected");
5975
5976 return true;
5977 }
5978
5979 static bool test_session_anon_signing1(struct torture_context *tctx,
5980 struct smb2_tree *tree0)
5981 {
5982 const char *host = torture_setting_string(tctx, "host", NULL);
5983 const char *share = "IPC$";
5984 char *unc = NULL;
5985 struct smb2_transport *transport0 = tree0->session->transport;
5986 struct cli_credentials *anon_creds = NULL;
5987 struct smbcli_options options;
5988 struct smb2_transport *transport = NULL;
5989 struct smb2_session *anon_session = NULL;
5990 struct smb2_tree *anon_tree = NULL;
5991 NTSTATUS status;
5992 bool ok = true;
5993 struct tevent_req *subreq = NULL;
5994 uint32_t timeout_msec;
5995
5996 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_00) {
5997 torture_skip(tctx,
5998 "Can't test without SMB3 support");
5999 }
6000
6001 unc = talloc_asprintf(tctx, "\\\\%s\\%s", host, share);
6002 torture_assert(tctx, unc != NULL, "talloc_asprintf");
6003
6004 anon_creds = cli_credentials_init_anon(tctx);
6005 torture_assert(tctx, anon_creds != NULL, "cli_credentials_init_anon");
6006 ok = cli_credentials_set_smb_signing(anon_creds,
6007 SMB_SIGNING_REQUIRED,
6008 CRED_SPECIFIED);
6009 torture_assert(tctx, ok, "cli_credentials_set_smb_signing");
6010 ok = cli_credentials_set_smb_ipc_signing(anon_creds,
6011 SMB_SIGNING_REQUIRED,
6012 CRED_SPECIFIED);
6013 torture_assert(tctx, ok, "cli_credentials_set_smb_ipc_signing");
6014 ok = cli_credentials_set_smb_encryption(anon_creds,
6015 SMB_ENCRYPTION_OFF,
6016 CRED_SPECIFIED);
6017 torture_assert(tctx, ok, "cli_credentials_set_smb_encryption");
6018
6019 options = transport0->options;
6020 options.client_guid = GUID_random();
6021 options.only_negprot = true;
6022 options.signing = SMB_SIGNING_REQUIRED;
6023
6024 status = smb2_connect(tctx,
6025 host,
6026 share,
6027 tctx->lp_ctx,
6028 lpcfg_resolve_context(tctx->lp_ctx),
6029 anon_creds,
6030 &anon_tree,
6031 tctx->ev,
6032 &options,
6033 lpcfg_socket_options(tctx->lp_ctx),
6034 lpcfg_gensec_settings(tctx, tctx->lp_ctx));
6035 torture_assert_ntstatus_ok(tctx, status, "smb2_connect failed");
6036 anon_session = anon_tree->session;
6037 transport = anon_session->transport;
6038
6039 anon_session->anonymous_session_key = true;
6040 smb2cli_session_torture_anonymous_signing(anon_session->smbXcli, true);
6041
6042 status = smb2_session_setup_spnego(anon_session,
6043 anon_creds,
6044 0 /* previous_session_id */);
6045 torture_assert_ntstatus_ok(tctx, status,
6046 "smb2_session_setup_spnego failed");
6047
6048 ok = smbXcli_session_is_authenticated(anon_session->smbXcli);
6049 torture_assert(tctx, !ok, "smbXcli_session_is_authenticated(anon) wrong");
6050
6051 timeout_msec = transport->options.request_timeout * 1000;
6052 subreq = smb2cli_tcon_send(tctx,
6053 tctx->ev,
6054 transport->conn,
6055 timeout_msec,
6056 anon_session->smbXcli,
6057 anon_tree->smbXcli,
6058 0, /* flags */
6059 unc);
6060 torture_assert(tctx, subreq != NULL, "smb2cli_tcon_send");
6061
6062 torture_assert(tctx,
6063 tevent_req_poll_ntstatus(subreq, tctx->ev, &status),
6064 "tevent_req_poll_ntstatus");
6065
6066 status = smb2cli_tcon_recv(subreq);
6067 TALLOC_FREE(subreq);
6068 torture_assert_ntstatus_ok(tctx, status, "smb2cli_tcon_recv");
6069
6070 ok = smbXcli_conn_is_connected(transport->conn);
6071 torture_assert(tctx, ok, "smbXcli_conn_is_connected");
6072
6073 return true;
6074 }
6075
6076 static bool test_session_anon_signing2(struct torture_context *tctx,
6077 struct smb2_tree *tree0)
6078 {
6079 const char *host = torture_setting_string(tctx, "host", NULL);
6080 const char *share = "IPC$";
6081 char *unc = NULL;
6082 struct smb2_transport *transport0 = tree0->session->transport;
6083 struct cli_credentials *anon_creds = NULL;
6084 struct smbcli_options options;
6085 struct smb2_transport *transport = NULL;
6086 struct smb2_session *anon_session = NULL;
6087 struct smb2_session *anon_session_nosign = NULL;
6088 struct smb2_tree *anon_tree = NULL;
6089 NTSTATUS status;
6090 bool ok = true;
6091 struct tevent_req *subreq = NULL;
6092 uint32_t timeout_msec;
6093 uint8_t wrong_session_key[16] = { 0x1f, 0x2f, 0x3f, };
6094 uint64_t session_id;
6095
6096 if (smbXcli_conn_protocol(transport0->conn) < PROTOCOL_SMB3_00) {
6097 torture_skip(tctx,
6098 "Can't test without SMB3 support");
6099 }
6100
6101 unc = talloc_asprintf(tctx, "\\\\%s\\%s", host, share);
6102 torture_assert(tctx, unc != NULL, "talloc_asprintf");
6103
6104 anon_creds = cli_credentials_init_anon(tctx);
6105 torture_assert(tctx, anon_creds != NULL, "cli_credentials_init_anon");
6106 ok = cli_credentials_set_smb_signing(anon_creds,
6107 SMB_SIGNING_REQUIRED,
6108 CRED_SPECIFIED);
6109 torture_assert(tctx, ok, "cli_credentials_set_smb_signing");
6110 ok = cli_credentials_set_smb_ipc_signing(anon_creds,
6111 SMB_SIGNING_REQUIRED,
6112 CRED_SPECIFIED);
6113 torture_assert(tctx, ok, "cli_credentials_set_smb_ipc_signing");
6114 ok = cli_credentials_set_smb_encryption(anon_creds,
6115 SMB_ENCRYPTION_OFF,
6116 CRED_SPECIFIED);
6117 torture_assert(tctx, ok, "cli_credentials_set_smb_encryption");
6118
6119 options = transport0->options;
6120 options.client_guid = GUID_random();
6121 options.only_negprot = true;
6122 options.signing = SMB_SIGNING_REQUIRED;
6123
6124 status = smb2_connect(tctx,
6125 host,
6126 share,
6127 tctx->lp_ctx,
6128 lpcfg_resolve_context(tctx->lp_ctx),
6129 anon_creds,
6130 &anon_tree,
6131 tctx->ev,
6132 &options,
6133 lpcfg_socket_options(tctx->lp_ctx),
6134 lpcfg_gensec_settings(tctx, tctx->lp_ctx));
6135 torture_assert_ntstatus_ok(tctx, status, "smb2_connect failed");
6136 anon_session = anon_tree->session;
6137 transport = anon_session->transport;
6138
6139 anon_session->anonymous_session_key = true;
6140 anon_session->forced_session_key = data_blob_const(wrong_session_key,
6141 ARRAY_SIZE(wrong_session_key));
6142 smb2cli_session_torture_anonymous_signing(anon_session->smbXcli, true);
6143 smb2cli_session_torture_no_signing_disconnect(anon_session->smbXcli);
6144
6145 status = smb2_session_setup_spnego(anon_session,
6146 anon_creds,
6147 0 /* previous_session_id */);
6148 torture_assert_ntstatus_ok(tctx, status,
6149 "smb2_session_setup_spnego failed");
6150
6151 ok = smbXcli_session_is_authenticated(anon_session->smbXcli);
6152 torture_assert(tctx, !ok, "smbXcli_session_is_authenticated(anon) wrong");
6153
6154 /*
6155 * create a new structure for the same session id,
6156 * but without smb2.should_sign set.
6157 */
6158 session_id = smb2cli_session_current_id(anon_session->smbXcli);
6159 anon_session_nosign = smb2_session_init(transport,
6160 tctx->lp_ctx,
6161 lpcfg_gensec_settings(tctx, tctx->lp_ctx),
6162 tctx);
6163 torture_assert(tctx, anon_session_nosign != NULL, "smb2_session_init(anon_nosign)");
6164 smb2cli_session_set_id_and_flags(anon_session_nosign->smbXcli, session_id, 0);
6165 smb2cli_session_torture_no_signing_disconnect(anon_session_nosign->smbXcli);
6166
6167 timeout_msec = transport->options.request_timeout * 1000;
6168 subreq = smb2cli_tcon_send(tctx,
6169 tctx->ev,
6170 transport->conn,
6171 timeout_msec,
6172 anon_session->smbXcli,
6173 anon_tree->smbXcli,
6174 0, /* flags */
6175 unc);
6176 torture_assert(tctx, subreq != NULL, "smb2cli_tcon_send");
6177
6178 torture_assert(tctx,
6179 tevent_req_poll_ntstatus(subreq, tctx->ev, &status),
6180 "tevent_req_poll_ntstatus");
6181
6182 status = smb2cli_tcon_recv(subreq);
6183 TALLOC_FREE(subreq);
6184 torture_assert_ntstatus_equal(tctx, status,
6185 NT_STATUS_ACCESS_DENIED,
6186 "smb2cli_tcon_recv");
6187
6188 ok = smbXcli_conn_is_connected(transport->conn);
6189 torture_assert(tctx, ok, "smbXcli_conn_is_connected");
6190
6191 subreq = smb2cli_tcon_send(tctx,
6192 tctx->ev,
6193 transport->conn,
6194 timeout_msec,
6195 anon_session_nosign->smbXcli,
6196 anon_tree->smbXcli,
6197 0, /* flags */
6198 unc);
6199 torture_assert(tctx, subreq != NULL, "smb2cli_tcon_send");
6200
6201 torture_assert(tctx,
6202 tevent_req_poll_ntstatus(subreq, tctx->ev, &status),
6203 "tevent_req_poll_ntstatus");
6204
6205 status = smb2cli_tcon_recv(subreq);
6206 TALLOC_FREE(subreq);
6207 torture_assert_ntstatus_ok(tctx, status, "smb2cli_tcon_recv");
6208
6209 ok = smbXcli_conn_is_connected(transport->conn);
6210 torture_assert(tctx, ok, "smbXcli_conn_is_connected");
6211
6212 return true;
6213 }
6214
6215 struct torture_suite *torture_smb2_session_init(TALLOC_CTX *ctx)
6216 {
6217 struct torture_suite *suite =
6218 torture_suite_create(ctx, "session");
6219
6220 torture_suite_add_1smb2_test(suite, "reconnect1", test_session_reconnect1);
6221 torture_suite_add_1smb2_test(suite, "reconnect2", test_session_reconnect2);
6222 torture_suite_add_1smb2_test(suite, "reauth1", test_session_reauth1);
6223 torture_suite_add_1smb2_test(suite, "reauth2", test_session_reauth2);
6224 torture_suite_add_1smb2_test(suite, "reauth3", test_session_reauth3);
6225 torture_suite_add_1smb2_test(suite, "reauth4", test_session_reauth4);
6226 torture_suite_add_1smb2_test(suite, "reauth5", test_session_reauth5);
6227 torture_suite_add_1smb2_test(suite, "reauth6", test_session_reauth6);
6228 torture_suite_add_simple_test(suite, "expire1n", test_session_expire1n);
6229 torture_suite_add_simple_test(suite, "expire1s", test_session_expire1s);
6230 torture_suite_add_simple_test(suite, "expire1e", test_session_expire1e);
6231 torture_suite_add_simple_test(suite, "expire2s", test_session_expire2s);
6232 torture_suite_add_simple_test(suite, "expire2e", test_session_expire2e);
6233 torture_suite_add_simple_test(suite, "expire_disconnect",
6234 test_session_expire_disconnect);
6235 torture_suite_add_1smb2_test(suite, "bind1", test_session_bind1);
6236 torture_suite_add_1smb2_test(suite, "bind2", test_session_bind2);
6237 torture_suite_add_1smb2_test(suite, "bind_invalid_auth", test_session_bind_invalid_auth);
6238 torture_suite_add_1smb2_test(suite, "bind_different_user", test_session_bind_different_user);
6239 torture_suite_add_1smb2_test(suite, "bind_negative_smb202", test_session_bind_negative_smb202);
6240 torture_suite_add_1smb2_test(suite, "bind_negative_smb210s", test_session_bind_negative_smb210s);
6241 torture_suite_add_1smb2_test(suite, "bind_negative_smb210d", test_session_bind_negative_smb210d);
6242 torture_suite_add_1smb2_test(suite, "bind_negative_smb2to3s", test_session_bind_negative_smb2to3s);
6243 torture_suite_add_1smb2_test(suite, "bind_negative_smb2to3d", test_session_bind_negative_smb2to3d);
6244 torture_suite_add_1smb2_test(suite, "bind_negative_smb3to2s", test_session_bind_negative_smb3to2s);
6245 torture_suite_add_1smb2_test(suite, "bind_negative_smb3to2d", test_session_bind_negative_smb3to2d);
6246 torture_suite_add_1smb2_test(suite, "bind_negative_smb3to3s", test_session_bind_negative_smb3to3s);
6247 torture_suite_add_1smb2_test(suite, "bind_negative_smb3to3d", test_session_bind_negative_smb3to3d);
6248 torture_suite_add_1smb2_test(suite, "bind_negative_smb3encGtoCs", test_session_bind_negative_smb3encGtoCs);
6249 torture_suite_add_1smb2_test(suite, "bind_negative_smb3encGtoCd", test_session_bind_negative_smb3encGtoCd);
6250 torture_suite_add_1smb2_test(suite, "bind_negative_smb3signCtoHs", test_session_bind_negative_smb3signCtoHs);
6251 torture_suite_add_1smb2_test(suite, "bind_negative_smb3signCtoHd", test_session_bind_negative_smb3signCtoHd);
6252 torture_suite_add_1smb2_test(suite, "bind_negative_smb3signCtoGs", test_session_bind_negative_smb3signCtoGs);
6253 torture_suite_add_1smb2_test(suite, "bind_negative_smb3signCtoGd", test_session_bind_negative_smb3signCtoGd);
6254 torture_suite_add_1smb2_test(suite, "bind_negative_smb3signHtoCs", test_session_bind_negative_smb3signHtoCs);
6255 torture_suite_add_1smb2_test(suite, "bind_negative_smb3signHtoCd", test_session_bind_negative_smb3signHtoCd);
6256 torture_suite_add_1smb2_test(suite, "bind_negative_smb3signHtoGs", test_session_bind_negative_smb3signHtoGs);
6257 torture_suite_add_1smb2_test(suite, "bind_negative_smb3signHtoGd", test_session_bind_negative_smb3signHtoGd);
6258 torture_suite_add_1smb2_test(suite, "bind_negative_smb3signGtoCs", test_session_bind_negative_smb3signGtoCs);
6259 torture_suite_add_1smb2_test(suite, "bind_negative_smb3signGtoCd", test_session_bind_negative_smb3signGtoCd);
6260 torture_suite_add_1smb2_test(suite, "bind_negative_smb3signGtoHs", test_session_bind_negative_smb3signGtoHs);
6261 torture_suite_add_1smb2_test(suite, "bind_negative_smb3signGtoHd", test_session_bind_negative_smb3signGtoHd);
6262 torture_suite_add_1smb2_test(suite, "bind_negative_smb3sneGtoCs", test_session_bind_negative_smb3sneGtoCs);
6263 torture_suite_add_1smb2_test(suite, "bind_negative_smb3sneGtoCd", test_session_bind_negative_smb3sneGtoCd);
6264 torture_suite_add_1smb2_test(suite, "bind_negative_smb3sneGtoHs", test_session_bind_negative_smb3sneGtoHs);
6265 torture_suite_add_1smb2_test(suite, "bind_negative_smb3sneGtoHd", test_session_bind_negative_smb3sneGtoHd);
6266 torture_suite_add_1smb2_test(suite, "bind_negative_smb3sneCtoGs", test_session_bind_negative_smb3sneCtoGs);
6267 torture_suite_add_1smb2_test(suite, "bind_negative_smb3sneCtoGd", test_session_bind_negative_smb3sneCtoGd);
6268 torture_suite_add_1smb2_test(suite, "bind_negative_smb3sneHtoGs", test_session_bind_negative_smb3sneHtoGs);
6269 torture_suite_add_1smb2_test(suite, "bind_negative_smb3sneHtoGd", test_session_bind_negative_smb3sneHtoGd);
6270 torture_suite_add_1smb2_test(suite, "bind_negative_smb3signC30toGs", test_session_bind_negative_smb3signC30toGs);
6271 torture_suite_add_1smb2_test(suite, "bind_negative_smb3signC30toGd", test_session_bind_negative_smb3signC30toGd);
6272 torture_suite_add_1smb2_test(suite, "bind_negative_smb3signH2XtoGs", test_session_bind_negative_smb3signH2XtoGs);
6273 torture_suite_add_1smb2_test(suite, "bind_negative_smb3signH2XtoGd", test_session_bind_negative_smb3signH2XtoGd);
6274 torture_suite_add_1smb2_test(suite, "bind_negative_smb3signGtoC30s", test_session_bind_negative_smb3signGtoC30s);
6275 torture_suite_add_1smb2_test(suite, "bind_negative_smb3signGtoC30d", test_session_bind_negative_smb3signGtoC30d);
6276 torture_suite_add_1smb2_test(suite, "bind_negative_smb3signGtoH2Xs", test_session_bind_negative_smb3signGtoH2Xs);
6277 torture_suite_add_1smb2_test(suite, "bind_negative_smb3signGtoH2Xd", test_session_bind_negative_smb3signGtoH2Xd);
6278 torture_suite_add_1smb2_test(suite, "two_logoff", test_session_two_logoff);
6279 torture_suite_add_1smb2_test(suite, "signing-hmac-sha-256", test_session_signing_hmac_sha_256);
6280 torture_suite_add_1smb2_test(suite, "signing-aes-128-cmac", test_session_signing_aes_128_cmac);
6281 torture_suite_add_1smb2_test(suite, "signing-aes-128-gmac", test_session_signing_aes_128_gmac);
6282 torture_suite_add_1smb2_test(suite, "encryption-aes-128-ccm", test_session_encryption_aes_128_ccm);
6283 torture_suite_add_1smb2_test(suite, "encryption-aes-128-gcm", test_session_encryption_aes_128_gcm);
6284 torture_suite_add_1smb2_test(suite, "encryption-aes-256-ccm", test_session_encryption_aes_256_ccm);
6285 torture_suite_add_1smb2_test(suite, "encryption-aes-256-gcm", test_session_encryption_aes_256_gcm);
6286 torture_suite_add_1smb2_test(suite, "ntlmssp_bug14932", test_session_ntlmssp_bug14932);
6287 torture_suite_add_1smb2_test(suite, "anon-encryption1", test_session_anon_encryption1);
6288 torture_suite_add_1smb2_test(suite, "anon-encryption2", test_session_anon_encryption2);
6289 torture_suite_add_1smb2_test(suite, "anon-encryption3", test_session_anon_encryption3);
6290 torture_suite_add_1smb2_test(suite, "anon-signing1", test_session_anon_signing1);
6291 torture_suite_add_1smb2_test(suite, "anon-signing2", test_session_anon_signing2);
6292
6293 suite->description = talloc_strdup(suite, "SMB2-SESSION tests");
6294
6295 return suite;
6296 }
6297
6298 static bool test_session_require_sign_bug15397(struct torture_context *tctx,
6299 struct smb2_tree *_tree)
6300 {
6301 const char *host = torture_setting_string(tctx, "host", NULL);
6302 const char *share = torture_setting_string(tctx, "share", NULL);
6303 struct cli_credentials *_creds = samba_cmdline_get_creds();
6304 struct cli_credentials *creds = NULL;
6305 struct smbcli_options options;
6306 struct smb2_tree *tree = NULL;
6307 uint8_t security_mode;
6308 NTSTATUS status;
6309 bool ok = true;
6310
6311 /*
6312 * Setup our own connection so we can control the signing flags
6313 */
6314
6315 creds = cli_credentials_shallow_copy(tctx, _creds);
6316 torture_assert(tctx, creds != NULL, "cli_credentials_shallow_copy");
6317
6318 options = _tree->session->transport->options;
6319 options.client_guid = GUID_random();
6320 options.signing = SMB_SIGNING_IF_REQUIRED;
6321
6322 status = smb2_connect(tctx,
6323 host,
6324 share,
6325 tctx->lp_ctx,
6326 lpcfg_resolve_context(tctx->lp_ctx),
6327 creds,
6328 &tree,
6329 tctx->ev,
6330 &options,
6331 lpcfg_socket_options(tctx->lp_ctx),
6332 lpcfg_gensec_settings(tctx, tctx->lp_ctx));
6333 torture_assert_ntstatus_ok_goto(tctx, status, ok, done,
6334 "smb2_connect failed");
6335
6336 security_mode = smb2cli_session_security_mode(tree->session->smbXcli);
6337
6338 torture_assert_int_equal_goto(
6339 tctx,
6340 security_mode,
6341 SMB2_NEGOTIATE_SIGNING_REQUIRED | SMB2_NEGOTIATE_SIGNING_ENABLED,
6342 ok,
6343 done,
6344 "Signing not required");
6345
6346 done:
6347 return ok;
6348 }
6349
6350 struct torture_suite *torture_smb2_session_req_sign_init(TALLOC_CTX *ctx)
6351 {
6352 struct torture_suite *suite =
6353 torture_suite_create(ctx, "session-require-signing");
6354
6355 torture_suite_add_1smb2_test(suite, "bug15397",
6356 test_session_require_sign_bug15397);
6357
6358 suite->description = talloc_strdup(suite, "SMB2-SESSION require signing tests");
6359 return suite;
6360 }