r22757: test if calling talloc_free() works on parent elements from within a destrutor
[Samba.git] / source / smb_server / blob.c
blob0b38d3901d73cd6e25b2fa830cd0952a67814bda
1 /*
2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 2003
5 Copyright (C) Stefan Metzmacher 2006
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "includes.h"
23 #include "lib/util/dlinklist.h"
24 #include "smb_server/smb_server.h"
25 #include "librpc/gen_ndr/ndr_misc.h"
26 #include "ntvfs/ntvfs.h"
27 #include "libcli/raw/libcliraw.h"
29 #define BLOB_CHECK(cmd) do { \
30 NTSTATUS _status; \
31 _status = cmd; \
32 NT_STATUS_NOT_OK_RETURN(_status); \
33 } while (0)
35 #define BLOB_CHECK_MIN_SIZE(blob, size) do { \
36 if ((blob)->length < (size)) { \
37 return NT_STATUS_INFO_LENGTH_MISMATCH; \
38 } \
39 } while (0)
42 /* align the end of the blob on an 8 byte boundary */
43 #define BLOB_ALIGN(blob, alignment) do { \
44 if ((blob)->length & ((alignment)-1)) { \
45 uint8_t _pad = (alignment) - ((blob)->length & ((alignment)-1)); \
46 BLOB_CHECK(smbsrv_blob_fill_data(blob, blob, (blob)->length+_pad)); \
47 } \
48 } while (0)
50 /* grow the data size of a trans2 reply */
51 NTSTATUS smbsrv_blob_grow_data(TALLOC_CTX *mem_ctx,
52 DATA_BLOB *blob,
53 uint32_t new_size)
55 if (new_size > blob->length) {
56 uint8_t *p;
57 p = talloc_realloc(mem_ctx, blob->data, uint8_t, new_size);
58 NT_STATUS_HAVE_NO_MEMORY(p);
59 blob->data = p;
61 blob->length = new_size;
62 return NT_STATUS_OK;
65 /* grow the data, zero filling any new bytes */
66 NTSTATUS smbsrv_blob_fill_data(TALLOC_CTX *mem_ctx,
67 DATA_BLOB *blob,
68 uint32_t new_size)
70 uint32_t old_size = blob->length;
71 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, new_size));
72 if (new_size > old_size) {
73 memset(blob->data + old_size, 0, new_size - old_size);
75 return NT_STATUS_OK;
79 pull a string from a blob in a trans2 request
81 size_t smbsrv_blob_pull_string(struct smbsrv_request *req,
82 const DATA_BLOB *blob,
83 uint16_t offset,
84 const char **str,
85 int flags)
87 *str = NULL;
88 /* we use STR_NO_RANGE_CHECK because the params are allocated
89 separately in a DATA_BLOB, so we need to do our own range
90 checking */
91 if (offset >= blob->length) {
92 return 0;
95 return req_pull_string(req, str,
96 blob->data + offset,
97 blob->length - offset,
98 STR_NO_RANGE_CHECK | flags);
102 push a string into the data section of a trans2 request
103 return the number of bytes consumed in the output
105 size_t smbsrv_blob_push_string(TALLOC_CTX *mem_ctx,
106 DATA_BLOB *blob,
107 uint32_t len_offset,
108 uint32_t offset,
109 const char *str,
110 int dest_len,
111 int default_flags,
112 int flags)
114 int alignment = 0, ret = 0, pkt_len;
116 /* we use STR_NO_RANGE_CHECK because the params are allocated
117 separately in a DATA_BLOB, so we need to do our own range
118 checking */
119 if (!str || offset >= blob->length) {
120 if (flags & STR_LEN8BIT) {
121 SCVAL(blob->data, len_offset, 0);
122 } else {
123 SIVAL(blob->data, len_offset, 0);
125 return 0;
128 flags |= STR_NO_RANGE_CHECK;
130 if (dest_len == -1 || (dest_len > blob->length - offset)) {
131 dest_len = blob->length - offset;
134 if (!(flags & (STR_ASCII|STR_UNICODE))) {
135 flags |= default_flags;
138 if ((offset&1) && (flags & STR_UNICODE) && !(flags & STR_NOALIGN)) {
139 alignment = 1;
140 if (dest_len > 0) {
141 SCVAL(blob->data + offset, 0, 0);
142 ret = push_string(blob->data + offset + 1, str, dest_len-1, flags);
144 } else {
145 ret = push_string(blob->data + offset, str, dest_len, flags);
148 /* sometimes the string needs to be terminated, but the length
149 on the wire must not include the termination! */
150 pkt_len = ret;
152 if ((flags & STR_LEN_NOTERM) && (flags & STR_TERMINATE)) {
153 if ((flags & STR_UNICODE) && ret >= 2) {
154 pkt_len = ret-2;
156 if ((flags & STR_ASCII) && ret >= 1) {
157 pkt_len = ret-1;
161 if (flags & STR_LEN8BIT) {
162 SCVAL(blob->data, len_offset, pkt_len);
163 } else {
164 SIVAL(blob->data, len_offset, pkt_len);
167 return ret + alignment;
171 append a string to the data section of a trans2 reply
172 len_offset points to the place in the packet where the length field
173 should go
175 NTSTATUS smbsrv_blob_append_string(TALLOC_CTX *mem_ctx,
176 DATA_BLOB *blob,
177 const char *str,
178 uint_t len_offset,
179 int default_flags,
180 int flags)
182 size_t ret;
183 uint32_t offset;
184 const int max_bytes_per_char = 3;
186 offset = blob->length;
187 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, offset + (2+strlen_m(str))*max_bytes_per_char));
188 ret = smbsrv_blob_push_string(mem_ctx, blob, len_offset, offset, str, -1, default_flags, flags);
189 if (ret < 0) {
190 return NT_STATUS_FOOBAR;
192 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, offset + ret));
193 return NT_STATUS_OK;
196 NTSTATUS smbsrv_push_passthru_fsinfo(TALLOC_CTX *mem_ctx,
197 DATA_BLOB *blob,
198 enum smb_fsinfo_level level,
199 union smb_fsinfo *fsinfo,
200 int default_str_flags)
202 uint_t i;
203 DATA_BLOB guid_blob;
205 switch (level) {
206 case RAW_QFS_VOLUME_INFORMATION:
207 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 18));
209 push_nttime(blob->data, 0, fsinfo->volume_info.out.create_time);
210 SIVAL(blob->data, 8, fsinfo->volume_info.out.serial_number);
211 SSVAL(blob->data, 16, 0); /* padding */
212 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob,
213 fsinfo->volume_info.out.volume_name.s,
214 12, default_str_flags,
215 STR_UNICODE));
217 return NT_STATUS_OK;
219 case RAW_QFS_SIZE_INFORMATION:
220 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 24));
222 SBVAL(blob->data, 0, fsinfo->size_info.out.total_alloc_units);
223 SBVAL(blob->data, 8, fsinfo->size_info.out.avail_alloc_units);
224 SIVAL(blob->data, 16, fsinfo->size_info.out.sectors_per_unit);
225 SIVAL(blob->data, 20, fsinfo->size_info.out.bytes_per_sector);
227 return NT_STATUS_OK;
229 case RAW_QFS_DEVICE_INFORMATION:
230 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 8));
232 SIVAL(blob->data, 0, fsinfo->device_info.out.device_type);
233 SIVAL(blob->data, 4, fsinfo->device_info.out.characteristics);
235 return NT_STATUS_OK;
237 case RAW_QFS_ATTRIBUTE_INFORMATION:
238 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 12));
240 SIVAL(blob->data, 0, fsinfo->attribute_info.out.fs_attr);
241 SIVAL(blob->data, 4, fsinfo->attribute_info.out.max_file_component_length);
242 /* this must not be null terminated or win98 gets
243 confused! also note that w2k3 returns this as
244 unicode even when ascii is negotiated */
245 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob,
246 fsinfo->attribute_info.out.fs_type.s,
247 8, default_str_flags,
248 STR_UNICODE));
249 return NT_STATUS_OK;
252 case RAW_QFS_QUOTA_INFORMATION:
253 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 48));
255 SBVAL(blob->data, 0, fsinfo->quota_information.out.unknown[0]);
256 SBVAL(blob->data, 8, fsinfo->quota_information.out.unknown[1]);
257 SBVAL(blob->data, 16, fsinfo->quota_information.out.unknown[2]);
258 SBVAL(blob->data, 24, fsinfo->quota_information.out.quota_soft);
259 SBVAL(blob->data, 32, fsinfo->quota_information.out.quota_hard);
260 SBVAL(blob->data, 40, fsinfo->quota_information.out.quota_flags);
262 return NT_STATUS_OK;
265 case RAW_QFS_FULL_SIZE_INFORMATION:
266 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 32));
268 SBVAL(blob->data, 0, fsinfo->full_size_information.out.total_alloc_units);
269 SBVAL(blob->data, 8, fsinfo->full_size_information.out.call_avail_alloc_units);
270 SBVAL(blob->data, 16, fsinfo->full_size_information.out.actual_avail_alloc_units);
271 SIVAL(blob->data, 24, fsinfo->full_size_information.out.sectors_per_unit);
272 SIVAL(blob->data, 28, fsinfo->full_size_information.out.bytes_per_sector);
274 return NT_STATUS_OK;
276 case RAW_QFS_OBJECTID_INFORMATION:
277 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 64));
279 BLOB_CHECK(ndr_push_struct_blob(&guid_blob, mem_ctx,
280 &fsinfo->objectid_information.out.guid,
281 (ndr_push_flags_fn_t)ndr_push_GUID));
282 memcpy(blob->data, guid_blob.data, guid_blob.length);
284 for (i=0;i<6;i++) {
285 SBVAL(blob->data, 16 + 8*i, fsinfo->objectid_information.out.unknown[i]);
288 return NT_STATUS_OK;
290 default:
291 return NT_STATUS_INVALID_LEVEL;
294 return NT_STATUS_INVALID_LEVEL;
297 NTSTATUS smbsrv_push_passthru_fileinfo(TALLOC_CTX *mem_ctx,
298 DATA_BLOB *blob,
299 enum smb_fileinfo_level level,
300 union smb_fileinfo *st,
301 int default_str_flags)
303 uint_t i;
304 size_t list_size;
306 switch (level) {
307 case RAW_FILEINFO_BASIC_INFORMATION:
308 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 40));
310 push_nttime(blob->data, 0, st->basic_info.out.create_time);
311 push_nttime(blob->data, 8, st->basic_info.out.access_time);
312 push_nttime(blob->data, 16, st->basic_info.out.write_time);
313 push_nttime(blob->data, 24, st->basic_info.out.change_time);
314 SIVAL(blob->data, 32, st->basic_info.out.attrib);
315 SIVAL(blob->data, 36, 0); /* padding */
316 return NT_STATUS_OK;
318 case RAW_FILEINFO_NETWORK_OPEN_INFORMATION:
319 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 56));
321 push_nttime(blob->data, 0, st->network_open_information.out.create_time);
322 push_nttime(blob->data, 8, st->network_open_information.out.access_time);
323 push_nttime(blob->data, 16, st->network_open_information.out.write_time);
324 push_nttime(blob->data, 24, st->network_open_information.out.change_time);
325 SBVAL(blob->data, 32, st->network_open_information.out.alloc_size);
326 SBVAL(blob->data, 40, st->network_open_information.out.size);
327 SIVAL(blob->data, 48, st->network_open_information.out.attrib);
328 SIVAL(blob->data, 52, 0); /* padding */
329 return NT_STATUS_OK;
331 case RAW_FILEINFO_STANDARD_INFORMATION:
332 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 24));
334 SBVAL(blob->data, 0, st->standard_info.out.alloc_size);
335 SBVAL(blob->data, 8, st->standard_info.out.size);
336 SIVAL(blob->data, 16, st->standard_info.out.nlink);
337 SCVAL(blob->data, 20, st->standard_info.out.delete_pending);
338 SCVAL(blob->data, 21, st->standard_info.out.directory);
339 SSVAL(blob->data, 22, 0); /* padding */
340 return NT_STATUS_OK;
342 case RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION:
343 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 8));
345 SIVAL(blob->data, 0, st->attribute_tag_information.out.attrib);
346 SIVAL(blob->data, 4, st->attribute_tag_information.out.reparse_tag);
347 return NT_STATUS_OK;
349 case RAW_FILEINFO_EA_INFORMATION:
350 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 4));
352 SIVAL(blob->data, 0, st->ea_info.out.ea_size);
353 return NT_STATUS_OK;
355 case RAW_FILEINFO_MODE_INFORMATION:
356 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 4));
358 SIVAL(blob->data, 0, st->mode_information.out.mode);
359 return NT_STATUS_OK;
361 case RAW_FILEINFO_ALIGNMENT_INFORMATION:
362 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 4));
364 SIVAL(blob->data, 0,
365 st->alignment_information.out.alignment_requirement);
366 return NT_STATUS_OK;
368 case RAW_FILEINFO_ACCESS_INFORMATION:
369 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 4));
371 SIVAL(blob->data, 0, st->access_information.out.access_flags);
372 return NT_STATUS_OK;
374 case RAW_FILEINFO_POSITION_INFORMATION:
375 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 8));
377 SBVAL(blob->data, 0, st->position_information.out.position);
378 return NT_STATUS_OK;
380 case RAW_FILEINFO_COMPRESSION_INFORMATION:
381 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 16));
383 SBVAL(blob->data, 0, st->compression_info.out.compressed_size);
384 SSVAL(blob->data, 8, st->compression_info.out.format);
385 SCVAL(blob->data, 10, st->compression_info.out.unit_shift);
386 SCVAL(blob->data, 11, st->compression_info.out.chunk_shift);
387 SCVAL(blob->data, 12, st->compression_info.out.cluster_shift);
388 SSVAL(blob->data, 13, 0); /* 3 bytes padding */
389 SCVAL(blob->data, 15, 0);
390 return NT_STATUS_OK;
392 case RAW_FILEINFO_INTERNAL_INFORMATION:
393 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 8));
395 SBVAL(blob->data, 0, st->internal_information.out.file_id);
396 return NT_STATUS_OK;
398 case RAW_FILEINFO_ALL_INFORMATION:
399 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 72));
401 push_nttime(blob->data, 0, st->all_info.out.create_time);
402 push_nttime(blob->data, 8, st->all_info.out.access_time);
403 push_nttime(blob->data, 16, st->all_info.out.write_time);
404 push_nttime(blob->data, 24, st->all_info.out.change_time);
405 SIVAL(blob->data, 32, st->all_info.out.attrib);
406 SIVAL(blob->data, 36, 0); /* padding */
407 SBVAL(blob->data, 40, st->all_info.out.alloc_size);
408 SBVAL(blob->data, 48, st->all_info.out.size);
409 SIVAL(blob->data, 56, st->all_info.out.nlink);
410 SCVAL(blob->data, 60, st->all_info.out.delete_pending);
411 SCVAL(blob->data, 61, st->all_info.out.directory);
412 SSVAL(blob->data, 62, 0); /* padding */
413 SIVAL(blob->data, 64, st->all_info.out.ea_size);
414 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob,
415 st->all_info.out.fname.s,
416 68, default_str_flags,
417 STR_UNICODE));
418 return NT_STATUS_OK;
420 case RAW_FILEINFO_NAME_INFORMATION:
421 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 4));
423 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob,
424 st->name_info.out.fname.s,
425 0, default_str_flags,
426 STR_UNICODE));
427 return NT_STATUS_OK;
429 case RAW_FILEINFO_ALT_NAME_INFORMATION:
430 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 4));
432 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob,
433 st->alt_name_info.out.fname.s,
434 0, default_str_flags,
435 STR_UNICODE));
436 return NT_STATUS_OK;
438 case RAW_FILEINFO_STREAM_INFORMATION:
439 for (i=0;i<st->stream_info.out.num_streams;i++) {
440 uint32_t data_size = blob->length;
441 uint8_t *data;
443 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, data_size + 24));
444 data = blob->data + data_size;
445 SBVAL(data, 8, st->stream_info.out.streams[i].size);
446 SBVAL(data, 16, st->stream_info.out.streams[i].alloc_size);
447 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob,
448 st->stream_info.out.streams[i].stream_name.s,
449 data_size + 4, default_str_flags,
450 STR_UNICODE));
451 if (i == st->stream_info.out.num_streams - 1) {
452 SIVAL(blob->data, data_size, 0);
453 } else {
454 BLOB_CHECK(smbsrv_blob_fill_data(mem_ctx, blob, (blob->length+7)&~7));
455 SIVAL(blob->data, data_size,
456 blob->length - data_size);
459 return NT_STATUS_OK;
461 case RAW_FILEINFO_SMB2_ALL_EAS:
462 /* if no eas are returned the backend should
463 * have returned NO_EAS_ON_FILE or NO_MORE_EAS
465 * so it's a programmer error if num_eas == 0
467 if (st->all_eas.out.num_eas == 0) {
468 smb_panic("0 eas for SMB2_ALL_EAS - programmer error in ntvfs backend");
471 list_size = ea_list_size_chained(st->all_eas.out.num_eas,
472 st->all_eas.out.eas);
473 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, list_size));
475 ea_put_list_chained(blob->data,
476 st->all_eas.out.num_eas,
477 st->all_eas.out.eas);
478 return NT_STATUS_OK;
480 case RAW_FILEINFO_SMB2_ALL_INFORMATION:
481 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 0x64));
483 push_nttime(blob->data, 0x00, st->all_info2.out.create_time);
484 push_nttime(blob->data, 0x08, st->all_info2.out.access_time);
485 push_nttime(blob->data, 0x10, st->all_info2.out.write_time);
486 push_nttime(blob->data, 0x18, st->all_info2.out.change_time);
487 SIVAL(blob->data, 0x20, st->all_info2.out.attrib);
488 SIVAL(blob->data, 0x24, st->all_info2.out.unknown1);
489 SBVAL(blob->data, 0x28, st->all_info2.out.alloc_size);
490 SBVAL(blob->data, 0x30, st->all_info2.out.size);
491 SIVAL(blob->data, 0x38, st->all_info2.out.nlink);
492 SCVAL(blob->data, 0x3C, st->all_info2.out.delete_pending);
493 SCVAL(blob->data, 0x3D, st->all_info2.out.directory);
494 SSVAL(blob->data, 0x3E, 0); /* padding */
495 SBVAL(blob->data, 0x40, st->all_info2.out.file_id);
496 SIVAL(blob->data, 0x48, st->all_info2.out.ea_size);
497 SIVAL(blob->data, 0x4C, st->all_info2.out.access_mask);
498 SBVAL(blob->data, 0x50, st->all_info2.out.position);
499 SBVAL(blob->data, 0x58, st->all_info2.out.mode);
500 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob,
501 st->all_info2.out.fname.s,
502 0x60, default_str_flags,
503 STR_UNICODE));
504 return NT_STATUS_OK;
506 default:
507 return NT_STATUS_INVALID_LEVEL;
510 return NT_STATUS_INVALID_LEVEL;
513 NTSTATUS smbsrv_pull_passthru_sfileinfo(TALLOC_CTX *mem_ctx,
514 enum smb_setfileinfo_level level,
515 union smb_setfileinfo *st,
516 const DATA_BLOB *blob,
517 int default_str_flags,
518 struct smbsrv_request *req)
520 uint32_t len;
521 DATA_BLOB str_blob;
523 switch (level) {
524 case SMB_SFILEINFO_BASIC_INFORMATION:
525 BLOB_CHECK_MIN_SIZE(blob, 36);
527 st->basic_info.in.create_time = pull_nttime(blob->data, 0);
528 st->basic_info.in.access_time = pull_nttime(blob->data, 8);
529 st->basic_info.in.write_time = pull_nttime(blob->data, 16);
530 st->basic_info.in.change_time = pull_nttime(blob->data, 24);
531 st->basic_info.in.attrib = IVAL(blob->data, 32);
533 return NT_STATUS_OK;
535 case SMB_SFILEINFO_DISPOSITION_INFORMATION:
536 BLOB_CHECK_MIN_SIZE(blob, 1);
538 st->disposition_info.in.delete_on_close = CVAL(blob->data, 0);
540 return NT_STATUS_OK;
542 case SMB_SFILEINFO_ALLOCATION_INFORMATION:
543 BLOB_CHECK_MIN_SIZE(blob, 8);
545 st->allocation_info.in.alloc_size = BVAL(blob->data, 0);
547 return NT_STATUS_OK;
549 case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
550 BLOB_CHECK_MIN_SIZE(blob, 8);
552 st->end_of_file_info.in.size = BVAL(blob->data, 0);
554 return NT_STATUS_OK;
556 case RAW_SFILEINFO_RENAME_INFORMATION:
557 if (!req) {
559 * TODO: get rid of smbsrv_request argument of
560 * smbsrv_blob_pull_string()
562 return NT_STATUS_NOT_IMPLEMENTED;
564 BLOB_CHECK_MIN_SIZE(blob, 12);
566 st->rename_information.in.overwrite = CVAL(blob->data, 0);
567 st->rename_information.in.root_fid = IVAL(blob->data, 4);
568 len = IVAL(blob->data, 8);
569 str_blob.data = blob->data+12;
570 str_blob.length = MIN(blob->length, len);
571 smbsrv_blob_pull_string(req, &str_blob, 0,
572 &st->rename_information.in.new_name,
573 STR_UNICODE);
574 if (st->rename_information.in.new_name == NULL) {
575 return NT_STATUS_FOOBAR;
578 return NT_STATUS_OK;
580 case RAW_SFILEINFO_POSITION_INFORMATION:
581 BLOB_CHECK_MIN_SIZE(blob, 8);
583 st->position_information.in.position = BVAL(blob->data, 0);
585 return NT_STATUS_OK;
587 case RAW_SFILEINFO_MODE_INFORMATION:
588 BLOB_CHECK_MIN_SIZE(blob, 4);
590 st->mode_information.in.mode = IVAL(blob->data, 0);
592 return NT_STATUS_OK;
594 default:
595 return NT_STATUS_INVALID_LEVEL;
598 return NT_STATUS_INVALID_LEVEL;
602 fill a single entry in a trans2 find reply
604 NTSTATUS smbsrv_push_passthru_search(TALLOC_CTX *mem_ctx,
605 DATA_BLOB *blob,
606 enum smb_search_data_level level,
607 union smb_search_data *file,
608 int default_str_flags)
610 uint8_t *data;
611 uint_t ofs = blob->length;
613 switch (level) {
614 case RAW_SEARCH_DATA_DIRECTORY_INFO:
615 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, ofs + 64));
616 data = blob->data + ofs;
617 SIVAL(data, 4, file->directory_info.file_index);
618 push_nttime(data, 8, file->directory_info.create_time);
619 push_nttime(data, 16, file->directory_info.access_time);
620 push_nttime(data, 24, file->directory_info.write_time);
621 push_nttime(data, 32, file->directory_info.change_time);
622 SBVAL(data, 40, file->directory_info.size);
623 SBVAL(data, 48, file->directory_info.alloc_size);
624 SIVAL(data, 56, file->directory_info.attrib);
625 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob, file->directory_info.name.s,
626 ofs + 60, default_str_flags,
627 STR_TERMINATE_ASCII));
628 BLOB_ALIGN(blob, 8);
629 data = blob->data + ofs;
630 SIVAL(data, 0, blob->length - ofs);
631 return NT_STATUS_OK;
633 case RAW_SEARCH_DATA_FULL_DIRECTORY_INFO:
634 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, ofs + 68));
635 data = blob->data + ofs;
636 SIVAL(data, 4, file->full_directory_info.file_index);
637 push_nttime(data, 8, file->full_directory_info.create_time);
638 push_nttime(data, 16, file->full_directory_info.access_time);
639 push_nttime(data, 24, file->full_directory_info.write_time);
640 push_nttime(data, 32, file->full_directory_info.change_time);
641 SBVAL(data, 40, file->full_directory_info.size);
642 SBVAL(data, 48, file->full_directory_info.alloc_size);
643 SIVAL(data, 56, file->full_directory_info.attrib);
644 SIVAL(data, 64, file->full_directory_info.ea_size);
645 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob, file->full_directory_info.name.s,
646 ofs + 60, default_str_flags,
647 STR_TERMINATE_ASCII));
648 BLOB_ALIGN(blob, 8);
649 data = blob->data + ofs;
650 SIVAL(data, 0, blob->length - ofs);
651 return NT_STATUS_OK;
653 case RAW_SEARCH_DATA_NAME_INFO:
654 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, ofs + 12));
655 data = blob->data + ofs;
656 SIVAL(data, 4, file->name_info.file_index);
657 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob, file->name_info.name.s,
658 ofs + 8, default_str_flags,
659 STR_TERMINATE_ASCII));
660 BLOB_ALIGN(blob, 8);
661 data = blob->data + ofs;
662 SIVAL(data, 0, blob->length - ofs);
663 return NT_STATUS_OK;
665 case RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO:
666 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, ofs + 94));
667 data = blob->data + ofs;
668 SIVAL(data, 4, file->both_directory_info.file_index);
669 push_nttime(data, 8, file->both_directory_info.create_time);
670 push_nttime(data, 16, file->both_directory_info.access_time);
671 push_nttime(data, 24, file->both_directory_info.write_time);
672 push_nttime(data, 32, file->both_directory_info.change_time);
673 SBVAL(data, 40, file->both_directory_info.size);
674 SBVAL(data, 48, file->both_directory_info.alloc_size);
675 SIVAL(data, 56, file->both_directory_info.attrib);
676 SIVAL(data, 64, file->both_directory_info.ea_size);
677 SCVAL(data, 69, 0); /* reserved */
678 memset(data+70,0,24);
679 smbsrv_blob_push_string(mem_ctx, blob,
680 68 + ofs, 70 + ofs,
681 file->both_directory_info.short_name.s,
682 24, default_str_flags,
683 STR_UNICODE | STR_LEN8BIT);
684 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob, file->both_directory_info.name.s,
685 ofs + 60, default_str_flags,
686 STR_TERMINATE_ASCII));
687 BLOB_ALIGN(blob, 8);
688 data = blob->data + ofs;
689 SIVAL(data, 0, blob->length - ofs);
690 return NT_STATUS_OK;
692 case RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO:
693 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, ofs + 80));
694 data = blob->data + ofs;
695 SIVAL(data, 4, file->id_full_directory_info.file_index);
696 push_nttime(data, 8, file->id_full_directory_info.create_time);
697 push_nttime(data, 16, file->id_full_directory_info.access_time);
698 push_nttime(data, 24, file->id_full_directory_info.write_time);
699 push_nttime(data, 32, file->id_full_directory_info.change_time);
700 SBVAL(data, 40, file->id_full_directory_info.size);
701 SBVAL(data, 48, file->id_full_directory_info.alloc_size);
702 SIVAL(data, 56, file->id_full_directory_info.attrib);
703 SIVAL(data, 64, file->id_full_directory_info.ea_size);
704 SIVAL(data, 68, 0); /* padding */
705 SBVAL(data, 72, file->id_full_directory_info.file_id);
706 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob, file->id_full_directory_info.name.s,
707 ofs + 60, default_str_flags,
708 STR_TERMINATE_ASCII));
709 BLOB_ALIGN(blob, 8);
710 data = blob->data + ofs;
711 SIVAL(data, 0, blob->length - ofs);
712 return NT_STATUS_OK;
714 case RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO:
715 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, ofs + 104));
716 data = blob->data + ofs;
717 SIVAL(data, 4, file->id_both_directory_info.file_index);
718 push_nttime(data, 8, file->id_both_directory_info.create_time);
719 push_nttime(data, 16, file->id_both_directory_info.access_time);
720 push_nttime(data, 24, file->id_both_directory_info.write_time);
721 push_nttime(data, 32, file->id_both_directory_info.change_time);
722 SBVAL(data, 40, file->id_both_directory_info.size);
723 SBVAL(data, 48, file->id_both_directory_info.alloc_size);
724 SIVAL(data, 56, file->id_both_directory_info.attrib);
725 SIVAL(data, 64, file->id_both_directory_info.ea_size);
726 SCVAL(data, 69, 0); /* reserved */
727 memset(data+70,0,26);
728 smbsrv_blob_push_string(mem_ctx, blob,
729 68 + ofs, 70 + ofs,
730 file->id_both_directory_info.short_name.s,
731 24, default_str_flags,
732 STR_UNICODE | STR_LEN8BIT);
733 SBVAL(data, 96, file->id_both_directory_info.file_id);
734 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob, file->id_both_directory_info.name.s,
735 ofs + 60, default_str_flags,
736 STR_TERMINATE_ASCII));
737 BLOB_ALIGN(blob, 8);
738 data = blob->data + ofs;
739 SIVAL(data, 0, blob->length - ofs);
740 return NT_STATUS_OK;
742 default:
743 return NT_STATUS_INVALID_LEVEL;
746 return NT_STATUS_INVALID_LEVEL;