Line data Source code
1 : /*
2 : Unix SMB/CIFS implementation.
3 : RAW_SFILEINFO_* calls
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 :
28 : /*
29 : Handle setfileinfo/setpathinfo passthu constructions
30 : */
31 9086 : bool smb_raw_setfileinfo_passthru(TALLOC_CTX *mem_ctx,
32 : enum smb_setfileinfo_level level,
33 : union smb_setfileinfo *parms,
34 : DATA_BLOB *blob)
35 : {
36 62 : unsigned int len;
37 :
38 : #define NEED_BLOB(n) do { \
39 : *blob = data_blob_talloc(mem_ctx, NULL, n); \
40 : if (blob->data == NULL && n != 0) return false; \
41 : } while (0)
42 :
43 9086 : switch (level) {
44 2242 : case RAW_SFILEINFO_BASIC_INFORMATION:
45 2242 : NEED_BLOB(40);
46 2242 : smbcli_push_nttime(blob->data, 0, parms->basic_info.in.create_time);
47 2242 : smbcli_push_nttime(blob->data, 8, parms->basic_info.in.access_time);
48 2242 : smbcli_push_nttime(blob->data, 16, parms->basic_info.in.write_time);
49 2242 : smbcli_push_nttime(blob->data, 24, parms->basic_info.in.change_time);
50 2242 : SIVAL(blob->data, 32, parms->basic_info.in.attrib);
51 2242 : SIVAL(blob->data, 36, 0); /* padding */
52 2242 : return true;
53 :
54 314 : case RAW_SFILEINFO_DISPOSITION_INFORMATION:
55 314 : NEED_BLOB(4);
56 314 : SIVAL(blob->data, 0, parms->disposition_info.in.delete_on_close);
57 314 : return true;
58 :
59 20 : case RAW_SFILEINFO_ALLOCATION_INFORMATION:
60 20 : NEED_BLOB(8);
61 20 : SBVAL(blob->data, 0, parms->allocation_info.in.alloc_size);
62 20 : return true;
63 :
64 831 : case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
65 831 : NEED_BLOB(8);
66 831 : SBVAL(blob->data, 0, parms->end_of_file_info.in.size);
67 831 : return true;
68 :
69 166 : case RAW_SFILEINFO_RENAME_INFORMATION:
70 166 : NEED_BLOB(12);
71 166 : SIVAL(blob->data, 0, parms->rename_information.in.overwrite);
72 166 : SIVAL(blob->data, 4, parms->rename_information.in.root_fid);
73 166 : len = smbcli_blob_append_string(NULL, mem_ctx, blob,
74 : parms->rename_information.in.new_name,
75 : STR_UNICODE|STR_TERMINATE);
76 166 : SIVAL(blob->data, 8, len - 2);
77 166 : return true;
78 :
79 698 : case RAW_SFILEINFO_RENAME_INFORMATION_SMB2:
80 698 : NEED_BLOB(20);
81 698 : SIVAL(blob->data, 0, parms->rename_information.in.overwrite);
82 698 : SIVAL(blob->data, 4, 0);
83 698 : SBVAL(blob->data, 8, parms->rename_information.in.root_fid);
84 698 : len = smbcli_blob_append_string(NULL, mem_ctx, blob,
85 : parms->rename_information.in.new_name,
86 : STR_UNICODE|STR_TERMINATE);
87 698 : SIVAL(blob->data, 16, len - 2);
88 698 : return true;
89 :
90 173 : case RAW_SFILEINFO_POSITION_INFORMATION:
91 173 : NEED_BLOB(8);
92 173 : SBVAL(blob->data, 0, parms->position_information.in.position);
93 173 : return true;
94 :
95 11 : case RAW_SFILEINFO_MODE_INFORMATION:
96 11 : NEED_BLOB(4);
97 11 : SIVAL(blob->data, 0, parms->mode_information.in.mode);
98 11 : return true;
99 :
100 4618 : case RAW_FILEINFO_SEC_DESC: {
101 2 : enum ndr_err_code ndr_err;
102 :
103 4618 : ndr_err = ndr_push_struct_blob(blob, mem_ctx, parms->set_secdesc.in.sd,
104 : (ndr_push_flags_fn_t)ndr_push_security_descriptor);
105 4618 : if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
106 0 : return false;
107 : }
108 :
109 4616 : return true;
110 : }
111 :
112 9 : case RAW_SFILEINFO_FULL_EA_INFORMATION:
113 9 : printf("num_eas=%d\n", parms->full_ea_information.in.eas.num_eas);
114 9 : NEED_BLOB(ea_list_size_chained(
115 : parms->full_ea_information.in.eas.num_eas,
116 : parms->full_ea_information.in.eas.eas, 4));
117 9 : ea_put_list_chained(blob->data,
118 : parms->full_ea_information.in.eas.num_eas,
119 : parms->full_ea_information.in.eas.eas, 4);
120 9 : return true;
121 :
122 : /* Unhandled levels */
123 4 : case RAW_SFILEINFO_PIPE_INFORMATION:
124 : case RAW_SFILEINFO_VALID_DATA_INFORMATION:
125 : case RAW_SFILEINFO_SHORT_NAME_INFORMATION:
126 : case RAW_SFILEINFO_1025:
127 : case RAW_SFILEINFO_1027:
128 : case RAW_SFILEINFO_1029:
129 : case RAW_SFILEINFO_1030:
130 : case RAW_SFILEINFO_1031:
131 : case RAW_SFILEINFO_1032:
132 : case RAW_SFILEINFO_1036:
133 : case RAW_SFILEINFO_1041:
134 : case RAW_SFILEINFO_1042:
135 : case RAW_SFILEINFO_1043:
136 : case RAW_SFILEINFO_1044:
137 4 : break;
138 :
139 0 : default:
140 0 : DEBUG(0,("Unhandled setfileinfo passthru level %d\n", level));
141 0 : return false;
142 : }
143 :
144 4 : return false;
145 : }
146 :
147 : /*
148 : Handle setfileinfo/setpathinfo trans2 backend.
149 : */
150 5909 : static bool smb_raw_setinfo_backend(struct smbcli_tree *tree,
151 : TALLOC_CTX *mem_ctx,
152 : union smb_setfileinfo *parms,
153 : DATA_BLOB *blob)
154 : {
155 5909 : switch (parms->generic.level) {
156 0 : case RAW_SFILEINFO_GENERIC:
157 : case RAW_SFILEINFO_SETATTR:
158 : case RAW_SFILEINFO_SETATTRE:
159 : case RAW_SFILEINFO_SEC_DESC:
160 : /* not handled here */
161 0 : return false;
162 :
163 3 : case RAW_SFILEINFO_STANDARD:
164 3 : NEED_BLOB(12);
165 3 : raw_push_dos_date2(tree->session->transport,
166 : blob->data, 0, parms->standard.in.create_time);
167 3 : raw_push_dos_date2(tree->session->transport,
168 : blob->data, 4, parms->standard.in.access_time);
169 3 : raw_push_dos_date2(tree->session->transport,
170 : blob->data, 8, parms->standard.in.write_time);
171 3 : return true;
172 :
173 3215 : case RAW_SFILEINFO_EA_SET:
174 3215 : NEED_BLOB(ea_list_size(parms->ea_set.in.num_eas, parms->ea_set.in.eas));
175 3215 : ea_put_list(blob->data, parms->ea_set.in.num_eas, parms->ea_set.in.eas);
176 3215 : return true;
177 :
178 1406 : case RAW_SFILEINFO_BASIC_INFO:
179 : case RAW_SFILEINFO_BASIC_INFORMATION:
180 1406 : return smb_raw_setfileinfo_passthru(mem_ctx, RAW_SFILEINFO_BASIC_INFORMATION,
181 : parms, blob);
182 :
183 14 : case RAW_SFILEINFO_UNIX_BASIC:
184 14 : NEED_BLOB(100);
185 14 : SBVAL(blob->data, 0, parms->unix_basic.in.end_of_file);
186 14 : SBVAL(blob->data, 8, parms->unix_basic.in.num_bytes);
187 14 : smbcli_push_nttime(blob->data, 16, parms->unix_basic.in.status_change_time);
188 14 : smbcli_push_nttime(blob->data, 24, parms->unix_basic.in.access_time);
189 14 : smbcli_push_nttime(blob->data, 32, parms->unix_basic.in.change_time);
190 14 : SBVAL(blob->data, 40, parms->unix_basic.in.uid);
191 14 : SBVAL(blob->data, 48, parms->unix_basic.in.gid);
192 14 : SIVAL(blob->data, 56, parms->unix_basic.in.file_type);
193 14 : SBVAL(blob->data, 60, parms->unix_basic.in.dev_major);
194 14 : SBVAL(blob->data, 68, parms->unix_basic.in.dev_minor);
195 14 : SBVAL(blob->data, 76, parms->unix_basic.in.unique_id);
196 14 : SBVAL(blob->data, 84, parms->unix_basic.in.permissions);
197 14 : SBVAL(blob->data, 92, parms->unix_basic.in.nlink);
198 14 : return true;
199 :
200 132 : case RAW_SFILEINFO_UNIX_INFO2:
201 132 : NEED_BLOB(116);
202 132 : SBVAL(blob->data, 0, parms->unix_info2.in.end_of_file);
203 132 : SBVAL(blob->data, 8, parms->unix_info2.in.num_bytes);
204 132 : smbcli_push_nttime(blob->data, 16, parms->unix_info2.in.status_change_time);
205 132 : smbcli_push_nttime(blob->data, 24, parms->unix_info2.in.access_time);
206 132 : smbcli_push_nttime(blob->data, 32, parms->unix_info2.in.change_time);
207 132 : SBVAL(blob->data, 40,parms->unix_info2.in.uid);
208 132 : SBVAL(blob->data, 48,parms->unix_info2.in.gid);
209 132 : SIVAL(blob->data, 56,parms->unix_info2.in.file_type);
210 132 : SBVAL(blob->data, 60,parms->unix_info2.in.dev_major);
211 132 : SBVAL(blob->data, 68,parms->unix_info2.in.dev_minor);
212 132 : SBVAL(blob->data, 76,parms->unix_info2.in.unique_id);
213 132 : SBVAL(blob->data, 84,parms->unix_info2.in.permissions);
214 132 : SBVAL(blob->data, 92,parms->unix_info2.in.nlink);
215 132 : smbcli_push_nttime(blob->data, 100, parms->unix_info2.in.create_time);
216 132 : SIVAL(blob->data, 108, parms->unix_info2.in.file_flags);
217 132 : SIVAL(blob->data, 112, parms->unix_info2.in.flags_mask);
218 132 : return true;
219 :
220 238 : case RAW_SFILEINFO_DISPOSITION_INFO:
221 : case RAW_SFILEINFO_DISPOSITION_INFORMATION:
222 238 : return smb_raw_setfileinfo_passthru(mem_ctx, RAW_SFILEINFO_DISPOSITION_INFORMATION,
223 : parms, blob);
224 :
225 15 : case RAW_SFILEINFO_ALLOCATION_INFO:
226 : case RAW_SFILEINFO_ALLOCATION_INFORMATION:
227 15 : return smb_raw_setfileinfo_passthru(mem_ctx, RAW_SFILEINFO_ALLOCATION_INFORMATION,
228 : parms, blob);
229 :
230 674 : case RAW_SFILEINFO_END_OF_FILE_INFO:
231 : case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
232 674 : return smb_raw_setfileinfo_passthru(mem_ctx, RAW_SFILEINFO_END_OF_FILE_INFORMATION,
233 : parms, blob);
234 :
235 166 : case RAW_SFILEINFO_RENAME_INFORMATION:
236 166 : return smb_raw_setfileinfo_passthru(mem_ctx, RAW_SFILEINFO_RENAME_INFORMATION,
237 : parms, blob);
238 :
239 32 : case RAW_SFILEINFO_POSITION_INFORMATION:
240 32 : return smb_raw_setfileinfo_passthru(mem_ctx, RAW_SFILEINFO_POSITION_INFORMATION,
241 : parms, blob);
242 :
243 8 : case RAW_SFILEINFO_MODE_INFORMATION:
244 8 : return smb_raw_setfileinfo_passthru(mem_ctx, RAW_SFILEINFO_MODE_INFORMATION,
245 : parms, blob);
246 :
247 : /* Unhandled passthru levels */
248 6 : case RAW_SFILEINFO_PIPE_INFORMATION:
249 : case RAW_SFILEINFO_VALID_DATA_INFORMATION:
250 : case RAW_SFILEINFO_SHORT_NAME_INFORMATION:
251 : case RAW_SFILEINFO_FULL_EA_INFORMATION:
252 : case RAW_SFILEINFO_1025:
253 : case RAW_SFILEINFO_1027:
254 : case RAW_SFILEINFO_1029:
255 : case RAW_SFILEINFO_1030:
256 : case RAW_SFILEINFO_1031:
257 : case RAW_SFILEINFO_1032:
258 : case RAW_SFILEINFO_1036:
259 : case RAW_SFILEINFO_1041:
260 : case RAW_SFILEINFO_1042:
261 : case RAW_SFILEINFO_1043:
262 : case RAW_SFILEINFO_1044:
263 6 : return smb_raw_setfileinfo_passthru(mem_ctx, parms->generic.level,
264 : parms, blob);
265 :
266 : /* Unhandled levels */
267 0 : case RAW_SFILEINFO_UNIX_LINK:
268 : case RAW_SFILEINFO_UNIX_HLINK:
269 : case RAW_SFILEINFO_RENAME_INFORMATION_SMB2:
270 : case RAW_SFILEINFO_LINK_INFORMATION:
271 0 : break;
272 : }
273 :
274 0 : return false;
275 : }
276 :
277 : /****************************************************************************
278 : Very raw set file info - takes data blob (async send)
279 : ****************************************************************************/
280 5547 : static struct smbcli_request *smb_raw_setfileinfo_blob_send(struct smbcli_tree *tree,
281 : TALLOC_CTX *mem_ctx,
282 : uint16_t fnum,
283 : uint16_t info_level,
284 : DATA_BLOB *blob)
285 : {
286 537 : struct smb_trans2 tp;
287 5547 : uint16_t setup = TRANSACT2_SETFILEINFO;
288 :
289 5547 : tp.in.max_setup = 0;
290 5547 : tp.in.flags = 0;
291 5547 : tp.in.timeout = 0;
292 5547 : tp.in.setup_count = 1;
293 5547 : tp.in.max_param = 2;
294 5547 : tp.in.max_data = 0;
295 5547 : tp.in.setup = &setup;
296 :
297 5547 : tp.in.params = data_blob_talloc(mem_ctx, NULL, 6);
298 5547 : if (!tp.in.params.data) {
299 0 : return NULL;
300 : }
301 5547 : SSVAL(tp.in.params.data, 0, fnum);
302 5547 : SSVAL(tp.in.params.data, 2, info_level);
303 5547 : SSVAL(tp.in.params.data, 4, 0); /* reserved */
304 :
305 5547 : tp.in.data = *blob;
306 :
307 5547 : return smb_raw_trans2_send(tree, &tp);
308 : }
309 :
310 : /****************************************************************************
311 : Very raw set path info - takes data blob
312 : ****************************************************************************/
313 358 : static struct smbcli_request *smb_raw_setpathinfo_blob_send(struct smbcli_tree *tree,
314 : TALLOC_CTX *mem_ctx,
315 : const char *fname,
316 : uint16_t info_level,
317 : DATA_BLOB *blob)
318 : {
319 12 : struct smb_trans2 tp;
320 358 : uint16_t setup = TRANSACT2_SETPATHINFO;
321 :
322 358 : tp.in.max_setup = 0;
323 358 : tp.in.flags = 0;
324 358 : tp.in.timeout = 0;
325 358 : tp.in.setup_count = 1;
326 358 : tp.in.max_param = 2;
327 358 : tp.in.max_data = 0;
328 358 : tp.in.setup = &setup;
329 :
330 358 : tp.in.params = data_blob_talloc(mem_ctx, NULL, 6);
331 358 : if (!tp.in.params.data) {
332 0 : return NULL;
333 : }
334 358 : SSVAL(tp.in.params.data, 0, info_level);
335 358 : SIVAL(tp.in.params.data, 2, 0);
336 358 : smbcli_blob_append_string(tree->session, mem_ctx,
337 : &tp.in.params,
338 : fname, STR_TERMINATE);
339 :
340 358 : tp.in.data = *blob;
341 :
342 358 : return smb_raw_trans2_send(tree, &tp);
343 : }
344 :
345 : /****************************************************************************
346 : Handle setattr (async send)
347 : ****************************************************************************/
348 1352 : static struct smbcli_request *smb_raw_setattr_send(struct smbcli_tree *tree,
349 : union smb_setfileinfo *parms)
350 : {
351 141 : struct smbcli_request *req;
352 :
353 1352 : req = smbcli_request_setup(tree, SMBsetatr, 8, 0);
354 1352 : if (!req) return NULL;
355 :
356 1352 : SSVAL(req->out.vwv, VWV(0), parms->setattr.in.attrib);
357 1352 : raw_push_dos_date3(tree->session->transport,
358 : req->out.vwv, VWV(1), parms->setattr.in.write_time);
359 1352 : memset(req->out.vwv + VWV(3), 0, 10); /* reserved */
360 1352 : smbcli_req_append_ascii4(req, parms->setattr.in.file.path, STR_TERMINATE);
361 1352 : smbcli_req_append_ascii4(req, "", STR_TERMINATE);
362 :
363 1352 : if (!smbcli_request_send(req)) {
364 0 : smbcli_request_destroy(req);
365 0 : return NULL;
366 : }
367 :
368 1211 : return req;
369 : }
370 :
371 : /****************************************************************************
372 : Handle setattrE. (async send)
373 : ****************************************************************************/
374 2 : static struct smbcli_request *smb_raw_setattrE_send(struct smbcli_tree *tree,
375 : union smb_setfileinfo *parms)
376 : {
377 0 : struct smbcli_request *req;
378 :
379 2 : req = smbcli_request_setup(tree, SMBsetattrE, 7, 0);
380 2 : if (!req) return NULL;
381 :
382 2 : SSVAL(req->out.vwv, VWV(0), parms->setattre.in.file.fnum);
383 2 : raw_push_dos_date2(tree->session->transport,
384 : req->out.vwv, VWV(1), parms->setattre.in.create_time);
385 2 : raw_push_dos_date2(tree->session->transport,
386 : req->out.vwv, VWV(3), parms->setattre.in.access_time);
387 2 : raw_push_dos_date2(tree->session->transport,
388 : req->out.vwv, VWV(5), parms->setattre.in.write_time);
389 :
390 2 : if (!smbcli_request_send(req)) {
391 0 : smbcli_request_destroy(req);
392 0 : return NULL;
393 : }
394 :
395 2 : return req;
396 : }
397 :
398 : /****************************************************************************
399 : Set file info (async send)
400 : ****************************************************************************/
401 12622 : struct smbcli_request *smb_raw_setfileinfo_send(struct smbcli_tree *tree,
402 : union smb_setfileinfo *parms)
403 : {
404 537 : DATA_BLOB blob;
405 537 : TALLOC_CTX *mem_ctx;
406 537 : struct smbcli_request *req;
407 :
408 12622 : if (parms->generic.level == RAW_SFILEINFO_SETATTRE) {
409 2 : return smb_raw_setattrE_send(tree, parms);
410 : }
411 12620 : if (parms->generic.level == RAW_SFILEINFO_SEC_DESC) {
412 7073 : return smb_raw_set_secdesc_send(tree, parms);
413 : }
414 5547 : if (parms->generic.level >= RAW_SFILEINFO_GENERIC) {
415 0 : return NULL;
416 : }
417 :
418 5547 : mem_ctx = talloc_init("setpathinfo");
419 5547 : if (!mem_ctx) return NULL;
420 :
421 5547 : if (!smb_raw_setinfo_backend(tree, mem_ctx, parms, &blob)) {
422 0 : talloc_free(mem_ctx);
423 0 : return NULL;
424 : }
425 :
426 : /* send request and process the output */
427 6084 : req = smb_raw_setfileinfo_blob_send(tree,
428 : mem_ctx,
429 5547 : parms->generic.in.file.fnum,
430 5547 : parms->generic.level,
431 : &blob);
432 :
433 5547 : talloc_free(mem_ctx);
434 5547 : return req;
435 : }
436 :
437 : /****************************************************************************
438 : Set file info (async send)
439 : ****************************************************************************/
440 12079 : _PUBLIC_ NTSTATUS smb_raw_setfileinfo(struct smbcli_tree *tree,
441 : union smb_setfileinfo *parms)
442 : {
443 12079 : struct smbcli_request *req = smb_raw_setfileinfo_send(tree, parms);
444 12079 : return smbcli_request_simple_recv(req);
445 : }
446 :
447 :
448 : /****************************************************************************
449 : Set path info (async send)
450 : ****************************************************************************/
451 1714 : _PUBLIC_ struct smbcli_request *smb_raw_setpathinfo_send(struct smbcli_tree *tree,
452 : union smb_setfileinfo *parms)
453 : {
454 153 : DATA_BLOB blob;
455 153 : TALLOC_CTX *mem_ctx;
456 153 : struct smbcli_request *req;
457 :
458 1714 : if (parms->generic.level == RAW_SFILEINFO_SETATTR) {
459 1352 : return smb_raw_setattr_send(tree, parms);
460 : }
461 362 : if (parms->generic.level >= RAW_SFILEINFO_GENERIC) {
462 0 : return NULL;
463 : }
464 :
465 362 : mem_ctx = talloc_init("setpathinfo");
466 362 : if (!mem_ctx) return NULL;
467 :
468 362 : if (!smb_raw_setinfo_backend(tree, mem_ctx, parms, &blob)) {
469 4 : talloc_free(mem_ctx);
470 4 : return NULL;
471 : }
472 :
473 : /* send request and process the output */
474 370 : req = smb_raw_setpathinfo_blob_send(tree,
475 : mem_ctx,
476 : parms->generic.in.file.path,
477 358 : parms->generic.level,
478 : &blob);
479 :
480 358 : talloc_free(mem_ctx);
481 358 : return req;
482 : }
483 :
484 : /****************************************************************************
485 : Set path info (sync interface)
486 : ****************************************************************************/
487 1568 : _PUBLIC_ NTSTATUS smb_raw_setpathinfo(struct smbcli_tree *tree,
488 : union smb_setfileinfo *parms)
489 : {
490 1568 : struct smbcli_request *req = smb_raw_setpathinfo_send(tree, parms);
491 1568 : return smbcli_request_simple_recv(req);
492 : }
|