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
.tcon
, "smb2-basic.txt",
77 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
78 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
79 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
80 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
81 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
82 FILE_CREATE
, /* create_disposition, */
83 FILE_DELETE_ON_CLOSE
, /* create_options, */
84 NULL
, /* smb2_create_blobs *blobs */
87 if (!NT_STATUS_IS_OK(status
)) {
88 printf("smb2cli_create returned %s\n", nt_errstr(status
));
92 status
= smb2cli_write(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
93 cli
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
94 fid_volatile
, 0, 0, (const uint8_t *)hello
);
95 if (!NT_STATUS_IS_OK(status
)) {
96 printf("smb2cli_write returned %s\n", nt_errstr(status
));
100 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
101 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
102 if (!NT_STATUS_IS_OK(status
)) {
103 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
107 status
= smb2cli_read(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
108 cli
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
110 talloc_tos(), &result
, &nread
);
111 if (!NT_STATUS_IS_OK(status
)) {
112 printf("smb2cli_read returned %s\n", nt_errstr(status
));
116 if (nread
!= strlen(hello
)) {
117 printf("smb2cli_read returned %d bytes, expected %d\n",
118 (int)nread
, (int)strlen(hello
));
122 if (memcmp(hello
, result
, nread
) != 0) {
123 printf("smb2cli_read returned '%s', expected '%s'\n",
128 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
129 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
130 if (!NT_STATUS_IS_OK(status
)) {
131 printf("smb2cli_close returned %s\n", nt_errstr(status
));
135 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
137 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
138 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
141 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
142 0, /* file_attributes, */
143 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
144 FILE_OPEN
, /* create_disposition, */
145 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
146 NULL
, /* smb2_create_blobs *blobs */
149 if (!NT_STATUS_IS_OK(status
)) {
150 printf("smb2cli_create returned %s\n", nt_errstr(status
));
154 status
= smb2cli_query_directory(
155 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.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
.tcon
, 0, fid_persistent
, fid_volatile
);
166 if (!NT_STATUS_IS_OK(status
)) {
167 printf("smb2cli_close returned %s\n", nt_errstr(status
));
171 saved_tid
= 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
.tcon
, "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
.tcon
, 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
.tcon
, 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
.tcon
, 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
.tcon
, 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
.tcon
, 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
.tcon
, 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
.tcon
, 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
.tcon
, "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
.tcon
, 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
.tcon
, 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
.tcon
, 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
.tcon
, "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
.tcon
, "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
.tcon
, 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
.tcon
, 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
.tcon
, 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";
713 struct smbXcli_tcon
*tcon2
;
716 printf("Starting SMB2-TCON-DEPENDENCE\n");
718 if (!torture_init_connection(&cli
)) {
721 cli
->smb2
.pid
= 0xFEFF;
723 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
724 PROTOCOL_SMB2_02
, PROTOCOL_LATEST
);
725 if (!NT_STATUS_IS_OK(status
)) {
726 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
730 status
= cli_session_setup(cli
, username
,
731 password
, strlen(password
),
732 password
, strlen(password
),
734 if (!NT_STATUS_IS_OK(status
)) {
735 printf("cli_session_setup returned %s\n", nt_errstr(status
));
739 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
740 if (!NT_STATUS_IS_OK(status
)) {
741 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
745 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
746 cli
->smb2
.tcon
, "tcon_depedence.txt",
747 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
748 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
749 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
750 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
751 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
752 FILE_CREATE
, /* create_disposition, */
753 FILE_DELETE_ON_CLOSE
, /* create_options, */
754 NULL
, /* smb2_create_blobs *blobs */
757 if (!NT_STATUS_IS_OK(status
)) {
758 printf("smb2cli_create on cli %s\n", nt_errstr(status
));
762 status
= smb2cli_write(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
763 cli
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
764 fid_volatile
, 0, 0, (const uint8_t *)hello
);
765 if (!NT_STATUS_IS_OK(status
)) {
766 printf("smb2cli_write returned %s\n", nt_errstr(status
));
770 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
771 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
772 if (!NT_STATUS_IS_OK(status
)) {
773 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
777 status
= smb2cli_read(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
778 cli
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
780 talloc_tos(), &result
, &nread
);
781 if (!NT_STATUS_IS_OK(status
)) {
782 printf("smb2cli_read returned %s\n", nt_errstr(status
));
786 if (nread
!= strlen(hello
)) {
787 printf("smb2cli_read returned %d bytes, expected %d\n",
788 (int)nread
, (int)strlen(hello
));
792 if (memcmp(hello
, result
, nread
) != 0) {
793 printf("smb2cli_read returned '%s', expected '%s'\n",
798 /* check behaviour with wrong tid... */
800 tcon2
= smbXcli_tcon_create(cli
);
801 tcon2_id
= smb2cli_tcon_current_id(cli
->smb2
.tcon
);
803 smb2cli_tcon_set_values(tcon2
,
807 0, /* capabilities */
808 0 /* maximal_access */);
810 status
= smb2cli_read(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
811 tcon2
, 0x10000, 0, fid_persistent
,
813 talloc_tos(), &result
, &nread
);
814 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
815 printf("smb2cli_read returned %s\n", nt_errstr(status
));
824 bool run_smb2_multi_channel(int dummy
)
826 struct cli_state
*cli1
;
827 struct cli_state
*cli2
;
828 struct cli_state
*cli3
;
831 uint64_t fid_persistent
, fid_volatile
;
832 struct tevent_context
*ev
;
833 struct tevent_req
*subreq
;
834 DATA_BLOB in_blob
= data_blob_null
;
836 DATA_BLOB channel_session_key
;
837 struct auth_generic_state
*auth_generic_state
;
838 struct iovec
*recv_iov
;
839 const char *hello
= "Hello, world\n";
843 printf("Starting SMB2-MULTI-CHANNEL\n");
845 if (!torture_init_connection(&cli1
)) {
848 cli1
->smb2
.pid
= 0xFEFF;
850 if (!torture_init_connection(&cli2
)) {
853 cli2
->smb2
.pid
= 0xFEFF;
855 if (!torture_init_connection(&cli3
)) {
858 cli3
->smb2
.pid
= 0xFEFF;
860 status
= smbXcli_negprot(cli1
->conn
, cli1
->timeout
,
861 PROTOCOL_SMB2_22
, PROTOCOL_LATEST
);
862 if (!NT_STATUS_IS_OK(status
)) {
863 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
867 status
= smbXcli_negprot(cli2
->conn
, cli2
->timeout
,
868 PROTOCOL_SMB2_22
, PROTOCOL_LATEST
);
869 if (!NT_STATUS_IS_OK(status
)) {
870 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
874 status
= smbXcli_negprot(cli3
->conn
, cli3
->timeout
,
875 PROTOCOL_SMB2_22
, PROTOCOL_LATEST
);
876 if (!NT_STATUS_IS_OK(status
)) {
877 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
881 status
= cli_session_setup(cli1
, username
,
882 password
, strlen(password
),
883 password
, strlen(password
),
885 if (!NT_STATUS_IS_OK(status
)) {
886 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status
));
890 status
= cli_tree_connect(cli1
, share
, "?????", "", 0);
891 if (!NT_STATUS_IS_OK(status
)) {
892 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
896 status
= smb2cli_session_create_channel(cli2
,
899 &cli2
->smb2
.session
);
900 if (!NT_STATUS_IS_OK(status
)) {
901 printf("smb2cli_session_create_channel returned %s\n",
906 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
907 if (!NT_STATUS_IS_OK(status
)) {
908 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
912 gensec_want_feature(auth_generic_state
->gensec_security
,
913 GENSEC_FEATURE_SESSION_KEY
);
914 status
= auth_generic_set_username(auth_generic_state
, username
);
915 if (!NT_STATUS_IS_OK(status
)) {
916 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
920 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
921 if (!NT_STATUS_IS_OK(status
)) {
922 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
926 status
= auth_generic_set_password(auth_generic_state
, password
);
927 if (!NT_STATUS_IS_OK(status
)) {
928 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
932 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
933 if (!NT_STATUS_IS_OK(status
)) {
934 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
938 ev
= event_context_init(talloc_tos());
940 printf("event_context_init() returned NULL\n");
944 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, data_blob_null
, &in_blob
);
945 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
946 printf("gensec_update returned %s\n", nt_errstr(status
));
950 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
955 SMB2_CAP_DFS
, /* in_capabilities */
957 0, /* in_previous_session_id */
958 &in_blob
); /* in_security_buffer */
959 if (subreq
== NULL
) {
960 printf("smb2cli_session_setup_send() returned NULL\n");
964 ok
= tevent_req_poll(subreq
, ev
);
966 printf("tevent_req_poll() returned false\n");
970 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
972 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
973 printf("smb2cli_session_setup_recv returned %s\n",
978 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, out_blob
, &in_blob
);
979 if (!NT_STATUS_IS_OK(status
)) {
980 printf("auth_generic_update returned %s\n", nt_errstr(status
));
984 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
989 SMB2_CAP_DFS
, /* in_capabilities */
991 0, /* in_previous_session_id */
992 &in_blob
); /* in_security_buffer */
993 if (subreq
== NULL
) {
994 printf("smb2cli_session_setup_send() returned NULL\n");
998 ok
= tevent_req_poll(subreq
, ev
);
1000 printf("tevent_req_poll() returned false\n");
1004 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1005 &recv_iov
, &out_blob
);
1006 if (!NT_STATUS_IS_OK(status
)) {
1007 printf("smb2cli_session_setup_recv returned %s\n",
1012 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
1013 &channel_session_key
);
1014 if (!NT_STATUS_IS_OK(status
)) {
1015 printf("gensec_session_key returned %s\n",
1020 status
= smb2cli_session_set_channel_key(cli2
->smb2
.session
,
1021 channel_session_key
,
1023 if (!NT_STATUS_IS_OK(status
)) {
1024 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status
));
1028 cli2
->smb2
.tid
= cli1
->smb2
.tid
;
1030 status
= smb2cli_session_create_channel(cli3
,
1033 &cli3
->smb2
.session
);
1034 if (!NT_STATUS_IS_OK(status
)) {
1035 printf("smb2cli_session_create_channel returned %s\n",
1040 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1041 if (!NT_STATUS_IS_OK(status
)) {
1042 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1046 gensec_want_feature(auth_generic_state
->gensec_security
,
1047 GENSEC_FEATURE_SESSION_KEY
);
1048 status
= auth_generic_set_username(auth_generic_state
, username
);
1049 if (!NT_STATUS_IS_OK(status
)) {
1050 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
1054 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
1055 if (!NT_STATUS_IS_OK(status
)) {
1056 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
1060 status
= auth_generic_set_password(auth_generic_state
, password
);
1061 if (!NT_STATUS_IS_OK(status
)) {
1062 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
1066 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1067 if (!NT_STATUS_IS_OK(status
)) {
1068 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1072 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, data_blob_null
, &in_blob
);
1073 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1074 printf("gensec_update returned %s\n", nt_errstr(status
));
1078 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1082 0x01, /* in_flags */
1083 SMB2_CAP_DFS
, /* in_capabilities */
1085 0, /* in_previous_session_id */
1086 &in_blob
); /* in_security_buffer */
1087 if (subreq
== NULL
) {
1088 printf("smb2cli_session_setup_send() returned NULL\n");
1092 ok
= tevent_req_poll(subreq
, ev
);
1094 printf("tevent_req_poll() returned false\n");
1098 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1100 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1101 printf("smb2cli_session_setup_recv returned %s\n",
1106 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, out_blob
, &in_blob
);
1107 if (!NT_STATUS_IS_OK(status
)) {
1108 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1112 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1116 0x01, /* in_flags */
1117 SMB2_CAP_DFS
, /* in_capabilities */
1119 0, /* in_previous_session_id */
1120 &in_blob
); /* in_security_buffer */
1121 if (subreq
== NULL
) {
1122 printf("smb2cli_session_setup_send() returned NULL\n");
1126 ok
= tevent_req_poll(subreq
, ev
);
1128 printf("tevent_req_poll() returned false\n");
1132 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1133 &recv_iov
, &out_blob
);
1134 if (!NT_STATUS_IS_OK(status
)) {
1135 printf("smb2cli_session_setup_recv returned %s\n",
1140 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
1141 &channel_session_key
);
1142 if (!NT_STATUS_IS_OK(status
)) {
1143 printf("gensec_session_key returned %s\n",
1148 status
= smb2cli_session_set_channel_key(cli3
->smb2
.session
,
1149 channel_session_key
,
1151 if (!NT_STATUS_IS_OK(status
)) {
1152 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status
));
1156 cli3
->smb2
.tid
= cli2
->smb2
.tid
;
1158 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1159 cli2
->smb2
.tcon
, "multi-channel.txt",
1160 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1161 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1162 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1163 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1164 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1165 FILE_CREATE
, /* create_disposition, */
1166 FILE_DELETE_ON_CLOSE
, /* create_options, */
1167 NULL
, /* smb2_create_blobs *blobs */
1170 if (!NT_STATUS_IS_OK(status
)) {
1171 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
1175 status
= smb2cli_write(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1176 cli1
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
1177 fid_volatile
, 0, 0, (const uint8_t *)hello
);
1178 if (!NT_STATUS_IS_OK(status
)) {
1179 printf("smb2cli_write returned %s\n", nt_errstr(status
));
1183 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1184 cli2
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1185 if (!NT_STATUS_IS_OK(status
)) {
1186 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1190 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1191 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1192 if (!NT_STATUS_IS_OK(status
)) {
1193 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1197 status
= smb2cli_flush(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1198 cli3
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1199 if (!NT_STATUS_IS_OK(status
)) {
1200 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1204 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1205 cli2
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
1207 talloc_tos(), &result
, &nread
);
1208 if (!NT_STATUS_IS_OK(status
)) {
1209 printf("smb2cli_read returned %s\n", nt_errstr(status
));
1213 if (nread
!= strlen(hello
)) {
1214 printf("smb2cli_read returned %d bytes, expected %d\n",
1215 (int)nread
, (int)strlen(hello
));
1219 if (memcmp(hello
, result
, nread
) != 0) {
1220 printf("smb2cli_read returned '%s', expected '%s'\n",
1225 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1226 if (!NT_STATUS_IS_OK(status
)) {
1227 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1231 gensec_want_feature(auth_generic_state
->gensec_security
,
1232 GENSEC_FEATURE_SESSION_KEY
);
1233 status
= auth_generic_set_username(auth_generic_state
, username
);
1234 if (!NT_STATUS_IS_OK(status
)) {
1235 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
1239 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
1240 if (!NT_STATUS_IS_OK(status
)) {
1241 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
1245 status
= auth_generic_set_password(auth_generic_state
, password
);
1246 if (!NT_STATUS_IS_OK(status
)) {
1247 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
1251 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1252 if (!NT_STATUS_IS_OK(status
)) {
1253 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1257 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, data_blob_null
, &in_blob
);
1258 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1259 printf("gensec_update returned %s\n", nt_errstr(status
));
1263 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1268 SMB2_CAP_DFS
, /* in_capabilities */
1270 0, /* in_previous_session_id */
1271 &in_blob
); /* in_security_buffer */
1272 if (subreq
== NULL
) {
1273 printf("smb2cli_session_setup_send() returned NULL\n");
1277 ok
= tevent_req_poll(subreq
, ev
);
1279 printf("tevent_req_poll() returned false\n");
1283 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1285 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1286 printf("smb2cli_session_setup_recv returned %s\n",
1291 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, out_blob
, &in_blob
);
1292 if (!NT_STATUS_IS_OK(status
)) {
1293 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1297 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1298 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1299 if (!NT_STATUS_IS_OK(status
)) {
1300 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1304 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1305 cli2
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1306 if (!NT_STATUS_IS_OK(status
)) {
1307 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1311 status
= smb2cli_flush(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1312 cli3
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1313 if (!NT_STATUS_IS_OK(status
)) {
1314 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1318 status
= smb2cli_create(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1319 cli1
->smb2
.tcon
, "multi-channel-invalid.txt",
1320 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1321 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1322 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1323 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1324 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1325 FILE_CREATE
, /* create_disposition, */
1326 FILE_DELETE_ON_CLOSE
, /* create_options, */
1327 NULL
, /* smb2_create_blobs *blobs */
1330 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1331 printf("smb2cli_create %s\n", nt_errstr(status
));
1335 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1336 cli2
->smb2
.tcon
, "multi-channel-invalid.txt",
1337 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1338 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1339 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1340 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1341 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1342 FILE_CREATE
, /* create_disposition, */
1343 FILE_DELETE_ON_CLOSE
, /* create_options, */
1344 NULL
, /* smb2_create_blobs *blobs */
1347 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1348 printf("smb2cli_create %s\n", nt_errstr(status
));
1352 status
= smb2cli_create(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1353 cli3
->smb2
.tcon
, "multi-channel-invalid.txt",
1354 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1355 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1356 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1357 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1358 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1359 FILE_CREATE
, /* create_disposition, */
1360 FILE_DELETE_ON_CLOSE
, /* create_options, */
1361 NULL
, /* smb2_create_blobs *blobs */
1364 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1365 printf("smb2cli_create %s\n", nt_errstr(status
));
1369 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1374 SMB2_CAP_DFS
, /* in_capabilities */
1376 0, /* in_previous_session_id */
1377 &in_blob
); /* in_security_buffer */
1378 if (subreq
== NULL
) {
1379 printf("smb2cli_session_setup_send() returned NULL\n");
1383 ok
= tevent_req_poll(subreq
, ev
);
1385 printf("tevent_req_poll() returned false\n");
1389 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1390 &recv_iov
, &out_blob
);
1391 if (!NT_STATUS_IS_OK(status
)) {
1392 printf("smb2cli_session_setup_recv returned %s\n",
1397 status
= smb2cli_close(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1398 cli3
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
1399 if (!NT_STATUS_IS_OK(status
)) {
1400 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1404 status
= smb2cli_flush(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1405 cli3
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1406 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1407 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1411 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1412 cli2
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1413 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1414 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1418 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1419 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1420 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1421 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1428 bool run_smb2_session_reauth(int dummy
)
1430 struct cli_state
*cli
;
1433 uint64_t fid_persistent
, fid_volatile
;
1434 uint64_t dir_persistent
, dir_volatile
;
1436 uint32_t dir_data_length
;
1437 struct tevent_context
*ev
;
1438 struct tevent_req
*subreq
;
1439 DATA_BLOB in_blob
= data_blob_null
;
1441 DATA_BLOB in_input_buffer
;
1442 DATA_BLOB out_output_buffer
;
1443 uint8_t in_file_info_class
;
1444 struct auth_generic_state
*auth_generic_state
;
1445 struct iovec
*recv_iov
;
1448 printf("Starting SMB2-SESSION_REAUTH\n");
1450 if (!torture_init_connection(&cli
)) {
1453 cli
->smb2
.pid
= 0xFEFF;
1456 * PROTOCOL_SMB2_22 has a bug in win8pre0
1457 * it behaves like PROTOCOL_SMB2_02
1458 * and returns NT_STATUS_REQUEST_NOT_ACCEPTED,
1459 * while it allows it on PROTOCOL_SMB2_02.
1461 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
1462 PROTOCOL_SMB2_10
, PROTOCOL_SMB2_10
);
1463 if (!NT_STATUS_IS_OK(status
)) {
1464 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
1468 status
= cli_session_setup(cli
, username
,
1469 password
, strlen(password
),
1470 password
, strlen(password
),
1472 if (!NT_STATUS_IS_OK(status
)) {
1473 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status
));
1477 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
1478 if (!NT_STATUS_IS_OK(status
)) {
1479 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1483 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1484 cli
->smb2
.tcon
, "session-reauth.txt",
1485 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1486 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1487 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1488 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1489 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1490 FILE_CREATE
, /* create_disposition, */
1491 FILE_DELETE_ON_CLOSE
, /* create_options, */
1492 NULL
, /* smb2_create_blobs *blobs */
1495 if (!NT_STATUS_IS_OK(status
)) {
1496 printf("smb2cli_create %s\n", nt_errstr(status
));
1500 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1502 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1503 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1504 SEC_STD_SYNCHRONIZE
|
1506 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
1507 0, /* file_attributes, */
1508 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1509 FILE_OPEN
, /* create_disposition, */
1510 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
1511 NULL
, /* smb2_create_blobs *blobs */
1514 if (!NT_STATUS_IS_OK(status
)) {
1515 printf("smb2cli_create returned %s\n", nt_errstr(status
));
1519 status
= smb2cli_query_directory(
1520 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tid
,
1521 1, 0x3, 0, dir_persistent
, dir_volatile
,
1522 "session-reauth.txt", 0xffff,
1523 talloc_tos(), &dir_data
, &dir_data_length
);
1524 if (!NT_STATUS_IS_OK(status
)) {
1525 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1529 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1530 if (!NT_STATUS_IS_OK(status
)) {
1531 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1535 gensec_want_feature(auth_generic_state
->gensec_security
,
1536 GENSEC_FEATURE_SESSION_KEY
);
1537 status
= auth_generic_set_username(auth_generic_state
, username
);
1538 if (!NT_STATUS_IS_OK(status
)) {
1539 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
1543 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
1544 if (!NT_STATUS_IS_OK(status
)) {
1545 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
1549 status
= auth_generic_set_password(auth_generic_state
, password
);
1550 if (!NT_STATUS_IS_OK(status
)) {
1551 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
1555 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1556 if (!NT_STATUS_IS_OK(status
)) {
1557 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1561 ev
= event_context_init(talloc_tos());
1563 printf("event_context_init() returned NULL\n");
1567 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, data_blob_null
, &in_blob
);
1568 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1569 printf("gensec_update returned %s\n", nt_errstr(status
));
1573 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1578 SMB2_CAP_DFS
, /* in_capabilities */
1580 0, /* in_previous_session_id */
1581 &in_blob
); /* in_security_buffer */
1582 if (subreq
== NULL
) {
1583 printf("smb2cli_session_setup_send() returned NULL\n");
1587 ok
= tevent_req_poll(subreq
, ev
);
1589 printf("tevent_req_poll() returned false\n");
1593 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1595 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1596 printf("smb2cli_session_setup_recv returned %s\n",
1601 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, out_blob
, &in_blob
);
1602 if (!NT_STATUS_IS_OK(status
)) {
1603 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1607 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1608 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1609 if (!NT_STATUS_IS_OK(status
)) {
1610 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1614 status
= smb2cli_query_directory(
1615 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tid
,
1616 1, 0x3, 0, dir_persistent
, dir_volatile
,
1617 "session-reauth.txt", 0xffff,
1618 talloc_tos(), &dir_data
, &dir_data_length
);
1619 if (!NT_STATUS_IS_OK(status
)) {
1620 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1625 * query_info seems to be a path based operation on Windows...
1627 status
= smb2cli_query_info(cli
->conn
,
1631 SMB2_GETINFO_SECURITY
,
1632 0, /* in_file_info_class */
1633 1024, /* in_max_output_length */
1634 NULL
, /* in_input_buffer */
1635 SECINFO_OWNER
, /* in_additional_info */
1640 &out_output_buffer
);
1641 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1642 printf("smb2cli_query_info (security) returned %s\n", nt_errstr(status
));
1646 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1647 status
= smb2cli_query_info(cli
->conn
,
1653 1024, /* in_max_output_length */
1654 NULL
, /* in_input_buffer */
1655 0, /* in_additional_info */
1660 &out_output_buffer
);
1661 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1662 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1666 in_input_buffer
= data_blob_talloc(talloc_tos(), NULL
, 8);
1667 SBVAL(in_input_buffer
.data
, 0, 512);
1669 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1670 status
= smb2cli_set_info(cli
->conn
,
1677 0, /* in_additional_info */
1680 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1681 printf("smb2cli_set_info (position) returned %s\n", nt_errstr(status
));
1685 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1686 cli
->smb2
.tcon
, "session-reauth-invalid.txt",
1687 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1688 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1689 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1690 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1691 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1692 FILE_CREATE
, /* create_disposition, */
1693 FILE_DELETE_ON_CLOSE
, /* create_options, */
1694 NULL
, /* smb2_create_blobs *blobs */
1697 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1698 printf("smb2cli_create %s\n", nt_errstr(status
));
1702 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1704 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1705 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1706 SEC_STD_SYNCHRONIZE
|
1708 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
1709 0, /* file_attributes, */
1710 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1711 FILE_OPEN
, /* create_disposition, */
1712 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
1713 NULL
, /* smb2_create_blobs *blobs */
1716 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1717 printf("smb2cli_create returned %s\n", nt_errstr(status
));
1721 saved_tid
= cli
->smb2
.tid
;
1722 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
1723 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1724 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1727 cli
->smb2
.tid
= saved_tid
;
1729 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1734 SMB2_CAP_DFS
, /* in_capabilities */
1736 0, /* in_previous_session_id */
1737 &in_blob
); /* in_security_buffer */
1738 if (subreq
== NULL
) {
1739 printf("smb2cli_session_setup_send() returned NULL\n");
1743 ok
= tevent_req_poll(subreq
, ev
);
1745 printf("tevent_req_poll() returned false\n");
1749 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1750 &recv_iov
, &out_blob
);
1751 if (!NT_STATUS_IS_OK(status
)) {
1752 printf("smb2cli_session_setup_recv returned %s\n",
1757 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1758 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1759 if (!NT_STATUS_IS_OK(status
)) {
1760 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1764 status
= smb2cli_query_info(cli
->conn
,
1768 SMB2_GETINFO_SECURITY
,
1769 0, /* in_file_info_class */
1770 1024, /* in_max_output_length */
1771 NULL
, /* in_input_buffer */
1772 SECINFO_OWNER
, /* in_additional_info */
1777 &out_output_buffer
);
1778 if (!NT_STATUS_IS_OK(status
)) {
1779 printf("smb2cli_query_info (security) returned %s\n", nt_errstr(status
));
1783 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1784 status
= smb2cli_query_info(cli
->conn
,
1790 1024, /* in_max_output_length */
1791 NULL
, /* in_input_buffer */
1792 0, /* in_additional_info */
1797 &out_output_buffer
);
1798 if (!NT_STATUS_IS_OK(status
)) {
1799 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1803 in_input_buffer
= data_blob_talloc(talloc_tos(), NULL
, 8);
1804 SBVAL(in_input_buffer
.data
, 0, 512);
1806 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1807 status
= smb2cli_set_info(cli
->conn
,
1814 0, /* in_additional_info */
1817 if (!NT_STATUS_IS_OK(status
)) {
1818 printf("smb2cli_set_info (position) returned %s\n", nt_errstr(status
));
1822 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1823 status
= smb2cli_query_info(cli
->conn
,
1829 1024, /* in_max_output_length */
1830 NULL
, /* in_input_buffer */
1831 0, /* in_additional_info */
1836 &out_output_buffer
);
1837 if (!NT_STATUS_IS_OK(status
)) {
1838 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1842 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1843 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
1844 if (!NT_STATUS_IS_OK(status
)) {
1845 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1849 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1850 cli
->smb2
.tcon
, "session-reauth.txt",
1851 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1852 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1853 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1854 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1855 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1856 FILE_CREATE
, /* create_disposition, */
1857 FILE_DELETE_ON_CLOSE
, /* create_options, */
1858 NULL
, /* smb2_create_blobs *blobs */
1861 if (!NT_STATUS_IS_OK(status
)) {
1862 printf("smb2cli_create %s\n", nt_errstr(status
));
1866 status
= smb2cli_query_directory(
1867 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tid
,
1868 1, 0x3, 0, dir_persistent
, dir_volatile
,
1869 "session-reauth.txt", 0xffff,
1870 talloc_tos(), &dir_data
, &dir_data_length
);
1871 if (!NT_STATUS_IS_OK(status
)) {
1872 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1876 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1877 cli
->smb2
.tcon
, 0, dir_persistent
, dir_volatile
);
1878 if (!NT_STATUS_IS_OK(status
)) {
1879 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1883 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1884 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
1885 if (!NT_STATUS_IS_OK(status
)) {
1886 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1890 saved_tid
= cli
->smb2
.tid
;
1891 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
1892 if (!NT_STATUS_IS_OK(status
)) {
1893 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1896 cli
->smb2
.tid
= saved_tid
;