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->conn,
188 if (!NT_STATUS_IS_OK(status)) {
189 printf("smb2cli_tdis returned %s\n", nt_errstr(status));
192 talloc_free(cli->smb2.tcon);
193 cli->smb2.tcon = 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);
251 case PROTOCOL_SMB2_02:
254 case PROTOCOL_SMB2_10:
257 case PROTOCOL_SMB2_22:
260 case PROTOCOL_SMB2_24:
263 case PROTOCOL_SMB3_00:
266 case PROTOCOL_SMB3_02:
274 printf("Server supports %s\n", name);
276 printf("Server DOES NOT support SMB2\n");
280 status = smbXcli_negprot(cli->conn, cli->timeout,
282 if (!NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_RESET) &&
283 !NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_DISCONNECTED) &&
284 !NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_ABORTED)) {
285 printf("2nd smbXcli_negprot should disconnect - returned %s\n",
290 if (smbXcli_conn_is_connected(cli->conn)) {
291 printf("2nd smbXcli_negprot should disconnect "
292 "- still connected\n");
299 bool run_smb2_session_reconnect(int dummy)
301 struct cli_state *cli1;
302 struct cli_state *cli2;
305 uint64_t fid_persistent, fid_volatile;
306 struct tevent_context *ev;
307 struct tevent_req *subreq;
308 DATA_BLOB in_blob = data_blob_null;
310 DATA_BLOB session_key;
311 struct auth_generic_state *auth_generic_state;
312 struct iovec *recv_iov;
313 const char *hello = "Hello, world\n";
317 printf("Starting SMB2-SESSION-RECONNECT\n");
319 if (!torture_init_connection(&cli1)) {
323 status = smbXcli_negprot(cli1->conn, cli1->timeout,
324 PROTOCOL_SMB2_02, PROTOCOL_LATEST);
325 if (!NT_STATUS_IS_OK(status)) {
326 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
330 status = cli_session_setup(cli1, username,
331 password, strlen(password),
332 password, strlen(password),
334 if (!NT_STATUS_IS_OK(status)) {
335 printf("cli_session_setup returned %s\n", nt_errstr(status));
339 status = cli_tree_connect(cli1, share, "?????", "", 0);
340 if (!NT_STATUS_IS_OK(status)) {
341 printf("cli_tree_connect returned %s\n", nt_errstr(status));
345 status = smb2cli_create(cli1->conn, cli1->timeout, cli1->smb2.session,
346 cli1->smb2.tcon, "session-reconnect.txt",
347 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
348 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
349 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
350 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
351 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
352 FILE_CREATE, /* create_disposition, */
353 FILE_DELETE_ON_CLOSE, /* create_options, */
354 NULL, /* smb2_create_blobs *blobs */
358 if (!NT_STATUS_IS_OK(status)) {
359 printf("smb2cli_create on cli1 %s\n", nt_errstr(status));
363 status = smb2cli_write(cli1->conn, cli1->timeout, cli1->smb2.session,
364 cli1->smb2.tcon, strlen(hello), 0, fid_persistent,
365 fid_volatile, 0, 0, (const uint8_t *)hello, NULL);
366 if (!NT_STATUS_IS_OK(status)) {
367 printf("smb2cli_write returned %s\n", nt_errstr(status));
371 status = smb2cli_flush(cli1->conn, cli1->timeout, cli1->smb2.session,
372 cli1->smb2.tcon, fid_persistent, fid_volatile);
373 if (!NT_STATUS_IS_OK(status)) {
374 printf("smb2cli_flush returned %s\n", nt_errstr(status));
378 status = smb2cli_read(cli1->conn, cli1->timeout, cli1->smb2.session,
379 cli1->smb2.tcon, 0x10000, 0, fid_persistent,
381 talloc_tos(), &result, &nread);
382 if (!NT_STATUS_IS_OK(status)) {
383 printf("smb2cli_read returned %s\n", nt_errstr(status));
387 if (nread != strlen(hello)) {
388 printf("smb2cli_read returned %d bytes, expected %d\n",
389 (int)nread, (int)strlen(hello));
393 if (memcmp(hello, result, nread) != 0) {
394 printf("smb2cli_read returned '%s', expected '%s'\n",
399 /* prepare second session */
401 if (!torture_init_connection(&cli2)) {
405 status = smbXcli_negprot(cli2->conn, cli2->timeout,
406 PROTOCOL_SMB2_02, PROTOCOL_LATEST);
407 if (!NT_STATUS_IS_OK(status)) {
408 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
412 status = auth_generic_client_prepare(talloc_tos(), &auth_generic_state);
413 if (!NT_STATUS_IS_OK(status)) {
414 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status));
418 gensec_want_feature(auth_generic_state->gensec_security,
419 GENSEC_FEATURE_SESSION_KEY);
420 status = auth_generic_set_username(auth_generic_state, username);
421 if (!NT_STATUS_IS_OK(status)) {
422 printf("auth_generic_set_username returned %s\n", nt_errstr(status));
426 status = auth_generic_set_domain(auth_generic_state, workgroup);
427 if (!NT_STATUS_IS_OK(status)) {
428 printf("auth_generic_set_domain returned %s\n", nt_errstr(status));
432 status = auth_generic_set_password(auth_generic_state, password);
433 if (!NT_STATUS_IS_OK(status)) {
434 printf("auth_generic_set_password returned %s\n", nt_errstr(status));
438 status = auth_generic_client_start(auth_generic_state, GENSEC_OID_NTLMSSP);
439 if (!NT_STATUS_IS_OK(status)) {
440 printf("auth_generic_client_start returned %s\n", nt_errstr(status));
444 ev = samba_tevent_context_init(talloc_tos());
446 printf("samba_tevent_context_init() returned NULL\n");
450 status = gensec_update(auth_generic_state->gensec_security,
451 talloc_tos(), data_blob_null, &in_blob);
452 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
453 printf("gensec_update returned %s\n", nt_errstr(status));
457 cli2->smb2.session = smbXcli_session_create(cli2, cli2->conn);
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(),
482 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
483 printf("smb2cli_session_setup_recv returned %s\n",
488 status = gensec_update(auth_generic_state->gensec_security,
489 talloc_tos(), out_blob, &in_blob);
490 if (!NT_STATUS_IS_OK(status)) {
491 printf("auth_generic_update returned %s\n", nt_errstr(status));
495 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
500 SMB2_CAP_DFS, /* in_capabilities */
502 /* in_previous_session_id: */
503 smb2cli_session_current_id(cli1->smb2.session),
504 &in_blob); /* in_security_buffer */
505 if (subreq == NULL) {
506 printf("smb2cli_session_setup_send() returned NULL\n");
510 ok = tevent_req_poll(subreq, ev);
512 printf("tevent_req_poll() returned false\n");
516 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
517 &recv_iov, &out_blob);
518 if (!NT_STATUS_IS_OK(status)) {
519 printf("smb2cli_session_setup_recv returned %s\n",
524 status = gensec_session_key(auth_generic_state->gensec_security, talloc_tos(),
526 if (!NT_STATUS_IS_OK(status)) {
527 printf("gensec_session_key returned %s\n",
532 /* check file operation on the old client */
534 status = smb2cli_flush(cli1->conn, cli1->timeout, cli1->smb2.session,
535 cli1->smb2.tcon, fid_persistent, fid_volatile);
536 if (!NT_STATUS_EQUAL(status, NT_STATUS_USER_SESSION_DELETED)) {
537 printf("smb2cli_flush returned %s\n", nt_errstr(status));
541 status = cli_tree_connect(cli1, share, "?????", "", 0);
542 if (!NT_STATUS_EQUAL(status, NT_STATUS_USER_SESSION_DELETED)) {
543 printf("cli_tree_connect returned %s\n", nt_errstr(status));
548 * checking file operations without signing.
549 * on w2k8r2 at least, flush, read and write also work the same way,
550 * while create gives ACCESS_DENIED without signing
552 status = smb2cli_flush(cli2->conn, cli2->timeout, cli2->smb2.session,
553 cli2->smb2.tcon, fid_persistent, fid_volatile);
554 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED) &&
555 !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED))
557 printf("smb2cli_flush returned %s\n", nt_errstr(status));
561 status = smb2cli_write(cli2->conn, cli2->timeout, cli2->smb2.session,
562 cli2->smb2.tcon, strlen(hello), 0, fid_persistent,
563 fid_volatile, 0, 0, (const uint8_t *)hello, NULL);
564 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED) &&
565 !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED))
567 printf("smb2cli_write returned %s\n", nt_errstr(status));
571 status = smb2cli_read(cli2->conn, cli2->timeout, cli2->smb2.session,
572 cli2->smb2.tcon, 0x10000, 0, fid_persistent,
574 talloc_tos(), &result, &nread);
575 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED) &&
576 !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED))
578 printf("smb2cli_read returned %s\n", nt_errstr(status));
582 status = smb2cli_create(cli2->conn, cli2->timeout, cli2->smb2.session,
583 cli2->smb2.tcon, "session-reconnect.txt",
584 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
585 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
586 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
587 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
588 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
589 FILE_CREATE, /* create_disposition, */
590 FILE_DELETE_ON_CLOSE, /* create_options, */
591 NULL, /* smb2_create_blobs *blobs */
595 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED) &&
596 !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED)) {
597 printf("smb2cli_create on cli2 %s\n", nt_errstr(status));
601 /* now grab the session key and try with signing */
603 status = smb2cli_session_set_session_key(cli2->smb2.session,
606 if (!NT_STATUS_IS_OK(status)) {
607 printf("smb2cli_session_set_session_key %s\n", nt_errstr(status));
611 /* the tid seems to be irrelevant at this stage */
613 status = smb2cli_flush(cli2->conn, cli2->timeout, cli2->smb2.session,
614 cli1->smb2.tcon, fid_persistent, fid_volatile);
615 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED) &&
616 !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED))
618 printf("smb2cli_flush returned %s\n", nt_errstr(status));
622 status = smb2cli_write(cli2->conn, cli2->timeout, cli2->smb2.session,
623 cli1->smb2.tcon, strlen(hello), 0, fid_persistent,
624 fid_volatile, 0, 0, (const uint8_t *)hello, NULL);
625 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED) &&
626 !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED))
628 printf("smb2cli_write returned %s\n", nt_errstr(status));
632 status = smb2cli_read(cli2->conn, cli2->timeout, cli2->smb2.session,
633 cli1->smb2.tcon, 0x10000, 0, fid_persistent,
635 talloc_tos(), &result, &nread);
636 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED) &&
637 !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED))
639 printf("smb2cli_read returned %s\n", nt_errstr(status));
643 status = smb2cli_create(cli2->conn, cli2->timeout, cli2->smb2.session,
644 cli1->smb2.tcon, "session-reconnect.txt",
645 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
646 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
647 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
648 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
649 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
650 FILE_CREATE, /* create_disposition, */
651 FILE_DELETE_ON_CLOSE, /* create_options, */
652 NULL, /* smb2_create_blobs *blobs */
656 if (!NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED) &&
657 !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED))
659 printf("smb2cli_create on cli2 %s\n", nt_errstr(status));
663 /* now do a new tcon and test file calls again */
665 status = cli_tree_connect(cli2, share, "?????", "", 0);
666 if (!NT_STATUS_IS_OK(status)) {
667 printf("cli_tree_connect returned %s\n", nt_errstr(status));
671 status = smb2cli_create(cli2->conn, cli2->timeout, cli2->smb2.session,
672 cli2->smb2.tcon, "session-reconnect.txt",
673 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
674 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
675 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
676 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
677 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
678 FILE_CREATE, /* create_disposition, */
679 FILE_DELETE_ON_CLOSE, /* create_options, */
680 NULL, /* smb2_create_blobs *blobs */
684 if (!NT_STATUS_IS_OK(status)) {
685 printf("smb2cli_create on cli2 %s\n", nt_errstr(status));
689 status = smb2cli_write(cli2->conn, cli2->timeout, cli2->smb2.session,
690 cli2->smb2.tcon, strlen(hello), 0, fid_persistent,
691 fid_volatile, 0, 0, (const uint8_t *)hello, NULL);
692 if (!NT_STATUS_IS_OK(status)) {
693 printf("smb2cli_write returned %s\n", nt_errstr(status));
697 status = smb2cli_flush(cli2->conn, cli2->timeout, cli2->smb2.session,
698 cli2->smb2.tcon, fid_persistent, fid_volatile);
699 if (!NT_STATUS_IS_OK(status)) {
700 printf("smb2cli_flush returned %s\n", nt_errstr(status));
704 status = smb2cli_read(cli2->conn, cli2->timeout, cli2->smb2.session,
705 cli2->smb2.tcon, 0x10000, 0, fid_persistent,
707 talloc_tos(), &result, &nread);
708 if (!NT_STATUS_IS_OK(status)) {
709 printf("smb2cli_read returned %s\n", nt_errstr(status));
713 if (nread != strlen(hello)) {
714 printf("smb2cli_read returned %d bytes, expected %d\n",
715 (int)nread, (int)strlen(hello));
719 if (memcmp(hello, result, nread) != 0) {
720 printf("smb2cli_read returned '%s', expected '%s'\n",
728 bool run_smb2_tcon_dependence(int dummy)
730 struct cli_state *cli;
732 uint64_t fid_persistent, fid_volatile;
733 const char *hello = "Hello, world\n";
736 struct smbXcli_tcon *tcon2;
739 printf("Starting SMB2-TCON-DEPENDENCE\n");
741 if (!torture_init_connection(&cli)) {
745 status = smbXcli_negprot(cli->conn, cli->timeout,
746 PROTOCOL_SMB2_02, PROTOCOL_LATEST);
747 if (!NT_STATUS_IS_OK(status)) {
748 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
752 status = cli_session_setup(cli, username,
753 password, strlen(password),
754 password, strlen(password),
756 if (!NT_STATUS_IS_OK(status)) {
757 printf("cli_session_setup returned %s\n", nt_errstr(status));
761 status = cli_tree_connect(cli, share, "?????", "", 0);
762 if (!NT_STATUS_IS_OK(status)) {
763 printf("cli_tree_connect returned %s\n", nt_errstr(status));
767 status = smb2cli_create(cli->conn, cli->timeout, cli->smb2.session,
768 cli->smb2.tcon, "tcon_depedence.txt",
769 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
770 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
771 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
772 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
773 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
774 FILE_CREATE, /* create_disposition, */
775 FILE_DELETE_ON_CLOSE, /* create_options, */
776 NULL, /* smb2_create_blobs *blobs */
780 if (!NT_STATUS_IS_OK(status)) {
781 printf("smb2cli_create on cli %s\n", nt_errstr(status));
785 status = smb2cli_write(cli->conn, cli->timeout, cli->smb2.session,
786 cli->smb2.tcon, strlen(hello), 0, fid_persistent,
787 fid_volatile, 0, 0, (const uint8_t *)hello, NULL);
788 if (!NT_STATUS_IS_OK(status)) {
789 printf("smb2cli_write returned %s\n", nt_errstr(status));
793 status = smb2cli_flush(cli->conn, cli->timeout, cli->smb2.session,
794 cli->smb2.tcon, fid_persistent, fid_volatile);
795 if (!NT_STATUS_IS_OK(status)) {
796 printf("smb2cli_flush returned %s\n", nt_errstr(status));
800 status = smb2cli_read(cli->conn, cli->timeout, cli->smb2.session,
801 cli->smb2.tcon, 0x10000, 0, fid_persistent,
803 talloc_tos(), &result, &nread);
804 if (!NT_STATUS_IS_OK(status)) {
805 printf("smb2cli_read returned %s\n", nt_errstr(status));
809 if (nread != strlen(hello)) {
810 printf("smb2cli_read returned %d bytes, expected %d\n",
811 (int)nread, (int)strlen(hello));
815 if (memcmp(hello, result, nread) != 0) {
816 printf("smb2cli_read returned '%s', expected '%s'\n",
821 /* check behaviour with wrong tid... */
823 tcon2 = smbXcli_tcon_create(cli);
824 tcon2_id = smb2cli_tcon_current_id(cli->smb2.tcon);
826 smb2cli_tcon_set_values(tcon2,
831 0, /* capabilities */
832 0 /* maximal_access */);
834 status = smb2cli_read(cli->conn, cli->timeout, cli->smb2.session,
835 tcon2, 0x10000, 0, fid_persistent,
837 talloc_tos(), &result, &nread);
838 if (!NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED)) {
839 printf("smb2cli_read returned %s\n", nt_errstr(status));
848 bool run_smb2_multi_channel(int dummy)
850 struct cli_state *cli1;
851 struct cli_state *cli2;
852 struct cli_state *cli3;
855 uint64_t fid_persistent, fid_volatile;
856 struct tevent_context *ev;
857 struct tevent_req *subreq;
858 DATA_BLOB in_blob = data_blob_null;
860 DATA_BLOB channel_session_key;
861 struct auth_generic_state *auth_generic_state;
862 struct iovec *recv_iov;
863 const char *hello = "Hello, world\n";
866 struct GUID saved_guid = cli_state_client_guid;
868 printf("Starting SMB2-MULTI-CHANNEL\n");
870 cli_state_client_guid = GUID_random();
872 if (!torture_init_connection(&cli1)) {
876 if (!torture_init_connection(&cli2)) {
880 if (!torture_init_connection(&cli3)) {
884 cli_state_client_guid = saved_guid;
886 status = smbXcli_negprot(cli1->conn, cli1->timeout,
887 PROTOCOL_SMB2_22, PROTOCOL_LATEST);
888 if (!NT_STATUS_IS_OK(status)) {
889 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
893 status = smbXcli_negprot(cli2->conn, cli2->timeout,
894 PROTOCOL_SMB2_22, PROTOCOL_LATEST);
895 if (!NT_STATUS_IS_OK(status)) {
896 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
900 status = smbXcli_negprot(cli3->conn, cli3->timeout,
901 PROTOCOL_SMB2_22, PROTOCOL_LATEST);
902 if (!NT_STATUS_IS_OK(status)) {
903 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
907 status = cli_session_setup(cli1, username,
908 password, strlen(password),
909 password, strlen(password),
911 if (!NT_STATUS_IS_OK(status)) {
912 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status));
916 status = cli_tree_connect(cli1, share, "?????", "", 0);
917 if (!NT_STATUS_IS_OK(status)) {
918 printf("cli_tree_connect returned %s\n", nt_errstr(status));
922 status = smb2cli_session_create_channel(cli2,
925 &cli2->smb2.session);
926 if (!NT_STATUS_IS_OK(status)) {
927 printf("smb2cli_session_create_channel returned %s\n",
932 status = auth_generic_client_prepare(talloc_tos(), &auth_generic_state);
933 if (!NT_STATUS_IS_OK(status)) {
934 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status));
938 gensec_want_feature(auth_generic_state->gensec_security,
939 GENSEC_FEATURE_SESSION_KEY);
940 status = auth_generic_set_username(auth_generic_state, username);
941 if (!NT_STATUS_IS_OK(status)) {
942 printf("auth_generic_set_username returned %s\n", nt_errstr(status));
946 status = auth_generic_set_domain(auth_generic_state, workgroup);
947 if (!NT_STATUS_IS_OK(status)) {
948 printf("auth_generic_set_domain returned %s\n", nt_errstr(status));
952 status = auth_generic_set_password(auth_generic_state, password);
953 if (!NT_STATUS_IS_OK(status)) {
954 printf("auth_generic_set_password returned %s\n", nt_errstr(status));
958 status = auth_generic_client_start(auth_generic_state, GENSEC_OID_NTLMSSP);
959 if (!NT_STATUS_IS_OK(status)) {
960 printf("auth_generic_client_start returned %s\n", nt_errstr(status));
964 ev = samba_tevent_context_init(talloc_tos());
966 printf("samba_tevent_context_init() returned NULL\n");
970 status = gensec_update(auth_generic_state->gensec_security,
971 talloc_tos(), data_blob_null, &in_blob);
972 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
973 printf("gensec_update returned %s\n", nt_errstr(status));
977 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
982 SMB2_CAP_DFS, /* in_capabilities */
984 0, /* in_previous_session_id */
985 &in_blob); /* in_security_buffer */
986 if (subreq == NULL) {
987 printf("smb2cli_session_setup_send() returned NULL\n");
991 ok = tevent_req_poll(subreq, ev);
993 printf("tevent_req_poll() returned false\n");
997 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
999 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1000 printf("smb2cli_session_setup_recv returned %s\n",
1005 status = gensec_update(auth_generic_state->gensec_security,
1006 talloc_tos(), out_blob, &in_blob);
1007 if (!NT_STATUS_IS_OK(status)) {
1008 printf("auth_generic_update returned %s\n", nt_errstr(status));
1012 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1016 0x01, /* in_flags */
1017 SMB2_CAP_DFS, /* in_capabilities */
1019 0, /* in_previous_session_id */
1020 &in_blob); /* in_security_buffer */
1021 if (subreq == NULL) {
1022 printf("smb2cli_session_setup_send() returned NULL\n");
1026 ok = tevent_req_poll(subreq, ev);
1028 printf("tevent_req_poll() returned false\n");
1032 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1033 &recv_iov, &out_blob);
1034 if (!NT_STATUS_IS_OK(status)) {
1035 printf("smb2cli_session_setup_recv returned %s\n",
1040 status = gensec_session_key(auth_generic_state->gensec_security, talloc_tos(),
1041 &channel_session_key);
1042 if (!NT_STATUS_IS_OK(status)) {
1043 printf("gensec_session_key returned %s\n",
1048 status = smb2cli_session_set_channel_key(cli2->smb2.session,
1049 channel_session_key,
1051 if (!NT_STATUS_IS_OK(status)) {
1052 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status));
1056 status = smb2cli_session_create_channel(cli3,
1059 &cli3->smb2.session);
1060 if (!NT_STATUS_IS_OK(status)) {
1061 printf("smb2cli_session_create_channel returned %s\n",
1066 status = auth_generic_client_prepare(talloc_tos(), &auth_generic_state);
1067 if (!NT_STATUS_IS_OK(status)) {
1068 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status));
1072 gensec_want_feature(auth_generic_state->gensec_security,
1073 GENSEC_FEATURE_SESSION_KEY);
1074 status = auth_generic_set_username(auth_generic_state, username);
1075 if (!NT_STATUS_IS_OK(status)) {
1076 printf("auth_generic_set_username returned %s\n", nt_errstr(status));
1080 status = auth_generic_set_domain(auth_generic_state, workgroup);
1081 if (!NT_STATUS_IS_OK(status)) {
1082 printf("auth_generic_set_domain returned %s\n", nt_errstr(status));
1086 status = auth_generic_set_password(auth_generic_state, password);
1087 if (!NT_STATUS_IS_OK(status)) {
1088 printf("auth_generic_set_password returned %s\n", nt_errstr(status));
1092 status = auth_generic_client_start(auth_generic_state, GENSEC_OID_NTLMSSP);
1093 if (!NT_STATUS_IS_OK(status)) {
1094 printf("auth_generic_client_start returned %s\n", nt_errstr(status));
1098 status = gensec_update(auth_generic_state->gensec_security,
1099 talloc_tos(), data_blob_null, &in_blob);
1100 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1101 printf("gensec_update returned %s\n", nt_errstr(status));
1105 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1109 0x01, /* in_flags */
1110 SMB2_CAP_DFS, /* in_capabilities */
1112 0, /* in_previous_session_id */
1113 &in_blob); /* in_security_buffer */
1114 if (subreq == NULL) {
1115 printf("smb2cli_session_setup_send() returned NULL\n");
1119 ok = tevent_req_poll(subreq, ev);
1121 printf("tevent_req_poll() returned false\n");
1125 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1127 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1128 printf("smb2cli_session_setup_recv returned %s\n",
1133 status = gensec_update(auth_generic_state->gensec_security,
1134 talloc_tos(), out_blob, &in_blob);
1135 if (!NT_STATUS_IS_OK(status)) {
1136 printf("auth_generic_update returned %s\n", nt_errstr(status));
1140 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1144 0x01, /* in_flags */
1145 SMB2_CAP_DFS, /* in_capabilities */
1147 0, /* in_previous_session_id */
1148 &in_blob); /* in_security_buffer */
1149 if (subreq == NULL) {
1150 printf("smb2cli_session_setup_send() returned NULL\n");
1154 ok = tevent_req_poll(subreq, ev);
1156 printf("tevent_req_poll() returned false\n");
1160 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1161 &recv_iov, &out_blob);
1162 if (!NT_STATUS_IS_OK(status)) {
1163 printf("smb2cli_session_setup_recv returned %s\n",
1168 status = gensec_session_key(auth_generic_state->gensec_security, talloc_tos(),
1169 &channel_session_key);
1170 if (!NT_STATUS_IS_OK(status)) {
1171 printf("gensec_session_key returned %s\n",
1176 status = smb2cli_session_set_channel_key(cli3->smb2.session,
1177 channel_session_key,
1179 if (!NT_STATUS_IS_OK(status)) {
1180 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status));
1184 status = smb2cli_create(cli2->conn, cli2->timeout, cli2->smb2.session,
1185 cli1->smb2.tcon, "multi-channel.txt",
1186 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1187 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1188 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1189 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1190 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1191 FILE_CREATE, /* create_disposition, */
1192 FILE_DELETE_ON_CLOSE, /* create_options, */
1193 NULL, /* smb2_create_blobs *blobs */
1197 if (!NT_STATUS_IS_OK(status)) {
1198 printf("smb2cli_create on cli2 %s\n", nt_errstr(status));
1202 status = smb2cli_write(cli1->conn, cli1->timeout, cli1->smb2.session,
1203 cli1->smb2.tcon, strlen(hello), 0, fid_persistent,
1204 fid_volatile, 0, 0, (const uint8_t *)hello, NULL);
1205 if (!NT_STATUS_IS_OK(status)) {
1206 printf("smb2cli_write returned %s\n", nt_errstr(status));
1210 status = smb2cli_flush(cli2->conn, cli2->timeout, cli2->smb2.session,
1211 cli1->smb2.tcon, fid_persistent, fid_volatile);
1212 if (!NT_STATUS_IS_OK(status)) {
1213 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1217 status = smb2cli_flush(cli1->conn, cli1->timeout, cli1->smb2.session,
1218 cli1->smb2.tcon, fid_persistent, fid_volatile);
1219 if (!NT_STATUS_IS_OK(status)) {
1220 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1224 status = smb2cli_flush(cli3->conn, cli3->timeout, cli3->smb2.session,
1225 cli1->smb2.tcon, fid_persistent, fid_volatile);
1226 if (!NT_STATUS_IS_OK(status)) {
1227 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1231 status = smb2cli_read(cli2->conn, cli2->timeout, cli2->smb2.session,
1232 cli1->smb2.tcon, 0x10000, 0, fid_persistent,
1234 talloc_tos(), &result, &nread);
1235 if (!NT_STATUS_IS_OK(status)) {
1236 printf("smb2cli_read returned %s\n", nt_errstr(status));
1240 if (nread != strlen(hello)) {
1241 printf("smb2cli_read returned %d bytes, expected %d\n",
1242 (int)nread, (int)strlen(hello));
1246 if (memcmp(hello, result, nread) != 0) {
1247 printf("smb2cli_read returned '%s', expected '%s'\n",
1252 status = auth_generic_client_prepare(talloc_tos(), &auth_generic_state);
1253 if (!NT_STATUS_IS_OK(status)) {
1254 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status));
1258 gensec_want_feature(auth_generic_state->gensec_security,
1259 GENSEC_FEATURE_SESSION_KEY);
1260 status = auth_generic_set_username(auth_generic_state, username);
1261 if (!NT_STATUS_IS_OK(status)) {
1262 printf("auth_generic_set_username returned %s\n", nt_errstr(status));
1266 status = auth_generic_set_domain(auth_generic_state, workgroup);
1267 if (!NT_STATUS_IS_OK(status)) {
1268 printf("auth_generic_set_domain returned %s\n", nt_errstr(status));
1272 status = auth_generic_set_password(auth_generic_state, password);
1273 if (!NT_STATUS_IS_OK(status)) {
1274 printf("auth_generic_set_password returned %s\n", nt_errstr(status));
1278 status = auth_generic_client_start(auth_generic_state, GENSEC_OID_NTLMSSP);
1279 if (!NT_STATUS_IS_OK(status)) {
1280 printf("auth_generic_client_start returned %s\n", nt_errstr(status));
1284 status = gensec_update(auth_generic_state->gensec_security,
1285 talloc_tos(), data_blob_null, &in_blob);
1286 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1287 printf("gensec_update returned %s\n", nt_errstr(status));
1291 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1296 SMB2_CAP_DFS, /* in_capabilities */
1298 0, /* in_previous_session_id */
1299 &in_blob); /* in_security_buffer */
1300 if (subreq == NULL) {
1301 printf("smb2cli_session_setup_send() returned NULL\n");
1305 ok = tevent_req_poll(subreq, ev);
1307 printf("tevent_req_poll() returned false\n");
1311 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1313 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1314 printf("smb2cli_session_setup_recv returned %s\n",
1319 status = gensec_update(auth_generic_state->gensec_security,
1320 talloc_tos(), out_blob, &in_blob);
1321 if (!NT_STATUS_IS_OK(status)) {
1322 printf("auth_generic_update returned %s\n", nt_errstr(status));
1326 status = smb2cli_flush(cli1->conn, cli1->timeout, cli1->smb2.session,
1327 cli1->smb2.tcon, fid_persistent, fid_volatile);
1328 if (!NT_STATUS_IS_OK(status)) {
1329 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1333 status = smb2cli_flush(cli2->conn, cli2->timeout, cli2->smb2.session,
1334 cli1->smb2.tcon, fid_persistent, fid_volatile);
1335 if (!NT_STATUS_IS_OK(status)) {
1336 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1340 status = smb2cli_flush(cli3->conn, cli3->timeout, cli3->smb2.session,
1341 cli1->smb2.tcon, fid_persistent, fid_volatile);
1342 if (!NT_STATUS_IS_OK(status)) {
1343 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1347 status = smb2cli_create(cli1->conn, cli1->timeout, cli1->smb2.session,
1348 cli1->smb2.tcon, "multi-channel-invalid.txt",
1349 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1350 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1351 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1352 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1353 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1354 FILE_CREATE, /* create_disposition, */
1355 FILE_DELETE_ON_CLOSE, /* create_options, */
1356 NULL, /* smb2_create_blobs *blobs */
1360 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1361 printf("smb2cli_create %s\n", nt_errstr(status));
1365 status = smb2cli_create(cli2->conn, cli2->timeout, cli2->smb2.session,
1366 cli1->smb2.tcon, "multi-channel-invalid.txt",
1367 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1368 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1369 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1370 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1371 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1372 FILE_CREATE, /* create_disposition, */
1373 FILE_DELETE_ON_CLOSE, /* create_options, */
1374 NULL, /* smb2_create_blobs *blobs */
1378 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1379 printf("smb2cli_create %s\n", nt_errstr(status));
1383 status = smb2cli_create(cli3->conn, cli3->timeout, cli3->smb2.session,
1384 cli1->smb2.tcon, "multi-channel-invalid.txt",
1385 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1386 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1387 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1388 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1389 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1390 FILE_CREATE, /* create_disposition, */
1391 FILE_DELETE_ON_CLOSE, /* create_options, */
1392 NULL, /* smb2_create_blobs *blobs */
1396 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1397 printf("smb2cli_create %s\n", nt_errstr(status));
1401 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1406 SMB2_CAP_DFS, /* in_capabilities */
1408 0, /* in_previous_session_id */
1409 &in_blob); /* in_security_buffer */
1410 if (subreq == NULL) {
1411 printf("smb2cli_session_setup_send() returned NULL\n");
1415 ok = tevent_req_poll(subreq, ev);
1417 printf("tevent_req_poll() returned false\n");
1421 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1422 &recv_iov, &out_blob);
1423 if (!NT_STATUS_IS_OK(status)) {
1424 printf("smb2cli_session_setup_recv returned %s\n",
1429 status = smb2cli_close(cli3->conn, cli3->timeout, cli3->smb2.session,
1430 cli1->smb2.tcon, 0, fid_persistent, fid_volatile);
1431 if (!NT_STATUS_IS_OK(status)) {
1432 printf("smb2cli_close returned %s\n", nt_errstr(status));
1436 status = smb2cli_flush(cli3->conn, cli3->timeout, cli3->smb2.session,
1437 cli1->smb2.tcon, fid_persistent, fid_volatile);
1438 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
1439 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1443 status = smb2cli_flush(cli2->conn, cli2->timeout, cli2->smb2.session,
1444 cli1->smb2.tcon, fid_persistent, fid_volatile);
1445 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
1446 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1450 status = smb2cli_flush(cli1->conn, cli1->timeout, cli1->smb2.session,
1451 cli1->smb2.tcon, fid_persistent, fid_volatile);
1452 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
1453 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1460 bool run_smb2_session_reauth(int dummy)
1462 struct cli_state *cli;
1465 uint64_t fid_persistent, fid_volatile;
1466 uint64_t dir_persistent, dir_volatile;
1468 uint32_t dir_data_length;
1469 struct tevent_context *ev;
1470 struct tevent_req *subreq;
1471 DATA_BLOB in_blob = data_blob_null;
1473 DATA_BLOB in_input_buffer;
1474 DATA_BLOB out_output_buffer;
1475 uint8_t in_file_info_class;
1476 struct auth_generic_state *auth_generic_state;
1477 struct iovec *recv_iov;
1479 struct smbXcli_tcon *saved_tcon;
1481 printf("Starting SMB2-SESSION_REAUTH\n");
1483 if (!torture_init_connection(&cli)) {
1488 * PROTOCOL_SMB2_22 has a bug in win8pre0
1489 * it behaves like PROTOCOL_SMB2_02
1490 * and returns NT_STATUS_REQUEST_NOT_ACCEPTED,
1491 * while it allows it on PROTOCOL_SMB2_02.
1493 status = smbXcli_negprot(cli->conn, cli->timeout,
1494 PROTOCOL_SMB2_10, PROTOCOL_SMB2_10);
1495 if (!NT_STATUS_IS_OK(status)) {
1496 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
1500 status = cli_session_setup(cli, username,
1501 password, strlen(password),
1502 password, strlen(password),
1504 if (!NT_STATUS_IS_OK(status)) {
1505 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status));
1509 status = cli_tree_connect(cli, share, "?????", "", 0);
1510 if (!NT_STATUS_IS_OK(status)) {
1511 printf("cli_tree_connect returned %s\n", nt_errstr(status));
1515 status = smb2cli_create(cli->conn, cli->timeout, cli->smb2.session,
1516 cli->smb2.tcon, "session-reauth.txt",
1517 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1518 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1519 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1520 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1521 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1522 FILE_CREATE, /* create_disposition, */
1523 FILE_DELETE_ON_CLOSE, /* create_options, */
1524 NULL, /* smb2_create_blobs *blobs */
1528 if (!NT_STATUS_IS_OK(status)) {
1529 printf("smb2cli_create %s\n", nt_errstr(status));
1533 status = smb2cli_create(cli->conn, cli->timeout, cli->smb2.session,
1535 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1536 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1537 SEC_STD_SYNCHRONIZE|
1539 SEC_DIR_READ_ATTRIBUTE, /* desired_access, */
1540 0, /* file_attributes, */
1541 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1542 FILE_OPEN, /* create_disposition, */
1543 FILE_SYNCHRONOUS_IO_NONALERT|FILE_DIRECTORY_FILE, /* create_options, */
1544 NULL, /* smb2_create_blobs *blobs */
1548 if (!NT_STATUS_IS_OK(status)) {
1549 printf("smb2cli_create returned %s\n", nt_errstr(status));
1553 status = smb2cli_query_directory(
1554 cli->conn, cli->timeout, cli->smb2.session, cli->smb2.tcon,
1555 1, 0x3, 0, dir_persistent, dir_volatile,
1556 "session-reauth.txt", 0xffff,
1557 talloc_tos(), &dir_data, &dir_data_length);
1558 if (!NT_STATUS_IS_OK(status)) {
1559 printf("smb2cli_query_directory returned %s\n", nt_errstr(status));
1563 status = auth_generic_client_prepare(talloc_tos(), &auth_generic_state);
1564 if (!NT_STATUS_IS_OK(status)) {
1565 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status));
1569 gensec_want_feature(auth_generic_state->gensec_security,
1570 GENSEC_FEATURE_SESSION_KEY);
1571 status = auth_generic_set_username(auth_generic_state, username);
1572 if (!NT_STATUS_IS_OK(status)) {
1573 printf("auth_generic_set_username returned %s\n", nt_errstr(status));
1577 status = auth_generic_set_domain(auth_generic_state, workgroup);
1578 if (!NT_STATUS_IS_OK(status)) {
1579 printf("auth_generic_set_domain returned %s\n", nt_errstr(status));
1583 status = auth_generic_set_password(auth_generic_state, password);
1584 if (!NT_STATUS_IS_OK(status)) {
1585 printf("auth_generic_set_password returned %s\n", nt_errstr(status));
1589 status = auth_generic_client_start(auth_generic_state, GENSEC_OID_NTLMSSP);
1590 if (!NT_STATUS_IS_OK(status)) {
1591 printf("auth_generic_client_start returned %s\n", nt_errstr(status));
1595 ev = samba_tevent_context_init(talloc_tos());
1597 printf("samba_tevent_context_init() returned NULL\n");
1601 status = gensec_update(auth_generic_state->gensec_security,
1602 talloc_tos(), data_blob_null, &in_blob);
1603 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1604 printf("gensec_update returned %s\n", nt_errstr(status));
1608 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1613 SMB2_CAP_DFS, /* in_capabilities */
1615 0, /* in_previous_session_id */
1616 &in_blob); /* in_security_buffer */
1617 if (subreq == NULL) {
1618 printf("smb2cli_session_setup_send() returned NULL\n");
1622 ok = tevent_req_poll(subreq, ev);
1624 printf("tevent_req_poll() returned false\n");
1628 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1630 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1631 printf("smb2cli_session_setup_recv returned %s\n",
1636 status = gensec_update(auth_generic_state->gensec_security,
1637 talloc_tos(), out_blob, &in_blob);
1638 if (!NT_STATUS_IS_OK(status)) {
1639 printf("auth_generic_update returned %s\n", nt_errstr(status));
1643 status = smb2cli_flush(cli->conn, cli->timeout, cli->smb2.session,
1644 cli->smb2.tcon, fid_persistent, fid_volatile);
1645 if (!NT_STATUS_IS_OK(status)) {
1646 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1650 status = smb2cli_query_directory(
1651 cli->conn, cli->timeout, cli->smb2.session, cli->smb2.tcon,
1652 1, 0x3, 0, dir_persistent, dir_volatile,
1653 "session-reauth.txt", 0xffff,
1654 talloc_tos(), &dir_data, &dir_data_length);
1655 if (!NT_STATUS_IS_OK(status)) {
1656 printf("smb2cli_query_directory returned %s\n", nt_errstr(status));
1661 * query_info seems to be a path based operation on Windows...
1663 status = smb2cli_query_info(cli->conn,
1667 SMB2_GETINFO_SECURITY,
1668 0, /* in_file_info_class */
1669 1024, /* in_max_output_length */
1670 NULL, /* in_input_buffer */
1671 SECINFO_OWNER, /* in_additional_info */
1676 &out_output_buffer);
1677 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1678 printf("smb2cli_query_info (security) returned %s\n", nt_errstr(status));
1682 in_file_info_class = SMB_FILE_POSITION_INFORMATION - 1000;
1683 status = smb2cli_query_info(cli->conn,
1689 1024, /* in_max_output_length */
1690 NULL, /* in_input_buffer */
1691 0, /* in_additional_info */
1696 &out_output_buffer);
1697 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1698 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status));
1702 in_input_buffer = data_blob_talloc(talloc_tos(), NULL, 8);
1703 SBVAL(in_input_buffer.data, 0, 512);
1705 in_file_info_class = SMB_FILE_POSITION_INFORMATION - 1000;
1706 status = smb2cli_set_info(cli->conn,
1713 0, /* in_additional_info */
1716 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1717 printf("smb2cli_set_info (position) returned %s\n", nt_errstr(status));
1721 status = smb2cli_create(cli->conn, cli->timeout, cli->smb2.session,
1722 cli->smb2.tcon, "session-reauth-invalid.txt",
1723 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1724 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1725 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1726 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1727 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1728 FILE_CREATE, /* create_disposition, */
1729 FILE_DELETE_ON_CLOSE, /* create_options, */
1730 NULL, /* smb2_create_blobs *blobs */
1734 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1735 printf("smb2cli_create %s\n", nt_errstr(status));
1739 status = smb2cli_create(cli->conn, cli->timeout, cli->smb2.session,
1741 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1742 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1743 SEC_STD_SYNCHRONIZE|
1745 SEC_DIR_READ_ATTRIBUTE, /* desired_access, */
1746 0, /* file_attributes, */
1747 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1748 FILE_OPEN, /* create_disposition, */
1749 FILE_SYNCHRONOUS_IO_NONALERT|FILE_DIRECTORY_FILE, /* create_options, */
1750 NULL, /* smb2_create_blobs *blobs */
1754 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1755 printf("smb2cli_create returned %s\n", nt_errstr(status));
1759 saved_tid = smb2cli_tcon_current_id(cli->smb2.tcon);
1760 saved_tcon = cli->smb2.tcon;
1761 cli->smb2.tcon = smbXcli_tcon_create(cli);
1762 smb2cli_tcon_set_values(cli->smb2.tcon,
1767 0, /* capabilities */
1768 0 /* maximal_access */);
1769 status = cli_tree_connect(cli, share, "?????", "", 0);
1770 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1771 printf("cli_tree_connect returned %s\n", nt_errstr(status));
1774 talloc_free(cli->smb2.tcon);
1775 cli->smb2.tcon = saved_tcon;
1777 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1782 SMB2_CAP_DFS, /* in_capabilities */
1784 0, /* in_previous_session_id */
1785 &in_blob); /* in_security_buffer */
1786 if (subreq == NULL) {
1787 printf("smb2cli_session_setup_send() returned NULL\n");
1791 ok = tevent_req_poll(subreq, ev);
1793 printf("tevent_req_poll() returned false\n");
1797 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1798 &recv_iov, &out_blob);
1799 if (!NT_STATUS_IS_OK(status)) {
1800 printf("smb2cli_session_setup_recv returned %s\n",
1805 status = smb2cli_flush(cli->conn, cli->timeout, cli->smb2.session,
1806 cli->smb2.tcon, fid_persistent, fid_volatile);
1807 if (!NT_STATUS_IS_OK(status)) {
1808 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1812 status = smb2cli_query_info(cli->conn,
1816 SMB2_GETINFO_SECURITY,
1817 0, /* in_file_info_class */
1818 1024, /* in_max_output_length */
1819 NULL, /* in_input_buffer */
1820 SECINFO_OWNER, /* in_additional_info */
1825 &out_output_buffer);
1826 if (!NT_STATUS_IS_OK(status)) {
1827 printf("smb2cli_query_info (security) returned %s\n", nt_errstr(status));
1831 in_file_info_class = SMB_FILE_POSITION_INFORMATION - 1000;
1832 status = smb2cli_query_info(cli->conn,
1838 1024, /* in_max_output_length */
1839 NULL, /* in_input_buffer */
1840 0, /* in_additional_info */
1845 &out_output_buffer);
1846 if (!NT_STATUS_IS_OK(status)) {
1847 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status));
1851 in_input_buffer = data_blob_talloc(talloc_tos(), NULL, 8);
1852 SBVAL(in_input_buffer.data, 0, 512);
1854 in_file_info_class = SMB_FILE_POSITION_INFORMATION - 1000;
1855 status = smb2cli_set_info(cli->conn,
1862 0, /* in_additional_info */
1865 if (!NT_STATUS_IS_OK(status)) {
1866 printf("smb2cli_set_info (position) returned %s\n", nt_errstr(status));
1870 in_file_info_class = SMB_FILE_POSITION_INFORMATION - 1000;
1871 status = smb2cli_query_info(cli->conn,
1877 1024, /* in_max_output_length */
1878 NULL, /* in_input_buffer */
1879 0, /* in_additional_info */
1884 &out_output_buffer);
1885 if (!NT_STATUS_IS_OK(status)) {
1886 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status));
1890 status = smb2cli_close(cli->conn, cli->timeout, cli->smb2.session,
1891 cli->smb2.tcon, 0, fid_persistent, fid_volatile);
1892 if (!NT_STATUS_IS_OK(status)) {
1893 printf("smb2cli_close returned %s\n", nt_errstr(status));
1897 status = smb2cli_create(cli->conn, cli->timeout, cli->smb2.session,
1898 cli->smb2.tcon, "session-reauth.txt",
1899 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1900 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1901 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1902 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1903 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1904 FILE_CREATE, /* create_disposition, */
1905 FILE_DELETE_ON_CLOSE, /* create_options, */
1906 NULL, /* smb2_create_blobs *blobs */
1910 if (!NT_STATUS_IS_OK(status)) {
1911 printf("smb2cli_create %s\n", nt_errstr(status));
1915 status = smb2cli_query_directory(
1916 cli->conn, cli->timeout, cli->smb2.session, cli->smb2.tcon,
1917 1, 0x3, 0, dir_persistent, dir_volatile,
1918 "session-reauth.txt", 0xffff,
1919 talloc_tos(), &dir_data, &dir_data_length);
1920 if (!NT_STATUS_IS_OK(status)) {
1921 printf("smb2cli_query_directory returned %s\n", nt_errstr(status));
1925 status = smb2cli_close(cli->conn, cli->timeout, cli->smb2.session,
1926 cli->smb2.tcon, 0, dir_persistent, dir_volatile);
1927 if (!NT_STATUS_IS_OK(status)) {
1928 printf("smb2cli_close returned %s\n", nt_errstr(status));
1932 status = smb2cli_close(cli->conn, cli->timeout, cli->smb2.session,
1933 cli->smb2.tcon, 0, fid_persistent, fid_volatile);
1934 if (!NT_STATUS_IS_OK(status)) {
1935 printf("smb2cli_close returned %s\n", nt_errstr(status));
1939 saved_tid = smb2cli_tcon_current_id(cli->smb2.tcon);
1940 saved_tcon = cli->smb2.tcon;
1941 cli->smb2.tcon = smbXcli_tcon_create(cli);
1942 smb2cli_tcon_set_values(cli->smb2.tcon,
1947 0, /* capabilities */
1948 0 /* maximal_access */);
1949 status = cli_tree_connect(cli, share, "?????", "", 0);
1950 if (!NT_STATUS_IS_OK(status)) {
1951 printf("cli_tree_connect returned %s\n", nt_errstr(status));
1954 talloc_free(cli->smb2.tcon);
1955 cli->smb2.tcon = saved_tcon;