idl: rebuild drsuapi.idl
[Samba/aatanasov.git] / source4 / smb_server / blob.c
blobf72074898af2d46845279eaa77969e7aac7836dc
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 "../lib/util/dlinklist.h"
23 #include "smb_server/smb_server.h"
24 #include "librpc/gen_ndr/ndr_misc.h"
25 #include "ntvfs/ntvfs.h"
26 #include "libcli/raw/libcliraw.h"
27 #include "libcli/raw/raw_proto.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_INVALID_PARAMETER; \
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 request_bufinfo *bufinfo,
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(bufinfo, 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 enum ndr_err_code ndr_err;
279 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 64));
281 ndr_err = ndr_push_struct_blob(&guid_blob, mem_ctx, NULL,
282 &fsinfo->objectid_information.out.guid,
283 (ndr_push_flags_fn_t)ndr_push_GUID);
284 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
285 BLOB_CHECK(ndr_map_error2ntstatus(ndr_err));
288 memcpy(blob->data, guid_blob.data, guid_blob.length);
290 for (i=0;i<6;i++) {
291 SBVAL(blob->data, 16 + 8*i, fsinfo->objectid_information.out.unknown[i]);
294 return NT_STATUS_OK;
296 default:
297 return NT_STATUS_INVALID_LEVEL;
300 return NT_STATUS_INVALID_LEVEL;
303 NTSTATUS smbsrv_push_passthru_fileinfo(TALLOC_CTX *mem_ctx,
304 DATA_BLOB *blob,
305 enum smb_fileinfo_level level,
306 union smb_fileinfo *st,
307 int default_str_flags)
309 uint_t i;
310 size_t list_size;
312 switch (level) {
313 case RAW_FILEINFO_BASIC_INFORMATION:
314 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 40));
316 push_nttime(blob->data, 0, st->basic_info.out.create_time);
317 push_nttime(blob->data, 8, st->basic_info.out.access_time);
318 push_nttime(blob->data, 16, st->basic_info.out.write_time);
319 push_nttime(blob->data, 24, st->basic_info.out.change_time);
320 SIVAL(blob->data, 32, st->basic_info.out.attrib);
321 SIVAL(blob->data, 36, 0); /* padding */
322 return NT_STATUS_OK;
324 case RAW_FILEINFO_NETWORK_OPEN_INFORMATION:
325 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 56));
327 push_nttime(blob->data, 0, st->network_open_information.out.create_time);
328 push_nttime(blob->data, 8, st->network_open_information.out.access_time);
329 push_nttime(blob->data, 16, st->network_open_information.out.write_time);
330 push_nttime(blob->data, 24, st->network_open_information.out.change_time);
331 SBVAL(blob->data, 32, st->network_open_information.out.alloc_size);
332 SBVAL(blob->data, 40, st->network_open_information.out.size);
333 SIVAL(blob->data, 48, st->network_open_information.out.attrib);
334 SIVAL(blob->data, 52, 0); /* padding */
335 return NT_STATUS_OK;
337 case RAW_FILEINFO_STANDARD_INFORMATION:
338 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 24));
340 SBVAL(blob->data, 0, st->standard_info.out.alloc_size);
341 SBVAL(blob->data, 8, st->standard_info.out.size);
342 SIVAL(blob->data, 16, st->standard_info.out.nlink);
343 SCVAL(blob->data, 20, st->standard_info.out.delete_pending);
344 SCVAL(blob->data, 21, st->standard_info.out.directory);
345 SSVAL(blob->data, 22, 0); /* padding */
346 return NT_STATUS_OK;
348 case RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION:
349 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 8));
351 SIVAL(blob->data, 0, st->attribute_tag_information.out.attrib);
352 SIVAL(blob->data, 4, st->attribute_tag_information.out.reparse_tag);
353 return NT_STATUS_OK;
355 case RAW_FILEINFO_EA_INFORMATION:
356 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 4));
358 SIVAL(blob->data, 0, st->ea_info.out.ea_size);
359 return NT_STATUS_OK;
361 case RAW_FILEINFO_MODE_INFORMATION:
362 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 4));
364 SIVAL(blob->data, 0, st->mode_information.out.mode);
365 return NT_STATUS_OK;
367 case RAW_FILEINFO_ALIGNMENT_INFORMATION:
368 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 4));
370 SIVAL(blob->data, 0,
371 st->alignment_information.out.alignment_requirement);
372 return NT_STATUS_OK;
374 case RAW_FILEINFO_ACCESS_INFORMATION:
375 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 4));
377 SIVAL(blob->data, 0, st->access_information.out.access_flags);
378 return NT_STATUS_OK;
380 case RAW_FILEINFO_POSITION_INFORMATION:
381 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 8));
383 SBVAL(blob->data, 0, st->position_information.out.position);
384 return NT_STATUS_OK;
386 case RAW_FILEINFO_COMPRESSION_INFORMATION:
387 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 16));
389 SBVAL(blob->data, 0, st->compression_info.out.compressed_size);
390 SSVAL(blob->data, 8, st->compression_info.out.format);
391 SCVAL(blob->data, 10, st->compression_info.out.unit_shift);
392 SCVAL(blob->data, 11, st->compression_info.out.chunk_shift);
393 SCVAL(blob->data, 12, st->compression_info.out.cluster_shift);
394 SSVAL(blob->data, 13, 0); /* 3 bytes padding */
395 SCVAL(blob->data, 15, 0);
396 return NT_STATUS_OK;
398 case RAW_FILEINFO_INTERNAL_INFORMATION:
399 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 8));
401 SBVAL(blob->data, 0, st->internal_information.out.file_id);
402 return NT_STATUS_OK;
404 case RAW_FILEINFO_ALL_INFORMATION:
405 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 72));
407 push_nttime(blob->data, 0, st->all_info.out.create_time);
408 push_nttime(blob->data, 8, st->all_info.out.access_time);
409 push_nttime(blob->data, 16, st->all_info.out.write_time);
410 push_nttime(blob->data, 24, st->all_info.out.change_time);
411 SIVAL(blob->data, 32, st->all_info.out.attrib);
412 SIVAL(blob->data, 36, 0); /* padding */
413 SBVAL(blob->data, 40, st->all_info.out.alloc_size);
414 SBVAL(blob->data, 48, st->all_info.out.size);
415 SIVAL(blob->data, 56, st->all_info.out.nlink);
416 SCVAL(blob->data, 60, st->all_info.out.delete_pending);
417 SCVAL(blob->data, 61, st->all_info.out.directory);
418 SSVAL(blob->data, 62, 0); /* padding */
419 SIVAL(blob->data, 64, st->all_info.out.ea_size);
420 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob,
421 st->all_info.out.fname.s,
422 68, default_str_flags,
423 STR_UNICODE));
424 return NT_STATUS_OK;
426 case RAW_FILEINFO_NAME_INFORMATION:
427 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 4));
429 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob,
430 st->name_info.out.fname.s,
431 0, default_str_flags,
432 STR_UNICODE));
433 return NT_STATUS_OK;
435 case RAW_FILEINFO_ALT_NAME_INFORMATION:
436 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 4));
438 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob,
439 st->alt_name_info.out.fname.s,
440 0, default_str_flags,
441 STR_UNICODE));
442 return NT_STATUS_OK;
444 case RAW_FILEINFO_STREAM_INFORMATION:
445 for (i=0;i<st->stream_info.out.num_streams;i++) {
446 uint32_t data_size = blob->length;
447 uint8_t *data;
449 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, data_size + 24));
450 data = blob->data + data_size;
451 SBVAL(data, 8, st->stream_info.out.streams[i].size);
452 SBVAL(data, 16, st->stream_info.out.streams[i].alloc_size);
453 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob,
454 st->stream_info.out.streams[i].stream_name.s,
455 data_size + 4, default_str_flags,
456 STR_UNICODE));
457 if (i == st->stream_info.out.num_streams - 1) {
458 SIVAL(blob->data, data_size, 0);
459 } else {
460 BLOB_CHECK(smbsrv_blob_fill_data(mem_ctx, blob, (blob->length+7)&~7));
461 SIVAL(blob->data, data_size,
462 blob->length - data_size);
465 return NT_STATUS_OK;
467 case RAW_FILEINFO_SMB2_ALL_EAS:
468 /* if no eas are returned the backend should
469 * have returned NO_EAS_ON_FILE or NO_MORE_EAS
471 * so it's a programmer error if num_eas == 0
473 if (st->all_eas.out.num_eas == 0) {
474 smb_panic("0 eas for SMB2_ALL_EAS - programmer error in ntvfs backend");
477 list_size = ea_list_size_chained(st->all_eas.out.num_eas,
478 st->all_eas.out.eas, 4);
479 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, list_size));
481 ea_put_list_chained(blob->data,
482 st->all_eas.out.num_eas,
483 st->all_eas.out.eas, 4);
484 return NT_STATUS_OK;
486 case RAW_FILEINFO_SMB2_ALL_INFORMATION:
487 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 0x64));
489 push_nttime(blob->data, 0x00, st->all_info2.out.create_time);
490 push_nttime(blob->data, 0x08, st->all_info2.out.access_time);
491 push_nttime(blob->data, 0x10, st->all_info2.out.write_time);
492 push_nttime(blob->data, 0x18, st->all_info2.out.change_time);
493 SIVAL(blob->data, 0x20, st->all_info2.out.attrib);
494 SIVAL(blob->data, 0x24, st->all_info2.out.unknown1);
495 SBVAL(blob->data, 0x28, st->all_info2.out.alloc_size);
496 SBVAL(blob->data, 0x30, st->all_info2.out.size);
497 SIVAL(blob->data, 0x38, st->all_info2.out.nlink);
498 SCVAL(blob->data, 0x3C, st->all_info2.out.delete_pending);
499 SCVAL(blob->data, 0x3D, st->all_info2.out.directory);
500 SSVAL(blob->data, 0x3E, 0); /* padding */
501 SBVAL(blob->data, 0x40, st->all_info2.out.file_id);
502 SIVAL(blob->data, 0x48, st->all_info2.out.ea_size);
503 SIVAL(blob->data, 0x4C, st->all_info2.out.access_mask);
504 SBVAL(blob->data, 0x50, st->all_info2.out.position);
505 SIVAL(blob->data, 0x58, st->all_info2.out.mode);
506 SIVAL(blob->data, 0x5C, st->all_info2.out.alignment_requirement);
507 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob,
508 st->all_info2.out.fname.s,
509 0x60, default_str_flags,
510 STR_UNICODE));
511 return NT_STATUS_OK;
513 default:
514 return NT_STATUS_INVALID_LEVEL;
517 return NT_STATUS_INVALID_LEVEL;
520 NTSTATUS smbsrv_pull_passthru_sfileinfo(TALLOC_CTX *mem_ctx,
521 enum smb_setfileinfo_level level,
522 union smb_setfileinfo *st,
523 const DATA_BLOB *blob,
524 int default_str_flags,
525 struct request_bufinfo *bufinfo)
527 uint32_t len, ofs;
528 DATA_BLOB str_blob;
530 switch (level) {
531 case SMB_SFILEINFO_BASIC_INFORMATION:
532 BLOB_CHECK_MIN_SIZE(blob, 40);
534 st->basic_info.in.create_time = pull_nttime(blob->data, 0);
535 st->basic_info.in.access_time = pull_nttime(blob->data, 8);
536 st->basic_info.in.write_time = pull_nttime(blob->data, 16);
537 st->basic_info.in.change_time = pull_nttime(blob->data, 24);
538 st->basic_info.in.attrib = IVAL(blob->data, 32);
539 st->basic_info.in.reserved = IVAL(blob->data, 36);
541 return NT_STATUS_OK;
543 case SMB_SFILEINFO_DISPOSITION_INFORMATION:
544 BLOB_CHECK_MIN_SIZE(blob, 1);
546 st->disposition_info.in.delete_on_close = CVAL(blob->data, 0);
548 return NT_STATUS_OK;
550 case SMB_SFILEINFO_ALLOCATION_INFORMATION:
551 BLOB_CHECK_MIN_SIZE(blob, 8);
553 st->allocation_info.in.alloc_size = BVAL(blob->data, 0);
555 return NT_STATUS_OK;
557 case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
558 BLOB_CHECK_MIN_SIZE(blob, 8);
560 st->end_of_file_info.in.size = BVAL(blob->data, 0);
562 return NT_STATUS_OK;
564 case RAW_SFILEINFO_RENAME_INFORMATION:
565 if (!bufinfo) {
566 return NT_STATUS_INTERNAL_ERROR;
568 BLOB_CHECK_MIN_SIZE(blob, 12);
569 st->rename_information.in.overwrite = CVAL(blob->data, 0);
570 st->rename_information.in.root_fid = IVAL(blob->data, 4);
571 len = IVAL(blob->data, 8);
572 ofs = 12;
573 str_blob = *blob;
574 str_blob.length = MIN(str_blob.length, ofs+len);
575 smbsrv_blob_pull_string(bufinfo, &str_blob, ofs,
576 &st->rename_information.in.new_name,
577 STR_UNICODE);
578 if (st->rename_information.in.new_name == NULL) {
579 return NT_STATUS_FOOBAR;
582 return NT_STATUS_OK;
585 case RAW_SFILEINFO_LINK_INFORMATION:
586 if (!bufinfo) {
587 return NT_STATUS_INTERNAL_ERROR;
589 BLOB_CHECK_MIN_SIZE(blob, 20);
590 st->link_information.in.overwrite = CVAL(blob->data, 0);
591 st->link_information.in.root_fid = IVAL(blob->data, 8);
592 len = IVAL(blob->data, 16);
593 ofs = 20;
594 str_blob = *blob;
595 str_blob.length = MIN(str_blob.length, ofs+len);
596 smbsrv_blob_pull_string(bufinfo, &str_blob, ofs,
597 &st->link_information.in.new_name,
598 STR_UNICODE);
599 if (st->link_information.in.new_name == NULL) {
600 return NT_STATUS_FOOBAR;
603 return NT_STATUS_OK;
605 case RAW_SFILEINFO_RENAME_INFORMATION_SMB2:
606 /* SMB2 uses a different format for rename information */
607 if (!bufinfo) {
608 return NT_STATUS_INTERNAL_ERROR;
610 BLOB_CHECK_MIN_SIZE(blob, 20);
611 st->rename_information.in.overwrite = CVAL(blob->data, 0);
612 st->rename_information.in.root_fid = BVAL(blob->data, 8);
613 len = IVAL(blob->data,16);
614 ofs = 20;
615 str_blob = *blob;
616 str_blob.length = MIN(str_blob.length, ofs+len);
617 smbsrv_blob_pull_string(bufinfo, &str_blob, ofs,
618 &st->rename_information.in.new_name,
619 STR_UNICODE);
620 if (st->rename_information.in.new_name == NULL) {
621 return NT_STATUS_FOOBAR;
624 return NT_STATUS_OK;
626 case RAW_SFILEINFO_POSITION_INFORMATION:
627 BLOB_CHECK_MIN_SIZE(blob, 8);
629 st->position_information.in.position = BVAL(blob->data, 0);
631 return NT_STATUS_OK;
633 case RAW_SFILEINFO_MODE_INFORMATION:
634 BLOB_CHECK_MIN_SIZE(blob, 4);
636 st->mode_information.in.mode = IVAL(blob->data, 0);
638 return NT_STATUS_OK;
640 default:
641 return NT_STATUS_INVALID_LEVEL;
644 return NT_STATUS_INVALID_LEVEL;
648 fill a single entry in a trans2 find reply
650 NTSTATUS smbsrv_push_passthru_search(TALLOC_CTX *mem_ctx,
651 DATA_BLOB *blob,
652 enum smb_search_data_level level,
653 const union smb_search_data *file,
654 int default_str_flags)
656 uint8_t *data;
657 uint_t ofs = blob->length;
659 switch (level) {
660 case RAW_SEARCH_DATA_DIRECTORY_INFO:
661 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, ofs + 64));
662 data = blob->data + ofs;
663 SIVAL(data, 4, file->directory_info.file_index);
664 push_nttime(data, 8, file->directory_info.create_time);
665 push_nttime(data, 16, file->directory_info.access_time);
666 push_nttime(data, 24, file->directory_info.write_time);
667 push_nttime(data, 32, file->directory_info.change_time);
668 SBVAL(data, 40, file->directory_info.size);
669 SBVAL(data, 48, file->directory_info.alloc_size);
670 SIVAL(data, 56, file->directory_info.attrib);
671 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob, file->directory_info.name.s,
672 ofs + 60, default_str_flags,
673 STR_TERMINATE_ASCII));
674 BLOB_ALIGN(blob, 8);
675 data = blob->data + ofs;
676 SIVAL(data, 0, blob->length - ofs);
677 return NT_STATUS_OK;
679 case RAW_SEARCH_DATA_FULL_DIRECTORY_INFO:
680 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, ofs + 68));
681 data = blob->data + ofs;
682 SIVAL(data, 4, file->full_directory_info.file_index);
683 push_nttime(data, 8, file->full_directory_info.create_time);
684 push_nttime(data, 16, file->full_directory_info.access_time);
685 push_nttime(data, 24, file->full_directory_info.write_time);
686 push_nttime(data, 32, file->full_directory_info.change_time);
687 SBVAL(data, 40, file->full_directory_info.size);
688 SBVAL(data, 48, file->full_directory_info.alloc_size);
689 SIVAL(data, 56, file->full_directory_info.attrib);
690 SIVAL(data, 64, file->full_directory_info.ea_size);
691 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob, file->full_directory_info.name.s,
692 ofs + 60, default_str_flags,
693 STR_TERMINATE_ASCII));
694 BLOB_ALIGN(blob, 8);
695 data = blob->data + ofs;
696 SIVAL(data, 0, blob->length - ofs);
697 return NT_STATUS_OK;
699 case RAW_SEARCH_DATA_NAME_INFO:
700 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, ofs + 12));
701 data = blob->data + ofs;
702 SIVAL(data, 4, file->name_info.file_index);
703 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob, file->name_info.name.s,
704 ofs + 8, default_str_flags,
705 STR_TERMINATE_ASCII));
706 BLOB_ALIGN(blob, 8);
707 data = blob->data + ofs;
708 SIVAL(data, 0, blob->length - ofs);
709 return NT_STATUS_OK;
711 case RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO:
712 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, ofs + 94));
713 data = blob->data + ofs;
714 SIVAL(data, 4, file->both_directory_info.file_index);
715 push_nttime(data, 8, file->both_directory_info.create_time);
716 push_nttime(data, 16, file->both_directory_info.access_time);
717 push_nttime(data, 24, file->both_directory_info.write_time);
718 push_nttime(data, 32, file->both_directory_info.change_time);
719 SBVAL(data, 40, file->both_directory_info.size);
720 SBVAL(data, 48, file->both_directory_info.alloc_size);
721 SIVAL(data, 56, file->both_directory_info.attrib);
722 SIVAL(data, 64, file->both_directory_info.ea_size);
723 SCVAL(data, 69, 0); /* reserved */
724 memset(data+70,0,24);
725 smbsrv_blob_push_string(mem_ctx, blob,
726 68 + ofs, 70 + ofs,
727 file->both_directory_info.short_name.s,
728 24, default_str_flags,
729 STR_UNICODE | STR_LEN8BIT);
730 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob, file->both_directory_info.name.s,
731 ofs + 60, default_str_flags,
732 STR_TERMINATE_ASCII));
733 BLOB_ALIGN(blob, 8);
734 data = blob->data + ofs;
735 SIVAL(data, 0, blob->length - ofs);
736 return NT_STATUS_OK;
738 case RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO:
739 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, ofs + 80));
740 data = blob->data + ofs;
741 SIVAL(data, 4, file->id_full_directory_info.file_index);
742 push_nttime(data, 8, file->id_full_directory_info.create_time);
743 push_nttime(data, 16, file->id_full_directory_info.access_time);
744 push_nttime(data, 24, file->id_full_directory_info.write_time);
745 push_nttime(data, 32, file->id_full_directory_info.change_time);
746 SBVAL(data, 40, file->id_full_directory_info.size);
747 SBVAL(data, 48, file->id_full_directory_info.alloc_size);
748 SIVAL(data, 56, file->id_full_directory_info.attrib);
749 SIVAL(data, 64, file->id_full_directory_info.ea_size);
750 SIVAL(data, 68, 0); /* padding */
751 SBVAL(data, 72, file->id_full_directory_info.file_id);
752 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob, file->id_full_directory_info.name.s,
753 ofs + 60, default_str_flags,
754 STR_TERMINATE_ASCII));
755 BLOB_ALIGN(blob, 8);
756 data = blob->data + ofs;
757 SIVAL(data, 0, blob->length - ofs);
758 return NT_STATUS_OK;
760 case RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO:
761 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, ofs + 104));
762 data = blob->data + ofs;
763 SIVAL(data, 4, file->id_both_directory_info.file_index);
764 push_nttime(data, 8, file->id_both_directory_info.create_time);
765 push_nttime(data, 16, file->id_both_directory_info.access_time);
766 push_nttime(data, 24, file->id_both_directory_info.write_time);
767 push_nttime(data, 32, file->id_both_directory_info.change_time);
768 SBVAL(data, 40, file->id_both_directory_info.size);
769 SBVAL(data, 48, file->id_both_directory_info.alloc_size);
770 SIVAL(data, 56, file->id_both_directory_info.attrib);
771 SIVAL(data, 64, file->id_both_directory_info.ea_size);
772 SCVAL(data, 69, 0); /* reserved */
773 memset(data+70,0,26);
774 smbsrv_blob_push_string(mem_ctx, blob,
775 68 + ofs, 70 + ofs,
776 file->id_both_directory_info.short_name.s,
777 24, default_str_flags,
778 STR_UNICODE | STR_LEN8BIT);
779 SBVAL(data, 96, file->id_both_directory_info.file_id);
780 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob, file->id_both_directory_info.name.s,
781 ofs + 60, default_str_flags,
782 STR_TERMINATE_ASCII));
783 BLOB_ALIGN(blob, 8);
784 data = blob->data + ofs;
785 SIVAL(data, 0, blob->length - ofs);
786 return NT_STATUS_OK;
788 default:
789 return NT_STATUS_INVALID_LEVEL;
792 return NT_STATUS_INVALID_LEVEL;