Line data Source code
1 : /*
2 : Unix SMB/CIFS implementation.
3 : client trans2 operations
4 : Copyright (C) James Myers 2003
5 : Copyright (C) Andrew Tridgell 2003
6 : Copyright (C) James Peach 2007
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 "libcli/raw/libcliraw.h"
24 : #include "libcli/raw/raw_proto.h"
25 : #include "librpc/gen_ndr/ndr_security.h"
26 :
27 : /* local macros to make the code more readable */
28 : #define FINFO_CHECK_MIN_SIZE(size) if (blob->length < (size)) { \
29 : DEBUG(1,("Unexpected FILEINFO reply size %d for level %u - expected min of %d\n", \
30 : (int)blob->length, parms->generic.level, (size))); \
31 : return NT_STATUS_INFO_LENGTH_MISMATCH; \
32 : }
33 : #define FINFO_CHECK_SIZE(size) if (blob->length != (size)) { \
34 : DEBUG(1,("Unexpected FILEINFO reply size %d for level %u - expected %d\n", \
35 : (int)blob->length, parms->generic.level, (size))); \
36 : return NT_STATUS_INFO_LENGTH_MISMATCH; \
37 : }
38 :
39 : /*
40 : parse a stream information structure
41 : */
42 1998 : NTSTATUS smbcli_parse_stream_info(DATA_BLOB blob, TALLOC_CTX *mem_ctx,
43 : struct stream_information *io)
44 : {
45 1998 : uint32_t ofs = 0;
46 1998 : io->num_streams = 0;
47 1998 : io->streams = NULL;
48 :
49 2844 : while (blob.length - ofs >= 24) {
50 2830 : unsigned int n = io->num_streams;
51 0 : uint32_t nlen, len;
52 0 : bool ret;
53 0 : void *vstr;
54 2830 : size_t converted_size = 0;
55 :
56 2830 : io->streams =
57 2830 : talloc_realloc(mem_ctx, io->streams, struct stream_struct, n+1);
58 2830 : if (!io->streams) {
59 0 : return NT_STATUS_NO_MEMORY;
60 : }
61 2830 : nlen = IVAL(blob.data, ofs + 0x04);
62 2830 : io->streams[n].size = BVAL(blob.data, ofs + 0x08);
63 2830 : io->streams[n].alloc_size = BVAL(blob.data, ofs + 0x10);
64 2830 : if (nlen > blob.length - (ofs + 24)) {
65 0 : return NT_STATUS_INFO_LENGTH_MISMATCH;
66 : }
67 2830 : ret = convert_string_talloc(io->streams,
68 : CH_UTF16, CH_UNIX,
69 2830 : blob.data+ofs+24, nlen, &vstr, &converted_size);
70 2830 : if (!ret) {
71 0 : return NT_STATUS_ILLEGAL_CHARACTER;
72 : }
73 2830 : io->streams[n].stream_name.s = (const char *)vstr;
74 2830 : io->streams[n].stream_name.private_length = nlen;
75 2830 : io->num_streams++;
76 2830 : len = IVAL(blob.data, ofs);
77 2830 : if (len > blob.length - ofs) {
78 0 : return NT_STATUS_INFO_LENGTH_MISMATCH;
79 : }
80 2830 : if (len == 0) break;
81 846 : ofs += len;
82 : }
83 :
84 1998 : return NT_STATUS_OK;
85 : }
86 :
87 : /*
88 : parse the fsinfo 'passthru' level replies
89 : */
90 16802 : NTSTATUS smb_raw_fileinfo_passthru_parse(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx,
91 : enum smb_fileinfo_level level,
92 : union smb_fileinfo *parms)
93 : {
94 16802 : switch (level) {
95 2371 : case RAW_FILEINFO_BASIC_INFORMATION:
96 : /* some servers return 40 bytes and some 36. w2k3 return 40, so that's
97 : what we should do, but we need to accept 36 */
98 2371 : if (blob->length != 36) {
99 688 : FINFO_CHECK_SIZE(40);
100 : }
101 2371 : parms->basic_info.out.create_time = smbcli_pull_nttime(blob->data, 0);
102 2371 : parms->basic_info.out.access_time = smbcli_pull_nttime(blob->data, 8);
103 2371 : parms->basic_info.out.write_time = smbcli_pull_nttime(blob->data, 16);
104 2371 : parms->basic_info.out.change_time = smbcli_pull_nttime(blob->data, 24);
105 2371 : parms->basic_info.out.attrib = IVAL(blob->data, 32);
106 2371 : return NT_STATUS_OK;
107 :
108 820 : case RAW_FILEINFO_STANDARD_INFORMATION:
109 820 : FINFO_CHECK_SIZE(24);
110 820 : parms->standard_info.out.alloc_size = BVAL(blob->data, 0);
111 820 : parms->standard_info.out.size = BVAL(blob->data, 8);
112 820 : parms->standard_info.out.nlink = IVAL(blob->data, 16);
113 820 : parms->standard_info.out.delete_pending = CVAL(blob->data, 20);
114 820 : parms->standard_info.out.directory = CVAL(blob->data, 21);
115 820 : return NT_STATUS_OK;
116 :
117 18 : case RAW_FILEINFO_EA_INFORMATION:
118 18 : FINFO_CHECK_SIZE(4);
119 18 : parms->ea_info.out.ea_size = IVAL(blob->data, 0);
120 18 : return NT_STATUS_OK;
121 :
122 194 : case RAW_FILEINFO_NAME_INFORMATION:
123 194 : FINFO_CHECK_MIN_SIZE(4);
124 194 : smbcli_blob_pull_string(NULL, mem_ctx, blob,
125 : &parms->name_info.out.fname, 0, 4, STR_UNICODE);
126 194 : return NT_STATUS_OK;
127 :
128 2231 : case RAW_FILEINFO_ALL_INFORMATION:
129 2231 : FINFO_CHECK_MIN_SIZE(72);
130 2231 : parms->all_info.out.create_time = smbcli_pull_nttime(blob->data, 0);
131 2231 : parms->all_info.out.access_time = smbcli_pull_nttime(blob->data, 8);
132 2231 : parms->all_info.out.write_time = smbcli_pull_nttime(blob->data, 16);
133 2231 : parms->all_info.out.change_time = smbcli_pull_nttime(blob->data, 24);
134 2231 : parms->all_info.out.attrib = IVAL(blob->data, 32);
135 2231 : parms->all_info.out.alloc_size = BVAL(blob->data, 40);
136 2231 : parms->all_info.out.size = BVAL(blob->data, 48);
137 2231 : parms->all_info.out.nlink = IVAL(blob->data, 56);
138 2231 : parms->all_info.out.delete_pending = CVAL(blob->data, 60);
139 2231 : parms->all_info.out.directory = CVAL(blob->data, 61);
140 : #if 1
141 2231 : parms->all_info.out.ea_size = IVAL(blob->data, 64);
142 2231 : smbcli_blob_pull_string(NULL, mem_ctx, blob,
143 : &parms->all_info.out.fname, 68, 72, STR_UNICODE);
144 : #else
145 : /* this is what the CIFS spec says - and its totally
146 : wrong, but its useful having it here so we can
147 : quickly adapt to broken servers when running
148 : tests */
149 : parms->all_info.out.ea_size = IVAL(blob->data, 72);
150 : /* access flags 4 bytes at 76
151 : current_position 8 bytes at 80
152 : mode 4 bytes at 88
153 : alignment 4 bytes at 92
154 : */
155 : smbcli_blob_pull_string(NULL, mem_ctx, blob,
156 : &parms->all_info.out.fname, 96, 100, STR_UNICODE);
157 : #endif
158 2231 : return NT_STATUS_OK;
159 :
160 164 : case RAW_FILEINFO_ALT_NAME_INFORMATION:
161 : case RAW_FILEINFO_SMB2_ALT_NAME_INFORMATION:
162 164 : FINFO_CHECK_MIN_SIZE(4);
163 164 : smbcli_blob_pull_string(NULL, mem_ctx, blob,
164 : &parms->alt_name_info.out.fname, 0, 4, STR_UNICODE);
165 164 : return NT_STATUS_OK;
166 :
167 1998 : case RAW_FILEINFO_STREAM_INFORMATION:
168 1998 : return smbcli_parse_stream_info(*blob, mem_ctx, &parms->stream_info.out);
169 :
170 24 : case RAW_FILEINFO_INTERNAL_INFORMATION:
171 24 : FINFO_CHECK_SIZE(8);
172 24 : parms->internal_information.out.file_id = BVAL(blob->data, 0);
173 24 : return NT_STATUS_OK;
174 :
175 1108 : case RAW_FILEINFO_ACCESS_INFORMATION:
176 1108 : FINFO_CHECK_SIZE(4);
177 1108 : parms->access_information.out.access_flags = IVAL(blob->data, 0);
178 1108 : return NT_STATUS_OK;
179 :
180 2116 : case RAW_FILEINFO_POSITION_INFORMATION:
181 2116 : FINFO_CHECK_SIZE(8);
182 2116 : parms->position_information.out.position = BVAL(blob->data, 0);
183 2116 : return NT_STATUS_OK;
184 :
185 19 : case RAW_FILEINFO_MODE_INFORMATION:
186 19 : FINFO_CHECK_SIZE(4);
187 19 : parms->mode_information.out.mode = IVAL(blob->data, 0);
188 19 : return NT_STATUS_OK;
189 :
190 13 : case RAW_FILEINFO_ALIGNMENT_INFORMATION:
191 13 : FINFO_CHECK_SIZE(4);
192 0 : parms->alignment_information.out.alignment_requirement
193 13 : = IVAL(blob->data, 0);
194 13 : return NT_STATUS_OK;
195 :
196 20 : case RAW_FILEINFO_COMPRESSION_INFORMATION:
197 20 : FINFO_CHECK_SIZE(16);
198 20 : parms->compression_info.out.compressed_size = BVAL(blob->data, 0);
199 20 : parms->compression_info.out.format = SVAL(blob->data, 8);
200 20 : parms->compression_info.out.unit_shift = CVAL(blob->data, 10);
201 20 : parms->compression_info.out.chunk_shift = CVAL(blob->data, 11);
202 20 : parms->compression_info.out.cluster_shift = CVAL(blob->data, 12);
203 : /* 3 bytes of padding */
204 20 : return NT_STATUS_OK;
205 :
206 8 : case RAW_FILEINFO_NETWORK_OPEN_INFORMATION:
207 8 : FINFO_CHECK_SIZE(56);
208 8 : parms->network_open_information.out.create_time = smbcli_pull_nttime(blob->data, 0);
209 8 : parms->network_open_information.out.access_time = smbcli_pull_nttime(blob->data, 8);
210 8 : parms->network_open_information.out.write_time = smbcli_pull_nttime(blob->data, 16);
211 8 : parms->network_open_information.out.change_time = smbcli_pull_nttime(blob->data, 24);
212 8 : parms->network_open_information.out.alloc_size = BVAL(blob->data, 32);
213 8 : parms->network_open_information.out.size = BVAL(blob->data, 40);
214 8 : parms->network_open_information.out.attrib = IVAL(blob->data, 48);
215 8 : return NT_STATUS_OK;
216 :
217 8 : case RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION:
218 8 : FINFO_CHECK_SIZE(8);
219 8 : parms->attribute_tag_information.out.attrib = IVAL(blob->data, 0);
220 8 : parms->attribute_tag_information.out.reparse_tag = IVAL(blob->data, 4);
221 8 : return NT_STATUS_OK;
222 :
223 96 : case RAW_FILEINFO_NORMALIZED_NAME_INFORMATION:
224 96 : FINFO_CHECK_MIN_SIZE(4);
225 96 : smbcli_blob_pull_string(NULL, mem_ctx, blob,
226 : &parms->normalized_name_info.out.fname,
227 : 0, 4, STR_UNICODE);
228 96 : return NT_STATUS_OK;
229 :
230 14 : case RAW_FILEINFO_SMB2_ALL_EAS:
231 14 : FINFO_CHECK_MIN_SIZE(4);
232 14 : return ea_pull_list_chained(blob, mem_ctx,
233 : &parms->all_eas.out.num_eas,
234 : &parms->all_eas.out.eas);
235 :
236 1529 : case RAW_FILEINFO_SMB2_ALL_INFORMATION:
237 1529 : FINFO_CHECK_MIN_SIZE(0x64);
238 1529 : parms->all_info2.out.create_time = smbcli_pull_nttime(blob->data, 0x00);
239 1529 : parms->all_info2.out.access_time = smbcli_pull_nttime(blob->data, 0x08);
240 1529 : parms->all_info2.out.write_time = smbcli_pull_nttime(blob->data, 0x10);
241 1529 : parms->all_info2.out.change_time = smbcli_pull_nttime(blob->data, 0x18);
242 1529 : parms->all_info2.out.attrib = IVAL(blob->data, 0x20);
243 1529 : parms->all_info2.out.unknown1 = IVAL(blob->data, 0x24);
244 1529 : parms->all_info2.out.alloc_size = BVAL(blob->data, 0x28);
245 1529 : parms->all_info2.out.size = BVAL(blob->data, 0x30);
246 1529 : parms->all_info2.out.nlink = IVAL(blob->data, 0x38);
247 1529 : parms->all_info2.out.delete_pending = CVAL(blob->data, 0x3C);
248 1529 : parms->all_info2.out.directory = CVAL(blob->data, 0x3D);
249 : /* 0x3E-0x3F padding */
250 1529 : parms->all_info2.out.file_id = BVAL(blob->data, 0x40);
251 1529 : parms->all_info2.out.ea_size = IVAL(blob->data, 0x48);
252 1529 : parms->all_info2.out.access_mask = IVAL(blob->data, 0x4C);
253 1529 : parms->all_info2.out.position = BVAL(blob->data, 0x50);
254 1529 : parms->all_info2.out.mode = IVAL(blob->data, 0x58);
255 1529 : parms->all_info2.out.alignment_requirement = IVAL(blob->data, 0x5C);
256 1529 : smbcli_blob_pull_string(NULL, mem_ctx, blob,
257 : &parms->all_info2.out.fname, 0x60, 0x64, STR_UNICODE);
258 1529 : return NT_STATUS_OK;
259 :
260 4051 : case RAW_FILEINFO_SEC_DESC: {
261 12 : enum ndr_err_code ndr_err;
262 :
263 4051 : parms->query_secdesc.out.sd = talloc(mem_ctx, struct security_descriptor);
264 4051 : NT_STATUS_HAVE_NO_MEMORY(parms->query_secdesc.out.sd);
265 :
266 4051 : ndr_err = ndr_pull_struct_blob(blob, mem_ctx,
267 4039 : parms->query_secdesc.out.sd,
268 : (ndr_pull_flags_fn_t)ndr_pull_security_descriptor);
269 4051 : if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
270 0 : return ndr_map_error2ntstatus(ndr_err);
271 : }
272 :
273 4051 : return NT_STATUS_OK;
274 : }
275 :
276 0 : default:
277 0 : break;
278 : }
279 :
280 0 : return NT_STATUS_INVALID_LEVEL;
281 : }
282 :
283 :
284 : /****************************************************************************
285 : Handle qfileinfo/qpathinfo trans2 backend.
286 : ****************************************************************************/
287 6824 : static NTSTATUS smb_raw_info_backend(struct smbcli_session *session,
288 : TALLOC_CTX *mem_ctx,
289 : union smb_fileinfo *parms,
290 : DATA_BLOB *blob)
291 : {
292 6824 : switch (parms->generic.level) {
293 0 : case RAW_FILEINFO_GENERIC:
294 : case RAW_FILEINFO_GETATTR:
295 : case RAW_FILEINFO_GETATTRE:
296 : case RAW_FILEINFO_SEC_DESC:
297 : /* not handled here */
298 0 : return NT_STATUS_INVALID_LEVEL;
299 :
300 607 : case RAW_FILEINFO_STANDARD:
301 607 : if (session == NULL) {
302 0 : return NT_STATUS_INVALID_PARAMETER;
303 : }
304 :
305 607 : FINFO_CHECK_SIZE(22);
306 1214 : parms->standard.out.create_time = raw_pull_dos_date2(session->transport,
307 607 : blob->data + 0);
308 1214 : parms->standard.out.access_time = raw_pull_dos_date2(session->transport,
309 607 : blob->data + 4);
310 1214 : parms->standard.out.write_time = raw_pull_dos_date2(session->transport,
311 607 : blob->data + 8);
312 607 : parms->standard.out.size = IVAL(blob->data, 12);
313 607 : parms->standard.out.alloc_size = IVAL(blob->data, 16);
314 607 : parms->standard.out.attrib = SVAL(blob->data, 20);
315 607 : return NT_STATUS_OK;
316 :
317 5 : case RAW_FILEINFO_EA_SIZE:
318 5 : if (session == NULL) {
319 0 : return NT_STATUS_INVALID_PARAMETER;
320 : }
321 :
322 5 : FINFO_CHECK_SIZE(26);
323 10 : parms->ea_size.out.create_time = raw_pull_dos_date2(session->transport,
324 5 : blob->data + 0);
325 10 : parms->ea_size.out.access_time = raw_pull_dos_date2(session->transport,
326 5 : blob->data + 4);
327 10 : parms->ea_size.out.write_time = raw_pull_dos_date2(session->transport,
328 5 : blob->data + 8);
329 5 : parms->ea_size.out.size = IVAL(blob->data, 12);
330 5 : parms->ea_size.out.alloc_size = IVAL(blob->data, 16);
331 5 : parms->ea_size.out.attrib = SVAL(blob->data, 20);
332 5 : parms->ea_size.out.ea_size = IVAL(blob->data, 22);
333 5 : return NT_STATUS_OK;
334 :
335 146 : case RAW_FILEINFO_EA_LIST:
336 146 : FINFO_CHECK_MIN_SIZE(4);
337 146 : return ea_pull_list(blob, mem_ctx,
338 : &parms->ea_list.out.num_eas,
339 : &parms->ea_list.out.eas);
340 :
341 8 : case RAW_FILEINFO_ALL_EAS:
342 8 : FINFO_CHECK_MIN_SIZE(4);
343 8 : return ea_pull_list(blob, mem_ctx,
344 : &parms->all_eas.out.num_eas,
345 : &parms->all_eas.out.eas);
346 :
347 5 : case RAW_FILEINFO_IS_NAME_VALID:
348 : /* no data! */
349 5 : FINFO_CHECK_SIZE(0);
350 5 : return NT_STATUS_OK;
351 :
352 1981 : case RAW_FILEINFO_BASIC_INFO:
353 : case RAW_FILEINFO_BASIC_INFORMATION:
354 1981 : return smb_raw_fileinfo_passthru_parse(blob, mem_ctx,
355 : RAW_FILEINFO_BASIC_INFORMATION, parms);
356 :
357 612 : case RAW_FILEINFO_STANDARD_INFO:
358 : case RAW_FILEINFO_STANDARD_INFORMATION:
359 612 : return smb_raw_fileinfo_passthru_parse(blob, mem_ctx,
360 : RAW_FILEINFO_STANDARD_INFORMATION, parms);
361 :
362 10 : case RAW_FILEINFO_EA_INFO:
363 : case RAW_FILEINFO_EA_INFORMATION:
364 10 : return smb_raw_fileinfo_passthru_parse(blob, mem_ctx,
365 : RAW_FILEINFO_EA_INFORMATION, parms);
366 :
367 194 : case RAW_FILEINFO_NAME_INFO:
368 : case RAW_FILEINFO_NAME_INFORMATION:
369 194 : return smb_raw_fileinfo_passthru_parse(blob, mem_ctx,
370 : RAW_FILEINFO_NAME_INFORMATION, parms);
371 :
372 2118 : case RAW_FILEINFO_ALL_INFO:
373 : case RAW_FILEINFO_ALL_INFORMATION:
374 2118 : return smb_raw_fileinfo_passthru_parse(blob, mem_ctx,
375 : RAW_FILEINFO_ALL_INFORMATION, parms);
376 :
377 91 : case RAW_FILEINFO_ALT_NAME_INFO:
378 : case RAW_FILEINFO_ALT_NAME_INFORMATION:
379 91 : return smb_raw_fileinfo_passthru_parse(blob, mem_ctx,
380 : RAW_FILEINFO_ALT_NAME_INFORMATION, parms);
381 :
382 106 : case RAW_FILEINFO_STREAM_INFO:
383 : case RAW_FILEINFO_STREAM_INFORMATION:
384 106 : return smb_raw_fileinfo_passthru_parse(blob, mem_ctx,
385 : RAW_FILEINFO_STREAM_INFORMATION, parms);
386 :
387 16 : case RAW_FILEINFO_INTERNAL_INFORMATION:
388 16 : return smb_raw_fileinfo_passthru_parse(blob, mem_ctx,
389 : RAW_FILEINFO_INTERNAL_INFORMATION, parms);
390 :
391 790 : case RAW_FILEINFO_ACCESS_INFORMATION:
392 790 : return smb_raw_fileinfo_passthru_parse(blob, mem_ctx,
393 : RAW_FILEINFO_ACCESS_INFORMATION, parms);
394 :
395 89 : case RAW_FILEINFO_POSITION_INFORMATION:
396 89 : return smb_raw_fileinfo_passthru_parse(blob, mem_ctx,
397 : RAW_FILEINFO_POSITION_INFORMATION, parms);
398 :
399 9 : case RAW_FILEINFO_MODE_INFORMATION:
400 9 : return smb_raw_fileinfo_passthru_parse(blob, mem_ctx,
401 : RAW_FILEINFO_MODE_INFORMATION, parms);
402 :
403 5 : case RAW_FILEINFO_ALIGNMENT_INFORMATION:
404 5 : return smb_raw_fileinfo_passthru_parse(blob, mem_ctx,
405 : RAW_FILEINFO_ALIGNMENT_INFORMATION, parms);
406 :
407 12 : case RAW_FILEINFO_COMPRESSION_INFO:
408 : case RAW_FILEINFO_COMPRESSION_INFORMATION:
409 12 : return smb_raw_fileinfo_passthru_parse(blob, mem_ctx,
410 : RAW_FILEINFO_COMPRESSION_INFORMATION, parms);
411 :
412 0 : case RAW_FILEINFO_UNIX_BASIC:
413 0 : FINFO_CHECK_SIZE(100);
414 0 : parms->unix_basic_info.out.end_of_file = BVAL(blob->data, 0);
415 0 : parms->unix_basic_info.out.num_bytes = BVAL(blob->data, 8);
416 0 : parms->unix_basic_info.out.status_change_time = smbcli_pull_nttime(blob->data, 16);
417 0 : parms->unix_basic_info.out.access_time = smbcli_pull_nttime(blob->data, 24);
418 0 : parms->unix_basic_info.out.change_time = smbcli_pull_nttime(blob->data, 32);
419 0 : parms->unix_basic_info.out.uid = BVAL(blob->data, 40);
420 0 : parms->unix_basic_info.out.gid = BVAL(blob->data, 48);
421 0 : parms->unix_basic_info.out.file_type = IVAL(blob->data, 52);
422 0 : parms->unix_basic_info.out.dev_major = BVAL(blob->data, 60);
423 0 : parms->unix_basic_info.out.dev_minor = BVAL(blob->data, 68);
424 0 : parms->unix_basic_info.out.unique_id = BVAL(blob->data, 76);
425 0 : parms->unix_basic_info.out.permissions = BVAL(blob->data, 84);
426 0 : parms->unix_basic_info.out.nlink = BVAL(blob->data, 92);
427 0 : return NT_STATUS_OK;
428 :
429 12 : case RAW_FILEINFO_UNIX_INFO2:
430 12 : FINFO_CHECK_SIZE(116);
431 12 : parms->unix_info2.out.end_of_file = BVAL(blob->data, 0);
432 12 : parms->unix_info2.out.num_bytes = BVAL(blob->data, 8);
433 12 : parms->unix_info2.out.status_change_time = smbcli_pull_nttime(blob->data, 16);
434 12 : parms->unix_info2.out.access_time = smbcli_pull_nttime(blob->data, 24);
435 12 : parms->unix_info2.out.change_time = smbcli_pull_nttime(blob->data, 32);
436 12 : parms->unix_info2.out.uid = BVAL(blob->data, 40);
437 12 : parms->unix_info2.out.gid = BVAL(blob->data, 48);
438 12 : parms->unix_info2.out.file_type = IVAL(blob->data, 52);
439 12 : parms->unix_info2.out.dev_major = BVAL(blob->data, 60);
440 12 : parms->unix_info2.out.dev_minor = BVAL(blob->data, 68);
441 12 : parms->unix_info2.out.unique_id = BVAL(blob->data, 76);
442 12 : parms->unix_info2.out.permissions = BVAL(blob->data, 84);
443 12 : parms->unix_info2.out.nlink = BVAL(blob->data, 92);
444 12 : parms->unix_info2.out.create_time = smbcli_pull_nttime(blob->data, 100);
445 12 : parms->unix_info2.out.file_flags = IVAL(blob->data, 108);
446 12 : parms->unix_info2.out.flags_mask = IVAL(blob->data, 112);
447 12 : return NT_STATUS_OK;
448 :
449 0 : case RAW_FILEINFO_UNIX_LINK:
450 0 : smbcli_blob_pull_string(session, mem_ctx, blob,
451 : &parms->unix_link_info.out.link_dest, 0, 4, STR_UNICODE);
452 0 : return NT_STATUS_OK;
453 :
454 4 : case RAW_FILEINFO_NETWORK_OPEN_INFORMATION:
455 4 : return smb_raw_fileinfo_passthru_parse(blob, mem_ctx,
456 : RAW_FILEINFO_NETWORK_OPEN_INFORMATION, parms);
457 :
458 4 : case RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION:
459 4 : return smb_raw_fileinfo_passthru_parse(blob, mem_ctx,
460 : RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION, parms);
461 :
462 0 : case RAW_FILEINFO_NORMALIZED_NAME_INFORMATION:
463 0 : return smb_raw_fileinfo_passthru_parse(blob, mem_ctx,
464 : RAW_FILEINFO_NORMALIZED_NAME_INFORMATION, parms);
465 :
466 0 : case RAW_FILEINFO_SMB2_ALL_INFORMATION:
467 0 : return smb_raw_fileinfo_passthru_parse(blob, mem_ctx,
468 : RAW_FILEINFO_SMB2_ALL_INFORMATION, parms);
469 :
470 0 : case RAW_FILEINFO_SMB2_ALL_EAS:
471 0 : return smb_raw_fileinfo_passthru_parse(blob, mem_ctx,
472 : RAW_FILEINFO_SMB2_ALL_EAS, parms);
473 :
474 0 : case RAW_FILEINFO_SMB2_ALT_NAME_INFORMATION:
475 0 : return smb_raw_fileinfo_passthru_parse(blob, mem_ctx,
476 : RAW_FILEINFO_SMB2_ALT_NAME_INFORMATION, parms);
477 :
478 : }
479 :
480 0 : return NT_STATUS_INVALID_LEVEL;
481 : }
482 :
483 :
484 : /****************************************************************************
485 : Very raw query file info - returns param/data blobs - (async send)
486 : ****************************************************************************/
487 6063 : static struct smbcli_request *smb_raw_fileinfo_blob_send(struct smbcli_tree *tree,
488 : uint16_t fnum,
489 : uint16_t info_level,
490 : DATA_BLOB data)
491 : {
492 185 : struct smb_trans2 tp;
493 6063 : uint16_t setup = TRANSACT2_QFILEINFO;
494 185 : struct smbcli_request *req;
495 6063 : TALLOC_CTX *mem_ctx = talloc_init("raw_fileinfo");
496 :
497 6063 : tp.in.max_setup = 0;
498 6063 : tp.in.flags = 0;
499 6063 : tp.in.timeout = 0;
500 6063 : tp.in.setup_count = 1;
501 6063 : tp.in.data = data;
502 6063 : tp.in.max_param = 2;
503 6063 : tp.in.max_data = 0xFFFF;
504 6063 : tp.in.setup = &setup;
505 :
506 6063 : tp.in.params = data_blob_talloc(mem_ctx, NULL, 4);
507 6063 : if (!tp.in.params.data) {
508 0 : talloc_free(mem_ctx);
509 0 : return NULL;
510 : }
511 :
512 6063 : SSVAL(tp.in.params.data, 0, fnum);
513 6063 : SSVAL(tp.in.params.data, 2, info_level);
514 :
515 6063 : req = smb_raw_trans2_send(tree, &tp);
516 :
517 6063 : talloc_free(mem_ctx);
518 :
519 6063 : return req;
520 : }
521 :
522 :
523 : /****************************************************************************
524 : Very raw query file info - returns param/data blobs - (async recv)
525 : ****************************************************************************/
526 11889 : static NTSTATUS smb_raw_fileinfo_blob_recv(struct smbcli_request *req,
527 : TALLOC_CTX *mem_ctx,
528 : DATA_BLOB *blob)
529 : {
530 474 : struct smb_trans2 tp;
531 11889 : NTSTATUS status = smb_raw_trans2_recv(req, mem_ctx, &tp);
532 11889 : if (NT_STATUS_IS_OK(status)) {
533 6824 : *blob = tp.out.data;
534 : }
535 11889 : return status;
536 : }
537 :
538 : /****************************************************************************
539 : Very raw query path info - returns param/data blobs (async send)
540 : ****************************************************************************/
541 5826 : static struct smbcli_request *smb_raw_pathinfo_blob_send(struct smbcli_tree *tree,
542 : const char *fname,
543 : uint16_t info_level,
544 : DATA_BLOB data)
545 : {
546 289 : struct smb_trans2 tp;
547 5826 : uint16_t setup = TRANSACT2_QPATHINFO;
548 289 : struct smbcli_request *req;
549 5826 : TALLOC_CTX *mem_ctx = talloc_init("raw_pathinfo");
550 :
551 5826 : tp.in.max_setup = 0;
552 5826 : tp.in.flags = 0;
553 5826 : tp.in.timeout = 0;
554 5826 : tp.in.setup_count = 1;
555 5826 : tp.in.data = data;
556 5826 : tp.in.max_param = 2;
557 5826 : tp.in.max_data = 0xFFFF;
558 5826 : tp.in.setup = &setup;
559 :
560 5826 : tp.in.params = data_blob_talloc(mem_ctx, NULL, 6);
561 5826 : if (!tp.in.params.data) {
562 0 : talloc_free(mem_ctx);
563 0 : return NULL;
564 : }
565 :
566 5826 : SSVAL(tp.in.params.data, 0, info_level);
567 5826 : SIVAL(tp.in.params.data, 2, 0);
568 5826 : smbcli_blob_append_string(tree->session, mem_ctx, &tp.in.params,
569 : fname, STR_TERMINATE);
570 :
571 5826 : req = smb_raw_trans2_send(tree, &tp);
572 :
573 5826 : talloc_free(mem_ctx);
574 :
575 5826 : return req;
576 : }
577 :
578 : /****************************************************************************
579 : send a SMBgetatr (async send)
580 : ****************************************************************************/
581 1182 : static struct smbcli_request *smb_raw_getattr_send(struct smbcli_tree *tree,
582 : union smb_fileinfo *parms)
583 : {
584 48 : struct smbcli_request *req;
585 :
586 1182 : req = smbcli_request_setup(tree, SMBgetatr, 0, 0);
587 1182 : if (!req) return NULL;
588 :
589 1182 : smbcli_req_append_ascii4(req, parms->getattr.in.file.path, STR_TERMINATE);
590 :
591 1182 : if (!smbcli_request_send(req)) {
592 0 : smbcli_request_destroy(req);
593 0 : return NULL;
594 : }
595 :
596 1134 : return req;
597 : }
598 :
599 : /****************************************************************************
600 : send a SMBgetatr (async recv)
601 : ****************************************************************************/
602 1182 : static NTSTATUS smb_raw_getattr_recv(struct smbcli_request *req,
603 : union smb_fileinfo *parms)
604 : {
605 1182 : if (req == NULL) {
606 0 : goto failed;
607 : }
608 :
609 2364 : if (!smbcli_request_receive(req) ||
610 1182 : smbcli_request_is_error(req)) {
611 156 : return smbcli_request_destroy(req);
612 : }
613 :
614 1026 : SMBCLI_CHECK_WCT(req, 10);
615 1026 : parms->getattr.out.attrib = SVAL(req->in.vwv, VWV(0));
616 2052 : parms->getattr.out.write_time = raw_pull_dos_date3(req->transport,
617 1026 : req->in.vwv + VWV(1));
618 1026 : parms->getattr.out.size = IVAL(req->in.vwv, VWV(3));
619 :
620 1026 : failed:
621 1026 : return smbcli_request_destroy(req);
622 : }
623 :
624 :
625 : /****************************************************************************
626 : Handle SMBgetattrE (async send)
627 : ****************************************************************************/
628 14 : static struct smbcli_request *smb_raw_getattrE_send(struct smbcli_tree *tree,
629 : union smb_fileinfo *parms)
630 : {
631 2 : struct smbcli_request *req;
632 :
633 14 : req = smbcli_request_setup(tree, SMBgetattrE, 1, 0);
634 14 : if (!req) return NULL;
635 :
636 14 : SSVAL(req->out.vwv, VWV(0), parms->getattre.in.file.fnum);
637 14 : if (!smbcli_request_send(req)) {
638 0 : smbcli_request_destroy(req);
639 0 : return NULL;
640 : }
641 :
642 12 : return req;
643 : }
644 :
645 : /****************************************************************************
646 : Handle SMBgetattrE (async send)
647 : ****************************************************************************/
648 16 : static NTSTATUS smb_raw_getattrE_recv(struct smbcli_request *req,
649 : union smb_fileinfo *parms)
650 : {
651 16 : if (req == NULL) {
652 2 : goto failed;
653 : }
654 :
655 28 : if (!smbcli_request_receive(req) ||
656 14 : smbcli_request_is_error(req)) {
657 0 : return smbcli_request_destroy(req);
658 : }
659 :
660 14 : SMBCLI_CHECK_WCT(req, 11);
661 28 : parms->getattre.out.create_time = raw_pull_dos_date2(req->transport,
662 14 : req->in.vwv + VWV(0));
663 28 : parms->getattre.out.access_time = raw_pull_dos_date2(req->transport,
664 14 : req->in.vwv + VWV(2));
665 28 : parms->getattre.out.write_time = raw_pull_dos_date2(req->transport,
666 14 : req->in.vwv + VWV(4));
667 14 : parms->getattre.out.size = IVAL(req->in.vwv, VWV(6));
668 14 : parms->getattre.out.alloc_size = IVAL(req->in.vwv, VWV(8));
669 14 : parms->getattre.out.attrib = SVAL(req->in.vwv, VWV(10));
670 :
671 16 : failed:
672 16 : return smbcli_request_destroy(req);
673 : }
674 :
675 :
676 : /****************************************************************************
677 : Query file info (async send)
678 : ****************************************************************************/
679 13899 : struct smbcli_request *smb_raw_fileinfo_send(struct smbcli_tree *tree,
680 : union smb_fileinfo *parms)
681 : {
682 187 : DATA_BLOB data;
683 187 : struct smbcli_request *req;
684 :
685 : /* pass off the non-trans2 level to specialised functions */
686 13899 : if (parms->generic.level == RAW_FILEINFO_GETATTRE) {
687 14 : return smb_raw_getattrE_send(tree, parms);
688 : }
689 13885 : if (parms->generic.level == RAW_FILEINFO_SEC_DESC) {
690 7822 : return smb_raw_query_secdesc_send(tree, parms);
691 : }
692 6063 : if (parms->generic.level >= RAW_FILEINFO_GENERIC) {
693 0 : return NULL;
694 : }
695 :
696 6063 : data = data_blob(NULL, 0);
697 :
698 6063 : if (parms->generic.level == RAW_FILEINFO_EA_LIST) {
699 0 : if (!ea_push_name_list(tree,
700 : &data,
701 : parms->ea_list.in.num_names,
702 : parms->ea_list.in.ea_names)) {
703 0 : return NULL;
704 : }
705 : }
706 :
707 6248 : req = smb_raw_fileinfo_blob_send(tree,
708 6063 : parms->generic.in.file.fnum,
709 6063 : parms->generic.level, data);
710 :
711 6063 : data_blob_free(&data);
712 :
713 6063 : return req;
714 : }
715 :
716 : /****************************************************************************
717 : Query file info (async recv)
718 : ****************************************************************************/
719 20909 : NTSTATUS smb_raw_fileinfo_recv(struct smbcli_request *req,
720 : TALLOC_CTX *mem_ctx,
721 : union smb_fileinfo *parms)
722 : {
723 524 : DATA_BLOB blob;
724 524 : NTSTATUS status;
725 20909 : struct smbcli_session *session = req?req->session:NULL;
726 :
727 20909 : if (parms->generic.level == RAW_FILEINFO_GETATTRE) {
728 16 : return smb_raw_getattrE_recv(req, parms);
729 : }
730 20893 : if (parms->generic.level == RAW_FILEINFO_SEC_DESC) {
731 7822 : return smb_raw_query_secdesc_recv(req, mem_ctx, parms);
732 : }
733 13071 : if (parms->generic.level == RAW_FILEINFO_GETATTR) {
734 1182 : return smb_raw_getattr_recv(req, parms);
735 : }
736 :
737 11889 : status = smb_raw_fileinfo_blob_recv(req, mem_ctx, &blob);
738 11889 : if (!NT_STATUS_IS_OK(status)) {
739 5065 : return status;
740 : }
741 :
742 6824 : return smb_raw_info_backend(session, mem_ctx, parms, &blob);
743 : }
744 :
745 : /****************************************************************************
746 : Query file info (sync interface)
747 : ****************************************************************************/
748 10742 : _PUBLIC_ NTSTATUS smb_raw_fileinfo(struct smbcli_tree *tree,
749 : TALLOC_CTX *mem_ctx,
750 : union smb_fileinfo *parms)
751 : {
752 10742 : struct smbcli_request *req = smb_raw_fileinfo_send(tree, parms);
753 10742 : return smb_raw_fileinfo_recv(req, mem_ctx, parms);
754 : }
755 :
756 : /****************************************************************************
757 : Query path info (async send)
758 : ****************************************************************************/
759 7010 : _PUBLIC_ struct smbcli_request *smb_raw_pathinfo_send(struct smbcli_tree *tree,
760 : union smb_fileinfo *parms)
761 : {
762 337 : DATA_BLOB data;
763 337 : struct smbcli_request *req;
764 :
765 7010 : if (parms->generic.level == RAW_FILEINFO_GETATTR) {
766 1182 : return smb_raw_getattr_send(tree, parms);
767 : }
768 5828 : if (parms->generic.level >= RAW_FILEINFO_GENERIC) {
769 2 : return NULL;
770 : }
771 :
772 5826 : data = data_blob(NULL, 0);
773 :
774 5826 : if (parms->generic.level == RAW_FILEINFO_EA_LIST) {
775 151 : if (!ea_push_name_list(tree,
776 : &data,
777 : parms->ea_list.in.num_names,
778 : parms->ea_list.in.ea_names)) {
779 0 : return NULL;
780 : }
781 : }
782 :
783 6115 : req = smb_raw_pathinfo_blob_send(tree, parms->generic.in.file.path,
784 5826 : parms->generic.level, data);
785 5826 : data_blob_free(&data);
786 :
787 5826 : return req;
788 : }
789 :
790 : /****************************************************************************
791 : Query path info (async recv)
792 : ****************************************************************************/
793 7010 : _PUBLIC_ NTSTATUS smb_raw_pathinfo_recv(struct smbcli_request *req,
794 : TALLOC_CTX *mem_ctx,
795 : union smb_fileinfo *parms)
796 : {
797 : /* recv is identical to fileinfo */
798 7010 : return smb_raw_fileinfo_recv(req, mem_ctx, parms);
799 : }
800 :
801 : /****************************************************************************
802 : Query path info (sync interface)
803 : ****************************************************************************/
804 4637 : _PUBLIC_ NTSTATUS smb_raw_pathinfo(struct smbcli_tree *tree,
805 : TALLOC_CTX *mem_ctx,
806 : union smb_fileinfo *parms)
807 : {
808 4637 : struct smbcli_request *req = smb_raw_pathinfo_send(tree, parms);
809 4637 : return smb_raw_pathinfo_recv(req, mem_ctx, parms);
810 : }
|