lib/util: add nsec_time_diff to calulate diffs from timespecs
[Samba/gebeck_regimport.git] / source4 / smb_server / blob.c
blobadc223ec7d832c5e35f261c9fe69697ae3beecfa
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;
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 unsigned int 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, 4);
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, 4);
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 SIVAL(blob->data, 0x58, st->all_info2.out.mode);
500 SIVAL(blob->data, 0x5C, st->all_info2.out.alignment_requirement);
501 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob,
502 st->all_info2.out.fname.s,
503 0x60, default_str_flags,
504 STR_UNICODE));
505 return NT_STATUS_OK;
507 default:
508 return NT_STATUS_INVALID_LEVEL;
512 NTSTATUS smbsrv_pull_passthru_sfileinfo(TALLOC_CTX *mem_ctx,
513 enum smb_setfileinfo_level level,
514 union smb_setfileinfo *st,
515 const DATA_BLOB *blob,
516 int default_str_flags,
517 struct request_bufinfo *bufinfo)
519 uint32_t len, ofs;
520 DATA_BLOB str_blob;
522 switch (level) {
523 case SMB_SFILEINFO_BASIC_INFORMATION:
524 BLOB_CHECK_MIN_SIZE(blob, 40);
526 st->basic_info.in.create_time = pull_nttime(blob->data, 0);
527 st->basic_info.in.access_time = pull_nttime(blob->data, 8);
528 st->basic_info.in.write_time = pull_nttime(blob->data, 16);
529 st->basic_info.in.change_time = pull_nttime(blob->data, 24);
530 st->basic_info.in.attrib = IVAL(blob->data, 32);
531 st->basic_info.in.reserved = IVAL(blob->data, 36);
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 (!bufinfo) {
558 return NT_STATUS_INTERNAL_ERROR;
560 BLOB_CHECK_MIN_SIZE(blob, 12);
561 st->rename_information.in.overwrite = CVAL(blob->data, 0);
562 st->rename_information.in.root_fid = IVAL(blob->data, 4);
563 len = IVAL(blob->data, 8);
564 ofs = 12;
565 str_blob = *blob;
566 str_blob.length = MIN(str_blob.length, ofs+len);
567 smbsrv_blob_pull_string(bufinfo, &str_blob, ofs,
568 &st->rename_information.in.new_name,
569 STR_UNICODE);
570 if (st->rename_information.in.new_name == NULL) {
571 return NT_STATUS_FOOBAR;
574 return NT_STATUS_OK;
577 case RAW_SFILEINFO_LINK_INFORMATION:
578 if (!bufinfo) {
579 return NT_STATUS_INTERNAL_ERROR;
581 BLOB_CHECK_MIN_SIZE(blob, 20);
582 st->link_information.in.overwrite = CVAL(blob->data, 0);
583 st->link_information.in.root_fid = IVAL(blob->data, 8);
584 len = IVAL(blob->data, 16);
585 ofs = 20;
586 str_blob = *blob;
587 str_blob.length = MIN(str_blob.length, ofs+len);
588 smbsrv_blob_pull_string(bufinfo, &str_blob, ofs,
589 &st->link_information.in.new_name,
590 STR_UNICODE);
591 if (st->link_information.in.new_name == NULL) {
592 return NT_STATUS_FOOBAR;
595 return NT_STATUS_OK;
597 case RAW_SFILEINFO_RENAME_INFORMATION_SMB2:
598 /* SMB2 uses a different format for rename information */
599 if (!bufinfo) {
600 return NT_STATUS_INTERNAL_ERROR;
602 BLOB_CHECK_MIN_SIZE(blob, 20);
603 st->rename_information.in.overwrite = CVAL(blob->data, 0);
604 st->rename_information.in.root_fid = BVAL(blob->data, 8);
605 len = IVAL(blob->data,16);
606 ofs = 20;
607 str_blob = *blob;
608 str_blob.length = MIN(str_blob.length, ofs+len);
609 smbsrv_blob_pull_string(bufinfo, &str_blob, ofs,
610 &st->rename_information.in.new_name,
611 STR_UNICODE);
612 if (st->rename_information.in.new_name == NULL) {
613 return NT_STATUS_FOOBAR;
616 return NT_STATUS_OK;
618 case RAW_SFILEINFO_POSITION_INFORMATION:
619 BLOB_CHECK_MIN_SIZE(blob, 8);
621 st->position_information.in.position = BVAL(blob->data, 0);
623 return NT_STATUS_OK;
625 case RAW_SFILEINFO_MODE_INFORMATION:
626 BLOB_CHECK_MIN_SIZE(blob, 4);
628 st->mode_information.in.mode = IVAL(blob->data, 0);
630 return NT_STATUS_OK;
632 default:
633 return NT_STATUS_INVALID_LEVEL;
638 fill a single entry in a trans2 find reply
640 NTSTATUS smbsrv_push_passthru_search(TALLOC_CTX *mem_ctx,
641 DATA_BLOB *blob,
642 enum smb_search_data_level level,
643 const union smb_search_data *file,
644 int default_str_flags)
646 uint8_t *data;
647 unsigned int ofs = blob->length;
649 switch (level) {
650 case RAW_SEARCH_DATA_DIRECTORY_INFO:
651 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, ofs + 64));
652 data = blob->data + ofs;
653 SIVAL(data, 4, file->directory_info.file_index);
654 push_nttime(data, 8, file->directory_info.create_time);
655 push_nttime(data, 16, file->directory_info.access_time);
656 push_nttime(data, 24, file->directory_info.write_time);
657 push_nttime(data, 32, file->directory_info.change_time);
658 SBVAL(data, 40, file->directory_info.size);
659 SBVAL(data, 48, file->directory_info.alloc_size);
660 SIVAL(data, 56, file->directory_info.attrib);
661 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob, file->directory_info.name.s,
662 ofs + 60, default_str_flags,
663 STR_TERMINATE_ASCII));
664 BLOB_ALIGN(blob, 8);
665 data = blob->data + ofs;
666 SIVAL(data, 0, blob->length - ofs);
667 return NT_STATUS_OK;
669 case RAW_SEARCH_DATA_FULL_DIRECTORY_INFO:
670 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, ofs + 68));
671 data = blob->data + ofs;
672 SIVAL(data, 4, file->full_directory_info.file_index);
673 push_nttime(data, 8, file->full_directory_info.create_time);
674 push_nttime(data, 16, file->full_directory_info.access_time);
675 push_nttime(data, 24, file->full_directory_info.write_time);
676 push_nttime(data, 32, file->full_directory_info.change_time);
677 SBVAL(data, 40, file->full_directory_info.size);
678 SBVAL(data, 48, file->full_directory_info.alloc_size);
679 SIVAL(data, 56, file->full_directory_info.attrib);
680 SIVAL(data, 64, file->full_directory_info.ea_size);
681 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob, file->full_directory_info.name.s,
682 ofs + 60, default_str_flags,
683 STR_TERMINATE_ASCII));
684 BLOB_ALIGN(blob, 8);
685 data = blob->data + ofs;
686 SIVAL(data, 0, blob->length - ofs);
687 return NT_STATUS_OK;
689 case RAW_SEARCH_DATA_NAME_INFO:
690 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, ofs + 12));
691 data = blob->data + ofs;
692 SIVAL(data, 4, file->name_info.file_index);
693 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob, file->name_info.name.s,
694 ofs + 8, default_str_flags,
695 STR_TERMINATE_ASCII));
696 BLOB_ALIGN(blob, 8);
697 data = blob->data + ofs;
698 SIVAL(data, 0, blob->length - ofs);
699 return NT_STATUS_OK;
701 case RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO:
702 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, ofs + 94));
703 data = blob->data + ofs;
704 SIVAL(data, 4, file->both_directory_info.file_index);
705 push_nttime(data, 8, file->both_directory_info.create_time);
706 push_nttime(data, 16, file->both_directory_info.access_time);
707 push_nttime(data, 24, file->both_directory_info.write_time);
708 push_nttime(data, 32, file->both_directory_info.change_time);
709 SBVAL(data, 40, file->both_directory_info.size);
710 SBVAL(data, 48, file->both_directory_info.alloc_size);
711 SIVAL(data, 56, file->both_directory_info.attrib);
712 SIVAL(data, 64, file->both_directory_info.ea_size);
713 SCVAL(data, 69, 0); /* reserved */
714 memset(data+70,0,24);
715 smbsrv_blob_push_string(mem_ctx, blob,
716 68 + ofs, 70 + ofs,
717 file->both_directory_info.short_name.s,
718 24, default_str_flags,
719 STR_UNICODE | STR_LEN8BIT);
720 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob, file->both_directory_info.name.s,
721 ofs + 60, default_str_flags,
722 STR_TERMINATE_ASCII));
723 BLOB_ALIGN(blob, 8);
724 data = blob->data + ofs;
725 SIVAL(data, 0, blob->length - ofs);
726 return NT_STATUS_OK;
728 case RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO:
729 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, ofs + 80));
730 data = blob->data + ofs;
731 SIVAL(data, 4, file->id_full_directory_info.file_index);
732 push_nttime(data, 8, file->id_full_directory_info.create_time);
733 push_nttime(data, 16, file->id_full_directory_info.access_time);
734 push_nttime(data, 24, file->id_full_directory_info.write_time);
735 push_nttime(data, 32, file->id_full_directory_info.change_time);
736 SBVAL(data, 40, file->id_full_directory_info.size);
737 SBVAL(data, 48, file->id_full_directory_info.alloc_size);
738 SIVAL(data, 56, file->id_full_directory_info.attrib);
739 SIVAL(data, 64, file->id_full_directory_info.ea_size);
740 SIVAL(data, 68, 0); /* padding */
741 SBVAL(data, 72, file->id_full_directory_info.file_id);
742 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob, file->id_full_directory_info.name.s,
743 ofs + 60, default_str_flags,
744 STR_TERMINATE_ASCII));
745 BLOB_ALIGN(blob, 8);
746 data = blob->data + ofs;
747 SIVAL(data, 0, blob->length - ofs);
748 return NT_STATUS_OK;
750 case RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO:
751 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, ofs + 104));
752 data = blob->data + ofs;
753 SIVAL(data, 4, file->id_both_directory_info.file_index);
754 push_nttime(data, 8, file->id_both_directory_info.create_time);
755 push_nttime(data, 16, file->id_both_directory_info.access_time);
756 push_nttime(data, 24, file->id_both_directory_info.write_time);
757 push_nttime(data, 32, file->id_both_directory_info.change_time);
758 SBVAL(data, 40, file->id_both_directory_info.size);
759 SBVAL(data, 48, file->id_both_directory_info.alloc_size);
760 SIVAL(data, 56, file->id_both_directory_info.attrib);
761 SIVAL(data, 64, file->id_both_directory_info.ea_size);
762 SCVAL(data, 69, 0); /* reserved */
763 memset(data+70,0,26);
764 smbsrv_blob_push_string(mem_ctx, blob,
765 68 + ofs, 70 + ofs,
766 file->id_both_directory_info.short_name.s,
767 24, default_str_flags,
768 STR_UNICODE | STR_LEN8BIT);
769 SBVAL(data, 96, file->id_both_directory_info.file_id);
770 BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob, file->id_both_directory_info.name.s,
771 ofs + 60, default_str_flags,
772 STR_TERMINATE_ASCII));
773 BLOB_ALIGN(blob, 8);
774 data = blob->data + ofs;
775 SIVAL(data, 0, blob->length - ofs);
776 return NT_STATUS_OK;
778 default:
779 return NT_STATUS_INVALID_LEVEL;