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_22);
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:
237 printf("Server supports %s\n", name);
239 printf("Server DOES NOT support SMB2\n");
243 status = smbXcli_negprot(cli->conn, cli->timeout,
245 if (!NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_RESET) &&
246 !NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_DISCONNECTED) &&
247 !NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_ABORTED)) {
248 printf("2nd smbXcli_negprot should disconnect - returned %s\n",
253 if (smbXcli_conn_is_connected(cli->conn)) {
254 printf("2nd smbXcli_negprot should disconnect "
255 "- still connected\n");
262 bool run_smb2_session_reconnect(int dummy)
264 struct cli_state *cli1;
265 struct cli_state *cli2;
268 uint64_t fid_persistent, fid_volatile;
269 struct tevent_context *ev;
270 struct tevent_req *subreq;
271 DATA_BLOB in_blob = data_blob_null;
273 struct ntlmssp_state *ntlmssp;
274 struct iovec *recv_iov;
275 const char *hello = "Hello, world\n";
279 printf("Starting SMB2-SESSION-RECONNECT\n");
281 if (!torture_init_connection(&cli1)) {
284 cli1->smb2.pid = 0xFEFF;
286 status = smbXcli_negprot(cli1->conn, cli1->timeout,
287 PROTOCOL_SMB2_02, PROTOCOL_SMB2_22);
288 if (!NT_STATUS_IS_OK(status)) {
289 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
293 status = cli_session_setup(cli1, username,
294 password, strlen(password),
295 password, strlen(password),
297 if (!NT_STATUS_IS_OK(status)) {
298 printf("cli_session_setup returned %s\n", nt_errstr(status));
302 status = cli_tree_connect(cli1, share, "?????", "", 0);
303 if (!NT_STATUS_IS_OK(status)) {
304 printf("cli_tree_connect returned %s\n", nt_errstr(status));
308 status = smb2cli_create(cli1, "session-reconnect.txt",
309 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
310 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
311 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
312 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
313 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
314 FILE_CREATE, /* create_disposition, */
315 FILE_DELETE_ON_CLOSE, /* create_options, */
316 NULL, /* smb2_create_blobs *blobs */
319 if (!NT_STATUS_IS_OK(status)) {
320 printf("smb2cli_create on cli1 %s\n", nt_errstr(status));
324 status = smb2cli_write(cli1, strlen(hello), 0, fid_persistent,
325 fid_volatile, 0, 0, (const uint8_t *)hello);
326 if (!NT_STATUS_IS_OK(status)) {
327 printf("smb2cli_write returned %s\n", nt_errstr(status));
331 status = smb2cli_flush(cli1, fid_persistent, fid_volatile);
332 if (!NT_STATUS_IS_OK(status)) {
333 printf("smb2cli_flush returned %s\n", nt_errstr(status));
337 status = smb2cli_read(cli1, 0x10000, 0, fid_persistent,
339 talloc_tos(), &result, &nread);
340 if (!NT_STATUS_IS_OK(status)) {
341 printf("smb2cli_read returned %s\n", nt_errstr(status));
345 if (nread != strlen(hello)) {
346 printf("smb2cli_read returned %d bytes, expected %d\n",
347 (int)nread, (int)strlen(hello));
351 if (memcmp(hello, result, nread) != 0) {
352 printf("smb2cli_read returned '%s', expected '%s'\n",
357 /* prepare second session */
359 if (!torture_init_connection(&cli2)) {
362 cli2->smb2.pid = 0xFEFF;
364 status = smbXcli_negprot(cli2->conn, cli2->timeout,
365 PROTOCOL_SMB2_02, PROTOCOL_SMB2_22);
366 if (!NT_STATUS_IS_OK(status)) {
367 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
371 status = ntlmssp_client_start(talloc_tos(),
374 lp_client_ntlmv2_auth(),
376 if (!NT_STATUS_IS_OK(status)) {
377 printf("ntlmssp_client_start returned %s\n", nt_errstr(status));
381 ntlmssp_want_feature(ntlmssp,
382 NTLMSSP_FEATURE_SESSION_KEY);
383 status = ntlmssp_set_username(ntlmssp, username);
384 if (!NT_STATUS_IS_OK(status)) {
385 printf("ntlmssp_set_username returned %s\n", nt_errstr(status));
389 status = ntlmssp_set_domain(ntlmssp, workgroup);
390 if (!NT_STATUS_IS_OK(status)) {
391 printf("ntlmssp_set_domain returned %s\n", nt_errstr(status));
395 status = ntlmssp_set_password(ntlmssp, password);
396 if (!NT_STATUS_IS_OK(status)) {
397 printf("ntlmssp_set_password returned %s\n", nt_errstr(status));
401 status = ntlmssp_update(ntlmssp, data_blob_null, &in_blob);
402 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
403 printf("ntlmssp_update returned %s\n", nt_errstr(status));
407 cli2->smb2.session = smbXcli_session_create(cli2, cli2->conn);
409 ev = event_context_init(talloc_tos());
411 printf("event_context_init() returned NULL\n");
415 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
420 SMB2_CAP_DFS, /* in_capabilities */
422 cli1->smb2.session, /* in_previous_session */
423 &in_blob); /* in_security_buffer */
424 if (subreq == NULL) {
425 printf("smb2cli_session_setup_send() returned NULL\n");
429 ok = tevent_req_poll(subreq, ev);
431 printf("tevent_req_poll() returned false\n");
435 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
437 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
438 printf("smb2cli_session_setup_recv returned %s\n",
443 status = ntlmssp_update(ntlmssp, out_blob, &in_blob);
444 if (!NT_STATUS_IS_OK(status)) {
445 printf("ntlmssp_update returned %s\n", nt_errstr(status));
449 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
454 SMB2_CAP_DFS, /* in_capabilities */
456 cli1->smb2.session, /* in_previous_session */
457 &in_blob); /* in_security_buffer */
458 if (subreq == NULL) {
459 printf("smb2cli_session_setup_send() returned NULL\n");
463 ok = tevent_req_poll(subreq, ev);
465 printf("tevent_req_poll() returned false\n");
469 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
470 &recv_iov, &out_blob);
471 if (!NT_STATUS_IS_OK(status)) {
472 printf("smb2cli_session_setup_recv returned %s\n",
477 status = smb2_signing_check_pdu(ntlmssp->session_key, recv_iov, 3);
478 if (!NT_STATUS_IS_OK(status)) {
479 printf("check pdu returned %s\n", nt_errstr(status));
483 /* check file operation on the old client */
485 status = smb2cli_flush(cli1, fid_persistent, fid_volatile);
486 if (!NT_STATUS_EQUAL(status, NT_STATUS_USER_SESSION_DELETED)) {
487 printf("smb2cli_flush returned %s\n", nt_errstr(status));
491 status = cli_tree_connect(cli1, share, "?????", "", 0);
492 if (!NT_STATUS_EQUAL(status, NT_STATUS_USER_SESSION_DELETED)) {
493 printf("cli_tree_connect returned %s\n", nt_errstr(status));
498 * checking file operations without signing.
499 * on w2k8r2 at least, flush, read and write also work the same way,
500 * while create gives ACCESS_DENIED without signing
502 status = smb2cli_flush(cli2, fid_persistent, fid_volatile);
503 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
504 printf("smb2cli_flush returned %s\n", nt_errstr(status));
508 status = smb2cli_write(cli2, strlen(hello), 0, fid_persistent,
509 fid_volatile, 0, 0, (const uint8_t *)hello);
510 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
511 printf("smb2cli_write returned %s\n", nt_errstr(status));
515 status = smb2cli_read(cli2, 0x10000, 0, fid_persistent,
517 talloc_tos(), &result, &nread);
518 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
519 printf("smb2cli_read returned %s\n", nt_errstr(status));
523 status = smb2cli_create(cli2, "session-reconnect.txt",
524 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
525 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
526 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
527 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
528 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
529 FILE_CREATE, /* create_disposition, */
530 FILE_DELETE_ON_CLOSE, /* create_options, */
531 NULL, /* smb2_create_blobs *blobs */
534 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
535 printf("smb2cli_create on cli2 %s\n", nt_errstr(status));
539 /* now grab the session key and try with signing */
541 status = smb2cli_session_update_session_key(cli2->smb2.session,
542 ntlmssp->session_key,
544 if (!NT_STATUS_IS_OK(status)) {
545 printf("smb2cli_session_update_session_key %s\n", nt_errstr(status));
549 /* the tid seems to be irrelevant at this stage */
551 cli2->smb2.tid = cli1->smb2.tid;
553 status = smb2cli_flush(cli2, fid_persistent, fid_volatile);
554 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
555 printf("smb2cli_flush returned %s\n", nt_errstr(status));
559 status = smb2cli_write(cli2, strlen(hello), 0, fid_persistent,
560 fid_volatile, 0, 0, (const uint8_t *)hello);
561 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
562 printf("smb2cli_write returned %s\n", nt_errstr(status));
566 status = smb2cli_read(cli2, 0x10000, 0, fid_persistent,
568 talloc_tos(), &result, &nread);
569 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
570 printf("smb2cli_read returned %s\n", nt_errstr(status));
574 status = smb2cli_create(cli2, "session-reconnect.txt",
575 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
576 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
577 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
578 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
579 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
580 FILE_CREATE, /* create_disposition, */
581 FILE_DELETE_ON_CLOSE, /* create_options, */
582 NULL, /* smb2_create_blobs *blobs */
585 if (!NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED)) {
586 printf("smb2cli_create on cli2 %s\n", nt_errstr(status));
590 /* now do a new tcon and test file calls again */
592 status = cli_tree_connect(cli2, share, "?????", "", 0);
593 if (!NT_STATUS_IS_OK(status)) {
594 printf("cli_tree_connect returned %s\n", nt_errstr(status));
598 status = smb2cli_create(cli2, "session-reconnect.txt",
599 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
600 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
601 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
602 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
603 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
604 FILE_CREATE, /* create_disposition, */
605 FILE_DELETE_ON_CLOSE, /* create_options, */
606 NULL, /* smb2_create_blobs *blobs */
609 if (!NT_STATUS_IS_OK(status)) {
610 printf("smb2cli_create on cli2 %s\n", nt_errstr(status));
614 status = smb2cli_write(cli2, strlen(hello), 0, fid_persistent,
615 fid_volatile, 0, 0, (const uint8_t *)hello);
616 if (!NT_STATUS_IS_OK(status)) {
617 printf("smb2cli_write returned %s\n", nt_errstr(status));
621 status = smb2cli_flush(cli2, fid_persistent, fid_volatile);
622 if (!NT_STATUS_IS_OK(status)) {
623 printf("smb2cli_flush returned %s\n", nt_errstr(status));
627 status = smb2cli_read(cli2, 0x10000, 0, fid_persistent,
629 talloc_tos(), &result, &nread);
630 if (!NT_STATUS_IS_OK(status)) {
631 printf("smb2cli_read returned %s\n", nt_errstr(status));
635 if (nread != strlen(hello)) {
636 printf("smb2cli_read returned %d bytes, expected %d\n",
637 (int)nread, (int)strlen(hello));
641 if (memcmp(hello, result, nread) != 0) {
642 printf("smb2cli_read returned '%s', expected '%s'\n",
650 bool run_smb2_tcon_dependence(int dummy)
652 struct cli_state *cli;
654 uint64_t fid_persistent, fid_volatile;
655 const char *hello = "Hello, world\n";
659 printf("Starting SMB2-TCON-DEPENDENCE\n");
661 if (!torture_init_connection(&cli)) {
664 cli->smb2.pid = 0xFEFF;
666 status = smbXcli_negprot(cli->conn, cli->timeout,
667 PROTOCOL_SMB2_02, PROTOCOL_SMB2_22);
668 if (!NT_STATUS_IS_OK(status)) {
669 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
673 status = cli_session_setup(cli, username,
674 password, strlen(password),
675 password, strlen(password),
677 if (!NT_STATUS_IS_OK(status)) {
678 printf("cli_session_setup returned %s\n", nt_errstr(status));
682 status = cli_tree_connect(cli, share, "?????", "", 0);
683 if (!NT_STATUS_IS_OK(status)) {
684 printf("cli_tree_connect returned %s\n", nt_errstr(status));
688 status = smb2cli_create(cli, "tcon_depedence.txt",
689 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
690 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
691 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
692 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
693 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
694 FILE_CREATE, /* create_disposition, */
695 FILE_DELETE_ON_CLOSE, /* create_options, */
696 NULL, /* smb2_create_blobs *blobs */
699 if (!NT_STATUS_IS_OK(status)) {
700 printf("smb2cli_create on cli %s\n", nt_errstr(status));
704 status = smb2cli_write(cli, strlen(hello), 0, fid_persistent,
705 fid_volatile, 0, 0, (const uint8_t *)hello);
706 if (!NT_STATUS_IS_OK(status)) {
707 printf("smb2cli_write returned %s\n", nt_errstr(status));
711 status = smb2cli_flush(cli, fid_persistent, fid_volatile);
712 if (!NT_STATUS_IS_OK(status)) {
713 printf("smb2cli_flush returned %s\n", nt_errstr(status));
717 status = smb2cli_read(cli, 0x10000, 0, fid_persistent,
719 talloc_tos(), &result, &nread);
720 if (!NT_STATUS_IS_OK(status)) {
721 printf("smb2cli_read returned %s\n", nt_errstr(status));
725 if (nread != strlen(hello)) {
726 printf("smb2cli_read returned %d bytes, expected %d\n",
727 (int)nread, (int)strlen(hello));
731 if (memcmp(hello, result, nread) != 0) {
732 printf("smb2cli_read returned '%s', expected '%s'\n",
737 /* check behaviour with wrong tid... */
741 status = smb2cli_read(cli, 0x10000, 0, fid_persistent,
743 talloc_tos(), &result, &nread);
744 if (!NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED)) {
745 printf("smb2cli_read returned %s\n", nt_errstr(status));
754 bool run_smb2_multi_channel(int dummy)
756 struct cli_state *cli1;
757 struct cli_state *cli2;
760 uint64_t fid_persistent, fid_volatile;
761 struct tevent_context *ev;
762 struct tevent_req *subreq;
763 DATA_BLOB in_blob = data_blob_null;
765 struct ntlmssp_state *ntlmssp;
766 struct iovec *recv_iov;
767 const char *hello = "Hello, world\n";
771 printf("Starting SMB2-MULTI-CHANNEL\n");
773 if (!torture_init_connection(&cli1)) {
776 cli1->smb2.pid = 0xFEFF;
778 if (!torture_init_connection(&cli2)) {
781 cli2->smb2.pid = 0xFEFF;
783 status = smbXcli_negprot(cli1->conn, cli1->timeout,
784 PROTOCOL_SMB2_22, PROTOCOL_SMB2_22);
785 if (!NT_STATUS_IS_OK(status)) {
786 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
790 status = smbXcli_negprot(cli2->conn, cli2->timeout,
791 PROTOCOL_SMB2_22, PROTOCOL_SMB2_22);
792 if (!NT_STATUS_IS_OK(status)) {
793 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
797 status = cli_session_setup(cli1, username,
798 password, strlen(password),
799 password, strlen(password),
801 if (!NT_STATUS_IS_OK(status)) {
802 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status));
806 status = cli_tree_connect(cli1, share, "?????", "", 0);
807 if (!NT_STATUS_IS_OK(status)) {
808 printf("cli_tree_connect returned %s\n", nt_errstr(status));
812 status = smb2cli_session_create_channel(cli2,
815 &cli2->smb2.session);
816 if (!NT_STATUS_IS_OK(status)) {
817 printf("smb2cli_session_create_channel returned %s\n",
822 status = ntlmssp_client_start(talloc_tos(),
825 lp_client_ntlmv2_auth(),
827 if (!NT_STATUS_IS_OK(status)) {
828 printf("ntlmssp_client_start returned %s\n", nt_errstr(status));
832 ntlmssp_want_feature(ntlmssp,
833 NTLMSSP_FEATURE_SESSION_KEY);
834 status = ntlmssp_set_username(ntlmssp, username);
835 if (!NT_STATUS_IS_OK(status)) {
836 printf("ntlmssp_set_username returned %s\n", nt_errstr(status));
840 status = ntlmssp_set_domain(ntlmssp, workgroup);
841 if (!NT_STATUS_IS_OK(status)) {
842 printf("ntlmssp_set_domain returned %s\n", nt_errstr(status));
846 status = ntlmssp_set_password(ntlmssp, password);
847 if (!NT_STATUS_IS_OK(status)) {
848 printf("ntlmssp_set_password returned %s\n", nt_errstr(status));
852 status = ntlmssp_update(ntlmssp, data_blob_null, &in_blob);
853 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
854 printf("ntlmssp_update returned %s\n", nt_errstr(status));
858 ev = event_context_init(talloc_tos());
860 printf("event_context_init() returned NULL\n");
864 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
869 SMB2_CAP_DFS, /* in_capabilities */
871 NULL, /* in_previous_session */
872 &in_blob); /* in_security_buffer */
873 if (subreq == NULL) {
874 printf("smb2cli_session_setup_send() returned NULL\n");
878 ok = tevent_req_poll(subreq, ev);
880 printf("tevent_req_poll() returned false\n");
884 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
886 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
887 printf("smb2cli_session_setup_recv returned %s\n",
892 status = ntlmssp_update(ntlmssp, out_blob, &in_blob);
893 if (!NT_STATUS_IS_OK(status)) {
894 printf("ntlmssp_update returned %s\n", nt_errstr(status));
898 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
903 SMB2_CAP_DFS, /* in_capabilities */
905 NULL, /* in_previous_session */
906 &in_blob); /* in_security_buffer */
907 if (subreq == NULL) {
908 printf("smb2cli_session_setup_send() returned NULL\n");
912 ok = tevent_req_poll(subreq, ev);
914 printf("tevent_req_poll() returned false\n");
918 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
919 &recv_iov, &out_blob);
920 if (!NT_STATUS_IS_OK(status)) {
921 printf("smb2cli_session_setup_recv returned %s\n",
926 status = smb2cli_session_update_session_key(cli2->smb2.session,
927 ntlmssp->session_key,
929 if (!NT_STATUS_IS_OK(status)) {
930 printf("smb2cli_session_update_session_key %s\n", nt_errstr(status));
934 cli2->smb2.tid = cli1->smb2.tid;
936 status = smb2cli_create(cli2, "multi-channel.txt",
937 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
938 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
939 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
940 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
941 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
942 FILE_CREATE, /* create_disposition, */
943 FILE_DELETE_ON_CLOSE, /* create_options, */
944 NULL, /* smb2_create_blobs *blobs */
947 if (!NT_STATUS_IS_OK(status)) {
948 printf("smb2cli_create on cli2 %s\n", nt_errstr(status));
952 status = smb2cli_write(cli1, strlen(hello), 0, fid_persistent,
953 fid_volatile, 0, 0, (const uint8_t *)hello);
954 if (!NT_STATUS_IS_OK(status)) {
955 printf("smb2cli_write returned %s\n", nt_errstr(status));
959 status = smb2cli_flush(cli2, fid_persistent, fid_volatile);
960 if (!NT_STATUS_IS_OK(status)) {
961 printf("smb2cli_flush returned %s\n", nt_errstr(status));
965 status = smb2cli_flush(cli1, fid_persistent, fid_volatile);
966 if (!NT_STATUS_IS_OK(status)) {
967 printf("smb2cli_flush returned %s\n", nt_errstr(status));
971 status = smb2cli_read(cli2, 0x10000, 0, fid_persistent,
973 talloc_tos(), &result, &nread);
974 if (!NT_STATUS_IS_OK(status)) {
975 printf("smb2cli_read returned %s\n", nt_errstr(status));
979 if (nread != strlen(hello)) {
980 printf("smb2cli_read returned %d bytes, expected %d\n",
981 (int)nread, (int)strlen(hello));
985 if (memcmp(hello, result, nread) != 0) {
986 printf("smb2cli_read returned '%s', expected '%s'\n",
991 status = smb2cli_close(cli1, 0, fid_persistent, fid_volatile);
992 if (!NT_STATUS_IS_OK(status)) {
993 printf("smb2cli_close returned %s\n", nt_errstr(status));
997 status = smb2cli_flush(cli2, fid_persistent, fid_volatile);
998 if (!NT_STATUS_IS_OK(status)) {
999 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1002 status = smb2cli_flush(cli1, fid_persistent, fid_volatile);
1003 if (!NT_STATUS_IS_OK(status)) {
1004 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1010 bool run_smb2_session_reauth(int dummy)
1012 struct cli_state *cli;
1015 uint64_t fid_persistent, fid_volatile;
1016 struct tevent_context *ev;
1017 struct tevent_req *subreq;
1018 DATA_BLOB in_blob = data_blob_null;
1020 struct ntlmssp_state *ntlmssp;
1021 struct iovec *recv_iov;
1023 printf("Starting SMB2-SESSION_REAUTH\n");
1025 if (!torture_init_connection(&cli)) {
1028 cli->smb2.pid = 0xFEFF;
1031 * PROTOCOL_SMB2_22 has a bug in win8pre0
1032 * it behaves like PROTOCOL_SMB2_02
1033 * and returns NT_STATUS_REQUEST_NOT_ACCEPTED,
1034 * while it allows it on PROTOCOL_SMB2_02.
1036 status = smbXcli_negprot(cli->conn, cli->timeout,
1037 PROTOCOL_SMB2_10, PROTOCOL_SMB2_10);
1038 if (!NT_STATUS_IS_OK(status)) {
1039 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
1043 status = cli_session_setup(cli, username,
1044 password, strlen(password),
1045 password, strlen(password),
1047 if (!NT_STATUS_IS_OK(status)) {
1048 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status));
1052 status = cli_tree_connect(cli, share, "?????", "", 0);
1053 if (!NT_STATUS_IS_OK(status)) {
1054 printf("cli_tree_connect returned %s\n", nt_errstr(status));
1058 status = smb2cli_create(cli, "session-reauth.txt",
1059 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1060 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1061 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1062 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1063 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1064 FILE_CREATE, /* create_disposition, */
1065 FILE_DELETE_ON_CLOSE, /* create_options, */
1066 NULL, /* smb2_create_blobs *blobs */
1069 if (!NT_STATUS_IS_OK(status)) {
1070 printf("smb2cli_create %s\n", nt_errstr(status));
1074 status = ntlmssp_client_start(talloc_tos(),
1077 lp_client_ntlmv2_auth(),
1079 if (!NT_STATUS_IS_OK(status)) {
1080 printf("ntlmssp_client_start returned %s\n", nt_errstr(status));
1084 ntlmssp_want_feature(ntlmssp,
1085 NTLMSSP_FEATURE_SESSION_KEY);
1086 status = ntlmssp_set_username(ntlmssp, username);
1087 if (!NT_STATUS_IS_OK(status)) {
1088 printf("ntlmssp_set_username returned %s\n", nt_errstr(status));
1092 status = ntlmssp_set_domain(ntlmssp, workgroup);
1093 if (!NT_STATUS_IS_OK(status)) {
1094 printf("ntlmssp_set_domain returned %s\n", nt_errstr(status));
1098 status = ntlmssp_set_password(ntlmssp, password);
1099 if (!NT_STATUS_IS_OK(status)) {
1100 printf("ntlmssp_set_password returned %s\n", nt_errstr(status));
1104 status = ntlmssp_update(ntlmssp, data_blob_null, &in_blob);
1105 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1106 printf("ntlmssp_update returned %s\n", nt_errstr(status));
1110 ev = event_context_init(talloc_tos());
1112 printf("event_context_init() returned NULL\n");
1116 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1121 SMB2_CAP_DFS, /* in_capabilities */
1123 NULL, /* in_previous_session */
1124 &in_blob); /* in_security_buffer */
1125 if (subreq == NULL) {
1126 printf("smb2cli_session_setup_send() returned NULL\n");
1130 ok = tevent_req_poll(subreq, ev);
1132 printf("tevent_req_poll() returned false\n");
1136 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1138 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1139 printf("smb2cli_session_setup_recv returned %s\n",
1144 status = ntlmssp_update(ntlmssp, out_blob, &in_blob);
1145 if (!NT_STATUS_IS_OK(status)) {
1146 printf("ntlmssp_update returned %s\n", nt_errstr(status));
1150 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1155 SMB2_CAP_DFS, /* in_capabilities */
1157 NULL, /* in_previous_session */
1158 &in_blob); /* in_security_buffer */
1159 if (subreq == NULL) {
1160 printf("smb2cli_session_setup_send() returned NULL\n");
1164 ok = tevent_req_poll(subreq, ev);
1166 printf("tevent_req_poll() returned false\n");
1170 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1171 &recv_iov, &out_blob);
1172 if (!NT_STATUS_IS_OK(status)) {
1173 printf("smb2cli_session_setup_recv returned %s\n",
1178 status = smb2cli_session_update_session_key(cli->smb2.session,
1179 ntlmssp->session_key,
1181 if (!NT_STATUS_IS_OK(status)) {
1182 printf("smb2cli_session_update_session_key %s\n", nt_errstr(status));
1186 status = smb2cli_flush(cli, fid_persistent, fid_volatile);
1187 if (!NT_STATUS_IS_OK(status)) {
1188 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1192 status = smb2cli_close(cli, 0, fid_persistent, fid_volatile);
1193 if (!NT_STATUS_IS_OK(status)) {
1194 printf("smb2cli_close returned %s\n", nt_errstr(status));
1198 status = smb2cli_create(cli, "multi-channel.txt",
1199 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1200 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1201 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1202 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1203 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1204 FILE_CREATE, /* create_disposition, */
1205 FILE_DELETE_ON_CLOSE, /* create_options, */
1206 NULL, /* smb2_create_blobs *blobs */
1209 if (!NT_STATUS_IS_OK(status)) {
1210 printf("smb2cli_create %s\n", nt_errstr(status));
1214 status = smb2cli_close(cli, 0, fid_persistent, fid_volatile);
1215 if (!NT_STATUS_IS_OK(status)) {
1216 printf("smb2cli_close returned %s\n", nt_errstr(status));