2 Unix SMB/CIFS implementation.
3 Initial test for the smb2 client lib
4 Copyright (C) Volker Lendecke 2011
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "torture/proto.h"
24 #include "../libcli/smb/smbXcli_base.h"
25 #include "libsmb/smb2cli.h"
26 #include "libcli/security/security.h"
27 #include "libsmb/proto.h"
28 #include "auth/gensec/gensec.h"
29 #include "auth_generic.h"
31 extern fstring host
, workgroup
, share
, password
, username
, myname
;
33 bool run_smb2_basic(int dummy
)
35 struct cli_state
*cli
;
37 uint64_t fid_persistent
, fid_volatile
;
38 const char *hello
= "Hello, world\n";
42 uint32_t dir_data_length
;
43 uint32_t saved_tid
= 0;
44 uint64_t saved_uid
= 0;
46 printf("Starting SMB2-BASIC\n");
48 if (!torture_init_connection(&cli
)) {
51 cli
->smb2
.pid
= 0xFEFF;
53 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
54 PROTOCOL_SMB2_02
, PROTOCOL_SMB2_02
);
55 if (!NT_STATUS_IS_OK(status
)) {
56 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
60 status
= cli_session_setup(cli
, username
,
61 password
, strlen(password
),
62 password
, strlen(password
),
64 if (!NT_STATUS_IS_OK(status
)) {
65 printf("cli_session_setup returned %s\n", nt_errstr(status
));
69 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
70 if (!NT_STATUS_IS_OK(status
)) {
71 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
75 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
76 cli
->smb2
.tid
, "smb2-basic.txt",
77 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
78 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
79 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
80 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
81 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
82 FILE_CREATE
, /* create_disposition, */
83 FILE_DELETE_ON_CLOSE
, /* create_options, */
84 NULL
, /* smb2_create_blobs *blobs */
87 if (!NT_STATUS_IS_OK(status
)) {
88 printf("smb2cli_create returned %s\n", nt_errstr(status
));
92 status
= smb2cli_write(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
93 cli
->smb2
.tid
, 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
.tid
, 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
.tid
, 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
.tid
, 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
.tid
,
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
.tid
, 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
= cli
->smb2
.tid
;
172 status
= smb2cli_tdis(cli
);
173 if (!NT_STATUS_IS_OK(status
)) {
174 printf("smb2cli_tdis returned %s\n", nt_errstr(status
));
177 cli
->smb2
.tid
= saved_tid
;
179 status
= smb2cli_tdis(cli
);
180 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
181 printf("2nd smb2cli_tdis returned %s\n", nt_errstr(status
));
185 saved_uid
= smb2cli_session_current_id(cli
->smb2
.session
);
186 status
= smb2cli_logoff(cli
->conn
, cli
->timeout
, cli
->smb2
.session
);
187 if (!NT_STATUS_IS_OK(status
)) {
188 printf("smb2cli_logoff returned %s\n", nt_errstr(status
));
192 cli
->smb2
.session
= smbXcli_session_create(cli
, cli
->conn
);
193 if (cli
->smb2
.session
== NULL
) {
194 printf("smbXcli_session_create() returned NULL\n");
198 smb2cli_session_set_id_and_flags(cli
->smb2
.session
, saved_uid
, 0);
200 status
= smb2cli_logoff(cli
->conn
, cli
->timeout
, cli
->smb2
.session
);
201 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
202 printf("2nd smb2cli_logoff returned %s\n", nt_errstr(status
));
209 bool run_smb2_negprot(int dummy
)
211 struct cli_state
*cli
;
213 enum protocol_types protocol
;
214 const char *name
= NULL
;
216 printf("Starting SMB2-NEGPROT\n");
218 if (!torture_init_connection(&cli
)) {
221 cli
->smb2
.pid
= 0xFEFF;
223 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
224 PROTOCOL_CORE
, PROTOCOL_LATEST
);
225 if (!NT_STATUS_IS_OK(status
)) {
226 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
230 protocol
= smbXcli_conn_protocol(cli
->conn
);
233 case PROTOCOL_SMB2_02
:
236 case PROTOCOL_SMB2_10
:
239 case PROTOCOL_SMB2_22
:
242 case PROTOCOL_SMB2_24
:
245 case PROTOCOL_SMB3_00
:
253 printf("Server supports %s\n", name
);
255 printf("Server DOES NOT support SMB2\n");
259 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
261 if (!NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_RESET
) &&
262 !NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_DISCONNECTED
) &&
263 !NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_ABORTED
)) {
264 printf("2nd smbXcli_negprot should disconnect - returned %s\n",
269 if (smbXcli_conn_is_connected(cli
->conn
)) {
270 printf("2nd smbXcli_negprot should disconnect "
271 "- still connected\n");
278 bool run_smb2_session_reconnect(int dummy
)
280 struct cli_state
*cli1
;
281 struct cli_state
*cli2
;
284 uint64_t fid_persistent
, fid_volatile
;
285 struct tevent_context
*ev
;
286 struct tevent_req
*subreq
;
287 DATA_BLOB in_blob
= data_blob_null
;
289 DATA_BLOB session_key
;
290 struct auth_generic_state
*auth_generic_state
;
291 struct iovec
*recv_iov
;
292 const char *hello
= "Hello, world\n";
296 printf("Starting SMB2-SESSION-RECONNECT\n");
298 if (!torture_init_connection(&cli1
)) {
301 cli1
->smb2
.pid
= 0xFEFF;
303 status
= smbXcli_negprot(cli1
->conn
, cli1
->timeout
,
304 PROTOCOL_SMB2_02
, PROTOCOL_LATEST
);
305 if (!NT_STATUS_IS_OK(status
)) {
306 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
310 status
= cli_session_setup(cli1
, username
,
311 password
, strlen(password
),
312 password
, strlen(password
),
314 if (!NT_STATUS_IS_OK(status
)) {
315 printf("cli_session_setup returned %s\n", nt_errstr(status
));
319 status
= cli_tree_connect(cli1
, share
, "?????", "", 0);
320 if (!NT_STATUS_IS_OK(status
)) {
321 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
325 status
= smb2cli_create(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
326 cli1
->smb2
.tid
, "session-reconnect.txt",
327 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
328 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
329 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
330 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
331 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
332 FILE_CREATE
, /* create_disposition, */
333 FILE_DELETE_ON_CLOSE
, /* create_options, */
334 NULL
, /* smb2_create_blobs *blobs */
337 if (!NT_STATUS_IS_OK(status
)) {
338 printf("smb2cli_create on cli1 %s\n", nt_errstr(status
));
342 status
= smb2cli_write(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
343 cli1
->smb2
.tid
, strlen(hello
), 0, fid_persistent
,
344 fid_volatile
, 0, 0, (const uint8_t *)hello
);
345 if (!NT_STATUS_IS_OK(status
)) {
346 printf("smb2cli_write returned %s\n", nt_errstr(status
));
350 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
351 cli1
->smb2
.tid
, fid_persistent
, fid_volatile
);
352 if (!NT_STATUS_IS_OK(status
)) {
353 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
357 status
= smb2cli_read(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
358 cli1
->smb2
.tid
, 0x10000, 0, fid_persistent
,
360 talloc_tos(), &result
, &nread
);
361 if (!NT_STATUS_IS_OK(status
)) {
362 printf("smb2cli_read returned %s\n", nt_errstr(status
));
366 if (nread
!= strlen(hello
)) {
367 printf("smb2cli_read returned %d bytes, expected %d\n",
368 (int)nread
, (int)strlen(hello
));
372 if (memcmp(hello
, result
, nread
) != 0) {
373 printf("smb2cli_read returned '%s', expected '%s'\n",
378 /* prepare second session */
380 if (!torture_init_connection(&cli2
)) {
383 cli2
->smb2
.pid
= 0xFEFF;
385 status
= smbXcli_negprot(cli2
->conn
, cli2
->timeout
,
386 PROTOCOL_SMB2_02
, PROTOCOL_LATEST
);
387 if (!NT_STATUS_IS_OK(status
)) {
388 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
392 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
393 if (!NT_STATUS_IS_OK(status
)) {
394 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
398 gensec_want_feature(auth_generic_state
->gensec_security
,
399 GENSEC_FEATURE_SESSION_KEY
);
400 status
= auth_generic_set_username(auth_generic_state
, username
);
401 if (!NT_STATUS_IS_OK(status
)) {
402 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
406 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
407 if (!NT_STATUS_IS_OK(status
)) {
408 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
412 status
= auth_generic_set_password(auth_generic_state
, password
);
413 if (!NT_STATUS_IS_OK(status
)) {
414 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
418 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
419 if (!NT_STATUS_IS_OK(status
)) {
420 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
424 ev
= event_context_init(talloc_tos());
426 printf("event_context_init() returned NULL\n");
430 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, data_blob_null
, &in_blob
);
431 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
432 printf("gensec_update returned %s\n", nt_errstr(status
));
436 cli2
->smb2
.session
= smbXcli_session_create(cli2
, cli2
->conn
);
438 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
443 SMB2_CAP_DFS
, /* in_capabilities */
445 /* in_previous_session_id: */
446 smb2cli_session_current_id(cli1
->smb2
.session
),
447 &in_blob
); /* in_security_buffer */
448 if (subreq
== NULL
) {
449 printf("smb2cli_session_setup_send() returned NULL\n");
453 ok
= tevent_req_poll(subreq
, ev
);
455 printf("tevent_req_poll() returned false\n");
459 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
461 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
462 printf("smb2cli_session_setup_recv returned %s\n",
467 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, out_blob
, &in_blob
);
468 if (!NT_STATUS_IS_OK(status
)) {
469 printf("auth_generic_update returned %s\n", nt_errstr(status
));
473 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
478 SMB2_CAP_DFS
, /* in_capabilities */
480 /* in_previous_session_id: */
481 smb2cli_session_current_id(cli1
->smb2
.session
),
482 &in_blob
); /* in_security_buffer */
483 if (subreq
== NULL
) {
484 printf("smb2cli_session_setup_send() returned NULL\n");
488 ok
= tevent_req_poll(subreq
, ev
);
490 printf("tevent_req_poll() returned false\n");
494 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
495 &recv_iov
, &out_blob
);
496 if (!NT_STATUS_IS_OK(status
)) {
497 printf("smb2cli_session_setup_recv returned %s\n",
502 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
504 if (!NT_STATUS_IS_OK(status
)) {
505 printf("gensec_session_key returned %s\n",
510 /* check file operation on the old client */
512 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
513 cli1
->smb2
.tid
, fid_persistent
, fid_volatile
);
514 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
515 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
519 status
= cli_tree_connect(cli1
, share
, "?????", "", 0);
520 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
521 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
526 * checking file operations without signing.
527 * on w2k8r2 at least, flush, read and write also work the same way,
528 * while create gives ACCESS_DENIED without signing
530 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
531 cli2
->smb2
.tid
, fid_persistent
, fid_volatile
);
532 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
533 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
537 status
= smb2cli_write(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
538 cli2
->smb2
.tid
, strlen(hello
), 0, fid_persistent
,
539 fid_volatile
, 0, 0, (const uint8_t *)hello
);
540 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
541 printf("smb2cli_write returned %s\n", nt_errstr(status
));
545 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
546 cli2
->smb2
.tid
, 0x10000, 0, fid_persistent
,
548 talloc_tos(), &result
, &nread
);
549 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
550 printf("smb2cli_read returned %s\n", nt_errstr(status
));
554 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
555 cli2
->smb2
.tid
, "session-reconnect.txt",
556 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
557 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
558 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
559 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
560 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
561 FILE_CREATE
, /* create_disposition, */
562 FILE_DELETE_ON_CLOSE
, /* create_options, */
563 NULL
, /* smb2_create_blobs *blobs */
566 if (!NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
) &&
567 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
568 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
572 /* now grab the session key and try with signing */
574 status
= smb2cli_session_set_session_key(cli2
->smb2
.session
,
577 if (!NT_STATUS_IS_OK(status
)) {
578 printf("smb2cli_session_set_session_key %s\n", nt_errstr(status
));
582 /* the tid seems to be irrelevant at this stage */
584 cli2
->smb2
.tid
= cli1
->smb2
.tid
;
586 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
587 cli2
->smb2
.tid
, fid_persistent
, fid_volatile
);
588 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
589 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
593 status
= smb2cli_write(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
594 cli2
->smb2
.tid
, strlen(hello
), 0, fid_persistent
,
595 fid_volatile
, 0, 0, (const uint8_t *)hello
);
596 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
597 printf("smb2cli_write returned %s\n", nt_errstr(status
));
601 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
602 cli2
->smb2
.tid
, 0x10000, 0, fid_persistent
,
604 talloc_tos(), &result
, &nread
);
605 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
606 printf("smb2cli_read returned %s\n", nt_errstr(status
));
610 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
611 cli2
->smb2
.tid
, "session-reconnect.txt",
612 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
613 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
614 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
615 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
616 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
617 FILE_CREATE
, /* create_disposition, */
618 FILE_DELETE_ON_CLOSE
, /* create_options, */
619 NULL
, /* smb2_create_blobs *blobs */
622 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
623 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
627 /* now do a new tcon and test file calls again */
629 status
= cli_tree_connect(cli2
, share
, "?????", "", 0);
630 if (!NT_STATUS_IS_OK(status
)) {
631 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
635 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
636 cli2
->smb2
.tid
, "session-reconnect.txt",
637 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
638 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
639 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
640 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
641 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
642 FILE_CREATE
, /* create_disposition, */
643 FILE_DELETE_ON_CLOSE
, /* create_options, */
644 NULL
, /* smb2_create_blobs *blobs */
647 if (!NT_STATUS_IS_OK(status
)) {
648 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
652 status
= smb2cli_write(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
653 cli2
->smb2
.tid
, strlen(hello
), 0, fid_persistent
,
654 fid_volatile
, 0, 0, (const uint8_t *)hello
);
655 if (!NT_STATUS_IS_OK(status
)) {
656 printf("smb2cli_write returned %s\n", nt_errstr(status
));
660 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
661 cli2
->smb2
.tid
, fid_persistent
, fid_volatile
);
662 if (!NT_STATUS_IS_OK(status
)) {
663 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
667 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
668 cli2
->smb2
.tid
, 0x10000, 0, fid_persistent
,
670 talloc_tos(), &result
, &nread
);
671 if (!NT_STATUS_IS_OK(status
)) {
672 printf("smb2cli_read returned %s\n", nt_errstr(status
));
676 if (nread
!= strlen(hello
)) {
677 printf("smb2cli_read returned %d bytes, expected %d\n",
678 (int)nread
, (int)strlen(hello
));
682 if (memcmp(hello
, result
, nread
) != 0) {
683 printf("smb2cli_read returned '%s', expected '%s'\n",
691 bool run_smb2_tcon_dependence(int dummy
)
693 struct cli_state
*cli
;
695 uint64_t fid_persistent
, fid_volatile
;
696 const char *hello
= "Hello, world\n";
700 printf("Starting SMB2-TCON-DEPENDENCE\n");
702 if (!torture_init_connection(&cli
)) {
705 cli
->smb2
.pid
= 0xFEFF;
707 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
708 PROTOCOL_SMB2_02
, PROTOCOL_LATEST
);
709 if (!NT_STATUS_IS_OK(status
)) {
710 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
714 status
= cli_session_setup(cli
, username
,
715 password
, strlen(password
),
716 password
, strlen(password
),
718 if (!NT_STATUS_IS_OK(status
)) {
719 printf("cli_session_setup returned %s\n", nt_errstr(status
));
723 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
724 if (!NT_STATUS_IS_OK(status
)) {
725 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
729 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
730 cli
->smb2
.tid
, "tcon_depedence.txt",
731 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
732 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
733 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
734 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
735 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
736 FILE_CREATE
, /* create_disposition, */
737 FILE_DELETE_ON_CLOSE
, /* create_options, */
738 NULL
, /* smb2_create_blobs *blobs */
741 if (!NT_STATUS_IS_OK(status
)) {
742 printf("smb2cli_create on cli %s\n", nt_errstr(status
));
746 status
= smb2cli_write(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
747 cli
->smb2
.tid
, strlen(hello
), 0, fid_persistent
,
748 fid_volatile
, 0, 0, (const uint8_t *)hello
);
749 if (!NT_STATUS_IS_OK(status
)) {
750 printf("smb2cli_write returned %s\n", nt_errstr(status
));
754 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
755 cli
->smb2
.tid
, fid_persistent
, fid_volatile
);
756 if (!NT_STATUS_IS_OK(status
)) {
757 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
761 status
= smb2cli_read(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
762 cli
->smb2
.tid
, 0x10000, 0, fid_persistent
,
764 talloc_tos(), &result
, &nread
);
765 if (!NT_STATUS_IS_OK(status
)) {
766 printf("smb2cli_read returned %s\n", nt_errstr(status
));
770 if (nread
!= strlen(hello
)) {
771 printf("smb2cli_read returned %d bytes, expected %d\n",
772 (int)nread
, (int)strlen(hello
));
776 if (memcmp(hello
, result
, nread
) != 0) {
777 printf("smb2cli_read returned '%s', expected '%s'\n",
782 /* check behaviour with wrong tid... */
786 status
= smb2cli_read(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
787 cli
->smb2
.tid
, 0x10000, 0, fid_persistent
,
789 talloc_tos(), &result
, &nread
);
790 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
791 printf("smb2cli_read returned %s\n", nt_errstr(status
));
800 bool run_smb2_multi_channel(int dummy
)
802 struct cli_state
*cli1
;
803 struct cli_state
*cli2
;
804 struct cli_state
*cli3
;
807 uint64_t fid_persistent
, fid_volatile
;
808 struct tevent_context
*ev
;
809 struct tevent_req
*subreq
;
810 DATA_BLOB in_blob
= data_blob_null
;
812 DATA_BLOB channel_session_key
;
813 struct auth_generic_state
*auth_generic_state
;
814 struct iovec
*recv_iov
;
815 const char *hello
= "Hello, world\n";
819 printf("Starting SMB2-MULTI-CHANNEL\n");
821 if (!torture_init_connection(&cli1
)) {
824 cli1
->smb2
.pid
= 0xFEFF;
826 if (!torture_init_connection(&cli2
)) {
829 cli2
->smb2
.pid
= 0xFEFF;
831 if (!torture_init_connection(&cli3
)) {
834 cli3
->smb2
.pid
= 0xFEFF;
836 status
= smbXcli_negprot(cli1
->conn
, cli1
->timeout
,
837 PROTOCOL_SMB2_22
, PROTOCOL_LATEST
);
838 if (!NT_STATUS_IS_OK(status
)) {
839 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
843 status
= smbXcli_negprot(cli2
->conn
, cli2
->timeout
,
844 PROTOCOL_SMB2_22
, PROTOCOL_LATEST
);
845 if (!NT_STATUS_IS_OK(status
)) {
846 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
850 status
= smbXcli_negprot(cli3
->conn
, cli3
->timeout
,
851 PROTOCOL_SMB2_22
, PROTOCOL_LATEST
);
852 if (!NT_STATUS_IS_OK(status
)) {
853 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
857 status
= cli_session_setup(cli1
, username
,
858 password
, strlen(password
),
859 password
, strlen(password
),
861 if (!NT_STATUS_IS_OK(status
)) {
862 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status
));
866 status
= cli_tree_connect(cli1
, share
, "?????", "", 0);
867 if (!NT_STATUS_IS_OK(status
)) {
868 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
872 status
= smb2cli_session_create_channel(cli2
,
875 &cli2
->smb2
.session
);
876 if (!NT_STATUS_IS_OK(status
)) {
877 printf("smb2cli_session_create_channel returned %s\n",
882 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
883 if (!NT_STATUS_IS_OK(status
)) {
884 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
888 gensec_want_feature(auth_generic_state
->gensec_security
,
889 GENSEC_FEATURE_SESSION_KEY
);
890 status
= auth_generic_set_username(auth_generic_state
, username
);
891 if (!NT_STATUS_IS_OK(status
)) {
892 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
896 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
897 if (!NT_STATUS_IS_OK(status
)) {
898 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
902 status
= auth_generic_set_password(auth_generic_state
, password
);
903 if (!NT_STATUS_IS_OK(status
)) {
904 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
908 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
909 if (!NT_STATUS_IS_OK(status
)) {
910 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
914 ev
= event_context_init(talloc_tos());
916 printf("event_context_init() returned NULL\n");
920 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, data_blob_null
, &in_blob
);
921 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
922 printf("gensec_update returned %s\n", nt_errstr(status
));
926 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
931 SMB2_CAP_DFS
, /* in_capabilities */
933 0, /* in_previous_session_id */
934 &in_blob
); /* in_security_buffer */
935 if (subreq
== NULL
) {
936 printf("smb2cli_session_setup_send() returned NULL\n");
940 ok
= tevent_req_poll(subreq
, ev
);
942 printf("tevent_req_poll() returned false\n");
946 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
948 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
949 printf("smb2cli_session_setup_recv returned %s\n",
954 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, out_blob
, &in_blob
);
955 if (!NT_STATUS_IS_OK(status
)) {
956 printf("auth_generic_update returned %s\n", nt_errstr(status
));
960 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
965 SMB2_CAP_DFS
, /* in_capabilities */
967 0, /* in_previous_session_id */
968 &in_blob
); /* in_security_buffer */
969 if (subreq
== NULL
) {
970 printf("smb2cli_session_setup_send() returned NULL\n");
974 ok
= tevent_req_poll(subreq
, ev
);
976 printf("tevent_req_poll() returned false\n");
980 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
981 &recv_iov
, &out_blob
);
982 if (!NT_STATUS_IS_OK(status
)) {
983 printf("smb2cli_session_setup_recv returned %s\n",
988 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
989 &channel_session_key
);
990 if (!NT_STATUS_IS_OK(status
)) {
991 printf("gensec_session_key returned %s\n",
996 status
= smb2cli_session_set_channel_key(cli2
->smb2
.session
,
999 if (!NT_STATUS_IS_OK(status
)) {
1000 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status
));
1004 cli2
->smb2
.tid
= cli1
->smb2
.tid
;
1006 status
= smb2cli_session_create_channel(cli3
,
1009 &cli3
->smb2
.session
);
1010 if (!NT_STATUS_IS_OK(status
)) {
1011 printf("smb2cli_session_create_channel returned %s\n",
1016 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1017 if (!NT_STATUS_IS_OK(status
)) {
1018 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1022 gensec_want_feature(auth_generic_state
->gensec_security
,
1023 GENSEC_FEATURE_SESSION_KEY
);
1024 status
= auth_generic_set_username(auth_generic_state
, username
);
1025 if (!NT_STATUS_IS_OK(status
)) {
1026 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
1030 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
1031 if (!NT_STATUS_IS_OK(status
)) {
1032 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
1036 status
= auth_generic_set_password(auth_generic_state
, password
);
1037 if (!NT_STATUS_IS_OK(status
)) {
1038 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
1042 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1043 if (!NT_STATUS_IS_OK(status
)) {
1044 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1048 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, data_blob_null
, &in_blob
);
1049 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1050 printf("gensec_update returned %s\n", nt_errstr(status
));
1054 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1058 0x01, /* in_flags */
1059 SMB2_CAP_DFS
, /* in_capabilities */
1061 0, /* in_previous_session_id */
1062 &in_blob
); /* in_security_buffer */
1063 if (subreq
== NULL
) {
1064 printf("smb2cli_session_setup_send() returned NULL\n");
1068 ok
= tevent_req_poll(subreq
, ev
);
1070 printf("tevent_req_poll() returned false\n");
1074 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1076 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1077 printf("smb2cli_session_setup_recv returned %s\n",
1082 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, out_blob
, &in_blob
);
1083 if (!NT_STATUS_IS_OK(status
)) {
1084 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1088 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1092 0x01, /* in_flags */
1093 SMB2_CAP_DFS
, /* in_capabilities */
1095 0, /* in_previous_session_id */
1096 &in_blob
); /* in_security_buffer */
1097 if (subreq
== NULL
) {
1098 printf("smb2cli_session_setup_send() returned NULL\n");
1102 ok
= tevent_req_poll(subreq
, ev
);
1104 printf("tevent_req_poll() returned false\n");
1108 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1109 &recv_iov
, &out_blob
);
1110 if (!NT_STATUS_IS_OK(status
)) {
1111 printf("smb2cli_session_setup_recv returned %s\n",
1116 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
1117 &channel_session_key
);
1118 if (!NT_STATUS_IS_OK(status
)) {
1119 printf("gensec_session_key returned %s\n",
1124 status
= smb2cli_session_set_channel_key(cli3
->smb2
.session
,
1125 channel_session_key
,
1127 if (!NT_STATUS_IS_OK(status
)) {
1128 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status
));
1132 cli3
->smb2
.tid
= cli2
->smb2
.tid
;
1134 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1135 cli2
->smb2
.tid
, "multi-channel.txt",
1136 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1137 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1138 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1139 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1140 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1141 FILE_CREATE
, /* create_disposition, */
1142 FILE_DELETE_ON_CLOSE
, /* create_options, */
1143 NULL
, /* smb2_create_blobs *blobs */
1146 if (!NT_STATUS_IS_OK(status
)) {
1147 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
1151 status
= smb2cli_write(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1152 cli1
->smb2
.tid
, strlen(hello
), 0, fid_persistent
,
1153 fid_volatile
, 0, 0, (const uint8_t *)hello
);
1154 if (!NT_STATUS_IS_OK(status
)) {
1155 printf("smb2cli_write returned %s\n", nt_errstr(status
));
1159 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1160 cli2
->smb2
.tid
, fid_persistent
, fid_volatile
);
1161 if (!NT_STATUS_IS_OK(status
)) {
1162 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1166 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1167 cli1
->smb2
.tid
, fid_persistent
, fid_volatile
);
1168 if (!NT_STATUS_IS_OK(status
)) {
1169 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1173 status
= smb2cli_flush(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1174 cli3
->smb2
.tid
, fid_persistent
, fid_volatile
);
1175 if (!NT_STATUS_IS_OK(status
)) {
1176 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1180 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1181 cli2
->smb2
.tid
, 0x10000, 0, fid_persistent
,
1183 talloc_tos(), &result
, &nread
);
1184 if (!NT_STATUS_IS_OK(status
)) {
1185 printf("smb2cli_read returned %s\n", nt_errstr(status
));
1189 if (nread
!= strlen(hello
)) {
1190 printf("smb2cli_read returned %d bytes, expected %d\n",
1191 (int)nread
, (int)strlen(hello
));
1195 if (memcmp(hello
, result
, nread
) != 0) {
1196 printf("smb2cli_read returned '%s', expected '%s'\n",
1201 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1202 if (!NT_STATUS_IS_OK(status
)) {
1203 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1207 gensec_want_feature(auth_generic_state
->gensec_security
,
1208 GENSEC_FEATURE_SESSION_KEY
);
1209 status
= auth_generic_set_username(auth_generic_state
, username
);
1210 if (!NT_STATUS_IS_OK(status
)) {
1211 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
1215 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
1216 if (!NT_STATUS_IS_OK(status
)) {
1217 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
1221 status
= auth_generic_set_password(auth_generic_state
, password
);
1222 if (!NT_STATUS_IS_OK(status
)) {
1223 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
1227 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1228 if (!NT_STATUS_IS_OK(status
)) {
1229 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1233 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, data_blob_null
, &in_blob
);
1234 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1235 printf("gensec_update returned %s\n", nt_errstr(status
));
1239 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1244 SMB2_CAP_DFS
, /* in_capabilities */
1246 0, /* in_previous_session_id */
1247 &in_blob
); /* in_security_buffer */
1248 if (subreq
== NULL
) {
1249 printf("smb2cli_session_setup_send() returned NULL\n");
1253 ok
= tevent_req_poll(subreq
, ev
);
1255 printf("tevent_req_poll() returned false\n");
1259 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1261 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1262 printf("smb2cli_session_setup_recv returned %s\n",
1267 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, out_blob
, &in_blob
);
1268 if (!NT_STATUS_IS_OK(status
)) {
1269 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1273 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1274 cli1
->smb2
.tid
, fid_persistent
, fid_volatile
);
1275 if (!NT_STATUS_IS_OK(status
)) {
1276 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1280 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1281 cli2
->smb2
.tid
, fid_persistent
, fid_volatile
);
1282 if (!NT_STATUS_IS_OK(status
)) {
1283 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1287 status
= smb2cli_flush(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1288 cli3
->smb2
.tid
, fid_persistent
, fid_volatile
);
1289 if (!NT_STATUS_IS_OK(status
)) {
1290 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1294 status
= smb2cli_create(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1295 cli1
->smb2
.tid
, "multi-channel-invalid.txt",
1296 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1297 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1298 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1299 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1300 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1301 FILE_CREATE
, /* create_disposition, */
1302 FILE_DELETE_ON_CLOSE
, /* create_options, */
1303 NULL
, /* smb2_create_blobs *blobs */
1306 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1307 printf("smb2cli_create %s\n", nt_errstr(status
));
1311 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1312 cli2
->smb2
.tid
, "multi-channel-invalid.txt",
1313 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1314 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1315 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1316 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1317 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1318 FILE_CREATE
, /* create_disposition, */
1319 FILE_DELETE_ON_CLOSE
, /* create_options, */
1320 NULL
, /* smb2_create_blobs *blobs */
1323 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1324 printf("smb2cli_create %s\n", nt_errstr(status
));
1328 status
= smb2cli_create(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1329 cli3
->smb2
.tid
, "multi-channel-invalid.txt",
1330 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1331 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1332 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1333 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1334 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1335 FILE_CREATE
, /* create_disposition, */
1336 FILE_DELETE_ON_CLOSE
, /* create_options, */
1337 NULL
, /* smb2_create_blobs *blobs */
1340 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1341 printf("smb2cli_create %s\n", nt_errstr(status
));
1345 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1350 SMB2_CAP_DFS
, /* in_capabilities */
1352 0, /* in_previous_session_id */
1353 &in_blob
); /* in_security_buffer */
1354 if (subreq
== NULL
) {
1355 printf("smb2cli_session_setup_send() returned NULL\n");
1359 ok
= tevent_req_poll(subreq
, ev
);
1361 printf("tevent_req_poll() returned false\n");
1365 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1366 &recv_iov
, &out_blob
);
1367 if (!NT_STATUS_IS_OK(status
)) {
1368 printf("smb2cli_session_setup_recv returned %s\n",
1373 status
= smb2cli_close(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1374 cli3
->smb2
.tid
, 0, fid_persistent
, fid_volatile
);
1375 if (!NT_STATUS_IS_OK(status
)) {
1376 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1380 status
= smb2cli_flush(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1381 cli3
->smb2
.tid
, fid_persistent
, fid_volatile
);
1382 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1383 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1387 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1388 cli2
->smb2
.tid
, fid_persistent
, fid_volatile
);
1389 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1390 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1394 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1395 cli1
->smb2
.tid
, fid_persistent
, fid_volatile
);
1396 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1397 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1404 bool run_smb2_session_reauth(int dummy
)
1406 struct cli_state
*cli
;
1409 uint64_t fid_persistent
, fid_volatile
;
1410 uint64_t dir_persistent
, dir_volatile
;
1412 uint32_t dir_data_length
;
1413 struct tevent_context
*ev
;
1414 struct tevent_req
*subreq
;
1415 DATA_BLOB in_blob
= data_blob_null
;
1417 DATA_BLOB in_input_buffer
;
1418 DATA_BLOB out_output_buffer
;
1419 uint8_t in_file_info_class
;
1420 struct auth_generic_state
*auth_generic_state
;
1421 struct iovec
*recv_iov
;
1424 printf("Starting SMB2-SESSION_REAUTH\n");
1426 if (!torture_init_connection(&cli
)) {
1429 cli
->smb2
.pid
= 0xFEFF;
1432 * PROTOCOL_SMB2_22 has a bug in win8pre0
1433 * it behaves like PROTOCOL_SMB2_02
1434 * and returns NT_STATUS_REQUEST_NOT_ACCEPTED,
1435 * while it allows it on PROTOCOL_SMB2_02.
1437 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
1438 PROTOCOL_SMB2_10
, PROTOCOL_SMB2_10
);
1439 if (!NT_STATUS_IS_OK(status
)) {
1440 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
1444 status
= cli_session_setup(cli
, username
,
1445 password
, strlen(password
),
1446 password
, strlen(password
),
1448 if (!NT_STATUS_IS_OK(status
)) {
1449 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status
));
1453 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
1454 if (!NT_STATUS_IS_OK(status
)) {
1455 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1459 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1460 cli
->smb2
.tid
, "session-reauth.txt",
1461 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1462 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1463 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1464 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1465 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1466 FILE_CREATE
, /* create_disposition, */
1467 FILE_DELETE_ON_CLOSE
, /* create_options, */
1468 NULL
, /* smb2_create_blobs *blobs */
1471 if (!NT_STATUS_IS_OK(status
)) {
1472 printf("smb2cli_create %s\n", nt_errstr(status
));
1476 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1478 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1479 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1480 SEC_STD_SYNCHRONIZE
|
1482 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
1483 0, /* file_attributes, */
1484 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1485 FILE_OPEN
, /* create_disposition, */
1486 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
1487 NULL
, /* smb2_create_blobs *blobs */
1490 if (!NT_STATUS_IS_OK(status
)) {
1491 printf("smb2cli_create returned %s\n", nt_errstr(status
));
1495 status
= smb2cli_query_directory(
1496 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tid
,
1497 1, 0x3, 0, dir_persistent
, dir_volatile
,
1498 "session-reauth.txt", 0xffff,
1499 talloc_tos(), &dir_data
, &dir_data_length
);
1500 if (!NT_STATUS_IS_OK(status
)) {
1501 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1505 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1506 if (!NT_STATUS_IS_OK(status
)) {
1507 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1511 gensec_want_feature(auth_generic_state
->gensec_security
,
1512 GENSEC_FEATURE_SESSION_KEY
);
1513 status
= auth_generic_set_username(auth_generic_state
, username
);
1514 if (!NT_STATUS_IS_OK(status
)) {
1515 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
1519 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
1520 if (!NT_STATUS_IS_OK(status
)) {
1521 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
1525 status
= auth_generic_set_password(auth_generic_state
, password
);
1526 if (!NT_STATUS_IS_OK(status
)) {
1527 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
1531 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1532 if (!NT_STATUS_IS_OK(status
)) {
1533 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1537 ev
= event_context_init(talloc_tos());
1539 printf("event_context_init() returned NULL\n");
1543 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, data_blob_null
, &in_blob
);
1544 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1545 printf("gensec_update returned %s\n", nt_errstr(status
));
1549 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1554 SMB2_CAP_DFS
, /* in_capabilities */
1556 0, /* in_previous_session_id */
1557 &in_blob
); /* in_security_buffer */
1558 if (subreq
== NULL
) {
1559 printf("smb2cli_session_setup_send() returned NULL\n");
1563 ok
= tevent_req_poll(subreq
, ev
);
1565 printf("tevent_req_poll() returned false\n");
1569 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1571 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1572 printf("smb2cli_session_setup_recv returned %s\n",
1577 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, out_blob
, &in_blob
);
1578 if (!NT_STATUS_IS_OK(status
)) {
1579 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1583 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1584 cli
->smb2
.tid
, fid_persistent
, fid_volatile
);
1585 if (!NT_STATUS_IS_OK(status
)) {
1586 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1590 status
= smb2cli_query_directory(
1591 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tid
,
1592 1, 0x3, 0, dir_persistent
, dir_volatile
,
1593 "session-reauth.txt", 0xffff,
1594 talloc_tos(), &dir_data
, &dir_data_length
);
1595 if (!NT_STATUS_IS_OK(status
)) {
1596 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1601 * query_info seems to be a path based operation on Windows...
1603 status
= smb2cli_query_info(cli
->conn
,
1607 SMB2_GETINFO_SECURITY
,
1608 0, /* in_file_info_class */
1609 1024, /* in_max_output_length */
1610 NULL
, /* in_input_buffer */
1611 SECINFO_OWNER
, /* in_additional_info */
1616 &out_output_buffer
);
1617 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1618 printf("smb2cli_query_info (security) returned %s\n", nt_errstr(status
));
1622 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1623 status
= smb2cli_query_info(cli
->conn
,
1629 1024, /* in_max_output_length */
1630 NULL
, /* in_input_buffer */
1631 0, /* in_additional_info */
1636 &out_output_buffer
);
1637 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1638 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1642 in_input_buffer
= data_blob_talloc(talloc_tos(), NULL
, 8);
1643 SBVAL(in_input_buffer
.data
, 0, 512);
1645 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1646 status
= smb2cli_set_info(cli
->conn
,
1653 0, /* in_additional_info */
1656 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1657 printf("smb2cli_set_info (position) returned %s\n", nt_errstr(status
));
1661 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1662 cli
->smb2
.tid
, "session-reauth-invalid.txt",
1663 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1664 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1665 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1666 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1667 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1668 FILE_CREATE
, /* create_disposition, */
1669 FILE_DELETE_ON_CLOSE
, /* create_options, */
1670 NULL
, /* smb2_create_blobs *blobs */
1673 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1674 printf("smb2cli_create %s\n", nt_errstr(status
));
1678 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1680 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1681 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1682 SEC_STD_SYNCHRONIZE
|
1684 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
1685 0, /* file_attributes, */
1686 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1687 FILE_OPEN
, /* create_disposition, */
1688 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
1689 NULL
, /* smb2_create_blobs *blobs */
1692 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1693 printf("smb2cli_create returned %s\n", nt_errstr(status
));
1697 saved_tid
= cli
->smb2
.tid
;
1698 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
1699 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1700 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1703 cli
->smb2
.tid
= saved_tid
;
1705 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1710 SMB2_CAP_DFS
, /* in_capabilities */
1712 0, /* in_previous_session_id */
1713 &in_blob
); /* in_security_buffer */
1714 if (subreq
== NULL
) {
1715 printf("smb2cli_session_setup_send() returned NULL\n");
1719 ok
= tevent_req_poll(subreq
, ev
);
1721 printf("tevent_req_poll() returned false\n");
1725 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1726 &recv_iov
, &out_blob
);
1727 if (!NT_STATUS_IS_OK(status
)) {
1728 printf("smb2cli_session_setup_recv returned %s\n",
1733 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1734 cli
->smb2
.tid
, fid_persistent
, fid_volatile
);
1735 if (!NT_STATUS_IS_OK(status
)) {
1736 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1740 status
= smb2cli_query_info(cli
->conn
,
1744 SMB2_GETINFO_SECURITY
,
1745 0, /* in_file_info_class */
1746 1024, /* in_max_output_length */
1747 NULL
, /* in_input_buffer */
1748 SECINFO_OWNER
, /* in_additional_info */
1753 &out_output_buffer
);
1754 if (!NT_STATUS_IS_OK(status
)) {
1755 printf("smb2cli_query_info (security) returned %s\n", nt_errstr(status
));
1759 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1760 status
= smb2cli_query_info(cli
->conn
,
1766 1024, /* in_max_output_length */
1767 NULL
, /* in_input_buffer */
1768 0, /* in_additional_info */
1773 &out_output_buffer
);
1774 if (!NT_STATUS_IS_OK(status
)) {
1775 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1779 in_input_buffer
= data_blob_talloc(talloc_tos(), NULL
, 8);
1780 SBVAL(in_input_buffer
.data
, 0, 512);
1782 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1783 status
= smb2cli_set_info(cli
->conn
,
1790 0, /* in_additional_info */
1793 if (!NT_STATUS_IS_OK(status
)) {
1794 printf("smb2cli_set_info (position) returned %s\n", nt_errstr(status
));
1798 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1799 status
= smb2cli_query_info(cli
->conn
,
1805 1024, /* in_max_output_length */
1806 NULL
, /* in_input_buffer */
1807 0, /* in_additional_info */
1812 &out_output_buffer
);
1813 if (!NT_STATUS_IS_OK(status
)) {
1814 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1818 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1819 cli
->smb2
.tid
, 0, fid_persistent
, fid_volatile
);
1820 if (!NT_STATUS_IS_OK(status
)) {
1821 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1825 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1826 cli
->smb2
.tid
, "session-reauth.txt",
1827 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1828 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1829 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1830 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1831 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1832 FILE_CREATE
, /* create_disposition, */
1833 FILE_DELETE_ON_CLOSE
, /* create_options, */
1834 NULL
, /* smb2_create_blobs *blobs */
1837 if (!NT_STATUS_IS_OK(status
)) {
1838 printf("smb2cli_create %s\n", nt_errstr(status
));
1842 status
= smb2cli_query_directory(
1843 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tid
,
1844 1, 0x3, 0, dir_persistent
, dir_volatile
,
1845 "session-reauth.txt", 0xffff,
1846 talloc_tos(), &dir_data
, &dir_data_length
);
1847 if (!NT_STATUS_IS_OK(status
)) {
1848 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1852 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1853 cli
->smb2
.tid
, 0, dir_persistent
, dir_volatile
);
1854 if (!NT_STATUS_IS_OK(status
)) {
1855 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1859 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1860 cli
->smb2
.tid
, 0, fid_persistent
, fid_volatile
);
1861 if (!NT_STATUS_IS_OK(status
)) {
1862 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1866 saved_tid
= cli
->smb2
.tid
;
1867 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
1868 if (!NT_STATUS_IS_OK(status
)) {
1869 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1872 cli
->smb2
.tid
= saved_tid
;