2 Unix SMB/CIFS implementation.
3 Initial test for the smb2 client lib
4 Copyright (C) Volker Lendecke 2011
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "torture/proto.h"
24 #include "../libcli/smb/smbXcli_base.h"
25 #include "libcli/security/security.h"
26 #include "libsmb/proto.h"
27 #include "auth/gensec/gensec.h"
28 #include "auth_generic.h"
29 #include "../librpc/ndr/libndr.h"
31 extern fstring host
, workgroup
, share
, password
, username
, myname
;
33 bool run_smb2_basic(int dummy
)
35 struct cli_state
*cli
;
37 uint64_t fid_persistent
, fid_volatile
;
38 const char *hello
= "Hello, world\n";
42 uint32_t dir_data_length
;
43 uint32_t saved_tid
= 0;
44 struct smbXcli_tcon
*saved_tcon
= NULL
;
45 uint64_t saved_uid
= 0;
47 printf("Starting SMB2-BASIC\n");
49 if (!torture_init_connection(&cli
)) {
53 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
54 PROTOCOL_SMB2_02
, PROTOCOL_SMB2_02
);
55 if (!NT_STATUS_IS_OK(status
)) {
56 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
60 status
= cli_session_setup(cli
, username
,
61 password
, strlen(password
),
62 password
, strlen(password
),
64 if (!NT_STATUS_IS_OK(status
)) {
65 printf("cli_session_setup returned %s\n", nt_errstr(status
));
69 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
70 if (!NT_STATUS_IS_OK(status
)) {
71 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
75 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
76 cli
->smb2
.tcon
, "smb2-basic.txt",
77 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
78 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
79 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
80 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
81 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
82 FILE_CREATE
, /* create_disposition, */
83 FILE_DELETE_ON_CLOSE
, /* create_options, */
84 NULL
, /* smb2_create_blobs *blobs */
88 if (!NT_STATUS_IS_OK(status
)) {
89 printf("smb2cli_create returned %s\n", nt_errstr(status
));
93 status
= smb2cli_write(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
94 cli
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
95 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
96 if (!NT_STATUS_IS_OK(status
)) {
97 printf("smb2cli_write returned %s\n", nt_errstr(status
));
101 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
102 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
103 if (!NT_STATUS_IS_OK(status
)) {
104 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
108 status
= smb2cli_read(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
109 cli
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
111 talloc_tos(), &result
, &nread
);
112 if (!NT_STATUS_IS_OK(status
)) {
113 printf("smb2cli_read returned %s\n", nt_errstr(status
));
117 if (nread
!= strlen(hello
)) {
118 printf("smb2cli_read returned %d bytes, expected %d\n",
119 (int)nread
, (int)strlen(hello
));
123 if (memcmp(hello
, result
, nread
) != 0) {
124 printf("smb2cli_read returned '%s', expected '%s'\n",
129 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
130 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
131 if (!NT_STATUS_IS_OK(status
)) {
132 printf("smb2cli_close returned %s\n", nt_errstr(status
));
136 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
138 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
139 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
142 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
143 0, /* file_attributes, */
144 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
145 FILE_OPEN
, /* create_disposition, */
146 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
147 NULL
, /* smb2_create_blobs *blobs */
151 if (!NT_STATUS_IS_OK(status
)) {
152 printf("smb2cli_create returned %s\n", nt_errstr(status
));
156 status
= smb2cli_query_directory(
157 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
158 1, 0, 0, fid_persistent
, fid_volatile
, "*", 0xffff,
159 talloc_tos(), &dir_data
, &dir_data_length
);
161 if (!NT_STATUS_IS_OK(status
)) {
162 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
166 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
167 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
168 if (!NT_STATUS_IS_OK(status
)) {
169 printf("smb2cli_close returned %s\n", nt_errstr(status
));
173 saved_tid
= smb2cli_tcon_current_id(cli
->smb2
.tcon
);
174 saved_tcon
= cli
->smb2
.tcon
;
175 cli
->smb2
.tcon
= smbXcli_tcon_create(cli
);
176 smb2cli_tcon_set_values(cli
->smb2
.tcon
,
181 0, /* capabilities */
182 0 /* maximal_access */);
183 status
= smb2cli_tdis(cli
->conn
,
187 if (!NT_STATUS_IS_OK(status
)) {
188 printf("smb2cli_tdis returned %s\n", nt_errstr(status
));
191 talloc_free(cli
->smb2
.tcon
);
192 cli
->smb2
.tcon
= saved_tcon
;
194 status
= smb2cli_tdis(cli
->conn
,
198 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
199 printf("2nd smb2cli_tdis returned %s\n", nt_errstr(status
));
203 saved_uid
= smb2cli_session_current_id(cli
->smb2
.session
);
204 status
= smb2cli_logoff(cli
->conn
, cli
->timeout
, cli
->smb2
.session
);
205 if (!NT_STATUS_IS_OK(status
)) {
206 printf("smb2cli_logoff returned %s\n", nt_errstr(status
));
210 cli
->smb2
.session
= smbXcli_session_create(cli
, cli
->conn
);
211 if (cli
->smb2
.session
== NULL
) {
212 printf("smbXcli_session_create() returned NULL\n");
216 smb2cli_session_set_id_and_flags(cli
->smb2
.session
, saved_uid
, 0);
218 status
= smb2cli_logoff(cli
->conn
, cli
->timeout
, cli
->smb2
.session
);
219 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
220 printf("2nd smb2cli_logoff returned %s\n", nt_errstr(status
));
227 bool run_smb2_negprot(int dummy
)
229 struct cli_state
*cli
;
231 enum protocol_types protocol
;
232 const char *name
= NULL
;
234 printf("Starting SMB2-NEGPROT\n");
236 if (!torture_init_connection(&cli
)) {
240 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
241 PROTOCOL_CORE
, PROTOCOL_LATEST
);
242 if (!NT_STATUS_IS_OK(status
)) {
243 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
247 protocol
= smbXcli_conn_protocol(cli
->conn
);
250 case PROTOCOL_SMB2_02
:
253 case PROTOCOL_SMB2_10
:
256 case PROTOCOL_SMB2_22
:
259 case PROTOCOL_SMB2_24
:
262 case PROTOCOL_SMB3_00
:
265 case PROTOCOL_SMB3_02
:
268 case PROTOCOL_SMB3_10
:
276 printf("Server supports %s\n", name
);
278 printf("Server DOES NOT support SMB2\n");
282 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
284 if (!NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_RESET
) &&
285 !NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_DISCONNECTED
) &&
286 !NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_ABORTED
)) {
287 printf("2nd smbXcli_negprot should disconnect - returned %s\n",
292 if (smbXcli_conn_is_connected(cli
->conn
)) {
293 printf("2nd smbXcli_negprot should disconnect "
294 "- still connected\n");
301 bool run_smb2_session_reconnect(int dummy
)
303 struct cli_state
*cli1
;
304 struct cli_state
*cli2
;
307 uint64_t fid_persistent
, fid_volatile
;
308 struct tevent_context
*ev
;
309 struct tevent_req
*subreq
;
310 DATA_BLOB in_blob
= data_blob_null
;
312 DATA_BLOB session_key
;
313 struct auth_generic_state
*auth_generic_state
;
314 struct iovec
*recv_iov
;
315 const char *hello
= "Hello, world\n";
319 printf("Starting SMB2-SESSION-RECONNECT\n");
321 if (!torture_init_connection(&cli1
)) {
325 status
= smbXcli_negprot(cli1
->conn
, cli1
->timeout
,
326 PROTOCOL_SMB2_02
, PROTOCOL_LATEST
);
327 if (!NT_STATUS_IS_OK(status
)) {
328 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
332 status
= cli_session_setup(cli1
, username
,
333 password
, strlen(password
),
334 password
, strlen(password
),
336 if (!NT_STATUS_IS_OK(status
)) {
337 printf("cli_session_setup returned %s\n", nt_errstr(status
));
341 status
= cli_tree_connect(cli1
, share
, "?????", "", 0);
342 if (!NT_STATUS_IS_OK(status
)) {
343 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
347 status
= smb2cli_create(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
348 cli1
->smb2
.tcon
, "session-reconnect.txt",
349 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
350 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
351 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
352 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
353 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
354 FILE_CREATE
, /* create_disposition, */
355 FILE_DELETE_ON_CLOSE
, /* create_options, */
356 NULL
, /* smb2_create_blobs *blobs */
360 if (!NT_STATUS_IS_OK(status
)) {
361 printf("smb2cli_create on cli1 %s\n", nt_errstr(status
));
365 status
= smb2cli_write(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
366 cli1
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
367 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
368 if (!NT_STATUS_IS_OK(status
)) {
369 printf("smb2cli_write returned %s\n", nt_errstr(status
));
373 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
374 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
375 if (!NT_STATUS_IS_OK(status
)) {
376 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
380 status
= smb2cli_read(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
381 cli1
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
383 talloc_tos(), &result
, &nread
);
384 if (!NT_STATUS_IS_OK(status
)) {
385 printf("smb2cli_read returned %s\n", nt_errstr(status
));
389 if (nread
!= strlen(hello
)) {
390 printf("smb2cli_read returned %d bytes, expected %d\n",
391 (int)nread
, (int)strlen(hello
));
395 if (memcmp(hello
, result
, nread
) != 0) {
396 printf("smb2cli_read returned '%s', expected '%s'\n",
401 /* prepare second session */
403 if (!torture_init_connection(&cli2
)) {
407 status
= smbXcli_negprot(cli2
->conn
, cli2
->timeout
,
408 PROTOCOL_SMB2_02
, PROTOCOL_LATEST
);
409 if (!NT_STATUS_IS_OK(status
)) {
410 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
414 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
415 if (!NT_STATUS_IS_OK(status
)) {
416 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
420 gensec_want_feature(auth_generic_state
->gensec_security
,
421 GENSEC_FEATURE_SESSION_KEY
);
422 status
= auth_generic_set_username(auth_generic_state
, username
);
423 if (!NT_STATUS_IS_OK(status
)) {
424 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
428 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
429 if (!NT_STATUS_IS_OK(status
)) {
430 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
434 status
= auth_generic_set_password(auth_generic_state
, password
);
435 if (!NT_STATUS_IS_OK(status
)) {
436 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
440 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
441 if (!NT_STATUS_IS_OK(status
)) {
442 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
446 ev
= samba_tevent_context_init(talloc_tos());
448 printf("samba_tevent_context_init() returned NULL\n");
452 status
= gensec_update(auth_generic_state
->gensec_security
,
453 talloc_tos(), data_blob_null
, &in_blob
);
454 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
455 printf("gensec_update returned %s\n", nt_errstr(status
));
459 cli2
->smb2
.session
= smbXcli_session_create(cli2
, cli2
->conn
);
461 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
466 SMB2_CAP_DFS
, /* in_capabilities */
468 /* in_previous_session_id: */
469 smb2cli_session_current_id(cli1
->smb2
.session
),
470 &in_blob
); /* in_security_buffer */
471 if (subreq
== NULL
) {
472 printf("smb2cli_session_setup_send() returned NULL\n");
476 ok
= tevent_req_poll(subreq
, ev
);
478 printf("tevent_req_poll() returned false\n");
482 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
484 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
485 printf("smb2cli_session_setup_recv returned %s\n",
490 status
= gensec_update(auth_generic_state
->gensec_security
,
491 talloc_tos(), out_blob
, &in_blob
);
492 if (!NT_STATUS_IS_OK(status
)) {
493 printf("auth_generic_update returned %s\n", nt_errstr(status
));
497 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
502 SMB2_CAP_DFS
, /* in_capabilities */
504 /* in_previous_session_id: */
505 smb2cli_session_current_id(cli1
->smb2
.session
),
506 &in_blob
); /* in_security_buffer */
507 if (subreq
== NULL
) {
508 printf("smb2cli_session_setup_send() returned NULL\n");
512 ok
= tevent_req_poll(subreq
, ev
);
514 printf("tevent_req_poll() returned false\n");
518 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
519 &recv_iov
, &out_blob
);
520 if (!NT_STATUS_IS_OK(status
)) {
521 printf("smb2cli_session_setup_recv returned %s\n",
526 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
528 if (!NT_STATUS_IS_OK(status
)) {
529 printf("gensec_session_key returned %s\n",
534 /* check file operation on the old client */
536 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
537 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
538 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
539 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
543 status
= cli_tree_connect(cli1
, share
, "?????", "", 0);
544 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
545 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
550 * checking file operations without signing.
551 * on w2k8r2 at least, flush, read and write also work the same way,
552 * while create gives ACCESS_DENIED without signing
554 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
555 cli2
->smb2
.tcon
, fid_persistent
, fid_volatile
);
556 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
557 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
559 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
563 status
= smb2cli_write(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
564 cli2
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
565 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
566 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
567 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
569 printf("smb2cli_write returned %s\n", nt_errstr(status
));
573 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
574 cli2
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
576 talloc_tos(), &result
, &nread
);
577 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
578 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
580 printf("smb2cli_read returned %s\n", nt_errstr(status
));
584 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
585 cli2
->smb2
.tcon
, "session-reconnect.txt",
586 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
587 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
588 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
589 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
590 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
591 FILE_CREATE
, /* create_disposition, */
592 FILE_DELETE_ON_CLOSE
, /* create_options, */
593 NULL
, /* smb2_create_blobs *blobs */
597 if (!NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
) &&
598 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
599 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
603 /* now grab the session key and try with signing */
605 status
= smb2cli_session_set_session_key(cli2
->smb2
.session
,
608 if (!NT_STATUS_IS_OK(status
)) {
609 printf("smb2cli_session_set_session_key %s\n", nt_errstr(status
));
613 /* the tid seems to be irrelevant at this stage */
615 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
616 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
617 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
618 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
620 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
624 status
= smb2cli_write(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
625 cli1
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
626 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
627 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
628 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
630 printf("smb2cli_write returned %s\n", nt_errstr(status
));
634 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
635 cli1
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
637 talloc_tos(), &result
, &nread
);
638 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
639 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
641 printf("smb2cli_read returned %s\n", nt_errstr(status
));
645 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
646 cli1
->smb2
.tcon
, "session-reconnect.txt",
647 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
648 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
649 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
650 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
651 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
652 FILE_CREATE
, /* create_disposition, */
653 FILE_DELETE_ON_CLOSE
, /* create_options, */
654 NULL
, /* smb2_create_blobs *blobs */
658 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
) &&
659 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
661 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
665 /* now do a new tcon and test file calls again */
667 status
= cli_tree_connect(cli2
, share
, "?????", "", 0);
668 if (!NT_STATUS_IS_OK(status
)) {
669 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
673 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
674 cli2
->smb2
.tcon
, "session-reconnect.txt",
675 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
676 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
677 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
678 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
679 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
680 FILE_CREATE
, /* create_disposition, */
681 FILE_DELETE_ON_CLOSE
, /* create_options, */
682 NULL
, /* smb2_create_blobs *blobs */
686 if (!NT_STATUS_IS_OK(status
)) {
687 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
691 status
= smb2cli_write(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
692 cli2
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
693 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
694 if (!NT_STATUS_IS_OK(status
)) {
695 printf("smb2cli_write returned %s\n", nt_errstr(status
));
699 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
700 cli2
->smb2
.tcon
, fid_persistent
, fid_volatile
);
701 if (!NT_STATUS_IS_OK(status
)) {
702 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
706 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
707 cli2
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
709 talloc_tos(), &result
, &nread
);
710 if (!NT_STATUS_IS_OK(status
)) {
711 printf("smb2cli_read returned %s\n", nt_errstr(status
));
715 if (nread
!= strlen(hello
)) {
716 printf("smb2cli_read returned %d bytes, expected %d\n",
717 (int)nread
, (int)strlen(hello
));
721 if (memcmp(hello
, result
, nread
) != 0) {
722 printf("smb2cli_read returned '%s', expected '%s'\n",
730 bool run_smb2_tcon_dependence(int dummy
)
732 struct cli_state
*cli
;
734 uint64_t fid_persistent
, fid_volatile
;
735 const char *hello
= "Hello, world\n";
738 struct smbXcli_tcon
*tcon2
;
741 printf("Starting SMB2-TCON-DEPENDENCE\n");
743 if (!torture_init_connection(&cli
)) {
747 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
748 PROTOCOL_SMB2_02
, PROTOCOL_LATEST
);
749 if (!NT_STATUS_IS_OK(status
)) {
750 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
754 status
= cli_session_setup(cli
, username
,
755 password
, strlen(password
),
756 password
, strlen(password
),
758 if (!NT_STATUS_IS_OK(status
)) {
759 printf("cli_session_setup returned %s\n", nt_errstr(status
));
763 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
764 if (!NT_STATUS_IS_OK(status
)) {
765 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
769 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
770 cli
->smb2
.tcon
, "tcon_depedence.txt",
771 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
772 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
773 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
774 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
775 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
776 FILE_CREATE
, /* create_disposition, */
777 FILE_DELETE_ON_CLOSE
, /* create_options, */
778 NULL
, /* smb2_create_blobs *blobs */
782 if (!NT_STATUS_IS_OK(status
)) {
783 printf("smb2cli_create on cli %s\n", nt_errstr(status
));
787 status
= smb2cli_write(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
788 cli
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
789 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
790 if (!NT_STATUS_IS_OK(status
)) {
791 printf("smb2cli_write returned %s\n", nt_errstr(status
));
795 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
796 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
797 if (!NT_STATUS_IS_OK(status
)) {
798 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
802 status
= smb2cli_read(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
803 cli
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
805 talloc_tos(), &result
, &nread
);
806 if (!NT_STATUS_IS_OK(status
)) {
807 printf("smb2cli_read returned %s\n", nt_errstr(status
));
811 if (nread
!= strlen(hello
)) {
812 printf("smb2cli_read returned %d bytes, expected %d\n",
813 (int)nread
, (int)strlen(hello
));
817 if (memcmp(hello
, result
, nread
) != 0) {
818 printf("smb2cli_read returned '%s', expected '%s'\n",
823 /* check behaviour with wrong tid... */
825 tcon2
= smbXcli_tcon_create(cli
);
826 tcon2_id
= smb2cli_tcon_current_id(cli
->smb2
.tcon
);
828 smb2cli_tcon_set_values(tcon2
,
833 0, /* capabilities */
834 0 /* maximal_access */);
836 status
= smb2cli_read(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
837 tcon2
, 0x10000, 0, fid_persistent
,
839 talloc_tos(), &result
, &nread
);
840 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
841 printf("smb2cli_read returned %s\n", nt_errstr(status
));
850 bool run_smb2_multi_channel(int dummy
)
852 struct cli_state
*cli1
;
853 struct cli_state
*cli2
;
854 struct cli_state
*cli3
;
857 uint64_t fid_persistent
, fid_volatile
;
858 struct tevent_context
*ev
;
859 struct tevent_req
*subreq
;
860 DATA_BLOB in_blob
= data_blob_null
;
862 DATA_BLOB channel_session_key
;
863 struct auth_generic_state
*auth_generic_state
;
864 struct iovec
*recv_iov
;
865 const char *hello
= "Hello, world\n";
868 struct GUID saved_guid
= cli_state_client_guid
;
870 printf("Starting SMB2-MULTI-CHANNEL\n");
872 cli_state_client_guid
= GUID_random();
874 if (!torture_init_connection(&cli1
)) {
878 if (!torture_init_connection(&cli2
)) {
882 if (!torture_init_connection(&cli3
)) {
886 cli_state_client_guid
= saved_guid
;
888 status
= smbXcli_negprot(cli1
->conn
, cli1
->timeout
,
889 PROTOCOL_SMB2_22
, PROTOCOL_LATEST
);
890 if (!NT_STATUS_IS_OK(status
)) {
891 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
895 status
= smbXcli_negprot(cli2
->conn
, cli2
->timeout
,
896 PROTOCOL_SMB2_22
, PROTOCOL_LATEST
);
897 if (!NT_STATUS_IS_OK(status
)) {
898 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
902 status
= smbXcli_negprot(cli3
->conn
, cli3
->timeout
,
903 PROTOCOL_SMB2_22
, PROTOCOL_LATEST
);
904 if (!NT_STATUS_IS_OK(status
)) {
905 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
909 status
= cli_session_setup(cli1
, username
,
910 password
, strlen(password
),
911 password
, strlen(password
),
913 if (!NT_STATUS_IS_OK(status
)) {
914 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status
));
918 status
= cli_tree_connect(cli1
, share
, "?????", "", 0);
919 if (!NT_STATUS_IS_OK(status
)) {
920 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
924 status
= smb2cli_session_create_channel(cli2
,
927 &cli2
->smb2
.session
);
928 if (!NT_STATUS_IS_OK(status
)) {
929 printf("smb2cli_session_create_channel returned %s\n",
934 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
935 if (!NT_STATUS_IS_OK(status
)) {
936 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
940 gensec_want_feature(auth_generic_state
->gensec_security
,
941 GENSEC_FEATURE_SESSION_KEY
);
942 status
= auth_generic_set_username(auth_generic_state
, username
);
943 if (!NT_STATUS_IS_OK(status
)) {
944 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
948 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
949 if (!NT_STATUS_IS_OK(status
)) {
950 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
954 status
= auth_generic_set_password(auth_generic_state
, password
);
955 if (!NT_STATUS_IS_OK(status
)) {
956 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
960 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
961 if (!NT_STATUS_IS_OK(status
)) {
962 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
966 ev
= samba_tevent_context_init(talloc_tos());
968 printf("samba_tevent_context_init() returned NULL\n");
972 status
= gensec_update(auth_generic_state
->gensec_security
,
973 talloc_tos(), data_blob_null
, &in_blob
);
974 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
975 printf("gensec_update returned %s\n", nt_errstr(status
));
979 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
984 SMB2_CAP_DFS
, /* in_capabilities */
986 0, /* in_previous_session_id */
987 &in_blob
); /* in_security_buffer */
988 if (subreq
== NULL
) {
989 printf("smb2cli_session_setup_send() returned NULL\n");
993 ok
= tevent_req_poll(subreq
, ev
);
995 printf("tevent_req_poll() returned false\n");
999 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1001 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1002 printf("smb2cli_session_setup_recv returned %s\n",
1007 status
= gensec_update(auth_generic_state
->gensec_security
,
1008 talloc_tos(), out_blob
, &in_blob
);
1009 if (!NT_STATUS_IS_OK(status
)) {
1010 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1014 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1018 0x01, /* in_flags */
1019 SMB2_CAP_DFS
, /* in_capabilities */
1021 0, /* in_previous_session_id */
1022 &in_blob
); /* in_security_buffer */
1023 if (subreq
== NULL
) {
1024 printf("smb2cli_session_setup_send() returned NULL\n");
1028 ok
= tevent_req_poll(subreq
, ev
);
1030 printf("tevent_req_poll() returned false\n");
1034 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1035 &recv_iov
, &out_blob
);
1036 if (!NT_STATUS_IS_OK(status
)) {
1037 printf("smb2cli_session_setup_recv returned %s\n",
1042 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
1043 &channel_session_key
);
1044 if (!NT_STATUS_IS_OK(status
)) {
1045 printf("gensec_session_key returned %s\n",
1050 status
= smb2cli_session_set_channel_key(cli2
->smb2
.session
,
1051 channel_session_key
,
1053 if (!NT_STATUS_IS_OK(status
)) {
1054 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status
));
1058 status
= smb2cli_session_create_channel(cli3
,
1061 &cli3
->smb2
.session
);
1062 if (!NT_STATUS_IS_OK(status
)) {
1063 printf("smb2cli_session_create_channel returned %s\n",
1068 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1069 if (!NT_STATUS_IS_OK(status
)) {
1070 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1074 gensec_want_feature(auth_generic_state
->gensec_security
,
1075 GENSEC_FEATURE_SESSION_KEY
);
1076 status
= auth_generic_set_username(auth_generic_state
, username
);
1077 if (!NT_STATUS_IS_OK(status
)) {
1078 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
1082 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
1083 if (!NT_STATUS_IS_OK(status
)) {
1084 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
1088 status
= auth_generic_set_password(auth_generic_state
, password
);
1089 if (!NT_STATUS_IS_OK(status
)) {
1090 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
1094 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1095 if (!NT_STATUS_IS_OK(status
)) {
1096 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1100 status
= gensec_update(auth_generic_state
->gensec_security
,
1101 talloc_tos(), data_blob_null
, &in_blob
);
1102 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1103 printf("gensec_update returned %s\n", nt_errstr(status
));
1107 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1111 0x01, /* in_flags */
1112 SMB2_CAP_DFS
, /* in_capabilities */
1114 0, /* in_previous_session_id */
1115 &in_blob
); /* in_security_buffer */
1116 if (subreq
== NULL
) {
1117 printf("smb2cli_session_setup_send() returned NULL\n");
1121 ok
= tevent_req_poll(subreq
, ev
);
1123 printf("tevent_req_poll() returned false\n");
1127 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1129 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1130 printf("smb2cli_session_setup_recv returned %s\n",
1135 status
= gensec_update(auth_generic_state
->gensec_security
,
1136 talloc_tos(), out_blob
, &in_blob
);
1137 if (!NT_STATUS_IS_OK(status
)) {
1138 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1142 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1146 0x01, /* in_flags */
1147 SMB2_CAP_DFS
, /* in_capabilities */
1149 0, /* in_previous_session_id */
1150 &in_blob
); /* in_security_buffer */
1151 if (subreq
== NULL
) {
1152 printf("smb2cli_session_setup_send() returned NULL\n");
1156 ok
= tevent_req_poll(subreq
, ev
);
1158 printf("tevent_req_poll() returned false\n");
1162 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1163 &recv_iov
, &out_blob
);
1164 if (!NT_STATUS_IS_OK(status
)) {
1165 printf("smb2cli_session_setup_recv returned %s\n",
1170 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
1171 &channel_session_key
);
1172 if (!NT_STATUS_IS_OK(status
)) {
1173 printf("gensec_session_key returned %s\n",
1178 status
= smb2cli_session_set_channel_key(cli3
->smb2
.session
,
1179 channel_session_key
,
1181 if (!NT_STATUS_IS_OK(status
)) {
1182 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status
));
1186 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1187 cli1
->smb2
.tcon
, "multi-channel.txt",
1188 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1189 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1190 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1191 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1192 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1193 FILE_CREATE
, /* create_disposition, */
1194 FILE_DELETE_ON_CLOSE
, /* create_options, */
1195 NULL
, /* smb2_create_blobs *blobs */
1199 if (!NT_STATUS_IS_OK(status
)) {
1200 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
1204 status
= smb2cli_write(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1205 cli1
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
1206 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
1207 if (!NT_STATUS_IS_OK(status
)) {
1208 printf("smb2cli_write returned %s\n", nt_errstr(status
));
1212 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1213 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1214 if (!NT_STATUS_IS_OK(status
)) {
1215 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1219 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1220 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1221 if (!NT_STATUS_IS_OK(status
)) {
1222 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1226 status
= smb2cli_flush(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1227 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1228 if (!NT_STATUS_IS_OK(status
)) {
1229 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1233 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1234 cli1
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
1236 talloc_tos(), &result
, &nread
);
1237 if (!NT_STATUS_IS_OK(status
)) {
1238 printf("smb2cli_read returned %s\n", nt_errstr(status
));
1242 if (nread
!= strlen(hello
)) {
1243 printf("smb2cli_read returned %d bytes, expected %d\n",
1244 (int)nread
, (int)strlen(hello
));
1248 if (memcmp(hello
, result
, nread
) != 0) {
1249 printf("smb2cli_read returned '%s', expected '%s'\n",
1254 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1255 if (!NT_STATUS_IS_OK(status
)) {
1256 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1260 gensec_want_feature(auth_generic_state
->gensec_security
,
1261 GENSEC_FEATURE_SESSION_KEY
);
1262 status
= auth_generic_set_username(auth_generic_state
, username
);
1263 if (!NT_STATUS_IS_OK(status
)) {
1264 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
1268 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
1269 if (!NT_STATUS_IS_OK(status
)) {
1270 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
1274 status
= auth_generic_set_password(auth_generic_state
, password
);
1275 if (!NT_STATUS_IS_OK(status
)) {
1276 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
1280 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1281 if (!NT_STATUS_IS_OK(status
)) {
1282 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1286 status
= gensec_update(auth_generic_state
->gensec_security
,
1287 talloc_tos(), data_blob_null
, &in_blob
);
1288 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1289 printf("gensec_update returned %s\n", nt_errstr(status
));
1293 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1298 SMB2_CAP_DFS
, /* in_capabilities */
1300 0, /* in_previous_session_id */
1301 &in_blob
); /* in_security_buffer */
1302 if (subreq
== NULL
) {
1303 printf("smb2cli_session_setup_send() returned NULL\n");
1307 ok
= tevent_req_poll(subreq
, ev
);
1309 printf("tevent_req_poll() returned false\n");
1313 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1315 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1316 printf("smb2cli_session_setup_recv returned %s\n",
1321 status
= gensec_update(auth_generic_state
->gensec_security
,
1322 talloc_tos(), out_blob
, &in_blob
);
1323 if (!NT_STATUS_IS_OK(status
)) {
1324 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1328 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1329 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1330 if (!NT_STATUS_IS_OK(status
)) {
1331 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1335 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1336 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1337 if (!NT_STATUS_IS_OK(status
)) {
1338 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1342 status
= smb2cli_flush(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1343 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1344 if (!NT_STATUS_IS_OK(status
)) {
1345 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1349 status
= smb2cli_create(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1350 cli1
->smb2
.tcon
, "multi-channel-invalid.txt",
1351 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1352 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1353 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1354 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1355 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1356 FILE_CREATE
, /* create_disposition, */
1357 FILE_DELETE_ON_CLOSE
, /* create_options, */
1358 NULL
, /* smb2_create_blobs *blobs */
1362 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1363 printf("smb2cli_create %s\n", nt_errstr(status
));
1367 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1368 cli1
->smb2
.tcon
, "multi-channel-invalid.txt",
1369 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1370 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1371 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1372 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1373 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1374 FILE_CREATE
, /* create_disposition, */
1375 FILE_DELETE_ON_CLOSE
, /* create_options, */
1376 NULL
, /* smb2_create_blobs *blobs */
1380 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1381 printf("smb2cli_create %s\n", nt_errstr(status
));
1385 status
= smb2cli_create(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1386 cli1
->smb2
.tcon
, "multi-channel-invalid.txt",
1387 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1388 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1389 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1390 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1391 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1392 FILE_CREATE
, /* create_disposition, */
1393 FILE_DELETE_ON_CLOSE
, /* create_options, */
1394 NULL
, /* smb2_create_blobs *blobs */
1398 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1399 printf("smb2cli_create %s\n", nt_errstr(status
));
1403 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1408 SMB2_CAP_DFS
, /* in_capabilities */
1410 0, /* in_previous_session_id */
1411 &in_blob
); /* in_security_buffer */
1412 if (subreq
== NULL
) {
1413 printf("smb2cli_session_setup_send() returned NULL\n");
1417 ok
= tevent_req_poll(subreq
, ev
);
1419 printf("tevent_req_poll() returned false\n");
1423 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1424 &recv_iov
, &out_blob
);
1425 if (!NT_STATUS_IS_OK(status
)) {
1426 printf("smb2cli_session_setup_recv returned %s\n",
1431 status
= smb2cli_close(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1432 cli1
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
1433 if (!NT_STATUS_IS_OK(status
)) {
1434 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1438 status
= smb2cli_flush(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1439 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1440 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1441 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1445 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1446 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1447 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1448 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1452 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1453 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1454 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1455 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1462 bool run_smb2_session_reauth(int dummy
)
1464 struct cli_state
*cli
;
1467 uint64_t fid_persistent
, fid_volatile
;
1468 uint64_t dir_persistent
, dir_volatile
;
1470 uint32_t dir_data_length
;
1471 struct tevent_context
*ev
;
1472 struct tevent_req
*subreq
;
1473 DATA_BLOB in_blob
= data_blob_null
;
1475 DATA_BLOB in_input_buffer
;
1476 DATA_BLOB out_output_buffer
;
1477 uint8_t in_file_info_class
;
1478 struct auth_generic_state
*auth_generic_state
;
1479 struct iovec
*recv_iov
;
1481 struct smbXcli_tcon
*saved_tcon
;
1483 printf("Starting SMB2-SESSION_REAUTH\n");
1485 if (!torture_init_connection(&cli
)) {
1490 * PROTOCOL_SMB2_22 has a bug in win8pre0
1491 * it behaves like PROTOCOL_SMB2_02
1492 * and returns NT_STATUS_REQUEST_NOT_ACCEPTED,
1493 * while it allows it on PROTOCOL_SMB2_02.
1495 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
1496 PROTOCOL_SMB2_10
, PROTOCOL_SMB2_10
);
1497 if (!NT_STATUS_IS_OK(status
)) {
1498 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
1502 status
= cli_session_setup(cli
, username
,
1503 password
, strlen(password
),
1504 password
, strlen(password
),
1506 if (!NT_STATUS_IS_OK(status
)) {
1507 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status
));
1511 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
1512 if (!NT_STATUS_IS_OK(status
)) {
1513 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1517 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1518 cli
->smb2
.tcon
, "session-reauth.txt",
1519 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1520 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1521 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1522 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1523 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1524 FILE_CREATE
, /* create_disposition, */
1525 FILE_DELETE_ON_CLOSE
, /* create_options, */
1526 NULL
, /* smb2_create_blobs *blobs */
1530 if (!NT_STATUS_IS_OK(status
)) {
1531 printf("smb2cli_create %s\n", nt_errstr(status
));
1535 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1537 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1538 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1539 SEC_STD_SYNCHRONIZE
|
1541 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
1542 0, /* file_attributes, */
1543 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1544 FILE_OPEN
, /* create_disposition, */
1545 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
1546 NULL
, /* smb2_create_blobs *blobs */
1550 if (!NT_STATUS_IS_OK(status
)) {
1551 printf("smb2cli_create returned %s\n", nt_errstr(status
));
1555 status
= smb2cli_query_directory(
1556 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
1557 1, 0x3, 0, dir_persistent
, dir_volatile
,
1558 "session-reauth.txt", 0xffff,
1559 talloc_tos(), &dir_data
, &dir_data_length
);
1560 if (!NT_STATUS_IS_OK(status
)) {
1561 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1565 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1566 if (!NT_STATUS_IS_OK(status
)) {
1567 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1571 gensec_want_feature(auth_generic_state
->gensec_security
,
1572 GENSEC_FEATURE_SESSION_KEY
);
1573 status
= auth_generic_set_username(auth_generic_state
, username
);
1574 if (!NT_STATUS_IS_OK(status
)) {
1575 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
1579 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
1580 if (!NT_STATUS_IS_OK(status
)) {
1581 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
1585 status
= auth_generic_set_password(auth_generic_state
, password
);
1586 if (!NT_STATUS_IS_OK(status
)) {
1587 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
1591 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1592 if (!NT_STATUS_IS_OK(status
)) {
1593 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1597 ev
= samba_tevent_context_init(talloc_tos());
1599 printf("samba_tevent_context_init() returned NULL\n");
1603 status
= gensec_update(auth_generic_state
->gensec_security
,
1604 talloc_tos(), data_blob_null
, &in_blob
);
1605 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1606 printf("gensec_update returned %s\n", nt_errstr(status
));
1610 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1615 SMB2_CAP_DFS
, /* in_capabilities */
1617 0, /* in_previous_session_id */
1618 &in_blob
); /* in_security_buffer */
1619 if (subreq
== NULL
) {
1620 printf("smb2cli_session_setup_send() returned NULL\n");
1624 ok
= tevent_req_poll(subreq
, ev
);
1626 printf("tevent_req_poll() returned false\n");
1630 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1632 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1633 printf("smb2cli_session_setup_recv returned %s\n",
1638 status
= gensec_update(auth_generic_state
->gensec_security
,
1639 talloc_tos(), out_blob
, &in_blob
);
1640 if (!NT_STATUS_IS_OK(status
)) {
1641 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1645 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1646 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1647 if (!NT_STATUS_IS_OK(status
)) {
1648 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1652 status
= smb2cli_query_directory(
1653 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
1654 1, 0x3, 0, dir_persistent
, dir_volatile
,
1655 "session-reauth.txt", 0xffff,
1656 talloc_tos(), &dir_data
, &dir_data_length
);
1657 if (!NT_STATUS_IS_OK(status
)) {
1658 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1663 * query_info seems to be a path based operation on Windows...
1665 status
= smb2cli_query_info(cli
->conn
,
1669 SMB2_GETINFO_SECURITY
,
1670 0, /* in_file_info_class */
1671 1024, /* in_max_output_length */
1672 NULL
, /* in_input_buffer */
1673 SECINFO_OWNER
, /* in_additional_info */
1678 &out_output_buffer
);
1679 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1680 printf("smb2cli_query_info (security) returned %s\n", nt_errstr(status
));
1684 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1685 status
= smb2cli_query_info(cli
->conn
,
1691 1024, /* in_max_output_length */
1692 NULL
, /* in_input_buffer */
1693 0, /* in_additional_info */
1698 &out_output_buffer
);
1699 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1700 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1704 in_input_buffer
= data_blob_talloc(talloc_tos(), NULL
, 8);
1705 SBVAL(in_input_buffer
.data
, 0, 512);
1707 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1708 status
= smb2cli_set_info(cli
->conn
,
1715 0, /* in_additional_info */
1718 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1719 printf("smb2cli_set_info (position) returned %s\n", nt_errstr(status
));
1723 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1724 cli
->smb2
.tcon
, "session-reauth-invalid.txt",
1725 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1726 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1727 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1728 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1729 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1730 FILE_CREATE
, /* create_disposition, */
1731 FILE_DELETE_ON_CLOSE
, /* create_options, */
1732 NULL
, /* smb2_create_blobs *blobs */
1736 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1737 printf("smb2cli_create %s\n", nt_errstr(status
));
1741 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1743 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1744 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1745 SEC_STD_SYNCHRONIZE
|
1747 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
1748 0, /* file_attributes, */
1749 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1750 FILE_OPEN
, /* create_disposition, */
1751 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
1752 NULL
, /* smb2_create_blobs *blobs */
1756 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1757 printf("smb2cli_create returned %s\n", nt_errstr(status
));
1761 saved_tid
= smb2cli_tcon_current_id(cli
->smb2
.tcon
);
1762 saved_tcon
= cli
->smb2
.tcon
;
1763 cli
->smb2
.tcon
= smbXcli_tcon_create(cli
);
1764 smb2cli_tcon_set_values(cli
->smb2
.tcon
,
1769 0, /* capabilities */
1770 0 /* maximal_access */);
1771 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
1772 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1773 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1776 talloc_free(cli
->smb2
.tcon
);
1777 cli
->smb2
.tcon
= saved_tcon
;
1779 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1784 SMB2_CAP_DFS
, /* in_capabilities */
1786 0, /* in_previous_session_id */
1787 &in_blob
); /* in_security_buffer */
1788 if (subreq
== NULL
) {
1789 printf("smb2cli_session_setup_send() returned NULL\n");
1793 ok
= tevent_req_poll(subreq
, ev
);
1795 printf("tevent_req_poll() returned false\n");
1799 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1800 &recv_iov
, &out_blob
);
1801 if (!NT_STATUS_IS_OK(status
)) {
1802 printf("smb2cli_session_setup_recv returned %s\n",
1807 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1808 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1809 if (!NT_STATUS_IS_OK(status
)) {
1810 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1814 status
= smb2cli_query_info(cli
->conn
,
1818 SMB2_GETINFO_SECURITY
,
1819 0, /* in_file_info_class */
1820 1024, /* in_max_output_length */
1821 NULL
, /* in_input_buffer */
1822 SECINFO_OWNER
, /* in_additional_info */
1827 &out_output_buffer
);
1828 if (!NT_STATUS_IS_OK(status
)) {
1829 printf("smb2cli_query_info (security) returned %s\n", nt_errstr(status
));
1833 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1834 status
= smb2cli_query_info(cli
->conn
,
1840 1024, /* in_max_output_length */
1841 NULL
, /* in_input_buffer */
1842 0, /* in_additional_info */
1847 &out_output_buffer
);
1848 if (!NT_STATUS_IS_OK(status
)) {
1849 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1853 in_input_buffer
= data_blob_talloc(talloc_tos(), NULL
, 8);
1854 SBVAL(in_input_buffer
.data
, 0, 512);
1856 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1857 status
= smb2cli_set_info(cli
->conn
,
1864 0, /* in_additional_info */
1867 if (!NT_STATUS_IS_OK(status
)) {
1868 printf("smb2cli_set_info (position) returned %s\n", nt_errstr(status
));
1872 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1873 status
= smb2cli_query_info(cli
->conn
,
1879 1024, /* in_max_output_length */
1880 NULL
, /* in_input_buffer */
1881 0, /* in_additional_info */
1886 &out_output_buffer
);
1887 if (!NT_STATUS_IS_OK(status
)) {
1888 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1892 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1893 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
1894 if (!NT_STATUS_IS_OK(status
)) {
1895 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1899 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1900 cli
->smb2
.tcon
, "session-reauth.txt",
1901 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1902 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1903 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1904 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1905 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1906 FILE_CREATE
, /* create_disposition, */
1907 FILE_DELETE_ON_CLOSE
, /* create_options, */
1908 NULL
, /* smb2_create_blobs *blobs */
1912 if (!NT_STATUS_IS_OK(status
)) {
1913 printf("smb2cli_create %s\n", nt_errstr(status
));
1917 status
= smb2cli_query_directory(
1918 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
1919 1, 0x3, 0, dir_persistent
, dir_volatile
,
1920 "session-reauth.txt", 0xffff,
1921 talloc_tos(), &dir_data
, &dir_data_length
);
1922 if (!NT_STATUS_IS_OK(status
)) {
1923 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1927 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1928 cli
->smb2
.tcon
, 0, dir_persistent
, dir_volatile
);
1929 if (!NT_STATUS_IS_OK(status
)) {
1930 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1934 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1935 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
1936 if (!NT_STATUS_IS_OK(status
)) {
1937 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1941 saved_tid
= smb2cli_tcon_current_id(cli
->smb2
.tcon
);
1942 saved_tcon
= cli
->smb2
.tcon
;
1943 cli
->smb2
.tcon
= smbXcli_tcon_create(cli
);
1944 smb2cli_tcon_set_values(cli
->smb2
.tcon
,
1949 0, /* capabilities */
1950 0 /* maximal_access */);
1951 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
1952 if (!NT_STATUS_IS_OK(status
)) {
1953 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1956 talloc_free(cli
->smb2
.tcon
);
1957 cli
->smb2
.tcon
= saved_tcon
;