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
,
444 talloc_tos(), data_blob_null
, &in_blob
);
445 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
446 printf("gensec_update returned %s\n", nt_errstr(status
));
450 cli2
->smb2
.session
= smbXcli_session_create(cli2
, cli2
->conn
);
452 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
457 SMB2_CAP_DFS
, /* in_capabilities */
459 /* in_previous_session_id: */
460 smb2cli_session_current_id(cli1
->smb2
.session
),
461 &in_blob
); /* in_security_buffer */
462 if (subreq
== NULL
) {
463 printf("smb2cli_session_setup_send() returned NULL\n");
467 ok
= tevent_req_poll(subreq
, ev
);
469 printf("tevent_req_poll() returned false\n");
473 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
475 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
476 printf("smb2cli_session_setup_recv returned %s\n",
481 status
= gensec_update(auth_generic_state
->gensec_security
,
482 talloc_tos(), out_blob
, &in_blob
);
483 if (!NT_STATUS_IS_OK(status
)) {
484 printf("auth_generic_update returned %s\n", nt_errstr(status
));
488 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
493 SMB2_CAP_DFS
, /* in_capabilities */
495 /* in_previous_session_id: */
496 smb2cli_session_current_id(cli1
->smb2
.session
),
497 &in_blob
); /* in_security_buffer */
498 if (subreq
== NULL
) {
499 printf("smb2cli_session_setup_send() returned NULL\n");
503 ok
= tevent_req_poll(subreq
, ev
);
505 printf("tevent_req_poll() returned false\n");
509 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
510 &recv_iov
, &out_blob
);
511 if (!NT_STATUS_IS_OK(status
)) {
512 printf("smb2cli_session_setup_recv returned %s\n",
517 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
519 if (!NT_STATUS_IS_OK(status
)) {
520 printf("gensec_session_key returned %s\n",
525 /* check file operation on the old client */
527 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
528 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
529 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
530 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
534 status
= cli_tree_connect(cli1
, share
, "?????", "", 0);
535 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
536 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
541 * checking file operations without signing.
542 * on w2k8r2 at least, flush, read and write also work the same way,
543 * while create gives ACCESS_DENIED without signing
545 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
546 cli2
->smb2
.tcon
, fid_persistent
, fid_volatile
);
547 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
548 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
550 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
554 status
= smb2cli_write(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
555 cli2
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
556 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
557 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
558 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
560 printf("smb2cli_write returned %s\n", nt_errstr(status
));
564 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
565 cli2
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
567 talloc_tos(), &result
, &nread
);
568 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
569 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
571 printf("smb2cli_read returned %s\n", nt_errstr(status
));
575 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
576 cli2
->smb2
.tcon
, "session-reconnect.txt",
577 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
578 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
579 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
580 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
581 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
582 FILE_CREATE
, /* create_disposition, */
583 FILE_DELETE_ON_CLOSE
, /* create_options, */
584 NULL
, /* smb2_create_blobs *blobs */
588 if (!NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
) &&
589 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
590 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
594 /* now grab the session key and try with signing */
596 status
= smb2cli_session_set_session_key(cli2
->smb2
.session
,
599 if (!NT_STATUS_IS_OK(status
)) {
600 printf("smb2cli_session_set_session_key %s\n", nt_errstr(status
));
604 /* the tid seems to be irrelevant at this stage */
606 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
607 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
608 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
609 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
611 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
615 status
= smb2cli_write(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
616 cli1
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
617 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
618 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
619 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
621 printf("smb2cli_write returned %s\n", nt_errstr(status
));
625 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
626 cli1
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
628 talloc_tos(), &result
, &nread
);
629 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
630 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
632 printf("smb2cli_read returned %s\n", nt_errstr(status
));
636 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
637 cli1
->smb2
.tcon
, "session-reconnect.txt",
638 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
639 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
640 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
641 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
642 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
643 FILE_CREATE
, /* create_disposition, */
644 FILE_DELETE_ON_CLOSE
, /* create_options, */
645 NULL
, /* smb2_create_blobs *blobs */
649 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
) &&
650 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
652 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
656 /* now do a new tcon and test file calls again */
658 status
= cli_tree_connect(cli2
, share
, "?????", "", 0);
659 if (!NT_STATUS_IS_OK(status
)) {
660 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
664 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
665 cli2
->smb2
.tcon
, "session-reconnect.txt",
666 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
667 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
668 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
669 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
670 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
671 FILE_CREATE
, /* create_disposition, */
672 FILE_DELETE_ON_CLOSE
, /* create_options, */
673 NULL
, /* smb2_create_blobs *blobs */
677 if (!NT_STATUS_IS_OK(status
)) {
678 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
682 status
= smb2cli_write(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
683 cli2
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
684 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
685 if (!NT_STATUS_IS_OK(status
)) {
686 printf("smb2cli_write returned %s\n", nt_errstr(status
));
690 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
691 cli2
->smb2
.tcon
, fid_persistent
, fid_volatile
);
692 if (!NT_STATUS_IS_OK(status
)) {
693 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
697 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
698 cli2
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
700 talloc_tos(), &result
, &nread
);
701 if (!NT_STATUS_IS_OK(status
)) {
702 printf("smb2cli_read returned %s\n", nt_errstr(status
));
706 if (nread
!= strlen(hello
)) {
707 printf("smb2cli_read returned %d bytes, expected %d\n",
708 (int)nread
, (int)strlen(hello
));
712 if (memcmp(hello
, result
, nread
) != 0) {
713 printf("smb2cli_read returned '%s', expected '%s'\n",
721 bool run_smb2_tcon_dependence(int dummy
)
723 struct cli_state
*cli
;
725 uint64_t fid_persistent
, fid_volatile
;
726 const char *hello
= "Hello, world\n";
729 struct smbXcli_tcon
*tcon2
;
732 printf("Starting SMB2-TCON-DEPENDENCE\n");
734 if (!torture_init_connection(&cli
)) {
738 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
739 PROTOCOL_SMB2_02
, PROTOCOL_LATEST
);
740 if (!NT_STATUS_IS_OK(status
)) {
741 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
745 status
= cli_session_setup(cli
, username
,
746 password
, strlen(password
),
747 password
, strlen(password
),
749 if (!NT_STATUS_IS_OK(status
)) {
750 printf("cli_session_setup returned %s\n", nt_errstr(status
));
754 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
755 if (!NT_STATUS_IS_OK(status
)) {
756 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
760 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
761 cli
->smb2
.tcon
, "tcon_depedence.txt",
762 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
763 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
764 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
765 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
766 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
767 FILE_CREATE
, /* create_disposition, */
768 FILE_DELETE_ON_CLOSE
, /* create_options, */
769 NULL
, /* smb2_create_blobs *blobs */
773 if (!NT_STATUS_IS_OK(status
)) {
774 printf("smb2cli_create on cli %s\n", nt_errstr(status
));
778 status
= smb2cli_write(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
779 cli
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
780 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
781 if (!NT_STATUS_IS_OK(status
)) {
782 printf("smb2cli_write returned %s\n", nt_errstr(status
));
786 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
787 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
788 if (!NT_STATUS_IS_OK(status
)) {
789 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
793 status
= smb2cli_read(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
794 cli
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
796 talloc_tos(), &result
, &nread
);
797 if (!NT_STATUS_IS_OK(status
)) {
798 printf("smb2cli_read returned %s\n", nt_errstr(status
));
802 if (nread
!= strlen(hello
)) {
803 printf("smb2cli_read returned %d bytes, expected %d\n",
804 (int)nread
, (int)strlen(hello
));
808 if (memcmp(hello
, result
, nread
) != 0) {
809 printf("smb2cli_read returned '%s', expected '%s'\n",
814 /* check behaviour with wrong tid... */
816 tcon2
= smbXcli_tcon_create(cli
);
817 tcon2_id
= smb2cli_tcon_current_id(cli
->smb2
.tcon
);
819 smb2cli_tcon_set_values(tcon2
,
824 0, /* capabilities */
825 0 /* maximal_access */);
827 status
= smb2cli_read(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
828 tcon2
, 0x10000, 0, fid_persistent
,
830 talloc_tos(), &result
, &nread
);
831 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
832 printf("smb2cli_read returned %s\n", nt_errstr(status
));
841 bool run_smb2_multi_channel(int dummy
)
843 struct cli_state
*cli1
;
844 struct cli_state
*cli2
;
845 struct cli_state
*cli3
;
848 uint64_t fid_persistent
, fid_volatile
;
849 struct tevent_context
*ev
;
850 struct tevent_req
*subreq
;
851 DATA_BLOB in_blob
= data_blob_null
;
853 DATA_BLOB channel_session_key
;
854 struct auth_generic_state
*auth_generic_state
;
855 struct iovec
*recv_iov
;
856 const char *hello
= "Hello, world\n";
860 printf("Starting SMB2-MULTI-CHANNEL\n");
862 if (!torture_init_connection(&cli1
)) {
866 if (!torture_init_connection(&cli2
)) {
870 if (!torture_init_connection(&cli3
)) {
874 status
= smbXcli_negprot(cli1
->conn
, cli1
->timeout
,
875 PROTOCOL_SMB2_22
, PROTOCOL_LATEST
);
876 if (!NT_STATUS_IS_OK(status
)) {
877 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
881 status
= smbXcli_negprot(cli2
->conn
, cli2
->timeout
,
882 PROTOCOL_SMB2_22
, PROTOCOL_LATEST
);
883 if (!NT_STATUS_IS_OK(status
)) {
884 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
888 status
= smbXcli_negprot(cli3
->conn
, cli3
->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
= cli_session_setup(cli1
, username
,
896 password
, strlen(password
),
897 password
, strlen(password
),
899 if (!NT_STATUS_IS_OK(status
)) {
900 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status
));
904 status
= cli_tree_connect(cli1
, share
, "?????", "", 0);
905 if (!NT_STATUS_IS_OK(status
)) {
906 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
910 status
= smb2cli_session_create_channel(cli2
,
913 &cli2
->smb2
.session
);
914 if (!NT_STATUS_IS_OK(status
)) {
915 printf("smb2cli_session_create_channel returned %s\n",
920 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
921 if (!NT_STATUS_IS_OK(status
)) {
922 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
926 gensec_want_feature(auth_generic_state
->gensec_security
,
927 GENSEC_FEATURE_SESSION_KEY
);
928 status
= auth_generic_set_username(auth_generic_state
, username
);
929 if (!NT_STATUS_IS_OK(status
)) {
930 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
934 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
935 if (!NT_STATUS_IS_OK(status
)) {
936 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
940 status
= auth_generic_set_password(auth_generic_state
, password
);
941 if (!NT_STATUS_IS_OK(status
)) {
942 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
946 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
947 if (!NT_STATUS_IS_OK(status
)) {
948 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
952 ev
= samba_tevent_context_init(talloc_tos());
954 printf("samba_tevent_context_init() returned NULL\n");
958 status
= gensec_update(auth_generic_state
->gensec_security
,
959 talloc_tos(), data_blob_null
, &in_blob
);
960 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
961 printf("gensec_update returned %s\n", nt_errstr(status
));
965 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
970 SMB2_CAP_DFS
, /* in_capabilities */
972 0, /* in_previous_session_id */
973 &in_blob
); /* in_security_buffer */
974 if (subreq
== NULL
) {
975 printf("smb2cli_session_setup_send() returned NULL\n");
979 ok
= tevent_req_poll(subreq
, ev
);
981 printf("tevent_req_poll() returned false\n");
985 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
987 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
988 printf("smb2cli_session_setup_recv returned %s\n",
993 status
= gensec_update(auth_generic_state
->gensec_security
,
994 talloc_tos(), out_blob
, &in_blob
);
995 if (!NT_STATUS_IS_OK(status
)) {
996 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1000 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1004 0x01, /* in_flags */
1005 SMB2_CAP_DFS
, /* in_capabilities */
1007 0, /* in_previous_session_id */
1008 &in_blob
); /* in_security_buffer */
1009 if (subreq
== NULL
) {
1010 printf("smb2cli_session_setup_send() returned NULL\n");
1014 ok
= tevent_req_poll(subreq
, ev
);
1016 printf("tevent_req_poll() returned false\n");
1020 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1021 &recv_iov
, &out_blob
);
1022 if (!NT_STATUS_IS_OK(status
)) {
1023 printf("smb2cli_session_setup_recv returned %s\n",
1028 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
1029 &channel_session_key
);
1030 if (!NT_STATUS_IS_OK(status
)) {
1031 printf("gensec_session_key returned %s\n",
1036 status
= smb2cli_session_set_channel_key(cli2
->smb2
.session
,
1037 channel_session_key
,
1039 if (!NT_STATUS_IS_OK(status
)) {
1040 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status
));
1044 status
= smb2cli_session_create_channel(cli3
,
1047 &cli3
->smb2
.session
);
1048 if (!NT_STATUS_IS_OK(status
)) {
1049 printf("smb2cli_session_create_channel returned %s\n",
1054 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1055 if (!NT_STATUS_IS_OK(status
)) {
1056 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1060 gensec_want_feature(auth_generic_state
->gensec_security
,
1061 GENSEC_FEATURE_SESSION_KEY
);
1062 status
= auth_generic_set_username(auth_generic_state
, username
);
1063 if (!NT_STATUS_IS_OK(status
)) {
1064 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
1068 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
1069 if (!NT_STATUS_IS_OK(status
)) {
1070 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
1074 status
= auth_generic_set_password(auth_generic_state
, password
);
1075 if (!NT_STATUS_IS_OK(status
)) {
1076 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
1080 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1081 if (!NT_STATUS_IS_OK(status
)) {
1082 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1086 status
= gensec_update(auth_generic_state
->gensec_security
,
1087 talloc_tos(), data_blob_null
, &in_blob
);
1088 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1089 printf("gensec_update returned %s\n", nt_errstr(status
));
1093 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1097 0x01, /* in_flags */
1098 SMB2_CAP_DFS
, /* in_capabilities */
1100 0, /* in_previous_session_id */
1101 &in_blob
); /* in_security_buffer */
1102 if (subreq
== NULL
) {
1103 printf("smb2cli_session_setup_send() returned NULL\n");
1107 ok
= tevent_req_poll(subreq
, ev
);
1109 printf("tevent_req_poll() returned false\n");
1113 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1115 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1116 printf("smb2cli_session_setup_recv returned %s\n",
1121 status
= gensec_update(auth_generic_state
->gensec_security
,
1122 talloc_tos(), out_blob
, &in_blob
);
1123 if (!NT_STATUS_IS_OK(status
)) {
1124 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1128 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1132 0x01, /* in_flags */
1133 SMB2_CAP_DFS
, /* in_capabilities */
1135 0, /* in_previous_session_id */
1136 &in_blob
); /* in_security_buffer */
1137 if (subreq
== NULL
) {
1138 printf("smb2cli_session_setup_send() returned NULL\n");
1142 ok
= tevent_req_poll(subreq
, ev
);
1144 printf("tevent_req_poll() returned false\n");
1148 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1149 &recv_iov
, &out_blob
);
1150 if (!NT_STATUS_IS_OK(status
)) {
1151 printf("smb2cli_session_setup_recv returned %s\n",
1156 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
1157 &channel_session_key
);
1158 if (!NT_STATUS_IS_OK(status
)) {
1159 printf("gensec_session_key returned %s\n",
1164 status
= smb2cli_session_set_channel_key(cli3
->smb2
.session
,
1165 channel_session_key
,
1167 if (!NT_STATUS_IS_OK(status
)) {
1168 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status
));
1172 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1173 cli1
->smb2
.tcon
, "multi-channel.txt",
1174 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1175 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1176 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1177 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1178 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1179 FILE_CREATE
, /* create_disposition, */
1180 FILE_DELETE_ON_CLOSE
, /* create_options, */
1181 NULL
, /* smb2_create_blobs *blobs */
1185 if (!NT_STATUS_IS_OK(status
)) {
1186 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
1190 status
= smb2cli_write(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1191 cli1
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
1192 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
1193 if (!NT_STATUS_IS_OK(status
)) {
1194 printf("smb2cli_write returned %s\n", nt_errstr(status
));
1198 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1199 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1200 if (!NT_STATUS_IS_OK(status
)) {
1201 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1205 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1206 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1207 if (!NT_STATUS_IS_OK(status
)) {
1208 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1212 status
= smb2cli_flush(cli3
->conn
, cli3
->timeout
, cli3
->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_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1220 cli1
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
1222 talloc_tos(), &result
, &nread
);
1223 if (!NT_STATUS_IS_OK(status
)) {
1224 printf("smb2cli_read returned %s\n", nt_errstr(status
));
1228 if (nread
!= strlen(hello
)) {
1229 printf("smb2cli_read returned %d bytes, expected %d\n",
1230 (int)nread
, (int)strlen(hello
));
1234 if (memcmp(hello
, result
, nread
) != 0) {
1235 printf("smb2cli_read returned '%s', expected '%s'\n",
1240 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1241 if (!NT_STATUS_IS_OK(status
)) {
1242 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1246 gensec_want_feature(auth_generic_state
->gensec_security
,
1247 GENSEC_FEATURE_SESSION_KEY
);
1248 status
= auth_generic_set_username(auth_generic_state
, username
);
1249 if (!NT_STATUS_IS_OK(status
)) {
1250 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
1254 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
1255 if (!NT_STATUS_IS_OK(status
)) {
1256 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
1260 status
= auth_generic_set_password(auth_generic_state
, password
);
1261 if (!NT_STATUS_IS_OK(status
)) {
1262 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
1266 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1267 if (!NT_STATUS_IS_OK(status
)) {
1268 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1272 status
= gensec_update(auth_generic_state
->gensec_security
,
1273 talloc_tos(), data_blob_null
, &in_blob
);
1274 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1275 printf("gensec_update returned %s\n", nt_errstr(status
));
1279 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1284 SMB2_CAP_DFS
, /* in_capabilities */
1286 0, /* in_previous_session_id */
1287 &in_blob
); /* in_security_buffer */
1288 if (subreq
== NULL
) {
1289 printf("smb2cli_session_setup_send() returned NULL\n");
1293 ok
= tevent_req_poll(subreq
, ev
);
1295 printf("tevent_req_poll() returned false\n");
1299 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1301 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1302 printf("smb2cli_session_setup_recv returned %s\n",
1307 status
= gensec_update(auth_generic_state
->gensec_security
,
1308 talloc_tos(), out_blob
, &in_blob
);
1309 if (!NT_STATUS_IS_OK(status
)) {
1310 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1314 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1315 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1316 if (!NT_STATUS_IS_OK(status
)) {
1317 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1321 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1322 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1323 if (!NT_STATUS_IS_OK(status
)) {
1324 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1328 status
= smb2cli_flush(cli3
->conn
, cli3
->timeout
, cli3
->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_create(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1336 cli1
->smb2
.tcon
, "multi-channel-invalid.txt",
1337 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1338 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1339 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1340 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1341 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1342 FILE_CREATE
, /* create_disposition, */
1343 FILE_DELETE_ON_CLOSE
, /* create_options, */
1344 NULL
, /* smb2_create_blobs *blobs */
1348 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1349 printf("smb2cli_create %s\n", nt_errstr(status
));
1353 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1354 cli1
->smb2
.tcon
, "multi-channel-invalid.txt",
1355 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1356 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1357 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1358 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1359 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1360 FILE_CREATE
, /* create_disposition, */
1361 FILE_DELETE_ON_CLOSE
, /* create_options, */
1362 NULL
, /* smb2_create_blobs *blobs */
1366 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1367 printf("smb2cli_create %s\n", nt_errstr(status
));
1371 status
= smb2cli_create(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1372 cli1
->smb2
.tcon
, "multi-channel-invalid.txt",
1373 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1374 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1375 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1376 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1377 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1378 FILE_CREATE
, /* create_disposition, */
1379 FILE_DELETE_ON_CLOSE
, /* create_options, */
1380 NULL
, /* smb2_create_blobs *blobs */
1384 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1385 printf("smb2cli_create %s\n", nt_errstr(status
));
1389 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1394 SMB2_CAP_DFS
, /* in_capabilities */
1396 0, /* in_previous_session_id */
1397 &in_blob
); /* in_security_buffer */
1398 if (subreq
== NULL
) {
1399 printf("smb2cli_session_setup_send() returned NULL\n");
1403 ok
= tevent_req_poll(subreq
, ev
);
1405 printf("tevent_req_poll() returned false\n");
1409 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1410 &recv_iov
, &out_blob
);
1411 if (!NT_STATUS_IS_OK(status
)) {
1412 printf("smb2cli_session_setup_recv returned %s\n",
1417 status
= smb2cli_close(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1418 cli1
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
1419 if (!NT_STATUS_IS_OK(status
)) {
1420 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1424 status
= smb2cli_flush(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1425 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1426 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1427 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1431 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1432 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1433 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1434 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1438 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->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
));
1448 bool run_smb2_session_reauth(int dummy
)
1450 struct cli_state
*cli
;
1453 uint64_t fid_persistent
, fid_volatile
;
1454 uint64_t dir_persistent
, dir_volatile
;
1456 uint32_t dir_data_length
;
1457 struct tevent_context
*ev
;
1458 struct tevent_req
*subreq
;
1459 DATA_BLOB in_blob
= data_blob_null
;
1461 DATA_BLOB in_input_buffer
;
1462 DATA_BLOB out_output_buffer
;
1463 uint8_t in_file_info_class
;
1464 struct auth_generic_state
*auth_generic_state
;
1465 struct iovec
*recv_iov
;
1467 struct smbXcli_tcon
*saved_tcon
;
1469 printf("Starting SMB2-SESSION_REAUTH\n");
1471 if (!torture_init_connection(&cli
)) {
1476 * PROTOCOL_SMB2_22 has a bug in win8pre0
1477 * it behaves like PROTOCOL_SMB2_02
1478 * and returns NT_STATUS_REQUEST_NOT_ACCEPTED,
1479 * while it allows it on PROTOCOL_SMB2_02.
1481 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
1482 PROTOCOL_SMB2_10
, PROTOCOL_SMB2_10
);
1483 if (!NT_STATUS_IS_OK(status
)) {
1484 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
1488 status
= cli_session_setup(cli
, username
,
1489 password
, strlen(password
),
1490 password
, strlen(password
),
1492 if (!NT_STATUS_IS_OK(status
)) {
1493 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status
));
1497 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
1498 if (!NT_STATUS_IS_OK(status
)) {
1499 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1503 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1504 cli
->smb2
.tcon
, "session-reauth.txt",
1505 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1506 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1507 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1508 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1509 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1510 FILE_CREATE
, /* create_disposition, */
1511 FILE_DELETE_ON_CLOSE
, /* create_options, */
1512 NULL
, /* smb2_create_blobs *blobs */
1516 if (!NT_STATUS_IS_OK(status
)) {
1517 printf("smb2cli_create %s\n", nt_errstr(status
));
1521 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1523 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1524 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1525 SEC_STD_SYNCHRONIZE
|
1527 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
1528 0, /* file_attributes, */
1529 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1530 FILE_OPEN
, /* create_disposition, */
1531 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
1532 NULL
, /* smb2_create_blobs *blobs */
1536 if (!NT_STATUS_IS_OK(status
)) {
1537 printf("smb2cli_create returned %s\n", nt_errstr(status
));
1541 status
= smb2cli_query_directory(
1542 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
1543 1, 0x3, 0, dir_persistent
, dir_volatile
,
1544 "session-reauth.txt", 0xffff,
1545 talloc_tos(), &dir_data
, &dir_data_length
);
1546 if (!NT_STATUS_IS_OK(status
)) {
1547 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1551 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1552 if (!NT_STATUS_IS_OK(status
)) {
1553 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1557 gensec_want_feature(auth_generic_state
->gensec_security
,
1558 GENSEC_FEATURE_SESSION_KEY
);
1559 status
= auth_generic_set_username(auth_generic_state
, username
);
1560 if (!NT_STATUS_IS_OK(status
)) {
1561 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
1565 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
1566 if (!NT_STATUS_IS_OK(status
)) {
1567 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
1571 status
= auth_generic_set_password(auth_generic_state
, password
);
1572 if (!NT_STATUS_IS_OK(status
)) {
1573 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
1577 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1578 if (!NT_STATUS_IS_OK(status
)) {
1579 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1583 ev
= samba_tevent_context_init(talloc_tos());
1585 printf("samba_tevent_context_init() returned NULL\n");
1589 status
= gensec_update(auth_generic_state
->gensec_security
,
1590 talloc_tos(), data_blob_null
, &in_blob
);
1591 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1592 printf("gensec_update returned %s\n", nt_errstr(status
));
1596 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1601 SMB2_CAP_DFS
, /* in_capabilities */
1603 0, /* in_previous_session_id */
1604 &in_blob
); /* in_security_buffer */
1605 if (subreq
== NULL
) {
1606 printf("smb2cli_session_setup_send() returned NULL\n");
1610 ok
= tevent_req_poll(subreq
, ev
);
1612 printf("tevent_req_poll() returned false\n");
1616 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1618 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1619 printf("smb2cli_session_setup_recv returned %s\n",
1624 status
= gensec_update(auth_generic_state
->gensec_security
,
1625 talloc_tos(), out_blob
, &in_blob
);
1626 if (!NT_STATUS_IS_OK(status
)) {
1627 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1631 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1632 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1633 if (!NT_STATUS_IS_OK(status
)) {
1634 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1638 status
= smb2cli_query_directory(
1639 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
1640 1, 0x3, 0, dir_persistent
, dir_volatile
,
1641 "session-reauth.txt", 0xffff,
1642 talloc_tos(), &dir_data
, &dir_data_length
);
1643 if (!NT_STATUS_IS_OK(status
)) {
1644 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1649 * query_info seems to be a path based operation on Windows...
1651 status
= smb2cli_query_info(cli
->conn
,
1655 SMB2_GETINFO_SECURITY
,
1656 0, /* in_file_info_class */
1657 1024, /* in_max_output_length */
1658 NULL
, /* in_input_buffer */
1659 SECINFO_OWNER
, /* in_additional_info */
1664 &out_output_buffer
);
1665 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1666 printf("smb2cli_query_info (security) returned %s\n", nt_errstr(status
));
1670 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1671 status
= smb2cli_query_info(cli
->conn
,
1677 1024, /* in_max_output_length */
1678 NULL
, /* in_input_buffer */
1679 0, /* in_additional_info */
1684 &out_output_buffer
);
1685 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1686 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1690 in_input_buffer
= data_blob_talloc(talloc_tos(), NULL
, 8);
1691 SBVAL(in_input_buffer
.data
, 0, 512);
1693 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1694 status
= smb2cli_set_info(cli
->conn
,
1701 0, /* in_additional_info */
1704 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1705 printf("smb2cli_set_info (position) returned %s\n", nt_errstr(status
));
1709 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1710 cli
->smb2
.tcon
, "session-reauth-invalid.txt",
1711 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1712 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1713 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1714 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1715 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1716 FILE_CREATE
, /* create_disposition, */
1717 FILE_DELETE_ON_CLOSE
, /* create_options, */
1718 NULL
, /* smb2_create_blobs *blobs */
1722 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1723 printf("smb2cli_create %s\n", nt_errstr(status
));
1727 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1729 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1730 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1731 SEC_STD_SYNCHRONIZE
|
1733 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
1734 0, /* file_attributes, */
1735 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1736 FILE_OPEN
, /* create_disposition, */
1737 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
1738 NULL
, /* smb2_create_blobs *blobs */
1742 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1743 printf("smb2cli_create returned %s\n", nt_errstr(status
));
1747 saved_tid
= smb2cli_tcon_current_id(cli
->smb2
.tcon
);
1748 saved_tcon
= cli
->smb2
.tcon
;
1749 cli
->smb2
.tcon
= smbXcli_tcon_create(cli
);
1750 smb2cli_tcon_set_values(cli
->smb2
.tcon
,
1755 0, /* capabilities */
1756 0 /* maximal_access */);
1757 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
1758 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1759 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1762 talloc_free(cli
->smb2
.tcon
);
1763 cli
->smb2
.tcon
= saved_tcon
;
1765 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1770 SMB2_CAP_DFS
, /* in_capabilities */
1772 0, /* in_previous_session_id */
1773 &in_blob
); /* in_security_buffer */
1774 if (subreq
== NULL
) {
1775 printf("smb2cli_session_setup_send() returned NULL\n");
1779 ok
= tevent_req_poll(subreq
, ev
);
1781 printf("tevent_req_poll() returned false\n");
1785 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1786 &recv_iov
, &out_blob
);
1787 if (!NT_STATUS_IS_OK(status
)) {
1788 printf("smb2cli_session_setup_recv returned %s\n",
1793 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1794 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1795 if (!NT_STATUS_IS_OK(status
)) {
1796 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1800 status
= smb2cli_query_info(cli
->conn
,
1804 SMB2_GETINFO_SECURITY
,
1805 0, /* in_file_info_class */
1806 1024, /* in_max_output_length */
1807 NULL
, /* in_input_buffer */
1808 SECINFO_OWNER
, /* in_additional_info */
1813 &out_output_buffer
);
1814 if (!NT_STATUS_IS_OK(status
)) {
1815 printf("smb2cli_query_info (security) returned %s\n", nt_errstr(status
));
1819 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1820 status
= smb2cli_query_info(cli
->conn
,
1826 1024, /* in_max_output_length */
1827 NULL
, /* in_input_buffer */
1828 0, /* in_additional_info */
1833 &out_output_buffer
);
1834 if (!NT_STATUS_IS_OK(status
)) {
1835 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1839 in_input_buffer
= data_blob_talloc(talloc_tos(), NULL
, 8);
1840 SBVAL(in_input_buffer
.data
, 0, 512);
1842 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1843 status
= smb2cli_set_info(cli
->conn
,
1850 0, /* in_additional_info */
1853 if (!NT_STATUS_IS_OK(status
)) {
1854 printf("smb2cli_set_info (position) returned %s\n", nt_errstr(status
));
1858 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1859 status
= smb2cli_query_info(cli
->conn
,
1865 1024, /* in_max_output_length */
1866 NULL
, /* in_input_buffer */
1867 0, /* in_additional_info */
1872 &out_output_buffer
);
1873 if (!NT_STATUS_IS_OK(status
)) {
1874 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1878 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1879 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
1880 if (!NT_STATUS_IS_OK(status
)) {
1881 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1885 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1886 cli
->smb2
.tcon
, "session-reauth.txt",
1887 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1888 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1889 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1890 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1891 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1892 FILE_CREATE
, /* create_disposition, */
1893 FILE_DELETE_ON_CLOSE
, /* create_options, */
1894 NULL
, /* smb2_create_blobs *blobs */
1898 if (!NT_STATUS_IS_OK(status
)) {
1899 printf("smb2cli_create %s\n", nt_errstr(status
));
1903 status
= smb2cli_query_directory(
1904 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
1905 1, 0x3, 0, dir_persistent
, dir_volatile
,
1906 "session-reauth.txt", 0xffff,
1907 talloc_tos(), &dir_data
, &dir_data_length
);
1908 if (!NT_STATUS_IS_OK(status
)) {
1909 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1913 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1914 cli
->smb2
.tcon
, 0, dir_persistent
, dir_volatile
);
1915 if (!NT_STATUS_IS_OK(status
)) {
1916 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1920 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1921 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
1922 if (!NT_STATUS_IS_OK(status
)) {
1923 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1927 saved_tid
= smb2cli_tcon_current_id(cli
->smb2
.tcon
);
1928 saved_tcon
= cli
->smb2
.tcon
;
1929 cli
->smb2
.tcon
= smbXcli_tcon_create(cli
);
1930 smb2cli_tcon_set_values(cli
->smb2
.tcon
,
1935 0, /* capabilities */
1936 0 /* maximal_access */);
1937 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
1938 if (!NT_STATUS_IS_OK(status
)) {
1939 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1942 talloc_free(cli
->smb2
.tcon
);
1943 cli
->smb2
.tcon
= saved_tcon
;