2 Unix SMB/CIFS implementation.
3 Initial test for the smb2 client lib
4 Copyright (C) Volker Lendecke 2011
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "torture/proto.h"
23 #include "../libcli/smb/smbXcli_base.h"
24 #include "libsmb/smb2cli.h"
25 #include "libcli/security/security.h"
26 #include "libsmb/proto.h"
27 #include "../auth/ntlmssp/ntlmssp.h"
29 extern fstring host, workgroup, share, password, username, myname;
31 bool run_smb2_basic(int dummy)
33 struct cli_state *cli;
35 uint64_t fid_persistent, fid_volatile;
36 const char *hello = "Hello, world\n";
40 uint32_t dir_data_length;
41 uint32_t saved_tid = 0;
42 uint64_t saved_uid = 0;
44 printf("Starting SMB2-BASIC\n");
46 if (!torture_init_connection(&cli)) {
49 cli->smb2.pid = 0xFEFF;
51 status = smbXcli_negprot(cli->conn, cli->timeout,
52 PROTOCOL_SMB2_02, PROTOCOL_SMB2_02);
53 if (!NT_STATUS_IS_OK(status)) {
54 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
58 status = cli_session_setup(cli, username,
59 password, strlen(password),
60 password, strlen(password),
62 if (!NT_STATUS_IS_OK(status)) {
63 printf("cli_session_setup returned %s\n", nt_errstr(status));
67 status = cli_tree_connect(cli, share, "?????", "", 0);
68 if (!NT_STATUS_IS_OK(status)) {
69 printf("cli_tree_connect returned %s\n", nt_errstr(status));
73 status = smb2cli_create(cli, "smb2-basic.txt",
74 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
75 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
76 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
77 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
78 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
79 FILE_CREATE, /* create_disposition, */
80 FILE_DELETE_ON_CLOSE, /* create_options, */
81 NULL, /* smb2_create_blobs *blobs */
84 if (!NT_STATUS_IS_OK(status)) {
85 printf("smb2cli_create returned %s\n", nt_errstr(status));
89 status = smb2cli_write(cli, strlen(hello), 0, fid_persistent,
90 fid_volatile, 0, 0, (const uint8_t *)hello);
91 if (!NT_STATUS_IS_OK(status)) {
92 printf("smb2cli_write returned %s\n", nt_errstr(status));
96 status = smb2cli_flush(cli, fid_persistent, fid_volatile);
97 if (!NT_STATUS_IS_OK(status)) {
98 printf("smb2cli_flush returned %s\n", nt_errstr(status));
102 status = smb2cli_read(cli, 0x10000, 0, fid_persistent,
104 talloc_tos(), &result, &nread);
105 if (!NT_STATUS_IS_OK(status)) {
106 printf("smb2cli_read returned %s\n", nt_errstr(status));
110 if (nread != strlen(hello)) {
111 printf("smb2cli_read returned %d bytes, expected %d\n",
112 (int)nread, (int)strlen(hello));
116 if (memcmp(hello, result, nread) != 0) {
117 printf("smb2cli_read returned '%s', expected '%s'\n",
122 status = smb2cli_close(cli, 0, fid_persistent, fid_volatile);
123 if (!NT_STATUS_IS_OK(status)) {
124 printf("smb2cli_close returned %s\n", nt_errstr(status));
128 status = smb2cli_create(cli, "",
129 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
130 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
133 SEC_DIR_READ_ATTRIBUTE, /* desired_access, */
134 0, /* file_attributes, */
135 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
136 FILE_OPEN, /* create_disposition, */
137 FILE_SYNCHRONOUS_IO_NONALERT|FILE_DIRECTORY_FILE, /* create_options, */
138 NULL, /* smb2_create_blobs *blobs */
141 if (!NT_STATUS_IS_OK(status)) {
142 printf("smb2cli_create returned %s\n", nt_errstr(status));
146 status = smb2cli_query_directory(
147 cli, 1, 0, 0, fid_persistent, fid_volatile, "*", 0xffff,
148 talloc_tos(), &dir_data, &dir_data_length);
150 if (!NT_STATUS_IS_OK(status)) {
151 printf("smb2cli_query_directory returned %s\n", nt_errstr(status));
155 status = smb2cli_close(cli, 0, fid_persistent, fid_volatile);
156 if (!NT_STATUS_IS_OK(status)) {
157 printf("smb2cli_close returned %s\n", nt_errstr(status));
161 saved_tid = cli->smb2.tid;
162 status = smb2cli_tdis(cli);
163 if (!NT_STATUS_IS_OK(status)) {
164 printf("smb2cli_tdis returned %s\n", nt_errstr(status));
167 cli->smb2.tid = saved_tid;
169 status = smb2cli_tdis(cli);
170 if (!NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED)) {
171 printf("2nd smb2cli_tdis returned %s\n", nt_errstr(status));
175 saved_uid = smb2cli_session_current_id(cli->smb2.session);
176 status = smb2cli_logoff(cli);
177 if (!NT_STATUS_IS_OK(status)) {
178 printf("smb2cli_logoff returned %s\n", nt_errstr(status));
182 cli->smb2.session = smbXcli_session_create(cli, cli->conn);
183 if (cli->smb2.session == NULL) {
184 printf("smbXcli_session_create() returned NULL\n");
188 smb2cli_session_set_id_and_flags(cli->smb2.session, saved_uid, 0);
190 status = smb2cli_logoff(cli);
191 if (!NT_STATUS_EQUAL(status, NT_STATUS_USER_SESSION_DELETED)) {
192 printf("2nd smb2cli_logoff returned %s\n", nt_errstr(status));
199 bool run_smb2_negprot(int dummy)
201 struct cli_state *cli;
203 enum protocol_types protocol;
204 const char *name = NULL;
206 printf("Starting SMB2-NEGPROT\n");
208 if (!torture_init_connection(&cli)) {
211 cli->smb2.pid = 0xFEFF;
213 status = smbXcli_negprot(cli->conn, cli->timeout,
214 PROTOCOL_CORE, PROTOCOL_SMB2_24);
215 if (!NT_STATUS_IS_OK(status)) {
216 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
220 protocol = smbXcli_conn_protocol(cli->conn);
223 case PROTOCOL_SMB2_02:
226 case PROTOCOL_SMB2_10:
229 case PROTOCOL_SMB2_22:
232 case PROTOCOL_SMB2_24:
240 printf("Server supports %s\n", name);
242 printf("Server DOES NOT support SMB2\n");
246 status = smbXcli_negprot(cli->conn, cli->timeout,
248 if (!NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_RESET) &&
249 !NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_DISCONNECTED) &&
250 !NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_ABORTED)) {
251 printf("2nd smbXcli_negprot should disconnect - returned %s\n",
256 if (smbXcli_conn_is_connected(cli->conn)) {
257 printf("2nd smbXcli_negprot should disconnect "
258 "- still connected\n");
265 bool run_smb2_session_reconnect(int dummy)
267 struct cli_state *cli1;
268 struct cli_state *cli2;
271 uint64_t fid_persistent, fid_volatile;
272 struct tevent_context *ev;
273 struct tevent_req *subreq;
274 DATA_BLOB in_blob = data_blob_null;
276 struct ntlmssp_state *ntlmssp;
277 struct iovec *recv_iov;
278 const char *hello = "Hello, world\n";
282 printf("Starting SMB2-SESSION-RECONNECT\n");
284 if (!torture_init_connection(&cli1)) {
287 cli1->smb2.pid = 0xFEFF;
289 status = smbXcli_negprot(cli1->conn, cli1->timeout,
290 PROTOCOL_SMB2_02, PROTOCOL_SMB2_24);
291 if (!NT_STATUS_IS_OK(status)) {
292 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
296 status = cli_session_setup(cli1, username,
297 password, strlen(password),
298 password, strlen(password),
300 if (!NT_STATUS_IS_OK(status)) {
301 printf("cli_session_setup returned %s\n", nt_errstr(status));
305 status = cli_tree_connect(cli1, share, "?????", "", 0);
306 if (!NT_STATUS_IS_OK(status)) {
307 printf("cli_tree_connect returned %s\n", nt_errstr(status));
311 status = smb2cli_create(cli1, "session-reconnect.txt",
312 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
313 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
314 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
315 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
316 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
317 FILE_CREATE, /* create_disposition, */
318 FILE_DELETE_ON_CLOSE, /* create_options, */
319 NULL, /* smb2_create_blobs *blobs */
322 if (!NT_STATUS_IS_OK(status)) {
323 printf("smb2cli_create on cli1 %s\n", nt_errstr(status));
327 status = smb2cli_write(cli1, strlen(hello), 0, fid_persistent,
328 fid_volatile, 0, 0, (const uint8_t *)hello);
329 if (!NT_STATUS_IS_OK(status)) {
330 printf("smb2cli_write returned %s\n", nt_errstr(status));
334 status = smb2cli_flush(cli1, fid_persistent, fid_volatile);
335 if (!NT_STATUS_IS_OK(status)) {
336 printf("smb2cli_flush returned %s\n", nt_errstr(status));
340 status = smb2cli_read(cli1, 0x10000, 0, fid_persistent,
342 talloc_tos(), &result, &nread);
343 if (!NT_STATUS_IS_OK(status)) {
344 printf("smb2cli_read returned %s\n", nt_errstr(status));
348 if (nread != strlen(hello)) {
349 printf("smb2cli_read returned %d bytes, expected %d\n",
350 (int)nread, (int)strlen(hello));
354 if (memcmp(hello, result, nread) != 0) {
355 printf("smb2cli_read returned '%s', expected '%s'\n",
360 /* prepare second session */
362 if (!torture_init_connection(&cli2)) {
365 cli2->smb2.pid = 0xFEFF;
367 status = smbXcli_negprot(cli2->conn, cli2->timeout,
368 PROTOCOL_SMB2_02, PROTOCOL_SMB2_24);
369 if (!NT_STATUS_IS_OK(status)) {
370 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
374 status = ntlmssp_client_start(talloc_tos(),
377 lp_client_ntlmv2_auth(),
379 if (!NT_STATUS_IS_OK(status)) {
380 printf("ntlmssp_client_start returned %s\n", nt_errstr(status));
384 ntlmssp_want_feature(ntlmssp,
385 NTLMSSP_FEATURE_SESSION_KEY);
386 status = ntlmssp_set_username(ntlmssp, username);
387 if (!NT_STATUS_IS_OK(status)) {
388 printf("ntlmssp_set_username returned %s\n", nt_errstr(status));
392 status = ntlmssp_set_domain(ntlmssp, workgroup);
393 if (!NT_STATUS_IS_OK(status)) {
394 printf("ntlmssp_set_domain returned %s\n", nt_errstr(status));
398 status = ntlmssp_set_password(ntlmssp, password);
399 if (!NT_STATUS_IS_OK(status)) {
400 printf("ntlmssp_set_password returned %s\n", nt_errstr(status));
404 status = ntlmssp_update(ntlmssp, data_blob_null, &in_blob);
405 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
406 printf("ntlmssp_update returned %s\n", nt_errstr(status));
410 cli2->smb2.session = smbXcli_session_create(cli2, cli2->conn);
412 ev = event_context_init(talloc_tos());
414 printf("event_context_init() returned NULL\n");
418 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
423 SMB2_CAP_DFS, /* in_capabilities */
425 cli1->smb2.session, /* in_previous_session */
426 &in_blob); /* in_security_buffer */
427 if (subreq == NULL) {
428 printf("smb2cli_session_setup_send() returned NULL\n");
432 ok = tevent_req_poll(subreq, ev);
434 printf("tevent_req_poll() returned false\n");
438 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
440 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
441 printf("smb2cli_session_setup_recv returned %s\n",
446 status = ntlmssp_update(ntlmssp, out_blob, &in_blob);
447 if (!NT_STATUS_IS_OK(status)) {
448 printf("ntlmssp_update returned %s\n", nt_errstr(status));
452 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
457 SMB2_CAP_DFS, /* in_capabilities */
459 cli1->smb2.session, /* in_previous_session */
460 &in_blob); /* in_security_buffer */
461 if (subreq == NULL) {
462 printf("smb2cli_session_setup_send() returned NULL\n");
466 ok = tevent_req_poll(subreq, ev);
468 printf("tevent_req_poll() returned false\n");
472 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
473 &recv_iov, &out_blob);
474 if (!NT_STATUS_IS_OK(status)) {
475 printf("smb2cli_session_setup_recv returned %s\n",
480 status = smb2_signing_check_pdu(ntlmssp->session_key, recv_iov, 3);
481 if (!NT_STATUS_IS_OK(status)) {
482 printf("check pdu returned %s\n", nt_errstr(status));
486 /* check file operation on the old client */
488 status = smb2cli_flush(cli1, fid_persistent, fid_volatile);
489 if (!NT_STATUS_EQUAL(status, NT_STATUS_USER_SESSION_DELETED)) {
490 printf("smb2cli_flush returned %s\n", nt_errstr(status));
494 status = cli_tree_connect(cli1, share, "?????", "", 0);
495 if (!NT_STATUS_EQUAL(status, NT_STATUS_USER_SESSION_DELETED)) {
496 printf("cli_tree_connect returned %s\n", nt_errstr(status));
501 * checking file operations without signing.
502 * on w2k8r2 at least, flush, read and write also work the same way,
503 * while create gives ACCESS_DENIED without signing
505 status = smb2cli_flush(cli2, fid_persistent, fid_volatile);
506 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
507 printf("smb2cli_flush returned %s\n", nt_errstr(status));
511 status = smb2cli_write(cli2, strlen(hello), 0, fid_persistent,
512 fid_volatile, 0, 0, (const uint8_t *)hello);
513 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
514 printf("smb2cli_write returned %s\n", nt_errstr(status));
518 status = smb2cli_read(cli2, 0x10000, 0, fid_persistent,
520 talloc_tos(), &result, &nread);
521 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
522 printf("smb2cli_read returned %s\n", nt_errstr(status));
526 status = smb2cli_create(cli2, "session-reconnect.txt",
527 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
528 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
529 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
530 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
531 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
532 FILE_CREATE, /* create_disposition, */
533 FILE_DELETE_ON_CLOSE, /* create_options, */
534 NULL, /* smb2_create_blobs *blobs */
537 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED) &&
538 !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED)) {
539 printf("smb2cli_create on cli2 %s\n", nt_errstr(status));
543 /* now grab the session key and try with signing */
545 status = smb2cli_session_update_session_key(cli2->smb2.session,
546 ntlmssp->session_key,
548 if (!NT_STATUS_IS_OK(status)) {
549 printf("smb2cli_session_update_session_key %s\n", nt_errstr(status));
553 /* the tid seems to be irrelevant at this stage */
555 cli2->smb2.tid = cli1->smb2.tid;
557 status = smb2cli_flush(cli2, fid_persistent, fid_volatile);
558 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
559 printf("smb2cli_flush returned %s\n", nt_errstr(status));
563 status = smb2cli_write(cli2, strlen(hello), 0, fid_persistent,
564 fid_volatile, 0, 0, (const uint8_t *)hello);
565 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
566 printf("smb2cli_write returned %s\n", nt_errstr(status));
570 status = smb2cli_read(cli2, 0x10000, 0, fid_persistent,
572 talloc_tos(), &result, &nread);
573 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
574 printf("smb2cli_read returned %s\n", nt_errstr(status));
578 status = smb2cli_create(cli2, "session-reconnect.txt",
579 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
580 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
581 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
582 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
583 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
584 FILE_CREATE, /* create_disposition, */
585 FILE_DELETE_ON_CLOSE, /* create_options, */
586 NULL, /* smb2_create_blobs *blobs */
589 if (!NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED)) {
590 printf("smb2cli_create on cli2 %s\n", nt_errstr(status));
594 /* now do a new tcon and test file calls again */
596 status = cli_tree_connect(cli2, share, "?????", "", 0);
597 if (!NT_STATUS_IS_OK(status)) {
598 printf("cli_tree_connect returned %s\n", nt_errstr(status));
602 status = smb2cli_create(cli2, "session-reconnect.txt",
603 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
604 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
605 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
606 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
607 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
608 FILE_CREATE, /* create_disposition, */
609 FILE_DELETE_ON_CLOSE, /* create_options, */
610 NULL, /* smb2_create_blobs *blobs */
613 if (!NT_STATUS_IS_OK(status)) {
614 printf("smb2cli_create on cli2 %s\n", nt_errstr(status));
618 status = smb2cli_write(cli2, strlen(hello), 0, fid_persistent,
619 fid_volatile, 0, 0, (const uint8_t *)hello);
620 if (!NT_STATUS_IS_OK(status)) {
621 printf("smb2cli_write returned %s\n", nt_errstr(status));
625 status = smb2cli_flush(cli2, fid_persistent, fid_volatile);
626 if (!NT_STATUS_IS_OK(status)) {
627 printf("smb2cli_flush returned %s\n", nt_errstr(status));
631 status = smb2cli_read(cli2, 0x10000, 0, fid_persistent,
633 talloc_tos(), &result, &nread);
634 if (!NT_STATUS_IS_OK(status)) {
635 printf("smb2cli_read returned %s\n", nt_errstr(status));
639 if (nread != strlen(hello)) {
640 printf("smb2cli_read returned %d bytes, expected %d\n",
641 (int)nread, (int)strlen(hello));
645 if (memcmp(hello, result, nread) != 0) {
646 printf("smb2cli_read returned '%s', expected '%s'\n",
654 bool run_smb2_tcon_dependence(int dummy)
656 struct cli_state *cli;
658 uint64_t fid_persistent, fid_volatile;
659 const char *hello = "Hello, world\n";
663 printf("Starting SMB2-TCON-DEPENDENCE\n");
665 if (!torture_init_connection(&cli)) {
668 cli->smb2.pid = 0xFEFF;
670 status = smbXcli_negprot(cli->conn, cli->timeout,
671 PROTOCOL_SMB2_02, PROTOCOL_SMB2_24);
672 if (!NT_STATUS_IS_OK(status)) {
673 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
677 status = cli_session_setup(cli, username,
678 password, strlen(password),
679 password, strlen(password),
681 if (!NT_STATUS_IS_OK(status)) {
682 printf("cli_session_setup returned %s\n", nt_errstr(status));
686 status = cli_tree_connect(cli, share, "?????", "", 0);
687 if (!NT_STATUS_IS_OK(status)) {
688 printf("cli_tree_connect returned %s\n", nt_errstr(status));
692 status = smb2cli_create(cli, "tcon_depedence.txt",
693 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
694 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
695 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
696 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
697 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
698 FILE_CREATE, /* create_disposition, */
699 FILE_DELETE_ON_CLOSE, /* create_options, */
700 NULL, /* smb2_create_blobs *blobs */
703 if (!NT_STATUS_IS_OK(status)) {
704 printf("smb2cli_create on cli %s\n", nt_errstr(status));
708 status = smb2cli_write(cli, strlen(hello), 0, fid_persistent,
709 fid_volatile, 0, 0, (const uint8_t *)hello);
710 if (!NT_STATUS_IS_OK(status)) {
711 printf("smb2cli_write returned %s\n", nt_errstr(status));
715 status = smb2cli_flush(cli, fid_persistent, fid_volatile);
716 if (!NT_STATUS_IS_OK(status)) {
717 printf("smb2cli_flush returned %s\n", nt_errstr(status));
721 status = smb2cli_read(cli, 0x10000, 0, fid_persistent,
723 talloc_tos(), &result, &nread);
724 if (!NT_STATUS_IS_OK(status)) {
725 printf("smb2cli_read returned %s\n", nt_errstr(status));
729 if (nread != strlen(hello)) {
730 printf("smb2cli_read returned %d bytes, expected %d\n",
731 (int)nread, (int)strlen(hello));
735 if (memcmp(hello, result, nread) != 0) {
736 printf("smb2cli_read returned '%s', expected '%s'\n",
741 /* check behaviour with wrong tid... */
745 status = smb2cli_read(cli, 0x10000, 0, fid_persistent,
747 talloc_tos(), &result, &nread);
748 if (!NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED)) {
749 printf("smb2cli_read returned %s\n", nt_errstr(status));
758 bool run_smb2_multi_channel(int dummy)
760 struct cli_state *cli1;
761 struct cli_state *cli2;
764 uint64_t fid_persistent, fid_volatile;
765 struct tevent_context *ev;
766 struct tevent_req *subreq;
767 DATA_BLOB in_blob = data_blob_null;
769 struct ntlmssp_state *ntlmssp;
770 struct iovec *recv_iov;
771 const char *hello = "Hello, world\n";
775 printf("Starting SMB2-MULTI-CHANNEL\n");
777 if (!torture_init_connection(&cli1)) {
780 cli1->smb2.pid = 0xFEFF;
782 if (!torture_init_connection(&cli2)) {
785 cli2->smb2.pid = 0xFEFF;
787 status = smbXcli_negprot(cli1->conn, cli1->timeout,
788 PROTOCOL_SMB2_22, PROTOCOL_SMB2_24);
789 if (!NT_STATUS_IS_OK(status)) {
790 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
794 status = smbXcli_negprot(cli2->conn, cli2->timeout,
795 PROTOCOL_SMB2_22, PROTOCOL_SMB2_24);
796 if (!NT_STATUS_IS_OK(status)) {
797 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
801 status = cli_session_setup(cli1, username,
802 password, strlen(password),
803 password, strlen(password),
805 if (!NT_STATUS_IS_OK(status)) {
806 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status));
810 status = cli_tree_connect(cli1, share, "?????", "", 0);
811 if (!NT_STATUS_IS_OK(status)) {
812 printf("cli_tree_connect returned %s\n", nt_errstr(status));
816 status = smb2cli_session_create_channel(cli2,
819 &cli2->smb2.session);
820 if (!NT_STATUS_IS_OK(status)) {
821 printf("smb2cli_session_create_channel returned %s\n",
826 status = ntlmssp_client_start(talloc_tos(),
829 lp_client_ntlmv2_auth(),
831 if (!NT_STATUS_IS_OK(status)) {
832 printf("ntlmssp_client_start returned %s\n", nt_errstr(status));
836 ntlmssp_want_feature(ntlmssp,
837 NTLMSSP_FEATURE_SESSION_KEY);
838 status = ntlmssp_set_username(ntlmssp, username);
839 if (!NT_STATUS_IS_OK(status)) {
840 printf("ntlmssp_set_username returned %s\n", nt_errstr(status));
844 status = ntlmssp_set_domain(ntlmssp, workgroup);
845 if (!NT_STATUS_IS_OK(status)) {
846 printf("ntlmssp_set_domain returned %s\n", nt_errstr(status));
850 status = ntlmssp_set_password(ntlmssp, password);
851 if (!NT_STATUS_IS_OK(status)) {
852 printf("ntlmssp_set_password returned %s\n", nt_errstr(status));
856 status = ntlmssp_update(ntlmssp, data_blob_null, &in_blob);
857 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
858 printf("ntlmssp_update returned %s\n", nt_errstr(status));
862 ev = event_context_init(talloc_tos());
864 printf("event_context_init() returned NULL\n");
868 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
873 SMB2_CAP_DFS, /* in_capabilities */
875 NULL, /* in_previous_session */
876 &in_blob); /* in_security_buffer */
877 if (subreq == NULL) {
878 printf("smb2cli_session_setup_send() returned NULL\n");
882 ok = tevent_req_poll(subreq, ev);
884 printf("tevent_req_poll() returned false\n");
888 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
890 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
891 printf("smb2cli_session_setup_recv returned %s\n",
896 status = ntlmssp_update(ntlmssp, out_blob, &in_blob);
897 if (!NT_STATUS_IS_OK(status)) {
898 printf("ntlmssp_update returned %s\n", nt_errstr(status));
902 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
907 SMB2_CAP_DFS, /* in_capabilities */
909 NULL, /* in_previous_session */
910 &in_blob); /* in_security_buffer */
911 if (subreq == NULL) {
912 printf("smb2cli_session_setup_send() returned NULL\n");
916 ok = tevent_req_poll(subreq, ev);
918 printf("tevent_req_poll() returned false\n");
922 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
923 &recv_iov, &out_blob);
924 if (!NT_STATUS_IS_OK(status)) {
925 printf("smb2cli_session_setup_recv returned %s\n",
930 status = smb2cli_session_update_session_key(cli2->smb2.session,
931 ntlmssp->session_key,
933 if (!NT_STATUS_IS_OK(status)) {
934 printf("smb2cli_session_update_session_key %s\n", nt_errstr(status));
938 cli2->smb2.tid = cli1->smb2.tid;
940 status = smb2cli_create(cli2, "multi-channel.txt",
941 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
942 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
943 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
944 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
945 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
946 FILE_CREATE, /* create_disposition, */
947 FILE_DELETE_ON_CLOSE, /* create_options, */
948 NULL, /* smb2_create_blobs *blobs */
951 if (!NT_STATUS_IS_OK(status)) {
952 printf("smb2cli_create on cli2 %s\n", nt_errstr(status));
956 status = smb2cli_write(cli1, strlen(hello), 0, fid_persistent,
957 fid_volatile, 0, 0, (const uint8_t *)hello);
958 if (!NT_STATUS_IS_OK(status)) {
959 printf("smb2cli_write returned %s\n", nt_errstr(status));
963 status = smb2cli_flush(cli2, fid_persistent, fid_volatile);
964 if (!NT_STATUS_IS_OK(status)) {
965 printf("smb2cli_flush returned %s\n", nt_errstr(status));
969 status = smb2cli_flush(cli1, fid_persistent, fid_volatile);
970 if (!NT_STATUS_IS_OK(status)) {
971 printf("smb2cli_flush returned %s\n", nt_errstr(status));
975 status = smb2cli_read(cli2, 0x10000, 0, fid_persistent,
977 talloc_tos(), &result, &nread);
978 if (!NT_STATUS_IS_OK(status)) {
979 printf("smb2cli_read returned %s\n", nt_errstr(status));
983 if (nread != strlen(hello)) {
984 printf("smb2cli_read returned %d bytes, expected %d\n",
985 (int)nread, (int)strlen(hello));
989 if (memcmp(hello, result, nread) != 0) {
990 printf("smb2cli_read returned '%s', expected '%s'\n",
995 status = smb2cli_close(cli1, 0, fid_persistent, fid_volatile);
996 if (!NT_STATUS_IS_OK(status)) {
997 printf("smb2cli_close returned %s\n", nt_errstr(status));
1001 status = smb2cli_flush(cli2, fid_persistent, fid_volatile);
1002 if (!NT_STATUS_IS_OK(status)) {
1003 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1006 status = smb2cli_flush(cli1, fid_persistent, fid_volatile);
1007 if (!NT_STATUS_IS_OK(status)) {
1008 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1014 bool run_smb2_session_reauth(int dummy)
1016 struct cli_state *cli;
1019 uint64_t fid_persistent, fid_volatile;
1020 struct tevent_context *ev;
1021 struct tevent_req *subreq;
1022 DATA_BLOB in_blob = data_blob_null;
1024 struct ntlmssp_state *ntlmssp;
1025 struct iovec *recv_iov;
1027 printf("Starting SMB2-SESSION_REAUTH\n");
1029 if (!torture_init_connection(&cli)) {
1032 cli->smb2.pid = 0xFEFF;
1035 * PROTOCOL_SMB2_22 has a bug in win8pre0
1036 * it behaves like PROTOCOL_SMB2_02
1037 * and returns NT_STATUS_REQUEST_NOT_ACCEPTED,
1038 * while it allows it on PROTOCOL_SMB2_02.
1040 status = smbXcli_negprot(cli->conn, cli->timeout,
1041 PROTOCOL_SMB2_10, PROTOCOL_SMB2_10);
1042 if (!NT_STATUS_IS_OK(status)) {
1043 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
1047 status = cli_session_setup(cli, username,
1048 password, strlen(password),
1049 password, strlen(password),
1051 if (!NT_STATUS_IS_OK(status)) {
1052 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status));
1056 status = cli_tree_connect(cli, share, "?????", "", 0);
1057 if (!NT_STATUS_IS_OK(status)) {
1058 printf("cli_tree_connect returned %s\n", nt_errstr(status));
1062 status = smb2cli_create(cli, "session-reauth.txt",
1063 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1064 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1065 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1066 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1067 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1068 FILE_CREATE, /* create_disposition, */
1069 FILE_DELETE_ON_CLOSE, /* create_options, */
1070 NULL, /* smb2_create_blobs *blobs */
1073 if (!NT_STATUS_IS_OK(status)) {
1074 printf("smb2cli_create %s\n", nt_errstr(status));
1078 status = ntlmssp_client_start(talloc_tos(),
1081 lp_client_ntlmv2_auth(),
1083 if (!NT_STATUS_IS_OK(status)) {
1084 printf("ntlmssp_client_start returned %s\n", nt_errstr(status));
1088 ntlmssp_want_feature(ntlmssp,
1089 NTLMSSP_FEATURE_SESSION_KEY);
1090 status = ntlmssp_set_username(ntlmssp, username);
1091 if (!NT_STATUS_IS_OK(status)) {
1092 printf("ntlmssp_set_username returned %s\n", nt_errstr(status));
1096 status = ntlmssp_set_domain(ntlmssp, workgroup);
1097 if (!NT_STATUS_IS_OK(status)) {
1098 printf("ntlmssp_set_domain returned %s\n", nt_errstr(status));
1102 status = ntlmssp_set_password(ntlmssp, password);
1103 if (!NT_STATUS_IS_OK(status)) {
1104 printf("ntlmssp_set_password returned %s\n", nt_errstr(status));
1108 status = ntlmssp_update(ntlmssp, data_blob_null, &in_blob);
1109 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1110 printf("ntlmssp_update returned %s\n", nt_errstr(status));
1114 ev = event_context_init(talloc_tos());
1116 printf("event_context_init() returned NULL\n");
1120 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1125 SMB2_CAP_DFS, /* in_capabilities */
1127 NULL, /* in_previous_session */
1128 &in_blob); /* in_security_buffer */
1129 if (subreq == NULL) {
1130 printf("smb2cli_session_setup_send() returned NULL\n");
1134 ok = tevent_req_poll(subreq, ev);
1136 printf("tevent_req_poll() returned false\n");
1140 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1142 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1143 printf("smb2cli_session_setup_recv returned %s\n",
1148 status = ntlmssp_update(ntlmssp, out_blob, &in_blob);
1149 if (!NT_STATUS_IS_OK(status)) {
1150 printf("ntlmssp_update returned %s\n", nt_errstr(status));
1154 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1159 SMB2_CAP_DFS, /* in_capabilities */
1161 NULL, /* in_previous_session */
1162 &in_blob); /* in_security_buffer */
1163 if (subreq == NULL) {
1164 printf("smb2cli_session_setup_send() returned NULL\n");
1168 ok = tevent_req_poll(subreq, ev);
1170 printf("tevent_req_poll() returned false\n");
1174 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1175 &recv_iov, &out_blob);
1176 if (!NT_STATUS_IS_OK(status)) {
1177 printf("smb2cli_session_setup_recv returned %s\n",
1182 status = smb2cli_session_update_session_key(cli->smb2.session,
1183 ntlmssp->session_key,
1185 if (!NT_STATUS_IS_OK(status)) {
1186 printf("smb2cli_session_update_session_key %s\n", nt_errstr(status));
1190 status = smb2cli_flush(cli, fid_persistent, fid_volatile);
1191 if (!NT_STATUS_IS_OK(status)) {
1192 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1196 status = smb2cli_close(cli, 0, fid_persistent, fid_volatile);
1197 if (!NT_STATUS_IS_OK(status)) {
1198 printf("smb2cli_close returned %s\n", nt_errstr(status));
1202 status = smb2cli_create(cli, "multi-channel.txt",
1203 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1204 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1205 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1206 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1207 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1208 FILE_CREATE, /* create_disposition, */
1209 FILE_DELETE_ON_CLOSE, /* create_options, */
1210 NULL, /* smb2_create_blobs *blobs */
1213 if (!NT_STATUS_IS_OK(status)) {
1214 printf("smb2cli_create %s\n", nt_errstr(status));
1218 status = smb2cli_close(cli, 0, fid_persistent, fid_volatile);
1219 if (!NT_STATUS_IS_OK(status)) {
1220 printf("smb2cli_close returned %s\n", nt_errstr(status));