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 2 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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "libcli/raw/libcliraw.h"
25 #include "libcli/smb2/smb2.h"
26 #include "libcli/smb2/smb2_calls.h"
27 #include "lib/cmdline/popt_common.h"
28 #include "lib/events/events.h"
31 show lots of information about a file
33 void torture_smb2_all_info(struct smb2_tree *tree, struct smb2_handle handle)
36 TALLOC_CTX *tmp_ctx = talloc_new(tree);
37 union smb2_fileinfo io;
39 status = smb2_getinfo_level(tree, tmp_ctx, handle, SMB2_GETINFO_FILE_ALL_INFO, &io);
40 if (!NT_STATUS_IS_OK(status)) {
41 DEBUG(0,("getinfo failed - %s\n", nt_errstr(status)));
46 d_printf("\tcreate_time: %s\n", nt_time_string(tmp_ctx, io.all_info.create_time));
47 d_printf("\taccess_time: %s\n", nt_time_string(tmp_ctx, io.all_info.access_time));
48 d_printf("\twrite_time: %s\n", nt_time_string(tmp_ctx, io.all_info.write_time));
49 d_printf("\tchange_time: %s\n", nt_time_string(tmp_ctx, io.all_info.change_time));
50 d_printf("\tattrib: 0x%x\n", io.all_info.file_attr);
51 d_printf("\talloc_size: %llu\n", (uint64_t)io.all_info.alloc_size);
52 d_printf("\tsize: %llu\n", (uint64_t)io.all_info.size);
53 d_printf("\tnlink: %u\n", io.all_info.nlink);
54 d_printf("\tdelete_pending: %u\n", io.all_info.delete_pending);
55 d_printf("\tdirectory: %u\n", io.all_info.directory);
56 d_printf("\tfile_id: %llu\n", io.all_info.file_id);
57 d_printf("\tea_size: %u\n", io.all_info.ea_size);
58 d_printf("\taccess_mask: 0x%08x\n", io.all_info.access_mask);
59 d_printf("\tunknown5: 0x%llx\n", io.all_info.unknown5);
60 d_printf("\tunknown6: 0x%llx\n", io.all_info.unknown6);
61 d_printf("\tfname: '%s'\n", io.all_info.fname);
68 open a smb2 connection
70 BOOL torture_smb2_connection(TALLOC_CTX *mem_ctx, struct smb2_tree **tree)
73 const char *host = lp_parm_string(-1, "torture", "host");
74 const char *share = lp_parm_string(-1, "torture", "share");
75 struct cli_credentials *credentials = cmdline_credentials;
77 status = smb2_connect(mem_ctx, host, share, credentials, tree,
78 event_context_find(mem_ctx));
79 if (!NT_STATUS_IS_OK(status)) {
80 printf("Failed to connect to SMB2 share \\\\%s\\%s - %s\n",
81 host, share, nt_errstr(status));
89 create and return a handle to a test file
91 NTSTATUS torture_smb2_testfile(struct smb2_tree *tree, const char *fname,
92 struct smb2_handle *handle)
94 struct smb2_create io;
99 io.in.buffer_code = 0x39;
100 io.in.oplock_flags = 0;
101 io.in.access_mask = SEC_RIGHTS_FILE_ALL;
102 io.in.file_attr = FILE_ATTRIBUTE_NORMAL;
103 io.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
105 NTCREATEX_SHARE_ACCESS_DELETE|
106 NTCREATEX_SHARE_ACCESS_READ|
107 NTCREATEX_SHARE_ACCESS_WRITE;
108 io.in.create_options = NTCREATEX_OPTIONS_DELETE_ON_CLOSE;
111 status = smb2_create(tree, &io);
112 NT_STATUS_NOT_OK_RETURN(status);
114 *handle = io.out.handle;
117 r.in.buffer_code = 0x31;
120 r.in.handle = *handle;
122 smb2_read(tree, tree, &r);
128 create and return a handle to a test directory
130 NTSTATUS torture_smb2_testdir(struct smb2_tree *tree, const char *fname,
131 struct smb2_handle *handle)
133 struct smb2_create io;
137 io.in.buffer_code = 0x39;
138 io.in.oplock_flags = 0;
139 io.in.access_mask = SEC_RIGHTS_DIR_ALL;
140 io.in.file_attr = FILE_ATTRIBUTE_DIRECTORY;
141 io.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
142 io.in.share_access = NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE;
143 io.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
146 status = smb2_create(tree, &io);
147 NT_STATUS_NOT_OK_RETURN(status);
149 *handle = io.out.handle;
156 create a complex file using the old SMB protocol, to make it easier to
157 find fields in SMB2 getinfo levels
159 BOOL torture_setup_complex_file(const char *fname)
161 struct smbcli_state *cli;
164 if (!torture_open_connection(&cli)) {
168 fnum = create_complex_file(cli, cli, fname);
171 torture_all_info(cli->tree, fname);
179 create a complex directory using the old SMB protocol, to make it easier to
180 find fields in SMB2 getinfo levels
182 BOOL torture_setup_complex_dir(const char *dname)
184 struct smbcli_state *cli;
187 if (!torture_open_connection(&cli)) {
191 fnum = create_complex_dir(cli, cli, dname);
194 torture_all_info(cli->tree, dname);