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 "libcli/security/security.h"
26 #include "libsmb/proto.h"
27 #include "auth/credentials/credentials.h"
28 #include "auth/gensec/gensec.h"
29 #include "auth_generic.h"
30 #include "../librpc/ndr/libndr.h"
31 #include "libsmb/clirap.h"
32 #include "libsmb/cli_smb2_fnum.h"
34 extern fstring host
, workgroup
, share
, password
, username
, myname
;
35 extern struct cli_credentials
*torture_creds
;
37 bool run_smb2_basic(int dummy
)
39 struct cli_state
*cli
;
41 uint64_t fid_persistent
, fid_volatile
;
42 const char *hello
= "Hello, world\n";
46 uint32_t dir_data_length
;
47 uint32_t saved_tid
= 0;
48 struct smbXcli_tcon
*saved_tcon
= NULL
;
49 char *saved_share
= NULL
;
50 uint64_t saved_uid
= 0;
52 printf("Starting SMB2-BASIC\n");
54 if (!torture_init_connection(&cli
)) {
58 status
= smbXcli_negprot(cli
->conn
,
65 if (!NT_STATUS_IS_OK(status
)) {
66 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
70 status
= cli_session_setup_creds(cli
, torture_creds
);
71 if (!NT_STATUS_IS_OK(status
)) {
72 printf("cli_session_setup returned %s\n", nt_errstr(status
));
76 status
= cli_tree_connect(cli
, share
, "?????", NULL
);
77 if (!NT_STATUS_IS_OK(status
)) {
78 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
82 status
= smb2cli_create(
88 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
89 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
90 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
91 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
94 FILE_SHARE_DELETE
, /* share_access, */
95 FILE_CREATE
, /* create_disposition, */
96 FILE_DELETE_ON_CLOSE
, /* create_options, */
97 NULL
, /* smb2_create_blobs *blobs */
104 if (!NT_STATUS_IS_OK(status
)) {
105 printf("smb2cli_create returned %s\n", nt_errstr(status
));
109 status
= smb2cli_write(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
110 cli
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
111 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
112 if (!NT_STATUS_IS_OK(status
)) {
113 printf("smb2cli_write returned %s\n", nt_errstr(status
));
117 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
118 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
119 if (!NT_STATUS_IS_OK(status
)) {
120 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
124 status
= smb2cli_read(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
125 cli
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
127 talloc_tos(), &result
, &nread
);
128 if (!NT_STATUS_IS_OK(status
)) {
129 printf("smb2cli_read returned %s\n", nt_errstr(status
));
133 if (nread
!= strlen(hello
)) {
134 printf("smb2cli_read returned %d bytes, expected %d\n",
135 (int)nread
, (int)strlen(hello
));
139 if (memcmp(hello
, result
, nread
) != 0) {
140 printf("smb2cli_read returned '%s', expected '%s'\n",
145 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
146 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
147 if (!NT_STATUS_IS_OK(status
)) {
148 printf("smb2cli_close returned %s\n", nt_errstr(status
));
152 status
= smb2cli_create(
158 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
159 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
162 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
163 0, /* file_attributes, */
166 FILE_SHARE_DELETE
, /* share_access, */
167 FILE_OPEN
, /* create_disposition, */
168 FILE_SYNCHRONOUS_IO_NONALERT
|
169 FILE_DIRECTORY_FILE
, /* create_options, */
170 NULL
, /* smb2_create_blobs *blobs */
177 if (!NT_STATUS_IS_OK(status
)) {
178 printf("smb2cli_create returned %s\n", nt_errstr(status
));
182 status
= smb2cli_query_directory(
183 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
184 1, 0, 0, fid_persistent
, fid_volatile
, "*", 0xffff,
185 talloc_tos(), &dir_data
, &dir_data_length
);
187 if (!NT_STATUS_IS_OK(status
)) {
188 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
192 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
193 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
194 if (!NT_STATUS_IS_OK(status
)) {
195 printf("smb2cli_close returned %s\n", nt_errstr(status
));
199 saved_tid
= smb2cli_tcon_current_id(cli
->smb2
.tcon
);
200 cli_state_save_tcon_share(cli
, &saved_tcon
, &saved_share
);
201 cli
->smb2
.tcon
= smbXcli_tcon_create(cli
);
202 smb2cli_tcon_set_values(cli
->smb2
.tcon
,
207 0, /* capabilities */
208 0 /* maximal_access */);
209 status
= smb2cli_tdis(cli
->conn
,
213 cli_state_restore_tcon_share(cli
, saved_tcon
, saved_share
);
214 if (!NT_STATUS_IS_OK(status
)) {
215 printf("smb2cli_tdis returned %s\n", nt_errstr(status
));
219 status
= smb2cli_tdis(cli
->conn
,
223 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
224 printf("2nd smb2cli_tdis returned %s\n", nt_errstr(status
));
228 saved_uid
= smb2cli_session_current_id(cli
->smb2
.session
);
229 status
= smb2cli_logoff(cli
->conn
, cli
->timeout
, cli
->smb2
.session
);
230 if (!NT_STATUS_IS_OK(status
)) {
231 printf("smb2cli_logoff returned %s\n", nt_errstr(status
));
235 cli
->smb2
.session
= smbXcli_session_create(cli
, cli
->conn
);
236 if (cli
->smb2
.session
== NULL
) {
237 printf("smbXcli_session_create() returned NULL\n");
241 smb2cli_session_set_id_and_flags(cli
->smb2
.session
, saved_uid
, 0);
243 status
= smb2cli_logoff(cli
->conn
, cli
->timeout
, cli
->smb2
.session
);
244 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
245 printf("2nd smb2cli_logoff returned %s\n", nt_errstr(status
));
252 bool run_smb2_negprot(int dummy
)
254 struct cli_state
*cli
;
256 enum protocol_types protocol
;
257 const char *name
= NULL
;
259 printf("Starting SMB2-NEGPROT\n");
261 if (!torture_init_connection(&cli
)) {
265 status
= smbXcli_negprot(cli
->conn
,
272 if (!NT_STATUS_IS_OK(status
)) {
273 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
277 protocol
= smbXcli_conn_protocol(cli
->conn
);
278 name
= smb_protocol_types_string(protocol
);
280 if (protocol
>= PROTOCOL_SMB2_02
) {
281 printf("Server supports %s\n", name
);
283 printf("Server DOES NOT support SMB2, only %s\n", name
);
287 status
= smbXcli_negprot(cli
->conn
,
294 if (!NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_RESET
) &&
295 !NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_DISCONNECTED
) &&
296 !NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_ABORTED
)) {
297 printf("2nd smbXcli_negprot should disconnect - returned %s\n",
302 if (smbXcli_conn_is_connected(cli
->conn
)) {
303 printf("2nd smbXcli_negprot should disconnect "
304 "- still connected\n");
311 bool run_smb2_anonymous(int dummy
)
313 struct cli_state
*cli
= NULL
;
315 struct cli_credentials
*anon_creds
= NULL
;
318 printf("Starting SMB2-ANONYMOUS\n");
320 if (!torture_init_connection(&cli
)) {
324 status
= smbXcli_negprot(cli
->conn
,
331 if (!NT_STATUS_IS_OK(status
)) {
332 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
336 anon_creds
= cli_credentials_init_anon(talloc_tos());
337 if (anon_creds
== NULL
) {
338 printf("cli_credentials_init_anon failed\n");
342 status
= cli_session_setup_creds(cli
, anon_creds
);
343 if (!NT_STATUS_IS_OK(status
)) {
344 printf("cli_session_setup returned %s\n", nt_errstr(status
));
348 guest
= smbXcli_session_is_guest(cli
->smb2
.session
);
350 printf("anonymous session should not have guest authentication\n");
357 bool run_smb2_session_reconnect(int dummy
)
359 struct cli_state
*cli1
;
360 struct cli_state
*cli2
;
363 uint64_t fid_persistent
, fid_volatile
;
364 struct tevent_context
*ev
;
365 struct tevent_req
*subreq
;
366 DATA_BLOB in_blob
= data_blob_null
;
368 DATA_BLOB session_key
;
369 struct auth_generic_state
*auth_generic_state
;
370 struct iovec
*recv_iov
;
371 const char *hello
= "Hello, world\n";
375 printf("Starting SMB2-SESSION-RECONNECT\n");
377 if (!torture_init_connection(&cli1
)) {
381 status
= smbXcli_negprot(cli1
->conn
,
388 if (!NT_STATUS_IS_OK(status
)) {
389 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
393 status
= cli_session_setup_creds(cli1
, torture_creds
);
394 if (!NT_STATUS_IS_OK(status
)) {
395 printf("cli_session_setup returned %s\n", nt_errstr(status
));
399 status
= cli_tree_connect(cli1
, share
, "?????", NULL
);
400 if (!NT_STATUS_IS_OK(status
)) {
401 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
405 status
= smb2cli_create(
410 "session-reconnect.txt",
411 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
412 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
413 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
414 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
417 FILE_SHARE_DELETE
, /* share_access, */
418 FILE_CREATE
, /* create_disposition, */
419 FILE_DELETE_ON_CLOSE
, /* create_options, */
420 NULL
, /* smb2_create_blobs *blobs */
427 if (!NT_STATUS_IS_OK(status
)) {
428 printf("smb2cli_create on cli1 %s\n", nt_errstr(status
));
432 status
= smb2cli_write(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
433 cli1
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
434 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
435 if (!NT_STATUS_IS_OK(status
)) {
436 printf("smb2cli_write returned %s\n", nt_errstr(status
));
440 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
441 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
442 if (!NT_STATUS_IS_OK(status
)) {
443 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
447 status
= smb2cli_read(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
448 cli1
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
450 talloc_tos(), &result
, &nread
);
451 if (!NT_STATUS_IS_OK(status
)) {
452 printf("smb2cli_read returned %s\n", nt_errstr(status
));
456 if (nread
!= strlen(hello
)) {
457 printf("smb2cli_read returned %d bytes, expected %d\n",
458 (int)nread
, (int)strlen(hello
));
462 if (memcmp(hello
, result
, nread
) != 0) {
463 printf("smb2cli_read returned '%s', expected '%s'\n",
468 /* prepare second session */
470 if (!torture_init_connection(&cli2
)) {
474 status
= smbXcli_negprot(cli2
->conn
,
481 if (!NT_STATUS_IS_OK(status
)) {
482 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
486 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
487 if (!NT_STATUS_IS_OK(status
)) {
488 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
492 gensec_want_feature(auth_generic_state
->gensec_security
,
493 GENSEC_FEATURE_SESSION_KEY
);
495 status
= auth_generic_set_creds(auth_generic_state
, torture_creds
);
496 if (!NT_STATUS_IS_OK(status
)) {
497 printf("auth_generic_set_creds returned %s\n", nt_errstr(status
));
501 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
502 if (!NT_STATUS_IS_OK(status
)) {
503 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
507 ev
= samba_tevent_context_init(talloc_tos());
509 printf("samba_tevent_context_init() returned NULL\n");
513 status
= gensec_update(auth_generic_state
->gensec_security
,
514 talloc_tos(), data_blob_null
, &in_blob
);
515 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
516 printf("gensec_update returned %s\n", nt_errstr(status
));
520 cli2
->smb2
.session
= smbXcli_session_create(cli2
, cli2
->conn
);
522 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
527 SMB2_CAP_DFS
, /* in_capabilities */
529 /* in_previous_session_id: */
530 smb2cli_session_current_id(cli1
->smb2
.session
),
531 &in_blob
); /* in_security_buffer */
532 if (subreq
== NULL
) {
533 printf("smb2cli_session_setup_send() returned NULL\n");
537 ok
= tevent_req_poll(subreq
, ev
);
539 printf("tevent_req_poll() returned false\n");
543 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
545 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
546 printf("smb2cli_session_setup_recv returned %s\n",
551 status
= gensec_update(auth_generic_state
->gensec_security
,
552 talloc_tos(), out_blob
, &in_blob
);
553 if (!NT_STATUS_IS_OK(status
)) {
554 printf("auth_generic_update returned %s\n", nt_errstr(status
));
558 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
563 SMB2_CAP_DFS
, /* in_capabilities */
565 /* in_previous_session_id: */
566 smb2cli_session_current_id(cli1
->smb2
.session
),
567 &in_blob
); /* in_security_buffer */
568 if (subreq
== NULL
) {
569 printf("smb2cli_session_setup_send() returned NULL\n");
573 ok
= tevent_req_poll(subreq
, ev
);
575 printf("tevent_req_poll() returned false\n");
579 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
580 &recv_iov
, &out_blob
);
581 if (!NT_STATUS_IS_OK(status
)) {
582 printf("smb2cli_session_setup_recv returned %s\n",
587 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
589 if (!NT_STATUS_IS_OK(status
)) {
590 printf("gensec_session_key returned %s\n",
595 /* check file operation on the old client */
597 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
598 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
599 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
600 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
604 status
= cli_tree_connect(cli1
, share
, "?????", NULL
);
605 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
606 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
611 * checking file operations without signing.
612 * on w2k8r2 at least, flush, read and write also work the same way,
613 * while create gives ACCESS_DENIED without signing
615 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
616 cli2
->smb2
.tcon
, fid_persistent
, fid_volatile
);
617 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
618 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
620 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
624 status
= smb2cli_write(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
625 cli2
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
626 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
627 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
628 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
630 printf("smb2cli_write returned %s\n", nt_errstr(status
));
634 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
635 cli2
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
637 talloc_tos(), &result
, &nread
);
638 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
639 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
641 printf("smb2cli_read returned %s\n", nt_errstr(status
));
645 status
= smb2cli_create(
650 "session-reconnect.txt",
651 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
652 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
653 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
654 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
657 FILE_SHARE_DELETE
, /* share_access, */
658 FILE_CREATE
, /* create_disposition, */
659 FILE_DELETE_ON_CLOSE
, /* create_options, */
660 NULL
, /* smb2_create_blobs *blobs */
667 if (!NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
) &&
668 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
669 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
673 /* now grab the session key and try with signing */
675 status
= smb2cli_session_set_session_key(cli2
->smb2
.session
,
678 if (!NT_STATUS_IS_OK(status
)) {
679 printf("smb2cli_session_set_session_key %s\n", nt_errstr(status
));
683 /* the tid seems to be irrelevant at this stage */
685 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
686 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
687 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
688 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
690 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
694 status
= smb2cli_write(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
695 cli1
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
696 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
697 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
698 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
700 printf("smb2cli_write returned %s\n", nt_errstr(status
));
704 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
705 cli1
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
707 talloc_tos(), &result
, &nread
);
708 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
709 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
711 printf("smb2cli_read returned %s\n", nt_errstr(status
));
715 status
= smb2cli_create(
720 "session-reconnect.txt",
721 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
722 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
723 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
724 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
727 FILE_SHARE_DELETE
, /* share_access, */
728 FILE_CREATE
, /* create_disposition, */
729 FILE_DELETE_ON_CLOSE
, /* create_options, */
730 NULL
, /* smb2_create_blobs *blobs */
737 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
) &&
738 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
740 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
744 /* now do a new tcon and test file calls again */
746 status
= cli_tree_connect(cli2
, share
, "?????", NULL
);
747 if (!NT_STATUS_IS_OK(status
)) {
748 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
752 status
= smb2cli_create(
757 "session-reconnect.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, */
764 FILE_SHARE_DELETE
, /* share_access, */
765 FILE_CREATE
, /* create_disposition, */
766 FILE_DELETE_ON_CLOSE
, /* create_options, */
767 NULL
, /* smb2_create_blobs *blobs */
774 if (!NT_STATUS_IS_OK(status
)) {
775 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
779 status
= smb2cli_write(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
780 cli2
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
781 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
782 if (!NT_STATUS_IS_OK(status
)) {
783 printf("smb2cli_write returned %s\n", nt_errstr(status
));
787 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
788 cli2
->smb2
.tcon
, fid_persistent
, fid_volatile
);
789 if (!NT_STATUS_IS_OK(status
)) {
790 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
794 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
795 cli2
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
797 talloc_tos(), &result
, &nread
);
798 if (!NT_STATUS_IS_OK(status
)) {
799 printf("smb2cli_read returned %s\n", nt_errstr(status
));
803 if (nread
!= strlen(hello
)) {
804 printf("smb2cli_read returned %d bytes, expected %d\n",
805 (int)nread
, (int)strlen(hello
));
809 if (memcmp(hello
, result
, nread
) != 0) {
810 printf("smb2cli_read returned '%s', expected '%s'\n",
818 bool run_smb2_tcon_dependence(int dummy
)
820 struct cli_state
*cli
;
822 uint64_t fid_persistent
, fid_volatile
;
823 const char *hello
= "Hello, world\n";
826 struct smbXcli_tcon
*tcon2
;
829 printf("Starting SMB2-TCON-DEPENDENCE\n");
831 if (!torture_init_connection(&cli
)) {
835 status
= smbXcli_negprot(cli
->conn
,
842 if (!NT_STATUS_IS_OK(status
)) {
843 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
847 status
= cli_session_setup_creds(cli
, torture_creds
);
848 if (!NT_STATUS_IS_OK(status
)) {
849 printf("cli_session_setup returned %s\n", nt_errstr(status
));
853 status
= cli_tree_connect(cli
, share
, "?????", NULL
);
854 if (!NT_STATUS_IS_OK(status
)) {
855 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
859 status
= smb2cli_create(
864 "tcon_depedence.txt",
865 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
866 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
867 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
868 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
871 FILE_SHARE_DELETE
, /* share_access, */
872 FILE_CREATE
, /* create_disposition, */
873 FILE_DELETE_ON_CLOSE
, /* create_options, */
874 NULL
, /* smb2_create_blobs *blobs */
881 if (!NT_STATUS_IS_OK(status
)) {
882 printf("smb2cli_create on cli %s\n", nt_errstr(status
));
886 status
= smb2cli_write(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
887 cli
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
888 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
889 if (!NT_STATUS_IS_OK(status
)) {
890 printf("smb2cli_write returned %s\n", nt_errstr(status
));
894 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
895 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
896 if (!NT_STATUS_IS_OK(status
)) {
897 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
901 status
= smb2cli_read(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
902 cli
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
904 talloc_tos(), &result
, &nread
);
905 if (!NT_STATUS_IS_OK(status
)) {
906 printf("smb2cli_read returned %s\n", nt_errstr(status
));
910 if (nread
!= strlen(hello
)) {
911 printf("smb2cli_read returned %d bytes, expected %d\n",
912 (int)nread
, (int)strlen(hello
));
916 if (memcmp(hello
, result
, nread
) != 0) {
917 printf("smb2cli_read returned '%s', expected '%s'\n",
922 /* check behaviour with wrong tid... */
924 tcon2
= smbXcli_tcon_create(cli
);
925 tcon2_id
= smb2cli_tcon_current_id(cli
->smb2
.tcon
);
927 smb2cli_tcon_set_values(tcon2
,
932 0, /* capabilities */
933 0 /* maximal_access */);
935 status
= smb2cli_read(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
936 tcon2
, 0x10000, 0, fid_persistent
,
938 talloc_tos(), &result
, &nread
);
939 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
940 printf("smb2cli_read returned %s\n", nt_errstr(status
));
949 bool run_smb2_multi_channel(int dummy
)
951 struct cli_state
*cli1
;
952 struct cli_state
*cli2
;
953 struct cli_state
*cli3
;
956 uint64_t fid_persistent
, fid_volatile
;
957 struct tevent_context
*ev
;
958 struct tevent_req
*subreq
;
959 DATA_BLOB in_blob
= data_blob_null
;
961 DATA_BLOB channel_session_key
;
962 struct auth_generic_state
*auth_generic_state
;
963 struct iovec
*recv_iov
;
964 const char *hello
= "Hello, world\n";
967 struct GUID saved_guid
= cli_state_client_guid
;
969 printf("Starting SMB2-MULTI-CHANNEL\n");
971 cli_state_client_guid
= GUID_random();
973 if (!torture_init_connection(&cli1
)) {
977 if (!torture_init_connection(&cli2
)) {
981 if (!torture_init_connection(&cli3
)) {
985 cli_state_client_guid
= saved_guid
;
987 status
= smbXcli_negprot(cli1
->conn
,
994 if (!NT_STATUS_IS_OK(status
)) {
995 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
999 status
= smbXcli_negprot(cli2
->conn
,
1006 if (!NT_STATUS_IS_OK(status
)) {
1007 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
1011 status
= smbXcli_negprot(cli3
->conn
,
1018 if (!NT_STATUS_IS_OK(status
)) {
1019 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
1023 status
= cli_session_setup_creds(cli1
, torture_creds
);
1024 if (!NT_STATUS_IS_OK(status
)) {
1025 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status
));
1029 status
= cli_tree_connect(cli1
, share
, "?????", NULL
);
1030 if (!NT_STATUS_IS_OK(status
)) {
1031 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1035 status
= smb2cli_session_create_channel(cli2
,
1038 &cli2
->smb2
.session
);
1039 if (!NT_STATUS_IS_OK(status
)) {
1040 printf("smb2cli_session_create_channel returned %s\n",
1045 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1046 if (!NT_STATUS_IS_OK(status
)) {
1047 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1051 gensec_want_feature(auth_generic_state
->gensec_security
,
1052 GENSEC_FEATURE_SESSION_KEY
);
1054 status
= auth_generic_set_creds(auth_generic_state
, torture_creds
);
1055 if (!NT_STATUS_IS_OK(status
)) {
1056 printf("auth_generic_set_creds returned %s\n", nt_errstr(status
));
1060 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1061 if (!NT_STATUS_IS_OK(status
)) {
1062 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1066 ev
= samba_tevent_context_init(talloc_tos());
1068 printf("samba_tevent_context_init() returned NULL\n");
1072 status
= gensec_update(auth_generic_state
->gensec_security
,
1073 talloc_tos(), data_blob_null
, &in_blob
);
1074 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1075 printf("gensec_update returned %s\n", nt_errstr(status
));
1079 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1083 0x01, /* in_flags */
1084 SMB2_CAP_DFS
, /* in_capabilities */
1086 0, /* in_previous_session_id */
1087 &in_blob
); /* in_security_buffer */
1088 if (subreq
== NULL
) {
1089 printf("smb2cli_session_setup_send() returned NULL\n");
1093 ok
= tevent_req_poll(subreq
, ev
);
1095 printf("tevent_req_poll() returned false\n");
1099 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1101 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1102 printf("smb2cli_session_setup_recv returned %s\n",
1107 status
= gensec_update(auth_generic_state
->gensec_security
,
1108 talloc_tos(), out_blob
, &in_blob
);
1109 if (!NT_STATUS_IS_OK(status
)) {
1110 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1114 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1118 0x01, /* in_flags */
1119 SMB2_CAP_DFS
, /* in_capabilities */
1121 0, /* in_previous_session_id */
1122 &in_blob
); /* in_security_buffer */
1123 if (subreq
== NULL
) {
1124 printf("smb2cli_session_setup_send() returned NULL\n");
1128 ok
= tevent_req_poll(subreq
, ev
);
1130 printf("tevent_req_poll() returned false\n");
1134 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1135 &recv_iov
, &out_blob
);
1136 if (!NT_STATUS_IS_OK(status
)) {
1137 printf("smb2cli_session_setup_recv returned %s\n",
1142 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
1143 &channel_session_key
);
1144 if (!NT_STATUS_IS_OK(status
)) {
1145 printf("gensec_session_key returned %s\n",
1150 status
= smb2cli_session_set_channel_key(cli2
->smb2
.session
,
1151 channel_session_key
,
1153 if (!NT_STATUS_IS_OK(status
)) {
1154 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status
));
1158 status
= smb2cli_session_create_channel(cli3
,
1161 &cli3
->smb2
.session
);
1162 if (!NT_STATUS_IS_OK(status
)) {
1163 printf("smb2cli_session_create_channel returned %s\n",
1168 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1169 if (!NT_STATUS_IS_OK(status
)) {
1170 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1174 gensec_want_feature(auth_generic_state
->gensec_security
,
1175 GENSEC_FEATURE_SESSION_KEY
);
1177 status
= auth_generic_set_creds(auth_generic_state
, torture_creds
);
1178 if (!NT_STATUS_IS_OK(status
)) {
1179 printf("auth_generic_set_creds returned %s\n", nt_errstr(status
));
1183 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1184 if (!NT_STATUS_IS_OK(status
)) {
1185 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1189 status
= gensec_update(auth_generic_state
->gensec_security
,
1190 talloc_tos(), data_blob_null
, &in_blob
);
1191 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1192 printf("gensec_update returned %s\n", nt_errstr(status
));
1196 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1200 0x01, /* in_flags */
1201 SMB2_CAP_DFS
, /* in_capabilities */
1203 0, /* in_previous_session_id */
1204 &in_blob
); /* in_security_buffer */
1205 if (subreq
== NULL
) {
1206 printf("smb2cli_session_setup_send() returned NULL\n");
1210 ok
= tevent_req_poll(subreq
, ev
);
1212 printf("tevent_req_poll() returned false\n");
1216 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1218 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1219 printf("smb2cli_session_setup_recv returned %s\n",
1224 status
= gensec_update(auth_generic_state
->gensec_security
,
1225 talloc_tos(), out_blob
, &in_blob
);
1226 if (!NT_STATUS_IS_OK(status
)) {
1227 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1231 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1235 0x01, /* in_flags */
1236 SMB2_CAP_DFS
, /* in_capabilities */
1238 0, /* in_previous_session_id */
1239 &in_blob
); /* in_security_buffer */
1240 if (subreq
== NULL
) {
1241 printf("smb2cli_session_setup_send() returned NULL\n");
1245 ok
= tevent_req_poll(subreq
, ev
);
1247 printf("tevent_req_poll() returned false\n");
1251 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1252 &recv_iov
, &out_blob
);
1253 if (!NT_STATUS_IS_OK(status
)) {
1254 printf("smb2cli_session_setup_recv returned %s\n",
1259 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
1260 &channel_session_key
);
1261 if (!NT_STATUS_IS_OK(status
)) {
1262 printf("gensec_session_key returned %s\n",
1267 status
= smb2cli_session_set_channel_key(cli3
->smb2
.session
,
1268 channel_session_key
,
1270 if (!NT_STATUS_IS_OK(status
)) {
1271 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status
));
1275 status
= smb2cli_create(
1280 "multi-channel.txt",
1281 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1282 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1283 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1284 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1287 FILE_SHARE_DELETE
, /* share_access, */
1288 FILE_CREATE
, /* create_disposition, */
1289 FILE_DELETE_ON_CLOSE
, /* create_options, */
1290 NULL
, /* smb2_create_blobs *blobs */
1297 if (!NT_STATUS_IS_OK(status
)) {
1298 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
1302 status
= smb2cli_write(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1303 cli1
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
1304 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
1305 if (!NT_STATUS_IS_OK(status
)) {
1306 printf("smb2cli_write returned %s\n", nt_errstr(status
));
1310 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1311 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1312 if (!NT_STATUS_IS_OK(status
)) {
1313 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1317 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1318 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1319 if (!NT_STATUS_IS_OK(status
)) {
1320 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1324 status
= smb2cli_flush(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1325 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1326 if (!NT_STATUS_IS_OK(status
)) {
1327 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1331 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1332 cli1
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
1334 talloc_tos(), &result
, &nread
);
1335 if (!NT_STATUS_IS_OK(status
)) {
1336 printf("smb2cli_read returned %s\n", nt_errstr(status
));
1340 if (nread
!= strlen(hello
)) {
1341 printf("smb2cli_read returned %d bytes, expected %d\n",
1342 (int)nread
, (int)strlen(hello
));
1346 if (memcmp(hello
, result
, nread
) != 0) {
1347 printf("smb2cli_read returned '%s', expected '%s'\n",
1352 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1353 if (!NT_STATUS_IS_OK(status
)) {
1354 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1358 gensec_want_feature(auth_generic_state
->gensec_security
,
1359 GENSEC_FEATURE_SESSION_KEY
);
1361 status
= auth_generic_set_creds(auth_generic_state
, torture_creds
);
1362 if (!NT_STATUS_IS_OK(status
)) {
1363 printf("auth_generic_set_creds returned %s\n", nt_errstr(status
));
1367 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1368 if (!NT_STATUS_IS_OK(status
)) {
1369 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1373 status
= gensec_update(auth_generic_state
->gensec_security
,
1374 talloc_tos(), data_blob_null
, &in_blob
);
1375 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1376 printf("gensec_update returned %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(),
1402 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1403 printf("smb2cli_session_setup_recv returned %s\n",
1408 status
= gensec_update(auth_generic_state
->gensec_security
,
1409 talloc_tos(), out_blob
, &in_blob
);
1410 if (!NT_STATUS_IS_OK(status
)) {
1411 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1415 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1416 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1417 if (!NT_STATUS_IS_OK(status
)) {
1418 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1422 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1423 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1424 if (!NT_STATUS_IS_OK(status
)) {
1425 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1429 status
= smb2cli_flush(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1430 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1431 if (!NT_STATUS_IS_OK(status
)) {
1432 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1436 status
= smb2cli_create(
1441 "multi-channel-invalid.txt",
1442 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1443 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1444 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1445 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1448 FILE_SHARE_DELETE
, /* share_access, */
1449 FILE_CREATE
, /* create_disposition, */
1450 FILE_DELETE_ON_CLOSE
, /* create_options, */
1451 NULL
, /* smb2_create_blobs *blobs */
1458 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1459 printf("smb2cli_create %s\n", nt_errstr(status
));
1463 status
= smb2cli_create(
1468 "multi-channel-invalid.txt",
1469 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1470 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1471 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1472 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1475 FILE_SHARE_DELETE
, /* share_access, */
1476 FILE_CREATE
, /* create_disposition, */
1477 FILE_DELETE_ON_CLOSE
, /* create_options, */
1478 NULL
, /* smb2_create_blobs *blobs */
1485 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1486 printf("smb2cli_create %s\n", nt_errstr(status
));
1490 status
= smb2cli_create(
1495 "multi-channel-invalid.txt",
1496 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1497 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1498 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1499 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1502 FILE_SHARE_DELETE
, /* share_access, */
1503 FILE_CREATE
, /* create_disposition, */
1504 FILE_DELETE_ON_CLOSE
, /* create_options, */
1505 NULL
, /* smb2_create_blobs *blobs */
1512 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1513 printf("smb2cli_create %s\n", nt_errstr(status
));
1517 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1522 SMB2_CAP_DFS
, /* in_capabilities */
1524 0, /* in_previous_session_id */
1525 &in_blob
); /* in_security_buffer */
1526 if (subreq
== NULL
) {
1527 printf("smb2cli_session_setup_send() returned NULL\n");
1531 ok
= tevent_req_poll(subreq
, ev
);
1533 printf("tevent_req_poll() returned false\n");
1537 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1538 &recv_iov
, &out_blob
);
1539 if (!NT_STATUS_IS_OK(status
)) {
1540 printf("smb2cli_session_setup_recv returned %s\n",
1545 status
= smb2cli_close(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1546 cli1
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
1547 if (!NT_STATUS_IS_OK(status
)) {
1548 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1552 status
= smb2cli_flush(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1553 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1554 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1555 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1559 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1560 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1561 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1562 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1566 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1567 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1568 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1569 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1576 bool run_smb2_session_reauth(int dummy
)
1578 struct cli_state
*cli
;
1581 uint64_t fid_persistent
, fid_volatile
;
1582 uint64_t dir_persistent
, dir_volatile
;
1584 uint32_t dir_data_length
;
1585 struct tevent_context
*ev
;
1586 struct tevent_req
*subreq
;
1587 DATA_BLOB in_blob
= data_blob_null
;
1589 DATA_BLOB in_input_buffer
;
1590 DATA_BLOB out_output_buffer
;
1591 uint8_t in_file_info_class
;
1592 struct auth_generic_state
*auth_generic_state
;
1593 struct iovec
*recv_iov
;
1595 struct smbXcli_tcon
*saved_tcon
;
1597 printf("Starting SMB2-SESSION_REAUTH\n");
1599 if (!torture_init_connection(&cli
)) {
1604 * PROTOCOL_SMB2_22 has a bug in win8pre0
1605 * it behaves like PROTOCOL_SMB2_02
1606 * and returns NT_STATUS_REQUEST_NOT_ACCEPTED,
1607 * while it allows it on PROTOCOL_SMB2_10.
1609 status
= smbXcli_negprot(cli
->conn
,
1616 if (!NT_STATUS_IS_OK(status
)) {
1617 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
1621 status
= cli_session_setup_creds(cli
, torture_creds
);
1622 if (!NT_STATUS_IS_OK(status
)) {
1623 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status
));
1627 status
= cli_tree_connect(cli
, share
, "?????", NULL
);
1628 if (!NT_STATUS_IS_OK(status
)) {
1629 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1633 status
= smb2cli_create(
1638 "session-reauth.txt",
1639 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1640 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1641 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1642 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1645 FILE_SHARE_DELETE
, /* share_access, */
1646 FILE_CREATE
, /* create_disposition, */
1647 FILE_DELETE_ON_CLOSE
, /* create_options, */
1648 NULL
, /* smb2_create_blobs *blobs */
1655 if (!NT_STATUS_IS_OK(status
)) {
1656 printf("smb2cli_create %s\n", nt_errstr(status
));
1660 status
= smb2cli_create(
1666 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1667 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1668 SEC_STD_SYNCHRONIZE
|
1670 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
1671 0, /* file_attributes, */
1674 FILE_SHARE_DELETE
, /* share_access, */
1675 FILE_OPEN
, /* create_disposition, */
1676 FILE_SYNCHRONOUS_IO_NONALERT
|
1677 FILE_DIRECTORY_FILE
, /* create_options, */
1678 NULL
, /* smb2_create_blobs *blobs */
1685 if (!NT_STATUS_IS_OK(status
)) {
1686 printf("smb2cli_create returned %s\n", nt_errstr(status
));
1690 status
= smb2cli_query_directory(
1691 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
1692 1, 0x3, 0, dir_persistent
, dir_volatile
,
1693 "session-reauth.txt", 0xffff,
1694 talloc_tos(), &dir_data
, &dir_data_length
);
1695 if (!NT_STATUS_IS_OK(status
)) {
1696 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1700 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1701 if (!NT_STATUS_IS_OK(status
)) {
1702 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1706 gensec_want_feature(auth_generic_state
->gensec_security
,
1707 GENSEC_FEATURE_SESSION_KEY
);
1709 status
= auth_generic_set_creds(auth_generic_state
, torture_creds
);
1710 if (!NT_STATUS_IS_OK(status
)) {
1711 printf("auth_generic_set_creds returned %s\n", nt_errstr(status
));
1715 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1716 if (!NT_STATUS_IS_OK(status
)) {
1717 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1721 ev
= samba_tevent_context_init(talloc_tos());
1723 printf("samba_tevent_context_init() returned NULL\n");
1727 status
= gensec_update(auth_generic_state
->gensec_security
,
1728 talloc_tos(), data_blob_null
, &in_blob
);
1729 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1730 printf("gensec_update returned %s\n", nt_errstr(status
));
1734 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1739 SMB2_CAP_DFS
, /* in_capabilities */
1741 0, /* in_previous_session_id */
1742 &in_blob
); /* in_security_buffer */
1743 if (subreq
== NULL
) {
1744 printf("smb2cli_session_setup_send() returned NULL\n");
1748 ok
= tevent_req_poll(subreq
, ev
);
1750 printf("tevent_req_poll() returned false\n");
1754 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1756 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1757 printf("smb2cli_session_setup_recv returned %s\n",
1762 status
= gensec_update(auth_generic_state
->gensec_security
,
1763 talloc_tos(), out_blob
, &in_blob
);
1764 if (!NT_STATUS_IS_OK(status
)) {
1765 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1769 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1770 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1771 if (!NT_STATUS_IS_OK(status
)) {
1772 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1776 status
= smb2cli_query_directory(
1777 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
1778 1, 0x3, 0, dir_persistent
, dir_volatile
,
1779 "session-reauth.txt", 0xffff,
1780 talloc_tos(), &dir_data
, &dir_data_length
);
1781 if (!NT_STATUS_IS_OK(status
)) {
1782 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1787 * query_info seems to be a path based operation on Windows...
1789 status
= smb2cli_query_info(cli
->conn
,
1793 SMB2_0_INFO_SECURITY
,
1794 0, /* in_file_info_class */
1795 1024, /* in_max_output_length */
1796 NULL
, /* in_input_buffer */
1797 SECINFO_OWNER
, /* in_additional_info */
1802 &out_output_buffer
);
1803 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1804 printf("smb2cli_query_info (security) returned %s\n", nt_errstr(status
));
1808 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1809 status
= smb2cli_query_info(cli
->conn
,
1815 1024, /* in_max_output_length */
1816 NULL
, /* in_input_buffer */
1817 0, /* in_additional_info */
1822 &out_output_buffer
);
1823 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1824 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1828 in_input_buffer
= data_blob_talloc(talloc_tos(), NULL
, 8);
1829 SBVAL(in_input_buffer
.data
, 0, 512);
1831 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1832 status
= smb2cli_set_info(cli
->conn
,
1839 0, /* in_additional_info */
1842 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1843 printf("smb2cli_set_info (position) returned %s\n", nt_errstr(status
));
1847 status
= smb2cli_create(
1852 "session-reauth-invalid.txt",
1853 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1854 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1855 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1856 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1859 FILE_SHARE_DELETE
, /* share_access, */
1860 FILE_CREATE
, /* create_disposition, */
1861 FILE_DELETE_ON_CLOSE
, /* create_options, */
1862 NULL
, /* smb2_create_blobs *blobs */
1869 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1870 printf("smb2cli_create %s\n", nt_errstr(status
));
1874 status
= smb2cli_create(
1880 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1881 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1882 SEC_STD_SYNCHRONIZE
|
1884 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
1885 0, /* file_attributes, */
1888 FILE_SHARE_DELETE
, /* share_access, */
1889 FILE_OPEN
, /* create_disposition, */
1890 FILE_SYNCHRONOUS_IO_NONALERT
|
1891 FILE_DIRECTORY_FILE
, /* create_options, */
1892 NULL
, /* smb2_create_blobs *blobs */
1899 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1900 printf("smb2cli_create returned %s\n", nt_errstr(status
));
1904 saved_tid
= smb2cli_tcon_current_id(cli
->smb2
.tcon
);
1905 saved_tcon
= cli
->smb2
.tcon
;
1906 cli
->smb2
.tcon
= smbXcli_tcon_create(cli
);
1907 smb2cli_tcon_set_values(cli
->smb2
.tcon
,
1912 0, /* capabilities */
1913 0 /* maximal_access */);
1914 status
= cli_tree_connect(cli
, share
, "?????", NULL
);
1915 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1916 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1919 talloc_free(cli
->smb2
.tcon
);
1920 cli
->smb2
.tcon
= saved_tcon
;
1922 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1927 SMB2_CAP_DFS
, /* in_capabilities */
1929 0, /* in_previous_session_id */
1930 &in_blob
); /* in_security_buffer */
1931 if (subreq
== NULL
) {
1932 printf("smb2cli_session_setup_send() returned NULL\n");
1936 ok
= tevent_req_poll(subreq
, ev
);
1938 printf("tevent_req_poll() returned false\n");
1942 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1943 &recv_iov
, &out_blob
);
1944 if (!NT_STATUS_IS_OK(status
)) {
1945 printf("smb2cli_session_setup_recv returned %s\n",
1950 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1951 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1952 if (!NT_STATUS_IS_OK(status
)) {
1953 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1957 status
= smb2cli_query_info(cli
->conn
,
1961 SMB2_0_INFO_SECURITY
,
1962 0, /* in_file_info_class */
1963 1024, /* in_max_output_length */
1964 NULL
, /* in_input_buffer */
1965 SECINFO_OWNER
, /* in_additional_info */
1970 &out_output_buffer
);
1971 if (!NT_STATUS_IS_OK(status
)) {
1972 printf("smb2cli_query_info (security) returned %s\n", nt_errstr(status
));
1976 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1977 status
= smb2cli_query_info(cli
->conn
,
1983 1024, /* in_max_output_length */
1984 NULL
, /* in_input_buffer */
1985 0, /* in_additional_info */
1990 &out_output_buffer
);
1991 if (!NT_STATUS_IS_OK(status
)) {
1992 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1996 in_input_buffer
= data_blob_talloc(talloc_tos(), NULL
, 8);
1997 SBVAL(in_input_buffer
.data
, 0, 512);
1999 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
2000 status
= smb2cli_set_info(cli
->conn
,
2007 0, /* in_additional_info */
2010 if (!NT_STATUS_IS_OK(status
)) {
2011 printf("smb2cli_set_info (position) returned %s\n", nt_errstr(status
));
2015 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
2016 status
= smb2cli_query_info(cli
->conn
,
2022 1024, /* in_max_output_length */
2023 NULL
, /* in_input_buffer */
2024 0, /* in_additional_info */
2029 &out_output_buffer
);
2030 if (!NT_STATUS_IS_OK(status
)) {
2031 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
2035 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
2036 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
2037 if (!NT_STATUS_IS_OK(status
)) {
2038 printf("smb2cli_close returned %s\n", nt_errstr(status
));
2042 status
= smb2cli_create(
2047 "session-reauth.txt",
2048 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
2049 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
2050 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
2051 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
2054 FILE_SHARE_DELETE
, /* share_access, */
2055 FILE_CREATE
, /* create_disposition, */
2056 FILE_DELETE_ON_CLOSE
, /* create_options, */
2057 NULL
, /* smb2_create_blobs *blobs */
2064 if (!NT_STATUS_IS_OK(status
)) {
2065 printf("smb2cli_create %s\n", nt_errstr(status
));
2069 status
= smb2cli_query_directory(
2070 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
2071 1, 0x3, 0, dir_persistent
, dir_volatile
,
2072 "session-reauth.txt", 0xffff,
2073 talloc_tos(), &dir_data
, &dir_data_length
);
2074 if (!NT_STATUS_IS_OK(status
)) {
2075 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
2079 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
2080 cli
->smb2
.tcon
, 0, dir_persistent
, dir_volatile
);
2081 if (!NT_STATUS_IS_OK(status
)) {
2082 printf("smb2cli_close returned %s\n", nt_errstr(status
));
2086 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
2087 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
2088 if (!NT_STATUS_IS_OK(status
)) {
2089 printf("smb2cli_close returned %s\n", nt_errstr(status
));
2093 saved_tid
= smb2cli_tcon_current_id(cli
->smb2
.tcon
);
2094 saved_tcon
= cli
->smb2
.tcon
;
2095 cli
->smb2
.tcon
= smbXcli_tcon_create(cli
);
2096 smb2cli_tcon_set_values(cli
->smb2
.tcon
,
2101 0, /* capabilities */
2102 0 /* maximal_access */);
2103 status
= cli_tree_connect(cli
, share
, "?????", NULL
);
2104 if (!NT_STATUS_IS_OK(status
)) {
2105 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
2108 talloc_free(cli
->smb2
.tcon
);
2109 cli
->smb2
.tcon
= saved_tcon
;
2114 static NTSTATUS
check_size(struct cli_state
*cli
,
2119 off_t size_read
= 0;
2121 NTSTATUS status
= cli_qfileinfo_basic(cli
,
2131 if (!NT_STATUS_IS_OK(status
)) {
2132 printf("cli_qfileinfo_basic of %s failed (%s)\n",
2138 if (size
!= size_read
) {
2139 printf("size (%u) != size_read(%u) for %s\n",
2141 (unsigned int)size_read
,
2143 /* Use EOF to mean bad size. */
2144 return NT_STATUS_END_OF_FILE
;
2146 return NT_STATUS_OK
;
2149 /* Ensure cli_ftruncate() works for SMB2. */
2151 bool run_smb2_ftruncate(int dummy
)
2153 struct cli_state
*cli
= NULL
;
2154 const char *fname
= "smb2_ftruncate.txt";
2155 uint16_t fnum
= (uint16_t)-1;
2156 bool correct
= false;
2157 size_t buflen
= 1024*1024;
2158 uint8_t *buf
= NULL
;
2162 printf("Starting SMB2-FTRUNCATE\n");
2164 if (!torture_init_connection(&cli
)) {
2168 status
= smbXcli_negprot(cli
->conn
,
2175 if (!NT_STATUS_IS_OK(status
)) {
2176 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
2180 status
= cli_session_setup_creds(cli
, torture_creds
);
2181 if (!NT_STATUS_IS_OK(status
)) {
2182 printf("cli_session_setup returned %s\n", nt_errstr(status
));
2186 status
= cli_tree_connect(cli
, share
, "?????", NULL
);
2187 if (!NT_STATUS_IS_OK(status
)) {
2188 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
2192 cli_setatr(cli
, fname
, 0, 0);
2193 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2195 status
= cli_ntcreate(cli
,
2199 FILE_ATTRIBUTE_NORMAL
,
2207 if (!NT_STATUS_IS_OK(status
)) {
2208 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
2212 buf
= talloc_zero_array(cli
, uint8_t, buflen
);
2218 status
= cli_writeall(cli
,
2226 if (!NT_STATUS_IS_OK(status
)) {
2227 printf("write of %u to %s failed (%s)\n",
2228 (unsigned int)buflen
,
2234 status
= check_size(cli
, fnum
, fname
, buflen
);
2235 if (!NT_STATUS_IS_OK(status
)) {
2239 /* Now ftruncate. */
2240 for ( i
= 0; i
< 10; i
++) {
2241 status
= cli_ftruncate(cli
, fnum
, i
*1024);
2242 if (!NT_STATUS_IS_OK(status
)) {
2243 printf("cli_ftruncate %u of %s failed (%s)\n",
2244 (unsigned int)i
*1024,
2249 status
= check_size(cli
, fnum
, fname
, i
*1024);
2250 if (!NT_STATUS_IS_OK(status
)) {
2263 if (fnum
!= (uint16_t)-1) {
2264 cli_close(cli
, fnum
);
2266 cli_setatr(cli
, fname
, 0, 0);
2267 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2269 if (!torture_close_connection(cli
)) {
2275 /* Ensure SMB2 flush on directories behaves correctly. */
2277 static bool test_dir_fsync(struct cli_state
*cli
, const char *path
)
2280 uint64_t fid_persistent
, fid_volatile
;
2281 uint8_t *dir_data
= NULL
;
2282 uint32_t dir_data_length
= 0;
2284 /* Open directory - no write abilities. */
2285 status
= smb2cli_create(
2291 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
2292 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
2293 SEC_STD_SYNCHRONIZE
|
2295 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
2296 0, /* file_attributes, */
2299 FILE_SHARE_DELETE
, /* share_access, */
2300 FILE_OPEN
, /* create_disposition, */
2301 FILE_SYNCHRONOUS_IO_NONALERT
|
2302 FILE_DIRECTORY_FILE
, /* create_options, */
2303 NULL
, /* smb2_create_blobs *blobs */
2310 if (!NT_STATUS_IS_OK(status
)) {
2311 printf("smb2cli_create '%s' (readonly) returned %s\n",
2317 status
= smb2cli_query_directory(
2318 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
2319 1, 0, 0, fid_persistent
, fid_volatile
, "*", 0xffff,
2320 talloc_tos(), &dir_data
, &dir_data_length
);
2322 if (!NT_STATUS_IS_OK(status
)) {
2323 printf("smb2cli_query_directory returned %s\n",
2328 /* Open directory no write access. Flush should fail. */
2330 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
2331 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
2332 if (!NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
)) {
2333 printf("smb2cli_flush on a read-only directory returned %s\n",
2338 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
2339 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
2340 if (!NT_STATUS_IS_OK(status
)) {
2341 printf("smb2cli_close returned %s\n", nt_errstr(status
));
2345 /* Open directory write-attributes only. Flush should still fail. */
2347 status
= smb2cli_create(
2353 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
2354 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
2355 SEC_STD_SYNCHRONIZE
|
2357 SEC_DIR_WRITE_ATTRIBUTE
|
2358 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
2359 0, /* file_attributes, */
2362 FILE_SHARE_DELETE
, /* share_access, */
2363 FILE_OPEN
, /* create_disposition, */
2364 FILE_SYNCHRONOUS_IO_NONALERT
|
2365 FILE_DIRECTORY_FILE
, /* create_options, */
2366 NULL
, /* smb2_create_blobs *blobs */
2373 if (!NT_STATUS_IS_OK(status
)) {
2374 printf("smb2cli_create '%s' (write attr) returned %s\n",
2380 status
= smb2cli_query_directory(
2381 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
2382 1, 0, 0, fid_persistent
, fid_volatile
, "*", 0xffff,
2383 talloc_tos(), &dir_data
, &dir_data_length
);
2385 if (!NT_STATUS_IS_OK(status
)) {
2386 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
2390 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
2391 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
2392 if (!NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
)) {
2393 printf("smb2cli_flush on a write-attributes directory "
2399 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
2400 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
2401 if (!NT_STATUS_IS_OK(status
)) {
2402 printf("smb2cli_close returned %s\n", nt_errstr(status
));
2406 /* Open directory with SEC_DIR_ADD_FILE access. Flush should now succeed. */
2408 status
= smb2cli_create(
2414 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
2415 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
2416 SEC_STD_SYNCHRONIZE
|
2418 SEC_DIR_ADD_FILE
, /* desired_access, */
2419 0, /* file_attributes, */
2422 FILE_SHARE_DELETE
, /* share_access, */
2423 FILE_OPEN
, /* create_disposition, */
2424 FILE_SYNCHRONOUS_IO_NONALERT
|
2425 FILE_DIRECTORY_FILE
, /* create_options, */
2426 NULL
, /* smb2_create_blobs *blobs */
2433 if (!NT_STATUS_IS_OK(status
)) {
2434 printf("smb2cli_create '%s' (write FILE access) returned %s\n",
2440 status
= smb2cli_query_directory(
2441 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
2442 1, 0, 0, fid_persistent
, fid_volatile
, "*", 0xffff,
2443 talloc_tos(), &dir_data
, &dir_data_length
);
2445 if (!NT_STATUS_IS_OK(status
)) {
2446 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
2450 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
2451 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
2452 if (!NT_STATUS_IS_OK(status
)) {
2453 printf("smb2cli_flush on a directory returned %s\n",
2458 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
2459 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
2460 if (!NT_STATUS_IS_OK(status
)) {
2461 printf("smb2cli_close returned %s\n", nt_errstr(status
));
2465 /* Open directory with SEC_DIR_ADD_FILE access. Flush should now succeed. */
2467 status
= smb2cli_create(
2473 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
2474 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
2475 SEC_STD_SYNCHRONIZE
|
2477 SEC_DIR_ADD_SUBDIR
, /* desired_access, */
2478 0, /* file_attributes, */
2481 FILE_SHARE_DELETE
, /* share_access, */
2482 FILE_OPEN
, /* create_disposition, */
2483 FILE_SYNCHRONOUS_IO_NONALERT
|
2484 FILE_DIRECTORY_FILE
, /* create_options, */
2485 NULL
, /* smb2_create_blobs *blobs */
2492 if (!NT_STATUS_IS_OK(status
)) {
2493 printf("smb2cli_create '%s' (write DIR access) returned %s\n",
2499 status
= smb2cli_query_directory(
2500 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
2501 1, 0, 0, fid_persistent
, fid_volatile
, "*", 0xffff,
2502 talloc_tos(), &dir_data
, &dir_data_length
);
2504 if (!NT_STATUS_IS_OK(status
)) {
2505 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
2509 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
2510 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
2511 if (!NT_STATUS_IS_OK(status
)) {
2512 printf("smb2cli_flush on a directory returned %s\n",
2517 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
2518 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
2519 if (!NT_STATUS_IS_OK(status
)) {
2520 printf("smb2cli_close returned %s\n", nt_errstr(status
));
2528 bool run_smb2_dir_fsync(int dummy
)
2530 struct cli_state
*cli
= NULL
;
2533 const char *dname
= "fsync_test_dir";
2535 printf("Starting SMB2-DIR-FSYNC\n");
2537 if (!torture_init_connection(&cli
)) {
2541 status
= smbXcli_negprot(cli
->conn
,
2548 if (!NT_STATUS_IS_OK(status
)) {
2549 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
2553 status
= cli_session_setup_creds(cli
, torture_creds
);
2554 if (!NT_STATUS_IS_OK(status
)) {
2555 printf("cli_session_setup returned %s\n", nt_errstr(status
));
2559 status
= cli_tree_connect(cli
, share
, "?????", NULL
);
2560 if (!NT_STATUS_IS_OK(status
)) {
2561 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
2565 (void)cli_rmdir(cli
, dname
);
2566 status
= cli_mkdir(cli
, dname
);
2567 if (!NT_STATUS_IS_OK(status
)) {
2568 printf("cli_mkdir(%s) returned %s\n",
2574 /* Test on a subdirectory. */
2575 bret
= test_dir_fsync(cli
, dname
);
2576 if (bret
== false) {
2577 (void)cli_rmdir(cli
, dname
);
2580 (void)cli_rmdir(cli
, dname
);
2582 /* Test on the root handle of a share. */
2583 bret
= test_dir_fsync(cli
, "");
2584 if (bret
== false) {
2590 bool run_smb2_path_slash(int dummy
)
2592 struct cli_state
*cli
= NULL
;
2594 uint64_t fid_persistent
;
2595 uint64_t fid_volatile
;
2596 const char *dname_noslash
= "smb2_dir_slash";
2597 const char *dname_backslash
= "smb2_dir_slash\\";
2598 const char *dname_slash
= "smb2_dir_slash/";
2599 const char *fname_noslash
= "smb2_file_slash";
2600 const char *fname_backslash
= "smb2_file_slash\\";
2601 const char *fname_slash
= "smb2_file_slash/";
2603 printf("Starting SMB2-PATH-SLASH\n");
2605 if (!torture_init_connection(&cli
)) {
2609 status
= smbXcli_negprot(cli
->conn
,
2616 if (!NT_STATUS_IS_OK(status
)) {
2617 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
2621 status
= cli_session_setup_creds(cli
, torture_creds
);
2622 if (!NT_STATUS_IS_OK(status
)) {
2623 printf("cli_session_setup returned %s\n", nt_errstr(status
));
2627 status
= cli_tree_connect(cli
, share
, "?????", NULL
);
2628 if (!NT_STATUS_IS_OK(status
)) {
2629 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
2633 (void)cli_unlink(cli
, dname_noslash
, 0);
2634 (void)cli_rmdir(cli
, dname_noslash
);
2635 (void)cli_unlink(cli
, fname_noslash
, 0);
2636 (void)cli_rmdir(cli
, fname_noslash
);
2638 /* Try to create a directory with the backslash name. */
2639 status
= smb2cli_create(
2645 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
2646 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
2647 FILE_READ_DATA
|FILE_READ_ATTRIBUTES
, /* desired_access, */
2648 0, /* file_attributes, */
2651 FILE_SHARE_DELETE
, /* share_access, */
2652 FILE_CREATE
, /* create_disposition, */
2653 FILE_DIRECTORY_FILE
, /* create_options, */
2654 NULL
, /* smb2_create_blobs *blobs */
2662 /* directory ending in '\\' should be success. */
2664 if (!NT_STATUS_IS_OK(status
)) {
2665 printf("smb2cli_create '%s' returned %s - "
2666 "should be NT_STATUS_OK\n",
2671 status
= smb2cli_close(cli
->conn
,
2678 if (!NT_STATUS_IS_OK(status
)) {
2679 printf("smb2cli_close returned %s\n", nt_errstr(status
));
2683 (void)cli_rmdir(cli
, dname_noslash
);
2685 /* Try to create a directory with the slash name. */
2686 status
= smb2cli_create(
2692 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
2693 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
2694 FILE_READ_DATA
|FILE_READ_ATTRIBUTES
, /* desired_access, */
2695 0, /* file_attributes, */
2698 FILE_SHARE_DELETE
, /* share_access, */
2699 FILE_CREATE
, /* create_disposition, */
2700 FILE_DIRECTORY_FILE
, /* create_options, */
2701 NULL
, /* smb2_create_blobs *blobs */
2709 /* directory ending in '/' is an error. */
2710 if (!NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_INVALID
)) {
2711 printf("smb2cli_create '%s' returned %s - "
2712 "should be NT_STATUS_OBJECT_NAME_INVALID\n",
2715 if (NT_STATUS_IS_OK(status
)) {
2716 (void)smb2cli_close(cli
->conn
,
2724 (void)cli_rmdir(cli
, dname_noslash
);
2728 (void)cli_rmdir(cli
, dname_noslash
);
2730 /* Try to create a file with the backslash name. */
2731 status
= smb2cli_create(
2737 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
2738 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
2739 FILE_READ_DATA
|FILE_READ_ATTRIBUTES
, /* desired_access, */
2740 0, /* file_attributes, */
2743 FILE_SHARE_DELETE
, /* share_access, */
2744 FILE_CREATE
, /* create_disposition, */
2745 FILE_NON_DIRECTORY_FILE
, /* create_options, */
2746 NULL
, /* smb2_create_blobs *blobs */
2754 /* file ending in '\\' should be error. */
2756 if (!NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_INVALID
)) {
2757 printf("smb2cli_create '%s' returned %s - "
2758 "should be NT_STATUS_OBJECT_NAME_INVALID\n",
2761 if (NT_STATUS_IS_OK(status
)) {
2762 (void)smb2cli_close(cli
->conn
,
2770 (void)cli_unlink(cli
, fname_noslash
, 0);
2774 (void)cli_unlink(cli
, fname_noslash
, 0);
2776 /* Try to create a file with the slash name. */
2777 status
= smb2cli_create(
2783 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
2784 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
2785 FILE_READ_DATA
|FILE_READ_ATTRIBUTES
, /* desired_access, */
2786 0, /* file_attributes, */
2789 FILE_SHARE_DELETE
, /* share_access, */
2790 FILE_CREATE
, /* create_disposition, */
2791 FILE_NON_DIRECTORY_FILE
, /* create_options, */
2792 NULL
, /* smb2_create_blobs *blobs */
2800 /* file ending in '/' should be error. */
2802 if (!NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_INVALID
)) {
2803 printf("smb2cli_create '%s' returned %s - "
2804 "should be NT_STATUS_OBJECT_NAME_INVALID\n",
2807 if (NT_STATUS_IS_OK(status
)) {
2808 (void)smb2cli_close(cli
->conn
,
2816 (void)cli_unlink(cli
, fname_noslash
, 0);
2820 (void)cli_unlink(cli
, fname_noslash
, 0);
2825 * NB. This can only work against a server where
2826 * the connecting user has been granted SeSecurityPrivilege.
2828 * 1). Create a test file.
2829 * 2). Open with SEC_FLAG_SYSTEM_SECURITY *only*. ACCESS_DENIED -
2830 * NB. SMB2-only behavior.
2831 * 3). Open with SEC_FLAG_SYSTEM_SECURITY|FILE_WRITE_ATTRIBUTES.
2832 * 4). Write SACL. Should fail with ACCESS_DENIED (seems to need WRITE_DAC).
2834 * 6). Open with SEC_FLAG_SYSTEM_SECURITY|SEC_STD_WRITE_DAC.
2835 * 7). Write SACL. Success.
2837 * 9). Open with SEC_FLAG_SYSTEM_SECURITY|READ_ATTRIBUTES.
2838 * 10). Read SACL. Success.
2839 * 11). Read DACL. Should fail with ACCESS_DENIED (no READ_CONTROL).
2843 bool run_smb2_sacl(int dummy
)
2845 struct cli_state
*cli
= NULL
;
2847 struct security_descriptor
*sd_dacl
= NULL
;
2848 struct security_descriptor
*sd_sacl
= NULL
;
2849 const char *fname
= "sacl_test_file";
2850 uint16_t fnum
= (uint16_t)-1;
2852 printf("Starting SMB2-SACL\n");
2854 if (!torture_init_connection(&cli
)) {
2858 status
= smbXcli_negprot(cli
->conn
,
2865 if (!NT_STATUS_IS_OK(status
)) {
2866 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
2870 status
= cli_session_setup_creds(cli
, torture_creds
);
2871 if (!NT_STATUS_IS_OK(status
)) {
2872 printf("cli_session_setup returned %s\n", nt_errstr(status
));
2876 status
= cli_tree_connect(cli
, share
, "?????", NULL
);
2877 if (!NT_STATUS_IS_OK(status
)) {
2878 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
2882 (void)cli_unlink(cli
, fname
, 0);
2884 /* First create a file. */
2885 status
= cli_ntcreate(cli
,
2889 FILE_ATTRIBUTE_NORMAL
,
2897 if (!NT_STATUS_IS_OK(status
)) {
2898 printf("Create of %s failed (%s)\n",
2904 cli_close(cli
, fnum
);
2905 fnum
= (uint16_t)-1;
2908 * Now try to open with *only* SEC_FLAG_SYSTEM_SECURITY.
2909 * This should fail with NT_STATUS_ACCESS_DENIED - but
2910 * only against an SMB2 server. SMB1 allows this as tested
2911 * in SMB1-SYSTEM-SECURITY.
2914 status
= cli_smb2_create_fnum(cli
,
2916 (struct cli_smb2_create_flags
){0},
2917 SMB2_IMPERSONATION_IMPERSONATION
,
2918 SEC_FLAG_SYSTEM_SECURITY
, /* desired access */
2919 0, /* file_attributes, */
2922 FILE_SHARE_DELETE
, /* share_access, */
2923 FILE_OPEN
, /* create_disposition, */
2924 FILE_NON_DIRECTORY_FILE
, /* create_options, */
2925 NULL
, /* in_cblobs. */
2927 NULL
, /* smb_create_returns */
2928 talloc_tos(), /* mem_ctx */
2929 NULL
); /* out_cblobs */
2931 if (NT_STATUS_EQUAL(status
, NT_STATUS_PRIVILEGE_NOT_HELD
)) {
2932 printf("SMB2-SACL-TEST can only work with a user "
2933 "who has been granted SeSecurityPrivilege.\n"
2935 "\"Manage auditing and security log\""
2936 "privilege setting on Windows\n");
2940 if (!NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
)) {
2941 printf("open file %s with SEC_FLAG_SYSTEM_SECURITY only: "
2942 "got %s - should fail with ACCESS_DENIED\n",
2949 * Open with SEC_FLAG_SYSTEM_SECURITY|FILE_WRITE_ATTRIBUTES.
2952 status
= cli_smb2_create_fnum(cli
,
2954 (struct cli_smb2_create_flags
){0},
2955 SMB2_IMPERSONATION_IMPERSONATION
,
2956 SEC_FLAG_SYSTEM_SECURITY
|
2957 FILE_WRITE_ATTRIBUTES
, /* desired access */
2958 0, /* file_attributes, */
2961 FILE_SHARE_DELETE
, /* share_access, */
2962 FILE_OPEN
, /* create_disposition, */
2963 FILE_NON_DIRECTORY_FILE
, /* create_options, */
2964 NULL
, /* in_cblobs. */
2966 NULL
, /* smb_create_returns */
2967 talloc_tos(), /* mem_ctx */
2968 NULL
); /* out_cblobs */
2970 if (!NT_STATUS_IS_OK(status
)) {
2971 printf("Open of %s with (SEC_FLAG_SYSTEM_SECURITY|"
2972 "FILE_WRITE_ATTRIBUTES) failed (%s)\n",
2978 /* Create an SD with a SACL. */
2979 sd_sacl
= security_descriptor_sacl_create(talloc_tos(),
2985 SEC_ACE_TYPE_SYSTEM_AUDIT
,
2987 SEC_ACE_FLAG_FAILED_ACCESS
,
2990 if (sd_sacl
== NULL
) {
2991 printf("Out of memory creating SACL\n");
2996 * Write the SACL SD. This should fail
2997 * even though we have SEC_FLAG_SYSTEM_SECURITY,
2998 * as it seems to also need WRITE_DAC access.
3000 status
= cli_set_security_descriptor(cli
,
3002 SECINFO_DACL
|SECINFO_SACL
,
3005 if (!NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
)) {
3006 printf("Writing SACL on file %s got (%s) "
3007 "should have failed with ACCESS_DENIED.\n",
3014 cli_smb2_close_fnum(cli
, fnum
);
3015 fnum
= (uint16_t)-1;
3018 * Open with SEC_FLAG_SYSTEM_SECURITY|SEC_STD_WRITE_DAC.
3021 status
= cli_smb2_create_fnum(cli
,
3023 (struct cli_smb2_create_flags
){0},
3024 SMB2_IMPERSONATION_IMPERSONATION
,
3025 SEC_FLAG_SYSTEM_SECURITY
|
3026 SEC_STD_WRITE_DAC
, /* desired access */
3027 0, /* file_attributes, */
3030 FILE_SHARE_DELETE
, /* share_access, */
3031 FILE_OPEN
, /* create_disposition, */
3032 FILE_NON_DIRECTORY_FILE
, /* create_options, */
3033 NULL
, /* in_cblobs. */
3035 NULL
, /* smb_create_returns */
3036 talloc_tos(), /* mem_ctx */
3037 NULL
); /* out_cblobs */
3039 if (!NT_STATUS_IS_OK(status
)) {
3040 printf("Open of %s with (SEC_FLAG_SYSTEM_SECURITY|"
3041 "FILE_WRITE_ATTRIBUTES) failed (%s)\n",
3048 * Write the SACL SD. This should now succeed
3049 * as we have both SEC_FLAG_SYSTEM_SECURITY
3050 * and WRITE_DAC access.
3052 status
= cli_set_security_descriptor(cli
,
3054 SECINFO_DACL
|SECINFO_SACL
,
3057 if (!NT_STATUS_IS_OK(status
)) {
3058 printf("cli_set_security_descriptor SACL "
3059 "on file %s failed (%s)\n",
3066 cli_smb2_close_fnum(cli
, fnum
);
3067 fnum
= (uint16_t)-1;
3069 /* We're done with the sacl we made. */
3070 TALLOC_FREE(sd_sacl
);
3073 * Now try to open with SEC_FLAG_SYSTEM_SECURITY|READ_ATTRIBUTES.
3074 * This gives us access to the SACL.
3077 status
= cli_smb2_create_fnum(cli
,
3079 (struct cli_smb2_create_flags
){0},
3080 SMB2_IMPERSONATION_IMPERSONATION
,
3081 SEC_FLAG_SYSTEM_SECURITY
|
3082 FILE_READ_ATTRIBUTES
, /* desired access */
3083 0, /* file_attributes, */
3086 FILE_SHARE_DELETE
, /* share_access, */
3087 FILE_OPEN
, /* create_disposition, */
3088 FILE_NON_DIRECTORY_FILE
, /* create_options, */
3089 NULL
, /* in_cblobs. */
3091 NULL
, /* smb_create_returns */
3092 talloc_tos(), /* mem_ctx */
3093 NULL
); /* out_cblobs */
3095 if (!NT_STATUS_IS_OK(status
)) {
3096 printf("Open of %s with (SEC_FLAG_SYSTEM_SECURITY|"
3097 "FILE_READ_ATTRIBUTES) failed (%s)\n",
3103 /* Try and read the SACL - should succeed. */
3104 status
= cli_query_security_descriptor(
3105 cli
, fnum
, SECINFO_SACL
, talloc_tos(), &sd_sacl
);
3107 if (!NT_STATUS_IS_OK(status
)) {
3108 printf("Read SACL from file %s failed (%s)\n",
3114 TALLOC_FREE(sd_sacl
);
3117 * Try and read the DACL - should fail as we have
3118 * no READ_DAC access.
3120 status
= cli_query_security_descriptor(
3121 cli
, fnum
, SECINFO_DACL
, talloc_tos(), &sd_sacl
);
3123 if (!NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
)) {
3124 printf("Reading DACL on file %s got (%s) "
3125 "should have failed with ACCESS_DENIED.\n",
3131 if (fnum
!= (uint16_t)-1) {
3132 cli_smb2_close_fnum(cli
, fnum
);
3133 fnum
= (uint16_t)-1;
3136 TALLOC_FREE(sd_dacl
);
3137 TALLOC_FREE(sd_sacl
);
3139 (void)cli_unlink(cli
, fname
, 0);
3144 TALLOC_FREE(sd_dacl
);
3145 TALLOC_FREE(sd_sacl
);
3147 if (fnum
!= (uint16_t)-1) {
3148 cli_smb2_close_fnum(cli
, fnum
);
3149 fnum
= (uint16_t)-1;
3152 (void)cli_unlink(cli
, fname
, 0);
3156 bool run_smb2_quota1(int dummy
)
3158 struct cli_state
*cli
= NULL
;
3160 uint16_t fnum
= (uint16_t)-1;
3161 SMB_NTQUOTA_STRUCT qt
= {0};
3163 printf("Starting SMB2-QUOTA1\n");
3165 if (!torture_init_connection(&cli
)) {
3169 status
= smbXcli_negprot(cli
->conn
,
3176 if (!NT_STATUS_IS_OK(status
)) {
3177 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
3181 status
= cli_session_setup_creds(cli
, torture_creds
);
3182 if (!NT_STATUS_IS_OK(status
)) {
3183 printf("cli_session_setup returned %s\n", nt_errstr(status
));
3187 status
= cli_tree_connect(cli
, share
, "?????", NULL
);
3188 if (!NT_STATUS_IS_OK(status
)) {
3189 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
3193 status
= cli_smb2_create_fnum(
3196 (struct cli_smb2_create_flags
){0},
3197 SMB2_IMPERSONATION_IMPERSONATION
,
3198 SEC_GENERIC_READ
, /* desired access */
3199 0, /* file_attributes, */
3202 FILE_SHARE_DELETE
, /* share_access, */
3203 FILE_OPEN
, /* create_disposition, */
3204 FILE_DIRECTORY_FILE
, /* create_options, */
3205 NULL
, /* in_cblobs. */
3207 NULL
, /* smb_create_returns */
3209 NULL
); /* out_cblobs */
3210 if (!NT_STATUS_IS_OK(status
)) {
3211 printf("cli_smb2_create_fnum failed: %s\n", nt_errstr(status
));
3215 status
= cli_smb2_get_user_quota(cli
, fnum
, &qt
);
3216 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
3217 printf("cli_smb2_get_user_quota returned %s, expected "
3218 "NT_STATUS_INVALID_HANDLE\n",
3226 bool run_smb2_stream_acl(int dummy
)
3228 struct cli_state
*cli
= NULL
;
3230 uint16_t fnum
= (uint16_t)-1;
3231 const char *fname
= "stream_acl_test_file";
3232 const char *sname
= "stream_acl_test_file:streamname";
3233 struct security_descriptor
*sd_dacl
= NULL
;
3236 printf("SMB2 stream acl\n");
3238 if (!torture_init_connection(&cli
)) {
3242 status
= smbXcli_negprot(cli
->conn
,
3249 if (!NT_STATUS_IS_OK(status
)) {
3250 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
3254 status
= cli_session_setup_creds(cli
, torture_creds
);
3255 if (!NT_STATUS_IS_OK(status
)) {
3256 printf("cli_session_setup returned %s\n", nt_errstr(status
));
3260 status
= cli_tree_connect(cli
, share
, "?????", NULL
);
3261 if (!NT_STATUS_IS_OK(status
)) {
3262 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
3266 /* Ensure file doesn't exist. */
3267 (void)cli_unlink(cli
, fname
, 0);
3269 /* Create the file. */
3270 status
= cli_ntcreate(cli
,
3274 FILE_ATTRIBUTE_NORMAL
,
3282 if (!NT_STATUS_IS_OK(status
)) {
3283 printf("Create of %s failed (%s)\n",
3289 /* Close the handle. */
3290 cli_smb2_close_fnum(cli
, fnum
);
3291 fnum
= (uint16_t)-1;
3293 /* Create the stream. */
3294 status
= cli_ntcreate(cli
,
3298 SEC_STD_READ_CONTROL
|
3300 FILE_ATTRIBUTE_NORMAL
,
3308 if (!NT_STATUS_IS_OK(status
)) {
3309 printf("Create of %s failed (%s)\n",
3315 /* Close the handle. */
3316 cli_smb2_close_fnum(cli
, fnum
);
3317 fnum
= (uint16_t)-1;
3320 * Open the stream - for Samba this ensures
3321 * we prove we have a pathref fsp.
3323 status
= cli_ntcreate(cli
,
3327 SEC_STD_READ_CONTROL
|
3329 FILE_ATTRIBUTE_NORMAL
,
3337 if (!NT_STATUS_IS_OK(status
)) {
3338 printf("Open of %s failed (%s)\n",
3344 /* Read the security descriptor off the stream handle. */
3345 status
= cli_query_security_descriptor(cli
,
3351 if (!NT_STATUS_IS_OK(status
)) {
3352 printf("Reading DACL on stream %s got (%s)\n",
3358 if (sd_dacl
== NULL
|| sd_dacl
->dacl
== NULL
||
3359 sd_dacl
->dacl
->num_aces
< 1) {
3360 printf("Invalid DACL returned on stream %s "
3361 "(this should not happen)\n",
3367 * Ensure it allows FILE_READ_DATA in the first ace.
3370 if ((sd_dacl
->dacl
->aces
[0].access_mask
& FILE_READ_DATA
) == 0) {
3371 printf("DACL->ace[0] returned on stream %s "
3372 "doesn't have read access (should not happen)\n",
3377 /* Remove FILE_READ_DATA from the first ace and set. */
3378 sd_dacl
->dacl
->aces
[0].access_mask
&= ~FILE_READ_DATA
;
3380 status
= cli_set_security_descriptor(cli
,
3385 if (!NT_STATUS_IS_OK(status
)) {
3386 printf("Setting DACL on stream %s got (%s)\n",
3392 TALLOC_FREE(sd_dacl
);
3394 /* Read again and check it changed. */
3395 status
= cli_query_security_descriptor(cli
,
3401 if (!NT_STATUS_IS_OK(status
)) {
3402 printf("Reading DACL on stream %s got (%s)\n",
3408 if (sd_dacl
== NULL
|| sd_dacl
->dacl
== NULL
||
3409 sd_dacl
->dacl
->num_aces
< 1) {
3410 printf("Invalid DACL (1) returned on stream %s "
3411 "(this should not happen)\n",
3416 /* FILE_READ_DATA should be gone from the first ace. */
3417 if ((sd_dacl
->dacl
->aces
[0].access_mask
& FILE_READ_DATA
) != 0) {
3418 printf("DACL on stream %s did not change\n",
3427 if (fnum
!= (uint16_t)-1) {
3428 cli_smb2_close_fnum(cli
, fnum
);
3429 fnum
= (uint16_t)-1;
3432 (void)cli_unlink(cli
, fname
, 0);
3436 static NTSTATUS
list_fn(struct file_info
*finfo
,
3440 bool *matched
= (bool *)state
;
3441 if (finfo
->attr
& FILE_ATTRIBUTE_DIRECTORY
) {
3444 return NT_STATUS_OK
;
3448 * Must be run against a share with "smbd async dosmode = yes".
3449 * Checks we can return DOS attriutes other than "N".
3450 * BUG: https://bugzilla.samba.org/show_bug.cgi?id=14758
3453 bool run_list_dir_async_test(int dummy
)
3455 struct cli_state
*cli
= NULL
;
3457 const char *dname
= "ASYNC_DIR";
3459 bool matched
= false;
3461 printf("SMB2 list dir async\n");
3463 if (!torture_init_connection(&cli
)) {
3467 status
= smbXcli_negprot(cli
->conn
,
3474 if (!NT_STATUS_IS_OK(status
)) {
3475 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
3479 status
= cli_session_setup_creds(cli
, torture_creds
);
3480 if (!NT_STATUS_IS_OK(status
)) {
3481 printf("cli_session_setup returned %s\n", nt_errstr(status
));
3485 status
= cli_tree_connect(cli
, share
, "?????", NULL
);
3486 if (!NT_STATUS_IS_OK(status
)) {
3487 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
3491 /* Ensure directory doesn't exist. */
3492 (void)cli_rmdir(cli
, dname
);
3494 status
= cli_mkdir(cli
, dname
);
3495 if (!NT_STATUS_IS_OK(status
)) {
3496 printf("cli_mkdir %s returned %s\n", dname
, nt_errstr(status
));
3500 status
= cli_list(cli
,
3502 FILE_ATTRIBUTE_NORMAL
|FILE_ATTRIBUTE_DIRECTORY
,
3505 if (!NT_STATUS_IS_OK(status
)) {
3506 printf("cli_list %s returned %s\n", dname
, nt_errstr(status
));
3511 printf("Failed to find %s\n", dname
);
3519 (void)cli_rmdir(cli
, dname
);
3524 * Test delete a directory fails if a file is created
3525 * in a directory after the delete on close is set.
3526 * BUG: https://bugzilla.samba.org/show_bug.cgi?id=14892
3529 bool run_delete_on_close_non_empty(int dummy
)
3531 struct cli_state
*cli
= NULL
;
3533 const char *dname
= "DEL_ON_CLOSE_DIR";
3534 const char *fname
= "DEL_ON_CLOSE_DIR\\testfile";
3535 uint16_t fnum
= (uint16_t)-1;
3536 uint16_t fnum1
= (uint16_t)-1;
3539 printf("SMB2 delete on close nonempty\n");
3541 if (!torture_init_connection(&cli
)) {
3545 status
= smbXcli_negprot(cli
->conn
,
3552 if (!NT_STATUS_IS_OK(status
)) {
3553 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
3557 status
= cli_session_setup_creds(cli
, torture_creds
);
3558 if (!NT_STATUS_IS_OK(status
)) {
3559 printf("cli_session_setup returned %s\n", nt_errstr(status
));
3563 status
= cli_tree_connect(cli
, share
, "?????", NULL
);
3564 if (!NT_STATUS_IS_OK(status
)) {
3565 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
3569 /* Ensure directory doesn't exist. */
3570 (void)cli_unlink(cli
,
3572 FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3573 (void)cli_rmdir(cli
, dname
);
3575 /* Create target directory. */
3576 status
= cli_ntcreate(cli
,
3579 DELETE_ACCESS
|FILE_READ_DATA
,
3580 FILE_ATTRIBUTE_DIRECTORY
,
3585 FILE_DIRECTORY_FILE
,
3589 if (!NT_STATUS_IS_OK(status
)) {
3590 printf("cli_ntcreate for directory %s returned %s\n",
3596 /* Now set the delete on close bit. */
3597 status
= cli_nt_delete_on_close(cli
, fnum
, 1);
3598 if (!NT_STATUS_IS_OK(status
)) {
3599 printf("cli_cli_nt_delete_on_close set for directory "
3606 /* Create file inside target directory. */
3608 * NB. On Windows this will return NT_STATUS_DELETE_PENDING. Only on
3609 * Samba will this succeed by default (the option "check parent
3610 * directory delete on close" configures behaviour), but we're using
3611 * this to test a race condition.
3613 status
= cli_ntcreate(cli
,
3617 FILE_ATTRIBUTE_NORMAL
,
3626 if (!NT_STATUS_IS_OK(status
)) {
3627 printf("cli_ntcreate for file %s returned %s\n",
3632 cli_close(cli
, fnum1
);
3633 fnum1
= (uint16_t)-1;
3635 /* Now the close should fail. */
3636 status
= cli_close(cli
, fnum
);
3637 if (!NT_STATUS_EQUAL(status
, NT_STATUS_DIRECTORY_NOT_EMPTY
)) {
3638 printf("cli_close for directory %s returned %s\n",
3648 if (fnum1
!= (uint16_t)-1) {
3649 cli_close(cli
, fnum1
);
3651 if (fnum
!= (uint16_t)-1) {
3652 cli_nt_delete_on_close(cli
, fnum
, 0);
3653 cli_close(cli
, fnum
);
3655 (void)cli_unlink(cli
,
3657 FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3658 (void)cli_rmdir(cli
, dname
);
3662 static NTSTATUS
check_empty_fn(struct file_info
*finfo
,
3666 unsigned int *pcount
= (unsigned int *)private_data
;
3668 if (ISDOT(finfo
->name
) || ISDOTDOT(finfo
->name
)) {
3670 return NT_STATUS_OK
;
3672 return NT_STATUS_DIRECTORY_NOT_EMPTY
;
3676 * Test setting the delete on close bit on a directory
3677 * containing an unwritable file fails or succeeds
3678 * an a share set with "hide unwritable = yes"
3679 * depending on the setting of "delete veto files".
3680 * BUG: https://bugzilla.samba.org/show_bug.cgi?id=15023
3682 * First version. With "delete veto files = yes"
3683 * setting the delete on close should succeed.
3686 bool run_delete_on_close_nonwrite_delete_yes_test(int dummy
)
3688 struct cli_state
*cli
= NULL
;
3690 const char *dname
= "delete_veto_yes";
3691 const char *list_dname
= "delete_veto_yes\\*";
3692 uint16_t fnum
= (uint16_t)-1;
3694 unsigned int list_count
= 0;
3696 printf("SMB2 delete on close nonwrite - delete veto yes\n");
3698 if (!torture_init_connection(&cli
)) {
3702 status
= smbXcli_negprot(cli
->conn
,
3709 if (!NT_STATUS_IS_OK(status
)) {
3710 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
3714 status
= cli_session_setup_creds(cli
, torture_creds
);
3715 if (!NT_STATUS_IS_OK(status
)) {
3716 printf("cli_session_setup returned %s\n", nt_errstr(status
));
3720 status
= cli_tree_connect(cli
, share
, "?????", NULL
);
3721 if (!NT_STATUS_IS_OK(status
)) {
3722 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
3726 /* Ensure target directory is seen as empty. */
3727 status
= cli_list(cli
,
3729 FILE_ATTRIBUTE_DIRECTORY
|
3730 FILE_ATTRIBUTE_HIDDEN
|
3731 FILE_ATTRIBUTE_SYSTEM
,
3734 if (!NT_STATUS_IS_OK(status
)) {
3735 printf("cli_list of %s returned %s\n",
3740 if (list_count
!= 2) {
3741 printf("cli_list of %s returned a count of %u\n",
3747 /* Open target directory. */
3748 status
= cli_ntcreate(cli
,
3751 DELETE_ACCESS
|FILE_READ_DATA
,
3752 FILE_ATTRIBUTE_DIRECTORY
,
3757 FILE_DIRECTORY_FILE
,
3761 if (!NT_STATUS_IS_OK(status
)) {
3762 printf("cli_ntcreate for directory %s returned %s\n",
3768 /* Now set the delete on close bit. */
3769 status
= cli_nt_delete_on_close(cli
, fnum
, 1);
3770 if (!NT_STATUS_IS_OK(status
)) {
3771 printf("cli_cli_nt_delete_on_close set for directory "
3772 "%s returned %s (should have succeeded)\n",
3782 if (fnum
!= (uint16_t)-1) {
3783 (void)cli_nt_delete_on_close(cli
, fnum
, 0);
3784 (void)cli_close(cli
, fnum
);
3790 * Test setting the delete on close bit on a directory
3791 * containing an unwritable file fails or succeeds
3792 * an a share set with "hide unwritable = yes"
3793 * depending on the setting of "delete veto files".
3794 * BUG: https://bugzilla.samba.org/show_bug.cgi?id=15023
3796 * Second version. With "delete veto files = no"
3797 * setting the delete on close should fail.
3800 bool run_delete_on_close_nonwrite_delete_no_test(int dummy
)
3802 struct cli_state
*cli
= NULL
;
3804 const char *dname
= "delete_veto_no";
3805 const char *list_dname
= "delete_veto_no\\*";
3806 uint16_t fnum
= (uint16_t)-1;
3808 unsigned int list_count
= 0;
3810 printf("SMB2 delete on close nonwrite - delete veto yes\n");
3812 if (!torture_init_connection(&cli
)) {
3816 status
= smbXcli_negprot(cli
->conn
,
3823 if (!NT_STATUS_IS_OK(status
)) {
3824 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
3828 status
= cli_session_setup_creds(cli
, torture_creds
);
3829 if (!NT_STATUS_IS_OK(status
)) {
3830 printf("cli_session_setup returned %s\n", nt_errstr(status
));
3834 status
= cli_tree_connect(cli
, share
, "?????", NULL
);
3835 if (!NT_STATUS_IS_OK(status
)) {
3836 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
3840 /* Ensure target directory is seen as empty. */
3841 status
= cli_list(cli
,
3843 FILE_ATTRIBUTE_DIRECTORY
|
3844 FILE_ATTRIBUTE_HIDDEN
|
3845 FILE_ATTRIBUTE_SYSTEM
,
3848 if (!NT_STATUS_IS_OK(status
)) {
3849 printf("cli_list of %s returned %s\n",
3854 if (list_count
!= 2) {
3855 printf("cli_list of %s returned a count of %u\n",
3861 /* Open target directory. */
3862 status
= cli_ntcreate(cli
,
3865 DELETE_ACCESS
|FILE_READ_DATA
,
3866 FILE_ATTRIBUTE_DIRECTORY
,
3871 FILE_DIRECTORY_FILE
,
3875 if (!NT_STATUS_IS_OK(status
)) {
3876 printf("cli_ntcreate for directory %s returned %s\n",
3882 /* Now set the delete on close bit. */
3883 status
= cli_nt_delete_on_close(cli
, fnum
, 1);
3884 if (NT_STATUS_IS_OK(status
)) {
3885 printf("cli_cli_nt_delete_on_close set for directory "
3886 "%s returned NT_STATUS_OK "
3887 "(should have failed)\n",
3891 if (!NT_STATUS_EQUAL(status
, NT_STATUS_DIRECTORY_NOT_EMPTY
)) {
3892 printf("cli_cli_nt_delete_on_close set for directory "
3894 "(should have returned "
3895 "NT_STATUS_DIRECTORY_NOT_EMPTY)\n",
3905 if (fnum
!= (uint16_t)-1) {
3906 (void)cli_nt_delete_on_close(cli
, fnum
, 0);
3907 (void)cli_close(cli
, fnum
);
3913 * Open an SMB2 file readonly and return the inode number.
3915 static NTSTATUS
get_smb2_inode(struct cli_state
*cli
,
3916 const char *pathname
,
3920 uint64_t fid_persistent
= 0;
3921 uint64_t fid_volatile
= 0;
3922 DATA_BLOB outbuf
= data_blob_null
;
3926 status
= smb2cli_create(cli
->conn
,
3931 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
3932 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
3933 SEC_STD_SYNCHRONIZE
|
3935 SEC_FILE_READ_ATTRIBUTE
, /* desired_access, */
3936 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
3937 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
3938 FILE_OPEN
, /* create_disposition, */
3939 0, /* create_options, */
3940 NULL
, /* smb2_create_blobs *blobs */
3943 NULL
, /* struct smb_create_returns * */
3944 talloc_tos(), /* mem_ctx. */
3945 NULL
, /* struct smb2_create_blobs * */
3946 NULL
); /* struct symlink_reparse_struct */
3947 if (!NT_STATUS_IS_OK(status
)) {
3954 status
= smb2cli_query_info(
3960 FSCC_FILE_ALL_INFORMATION
, /* in_file_info_class */
3961 1024, /* in_max_output_length */
3962 NULL
, /* in_input_buffer */
3963 0, /* in_additional_info */
3970 if (NT_STATUS_IS_OK(status
)) {
3971 *ino_ret
= PULL_LE_U64(outbuf
.data
, 0x40);
3974 (void)smb2cli_close(cli
->conn
,
3985 * Check an inode matches a given SMB2 path.
3987 static bool smb2_inode_matches(struct cli_state
*cli
,
3988 const char *match_pathname
,
3989 uint64_t ino_tomatch
,
3990 const char *test_pathname
)
3992 uint64_t test_ino
= 0;
3995 status
= get_smb2_inode(cli
,
3998 if (!NT_STATUS_IS_OK(status
)) {
3999 printf("%s: Failed to get ino "
4000 "number for %s, (%s)\n",
4006 if (test_ino
!= ino_tomatch
) {
4007 printf("%s: Inode mismatch, ino_tomatch (%s) "
4008 "ino=%"PRIu64
" test (%s) "
4021 * Delete an SMB2 file on a DFS share.
4023 static NTSTATUS
smb2_dfs_delete(struct cli_state
*cli
,
4024 const char *pathname
)
4027 uint64_t fid_persistent
= 0;
4028 uint64_t fid_volatile
= 0;
4035 status
= smb2cli_create(cli
->conn
,
4040 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
4041 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
4042 SEC_STD_SYNCHRONIZE
|
4043 SEC_STD_DELETE
, /* desired_access, */
4044 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
4045 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
4046 FILE_OPEN
, /* create_disposition, */
4047 0, /* create_options, */
4048 NULL
, /* smb2_create_blobs *blobs */
4051 NULL
, /* struct smb_create_returns * */
4052 talloc_tos(), /* mem_ctx. */
4053 NULL
, /* struct smb2_create_blobs * */
4054 NULL
); /* struct symlink_reparse_struct */
4055 if (!NT_STATUS_IS_OK(status
)) {
4060 * Set delete on close.
4062 PUSH_LE_U8(&data
[0], 0, 1);
4063 inbuf
.data
= &data
[0];
4066 status
= smb2cli_set_info(cli
->conn
,
4070 SMB2_0_INFO_FILE
, /* info_type. */
4071 SMB_FILE_DISPOSITION_INFORMATION
- 1000, /* info_class */
4073 0, /* additional_info. */
4076 if (!NT_STATUS_IS_OK(status
)) {
4079 status
= smb2cli_close(cli
->conn
,
4090 * Rename or hardlink an SMB2 file on a DFS share.
4092 static NTSTATUS
smb2_dfs_setinfo_name(struct cli_state
*cli
,
4093 uint64_t fid_persistent
,
4094 uint64_t fid_volatile
,
4095 const char *newname
,
4100 smb_ucs2_t
*converted_str
= NULL
;
4101 size_t converted_size_bytes
= 0;
4103 uint8_t info_class
= 0;
4106 ok
= push_ucs2_talloc(talloc_tos(),
4109 &converted_size_bytes
);
4111 return NT_STATUS_INVALID_PARAMETER
;
4114 * W2K8 insists the dest name is not null terminated. Remove
4115 * the last 2 zero bytes and reduce the name length.
4117 if (converted_size_bytes
< 2) {
4118 return NT_STATUS_INVALID_PARAMETER
;
4120 converted_size_bytes
-= 2;
4121 inbuf_size
= 20 + converted_size_bytes
;
4122 if (inbuf_size
< 20) {
4123 /* Integer wrap check. */
4124 return NT_STATUS_INVALID_PARAMETER
;
4128 * The Windows 10 SMB2 server has a minimum length
4129 * for a SMB2_FILE_RENAME_INFORMATION buffer of
4130 * 24 bytes. It returns NT_STATUS_INFO_LENGTH_MISMATCH
4131 * if the length is less.
4133 inbuf_size
= MAX(inbuf_size
, 24);
4134 inbuf
= data_blob_talloc_zero(talloc_tos(), inbuf_size
);
4135 if (inbuf
.data
== NULL
) {
4136 return NT_STATUS_NO_MEMORY
;
4138 PUSH_LE_U32(inbuf
.data
, 16, converted_size_bytes
);
4139 memcpy(inbuf
.data
+ 20, converted_str
, converted_size_bytes
);
4140 TALLOC_FREE(converted_str
);
4142 if (do_rename
== true) {
4143 info_class
= SMB_FILE_RENAME_INFORMATION
- 1000;
4146 info_class
= SMB_FILE_LINK_INFORMATION
- 1000;
4149 status
= smb2cli_set_info(cli
->conn
,
4153 SMB2_0_INFO_FILE
, /* info_type. */
4154 info_class
, /* info_class */
4156 0, /* additional_info. */
4162 static NTSTATUS
smb2_dfs_rename(struct cli_state
*cli
,
4163 uint64_t fid_persistent
,
4164 uint64_t fid_volatile
,
4165 const char *newname
)
4167 return smb2_dfs_setinfo_name(cli
,
4171 true); /* do_rename */
4174 static NTSTATUS
smb2_dfs_hlink(struct cli_state
*cli
,
4175 uint64_t fid_persistent
,
4176 uint64_t fid_volatile
,
4177 const char *newname
)
4179 return smb2_dfs_setinfo_name(cli
,
4183 false); /* do_rename */
4189 * https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/dc9978d7-6299-4c5a-a22d-a039cdc716ea
4191 * (Characters " \ / [ ] : | < > + = ; , * ?,
4192 * and control characters in range 0x00 through
4193 * 0x1F, inclusive, are illegal in a share name)
4195 * But Windows server only checks in DFS sharenames ':'. All other
4196 * share names are allowed.
4199 static bool test_smb2_dfs_sharenames(struct cli_state
*cli
,
4200 const char *dfs_root_share_name
,
4204 const char *test_str
= "/[]:|<>+=;,*?";
4207 bool ino_matched
= false;
4209 /* Setup template pathname. */
4210 memcpy(test_path
, "SERVER\\X", 9);
4212 /* Test invalid control characters. */
4213 for (i
= 1; i
< 0x20; i
++) {
4215 ino_matched
= smb2_inode_matches(cli
,
4216 dfs_root_share_name
,
4224 /* Test explicit invalid characters. */
4225 for (p
= test_str
; *p
!= '\0'; p
++) {
4229 * Only ':' is treated as an INVALID sharename
4230 * for a DFS SERVER\\SHARE path.
4232 uint64_t test_ino
= 0;
4233 NTSTATUS status
= get_smb2_inode(cli
,
4236 if (!NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_INVALID
)) {
4237 printf("%s:%d Open of %s should get "
4238 "NT_STATUS_OBJECT_NAME_INVALID, got %s\n",
4246 ino_matched
= smb2_inode_matches(cli
,
4247 dfs_root_share_name
,
4259 * "Raw" test of SMB2 paths to a DFS share.
4260 * We must use the lower level smb2cli_XXXX() interfaces,
4261 * not the cli_XXX() ones here as the ultimate goal is to fix our
4262 * cli_XXX() interfaces to work transparently over DFS.
4264 * So here, we're testing the server code, not the client code.
4266 * Passes cleanly against Windows.
4269 bool run_smb2_dfs_paths(int dummy
)
4271 struct cli_state
*cli
= NULL
;
4273 bool dfs_supported
= false;
4274 char *dfs_root_share_name
= NULL
;
4275 uint64_t root_ino
= 0;
4276 uint64_t test_ino
= 0;
4277 bool ino_matched
= false;
4278 uint64_t fid_persistent
= 0;
4279 uint64_t fid_volatile
= 0;
4280 bool retval
= false;
4283 printf("Starting SMB2-DFS-PATHS\n");
4285 if (!torture_init_connection(&cli
)) {
4289 status
= smbXcli_negprot(cli
->conn
,
4296 if (!NT_STATUS_IS_OK(status
)) {
4297 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
4301 status
= cli_session_setup_creds(cli
, torture_creds
);
4302 if (!NT_STATUS_IS_OK(status
)) {
4303 printf("cli_session_setup returned %s\n", nt_errstr(status
));
4307 status
= cli_tree_connect(cli
, share
, "?????", NULL
);
4308 if (!NT_STATUS_IS_OK(status
)) {
4309 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
4313 /* Ensure this is a DFS share. */
4314 dfs_supported
= smbXcli_conn_dfs_supported(cli
->conn
);
4315 if (!dfs_supported
) {
4316 printf("Server %s does not support DFS\n",
4317 smbXcli_conn_remote_name(cli
->conn
));
4320 dfs_supported
= smbXcli_tcon_is_dfs_share(cli
->smb2
.tcon
);
4321 if (!dfs_supported
) {
4322 printf("Share %s does not support DFS\n",
4327 * Create the "official" DFS share root name.
4328 * No SMB2 paths can start with '\\'.
4330 dfs_root_share_name
= talloc_asprintf(talloc_tos(),
4332 smbXcli_conn_remote_name(cli
->conn
),
4334 if (dfs_root_share_name
== NULL
) {
4335 printf("Out of memory\n");
4339 /* Get the share root inode number. */
4340 status
= get_smb2_inode(cli
,
4341 dfs_root_share_name
,
4343 if (!NT_STATUS_IS_OK(status
)) {
4344 printf("%s:%d Failed to get ino number for share root %s, (%s)\n",
4347 dfs_root_share_name
,
4353 * Test the Windows algorithm for parsing DFS names.
4356 * A single "SERVER" element should open and match the share root.
4358 ino_matched
= smb2_inode_matches(cli
,
4359 dfs_root_share_name
,
4361 smbXcli_conn_remote_name(cli
->conn
));
4363 printf("%s:%d Failed to match ino number for %s\n",
4366 smbXcli_conn_remote_name(cli
->conn
));
4371 * An "" DFS empty server name should open and match the share root on
4372 * Windows 2008. Windows 2022 returns NT_STATUS_INVALID_PARAMETER
4373 * for a DFS empty server name.
4375 status
= get_smb2_inode(cli
,
4378 if (NT_STATUS_IS_OK(status
)) {
4380 * Windows 2008 - open succeeded. Proceed to
4383 ino_matched
= smb2_inode_matches(cli
,
4384 dfs_root_share_name
,
4388 printf("%s:%d Failed to match ino number for %s\n",
4395 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_PARAMETER
)) {
4397 * For Windows 2022 we expect to fail with
4398 * NT_STATUS_INVALID_PARAMETER. Anything else is
4401 printf("%s:%d Unexpected error (%s) getting ino number for %s\n",
4408 /* A "BAD" server name should open and match the share root. */
4409 ino_matched
= smb2_inode_matches(cli
,
4410 dfs_root_share_name
,
4414 printf("%s:%d Failed to match ino number for %s\n",
4421 * A "BAD\\BAD" server and share name should open
4422 * and match the share root.
4424 ino_matched
= smb2_inode_matches(cli
,
4425 dfs_root_share_name
,
4429 printf("%s:%d Failed to match ino number for %s\n",
4436 * Trying to open "BAD\\BAD\\BAD" should get
4437 * NT_STATUS_OBJECT_NAME_NOT_FOUND.
4439 status
= get_smb2_inode(cli
,
4442 if (!NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
4443 printf("%s:%d Open of %s should get "
4444 "STATUS_OBJECT_NAME_NOT_FOUND, got %s\n",
4452 * Trying to open "BAD\\BAD\\BAD\\BAD" should get
4453 * NT_STATUS_OBJECT_PATH_NOT_FOUND.
4455 status
= get_smb2_inode(cli
,
4456 "BAD\\BAD\\BAD\\BAD",
4458 if (!NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_PATH_NOT_FOUND
)) {
4459 printf("%s:%d Open of %s should get "
4460 "STATUS_OBJECT_NAME_NOT_FOUND, got %s\n",
4463 "BAD\\BAD\\BAD\\BAD",
4468 * Test for invalid pathname characters in the servername.
4469 * They are ignored, and it still opens the share root.
4471 ino_matched
= smb2_inode_matches(cli
,
4472 dfs_root_share_name
,
4476 printf("%s:%d Failed to match ino number for %s\n",
4484 * Test for invalid pathname characters in the sharename.
4485 * Invalid sharename characters should still be flagged as
4486 * NT_STATUS_OBJECT_NAME_INVALID. It turns out only ':'
4487 * is considered an invalid sharename character.
4489 ok
= test_smb2_dfs_sharenames(cli
,
4490 dfs_root_share_name
,
4496 /* Now create a file called "file". */
4497 status
= smb2cli_create(cli
->conn
,
4502 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
4503 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
4504 SEC_STD_SYNCHRONIZE
|
4507 SEC_FILE_READ_ATTRIBUTE
, /* desired_access, */
4508 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
4509 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
4510 FILE_CREATE
, /* create_disposition, */
4511 0, /* create_options, */
4512 NULL
, /* smb2_create_blobs *blobs */
4515 NULL
, /* struct smb_create_returns * */
4516 talloc_tos(), /* mem_ctx. */
4517 NULL
, /* struct smb2_create_blobs * */
4518 NULL
); /* struct symlink_reparse_struct */
4519 if (!NT_STATUS_IS_OK(status
)) {
4520 printf("%s:%d smb2cli_create on %s returned %s\n",
4529 * Trying to open "BAD\\BAD\\file" should now get
4532 status
= get_smb2_inode(cli
,
4535 if (!NT_STATUS_IS_OK(status
)) {
4536 printf("%s:%d Open of %s should succeed "
4546 * Now show that renames use relative,
4547 * not full DFS paths.
4550 /* Full DFS path should fail. */
4551 status
= smb2_dfs_rename(cli
,
4554 "ANY\\NAME\\renamed_file");
4555 if (!NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_PATH_NOT_FOUND
)) {
4556 printf("%s:%d Rename of %s -> %s should fail "
4557 "with NT_STATUS_OBJECT_PATH_NOT_FOUND. Got %s\n",
4561 "ANY\\NAME\\renamed_file",
4565 /* Relative DFS path should succeed. */
4566 status
= smb2_dfs_rename(cli
,
4570 if (!NT_STATUS_IS_OK(status
)) {
4571 printf("%s:%d: Rename of %s -> %s should succeed. "
4582 * Trying to open "BAD\\BAD\\renamed_file" should now get
4585 status
= get_smb2_inode(cli
,
4586 "BAD\\BAD\\renamed_file",
4588 if (!NT_STATUS_IS_OK(status
)) {
4589 printf("%s:%d: Open of %s should succeed "
4593 "BAD\\BAD\\renamed_file",
4599 * Now show that hard links use relative,
4600 * not full DFS paths.
4603 /* Full DFS path should fail. */
4604 status
= smb2_dfs_hlink(cli
,
4607 "ANY\\NAME\\hlink");
4608 if (!NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_PATH_NOT_FOUND
)) {
4609 printf("%s:%d Hlink of %s -> %s should fail "
4610 "with NT_STATUS_OBJECT_PATH_NOT_FOUND. Got %s\n",
4613 "ANY\\NAME\\renamed_file",
4618 /* Relative DFS path should succeed. */
4619 status
= smb2_dfs_hlink(cli
,
4623 if (!NT_STATUS_IS_OK(status
)) {
4624 printf("%s:%d: Hlink of %s -> %s should succeed. "
4628 "ANY\\NAME\\renamed_file",
4635 * Trying to open "BAD\\BAD\\hlink" should now get
4638 status
= get_smb2_inode(cli
,
4641 if (!NT_STATUS_IS_OK(status
)) {
4642 printf("%s:%d Open of %s should succeed "
4655 if (fid_persistent
!= 0 || fid_volatile
!= 0) {
4656 smb2cli_close(cli
->conn
,
4664 /* Delete anything we made. */
4665 (void)smb2_dfs_delete(cli
, "BAD\\BAD\\BAD");
4666 (void)smb2_dfs_delete(cli
, "BAD\\BAD\\file");
4667 (void)smb2_dfs_delete(cli
, "BAD\\BAD\\renamed_file");
4668 (void)smb2_dfs_delete(cli
, "BAD\\BAD\\hlink");
4673 * Add a test that sends DFS paths and sets the
4674 * SMB2 flag FLAGS2_DFS_PATHNAMES, but to a non-DFS
4675 * share. Windows passes this (it just treats the
4676 * pathnames as non-DFS and ignores the FLAGS2_DFS_PATHNAMES
4680 bool run_smb2_non_dfs_share(int dummy
)
4682 struct cli_state
*cli
= NULL
;
4684 bool dfs_supported
= false;
4685 uint64_t fid_persistent
= 0;
4686 uint64_t fid_volatile
= 0;
4687 bool retval
= false;
4688 char *dfs_filename
= NULL
;
4690 printf("Starting SMB2-DFS-NON-DFS-SHARE\n");
4692 if (!torture_init_connection(&cli
)) {
4696 status
= smbXcli_negprot(cli
->conn
,
4703 if (!NT_STATUS_IS_OK(status
)) {
4704 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
4708 status
= cli_session_setup_creds(cli
, torture_creds
);
4709 if (!NT_STATUS_IS_OK(status
)) {
4710 printf("cli_session_setup returned %s\n", nt_errstr(status
));
4714 status
= cli_tree_connect(cli
, share
, "?????", NULL
);
4715 if (!NT_STATUS_IS_OK(status
)) {
4716 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
4720 dfs_supported
= smbXcli_conn_dfs_supported(cli
->conn
);
4721 if (!dfs_supported
) {
4722 printf("Server %s does not support DFS\n",
4723 smbXcli_conn_remote_name(cli
->conn
));
4726 /* Ensure this is *NOT* a DFS share. */
4727 dfs_supported
= smbXcli_tcon_is_dfs_share(cli
->smb2
.tcon
);
4728 if (dfs_supported
) {
4729 printf("Share %s is a DFS share.\n",
4734 * Force the share to be DFS, as far as the client
4737 smb2cli_tcon_set_values(cli
->smb2
.tcon
,
4739 smb2cli_tcon_current_id(cli
->smb2
.tcon
),
4741 smb2cli_tcon_flags(cli
->smb2
.tcon
),
4742 smb2cli_tcon_capabilities(cli
->smb2
.tcon
) |
4746 /* Come up with a "valid" SMB2 DFS name. */
4747 dfs_filename
= talloc_asprintf(talloc_tos(),
4749 smbXcli_conn_remote_name(cli
->conn
),
4751 if (dfs_filename
== NULL
) {
4752 printf("Out of memory\n");
4756 /* Now try create dfs_filename. */
4757 status
= smb2cli_create(cli
->conn
,
4762 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
4763 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
4764 SEC_STD_SYNCHRONIZE
|
4767 SEC_FILE_READ_ATTRIBUTE
, /* desired_access, */
4768 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
4769 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
4770 FILE_CREATE
, /* create_disposition, */
4771 0, /* create_options, */
4772 NULL
, /* smb2_create_blobs *blobs */
4775 NULL
, /* struct smb_create_returns * */
4776 talloc_tos(), /* mem_ctx. */
4777 NULL
, /* struct smb2_create_blobs */
4778 NULL
); /* struct symlink_reparse_struct */
4780 * Should fail with NT_STATUS_OBJECT_PATH_NOT_FOUND, as
4781 * even though we set the FLAGS2_DFS_PATHNAMES the server
4782 * knows this isn't a DFS share and so treats BAD\\BAD as
4783 * part of the filename.
4785 if (!NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_PATH_NOT_FOUND
)) {
4786 printf("%s:%d create of %s should fail "
4787 "with NT_STATUS_OBJECT_PATH_NOT_FOUND. Got %s\n",
4795 * Prove we can still use non-DFS pathnames, even though
4796 * we are setting the FLAGS2_DFS_PATHNAMES in the SMB2
4799 status
= smb2cli_create(cli
->conn
,
4804 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
4805 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
4806 SEC_STD_SYNCHRONIZE
|
4809 SEC_FILE_READ_ATTRIBUTE
, /* desired_access, */
4810 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
4811 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
4812 FILE_CREATE
, /* create_disposition, */
4813 0, /* create_options, */
4814 NULL
, /* smb2_create_blobs *blobs */
4817 NULL
, /* struct smb_create_returns * */
4818 talloc_tos(), /* mem_ctx. */
4819 NULL
, /* struct smb2_create_blobs * */
4820 NULL
); /* struct symlink_reparse_struct */
4821 if (!NT_STATUS_IS_OK(status
)) {
4822 printf("%s:%d smb2cli_create on %s returned %s\n",
4834 (void)smb2_dfs_delete(cli
, dfs_filename
);
4835 (void)smb2_dfs_delete(cli
, "file");
4840 * Add a test that sends a non-DFS path and does not set the
4841 * SMB2 flag FLAGS2_DFS_PATHNAMES to a DFS
4842 * share. Windows passes this (it just treats the
4843 * pathnames as non-DFS).
4846 bool run_smb2_dfs_share_non_dfs_path(int dummy
)
4848 struct cli_state
*cli
= NULL
;
4850 bool dfs_supported
= false;
4851 uint64_t fid_persistent
= 0;
4852 uint64_t fid_volatile
= 0;
4853 bool retval
= false;
4854 char *dfs_filename
= NULL
;
4855 uint64_t root_ino
= (uint64_t)-1;
4856 bool ino_matched
= false;
4858 printf("Starting SMB2-DFS-SHARE-NON-DFS-PATH\n");
4860 if (!torture_init_connection(&cli
)) {
4864 status
= smbXcli_negprot(cli
->conn
,
4871 if (!NT_STATUS_IS_OK(status
)) {
4872 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
4876 status
= cli_session_setup_creds(cli
, torture_creds
);
4877 if (!NT_STATUS_IS_OK(status
)) {
4878 printf("cli_session_setup returned %s\n", nt_errstr(status
));
4882 status
= cli_tree_connect(cli
, share
, "?????", NULL
);
4883 if (!NT_STATUS_IS_OK(status
)) {
4884 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
4888 dfs_supported
= smbXcli_conn_dfs_supported(cli
->conn
);
4889 if (!dfs_supported
) {
4890 printf("Server %s does not support DFS\n",
4891 smbXcli_conn_remote_name(cli
->conn
));
4894 /* Ensure this is a DFS share. */
4895 dfs_supported
= smbXcli_tcon_is_dfs_share(cli
->smb2
.tcon
);
4896 if (!dfs_supported
) {
4897 printf("Share %s is not a DFS share.\n",
4901 /* Come up with a "valid" SMB2 DFS name. */
4902 dfs_filename
= talloc_asprintf(talloc_tos(),
4904 smbXcli_conn_remote_name(cli
->conn
),
4906 if (dfs_filename
== NULL
) {
4907 printf("Out of memory\n");
4911 /* Get the root of the share ino. */
4912 status
= get_smb2_inode(cli
,
4915 if (!NT_STATUS_IS_OK(status
)) {
4916 printf("%s:%d get_smb2_inode on %s returned %s\n",
4924 /* Create a dfs_filename. */
4925 status
= smb2cli_create(cli
->conn
,
4930 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
4931 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
4932 SEC_STD_SYNCHRONIZE
|
4935 SEC_FILE_READ_ATTRIBUTE
, /* desired_access, */
4936 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
4937 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
4938 FILE_CREATE
, /* create_disposition, */
4939 0, /* create_options, */
4940 NULL
, /* smb2_create_blobs *blobs */
4943 NULL
, /* struct smb_create_returns * */
4944 talloc_tos(), /* mem_ctx. */
4945 NULL
, /* struct smb2_create_blobs * */
4946 NULL
); /* psymlink */
4947 if (!NT_STATUS_IS_OK(status
)) {
4948 printf("%s:%d smb2cli_create on %s returned %s\n",
4956 /* Close the handle we just opened. */
4957 smb2cli_close(cli
->conn
,
4969 * Force the share to be non-DFS, as far as the client
4972 smb2cli_tcon_set_values(cli
->smb2
.tcon
,
4974 smb2cli_tcon_current_id(cli
->smb2
.tcon
),
4976 smb2cli_tcon_flags(cli
->smb2
.tcon
),
4977 smb2cli_tcon_capabilities(cli
->smb2
.tcon
) &
4978 ~SMB2_SHARE_CAP_DFS
,
4982 * Prove we can still use non-DFS pathnames on a DFS
4983 * share so long as we don't set the FLAGS2_DFS_PATHNAMES
4984 * in the SMB2 request.
4986 status
= smb2cli_create(cli
->conn
,
4991 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
4992 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
4993 SEC_STD_SYNCHRONIZE
|
4996 SEC_FILE_READ_ATTRIBUTE
, /* desired_access, */
4997 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
4998 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
4999 FILE_OPEN
, /* create_disposition, */
5000 0, /* create_options, */
5001 NULL
, /* smb2_create_blobs *blobs */
5004 NULL
, /* struct smb_create_returns * */
5005 talloc_tos(), /* mem_ctx. */
5006 NULL
, /* struct smb2_create_blobs * */
5007 NULL
); /* psymlink */
5008 if (!NT_STATUS_IS_OK(status
)) {
5009 printf("%s:%d smb2cli_create on %s returned %s\n",
5018 * Show that now we're using non-DFS pathnames
5019 * on a DFS share, "" opens the root of the share.
5021 ino_matched
= smb2_inode_matches(cli
,
5026 printf("%s:%d Failed to match ino number for %s\n",
5037 if (fid_volatile
!= 0) {
5038 smb2cli_close(cli
->conn
,
5046 (void)smb2_dfs_delete(cli
, "file");
5047 (void)smb2_dfs_delete(cli
, dfs_filename
);
5052 * "Raw" test of an SMB2 filename with one or more leading
5053 * backslash characters to a DFS share.
5055 * BUG: https://bugzilla.samba.org/show_bug.cgi?id=15277
5057 * Once the server passes SMB2-DFS-PATHS we can
5058 * fold this test into that one.
5060 * Passes cleanly against Windows.
5063 bool run_smb2_dfs_filename_leading_backslash(int dummy
)
5065 struct cli_state
*cli
= NULL
;
5067 bool dfs_supported
= false;
5068 char *dfs_filename_slash
= NULL
;
5069 char *dfs_filename_slash_multi
= NULL
;
5070 uint64_t file_ino
= 0;
5071 bool ino_matched
= false;
5072 uint64_t fid_persistent
= 0;
5073 uint64_t fid_volatile
= 0;
5074 bool retval
= false;
5076 printf("Starting SMB2-DFS-FILENAME-LEADING-BACKSLASH\n");
5078 if (!torture_init_connection(&cli
)) {
5082 status
= smbXcli_negprot(cli
->conn
,
5089 if (!NT_STATUS_IS_OK(status
)) {
5090 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
5094 status
= cli_session_setup_creds(cli
, torture_creds
);
5095 if (!NT_STATUS_IS_OK(status
)) {
5096 printf("cli_session_setup returned %s\n", nt_errstr(status
));
5100 status
= cli_tree_connect(cli
, share
, "?????", NULL
);
5101 if (!NT_STATUS_IS_OK(status
)) {
5102 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
5106 /* Ensure this is a DFS share. */
5107 dfs_supported
= smbXcli_conn_dfs_supported(cli
->conn
);
5108 if (!dfs_supported
) {
5109 printf("Server %s does not support DFS\n",
5110 smbXcli_conn_remote_name(cli
->conn
));
5113 dfs_supported
= smbXcli_tcon_is_dfs_share(cli
->smb2
.tcon
);
5114 if (!dfs_supported
) {
5115 printf("Share %s does not support DFS\n",
5121 * Create the filename with one leading backslash.
5123 dfs_filename_slash
= talloc_asprintf(talloc_tos(),
5125 smbXcli_conn_remote_name(cli
->conn
),
5127 if (dfs_filename_slash
== NULL
) {
5128 printf("Out of memory\n");
5133 * Create the filename with many leading backslashes.
5135 dfs_filename_slash_multi
= talloc_asprintf(talloc_tos(),
5136 "\\\\\\\\%s\\%s\\file",
5137 smbXcli_conn_remote_name(cli
->conn
),
5139 if (dfs_filename_slash_multi
== NULL
) {
5140 printf("Out of memory\n");
5145 * Trying to open "\\server\\share\\file" should get
5146 * NT_STATUS_OBJECT_NAME_NOT_FOUND.
5148 status
= get_smb2_inode(cli
,
5151 if (!NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
5152 printf("%s:%d Open of %s should get "
5153 "STATUS_OBJECT_NAME_NOT_FOUND, got %s\n",
5161 /* Now create a file called "\\server\\share\\file". */
5162 status
= smb2cli_create(cli
->conn
,
5167 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
5168 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
5169 SEC_STD_SYNCHRONIZE
|
5172 SEC_FILE_READ_ATTRIBUTE
, /* desired_access, */
5173 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
5174 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
5175 FILE_CREATE
, /* create_disposition, */
5176 0, /* create_options, */
5177 NULL
, /* smb2_create_blobs *blobs */
5180 NULL
, /* struct smb_create_returns * */
5181 talloc_tos(), /* mem_ctx. */
5182 NULL
, /* struct smb2_create_blobs * */
5183 NULL
); /* struct symlink_reparse_struct */
5184 if (!NT_STATUS_IS_OK(status
)) {
5185 printf("%s:%d smb2cli_create on %s returned %s\n",
5194 * Trying to open "\\server\\share\\file" should now get
5197 status
= get_smb2_inode(cli
,
5200 if (!NT_STATUS_IS_OK(status
)) {
5201 printf("%s:%d Open of %s should succeed "
5211 * Trying to open "\\\\\\server\\share\\file" should now get
5212 * a valid inode that matches. MacOSX-style of DFS name test.
5214 ino_matched
= smb2_inode_matches(cli
,
5217 dfs_filename_slash_multi
);
5219 printf("%s:%d Failed to match ino number for %s\n",
5222 dfs_filename_slash_multi
);
5230 if (fid_persistent
!= 0 || fid_volatile
!= 0) {
5231 smb2cli_close(cli
->conn
,
5239 /* Delete anything we made. */
5240 (void)smb2_dfs_delete(cli
, dfs_filename_slash
);
5245 * Ensure a named pipe async read followed by a disconnect
5246 * doesn't crash the server (server crash checked for in
5247 * containing test script:
5248 * source3/script/tests/test_smbtorture_nocrash_s3.sh)
5249 * BUG: https://bugzilla.samba.org/show_bug.cgi?id=15423
5252 bool run_smb2_pipe_read_async_disconnect(int dummy
)
5254 struct cli_state
*cli
= NULL
;
5256 uint64_t fid_persistent
= 0;
5257 uint64_t fid_volatile
= 0;
5258 struct tevent_context
*ev
;
5259 struct tevent_req
*req
;
5260 bool retval
= false;
5262 printf("Starting SMB2-PIPE-READ-ASYNC-DISCONNECT\n");
5264 if (!torture_init_connection(&cli
)) {
5268 status
= smbXcli_negprot(cli
->conn
,
5275 if (!NT_STATUS_IS_OK(status
)) {
5276 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
5280 status
= cli_session_setup_creds(cli
, torture_creds
);
5281 if (!NT_STATUS_IS_OK(status
)) {
5282 printf("cli_session_setup returned %s\n", nt_errstr(status
));
5286 status
= cli_tree_connect_creds(cli
, "IPC$", "IPC", torture_creds
);
5287 if (!NT_STATUS_IS_OK(status
)) {
5288 printf("cli_tree_connect to IPC$ returned %s\n",
5293 /* Open the SAMR pipe. */
5294 status
= smb2cli_create(cli
->conn
,
5299 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
5300 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
5301 SEC_STD_SYNCHRONIZE
|
5303 SEC_FILE_WRITE_DATA
, /* desired_access, */
5304 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
5305 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
5306 FILE_OPEN
, /* create_disposition, */
5307 0, /* create_options, */
5308 NULL
, /* smb2_create_blobs *blobs */
5311 NULL
, /* struct smb_create_returns * */
5312 talloc_tos(), /* mem_ctx. */
5313 NULL
, /* struct smb2_create_blobs * */
5314 NULL
); /* psymlink */
5315 if (!NT_STATUS_IS_OK(status
)) {
5316 printf("%s:%d smb2cli_create on SAMR returned %s\n",
5323 ev
= samba_tevent_context_init(talloc_tos());
5328 /* Start an async read. */
5329 req
= smb2cli_read_send(talloc_tos(),
5339 0, /* minimum_count */
5340 0); /* remaining_bytes */
5345 /* Force disconnect. */
5346 smbXcli_conn_disconnect(cli
->conn
, NT_STATUS_LOCAL_DISCONNECT
);
5352 if (fid_volatile
!= 0) {
5353 smb2cli_close(cli
->conn
,
5364 bool run_smb2_invalid_pipename(int dummy
)
5366 struct cli_state
*cli
= NULL
;
5368 uint64_t fid_persistent
= 0;
5369 uint64_t fid_volatile
= 0;
5370 const char *unknown_pipe
= "badpipe";
5371 const char *invalid_pipe
= "../../../../../../../../../badpipe";
5373 printf("Starting SMB2-INVALID-PIPENAME\n");
5375 if (!torture_init_connection(&cli
)) {
5379 status
= smbXcli_negprot(cli
->conn
,
5386 if (!NT_STATUS_IS_OK(status
)) {
5387 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
5391 status
= cli_session_setup_creds(cli
, torture_creds
);
5392 if (!NT_STATUS_IS_OK(status
)) {
5393 printf("cli_session_setup returned %s\n", nt_errstr(status
));
5397 status
= cli_tree_connect(cli
, "IPC$", "?????", NULL
);
5398 if (!NT_STATUS_IS_OK(status
)) {
5399 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
5403 /* Try and connect to an unknown pipename. */
5404 status
= smb2cli_create(cli
->conn
,
5409 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
5410 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
5411 SEC_STD_SYNCHRONIZE
|
5413 SEC_FILE_WRITE_DATA
|
5414 SEC_FILE_READ_ATTRIBUTE
, /* desired_access, */
5415 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
5416 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
5417 FILE_CREATE
, /* create_disposition, */
5418 0, /* create_options, */
5419 NULL
, /* smb2_create_blobs *blobs */
5422 NULL
, /* struct smb_create_returns * */
5423 talloc_tos(), /* mem_ctx. */
5424 NULL
, /* struct smb2_create_blobs * */
5425 NULL
); /* struct symlink_reparse_struct */
5426 /* We should get NT_STATUS_OBJECT_NAME_NOT_FOUND */
5427 if (!NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
5428 printf("%s:%d smb2cli_create on name %s returned %s\n",
5436 /* Try and connect to an invalid pipename containing unix separators. */
5437 status
= smb2cli_create(cli
->conn
,
5442 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
5443 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
5444 SEC_STD_SYNCHRONIZE
|
5446 SEC_FILE_WRITE_DATA
|
5447 SEC_FILE_READ_ATTRIBUTE
, /* desired_access, */
5448 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
5449 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
5450 FILE_CREATE
, /* create_disposition, */
5451 0, /* create_options, */
5452 NULL
, /* smb2_create_blobs *blobs */
5455 NULL
, /* struct smb_create_returns * */
5456 talloc_tos(), /* mem_ctx. */
5457 NULL
, /* struct smb2_create_blobs * */
5458 NULL
); /* struct symlink_reparse_struct */
5460 * We should still get NT_STATUS_OBJECT_NAME_NOT_FOUND
5461 * (tested against Windows 2022).
5463 if (!NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
5464 printf("%s:%d smb2cli_create on name %s returned %s\n",