Line data Source code
1 : /*
2 : Unix SMB/CIFS implementation.
3 :
4 : SMB2 setinfo individual test suite
5 :
6 : Copyright (C) Ralph Boehme 2016
7 :
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.
12 :
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.
17 :
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/>.
20 : */
21 :
22 : #include "includes.h"
23 : #include "system/time.h"
24 : #include "libcli/smb2/smb2.h"
25 : #include "libcli/smb2/smb2_calls.h"
26 :
27 : #include "torture/torture.h"
28 : #include "torture/smb2/proto.h"
29 :
30 : /*
31 : test dosmode and hidden files
32 : */
33 0 : bool torture_smb2_dosmode(struct torture_context *tctx)
34 : {
35 0 : bool ret = true;
36 : NTSTATUS status;
37 0 : struct smb2_tree *tree = NULL;
38 0 : const char *dname = "torture_dosmode";
39 0 : const char *fname = "torture_dosmode\\file";
40 0 : const char *hidefile = "torture_dosmode\\hidefile";
41 0 : const char *dotfile = "torture_dosmode\\.dotfile";
42 0 : struct smb2_handle h1 = {{0}};
43 : struct smb2_create io;
44 : union smb_setfileinfo sfinfo;
45 : union smb_fileinfo finfo2;
46 :
47 0 : torture_comment(tctx, "Checking dosmode with \"hide files\" "
48 : "and \"hide dot files\"\n");
49 :
50 0 : if (!torture_smb2_connection(tctx, &tree)) {
51 0 : return false;
52 : }
53 :
54 0 : smb2_deltree(tree, dname);
55 :
56 0 : status = torture_smb2_testdir(tree, dname, &h1);
57 0 : torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
58 : "torture_smb2_testdir failed");
59 :
60 0 : ZERO_STRUCT(io);
61 0 : io.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED;
62 0 : io.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
63 0 : io.in.create_disposition = NTCREATEX_DISP_CREATE;
64 0 : io.in.create_options = 0;
65 0 : io.in.fname = fname;
66 :
67 0 : status = smb2_create(tree, tctx, &io);
68 0 : torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
69 : "smb2_create failed");
70 :
71 0 : ZERO_STRUCT(sfinfo);
72 0 : sfinfo.basic_info.in.attrib = FILE_ATTRIBUTE_HIDDEN;
73 0 : sfinfo.generic.level = RAW_SFILEINFO_BASIC_INFORMATION;
74 0 : sfinfo.generic.in.file.handle = io.out.file.handle;
75 0 : status = smb2_setinfo_file(tree, &sfinfo);
76 0 : torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
77 : "smb2_setinfo_filefailed");
78 :
79 0 : ZERO_STRUCT(finfo2);
80 0 : finfo2.generic.level = RAW_FILEINFO_BASIC_INFORMATION;
81 0 : finfo2.generic.in.file.handle = io.out.file.handle;
82 0 : status = smb2_getinfo_file(tree, tctx, &finfo2);
83 0 : torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
84 : "smb2_getinfo_file failed");
85 0 : torture_assert_int_equal_goto(tctx, finfo2.all_info2.out.attrib & FILE_ATTRIBUTE_HIDDEN,
86 : FILE_ATTRIBUTE_HIDDEN, ret, done,
87 : "FILE_ATTRIBUTE_HIDDEN is not set");
88 :
89 0 : smb2_util_close(tree, io.out.file.handle);
90 :
91 : /* This must fail with attribute mismatch */
92 0 : ZERO_STRUCT(io);
93 0 : io.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED;
94 0 : io.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
95 0 : io.in.create_disposition = NTCREATEX_DISP_OVERWRITE_IF;
96 0 : io.in.create_options = 0;
97 0 : io.in.fname = fname;
98 :
99 0 : status = smb2_create(tree, tctx, &io);
100 0 : torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_ACCESS_DENIED,
101 : ret, done,"smb2_create failed");
102 :
103 : /* Create a file in "hide files" */
104 0 : ZERO_STRUCT(io);
105 0 : io.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED;
106 0 : io.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
107 0 : io.in.create_disposition = NTCREATEX_DISP_CREATE;
108 0 : io.in.create_options = 0;
109 0 : io.in.fname = hidefile;
110 :
111 0 : status = smb2_create(tree, tctx, &io);
112 0 : torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
113 : "smb2_create failed");
114 :
115 0 : ZERO_STRUCT(finfo2);
116 0 : finfo2.generic.level = RAW_FILEINFO_BASIC_INFORMATION;
117 0 : finfo2.generic.in.file.handle = io.out.file.handle;
118 0 : status = smb2_getinfo_file(tree, tctx, &finfo2);
119 0 : torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
120 : "smb2_getinfo_file failed");
121 0 : torture_assert_int_equal_goto(tctx, finfo2.all_info2.out.attrib & FILE_ATTRIBUTE_HIDDEN,
122 : FILE_ATTRIBUTE_HIDDEN, ret, done,
123 : "FILE_ATTRIBUTE_HIDDEN is not set");
124 :
125 0 : smb2_util_close(tree, io.out.file.handle);
126 :
127 : /* Overwrite a file in "hide files", should pass */
128 0 : ZERO_STRUCT(io);
129 0 : io.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED;
130 0 : io.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
131 0 : io.in.create_disposition = NTCREATEX_DISP_OVERWRITE_IF;
132 0 : io.in.create_options = 0;
133 0 : io.in.fname = hidefile;
134 :
135 0 : status = smb2_create(tree, tctx, &io);
136 0 : torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
137 : "smb2_create failed");
138 0 : smb2_util_close(tree, io.out.file.handle);
139 :
140 : /* Create a "hide dot files" */
141 0 : ZERO_STRUCT(io);
142 0 : io.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED;
143 0 : io.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
144 0 : io.in.create_disposition = NTCREATEX_DISP_CREATE;
145 0 : io.in.create_options = 0;
146 0 : io.in.fname = dotfile;
147 :
148 0 : status = smb2_create(tree, tctx, &io);
149 0 : torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
150 : "smb2_create failed");
151 :
152 0 : ZERO_STRUCT(finfo2);
153 0 : finfo2.generic.level = RAW_FILEINFO_BASIC_INFORMATION;
154 0 : finfo2.generic.in.file.handle = io.out.file.handle;
155 0 : status = smb2_getinfo_file(tree, tctx, &finfo2);
156 0 : torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
157 : "smb2_getinfo_file failed");
158 0 : torture_assert_int_equal_goto(tctx, finfo2.all_info2.out.attrib & FILE_ATTRIBUTE_HIDDEN,
159 : FILE_ATTRIBUTE_HIDDEN, ret, done,
160 : "FILE_ATTRIBUTE_HIDDEN is not set");
161 :
162 0 : smb2_util_close(tree, io.out.file.handle);
163 :
164 : /* Overwrite a "hide dot files", should pass */
165 0 : ZERO_STRUCT(io);
166 0 : io.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED;
167 0 : io.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
168 0 : io.in.create_disposition = NTCREATEX_DISP_OVERWRITE_IF;
169 0 : io.in.create_options = 0;
170 0 : io.in.fname = dotfile;
171 :
172 0 : status = smb2_create(tree, tctx, &io);
173 0 : torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
174 : "smb2_create failed");
175 0 : smb2_util_close(tree, io.out.file.handle);
176 :
177 0 : done:
178 0 : if (!smb2_util_handle_empty(h1)) {
179 0 : smb2_util_close(tree, h1);
180 : }
181 0 : smb2_deltree(tree, dname);
182 0 : return ret;
183 : }
184 :
185 0 : bool torture_smb2_async_dosmode(struct torture_context *tctx)
186 : {
187 0 : bool ret = true;
188 : NTSTATUS status;
189 0 : struct smb2_tree *tree = NULL;
190 0 : const char *dname = "torture_dosmode";
191 0 : const char *fname = "torture_dosmode\\file";
192 0 : struct smb2_handle h = {{0}};
193 : struct smb2_create io;
194 : union smb_setfileinfo sfinfo;
195 : struct smb2_find f;
196 : union smb_search_data *d;
197 : unsigned int count;
198 :
199 0 : if (!torture_smb2_connection(tctx, &tree)) {
200 0 : return false;
201 : }
202 :
203 0 : smb2_deltree(tree, dname);
204 :
205 0 : status = torture_smb2_testdir(tree, dname, &h);
206 0 : torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
207 : "torture_smb2_testdir failed");
208 :
209 0 : ZERO_STRUCT(io);
210 0 : io.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED;
211 0 : io.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
212 0 : io.in.create_disposition = NTCREATEX_DISP_CREATE;
213 0 : io.in.create_options = 0;
214 0 : io.in.fname = fname;
215 :
216 0 : status = smb2_create(tree, tctx, &io);
217 0 : torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
218 : "smb2_create failed");
219 :
220 0 : ZERO_STRUCT(sfinfo);
221 0 : sfinfo.basic_info.in.attrib = FILE_ATTRIBUTE_HIDDEN;
222 0 : sfinfo.generic.level = RAW_SFILEINFO_BASIC_INFORMATION;
223 0 : sfinfo.generic.in.file.handle = io.out.file.handle;
224 0 : status = smb2_setinfo_file(tree, &sfinfo);
225 0 : torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
226 : "smb2_setinfo_filefailed");
227 :
228 0 : smb2_util_close(tree, io.out.file.handle);
229 :
230 0 : ZERO_STRUCT(f);
231 0 : f.in.file.handle = h;
232 0 : f.in.pattern = "file";
233 0 : f.in.continue_flags = SMB2_CONTINUE_FLAG_RESTART;
234 0 : f.in.max_response_size = 0x1000;
235 0 : f.in.level = SMB2_FIND_BOTH_DIRECTORY_INFO;
236 :
237 0 : status = smb2_find_level(tree, tree, &f, &count, &d);
238 0 : torture_assert_ntstatus_ok_goto(tctx, status, ret, done, "");
239 :
240 0 : smb2_util_close(tree, h);
241 0 : ZERO_STRUCT(h);
242 :
243 0 : torture_assert_goto(tctx,
244 : d->both_directory_info.attrib & FILE_ATTRIBUTE_HIDDEN,
245 : ret, done,
246 : "FILE_ATTRIBUTE_HIDDEN is not set\n");
247 :
248 0 : done:
249 0 : if (!smb2_util_handle_empty(h)) {
250 0 : smb2_util_close(tree, h);
251 : }
252 0 : smb2_deltree(tree, dname);
253 0 : return ret;
254 : }
|