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 */
87 if (!NT_STATUS_IS_OK(status
)) {
88 printf("smb2cli_create returned %s\n", nt_errstr(status
));
92 status
= smb2cli_write(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
93 cli
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
94 fid_volatile
, 0, 0, (const uint8_t *)hello
);
95 if (!NT_STATUS_IS_OK(status
)) {
96 printf("smb2cli_write returned %s\n", nt_errstr(status
));
100 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
101 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
102 if (!NT_STATUS_IS_OK(status
)) {
103 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
107 status
= smb2cli_read(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
108 cli
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
110 talloc_tos(), &result
, &nread
);
111 if (!NT_STATUS_IS_OK(status
)) {
112 printf("smb2cli_read returned %s\n", nt_errstr(status
));
116 if (nread
!= strlen(hello
)) {
117 printf("smb2cli_read returned %d bytes, expected %d\n",
118 (int)nread
, (int)strlen(hello
));
122 if (memcmp(hello
, result
, nread
) != 0) {
123 printf("smb2cli_read returned '%s', expected '%s'\n",
128 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
129 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
130 if (!NT_STATUS_IS_OK(status
)) {
131 printf("smb2cli_close returned %s\n", nt_errstr(status
));
135 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
137 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
138 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
141 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
142 0, /* file_attributes, */
143 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
144 FILE_OPEN
, /* create_disposition, */
145 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
146 NULL
, /* smb2_create_blobs *blobs */
149 if (!NT_STATUS_IS_OK(status
)) {
150 printf("smb2cli_create returned %s\n", nt_errstr(status
));
154 status
= smb2cli_query_directory(
155 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
156 1, 0, 0, fid_persistent
, fid_volatile
, "*", 0xffff,
157 talloc_tos(), &dir_data
, &dir_data_length
);
159 if (!NT_STATUS_IS_OK(status
)) {
160 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
164 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
165 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
166 if (!NT_STATUS_IS_OK(status
)) {
167 printf("smb2cli_close returned %s\n", nt_errstr(status
));
171 saved_tid
= smb2cli_tcon_current_id(cli
->smb2
.tcon
);
172 saved_tcon
= cli
->smb2
.tcon
;
173 cli
->smb2
.tcon
= smbXcli_tcon_create(cli
);
174 smb2cli_tcon_set_values(cli
->smb2
.tcon
,
179 0, /* capabilities */
180 0 /* maximal_access */);
181 status
= smb2cli_tdis(cli
);
182 if (!NT_STATUS_IS_OK(status
)) {
183 printf("smb2cli_tdis returned %s\n", nt_errstr(status
));
186 talloc_free(cli
->smb2
.tcon
);
187 cli
->smb2
.tcon
= saved_tcon
;
189 status
= smb2cli_tdis(cli
);
190 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
191 printf("2nd smb2cli_tdis returned %s\n", nt_errstr(status
));
195 saved_uid
= smb2cli_session_current_id(cli
->smb2
.session
);
196 status
= smb2cli_logoff(cli
->conn
, cli
->timeout
, cli
->smb2
.session
);
197 if (!NT_STATUS_IS_OK(status
)) {
198 printf("smb2cli_logoff returned %s\n", nt_errstr(status
));
202 cli
->smb2
.session
= smbXcli_session_create(cli
, cli
->conn
);
203 if (cli
->smb2
.session
== NULL
) {
204 printf("smbXcli_session_create() returned NULL\n");
208 smb2cli_session_set_id_and_flags(cli
->smb2
.session
, saved_uid
, 0);
210 status
= smb2cli_logoff(cli
->conn
, cli
->timeout
, cli
->smb2
.session
);
211 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
212 printf("2nd smb2cli_logoff returned %s\n", nt_errstr(status
));
219 bool run_smb2_negprot(int dummy
)
221 struct cli_state
*cli
;
223 enum protocol_types protocol
;
224 const char *name
= NULL
;
226 printf("Starting SMB2-NEGPROT\n");
228 if (!torture_init_connection(&cli
)) {
232 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
233 PROTOCOL_CORE
, PROTOCOL_LATEST
);
234 if (!NT_STATUS_IS_OK(status
)) {
235 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
239 protocol
= smbXcli_conn_protocol(cli
->conn
);
242 case PROTOCOL_SMB2_02
:
245 case PROTOCOL_SMB2_10
:
248 case PROTOCOL_SMB2_22
:
251 case PROTOCOL_SMB2_24
:
254 case PROTOCOL_SMB3_00
:
262 printf("Server supports %s\n", name
);
264 printf("Server DOES NOT support SMB2\n");
268 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
270 if (!NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_RESET
) &&
271 !NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_DISCONNECTED
) &&
272 !NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_ABORTED
)) {
273 printf("2nd smbXcli_negprot should disconnect - returned %s\n",
278 if (smbXcli_conn_is_connected(cli
->conn
)) {
279 printf("2nd smbXcli_negprot should disconnect "
280 "- still connected\n");
287 bool run_smb2_session_reconnect(int dummy
)
289 struct cli_state
*cli1
;
290 struct cli_state
*cli2
;
293 uint64_t fid_persistent
, fid_volatile
;
294 struct tevent_context
*ev
;
295 struct tevent_req
*subreq
;
296 DATA_BLOB in_blob
= data_blob_null
;
298 DATA_BLOB session_key
;
299 struct auth_generic_state
*auth_generic_state
;
300 struct iovec
*recv_iov
;
301 const char *hello
= "Hello, world\n";
305 printf("Starting SMB2-SESSION-RECONNECT\n");
307 if (!torture_init_connection(&cli1
)) {
311 status
= smbXcli_negprot(cli1
->conn
, cli1
->timeout
,
312 PROTOCOL_SMB2_02
, PROTOCOL_LATEST
);
313 if (!NT_STATUS_IS_OK(status
)) {
314 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
318 status
= cli_session_setup(cli1
, username
,
319 password
, strlen(password
),
320 password
, strlen(password
),
322 if (!NT_STATUS_IS_OK(status
)) {
323 printf("cli_session_setup returned %s\n", nt_errstr(status
));
327 status
= cli_tree_connect(cli1
, share
, "?????", "", 0);
328 if (!NT_STATUS_IS_OK(status
)) {
329 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
333 status
= smb2cli_create(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
334 cli1
->smb2
.tcon
, "session-reconnect.txt",
335 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
336 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
337 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
338 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
339 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
340 FILE_CREATE
, /* create_disposition, */
341 FILE_DELETE_ON_CLOSE
, /* create_options, */
342 NULL
, /* smb2_create_blobs *blobs */
345 if (!NT_STATUS_IS_OK(status
)) {
346 printf("smb2cli_create on cli1 %s\n", nt_errstr(status
));
350 status
= smb2cli_write(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
351 cli1
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
352 fid_volatile
, 0, 0, (const uint8_t *)hello
);
353 if (!NT_STATUS_IS_OK(status
)) {
354 printf("smb2cli_write returned %s\n", nt_errstr(status
));
358 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
359 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
360 if (!NT_STATUS_IS_OK(status
)) {
361 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
365 status
= smb2cli_read(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
366 cli1
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
368 talloc_tos(), &result
, &nread
);
369 if (!NT_STATUS_IS_OK(status
)) {
370 printf("smb2cli_read returned %s\n", nt_errstr(status
));
374 if (nread
!= strlen(hello
)) {
375 printf("smb2cli_read returned %d bytes, expected %d\n",
376 (int)nread
, (int)strlen(hello
));
380 if (memcmp(hello
, result
, nread
) != 0) {
381 printf("smb2cli_read returned '%s', expected '%s'\n",
386 /* prepare second session */
388 if (!torture_init_connection(&cli2
)) {
392 status
= smbXcli_negprot(cli2
->conn
, cli2
->timeout
,
393 PROTOCOL_SMB2_02
, PROTOCOL_LATEST
);
394 if (!NT_STATUS_IS_OK(status
)) {
395 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
399 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
400 if (!NT_STATUS_IS_OK(status
)) {
401 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
405 gensec_want_feature(auth_generic_state
->gensec_security
,
406 GENSEC_FEATURE_SESSION_KEY
);
407 status
= auth_generic_set_username(auth_generic_state
, username
);
408 if (!NT_STATUS_IS_OK(status
)) {
409 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
413 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
414 if (!NT_STATUS_IS_OK(status
)) {
415 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
419 status
= auth_generic_set_password(auth_generic_state
, password
);
420 if (!NT_STATUS_IS_OK(status
)) {
421 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
425 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
426 if (!NT_STATUS_IS_OK(status
)) {
427 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
431 ev
= event_context_init(talloc_tos());
433 printf("event_context_init() returned NULL\n");
437 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, data_blob_null
, &in_blob
);
438 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
439 printf("gensec_update returned %s\n", nt_errstr(status
));
443 cli2
->smb2
.session
= smbXcli_session_create(cli2
, cli2
->conn
);
445 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
450 SMB2_CAP_DFS
, /* in_capabilities */
452 /* in_previous_session_id: */
453 smb2cli_session_current_id(cli1
->smb2
.session
),
454 &in_blob
); /* in_security_buffer */
455 if (subreq
== NULL
) {
456 printf("smb2cli_session_setup_send() returned NULL\n");
460 ok
= tevent_req_poll(subreq
, ev
);
462 printf("tevent_req_poll() returned false\n");
466 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
468 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
469 printf("smb2cli_session_setup_recv returned %s\n",
474 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, out_blob
, &in_blob
);
475 if (!NT_STATUS_IS_OK(status
)) {
476 printf("auth_generic_update returned %s\n", nt_errstr(status
));
480 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
485 SMB2_CAP_DFS
, /* in_capabilities */
487 /* in_previous_session_id: */
488 smb2cli_session_current_id(cli1
->smb2
.session
),
489 &in_blob
); /* in_security_buffer */
490 if (subreq
== NULL
) {
491 printf("smb2cli_session_setup_send() returned NULL\n");
495 ok
= tevent_req_poll(subreq
, ev
);
497 printf("tevent_req_poll() returned false\n");
501 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
502 &recv_iov
, &out_blob
);
503 if (!NT_STATUS_IS_OK(status
)) {
504 printf("smb2cli_session_setup_recv returned %s\n",
509 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
511 if (!NT_STATUS_IS_OK(status
)) {
512 printf("gensec_session_key returned %s\n",
517 /* check file operation on the old client */
519 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
520 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
521 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
522 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
526 status
= cli_tree_connect(cli1
, share
, "?????", "", 0);
527 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
528 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
533 * checking file operations without signing.
534 * on w2k8r2 at least, flush, read and write also work the same way,
535 * while create gives ACCESS_DENIED without signing
537 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
538 cli2
->smb2
.tcon
, fid_persistent
, fid_volatile
);
539 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
540 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
542 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
546 status
= smb2cli_write(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
547 cli2
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
548 fid_volatile
, 0, 0, (const uint8_t *)hello
);
549 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
550 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
552 printf("smb2cli_write returned %s\n", nt_errstr(status
));
556 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
557 cli2
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
559 talloc_tos(), &result
, &nread
);
560 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
561 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
563 printf("smb2cli_read returned %s\n", nt_errstr(status
));
567 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
568 cli2
->smb2
.tcon
, "session-reconnect.txt",
569 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
570 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
571 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
572 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
573 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
574 FILE_CREATE
, /* create_disposition, */
575 FILE_DELETE_ON_CLOSE
, /* create_options, */
576 NULL
, /* smb2_create_blobs *blobs */
579 if (!NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
) &&
580 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
581 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
585 /* now grab the session key and try with signing */
587 status
= smb2cli_session_set_session_key(cli2
->smb2
.session
,
590 if (!NT_STATUS_IS_OK(status
)) {
591 printf("smb2cli_session_set_session_key %s\n", nt_errstr(status
));
595 /* the tid seems to be irrelevant at this stage */
597 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
598 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
599 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
600 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
602 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
606 status
= smb2cli_write(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
607 cli1
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
608 fid_volatile
, 0, 0, (const uint8_t *)hello
);
609 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
610 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
612 printf("smb2cli_write returned %s\n", nt_errstr(status
));
616 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
617 cli1
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
619 talloc_tos(), &result
, &nread
);
620 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
621 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
623 printf("smb2cli_read returned %s\n", nt_errstr(status
));
627 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
628 cli1
->smb2
.tcon
, "session-reconnect.txt",
629 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
630 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
631 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
632 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
633 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
634 FILE_CREATE
, /* create_disposition, */
635 FILE_DELETE_ON_CLOSE
, /* create_options, */
636 NULL
, /* smb2_create_blobs *blobs */
639 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
) &&
640 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
642 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
646 /* now do a new tcon and test file calls again */
648 status
= cli_tree_connect(cli2
, share
, "?????", "", 0);
649 if (!NT_STATUS_IS_OK(status
)) {
650 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
654 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
655 cli2
->smb2
.tcon
, "session-reconnect.txt",
656 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
657 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
658 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
659 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
660 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
661 FILE_CREATE
, /* create_disposition, */
662 FILE_DELETE_ON_CLOSE
, /* create_options, */
663 NULL
, /* smb2_create_blobs *blobs */
666 if (!NT_STATUS_IS_OK(status
)) {
667 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
671 status
= smb2cli_write(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
672 cli2
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
673 fid_volatile
, 0, 0, (const uint8_t *)hello
);
674 if (!NT_STATUS_IS_OK(status
)) {
675 printf("smb2cli_write returned %s\n", nt_errstr(status
));
679 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
680 cli2
->smb2
.tcon
, fid_persistent
, fid_volatile
);
681 if (!NT_STATUS_IS_OK(status
)) {
682 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
686 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
687 cli2
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
689 talloc_tos(), &result
, &nread
);
690 if (!NT_STATUS_IS_OK(status
)) {
691 printf("smb2cli_read returned %s\n", nt_errstr(status
));
695 if (nread
!= strlen(hello
)) {
696 printf("smb2cli_read returned %d bytes, expected %d\n",
697 (int)nread
, (int)strlen(hello
));
701 if (memcmp(hello
, result
, nread
) != 0) {
702 printf("smb2cli_read returned '%s', expected '%s'\n",
710 bool run_smb2_tcon_dependence(int dummy
)
712 struct cli_state
*cli
;
714 uint64_t fid_persistent
, fid_volatile
;
715 const char *hello
= "Hello, world\n";
718 struct smbXcli_tcon
*tcon2
;
721 printf("Starting SMB2-TCON-DEPENDENCE\n");
723 if (!torture_init_connection(&cli
)) {
727 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
728 PROTOCOL_SMB2_02
, PROTOCOL_LATEST
);
729 if (!NT_STATUS_IS_OK(status
)) {
730 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
734 status
= cli_session_setup(cli
, username
,
735 password
, strlen(password
),
736 password
, strlen(password
),
738 if (!NT_STATUS_IS_OK(status
)) {
739 printf("cli_session_setup returned %s\n", nt_errstr(status
));
743 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
744 if (!NT_STATUS_IS_OK(status
)) {
745 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
749 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
750 cli
->smb2
.tcon
, "tcon_depedence.txt",
751 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
752 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
753 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
754 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
755 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
756 FILE_CREATE
, /* create_disposition, */
757 FILE_DELETE_ON_CLOSE
, /* create_options, */
758 NULL
, /* smb2_create_blobs *blobs */
761 if (!NT_STATUS_IS_OK(status
)) {
762 printf("smb2cli_create on cli %s\n", nt_errstr(status
));
766 status
= smb2cli_write(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
767 cli
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
768 fid_volatile
, 0, 0, (const uint8_t *)hello
);
769 if (!NT_STATUS_IS_OK(status
)) {
770 printf("smb2cli_write returned %s\n", nt_errstr(status
));
774 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
775 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
776 if (!NT_STATUS_IS_OK(status
)) {
777 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
781 status
= smb2cli_read(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
782 cli
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
784 talloc_tos(), &result
, &nread
);
785 if (!NT_STATUS_IS_OK(status
)) {
786 printf("smb2cli_read returned %s\n", nt_errstr(status
));
790 if (nread
!= strlen(hello
)) {
791 printf("smb2cli_read returned %d bytes, expected %d\n",
792 (int)nread
, (int)strlen(hello
));
796 if (memcmp(hello
, result
, nread
) != 0) {
797 printf("smb2cli_read returned '%s', expected '%s'\n",
802 /* check behaviour with wrong tid... */
804 tcon2
= smbXcli_tcon_create(cli
);
805 tcon2_id
= smb2cli_tcon_current_id(cli
->smb2
.tcon
);
807 smb2cli_tcon_set_values(tcon2
,
812 0, /* capabilities */
813 0 /* maximal_access */);
815 status
= smb2cli_read(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
816 tcon2
, 0x10000, 0, fid_persistent
,
818 talloc_tos(), &result
, &nread
);
819 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
820 printf("smb2cli_read returned %s\n", nt_errstr(status
));
829 bool run_smb2_multi_channel(int dummy
)
831 struct cli_state
*cli1
;
832 struct cli_state
*cli2
;
833 struct cli_state
*cli3
;
836 uint64_t fid_persistent
, fid_volatile
;
837 struct tevent_context
*ev
;
838 struct tevent_req
*subreq
;
839 DATA_BLOB in_blob
= data_blob_null
;
841 DATA_BLOB channel_session_key
;
842 struct auth_generic_state
*auth_generic_state
;
843 struct iovec
*recv_iov
;
844 const char *hello
= "Hello, world\n";
848 printf("Starting SMB2-MULTI-CHANNEL\n");
850 if (!torture_init_connection(&cli1
)) {
854 if (!torture_init_connection(&cli2
)) {
858 if (!torture_init_connection(&cli3
)) {
862 status
= smbXcli_negprot(cli1
->conn
, cli1
->timeout
,
863 PROTOCOL_SMB2_22
, PROTOCOL_LATEST
);
864 if (!NT_STATUS_IS_OK(status
)) {
865 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
869 status
= smbXcli_negprot(cli2
->conn
, cli2
->timeout
,
870 PROTOCOL_SMB2_22
, PROTOCOL_LATEST
);
871 if (!NT_STATUS_IS_OK(status
)) {
872 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
876 status
= smbXcli_negprot(cli3
->conn
, cli3
->timeout
,
877 PROTOCOL_SMB2_22
, PROTOCOL_LATEST
);
878 if (!NT_STATUS_IS_OK(status
)) {
879 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
883 status
= cli_session_setup(cli1
, username
,
884 password
, strlen(password
),
885 password
, strlen(password
),
887 if (!NT_STATUS_IS_OK(status
)) {
888 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status
));
892 status
= cli_tree_connect(cli1
, share
, "?????", "", 0);
893 if (!NT_STATUS_IS_OK(status
)) {
894 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
898 status
= smb2cli_session_create_channel(cli2
,
901 &cli2
->smb2
.session
);
902 if (!NT_STATUS_IS_OK(status
)) {
903 printf("smb2cli_session_create_channel returned %s\n",
908 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
909 if (!NT_STATUS_IS_OK(status
)) {
910 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
914 gensec_want_feature(auth_generic_state
->gensec_security
,
915 GENSEC_FEATURE_SESSION_KEY
);
916 status
= auth_generic_set_username(auth_generic_state
, username
);
917 if (!NT_STATUS_IS_OK(status
)) {
918 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
922 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
923 if (!NT_STATUS_IS_OK(status
)) {
924 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
928 status
= auth_generic_set_password(auth_generic_state
, password
);
929 if (!NT_STATUS_IS_OK(status
)) {
930 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
934 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
935 if (!NT_STATUS_IS_OK(status
)) {
936 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
940 ev
= event_context_init(talloc_tos());
942 printf("event_context_init() returned NULL\n");
946 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, data_blob_null
, &in_blob
);
947 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
948 printf("gensec_update returned %s\n", nt_errstr(status
));
952 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
957 SMB2_CAP_DFS
, /* in_capabilities */
959 0, /* in_previous_session_id */
960 &in_blob
); /* in_security_buffer */
961 if (subreq
== NULL
) {
962 printf("smb2cli_session_setup_send() returned NULL\n");
966 ok
= tevent_req_poll(subreq
, ev
);
968 printf("tevent_req_poll() returned false\n");
972 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
974 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
975 printf("smb2cli_session_setup_recv returned %s\n",
980 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, out_blob
, &in_blob
);
981 if (!NT_STATUS_IS_OK(status
)) {
982 printf("auth_generic_update returned %s\n", nt_errstr(status
));
986 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
991 SMB2_CAP_DFS
, /* in_capabilities */
993 0, /* in_previous_session_id */
994 &in_blob
); /* in_security_buffer */
995 if (subreq
== NULL
) {
996 printf("smb2cli_session_setup_send() returned NULL\n");
1000 ok
= tevent_req_poll(subreq
, ev
);
1002 printf("tevent_req_poll() returned false\n");
1006 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1007 &recv_iov
, &out_blob
);
1008 if (!NT_STATUS_IS_OK(status
)) {
1009 printf("smb2cli_session_setup_recv returned %s\n",
1014 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
1015 &channel_session_key
);
1016 if (!NT_STATUS_IS_OK(status
)) {
1017 printf("gensec_session_key returned %s\n",
1022 status
= smb2cli_session_set_channel_key(cli2
->smb2
.session
,
1023 channel_session_key
,
1025 if (!NT_STATUS_IS_OK(status
)) {
1026 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status
));
1030 status
= smb2cli_session_create_channel(cli3
,
1033 &cli3
->smb2
.session
);
1034 if (!NT_STATUS_IS_OK(status
)) {
1035 printf("smb2cli_session_create_channel returned %s\n",
1040 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1041 if (!NT_STATUS_IS_OK(status
)) {
1042 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1046 gensec_want_feature(auth_generic_state
->gensec_security
,
1047 GENSEC_FEATURE_SESSION_KEY
);
1048 status
= auth_generic_set_username(auth_generic_state
, username
);
1049 if (!NT_STATUS_IS_OK(status
)) {
1050 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
1054 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
1055 if (!NT_STATUS_IS_OK(status
)) {
1056 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
1060 status
= auth_generic_set_password(auth_generic_state
, password
);
1061 if (!NT_STATUS_IS_OK(status
)) {
1062 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
1066 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1067 if (!NT_STATUS_IS_OK(status
)) {
1068 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1072 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, data_blob_null
, &in_blob
);
1073 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1074 printf("gensec_update returned %s\n", nt_errstr(status
));
1078 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1082 0x01, /* in_flags */
1083 SMB2_CAP_DFS
, /* in_capabilities */
1085 0, /* in_previous_session_id */
1086 &in_blob
); /* in_security_buffer */
1087 if (subreq
== NULL
) {
1088 printf("smb2cli_session_setup_send() returned NULL\n");
1092 ok
= tevent_req_poll(subreq
, ev
);
1094 printf("tevent_req_poll() returned false\n");
1098 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1100 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1101 printf("smb2cli_session_setup_recv returned %s\n",
1106 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, out_blob
, &in_blob
);
1107 if (!NT_STATUS_IS_OK(status
)) {
1108 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1112 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1116 0x01, /* in_flags */
1117 SMB2_CAP_DFS
, /* in_capabilities */
1119 0, /* in_previous_session_id */
1120 &in_blob
); /* in_security_buffer */
1121 if (subreq
== NULL
) {
1122 printf("smb2cli_session_setup_send() returned NULL\n");
1126 ok
= tevent_req_poll(subreq
, ev
);
1128 printf("tevent_req_poll() returned false\n");
1132 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1133 &recv_iov
, &out_blob
);
1134 if (!NT_STATUS_IS_OK(status
)) {
1135 printf("smb2cli_session_setup_recv returned %s\n",
1140 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
1141 &channel_session_key
);
1142 if (!NT_STATUS_IS_OK(status
)) {
1143 printf("gensec_session_key returned %s\n",
1148 status
= smb2cli_session_set_channel_key(cli3
->smb2
.session
,
1149 channel_session_key
,
1151 if (!NT_STATUS_IS_OK(status
)) {
1152 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status
));
1156 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1157 cli1
->smb2
.tcon
, "multi-channel.txt",
1158 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1159 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1160 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1161 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1162 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1163 FILE_CREATE
, /* create_disposition, */
1164 FILE_DELETE_ON_CLOSE
, /* create_options, */
1165 NULL
, /* smb2_create_blobs *blobs */
1168 if (!NT_STATUS_IS_OK(status
)) {
1169 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
1173 status
= smb2cli_write(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1174 cli1
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
1175 fid_volatile
, 0, 0, (const uint8_t *)hello
);
1176 if (!NT_STATUS_IS_OK(status
)) {
1177 printf("smb2cli_write returned %s\n", nt_errstr(status
));
1181 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1182 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1183 if (!NT_STATUS_IS_OK(status
)) {
1184 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1188 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1189 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1190 if (!NT_STATUS_IS_OK(status
)) {
1191 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1195 status
= smb2cli_flush(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1196 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1197 if (!NT_STATUS_IS_OK(status
)) {
1198 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1202 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1203 cli1
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
1205 talloc_tos(), &result
, &nread
);
1206 if (!NT_STATUS_IS_OK(status
)) {
1207 printf("smb2cli_read returned %s\n", nt_errstr(status
));
1211 if (nread
!= strlen(hello
)) {
1212 printf("smb2cli_read returned %d bytes, expected %d\n",
1213 (int)nread
, (int)strlen(hello
));
1217 if (memcmp(hello
, result
, nread
) != 0) {
1218 printf("smb2cli_read returned '%s', expected '%s'\n",
1223 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1224 if (!NT_STATUS_IS_OK(status
)) {
1225 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1229 gensec_want_feature(auth_generic_state
->gensec_security
,
1230 GENSEC_FEATURE_SESSION_KEY
);
1231 status
= auth_generic_set_username(auth_generic_state
, username
);
1232 if (!NT_STATUS_IS_OK(status
)) {
1233 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
1237 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
1238 if (!NT_STATUS_IS_OK(status
)) {
1239 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
1243 status
= auth_generic_set_password(auth_generic_state
, password
);
1244 if (!NT_STATUS_IS_OK(status
)) {
1245 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
1249 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1250 if (!NT_STATUS_IS_OK(status
)) {
1251 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1255 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, data_blob_null
, &in_blob
);
1256 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1257 printf("gensec_update returned %s\n", nt_errstr(status
));
1261 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1266 SMB2_CAP_DFS
, /* in_capabilities */
1268 0, /* in_previous_session_id */
1269 &in_blob
); /* in_security_buffer */
1270 if (subreq
== NULL
) {
1271 printf("smb2cli_session_setup_send() returned NULL\n");
1275 ok
= tevent_req_poll(subreq
, ev
);
1277 printf("tevent_req_poll() returned false\n");
1281 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1283 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1284 printf("smb2cli_session_setup_recv returned %s\n",
1289 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, out_blob
, &in_blob
);
1290 if (!NT_STATUS_IS_OK(status
)) {
1291 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1295 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1296 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1297 if (!NT_STATUS_IS_OK(status
)) {
1298 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1302 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1303 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1304 if (!NT_STATUS_IS_OK(status
)) {
1305 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1309 status
= smb2cli_flush(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1310 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1311 if (!NT_STATUS_IS_OK(status
)) {
1312 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1316 status
= smb2cli_create(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1317 cli1
->smb2
.tcon
, "multi-channel-invalid.txt",
1318 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1319 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1320 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1321 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1322 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1323 FILE_CREATE
, /* create_disposition, */
1324 FILE_DELETE_ON_CLOSE
, /* create_options, */
1325 NULL
, /* smb2_create_blobs *blobs */
1328 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1329 printf("smb2cli_create %s\n", nt_errstr(status
));
1333 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1334 cli1
->smb2
.tcon
, "multi-channel-invalid.txt",
1335 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1336 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1337 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1338 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1339 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1340 FILE_CREATE
, /* create_disposition, */
1341 FILE_DELETE_ON_CLOSE
, /* create_options, */
1342 NULL
, /* smb2_create_blobs *blobs */
1345 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1346 printf("smb2cli_create %s\n", nt_errstr(status
));
1350 status
= smb2cli_create(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1351 cli1
->smb2
.tcon
, "multi-channel-invalid.txt",
1352 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1353 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1354 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1355 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1356 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1357 FILE_CREATE
, /* create_disposition, */
1358 FILE_DELETE_ON_CLOSE
, /* create_options, */
1359 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 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1372 SMB2_CAP_DFS
, /* in_capabilities */
1374 0, /* in_previous_session_id */
1375 &in_blob
); /* in_security_buffer */
1376 if (subreq
== NULL
) {
1377 printf("smb2cli_session_setup_send() returned NULL\n");
1381 ok
= tevent_req_poll(subreq
, ev
);
1383 printf("tevent_req_poll() returned false\n");
1387 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1388 &recv_iov
, &out_blob
);
1389 if (!NT_STATUS_IS_OK(status
)) {
1390 printf("smb2cli_session_setup_recv returned %s\n",
1395 status
= smb2cli_close(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1396 cli1
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
1397 if (!NT_STATUS_IS_OK(status
)) {
1398 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1402 status
= smb2cli_flush(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1403 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1404 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1405 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1409 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1410 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1411 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1412 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1416 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1417 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1418 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1419 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1426 bool run_smb2_session_reauth(int dummy
)
1428 struct cli_state
*cli
;
1431 uint64_t fid_persistent
, fid_volatile
;
1432 uint64_t dir_persistent
, dir_volatile
;
1434 uint32_t dir_data_length
;
1435 struct tevent_context
*ev
;
1436 struct tevent_req
*subreq
;
1437 DATA_BLOB in_blob
= data_blob_null
;
1439 DATA_BLOB in_input_buffer
;
1440 DATA_BLOB out_output_buffer
;
1441 uint8_t in_file_info_class
;
1442 struct auth_generic_state
*auth_generic_state
;
1443 struct iovec
*recv_iov
;
1445 struct smbXcli_tcon
*saved_tcon
;
1447 printf("Starting SMB2-SESSION_REAUTH\n");
1449 if (!torture_init_connection(&cli
)) {
1454 * PROTOCOL_SMB2_22 has a bug in win8pre0
1455 * it behaves like PROTOCOL_SMB2_02
1456 * and returns NT_STATUS_REQUEST_NOT_ACCEPTED,
1457 * while it allows it on PROTOCOL_SMB2_02.
1459 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
1460 PROTOCOL_SMB2_10
, PROTOCOL_SMB2_10
);
1461 if (!NT_STATUS_IS_OK(status
)) {
1462 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
1466 status
= cli_session_setup(cli
, username
,
1467 password
, strlen(password
),
1468 password
, strlen(password
),
1470 if (!NT_STATUS_IS_OK(status
)) {
1471 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status
));
1475 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
1476 if (!NT_STATUS_IS_OK(status
)) {
1477 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1481 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1482 cli
->smb2
.tcon
, "session-reauth.txt",
1483 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1484 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1485 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1486 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1487 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1488 FILE_CREATE
, /* create_disposition, */
1489 FILE_DELETE_ON_CLOSE
, /* create_options, */
1490 NULL
, /* smb2_create_blobs *blobs */
1493 if (!NT_STATUS_IS_OK(status
)) {
1494 printf("smb2cli_create %s\n", nt_errstr(status
));
1498 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1500 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1501 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1502 SEC_STD_SYNCHRONIZE
|
1504 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
1505 0, /* file_attributes, */
1506 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1507 FILE_OPEN
, /* create_disposition, */
1508 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
1509 NULL
, /* smb2_create_blobs *blobs */
1512 if (!NT_STATUS_IS_OK(status
)) {
1513 printf("smb2cli_create returned %s\n", nt_errstr(status
));
1517 status
= smb2cli_query_directory(
1518 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
1519 1, 0x3, 0, dir_persistent
, dir_volatile
,
1520 "session-reauth.txt", 0xffff,
1521 talloc_tos(), &dir_data
, &dir_data_length
);
1522 if (!NT_STATUS_IS_OK(status
)) {
1523 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1527 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1528 if (!NT_STATUS_IS_OK(status
)) {
1529 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1533 gensec_want_feature(auth_generic_state
->gensec_security
,
1534 GENSEC_FEATURE_SESSION_KEY
);
1535 status
= auth_generic_set_username(auth_generic_state
, username
);
1536 if (!NT_STATUS_IS_OK(status
)) {
1537 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
1541 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
1542 if (!NT_STATUS_IS_OK(status
)) {
1543 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
1547 status
= auth_generic_set_password(auth_generic_state
, password
);
1548 if (!NT_STATUS_IS_OK(status
)) {
1549 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
1553 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1554 if (!NT_STATUS_IS_OK(status
)) {
1555 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1559 ev
= event_context_init(talloc_tos());
1561 printf("event_context_init() returned NULL\n");
1565 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, data_blob_null
, &in_blob
);
1566 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1567 printf("gensec_update returned %s\n", nt_errstr(status
));
1571 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1576 SMB2_CAP_DFS
, /* in_capabilities */
1578 0, /* in_previous_session_id */
1579 &in_blob
); /* in_security_buffer */
1580 if (subreq
== NULL
) {
1581 printf("smb2cli_session_setup_send() returned NULL\n");
1585 ok
= tevent_req_poll(subreq
, ev
);
1587 printf("tevent_req_poll() returned false\n");
1591 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1593 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1594 printf("smb2cli_session_setup_recv returned %s\n",
1599 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, out_blob
, &in_blob
);
1600 if (!NT_STATUS_IS_OK(status
)) {
1601 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1605 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1606 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1607 if (!NT_STATUS_IS_OK(status
)) {
1608 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1612 status
= smb2cli_query_directory(
1613 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
1614 1, 0x3, 0, dir_persistent
, dir_volatile
,
1615 "session-reauth.txt", 0xffff,
1616 talloc_tos(), &dir_data
, &dir_data_length
);
1617 if (!NT_STATUS_IS_OK(status
)) {
1618 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1623 * query_info seems to be a path based operation on Windows...
1625 status
= smb2cli_query_info(cli
->conn
,
1629 SMB2_GETINFO_SECURITY
,
1630 0, /* in_file_info_class */
1631 1024, /* in_max_output_length */
1632 NULL
, /* in_input_buffer */
1633 SECINFO_OWNER
, /* in_additional_info */
1638 &out_output_buffer
);
1639 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1640 printf("smb2cli_query_info (security) returned %s\n", nt_errstr(status
));
1644 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1645 status
= smb2cli_query_info(cli
->conn
,
1651 1024, /* in_max_output_length */
1652 NULL
, /* in_input_buffer */
1653 0, /* in_additional_info */
1658 &out_output_buffer
);
1659 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1660 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1664 in_input_buffer
= data_blob_talloc(talloc_tos(), NULL
, 8);
1665 SBVAL(in_input_buffer
.data
, 0, 512);
1667 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1668 status
= smb2cli_set_info(cli
->conn
,
1675 0, /* in_additional_info */
1678 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1679 printf("smb2cli_set_info (position) returned %s\n", nt_errstr(status
));
1683 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1684 cli
->smb2
.tcon
, "session-reauth-invalid.txt",
1685 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1686 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1687 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1688 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1689 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1690 FILE_CREATE
, /* create_disposition, */
1691 FILE_DELETE_ON_CLOSE
, /* create_options, */
1692 NULL
, /* smb2_create_blobs *blobs */
1695 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1696 printf("smb2cli_create %s\n", nt_errstr(status
));
1700 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1702 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1703 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1704 SEC_STD_SYNCHRONIZE
|
1706 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
1707 0, /* file_attributes, */
1708 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1709 FILE_OPEN
, /* create_disposition, */
1710 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
1711 NULL
, /* smb2_create_blobs *blobs */
1714 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1715 printf("smb2cli_create returned %s\n", nt_errstr(status
));
1719 saved_tid
= smb2cli_tcon_current_id(cli
->smb2
.tcon
);
1720 saved_tcon
= cli
->smb2
.tcon
;
1721 cli
->smb2
.tcon
= smbXcli_tcon_create(cli
);
1722 smb2cli_tcon_set_values(cli
->smb2
.tcon
,
1727 0, /* capabilities */
1728 0 /* maximal_access */);
1729 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
1730 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1731 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1734 talloc_free(cli
->smb2
.tcon
);
1735 cli
->smb2
.tcon
= saved_tcon
;
1737 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1742 SMB2_CAP_DFS
, /* in_capabilities */
1744 0, /* in_previous_session_id */
1745 &in_blob
); /* in_security_buffer */
1746 if (subreq
== NULL
) {
1747 printf("smb2cli_session_setup_send() returned NULL\n");
1751 ok
= tevent_req_poll(subreq
, ev
);
1753 printf("tevent_req_poll() returned false\n");
1757 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1758 &recv_iov
, &out_blob
);
1759 if (!NT_STATUS_IS_OK(status
)) {
1760 printf("smb2cli_session_setup_recv returned %s\n",
1765 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1766 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1767 if (!NT_STATUS_IS_OK(status
)) {
1768 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1772 status
= smb2cli_query_info(cli
->conn
,
1776 SMB2_GETINFO_SECURITY
,
1777 0, /* in_file_info_class */
1778 1024, /* in_max_output_length */
1779 NULL
, /* in_input_buffer */
1780 SECINFO_OWNER
, /* in_additional_info */
1785 &out_output_buffer
);
1786 if (!NT_STATUS_IS_OK(status
)) {
1787 printf("smb2cli_query_info (security) returned %s\n", nt_errstr(status
));
1791 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1792 status
= smb2cli_query_info(cli
->conn
,
1798 1024, /* in_max_output_length */
1799 NULL
, /* in_input_buffer */
1800 0, /* in_additional_info */
1805 &out_output_buffer
);
1806 if (!NT_STATUS_IS_OK(status
)) {
1807 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1811 in_input_buffer
= data_blob_talloc(talloc_tos(), NULL
, 8);
1812 SBVAL(in_input_buffer
.data
, 0, 512);
1814 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1815 status
= smb2cli_set_info(cli
->conn
,
1822 0, /* in_additional_info */
1825 if (!NT_STATUS_IS_OK(status
)) {
1826 printf("smb2cli_set_info (position) returned %s\n", nt_errstr(status
));
1830 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1831 status
= smb2cli_query_info(cli
->conn
,
1837 1024, /* in_max_output_length */
1838 NULL
, /* in_input_buffer */
1839 0, /* in_additional_info */
1844 &out_output_buffer
);
1845 if (!NT_STATUS_IS_OK(status
)) {
1846 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1850 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1851 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
1852 if (!NT_STATUS_IS_OK(status
)) {
1853 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1857 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1858 cli
->smb2
.tcon
, "session-reauth.txt",
1859 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1860 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1861 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1862 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1863 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1864 FILE_CREATE
, /* create_disposition, */
1865 FILE_DELETE_ON_CLOSE
, /* create_options, */
1866 NULL
, /* smb2_create_blobs *blobs */
1869 if (!NT_STATUS_IS_OK(status
)) {
1870 printf("smb2cli_create %s\n", nt_errstr(status
));
1874 status
= smb2cli_query_directory(
1875 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
1876 1, 0x3, 0, dir_persistent
, dir_volatile
,
1877 "session-reauth.txt", 0xffff,
1878 talloc_tos(), &dir_data
, &dir_data_length
);
1879 if (!NT_STATUS_IS_OK(status
)) {
1880 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1884 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1885 cli
->smb2
.tcon
, 0, dir_persistent
, dir_volatile
);
1886 if (!NT_STATUS_IS_OK(status
)) {
1887 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1891 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1892 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
1893 if (!NT_STATUS_IS_OK(status
)) {
1894 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1898 saved_tid
= smb2cli_tcon_current_id(cli
->smb2
.tcon
);
1899 saved_tcon
= cli
->smb2
.tcon
;
1900 cli
->smb2
.tcon
= smbXcli_tcon_create(cli
);
1901 smb2cli_tcon_set_values(cli
->smb2
.tcon
,
1906 0, /* capabilities */
1907 0 /* maximal_access */);
1908 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
1909 if (!NT_STATUS_IS_OK(status
)) {
1910 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1913 talloc_free(cli
->smb2
.tcon
);
1914 cli
->smb2
.tcon
= saved_tcon
;