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
->conn
, cli
->timeout
, cli
->smb2
.session
,
76 cli
->smb2
.tid
, "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 */
87 if (!NT_STATUS_IS_OK(status
)) {
88 printf("smb2cli_create returned %s\n", nt_errstr(status
));
92 status
= smb2cli_write(cli
, strlen(hello
), 0, fid_persistent
,
93 fid_volatile
, 0, 0, (const uint8_t *)hello
);
94 if (!NT_STATUS_IS_OK(status
)) {
95 printf("smb2cli_write returned %s\n", nt_errstr(status
));
99 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
100 cli
->smb2
.tid
, fid_persistent
, fid_volatile
);
101 if (!NT_STATUS_IS_OK(status
)) {
102 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
106 status
= smb2cli_read(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
107 cli
->smb2
.tid
, 0x10000, 0, fid_persistent
,
109 talloc_tos(), &result
, &nread
);
110 if (!NT_STATUS_IS_OK(status
)) {
111 printf("smb2cli_read returned %s\n", nt_errstr(status
));
115 if (nread
!= strlen(hello
)) {
116 printf("smb2cli_read returned %d bytes, expected %d\n",
117 (int)nread
, (int)strlen(hello
));
121 if (memcmp(hello
, result
, nread
) != 0) {
122 printf("smb2cli_read returned '%s', expected '%s'\n",
127 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
128 cli
->smb2
.tid
, 0, fid_persistent
, fid_volatile
);
129 if (!NT_STATUS_IS_OK(status
)) {
130 printf("smb2cli_close returned %s\n", nt_errstr(status
));
134 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
136 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
137 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
140 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
141 0, /* file_attributes, */
142 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
143 FILE_OPEN
, /* create_disposition, */
144 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
145 NULL
, /* smb2_create_blobs *blobs */
148 if (!NT_STATUS_IS_OK(status
)) {
149 printf("smb2cli_create returned %s\n", nt_errstr(status
));
153 status
= smb2cli_query_directory(
154 cli
, 1, 0, 0, fid_persistent
, fid_volatile
, "*", 0xffff,
155 talloc_tos(), &dir_data
, &dir_data_length
);
157 if (!NT_STATUS_IS_OK(status
)) {
158 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
162 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
163 cli
->smb2
.tid
, 0, fid_persistent
, fid_volatile
);
164 if (!NT_STATUS_IS_OK(status
)) {
165 printf("smb2cli_close returned %s\n", nt_errstr(status
));
169 saved_tid
= cli
->smb2
.tid
;
170 status
= smb2cli_tdis(cli
);
171 if (!NT_STATUS_IS_OK(status
)) {
172 printf("smb2cli_tdis returned %s\n", nt_errstr(status
));
175 cli
->smb2
.tid
= saved_tid
;
177 status
= smb2cli_tdis(cli
);
178 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
179 printf("2nd smb2cli_tdis returned %s\n", nt_errstr(status
));
183 saved_uid
= smb2cli_session_current_id(cli
->smb2
.session
);
184 status
= smb2cli_logoff(cli
);
185 if (!NT_STATUS_IS_OK(status
)) {
186 printf("smb2cli_logoff returned %s\n", nt_errstr(status
));
190 cli
->smb2
.session
= smbXcli_session_create(cli
, cli
->conn
);
191 if (cli
->smb2
.session
== NULL
) {
192 printf("smbXcli_session_create() returned NULL\n");
196 smb2cli_session_set_id_and_flags(cli
->smb2
.session
, saved_uid
, 0);
198 status
= smb2cli_logoff(cli
);
199 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
200 printf("2nd smb2cli_logoff returned %s\n", nt_errstr(status
));
207 bool run_smb2_negprot(int dummy
)
209 struct cli_state
*cli
;
211 enum protocol_types protocol
;
212 const char *name
= NULL
;
214 printf("Starting SMB2-NEGPROT\n");
216 if (!torture_init_connection(&cli
)) {
219 cli
->smb2
.pid
= 0xFEFF;
221 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
222 PROTOCOL_CORE
, PROTOCOL_LATEST
);
223 if (!NT_STATUS_IS_OK(status
)) {
224 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
228 protocol
= smbXcli_conn_protocol(cli
->conn
);
231 case PROTOCOL_SMB2_02
:
234 case PROTOCOL_SMB2_10
:
237 case PROTOCOL_SMB2_22
:
240 case PROTOCOL_SMB2_24
:
243 case PROTOCOL_SMB3_00
:
251 printf("Server supports %s\n", name
);
253 printf("Server DOES NOT support SMB2\n");
257 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
259 if (!NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_RESET
) &&
260 !NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_DISCONNECTED
) &&
261 !NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_ABORTED
)) {
262 printf("2nd smbXcli_negprot should disconnect - returned %s\n",
267 if (smbXcli_conn_is_connected(cli
->conn
)) {
268 printf("2nd smbXcli_negprot should disconnect "
269 "- still connected\n");
276 bool run_smb2_session_reconnect(int dummy
)
278 struct cli_state
*cli1
;
279 struct cli_state
*cli2
;
282 uint64_t fid_persistent
, fid_volatile
;
283 struct tevent_context
*ev
;
284 struct tevent_req
*subreq
;
285 DATA_BLOB in_blob
= data_blob_null
;
287 DATA_BLOB session_key
;
288 struct auth_generic_state
*auth_generic_state
;
289 struct iovec
*recv_iov
;
290 const char *hello
= "Hello, world\n";
294 printf("Starting SMB2-SESSION-RECONNECT\n");
296 if (!torture_init_connection(&cli1
)) {
299 cli1
->smb2
.pid
= 0xFEFF;
301 status
= smbXcli_negprot(cli1
->conn
, cli1
->timeout
,
302 PROTOCOL_SMB2_02
, PROTOCOL_LATEST
);
303 if (!NT_STATUS_IS_OK(status
)) {
304 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
308 status
= cli_session_setup(cli1
, username
,
309 password
, strlen(password
),
310 password
, strlen(password
),
312 if (!NT_STATUS_IS_OK(status
)) {
313 printf("cli_session_setup returned %s\n", nt_errstr(status
));
317 status
= cli_tree_connect(cli1
, share
, "?????", "", 0);
318 if (!NT_STATUS_IS_OK(status
)) {
319 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
323 status
= smb2cli_create(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
324 cli1
->smb2
.tid
, "session-reconnect.txt",
325 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
326 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
327 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
328 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
329 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
330 FILE_CREATE
, /* create_disposition, */
331 FILE_DELETE_ON_CLOSE
, /* create_options, */
332 NULL
, /* smb2_create_blobs *blobs */
335 if (!NT_STATUS_IS_OK(status
)) {
336 printf("smb2cli_create on cli1 %s\n", nt_errstr(status
));
340 status
= smb2cli_write(cli1
, strlen(hello
), 0, fid_persistent
,
341 fid_volatile
, 0, 0, (const uint8_t *)hello
);
342 if (!NT_STATUS_IS_OK(status
)) {
343 printf("smb2cli_write returned %s\n", nt_errstr(status
));
347 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
348 cli1
->smb2
.tid
, fid_persistent
, fid_volatile
);
349 if (!NT_STATUS_IS_OK(status
)) {
350 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
354 status
= smb2cli_read(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
355 cli1
->smb2
.tid
, 0x10000, 0, fid_persistent
,
357 talloc_tos(), &result
, &nread
);
358 if (!NT_STATUS_IS_OK(status
)) {
359 printf("smb2cli_read returned %s\n", nt_errstr(status
));
363 if (nread
!= strlen(hello
)) {
364 printf("smb2cli_read returned %d bytes, expected %d\n",
365 (int)nread
, (int)strlen(hello
));
369 if (memcmp(hello
, result
, nread
) != 0) {
370 printf("smb2cli_read returned '%s', expected '%s'\n",
375 /* prepare second session */
377 if (!torture_init_connection(&cli2
)) {
380 cli2
->smb2
.pid
= 0xFEFF;
382 status
= smbXcli_negprot(cli2
->conn
, cli2
->timeout
,
383 PROTOCOL_SMB2_02
, PROTOCOL_LATEST
);
384 if (!NT_STATUS_IS_OK(status
)) {
385 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
389 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
390 if (!NT_STATUS_IS_OK(status
)) {
391 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
395 gensec_want_feature(auth_generic_state
->gensec_security
,
396 GENSEC_FEATURE_SESSION_KEY
);
397 status
= auth_generic_set_username(auth_generic_state
, username
);
398 if (!NT_STATUS_IS_OK(status
)) {
399 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
403 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
404 if (!NT_STATUS_IS_OK(status
)) {
405 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
409 status
= auth_generic_set_password(auth_generic_state
, password
);
410 if (!NT_STATUS_IS_OK(status
)) {
411 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
415 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
416 if (!NT_STATUS_IS_OK(status
)) {
417 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
421 ev
= event_context_init(talloc_tos());
423 printf("event_context_init() returned NULL\n");
427 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, data_blob_null
, &in_blob
);
428 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
429 printf("gensec_update returned %s\n", nt_errstr(status
));
433 cli2
->smb2
.session
= smbXcli_session_create(cli2
, cli2
->conn
);
435 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
440 SMB2_CAP_DFS
, /* in_capabilities */
442 /* in_previous_session_id: */
443 smb2cli_session_current_id(cli1
->smb2
.session
),
444 &in_blob
); /* in_security_buffer */
445 if (subreq
== NULL
) {
446 printf("smb2cli_session_setup_send() returned NULL\n");
450 ok
= tevent_req_poll(subreq
, ev
);
452 printf("tevent_req_poll() returned false\n");
456 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
458 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
459 printf("smb2cli_session_setup_recv returned %s\n",
464 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, out_blob
, &in_blob
);
465 if (!NT_STATUS_IS_OK(status
)) {
466 printf("auth_generic_update returned %s\n", nt_errstr(status
));
470 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
475 SMB2_CAP_DFS
, /* in_capabilities */
477 /* in_previous_session_id: */
478 smb2cli_session_current_id(cli1
->smb2
.session
),
479 &in_blob
); /* in_security_buffer */
480 if (subreq
== NULL
) {
481 printf("smb2cli_session_setup_send() returned NULL\n");
485 ok
= tevent_req_poll(subreq
, ev
);
487 printf("tevent_req_poll() returned false\n");
491 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
492 &recv_iov
, &out_blob
);
493 if (!NT_STATUS_IS_OK(status
)) {
494 printf("smb2cli_session_setup_recv returned %s\n",
499 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
501 if (!NT_STATUS_IS_OK(status
)) {
502 printf("gensec_session_key returned %s\n",
507 /* check file operation on the old client */
509 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
510 cli1
->smb2
.tid
, fid_persistent
, fid_volatile
);
511 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
512 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
516 status
= cli_tree_connect(cli1
, share
, "?????", "", 0);
517 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
518 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
523 * checking file operations without signing.
524 * on w2k8r2 at least, flush, read and write also work the same way,
525 * while create gives ACCESS_DENIED without signing
527 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
528 cli2
->smb2
.tid
, fid_persistent
, fid_volatile
);
529 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
530 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
534 status
= smb2cli_write(cli2
, strlen(hello
), 0, fid_persistent
,
535 fid_volatile
, 0, 0, (const uint8_t *)hello
);
536 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
537 printf("smb2cli_write returned %s\n", nt_errstr(status
));
541 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
542 cli2
->smb2
.tid
, 0x10000, 0, fid_persistent
,
544 talloc_tos(), &result
, &nread
);
545 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
546 printf("smb2cli_read returned %s\n", nt_errstr(status
));
550 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
551 cli2
->smb2
.tid
, "session-reconnect.txt",
552 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
553 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
554 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
555 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
556 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
557 FILE_CREATE
, /* create_disposition, */
558 FILE_DELETE_ON_CLOSE
, /* create_options, */
559 NULL
, /* smb2_create_blobs *blobs */
562 if (!NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
) &&
563 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
564 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
568 /* now grab the session key and try with signing */
570 status
= smb2cli_session_set_session_key(cli2
->smb2
.session
,
573 if (!NT_STATUS_IS_OK(status
)) {
574 printf("smb2cli_session_set_session_key %s\n", nt_errstr(status
));
578 /* the tid seems to be irrelevant at this stage */
580 cli2
->smb2
.tid
= cli1
->smb2
.tid
;
582 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
583 cli2
->smb2
.tid
, fid_persistent
, fid_volatile
);
584 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
585 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
589 status
= smb2cli_write(cli2
, strlen(hello
), 0, fid_persistent
,
590 fid_volatile
, 0, 0, (const uint8_t *)hello
);
591 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
592 printf("smb2cli_write returned %s\n", nt_errstr(status
));
596 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
597 cli2
->smb2
.tid
, 0x10000, 0, fid_persistent
,
599 talloc_tos(), &result
, &nread
);
600 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
601 printf("smb2cli_read returned %s\n", nt_errstr(status
));
605 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
606 cli2
->smb2
.tid
, "session-reconnect.txt",
607 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
608 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
609 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
610 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
611 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
612 FILE_CREATE
, /* create_disposition, */
613 FILE_DELETE_ON_CLOSE
, /* create_options, */
614 NULL
, /* smb2_create_blobs *blobs */
617 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
618 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
622 /* now do a new tcon and test file calls again */
624 status
= cli_tree_connect(cli2
, share
, "?????", "", 0);
625 if (!NT_STATUS_IS_OK(status
)) {
626 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
630 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
631 cli2
->smb2
.tid
, "session-reconnect.txt",
632 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
633 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
634 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
635 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
636 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
637 FILE_CREATE
, /* create_disposition, */
638 FILE_DELETE_ON_CLOSE
, /* create_options, */
639 NULL
, /* smb2_create_blobs *blobs */
642 if (!NT_STATUS_IS_OK(status
)) {
643 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
647 status
= smb2cli_write(cli2
, strlen(hello
), 0, fid_persistent
,
648 fid_volatile
, 0, 0, (const uint8_t *)hello
);
649 if (!NT_STATUS_IS_OK(status
)) {
650 printf("smb2cli_write returned %s\n", nt_errstr(status
));
654 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
655 cli2
->smb2
.tid
, fid_persistent
, fid_volatile
);
656 if (!NT_STATUS_IS_OK(status
)) {
657 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
661 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
662 cli2
->smb2
.tid
, 0x10000, 0, fid_persistent
,
664 talloc_tos(), &result
, &nread
);
665 if (!NT_STATUS_IS_OK(status
)) {
666 printf("smb2cli_read returned %s\n", nt_errstr(status
));
670 if (nread
!= strlen(hello
)) {
671 printf("smb2cli_read returned %d bytes, expected %d\n",
672 (int)nread
, (int)strlen(hello
));
676 if (memcmp(hello
, result
, nread
) != 0) {
677 printf("smb2cli_read returned '%s', expected '%s'\n",
685 bool run_smb2_tcon_dependence(int dummy
)
687 struct cli_state
*cli
;
689 uint64_t fid_persistent
, fid_volatile
;
690 const char *hello
= "Hello, world\n";
694 printf("Starting SMB2-TCON-DEPENDENCE\n");
696 if (!torture_init_connection(&cli
)) {
699 cli
->smb2
.pid
= 0xFEFF;
701 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
702 PROTOCOL_SMB2_02
, PROTOCOL_LATEST
);
703 if (!NT_STATUS_IS_OK(status
)) {
704 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
708 status
= cli_session_setup(cli
, username
,
709 password
, strlen(password
),
710 password
, strlen(password
),
712 if (!NT_STATUS_IS_OK(status
)) {
713 printf("cli_session_setup returned %s\n", nt_errstr(status
));
717 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
718 if (!NT_STATUS_IS_OK(status
)) {
719 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
723 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
724 cli
->smb2
.tid
, "tcon_depedence.txt",
725 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
726 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
727 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
728 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
729 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
730 FILE_CREATE
, /* create_disposition, */
731 FILE_DELETE_ON_CLOSE
, /* create_options, */
732 NULL
, /* smb2_create_blobs *blobs */
735 if (!NT_STATUS_IS_OK(status
)) {
736 printf("smb2cli_create on cli %s\n", nt_errstr(status
));
740 status
= smb2cli_write(cli
, strlen(hello
), 0, fid_persistent
,
741 fid_volatile
, 0, 0, (const uint8_t *)hello
);
742 if (!NT_STATUS_IS_OK(status
)) {
743 printf("smb2cli_write returned %s\n", nt_errstr(status
));
747 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
748 cli
->smb2
.tid
, fid_persistent
, fid_volatile
);
749 if (!NT_STATUS_IS_OK(status
)) {
750 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
754 status
= smb2cli_read(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
755 cli
->smb2
.tid
, 0x10000, 0, fid_persistent
,
757 talloc_tos(), &result
, &nread
);
758 if (!NT_STATUS_IS_OK(status
)) {
759 printf("smb2cli_read returned %s\n", nt_errstr(status
));
763 if (nread
!= strlen(hello
)) {
764 printf("smb2cli_read returned %d bytes, expected %d\n",
765 (int)nread
, (int)strlen(hello
));
769 if (memcmp(hello
, result
, nread
) != 0) {
770 printf("smb2cli_read returned '%s', expected '%s'\n",
775 /* check behaviour with wrong tid... */
779 status
= smb2cli_read(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
780 cli
->smb2
.tid
, 0x10000, 0, fid_persistent
,
782 talloc_tos(), &result
, &nread
);
783 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
784 printf("smb2cli_read returned %s\n", nt_errstr(status
));
793 bool run_smb2_multi_channel(int dummy
)
795 struct cli_state
*cli1
;
796 struct cli_state
*cli2
;
797 struct cli_state
*cli3
;
800 uint64_t fid_persistent
, fid_volatile
;
801 struct tevent_context
*ev
;
802 struct tevent_req
*subreq
;
803 DATA_BLOB in_blob
= data_blob_null
;
805 DATA_BLOB channel_session_key
;
806 struct auth_generic_state
*auth_generic_state
;
807 struct iovec
*recv_iov
;
808 const char *hello
= "Hello, world\n";
812 printf("Starting SMB2-MULTI-CHANNEL\n");
814 if (!torture_init_connection(&cli1
)) {
817 cli1
->smb2
.pid
= 0xFEFF;
819 if (!torture_init_connection(&cli2
)) {
822 cli2
->smb2
.pid
= 0xFEFF;
824 if (!torture_init_connection(&cli3
)) {
827 cli3
->smb2
.pid
= 0xFEFF;
829 status
= smbXcli_negprot(cli1
->conn
, cli1
->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
= smbXcli_negprot(cli2
->conn
, cli2
->timeout
,
837 PROTOCOL_SMB2_22
, PROTOCOL_LATEST
);
838 if (!NT_STATUS_IS_OK(status
)) {
839 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
843 status
= smbXcli_negprot(cli3
->conn
, cli3
->timeout
,
844 PROTOCOL_SMB2_22
, PROTOCOL_LATEST
);
845 if (!NT_STATUS_IS_OK(status
)) {
846 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
850 status
= cli_session_setup(cli1
, username
,
851 password
, strlen(password
),
852 password
, strlen(password
),
854 if (!NT_STATUS_IS_OK(status
)) {
855 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status
));
859 status
= cli_tree_connect(cli1
, share
, "?????", "", 0);
860 if (!NT_STATUS_IS_OK(status
)) {
861 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
865 status
= smb2cli_session_create_channel(cli2
,
868 &cli2
->smb2
.session
);
869 if (!NT_STATUS_IS_OK(status
)) {
870 printf("smb2cli_session_create_channel returned %s\n",
875 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
876 if (!NT_STATUS_IS_OK(status
)) {
877 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
881 gensec_want_feature(auth_generic_state
->gensec_security
,
882 GENSEC_FEATURE_SESSION_KEY
);
883 status
= auth_generic_set_username(auth_generic_state
, username
);
884 if (!NT_STATUS_IS_OK(status
)) {
885 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
889 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
890 if (!NT_STATUS_IS_OK(status
)) {
891 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
895 status
= auth_generic_set_password(auth_generic_state
, password
);
896 if (!NT_STATUS_IS_OK(status
)) {
897 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
901 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
902 if (!NT_STATUS_IS_OK(status
)) {
903 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
907 ev
= event_context_init(talloc_tos());
909 printf("event_context_init() returned NULL\n");
913 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, data_blob_null
, &in_blob
);
914 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
915 printf("gensec_update returned %s\n", nt_errstr(status
));
919 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
924 SMB2_CAP_DFS
, /* in_capabilities */
926 0, /* in_previous_session_id */
927 &in_blob
); /* in_security_buffer */
928 if (subreq
== NULL
) {
929 printf("smb2cli_session_setup_send() returned NULL\n");
933 ok
= tevent_req_poll(subreq
, ev
);
935 printf("tevent_req_poll() returned false\n");
939 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
941 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
942 printf("smb2cli_session_setup_recv returned %s\n",
947 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, out_blob
, &in_blob
);
948 if (!NT_STATUS_IS_OK(status
)) {
949 printf("auth_generic_update returned %s\n", nt_errstr(status
));
953 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
958 SMB2_CAP_DFS
, /* in_capabilities */
960 0, /* in_previous_session_id */
961 &in_blob
); /* in_security_buffer */
962 if (subreq
== NULL
) {
963 printf("smb2cli_session_setup_send() returned NULL\n");
967 ok
= tevent_req_poll(subreq
, ev
);
969 printf("tevent_req_poll() returned false\n");
973 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
974 &recv_iov
, &out_blob
);
975 if (!NT_STATUS_IS_OK(status
)) {
976 printf("smb2cli_session_setup_recv returned %s\n",
981 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
982 &channel_session_key
);
983 if (!NT_STATUS_IS_OK(status
)) {
984 printf("gensec_session_key returned %s\n",
989 status
= smb2cli_session_set_channel_key(cli2
->smb2
.session
,
992 if (!NT_STATUS_IS_OK(status
)) {
993 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status
));
997 cli2
->smb2
.tid
= cli1
->smb2
.tid
;
999 status
= smb2cli_session_create_channel(cli3
,
1002 &cli3
->smb2
.session
);
1003 if (!NT_STATUS_IS_OK(status
)) {
1004 printf("smb2cli_session_create_channel returned %s\n",
1009 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1010 if (!NT_STATUS_IS_OK(status
)) {
1011 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1015 gensec_want_feature(auth_generic_state
->gensec_security
,
1016 GENSEC_FEATURE_SESSION_KEY
);
1017 status
= auth_generic_set_username(auth_generic_state
, username
);
1018 if (!NT_STATUS_IS_OK(status
)) {
1019 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
1023 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
1024 if (!NT_STATUS_IS_OK(status
)) {
1025 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
1029 status
= auth_generic_set_password(auth_generic_state
, password
);
1030 if (!NT_STATUS_IS_OK(status
)) {
1031 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
1035 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1036 if (!NT_STATUS_IS_OK(status
)) {
1037 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1041 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, data_blob_null
, &in_blob
);
1042 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1043 printf("gensec_update returned %s\n", nt_errstr(status
));
1047 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1051 0x01, /* in_flags */
1052 SMB2_CAP_DFS
, /* in_capabilities */
1054 0, /* in_previous_session_id */
1055 &in_blob
); /* in_security_buffer */
1056 if (subreq
== NULL
) {
1057 printf("smb2cli_session_setup_send() returned NULL\n");
1061 ok
= tevent_req_poll(subreq
, ev
);
1063 printf("tevent_req_poll() returned false\n");
1067 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1069 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1070 printf("smb2cli_session_setup_recv returned %s\n",
1075 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, out_blob
, &in_blob
);
1076 if (!NT_STATUS_IS_OK(status
)) {
1077 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1081 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1085 0x01, /* in_flags */
1086 SMB2_CAP_DFS
, /* in_capabilities */
1088 0, /* in_previous_session_id */
1089 &in_blob
); /* in_security_buffer */
1090 if (subreq
== NULL
) {
1091 printf("smb2cli_session_setup_send() returned NULL\n");
1095 ok
= tevent_req_poll(subreq
, ev
);
1097 printf("tevent_req_poll() returned false\n");
1101 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1102 &recv_iov
, &out_blob
);
1103 if (!NT_STATUS_IS_OK(status
)) {
1104 printf("smb2cli_session_setup_recv returned %s\n",
1109 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
1110 &channel_session_key
);
1111 if (!NT_STATUS_IS_OK(status
)) {
1112 printf("gensec_session_key returned %s\n",
1117 status
= smb2cli_session_set_channel_key(cli3
->smb2
.session
,
1118 channel_session_key
,
1120 if (!NT_STATUS_IS_OK(status
)) {
1121 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status
));
1125 cli3
->smb2
.tid
= cli2
->smb2
.tid
;
1127 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1128 cli2
->smb2
.tid
, "multi-channel.txt",
1129 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1130 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1131 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1132 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1133 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1134 FILE_CREATE
, /* create_disposition, */
1135 FILE_DELETE_ON_CLOSE
, /* create_options, */
1136 NULL
, /* smb2_create_blobs *blobs */
1139 if (!NT_STATUS_IS_OK(status
)) {
1140 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
1144 status
= smb2cli_write(cli1
, strlen(hello
), 0, fid_persistent
,
1145 fid_volatile
, 0, 0, (const uint8_t *)hello
);
1146 if (!NT_STATUS_IS_OK(status
)) {
1147 printf("smb2cli_write returned %s\n", nt_errstr(status
));
1151 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1152 cli2
->smb2
.tid
, fid_persistent
, fid_volatile
);
1153 if (!NT_STATUS_IS_OK(status
)) {
1154 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1158 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1159 cli1
->smb2
.tid
, fid_persistent
, fid_volatile
);
1160 if (!NT_STATUS_IS_OK(status
)) {
1161 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1165 status
= smb2cli_flush(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1166 cli3
->smb2
.tid
, fid_persistent
, fid_volatile
);
1167 if (!NT_STATUS_IS_OK(status
)) {
1168 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1172 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1173 cli2
->smb2
.tid
, 0x10000, 0, fid_persistent
,
1175 talloc_tos(), &result
, &nread
);
1176 if (!NT_STATUS_IS_OK(status
)) {
1177 printf("smb2cli_read returned %s\n", nt_errstr(status
));
1181 if (nread
!= strlen(hello
)) {
1182 printf("smb2cli_read returned %d bytes, expected %d\n",
1183 (int)nread
, (int)strlen(hello
));
1187 if (memcmp(hello
, result
, nread
) != 0) {
1188 printf("smb2cli_read returned '%s', expected '%s'\n",
1193 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1194 if (!NT_STATUS_IS_OK(status
)) {
1195 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1199 gensec_want_feature(auth_generic_state
->gensec_security
,
1200 GENSEC_FEATURE_SESSION_KEY
);
1201 status
= auth_generic_set_username(auth_generic_state
, username
);
1202 if (!NT_STATUS_IS_OK(status
)) {
1203 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
1207 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
1208 if (!NT_STATUS_IS_OK(status
)) {
1209 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
1213 status
= auth_generic_set_password(auth_generic_state
, password
);
1214 if (!NT_STATUS_IS_OK(status
)) {
1215 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
1219 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1220 if (!NT_STATUS_IS_OK(status
)) {
1221 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1225 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, data_blob_null
, &in_blob
);
1226 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1227 printf("gensec_update returned %s\n", nt_errstr(status
));
1231 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1236 SMB2_CAP_DFS
, /* in_capabilities */
1238 0, /* in_previous_session_id */
1239 &in_blob
); /* in_security_buffer */
1240 if (subreq
== NULL
) {
1241 printf("smb2cli_session_setup_send() returned NULL\n");
1245 ok
= tevent_req_poll(subreq
, ev
);
1247 printf("tevent_req_poll() returned false\n");
1251 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1253 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1254 printf("smb2cli_session_setup_recv returned %s\n",
1259 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, out_blob
, &in_blob
);
1260 if (!NT_STATUS_IS_OK(status
)) {
1261 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1265 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1266 cli1
->smb2
.tid
, fid_persistent
, fid_volatile
);
1267 if (!NT_STATUS_IS_OK(status
)) {
1268 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1272 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1273 cli2
->smb2
.tid
, fid_persistent
, fid_volatile
);
1274 if (!NT_STATUS_IS_OK(status
)) {
1275 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1279 status
= smb2cli_flush(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1280 cli3
->smb2
.tid
, fid_persistent
, fid_volatile
);
1281 if (!NT_STATUS_IS_OK(status
)) {
1282 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1286 status
= smb2cli_create(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1287 cli1
->smb2
.tid
, "multi-channel-invalid.txt",
1288 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1289 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1290 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1291 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1292 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1293 FILE_CREATE
, /* create_disposition, */
1294 FILE_DELETE_ON_CLOSE
, /* create_options, */
1295 NULL
, /* smb2_create_blobs *blobs */
1298 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1299 printf("smb2cli_create %s\n", nt_errstr(status
));
1303 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1304 cli2
->smb2
.tid
, "multi-channel-invalid.txt",
1305 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1306 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1307 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1308 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1309 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1310 FILE_CREATE
, /* create_disposition, */
1311 FILE_DELETE_ON_CLOSE
, /* create_options, */
1312 NULL
, /* smb2_create_blobs *blobs */
1315 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1316 printf("smb2cli_create %s\n", nt_errstr(status
));
1320 status
= smb2cli_create(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1321 cli3
->smb2
.tid
, "multi-channel-invalid.txt",
1322 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1323 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1324 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1325 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1326 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1327 FILE_CREATE
, /* create_disposition, */
1328 FILE_DELETE_ON_CLOSE
, /* create_options, */
1329 NULL
, /* smb2_create_blobs *blobs */
1332 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1333 printf("smb2cli_create %s\n", nt_errstr(status
));
1337 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1342 SMB2_CAP_DFS
, /* in_capabilities */
1344 0, /* in_previous_session_id */
1345 &in_blob
); /* in_security_buffer */
1346 if (subreq
== NULL
) {
1347 printf("smb2cli_session_setup_send() returned NULL\n");
1351 ok
= tevent_req_poll(subreq
, ev
);
1353 printf("tevent_req_poll() returned false\n");
1357 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1358 &recv_iov
, &out_blob
);
1359 if (!NT_STATUS_IS_OK(status
)) {
1360 printf("smb2cli_session_setup_recv returned %s\n",
1365 status
= smb2cli_close(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1366 cli3
->smb2
.tid
, 0, fid_persistent
, fid_volatile
);
1367 if (!NT_STATUS_IS_OK(status
)) {
1368 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1372 status
= smb2cli_flush(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1373 cli3
->smb2
.tid
, fid_persistent
, fid_volatile
);
1374 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1375 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1379 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1380 cli2
->smb2
.tid
, fid_persistent
, fid_volatile
);
1381 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1382 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1386 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1387 cli1
->smb2
.tid
, fid_persistent
, fid_volatile
);
1388 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1389 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1396 bool run_smb2_session_reauth(int dummy
)
1398 struct cli_state
*cli
;
1401 uint64_t fid_persistent
, fid_volatile
;
1402 uint64_t dir_persistent
, dir_volatile
;
1404 uint32_t dir_data_length
;
1405 struct tevent_context
*ev
;
1406 struct tevent_req
*subreq
;
1407 DATA_BLOB in_blob
= data_blob_null
;
1409 DATA_BLOB in_input_buffer
;
1410 DATA_BLOB out_output_buffer
;
1411 uint8_t in_file_info_class
;
1412 struct auth_generic_state
*auth_generic_state
;
1413 struct iovec
*recv_iov
;
1416 printf("Starting SMB2-SESSION_REAUTH\n");
1418 if (!torture_init_connection(&cli
)) {
1421 cli
->smb2
.pid
= 0xFEFF;
1424 * PROTOCOL_SMB2_22 has a bug in win8pre0
1425 * it behaves like PROTOCOL_SMB2_02
1426 * and returns NT_STATUS_REQUEST_NOT_ACCEPTED,
1427 * while it allows it on PROTOCOL_SMB2_02.
1429 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
1430 PROTOCOL_SMB2_10
, PROTOCOL_SMB2_10
);
1431 if (!NT_STATUS_IS_OK(status
)) {
1432 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
1436 status
= cli_session_setup(cli
, username
,
1437 password
, strlen(password
),
1438 password
, strlen(password
),
1440 if (!NT_STATUS_IS_OK(status
)) {
1441 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status
));
1445 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
1446 if (!NT_STATUS_IS_OK(status
)) {
1447 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1451 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1452 cli
->smb2
.tid
, "session-reauth.txt",
1453 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1454 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1455 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1456 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1457 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1458 FILE_CREATE
, /* create_disposition, */
1459 FILE_DELETE_ON_CLOSE
, /* create_options, */
1460 NULL
, /* smb2_create_blobs *blobs */
1463 if (!NT_STATUS_IS_OK(status
)) {
1464 printf("smb2cli_create %s\n", nt_errstr(status
));
1468 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1470 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1471 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1472 SEC_STD_SYNCHRONIZE
|
1474 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
1475 0, /* file_attributes, */
1476 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1477 FILE_OPEN
, /* create_disposition, */
1478 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
1479 NULL
, /* smb2_create_blobs *blobs */
1482 if (!NT_STATUS_IS_OK(status
)) {
1483 printf("smb2cli_create returned %s\n", nt_errstr(status
));
1487 status
= smb2cli_query_directory(
1488 cli
, 1, 0x3, 0, dir_persistent
, dir_volatile
,
1489 "session-reauth.txt", 0xffff,
1490 talloc_tos(), &dir_data
, &dir_data_length
);
1491 if (!NT_STATUS_IS_OK(status
)) {
1492 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1496 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1497 if (!NT_STATUS_IS_OK(status
)) {
1498 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1502 gensec_want_feature(auth_generic_state
->gensec_security
,
1503 GENSEC_FEATURE_SESSION_KEY
);
1504 status
= auth_generic_set_username(auth_generic_state
, username
);
1505 if (!NT_STATUS_IS_OK(status
)) {
1506 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
1510 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
1511 if (!NT_STATUS_IS_OK(status
)) {
1512 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
1516 status
= auth_generic_set_password(auth_generic_state
, password
);
1517 if (!NT_STATUS_IS_OK(status
)) {
1518 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
1522 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1523 if (!NT_STATUS_IS_OK(status
)) {
1524 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1528 ev
= event_context_init(talloc_tos());
1530 printf("event_context_init() returned NULL\n");
1534 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, data_blob_null
, &in_blob
);
1535 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1536 printf("gensec_update returned %s\n", nt_errstr(status
));
1540 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1545 SMB2_CAP_DFS
, /* in_capabilities */
1547 0, /* in_previous_session_id */
1548 &in_blob
); /* in_security_buffer */
1549 if (subreq
== NULL
) {
1550 printf("smb2cli_session_setup_send() returned NULL\n");
1554 ok
= tevent_req_poll(subreq
, ev
);
1556 printf("tevent_req_poll() returned false\n");
1560 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1562 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1563 printf("smb2cli_session_setup_recv returned %s\n",
1568 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, out_blob
, &in_blob
);
1569 if (!NT_STATUS_IS_OK(status
)) {
1570 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1574 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1575 cli
->smb2
.tid
, fid_persistent
, fid_volatile
);
1576 if (!NT_STATUS_IS_OK(status
)) {
1577 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1581 status
= smb2cli_query_directory(
1582 cli
, 1, 0x3, 0, dir_persistent
, dir_volatile
,
1583 "session-reauth.txt", 0xffff,
1584 talloc_tos(), &dir_data
, &dir_data_length
);
1585 if (!NT_STATUS_IS_OK(status
)) {
1586 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1591 * query_info seems to be a path based operation on Windows...
1593 status
= smb2cli_query_info(cli
->conn
,
1597 SMB2_GETINFO_SECURITY
,
1598 0, /* in_file_info_class */
1599 1024, /* in_max_output_length */
1600 NULL
, /* in_input_buffer */
1601 SECINFO_OWNER
, /* in_additional_info */
1606 &out_output_buffer
);
1607 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1608 printf("smb2cli_query_info (security) returned %s\n", nt_errstr(status
));
1612 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1613 status
= smb2cli_query_info(cli
->conn
,
1619 1024, /* in_max_output_length */
1620 NULL
, /* in_input_buffer */
1621 0, /* in_additional_info */
1626 &out_output_buffer
);
1627 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1628 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1632 in_input_buffer
= data_blob_talloc(talloc_tos(), NULL
, 8);
1633 SBVAL(in_input_buffer
.data
, 0, 512);
1635 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1636 status
= smb2cli_set_info(cli
->conn
,
1643 0, /* in_additional_info */
1646 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1647 printf("smb2cli_set_info (position) returned %s\n", nt_errstr(status
));
1651 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1652 cli
->smb2
.tid
, "session-reauth-invalid.txt",
1653 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1654 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1655 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1656 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1657 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1658 FILE_CREATE
, /* create_disposition, */
1659 FILE_DELETE_ON_CLOSE
, /* create_options, */
1660 NULL
, /* smb2_create_blobs *blobs */
1663 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1664 printf("smb2cli_create %s\n", nt_errstr(status
));
1668 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1670 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1671 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1672 SEC_STD_SYNCHRONIZE
|
1674 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
1675 0, /* file_attributes, */
1676 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1677 FILE_OPEN
, /* create_disposition, */
1678 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
1679 NULL
, /* smb2_create_blobs *blobs */
1682 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1683 printf("smb2cli_create returned %s\n", nt_errstr(status
));
1687 saved_tid
= cli
->smb2
.tid
;
1688 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
1689 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1690 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1693 cli
->smb2
.tid
= saved_tid
;
1695 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1700 SMB2_CAP_DFS
, /* in_capabilities */
1702 0, /* in_previous_session_id */
1703 &in_blob
); /* in_security_buffer */
1704 if (subreq
== NULL
) {
1705 printf("smb2cli_session_setup_send() returned NULL\n");
1709 ok
= tevent_req_poll(subreq
, ev
);
1711 printf("tevent_req_poll() returned false\n");
1715 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1716 &recv_iov
, &out_blob
);
1717 if (!NT_STATUS_IS_OK(status
)) {
1718 printf("smb2cli_session_setup_recv returned %s\n",
1723 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1724 cli
->smb2
.tid
, fid_persistent
, fid_volatile
);
1725 if (!NT_STATUS_IS_OK(status
)) {
1726 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1730 status
= smb2cli_query_info(cli
->conn
,
1734 SMB2_GETINFO_SECURITY
,
1735 0, /* in_file_info_class */
1736 1024, /* in_max_output_length */
1737 NULL
, /* in_input_buffer */
1738 SECINFO_OWNER
, /* in_additional_info */
1743 &out_output_buffer
);
1744 if (!NT_STATUS_IS_OK(status
)) {
1745 printf("smb2cli_query_info (security) returned %s\n", nt_errstr(status
));
1749 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1750 status
= smb2cli_query_info(cli
->conn
,
1756 1024, /* in_max_output_length */
1757 NULL
, /* in_input_buffer */
1758 0, /* in_additional_info */
1763 &out_output_buffer
);
1764 if (!NT_STATUS_IS_OK(status
)) {
1765 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1769 in_input_buffer
= data_blob_talloc(talloc_tos(), NULL
, 8);
1770 SBVAL(in_input_buffer
.data
, 0, 512);
1772 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1773 status
= smb2cli_set_info(cli
->conn
,
1780 0, /* in_additional_info */
1783 if (!NT_STATUS_IS_OK(status
)) {
1784 printf("smb2cli_set_info (position) returned %s\n", nt_errstr(status
));
1788 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1789 status
= smb2cli_query_info(cli
->conn
,
1795 1024, /* in_max_output_length */
1796 NULL
, /* in_input_buffer */
1797 0, /* in_additional_info */
1802 &out_output_buffer
);
1803 if (!NT_STATUS_IS_OK(status
)) {
1804 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1808 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1809 cli
->smb2
.tid
, 0, fid_persistent
, fid_volatile
);
1810 if (!NT_STATUS_IS_OK(status
)) {
1811 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1815 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1816 cli
->smb2
.tid
, "session-reauth.txt",
1817 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1818 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1819 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1820 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1821 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1822 FILE_CREATE
, /* create_disposition, */
1823 FILE_DELETE_ON_CLOSE
, /* create_options, */
1824 NULL
, /* smb2_create_blobs *blobs */
1827 if (!NT_STATUS_IS_OK(status
)) {
1828 printf("smb2cli_create %s\n", nt_errstr(status
));
1832 status
= smb2cli_query_directory(
1833 cli
, 1, 0x3, 0, dir_persistent
, dir_volatile
,
1834 "session-reauth.txt", 0xffff,
1835 talloc_tos(), &dir_data
, &dir_data_length
);
1836 if (!NT_STATUS_IS_OK(status
)) {
1837 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1841 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1842 cli
->smb2
.tid
, 0, dir_persistent
, dir_volatile
);
1843 if (!NT_STATUS_IS_OK(status
)) {
1844 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1848 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1849 cli
->smb2
.tid
, 0, fid_persistent
, fid_volatile
);
1850 if (!NT_STATUS_IS_OK(status
)) {
1851 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1855 saved_tid
= cli
->smb2
.tid
;
1856 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
1857 if (!NT_STATUS_IS_OK(status
)) {
1858 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1861 cli
->smb2
.tid
= saved_tid
;