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"
24 #include "../libcli/smb/smbXcli_base.h"
25 #include "libcli/security/security.h"
26 #include "libsmb/proto.h"
27 #include "auth/gensec/gensec.h"
28 #include "auth_generic.h"
29 #include "../librpc/ndr/libndr.h"
31 extern fstring host
, workgroup
, share
, password
, username
, myname
;
33 bool run_smb2_basic(int dummy
)
35 struct cli_state
*cli
;
37 uint64_t fid_persistent
, fid_volatile
;
38 const char *hello
= "Hello, world\n";
42 uint32_t dir_data_length
;
43 uint32_t saved_tid
= 0;
44 struct smbXcli_tcon
*saved_tcon
= NULL
;
45 uint64_t saved_uid
= 0;
47 printf("Starting SMB2-BASIC\n");
49 if (!torture_init_connection(&cli
)) {
53 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
54 PROTOCOL_SMB2_02
, PROTOCOL_SMB2_02
);
55 if (!NT_STATUS_IS_OK(status
)) {
56 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
60 status
= cli_session_setup(cli
, username
,
61 password
, strlen(password
),
62 password
, strlen(password
),
64 if (!NT_STATUS_IS_OK(status
)) {
65 printf("cli_session_setup returned %s\n", nt_errstr(status
));
69 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
70 if (!NT_STATUS_IS_OK(status
)) {
71 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
75 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
76 cli
->smb2
.tcon
, "smb2-basic.txt",
77 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
78 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
79 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
80 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
81 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
82 FILE_CREATE
, /* create_disposition, */
83 FILE_DELETE_ON_CLOSE
, /* create_options, */
84 NULL
, /* smb2_create_blobs *blobs */
88 if (!NT_STATUS_IS_OK(status
)) {
89 printf("smb2cli_create returned %s\n", nt_errstr(status
));
93 status
= smb2cli_write(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
94 cli
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
95 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
96 if (!NT_STATUS_IS_OK(status
)) {
97 printf("smb2cli_write returned %s\n", nt_errstr(status
));
101 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
102 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
103 if (!NT_STATUS_IS_OK(status
)) {
104 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
108 status
= smb2cli_read(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
109 cli
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
111 talloc_tos(), &result
, &nread
);
112 if (!NT_STATUS_IS_OK(status
)) {
113 printf("smb2cli_read returned %s\n", nt_errstr(status
));
117 if (nread
!= strlen(hello
)) {
118 printf("smb2cli_read returned %d bytes, expected %d\n",
119 (int)nread
, (int)strlen(hello
));
123 if (memcmp(hello
, result
, nread
) != 0) {
124 printf("smb2cli_read returned '%s', expected '%s'\n",
129 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
130 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
131 if (!NT_STATUS_IS_OK(status
)) {
132 printf("smb2cli_close returned %s\n", nt_errstr(status
));
136 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
138 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
139 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
142 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
143 0, /* file_attributes, */
144 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
145 FILE_OPEN
, /* create_disposition, */
146 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
147 NULL
, /* smb2_create_blobs *blobs */
151 if (!NT_STATUS_IS_OK(status
)) {
152 printf("smb2cli_create returned %s\n", nt_errstr(status
));
156 status
= smb2cli_query_directory(
157 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
158 1, 0, 0, fid_persistent
, fid_volatile
, "*", 0xffff,
159 talloc_tos(), &dir_data
, &dir_data_length
);
161 if (!NT_STATUS_IS_OK(status
)) {
162 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
166 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
167 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
168 if (!NT_STATUS_IS_OK(status
)) {
169 printf("smb2cli_close returned %s\n", nt_errstr(status
));
173 saved_tid
= smb2cli_tcon_current_id(cli
->smb2
.tcon
);
174 saved_tcon
= cli
->smb2
.tcon
;
175 cli
->smb2
.tcon
= smbXcli_tcon_create(cli
);
176 smb2cli_tcon_set_values(cli
->smb2
.tcon
,
181 0, /* capabilities */
182 0 /* maximal_access */);
183 status
= smb2cli_tdis(cli
->conn
,
187 if (!NT_STATUS_IS_OK(status
)) {
188 printf("smb2cli_tdis returned %s\n", nt_errstr(status
));
191 talloc_free(cli
->smb2
.tcon
);
192 cli
->smb2
.tcon
= saved_tcon
;
194 status
= smb2cli_tdis(cli
->conn
,
198 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
199 printf("2nd smb2cli_tdis returned %s\n", nt_errstr(status
));
203 saved_uid
= smb2cli_session_current_id(cli
->smb2
.session
);
204 status
= smb2cli_logoff(cli
->conn
, cli
->timeout
, cli
->smb2
.session
);
205 if (!NT_STATUS_IS_OK(status
)) {
206 printf("smb2cli_logoff returned %s\n", nt_errstr(status
));
210 cli
->smb2
.session
= smbXcli_session_create(cli
, cli
->conn
);
211 if (cli
->smb2
.session
== NULL
) {
212 printf("smbXcli_session_create() returned NULL\n");
216 smb2cli_session_set_id_and_flags(cli
->smb2
.session
, saved_uid
, 0);
218 status
= smb2cli_logoff(cli
->conn
, cli
->timeout
, cli
->smb2
.session
);
219 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
220 printf("2nd smb2cli_logoff returned %s\n", nt_errstr(status
));
227 bool run_smb2_negprot(int dummy
)
229 struct cli_state
*cli
;
231 enum protocol_types protocol
;
232 const char *name
= NULL
;
234 printf("Starting SMB2-NEGPROT\n");
236 if (!torture_init_connection(&cli
)) {
240 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
241 PROTOCOL_CORE
, PROTOCOL_LATEST
);
242 if (!NT_STATUS_IS_OK(status
)) {
243 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
247 protocol
= smbXcli_conn_protocol(cli
->conn
);
250 case PROTOCOL_SMB2_02
:
253 case PROTOCOL_SMB2_10
:
256 case PROTOCOL_SMB2_22
:
259 case PROTOCOL_SMB2_24
:
262 case PROTOCOL_SMB3_00
:
265 case PROTOCOL_SMB3_02
:
273 printf("Server supports %s\n", name
);
275 printf("Server DOES NOT support SMB2\n");
279 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
281 if (!NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_RESET
) &&
282 !NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_DISCONNECTED
) &&
283 !NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_ABORTED
)) {
284 printf("2nd smbXcli_negprot should disconnect - returned %s\n",
289 if (smbXcli_conn_is_connected(cli
->conn
)) {
290 printf("2nd smbXcli_negprot should disconnect "
291 "- still connected\n");
298 bool run_smb2_session_reconnect(int dummy
)
300 struct cli_state
*cli1
;
301 struct cli_state
*cli2
;
304 uint64_t fid_persistent
, fid_volatile
;
305 struct tevent_context
*ev
;
306 struct tevent_req
*subreq
;
307 DATA_BLOB in_blob
= data_blob_null
;
309 DATA_BLOB session_key
;
310 struct auth_generic_state
*auth_generic_state
;
311 struct iovec
*recv_iov
;
312 const char *hello
= "Hello, world\n";
316 printf("Starting SMB2-SESSION-RECONNECT\n");
318 if (!torture_init_connection(&cli1
)) {
322 status
= smbXcli_negprot(cli1
->conn
, cli1
->timeout
,
323 PROTOCOL_SMB2_02
, PROTOCOL_LATEST
);
324 if (!NT_STATUS_IS_OK(status
)) {
325 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
329 status
= cli_session_setup(cli1
, username
,
330 password
, strlen(password
),
331 password
, strlen(password
),
333 if (!NT_STATUS_IS_OK(status
)) {
334 printf("cli_session_setup returned %s\n", nt_errstr(status
));
338 status
= cli_tree_connect(cli1
, share
, "?????", "", 0);
339 if (!NT_STATUS_IS_OK(status
)) {
340 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
344 status
= smb2cli_create(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
345 cli1
->smb2
.tcon
, "session-reconnect.txt",
346 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
347 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
348 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
349 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
350 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
351 FILE_CREATE
, /* create_disposition, */
352 FILE_DELETE_ON_CLOSE
, /* create_options, */
353 NULL
, /* smb2_create_blobs *blobs */
357 if (!NT_STATUS_IS_OK(status
)) {
358 printf("smb2cli_create on cli1 %s\n", nt_errstr(status
));
362 status
= smb2cli_write(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
363 cli1
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
364 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
365 if (!NT_STATUS_IS_OK(status
)) {
366 printf("smb2cli_write returned %s\n", nt_errstr(status
));
370 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
371 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
372 if (!NT_STATUS_IS_OK(status
)) {
373 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
377 status
= smb2cli_read(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
378 cli1
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
380 talloc_tos(), &result
, &nread
);
381 if (!NT_STATUS_IS_OK(status
)) {
382 printf("smb2cli_read returned %s\n", nt_errstr(status
));
386 if (nread
!= strlen(hello
)) {
387 printf("smb2cli_read returned %d bytes, expected %d\n",
388 (int)nread
, (int)strlen(hello
));
392 if (memcmp(hello
, result
, nread
) != 0) {
393 printf("smb2cli_read returned '%s', expected '%s'\n",
398 /* prepare second session */
400 if (!torture_init_connection(&cli2
)) {
404 status
= smbXcli_negprot(cli2
->conn
, cli2
->timeout
,
405 PROTOCOL_SMB2_02
, PROTOCOL_LATEST
);
406 if (!NT_STATUS_IS_OK(status
)) {
407 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
411 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
412 if (!NT_STATUS_IS_OK(status
)) {
413 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
417 gensec_want_feature(auth_generic_state
->gensec_security
,
418 GENSEC_FEATURE_SESSION_KEY
);
419 status
= auth_generic_set_username(auth_generic_state
, username
);
420 if (!NT_STATUS_IS_OK(status
)) {
421 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
425 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
426 if (!NT_STATUS_IS_OK(status
)) {
427 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
431 status
= auth_generic_set_password(auth_generic_state
, password
);
432 if (!NT_STATUS_IS_OK(status
)) {
433 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
437 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
438 if (!NT_STATUS_IS_OK(status
)) {
439 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
443 ev
= samba_tevent_context_init(talloc_tos());
445 printf("samba_tevent_context_init() returned NULL\n");
449 status
= gensec_update(auth_generic_state
->gensec_security
,
450 talloc_tos(), data_blob_null
, &in_blob
);
451 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
452 printf("gensec_update returned %s\n", nt_errstr(status
));
456 cli2
->smb2
.session
= smbXcli_session_create(cli2
, cli2
->conn
);
458 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
463 SMB2_CAP_DFS
, /* in_capabilities */
465 /* in_previous_session_id: */
466 smb2cli_session_current_id(cli1
->smb2
.session
),
467 &in_blob
); /* in_security_buffer */
468 if (subreq
== NULL
) {
469 printf("smb2cli_session_setup_send() returned NULL\n");
473 ok
= tevent_req_poll(subreq
, ev
);
475 printf("tevent_req_poll() returned false\n");
479 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
481 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
482 printf("smb2cli_session_setup_recv returned %s\n",
487 status
= gensec_update(auth_generic_state
->gensec_security
,
488 talloc_tos(), out_blob
, &in_blob
);
489 if (!NT_STATUS_IS_OK(status
)) {
490 printf("auth_generic_update returned %s\n", nt_errstr(status
));
494 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
499 SMB2_CAP_DFS
, /* in_capabilities */
501 /* in_previous_session_id: */
502 smb2cli_session_current_id(cli1
->smb2
.session
),
503 &in_blob
); /* in_security_buffer */
504 if (subreq
== NULL
) {
505 printf("smb2cli_session_setup_send() returned NULL\n");
509 ok
= tevent_req_poll(subreq
, ev
);
511 printf("tevent_req_poll() returned false\n");
515 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
516 &recv_iov
, &out_blob
);
517 if (!NT_STATUS_IS_OK(status
)) {
518 printf("smb2cli_session_setup_recv returned %s\n",
523 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
525 if (!NT_STATUS_IS_OK(status
)) {
526 printf("gensec_session_key returned %s\n",
531 /* check file operation on the old client */
533 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
534 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
535 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
536 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
540 status
= cli_tree_connect(cli1
, share
, "?????", "", 0);
541 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
542 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
547 * checking file operations without signing.
548 * on w2k8r2 at least, flush, read and write also work the same way,
549 * while create gives ACCESS_DENIED without signing
551 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
552 cli2
->smb2
.tcon
, fid_persistent
, fid_volatile
);
553 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
554 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
556 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
560 status
= smb2cli_write(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
561 cli2
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
562 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
563 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
564 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
566 printf("smb2cli_write returned %s\n", nt_errstr(status
));
570 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
571 cli2
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
573 talloc_tos(), &result
, &nread
);
574 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
575 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
577 printf("smb2cli_read returned %s\n", nt_errstr(status
));
581 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
582 cli2
->smb2
.tcon
, "session-reconnect.txt",
583 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
584 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
585 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
586 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
587 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
588 FILE_CREATE
, /* create_disposition, */
589 FILE_DELETE_ON_CLOSE
, /* create_options, */
590 NULL
, /* smb2_create_blobs *blobs */
594 if (!NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
) &&
595 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
596 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
600 /* now grab the session key and try with signing */
602 status
= smb2cli_session_set_session_key(cli2
->smb2
.session
,
605 if (!NT_STATUS_IS_OK(status
)) {
606 printf("smb2cli_session_set_session_key %s\n", nt_errstr(status
));
610 /* the tid seems to be irrelevant at this stage */
612 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
613 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
614 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
615 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
617 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
621 status
= smb2cli_write(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
622 cli1
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
623 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
624 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
625 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
627 printf("smb2cli_write returned %s\n", nt_errstr(status
));
631 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
632 cli1
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
634 talloc_tos(), &result
, &nread
);
635 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
636 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
638 printf("smb2cli_read returned %s\n", nt_errstr(status
));
642 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
643 cli1
->smb2
.tcon
, "session-reconnect.txt",
644 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
645 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
646 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
647 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
648 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
649 FILE_CREATE
, /* create_disposition, */
650 FILE_DELETE_ON_CLOSE
, /* create_options, */
651 NULL
, /* smb2_create_blobs *blobs */
655 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
) &&
656 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
658 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
662 /* now do a new tcon and test file calls again */
664 status
= cli_tree_connect(cli2
, share
, "?????", "", 0);
665 if (!NT_STATUS_IS_OK(status
)) {
666 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
670 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
671 cli2
->smb2
.tcon
, "session-reconnect.txt",
672 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
673 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
674 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
675 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
676 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
677 FILE_CREATE
, /* create_disposition, */
678 FILE_DELETE_ON_CLOSE
, /* create_options, */
679 NULL
, /* smb2_create_blobs *blobs */
683 if (!NT_STATUS_IS_OK(status
)) {
684 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
688 status
= smb2cli_write(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
689 cli2
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
690 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
691 if (!NT_STATUS_IS_OK(status
)) {
692 printf("smb2cli_write returned %s\n", nt_errstr(status
));
696 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
697 cli2
->smb2
.tcon
, fid_persistent
, fid_volatile
);
698 if (!NT_STATUS_IS_OK(status
)) {
699 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
703 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
704 cli2
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
706 talloc_tos(), &result
, &nread
);
707 if (!NT_STATUS_IS_OK(status
)) {
708 printf("smb2cli_read returned %s\n", nt_errstr(status
));
712 if (nread
!= strlen(hello
)) {
713 printf("smb2cli_read returned %d bytes, expected %d\n",
714 (int)nread
, (int)strlen(hello
));
718 if (memcmp(hello
, result
, nread
) != 0) {
719 printf("smb2cli_read returned '%s', expected '%s'\n",
727 bool run_smb2_tcon_dependence(int dummy
)
729 struct cli_state
*cli
;
731 uint64_t fid_persistent
, fid_volatile
;
732 const char *hello
= "Hello, world\n";
735 struct smbXcli_tcon
*tcon2
;
738 printf("Starting SMB2-TCON-DEPENDENCE\n");
740 if (!torture_init_connection(&cli
)) {
744 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
745 PROTOCOL_SMB2_02
, PROTOCOL_LATEST
);
746 if (!NT_STATUS_IS_OK(status
)) {
747 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
751 status
= cli_session_setup(cli
, username
,
752 password
, strlen(password
),
753 password
, strlen(password
),
755 if (!NT_STATUS_IS_OK(status
)) {
756 printf("cli_session_setup returned %s\n", nt_errstr(status
));
760 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
761 if (!NT_STATUS_IS_OK(status
)) {
762 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
766 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
767 cli
->smb2
.tcon
, "tcon_depedence.txt",
768 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
769 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
770 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
771 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
772 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
773 FILE_CREATE
, /* create_disposition, */
774 FILE_DELETE_ON_CLOSE
, /* create_options, */
775 NULL
, /* smb2_create_blobs *blobs */
779 if (!NT_STATUS_IS_OK(status
)) {
780 printf("smb2cli_create on cli %s\n", nt_errstr(status
));
784 status
= smb2cli_write(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
785 cli
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
786 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
787 if (!NT_STATUS_IS_OK(status
)) {
788 printf("smb2cli_write returned %s\n", nt_errstr(status
));
792 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
793 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
794 if (!NT_STATUS_IS_OK(status
)) {
795 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
799 status
= smb2cli_read(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
800 cli
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
802 talloc_tos(), &result
, &nread
);
803 if (!NT_STATUS_IS_OK(status
)) {
804 printf("smb2cli_read returned %s\n", nt_errstr(status
));
808 if (nread
!= strlen(hello
)) {
809 printf("smb2cli_read returned %d bytes, expected %d\n",
810 (int)nread
, (int)strlen(hello
));
814 if (memcmp(hello
, result
, nread
) != 0) {
815 printf("smb2cli_read returned '%s', expected '%s'\n",
820 /* check behaviour with wrong tid... */
822 tcon2
= smbXcli_tcon_create(cli
);
823 tcon2_id
= smb2cli_tcon_current_id(cli
->smb2
.tcon
);
825 smb2cli_tcon_set_values(tcon2
,
830 0, /* capabilities */
831 0 /* maximal_access */);
833 status
= smb2cli_read(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
834 tcon2
, 0x10000, 0, fid_persistent
,
836 talloc_tos(), &result
, &nread
);
837 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
838 printf("smb2cli_read returned %s\n", nt_errstr(status
));
847 bool run_smb2_multi_channel(int dummy
)
849 struct cli_state
*cli1
;
850 struct cli_state
*cli2
;
851 struct cli_state
*cli3
;
854 uint64_t fid_persistent
, fid_volatile
;
855 struct tevent_context
*ev
;
856 struct tevent_req
*subreq
;
857 DATA_BLOB in_blob
= data_blob_null
;
859 DATA_BLOB channel_session_key
;
860 struct auth_generic_state
*auth_generic_state
;
861 struct iovec
*recv_iov
;
862 const char *hello
= "Hello, world\n";
865 struct GUID saved_guid
= cli_state_client_guid
;
867 printf("Starting SMB2-MULTI-CHANNEL\n");
869 cli_state_client_guid
= GUID_random();
871 if (!torture_init_connection(&cli1
)) {
875 if (!torture_init_connection(&cli2
)) {
879 if (!torture_init_connection(&cli3
)) {
883 cli_state_client_guid
= saved_guid
;
885 status
= smbXcli_negprot(cli1
->conn
, cli1
->timeout
,
886 PROTOCOL_SMB2_22
, PROTOCOL_LATEST
);
887 if (!NT_STATUS_IS_OK(status
)) {
888 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
892 status
= smbXcli_negprot(cli2
->conn
, cli2
->timeout
,
893 PROTOCOL_SMB2_22
, PROTOCOL_LATEST
);
894 if (!NT_STATUS_IS_OK(status
)) {
895 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
899 status
= smbXcli_negprot(cli3
->conn
, cli3
->timeout
,
900 PROTOCOL_SMB2_22
, PROTOCOL_LATEST
);
901 if (!NT_STATUS_IS_OK(status
)) {
902 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
906 status
= cli_session_setup(cli1
, username
,
907 password
, strlen(password
),
908 password
, strlen(password
),
910 if (!NT_STATUS_IS_OK(status
)) {
911 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status
));
915 status
= cli_tree_connect(cli1
, share
, "?????", "", 0);
916 if (!NT_STATUS_IS_OK(status
)) {
917 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
921 status
= smb2cli_session_create_channel(cli2
,
924 &cli2
->smb2
.session
);
925 if (!NT_STATUS_IS_OK(status
)) {
926 printf("smb2cli_session_create_channel returned %s\n",
931 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
932 if (!NT_STATUS_IS_OK(status
)) {
933 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
937 gensec_want_feature(auth_generic_state
->gensec_security
,
938 GENSEC_FEATURE_SESSION_KEY
);
939 status
= auth_generic_set_username(auth_generic_state
, username
);
940 if (!NT_STATUS_IS_OK(status
)) {
941 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
945 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
946 if (!NT_STATUS_IS_OK(status
)) {
947 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
951 status
= auth_generic_set_password(auth_generic_state
, password
);
952 if (!NT_STATUS_IS_OK(status
)) {
953 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
957 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
958 if (!NT_STATUS_IS_OK(status
)) {
959 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
963 ev
= samba_tevent_context_init(talloc_tos());
965 printf("samba_tevent_context_init() returned NULL\n");
969 status
= gensec_update(auth_generic_state
->gensec_security
,
970 talloc_tos(), data_blob_null
, &in_blob
);
971 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
972 printf("gensec_update returned %s\n", nt_errstr(status
));
976 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
981 SMB2_CAP_DFS
, /* in_capabilities */
983 0, /* in_previous_session_id */
984 &in_blob
); /* in_security_buffer */
985 if (subreq
== NULL
) {
986 printf("smb2cli_session_setup_send() returned NULL\n");
990 ok
= tevent_req_poll(subreq
, ev
);
992 printf("tevent_req_poll() returned false\n");
996 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
998 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
999 printf("smb2cli_session_setup_recv returned %s\n",
1004 status
= gensec_update(auth_generic_state
->gensec_security
,
1005 talloc_tos(), out_blob
, &in_blob
);
1006 if (!NT_STATUS_IS_OK(status
)) {
1007 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1011 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1015 0x01, /* in_flags */
1016 SMB2_CAP_DFS
, /* in_capabilities */
1018 0, /* in_previous_session_id */
1019 &in_blob
); /* in_security_buffer */
1020 if (subreq
== NULL
) {
1021 printf("smb2cli_session_setup_send() returned NULL\n");
1025 ok
= tevent_req_poll(subreq
, ev
);
1027 printf("tevent_req_poll() returned false\n");
1031 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1032 &recv_iov
, &out_blob
);
1033 if (!NT_STATUS_IS_OK(status
)) {
1034 printf("smb2cli_session_setup_recv returned %s\n",
1039 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
1040 &channel_session_key
);
1041 if (!NT_STATUS_IS_OK(status
)) {
1042 printf("gensec_session_key returned %s\n",
1047 status
= smb2cli_session_set_channel_key(cli2
->smb2
.session
,
1048 channel_session_key
,
1050 if (!NT_STATUS_IS_OK(status
)) {
1051 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status
));
1055 status
= smb2cli_session_create_channel(cli3
,
1058 &cli3
->smb2
.session
);
1059 if (!NT_STATUS_IS_OK(status
)) {
1060 printf("smb2cli_session_create_channel returned %s\n",
1065 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1066 if (!NT_STATUS_IS_OK(status
)) {
1067 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1071 gensec_want_feature(auth_generic_state
->gensec_security
,
1072 GENSEC_FEATURE_SESSION_KEY
);
1073 status
= auth_generic_set_username(auth_generic_state
, username
);
1074 if (!NT_STATUS_IS_OK(status
)) {
1075 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
1079 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
1080 if (!NT_STATUS_IS_OK(status
)) {
1081 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
1085 status
= auth_generic_set_password(auth_generic_state
, password
);
1086 if (!NT_STATUS_IS_OK(status
)) {
1087 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
1091 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1092 if (!NT_STATUS_IS_OK(status
)) {
1093 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1097 status
= gensec_update(auth_generic_state
->gensec_security
,
1098 talloc_tos(), data_blob_null
, &in_blob
);
1099 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1100 printf("gensec_update returned %s\n", nt_errstr(status
));
1104 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1108 0x01, /* in_flags */
1109 SMB2_CAP_DFS
, /* in_capabilities */
1111 0, /* in_previous_session_id */
1112 &in_blob
); /* in_security_buffer */
1113 if (subreq
== NULL
) {
1114 printf("smb2cli_session_setup_send() returned NULL\n");
1118 ok
= tevent_req_poll(subreq
, ev
);
1120 printf("tevent_req_poll() returned false\n");
1124 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1126 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1127 printf("smb2cli_session_setup_recv returned %s\n",
1132 status
= gensec_update(auth_generic_state
->gensec_security
,
1133 talloc_tos(), out_blob
, &in_blob
);
1134 if (!NT_STATUS_IS_OK(status
)) {
1135 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1139 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1143 0x01, /* in_flags */
1144 SMB2_CAP_DFS
, /* in_capabilities */
1146 0, /* in_previous_session_id */
1147 &in_blob
); /* in_security_buffer */
1148 if (subreq
== NULL
) {
1149 printf("smb2cli_session_setup_send() returned NULL\n");
1153 ok
= tevent_req_poll(subreq
, ev
);
1155 printf("tevent_req_poll() returned false\n");
1159 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1160 &recv_iov
, &out_blob
);
1161 if (!NT_STATUS_IS_OK(status
)) {
1162 printf("smb2cli_session_setup_recv returned %s\n",
1167 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
1168 &channel_session_key
);
1169 if (!NT_STATUS_IS_OK(status
)) {
1170 printf("gensec_session_key returned %s\n",
1175 status
= smb2cli_session_set_channel_key(cli3
->smb2
.session
,
1176 channel_session_key
,
1178 if (!NT_STATUS_IS_OK(status
)) {
1179 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status
));
1183 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1184 cli1
->smb2
.tcon
, "multi-channel.txt",
1185 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1186 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1187 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1188 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1189 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1190 FILE_CREATE
, /* create_disposition, */
1191 FILE_DELETE_ON_CLOSE
, /* create_options, */
1192 NULL
, /* smb2_create_blobs *blobs */
1196 if (!NT_STATUS_IS_OK(status
)) {
1197 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
1201 status
= smb2cli_write(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1202 cli1
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
1203 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
1204 if (!NT_STATUS_IS_OK(status
)) {
1205 printf("smb2cli_write returned %s\n", nt_errstr(status
));
1209 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1210 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1211 if (!NT_STATUS_IS_OK(status
)) {
1212 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1216 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1217 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1218 if (!NT_STATUS_IS_OK(status
)) {
1219 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1223 status
= smb2cli_flush(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1224 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1225 if (!NT_STATUS_IS_OK(status
)) {
1226 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1230 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1231 cli1
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
1233 talloc_tos(), &result
, &nread
);
1234 if (!NT_STATUS_IS_OK(status
)) {
1235 printf("smb2cli_read returned %s\n", nt_errstr(status
));
1239 if (nread
!= strlen(hello
)) {
1240 printf("smb2cli_read returned %d bytes, expected %d\n",
1241 (int)nread
, (int)strlen(hello
));
1245 if (memcmp(hello
, result
, nread
) != 0) {
1246 printf("smb2cli_read returned '%s', expected '%s'\n",
1251 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1252 if (!NT_STATUS_IS_OK(status
)) {
1253 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1257 gensec_want_feature(auth_generic_state
->gensec_security
,
1258 GENSEC_FEATURE_SESSION_KEY
);
1259 status
= auth_generic_set_username(auth_generic_state
, username
);
1260 if (!NT_STATUS_IS_OK(status
)) {
1261 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
1265 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
1266 if (!NT_STATUS_IS_OK(status
)) {
1267 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
1271 status
= auth_generic_set_password(auth_generic_state
, password
);
1272 if (!NT_STATUS_IS_OK(status
)) {
1273 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
1277 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1278 if (!NT_STATUS_IS_OK(status
)) {
1279 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1283 status
= gensec_update(auth_generic_state
->gensec_security
,
1284 talloc_tos(), data_blob_null
, &in_blob
);
1285 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1286 printf("gensec_update returned %s\n", nt_errstr(status
));
1290 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1295 SMB2_CAP_DFS
, /* in_capabilities */
1297 0, /* in_previous_session_id */
1298 &in_blob
); /* in_security_buffer */
1299 if (subreq
== NULL
) {
1300 printf("smb2cli_session_setup_send() returned NULL\n");
1304 ok
= tevent_req_poll(subreq
, ev
);
1306 printf("tevent_req_poll() returned false\n");
1310 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1312 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1313 printf("smb2cli_session_setup_recv returned %s\n",
1318 status
= gensec_update(auth_generic_state
->gensec_security
,
1319 talloc_tos(), out_blob
, &in_blob
);
1320 if (!NT_STATUS_IS_OK(status
)) {
1321 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1325 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1326 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1327 if (!NT_STATUS_IS_OK(status
)) {
1328 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1332 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1333 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1334 if (!NT_STATUS_IS_OK(status
)) {
1335 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1339 status
= smb2cli_flush(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1340 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1341 if (!NT_STATUS_IS_OK(status
)) {
1342 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1346 status
= smb2cli_create(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1347 cli1
->smb2
.tcon
, "multi-channel-invalid.txt",
1348 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1349 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1350 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1351 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1352 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1353 FILE_CREATE
, /* create_disposition, */
1354 FILE_DELETE_ON_CLOSE
, /* create_options, */
1355 NULL
, /* smb2_create_blobs *blobs */
1359 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1360 printf("smb2cli_create %s\n", nt_errstr(status
));
1364 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1365 cli1
->smb2
.tcon
, "multi-channel-invalid.txt",
1366 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1367 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1368 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1369 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1370 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1371 FILE_CREATE
, /* create_disposition, */
1372 FILE_DELETE_ON_CLOSE
, /* create_options, */
1373 NULL
, /* smb2_create_blobs *blobs */
1377 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1378 printf("smb2cli_create %s\n", nt_errstr(status
));
1382 status
= smb2cli_create(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1383 cli1
->smb2
.tcon
, "multi-channel-invalid.txt",
1384 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1385 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1386 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1387 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1388 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1389 FILE_CREATE
, /* create_disposition, */
1390 FILE_DELETE_ON_CLOSE
, /* create_options, */
1391 NULL
, /* smb2_create_blobs *blobs */
1395 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1396 printf("smb2cli_create %s\n", nt_errstr(status
));
1400 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1405 SMB2_CAP_DFS
, /* in_capabilities */
1407 0, /* in_previous_session_id */
1408 &in_blob
); /* in_security_buffer */
1409 if (subreq
== NULL
) {
1410 printf("smb2cli_session_setup_send() returned NULL\n");
1414 ok
= tevent_req_poll(subreq
, ev
);
1416 printf("tevent_req_poll() returned false\n");
1420 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1421 &recv_iov
, &out_blob
);
1422 if (!NT_STATUS_IS_OK(status
)) {
1423 printf("smb2cli_session_setup_recv returned %s\n",
1428 status
= smb2cli_close(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1429 cli1
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
1430 if (!NT_STATUS_IS_OK(status
)) {
1431 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1435 status
= smb2cli_flush(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1436 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1437 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1438 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1442 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1443 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1444 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1445 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1449 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1450 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1451 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1452 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1459 bool run_smb2_session_reauth(int dummy
)
1461 struct cli_state
*cli
;
1464 uint64_t fid_persistent
, fid_volatile
;
1465 uint64_t dir_persistent
, dir_volatile
;
1467 uint32_t dir_data_length
;
1468 struct tevent_context
*ev
;
1469 struct tevent_req
*subreq
;
1470 DATA_BLOB in_blob
= data_blob_null
;
1472 DATA_BLOB in_input_buffer
;
1473 DATA_BLOB out_output_buffer
;
1474 uint8_t in_file_info_class
;
1475 struct auth_generic_state
*auth_generic_state
;
1476 struct iovec
*recv_iov
;
1478 struct smbXcli_tcon
*saved_tcon
;
1480 printf("Starting SMB2-SESSION_REAUTH\n");
1482 if (!torture_init_connection(&cli
)) {
1487 * PROTOCOL_SMB2_22 has a bug in win8pre0
1488 * it behaves like PROTOCOL_SMB2_02
1489 * and returns NT_STATUS_REQUEST_NOT_ACCEPTED,
1490 * while it allows it on PROTOCOL_SMB2_02.
1492 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
1493 PROTOCOL_SMB2_10
, PROTOCOL_SMB2_10
);
1494 if (!NT_STATUS_IS_OK(status
)) {
1495 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
1499 status
= cli_session_setup(cli
, username
,
1500 password
, strlen(password
),
1501 password
, strlen(password
),
1503 if (!NT_STATUS_IS_OK(status
)) {
1504 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status
));
1508 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
1509 if (!NT_STATUS_IS_OK(status
)) {
1510 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1514 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1515 cli
->smb2
.tcon
, "session-reauth.txt",
1516 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1517 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1518 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1519 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1520 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1521 FILE_CREATE
, /* create_disposition, */
1522 FILE_DELETE_ON_CLOSE
, /* create_options, */
1523 NULL
, /* smb2_create_blobs *blobs */
1527 if (!NT_STATUS_IS_OK(status
)) {
1528 printf("smb2cli_create %s\n", nt_errstr(status
));
1532 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1534 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1535 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1536 SEC_STD_SYNCHRONIZE
|
1538 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
1539 0, /* file_attributes, */
1540 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1541 FILE_OPEN
, /* create_disposition, */
1542 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
1543 NULL
, /* smb2_create_blobs *blobs */
1547 if (!NT_STATUS_IS_OK(status
)) {
1548 printf("smb2cli_create returned %s\n", nt_errstr(status
));
1552 status
= smb2cli_query_directory(
1553 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
1554 1, 0x3, 0, dir_persistent
, dir_volatile
,
1555 "session-reauth.txt", 0xffff,
1556 talloc_tos(), &dir_data
, &dir_data_length
);
1557 if (!NT_STATUS_IS_OK(status
)) {
1558 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1562 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1563 if (!NT_STATUS_IS_OK(status
)) {
1564 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1568 gensec_want_feature(auth_generic_state
->gensec_security
,
1569 GENSEC_FEATURE_SESSION_KEY
);
1570 status
= auth_generic_set_username(auth_generic_state
, username
);
1571 if (!NT_STATUS_IS_OK(status
)) {
1572 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
1576 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
1577 if (!NT_STATUS_IS_OK(status
)) {
1578 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
1582 status
= auth_generic_set_password(auth_generic_state
, password
);
1583 if (!NT_STATUS_IS_OK(status
)) {
1584 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
1588 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1589 if (!NT_STATUS_IS_OK(status
)) {
1590 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1594 ev
= samba_tevent_context_init(talloc_tos());
1596 printf("samba_tevent_context_init() returned NULL\n");
1600 status
= gensec_update(auth_generic_state
->gensec_security
,
1601 talloc_tos(), data_blob_null
, &in_blob
);
1602 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1603 printf("gensec_update returned %s\n", nt_errstr(status
));
1607 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1612 SMB2_CAP_DFS
, /* in_capabilities */
1614 0, /* in_previous_session_id */
1615 &in_blob
); /* in_security_buffer */
1616 if (subreq
== NULL
) {
1617 printf("smb2cli_session_setup_send() returned NULL\n");
1621 ok
= tevent_req_poll(subreq
, ev
);
1623 printf("tevent_req_poll() returned false\n");
1627 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1629 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1630 printf("smb2cli_session_setup_recv returned %s\n",
1635 status
= gensec_update(auth_generic_state
->gensec_security
,
1636 talloc_tos(), out_blob
, &in_blob
);
1637 if (!NT_STATUS_IS_OK(status
)) {
1638 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1642 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1643 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1644 if (!NT_STATUS_IS_OK(status
)) {
1645 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1649 status
= smb2cli_query_directory(
1650 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
1651 1, 0x3, 0, dir_persistent
, dir_volatile
,
1652 "session-reauth.txt", 0xffff,
1653 talloc_tos(), &dir_data
, &dir_data_length
);
1654 if (!NT_STATUS_IS_OK(status
)) {
1655 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1660 * query_info seems to be a path based operation on Windows...
1662 status
= smb2cli_query_info(cli
->conn
,
1666 SMB2_GETINFO_SECURITY
,
1667 0, /* in_file_info_class */
1668 1024, /* in_max_output_length */
1669 NULL
, /* in_input_buffer */
1670 SECINFO_OWNER
, /* in_additional_info */
1675 &out_output_buffer
);
1676 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1677 printf("smb2cli_query_info (security) returned %s\n", nt_errstr(status
));
1681 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1682 status
= smb2cli_query_info(cli
->conn
,
1688 1024, /* in_max_output_length */
1689 NULL
, /* in_input_buffer */
1690 0, /* in_additional_info */
1695 &out_output_buffer
);
1696 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1697 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1701 in_input_buffer
= data_blob_talloc(talloc_tos(), NULL
, 8);
1702 SBVAL(in_input_buffer
.data
, 0, 512);
1704 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1705 status
= smb2cli_set_info(cli
->conn
,
1712 0, /* in_additional_info */
1715 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1716 printf("smb2cli_set_info (position) returned %s\n", nt_errstr(status
));
1720 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1721 cli
->smb2
.tcon
, "session-reauth-invalid.txt",
1722 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1723 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1724 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1725 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1726 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1727 FILE_CREATE
, /* create_disposition, */
1728 FILE_DELETE_ON_CLOSE
, /* create_options, */
1729 NULL
, /* smb2_create_blobs *blobs */
1733 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1734 printf("smb2cli_create %s\n", nt_errstr(status
));
1738 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1740 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1741 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1742 SEC_STD_SYNCHRONIZE
|
1744 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
1745 0, /* file_attributes, */
1746 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1747 FILE_OPEN
, /* create_disposition, */
1748 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
1749 NULL
, /* smb2_create_blobs *blobs */
1753 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1754 printf("smb2cli_create returned %s\n", nt_errstr(status
));
1758 saved_tid
= smb2cli_tcon_current_id(cli
->smb2
.tcon
);
1759 saved_tcon
= cli
->smb2
.tcon
;
1760 cli
->smb2
.tcon
= smbXcli_tcon_create(cli
);
1761 smb2cli_tcon_set_values(cli
->smb2
.tcon
,
1766 0, /* capabilities */
1767 0 /* maximal_access */);
1768 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
1769 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1770 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1773 talloc_free(cli
->smb2
.tcon
);
1774 cli
->smb2
.tcon
= saved_tcon
;
1776 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1781 SMB2_CAP_DFS
, /* in_capabilities */
1783 0, /* in_previous_session_id */
1784 &in_blob
); /* in_security_buffer */
1785 if (subreq
== NULL
) {
1786 printf("smb2cli_session_setup_send() returned NULL\n");
1790 ok
= tevent_req_poll(subreq
, ev
);
1792 printf("tevent_req_poll() returned false\n");
1796 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1797 &recv_iov
, &out_blob
);
1798 if (!NT_STATUS_IS_OK(status
)) {
1799 printf("smb2cli_session_setup_recv returned %s\n",
1804 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1805 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1806 if (!NT_STATUS_IS_OK(status
)) {
1807 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1811 status
= smb2cli_query_info(cli
->conn
,
1815 SMB2_GETINFO_SECURITY
,
1816 0, /* in_file_info_class */
1817 1024, /* in_max_output_length */
1818 NULL
, /* in_input_buffer */
1819 SECINFO_OWNER
, /* in_additional_info */
1824 &out_output_buffer
);
1825 if (!NT_STATUS_IS_OK(status
)) {
1826 printf("smb2cli_query_info (security) returned %s\n", nt_errstr(status
));
1830 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1831 status
= smb2cli_query_info(cli
->conn
,
1837 1024, /* in_max_output_length */
1838 NULL
, /* in_input_buffer */
1839 0, /* in_additional_info */
1844 &out_output_buffer
);
1845 if (!NT_STATUS_IS_OK(status
)) {
1846 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1850 in_input_buffer
= data_blob_talloc(talloc_tos(), NULL
, 8);
1851 SBVAL(in_input_buffer
.data
, 0, 512);
1853 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1854 status
= smb2cli_set_info(cli
->conn
,
1861 0, /* in_additional_info */
1864 if (!NT_STATUS_IS_OK(status
)) {
1865 printf("smb2cli_set_info (position) returned %s\n", nt_errstr(status
));
1869 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1870 status
= smb2cli_query_info(cli
->conn
,
1876 1024, /* in_max_output_length */
1877 NULL
, /* in_input_buffer */
1878 0, /* in_additional_info */
1883 &out_output_buffer
);
1884 if (!NT_STATUS_IS_OK(status
)) {
1885 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1889 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1890 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
1891 if (!NT_STATUS_IS_OK(status
)) {
1892 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1896 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1897 cli
->smb2
.tcon
, "session-reauth.txt",
1898 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1899 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1900 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1901 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1902 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1903 FILE_CREATE
, /* create_disposition, */
1904 FILE_DELETE_ON_CLOSE
, /* create_options, */
1905 NULL
, /* smb2_create_blobs *blobs */
1909 if (!NT_STATUS_IS_OK(status
)) {
1910 printf("smb2cli_create %s\n", nt_errstr(status
));
1914 status
= smb2cli_query_directory(
1915 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
1916 1, 0x3, 0, dir_persistent
, dir_volatile
,
1917 "session-reauth.txt", 0xffff,
1918 talloc_tos(), &dir_data
, &dir_data_length
);
1919 if (!NT_STATUS_IS_OK(status
)) {
1920 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1924 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1925 cli
->smb2
.tcon
, 0, dir_persistent
, dir_volatile
);
1926 if (!NT_STATUS_IS_OK(status
)) {
1927 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1931 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1932 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
1933 if (!NT_STATUS_IS_OK(status
)) {
1934 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1938 saved_tid
= smb2cli_tcon_current_id(cli
->smb2
.tcon
);
1939 saved_tcon
= cli
->smb2
.tcon
;
1940 cli
->smb2
.tcon
= smbXcli_tcon_create(cli
);
1941 smb2cli_tcon_set_values(cli
->smb2
.tcon
,
1946 0, /* capabilities */
1947 0 /* maximal_access */);
1948 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
1949 if (!NT_STATUS_IS_OK(status
)) {
1950 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1953 talloc_free(cli
->smb2
.tcon
);
1954 cli
->smb2
.tcon
= saved_tcon
;