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/>.
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 { \
32 NT_STATUS_NOT_OK_RETURN(_status); \
35 #define BLOB_CHECK_MIN_SIZE(blob, size) do { \
36 if ((blob)->length < (size)) { \
37 return NT_STATUS_INVALID_PARAMETER; \
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)); \
50 /* grow the data size of a trans2 reply */
51 NTSTATUS
smbsrv_blob_grow_data(TALLOC_CTX
*mem_ctx
,
55 if (new_size
> blob
->length
) {
57 p
= talloc_realloc(mem_ctx
, blob
->data
, uint8_t, new_size
);
58 NT_STATUS_HAVE_NO_MEMORY(p
);
61 blob
->length
= new_size
;
65 /* grow the data, zero filling any new bytes */
66 NTSTATUS
smbsrv_blob_fill_data(TALLOC_CTX
*mem_ctx
,
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
);
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
,
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
91 if (offset
>= blob
->length
) {
95 return req_pull_string(bufinfo
, str
,
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
,
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
119 if (!str
|| offset
>= blob
->length
) {
120 if (flags
& STR_LEN8BIT
) {
121 SCVAL(blob
->data
, len_offset
, 0);
123 SIVAL(blob
->data
, len_offset
, 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
)) {
141 SCVAL(blob
->data
+ offset
, 0, 0);
142 ret
= push_string(blob
->data
+ offset
+ 1, str
, dest_len
-1, flags
);
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! */
152 if ((flags
& STR_LEN_NOTERM
) && (flags
& STR_TERMINATE
)) {
153 if ((flags
& STR_UNICODE
) && ret
>= 2) {
156 if ((flags
& STR_ASCII
) && ret
>= 1) {
161 if (flags
& STR_LEN8BIT
) {
162 SCVAL(blob
->data
, len_offset
, pkt_len
);
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
175 NTSTATUS
smbsrv_blob_append_string(TALLOC_CTX
*mem_ctx
,
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
);
190 return NT_STATUS_FOOBAR
;
192 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx
, blob
, offset
+ ret
));
196 NTSTATUS
smbsrv_push_passthru_fsinfo(TALLOC_CTX
*mem_ctx
,
198 enum smb_fsinfo_level level
,
199 union smb_fsinfo
*fsinfo
,
200 int default_str_flags
)
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
,
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
);
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
);
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
,
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
);
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
);
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
);
291 SBVAL(blob
->data
, 16 + 8*i
, fsinfo
->objectid_information
.out
.unknown
[i
]);
297 return NT_STATUS_INVALID_LEVEL
;
300 return NT_STATUS_INVALID_LEVEL
;
303 NTSTATUS
smbsrv_push_passthru_fileinfo(TALLOC_CTX
*mem_ctx
,
305 enum smb_fileinfo_level level
,
306 union smb_fileinfo
*st
,
307 int default_str_flags
)
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 */
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 */
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 */
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
);
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
);
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
);
367 case RAW_FILEINFO_ALIGNMENT_INFORMATION
:
368 BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx
, blob
, 4));
371 st
->alignment_information
.out
.alignment_requirement
);
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
);
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
);
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);
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
);
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
,
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
,
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
,
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
;
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
,
457 if (i
== st
->stream_info
.out
.num_streams
- 1) {
458 SIVAL(blob
->data
, data_size
, 0);
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
);
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);
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
,
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
)
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);
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);
550 case SMB_SFILEINFO_ALLOCATION_INFORMATION
:
551 BLOB_CHECK_MIN_SIZE(blob
, 8);
553 st
->allocation_info
.in
.alloc_size
= BVAL(blob
->data
, 0);
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);
564 case RAW_SFILEINFO_RENAME_INFORMATION
:
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);
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
,
578 if (st
->rename_information
.in
.new_name
== NULL
) {
579 return NT_STATUS_FOOBAR
;
585 case RAW_SFILEINFO_LINK_INFORMATION
:
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);
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
,
599 if (st
->link_information
.in
.new_name
== NULL
) {
600 return NT_STATUS_FOOBAR
;
605 case RAW_SFILEINFO_RENAME_INFORMATION_SMB2
:
606 /* SMB2 uses a different format for rename information */
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);
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
,
620 if (st
->rename_information
.in
.new_name
== NULL
) {
621 return NT_STATUS_FOOBAR
;
626 case RAW_SFILEINFO_POSITION_INFORMATION
:
627 BLOB_CHECK_MIN_SIZE(blob
, 8);
629 st
->position_information
.in
.position
= BVAL(blob
->data
, 0);
633 case RAW_SFILEINFO_MODE_INFORMATION
:
634 BLOB_CHECK_MIN_SIZE(blob
, 4);
636 st
->mode_information
.in
.mode
= IVAL(blob
->data
, 0);
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
,
652 enum smb_search_data_level level
,
653 const union smb_search_data
*file
,
654 int default_str_flags
)
657 uint_t ofs
= blob
->length
;
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
));
675 data
= blob
->data
+ ofs
;
676 SIVAL(data
, 0, blob
->length
- ofs
);
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
));
695 data
= blob
->data
+ ofs
;
696 SIVAL(data
, 0, blob
->length
- ofs
);
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
));
707 data
= blob
->data
+ ofs
;
708 SIVAL(data
, 0, blob
->length
- ofs
);
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
,
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
));
734 data
= blob
->data
+ ofs
;
735 SIVAL(data
, 0, blob
->length
- ofs
);
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
));
756 data
= blob
->data
+ ofs
;
757 SIVAL(data
, 0, blob
->length
- ofs
);
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
,
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
));
784 data
= blob
->data
+ ofs
;
785 SIVAL(data
, 0, blob
->length
- ofs
);
789 return NT_STATUS_INVALID_LEVEL
;
792 return NT_STATUS_INVALID_LEVEL
;