2 Unix SMB/CIFS implementation.
3 Initial test for the smb2 client lib
4 Copyright (C) Volker Lendecke 2011
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "torture/proto.h"
24 #include "../libcli/smb/smbXcli_base.h"
25 #include "libsmb/smb2cli.h"
26 #include "libcli/security/security.h"
27 #include "libsmb/proto.h"
28 #include "auth/gensec/gensec.h"
29 #include "auth_generic.h"
31 extern fstring host, workgroup, share, password, username, myname;
33 bool run_smb2_basic(int dummy)
35 struct cli_state *cli;
37 uint64_t fid_persistent, fid_volatile;
38 const char *hello = "Hello, world\n";
42 uint32_t dir_data_length;
43 uint32_t saved_tid = 0;
44 struct smbXcli_tcon *saved_tcon = NULL;
45 uint64_t saved_uid = 0;
47 printf("Starting SMB2-BASIC\n");
49 if (!torture_init_connection(&cli)) {
53 status = smbXcli_negprot(cli->conn, cli->timeout,
54 PROTOCOL_SMB2_02, PROTOCOL_SMB2_02);
55 if (!NT_STATUS_IS_OK(status)) {
56 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
60 status = cli_session_setup(cli, username,
61 password, strlen(password),
62 password, strlen(password),
64 if (!NT_STATUS_IS_OK(status)) {
65 printf("cli_session_setup returned %s\n", nt_errstr(status));
69 status = cli_tree_connect(cli, share, "?????", "", 0);
70 if (!NT_STATUS_IS_OK(status)) {
71 printf("cli_tree_connect returned %s\n", nt_errstr(status));
75 status = smb2cli_create(cli->conn, cli->timeout, cli->smb2.session,
76 cli->smb2.tcon, "smb2-basic.txt",
77 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
78 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
79 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
80 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
81 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
82 FILE_CREATE, /* create_disposition, */
83 FILE_DELETE_ON_CLOSE, /* create_options, */
84 NULL, /* smb2_create_blobs *blobs */
88 if (!NT_STATUS_IS_OK(status)) {
89 printf("smb2cli_create returned %s\n", nt_errstr(status));
93 status = smb2cli_write(cli->conn, cli->timeout, cli->smb2.session,
94 cli->smb2.tcon, strlen(hello), 0, fid_persistent,
95 fid_volatile, 0, 0, (const uint8_t *)hello, NULL);
96 if (!NT_STATUS_IS_OK(status)) {
97 printf("smb2cli_write returned %s\n", nt_errstr(status));
101 status = smb2cli_flush(cli->conn, cli->timeout, cli->smb2.session,
102 cli->smb2.tcon, fid_persistent, fid_volatile);
103 if (!NT_STATUS_IS_OK(status)) {
104 printf("smb2cli_flush returned %s\n", nt_errstr(status));
108 status = smb2cli_read(cli->conn, cli->timeout, cli->smb2.session,
109 cli->smb2.tcon, 0x10000, 0, fid_persistent,
111 talloc_tos(), &result, &nread);
112 if (!NT_STATUS_IS_OK(status)) {
113 printf("smb2cli_read returned %s\n", nt_errstr(status));
117 if (nread != strlen(hello)) {
118 printf("smb2cli_read returned %d bytes, expected %d\n",
119 (int)nread, (int)strlen(hello));
123 if (memcmp(hello, result, nread) != 0) {
124 printf("smb2cli_read returned '%s', expected '%s'\n",
129 status = smb2cli_close(cli->conn, cli->timeout, cli->smb2.session,
130 cli->smb2.tcon, 0, fid_persistent, fid_volatile);
131 if (!NT_STATUS_IS_OK(status)) {
132 printf("smb2cli_close returned %s\n", nt_errstr(status));
136 status = smb2cli_create(cli->conn, cli->timeout, cli->smb2.session,
138 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
139 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
142 SEC_DIR_READ_ATTRIBUTE, /* desired_access, */
143 0, /* file_attributes, */
144 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
145 FILE_OPEN, /* create_disposition, */
146 FILE_SYNCHRONOUS_IO_NONALERT|FILE_DIRECTORY_FILE, /* create_options, */
147 NULL, /* smb2_create_blobs *blobs */
151 if (!NT_STATUS_IS_OK(status)) {
152 printf("smb2cli_create returned %s\n", nt_errstr(status));
156 status = smb2cli_query_directory(
157 cli->conn, cli->timeout, cli->smb2.session, cli->smb2.tcon,
158 1, 0, 0, fid_persistent, fid_volatile, "*", 0xffff,
159 talloc_tos(), &dir_data, &dir_data_length);
161 if (!NT_STATUS_IS_OK(status)) {
162 printf("smb2cli_query_directory returned %s\n", nt_errstr(status));
166 status = smb2cli_close(cli->conn, cli->timeout, cli->smb2.session,
167 cli->smb2.tcon, 0, fid_persistent, fid_volatile);
168 if (!NT_STATUS_IS_OK(status)) {
169 printf("smb2cli_close returned %s\n", nt_errstr(status));
173 saved_tid = smb2cli_tcon_current_id(cli->smb2.tcon);
174 saved_tcon = cli->smb2.tcon;
175 cli->smb2.tcon = smbXcli_tcon_create(cli);
176 smb2cli_tcon_set_values(cli->smb2.tcon,
181 0, /* capabilities */
182 0 /* maximal_access */);
183 status = smb2cli_tdis(cli);
184 if (!NT_STATUS_IS_OK(status)) {
185 printf("smb2cli_tdis returned %s\n", nt_errstr(status));
188 talloc_free(cli->smb2.tcon);
189 cli->smb2.tcon = saved_tcon;
191 status = smb2cli_tdis(cli);
192 if (!NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED)) {
193 printf("2nd smb2cli_tdis returned %s\n", nt_errstr(status));
197 saved_uid = smb2cli_session_current_id(cli->smb2.session);
198 status = smb2cli_logoff(cli->conn, cli->timeout, cli->smb2.session);
199 if (!NT_STATUS_IS_OK(status)) {
200 printf("smb2cli_logoff returned %s\n", nt_errstr(status));
204 cli->smb2.session = smbXcli_session_create(cli, cli->conn);
205 if (cli->smb2.session == NULL) {
206 printf("smbXcli_session_create() returned NULL\n");
210 smb2cli_session_set_id_and_flags(cli->smb2.session, saved_uid, 0);
212 status = smb2cli_logoff(cli->conn, cli->timeout, cli->smb2.session);
213 if (!NT_STATUS_EQUAL(status, NT_STATUS_USER_SESSION_DELETED)) {
214 printf("2nd smb2cli_logoff returned %s\n", nt_errstr(status));
221 bool run_smb2_negprot(int dummy)
223 struct cli_state *cli;
225 enum protocol_types protocol;
226 const char *name = NULL;
228 printf("Starting SMB2-NEGPROT\n");
230 if (!torture_init_connection(&cli)) {
234 status = smbXcli_negprot(cli->conn, cli->timeout,
235 PROTOCOL_CORE, PROTOCOL_LATEST);
236 if (!NT_STATUS_IS_OK(status)) {
237 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
241 protocol = smbXcli_conn_protocol(cli->conn);
244 case PROTOCOL_SMB2_02:
247 case PROTOCOL_SMB2_10:
250 case PROTOCOL_SMB2_22:
253 case PROTOCOL_SMB2_24:
256 case PROTOCOL_SMB3_00:
264 printf("Server supports %s\n", name);
266 printf("Server DOES NOT support SMB2\n");
270 status = smbXcli_negprot(cli->conn, cli->timeout,
272 if (!NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_RESET) &&
273 !NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_DISCONNECTED) &&
274 !NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_ABORTED)) {
275 printf("2nd smbXcli_negprot should disconnect - returned %s\n",
280 if (smbXcli_conn_is_connected(cli->conn)) {
281 printf("2nd smbXcli_negprot should disconnect "
282 "- still connected\n");
289 bool run_smb2_session_reconnect(int dummy)
291 struct cli_state *cli1;
292 struct cli_state *cli2;
295 uint64_t fid_persistent, fid_volatile;
296 struct tevent_context *ev;
297 struct tevent_req *subreq;
298 DATA_BLOB in_blob = data_blob_null;
300 DATA_BLOB session_key;
301 struct auth_generic_state *auth_generic_state;
302 struct iovec *recv_iov;
303 const char *hello = "Hello, world\n";
307 printf("Starting SMB2-SESSION-RECONNECT\n");
309 if (!torture_init_connection(&cli1)) {
313 status = smbXcli_negprot(cli1->conn, cli1->timeout,
314 PROTOCOL_SMB2_02, PROTOCOL_LATEST);
315 if (!NT_STATUS_IS_OK(status)) {
316 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
320 status = cli_session_setup(cli1, username,
321 password, strlen(password),
322 password, strlen(password),
324 if (!NT_STATUS_IS_OK(status)) {
325 printf("cli_session_setup returned %s\n", nt_errstr(status));
329 status = cli_tree_connect(cli1, share, "?????", "", 0);
330 if (!NT_STATUS_IS_OK(status)) {
331 printf("cli_tree_connect returned %s\n", nt_errstr(status));
335 status = smb2cli_create(cli1->conn, cli1->timeout, cli1->smb2.session,
336 cli1->smb2.tcon, "session-reconnect.txt",
337 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
338 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
339 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
340 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
341 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
342 FILE_CREATE, /* create_disposition, */
343 FILE_DELETE_ON_CLOSE, /* create_options, */
344 NULL, /* smb2_create_blobs *blobs */
348 if (!NT_STATUS_IS_OK(status)) {
349 printf("smb2cli_create on cli1 %s\n", nt_errstr(status));
353 status = smb2cli_write(cli1->conn, cli1->timeout, cli1->smb2.session,
354 cli1->smb2.tcon, strlen(hello), 0, fid_persistent,
355 fid_volatile, 0, 0, (const uint8_t *)hello, NULL);
356 if (!NT_STATUS_IS_OK(status)) {
357 printf("smb2cli_write returned %s\n", nt_errstr(status));
361 status = smb2cli_flush(cli1->conn, cli1->timeout, cli1->smb2.session,
362 cli1->smb2.tcon, fid_persistent, fid_volatile);
363 if (!NT_STATUS_IS_OK(status)) {
364 printf("smb2cli_flush returned %s\n", nt_errstr(status));
368 status = smb2cli_read(cli1->conn, cli1->timeout, cli1->smb2.session,
369 cli1->smb2.tcon, 0x10000, 0, fid_persistent,
371 talloc_tos(), &result, &nread);
372 if (!NT_STATUS_IS_OK(status)) {
373 printf("smb2cli_read returned %s\n", nt_errstr(status));
377 if (nread != strlen(hello)) {
378 printf("smb2cli_read returned %d bytes, expected %d\n",
379 (int)nread, (int)strlen(hello));
383 if (memcmp(hello, result, nread) != 0) {
384 printf("smb2cli_read returned '%s', expected '%s'\n",
389 /* prepare second session */
391 if (!torture_init_connection(&cli2)) {
395 status = smbXcli_negprot(cli2->conn, cli2->timeout,
396 PROTOCOL_SMB2_02, PROTOCOL_LATEST);
397 if (!NT_STATUS_IS_OK(status)) {
398 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
402 status = auth_generic_client_prepare(talloc_tos(), &auth_generic_state);
403 if (!NT_STATUS_IS_OK(status)) {
404 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status));
408 gensec_want_feature(auth_generic_state->gensec_security,
409 GENSEC_FEATURE_SESSION_KEY);
410 status = auth_generic_set_username(auth_generic_state, username);
411 if (!NT_STATUS_IS_OK(status)) {
412 printf("auth_generic_set_username returned %s\n", nt_errstr(status));
416 status = auth_generic_set_domain(auth_generic_state, workgroup);
417 if (!NT_STATUS_IS_OK(status)) {
418 printf("auth_generic_set_domain returned %s\n", nt_errstr(status));
422 status = auth_generic_set_password(auth_generic_state, password);
423 if (!NT_STATUS_IS_OK(status)) {
424 printf("auth_generic_set_password returned %s\n", nt_errstr(status));
428 status = auth_generic_client_start(auth_generic_state, GENSEC_OID_NTLMSSP);
429 if (!NT_STATUS_IS_OK(status)) {
430 printf("auth_generic_client_start returned %s\n", nt_errstr(status));
434 ev = samba_tevent_context_init(talloc_tos());
436 printf("samba_tevent_context_init() returned NULL\n");
440 status = gensec_update(auth_generic_state->gensec_security, talloc_tos(), ev, data_blob_null, &in_blob);
441 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
442 printf("gensec_update returned %s\n", nt_errstr(status));
446 cli2->smb2.session = smbXcli_session_create(cli2, cli2->conn);
448 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
453 SMB2_CAP_DFS, /* in_capabilities */
455 /* in_previous_session_id: */
456 smb2cli_session_current_id(cli1->smb2.session),
457 &in_blob); /* in_security_buffer */
458 if (subreq == NULL) {
459 printf("smb2cli_session_setup_send() returned NULL\n");
463 ok = tevent_req_poll(subreq, ev);
465 printf("tevent_req_poll() returned false\n");
469 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
471 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
472 printf("smb2cli_session_setup_recv returned %s\n",
477 status = gensec_update(auth_generic_state->gensec_security, talloc_tos(), ev, out_blob, &in_blob);
478 if (!NT_STATUS_IS_OK(status)) {
479 printf("auth_generic_update returned %s\n", nt_errstr(status));
483 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
488 SMB2_CAP_DFS, /* in_capabilities */
490 /* in_previous_session_id: */
491 smb2cli_session_current_id(cli1->smb2.session),
492 &in_blob); /* in_security_buffer */
493 if (subreq == NULL) {
494 printf("smb2cli_session_setup_send() returned NULL\n");
498 ok = tevent_req_poll(subreq, ev);
500 printf("tevent_req_poll() returned false\n");
504 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
505 &recv_iov, &out_blob);
506 if (!NT_STATUS_IS_OK(status)) {
507 printf("smb2cli_session_setup_recv returned %s\n",
512 status = gensec_session_key(auth_generic_state->gensec_security, talloc_tos(),
514 if (!NT_STATUS_IS_OK(status)) {
515 printf("gensec_session_key returned %s\n",
520 /* check file operation on the old client */
522 status = smb2cli_flush(cli1->conn, cli1->timeout, cli1->smb2.session,
523 cli1->smb2.tcon, fid_persistent, fid_volatile);
524 if (!NT_STATUS_EQUAL(status, NT_STATUS_USER_SESSION_DELETED)) {
525 printf("smb2cli_flush returned %s\n", nt_errstr(status));
529 status = cli_tree_connect(cli1, share, "?????", "", 0);
530 if (!NT_STATUS_EQUAL(status, NT_STATUS_USER_SESSION_DELETED)) {
531 printf("cli_tree_connect returned %s\n", nt_errstr(status));
536 * checking file operations without signing.
537 * on w2k8r2 at least, flush, read and write also work the same way,
538 * while create gives ACCESS_DENIED without signing
540 status = smb2cli_flush(cli2->conn, cli2->timeout, cli2->smb2.session,
541 cli2->smb2.tcon, fid_persistent, fid_volatile);
542 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED) &&
543 !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED))
545 printf("smb2cli_flush returned %s\n", nt_errstr(status));
549 status = smb2cli_write(cli2->conn, cli2->timeout, cli2->smb2.session,
550 cli2->smb2.tcon, strlen(hello), 0, fid_persistent,
551 fid_volatile, 0, 0, (const uint8_t *)hello, NULL);
552 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED) &&
553 !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED))
555 printf("smb2cli_write returned %s\n", nt_errstr(status));
559 status = smb2cli_read(cli2->conn, cli2->timeout, cli2->smb2.session,
560 cli2->smb2.tcon, 0x10000, 0, fid_persistent,
562 talloc_tos(), &result, &nread);
563 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED) &&
564 !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED))
566 printf("smb2cli_read returned %s\n", nt_errstr(status));
570 status = smb2cli_create(cli2->conn, cli2->timeout, cli2->smb2.session,
571 cli2->smb2.tcon, "session-reconnect.txt",
572 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
573 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
574 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
575 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
576 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
577 FILE_CREATE, /* create_disposition, */
578 FILE_DELETE_ON_CLOSE, /* create_options, */
579 NULL, /* smb2_create_blobs *blobs */
583 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED) &&
584 !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED)) {
585 printf("smb2cli_create on cli2 %s\n", nt_errstr(status));
589 /* now grab the session key and try with signing */
591 status = smb2cli_session_set_session_key(cli2->smb2.session,
594 if (!NT_STATUS_IS_OK(status)) {
595 printf("smb2cli_session_set_session_key %s\n", nt_errstr(status));
599 /* the tid seems to be irrelevant at this stage */
601 status = smb2cli_flush(cli2->conn, cli2->timeout, cli2->smb2.session,
602 cli1->smb2.tcon, fid_persistent, fid_volatile);
603 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED) &&
604 !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED))
606 printf("smb2cli_flush returned %s\n", nt_errstr(status));
610 status = smb2cli_write(cli2->conn, cli2->timeout, cli2->smb2.session,
611 cli1->smb2.tcon, strlen(hello), 0, fid_persistent,
612 fid_volatile, 0, 0, (const uint8_t *)hello, NULL);
613 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED) &&
614 !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED))
616 printf("smb2cli_write returned %s\n", nt_errstr(status));
620 status = smb2cli_read(cli2->conn, cli2->timeout, cli2->smb2.session,
621 cli1->smb2.tcon, 0x10000, 0, fid_persistent,
623 talloc_tos(), &result, &nread);
624 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED) &&
625 !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED))
627 printf("smb2cli_read returned %s\n", nt_errstr(status));
631 status = smb2cli_create(cli2->conn, cli2->timeout, cli2->smb2.session,
632 cli1->smb2.tcon, "session-reconnect.txt",
633 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
634 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
635 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
636 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
637 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
638 FILE_CREATE, /* create_disposition, */
639 FILE_DELETE_ON_CLOSE, /* create_options, */
640 NULL, /* smb2_create_blobs *blobs */
644 if (!NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED) &&
645 !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED))
647 printf("smb2cli_create on cli2 %s\n", nt_errstr(status));
651 /* now do a new tcon and test file calls again */
653 status = cli_tree_connect(cli2, share, "?????", "", 0);
654 if (!NT_STATUS_IS_OK(status)) {
655 printf("cli_tree_connect returned %s\n", nt_errstr(status));
659 status = smb2cli_create(cli2->conn, cli2->timeout, cli2->smb2.session,
660 cli2->smb2.tcon, "session-reconnect.txt",
661 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
662 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
663 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
664 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
665 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
666 FILE_CREATE, /* create_disposition, */
667 FILE_DELETE_ON_CLOSE, /* create_options, */
668 NULL, /* smb2_create_blobs *blobs */
672 if (!NT_STATUS_IS_OK(status)) {
673 printf("smb2cli_create on cli2 %s\n", nt_errstr(status));
677 status = smb2cli_write(cli2->conn, cli2->timeout, cli2->smb2.session,
678 cli2->smb2.tcon, strlen(hello), 0, fid_persistent,
679 fid_volatile, 0, 0, (const uint8_t *)hello, NULL);
680 if (!NT_STATUS_IS_OK(status)) {
681 printf("smb2cli_write returned %s\n", nt_errstr(status));
685 status = smb2cli_flush(cli2->conn, cli2->timeout, cli2->smb2.session,
686 cli2->smb2.tcon, fid_persistent, fid_volatile);
687 if (!NT_STATUS_IS_OK(status)) {
688 printf("smb2cli_flush returned %s\n", nt_errstr(status));
692 status = smb2cli_read(cli2->conn, cli2->timeout, cli2->smb2.session,
693 cli2->smb2.tcon, 0x10000, 0, fid_persistent,
695 talloc_tos(), &result, &nread);
696 if (!NT_STATUS_IS_OK(status)) {
697 printf("smb2cli_read returned %s\n", nt_errstr(status));
701 if (nread != strlen(hello)) {
702 printf("smb2cli_read returned %d bytes, expected %d\n",
703 (int)nread, (int)strlen(hello));
707 if (memcmp(hello, result, nread) != 0) {
708 printf("smb2cli_read returned '%s', expected '%s'\n",
716 bool run_smb2_tcon_dependence(int dummy)
718 struct cli_state *cli;
720 uint64_t fid_persistent, fid_volatile;
721 const char *hello = "Hello, world\n";
724 struct smbXcli_tcon *tcon2;
727 printf("Starting SMB2-TCON-DEPENDENCE\n");
729 if (!torture_init_connection(&cli)) {
733 status = smbXcli_negprot(cli->conn, cli->timeout,
734 PROTOCOL_SMB2_02, PROTOCOL_LATEST);
735 if (!NT_STATUS_IS_OK(status)) {
736 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
740 status = cli_session_setup(cli, username,
741 password, strlen(password),
742 password, strlen(password),
744 if (!NT_STATUS_IS_OK(status)) {
745 printf("cli_session_setup returned %s\n", nt_errstr(status));
749 status = cli_tree_connect(cli, share, "?????", "", 0);
750 if (!NT_STATUS_IS_OK(status)) {
751 printf("cli_tree_connect returned %s\n", nt_errstr(status));
755 status = smb2cli_create(cli->conn, cli->timeout, cli->smb2.session,
756 cli->smb2.tcon, "tcon_depedence.txt",
757 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
758 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
759 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
760 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
761 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
762 FILE_CREATE, /* create_disposition, */
763 FILE_DELETE_ON_CLOSE, /* create_options, */
764 NULL, /* smb2_create_blobs *blobs */
768 if (!NT_STATUS_IS_OK(status)) {
769 printf("smb2cli_create on cli %s\n", nt_errstr(status));
773 status = smb2cli_write(cli->conn, cli->timeout, cli->smb2.session,
774 cli->smb2.tcon, strlen(hello), 0, fid_persistent,
775 fid_volatile, 0, 0, (const uint8_t *)hello, NULL);
776 if (!NT_STATUS_IS_OK(status)) {
777 printf("smb2cli_write returned %s\n", nt_errstr(status));
781 status = smb2cli_flush(cli->conn, cli->timeout, cli->smb2.session,
782 cli->smb2.tcon, fid_persistent, fid_volatile);
783 if (!NT_STATUS_IS_OK(status)) {
784 printf("smb2cli_flush returned %s\n", nt_errstr(status));
788 status = smb2cli_read(cli->conn, cli->timeout, cli->smb2.session,
789 cli->smb2.tcon, 0x10000, 0, fid_persistent,
791 talloc_tos(), &result, &nread);
792 if (!NT_STATUS_IS_OK(status)) {
793 printf("smb2cli_read returned %s\n", nt_errstr(status));
797 if (nread != strlen(hello)) {
798 printf("smb2cli_read returned %d bytes, expected %d\n",
799 (int)nread, (int)strlen(hello));
803 if (memcmp(hello, result, nread) != 0) {
804 printf("smb2cli_read returned '%s', expected '%s'\n",
809 /* check behaviour with wrong tid... */
811 tcon2 = smbXcli_tcon_create(cli);
812 tcon2_id = smb2cli_tcon_current_id(cli->smb2.tcon);
814 smb2cli_tcon_set_values(tcon2,
819 0, /* capabilities */
820 0 /* maximal_access */);
822 status = smb2cli_read(cli->conn, cli->timeout, cli->smb2.session,
823 tcon2, 0x10000, 0, fid_persistent,
825 talloc_tos(), &result, &nread);
826 if (!NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED)) {
827 printf("smb2cli_read returned %s\n", nt_errstr(status));
836 bool run_smb2_multi_channel(int dummy)
838 struct cli_state *cli1;
839 struct cli_state *cli2;
840 struct cli_state *cli3;
843 uint64_t fid_persistent, fid_volatile;
844 struct tevent_context *ev;
845 struct tevent_req *subreq;
846 DATA_BLOB in_blob = data_blob_null;
848 DATA_BLOB channel_session_key;
849 struct auth_generic_state *auth_generic_state;
850 struct iovec *recv_iov;
851 const char *hello = "Hello, world\n";
855 printf("Starting SMB2-MULTI-CHANNEL\n");
857 if (!torture_init_connection(&cli1)) {
861 if (!torture_init_connection(&cli2)) {
865 if (!torture_init_connection(&cli3)) {
869 status = smbXcli_negprot(cli1->conn, cli1->timeout,
870 PROTOCOL_SMB2_22, PROTOCOL_LATEST);
871 if (!NT_STATUS_IS_OK(status)) {
872 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
876 status = smbXcli_negprot(cli2->conn, cli2->timeout,
877 PROTOCOL_SMB2_22, PROTOCOL_LATEST);
878 if (!NT_STATUS_IS_OK(status)) {
879 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
883 status = smbXcli_negprot(cli3->conn, cli3->timeout,
884 PROTOCOL_SMB2_22, PROTOCOL_LATEST);
885 if (!NT_STATUS_IS_OK(status)) {
886 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
890 status = cli_session_setup(cli1, username,
891 password, strlen(password),
892 password, strlen(password),
894 if (!NT_STATUS_IS_OK(status)) {
895 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status));
899 status = cli_tree_connect(cli1, share, "?????", "", 0);
900 if (!NT_STATUS_IS_OK(status)) {
901 printf("cli_tree_connect returned %s\n", nt_errstr(status));
905 status = smb2cli_session_create_channel(cli2,
908 &cli2->smb2.session);
909 if (!NT_STATUS_IS_OK(status)) {
910 printf("smb2cli_session_create_channel returned %s\n",
915 status = auth_generic_client_prepare(talloc_tos(), &auth_generic_state);
916 if (!NT_STATUS_IS_OK(status)) {
917 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status));
921 gensec_want_feature(auth_generic_state->gensec_security,
922 GENSEC_FEATURE_SESSION_KEY);
923 status = auth_generic_set_username(auth_generic_state, username);
924 if (!NT_STATUS_IS_OK(status)) {
925 printf("auth_generic_set_username returned %s\n", nt_errstr(status));
929 status = auth_generic_set_domain(auth_generic_state, workgroup);
930 if (!NT_STATUS_IS_OK(status)) {
931 printf("auth_generic_set_domain returned %s\n", nt_errstr(status));
935 status = auth_generic_set_password(auth_generic_state, password);
936 if (!NT_STATUS_IS_OK(status)) {
937 printf("auth_generic_set_password returned %s\n", nt_errstr(status));
941 status = auth_generic_client_start(auth_generic_state, GENSEC_OID_NTLMSSP);
942 if (!NT_STATUS_IS_OK(status)) {
943 printf("auth_generic_client_start returned %s\n", nt_errstr(status));
947 ev = samba_tevent_context_init(talloc_tos());
949 printf("samba_tevent_context_init() returned NULL\n");
953 status = gensec_update(auth_generic_state->gensec_security, talloc_tos(), ev, data_blob_null, &in_blob);
954 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
955 printf("gensec_update returned %s\n", nt_errstr(status));
959 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
964 SMB2_CAP_DFS, /* in_capabilities */
966 0, /* in_previous_session_id */
967 &in_blob); /* in_security_buffer */
968 if (subreq == NULL) {
969 printf("smb2cli_session_setup_send() returned NULL\n");
973 ok = tevent_req_poll(subreq, ev);
975 printf("tevent_req_poll() returned false\n");
979 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
981 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
982 printf("smb2cli_session_setup_recv returned %s\n",
987 status = gensec_update(auth_generic_state->gensec_security, talloc_tos(), ev, out_blob, &in_blob);
988 if (!NT_STATUS_IS_OK(status)) {
989 printf("auth_generic_update returned %s\n", nt_errstr(status));
993 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
998 SMB2_CAP_DFS, /* in_capabilities */
1000 0, /* in_previous_session_id */
1001 &in_blob); /* in_security_buffer */
1002 if (subreq == NULL) {
1003 printf("smb2cli_session_setup_send() returned NULL\n");
1007 ok = tevent_req_poll(subreq, ev);
1009 printf("tevent_req_poll() returned false\n");
1013 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1014 &recv_iov, &out_blob);
1015 if (!NT_STATUS_IS_OK(status)) {
1016 printf("smb2cli_session_setup_recv returned %s\n",
1021 status = gensec_session_key(auth_generic_state->gensec_security, talloc_tos(),
1022 &channel_session_key);
1023 if (!NT_STATUS_IS_OK(status)) {
1024 printf("gensec_session_key returned %s\n",
1029 status = smb2cli_session_set_channel_key(cli2->smb2.session,
1030 channel_session_key,
1032 if (!NT_STATUS_IS_OK(status)) {
1033 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status));
1037 status = smb2cli_session_create_channel(cli3,
1040 &cli3->smb2.session);
1041 if (!NT_STATUS_IS_OK(status)) {
1042 printf("smb2cli_session_create_channel returned %s\n",
1047 status = auth_generic_client_prepare(talloc_tos(), &auth_generic_state);
1048 if (!NT_STATUS_IS_OK(status)) {
1049 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status));
1053 gensec_want_feature(auth_generic_state->gensec_security,
1054 GENSEC_FEATURE_SESSION_KEY);
1055 status = auth_generic_set_username(auth_generic_state, username);
1056 if (!NT_STATUS_IS_OK(status)) {
1057 printf("auth_generic_set_username returned %s\n", nt_errstr(status));
1061 status = auth_generic_set_domain(auth_generic_state, workgroup);
1062 if (!NT_STATUS_IS_OK(status)) {
1063 printf("auth_generic_set_domain returned %s\n", nt_errstr(status));
1067 status = auth_generic_set_password(auth_generic_state, password);
1068 if (!NT_STATUS_IS_OK(status)) {
1069 printf("auth_generic_set_password returned %s\n", nt_errstr(status));
1073 status = auth_generic_client_start(auth_generic_state, GENSEC_OID_NTLMSSP);
1074 if (!NT_STATUS_IS_OK(status)) {
1075 printf("auth_generic_client_start returned %s\n", nt_errstr(status));
1079 status = gensec_update(auth_generic_state->gensec_security, talloc_tos(), ev, data_blob_null, &in_blob);
1080 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1081 printf("gensec_update returned %s\n", nt_errstr(status));
1085 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1089 0x01, /* in_flags */
1090 SMB2_CAP_DFS, /* in_capabilities */
1092 0, /* in_previous_session_id */
1093 &in_blob); /* in_security_buffer */
1094 if (subreq == NULL) {
1095 printf("smb2cli_session_setup_send() returned NULL\n");
1099 ok = tevent_req_poll(subreq, ev);
1101 printf("tevent_req_poll() returned false\n");
1105 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1107 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1108 printf("smb2cli_session_setup_recv returned %s\n",
1113 status = gensec_update(auth_generic_state->gensec_security, talloc_tos(), ev, out_blob, &in_blob);
1114 if (!NT_STATUS_IS_OK(status)) {
1115 printf("auth_generic_update returned %s\n", nt_errstr(status));
1119 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1123 0x01, /* in_flags */
1124 SMB2_CAP_DFS, /* in_capabilities */
1126 0, /* in_previous_session_id */
1127 &in_blob); /* in_security_buffer */
1128 if (subreq == NULL) {
1129 printf("smb2cli_session_setup_send() returned NULL\n");
1133 ok = tevent_req_poll(subreq, ev);
1135 printf("tevent_req_poll() returned false\n");
1139 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1140 &recv_iov, &out_blob);
1141 if (!NT_STATUS_IS_OK(status)) {
1142 printf("smb2cli_session_setup_recv returned %s\n",
1147 status = gensec_session_key(auth_generic_state->gensec_security, talloc_tos(),
1148 &channel_session_key);
1149 if (!NT_STATUS_IS_OK(status)) {
1150 printf("gensec_session_key returned %s\n",
1155 status = smb2cli_session_set_channel_key(cli3->smb2.session,
1156 channel_session_key,
1158 if (!NT_STATUS_IS_OK(status)) {
1159 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status));
1163 status = smb2cli_create(cli2->conn, cli2->timeout, cli2->smb2.session,
1164 cli1->smb2.tcon, "multi-channel.txt",
1165 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1166 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1167 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1168 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1169 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1170 FILE_CREATE, /* create_disposition, */
1171 FILE_DELETE_ON_CLOSE, /* create_options, */
1172 NULL, /* smb2_create_blobs *blobs */
1176 if (!NT_STATUS_IS_OK(status)) {
1177 printf("smb2cli_create on cli2 %s\n", nt_errstr(status));
1181 status = smb2cli_write(cli1->conn, cli1->timeout, cli1->smb2.session,
1182 cli1->smb2.tcon, strlen(hello), 0, fid_persistent,
1183 fid_volatile, 0, 0, (const uint8_t *)hello, NULL);
1184 if (!NT_STATUS_IS_OK(status)) {
1185 printf("smb2cli_write returned %s\n", nt_errstr(status));
1189 status = smb2cli_flush(cli2->conn, cli2->timeout, cli2->smb2.session,
1190 cli1->smb2.tcon, fid_persistent, fid_volatile);
1191 if (!NT_STATUS_IS_OK(status)) {
1192 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1196 status = smb2cli_flush(cli1->conn, cli1->timeout, cli1->smb2.session,
1197 cli1->smb2.tcon, fid_persistent, fid_volatile);
1198 if (!NT_STATUS_IS_OK(status)) {
1199 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1203 status = smb2cli_flush(cli3->conn, cli3->timeout, cli3->smb2.session,
1204 cli1->smb2.tcon, fid_persistent, fid_volatile);
1205 if (!NT_STATUS_IS_OK(status)) {
1206 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1210 status = smb2cli_read(cli2->conn, cli2->timeout, cli2->smb2.session,
1211 cli1->smb2.tcon, 0x10000, 0, fid_persistent,
1213 talloc_tos(), &result, &nread);
1214 if (!NT_STATUS_IS_OK(status)) {
1215 printf("smb2cli_read returned %s\n", nt_errstr(status));
1219 if (nread != strlen(hello)) {
1220 printf("smb2cli_read returned %d bytes, expected %d\n",
1221 (int)nread, (int)strlen(hello));
1225 if (memcmp(hello, result, nread) != 0) {
1226 printf("smb2cli_read returned '%s', expected '%s'\n",
1231 status = auth_generic_client_prepare(talloc_tos(), &auth_generic_state);
1232 if (!NT_STATUS_IS_OK(status)) {
1233 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status));
1237 gensec_want_feature(auth_generic_state->gensec_security,
1238 GENSEC_FEATURE_SESSION_KEY);
1239 status = auth_generic_set_username(auth_generic_state, username);
1240 if (!NT_STATUS_IS_OK(status)) {
1241 printf("auth_generic_set_username returned %s\n", nt_errstr(status));
1245 status = auth_generic_set_domain(auth_generic_state, workgroup);
1246 if (!NT_STATUS_IS_OK(status)) {
1247 printf("auth_generic_set_domain returned %s\n", nt_errstr(status));
1251 status = auth_generic_set_password(auth_generic_state, password);
1252 if (!NT_STATUS_IS_OK(status)) {
1253 printf("auth_generic_set_password returned %s\n", nt_errstr(status));
1257 status = auth_generic_client_start(auth_generic_state, GENSEC_OID_NTLMSSP);
1258 if (!NT_STATUS_IS_OK(status)) {
1259 printf("auth_generic_client_start returned %s\n", nt_errstr(status));
1263 status = gensec_update(auth_generic_state->gensec_security, talloc_tos(), ev, data_blob_null, &in_blob);
1264 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1265 printf("gensec_update returned %s\n", nt_errstr(status));
1269 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1274 SMB2_CAP_DFS, /* in_capabilities */
1276 0, /* in_previous_session_id */
1277 &in_blob); /* in_security_buffer */
1278 if (subreq == NULL) {
1279 printf("smb2cli_session_setup_send() returned NULL\n");
1283 ok = tevent_req_poll(subreq, ev);
1285 printf("tevent_req_poll() returned false\n");
1289 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1291 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1292 printf("smb2cli_session_setup_recv returned %s\n",
1297 status = gensec_update(auth_generic_state->gensec_security, talloc_tos(), ev, out_blob, &in_blob);
1298 if (!NT_STATUS_IS_OK(status)) {
1299 printf("auth_generic_update returned %s\n", nt_errstr(status));
1303 status = smb2cli_flush(cli1->conn, cli1->timeout, cli1->smb2.session,
1304 cli1->smb2.tcon, fid_persistent, fid_volatile);
1305 if (!NT_STATUS_IS_OK(status)) {
1306 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1310 status = smb2cli_flush(cli2->conn, cli2->timeout, cli2->smb2.session,
1311 cli1->smb2.tcon, fid_persistent, fid_volatile);
1312 if (!NT_STATUS_IS_OK(status)) {
1313 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1317 status = smb2cli_flush(cli3->conn, cli3->timeout, cli3->smb2.session,
1318 cli1->smb2.tcon, fid_persistent, fid_volatile);
1319 if (!NT_STATUS_IS_OK(status)) {
1320 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1324 status = smb2cli_create(cli1->conn, cli1->timeout, cli1->smb2.session,
1325 cli1->smb2.tcon, "multi-channel-invalid.txt",
1326 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1327 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1328 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1329 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1330 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1331 FILE_CREATE, /* create_disposition, */
1332 FILE_DELETE_ON_CLOSE, /* create_options, */
1333 NULL, /* smb2_create_blobs *blobs */
1337 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1338 printf("smb2cli_create %s\n", nt_errstr(status));
1342 status = smb2cli_create(cli2->conn, cli2->timeout, cli2->smb2.session,
1343 cli1->smb2.tcon, "multi-channel-invalid.txt",
1344 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1345 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1346 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1347 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1348 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1349 FILE_CREATE, /* create_disposition, */
1350 FILE_DELETE_ON_CLOSE, /* create_options, */
1351 NULL, /* smb2_create_blobs *blobs */
1355 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1356 printf("smb2cli_create %s\n", nt_errstr(status));
1360 status = smb2cli_create(cli3->conn, cli3->timeout, cli3->smb2.session,
1361 cli1->smb2.tcon, "multi-channel-invalid.txt",
1362 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1363 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1364 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1365 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1366 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1367 FILE_CREATE, /* create_disposition, */
1368 FILE_DELETE_ON_CLOSE, /* create_options, */
1369 NULL, /* smb2_create_blobs *blobs */
1373 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1374 printf("smb2cli_create %s\n", nt_errstr(status));
1378 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1383 SMB2_CAP_DFS, /* in_capabilities */
1385 0, /* in_previous_session_id */
1386 &in_blob); /* in_security_buffer */
1387 if (subreq == NULL) {
1388 printf("smb2cli_session_setup_send() returned NULL\n");
1392 ok = tevent_req_poll(subreq, ev);
1394 printf("tevent_req_poll() returned false\n");
1398 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1399 &recv_iov, &out_blob);
1400 if (!NT_STATUS_IS_OK(status)) {
1401 printf("smb2cli_session_setup_recv returned %s\n",
1406 status = smb2cli_close(cli3->conn, cli3->timeout, cli3->smb2.session,
1407 cli1->smb2.tcon, 0, fid_persistent, fid_volatile);
1408 if (!NT_STATUS_IS_OK(status)) {
1409 printf("smb2cli_close returned %s\n", nt_errstr(status));
1413 status = smb2cli_flush(cli3->conn, cli3->timeout, cli3->smb2.session,
1414 cli1->smb2.tcon, fid_persistent, fid_volatile);
1415 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
1416 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1420 status = smb2cli_flush(cli2->conn, cli2->timeout, cli2->smb2.session,
1421 cli1->smb2.tcon, fid_persistent, fid_volatile);
1422 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
1423 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1427 status = smb2cli_flush(cli1->conn, cli1->timeout, cli1->smb2.session,
1428 cli1->smb2.tcon, fid_persistent, fid_volatile);
1429 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
1430 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1437 bool run_smb2_session_reauth(int dummy)
1439 struct cli_state *cli;
1442 uint64_t fid_persistent, fid_volatile;
1443 uint64_t dir_persistent, dir_volatile;
1445 uint32_t dir_data_length;
1446 struct tevent_context *ev;
1447 struct tevent_req *subreq;
1448 DATA_BLOB in_blob = data_blob_null;
1450 DATA_BLOB in_input_buffer;
1451 DATA_BLOB out_output_buffer;
1452 uint8_t in_file_info_class;
1453 struct auth_generic_state *auth_generic_state;
1454 struct iovec *recv_iov;
1456 struct smbXcli_tcon *saved_tcon;
1458 printf("Starting SMB2-SESSION_REAUTH\n");
1460 if (!torture_init_connection(&cli)) {
1465 * PROTOCOL_SMB2_22 has a bug in win8pre0
1466 * it behaves like PROTOCOL_SMB2_02
1467 * and returns NT_STATUS_REQUEST_NOT_ACCEPTED,
1468 * while it allows it on PROTOCOL_SMB2_02.
1470 status = smbXcli_negprot(cli->conn, cli->timeout,
1471 PROTOCOL_SMB2_10, PROTOCOL_SMB2_10);
1472 if (!NT_STATUS_IS_OK(status)) {
1473 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
1477 status = cli_session_setup(cli, username,
1478 password, strlen(password),
1479 password, strlen(password),
1481 if (!NT_STATUS_IS_OK(status)) {
1482 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status));
1486 status = cli_tree_connect(cli, share, "?????", "", 0);
1487 if (!NT_STATUS_IS_OK(status)) {
1488 printf("cli_tree_connect returned %s\n", nt_errstr(status));
1492 status = smb2cli_create(cli->conn, cli->timeout, cli->smb2.session,
1493 cli->smb2.tcon, "session-reauth.txt",
1494 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1495 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1496 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1497 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1498 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1499 FILE_CREATE, /* create_disposition, */
1500 FILE_DELETE_ON_CLOSE, /* create_options, */
1501 NULL, /* smb2_create_blobs *blobs */
1505 if (!NT_STATUS_IS_OK(status)) {
1506 printf("smb2cli_create %s\n", nt_errstr(status));
1510 status = smb2cli_create(cli->conn, cli->timeout, cli->smb2.session,
1512 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1513 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1514 SEC_STD_SYNCHRONIZE|
1516 SEC_DIR_READ_ATTRIBUTE, /* desired_access, */
1517 0, /* file_attributes, */
1518 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1519 FILE_OPEN, /* create_disposition, */
1520 FILE_SYNCHRONOUS_IO_NONALERT|FILE_DIRECTORY_FILE, /* create_options, */
1521 NULL, /* smb2_create_blobs *blobs */
1525 if (!NT_STATUS_IS_OK(status)) {
1526 printf("smb2cli_create returned %s\n", nt_errstr(status));
1530 status = smb2cli_query_directory(
1531 cli->conn, cli->timeout, cli->smb2.session, cli->smb2.tcon,
1532 1, 0x3, 0, dir_persistent, dir_volatile,
1533 "session-reauth.txt", 0xffff,
1534 talloc_tos(), &dir_data, &dir_data_length);
1535 if (!NT_STATUS_IS_OK(status)) {
1536 printf("smb2cli_query_directory returned %s\n", nt_errstr(status));
1540 status = auth_generic_client_prepare(talloc_tos(), &auth_generic_state);
1541 if (!NT_STATUS_IS_OK(status)) {
1542 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status));
1546 gensec_want_feature(auth_generic_state->gensec_security,
1547 GENSEC_FEATURE_SESSION_KEY);
1548 status = auth_generic_set_username(auth_generic_state, username);
1549 if (!NT_STATUS_IS_OK(status)) {
1550 printf("auth_generic_set_username returned %s\n", nt_errstr(status));
1554 status = auth_generic_set_domain(auth_generic_state, workgroup);
1555 if (!NT_STATUS_IS_OK(status)) {
1556 printf("auth_generic_set_domain returned %s\n", nt_errstr(status));
1560 status = auth_generic_set_password(auth_generic_state, password);
1561 if (!NT_STATUS_IS_OK(status)) {
1562 printf("auth_generic_set_password returned %s\n", nt_errstr(status));
1566 status = auth_generic_client_start(auth_generic_state, GENSEC_OID_NTLMSSP);
1567 if (!NT_STATUS_IS_OK(status)) {
1568 printf("auth_generic_client_start returned %s\n", nt_errstr(status));
1572 ev = samba_tevent_context_init(talloc_tos());
1574 printf("samba_tevent_context_init() returned NULL\n");
1578 status = gensec_update(auth_generic_state->gensec_security, talloc_tos(), ev, data_blob_null, &in_blob);
1579 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1580 printf("gensec_update returned %s\n", nt_errstr(status));
1584 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1589 SMB2_CAP_DFS, /* in_capabilities */
1591 0, /* in_previous_session_id */
1592 &in_blob); /* in_security_buffer */
1593 if (subreq == NULL) {
1594 printf("smb2cli_session_setup_send() returned NULL\n");
1598 ok = tevent_req_poll(subreq, ev);
1600 printf("tevent_req_poll() returned false\n");
1604 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1606 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1607 printf("smb2cli_session_setup_recv returned %s\n",
1612 status = gensec_update(auth_generic_state->gensec_security, talloc_tos(), ev, out_blob, &in_blob);
1613 if (!NT_STATUS_IS_OK(status)) {
1614 printf("auth_generic_update returned %s\n", nt_errstr(status));
1618 status = smb2cli_flush(cli->conn, cli->timeout, cli->smb2.session,
1619 cli->smb2.tcon, fid_persistent, fid_volatile);
1620 if (!NT_STATUS_IS_OK(status)) {
1621 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1625 status = smb2cli_query_directory(
1626 cli->conn, cli->timeout, cli->smb2.session, cli->smb2.tcon,
1627 1, 0x3, 0, dir_persistent, dir_volatile,
1628 "session-reauth.txt", 0xffff,
1629 talloc_tos(), &dir_data, &dir_data_length);
1630 if (!NT_STATUS_IS_OK(status)) {
1631 printf("smb2cli_query_directory returned %s\n", nt_errstr(status));
1636 * query_info seems to be a path based operation on Windows...
1638 status = smb2cli_query_info(cli->conn,
1642 SMB2_GETINFO_SECURITY,
1643 0, /* in_file_info_class */
1644 1024, /* in_max_output_length */
1645 NULL, /* in_input_buffer */
1646 SECINFO_OWNER, /* in_additional_info */
1651 &out_output_buffer);
1652 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1653 printf("smb2cli_query_info (security) returned %s\n", nt_errstr(status));
1657 in_file_info_class = SMB_FILE_POSITION_INFORMATION - 1000;
1658 status = smb2cli_query_info(cli->conn,
1664 1024, /* in_max_output_length */
1665 NULL, /* in_input_buffer */
1666 0, /* in_additional_info */
1671 &out_output_buffer);
1672 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1673 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status));
1677 in_input_buffer = data_blob_talloc(talloc_tos(), NULL, 8);
1678 SBVAL(in_input_buffer.data, 0, 512);
1680 in_file_info_class = SMB_FILE_POSITION_INFORMATION - 1000;
1681 status = smb2cli_set_info(cli->conn,
1688 0, /* in_additional_info */
1691 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1692 printf("smb2cli_set_info (position) returned %s\n", nt_errstr(status));
1696 status = smb2cli_create(cli->conn, cli->timeout, cli->smb2.session,
1697 cli->smb2.tcon, "session-reauth-invalid.txt",
1698 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1699 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1700 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1701 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1702 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1703 FILE_CREATE, /* create_disposition, */
1704 FILE_DELETE_ON_CLOSE, /* create_options, */
1705 NULL, /* smb2_create_blobs *blobs */
1709 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1710 printf("smb2cli_create %s\n", nt_errstr(status));
1714 status = smb2cli_create(cli->conn, cli->timeout, cli->smb2.session,
1716 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1717 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1718 SEC_STD_SYNCHRONIZE|
1720 SEC_DIR_READ_ATTRIBUTE, /* desired_access, */
1721 0, /* file_attributes, */
1722 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1723 FILE_OPEN, /* create_disposition, */
1724 FILE_SYNCHRONOUS_IO_NONALERT|FILE_DIRECTORY_FILE, /* create_options, */
1725 NULL, /* smb2_create_blobs *blobs */
1729 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1730 printf("smb2cli_create returned %s\n", nt_errstr(status));
1734 saved_tid = smb2cli_tcon_current_id(cli->smb2.tcon);
1735 saved_tcon = cli->smb2.tcon;
1736 cli->smb2.tcon = smbXcli_tcon_create(cli);
1737 smb2cli_tcon_set_values(cli->smb2.tcon,
1742 0, /* capabilities */
1743 0 /* maximal_access */);
1744 status = cli_tree_connect(cli, share, "?????", "", 0);
1745 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1746 printf("cli_tree_connect returned %s\n", nt_errstr(status));
1749 talloc_free(cli->smb2.tcon);
1750 cli->smb2.tcon = saved_tcon;
1752 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1757 SMB2_CAP_DFS, /* in_capabilities */
1759 0, /* in_previous_session_id */
1760 &in_blob); /* in_security_buffer */
1761 if (subreq == NULL) {
1762 printf("smb2cli_session_setup_send() returned NULL\n");
1766 ok = tevent_req_poll(subreq, ev);
1768 printf("tevent_req_poll() returned false\n");
1772 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1773 &recv_iov, &out_blob);
1774 if (!NT_STATUS_IS_OK(status)) {
1775 printf("smb2cli_session_setup_recv returned %s\n",
1780 status = smb2cli_flush(cli->conn, cli->timeout, cli->smb2.session,
1781 cli->smb2.tcon, fid_persistent, fid_volatile);
1782 if (!NT_STATUS_IS_OK(status)) {
1783 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1787 status = smb2cli_query_info(cli->conn,
1791 SMB2_GETINFO_SECURITY,
1792 0, /* in_file_info_class */
1793 1024, /* in_max_output_length */
1794 NULL, /* in_input_buffer */
1795 SECINFO_OWNER, /* in_additional_info */
1800 &out_output_buffer);
1801 if (!NT_STATUS_IS_OK(status)) {
1802 printf("smb2cli_query_info (security) returned %s\n", nt_errstr(status));
1806 in_file_info_class = SMB_FILE_POSITION_INFORMATION - 1000;
1807 status = smb2cli_query_info(cli->conn,
1813 1024, /* in_max_output_length */
1814 NULL, /* in_input_buffer */
1815 0, /* in_additional_info */
1820 &out_output_buffer);
1821 if (!NT_STATUS_IS_OK(status)) {
1822 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status));
1826 in_input_buffer = data_blob_talloc(talloc_tos(), NULL, 8);
1827 SBVAL(in_input_buffer.data, 0, 512);
1829 in_file_info_class = SMB_FILE_POSITION_INFORMATION - 1000;
1830 status = smb2cli_set_info(cli->conn,
1837 0, /* in_additional_info */
1840 if (!NT_STATUS_IS_OK(status)) {
1841 printf("smb2cli_set_info (position) returned %s\n", nt_errstr(status));
1845 in_file_info_class = SMB_FILE_POSITION_INFORMATION - 1000;
1846 status = smb2cli_query_info(cli->conn,
1852 1024, /* in_max_output_length */
1853 NULL, /* in_input_buffer */
1854 0, /* in_additional_info */
1859 &out_output_buffer);
1860 if (!NT_STATUS_IS_OK(status)) {
1861 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status));
1865 status = smb2cli_close(cli->conn, cli->timeout, cli->smb2.session,
1866 cli->smb2.tcon, 0, fid_persistent, fid_volatile);
1867 if (!NT_STATUS_IS_OK(status)) {
1868 printf("smb2cli_close returned %s\n", nt_errstr(status));
1872 status = smb2cli_create(cli->conn, cli->timeout, cli->smb2.session,
1873 cli->smb2.tcon, "session-reauth.txt",
1874 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1875 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1876 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1877 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1878 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1879 FILE_CREATE, /* create_disposition, */
1880 FILE_DELETE_ON_CLOSE, /* create_options, */
1881 NULL, /* smb2_create_blobs *blobs */
1885 if (!NT_STATUS_IS_OK(status)) {
1886 printf("smb2cli_create %s\n", nt_errstr(status));
1890 status = smb2cli_query_directory(
1891 cli->conn, cli->timeout, cli->smb2.session, cli->smb2.tcon,
1892 1, 0x3, 0, dir_persistent, dir_volatile,
1893 "session-reauth.txt", 0xffff,
1894 talloc_tos(), &dir_data, &dir_data_length);
1895 if (!NT_STATUS_IS_OK(status)) {
1896 printf("smb2cli_query_directory returned %s\n", nt_errstr(status));
1900 status = smb2cli_close(cli->conn, cli->timeout, cli->smb2.session,
1901 cli->smb2.tcon, 0, dir_persistent, dir_volatile);
1902 if (!NT_STATUS_IS_OK(status)) {
1903 printf("smb2cli_close returned %s\n", nt_errstr(status));
1907 status = smb2cli_close(cli->conn, cli->timeout, cli->smb2.session,
1908 cli->smb2.tcon, 0, fid_persistent, fid_volatile);
1909 if (!NT_STATUS_IS_OK(status)) {
1910 printf("smb2cli_close returned %s\n", nt_errstr(status));
1914 saved_tid = smb2cli_tcon_current_id(cli->smb2.tcon);
1915 saved_tcon = cli->smb2.tcon;
1916 cli->smb2.tcon = smbXcli_tcon_create(cli);
1917 smb2cli_tcon_set_values(cli->smb2.tcon,
1922 0, /* capabilities */
1923 0 /* maximal_access */);
1924 status = cli_tree_connect(cli, share, "?????", "", 0);
1925 if (!NT_STATUS_IS_OK(status)) {
1926 printf("cli_tree_connect returned %s\n", nt_errstr(status));
1929 talloc_free(cli->smb2.tcon);
1930 cli->smb2.tcon = saved_tcon;