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)) {
52 cli->smb2.pid = 0xFEFF;
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 */
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);
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 */
150 if (!NT_STATUS_IS_OK(status)) {
151 printf("smb2cli_create returned %s\n", nt_errstr(status));
155 status = smb2cli_query_directory(
156 cli->conn, cli->timeout, cli->smb2.session, cli->smb2.tcon,
157 1, 0, 0, fid_persistent, fid_volatile, "*", 0xffff,
158 talloc_tos(), &dir_data, &dir_data_length);
160 if (!NT_STATUS_IS_OK(status)) {
161 printf("smb2cli_query_directory returned %s\n", nt_errstr(status));
165 status = smb2cli_close(cli->conn, cli->timeout, cli->smb2.session,
166 cli->smb2.tcon, 0, fid_persistent, fid_volatile);
167 if (!NT_STATUS_IS_OK(status)) {
168 printf("smb2cli_close returned %s\n", nt_errstr(status));
172 saved_tid = cli->smb2.tid;
173 saved_tcon = cli->smb2.tcon;
174 cli->smb2.tcon = smbXcli_tcon_create(cli);
175 smb2cli_tcon_set_values(cli->smb2.tcon,
179 0, /* capabilities */
180 0 /* maximal_access */);
181 status = smb2cli_tdis(cli);
182 if (!NT_STATUS_IS_OK(status)) {
183 printf("smb2cli_tdis returned %s\n", nt_errstr(status));
186 talloc_free(cli->smb2.tcon);
187 cli->smb2.tcon = saved_tcon;
188 cli->smb2.tid = saved_tid;
190 status = smb2cli_tdis(cli);
191 if (!NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED)) {
192 printf("2nd smb2cli_tdis returned %s\n", nt_errstr(status));
196 saved_uid = smb2cli_session_current_id(cli->smb2.session);
197 status = smb2cli_logoff(cli->conn, cli->timeout, cli->smb2.session);
198 if (!NT_STATUS_IS_OK(status)) {
199 printf("smb2cli_logoff returned %s\n", nt_errstr(status));
203 cli->smb2.session = smbXcli_session_create(cli, cli->conn);
204 if (cli->smb2.session == NULL) {
205 printf("smbXcli_session_create() returned NULL\n");
209 smb2cli_session_set_id_and_flags(cli->smb2.session, saved_uid, 0);
211 status = smb2cli_logoff(cli->conn, cli->timeout, cli->smb2.session);
212 if (!NT_STATUS_EQUAL(status, NT_STATUS_USER_SESSION_DELETED)) {
213 printf("2nd smb2cli_logoff returned %s\n", nt_errstr(status));
220 bool run_smb2_negprot(int dummy)
222 struct cli_state *cli;
224 enum protocol_types protocol;
225 const char *name = NULL;
227 printf("Starting SMB2-NEGPROT\n");
229 if (!torture_init_connection(&cli)) {
232 cli->smb2.pid = 0xFEFF;
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)) {
312 cli1->smb2.pid = 0xFEFF;
314 status = smbXcli_negprot(cli1->conn, cli1->timeout,
315 PROTOCOL_SMB2_02, PROTOCOL_LATEST);
316 if (!NT_STATUS_IS_OK(status)) {
317 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
321 status = cli_session_setup(cli1, username,
322 password, strlen(password),
323 password, strlen(password),
325 if (!NT_STATUS_IS_OK(status)) {
326 printf("cli_session_setup returned %s\n", nt_errstr(status));
330 status = cli_tree_connect(cli1, share, "?????", "", 0);
331 if (!NT_STATUS_IS_OK(status)) {
332 printf("cli_tree_connect returned %s\n", nt_errstr(status));
336 status = smb2cli_create(cli1->conn, cli1->timeout, cli1->smb2.session,
337 cli1->smb2.tcon, "session-reconnect.txt",
338 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
339 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
340 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
341 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
342 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
343 FILE_CREATE, /* create_disposition, */
344 FILE_DELETE_ON_CLOSE, /* create_options, */
345 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);
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)) {
394 cli2->smb2.pid = 0xFEFF;
396 status = smbXcli_negprot(cli2->conn, cli2->timeout,
397 PROTOCOL_SMB2_02, PROTOCOL_LATEST);
398 if (!NT_STATUS_IS_OK(status)) {
399 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
403 status = auth_generic_client_prepare(talloc_tos(), &auth_generic_state);
404 if (!NT_STATUS_IS_OK(status)) {
405 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status));
409 gensec_want_feature(auth_generic_state->gensec_security,
410 GENSEC_FEATURE_SESSION_KEY);
411 status = auth_generic_set_username(auth_generic_state, username);
412 if (!NT_STATUS_IS_OK(status)) {
413 printf("auth_generic_set_username returned %s\n", nt_errstr(status));
417 status = auth_generic_set_domain(auth_generic_state, workgroup);
418 if (!NT_STATUS_IS_OK(status)) {
419 printf("auth_generic_set_domain returned %s\n", nt_errstr(status));
423 status = auth_generic_set_password(auth_generic_state, password);
424 if (!NT_STATUS_IS_OK(status)) {
425 printf("auth_generic_set_password returned %s\n", nt_errstr(status));
429 status = auth_generic_client_start(auth_generic_state, GENSEC_OID_NTLMSSP);
430 if (!NT_STATUS_IS_OK(status)) {
431 printf("auth_generic_client_start returned %s\n", nt_errstr(status));
435 ev = event_context_init(talloc_tos());
437 printf("event_context_init() returned NULL\n");
441 status = gensec_update(auth_generic_state->gensec_security, talloc_tos(), ev, data_blob_null, &in_blob);
442 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
443 printf("gensec_update returned %s\n", nt_errstr(status));
447 cli2->smb2.session = smbXcli_session_create(cli2, cli2->conn);
449 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
454 SMB2_CAP_DFS, /* in_capabilities */
456 /* in_previous_session_id: */
457 smb2cli_session_current_id(cli1->smb2.session),
458 &in_blob); /* in_security_buffer */
459 if (subreq == NULL) {
460 printf("smb2cli_session_setup_send() returned NULL\n");
464 ok = tevent_req_poll(subreq, ev);
466 printf("tevent_req_poll() returned false\n");
470 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
472 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
473 printf("smb2cli_session_setup_recv returned %s\n",
478 status = gensec_update(auth_generic_state->gensec_security, talloc_tos(), ev, out_blob, &in_blob);
479 if (!NT_STATUS_IS_OK(status)) {
480 printf("auth_generic_update returned %s\n", nt_errstr(status));
484 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
489 SMB2_CAP_DFS, /* in_capabilities */
491 /* in_previous_session_id: */
492 smb2cli_session_current_id(cli1->smb2.session),
493 &in_blob); /* in_security_buffer */
494 if (subreq == NULL) {
495 printf("smb2cli_session_setup_send() returned NULL\n");
499 ok = tevent_req_poll(subreq, ev);
501 printf("tevent_req_poll() returned false\n");
505 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
506 &recv_iov, &out_blob);
507 if (!NT_STATUS_IS_OK(status)) {
508 printf("smb2cli_session_setup_recv returned %s\n",
513 status = gensec_session_key(auth_generic_state->gensec_security, talloc_tos(),
515 if (!NT_STATUS_IS_OK(status)) {
516 printf("gensec_session_key returned %s\n",
521 /* check file operation on the old client */
523 status = smb2cli_flush(cli1->conn, cli1->timeout, cli1->smb2.session,
524 cli1->smb2.tcon, fid_persistent, fid_volatile);
525 if (!NT_STATUS_EQUAL(status, NT_STATUS_USER_SESSION_DELETED)) {
526 printf("smb2cli_flush returned %s\n", nt_errstr(status));
530 status = cli_tree_connect(cli1, share, "?????", "", 0);
531 if (!NT_STATUS_EQUAL(status, NT_STATUS_USER_SESSION_DELETED)) {
532 printf("cli_tree_connect returned %s\n", nt_errstr(status));
537 * checking file operations without signing.
538 * on w2k8r2 at least, flush, read and write also work the same way,
539 * while create gives ACCESS_DENIED without signing
541 status = smb2cli_flush(cli2->conn, cli2->timeout, cli2->smb2.session,
542 cli2->smb2.tcon, fid_persistent, fid_volatile);
543 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED) &&
544 !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED))
546 printf("smb2cli_flush returned %s\n", nt_errstr(status));
550 status = smb2cli_write(cli2->conn, cli2->timeout, cli2->smb2.session,
551 cli2->smb2.tcon, strlen(hello), 0, fid_persistent,
552 fid_volatile, 0, 0, (const uint8_t *)hello);
553 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED) &&
554 !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED))
556 printf("smb2cli_write returned %s\n", nt_errstr(status));
560 status = smb2cli_read(cli2->conn, cli2->timeout, cli2->smb2.session,
561 cli2->smb2.tcon, 0x10000, 0, fid_persistent,
563 talloc_tos(), &result, &nread);
564 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED) &&
565 !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED))
567 printf("smb2cli_read returned %s\n", nt_errstr(status));
571 status = smb2cli_create(cli2->conn, cli2->timeout, cli2->smb2.session,
572 cli2->smb2.tcon, "session-reconnect.txt",
573 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
574 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
575 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
576 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
577 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
578 FILE_CREATE, /* create_disposition, */
579 FILE_DELETE_ON_CLOSE, /* create_options, */
580 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 cli2->smb2.tid = cli1->smb2.tid;
603 status = smb2cli_flush(cli2->conn, cli2->timeout, cli2->smb2.session,
604 cli2->smb2.tcon, fid_persistent, fid_volatile);
605 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED) &&
606 !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED))
608 printf("smb2cli_flush returned %s\n", nt_errstr(status));
612 status = smb2cli_write(cli2->conn, cli2->timeout, cli2->smb2.session,
613 cli2->smb2.tcon, strlen(hello), 0, fid_persistent,
614 fid_volatile, 0, 0, (const uint8_t *)hello);
615 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED) &&
616 !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED))
618 printf("smb2cli_write returned %s\n", nt_errstr(status));
622 status = smb2cli_read(cli2->conn, cli2->timeout, cli2->smb2.session,
623 cli2->smb2.tcon, 0x10000, 0, fid_persistent,
625 talloc_tos(), &result, &nread);
626 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED) &&
627 !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED))
629 printf("smb2cli_read returned %s\n", nt_errstr(status));
633 status = smb2cli_create(cli2->conn, cli2->timeout, cli2->smb2.session,
634 cli2->smb2.tcon, "session-reconnect.txt",
635 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
636 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
637 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
638 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
639 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
640 FILE_CREATE, /* create_disposition, */
641 FILE_DELETE_ON_CLOSE, /* create_options, */
642 NULL, /* smb2_create_blobs *blobs */
645 if (!NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED) &&
646 !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED))
648 printf("smb2cli_create on cli2 %s\n", nt_errstr(status));
652 /* now do a new tcon and test file calls again */
654 status = cli_tree_connect(cli2, share, "?????", "", 0);
655 if (!NT_STATUS_IS_OK(status)) {
656 printf("cli_tree_connect returned %s\n", nt_errstr(status));
660 status = smb2cli_create(cli2->conn, cli2->timeout, cli2->smb2.session,
661 cli2->smb2.tcon, "session-reconnect.txt",
662 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
663 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
664 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
665 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
666 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
667 FILE_CREATE, /* create_disposition, */
668 FILE_DELETE_ON_CLOSE, /* create_options, */
669 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);
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)) {
732 cli->smb2.pid = 0xFEFF;
734 status = smbXcli_negprot(cli->conn, cli->timeout,
735 PROTOCOL_SMB2_02, PROTOCOL_LATEST);
736 if (!NT_STATUS_IS_OK(status)) {
737 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
741 status = cli_session_setup(cli, username,
742 password, strlen(password),
743 password, strlen(password),
745 if (!NT_STATUS_IS_OK(status)) {
746 printf("cli_session_setup returned %s\n", nt_errstr(status));
750 status = cli_tree_connect(cli, share, "?????", "", 0);
751 if (!NT_STATUS_IS_OK(status)) {
752 printf("cli_tree_connect returned %s\n", nt_errstr(status));
756 status = smb2cli_create(cli->conn, cli->timeout, cli->smb2.session,
757 cli->smb2.tcon, "tcon_depedence.txt",
758 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
759 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
760 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
761 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
762 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
763 FILE_CREATE, /* create_disposition, */
764 FILE_DELETE_ON_CLOSE, /* create_options, */
765 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);
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,
818 0, /* capabilities */
819 0 /* maximal_access */);
821 status = smb2cli_read(cli->conn, cli->timeout, cli->smb2.session,
822 tcon2, 0x10000, 0, fid_persistent,
824 talloc_tos(), &result, &nread);
825 if (!NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED)) {
826 printf("smb2cli_read returned %s\n", nt_errstr(status));
835 bool run_smb2_multi_channel(int dummy)
837 struct cli_state *cli1;
838 struct cli_state *cli2;
839 struct cli_state *cli3;
842 uint64_t fid_persistent, fid_volatile;
843 struct tevent_context *ev;
844 struct tevent_req *subreq;
845 DATA_BLOB in_blob = data_blob_null;
847 DATA_BLOB channel_session_key;
848 struct auth_generic_state *auth_generic_state;
849 struct iovec *recv_iov;
850 const char *hello = "Hello, world\n";
854 printf("Starting SMB2-MULTI-CHANNEL\n");
856 if (!torture_init_connection(&cli1)) {
859 cli1->smb2.pid = 0xFEFF;
861 if (!torture_init_connection(&cli2)) {
864 cli2->smb2.pid = 0xFEFF;
866 if (!torture_init_connection(&cli3)) {
869 cli3->smb2.pid = 0xFEFF;
871 status = smbXcli_negprot(cli1->conn, cli1->timeout,
872 PROTOCOL_SMB2_22, PROTOCOL_LATEST);
873 if (!NT_STATUS_IS_OK(status)) {
874 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
878 status = smbXcli_negprot(cli2->conn, cli2->timeout,
879 PROTOCOL_SMB2_22, PROTOCOL_LATEST);
880 if (!NT_STATUS_IS_OK(status)) {
881 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
885 status = smbXcli_negprot(cli3->conn, cli3->timeout,
886 PROTOCOL_SMB2_22, PROTOCOL_LATEST);
887 if (!NT_STATUS_IS_OK(status)) {
888 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
892 status = cli_session_setup(cli1, username,
893 password, strlen(password),
894 password, strlen(password),
896 if (!NT_STATUS_IS_OK(status)) {
897 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status));
901 status = cli_tree_connect(cli1, share, "?????", "", 0);
902 if (!NT_STATUS_IS_OK(status)) {
903 printf("cli_tree_connect returned %s\n", nt_errstr(status));
907 status = smb2cli_session_create_channel(cli2,
910 &cli2->smb2.session);
911 if (!NT_STATUS_IS_OK(status)) {
912 printf("smb2cli_session_create_channel returned %s\n",
917 status = auth_generic_client_prepare(talloc_tos(), &auth_generic_state);
918 if (!NT_STATUS_IS_OK(status)) {
919 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status));
923 gensec_want_feature(auth_generic_state->gensec_security,
924 GENSEC_FEATURE_SESSION_KEY);
925 status = auth_generic_set_username(auth_generic_state, username);
926 if (!NT_STATUS_IS_OK(status)) {
927 printf("auth_generic_set_username returned %s\n", nt_errstr(status));
931 status = auth_generic_set_domain(auth_generic_state, workgroup);
932 if (!NT_STATUS_IS_OK(status)) {
933 printf("auth_generic_set_domain returned %s\n", nt_errstr(status));
937 status = auth_generic_set_password(auth_generic_state, password);
938 if (!NT_STATUS_IS_OK(status)) {
939 printf("auth_generic_set_password returned %s\n", nt_errstr(status));
943 status = auth_generic_client_start(auth_generic_state, GENSEC_OID_NTLMSSP);
944 if (!NT_STATUS_IS_OK(status)) {
945 printf("auth_generic_client_start returned %s\n", nt_errstr(status));
949 ev = event_context_init(talloc_tos());
951 printf("event_context_init() returned NULL\n");
955 status = gensec_update(auth_generic_state->gensec_security, talloc_tos(), ev, data_blob_null, &in_blob);
956 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
957 printf("gensec_update returned %s\n", nt_errstr(status));
961 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
966 SMB2_CAP_DFS, /* in_capabilities */
968 0, /* in_previous_session_id */
969 &in_blob); /* in_security_buffer */
970 if (subreq == NULL) {
971 printf("smb2cli_session_setup_send() returned NULL\n");
975 ok = tevent_req_poll(subreq, ev);
977 printf("tevent_req_poll() returned false\n");
981 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
983 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
984 printf("smb2cli_session_setup_recv returned %s\n",
989 status = gensec_update(auth_generic_state->gensec_security, talloc_tos(), ev, out_blob, &in_blob);
990 if (!NT_STATUS_IS_OK(status)) {
991 printf("auth_generic_update returned %s\n", nt_errstr(status));
995 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1000 SMB2_CAP_DFS, /* in_capabilities */
1002 0, /* in_previous_session_id */
1003 &in_blob); /* in_security_buffer */
1004 if (subreq == NULL) {
1005 printf("smb2cli_session_setup_send() returned NULL\n");
1009 ok = tevent_req_poll(subreq, ev);
1011 printf("tevent_req_poll() returned false\n");
1015 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1016 &recv_iov, &out_blob);
1017 if (!NT_STATUS_IS_OK(status)) {
1018 printf("smb2cli_session_setup_recv returned %s\n",
1023 status = gensec_session_key(auth_generic_state->gensec_security, talloc_tos(),
1024 &channel_session_key);
1025 if (!NT_STATUS_IS_OK(status)) {
1026 printf("gensec_session_key returned %s\n",
1031 status = smb2cli_session_set_channel_key(cli2->smb2.session,
1032 channel_session_key,
1034 if (!NT_STATUS_IS_OK(status)) {
1035 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status));
1039 cli2->smb2.tid = cli1->smb2.tid;
1041 status = smb2cli_session_create_channel(cli3,
1044 &cli3->smb2.session);
1045 if (!NT_STATUS_IS_OK(status)) {
1046 printf("smb2cli_session_create_channel returned %s\n",
1051 status = auth_generic_client_prepare(talloc_tos(), &auth_generic_state);
1052 if (!NT_STATUS_IS_OK(status)) {
1053 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status));
1057 gensec_want_feature(auth_generic_state->gensec_security,
1058 GENSEC_FEATURE_SESSION_KEY);
1059 status = auth_generic_set_username(auth_generic_state, username);
1060 if (!NT_STATUS_IS_OK(status)) {
1061 printf("auth_generic_set_username returned %s\n", nt_errstr(status));
1065 status = auth_generic_set_domain(auth_generic_state, workgroup);
1066 if (!NT_STATUS_IS_OK(status)) {
1067 printf("auth_generic_set_domain returned %s\n", nt_errstr(status));
1071 status = auth_generic_set_password(auth_generic_state, password);
1072 if (!NT_STATUS_IS_OK(status)) {
1073 printf("auth_generic_set_password returned %s\n", nt_errstr(status));
1077 status = auth_generic_client_start(auth_generic_state, GENSEC_OID_NTLMSSP);
1078 if (!NT_STATUS_IS_OK(status)) {
1079 printf("auth_generic_client_start returned %s\n", nt_errstr(status));
1083 status = gensec_update(auth_generic_state->gensec_security, talloc_tos(), ev, data_blob_null, &in_blob);
1084 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1085 printf("gensec_update returned %s\n", nt_errstr(status));
1089 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1093 0x01, /* in_flags */
1094 SMB2_CAP_DFS, /* in_capabilities */
1096 0, /* in_previous_session_id */
1097 &in_blob); /* in_security_buffer */
1098 if (subreq == NULL) {
1099 printf("smb2cli_session_setup_send() returned NULL\n");
1103 ok = tevent_req_poll(subreq, ev);
1105 printf("tevent_req_poll() returned false\n");
1109 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1111 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1112 printf("smb2cli_session_setup_recv returned %s\n",
1117 status = gensec_update(auth_generic_state->gensec_security, talloc_tos(), ev, out_blob, &in_blob);
1118 if (!NT_STATUS_IS_OK(status)) {
1119 printf("auth_generic_update returned %s\n", nt_errstr(status));
1123 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1127 0x01, /* in_flags */
1128 SMB2_CAP_DFS, /* in_capabilities */
1130 0, /* in_previous_session_id */
1131 &in_blob); /* in_security_buffer */
1132 if (subreq == NULL) {
1133 printf("smb2cli_session_setup_send() returned NULL\n");
1137 ok = tevent_req_poll(subreq, ev);
1139 printf("tevent_req_poll() returned false\n");
1143 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1144 &recv_iov, &out_blob);
1145 if (!NT_STATUS_IS_OK(status)) {
1146 printf("smb2cli_session_setup_recv returned %s\n",
1151 status = gensec_session_key(auth_generic_state->gensec_security, talloc_tos(),
1152 &channel_session_key);
1153 if (!NT_STATUS_IS_OK(status)) {
1154 printf("gensec_session_key returned %s\n",
1159 status = smb2cli_session_set_channel_key(cli3->smb2.session,
1160 channel_session_key,
1162 if (!NT_STATUS_IS_OK(status)) {
1163 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status));
1167 cli3->smb2.tid = cli2->smb2.tid;
1169 status = smb2cli_create(cli2->conn, cli2->timeout, cli2->smb2.session,
1170 cli2->smb2.tcon, "multi-channel.txt",
1171 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1172 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1173 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1174 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1175 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1176 FILE_CREATE, /* create_disposition, */
1177 FILE_DELETE_ON_CLOSE, /* create_options, */
1178 NULL, /* smb2_create_blobs *blobs */
1181 if (!NT_STATUS_IS_OK(status)) {
1182 printf("smb2cli_create on cli2 %s\n", nt_errstr(status));
1186 status = smb2cli_write(cli1->conn, cli1->timeout, cli1->smb2.session,
1187 cli1->smb2.tcon, strlen(hello), 0, fid_persistent,
1188 fid_volatile, 0, 0, (const uint8_t *)hello);
1189 if (!NT_STATUS_IS_OK(status)) {
1190 printf("smb2cli_write returned %s\n", nt_errstr(status));
1194 status = smb2cli_flush(cli2->conn, cli2->timeout, cli2->smb2.session,
1195 cli2->smb2.tcon, fid_persistent, fid_volatile);
1196 if (!NT_STATUS_IS_OK(status)) {
1197 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1201 status = smb2cli_flush(cli1->conn, cli1->timeout, cli1->smb2.session,
1202 cli1->smb2.tcon, fid_persistent, fid_volatile);
1203 if (!NT_STATUS_IS_OK(status)) {
1204 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1208 status = smb2cli_flush(cli3->conn, cli3->timeout, cli3->smb2.session,
1209 cli3->smb2.tcon, fid_persistent, fid_volatile);
1210 if (!NT_STATUS_IS_OK(status)) {
1211 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1215 status = smb2cli_read(cli2->conn, cli2->timeout, cli2->smb2.session,
1216 cli2->smb2.tcon, 0x10000, 0, fid_persistent,
1218 talloc_tos(), &result, &nread);
1219 if (!NT_STATUS_IS_OK(status)) {
1220 printf("smb2cli_read returned %s\n", nt_errstr(status));
1224 if (nread != strlen(hello)) {
1225 printf("smb2cli_read returned %d bytes, expected %d\n",
1226 (int)nread, (int)strlen(hello));
1230 if (memcmp(hello, result, nread) != 0) {
1231 printf("smb2cli_read returned '%s', expected '%s'\n",
1236 status = auth_generic_client_prepare(talloc_tos(), &auth_generic_state);
1237 if (!NT_STATUS_IS_OK(status)) {
1238 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status));
1242 gensec_want_feature(auth_generic_state->gensec_security,
1243 GENSEC_FEATURE_SESSION_KEY);
1244 status = auth_generic_set_username(auth_generic_state, username);
1245 if (!NT_STATUS_IS_OK(status)) {
1246 printf("auth_generic_set_username returned %s\n", nt_errstr(status));
1250 status = auth_generic_set_domain(auth_generic_state, workgroup);
1251 if (!NT_STATUS_IS_OK(status)) {
1252 printf("auth_generic_set_domain returned %s\n", nt_errstr(status));
1256 status = auth_generic_set_password(auth_generic_state, password);
1257 if (!NT_STATUS_IS_OK(status)) {
1258 printf("auth_generic_set_password returned %s\n", nt_errstr(status));
1262 status = auth_generic_client_start(auth_generic_state, GENSEC_OID_NTLMSSP);
1263 if (!NT_STATUS_IS_OK(status)) {
1264 printf("auth_generic_client_start returned %s\n", nt_errstr(status));
1268 status = gensec_update(auth_generic_state->gensec_security, talloc_tos(), ev, data_blob_null, &in_blob);
1269 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1270 printf("gensec_update returned %s\n", nt_errstr(status));
1274 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1279 SMB2_CAP_DFS, /* in_capabilities */
1281 0, /* in_previous_session_id */
1282 &in_blob); /* in_security_buffer */
1283 if (subreq == NULL) {
1284 printf("smb2cli_session_setup_send() returned NULL\n");
1288 ok = tevent_req_poll(subreq, ev);
1290 printf("tevent_req_poll() returned false\n");
1294 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1296 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1297 printf("smb2cli_session_setup_recv returned %s\n",
1302 status = gensec_update(auth_generic_state->gensec_security, talloc_tos(), ev, out_blob, &in_blob);
1303 if (!NT_STATUS_IS_OK(status)) {
1304 printf("auth_generic_update returned %s\n", nt_errstr(status));
1308 status = smb2cli_flush(cli1->conn, cli1->timeout, cli1->smb2.session,
1309 cli1->smb2.tcon, fid_persistent, fid_volatile);
1310 if (!NT_STATUS_IS_OK(status)) {
1311 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1315 status = smb2cli_flush(cli2->conn, cli2->timeout, cli2->smb2.session,
1316 cli2->smb2.tcon, fid_persistent, fid_volatile);
1317 if (!NT_STATUS_IS_OK(status)) {
1318 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1322 status = smb2cli_flush(cli3->conn, cli3->timeout, cli3->smb2.session,
1323 cli3->smb2.tcon, fid_persistent, fid_volatile);
1324 if (!NT_STATUS_IS_OK(status)) {
1325 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1329 status = smb2cli_create(cli1->conn, cli1->timeout, cli1->smb2.session,
1330 cli1->smb2.tcon, "multi-channel-invalid.txt",
1331 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1332 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1333 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1334 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1335 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1336 FILE_CREATE, /* create_disposition, */
1337 FILE_DELETE_ON_CLOSE, /* create_options, */
1338 NULL, /* smb2_create_blobs *blobs */
1341 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1342 printf("smb2cli_create %s\n", nt_errstr(status));
1346 status = smb2cli_create(cli2->conn, cli2->timeout, cli2->smb2.session,
1347 cli2->smb2.tcon, "multi-channel-invalid.txt",
1348 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1349 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1350 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1351 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1352 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1353 FILE_CREATE, /* create_disposition, */
1354 FILE_DELETE_ON_CLOSE, /* create_options, */
1355 NULL, /* smb2_create_blobs *blobs */
1358 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1359 printf("smb2cli_create %s\n", nt_errstr(status));
1363 status = smb2cli_create(cli3->conn, cli3->timeout, cli3->smb2.session,
1364 cli3->smb2.tcon, "multi-channel-invalid.txt",
1365 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1366 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1367 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1368 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1369 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1370 FILE_CREATE, /* create_disposition, */
1371 FILE_DELETE_ON_CLOSE, /* create_options, */
1372 NULL, /* smb2_create_blobs *blobs */
1375 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1376 printf("smb2cli_create %s\n", nt_errstr(status));
1380 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1385 SMB2_CAP_DFS, /* in_capabilities */
1387 0, /* in_previous_session_id */
1388 &in_blob); /* in_security_buffer */
1389 if (subreq == NULL) {
1390 printf("smb2cli_session_setup_send() returned NULL\n");
1394 ok = tevent_req_poll(subreq, ev);
1396 printf("tevent_req_poll() returned false\n");
1400 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1401 &recv_iov, &out_blob);
1402 if (!NT_STATUS_IS_OK(status)) {
1403 printf("smb2cli_session_setup_recv returned %s\n",
1408 status = smb2cli_close(cli3->conn, cli3->timeout, cli3->smb2.session,
1409 cli3->smb2.tcon, 0, fid_persistent, fid_volatile);
1410 if (!NT_STATUS_IS_OK(status)) {
1411 printf("smb2cli_close returned %s\n", nt_errstr(status));
1415 status = smb2cli_flush(cli3->conn, cli3->timeout, cli3->smb2.session,
1416 cli3->smb2.tcon, fid_persistent, fid_volatile);
1417 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
1418 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1422 status = smb2cli_flush(cli2->conn, cli2->timeout, cli2->smb2.session,
1423 cli2->smb2.tcon, fid_persistent, fid_volatile);
1424 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
1425 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1429 status = smb2cli_flush(cli1->conn, cli1->timeout, cli1->smb2.session,
1430 cli1->smb2.tcon, fid_persistent, fid_volatile);
1431 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
1432 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1439 bool run_smb2_session_reauth(int dummy)
1441 struct cli_state *cli;
1444 uint64_t fid_persistent, fid_volatile;
1445 uint64_t dir_persistent, dir_volatile;
1447 uint32_t dir_data_length;
1448 struct tevent_context *ev;
1449 struct tevent_req *subreq;
1450 DATA_BLOB in_blob = data_blob_null;
1452 DATA_BLOB in_input_buffer;
1453 DATA_BLOB out_output_buffer;
1454 uint8_t in_file_info_class;
1455 struct auth_generic_state *auth_generic_state;
1456 struct iovec *recv_iov;
1458 struct smbXcli_tcon *saved_tcon;
1460 printf("Starting SMB2-SESSION_REAUTH\n");
1462 if (!torture_init_connection(&cli)) {
1465 cli->smb2.pid = 0xFEFF;
1468 * PROTOCOL_SMB2_22 has a bug in win8pre0
1469 * it behaves like PROTOCOL_SMB2_02
1470 * and returns NT_STATUS_REQUEST_NOT_ACCEPTED,
1471 * while it allows it on PROTOCOL_SMB2_02.
1473 status = smbXcli_negprot(cli->conn, cli->timeout,
1474 PROTOCOL_SMB2_10, PROTOCOL_SMB2_10);
1475 if (!NT_STATUS_IS_OK(status)) {
1476 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
1480 status = cli_session_setup(cli, username,
1481 password, strlen(password),
1482 password, strlen(password),
1484 if (!NT_STATUS_IS_OK(status)) {
1485 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status));
1489 status = cli_tree_connect(cli, share, "?????", "", 0);
1490 if (!NT_STATUS_IS_OK(status)) {
1491 printf("cli_tree_connect returned %s\n", nt_errstr(status));
1495 status = smb2cli_create(cli->conn, cli->timeout, cli->smb2.session,
1496 cli->smb2.tcon, "session-reauth.txt",
1497 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1498 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1499 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1500 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1501 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1502 FILE_CREATE, /* create_disposition, */
1503 FILE_DELETE_ON_CLOSE, /* create_options, */
1504 NULL, /* smb2_create_blobs *blobs */
1507 if (!NT_STATUS_IS_OK(status)) {
1508 printf("smb2cli_create %s\n", nt_errstr(status));
1512 status = smb2cli_create(cli->conn, cli->timeout, cli->smb2.session,
1514 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1515 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1516 SEC_STD_SYNCHRONIZE|
1518 SEC_DIR_READ_ATTRIBUTE, /* desired_access, */
1519 0, /* file_attributes, */
1520 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1521 FILE_OPEN, /* create_disposition, */
1522 FILE_SYNCHRONOUS_IO_NONALERT|FILE_DIRECTORY_FILE, /* create_options, */
1523 NULL, /* smb2_create_blobs *blobs */
1526 if (!NT_STATUS_IS_OK(status)) {
1527 printf("smb2cli_create returned %s\n", nt_errstr(status));
1531 status = smb2cli_query_directory(
1532 cli->conn, cli->timeout, cli->smb2.session, cli->smb2.tcon,
1533 1, 0x3, 0, dir_persistent, dir_volatile,
1534 "session-reauth.txt", 0xffff,
1535 talloc_tos(), &dir_data, &dir_data_length);
1536 if (!NT_STATUS_IS_OK(status)) {
1537 printf("smb2cli_query_directory returned %s\n", nt_errstr(status));
1541 status = auth_generic_client_prepare(talloc_tos(), &auth_generic_state);
1542 if (!NT_STATUS_IS_OK(status)) {
1543 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status));
1547 gensec_want_feature(auth_generic_state->gensec_security,
1548 GENSEC_FEATURE_SESSION_KEY);
1549 status = auth_generic_set_username(auth_generic_state, username);
1550 if (!NT_STATUS_IS_OK(status)) {
1551 printf("auth_generic_set_username returned %s\n", nt_errstr(status));
1555 status = auth_generic_set_domain(auth_generic_state, workgroup);
1556 if (!NT_STATUS_IS_OK(status)) {
1557 printf("auth_generic_set_domain returned %s\n", nt_errstr(status));
1561 status = auth_generic_set_password(auth_generic_state, password);
1562 if (!NT_STATUS_IS_OK(status)) {
1563 printf("auth_generic_set_password returned %s\n", nt_errstr(status));
1567 status = auth_generic_client_start(auth_generic_state, GENSEC_OID_NTLMSSP);
1568 if (!NT_STATUS_IS_OK(status)) {
1569 printf("auth_generic_client_start returned %s\n", nt_errstr(status));
1573 ev = event_context_init(talloc_tos());
1575 printf("event_context_init() returned NULL\n");
1579 status = gensec_update(auth_generic_state->gensec_security, talloc_tos(), ev, data_blob_null, &in_blob);
1580 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1581 printf("gensec_update returned %s\n", nt_errstr(status));
1585 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1590 SMB2_CAP_DFS, /* in_capabilities */
1592 0, /* in_previous_session_id */
1593 &in_blob); /* in_security_buffer */
1594 if (subreq == NULL) {
1595 printf("smb2cli_session_setup_send() returned NULL\n");
1599 ok = tevent_req_poll(subreq, ev);
1601 printf("tevent_req_poll() returned false\n");
1605 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1607 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1608 printf("smb2cli_session_setup_recv returned %s\n",
1613 status = gensec_update(auth_generic_state->gensec_security, talloc_tos(), ev, out_blob, &in_blob);
1614 if (!NT_STATUS_IS_OK(status)) {
1615 printf("auth_generic_update returned %s\n", nt_errstr(status));
1619 status = smb2cli_flush(cli->conn, cli->timeout, cli->smb2.session,
1620 cli->smb2.tcon, fid_persistent, fid_volatile);
1621 if (!NT_STATUS_IS_OK(status)) {
1622 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1626 status = smb2cli_query_directory(
1627 cli->conn, cli->timeout, cli->smb2.session, cli->smb2.tcon,
1628 1, 0x3, 0, dir_persistent, dir_volatile,
1629 "session-reauth.txt", 0xffff,
1630 talloc_tos(), &dir_data, &dir_data_length);
1631 if (!NT_STATUS_IS_OK(status)) {
1632 printf("smb2cli_query_directory returned %s\n", nt_errstr(status));
1637 * query_info seems to be a path based operation on Windows...
1639 status = smb2cli_query_info(cli->conn,
1643 SMB2_GETINFO_SECURITY,
1644 0, /* in_file_info_class */
1645 1024, /* in_max_output_length */
1646 NULL, /* in_input_buffer */
1647 SECINFO_OWNER, /* in_additional_info */
1652 &out_output_buffer);
1653 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1654 printf("smb2cli_query_info (security) returned %s\n", nt_errstr(status));
1658 in_file_info_class = SMB_FILE_POSITION_INFORMATION - 1000;
1659 status = smb2cli_query_info(cli->conn,
1665 1024, /* in_max_output_length */
1666 NULL, /* in_input_buffer */
1667 0, /* in_additional_info */
1672 &out_output_buffer);
1673 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1674 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status));
1678 in_input_buffer = data_blob_talloc(talloc_tos(), NULL, 8);
1679 SBVAL(in_input_buffer.data, 0, 512);
1681 in_file_info_class = SMB_FILE_POSITION_INFORMATION - 1000;
1682 status = smb2cli_set_info(cli->conn,
1689 0, /* in_additional_info */
1692 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1693 printf("smb2cli_set_info (position) returned %s\n", nt_errstr(status));
1697 status = smb2cli_create(cli->conn, cli->timeout, cli->smb2.session,
1698 cli->smb2.tcon, "session-reauth-invalid.txt",
1699 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1700 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1701 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1702 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1703 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1704 FILE_CREATE, /* create_disposition, */
1705 FILE_DELETE_ON_CLOSE, /* create_options, */
1706 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 */
1728 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1729 printf("smb2cli_create returned %s\n", nt_errstr(status));
1733 saved_tid = cli->smb2.tid;
1734 saved_tcon = cli->smb2.tcon;
1735 cli->smb2.tcon = smbXcli_tcon_create(cli);
1736 smb2cli_tcon_set_values(cli->smb2.tcon,
1740 0, /* capabilities */
1741 0 /* maximal_access */);
1742 status = cli_tree_connect(cli, share, "?????", "", 0);
1743 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1744 printf("cli_tree_connect returned %s\n", nt_errstr(status));
1747 talloc_free(cli->smb2.tcon);
1748 cli->smb2.tcon = saved_tcon;
1749 cli->smb2.tid = saved_tid;
1751 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1756 SMB2_CAP_DFS, /* in_capabilities */
1758 0, /* in_previous_session_id */
1759 &in_blob); /* in_security_buffer */
1760 if (subreq == NULL) {
1761 printf("smb2cli_session_setup_send() returned NULL\n");
1765 ok = tevent_req_poll(subreq, ev);
1767 printf("tevent_req_poll() returned false\n");
1771 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1772 &recv_iov, &out_blob);
1773 if (!NT_STATUS_IS_OK(status)) {
1774 printf("smb2cli_session_setup_recv returned %s\n",
1779 status = smb2cli_flush(cli->conn, cli->timeout, cli->smb2.session,
1780 cli->smb2.tcon, fid_persistent, fid_volatile);
1781 if (!NT_STATUS_IS_OK(status)) {
1782 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1786 status = smb2cli_query_info(cli->conn,
1790 SMB2_GETINFO_SECURITY,
1791 0, /* in_file_info_class */
1792 1024, /* in_max_output_length */
1793 NULL, /* in_input_buffer */
1794 SECINFO_OWNER, /* in_additional_info */
1799 &out_output_buffer);
1800 if (!NT_STATUS_IS_OK(status)) {
1801 printf("smb2cli_query_info (security) returned %s\n", nt_errstr(status));
1805 in_file_info_class = SMB_FILE_POSITION_INFORMATION - 1000;
1806 status = smb2cli_query_info(cli->conn,
1812 1024, /* in_max_output_length */
1813 NULL, /* in_input_buffer */
1814 0, /* in_additional_info */
1819 &out_output_buffer);
1820 if (!NT_STATUS_IS_OK(status)) {
1821 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status));
1825 in_input_buffer = data_blob_talloc(talloc_tos(), NULL, 8);
1826 SBVAL(in_input_buffer.data, 0, 512);
1828 in_file_info_class = SMB_FILE_POSITION_INFORMATION - 1000;
1829 status = smb2cli_set_info(cli->conn,
1836 0, /* in_additional_info */
1839 if (!NT_STATUS_IS_OK(status)) {
1840 printf("smb2cli_set_info (position) returned %s\n", nt_errstr(status));
1844 in_file_info_class = SMB_FILE_POSITION_INFORMATION - 1000;
1845 status = smb2cli_query_info(cli->conn,
1851 1024, /* in_max_output_length */
1852 NULL, /* in_input_buffer */
1853 0, /* in_additional_info */
1858 &out_output_buffer);
1859 if (!NT_STATUS_IS_OK(status)) {
1860 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status));
1864 status = smb2cli_close(cli->conn, cli->timeout, cli->smb2.session,
1865 cli->smb2.tcon, 0, fid_persistent, fid_volatile);
1866 if (!NT_STATUS_IS_OK(status)) {
1867 printf("smb2cli_close returned %s\n", nt_errstr(status));
1871 status = smb2cli_create(cli->conn, cli->timeout, cli->smb2.session,
1872 cli->smb2.tcon, "session-reauth.txt",
1873 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1874 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1875 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1876 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1877 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1878 FILE_CREATE, /* create_disposition, */
1879 FILE_DELETE_ON_CLOSE, /* create_options, */
1880 NULL, /* smb2_create_blobs *blobs */
1883 if (!NT_STATUS_IS_OK(status)) {
1884 printf("smb2cli_create %s\n", nt_errstr(status));
1888 status = smb2cli_query_directory(
1889 cli->conn, cli->timeout, cli->smb2.session, cli->smb2.tcon,
1890 1, 0x3, 0, dir_persistent, dir_volatile,
1891 "session-reauth.txt", 0xffff,
1892 talloc_tos(), &dir_data, &dir_data_length);
1893 if (!NT_STATUS_IS_OK(status)) {
1894 printf("smb2cli_query_directory returned %s\n", nt_errstr(status));
1898 status = smb2cli_close(cli->conn, cli->timeout, cli->smb2.session,
1899 cli->smb2.tcon, 0, dir_persistent, dir_volatile);
1900 if (!NT_STATUS_IS_OK(status)) {
1901 printf("smb2cli_close returned %s\n", nt_errstr(status));
1905 status = smb2cli_close(cli->conn, cli->timeout, cli->smb2.session,
1906 cli->smb2.tcon, 0, fid_persistent, fid_volatile);
1907 if (!NT_STATUS_IS_OK(status)) {
1908 printf("smb2cli_close returned %s\n", nt_errstr(status));
1912 saved_tid = cli->smb2.tid;
1913 saved_tcon = cli->smb2.tcon;
1914 cli->smb2.tcon = smbXcli_tcon_create(cli);
1915 smb2cli_tcon_set_values(cli->smb2.tcon,
1919 0, /* capabilities */
1920 0 /* maximal_access */);
1921 status = cli_tree_connect(cli, share, "?????", "", 0);
1922 if (!NT_STATUS_IS_OK(status)) {
1923 printf("cli_tree_connect returned %s\n", nt_errstr(status));
1926 talloc_free(cli->smb2.tcon);
1927 cli->smb2.tcon = saved_tcon;
1928 cli->smb2.tid = saved_tid;