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 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
542 /* now grab the session key and try with signing */
544 status
= smb2cli_session_update_session_key(cli2
->smb2
.session
,
545 ntlmssp
->session_key
,
547 if (!NT_STATUS_IS_OK(status
)) {
548 printf("smb2cli_session_update_session_key %s\n", nt_errstr(status
));
552 /* the tid seems to be irrelevant at this stage */
554 cli2
->smb2
.tid
= cli1
->smb2
.tid
;
556 status
= smb2cli_flush(cli2
, fid_persistent
, fid_volatile
);
557 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
558 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
562 status
= smb2cli_write(cli2
, strlen(hello
), 0, fid_persistent
,
563 fid_volatile
, 0, 0, (const uint8_t *)hello
);
564 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
565 printf("smb2cli_write returned %s\n", nt_errstr(status
));
569 status
= smb2cli_read(cli2
, 0x10000, 0, fid_persistent
,
571 talloc_tos(), &result
, &nread
);
572 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
573 printf("smb2cli_read returned %s\n", nt_errstr(status
));
577 status
= smb2cli_create(cli2
, "session-reconnect.txt",
578 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
579 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
580 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
581 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
582 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
583 FILE_CREATE
, /* create_disposition, */
584 FILE_DELETE_ON_CLOSE
, /* create_options, */
585 NULL
, /* smb2_create_blobs *blobs */
588 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
589 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
593 /* now do a new tcon and test file calls again */
595 status
= cli_tree_connect(cli2
, share
, "?????", "", 0);
596 if (!NT_STATUS_IS_OK(status
)) {
597 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
601 status
= smb2cli_create(cli2
, "session-reconnect.txt",
602 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
603 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
604 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
605 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
606 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
607 FILE_CREATE
, /* create_disposition, */
608 FILE_DELETE_ON_CLOSE
, /* create_options, */
609 NULL
, /* smb2_create_blobs *blobs */
612 if (!NT_STATUS_IS_OK(status
)) {
613 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
617 status
= smb2cli_write(cli2
, strlen(hello
), 0, fid_persistent
,
618 fid_volatile
, 0, 0, (const uint8_t *)hello
);
619 if (!NT_STATUS_IS_OK(status
)) {
620 printf("smb2cli_write returned %s\n", nt_errstr(status
));
624 status
= smb2cli_flush(cli2
, fid_persistent
, fid_volatile
);
625 if (!NT_STATUS_IS_OK(status
)) {
626 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
630 status
= smb2cli_read(cli2
, 0x10000, 0, fid_persistent
,
632 talloc_tos(), &result
, &nread
);
633 if (!NT_STATUS_IS_OK(status
)) {
634 printf("smb2cli_read returned %s\n", nt_errstr(status
));
638 if (nread
!= strlen(hello
)) {
639 printf("smb2cli_read returned %d bytes, expected %d\n",
640 (int)nread
, (int)strlen(hello
));
644 if (memcmp(hello
, result
, nread
) != 0) {
645 printf("smb2cli_read returned '%s', expected '%s'\n",
653 bool run_smb2_tcon_dependence(int dummy
)
655 struct cli_state
*cli
;
657 uint64_t fid_persistent
, fid_volatile
;
658 const char *hello
= "Hello, world\n";
662 printf("Starting SMB2-TCON-DEPENDENCE\n");
664 if (!torture_init_connection(&cli
)) {
667 cli
->smb2
.pid
= 0xFEFF;
669 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
670 PROTOCOL_SMB2_02
, PROTOCOL_SMB2_24
);
671 if (!NT_STATUS_IS_OK(status
)) {
672 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
676 status
= cli_session_setup(cli
, username
,
677 password
, strlen(password
),
678 password
, strlen(password
),
680 if (!NT_STATUS_IS_OK(status
)) {
681 printf("cli_session_setup returned %s\n", nt_errstr(status
));
685 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
686 if (!NT_STATUS_IS_OK(status
)) {
687 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
691 status
= smb2cli_create(cli
, "tcon_depedence.txt",
692 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
693 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
694 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
695 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
696 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
697 FILE_CREATE
, /* create_disposition, */
698 FILE_DELETE_ON_CLOSE
, /* create_options, */
699 NULL
, /* smb2_create_blobs *blobs */
702 if (!NT_STATUS_IS_OK(status
)) {
703 printf("smb2cli_create on cli %s\n", nt_errstr(status
));
707 status
= smb2cli_write(cli
, strlen(hello
), 0, fid_persistent
,
708 fid_volatile
, 0, 0, (const uint8_t *)hello
);
709 if (!NT_STATUS_IS_OK(status
)) {
710 printf("smb2cli_write returned %s\n", nt_errstr(status
));
714 status
= smb2cli_flush(cli
, fid_persistent
, fid_volatile
);
715 if (!NT_STATUS_IS_OK(status
)) {
716 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
720 status
= smb2cli_read(cli
, 0x10000, 0, fid_persistent
,
722 talloc_tos(), &result
, &nread
);
723 if (!NT_STATUS_IS_OK(status
)) {
724 printf("smb2cli_read returned %s\n", nt_errstr(status
));
728 if (nread
!= strlen(hello
)) {
729 printf("smb2cli_read returned %d bytes, expected %d\n",
730 (int)nread
, (int)strlen(hello
));
734 if (memcmp(hello
, result
, nread
) != 0) {
735 printf("smb2cli_read returned '%s', expected '%s'\n",
740 /* check behaviour with wrong tid... */
744 status
= smb2cli_read(cli
, 0x10000, 0, fid_persistent
,
746 talloc_tos(), &result
, &nread
);
747 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
748 printf("smb2cli_read returned %s\n", nt_errstr(status
));
757 bool run_smb2_multi_channel(int dummy
)
759 struct cli_state
*cli1
;
760 struct cli_state
*cli2
;
763 uint64_t fid_persistent
, fid_volatile
;
764 struct tevent_context
*ev
;
765 struct tevent_req
*subreq
;
766 DATA_BLOB in_blob
= data_blob_null
;
768 struct ntlmssp_state
*ntlmssp
;
769 struct iovec
*recv_iov
;
770 const char *hello
= "Hello, world\n";
774 printf("Starting SMB2-MULTI-CHANNEL\n");
776 if (!torture_init_connection(&cli1
)) {
779 cli1
->smb2
.pid
= 0xFEFF;
781 if (!torture_init_connection(&cli2
)) {
784 cli2
->smb2
.pid
= 0xFEFF;
786 status
= smbXcli_negprot(cli1
->conn
, cli1
->timeout
,
787 PROTOCOL_SMB2_22
, PROTOCOL_SMB2_24
);
788 if (!NT_STATUS_IS_OK(status
)) {
789 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
793 status
= smbXcli_negprot(cli2
->conn
, cli2
->timeout
,
794 PROTOCOL_SMB2_22
, PROTOCOL_SMB2_24
);
795 if (!NT_STATUS_IS_OK(status
)) {
796 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
800 status
= cli_session_setup(cli1
, username
,
801 password
, strlen(password
),
802 password
, strlen(password
),
804 if (!NT_STATUS_IS_OK(status
)) {
805 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status
));
809 status
= cli_tree_connect(cli1
, share
, "?????", "", 0);
810 if (!NT_STATUS_IS_OK(status
)) {
811 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
815 status
= smb2cli_session_create_channel(cli2
,
818 &cli2
->smb2
.session
);
819 if (!NT_STATUS_IS_OK(status
)) {
820 printf("smb2cli_session_create_channel returned %s\n",
825 status
= ntlmssp_client_start(talloc_tos(),
828 lp_client_ntlmv2_auth(),
830 if (!NT_STATUS_IS_OK(status
)) {
831 printf("ntlmssp_client_start returned %s\n", nt_errstr(status
));
835 ntlmssp_want_feature(ntlmssp
,
836 NTLMSSP_FEATURE_SESSION_KEY
);
837 status
= ntlmssp_set_username(ntlmssp
, username
);
838 if (!NT_STATUS_IS_OK(status
)) {
839 printf("ntlmssp_set_username returned %s\n", nt_errstr(status
));
843 status
= ntlmssp_set_domain(ntlmssp
, workgroup
);
844 if (!NT_STATUS_IS_OK(status
)) {
845 printf("ntlmssp_set_domain returned %s\n", nt_errstr(status
));
849 status
= ntlmssp_set_password(ntlmssp
, password
);
850 if (!NT_STATUS_IS_OK(status
)) {
851 printf("ntlmssp_set_password returned %s\n", nt_errstr(status
));
855 status
= ntlmssp_update(ntlmssp
, data_blob_null
, &in_blob
);
856 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
857 printf("ntlmssp_update returned %s\n", nt_errstr(status
));
861 ev
= event_context_init(talloc_tos());
863 printf("event_context_init() returned NULL\n");
867 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
872 SMB2_CAP_DFS
, /* in_capabilities */
874 NULL
, /* in_previous_session */
875 &in_blob
); /* in_security_buffer */
876 if (subreq
== NULL
) {
877 printf("smb2cli_session_setup_send() returned NULL\n");
881 ok
= tevent_req_poll(subreq
, ev
);
883 printf("tevent_req_poll() returned false\n");
887 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
889 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
890 printf("smb2cli_session_setup_recv returned %s\n",
895 status
= ntlmssp_update(ntlmssp
, out_blob
, &in_blob
);
896 if (!NT_STATUS_IS_OK(status
)) {
897 printf("ntlmssp_update returned %s\n", nt_errstr(status
));
901 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
906 SMB2_CAP_DFS
, /* in_capabilities */
908 NULL
, /* in_previous_session */
909 &in_blob
); /* in_security_buffer */
910 if (subreq
== NULL
) {
911 printf("smb2cli_session_setup_send() returned NULL\n");
915 ok
= tevent_req_poll(subreq
, ev
);
917 printf("tevent_req_poll() returned false\n");
921 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
922 &recv_iov
, &out_blob
);
923 if (!NT_STATUS_IS_OK(status
)) {
924 printf("smb2cli_session_setup_recv returned %s\n",
929 status
= smb2cli_session_update_session_key(cli2
->smb2
.session
,
930 ntlmssp
->session_key
,
932 if (!NT_STATUS_IS_OK(status
)) {
933 printf("smb2cli_session_update_session_key %s\n", nt_errstr(status
));
937 cli2
->smb2
.tid
= cli1
->smb2
.tid
;
939 status
= smb2cli_create(cli2
, "multi-channel.txt",
940 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
941 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
942 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
943 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
944 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
945 FILE_CREATE
, /* create_disposition, */
946 FILE_DELETE_ON_CLOSE
, /* create_options, */
947 NULL
, /* smb2_create_blobs *blobs */
950 if (!NT_STATUS_IS_OK(status
)) {
951 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
955 status
= smb2cli_write(cli1
, strlen(hello
), 0, fid_persistent
,
956 fid_volatile
, 0, 0, (const uint8_t *)hello
);
957 if (!NT_STATUS_IS_OK(status
)) {
958 printf("smb2cli_write returned %s\n", nt_errstr(status
));
962 status
= smb2cli_flush(cli2
, fid_persistent
, fid_volatile
);
963 if (!NT_STATUS_IS_OK(status
)) {
964 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
968 status
= smb2cli_flush(cli1
, fid_persistent
, fid_volatile
);
969 if (!NT_STATUS_IS_OK(status
)) {
970 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
974 status
= smb2cli_read(cli2
, 0x10000, 0, fid_persistent
,
976 talloc_tos(), &result
, &nread
);
977 if (!NT_STATUS_IS_OK(status
)) {
978 printf("smb2cli_read returned %s\n", nt_errstr(status
));
982 if (nread
!= strlen(hello
)) {
983 printf("smb2cli_read returned %d bytes, expected %d\n",
984 (int)nread
, (int)strlen(hello
));
988 if (memcmp(hello
, result
, nread
) != 0) {
989 printf("smb2cli_read returned '%s', expected '%s'\n",
994 status
= smb2cli_close(cli1
, 0, fid_persistent
, fid_volatile
);
995 if (!NT_STATUS_IS_OK(status
)) {
996 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1000 status
= smb2cli_flush(cli2
, fid_persistent
, fid_volatile
);
1001 if (!NT_STATUS_IS_OK(status
)) {
1002 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1005 status
= smb2cli_flush(cli1
, fid_persistent
, fid_volatile
);
1006 if (!NT_STATUS_IS_OK(status
)) {
1007 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1013 bool run_smb2_session_reauth(int dummy
)
1015 struct cli_state
*cli
;
1018 uint64_t fid_persistent
, fid_volatile
;
1019 struct tevent_context
*ev
;
1020 struct tevent_req
*subreq
;
1021 DATA_BLOB in_blob
= data_blob_null
;
1023 struct ntlmssp_state
*ntlmssp
;
1024 struct iovec
*recv_iov
;
1026 printf("Starting SMB2-SESSION_REAUTH\n");
1028 if (!torture_init_connection(&cli
)) {
1031 cli
->smb2
.pid
= 0xFEFF;
1034 * PROTOCOL_SMB2_22 has a bug in win8pre0
1035 * it behaves like PROTOCOL_SMB2_02
1036 * and returns NT_STATUS_REQUEST_NOT_ACCEPTED,
1037 * while it allows it on PROTOCOL_SMB2_02.
1039 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
1040 PROTOCOL_SMB2_10
, PROTOCOL_SMB2_10
);
1041 if (!NT_STATUS_IS_OK(status
)) {
1042 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
1046 status
= cli_session_setup(cli
, username
,
1047 password
, strlen(password
),
1048 password
, strlen(password
),
1050 if (!NT_STATUS_IS_OK(status
)) {
1051 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status
));
1055 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
1056 if (!NT_STATUS_IS_OK(status
)) {
1057 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1061 status
= smb2cli_create(cli
, "session-reauth.txt",
1062 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1063 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1064 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1065 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1066 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1067 FILE_CREATE
, /* create_disposition, */
1068 FILE_DELETE_ON_CLOSE
, /* create_options, */
1069 NULL
, /* smb2_create_blobs *blobs */
1072 if (!NT_STATUS_IS_OK(status
)) {
1073 printf("smb2cli_create %s\n", nt_errstr(status
));
1077 status
= ntlmssp_client_start(talloc_tos(),
1080 lp_client_ntlmv2_auth(),
1082 if (!NT_STATUS_IS_OK(status
)) {
1083 printf("ntlmssp_client_start returned %s\n", nt_errstr(status
));
1087 ntlmssp_want_feature(ntlmssp
,
1088 NTLMSSP_FEATURE_SESSION_KEY
);
1089 status
= ntlmssp_set_username(ntlmssp
, username
);
1090 if (!NT_STATUS_IS_OK(status
)) {
1091 printf("ntlmssp_set_username returned %s\n", nt_errstr(status
));
1095 status
= ntlmssp_set_domain(ntlmssp
, workgroup
);
1096 if (!NT_STATUS_IS_OK(status
)) {
1097 printf("ntlmssp_set_domain returned %s\n", nt_errstr(status
));
1101 status
= ntlmssp_set_password(ntlmssp
, password
);
1102 if (!NT_STATUS_IS_OK(status
)) {
1103 printf("ntlmssp_set_password returned %s\n", nt_errstr(status
));
1107 status
= ntlmssp_update(ntlmssp
, data_blob_null
, &in_blob
);
1108 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1109 printf("ntlmssp_update returned %s\n", nt_errstr(status
));
1113 ev
= event_context_init(talloc_tos());
1115 printf("event_context_init() returned NULL\n");
1119 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1124 SMB2_CAP_DFS
, /* in_capabilities */
1126 NULL
, /* in_previous_session */
1127 &in_blob
); /* in_security_buffer */
1128 if (subreq
== NULL
) {
1129 printf("smb2cli_session_setup_send() returned NULL\n");
1133 ok
= tevent_req_poll(subreq
, ev
);
1135 printf("tevent_req_poll() returned false\n");
1139 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1141 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1142 printf("smb2cli_session_setup_recv returned %s\n",
1147 status
= ntlmssp_update(ntlmssp
, out_blob
, &in_blob
);
1148 if (!NT_STATUS_IS_OK(status
)) {
1149 printf("ntlmssp_update returned %s\n", nt_errstr(status
));
1153 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1158 SMB2_CAP_DFS
, /* in_capabilities */
1160 NULL
, /* in_previous_session */
1161 &in_blob
); /* in_security_buffer */
1162 if (subreq
== NULL
) {
1163 printf("smb2cli_session_setup_send() returned NULL\n");
1167 ok
= tevent_req_poll(subreq
, ev
);
1169 printf("tevent_req_poll() returned false\n");
1173 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1174 &recv_iov
, &out_blob
);
1175 if (!NT_STATUS_IS_OK(status
)) {
1176 printf("smb2cli_session_setup_recv returned %s\n",
1181 status
= smb2cli_session_update_session_key(cli
->smb2
.session
,
1182 ntlmssp
->session_key
,
1184 if (!NT_STATUS_IS_OK(status
)) {
1185 printf("smb2cli_session_update_session_key %s\n", nt_errstr(status
));
1189 status
= smb2cli_flush(cli
, fid_persistent
, fid_volatile
);
1190 if (!NT_STATUS_IS_OK(status
)) {
1191 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1195 status
= smb2cli_close(cli
, 0, fid_persistent
, fid_volatile
);
1196 if (!NT_STATUS_IS_OK(status
)) {
1197 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1201 status
= smb2cli_create(cli
, "multi-channel.txt",
1202 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1203 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1204 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1205 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1206 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1207 FILE_CREATE
, /* create_disposition, */
1208 FILE_DELETE_ON_CLOSE
, /* create_options, */
1209 NULL
, /* smb2_create_blobs *blobs */
1212 if (!NT_STATUS_IS_OK(status
)) {
1213 printf("smb2cli_create %s\n", nt_errstr(status
));
1217 status
= smb2cli_close(cli
, 0, fid_persistent
, fid_volatile
);
1218 if (!NT_STATUS_IS_OK(status
)) {
1219 printf("smb2cli_close returned %s\n", nt_errstr(status
));