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
;
42 printf("Starting SMB2-BASIC\n");
44 if (!torture_init_connection(&cli
)) {
47 cli
->smb2
.pid
= 0xFEFF;
49 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
50 PROTOCOL_SMB2_02
, PROTOCOL_SMB2_02
);
51 if (!NT_STATUS_IS_OK(status
)) {
52 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
56 status
= cli_session_setup(cli
, username
,
57 password
, strlen(password
),
58 password
, strlen(password
),
60 if (!NT_STATUS_IS_OK(status
)) {
61 printf("cli_session_setup returned %s\n", nt_errstr(status
));
65 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
66 if (!NT_STATUS_IS_OK(status
)) {
67 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
71 status
= smb2cli_create(cli
, "smb2-basic.txt",
72 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
73 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
74 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
75 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
76 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
77 FILE_CREATE
, /* create_disposition, */
78 FILE_DELETE_ON_CLOSE
, /* create_options, */
79 NULL
, /* smb2_create_blobs *blobs */
82 if (!NT_STATUS_IS_OK(status
)) {
83 printf("smb2cli_create returned %s\n", nt_errstr(status
));
87 status
= smb2cli_write(cli
, strlen(hello
), 0, fid_persistent
,
88 fid_volatile
, 0, 0, (const uint8_t *)hello
);
89 if (!NT_STATUS_IS_OK(status
)) {
90 printf("smb2cli_write returned %s\n", nt_errstr(status
));
94 status
= smb2cli_flush(cli
, fid_persistent
, fid_volatile
);
95 if (!NT_STATUS_IS_OK(status
)) {
96 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
100 status
= smb2cli_read(cli
, 0x10000, 0, fid_persistent
,
102 talloc_tos(), &result
, &nread
);
103 if (!NT_STATUS_IS_OK(status
)) {
104 printf("smb2cli_read returned %s\n", nt_errstr(status
));
108 if (nread
!= strlen(hello
)) {
109 printf("smb2cli_read returned %d bytes, expected %d\n",
110 (int)nread
, (int)strlen(hello
));
114 if (memcmp(hello
, result
, nread
) != 0) {
115 printf("smb2cli_read returned '%s', expected '%s'\n",
120 status
= smb2cli_close(cli
, 0, fid_persistent
, fid_volatile
);
121 if (!NT_STATUS_IS_OK(status
)) {
122 printf("smb2cli_close returned %s\n", nt_errstr(status
));
126 status
= smb2cli_create(cli
, "",
127 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
128 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
131 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
132 0, /* file_attributes, */
133 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
134 FILE_OPEN
, /* create_disposition, */
135 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
136 NULL
, /* smb2_create_blobs *blobs */
139 if (!NT_STATUS_IS_OK(status
)) {
140 printf("smb2cli_create returned %s\n", nt_errstr(status
));
144 status
= smb2cli_query_directory(
145 cli
, 1, 0, 0, fid_persistent
, fid_volatile
, "*", 0xffff,
146 talloc_tos(), &dir_data
, &dir_data_length
);
148 if (!NT_STATUS_IS_OK(status
)) {
149 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
153 status
= smb2cli_close(cli
, 0, fid_persistent
, fid_volatile
);
154 if (!NT_STATUS_IS_OK(status
)) {
155 printf("smb2cli_close returned %s\n", nt_errstr(status
));
162 bool run_smb2_negprot(int dummy
)
164 struct cli_state
*cli
;
166 enum protocol_types protocol
;
167 const char *name
= NULL
;
169 printf("Starting SMB2-NEGPROT\n");
171 if (!torture_init_connection(&cli
)) {
174 cli
->smb2
.pid
= 0xFEFF;
176 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
177 PROTOCOL_CORE
, PROTOCOL_SMB2_22
);
178 if (!NT_STATUS_IS_OK(status
)) {
179 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
183 protocol
= smbXcli_conn_protocol(cli
->conn
);
186 case PROTOCOL_SMB2_02
:
189 case PROTOCOL_SMB2_10
:
192 case PROTOCOL_SMB2_22
:
200 printf("Server supports %s\n", name
);
202 printf("Server DOES NOT support SMB2\n");
206 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
208 if (!NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_RESET
) &&
209 !NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_DISCONNECTED
) &&
210 !NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_ABORTED
)) {
211 printf("2nd smbXcli_negprot should disconnect - returned %s\n",
216 if (smbXcli_conn_is_connected(cli
->conn
)) {
217 printf("2nd smbXcli_negprot should disconnect "
218 "- still connected\n");
225 bool run_smb2_session_reconnect(int dummy
)
227 struct cli_state
*cli1
;
228 struct cli_state
*cli2
;
231 uint64_t fid_persistent
, fid_volatile
;
232 struct tevent_context
*ev
;
233 struct tevent_req
*subreq
;
234 DATA_BLOB in_blob
= data_blob_null
;
236 struct ntlmssp_state
*ntlmssp
;
237 struct iovec
*recv_iov
;
238 const char *hello
= "Hello, world\n";
242 printf("Starting SMB2-SESSION-RECONNECT\n");
244 if (!torture_init_connection(&cli1
)) {
247 cli1
->smb2
.pid
= 0xFEFF;
249 status
= smbXcli_negprot(cli1
->conn
, cli1
->timeout
,
250 PROTOCOL_SMB2_02
, PROTOCOL_SMB2_22
);
251 if (!NT_STATUS_IS_OK(status
)) {
252 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
256 status
= cli_session_setup(cli1
, username
,
257 password
, strlen(password
),
258 password
, strlen(password
),
260 if (!NT_STATUS_IS_OK(status
)) {
261 printf("cli_session_setup returned %s\n", nt_errstr(status
));
265 status
= cli_tree_connect(cli1
, share
, "?????", "", 0);
266 if (!NT_STATUS_IS_OK(status
)) {
267 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
271 status
= smb2cli_create(cli1
, "session-reconnect.txt",
272 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
273 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
274 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
275 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
276 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
277 FILE_CREATE
, /* create_disposition, */
278 FILE_DELETE_ON_CLOSE
, /* create_options, */
279 NULL
, /* smb2_create_blobs *blobs */
282 if (!NT_STATUS_IS_OK(status
)) {
283 printf("smb2cli_create on cli1 %s\n", nt_errstr(status
));
287 status
= smb2cli_write(cli1
, strlen(hello
), 0, fid_persistent
,
288 fid_volatile
, 0, 0, (const uint8_t *)hello
);
289 if (!NT_STATUS_IS_OK(status
)) {
290 printf("smb2cli_write returned %s\n", nt_errstr(status
));
294 status
= smb2cli_flush(cli1
, fid_persistent
, fid_volatile
);
295 if (!NT_STATUS_IS_OK(status
)) {
296 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
300 status
= smb2cli_read(cli1
, 0x10000, 0, fid_persistent
,
302 talloc_tos(), &result
, &nread
);
303 if (!NT_STATUS_IS_OK(status
)) {
304 printf("smb2cli_read returned %s\n", nt_errstr(status
));
308 if (nread
!= strlen(hello
)) {
309 printf("smb2cli_read returned %d bytes, expected %d\n",
310 (int)nread
, (int)strlen(hello
));
314 if (memcmp(hello
, result
, nread
) != 0) {
315 printf("smb2cli_read returned '%s', expected '%s'\n",
320 /* prepare second session */
322 if (!torture_init_connection(&cli2
)) {
325 cli2
->smb2
.pid
= 0xFEFF;
327 status
= smbXcli_negprot(cli2
->conn
, cli2
->timeout
,
328 PROTOCOL_SMB2_02
, PROTOCOL_SMB2_22
);
329 if (!NT_STATUS_IS_OK(status
)) {
330 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
334 status
= ntlmssp_client_start(talloc_tos(),
337 lp_client_ntlmv2_auth(),
339 if (!NT_STATUS_IS_OK(status
)) {
340 printf("ntlmssp_client_start returned %s\n", nt_errstr(status
));
344 ntlmssp_want_feature(ntlmssp
,
345 NTLMSSP_FEATURE_SESSION_KEY
);
346 status
= ntlmssp_set_username(ntlmssp
, username
);
347 if (!NT_STATUS_IS_OK(status
)) {
348 printf("ntlmssp_set_username returned %s\n", nt_errstr(status
));
352 status
= ntlmssp_set_domain(ntlmssp
, workgroup
);
353 if (!NT_STATUS_IS_OK(status
)) {
354 printf("ntlmssp_set_domain returned %s\n", nt_errstr(status
));
358 status
= ntlmssp_set_password(ntlmssp
, password
);
359 if (!NT_STATUS_IS_OK(status
)) {
360 printf("ntlmssp_set_password returned %s\n", nt_errstr(status
));
364 status
= ntlmssp_update(ntlmssp
, data_blob_null
, &in_blob
);
365 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
366 printf("ntlmssp_update returned %s\n", nt_errstr(status
));
370 cli2
->smb2
.session
= smbXcli_session_create(cli2
, cli2
->conn
);
372 ev
= event_context_init(talloc_tos());
374 printf("event_context_init() returned NULL\n");
378 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
383 SMB2_CAP_DFS
, /* in_capabilities */
385 cli1
->smb2
.session
, /* in_previous_session */
386 &in_blob
); /* in_security_buffer */
387 if (subreq
== NULL
) {
388 printf("smb2cli_session_setup_send() returned NULL\n");
392 ok
= tevent_req_poll(subreq
, ev
);
394 printf("tevent_req_poll() returned false\n");
398 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
400 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
401 printf("smb2cli_session_setup_recv returned %s\n",
406 status
= ntlmssp_update(ntlmssp
, out_blob
, &in_blob
);
407 if (!NT_STATUS_IS_OK(status
)) {
408 printf("ntlmssp_update returned %s\n", nt_errstr(status
));
412 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
417 SMB2_CAP_DFS
, /* in_capabilities */
419 cli1
->smb2
.session
, /* in_previous_session */
420 &in_blob
); /* in_security_buffer */
421 if (subreq
== NULL
) {
422 printf("smb2cli_session_setup_send() returned NULL\n");
426 ok
= tevent_req_poll(subreq
, ev
);
428 printf("tevent_req_poll() returned false\n");
432 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
433 &recv_iov
, &out_blob
);
434 if (!NT_STATUS_IS_OK(status
)) {
435 printf("smb2cli_session_setup_recv returned %s\n",
440 status
= smb2_signing_check_pdu(ntlmssp
->session_key
, recv_iov
, 3);
441 if (!NT_STATUS_IS_OK(status
)) {
442 printf("check pdu returned %s\n", nt_errstr(status
));
446 /* check file operation on the old client */
448 status
= smb2cli_flush(cli1
, fid_persistent
, fid_volatile
);
449 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
450 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
454 status
= cli_tree_connect(cli1
, share
, "?????", "", 0);
455 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
456 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
461 * checking file operations without signing.
462 * on w2k8r2 at least, flush, read and write also work the same way,
463 * while create gives ACCESS_DENIED without signing
465 status
= smb2cli_flush(cli2
, fid_persistent
, fid_volatile
);
466 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
467 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
471 status
= smb2cli_write(cli2
, strlen(hello
), 0, fid_persistent
,
472 fid_volatile
, 0, 0, (const uint8_t *)hello
);
473 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
474 printf("smb2cli_write returned %s\n", nt_errstr(status
));
478 status
= smb2cli_read(cli2
, 0x10000, 0, fid_persistent
,
480 talloc_tos(), &result
, &nread
);
481 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
482 printf("smb2cli_read returned %s\n", nt_errstr(status
));
486 status
= smb2cli_create(cli2
, "session-reconnect.txt",
487 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
488 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
489 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
490 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
491 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
492 FILE_CREATE
, /* create_disposition, */
493 FILE_DELETE_ON_CLOSE
, /* create_options, */
494 NULL
, /* smb2_create_blobs *blobs */
497 if (!NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
)) {
498 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
502 /* now grab the session key and try with signing */
504 status
= smb2cli_session_update_session_key(cli2
->smb2
.session
,
505 ntlmssp
->session_key
,
507 if (!NT_STATUS_IS_OK(status
)) {
508 printf("smb2cli_session_update_session_key %s\n", nt_errstr(status
));
512 /* the tid seems to be irrelevant at this stage */
514 cli2
->smb2
.tid
= cli1
->smb2
.tid
;
516 status
= smb2cli_flush(cli2
, fid_persistent
, fid_volatile
);
517 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
518 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
522 status
= smb2cli_write(cli2
, strlen(hello
), 0, fid_persistent
,
523 fid_volatile
, 0, 0, (const uint8_t *)hello
);
524 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
525 printf("smb2cli_write returned %s\n", nt_errstr(status
));
529 status
= smb2cli_read(cli2
, 0x10000, 0, fid_persistent
,
531 talloc_tos(), &result
, &nread
);
532 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
533 printf("smb2cli_read returned %s\n", nt_errstr(status
));
537 status
= smb2cli_create(cli2
, "session-reconnect.txt",
538 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
539 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
540 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
541 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
542 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
543 FILE_CREATE
, /* create_disposition, */
544 FILE_DELETE_ON_CLOSE
, /* create_options, */
545 NULL
, /* smb2_create_blobs *blobs */
548 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
549 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
553 /* now do a new tcon and test file calls again */
555 status
= cli_tree_connect(cli2
, share
, "?????", "", 0);
556 if (!NT_STATUS_IS_OK(status
)) {
557 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
561 status
= smb2cli_create(cli2
, "session-reconnect.txt",
562 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
563 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
564 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
565 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
566 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
567 FILE_CREATE
, /* create_disposition, */
568 FILE_DELETE_ON_CLOSE
, /* create_options, */
569 NULL
, /* smb2_create_blobs *blobs */
572 if (!NT_STATUS_IS_OK(status
)) {
573 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
577 status
= smb2cli_write(cli2
, strlen(hello
), 0, fid_persistent
,
578 fid_volatile
, 0, 0, (const uint8_t *)hello
);
579 if (!NT_STATUS_IS_OK(status
)) {
580 printf("smb2cli_write returned %s\n", nt_errstr(status
));
584 status
= smb2cli_flush(cli2
, fid_persistent
, fid_volatile
);
585 if (!NT_STATUS_IS_OK(status
)) {
586 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
590 status
= smb2cli_read(cli2
, 0x10000, 0, fid_persistent
,
592 talloc_tos(), &result
, &nread
);
593 if (!NT_STATUS_IS_OK(status
)) {
594 printf("smb2cli_read returned %s\n", nt_errstr(status
));
598 if (nread
!= strlen(hello
)) {
599 printf("smb2cli_read returned %d bytes, expected %d\n",
600 (int)nread
, (int)strlen(hello
));
604 if (memcmp(hello
, result
, nread
) != 0) {
605 printf("smb2cli_read returned '%s', expected '%s'\n",
613 bool run_smb2_tcon_dependence(int dummy
)
615 struct cli_state
*cli
;
617 uint64_t fid_persistent
, fid_volatile
;
618 const char *hello
= "Hello, world\n";
622 printf("Starting SMB2-TCON-DEPENDENCE\n");
624 if (!torture_init_connection(&cli
)) {
627 cli
->smb2
.pid
= 0xFEFF;
629 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
630 PROTOCOL_SMB2_02
, PROTOCOL_SMB2_22
);
631 if (!NT_STATUS_IS_OK(status
)) {
632 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
636 status
= cli_session_setup(cli
, username
,
637 password
, strlen(password
),
638 password
, strlen(password
),
640 if (!NT_STATUS_IS_OK(status
)) {
641 printf("cli_session_setup returned %s\n", nt_errstr(status
));
645 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
646 if (!NT_STATUS_IS_OK(status
)) {
647 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
651 status
= smb2cli_create(cli
, "tcon_depedence.txt",
652 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
653 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
654 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
655 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
656 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
657 FILE_CREATE
, /* create_disposition, */
658 FILE_DELETE_ON_CLOSE
, /* create_options, */
659 NULL
, /* smb2_create_blobs *blobs */
662 if (!NT_STATUS_IS_OK(status
)) {
663 printf("smb2cli_create on cli %s\n", nt_errstr(status
));
667 status
= smb2cli_write(cli
, strlen(hello
), 0, fid_persistent
,
668 fid_volatile
, 0, 0, (const uint8_t *)hello
);
669 if (!NT_STATUS_IS_OK(status
)) {
670 printf("smb2cli_write returned %s\n", nt_errstr(status
));
674 status
= smb2cli_flush(cli
, fid_persistent
, fid_volatile
);
675 if (!NT_STATUS_IS_OK(status
)) {
676 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
680 status
= smb2cli_read(cli
, 0x10000, 0, fid_persistent
,
682 talloc_tos(), &result
, &nread
);
683 if (!NT_STATUS_IS_OK(status
)) {
684 printf("smb2cli_read returned %s\n", nt_errstr(status
));
688 if (nread
!= strlen(hello
)) {
689 printf("smb2cli_read returned %d bytes, expected %d\n",
690 (int)nread
, (int)strlen(hello
));
694 if (memcmp(hello
, result
, nread
) != 0) {
695 printf("smb2cli_read returned '%s', expected '%s'\n",
700 /* check behaviour with wrong tid... */
704 status
= smb2cli_read(cli
, 0x10000, 0, fid_persistent
,
706 talloc_tos(), &result
, &nread
);
707 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
708 printf("smb2cli_read returned %s\n", nt_errstr(status
));
717 bool run_smb2_multi_channel(int dummy
)
719 struct cli_state
*cli1
;
720 struct cli_state
*cli2
;
723 uint64_t fid_persistent
, fid_volatile
;
724 struct tevent_context
*ev
;
725 struct tevent_req
*subreq
;
726 DATA_BLOB in_blob
= data_blob_null
;
728 struct ntlmssp_state
*ntlmssp
;
729 struct iovec
*recv_iov
;
730 const char *hello
= "Hello, world\n";
734 printf("Starting SMB2-MULTI-CHANNEL\n");
736 if (!torture_init_connection(&cli1
)) {
739 cli1
->smb2
.pid
= 0xFEFF;
741 if (!torture_init_connection(&cli2
)) {
744 cli2
->smb2
.pid
= 0xFEFF;
746 status
= smbXcli_negprot(cli1
->conn
, cli1
->timeout
,
747 PROTOCOL_SMB2_22
, PROTOCOL_SMB2_22
);
748 if (!NT_STATUS_IS_OK(status
)) {
749 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
753 status
= smbXcli_negprot(cli2
->conn
, cli2
->timeout
,
754 PROTOCOL_SMB2_22
, PROTOCOL_SMB2_22
);
755 if (!NT_STATUS_IS_OK(status
)) {
756 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
760 status
= cli_session_setup(cli1
, username
,
761 password
, strlen(password
),
762 password
, strlen(password
),
764 if (!NT_STATUS_IS_OK(status
)) {
765 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status
));
769 status
= cli_tree_connect(cli1
, share
, "?????", "", 0);
770 if (!NT_STATUS_IS_OK(status
)) {
771 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
775 status
= smb2cli_session_create_channel(cli2
,
778 &cli2
->smb2
.session
);
779 if (!NT_STATUS_IS_OK(status
)) {
780 printf("smb2cli_session_create_channel returned %s\n",
785 status
= ntlmssp_client_start(talloc_tos(),
788 lp_client_ntlmv2_auth(),
790 if (!NT_STATUS_IS_OK(status
)) {
791 printf("ntlmssp_client_start returned %s\n", nt_errstr(status
));
795 ntlmssp_want_feature(ntlmssp
,
796 NTLMSSP_FEATURE_SESSION_KEY
);
797 status
= ntlmssp_set_username(ntlmssp
, username
);
798 if (!NT_STATUS_IS_OK(status
)) {
799 printf("ntlmssp_set_username returned %s\n", nt_errstr(status
));
803 status
= ntlmssp_set_domain(ntlmssp
, workgroup
);
804 if (!NT_STATUS_IS_OK(status
)) {
805 printf("ntlmssp_set_domain returned %s\n", nt_errstr(status
));
809 status
= ntlmssp_set_password(ntlmssp
, password
);
810 if (!NT_STATUS_IS_OK(status
)) {
811 printf("ntlmssp_set_password returned %s\n", nt_errstr(status
));
815 status
= ntlmssp_update(ntlmssp
, data_blob_null
, &in_blob
);
816 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
817 printf("ntlmssp_update returned %s\n", nt_errstr(status
));
821 ev
= event_context_init(talloc_tos());
823 printf("event_context_init() returned NULL\n");
827 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
832 SMB2_CAP_DFS
, /* in_capabilities */
834 NULL
, /* in_previous_session */
835 &in_blob
); /* in_security_buffer */
836 if (subreq
== NULL
) {
837 printf("smb2cli_session_setup_send() returned NULL\n");
841 ok
= tevent_req_poll(subreq
, ev
);
843 printf("tevent_req_poll() returned false\n");
847 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
849 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
850 printf("smb2cli_session_setup_recv returned %s\n",
855 status
= ntlmssp_update(ntlmssp
, out_blob
, &in_blob
);
856 if (!NT_STATUS_IS_OK(status
)) {
857 printf("ntlmssp_update returned %s\n", nt_errstr(status
));
861 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
866 SMB2_CAP_DFS
, /* in_capabilities */
868 NULL
, /* in_previous_session */
869 &in_blob
); /* in_security_buffer */
870 if (subreq
== NULL
) {
871 printf("smb2cli_session_setup_send() returned NULL\n");
875 ok
= tevent_req_poll(subreq
, ev
);
877 printf("tevent_req_poll() returned false\n");
881 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
882 &recv_iov
, &out_blob
);
883 if (!NT_STATUS_IS_OK(status
)) {
884 printf("smb2cli_session_setup_recv returned %s\n",
889 status
= smb2cli_session_update_session_key(cli2
->smb2
.session
,
890 ntlmssp
->session_key
,
892 if (!NT_STATUS_IS_OK(status
)) {
893 printf("smb2cli_session_update_session_key %s\n", nt_errstr(status
));
897 cli2
->smb2
.tid
= cli1
->smb2
.tid
;
899 status
= smb2cli_create(cli2
, "multi-channel.txt",
900 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
901 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
902 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
903 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
904 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
905 FILE_CREATE
, /* create_disposition, */
906 FILE_DELETE_ON_CLOSE
, /* create_options, */
907 NULL
, /* smb2_create_blobs *blobs */
910 if (!NT_STATUS_IS_OK(status
)) {
911 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
915 status
= smb2cli_write(cli1
, strlen(hello
), 0, fid_persistent
,
916 fid_volatile
, 0, 0, (const uint8_t *)hello
);
917 if (!NT_STATUS_IS_OK(status
)) {
918 printf("smb2cli_write returned %s\n", nt_errstr(status
));
922 status
= smb2cli_flush(cli2
, fid_persistent
, fid_volatile
);
923 if (!NT_STATUS_IS_OK(status
)) {
924 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
928 status
= smb2cli_flush(cli1
, fid_persistent
, fid_volatile
);
929 if (!NT_STATUS_IS_OK(status
)) {
930 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
934 status
= smb2cli_read(cli2
, 0x10000, 0, fid_persistent
,
936 talloc_tos(), &result
, &nread
);
937 if (!NT_STATUS_IS_OK(status
)) {
938 printf("smb2cli_read returned %s\n", nt_errstr(status
));
942 if (nread
!= strlen(hello
)) {
943 printf("smb2cli_read returned %d bytes, expected %d\n",
944 (int)nread
, (int)strlen(hello
));
948 if (memcmp(hello
, result
, nread
) != 0) {
949 printf("smb2cli_read returned '%s', expected '%s'\n",
954 status
= smb2cli_close(cli1
, 0, fid_persistent
, fid_volatile
);
955 if (!NT_STATUS_IS_OK(status
)) {
956 printf("smb2cli_close returned %s\n", nt_errstr(status
));
960 status
= smb2cli_flush(cli2
, fid_persistent
, fid_volatile
);
961 if (!NT_STATUS_IS_OK(status
)) {
962 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
));
973 bool run_smb2_session_reauth(int dummy
)
975 struct cli_state
*cli
;
978 uint64_t fid_persistent
, fid_volatile
;
979 struct tevent_context
*ev
;
980 struct tevent_req
*subreq
;
981 DATA_BLOB in_blob
= data_blob_null
;
983 struct ntlmssp_state
*ntlmssp
;
984 struct iovec
*recv_iov
;
986 printf("Starting SMB2-SESSION_REAUTH\n");
988 if (!torture_init_connection(&cli
)) {
991 cli
->smb2
.pid
= 0xFEFF;
994 * PROTOCOL_SMB2_22 has a bug in win8pre0
995 * it behaves like PROTOCOL_SMB2_02
996 * and returns NT_STATUS_REQUEST_NOT_ACCEPTED,
997 * while it allows it on PROTOCOL_SMB2_02.
999 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
1000 PROTOCOL_SMB2_10
, PROTOCOL_SMB2_10
);
1001 if (!NT_STATUS_IS_OK(status
)) {
1002 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
1006 status
= cli_session_setup(cli
, username
,
1007 password
, strlen(password
),
1008 password
, strlen(password
),
1010 if (!NT_STATUS_IS_OK(status
)) {
1011 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status
));
1015 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
1016 if (!NT_STATUS_IS_OK(status
)) {
1017 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1021 status
= smb2cli_create(cli
, "session-reauth.txt",
1022 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1023 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1024 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1025 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1026 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1027 FILE_CREATE
, /* create_disposition, */
1028 FILE_DELETE_ON_CLOSE
, /* create_options, */
1029 NULL
, /* smb2_create_blobs *blobs */
1032 if (!NT_STATUS_IS_OK(status
)) {
1033 printf("smb2cli_create %s\n", nt_errstr(status
));
1037 status
= ntlmssp_client_start(talloc_tos(),
1040 lp_client_ntlmv2_auth(),
1042 if (!NT_STATUS_IS_OK(status
)) {
1043 printf("ntlmssp_client_start returned %s\n", nt_errstr(status
));
1047 ntlmssp_want_feature(ntlmssp
,
1048 NTLMSSP_FEATURE_SESSION_KEY
);
1049 status
= ntlmssp_set_username(ntlmssp
, username
);
1050 if (!NT_STATUS_IS_OK(status
)) {
1051 printf("ntlmssp_set_username returned %s\n", nt_errstr(status
));
1055 status
= ntlmssp_set_domain(ntlmssp
, workgroup
);
1056 if (!NT_STATUS_IS_OK(status
)) {
1057 printf("ntlmssp_set_domain returned %s\n", nt_errstr(status
));
1061 status
= ntlmssp_set_password(ntlmssp
, password
);
1062 if (!NT_STATUS_IS_OK(status
)) {
1063 printf("ntlmssp_set_password returned %s\n", nt_errstr(status
));
1067 status
= ntlmssp_update(ntlmssp
, data_blob_null
, &in_blob
);
1068 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1069 printf("ntlmssp_update returned %s\n", nt_errstr(status
));
1073 ev
= event_context_init(talloc_tos());
1075 printf("event_context_init() returned NULL\n");
1079 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1084 SMB2_CAP_DFS
, /* in_capabilities */
1086 NULL
, /* in_previous_session */
1087 &in_blob
); /* in_security_buffer */
1088 if (subreq
== NULL
) {
1089 printf("smb2cli_session_setup_send() returned NULL\n");
1093 ok
= tevent_req_poll(subreq
, ev
);
1095 printf("tevent_req_poll() returned false\n");
1099 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1101 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1102 printf("smb2cli_session_setup_recv returned %s\n",
1107 status
= ntlmssp_update(ntlmssp
, out_blob
, &in_blob
);
1108 if (!NT_STATUS_IS_OK(status
)) {
1109 printf("ntlmssp_update returned %s\n", nt_errstr(status
));
1113 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1118 SMB2_CAP_DFS
, /* in_capabilities */
1120 NULL
, /* in_previous_session */
1121 &in_blob
); /* in_security_buffer */
1122 if (subreq
== NULL
) {
1123 printf("smb2cli_session_setup_send() returned NULL\n");
1127 ok
= tevent_req_poll(subreq
, ev
);
1129 printf("tevent_req_poll() returned false\n");
1133 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1134 &recv_iov
, &out_blob
);
1135 if (!NT_STATUS_IS_OK(status
)) {
1136 printf("smb2cli_session_setup_recv returned %s\n",
1141 status
= smb2cli_session_update_session_key(cli
->smb2
.session
,
1142 ntlmssp
->session_key
,
1144 if (!NT_STATUS_IS_OK(status
)) {
1145 printf("smb2cli_session_update_session_key %s\n", nt_errstr(status
));
1149 status
= smb2cli_flush(cli
, fid_persistent
, fid_volatile
);
1150 if (!NT_STATUS_IS_OK(status
)) {
1151 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1155 status
= smb2cli_close(cli
, 0, fid_persistent
, fid_volatile
);
1156 if (!NT_STATUS_IS_OK(status
)) {
1157 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1161 status
= smb2cli_create(cli
, "multi-channel.txt",
1162 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1163 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1164 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1165 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1166 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1167 FILE_CREATE
, /* create_disposition, */
1168 FILE_DELETE_ON_CLOSE
, /* create_options, */
1169 NULL
, /* smb2_create_blobs *blobs */
1172 if (!NT_STATUS_IS_OK(status
)) {
1173 printf("smb2cli_create %s\n", nt_errstr(status
));
1177 status
= smb2cli_close(cli
, 0, fid_persistent
, fid_volatile
);
1178 if (!NT_STATUS_IS_OK(status
)) {
1179 printf("smb2cli_close returned %s\n", nt_errstr(status
));