2 Unix SMB/CIFS implementation.
3 SMB transaction2 handling
4 Copyright (C) Jeremy Allison 1994-2007
5 Copyright (C) Stefan (metze) Metzmacher 2003
6 Copyright (C) Volker Lendecke 2005-2007
7 Copyright (C) Steve French 2005
8 Copyright (C) James Peach 2006-2007
10 Extensively modified by Andrew Tridgell, 1995
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 3 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program. If not, see <http://www.gnu.org/licenses/>.
27 #include "system/filesys.h"
29 #include "smbd/smbd.h"
30 #include "smbd/globals.h"
31 #include "../libcli/auth/libcli_auth.h"
32 #include "../librpc/gen_ndr/xattr.h"
33 #include "../librpc/gen_ndr/ndr_security.h"
34 #include "libcli/security/security.h"
37 #include "smbprofile.h"
39 #define DIR_ENTRY_SAFETY_MARGIN 4096
41 static char *store_file_unix_basic(connection_struct
*conn
,
44 const SMB_STRUCT_STAT
*psbuf
);
46 static char *store_file_unix_basic_info2(connection_struct
*conn
,
49 const SMB_STRUCT_STAT
*psbuf
);
51 /********************************************************************
52 Roundup a value to the nearest allocation roundup size boundary.
53 Only do this for Windows clients.
54 ********************************************************************/
56 uint64_t smb_roundup(connection_struct
*conn
, uint64_t val
)
58 uint64_t rval
= lp_allocation_roundup_size(SNUM(conn
));
60 /* Only roundup for Windows clients. */
61 enum remote_arch_types ra_type
= get_remote_arch();
62 if (rval
&& (ra_type
!= RA_SAMBA
) && (ra_type
!= RA_CIFSFS
)) {
63 val
= SMB_ROUNDUP(val
,rval
);
68 /********************************************************************
69 Create a 64 bit FileIndex. If the file is on the same device as
70 the root of the share, just return the 64-bit inode. If it isn't,
71 mangle as we used to do.
72 ********************************************************************/
74 uint64_t get_FileIndex(connection_struct
*conn
, const SMB_STRUCT_STAT
*psbuf
)
77 if (conn
->base_share_dev
== psbuf
->st_ex_dev
) {
78 return (uint64_t)psbuf
->st_ex_ino
;
80 file_index
= ((psbuf
->st_ex_ino
) & UINT32_MAX
); /* FileIndexLow */
81 file_index
|= ((uint64_t)((psbuf
->st_ex_dev
) & UINT32_MAX
)) << 32; /* FileIndexHigh */
85 /****************************************************************************
86 Utility functions for dealing with extended attributes.
87 ****************************************************************************/
89 /****************************************************************************
90 Refuse to allow clients to overwrite our private xattrs.
91 ****************************************************************************/
93 static bool samba_private_attr_name(const char *unix_ea_name
)
95 static const char * const prohibited_ea_names
[] = {
96 SAMBA_POSIX_INHERITANCE_EA_NAME
,
97 SAMBA_XATTR_DOS_ATTRIB
,
105 for (i
= 0; prohibited_ea_names
[i
]; i
++) {
106 if (strequal( prohibited_ea_names
[i
], unix_ea_name
))
109 if (StrnCaseCmp(unix_ea_name
, SAMBA_XATTR_DOSSTREAM_PREFIX
,
110 strlen(SAMBA_XATTR_DOSSTREAM_PREFIX
)) == 0) {
116 /****************************************************************************
117 Get one EA value. Fill in a struct ea_struct.
118 ****************************************************************************/
120 NTSTATUS
get_ea_value(TALLOC_CTX
*mem_ctx
, connection_struct
*conn
,
121 files_struct
*fsp
, const char *fname
,
122 const char *ea_name
, struct ea_struct
*pea
)
124 /* Get the value of this xattr. Max size is 64k. */
125 size_t attr_size
= 256;
131 val
= TALLOC_REALLOC_ARRAY(mem_ctx
, val
, char, attr_size
);
133 return NT_STATUS_NO_MEMORY
;
136 if (fsp
&& fsp
->fh
->fd
!= -1) {
137 sizeret
= SMB_VFS_FGETXATTR(fsp
, ea_name
, val
, attr_size
);
139 sizeret
= SMB_VFS_GETXATTR(conn
, fname
, ea_name
, val
, attr_size
);
142 if (sizeret
== -1 && errno
== ERANGE
&& attr_size
!= 65536) {
148 return map_nt_error_from_unix(errno
);
151 DEBUG(10,("get_ea_value: EA %s is of length %u\n", ea_name
, (unsigned int)sizeret
));
152 dump_data(10, (uint8
*)val
, sizeret
);
155 if (strnequal(ea_name
, "user.", 5)) {
156 pea
->name
= talloc_strdup(mem_ctx
, &ea_name
[5]);
158 pea
->name
= talloc_strdup(mem_ctx
, ea_name
);
160 if (pea
->name
== NULL
) {
162 return NT_STATUS_NO_MEMORY
;
164 pea
->value
.data
= (unsigned char *)val
;
165 pea
->value
.length
= (size_t)sizeret
;
169 NTSTATUS
get_ea_names_from_file(TALLOC_CTX
*mem_ctx
, connection_struct
*conn
,
170 files_struct
*fsp
, const char *fname
,
171 char ***pnames
, size_t *pnum_names
)
173 /* Get a list of all xattrs. Max namesize is 64k. */
174 size_t ea_namelist_size
= 1024;
175 char *ea_namelist
= NULL
;
180 ssize_t sizeret
= -1;
182 if (!lp_ea_support(SNUM(conn
))) {
191 * TALLOC the result early to get the talloc hierarchy right.
194 names
= TALLOC_ARRAY(mem_ctx
, char *, 1);
196 DEBUG(0, ("talloc failed\n"));
197 return NT_STATUS_NO_MEMORY
;
200 while (ea_namelist_size
<= 65536) {
202 ea_namelist
= TALLOC_REALLOC_ARRAY(
203 names
, ea_namelist
, char, ea_namelist_size
);
204 if (ea_namelist
== NULL
) {
205 DEBUG(0, ("talloc failed\n"));
207 return NT_STATUS_NO_MEMORY
;
210 if (fsp
&& fsp
->fh
->fd
!= -1) {
211 sizeret
= SMB_VFS_FLISTXATTR(fsp
, ea_namelist
,
214 sizeret
= SMB_VFS_LISTXATTR(conn
, fname
, ea_namelist
,
218 if ((sizeret
== -1) && (errno
== ERANGE
)) {
219 ea_namelist_size
*= 2;
228 return map_nt_error_from_unix(errno
);
231 DEBUG(10, ("get_ea_list_from_file: ea_namelist size = %u\n",
232 (unsigned int)sizeret
));
244 * Ensure the result is 0-terminated
247 if (ea_namelist
[sizeret
-1] != '\0') {
249 return NT_STATUS_INTERNAL_ERROR
;
257 for (p
= ea_namelist
; p
- ea_namelist
< sizeret
; p
+= strlen(p
)+1) {
261 tmp
= TALLOC_REALLOC_ARRAY(mem_ctx
, names
, char *, num_names
);
263 DEBUG(0, ("talloc failed\n"));
265 return NT_STATUS_NO_MEMORY
;
271 for (p
= ea_namelist
; p
- ea_namelist
< sizeret
; p
+= strlen(p
)+1) {
272 names
[num_names
++] = p
;
280 *pnum_names
= num_names
;
284 /****************************************************************************
285 Return a linked list of the total EA's. Plus the total size
286 ****************************************************************************/
288 static struct ea_list
*get_ea_list_from_file(TALLOC_CTX
*mem_ctx
, connection_struct
*conn
, files_struct
*fsp
,
289 const char *fname
, size_t *pea_total_len
)
291 /* Get a list of all xattrs. Max namesize is 64k. */
294 struct ea_list
*ea_list_head
= NULL
;
299 if (!lp_ea_support(SNUM(conn
))) {
303 status
= get_ea_names_from_file(talloc_tos(), conn
, fsp
, fname
,
306 if (!NT_STATUS_IS_OK(status
) || (num_names
== 0)) {
310 for (i
=0; i
<num_names
; i
++) {
311 struct ea_list
*listp
;
314 if (strnequal(names
[i
], "system.", 7)
315 || samba_private_attr_name(names
[i
]))
318 listp
= TALLOC_P(mem_ctx
, struct ea_list
);
323 if (!NT_STATUS_IS_OK(get_ea_value(mem_ctx
, conn
, fsp
,
329 push_ascii_fstring(dos_ea_name
, listp
->ea
.name
);
332 4 + strlen(dos_ea_name
) + 1 + listp
->ea
.value
.length
;
334 DEBUG(10,("get_ea_list_from_file: total_len = %u, %s, val len "
335 "= %u\n", (unsigned int)*pea_total_len
, dos_ea_name
,
336 (unsigned int)listp
->ea
.value
.length
));
338 DLIST_ADD_END(ea_list_head
, listp
, struct ea_list
*);
342 /* Add on 4 for total length. */
343 if (*pea_total_len
) {
347 DEBUG(10, ("get_ea_list_from_file: total_len = %u\n",
348 (unsigned int)*pea_total_len
));
353 /****************************************************************************
354 Fill a qfilepathinfo buffer with EA's. Returns the length of the buffer
356 ****************************************************************************/
358 static unsigned int fill_ea_buffer(TALLOC_CTX
*mem_ctx
, char *pdata
, unsigned int total_data_size
,
359 connection_struct
*conn
, struct ea_list
*ea_list
)
361 unsigned int ret_data_size
= 4;
364 SMB_ASSERT(total_data_size
>= 4);
366 if (!lp_ea_support(SNUM(conn
))) {
371 for (p
= pdata
+ 4; ea_list
; ea_list
= ea_list
->next
) {
374 push_ascii_fstring(dos_ea_name
, ea_list
->ea
.name
);
375 dos_namelen
= strlen(dos_ea_name
);
376 if (dos_namelen
> 255 || dos_namelen
== 0) {
379 if (ea_list
->ea
.value
.length
> 65535) {
382 if (4 + dos_namelen
+ 1 + ea_list
->ea
.value
.length
> total_data_size
) {
386 /* We know we have room. */
387 SCVAL(p
,0,ea_list
->ea
.flags
);
388 SCVAL(p
,1,dos_namelen
);
389 SSVAL(p
,2,ea_list
->ea
.value
.length
);
390 fstrcpy(p
+4, dos_ea_name
);
391 memcpy( p
+ 4 + dos_namelen
+ 1, ea_list
->ea
.value
.data
, ea_list
->ea
.value
.length
);
393 total_data_size
-= 4 + dos_namelen
+ 1 + ea_list
->ea
.value
.length
;
394 p
+= 4 + dos_namelen
+ 1 + ea_list
->ea
.value
.length
;
397 ret_data_size
= PTR_DIFF(p
, pdata
);
398 DEBUG(10,("fill_ea_buffer: data_size = %u\n", ret_data_size
));
399 SIVAL(pdata
,0,ret_data_size
);
400 return ret_data_size
;
403 static NTSTATUS
fill_ea_chained_buffer(TALLOC_CTX
*mem_ctx
,
405 unsigned int total_data_size
,
406 unsigned int *ret_data_size
,
407 connection_struct
*conn
,
408 struct ea_list
*ea_list
)
410 uint8_t *p
= (uint8_t *)pdata
;
411 uint8_t *last_start
= NULL
;
415 if (!lp_ea_support(SNUM(conn
))) {
416 return NT_STATUS_NO_EAS_ON_FILE
;
419 for (; ea_list
; ea_list
= ea_list
->next
) {
425 SIVAL(last_start
, 0, PTR_DIFF(p
, last_start
));
429 push_ascii_fstring(dos_ea_name
, ea_list
->ea
.name
);
430 dos_namelen
= strlen(dos_ea_name
);
431 if (dos_namelen
> 255 || dos_namelen
== 0) {
432 return NT_STATUS_INTERNAL_ERROR
;
434 if (ea_list
->ea
.value
.length
> 65535) {
435 return NT_STATUS_INTERNAL_ERROR
;
438 this_size
= 0x08 + dos_namelen
+ 1 + ea_list
->ea
.value
.length
;
441 size_t pad
= 4 - (this_size
% 4);
445 if (this_size
> total_data_size
) {
446 return NT_STATUS_INFO_LENGTH_MISMATCH
;
449 /* We know we have room. */
450 SIVAL(p
, 0x00, 0); /* next offset */
451 SCVAL(p
, 0x04, ea_list
->ea
.flags
);
452 SCVAL(p
, 0x05, dos_namelen
);
453 SSVAL(p
, 0x06, ea_list
->ea
.value
.length
);
454 fstrcpy((char *)(p
+0x08), dos_ea_name
);
455 memcpy(p
+ 0x08 + dos_namelen
+ 1, ea_list
->ea
.value
.data
, ea_list
->ea
.value
.length
);
457 total_data_size
-= this_size
;
461 *ret_data_size
= PTR_DIFF(p
, pdata
);
462 DEBUG(10,("fill_ea_chained_buffer: data_size = %u\n", *ret_data_size
));
466 static unsigned int estimate_ea_size(connection_struct
*conn
, files_struct
*fsp
, const char *fname
)
468 size_t total_ea_len
= 0;
469 TALLOC_CTX
*mem_ctx
= NULL
;
471 if (!lp_ea_support(SNUM(conn
))) {
474 mem_ctx
= talloc_tos();
475 (void)get_ea_list_from_file(mem_ctx
, conn
, fsp
, fname
, &total_ea_len
);
479 /****************************************************************************
480 Ensure the EA name is case insensitive by matching any existing EA name.
481 ****************************************************************************/
483 static void canonicalize_ea_name(connection_struct
*conn
, files_struct
*fsp
, const char *fname
, fstring unix_ea_name
)
486 TALLOC_CTX
*mem_ctx
= talloc_tos();
487 struct ea_list
*ea_list
= get_ea_list_from_file(mem_ctx
, conn
, fsp
, fname
, &total_ea_len
);
489 for (; ea_list
; ea_list
= ea_list
->next
) {
490 if (strequal(&unix_ea_name
[5], ea_list
->ea
.name
)) {
491 DEBUG(10,("canonicalize_ea_name: %s -> %s\n",
492 &unix_ea_name
[5], ea_list
->ea
.name
));
493 safe_strcpy(&unix_ea_name
[5], ea_list
->ea
.name
, sizeof(fstring
)-6);
499 /****************************************************************************
500 Set or delete an extended attribute.
501 ****************************************************************************/
503 NTSTATUS
set_ea(connection_struct
*conn
, files_struct
*fsp
,
504 const struct smb_filename
*smb_fname
, struct ea_list
*ea_list
)
508 if (!lp_ea_support(SNUM(conn
))) {
509 return NT_STATUS_EAS_NOT_SUPPORTED
;
512 if (fsp
&& !(fsp
->access_mask
& FILE_WRITE_EA
)) {
513 return NT_STATUS_ACCESS_DENIED
;
516 /* For now setting EAs on streams isn't supported. */
517 fname
= smb_fname
->base_name
;
519 for (;ea_list
; ea_list
= ea_list
->next
) {
521 fstring unix_ea_name
;
523 fstrcpy(unix_ea_name
, "user."); /* All EA's must start with user. */
524 fstrcat(unix_ea_name
, ea_list
->ea
.name
);
526 canonicalize_ea_name(conn
, fsp
, fname
, unix_ea_name
);
528 DEBUG(10,("set_ea: ea_name %s ealen = %u\n", unix_ea_name
, (unsigned int)ea_list
->ea
.value
.length
));
530 if (samba_private_attr_name(unix_ea_name
)) {
531 DEBUG(10,("set_ea: ea name %s is a private Samba name.\n", unix_ea_name
));
532 return NT_STATUS_ACCESS_DENIED
;
535 if (ea_list
->ea
.value
.length
== 0) {
536 /* Remove the attribute. */
537 if (fsp
&& (fsp
->fh
->fd
!= -1)) {
538 DEBUG(10,("set_ea: deleting ea name %s on "
539 "file %s by file descriptor.\n",
540 unix_ea_name
, fsp_str_dbg(fsp
)));
541 ret
= SMB_VFS_FREMOVEXATTR(fsp
, unix_ea_name
);
543 DEBUG(10,("set_ea: deleting ea name %s on file %s.\n",
544 unix_ea_name
, fname
));
545 ret
= SMB_VFS_REMOVEXATTR(conn
, fname
, unix_ea_name
);
548 /* Removing a non existent attribute always succeeds. */
549 if (ret
== -1 && errno
== ENOATTR
) {
550 DEBUG(10,("set_ea: deleting ea name %s didn't exist - succeeding by default.\n",
556 if (fsp
&& (fsp
->fh
->fd
!= -1)) {
557 DEBUG(10,("set_ea: setting ea name %s on file "
558 "%s by file descriptor.\n",
559 unix_ea_name
, fsp_str_dbg(fsp
)));
560 ret
= SMB_VFS_FSETXATTR(fsp
, unix_ea_name
,
561 ea_list
->ea
.value
.data
, ea_list
->ea
.value
.length
, 0);
563 DEBUG(10,("set_ea: setting ea name %s on file %s.\n",
564 unix_ea_name
, fname
));
565 ret
= SMB_VFS_SETXATTR(conn
, fname
, unix_ea_name
,
566 ea_list
->ea
.value
.data
, ea_list
->ea
.value
.length
, 0);
572 if (errno
== ENOTSUP
) {
573 return NT_STATUS_EAS_NOT_SUPPORTED
;
576 return map_nt_error_from_unix(errno
);
582 /****************************************************************************
583 Read a list of EA names from an incoming data buffer. Create an ea_list with them.
584 ****************************************************************************/
586 static struct ea_list
*read_ea_name_list(TALLOC_CTX
*ctx
, const char *pdata
, size_t data_size
)
588 struct ea_list
*ea_list_head
= NULL
;
589 size_t converted_size
, offset
= 0;
591 while (offset
+ 2 < data_size
) {
592 struct ea_list
*eal
= TALLOC_ZERO_P(ctx
, struct ea_list
);
593 unsigned int namelen
= CVAL(pdata
,offset
);
595 offset
++; /* Go past the namelen byte. */
597 /* integer wrap paranioa. */
598 if ((offset
+ namelen
< offset
) || (offset
+ namelen
< namelen
) ||
599 (offset
> data_size
) || (namelen
> data_size
) ||
600 (offset
+ namelen
>= data_size
)) {
603 /* Ensure the name is null terminated. */
604 if (pdata
[offset
+ namelen
] != '\0') {
607 if (!pull_ascii_talloc(ctx
, &eal
->ea
.name
, &pdata
[offset
],
609 DEBUG(0,("read_ea_name_list: pull_ascii_talloc "
610 "failed: %s", strerror(errno
)));
616 offset
+= (namelen
+ 1); /* Go past the name + terminating zero. */
617 DLIST_ADD_END(ea_list_head
, eal
, struct ea_list
*);
618 DEBUG(10,("read_ea_name_list: read ea name %s\n", eal
->ea
.name
));
624 /****************************************************************************
625 Read one EA list entry from the buffer.
626 ****************************************************************************/
628 struct ea_list
*read_ea_list_entry(TALLOC_CTX
*ctx
, const char *pdata
, size_t data_size
, size_t *pbytes_used
)
630 struct ea_list
*eal
= TALLOC_ZERO_P(ctx
, struct ea_list
);
632 unsigned int namelen
;
633 size_t converted_size
;
643 eal
->ea
.flags
= CVAL(pdata
,0);
644 namelen
= CVAL(pdata
,1);
645 val_len
= SVAL(pdata
,2);
647 if (4 + namelen
+ 1 + val_len
> data_size
) {
651 /* Ensure the name is null terminated. */
652 if (pdata
[namelen
+ 4] != '\0') {
655 if (!pull_ascii_talloc(ctx
, &eal
->ea
.name
, pdata
+ 4, &converted_size
)) {
656 DEBUG(0,("read_ea_list_entry: pull_ascii_talloc failed: %s",
663 eal
->ea
.value
= data_blob_talloc(eal
, NULL
, (size_t)val_len
+ 1);
664 if (!eal
->ea
.value
.data
) {
668 memcpy(eal
->ea
.value
.data
, pdata
+ 4 + namelen
+ 1, val_len
);
670 /* Ensure we're null terminated just in case we print the value. */
671 eal
->ea
.value
.data
[val_len
] = '\0';
672 /* But don't count the null. */
673 eal
->ea
.value
.length
--;
676 *pbytes_used
= 4 + namelen
+ 1 + val_len
;
679 DEBUG(10,("read_ea_list_entry: read ea name %s\n", eal
->ea
.name
));
680 dump_data(10, eal
->ea
.value
.data
, eal
->ea
.value
.length
);
685 /****************************************************************************
686 Read a list of EA names and data from an incoming data buffer. Create an ea_list with them.
687 ****************************************************************************/
689 static struct ea_list
*read_ea_list(TALLOC_CTX
*ctx
, const char *pdata
, size_t data_size
)
691 struct ea_list
*ea_list_head
= NULL
;
693 size_t bytes_used
= 0;
695 while (offset
< data_size
) {
696 struct ea_list
*eal
= read_ea_list_entry(ctx
, pdata
+ offset
, data_size
- offset
, &bytes_used
);
702 DLIST_ADD_END(ea_list_head
, eal
, struct ea_list
*);
703 offset
+= bytes_used
;
709 /****************************************************************************
710 Count the total EA size needed.
711 ****************************************************************************/
713 static size_t ea_list_size(struct ea_list
*ealist
)
716 struct ea_list
*listp
;
719 for (listp
= ealist
; listp
; listp
= listp
->next
) {
720 push_ascii_fstring(dos_ea_name
, listp
->ea
.name
);
721 ret
+= 4 + strlen(dos_ea_name
) + 1 + listp
->ea
.value
.length
;
723 /* Add on 4 for total length. */
731 /****************************************************************************
732 Return a union of EA's from a file list and a list of names.
733 The TALLOC context for the two lists *MUST* be identical as we steal
734 memory from one list to add to another. JRA.
735 ****************************************************************************/
737 static struct ea_list
*ea_list_union(struct ea_list
*name_list
, struct ea_list
*file_list
, size_t *total_ea_len
)
739 struct ea_list
*nlistp
, *flistp
;
741 for (nlistp
= name_list
; nlistp
; nlistp
= nlistp
->next
) {
742 for (flistp
= file_list
; flistp
; flistp
= flistp
->next
) {
743 if (strequal(nlistp
->ea
.name
, flistp
->ea
.name
)) {
749 /* Copy the data from this entry. */
750 nlistp
->ea
.flags
= flistp
->ea
.flags
;
751 nlistp
->ea
.value
= flistp
->ea
.value
;
754 nlistp
->ea
.flags
= 0;
755 ZERO_STRUCT(nlistp
->ea
.value
);
759 *total_ea_len
= ea_list_size(name_list
);
763 /****************************************************************************
764 Send the required number of replies back.
765 We assume all fields other than the data fields are
766 set correctly for the type of call.
767 HACK ! Always assumes smb_setup field is zero.
768 ****************************************************************************/
770 void send_trans2_replies(connection_struct
*conn
,
771 struct smb_request
*req
,
778 /* As we are using a protocol > LANMAN1 then the max_send
779 variable must have been set in the sessetupX call.
780 This takes precedence over the max_xmit field in the
781 global struct. These different max_xmit variables should
782 be merged as this is now too confusing */
784 int data_to_send
= datasize
;
785 int params_to_send
= paramsize
;
787 const char *pp
= params
;
788 const char *pd
= pdata
;
789 int params_sent_thistime
, data_sent_thistime
, total_sent_thistime
;
790 int alignment_offset
= 1; /* JRA. This used to be 3. Set to 1 to make netmon parse ok. */
791 int data_alignment_offset
= 0;
792 bool overflow
= False
;
793 struct smbd_server_connection
*sconn
= req
->sconn
;
794 int max_send
= sconn
->smb1
.sessions
.max_send
;
796 /* Modify the data_to_send and datasize and set the error if
797 we're trying to send more than max_data_bytes. We still send
798 the part of the packet(s) that fit. Strange, but needed
801 if (max_data_bytes
> 0 && datasize
> max_data_bytes
) {
802 DEBUG(5,("send_trans2_replies: max_data_bytes %d exceeded by data %d\n",
803 max_data_bytes
, datasize
));
804 datasize
= data_to_send
= max_data_bytes
;
808 /* If there genuinely are no parameters or data to send just send the empty packet */
810 if(params_to_send
== 0 && data_to_send
== 0) {
811 reply_outbuf(req
, 10, 0);
812 show_msg((char *)req
->outbuf
);
813 if (!srv_send_smb(sconn
,
816 IS_CONN_ENCRYPTED(conn
),
818 exit_server_cleanly("send_trans2_replies: srv_send_smb failed.");
820 TALLOC_FREE(req
->outbuf
);
824 /* When sending params and data ensure that both are nicely aligned */
825 /* Only do this alignment when there is also data to send - else
826 can cause NT redirector problems. */
828 if (((params_to_send
% 4) != 0) && (data_to_send
!= 0))
829 data_alignment_offset
= 4 - (params_to_send
% 4);
831 /* Space is bufsize minus Netbios over TCP header minus SMB header */
832 /* The alignment_offset is to align the param bytes on an even byte
833 boundary. NT 4.0 Beta needs this to work correctly. */
835 useable_space
= max_send
- (smb_size
838 + data_alignment_offset
);
840 if (useable_space
< 0) {
841 DEBUG(0, ("send_trans2_replies failed sanity useable_space "
842 "= %d!!!", useable_space
));
843 exit_server_cleanly("send_trans2_replies: Not enough space");
846 while (params_to_send
|| data_to_send
) {
847 /* Calculate whether we will totally or partially fill this packet */
849 total_sent_thistime
= params_to_send
+ data_to_send
;
851 /* We can never send more than useable_space */
853 * Note that 'useable_space' does not include the alignment offsets,
854 * but we must include the alignment offsets in the calculation of
855 * the length of the data we send over the wire, as the alignment offsets
856 * are sent here. Fix from Marc_Jacobsen@hp.com.
859 total_sent_thistime
= MIN(total_sent_thistime
, useable_space
);
861 reply_outbuf(req
, 10, total_sent_thistime
+ alignment_offset
862 + data_alignment_offset
);
865 * We might have SMBtrans2s in req which was transferred to
866 * the outbuf, fix that.
868 SCVAL(req
->outbuf
, smb_com
, SMBtrans2
);
870 /* Set total params and data to be sent */
871 SSVAL(req
->outbuf
,smb_tprcnt
,paramsize
);
872 SSVAL(req
->outbuf
,smb_tdrcnt
,datasize
);
874 /* Calculate how many parameters and data we can fit into
875 * this packet. Parameters get precedence
878 params_sent_thistime
= MIN(params_to_send
,useable_space
);
879 data_sent_thistime
= useable_space
- params_sent_thistime
;
880 data_sent_thistime
= MIN(data_sent_thistime
,data_to_send
);
882 SSVAL(req
->outbuf
,smb_prcnt
, params_sent_thistime
);
884 /* smb_proff is the offset from the start of the SMB header to the
885 parameter bytes, however the first 4 bytes of outbuf are
886 the Netbios over TCP header. Thus use smb_base() to subtract
887 them from the calculation */
889 SSVAL(req
->outbuf
,smb_proff
,
890 ((smb_buf(req
->outbuf
)+alignment_offset
)
891 - smb_base(req
->outbuf
)));
893 if(params_sent_thistime
== 0)
894 SSVAL(req
->outbuf
,smb_prdisp
,0);
896 /* Absolute displacement of param bytes sent in this packet */
897 SSVAL(req
->outbuf
,smb_prdisp
,pp
- params
);
899 SSVAL(req
->outbuf
,smb_drcnt
, data_sent_thistime
);
900 if(data_sent_thistime
== 0) {
901 SSVAL(req
->outbuf
,smb_droff
,0);
902 SSVAL(req
->outbuf
,smb_drdisp
, 0);
904 /* The offset of the data bytes is the offset of the
905 parameter bytes plus the number of parameters being sent this time */
906 SSVAL(req
->outbuf
, smb_droff
,
907 ((smb_buf(req
->outbuf
)+alignment_offset
)
908 - smb_base(req
->outbuf
))
909 + params_sent_thistime
+ data_alignment_offset
);
910 SSVAL(req
->outbuf
,smb_drdisp
, pd
- pdata
);
913 /* Initialize the padding for alignment */
915 if (alignment_offset
!= 0) {
916 memset(smb_buf(req
->outbuf
), 0, alignment_offset
);
919 /* Copy the param bytes into the packet */
921 if(params_sent_thistime
) {
922 memcpy((smb_buf(req
->outbuf
)+alignment_offset
), pp
,
923 params_sent_thistime
);
926 /* Copy in the data bytes */
927 if(data_sent_thistime
) {
928 if (data_alignment_offset
!= 0) {
929 memset((smb_buf(req
->outbuf
)+alignment_offset
+
930 params_sent_thistime
), 0,
931 data_alignment_offset
);
933 memcpy(smb_buf(req
->outbuf
)+alignment_offset
934 +params_sent_thistime
+data_alignment_offset
,
935 pd
,data_sent_thistime
);
938 DEBUG(9,("t2_rep: params_sent_thistime = %d, data_sent_thistime = %d, useable_space = %d\n",
939 params_sent_thistime
, data_sent_thistime
, useable_space
));
940 DEBUG(9,("t2_rep: params_to_send = %d, data_to_send = %d, paramsize = %d, datasize = %d\n",
941 params_to_send
, data_to_send
, paramsize
, datasize
));
944 error_packet_set((char *)req
->outbuf
,
945 ERRDOS
,ERRbufferoverflow
,
946 STATUS_BUFFER_OVERFLOW
,
950 /* Send the packet */
951 show_msg((char *)req
->outbuf
);
952 if (!srv_send_smb(sconn
,
955 IS_CONN_ENCRYPTED(conn
),
957 exit_server_cleanly("send_trans2_replies: srv_send_smb failed.");
959 TALLOC_FREE(req
->outbuf
);
961 pp
+= params_sent_thistime
;
962 pd
+= data_sent_thistime
;
964 params_to_send
-= params_sent_thistime
;
965 data_to_send
-= data_sent_thistime
;
968 if(params_to_send
< 0 || data_to_send
< 0) {
969 DEBUG(0,("send_trans2_replies failed sanity check pts = %d, dts = %d\n!!!",
970 params_to_send
, data_to_send
));
978 /****************************************************************************
979 Reply to a TRANSACT2_OPEN.
980 ****************************************************************************/
982 static void call_trans2open(connection_struct
*conn
,
983 struct smb_request
*req
,
984 char **pparams
, int total_params
,
985 char **ppdata
, int total_data
,
986 unsigned int max_data_bytes
)
988 struct smb_filename
*smb_fname
= NULL
;
989 char *params
= *pparams
;
990 char *pdata
= *ppdata
;
995 bool return_additional_info
;
1004 int fattr
=0,mtime
=0;
1005 SMB_INO_T inode
= 0;
1008 struct ea_list
*ea_list
= NULL
;
1013 uint32 create_disposition
;
1014 uint32 create_options
= 0;
1015 uint32_t private_flags
= 0;
1016 TALLOC_CTX
*ctx
= talloc_tos();
1019 * Ensure we have enough parameters to perform the operation.
1022 if (total_params
< 29) {
1023 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1027 flags
= SVAL(params
, 0);
1028 deny_mode
= SVAL(params
, 2);
1029 open_attr
= SVAL(params
,6);
1030 oplock_request
= (flags
& REQUEST_OPLOCK
) ? EXCLUSIVE_OPLOCK
: 0;
1031 if (oplock_request
) {
1032 oplock_request
|= (flags
& REQUEST_BATCH_OPLOCK
) ? BATCH_OPLOCK
: 0;
1036 return_additional_info
= BITSETW(params
,0);
1037 open_sattr
= SVAL(params
, 4);
1038 open_time
= make_unix_date3(params
+8);
1040 open_ofun
= SVAL(params
,12);
1041 open_size
= IVAL(params
,14);
1042 pname
= ¶ms
[28];
1045 reply_nterror(req
, NT_STATUS_NETWORK_ACCESS_DENIED
);
1049 srvstr_get_path(ctx
, params
, req
->flags2
, &fname
, pname
,
1050 total_params
- 28, STR_TERMINATE
,
1052 if (!NT_STATUS_IS_OK(status
)) {
1053 reply_nterror(req
, status
);
1057 DEBUG(3,("call_trans2open %s deny_mode=0x%x attr=%d ofun=0x%x size=%d\n",
1058 fname
, (unsigned int)deny_mode
, (unsigned int)open_attr
,
1059 (unsigned int)open_ofun
, open_size
));
1061 status
= filename_convert(ctx
,
1063 req
->flags2
& FLAGS2_DFS_PATHNAMES
,
1068 if (!NT_STATUS_IS_OK(status
)) {
1069 if (NT_STATUS_EQUAL(status
,NT_STATUS_PATH_NOT_COVERED
)) {
1070 reply_botherror(req
,
1071 NT_STATUS_PATH_NOT_COVERED
,
1072 ERRSRV
, ERRbadpath
);
1075 reply_nterror(req
, status
);
1079 if (open_ofun
== 0) {
1080 reply_nterror(req
, NT_STATUS_OBJECT_NAME_COLLISION
);
1084 if (!map_open_params_to_ntcreate(smb_fname
, deny_mode
, open_ofun
,
1085 &access_mask
, &share_mode
,
1086 &create_disposition
,
1089 reply_nterror(req
, NT_STATUS_ACCESS_DENIED
);
1093 /* Any data in this call is an EA list. */
1094 if (total_data
&& (total_data
!= 4)) {
1095 if (total_data
< 10) {
1096 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1100 if (IVAL(pdata
,0) > total_data
) {
1101 DEBUG(10,("call_trans2open: bad total data size (%u) > %u\n",
1102 IVAL(pdata
,0), (unsigned int)total_data
));
1103 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1107 ea_list
= read_ea_list(talloc_tos(), pdata
+ 4,
1110 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1114 if (!lp_ea_support(SNUM(conn
))) {
1115 reply_nterror(req
, NT_STATUS_EAS_NOT_SUPPORTED
);
1120 status
= SMB_VFS_CREATE_FILE(
1123 0, /* root_dir_fid */
1124 smb_fname
, /* fname */
1125 access_mask
, /* access_mask */
1126 share_mode
, /* share_access */
1127 create_disposition
, /* create_disposition*/
1128 create_options
, /* create_options */
1129 open_attr
, /* file_attributes */
1130 oplock_request
, /* oplock_request */
1131 open_size
, /* allocation_size */
1134 ea_list
, /* ea_list */
1136 &smb_action
); /* psbuf */
1138 if (!NT_STATUS_IS_OK(status
)) {
1139 if (open_was_deferred(req
->mid
)) {
1140 /* We have re-scheduled this call. */
1143 reply_openerror(req
, status
);
1147 size
= get_file_size_stat(&smb_fname
->st
);
1148 fattr
= dos_mode(conn
, smb_fname
);
1149 mtime
= convert_timespec_to_time_t(smb_fname
->st
.st_ex_mtime
);
1150 inode
= smb_fname
->st
.st_ex_ino
;
1152 close_file(req
, fsp
, ERROR_CLOSE
);
1153 reply_nterror(req
, NT_STATUS_ACCESS_DENIED
);
1157 /* Realloc the size of parameters and data we will return */
1158 *pparams
= (char *)SMB_REALLOC(*pparams
, 30);
1159 if(*pparams
== NULL
) {
1160 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1165 SSVAL(params
,0,fsp
->fnum
);
1166 SSVAL(params
,2,fattr
);
1167 srv_put_dos_date2(params
,4, mtime
);
1168 SIVAL(params
,8, (uint32
)size
);
1169 SSVAL(params
,12,deny_mode
);
1170 SSVAL(params
,14,0); /* open_type - file or directory. */
1171 SSVAL(params
,16,0); /* open_state - only valid for IPC device. */
1173 if (oplock_request
&& lp_fake_oplocks(SNUM(conn
))) {
1174 smb_action
|= EXTENDED_OPLOCK_GRANTED
;
1177 SSVAL(params
,18,smb_action
);
1180 * WARNING - this may need to be changed if SMB_INO_T <> 4 bytes.
1182 SIVAL(params
,20,inode
);
1183 SSVAL(params
,24,0); /* Padding. */
1185 uint32 ea_size
= estimate_ea_size(conn
, fsp
,
1186 fsp
->fsp_name
->base_name
);
1187 SIVAL(params
, 26, ea_size
);
1189 SIVAL(params
, 26, 0);
1192 /* Send the required number of replies */
1193 send_trans2_replies(conn
, req
, params
, 30, *ppdata
, 0, max_data_bytes
);
1195 TALLOC_FREE(smb_fname
);
1198 /*********************************************************
1199 Routine to check if a given string matches exactly.
1200 as a special case a mask of "." does NOT match. That
1201 is required for correct wildcard semantics
1202 Case can be significant or not.
1203 **********************************************************/
1205 static bool exact_match(bool has_wild
,
1206 bool case_sensitive
,
1210 if (mask
[0] == '.' && mask
[1] == 0) {
1218 if (case_sensitive
) {
1219 return strcmp(str
,mask
)==0;
1221 return StrCaseCmp(str
,mask
) == 0;
1225 /****************************************************************************
1226 Return the filetype for UNIX extensions.
1227 ****************************************************************************/
1229 static uint32
unix_filetype(mode_t mode
)
1232 return UNIX_TYPE_FILE
;
1233 else if(S_ISDIR(mode
))
1234 return UNIX_TYPE_DIR
;
1236 else if(S_ISLNK(mode
))
1237 return UNIX_TYPE_SYMLINK
;
1240 else if(S_ISCHR(mode
))
1241 return UNIX_TYPE_CHARDEV
;
1244 else if(S_ISBLK(mode
))
1245 return UNIX_TYPE_BLKDEV
;
1248 else if(S_ISFIFO(mode
))
1249 return UNIX_TYPE_FIFO
;
1252 else if(S_ISSOCK(mode
))
1253 return UNIX_TYPE_SOCKET
;
1256 DEBUG(0,("unix_filetype: unknown filetype %u\n", (unsigned)mode
));
1257 return UNIX_TYPE_UNKNOWN
;
1260 /****************************************************************************
1261 Map wire perms onto standard UNIX permissions. Obey share restrictions.
1262 ****************************************************************************/
1264 enum perm_type
{ PERM_NEW_FILE
, PERM_NEW_DIR
, PERM_EXISTING_FILE
, PERM_EXISTING_DIR
};
1266 static NTSTATUS
unix_perms_from_wire( connection_struct
*conn
,
1267 const SMB_STRUCT_STAT
*psbuf
,
1269 enum perm_type ptype
,
1274 if (perms
== SMB_MODE_NO_CHANGE
) {
1275 if (!VALID_STAT(*psbuf
)) {
1276 return NT_STATUS_INVALID_PARAMETER
;
1278 *ret_perms
= psbuf
->st_ex_mode
;
1279 return NT_STATUS_OK
;
1283 ret
|= ((perms
& UNIX_X_OTH
) ? S_IXOTH
: 0);
1284 ret
|= ((perms
& UNIX_W_OTH
) ? S_IWOTH
: 0);
1285 ret
|= ((perms
& UNIX_R_OTH
) ? S_IROTH
: 0);
1286 ret
|= ((perms
& UNIX_X_GRP
) ? S_IXGRP
: 0);
1287 ret
|= ((perms
& UNIX_W_GRP
) ? S_IWGRP
: 0);
1288 ret
|= ((perms
& UNIX_R_GRP
) ? S_IRGRP
: 0);
1289 ret
|= ((perms
& UNIX_X_USR
) ? S_IXUSR
: 0);
1290 ret
|= ((perms
& UNIX_W_USR
) ? S_IWUSR
: 0);
1291 ret
|= ((perms
& UNIX_R_USR
) ? S_IRUSR
: 0);
1293 ret
|= ((perms
& UNIX_STICKY
) ? S_ISVTX
: 0);
1296 ret
|= ((perms
& UNIX_SET_GID
) ? S_ISGID
: 0);
1299 ret
|= ((perms
& UNIX_SET_UID
) ? S_ISUID
: 0);
1304 /* Apply mode mask */
1305 ret
&= lp_create_mask(SNUM(conn
));
1306 /* Add in force bits */
1307 ret
|= lp_force_create_mode(SNUM(conn
));
1310 ret
&= lp_dir_mask(SNUM(conn
));
1311 /* Add in force bits */
1312 ret
|= lp_force_dir_mode(SNUM(conn
));
1314 case PERM_EXISTING_FILE
:
1315 /* Apply mode mask */
1316 ret
&= lp_security_mask(SNUM(conn
));
1317 /* Add in force bits */
1318 ret
|= lp_force_security_mode(SNUM(conn
));
1320 case PERM_EXISTING_DIR
:
1321 /* Apply mode mask */
1322 ret
&= lp_dir_security_mask(SNUM(conn
));
1323 /* Add in force bits */
1324 ret
|= lp_force_dir_security_mode(SNUM(conn
));
1329 return NT_STATUS_OK
;
1332 /****************************************************************************
1333 Needed to show the msdfs symlinks as directories. Modifies psbuf
1334 to be a directory if it's a msdfs link.
1335 ****************************************************************************/
1337 static bool check_msdfs_link(connection_struct
*conn
,
1338 const char *pathname
,
1339 SMB_STRUCT_STAT
*psbuf
)
1341 int saved_errno
= errno
;
1342 if(lp_host_msdfs() &&
1343 lp_msdfs_root(SNUM(conn
)) &&
1344 is_msdfs_link(conn
, pathname
, psbuf
)) {
1346 DEBUG(5,("check_msdfs_link: Masquerading msdfs link %s "
1349 psbuf
->st_ex_mode
= (psbuf
->st_ex_mode
& 0xFFF) | S_IFDIR
;
1350 errno
= saved_errno
;
1353 errno
= saved_errno
;
1358 /****************************************************************************
1359 Get a level dependent lanman2 dir entry.
1360 ****************************************************************************/
1362 struct smbd_dirptr_lanman2_state
{
1363 connection_struct
*conn
;
1364 uint32_t info_level
;
1365 bool check_mangled_names
;
1367 bool got_exact_match
;
1370 static bool smbd_dirptr_lanman2_match_fn(TALLOC_CTX
*ctx
,
1376 struct smbd_dirptr_lanman2_state
*state
=
1377 (struct smbd_dirptr_lanman2_state
*)private_data
;
1379 char mangled_name
[13]; /* mangled 8.3 name. */
1383 /* Mangle fname if it's an illegal name. */
1384 if (mangle_must_mangle(dname
, state
->conn
->params
)) {
1385 ok
= name_to_8_3(dname
, mangled_name
,
1386 true, state
->conn
->params
);
1390 fname
= mangled_name
;
1395 got_match
= exact_match(state
->has_wild
,
1396 state
->conn
->case_sensitive
,
1398 state
->got_exact_match
= got_match
;
1400 got_match
= mask_match(fname
, mask
,
1401 state
->conn
->case_sensitive
);
1404 if(!got_match
&& state
->check_mangled_names
&&
1405 !mangle_is_8_3(fname
, false, state
->conn
->params
)) {
1407 * It turns out that NT matches wildcards against
1408 * both long *and* short names. This may explain some
1409 * of the wildcard wierdness from old DOS clients
1410 * that some people have been seeing.... JRA.
1412 /* Force the mangling into 8.3. */
1413 ok
= name_to_8_3(fname
, mangled_name
,
1414 false, state
->conn
->params
);
1419 got_match
= exact_match(state
->has_wild
,
1420 state
->conn
->case_sensitive
,
1421 mangled_name
, mask
);
1422 state
->got_exact_match
= got_match
;
1424 got_match
= mask_match(mangled_name
, mask
,
1425 state
->conn
->case_sensitive
);
1433 *_fname
= talloc_strdup(ctx
, fname
);
1434 if (*_fname
== NULL
) {
1441 static bool smbd_dirptr_lanman2_mode_fn(TALLOC_CTX
*ctx
,
1443 struct smb_filename
*smb_fname
,
1446 struct smbd_dirptr_lanman2_state
*state
=
1447 (struct smbd_dirptr_lanman2_state
*)private_data
;
1448 bool ms_dfs_link
= false;
1451 if (INFO_LEVEL_IS_UNIX(state
->info_level
)) {
1452 if (SMB_VFS_LSTAT(state
->conn
, smb_fname
) != 0) {
1453 DEBUG(5,("smbd_dirptr_lanman2_mode_fn: "
1454 "Couldn't lstat [%s] (%s)\n",
1455 smb_fname_str_dbg(smb_fname
),
1459 } else if (!VALID_STAT(smb_fname
->st
) &&
1460 SMB_VFS_STAT(state
->conn
, smb_fname
) != 0) {
1461 /* Needed to show the msdfs symlinks as
1464 ms_dfs_link
= check_msdfs_link(state
->conn
,
1465 smb_fname
->base_name
,
1468 DEBUG(5,("smbd_dirptr_lanman2_mode_fn: "
1469 "Couldn't stat [%s] (%s)\n",
1470 smb_fname_str_dbg(smb_fname
),
1477 mode
= dos_mode_msdfs(state
->conn
, smb_fname
);
1479 mode
= dos_mode(state
->conn
, smb_fname
);
1486 static bool smbd_marshall_dir_entry(TALLOC_CTX
*ctx
,
1487 connection_struct
*conn
,
1489 uint32_t info_level
,
1490 struct ea_list
*name_list
,
1491 bool check_mangled_names
,
1492 bool requires_resume_key
,
1495 const struct smb_filename
*smb_fname
,
1496 int space_remaining
,
1503 uint64_t *last_entry_off
)
1505 char *p
, *q
, *pdata
= *ppdata
;
1507 uint64_t file_size
= 0;
1508 uint64_t allocation_size
= 0;
1509 uint64_t file_index
= 0;
1511 struct timespec mdate_ts
, adate_ts
, cdate_ts
, create_date_ts
;
1512 time_t mdate
= (time_t)0, adate
= (time_t)0, create_date
= (time_t)0;
1513 time_t c_date
= (time_t)0;
1515 char *last_entry_ptr
;
1520 *out_of_space
= false;
1522 ZERO_STRUCT(mdate_ts
);
1523 ZERO_STRUCT(adate_ts
);
1524 ZERO_STRUCT(create_date_ts
);
1525 ZERO_STRUCT(cdate_ts
);
1527 if (!(mode
& aDIR
)) {
1528 file_size
= get_file_size_stat(&smb_fname
->st
);
1530 allocation_size
= SMB_VFS_GET_ALLOC_SIZE(conn
, NULL
, &smb_fname
->st
);
1532 file_index
= get_FileIndex(conn
, &smb_fname
->st
);
1534 mdate_ts
= smb_fname
->st
.st_ex_mtime
;
1535 adate_ts
= smb_fname
->st
.st_ex_atime
;
1536 create_date_ts
= get_create_timespec(conn
, NULL
, smb_fname
);
1537 cdate_ts
= get_change_timespec(conn
, NULL
, smb_fname
);
1539 if (lp_dos_filetime_resolution(SNUM(conn
))) {
1540 dos_filetime_timespec(&create_date_ts
);
1541 dos_filetime_timespec(&mdate_ts
);
1542 dos_filetime_timespec(&adate_ts
);
1543 dos_filetime_timespec(&cdate_ts
);
1546 create_date
= convert_timespec_to_time_t(create_date_ts
);
1547 mdate
= convert_timespec_to_time_t(mdate_ts
);
1548 adate
= convert_timespec_to_time_t(adate_ts
);
1549 c_date
= convert_timespec_to_time_t(cdate_ts
);
1551 /* align the record */
1552 SMB_ASSERT(align
>= 1);
1554 off
= (int)PTR_DIFF(pdata
, base_data
);
1555 pad
= (off
+ (align
-1)) & ~(align
-1);
1558 if (pad
&& pad
> space_remaining
) {
1559 *out_of_space
= true;
1560 DEBUG(9,("smbd_marshall_dir_entry: out of space "
1561 "for padding (wanted %u, had %d)\n",
1564 return false; /* Not finished - just out of space */
1568 /* initialize padding to 0 */
1570 memset(pdata
, 0, pad
);
1572 space_remaining
-= pad
;
1574 DEBUG(10,("smbd_marshall_dir_entry: space_remaining = %d\n",
1584 switch (info_level
) {
1585 case SMB_FIND_INFO_STANDARD
:
1586 DEBUG(10,("smbd_marshall_dir_entry: SMB_FIND_INFO_STANDARD\n"));
1587 if(requires_resume_key
) {
1591 srv_put_dos_date2(p
,0,create_date
);
1592 srv_put_dos_date2(p
,4,adate
);
1593 srv_put_dos_date2(p
,8,mdate
);
1594 SIVAL(p
,12,(uint32
)file_size
);
1595 SIVAL(p
,16,(uint32
)allocation_size
);
1599 if (flags2
& FLAGS2_UNICODE_STRINGS
) {
1600 p
+= ucs2_align(base_data
, p
, 0);
1602 len
= srvstr_push(base_data
, flags2
, p
,
1603 fname
, PTR_DIFF(end_data
, p
),
1605 if (flags2
& FLAGS2_UNICODE_STRINGS
) {
1607 SCVAL(nameptr
, -1, len
- 2);
1609 SCVAL(nameptr
, -1, 0);
1613 SCVAL(nameptr
, -1, len
- 1);
1615 SCVAL(nameptr
, -1, 0);
1621 case SMB_FIND_EA_SIZE
:
1622 DEBUG(10,("smbd_marshall_dir_entry: SMB_FIND_EA_SIZE\n"));
1623 if (requires_resume_key
) {
1627 srv_put_dos_date2(p
,0,create_date
);
1628 srv_put_dos_date2(p
,4,adate
);
1629 srv_put_dos_date2(p
,8,mdate
);
1630 SIVAL(p
,12,(uint32
)file_size
);
1631 SIVAL(p
,16,(uint32
)allocation_size
);
1634 unsigned int ea_size
= estimate_ea_size(conn
, NULL
,
1635 smb_fname
->base_name
);
1636 SIVAL(p
,22,ea_size
); /* Extended attributes */
1640 len
= srvstr_push(base_data
, flags2
,
1641 p
, fname
, PTR_DIFF(end_data
, p
),
1642 STR_TERMINATE
| STR_NOALIGN
);
1643 if (flags2
& FLAGS2_UNICODE_STRINGS
) {
1656 SCVAL(nameptr
,0,len
);
1658 SCVAL(p
,0,0); p
+= 1; /* Extra zero byte ? - why.. */
1661 case SMB_FIND_EA_LIST
:
1663 struct ea_list
*file_list
= NULL
;
1666 DEBUG(10,("smbd_marshall_dir_entry: SMB_FIND_EA_LIST\n"));
1670 if (requires_resume_key
) {
1674 srv_put_dos_date2(p
,0,create_date
);
1675 srv_put_dos_date2(p
,4,adate
);
1676 srv_put_dos_date2(p
,8,mdate
);
1677 SIVAL(p
,12,(uint32
)file_size
);
1678 SIVAL(p
,16,(uint32
)allocation_size
);
1680 p
+= 22; /* p now points to the EA area. */
1682 file_list
= get_ea_list_from_file(ctx
, conn
, NULL
,
1683 smb_fname
->base_name
,
1685 name_list
= ea_list_union(name_list
, file_list
, &ea_len
);
1687 /* We need to determine if this entry will fit in the space available. */
1688 /* Max string size is 255 bytes. */
1689 if (PTR_DIFF(p
+ 255 + ea_len
,pdata
) > space_remaining
) {
1690 *out_of_space
= true;
1691 DEBUG(9,("smbd_marshall_dir_entry: out of space "
1692 "(wanted %u, had %d)\n",
1693 (unsigned int)PTR_DIFF(p
+ 255 + ea_len
,pdata
),
1695 return False
; /* Not finished - just out of space */
1698 /* Push the ea_data followed by the name. */
1699 p
+= fill_ea_buffer(ctx
, p
, space_remaining
, conn
, name_list
);
1701 len
= srvstr_push(base_data
, flags2
,
1702 p
+ 1, fname
, PTR_DIFF(end_data
, p
+1),
1703 STR_TERMINATE
| STR_NOALIGN
);
1704 if (flags2
& FLAGS2_UNICODE_STRINGS
) {
1717 SCVAL(nameptr
,0,len
);
1719 SCVAL(p
,0,0); p
+= 1; /* Extra zero byte ? - why.. */
1723 case SMB_FIND_FILE_BOTH_DIRECTORY_INFO
:
1724 DEBUG(10,("smbd_marshall_dir_entry: SMB_FIND_FILE_BOTH_DIRECTORY_INFO\n"));
1725 was_8_3
= mangle_is_8_3(fname
, True
, conn
->params
);
1727 SIVAL(p
,0,reskey
); p
+= 4;
1728 put_long_date_timespec(conn
->ts_res
,p
,create_date_ts
); p
+= 8;
1729 put_long_date_timespec(conn
->ts_res
,p
,adate_ts
); p
+= 8;
1730 put_long_date_timespec(conn
->ts_res
,p
,mdate_ts
); p
+= 8;
1731 put_long_date_timespec(conn
->ts_res
,p
,cdate_ts
); p
+= 8;
1732 SOFF_T(p
,0,file_size
); p
+= 8;
1733 SOFF_T(p
,0,allocation_size
); p
+= 8;
1734 SIVAL(p
,0,mode
); p
+= 4;
1735 q
= p
; p
+= 4; /* q is placeholder for name length. */
1737 unsigned int ea_size
= estimate_ea_size(conn
, NULL
,
1738 smb_fname
->base_name
);
1739 SIVAL(p
,0,ea_size
); /* Extended attributes */
1742 /* Clear the short name buffer. This is
1743 * IMPORTANT as not doing so will trigger
1744 * a Win2k client bug. JRA.
1746 if (!was_8_3
&& check_mangled_names
) {
1747 char mangled_name
[13]; /* mangled 8.3 name. */
1748 if (!name_to_8_3(fname
,mangled_name
,True
,
1750 /* Error - mangle failed ! */
1751 memset(mangled_name
,'\0',12);
1753 mangled_name
[12] = 0;
1754 len
= srvstr_push(base_data
, flags2
,
1755 p
+2, mangled_name
, 24,
1756 STR_UPPER
|STR_UNICODE
);
1758 memset(p
+ 2 + len
,'\0',24 - len
);
1765 len
= srvstr_push(base_data
, flags2
, p
,
1766 fname
, PTR_DIFF(end_data
, p
),
1767 STR_TERMINATE_ASCII
);
1771 len
= PTR_DIFF(p
, pdata
);
1772 pad
= (len
+ (align
-1)) & ~(align
-1);
1774 * offset to the next entry, the caller
1775 * will overwrite it for the last entry
1776 * that's why we always include the padding
1780 * set padding to zero
1783 memset(p
, 0, pad
- len
);
1790 case SMB_FIND_FILE_DIRECTORY_INFO
:
1791 DEBUG(10,("smbd_marshall_dir_entry: SMB_FIND_FILE_DIRECTORY_INFO\n"));
1793 SIVAL(p
,0,reskey
); p
+= 4;
1794 put_long_date_timespec(conn
->ts_res
,p
,create_date_ts
); p
+= 8;
1795 put_long_date_timespec(conn
->ts_res
,p
,adate_ts
); p
+= 8;
1796 put_long_date_timespec(conn
->ts_res
,p
,mdate_ts
); p
+= 8;
1797 put_long_date_timespec(conn
->ts_res
,p
,cdate_ts
); p
+= 8;
1798 SOFF_T(p
,0,file_size
); p
+= 8;
1799 SOFF_T(p
,0,allocation_size
); p
+= 8;
1800 SIVAL(p
,0,mode
); p
+= 4;
1801 len
= srvstr_push(base_data
, flags2
,
1802 p
+ 4, fname
, PTR_DIFF(end_data
, p
+4),
1803 STR_TERMINATE_ASCII
);
1807 len
= PTR_DIFF(p
, pdata
);
1808 pad
= (len
+ (align
-1)) & ~(align
-1);
1810 * offset to the next entry, the caller
1811 * will overwrite it for the last entry
1812 * that's why we always include the padding
1816 * set padding to zero
1819 memset(p
, 0, pad
- len
);
1826 case SMB_FIND_FILE_FULL_DIRECTORY_INFO
:
1827 DEBUG(10,("smbd_marshall_dir_entry: SMB_FIND_FILE_FULL_DIRECTORY_INFO\n"));
1829 SIVAL(p
,0,reskey
); p
+= 4;
1830 put_long_date_timespec(conn
->ts_res
,p
,create_date_ts
); p
+= 8;
1831 put_long_date_timespec(conn
->ts_res
,p
,adate_ts
); p
+= 8;
1832 put_long_date_timespec(conn
->ts_res
,p
,mdate_ts
); p
+= 8;
1833 put_long_date_timespec(conn
->ts_res
,p
,cdate_ts
); p
+= 8;
1834 SOFF_T(p
,0,file_size
); p
+= 8;
1835 SOFF_T(p
,0,allocation_size
); p
+= 8;
1836 SIVAL(p
,0,mode
); p
+= 4;
1837 q
= p
; p
+= 4; /* q is placeholder for name length. */
1839 unsigned int ea_size
= estimate_ea_size(conn
, NULL
,
1840 smb_fname
->base_name
);
1841 SIVAL(p
,0,ea_size
); /* Extended attributes */
1844 len
= srvstr_push(base_data
, flags2
, p
,
1845 fname
, PTR_DIFF(end_data
, p
),
1846 STR_TERMINATE_ASCII
);
1850 len
= PTR_DIFF(p
, pdata
);
1851 pad
= (len
+ (align
-1)) & ~(align
-1);
1853 * offset to the next entry, the caller
1854 * will overwrite it for the last entry
1855 * that's why we always include the padding
1859 * set padding to zero
1862 memset(p
, 0, pad
- len
);
1869 case SMB_FIND_FILE_NAMES_INFO
:
1870 DEBUG(10,("smbd_marshall_dir_entry: SMB_FIND_FILE_NAMES_INFO\n"));
1872 SIVAL(p
,0,reskey
); p
+= 4;
1874 /* this must *not* be null terminated or w2k gets in a loop trying to set an
1875 acl on a dir (tridge) */
1876 len
= srvstr_push(base_data
, flags2
, p
,
1877 fname
, PTR_DIFF(end_data
, p
),
1878 STR_TERMINATE_ASCII
);
1882 len
= PTR_DIFF(p
, pdata
);
1883 pad
= (len
+ (align
-1)) & ~(align
-1);
1885 * offset to the next entry, the caller
1886 * will overwrite it for the last entry
1887 * that's why we always include the padding
1891 * set padding to zero
1894 memset(p
, 0, pad
- len
);
1901 case SMB_FIND_ID_FULL_DIRECTORY_INFO
:
1902 DEBUG(10,("smbd_marshall_dir_entry: SMB_FIND_ID_FULL_DIRECTORY_INFO\n"));
1904 SIVAL(p
,0,reskey
); p
+= 4;
1905 put_long_date_timespec(conn
->ts_res
,p
,create_date_ts
); p
+= 8;
1906 put_long_date_timespec(conn
->ts_res
,p
,adate_ts
); p
+= 8;
1907 put_long_date_timespec(conn
->ts_res
,p
,mdate_ts
); p
+= 8;
1908 put_long_date_timespec(conn
->ts_res
,p
,cdate_ts
); p
+= 8;
1909 SOFF_T(p
,0,file_size
); p
+= 8;
1910 SOFF_T(p
,0,allocation_size
); p
+= 8;
1911 SIVAL(p
,0,mode
); p
+= 4;
1912 q
= p
; p
+= 4; /* q is placeholder for name length. */
1914 unsigned int ea_size
= estimate_ea_size(conn
, NULL
,
1915 smb_fname
->base_name
);
1916 SIVAL(p
,0,ea_size
); /* Extended attributes */
1919 SIVAL(p
,0,0); p
+= 4; /* Unknown - reserved ? */
1920 SBVAL(p
,0,file_index
); p
+= 8;
1921 len
= srvstr_push(base_data
, flags2
, p
,
1922 fname
, PTR_DIFF(end_data
, p
),
1923 STR_TERMINATE_ASCII
);
1927 len
= PTR_DIFF(p
, pdata
);
1928 pad
= (len
+ (align
-1)) & ~(align
-1);
1930 * offset to the next entry, the caller
1931 * will overwrite it for the last entry
1932 * that's why we always include the padding
1936 * set padding to zero
1939 memset(p
, 0, pad
- len
);
1946 case SMB_FIND_ID_BOTH_DIRECTORY_INFO
:
1947 DEBUG(10,("smbd_marshall_dir_entry: SMB_FIND_ID_BOTH_DIRECTORY_INFO\n"));
1948 was_8_3
= mangle_is_8_3(fname
, True
, conn
->params
);
1950 SIVAL(p
,0,reskey
); p
+= 4;
1951 put_long_date_timespec(conn
->ts_res
,p
,create_date_ts
); p
+= 8;
1952 put_long_date_timespec(conn
->ts_res
,p
,adate_ts
); p
+= 8;
1953 put_long_date_timespec(conn
->ts_res
,p
,mdate_ts
); p
+= 8;
1954 put_long_date_timespec(conn
->ts_res
,p
,cdate_ts
); p
+= 8;
1955 SOFF_T(p
,0,file_size
); p
+= 8;
1956 SOFF_T(p
,0,allocation_size
); p
+= 8;
1957 SIVAL(p
,0,mode
); p
+= 4;
1958 q
= p
; p
+= 4; /* q is placeholder for name length */
1960 unsigned int ea_size
= estimate_ea_size(conn
, NULL
,
1961 smb_fname
->base_name
);
1962 SIVAL(p
,0,ea_size
); /* Extended attributes */
1965 /* Clear the short name buffer. This is
1966 * IMPORTANT as not doing so will trigger
1967 * a Win2k client bug. JRA.
1969 if (!was_8_3
&& check_mangled_names
) {
1970 char mangled_name
[13]; /* mangled 8.3 name. */
1971 if (!name_to_8_3(fname
,mangled_name
,True
,
1973 /* Error - mangle failed ! */
1974 memset(mangled_name
,'\0',12);
1976 mangled_name
[12] = 0;
1977 len
= srvstr_push(base_data
, flags2
,
1978 p
+2, mangled_name
, 24,
1979 STR_UPPER
|STR_UNICODE
);
1982 memset(p
+ 2 + len
,'\0',24 - len
);
1989 SSVAL(p
,0,0); p
+= 2; /* Reserved ? */
1990 SBVAL(p
,0,file_index
); p
+= 8;
1991 len
= srvstr_push(base_data
, flags2
, p
,
1992 fname
, PTR_DIFF(end_data
, p
),
1993 STR_TERMINATE_ASCII
);
1997 len
= PTR_DIFF(p
, pdata
);
1998 pad
= (len
+ (align
-1)) & ~(align
-1);
2000 * offset to the next entry, the caller
2001 * will overwrite it for the last entry
2002 * that's why we always include the padding
2006 * set padding to zero
2009 memset(p
, 0, pad
- len
);
2016 /* CIFS UNIX Extension. */
2018 case SMB_FIND_FILE_UNIX
:
2019 case SMB_FIND_FILE_UNIX_INFO2
:
2021 SIVAL(p
,0,reskey
); p
+= 4; /* Used for continuing search. */
2023 /* Begin of SMB_QUERY_FILE_UNIX_BASIC */
2025 if (info_level
== SMB_FIND_FILE_UNIX
) {
2026 DEBUG(10,("smbd_marshall_dir_entry: SMB_FIND_FILE_UNIX\n"));
2027 p
= store_file_unix_basic(conn
, p
,
2028 NULL
, &smb_fname
->st
);
2029 len
= srvstr_push(base_data
, flags2
, p
,
2030 fname
, PTR_DIFF(end_data
, p
),
2033 DEBUG(10,("smbd_marshall_dir_entry: SMB_FIND_FILE_UNIX_INFO2\n"));
2034 p
= store_file_unix_basic_info2(conn
, p
,
2035 NULL
, &smb_fname
->st
);
2038 len
= srvstr_push(base_data
, flags2
, p
, fname
,
2039 PTR_DIFF(end_data
, p
), 0);
2040 SIVAL(nameptr
, 0, len
);
2045 len
= PTR_DIFF(p
, pdata
);
2046 pad
= (len
+ (align
-1)) & ~(align
-1);
2048 * offset to the next entry, the caller
2049 * will overwrite it for the last entry
2050 * that's why we always include the padding
2054 * set padding to zero
2057 memset(p
, 0, pad
- len
);
2062 /* End of SMB_QUERY_FILE_UNIX_BASIC */
2070 if (PTR_DIFF(p
,pdata
) > space_remaining
) {
2071 *out_of_space
= true;
2072 DEBUG(9,("smbd_marshall_dir_entry: out of space "
2073 "(wanted %u, had %d)\n",
2074 (unsigned int)PTR_DIFF(p
,pdata
),
2076 return false; /* Not finished - just out of space */
2079 /* Setup the last entry pointer, as an offset from base_data */
2080 *last_entry_off
= PTR_DIFF(last_entry_ptr
,base_data
);
2081 /* Advance the data pointer to the next slot */
2087 bool smbd_dirptr_lanman2_entry(TALLOC_CTX
*ctx
,
2088 connection_struct
*conn
,
2089 struct dptr_struct
*dirptr
,
2091 const char *path_mask
,
2094 int requires_resume_key
,
2102 int space_remaining
,
2104 bool *got_exact_match
,
2105 int *_last_entry_off
,
2106 struct ea_list
*name_list
)
2109 const char *mask
= NULL
;
2110 long prev_dirpos
= 0;
2113 struct smb_filename
*smb_fname
= NULL
;
2114 struct smbd_dirptr_lanman2_state state
;
2116 uint64_t last_entry_off
= 0;
2120 state
.info_level
= info_level
;
2121 state
.check_mangled_names
= lp_manglednames(conn
->params
);
2122 state
.has_wild
= dptr_has_wild(dirptr
);
2123 state
.got_exact_match
= false;
2125 *out_of_space
= false;
2126 *got_exact_match
= false;
2128 p
= strrchr_m(path_mask
,'/');
2139 ok
= smbd_dirptr_get_entry(ctx
,
2145 smbd_dirptr_lanman2_match_fn
,
2146 smbd_dirptr_lanman2_mode_fn
,
2156 *got_exact_match
= state
.got_exact_match
;
2158 ok
= smbd_marshall_dir_entry(ctx
,
2163 state
.check_mangled_names
,
2164 requires_resume_key
,
2177 TALLOC_FREE(smb_fname
);
2178 if (*out_of_space
) {
2179 dptr_SeekDir(dirptr
, prev_dirpos
);
2186 *_last_entry_off
= last_entry_off
;
2190 static bool get_lanman2_dir_entry(TALLOC_CTX
*ctx
,
2191 connection_struct
*conn
,
2192 struct dptr_struct
*dirptr
,
2194 const char *path_mask
,
2197 bool requires_resume_key
,
2203 int space_remaining
,
2205 bool *got_exact_match
,
2206 int *last_entry_off
,
2207 struct ea_list
*name_list
)
2210 const bool do_pad
= true;
2212 if (info_level
>= 1 && info_level
<= 3) {
2213 /* No alignment on earlier info levels. */
2217 return smbd_dirptr_lanman2_entry(ctx
, conn
, dirptr
, flags2
,
2218 path_mask
, dirtype
, info_level
,
2219 requires_resume_key
, dont_descend
, ask_sharemode
,
2221 ppdata
, base_data
, end_data
,
2223 out_of_space
, got_exact_match
,
2224 last_entry_off
, name_list
);
2227 /****************************************************************************
2228 Reply to a TRANS2_FINDFIRST.
2229 ****************************************************************************/
2231 static void call_trans2findfirst(connection_struct
*conn
,
2232 struct smb_request
*req
,
2233 char **pparams
, int total_params
,
2234 char **ppdata
, int total_data
,
2235 unsigned int max_data_bytes
)
2237 /* We must be careful here that we don't return more than the
2238 allowed number of data bytes. If this means returning fewer than
2239 maxentries then so be it. We assume that the redirector has
2240 enough room for the fixed number of parameter bytes it has
2242 struct smb_filename
*smb_dname
= NULL
;
2243 char *params
= *pparams
;
2244 char *pdata
= *ppdata
;
2248 uint16 findfirst_flags
;
2249 bool close_after_first
;
2251 bool requires_resume_key
;
2253 char *directory
= NULL
;
2256 int last_entry_off
=0;
2260 bool finished
= False
;
2261 bool dont_descend
= False
;
2262 bool out_of_space
= False
;
2263 int space_remaining
;
2264 bool mask_contains_wcard
= False
;
2265 struct ea_list
*ea_list
= NULL
;
2266 NTSTATUS ntstatus
= NT_STATUS_OK
;
2267 bool ask_sharemode
= lp_parm_bool(SNUM(conn
), "smbd", "search ask sharemode", true);
2268 TALLOC_CTX
*ctx
= talloc_tos();
2269 struct dptr_struct
*dirptr
= NULL
;
2270 struct smbd_server_connection
*sconn
= req
->sconn
;
2272 if (total_params
< 13) {
2273 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2277 dirtype
= SVAL(params
,0);
2278 maxentries
= SVAL(params
,2);
2279 findfirst_flags
= SVAL(params
,4);
2280 close_after_first
= (findfirst_flags
& FLAG_TRANS2_FIND_CLOSE
);
2281 close_if_end
= (findfirst_flags
& FLAG_TRANS2_FIND_CLOSE_IF_END
);
2282 requires_resume_key
= (findfirst_flags
& FLAG_TRANS2_FIND_REQUIRE_RESUME
);
2283 info_level
= SVAL(params
,6);
2285 DEBUG(3,("call_trans2findfirst: dirtype = %x, maxentries = %d, close_after_first=%d, \
2286 close_if_end = %d requires_resume_key = %d level = 0x%x, max_data_bytes = %d\n",
2287 (unsigned int)dirtype
, maxentries
, close_after_first
, close_if_end
, requires_resume_key
,
2288 info_level
, max_data_bytes
));
2291 /* W2K3 seems to treat zero as 1. */
2295 switch (info_level
) {
2296 case SMB_FIND_INFO_STANDARD
:
2297 case SMB_FIND_EA_SIZE
:
2298 case SMB_FIND_EA_LIST
:
2299 case SMB_FIND_FILE_DIRECTORY_INFO
:
2300 case SMB_FIND_FILE_FULL_DIRECTORY_INFO
:
2301 case SMB_FIND_FILE_NAMES_INFO
:
2302 case SMB_FIND_FILE_BOTH_DIRECTORY_INFO
:
2303 case SMB_FIND_ID_FULL_DIRECTORY_INFO
:
2304 case SMB_FIND_ID_BOTH_DIRECTORY_INFO
:
2306 case SMB_FIND_FILE_UNIX
:
2307 case SMB_FIND_FILE_UNIX_INFO2
:
2308 /* Always use filesystem for UNIX mtime query. */
2309 ask_sharemode
= false;
2310 if (!lp_unix_extensions()) {
2311 reply_nterror(req
, NT_STATUS_INVALID_LEVEL
);
2316 reply_nterror(req
, NT_STATUS_INVALID_LEVEL
);
2320 srvstr_get_path_wcard(ctx
, params
, req
->flags2
, &directory
,
2321 params
+12, total_params
- 12,
2322 STR_TERMINATE
, &ntstatus
, &mask_contains_wcard
);
2323 if (!NT_STATUS_IS_OK(ntstatus
)) {
2324 reply_nterror(req
, ntstatus
);
2328 ntstatus
= filename_convert(ctx
, conn
,
2329 req
->flags2
& FLAGS2_DFS_PATHNAMES
,
2332 UCF_ALWAYS_ALLOW_WCARD_LCOMP
),
2333 &mask_contains_wcard
,
2335 if (!NT_STATUS_IS_OK(ntstatus
)) {
2336 if (NT_STATUS_EQUAL(ntstatus
,NT_STATUS_PATH_NOT_COVERED
)) {
2337 reply_botherror(req
, NT_STATUS_PATH_NOT_COVERED
,
2338 ERRSRV
, ERRbadpath
);
2341 reply_nterror(req
, ntstatus
);
2345 mask
= smb_dname
->original_lcomp
;
2347 directory
= smb_dname
->base_name
;
2349 p
= strrchr_m(directory
,'/');
2351 /* Windows and OS/2 systems treat search on the root '\' as if it were '\*' */
2352 if((directory
[0] == '.') && (directory
[1] == '\0')) {
2353 mask
= talloc_strdup(ctx
,"*");
2355 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2358 mask_contains_wcard
= True
;
2364 if (p
== NULL
|| p
== directory
) {
2365 /* Ensure we don't have a directory name of "". */
2366 directory
= talloc_strdup(talloc_tos(), ".");
2368 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2373 DEBUG(5,("dir=%s, mask = %s\n",directory
, mask
));
2375 if (info_level
== SMB_FIND_EA_LIST
) {
2378 if (total_data
< 4) {
2379 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2383 ea_size
= IVAL(pdata
,0);
2384 if (ea_size
!= total_data
) {
2385 DEBUG(4,("call_trans2findfirst: Rejecting EA request with incorrect \
2386 total_data=%u (should be %u)\n", (unsigned int)total_data
, (unsigned int)IVAL(pdata
,0) ));
2387 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2391 if (!lp_ea_support(SNUM(conn
))) {
2392 reply_nterror(req
, NT_STATUS_EAS_NOT_SUPPORTED
);
2396 /* Pull out the list of names. */
2397 ea_list
= read_ea_name_list(ctx
, pdata
+ 4, ea_size
- 4);
2399 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2404 *ppdata
= (char *)SMB_REALLOC(
2405 *ppdata
, max_data_bytes
+ DIR_ENTRY_SAFETY_MARGIN
);
2406 if(*ppdata
== NULL
) {
2407 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2411 data_end
= pdata
+ max_data_bytes
+ DIR_ENTRY_SAFETY_MARGIN
- 1;
2413 /* Realloc the params space */
2414 *pparams
= (char *)SMB_REALLOC(*pparams
, 10);
2415 if (*pparams
== NULL
) {
2416 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2421 /* Save the wildcard match and attribs we are using on this directory -
2422 needed as lanman2 assumes these are being saved between calls */
2424 ntstatus
= dptr_create(conn
,
2431 mask_contains_wcard
,
2435 if (!NT_STATUS_IS_OK(ntstatus
)) {
2436 reply_nterror(req
, ntstatus
);
2440 dptr_num
= dptr_dnum(dirptr
);
2441 DEBUG(4,("dptr_num is %d, wcard = %s, attr = %d\n", dptr_num
, mask
, dirtype
));
2443 /* Initialize per TRANS2_FIND_FIRST operation data */
2444 dptr_init_search_op(dirptr
);
2446 /* We don't need to check for VOL here as this is returned by
2447 a different TRANS2 call. */
2449 DEBUG(8,("dirpath=<%s> dontdescend=<%s>\n",
2450 directory
,lp_dontdescend(SNUM(conn
))));
2451 if (in_list(directory
,lp_dontdescend(SNUM(conn
)),conn
->case_sensitive
))
2452 dont_descend
= True
;
2455 space_remaining
= max_data_bytes
;
2456 out_of_space
= False
;
2458 for (i
=0;(i
<maxentries
) && !finished
&& !out_of_space
;i
++) {
2459 bool got_exact_match
= False
;
2461 /* this is a heuristic to avoid seeking the dirptr except when
2462 absolutely necessary. It allows for a filename of about 40 chars */
2463 if (space_remaining
< DIRLEN_GUESS
&& numentries
> 0) {
2464 out_of_space
= True
;
2467 finished
= !get_lanman2_dir_entry(ctx
,
2471 mask
,dirtype
,info_level
,
2472 requires_resume_key
,dont_descend
,
2475 space_remaining
, &out_of_space
,
2477 &last_entry_off
, ea_list
);
2480 if (finished
&& out_of_space
)
2483 if (!finished
&& !out_of_space
)
2487 * As an optimisation if we know we aren't looking
2488 * for a wildcard name (ie. the name matches the wildcard exactly)
2489 * then we can finish on any (first) match.
2490 * This speeds up large directory searches. JRA.
2496 /* Ensure space_remaining never goes -ve. */
2497 if (PTR_DIFF(p
,pdata
) > max_data_bytes
) {
2498 space_remaining
= 0;
2499 out_of_space
= true;
2501 space_remaining
= max_data_bytes
- PTR_DIFF(p
,pdata
);
2505 /* Check if we can close the dirptr */
2506 if(close_after_first
|| (finished
&& close_if_end
)) {
2507 DEBUG(5,("call_trans2findfirst - (2) closing dptr_num %d\n", dptr_num
));
2508 dptr_close(sconn
, &dptr_num
);
2512 * If there are no matching entries we must return ERRDOS/ERRbadfile -
2513 * from observation of NT. NB. This changes to ERRDOS,ERRnofiles if
2514 * the protocol level is less than NT1. Tested with smbclient. JRA.
2515 * This should fix the OS/2 client bug #2335.
2518 if(numentries
== 0) {
2519 dptr_close(sconn
, &dptr_num
);
2520 if (get_Protocol() < PROTOCOL_NT1
) {
2521 reply_force_doserror(req
, ERRDOS
, ERRnofiles
);
2524 reply_botherror(req
, NT_STATUS_NO_SUCH_FILE
,
2525 ERRDOS
, ERRbadfile
);
2530 /* At this point pdata points to numentries directory entries. */
2532 /* Set up the return parameter block */
2533 SSVAL(params
,0,dptr_num
);
2534 SSVAL(params
,2,numentries
);
2535 SSVAL(params
,4,finished
);
2536 SSVAL(params
,6,0); /* Never an EA error */
2537 SSVAL(params
,8,last_entry_off
);
2539 send_trans2_replies(conn
, req
, params
, 10, pdata
, PTR_DIFF(p
,pdata
),
2542 if ((! *directory
) && dptr_path(sconn
, dptr_num
)) {
2543 directory
= talloc_strdup(talloc_tos(),dptr_path(sconn
, dptr_num
));
2545 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2549 DEBUG( 4, ( "%s mask=%s directory=%s dirtype=%d numentries=%d\n",
2550 smb_fn_name(req
->cmd
),
2551 mask
, directory
, dirtype
, numentries
) );
2554 * Force a name mangle here to ensure that the
2555 * mask as an 8.3 name is top of the mangled cache.
2556 * The reasons for this are subtle. Don't remove
2557 * this code unless you know what you are doing
2558 * (see PR#13758). JRA.
2561 if(!mangle_is_8_3_wildcards( mask
, False
, conn
->params
)) {
2562 char mangled_name
[13];
2563 name_to_8_3(mask
, mangled_name
, True
, conn
->params
);
2566 TALLOC_FREE(smb_dname
);
2570 /****************************************************************************
2571 Reply to a TRANS2_FINDNEXT.
2572 ****************************************************************************/
2574 static void call_trans2findnext(connection_struct
*conn
,
2575 struct smb_request
*req
,
2576 char **pparams
, int total_params
,
2577 char **ppdata
, int total_data
,
2578 unsigned int max_data_bytes
)
2580 /* We must be careful here that we don't return more than the
2581 allowed number of data bytes. If this means returning fewer than
2582 maxentries then so be it. We assume that the redirector has
2583 enough room for the fixed number of parameter bytes it has
2585 char *params
= *pparams
;
2586 char *pdata
= *ppdata
;
2592 uint16 findnext_flags
;
2593 bool close_after_request
;
2595 bool requires_resume_key
;
2597 bool mask_contains_wcard
= False
;
2598 char *resume_name
= NULL
;
2599 const char *mask
= NULL
;
2600 const char *directory
= NULL
;
2604 int i
, last_entry_off
=0;
2605 bool finished
= False
;
2606 bool dont_descend
= False
;
2607 bool out_of_space
= False
;
2608 int space_remaining
;
2609 struct ea_list
*ea_list
= NULL
;
2610 NTSTATUS ntstatus
= NT_STATUS_OK
;
2611 bool ask_sharemode
= lp_parm_bool(SNUM(conn
), "smbd", "search ask sharemode", true);
2612 TALLOC_CTX
*ctx
= talloc_tos();
2613 struct dptr_struct
*dirptr
;
2614 struct smbd_server_connection
*sconn
= req
->sconn
;
2616 if (total_params
< 13) {
2617 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2621 dptr_num
= SVAL(params
,0);
2622 maxentries
= SVAL(params
,2);
2623 info_level
= SVAL(params
,4);
2624 resume_key
= IVAL(params
,6);
2625 findnext_flags
= SVAL(params
,10);
2626 close_after_request
= (findnext_flags
& FLAG_TRANS2_FIND_CLOSE
);
2627 close_if_end
= (findnext_flags
& FLAG_TRANS2_FIND_CLOSE_IF_END
);
2628 requires_resume_key
= (findnext_flags
& FLAG_TRANS2_FIND_REQUIRE_RESUME
);
2629 continue_bit
= (findnext_flags
& FLAG_TRANS2_FIND_CONTINUE
);
2631 if (!continue_bit
) {
2632 /* We only need resume_name if continue_bit is zero. */
2633 srvstr_get_path_wcard(ctx
, params
, req
->flags2
, &resume_name
,
2635 total_params
- 12, STR_TERMINATE
, &ntstatus
,
2636 &mask_contains_wcard
);
2637 if (!NT_STATUS_IS_OK(ntstatus
)) {
2638 /* Win9x or OS/2 can send a resume name of ".." or ".". This will cause the parser to
2639 complain (it thinks we're asking for the directory above the shared
2640 path or an invalid name). Catch this as the resume name is only compared, never used in
2641 a file access. JRA. */
2642 srvstr_pull_talloc(ctx
, params
, req
->flags2
,
2643 &resume_name
, params
+12,
2647 if (!resume_name
|| !(ISDOT(resume_name
) || ISDOTDOT(resume_name
))) {
2648 reply_nterror(req
, ntstatus
);
2654 DEBUG(3,("call_trans2findnext: dirhandle = %d, max_data_bytes = %d, maxentries = %d, \
2655 close_after_request=%d, close_if_end = %d requires_resume_key = %d \
2656 resume_key = %d resume name = %s continue=%d level = %d\n",
2657 dptr_num
, max_data_bytes
, maxentries
, close_after_request
, close_if_end
,
2658 requires_resume_key
, resume_key
,
2659 resume_name
? resume_name
: "(NULL)", continue_bit
, info_level
));
2662 /* W2K3 seems to treat zero as 1. */
2666 switch (info_level
) {
2667 case SMB_FIND_INFO_STANDARD
:
2668 case SMB_FIND_EA_SIZE
:
2669 case SMB_FIND_EA_LIST
:
2670 case SMB_FIND_FILE_DIRECTORY_INFO
:
2671 case SMB_FIND_FILE_FULL_DIRECTORY_INFO
:
2672 case SMB_FIND_FILE_NAMES_INFO
:
2673 case SMB_FIND_FILE_BOTH_DIRECTORY_INFO
:
2674 case SMB_FIND_ID_FULL_DIRECTORY_INFO
:
2675 case SMB_FIND_ID_BOTH_DIRECTORY_INFO
:
2677 case SMB_FIND_FILE_UNIX
:
2678 case SMB_FIND_FILE_UNIX_INFO2
:
2679 /* Always use filesystem for UNIX mtime query. */
2680 ask_sharemode
= false;
2681 if (!lp_unix_extensions()) {
2682 reply_nterror(req
, NT_STATUS_INVALID_LEVEL
);
2687 reply_nterror(req
, NT_STATUS_INVALID_LEVEL
);
2691 if (info_level
== SMB_FIND_EA_LIST
) {
2694 if (total_data
< 4) {
2695 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2699 ea_size
= IVAL(pdata
,0);
2700 if (ea_size
!= total_data
) {
2701 DEBUG(4,("call_trans2findnext: Rejecting EA request with incorrect \
2702 total_data=%u (should be %u)\n", (unsigned int)total_data
, (unsigned int)IVAL(pdata
,0) ));
2703 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2707 if (!lp_ea_support(SNUM(conn
))) {
2708 reply_nterror(req
, NT_STATUS_EAS_NOT_SUPPORTED
);
2712 /* Pull out the list of names. */
2713 ea_list
= read_ea_name_list(ctx
, pdata
+ 4, ea_size
- 4);
2715 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2720 *ppdata
= (char *)SMB_REALLOC(
2721 *ppdata
, max_data_bytes
+ DIR_ENTRY_SAFETY_MARGIN
);
2722 if(*ppdata
== NULL
) {
2723 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2728 data_end
= pdata
+ max_data_bytes
+ DIR_ENTRY_SAFETY_MARGIN
- 1;
2730 /* Realloc the params space */
2731 *pparams
= (char *)SMB_REALLOC(*pparams
, 6*SIZEOFWORD
);
2732 if(*pparams
== NULL
) {
2733 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2739 /* Check that the dptr is valid */
2740 if(!(dirptr
= dptr_fetch_lanman2(sconn
, dptr_num
))) {
2741 reply_nterror(req
, STATUS_NO_MORE_FILES
);
2745 directory
= dptr_path(sconn
, dptr_num
);
2747 /* Get the wildcard mask from the dptr */
2748 if((p
= dptr_wcard(sconn
, dptr_num
))== NULL
) {
2749 DEBUG(2,("dptr_num %d has no wildcard\n", dptr_num
));
2750 reply_nterror(req
, STATUS_NO_MORE_FILES
);
2756 /* Get the attr mask from the dptr */
2757 dirtype
= dptr_attr(sconn
, dptr_num
);
2759 DEBUG(3,("dptr_num is %d, mask = %s, attr = %x, dirptr=(0x%lX,%ld)\n",
2760 dptr_num
, mask
, dirtype
,
2762 dptr_TellDir(dirptr
)));
2764 /* Initialize per TRANS2_FIND_NEXT operation data */
2765 dptr_init_search_op(dirptr
);
2767 /* We don't need to check for VOL here as this is returned by
2768 a different TRANS2 call. */
2770 DEBUG(8,("dirpath=<%s> dontdescend=<%s>\n",
2771 directory
,lp_dontdescend(SNUM(conn
))));
2772 if (in_list(directory
,lp_dontdescend(SNUM(conn
)),conn
->case_sensitive
))
2773 dont_descend
= True
;
2776 space_remaining
= max_data_bytes
;
2777 out_of_space
= False
;
2780 * Seek to the correct position. We no longer use the resume key but
2781 * depend on the last file name instead.
2784 if(!continue_bit
&& resume_name
&& *resume_name
) {
2787 long current_pos
= 0;
2789 * Remember, name_to_8_3 is called by
2790 * get_lanman2_dir_entry(), so the resume name
2791 * could be mangled. Ensure we check the unmangled name.
2794 if (mangle_is_mangled(resume_name
, conn
->params
)) {
2795 char *new_resume_name
= NULL
;
2796 mangle_lookup_name_from_8_3(ctx
,
2800 if (new_resume_name
) {
2801 resume_name
= new_resume_name
;
2806 * Fix for NT redirector problem triggered by resume key indexes
2807 * changing between directory scans. We now return a resume key of 0
2808 * and instead look for the filename to continue from (also given
2809 * to us by NT/95/smbfs/smbclient). If no other scans have been done between the
2810 * findfirst/findnext (as is usual) then the directory pointer
2811 * should already be at the correct place.
2814 finished
= !dptr_SearchDir(dirptr
, resume_name
, ¤t_pos
, &st
);
2815 } /* end if resume_name && !continue_bit */
2817 for (i
=0;(i
<(int)maxentries
) && !finished
&& !out_of_space
;i
++) {
2818 bool got_exact_match
= False
;
2820 /* this is a heuristic to avoid seeking the dirptr except when
2821 absolutely necessary. It allows for a filename of about 40 chars */
2822 if (space_remaining
< DIRLEN_GUESS
&& numentries
> 0) {
2823 out_of_space
= True
;
2826 finished
= !get_lanman2_dir_entry(ctx
,
2830 mask
,dirtype
,info_level
,
2831 requires_resume_key
,dont_descend
,
2834 space_remaining
, &out_of_space
,
2836 &last_entry_off
, ea_list
);
2839 if (finished
&& out_of_space
)
2842 if (!finished
&& !out_of_space
)
2846 * As an optimisation if we know we aren't looking
2847 * for a wildcard name (ie. the name matches the wildcard exactly)
2848 * then we can finish on any (first) match.
2849 * This speeds up large directory searches. JRA.
2855 space_remaining
= max_data_bytes
- PTR_DIFF(p
,pdata
);
2858 DEBUG( 3, ( "%s mask=%s directory=%s dirtype=%d numentries=%d\n",
2859 smb_fn_name(req
->cmd
),
2860 mask
, directory
, dirtype
, numentries
) );
2862 /* Check if we can close the dirptr */
2863 if(close_after_request
|| (finished
&& close_if_end
)) {
2864 DEBUG(5,("call_trans2findnext: closing dptr_num = %d\n", dptr_num
));
2865 dptr_close(sconn
, &dptr_num
); /* This frees up the saved mask */
2868 /* Set up the return parameter block */
2869 SSVAL(params
,0,numentries
);
2870 SSVAL(params
,2,finished
);
2871 SSVAL(params
,4,0); /* Never an EA error */
2872 SSVAL(params
,6,last_entry_off
);
2874 send_trans2_replies(conn
, req
, params
, 8, pdata
, PTR_DIFF(p
,pdata
),
2880 unsigned char *create_volume_objectid(connection_struct
*conn
, unsigned char objid
[16])
2882 E_md4hash(lp_servicename(SNUM(conn
)),objid
);
2886 static void samba_extended_info_version(struct smb_extended_info
*extended_info
)
2888 SMB_ASSERT(extended_info
!= NULL
);
2890 extended_info
->samba_magic
= SAMBA_EXTENDED_INFO_MAGIC
;
2891 extended_info
->samba_version
= ((SAMBA_VERSION_MAJOR
& 0xff) << 24)
2892 | ((SAMBA_VERSION_MINOR
& 0xff) << 16)
2893 | ((SAMBA_VERSION_RELEASE
& 0xff) << 8);
2894 #ifdef SAMBA_VERSION_REVISION
2895 extended_info
->samba_version
|= (tolower(*SAMBA_VERSION_REVISION
) - 'a' + 1) & 0xff;
2897 extended_info
->samba_subversion
= 0;
2898 #ifdef SAMBA_VERSION_RC_RELEASE
2899 extended_info
->samba_subversion
|= (SAMBA_VERSION_RC_RELEASE
& 0xff) << 24;
2901 #ifdef SAMBA_VERSION_PRE_RELEASE
2902 extended_info
->samba_subversion
|= (SAMBA_VERSION_PRE_RELEASE
& 0xff) << 16;
2905 #ifdef SAMBA_VERSION_VENDOR_PATCH
2906 extended_info
->samba_subversion
|= (SAMBA_VERSION_VENDOR_PATCH
& 0xffff);
2908 extended_info
->samba_gitcommitdate
= 0;
2909 #ifdef SAMBA_VERSION_COMMIT_TIME
2910 unix_to_nt_time(&extended_info
->samba_gitcommitdate
, SAMBA_VERSION_COMMIT_TIME
);
2913 memset(extended_info
->samba_version_string
, 0,
2914 sizeof(extended_info
->samba_version_string
));
2916 snprintf (extended_info
->samba_version_string
,
2917 sizeof(extended_info
->samba_version_string
),
2918 "%s", samba_version_string());
2921 NTSTATUS
smbd_do_qfsinfo(connection_struct
*conn
,
2922 TALLOC_CTX
*mem_ctx
,
2923 uint16_t info_level
,
2925 unsigned int max_data_bytes
,
2929 char *pdata
, *end_data
;
2930 int data_len
= 0, len
;
2931 const char *vname
= volume_label(SNUM(conn
));
2932 int snum
= SNUM(conn
);
2933 char *fstype
= lp_fstype(SNUM(conn
));
2934 uint32 additional_flags
= 0;
2935 struct smb_filename smb_fname_dot
;
2939 if (info_level
!= SMB_QUERY_CIFS_UNIX_INFO
) {
2940 DEBUG(0,("smbd_do_qfsinfo: not an allowed "
2941 "info level (0x%x) on IPC$.\n",
2942 (unsigned int)info_level
));
2943 return NT_STATUS_ACCESS_DENIED
;
2947 DEBUG(3,("smbd_do_qfsinfo: level = %d\n", info_level
));
2949 ZERO_STRUCT(smb_fname_dot
);
2950 smb_fname_dot
.base_name
= discard_const_p(char, ".");
2952 if(SMB_VFS_STAT(conn
, &smb_fname_dot
) != 0) {
2953 DEBUG(2,("stat of . failed (%s)\n", strerror(errno
)));
2954 return map_nt_error_from_unix(errno
);
2957 st
= smb_fname_dot
.st
;
2959 *ppdata
= (char *)SMB_REALLOC(
2960 *ppdata
, max_data_bytes
+ DIR_ENTRY_SAFETY_MARGIN
);
2961 if (*ppdata
== NULL
) {
2962 return NT_STATUS_NO_MEMORY
;
2966 memset((char *)pdata
,'\0',max_data_bytes
+ DIR_ENTRY_SAFETY_MARGIN
);
2967 end_data
= pdata
+ max_data_bytes
+ DIR_ENTRY_SAFETY_MARGIN
- 1;
2969 switch (info_level
) {
2970 case SMB_INFO_ALLOCATION
:
2972 uint64_t dfree
,dsize
,bsize
,block_size
,sectors_per_unit
,bytes_per_sector
;
2974 if (get_dfree_info(conn
,".",False
,&bsize
,&dfree
,&dsize
) == (uint64_t)-1) {
2975 return map_nt_error_from_unix(errno
);
2978 block_size
= lp_block_size(snum
);
2979 if (bsize
< block_size
) {
2980 uint64_t factor
= block_size
/bsize
;
2985 if (bsize
> block_size
) {
2986 uint64_t factor
= bsize
/block_size
;
2991 bytes_per_sector
= 512;
2992 sectors_per_unit
= bsize
/bytes_per_sector
;
2994 DEBUG(5,("smbd_do_qfsinfo : SMB_INFO_ALLOCATION id=%x, bsize=%u, cSectorUnit=%u, \
2995 cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", (unsigned int)st
.st_ex_dev
, (unsigned int)bsize
, (unsigned int)sectors_per_unit
,
2996 (unsigned int)bytes_per_sector
, (unsigned int)dsize
, (unsigned int)dfree
));
2998 SIVAL(pdata
,l1_idFileSystem
,st
.st_ex_dev
);
2999 SIVAL(pdata
,l1_cSectorUnit
,sectors_per_unit
);
3000 SIVAL(pdata
,l1_cUnit
,dsize
);
3001 SIVAL(pdata
,l1_cUnitAvail
,dfree
);
3002 SSVAL(pdata
,l1_cbSector
,bytes_per_sector
);
3006 case SMB_INFO_VOLUME
:
3007 /* Return volume name */
3009 * Add volume serial number - hash of a combination of
3010 * the called hostname and the service name.
3012 SIVAL(pdata
,0,str_checksum(lp_servicename(snum
)) ^ (str_checksum(get_local_machine_name())<<16) );
3014 * Win2k3 and previous mess this up by sending a name length
3015 * one byte short. I believe only older clients (OS/2 Win9x) use
3016 * this call so try fixing this by adding a terminating null to
3017 * the pushed string. The change here was adding the STR_TERMINATE. JRA.
3021 pdata
+l2_vol_szVolLabel
, vname
,
3022 PTR_DIFF(end_data
, pdata
+l2_vol_szVolLabel
),
3023 STR_NOALIGN
|STR_TERMINATE
);
3024 SCVAL(pdata
,l2_vol_cch
,len
);
3025 data_len
= l2_vol_szVolLabel
+ len
;
3026 DEBUG(5,("smbd_do_qfsinfo : time = %x, namelen = %d, name = %s\n",
3027 (unsigned)convert_timespec_to_time_t(st
.st_ex_ctime
),
3031 case SMB_QUERY_FS_ATTRIBUTE_INFO
:
3032 case SMB_FS_ATTRIBUTE_INFORMATION
:
3034 additional_flags
= 0;
3035 #if defined(HAVE_SYS_QUOTAS)
3036 additional_flags
|= FILE_VOLUME_QUOTAS
;
3039 if(lp_nt_acl_support(SNUM(conn
))) {
3040 additional_flags
|= FILE_PERSISTENT_ACLS
;
3043 /* Capabilities are filled in at connection time through STATVFS call */
3044 additional_flags
|= conn
->fs_capabilities
;
3045 additional_flags
|= lp_parm_int(conn
->params
->service
,
3046 "share", "fake_fscaps",
3049 SIVAL(pdata
,0,FILE_CASE_PRESERVED_NAMES
|FILE_CASE_SENSITIVE_SEARCH
|
3050 FILE_SUPPORTS_OBJECT_IDS
|FILE_UNICODE_ON_DISK
|
3051 additional_flags
); /* FS ATTRIBUTES */
3053 SIVAL(pdata
,4,255); /* Max filename component length */
3054 /* NOTE! the fstype must *not* be null terminated or win98 won't recognise it
3055 and will think we can't do long filenames */
3056 len
= srvstr_push(pdata
, flags2
, pdata
+12, fstype
,
3057 PTR_DIFF(end_data
, pdata
+12),
3060 data_len
= 12 + len
;
3063 case SMB_QUERY_FS_LABEL_INFO
:
3064 case SMB_FS_LABEL_INFORMATION
:
3065 len
= srvstr_push(pdata
, flags2
, pdata
+4, vname
,
3066 PTR_DIFF(end_data
, pdata
+4), 0);
3071 case SMB_QUERY_FS_VOLUME_INFO
:
3072 case SMB_FS_VOLUME_INFORMATION
:
3075 * Add volume serial number - hash of a combination of
3076 * the called hostname and the service name.
3078 SIVAL(pdata
,8,str_checksum(lp_servicename(snum
)) ^
3079 (str_checksum(get_local_machine_name())<<16));
3081 /* Max label len is 32 characters. */
3082 len
= srvstr_push(pdata
, flags2
, pdata
+18, vname
,
3083 PTR_DIFF(end_data
, pdata
+18),
3085 SIVAL(pdata
,12,len
);
3088 DEBUG(5,("smbd_do_qfsinfo : SMB_QUERY_FS_VOLUME_INFO namelen = %d, vol=%s serv=%s\n",
3089 (int)strlen(vname
),vname
, lp_servicename(snum
)));
3092 case SMB_QUERY_FS_SIZE_INFO
:
3093 case SMB_FS_SIZE_INFORMATION
:
3095 uint64_t dfree
,dsize
,bsize
,block_size
,sectors_per_unit
,bytes_per_sector
;
3097 if (get_dfree_info(conn
,".",False
,&bsize
,&dfree
,&dsize
) == (uint64_t)-1) {
3098 return map_nt_error_from_unix(errno
);
3100 block_size
= lp_block_size(snum
);
3101 if (bsize
< block_size
) {
3102 uint64_t factor
= block_size
/bsize
;
3107 if (bsize
> block_size
) {
3108 uint64_t factor
= bsize
/block_size
;
3113 bytes_per_sector
= 512;
3114 sectors_per_unit
= bsize
/bytes_per_sector
;
3115 DEBUG(5,("smbd_do_qfsinfo : SMB_QUERY_FS_SIZE_INFO bsize=%u, cSectorUnit=%u, \
3116 cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", (unsigned int)bsize
, (unsigned int)sectors_per_unit
,
3117 (unsigned int)bytes_per_sector
, (unsigned int)dsize
, (unsigned int)dfree
));
3118 SBIG_UINT(pdata
,0,dsize
);
3119 SBIG_UINT(pdata
,8,dfree
);
3120 SIVAL(pdata
,16,sectors_per_unit
);
3121 SIVAL(pdata
,20,bytes_per_sector
);
3125 case SMB_FS_FULL_SIZE_INFORMATION
:
3127 uint64_t dfree
,dsize
,bsize
,block_size
,sectors_per_unit
,bytes_per_sector
;
3129 if (get_dfree_info(conn
,".",False
,&bsize
,&dfree
,&dsize
) == (uint64_t)-1) {
3130 return map_nt_error_from_unix(errno
);
3132 block_size
= lp_block_size(snum
);
3133 if (bsize
< block_size
) {
3134 uint64_t factor
= block_size
/bsize
;
3139 if (bsize
> block_size
) {
3140 uint64_t factor
= bsize
/block_size
;
3145 bytes_per_sector
= 512;
3146 sectors_per_unit
= bsize
/bytes_per_sector
;
3147 DEBUG(5,("smbd_do_qfsinfo : SMB_QUERY_FS_FULL_SIZE_INFO bsize=%u, cSectorUnit=%u, \
3148 cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", (unsigned int)bsize
, (unsigned int)sectors_per_unit
,
3149 (unsigned int)bytes_per_sector
, (unsigned int)dsize
, (unsigned int)dfree
));
3150 SBIG_UINT(pdata
,0,dsize
); /* Total Allocation units. */
3151 SBIG_UINT(pdata
,8,dfree
); /* Caller available allocation units. */
3152 SBIG_UINT(pdata
,16,dfree
); /* Actual available allocation units. */
3153 SIVAL(pdata
,24,sectors_per_unit
); /* Sectors per allocation unit. */
3154 SIVAL(pdata
,28,bytes_per_sector
); /* Bytes per sector. */
3158 case SMB_QUERY_FS_DEVICE_INFO
:
3159 case SMB_FS_DEVICE_INFORMATION
:
3161 uint32_t characteristics
= FILE_DEVICE_IS_MOUNTED
;
3163 if (!CAN_WRITE(conn
)) {
3164 characteristics
|= FILE_READ_ONLY_DEVICE
;
3167 SIVAL(pdata
,0,FILE_DEVICE_DISK
); /* dev type */
3168 SIVAL(pdata
,4,characteristics
);
3172 #ifdef HAVE_SYS_QUOTAS
3173 case SMB_FS_QUOTA_INFORMATION
:
3175 * what we have to send --metze:
3177 * Unknown1: 24 NULL bytes
3178 * Soft Quota Treshold: 8 bytes seems like uint64_t or so
3179 * Hard Quota Limit: 8 bytes seems like uint64_t or so
3180 * Quota Flags: 2 byte :
3181 * Unknown3: 6 NULL bytes
3185 * details for Quota Flags:
3187 * 0x0020 Log Limit: log if the user exceeds his Hard Quota
3188 * 0x0010 Log Warn: log if the user exceeds his Soft Quota
3189 * 0x0002 Deny Disk: deny disk access when the user exceeds his Hard Quota
3190 * 0x0001 Enable Quotas: enable quota for this fs
3194 /* we need to fake up a fsp here,
3195 * because its not send in this call
3198 SMB_NTQUOTA_STRUCT quotas
;
3201 ZERO_STRUCT(quotas
);
3207 if (get_current_uid(conn
) != 0) {
3208 DEBUG(0,("set_user_quota: access_denied "
3209 "service [%s] user [%s]\n",
3210 lp_servicename(SNUM(conn
)),
3211 conn
->session_info
->unix_name
));
3212 return NT_STATUS_ACCESS_DENIED
;
3215 if (vfs_get_ntquota(&fsp
, SMB_USER_FS_QUOTA_TYPE
, NULL
, "as
)!=0) {
3216 DEBUG(0,("vfs_get_ntquota() failed for service [%s]\n",lp_servicename(SNUM(conn
))));
3217 return map_nt_error_from_unix(errno
);
3222 DEBUG(10,("SMB_FS_QUOTA_INFORMATION: for service [%s]\n",
3223 lp_servicename(SNUM(conn
))));
3225 /* Unknown1 24 NULL bytes*/
3226 SBIG_UINT(pdata
,0,(uint64_t)0);
3227 SBIG_UINT(pdata
,8,(uint64_t)0);
3228 SBIG_UINT(pdata
,16,(uint64_t)0);
3230 /* Default Soft Quota 8 bytes */
3231 SBIG_UINT(pdata
,24,quotas
.softlim
);
3233 /* Default Hard Quota 8 bytes */
3234 SBIG_UINT(pdata
,32,quotas
.hardlim
);
3236 /* Quota flag 2 bytes */
3237 SSVAL(pdata
,40,quotas
.qflags
);
3239 /* Unknown3 6 NULL bytes */
3245 #endif /* HAVE_SYS_QUOTAS */
3246 case SMB_FS_OBJECTID_INFORMATION
:
3248 unsigned char objid
[16];
3249 struct smb_extended_info extended_info
;
3250 memcpy(pdata
,create_volume_objectid(conn
, objid
),16);
3251 samba_extended_info_version (&extended_info
);
3252 SIVAL(pdata
,16,extended_info
.samba_magic
);
3253 SIVAL(pdata
,20,extended_info
.samba_version
);
3254 SIVAL(pdata
,24,extended_info
.samba_subversion
);
3255 SBIG_UINT(pdata
,28,extended_info
.samba_gitcommitdate
);
3256 memcpy(pdata
+36,extended_info
.samba_version_string
,28);
3262 * Query the version and capabilities of the CIFS UNIX extensions
3266 case SMB_QUERY_CIFS_UNIX_INFO
:
3268 bool large_write
= lp_min_receive_file_size() &&
3269 !srv_is_signing_active(conn
->sconn
);
3270 bool large_read
= !srv_is_signing_active(conn
->sconn
);
3271 int encrypt_caps
= 0;
3273 if (!lp_unix_extensions()) {
3274 return NT_STATUS_INVALID_LEVEL
;
3277 switch (conn
->encrypt_level
) {
3283 encrypt_caps
= CIFS_UNIX_TRANSPORT_ENCRYPTION_CAP
;
3286 encrypt_caps
= CIFS_UNIX_TRANSPORT_ENCRYPTION_CAP
|
3287 CIFS_UNIX_TRANSPORT_ENCRYPTION_MANDATORY_CAP
;
3288 large_write
= false;
3294 SSVAL(pdata
,0,CIFS_UNIX_MAJOR_VERSION
);
3295 SSVAL(pdata
,2,CIFS_UNIX_MINOR_VERSION
);
3297 /* We have POSIX ACLs, pathname, encryption,
3298 * large read/write, and locking capability. */
3300 SBIG_UINT(pdata
,4,((uint64_t)(
3301 CIFS_UNIX_POSIX_ACLS_CAP
|
3302 CIFS_UNIX_POSIX_PATHNAMES_CAP
|
3303 CIFS_UNIX_FCNTL_LOCKS_CAP
|
3304 CIFS_UNIX_EXTATTR_CAP
|
3305 CIFS_UNIX_POSIX_PATH_OPERATIONS_CAP
|
3307 (large_read
? CIFS_UNIX_LARGE_READ_CAP
: 0) |
3309 CIFS_UNIX_LARGE_WRITE_CAP
: 0))));
3313 case SMB_QUERY_POSIX_FS_INFO
:
3316 vfs_statvfs_struct svfs
;
3318 if (!lp_unix_extensions()) {
3319 return NT_STATUS_INVALID_LEVEL
;
3322 rc
= SMB_VFS_STATVFS(conn
, ".", &svfs
);
3326 SIVAL(pdata
,0,svfs
.OptimalTransferSize
);
3327 SIVAL(pdata
,4,svfs
.BlockSize
);
3328 SBIG_UINT(pdata
,8,svfs
.TotalBlocks
);
3329 SBIG_UINT(pdata
,16,svfs
.BlocksAvail
);
3330 SBIG_UINT(pdata
,24,svfs
.UserBlocksAvail
);
3331 SBIG_UINT(pdata
,32,svfs
.TotalFileNodes
);
3332 SBIG_UINT(pdata
,40,svfs
.FreeFileNodes
);
3333 SBIG_UINT(pdata
,48,svfs
.FsIdentifier
);
3334 DEBUG(5,("smbd_do_qfsinfo : SMB_QUERY_POSIX_FS_INFO succsessful\n"));
3336 } else if (rc
== EOPNOTSUPP
) {
3337 return NT_STATUS_INVALID_LEVEL
;
3338 #endif /* EOPNOTSUPP */
3340 DEBUG(0,("vfs_statvfs() failed for service [%s]\n",lp_servicename(SNUM(conn
))));
3341 return NT_STATUS_DOS(ERRSRV
, ERRerror
);
3346 case SMB_QUERY_POSIX_WHOAMI
:
3352 if (!lp_unix_extensions()) {
3353 return NT_STATUS_INVALID_LEVEL
;
3356 if (max_data_bytes
< 40) {
3357 return NT_STATUS_BUFFER_TOO_SMALL
;
3360 /* We ARE guest if global_sid_Builtin_Guests is
3361 * in our list of SIDs.
3363 if (nt_token_check_sid(&global_sid_Builtin_Guests
,
3364 conn
->session_info
->security_token
)) {
3365 flags
|= SMB_WHOAMI_GUEST
;
3368 /* We are NOT guest if global_sid_Authenticated_Users
3369 * is in our list of SIDs.
3371 if (nt_token_check_sid(&global_sid_Authenticated_Users
,
3372 conn
->session_info
->security_token
)) {
3373 flags
&= ~SMB_WHOAMI_GUEST
;
3376 /* NOTE: 8 bytes for UID/GID, irrespective of native
3377 * platform size. This matches
3378 * SMB_QUERY_FILE_UNIX_BASIC and friends.
3380 data_len
= 4 /* flags */
3387 + 4 /* pad/reserved */
3388 + (conn
->session_info
->utok
.ngroups
* 8)
3390 + (conn
->session_info
->security_token
->num_sids
*
3394 SIVAL(pdata
, 0, flags
);
3395 SIVAL(pdata
, 4, SMB_WHOAMI_MASK
);
3397 (uint64_t)conn
->session_info
->utok
.uid
);
3398 SBIG_UINT(pdata
, 16,
3399 (uint64_t)conn
->session_info
->utok
.gid
);
3402 if (data_len
>= max_data_bytes
) {
3403 /* Potential overflow, skip the GIDs and SIDs. */
3405 SIVAL(pdata
, 24, 0); /* num_groups */
3406 SIVAL(pdata
, 28, 0); /* num_sids */
3407 SIVAL(pdata
, 32, 0); /* num_sid_bytes */
3408 SIVAL(pdata
, 36, 0); /* reserved */
3414 SIVAL(pdata
, 24, conn
->session_info
->utok
.ngroups
);
3415 SIVAL(pdata
, 28, conn
->session_info
->security_token
->num_sids
);
3417 /* We walk the SID list twice, but this call is fairly
3418 * infrequent, and I don't expect that it's performance
3419 * sensitive -- jpeach
3421 for (i
= 0, sid_bytes
= 0;
3422 i
< conn
->session_info
->security_token
->num_sids
; ++i
) {
3423 sid_bytes
+= ndr_size_dom_sid(
3424 &conn
->session_info
->security_token
->sids
[i
],
3428 /* SID list byte count */
3429 SIVAL(pdata
, 32, sid_bytes
);
3431 /* 4 bytes pad/reserved - must be zero */
3432 SIVAL(pdata
, 36, 0);
3436 for (i
= 0; i
< conn
->session_info
->utok
.ngroups
; ++i
) {
3437 SBIG_UINT(pdata
, data_len
,
3438 (uint64_t)conn
->session_info
->utok
.groups
[i
]);
3444 i
< conn
->session_info
->security_token
->num_sids
; ++i
) {
3445 int sid_len
= ndr_size_dom_sid(
3446 &conn
->session_info
->security_token
->sids
[i
],
3449 sid_linearize(pdata
+ data_len
, sid_len
,
3450 &conn
->session_info
->security_token
->sids
[i
]);
3451 data_len
+= sid_len
;
3457 case SMB_MAC_QUERY_FS_INFO
:
3459 * Thursby MAC extension... ONLY on NTFS filesystems
3460 * once we do streams then we don't need this
3462 if (strequal(lp_fstype(SNUM(conn
)),"NTFS")) {
3464 SIVAL(pdata
,84,0x100); /* Don't support mac... */
3469 return NT_STATUS_INVALID_LEVEL
;
3472 *ret_data_len
= data_len
;
3473 return NT_STATUS_OK
;
3476 /****************************************************************************
3477 Reply to a TRANS2_QFSINFO (query filesystem info).
3478 ****************************************************************************/
3480 static void call_trans2qfsinfo(connection_struct
*conn
,
3481 struct smb_request
*req
,
3482 char **pparams
, int total_params
,
3483 char **ppdata
, int total_data
,
3484 unsigned int max_data_bytes
)
3486 char *params
= *pparams
;
3487 uint16_t info_level
;
3491 if (total_params
< 2) {
3492 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
3496 info_level
= SVAL(params
,0);
3498 if (ENCRYPTION_REQUIRED(conn
) && !req
->encrypted
) {
3499 if (info_level
!= SMB_QUERY_CIFS_UNIX_INFO
) {
3500 DEBUG(0,("call_trans2qfsinfo: encryption required "
3501 "and info level 0x%x sent.\n",
3502 (unsigned int)info_level
));
3503 exit_server_cleanly("encryption required "
3509 DEBUG(3,("call_trans2qfsinfo: level = %d\n", info_level
));
3511 status
= smbd_do_qfsinfo(conn
, req
,
3516 if (!NT_STATUS_IS_OK(status
)) {
3517 reply_nterror(req
, status
);
3521 send_trans2_replies(conn
, req
, params
, 0, *ppdata
, data_len
,
3524 DEBUG( 4, ( "%s info_level = %d\n",
3525 smb_fn_name(req
->cmd
), info_level
) );
3530 /****************************************************************************
3531 Reply to a TRANS2_SETFSINFO (set filesystem info).
3532 ****************************************************************************/
3534 static void call_trans2setfsinfo(connection_struct
*conn
,
3535 struct smb_request
*req
,
3536 char **pparams
, int total_params
,
3537 char **ppdata
, int total_data
,
3538 unsigned int max_data_bytes
)
3540 char *pdata
= *ppdata
;
3541 char *params
= *pparams
;
3544 DEBUG(10,("call_trans2setfsinfo: for service [%s]\n",lp_servicename(SNUM(conn
))));
3547 if (total_params
< 4) {
3548 DEBUG(0,("call_trans2setfsinfo: requires total_params(%d) >= 4 bytes!\n",
3550 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
3554 info_level
= SVAL(params
,2);
3557 if (info_level
!= SMB_REQUEST_TRANSPORT_ENCRYPTION
&&
3558 info_level
!= SMB_SET_CIFS_UNIX_INFO
) {
3559 DEBUG(0,("call_trans2setfsinfo: not an allowed "
3560 "info level (0x%x) on IPC$.\n",
3561 (unsigned int)info_level
));
3562 reply_nterror(req
, NT_STATUS_ACCESS_DENIED
);
3567 if (ENCRYPTION_REQUIRED(conn
) && !req
->encrypted
) {
3568 if (info_level
!= SMB_REQUEST_TRANSPORT_ENCRYPTION
) {
3569 DEBUG(0,("call_trans2setfsinfo: encryption required "
3570 "and info level 0x%x sent.\n",
3571 (unsigned int)info_level
));
3572 exit_server_cleanly("encryption required "
3578 switch(info_level
) {
3579 case SMB_SET_CIFS_UNIX_INFO
:
3581 uint16 client_unix_major
;
3582 uint16 client_unix_minor
;
3583 uint32 client_unix_cap_low
;
3584 uint32 client_unix_cap_high
;
3586 if (!lp_unix_extensions()) {
3588 NT_STATUS_INVALID_LEVEL
);
3592 /* There should be 12 bytes of capabilities set. */
3593 if (total_data
< 8) {
3596 NT_STATUS_INVALID_PARAMETER
);
3599 client_unix_major
= SVAL(pdata
,0);
3600 client_unix_minor
= SVAL(pdata
,2);
3601 client_unix_cap_low
= IVAL(pdata
,4);
3602 client_unix_cap_high
= IVAL(pdata
,8);
3603 /* Just print these values for now. */
3604 DEBUG(10,("call_trans2setfsinfo: set unix info. major = %u, minor = %u \
3605 cap_low = 0x%x, cap_high = 0x%x\n",
3606 (unsigned int)client_unix_major
,
3607 (unsigned int)client_unix_minor
,
3608 (unsigned int)client_unix_cap_low
,
3609 (unsigned int)client_unix_cap_high
));
3611 /* Here is where we must switch to posix pathname processing... */
3612 if (client_unix_cap_low
& CIFS_UNIX_POSIX_PATHNAMES_CAP
) {
3613 lp_set_posix_pathnames();
3614 mangle_change_to_posix();
3617 if ((client_unix_cap_low
& CIFS_UNIX_FCNTL_LOCKS_CAP
) &&
3618 !(client_unix_cap_low
& CIFS_UNIX_POSIX_PATH_OPERATIONS_CAP
)) {
3619 /* Client that knows how to do posix locks,
3620 * but not posix open/mkdir operations. Set a
3621 * default type for read/write checks. */
3623 lp_set_posix_default_cifsx_readwrite_locktype(POSIX_LOCK
);
3629 case SMB_REQUEST_TRANSPORT_ENCRYPTION
:
3632 size_t param_len
= 0;
3633 size_t data_len
= total_data
;
3635 if (!lp_unix_extensions()) {
3638 NT_STATUS_INVALID_LEVEL
);
3642 if (lp_smb_encrypt(SNUM(conn
)) == false) {
3645 NT_STATUS_NOT_SUPPORTED
);
3649 if (req
->sconn
->smb1
.echo_handler
.trusted_fde
) {
3650 DEBUG( 2,("call_trans2setfsinfo: "
3651 "request transport encryption disabled"
3652 "with 'fork echo handler = yes'\n"));
3655 NT_STATUS_NOT_SUPPORTED
);
3659 DEBUG( 4,("call_trans2setfsinfo: "
3660 "request transport encryption.\n"));
3662 status
= srv_request_encryption_setup(conn
,
3663 (unsigned char **)ppdata
,
3665 (unsigned char **)pparams
,
3668 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
) &&
3669 !NT_STATUS_IS_OK(status
)) {
3670 reply_nterror(req
, status
);
3674 send_trans2_replies(conn
, req
,
3681 if (NT_STATUS_IS_OK(status
)) {
3682 /* Server-side transport
3683 * encryption is now *on*. */
3684 status
= srv_encryption_start(conn
);
3685 if (!NT_STATUS_IS_OK(status
)) {
3686 exit_server_cleanly(
3687 "Failure in setting "
3688 "up encrypted transport");
3694 case SMB_FS_QUOTA_INFORMATION
:
3696 files_struct
*fsp
= NULL
;
3697 SMB_NTQUOTA_STRUCT quotas
;
3699 ZERO_STRUCT(quotas
);
3702 if ((get_current_uid(conn
) != 0) || !CAN_WRITE(conn
)) {
3703 DEBUG(0,("set_user_quota: access_denied service [%s] user [%s]\n",
3704 lp_servicename(SNUM(conn
)),
3705 conn
->session_info
->unix_name
));
3706 reply_nterror(req
, NT_STATUS_ACCESS_DENIED
);
3710 /* note: normaly there're 48 bytes,
3711 * but we didn't use the last 6 bytes for now
3714 fsp
= file_fsp(req
, SVAL(params
,0));
3716 if (!check_fsp_ntquota_handle(conn
, req
,
3718 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
3720 req
, NT_STATUS_INVALID_HANDLE
);
3724 if (total_data
< 42) {
3725 DEBUG(0,("call_trans2setfsinfo: SET_FS_QUOTA: requires total_data(%d) >= 42 bytes!\n",
3729 NT_STATUS_INVALID_PARAMETER
);
3733 /* unknown_1 24 NULL bytes in pdata*/
3735 /* the soft quotas 8 bytes (uint64_t)*/
3736 quotas
.softlim
= (uint64_t)IVAL(pdata
,24);
3737 #ifdef LARGE_SMB_OFF_T
3738 quotas
.softlim
|= (((uint64_t)IVAL(pdata
,28)) << 32);
3739 #else /* LARGE_SMB_OFF_T */
3740 if ((IVAL(pdata
,28) != 0)&&
3741 ((quotas
.softlim
!= 0xFFFFFFFF)||
3742 (IVAL(pdata
,28)!=0xFFFFFFFF))) {
3743 /* more than 32 bits? */
3746 NT_STATUS_INVALID_PARAMETER
);
3749 #endif /* LARGE_SMB_OFF_T */
3751 /* the hard quotas 8 bytes (uint64_t)*/
3752 quotas
.hardlim
= (uint64_t)IVAL(pdata
,32);
3753 #ifdef LARGE_SMB_OFF_T
3754 quotas
.hardlim
|= (((uint64_t)IVAL(pdata
,36)) << 32);
3755 #else /* LARGE_SMB_OFF_T */
3756 if ((IVAL(pdata
,36) != 0)&&
3757 ((quotas
.hardlim
!= 0xFFFFFFFF)||
3758 (IVAL(pdata
,36)!=0xFFFFFFFF))) {
3759 /* more than 32 bits? */
3762 NT_STATUS_INVALID_PARAMETER
);
3765 #endif /* LARGE_SMB_OFF_T */
3767 /* quota_flags 2 bytes **/
3768 quotas
.qflags
= SVAL(pdata
,40);
3770 /* unknown_2 6 NULL bytes follow*/
3772 /* now set the quotas */
3773 if (vfs_set_ntquota(fsp
, SMB_USER_FS_QUOTA_TYPE
, NULL
, "as
)!=0) {
3774 DEBUG(0,("vfs_set_ntquota() failed for service [%s]\n",lp_servicename(SNUM(conn
))));
3775 reply_nterror(req
, map_nt_error_from_unix(errno
));
3782 DEBUG(3,("call_trans2setfsinfo: unknown level (0x%X) not implemented yet.\n",
3784 reply_nterror(req
, NT_STATUS_INVALID_LEVEL
);
3790 * sending this reply works fine,
3791 * but I'm not sure it's the same
3792 * like windows do...
3795 reply_outbuf(req
, 10, 0);
3798 #if defined(HAVE_POSIX_ACLS)
3799 /****************************************************************************
3800 Utility function to count the number of entries in a POSIX acl.
3801 ****************************************************************************/
3803 static unsigned int count_acl_entries(connection_struct
*conn
, SMB_ACL_T posix_acl
)
3805 unsigned int ace_count
= 0;
3806 int entry_id
= SMB_ACL_FIRST_ENTRY
;
3807 SMB_ACL_ENTRY_T entry
;
3809 while ( posix_acl
&& (SMB_VFS_SYS_ACL_GET_ENTRY(conn
, posix_acl
, entry_id
, &entry
) == 1)) {
3811 if (entry_id
== SMB_ACL_FIRST_ENTRY
) {
3812 entry_id
= SMB_ACL_NEXT_ENTRY
;
3819 /****************************************************************************
3820 Utility function to marshall a POSIX acl into wire format.
3821 ****************************************************************************/
3823 static bool marshall_posix_acl(connection_struct
*conn
, char *pdata
, SMB_STRUCT_STAT
*pst
, SMB_ACL_T posix_acl
)
3825 int entry_id
= SMB_ACL_FIRST_ENTRY
;
3826 SMB_ACL_ENTRY_T entry
;
3828 while ( posix_acl
&& (SMB_VFS_SYS_ACL_GET_ENTRY(conn
, posix_acl
, entry_id
, &entry
) == 1)) {
3829 SMB_ACL_TAG_T tagtype
;
3830 SMB_ACL_PERMSET_T permset
;
3831 unsigned char perms
= 0;
3832 unsigned int own_grp
;
3835 if (entry_id
== SMB_ACL_FIRST_ENTRY
) {
3836 entry_id
= SMB_ACL_NEXT_ENTRY
;
3839 if (SMB_VFS_SYS_ACL_GET_TAG_TYPE(conn
, entry
, &tagtype
) == -1) {
3840 DEBUG(0,("marshall_posix_acl: SMB_VFS_SYS_ACL_GET_TAG_TYPE failed.\n"));
3844 if (SMB_VFS_SYS_ACL_GET_PERMSET(conn
, entry
, &permset
) == -1) {
3845 DEBUG(0,("marshall_posix_acl: SMB_VFS_SYS_ACL_GET_PERMSET failed.\n"));
3849 perms
|= (SMB_VFS_SYS_ACL_GET_PERM(conn
, permset
, SMB_ACL_READ
) ? SMB_POSIX_ACL_READ
: 0);
3850 perms
|= (SMB_VFS_SYS_ACL_GET_PERM(conn
, permset
, SMB_ACL_WRITE
) ? SMB_POSIX_ACL_WRITE
: 0);
3851 perms
|= (SMB_VFS_SYS_ACL_GET_PERM(conn
, permset
, SMB_ACL_EXECUTE
) ? SMB_POSIX_ACL_EXECUTE
: 0);
3853 SCVAL(pdata
,1,perms
);
3856 case SMB_ACL_USER_OBJ
:
3857 SCVAL(pdata
,0,SMB_POSIX_ACL_USER_OBJ
);
3858 own_grp
= (unsigned int)pst
->st_ex_uid
;
3859 SIVAL(pdata
,2,own_grp
);
3864 uid_t
*puid
= (uid_t
*)SMB_VFS_SYS_ACL_GET_QUALIFIER(conn
, entry
);
3866 DEBUG(0,("marshall_posix_acl: SMB_VFS_SYS_ACL_GET_QUALIFIER failed.\n"));
3869 own_grp
= (unsigned int)*puid
;
3870 SMB_VFS_SYS_ACL_FREE_QUALIFIER(conn
, (void *)puid
,tagtype
);
3871 SCVAL(pdata
,0,SMB_POSIX_ACL_USER
);
3872 SIVAL(pdata
,2,own_grp
);
3876 case SMB_ACL_GROUP_OBJ
:
3877 SCVAL(pdata
,0,SMB_POSIX_ACL_GROUP_OBJ
);
3878 own_grp
= (unsigned int)pst
->st_ex_gid
;
3879 SIVAL(pdata
,2,own_grp
);
3884 gid_t
*pgid
= (gid_t
*)SMB_VFS_SYS_ACL_GET_QUALIFIER(conn
, entry
);
3886 DEBUG(0,("marshall_posix_acl: SMB_VFS_SYS_ACL_GET_QUALIFIER failed.\n"));
3889 own_grp
= (unsigned int)*pgid
;
3890 SMB_VFS_SYS_ACL_FREE_QUALIFIER(conn
, (void *)pgid
,tagtype
);
3891 SCVAL(pdata
,0,SMB_POSIX_ACL_GROUP
);
3892 SIVAL(pdata
,2,own_grp
);
3897 SCVAL(pdata
,0,SMB_POSIX_ACL_MASK
);
3898 SIVAL(pdata
,2,0xFFFFFFFF);
3899 SIVAL(pdata
,6,0xFFFFFFFF);
3902 SCVAL(pdata
,0,SMB_POSIX_ACL_OTHER
);
3903 SIVAL(pdata
,2,0xFFFFFFFF);
3904 SIVAL(pdata
,6,0xFFFFFFFF);
3907 DEBUG(0,("marshall_posix_acl: unknown tagtype.\n"));
3910 pdata
+= SMB_POSIX_ACL_ENTRY_SIZE
;
3917 /****************************************************************************
3918 Store the FILE_UNIX_BASIC info.
3919 ****************************************************************************/
3921 static char *store_file_unix_basic(connection_struct
*conn
,
3924 const SMB_STRUCT_STAT
*psbuf
)
3926 uint64_t file_index
= get_FileIndex(conn
, psbuf
);
3928 DEBUG(10,("store_file_unix_basic: SMB_QUERY_FILE_UNIX_BASIC\n"));
3929 DEBUG(4,("store_file_unix_basic: st_mode=%o\n",(int)psbuf
->st_ex_mode
));
3931 SOFF_T(pdata
,0,get_file_size_stat(psbuf
)); /* File size 64 Bit */
3934 SOFF_T(pdata
,0,SMB_VFS_GET_ALLOC_SIZE(conn
,fsp
,psbuf
)); /* Number of bytes used on disk - 64 Bit */
3937 put_long_date_timespec(TIMESTAMP_SET_NT_OR_BETTER
, pdata
, psbuf
->st_ex_ctime
); /* Change Time 64 Bit */
3938 put_long_date_timespec(TIMESTAMP_SET_NT_OR_BETTER
,pdata
+8, psbuf
->st_ex_atime
); /* Last access time 64 Bit */
3939 put_long_date_timespec(TIMESTAMP_SET_NT_OR_BETTER
, pdata
+16, psbuf
->st_ex_mtime
); /* Last modification time 64 Bit */
3942 SIVAL(pdata
,0,psbuf
->st_ex_uid
); /* user id for the owner */
3946 SIVAL(pdata
,0,psbuf
->st_ex_gid
); /* group id of owner */
3950 SIVAL(pdata
,0,unix_filetype(psbuf
->st_ex_mode
));
3953 SIVAL(pdata
,0,unix_dev_major(psbuf
->st_ex_rdev
)); /* Major device number if type is device */
3957 SIVAL(pdata
,0,unix_dev_minor(psbuf
->st_ex_rdev
)); /* Minor device number if type is device */
3961 SINO_T_VAL(pdata
,0,(SMB_INO_T
)file_index
); /* inode number */
3964 SIVAL(pdata
,0, unix_perms_to_wire(psbuf
->st_ex_mode
)); /* Standard UNIX file permissions */
3968 SIVAL(pdata
,0,psbuf
->st_ex_nlink
); /* number of hard links */
3975 /* Forward and reverse mappings from the UNIX_INFO2 file flags field and
3976 * the chflags(2) (or equivalent) flags.
3978 * XXX: this really should be behind the VFS interface. To do this, we would
3979 * need to alter SMB_STRUCT_STAT so that it included a flags and a mask field.
3980 * Each VFS module could then implement its own mapping as appropriate for the
3981 * platform. We would then pass the SMB flags into SMB_VFS_CHFLAGS.
3983 static const struct {unsigned stat_fflag
; unsigned smb_fflag
;}
3987 { UF_NODUMP
, EXT_DO_NOT_BACKUP
},
3991 { UF_IMMUTABLE
, EXT_IMMUTABLE
},
3995 { UF_APPEND
, EXT_OPEN_APPEND_ONLY
},
3999 { UF_HIDDEN
, EXT_HIDDEN
},
4002 /* Do not remove. We need to guarantee that this array has at least one
4003 * entry to build on HP-UX.
4009 static void map_info2_flags_from_sbuf(const SMB_STRUCT_STAT
*psbuf
,
4010 uint32
*smb_fflags
, uint32
*smb_fmask
)
4014 for (i
= 0; i
< ARRAY_SIZE(info2_flags_map
); ++i
) {
4015 *smb_fmask
|= info2_flags_map
[i
].smb_fflag
;
4016 if (psbuf
->st_ex_flags
& info2_flags_map
[i
].stat_fflag
) {
4017 *smb_fflags
|= info2_flags_map
[i
].smb_fflag
;
4022 static bool map_info2_flags_to_sbuf(const SMB_STRUCT_STAT
*psbuf
,
4023 const uint32 smb_fflags
,
4024 const uint32 smb_fmask
,
4027 uint32 max_fmask
= 0;
4030 *stat_fflags
= psbuf
->st_ex_flags
;
4032 /* For each flags requested in smb_fmask, check the state of the
4033 * corresponding flag in smb_fflags and set or clear the matching
4037 for (i
= 0; i
< ARRAY_SIZE(info2_flags_map
); ++i
) {
4038 max_fmask
|= info2_flags_map
[i
].smb_fflag
;
4039 if (smb_fmask
& info2_flags_map
[i
].smb_fflag
) {
4040 if (smb_fflags
& info2_flags_map
[i
].smb_fflag
) {
4041 *stat_fflags
|= info2_flags_map
[i
].stat_fflag
;
4043 *stat_fflags
&= ~info2_flags_map
[i
].stat_fflag
;
4048 /* If smb_fmask is asking to set any bits that are not supported by
4049 * our flag mappings, we should fail.
4051 if ((smb_fmask
& max_fmask
) != smb_fmask
) {
4059 /* Just like SMB_QUERY_FILE_UNIX_BASIC, but with the addition
4060 * of file flags and birth (create) time.
4062 static char *store_file_unix_basic_info2(connection_struct
*conn
,
4065 const SMB_STRUCT_STAT
*psbuf
)
4067 uint32 file_flags
= 0;
4068 uint32 flags_mask
= 0;
4070 pdata
= store_file_unix_basic(conn
, pdata
, fsp
, psbuf
);
4072 /* Create (birth) time 64 bit */
4073 put_long_date_timespec(TIMESTAMP_SET_NT_OR_BETTER
,pdata
, psbuf
->st_ex_btime
);
4076 map_info2_flags_from_sbuf(psbuf
, &file_flags
, &flags_mask
);
4077 SIVAL(pdata
, 0, file_flags
); /* flags */
4078 SIVAL(pdata
, 4, flags_mask
); /* mask */
4084 static NTSTATUS
marshall_stream_info(unsigned int num_streams
,
4085 const struct stream_struct
*streams
,
4087 unsigned int max_data_bytes
,
4088 unsigned int *data_size
)
4091 unsigned int ofs
= 0;
4093 for (i
= 0; i
< num_streams
&& ofs
<= max_data_bytes
; i
++) {
4094 unsigned int next_offset
;
4096 smb_ucs2_t
*namebuf
;
4098 if (!push_ucs2_talloc(talloc_tos(), &namebuf
,
4099 streams
[i
].name
, &namelen
) ||
4102 return NT_STATUS_INVALID_PARAMETER
;
4106 * name_buf is now null-terminated, we need to marshall as not
4112 SIVAL(data
, ofs
+4, namelen
);
4113 SOFF_T(data
, ofs
+8, streams
[i
].size
);
4114 SOFF_T(data
, ofs
+16, streams
[i
].alloc_size
);
4115 memcpy(data
+ofs
+24, namebuf
, namelen
);
4116 TALLOC_FREE(namebuf
);
4118 next_offset
= ofs
+ 24 + namelen
;
4120 if (i
== num_streams
-1) {
4121 SIVAL(data
, ofs
, 0);
4124 unsigned int align
= ndr_align_size(next_offset
, 8);
4126 memset(data
+next_offset
, 0, align
);
4127 next_offset
+= align
;
4129 SIVAL(data
, ofs
, next_offset
- ofs
);
4138 return NT_STATUS_OK
;
4141 /****************************************************************************
4142 Reply to a TRANSACT2_QFILEINFO on a PIPE !
4143 ****************************************************************************/
4145 static void call_trans2qpipeinfo(connection_struct
*conn
,
4146 struct smb_request
*req
,
4147 unsigned int tran_call
,
4148 char **pparams
, int total_params
,
4149 char **ppdata
, int total_data
,
4150 unsigned int max_data_bytes
)
4152 char *params
= *pparams
;
4153 char *pdata
= *ppdata
;
4154 unsigned int data_size
= 0;
4155 unsigned int param_size
= 2;
4160 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
4164 if (total_params
< 4) {
4165 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
4169 fsp
= file_fsp(req
, SVAL(params
,0));
4170 if (!fsp_is_np(fsp
)) {
4171 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
4175 info_level
= SVAL(params
,2);
4177 *pparams
= (char *)SMB_REALLOC(*pparams
,2);
4178 if (*pparams
== NULL
) {
4179 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
4184 data_size
= max_data_bytes
+ DIR_ENTRY_SAFETY_MARGIN
;
4185 *ppdata
= (char *)SMB_REALLOC(*ppdata
, data_size
);
4186 if (*ppdata
== NULL
) {
4187 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
4192 switch (info_level
) {
4193 case SMB_FILE_STANDARD_INFORMATION
:
4195 SOFF_T(pdata
,0,4096LL);
4202 reply_nterror(req
, NT_STATUS_INVALID_LEVEL
);
4206 send_trans2_replies(conn
, req
, params
, param_size
, *ppdata
, data_size
,
4212 NTSTATUS
smbd_do_qfilepathinfo(connection_struct
*conn
,
4213 TALLOC_CTX
*mem_ctx
,
4214 uint16_t info_level
,
4216 struct smb_filename
*smb_fname
,
4217 bool delete_pending
,
4218 struct timespec write_time_ts
,
4219 struct ea_list
*ea_list
,
4220 int lock_data_count
,
4223 unsigned int max_data_bytes
,
4225 unsigned int *pdata_size
)
4227 char *pdata
= *ppdata
;
4228 char *dstart
, *dend
;
4229 unsigned int data_size
;
4230 struct timespec create_time_ts
, mtime_ts
, atime_ts
, ctime_ts
;
4231 time_t create_time
, mtime
, atime
, c_time
;
4232 SMB_STRUCT_STAT
*psbuf
= &smb_fname
->st
;
4239 uint64_t file_size
= 0;
4241 uint64_t allocation_size
= 0;
4242 uint64_t file_index
= 0;
4243 uint32_t access_mask
= 0;
4245 if (INFO_LEVEL_IS_UNIX(info_level
) && !lp_unix_extensions()) {
4246 return NT_STATUS_INVALID_LEVEL
;
4249 DEBUG(5,("smbd_do_qfilepathinfo: %s (fnum = %d) level=%d max_data=%u\n",
4250 smb_fname_str_dbg(smb_fname
), fsp
? fsp
->fnum
: -1,
4251 info_level
, max_data_bytes
));
4253 mode
= dos_mode(conn
, smb_fname
);
4254 nlink
= psbuf
->st_ex_nlink
;
4256 if (nlink
&& (mode
&aDIR
)) {
4260 if ((nlink
> 0) && delete_pending
) {
4264 data_size
= max_data_bytes
+ DIR_ENTRY_SAFETY_MARGIN
;
4265 *ppdata
= (char *)SMB_REALLOC(*ppdata
, data_size
);
4266 if (*ppdata
== NULL
) {
4267 return NT_STATUS_NO_MEMORY
;
4271 dend
= dstart
+ data_size
- 1;
4273 if (!null_timespec(write_time_ts
) && !INFO_LEVEL_IS_UNIX(info_level
)) {
4274 update_stat_ex_mtime(psbuf
, write_time_ts
);
4277 create_time_ts
= get_create_timespec(conn
, fsp
, smb_fname
);
4278 mtime_ts
= psbuf
->st_ex_mtime
;
4279 atime_ts
= psbuf
->st_ex_atime
;
4280 ctime_ts
= get_change_timespec(conn
, fsp
, smb_fname
);
4282 if (lp_dos_filetime_resolution(SNUM(conn
))) {
4283 dos_filetime_timespec(&create_time_ts
);
4284 dos_filetime_timespec(&mtime_ts
);
4285 dos_filetime_timespec(&atime_ts
);
4286 dos_filetime_timespec(&ctime_ts
);
4289 create_time
= convert_timespec_to_time_t(create_time_ts
);
4290 mtime
= convert_timespec_to_time_t(mtime_ts
);
4291 atime
= convert_timespec_to_time_t(atime_ts
);
4292 c_time
= convert_timespec_to_time_t(ctime_ts
);
4294 p
= strrchr_m(smb_fname
->base_name
,'/');
4296 base_name
= smb_fname
->base_name
;
4300 /* NT expects the name to be in an exact form of the *full*
4301 filename. See the trans2 torture test */
4302 if (ISDOT(base_name
)) {
4303 dos_fname
= talloc_strdup(mem_ctx
, "\\");
4305 return NT_STATUS_NO_MEMORY
;
4308 dos_fname
= talloc_asprintf(mem_ctx
,
4310 smb_fname
->base_name
);
4312 return NT_STATUS_NO_MEMORY
;
4314 if (is_ntfs_stream_smb_fname(smb_fname
)) {
4315 dos_fname
= talloc_asprintf(dos_fname
, "%s",
4316 smb_fname
->stream_name
);
4318 return NT_STATUS_NO_MEMORY
;
4322 string_replace(dos_fname
, '/', '\\');
4325 allocation_size
= SMB_VFS_GET_ALLOC_SIZE(conn
, fsp
, psbuf
);
4328 /* Do we have this path open ? */
4330 struct file_id fileid
= vfs_file_id_from_sbuf(conn
, psbuf
);
4331 fsp1
= file_find_di_first(conn
->sconn
, fileid
);
4332 if (fsp1
&& fsp1
->initial_allocation_size
) {
4333 allocation_size
= SMB_VFS_GET_ALLOC_SIZE(conn
, fsp1
, psbuf
);
4337 if (!(mode
& aDIR
)) {
4338 file_size
= get_file_size_stat(psbuf
);
4342 pos
= fsp
->fh
->position_information
;
4346 access_mask
= fsp
->access_mask
;
4348 /* GENERIC_EXECUTE mapping from Windows */
4349 access_mask
= 0x12019F;
4352 /* This should be an index number - looks like
4355 I think this causes us to fail the IFSKIT
4356 BasicFileInformationTest. -tpot */
4357 file_index
= get_FileIndex(conn
, psbuf
);
4359 switch (info_level
) {
4360 case SMB_INFO_STANDARD
:
4361 DEBUG(10,("smbd_do_qfilepathinfo: SMB_INFO_STANDARD\n"));
4363 srv_put_dos_date2(pdata
,l1_fdateCreation
,create_time
);
4364 srv_put_dos_date2(pdata
,l1_fdateLastAccess
,atime
);
4365 srv_put_dos_date2(pdata
,l1_fdateLastWrite
,mtime
); /* write time */
4366 SIVAL(pdata
,l1_cbFile
,(uint32
)file_size
);
4367 SIVAL(pdata
,l1_cbFileAlloc
,(uint32
)allocation_size
);
4368 SSVAL(pdata
,l1_attrFile
,mode
);
4371 case SMB_INFO_QUERY_EA_SIZE
:
4373 unsigned int ea_size
=
4374 estimate_ea_size(conn
, fsp
,
4375 smb_fname
->base_name
);
4376 DEBUG(10,("smbd_do_qfilepathinfo: SMB_INFO_QUERY_EA_SIZE\n"));
4378 srv_put_dos_date2(pdata
,0,create_time
);
4379 srv_put_dos_date2(pdata
,4,atime
);
4380 srv_put_dos_date2(pdata
,8,mtime
); /* write time */
4381 SIVAL(pdata
,12,(uint32
)file_size
);
4382 SIVAL(pdata
,16,(uint32
)allocation_size
);
4383 SSVAL(pdata
,20,mode
);
4384 SIVAL(pdata
,22,ea_size
);
4388 case SMB_INFO_IS_NAME_VALID
:
4389 DEBUG(10,("smbd_do_qfilepathinfo: SMB_INFO_IS_NAME_VALID\n"));
4391 /* os/2 needs this ? really ?*/
4392 return NT_STATUS_DOS(ERRDOS
, ERRbadfunc
);
4394 /* This is only reached for qpathinfo */
4398 case SMB_INFO_QUERY_EAS_FROM_LIST
:
4400 size_t total_ea_len
= 0;
4401 struct ea_list
*ea_file_list
= NULL
;
4403 DEBUG(10,("smbd_do_qfilepathinfo: SMB_INFO_QUERY_EAS_FROM_LIST\n"));
4406 get_ea_list_from_file(mem_ctx
, conn
, fsp
,
4407 smb_fname
->base_name
,
4409 ea_list
= ea_list_union(ea_list
, ea_file_list
, &total_ea_len
);
4411 if (!ea_list
|| (total_ea_len
> data_size
)) {
4413 SIVAL(pdata
,0,4); /* EA List Length must be set to 4 if no EA's. */
4417 data_size
= fill_ea_buffer(mem_ctx
, pdata
, data_size
, conn
, ea_list
);
4421 case SMB_INFO_QUERY_ALL_EAS
:
4423 /* We have data_size bytes to put EA's into. */
4424 size_t total_ea_len
= 0;
4426 DEBUG(10,("smbd_do_qfilepathinfo: SMB_INFO_QUERY_ALL_EAS\n"));
4428 ea_list
= get_ea_list_from_file(mem_ctx
, conn
, fsp
,
4429 smb_fname
->base_name
,
4431 if (!ea_list
|| (total_ea_len
> data_size
)) {
4433 SIVAL(pdata
,0,4); /* EA List Length must be set to 4 if no EA's. */
4437 data_size
= fill_ea_buffer(mem_ctx
, pdata
, data_size
, conn
, ea_list
);
4441 case 0xFF0F:/*SMB2_INFO_QUERY_ALL_EAS*/
4443 /* This is FileFullEaInformation - 0xF which maps to
4444 * 1015 (decimal) in smbd_do_setfilepathinfo. */
4446 /* We have data_size bytes to put EA's into. */
4447 size_t total_ea_len
= 0;
4448 struct ea_list
*ea_file_list
= NULL
;
4450 DEBUG(10,("smbd_do_qfilepathinfo: SMB2_INFO_QUERY_ALL_EAS\n"));
4452 /*TODO: add filtering and index handling */
4455 get_ea_list_from_file(mem_ctx
, conn
, fsp
,
4456 smb_fname
->base_name
,
4458 if (!ea_file_list
) {
4459 return NT_STATUS_NO_EAS_ON_FILE
;
4462 status
= fill_ea_chained_buffer(mem_ctx
,
4466 conn
, ea_file_list
);
4467 if (!NT_STATUS_IS_OK(status
)) {
4473 case SMB_FILE_BASIC_INFORMATION
:
4474 case SMB_QUERY_FILE_BASIC_INFO
:
4476 if (info_level
== SMB_QUERY_FILE_BASIC_INFO
) {
4477 DEBUG(10,("smbd_do_qfilepathinfo: SMB_QUERY_FILE_BASIC_INFO\n"));
4478 data_size
= 36; /* w95 returns 40 bytes not 36 - why ?. */
4480 DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_BASIC_INFORMATION\n"));
4484 put_long_date_timespec(conn
->ts_res
,pdata
,create_time_ts
);
4485 put_long_date_timespec(conn
->ts_res
,pdata
+8,atime_ts
);
4486 put_long_date_timespec(conn
->ts_res
,pdata
+16,mtime_ts
); /* write time */
4487 put_long_date_timespec(conn
->ts_res
,pdata
+24,ctime_ts
); /* change time */
4488 SIVAL(pdata
,32,mode
);
4490 DEBUG(5,("SMB_QFBI - "));
4491 DEBUG(5,("create: %s ", ctime(&create_time
)));
4492 DEBUG(5,("access: %s ", ctime(&atime
)));
4493 DEBUG(5,("write: %s ", ctime(&mtime
)));
4494 DEBUG(5,("change: %s ", ctime(&c_time
)));
4495 DEBUG(5,("mode: %x\n", mode
));
4498 case SMB_FILE_STANDARD_INFORMATION
:
4499 case SMB_QUERY_FILE_STANDARD_INFO
:
4501 DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_STANDARD_INFORMATION\n"));
4503 SOFF_T(pdata
,0,allocation_size
);
4504 SOFF_T(pdata
,8,file_size
);
4505 SIVAL(pdata
,16,nlink
);
4506 SCVAL(pdata
,20,delete_pending
?1:0);
4507 SCVAL(pdata
,21,(mode
&aDIR
)?1:0);
4508 SSVAL(pdata
,22,0); /* Padding. */
4511 case SMB_FILE_EA_INFORMATION
:
4512 case SMB_QUERY_FILE_EA_INFO
:
4514 unsigned int ea_size
=
4515 estimate_ea_size(conn
, fsp
, smb_fname
->base_name
);
4516 DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_EA_INFORMATION\n"));
4518 SIVAL(pdata
,0,ea_size
);
4522 /* Get the 8.3 name - used if NT SMB was negotiated. */
4523 case SMB_QUERY_FILE_ALT_NAME_INFO
:
4524 case SMB_FILE_ALTERNATE_NAME_INFORMATION
:
4527 char mangled_name
[13];
4528 DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_ALTERNATE_NAME_INFORMATION\n"));
4529 if (!name_to_8_3(base_name
,mangled_name
,
4530 True
,conn
->params
)) {
4531 return NT_STATUS_NO_MEMORY
;
4533 len
= srvstr_push(dstart
, flags2
,
4534 pdata
+4, mangled_name
,
4535 PTR_DIFF(dend
, pdata
+4),
4537 data_size
= 4 + len
;
4542 case SMB_QUERY_FILE_NAME_INFO
:
4546 this must be *exactly* right for ACLs on mapped drives to work
4548 len
= srvstr_push(dstart
, flags2
,
4550 PTR_DIFF(dend
, pdata
+4),
4552 DEBUG(10,("smbd_do_qfilepathinfo: SMB_QUERY_FILE_NAME_INFO\n"));
4553 data_size
= 4 + len
;
4558 case SMB_FILE_ALLOCATION_INFORMATION
:
4559 case SMB_QUERY_FILE_ALLOCATION_INFO
:
4560 DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_ALLOCATION_INFORMATION\n"));
4562 SOFF_T(pdata
,0,allocation_size
);
4565 case SMB_FILE_END_OF_FILE_INFORMATION
:
4566 case SMB_QUERY_FILE_END_OF_FILEINFO
:
4567 DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_END_OF_FILE_INFORMATION\n"));
4569 SOFF_T(pdata
,0,file_size
);
4572 case SMB_QUERY_FILE_ALL_INFO
:
4573 case SMB_FILE_ALL_INFORMATION
:
4576 unsigned int ea_size
=
4577 estimate_ea_size(conn
, fsp
, smb_fname
->base_name
);
4578 DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_ALL_INFORMATION\n"));
4579 put_long_date_timespec(conn
->ts_res
,pdata
,create_time_ts
);
4580 put_long_date_timespec(conn
->ts_res
,pdata
+8,atime_ts
);
4581 put_long_date_timespec(conn
->ts_res
,pdata
+16,mtime_ts
); /* write time */
4582 put_long_date_timespec(conn
->ts_res
,pdata
+24,ctime_ts
); /* change time */
4583 SIVAL(pdata
,32,mode
);
4584 SIVAL(pdata
,36,0); /* padding. */
4586 SOFF_T(pdata
,0,allocation_size
);
4587 SOFF_T(pdata
,8,file_size
);
4588 SIVAL(pdata
,16,nlink
);
4589 SCVAL(pdata
,20,delete_pending
);
4590 SCVAL(pdata
,21,(mode
&aDIR
)?1:0);
4593 SIVAL(pdata
,0,ea_size
);
4594 pdata
+= 4; /* EA info */
4595 len
= srvstr_push(dstart
, flags2
,
4597 PTR_DIFF(dend
, pdata
+4),
4601 data_size
= PTR_DIFF(pdata
,(*ppdata
));
4605 case 0xFF12:/*SMB2_FILE_ALL_INFORMATION*/
4608 unsigned int ea_size
=
4609 estimate_ea_size(conn
, fsp
, smb_fname
->base_name
);
4610 DEBUG(10,("smbd_do_qfilepathinfo: SMB2_FILE_ALL_INFORMATION\n"));
4611 put_long_date_timespec(conn
->ts_res
,pdata
+0x00,create_time_ts
);
4612 put_long_date_timespec(conn
->ts_res
,pdata
+0x08,atime_ts
);
4613 put_long_date_timespec(conn
->ts_res
,pdata
+0x10,mtime_ts
); /* write time */
4614 put_long_date_timespec(conn
->ts_res
,pdata
+0x18,ctime_ts
); /* change time */
4615 SIVAL(pdata
, 0x20, mode
);
4616 SIVAL(pdata
, 0x24, 0); /* padding. */
4617 SBVAL(pdata
, 0x28, allocation_size
);
4618 SBVAL(pdata
, 0x30, file_size
);
4619 SIVAL(pdata
, 0x38, nlink
);
4620 SCVAL(pdata
, 0x3C, delete_pending
);
4621 SCVAL(pdata
, 0x3D, (mode
&aDIR
)?1:0);
4622 SSVAL(pdata
, 0x3E, 0); /* padding */
4623 SBVAL(pdata
, 0x40, file_index
);
4624 SIVAL(pdata
, 0x48, ea_size
);
4625 SIVAL(pdata
, 0x4C, access_mask
);
4626 SBVAL(pdata
, 0x50, pos
);
4627 SIVAL(pdata
, 0x58, mode
); /*TODO: mode != mode fix this!!! */
4628 SIVAL(pdata
, 0x5C, 0); /* No alignment needed. */
4632 len
= srvstr_push(dstart
, flags2
,
4634 PTR_DIFF(dend
, pdata
+4),
4638 data_size
= PTR_DIFF(pdata
,(*ppdata
));
4641 case SMB_FILE_INTERNAL_INFORMATION
:
4643 DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_INTERNAL_INFORMATION\n"));
4644 SBVAL(pdata
, 0, file_index
);
4648 case SMB_FILE_ACCESS_INFORMATION
:
4649 DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_ACCESS_INFORMATION\n"));
4650 SIVAL(pdata
, 0, access_mask
);
4654 case SMB_FILE_NAME_INFORMATION
:
4655 /* Pathname with leading '\'. */
4658 byte_len
= dos_PutUniCode(pdata
+4,dos_fname
,(size_t)max_data_bytes
,False
);
4659 DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_NAME_INFORMATION\n"));
4660 SIVAL(pdata
,0,byte_len
);
4661 data_size
= 4 + byte_len
;
4665 case SMB_FILE_DISPOSITION_INFORMATION
:
4666 DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_DISPOSITION_INFORMATION\n"));
4668 SCVAL(pdata
,0,delete_pending
);
4671 case SMB_FILE_POSITION_INFORMATION
:
4672 DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_POSITION_INFORMATION\n"));
4674 SOFF_T(pdata
,0,pos
);
4677 case SMB_FILE_MODE_INFORMATION
:
4678 DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_MODE_INFORMATION\n"));
4679 SIVAL(pdata
,0,mode
);
4683 case SMB_FILE_ALIGNMENT_INFORMATION
:
4684 DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_ALIGNMENT_INFORMATION\n"));
4685 SIVAL(pdata
,0,0); /* No alignment needed. */
4690 * NT4 server just returns "invalid query" to this - if we try
4691 * to answer it then NTws gets a BSOD! (tridge). W2K seems to
4694 /* The first statement above is false - verified using Thursby
4695 * client against NT4 -- gcolley.
4697 case SMB_QUERY_FILE_STREAM_INFO
:
4698 case SMB_FILE_STREAM_INFORMATION
: {
4699 unsigned int num_streams
;
4700 struct stream_struct
*streams
;
4702 DEBUG(10,("smbd_do_qfilepathinfo: "
4703 "SMB_FILE_STREAM_INFORMATION\n"));
4705 if (is_ntfs_stream_smb_fname(smb_fname
)) {
4706 return NT_STATUS_INVALID_PARAMETER
;
4709 status
= SMB_VFS_STREAMINFO(
4710 conn
, fsp
, smb_fname
->base_name
, talloc_tos(),
4711 &num_streams
, &streams
);
4713 if (!NT_STATUS_IS_OK(status
)) {
4714 DEBUG(10, ("could not get stream info: %s\n",
4715 nt_errstr(status
)));
4719 status
= marshall_stream_info(num_streams
, streams
,
4720 pdata
, max_data_bytes
,
4723 if (!NT_STATUS_IS_OK(status
)) {
4724 DEBUG(10, ("marshall_stream_info failed: %s\n",
4725 nt_errstr(status
)));
4729 TALLOC_FREE(streams
);
4733 case SMB_QUERY_COMPRESSION_INFO
:
4734 case SMB_FILE_COMPRESSION_INFORMATION
:
4735 DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_COMPRESSION_INFORMATION\n"));
4736 SOFF_T(pdata
,0,file_size
);
4737 SIVAL(pdata
,8,0); /* ??? */
4738 SIVAL(pdata
,12,0); /* ??? */
4742 case SMB_FILE_NETWORK_OPEN_INFORMATION
:
4743 DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_NETWORK_OPEN_INFORMATION\n"));
4744 put_long_date_timespec(conn
->ts_res
,pdata
,create_time_ts
);
4745 put_long_date_timespec(conn
->ts_res
,pdata
+8,atime_ts
);
4746 put_long_date_timespec(conn
->ts_res
,pdata
+16,mtime_ts
); /* write time */
4747 put_long_date_timespec(conn
->ts_res
,pdata
+24,ctime_ts
); /* change time */
4748 SOFF_T(pdata
,32,allocation_size
);
4749 SOFF_T(pdata
,40,file_size
);
4750 SIVAL(pdata
,48,mode
);
4751 SIVAL(pdata
,52,0); /* ??? */
4755 case SMB_FILE_ATTRIBUTE_TAG_INFORMATION
:
4756 DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_ATTRIBUTE_TAG_INFORMATION\n"));
4757 SIVAL(pdata
,0,mode
);
4763 * CIFS UNIX Extensions.
4766 case SMB_QUERY_FILE_UNIX_BASIC
:
4768 pdata
= store_file_unix_basic(conn
, pdata
, fsp
, psbuf
);
4769 data_size
= PTR_DIFF(pdata
,(*ppdata
));
4771 DEBUG(4,("smbd_do_qfilepathinfo: "
4772 "SMB_QUERY_FILE_UNIX_BASIC\n"));
4773 dump_data(4, (uint8_t *)(*ppdata
), data_size
);
4777 case SMB_QUERY_FILE_UNIX_INFO2
:
4779 pdata
= store_file_unix_basic_info2(conn
, pdata
, fsp
, psbuf
);
4780 data_size
= PTR_DIFF(pdata
,(*ppdata
));
4784 DEBUG(4,("smbd_do_qfilepathinfo: SMB_QUERY_FILE_UNIX_INFO2 "));
4786 for (i
=0; i
<100; i
++)
4787 DEBUG(4,("%d=%x, ",i
, (*ppdata
)[i
]));
4793 case SMB_QUERY_FILE_UNIX_LINK
:
4796 char *buffer
= TALLOC_ARRAY(mem_ctx
, char, PATH_MAX
+1);
4799 return NT_STATUS_NO_MEMORY
;
4802 DEBUG(10,("smbd_do_qfilepathinfo: SMB_QUERY_FILE_UNIX_LINK\n"));
4804 if(!S_ISLNK(psbuf
->st_ex_mode
)) {
4805 return NT_STATUS_DOS(ERRSRV
, ERRbadlink
);
4808 return NT_STATUS_DOS(ERRDOS
, ERRbadlink
);
4810 len
= SMB_VFS_READLINK(conn
,
4811 smb_fname
->base_name
,
4814 return map_nt_error_from_unix(errno
);
4817 len
= srvstr_push(dstart
, flags2
,
4819 PTR_DIFF(dend
, pdata
),
4822 data_size
= PTR_DIFF(pdata
,(*ppdata
));
4827 #if defined(HAVE_POSIX_ACLS)
4828 case SMB_QUERY_POSIX_ACL
:
4830 SMB_ACL_T file_acl
= NULL
;
4831 SMB_ACL_T def_acl
= NULL
;
4832 uint16 num_file_acls
= 0;
4833 uint16 num_def_acls
= 0;
4835 if (fsp
&& fsp
->fh
->fd
!= -1) {
4836 file_acl
= SMB_VFS_SYS_ACL_GET_FD(fsp
);
4839 SMB_VFS_SYS_ACL_GET_FILE(conn
,
4840 smb_fname
->base_name
,
4841 SMB_ACL_TYPE_ACCESS
);
4844 if (file_acl
== NULL
&& no_acl_syscall_error(errno
)) {
4845 DEBUG(5,("smbd_do_qfilepathinfo: ACLs "
4846 "not implemented on "
4847 "filesystem containing %s\n",
4848 smb_fname
->base_name
));
4849 return NT_STATUS_NOT_IMPLEMENTED
;
4852 if (S_ISDIR(psbuf
->st_ex_mode
)) {
4853 if (fsp
&& fsp
->is_directory
) {
4855 SMB_VFS_SYS_ACL_GET_FILE(
4857 fsp
->fsp_name
->base_name
,
4858 SMB_ACL_TYPE_DEFAULT
);
4861 SMB_VFS_SYS_ACL_GET_FILE(
4863 smb_fname
->base_name
,
4864 SMB_ACL_TYPE_DEFAULT
);
4866 def_acl
= free_empty_sys_acl(conn
, def_acl
);
4869 num_file_acls
= count_acl_entries(conn
, file_acl
);
4870 num_def_acls
= count_acl_entries(conn
, def_acl
);
4872 if ( data_size
< (num_file_acls
+ num_def_acls
)*SMB_POSIX_ACL_ENTRY_SIZE
+ SMB_POSIX_ACL_HEADER_SIZE
) {
4873 DEBUG(5,("smbd_do_qfilepathinfo: data_size too small (%u) need %u\n",
4875 (unsigned int)((num_file_acls
+ num_def_acls
)*SMB_POSIX_ACL_ENTRY_SIZE
+
4876 SMB_POSIX_ACL_HEADER_SIZE
) ));
4878 SMB_VFS_SYS_ACL_FREE_ACL(conn
, file_acl
);
4881 SMB_VFS_SYS_ACL_FREE_ACL(conn
, def_acl
);
4883 return NT_STATUS_BUFFER_TOO_SMALL
;
4886 SSVAL(pdata
,0,SMB_POSIX_ACL_VERSION
);
4887 SSVAL(pdata
,2,num_file_acls
);
4888 SSVAL(pdata
,4,num_def_acls
);
4889 if (!marshall_posix_acl(conn
, pdata
+ SMB_POSIX_ACL_HEADER_SIZE
, psbuf
, file_acl
)) {
4891 SMB_VFS_SYS_ACL_FREE_ACL(conn
, file_acl
);
4894 SMB_VFS_SYS_ACL_FREE_ACL(conn
, def_acl
);
4896 return NT_STATUS_INTERNAL_ERROR
;
4898 if (!marshall_posix_acl(conn
, pdata
+ SMB_POSIX_ACL_HEADER_SIZE
+ (num_file_acls
*SMB_POSIX_ACL_ENTRY_SIZE
), psbuf
, def_acl
)) {
4900 SMB_VFS_SYS_ACL_FREE_ACL(conn
, file_acl
);
4903 SMB_VFS_SYS_ACL_FREE_ACL(conn
, def_acl
);
4905 return NT_STATUS_INTERNAL_ERROR
;
4909 SMB_VFS_SYS_ACL_FREE_ACL(conn
, file_acl
);
4912 SMB_VFS_SYS_ACL_FREE_ACL(conn
, def_acl
);
4914 data_size
= (num_file_acls
+ num_def_acls
)*SMB_POSIX_ACL_ENTRY_SIZE
+ SMB_POSIX_ACL_HEADER_SIZE
;
4920 case SMB_QUERY_POSIX_LOCK
:
4925 enum brl_type lock_type
;
4927 /* We need an open file with a real fd for this. */
4928 if (!fsp
|| fsp
->fh
->fd
== -1) {
4929 return NT_STATUS_INVALID_LEVEL
;
4932 if (lock_data_count
!= POSIX_LOCK_DATA_SIZE
) {
4933 return NT_STATUS_INVALID_PARAMETER
;
4936 switch (SVAL(pdata
, POSIX_LOCK_TYPE_OFFSET
)) {
4937 case POSIX_LOCK_TYPE_READ
:
4938 lock_type
= READ_LOCK
;
4940 case POSIX_LOCK_TYPE_WRITE
:
4941 lock_type
= WRITE_LOCK
;
4943 case POSIX_LOCK_TYPE_UNLOCK
:
4945 /* There's no point in asking for an unlock... */
4946 return NT_STATUS_INVALID_PARAMETER
;
4949 smblctx
= (uint64_t)IVAL(pdata
, POSIX_LOCK_PID_OFFSET
);
4950 #if defined(HAVE_LONGLONG)
4951 offset
= (((uint64_t) IVAL(pdata
,(POSIX_LOCK_START_OFFSET
+4))) << 32) |
4952 ((uint64_t) IVAL(pdata
,POSIX_LOCK_START_OFFSET
));
4953 count
= (((uint64_t) IVAL(pdata
,(POSIX_LOCK_LEN_OFFSET
+4))) << 32) |
4954 ((uint64_t) IVAL(pdata
,POSIX_LOCK_LEN_OFFSET
));
4955 #else /* HAVE_LONGLONG */
4956 offset
= (uint64_t)IVAL(pdata
,POSIX_LOCK_START_OFFSET
);
4957 count
= (uint64_t)IVAL(pdata
,POSIX_LOCK_LEN_OFFSET
);
4958 #endif /* HAVE_LONGLONG */
4960 status
= query_lock(fsp
,
4967 if (ERROR_WAS_LOCK_DENIED(status
)) {
4968 /* Here we need to report who has it locked... */
4969 data_size
= POSIX_LOCK_DATA_SIZE
;
4971 SSVAL(pdata
, POSIX_LOCK_TYPE_OFFSET
, lock_type
);
4972 SSVAL(pdata
, POSIX_LOCK_FLAGS_OFFSET
, 0);
4973 SIVAL(pdata
, POSIX_LOCK_PID_OFFSET
, (uint32_t)smblctx
);
4974 #if defined(HAVE_LONGLONG)
4975 SIVAL(pdata
, POSIX_LOCK_START_OFFSET
, (uint32
)(offset
& 0xFFFFFFFF));
4976 SIVAL(pdata
, POSIX_LOCK_START_OFFSET
+ 4, (uint32
)((offset
>> 32) & 0xFFFFFFFF));
4977 SIVAL(pdata
, POSIX_LOCK_LEN_OFFSET
, (uint32
)(count
& 0xFFFFFFFF));
4978 SIVAL(pdata
, POSIX_LOCK_LEN_OFFSET
+ 4, (uint32
)((count
>> 32) & 0xFFFFFFFF));
4979 #else /* HAVE_LONGLONG */
4980 SIVAL(pdata
, POSIX_LOCK_START_OFFSET
, offset
);
4981 SIVAL(pdata
, POSIX_LOCK_LEN_OFFSET
, count
);
4982 #endif /* HAVE_LONGLONG */
4984 } else if (NT_STATUS_IS_OK(status
)) {
4985 /* For success we just return a copy of what we sent
4986 with the lock type set to POSIX_LOCK_TYPE_UNLOCK. */
4987 data_size
= POSIX_LOCK_DATA_SIZE
;
4988 memcpy(pdata
, lock_data
, POSIX_LOCK_DATA_SIZE
);
4989 SSVAL(pdata
, POSIX_LOCK_TYPE_OFFSET
, POSIX_LOCK_TYPE_UNLOCK
);
4997 return NT_STATUS_INVALID_LEVEL
;
5000 *pdata_size
= data_size
;
5001 return NT_STATUS_OK
;
5004 /****************************************************************************
5005 Reply to a TRANS2_QFILEPATHINFO or TRANSACT2_QFILEINFO (query file info by
5006 file name or file id).
5007 ****************************************************************************/
5009 static void call_trans2qfilepathinfo(connection_struct
*conn
,
5010 struct smb_request
*req
,
5011 unsigned int tran_call
,
5012 char **pparams
, int total_params
,
5013 char **ppdata
, int total_data
,
5014 unsigned int max_data_bytes
)
5016 char *params
= *pparams
;
5017 char *pdata
= *ppdata
;
5019 unsigned int data_size
= 0;
5020 unsigned int param_size
= 2;
5021 struct smb_filename
*smb_fname
= NULL
;
5022 bool delete_pending
= False
;
5023 struct timespec write_time_ts
;
5024 files_struct
*fsp
= NULL
;
5025 struct file_id fileid
;
5026 struct ea_list
*ea_list
= NULL
;
5027 int lock_data_count
= 0;
5028 char *lock_data
= NULL
;
5029 NTSTATUS status
= NT_STATUS_OK
;
5032 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
5036 ZERO_STRUCT(write_time_ts
);
5038 if (tran_call
== TRANSACT2_QFILEINFO
) {
5039 if (total_params
< 4) {
5040 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
5045 call_trans2qpipeinfo(conn
, req
, tran_call
,
5046 pparams
, total_params
,
5052 fsp
= file_fsp(req
, SVAL(params
,0));
5053 info_level
= SVAL(params
,2);
5055 DEBUG(3,("call_trans2qfilepathinfo: TRANSACT2_QFILEINFO: level = %d\n", info_level
));
5057 if (INFO_LEVEL_IS_UNIX(info_level
) && !lp_unix_extensions()) {
5058 reply_nterror(req
, NT_STATUS_INVALID_LEVEL
);
5062 /* Initial check for valid fsp ptr. */
5063 if (!check_fsp_open(conn
, req
, fsp
)) {
5067 status
= copy_smb_filename(talloc_tos(), fsp
->fsp_name
,
5069 if (!NT_STATUS_IS_OK(status
)) {
5070 reply_nterror(req
, status
);
5074 if(fsp
->fake_file_handle
) {
5076 * This is actually for the QUOTA_FAKE_FILE --metze
5079 /* We know this name is ok, it's already passed the checks. */
5081 } else if(fsp
->fh
->fd
== -1) {
5083 * This is actually a QFILEINFO on a directory
5084 * handle (returned from an NT SMB). NT5.0 seems
5085 * to do this call. JRA.
5088 if (INFO_LEVEL_IS_UNIX(info_level
)) {
5089 /* Always do lstat for UNIX calls. */
5090 if (SMB_VFS_LSTAT(conn
, smb_fname
)) {
5091 DEBUG(3,("call_trans2qfilepathinfo: "
5092 "SMB_VFS_LSTAT of %s failed "
5094 smb_fname_str_dbg(smb_fname
),
5097 map_nt_error_from_unix(errno
));
5100 } else if (SMB_VFS_STAT(conn
, smb_fname
)) {
5101 DEBUG(3,("call_trans2qfilepathinfo: "
5102 "SMB_VFS_STAT of %s failed (%s)\n",
5103 smb_fname_str_dbg(smb_fname
),
5106 map_nt_error_from_unix(errno
));
5110 fileid
= vfs_file_id_from_sbuf(conn
, &smb_fname
->st
);
5111 get_file_infos(fileid
, fsp
->name_hash
, &delete_pending
, &write_time_ts
);
5114 * Original code - this is an open file.
5116 if (SMB_VFS_FSTAT(fsp
, &smb_fname
->st
) != 0) {
5117 DEBUG(3, ("fstat of fnum %d failed (%s)\n",
5118 fsp
->fnum
, strerror(errno
)));
5120 map_nt_error_from_unix(errno
));
5123 fileid
= vfs_file_id_from_sbuf(conn
, &smb_fname
->st
);
5124 get_file_infos(fileid
, fsp
->name_hash
, &delete_pending
, &write_time_ts
);
5132 if (total_params
< 7) {
5133 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
5137 info_level
= SVAL(params
,0);
5139 DEBUG(3,("call_trans2qfilepathinfo: TRANSACT2_QPATHINFO: level = %d\n", info_level
));
5141 if (INFO_LEVEL_IS_UNIX(info_level
) && !lp_unix_extensions()) {
5142 reply_nterror(req
, NT_STATUS_INVALID_LEVEL
);
5146 srvstr_get_path(req
, params
, req
->flags2
, &fname
, ¶ms
[6],
5148 STR_TERMINATE
, &status
);
5149 if (!NT_STATUS_IS_OK(status
)) {
5150 reply_nterror(req
, status
);
5154 status
= filename_convert(req
,
5156 req
->flags2
& FLAGS2_DFS_PATHNAMES
,
5161 if (!NT_STATUS_IS_OK(status
)) {
5162 if (NT_STATUS_EQUAL(status
,NT_STATUS_PATH_NOT_COVERED
)) {
5163 reply_botherror(req
,
5164 NT_STATUS_PATH_NOT_COVERED
,
5165 ERRSRV
, ERRbadpath
);
5168 reply_nterror(req
, status
);
5172 /* If this is a stream, check if there is a delete_pending. */
5173 if ((conn
->fs_capabilities
& FILE_NAMED_STREAMS
)
5174 && is_ntfs_stream_smb_fname(smb_fname
)) {
5175 struct smb_filename
*smb_fname_base
= NULL
;
5177 /* Create an smb_filename with stream_name == NULL. */
5179 create_synthetic_smb_fname(talloc_tos(),
5180 smb_fname
->base_name
,
5183 if (!NT_STATUS_IS_OK(status
)) {
5184 reply_nterror(req
, status
);
5188 if (INFO_LEVEL_IS_UNIX(info_level
)) {
5189 /* Always do lstat for UNIX calls. */
5190 if (SMB_VFS_LSTAT(conn
, smb_fname_base
) != 0) {
5191 DEBUG(3,("call_trans2qfilepathinfo: "
5192 "SMB_VFS_LSTAT of %s failed "
5194 smb_fname_str_dbg(smb_fname_base
),
5196 TALLOC_FREE(smb_fname_base
);
5198 map_nt_error_from_unix(errno
));
5202 if (SMB_VFS_STAT(conn
, smb_fname_base
) != 0) {
5203 DEBUG(3,("call_trans2qfilepathinfo: "
5204 "fileinfo of %s failed "
5206 smb_fname_str_dbg(smb_fname_base
),
5208 TALLOC_FREE(smb_fname_base
);
5210 map_nt_error_from_unix(errno
));
5215 status
= file_name_hash(conn
,
5216 smb_fname_str_dbg(smb_fname_base
),
5218 if (!NT_STATUS_IS_OK(status
)) {
5219 TALLOC_FREE(smb_fname_base
);
5220 reply_nterror(req
, status
);
5224 fileid
= vfs_file_id_from_sbuf(conn
,
5225 &smb_fname_base
->st
);
5226 TALLOC_FREE(smb_fname_base
);
5227 get_file_infos(fileid
, name_hash
, &delete_pending
, NULL
);
5228 if (delete_pending
) {
5229 reply_nterror(req
, NT_STATUS_DELETE_PENDING
);
5234 if (INFO_LEVEL_IS_UNIX(info_level
)) {
5235 /* Always do lstat for UNIX calls. */
5236 if (SMB_VFS_LSTAT(conn
, smb_fname
)) {
5237 DEBUG(3,("call_trans2qfilepathinfo: "
5238 "SMB_VFS_LSTAT of %s failed (%s)\n",
5239 smb_fname_str_dbg(smb_fname
),
5242 map_nt_error_from_unix(errno
));
5247 if (SMB_VFS_STAT(conn
, smb_fname
) != 0) {
5248 DEBUG(3,("call_trans2qfilepathinfo: "
5249 "SMB_VFS_STAT of %s failed (%s)\n",
5250 smb_fname_str_dbg(smb_fname
),
5253 map_nt_error_from_unix(errno
));
5258 status
= file_name_hash(conn
,
5259 smb_fname_str_dbg(smb_fname
),
5261 if (!NT_STATUS_IS_OK(status
)) {
5262 reply_nterror(req
, status
);
5266 fileid
= vfs_file_id_from_sbuf(conn
, &smb_fname
->st
);
5267 get_file_infos(fileid
, name_hash
, &delete_pending
, &write_time_ts
);
5268 if (delete_pending
) {
5269 reply_nterror(req
, NT_STATUS_DELETE_PENDING
);
5274 DEBUG(3,("call_trans2qfilepathinfo %s (fnum = %d) level=%d call=%d "
5275 "total_data=%d\n", smb_fname_str_dbg(smb_fname
),
5276 fsp
? fsp
->fnum
: -1, info_level
,tran_call
,total_data
));
5278 /* Pull out any data sent here before we realloc. */
5279 switch (info_level
) {
5280 case SMB_INFO_QUERY_EAS_FROM_LIST
:
5282 /* Pull any EA list from the data portion. */
5285 if (total_data
< 4) {
5287 req
, NT_STATUS_INVALID_PARAMETER
);
5290 ea_size
= IVAL(pdata
,0);
5292 if (total_data
> 0 && ea_size
!= total_data
) {
5293 DEBUG(4,("call_trans2qfilepathinfo: Rejecting EA request with incorrect \
5294 total_data=%u (should be %u)\n", (unsigned int)total_data
, (unsigned int)IVAL(pdata
,0) ));
5296 req
, NT_STATUS_INVALID_PARAMETER
);
5300 if (!lp_ea_support(SNUM(conn
))) {
5301 reply_nterror(req
, NT_STATUS_EAS_NOT_SUPPORTED
);
5305 /* Pull out the list of names. */
5306 ea_list
= read_ea_name_list(req
, pdata
+ 4, ea_size
- 4);
5309 req
, NT_STATUS_INVALID_PARAMETER
);
5315 case SMB_QUERY_POSIX_LOCK
:
5317 if (fsp
== NULL
|| fsp
->fh
->fd
== -1) {
5318 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
5322 if (total_data
!= POSIX_LOCK_DATA_SIZE
) {
5324 req
, NT_STATUS_INVALID_PARAMETER
);
5328 /* Copy the lock range data. */
5329 lock_data
= (char *)TALLOC_MEMDUP(
5330 req
, pdata
, total_data
);
5332 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
5335 lock_data_count
= total_data
;
5341 *pparams
= (char *)SMB_REALLOC(*pparams
,2);
5342 if (*pparams
== NULL
) {
5343 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
5350 * draft-leach-cifs-v1-spec-02.txt
5351 * 4.2.14 TRANS2_QUERY_PATH_INFORMATION: Get File Attributes given Path
5354 * The requested information is placed in the Data portion of the
5355 * transaction response. For the information levels greater than 0x100,
5356 * the transaction response has 1 parameter word which should be
5357 * ignored by the client.
5359 * However Windows only follows this rule for the IS_NAME_VALID call.
5361 switch (info_level
) {
5362 case SMB_INFO_IS_NAME_VALID
:
5367 if ((info_level
& 0xFF00) == 0xFF00) {
5369 * We use levels that start with 0xFF00
5370 * internally to represent SMB2 specific levels
5372 reply_nterror(req
, NT_STATUS_INVALID_LEVEL
);
5376 status
= smbd_do_qfilepathinfo(conn
, req
, info_level
,
5378 delete_pending
, write_time_ts
,
5380 lock_data_count
, lock_data
,
5381 req
->flags2
, max_data_bytes
,
5382 ppdata
, &data_size
);
5383 if (!NT_STATUS_IS_OK(status
)) {
5384 reply_nterror(req
, status
);
5388 send_trans2_replies(conn
, req
, params
, param_size
, *ppdata
, data_size
,
5394 /****************************************************************************
5395 Set a hard link (called by UNIX extensions and by NT rename with HARD link
5397 ****************************************************************************/
5399 NTSTATUS
hardlink_internals(TALLOC_CTX
*ctx
,
5400 connection_struct
*conn
,
5401 struct smb_request
*req
,
5402 bool overwrite_if_exists
,
5403 const struct smb_filename
*smb_fname_old
,
5404 struct smb_filename
*smb_fname_new
)
5406 NTSTATUS status
= NT_STATUS_OK
;
5408 /* source must already exist. */
5409 if (!VALID_STAT(smb_fname_old
->st
)) {
5410 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
5413 if (VALID_STAT(smb_fname_new
->st
)) {
5414 if (overwrite_if_exists
) {
5415 if (S_ISDIR(smb_fname_new
->st
.st_ex_mode
)) {
5416 return NT_STATUS_FILE_IS_A_DIRECTORY
;
5418 status
= unlink_internals(conn
,
5420 FILE_ATTRIBUTE_NORMAL
,
5423 if (!NT_STATUS_IS_OK(status
)) {
5427 /* Disallow if newname already exists. */
5428 return NT_STATUS_OBJECT_NAME_COLLISION
;
5432 /* No links from a directory. */
5433 if (S_ISDIR(smb_fname_old
->st
.st_ex_mode
)) {
5434 return NT_STATUS_FILE_IS_A_DIRECTORY
;
5437 /* Setting a hardlink to/from a stream isn't currently supported. */
5438 if (is_ntfs_stream_smb_fname(smb_fname_old
) ||
5439 is_ntfs_stream_smb_fname(smb_fname_new
)) {
5440 return NT_STATUS_INVALID_PARAMETER
;
5443 DEBUG(10,("hardlink_internals: doing hard link %s -> %s\n",
5444 smb_fname_old
->base_name
, smb_fname_new
->base_name
));
5446 if (SMB_VFS_LINK(conn
, smb_fname_old
->base_name
,
5447 smb_fname_new
->base_name
) != 0) {
5448 status
= map_nt_error_from_unix(errno
);
5449 DEBUG(3,("hardlink_internals: Error %s hard link %s -> %s\n",
5450 nt_errstr(status
), smb_fname_old
->base_name
,
5451 smb_fname_new
->base_name
));
5456 /****************************************************************************
5457 Deal with setting the time from any of the setfilepathinfo functions.
5458 ****************************************************************************/
5460 NTSTATUS
smb_set_file_time(connection_struct
*conn
,
5462 const struct smb_filename
*smb_fname
,
5463 struct smb_file_time
*ft
,
5464 bool setting_write_time
)
5466 struct smb_filename smb_fname_base
;
5468 FILE_NOTIFY_CHANGE_LAST_ACCESS
5469 |FILE_NOTIFY_CHANGE_LAST_WRITE
5470 |FILE_NOTIFY_CHANGE_CREATION
;
5472 if (!VALID_STAT(smb_fname
->st
)) {
5473 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
5476 if (fsp
&& !(fsp
->access_mask
& FILE_WRITE_ATTRIBUTES
)) {
5477 return NT_STATUS_ACCESS_DENIED
;
5480 /* get some defaults (no modifications) if any info is zero or -1. */
5481 if (null_timespec(ft
->create_time
)) {
5482 action
&= ~FILE_NOTIFY_CHANGE_CREATION
;
5485 if (null_timespec(ft
->atime
)) {
5486 action
&= ~FILE_NOTIFY_CHANGE_LAST_ACCESS
;
5489 if (null_timespec(ft
->mtime
)) {
5490 action
&= ~FILE_NOTIFY_CHANGE_LAST_WRITE
;
5493 if (!setting_write_time
) {
5494 /* ft->mtime comes from change time, not write time. */
5495 action
&= ~FILE_NOTIFY_CHANGE_LAST_WRITE
;
5498 /* Ensure the resolution is the correct for
5499 * what we can store on this filesystem. */
5501 round_timespec(conn
->ts_res
, &ft
->create_time
);
5502 round_timespec(conn
->ts_res
, &ft
->ctime
);
5503 round_timespec(conn
->ts_res
, &ft
->atime
);
5504 round_timespec(conn
->ts_res
, &ft
->mtime
);
5506 DEBUG(5,("smb_set_filetime: actime: %s\n ",
5507 time_to_asc(convert_timespec_to_time_t(ft
->atime
))));
5508 DEBUG(5,("smb_set_filetime: modtime: %s\n ",
5509 time_to_asc(convert_timespec_to_time_t(ft
->mtime
))));
5510 DEBUG(5,("smb_set_filetime: ctime: %s\n ",
5511 time_to_asc(convert_timespec_to_time_t(ft
->ctime
))));
5512 DEBUG(5,("smb_set_file_time: createtime: %s\n ",
5513 time_to_asc(convert_timespec_to_time_t(ft
->create_time
))));
5515 if (setting_write_time
) {
5517 * This was a Windows setfileinfo on an open file.
5518 * NT does this a lot. We also need to
5519 * set the time here, as it can be read by
5520 * FindFirst/FindNext and with the patch for bug #2045
5521 * in smbd/fileio.c it ensures that this timestamp is
5522 * kept sticky even after a write. We save the request
5523 * away and will set it on file close and after a write. JRA.
5526 DEBUG(10,("smb_set_file_time: setting pending modtime to %s\n",
5527 time_to_asc(convert_timespec_to_time_t(ft
->mtime
))));
5530 if (fsp
->base_fsp
) {
5531 set_sticky_write_time_fsp(fsp
->base_fsp
,
5534 set_sticky_write_time_fsp(fsp
, ft
->mtime
);
5537 set_sticky_write_time_path(
5538 vfs_file_id_from_sbuf(conn
, &smb_fname
->st
),
5543 DEBUG(10,("smb_set_file_time: setting utimes to modified values.\n"));
5545 /* Always call ntimes on the base, even if a stream was passed in. */
5546 smb_fname_base
= *smb_fname
;
5547 smb_fname_base
.stream_name
= NULL
;
5549 if(file_ntimes(conn
, &smb_fname_base
, ft
)!=0) {
5550 return map_nt_error_from_unix(errno
);
5553 notify_fname(conn
, NOTIFY_ACTION_MODIFIED
, action
,
5554 smb_fname
->base_name
);
5555 return NT_STATUS_OK
;
5558 /****************************************************************************
5559 Deal with setting the dosmode from any of the setfilepathinfo functions.
5560 ****************************************************************************/
5562 static NTSTATUS
smb_set_file_dosmode(connection_struct
*conn
,
5563 const struct smb_filename
*smb_fname
,
5566 struct smb_filename
*smb_fname_base
= NULL
;
5569 if (!VALID_STAT(smb_fname
->st
)) {
5570 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
5573 /* Always operate on the base_name, even if a stream was passed in. */
5574 status
= create_synthetic_smb_fname(talloc_tos(), smb_fname
->base_name
,
5575 NULL
, &smb_fname
->st
,
5577 if (!NT_STATUS_IS_OK(status
)) {
5582 if (S_ISDIR(smb_fname_base
->st
.st_ex_mode
)) {
5589 DEBUG(6,("smb_set_file_dosmode: dosmode: 0x%x\n", (unsigned int)dosmode
));
5591 /* check the mode isn't different, before changing it */
5592 if ((dosmode
!= 0) && (dosmode
!= dos_mode(conn
, smb_fname_base
))) {
5593 DEBUG(10,("smb_set_file_dosmode: file %s : setting dos mode "
5594 "0x%x\n", smb_fname_str_dbg(smb_fname_base
),
5595 (unsigned int)dosmode
));
5597 if(file_set_dosmode(conn
, smb_fname_base
, dosmode
, NULL
,
5599 DEBUG(2,("smb_set_file_dosmode: file_set_dosmode of "
5601 smb_fname_str_dbg(smb_fname_base
),
5603 status
= map_nt_error_from_unix(errno
);
5607 status
= NT_STATUS_OK
;
5609 TALLOC_FREE(smb_fname_base
);
5613 /****************************************************************************
5614 Deal with setting the size from any of the setfilepathinfo functions.
5615 ****************************************************************************/
5617 static NTSTATUS
smb_set_file_size(connection_struct
*conn
,
5618 struct smb_request
*req
,
5620 const struct smb_filename
*smb_fname
,
5621 const SMB_STRUCT_STAT
*psbuf
,
5623 bool fail_after_createfile
)
5625 NTSTATUS status
= NT_STATUS_OK
;
5626 struct smb_filename
*smb_fname_tmp
= NULL
;
5627 files_struct
*new_fsp
= NULL
;
5629 if (!VALID_STAT(*psbuf
)) {
5630 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
5633 if (fsp
&& !(fsp
->access_mask
& FILE_WRITE_DATA
)) {
5634 return NT_STATUS_ACCESS_DENIED
;
5637 DEBUG(6,("smb_set_file_size: size: %.0f ", (double)size
));
5639 if (size
== get_file_size_stat(psbuf
)) {
5640 return NT_STATUS_OK
;
5643 DEBUG(10,("smb_set_file_size: file %s : setting new size to %.0f\n",
5644 smb_fname_str_dbg(smb_fname
), (double)size
));
5646 if (fsp
&& fsp
->fh
->fd
!= -1) {
5647 /* Handle based call. */
5648 if (vfs_set_filelen(fsp
, size
) == -1) {
5649 return map_nt_error_from_unix(errno
);
5651 trigger_write_time_update_immediate(fsp
);
5652 return NT_STATUS_OK
;
5655 status
= copy_smb_filename(talloc_tos(), smb_fname
, &smb_fname_tmp
);
5656 if (!NT_STATUS_IS_OK(status
)) {
5660 smb_fname_tmp
->st
= *psbuf
;
5662 status
= SMB_VFS_CREATE_FILE(
5665 0, /* root_dir_fid */
5666 smb_fname_tmp
, /* fname */
5667 FILE_WRITE_DATA
, /* access_mask */
5668 (FILE_SHARE_READ
| FILE_SHARE_WRITE
| /* share_access */
5670 FILE_OPEN
, /* create_disposition*/
5671 0, /* create_options */
5672 FILE_ATTRIBUTE_NORMAL
, /* file_attributes */
5673 FORCE_OPLOCK_BREAK_TO_NONE
, /* oplock_request */
5674 0, /* allocation_size */
5675 0, /* private_flags */
5678 &new_fsp
, /* result */
5681 TALLOC_FREE(smb_fname_tmp
);
5683 if (!NT_STATUS_IS_OK(status
)) {
5684 /* NB. We check for open_was_deferred in the caller. */
5688 /* See RAW-SFILEINFO-END-OF-FILE */
5689 if (fail_after_createfile
) {
5690 close_file(req
, new_fsp
,NORMAL_CLOSE
);
5691 return NT_STATUS_INVALID_LEVEL
;
5694 if (vfs_set_filelen(new_fsp
, size
) == -1) {
5695 status
= map_nt_error_from_unix(errno
);
5696 close_file(req
, new_fsp
,NORMAL_CLOSE
);
5700 trigger_write_time_update_immediate(new_fsp
);
5701 close_file(req
, new_fsp
,NORMAL_CLOSE
);
5702 return NT_STATUS_OK
;
5705 /****************************************************************************
5706 Deal with SMB_INFO_SET_EA.
5707 ****************************************************************************/
5709 static NTSTATUS
smb_info_set_ea(connection_struct
*conn
,
5713 const struct smb_filename
*smb_fname
)
5715 struct ea_list
*ea_list
= NULL
;
5716 TALLOC_CTX
*ctx
= NULL
;
5717 NTSTATUS status
= NT_STATUS_OK
;
5719 if (total_data
< 10) {
5721 /* OS/2 workplace shell seems to send SET_EA requests of "null"
5722 length. They seem to have no effect. Bug #3212. JRA */
5724 if ((total_data
== 4) && (IVAL(pdata
,0) == 4)) {
5725 /* We're done. We only get EA info in this call. */
5726 return NT_STATUS_OK
;
5729 return NT_STATUS_INVALID_PARAMETER
;
5732 if (IVAL(pdata
,0) > total_data
) {
5733 DEBUG(10,("smb_info_set_ea: bad total data size (%u) > %u\n",
5734 IVAL(pdata
,0), (unsigned int)total_data
));
5735 return NT_STATUS_INVALID_PARAMETER
;
5739 ea_list
= read_ea_list(ctx
, pdata
+ 4, total_data
- 4);
5741 return NT_STATUS_INVALID_PARAMETER
;
5744 if (fsp
&& !(fsp
->access_mask
& FILE_WRITE_EA
)) {
5745 return NT_STATUS_ACCESS_DENIED
;
5748 status
= set_ea(conn
, fsp
, smb_fname
, ea_list
);
5753 /****************************************************************************
5754 Deal with SMB_FILE_FULL_EA_INFORMATION set.
5755 ****************************************************************************/
5757 static NTSTATUS
smb_set_file_full_ea_info(connection_struct
*conn
,
5762 struct ea_list
*ea_list
= NULL
;
5766 return NT_STATUS_INVALID_HANDLE
;
5769 if (!lp_ea_support(SNUM(conn
))) {
5770 DEBUG(10, ("smb_set_file_full_ea_info - ea_len = %u but "
5771 "EA's not supported.\n",
5772 (unsigned int)total_data
));
5773 return NT_STATUS_EAS_NOT_SUPPORTED
;
5776 if (total_data
< 10) {
5777 DEBUG(10, ("smb_set_file_full_ea_info - ea_len = %u "
5779 (unsigned int)total_data
));
5780 return NT_STATUS_INVALID_PARAMETER
;
5783 ea_list
= read_nttrans_ea_list(talloc_tos(),
5788 return NT_STATUS_INVALID_PARAMETER
;
5791 if (fsp
&& !(fsp
->access_mask
& FILE_WRITE_EA
)) {
5792 return NT_STATUS_ACCESS_DENIED
;
5795 status
= set_ea(conn
, fsp
, fsp
->fsp_name
, ea_list
);
5797 DEBUG(10, ("smb_set_file_full_ea_info on file %s returned %s\n",
5798 smb_fname_str_dbg(fsp
->fsp_name
),
5799 nt_errstr(status
) ));
5805 /****************************************************************************
5806 Deal with SMB_SET_FILE_DISPOSITION_INFO.
5807 ****************************************************************************/
5809 static NTSTATUS
smb_set_file_disposition_info(connection_struct
*conn
,
5813 struct smb_filename
*smb_fname
)
5815 NTSTATUS status
= NT_STATUS_OK
;
5816 bool delete_on_close
;
5819 if (total_data
< 1) {
5820 return NT_STATUS_INVALID_PARAMETER
;
5824 return NT_STATUS_INVALID_HANDLE
;
5827 delete_on_close
= (CVAL(pdata
,0) ? True
: False
);
5828 dosmode
= dos_mode(conn
, smb_fname
);
5830 DEBUG(10,("smb_set_file_disposition_info: file %s, dosmode = %u, "
5831 "delete_on_close = %u\n",
5832 smb_fname_str_dbg(smb_fname
),
5833 (unsigned int)dosmode
,
5834 (unsigned int)delete_on_close
));
5836 if (delete_on_close
) {
5837 status
= can_set_delete_on_close(fsp
, dosmode
);
5838 if (!NT_STATUS_IS_OK(status
)) {
5843 /* The set is across all open files on this dev/inode pair. */
5844 if (!set_delete_on_close(fsp
, delete_on_close
,
5845 &conn
->session_info
->utok
)) {
5846 return NT_STATUS_ACCESS_DENIED
;
5848 return NT_STATUS_OK
;
5851 /****************************************************************************
5852 Deal with SMB_FILE_POSITION_INFORMATION.
5853 ****************************************************************************/
5855 static NTSTATUS
smb_file_position_information(connection_struct
*conn
,
5860 uint64_t position_information
;
5862 if (total_data
< 8) {
5863 return NT_STATUS_INVALID_PARAMETER
;
5867 /* Ignore on pathname based set. */
5868 return NT_STATUS_OK
;
5871 position_information
= (uint64_t)IVAL(pdata
,0);
5872 #ifdef LARGE_SMB_OFF_T
5873 position_information
|= (((uint64_t)IVAL(pdata
,4)) << 32);
5874 #else /* LARGE_SMB_OFF_T */
5875 if (IVAL(pdata
,4) != 0) {
5876 /* more than 32 bits? */
5877 return NT_STATUS_INVALID_PARAMETER
;
5879 #endif /* LARGE_SMB_OFF_T */
5881 DEBUG(10,("smb_file_position_information: Set file position "
5882 "information for file %s to %.0f\n", fsp_str_dbg(fsp
),
5883 (double)position_information
));
5884 fsp
->fh
->position_information
= position_information
;
5885 return NT_STATUS_OK
;
5888 /****************************************************************************
5889 Deal with SMB_FILE_MODE_INFORMATION.
5890 ****************************************************************************/
5892 static NTSTATUS
smb_file_mode_information(connection_struct
*conn
,
5898 if (total_data
< 4) {
5899 return NT_STATUS_INVALID_PARAMETER
;
5901 mode
= IVAL(pdata
,0);
5902 if (mode
!= 0 && mode
!= 2 && mode
!= 4 && mode
!= 6) {
5903 return NT_STATUS_INVALID_PARAMETER
;
5905 return NT_STATUS_OK
;
5908 /****************************************************************************
5909 Deal with SMB_SET_FILE_UNIX_LINK (create a UNIX symlink).
5910 ****************************************************************************/
5912 static NTSTATUS
smb_set_file_unix_link(connection_struct
*conn
,
5913 struct smb_request
*req
,
5916 const struct smb_filename
*smb_fname
)
5918 char *link_target
= NULL
;
5919 const char *newname
= smb_fname
->base_name
;
5920 TALLOC_CTX
*ctx
= talloc_tos();
5922 /* Set a symbolic link. */
5923 /* Don't allow this if follow links is false. */
5925 if (total_data
== 0) {
5926 return NT_STATUS_INVALID_PARAMETER
;
5929 if (!lp_symlinks(SNUM(conn
))) {
5930 return NT_STATUS_ACCESS_DENIED
;
5933 srvstr_pull_talloc(ctx
, pdata
, req
->flags2
, &link_target
, pdata
,
5934 total_data
, STR_TERMINATE
);
5937 return NT_STATUS_INVALID_PARAMETER
;
5940 DEBUG(10,("smb_set_file_unix_link: SMB_SET_FILE_UNIX_LINK doing symlink %s -> %s\n",
5941 newname
, link_target
));
5943 if (SMB_VFS_SYMLINK(conn
,link_target
,newname
) != 0) {
5944 return map_nt_error_from_unix(errno
);
5947 return NT_STATUS_OK
;
5950 /****************************************************************************
5951 Deal with SMB_SET_FILE_UNIX_HLINK (create a UNIX hard link).
5952 ****************************************************************************/
5954 static NTSTATUS
smb_set_file_unix_hlink(connection_struct
*conn
,
5955 struct smb_request
*req
,
5956 const char *pdata
, int total_data
,
5957 struct smb_filename
*smb_fname_new
)
5959 char *oldname
= NULL
;
5960 struct smb_filename
*smb_fname_old
= NULL
;
5961 TALLOC_CTX
*ctx
= talloc_tos();
5962 NTSTATUS status
= NT_STATUS_OK
;
5964 /* Set a hard link. */
5965 if (total_data
== 0) {
5966 return NT_STATUS_INVALID_PARAMETER
;
5969 srvstr_get_path(ctx
, pdata
, req
->flags2
, &oldname
, pdata
,
5970 total_data
, STR_TERMINATE
, &status
);
5971 if (!NT_STATUS_IS_OK(status
)) {
5975 DEBUG(10,("smb_set_file_unix_hlink: SMB_SET_FILE_UNIX_LINK doing hard link %s -> %s\n",
5976 smb_fname_str_dbg(smb_fname_new
), oldname
));
5978 status
= filename_convert(ctx
,
5980 req
->flags2
& FLAGS2_DFS_PATHNAMES
,
5985 if (!NT_STATUS_IS_OK(status
)) {
5989 return hardlink_internals(ctx
, conn
, req
, false,
5990 smb_fname_old
, smb_fname_new
);
5993 /****************************************************************************
5994 Deal with SMB2_FILE_RENAME_INFORMATION_INTERNAL
5995 ****************************************************************************/
5997 static NTSTATUS
smb2_file_rename_information(connection_struct
*conn
,
5998 struct smb_request
*req
,
6002 struct smb_filename
*smb_fname_src
)
6006 char *newname
= NULL
;
6007 struct smb_filename
*smb_fname_dst
= NULL
;
6008 NTSTATUS status
= NT_STATUS_OK
;
6009 TALLOC_CTX
*ctx
= talloc_tos();
6012 return NT_STATUS_INVALID_HANDLE
;
6015 if (total_data
< 20) {
6016 return NT_STATUS_INVALID_PARAMETER
;
6019 overwrite
= (CVAL(pdata
,0) ? True
: False
);
6020 len
= IVAL(pdata
,16);
6022 if (len
> (total_data
- 20) || (len
== 0)) {
6023 return NT_STATUS_INVALID_PARAMETER
;
6026 srvstr_get_path(ctx
, pdata
, req
->flags2
, &newname
,
6027 &pdata
[20], len
, STR_TERMINATE
,
6029 if (!NT_STATUS_IS_OK(status
)) {
6033 DEBUG(10,("smb2_file_rename_information: got name |%s|\n",
6036 status
= filename_convert(ctx
,
6038 req
->flags2
& FLAGS2_DFS_PATHNAMES
,
6043 if (!NT_STATUS_IS_OK(status
)) {
6047 if (fsp
->base_fsp
) {
6048 /* newname must be a stream name. */
6049 if (newname
[0] != ':') {
6050 return NT_STATUS_NOT_SUPPORTED
;
6053 /* Create an smb_fname to call rename_internals_fsp() with. */
6054 status
= create_synthetic_smb_fname(talloc_tos(),
6055 fsp
->base_fsp
->fsp_name
->base_name
, newname
, NULL
,
6057 if (!NT_STATUS_IS_OK(status
)) {
6062 * Set the original last component, since
6063 * rename_internals_fsp() requires it.
6065 smb_fname_dst
->original_lcomp
= talloc_strdup(smb_fname_dst
,
6067 if (smb_fname_dst
->original_lcomp
== NULL
) {
6068 status
= NT_STATUS_NO_MEMORY
;
6074 DEBUG(10,("smb2_file_rename_information: "
6075 "SMB_FILE_RENAME_INFORMATION (fnum %d) %s -> %s\n",
6076 fsp
->fnum
, fsp_str_dbg(fsp
),
6077 smb_fname_str_dbg(smb_fname_dst
)));
6078 status
= rename_internals_fsp(conn
, fsp
, smb_fname_dst
, 0,
6082 TALLOC_FREE(smb_fname_dst
);
6086 static NTSTATUS
smb_file_link_information(connection_struct
*conn
,
6087 struct smb_request
*req
,
6091 struct smb_filename
*smb_fname_src
)
6095 char *newname
= NULL
;
6096 struct smb_filename
*smb_fname_dst
= NULL
;
6097 NTSTATUS status
= NT_STATUS_OK
;
6098 TALLOC_CTX
*ctx
= talloc_tos();
6101 return NT_STATUS_INVALID_HANDLE
;
6104 if (total_data
< 20) {
6105 return NT_STATUS_INVALID_PARAMETER
;
6108 overwrite
= (CVAL(pdata
,0) ? true : false);
6109 len
= IVAL(pdata
,16);
6111 if (len
> (total_data
- 20) || (len
== 0)) {
6112 return NT_STATUS_INVALID_PARAMETER
;
6115 srvstr_get_path(ctx
, pdata
, req
->flags2
, &newname
,
6116 &pdata
[20], len
, STR_TERMINATE
,
6118 if (!NT_STATUS_IS_OK(status
)) {
6122 DEBUG(10,("smb_file_link_information: got name |%s|\n",
6125 status
= filename_convert(ctx
,
6127 req
->flags2
& FLAGS2_DFS_PATHNAMES
,
6132 if (!NT_STATUS_IS_OK(status
)) {
6136 if (fsp
->base_fsp
) {
6137 /* No stream names. */
6138 return NT_STATUS_NOT_SUPPORTED
;
6141 DEBUG(10,("smb_file_link_information: "
6142 "SMB_FILE_LINK_INFORMATION (fnum %d) %s -> %s\n",
6143 fsp
->fnum
, fsp_str_dbg(fsp
),
6144 smb_fname_str_dbg(smb_fname_dst
)));
6145 status
= hardlink_internals(ctx
,
6152 TALLOC_FREE(smb_fname_dst
);
6156 /****************************************************************************
6157 Deal with SMB_FILE_RENAME_INFORMATION.
6158 ****************************************************************************/
6160 static NTSTATUS
smb_file_rename_information(connection_struct
*conn
,
6161 struct smb_request
*req
,
6165 struct smb_filename
*smb_fname_src
)
6170 char *newname
= NULL
;
6171 struct smb_filename
*smb_fname_dst
= NULL
;
6172 bool dest_has_wcard
= False
;
6173 NTSTATUS status
= NT_STATUS_OK
;
6175 TALLOC_CTX
*ctx
= talloc_tos();
6177 if (total_data
< 13) {
6178 return NT_STATUS_INVALID_PARAMETER
;
6181 overwrite
= (CVAL(pdata
,0) ? True
: False
);
6182 root_fid
= IVAL(pdata
,4);
6183 len
= IVAL(pdata
,8);
6185 if (len
> (total_data
- 12) || (len
== 0) || (root_fid
!= 0)) {
6186 return NT_STATUS_INVALID_PARAMETER
;
6189 srvstr_get_path_wcard(ctx
, pdata
, req
->flags2
, &newname
, &pdata
[12],
6192 if (!NT_STATUS_IS_OK(status
)) {
6196 DEBUG(10,("smb_file_rename_information: got name |%s|\n",
6199 status
= resolve_dfspath_wcard(ctx
, conn
,
6200 req
->flags2
& FLAGS2_DFS_PATHNAMES
,
6205 if (!NT_STATUS_IS_OK(status
)) {
6209 /* Check the new name has no '/' characters. */
6210 if (strchr_m(newname
, '/')) {
6211 return NT_STATUS_NOT_SUPPORTED
;
6214 if (fsp
&& fsp
->base_fsp
) {
6215 /* newname must be a stream name. */
6216 if (newname
[0] != ':') {
6217 return NT_STATUS_NOT_SUPPORTED
;
6220 /* Create an smb_fname to call rename_internals_fsp() with. */
6221 status
= create_synthetic_smb_fname(talloc_tos(),
6222 fsp
->base_fsp
->fsp_name
->base_name
, newname
, NULL
,
6224 if (!NT_STATUS_IS_OK(status
)) {
6229 * Set the original last component, since
6230 * rename_internals_fsp() requires it.
6232 smb_fname_dst
->original_lcomp
= talloc_strdup(smb_fname_dst
,
6234 if (smb_fname_dst
->original_lcomp
== NULL
) {
6235 status
= NT_STATUS_NO_MEMORY
;
6241 * Build up an smb_fname_dst based on the filename passed in.
6242 * We basically just strip off the last component, and put on
6243 * the newname instead.
6245 char *base_name
= NULL
;
6247 /* newname must *not* be a stream name. */
6248 if (newname
[0] == ':') {
6249 return NT_STATUS_NOT_SUPPORTED
;
6253 * Strip off the last component (filename) of the path passed
6256 base_name
= talloc_strdup(ctx
, smb_fname_src
->base_name
);
6258 return NT_STATUS_NO_MEMORY
;
6260 p
= strrchr_m(base_name
, '/');
6264 base_name
= talloc_strdup(ctx
, "");
6266 return NT_STATUS_NO_MEMORY
;
6269 /* Append the new name. */
6270 base_name
= talloc_asprintf_append(base_name
,
6274 return NT_STATUS_NO_MEMORY
;
6277 status
= unix_convert(ctx
, conn
, base_name
, &smb_fname_dst
,
6280 UCF_ALWAYS_ALLOW_WCARD_LCOMP
:
6283 /* If an error we expect this to be
6284 * NT_STATUS_OBJECT_PATH_NOT_FOUND */
6286 if (!NT_STATUS_IS_OK(status
)) {
6287 if(!NT_STATUS_EQUAL(NT_STATUS_OBJECT_PATH_NOT_FOUND
,
6291 /* Create an smb_fname to call rename_internals_fsp() */
6292 status
= create_synthetic_smb_fname(ctx
,
6296 if (!NT_STATUS_IS_OK(status
)) {
6303 DEBUG(10,("smb_file_rename_information: "
6304 "SMB_FILE_RENAME_INFORMATION (fnum %d) %s -> %s\n",
6305 fsp
->fnum
, fsp_str_dbg(fsp
),
6306 smb_fname_str_dbg(smb_fname_dst
)));
6307 status
= rename_internals_fsp(conn
, fsp
, smb_fname_dst
, 0,
6310 DEBUG(10,("smb_file_rename_information: "
6311 "SMB_FILE_RENAME_INFORMATION %s -> %s\n",
6312 smb_fname_str_dbg(smb_fname_src
),
6313 smb_fname_str_dbg(smb_fname_dst
)));
6314 status
= rename_internals(ctx
, conn
, req
, smb_fname_src
,
6315 smb_fname_dst
, 0, overwrite
, false,
6317 FILE_WRITE_ATTRIBUTES
);
6320 TALLOC_FREE(smb_fname_dst
);
6324 /****************************************************************************
6325 Deal with SMB_SET_POSIX_ACL.
6326 ****************************************************************************/
6328 #if defined(HAVE_POSIX_ACLS)
6329 static NTSTATUS
smb_set_posix_acl(connection_struct
*conn
,
6333 const struct smb_filename
*smb_fname
)
6335 uint16 posix_acl_version
;
6336 uint16 num_file_acls
;
6337 uint16 num_def_acls
;
6338 bool valid_file_acls
= True
;
6339 bool valid_def_acls
= True
;
6341 if (total_data
< SMB_POSIX_ACL_HEADER_SIZE
) {
6342 return NT_STATUS_INVALID_PARAMETER
;
6344 posix_acl_version
= SVAL(pdata
,0);
6345 num_file_acls
= SVAL(pdata
,2);
6346 num_def_acls
= SVAL(pdata
,4);
6348 if (num_file_acls
== SMB_POSIX_IGNORE_ACE_ENTRIES
) {
6349 valid_file_acls
= False
;
6353 if (num_def_acls
== SMB_POSIX_IGNORE_ACE_ENTRIES
) {
6354 valid_def_acls
= False
;
6358 if (posix_acl_version
!= SMB_POSIX_ACL_VERSION
) {
6359 return NT_STATUS_INVALID_PARAMETER
;
6362 if (total_data
< SMB_POSIX_ACL_HEADER_SIZE
+
6363 (num_file_acls
+num_def_acls
)*SMB_POSIX_ACL_ENTRY_SIZE
) {
6364 return NT_STATUS_INVALID_PARAMETER
;
6367 DEBUG(10,("smb_set_posix_acl: file %s num_file_acls = %u, num_def_acls = %u\n",
6368 smb_fname
? smb_fname_str_dbg(smb_fname
) : fsp_str_dbg(fsp
),
6369 (unsigned int)num_file_acls
,
6370 (unsigned int)num_def_acls
));
6372 if (valid_file_acls
&& !set_unix_posix_acl(conn
, fsp
,
6373 smb_fname
->base_name
, num_file_acls
,
6374 pdata
+ SMB_POSIX_ACL_HEADER_SIZE
)) {
6375 return map_nt_error_from_unix(errno
);
6378 if (valid_def_acls
&& !set_unix_posix_default_acl(conn
,
6379 smb_fname
->base_name
, &smb_fname
->st
, num_def_acls
,
6380 pdata
+ SMB_POSIX_ACL_HEADER_SIZE
+
6381 (num_file_acls
*SMB_POSIX_ACL_ENTRY_SIZE
))) {
6382 return map_nt_error_from_unix(errno
);
6384 return NT_STATUS_OK
;
6388 /****************************************************************************
6389 Deal with SMB_SET_POSIX_LOCK.
6390 ****************************************************************************/
6392 static NTSTATUS
smb_set_posix_lock(connection_struct
*conn
,
6393 struct smb_request
*req
,
6401 bool blocking_lock
= False
;
6402 enum brl_type lock_type
;
6404 NTSTATUS status
= NT_STATUS_OK
;
6406 if (fsp
== NULL
|| fsp
->fh
->fd
== -1) {
6407 return NT_STATUS_INVALID_HANDLE
;
6410 if (total_data
!= POSIX_LOCK_DATA_SIZE
) {
6411 return NT_STATUS_INVALID_PARAMETER
;
6414 switch (SVAL(pdata
, POSIX_LOCK_TYPE_OFFSET
)) {
6415 case POSIX_LOCK_TYPE_READ
:
6416 lock_type
= READ_LOCK
;
6418 case POSIX_LOCK_TYPE_WRITE
:
6419 /* Return the right POSIX-mappable error code for files opened read-only. */
6420 if (!fsp
->can_write
) {
6421 return NT_STATUS_INVALID_HANDLE
;
6423 lock_type
= WRITE_LOCK
;
6425 case POSIX_LOCK_TYPE_UNLOCK
:
6426 lock_type
= UNLOCK_LOCK
;
6429 return NT_STATUS_INVALID_PARAMETER
;
6432 if (SVAL(pdata
,POSIX_LOCK_FLAGS_OFFSET
) == POSIX_LOCK_FLAG_NOWAIT
) {
6433 blocking_lock
= False
;
6434 } else if (SVAL(pdata
,POSIX_LOCK_FLAGS_OFFSET
) == POSIX_LOCK_FLAG_WAIT
) {
6435 blocking_lock
= True
;
6437 return NT_STATUS_INVALID_PARAMETER
;
6440 if (!lp_blocking_locks(SNUM(conn
))) {
6441 blocking_lock
= False
;
6444 smblctx
= (uint64_t)IVAL(pdata
, POSIX_LOCK_PID_OFFSET
);
6445 #if defined(HAVE_LONGLONG)
6446 offset
= (((uint64_t) IVAL(pdata
,(POSIX_LOCK_START_OFFSET
+4))) << 32) |
6447 ((uint64_t) IVAL(pdata
,POSIX_LOCK_START_OFFSET
));
6448 count
= (((uint64_t) IVAL(pdata
,(POSIX_LOCK_LEN_OFFSET
+4))) << 32) |
6449 ((uint64_t) IVAL(pdata
,POSIX_LOCK_LEN_OFFSET
));
6450 #else /* HAVE_LONGLONG */
6451 offset
= (uint64_t)IVAL(pdata
,POSIX_LOCK_START_OFFSET
);
6452 count
= (uint64_t)IVAL(pdata
,POSIX_LOCK_LEN_OFFSET
);
6453 #endif /* HAVE_LONGLONG */
6455 DEBUG(10,("smb_set_posix_lock: file %s, lock_type = %u,"
6456 "smblctx = %llu, count = %.0f, offset = %.0f\n",
6458 (unsigned int)lock_type
,
6459 (unsigned long long)smblctx
,
6463 if (lock_type
== UNLOCK_LOCK
) {
6464 status
= do_unlock(req
->sconn
->msg_ctx
,
6471 uint64_t block_smblctx
;
6473 struct byte_range_lock
*br_lck
= do_lock(req
->sconn
->msg_ctx
,
6485 if (br_lck
&& blocking_lock
&& ERROR_WAS_LOCK_DENIED(status
)) {
6487 * A blocking lock was requested. Package up
6488 * this smb into a queued request and push it
6489 * onto the blocking lock queue.
6491 if(push_blocking_lock_request(br_lck
,
6494 -1, /* infinite timeout. */
6502 TALLOC_FREE(br_lck
);
6506 TALLOC_FREE(br_lck
);
6512 /****************************************************************************
6513 Deal with SMB_SET_FILE_BASIC_INFO.
6514 ****************************************************************************/
6516 static NTSTATUS
smb_set_file_basic_info(connection_struct
*conn
,
6520 const struct smb_filename
*smb_fname
)
6522 /* Patch to do this correctly from Paul Eggert <eggert@twinsun.com>. */
6523 struct smb_file_time ft
;
6525 NTSTATUS status
= NT_STATUS_OK
;
6529 if (total_data
< 36) {
6530 return NT_STATUS_INVALID_PARAMETER
;
6533 if (fsp
&& !(fsp
->access_mask
& FILE_WRITE_ATTRIBUTES
)) {
6534 return NT_STATUS_ACCESS_DENIED
;
6537 /* Set the attributes */
6538 dosmode
= IVAL(pdata
,32);
6539 status
= smb_set_file_dosmode(conn
, smb_fname
, dosmode
);
6540 if (!NT_STATUS_IS_OK(status
)) {
6545 ft
.create_time
= interpret_long_date(pdata
);
6548 ft
.atime
= interpret_long_date(pdata
+8);
6551 ft
.mtime
= interpret_long_date(pdata
+16);
6554 ft
.ctime
= interpret_long_date(pdata
+24);
6556 DEBUG(10, ("smb_set_file_basic_info: file %s\n",
6557 smb_fname_str_dbg(smb_fname
)));
6559 return smb_set_file_time(conn
, fsp
, smb_fname
, &ft
,
6563 /****************************************************************************
6564 Deal with SMB_INFO_STANDARD.
6565 ****************************************************************************/
6567 static NTSTATUS
smb_set_info_standard(connection_struct
*conn
,
6571 const struct smb_filename
*smb_fname
)
6573 struct smb_file_time ft
;
6577 if (total_data
< 12) {
6578 return NT_STATUS_INVALID_PARAMETER
;
6581 if (fsp
&& !(fsp
->access_mask
& FILE_WRITE_ATTRIBUTES
)) {
6582 return NT_STATUS_ACCESS_DENIED
;
6586 ft
.create_time
= convert_time_t_to_timespec(srv_make_unix_date2(pdata
));
6588 ft
.atime
= convert_time_t_to_timespec(srv_make_unix_date2(pdata
+4));
6590 ft
.mtime
= convert_time_t_to_timespec(srv_make_unix_date2(pdata
+8));
6592 DEBUG(10,("smb_set_info_standard: file %s\n",
6593 smb_fname_str_dbg(smb_fname
)));
6595 return smb_set_file_time(conn
,
6602 /****************************************************************************
6603 Deal with SMB_SET_FILE_ALLOCATION_INFO.
6604 ****************************************************************************/
6606 static NTSTATUS
smb_set_file_allocation_info(connection_struct
*conn
,
6607 struct smb_request
*req
,
6611 struct smb_filename
*smb_fname
)
6613 uint64_t allocation_size
= 0;
6614 NTSTATUS status
= NT_STATUS_OK
;
6615 files_struct
*new_fsp
= NULL
;
6617 if (!VALID_STAT(smb_fname
->st
)) {
6618 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
6621 if (total_data
< 8) {
6622 return NT_STATUS_INVALID_PARAMETER
;
6625 allocation_size
= (uint64_t)IVAL(pdata
,0);
6626 #ifdef LARGE_SMB_OFF_T
6627 allocation_size
|= (((uint64_t)IVAL(pdata
,4)) << 32);
6628 #else /* LARGE_SMB_OFF_T */
6629 if (IVAL(pdata
,4) != 0) {
6630 /* more than 32 bits? */
6631 return NT_STATUS_INVALID_PARAMETER
;
6633 #endif /* LARGE_SMB_OFF_T */
6635 DEBUG(10,("smb_set_file_allocation_info: Set file allocation info for "
6636 "file %s to %.0f\n", smb_fname_str_dbg(smb_fname
),
6637 (double)allocation_size
));
6639 if (allocation_size
) {
6640 allocation_size
= smb_roundup(conn
, allocation_size
);
6643 if (fsp
&& !(fsp
->access_mask
& FILE_WRITE_DATA
)) {
6644 return NT_STATUS_ACCESS_DENIED
;
6647 DEBUG(10,("smb_set_file_allocation_info: file %s : setting new "
6648 "allocation size to %.0f\n", smb_fname_str_dbg(smb_fname
),
6649 (double)allocation_size
));
6651 if (fsp
&& fsp
->fh
->fd
!= -1) {
6652 /* Open file handle. */
6653 /* Only change if needed. */
6654 if (allocation_size
!= get_file_size_stat(&smb_fname
->st
)) {
6655 if (vfs_allocate_file_space(fsp
, allocation_size
) == -1) {
6656 return map_nt_error_from_unix(errno
);
6659 /* But always update the time. */
6661 * This is equivalent to a write. Ensure it's seen immediately
6662 * if there are no pending writes.
6664 trigger_write_time_update_immediate(fsp
);
6665 return NT_STATUS_OK
;
6668 /* Pathname or stat or directory file. */
6669 status
= SMB_VFS_CREATE_FILE(
6672 0, /* root_dir_fid */
6673 smb_fname
, /* fname */
6674 FILE_WRITE_DATA
, /* access_mask */
6675 (FILE_SHARE_READ
| FILE_SHARE_WRITE
| /* share_access */
6677 FILE_OPEN
, /* create_disposition*/
6678 0, /* create_options */
6679 FILE_ATTRIBUTE_NORMAL
, /* file_attributes */
6680 FORCE_OPLOCK_BREAK_TO_NONE
, /* oplock_request */
6681 0, /* allocation_size */
6682 0, /* private_flags */
6685 &new_fsp
, /* result */
6688 if (!NT_STATUS_IS_OK(status
)) {
6689 /* NB. We check for open_was_deferred in the caller. */
6693 /* Only change if needed. */
6694 if (allocation_size
!= get_file_size_stat(&smb_fname
->st
)) {
6695 if (vfs_allocate_file_space(new_fsp
, allocation_size
) == -1) {
6696 status
= map_nt_error_from_unix(errno
);
6697 close_file(req
, new_fsp
, NORMAL_CLOSE
);
6702 /* Changing the allocation size should set the last mod time. */
6704 * This is equivalent to a write. Ensure it's seen immediately
6705 * if there are no pending writes.
6707 trigger_write_time_update_immediate(new_fsp
);
6709 close_file(req
, new_fsp
, NORMAL_CLOSE
);
6710 return NT_STATUS_OK
;
6713 /****************************************************************************
6714 Deal with SMB_SET_FILE_END_OF_FILE_INFO.
6715 ****************************************************************************/
6717 static NTSTATUS
smb_set_file_end_of_file_info(connection_struct
*conn
,
6718 struct smb_request
*req
,
6722 const struct smb_filename
*smb_fname
,
6723 bool fail_after_createfile
)
6727 if (total_data
< 8) {
6728 return NT_STATUS_INVALID_PARAMETER
;
6731 size
= IVAL(pdata
,0);
6732 #ifdef LARGE_SMB_OFF_T
6733 size
|= (((SMB_OFF_T
)IVAL(pdata
,4)) << 32);
6734 #else /* LARGE_SMB_OFF_T */
6735 if (IVAL(pdata
,4) != 0) {
6736 /* more than 32 bits? */
6737 return NT_STATUS_INVALID_PARAMETER
;
6739 #endif /* LARGE_SMB_OFF_T */
6740 DEBUG(10,("smb_set_file_end_of_file_info: Set end of file info for "
6741 "file %s to %.0f\n", smb_fname_str_dbg(smb_fname
),
6744 if (fsp
&& !(fsp
->access_mask
& FILE_WRITE_DATA
)) {
6745 return NT_STATUS_ACCESS_DENIED
;
6748 return smb_set_file_size(conn
, req
,
6753 fail_after_createfile
);
6756 /****************************************************************************
6757 Allow a UNIX info mknod.
6758 ****************************************************************************/
6760 static NTSTATUS
smb_unix_mknod(connection_struct
*conn
,
6763 const struct smb_filename
*smb_fname
)
6765 uint32 file_type
= IVAL(pdata
,56);
6766 #if defined(HAVE_MAKEDEV)
6767 uint32 dev_major
= IVAL(pdata
,60);
6768 uint32 dev_minor
= IVAL(pdata
,68);
6770 SMB_DEV_T dev
= (SMB_DEV_T
)0;
6771 uint32 raw_unixmode
= IVAL(pdata
,84);
6775 if (total_data
< 100) {
6776 return NT_STATUS_INVALID_PARAMETER
;
6779 status
= unix_perms_from_wire(conn
, &smb_fname
->st
, raw_unixmode
,
6780 PERM_NEW_FILE
, &unixmode
);
6781 if (!NT_STATUS_IS_OK(status
)) {
6785 #if defined(HAVE_MAKEDEV)
6786 dev
= makedev(dev_major
, dev_minor
);
6789 switch (file_type
) {
6790 #if defined(S_IFIFO)
6791 case UNIX_TYPE_FIFO
:
6792 unixmode
|= S_IFIFO
;
6795 #if defined(S_IFSOCK)
6796 case UNIX_TYPE_SOCKET
:
6797 unixmode
|= S_IFSOCK
;
6800 #if defined(S_IFCHR)
6801 case UNIX_TYPE_CHARDEV
:
6802 unixmode
|= S_IFCHR
;
6805 #if defined(S_IFBLK)
6806 case UNIX_TYPE_BLKDEV
:
6807 unixmode
|= S_IFBLK
;
6811 return NT_STATUS_INVALID_PARAMETER
;
6814 DEBUG(10,("smb_unix_mknod: SMB_SET_FILE_UNIX_BASIC doing mknod dev "
6815 "%.0f mode 0%o for file %s\n", (double)dev
,
6816 (unsigned int)unixmode
, smb_fname_str_dbg(smb_fname
)));
6818 /* Ok - do the mknod. */
6819 if (SMB_VFS_MKNOD(conn
, smb_fname
->base_name
, unixmode
, dev
) != 0) {
6820 return map_nt_error_from_unix(errno
);
6823 /* If any of the other "set" calls fail we
6824 * don't want to end up with a half-constructed mknod.
6827 if (lp_inherit_perms(SNUM(conn
))) {
6829 if (!parent_dirname(talloc_tos(), smb_fname
->base_name
,
6831 return NT_STATUS_NO_MEMORY
;
6833 inherit_access_posix_acl(conn
, parent
, smb_fname
->base_name
,
6835 TALLOC_FREE(parent
);
6838 return NT_STATUS_OK
;
6841 /****************************************************************************
6842 Deal with SMB_SET_FILE_UNIX_BASIC.
6843 ****************************************************************************/
6845 static NTSTATUS
smb_set_file_unix_basic(connection_struct
*conn
,
6846 struct smb_request
*req
,
6850 const struct smb_filename
*smb_fname
)
6852 struct smb_file_time ft
;
6853 uint32 raw_unixmode
;
6856 uid_t set_owner
= (uid_t
)SMB_UID_NO_CHANGE
;
6857 gid_t set_grp
= (uid_t
)SMB_GID_NO_CHANGE
;
6858 NTSTATUS status
= NT_STATUS_OK
;
6859 bool delete_on_fail
= False
;
6860 enum perm_type ptype
;
6861 files_struct
*all_fsps
= NULL
;
6862 bool modify_mtime
= true;
6864 struct smb_filename
*smb_fname_tmp
= NULL
;
6865 SMB_STRUCT_STAT sbuf
;
6869 if (total_data
< 100) {
6870 return NT_STATUS_INVALID_PARAMETER
;
6873 if(IVAL(pdata
, 0) != SMB_SIZE_NO_CHANGE_LO
&&
6874 IVAL(pdata
, 4) != SMB_SIZE_NO_CHANGE_HI
) {
6875 size
=IVAL(pdata
,0); /* first 8 Bytes are size */
6876 #ifdef LARGE_SMB_OFF_T
6877 size
|= (((SMB_OFF_T
)IVAL(pdata
,4)) << 32);
6878 #else /* LARGE_SMB_OFF_T */
6879 if (IVAL(pdata
,4) != 0) {
6880 /* more than 32 bits? */
6881 return NT_STATUS_INVALID_PARAMETER
;
6883 #endif /* LARGE_SMB_OFF_T */
6886 ft
.atime
= interpret_long_date(pdata
+24); /* access_time */
6887 ft
.mtime
= interpret_long_date(pdata
+32); /* modification_time */
6888 set_owner
= (uid_t
)IVAL(pdata
,40);
6889 set_grp
= (gid_t
)IVAL(pdata
,48);
6890 raw_unixmode
= IVAL(pdata
,84);
6892 if (VALID_STAT(smb_fname
->st
)) {
6893 if (S_ISDIR(smb_fname
->st
.st_ex_mode
)) {
6894 ptype
= PERM_EXISTING_DIR
;
6896 ptype
= PERM_EXISTING_FILE
;
6899 ptype
= PERM_NEW_FILE
;
6902 status
= unix_perms_from_wire(conn
, &smb_fname
->st
, raw_unixmode
,
6904 if (!NT_STATUS_IS_OK(status
)) {
6908 DEBUG(10,("smb_set_file_unix_basic: SMB_SET_FILE_UNIX_BASIC: name = "
6909 "%s size = %.0f, uid = %u, gid = %u, raw perms = 0%o\n",
6910 smb_fname_str_dbg(smb_fname
), (double)size
,
6911 (unsigned int)set_owner
, (unsigned int)set_grp
,
6912 (int)raw_unixmode
));
6914 sbuf
= smb_fname
->st
;
6916 if (!VALID_STAT(sbuf
)) {
6918 * The only valid use of this is to create character and block
6919 * devices, and named pipes. This is deprecated (IMHO) and
6920 * a new info level should be used for mknod. JRA.
6923 status
= smb_unix_mknod(conn
,
6927 if (!NT_STATUS_IS_OK(status
)) {
6931 status
= copy_smb_filename(talloc_tos(), smb_fname
,
6933 if (!NT_STATUS_IS_OK(status
)) {
6937 if (SMB_VFS_STAT(conn
, smb_fname_tmp
) != 0) {
6938 status
= map_nt_error_from_unix(errno
);
6939 TALLOC_FREE(smb_fname_tmp
);
6940 SMB_VFS_UNLINK(conn
, smb_fname
);
6944 sbuf
= smb_fname_tmp
->st
;
6945 smb_fname
= smb_fname_tmp
;
6947 /* Ensure we don't try and change anything else. */
6948 raw_unixmode
= SMB_MODE_NO_CHANGE
;
6949 size
= get_file_size_stat(&sbuf
);
6950 ft
.atime
= sbuf
.st_ex_atime
;
6951 ft
.mtime
= sbuf
.st_ex_mtime
;
6953 * We continue here as we might want to change the
6956 delete_on_fail
= True
;
6960 /* Horrible backwards compatibility hack as an old server bug
6961 * allowed a CIFS client bug to remain unnoticed :-(. JRA.
6965 size
= get_file_size_stat(&sbuf
);
6970 * Deal with the UNIX specific mode set.
6973 if (raw_unixmode
!= SMB_MODE_NO_CHANGE
) {
6974 DEBUG(10,("smb_set_file_unix_basic: SMB_SET_FILE_UNIX_BASIC "
6975 "setting mode 0%o for file %s\n",
6976 (unsigned int)unixmode
,
6977 smb_fname_str_dbg(smb_fname
)));
6978 if (SMB_VFS_CHMOD(conn
, smb_fname
->base_name
, unixmode
) != 0) {
6979 return map_nt_error_from_unix(errno
);
6984 * Deal with the UNIX specific uid set.
6987 if ((set_owner
!= (uid_t
)SMB_UID_NO_CHANGE
) &&
6988 (sbuf
.st_ex_uid
!= set_owner
)) {
6991 DEBUG(10,("smb_set_file_unix_basic: SMB_SET_FILE_UNIX_BASIC "
6992 "changing owner %u for path %s\n",
6993 (unsigned int)set_owner
,
6994 smb_fname_str_dbg(smb_fname
)));
6996 if (S_ISLNK(sbuf
.st_ex_mode
)) {
6997 ret
= SMB_VFS_LCHOWN(conn
, smb_fname
->base_name
,
6998 set_owner
, (gid_t
)-1);
7000 ret
= SMB_VFS_CHOWN(conn
, smb_fname
->base_name
,
7001 set_owner
, (gid_t
)-1);
7005 status
= map_nt_error_from_unix(errno
);
7006 if (delete_on_fail
) {
7007 SMB_VFS_UNLINK(conn
, smb_fname
);
7014 * Deal with the UNIX specific gid set.
7017 if ((set_grp
!= (uid_t
)SMB_GID_NO_CHANGE
) &&
7018 (sbuf
.st_ex_gid
!= set_grp
)) {
7019 DEBUG(10,("smb_set_file_unix_basic: SMB_SET_FILE_UNIX_BASIC "
7020 "changing group %u for file %s\n",
7021 (unsigned int)set_owner
,
7022 smb_fname_str_dbg(smb_fname
)));
7023 if (SMB_VFS_CHOWN(conn
, smb_fname
->base_name
, (uid_t
)-1,
7025 status
= map_nt_error_from_unix(errno
);
7026 if (delete_on_fail
) {
7027 SMB_VFS_UNLINK(conn
, smb_fname
);
7033 /* Deal with any size changes. */
7035 status
= smb_set_file_size(conn
, req
,
7041 if (!NT_STATUS_IS_OK(status
)) {
7045 /* Deal with any time changes. */
7046 if (null_timespec(ft
.mtime
) && null_timespec(ft
.atime
)) {
7047 /* No change, don't cancel anything. */
7051 id
= vfs_file_id_from_sbuf(conn
, &sbuf
);
7052 for(all_fsps
= file_find_di_first(conn
->sconn
, id
); all_fsps
;
7053 all_fsps
= file_find_di_next(all_fsps
)) {
7055 * We're setting the time explicitly for UNIX.
7056 * Cancel any pending changes over all handles.
7058 all_fsps
->update_write_time_on_close
= false;
7059 TALLOC_FREE(all_fsps
->update_write_time_event
);
7063 * Override the "setting_write_time"
7064 * parameter here as it almost does what
7065 * we need. Just remember if we modified
7066 * mtime and send the notify ourselves.
7068 if (null_timespec(ft
.mtime
)) {
7069 modify_mtime
= false;
7072 status
= smb_set_file_time(conn
,
7078 notify_fname(conn
, NOTIFY_ACTION_MODIFIED
,
7079 FILE_NOTIFY_CHANGE_LAST_WRITE
, smb_fname
->base_name
);
7084 /****************************************************************************
7085 Deal with SMB_SET_FILE_UNIX_INFO2.
7086 ****************************************************************************/
7088 static NTSTATUS
smb_set_file_unix_info2(connection_struct
*conn
,
7089 struct smb_request
*req
,
7093 const struct smb_filename
*smb_fname
)
7099 if (total_data
< 116) {
7100 return NT_STATUS_INVALID_PARAMETER
;
7103 /* Start by setting all the fields that are common between UNIX_BASIC
7106 status
= smb_set_file_unix_basic(conn
, req
, pdata
, total_data
,
7108 if (!NT_STATUS_IS_OK(status
)) {
7112 smb_fflags
= IVAL(pdata
, 108);
7113 smb_fmask
= IVAL(pdata
, 112);
7115 /* NB: We should only attempt to alter the file flags if the client
7116 * sends a non-zero mask.
7118 if (smb_fmask
!= 0) {
7119 int stat_fflags
= 0;
7121 if (!map_info2_flags_to_sbuf(&smb_fname
->st
, smb_fflags
,
7122 smb_fmask
, &stat_fflags
)) {
7123 /* Client asked to alter a flag we don't understand. */
7124 return NT_STATUS_INVALID_PARAMETER
;
7127 if (fsp
&& fsp
->fh
->fd
!= -1) {
7128 /* XXX: we should be using SMB_VFS_FCHFLAGS here. */
7129 return NT_STATUS_NOT_SUPPORTED
;
7131 if (SMB_VFS_CHFLAGS(conn
, smb_fname
->base_name
,
7132 stat_fflags
) != 0) {
7133 return map_nt_error_from_unix(errno
);
7138 /* XXX: need to add support for changing the create_time here. You
7139 * can do this for paths on Darwin with setattrlist(2). The right way
7140 * to hook this up is probably by extending the VFS utimes interface.
7143 return NT_STATUS_OK
;
7146 /****************************************************************************
7147 Create a directory with POSIX semantics.
7148 ****************************************************************************/
7150 static NTSTATUS
smb_posix_mkdir(connection_struct
*conn
,
7151 struct smb_request
*req
,
7154 struct smb_filename
*smb_fname
,
7155 int *pdata_return_size
)
7157 NTSTATUS status
= NT_STATUS_OK
;
7158 uint32 raw_unixmode
= 0;
7159 uint32 mod_unixmode
= 0;
7160 mode_t unixmode
= (mode_t
)0;
7161 files_struct
*fsp
= NULL
;
7162 uint16 info_level_return
= 0;
7164 char *pdata
= *ppdata
;
7166 if (total_data
< 18) {
7167 return NT_STATUS_INVALID_PARAMETER
;
7170 raw_unixmode
= IVAL(pdata
,8);
7171 /* Next 4 bytes are not yet defined. */
7173 status
= unix_perms_from_wire(conn
, &smb_fname
->st
, raw_unixmode
,
7174 PERM_NEW_DIR
, &unixmode
);
7175 if (!NT_STATUS_IS_OK(status
)) {
7179 mod_unixmode
= (uint32
)unixmode
| FILE_FLAG_POSIX_SEMANTICS
;
7181 DEBUG(10,("smb_posix_mkdir: file %s, mode 0%o\n",
7182 smb_fname_str_dbg(smb_fname
), (unsigned int)unixmode
));
7184 status
= SMB_VFS_CREATE_FILE(
7187 0, /* root_dir_fid */
7188 smb_fname
, /* fname */
7189 FILE_READ_ATTRIBUTES
, /* access_mask */
7190 FILE_SHARE_NONE
, /* share_access */
7191 FILE_CREATE
, /* create_disposition*/
7192 FILE_DIRECTORY_FILE
, /* create_options */
7193 mod_unixmode
, /* file_attributes */
7194 0, /* oplock_request */
7195 0, /* allocation_size */
7196 0, /* private_flags */
7202 if (NT_STATUS_IS_OK(status
)) {
7203 close_file(req
, fsp
, NORMAL_CLOSE
);
7206 info_level_return
= SVAL(pdata
,16);
7208 if (info_level_return
== SMB_QUERY_FILE_UNIX_BASIC
) {
7209 *pdata_return_size
= 12 + SMB_FILE_UNIX_BASIC_SIZE
;
7210 } else if (info_level_return
== SMB_QUERY_FILE_UNIX_INFO2
) {
7211 *pdata_return_size
= 12 + SMB_FILE_UNIX_INFO2_SIZE
;
7213 *pdata_return_size
= 12;
7216 /* Realloc the data size */
7217 *ppdata
= (char *)SMB_REALLOC(*ppdata
,*pdata_return_size
);
7218 if (*ppdata
== NULL
) {
7219 *pdata_return_size
= 0;
7220 return NT_STATUS_NO_MEMORY
;
7224 SSVAL(pdata
,0,NO_OPLOCK_RETURN
);
7225 SSVAL(pdata
,2,0); /* No fnum. */
7226 SIVAL(pdata
,4,info
); /* Was directory created. */
7228 switch (info_level_return
) {
7229 case SMB_QUERY_FILE_UNIX_BASIC
:
7230 SSVAL(pdata
,8,SMB_QUERY_FILE_UNIX_BASIC
);
7231 SSVAL(pdata
,10,0); /* Padding. */
7232 store_file_unix_basic(conn
, pdata
+ 12, fsp
,
7235 case SMB_QUERY_FILE_UNIX_INFO2
:
7236 SSVAL(pdata
,8,SMB_QUERY_FILE_UNIX_INFO2
);
7237 SSVAL(pdata
,10,0); /* Padding. */
7238 store_file_unix_basic_info2(conn
, pdata
+ 12, fsp
,
7242 SSVAL(pdata
,8,SMB_NO_INFO_LEVEL_RETURNED
);
7243 SSVAL(pdata
,10,0); /* Padding. */
7250 /****************************************************************************
7251 Open/Create a file with POSIX semantics.
7252 ****************************************************************************/
7254 static NTSTATUS
smb_posix_open(connection_struct
*conn
,
7255 struct smb_request
*req
,
7258 struct smb_filename
*smb_fname
,
7259 int *pdata_return_size
)
7261 bool extended_oplock_granted
= False
;
7262 char *pdata
= *ppdata
;
7264 uint32 wire_open_mode
= 0;
7265 uint32 raw_unixmode
= 0;
7266 uint32 mod_unixmode
= 0;
7267 uint32 create_disp
= 0;
7268 uint32 access_mask
= 0;
7269 uint32 create_options
= 0;
7270 NTSTATUS status
= NT_STATUS_OK
;
7271 mode_t unixmode
= (mode_t
)0;
7272 files_struct
*fsp
= NULL
;
7273 int oplock_request
= 0;
7275 uint16 info_level_return
= 0;
7277 if (total_data
< 18) {
7278 return NT_STATUS_INVALID_PARAMETER
;
7281 flags
= IVAL(pdata
,0);
7282 oplock_request
= (flags
& REQUEST_OPLOCK
) ? EXCLUSIVE_OPLOCK
: 0;
7283 if (oplock_request
) {
7284 oplock_request
|= (flags
& REQUEST_BATCH_OPLOCK
) ? BATCH_OPLOCK
: 0;
7287 wire_open_mode
= IVAL(pdata
,4);
7289 if (wire_open_mode
== (SMB_O_CREAT
|SMB_O_DIRECTORY
)) {
7290 return smb_posix_mkdir(conn
, req
,
7297 switch (wire_open_mode
& SMB_ACCMODE
) {
7299 access_mask
= FILE_READ_DATA
;
7302 access_mask
= FILE_WRITE_DATA
;
7305 access_mask
= FILE_READ_DATA
|FILE_WRITE_DATA
;
7308 DEBUG(5,("smb_posix_open: invalid open mode 0x%x\n",
7309 (unsigned int)wire_open_mode
));
7310 return NT_STATUS_INVALID_PARAMETER
;
7313 wire_open_mode
&= ~SMB_ACCMODE
;
7315 if((wire_open_mode
& (SMB_O_CREAT
| SMB_O_EXCL
)) == (SMB_O_CREAT
| SMB_O_EXCL
)) {
7316 create_disp
= FILE_CREATE
;
7317 } else if((wire_open_mode
& (SMB_O_CREAT
| SMB_O_TRUNC
)) == (SMB_O_CREAT
| SMB_O_TRUNC
)) {
7318 create_disp
= FILE_OVERWRITE_IF
;
7319 } else if((wire_open_mode
& SMB_O_CREAT
) == SMB_O_CREAT
) {
7320 create_disp
= FILE_OPEN_IF
;
7321 } else if ((wire_open_mode
& (SMB_O_CREAT
| SMB_O_EXCL
| SMB_O_TRUNC
)) == 0) {
7322 create_disp
= FILE_OPEN
;
7324 DEBUG(5,("smb_posix_open: invalid create mode 0x%x\n",
7325 (unsigned int)wire_open_mode
));
7326 return NT_STATUS_INVALID_PARAMETER
;
7329 raw_unixmode
= IVAL(pdata
,8);
7330 /* Next 4 bytes are not yet defined. */
7332 status
= unix_perms_from_wire(conn
, &smb_fname
->st
, raw_unixmode
,
7333 (VALID_STAT(smb_fname
->st
) ?
7334 PERM_EXISTING_FILE
: PERM_NEW_FILE
),
7337 if (!NT_STATUS_IS_OK(status
)) {
7341 mod_unixmode
= (uint32
)unixmode
| FILE_FLAG_POSIX_SEMANTICS
;
7343 if (wire_open_mode
& SMB_O_SYNC
) {
7344 create_options
|= FILE_WRITE_THROUGH
;
7346 if (wire_open_mode
& SMB_O_APPEND
) {
7347 access_mask
|= FILE_APPEND_DATA
;
7349 if (wire_open_mode
& SMB_O_DIRECT
) {
7350 mod_unixmode
|= FILE_FLAG_NO_BUFFERING
;
7353 DEBUG(10,("smb_posix_open: file %s, smb_posix_flags = %u, mode 0%o\n",
7354 smb_fname_str_dbg(smb_fname
),
7355 (unsigned int)wire_open_mode
,
7356 (unsigned int)unixmode
));
7358 status
= SMB_VFS_CREATE_FILE(
7361 0, /* root_dir_fid */
7362 smb_fname
, /* fname */
7363 access_mask
, /* access_mask */
7364 (FILE_SHARE_READ
| FILE_SHARE_WRITE
| /* share_access */
7366 create_disp
, /* create_disposition*/
7367 FILE_NON_DIRECTORY_FILE
, /* create_options */
7368 mod_unixmode
, /* file_attributes */
7369 oplock_request
, /* oplock_request */
7370 0, /* allocation_size */
7371 0, /* private_flags */
7377 if (!NT_STATUS_IS_OK(status
)) {
7381 if (oplock_request
&& lp_fake_oplocks(SNUM(conn
))) {
7382 extended_oplock_granted
= True
;
7385 if(oplock_request
&& EXCLUSIVE_OPLOCK_TYPE(fsp
->oplock_type
)) {
7386 extended_oplock_granted
= True
;
7389 info_level_return
= SVAL(pdata
,16);
7391 /* Allocate the correct return size. */
7393 if (info_level_return
== SMB_QUERY_FILE_UNIX_BASIC
) {
7394 *pdata_return_size
= 12 + SMB_FILE_UNIX_BASIC_SIZE
;
7395 } else if (info_level_return
== SMB_QUERY_FILE_UNIX_INFO2
) {
7396 *pdata_return_size
= 12 + SMB_FILE_UNIX_INFO2_SIZE
;
7398 *pdata_return_size
= 12;
7401 /* Realloc the data size */
7402 *ppdata
= (char *)SMB_REALLOC(*ppdata
,*pdata_return_size
);
7403 if (*ppdata
== NULL
) {
7404 close_file(req
, fsp
, ERROR_CLOSE
);
7405 *pdata_return_size
= 0;
7406 return NT_STATUS_NO_MEMORY
;
7410 if (extended_oplock_granted
) {
7411 if (flags
& REQUEST_BATCH_OPLOCK
) {
7412 SSVAL(pdata
,0, BATCH_OPLOCK_RETURN
);
7414 SSVAL(pdata
,0, EXCLUSIVE_OPLOCK_RETURN
);
7416 } else if (fsp
->oplock_type
== LEVEL_II_OPLOCK
) {
7417 SSVAL(pdata
,0, LEVEL_II_OPLOCK_RETURN
);
7419 SSVAL(pdata
,0,NO_OPLOCK_RETURN
);
7422 SSVAL(pdata
,2,fsp
->fnum
);
7423 SIVAL(pdata
,4,info
); /* Was file created etc. */
7425 switch (info_level_return
) {
7426 case SMB_QUERY_FILE_UNIX_BASIC
:
7427 SSVAL(pdata
,8,SMB_QUERY_FILE_UNIX_BASIC
);
7428 SSVAL(pdata
,10,0); /* padding. */
7429 store_file_unix_basic(conn
, pdata
+ 12, fsp
,
7432 case SMB_QUERY_FILE_UNIX_INFO2
:
7433 SSVAL(pdata
,8,SMB_QUERY_FILE_UNIX_INFO2
);
7434 SSVAL(pdata
,10,0); /* padding. */
7435 store_file_unix_basic_info2(conn
, pdata
+ 12, fsp
,
7439 SSVAL(pdata
,8,SMB_NO_INFO_LEVEL_RETURNED
);
7440 SSVAL(pdata
,10,0); /* padding. */
7443 return NT_STATUS_OK
;
7446 /****************************************************************************
7447 Delete a file with POSIX semantics.
7448 ****************************************************************************/
7450 static NTSTATUS
smb_posix_unlink(connection_struct
*conn
,
7451 struct smb_request
*req
,
7454 struct smb_filename
*smb_fname
)
7456 NTSTATUS status
= NT_STATUS_OK
;
7457 files_struct
*fsp
= NULL
;
7461 int create_options
= 0;
7463 struct share_mode_lock
*lck
= NULL
;
7465 if (total_data
< 2) {
7466 return NT_STATUS_INVALID_PARAMETER
;
7469 flags
= SVAL(pdata
,0);
7471 if (!VALID_STAT(smb_fname
->st
)) {
7472 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
7475 if ((flags
== SMB_POSIX_UNLINK_DIRECTORY_TARGET
) &&
7476 !VALID_STAT_OF_DIR(smb_fname
->st
)) {
7477 return NT_STATUS_NOT_A_DIRECTORY
;
7480 DEBUG(10,("smb_posix_unlink: %s %s\n",
7481 (flags
== SMB_POSIX_UNLINK_DIRECTORY_TARGET
) ? "directory" : "file",
7482 smb_fname_str_dbg(smb_fname
)));
7484 if (VALID_STAT_OF_DIR(smb_fname
->st
)) {
7485 create_options
|= FILE_DIRECTORY_FILE
;
7488 status
= SMB_VFS_CREATE_FILE(
7491 0, /* root_dir_fid */
7492 smb_fname
, /* fname */
7493 DELETE_ACCESS
, /* access_mask */
7494 (FILE_SHARE_READ
| FILE_SHARE_WRITE
| /* share_access */
7496 FILE_OPEN
, /* create_disposition*/
7497 create_options
, /* create_options */
7498 FILE_FLAG_POSIX_SEMANTICS
|0777, /* file_attributes */
7499 0, /* oplock_request */
7500 0, /* allocation_size */
7501 0, /* private_flags */
7507 if (!NT_STATUS_IS_OK(status
)) {
7512 * Don't lie to client. If we can't really delete due to
7513 * non-POSIX opens return SHARING_VIOLATION.
7516 lck
= get_share_mode_lock(talloc_tos(), fsp
->file_id
, NULL
, NULL
,
7519 DEBUG(0, ("smb_posix_unlink: Could not get share mode "
7520 "lock for file %s\n", fsp_str_dbg(fsp
)));
7521 close_file(req
, fsp
, NORMAL_CLOSE
);
7522 return NT_STATUS_INVALID_PARAMETER
;
7526 * See if others still have the file open. If this is the case, then
7527 * don't delete. If all opens are POSIX delete we can set the delete
7528 * on close disposition.
7530 for (i
=0; i
<lck
->num_share_modes
; i
++) {
7531 struct share_mode_entry
*e
= &lck
->share_modes
[i
];
7532 if (is_valid_share_mode_entry(e
)) {
7533 if (e
->flags
& SHARE_MODE_FLAG_POSIX_OPEN
) {
7536 /* Fail with sharing violation. */
7537 close_file(req
, fsp
, NORMAL_CLOSE
);
7539 return NT_STATUS_SHARING_VIOLATION
;
7544 * Set the delete on close.
7546 status
= smb_set_file_disposition_info(conn
,
7552 if (!NT_STATUS_IS_OK(status
)) {
7553 close_file(req
, fsp
, NORMAL_CLOSE
);
7558 return close_file(req
, fsp
, NORMAL_CLOSE
);
7561 NTSTATUS
smbd_do_setfilepathinfo(connection_struct
*conn
,
7562 struct smb_request
*req
,
7563 TALLOC_CTX
*mem_ctx
,
7564 uint16_t info_level
,
7566 struct smb_filename
*smb_fname
,
7567 char **ppdata
, int total_data
,
7570 char *pdata
= *ppdata
;
7571 NTSTATUS status
= NT_STATUS_OK
;
7572 int data_return_size
= 0;
7576 if (INFO_LEVEL_IS_UNIX(info_level
) && !lp_unix_extensions()) {
7577 return NT_STATUS_INVALID_LEVEL
;
7580 if (!CAN_WRITE(conn
)) {
7581 /* Allow POSIX opens. The open path will deny
7582 * any non-readonly opens. */
7583 if (info_level
!= SMB_POSIX_PATH_OPEN
) {
7584 return NT_STATUS_DOS(ERRSRV
, ERRaccess
);
7588 DEBUG(3,("smbd_do_setfilepathinfo: %s (fnum %d) info_level=%d "
7589 "totdata=%d\n", smb_fname_str_dbg(smb_fname
),
7590 fsp
? fsp
->fnum
: -1, info_level
, total_data
));
7592 switch (info_level
) {
7594 case SMB_INFO_STANDARD
:
7596 status
= smb_set_info_standard(conn
,
7604 case SMB_INFO_SET_EA
:
7606 status
= smb_info_set_ea(conn
,
7614 case SMB_SET_FILE_BASIC_INFO
:
7615 case SMB_FILE_BASIC_INFORMATION
:
7617 status
= smb_set_file_basic_info(conn
,
7625 case SMB_FILE_ALLOCATION_INFORMATION
:
7626 case SMB_SET_FILE_ALLOCATION_INFO
:
7628 status
= smb_set_file_allocation_info(conn
, req
,
7636 case SMB_FILE_END_OF_FILE_INFORMATION
:
7637 case SMB_SET_FILE_END_OF_FILE_INFO
:
7640 * XP/Win7 both fail after the createfile with
7641 * SMB_SET_FILE_END_OF_FILE_INFO but not
7642 * SMB_FILE_END_OF_FILE_INFORMATION (pass-through).
7643 * The level is known here, so pass it down
7647 (info_level
== SMB_SET_FILE_END_OF_FILE_INFO
);
7649 status
= smb_set_file_end_of_file_info(conn
, req
,
7658 case SMB_FILE_DISPOSITION_INFORMATION
:
7659 case SMB_SET_FILE_DISPOSITION_INFO
: /* Set delete on close for open file. */
7662 /* JRA - We used to just ignore this on a path ?
7663 * Shouldn't this be invalid level on a pathname
7666 if (tran_call
!= TRANSACT2_SETFILEINFO
) {
7667 return ERROR_NT(NT_STATUS_INVALID_LEVEL
);
7670 status
= smb_set_file_disposition_info(conn
,
7678 case SMB_FILE_POSITION_INFORMATION
:
7680 status
= smb_file_position_information(conn
,
7687 case SMB_FILE_FULL_EA_INFORMATION
:
7689 status
= smb_set_file_full_ea_info(conn
,
7696 /* From tridge Samba4 :
7697 * MODE_INFORMATION in setfileinfo (I have no
7698 * idea what "mode information" on a file is - it takes a value of 0,
7699 * 2, 4 or 6. What could it be?).
7702 case SMB_FILE_MODE_INFORMATION
:
7704 status
= smb_file_mode_information(conn
,
7711 * CIFS UNIX extensions.
7714 case SMB_SET_FILE_UNIX_BASIC
:
7716 status
= smb_set_file_unix_basic(conn
, req
,
7724 case SMB_SET_FILE_UNIX_INFO2
:
7726 status
= smb_set_file_unix_info2(conn
, req
,
7734 case SMB_SET_FILE_UNIX_LINK
:
7737 /* We must have a pathname for this. */
7738 return NT_STATUS_INVALID_LEVEL
;
7740 status
= smb_set_file_unix_link(conn
, req
, pdata
,
7741 total_data
, smb_fname
);
7745 case SMB_SET_FILE_UNIX_HLINK
:
7748 /* We must have a pathname for this. */
7749 return NT_STATUS_INVALID_LEVEL
;
7751 status
= smb_set_file_unix_hlink(conn
, req
,
7757 case SMB_FILE_RENAME_INFORMATION
:
7759 status
= smb_file_rename_information(conn
, req
,
7765 case SMB2_FILE_RENAME_INFORMATION_INTERNAL
:
7767 /* SMB2 rename information. */
7768 status
= smb2_file_rename_information(conn
, req
,
7774 case SMB_FILE_LINK_INFORMATION
:
7776 status
= smb_file_link_information(conn
, req
,
7782 #if defined(HAVE_POSIX_ACLS)
7783 case SMB_SET_POSIX_ACL
:
7785 status
= smb_set_posix_acl(conn
,
7794 case SMB_SET_POSIX_LOCK
:
7797 return NT_STATUS_INVALID_LEVEL
;
7799 status
= smb_set_posix_lock(conn
, req
,
7800 pdata
, total_data
, fsp
);
7804 case SMB_POSIX_PATH_OPEN
:
7807 /* We must have a pathname for this. */
7808 return NT_STATUS_INVALID_LEVEL
;
7811 status
= smb_posix_open(conn
, req
,
7819 case SMB_POSIX_PATH_UNLINK
:
7822 /* We must have a pathname for this. */
7823 return NT_STATUS_INVALID_LEVEL
;
7826 status
= smb_posix_unlink(conn
, req
,
7834 return NT_STATUS_INVALID_LEVEL
;
7837 if (!NT_STATUS_IS_OK(status
)) {
7841 *ret_data_size
= data_return_size
;
7842 return NT_STATUS_OK
;
7845 /****************************************************************************
7846 Reply to a TRANS2_SETFILEINFO (set file info by fileid or pathname).
7847 ****************************************************************************/
7849 static void call_trans2setfilepathinfo(connection_struct
*conn
,
7850 struct smb_request
*req
,
7851 unsigned int tran_call
,
7852 char **pparams
, int total_params
,
7853 char **ppdata
, int total_data
,
7854 unsigned int max_data_bytes
)
7856 char *params
= *pparams
;
7857 char *pdata
= *ppdata
;
7859 struct smb_filename
*smb_fname
= NULL
;
7860 files_struct
*fsp
= NULL
;
7861 NTSTATUS status
= NT_STATUS_OK
;
7862 int data_return_size
= 0;
7865 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
7869 if (tran_call
== TRANSACT2_SETFILEINFO
) {
7870 if (total_params
< 4) {
7871 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
7875 fsp
= file_fsp(req
, SVAL(params
,0));
7876 /* Basic check for non-null fsp. */
7877 if (!check_fsp_open(conn
, req
, fsp
)) {
7880 info_level
= SVAL(params
,2);
7882 status
= copy_smb_filename(talloc_tos(), fsp
->fsp_name
,
7884 if (!NT_STATUS_IS_OK(status
)) {
7885 reply_nterror(req
, status
);
7889 if(fsp
->fh
->fd
== -1) {
7891 * This is actually a SETFILEINFO on a directory
7892 * handle (returned from an NT SMB). NT5.0 seems
7893 * to do this call. JRA.
7895 if (INFO_LEVEL_IS_UNIX(info_level
)) {
7896 /* Always do lstat for UNIX calls. */
7897 if (SMB_VFS_LSTAT(conn
, smb_fname
)) {
7898 DEBUG(3,("call_trans2setfilepathinfo: "
7899 "SMB_VFS_LSTAT of %s failed "
7901 smb_fname_str_dbg(smb_fname
),
7903 reply_nterror(req
, map_nt_error_from_unix(errno
));
7907 if (SMB_VFS_STAT(conn
, smb_fname
) != 0) {
7908 DEBUG(3,("call_trans2setfilepathinfo: "
7909 "fileinfo of %s failed (%s)\n",
7910 smb_fname_str_dbg(smb_fname
),
7912 reply_nterror(req
, map_nt_error_from_unix(errno
));
7916 } else if (fsp
->print_file
) {
7918 * Doing a DELETE_ON_CLOSE should cancel a print job.
7920 if ((info_level
== SMB_SET_FILE_DISPOSITION_INFO
) && CVAL(pdata
,0)) {
7921 fsp
->fh
->private_options
|= NTCREATEX_OPTIONS_PRIVATE_DELETE_ON_CLOSE
;
7923 DEBUG(3,("call_trans2setfilepathinfo: "
7924 "Cancelling print job (%s)\n",
7928 send_trans2_replies(conn
, req
, params
, 2,
7934 NT_STATUS_OBJECT_PATH_NOT_FOUND
);
7939 * Original code - this is an open file.
7941 if (SMB_VFS_FSTAT(fsp
, &smb_fname
->st
) != 0) {
7942 DEBUG(3,("call_trans2setfilepathinfo: fstat "
7943 "of fnum %d failed (%s)\n", fsp
->fnum
,
7945 reply_nterror(req
, map_nt_error_from_unix(errno
));
7953 if (total_params
< 7) {
7954 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
7958 info_level
= SVAL(params
,0);
7959 srvstr_get_path(req
, params
, req
->flags2
, &fname
, ¶ms
[6],
7960 total_params
- 6, STR_TERMINATE
,
7962 if (!NT_STATUS_IS_OK(status
)) {
7963 reply_nterror(req
, status
);
7967 status
= filename_convert(req
, conn
,
7968 req
->flags2
& FLAGS2_DFS_PATHNAMES
,
7973 if (!NT_STATUS_IS_OK(status
)) {
7974 if (NT_STATUS_EQUAL(status
,NT_STATUS_PATH_NOT_COVERED
)) {
7975 reply_botherror(req
,
7976 NT_STATUS_PATH_NOT_COVERED
,
7977 ERRSRV
, ERRbadpath
);
7980 reply_nterror(req
, status
);
7984 if (INFO_LEVEL_IS_UNIX(info_level
)) {
7986 * For CIFS UNIX extensions the target name may not exist.
7989 /* Always do lstat for UNIX calls. */
7990 SMB_VFS_LSTAT(conn
, smb_fname
);
7992 } else if (!VALID_STAT(smb_fname
->st
) &&
7993 SMB_VFS_STAT(conn
, smb_fname
)) {
7994 DEBUG(3,("call_trans2setfilepathinfo: SMB_VFS_STAT of "
7996 smb_fname_str_dbg(smb_fname
),
7998 reply_nterror(req
, map_nt_error_from_unix(errno
));
8003 DEBUG(3,("call_trans2setfilepathinfo(%d) %s (fnum %d) info_level=%d "
8004 "totdata=%d\n", tran_call
, smb_fname_str_dbg(smb_fname
),
8005 fsp
? fsp
->fnum
: -1, info_level
,total_data
));
8007 /* Realloc the parameter size */
8008 *pparams
= (char *)SMB_REALLOC(*pparams
,2);
8009 if (*pparams
== NULL
) {
8010 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
8017 status
= smbd_do_setfilepathinfo(conn
, req
, req
,
8023 if (!NT_STATUS_IS_OK(status
)) {
8024 if (open_was_deferred(req
->mid
)) {
8025 /* We have re-scheduled this call. */
8028 if (blocking_lock_was_deferred_smb1(req
->sconn
, req
->mid
)) {
8029 /* We have re-scheduled this call. */
8032 if (NT_STATUS_EQUAL(status
,NT_STATUS_PATH_NOT_COVERED
)) {
8033 reply_botherror(req
, NT_STATUS_PATH_NOT_COVERED
,
8034 ERRSRV
, ERRbadpath
);
8037 if (info_level
== SMB_POSIX_PATH_OPEN
) {
8038 reply_openerror(req
, status
);
8042 reply_nterror(req
, status
);
8046 send_trans2_replies(conn
, req
, params
, 2, *ppdata
, data_return_size
,
8052 /****************************************************************************
8053 Reply to a TRANS2_MKDIR (make directory with extended attributes).
8054 ****************************************************************************/
8056 static void call_trans2mkdir(connection_struct
*conn
, struct smb_request
*req
,
8057 char **pparams
, int total_params
,
8058 char **ppdata
, int total_data
,
8059 unsigned int max_data_bytes
)
8061 struct smb_filename
*smb_dname
= NULL
;
8062 char *params
= *pparams
;
8063 char *pdata
= *ppdata
;
8064 char *directory
= NULL
;
8065 NTSTATUS status
= NT_STATUS_OK
;
8066 struct ea_list
*ea_list
= NULL
;
8067 TALLOC_CTX
*ctx
= talloc_tos();
8069 if (!CAN_WRITE(conn
)) {
8070 reply_nterror(req
, NT_STATUS_ACCESS_DENIED
);
8074 if (total_params
< 5) {
8075 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
8079 srvstr_get_path(ctx
, params
, req
->flags2
, &directory
, ¶ms
[4],
8080 total_params
- 4, STR_TERMINATE
,
8082 if (!NT_STATUS_IS_OK(status
)) {
8083 reply_nterror(req
, status
);
8087 DEBUG(3,("call_trans2mkdir : name = %s\n", directory
));
8089 status
= filename_convert(ctx
,
8091 req
->flags2
& FLAGS2_DFS_PATHNAMES
,
8097 if (!NT_STATUS_IS_OK(status
)) {
8098 if (NT_STATUS_EQUAL(status
,NT_STATUS_PATH_NOT_COVERED
)) {
8099 reply_botherror(req
,
8100 NT_STATUS_PATH_NOT_COVERED
,
8101 ERRSRV
, ERRbadpath
);
8104 reply_nterror(req
, status
);
8109 * OS/2 workplace shell seems to send SET_EA requests of "null"
8110 * length (4 bytes containing IVAL 4).
8111 * They seem to have no effect. Bug #3212. JRA.
8114 if (total_data
&& (total_data
!= 4)) {
8115 /* Any data in this call is an EA list. */
8116 if (total_data
< 10) {
8117 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
8121 if (IVAL(pdata
,0) > total_data
) {
8122 DEBUG(10,("call_trans2mkdir: bad total data size (%u) > %u\n",
8123 IVAL(pdata
,0), (unsigned int)total_data
));
8124 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
8128 ea_list
= read_ea_list(talloc_tos(), pdata
+ 4,
8131 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
8135 if (!lp_ea_support(SNUM(conn
))) {
8136 reply_nterror(req
, NT_STATUS_EAS_NOT_SUPPORTED
);
8140 /* If total_data == 4 Windows doesn't care what values
8141 * are placed in that field, it just ignores them.
8142 * The System i QNTC IBM SMB client puts bad values here,
8143 * so ignore them. */
8145 status
= create_directory(conn
, req
, smb_dname
);
8147 if (!NT_STATUS_IS_OK(status
)) {
8148 reply_nterror(req
, status
);
8152 /* Try and set any given EA. */
8154 status
= set_ea(conn
, NULL
, smb_dname
, ea_list
);
8155 if (!NT_STATUS_IS_OK(status
)) {
8156 reply_nterror(req
, status
);
8161 /* Realloc the parameter and data sizes */
8162 *pparams
= (char *)SMB_REALLOC(*pparams
,2);
8163 if(*pparams
== NULL
) {
8164 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
8171 send_trans2_replies(conn
, req
, params
, 2, *ppdata
, 0, max_data_bytes
);
8174 TALLOC_FREE(smb_dname
);
8178 /****************************************************************************
8179 Reply to a TRANS2_FINDNOTIFYFIRST (start monitoring a directory for changes).
8180 We don't actually do this - we just send a null response.
8181 ****************************************************************************/
8183 static void call_trans2findnotifyfirst(connection_struct
*conn
,
8184 struct smb_request
*req
,
8185 char **pparams
, int total_params
,
8186 char **ppdata
, int total_data
,
8187 unsigned int max_data_bytes
)
8189 char *params
= *pparams
;
8192 if (total_params
< 6) {
8193 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
8197 info_level
= SVAL(params
,4);
8198 DEBUG(3,("call_trans2findnotifyfirst - info_level %d\n", info_level
));
8200 switch (info_level
) {
8205 reply_nterror(req
, NT_STATUS_INVALID_LEVEL
);
8209 /* Realloc the parameter and data sizes */
8210 *pparams
= (char *)SMB_REALLOC(*pparams
,6);
8211 if (*pparams
== NULL
) {
8212 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
8217 SSVAL(params
,0,fnf_handle
);
8218 SSVAL(params
,2,0); /* No changes */
8219 SSVAL(params
,4,0); /* No EA errors */
8226 send_trans2_replies(conn
, req
, params
, 6, *ppdata
, 0, max_data_bytes
);
8231 /****************************************************************************
8232 Reply to a TRANS2_FINDNOTIFYNEXT (continue monitoring a directory for
8233 changes). Currently this does nothing.
8234 ****************************************************************************/
8236 static void call_trans2findnotifynext(connection_struct
*conn
,
8237 struct smb_request
*req
,
8238 char **pparams
, int total_params
,
8239 char **ppdata
, int total_data
,
8240 unsigned int max_data_bytes
)
8242 char *params
= *pparams
;
8244 DEBUG(3,("call_trans2findnotifynext\n"));
8246 /* Realloc the parameter and data sizes */
8247 *pparams
= (char *)SMB_REALLOC(*pparams
,4);
8248 if (*pparams
== NULL
) {
8249 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
8254 SSVAL(params
,0,0); /* No changes */
8255 SSVAL(params
,2,0); /* No EA errors */
8257 send_trans2_replies(conn
, req
, params
, 4, *ppdata
, 0, max_data_bytes
);
8262 /****************************************************************************
8263 Reply to a TRANS2_GET_DFS_REFERRAL - Shirish Kalele <kalele@veritas.com>.
8264 ****************************************************************************/
8266 static void call_trans2getdfsreferral(connection_struct
*conn
,
8267 struct smb_request
*req
,
8268 char **pparams
, int total_params
,
8269 char **ppdata
, int total_data
,
8270 unsigned int max_data_bytes
)
8272 char *params
= *pparams
;
8273 char *pathname
= NULL
;
8275 int max_referral_level
;
8276 NTSTATUS status
= NT_STATUS_OK
;
8277 TALLOC_CTX
*ctx
= talloc_tos();
8279 DEBUG(10,("call_trans2getdfsreferral\n"));
8281 if (total_params
< 3) {
8282 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
8286 max_referral_level
= SVAL(params
,0);
8288 if(!lp_host_msdfs()) {
8289 reply_nterror(req
, NT_STATUS_NOT_IMPLEMENTED
);
8293 srvstr_pull_talloc(ctx
, params
, req
->flags2
, &pathname
, ¶ms
[2],
8294 total_params
- 2, STR_TERMINATE
);
8296 reply_nterror(req
, NT_STATUS_NOT_FOUND
);
8299 if((reply_size
= setup_dfs_referral(conn
, pathname
, max_referral_level
,
8300 ppdata
,&status
)) < 0) {
8301 reply_nterror(req
, status
);
8305 SSVAL(req
->inbuf
, smb_flg2
,
8306 SVAL(req
->inbuf
,smb_flg2
) | FLAGS2_DFS_PATHNAMES
);
8307 send_trans2_replies(conn
, req
,0,0,*ppdata
,reply_size
, max_data_bytes
);
8312 #define LMCAT_SPL 0x53
8313 #define LMFUNC_GETJOBID 0x60
8315 /****************************************************************************
8316 Reply to a TRANS2_IOCTL - used for OS/2 printing.
8317 ****************************************************************************/
8319 static void call_trans2ioctl(connection_struct
*conn
,
8320 struct smb_request
*req
,
8321 char **pparams
, int total_params
,
8322 char **ppdata
, int total_data
,
8323 unsigned int max_data_bytes
)
8325 char *pdata
= *ppdata
;
8326 files_struct
*fsp
= file_fsp(req
, SVAL(req
->vwv
+15, 0));
8328 /* check for an invalid fid before proceeding */
8331 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
8335 if ((SVAL(req
->vwv
+16, 0) == LMCAT_SPL
)
8336 && (SVAL(req
->vwv
+17, 0) == LMFUNC_GETJOBID
)) {
8337 *ppdata
= (char *)SMB_REALLOC(*ppdata
, 32);
8338 if (*ppdata
== NULL
) {
8339 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
8344 /* NOTE - THIS IS ASCII ONLY AT THE MOMENT - NOT SURE IF OS/2
8345 CAN ACCEPT THIS IN UNICODE. JRA. */
8348 if (fsp
->print_file
) {
8349 SSVAL(pdata
, 0, fsp
->print_file
->rap_jobid
);
8353 srvstr_push(pdata
, req
->flags2
, pdata
+ 2,
8354 global_myname(), 15,
8355 STR_ASCII
|STR_TERMINATE
); /* Our NetBIOS name */
8356 srvstr_push(pdata
, req
->flags2
, pdata
+18,
8357 lp_servicename(SNUM(conn
)), 13,
8358 STR_ASCII
|STR_TERMINATE
); /* Service name */
8359 send_trans2_replies(conn
, req
, *pparams
, 0, *ppdata
, 32,
8364 DEBUG(2,("Unknown TRANS2_IOCTL\n"));
8365 reply_nterror(req
, NT_STATUS_NOT_IMPLEMENTED
);
8368 /****************************************************************************
8369 Reply to a SMBfindclose (stop trans2 directory search).
8370 ****************************************************************************/
8372 void reply_findclose(struct smb_request
*req
)
8375 struct smbd_server_connection
*sconn
= req
->sconn
;
8377 START_PROFILE(SMBfindclose
);
8380 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
8381 END_PROFILE(SMBfindclose
);
8385 dptr_num
= SVALS(req
->vwv
+0, 0);
8387 DEBUG(3,("reply_findclose, dptr_num = %d\n", dptr_num
));
8389 dptr_close(sconn
, &dptr_num
);
8391 reply_outbuf(req
, 0, 0);
8393 DEBUG(3,("SMBfindclose dptr_num = %d\n", dptr_num
));
8395 END_PROFILE(SMBfindclose
);
8399 /****************************************************************************
8400 Reply to a SMBfindnclose (stop FINDNOTIFYFIRST directory search).
8401 ****************************************************************************/
8403 void reply_findnclose(struct smb_request
*req
)
8407 START_PROFILE(SMBfindnclose
);
8410 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
8411 END_PROFILE(SMBfindnclose
);
8415 dptr_num
= SVAL(req
->vwv
+0, 0);
8417 DEBUG(3,("reply_findnclose, dptr_num = %d\n", dptr_num
));
8419 /* We never give out valid handles for a
8420 findnotifyfirst - so any dptr_num is ok here.
8423 reply_outbuf(req
, 0, 0);
8425 DEBUG(3,("SMB_findnclose dptr_num = %d\n", dptr_num
));
8427 END_PROFILE(SMBfindnclose
);
8431 static void handle_trans2(connection_struct
*conn
, struct smb_request
*req
,
8432 struct trans_state
*state
)
8434 if (get_Protocol() >= PROTOCOL_NT1
) {
8435 req
->flags2
|= 0x40; /* IS_LONG_NAME */
8436 SSVAL(req
->inbuf
,smb_flg2
,req
->flags2
);
8439 if (conn
->encrypt_level
== Required
&& !req
->encrypted
) {
8440 if (state
->call
!= TRANSACT2_QFSINFO
&&
8441 state
->call
!= TRANSACT2_SETFSINFO
) {
8442 DEBUG(0,("handle_trans2: encryption required "
8444 (unsigned int)state
->call
));
8445 reply_nterror(req
, NT_STATUS_ACCESS_DENIED
);
8450 SMB_PERFCOUNT_SET_SUBOP(&req
->pcd
, state
->call
);
8452 /* Now we must call the relevant TRANS2 function */
8453 switch(state
->call
) {
8454 case TRANSACT2_OPEN
:
8456 START_PROFILE(Trans2_open
);
8457 call_trans2open(conn
, req
,
8458 &state
->param
, state
->total_param
,
8459 &state
->data
, state
->total_data
,
8460 state
->max_data_return
);
8461 END_PROFILE(Trans2_open
);
8465 case TRANSACT2_FINDFIRST
:
8467 START_PROFILE(Trans2_findfirst
);
8468 call_trans2findfirst(conn
, req
,
8469 &state
->param
, state
->total_param
,
8470 &state
->data
, state
->total_data
,
8471 state
->max_data_return
);
8472 END_PROFILE(Trans2_findfirst
);
8476 case TRANSACT2_FINDNEXT
:
8478 START_PROFILE(Trans2_findnext
);
8479 call_trans2findnext(conn
, req
,
8480 &state
->param
, state
->total_param
,
8481 &state
->data
, state
->total_data
,
8482 state
->max_data_return
);
8483 END_PROFILE(Trans2_findnext
);
8487 case TRANSACT2_QFSINFO
:
8489 START_PROFILE(Trans2_qfsinfo
);
8490 call_trans2qfsinfo(conn
, req
,
8491 &state
->param
, state
->total_param
,
8492 &state
->data
, state
->total_data
,
8493 state
->max_data_return
);
8494 END_PROFILE(Trans2_qfsinfo
);
8498 case TRANSACT2_SETFSINFO
:
8500 START_PROFILE(Trans2_setfsinfo
);
8501 call_trans2setfsinfo(conn
, req
,
8502 &state
->param
, state
->total_param
,
8503 &state
->data
, state
->total_data
,
8504 state
->max_data_return
);
8505 END_PROFILE(Trans2_setfsinfo
);
8509 case TRANSACT2_QPATHINFO
:
8510 case TRANSACT2_QFILEINFO
:
8512 START_PROFILE(Trans2_qpathinfo
);
8513 call_trans2qfilepathinfo(conn
, req
, state
->call
,
8514 &state
->param
, state
->total_param
,
8515 &state
->data
, state
->total_data
,
8516 state
->max_data_return
);
8517 END_PROFILE(Trans2_qpathinfo
);
8521 case TRANSACT2_SETPATHINFO
:
8522 case TRANSACT2_SETFILEINFO
:
8524 START_PROFILE(Trans2_setpathinfo
);
8525 call_trans2setfilepathinfo(conn
, req
, state
->call
,
8526 &state
->param
, state
->total_param
,
8527 &state
->data
, state
->total_data
,
8528 state
->max_data_return
);
8529 END_PROFILE(Trans2_setpathinfo
);
8533 case TRANSACT2_FINDNOTIFYFIRST
:
8535 START_PROFILE(Trans2_findnotifyfirst
);
8536 call_trans2findnotifyfirst(conn
, req
,
8537 &state
->param
, state
->total_param
,
8538 &state
->data
, state
->total_data
,
8539 state
->max_data_return
);
8540 END_PROFILE(Trans2_findnotifyfirst
);
8544 case TRANSACT2_FINDNOTIFYNEXT
:
8546 START_PROFILE(Trans2_findnotifynext
);
8547 call_trans2findnotifynext(conn
, req
,
8548 &state
->param
, state
->total_param
,
8549 &state
->data
, state
->total_data
,
8550 state
->max_data_return
);
8551 END_PROFILE(Trans2_findnotifynext
);
8555 case TRANSACT2_MKDIR
:
8557 START_PROFILE(Trans2_mkdir
);
8558 call_trans2mkdir(conn
, req
,
8559 &state
->param
, state
->total_param
,
8560 &state
->data
, state
->total_data
,
8561 state
->max_data_return
);
8562 END_PROFILE(Trans2_mkdir
);
8566 case TRANSACT2_GET_DFS_REFERRAL
:
8568 START_PROFILE(Trans2_get_dfs_referral
);
8569 call_trans2getdfsreferral(conn
, req
,
8570 &state
->param
, state
->total_param
,
8571 &state
->data
, state
->total_data
,
8572 state
->max_data_return
);
8573 END_PROFILE(Trans2_get_dfs_referral
);
8577 case TRANSACT2_IOCTL
:
8579 START_PROFILE(Trans2_ioctl
);
8580 call_trans2ioctl(conn
, req
,
8581 &state
->param
, state
->total_param
,
8582 &state
->data
, state
->total_data
,
8583 state
->max_data_return
);
8584 END_PROFILE(Trans2_ioctl
);
8589 /* Error in request */
8590 DEBUG(2,("Unknown request %d in trans2 call\n", state
->call
));
8591 reply_nterror(req
, NT_STATUS_NOT_IMPLEMENTED
);
8595 /****************************************************************************
8596 Reply to a SMBtrans2.
8597 ****************************************************************************/
8599 void reply_trans2(struct smb_request
*req
)
8601 connection_struct
*conn
= req
->conn
;
8606 unsigned int tran_call
;
8607 struct trans_state
*state
;
8610 START_PROFILE(SMBtrans2
);
8612 if (req
->wct
< 14) {
8613 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
8614 END_PROFILE(SMBtrans2
);
8618 dsoff
= SVAL(req
->vwv
+12, 0);
8619 dscnt
= SVAL(req
->vwv
+11, 0);
8620 psoff
= SVAL(req
->vwv
+10, 0);
8621 pscnt
= SVAL(req
->vwv
+9, 0);
8622 tran_call
= SVAL(req
->vwv
+14, 0);
8624 result
= allow_new_trans(conn
->pending_trans
, req
->mid
);
8625 if (!NT_STATUS_IS_OK(result
)) {
8626 DEBUG(2, ("Got invalid trans2 request: %s\n",
8627 nt_errstr(result
)));
8628 reply_nterror(req
, result
);
8629 END_PROFILE(SMBtrans2
);
8634 switch (tran_call
) {
8635 /* List the allowed trans2 calls on IPC$ */
8636 case TRANSACT2_OPEN
:
8637 case TRANSACT2_GET_DFS_REFERRAL
:
8638 case TRANSACT2_QFILEINFO
:
8639 case TRANSACT2_QFSINFO
:
8640 case TRANSACT2_SETFSINFO
:
8643 reply_nterror(req
, NT_STATUS_ACCESS_DENIED
);
8644 END_PROFILE(SMBtrans2
);
8649 if ((state
= TALLOC_P(conn
, struct trans_state
)) == NULL
) {
8650 DEBUG(0, ("talloc failed\n"));
8651 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
8652 END_PROFILE(SMBtrans2
);
8656 state
->cmd
= SMBtrans2
;
8658 state
->mid
= req
->mid
;
8659 state
->vuid
= req
->vuid
;
8660 state
->setup_count
= SVAL(req
->vwv
+13, 0);
8661 state
->setup
= NULL
;
8662 state
->total_param
= SVAL(req
->vwv
+0, 0);
8663 state
->param
= NULL
;
8664 state
->total_data
= SVAL(req
->vwv
+1, 0);
8666 state
->max_param_return
= SVAL(req
->vwv
+2, 0);
8667 state
->max_data_return
= SVAL(req
->vwv
+3, 0);
8668 state
->max_setup_return
= SVAL(req
->vwv
+4, 0);
8669 state
->close_on_completion
= BITSETW(req
->vwv
+5, 0);
8670 state
->one_way
= BITSETW(req
->vwv
+5, 1);
8672 state
->call
= tran_call
;
8674 /* All trans2 messages we handle have smb_sucnt == 1 - ensure this
8675 is so as a sanity check */
8676 if (state
->setup_count
!= 1) {
8678 * Need to have rc=0 for ioctl to get job id for OS/2.
8679 * Network printing will fail if function is not successful.
8680 * Similar function in reply.c will be used if protocol
8681 * is LANMAN1.0 instead of LM1.2X002.
8682 * Until DosPrintSetJobInfo with PRJINFO3 is supported,
8683 * outbuf doesn't have to be set(only job id is used).
8685 if ( (state
->setup_count
== 4)
8686 && (tran_call
== TRANSACT2_IOCTL
)
8687 && (SVAL(req
->vwv
+16, 0) == LMCAT_SPL
)
8688 && (SVAL(req
->vwv
+17, 0) == LMFUNC_GETJOBID
)) {
8689 DEBUG(2,("Got Trans2 DevIOctl jobid\n"));
8691 DEBUG(2,("Invalid smb_sucnt in trans2 call(%u)\n",state
->setup_count
));
8692 DEBUG(2,("Transaction is %d\n",tran_call
));
8694 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
8695 END_PROFILE(SMBtrans2
);
8700 if ((dscnt
> state
->total_data
) || (pscnt
> state
->total_param
))
8703 if (state
->total_data
) {
8705 if (trans_oob(state
->total_data
, 0, dscnt
)
8706 || trans_oob(smb_len(req
->inbuf
), dsoff
, dscnt
)) {
8710 /* Can't use talloc here, the core routines do realloc on the
8711 * params and data. */
8712 state
->data
= (char *)SMB_MALLOC(state
->total_data
);
8713 if (state
->data
== NULL
) {
8714 DEBUG(0,("reply_trans2: data malloc fail for %u "
8715 "bytes !\n", (unsigned int)state
->total_data
));
8717 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
8718 END_PROFILE(SMBtrans2
);
8722 memcpy(state
->data
,smb_base(req
->inbuf
)+dsoff
,dscnt
);
8725 if (state
->total_param
) {
8727 if (trans_oob(state
->total_param
, 0, pscnt
)
8728 || trans_oob(smb_len(req
->inbuf
), psoff
, pscnt
)) {
8732 /* Can't use talloc here, the core routines do realloc on the
8733 * params and data. */
8734 state
->param
= (char *)SMB_MALLOC(state
->total_param
);
8735 if (state
->param
== NULL
) {
8736 DEBUG(0,("reply_trans: param malloc fail for %u "
8737 "bytes !\n", (unsigned int)state
->total_param
));
8738 SAFE_FREE(state
->data
);
8740 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
8741 END_PROFILE(SMBtrans2
);
8745 memcpy(state
->param
,smb_base(req
->inbuf
)+psoff
,pscnt
);
8748 state
->received_data
= dscnt
;
8749 state
->received_param
= pscnt
;
8751 if ((state
->received_param
== state
->total_param
) &&
8752 (state
->received_data
== state
->total_data
)) {
8754 handle_trans2(conn
, req
, state
);
8756 SAFE_FREE(state
->data
);
8757 SAFE_FREE(state
->param
);
8759 END_PROFILE(SMBtrans2
);
8763 DLIST_ADD(conn
->pending_trans
, state
);
8765 /* We need to send an interim response then receive the rest
8766 of the parameter/data bytes */
8767 reply_outbuf(req
, 0, 0);
8768 show_msg((char *)req
->outbuf
);
8769 END_PROFILE(SMBtrans2
);
8774 DEBUG(0,("reply_trans2: invalid trans parameters\n"));
8775 SAFE_FREE(state
->data
);
8776 SAFE_FREE(state
->param
);
8778 END_PROFILE(SMBtrans2
);
8779 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
8783 /****************************************************************************
8784 Reply to a SMBtranss2
8785 ****************************************************************************/
8787 void reply_transs2(struct smb_request
*req
)
8789 connection_struct
*conn
= req
->conn
;
8790 unsigned int pcnt
,poff
,dcnt
,doff
,pdisp
,ddisp
;
8791 struct trans_state
*state
;
8793 START_PROFILE(SMBtranss2
);
8795 show_msg((char *)req
->inbuf
);
8798 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
8799 END_PROFILE(SMBtranss2
);
8803 for (state
= conn
->pending_trans
; state
!= NULL
;
8804 state
= state
->next
) {
8805 if (state
->mid
== req
->mid
) {
8810 if ((state
== NULL
) || (state
->cmd
!= SMBtrans2
)) {
8811 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
8812 END_PROFILE(SMBtranss2
);
8816 /* Revise state->total_param and state->total_data in case they have
8817 changed downwards */
8819 if (SVAL(req
->vwv
+0, 0) < state
->total_param
)
8820 state
->total_param
= SVAL(req
->vwv
+0, 0);
8821 if (SVAL(req
->vwv
+1, 0) < state
->total_data
)
8822 state
->total_data
= SVAL(req
->vwv
+1, 0);
8824 pcnt
= SVAL(req
->vwv
+2, 0);
8825 poff
= SVAL(req
->vwv
+3, 0);
8826 pdisp
= SVAL(req
->vwv
+4, 0);
8828 dcnt
= SVAL(req
->vwv
+5, 0);
8829 doff
= SVAL(req
->vwv
+6, 0);
8830 ddisp
= SVAL(req
->vwv
+7, 0);
8832 state
->received_param
+= pcnt
;
8833 state
->received_data
+= dcnt
;
8835 if ((state
->received_data
> state
->total_data
) ||
8836 (state
->received_param
> state
->total_param
))
8840 if (trans_oob(state
->total_param
, pdisp
, pcnt
)
8841 || trans_oob(smb_len(req
->inbuf
), poff
, pcnt
)) {
8844 memcpy(state
->param
+pdisp
,smb_base(req
->inbuf
)+poff
,pcnt
);
8848 if (trans_oob(state
->total_data
, ddisp
, dcnt
)
8849 || trans_oob(smb_len(req
->inbuf
), doff
, dcnt
)) {
8852 memcpy(state
->data
+ddisp
, smb_base(req
->inbuf
)+doff
,dcnt
);
8855 if ((state
->received_param
< state
->total_param
) ||
8856 (state
->received_data
< state
->total_data
)) {
8857 END_PROFILE(SMBtranss2
);
8861 handle_trans2(conn
, req
, state
);
8863 DLIST_REMOVE(conn
->pending_trans
, state
);
8864 SAFE_FREE(state
->data
);
8865 SAFE_FREE(state
->param
);
8868 END_PROFILE(SMBtranss2
);
8873 DEBUG(0,("reply_transs2: invalid trans parameters\n"));
8874 DLIST_REMOVE(conn
->pending_trans
, state
);
8875 SAFE_FREE(state
->data
);
8876 SAFE_FREE(state
->param
);
8878 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
8879 END_PROFILE(SMBtranss2
);