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 1333 : 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 : 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 1333 : switch (level) {
44 552 : case RAW_SFILEINFO_BASIC_INFORMATION:
45 552 : NEED_BLOB(40);
46 552 : smbcli_push_nttime(blob->data, 0, parms->basic_info.in.create_time);
47 552 : smbcli_push_nttime(blob->data, 8, parms->basic_info.in.access_time);
48 552 : smbcli_push_nttime(blob->data, 16, parms->basic_info.in.write_time);
49 552 : smbcli_push_nttime(blob->data, 24, parms->basic_info.in.change_time);
50 552 : SIVAL(blob->data, 32, parms->basic_info.in.attrib);
51 552 : SIVAL(blob->data, 36, 0); /* padding */
52 552 : return true;
53 :
54 95 : case RAW_SFILEINFO_DISPOSITION_INFORMATION:
55 95 : NEED_BLOB(4);
56 95 : SIVAL(blob->data, 0, parms->disposition_info.in.delete_on_close);
57 95 : return true;
58 :
59 12 : case RAW_SFILEINFO_ALLOCATION_INFORMATION:
60 12 : NEED_BLOB(8);
61 12 : SBVAL(blob->data, 0, parms->allocation_info.in.alloc_size);
62 12 : return true;
63 :
64 566 : case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
65 566 : NEED_BLOB(8);
66 566 : SBVAL(blob->data, 0, parms->end_of_file_info.in.size);
67 566 : return true;
68 :
69 43 : case RAW_SFILEINFO_RENAME_INFORMATION:
70 43 : NEED_BLOB(12);
71 43 : SIVAL(blob->data, 0, parms->rename_information.in.overwrite);
72 43 : SIVAL(blob->data, 4, parms->rename_information.in.root_fid);
73 43 : len = smbcli_blob_append_string(NULL, mem_ctx, blob,
74 : parms->rename_information.in.new_name,
75 : STR_UNICODE|STR_TERMINATE);
76 43 : SIVAL(blob->data, 8, len - 2);
77 43 : return true;
78 :
79 8 : case RAW_SFILEINFO_RENAME_INFORMATION_SMB2:
80 8 : NEED_BLOB(20);
81 8 : SIVAL(blob->data, 0, parms->rename_information.in.overwrite);
82 8 : SIVAL(blob->data, 4, 0);
83 8 : SBVAL(blob->data, 8, parms->rename_information.in.root_fid);
84 8 : len = smbcli_blob_append_string(NULL, mem_ctx, blob,
85 : parms->rename_information.in.new_name,
86 : STR_UNICODE|STR_TERMINATE);
87 8 : SIVAL(blob->data, 16, len - 2);
88 8 : return true;
89 :
90 11 : case RAW_SFILEINFO_POSITION_INFORMATION:
91 11 : NEED_BLOB(8);
92 11 : SBVAL(blob->data, 0, parms->position_information.in.position);
93 11 : return true;
94 :
95 9 : case RAW_SFILEINFO_MODE_INFORMATION:
96 9 : NEED_BLOB(4);
97 9 : SIVAL(blob->data, 0, parms->mode_information.in.mode);
98 9 : return true;
99 :
100 24 : case RAW_FILEINFO_SEC_DESC: {
101 : enum ndr_err_code ndr_err;
102 :
103 24 : 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 24 : if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
106 0 : return false;
107 : }
108 :
109 24 : return true;
110 : }
111 :
112 3 : case RAW_SFILEINFO_FULL_EA_INFORMATION:
113 3 : printf("num_eas=%d\n", parms->full_ea_information.in.eas.num_eas);
114 3 : 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 3 : 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 3 : return true;
121 :
122 : /* Unhandled levels */
123 10 : 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 10 : break;
138 :
139 0 : default:
140 0 : DEBUG(0,("Unhandled setfileinfo passthru level %d\n", level));
141 0 : return false;
142 : }
143 :
144 10 : return false;
145 : }
146 :
147 : /*
148 : Handle setfileinfo/setpathinfo trans2 backend.
149 : */
150 1500 : 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 1500 : 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 5 : case RAW_SFILEINFO_STANDARD:
164 5 : NEED_BLOB(12);
165 5 : raw_push_dos_date2(tree->session->transport,
166 : blob->data, 0, parms->standard.in.create_time);
167 5 : raw_push_dos_date2(tree->session->transport,
168 : blob->data, 4, parms->standard.in.access_time);
169 5 : raw_push_dos_date2(tree->session->transport,
170 : blob->data, 8, parms->standard.in.write_time);
171 5 : return true;
172 :
173 290 : case RAW_SFILEINFO_EA_SET:
174 290 : NEED_BLOB(ea_list_size(parms->ea_set.in.num_eas, parms->ea_set.in.eas));
175 290 : ea_put_list(blob->data, parms->ea_set.in.num_eas, parms->ea_set.in.eas);
176 290 : return true;
177 :
178 479 : case RAW_SFILEINFO_BASIC_INFO:
179 : case RAW_SFILEINFO_BASIC_INFORMATION:
180 479 : return smb_raw_setfileinfo_passthru(mem_ctx, RAW_SFILEINFO_BASIC_INFORMATION,
181 : parms, blob);
182 :
183 0 : case RAW_SFILEINFO_UNIX_BASIC:
184 0 : NEED_BLOB(100);
185 0 : SBVAL(blob->data, 0, parms->unix_basic.in.end_of_file);
186 0 : SBVAL(blob->data, 8, parms->unix_basic.in.num_bytes);
187 0 : smbcli_push_nttime(blob->data, 16, parms->unix_basic.in.status_change_time);
188 0 : smbcli_push_nttime(blob->data, 24, parms->unix_basic.in.access_time);
189 0 : smbcli_push_nttime(blob->data, 32, parms->unix_basic.in.change_time);
190 0 : SBVAL(blob->data, 40, parms->unix_basic.in.uid);
191 0 : SBVAL(blob->data, 48, parms->unix_basic.in.gid);
192 0 : SIVAL(blob->data, 56, parms->unix_basic.in.file_type);
193 0 : SBVAL(blob->data, 60, parms->unix_basic.in.dev_major);
194 0 : SBVAL(blob->data, 68, parms->unix_basic.in.dev_minor);
195 0 : SBVAL(blob->data, 76, parms->unix_basic.in.unique_id);
196 0 : SBVAL(blob->data, 84, parms->unix_basic.in.permissions);
197 0 : SBVAL(blob->data, 92, parms->unix_basic.in.nlink);
198 0 : return true;
199 :
200 0 : case RAW_SFILEINFO_UNIX_INFO2:
201 0 : NEED_BLOB(116);
202 0 : SBVAL(blob->data, 0, parms->unix_info2.in.end_of_file);
203 0 : SBVAL(blob->data, 8, parms->unix_info2.in.num_bytes);
204 0 : smbcli_push_nttime(blob->data, 16, parms->unix_info2.in.status_change_time);
205 0 : smbcli_push_nttime(blob->data, 24, parms->unix_info2.in.access_time);
206 0 : smbcli_push_nttime(blob->data, 32, parms->unix_info2.in.change_time);
207 0 : SBVAL(blob->data, 40,parms->unix_info2.in.uid);
208 0 : SBVAL(blob->data, 48,parms->unix_info2.in.gid);
209 0 : SIVAL(blob->data, 56,parms->unix_info2.in.file_type);
210 0 : SBVAL(blob->data, 60,parms->unix_info2.in.dev_major);
211 0 : SBVAL(blob->data, 68,parms->unix_info2.in.dev_minor);
212 0 : SBVAL(blob->data, 76,parms->unix_info2.in.unique_id);
213 0 : SBVAL(blob->data, 84,parms->unix_info2.in.permissions);
214 0 : SBVAL(blob->data, 92,parms->unix_info2.in.nlink);
215 0 : smbcli_push_nttime(blob->data, 100, parms->unix_info2.in.create_time);
216 0 : SIVAL(blob->data, 108, parms->unix_info2.in.file_flags);
217 0 : SIVAL(blob->data, 112, parms->unix_info2.in.flags_mask);
218 0 : return true;
219 :
220 89 : case RAW_SFILEINFO_DISPOSITION_INFO:
221 : case RAW_SFILEINFO_DISPOSITION_INFORMATION:
222 89 : return smb_raw_setfileinfo_passthru(mem_ctx, RAW_SFILEINFO_DISPOSITION_INFORMATION,
223 : parms, blob);
224 :
225 9 : case RAW_SFILEINFO_ALLOCATION_INFO:
226 : case RAW_SFILEINFO_ALLOCATION_INFORMATION:
227 9 : return smb_raw_setfileinfo_passthru(mem_ctx, RAW_SFILEINFO_ALLOCATION_INFORMATION,
228 : parms, blob);
229 :
230 559 : case RAW_SFILEINFO_END_OF_FILE_INFO:
231 : case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
232 559 : return smb_raw_setfileinfo_passthru(mem_ctx, RAW_SFILEINFO_END_OF_FILE_INFORMATION,
233 : parms, blob);
234 :
235 43 : case RAW_SFILEINFO_RENAME_INFORMATION:
236 43 : return smb_raw_setfileinfo_passthru(mem_ctx, RAW_SFILEINFO_RENAME_INFORMATION,
237 : parms, blob);
238 :
239 10 : case RAW_SFILEINFO_POSITION_INFORMATION:
240 10 : return smb_raw_setfileinfo_passthru(mem_ctx, RAW_SFILEINFO_POSITION_INFORMATION,
241 : parms, blob);
242 :
243 6 : case RAW_SFILEINFO_MODE_INFORMATION:
244 6 : return smb_raw_setfileinfo_passthru(mem_ctx, RAW_SFILEINFO_MODE_INFORMATION,
245 : parms, blob);
246 :
247 : /* Unhandled passthru levels */
248 10 : 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 10 : 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 1432 : 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 : struct smb_trans2 tp;
287 1432 : uint16_t setup = TRANSACT2_SETFILEINFO;
288 :
289 1432 : tp.in.max_setup = 0;
290 1432 : tp.in.flags = 0;
291 1432 : tp.in.timeout = 0;
292 1432 : tp.in.setup_count = 1;
293 1432 : tp.in.max_param = 2;
294 1432 : tp.in.max_data = 0;
295 1432 : tp.in.setup = &setup;
296 :
297 1432 : tp.in.params = data_blob_talloc(mem_ctx, NULL, 6);
298 1432 : if (!tp.in.params.data) {
299 0 : return NULL;
300 : }
301 1432 : SSVAL(tp.in.params.data, 0, fnum);
302 1432 : SSVAL(tp.in.params.data, 2, info_level);
303 1432 : SSVAL(tp.in.params.data, 4, 0); /* reserved */
304 :
305 1432 : tp.in.data = *blob;
306 :
307 1432 : return smb_raw_trans2_send(tree, &tp);
308 : }
309 :
310 : /****************************************************************************
311 : Very raw set path info - takes data blob
312 : ****************************************************************************/
313 58 : 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 : struct smb_trans2 tp;
320 58 : uint16_t setup = TRANSACT2_SETPATHINFO;
321 :
322 58 : tp.in.max_setup = 0;
323 58 : tp.in.flags = 0;
324 58 : tp.in.timeout = 0;
325 58 : tp.in.setup_count = 1;
326 58 : tp.in.max_param = 2;
327 58 : tp.in.max_data = 0;
328 58 : tp.in.setup = &setup;
329 :
330 58 : tp.in.params = data_blob_talloc(mem_ctx, NULL, 6);
331 58 : if (!tp.in.params.data) {
332 0 : return NULL;
333 : }
334 58 : SSVAL(tp.in.params.data, 0, info_level);
335 58 : SIVAL(tp.in.params.data, 2, 0);
336 58 : smbcli_blob_append_string(tree->session, mem_ctx,
337 : &tp.in.params,
338 : fname, STR_TERMINATE);
339 :
340 58 : tp.in.data = *blob;
341 :
342 58 : return smb_raw_trans2_send(tree, &tp);
343 : }
344 :
345 : /****************************************************************************
346 : Handle setattr (async send)
347 : ****************************************************************************/
348 499 : static struct smbcli_request *smb_raw_setattr_send(struct smbcli_tree *tree,
349 : union smb_setfileinfo *parms)
350 : {
351 : struct smbcli_request *req;
352 :
353 499 : req = smbcli_request_setup(tree, SMBsetatr, 8, 0);
354 499 : if (!req) return NULL;
355 :
356 499 : SSVAL(req->out.vwv, VWV(0), parms->setattr.in.attrib);
357 499 : raw_push_dos_date3(tree->session->transport,
358 : req->out.vwv, VWV(1), parms->setattr.in.write_time);
359 499 : memset(req->out.vwv + VWV(3), 0, 10); /* reserved */
360 499 : smbcli_req_append_ascii4(req, parms->setattr.in.file.path, STR_TERMINATE);
361 499 : smbcli_req_append_ascii4(req, "", STR_TERMINATE);
362 :
363 499 : if (!smbcli_request_send(req)) {
364 0 : smbcli_request_destroy(req);
365 0 : return NULL;
366 : }
367 :
368 499 : return req;
369 : }
370 :
371 : /****************************************************************************
372 : Handle setattrE. (async send)
373 : ****************************************************************************/
374 4 : static struct smbcli_request *smb_raw_setattrE_send(struct smbcli_tree *tree,
375 : union smb_setfileinfo *parms)
376 : {
377 : struct smbcli_request *req;
378 :
379 4 : req = smbcli_request_setup(tree, SMBsetattrE, 7, 0);
380 4 : if (!req) return NULL;
381 :
382 4 : SSVAL(req->out.vwv, VWV(0), parms->setattre.in.file.fnum);
383 4 : raw_push_dos_date2(tree->session->transport,
384 : req->out.vwv, VWV(1), parms->setattre.in.create_time);
385 4 : raw_push_dos_date2(tree->session->transport,
386 : req->out.vwv, VWV(3), parms->setattre.in.access_time);
387 4 : raw_push_dos_date2(tree->session->transport,
388 : req->out.vwv, VWV(5), parms->setattre.in.write_time);
389 :
390 4 : if (!smbcli_request_send(req)) {
391 0 : smbcli_request_destroy(req);
392 0 : return NULL;
393 : }
394 :
395 4 : return req;
396 : }
397 :
398 : /****************************************************************************
399 : Set file info (async send)
400 : ****************************************************************************/
401 1971 : struct smbcli_request *smb_raw_setfileinfo_send(struct smbcli_tree *tree,
402 : union smb_setfileinfo *parms)
403 : {
404 : DATA_BLOB blob;
405 : TALLOC_CTX *mem_ctx;
406 : struct smbcli_request *req;
407 :
408 1971 : if (parms->generic.level == RAW_SFILEINFO_SETATTRE) {
409 4 : return smb_raw_setattrE_send(tree, parms);
410 : }
411 1967 : if (parms->generic.level == RAW_SFILEINFO_SEC_DESC) {
412 531 : return smb_raw_set_secdesc_send(tree, parms);
413 : }
414 1436 : if (parms->generic.level >= RAW_SFILEINFO_GENERIC) {
415 0 : return NULL;
416 : }
417 :
418 1436 : mem_ctx = talloc_init("setpathinfo");
419 1436 : if (!mem_ctx) return NULL;
420 :
421 1436 : if (!smb_raw_setinfo_backend(tree, mem_ctx, parms, &blob)) {
422 4 : talloc_free(mem_ctx);
423 4 : return NULL;
424 : }
425 :
426 : /* send request and process the output */
427 2864 : req = smb_raw_setfileinfo_blob_send(tree,
428 : mem_ctx,
429 1432 : parms->generic.in.file.fnum,
430 1432 : parms->generic.level,
431 : &blob);
432 :
433 1432 : talloc_free(mem_ctx);
434 1432 : return req;
435 : }
436 :
437 : /****************************************************************************
438 : Set file info (async send)
439 : ****************************************************************************/
440 1832 : _PUBLIC_ NTSTATUS smb_raw_setfileinfo(struct smbcli_tree *tree,
441 : union smb_setfileinfo *parms)
442 : {
443 1832 : struct smbcli_request *req = smb_raw_setfileinfo_send(tree, parms);
444 1832 : return smbcli_request_simple_recv(req);
445 : }
446 :
447 :
448 : /****************************************************************************
449 : Set path info (async send)
450 : ****************************************************************************/
451 563 : _PUBLIC_ struct smbcli_request *smb_raw_setpathinfo_send(struct smbcli_tree *tree,
452 : union smb_setfileinfo *parms)
453 : {
454 : DATA_BLOB blob;
455 : TALLOC_CTX *mem_ctx;
456 : struct smbcli_request *req;
457 :
458 563 : if (parms->generic.level == RAW_SFILEINFO_SETATTR) {
459 499 : return smb_raw_setattr_send(tree, parms);
460 : }
461 64 : if (parms->generic.level >= RAW_SFILEINFO_GENERIC) {
462 0 : return NULL;
463 : }
464 :
465 64 : mem_ctx = talloc_init("setpathinfo");
466 64 : if (!mem_ctx) return NULL;
467 :
468 64 : if (!smb_raw_setinfo_backend(tree, mem_ctx, parms, &blob)) {
469 6 : talloc_free(mem_ctx);
470 6 : return NULL;
471 : }
472 :
473 : /* send request and process the output */
474 58 : req = smb_raw_setpathinfo_blob_send(tree,
475 : mem_ctx,
476 : parms->generic.in.file.path,
477 58 : parms->generic.level,
478 : &blob);
479 :
480 58 : talloc_free(mem_ctx);
481 58 : return req;
482 : }
483 :
484 : /****************************************************************************
485 : Set path info (sync interface)
486 : ****************************************************************************/
487 417 : _PUBLIC_ NTSTATUS smb_raw_setpathinfo(struct smbcli_tree *tree,
488 : union smb_setfileinfo *parms)
489 : {
490 417 : struct smbcli_request *req = smb_raw_setpathinfo_send(tree, parms);
491 417 : return smbcli_request_simple_recv(req);
492 : }
|