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/gensec/gensec.h"
28 #include "auth_generic.h"
30 extern fstring host
, workgroup
, share
, password
, username
, myname
;
32 bool run_smb2_basic(int dummy
)
34 struct cli_state
*cli
;
36 uint64_t fid_persistent
, fid_volatile
;
37 const char *hello
= "Hello, world\n";
41 uint32_t dir_data_length
;
42 uint32_t saved_tid
= 0;
43 uint64_t saved_uid
= 0;
45 printf("Starting SMB2-BASIC\n");
47 if (!torture_init_connection(&cli
)) {
50 cli
->smb2
.pid
= 0xFEFF;
52 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
53 PROTOCOL_SMB2_02
, PROTOCOL_SMB2_02
);
54 if (!NT_STATUS_IS_OK(status
)) {
55 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
59 status
= cli_session_setup(cli
, username
,
60 password
, strlen(password
),
61 password
, strlen(password
),
63 if (!NT_STATUS_IS_OK(status
)) {
64 printf("cli_session_setup returned %s\n", nt_errstr(status
));
68 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
69 if (!NT_STATUS_IS_OK(status
)) {
70 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
74 status
= smb2cli_create(cli
, "smb2-basic.txt",
75 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
76 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
77 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
78 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
79 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
80 FILE_CREATE
, /* create_disposition, */
81 FILE_DELETE_ON_CLOSE
, /* create_options, */
82 NULL
, /* smb2_create_blobs *blobs */
85 if (!NT_STATUS_IS_OK(status
)) {
86 printf("smb2cli_create returned %s\n", nt_errstr(status
));
90 status
= smb2cli_write(cli
, strlen(hello
), 0, fid_persistent
,
91 fid_volatile
, 0, 0, (const uint8_t *)hello
);
92 if (!NT_STATUS_IS_OK(status
)) {
93 printf("smb2cli_write returned %s\n", nt_errstr(status
));
97 status
= smb2cli_flush(cli
, fid_persistent
, fid_volatile
);
98 if (!NT_STATUS_IS_OK(status
)) {
99 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
103 status
= smb2cli_read(cli
, 0x10000, 0, fid_persistent
,
105 talloc_tos(), &result
, &nread
);
106 if (!NT_STATUS_IS_OK(status
)) {
107 printf("smb2cli_read returned %s\n", nt_errstr(status
));
111 if (nread
!= strlen(hello
)) {
112 printf("smb2cli_read returned %d bytes, expected %d\n",
113 (int)nread
, (int)strlen(hello
));
117 if (memcmp(hello
, result
, nread
) != 0) {
118 printf("smb2cli_read returned '%s', expected '%s'\n",
123 status
= smb2cli_close(cli
, 0, fid_persistent
, fid_volatile
);
124 if (!NT_STATUS_IS_OK(status
)) {
125 printf("smb2cli_close returned %s\n", nt_errstr(status
));
129 status
= smb2cli_create(cli
, "",
130 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
131 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
134 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
135 0, /* file_attributes, */
136 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
137 FILE_OPEN
, /* create_disposition, */
138 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
139 NULL
, /* smb2_create_blobs *blobs */
142 if (!NT_STATUS_IS_OK(status
)) {
143 printf("smb2cli_create returned %s\n", nt_errstr(status
));
147 status
= smb2cli_query_directory(
148 cli
, 1, 0, 0, fid_persistent
, fid_volatile
, "*", 0xffff,
149 talloc_tos(), &dir_data
, &dir_data_length
);
151 if (!NT_STATUS_IS_OK(status
)) {
152 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
156 status
= smb2cli_close(cli
, 0, fid_persistent
, fid_volatile
);
157 if (!NT_STATUS_IS_OK(status
)) {
158 printf("smb2cli_close returned %s\n", nt_errstr(status
));
162 saved_tid
= cli
->smb2
.tid
;
163 status
= smb2cli_tdis(cli
);
164 if (!NT_STATUS_IS_OK(status
)) {
165 printf("smb2cli_tdis returned %s\n", nt_errstr(status
));
168 cli
->smb2
.tid
= saved_tid
;
170 status
= smb2cli_tdis(cli
);
171 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
172 printf("2nd smb2cli_tdis returned %s\n", nt_errstr(status
));
176 saved_uid
= smb2cli_session_current_id(cli
->smb2
.session
);
177 status
= smb2cli_logoff(cli
);
178 if (!NT_STATUS_IS_OK(status
)) {
179 printf("smb2cli_logoff returned %s\n", nt_errstr(status
));
183 cli
->smb2
.session
= smbXcli_session_create(cli
, cli
->conn
);
184 if (cli
->smb2
.session
== NULL
) {
185 printf("smbXcli_session_create() returned NULL\n");
189 smb2cli_session_set_id_and_flags(cli
->smb2
.session
, saved_uid
, 0);
191 status
= smb2cli_logoff(cli
);
192 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
193 printf("2nd smb2cli_logoff returned %s\n", nt_errstr(status
));
200 bool run_smb2_negprot(int dummy
)
202 struct cli_state
*cli
;
204 enum protocol_types protocol
;
205 const char *name
= NULL
;
207 printf("Starting SMB2-NEGPROT\n");
209 if (!torture_init_connection(&cli
)) {
212 cli
->smb2
.pid
= 0xFEFF;
214 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
215 PROTOCOL_CORE
, PROTOCOL_SMB2_24
);
216 if (!NT_STATUS_IS_OK(status
)) {
217 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
221 protocol
= smbXcli_conn_protocol(cli
->conn
);
224 case PROTOCOL_SMB2_02
:
227 case PROTOCOL_SMB2_10
:
230 case PROTOCOL_SMB2_22
:
233 case PROTOCOL_SMB2_24
:
241 printf("Server supports %s\n", name
);
243 printf("Server DOES NOT support SMB2\n");
247 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
249 if (!NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_RESET
) &&
250 !NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_DISCONNECTED
) &&
251 !NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_ABORTED
)) {
252 printf("2nd smbXcli_negprot should disconnect - returned %s\n",
257 if (smbXcli_conn_is_connected(cli
->conn
)) {
258 printf("2nd smbXcli_negprot should disconnect "
259 "- still connected\n");
266 bool run_smb2_session_reconnect(int dummy
)
268 struct cli_state
*cli1
;
269 struct cli_state
*cli2
;
272 uint64_t fid_persistent
, fid_volatile
;
273 struct tevent_context
*ev
;
274 struct tevent_req
*subreq
;
275 DATA_BLOB in_blob
= data_blob_null
;
277 DATA_BLOB session_key
;
278 struct auth_generic_state
*auth_generic_state
;
279 struct iovec
*recv_iov
;
280 const char *hello
= "Hello, world\n";
284 printf("Starting SMB2-SESSION-RECONNECT\n");
286 if (!torture_init_connection(&cli1
)) {
289 cli1
->smb2
.pid
= 0xFEFF;
291 status
= smbXcli_negprot(cli1
->conn
, cli1
->timeout
,
292 PROTOCOL_SMB2_02
, PROTOCOL_SMB2_24
);
293 if (!NT_STATUS_IS_OK(status
)) {
294 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
298 status
= cli_session_setup(cli1
, username
,
299 password
, strlen(password
),
300 password
, strlen(password
),
302 if (!NT_STATUS_IS_OK(status
)) {
303 printf("cli_session_setup returned %s\n", nt_errstr(status
));
307 status
= cli_tree_connect(cli1
, share
, "?????", "", 0);
308 if (!NT_STATUS_IS_OK(status
)) {
309 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
313 status
= smb2cli_create(cli1
, "session-reconnect.txt",
314 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
315 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
316 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
317 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
318 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
319 FILE_CREATE
, /* create_disposition, */
320 FILE_DELETE_ON_CLOSE
, /* create_options, */
321 NULL
, /* smb2_create_blobs *blobs */
324 if (!NT_STATUS_IS_OK(status
)) {
325 printf("smb2cli_create on cli1 %s\n", nt_errstr(status
));
329 status
= smb2cli_write(cli1
, strlen(hello
), 0, fid_persistent
,
330 fid_volatile
, 0, 0, (const uint8_t *)hello
);
331 if (!NT_STATUS_IS_OK(status
)) {
332 printf("smb2cli_write returned %s\n", nt_errstr(status
));
336 status
= smb2cli_flush(cli1
, fid_persistent
, fid_volatile
);
337 if (!NT_STATUS_IS_OK(status
)) {
338 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
342 status
= smb2cli_read(cli1
, 0x10000, 0, fid_persistent
,
344 talloc_tos(), &result
, &nread
);
345 if (!NT_STATUS_IS_OK(status
)) {
346 printf("smb2cli_read returned %s\n", nt_errstr(status
));
350 if (nread
!= strlen(hello
)) {
351 printf("smb2cli_read returned %d bytes, expected %d\n",
352 (int)nread
, (int)strlen(hello
));
356 if (memcmp(hello
, result
, nread
) != 0) {
357 printf("smb2cli_read returned '%s', expected '%s'\n",
362 /* prepare second session */
364 if (!torture_init_connection(&cli2
)) {
367 cli2
->smb2
.pid
= 0xFEFF;
369 status
= smbXcli_negprot(cli2
->conn
, cli2
->timeout
,
370 PROTOCOL_SMB2_02
, PROTOCOL_SMB2_24
);
371 if (!NT_STATUS_IS_OK(status
)) {
372 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
376 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
377 if (!NT_STATUS_IS_OK(status
)) {
378 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
382 gensec_want_feature(auth_generic_state
->gensec_security
,
383 GENSEC_FEATURE_SESSION_KEY
);
384 status
= auth_generic_set_username(auth_generic_state
, username
);
385 if (!NT_STATUS_IS_OK(status
)) {
386 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
390 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
391 if (!NT_STATUS_IS_OK(status
)) {
392 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
396 status
= auth_generic_set_password(auth_generic_state
, password
);
397 if (!NT_STATUS_IS_OK(status
)) {
398 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
402 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
403 if (!NT_STATUS_IS_OK(status
)) {
404 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
408 ev
= event_context_init(talloc_tos());
410 printf("event_context_init() returned NULL\n");
414 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, data_blob_null
, &in_blob
);
415 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
416 printf("gensec_update returned %s\n", nt_errstr(status
));
420 cli2
->smb2
.session
= smbXcli_session_create(cli2
, cli2
->conn
);
422 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
427 SMB2_CAP_DFS
, /* in_capabilities */
429 cli1
->smb2
.session
, /* in_previous_session */
430 &in_blob
); /* in_security_buffer */
431 if (subreq
== NULL
) {
432 printf("smb2cli_session_setup_send() returned NULL\n");
436 ok
= tevent_req_poll(subreq
, ev
);
438 printf("tevent_req_poll() returned false\n");
442 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
444 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
445 printf("smb2cli_session_setup_recv returned %s\n",
450 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, out_blob
, &in_blob
);
451 if (!NT_STATUS_IS_OK(status
)) {
452 printf("auth_generic_update returned %s\n", nt_errstr(status
));
456 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
461 SMB2_CAP_DFS
, /* in_capabilities */
463 cli1
->smb2
.session
, /* in_previous_session */
464 &in_blob
); /* in_security_buffer */
465 if (subreq
== NULL
) {
466 printf("smb2cli_session_setup_send() returned NULL\n");
470 ok
= tevent_req_poll(subreq
, ev
);
472 printf("tevent_req_poll() returned false\n");
476 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
477 &recv_iov
, &out_blob
);
478 if (!NT_STATUS_IS_OK(status
)) {
479 printf("smb2cli_session_setup_recv returned %s\n",
484 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
486 if (!NT_STATUS_IS_OK(status
)) {
487 printf("gensec_session_key returned %s\n",
492 status
= smb2_signing_check_pdu(session_key
, recv_iov
, 3);
493 if (!NT_STATUS_IS_OK(status
)) {
494 printf("check pdu returned %s\n", nt_errstr(status
));
498 /* check file operation on the old client */
500 status
= smb2cli_flush(cli1
, fid_persistent
, fid_volatile
);
501 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
502 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
506 status
= cli_tree_connect(cli1
, share
, "?????", "", 0);
507 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
508 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
513 * checking file operations without signing.
514 * on w2k8r2 at least, flush, read and write also work the same way,
515 * while create gives ACCESS_DENIED without signing
517 status
= smb2cli_flush(cli2
, fid_persistent
, fid_volatile
);
518 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
519 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
523 status
= smb2cli_write(cli2
, strlen(hello
), 0, fid_persistent
,
524 fid_volatile
, 0, 0, (const uint8_t *)hello
);
525 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
526 printf("smb2cli_write returned %s\n", nt_errstr(status
));
530 status
= smb2cli_read(cli2
, 0x10000, 0, fid_persistent
,
532 talloc_tos(), &result
, &nread
);
533 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
534 printf("smb2cli_read returned %s\n", nt_errstr(status
));
538 status
= smb2cli_create(cli2
, "session-reconnect.txt",
539 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
540 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
541 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
542 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
543 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
544 FILE_CREATE
, /* create_disposition, */
545 FILE_DELETE_ON_CLOSE
, /* create_options, */
546 NULL
, /* smb2_create_blobs *blobs */
549 if (!NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
) &&
550 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
551 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
555 /* now grab the session key and try with signing */
557 status
= smb2cli_session_update_session_key(cli2
->smb2
.session
,
560 if (!NT_STATUS_IS_OK(status
)) {
561 printf("smb2cli_session_update_session_key %s\n", nt_errstr(status
));
565 /* the tid seems to be irrelevant at this stage */
567 cli2
->smb2
.tid
= cli1
->smb2
.tid
;
569 status
= smb2cli_flush(cli2
, fid_persistent
, fid_volatile
);
570 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
571 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
575 status
= smb2cli_write(cli2
, strlen(hello
), 0, fid_persistent
,
576 fid_volatile
, 0, 0, (const uint8_t *)hello
);
577 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
578 printf("smb2cli_write returned %s\n", nt_errstr(status
));
582 status
= smb2cli_read(cli2
, 0x10000, 0, fid_persistent
,
584 talloc_tos(), &result
, &nread
);
585 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
586 printf("smb2cli_read returned %s\n", nt_errstr(status
));
590 status
= smb2cli_create(cli2
, "session-reconnect.txt",
591 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
592 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
593 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
594 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
595 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
596 FILE_CREATE
, /* create_disposition, */
597 FILE_DELETE_ON_CLOSE
, /* create_options, */
598 NULL
, /* smb2_create_blobs *blobs */
601 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
602 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
606 /* now do a new tcon and test file calls again */
608 status
= cli_tree_connect(cli2
, share
, "?????", "", 0);
609 if (!NT_STATUS_IS_OK(status
)) {
610 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
614 status
= smb2cli_create(cli2
, "session-reconnect.txt",
615 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
616 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
617 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
618 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
619 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
620 FILE_CREATE
, /* create_disposition, */
621 FILE_DELETE_ON_CLOSE
, /* create_options, */
622 NULL
, /* smb2_create_blobs *blobs */
625 if (!NT_STATUS_IS_OK(status
)) {
626 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
630 status
= smb2cli_write(cli2
, strlen(hello
), 0, fid_persistent
,
631 fid_volatile
, 0, 0, (const uint8_t *)hello
);
632 if (!NT_STATUS_IS_OK(status
)) {
633 printf("smb2cli_write returned %s\n", nt_errstr(status
));
637 status
= smb2cli_flush(cli2
, fid_persistent
, fid_volatile
);
638 if (!NT_STATUS_IS_OK(status
)) {
639 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
643 status
= smb2cli_read(cli2
, 0x10000, 0, fid_persistent
,
645 talloc_tos(), &result
, &nread
);
646 if (!NT_STATUS_IS_OK(status
)) {
647 printf("smb2cli_read returned %s\n", nt_errstr(status
));
651 if (nread
!= strlen(hello
)) {
652 printf("smb2cli_read returned %d bytes, expected %d\n",
653 (int)nread
, (int)strlen(hello
));
657 if (memcmp(hello
, result
, nread
) != 0) {
658 printf("smb2cli_read returned '%s', expected '%s'\n",
666 bool run_smb2_tcon_dependence(int dummy
)
668 struct cli_state
*cli
;
670 uint64_t fid_persistent
, fid_volatile
;
671 const char *hello
= "Hello, world\n";
675 printf("Starting SMB2-TCON-DEPENDENCE\n");
677 if (!torture_init_connection(&cli
)) {
680 cli
->smb2
.pid
= 0xFEFF;
682 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
683 PROTOCOL_SMB2_02
, PROTOCOL_SMB2_24
);
684 if (!NT_STATUS_IS_OK(status
)) {
685 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
689 status
= cli_session_setup(cli
, username
,
690 password
, strlen(password
),
691 password
, strlen(password
),
693 if (!NT_STATUS_IS_OK(status
)) {
694 printf("cli_session_setup returned %s\n", nt_errstr(status
));
698 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
699 if (!NT_STATUS_IS_OK(status
)) {
700 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
704 status
= smb2cli_create(cli
, "tcon_depedence.txt",
705 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
706 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
707 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
708 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
709 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
710 FILE_CREATE
, /* create_disposition, */
711 FILE_DELETE_ON_CLOSE
, /* create_options, */
712 NULL
, /* smb2_create_blobs *blobs */
715 if (!NT_STATUS_IS_OK(status
)) {
716 printf("smb2cli_create on cli %s\n", nt_errstr(status
));
720 status
= smb2cli_write(cli
, strlen(hello
), 0, fid_persistent
,
721 fid_volatile
, 0, 0, (const uint8_t *)hello
);
722 if (!NT_STATUS_IS_OK(status
)) {
723 printf("smb2cli_write returned %s\n", nt_errstr(status
));
727 status
= smb2cli_flush(cli
, fid_persistent
, fid_volatile
);
728 if (!NT_STATUS_IS_OK(status
)) {
729 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
733 status
= smb2cli_read(cli
, 0x10000, 0, fid_persistent
,
735 talloc_tos(), &result
, &nread
);
736 if (!NT_STATUS_IS_OK(status
)) {
737 printf("smb2cli_read returned %s\n", nt_errstr(status
));
741 if (nread
!= strlen(hello
)) {
742 printf("smb2cli_read returned %d bytes, expected %d\n",
743 (int)nread
, (int)strlen(hello
));
747 if (memcmp(hello
, result
, nread
) != 0) {
748 printf("smb2cli_read returned '%s', expected '%s'\n",
753 /* check behaviour with wrong tid... */
757 status
= smb2cli_read(cli
, 0x10000, 0, fid_persistent
,
759 talloc_tos(), &result
, &nread
);
760 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
761 printf("smb2cli_read returned %s\n", nt_errstr(status
));
770 bool run_smb2_multi_channel(int dummy
)
772 struct cli_state
*cli1
;
773 struct cli_state
*cli2
;
776 uint64_t fid_persistent
, fid_volatile
;
777 struct tevent_context
*ev
;
778 struct tevent_req
*subreq
;
779 DATA_BLOB in_blob
= data_blob_null
;
781 DATA_BLOB session_key
;
782 struct auth_generic_state
*auth_generic_state
;
783 struct iovec
*recv_iov
;
784 const char *hello
= "Hello, world\n";
788 printf("Starting SMB2-MULTI-CHANNEL\n");
790 if (!torture_init_connection(&cli1
)) {
793 cli1
->smb2
.pid
= 0xFEFF;
795 if (!torture_init_connection(&cli2
)) {
798 cli2
->smb2
.pid
= 0xFEFF;
800 status
= smbXcli_negprot(cli1
->conn
, cli1
->timeout
,
801 PROTOCOL_SMB2_22
, PROTOCOL_SMB2_24
);
802 if (!NT_STATUS_IS_OK(status
)) {
803 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
807 status
= smbXcli_negprot(cli2
->conn
, cli2
->timeout
,
808 PROTOCOL_SMB2_22
, PROTOCOL_SMB2_24
);
809 if (!NT_STATUS_IS_OK(status
)) {
810 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
814 status
= cli_session_setup(cli1
, username
,
815 password
, strlen(password
),
816 password
, strlen(password
),
818 if (!NT_STATUS_IS_OK(status
)) {
819 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status
));
823 status
= cli_tree_connect(cli1
, share
, "?????", "", 0);
824 if (!NT_STATUS_IS_OK(status
)) {
825 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
829 status
= smb2cli_session_create_channel(cli2
,
832 &cli2
->smb2
.session
);
833 if (!NT_STATUS_IS_OK(status
)) {
834 printf("smb2cli_session_create_channel returned %s\n",
839 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
840 if (!NT_STATUS_IS_OK(status
)) {
841 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
845 gensec_want_feature(auth_generic_state
->gensec_security
,
846 GENSEC_FEATURE_SESSION_KEY
);
847 status
= auth_generic_set_username(auth_generic_state
, username
);
848 if (!NT_STATUS_IS_OK(status
)) {
849 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
853 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
854 if (!NT_STATUS_IS_OK(status
)) {
855 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
859 status
= auth_generic_set_password(auth_generic_state
, password
);
860 if (!NT_STATUS_IS_OK(status
)) {
861 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
865 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
866 if (!NT_STATUS_IS_OK(status
)) {
867 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
871 ev
= event_context_init(talloc_tos());
873 printf("event_context_init() returned NULL\n");
877 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, data_blob_null
, &in_blob
);
878 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
879 printf("gensec_update returned %s\n", nt_errstr(status
));
883 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
888 SMB2_CAP_DFS
, /* in_capabilities */
890 NULL
, /* in_previous_session */
891 &in_blob
); /* in_security_buffer */
892 if (subreq
== NULL
) {
893 printf("smb2cli_session_setup_send() returned NULL\n");
897 ok
= tevent_req_poll(subreq
, ev
);
899 printf("tevent_req_poll() returned false\n");
903 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
905 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
906 printf("smb2cli_session_setup_recv returned %s\n",
911 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, out_blob
, &in_blob
);
912 if (!NT_STATUS_IS_OK(status
)) {
913 printf("auth_generic_update returned %s\n", nt_errstr(status
));
917 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
922 SMB2_CAP_DFS
, /* in_capabilities */
924 NULL
, /* in_previous_session */
925 &in_blob
); /* in_security_buffer */
926 if (subreq
== NULL
) {
927 printf("smb2cli_session_setup_send() returned NULL\n");
931 ok
= tevent_req_poll(subreq
, ev
);
933 printf("tevent_req_poll() returned false\n");
937 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
938 &recv_iov
, &out_blob
);
939 if (!NT_STATUS_IS_OK(status
)) {
940 printf("smb2cli_session_setup_recv returned %s\n",
945 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
947 if (!NT_STATUS_IS_OK(status
)) {
948 printf("gensec_session_key returned %s\n",
953 status
= smb2cli_session_update_session_key(cli2
->smb2
.session
,
956 if (!NT_STATUS_IS_OK(status
)) {
957 printf("smb2cli_session_update_session_key %s\n", nt_errstr(status
));
961 cli2
->smb2
.tid
= cli1
->smb2
.tid
;
963 status
= smb2cli_create(cli2
, "multi-channel.txt",
964 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
965 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
966 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
967 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
968 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
969 FILE_CREATE
, /* create_disposition, */
970 FILE_DELETE_ON_CLOSE
, /* create_options, */
971 NULL
, /* smb2_create_blobs *blobs */
974 if (!NT_STATUS_IS_OK(status
)) {
975 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
979 status
= smb2cli_write(cli1
, strlen(hello
), 0, fid_persistent
,
980 fid_volatile
, 0, 0, (const uint8_t *)hello
);
981 if (!NT_STATUS_IS_OK(status
)) {
982 printf("smb2cli_write returned %s\n", nt_errstr(status
));
986 status
= smb2cli_flush(cli2
, fid_persistent
, fid_volatile
);
987 if (!NT_STATUS_IS_OK(status
)) {
988 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
992 status
= smb2cli_flush(cli1
, fid_persistent
, fid_volatile
);
993 if (!NT_STATUS_IS_OK(status
)) {
994 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
998 status
= smb2cli_read(cli2
, 0x10000, 0, fid_persistent
,
1000 talloc_tos(), &result
, &nread
);
1001 if (!NT_STATUS_IS_OK(status
)) {
1002 printf("smb2cli_read returned %s\n", nt_errstr(status
));
1006 if (nread
!= strlen(hello
)) {
1007 printf("smb2cli_read returned %d bytes, expected %d\n",
1008 (int)nread
, (int)strlen(hello
));
1012 if (memcmp(hello
, result
, nread
) != 0) {
1013 printf("smb2cli_read returned '%s', expected '%s'\n",
1018 status
= smb2cli_close(cli1
, 0, fid_persistent
, fid_volatile
);
1019 if (!NT_STATUS_IS_OK(status
)) {
1020 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1024 status
= smb2cli_flush(cli2
, fid_persistent
, fid_volatile
);
1025 if (!NT_STATUS_IS_OK(status
)) {
1026 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1029 status
= smb2cli_flush(cli1
, fid_persistent
, fid_volatile
);
1030 if (!NT_STATUS_IS_OK(status
)) {
1031 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1037 bool run_smb2_session_reauth(int dummy
)
1039 struct cli_state
*cli
;
1042 uint64_t fid_persistent
, fid_volatile
;
1043 struct tevent_context
*ev
;
1044 struct tevent_req
*subreq
;
1045 DATA_BLOB in_blob
= data_blob_null
;
1047 DATA_BLOB session_key
;
1048 struct auth_generic_state
*auth_generic_state
;
1049 struct iovec
*recv_iov
;
1051 printf("Starting SMB2-SESSION_REAUTH\n");
1053 if (!torture_init_connection(&cli
)) {
1056 cli
->smb2
.pid
= 0xFEFF;
1059 * PROTOCOL_SMB2_22 has a bug in win8pre0
1060 * it behaves like PROTOCOL_SMB2_02
1061 * and returns NT_STATUS_REQUEST_NOT_ACCEPTED,
1062 * while it allows it on PROTOCOL_SMB2_02.
1064 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
1065 PROTOCOL_SMB2_10
, PROTOCOL_SMB2_10
);
1066 if (!NT_STATUS_IS_OK(status
)) {
1067 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
1071 status
= cli_session_setup(cli
, username
,
1072 password
, strlen(password
),
1073 password
, strlen(password
),
1075 if (!NT_STATUS_IS_OK(status
)) {
1076 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status
));
1080 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
1081 if (!NT_STATUS_IS_OK(status
)) {
1082 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1086 status
= smb2cli_create(cli
, "session-reauth.txt",
1087 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1088 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1089 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1090 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1091 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1092 FILE_CREATE
, /* create_disposition, */
1093 FILE_DELETE_ON_CLOSE
, /* create_options, */
1094 NULL
, /* smb2_create_blobs *blobs */
1097 if (!NT_STATUS_IS_OK(status
)) {
1098 printf("smb2cli_create %s\n", nt_errstr(status
));
1102 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1103 if (!NT_STATUS_IS_OK(status
)) {
1104 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1108 gensec_want_feature(auth_generic_state
->gensec_security
,
1109 GENSEC_FEATURE_SESSION_KEY
);
1110 status
= auth_generic_set_username(auth_generic_state
, username
);
1111 if (!NT_STATUS_IS_OK(status
)) {
1112 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
1116 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
1117 if (!NT_STATUS_IS_OK(status
)) {
1118 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
1122 status
= auth_generic_set_password(auth_generic_state
, password
);
1123 if (!NT_STATUS_IS_OK(status
)) {
1124 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
1128 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1129 if (!NT_STATUS_IS_OK(status
)) {
1130 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1134 ev
= event_context_init(talloc_tos());
1136 printf("event_context_init() returned NULL\n");
1140 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, data_blob_null
, &in_blob
);
1141 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1142 printf("gensec_update returned %s\n", nt_errstr(status
));
1146 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1151 SMB2_CAP_DFS
, /* in_capabilities */
1153 NULL
, /* in_previous_session */
1154 &in_blob
); /* in_security_buffer */
1155 if (subreq
== NULL
) {
1156 printf("smb2cli_session_setup_send() returned NULL\n");
1160 ok
= tevent_req_poll(subreq
, ev
);
1162 printf("tevent_req_poll() returned false\n");
1166 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1168 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1169 printf("smb2cli_session_setup_recv returned %s\n",
1174 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, out_blob
, &in_blob
);
1175 if (!NT_STATUS_IS_OK(status
)) {
1176 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1180 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1185 SMB2_CAP_DFS
, /* in_capabilities */
1187 NULL
, /* in_previous_session */
1188 &in_blob
); /* in_security_buffer */
1189 if (subreq
== NULL
) {
1190 printf("smb2cli_session_setup_send() returned NULL\n");
1194 ok
= tevent_req_poll(subreq
, ev
);
1196 printf("tevent_req_poll() returned false\n");
1200 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1201 &recv_iov
, &out_blob
);
1202 if (!NT_STATUS_IS_OK(status
)) {
1203 printf("smb2cli_session_setup_recv returned %s\n",
1208 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
1210 if (!NT_STATUS_IS_OK(status
)) {
1211 printf("gensec_session_key returned %s\n",
1216 status
= smb2cli_session_update_session_key(cli
->smb2
.session
,
1219 if (!NT_STATUS_IS_OK(status
)) {
1220 printf("smb2cli_session_update_session_key %s\n", nt_errstr(status
));
1224 status
= smb2cli_flush(cli
, fid_persistent
, fid_volatile
);
1225 if (!NT_STATUS_IS_OK(status
)) {
1226 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1230 status
= smb2cli_close(cli
, 0, fid_persistent
, fid_volatile
);
1231 if (!NT_STATUS_IS_OK(status
)) {
1232 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1236 status
= smb2cli_create(cli
, "multi-channel.txt",
1237 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1238 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1239 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1240 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1241 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1242 FILE_CREATE
, /* create_disposition, */
1243 FILE_DELETE_ON_CLOSE
, /* create_options, */
1244 NULL
, /* smb2_create_blobs *blobs */
1247 if (!NT_STATUS_IS_OK(status
)) {
1248 printf("smb2cli_create %s\n", nt_errstr(status
));
1252 status
= smb2cli_close(cli
, 0, fid_persistent
, fid_volatile
);
1253 if (!NT_STATUS_IS_OK(status
)) {
1254 printf("smb2cli_close returned %s\n", nt_errstr(status
));