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 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
535 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
539 status
= smb2cli_write(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
540 cli2
->smb2
.tid
, strlen(hello
), 0, fid_persistent
,
541 fid_volatile
, 0, 0, (const uint8_t *)hello
);
542 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
543 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
545 printf("smb2cli_write returned %s\n", nt_errstr(status
));
549 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
550 cli2
->smb2
.tid
, 0x10000, 0, fid_persistent
,
552 talloc_tos(), &result
, &nread
);
553 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
554 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
556 printf("smb2cli_read returned %s\n", nt_errstr(status
));
560 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
561 cli2
->smb2
.tid
, "session-reconnect.txt",
562 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
563 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
564 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
565 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
566 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
567 FILE_CREATE
, /* create_disposition, */
568 FILE_DELETE_ON_CLOSE
, /* create_options, */
569 NULL
, /* smb2_create_blobs *blobs */
572 if (!NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
) &&
573 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
574 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
578 /* now grab the session key and try with signing */
580 status
= smb2cli_session_set_session_key(cli2
->smb2
.session
,
583 if (!NT_STATUS_IS_OK(status
)) {
584 printf("smb2cli_session_set_session_key %s\n", nt_errstr(status
));
588 /* the tid seems to be irrelevant at this stage */
590 cli2
->smb2
.tid
= cli1
->smb2
.tid
;
592 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
593 cli2
->smb2
.tid
, fid_persistent
, fid_volatile
);
594 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
595 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
597 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
601 status
= smb2cli_write(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
602 cli2
->smb2
.tid
, strlen(hello
), 0, fid_persistent
,
603 fid_volatile
, 0, 0, (const uint8_t *)hello
);
604 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
605 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
607 printf("smb2cli_write returned %s\n", nt_errstr(status
));
611 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
612 cli2
->smb2
.tid
, 0x10000, 0, fid_persistent
,
614 talloc_tos(), &result
, &nread
);
615 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
616 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
618 printf("smb2cli_read returned %s\n", nt_errstr(status
));
622 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
623 cli2
->smb2
.tid
, "session-reconnect.txt",
624 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
625 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
626 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
627 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
628 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
629 FILE_CREATE
, /* create_disposition, */
630 FILE_DELETE_ON_CLOSE
, /* create_options, */
631 NULL
, /* smb2_create_blobs *blobs */
634 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
) &&
635 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
637 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
641 /* now do a new tcon and test file calls again */
643 status
= cli_tree_connect(cli2
, share
, "?????", "", 0);
644 if (!NT_STATUS_IS_OK(status
)) {
645 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
649 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
650 cli2
->smb2
.tid
, "session-reconnect.txt",
651 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
652 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
653 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
654 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
655 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
656 FILE_CREATE
, /* create_disposition, */
657 FILE_DELETE_ON_CLOSE
, /* create_options, */
658 NULL
, /* smb2_create_blobs *blobs */
661 if (!NT_STATUS_IS_OK(status
)) {
662 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
666 status
= smb2cli_write(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
667 cli2
->smb2
.tid
, strlen(hello
), 0, fid_persistent
,
668 fid_volatile
, 0, 0, (const uint8_t *)hello
);
669 if (!NT_STATUS_IS_OK(status
)) {
670 printf("smb2cli_write returned %s\n", nt_errstr(status
));
674 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
675 cli2
->smb2
.tid
, fid_persistent
, fid_volatile
);
676 if (!NT_STATUS_IS_OK(status
)) {
677 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
681 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
682 cli2
->smb2
.tid
, 0x10000, 0, fid_persistent
,
684 talloc_tos(), &result
, &nread
);
685 if (!NT_STATUS_IS_OK(status
)) {
686 printf("smb2cli_read returned %s\n", nt_errstr(status
));
690 if (nread
!= strlen(hello
)) {
691 printf("smb2cli_read returned %d bytes, expected %d\n",
692 (int)nread
, (int)strlen(hello
));
696 if (memcmp(hello
, result
, nread
) != 0) {
697 printf("smb2cli_read returned '%s', expected '%s'\n",
705 bool run_smb2_tcon_dependence(int dummy
)
707 struct cli_state
*cli
;
709 uint64_t fid_persistent
, fid_volatile
;
710 const char *hello
= "Hello, world\n";
714 printf("Starting SMB2-TCON-DEPENDENCE\n");
716 if (!torture_init_connection(&cli
)) {
719 cli
->smb2
.pid
= 0xFEFF;
721 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
722 PROTOCOL_SMB2_02
, PROTOCOL_LATEST
);
723 if (!NT_STATUS_IS_OK(status
)) {
724 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
728 status
= cli_session_setup(cli
, username
,
729 password
, strlen(password
),
730 password
, strlen(password
),
732 if (!NT_STATUS_IS_OK(status
)) {
733 printf("cli_session_setup returned %s\n", nt_errstr(status
));
737 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
738 if (!NT_STATUS_IS_OK(status
)) {
739 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
743 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
744 cli
->smb2
.tid
, "tcon_depedence.txt",
745 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
746 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
747 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
748 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
749 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
750 FILE_CREATE
, /* create_disposition, */
751 FILE_DELETE_ON_CLOSE
, /* create_options, */
752 NULL
, /* smb2_create_blobs *blobs */
755 if (!NT_STATUS_IS_OK(status
)) {
756 printf("smb2cli_create on cli %s\n", nt_errstr(status
));
760 status
= smb2cli_write(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
761 cli
->smb2
.tid
, strlen(hello
), 0, fid_persistent
,
762 fid_volatile
, 0, 0, (const uint8_t *)hello
);
763 if (!NT_STATUS_IS_OK(status
)) {
764 printf("smb2cli_write returned %s\n", nt_errstr(status
));
768 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
769 cli
->smb2
.tid
, fid_persistent
, fid_volatile
);
770 if (!NT_STATUS_IS_OK(status
)) {
771 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
775 status
= smb2cli_read(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
776 cli
->smb2
.tid
, 0x10000, 0, fid_persistent
,
778 talloc_tos(), &result
, &nread
);
779 if (!NT_STATUS_IS_OK(status
)) {
780 printf("smb2cli_read returned %s\n", nt_errstr(status
));
784 if (nread
!= strlen(hello
)) {
785 printf("smb2cli_read returned %d bytes, expected %d\n",
786 (int)nread
, (int)strlen(hello
));
790 if (memcmp(hello
, result
, nread
) != 0) {
791 printf("smb2cli_read returned '%s', expected '%s'\n",
796 /* check behaviour with wrong tid... */
800 status
= smb2cli_read(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
801 cli
->smb2
.tid
, 0x10000, 0, fid_persistent
,
803 talloc_tos(), &result
, &nread
);
804 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
805 printf("smb2cli_read returned %s\n", nt_errstr(status
));
814 bool run_smb2_multi_channel(int dummy
)
816 struct cli_state
*cli1
;
817 struct cli_state
*cli2
;
818 struct cli_state
*cli3
;
821 uint64_t fid_persistent
, fid_volatile
;
822 struct tevent_context
*ev
;
823 struct tevent_req
*subreq
;
824 DATA_BLOB in_blob
= data_blob_null
;
826 DATA_BLOB channel_session_key
;
827 struct auth_generic_state
*auth_generic_state
;
828 struct iovec
*recv_iov
;
829 const char *hello
= "Hello, world\n";
833 printf("Starting SMB2-MULTI-CHANNEL\n");
835 if (!torture_init_connection(&cli1
)) {
838 cli1
->smb2
.pid
= 0xFEFF;
840 if (!torture_init_connection(&cli2
)) {
843 cli2
->smb2
.pid
= 0xFEFF;
845 if (!torture_init_connection(&cli3
)) {
848 cli3
->smb2
.pid
= 0xFEFF;
850 status
= smbXcli_negprot(cli1
->conn
, cli1
->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
= smbXcli_negprot(cli2
->conn
, cli2
->timeout
,
858 PROTOCOL_SMB2_22
, PROTOCOL_LATEST
);
859 if (!NT_STATUS_IS_OK(status
)) {
860 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
864 status
= smbXcli_negprot(cli3
->conn
, cli3
->timeout
,
865 PROTOCOL_SMB2_22
, PROTOCOL_LATEST
);
866 if (!NT_STATUS_IS_OK(status
)) {
867 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
871 status
= cli_session_setup(cli1
, username
,
872 password
, strlen(password
),
873 password
, strlen(password
),
875 if (!NT_STATUS_IS_OK(status
)) {
876 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status
));
880 status
= cli_tree_connect(cli1
, share
, "?????", "", 0);
881 if (!NT_STATUS_IS_OK(status
)) {
882 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
886 status
= smb2cli_session_create_channel(cli2
,
889 &cli2
->smb2
.session
);
890 if (!NT_STATUS_IS_OK(status
)) {
891 printf("smb2cli_session_create_channel returned %s\n",
896 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
897 if (!NT_STATUS_IS_OK(status
)) {
898 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
902 gensec_want_feature(auth_generic_state
->gensec_security
,
903 GENSEC_FEATURE_SESSION_KEY
);
904 status
= auth_generic_set_username(auth_generic_state
, username
);
905 if (!NT_STATUS_IS_OK(status
)) {
906 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
910 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
911 if (!NT_STATUS_IS_OK(status
)) {
912 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
916 status
= auth_generic_set_password(auth_generic_state
, password
);
917 if (!NT_STATUS_IS_OK(status
)) {
918 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
922 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
923 if (!NT_STATUS_IS_OK(status
)) {
924 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
928 ev
= event_context_init(talloc_tos());
930 printf("event_context_init() returned NULL\n");
934 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, data_blob_null
, &in_blob
);
935 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
936 printf("gensec_update returned %s\n", nt_errstr(status
));
940 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
945 SMB2_CAP_DFS
, /* in_capabilities */
947 0, /* in_previous_session_id */
948 &in_blob
); /* in_security_buffer */
949 if (subreq
== NULL
) {
950 printf("smb2cli_session_setup_send() returned NULL\n");
954 ok
= tevent_req_poll(subreq
, ev
);
956 printf("tevent_req_poll() returned false\n");
960 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
962 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
963 printf("smb2cli_session_setup_recv returned %s\n",
968 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, out_blob
, &in_blob
);
969 if (!NT_STATUS_IS_OK(status
)) {
970 printf("auth_generic_update returned %s\n", nt_errstr(status
));
974 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
979 SMB2_CAP_DFS
, /* in_capabilities */
981 0, /* in_previous_session_id */
982 &in_blob
); /* in_security_buffer */
983 if (subreq
== NULL
) {
984 printf("smb2cli_session_setup_send() returned NULL\n");
988 ok
= tevent_req_poll(subreq
, ev
);
990 printf("tevent_req_poll() returned false\n");
994 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
995 &recv_iov
, &out_blob
);
996 if (!NT_STATUS_IS_OK(status
)) {
997 printf("smb2cli_session_setup_recv returned %s\n",
1002 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
1003 &channel_session_key
);
1004 if (!NT_STATUS_IS_OK(status
)) {
1005 printf("gensec_session_key returned %s\n",
1010 status
= smb2cli_session_set_channel_key(cli2
->smb2
.session
,
1011 channel_session_key
,
1013 if (!NT_STATUS_IS_OK(status
)) {
1014 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status
));
1018 cli2
->smb2
.tid
= cli1
->smb2
.tid
;
1020 status
= smb2cli_session_create_channel(cli3
,
1023 &cli3
->smb2
.session
);
1024 if (!NT_STATUS_IS_OK(status
)) {
1025 printf("smb2cli_session_create_channel returned %s\n",
1030 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1031 if (!NT_STATUS_IS_OK(status
)) {
1032 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1036 gensec_want_feature(auth_generic_state
->gensec_security
,
1037 GENSEC_FEATURE_SESSION_KEY
);
1038 status
= auth_generic_set_username(auth_generic_state
, username
);
1039 if (!NT_STATUS_IS_OK(status
)) {
1040 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
1044 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
1045 if (!NT_STATUS_IS_OK(status
)) {
1046 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
1050 status
= auth_generic_set_password(auth_generic_state
, password
);
1051 if (!NT_STATUS_IS_OK(status
)) {
1052 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
1056 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1057 if (!NT_STATUS_IS_OK(status
)) {
1058 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1062 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, data_blob_null
, &in_blob
);
1063 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1064 printf("gensec_update returned %s\n", nt_errstr(status
));
1068 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1072 0x01, /* in_flags */
1073 SMB2_CAP_DFS
, /* in_capabilities */
1075 0, /* in_previous_session_id */
1076 &in_blob
); /* in_security_buffer */
1077 if (subreq
== NULL
) {
1078 printf("smb2cli_session_setup_send() returned NULL\n");
1082 ok
= tevent_req_poll(subreq
, ev
);
1084 printf("tevent_req_poll() returned false\n");
1088 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1090 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1091 printf("smb2cli_session_setup_recv returned %s\n",
1096 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, out_blob
, &in_blob
);
1097 if (!NT_STATUS_IS_OK(status
)) {
1098 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1102 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1106 0x01, /* in_flags */
1107 SMB2_CAP_DFS
, /* in_capabilities */
1109 0, /* in_previous_session_id */
1110 &in_blob
); /* in_security_buffer */
1111 if (subreq
== NULL
) {
1112 printf("smb2cli_session_setup_send() returned NULL\n");
1116 ok
= tevent_req_poll(subreq
, ev
);
1118 printf("tevent_req_poll() returned false\n");
1122 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1123 &recv_iov
, &out_blob
);
1124 if (!NT_STATUS_IS_OK(status
)) {
1125 printf("smb2cli_session_setup_recv returned %s\n",
1130 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
1131 &channel_session_key
);
1132 if (!NT_STATUS_IS_OK(status
)) {
1133 printf("gensec_session_key returned %s\n",
1138 status
= smb2cli_session_set_channel_key(cli3
->smb2
.session
,
1139 channel_session_key
,
1141 if (!NT_STATUS_IS_OK(status
)) {
1142 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status
));
1146 cli3
->smb2
.tid
= cli2
->smb2
.tid
;
1148 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1149 cli2
->smb2
.tid
, "multi-channel.txt",
1150 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1151 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1152 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1153 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1154 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1155 FILE_CREATE
, /* create_disposition, */
1156 FILE_DELETE_ON_CLOSE
, /* create_options, */
1157 NULL
, /* smb2_create_blobs *blobs */
1160 if (!NT_STATUS_IS_OK(status
)) {
1161 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
1165 status
= smb2cli_write(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1166 cli1
->smb2
.tid
, strlen(hello
), 0, fid_persistent
,
1167 fid_volatile
, 0, 0, (const uint8_t *)hello
);
1168 if (!NT_STATUS_IS_OK(status
)) {
1169 printf("smb2cli_write returned %s\n", nt_errstr(status
));
1173 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1174 cli2
->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_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1181 cli1
->smb2
.tid
, fid_persistent
, fid_volatile
);
1182 if (!NT_STATUS_IS_OK(status
)) {
1183 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1187 status
= smb2cli_flush(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1188 cli3
->smb2
.tid
, fid_persistent
, fid_volatile
);
1189 if (!NT_STATUS_IS_OK(status
)) {
1190 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1194 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1195 cli2
->smb2
.tid
, 0x10000, 0, fid_persistent
,
1197 talloc_tos(), &result
, &nread
);
1198 if (!NT_STATUS_IS_OK(status
)) {
1199 printf("smb2cli_read returned %s\n", nt_errstr(status
));
1203 if (nread
!= strlen(hello
)) {
1204 printf("smb2cli_read returned %d bytes, expected %d\n",
1205 (int)nread
, (int)strlen(hello
));
1209 if (memcmp(hello
, result
, nread
) != 0) {
1210 printf("smb2cli_read returned '%s', expected '%s'\n",
1215 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1216 if (!NT_STATUS_IS_OK(status
)) {
1217 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1221 gensec_want_feature(auth_generic_state
->gensec_security
,
1222 GENSEC_FEATURE_SESSION_KEY
);
1223 status
= auth_generic_set_username(auth_generic_state
, username
);
1224 if (!NT_STATUS_IS_OK(status
)) {
1225 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
1229 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
1230 if (!NT_STATUS_IS_OK(status
)) {
1231 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
1235 status
= auth_generic_set_password(auth_generic_state
, password
);
1236 if (!NT_STATUS_IS_OK(status
)) {
1237 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
1241 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1242 if (!NT_STATUS_IS_OK(status
)) {
1243 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1247 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, data_blob_null
, &in_blob
);
1248 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1249 printf("gensec_update returned %s\n", nt_errstr(status
));
1253 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1258 SMB2_CAP_DFS
, /* in_capabilities */
1260 0, /* in_previous_session_id */
1261 &in_blob
); /* in_security_buffer */
1262 if (subreq
== NULL
) {
1263 printf("smb2cli_session_setup_send() returned NULL\n");
1267 ok
= tevent_req_poll(subreq
, ev
);
1269 printf("tevent_req_poll() returned false\n");
1273 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1275 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1276 printf("smb2cli_session_setup_recv returned %s\n",
1281 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, out_blob
, &in_blob
);
1282 if (!NT_STATUS_IS_OK(status
)) {
1283 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1287 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1288 cli1
->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_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1295 cli2
->smb2
.tid
, fid_persistent
, fid_volatile
);
1296 if (!NT_STATUS_IS_OK(status
)) {
1297 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1301 status
= smb2cli_flush(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1302 cli3
->smb2
.tid
, fid_persistent
, fid_volatile
);
1303 if (!NT_STATUS_IS_OK(status
)) {
1304 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1308 status
= smb2cli_create(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1309 cli1
->smb2
.tid
, "multi-channel-invalid.txt",
1310 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1311 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1312 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1313 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1314 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1315 FILE_CREATE
, /* create_disposition, */
1316 FILE_DELETE_ON_CLOSE
, /* create_options, */
1317 NULL
, /* smb2_create_blobs *blobs */
1320 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1321 printf("smb2cli_create %s\n", nt_errstr(status
));
1325 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1326 cli2
->smb2
.tid
, "multi-channel-invalid.txt",
1327 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1328 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1329 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1330 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1331 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1332 FILE_CREATE
, /* create_disposition, */
1333 FILE_DELETE_ON_CLOSE
, /* create_options, */
1334 NULL
, /* smb2_create_blobs *blobs */
1337 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1338 printf("smb2cli_create %s\n", nt_errstr(status
));
1342 status
= smb2cli_create(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1343 cli3
->smb2
.tid
, "multi-channel-invalid.txt",
1344 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1345 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1346 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1347 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1348 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1349 FILE_CREATE
, /* create_disposition, */
1350 FILE_DELETE_ON_CLOSE
, /* create_options, */
1351 NULL
, /* smb2_create_blobs *blobs */
1354 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1355 printf("smb2cli_create %s\n", nt_errstr(status
));
1359 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1364 SMB2_CAP_DFS
, /* in_capabilities */
1366 0, /* in_previous_session_id */
1367 &in_blob
); /* in_security_buffer */
1368 if (subreq
== NULL
) {
1369 printf("smb2cli_session_setup_send() returned NULL\n");
1373 ok
= tevent_req_poll(subreq
, ev
);
1375 printf("tevent_req_poll() returned false\n");
1379 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1380 &recv_iov
, &out_blob
);
1381 if (!NT_STATUS_IS_OK(status
)) {
1382 printf("smb2cli_session_setup_recv returned %s\n",
1387 status
= smb2cli_close(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1388 cli3
->smb2
.tid
, 0, fid_persistent
, fid_volatile
);
1389 if (!NT_STATUS_IS_OK(status
)) {
1390 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1394 status
= smb2cli_flush(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1395 cli3
->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
));
1401 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1402 cli2
->smb2
.tid
, fid_persistent
, fid_volatile
);
1403 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1404 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1408 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1409 cli1
->smb2
.tid
, fid_persistent
, fid_volatile
);
1410 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1411 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1418 bool run_smb2_session_reauth(int dummy
)
1420 struct cli_state
*cli
;
1423 uint64_t fid_persistent
, fid_volatile
;
1424 uint64_t dir_persistent
, dir_volatile
;
1426 uint32_t dir_data_length
;
1427 struct tevent_context
*ev
;
1428 struct tevent_req
*subreq
;
1429 DATA_BLOB in_blob
= data_blob_null
;
1431 DATA_BLOB in_input_buffer
;
1432 DATA_BLOB out_output_buffer
;
1433 uint8_t in_file_info_class
;
1434 struct auth_generic_state
*auth_generic_state
;
1435 struct iovec
*recv_iov
;
1438 printf("Starting SMB2-SESSION_REAUTH\n");
1440 if (!torture_init_connection(&cli
)) {
1443 cli
->smb2
.pid
= 0xFEFF;
1446 * PROTOCOL_SMB2_22 has a bug in win8pre0
1447 * it behaves like PROTOCOL_SMB2_02
1448 * and returns NT_STATUS_REQUEST_NOT_ACCEPTED,
1449 * while it allows it on PROTOCOL_SMB2_02.
1451 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
1452 PROTOCOL_SMB2_10
, PROTOCOL_SMB2_10
);
1453 if (!NT_STATUS_IS_OK(status
)) {
1454 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
1458 status
= cli_session_setup(cli
, username
,
1459 password
, strlen(password
),
1460 password
, strlen(password
),
1462 if (!NT_STATUS_IS_OK(status
)) {
1463 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status
));
1467 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
1468 if (!NT_STATUS_IS_OK(status
)) {
1469 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1473 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1474 cli
->smb2
.tid
, "session-reauth.txt",
1475 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1476 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1477 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1478 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1479 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1480 FILE_CREATE
, /* create_disposition, */
1481 FILE_DELETE_ON_CLOSE
, /* create_options, */
1482 NULL
, /* smb2_create_blobs *blobs */
1485 if (!NT_STATUS_IS_OK(status
)) {
1486 printf("smb2cli_create %s\n", nt_errstr(status
));
1490 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1492 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1493 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1494 SEC_STD_SYNCHRONIZE
|
1496 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
1497 0, /* file_attributes, */
1498 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1499 FILE_OPEN
, /* create_disposition, */
1500 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
1501 NULL
, /* smb2_create_blobs *blobs */
1504 if (!NT_STATUS_IS_OK(status
)) {
1505 printf("smb2cli_create returned %s\n", nt_errstr(status
));
1509 status
= smb2cli_query_directory(
1510 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tid
,
1511 1, 0x3, 0, dir_persistent
, dir_volatile
,
1512 "session-reauth.txt", 0xffff,
1513 talloc_tos(), &dir_data
, &dir_data_length
);
1514 if (!NT_STATUS_IS_OK(status
)) {
1515 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1519 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1520 if (!NT_STATUS_IS_OK(status
)) {
1521 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1525 gensec_want_feature(auth_generic_state
->gensec_security
,
1526 GENSEC_FEATURE_SESSION_KEY
);
1527 status
= auth_generic_set_username(auth_generic_state
, username
);
1528 if (!NT_STATUS_IS_OK(status
)) {
1529 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
1533 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
1534 if (!NT_STATUS_IS_OK(status
)) {
1535 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
1539 status
= auth_generic_set_password(auth_generic_state
, password
);
1540 if (!NT_STATUS_IS_OK(status
)) {
1541 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
1545 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1546 if (!NT_STATUS_IS_OK(status
)) {
1547 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1551 ev
= event_context_init(talloc_tos());
1553 printf("event_context_init() returned NULL\n");
1557 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, data_blob_null
, &in_blob
);
1558 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1559 printf("gensec_update returned %s\n", nt_errstr(status
));
1563 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1568 SMB2_CAP_DFS
, /* in_capabilities */
1570 0, /* in_previous_session_id */
1571 &in_blob
); /* in_security_buffer */
1572 if (subreq
== NULL
) {
1573 printf("smb2cli_session_setup_send() returned NULL\n");
1577 ok
= tevent_req_poll(subreq
, ev
);
1579 printf("tevent_req_poll() returned false\n");
1583 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1585 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1586 printf("smb2cli_session_setup_recv returned %s\n",
1591 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, out_blob
, &in_blob
);
1592 if (!NT_STATUS_IS_OK(status
)) {
1593 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1597 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1598 cli
->smb2
.tid
, fid_persistent
, fid_volatile
);
1599 if (!NT_STATUS_IS_OK(status
)) {
1600 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1604 status
= smb2cli_query_directory(
1605 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tid
,
1606 1, 0x3, 0, dir_persistent
, dir_volatile
,
1607 "session-reauth.txt", 0xffff,
1608 talloc_tos(), &dir_data
, &dir_data_length
);
1609 if (!NT_STATUS_IS_OK(status
)) {
1610 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1615 * query_info seems to be a path based operation on Windows...
1617 status
= smb2cli_query_info(cli
->conn
,
1621 SMB2_GETINFO_SECURITY
,
1622 0, /* in_file_info_class */
1623 1024, /* in_max_output_length */
1624 NULL
, /* in_input_buffer */
1625 SECINFO_OWNER
, /* in_additional_info */
1630 &out_output_buffer
);
1631 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1632 printf("smb2cli_query_info (security) returned %s\n", nt_errstr(status
));
1636 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1637 status
= smb2cli_query_info(cli
->conn
,
1643 1024, /* in_max_output_length */
1644 NULL
, /* in_input_buffer */
1645 0, /* in_additional_info */
1650 &out_output_buffer
);
1651 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1652 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1656 in_input_buffer
= data_blob_talloc(talloc_tos(), NULL
, 8);
1657 SBVAL(in_input_buffer
.data
, 0, 512);
1659 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1660 status
= smb2cli_set_info(cli
->conn
,
1667 0, /* in_additional_info */
1670 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1671 printf("smb2cli_set_info (position) returned %s\n", nt_errstr(status
));
1675 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1676 cli
->smb2
.tid
, "session-reauth-invalid.txt",
1677 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1678 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1679 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1680 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1681 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1682 FILE_CREATE
, /* create_disposition, */
1683 FILE_DELETE_ON_CLOSE
, /* create_options, */
1684 NULL
, /* smb2_create_blobs *blobs */
1687 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1688 printf("smb2cli_create %s\n", nt_errstr(status
));
1692 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1694 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1695 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1696 SEC_STD_SYNCHRONIZE
|
1698 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
1699 0, /* file_attributes, */
1700 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1701 FILE_OPEN
, /* create_disposition, */
1702 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
1703 NULL
, /* smb2_create_blobs *blobs */
1706 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1707 printf("smb2cli_create returned %s\n", nt_errstr(status
));
1711 saved_tid
= cli
->smb2
.tid
;
1712 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
1713 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1714 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1717 cli
->smb2
.tid
= saved_tid
;
1719 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1724 SMB2_CAP_DFS
, /* in_capabilities */
1726 0, /* in_previous_session_id */
1727 &in_blob
); /* in_security_buffer */
1728 if (subreq
== NULL
) {
1729 printf("smb2cli_session_setup_send() returned NULL\n");
1733 ok
= tevent_req_poll(subreq
, ev
);
1735 printf("tevent_req_poll() returned false\n");
1739 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1740 &recv_iov
, &out_blob
);
1741 if (!NT_STATUS_IS_OK(status
)) {
1742 printf("smb2cli_session_setup_recv returned %s\n",
1747 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1748 cli
->smb2
.tid
, fid_persistent
, fid_volatile
);
1749 if (!NT_STATUS_IS_OK(status
)) {
1750 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1754 status
= smb2cli_query_info(cli
->conn
,
1758 SMB2_GETINFO_SECURITY
,
1759 0, /* in_file_info_class */
1760 1024, /* in_max_output_length */
1761 NULL
, /* in_input_buffer */
1762 SECINFO_OWNER
, /* in_additional_info */
1767 &out_output_buffer
);
1768 if (!NT_STATUS_IS_OK(status
)) {
1769 printf("smb2cli_query_info (security) returned %s\n", nt_errstr(status
));
1773 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1774 status
= smb2cli_query_info(cli
->conn
,
1780 1024, /* in_max_output_length */
1781 NULL
, /* in_input_buffer */
1782 0, /* in_additional_info */
1787 &out_output_buffer
);
1788 if (!NT_STATUS_IS_OK(status
)) {
1789 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1793 in_input_buffer
= data_blob_talloc(talloc_tos(), NULL
, 8);
1794 SBVAL(in_input_buffer
.data
, 0, 512);
1796 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1797 status
= smb2cli_set_info(cli
->conn
,
1804 0, /* in_additional_info */
1807 if (!NT_STATUS_IS_OK(status
)) {
1808 printf("smb2cli_set_info (position) returned %s\n", nt_errstr(status
));
1812 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1813 status
= smb2cli_query_info(cli
->conn
,
1819 1024, /* in_max_output_length */
1820 NULL
, /* in_input_buffer */
1821 0, /* in_additional_info */
1826 &out_output_buffer
);
1827 if (!NT_STATUS_IS_OK(status
)) {
1828 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1832 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1833 cli
->smb2
.tid
, 0, fid_persistent
, fid_volatile
);
1834 if (!NT_STATUS_IS_OK(status
)) {
1835 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1839 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1840 cli
->smb2
.tid
, "session-reauth.txt",
1841 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1842 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1843 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1844 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1845 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1846 FILE_CREATE
, /* create_disposition, */
1847 FILE_DELETE_ON_CLOSE
, /* create_options, */
1848 NULL
, /* smb2_create_blobs *blobs */
1851 if (!NT_STATUS_IS_OK(status
)) {
1852 printf("smb2cli_create %s\n", nt_errstr(status
));
1856 status
= smb2cli_query_directory(
1857 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tid
,
1858 1, 0x3, 0, dir_persistent
, dir_volatile
,
1859 "session-reauth.txt", 0xffff,
1860 talloc_tos(), &dir_data
, &dir_data_length
);
1861 if (!NT_STATUS_IS_OK(status
)) {
1862 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1866 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1867 cli
->smb2
.tid
, 0, dir_persistent
, dir_volatile
);
1868 if (!NT_STATUS_IS_OK(status
)) {
1869 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1873 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1874 cli
->smb2
.tid
, 0, fid_persistent
, fid_volatile
);
1875 if (!NT_STATUS_IS_OK(status
)) {
1876 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1880 saved_tid
= cli
->smb2
.tid
;
1881 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
1882 if (!NT_STATUS_IS_OK(status
)) {
1883 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1886 cli
->smb2
.tid
= saved_tid
;