librpc: add FSRVP server state idl
[Samba.git] / source4 / smb_server / blob.c
blob24893299a903c701ce56267ab1558bf11610ff66
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 3 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, see <http://www.gnu.org/licenses/>.
21 #include "includes.h"
22 #include "smb_server/smb_server.h"
23 #include "librpc/gen_ndr/ndr_misc.h"
24 #include "libcli/raw/libcliraw.h"
25 #include "libcli/raw/raw_proto.h"
27 #define BLOB_CHECK(cmd) do { \
28 NTSTATUS _status; \
29 _status = cmd; \
30 NT_STATUS_NOT_OK_RETURN(_status); \
31 } while (0)
33 #define BLOB_CHECK_MIN_SIZE(blob, size) do { \
34 if ((blob)->length < (size)) { \
35 return NT_STATUS_INVALID_PARAMETER; \
36 } \
37 } while (0)
40 /* align the end of the blob on an 8 byte boundary */
41 #define BLOB_ALIGN(blob, alignment) do { \
42 if ((blob)->length & ((alignment)-1)) { \
43 uint8_t _pad = (alignment) - ((blob)->length & ((alignment)-1)); \
44 BLOB_CHECK(smbsrv_blob_fill_data(blob, blob, (blob)->length+_pad)); \
45 } \
46 } while (0)
48 /* grow the data size of a trans2 reply */
49 NTSTATUS smbsrv_blob_grow_data(TALLOC_CTX *mem_ctx,
50 DATA_BLOB *blob,
51 uint32_t new_size)
53 if (new_size > blob->length) {
54 uint8_t *p;
55 p = talloc_realloc(mem_ctx, blob->data, uint8_t, new_size);
56 NT_STATUS_HAVE_NO_MEMORY(p);
57 blob->data = p;
59 blob->length = new_size;
60 return NT_STATUS_OK;
63 /* grow the data, zero filling any new bytes */
64 NTSTATUS smbsrv_blob_fill_data(TALLOC_CTX *mem_ctx,
65 DATA_BLOB *blob,
66 uint32_t new_size)
68 uint32_t old_size = blob->length;
69 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, new_size));
70 if (new_size > old_size) {
71 memset(blob->data + old_size, 0, new_size - old_size);
73 return NT_STATUS_OK;
77 pull a string from a blob in a trans2 request
79 size_t smbsrv_blob_pull_string(struct request_bufinfo *bufinfo,
80 const DATA_BLOB *blob,
81 uint16_t offset,
82 const char **str,
83 int flags)
85 *str = NULL;
86 /* we use STR_NO_RANGE_CHECK because the params are allocated
87 separately in a DATA_BLOB, so we need to do our own range
88 checking */
89 if (offset >= blob->length) {
90 return 0;
93 return req_pull_string(bufinfo, str,
94 blob->data + offset,
95 blob->length - offset,
96 STR_NO_RANGE_CHECK | flags);
100 push a string into the data section of a trans2 request
101 return the number of bytes consumed in the output
103 static ssize_t smbsrv_blob_push_string(TALLOC_CTX *mem_ctx,
104 DATA_BLOB *blob,
105 uint32_t len_offset,
106 uint32_t offset,
107 const char *str,
108 int dest_len,
109 int default_flags,
110 int flags)
112 int alignment = 0, ret = 0, pkt_len;
114 /* we use STR_NO_RANGE_CHECK because the params are allocated
115 separately in a DATA_BLOB, so we need to do our own range
116 checking */
117 if (!str || offset >= blob->length) {
118 if (flags & STR_LEN8BIT) {
119 SCVAL(blob->data, len_offset, 0);
120 } else {
121 SIVAL(blob->data, len_offset, 0);
123 return 0;
126 flags |= STR_NO_RANGE_CHECK;
128 if (dest_len == -1 || (dest_len > blob->length - offset)) {
129 dest_len = blob->length - offset;
132 if (!(flags & (STR_ASCII|STR_UNICODE))) {
133 flags |= default_flags;
136 if ((offset&1) && (flags & STR_UNICODE) && !(flags & STR_NOALIGN)) {
137 alignment = 1;
138 if (dest_len > 0) {
139 SCVAL(blob->data + offset, 0, 0);
140 ret = push_string(blob->data + offset + 1, str, dest_len-1, flags);
142 } else {
143 ret = push_string(blob->data + offset, str, dest_len, flags);
145 if (ret == -1) {
146 return -1;
149 /* sometimes the string needs to be terminated, but the length
150 on the wire must not include the termination! */
151 pkt_len = ret;
153 if ((flags & STR_LEN_NOTERM) && (flags & STR_TERMINATE)) {
154 if ((flags & STR_UNICODE) && ret >= 2) {
155 pkt_len = ret-2;
157 if ((flags & STR_ASCII) && ret >= 1) {
158 pkt_len = ret-1;
162 if (flags & STR_LEN8BIT) {
163 SCVAL(blob->data, len_offset, pkt_len);
164 } else {
165 SIVAL(blob->data, len_offset, pkt_len);
168 return ret + alignment;
172 append a string to the data section of a trans2 reply
173 len_offset points to the place in the packet where the length field
174 should go
176 NTSTATUS smbsrv_blob_append_string(TALLOC_CTX *mem_ctx,
177 DATA_BLOB *blob,
178 const char *str,
179 unsigned int len_offset,
180 int default_flags,
181 int flags)
183 ssize_t ret;
184 uint32_t offset;
185 const int max_bytes_per_char = 3;
187 offset = blob->length;
188 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, offset + (2+strlen_m(str))*max_bytes_per_char));
189 ret = smbsrv_blob_push_string(mem_ctx, blob, len_offset, offset, str, -1, default_flags, flags);
190 if (ret < 0) {
191 return NT_STATUS_FOOBAR;
193 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, offset + ret));
194 return NT_STATUS_OK;
197 NTSTATUS smbsrv_push_passthru_fsinfo(TALLOC_CTX *mem_ctx,
198 DATA_BLOB *blob,
199 enum smb_fsinfo_level level,
200 union smb_fsinfo *fsinfo,
201 int default_str_flags)
203 unsigned int i;
204 DATA_BLOB guid_blob;
206 switch (level) {
207 case RAW_QFS_VOLUME_INFORMATION:
208 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 18));
210 push_nttime(blob->data, 0, fsinfo->volume_info.out.create_time);
211 SIVAL(blob->data, 8, fsinfo->volume_info.out.serial_number);
212 SSVAL(blob->data, 16, 0); /* padding */
213 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob,
214 fsinfo->volume_info.out.volume_name.s,
215 12, default_str_flags,
216 STR_UNICODE));
218 return NT_STATUS_OK;
220 case RAW_QFS_SIZE_INFORMATION:
221 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 24));
223 SBVAL(blob->data, 0, fsinfo->size_info.out.total_alloc_units);
224 SBVAL(blob->data, 8, fsinfo->size_info.out.avail_alloc_units);
225 SIVAL(blob->data, 16, fsinfo->size_info.out.sectors_per_unit);
226 SIVAL(blob->data, 20, fsinfo->size_info.out.bytes_per_sector);
228 return NT_STATUS_OK;
230 case RAW_QFS_DEVICE_INFORMATION:
231 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 8));
233 SIVAL(blob->data, 0, fsinfo->device_info.out.device_type);
234 SIVAL(blob->data, 4, fsinfo->device_info.out.characteristics);
236 return NT_STATUS_OK;
238 case RAW_QFS_ATTRIBUTE_INFORMATION:
239 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 12));
241 SIVAL(blob->data, 0, fsinfo->attribute_info.out.fs_attr);
242 SIVAL(blob->data, 4, fsinfo->attribute_info.out.max_file_component_length);
243 /* this must not be null terminated or win98 gets
244 confused! also note that w2k3 returns this as
245 unicode even when ascii is negotiated */
246 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob,
247 fsinfo->attribute_info.out.fs_type.s,
248 8, default_str_flags,
249 STR_UNICODE));
250 return NT_STATUS_OK;
253 case RAW_QFS_QUOTA_INFORMATION:
254 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 48));
256 SBVAL(blob->data, 0, fsinfo->quota_information.out.unknown[0]);
257 SBVAL(blob->data, 8, fsinfo->quota_information.out.unknown[1]);
258 SBVAL(blob->data, 16, fsinfo->quota_information.out.unknown[2]);
259 SBVAL(blob->data, 24, fsinfo->quota_information.out.quota_soft);
260 SBVAL(blob->data, 32, fsinfo->quota_information.out.quota_hard);
261 SBVAL(blob->data, 40, fsinfo->quota_information.out.quota_flags);
263 return NT_STATUS_OK;
266 case RAW_QFS_FULL_SIZE_INFORMATION:
267 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 32));
269 SBVAL(blob->data, 0, fsinfo->full_size_information.out.total_alloc_units);
270 SBVAL(blob->data, 8, fsinfo->full_size_information.out.call_avail_alloc_units);
271 SBVAL(blob->data, 16, fsinfo->full_size_information.out.actual_avail_alloc_units);
272 SIVAL(blob->data, 24, fsinfo->full_size_information.out.sectors_per_unit);
273 SIVAL(blob->data, 28, fsinfo->full_size_information.out.bytes_per_sector);
275 return NT_STATUS_OK;
277 case RAW_QFS_OBJECTID_INFORMATION: {
278 NTSTATUS status;
280 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 64));
282 status = GUID_to_ndr_blob(&fsinfo->objectid_information.out.guid, mem_ctx, &guid_blob);
283 if (!NT_STATUS_IS_OK(status)) {
284 BLOB_CHECK(status);
287 memcpy(blob->data, guid_blob.data, guid_blob.length);
289 for (i=0;i<6;i++) {
290 SBVAL(blob->data, 16 + 8*i, fsinfo->objectid_information.out.unknown[i]);
293 return NT_STATUS_OK;
296 case RAW_QFS_SECTOR_SIZE_INFORMATION:
297 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 28));
298 SIVAL(blob->data, 0,
299 fsinfo->sector_size_info.out.logical_bytes_per_sector);
300 SIVAL(blob->data, 4,
301 fsinfo->sector_size_info.out.phys_bytes_per_sector_atomic);
302 SIVAL(blob->data, 8,
303 fsinfo->sector_size_info.out.phys_bytes_per_sector_perf);
304 SIVAL(blob->data, 12,
305 fsinfo->sector_size_info.out.fs_effective_phys_bytes_per_sector_atomic);
306 SIVAL(blob->data, 16,
307 fsinfo->sector_size_info.out.flags);
308 SIVAL(blob->data, 20,
309 fsinfo->sector_size_info.out.byte_off_sector_align);
310 SIVAL(blob->data, 24,
311 fsinfo->sector_size_info.out.byte_off_partition_align);
313 return NT_STATUS_OK;
315 default:
316 return NT_STATUS_INVALID_LEVEL;
320 NTSTATUS smbsrv_push_passthru_fileinfo(TALLOC_CTX *mem_ctx,
321 DATA_BLOB *blob,
322 enum smb_fileinfo_level level,
323 union smb_fileinfo *st,
324 int default_str_flags)
326 unsigned int i;
327 size_t list_size;
329 switch (level) {
330 case RAW_FILEINFO_BASIC_INFORMATION:
331 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 40));
333 push_nttime(blob->data, 0, st->basic_info.out.create_time);
334 push_nttime(blob->data, 8, st->basic_info.out.access_time);
335 push_nttime(blob->data, 16, st->basic_info.out.write_time);
336 push_nttime(blob->data, 24, st->basic_info.out.change_time);
337 SIVAL(blob->data, 32, st->basic_info.out.attrib);
338 SIVAL(blob->data, 36, 0); /* padding */
339 return NT_STATUS_OK;
341 case RAW_FILEINFO_NETWORK_OPEN_INFORMATION:
342 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 56));
344 push_nttime(blob->data, 0, st->network_open_information.out.create_time);
345 push_nttime(blob->data, 8, st->network_open_information.out.access_time);
346 push_nttime(blob->data, 16, st->network_open_information.out.write_time);
347 push_nttime(blob->data, 24, st->network_open_information.out.change_time);
348 SBVAL(blob->data, 32, st->network_open_information.out.alloc_size);
349 SBVAL(blob->data, 40, st->network_open_information.out.size);
350 SIVAL(blob->data, 48, st->network_open_information.out.attrib);
351 SIVAL(blob->data, 52, 0); /* padding */
352 return NT_STATUS_OK;
354 case RAW_FILEINFO_STANDARD_INFORMATION:
355 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 24));
357 SBVAL(blob->data, 0, st->standard_info.out.alloc_size);
358 SBVAL(blob->data, 8, st->standard_info.out.size);
359 SIVAL(blob->data, 16, st->standard_info.out.nlink);
360 SCVAL(blob->data, 20, st->standard_info.out.delete_pending);
361 SCVAL(blob->data, 21, st->standard_info.out.directory);
362 SSVAL(blob->data, 22, 0); /* padding */
363 return NT_STATUS_OK;
365 case RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION:
366 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 8));
368 SIVAL(blob->data, 0, st->attribute_tag_information.out.attrib);
369 SIVAL(blob->data, 4, st->attribute_tag_information.out.reparse_tag);
370 return NT_STATUS_OK;
372 case RAW_FILEINFO_EA_INFORMATION:
373 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 4));
375 SIVAL(blob->data, 0, st->ea_info.out.ea_size);
376 return NT_STATUS_OK;
378 case RAW_FILEINFO_MODE_INFORMATION:
379 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 4));
381 SIVAL(blob->data, 0, st->mode_information.out.mode);
382 return NT_STATUS_OK;
384 case RAW_FILEINFO_ALIGNMENT_INFORMATION:
385 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 4));
387 SIVAL(blob->data, 0,
388 st->alignment_information.out.alignment_requirement);
389 return NT_STATUS_OK;
391 case RAW_FILEINFO_ACCESS_INFORMATION:
392 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 4));
394 SIVAL(blob->data, 0, st->access_information.out.access_flags);
395 return NT_STATUS_OK;
397 case RAW_FILEINFO_POSITION_INFORMATION:
398 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 8));
400 SBVAL(blob->data, 0, st->position_information.out.position);
401 return NT_STATUS_OK;
403 case RAW_FILEINFO_COMPRESSION_INFORMATION:
404 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 16));
406 SBVAL(blob->data, 0, st->compression_info.out.compressed_size);
407 SSVAL(blob->data, 8, st->compression_info.out.format);
408 SCVAL(blob->data, 10, st->compression_info.out.unit_shift);
409 SCVAL(blob->data, 11, st->compression_info.out.chunk_shift);
410 SCVAL(blob->data, 12, st->compression_info.out.cluster_shift);
411 SSVAL(blob->data, 13, 0); /* 3 bytes padding */
412 SCVAL(blob->data, 15, 0);
413 return NT_STATUS_OK;
415 case RAW_FILEINFO_INTERNAL_INFORMATION:
416 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 8));
418 SBVAL(blob->data, 0, st->internal_information.out.file_id);
419 return NT_STATUS_OK;
421 case RAW_FILEINFO_ALL_INFORMATION:
422 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 72));
424 push_nttime(blob->data, 0, st->all_info.out.create_time);
425 push_nttime(blob->data, 8, st->all_info.out.access_time);
426 push_nttime(blob->data, 16, st->all_info.out.write_time);
427 push_nttime(blob->data, 24, st->all_info.out.change_time);
428 SIVAL(blob->data, 32, st->all_info.out.attrib);
429 SIVAL(blob->data, 36, 0); /* padding */
430 SBVAL(blob->data, 40, st->all_info.out.alloc_size);
431 SBVAL(blob->data, 48, st->all_info.out.size);
432 SIVAL(blob->data, 56, st->all_info.out.nlink);
433 SCVAL(blob->data, 60, st->all_info.out.delete_pending);
434 SCVAL(blob->data, 61, st->all_info.out.directory);
435 SSVAL(blob->data, 62, 0); /* padding */
436 SIVAL(blob->data, 64, st->all_info.out.ea_size);
437 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob,
438 st->all_info.out.fname.s,
439 68, default_str_flags,
440 STR_UNICODE));
441 return NT_STATUS_OK;
443 case RAW_FILEINFO_NAME_INFORMATION:
444 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 4));
446 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob,
447 st->name_info.out.fname.s,
448 0, default_str_flags,
449 STR_UNICODE));
450 return NT_STATUS_OK;
452 case RAW_FILEINFO_ALT_NAME_INFORMATION:
453 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 4));
455 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob,
456 st->alt_name_info.out.fname.s,
457 0, default_str_flags,
458 STR_UNICODE));
459 return NT_STATUS_OK;
461 case RAW_FILEINFO_STREAM_INFORMATION:
462 for (i=0;i<st->stream_info.out.num_streams;i++) {
463 uint32_t data_size = blob->length;
464 uint8_t *data;
466 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, data_size + 24));
467 data = blob->data + data_size;
468 SBVAL(data, 8, st->stream_info.out.streams[i].size);
469 SBVAL(data, 16, st->stream_info.out.streams[i].alloc_size);
470 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob,
471 st->stream_info.out.streams[i].stream_name.s,
472 data_size + 4, default_str_flags,
473 STR_UNICODE));
474 if (i == st->stream_info.out.num_streams - 1) {
475 SIVAL(blob->data, data_size, 0);
476 } else {
477 BLOB_CHECK(smbsrv_blob_fill_data(mem_ctx, blob, (blob->length+7)&~7));
478 SIVAL(blob->data, data_size,
479 blob->length - data_size);
482 return NT_STATUS_OK;
484 case RAW_FILEINFO_SMB2_ALL_EAS:
485 /* if no eas are returned the backend should
486 * have returned NO_EAS_ON_FILE or NO_MORE_EAS
488 * so it's a programmer error if num_eas == 0
490 if (st->all_eas.out.num_eas == 0) {
491 smb_panic("0 eas for SMB2_ALL_EAS - programmer error in ntvfs backend");
494 list_size = ea_list_size_chained(st->all_eas.out.num_eas,
495 st->all_eas.out.eas, 4);
496 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, list_size));
498 ea_put_list_chained(blob->data,
499 st->all_eas.out.num_eas,
500 st->all_eas.out.eas, 4);
501 return NT_STATUS_OK;
503 case RAW_FILEINFO_SMB2_ALL_INFORMATION:
504 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 0x64));
506 push_nttime(blob->data, 0x00, st->all_info2.out.create_time);
507 push_nttime(blob->data, 0x08, st->all_info2.out.access_time);
508 push_nttime(blob->data, 0x10, st->all_info2.out.write_time);
509 push_nttime(blob->data, 0x18, st->all_info2.out.change_time);
510 SIVAL(blob->data, 0x20, st->all_info2.out.attrib);
511 SIVAL(blob->data, 0x24, st->all_info2.out.unknown1);
512 SBVAL(blob->data, 0x28, st->all_info2.out.alloc_size);
513 SBVAL(blob->data, 0x30, st->all_info2.out.size);
514 SIVAL(blob->data, 0x38, st->all_info2.out.nlink);
515 SCVAL(blob->data, 0x3C, st->all_info2.out.delete_pending);
516 SCVAL(blob->data, 0x3D, st->all_info2.out.directory);
517 SSVAL(blob->data, 0x3E, 0); /* padding */
518 SBVAL(blob->data, 0x40, st->all_info2.out.file_id);
519 SIVAL(blob->data, 0x48, st->all_info2.out.ea_size);
520 SIVAL(blob->data, 0x4C, st->all_info2.out.access_mask);
521 SBVAL(blob->data, 0x50, st->all_info2.out.position);
522 SIVAL(blob->data, 0x58, st->all_info2.out.mode);
523 SIVAL(blob->data, 0x5C, st->all_info2.out.alignment_requirement);
524 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob,
525 st->all_info2.out.fname.s,
526 0x60, default_str_flags,
527 STR_UNICODE));
528 return NT_STATUS_OK;
530 default:
531 return NT_STATUS_INVALID_LEVEL;
535 NTSTATUS smbsrv_pull_passthru_sfileinfo(TALLOC_CTX *mem_ctx,
536 enum smb_setfileinfo_level level,
537 union smb_setfileinfo *st,
538 const DATA_BLOB *blob,
539 int default_str_flags,
540 struct request_bufinfo *bufinfo)
542 uint32_t len, ofs;
543 DATA_BLOB str_blob;
545 switch (level) {
546 case SMB_SFILEINFO_BASIC_INFORMATION:
547 BLOB_CHECK_MIN_SIZE(blob, 40);
549 st->basic_info.in.create_time = pull_nttime(blob->data, 0);
550 st->basic_info.in.access_time = pull_nttime(blob->data, 8);
551 st->basic_info.in.write_time = pull_nttime(blob->data, 16);
552 st->basic_info.in.change_time = pull_nttime(blob->data, 24);
553 st->basic_info.in.attrib = IVAL(blob->data, 32);
554 st->basic_info.in.reserved = IVAL(blob->data, 36);
556 return NT_STATUS_OK;
558 case SMB_SFILEINFO_DISPOSITION_INFORMATION:
559 BLOB_CHECK_MIN_SIZE(blob, 1);
561 st->disposition_info.in.delete_on_close = CVAL(blob->data, 0);
563 return NT_STATUS_OK;
565 case SMB_SFILEINFO_ALLOCATION_INFORMATION:
566 BLOB_CHECK_MIN_SIZE(blob, 8);
568 st->allocation_info.in.alloc_size = BVAL(blob->data, 0);
570 return NT_STATUS_OK;
572 case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
573 BLOB_CHECK_MIN_SIZE(blob, 8);
575 st->end_of_file_info.in.size = BVAL(blob->data, 0);
577 return NT_STATUS_OK;
579 case RAW_SFILEINFO_RENAME_INFORMATION:
580 if (!bufinfo) {
581 return NT_STATUS_INTERNAL_ERROR;
583 BLOB_CHECK_MIN_SIZE(blob, 12);
584 st->rename_information.in.overwrite = CVAL(blob->data, 0);
585 st->rename_information.in.root_fid = IVAL(blob->data, 4);
586 len = IVAL(blob->data, 8);
587 ofs = 12;
588 str_blob = *blob;
589 str_blob.length = MIN(str_blob.length, ofs+len);
590 smbsrv_blob_pull_string(bufinfo, &str_blob, ofs,
591 &st->rename_information.in.new_name,
592 STR_UNICODE);
593 if (st->rename_information.in.new_name == NULL) {
594 return NT_STATUS_FOOBAR;
597 return NT_STATUS_OK;
600 case RAW_SFILEINFO_LINK_INFORMATION:
601 if (!bufinfo) {
602 return NT_STATUS_INTERNAL_ERROR;
604 BLOB_CHECK_MIN_SIZE(blob, 20);
605 st->link_information.in.overwrite = CVAL(blob->data, 0);
606 st->link_information.in.root_fid = IVAL(blob->data, 8);
607 len = IVAL(blob->data, 16);
608 ofs = 20;
609 str_blob = *blob;
610 str_blob.length = MIN(str_blob.length, ofs+len);
611 smbsrv_blob_pull_string(bufinfo, &str_blob, ofs,
612 &st->link_information.in.new_name,
613 STR_UNICODE);
614 if (st->link_information.in.new_name == NULL) {
615 return NT_STATUS_FOOBAR;
618 return NT_STATUS_OK;
620 case RAW_SFILEINFO_RENAME_INFORMATION_SMB2:
621 /* SMB2 uses a different format for rename information */
622 if (!bufinfo) {
623 return NT_STATUS_INTERNAL_ERROR;
625 BLOB_CHECK_MIN_SIZE(blob, 20);
626 st->rename_information.in.overwrite = CVAL(blob->data, 0);
627 st->rename_information.in.root_fid = BVAL(blob->data, 8);
628 len = IVAL(blob->data,16);
629 ofs = 20;
630 str_blob = *blob;
631 str_blob.length = MIN(str_blob.length, ofs+len);
632 smbsrv_blob_pull_string(bufinfo, &str_blob, ofs,
633 &st->rename_information.in.new_name,
634 STR_UNICODE);
635 if (st->rename_information.in.new_name == NULL) {
636 return NT_STATUS_FOOBAR;
639 return NT_STATUS_OK;
641 case RAW_SFILEINFO_POSITION_INFORMATION:
642 BLOB_CHECK_MIN_SIZE(blob, 8);
644 st->position_information.in.position = BVAL(blob->data, 0);
646 return NT_STATUS_OK;
648 case RAW_SFILEINFO_FULL_EA_INFORMATION:
649 return ea_pull_list_chained(blob,
650 mem_ctx,
651 &st->full_ea_information.in.eas.num_eas,
652 &st->full_ea_information.in.eas.eas);
654 case RAW_SFILEINFO_MODE_INFORMATION:
655 BLOB_CHECK_MIN_SIZE(blob, 4);
657 st->mode_information.in.mode = IVAL(blob->data, 0);
659 return NT_STATUS_OK;
661 default:
662 return NT_STATUS_INVALID_LEVEL;
667 fill a single entry in a trans2 find reply
669 NTSTATUS smbsrv_push_passthru_search(TALLOC_CTX *mem_ctx,
670 DATA_BLOB *blob,
671 enum smb_search_data_level level,
672 const union smb_search_data *file,
673 int default_str_flags)
675 uint8_t *data;
676 unsigned int ofs = blob->length;
678 switch (level) {
679 case RAW_SEARCH_DATA_DIRECTORY_INFO:
680 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, ofs + 64));
681 data = blob->data + ofs;
682 SIVAL(data, 4, file->directory_info.file_index);
683 push_nttime(data, 8, file->directory_info.create_time);
684 push_nttime(data, 16, file->directory_info.access_time);
685 push_nttime(data, 24, file->directory_info.write_time);
686 push_nttime(data, 32, file->directory_info.change_time);
687 SBVAL(data, 40, file->directory_info.size);
688 SBVAL(data, 48, file->directory_info.alloc_size);
689 SIVAL(data, 56, file->directory_info.attrib);
690 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob, file->directory_info.name.s,
691 ofs + 60, default_str_flags,
692 STR_TERMINATE_ASCII));
693 BLOB_ALIGN(blob, 8);
694 data = blob->data + ofs;
695 SIVAL(data, 0, blob->length - ofs);
696 return NT_STATUS_OK;
698 case RAW_SEARCH_DATA_FULL_DIRECTORY_INFO:
699 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, ofs + 68));
700 data = blob->data + ofs;
701 SIVAL(data, 4, file->full_directory_info.file_index);
702 push_nttime(data, 8, file->full_directory_info.create_time);
703 push_nttime(data, 16, file->full_directory_info.access_time);
704 push_nttime(data, 24, file->full_directory_info.write_time);
705 push_nttime(data, 32, file->full_directory_info.change_time);
706 SBVAL(data, 40, file->full_directory_info.size);
707 SBVAL(data, 48, file->full_directory_info.alloc_size);
708 SIVAL(data, 56, file->full_directory_info.attrib);
709 SIVAL(data, 64, file->full_directory_info.ea_size);
710 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob, file->full_directory_info.name.s,
711 ofs + 60, default_str_flags,
712 STR_TERMINATE_ASCII));
713 BLOB_ALIGN(blob, 8);
714 data = blob->data + ofs;
715 SIVAL(data, 0, blob->length - ofs);
716 return NT_STATUS_OK;
718 case RAW_SEARCH_DATA_NAME_INFO:
719 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, ofs + 12));
720 data = blob->data + ofs;
721 SIVAL(data, 4, file->name_info.file_index);
722 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob, file->name_info.name.s,
723 ofs + 8, default_str_flags,
724 STR_TERMINATE_ASCII));
725 BLOB_ALIGN(blob, 8);
726 data = blob->data + ofs;
727 SIVAL(data, 0, blob->length - ofs);
728 return NT_STATUS_OK;
730 case RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO:
731 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, ofs + 94));
732 data = blob->data + ofs;
733 SIVAL(data, 4, file->both_directory_info.file_index);
734 push_nttime(data, 8, file->both_directory_info.create_time);
735 push_nttime(data, 16, file->both_directory_info.access_time);
736 push_nttime(data, 24, file->both_directory_info.write_time);
737 push_nttime(data, 32, file->both_directory_info.change_time);
738 SBVAL(data, 40, file->both_directory_info.size);
739 SBVAL(data, 48, file->both_directory_info.alloc_size);
740 SIVAL(data, 56, file->both_directory_info.attrib);
741 SIVAL(data, 64, file->both_directory_info.ea_size);
742 SCVAL(data, 69, 0); /* reserved */
743 memset(data+70,0,24);
744 smbsrv_blob_push_string(mem_ctx, blob,
745 68 + ofs, 70 + ofs,
746 file->both_directory_info.short_name.s,
747 24, default_str_flags,
748 STR_UNICODE | STR_LEN8BIT);
749 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob, file->both_directory_info.name.s,
750 ofs + 60, default_str_flags,
751 STR_TERMINATE_ASCII));
752 BLOB_ALIGN(blob, 8);
753 data = blob->data + ofs;
754 SIVAL(data, 0, blob->length - ofs);
755 return NT_STATUS_OK;
757 case RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO:
758 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, ofs + 80));
759 data = blob->data + ofs;
760 SIVAL(data, 4, file->id_full_directory_info.file_index);
761 push_nttime(data, 8, file->id_full_directory_info.create_time);
762 push_nttime(data, 16, file->id_full_directory_info.access_time);
763 push_nttime(data, 24, file->id_full_directory_info.write_time);
764 push_nttime(data, 32, file->id_full_directory_info.change_time);
765 SBVAL(data, 40, file->id_full_directory_info.size);
766 SBVAL(data, 48, file->id_full_directory_info.alloc_size);
767 SIVAL(data, 56, file->id_full_directory_info.attrib);
768 SIVAL(data, 64, file->id_full_directory_info.ea_size);
769 SIVAL(data, 68, 0); /* padding */
770 SBVAL(data, 72, file->id_full_directory_info.file_id);
771 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob, file->id_full_directory_info.name.s,
772 ofs + 60, default_str_flags,
773 STR_TERMINATE_ASCII));
774 BLOB_ALIGN(blob, 8);
775 data = blob->data + ofs;
776 SIVAL(data, 0, blob->length - ofs);
777 return NT_STATUS_OK;
779 case RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO:
780 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, ofs + 104));
781 data = blob->data + ofs;
782 SIVAL(data, 4, file->id_both_directory_info.file_index);
783 push_nttime(data, 8, file->id_both_directory_info.create_time);
784 push_nttime(data, 16, file->id_both_directory_info.access_time);
785 push_nttime(data, 24, file->id_both_directory_info.write_time);
786 push_nttime(data, 32, file->id_both_directory_info.change_time);
787 SBVAL(data, 40, file->id_both_directory_info.size);
788 SBVAL(data, 48, file->id_both_directory_info.alloc_size);
789 SIVAL(data, 56, file->id_both_directory_info.attrib);
790 SIVAL(data, 64, file->id_both_directory_info.ea_size);
791 SCVAL(data, 69, 0); /* reserved */
792 memset(data+70,0,26);
793 smbsrv_blob_push_string(mem_ctx, blob,
794 68 + ofs, 70 + ofs,
795 file->id_both_directory_info.short_name.s,
796 24, default_str_flags,
797 STR_UNICODE | STR_LEN8BIT);
798 SBVAL(data, 96, file->id_both_directory_info.file_id);
799 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob, file->id_both_directory_info.name.s,
800 ofs + 60, default_str_flags,
801 STR_TERMINATE_ASCII));
802 BLOB_ALIGN(blob, 8);
803 data = blob->data + ofs;
804 SIVAL(data, 0, blob->length - ofs);
805 return NT_STATUS_OK;
807 default:
808 return NT_STATUS_INVALID_LEVEL;