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 "libcli/security/security.h"
26 #include "libsmb/proto.h"
27 #include "auth/gensec/gensec.h"
28 #include "auth_generic.h"
29 #include "../librpc/ndr/libndr.h"
30 #include "libsmb/clirap.h"
32 extern fstring host
, workgroup
, share
, password
, username
, myname
;
33 extern struct cli_credentials
*torture_creds
;
35 bool run_smb2_basic(int dummy
)
37 struct cli_state
*cli
;
39 uint64_t fid_persistent
, fid_volatile
;
40 const char *hello
= "Hello, world\n";
44 uint32_t dir_data_length
;
45 uint32_t saved_tid
= 0;
46 struct smbXcli_tcon
*saved_tcon
= NULL
;
47 uint64_t saved_uid
= 0;
49 printf("Starting SMB2-BASIC\n");
51 if (!torture_init_connection(&cli
)) {
55 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
56 PROTOCOL_SMB2_02
, PROTOCOL_SMB2_02
);
57 if (!NT_STATUS_IS_OK(status
)) {
58 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
62 status
= cli_session_setup_creds(cli
, torture_creds
);
63 if (!NT_STATUS_IS_OK(status
)) {
64 printf("cli_session_setup returned %s\n", nt_errstr(status
));
68 status
= cli_tree_connect(cli
, share
, "?????", NULL
);
69 if (!NT_STATUS_IS_OK(status
)) {
70 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
74 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
75 cli
->smb2
.tcon
, "smb2-basic.txt",
76 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
77 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
78 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
79 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
80 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
81 FILE_CREATE
, /* create_disposition, */
82 FILE_DELETE_ON_CLOSE
, /* create_options, */
83 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
, NULL
);
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 */
150 if (!NT_STATUS_IS_OK(status
)) {
151 printf("smb2cli_create returned %s\n", nt_errstr(status
));
155 status
= smb2cli_query_directory(
156 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
157 1, 0, 0, fid_persistent
, fid_volatile
, "*", 0xffff,
158 talloc_tos(), &dir_data
, &dir_data_length
);
160 if (!NT_STATUS_IS_OK(status
)) {
161 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
165 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
166 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
167 if (!NT_STATUS_IS_OK(status
)) {
168 printf("smb2cli_close returned %s\n", nt_errstr(status
));
172 saved_tid
= smb2cli_tcon_current_id(cli
->smb2
.tcon
);
173 saved_tcon
= cli_state_save_tcon(cli
);
174 if (saved_tcon
== NULL
) {
177 cli
->smb2
.tcon
= smbXcli_tcon_create(cli
);
178 smb2cli_tcon_set_values(cli
->smb2
.tcon
,
183 0, /* capabilities */
184 0 /* maximal_access */);
185 status
= smb2cli_tdis(cli
->conn
,
189 if (!NT_STATUS_IS_OK(status
)) {
190 printf("smb2cli_tdis returned %s\n", nt_errstr(status
));
193 cli_state_restore_tcon(cli
, saved_tcon
);
195 status
= smb2cli_tdis(cli
->conn
,
199 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
200 printf("2nd smb2cli_tdis returned %s\n", nt_errstr(status
));
204 saved_uid
= smb2cli_session_current_id(cli
->smb2
.session
);
205 status
= smb2cli_logoff(cli
->conn
, cli
->timeout
, cli
->smb2
.session
);
206 if (!NT_STATUS_IS_OK(status
)) {
207 printf("smb2cli_logoff returned %s\n", nt_errstr(status
));
211 cli
->smb2
.session
= smbXcli_session_create(cli
, cli
->conn
);
212 if (cli
->smb2
.session
== NULL
) {
213 printf("smbXcli_session_create() returned NULL\n");
217 smb2cli_session_set_id_and_flags(cli
->smb2
.session
, saved_uid
, 0);
219 status
= smb2cli_logoff(cli
->conn
, cli
->timeout
, cli
->smb2
.session
);
220 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
221 printf("2nd smb2cli_logoff returned %s\n", nt_errstr(status
));
228 bool run_smb2_negprot(int dummy
)
230 struct cli_state
*cli
;
232 enum protocol_types protocol
;
233 const char *name
= NULL
;
235 printf("Starting SMB2-NEGPROT\n");
237 if (!torture_init_connection(&cli
)) {
241 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
242 PROTOCOL_CORE
, PROTOCOL_LATEST
);
243 if (!NT_STATUS_IS_OK(status
)) {
244 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
248 protocol
= smbXcli_conn_protocol(cli
->conn
);
249 name
= smb_protocol_types_string(protocol
);
251 if (protocol
>= PROTOCOL_SMB2_02
) {
252 printf("Server supports %s\n", name
);
254 printf("Server DOES NOT support SMB2, only %s\n", name
);
258 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
260 if (!NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_RESET
) &&
261 !NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_DISCONNECTED
) &&
262 !NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_ABORTED
)) {
263 printf("2nd smbXcli_negprot should disconnect - returned %s\n",
268 if (smbXcli_conn_is_connected(cli
->conn
)) {
269 printf("2nd smbXcli_negprot should disconnect "
270 "- still connected\n");
277 bool run_smb2_session_reconnect(int dummy
)
279 struct cli_state
*cli1
;
280 struct cli_state
*cli2
;
283 uint64_t fid_persistent
, fid_volatile
;
284 struct tevent_context
*ev
;
285 struct tevent_req
*subreq
;
286 DATA_BLOB in_blob
= data_blob_null
;
288 DATA_BLOB session_key
;
289 struct auth_generic_state
*auth_generic_state
;
290 struct iovec
*recv_iov
;
291 const char *hello
= "Hello, world\n";
295 printf("Starting SMB2-SESSION-RECONNECT\n");
297 if (!torture_init_connection(&cli1
)) {
301 status
= smbXcli_negprot(cli1
->conn
, cli1
->timeout
,
302 PROTOCOL_SMB2_02
, PROTOCOL_LATEST
);
303 if (!NT_STATUS_IS_OK(status
)) {
304 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
308 status
= cli_session_setup_creds(cli1
, torture_creds
);
309 if (!NT_STATUS_IS_OK(status
)) {
310 printf("cli_session_setup returned %s\n", nt_errstr(status
));
314 status
= cli_tree_connect(cli1
, share
, "?????", NULL
);
315 if (!NT_STATUS_IS_OK(status
)) {
316 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
320 status
= smb2cli_create(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
321 cli1
->smb2
.tcon
, "session-reconnect.txt",
322 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
323 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
324 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
325 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
326 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
327 FILE_CREATE
, /* create_disposition, */
328 FILE_DELETE_ON_CLOSE
, /* create_options, */
329 NULL
, /* smb2_create_blobs *blobs */
333 if (!NT_STATUS_IS_OK(status
)) {
334 printf("smb2cli_create on cli1 %s\n", nt_errstr(status
));
338 status
= smb2cli_write(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
339 cli1
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
340 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
341 if (!NT_STATUS_IS_OK(status
)) {
342 printf("smb2cli_write returned %s\n", nt_errstr(status
));
346 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
347 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
348 if (!NT_STATUS_IS_OK(status
)) {
349 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
353 status
= smb2cli_read(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
354 cli1
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
356 talloc_tos(), &result
, &nread
);
357 if (!NT_STATUS_IS_OK(status
)) {
358 printf("smb2cli_read returned %s\n", nt_errstr(status
));
362 if (nread
!= strlen(hello
)) {
363 printf("smb2cli_read returned %d bytes, expected %d\n",
364 (int)nread
, (int)strlen(hello
));
368 if (memcmp(hello
, result
, nread
) != 0) {
369 printf("smb2cli_read returned '%s', expected '%s'\n",
374 /* prepare second session */
376 if (!torture_init_connection(&cli2
)) {
380 status
= smbXcli_negprot(cli2
->conn
, cli2
->timeout
,
381 PROTOCOL_SMB2_02
, PROTOCOL_LATEST
);
382 if (!NT_STATUS_IS_OK(status
)) {
383 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
387 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
388 if (!NT_STATUS_IS_OK(status
)) {
389 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
393 gensec_want_feature(auth_generic_state
->gensec_security
,
394 GENSEC_FEATURE_SESSION_KEY
);
396 status
= auth_generic_set_creds(auth_generic_state
, torture_creds
);
397 if (!NT_STATUS_IS_OK(status
)) {
398 printf("auth_generic_set_creds returned %s\n", nt_errstr(status
));
402 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
403 if (!NT_STATUS_IS_OK(status
)) {
404 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
408 ev
= samba_tevent_context_init(talloc_tos());
410 printf("samba_tevent_context_init() returned NULL\n");
414 status
= gensec_update(auth_generic_state
->gensec_security
,
415 talloc_tos(), data_blob_null
, &in_blob
);
416 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
417 printf("gensec_update returned %s\n", nt_errstr(status
));
421 cli2
->smb2
.session
= smbXcli_session_create(cli2
, cli2
->conn
);
423 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
428 SMB2_CAP_DFS
, /* in_capabilities */
430 /* in_previous_session_id: */
431 smb2cli_session_current_id(cli1
->smb2
.session
),
432 &in_blob
); /* in_security_buffer */
433 if (subreq
== NULL
) {
434 printf("smb2cli_session_setup_send() returned NULL\n");
438 ok
= tevent_req_poll(subreq
, ev
);
440 printf("tevent_req_poll() returned false\n");
444 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
446 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
447 printf("smb2cli_session_setup_recv returned %s\n",
452 status
= gensec_update(auth_generic_state
->gensec_security
,
453 talloc_tos(), out_blob
, &in_blob
);
454 if (!NT_STATUS_IS_OK(status
)) {
455 printf("auth_generic_update returned %s\n", nt_errstr(status
));
459 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
464 SMB2_CAP_DFS
, /* in_capabilities */
466 /* in_previous_session_id: */
467 smb2cli_session_current_id(cli1
->smb2
.session
),
468 &in_blob
); /* in_security_buffer */
469 if (subreq
== NULL
) {
470 printf("smb2cli_session_setup_send() returned NULL\n");
474 ok
= tevent_req_poll(subreq
, ev
);
476 printf("tevent_req_poll() returned false\n");
480 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
481 &recv_iov
, &out_blob
);
482 if (!NT_STATUS_IS_OK(status
)) {
483 printf("smb2cli_session_setup_recv returned %s\n",
488 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
490 if (!NT_STATUS_IS_OK(status
)) {
491 printf("gensec_session_key returned %s\n",
496 /* check file operation on the old client */
498 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
499 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
500 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
501 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
505 status
= cli_tree_connect(cli1
, share
, "?????", NULL
);
506 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
507 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
512 * checking file operations without signing.
513 * on w2k8r2 at least, flush, read and write also work the same way,
514 * while create gives ACCESS_DENIED without signing
516 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
517 cli2
->smb2
.tcon
, fid_persistent
, fid_volatile
);
518 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
519 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
521 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
525 status
= smb2cli_write(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
526 cli2
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
527 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
528 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
529 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
531 printf("smb2cli_write returned %s\n", nt_errstr(status
));
535 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
536 cli2
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
538 talloc_tos(), &result
, &nread
);
539 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
540 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
542 printf("smb2cli_read returned %s\n", nt_errstr(status
));
546 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
547 cli2
->smb2
.tcon
, "session-reconnect.txt",
548 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
549 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
550 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
551 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
552 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
553 FILE_CREATE
, /* create_disposition, */
554 FILE_DELETE_ON_CLOSE
, /* create_options, */
555 NULL
, /* smb2_create_blobs *blobs */
559 if (!NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
) &&
560 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
561 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
565 /* now grab the session key and try with signing */
567 status
= smb2cli_session_set_session_key(cli2
->smb2
.session
,
570 if (!NT_STATUS_IS_OK(status
)) {
571 printf("smb2cli_session_set_session_key %s\n", nt_errstr(status
));
575 /* the tid seems to be irrelevant at this stage */
577 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
578 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
579 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
580 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
582 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
586 status
= smb2cli_write(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
587 cli1
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
588 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
589 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
590 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
592 printf("smb2cli_write returned %s\n", nt_errstr(status
));
596 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
597 cli1
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
599 talloc_tos(), &result
, &nread
);
600 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
601 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
603 printf("smb2cli_read returned %s\n", nt_errstr(status
));
607 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
608 cli1
->smb2
.tcon
, "session-reconnect.txt",
609 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
610 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
611 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
612 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
613 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
614 FILE_CREATE
, /* create_disposition, */
615 FILE_DELETE_ON_CLOSE
, /* create_options, */
616 NULL
, /* smb2_create_blobs *blobs */
620 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
) &&
621 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
623 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
627 /* now do a new tcon and test file calls again */
629 status
= cli_tree_connect(cli2
, share
, "?????", NULL
);
630 if (!NT_STATUS_IS_OK(status
)) {
631 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
635 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
636 cli2
->smb2
.tcon
, "session-reconnect.txt",
637 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
638 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
639 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
640 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
641 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
642 FILE_CREATE
, /* create_disposition, */
643 FILE_DELETE_ON_CLOSE
, /* create_options, */
644 NULL
, /* smb2_create_blobs *blobs */
648 if (!NT_STATUS_IS_OK(status
)) {
649 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
653 status
= smb2cli_write(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
654 cli2
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
655 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
656 if (!NT_STATUS_IS_OK(status
)) {
657 printf("smb2cli_write returned %s\n", nt_errstr(status
));
661 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
662 cli2
->smb2
.tcon
, fid_persistent
, fid_volatile
);
663 if (!NT_STATUS_IS_OK(status
)) {
664 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
668 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
669 cli2
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
671 talloc_tos(), &result
, &nread
);
672 if (!NT_STATUS_IS_OK(status
)) {
673 printf("smb2cli_read returned %s\n", nt_errstr(status
));
677 if (nread
!= strlen(hello
)) {
678 printf("smb2cli_read returned %d bytes, expected %d\n",
679 (int)nread
, (int)strlen(hello
));
683 if (memcmp(hello
, result
, nread
) != 0) {
684 printf("smb2cli_read returned '%s', expected '%s'\n",
692 bool run_smb2_tcon_dependence(int dummy
)
694 struct cli_state
*cli
;
696 uint64_t fid_persistent
, fid_volatile
;
697 const char *hello
= "Hello, world\n";
700 struct smbXcli_tcon
*tcon2
;
703 printf("Starting SMB2-TCON-DEPENDENCE\n");
705 if (!torture_init_connection(&cli
)) {
709 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
710 PROTOCOL_SMB2_02
, PROTOCOL_LATEST
);
711 if (!NT_STATUS_IS_OK(status
)) {
712 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
716 status
= cli_session_setup_creds(cli
, torture_creds
);
717 if (!NT_STATUS_IS_OK(status
)) {
718 printf("cli_session_setup returned %s\n", nt_errstr(status
));
722 status
= cli_tree_connect(cli
, share
, "?????", NULL
);
723 if (!NT_STATUS_IS_OK(status
)) {
724 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
728 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
729 cli
->smb2
.tcon
, "tcon_depedence.txt",
730 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
731 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
732 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
733 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
734 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
735 FILE_CREATE
, /* create_disposition, */
736 FILE_DELETE_ON_CLOSE
, /* create_options, */
737 NULL
, /* smb2_create_blobs *blobs */
741 if (!NT_STATUS_IS_OK(status
)) {
742 printf("smb2cli_create on cli %s\n", nt_errstr(status
));
746 status
= smb2cli_write(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
747 cli
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
748 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
749 if (!NT_STATUS_IS_OK(status
)) {
750 printf("smb2cli_write returned %s\n", nt_errstr(status
));
754 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
755 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
756 if (!NT_STATUS_IS_OK(status
)) {
757 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
761 status
= smb2cli_read(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
762 cli
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
764 talloc_tos(), &result
, &nread
);
765 if (!NT_STATUS_IS_OK(status
)) {
766 printf("smb2cli_read returned %s\n", nt_errstr(status
));
770 if (nread
!= strlen(hello
)) {
771 printf("smb2cli_read returned %d bytes, expected %d\n",
772 (int)nread
, (int)strlen(hello
));
776 if (memcmp(hello
, result
, nread
) != 0) {
777 printf("smb2cli_read returned '%s', expected '%s'\n",
782 /* check behaviour with wrong tid... */
784 tcon2
= smbXcli_tcon_create(cli
);
785 tcon2_id
= smb2cli_tcon_current_id(cli
->smb2
.tcon
);
787 smb2cli_tcon_set_values(tcon2
,
792 0, /* capabilities */
793 0 /* maximal_access */);
795 status
= smb2cli_read(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
796 tcon2
, 0x10000, 0, fid_persistent
,
798 talloc_tos(), &result
, &nread
);
799 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
800 printf("smb2cli_read returned %s\n", nt_errstr(status
));
809 bool run_smb2_multi_channel(int dummy
)
811 struct cli_state
*cli1
;
812 struct cli_state
*cli2
;
813 struct cli_state
*cli3
;
816 uint64_t fid_persistent
, fid_volatile
;
817 struct tevent_context
*ev
;
818 struct tevent_req
*subreq
;
819 DATA_BLOB in_blob
= data_blob_null
;
821 DATA_BLOB channel_session_key
;
822 struct auth_generic_state
*auth_generic_state
;
823 struct iovec
*recv_iov
;
824 const char *hello
= "Hello, world\n";
827 struct GUID saved_guid
= cli_state_client_guid
;
829 printf("Starting SMB2-MULTI-CHANNEL\n");
831 cli_state_client_guid
= GUID_random();
833 if (!torture_init_connection(&cli1
)) {
837 if (!torture_init_connection(&cli2
)) {
841 if (!torture_init_connection(&cli3
)) {
845 cli_state_client_guid
= saved_guid
;
847 status
= smbXcli_negprot(cli1
->conn
, cli1
->timeout
,
848 PROTOCOL_SMB2_22
, PROTOCOL_LATEST
);
849 if (!NT_STATUS_IS_OK(status
)) {
850 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
854 status
= smbXcli_negprot(cli2
->conn
, cli2
->timeout
,
855 PROTOCOL_SMB2_22
, PROTOCOL_LATEST
);
856 if (!NT_STATUS_IS_OK(status
)) {
857 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
861 status
= smbXcli_negprot(cli3
->conn
, cli3
->timeout
,
862 PROTOCOL_SMB2_22
, PROTOCOL_LATEST
);
863 if (!NT_STATUS_IS_OK(status
)) {
864 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
868 status
= cli_session_setup_creds(cli1
, torture_creds
);
869 if (!NT_STATUS_IS_OK(status
)) {
870 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status
));
874 status
= cli_tree_connect(cli1
, share
, "?????", NULL
);
875 if (!NT_STATUS_IS_OK(status
)) {
876 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
880 status
= smb2cli_session_create_channel(cli2
,
883 &cli2
->smb2
.session
);
884 if (!NT_STATUS_IS_OK(status
)) {
885 printf("smb2cli_session_create_channel returned %s\n",
890 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
891 if (!NT_STATUS_IS_OK(status
)) {
892 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
896 gensec_want_feature(auth_generic_state
->gensec_security
,
897 GENSEC_FEATURE_SESSION_KEY
);
899 status
= auth_generic_set_creds(auth_generic_state
, torture_creds
);
900 if (!NT_STATUS_IS_OK(status
)) {
901 printf("auth_generic_set_creds returned %s\n", nt_errstr(status
));
905 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
906 if (!NT_STATUS_IS_OK(status
)) {
907 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
911 ev
= samba_tevent_context_init(talloc_tos());
913 printf("samba_tevent_context_init() returned NULL\n");
917 status
= gensec_update(auth_generic_state
->gensec_security
,
918 talloc_tos(), data_blob_null
, &in_blob
);
919 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
920 printf("gensec_update returned %s\n", nt_errstr(status
));
924 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
929 SMB2_CAP_DFS
, /* in_capabilities */
931 0, /* in_previous_session_id */
932 &in_blob
); /* in_security_buffer */
933 if (subreq
== NULL
) {
934 printf("smb2cli_session_setup_send() returned NULL\n");
938 ok
= tevent_req_poll(subreq
, ev
);
940 printf("tevent_req_poll() returned false\n");
944 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
946 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
947 printf("smb2cli_session_setup_recv returned %s\n",
952 status
= gensec_update(auth_generic_state
->gensec_security
,
953 talloc_tos(), out_blob
, &in_blob
);
954 if (!NT_STATUS_IS_OK(status
)) {
955 printf("auth_generic_update returned %s\n", nt_errstr(status
));
959 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
964 SMB2_CAP_DFS
, /* in_capabilities */
966 0, /* in_previous_session_id */
967 &in_blob
); /* in_security_buffer */
968 if (subreq
== NULL
) {
969 printf("smb2cli_session_setup_send() returned NULL\n");
973 ok
= tevent_req_poll(subreq
, ev
);
975 printf("tevent_req_poll() returned false\n");
979 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
980 &recv_iov
, &out_blob
);
981 if (!NT_STATUS_IS_OK(status
)) {
982 printf("smb2cli_session_setup_recv returned %s\n",
987 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
988 &channel_session_key
);
989 if (!NT_STATUS_IS_OK(status
)) {
990 printf("gensec_session_key returned %s\n",
995 status
= smb2cli_session_set_channel_key(cli2
->smb2
.session
,
998 if (!NT_STATUS_IS_OK(status
)) {
999 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status
));
1003 status
= smb2cli_session_create_channel(cli3
,
1006 &cli3
->smb2
.session
);
1007 if (!NT_STATUS_IS_OK(status
)) {
1008 printf("smb2cli_session_create_channel returned %s\n",
1013 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1014 if (!NT_STATUS_IS_OK(status
)) {
1015 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1019 gensec_want_feature(auth_generic_state
->gensec_security
,
1020 GENSEC_FEATURE_SESSION_KEY
);
1022 status
= auth_generic_set_creds(auth_generic_state
, torture_creds
);
1023 if (!NT_STATUS_IS_OK(status
)) {
1024 printf("auth_generic_set_creds returned %s\n", nt_errstr(status
));
1028 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1029 if (!NT_STATUS_IS_OK(status
)) {
1030 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1034 status
= gensec_update(auth_generic_state
->gensec_security
,
1035 talloc_tos(), data_blob_null
, &in_blob
);
1036 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1037 printf("gensec_update returned %s\n", nt_errstr(status
));
1041 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1045 0x01, /* in_flags */
1046 SMB2_CAP_DFS
, /* in_capabilities */
1048 0, /* in_previous_session_id */
1049 &in_blob
); /* in_security_buffer */
1050 if (subreq
== NULL
) {
1051 printf("smb2cli_session_setup_send() returned NULL\n");
1055 ok
= tevent_req_poll(subreq
, ev
);
1057 printf("tevent_req_poll() returned false\n");
1061 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1063 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1064 printf("smb2cli_session_setup_recv returned %s\n",
1069 status
= gensec_update(auth_generic_state
->gensec_security
,
1070 talloc_tos(), out_blob
, &in_blob
);
1071 if (!NT_STATUS_IS_OK(status
)) {
1072 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1076 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1080 0x01, /* in_flags */
1081 SMB2_CAP_DFS
, /* in_capabilities */
1083 0, /* in_previous_session_id */
1084 &in_blob
); /* in_security_buffer */
1085 if (subreq
== NULL
) {
1086 printf("smb2cli_session_setup_send() returned NULL\n");
1090 ok
= tevent_req_poll(subreq
, ev
);
1092 printf("tevent_req_poll() returned false\n");
1096 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1097 &recv_iov
, &out_blob
);
1098 if (!NT_STATUS_IS_OK(status
)) {
1099 printf("smb2cli_session_setup_recv returned %s\n",
1104 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
1105 &channel_session_key
);
1106 if (!NT_STATUS_IS_OK(status
)) {
1107 printf("gensec_session_key returned %s\n",
1112 status
= smb2cli_session_set_channel_key(cli3
->smb2
.session
,
1113 channel_session_key
,
1115 if (!NT_STATUS_IS_OK(status
)) {
1116 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status
));
1120 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1121 cli1
->smb2
.tcon
, "multi-channel.txt",
1122 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1123 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1124 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1125 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1126 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1127 FILE_CREATE
, /* create_disposition, */
1128 FILE_DELETE_ON_CLOSE
, /* create_options, */
1129 NULL
, /* smb2_create_blobs *blobs */
1133 if (!NT_STATUS_IS_OK(status
)) {
1134 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
1138 status
= smb2cli_write(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1139 cli1
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
1140 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
1141 if (!NT_STATUS_IS_OK(status
)) {
1142 printf("smb2cli_write returned %s\n", nt_errstr(status
));
1146 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1147 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1148 if (!NT_STATUS_IS_OK(status
)) {
1149 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1153 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1154 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1155 if (!NT_STATUS_IS_OK(status
)) {
1156 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1160 status
= smb2cli_flush(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1161 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1162 if (!NT_STATUS_IS_OK(status
)) {
1163 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1167 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1168 cli1
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
1170 talloc_tos(), &result
, &nread
);
1171 if (!NT_STATUS_IS_OK(status
)) {
1172 printf("smb2cli_read returned %s\n", nt_errstr(status
));
1176 if (nread
!= strlen(hello
)) {
1177 printf("smb2cli_read returned %d bytes, expected %d\n",
1178 (int)nread
, (int)strlen(hello
));
1182 if (memcmp(hello
, result
, nread
) != 0) {
1183 printf("smb2cli_read returned '%s', expected '%s'\n",
1188 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1189 if (!NT_STATUS_IS_OK(status
)) {
1190 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1194 gensec_want_feature(auth_generic_state
->gensec_security
,
1195 GENSEC_FEATURE_SESSION_KEY
);
1197 status
= auth_generic_set_creds(auth_generic_state
, torture_creds
);
1198 if (!NT_STATUS_IS_OK(status
)) {
1199 printf("auth_generic_set_creds returned %s\n", nt_errstr(status
));
1203 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1204 if (!NT_STATUS_IS_OK(status
)) {
1205 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1209 status
= gensec_update(auth_generic_state
->gensec_security
,
1210 talloc_tos(), data_blob_null
, &in_blob
);
1211 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1212 printf("gensec_update returned %s\n", nt_errstr(status
));
1216 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1221 SMB2_CAP_DFS
, /* in_capabilities */
1223 0, /* in_previous_session_id */
1224 &in_blob
); /* in_security_buffer */
1225 if (subreq
== NULL
) {
1226 printf("smb2cli_session_setup_send() returned NULL\n");
1230 ok
= tevent_req_poll(subreq
, ev
);
1232 printf("tevent_req_poll() returned false\n");
1236 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1238 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1239 printf("smb2cli_session_setup_recv returned %s\n",
1244 status
= gensec_update(auth_generic_state
->gensec_security
,
1245 talloc_tos(), out_blob
, &in_blob
);
1246 if (!NT_STATUS_IS_OK(status
)) {
1247 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1251 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1252 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1253 if (!NT_STATUS_IS_OK(status
)) {
1254 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1258 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1259 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1260 if (!NT_STATUS_IS_OK(status
)) {
1261 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1265 status
= smb2cli_flush(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1266 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1267 if (!NT_STATUS_IS_OK(status
)) {
1268 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1272 status
= smb2cli_create(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1273 cli1
->smb2
.tcon
, "multi-channel-invalid.txt",
1274 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1275 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1276 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1277 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1278 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1279 FILE_CREATE
, /* create_disposition, */
1280 FILE_DELETE_ON_CLOSE
, /* create_options, */
1281 NULL
, /* smb2_create_blobs *blobs */
1285 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1286 printf("smb2cli_create %s\n", nt_errstr(status
));
1290 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1291 cli1
->smb2
.tcon
, "multi-channel-invalid.txt",
1292 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1293 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1294 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1295 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1296 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1297 FILE_CREATE
, /* create_disposition, */
1298 FILE_DELETE_ON_CLOSE
, /* create_options, */
1299 NULL
, /* smb2_create_blobs *blobs */
1303 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1304 printf("smb2cli_create %s\n", nt_errstr(status
));
1308 status
= smb2cli_create(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1309 cli1
->smb2
.tcon
, "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 */
1321 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1322 printf("smb2cli_create %s\n", nt_errstr(status
));
1326 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1331 SMB2_CAP_DFS
, /* in_capabilities */
1333 0, /* in_previous_session_id */
1334 &in_blob
); /* in_security_buffer */
1335 if (subreq
== NULL
) {
1336 printf("smb2cli_session_setup_send() returned NULL\n");
1340 ok
= tevent_req_poll(subreq
, ev
);
1342 printf("tevent_req_poll() returned false\n");
1346 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1347 &recv_iov
, &out_blob
);
1348 if (!NT_STATUS_IS_OK(status
)) {
1349 printf("smb2cli_session_setup_recv returned %s\n",
1354 status
= smb2cli_close(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1355 cli1
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
1356 if (!NT_STATUS_IS_OK(status
)) {
1357 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1361 status
= smb2cli_flush(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1362 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1363 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1364 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1368 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1369 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1370 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1371 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1375 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1376 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1377 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1378 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1385 bool run_smb2_session_reauth(int dummy
)
1387 struct cli_state
*cli
;
1390 uint64_t fid_persistent
, fid_volatile
;
1391 uint64_t dir_persistent
, dir_volatile
;
1393 uint32_t dir_data_length
;
1394 struct tevent_context
*ev
;
1395 struct tevent_req
*subreq
;
1396 DATA_BLOB in_blob
= data_blob_null
;
1398 DATA_BLOB in_input_buffer
;
1399 DATA_BLOB out_output_buffer
;
1400 uint8_t in_file_info_class
;
1401 struct auth_generic_state
*auth_generic_state
;
1402 struct iovec
*recv_iov
;
1404 struct smbXcli_tcon
*saved_tcon
;
1406 printf("Starting SMB2-SESSION_REAUTH\n");
1408 if (!torture_init_connection(&cli
)) {
1413 * PROTOCOL_SMB2_22 has a bug in win8pre0
1414 * it behaves like PROTOCOL_SMB2_02
1415 * and returns NT_STATUS_REQUEST_NOT_ACCEPTED,
1416 * while it allows it on PROTOCOL_SMB2_02.
1418 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
1419 PROTOCOL_SMB2_10
, PROTOCOL_SMB2_10
);
1420 if (!NT_STATUS_IS_OK(status
)) {
1421 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
1425 status
= cli_session_setup_creds(cli
, torture_creds
);
1426 if (!NT_STATUS_IS_OK(status
)) {
1427 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status
));
1431 status
= cli_tree_connect(cli
, share
, "?????", NULL
);
1432 if (!NT_STATUS_IS_OK(status
)) {
1433 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1437 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1438 cli
->smb2
.tcon
, "session-reauth.txt",
1439 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1440 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1441 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1442 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1443 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1444 FILE_CREATE
, /* create_disposition, */
1445 FILE_DELETE_ON_CLOSE
, /* create_options, */
1446 NULL
, /* smb2_create_blobs *blobs */
1450 if (!NT_STATUS_IS_OK(status
)) {
1451 printf("smb2cli_create %s\n", nt_errstr(status
));
1455 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1457 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1458 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1459 SEC_STD_SYNCHRONIZE
|
1461 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
1462 0, /* file_attributes, */
1463 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1464 FILE_OPEN
, /* create_disposition, */
1465 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
1466 NULL
, /* smb2_create_blobs *blobs */
1470 if (!NT_STATUS_IS_OK(status
)) {
1471 printf("smb2cli_create returned %s\n", nt_errstr(status
));
1475 status
= smb2cli_query_directory(
1476 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
1477 1, 0x3, 0, dir_persistent
, dir_volatile
,
1478 "session-reauth.txt", 0xffff,
1479 talloc_tos(), &dir_data
, &dir_data_length
);
1480 if (!NT_STATUS_IS_OK(status
)) {
1481 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1485 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1486 if (!NT_STATUS_IS_OK(status
)) {
1487 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1491 gensec_want_feature(auth_generic_state
->gensec_security
,
1492 GENSEC_FEATURE_SESSION_KEY
);
1494 status
= auth_generic_set_creds(auth_generic_state
, torture_creds
);
1495 if (!NT_STATUS_IS_OK(status
)) {
1496 printf("auth_generic_set_creds returned %s\n", nt_errstr(status
));
1500 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1501 if (!NT_STATUS_IS_OK(status
)) {
1502 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1506 ev
= samba_tevent_context_init(talloc_tos());
1508 printf("samba_tevent_context_init() returned NULL\n");
1512 status
= gensec_update(auth_generic_state
->gensec_security
,
1513 talloc_tos(), data_blob_null
, &in_blob
);
1514 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1515 printf("gensec_update returned %s\n", nt_errstr(status
));
1519 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1524 SMB2_CAP_DFS
, /* in_capabilities */
1526 0, /* in_previous_session_id */
1527 &in_blob
); /* in_security_buffer */
1528 if (subreq
== NULL
) {
1529 printf("smb2cli_session_setup_send() returned NULL\n");
1533 ok
= tevent_req_poll(subreq
, ev
);
1535 printf("tevent_req_poll() returned false\n");
1539 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1541 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1542 printf("smb2cli_session_setup_recv returned %s\n",
1547 status
= gensec_update(auth_generic_state
->gensec_security
,
1548 talloc_tos(), out_blob
, &in_blob
);
1549 if (!NT_STATUS_IS_OK(status
)) {
1550 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1554 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1555 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1556 if (!NT_STATUS_IS_OK(status
)) {
1557 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1561 status
= smb2cli_query_directory(
1562 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
1563 1, 0x3, 0, dir_persistent
, dir_volatile
,
1564 "session-reauth.txt", 0xffff,
1565 talloc_tos(), &dir_data
, &dir_data_length
);
1566 if (!NT_STATUS_IS_OK(status
)) {
1567 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1572 * query_info seems to be a path based operation on Windows...
1574 status
= smb2cli_query_info(cli
->conn
,
1578 SMB2_GETINFO_SECURITY
,
1579 0, /* in_file_info_class */
1580 1024, /* in_max_output_length */
1581 NULL
, /* in_input_buffer */
1582 SECINFO_OWNER
, /* in_additional_info */
1587 &out_output_buffer
);
1588 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1589 printf("smb2cli_query_info (security) returned %s\n", nt_errstr(status
));
1593 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1594 status
= smb2cli_query_info(cli
->conn
,
1600 1024, /* in_max_output_length */
1601 NULL
, /* in_input_buffer */
1602 0, /* in_additional_info */
1607 &out_output_buffer
);
1608 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1609 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1613 in_input_buffer
= data_blob_talloc(talloc_tos(), NULL
, 8);
1614 SBVAL(in_input_buffer
.data
, 0, 512);
1616 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1617 status
= smb2cli_set_info(cli
->conn
,
1624 0, /* in_additional_info */
1627 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1628 printf("smb2cli_set_info (position) returned %s\n", nt_errstr(status
));
1632 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1633 cli
->smb2
.tcon
, "session-reauth-invalid.txt",
1634 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1635 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1636 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1637 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1638 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1639 FILE_CREATE
, /* create_disposition, */
1640 FILE_DELETE_ON_CLOSE
, /* create_options, */
1641 NULL
, /* smb2_create_blobs *blobs */
1645 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1646 printf("smb2cli_create %s\n", nt_errstr(status
));
1650 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1652 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1653 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1654 SEC_STD_SYNCHRONIZE
|
1656 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
1657 0, /* file_attributes, */
1658 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1659 FILE_OPEN
, /* create_disposition, */
1660 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
1661 NULL
, /* smb2_create_blobs *blobs */
1665 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1666 printf("smb2cli_create returned %s\n", nt_errstr(status
));
1670 saved_tid
= smb2cli_tcon_current_id(cli
->smb2
.tcon
);
1671 saved_tcon
= cli
->smb2
.tcon
;
1672 cli
->smb2
.tcon
= smbXcli_tcon_create(cli
);
1673 smb2cli_tcon_set_values(cli
->smb2
.tcon
,
1678 0, /* capabilities */
1679 0 /* maximal_access */);
1680 status
= cli_tree_connect(cli
, share
, "?????", NULL
);
1681 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1682 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1685 talloc_free(cli
->smb2
.tcon
);
1686 cli
->smb2
.tcon
= saved_tcon
;
1688 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1693 SMB2_CAP_DFS
, /* in_capabilities */
1695 0, /* in_previous_session_id */
1696 &in_blob
); /* in_security_buffer */
1697 if (subreq
== NULL
) {
1698 printf("smb2cli_session_setup_send() returned NULL\n");
1702 ok
= tevent_req_poll(subreq
, ev
);
1704 printf("tevent_req_poll() returned false\n");
1708 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1709 &recv_iov
, &out_blob
);
1710 if (!NT_STATUS_IS_OK(status
)) {
1711 printf("smb2cli_session_setup_recv returned %s\n",
1716 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1717 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1718 if (!NT_STATUS_IS_OK(status
)) {
1719 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1723 status
= smb2cli_query_info(cli
->conn
,
1727 SMB2_GETINFO_SECURITY
,
1728 0, /* in_file_info_class */
1729 1024, /* in_max_output_length */
1730 NULL
, /* in_input_buffer */
1731 SECINFO_OWNER
, /* in_additional_info */
1736 &out_output_buffer
);
1737 if (!NT_STATUS_IS_OK(status
)) {
1738 printf("smb2cli_query_info (security) returned %s\n", nt_errstr(status
));
1742 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1743 status
= smb2cli_query_info(cli
->conn
,
1749 1024, /* in_max_output_length */
1750 NULL
, /* in_input_buffer */
1751 0, /* in_additional_info */
1756 &out_output_buffer
);
1757 if (!NT_STATUS_IS_OK(status
)) {
1758 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1762 in_input_buffer
= data_blob_talloc(talloc_tos(), NULL
, 8);
1763 SBVAL(in_input_buffer
.data
, 0, 512);
1765 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1766 status
= smb2cli_set_info(cli
->conn
,
1773 0, /* in_additional_info */
1776 if (!NT_STATUS_IS_OK(status
)) {
1777 printf("smb2cli_set_info (position) returned %s\n", nt_errstr(status
));
1781 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1782 status
= smb2cli_query_info(cli
->conn
,
1788 1024, /* in_max_output_length */
1789 NULL
, /* in_input_buffer */
1790 0, /* in_additional_info */
1795 &out_output_buffer
);
1796 if (!NT_STATUS_IS_OK(status
)) {
1797 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1801 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1802 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
1803 if (!NT_STATUS_IS_OK(status
)) {
1804 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1808 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1809 cli
->smb2
.tcon
, "session-reauth.txt",
1810 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1811 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1812 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1813 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1814 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1815 FILE_CREATE
, /* create_disposition, */
1816 FILE_DELETE_ON_CLOSE
, /* create_options, */
1817 NULL
, /* smb2_create_blobs *blobs */
1821 if (!NT_STATUS_IS_OK(status
)) {
1822 printf("smb2cli_create %s\n", nt_errstr(status
));
1826 status
= smb2cli_query_directory(
1827 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
1828 1, 0x3, 0, dir_persistent
, dir_volatile
,
1829 "session-reauth.txt", 0xffff,
1830 talloc_tos(), &dir_data
, &dir_data_length
);
1831 if (!NT_STATUS_IS_OK(status
)) {
1832 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1836 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1837 cli
->smb2
.tcon
, 0, dir_persistent
, dir_volatile
);
1838 if (!NT_STATUS_IS_OK(status
)) {
1839 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1843 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1844 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
1845 if (!NT_STATUS_IS_OK(status
)) {
1846 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1850 saved_tid
= smb2cli_tcon_current_id(cli
->smb2
.tcon
);
1851 saved_tcon
= cli
->smb2
.tcon
;
1852 cli
->smb2
.tcon
= smbXcli_tcon_create(cli
);
1853 smb2cli_tcon_set_values(cli
->smb2
.tcon
,
1858 0, /* capabilities */
1859 0 /* maximal_access */);
1860 status
= cli_tree_connect(cli
, share
, "?????", NULL
);
1861 if (!NT_STATUS_IS_OK(status
)) {
1862 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1865 talloc_free(cli
->smb2
.tcon
);
1866 cli
->smb2
.tcon
= saved_tcon
;
1871 static NTSTATUS
check_size(struct cli_state
*cli
,
1876 off_t size_read
= 0;
1878 NTSTATUS status
= cli_qfileinfo_basic(cli
,
1888 if (!NT_STATUS_IS_OK(status
)) {
1889 printf("cli_smb2_qfileinfo_basic of %s failed (%s)\n",
1895 if (size
!= size_read
) {
1896 printf("size (%u) != size_read(%u) for %s\n",
1898 (unsigned int)size_read
,
1900 /* Use EOF to mean bad size. */
1901 return NT_STATUS_END_OF_FILE
;
1903 return NT_STATUS_OK
;
1906 /* Ensure cli_ftruncate() works for SMB2. */
1908 bool run_smb2_ftruncate(int dummy
)
1910 struct cli_state
*cli
= NULL
;
1911 const char *fname
= "smb2_ftruncate.txt";
1912 uint16_t fnum
= (uint16_t)-1;
1913 bool correct
= false;
1914 size_t buflen
= 1024*1024;
1915 uint8_t *buf
= NULL
;
1919 printf("Starting SMB2-FTRUNCATE\n");
1921 if (!torture_init_connection(&cli
)) {
1925 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
1926 PROTOCOL_SMB2_02
, PROTOCOL_SMB2_02
);
1927 if (!NT_STATUS_IS_OK(status
)) {
1928 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
1932 status
= cli_session_setup_creds(cli
, torture_creds
);
1933 if (!NT_STATUS_IS_OK(status
)) {
1934 printf("cli_session_setup returned %s\n", nt_errstr(status
));
1938 status
= cli_tree_connect(cli
, share
, "?????", NULL
);
1939 if (!NT_STATUS_IS_OK(status
)) {
1940 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1944 cli_setatr(cli
, fname
, 0, 0);
1945 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
1947 status
= cli_ntcreate(cli
,
1951 FILE_ATTRIBUTE_NORMAL
,
1959 if (!NT_STATUS_IS_OK(status
)) {
1960 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
1964 buf
= talloc_zero_array(cli
, uint8_t, buflen
);
1970 status
= cli_writeall(cli
,
1978 if (!NT_STATUS_IS_OK(status
)) {
1979 printf("write of %u to %s failed (%s)\n",
1980 (unsigned int)buflen
,
1986 status
= check_size(cli
, fnum
, fname
, buflen
);
1987 if (!NT_STATUS_IS_OK(status
)) {
1991 /* Now ftruncate. */
1992 for ( i
= 0; i
< 10; i
++) {
1993 status
= cli_ftruncate(cli
, fnum
, i
*1024);
1994 if (!NT_STATUS_IS_OK(status
)) {
1995 printf("cli_ftruncate %u of %s failed (%s)\n",
1996 (unsigned int)i
*1024,
2001 status
= check_size(cli
, fnum
, fname
, i
*1024);
2002 if (!NT_STATUS_IS_OK(status
)) {
2015 if (fnum
!= (uint16_t)-1) {
2016 cli_close(cli
, fnum
);
2018 cli_setatr(cli
, fname
, 0, 0);
2019 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2021 if (!torture_close_connection(cli
)) {