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"
23 #include "../libcli/smb/smbXcli_base.h"
24 #include "libsmb/smb2cli.h"
25 #include "libcli/security/security.h"
26 #include "libsmb/proto.h"
27 #include "auth/gensec/gensec.h"
28 #include "auth_generic.h"
30 extern fstring host
, workgroup
, share
, password
, username
, myname
;
32 bool run_smb2_basic(int dummy
)
34 struct cli_state
*cli
;
36 uint64_t fid_persistent
, fid_volatile
;
37 const char *hello
= "Hello, world\n";
41 uint32_t dir_data_length
;
42 uint32_t saved_tid
= 0;
43 uint64_t saved_uid
= 0;
45 printf("Starting SMB2-BASIC\n");
47 if (!torture_init_connection(&cli
)) {
50 cli
->smb2
.pid
= 0xFEFF;
52 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
53 PROTOCOL_SMB2_02
, PROTOCOL_SMB2_02
);
54 if (!NT_STATUS_IS_OK(status
)) {
55 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
59 status
= cli_session_setup(cli
, username
,
60 password
, strlen(password
),
61 password
, strlen(password
),
63 if (!NT_STATUS_IS_OK(status
)) {
64 printf("cli_session_setup returned %s\n", nt_errstr(status
));
68 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
69 if (!NT_STATUS_IS_OK(status
)) {
70 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
74 status
= smb2cli_create(cli
, "smb2-basic.txt",
75 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
76 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
77 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
78 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
79 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
80 FILE_CREATE
, /* create_disposition, */
81 FILE_DELETE_ON_CLOSE
, /* create_options, */
82 NULL
, /* smb2_create_blobs *blobs */
85 if (!NT_STATUS_IS_OK(status
)) {
86 printf("smb2cli_create returned %s\n", nt_errstr(status
));
90 status
= smb2cli_write(cli
, strlen(hello
), 0, fid_persistent
,
91 fid_volatile
, 0, 0, (const uint8_t *)hello
);
92 if (!NT_STATUS_IS_OK(status
)) {
93 printf("smb2cli_write returned %s\n", nt_errstr(status
));
97 status
= smb2cli_flush(cli
, fid_persistent
, fid_volatile
);
98 if (!NT_STATUS_IS_OK(status
)) {
99 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
103 status
= smb2cli_read(cli
, 0x10000, 0, fid_persistent
,
105 talloc_tos(), &result
, &nread
);
106 if (!NT_STATUS_IS_OK(status
)) {
107 printf("smb2cli_read returned %s\n", nt_errstr(status
));
111 if (nread
!= strlen(hello
)) {
112 printf("smb2cli_read returned %d bytes, expected %d\n",
113 (int)nread
, (int)strlen(hello
));
117 if (memcmp(hello
, result
, nread
) != 0) {
118 printf("smb2cli_read returned '%s', expected '%s'\n",
123 status
= smb2cli_close(cli
, 0, fid_persistent
, fid_volatile
);
124 if (!NT_STATUS_IS_OK(status
)) {
125 printf("smb2cli_close returned %s\n", nt_errstr(status
));
129 status
= smb2cli_create(cli
, "",
130 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
131 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
134 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
135 0, /* file_attributes, */
136 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
137 FILE_OPEN
, /* create_disposition, */
138 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
139 NULL
, /* smb2_create_blobs *blobs */
142 if (!NT_STATUS_IS_OK(status
)) {
143 printf("smb2cli_create returned %s\n", nt_errstr(status
));
147 status
= smb2cli_query_directory(
148 cli
, 1, 0, 0, fid_persistent
, fid_volatile
, "*", 0xffff,
149 talloc_tos(), &dir_data
, &dir_data_length
);
151 if (!NT_STATUS_IS_OK(status
)) {
152 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
156 status
= smb2cli_close(cli
, 0, fid_persistent
, fid_volatile
);
157 if (!NT_STATUS_IS_OK(status
)) {
158 printf("smb2cli_close returned %s\n", nt_errstr(status
));
162 saved_tid
= cli
->smb2
.tid
;
163 status
= smb2cli_tdis(cli
);
164 if (!NT_STATUS_IS_OK(status
)) {
165 printf("smb2cli_tdis returned %s\n", nt_errstr(status
));
168 cli
->smb2
.tid
= saved_tid
;
170 status
= smb2cli_tdis(cli
);
171 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
172 printf("2nd smb2cli_tdis returned %s\n", nt_errstr(status
));
176 saved_uid
= smb2cli_session_current_id(cli
->smb2
.session
);
177 status
= smb2cli_logoff(cli
);
178 if (!NT_STATUS_IS_OK(status
)) {
179 printf("smb2cli_logoff returned %s\n", nt_errstr(status
));
183 cli
->smb2
.session
= smbXcli_session_create(cli
, cli
->conn
);
184 if (cli
->smb2
.session
== NULL
) {
185 printf("smbXcli_session_create() returned NULL\n");
189 smb2cli_session_set_id_and_flags(cli
->smb2
.session
, saved_uid
, 0);
191 status
= smb2cli_logoff(cli
);
192 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
193 printf("2nd smb2cli_logoff returned %s\n", nt_errstr(status
));
200 bool run_smb2_negprot(int dummy
)
202 struct cli_state
*cli
;
204 enum protocol_types protocol
;
205 const char *name
= NULL
;
207 printf("Starting SMB2-NEGPROT\n");
209 if (!torture_init_connection(&cli
)) {
212 cli
->smb2
.pid
= 0xFEFF;
214 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
215 PROTOCOL_CORE
, PROTOCOL_SMB2_24
);
216 if (!NT_STATUS_IS_OK(status
)) {
217 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
221 protocol
= smbXcli_conn_protocol(cli
->conn
);
224 case PROTOCOL_SMB2_02
:
227 case PROTOCOL_SMB2_10
:
230 case PROTOCOL_SMB2_22
:
233 case PROTOCOL_SMB2_24
:
241 printf("Server supports %s\n", name
);
243 printf("Server DOES NOT support SMB2\n");
247 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
249 if (!NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_RESET
) &&
250 !NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_DISCONNECTED
) &&
251 !NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_ABORTED
)) {
252 printf("2nd smbXcli_negprot should disconnect - returned %s\n",
257 if (smbXcli_conn_is_connected(cli
->conn
)) {
258 printf("2nd smbXcli_negprot should disconnect "
259 "- still connected\n");
266 bool run_smb2_session_reconnect(int dummy
)
268 struct cli_state
*cli1
;
269 struct cli_state
*cli2
;
272 uint64_t fid_persistent
, fid_volatile
;
273 struct tevent_context
*ev
;
274 struct tevent_req
*subreq
;
275 DATA_BLOB in_blob
= data_blob_null
;
277 DATA_BLOB session_key
;
278 struct auth_generic_state
*auth_generic_state
;
279 struct iovec
*recv_iov
;
280 const char *hello
= "Hello, world\n";
284 printf("Starting SMB2-SESSION-RECONNECT\n");
286 if (!torture_init_connection(&cli1
)) {
289 cli1
->smb2
.pid
= 0xFEFF;
291 status
= smbXcli_negprot(cli1
->conn
, cli1
->timeout
,
292 PROTOCOL_SMB2_02
, PROTOCOL_SMB2_24
);
293 if (!NT_STATUS_IS_OK(status
)) {
294 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
298 status
= cli_session_setup(cli1
, username
,
299 password
, strlen(password
),
300 password
, strlen(password
),
302 if (!NT_STATUS_IS_OK(status
)) {
303 printf("cli_session_setup returned %s\n", nt_errstr(status
));
307 status
= cli_tree_connect(cli1
, share
, "?????", "", 0);
308 if (!NT_STATUS_IS_OK(status
)) {
309 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
313 status
= smb2cli_create(cli1
, "session-reconnect.txt",
314 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
315 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
316 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
317 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
318 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
319 FILE_CREATE
, /* create_disposition, */
320 FILE_DELETE_ON_CLOSE
, /* create_options, */
321 NULL
, /* smb2_create_blobs *blobs */
324 if (!NT_STATUS_IS_OK(status
)) {
325 printf("smb2cli_create on cli1 %s\n", nt_errstr(status
));
329 status
= smb2cli_write(cli1
, strlen(hello
), 0, fid_persistent
,
330 fid_volatile
, 0, 0, (const uint8_t *)hello
);
331 if (!NT_STATUS_IS_OK(status
)) {
332 printf("smb2cli_write returned %s\n", nt_errstr(status
));
336 status
= smb2cli_flush(cli1
, fid_persistent
, fid_volatile
);
337 if (!NT_STATUS_IS_OK(status
)) {
338 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
342 status
= smb2cli_read(cli1
, 0x10000, 0, fid_persistent
,
344 talloc_tos(), &result
, &nread
);
345 if (!NT_STATUS_IS_OK(status
)) {
346 printf("smb2cli_read returned %s\n", nt_errstr(status
));
350 if (nread
!= strlen(hello
)) {
351 printf("smb2cli_read returned %d bytes, expected %d\n",
352 (int)nread
, (int)strlen(hello
));
356 if (memcmp(hello
, result
, nread
) != 0) {
357 printf("smb2cli_read returned '%s', expected '%s'\n",
362 /* prepare second session */
364 if (!torture_init_connection(&cli2
)) {
367 cli2
->smb2
.pid
= 0xFEFF;
369 status
= smbXcli_negprot(cli2
->conn
, cli2
->timeout
,
370 PROTOCOL_SMB2_02
, PROTOCOL_SMB2_24
);
371 if (!NT_STATUS_IS_OK(status
)) {
372 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
376 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
377 if (!NT_STATUS_IS_OK(status
)) {
378 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
382 gensec_want_feature(auth_generic_state
->gensec_security
,
383 GENSEC_FEATURE_SESSION_KEY
);
384 status
= auth_generic_set_username(auth_generic_state
, username
);
385 if (!NT_STATUS_IS_OK(status
)) {
386 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
390 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
391 if (!NT_STATUS_IS_OK(status
)) {
392 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
396 status
= auth_generic_set_password(auth_generic_state
, password
);
397 if (!NT_STATUS_IS_OK(status
)) {
398 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
402 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
403 if (!NT_STATUS_IS_OK(status
)) {
404 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
408 ev
= event_context_init(talloc_tos());
410 printf("event_context_init() returned NULL\n");
414 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, data_blob_null
, &in_blob
);
415 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
416 printf("gensec_update returned %s\n", nt_errstr(status
));
420 cli2
->smb2
.session
= smbXcli_session_create(cli2
, cli2
->conn
);
422 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
427 SMB2_CAP_DFS
, /* in_capabilities */
429 /* in_previous_session_id: */
430 smb2cli_session_current_id(cli1
->smb2
.session
),
431 &in_blob
); /* in_security_buffer */
432 if (subreq
== NULL
) {
433 printf("smb2cli_session_setup_send() returned NULL\n");
437 ok
= tevent_req_poll(subreq
, ev
);
439 printf("tevent_req_poll() returned false\n");
443 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
445 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
446 printf("smb2cli_session_setup_recv returned %s\n",
451 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, out_blob
, &in_blob
);
452 if (!NT_STATUS_IS_OK(status
)) {
453 printf("auth_generic_update returned %s\n", nt_errstr(status
));
457 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
462 SMB2_CAP_DFS
, /* in_capabilities */
464 /* in_previous_session_id: */
465 smb2cli_session_current_id(cli1
->smb2
.session
),
466 &in_blob
); /* in_security_buffer */
467 if (subreq
== NULL
) {
468 printf("smb2cli_session_setup_send() returned NULL\n");
472 ok
= tevent_req_poll(subreq
, ev
);
474 printf("tevent_req_poll() returned false\n");
478 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
479 &recv_iov
, &out_blob
);
480 if (!NT_STATUS_IS_OK(status
)) {
481 printf("smb2cli_session_setup_recv returned %s\n",
486 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
488 if (!NT_STATUS_IS_OK(status
)) {
489 printf("gensec_session_key returned %s\n",
494 /* check file operation on the old client */
496 status
= smb2cli_flush(cli1
, fid_persistent
, fid_volatile
);
497 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
498 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
502 status
= cli_tree_connect(cli1
, share
, "?????", "", 0);
503 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
504 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
509 * checking file operations without signing.
510 * on w2k8r2 at least, flush, read and write also work the same way,
511 * while create gives ACCESS_DENIED without signing
513 status
= smb2cli_flush(cli2
, fid_persistent
, fid_volatile
);
514 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
515 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
519 status
= smb2cli_write(cli2
, strlen(hello
), 0, fid_persistent
,
520 fid_volatile
, 0, 0, (const uint8_t *)hello
);
521 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
522 printf("smb2cli_write returned %s\n", nt_errstr(status
));
526 status
= smb2cli_read(cli2
, 0x10000, 0, fid_persistent
,
528 talloc_tos(), &result
, &nread
);
529 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
530 printf("smb2cli_read returned %s\n", nt_errstr(status
));
534 status
= smb2cli_create(cli2
, "session-reconnect.txt",
535 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
536 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
537 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
538 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
539 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
540 FILE_CREATE
, /* create_disposition, */
541 FILE_DELETE_ON_CLOSE
, /* create_options, */
542 NULL
, /* smb2_create_blobs *blobs */
545 if (!NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
) &&
546 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
547 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
551 /* now grab the session key and try with signing */
553 status
= smb2cli_session_set_session_key(cli2
->smb2
.session
,
556 if (!NT_STATUS_IS_OK(status
)) {
557 printf("smb2cli_session_set_session_key %s\n", nt_errstr(status
));
561 /* the tid seems to be irrelevant at this stage */
563 cli2
->smb2
.tid
= cli1
->smb2
.tid
;
565 status
= smb2cli_flush(cli2
, fid_persistent
, fid_volatile
);
566 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
567 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
571 status
= smb2cli_write(cli2
, strlen(hello
), 0, fid_persistent
,
572 fid_volatile
, 0, 0, (const uint8_t *)hello
);
573 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
574 printf("smb2cli_write returned %s\n", nt_errstr(status
));
578 status
= smb2cli_read(cli2
, 0x10000, 0, fid_persistent
,
580 talloc_tos(), &result
, &nread
);
581 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
582 printf("smb2cli_read returned %s\n", nt_errstr(status
));
586 status
= smb2cli_create(cli2
, "session-reconnect.txt",
587 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
588 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
589 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
590 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
591 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
592 FILE_CREATE
, /* create_disposition, */
593 FILE_DELETE_ON_CLOSE
, /* create_options, */
594 NULL
, /* smb2_create_blobs *blobs */
597 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
598 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
602 /* now do a new tcon and test file calls again */
604 status
= cli_tree_connect(cli2
, share
, "?????", "", 0);
605 if (!NT_STATUS_IS_OK(status
)) {
606 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
610 status
= smb2cli_create(cli2
, "session-reconnect.txt",
611 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
612 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
613 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
614 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
615 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
616 FILE_CREATE
, /* create_disposition, */
617 FILE_DELETE_ON_CLOSE
, /* create_options, */
618 NULL
, /* smb2_create_blobs *blobs */
621 if (!NT_STATUS_IS_OK(status
)) {
622 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
626 status
= smb2cli_write(cli2
, strlen(hello
), 0, fid_persistent
,
627 fid_volatile
, 0, 0, (const uint8_t *)hello
);
628 if (!NT_STATUS_IS_OK(status
)) {
629 printf("smb2cli_write returned %s\n", nt_errstr(status
));
633 status
= smb2cli_flush(cli2
, fid_persistent
, fid_volatile
);
634 if (!NT_STATUS_IS_OK(status
)) {
635 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
639 status
= smb2cli_read(cli2
, 0x10000, 0, fid_persistent
,
641 talloc_tos(), &result
, &nread
);
642 if (!NT_STATUS_IS_OK(status
)) {
643 printf("smb2cli_read returned %s\n", nt_errstr(status
));
647 if (nread
!= strlen(hello
)) {
648 printf("smb2cli_read returned %d bytes, expected %d\n",
649 (int)nread
, (int)strlen(hello
));
653 if (memcmp(hello
, result
, nread
) != 0) {
654 printf("smb2cli_read returned '%s', expected '%s'\n",
662 bool run_smb2_tcon_dependence(int dummy
)
664 struct cli_state
*cli
;
666 uint64_t fid_persistent
, fid_volatile
;
667 const char *hello
= "Hello, world\n";
671 printf("Starting SMB2-TCON-DEPENDENCE\n");
673 if (!torture_init_connection(&cli
)) {
676 cli
->smb2
.pid
= 0xFEFF;
678 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
679 PROTOCOL_SMB2_02
, PROTOCOL_SMB2_24
);
680 if (!NT_STATUS_IS_OK(status
)) {
681 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
685 status
= cli_session_setup(cli
, username
,
686 password
, strlen(password
),
687 password
, strlen(password
),
689 if (!NT_STATUS_IS_OK(status
)) {
690 printf("cli_session_setup returned %s\n", nt_errstr(status
));
694 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
695 if (!NT_STATUS_IS_OK(status
)) {
696 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
700 status
= smb2cli_create(cli
, "tcon_depedence.txt",
701 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
702 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
703 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
704 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
705 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
706 FILE_CREATE
, /* create_disposition, */
707 FILE_DELETE_ON_CLOSE
, /* create_options, */
708 NULL
, /* smb2_create_blobs *blobs */
711 if (!NT_STATUS_IS_OK(status
)) {
712 printf("smb2cli_create on cli %s\n", nt_errstr(status
));
716 status
= smb2cli_write(cli
, strlen(hello
), 0, fid_persistent
,
717 fid_volatile
, 0, 0, (const uint8_t *)hello
);
718 if (!NT_STATUS_IS_OK(status
)) {
719 printf("smb2cli_write returned %s\n", nt_errstr(status
));
723 status
= smb2cli_flush(cli
, fid_persistent
, fid_volatile
);
724 if (!NT_STATUS_IS_OK(status
)) {
725 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
729 status
= smb2cli_read(cli
, 0x10000, 0, fid_persistent
,
731 talloc_tos(), &result
, &nread
);
732 if (!NT_STATUS_IS_OK(status
)) {
733 printf("smb2cli_read returned %s\n", nt_errstr(status
));
737 if (nread
!= strlen(hello
)) {
738 printf("smb2cli_read returned %d bytes, expected %d\n",
739 (int)nread
, (int)strlen(hello
));
743 if (memcmp(hello
, result
, nread
) != 0) {
744 printf("smb2cli_read returned '%s', expected '%s'\n",
749 /* check behaviour with wrong tid... */
753 status
= smb2cli_read(cli
, 0x10000, 0, fid_persistent
,
755 talloc_tos(), &result
, &nread
);
756 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
757 printf("smb2cli_read returned %s\n", nt_errstr(status
));
766 bool run_smb2_multi_channel(int dummy
)
768 struct cli_state
*cli1
;
769 struct cli_state
*cli2
;
770 struct cli_state
*cli3
;
773 uint64_t fid_persistent
, fid_volatile
;
774 struct tevent_context
*ev
;
775 struct tevent_req
*subreq
;
776 DATA_BLOB in_blob
= data_blob_null
;
778 DATA_BLOB channel_session_key
;
779 struct auth_generic_state
*auth_generic_state
;
780 struct iovec
*recv_iov
;
781 const char *hello
= "Hello, world\n";
785 printf("Starting SMB2-MULTI-CHANNEL\n");
787 if (!torture_init_connection(&cli1
)) {
790 cli1
->smb2
.pid
= 0xFEFF;
792 if (!torture_init_connection(&cli2
)) {
795 cli2
->smb2
.pid
= 0xFEFF;
797 if (!torture_init_connection(&cli3
)) {
800 cli3
->smb2
.pid
= 0xFEFF;
802 status
= smbXcli_negprot(cli1
->conn
, cli1
->timeout
,
803 PROTOCOL_SMB2_22
, PROTOCOL_SMB2_24
);
804 if (!NT_STATUS_IS_OK(status
)) {
805 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
809 status
= smbXcli_negprot(cli2
->conn
, cli2
->timeout
,
810 PROTOCOL_SMB2_22
, PROTOCOL_SMB2_24
);
811 if (!NT_STATUS_IS_OK(status
)) {
812 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
816 status
= smbXcli_negprot(cli3
->conn
, cli3
->timeout
,
817 PROTOCOL_SMB2_22
, PROTOCOL_SMB2_24
);
818 if (!NT_STATUS_IS_OK(status
)) {
819 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
823 status
= cli_session_setup(cli1
, username
,
824 password
, strlen(password
),
825 password
, strlen(password
),
827 if (!NT_STATUS_IS_OK(status
)) {
828 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status
));
832 status
= cli_tree_connect(cli1
, share
, "?????", "", 0);
833 if (!NT_STATUS_IS_OK(status
)) {
834 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
838 status
= smb2cli_session_create_channel(cli2
,
841 &cli2
->smb2
.session
);
842 if (!NT_STATUS_IS_OK(status
)) {
843 printf("smb2cli_session_create_channel returned %s\n",
848 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
849 if (!NT_STATUS_IS_OK(status
)) {
850 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
854 gensec_want_feature(auth_generic_state
->gensec_security
,
855 GENSEC_FEATURE_SESSION_KEY
);
856 status
= auth_generic_set_username(auth_generic_state
, username
);
857 if (!NT_STATUS_IS_OK(status
)) {
858 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
862 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
863 if (!NT_STATUS_IS_OK(status
)) {
864 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
868 status
= auth_generic_set_password(auth_generic_state
, password
);
869 if (!NT_STATUS_IS_OK(status
)) {
870 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
874 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
875 if (!NT_STATUS_IS_OK(status
)) {
876 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
880 ev
= event_context_init(talloc_tos());
882 printf("event_context_init() returned NULL\n");
886 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, data_blob_null
, &in_blob
);
887 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
888 printf("gensec_update returned %s\n", nt_errstr(status
));
892 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
897 SMB2_CAP_DFS
, /* in_capabilities */
899 0, /* in_previous_session_id */
900 &in_blob
); /* in_security_buffer */
901 if (subreq
== NULL
) {
902 printf("smb2cli_session_setup_send() returned NULL\n");
906 ok
= tevent_req_poll(subreq
, ev
);
908 printf("tevent_req_poll() returned false\n");
912 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
914 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
915 printf("smb2cli_session_setup_recv returned %s\n",
920 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, out_blob
, &in_blob
);
921 if (!NT_STATUS_IS_OK(status
)) {
922 printf("auth_generic_update returned %s\n", nt_errstr(status
));
926 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
931 SMB2_CAP_DFS
, /* in_capabilities */
933 0, /* in_previous_session_id */
934 &in_blob
); /* in_security_buffer */
935 if (subreq
== NULL
) {
936 printf("smb2cli_session_setup_send() returned NULL\n");
940 ok
= tevent_req_poll(subreq
, ev
);
942 printf("tevent_req_poll() returned false\n");
946 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
947 &recv_iov
, &out_blob
);
948 if (!NT_STATUS_IS_OK(status
)) {
949 printf("smb2cli_session_setup_recv returned %s\n",
954 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
955 &channel_session_key
);
956 if (!NT_STATUS_IS_OK(status
)) {
957 printf("gensec_session_key returned %s\n",
962 status
= smb2cli_session_set_channel_key(cli2
->smb2
.session
,
965 if (!NT_STATUS_IS_OK(status
)) {
966 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status
));
970 cli2
->smb2
.tid
= cli1
->smb2
.tid
;
972 status
= smb2cli_session_create_channel(cli3
,
975 &cli3
->smb2
.session
);
976 if (!NT_STATUS_IS_OK(status
)) {
977 printf("smb2cli_session_create_channel returned %s\n",
982 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
983 if (!NT_STATUS_IS_OK(status
)) {
984 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
988 gensec_want_feature(auth_generic_state
->gensec_security
,
989 GENSEC_FEATURE_SESSION_KEY
);
990 status
= auth_generic_set_username(auth_generic_state
, username
);
991 if (!NT_STATUS_IS_OK(status
)) {
992 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
996 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
997 if (!NT_STATUS_IS_OK(status
)) {
998 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
1002 status
= auth_generic_set_password(auth_generic_state
, password
);
1003 if (!NT_STATUS_IS_OK(status
)) {
1004 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
1008 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1009 if (!NT_STATUS_IS_OK(status
)) {
1010 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1014 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, data_blob_null
, &in_blob
);
1015 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1016 printf("gensec_update returned %s\n", nt_errstr(status
));
1020 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1024 0x01, /* in_flags */
1025 SMB2_CAP_DFS
, /* in_capabilities */
1027 0, /* in_previous_session_id */
1028 &in_blob
); /* in_security_buffer */
1029 if (subreq
== NULL
) {
1030 printf("smb2cli_session_setup_send() returned NULL\n");
1034 ok
= tevent_req_poll(subreq
, ev
);
1036 printf("tevent_req_poll() returned false\n");
1040 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1042 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1043 printf("smb2cli_session_setup_recv returned %s\n",
1048 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, out_blob
, &in_blob
);
1049 if (!NT_STATUS_IS_OK(status
)) {
1050 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1054 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1058 0x01, /* in_flags */
1059 SMB2_CAP_DFS
, /* in_capabilities */
1061 0, /* in_previous_session_id */
1062 &in_blob
); /* in_security_buffer */
1063 if (subreq
== NULL
) {
1064 printf("smb2cli_session_setup_send() returned NULL\n");
1068 ok
= tevent_req_poll(subreq
, ev
);
1070 printf("tevent_req_poll() returned false\n");
1074 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1075 &recv_iov
, &out_blob
);
1076 if (!NT_STATUS_IS_OK(status
)) {
1077 printf("smb2cli_session_setup_recv returned %s\n",
1082 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
1083 &channel_session_key
);
1084 if (!NT_STATUS_IS_OK(status
)) {
1085 printf("gensec_session_key returned %s\n",
1090 status
= smb2cli_session_set_channel_key(cli3
->smb2
.session
,
1091 channel_session_key
,
1093 if (!NT_STATUS_IS_OK(status
)) {
1094 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status
));
1098 cli3
->smb2
.tid
= cli2
->smb2
.tid
;
1100 status
= smb2cli_create(cli2
, "multi-channel.txt",
1101 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1102 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1103 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1104 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1105 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1106 FILE_CREATE
, /* create_disposition, */
1107 FILE_DELETE_ON_CLOSE
, /* create_options, */
1108 NULL
, /* smb2_create_blobs *blobs */
1111 if (!NT_STATUS_IS_OK(status
)) {
1112 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
1116 status
= smb2cli_write(cli1
, strlen(hello
), 0, fid_persistent
,
1117 fid_volatile
, 0, 0, (const uint8_t *)hello
);
1118 if (!NT_STATUS_IS_OK(status
)) {
1119 printf("smb2cli_write returned %s\n", nt_errstr(status
));
1123 status
= smb2cli_flush(cli2
, fid_persistent
, fid_volatile
);
1124 if (!NT_STATUS_IS_OK(status
)) {
1125 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1129 status
= smb2cli_flush(cli1
, fid_persistent
, fid_volatile
);
1130 if (!NT_STATUS_IS_OK(status
)) {
1131 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1135 status
= smb2cli_flush(cli3
, fid_persistent
, fid_volatile
);
1136 if (!NT_STATUS_IS_OK(status
)) {
1137 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1141 status
= smb2cli_read(cli2
, 0x10000, 0, fid_persistent
,
1143 talloc_tos(), &result
, &nread
);
1144 if (!NT_STATUS_IS_OK(status
)) {
1145 printf("smb2cli_read returned %s\n", nt_errstr(status
));
1149 if (nread
!= strlen(hello
)) {
1150 printf("smb2cli_read returned %d bytes, expected %d\n",
1151 (int)nread
, (int)strlen(hello
));
1155 if (memcmp(hello
, result
, nread
) != 0) {
1156 printf("smb2cli_read returned '%s', expected '%s'\n",
1161 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1162 if (!NT_STATUS_IS_OK(status
)) {
1163 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1167 gensec_want_feature(auth_generic_state
->gensec_security
,
1168 GENSEC_FEATURE_SESSION_KEY
);
1169 status
= auth_generic_set_username(auth_generic_state
, username
);
1170 if (!NT_STATUS_IS_OK(status
)) {
1171 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
1175 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
1176 if (!NT_STATUS_IS_OK(status
)) {
1177 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
1181 status
= auth_generic_set_password(auth_generic_state
, password
);
1182 if (!NT_STATUS_IS_OK(status
)) {
1183 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
1187 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1188 if (!NT_STATUS_IS_OK(status
)) {
1189 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1193 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, data_blob_null
, &in_blob
);
1194 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1195 printf("gensec_update returned %s\n", nt_errstr(status
));
1199 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1204 SMB2_CAP_DFS
, /* in_capabilities */
1206 0, /* in_previous_session_id */
1207 &in_blob
); /* in_security_buffer */
1208 if (subreq
== NULL
) {
1209 printf("smb2cli_session_setup_send() returned NULL\n");
1213 ok
= tevent_req_poll(subreq
, ev
);
1215 printf("tevent_req_poll() returned false\n");
1219 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1221 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1222 printf("smb2cli_session_setup_recv returned %s\n",
1227 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, out_blob
, &in_blob
);
1228 if (!NT_STATUS_IS_OK(status
)) {
1229 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1233 status
= smb2cli_flush(cli1
, fid_persistent
, fid_volatile
);
1234 if (!NT_STATUS_IS_OK(status
)) {
1235 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1239 status
= smb2cli_flush(cli2
, fid_persistent
, fid_volatile
);
1240 if (!NT_STATUS_IS_OK(status
)) {
1241 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1245 status
= smb2cli_flush(cli3
, fid_persistent
, fid_volatile
);
1246 if (!NT_STATUS_IS_OK(status
)) {
1247 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1251 status
= smb2cli_create(cli1
, "multi-channel-invalid.txt",
1252 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1253 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1254 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1255 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1256 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1257 FILE_CREATE
, /* create_disposition, */
1258 FILE_DELETE_ON_CLOSE
, /* create_options, */
1259 NULL
, /* smb2_create_blobs *blobs */
1262 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1263 printf("smb2cli_create %s\n", nt_errstr(status
));
1267 status
= smb2cli_create(cli2
, "multi-channel-invalid.txt",
1268 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1269 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1270 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1271 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1272 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1273 FILE_CREATE
, /* create_disposition, */
1274 FILE_DELETE_ON_CLOSE
, /* create_options, */
1275 NULL
, /* smb2_create_blobs *blobs */
1278 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1279 printf("smb2cli_create %s\n", nt_errstr(status
));
1283 status
= smb2cli_create(cli3
, "multi-channel-invalid.txt",
1284 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1285 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1286 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1287 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1288 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1289 FILE_CREATE
, /* create_disposition, */
1290 FILE_DELETE_ON_CLOSE
, /* create_options, */
1291 NULL
, /* smb2_create_blobs *blobs */
1294 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1295 printf("smb2cli_create %s\n", nt_errstr(status
));
1299 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1304 SMB2_CAP_DFS
, /* in_capabilities */
1306 0, /* in_previous_session_id */
1307 &in_blob
); /* in_security_buffer */
1308 if (subreq
== NULL
) {
1309 printf("smb2cli_session_setup_send() returned NULL\n");
1313 ok
= tevent_req_poll(subreq
, ev
);
1315 printf("tevent_req_poll() returned false\n");
1319 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1320 &recv_iov
, &out_blob
);
1321 if (!NT_STATUS_IS_OK(status
)) {
1322 printf("smb2cli_session_setup_recv returned %s\n",
1327 status
= smb2cli_close(cli3
, 0, fid_persistent
, fid_volatile
);
1328 if (!NT_STATUS_IS_OK(status
)) {
1329 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1333 status
= smb2cli_flush(cli3
, fid_persistent
, fid_volatile
);
1334 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1335 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1339 status
= smb2cli_flush(cli2
, fid_persistent
, fid_volatile
);
1340 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1341 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1345 status
= smb2cli_flush(cli1
, fid_persistent
, fid_volatile
);
1346 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1347 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1354 bool run_smb2_session_reauth(int dummy
)
1356 struct cli_state
*cli
;
1359 uint64_t fid_persistent
, fid_volatile
;
1360 uint64_t dir_persistent
, dir_volatile
;
1362 uint32_t dir_data_length
;
1363 struct tevent_context
*ev
;
1364 struct tevent_req
*subreq
;
1365 DATA_BLOB in_blob
= data_blob_null
;
1367 struct auth_generic_state
*auth_generic_state
;
1368 struct iovec
*recv_iov
;
1371 printf("Starting SMB2-SESSION_REAUTH\n");
1373 if (!torture_init_connection(&cli
)) {
1376 cli
->smb2
.pid
= 0xFEFF;
1379 * PROTOCOL_SMB2_22 has a bug in win8pre0
1380 * it behaves like PROTOCOL_SMB2_02
1381 * and returns NT_STATUS_REQUEST_NOT_ACCEPTED,
1382 * while it allows it on PROTOCOL_SMB2_02.
1384 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
1385 PROTOCOL_SMB2_10
, PROTOCOL_SMB2_10
);
1386 if (!NT_STATUS_IS_OK(status
)) {
1387 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
1391 status
= cli_session_setup(cli
, username
,
1392 password
, strlen(password
),
1393 password
, strlen(password
),
1395 if (!NT_STATUS_IS_OK(status
)) {
1396 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status
));
1400 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
1401 if (!NT_STATUS_IS_OK(status
)) {
1402 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1406 status
= smb2cli_create(cli
, "session-reauth.txt",
1407 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1408 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1409 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1410 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1411 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1412 FILE_CREATE
, /* create_disposition, */
1413 FILE_DELETE_ON_CLOSE
, /* create_options, */
1414 NULL
, /* smb2_create_blobs *blobs */
1417 if (!NT_STATUS_IS_OK(status
)) {
1418 printf("smb2cli_create %s\n", nt_errstr(status
));
1422 status
= smb2cli_create(cli
, "",
1423 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1424 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1425 SEC_STD_SYNCHRONIZE
|
1427 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
1428 0, /* file_attributes, */
1429 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1430 FILE_OPEN
, /* create_disposition, */
1431 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
1432 NULL
, /* smb2_create_blobs *blobs */
1435 if (!NT_STATUS_IS_OK(status
)) {
1436 printf("smb2cli_create returned %s\n", nt_errstr(status
));
1440 status
= smb2cli_query_directory(
1441 cli
, 1, 0x3, 0, dir_persistent
, dir_volatile
,
1442 "session-reauth.txt", 0xffff,
1443 talloc_tos(), &dir_data
, &dir_data_length
);
1444 if (!NT_STATUS_IS_OK(status
)) {
1445 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1449 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1450 if (!NT_STATUS_IS_OK(status
)) {
1451 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1455 gensec_want_feature(auth_generic_state
->gensec_security
,
1456 GENSEC_FEATURE_SESSION_KEY
);
1457 status
= auth_generic_set_username(auth_generic_state
, username
);
1458 if (!NT_STATUS_IS_OK(status
)) {
1459 printf("auth_generic_set_username returned %s\n", nt_errstr(status
));
1463 status
= auth_generic_set_domain(auth_generic_state
, workgroup
);
1464 if (!NT_STATUS_IS_OK(status
)) {
1465 printf("auth_generic_set_domain returned %s\n", nt_errstr(status
));
1469 status
= auth_generic_set_password(auth_generic_state
, password
);
1470 if (!NT_STATUS_IS_OK(status
)) {
1471 printf("auth_generic_set_password returned %s\n", nt_errstr(status
));
1475 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1476 if (!NT_STATUS_IS_OK(status
)) {
1477 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1481 ev
= event_context_init(talloc_tos());
1483 printf("event_context_init() returned NULL\n");
1487 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, data_blob_null
, &in_blob
);
1488 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1489 printf("gensec_update returned %s\n", nt_errstr(status
));
1493 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1498 SMB2_CAP_DFS
, /* in_capabilities */
1500 0, /* in_previous_session_id */
1501 &in_blob
); /* in_security_buffer */
1502 if (subreq
== NULL
) {
1503 printf("smb2cli_session_setup_send() returned NULL\n");
1507 ok
= tevent_req_poll(subreq
, ev
);
1509 printf("tevent_req_poll() returned false\n");
1513 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1515 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1516 printf("smb2cli_session_setup_recv returned %s\n",
1521 status
= gensec_update(auth_generic_state
->gensec_security
, talloc_tos(), ev
, out_blob
, &in_blob
);
1522 if (!NT_STATUS_IS_OK(status
)) {
1523 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1527 status
= smb2cli_flush(cli
, fid_persistent
, fid_volatile
);
1528 if (!NT_STATUS_IS_OK(status
)) {
1529 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1533 status
= smb2cli_query_directory(
1534 cli
, 1, 0x3, 0, dir_persistent
, dir_volatile
,
1535 "session-reauth.txt", 0xffff,
1536 talloc_tos(), &dir_data
, &dir_data_length
);
1537 if (!NT_STATUS_IS_OK(status
)) {
1538 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1542 status
= smb2cli_create(cli
, "session-reauth-invalid.txt",
1543 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1544 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1545 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1546 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1547 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1548 FILE_CREATE
, /* create_disposition, */
1549 FILE_DELETE_ON_CLOSE
, /* create_options, */
1550 NULL
, /* smb2_create_blobs *blobs */
1553 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1554 printf("smb2cli_create %s\n", nt_errstr(status
));
1558 status
= smb2cli_create(cli
, "",
1559 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1560 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1561 SEC_STD_SYNCHRONIZE
|
1563 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
1564 0, /* file_attributes, */
1565 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1566 FILE_OPEN
, /* create_disposition, */
1567 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
1568 NULL
, /* smb2_create_blobs *blobs */
1571 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1572 printf("smb2cli_create returned %s\n", nt_errstr(status
));
1576 saved_tid
= cli
->smb2
.tid
;
1577 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
1578 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1579 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1582 cli
->smb2
.tid
= saved_tid
;
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(),
1605 &recv_iov
, &out_blob
);
1606 if (!NT_STATUS_IS_OK(status
)) {
1607 printf("smb2cli_session_setup_recv returned %s\n",
1612 status
= smb2cli_flush(cli
, fid_persistent
, fid_volatile
);
1613 if (!NT_STATUS_IS_OK(status
)) {
1614 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1618 status
= smb2cli_close(cli
, 0, fid_persistent
, fid_volatile
);
1619 if (!NT_STATUS_IS_OK(status
)) {
1620 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1624 status
= smb2cli_create(cli
, "session-reauth.txt",
1625 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1626 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1627 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1628 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1629 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1630 FILE_CREATE
, /* create_disposition, */
1631 FILE_DELETE_ON_CLOSE
, /* create_options, */
1632 NULL
, /* smb2_create_blobs *blobs */
1635 if (!NT_STATUS_IS_OK(status
)) {
1636 printf("smb2cli_create %s\n", nt_errstr(status
));
1640 status
= smb2cli_query_directory(
1641 cli
, 1, 0x3, 0, dir_persistent
, dir_volatile
,
1642 "session-reauth.txt", 0xffff,
1643 talloc_tos(), &dir_data
, &dir_data_length
);
1644 if (!NT_STATUS_IS_OK(status
)) {
1645 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1649 status
= smb2cli_close(cli
, 0, dir_persistent
, dir_volatile
);
1650 if (!NT_STATUS_IS_OK(status
)) {
1651 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1655 status
= smb2cli_close(cli
, 0, fid_persistent
, fid_volatile
);
1656 if (!NT_STATUS_IS_OK(status
)) {
1657 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1661 saved_tid
= cli
->smb2
.tid
;
1662 status
= cli_tree_connect(cli
, share
, "?????", "", 0);
1663 if (!NT_STATUS_IS_OK(status
)) {
1664 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1667 cli
->smb2
.tid
= saved_tid
;