s4:kdc make function static
[Samba/ekacnet.git] / source4 / smb_server / blob.c
blobc17cde070d6b53845105edabc8088e5f8c435230
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 size_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);
146 /* sometimes the string needs to be terminated, but the length
147 on the wire must not include the termination! */
148 pkt_len = ret;
150 if ((flags & STR_LEN_NOTERM) && (flags & STR_TERMINATE)) {
151 if ((flags & STR_UNICODE) && ret >= 2) {
152 pkt_len = ret-2;
154 if ((flags & STR_ASCII) && ret >= 1) {
155 pkt_len = ret-1;
159 if (flags & STR_LEN8BIT) {
160 SCVAL(blob->data, len_offset, pkt_len);
161 } else {
162 SIVAL(blob->data, len_offset, pkt_len);
165 return ret + alignment;
169 append a string to the data section of a trans2 reply
170 len_offset points to the place in the packet where the length field
171 should go
173 NTSTATUS smbsrv_blob_append_string(TALLOC_CTX *mem_ctx,
174 DATA_BLOB *blob,
175 const char *str,
176 unsigned int len_offset,
177 int default_flags,
178 int flags)
180 size_t ret;
181 uint32_t offset;
182 const int max_bytes_per_char = 3;
184 offset = blob->length;
185 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, offset + (2+strlen_m(str))*max_bytes_per_char));
186 ret = smbsrv_blob_push_string(mem_ctx, blob, len_offset, offset, str, -1, default_flags, flags);
187 if (ret < 0) {
188 return NT_STATUS_FOOBAR;
190 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, offset + ret));
191 return NT_STATUS_OK;
194 NTSTATUS smbsrv_push_passthru_fsinfo(TALLOC_CTX *mem_ctx,
195 DATA_BLOB *blob,
196 enum smb_fsinfo_level level,
197 union smb_fsinfo *fsinfo,
198 int default_str_flags)
200 unsigned int i;
201 DATA_BLOB guid_blob;
203 switch (level) {
204 case RAW_QFS_VOLUME_INFORMATION:
205 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 18));
207 push_nttime(blob->data, 0, fsinfo->volume_info.out.create_time);
208 SIVAL(blob->data, 8, fsinfo->volume_info.out.serial_number);
209 SSVAL(blob->data, 16, 0); /* padding */
210 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob,
211 fsinfo->volume_info.out.volume_name.s,
212 12, default_str_flags,
213 STR_UNICODE));
215 return NT_STATUS_OK;
217 case RAW_QFS_SIZE_INFORMATION:
218 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 24));
220 SBVAL(blob->data, 0, fsinfo->size_info.out.total_alloc_units);
221 SBVAL(blob->data, 8, fsinfo->size_info.out.avail_alloc_units);
222 SIVAL(blob->data, 16, fsinfo->size_info.out.sectors_per_unit);
223 SIVAL(blob->data, 20, fsinfo->size_info.out.bytes_per_sector);
225 return NT_STATUS_OK;
227 case RAW_QFS_DEVICE_INFORMATION:
228 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 8));
230 SIVAL(blob->data, 0, fsinfo->device_info.out.device_type);
231 SIVAL(blob->data, 4, fsinfo->device_info.out.characteristics);
233 return NT_STATUS_OK;
235 case RAW_QFS_ATTRIBUTE_INFORMATION:
236 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 12));
238 SIVAL(blob->data, 0, fsinfo->attribute_info.out.fs_attr);
239 SIVAL(blob->data, 4, fsinfo->attribute_info.out.max_file_component_length);
240 /* this must not be null terminated or win98 gets
241 confused! also note that w2k3 returns this as
242 unicode even when ascii is negotiated */
243 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob,
244 fsinfo->attribute_info.out.fs_type.s,
245 8, default_str_flags,
246 STR_UNICODE));
247 return NT_STATUS_OK;
250 case RAW_QFS_QUOTA_INFORMATION:
251 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 48));
253 SBVAL(blob->data, 0, fsinfo->quota_information.out.unknown[0]);
254 SBVAL(blob->data, 8, fsinfo->quota_information.out.unknown[1]);
255 SBVAL(blob->data, 16, fsinfo->quota_information.out.unknown[2]);
256 SBVAL(blob->data, 24, fsinfo->quota_information.out.quota_soft);
257 SBVAL(blob->data, 32, fsinfo->quota_information.out.quota_hard);
258 SBVAL(blob->data, 40, fsinfo->quota_information.out.quota_flags);
260 return NT_STATUS_OK;
263 case RAW_QFS_FULL_SIZE_INFORMATION:
264 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 32));
266 SBVAL(blob->data, 0, fsinfo->full_size_information.out.total_alloc_units);
267 SBVAL(blob->data, 8, fsinfo->full_size_information.out.call_avail_alloc_units);
268 SBVAL(blob->data, 16, fsinfo->full_size_information.out.actual_avail_alloc_units);
269 SIVAL(blob->data, 24, fsinfo->full_size_information.out.sectors_per_unit);
270 SIVAL(blob->data, 28, fsinfo->full_size_information.out.bytes_per_sector);
272 return NT_STATUS_OK;
274 case RAW_QFS_OBJECTID_INFORMATION: {
275 NTSTATUS status;
277 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 64));
279 status = GUID_to_ndr_blob(&fsinfo->objectid_information.out.guid, mem_ctx, &guid_blob);
280 if (!NT_STATUS_IS_OK(status)) {
281 BLOB_CHECK(status);
284 memcpy(blob->data, guid_blob.data, guid_blob.length);
286 for (i=0;i<6;i++) {
287 SBVAL(blob->data, 16 + 8*i, fsinfo->objectid_information.out.unknown[i]);
290 return NT_STATUS_OK;
292 default:
293 return NT_STATUS_INVALID_LEVEL;
296 return NT_STATUS_INVALID_LEVEL;
299 NTSTATUS smbsrv_push_passthru_fileinfo(TALLOC_CTX *mem_ctx,
300 DATA_BLOB *blob,
301 enum smb_fileinfo_level level,
302 union smb_fileinfo *st,
303 int default_str_flags)
305 unsigned int i;
306 size_t list_size;
308 switch (level) {
309 case RAW_FILEINFO_BASIC_INFORMATION:
310 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 40));
312 push_nttime(blob->data, 0, st->basic_info.out.create_time);
313 push_nttime(blob->data, 8, st->basic_info.out.access_time);
314 push_nttime(blob->data, 16, st->basic_info.out.write_time);
315 push_nttime(blob->data, 24, st->basic_info.out.change_time);
316 SIVAL(blob->data, 32, st->basic_info.out.attrib);
317 SIVAL(blob->data, 36, 0); /* padding */
318 return NT_STATUS_OK;
320 case RAW_FILEINFO_NETWORK_OPEN_INFORMATION:
321 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 56));
323 push_nttime(blob->data, 0, st->network_open_information.out.create_time);
324 push_nttime(blob->data, 8, st->network_open_information.out.access_time);
325 push_nttime(blob->data, 16, st->network_open_information.out.write_time);
326 push_nttime(blob->data, 24, st->network_open_information.out.change_time);
327 SBVAL(blob->data, 32, st->network_open_information.out.alloc_size);
328 SBVAL(blob->data, 40, st->network_open_information.out.size);
329 SIVAL(blob->data, 48, st->network_open_information.out.attrib);
330 SIVAL(blob->data, 52, 0); /* padding */
331 return NT_STATUS_OK;
333 case RAW_FILEINFO_STANDARD_INFORMATION:
334 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 24));
336 SBVAL(blob->data, 0, st->standard_info.out.alloc_size);
337 SBVAL(blob->data, 8, st->standard_info.out.size);
338 SIVAL(blob->data, 16, st->standard_info.out.nlink);
339 SCVAL(blob->data, 20, st->standard_info.out.delete_pending);
340 SCVAL(blob->data, 21, st->standard_info.out.directory);
341 SSVAL(blob->data, 22, 0); /* padding */
342 return NT_STATUS_OK;
344 case RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION:
345 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 8));
347 SIVAL(blob->data, 0, st->attribute_tag_information.out.attrib);
348 SIVAL(blob->data, 4, st->attribute_tag_information.out.reparse_tag);
349 return NT_STATUS_OK;
351 case RAW_FILEINFO_EA_INFORMATION:
352 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 4));
354 SIVAL(blob->data, 0, st->ea_info.out.ea_size);
355 return NT_STATUS_OK;
357 case RAW_FILEINFO_MODE_INFORMATION:
358 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 4));
360 SIVAL(blob->data, 0, st->mode_information.out.mode);
361 return NT_STATUS_OK;
363 case RAW_FILEINFO_ALIGNMENT_INFORMATION:
364 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 4));
366 SIVAL(blob->data, 0,
367 st->alignment_information.out.alignment_requirement);
368 return NT_STATUS_OK;
370 case RAW_FILEINFO_ACCESS_INFORMATION:
371 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 4));
373 SIVAL(blob->data, 0, st->access_information.out.access_flags);
374 return NT_STATUS_OK;
376 case RAW_FILEINFO_POSITION_INFORMATION:
377 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 8));
379 SBVAL(blob->data, 0, st->position_information.out.position);
380 return NT_STATUS_OK;
382 case RAW_FILEINFO_COMPRESSION_INFORMATION:
383 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 16));
385 SBVAL(blob->data, 0, st->compression_info.out.compressed_size);
386 SSVAL(blob->data, 8, st->compression_info.out.format);
387 SCVAL(blob->data, 10, st->compression_info.out.unit_shift);
388 SCVAL(blob->data, 11, st->compression_info.out.chunk_shift);
389 SCVAL(blob->data, 12, st->compression_info.out.cluster_shift);
390 SSVAL(blob->data, 13, 0); /* 3 bytes padding */
391 SCVAL(blob->data, 15, 0);
392 return NT_STATUS_OK;
394 case RAW_FILEINFO_INTERNAL_INFORMATION:
395 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 8));
397 SBVAL(blob->data, 0, st->internal_information.out.file_id);
398 return NT_STATUS_OK;
400 case RAW_FILEINFO_ALL_INFORMATION:
401 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 72));
403 push_nttime(blob->data, 0, st->all_info.out.create_time);
404 push_nttime(blob->data, 8, st->all_info.out.access_time);
405 push_nttime(blob->data, 16, st->all_info.out.write_time);
406 push_nttime(blob->data, 24, st->all_info.out.change_time);
407 SIVAL(blob->data, 32, st->all_info.out.attrib);
408 SIVAL(blob->data, 36, 0); /* padding */
409 SBVAL(blob->data, 40, st->all_info.out.alloc_size);
410 SBVAL(blob->data, 48, st->all_info.out.size);
411 SIVAL(blob->data, 56, st->all_info.out.nlink);
412 SCVAL(blob->data, 60, st->all_info.out.delete_pending);
413 SCVAL(blob->data, 61, st->all_info.out.directory);
414 SSVAL(blob->data, 62, 0); /* padding */
415 SIVAL(blob->data, 64, st->all_info.out.ea_size);
416 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob,
417 st->all_info.out.fname.s,
418 68, default_str_flags,
419 STR_UNICODE));
420 return NT_STATUS_OK;
422 case RAW_FILEINFO_NAME_INFORMATION:
423 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 4));
425 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob,
426 st->name_info.out.fname.s,
427 0, default_str_flags,
428 STR_UNICODE));
429 return NT_STATUS_OK;
431 case RAW_FILEINFO_ALT_NAME_INFORMATION:
432 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 4));
434 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob,
435 st->alt_name_info.out.fname.s,
436 0, default_str_flags,
437 STR_UNICODE));
438 return NT_STATUS_OK;
440 case RAW_FILEINFO_STREAM_INFORMATION:
441 for (i=0;i<st->stream_info.out.num_streams;i++) {
442 uint32_t data_size = blob->length;
443 uint8_t *data;
445 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, data_size + 24));
446 data = blob->data + data_size;
447 SBVAL(data, 8, st->stream_info.out.streams[i].size);
448 SBVAL(data, 16, st->stream_info.out.streams[i].alloc_size);
449 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob,
450 st->stream_info.out.streams[i].stream_name.s,
451 data_size + 4, default_str_flags,
452 STR_UNICODE));
453 if (i == st->stream_info.out.num_streams - 1) {
454 SIVAL(blob->data, data_size, 0);
455 } else {
456 BLOB_CHECK(smbsrv_blob_fill_data(mem_ctx, blob, (blob->length+7)&~7));
457 SIVAL(blob->data, data_size,
458 blob->length - data_size);
461 return NT_STATUS_OK;
463 case RAW_FILEINFO_SMB2_ALL_EAS:
464 /* if no eas are returned the backend should
465 * have returned NO_EAS_ON_FILE or NO_MORE_EAS
467 * so it's a programmer error if num_eas == 0
469 if (st->all_eas.out.num_eas == 0) {
470 smb_panic("0 eas for SMB2_ALL_EAS - programmer error in ntvfs backend");
473 list_size = ea_list_size_chained(st->all_eas.out.num_eas,
474 st->all_eas.out.eas, 4);
475 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, list_size));
477 ea_put_list_chained(blob->data,
478 st->all_eas.out.num_eas,
479 st->all_eas.out.eas, 4);
480 return NT_STATUS_OK;
482 case RAW_FILEINFO_SMB2_ALL_INFORMATION:
483 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 0x64));
485 push_nttime(blob->data, 0x00, st->all_info2.out.create_time);
486 push_nttime(blob->data, 0x08, st->all_info2.out.access_time);
487 push_nttime(blob->data, 0x10, st->all_info2.out.write_time);
488 push_nttime(blob->data, 0x18, st->all_info2.out.change_time);
489 SIVAL(blob->data, 0x20, st->all_info2.out.attrib);
490 SIVAL(blob->data, 0x24, st->all_info2.out.unknown1);
491 SBVAL(blob->data, 0x28, st->all_info2.out.alloc_size);
492 SBVAL(blob->data, 0x30, st->all_info2.out.size);
493 SIVAL(blob->data, 0x38, st->all_info2.out.nlink);
494 SCVAL(blob->data, 0x3C, st->all_info2.out.delete_pending);
495 SCVAL(blob->data, 0x3D, st->all_info2.out.directory);
496 SSVAL(blob->data, 0x3E, 0); /* padding */
497 SBVAL(blob->data, 0x40, st->all_info2.out.file_id);
498 SIVAL(blob->data, 0x48, st->all_info2.out.ea_size);
499 SIVAL(blob->data, 0x4C, st->all_info2.out.access_mask);
500 SBVAL(blob->data, 0x50, st->all_info2.out.position);
501 SIVAL(blob->data, 0x58, st->all_info2.out.mode);
502 SIVAL(blob->data, 0x5C, st->all_info2.out.alignment_requirement);
503 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob,
504 st->all_info2.out.fname.s,
505 0x60, default_str_flags,
506 STR_UNICODE));
507 return NT_STATUS_OK;
509 default:
510 return NT_STATUS_INVALID_LEVEL;
513 return NT_STATUS_INVALID_LEVEL;
516 NTSTATUS smbsrv_pull_passthru_sfileinfo(TALLOC_CTX *mem_ctx,
517 enum smb_setfileinfo_level level,
518 union smb_setfileinfo *st,
519 const DATA_BLOB *blob,
520 int default_str_flags,
521 struct request_bufinfo *bufinfo)
523 uint32_t len, ofs;
524 DATA_BLOB str_blob;
526 switch (level) {
527 case SMB_SFILEINFO_BASIC_INFORMATION:
528 BLOB_CHECK_MIN_SIZE(blob, 40);
530 st->basic_info.in.create_time = pull_nttime(blob->data, 0);
531 st->basic_info.in.access_time = pull_nttime(blob->data, 8);
532 st->basic_info.in.write_time = pull_nttime(blob->data, 16);
533 st->basic_info.in.change_time = pull_nttime(blob->data, 24);
534 st->basic_info.in.attrib = IVAL(blob->data, 32);
535 st->basic_info.in.reserved = IVAL(blob->data, 36);
537 return NT_STATUS_OK;
539 case SMB_SFILEINFO_DISPOSITION_INFORMATION:
540 BLOB_CHECK_MIN_SIZE(blob, 1);
542 st->disposition_info.in.delete_on_close = CVAL(blob->data, 0);
544 return NT_STATUS_OK;
546 case SMB_SFILEINFO_ALLOCATION_INFORMATION:
547 BLOB_CHECK_MIN_SIZE(blob, 8);
549 st->allocation_info.in.alloc_size = BVAL(blob->data, 0);
551 return NT_STATUS_OK;
553 case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
554 BLOB_CHECK_MIN_SIZE(blob, 8);
556 st->end_of_file_info.in.size = BVAL(blob->data, 0);
558 return NT_STATUS_OK;
560 case RAW_SFILEINFO_RENAME_INFORMATION:
561 if (!bufinfo) {
562 return NT_STATUS_INTERNAL_ERROR;
564 BLOB_CHECK_MIN_SIZE(blob, 12);
565 st->rename_information.in.overwrite = CVAL(blob->data, 0);
566 st->rename_information.in.root_fid = IVAL(blob->data, 4);
567 len = IVAL(blob->data, 8);
568 ofs = 12;
569 str_blob = *blob;
570 str_blob.length = MIN(str_blob.length, ofs+len);
571 smbsrv_blob_pull_string(bufinfo, &str_blob, ofs,
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;
581 case RAW_SFILEINFO_LINK_INFORMATION:
582 if (!bufinfo) {
583 return NT_STATUS_INTERNAL_ERROR;
585 BLOB_CHECK_MIN_SIZE(blob, 20);
586 st->link_information.in.overwrite = CVAL(blob->data, 0);
587 st->link_information.in.root_fid = IVAL(blob->data, 8);
588 len = IVAL(blob->data, 16);
589 ofs = 20;
590 str_blob = *blob;
591 str_blob.length = MIN(str_blob.length, ofs+len);
592 smbsrv_blob_pull_string(bufinfo, &str_blob, ofs,
593 &st->link_information.in.new_name,
594 STR_UNICODE);
595 if (st->link_information.in.new_name == NULL) {
596 return NT_STATUS_FOOBAR;
599 return NT_STATUS_OK;
601 case RAW_SFILEINFO_RENAME_INFORMATION_SMB2:
602 /* SMB2 uses a different format for rename information */
603 if (!bufinfo) {
604 return NT_STATUS_INTERNAL_ERROR;
606 BLOB_CHECK_MIN_SIZE(blob, 20);
607 st->rename_information.in.overwrite = CVAL(blob->data, 0);
608 st->rename_information.in.root_fid = BVAL(blob->data, 8);
609 len = IVAL(blob->data,16);
610 ofs = 20;
611 str_blob = *blob;
612 str_blob.length = MIN(str_blob.length, ofs+len);
613 smbsrv_blob_pull_string(bufinfo, &str_blob, ofs,
614 &st->rename_information.in.new_name,
615 STR_UNICODE);
616 if (st->rename_information.in.new_name == NULL) {
617 return NT_STATUS_FOOBAR;
620 return NT_STATUS_OK;
622 case RAW_SFILEINFO_POSITION_INFORMATION:
623 BLOB_CHECK_MIN_SIZE(blob, 8);
625 st->position_information.in.position = BVAL(blob->data, 0);
627 return NT_STATUS_OK;
629 case RAW_SFILEINFO_MODE_INFORMATION:
630 BLOB_CHECK_MIN_SIZE(blob, 4);
632 st->mode_information.in.mode = IVAL(blob->data, 0);
634 return NT_STATUS_OK;
636 default:
637 return NT_STATUS_INVALID_LEVEL;
640 return NT_STATUS_INVALID_LEVEL;
644 fill a single entry in a trans2 find reply
646 NTSTATUS smbsrv_push_passthru_search(TALLOC_CTX *mem_ctx,
647 DATA_BLOB *blob,
648 enum smb_search_data_level level,
649 const union smb_search_data *file,
650 int default_str_flags)
652 uint8_t *data;
653 unsigned int ofs = blob->length;
655 switch (level) {
656 case RAW_SEARCH_DATA_DIRECTORY_INFO:
657 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, ofs + 64));
658 data = blob->data + ofs;
659 SIVAL(data, 4, file->directory_info.file_index);
660 push_nttime(data, 8, file->directory_info.create_time);
661 push_nttime(data, 16, file->directory_info.access_time);
662 push_nttime(data, 24, file->directory_info.write_time);
663 push_nttime(data, 32, file->directory_info.change_time);
664 SBVAL(data, 40, file->directory_info.size);
665 SBVAL(data, 48, file->directory_info.alloc_size);
666 SIVAL(data, 56, file->directory_info.attrib);
667 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob, file->directory_info.name.s,
668 ofs + 60, default_str_flags,
669 STR_TERMINATE_ASCII));
670 BLOB_ALIGN(blob, 8);
671 data = blob->data + ofs;
672 SIVAL(data, 0, blob->length - ofs);
673 return NT_STATUS_OK;
675 case RAW_SEARCH_DATA_FULL_DIRECTORY_INFO:
676 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, ofs + 68));
677 data = blob->data + ofs;
678 SIVAL(data, 4, file->full_directory_info.file_index);
679 push_nttime(data, 8, file->full_directory_info.create_time);
680 push_nttime(data, 16, file->full_directory_info.access_time);
681 push_nttime(data, 24, file->full_directory_info.write_time);
682 push_nttime(data, 32, file->full_directory_info.change_time);
683 SBVAL(data, 40, file->full_directory_info.size);
684 SBVAL(data, 48, file->full_directory_info.alloc_size);
685 SIVAL(data, 56, file->full_directory_info.attrib);
686 SIVAL(data, 64, file->full_directory_info.ea_size);
687 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob, file->full_directory_info.name.s,
688 ofs + 60, default_str_flags,
689 STR_TERMINATE_ASCII));
690 BLOB_ALIGN(blob, 8);
691 data = blob->data + ofs;
692 SIVAL(data, 0, blob->length - ofs);
693 return NT_STATUS_OK;
695 case RAW_SEARCH_DATA_NAME_INFO:
696 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, ofs + 12));
697 data = blob->data + ofs;
698 SIVAL(data, 4, file->name_info.file_index);
699 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob, file->name_info.name.s,
700 ofs + 8, default_str_flags,
701 STR_TERMINATE_ASCII));
702 BLOB_ALIGN(blob, 8);
703 data = blob->data + ofs;
704 SIVAL(data, 0, blob->length - ofs);
705 return NT_STATUS_OK;
707 case RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO:
708 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, ofs + 94));
709 data = blob->data + ofs;
710 SIVAL(data, 4, file->both_directory_info.file_index);
711 push_nttime(data, 8, file->both_directory_info.create_time);
712 push_nttime(data, 16, file->both_directory_info.access_time);
713 push_nttime(data, 24, file->both_directory_info.write_time);
714 push_nttime(data, 32, file->both_directory_info.change_time);
715 SBVAL(data, 40, file->both_directory_info.size);
716 SBVAL(data, 48, file->both_directory_info.alloc_size);
717 SIVAL(data, 56, file->both_directory_info.attrib);
718 SIVAL(data, 64, file->both_directory_info.ea_size);
719 SCVAL(data, 69, 0); /* reserved */
720 memset(data+70,0,24);
721 smbsrv_blob_push_string(mem_ctx, blob,
722 68 + ofs, 70 + ofs,
723 file->both_directory_info.short_name.s,
724 24, default_str_flags,
725 STR_UNICODE | STR_LEN8BIT);
726 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob, file->both_directory_info.name.s,
727 ofs + 60, default_str_flags,
728 STR_TERMINATE_ASCII));
729 BLOB_ALIGN(blob, 8);
730 data = blob->data + ofs;
731 SIVAL(data, 0, blob->length - ofs);
732 return NT_STATUS_OK;
734 case RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO:
735 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, ofs + 80));
736 data = blob->data + ofs;
737 SIVAL(data, 4, file->id_full_directory_info.file_index);
738 push_nttime(data, 8, file->id_full_directory_info.create_time);
739 push_nttime(data, 16, file->id_full_directory_info.access_time);
740 push_nttime(data, 24, file->id_full_directory_info.write_time);
741 push_nttime(data, 32, file->id_full_directory_info.change_time);
742 SBVAL(data, 40, file->id_full_directory_info.size);
743 SBVAL(data, 48, file->id_full_directory_info.alloc_size);
744 SIVAL(data, 56, file->id_full_directory_info.attrib);
745 SIVAL(data, 64, file->id_full_directory_info.ea_size);
746 SIVAL(data, 68, 0); /* padding */
747 SBVAL(data, 72, file->id_full_directory_info.file_id);
748 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob, file->id_full_directory_info.name.s,
749 ofs + 60, default_str_flags,
750 STR_TERMINATE_ASCII));
751 BLOB_ALIGN(blob, 8);
752 data = blob->data + ofs;
753 SIVAL(data, 0, blob->length - ofs);
754 return NT_STATUS_OK;
756 case RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO:
757 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, ofs + 104));
758 data = blob->data + ofs;
759 SIVAL(data, 4, file->id_both_directory_info.file_index);
760 push_nttime(data, 8, file->id_both_directory_info.create_time);
761 push_nttime(data, 16, file->id_both_directory_info.access_time);
762 push_nttime(data, 24, file->id_both_directory_info.write_time);
763 push_nttime(data, 32, file->id_both_directory_info.change_time);
764 SBVAL(data, 40, file->id_both_directory_info.size);
765 SBVAL(data, 48, file->id_both_directory_info.alloc_size);
766 SIVAL(data, 56, file->id_both_directory_info.attrib);
767 SIVAL(data, 64, file->id_both_directory_info.ea_size);
768 SCVAL(data, 69, 0); /* reserved */
769 memset(data+70,0,26);
770 smbsrv_blob_push_string(mem_ctx, blob,
771 68 + ofs, 70 + ofs,
772 file->id_both_directory_info.short_name.s,
773 24, default_str_flags,
774 STR_UNICODE | STR_LEN8BIT);
775 SBVAL(data, 96, file->id_both_directory_info.file_id);
776 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob, file->id_both_directory_info.name.s,
777 ofs + 60, default_str_flags,
778 STR_TERMINATE_ASCII));
779 BLOB_ALIGN(blob, 8);
780 data = blob->data + ofs;
781 SIVAL(data, 0, blob->length - ofs);
782 return NT_STATUS_OK;
784 default:
785 return NT_STATUS_INVALID_LEVEL;
788 return NT_STATUS_INVALID_LEVEL;