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 "libsmb/smb2cli.h"
26 #include "libcli/security/security.h"
27 #include "libsmb/proto.h"
28 #include "auth/gensec/gensec.h"
29 #include "auth_generic.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 uint64_t saved_uid
= 0;
46 printf("Starting SMB2-BASIC\n");
48 if (!torture_init_connection(&cli
)) {
51 cli
->smb2
.pid
= 0xFEFF;
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
, "smb2-basic.txt",
76 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
77 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
78 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
79 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
80 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
81 FILE_CREATE
, /* create_disposition, */
82 FILE_DELETE_ON_CLOSE
, /* create_options, */
83 NULL
, /* smb2_create_blobs *blobs */
86 if (!NT_STATUS_IS_OK(status
)) {
87 printf("smb2cli_create returned %s\n", nt_errstr(status
));
91 status
= smb2cli_write(cli
, strlen(hello
), 0, fid_persistent
,
92 fid_volatile
, 0, 0, (const uint8_t *)hello
);
93 if (!NT_STATUS_IS_OK(status
)) {
94 printf("smb2cli_write returned %s\n", nt_errstr(status
));
98 status
= smb2cli_flush(cli
, fid_persistent
, fid_volatile
);
99 if (!NT_STATUS_IS_OK(status
)) {
100 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
104 status
= smb2cli_read(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
105 cli
->smb2
.tid
, 0x10000, 0, fid_persistent
,
107 talloc_tos(), &result
, &nread
);
108 if (!NT_STATUS_IS_OK(status
)) {
109 printf("smb2cli_read returned %s\n", nt_errstr(status
));
113 if (nread
!= strlen(hello
)) {
114 printf("smb2cli_read returned %d bytes, expected %d\n",
115 (int)nread
, (int)strlen(hello
));
119 if (memcmp(hello
, result
, nread
) != 0) {
120 printf("smb2cli_read returned '%s', expected '%s'\n",
125 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
126 cli
->smb2
.tid
, 0, fid_persistent
, fid_volatile
);
127 if (!NT_STATUS_IS_OK(status
)) {
128 printf("smb2cli_close returned %s\n", nt_errstr(status
));
132 status
= smb2cli_create(cli
, "",
133 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
134 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
137 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
138 0, /* file_attributes, */
139 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
140 FILE_OPEN
, /* create_disposition, */
141 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
142 NULL
, /* smb2_create_blobs *blobs */
145 if (!NT_STATUS_IS_OK(status
)) {
146 printf("smb2cli_create returned %s\n", nt_errstr(status
));
150 status
= smb2cli_query_directory(
151 cli
, 1, 0, 0, fid_persistent
, fid_volatile
, "*", 0xffff,
152 talloc_tos(), &dir_data
, &dir_data_length
);
154 if (!NT_STATUS_IS_OK(status
)) {
155 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
159 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
160 cli
->smb2
.tid
, 0, fid_persistent
, fid_volatile
);
161 if (!NT_STATUS_IS_OK(status
)) {
162 printf("smb2cli_close returned %s\n", nt_errstr(status
));
166 saved_tid
= cli
->smb2
.tid
;
167 status
= smb2cli_tdis(cli
);
168 if (!NT_STATUS_IS_OK(status
)) {
169 printf("smb2cli_tdis returned %s\n", nt_errstr(status
));
172 cli
->smb2
.tid
= saved_tid
;
174 status
= smb2cli_tdis(cli
);
175 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
176 printf("2nd smb2cli_tdis returned %s\n", nt_errstr(status
));
180 saved_uid
= smb2cli_session_current_id(cli
->smb2
.session
);
181 status
= smb2cli_logoff(cli
);
182 if (!NT_STATUS_IS_OK(status
)) {
183 printf("smb2cli_logoff returned %s\n", nt_errstr(status
));
187 cli
->smb2
.session
= smbXcli_session_create(cli
, cli
->conn
);
188 if (cli
->smb2
.session
== NULL
) {
189 printf("smbXcli_session_create() returned NULL\n");
193 smb2cli_session_set_id_and_flags(cli
->smb2
.session
, saved_uid
, 0);
195 status
= smb2cli_logoff(cli
);
196 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
197 printf("2nd smb2cli_logoff returned %s\n", nt_errstr(status
));
204 bool run_smb2_negprot(int dummy
)
206 struct cli_state
*cli
;
208 enum protocol_types protocol
;
209 const char *name
= NULL
;
211 printf("Starting SMB2-NEGPROT\n");
213 if (!torture_init_connection(&cli
)) {
216 cli
->smb2
.pid
= 0xFEFF;
218 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
219 PROTOCOL_CORE
, PROTOCOL_LATEST
);
220 if (!NT_STATUS_IS_OK(status
)) {
221 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
225 protocol
= smbXcli_conn_protocol(cli
->conn
);
228 case PROTOCOL_SMB2_02
:
231 case PROTOCOL_SMB2_10
:
234 case PROTOCOL_SMB2_22
:
237 case PROTOCOL_SMB2_24
:
240 case PROTOCOL_SMB3_00
:
248 printf("Server supports %s\n", name
);
250 printf("Server DOES NOT support SMB2\n");
254 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
256 if (!NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_RESET
) &&
257 !NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_DISCONNECTED
) &&
258 !NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_ABORTED
)) {
259 printf("2nd smbXcli_negprot should disconnect - returned %s\n",
264 if (smbXcli_conn_is_connected(cli
->conn
)) {
265 printf("2nd smbXcli_negprot should disconnect "
266 "- still connected\n");
273 bool run_smb2_session_reconnect(int dummy
)
275 struct cli_state
*cli1
;
276 struct cli_state
*cli2
;
279 uint64_t fid_persistent
, fid_volatile
;
280 struct tevent_context
*ev
;
281 struct tevent_req
*subreq
;
282 DATA_BLOB in_blob
= data_blob_null
;
284 DATA_BLOB session_key
;
285 struct auth_generic_state
*auth_generic_state
;
286 struct iovec
*recv_iov
;
287 const char *hello
= "Hello, world\n";
291 printf("Starting SMB2-SESSION-RECONNECT\n");
293 if (!torture_init_connection(&cli1
)) {
296 cli1
->smb2
.pid
= 0xFEFF;
298 status
= smbXcli_negprot(cli1
->conn
, cli1
->timeout
,
299 PROTOCOL_SMB2_02
, PROTOCOL_LATEST
);
300 if (!NT_STATUS_IS_OK(status
)) {
301 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
305 status
= cli_session_setup(cli1
, username
,
306 password
, strlen(password
),
307 password
, strlen(password
),
309 if (!NT_STATUS_IS_OK(status
)) {
310 printf("cli_session_setup returned %s\n", nt_errstr(status
));
314 status
= cli_tree_connect(cli1
, share
, "?????", "", 0);
315 if (!NT_STATUS_IS_OK(status
)) {
316 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
320 status
= smb2cli_create(cli1
, "session-reconnect.txt",
321 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
322 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
323 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
324 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
325 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
326 FILE_CREATE
, /* create_disposition, */
327 FILE_DELETE_ON_CLOSE
, /* create_options, */
328 NULL
, /* smb2_create_blobs *blobs */
331 if (!NT_STATUS_IS_OK(status
)) {
332 printf("smb2cli_create on cli1 %s\n", nt_errstr(status
));
336 status
= smb2cli_write(cli1
, strlen(hello
), 0, fid_persistent
,
337 fid_volatile
, 0, 0, (const uint8_t *)hello
);
338 if (!NT_STATUS_IS_OK(status
)) {
339 printf("smb2cli_write returned %s\n", nt_errstr(status
));
343 status
= smb2cli_flush(cli1
, fid_persistent
, fid_volatile
);
344 if (!NT_STATUS_IS_OK(status
)) {
345 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
349 status
= smb2cli_read(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
350 cli1
->smb2
.tid
, 0x10000, 0, fid_persistent
,
352 talloc_tos(), &result
, &nread
);
353 if (!NT_STATUS_IS_OK(status
)) {
354 printf("smb2cli_read returned %s\n", nt_errstr(status
));
358 if (nread
!= strlen(hello
)) {
359 printf("smb2cli_read returned %d bytes, expected %d\n",
360 (int)nread
, (int)strlen(hello
));
364 if (memcmp(hello
, result
, nread
) != 0) {
365 printf("smb2cli_read returned '%s', expected '%s'\n",
370 /* prepare second session */
372 if (!torture_init_connection(&cli2
)) {
375 cli2
->smb2
.pid
= 0xFEFF;
377 status
= smbXcli_negprot(cli2
->conn
, cli2
->timeout
,
378 PROTOCOL_SMB2_02
, PROTOCOL_LATEST
);
379 if (!NT_STATUS_IS_OK(status
)) {
380 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
384 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
385 if (!NT_STATUS_IS_OK(status
)) {
386 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
390 gensec_want_feature(auth_generic_state
->gensec_security
,
391 GENSEC_FEATURE_SESSION_KEY
);
392 status
= auth_generic_set_username(auth_generic_state
, username
);
393 if (!NT_STATUS_IS_OK(status
)) {
394 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
398 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
399 if (!NT_STATUS_IS_OK(status
)) {
400 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
404 status
= auth_generic_set_password(auth_generic_state
, password
);
405 if (!NT_STATUS_IS_OK(status
)) {
406 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
410 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
411 if (!NT_STATUS_IS_OK(status
)) {
412 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
416 ev
= event_context_init(talloc_tos());
418 printf("event_context_init() returned NULL\n");
422 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, data_blob_null
, &in_blob
);
423 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
424 printf("gensec_update returned %s\n", nt_errstr(status
));
428 cli2
->smb2
.session
= smbXcli_session_create(cli2
, cli2
->conn
);
430 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
435 SMB2_CAP_DFS
, /* in_capabilities */
437 /* in_previous_session_id: */
438 smb2cli_session_current_id(cli1
->smb2
.session
),
439 &in_blob
); /* in_security_buffer */
440 if (subreq
== NULL
) {
441 printf("smb2cli_session_setup_send() returned NULL\n");
445 ok
= tevent_req_poll(subreq
, ev
);
447 printf("tevent_req_poll() returned false\n");
451 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
453 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
454 printf("smb2cli_session_setup_recv returned %s\n",
459 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, out_blob
, &in_blob
);
460 if (!NT_STATUS_IS_OK(status
)) {
461 printf("auth_generic_update returned %s\n", nt_errstr(status
));
465 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
470 SMB2_CAP_DFS
, /* in_capabilities */
472 /* in_previous_session_id: */
473 smb2cli_session_current_id(cli1
->smb2
.session
),
474 &in_blob
); /* in_security_buffer */
475 if (subreq
== NULL
) {
476 printf("smb2cli_session_setup_send() returned NULL\n");
480 ok
= tevent_req_poll(subreq
, ev
);
482 printf("tevent_req_poll() returned false\n");
486 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
487 &recv_iov
, &out_blob
);
488 if (!NT_STATUS_IS_OK(status
)) {
489 printf("smb2cli_session_setup_recv returned %s\n",
494 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
496 if (!NT_STATUS_IS_OK(status
)) {
497 printf("gensec_session_key returned %s\n",
502 /* check file operation on the old client */
504 status
= smb2cli_flush(cli1
, fid_persistent
, fid_volatile
);
505 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
506 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
510 status
= cli_tree_connect(cli1
, share
, "?????", "", 0);
511 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
512 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
517 * checking file operations without signing.
518 * on w2k8r2 at least, flush, read and write also work the same way,
519 * while create gives ACCESS_DENIED without signing
521 status
= smb2cli_flush(cli2
, fid_persistent
, fid_volatile
);
522 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
523 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
527 status
= smb2cli_write(cli2
, strlen(hello
), 0, fid_persistent
,
528 fid_volatile
, 0, 0, (const uint8_t *)hello
);
529 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
530 printf("smb2cli_write returned %s\n", nt_errstr(status
));
534 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
535 cli2
->smb2
.tid
, 0x10000, 0, fid_persistent
,
537 talloc_tos(), &result
, &nread
);
538 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
539 printf("smb2cli_read returned %s\n", nt_errstr(status
));
543 status
= smb2cli_create(cli2
, "session-reconnect.txt",
544 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
545 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
546 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
547 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
548 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
549 FILE_CREATE
, /* create_disposition, */
550 FILE_DELETE_ON_CLOSE
, /* create_options, */
551 NULL
, /* smb2_create_blobs *blobs */
554 if (!NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
) &&
555 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
556 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
560 /* now grab the session key and try with signing */
562 status
= smb2cli_session_set_session_key(cli2
->smb2
.session
,
565 if (!NT_STATUS_IS_OK(status
)) {
566 printf("smb2cli_session_set_session_key %s\n", nt_errstr(status
));
570 /* the tid seems to be irrelevant at this stage */
572 cli2
->smb2
.tid
= cli1
->smb2
.tid
;
574 status
= smb2cli_flush(cli2
, fid_persistent
, fid_volatile
);
575 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
576 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
580 status
= smb2cli_write(cli2
, strlen(hello
), 0, fid_persistent
,
581 fid_volatile
, 0, 0, (const uint8_t *)hello
);
582 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
583 printf("smb2cli_write returned %s\n", nt_errstr(status
));
587 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
588 cli2
->smb2
.tid
, 0x10000, 0, fid_persistent
,
590 talloc_tos(), &result
, &nread
);
591 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
592 printf("smb2cli_read returned %s\n", nt_errstr(status
));
596 status
= smb2cli_create(cli2
, "session-reconnect.txt",
597 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
598 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
599 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
600 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
601 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
602 FILE_CREATE
, /* create_disposition, */
603 FILE_DELETE_ON_CLOSE
, /* create_options, */
604 NULL
, /* smb2_create_blobs *blobs */
607 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
608 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
612 /* now do a new tcon and test file calls again */
614 status
= cli_tree_connect(cli2
, share
, "?????", "", 0);
615 if (!NT_STATUS_IS_OK(status
)) {
616 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
620 status
= smb2cli_create(cli2
, "session-reconnect.txt",
621 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
622 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
623 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
624 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
625 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
626 FILE_CREATE
, /* create_disposition, */
627 FILE_DELETE_ON_CLOSE
, /* create_options, */
628 NULL
, /* smb2_create_blobs *blobs */
631 if (!NT_STATUS_IS_OK(status
)) {
632 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
636 status
= smb2cli_write(cli2
, strlen(hello
), 0, fid_persistent
,
637 fid_volatile
, 0, 0, (const uint8_t *)hello
);
638 if (!NT_STATUS_IS_OK(status
)) {
639 printf("smb2cli_write returned %s\n", nt_errstr(status
));
643 status
= smb2cli_flush(cli2
, fid_persistent
, fid_volatile
);
644 if (!NT_STATUS_IS_OK(status
)) {
645 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
649 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
650 cli2
->smb2
.tid
, 0x10000, 0, fid_persistent
,
652 talloc_tos(), &result
, &nread
);
653 if (!NT_STATUS_IS_OK(status
)) {
654 printf("smb2cli_read returned %s\n", nt_errstr(status
));
658 if (nread
!= strlen(hello
)) {
659 printf("smb2cli_read returned %d bytes, expected %d\n",
660 (int)nread
, (int)strlen(hello
));
664 if (memcmp(hello
, result
, nread
) != 0) {
665 printf("smb2cli_read returned '%s', expected '%s'\n",
673 bool run_smb2_tcon_dependence(int dummy
)
675 struct cli_state
*cli
;
677 uint64_t fid_persistent
, fid_volatile
;
678 const char *hello
= "Hello, world\n";
682 printf("Starting SMB2-TCON-DEPENDENCE\n");
684 if (!torture_init_connection(&cli
)) {
687 cli
->smb2
.pid
= 0xFEFF;
689 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
690 PROTOCOL_SMB2_02
, PROTOCOL_LATEST
);
691 if (!NT_STATUS_IS_OK(status
)) {
692 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
696 status
= cli_session_setup(cli
, username
,
697 password
, strlen(password
),
698 password
, strlen(password
),
700 if (!NT_STATUS_IS_OK(status
)) {
701 printf("cli_session_setup returned %s\n", nt_errstr(status
));
705 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
706 if (!NT_STATUS_IS_OK(status
)) {
707 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
711 status
= smb2cli_create(cli
, "tcon_depedence.txt",
712 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
713 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
714 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
715 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
716 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
717 FILE_CREATE
, /* create_disposition, */
718 FILE_DELETE_ON_CLOSE
, /* create_options, */
719 NULL
, /* smb2_create_blobs *blobs */
722 if (!NT_STATUS_IS_OK(status
)) {
723 printf("smb2cli_create on cli %s\n", nt_errstr(status
));
727 status
= smb2cli_write(cli
, strlen(hello
), 0, fid_persistent
,
728 fid_volatile
, 0, 0, (const uint8_t *)hello
);
729 if (!NT_STATUS_IS_OK(status
)) {
730 printf("smb2cli_write returned %s\n", nt_errstr(status
));
734 status
= smb2cli_flush(cli
, fid_persistent
, fid_volatile
);
735 if (!NT_STATUS_IS_OK(status
)) {
736 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
740 status
= smb2cli_read(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
741 cli
->smb2
.tid
, 0x10000, 0, fid_persistent
,
743 talloc_tos(), &result
, &nread
);
744 if (!NT_STATUS_IS_OK(status
)) {
745 printf("smb2cli_read returned %s\n", nt_errstr(status
));
749 if (nread
!= strlen(hello
)) {
750 printf("smb2cli_read returned %d bytes, expected %d\n",
751 (int)nread
, (int)strlen(hello
));
755 if (memcmp(hello
, result
, nread
) != 0) {
756 printf("smb2cli_read returned '%s', expected '%s'\n",
761 /* check behaviour with wrong tid... */
765 status
= smb2cli_read(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
766 cli
->smb2
.tid
, 0x10000, 0, fid_persistent
,
768 talloc_tos(), &result
, &nread
);
769 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
770 printf("smb2cli_read returned %s\n", nt_errstr(status
));
779 bool run_smb2_multi_channel(int dummy
)
781 struct cli_state
*cli1
;
782 struct cli_state
*cli2
;
783 struct cli_state
*cli3
;
786 uint64_t fid_persistent
, fid_volatile
;
787 struct tevent_context
*ev
;
788 struct tevent_req
*subreq
;
789 DATA_BLOB in_blob
= data_blob_null
;
791 DATA_BLOB channel_session_key
;
792 struct auth_generic_state
*auth_generic_state
;
793 struct iovec
*recv_iov
;
794 const char *hello
= "Hello, world\n";
798 printf("Starting SMB2-MULTI-CHANNEL\n");
800 if (!torture_init_connection(&cli1
)) {
803 cli1
->smb2
.pid
= 0xFEFF;
805 if (!torture_init_connection(&cli2
)) {
808 cli2
->smb2
.pid
= 0xFEFF;
810 if (!torture_init_connection(&cli3
)) {
813 cli3
->smb2
.pid
= 0xFEFF;
815 status
= smbXcli_negprot(cli1
->conn
, cli1
->timeout
,
816 PROTOCOL_SMB2_22
, PROTOCOL_LATEST
);
817 if (!NT_STATUS_IS_OK(status
)) {
818 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
822 status
= smbXcli_negprot(cli2
->conn
, cli2
->timeout
,
823 PROTOCOL_SMB2_22
, PROTOCOL_LATEST
);
824 if (!NT_STATUS_IS_OK(status
)) {
825 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
829 status
= smbXcli_negprot(cli3
->conn
, cli3
->timeout
,
830 PROTOCOL_SMB2_22
, PROTOCOL_LATEST
);
831 if (!NT_STATUS_IS_OK(status
)) {
832 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
836 status
= cli_session_setup(cli1
, username
,
837 password
, strlen(password
),
838 password
, strlen(password
),
840 if (!NT_STATUS_IS_OK(status
)) {
841 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status
));
845 status
= cli_tree_connect(cli1
, share
, "?????", "", 0);
846 if (!NT_STATUS_IS_OK(status
)) {
847 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
851 status
= smb2cli_session_create_channel(cli2
,
854 &cli2
->smb2
.session
);
855 if (!NT_STATUS_IS_OK(status
)) {
856 printf("smb2cli_session_create_channel returned %s\n",
861 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
862 if (!NT_STATUS_IS_OK(status
)) {
863 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
867 gensec_want_feature(auth_generic_state
->gensec_security
,
868 GENSEC_FEATURE_SESSION_KEY
);
869 status
= auth_generic_set_username(auth_generic_state
, username
);
870 if (!NT_STATUS_IS_OK(status
)) {
871 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
875 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
876 if (!NT_STATUS_IS_OK(status
)) {
877 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
881 status
= auth_generic_set_password(auth_generic_state
, password
);
882 if (!NT_STATUS_IS_OK(status
)) {
883 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
887 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
888 if (!NT_STATUS_IS_OK(status
)) {
889 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
893 ev
= event_context_init(talloc_tos());
895 printf("event_context_init() returned NULL\n");
899 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, data_blob_null
, &in_blob
);
900 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
901 printf("gensec_update returned %s\n", nt_errstr(status
));
905 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
910 SMB2_CAP_DFS
, /* in_capabilities */
912 0, /* in_previous_session_id */
913 &in_blob
); /* in_security_buffer */
914 if (subreq
== NULL
) {
915 printf("smb2cli_session_setup_send() returned NULL\n");
919 ok
= tevent_req_poll(subreq
, ev
);
921 printf("tevent_req_poll() returned false\n");
925 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
927 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
928 printf("smb2cli_session_setup_recv returned %s\n",
933 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, out_blob
, &in_blob
);
934 if (!NT_STATUS_IS_OK(status
)) {
935 printf("auth_generic_update returned %s\n", nt_errstr(status
));
939 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
944 SMB2_CAP_DFS
, /* in_capabilities */
946 0, /* in_previous_session_id */
947 &in_blob
); /* in_security_buffer */
948 if (subreq
== NULL
) {
949 printf("smb2cli_session_setup_send() returned NULL\n");
953 ok
= tevent_req_poll(subreq
, ev
);
955 printf("tevent_req_poll() returned false\n");
959 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
960 &recv_iov
, &out_blob
);
961 if (!NT_STATUS_IS_OK(status
)) {
962 printf("smb2cli_session_setup_recv returned %s\n",
967 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
968 &channel_session_key
);
969 if (!NT_STATUS_IS_OK(status
)) {
970 printf("gensec_session_key returned %s\n",
975 status
= smb2cli_session_set_channel_key(cli2
->smb2
.session
,
978 if (!NT_STATUS_IS_OK(status
)) {
979 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status
));
983 cli2
->smb2
.tid
= cli1
->smb2
.tid
;
985 status
= smb2cli_session_create_channel(cli3
,
988 &cli3
->smb2
.session
);
989 if (!NT_STATUS_IS_OK(status
)) {
990 printf("smb2cli_session_create_channel returned %s\n",
995 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
996 if (!NT_STATUS_IS_OK(status
)) {
997 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1001 gensec_want_feature(auth_generic_state
->gensec_security
,
1002 GENSEC_FEATURE_SESSION_KEY
);
1003 status
= auth_generic_set_username(auth_generic_state
, username
);
1004 if (!NT_STATUS_IS_OK(status
)) {
1005 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
1009 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
1010 if (!NT_STATUS_IS_OK(status
)) {
1011 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
1015 status
= auth_generic_set_password(auth_generic_state
, password
);
1016 if (!NT_STATUS_IS_OK(status
)) {
1017 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
1021 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1022 if (!NT_STATUS_IS_OK(status
)) {
1023 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1027 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, data_blob_null
, &in_blob
);
1028 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1029 printf("gensec_update returned %s\n", nt_errstr(status
));
1033 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1037 0x01, /* in_flags */
1038 SMB2_CAP_DFS
, /* in_capabilities */
1040 0, /* in_previous_session_id */
1041 &in_blob
); /* in_security_buffer */
1042 if (subreq
== NULL
) {
1043 printf("smb2cli_session_setup_send() returned NULL\n");
1047 ok
= tevent_req_poll(subreq
, ev
);
1049 printf("tevent_req_poll() returned false\n");
1053 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1055 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1056 printf("smb2cli_session_setup_recv returned %s\n",
1061 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, out_blob
, &in_blob
);
1062 if (!NT_STATUS_IS_OK(status
)) {
1063 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1067 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1071 0x01, /* in_flags */
1072 SMB2_CAP_DFS
, /* in_capabilities */
1074 0, /* in_previous_session_id */
1075 &in_blob
); /* in_security_buffer */
1076 if (subreq
== NULL
) {
1077 printf("smb2cli_session_setup_send() returned NULL\n");
1081 ok
= tevent_req_poll(subreq
, ev
);
1083 printf("tevent_req_poll() returned false\n");
1087 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1088 &recv_iov
, &out_blob
);
1089 if (!NT_STATUS_IS_OK(status
)) {
1090 printf("smb2cli_session_setup_recv returned %s\n",
1095 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
1096 &channel_session_key
);
1097 if (!NT_STATUS_IS_OK(status
)) {
1098 printf("gensec_session_key returned %s\n",
1103 status
= smb2cli_session_set_channel_key(cli3
->smb2
.session
,
1104 channel_session_key
,
1106 if (!NT_STATUS_IS_OK(status
)) {
1107 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status
));
1111 cli3
->smb2
.tid
= cli2
->smb2
.tid
;
1113 status
= smb2cli_create(cli2
, "multi-channel.txt",
1114 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1115 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1116 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1117 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1118 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1119 FILE_CREATE
, /* create_disposition, */
1120 FILE_DELETE_ON_CLOSE
, /* create_options, */
1121 NULL
, /* smb2_create_blobs *blobs */
1124 if (!NT_STATUS_IS_OK(status
)) {
1125 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
1129 status
= smb2cli_write(cli1
, strlen(hello
), 0, fid_persistent
,
1130 fid_volatile
, 0, 0, (const uint8_t *)hello
);
1131 if (!NT_STATUS_IS_OK(status
)) {
1132 printf("smb2cli_write returned %s\n", nt_errstr(status
));
1136 status
= smb2cli_flush(cli2
, fid_persistent
, fid_volatile
);
1137 if (!NT_STATUS_IS_OK(status
)) {
1138 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1142 status
= smb2cli_flush(cli1
, fid_persistent
, fid_volatile
);
1143 if (!NT_STATUS_IS_OK(status
)) {
1144 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1148 status
= smb2cli_flush(cli3
, fid_persistent
, fid_volatile
);
1149 if (!NT_STATUS_IS_OK(status
)) {
1150 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1154 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1155 cli2
->smb2
.tid
, 0x10000, 0, fid_persistent
,
1157 talloc_tos(), &result
, &nread
);
1158 if (!NT_STATUS_IS_OK(status
)) {
1159 printf("smb2cli_read returned %s\n", nt_errstr(status
));
1163 if (nread
!= strlen(hello
)) {
1164 printf("smb2cli_read returned %d bytes, expected %d\n",
1165 (int)nread
, (int)strlen(hello
));
1169 if (memcmp(hello
, result
, nread
) != 0) {
1170 printf("smb2cli_read returned '%s', expected '%s'\n",
1175 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1176 if (!NT_STATUS_IS_OK(status
)) {
1177 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1181 gensec_want_feature(auth_generic_state
->gensec_security
,
1182 GENSEC_FEATURE_SESSION_KEY
);
1183 status
= auth_generic_set_username(auth_generic_state
, username
);
1184 if (!NT_STATUS_IS_OK(status
)) {
1185 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
1189 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
1190 if (!NT_STATUS_IS_OK(status
)) {
1191 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
1195 status
= auth_generic_set_password(auth_generic_state
, password
);
1196 if (!NT_STATUS_IS_OK(status
)) {
1197 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
1201 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1202 if (!NT_STATUS_IS_OK(status
)) {
1203 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1207 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, data_blob_null
, &in_blob
);
1208 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1209 printf("gensec_update returned %s\n", nt_errstr(status
));
1213 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1218 SMB2_CAP_DFS
, /* in_capabilities */
1220 0, /* in_previous_session_id */
1221 &in_blob
); /* in_security_buffer */
1222 if (subreq
== NULL
) {
1223 printf("smb2cli_session_setup_send() returned NULL\n");
1227 ok
= tevent_req_poll(subreq
, ev
);
1229 printf("tevent_req_poll() returned false\n");
1233 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1235 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1236 printf("smb2cli_session_setup_recv returned %s\n",
1241 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, out_blob
, &in_blob
);
1242 if (!NT_STATUS_IS_OK(status
)) {
1243 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1247 status
= smb2cli_flush(cli1
, fid_persistent
, fid_volatile
);
1248 if (!NT_STATUS_IS_OK(status
)) {
1249 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1253 status
= smb2cli_flush(cli2
, fid_persistent
, fid_volatile
);
1254 if (!NT_STATUS_IS_OK(status
)) {
1255 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1259 status
= smb2cli_flush(cli3
, fid_persistent
, fid_volatile
);
1260 if (!NT_STATUS_IS_OK(status
)) {
1261 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1265 status
= smb2cli_create(cli1
, "multi-channel-invalid.txt",
1266 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1267 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1268 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1269 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1270 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1271 FILE_CREATE
, /* create_disposition, */
1272 FILE_DELETE_ON_CLOSE
, /* create_options, */
1273 NULL
, /* smb2_create_blobs *blobs */
1276 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1277 printf("smb2cli_create %s\n", nt_errstr(status
));
1281 status
= smb2cli_create(cli2
, "multi-channel-invalid.txt",
1282 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1283 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1284 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1285 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1286 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1287 FILE_CREATE
, /* create_disposition, */
1288 FILE_DELETE_ON_CLOSE
, /* create_options, */
1289 NULL
, /* smb2_create_blobs *blobs */
1292 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1293 printf("smb2cli_create %s\n", nt_errstr(status
));
1297 status
= smb2cli_create(cli3
, "multi-channel-invalid.txt",
1298 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1299 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1300 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1301 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1302 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1303 FILE_CREATE
, /* create_disposition, */
1304 FILE_DELETE_ON_CLOSE
, /* create_options, */
1305 NULL
, /* smb2_create_blobs *blobs */
1308 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1309 printf("smb2cli_create %s\n", nt_errstr(status
));
1313 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1318 SMB2_CAP_DFS
, /* in_capabilities */
1320 0, /* in_previous_session_id */
1321 &in_blob
); /* in_security_buffer */
1322 if (subreq
== NULL
) {
1323 printf("smb2cli_session_setup_send() returned NULL\n");
1327 ok
= tevent_req_poll(subreq
, ev
);
1329 printf("tevent_req_poll() returned false\n");
1333 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1334 &recv_iov
, &out_blob
);
1335 if (!NT_STATUS_IS_OK(status
)) {
1336 printf("smb2cli_session_setup_recv returned %s\n",
1341 status
= smb2cli_close(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1342 cli3
->smb2
.tid
, 0, fid_persistent
, fid_volatile
);
1343 if (!NT_STATUS_IS_OK(status
)) {
1344 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1348 status
= smb2cli_flush(cli3
, fid_persistent
, fid_volatile
);
1349 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1350 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1354 status
= smb2cli_flush(cli2
, fid_persistent
, fid_volatile
);
1355 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1356 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1360 status
= smb2cli_flush(cli1
, fid_persistent
, fid_volatile
);
1361 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1362 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1369 bool run_smb2_session_reauth(int dummy
)
1371 struct cli_state
*cli
;
1374 uint64_t fid_persistent
, fid_volatile
;
1375 uint64_t dir_persistent
, dir_volatile
;
1377 uint32_t dir_data_length
;
1378 struct tevent_context
*ev
;
1379 struct tevent_req
*subreq
;
1380 DATA_BLOB in_blob
= data_blob_null
;
1382 DATA_BLOB in_input_buffer
;
1383 DATA_BLOB out_output_buffer
;
1384 uint8_t in_file_info_class
;
1385 struct auth_generic_state
*auth_generic_state
;
1386 struct iovec
*recv_iov
;
1389 printf("Starting SMB2-SESSION_REAUTH\n");
1391 if (!torture_init_connection(&cli
)) {
1394 cli
->smb2
.pid
= 0xFEFF;
1397 * PROTOCOL_SMB2_22 has a bug in win8pre0
1398 * it behaves like PROTOCOL_SMB2_02
1399 * and returns NT_STATUS_REQUEST_NOT_ACCEPTED,
1400 * while it allows it on PROTOCOL_SMB2_02.
1402 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
1403 PROTOCOL_SMB2_10
, PROTOCOL_SMB2_10
);
1404 if (!NT_STATUS_IS_OK(status
)) {
1405 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
1409 status
= cli_session_setup(cli
, username
,
1410 password
, strlen(password
),
1411 password
, strlen(password
),
1413 if (!NT_STATUS_IS_OK(status
)) {
1414 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status
));
1418 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
1419 if (!NT_STATUS_IS_OK(status
)) {
1420 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1424 status
= smb2cli_create(cli
, "session-reauth.txt",
1425 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1426 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1427 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1428 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1429 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1430 FILE_CREATE
, /* create_disposition, */
1431 FILE_DELETE_ON_CLOSE
, /* create_options, */
1432 NULL
, /* smb2_create_blobs *blobs */
1435 if (!NT_STATUS_IS_OK(status
)) {
1436 printf("smb2cli_create %s\n", nt_errstr(status
));
1440 status
= smb2cli_create(cli
, "",
1441 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1442 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1443 SEC_STD_SYNCHRONIZE
|
1445 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
1446 0, /* file_attributes, */
1447 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1448 FILE_OPEN
, /* create_disposition, */
1449 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
1450 NULL
, /* smb2_create_blobs *blobs */
1453 if (!NT_STATUS_IS_OK(status
)) {
1454 printf("smb2cli_create returned %s\n", nt_errstr(status
));
1458 status
= smb2cli_query_directory(
1459 cli
, 1, 0x3, 0, dir_persistent
, dir_volatile
,
1460 "session-reauth.txt", 0xffff,
1461 talloc_tos(), &dir_data
, &dir_data_length
);
1462 if (!NT_STATUS_IS_OK(status
)) {
1463 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1467 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1468 if (!NT_STATUS_IS_OK(status
)) {
1469 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1473 gensec_want_feature(auth_generic_state
->gensec_security
,
1474 GENSEC_FEATURE_SESSION_KEY
);
1475 status
= auth_generic_set_username(auth_generic_state
, username
);
1476 if (!NT_STATUS_IS_OK(status
)) {
1477 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
1481 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
1482 if (!NT_STATUS_IS_OK(status
)) {
1483 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
1487 status
= auth_generic_set_password(auth_generic_state
, password
);
1488 if (!NT_STATUS_IS_OK(status
)) {
1489 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
1493 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1494 if (!NT_STATUS_IS_OK(status
)) {
1495 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1499 ev
= event_context_init(talloc_tos());
1501 printf("event_context_init() returned NULL\n");
1505 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, data_blob_null
, &in_blob
);
1506 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1507 printf("gensec_update returned %s\n", nt_errstr(status
));
1511 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1516 SMB2_CAP_DFS
, /* in_capabilities */
1518 0, /* in_previous_session_id */
1519 &in_blob
); /* in_security_buffer */
1520 if (subreq
== NULL
) {
1521 printf("smb2cli_session_setup_send() returned NULL\n");
1525 ok
= tevent_req_poll(subreq
, ev
);
1527 printf("tevent_req_poll() returned false\n");
1531 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1533 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1534 printf("smb2cli_session_setup_recv returned %s\n",
1539 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, out_blob
, &in_blob
);
1540 if (!NT_STATUS_IS_OK(status
)) {
1541 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1545 status
= smb2cli_flush(cli
, fid_persistent
, fid_volatile
);
1546 if (!NT_STATUS_IS_OK(status
)) {
1547 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1551 status
= smb2cli_query_directory(
1552 cli
, 1, 0x3, 0, dir_persistent
, dir_volatile
,
1553 "session-reauth.txt", 0xffff,
1554 talloc_tos(), &dir_data
, &dir_data_length
);
1555 if (!NT_STATUS_IS_OK(status
)) {
1556 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1561 * query_info seems to be a path based operation on Windows...
1563 status
= smb2cli_query_info(cli
->conn
,
1567 SMB2_GETINFO_SECURITY
,
1568 0, /* in_file_info_class */
1569 1024, /* in_max_output_length */
1570 NULL
, /* in_input_buffer */
1571 SECINFO_OWNER
, /* in_additional_info */
1576 &out_output_buffer
);
1577 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1578 printf("smb2cli_query_info (security) returned %s\n", nt_errstr(status
));
1582 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1583 status
= smb2cli_query_info(cli
->conn
,
1589 1024, /* in_max_output_length */
1590 NULL
, /* in_input_buffer */
1591 0, /* in_additional_info */
1596 &out_output_buffer
);
1597 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1598 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1602 in_input_buffer
= data_blob_talloc(talloc_tos(), NULL
, 8);
1603 SBVAL(in_input_buffer
.data
, 0, 512);
1605 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1606 status
= smb2cli_set_info(cli
->conn
,
1613 0, /* in_additional_info */
1616 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1617 printf("smb2cli_set_info (position) returned %s\n", nt_errstr(status
));
1621 status
= smb2cli_create(cli
, "session-reauth-invalid.txt",
1622 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1623 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1624 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1625 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1626 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1627 FILE_CREATE
, /* create_disposition, */
1628 FILE_DELETE_ON_CLOSE
, /* create_options, */
1629 NULL
, /* smb2_create_blobs *blobs */
1632 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1633 printf("smb2cli_create %s\n", nt_errstr(status
));
1637 status
= smb2cli_create(cli
, "",
1638 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1639 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1640 SEC_STD_SYNCHRONIZE
|
1642 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
1643 0, /* file_attributes, */
1644 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1645 FILE_OPEN
, /* create_disposition, */
1646 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
1647 NULL
, /* smb2_create_blobs *blobs */
1650 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1651 printf("smb2cli_create returned %s\n", nt_errstr(status
));
1655 saved_tid
= cli
->smb2
.tid
;
1656 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
1657 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1658 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1661 cli
->smb2
.tid
= saved_tid
;
1663 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1668 SMB2_CAP_DFS
, /* in_capabilities */
1670 0, /* in_previous_session_id */
1671 &in_blob
); /* in_security_buffer */
1672 if (subreq
== NULL
) {
1673 printf("smb2cli_session_setup_send() returned NULL\n");
1677 ok
= tevent_req_poll(subreq
, ev
);
1679 printf("tevent_req_poll() returned false\n");
1683 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1684 &recv_iov
, &out_blob
);
1685 if (!NT_STATUS_IS_OK(status
)) {
1686 printf("smb2cli_session_setup_recv returned %s\n",
1691 status
= smb2cli_flush(cli
, fid_persistent
, fid_volatile
);
1692 if (!NT_STATUS_IS_OK(status
)) {
1693 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1697 status
= smb2cli_query_info(cli
->conn
,
1701 SMB2_GETINFO_SECURITY
,
1702 0, /* in_file_info_class */
1703 1024, /* in_max_output_length */
1704 NULL
, /* in_input_buffer */
1705 SECINFO_OWNER
, /* in_additional_info */
1710 &out_output_buffer
);
1711 if (!NT_STATUS_IS_OK(status
)) {
1712 printf("smb2cli_query_info (security) returned %s\n", nt_errstr(status
));
1716 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1717 status
= smb2cli_query_info(cli
->conn
,
1723 1024, /* in_max_output_length */
1724 NULL
, /* in_input_buffer */
1725 0, /* in_additional_info */
1730 &out_output_buffer
);
1731 if (!NT_STATUS_IS_OK(status
)) {
1732 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1736 in_input_buffer
= data_blob_talloc(talloc_tos(), NULL
, 8);
1737 SBVAL(in_input_buffer
.data
, 0, 512);
1739 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1740 status
= smb2cli_set_info(cli
->conn
,
1747 0, /* in_additional_info */
1750 if (!NT_STATUS_IS_OK(status
)) {
1751 printf("smb2cli_set_info (position) returned %s\n", nt_errstr(status
));
1755 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1756 status
= smb2cli_query_info(cli
->conn
,
1762 1024, /* in_max_output_length */
1763 NULL
, /* in_input_buffer */
1764 0, /* in_additional_info */
1769 &out_output_buffer
);
1770 if (!NT_STATUS_IS_OK(status
)) {
1771 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1775 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1776 cli
->smb2
.tid
, 0, fid_persistent
, fid_volatile
);
1777 if (!NT_STATUS_IS_OK(status
)) {
1778 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1782 status
= smb2cli_create(cli
, "session-reauth.txt",
1783 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1784 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1785 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1786 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1787 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1788 FILE_CREATE
, /* create_disposition, */
1789 FILE_DELETE_ON_CLOSE
, /* create_options, */
1790 NULL
, /* smb2_create_blobs *blobs */
1793 if (!NT_STATUS_IS_OK(status
)) {
1794 printf("smb2cli_create %s\n", nt_errstr(status
));
1798 status
= smb2cli_query_directory(
1799 cli
, 1, 0x3, 0, dir_persistent
, dir_volatile
,
1800 "session-reauth.txt", 0xffff,
1801 talloc_tos(), &dir_data
, &dir_data_length
);
1802 if (!NT_STATUS_IS_OK(status
)) {
1803 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1807 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1808 cli
->smb2
.tid
, 0, dir_persistent
, dir_volatile
);
1809 if (!NT_STATUS_IS_OK(status
)) {
1810 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1814 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1815 cli
->smb2
.tid
, 0, fid_persistent
, fid_volatile
);
1816 if (!NT_STATUS_IS_OK(status
)) {
1817 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1821 saved_tid
= cli
->smb2
.tid
;
1822 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
1823 if (!NT_STATUS_IS_OK(status
)) {
1824 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1827 cli
->smb2
.tid
= saved_tid
;