2 Unix SMB/CIFS implementation.
4 helper functions for SMB2 test suite
6 Copyright (C) Andrew Tridgell 2005
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "libcli/security/security_descriptor.h"
24 #include "libcli/smb2/smb2.h"
25 #include "libcli/smb2/smb2_calls.h"
26 #include "../libcli/smb/smbXcli_base.h"
27 #include "lib/cmdline/popt_common.h"
28 #include "system/time.h"
29 #include "librpc/gen_ndr/ndr_security.h"
30 #include "param/param.h"
31 #include "libcli/resolve/resolve.h"
32 #include "lib/util/tevent_ntstatus.h"
34 #include "torture/torture.h"
35 #include "torture/smb2/proto.h"
36 #include "source4/torture/util.h"
40 write to a file on SMB2
42 NTSTATUS smb2_util_write(struct smb2_tree *tree,
43 struct smb2_handle handle,
44 const void *buf, off_t offset, size_t size)
49 w.in.file.handle = handle;
51 w.in.data = data_blob_const(buf, size);
53 return smb2_write(tree, &w);
57 create a complex file/dir using the SMB2 protocol
59 static NTSTATUS smb2_create_complex(struct torture_context *tctx,
60 struct smb2_tree *tree,
62 struct smb2_handle *handle,
65 TALLOC_CTX *tmp_ctx = talloc_new(tree);
67 struct smb2_create io;
68 union smb_setfileinfo setfile;
69 union smb_fileinfo fileinfo;
70 time_t t = (time(NULL) & ~1);
73 smb2_util_unlink(tree, fname);
75 io.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED;
76 io.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
77 io.in.create_disposition = NTCREATEX_DISP_OVERWRITE_IF;
79 NTCREATEX_SHARE_ACCESS_DELETE|
80 NTCREATEX_SHARE_ACCESS_READ|
81 NTCREATEX_SHARE_ACCESS_WRITE;
82 io.in.create_options = 0;
85 io.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
86 io.in.share_access &= ~NTCREATEX_SHARE_ACCESS_DELETE;
87 io.in.file_attributes = FILE_ATTRIBUTE_DIRECTORY;
88 io.in.create_disposition = NTCREATEX_DISP_CREATE;
91 /* it seems vista is now fussier about alignment? */
92 if (strchr(fname, ':') == NULL) {
94 io.in.eas.num_eas = 2;
95 io.in.eas.eas = talloc_array(tmp_ctx, struct ea_struct, 2);
96 io.in.eas.eas[0].flags = 0;
97 io.in.eas.eas[0].name.s = "EAONE";
98 io.in.eas.eas[0].value = data_blob_talloc(tmp_ctx, "VALUE1", 6);
99 io.in.eas.eas[1].flags = 0;
100 io.in.eas.eas[1].name.s = "SECONDEA";
101 io.in.eas.eas[1].value = data_blob_talloc(tmp_ctx, "ValueTwo", 8);
104 status = smb2_create(tree, tmp_ctx, &io);
105 if (NT_STATUS_EQUAL(status, NT_STATUS_EAS_NOT_SUPPORTED)) {
107 tctx, "EAs not supported, creating: %s\n", fname);
108 io.in.eas.num_eas = 0;
109 status = smb2_create(tree, tmp_ctx, &io);
112 talloc_free(tmp_ctx);
113 NT_STATUS_NOT_OK_RETURN(status);
115 *handle = io.out.file.handle;
118 status = smb2_util_write(tree, *handle, buf, 0, sizeof(buf));
119 NT_STATUS_NOT_OK_RETURN(status);
122 /* make sure all the timestamps aren't the same, and are also
123 in different DST zones*/
124 setfile.generic.level = RAW_SFILEINFO_BASIC_INFORMATION;
125 setfile.generic.in.file.handle = *handle;
127 unix_to_nt_time(&setfile.basic_info.in.create_time, t + 9*30*24*60*60);
128 unix_to_nt_time(&setfile.basic_info.in.access_time, t + 6*30*24*60*60);
129 unix_to_nt_time(&setfile.basic_info.in.write_time, t + 3*30*24*60*60);
130 unix_to_nt_time(&setfile.basic_info.in.change_time, t + 1*30*24*60*60);
131 setfile.basic_info.in.attrib = FILE_ATTRIBUTE_NORMAL;
133 status = smb2_setinfo_file(tree, &setfile);
134 if (!NT_STATUS_IS_OK(status)) {
135 torture_comment(tctx, "Failed to setup file times - %s\n", nt_errstr(status));
139 /* make sure all the timestamps aren't the same */
140 fileinfo.generic.level = RAW_FILEINFO_SMB2_ALL_INFORMATION;
141 fileinfo.generic.in.file.handle = *handle;
143 status = smb2_getinfo_file(tree, tree, &fileinfo);
144 if (!NT_STATUS_IS_OK(status)) {
145 torture_comment(tctx, "Failed to query file times - %s\n", nt_errstr(status));
150 #define CHECK_TIME(field) do {\
151 if (setfile.basic_info.in.field != fileinfo.all_info2.out.field) { \
152 torture_comment(tctx, "(%s) " #field " not setup correctly: %s(%llu) => %s(%llu)\n", \
154 nt_time_string(tree, setfile.basic_info.in.field), \
155 (unsigned long long)setfile.basic_info.in.field, \
156 nt_time_string(tree, fileinfo.basic_info.out.field), \
157 (unsigned long long)fileinfo.basic_info.out.field); \
158 status = NT_STATUS_INVALID_PARAMETER; \
162 CHECK_TIME(create_time);
163 CHECK_TIME(access_time);
164 CHECK_TIME(write_time);
165 CHECK_TIME(change_time);
171 create a complex file using the SMB2 protocol
173 NTSTATUS smb2_create_complex_file(struct torture_context *tctx,
174 struct smb2_tree *tree, const char *fname,
175 struct smb2_handle *handle)
177 return smb2_create_complex(tctx, tree, fname, handle, false);
181 create a complex dir using the SMB2 protocol
183 NTSTATUS smb2_create_complex_dir(struct torture_context *tctx,
184 struct smb2_tree *tree, const char *fname,
185 struct smb2_handle *handle)
187 return smb2_create_complex(tctx, tree, fname, handle, true);
191 show lots of information about a file
193 void torture_smb2_all_info(struct torture_context *tctx,
194 struct smb2_tree *tree, struct smb2_handle handle)
197 TALLOC_CTX *tmp_ctx = talloc_new(tree);
198 union smb_fileinfo io;
200 io.generic.level = RAW_FILEINFO_SMB2_ALL_INFORMATION;
201 io.generic.in.file.handle = handle;
203 status = smb2_getinfo_file(tree, tmp_ctx, &io);
204 if (!NT_STATUS_IS_OK(status)) {
205 DEBUG(0,("getinfo failed - %s\n", nt_errstr(status)));
206 talloc_free(tmp_ctx);
210 torture_comment(tctx, "all_info for '%s'\n", io.all_info2.out.fname.s);
211 torture_comment(tctx, "\tcreate_time: %s\n", nt_time_string(tmp_ctx, io.all_info2.out.create_time));
212 torture_comment(tctx, "\taccess_time: %s\n", nt_time_string(tmp_ctx, io.all_info2.out.access_time));
213 torture_comment(tctx, "\twrite_time: %s\n", nt_time_string(tmp_ctx, io.all_info2.out.write_time));
214 torture_comment(tctx, "\tchange_time: %s\n", nt_time_string(tmp_ctx, io.all_info2.out.change_time));
215 torture_comment(tctx, "\tattrib: 0x%x\n", io.all_info2.out.attrib);
216 torture_comment(tctx, "\tunknown1: 0x%x\n", io.all_info2.out.unknown1);
217 torture_comment(tctx, "\talloc_size: %llu\n", (long long)io.all_info2.out.alloc_size);
218 torture_comment(tctx, "\tsize: %llu\n", (long long)io.all_info2.out.size);
219 torture_comment(tctx, "\tnlink: %u\n", io.all_info2.out.nlink);
220 torture_comment(tctx, "\tdelete_pending: %u\n", io.all_info2.out.delete_pending);
221 torture_comment(tctx, "\tdirectory: %u\n", io.all_info2.out.directory);
222 torture_comment(tctx, "\tfile_id: %llu\n", (long long)io.all_info2.out.file_id);
223 torture_comment(tctx, "\tea_size: %u\n", io.all_info2.out.ea_size);
224 torture_comment(tctx, "\taccess_mask: 0x%08x\n", io.all_info2.out.access_mask);
225 torture_comment(tctx, "\tposition: 0x%llx\n", (long long)io.all_info2.out.position);
226 torture_comment(tctx, "\tmode: 0x%llx\n", (long long)io.all_info2.out.mode);
228 /* short name, if any */
229 io.generic.level = RAW_FILEINFO_ALT_NAME_INFORMATION;
230 status = smb2_getinfo_file(tree, tmp_ctx, &io);
231 if (NT_STATUS_IS_OK(status)) {
232 torture_comment(tctx, "\tshort name: '%s'\n", io.alt_name_info.out.fname.s);
235 /* the EAs, if any */
236 io.generic.level = RAW_FILEINFO_SMB2_ALL_EAS;
237 status = smb2_getinfo_file(tree, tmp_ctx, &io);
238 if (NT_STATUS_IS_OK(status)) {
240 for (i=0;i<io.all_eas.out.num_eas;i++) {
241 torture_comment(tctx, "\tEA[%d] flags=%d len=%d '%s'\n", i,
242 io.all_eas.out.eas[i].flags,
243 (int)io.all_eas.out.eas[i].value.length,
244 io.all_eas.out.eas[i].name.s);
248 /* streams, if available */
249 io.generic.level = RAW_FILEINFO_STREAM_INFORMATION;
250 status = smb2_getinfo_file(tree, tmp_ctx, &io);
251 if (NT_STATUS_IS_OK(status)) {
253 for (i=0;i<io.stream_info.out.num_streams;i++) {
254 torture_comment(tctx, "\tstream %d:\n", i);
255 torture_comment(tctx, "\t\tsize %ld\n",
256 (long)io.stream_info.out.streams[i].size);
257 torture_comment(tctx, "\t\talloc size %ld\n",
258 (long)io.stream_info.out.streams[i].alloc_size);
259 torture_comment(tctx, "\t\tname %s\n", io.stream_info.out.streams[i].stream_name.s);
264 /* the security descriptor */
265 io.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
266 io.query_secdesc.in.secinfo_flags =
267 SECINFO_OWNER|SECINFO_GROUP|
269 status = smb2_getinfo_file(tree, tmp_ctx, &io);
270 if (NT_STATUS_IS_OK(status)) {
271 NDR_PRINT_DEBUG(security_descriptor, io.query_secdesc.out.sd);
275 talloc_free(tmp_ctx);
279 get granted access of a file handle
281 NTSTATUS torture_smb2_get_allinfo_access(struct smb2_tree *tree,
282 struct smb2_handle handle,
283 uint32_t *granted_access)
286 TALLOC_CTX *tmp_ctx = talloc_new(tree);
287 union smb_fileinfo io;
289 io.generic.level = RAW_FILEINFO_SMB2_ALL_INFORMATION;
290 io.generic.in.file.handle = handle;
292 status = smb2_getinfo_file(tree, tmp_ctx, &io);
293 if (!NT_STATUS_IS_OK(status)) {
294 DEBUG(0, ("getinfo failed - %s\n", nt_errstr(status)));
298 *granted_access = io.all_info2.out.access_mask;
301 talloc_free(tmp_ctx);
306 * open a smb2 tree connect
308 bool torture_smb2_tree_connect(struct torture_context *tctx,
309 struct smb2_session *session,
311 struct smb2_tree **_tree)
314 const char *host = torture_setting_string(tctx, "host", NULL);
315 const char *share = torture_setting_string(tctx, "share", NULL);
317 struct smb2_tree *tree;
318 struct tevent_req *subreq;
319 uint32_t timeout_msec;
321 unc = talloc_asprintf(tctx, "\\\\%s\\%s", host, share);
322 torture_assert(tctx, unc != NULL, "talloc_asprintf");
324 tree = smb2_tree_init(session, mem_ctx, false);
325 torture_assert(tctx, tree != NULL, "smb2_tree_init");
327 timeout_msec = session->transport->options.request_timeout * 1000;
329 subreq = smb2cli_tcon_send(tree, tctx->ev,
330 session->transport->conn,
336 torture_assert(tctx, subreq != NULL, "smb2cli_tcon_send");
339 tevent_req_poll_ntstatus(subreq, tctx->ev, &status),
340 "tevent_req_poll_ntstatus");
342 status = smb2cli_tcon_recv(subreq);
344 torture_assert_ntstatus_ok(tctx, status, "smb2cli_tcon_recv");
352 * do a smb2 session setup (without a tree connect)
354 bool torture_smb2_session_setup(struct torture_context *tctx,
355 struct smb2_transport *transport,
356 uint64_t previous_session_id,
358 struct smb2_session **_session)
361 struct smb2_session *session;
363 session = smb2_session_init(transport,
364 lpcfg_gensec_settings(tctx, tctx->lp_ctx),
367 if (session == NULL) {
371 status = smb2_session_setup_spnego(session,
372 popt_get_cmdline_credentials(),
373 previous_session_id);
374 if (!NT_STATUS_IS_OK(status)) {
375 torture_comment(tctx, "session setup failed: %s\n", nt_errstr(status));
376 talloc_free(session);
386 open a smb2 connection
388 bool torture_smb2_connection_ext(struct torture_context *tctx,
389 uint64_t previous_session_id,
390 const struct smbcli_options *options,
391 struct smb2_tree **tree)
394 const char *host = torture_setting_string(tctx, "host", NULL);
395 const char *share = torture_setting_string(tctx, "share", NULL);
396 const char *p = torture_setting_string(tctx, "unclist", NULL);
397 TALLOC_CTX *mem_ctx = NULL;
404 mem_ctx = talloc_new(tctx);
405 if (mem_ctx == NULL) {
409 ok = torture_get_conn_index(tctx->conn_index++, mem_ctx, tctx,
412 TALLOC_FREE(mem_ctx);
420 status = smb2_connect_ext(tctx,
422 lpcfg_smb_ports(tctx->lp_ctx),
424 lpcfg_resolve_context(tctx->lp_ctx),
425 popt_get_cmdline_credentials(),
430 lpcfg_socket_options(tctx->lp_ctx),
431 lpcfg_gensec_settings(tctx, tctx->lp_ctx)
433 if (!NT_STATUS_IS_OK(status)) {
434 torture_comment(tctx, "Failed to connect to SMB2 share \\\\%s\\%s - %s\n",
435 host, share, nt_errstr(status));
436 TALLOC_FREE(mem_ctx);
440 TALLOC_FREE(mem_ctx);
444 bool torture_smb2_connection(struct torture_context *tctx, struct smb2_tree **tree)
447 struct smbcli_options options;
449 lpcfg_smbcli_options(tctx->lp_ctx, &options);
451 ret = torture_smb2_connection_ext(tctx, 0, &options, tree);
457 * SMB2 connect with share from soption
459 bool torture_smb2_con_sopt(struct torture_context *tctx,
461 struct smb2_tree **tree)
463 struct smbcli_options options;
465 const char *host = torture_setting_string(tctx, "host", NULL);
466 const char *share = torture_setting_string(tctx, soption, NULL);
468 lpcfg_smbcli_options(tctx->lp_ctx, &options);
471 torture_comment(tctx, "No share for option %s\n", soption);
475 status = smb2_connect_ext(tctx,
477 lpcfg_smb_ports(tctx->lp_ctx),
479 lpcfg_resolve_context(tctx->lp_ctx),
480 popt_get_cmdline_credentials(),
485 lpcfg_socket_options(tctx->lp_ctx),
486 lpcfg_gensec_settings(tctx, tctx->lp_ctx)
488 if (!NT_STATUS_IS_OK(status)) {
489 torture_comment(tctx, "Failed to connect to SMB2 share \\\\%s\\%s - %s\n",
490 host, share, nt_errstr(status));
497 create and return a handle to a test file
498 with a specific access mask
500 NTSTATUS torture_smb2_testfile_access(struct smb2_tree *tree, const char *fname,
501 struct smb2_handle *handle,
502 uint32_t desired_access)
504 struct smb2_create io;
508 io.in.oplock_level = 0;
509 io.in.desired_access = desired_access;
510 io.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
511 io.in.create_disposition = NTCREATEX_DISP_OPEN_IF;
513 NTCREATEX_SHARE_ACCESS_DELETE|
514 NTCREATEX_SHARE_ACCESS_READ|
515 NTCREATEX_SHARE_ACCESS_WRITE;
516 io.in.create_options = 0;
519 status = smb2_create(tree, tree, &io);
520 NT_STATUS_NOT_OK_RETURN(status);
522 *handle = io.out.file.handle;
528 create and return a handle to a test file
530 NTSTATUS torture_smb2_testfile(struct smb2_tree *tree, const char *fname,
531 struct smb2_handle *handle)
533 return torture_smb2_testfile_access(tree, fname, handle,
534 SEC_RIGHTS_FILE_ALL);
538 create and return a handle to a test file
539 with a specific access mask
541 NTSTATUS torture_smb2_open(struct smb2_tree *tree,
543 uint32_t desired_access,
544 struct smb2_handle *handle)
546 struct smb2_create io;
549 io = (struct smb2_create) {
551 .in.desired_access = desired_access,
552 .in.file_attributes = FILE_ATTRIBUTE_NORMAL,
553 .in.create_disposition = NTCREATEX_DISP_OPEN,
554 .in.share_access = NTCREATEX_SHARE_ACCESS_MASK,
557 status = smb2_create(tree, tree, &io);
558 if (!NT_STATUS_IS_OK(status)) {
562 *handle = io.out.file.handle;
568 create and return a handle to a test directory
569 with specific desired access
571 NTSTATUS torture_smb2_testdir_access(struct smb2_tree *tree, const char *fname,
572 struct smb2_handle *handle,
573 uint32_t desired_access)
575 struct smb2_create io;
579 io.in.oplock_level = 0;
580 io.in.desired_access = desired_access;
581 io.in.file_attributes = FILE_ATTRIBUTE_DIRECTORY;
582 io.in.create_disposition = NTCREATEX_DISP_OPEN_IF;
583 io.in.share_access = NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE;
584 io.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
587 status = smb2_create(tree, tree, &io);
588 NT_STATUS_NOT_OK_RETURN(status);
590 *handle = io.out.file.handle;
596 create and return a handle to a test directory
598 NTSTATUS torture_smb2_testdir(struct smb2_tree *tree, const char *fname,
599 struct smb2_handle *handle)
601 return torture_smb2_testdir_access(tree, fname, handle,
606 create a simple file using the SMB2 protocol
608 NTSTATUS smb2_create_simple_file(struct torture_context *tctx,
609 struct smb2_tree *tree, const char *fname,
610 struct smb2_handle *handle)
615 smb2_util_unlink(tree, fname);
616 status = torture_smb2_testfile_access(tree,
618 SEC_FLAG_MAXIMUM_ALLOWED);
619 NT_STATUS_NOT_OK_RETURN(status);
621 status = smb2_util_write(tree, *handle, buf, 0, sizeof(buf));
622 NT_STATUS_NOT_OK_RETURN(status);
628 create a simple file using SMB2.
630 NTSTATUS torture_setup_simple_file(struct torture_context *tctx,
631 struct smb2_tree *tree, const char *fname)
633 struct smb2_handle handle;
634 NTSTATUS status = smb2_create_simple_file(tctx, tree, fname, &handle);
635 NT_STATUS_NOT_OK_RETURN(status);
636 return smb2_util_close(tree, handle);
640 create a complex file using SMB2, to make it easier to
641 find fields in SMB2 getinfo levels
643 NTSTATUS torture_setup_complex_file(struct torture_context *tctx,
644 struct smb2_tree *tree, const char *fname)
646 struct smb2_handle handle;
647 NTSTATUS status = smb2_create_complex_file(tctx, tree, fname, &handle);
648 NT_STATUS_NOT_OK_RETURN(status);
649 return smb2_util_close(tree, handle);
654 create a complex dir using SMB2, to make it easier to
655 find fields in SMB2 getinfo levels
657 NTSTATUS torture_setup_complex_dir(struct torture_context *tctx,
658 struct smb2_tree *tree, const char *fname)
660 struct smb2_handle handle;
661 NTSTATUS status = smb2_create_complex_dir(tctx, tree, fname, &handle);
662 NT_STATUS_NOT_OK_RETURN(status);
663 return smb2_util_close(tree, handle);
668 return a handle to the root of the share
670 NTSTATUS smb2_util_roothandle(struct smb2_tree *tree, struct smb2_handle *handle)
672 struct smb2_create io;
676 io.in.oplock_level = 0;
677 io.in.desired_access = SEC_STD_SYNCHRONIZE | SEC_DIR_READ_ATTRIBUTE | SEC_DIR_LIST;
678 io.in.file_attributes = 0;
679 io.in.create_disposition = NTCREATEX_DISP_OPEN;
680 io.in.share_access = NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_DELETE;
681 io.in.create_options = NTCREATEX_OPTIONS_ASYNC_ALERT;
684 status = smb2_create(tree, tree, &io);
685 NT_STATUS_NOT_OK_RETURN(status);
687 *handle = io.out.file.handle;
692 /* Comparable to torture_setup_dir, but for SMB2. */
693 bool smb2_util_setup_dir(struct torture_context *tctx, struct smb2_tree *tree,
698 /* XXX: smb_raw_exit equivalent?
699 smb_raw_exit(cli->session); */
700 if (smb2_deltree(tree, dname) == -1) {
701 torture_result(tctx, TORTURE_ERROR, "Unable to deltree when setting up %s.\n", dname);
705 status = smb2_util_mkdir(tree, dname);
706 if (NT_STATUS_IS_ERR(status)) {
707 torture_result(tctx, TORTURE_ERROR, "Unable to mkdir when setting up %s - %s\n", dname,
716 * Helper function to verify a security descriptor, by querying
717 * and comparing against the passed in sd.
719 bool smb2_util_verify_sd(TALLOC_CTX *tctx, struct smb2_tree *tree,
720 struct smb2_handle handle, struct security_descriptor *sd)
724 union smb_fileinfo q = {};
726 q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
727 q.query_secdesc.in.file.handle = handle;
728 q.query_secdesc.in.secinfo_flags =
732 status = smb2_getinfo_file(tree, tctx, &q);
733 torture_assert_ntstatus_ok(tctx, status, "");
735 if (!security_acl_equal(
736 q.query_secdesc.out.sd->dacl, sd->dacl)) {
737 torture_warning(tctx, "%s: security descriptors don't match!\n",
739 torture_warning(tctx, "got:\n");
740 NDR_PRINT_DEBUG(security_descriptor,
741 q.query_secdesc.out.sd);
742 torture_warning(tctx, "expected:\n");
743 NDR_PRINT_DEBUG(security_descriptor, sd);
751 * Helper function to verify attributes, by querying
752 * and comparing against the passed in attrib.
754 bool smb2_util_verify_attrib(TALLOC_CTX *tctx, struct smb2_tree *tree,
755 struct smb2_handle handle, uint32_t attrib)
759 union smb_fileinfo q = {};
761 q.standard.level = RAW_FILEINFO_SMB2_ALL_INFORMATION;
762 q.standard.in.file.handle = handle;
763 status = smb2_getinfo_file(tree, tctx, &q);
764 torture_assert_ntstatus_ok(tctx, status, "");
766 q.all_info2.out.attrib &= ~(FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_NONINDEXED);
768 if (q.all_info2.out.attrib != attrib) {
769 torture_warning(tctx, "%s: attributes don't match! "
770 "got %x, expected %x\n", __location__,
771 (uint32_t)q.standard.out.attrib,
780 uint32_t smb2_util_lease_state(const char *ls)
785 for (i = 0; i < strlen(ls); i++) {
788 val |= SMB2_LEASE_READ;
791 val |= SMB2_LEASE_HANDLE;
794 val |= SMB2_LEASE_WRITE;
803 uint32_t smb2_util_share_access(const char *sharemode)
805 uint32_t val = NTCREATEX_SHARE_ACCESS_NONE; /* 0 */
808 for (i = 0; i < strlen(sharemode); i++) {
809 switch(sharemode[i]) {
811 val |= NTCREATEX_SHARE_ACCESS_READ;
814 val |= NTCREATEX_SHARE_ACCESS_WRITE;
817 val |= NTCREATEX_SHARE_ACCESS_DELETE;
825 uint8_t smb2_util_oplock_level(const char *op)
827 uint8_t val = SMB2_OPLOCK_LEVEL_NONE;
830 for (i = 0; i < strlen(op); i++) {
833 return SMB2_OPLOCK_LEVEL_II;
835 return SMB2_OPLOCK_LEVEL_EXCLUSIVE;
837 return SMB2_OPLOCK_LEVEL_BATCH;
847 * Helper functions to fill a smb2_create struct for several
850 void smb2_generic_create_share(struct smb2_create *io, struct smb2_lease *ls,
851 bool dir, const char *name, uint32_t disposition,
852 uint32_t share_access,
853 uint8_t oplock, uint64_t leasekey,
857 io->in.security_flags = 0x00;
858 io->in.oplock_level = oplock;
859 io->in.impersonation_level = NTCREATEX_IMPERSONATION_IMPERSONATION;
860 io->in.create_flags = 0x00000000;
861 io->in.reserved = 0x00000000;
862 io->in.desired_access = SEC_RIGHTS_FILE_ALL;
863 io->in.file_attributes = FILE_ATTRIBUTE_NORMAL;
864 io->in.share_access = share_access;
865 io->in.create_disposition = disposition;
866 io->in.create_options = NTCREATEX_OPTIONS_SEQUENTIAL_ONLY |
867 NTCREATEX_OPTIONS_ASYNC_ALERT |
868 NTCREATEX_OPTIONS_NON_DIRECTORY_FILE |
873 io->in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
874 io->in.file_attributes = FILE_ATTRIBUTE_DIRECTORY;
875 io->in.create_disposition = NTCREATEX_DISP_CREATE;
880 ls->lease_key.data[0] = leasekey;
881 ls->lease_key.data[1] = ~leasekey;
882 ls->lease_state = leasestate;
883 io->in.lease_request = ls;
887 void smb2_generic_create(struct smb2_create *io, struct smb2_lease *ls,
888 bool dir, const char *name, uint32_t disposition,
889 uint8_t oplock, uint64_t leasekey,
892 smb2_generic_create_share(io, ls, dir, name, disposition,
893 smb2_util_share_access("RWD"),
895 leasekey, leasestate);
898 void smb2_lease_create_share(struct smb2_create *io, struct smb2_lease *ls,
899 bool dir, const char *name, uint32_t share_access,
900 uint64_t leasekey, uint32_t leasestate)
902 smb2_generic_create_share(io, ls, dir, name, NTCREATEX_DISP_OPEN_IF,
903 share_access, SMB2_OPLOCK_LEVEL_LEASE,
904 leasekey, leasestate);
907 void smb2_lease_create(struct smb2_create *io, struct smb2_lease *ls,
908 bool dir, const char *name, uint64_t leasekey,
911 smb2_lease_create_share(io, ls, dir, name,
912 smb2_util_share_access("RWD"),
913 leasekey, leasestate);
916 void smb2_lease_v2_create_share(struct smb2_create *io,
917 struct smb2_lease *ls,
920 uint32_t share_access,
922 const uint64_t *parentleasekey,
924 uint16_t lease_epoch)
926 smb2_generic_create_share(io, NULL, dir, name, NTCREATEX_DISP_OPEN_IF,
927 share_access, SMB2_OPLOCK_LEVEL_LEASE, 0, 0);
931 ls->lease_key.data[0] = leasekey;
932 ls->lease_key.data[1] = ~leasekey;
933 ls->lease_state = leasestate;
934 if (parentleasekey != NULL) {
935 ls->lease_flags |= SMB2_LEASE_FLAG_PARENT_LEASE_KEY_SET;
936 ls->parent_lease_key.data[0] = *parentleasekey;
937 ls->parent_lease_key.data[1] = ~(*parentleasekey);
939 ls->lease_epoch = lease_epoch;
940 io->in.lease_request_v2 = ls;
944 void smb2_lease_v2_create(struct smb2_create *io,
945 struct smb2_lease *ls,
949 const uint64_t *parentleasekey,
951 uint16_t lease_epoch)
953 smb2_lease_v2_create_share(io, ls, dir, name,
954 smb2_util_share_access("RWD"),
955 leasekey, parentleasekey,
956 leasestate, lease_epoch);
960 void smb2_oplock_create_share(struct smb2_create *io, const char *name,
961 uint32_t share_access, uint8_t oplock)
963 smb2_generic_create_share(io, NULL, false, name, NTCREATEX_DISP_OPEN_IF,
964 share_access, oplock, 0, 0);
966 void smb2_oplock_create(struct smb2_create *io, const char *name, uint8_t oplock)
968 smb2_oplock_create_share(io, name, smb2_util_share_access("RWD"),