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 uint64_t saved_uid
= 0;
51 printf("Starting SMB2-BASIC\n");
53 if (!torture_init_connection(&cli
)) {
57 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
58 PROTOCOL_SMB2_02
, PROTOCOL_SMB2_02
);
59 if (!NT_STATUS_IS_OK(status
)) {
60 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
64 status
= cli_session_setup_creds(cli
, torture_creds
);
65 if (!NT_STATUS_IS_OK(status
)) {
66 printf("cli_session_setup returned %s\n", nt_errstr(status
));
70 status
= cli_tree_connect(cli
, share
, "?????", NULL
);
71 if (!NT_STATUS_IS_OK(status
)) {
72 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
76 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
77 cli
->smb2
.tcon
, "smb2-basic.txt",
78 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
79 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
80 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
81 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
82 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
83 FILE_CREATE
, /* create_disposition, */
84 FILE_DELETE_ON_CLOSE
, /* create_options, */
85 NULL
, /* smb2_create_blobs *blobs */
89 if (!NT_STATUS_IS_OK(status
)) {
90 printf("smb2cli_create returned %s\n", nt_errstr(status
));
94 status
= smb2cli_write(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
95 cli
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
96 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
97 if (!NT_STATUS_IS_OK(status
)) {
98 printf("smb2cli_write returned %s\n", nt_errstr(status
));
102 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
103 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
104 if (!NT_STATUS_IS_OK(status
)) {
105 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
109 status
= smb2cli_read(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
110 cli
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
112 talloc_tos(), &result
, &nread
);
113 if (!NT_STATUS_IS_OK(status
)) {
114 printf("smb2cli_read returned %s\n", nt_errstr(status
));
118 if (nread
!= strlen(hello
)) {
119 printf("smb2cli_read returned %d bytes, expected %d\n",
120 (int)nread
, (int)strlen(hello
));
124 if (memcmp(hello
, result
, nread
) != 0) {
125 printf("smb2cli_read returned '%s', expected '%s'\n",
130 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
131 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
132 if (!NT_STATUS_IS_OK(status
)) {
133 printf("smb2cli_close returned %s\n", nt_errstr(status
));
137 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
139 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
140 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
143 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
144 0, /* file_attributes, */
145 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
146 FILE_OPEN
, /* create_disposition, */
147 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
148 NULL
, /* smb2_create_blobs *blobs */
152 if (!NT_STATUS_IS_OK(status
)) {
153 printf("smb2cli_create returned %s\n", nt_errstr(status
));
157 status
= smb2cli_query_directory(
158 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
159 1, 0, 0, fid_persistent
, fid_volatile
, "*", 0xffff,
160 talloc_tos(), &dir_data
, &dir_data_length
);
162 if (!NT_STATUS_IS_OK(status
)) {
163 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
167 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
168 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
169 if (!NT_STATUS_IS_OK(status
)) {
170 printf("smb2cli_close returned %s\n", nt_errstr(status
));
174 saved_tid
= smb2cli_tcon_current_id(cli
->smb2
.tcon
);
175 saved_tcon
= cli_state_save_tcon(cli
);
176 if (saved_tcon
== NULL
) {
179 cli
->smb2
.tcon
= smbXcli_tcon_create(cli
);
180 smb2cli_tcon_set_values(cli
->smb2
.tcon
,
185 0, /* capabilities */
186 0 /* maximal_access */);
187 status
= smb2cli_tdis(cli
->conn
,
191 cli_state_restore_tcon(cli
, saved_tcon
);
192 if (!NT_STATUS_IS_OK(status
)) {
193 printf("smb2cli_tdis returned %s\n", nt_errstr(status
));
197 status
= smb2cli_tdis(cli
->conn
,
201 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
202 printf("2nd smb2cli_tdis returned %s\n", nt_errstr(status
));
206 saved_uid
= smb2cli_session_current_id(cli
->smb2
.session
);
207 status
= smb2cli_logoff(cli
->conn
, cli
->timeout
, cli
->smb2
.session
);
208 if (!NT_STATUS_IS_OK(status
)) {
209 printf("smb2cli_logoff returned %s\n", nt_errstr(status
));
213 cli
->smb2
.session
= smbXcli_session_create(cli
, cli
->conn
);
214 if (cli
->smb2
.session
== NULL
) {
215 printf("smbXcli_session_create() returned NULL\n");
219 smb2cli_session_set_id_and_flags(cli
->smb2
.session
, saved_uid
, 0);
221 status
= smb2cli_logoff(cli
->conn
, cli
->timeout
, cli
->smb2
.session
);
222 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
223 printf("2nd smb2cli_logoff returned %s\n", nt_errstr(status
));
230 bool run_smb2_negprot(int dummy
)
232 struct cli_state
*cli
;
234 enum protocol_types protocol
;
235 const char *name
= NULL
;
237 printf("Starting SMB2-NEGPROT\n");
239 if (!torture_init_connection(&cli
)) {
243 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
244 PROTOCOL_CORE
, PROTOCOL_LATEST
);
245 if (!NT_STATUS_IS_OK(status
)) {
246 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
250 protocol
= smbXcli_conn_protocol(cli
->conn
);
251 name
= smb_protocol_types_string(protocol
);
253 if (protocol
>= PROTOCOL_SMB2_02
) {
254 printf("Server supports %s\n", name
);
256 printf("Server DOES NOT support SMB2, only %s\n", name
);
260 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
262 if (!NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_RESET
) &&
263 !NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_DISCONNECTED
) &&
264 !NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_ABORTED
)) {
265 printf("2nd smbXcli_negprot should disconnect - returned %s\n",
270 if (smbXcli_conn_is_connected(cli
->conn
)) {
271 printf("2nd smbXcli_negprot should disconnect "
272 "- still connected\n");
279 bool run_smb2_anonymous(int dummy
)
281 struct cli_state
*cli
= NULL
;
283 struct cli_credentials
*anon_creds
= NULL
;
286 printf("Starting SMB2-ANONYMOUS\n");
288 if (!torture_init_connection(&cli
)) {
292 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
293 PROTOCOL_SMB2_02
, PROTOCOL_LATEST
);
294 if (!NT_STATUS_IS_OK(status
)) {
295 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
299 anon_creds
= cli_credentials_init_anon(talloc_tos());
300 if (anon_creds
== NULL
) {
301 printf("cli_credentials_init_anon failed\n");
305 status
= cli_session_setup_creds(cli
, anon_creds
);
306 if (!NT_STATUS_IS_OK(status
)) {
307 printf("cli_session_setup returned %s\n", nt_errstr(status
));
311 guest
= smbXcli_session_is_guest(cli
->smb2
.session
);
313 printf("anonymous session should not have guest authentication\n");
320 bool run_smb2_session_reconnect(int dummy
)
322 struct cli_state
*cli1
;
323 struct cli_state
*cli2
;
326 uint64_t fid_persistent
, fid_volatile
;
327 struct tevent_context
*ev
;
328 struct tevent_req
*subreq
;
329 DATA_BLOB in_blob
= data_blob_null
;
331 DATA_BLOB session_key
;
332 struct auth_generic_state
*auth_generic_state
;
333 struct iovec
*recv_iov
;
334 const char *hello
= "Hello, world\n";
338 printf("Starting SMB2-SESSION-RECONNECT\n");
340 if (!torture_init_connection(&cli1
)) {
344 status
= smbXcli_negprot(cli1
->conn
, cli1
->timeout
,
345 PROTOCOL_SMB2_02
, PROTOCOL_LATEST
);
346 if (!NT_STATUS_IS_OK(status
)) {
347 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
351 status
= cli_session_setup_creds(cli1
, torture_creds
);
352 if (!NT_STATUS_IS_OK(status
)) {
353 printf("cli_session_setup returned %s\n", nt_errstr(status
));
357 status
= cli_tree_connect(cli1
, share
, "?????", NULL
);
358 if (!NT_STATUS_IS_OK(status
)) {
359 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
363 status
= smb2cli_create(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
364 cli1
->smb2
.tcon
, "session-reconnect.txt",
365 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
366 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
367 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
368 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
369 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
370 FILE_CREATE
, /* create_disposition, */
371 FILE_DELETE_ON_CLOSE
, /* create_options, */
372 NULL
, /* smb2_create_blobs *blobs */
376 if (!NT_STATUS_IS_OK(status
)) {
377 printf("smb2cli_create on cli1 %s\n", nt_errstr(status
));
381 status
= smb2cli_write(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
382 cli1
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
383 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
384 if (!NT_STATUS_IS_OK(status
)) {
385 printf("smb2cli_write returned %s\n", nt_errstr(status
));
389 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
390 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
391 if (!NT_STATUS_IS_OK(status
)) {
392 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
396 status
= smb2cli_read(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
397 cli1
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
399 talloc_tos(), &result
, &nread
);
400 if (!NT_STATUS_IS_OK(status
)) {
401 printf("smb2cli_read returned %s\n", nt_errstr(status
));
405 if (nread
!= strlen(hello
)) {
406 printf("smb2cli_read returned %d bytes, expected %d\n",
407 (int)nread
, (int)strlen(hello
));
411 if (memcmp(hello
, result
, nread
) != 0) {
412 printf("smb2cli_read returned '%s', expected '%s'\n",
417 /* prepare second session */
419 if (!torture_init_connection(&cli2
)) {
423 status
= smbXcli_negprot(cli2
->conn
, cli2
->timeout
,
424 PROTOCOL_SMB2_02
, PROTOCOL_LATEST
);
425 if (!NT_STATUS_IS_OK(status
)) {
426 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
430 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
431 if (!NT_STATUS_IS_OK(status
)) {
432 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
436 gensec_want_feature(auth_generic_state
->gensec_security
,
437 GENSEC_FEATURE_SESSION_KEY
);
439 status
= auth_generic_set_creds(auth_generic_state
, torture_creds
);
440 if (!NT_STATUS_IS_OK(status
)) {
441 printf("auth_generic_set_creds returned %s\n", nt_errstr(status
));
445 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
446 if (!NT_STATUS_IS_OK(status
)) {
447 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
451 ev
= samba_tevent_context_init(talloc_tos());
453 printf("samba_tevent_context_init() returned NULL\n");
457 status
= gensec_update(auth_generic_state
->gensec_security
,
458 talloc_tos(), data_blob_null
, &in_blob
);
459 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
460 printf("gensec_update returned %s\n", nt_errstr(status
));
464 cli2
->smb2
.session
= smbXcli_session_create(cli2
, cli2
->conn
);
466 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
471 SMB2_CAP_DFS
, /* in_capabilities */
473 /* in_previous_session_id: */
474 smb2cli_session_current_id(cli1
->smb2
.session
),
475 &in_blob
); /* in_security_buffer */
476 if (subreq
== NULL
) {
477 printf("smb2cli_session_setup_send() returned NULL\n");
481 ok
= tevent_req_poll(subreq
, ev
);
483 printf("tevent_req_poll() returned false\n");
487 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
489 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
490 printf("smb2cli_session_setup_recv returned %s\n",
495 status
= gensec_update(auth_generic_state
->gensec_security
,
496 talloc_tos(), out_blob
, &in_blob
);
497 if (!NT_STATUS_IS_OK(status
)) {
498 printf("auth_generic_update returned %s\n", nt_errstr(status
));
502 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
507 SMB2_CAP_DFS
, /* in_capabilities */
509 /* in_previous_session_id: */
510 smb2cli_session_current_id(cli1
->smb2
.session
),
511 &in_blob
); /* in_security_buffer */
512 if (subreq
== NULL
) {
513 printf("smb2cli_session_setup_send() returned NULL\n");
517 ok
= tevent_req_poll(subreq
, ev
);
519 printf("tevent_req_poll() returned false\n");
523 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
524 &recv_iov
, &out_blob
);
525 if (!NT_STATUS_IS_OK(status
)) {
526 printf("smb2cli_session_setup_recv returned %s\n",
531 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
533 if (!NT_STATUS_IS_OK(status
)) {
534 printf("gensec_session_key returned %s\n",
539 /* check file operation on the old client */
541 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
542 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
543 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
544 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
548 status
= cli_tree_connect(cli1
, share
, "?????", NULL
);
549 if (!NT_STATUS_EQUAL(status
, NT_STATUS_USER_SESSION_DELETED
)) {
550 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
555 * checking file operations without signing.
556 * on w2k8r2 at least, flush, read and write also work the same way,
557 * while create gives ACCESS_DENIED without signing
559 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
560 cli2
->smb2
.tcon
, fid_persistent
, fid_volatile
);
561 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
562 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
564 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
568 status
= smb2cli_write(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
569 cli2
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
570 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
571 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
572 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
574 printf("smb2cli_write returned %s\n", nt_errstr(status
));
578 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
579 cli2
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
581 talloc_tos(), &result
, &nread
);
582 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
583 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
585 printf("smb2cli_read returned %s\n", nt_errstr(status
));
589 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
590 cli2
->smb2
.tcon
, "session-reconnect.txt",
591 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
592 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
593 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
594 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
595 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
596 FILE_CREATE
, /* create_disposition, */
597 FILE_DELETE_ON_CLOSE
, /* create_options, */
598 NULL
, /* smb2_create_blobs *blobs */
602 if (!NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
) &&
603 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
604 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
608 /* now grab the session key and try with signing */
610 status
= smb2cli_session_set_session_key(cli2
->smb2
.session
,
613 if (!NT_STATUS_IS_OK(status
)) {
614 printf("smb2cli_session_set_session_key %s\n", nt_errstr(status
));
618 /* the tid seems to be irrelevant at this stage */
620 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
621 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
622 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
623 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
625 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
629 status
= smb2cli_write(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
630 cli1
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
631 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
632 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
633 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
635 printf("smb2cli_write returned %s\n", nt_errstr(status
));
639 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
640 cli1
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
642 talloc_tos(), &result
, &nread
);
643 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
) &&
644 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
646 printf("smb2cli_read returned %s\n", nt_errstr(status
));
650 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
651 cli1
->smb2
.tcon
, "session-reconnect.txt",
652 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
653 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
654 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
655 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
656 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
657 FILE_CREATE
, /* create_disposition, */
658 FILE_DELETE_ON_CLOSE
, /* create_options, */
659 NULL
, /* smb2_create_blobs *blobs */
663 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
) &&
664 !NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
))
666 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
670 /* now do a new tcon and test file calls again */
672 status
= cli_tree_connect(cli2
, share
, "?????", NULL
);
673 if (!NT_STATUS_IS_OK(status
)) {
674 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
678 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
679 cli2
->smb2
.tcon
, "session-reconnect.txt",
680 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
681 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
682 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
683 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
684 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
685 FILE_CREATE
, /* create_disposition, */
686 FILE_DELETE_ON_CLOSE
, /* create_options, */
687 NULL
, /* smb2_create_blobs *blobs */
691 if (!NT_STATUS_IS_OK(status
)) {
692 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
696 status
= smb2cli_write(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
697 cli2
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
698 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
699 if (!NT_STATUS_IS_OK(status
)) {
700 printf("smb2cli_write returned %s\n", nt_errstr(status
));
704 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
705 cli2
->smb2
.tcon
, fid_persistent
, fid_volatile
);
706 if (!NT_STATUS_IS_OK(status
)) {
707 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
711 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
712 cli2
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
714 talloc_tos(), &result
, &nread
);
715 if (!NT_STATUS_IS_OK(status
)) {
716 printf("smb2cli_read returned %s\n", nt_errstr(status
));
720 if (nread
!= strlen(hello
)) {
721 printf("smb2cli_read returned %d bytes, expected %d\n",
722 (int)nread
, (int)strlen(hello
));
726 if (memcmp(hello
, result
, nread
) != 0) {
727 printf("smb2cli_read returned '%s', expected '%s'\n",
735 bool run_smb2_tcon_dependence(int dummy
)
737 struct cli_state
*cli
;
739 uint64_t fid_persistent
, fid_volatile
;
740 const char *hello
= "Hello, world\n";
743 struct smbXcli_tcon
*tcon2
;
746 printf("Starting SMB2-TCON-DEPENDENCE\n");
748 if (!torture_init_connection(&cli
)) {
752 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
753 PROTOCOL_SMB2_02
, PROTOCOL_LATEST
);
754 if (!NT_STATUS_IS_OK(status
)) {
755 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
759 status
= cli_session_setup_creds(cli
, torture_creds
);
760 if (!NT_STATUS_IS_OK(status
)) {
761 printf("cli_session_setup returned %s\n", nt_errstr(status
));
765 status
= cli_tree_connect(cli
, share
, "?????", NULL
);
766 if (!NT_STATUS_IS_OK(status
)) {
767 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
771 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
772 cli
->smb2
.tcon
, "tcon_depedence.txt",
773 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
774 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
775 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
776 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
777 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
778 FILE_CREATE
, /* create_disposition, */
779 FILE_DELETE_ON_CLOSE
, /* create_options, */
780 NULL
, /* smb2_create_blobs *blobs */
784 if (!NT_STATUS_IS_OK(status
)) {
785 printf("smb2cli_create on cli %s\n", nt_errstr(status
));
789 status
= smb2cli_write(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
790 cli
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
791 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
792 if (!NT_STATUS_IS_OK(status
)) {
793 printf("smb2cli_write returned %s\n", nt_errstr(status
));
797 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
798 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
799 if (!NT_STATUS_IS_OK(status
)) {
800 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
804 status
= smb2cli_read(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
805 cli
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
807 talloc_tos(), &result
, &nread
);
808 if (!NT_STATUS_IS_OK(status
)) {
809 printf("smb2cli_read returned %s\n", nt_errstr(status
));
813 if (nread
!= strlen(hello
)) {
814 printf("smb2cli_read returned %d bytes, expected %d\n",
815 (int)nread
, (int)strlen(hello
));
819 if (memcmp(hello
, result
, nread
) != 0) {
820 printf("smb2cli_read returned '%s', expected '%s'\n",
825 /* check behaviour with wrong tid... */
827 tcon2
= smbXcli_tcon_create(cli
);
828 tcon2_id
= smb2cli_tcon_current_id(cli
->smb2
.tcon
);
830 smb2cli_tcon_set_values(tcon2
,
835 0, /* capabilities */
836 0 /* maximal_access */);
838 status
= smb2cli_read(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
839 tcon2
, 0x10000, 0, fid_persistent
,
841 talloc_tos(), &result
, &nread
);
842 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_NAME_DELETED
)) {
843 printf("smb2cli_read returned %s\n", nt_errstr(status
));
852 bool run_smb2_multi_channel(int dummy
)
854 struct cli_state
*cli1
;
855 struct cli_state
*cli2
;
856 struct cli_state
*cli3
;
859 uint64_t fid_persistent
, fid_volatile
;
860 struct tevent_context
*ev
;
861 struct tevent_req
*subreq
;
862 DATA_BLOB in_blob
= data_blob_null
;
864 DATA_BLOB channel_session_key
;
865 struct auth_generic_state
*auth_generic_state
;
866 struct iovec
*recv_iov
;
867 const char *hello
= "Hello, world\n";
870 struct GUID saved_guid
= cli_state_client_guid
;
872 printf("Starting SMB2-MULTI-CHANNEL\n");
874 cli_state_client_guid
= GUID_random();
876 if (!torture_init_connection(&cli1
)) {
880 if (!torture_init_connection(&cli2
)) {
884 if (!torture_init_connection(&cli3
)) {
888 cli_state_client_guid
= saved_guid
;
890 status
= smbXcli_negprot(cli1
->conn
, cli1
->timeout
,
891 PROTOCOL_SMB3_00
, PROTOCOL_LATEST
);
892 if (!NT_STATUS_IS_OK(status
)) {
893 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
897 status
= smbXcli_negprot(cli2
->conn
, cli2
->timeout
,
898 PROTOCOL_SMB3_00
, PROTOCOL_LATEST
);
899 if (!NT_STATUS_IS_OK(status
)) {
900 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
904 status
= smbXcli_negprot(cli3
->conn
, cli3
->timeout
,
905 PROTOCOL_SMB3_00
, PROTOCOL_LATEST
);
906 if (!NT_STATUS_IS_OK(status
)) {
907 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
911 status
= cli_session_setup_creds(cli1
, torture_creds
);
912 if (!NT_STATUS_IS_OK(status
)) {
913 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status
));
917 status
= cli_tree_connect(cli1
, share
, "?????", NULL
);
918 if (!NT_STATUS_IS_OK(status
)) {
919 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
923 status
= smb2cli_session_create_channel(cli2
,
926 &cli2
->smb2
.session
);
927 if (!NT_STATUS_IS_OK(status
)) {
928 printf("smb2cli_session_create_channel returned %s\n",
933 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
934 if (!NT_STATUS_IS_OK(status
)) {
935 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
939 gensec_want_feature(auth_generic_state
->gensec_security
,
940 GENSEC_FEATURE_SESSION_KEY
);
942 status
= auth_generic_set_creds(auth_generic_state
, torture_creds
);
943 if (!NT_STATUS_IS_OK(status
)) {
944 printf("auth_generic_set_creds returned %s\n", nt_errstr(status
));
948 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
949 if (!NT_STATUS_IS_OK(status
)) {
950 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
954 ev
= samba_tevent_context_init(talloc_tos());
956 printf("samba_tevent_context_init() returned NULL\n");
960 status
= gensec_update(auth_generic_state
->gensec_security
,
961 talloc_tos(), data_blob_null
, &in_blob
);
962 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
963 printf("gensec_update returned %s\n", nt_errstr(status
));
967 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
972 SMB2_CAP_DFS
, /* in_capabilities */
974 0, /* in_previous_session_id */
975 &in_blob
); /* in_security_buffer */
976 if (subreq
== NULL
) {
977 printf("smb2cli_session_setup_send() returned NULL\n");
981 ok
= tevent_req_poll(subreq
, ev
);
983 printf("tevent_req_poll() returned false\n");
987 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
989 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
990 printf("smb2cli_session_setup_recv returned %s\n",
995 status
= gensec_update(auth_generic_state
->gensec_security
,
996 talloc_tos(), out_blob
, &in_blob
);
997 if (!NT_STATUS_IS_OK(status
)) {
998 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1002 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1006 0x01, /* in_flags */
1007 SMB2_CAP_DFS
, /* in_capabilities */
1009 0, /* in_previous_session_id */
1010 &in_blob
); /* in_security_buffer */
1011 if (subreq
== NULL
) {
1012 printf("smb2cli_session_setup_send() returned NULL\n");
1016 ok
= tevent_req_poll(subreq
, ev
);
1018 printf("tevent_req_poll() returned false\n");
1022 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1023 &recv_iov
, &out_blob
);
1024 if (!NT_STATUS_IS_OK(status
)) {
1025 printf("smb2cli_session_setup_recv returned %s\n",
1030 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
1031 &channel_session_key
);
1032 if (!NT_STATUS_IS_OK(status
)) {
1033 printf("gensec_session_key returned %s\n",
1038 status
= smb2cli_session_set_channel_key(cli2
->smb2
.session
,
1039 channel_session_key
,
1041 if (!NT_STATUS_IS_OK(status
)) {
1042 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status
));
1046 status
= smb2cli_session_create_channel(cli3
,
1049 &cli3
->smb2
.session
);
1050 if (!NT_STATUS_IS_OK(status
)) {
1051 printf("smb2cli_session_create_channel returned %s\n",
1056 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1057 if (!NT_STATUS_IS_OK(status
)) {
1058 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1062 gensec_want_feature(auth_generic_state
->gensec_security
,
1063 GENSEC_FEATURE_SESSION_KEY
);
1065 status
= auth_generic_set_creds(auth_generic_state
, torture_creds
);
1066 if (!NT_STATUS_IS_OK(status
)) {
1067 printf("auth_generic_set_creds returned %s\n", nt_errstr(status
));
1071 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1072 if (!NT_STATUS_IS_OK(status
)) {
1073 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1077 status
= gensec_update(auth_generic_state
->gensec_security
,
1078 talloc_tos(), data_blob_null
, &in_blob
);
1079 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1080 printf("gensec_update returned %s\n", nt_errstr(status
));
1084 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1088 0x01, /* in_flags */
1089 SMB2_CAP_DFS
, /* in_capabilities */
1091 0, /* in_previous_session_id */
1092 &in_blob
); /* in_security_buffer */
1093 if (subreq
== NULL
) {
1094 printf("smb2cli_session_setup_send() returned NULL\n");
1098 ok
= tevent_req_poll(subreq
, ev
);
1100 printf("tevent_req_poll() returned false\n");
1104 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1106 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1107 printf("smb2cli_session_setup_recv returned %s\n",
1112 status
= gensec_update(auth_generic_state
->gensec_security
,
1113 talloc_tos(), out_blob
, &in_blob
);
1114 if (!NT_STATUS_IS_OK(status
)) {
1115 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1119 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1123 0x01, /* in_flags */
1124 SMB2_CAP_DFS
, /* in_capabilities */
1126 0, /* in_previous_session_id */
1127 &in_blob
); /* in_security_buffer */
1128 if (subreq
== NULL
) {
1129 printf("smb2cli_session_setup_send() returned NULL\n");
1133 ok
= tevent_req_poll(subreq
, ev
);
1135 printf("tevent_req_poll() returned false\n");
1139 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1140 &recv_iov
, &out_blob
);
1141 if (!NT_STATUS_IS_OK(status
)) {
1142 printf("smb2cli_session_setup_recv returned %s\n",
1147 status
= gensec_session_key(auth_generic_state
->gensec_security
, talloc_tos(),
1148 &channel_session_key
);
1149 if (!NT_STATUS_IS_OK(status
)) {
1150 printf("gensec_session_key returned %s\n",
1155 status
= smb2cli_session_set_channel_key(cli3
->smb2
.session
,
1156 channel_session_key
,
1158 if (!NT_STATUS_IS_OK(status
)) {
1159 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status
));
1163 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1164 cli1
->smb2
.tcon
, "multi-channel.txt",
1165 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1166 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1167 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1168 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1169 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1170 FILE_CREATE
, /* create_disposition, */
1171 FILE_DELETE_ON_CLOSE
, /* create_options, */
1172 NULL
, /* smb2_create_blobs *blobs */
1176 if (!NT_STATUS_IS_OK(status
)) {
1177 printf("smb2cli_create on cli2 %s\n", nt_errstr(status
));
1181 status
= smb2cli_write(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1182 cli1
->smb2
.tcon
, strlen(hello
), 0, fid_persistent
,
1183 fid_volatile
, 0, 0, (const uint8_t *)hello
, NULL
);
1184 if (!NT_STATUS_IS_OK(status
)) {
1185 printf("smb2cli_write returned %s\n", nt_errstr(status
));
1189 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1190 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1191 if (!NT_STATUS_IS_OK(status
)) {
1192 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1196 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1197 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1198 if (!NT_STATUS_IS_OK(status
)) {
1199 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1203 status
= smb2cli_flush(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1204 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1205 if (!NT_STATUS_IS_OK(status
)) {
1206 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1210 status
= smb2cli_read(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1211 cli1
->smb2
.tcon
, 0x10000, 0, fid_persistent
,
1213 talloc_tos(), &result
, &nread
);
1214 if (!NT_STATUS_IS_OK(status
)) {
1215 printf("smb2cli_read returned %s\n", nt_errstr(status
));
1219 if (nread
!= strlen(hello
)) {
1220 printf("smb2cli_read returned %d bytes, expected %d\n",
1221 (int)nread
, (int)strlen(hello
));
1225 if (memcmp(hello
, result
, nread
) != 0) {
1226 printf("smb2cli_read returned '%s', expected '%s'\n",
1231 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1232 if (!NT_STATUS_IS_OK(status
)) {
1233 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1237 gensec_want_feature(auth_generic_state
->gensec_security
,
1238 GENSEC_FEATURE_SESSION_KEY
);
1240 status
= auth_generic_set_creds(auth_generic_state
, torture_creds
);
1241 if (!NT_STATUS_IS_OK(status
)) {
1242 printf("auth_generic_set_creds returned %s\n", nt_errstr(status
));
1246 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1247 if (!NT_STATUS_IS_OK(status
)) {
1248 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1252 status
= gensec_update(auth_generic_state
->gensec_security
,
1253 talloc_tos(), data_blob_null
, &in_blob
);
1254 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1255 printf("gensec_update returned %s\n", nt_errstr(status
));
1259 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1264 SMB2_CAP_DFS
, /* in_capabilities */
1266 0, /* in_previous_session_id */
1267 &in_blob
); /* in_security_buffer */
1268 if (subreq
== NULL
) {
1269 printf("smb2cli_session_setup_send() returned NULL\n");
1273 ok
= tevent_req_poll(subreq
, ev
);
1275 printf("tevent_req_poll() returned false\n");
1279 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1281 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1282 printf("smb2cli_session_setup_recv returned %s\n",
1287 status
= gensec_update(auth_generic_state
->gensec_security
,
1288 talloc_tos(), out_blob
, &in_blob
);
1289 if (!NT_STATUS_IS_OK(status
)) {
1290 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1294 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1295 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1296 if (!NT_STATUS_IS_OK(status
)) {
1297 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1301 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1302 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1303 if (!NT_STATUS_IS_OK(status
)) {
1304 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1308 status
= smb2cli_flush(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1309 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1310 if (!NT_STATUS_IS_OK(status
)) {
1311 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1315 status
= smb2cli_create(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1316 cli1
->smb2
.tcon
, "multi-channel-invalid.txt",
1317 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1318 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1319 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1320 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1321 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1322 FILE_CREATE
, /* create_disposition, */
1323 FILE_DELETE_ON_CLOSE
, /* create_options, */
1324 NULL
, /* smb2_create_blobs *blobs */
1328 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1329 printf("smb2cli_create %s\n", nt_errstr(status
));
1333 status
= smb2cli_create(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1334 cli1
->smb2
.tcon
, "multi-channel-invalid.txt",
1335 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1336 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1337 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1338 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1339 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1340 FILE_CREATE
, /* create_disposition, */
1341 FILE_DELETE_ON_CLOSE
, /* create_options, */
1342 NULL
, /* smb2_create_blobs *blobs */
1346 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1347 printf("smb2cli_create %s\n", nt_errstr(status
));
1351 status
= smb2cli_create(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1352 cli1
->smb2
.tcon
, "multi-channel-invalid.txt",
1353 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1354 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1355 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1356 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1357 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1358 FILE_CREATE
, /* create_disposition, */
1359 FILE_DELETE_ON_CLOSE
, /* create_options, */
1360 NULL
, /* smb2_create_blobs *blobs */
1364 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1365 printf("smb2cli_create %s\n", nt_errstr(status
));
1369 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1374 SMB2_CAP_DFS
, /* in_capabilities */
1376 0, /* in_previous_session_id */
1377 &in_blob
); /* in_security_buffer */
1378 if (subreq
== NULL
) {
1379 printf("smb2cli_session_setup_send() returned NULL\n");
1383 ok
= tevent_req_poll(subreq
, ev
);
1385 printf("tevent_req_poll() returned false\n");
1389 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1390 &recv_iov
, &out_blob
);
1391 if (!NT_STATUS_IS_OK(status
)) {
1392 printf("smb2cli_session_setup_recv returned %s\n",
1397 status
= smb2cli_close(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1398 cli1
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
1399 if (!NT_STATUS_IS_OK(status
)) {
1400 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1404 status
= smb2cli_flush(cli3
->conn
, cli3
->timeout
, cli3
->smb2
.session
,
1405 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1406 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1407 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1411 status
= smb2cli_flush(cli2
->conn
, cli2
->timeout
, cli2
->smb2
.session
,
1412 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1413 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1414 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1418 status
= smb2cli_flush(cli1
->conn
, cli1
->timeout
, cli1
->smb2
.session
,
1419 cli1
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1420 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_CLOSED
)) {
1421 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1428 bool run_smb2_session_reauth(int dummy
)
1430 struct cli_state
*cli
;
1433 uint64_t fid_persistent
, fid_volatile
;
1434 uint64_t dir_persistent
, dir_volatile
;
1436 uint32_t dir_data_length
;
1437 struct tevent_context
*ev
;
1438 struct tevent_req
*subreq
;
1439 DATA_BLOB in_blob
= data_blob_null
;
1441 DATA_BLOB in_input_buffer
;
1442 DATA_BLOB out_output_buffer
;
1443 uint8_t in_file_info_class
;
1444 struct auth_generic_state
*auth_generic_state
;
1445 struct iovec
*recv_iov
;
1447 struct smbXcli_tcon
*saved_tcon
;
1449 printf("Starting SMB2-SESSION_REAUTH\n");
1451 if (!torture_init_connection(&cli
)) {
1456 * PROTOCOL_SMB2_22 has a bug in win8pre0
1457 * it behaves like PROTOCOL_SMB2_02
1458 * and returns NT_STATUS_REQUEST_NOT_ACCEPTED,
1459 * while it allows it on PROTOCOL_SMB2_10.
1461 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
1462 PROTOCOL_SMB2_10
, PROTOCOL_SMB2_10
);
1463 if (!NT_STATUS_IS_OK(status
)) {
1464 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
1468 status
= cli_session_setup_creds(cli
, torture_creds
);
1469 if (!NT_STATUS_IS_OK(status
)) {
1470 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status
));
1474 status
= cli_tree_connect(cli
, share
, "?????", NULL
);
1475 if (!NT_STATUS_IS_OK(status
)) {
1476 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1480 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1481 cli
->smb2
.tcon
, "session-reauth.txt",
1482 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1483 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1484 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1485 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1486 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1487 FILE_CREATE
, /* create_disposition, */
1488 FILE_DELETE_ON_CLOSE
, /* create_options, */
1489 NULL
, /* smb2_create_blobs *blobs */
1493 if (!NT_STATUS_IS_OK(status
)) {
1494 printf("smb2cli_create %s\n", nt_errstr(status
));
1498 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1500 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1501 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1502 SEC_STD_SYNCHRONIZE
|
1504 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
1505 0, /* file_attributes, */
1506 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1507 FILE_OPEN
, /* create_disposition, */
1508 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
1509 NULL
, /* smb2_create_blobs *blobs */
1513 if (!NT_STATUS_IS_OK(status
)) {
1514 printf("smb2cli_create returned %s\n", nt_errstr(status
));
1518 status
= smb2cli_query_directory(
1519 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
1520 1, 0x3, 0, dir_persistent
, dir_volatile
,
1521 "session-reauth.txt", 0xffff,
1522 talloc_tos(), &dir_data
, &dir_data_length
);
1523 if (!NT_STATUS_IS_OK(status
)) {
1524 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1528 status
= auth_generic_client_prepare(talloc_tos(), &auth_generic_state
);
1529 if (!NT_STATUS_IS_OK(status
)) {
1530 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status
));
1534 gensec_want_feature(auth_generic_state
->gensec_security
,
1535 GENSEC_FEATURE_SESSION_KEY
);
1537 status
= auth_generic_set_creds(auth_generic_state
, torture_creds
);
1538 if (!NT_STATUS_IS_OK(status
)) {
1539 printf("auth_generic_set_creds returned %s\n", nt_errstr(status
));
1543 status
= auth_generic_client_start(auth_generic_state
, GENSEC_OID_NTLMSSP
);
1544 if (!NT_STATUS_IS_OK(status
)) {
1545 printf("auth_generic_client_start returned %s\n", nt_errstr(status
));
1549 ev
= samba_tevent_context_init(talloc_tos());
1551 printf("samba_tevent_context_init() returned NULL\n");
1555 status
= gensec_update(auth_generic_state
->gensec_security
,
1556 talloc_tos(), data_blob_null
, &in_blob
);
1557 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1558 printf("gensec_update returned %s\n", nt_errstr(status
));
1562 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1567 SMB2_CAP_DFS
, /* in_capabilities */
1569 0, /* in_previous_session_id */
1570 &in_blob
); /* in_security_buffer */
1571 if (subreq
== NULL
) {
1572 printf("smb2cli_session_setup_send() returned NULL\n");
1576 ok
= tevent_req_poll(subreq
, ev
);
1578 printf("tevent_req_poll() returned false\n");
1582 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1584 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1585 printf("smb2cli_session_setup_recv returned %s\n",
1590 status
= gensec_update(auth_generic_state
->gensec_security
,
1591 talloc_tos(), out_blob
, &in_blob
);
1592 if (!NT_STATUS_IS_OK(status
)) {
1593 printf("auth_generic_update returned %s\n", nt_errstr(status
));
1597 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1598 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1599 if (!NT_STATUS_IS_OK(status
)) {
1600 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1604 status
= smb2cli_query_directory(
1605 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
1606 1, 0x3, 0, dir_persistent
, dir_volatile
,
1607 "session-reauth.txt", 0xffff,
1608 talloc_tos(), &dir_data
, &dir_data_length
);
1609 if (!NT_STATUS_IS_OK(status
)) {
1610 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1615 * query_info seems to be a path based operation on Windows...
1617 status
= smb2cli_query_info(cli
->conn
,
1621 SMB2_0_INFO_SECURITY
,
1622 0, /* in_file_info_class */
1623 1024, /* in_max_output_length */
1624 NULL
, /* in_input_buffer */
1625 SECINFO_OWNER
, /* in_additional_info */
1630 &out_output_buffer
);
1631 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1632 printf("smb2cli_query_info (security) returned %s\n", nt_errstr(status
));
1636 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1637 status
= smb2cli_query_info(cli
->conn
,
1643 1024, /* in_max_output_length */
1644 NULL
, /* in_input_buffer */
1645 0, /* in_additional_info */
1650 &out_output_buffer
);
1651 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1652 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1656 in_input_buffer
= data_blob_talloc(talloc_tos(), NULL
, 8);
1657 SBVAL(in_input_buffer
.data
, 0, 512);
1659 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1660 status
= smb2cli_set_info(cli
->conn
,
1667 0, /* in_additional_info */
1670 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1671 printf("smb2cli_set_info (position) returned %s\n", nt_errstr(status
));
1675 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1676 cli
->smb2
.tcon
, "session-reauth-invalid.txt",
1677 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1678 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1679 SEC_STD_ALL
| SEC_FILE_ALL
, /* desired_access, */
1680 FILE_ATTRIBUTE_NORMAL
, /* file_attributes, */
1681 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1682 FILE_CREATE
, /* create_disposition, */
1683 FILE_DELETE_ON_CLOSE
, /* create_options, */
1684 NULL
, /* smb2_create_blobs *blobs */
1688 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1689 printf("smb2cli_create %s\n", nt_errstr(status
));
1693 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1695 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
1696 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
1697 SEC_STD_SYNCHRONIZE
|
1699 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
1700 0, /* file_attributes, */
1701 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1702 FILE_OPEN
, /* create_disposition, */
1703 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
1704 NULL
, /* smb2_create_blobs *blobs */
1708 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1709 printf("smb2cli_create returned %s\n", nt_errstr(status
));
1713 saved_tid
= smb2cli_tcon_current_id(cli
->smb2
.tcon
);
1714 saved_tcon
= cli
->smb2
.tcon
;
1715 cli
->smb2
.tcon
= smbXcli_tcon_create(cli
);
1716 smb2cli_tcon_set_values(cli
->smb2
.tcon
,
1721 0, /* capabilities */
1722 0 /* maximal_access */);
1723 status
= cli_tree_connect(cli
, share
, "?????", NULL
);
1724 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1725 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1728 talloc_free(cli
->smb2
.tcon
);
1729 cli
->smb2
.tcon
= saved_tcon
;
1731 subreq
= smb2cli_session_setup_send(talloc_tos(), ev
,
1736 SMB2_CAP_DFS
, /* in_capabilities */
1738 0, /* in_previous_session_id */
1739 &in_blob
); /* in_security_buffer */
1740 if (subreq
== NULL
) {
1741 printf("smb2cli_session_setup_send() returned NULL\n");
1745 ok
= tevent_req_poll(subreq
, ev
);
1747 printf("tevent_req_poll() returned false\n");
1751 status
= smb2cli_session_setup_recv(subreq
, talloc_tos(),
1752 &recv_iov
, &out_blob
);
1753 if (!NT_STATUS_IS_OK(status
)) {
1754 printf("smb2cli_session_setup_recv returned %s\n",
1759 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1760 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
1761 if (!NT_STATUS_IS_OK(status
)) {
1762 printf("smb2cli_flush returned %s\n", nt_errstr(status
));
1766 status
= smb2cli_query_info(cli
->conn
,
1770 SMB2_0_INFO_SECURITY
,
1771 0, /* in_file_info_class */
1772 1024, /* in_max_output_length */
1773 NULL
, /* in_input_buffer */
1774 SECINFO_OWNER
, /* in_additional_info */
1779 &out_output_buffer
);
1780 if (!NT_STATUS_IS_OK(status
)) {
1781 printf("smb2cli_query_info (security) returned %s\n", nt_errstr(status
));
1785 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1786 status
= smb2cli_query_info(cli
->conn
,
1792 1024, /* in_max_output_length */
1793 NULL
, /* in_input_buffer */
1794 0, /* in_additional_info */
1799 &out_output_buffer
);
1800 if (!NT_STATUS_IS_OK(status
)) {
1801 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1805 in_input_buffer
= data_blob_talloc(talloc_tos(), NULL
, 8);
1806 SBVAL(in_input_buffer
.data
, 0, 512);
1808 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1809 status
= smb2cli_set_info(cli
->conn
,
1816 0, /* in_additional_info */
1819 if (!NT_STATUS_IS_OK(status
)) {
1820 printf("smb2cli_set_info (position) returned %s\n", nt_errstr(status
));
1824 in_file_info_class
= SMB_FILE_POSITION_INFORMATION
- 1000;
1825 status
= smb2cli_query_info(cli
->conn
,
1831 1024, /* in_max_output_length */
1832 NULL
, /* in_input_buffer */
1833 0, /* in_additional_info */
1838 &out_output_buffer
);
1839 if (!NT_STATUS_IS_OK(status
)) {
1840 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status
));
1844 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1845 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
1846 if (!NT_STATUS_IS_OK(status
)) {
1847 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1851 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1852 cli
->smb2
.tcon
, "session-reauth.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, */
1857 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
1858 FILE_CREATE
, /* create_disposition, */
1859 FILE_DELETE_ON_CLOSE
, /* create_options, */
1860 NULL
, /* smb2_create_blobs *blobs */
1864 if (!NT_STATUS_IS_OK(status
)) {
1865 printf("smb2cli_create %s\n", nt_errstr(status
));
1869 status
= smb2cli_query_directory(
1870 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
1871 1, 0x3, 0, dir_persistent
, dir_volatile
,
1872 "session-reauth.txt", 0xffff,
1873 talloc_tos(), &dir_data
, &dir_data_length
);
1874 if (!NT_STATUS_IS_OK(status
)) {
1875 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
1879 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1880 cli
->smb2
.tcon
, 0, dir_persistent
, dir_volatile
);
1881 if (!NT_STATUS_IS_OK(status
)) {
1882 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1886 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
1887 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
1888 if (!NT_STATUS_IS_OK(status
)) {
1889 printf("smb2cli_close returned %s\n", nt_errstr(status
));
1893 saved_tid
= smb2cli_tcon_current_id(cli
->smb2
.tcon
);
1894 saved_tcon
= cli
->smb2
.tcon
;
1895 cli
->smb2
.tcon
= smbXcli_tcon_create(cli
);
1896 smb2cli_tcon_set_values(cli
->smb2
.tcon
,
1901 0, /* capabilities */
1902 0 /* maximal_access */);
1903 status
= cli_tree_connect(cli
, share
, "?????", NULL
);
1904 if (!NT_STATUS_IS_OK(status
)) {
1905 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1908 talloc_free(cli
->smb2
.tcon
);
1909 cli
->smb2
.tcon
= saved_tcon
;
1914 static NTSTATUS
check_size(struct cli_state
*cli
,
1919 off_t size_read
= 0;
1921 NTSTATUS status
= cli_qfileinfo_basic(cli
,
1931 if (!NT_STATUS_IS_OK(status
)) {
1932 printf("cli_qfileinfo_basic of %s failed (%s)\n",
1938 if (size
!= size_read
) {
1939 printf("size (%u) != size_read(%u) for %s\n",
1941 (unsigned int)size_read
,
1943 /* Use EOF to mean bad size. */
1944 return NT_STATUS_END_OF_FILE
;
1946 return NT_STATUS_OK
;
1949 /* Ensure cli_ftruncate() works for SMB2. */
1951 bool run_smb2_ftruncate(int dummy
)
1953 struct cli_state
*cli
= NULL
;
1954 const char *fname
= "smb2_ftruncate.txt";
1955 uint16_t fnum
= (uint16_t)-1;
1956 bool correct
= false;
1957 size_t buflen
= 1024*1024;
1958 uint8_t *buf
= NULL
;
1962 printf("Starting SMB2-FTRUNCATE\n");
1964 if (!torture_init_connection(&cli
)) {
1968 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
1969 PROTOCOL_SMB2_02
, PROTOCOL_SMB2_02
);
1970 if (!NT_STATUS_IS_OK(status
)) {
1971 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
1975 status
= cli_session_setup_creds(cli
, torture_creds
);
1976 if (!NT_STATUS_IS_OK(status
)) {
1977 printf("cli_session_setup returned %s\n", nt_errstr(status
));
1981 status
= cli_tree_connect(cli
, share
, "?????", NULL
);
1982 if (!NT_STATUS_IS_OK(status
)) {
1983 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
1987 cli_setatr(cli
, fname
, 0, 0);
1988 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
1990 status
= cli_ntcreate(cli
,
1994 FILE_ATTRIBUTE_NORMAL
,
2002 if (!NT_STATUS_IS_OK(status
)) {
2003 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
2007 buf
= talloc_zero_array(cli
, uint8_t, buflen
);
2013 status
= cli_writeall(cli
,
2021 if (!NT_STATUS_IS_OK(status
)) {
2022 printf("write of %u to %s failed (%s)\n",
2023 (unsigned int)buflen
,
2029 status
= check_size(cli
, fnum
, fname
, buflen
);
2030 if (!NT_STATUS_IS_OK(status
)) {
2034 /* Now ftruncate. */
2035 for ( i
= 0; i
< 10; i
++) {
2036 status
= cli_ftruncate(cli
, fnum
, i
*1024);
2037 if (!NT_STATUS_IS_OK(status
)) {
2038 printf("cli_ftruncate %u of %s failed (%s)\n",
2039 (unsigned int)i
*1024,
2044 status
= check_size(cli
, fnum
, fname
, i
*1024);
2045 if (!NT_STATUS_IS_OK(status
)) {
2058 if (fnum
!= (uint16_t)-1) {
2059 cli_close(cli
, fnum
);
2061 cli_setatr(cli
, fname
, 0, 0);
2062 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2064 if (!torture_close_connection(cli
)) {
2070 /* Ensure SMB2 flush on directories behaves correctly. */
2072 static bool test_dir_fsync(struct cli_state
*cli
, const char *path
)
2075 uint64_t fid_persistent
, fid_volatile
;
2076 uint8_t *dir_data
= NULL
;
2077 uint32_t dir_data_length
= 0;
2079 /* Open directory - no write abilities. */
2080 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
2081 cli
->smb2
.tcon
, path
,
2082 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
2083 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
2084 SEC_STD_SYNCHRONIZE
|
2086 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
2087 0, /* file_attributes, */
2088 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
2089 FILE_OPEN
, /* create_disposition, */
2090 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
2091 NULL
, /* smb2_create_blobs *blobs */
2095 if (!NT_STATUS_IS_OK(status
)) {
2096 printf("smb2cli_create '%s' (readonly) returned %s\n",
2102 status
= smb2cli_query_directory(
2103 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
2104 1, 0, 0, fid_persistent
, fid_volatile
, "*", 0xffff,
2105 talloc_tos(), &dir_data
, &dir_data_length
);
2107 if (!NT_STATUS_IS_OK(status
)) {
2108 printf("smb2cli_query_directory returned %s\n",
2113 /* Open directory no write access. Flush should fail. */
2115 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
2116 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
2117 if (!NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
)) {
2118 printf("smb2cli_flush on a read-only directory returned %s\n",
2123 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
2124 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
2125 if (!NT_STATUS_IS_OK(status
)) {
2126 printf("smb2cli_close returned %s\n", nt_errstr(status
));
2130 /* Open directory write-attributes only. Flush should still fail. */
2132 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
2133 cli
->smb2
.tcon
, path
,
2134 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
2135 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
2136 SEC_STD_SYNCHRONIZE
|
2138 SEC_DIR_WRITE_ATTRIBUTE
|
2139 SEC_DIR_READ_ATTRIBUTE
, /* desired_access, */
2140 0, /* file_attributes, */
2141 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
2142 FILE_OPEN
, /* create_disposition, */
2143 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
2144 NULL
, /* smb2_create_blobs *blobs */
2148 if (!NT_STATUS_IS_OK(status
)) {
2149 printf("smb2cli_create '%s' (write attr) returned %s\n",
2155 status
= smb2cli_query_directory(
2156 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
2157 1, 0, 0, fid_persistent
, fid_volatile
, "*", 0xffff,
2158 talloc_tos(), &dir_data
, &dir_data_length
);
2160 if (!NT_STATUS_IS_OK(status
)) {
2161 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
2165 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
2166 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
2167 if (!NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
)) {
2168 printf("smb2cli_flush on a write-attributes directory "
2174 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
2175 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
2176 if (!NT_STATUS_IS_OK(status
)) {
2177 printf("smb2cli_close returned %s\n", nt_errstr(status
));
2181 /* Open directory with SEC_DIR_ADD_FILE access. Flush should now succeed. */
2183 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
2184 cli
->smb2
.tcon
, path
,
2185 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
2186 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
2187 SEC_STD_SYNCHRONIZE
|
2189 SEC_DIR_ADD_FILE
, /* desired_access, */
2190 0, /* file_attributes, */
2191 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
2192 FILE_OPEN
, /* create_disposition, */
2193 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
2194 NULL
, /* smb2_create_blobs *blobs */
2198 if (!NT_STATUS_IS_OK(status
)) {
2199 printf("smb2cli_create '%s' (write FILE access) returned %s\n",
2205 status
= smb2cli_query_directory(
2206 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
2207 1, 0, 0, fid_persistent
, fid_volatile
, "*", 0xffff,
2208 talloc_tos(), &dir_data
, &dir_data_length
);
2210 if (!NT_STATUS_IS_OK(status
)) {
2211 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
2215 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
2216 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
2217 if (!NT_STATUS_IS_OK(status
)) {
2218 printf("smb2cli_flush on a directory returned %s\n",
2223 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
2224 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
2225 if (!NT_STATUS_IS_OK(status
)) {
2226 printf("smb2cli_close returned %s\n", nt_errstr(status
));
2230 /* Open directory with SEC_DIR_ADD_FILE access. Flush should now succeed. */
2232 status
= smb2cli_create(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
2233 cli
->smb2
.tcon
, path
,
2234 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
2235 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
2236 SEC_STD_SYNCHRONIZE
|
2238 SEC_DIR_ADD_SUBDIR
, /* desired_access, */
2239 0, /* file_attributes, */
2240 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
2241 FILE_OPEN
, /* create_disposition, */
2242 FILE_SYNCHRONOUS_IO_NONALERT
|FILE_DIRECTORY_FILE
, /* create_options, */
2243 NULL
, /* smb2_create_blobs *blobs */
2247 if (!NT_STATUS_IS_OK(status
)) {
2248 printf("smb2cli_create '%s' (write DIR access) returned %s\n",
2254 status
= smb2cli_query_directory(
2255 cli
->conn
, cli
->timeout
, cli
->smb2
.session
, cli
->smb2
.tcon
,
2256 1, 0, 0, fid_persistent
, fid_volatile
, "*", 0xffff,
2257 talloc_tos(), &dir_data
, &dir_data_length
);
2259 if (!NT_STATUS_IS_OK(status
)) {
2260 printf("smb2cli_query_directory returned %s\n", nt_errstr(status
));
2264 status
= smb2cli_flush(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
2265 cli
->smb2
.tcon
, fid_persistent
, fid_volatile
);
2266 if (!NT_STATUS_IS_OK(status
)) {
2267 printf("smb2cli_flush on a directory returned %s\n",
2272 status
= smb2cli_close(cli
->conn
, cli
->timeout
, cli
->smb2
.session
,
2273 cli
->smb2
.tcon
, 0, fid_persistent
, fid_volatile
);
2274 if (!NT_STATUS_IS_OK(status
)) {
2275 printf("smb2cli_close returned %s\n", nt_errstr(status
));
2283 bool run_smb2_dir_fsync(int dummy
)
2285 struct cli_state
*cli
= NULL
;
2288 const char *dname
= "fsync_test_dir";
2290 printf("Starting SMB2-DIR-FSYNC\n");
2292 if (!torture_init_connection(&cli
)) {
2296 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
2297 PROTOCOL_SMB2_02
, PROTOCOL_SMB2_02
);
2298 if (!NT_STATUS_IS_OK(status
)) {
2299 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
2303 status
= cli_session_setup_creds(cli
, torture_creds
);
2304 if (!NT_STATUS_IS_OK(status
)) {
2305 printf("cli_session_setup returned %s\n", nt_errstr(status
));
2309 status
= cli_tree_connect(cli
, share
, "?????", NULL
);
2310 if (!NT_STATUS_IS_OK(status
)) {
2311 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
2315 (void)cli_rmdir(cli
, dname
);
2316 status
= cli_mkdir(cli
, dname
);
2317 if (!NT_STATUS_IS_OK(status
)) {
2318 printf("cli_mkdir(%s) returned %s\n",
2324 /* Test on a subdirectory. */
2325 bret
= test_dir_fsync(cli
, dname
);
2326 if (bret
== false) {
2327 (void)cli_rmdir(cli
, dname
);
2330 (void)cli_rmdir(cli
, dname
);
2332 /* Test on the root handle of a share. */
2333 bret
= test_dir_fsync(cli
, "");
2334 if (bret
== false) {
2340 bool run_smb2_path_slash(int dummy
)
2342 struct cli_state
*cli
= NULL
;
2344 uint64_t fid_persistent
;
2345 uint64_t fid_volatile
;
2346 const char *dname_noslash
= "smb2_dir_slash";
2347 const char *dname_backslash
= "smb2_dir_slash\\";
2348 const char *dname_slash
= "smb2_dir_slash/";
2349 const char *fname_noslash
= "smb2_file_slash";
2350 const char *fname_backslash
= "smb2_file_slash\\";
2351 const char *fname_slash
= "smb2_file_slash/";
2353 printf("Starting SMB2-PATH-SLASH\n");
2355 if (!torture_init_connection(&cli
)) {
2359 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
2360 PROTOCOL_SMB2_02
, PROTOCOL_SMB2_02
);
2361 if (!NT_STATUS_IS_OK(status
)) {
2362 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
2366 status
= cli_session_setup_creds(cli
, torture_creds
);
2367 if (!NT_STATUS_IS_OK(status
)) {
2368 printf("cli_session_setup returned %s\n", nt_errstr(status
));
2372 status
= cli_tree_connect(cli
, share
, "?????", NULL
);
2373 if (!NT_STATUS_IS_OK(status
)) {
2374 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
2378 (void)cli_unlink(cli
, dname_noslash
, 0);
2379 (void)cli_rmdir(cli
, dname_noslash
);
2380 (void)cli_unlink(cli
, fname_noslash
, 0);
2381 (void)cli_rmdir(cli
, fname_noslash
);
2383 /* Try to create a directory with the backslash name. */
2384 status
= smb2cli_create(cli
->conn
,
2389 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
2390 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
2391 FILE_READ_DATA
|FILE_READ_ATTRIBUTES
, /* desired_access, */
2392 0, /* file_attributes, */
2393 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
2394 FILE_CREATE
, /* create_disposition, */
2395 FILE_DIRECTORY_FILE
, /* create_options, */
2396 NULL
, /* smb2_create_blobs *blobs */
2401 /* directory ending in '\\' should be success. */
2403 if (!NT_STATUS_IS_OK(status
)) {
2404 printf("smb2cli_create '%s' returned %s - "
2405 "should be NT_STATUS_OK\n",
2410 status
= smb2cli_close(cli
->conn
,
2417 if (!NT_STATUS_IS_OK(status
)) {
2418 printf("smb2cli_close returned %s\n", nt_errstr(status
));
2422 (void)cli_rmdir(cli
, dname_noslash
);
2424 /* Try to create a directory with the slash name. */
2425 status
= smb2cli_create(cli
->conn
,
2430 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
2431 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
2432 FILE_READ_DATA
|FILE_READ_ATTRIBUTES
, /* desired_access, */
2433 0, /* file_attributes, */
2434 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
2435 FILE_CREATE
, /* create_disposition, */
2436 FILE_DIRECTORY_FILE
, /* create_options, */
2437 NULL
, /* smb2_create_blobs *blobs */
2442 /* directory ending in '/' is an error. */
2443 if (!NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_INVALID
)) {
2444 printf("smb2cli_create '%s' returned %s - "
2445 "should be NT_STATUS_OBJECT_NAME_INVALID\n",
2448 if (NT_STATUS_IS_OK(status
)) {
2449 (void)smb2cli_close(cli
->conn
,
2457 (void)cli_rmdir(cli
, dname_noslash
);
2461 (void)cli_rmdir(cli
, dname_noslash
);
2463 /* Try to create a file with the backslash name. */
2464 status
= smb2cli_create(cli
->conn
,
2469 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
2470 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
2471 FILE_READ_DATA
|FILE_READ_ATTRIBUTES
, /* desired_access, */
2472 0, /* file_attributes, */
2473 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
2474 FILE_CREATE
, /* create_disposition, */
2475 FILE_NON_DIRECTORY_FILE
, /* create_options, */
2476 NULL
, /* smb2_create_blobs *blobs */
2481 /* file ending in '\\' should be error. */
2483 if (!NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_INVALID
)) {
2484 printf("smb2cli_create '%s' returned %s - "
2485 "should be NT_STATUS_OBJECT_NAME_INVALID\n",
2488 if (NT_STATUS_IS_OK(status
)) {
2489 (void)smb2cli_close(cli
->conn
,
2497 (void)cli_unlink(cli
, fname_noslash
, 0);
2501 (void)cli_unlink(cli
, fname_noslash
, 0);
2503 /* Try to create a file with the slash name. */
2504 status
= smb2cli_create(cli
->conn
,
2509 SMB2_OPLOCK_LEVEL_NONE
, /* oplock_level, */
2510 SMB2_IMPERSONATION_IMPERSONATION
, /* impersonation_level, */
2511 FILE_READ_DATA
|FILE_READ_ATTRIBUTES
, /* desired_access, */
2512 0, /* file_attributes, */
2513 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, /* share_access, */
2514 FILE_CREATE
, /* create_disposition, */
2515 FILE_NON_DIRECTORY_FILE
, /* create_options, */
2516 NULL
, /* smb2_create_blobs *blobs */
2521 /* file ending in '/' should be error. */
2523 if (!NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_INVALID
)) {
2524 printf("smb2cli_create '%s' returned %s - "
2525 "should be NT_STATUS_OBJECT_NAME_INVALID\n",
2528 if (NT_STATUS_IS_OK(status
)) {
2529 (void)smb2cli_close(cli
->conn
,
2537 (void)cli_unlink(cli
, fname_noslash
, 0);
2541 (void)cli_unlink(cli
, fname_noslash
, 0);
2546 * NB. This can only work against a server where
2547 * the connecting user has been granted SeSecurityPrivilege.
2549 * 1). Create a test file.
2550 * 2). Open with SEC_FLAG_SYSTEM_SECURITY *only*. ACCESS_DENIED -
2551 * NB. SMB2-only behavior.
2552 * 3). Open with SEC_FLAG_SYSTEM_SECURITY|FILE_WRITE_ATTRIBUTES.
2553 * 4). Write SACL. Should fail with ACCESS_DENIED (seems to need WRITE_DAC).
2555 * 6). Open with SEC_FLAG_SYSTEM_SECURITY|SEC_STD_WRITE_DAC.
2556 * 7). Write SACL. Success.
2558 * 9). Open with SEC_FLAG_SYSTEM_SECURITY|READ_ATTRIBUTES.
2559 * 10). Read SACL. Success.
2560 * 11). Read DACL. Should fail with ACCESS_DENIED (no READ_CONTROL).
2564 bool run_smb2_sacl(int dummy
)
2566 struct cli_state
*cli
= NULL
;
2568 struct security_descriptor
*sd_dacl
= NULL
;
2569 struct security_descriptor
*sd_sacl
= NULL
;
2570 const char *fname
= "sacl_test_file";
2571 uint16_t fnum
= (uint16_t)-1;
2573 printf("Starting SMB2-SACL\n");
2575 if (!torture_init_connection(&cli
)) {
2579 status
= smbXcli_negprot(cli
->conn
,
2583 if (!NT_STATUS_IS_OK(status
)) {
2584 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
2588 status
= cli_session_setup_creds(cli
, torture_creds
);
2589 if (!NT_STATUS_IS_OK(status
)) {
2590 printf("cli_session_setup returned %s\n", nt_errstr(status
));
2594 status
= cli_tree_connect(cli
, share
, "?????", NULL
);
2595 if (!NT_STATUS_IS_OK(status
)) {
2596 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
2600 (void)cli_unlink(cli
, fname
, 0);
2602 /* First create a file. */
2603 status
= cli_ntcreate(cli
,
2607 FILE_ATTRIBUTE_NORMAL
,
2615 if (!NT_STATUS_IS_OK(status
)) {
2616 printf("Create of %s failed (%s)\n",
2622 cli_close(cli
, fnum
);
2623 fnum
= (uint16_t)-1;
2626 * Now try to open with *only* SEC_FLAG_SYSTEM_SECURITY.
2627 * This should fail with NT_STATUS_ACCESS_DENIED - but
2628 * only against an SMB2 server. SMB1 allows this as tested
2629 * in SMB1-SYSTEM-SECURITY.
2632 status
= cli_smb2_create_fnum(cli
,
2634 SMB2_OPLOCK_LEVEL_NONE
,
2635 SMB2_IMPERSONATION_IMPERSONATION
,
2636 SEC_FLAG_SYSTEM_SECURITY
, /* desired access */
2637 0, /* file_attributes, */
2640 FILE_SHARE_DELETE
, /* share_access, */
2641 FILE_OPEN
, /* create_disposition, */
2642 FILE_NON_DIRECTORY_FILE
, /* create_options, */
2643 NULL
, /* in_cblobs. */
2645 NULL
, /* smb_create_returns */
2646 talloc_tos(), /* mem_ctx */
2647 NULL
); /* out_cblobs */
2649 if (NT_STATUS_EQUAL(status
, NT_STATUS_PRIVILEGE_NOT_HELD
)) {
2650 printf("SMB2-SACL-TEST can only work with a user "
2651 "who has been granted SeSecurityPrivilege.\n"
2653 "\"Manage auditing and security log\""
2654 "privilege setting on Windows\n");
2658 if (!NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
)) {
2659 printf("open file %s with SEC_FLAG_SYSTEM_SECURITY only: "
2660 "got %s - should fail with ACCESS_DENIED\n",
2667 * Open with SEC_FLAG_SYSTEM_SECURITY|FILE_WRITE_ATTRIBUTES.
2670 status
= cli_smb2_create_fnum(cli
,
2672 SMB2_OPLOCK_LEVEL_NONE
,
2673 SMB2_IMPERSONATION_IMPERSONATION
,
2674 SEC_FLAG_SYSTEM_SECURITY
|
2675 FILE_WRITE_ATTRIBUTES
, /* desired access */
2676 0, /* file_attributes, */
2679 FILE_SHARE_DELETE
, /* share_access, */
2680 FILE_OPEN
, /* create_disposition, */
2681 FILE_NON_DIRECTORY_FILE
, /* create_options, */
2682 NULL
, /* in_cblobs. */
2684 NULL
, /* smb_create_returns */
2685 talloc_tos(), /* mem_ctx */
2686 NULL
); /* out_cblobs */
2688 if (!NT_STATUS_IS_OK(status
)) {
2689 printf("Open of %s with (SEC_FLAG_SYSTEM_SECURITY|"
2690 "FILE_WRITE_ATTRIBUTES) failed (%s)\n",
2696 /* Create an SD with a SACL. */
2697 sd_sacl
= security_descriptor_sacl_create(talloc_tos(),
2703 SEC_ACE_TYPE_SYSTEM_AUDIT
,
2705 SEC_ACE_FLAG_FAILED_ACCESS
,
2708 if (sd_sacl
== NULL
) {
2709 printf("Out of memory creating SACL\n");
2714 * Write the SACL SD. This should fail
2715 * even though we have SEC_FLAG_SYSTEM_SECURITY,
2716 * as it seems to also need WRITE_DAC access.
2718 status
= cli_set_security_descriptor(cli
,
2720 SECINFO_DACL
|SECINFO_SACL
,
2723 if (!NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
)) {
2724 printf("Writing SACL on file %s got (%s) "
2725 "should have failed with ACCESS_DENIED.\n",
2732 cli_smb2_close_fnum(cli
, fnum
);
2733 fnum
= (uint16_t)-1;
2736 * Open with SEC_FLAG_SYSTEM_SECURITY|SEC_STD_WRITE_DAC.
2739 status
= cli_smb2_create_fnum(cli
,
2741 SMB2_OPLOCK_LEVEL_NONE
,
2742 SMB2_IMPERSONATION_IMPERSONATION
,
2743 SEC_FLAG_SYSTEM_SECURITY
|
2744 SEC_STD_WRITE_DAC
, /* desired access */
2745 0, /* file_attributes, */
2748 FILE_SHARE_DELETE
, /* share_access, */
2749 FILE_OPEN
, /* create_disposition, */
2750 FILE_NON_DIRECTORY_FILE
, /* create_options, */
2751 NULL
, /* in_cblobs. */
2753 NULL
, /* smb_create_returns */
2754 talloc_tos(), /* mem_ctx */
2755 NULL
); /* out_cblobs */
2757 if (!NT_STATUS_IS_OK(status
)) {
2758 printf("Open of %s with (SEC_FLAG_SYSTEM_SECURITY|"
2759 "FILE_WRITE_ATTRIBUTES) failed (%s)\n",
2766 * Write the SACL SD. This should now succeed
2767 * as we have both SEC_FLAG_SYSTEM_SECURITY
2768 * and WRITE_DAC access.
2770 status
= cli_set_security_descriptor(cli
,
2772 SECINFO_DACL
|SECINFO_SACL
,
2775 if (!NT_STATUS_IS_OK(status
)) {
2776 printf("cli_set_security_descriptor SACL "
2777 "on file %s failed (%s)\n",
2784 cli_smb2_close_fnum(cli
, fnum
);
2785 fnum
= (uint16_t)-1;
2787 /* We're done with the sacl we made. */
2788 TALLOC_FREE(sd_sacl
);
2791 * Now try to open with SEC_FLAG_SYSTEM_SECURITY|READ_ATTRIBUTES.
2792 * This gives us access to the SACL.
2795 status
= cli_smb2_create_fnum(cli
,
2797 SMB2_OPLOCK_LEVEL_NONE
,
2798 SMB2_IMPERSONATION_IMPERSONATION
,
2799 SEC_FLAG_SYSTEM_SECURITY
|
2800 FILE_READ_ATTRIBUTES
, /* desired access */
2801 0, /* file_attributes, */
2804 FILE_SHARE_DELETE
, /* share_access, */
2805 FILE_OPEN
, /* create_disposition, */
2806 FILE_NON_DIRECTORY_FILE
, /* create_options, */
2807 NULL
, /* in_cblobs. */
2809 NULL
, /* smb_create_returns */
2810 talloc_tos(), /* mem_ctx */
2811 NULL
); /* out_cblobs */
2813 if (!NT_STATUS_IS_OK(status
)) {
2814 printf("Open of %s with (SEC_FLAG_SYSTEM_SECURITY|"
2815 "FILE_READ_ATTRIBUTES) failed (%s)\n",
2821 /* Try and read the SACL - should succeed. */
2822 status
= cli_query_security_descriptor(
2823 cli
, fnum
, SECINFO_SACL
, talloc_tos(), &sd_sacl
);
2825 if (!NT_STATUS_IS_OK(status
)) {
2826 printf("Read SACL from file %s failed (%s)\n",
2832 TALLOC_FREE(sd_sacl
);
2835 * Try and read the DACL - should fail as we have
2836 * no READ_DAC access.
2838 status
= cli_query_security_descriptor(
2839 cli
, fnum
, SECINFO_DACL
, talloc_tos(), &sd_sacl
);
2841 if (!NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
)) {
2842 printf("Reading DACL on file %s got (%s) "
2843 "should have failed with ACCESS_DENIED.\n",
2849 if (fnum
!= (uint16_t)-1) {
2850 cli_smb2_close_fnum(cli
, fnum
);
2851 fnum
= (uint16_t)-1;
2854 TALLOC_FREE(sd_dacl
);
2855 TALLOC_FREE(sd_sacl
);
2857 (void)cli_unlink(cli
, fname
, 0);
2862 TALLOC_FREE(sd_dacl
);
2863 TALLOC_FREE(sd_sacl
);
2865 if (fnum
!= (uint16_t)-1) {
2866 cli_smb2_close_fnum(cli
, fnum
);
2867 fnum
= (uint16_t)-1;
2870 (void)cli_unlink(cli
, fname
, 0);
2874 bool run_smb2_quota1(int dummy
)
2876 struct cli_state
*cli
= NULL
;
2878 uint16_t fnum
= (uint16_t)-1;
2879 SMB_NTQUOTA_STRUCT qt
= {0};
2881 printf("Starting SMB2-QUOTA1\n");
2883 if (!torture_init_connection(&cli
)) {
2887 status
= smbXcli_negprot(cli
->conn
,
2891 if (!NT_STATUS_IS_OK(status
)) {
2892 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
2896 status
= cli_session_setup_creds(cli
, torture_creds
);
2897 if (!NT_STATUS_IS_OK(status
)) {
2898 printf("cli_session_setup returned %s\n", nt_errstr(status
));
2902 status
= cli_tree_connect(cli
, share
, "?????", NULL
);
2903 if (!NT_STATUS_IS_OK(status
)) {
2904 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
2908 status
= cli_smb2_create_fnum(
2911 SMB2_OPLOCK_LEVEL_NONE
,
2912 SMB2_IMPERSONATION_IMPERSONATION
,
2913 SEC_GENERIC_READ
, /* desired access */
2914 0, /* file_attributes, */
2917 FILE_SHARE_DELETE
, /* share_access, */
2918 FILE_OPEN
, /* create_disposition, */
2919 FILE_DIRECTORY_FILE
, /* create_options, */
2920 NULL
, /* in_cblobs. */
2922 NULL
, /* smb_create_returns */
2924 NULL
); /* out_cblobs */
2925 if (!NT_STATUS_IS_OK(status
)) {
2926 printf("cli_smb2_create_fnum failed: %s\n", nt_errstr(status
));
2930 status
= cli_smb2_get_user_quota(cli
, fnum
, &qt
);
2931 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
2932 printf("cli_smb2_get_user_quota returned %s, expected "
2933 "NT_STATUS_INVALID_HANDLE\n",
2941 bool run_smb2_stream_acl(int dummy
)
2943 struct cli_state
*cli
= NULL
;
2945 uint16_t fnum
= (uint16_t)-1;
2946 const char *fname
= "stream_acl_test_file";
2947 const char *sname
= "stream_acl_test_file:streamname";
2948 struct security_descriptor
*sd_dacl
= NULL
;
2951 printf("SMB2 stream acl\n");
2953 if (!torture_init_connection(&cli
)) {
2957 status
= smbXcli_negprot(cli
->conn
,
2961 if (!NT_STATUS_IS_OK(status
)) {
2962 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
2966 status
= cli_session_setup_creds(cli
, torture_creds
);
2967 if (!NT_STATUS_IS_OK(status
)) {
2968 printf("cli_session_setup returned %s\n", nt_errstr(status
));
2972 status
= cli_tree_connect(cli
, share
, "?????", NULL
);
2973 if (!NT_STATUS_IS_OK(status
)) {
2974 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
2978 /* Ensure file doesn't exist. */
2979 (void)cli_unlink(cli
, fname
, 0);
2981 /* Create the file. */
2982 status
= cli_ntcreate(cli
,
2986 FILE_ATTRIBUTE_NORMAL
,
2994 if (!NT_STATUS_IS_OK(status
)) {
2995 printf("Create of %s failed (%s)\n",
3001 /* Close the handle. */
3002 cli_smb2_close_fnum(cli
, fnum
);
3003 fnum
= (uint16_t)-1;
3005 /* Create the stream. */
3006 status
= cli_ntcreate(cli
,
3010 SEC_STD_READ_CONTROL
|
3012 FILE_ATTRIBUTE_NORMAL
,
3020 if (!NT_STATUS_IS_OK(status
)) {
3021 printf("Create of %s failed (%s)\n",
3027 /* Close the handle. */
3028 cli_smb2_close_fnum(cli
, fnum
);
3029 fnum
= (uint16_t)-1;
3032 * Open the stream - for Samba this ensures
3033 * we prove we have a pathref fsp.
3035 status
= cli_ntcreate(cli
,
3039 SEC_STD_READ_CONTROL
|
3041 FILE_ATTRIBUTE_NORMAL
,
3049 if (!NT_STATUS_IS_OK(status
)) {
3050 printf("Open of %s failed (%s)\n",
3056 /* Read the security descriptor off the stream handle. */
3057 status
= cli_query_security_descriptor(cli
,
3063 if (!NT_STATUS_IS_OK(status
)) {
3064 printf("Reading DACL on stream %s got (%s)\n",
3070 if (sd_dacl
== NULL
|| sd_dacl
->dacl
== NULL
||
3071 sd_dacl
->dacl
->num_aces
< 1) {
3072 printf("Invalid DACL returned on stream %s "
3073 "(this should not happen)\n",
3079 * Ensure it allows FILE_READ_DATA in the first ace.
3082 if ((sd_dacl
->dacl
->aces
[0].access_mask
& FILE_READ_DATA
) == 0) {
3083 printf("DACL->ace[0] returned on stream %s "
3084 "doesn't have read access (should not happen)\n",
3089 /* Remove FILE_READ_DATA from the first ace and set. */
3090 sd_dacl
->dacl
->aces
[0].access_mask
&= ~FILE_READ_DATA
;
3092 status
= cli_set_security_descriptor(cli
,
3097 if (!NT_STATUS_IS_OK(status
)) {
3098 printf("Setting DACL on stream %s got (%s)\n",
3104 TALLOC_FREE(sd_dacl
);
3106 /* Read again and check it changed. */
3107 status
= cli_query_security_descriptor(cli
,
3113 if (!NT_STATUS_IS_OK(status
)) {
3114 printf("Reading DACL on stream %s got (%s)\n",
3120 if (sd_dacl
== NULL
|| sd_dacl
->dacl
== NULL
||
3121 sd_dacl
->dacl
->num_aces
< 1) {
3122 printf("Invalid DACL (1) returned on stream %s "
3123 "(this should not happen)\n",
3128 /* FILE_READ_DATA should be gone from the first ace. */
3129 if ((sd_dacl
->dacl
->aces
[0].access_mask
& FILE_READ_DATA
) != 0) {
3130 printf("DACL on stream %s did not change\n",
3139 if (fnum
!= (uint16_t)-1) {
3140 cli_smb2_close_fnum(cli
, fnum
);
3141 fnum
= (uint16_t)-1;
3144 (void)cli_unlink(cli
, fname
, 0);
3148 static NTSTATUS
list_fn(struct file_info
*finfo
,
3152 bool *matched
= (bool *)state
;
3153 if (finfo
->attr
& FILE_ATTRIBUTE_DIRECTORY
) {
3156 return NT_STATUS_OK
;
3160 * Must be run against a share with "smbd async dosmode = yes".
3161 * Checks we can return DOS attriutes other than "N".
3162 * BUG: https://bugzilla.samba.org/show_bug.cgi?id=14758
3165 bool run_list_dir_async_test(int dummy
)
3167 struct cli_state
*cli
= NULL
;
3169 const char *dname
= "ASYNC_DIR";
3171 bool matched
= false;
3173 printf("SMB2 list dir async\n");
3175 if (!torture_init_connection(&cli
)) {
3179 status
= smbXcli_negprot(cli
->conn
,
3183 if (!NT_STATUS_IS_OK(status
)) {
3184 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
3188 status
= cli_session_setup_creds(cli
, torture_creds
);
3189 if (!NT_STATUS_IS_OK(status
)) {
3190 printf("cli_session_setup returned %s\n", nt_errstr(status
));
3194 status
= cli_tree_connect(cli
, share
, "?????", NULL
);
3195 if (!NT_STATUS_IS_OK(status
)) {
3196 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
3200 /* Ensure directory doesn't exist. */
3201 (void)cli_rmdir(cli
, dname
);
3203 status
= cli_mkdir(cli
, dname
);
3204 if (!NT_STATUS_IS_OK(status
)) {
3205 printf("cli_mkdir %s returned %s\n", dname
, nt_errstr(status
));
3209 status
= cli_list(cli
,
3211 FILE_ATTRIBUTE_NORMAL
|FILE_ATTRIBUTE_DIRECTORY
,
3214 if (!NT_STATUS_IS_OK(status
)) {
3215 printf("cli_list %s returned %s\n", dname
, nt_errstr(status
));
3220 printf("Failed to find %s\n", dname
);
3228 (void)cli_rmdir(cli
, dname
);
3233 * Test delete a directory fails if a file is created
3234 * in a directory after the delete on close is set.
3235 * BUG: https://bugzilla.samba.org/show_bug.cgi?id=14892
3238 bool run_delete_on_close_non_empty(int dummy
)
3240 struct cli_state
*cli
= NULL
;
3242 const char *dname
= "DEL_ON_CLOSE_DIR";
3243 const char *fname
= "DEL_ON_CLOSE_DIR\\testfile";
3244 uint16_t fnum
= (uint16_t)-1;
3245 uint16_t fnum1
= (uint16_t)-1;
3248 printf("SMB2 delete on close nonempty\n");
3250 if (!torture_init_connection(&cli
)) {
3254 status
= smbXcli_negprot(cli
->conn
,
3258 if (!NT_STATUS_IS_OK(status
)) {
3259 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
3263 status
= cli_session_setup_creds(cli
, torture_creds
);
3264 if (!NT_STATUS_IS_OK(status
)) {
3265 printf("cli_session_setup returned %s\n", nt_errstr(status
));
3269 status
= cli_tree_connect(cli
, share
, "?????", NULL
);
3270 if (!NT_STATUS_IS_OK(status
)) {
3271 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
3275 /* Ensure directory doesn't exist. */
3276 (void)cli_unlink(cli
,
3278 FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3279 (void)cli_rmdir(cli
, dname
);
3281 /* Create target directory. */
3282 status
= cli_ntcreate(cli
,
3285 DELETE_ACCESS
|FILE_READ_DATA
,
3286 FILE_ATTRIBUTE_DIRECTORY
,
3291 FILE_DIRECTORY_FILE
,
3295 if (!NT_STATUS_IS_OK(status
)) {
3296 printf("cli_ntcreate for directory %s returned %s\n",
3302 /* Now set the delete on close bit. */
3303 status
= cli_nt_delete_on_close(cli
, fnum
, 1);
3304 if (!NT_STATUS_IS_OK(status
)) {
3305 printf("cli_cli_nt_delete_on_close set for directory "
3312 /* Create file inside target directory. */
3314 * NB. On Windows this will return NT_STATUS_DELETE_PENDING. Only on
3315 * Samba will this succeed by default (the option "check parent
3316 * directory delete on close" configures behaviour), but we're using
3317 * this to test a race condition.
3319 status
= cli_ntcreate(cli
,
3323 FILE_ATTRIBUTE_NORMAL
,
3332 if (!NT_STATUS_IS_OK(status
)) {
3333 printf("cli_ntcreate for file %s returned %s\n",
3338 cli_close(cli
, fnum1
);
3339 fnum1
= (uint16_t)-1;
3341 /* Now the close should fail. */
3342 status
= cli_close(cli
, fnum
);
3343 if (!NT_STATUS_EQUAL(status
, NT_STATUS_DIRECTORY_NOT_EMPTY
)) {
3344 printf("cli_close for directory %s returned %s\n",
3354 if (fnum1
!= (uint16_t)-1) {
3355 cli_close(cli
, fnum1
);
3357 if (fnum
!= (uint16_t)-1) {
3358 cli_nt_delete_on_close(cli
, fnum
, 0);
3359 cli_close(cli
, fnum
);
3361 (void)cli_unlink(cli
,
3363 FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3364 (void)cli_rmdir(cli
, dname
);
3368 static NTSTATUS
check_empty_fn(struct file_info
*finfo
,
3372 unsigned int *pcount
= (unsigned int *)private_data
;
3374 if (ISDOT(finfo
->name
) || ISDOTDOT(finfo
->name
)) {
3376 return NT_STATUS_OK
;
3378 return NT_STATUS_DIRECTORY_NOT_EMPTY
;
3382 * Test setting the delete on close bit on a directory
3383 * containing an unwritable file fails or succeeds
3384 * an a share set with "hide unwritable = yes"
3385 * depending on the setting of "delete veto files".
3386 * BUG: https://bugzilla.samba.org/show_bug.cgi?id=15023
3388 * First version. With "delete veto files = yes"
3389 * setting the delete on close should succeed.
3392 bool run_delete_on_close_nonwrite_delete_yes_test(int dummy
)
3394 struct cli_state
*cli
= NULL
;
3396 const char *dname
= "delete_veto_yes";
3397 const char *list_dname
= "delete_veto_yes\\*";
3398 uint16_t fnum
= (uint16_t)-1;
3400 unsigned int list_count
= 0;
3402 printf("SMB2 delete on close nonwrite - delete veto yes\n");
3404 if (!torture_init_connection(&cli
)) {
3408 status
= smbXcli_negprot(cli
->conn
,
3412 if (!NT_STATUS_IS_OK(status
)) {
3413 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
3417 status
= cli_session_setup_creds(cli
, torture_creds
);
3418 if (!NT_STATUS_IS_OK(status
)) {
3419 printf("cli_session_setup returned %s\n", nt_errstr(status
));
3423 status
= cli_tree_connect(cli
, share
, "?????", NULL
);
3424 if (!NT_STATUS_IS_OK(status
)) {
3425 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
3429 /* Ensure target directory is seen as empty. */
3430 status
= cli_list(cli
,
3432 FILE_ATTRIBUTE_DIRECTORY
|
3433 FILE_ATTRIBUTE_HIDDEN
|
3434 FILE_ATTRIBUTE_SYSTEM
,
3437 if (!NT_STATUS_IS_OK(status
)) {
3438 printf("cli_list of %s returned %s\n",
3443 if (list_count
!= 2) {
3444 printf("cli_list of %s returned a count of %u\n",
3450 /* Open target directory. */
3451 status
= cli_ntcreate(cli
,
3454 DELETE_ACCESS
|FILE_READ_DATA
,
3455 FILE_ATTRIBUTE_DIRECTORY
,
3460 FILE_DIRECTORY_FILE
,
3464 if (!NT_STATUS_IS_OK(status
)) {
3465 printf("cli_ntcreate for directory %s returned %s\n",
3471 /* Now set the delete on close bit. */
3472 status
= cli_nt_delete_on_close(cli
, fnum
, 1);
3473 if (!NT_STATUS_IS_OK(status
)) {
3474 printf("cli_cli_nt_delete_on_close set for directory "
3475 "%s returned %s (should have succeeded)\n",
3485 if (fnum
!= (uint16_t)-1) {
3486 (void)cli_nt_delete_on_close(cli
, fnum
, 0);
3487 (void)cli_close(cli
, fnum
);
3493 * Test setting the delete on close bit on a directory
3494 * containing an unwritable file fails or succeeds
3495 * an a share set with "hide unwritable = yes"
3496 * depending on the setting of "delete veto files".
3497 * BUG: https://bugzilla.samba.org/show_bug.cgi?id=15023
3499 * Second version. With "delete veto files = no"
3500 * setting the delete on close should fail.
3503 bool run_delete_on_close_nonwrite_delete_no_test(int dummy
)
3505 struct cli_state
*cli
= NULL
;
3507 const char *dname
= "delete_veto_no";
3508 const char *list_dname
= "delete_veto_no\\*";
3509 uint16_t fnum
= (uint16_t)-1;
3511 unsigned int list_count
= 0;
3513 printf("SMB2 delete on close nonwrite - delete veto yes\n");
3515 if (!torture_init_connection(&cli
)) {
3519 status
= smbXcli_negprot(cli
->conn
,
3523 if (!NT_STATUS_IS_OK(status
)) {
3524 printf("smbXcli_negprot returned %s\n", nt_errstr(status
));
3528 status
= cli_session_setup_creds(cli
, torture_creds
);
3529 if (!NT_STATUS_IS_OK(status
)) {
3530 printf("cli_session_setup returned %s\n", nt_errstr(status
));
3534 status
= cli_tree_connect(cli
, share
, "?????", NULL
);
3535 if (!NT_STATUS_IS_OK(status
)) {
3536 printf("cli_tree_connect returned %s\n", nt_errstr(status
));
3540 /* Ensure target directory is seen as empty. */
3541 status
= cli_list(cli
,
3543 FILE_ATTRIBUTE_DIRECTORY
|
3544 FILE_ATTRIBUTE_HIDDEN
|
3545 FILE_ATTRIBUTE_SYSTEM
,
3548 if (!NT_STATUS_IS_OK(status
)) {
3549 printf("cli_list of %s returned %s\n",
3554 if (list_count
!= 2) {
3555 printf("cli_list of %s returned a count of %u\n",
3561 /* Open target directory. */
3562 status
= cli_ntcreate(cli
,
3565 DELETE_ACCESS
|FILE_READ_DATA
,
3566 FILE_ATTRIBUTE_DIRECTORY
,
3571 FILE_DIRECTORY_FILE
,
3575 if (!NT_STATUS_IS_OK(status
)) {
3576 printf("cli_ntcreate for directory %s returned %s\n",
3582 /* Now set the delete on close bit. */
3583 status
= cli_nt_delete_on_close(cli
, fnum
, 1);
3584 if (NT_STATUS_IS_OK(status
)) {
3585 printf("cli_cli_nt_delete_on_close set for directory "
3586 "%s returned NT_STATUS_OK "
3587 "(should have failed)\n",
3591 if (!NT_STATUS_EQUAL(status
, NT_STATUS_DIRECTORY_NOT_EMPTY
)) {
3592 printf("cli_cli_nt_delete_on_close set for directory "
3594 "(should have returned "
3595 "NT_STATUS_DIRECTORY_NOT_EMPTY)\n",
3605 if (fnum
!= (uint16_t)-1) {
3606 (void)cli_nt_delete_on_close(cli
, fnum
, 0);
3607 (void)cli_close(cli
, fnum
);