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
:
268 case PROTOCOL_SMB3_10
:
271 case PROTOCOL_SMB3_11
:
279 printf("Server supports %s\n", name
);
281 printf("Server DOES NOT support SMB2\n");
285 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
287 if (!NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_RESET
) &&
288 !NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_DISCONNECTED
) &&
289 !NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_ABORTED
)) {
290 printf("2nd smbXcli_negprot should disconnect - returned %s\n",
295 if (smbXcli_conn_is_connected(cli
->conn
)) {
296 printf("2nd smbXcli_negprot should disconnect "
297 "- still connected\n");
304 bool run_smb2_session_reconnect(int dummy
)
306 struct cli_state
*cli1
;
307 struct cli_state
*cli2
;
310 uint64_t fid_persistent
, fid_volatile
;
311 struct tevent_context
*ev
;
312 struct tevent_req
*subreq
;
313 DATA_BLOB in_blob
= data_blob_null
;
315 DATA_BLOB session_key
;
316 struct auth_generic_state
*auth_generic_state
;
317 struct iovec
*recv_iov
;
318 const char *hello
= "Hello, world\n";
322 printf("Starting SMB2-SESSION-RECONNECT\n");
324 if (!torture_init_connection(&cli1
)) {
328 status
= smbXcli_negprot(cli1
->conn
, cli1
->timeout
,
329 PROTOCOL_SMB2_02
, PROTOCOL_LATEST
);
330 if (!NT_STATUS_IS_OK(status
)) {
331 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
335 status
= cli_session_setup(cli1
, username
,
336 password
, strlen(password
),
337 password
, strlen(password
),
339 if (!NT_STATUS_IS_OK(status
)) {
340 printf("cli_session_setup returned %s\n", nt_errstr(status
));
344 status
= cli_tree_connect(cli1
, share
, "?????", "", 0);
345 if (!NT_STATUS_IS_OK(status
)) {
346 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
350 status
= smb2cli_create(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
351 cli1
->smb2
.tcon
, "session-reconnect.txt",
352 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
353 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
354 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
355 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
356 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
357 FILE_CREATE
, /* create_disposition, */
358 FILE_DELETE_ON_CLOSE
, /* create_options, */
359 NULL
, /* smb2_create_blobs *blobs */
363 if (!NT_STATUS_IS_OK(status
)) {
364 printf("smb2cli_create on cli1 %s\n", nt_errstr(status
));
368 status
= smb2cli_write(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
369 cli1
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
370 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
371 if (!NT_STATUS_IS_OK(status
)) {
372 printf("smb2cli_write returned %s\n", nt_errstr(status
));
376 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
377 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
378 if (!NT_STATUS_IS_OK(status
)) {
379 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
383 status
= smb2cli_read(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
384 cli1
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
386 talloc_tos(), &result
, &nread
);
387 if (!NT_STATUS_IS_OK(status
)) {
388 printf("smb2cli_read returned %s\n", nt_errstr(status
));
392 if (nread
!= strlen(hello
)) {
393 printf("smb2cli_read returned %d bytes, expected %d\n",
394 (int)nread
, (int)strlen(hello
));
398 if (memcmp(hello
, result
, nread
) != 0) {
399 printf("smb2cli_read returned '%s', expected '%s'\n",
404 /* prepare second session */
406 if (!torture_init_connection(&cli2
)) {
410 status
= smbXcli_negprot(cli2
->conn
, cli2
->timeout
,
411 PROTOCOL_SMB2_02
, PROTOCOL_LATEST
);
412 if (!NT_STATUS_IS_OK(status
)) {
413 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
417 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
418 if (!NT_STATUS_IS_OK(status
)) {
419 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
423 gensec_want_feature(auth_generic_state
->gensec_security
,
424 GENSEC_FEATURE_SESSION_KEY
);
425 status
= auth_generic_set_username(auth_generic_state
, username
);
426 if (!NT_STATUS_IS_OK(status
)) {
427 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
431 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
432 if (!NT_STATUS_IS_OK(status
)) {
433 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
437 status
= auth_generic_set_password(auth_generic_state
, password
);
438 if (!NT_STATUS_IS_OK(status
)) {
439 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
443 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
444 if (!NT_STATUS_IS_OK(status
)) {
445 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
449 ev
= samba_tevent_context_init(talloc_tos());
451 printf("samba_tevent_context_init() returned NULL\n");
455 status
= gensec_update(auth_generic_state
->gensec_security
,
456 talloc_tos(), data_blob_null
, &in_blob
);
457 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
458 printf("gensec_update returned %s\n", nt_errstr(status
));
462 cli2
->smb2
.session
= smbXcli_session_create(cli2
, cli2
->conn
);
464 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
469 SMB2_CAP_DFS
, /* in_capabilities */
471 /* in_previous_session_id: */
472 smb2cli_session_current_id(cli1
->smb2
.session
),
473 &in_blob
); /* in_security_buffer */
474 if (subreq
== NULL
) {
475 printf("smb2cli_session_setup_send() returned NULL\n");
479 ok
= tevent_req_poll(subreq
, ev
);
481 printf("tevent_req_poll() returned false\n");
485 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
487 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
488 printf("smb2cli_session_setup_recv returned %s\n",
493 status
= gensec_update(auth_generic_state
->gensec_security
,
494 talloc_tos(), out_blob
, &in_blob
);
495 if (!NT_STATUS_IS_OK(status
)) {
496 printf("auth_generic_update returned %s\n", nt_errstr(status
));
500 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
505 SMB2_CAP_DFS
, /* in_capabilities */
507 /* in_previous_session_id: */
508 smb2cli_session_current_id(cli1
->smb2
.session
),
509 &in_blob
); /* in_security_buffer */
510 if (subreq
== NULL
) {
511 printf("smb2cli_session_setup_send() returned NULL\n");
515 ok
= tevent_req_poll(subreq
, ev
);
517 printf("tevent_req_poll() returned false\n");
521 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
522 &recv_iov
, &out_blob
);
523 if (!NT_STATUS_IS_OK(status
)) {
524 printf("smb2cli_session_setup_recv returned %s\n",
529 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
531 if (!NT_STATUS_IS_OK(status
)) {
532 printf("gensec_session_key returned %s\n",
537 /* check file operation on the old client */
539 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
540 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
541 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
542 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
546 status
= cli_tree_connect(cli1
, share
, "?????", "", 0);
547 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
548 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
553 * checking file operations without signing.
554 * on w2k8r2 at least, flush, read and write also work the same way,
555 * while create gives ACCESS_DENIED without signing
557 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
558 cli2
->smb2
.tcon
, fid_persistent
, fid_volatile
);
559 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
560 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
562 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
566 status
= smb2cli_write(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
567 cli2
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
568 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
569 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
570 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
572 printf("smb2cli_write returned %s\n", nt_errstr(status
));
576 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
577 cli2
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
579 talloc_tos(), &result
, &nread
);
580 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
581 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
583 printf("smb2cli_read returned %s\n", nt_errstr(status
));
587 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
588 cli2
->smb2
.tcon
, "session-reconnect.txt",
589 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
590 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
591 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
592 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
593 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
594 FILE_CREATE
, /* create_disposition, */
595 FILE_DELETE_ON_CLOSE
, /* create_options, */
596 NULL
, /* smb2_create_blobs *blobs */
600 if (!NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
) &&
601 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
602 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
606 /* now grab the session key and try with signing */
608 status
= smb2cli_session_set_session_key(cli2
->smb2
.session
,
611 if (!NT_STATUS_IS_OK(status
)) {
612 printf("smb2cli_session_set_session_key %s\n", nt_errstr(status
));
616 /* the tid seems to be irrelevant at this stage */
618 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
619 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
620 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
621 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
623 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
627 status
= smb2cli_write(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
628 cli1
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
629 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
630 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
631 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
633 printf("smb2cli_write returned %s\n", nt_errstr(status
));
637 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
638 cli1
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
640 talloc_tos(), &result
, &nread
);
641 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
642 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
644 printf("smb2cli_read returned %s\n", nt_errstr(status
));
648 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
649 cli1
->smb2
.tcon
, "session-reconnect.txt",
650 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
651 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
652 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
653 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
654 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
655 FILE_CREATE
, /* create_disposition, */
656 FILE_DELETE_ON_CLOSE
, /* create_options, */
657 NULL
, /* smb2_create_blobs *blobs */
661 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
) &&
662 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
664 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
668 /* now do a new tcon and test file calls again */
670 status
= cli_tree_connect(cli2
, share
, "?????", "", 0);
671 if (!NT_STATUS_IS_OK(status
)) {
672 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
676 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
677 cli2
->smb2
.tcon
, "session-reconnect.txt",
678 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
679 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
680 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
681 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
682 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
683 FILE_CREATE
, /* create_disposition, */
684 FILE_DELETE_ON_CLOSE
, /* create_options, */
685 NULL
, /* smb2_create_blobs *blobs */
689 if (!NT_STATUS_IS_OK(status
)) {
690 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
694 status
= smb2cli_write(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
695 cli2
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
696 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
697 if (!NT_STATUS_IS_OK(status
)) {
698 printf("smb2cli_write returned %s\n", nt_errstr(status
));
702 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
703 cli2
->smb2
.tcon
, fid_persistent
, fid_volatile
);
704 if (!NT_STATUS_IS_OK(status
)) {
705 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
709 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
710 cli2
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
712 talloc_tos(), &result
, &nread
);
713 if (!NT_STATUS_IS_OK(status
)) {
714 printf("smb2cli_read returned %s\n", nt_errstr(status
));
718 if (nread
!= strlen(hello
)) {
719 printf("smb2cli_read returned %d bytes, expected %d\n",
720 (int)nread
, (int)strlen(hello
));
724 if (memcmp(hello
, result
, nread
) != 0) {
725 printf("smb2cli_read returned '%s', expected '%s'\n",
733 bool run_smb2_tcon_dependence(int dummy
)
735 struct cli_state
*cli
;
737 uint64_t fid_persistent
, fid_volatile
;
738 const char *hello
= "Hello, world\n";
741 struct smbXcli_tcon
*tcon2
;
744 printf("Starting SMB2-TCON-DEPENDENCE\n");
746 if (!torture_init_connection(&cli
)) {
750 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
751 PROTOCOL_SMB2_02
, PROTOCOL_LATEST
);
752 if (!NT_STATUS_IS_OK(status
)) {
753 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
757 status
= cli_session_setup(cli
, username
,
758 password
, strlen(password
),
759 password
, strlen(password
),
761 if (!NT_STATUS_IS_OK(status
)) {
762 printf("cli_session_setup returned %s\n", nt_errstr(status
));
766 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
767 if (!NT_STATUS_IS_OK(status
)) {
768 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
772 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
773 cli
->smb2
.tcon
, "tcon_depedence.txt",
774 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
775 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
776 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
777 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
778 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
779 FILE_CREATE
, /* create_disposition, */
780 FILE_DELETE_ON_CLOSE
, /* create_options, */
781 NULL
, /* smb2_create_blobs *blobs */
785 if (!NT_STATUS_IS_OK(status
)) {
786 printf("smb2cli_create on cli %s\n", nt_errstr(status
));
790 status
= smb2cli_write(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
791 cli
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
792 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
793 if (!NT_STATUS_IS_OK(status
)) {
794 printf("smb2cli_write returned %s\n", nt_errstr(status
));
798 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
799 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
800 if (!NT_STATUS_IS_OK(status
)) {
801 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
805 status
= smb2cli_read(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
806 cli
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
808 talloc_tos(), &result
, &nread
);
809 if (!NT_STATUS_IS_OK(status
)) {
810 printf("smb2cli_read returned %s\n", nt_errstr(status
));
814 if (nread
!= strlen(hello
)) {
815 printf("smb2cli_read returned %d bytes, expected %d\n",
816 (int)nread
, (int)strlen(hello
));
820 if (memcmp(hello
, result
, nread
) != 0) {
821 printf("smb2cli_read returned '%s', expected '%s'\n",
826 /* check behaviour with wrong tid... */
828 tcon2
= smbXcli_tcon_create(cli
);
829 tcon2_id
= smb2cli_tcon_current_id(cli
->smb2
.tcon
);
831 smb2cli_tcon_set_values(tcon2
,
836 0, /* capabilities */
837 0 /* maximal_access */);
839 status
= smb2cli_read(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
840 tcon2
, 0x10000, 0, fid_persistent
,
842 talloc_tos(), &result
, &nread
);
843 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
844 printf("smb2cli_read returned %s\n", nt_errstr(status
));
853 bool run_smb2_multi_channel(int dummy
)
855 struct cli_state
*cli1
;
856 struct cli_state
*cli2
;
857 struct cli_state
*cli3
;
860 uint64_t fid_persistent
, fid_volatile
;
861 struct tevent_context
*ev
;
862 struct tevent_req
*subreq
;
863 DATA_BLOB in_blob
= data_blob_null
;
865 DATA_BLOB channel_session_key
;
866 struct auth_generic_state
*auth_generic_state
;
867 struct iovec
*recv_iov
;
868 const char *hello
= "Hello, world\n";
871 struct GUID saved_guid
= cli_state_client_guid
;
873 printf("Starting SMB2-MULTI-CHANNEL\n");
875 cli_state_client_guid
= GUID_random();
877 if (!torture_init_connection(&cli1
)) {
881 if (!torture_init_connection(&cli2
)) {
885 if (!torture_init_connection(&cli3
)) {
889 cli_state_client_guid
= saved_guid
;
891 status
= smbXcli_negprot(cli1
->conn
, cli1
->timeout
,
892 PROTOCOL_SMB2_22
, PROTOCOL_LATEST
);
893 if (!NT_STATUS_IS_OK(status
)) {
894 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
898 status
= smbXcli_negprot(cli2
->conn
, cli2
->timeout
,
899 PROTOCOL_SMB2_22
, PROTOCOL_LATEST
);
900 if (!NT_STATUS_IS_OK(status
)) {
901 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
905 status
= smbXcli_negprot(cli3
->conn
, cli3
->timeout
,
906 PROTOCOL_SMB2_22
, PROTOCOL_LATEST
);
907 if (!NT_STATUS_IS_OK(status
)) {
908 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
912 status
= cli_session_setup(cli1
, username
,
913 password
, strlen(password
),
914 password
, strlen(password
),
916 if (!NT_STATUS_IS_OK(status
)) {
917 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status
));
921 status
= cli_tree_connect(cli1
, share
, "?????", "", 0);
922 if (!NT_STATUS_IS_OK(status
)) {
923 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
927 status
= smb2cli_session_create_channel(cli2
,
930 &cli2
->smb2
.session
);
931 if (!NT_STATUS_IS_OK(status
)) {
932 printf("smb2cli_session_create_channel returned %s\n",
937 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
938 if (!NT_STATUS_IS_OK(status
)) {
939 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
943 gensec_want_feature(auth_generic_state
->gensec_security
,
944 GENSEC_FEATURE_SESSION_KEY
);
945 status
= auth_generic_set_username(auth_generic_state
, username
);
946 if (!NT_STATUS_IS_OK(status
)) {
947 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
951 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
952 if (!NT_STATUS_IS_OK(status
)) {
953 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
957 status
= auth_generic_set_password(auth_generic_state
, password
);
958 if (!NT_STATUS_IS_OK(status
)) {
959 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
963 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
964 if (!NT_STATUS_IS_OK(status
)) {
965 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
969 ev
= samba_tevent_context_init(talloc_tos());
971 printf("samba_tevent_context_init() returned NULL\n");
975 status
= gensec_update(auth_generic_state
->gensec_security
,
976 talloc_tos(), data_blob_null
, &in_blob
);
977 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
978 printf("gensec_update returned %s\n", nt_errstr(status
));
982 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
987 SMB2_CAP_DFS
, /* in_capabilities */
989 0, /* in_previous_session_id */
990 &in_blob
); /* in_security_buffer */
991 if (subreq
== NULL
) {
992 printf("smb2cli_session_setup_send() returned NULL\n");
996 ok
= tevent_req_poll(subreq
, ev
);
998 printf("tevent_req_poll() returned false\n");
1002 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1004 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1005 printf("smb2cli_session_setup_recv returned %s\n",
1010 status
= gensec_update(auth_generic_state
->gensec_security
,
1011 talloc_tos(), out_blob
, &in_blob
);
1012 if (!NT_STATUS_IS_OK(status
)) {
1013 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1017 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1021 0x01, /* in_flags */
1022 SMB2_CAP_DFS
, /* in_capabilities */
1024 0, /* in_previous_session_id */
1025 &in_blob
); /* in_security_buffer */
1026 if (subreq
== NULL
) {
1027 printf("smb2cli_session_setup_send() returned NULL\n");
1031 ok
= tevent_req_poll(subreq
, ev
);
1033 printf("tevent_req_poll() returned false\n");
1037 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1038 &recv_iov
, &out_blob
);
1039 if (!NT_STATUS_IS_OK(status
)) {
1040 printf("smb2cli_session_setup_recv returned %s\n",
1045 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
1046 &channel_session_key
);
1047 if (!NT_STATUS_IS_OK(status
)) {
1048 printf("gensec_session_key returned %s\n",
1053 status
= smb2cli_session_set_channel_key(cli2
->smb2
.session
,
1054 channel_session_key
,
1056 if (!NT_STATUS_IS_OK(status
)) {
1057 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status
));
1061 status
= smb2cli_session_create_channel(cli3
,
1064 &cli3
->smb2
.session
);
1065 if (!NT_STATUS_IS_OK(status
)) {
1066 printf("smb2cli_session_create_channel returned %s\n",
1071 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1072 if (!NT_STATUS_IS_OK(status
)) {
1073 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1077 gensec_want_feature(auth_generic_state
->gensec_security
,
1078 GENSEC_FEATURE_SESSION_KEY
);
1079 status
= auth_generic_set_username(auth_generic_state
, username
);
1080 if (!NT_STATUS_IS_OK(status
)) {
1081 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
1085 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
1086 if (!NT_STATUS_IS_OK(status
)) {
1087 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
1091 status
= auth_generic_set_password(auth_generic_state
, password
);
1092 if (!NT_STATUS_IS_OK(status
)) {
1093 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
1097 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1098 if (!NT_STATUS_IS_OK(status
)) {
1099 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1103 status
= gensec_update(auth_generic_state
->gensec_security
,
1104 talloc_tos(), data_blob_null
, &in_blob
);
1105 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1106 printf("gensec_update returned %s\n", nt_errstr(status
));
1110 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1114 0x01, /* in_flags */
1115 SMB2_CAP_DFS
, /* in_capabilities */
1117 0, /* in_previous_session_id */
1118 &in_blob
); /* in_security_buffer */
1119 if (subreq
== NULL
) {
1120 printf("smb2cli_session_setup_send() returned NULL\n");
1124 ok
= tevent_req_poll(subreq
, ev
);
1126 printf("tevent_req_poll() returned false\n");
1130 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1132 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1133 printf("smb2cli_session_setup_recv returned %s\n",
1138 status
= gensec_update(auth_generic_state
->gensec_security
,
1139 talloc_tos(), out_blob
, &in_blob
);
1140 if (!NT_STATUS_IS_OK(status
)) {
1141 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1145 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1149 0x01, /* in_flags */
1150 SMB2_CAP_DFS
, /* in_capabilities */
1152 0, /* in_previous_session_id */
1153 &in_blob
); /* in_security_buffer */
1154 if (subreq
== NULL
) {
1155 printf("smb2cli_session_setup_send() returned NULL\n");
1159 ok
= tevent_req_poll(subreq
, ev
);
1161 printf("tevent_req_poll() returned false\n");
1165 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1166 &recv_iov
, &out_blob
);
1167 if (!NT_STATUS_IS_OK(status
)) {
1168 printf("smb2cli_session_setup_recv returned %s\n",
1173 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
1174 &channel_session_key
);
1175 if (!NT_STATUS_IS_OK(status
)) {
1176 printf("gensec_session_key returned %s\n",
1181 status
= smb2cli_session_set_channel_key(cli3
->smb2
.session
,
1182 channel_session_key
,
1184 if (!NT_STATUS_IS_OK(status
)) {
1185 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status
));
1189 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1190 cli1
->smb2
.tcon
, "multi-channel.txt",
1191 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1192 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1193 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1194 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1195 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1196 FILE_CREATE
, /* create_disposition, */
1197 FILE_DELETE_ON_CLOSE
, /* create_options, */
1198 NULL
, /* smb2_create_blobs *blobs */
1202 if (!NT_STATUS_IS_OK(status
)) {
1203 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
1207 status
= smb2cli_write(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1208 cli1
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
1209 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
1210 if (!NT_STATUS_IS_OK(status
)) {
1211 printf("smb2cli_write returned %s\n", nt_errstr(status
));
1215 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1216 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1217 if (!NT_STATUS_IS_OK(status
)) {
1218 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1222 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1223 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1224 if (!NT_STATUS_IS_OK(status
)) {
1225 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1229 status
= smb2cli_flush(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1230 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1231 if (!NT_STATUS_IS_OK(status
)) {
1232 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1236 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1237 cli1
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
1239 talloc_tos(), &result
, &nread
);
1240 if (!NT_STATUS_IS_OK(status
)) {
1241 printf("smb2cli_read returned %s\n", nt_errstr(status
));
1245 if (nread
!= strlen(hello
)) {
1246 printf("smb2cli_read returned %d bytes, expected %d\n",
1247 (int)nread
, (int)strlen(hello
));
1251 if (memcmp(hello
, result
, nread
) != 0) {
1252 printf("smb2cli_read returned '%s', expected '%s'\n",
1257 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1258 if (!NT_STATUS_IS_OK(status
)) {
1259 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1263 gensec_want_feature(auth_generic_state
->gensec_security
,
1264 GENSEC_FEATURE_SESSION_KEY
);
1265 status
= auth_generic_set_username(auth_generic_state
, username
);
1266 if (!NT_STATUS_IS_OK(status
)) {
1267 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
1271 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
1272 if (!NT_STATUS_IS_OK(status
)) {
1273 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
1277 status
= auth_generic_set_password(auth_generic_state
, password
);
1278 if (!NT_STATUS_IS_OK(status
)) {
1279 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
1283 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1284 if (!NT_STATUS_IS_OK(status
)) {
1285 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1289 status
= gensec_update(auth_generic_state
->gensec_security
,
1290 talloc_tos(), data_blob_null
, &in_blob
);
1291 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1292 printf("gensec_update returned %s\n", nt_errstr(status
));
1296 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1301 SMB2_CAP_DFS
, /* in_capabilities */
1303 0, /* in_previous_session_id */
1304 &in_blob
); /* in_security_buffer */
1305 if (subreq
== NULL
) {
1306 printf("smb2cli_session_setup_send() returned NULL\n");
1310 ok
= tevent_req_poll(subreq
, ev
);
1312 printf("tevent_req_poll() returned false\n");
1316 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1318 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1319 printf("smb2cli_session_setup_recv returned %s\n",
1324 status
= gensec_update(auth_generic_state
->gensec_security
,
1325 talloc_tos(), out_blob
, &in_blob
);
1326 if (!NT_STATUS_IS_OK(status
)) {
1327 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1331 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1332 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1333 if (!NT_STATUS_IS_OK(status
)) {
1334 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1338 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1339 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1340 if (!NT_STATUS_IS_OK(status
)) {
1341 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1345 status
= smb2cli_flush(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1346 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1347 if (!NT_STATUS_IS_OK(status
)) {
1348 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1352 status
= smb2cli_create(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1353 cli1
->smb2
.tcon
, "multi-channel-invalid.txt",
1354 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1355 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1356 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1357 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1358 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1359 FILE_CREATE
, /* create_disposition, */
1360 FILE_DELETE_ON_CLOSE
, /* create_options, */
1361 NULL
, /* smb2_create_blobs *blobs */
1365 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1366 printf("smb2cli_create %s\n", nt_errstr(status
));
1370 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1371 cli1
->smb2
.tcon
, "multi-channel-invalid.txt",
1372 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1373 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1374 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1375 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1376 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1377 FILE_CREATE
, /* create_disposition, */
1378 FILE_DELETE_ON_CLOSE
, /* create_options, */
1379 NULL
, /* smb2_create_blobs *blobs */
1383 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1384 printf("smb2cli_create %s\n", nt_errstr(status
));
1388 status
= smb2cli_create(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1389 cli1
->smb2
.tcon
, "multi-channel-invalid.txt",
1390 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1391 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1392 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1393 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1394 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1395 FILE_CREATE
, /* create_disposition, */
1396 FILE_DELETE_ON_CLOSE
, /* create_options, */
1397 NULL
, /* smb2_create_blobs *blobs */
1401 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1402 printf("smb2cli_create %s\n", nt_errstr(status
));
1406 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1411 SMB2_CAP_DFS
, /* in_capabilities */
1413 0, /* in_previous_session_id */
1414 &in_blob
); /* in_security_buffer */
1415 if (subreq
== NULL
) {
1416 printf("smb2cli_session_setup_send() returned NULL\n");
1420 ok
= tevent_req_poll(subreq
, ev
);
1422 printf("tevent_req_poll() returned false\n");
1426 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1427 &recv_iov
, &out_blob
);
1428 if (!NT_STATUS_IS_OK(status
)) {
1429 printf("smb2cli_session_setup_recv returned %s\n",
1434 status
= smb2cli_close(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1435 cli1
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
1436 if (!NT_STATUS_IS_OK(status
)) {
1437 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1441 status
= smb2cli_flush(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1442 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1443 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1444 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1448 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1449 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1450 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1451 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1455 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1456 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1457 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1458 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1465 bool run_smb2_session_reauth(int dummy
)
1467 struct cli_state
*cli
;
1470 uint64_t fid_persistent
, fid_volatile
;
1471 uint64_t dir_persistent
, dir_volatile
;
1473 uint32_t dir_data_length
;
1474 struct tevent_context
*ev
;
1475 struct tevent_req
*subreq
;
1476 DATA_BLOB in_blob
= data_blob_null
;
1478 DATA_BLOB in_input_buffer
;
1479 DATA_BLOB out_output_buffer
;
1480 uint8_t in_file_info_class
;
1481 struct auth_generic_state
*auth_generic_state
;
1482 struct iovec
*recv_iov
;
1484 struct smbXcli_tcon
*saved_tcon
;
1486 printf("Starting SMB2-SESSION_REAUTH\n");
1488 if (!torture_init_connection(&cli
)) {
1493 * PROTOCOL_SMB2_22 has a bug in win8pre0
1494 * it behaves like PROTOCOL_SMB2_02
1495 * and returns NT_STATUS_REQUEST_NOT_ACCEPTED,
1496 * while it allows it on PROTOCOL_SMB2_02.
1498 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
1499 PROTOCOL_SMB2_10
, PROTOCOL_SMB2_10
);
1500 if (!NT_STATUS_IS_OK(status
)) {
1501 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
1505 status
= cli_session_setup(cli
, username
,
1506 password
, strlen(password
),
1507 password
, strlen(password
),
1509 if (!NT_STATUS_IS_OK(status
)) {
1510 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status
));
1514 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
1515 if (!NT_STATUS_IS_OK(status
)) {
1516 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1520 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1521 cli
->smb2
.tcon
, "session-reauth.txt",
1522 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1523 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1524 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1525 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1526 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1527 FILE_CREATE
, /* create_disposition, */
1528 FILE_DELETE_ON_CLOSE
, /* create_options, */
1529 NULL
, /* smb2_create_blobs *blobs */
1533 if (!NT_STATUS_IS_OK(status
)) {
1534 printf("smb2cli_create %s\n", nt_errstr(status
));
1538 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1540 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1541 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1542 SEC_STD_SYNCHRONIZE
|
1544 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
1545 0, /* file_attributes, */
1546 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1547 FILE_OPEN
, /* create_disposition, */
1548 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
1549 NULL
, /* smb2_create_blobs *blobs */
1553 if (!NT_STATUS_IS_OK(status
)) {
1554 printf("smb2cli_create returned %s\n", nt_errstr(status
));
1558 status
= smb2cli_query_directory(
1559 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
1560 1, 0x3, 0, dir_persistent
, dir_volatile
,
1561 "session-reauth.txt", 0xffff,
1562 talloc_tos(), &dir_data
, &dir_data_length
);
1563 if (!NT_STATUS_IS_OK(status
)) {
1564 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1568 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1569 if (!NT_STATUS_IS_OK(status
)) {
1570 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1574 gensec_want_feature(auth_generic_state
->gensec_security
,
1575 GENSEC_FEATURE_SESSION_KEY
);
1576 status
= auth_generic_set_username(auth_generic_state
, username
);
1577 if (!NT_STATUS_IS_OK(status
)) {
1578 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
1582 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
1583 if (!NT_STATUS_IS_OK(status
)) {
1584 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
1588 status
= auth_generic_set_password(auth_generic_state
, password
);
1589 if (!NT_STATUS_IS_OK(status
)) {
1590 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
1594 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1595 if (!NT_STATUS_IS_OK(status
)) {
1596 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1600 ev
= samba_tevent_context_init(talloc_tos());
1602 printf("samba_tevent_context_init() returned NULL\n");
1606 status
= gensec_update(auth_generic_state
->gensec_security
,
1607 talloc_tos(), data_blob_null
, &in_blob
);
1608 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1609 printf("gensec_update returned %s\n", nt_errstr(status
));
1613 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1618 SMB2_CAP_DFS
, /* in_capabilities */
1620 0, /* in_previous_session_id */
1621 &in_blob
); /* in_security_buffer */
1622 if (subreq
== NULL
) {
1623 printf("smb2cli_session_setup_send() returned NULL\n");
1627 ok
= tevent_req_poll(subreq
, ev
);
1629 printf("tevent_req_poll() returned false\n");
1633 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1635 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1636 printf("smb2cli_session_setup_recv returned %s\n",
1641 status
= gensec_update(auth_generic_state
->gensec_security
,
1642 talloc_tos(), out_blob
, &in_blob
);
1643 if (!NT_STATUS_IS_OK(status
)) {
1644 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1648 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1649 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1650 if (!NT_STATUS_IS_OK(status
)) {
1651 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1655 status
= smb2cli_query_directory(
1656 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
1657 1, 0x3, 0, dir_persistent
, dir_volatile
,
1658 "session-reauth.txt", 0xffff,
1659 talloc_tos(), &dir_data
, &dir_data_length
);
1660 if (!NT_STATUS_IS_OK(status
)) {
1661 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1666 * query_info seems to be a path based operation on Windows...
1668 status
= smb2cli_query_info(cli
->conn
,
1672 SMB2_GETINFO_SECURITY
,
1673 0, /* in_file_info_class */
1674 1024, /* in_max_output_length */
1675 NULL
, /* in_input_buffer */
1676 SECINFO_OWNER
, /* in_additional_info */
1681 &out_output_buffer
);
1682 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1683 printf("smb2cli_query_info (security) returned %s\n", nt_errstr(status
));
1687 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1688 status
= smb2cli_query_info(cli
->conn
,
1694 1024, /* in_max_output_length */
1695 NULL
, /* in_input_buffer */
1696 0, /* in_additional_info */
1701 &out_output_buffer
);
1702 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1703 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1707 in_input_buffer
= data_blob_talloc(talloc_tos(), NULL
, 8);
1708 SBVAL(in_input_buffer
.data
, 0, 512);
1710 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1711 status
= smb2cli_set_info(cli
->conn
,
1718 0, /* in_additional_info */
1721 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1722 printf("smb2cli_set_info (position) returned %s\n", nt_errstr(status
));
1726 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1727 cli
->smb2
.tcon
, "session-reauth-invalid.txt",
1728 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1729 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1730 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1731 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1732 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1733 FILE_CREATE
, /* create_disposition, */
1734 FILE_DELETE_ON_CLOSE
, /* create_options, */
1735 NULL
, /* smb2_create_blobs *blobs */
1739 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1740 printf("smb2cli_create %s\n", nt_errstr(status
));
1744 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1746 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1747 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1748 SEC_STD_SYNCHRONIZE
|
1750 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
1751 0, /* file_attributes, */
1752 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1753 FILE_OPEN
, /* create_disposition, */
1754 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
1755 NULL
, /* smb2_create_blobs *blobs */
1759 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1760 printf("smb2cli_create returned %s\n", nt_errstr(status
));
1764 saved_tid
= smb2cli_tcon_current_id(cli
->smb2
.tcon
);
1765 saved_tcon
= cli
->smb2
.tcon
;
1766 cli
->smb2
.tcon
= smbXcli_tcon_create(cli
);
1767 smb2cli_tcon_set_values(cli
->smb2
.tcon
,
1772 0, /* capabilities */
1773 0 /* maximal_access */);
1774 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
1775 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1776 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1779 talloc_free(cli
->smb2
.tcon
);
1780 cli
->smb2
.tcon
= saved_tcon
;
1782 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1787 SMB2_CAP_DFS
, /* in_capabilities */
1789 0, /* in_previous_session_id */
1790 &in_blob
); /* in_security_buffer */
1791 if (subreq
== NULL
) {
1792 printf("smb2cli_session_setup_send() returned NULL\n");
1796 ok
= tevent_req_poll(subreq
, ev
);
1798 printf("tevent_req_poll() returned false\n");
1802 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1803 &recv_iov
, &out_blob
);
1804 if (!NT_STATUS_IS_OK(status
)) {
1805 printf("smb2cli_session_setup_recv returned %s\n",
1810 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1811 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1812 if (!NT_STATUS_IS_OK(status
)) {
1813 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1817 status
= smb2cli_query_info(cli
->conn
,
1821 SMB2_GETINFO_SECURITY
,
1822 0, /* in_file_info_class */
1823 1024, /* in_max_output_length */
1824 NULL
, /* in_input_buffer */
1825 SECINFO_OWNER
, /* in_additional_info */
1830 &out_output_buffer
);
1831 if (!NT_STATUS_IS_OK(status
)) {
1832 printf("smb2cli_query_info (security) returned %s\n", nt_errstr(status
));
1836 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1837 status
= smb2cli_query_info(cli
->conn
,
1843 1024, /* in_max_output_length */
1844 NULL
, /* in_input_buffer */
1845 0, /* in_additional_info */
1850 &out_output_buffer
);
1851 if (!NT_STATUS_IS_OK(status
)) {
1852 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1856 in_input_buffer
= data_blob_talloc(talloc_tos(), NULL
, 8);
1857 SBVAL(in_input_buffer
.data
, 0, 512);
1859 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1860 status
= smb2cli_set_info(cli
->conn
,
1867 0, /* in_additional_info */
1870 if (!NT_STATUS_IS_OK(status
)) {
1871 printf("smb2cli_set_info (position) returned %s\n", nt_errstr(status
));
1875 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1876 status
= smb2cli_query_info(cli
->conn
,
1882 1024, /* in_max_output_length */
1883 NULL
, /* in_input_buffer */
1884 0, /* in_additional_info */
1889 &out_output_buffer
);
1890 if (!NT_STATUS_IS_OK(status
)) {
1891 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1895 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1896 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
1897 if (!NT_STATUS_IS_OK(status
)) {
1898 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1902 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1903 cli
->smb2
.tcon
, "session-reauth.txt",
1904 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1905 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1906 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1907 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1908 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1909 FILE_CREATE
, /* create_disposition, */
1910 FILE_DELETE_ON_CLOSE
, /* create_options, */
1911 NULL
, /* smb2_create_blobs *blobs */
1915 if (!NT_STATUS_IS_OK(status
)) {
1916 printf("smb2cli_create %s\n", nt_errstr(status
));
1920 status
= smb2cli_query_directory(
1921 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
1922 1, 0x3, 0, dir_persistent
, dir_volatile
,
1923 "session-reauth.txt", 0xffff,
1924 talloc_tos(), &dir_data
, &dir_data_length
);
1925 if (!NT_STATUS_IS_OK(status
)) {
1926 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1930 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1931 cli
->smb2
.tcon
, 0, dir_persistent
, dir_volatile
);
1932 if (!NT_STATUS_IS_OK(status
)) {
1933 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1937 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1938 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
1939 if (!NT_STATUS_IS_OK(status
)) {
1940 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1944 saved_tid
= smb2cli_tcon_current_id(cli
->smb2
.tcon
);
1945 saved_tcon
= cli
->smb2
.tcon
;
1946 cli
->smb2
.tcon
= smbXcli_tcon_create(cli
);
1947 smb2cli_tcon_set_values(cli
->smb2
.tcon
,
1952 0, /* capabilities */
1953 0 /* maximal_access */);
1954 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
1955 if (!NT_STATUS_IS_OK(status
)) {
1956 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1959 talloc_free(cli
->smb2
.tcon
);
1960 cli
->smb2
.tcon
= saved_tcon
;