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 struct smbXcli_tcon
*saved_tcon
= NULL
;
45 uint64_t saved_uid
= 0;
47 printf("Starting SMB2-BASIC\n");
49 if (!torture_init_connection(&cli
)) {
53 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
54 PROTOCOL_SMB2_02
, PROTOCOL_SMB2_02
);
55 if (!NT_STATUS_IS_OK(status
)) {
56 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
60 status
= cli_session_setup(cli
, username
,
61 password
, strlen(password
),
62 password
, strlen(password
),
64 if (!NT_STATUS_IS_OK(status
)) {
65 printf("cli_session_setup returned %s\n", nt_errstr(status
));
69 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
70 if (!NT_STATUS_IS_OK(status
)) {
71 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
75 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
76 cli
->smb2
.tcon
, "smb2-basic.txt",
77 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
78 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
79 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
80 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
81 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
82 FILE_CREATE
, /* create_disposition, */
83 FILE_DELETE_ON_CLOSE
, /* create_options, */
84 NULL
, /* smb2_create_blobs *blobs */
88 if (!NT_STATUS_IS_OK(status
)) {
89 printf("smb2cli_create returned %s\n", nt_errstr(status
));
93 status
= smb2cli_write(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
94 cli
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
95 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
96 if (!NT_STATUS_IS_OK(status
)) {
97 printf("smb2cli_write returned %s\n", nt_errstr(status
));
101 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
102 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
103 if (!NT_STATUS_IS_OK(status
)) {
104 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
108 status
= smb2cli_read(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
109 cli
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
111 talloc_tos(), &result
, &nread
);
112 if (!NT_STATUS_IS_OK(status
)) {
113 printf("smb2cli_read returned %s\n", nt_errstr(status
));
117 if (nread
!= strlen(hello
)) {
118 printf("smb2cli_read returned %d bytes, expected %d\n",
119 (int)nread
, (int)strlen(hello
));
123 if (memcmp(hello
, result
, nread
) != 0) {
124 printf("smb2cli_read returned '%s', expected '%s'\n",
129 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
130 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
131 if (!NT_STATUS_IS_OK(status
)) {
132 printf("smb2cli_close returned %s\n", nt_errstr(status
));
136 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
138 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
139 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
142 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
143 0, /* file_attributes, */
144 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
145 FILE_OPEN
, /* create_disposition, */
146 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
147 NULL
, /* smb2_create_blobs *blobs */
151 if (!NT_STATUS_IS_OK(status
)) {
152 printf("smb2cli_create returned %s\n", nt_errstr(status
));
156 status
= smb2cli_query_directory(
157 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
158 1, 0, 0, fid_persistent
, fid_volatile
, "*", 0xffff,
159 talloc_tos(), &dir_data
, &dir_data_length
);
161 if (!NT_STATUS_IS_OK(status
)) {
162 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
166 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
167 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
168 if (!NT_STATUS_IS_OK(status
)) {
169 printf("smb2cli_close returned %s\n", nt_errstr(status
));
173 saved_tid
= smb2cli_tcon_current_id(cli
->smb2
.tcon
);
174 saved_tcon
= cli
->smb2
.tcon
;
175 cli
->smb2
.tcon
= smbXcli_tcon_create(cli
);
176 smb2cli_tcon_set_values(cli
->smb2
.tcon
,
181 0, /* capabilities */
182 0 /* maximal_access */);
183 status
= smb2cli_tdis(cli
);
184 if (!NT_STATUS_IS_OK(status
)) {
185 printf("smb2cli_tdis returned %s\n", nt_errstr(status
));
188 talloc_free(cli
->smb2
.tcon
);
189 cli
->smb2
.tcon
= saved_tcon
;
191 status
= smb2cli_tdis(cli
);
192 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
193 printf("2nd smb2cli_tdis returned %s\n", nt_errstr(status
));
197 saved_uid
= smb2cli_session_current_id(cli
->smb2
.session
);
198 status
= smb2cli_logoff(cli
->conn
, cli
->timeout
, cli
->smb2
.session
);
199 if (!NT_STATUS_IS_OK(status
)) {
200 printf("smb2cli_logoff returned %s\n", nt_errstr(status
));
204 cli
->smb2
.session
= smbXcli_session_create(cli
, cli
->conn
);
205 if (cli
->smb2
.session
== NULL
) {
206 printf("smbXcli_session_create() returned NULL\n");
210 smb2cli_session_set_id_and_flags(cli
->smb2
.session
, saved_uid
, 0);
212 status
= smb2cli_logoff(cli
->conn
, cli
->timeout
, cli
->smb2
.session
);
213 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
214 printf("2nd smb2cli_logoff returned %s\n", nt_errstr(status
));
221 bool run_smb2_negprot(int dummy
)
223 struct cli_state
*cli
;
225 enum protocol_types protocol
;
226 const char *name
= NULL
;
228 printf("Starting SMB2-NEGPROT\n");
230 if (!torture_init_connection(&cli
)) {
234 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
235 PROTOCOL_CORE
, PROTOCOL_LATEST
);
236 if (!NT_STATUS_IS_OK(status
)) {
237 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
241 protocol
= smbXcli_conn_protocol(cli
->conn
);
244 case PROTOCOL_SMB2_02
:
247 case PROTOCOL_SMB2_10
:
250 case PROTOCOL_SMB2_22
:
253 case PROTOCOL_SMB2_24
:
256 case PROTOCOL_SMB3_00
:
259 case PROTOCOL_SMB3_02
:
267 printf("Server supports %s\n", name
);
269 printf("Server DOES NOT support SMB2\n");
273 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
275 if (!NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_RESET
) &&
276 !NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_DISCONNECTED
) &&
277 !NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_ABORTED
)) {
278 printf("2nd smbXcli_negprot should disconnect - returned %s\n",
283 if (smbXcli_conn_is_connected(cli
->conn
)) {
284 printf("2nd smbXcli_negprot should disconnect "
285 "- still connected\n");
292 bool run_smb2_session_reconnect(int dummy
)
294 struct cli_state
*cli1
;
295 struct cli_state
*cli2
;
298 uint64_t fid_persistent
, fid_volatile
;
299 struct tevent_context
*ev
;
300 struct tevent_req
*subreq
;
301 DATA_BLOB in_blob
= data_blob_null
;
303 DATA_BLOB session_key
;
304 struct auth_generic_state
*auth_generic_state
;
305 struct iovec
*recv_iov
;
306 const char *hello
= "Hello, world\n";
310 printf("Starting SMB2-SESSION-RECONNECT\n");
312 if (!torture_init_connection(&cli1
)) {
316 status
= smbXcli_negprot(cli1
->conn
, cli1
->timeout
,
317 PROTOCOL_SMB2_02
, PROTOCOL_LATEST
);
318 if (!NT_STATUS_IS_OK(status
)) {
319 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
323 status
= cli_session_setup(cli1
, username
,
324 password
, strlen(password
),
325 password
, strlen(password
),
327 if (!NT_STATUS_IS_OK(status
)) {
328 printf("cli_session_setup returned %s\n", nt_errstr(status
));
332 status
= cli_tree_connect(cli1
, share
, "?????", "", 0);
333 if (!NT_STATUS_IS_OK(status
)) {
334 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
338 status
= smb2cli_create(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
339 cli1
->smb2
.tcon
, "session-reconnect.txt",
340 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
341 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
342 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
343 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
344 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
345 FILE_CREATE
, /* create_disposition, */
346 FILE_DELETE_ON_CLOSE
, /* create_options, */
347 NULL
, /* smb2_create_blobs *blobs */
351 if (!NT_STATUS_IS_OK(status
)) {
352 printf("smb2cli_create on cli1 %s\n", nt_errstr(status
));
356 status
= smb2cli_write(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
357 cli1
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
358 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
359 if (!NT_STATUS_IS_OK(status
)) {
360 printf("smb2cli_write returned %s\n", nt_errstr(status
));
364 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
365 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
366 if (!NT_STATUS_IS_OK(status
)) {
367 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
371 status
= smb2cli_read(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
372 cli1
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
374 talloc_tos(), &result
, &nread
);
375 if (!NT_STATUS_IS_OK(status
)) {
376 printf("smb2cli_read returned %s\n", nt_errstr(status
));
380 if (nread
!= strlen(hello
)) {
381 printf("smb2cli_read returned %d bytes, expected %d\n",
382 (int)nread
, (int)strlen(hello
));
386 if (memcmp(hello
, result
, nread
) != 0) {
387 printf("smb2cli_read returned '%s', expected '%s'\n",
392 /* prepare second session */
394 if (!torture_init_connection(&cli2
)) {
398 status
= smbXcli_negprot(cli2
->conn
, cli2
->timeout
,
399 PROTOCOL_SMB2_02
, PROTOCOL_LATEST
);
400 if (!NT_STATUS_IS_OK(status
)) {
401 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
405 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
406 if (!NT_STATUS_IS_OK(status
)) {
407 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
411 gensec_want_feature(auth_generic_state
->gensec_security
,
412 GENSEC_FEATURE_SESSION_KEY
);
413 status
= auth_generic_set_username(auth_generic_state
, username
);
414 if (!NT_STATUS_IS_OK(status
)) {
415 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
419 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
420 if (!NT_STATUS_IS_OK(status
)) {
421 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
425 status
= auth_generic_set_password(auth_generic_state
, password
);
426 if (!NT_STATUS_IS_OK(status
)) {
427 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
431 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
432 if (!NT_STATUS_IS_OK(status
)) {
433 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
437 ev
= samba_tevent_context_init(talloc_tos());
439 printf("samba_tevent_context_init() returned NULL\n");
443 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, data_blob_null
, &in_blob
);
444 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
445 printf("gensec_update returned %s\n", nt_errstr(status
));
449 cli2
->smb2
.session
= smbXcli_session_create(cli2
, cli2
->conn
);
451 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
456 SMB2_CAP_DFS
, /* in_capabilities */
458 /* in_previous_session_id: */
459 smb2cli_session_current_id(cli1
->smb2
.session
),
460 &in_blob
); /* in_security_buffer */
461 if (subreq
== NULL
) {
462 printf("smb2cli_session_setup_send() returned NULL\n");
466 ok
= tevent_req_poll(subreq
, ev
);
468 printf("tevent_req_poll() returned false\n");
472 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
474 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
475 printf("smb2cli_session_setup_recv returned %s\n",
480 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, out_blob
, &in_blob
);
481 if (!NT_STATUS_IS_OK(status
)) {
482 printf("auth_generic_update returned %s\n", nt_errstr(status
));
486 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
491 SMB2_CAP_DFS
, /* in_capabilities */
493 /* in_previous_session_id: */
494 smb2cli_session_current_id(cli1
->smb2
.session
),
495 &in_blob
); /* in_security_buffer */
496 if (subreq
== NULL
) {
497 printf("smb2cli_session_setup_send() returned NULL\n");
501 ok
= tevent_req_poll(subreq
, ev
);
503 printf("tevent_req_poll() returned false\n");
507 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
508 &recv_iov
, &out_blob
);
509 if (!NT_STATUS_IS_OK(status
)) {
510 printf("smb2cli_session_setup_recv returned %s\n",
515 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
517 if (!NT_STATUS_IS_OK(status
)) {
518 printf("gensec_session_key returned %s\n",
523 /* check file operation on the old client */
525 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
526 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
527 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
528 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
532 status
= cli_tree_connect(cli1
, share
, "?????", "", 0);
533 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
534 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
539 * checking file operations without signing.
540 * on w2k8r2 at least, flush, read and write also work the same way,
541 * while create gives ACCESS_DENIED without signing
543 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
544 cli2
->smb2
.tcon
, fid_persistent
, fid_volatile
);
545 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
546 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
548 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
552 status
= smb2cli_write(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
553 cli2
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
554 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
555 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
556 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
558 printf("smb2cli_write returned %s\n", nt_errstr(status
));
562 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
563 cli2
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
565 talloc_tos(), &result
, &nread
);
566 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
567 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
569 printf("smb2cli_read returned %s\n", nt_errstr(status
));
573 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
574 cli2
->smb2
.tcon
, "session-reconnect.txt",
575 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
576 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
577 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
578 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
579 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
580 FILE_CREATE
, /* create_disposition, */
581 FILE_DELETE_ON_CLOSE
, /* create_options, */
582 NULL
, /* smb2_create_blobs *blobs */
586 if (!NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
) &&
587 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
588 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
592 /* now grab the session key and try with signing */
594 status
= smb2cli_session_set_session_key(cli2
->smb2
.session
,
597 if (!NT_STATUS_IS_OK(status
)) {
598 printf("smb2cli_session_set_session_key %s\n", nt_errstr(status
));
602 /* the tid seems to be irrelevant at this stage */
604 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
605 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
606 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
607 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
609 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
613 status
= smb2cli_write(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
614 cli1
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
615 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
616 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
617 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
619 printf("smb2cli_write returned %s\n", nt_errstr(status
));
623 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
624 cli1
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
626 talloc_tos(), &result
, &nread
);
627 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
628 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
630 printf("smb2cli_read returned %s\n", nt_errstr(status
));
634 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
635 cli1
->smb2
.tcon
, "session-reconnect.txt",
636 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
637 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
638 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
639 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
640 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
641 FILE_CREATE
, /* create_disposition, */
642 FILE_DELETE_ON_CLOSE
, /* create_options, */
643 NULL
, /* smb2_create_blobs *blobs */
647 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
) &&
648 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
650 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
654 /* now do a new tcon and test file calls again */
656 status
= cli_tree_connect(cli2
, share
, "?????", "", 0);
657 if (!NT_STATUS_IS_OK(status
)) {
658 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
662 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
663 cli2
->smb2
.tcon
, "session-reconnect.txt",
664 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
665 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
666 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
667 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
668 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
669 FILE_CREATE
, /* create_disposition, */
670 FILE_DELETE_ON_CLOSE
, /* create_options, */
671 NULL
, /* smb2_create_blobs *blobs */
675 if (!NT_STATUS_IS_OK(status
)) {
676 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
680 status
= smb2cli_write(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
681 cli2
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
682 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
683 if (!NT_STATUS_IS_OK(status
)) {
684 printf("smb2cli_write returned %s\n", nt_errstr(status
));
688 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
689 cli2
->smb2
.tcon
, fid_persistent
, fid_volatile
);
690 if (!NT_STATUS_IS_OK(status
)) {
691 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
695 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
696 cli2
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
698 talloc_tos(), &result
, &nread
);
699 if (!NT_STATUS_IS_OK(status
)) {
700 printf("smb2cli_read returned %s\n", nt_errstr(status
));
704 if (nread
!= strlen(hello
)) {
705 printf("smb2cli_read returned %d bytes, expected %d\n",
706 (int)nread
, (int)strlen(hello
));
710 if (memcmp(hello
, result
, nread
) != 0) {
711 printf("smb2cli_read returned '%s', expected '%s'\n",
719 bool run_smb2_tcon_dependence(int dummy
)
721 struct cli_state
*cli
;
723 uint64_t fid_persistent
, fid_volatile
;
724 const char *hello
= "Hello, world\n";
727 struct smbXcli_tcon
*tcon2
;
730 printf("Starting SMB2-TCON-DEPENDENCE\n");
732 if (!torture_init_connection(&cli
)) {
736 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
737 PROTOCOL_SMB2_02
, PROTOCOL_LATEST
);
738 if (!NT_STATUS_IS_OK(status
)) {
739 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
743 status
= cli_session_setup(cli
, username
,
744 password
, strlen(password
),
745 password
, strlen(password
),
747 if (!NT_STATUS_IS_OK(status
)) {
748 printf("cli_session_setup returned %s\n", nt_errstr(status
));
752 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
753 if (!NT_STATUS_IS_OK(status
)) {
754 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
758 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
759 cli
->smb2
.tcon
, "tcon_depedence.txt",
760 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
761 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
762 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
763 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
764 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
765 FILE_CREATE
, /* create_disposition, */
766 FILE_DELETE_ON_CLOSE
, /* create_options, */
767 NULL
, /* smb2_create_blobs *blobs */
771 if (!NT_STATUS_IS_OK(status
)) {
772 printf("smb2cli_create on cli %s\n", nt_errstr(status
));
776 status
= smb2cli_write(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
777 cli
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
778 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
779 if (!NT_STATUS_IS_OK(status
)) {
780 printf("smb2cli_write returned %s\n", nt_errstr(status
));
784 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
785 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
786 if (!NT_STATUS_IS_OK(status
)) {
787 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
791 status
= smb2cli_read(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
792 cli
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
794 talloc_tos(), &result
, &nread
);
795 if (!NT_STATUS_IS_OK(status
)) {
796 printf("smb2cli_read returned %s\n", nt_errstr(status
));
800 if (nread
!= strlen(hello
)) {
801 printf("smb2cli_read returned %d bytes, expected %d\n",
802 (int)nread
, (int)strlen(hello
));
806 if (memcmp(hello
, result
, nread
) != 0) {
807 printf("smb2cli_read returned '%s', expected '%s'\n",
812 /* check behaviour with wrong tid... */
814 tcon2
= smbXcli_tcon_create(cli
);
815 tcon2_id
= smb2cli_tcon_current_id(cli
->smb2
.tcon
);
817 smb2cli_tcon_set_values(tcon2
,
822 0, /* capabilities */
823 0 /* maximal_access */);
825 status
= smb2cli_read(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
826 tcon2
, 0x10000, 0, fid_persistent
,
828 talloc_tos(), &result
, &nread
);
829 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
830 printf("smb2cli_read returned %s\n", nt_errstr(status
));
839 bool run_smb2_multi_channel(int dummy
)
841 struct cli_state
*cli1
;
842 struct cli_state
*cli2
;
843 struct cli_state
*cli3
;
846 uint64_t fid_persistent
, fid_volatile
;
847 struct tevent_context
*ev
;
848 struct tevent_req
*subreq
;
849 DATA_BLOB in_blob
= data_blob_null
;
851 DATA_BLOB channel_session_key
;
852 struct auth_generic_state
*auth_generic_state
;
853 struct iovec
*recv_iov
;
854 const char *hello
= "Hello, world\n";
858 printf("Starting SMB2-MULTI-CHANNEL\n");
860 if (!torture_init_connection(&cli1
)) {
864 if (!torture_init_connection(&cli2
)) {
868 if (!torture_init_connection(&cli3
)) {
872 status
= smbXcli_negprot(cli1
->conn
, cli1
->timeout
,
873 PROTOCOL_SMB2_22
, PROTOCOL_LATEST
);
874 if (!NT_STATUS_IS_OK(status
)) {
875 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
879 status
= smbXcli_negprot(cli2
->conn
, cli2
->timeout
,
880 PROTOCOL_SMB2_22
, PROTOCOL_LATEST
);
881 if (!NT_STATUS_IS_OK(status
)) {
882 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
886 status
= smbXcli_negprot(cli3
->conn
, cli3
->timeout
,
887 PROTOCOL_SMB2_22
, PROTOCOL_LATEST
);
888 if (!NT_STATUS_IS_OK(status
)) {
889 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
893 status
= cli_session_setup(cli1
, username
,
894 password
, strlen(password
),
895 password
, strlen(password
),
897 if (!NT_STATUS_IS_OK(status
)) {
898 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status
));
902 status
= cli_tree_connect(cli1
, share
, "?????", "", 0);
903 if (!NT_STATUS_IS_OK(status
)) {
904 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
908 status
= smb2cli_session_create_channel(cli2
,
911 &cli2
->smb2
.session
);
912 if (!NT_STATUS_IS_OK(status
)) {
913 printf("smb2cli_session_create_channel returned %s\n",
918 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
919 if (!NT_STATUS_IS_OK(status
)) {
920 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
924 gensec_want_feature(auth_generic_state
->gensec_security
,
925 GENSEC_FEATURE_SESSION_KEY
);
926 status
= auth_generic_set_username(auth_generic_state
, username
);
927 if (!NT_STATUS_IS_OK(status
)) {
928 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
932 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
933 if (!NT_STATUS_IS_OK(status
)) {
934 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
938 status
= auth_generic_set_password(auth_generic_state
, password
);
939 if (!NT_STATUS_IS_OK(status
)) {
940 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
944 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
945 if (!NT_STATUS_IS_OK(status
)) {
946 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
950 ev
= samba_tevent_context_init(talloc_tos());
952 printf("samba_tevent_context_init() returned NULL\n");
956 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, data_blob_null
, &in_blob
);
957 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
958 printf("gensec_update returned %s\n", nt_errstr(status
));
962 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
967 SMB2_CAP_DFS
, /* in_capabilities */
969 0, /* in_previous_session_id */
970 &in_blob
); /* in_security_buffer */
971 if (subreq
== NULL
) {
972 printf("smb2cli_session_setup_send() returned NULL\n");
976 ok
= tevent_req_poll(subreq
, ev
);
978 printf("tevent_req_poll() returned false\n");
982 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
984 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
985 printf("smb2cli_session_setup_recv returned %s\n",
990 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, out_blob
, &in_blob
);
991 if (!NT_STATUS_IS_OK(status
)) {
992 printf("auth_generic_update returned %s\n", nt_errstr(status
));
996 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1000 0x01, /* in_flags */
1001 SMB2_CAP_DFS
, /* in_capabilities */
1003 0, /* in_previous_session_id */
1004 &in_blob
); /* in_security_buffer */
1005 if (subreq
== NULL
) {
1006 printf("smb2cli_session_setup_send() returned NULL\n");
1010 ok
= tevent_req_poll(subreq
, ev
);
1012 printf("tevent_req_poll() returned false\n");
1016 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1017 &recv_iov
, &out_blob
);
1018 if (!NT_STATUS_IS_OK(status
)) {
1019 printf("smb2cli_session_setup_recv returned %s\n",
1024 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
1025 &channel_session_key
);
1026 if (!NT_STATUS_IS_OK(status
)) {
1027 printf("gensec_session_key returned %s\n",
1032 status
= smb2cli_session_set_channel_key(cli2
->smb2
.session
,
1033 channel_session_key
,
1035 if (!NT_STATUS_IS_OK(status
)) {
1036 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status
));
1040 status
= smb2cli_session_create_channel(cli3
,
1043 &cli3
->smb2
.session
);
1044 if (!NT_STATUS_IS_OK(status
)) {
1045 printf("smb2cli_session_create_channel returned %s\n",
1050 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1051 if (!NT_STATUS_IS_OK(status
)) {
1052 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1056 gensec_want_feature(auth_generic_state
->gensec_security
,
1057 GENSEC_FEATURE_SESSION_KEY
);
1058 status
= auth_generic_set_username(auth_generic_state
, username
);
1059 if (!NT_STATUS_IS_OK(status
)) {
1060 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
1064 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
1065 if (!NT_STATUS_IS_OK(status
)) {
1066 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
1070 status
= auth_generic_set_password(auth_generic_state
, password
);
1071 if (!NT_STATUS_IS_OK(status
)) {
1072 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
1076 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1077 if (!NT_STATUS_IS_OK(status
)) {
1078 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1082 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, data_blob_null
, &in_blob
);
1083 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1084 printf("gensec_update returned %s\n", nt_errstr(status
));
1088 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1092 0x01, /* in_flags */
1093 SMB2_CAP_DFS
, /* in_capabilities */
1095 0, /* in_previous_session_id */
1096 &in_blob
); /* in_security_buffer */
1097 if (subreq
== NULL
) {
1098 printf("smb2cli_session_setup_send() returned NULL\n");
1102 ok
= tevent_req_poll(subreq
, ev
);
1104 printf("tevent_req_poll() returned false\n");
1108 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1110 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1111 printf("smb2cli_session_setup_recv returned %s\n",
1116 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, out_blob
, &in_blob
);
1117 if (!NT_STATUS_IS_OK(status
)) {
1118 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1122 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1126 0x01, /* in_flags */
1127 SMB2_CAP_DFS
, /* in_capabilities */
1129 0, /* in_previous_session_id */
1130 &in_blob
); /* in_security_buffer */
1131 if (subreq
== NULL
) {
1132 printf("smb2cli_session_setup_send() returned NULL\n");
1136 ok
= tevent_req_poll(subreq
, ev
);
1138 printf("tevent_req_poll() returned false\n");
1142 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1143 &recv_iov
, &out_blob
);
1144 if (!NT_STATUS_IS_OK(status
)) {
1145 printf("smb2cli_session_setup_recv returned %s\n",
1150 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
1151 &channel_session_key
);
1152 if (!NT_STATUS_IS_OK(status
)) {
1153 printf("gensec_session_key returned %s\n",
1158 status
= smb2cli_session_set_channel_key(cli3
->smb2
.session
,
1159 channel_session_key
,
1161 if (!NT_STATUS_IS_OK(status
)) {
1162 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status
));
1166 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1167 cli1
->smb2
.tcon
, "multi-channel.txt",
1168 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1169 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1170 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1171 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1172 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1173 FILE_CREATE
, /* create_disposition, */
1174 FILE_DELETE_ON_CLOSE
, /* create_options, */
1175 NULL
, /* smb2_create_blobs *blobs */
1179 if (!NT_STATUS_IS_OK(status
)) {
1180 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
1184 status
= smb2cli_write(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1185 cli1
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
1186 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
1187 if (!NT_STATUS_IS_OK(status
)) {
1188 printf("smb2cli_write returned %s\n", nt_errstr(status
));
1192 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1193 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1194 if (!NT_STATUS_IS_OK(status
)) {
1195 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1199 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1200 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1201 if (!NT_STATUS_IS_OK(status
)) {
1202 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1206 status
= smb2cli_flush(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1207 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1208 if (!NT_STATUS_IS_OK(status
)) {
1209 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1213 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1214 cli1
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
1216 talloc_tos(), &result
, &nread
);
1217 if (!NT_STATUS_IS_OK(status
)) {
1218 printf("smb2cli_read returned %s\n", nt_errstr(status
));
1222 if (nread
!= strlen(hello
)) {
1223 printf("smb2cli_read returned %d bytes, expected %d\n",
1224 (int)nread
, (int)strlen(hello
));
1228 if (memcmp(hello
, result
, nread
) != 0) {
1229 printf("smb2cli_read returned '%s', expected '%s'\n",
1234 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1235 if (!NT_STATUS_IS_OK(status
)) {
1236 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1240 gensec_want_feature(auth_generic_state
->gensec_security
,
1241 GENSEC_FEATURE_SESSION_KEY
);
1242 status
= auth_generic_set_username(auth_generic_state
, username
);
1243 if (!NT_STATUS_IS_OK(status
)) {
1244 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
1248 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
1249 if (!NT_STATUS_IS_OK(status
)) {
1250 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
1254 status
= auth_generic_set_password(auth_generic_state
, password
);
1255 if (!NT_STATUS_IS_OK(status
)) {
1256 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
1260 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1261 if (!NT_STATUS_IS_OK(status
)) {
1262 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1266 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, data_blob_null
, &in_blob
);
1267 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1268 printf("gensec_update returned %s\n", nt_errstr(status
));
1272 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1277 SMB2_CAP_DFS
, /* in_capabilities */
1279 0, /* in_previous_session_id */
1280 &in_blob
); /* in_security_buffer */
1281 if (subreq
== NULL
) {
1282 printf("smb2cli_session_setup_send() returned NULL\n");
1286 ok
= tevent_req_poll(subreq
, ev
);
1288 printf("tevent_req_poll() returned false\n");
1292 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1294 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1295 printf("smb2cli_session_setup_recv returned %s\n",
1300 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, out_blob
, &in_blob
);
1301 if (!NT_STATUS_IS_OK(status
)) {
1302 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1306 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1307 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1308 if (!NT_STATUS_IS_OK(status
)) {
1309 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1313 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1314 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1315 if (!NT_STATUS_IS_OK(status
)) {
1316 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1320 status
= smb2cli_flush(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1321 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1322 if (!NT_STATUS_IS_OK(status
)) {
1323 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1327 status
= smb2cli_create(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1328 cli1
->smb2
.tcon
, "multi-channel-invalid.txt",
1329 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1330 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1331 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1332 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1333 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1334 FILE_CREATE
, /* create_disposition, */
1335 FILE_DELETE_ON_CLOSE
, /* create_options, */
1336 NULL
, /* smb2_create_blobs *blobs */
1340 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1341 printf("smb2cli_create %s\n", nt_errstr(status
));
1345 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1346 cli1
->smb2
.tcon
, "multi-channel-invalid.txt",
1347 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1348 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1349 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1350 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1351 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1352 FILE_CREATE
, /* create_disposition, */
1353 FILE_DELETE_ON_CLOSE
, /* create_options, */
1354 NULL
, /* smb2_create_blobs *blobs */
1358 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1359 printf("smb2cli_create %s\n", nt_errstr(status
));
1363 status
= smb2cli_create(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1364 cli1
->smb2
.tcon
, "multi-channel-invalid.txt",
1365 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1366 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1367 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1368 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1369 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1370 FILE_CREATE
, /* create_disposition, */
1371 FILE_DELETE_ON_CLOSE
, /* create_options, */
1372 NULL
, /* smb2_create_blobs *blobs */
1376 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1377 printf("smb2cli_create %s\n", nt_errstr(status
));
1381 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1386 SMB2_CAP_DFS
, /* in_capabilities */
1388 0, /* in_previous_session_id */
1389 &in_blob
); /* in_security_buffer */
1390 if (subreq
== NULL
) {
1391 printf("smb2cli_session_setup_send() returned NULL\n");
1395 ok
= tevent_req_poll(subreq
, ev
);
1397 printf("tevent_req_poll() returned false\n");
1401 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1402 &recv_iov
, &out_blob
);
1403 if (!NT_STATUS_IS_OK(status
)) {
1404 printf("smb2cli_session_setup_recv returned %s\n",
1409 status
= smb2cli_close(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1410 cli1
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
1411 if (!NT_STATUS_IS_OK(status
)) {
1412 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1416 status
= smb2cli_flush(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1417 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1418 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1419 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1423 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1424 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1425 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1426 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1430 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1431 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1432 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1433 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1440 bool run_smb2_session_reauth(int dummy
)
1442 struct cli_state
*cli
;
1445 uint64_t fid_persistent
, fid_volatile
;
1446 uint64_t dir_persistent
, dir_volatile
;
1448 uint32_t dir_data_length
;
1449 struct tevent_context
*ev
;
1450 struct tevent_req
*subreq
;
1451 DATA_BLOB in_blob
= data_blob_null
;
1453 DATA_BLOB in_input_buffer
;
1454 DATA_BLOB out_output_buffer
;
1455 uint8_t in_file_info_class
;
1456 struct auth_generic_state
*auth_generic_state
;
1457 struct iovec
*recv_iov
;
1459 struct smbXcli_tcon
*saved_tcon
;
1461 printf("Starting SMB2-SESSION_REAUTH\n");
1463 if (!torture_init_connection(&cli
)) {
1468 * PROTOCOL_SMB2_22 has a bug in win8pre0
1469 * it behaves like PROTOCOL_SMB2_02
1470 * and returns NT_STATUS_REQUEST_NOT_ACCEPTED,
1471 * while it allows it on PROTOCOL_SMB2_02.
1473 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
1474 PROTOCOL_SMB2_10
, PROTOCOL_SMB2_10
);
1475 if (!NT_STATUS_IS_OK(status
)) {
1476 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
1480 status
= cli_session_setup(cli
, username
,
1481 password
, strlen(password
),
1482 password
, strlen(password
),
1484 if (!NT_STATUS_IS_OK(status
)) {
1485 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status
));
1489 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
1490 if (!NT_STATUS_IS_OK(status
)) {
1491 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1495 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1496 cli
->smb2
.tcon
, "session-reauth.txt",
1497 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1498 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1499 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1500 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1501 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1502 FILE_CREATE
, /* create_disposition, */
1503 FILE_DELETE_ON_CLOSE
, /* create_options, */
1504 NULL
, /* smb2_create_blobs *blobs */
1508 if (!NT_STATUS_IS_OK(status
)) {
1509 printf("smb2cli_create %s\n", nt_errstr(status
));
1513 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1515 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1516 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1517 SEC_STD_SYNCHRONIZE
|
1519 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
1520 0, /* file_attributes, */
1521 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1522 FILE_OPEN
, /* create_disposition, */
1523 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
1524 NULL
, /* smb2_create_blobs *blobs */
1528 if (!NT_STATUS_IS_OK(status
)) {
1529 printf("smb2cli_create returned %s\n", nt_errstr(status
));
1533 status
= smb2cli_query_directory(
1534 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
1535 1, 0x3, 0, dir_persistent
, dir_volatile
,
1536 "session-reauth.txt", 0xffff,
1537 talloc_tos(), &dir_data
, &dir_data_length
);
1538 if (!NT_STATUS_IS_OK(status
)) {
1539 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1543 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1544 if (!NT_STATUS_IS_OK(status
)) {
1545 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1549 gensec_want_feature(auth_generic_state
->gensec_security
,
1550 GENSEC_FEATURE_SESSION_KEY
);
1551 status
= auth_generic_set_username(auth_generic_state
, username
);
1552 if (!NT_STATUS_IS_OK(status
)) {
1553 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
1557 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
1558 if (!NT_STATUS_IS_OK(status
)) {
1559 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
1563 status
= auth_generic_set_password(auth_generic_state
, password
);
1564 if (!NT_STATUS_IS_OK(status
)) {
1565 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
1569 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1570 if (!NT_STATUS_IS_OK(status
)) {
1571 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1575 ev
= samba_tevent_context_init(talloc_tos());
1577 printf("samba_tevent_context_init() returned NULL\n");
1581 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, data_blob_null
, &in_blob
);
1582 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1583 printf("gensec_update returned %s\n", nt_errstr(status
));
1587 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1592 SMB2_CAP_DFS
, /* in_capabilities */
1594 0, /* in_previous_session_id */
1595 &in_blob
); /* in_security_buffer */
1596 if (subreq
== NULL
) {
1597 printf("smb2cli_session_setup_send() returned NULL\n");
1601 ok
= tevent_req_poll(subreq
, ev
);
1603 printf("tevent_req_poll() returned false\n");
1607 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1609 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1610 printf("smb2cli_session_setup_recv returned %s\n",
1615 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, out_blob
, &in_blob
);
1616 if (!NT_STATUS_IS_OK(status
)) {
1617 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1621 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1622 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1623 if (!NT_STATUS_IS_OK(status
)) {
1624 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1628 status
= smb2cli_query_directory(
1629 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
1630 1, 0x3, 0, dir_persistent
, dir_volatile
,
1631 "session-reauth.txt", 0xffff,
1632 talloc_tos(), &dir_data
, &dir_data_length
);
1633 if (!NT_STATUS_IS_OK(status
)) {
1634 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1639 * query_info seems to be a path based operation on Windows...
1641 status
= smb2cli_query_info(cli
->conn
,
1645 SMB2_GETINFO_SECURITY
,
1646 0, /* in_file_info_class */
1647 1024, /* in_max_output_length */
1648 NULL
, /* in_input_buffer */
1649 SECINFO_OWNER
, /* in_additional_info */
1654 &out_output_buffer
);
1655 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1656 printf("smb2cli_query_info (security) returned %s\n", nt_errstr(status
));
1660 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1661 status
= smb2cli_query_info(cli
->conn
,
1667 1024, /* in_max_output_length */
1668 NULL
, /* in_input_buffer */
1669 0, /* in_additional_info */
1674 &out_output_buffer
);
1675 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1676 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1680 in_input_buffer
= data_blob_talloc(talloc_tos(), NULL
, 8);
1681 SBVAL(in_input_buffer
.data
, 0, 512);
1683 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1684 status
= smb2cli_set_info(cli
->conn
,
1691 0, /* in_additional_info */
1694 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1695 printf("smb2cli_set_info (position) returned %s\n", nt_errstr(status
));
1699 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1700 cli
->smb2
.tcon
, "session-reauth-invalid.txt",
1701 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1702 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1703 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1704 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1705 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1706 FILE_CREATE
, /* create_disposition, */
1707 FILE_DELETE_ON_CLOSE
, /* create_options, */
1708 NULL
, /* smb2_create_blobs *blobs */
1712 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1713 printf("smb2cli_create %s\n", nt_errstr(status
));
1717 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1719 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1720 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1721 SEC_STD_SYNCHRONIZE
|
1723 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
1724 0, /* file_attributes, */
1725 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1726 FILE_OPEN
, /* create_disposition, */
1727 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
1728 NULL
, /* smb2_create_blobs *blobs */
1732 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1733 printf("smb2cli_create returned %s\n", nt_errstr(status
));
1737 saved_tid
= smb2cli_tcon_current_id(cli
->smb2
.tcon
);
1738 saved_tcon
= cli
->smb2
.tcon
;
1739 cli
->smb2
.tcon
= smbXcli_tcon_create(cli
);
1740 smb2cli_tcon_set_values(cli
->smb2
.tcon
,
1745 0, /* capabilities */
1746 0 /* maximal_access */);
1747 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
1748 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1749 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1752 talloc_free(cli
->smb2
.tcon
);
1753 cli
->smb2
.tcon
= saved_tcon
;
1755 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1760 SMB2_CAP_DFS
, /* in_capabilities */
1762 0, /* in_previous_session_id */
1763 &in_blob
); /* in_security_buffer */
1764 if (subreq
== NULL
) {
1765 printf("smb2cli_session_setup_send() returned NULL\n");
1769 ok
= tevent_req_poll(subreq
, ev
);
1771 printf("tevent_req_poll() returned false\n");
1775 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1776 &recv_iov
, &out_blob
);
1777 if (!NT_STATUS_IS_OK(status
)) {
1778 printf("smb2cli_session_setup_recv returned %s\n",
1783 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1784 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1785 if (!NT_STATUS_IS_OK(status
)) {
1786 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1790 status
= smb2cli_query_info(cli
->conn
,
1794 SMB2_GETINFO_SECURITY
,
1795 0, /* in_file_info_class */
1796 1024, /* in_max_output_length */
1797 NULL
, /* in_input_buffer */
1798 SECINFO_OWNER
, /* in_additional_info */
1803 &out_output_buffer
);
1804 if (!NT_STATUS_IS_OK(status
)) {
1805 printf("smb2cli_query_info (security) returned %s\n", nt_errstr(status
));
1809 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1810 status
= smb2cli_query_info(cli
->conn
,
1816 1024, /* in_max_output_length */
1817 NULL
, /* in_input_buffer */
1818 0, /* in_additional_info */
1823 &out_output_buffer
);
1824 if (!NT_STATUS_IS_OK(status
)) {
1825 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1829 in_input_buffer
= data_blob_talloc(talloc_tos(), NULL
, 8);
1830 SBVAL(in_input_buffer
.data
, 0, 512);
1832 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1833 status
= smb2cli_set_info(cli
->conn
,
1840 0, /* in_additional_info */
1843 if (!NT_STATUS_IS_OK(status
)) {
1844 printf("smb2cli_set_info (position) returned %s\n", nt_errstr(status
));
1848 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1849 status
= smb2cli_query_info(cli
->conn
,
1855 1024, /* in_max_output_length */
1856 NULL
, /* in_input_buffer */
1857 0, /* in_additional_info */
1862 &out_output_buffer
);
1863 if (!NT_STATUS_IS_OK(status
)) {
1864 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1868 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1869 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
1870 if (!NT_STATUS_IS_OK(status
)) {
1871 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1875 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1876 cli
->smb2
.tcon
, "session-reauth.txt",
1877 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1878 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1879 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1880 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1881 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1882 FILE_CREATE
, /* create_disposition, */
1883 FILE_DELETE_ON_CLOSE
, /* create_options, */
1884 NULL
, /* smb2_create_blobs *blobs */
1888 if (!NT_STATUS_IS_OK(status
)) {
1889 printf("smb2cli_create %s\n", nt_errstr(status
));
1893 status
= smb2cli_query_directory(
1894 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
1895 1, 0x3, 0, dir_persistent
, dir_volatile
,
1896 "session-reauth.txt", 0xffff,
1897 talloc_tos(), &dir_data
, &dir_data_length
);
1898 if (!NT_STATUS_IS_OK(status
)) {
1899 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1903 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1904 cli
->smb2
.tcon
, 0, dir_persistent
, dir_volatile
);
1905 if (!NT_STATUS_IS_OK(status
)) {
1906 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1910 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1911 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
1912 if (!NT_STATUS_IS_OK(status
)) {
1913 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1917 saved_tid
= smb2cli_tcon_current_id(cli
->smb2
.tcon
);
1918 saved_tcon
= cli
->smb2
.tcon
;
1919 cli
->smb2
.tcon
= smbXcli_tcon_create(cli
);
1920 smb2cli_tcon_set_values(cli
->smb2
.tcon
,
1925 0, /* capabilities */
1926 0 /* maximal_access */);
1927 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
1928 if (!NT_STATUS_IS_OK(status
)) {
1929 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1932 talloc_free(cli
->smb2
.tcon
);
1933 cli
->smb2
.tcon
= saved_tcon
;