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"
30 #include "../librpc/ndr/libndr.h"
32 extern fstring host
, workgroup
, share
, password
, username
, myname
;
34 bool run_smb2_basic(int dummy
)
36 struct cli_state
*cli
;
38 uint64_t fid_persistent
, fid_volatile
;
39 const char *hello
= "Hello, world\n";
43 uint32_t dir_data_length
;
44 uint32_t saved_tid
= 0;
45 struct smbXcli_tcon
*saved_tcon
= NULL
;
46 uint64_t saved_uid
= 0;
48 printf("Starting SMB2-BASIC\n");
50 if (!torture_init_connection(&cli
)) {
54 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
55 PROTOCOL_SMB2_02
, PROTOCOL_SMB2_02
);
56 if (!NT_STATUS_IS_OK(status
)) {
57 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
61 status
= cli_session_setup(cli
, username
,
62 password
, strlen(password
),
63 password
, strlen(password
),
65 if (!NT_STATUS_IS_OK(status
)) {
66 printf("cli_session_setup returned %s\n", nt_errstr(status
));
70 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
71 if (!NT_STATUS_IS_OK(status
)) {
72 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
76 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
77 cli
->smb2
.tcon
, "smb2-basic.txt",
78 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
79 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
80 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
81 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
82 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
83 FILE_CREATE
, /* create_disposition, */
84 FILE_DELETE_ON_CLOSE
, /* create_options, */
85 NULL
, /* smb2_create_blobs *blobs */
89 if (!NT_STATUS_IS_OK(status
)) {
90 printf("smb2cli_create returned %s\n", nt_errstr(status
));
94 status
= smb2cli_write(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
95 cli
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
96 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
97 if (!NT_STATUS_IS_OK(status
)) {
98 printf("smb2cli_write returned %s\n", nt_errstr(status
));
102 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
103 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
104 if (!NT_STATUS_IS_OK(status
)) {
105 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
109 status
= smb2cli_read(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
110 cli
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
112 talloc_tos(), &result
, &nread
);
113 if (!NT_STATUS_IS_OK(status
)) {
114 printf("smb2cli_read returned %s\n", nt_errstr(status
));
118 if (nread
!= strlen(hello
)) {
119 printf("smb2cli_read returned %d bytes, expected %d\n",
120 (int)nread
, (int)strlen(hello
));
124 if (memcmp(hello
, result
, nread
) != 0) {
125 printf("smb2cli_read returned '%s', expected '%s'\n",
130 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
131 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
132 if (!NT_STATUS_IS_OK(status
)) {
133 printf("smb2cli_close returned %s\n", nt_errstr(status
));
137 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
139 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
140 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
143 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
144 0, /* file_attributes, */
145 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
146 FILE_OPEN
, /* create_disposition, */
147 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
148 NULL
, /* smb2_create_blobs *blobs */
152 if (!NT_STATUS_IS_OK(status
)) {
153 printf("smb2cli_create returned %s\n", nt_errstr(status
));
157 status
= smb2cli_query_directory(
158 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
159 1, 0, 0, fid_persistent
, fid_volatile
, "*", 0xffff,
160 talloc_tos(), &dir_data
, &dir_data_length
);
162 if (!NT_STATUS_IS_OK(status
)) {
163 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
167 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
168 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
169 if (!NT_STATUS_IS_OK(status
)) {
170 printf("smb2cli_close returned %s\n", nt_errstr(status
));
174 saved_tid
= smb2cli_tcon_current_id(cli
->smb2
.tcon
);
175 saved_tcon
= cli
->smb2
.tcon
;
176 cli
->smb2
.tcon
= smbXcli_tcon_create(cli
);
177 smb2cli_tcon_set_values(cli
->smb2
.tcon
,
182 0, /* capabilities */
183 0 /* maximal_access */);
184 status
= smb2cli_tdis(cli
);
185 if (!NT_STATUS_IS_OK(status
)) {
186 printf("smb2cli_tdis returned %s\n", nt_errstr(status
));
189 talloc_free(cli
->smb2
.tcon
);
190 cli
->smb2
.tcon
= saved_tcon
;
192 status
= smb2cli_tdis(cli
);
193 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
194 printf("2nd smb2cli_tdis returned %s\n", nt_errstr(status
));
198 saved_uid
= smb2cli_session_current_id(cli
->smb2
.session
);
199 status
= smb2cli_logoff(cli
->conn
, cli
->timeout
, cli
->smb2
.session
);
200 if (!NT_STATUS_IS_OK(status
)) {
201 printf("smb2cli_logoff returned %s\n", nt_errstr(status
));
205 cli
->smb2
.session
= smbXcli_session_create(cli
, cli
->conn
);
206 if (cli
->smb2
.session
== NULL
) {
207 printf("smbXcli_session_create() returned NULL\n");
211 smb2cli_session_set_id_and_flags(cli
->smb2
.session
, saved_uid
, 0);
213 status
= smb2cli_logoff(cli
->conn
, cli
->timeout
, cli
->smb2
.session
);
214 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
215 printf("2nd smb2cli_logoff returned %s\n", nt_errstr(status
));
222 bool run_smb2_negprot(int dummy
)
224 struct cli_state
*cli
;
226 enum protocol_types protocol
;
227 const char *name
= NULL
;
229 printf("Starting SMB2-NEGPROT\n");
231 if (!torture_init_connection(&cli
)) {
235 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
236 PROTOCOL_CORE
, PROTOCOL_LATEST
);
237 if (!NT_STATUS_IS_OK(status
)) {
238 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
242 protocol
= smbXcli_conn_protocol(cli
->conn
);
245 case PROTOCOL_SMB2_02
:
248 case PROTOCOL_SMB2_10
:
251 case PROTOCOL_SMB2_22
:
254 case PROTOCOL_SMB2_24
:
257 case PROTOCOL_SMB3_00
:
260 case PROTOCOL_SMB3_02
:
268 printf("Server supports %s\n", name
);
270 printf("Server DOES NOT support SMB2\n");
274 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
276 if (!NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_RESET
) &&
277 !NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_DISCONNECTED
) &&
278 !NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_ABORTED
)) {
279 printf("2nd smbXcli_negprot should disconnect - returned %s\n",
284 if (smbXcli_conn_is_connected(cli
->conn
)) {
285 printf("2nd smbXcli_negprot should disconnect "
286 "- still connected\n");
293 bool run_smb2_session_reconnect(int dummy
)
295 struct cli_state
*cli1
;
296 struct cli_state
*cli2
;
299 uint64_t fid_persistent
, fid_volatile
;
300 struct tevent_context
*ev
;
301 struct tevent_req
*subreq
;
302 DATA_BLOB in_blob
= data_blob_null
;
304 DATA_BLOB session_key
;
305 struct auth_generic_state
*auth_generic_state
;
306 struct iovec
*recv_iov
;
307 const char *hello
= "Hello, world\n";
311 printf("Starting SMB2-SESSION-RECONNECT\n");
313 if (!torture_init_connection(&cli1
)) {
317 status
= smbXcli_negprot(cli1
->conn
, cli1
->timeout
,
318 PROTOCOL_SMB2_02
, PROTOCOL_LATEST
);
319 if (!NT_STATUS_IS_OK(status
)) {
320 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
324 status
= cli_session_setup(cli1
, username
,
325 password
, strlen(password
),
326 password
, strlen(password
),
328 if (!NT_STATUS_IS_OK(status
)) {
329 printf("cli_session_setup returned %s\n", nt_errstr(status
));
333 status
= cli_tree_connect(cli1
, share
, "?????", "", 0);
334 if (!NT_STATUS_IS_OK(status
)) {
335 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
339 status
= smb2cli_create(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
340 cli1
->smb2
.tcon
, "session-reconnect.txt",
341 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
342 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
343 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
344 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
345 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
346 FILE_CREATE
, /* create_disposition, */
347 FILE_DELETE_ON_CLOSE
, /* create_options, */
348 NULL
, /* smb2_create_blobs *blobs */
352 if (!NT_STATUS_IS_OK(status
)) {
353 printf("smb2cli_create on cli1 %s\n", nt_errstr(status
));
357 status
= smb2cli_write(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
358 cli1
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
359 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
360 if (!NT_STATUS_IS_OK(status
)) {
361 printf("smb2cli_write returned %s\n", nt_errstr(status
));
365 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
366 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
367 if (!NT_STATUS_IS_OK(status
)) {
368 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
372 status
= smb2cli_read(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
373 cli1
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
375 talloc_tos(), &result
, &nread
);
376 if (!NT_STATUS_IS_OK(status
)) {
377 printf("smb2cli_read returned %s\n", nt_errstr(status
));
381 if (nread
!= strlen(hello
)) {
382 printf("smb2cli_read returned %d bytes, expected %d\n",
383 (int)nread
, (int)strlen(hello
));
387 if (memcmp(hello
, result
, nread
) != 0) {
388 printf("smb2cli_read returned '%s', expected '%s'\n",
393 /* prepare second session */
395 if (!torture_init_connection(&cli2
)) {
399 status
= smbXcli_negprot(cli2
->conn
, cli2
->timeout
,
400 PROTOCOL_SMB2_02
, PROTOCOL_LATEST
);
401 if (!NT_STATUS_IS_OK(status
)) {
402 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
406 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
407 if (!NT_STATUS_IS_OK(status
)) {
408 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
412 gensec_want_feature(auth_generic_state
->gensec_security
,
413 GENSEC_FEATURE_SESSION_KEY
);
414 status
= auth_generic_set_username(auth_generic_state
, username
);
415 if (!NT_STATUS_IS_OK(status
)) {
416 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
420 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
421 if (!NT_STATUS_IS_OK(status
)) {
422 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
426 status
= auth_generic_set_password(auth_generic_state
, password
);
427 if (!NT_STATUS_IS_OK(status
)) {
428 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
432 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
433 if (!NT_STATUS_IS_OK(status
)) {
434 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
438 ev
= samba_tevent_context_init(talloc_tos());
440 printf("samba_tevent_context_init() returned NULL\n");
444 status
= gensec_update(auth_generic_state
->gensec_security
,
445 talloc_tos(), data_blob_null
, &in_blob
);
446 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
447 printf("gensec_update returned %s\n", nt_errstr(status
));
451 cli2
->smb2
.session
= smbXcli_session_create(cli2
, cli2
->conn
);
453 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
458 SMB2_CAP_DFS
, /* in_capabilities */
460 /* in_previous_session_id: */
461 smb2cli_session_current_id(cli1
->smb2
.session
),
462 &in_blob
); /* in_security_buffer */
463 if (subreq
== NULL
) {
464 printf("smb2cli_session_setup_send() returned NULL\n");
468 ok
= tevent_req_poll(subreq
, ev
);
470 printf("tevent_req_poll() returned false\n");
474 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
476 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
477 printf("smb2cli_session_setup_recv returned %s\n",
482 status
= gensec_update(auth_generic_state
->gensec_security
,
483 talloc_tos(), out_blob
, &in_blob
);
484 if (!NT_STATUS_IS_OK(status
)) {
485 printf("auth_generic_update returned %s\n", nt_errstr(status
));
489 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
494 SMB2_CAP_DFS
, /* in_capabilities */
496 /* in_previous_session_id: */
497 smb2cli_session_current_id(cli1
->smb2
.session
),
498 &in_blob
); /* in_security_buffer */
499 if (subreq
== NULL
) {
500 printf("smb2cli_session_setup_send() returned NULL\n");
504 ok
= tevent_req_poll(subreq
, ev
);
506 printf("tevent_req_poll() returned false\n");
510 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
511 &recv_iov
, &out_blob
);
512 if (!NT_STATUS_IS_OK(status
)) {
513 printf("smb2cli_session_setup_recv returned %s\n",
518 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
520 if (!NT_STATUS_IS_OK(status
)) {
521 printf("gensec_session_key returned %s\n",
526 /* check file operation on the old client */
528 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
529 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
530 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
531 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
535 status
= cli_tree_connect(cli1
, share
, "?????", "", 0);
536 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
537 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
542 * checking file operations without signing.
543 * on w2k8r2 at least, flush, read and write also work the same way,
544 * while create gives ACCESS_DENIED without signing
546 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
547 cli2
->smb2
.tcon
, fid_persistent
, fid_volatile
);
548 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
549 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
551 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
555 status
= smb2cli_write(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
556 cli2
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
557 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
558 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
559 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
561 printf("smb2cli_write returned %s\n", nt_errstr(status
));
565 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
566 cli2
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
568 talloc_tos(), &result
, &nread
);
569 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
570 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
572 printf("smb2cli_read returned %s\n", nt_errstr(status
));
576 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
577 cli2
->smb2
.tcon
, "session-reconnect.txt",
578 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
579 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
580 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
581 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
582 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
583 FILE_CREATE
, /* create_disposition, */
584 FILE_DELETE_ON_CLOSE
, /* create_options, */
585 NULL
, /* smb2_create_blobs *blobs */
589 if (!NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
) &&
590 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
591 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
595 /* now grab the session key and try with signing */
597 status
= smb2cli_session_set_session_key(cli2
->smb2
.session
,
600 if (!NT_STATUS_IS_OK(status
)) {
601 printf("smb2cli_session_set_session_key %s\n", nt_errstr(status
));
605 /* the tid seems to be irrelevant at this stage */
607 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
608 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
609 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
610 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
612 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
616 status
= smb2cli_write(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
617 cli1
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
618 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
619 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
620 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
622 printf("smb2cli_write returned %s\n", nt_errstr(status
));
626 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
627 cli1
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
629 talloc_tos(), &result
, &nread
);
630 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
631 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
633 printf("smb2cli_read returned %s\n", nt_errstr(status
));
637 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
638 cli1
->smb2
.tcon
, "session-reconnect.txt",
639 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
640 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
641 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
642 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
643 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
644 FILE_CREATE
, /* create_disposition, */
645 FILE_DELETE_ON_CLOSE
, /* create_options, */
646 NULL
, /* smb2_create_blobs *blobs */
650 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
) &&
651 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
653 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
657 /* now do a new tcon and test file calls again */
659 status
= cli_tree_connect(cli2
, share
, "?????", "", 0);
660 if (!NT_STATUS_IS_OK(status
)) {
661 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
665 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
666 cli2
->smb2
.tcon
, "session-reconnect.txt",
667 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
668 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
669 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
670 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
671 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
672 FILE_CREATE
, /* create_disposition, */
673 FILE_DELETE_ON_CLOSE
, /* create_options, */
674 NULL
, /* smb2_create_blobs *blobs */
678 if (!NT_STATUS_IS_OK(status
)) {
679 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
683 status
= smb2cli_write(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
684 cli2
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
685 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
686 if (!NT_STATUS_IS_OK(status
)) {
687 printf("smb2cli_write returned %s\n", nt_errstr(status
));
691 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
692 cli2
->smb2
.tcon
, fid_persistent
, fid_volatile
);
693 if (!NT_STATUS_IS_OK(status
)) {
694 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
698 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
699 cli2
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
701 talloc_tos(), &result
, &nread
);
702 if (!NT_STATUS_IS_OK(status
)) {
703 printf("smb2cli_read returned %s\n", nt_errstr(status
));
707 if (nread
!= strlen(hello
)) {
708 printf("smb2cli_read returned %d bytes, expected %d\n",
709 (int)nread
, (int)strlen(hello
));
713 if (memcmp(hello
, result
, nread
) != 0) {
714 printf("smb2cli_read returned '%s', expected '%s'\n",
722 bool run_smb2_tcon_dependence(int dummy
)
724 struct cli_state
*cli
;
726 uint64_t fid_persistent
, fid_volatile
;
727 const char *hello
= "Hello, world\n";
730 struct smbXcli_tcon
*tcon2
;
733 printf("Starting SMB2-TCON-DEPENDENCE\n");
735 if (!torture_init_connection(&cli
)) {
739 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
740 PROTOCOL_SMB2_02
, PROTOCOL_LATEST
);
741 if (!NT_STATUS_IS_OK(status
)) {
742 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
746 status
= cli_session_setup(cli
, username
,
747 password
, strlen(password
),
748 password
, strlen(password
),
750 if (!NT_STATUS_IS_OK(status
)) {
751 printf("cli_session_setup returned %s\n", nt_errstr(status
));
755 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
756 if (!NT_STATUS_IS_OK(status
)) {
757 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
761 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
762 cli
->smb2
.tcon
, "tcon_depedence.txt",
763 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
764 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
765 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
766 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
767 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
768 FILE_CREATE
, /* create_disposition, */
769 FILE_DELETE_ON_CLOSE
, /* create_options, */
770 NULL
, /* smb2_create_blobs *blobs */
774 if (!NT_STATUS_IS_OK(status
)) {
775 printf("smb2cli_create on cli %s\n", nt_errstr(status
));
779 status
= smb2cli_write(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
780 cli
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
781 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
782 if (!NT_STATUS_IS_OK(status
)) {
783 printf("smb2cli_write returned %s\n", nt_errstr(status
));
787 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
788 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
789 if (!NT_STATUS_IS_OK(status
)) {
790 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
794 status
= smb2cli_read(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
795 cli
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
797 talloc_tos(), &result
, &nread
);
798 if (!NT_STATUS_IS_OK(status
)) {
799 printf("smb2cli_read returned %s\n", nt_errstr(status
));
803 if (nread
!= strlen(hello
)) {
804 printf("smb2cli_read returned %d bytes, expected %d\n",
805 (int)nread
, (int)strlen(hello
));
809 if (memcmp(hello
, result
, nread
) != 0) {
810 printf("smb2cli_read returned '%s', expected '%s'\n",
815 /* check behaviour with wrong tid... */
817 tcon2
= smbXcli_tcon_create(cli
);
818 tcon2_id
= smb2cli_tcon_current_id(cli
->smb2
.tcon
);
820 smb2cli_tcon_set_values(tcon2
,
825 0, /* capabilities */
826 0 /* maximal_access */);
828 status
= smb2cli_read(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
829 tcon2
, 0x10000, 0, fid_persistent
,
831 talloc_tos(), &result
, &nread
);
832 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
833 printf("smb2cli_read returned %s\n", nt_errstr(status
));
842 bool run_smb2_multi_channel(int dummy
)
844 struct cli_state
*cli1
;
845 struct cli_state
*cli2
;
846 struct cli_state
*cli3
;
849 uint64_t fid_persistent
, fid_volatile
;
850 struct tevent_context
*ev
;
851 struct tevent_req
*subreq
;
852 DATA_BLOB in_blob
= data_blob_null
;
854 DATA_BLOB channel_session_key
;
855 struct auth_generic_state
*auth_generic_state
;
856 struct iovec
*recv_iov
;
857 const char *hello
= "Hello, world\n";
860 struct GUID saved_guid
= cli_state_client_guid
;
862 printf("Starting SMB2-MULTI-CHANNEL\n");
864 cli_state_client_guid
= GUID_random();
866 if (!torture_init_connection(&cli1
)) {
870 if (!torture_init_connection(&cli2
)) {
874 if (!torture_init_connection(&cli3
)) {
878 cli_state_client_guid
= saved_guid
;
880 status
= smbXcli_negprot(cli1
->conn
, cli1
->timeout
,
881 PROTOCOL_SMB2_22
, PROTOCOL_LATEST
);
882 if (!NT_STATUS_IS_OK(status
)) {
883 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
887 status
= smbXcli_negprot(cli2
->conn
, cli2
->timeout
,
888 PROTOCOL_SMB2_22
, PROTOCOL_LATEST
);
889 if (!NT_STATUS_IS_OK(status
)) {
890 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
894 status
= smbXcli_negprot(cli3
->conn
, cli3
->timeout
,
895 PROTOCOL_SMB2_22
, PROTOCOL_LATEST
);
896 if (!NT_STATUS_IS_OK(status
)) {
897 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
901 status
= cli_session_setup(cli1
, username
,
902 password
, strlen(password
),
903 password
, strlen(password
),
905 if (!NT_STATUS_IS_OK(status
)) {
906 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status
));
910 status
= cli_tree_connect(cli1
, share
, "?????", "", 0);
911 if (!NT_STATUS_IS_OK(status
)) {
912 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
916 status
= smb2cli_session_create_channel(cli2
,
919 &cli2
->smb2
.session
);
920 if (!NT_STATUS_IS_OK(status
)) {
921 printf("smb2cli_session_create_channel returned %s\n",
926 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
927 if (!NT_STATUS_IS_OK(status
)) {
928 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
932 gensec_want_feature(auth_generic_state
->gensec_security
,
933 GENSEC_FEATURE_SESSION_KEY
);
934 status
= auth_generic_set_username(auth_generic_state
, username
);
935 if (!NT_STATUS_IS_OK(status
)) {
936 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
940 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
941 if (!NT_STATUS_IS_OK(status
)) {
942 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
946 status
= auth_generic_set_password(auth_generic_state
, password
);
947 if (!NT_STATUS_IS_OK(status
)) {
948 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
952 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
953 if (!NT_STATUS_IS_OK(status
)) {
954 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
958 ev
= samba_tevent_context_init(talloc_tos());
960 printf("samba_tevent_context_init() returned NULL\n");
964 status
= gensec_update(auth_generic_state
->gensec_security
,
965 talloc_tos(), data_blob_null
, &in_blob
);
966 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
967 printf("gensec_update returned %s\n", nt_errstr(status
));
971 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
976 SMB2_CAP_DFS
, /* in_capabilities */
978 0, /* in_previous_session_id */
979 &in_blob
); /* in_security_buffer */
980 if (subreq
== NULL
) {
981 printf("smb2cli_session_setup_send() returned NULL\n");
985 ok
= tevent_req_poll(subreq
, ev
);
987 printf("tevent_req_poll() returned false\n");
991 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
993 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
994 printf("smb2cli_session_setup_recv returned %s\n",
999 status
= gensec_update(auth_generic_state
->gensec_security
,
1000 talloc_tos(), out_blob
, &in_blob
);
1001 if (!NT_STATUS_IS_OK(status
)) {
1002 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1006 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1010 0x01, /* in_flags */
1011 SMB2_CAP_DFS
, /* in_capabilities */
1013 0, /* in_previous_session_id */
1014 &in_blob
); /* in_security_buffer */
1015 if (subreq
== NULL
) {
1016 printf("smb2cli_session_setup_send() returned NULL\n");
1020 ok
= tevent_req_poll(subreq
, ev
);
1022 printf("tevent_req_poll() returned false\n");
1026 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1027 &recv_iov
, &out_blob
);
1028 if (!NT_STATUS_IS_OK(status
)) {
1029 printf("smb2cli_session_setup_recv returned %s\n",
1034 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
1035 &channel_session_key
);
1036 if (!NT_STATUS_IS_OK(status
)) {
1037 printf("gensec_session_key returned %s\n",
1042 status
= smb2cli_session_set_channel_key(cli2
->smb2
.session
,
1043 channel_session_key
,
1045 if (!NT_STATUS_IS_OK(status
)) {
1046 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status
));
1050 status
= smb2cli_session_create_channel(cli3
,
1053 &cli3
->smb2
.session
);
1054 if (!NT_STATUS_IS_OK(status
)) {
1055 printf("smb2cli_session_create_channel returned %s\n",
1060 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1061 if (!NT_STATUS_IS_OK(status
)) {
1062 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1066 gensec_want_feature(auth_generic_state
->gensec_security
,
1067 GENSEC_FEATURE_SESSION_KEY
);
1068 status
= auth_generic_set_username(auth_generic_state
, username
);
1069 if (!NT_STATUS_IS_OK(status
)) {
1070 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
1074 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
1075 if (!NT_STATUS_IS_OK(status
)) {
1076 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
1080 status
= auth_generic_set_password(auth_generic_state
, password
);
1081 if (!NT_STATUS_IS_OK(status
)) {
1082 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
1086 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1087 if (!NT_STATUS_IS_OK(status
)) {
1088 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1092 status
= gensec_update(auth_generic_state
->gensec_security
,
1093 talloc_tos(), data_blob_null
, &in_blob
);
1094 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1095 printf("gensec_update returned %s\n", nt_errstr(status
));
1099 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1103 0x01, /* in_flags */
1104 SMB2_CAP_DFS
, /* in_capabilities */
1106 0, /* in_previous_session_id */
1107 &in_blob
); /* in_security_buffer */
1108 if (subreq
== NULL
) {
1109 printf("smb2cli_session_setup_send() returned NULL\n");
1113 ok
= tevent_req_poll(subreq
, ev
);
1115 printf("tevent_req_poll() returned false\n");
1119 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1121 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1122 printf("smb2cli_session_setup_recv returned %s\n",
1127 status
= gensec_update(auth_generic_state
->gensec_security
,
1128 talloc_tos(), out_blob
, &in_blob
);
1129 if (!NT_STATUS_IS_OK(status
)) {
1130 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1134 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1138 0x01, /* in_flags */
1139 SMB2_CAP_DFS
, /* in_capabilities */
1141 0, /* in_previous_session_id */
1142 &in_blob
); /* in_security_buffer */
1143 if (subreq
== NULL
) {
1144 printf("smb2cli_session_setup_send() returned NULL\n");
1148 ok
= tevent_req_poll(subreq
, ev
);
1150 printf("tevent_req_poll() returned false\n");
1154 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1155 &recv_iov
, &out_blob
);
1156 if (!NT_STATUS_IS_OK(status
)) {
1157 printf("smb2cli_session_setup_recv returned %s\n",
1162 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
1163 &channel_session_key
);
1164 if (!NT_STATUS_IS_OK(status
)) {
1165 printf("gensec_session_key returned %s\n",
1170 status
= smb2cli_session_set_channel_key(cli3
->smb2
.session
,
1171 channel_session_key
,
1173 if (!NT_STATUS_IS_OK(status
)) {
1174 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status
));
1178 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1179 cli1
->smb2
.tcon
, "multi-channel.txt",
1180 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1181 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1182 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1183 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1184 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1185 FILE_CREATE
, /* create_disposition, */
1186 FILE_DELETE_ON_CLOSE
, /* create_options, */
1187 NULL
, /* smb2_create_blobs *blobs */
1191 if (!NT_STATUS_IS_OK(status
)) {
1192 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
1196 status
= smb2cli_write(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1197 cli1
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
1198 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
1199 if (!NT_STATUS_IS_OK(status
)) {
1200 printf("smb2cli_write returned %s\n", nt_errstr(status
));
1204 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1205 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1206 if (!NT_STATUS_IS_OK(status
)) {
1207 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1211 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1212 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1213 if (!NT_STATUS_IS_OK(status
)) {
1214 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1218 status
= smb2cli_flush(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1219 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1220 if (!NT_STATUS_IS_OK(status
)) {
1221 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1225 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1226 cli1
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
1228 talloc_tos(), &result
, &nread
);
1229 if (!NT_STATUS_IS_OK(status
)) {
1230 printf("smb2cli_read returned %s\n", nt_errstr(status
));
1234 if (nread
!= strlen(hello
)) {
1235 printf("smb2cli_read returned %d bytes, expected %d\n",
1236 (int)nread
, (int)strlen(hello
));
1240 if (memcmp(hello
, result
, nread
) != 0) {
1241 printf("smb2cli_read returned '%s', expected '%s'\n",
1246 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1247 if (!NT_STATUS_IS_OK(status
)) {
1248 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1252 gensec_want_feature(auth_generic_state
->gensec_security
,
1253 GENSEC_FEATURE_SESSION_KEY
);
1254 status
= auth_generic_set_username(auth_generic_state
, username
);
1255 if (!NT_STATUS_IS_OK(status
)) {
1256 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
1260 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
1261 if (!NT_STATUS_IS_OK(status
)) {
1262 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
1266 status
= auth_generic_set_password(auth_generic_state
, password
);
1267 if (!NT_STATUS_IS_OK(status
)) {
1268 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
1272 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1273 if (!NT_STATUS_IS_OK(status
)) {
1274 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1278 status
= gensec_update(auth_generic_state
->gensec_security
,
1279 talloc_tos(), data_blob_null
, &in_blob
);
1280 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1281 printf("gensec_update returned %s\n", nt_errstr(status
));
1285 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1290 SMB2_CAP_DFS
, /* in_capabilities */
1292 0, /* in_previous_session_id */
1293 &in_blob
); /* in_security_buffer */
1294 if (subreq
== NULL
) {
1295 printf("smb2cli_session_setup_send() returned NULL\n");
1299 ok
= tevent_req_poll(subreq
, ev
);
1301 printf("tevent_req_poll() returned false\n");
1305 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1307 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1308 printf("smb2cli_session_setup_recv returned %s\n",
1313 status
= gensec_update(auth_generic_state
->gensec_security
,
1314 talloc_tos(), out_blob
, &in_blob
);
1315 if (!NT_STATUS_IS_OK(status
)) {
1316 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1320 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1321 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1322 if (!NT_STATUS_IS_OK(status
)) {
1323 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1327 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1328 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1329 if (!NT_STATUS_IS_OK(status
)) {
1330 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1334 status
= smb2cli_flush(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1335 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1336 if (!NT_STATUS_IS_OK(status
)) {
1337 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1341 status
= smb2cli_create(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1342 cli1
->smb2
.tcon
, "multi-channel-invalid.txt",
1343 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1344 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1345 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1346 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1347 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1348 FILE_CREATE
, /* create_disposition, */
1349 FILE_DELETE_ON_CLOSE
, /* create_options, */
1350 NULL
, /* smb2_create_blobs *blobs */
1354 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1355 printf("smb2cli_create %s\n", nt_errstr(status
));
1359 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1360 cli1
->smb2
.tcon
, "multi-channel-invalid.txt",
1361 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1362 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1363 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1364 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1365 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1366 FILE_CREATE
, /* create_disposition, */
1367 FILE_DELETE_ON_CLOSE
, /* create_options, */
1368 NULL
, /* smb2_create_blobs *blobs */
1372 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1373 printf("smb2cli_create %s\n", nt_errstr(status
));
1377 status
= smb2cli_create(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1378 cli1
->smb2
.tcon
, "multi-channel-invalid.txt",
1379 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1380 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1381 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1382 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1383 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1384 FILE_CREATE
, /* create_disposition, */
1385 FILE_DELETE_ON_CLOSE
, /* create_options, */
1386 NULL
, /* smb2_create_blobs *blobs */
1390 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1391 printf("smb2cli_create %s\n", nt_errstr(status
));
1395 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1400 SMB2_CAP_DFS
, /* in_capabilities */
1402 0, /* in_previous_session_id */
1403 &in_blob
); /* in_security_buffer */
1404 if (subreq
== NULL
) {
1405 printf("smb2cli_session_setup_send() returned NULL\n");
1409 ok
= tevent_req_poll(subreq
, ev
);
1411 printf("tevent_req_poll() returned false\n");
1415 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1416 &recv_iov
, &out_blob
);
1417 if (!NT_STATUS_IS_OK(status
)) {
1418 printf("smb2cli_session_setup_recv returned %s\n",
1423 status
= smb2cli_close(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1424 cli1
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
1425 if (!NT_STATUS_IS_OK(status
)) {
1426 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1430 status
= smb2cli_flush(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1431 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1432 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1433 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1437 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1438 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1439 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1440 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1444 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1445 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1446 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1447 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1454 bool run_smb2_session_reauth(int dummy
)
1456 struct cli_state
*cli
;
1459 uint64_t fid_persistent
, fid_volatile
;
1460 uint64_t dir_persistent
, dir_volatile
;
1462 uint32_t dir_data_length
;
1463 struct tevent_context
*ev
;
1464 struct tevent_req
*subreq
;
1465 DATA_BLOB in_blob
= data_blob_null
;
1467 DATA_BLOB in_input_buffer
;
1468 DATA_BLOB out_output_buffer
;
1469 uint8_t in_file_info_class
;
1470 struct auth_generic_state
*auth_generic_state
;
1471 struct iovec
*recv_iov
;
1473 struct smbXcli_tcon
*saved_tcon
;
1475 printf("Starting SMB2-SESSION_REAUTH\n");
1477 if (!torture_init_connection(&cli
)) {
1482 * PROTOCOL_SMB2_22 has a bug in win8pre0
1483 * it behaves like PROTOCOL_SMB2_02
1484 * and returns NT_STATUS_REQUEST_NOT_ACCEPTED,
1485 * while it allows it on PROTOCOL_SMB2_02.
1487 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
1488 PROTOCOL_SMB2_10
, PROTOCOL_SMB2_10
);
1489 if (!NT_STATUS_IS_OK(status
)) {
1490 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
1494 status
= cli_session_setup(cli
, username
,
1495 password
, strlen(password
),
1496 password
, strlen(password
),
1498 if (!NT_STATUS_IS_OK(status
)) {
1499 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status
));
1503 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
1504 if (!NT_STATUS_IS_OK(status
)) {
1505 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1509 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1510 cli
->smb2
.tcon
, "session-reauth.txt",
1511 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1512 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1513 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1514 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1515 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1516 FILE_CREATE
, /* create_disposition, */
1517 FILE_DELETE_ON_CLOSE
, /* create_options, */
1518 NULL
, /* smb2_create_blobs *blobs */
1522 if (!NT_STATUS_IS_OK(status
)) {
1523 printf("smb2cli_create %s\n", nt_errstr(status
));
1527 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1529 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1530 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1531 SEC_STD_SYNCHRONIZE
|
1533 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
1534 0, /* file_attributes, */
1535 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1536 FILE_OPEN
, /* create_disposition, */
1537 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
1538 NULL
, /* smb2_create_blobs *blobs */
1542 if (!NT_STATUS_IS_OK(status
)) {
1543 printf("smb2cli_create returned %s\n", nt_errstr(status
));
1547 status
= smb2cli_query_directory(
1548 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
1549 1, 0x3, 0, dir_persistent
, dir_volatile
,
1550 "session-reauth.txt", 0xffff,
1551 talloc_tos(), &dir_data
, &dir_data_length
);
1552 if (!NT_STATUS_IS_OK(status
)) {
1553 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1557 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1558 if (!NT_STATUS_IS_OK(status
)) {
1559 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1563 gensec_want_feature(auth_generic_state
->gensec_security
,
1564 GENSEC_FEATURE_SESSION_KEY
);
1565 status
= auth_generic_set_username(auth_generic_state
, username
);
1566 if (!NT_STATUS_IS_OK(status
)) {
1567 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
1571 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
1572 if (!NT_STATUS_IS_OK(status
)) {
1573 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
1577 status
= auth_generic_set_password(auth_generic_state
, password
);
1578 if (!NT_STATUS_IS_OK(status
)) {
1579 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
1583 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1584 if (!NT_STATUS_IS_OK(status
)) {
1585 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1589 ev
= samba_tevent_context_init(talloc_tos());
1591 printf("samba_tevent_context_init() returned NULL\n");
1595 status
= gensec_update(auth_generic_state
->gensec_security
,
1596 talloc_tos(), data_blob_null
, &in_blob
);
1597 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1598 printf("gensec_update returned %s\n", nt_errstr(status
));
1602 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1607 SMB2_CAP_DFS
, /* in_capabilities */
1609 0, /* in_previous_session_id */
1610 &in_blob
); /* in_security_buffer */
1611 if (subreq
== NULL
) {
1612 printf("smb2cli_session_setup_send() returned NULL\n");
1616 ok
= tevent_req_poll(subreq
, ev
);
1618 printf("tevent_req_poll() returned false\n");
1622 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1624 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1625 printf("smb2cli_session_setup_recv returned %s\n",
1630 status
= gensec_update(auth_generic_state
->gensec_security
,
1631 talloc_tos(), out_blob
, &in_blob
);
1632 if (!NT_STATUS_IS_OK(status
)) {
1633 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1637 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1638 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1639 if (!NT_STATUS_IS_OK(status
)) {
1640 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1644 status
= smb2cli_query_directory(
1645 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
1646 1, 0x3, 0, dir_persistent
, dir_volatile
,
1647 "session-reauth.txt", 0xffff,
1648 talloc_tos(), &dir_data
, &dir_data_length
);
1649 if (!NT_STATUS_IS_OK(status
)) {
1650 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1655 * query_info seems to be a path based operation on Windows...
1657 status
= smb2cli_query_info(cli
->conn
,
1661 SMB2_GETINFO_SECURITY
,
1662 0, /* in_file_info_class */
1663 1024, /* in_max_output_length */
1664 NULL
, /* in_input_buffer */
1665 SECINFO_OWNER
, /* in_additional_info */
1670 &out_output_buffer
);
1671 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1672 printf("smb2cli_query_info (security) returned %s\n", nt_errstr(status
));
1676 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1677 status
= smb2cli_query_info(cli
->conn
,
1683 1024, /* in_max_output_length */
1684 NULL
, /* in_input_buffer */
1685 0, /* in_additional_info */
1690 &out_output_buffer
);
1691 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1692 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1696 in_input_buffer
= data_blob_talloc(talloc_tos(), NULL
, 8);
1697 SBVAL(in_input_buffer
.data
, 0, 512);
1699 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1700 status
= smb2cli_set_info(cli
->conn
,
1707 0, /* in_additional_info */
1710 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1711 printf("smb2cli_set_info (position) returned %s\n", nt_errstr(status
));
1715 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1716 cli
->smb2
.tcon
, "session-reauth-invalid.txt",
1717 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1718 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1719 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1720 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1721 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1722 FILE_CREATE
, /* create_disposition, */
1723 FILE_DELETE_ON_CLOSE
, /* create_options, */
1724 NULL
, /* smb2_create_blobs *blobs */
1728 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1729 printf("smb2cli_create %s\n", nt_errstr(status
));
1733 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1735 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1736 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1737 SEC_STD_SYNCHRONIZE
|
1739 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
1740 0, /* file_attributes, */
1741 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1742 FILE_OPEN
, /* create_disposition, */
1743 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
1744 NULL
, /* smb2_create_blobs *blobs */
1748 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1749 printf("smb2cli_create returned %s\n", nt_errstr(status
));
1753 saved_tid
= smb2cli_tcon_current_id(cli
->smb2
.tcon
);
1754 saved_tcon
= cli
->smb2
.tcon
;
1755 cli
->smb2
.tcon
= smbXcli_tcon_create(cli
);
1756 smb2cli_tcon_set_values(cli
->smb2
.tcon
,
1761 0, /* capabilities */
1762 0 /* maximal_access */);
1763 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
1764 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1765 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1768 talloc_free(cli
->smb2
.tcon
);
1769 cli
->smb2
.tcon
= saved_tcon
;
1771 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1776 SMB2_CAP_DFS
, /* in_capabilities */
1778 0, /* in_previous_session_id */
1779 &in_blob
); /* in_security_buffer */
1780 if (subreq
== NULL
) {
1781 printf("smb2cli_session_setup_send() returned NULL\n");
1785 ok
= tevent_req_poll(subreq
, ev
);
1787 printf("tevent_req_poll() returned false\n");
1791 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1792 &recv_iov
, &out_blob
);
1793 if (!NT_STATUS_IS_OK(status
)) {
1794 printf("smb2cli_session_setup_recv returned %s\n",
1799 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1800 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1801 if (!NT_STATUS_IS_OK(status
)) {
1802 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1806 status
= smb2cli_query_info(cli
->conn
,
1810 SMB2_GETINFO_SECURITY
,
1811 0, /* in_file_info_class */
1812 1024, /* in_max_output_length */
1813 NULL
, /* in_input_buffer */
1814 SECINFO_OWNER
, /* in_additional_info */
1819 &out_output_buffer
);
1820 if (!NT_STATUS_IS_OK(status
)) {
1821 printf("smb2cli_query_info (security) returned %s\n", nt_errstr(status
));
1825 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1826 status
= smb2cli_query_info(cli
->conn
,
1832 1024, /* in_max_output_length */
1833 NULL
, /* in_input_buffer */
1834 0, /* in_additional_info */
1839 &out_output_buffer
);
1840 if (!NT_STATUS_IS_OK(status
)) {
1841 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1845 in_input_buffer
= data_blob_talloc(talloc_tos(), NULL
, 8);
1846 SBVAL(in_input_buffer
.data
, 0, 512);
1848 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1849 status
= smb2cli_set_info(cli
->conn
,
1856 0, /* in_additional_info */
1859 if (!NT_STATUS_IS_OK(status
)) {
1860 printf("smb2cli_set_info (position) returned %s\n", nt_errstr(status
));
1864 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1865 status
= smb2cli_query_info(cli
->conn
,
1871 1024, /* in_max_output_length */
1872 NULL
, /* in_input_buffer */
1873 0, /* in_additional_info */
1878 &out_output_buffer
);
1879 if (!NT_STATUS_IS_OK(status
)) {
1880 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1884 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1885 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
1886 if (!NT_STATUS_IS_OK(status
)) {
1887 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1891 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1892 cli
->smb2
.tcon
, "session-reauth.txt",
1893 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1894 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1895 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1896 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1897 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1898 FILE_CREATE
, /* create_disposition, */
1899 FILE_DELETE_ON_CLOSE
, /* create_options, */
1900 NULL
, /* smb2_create_blobs *blobs */
1904 if (!NT_STATUS_IS_OK(status
)) {
1905 printf("smb2cli_create %s\n", nt_errstr(status
));
1909 status
= smb2cli_query_directory(
1910 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
1911 1, 0x3, 0, dir_persistent
, dir_volatile
,
1912 "session-reauth.txt", 0xffff,
1913 talloc_tos(), &dir_data
, &dir_data_length
);
1914 if (!NT_STATUS_IS_OK(status
)) {
1915 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1919 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1920 cli
->smb2
.tcon
, 0, dir_persistent
, dir_volatile
);
1921 if (!NT_STATUS_IS_OK(status
)) {
1922 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1926 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1927 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
1928 if (!NT_STATUS_IS_OK(status
)) {
1929 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1933 saved_tid
= smb2cli_tcon_current_id(cli
->smb2
.tcon
);
1934 saved_tcon
= cli
->smb2
.tcon
;
1935 cli
->smb2
.tcon
= smbXcli_tcon_create(cli
);
1936 smb2cli_tcon_set_values(cli
->smb2
.tcon
,
1941 0, /* capabilities */
1942 0 /* maximal_access */);
1943 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
1944 if (!NT_STATUS_IS_OK(status
)) {
1945 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1948 talloc_free(cli
->smb2
.tcon
);
1949 cli
->smb2
.tcon
= saved_tcon
;