2 Unix SMB/CIFS implementation.
3 Wrap disk only vfs functions to sidestep dodgy compilers.
4 Copyright (C) Tim Potter 1998
5 Copyright (C) Jeremy Allison 2007
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "system/time.h"
23 #include "system/filesys.h"
24 #include "smbd/smbd.h"
26 #include "smbprofile.h"
27 #include "../libcli/security/security.h"
28 #include "passdb/lookup_sid.h"
31 #define DBGC_CLASS DBGC_VFS
33 /* Check for NULL pointer parameters in vfswrap_* functions */
35 /* We don't want to have NULL function pointers lying around. Someone
36 is sure to try and execute them. These stubs are used to prevent
39 static int vfswrap_connect(vfs_handle_struct
*handle
, const char *service
, const char *user
)
41 return 0; /* Return >= 0 for success */
44 static void vfswrap_disconnect(vfs_handle_struct
*handle
)
50 static uint64_t vfswrap_disk_free(vfs_handle_struct
*handle
, const char *path
, bool small_query
, uint64_t *bsize
,
51 uint64_t *dfree
, uint64_t *dsize
)
55 result
= sys_disk_free(handle
->conn
, path
, small_query
, bsize
, dfree
, dsize
);
59 static int vfswrap_get_quota(struct vfs_handle_struct
*handle
, enum SMB_QUOTA_TYPE qtype
, unid_t id
, SMB_DISK_QUOTA
*qt
)
61 #ifdef HAVE_SYS_QUOTAS
64 START_PROFILE(syscall_get_quota
);
65 result
= sys_get_quota(handle
->conn
->connectpath
, qtype
, id
, qt
);
66 END_PROFILE(syscall_get_quota
);
74 static int vfswrap_set_quota(struct vfs_handle_struct
*handle
, enum SMB_QUOTA_TYPE qtype
, unid_t id
, SMB_DISK_QUOTA
*qt
)
76 #ifdef HAVE_SYS_QUOTAS
79 START_PROFILE(syscall_set_quota
);
80 result
= sys_set_quota(handle
->conn
->connectpath
, qtype
, id
, qt
);
81 END_PROFILE(syscall_set_quota
);
89 static int vfswrap_get_shadow_copy_data(struct vfs_handle_struct
*handle
,
90 struct files_struct
*fsp
,
91 struct shadow_copy_data
*shadow_copy_data
,
95 return -1; /* Not implemented. */
98 static int vfswrap_statvfs(struct vfs_handle_struct
*handle
, const char *path
, vfs_statvfs_struct
*statbuf
)
100 return sys_statvfs(path
, statbuf
);
103 static uint32_t vfswrap_fs_capabilities(struct vfs_handle_struct
*handle
,
104 enum timestamp_set_resolution
*p_ts_res
)
106 connection_struct
*conn
= handle
->conn
;
107 uint32_t caps
= FILE_CASE_SENSITIVE_SEARCH
| FILE_CASE_PRESERVED_NAMES
;
108 struct smb_filename
*smb_fname_cpath
= NULL
;
112 #if defined(DARWINOS)
113 struct vfs_statvfs_struct statbuf
;
114 ZERO_STRUCT(statbuf
);
115 sys_statvfs(conn
->connectpath
, &statbuf
);
116 caps
= statbuf
.FsCapabilities
;
119 *p_ts_res
= TIMESTAMP_SET_SECONDS
;
121 /* Work out what timestamp resolution we can
122 * use when setting a timestamp. */
124 status
= create_synthetic_smb_fname(talloc_tos(),
129 if (!NT_STATUS_IS_OK(status
)) {
133 ret
= SMB_VFS_STAT(conn
, smb_fname_cpath
);
135 TALLOC_FREE(smb_fname_cpath
);
139 if (smb_fname_cpath
->st
.st_ex_mtime
.tv_nsec
||
140 smb_fname_cpath
->st
.st_ex_atime
.tv_nsec
||
141 smb_fname_cpath
->st
.st_ex_ctime
.tv_nsec
) {
142 /* If any of the normal UNIX directory timestamps
143 * have a non-zero tv_nsec component assume
144 * we might be able to set sub-second timestamps.
145 * See what filetime set primitives we have.
147 #if defined(HAVE_UTIMENSAT)
148 *p_ts_res
= TIMESTAMP_SET_NT_OR_BETTER
;
149 #elif defined(HAVE_UTIMES)
150 /* utimes allows msec timestamps to be set. */
151 *p_ts_res
= TIMESTAMP_SET_MSEC
;
152 #elif defined(HAVE_UTIME)
153 /* utime only allows sec timestamps to be set. */
154 *p_ts_res
= TIMESTAMP_SET_SECONDS
;
157 DEBUG(10,("vfswrap_fs_capabilities: timestamp "
159 "available on share %s, directory %s\n",
160 *p_ts_res
== TIMESTAMP_SET_MSEC
? "msec" : "sec",
161 lp_servicename(conn
->params
->service
),
162 conn
->connectpath
));
164 TALLOC_FREE(smb_fname_cpath
);
168 /* Directory operations */
170 static SMB_STRUCT_DIR
*vfswrap_opendir(vfs_handle_struct
*handle
, const char *fname
, const char *mask
, uint32 attr
)
172 SMB_STRUCT_DIR
*result
;
174 START_PROFILE(syscall_opendir
);
175 result
= sys_opendir(fname
);
176 END_PROFILE(syscall_opendir
);
180 static SMB_STRUCT_DIR
*vfswrap_fdopendir(vfs_handle_struct
*handle
,
185 SMB_STRUCT_DIR
*result
;
187 START_PROFILE(syscall_fdopendir
);
188 result
= sys_fdopendir(fsp
->fh
->fd
);
189 END_PROFILE(syscall_fdopendir
);
194 static SMB_STRUCT_DIRENT
*vfswrap_readdir(vfs_handle_struct
*handle
,
195 SMB_STRUCT_DIR
*dirp
,
196 SMB_STRUCT_STAT
*sbuf
)
198 SMB_STRUCT_DIRENT
*result
;
200 START_PROFILE(syscall_readdir
);
201 result
= sys_readdir(dirp
);
202 /* Default Posix readdir() does not give us stat info.
203 * Set to invalid to indicate we didn't return this info. */
205 SET_STAT_INVALID(*sbuf
);
206 END_PROFILE(syscall_readdir
);
210 static void vfswrap_seekdir(vfs_handle_struct
*handle
, SMB_STRUCT_DIR
*dirp
, long offset
)
212 START_PROFILE(syscall_seekdir
);
213 sys_seekdir(dirp
, offset
);
214 END_PROFILE(syscall_seekdir
);
217 static long vfswrap_telldir(vfs_handle_struct
*handle
, SMB_STRUCT_DIR
*dirp
)
220 START_PROFILE(syscall_telldir
);
221 result
= sys_telldir(dirp
);
222 END_PROFILE(syscall_telldir
);
226 static void vfswrap_rewinddir(vfs_handle_struct
*handle
, SMB_STRUCT_DIR
*dirp
)
228 START_PROFILE(syscall_rewinddir
);
230 END_PROFILE(syscall_rewinddir
);
233 static int vfswrap_mkdir(vfs_handle_struct
*handle
, const char *path
, mode_t mode
)
236 bool has_dacl
= False
;
239 START_PROFILE(syscall_mkdir
);
241 if (lp_inherit_acls(SNUM(handle
->conn
))
242 && parent_dirname(talloc_tos(), path
, &parent
, NULL
)
243 && (has_dacl
= directory_has_default_acl(handle
->conn
, parent
)))
244 mode
= (0777 & lp_dir_mask(SNUM(handle
->conn
)));
248 result
= mkdir(path
, mode
);
250 if (result
== 0 && !has_dacl
) {
252 * We need to do this as the default behavior of POSIX ACLs
253 * is to set the mask to be the requested group permission
254 * bits, not the group permission bits to be the requested
255 * group permission bits. This is not what we want, as it will
256 * mess up any inherited ACL bits that were set. JRA.
258 int saved_errno
= errno
; /* We may get ENOSYS */
259 if ((SMB_VFS_CHMOD_ACL(handle
->conn
, path
, mode
) == -1) && (errno
== ENOSYS
))
263 END_PROFILE(syscall_mkdir
);
267 static int vfswrap_rmdir(vfs_handle_struct
*handle
, const char *path
)
271 START_PROFILE(syscall_rmdir
);
272 result
= rmdir(path
);
273 END_PROFILE(syscall_rmdir
);
277 static int vfswrap_closedir(vfs_handle_struct
*handle
, SMB_STRUCT_DIR
*dirp
)
281 START_PROFILE(syscall_closedir
);
282 result
= sys_closedir(dirp
);
283 END_PROFILE(syscall_closedir
);
287 static void vfswrap_init_search_op(vfs_handle_struct
*handle
,
288 SMB_STRUCT_DIR
*dirp
)
290 /* Default behavior is a NOOP */
293 /* File operations */
295 static int vfswrap_open(vfs_handle_struct
*handle
,
296 struct smb_filename
*smb_fname
,
297 files_struct
*fsp
, int flags
, mode_t mode
)
301 START_PROFILE(syscall_open
);
303 if (smb_fname
->stream_name
) {
308 result
= sys_open(smb_fname
->base_name
, flags
, mode
);
310 END_PROFILE(syscall_open
);
314 static NTSTATUS
vfswrap_create_file(vfs_handle_struct
*handle
,
315 struct smb_request
*req
,
316 uint16_t root_dir_fid
,
317 struct smb_filename
*smb_fname
,
318 uint32_t access_mask
,
319 uint32_t share_access
,
320 uint32_t create_disposition
,
321 uint32_t create_options
,
322 uint32_t file_attributes
,
323 uint32_t oplock_request
,
324 uint64_t allocation_size
,
325 uint32_t private_flags
,
326 struct security_descriptor
*sd
,
327 struct ea_list
*ea_list
,
328 files_struct
**result
,
331 return create_file_default(handle
->conn
, req
, root_dir_fid
, smb_fname
,
332 access_mask
, share_access
,
333 create_disposition
, create_options
,
334 file_attributes
, oplock_request
,
335 allocation_size
, private_flags
,
340 static int vfswrap_close(vfs_handle_struct
*handle
, files_struct
*fsp
)
344 START_PROFILE(syscall_close
);
345 result
= fd_close_posix(fsp
);
346 END_PROFILE(syscall_close
);
350 static ssize_t
vfswrap_read(vfs_handle_struct
*handle
, files_struct
*fsp
, void *data
, size_t n
)
354 START_PROFILE_BYTES(syscall_read
, n
);
355 result
= sys_read(fsp
->fh
->fd
, data
, n
);
356 END_PROFILE(syscall_read
);
360 static ssize_t
vfswrap_pread(vfs_handle_struct
*handle
, files_struct
*fsp
, void *data
,
361 size_t n
, SMB_OFF_T offset
)
365 #if defined(HAVE_PREAD) || defined(HAVE_PREAD64)
366 START_PROFILE_BYTES(syscall_pread
, n
);
367 result
= sys_pread(fsp
->fh
->fd
, data
, n
, offset
);
368 END_PROFILE(syscall_pread
);
370 if (result
== -1 && errno
== ESPIPE
) {
371 /* Maintain the fiction that pipes can be seeked (sought?) on. */
372 result
= SMB_VFS_READ(fsp
, data
, n
);
376 #else /* HAVE_PREAD */
380 curr
= SMB_VFS_LSEEK(fsp
, 0, SEEK_CUR
);
381 if (curr
== -1 && errno
== ESPIPE
) {
382 /* Maintain the fiction that pipes can be seeked (sought?) on. */
383 result
= SMB_VFS_READ(fsp
, data
, n
);
388 if (SMB_VFS_LSEEK(fsp
, offset
, SEEK_SET
) == -1) {
393 result
= SMB_VFS_READ(fsp
, data
, n
);
396 SMB_VFS_LSEEK(fsp
, curr
, SEEK_SET
);
399 #endif /* HAVE_PREAD */
404 static ssize_t
vfswrap_write(vfs_handle_struct
*handle
, files_struct
*fsp
, const void *data
, size_t n
)
408 START_PROFILE_BYTES(syscall_write
, n
);
409 result
= sys_write(fsp
->fh
->fd
, data
, n
);
410 END_PROFILE(syscall_write
);
414 static ssize_t
vfswrap_pwrite(vfs_handle_struct
*handle
, files_struct
*fsp
, const void *data
,
415 size_t n
, SMB_OFF_T offset
)
419 #if defined(HAVE_PWRITE) || defined(HAVE_PRWITE64)
420 START_PROFILE_BYTES(syscall_pwrite
, n
);
421 result
= sys_pwrite(fsp
->fh
->fd
, data
, n
, offset
);
422 END_PROFILE(syscall_pwrite
);
424 if (result
== -1 && errno
== ESPIPE
) {
425 /* Maintain the fiction that pipes can be sought on. */
426 result
= SMB_VFS_WRITE(fsp
, data
, n
);
429 #else /* HAVE_PWRITE */
433 curr
= SMB_VFS_LSEEK(fsp
, 0, SEEK_CUR
);
438 if (SMB_VFS_LSEEK(fsp
, offset
, SEEK_SET
) == -1) {
442 result
= SMB_VFS_WRITE(fsp
, data
, n
);
445 SMB_VFS_LSEEK(fsp
, curr
, SEEK_SET
);
448 #endif /* HAVE_PWRITE */
453 static SMB_OFF_T
vfswrap_lseek(vfs_handle_struct
*handle
, files_struct
*fsp
, SMB_OFF_T offset
, int whence
)
455 SMB_OFF_T result
= 0;
457 START_PROFILE(syscall_lseek
);
459 /* Cope with 'stat' file opens. */
460 if (fsp
->fh
->fd
!= -1)
461 result
= sys_lseek(fsp
->fh
->fd
, offset
, whence
);
464 * We want to maintain the fiction that we can seek
465 * on a fifo for file system purposes. This allows
466 * people to set up UNIX fifo's that feed data to Windows
470 if((result
== -1) && (errno
== ESPIPE
)) {
475 END_PROFILE(syscall_lseek
);
479 static ssize_t
vfswrap_sendfile(vfs_handle_struct
*handle
, int tofd
, files_struct
*fromfsp
, const DATA_BLOB
*hdr
,
480 SMB_OFF_T offset
, size_t n
)
484 START_PROFILE_BYTES(syscall_sendfile
, n
);
485 result
= sys_sendfile(tofd
, fromfsp
->fh
->fd
, hdr
, offset
, n
);
486 END_PROFILE(syscall_sendfile
);
490 static ssize_t
vfswrap_recvfile(vfs_handle_struct
*handle
,
498 START_PROFILE_BYTES(syscall_recvfile
, n
);
499 result
= sys_recvfile(fromfd
, tofsp
->fh
->fd
, offset
, n
);
500 END_PROFILE(syscall_recvfile
);
504 static int vfswrap_rename(vfs_handle_struct
*handle
,
505 const struct smb_filename
*smb_fname_src
,
506 const struct smb_filename
*smb_fname_dst
)
510 START_PROFILE(syscall_rename
);
512 if (smb_fname_src
->stream_name
|| smb_fname_dst
->stream_name
) {
517 result
= rename(smb_fname_src
->base_name
, smb_fname_dst
->base_name
);
520 END_PROFILE(syscall_rename
);
524 static int vfswrap_fsync(vfs_handle_struct
*handle
, files_struct
*fsp
)
529 START_PROFILE(syscall_fsync
);
530 result
= fsync(fsp
->fh
->fd
);
531 END_PROFILE(syscall_fsync
);
538 static int vfswrap_stat(vfs_handle_struct
*handle
,
539 struct smb_filename
*smb_fname
)
543 START_PROFILE(syscall_stat
);
545 if (smb_fname
->stream_name
) {
550 result
= sys_stat(smb_fname
->base_name
, &smb_fname
->st
,
551 lp_fake_dir_create_times(SNUM(handle
->conn
)));
553 END_PROFILE(syscall_stat
);
557 static int vfswrap_fstat(vfs_handle_struct
*handle
, files_struct
*fsp
, SMB_STRUCT_STAT
*sbuf
)
561 START_PROFILE(syscall_fstat
);
562 result
= sys_fstat(fsp
->fh
->fd
,
563 sbuf
, lp_fake_dir_create_times(SNUM(handle
->conn
)));
564 END_PROFILE(syscall_fstat
);
568 static int vfswrap_lstat(vfs_handle_struct
*handle
,
569 struct smb_filename
*smb_fname
)
573 START_PROFILE(syscall_lstat
);
575 if (smb_fname
->stream_name
) {
580 result
= sys_lstat(smb_fname
->base_name
, &smb_fname
->st
,
581 lp_fake_dir_create_times(SNUM(handle
->conn
)));
583 END_PROFILE(syscall_lstat
);
587 static NTSTATUS
vfswrap_translate_name(struct vfs_handle_struct
*handle
,
589 enum vfs_translate_direction direction
,
593 return NT_STATUS_NONE_MAPPED
;
597 * Implement the default fsctl operation.
599 static bool vfswrap_logged_ioctl_message
= false;
601 static NTSTATUS
vfswrap_fsctl(struct vfs_handle_struct
*handle
,
602 struct files_struct
*fsp
,
605 uint16_t req_flags
, /* Needed for UNICODE ... */
606 const uint8_t *_in_data
,
609 uint32_t max_out_len
,
612 const char *in_data
= (const char *)_in_data
;
613 char **out_data
= (char **)_out_data
;
616 case FSCTL_SET_SPARSE
:
618 bool set_sparse
= true;
621 if (in_len
>= 1 && in_data
[0] == 0) {
625 status
= file_set_sparse(handle
->conn
, fsp
, set_sparse
);
627 DEBUG(NT_STATUS_IS_OK(status
) ? 10 : 9,
628 ("FSCTL_SET_SPARSE: fname[%s] set[%u] - %s\n",
629 smb_fname_str_dbg(fsp
->fsp_name
), set_sparse
,
635 case FSCTL_CREATE_OR_GET_OBJECT_ID
:
637 unsigned char objid
[16];
638 char *return_data
= NULL
;
640 /* This should return the object-id on this file.
641 * I think I'll make this be the inode+dev. JRA.
644 DEBUG(10,("FSCTL_CREATE_OR_GET_OBJECT_ID: called on FID[0x%04X]\n",fsp
->fnum
));
646 *out_len
= (max_out_len
>= 64) ? 64 : max_out_len
;
647 /* Hmmm, will this cause problems if less data asked for? */
648 return_data
= talloc_array(ctx
, char, 64);
649 if (return_data
== NULL
) {
650 return NT_STATUS_NO_MEMORY
;
653 /* For backwards compatibility only store the dev/inode. */
654 push_file_id_16(return_data
, &fsp
->file_id
);
655 memcpy(return_data
+16,create_volume_objectid(fsp
->conn
,objid
),16);
656 push_file_id_16(return_data
+32, &fsp
->file_id
);
657 *out_data
= return_data
;
661 case FSCTL_GET_REPARSE_POINT
:
663 /* Fail it with STATUS_NOT_A_REPARSE_POINT */
664 DEBUG(10, ("FSCTL_GET_REPARSE_POINT: called on FID[0x%04X] Status: NOT_IMPLEMENTED\n", fsp
->fnum
));
665 return NT_STATUS_NOT_A_REPARSE_POINT
;
668 case FSCTL_SET_REPARSE_POINT
:
670 /* Fail it with STATUS_NOT_A_REPARSE_POINT */
671 DEBUG(10, ("FSCTL_SET_REPARSE_POINT: called on FID[0x%04X] Status: NOT_IMPLEMENTED\n", fsp
->fnum
));
672 return NT_STATUS_NOT_A_REPARSE_POINT
;
675 case FSCTL_GET_SHADOW_COPY_DATA
:
678 * This is called to retrieve the number of Shadow Copies (a.k.a. snapshots)
679 * and return their volume names. If max_data_count is 16, then it is just
680 * asking for the number of volumes and length of the combined names.
682 * pdata is the data allocated by our caller, but that uses
683 * total_data_count (which is 0 in our case) rather than max_data_count.
684 * Allocate the correct amount and return the pointer to let
685 * it be deallocated when we return.
687 struct shadow_copy_data
*shadow_data
= NULL
;
689 uint32 labels_data_count
= 0;
691 char *cur_pdata
= NULL
;
693 if (max_out_len
< 16) {
694 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) < 16 is invalid!\n",
696 return NT_STATUS_INVALID_PARAMETER
;
699 if (max_out_len
> 16) {
703 shadow_data
= talloc_zero(ctx
, struct shadow_copy_data
);
704 if (shadow_data
== NULL
) {
705 DEBUG(0,("TALLOC_ZERO() failed!\n"));
706 return NT_STATUS_NO_MEMORY
;
710 * Call the VFS routine to actually do the work.
712 if (SMB_VFS_GET_SHADOW_COPY_DATA(fsp
, shadow_data
, labels
)!=0) {
713 TALLOC_FREE(shadow_data
);
714 if (errno
== ENOSYS
) {
715 DEBUG(5,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, not supported.\n",
716 fsp
->conn
->connectpath
));
717 return NT_STATUS_NOT_SUPPORTED
;
719 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, failed.\n",
720 fsp
->conn
->connectpath
));
721 return NT_STATUS_UNSUCCESSFUL
;
725 labels_data_count
= (shadow_data
->num_volumes
* 2 *
726 sizeof(SHADOW_COPY_LABEL
)) + 2;
731 *out_len
= 12 + labels_data_count
+ 4;
734 if (max_out_len
< *out_len
) {
735 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) too small (%u) bytes needed!\n",
736 max_out_len
, *out_len
));
737 TALLOC_FREE(shadow_data
);
738 return NT_STATUS_BUFFER_TOO_SMALL
;
741 cur_pdata
= talloc_array(ctx
, char, *out_len
);
742 if (cur_pdata
== NULL
) {
743 TALLOC_FREE(shadow_data
);
744 return NT_STATUS_NO_MEMORY
;
747 *out_data
= cur_pdata
;
749 /* num_volumes 4 bytes */
750 SIVAL(cur_pdata
, 0, shadow_data
->num_volumes
);
753 /* num_labels 4 bytes */
754 SIVAL(cur_pdata
, 4, shadow_data
->num_volumes
);
757 /* needed_data_count 4 bytes */
758 SIVAL(cur_pdata
, 8, labels_data_count
+ 4);
762 DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for path[%s].\n",
763 shadow_data
->num_volumes
, fsp_str_dbg(fsp
)));
764 if (labels
&& shadow_data
->labels
) {
765 for (i
=0; i
<shadow_data
->num_volumes
; i
++) {
766 srvstr_push(cur_pdata
, req_flags
,
767 cur_pdata
, shadow_data
->labels
[i
],
768 2 * sizeof(SHADOW_COPY_LABEL
),
769 STR_UNICODE
|STR_TERMINATE
);
770 cur_pdata
+= 2 * sizeof(SHADOW_COPY_LABEL
);
771 DEBUGADD(10,("Label[%u]: '%s'\n",i
,shadow_data
->labels
[i
]));
775 TALLOC_FREE(shadow_data
);
780 case FSCTL_FIND_FILES_BY_SID
:
782 /* pretend this succeeded -
784 * we have to send back a list with all files owned by this SID
786 * but I have to check that --metze
792 DEBUG(10,("FSCTL_FIND_FILES_BY_SID: called on FID[0x%04X]\n", fsp
->fnum
));
795 /* NT_STATUS_BUFFER_TOO_SMALL maybe? */
796 return NT_STATUS_INVALID_PARAMETER
;
799 sid_len
= MIN(in_len
- 4,SID_MAX_SIZE
);
801 /* unknown 4 bytes: this is not the length of the sid :-( */
802 /*unknown = IVAL(pdata,0);*/
804 if (!sid_parse(in_data
+ 4, sid_len
, &sid
)) {
805 return NT_STATUS_INVALID_PARAMETER
;
807 DEBUGADD(10, ("for SID: %s\n", sid_string_dbg(&sid
)));
809 if (!sid_to_uid(&sid
, &uid
)) {
810 DEBUG(0,("sid_to_uid: failed, sid[%s] sid_len[%lu]\n",
811 sid_string_dbg(&sid
),
812 (unsigned long)sid_len
));
816 /* we can take a look at the find source :-)
818 * find ./ -uid $uid -name '*' is what we need here
821 * and send 4bytes len and then NULL terminated unicode strings
824 * but I don't know how to deal with the paged results
825 * (maybe we can hang the result anywhere in the fsp struct)
827 * but I don't know how to deal with the paged results
828 * (maybe we can hang the result anywhere in the fsp struct)
830 * we don't send all files at once
831 * and at the next we should *not* start from the beginning,
832 * so we have to cache the result
837 /* this works for now... */
841 case FSCTL_QUERY_ALLOCATED_RANGES
:
843 /* FIXME: This is just a dummy reply, telling that all of the
844 * file is allocated. MKS cp needs that.
845 * Adding the real allocated ranges via FIEMAP on Linux
846 * and SEEK_DATA/SEEK_HOLE on Solaris is needed to make
847 * this FSCTL correct for sparse files.
850 uint64_t offset
, length
;
851 char *out_data_tmp
= NULL
;
854 DEBUG(0,("FSCTL_QUERY_ALLOCATED_RANGES: data_count(%u) != 16 is invalid!\n",
856 return NT_STATUS_INVALID_PARAMETER
;
859 if (max_out_len
< 16) {
860 DEBUG(0,("FSCTL_QUERY_ALLOCATED_RANGES: max_out_len (%u) < 16 is invalid!\n",
862 return NT_STATUS_INVALID_PARAMETER
;
865 offset
= BVAL(in_data
,0);
866 length
= BVAL(in_data
,8);
868 if (offset
+ length
< offset
) {
869 /* No 64-bit integer wrap. */
870 return NT_STATUS_INVALID_PARAMETER
;
873 /* Shouldn't this be SMB_VFS_STAT ... ? */
874 status
= vfs_stat_fsp(fsp
);
875 if (!NT_STATUS_IS_OK(status
)) {
880 out_data_tmp
= talloc_array(ctx
, char, *out_len
);
881 if (out_data_tmp
== NULL
) {
882 DEBUG(10, ("unable to allocate memory for response\n"));
883 return NT_STATUS_NO_MEMORY
;
886 if (offset
> fsp
->fsp_name
->st
.st_ex_size
||
887 fsp
->fsp_name
->st
.st_ex_size
== 0 ||
889 memset(out_data_tmp
, 0, *out_len
);
891 uint64_t end
= offset
+ length
;
892 end
= MIN(end
, fsp
->fsp_name
->st
.st_ex_size
);
893 SBVAL(out_data_tmp
, 0, 0);
894 SBVAL(out_data_tmp
, 8, end
);
897 *out_data
= out_data_tmp
;
902 case FSCTL_IS_VOLUME_DIRTY
:
904 DEBUG(10,("FSCTL_IS_VOLUME_DIRTY: called on FID[0x%04X] "
905 "(but not implemented)\n", fsp
->fnum
));
907 * http://msdn.microsoft.com/en-us/library/cc232128%28PROT.10%29.aspx
908 * says we have to respond with NT_STATUS_INVALID_PARAMETER
910 return NT_STATUS_INVALID_PARAMETER
;
915 * Only print once ... unfortunately there could be lots of
916 * different FSCTLs that are called.
918 if (!vfswrap_logged_ioctl_message
) {
919 vfswrap_logged_ioctl_message
= true;
920 DEBUG(2, ("%s (0x%x): Currently not implemented.\n",
921 __func__
, function
));
925 return NT_STATUS_NOT_SUPPORTED
;
928 /********************************************************************
929 Given a stat buffer return the allocated size on disk, taking into
930 account sparse files.
931 ********************************************************************/
932 static uint64_t vfswrap_get_alloc_size(vfs_handle_struct
*handle
,
933 struct files_struct
*fsp
,
934 const SMB_STRUCT_STAT
*sbuf
)
938 START_PROFILE(syscall_get_alloc_size
);
940 if(S_ISDIR(sbuf
->st_ex_mode
)) {
945 #if defined(HAVE_STAT_ST_BLOCKS) && defined(STAT_ST_BLOCKSIZE)
946 result
= (uint64_t)STAT_ST_BLOCKSIZE
* (uint64_t)sbuf
->st_ex_blocks
;
948 result
= get_file_size_stat(sbuf
);
951 if (fsp
&& fsp
->initial_allocation_size
)
952 result
= MAX(result
,fsp
->initial_allocation_size
);
954 result
= smb_roundup(handle
->conn
, result
);
957 END_PROFILE(syscall_get_alloc_size
);
961 static int vfswrap_unlink(vfs_handle_struct
*handle
,
962 const struct smb_filename
*smb_fname
)
966 START_PROFILE(syscall_unlink
);
968 if (smb_fname
->stream_name
) {
972 result
= unlink(smb_fname
->base_name
);
975 END_PROFILE(syscall_unlink
);
979 static int vfswrap_chmod(vfs_handle_struct
*handle
, const char *path
, mode_t mode
)
983 START_PROFILE(syscall_chmod
);
986 * We need to do this due to the fact that the default POSIX ACL
987 * chmod modifies the ACL *mask* for the group owner, not the
988 * group owner bits directly. JRA.
993 int saved_errno
= errno
; /* We might get ENOSYS */
994 if ((result
= SMB_VFS_CHMOD_ACL(handle
->conn
, path
, mode
)) == 0) {
995 END_PROFILE(syscall_chmod
);
998 /* Error - return the old errno. */
1002 result
= chmod(path
, mode
);
1003 END_PROFILE(syscall_chmod
);
1007 static int vfswrap_fchmod(vfs_handle_struct
*handle
, files_struct
*fsp
, mode_t mode
)
1011 START_PROFILE(syscall_fchmod
);
1014 * We need to do this due to the fact that the default POSIX ACL
1015 * chmod modifies the ACL *mask* for the group owner, not the
1016 * group owner bits directly. JRA.
1020 int saved_errno
= errno
; /* We might get ENOSYS */
1021 if ((result
= SMB_VFS_FCHMOD_ACL(fsp
, mode
)) == 0) {
1022 END_PROFILE(syscall_fchmod
);
1025 /* Error - return the old errno. */
1026 errno
= saved_errno
;
1029 #if defined(HAVE_FCHMOD)
1030 result
= fchmod(fsp
->fh
->fd
, mode
);
1036 END_PROFILE(syscall_fchmod
);
1040 static int vfswrap_chown(vfs_handle_struct
*handle
, const char *path
, uid_t uid
, gid_t gid
)
1044 START_PROFILE(syscall_chown
);
1045 result
= chown(path
, uid
, gid
);
1046 END_PROFILE(syscall_chown
);
1050 static int vfswrap_fchown(vfs_handle_struct
*handle
, files_struct
*fsp
, uid_t uid
, gid_t gid
)
1055 START_PROFILE(syscall_fchown
);
1056 result
= fchown(fsp
->fh
->fd
, uid
, gid
);
1057 END_PROFILE(syscall_fchown
);
1065 static int vfswrap_lchown(vfs_handle_struct
*handle
, const char *path
, uid_t uid
, gid_t gid
)
1069 START_PROFILE(syscall_lchown
);
1070 result
= lchown(path
, uid
, gid
);
1071 END_PROFILE(syscall_lchown
);
1075 static int vfswrap_chdir(vfs_handle_struct
*handle
, const char *path
)
1079 START_PROFILE(syscall_chdir
);
1080 result
= chdir(path
);
1081 END_PROFILE(syscall_chdir
);
1085 static char *vfswrap_getwd(vfs_handle_struct
*handle
)
1089 START_PROFILE(syscall_getwd
);
1090 result
= sys_getwd();
1091 END_PROFILE(syscall_getwd
);
1095 /*********************************************************************
1096 nsec timestamp resolution call. Convert down to whatever the underlying
1097 system will support.
1098 **********************************************************************/
1100 static int vfswrap_ntimes(vfs_handle_struct
*handle
,
1101 const struct smb_filename
*smb_fname
,
1102 struct smb_file_time
*ft
)
1106 START_PROFILE(syscall_ntimes
);
1108 if (smb_fname
->stream_name
) {
1114 if (null_timespec(ft
->atime
)) {
1115 ft
->atime
= smb_fname
->st
.st_ex_atime
;
1118 if (null_timespec(ft
->mtime
)) {
1119 ft
->mtime
= smb_fname
->st
.st_ex_mtime
;
1122 if (!null_timespec(ft
->create_time
)) {
1123 set_create_timespec_ea(handle
->conn
,
1128 if ((timespec_compare(&ft
->atime
,
1129 &smb_fname
->st
.st_ex_atime
) == 0) &&
1130 (timespec_compare(&ft
->mtime
,
1131 &smb_fname
->st
.st_ex_mtime
) == 0)) {
1136 #if defined(HAVE_UTIMENSAT)
1138 struct timespec ts
[2];
1141 result
= utimensat(AT_FDCWD
, smb_fname
->base_name
, ts
, 0);
1143 result
= utimensat(AT_FDCWD
, smb_fname
->base_name
, NULL
, 0);
1145 if (!((result
== -1) && (errno
== ENOSYS
))) {
1149 #if defined(HAVE_UTIMES)
1151 struct timeval tv
[2];
1152 tv
[0] = convert_timespec_to_timeval(ft
->atime
);
1153 tv
[1] = convert_timespec_to_timeval(ft
->mtime
);
1154 result
= utimes(smb_fname
->base_name
, tv
);
1156 result
= utimes(smb_fname
->base_name
, NULL
);
1158 if (!((result
== -1) && (errno
== ENOSYS
))) {
1162 #if defined(HAVE_UTIME)
1164 struct utimbuf times
;
1165 times
.actime
= convert_timespec_to_time_t(ft
->atime
);
1166 times
.modtime
= convert_timespec_to_time_t(ft
->mtime
);
1167 result
= utime(smb_fname
->base_name
, ×
);
1169 result
= utime(smb_fname
->base_name
, NULL
);
1171 if (!((result
== -1) && (errno
== ENOSYS
))) {
1179 END_PROFILE(syscall_ntimes
);
1183 /*********************************************************************
1184 A version of ftruncate that will write the space on disk if strict
1186 **********************************************************************/
1188 static int strict_allocate_ftruncate(vfs_handle_struct
*handle
, files_struct
*fsp
, SMB_OFF_T len
)
1190 SMB_OFF_T space_to_write
;
1191 uint64_t space_avail
;
1192 uint64_t bsize
,dfree
,dsize
;
1195 SMB_STRUCT_STAT
*pst
;
1197 status
= vfs_stat_fsp(fsp
);
1198 if (!NT_STATUS_IS_OK(status
)) {
1201 pst
= &fsp
->fsp_name
->st
;
1204 if (S_ISFIFO(pst
->st_ex_mode
))
1208 if (pst
->st_ex_size
== len
)
1211 /* Shrink - just ftruncate. */
1212 if (pst
->st_ex_size
> len
)
1213 return sys_ftruncate(fsp
->fh
->fd
, len
);
1215 space_to_write
= len
- pst
->st_ex_size
;
1217 /* for allocation try fallocate first. This can fail on some
1218 platforms e.g. when the filesystem doesn't support it and no
1219 emulation is being done by the libc (like on AIX with JFS1). In that
1220 case we do our own emulation. fallocate implementations can
1221 return ENOTSUP or EINVAL in cases like that. */
1222 ret
= SMB_VFS_FALLOCATE(fsp
, VFS_FALLOCATE_EXTEND_SIZE
,
1223 pst
->st_ex_size
, space_to_write
);
1224 if (ret
== ENOSPC
) {
1231 DEBUG(10,("strict_allocate_ftruncate: SMB_VFS_FALLOCATE failed with "
1232 "error %d. Falling back to slow manual allocation\n", ret
));
1234 /* available disk space is enough or not? */
1235 space_avail
= get_dfree_info(fsp
->conn
,
1236 fsp
->fsp_name
->base_name
, false,
1237 &bsize
,&dfree
,&dsize
);
1238 /* space_avail is 1k blocks */
1239 if (space_avail
== (uint64_t)-1 ||
1240 ((uint64_t)space_to_write
/1024 > space_avail
) ) {
1245 /* Write out the real space on disk. */
1246 ret
= vfs_slow_fallocate(fsp
, pst
->st_ex_size
, space_to_write
);
1255 static int vfswrap_ftruncate(vfs_handle_struct
*handle
, files_struct
*fsp
, SMB_OFF_T len
)
1258 SMB_STRUCT_STAT
*pst
;
1262 START_PROFILE(syscall_ftruncate
);
1264 if (lp_strict_allocate(SNUM(fsp
->conn
)) && !fsp
->is_sparse
) {
1265 result
= strict_allocate_ftruncate(handle
, fsp
, len
);
1266 END_PROFILE(syscall_ftruncate
);
1270 /* we used to just check HAVE_FTRUNCATE_EXTEND and only use
1271 sys_ftruncate if the system supports it. Then I discovered that
1272 you can have some filesystems that support ftruncate
1273 expansion and some that don't! On Linux fat can't do
1274 ftruncate extend but ext2 can. */
1276 result
= sys_ftruncate(fsp
->fh
->fd
, len
);
1280 /* According to W. R. Stevens advanced UNIX prog. Pure 4.3 BSD cannot
1281 extend a file with ftruncate. Provide alternate implementation
1284 /* Do an fstat to see if the file is longer than the requested
1285 size in which case the ftruncate above should have
1286 succeeded or shorter, in which case seek to len - 1 and
1287 write 1 byte of zero */
1288 status
= vfs_stat_fsp(fsp
);
1289 if (!NT_STATUS_IS_OK(status
)) {
1292 pst
= &fsp
->fsp_name
->st
;
1295 if (S_ISFIFO(pst
->st_ex_mode
)) {
1301 if (pst
->st_ex_size
== len
) {
1306 if (pst
->st_ex_size
> len
) {
1307 /* the sys_ftruncate should have worked */
1311 if (SMB_VFS_PWRITE(fsp
, &c
, 1, len
-1)!=1) {
1319 END_PROFILE(syscall_ftruncate
);
1323 static int vfswrap_fallocate(vfs_handle_struct
*handle
,
1325 enum vfs_fallocate_mode mode
,
1331 START_PROFILE(syscall_fallocate
);
1332 if (mode
== VFS_FALLOCATE_EXTEND_SIZE
) {
1333 result
= sys_posix_fallocate(fsp
->fh
->fd
, offset
, len
);
1334 } else if (mode
== VFS_FALLOCATE_KEEP_SIZE
) {
1335 result
= sys_fallocate(fsp
->fh
->fd
, mode
, offset
, len
);
1340 END_PROFILE(syscall_fallocate
);
1344 static bool vfswrap_lock(vfs_handle_struct
*handle
, files_struct
*fsp
, int op
, SMB_OFF_T offset
, SMB_OFF_T count
, int type
)
1348 START_PROFILE(syscall_fcntl_lock
);
1349 result
= fcntl_lock(fsp
->fh
->fd
, op
, offset
, count
, type
);
1350 END_PROFILE(syscall_fcntl_lock
);
1354 static int vfswrap_kernel_flock(vfs_handle_struct
*handle
, files_struct
*fsp
,
1355 uint32 share_mode
, uint32 access_mask
)
1357 START_PROFILE(syscall_kernel_flock
);
1358 kernel_flock(fsp
->fh
->fd
, share_mode
, access_mask
);
1359 END_PROFILE(syscall_kernel_flock
);
1363 static bool vfswrap_getlock(vfs_handle_struct
*handle
, files_struct
*fsp
, SMB_OFF_T
*poffset
, SMB_OFF_T
*pcount
, int *ptype
, pid_t
*ppid
)
1367 START_PROFILE(syscall_fcntl_getlock
);
1368 result
= fcntl_getlock(fsp
->fh
->fd
, poffset
, pcount
, ptype
, ppid
);
1369 END_PROFILE(syscall_fcntl_getlock
);
1373 static int vfswrap_linux_setlease(vfs_handle_struct
*handle
, files_struct
*fsp
,
1378 START_PROFILE(syscall_linux_setlease
);
1380 #ifdef HAVE_KERNEL_OPLOCKS_LINUX
1381 /* first set the signal handler */
1382 if(linux_set_lease_sighandler(fsp
->fh
->fd
) == -1) {
1386 result
= linux_setlease(fsp
->fh
->fd
, leasetype
);
1390 END_PROFILE(syscall_linux_setlease
);
1394 static int vfswrap_symlink(vfs_handle_struct
*handle
, const char *oldpath
, const char *newpath
)
1398 START_PROFILE(syscall_symlink
);
1399 result
= symlink(oldpath
, newpath
);
1400 END_PROFILE(syscall_symlink
);
1404 static int vfswrap_readlink(vfs_handle_struct
*handle
, const char *path
, char *buf
, size_t bufsiz
)
1408 START_PROFILE(syscall_readlink
);
1409 result
= readlink(path
, buf
, bufsiz
);
1410 END_PROFILE(syscall_readlink
);
1414 static int vfswrap_link(vfs_handle_struct
*handle
, const char *oldpath
, const char *newpath
)
1418 START_PROFILE(syscall_link
);
1419 result
= link(oldpath
, newpath
);
1420 END_PROFILE(syscall_link
);
1424 static int vfswrap_mknod(vfs_handle_struct
*handle
, const char *pathname
, mode_t mode
, SMB_DEV_T dev
)
1428 START_PROFILE(syscall_mknod
);
1429 result
= sys_mknod(pathname
, mode
, dev
);
1430 END_PROFILE(syscall_mknod
);
1434 static char *vfswrap_realpath(vfs_handle_struct
*handle
, const char *path
)
1438 START_PROFILE(syscall_realpath
);
1439 #ifdef REALPATH_TAKES_NULL
1440 result
= realpath(path
, NULL
);
1442 result
= SMB_MALLOC_ARRAY(char, PATH_MAX
+1);
1444 char *resolved_path
= realpath(path
, result
);
1445 if (!resolved_path
) {
1448 /* SMB_ASSERT(result == resolved_path) ? */
1449 result
= resolved_path
;
1453 END_PROFILE(syscall_realpath
);
1457 static NTSTATUS
vfswrap_notify_watch(vfs_handle_struct
*vfs_handle
,
1458 struct sys_notify_context
*ctx
,
1459 struct notify_entry
*e
,
1460 void (*callback
)(struct sys_notify_context
*ctx
,
1462 struct notify_event
*ev
),
1463 void *private_data
, void *handle
)
1466 * So far inotify is the only supported default notify mechanism. If
1467 * another platform like the the BSD's or a proprietary Unix comes
1468 * along and wants another default, we can play the same trick we
1469 * played with Posix ACLs.
1471 * Until that is the case, hard-code inotify here.
1474 if (lp_kernel_change_notify(ctx
->conn
->params
)) {
1475 return inotify_watch(ctx
, e
, callback
, private_data
, handle
);
1479 * Do nothing, leave everything to notify_internal.c
1481 return NT_STATUS_OK
;
1484 static int vfswrap_chflags(vfs_handle_struct
*handle
, const char *path
,
1488 return chflags(path
, flags
);
1495 static struct file_id
vfswrap_file_id_create(struct vfs_handle_struct
*handle
,
1496 const SMB_STRUCT_STAT
*sbuf
)
1500 /* the ZERO_STRUCT ensures padding doesn't break using the key as a
1504 key
.devid
= sbuf
->st_ex_dev
;
1505 key
.inode
= sbuf
->st_ex_ino
;
1506 /* key.extid is unused by default. */
1511 static NTSTATUS
vfswrap_streaminfo(vfs_handle_struct
*handle
,
1512 struct files_struct
*fsp
,
1514 TALLOC_CTX
*mem_ctx
,
1515 unsigned int *pnum_streams
,
1516 struct stream_struct
**pstreams
)
1518 SMB_STRUCT_STAT sbuf
;
1519 unsigned int num_streams
= 0;
1520 struct stream_struct
*streams
= NULL
;
1523 if ((fsp
!= NULL
) && (fsp
->is_directory
)) {
1525 * No default streams on directories
1530 if ((fsp
!= NULL
) && (fsp
->fh
->fd
!= -1)) {
1531 ret
= SMB_VFS_FSTAT(fsp
, &sbuf
);
1534 struct smb_filename smb_fname
;
1536 ZERO_STRUCT(smb_fname
);
1537 smb_fname
.base_name
= discard_const_p(char, fname
);
1539 if (lp_posix_pathnames()) {
1540 ret
= SMB_VFS_LSTAT(handle
->conn
, &smb_fname
);
1542 ret
= SMB_VFS_STAT(handle
->conn
, &smb_fname
);
1544 sbuf
= smb_fname
.st
;
1548 return map_nt_error_from_unix(errno
);
1551 if (S_ISDIR(sbuf
.st_ex_mode
)) {
1555 streams
= talloc(mem_ctx
, struct stream_struct
);
1557 if (streams
== NULL
) {
1558 return NT_STATUS_NO_MEMORY
;
1561 streams
->size
= sbuf
.st_ex_size
;
1562 streams
->alloc_size
= SMB_VFS_GET_ALLOC_SIZE(handle
->conn
, fsp
, &sbuf
);
1564 streams
->name
= talloc_strdup(streams
, "::$DATA");
1565 if (streams
->name
== NULL
) {
1566 TALLOC_FREE(streams
);
1567 return NT_STATUS_NO_MEMORY
;
1572 *pnum_streams
= num_streams
;
1573 *pstreams
= streams
;
1574 return NT_STATUS_OK
;
1577 static int vfswrap_get_real_filename(struct vfs_handle_struct
*handle
,
1580 TALLOC_CTX
*mem_ctx
,
1584 * Don't fall back to get_real_filename so callers can differentiate
1585 * between a full directory scan and an actual case-insensitive stat.
1591 static const char *vfswrap_connectpath(struct vfs_handle_struct
*handle
,
1594 return handle
->conn
->connectpath
;
1597 static NTSTATUS
vfswrap_brl_lock_windows(struct vfs_handle_struct
*handle
,
1598 struct byte_range_lock
*br_lck
,
1599 struct lock_struct
*plock
,
1601 struct blocking_lock_record
*blr
)
1603 SMB_ASSERT(plock
->lock_flav
== WINDOWS_LOCK
);
1605 /* Note: blr is not used in the default implementation. */
1606 return brl_lock_windows_default(br_lck
, plock
, blocking_lock
);
1609 static bool vfswrap_brl_unlock_windows(struct vfs_handle_struct
*handle
,
1610 struct messaging_context
*msg_ctx
,
1611 struct byte_range_lock
*br_lck
,
1612 const struct lock_struct
*plock
)
1614 SMB_ASSERT(plock
->lock_flav
== WINDOWS_LOCK
);
1616 return brl_unlock_windows_default(msg_ctx
, br_lck
, plock
);
1619 static bool vfswrap_brl_cancel_windows(struct vfs_handle_struct
*handle
,
1620 struct byte_range_lock
*br_lck
,
1621 struct lock_struct
*plock
,
1622 struct blocking_lock_record
*blr
)
1624 SMB_ASSERT(plock
->lock_flav
== WINDOWS_LOCK
);
1626 /* Note: blr is not used in the default implementation. */
1627 return brl_lock_cancel_default(br_lck
, plock
);
1630 static bool vfswrap_strict_lock(struct vfs_handle_struct
*handle
,
1632 struct lock_struct
*plock
)
1634 SMB_ASSERT(plock
->lock_type
== READ_LOCK
||
1635 plock
->lock_type
== WRITE_LOCK
);
1637 return strict_lock_default(fsp
, plock
);
1640 static void vfswrap_strict_unlock(struct vfs_handle_struct
*handle
,
1642 struct lock_struct
*plock
)
1644 SMB_ASSERT(plock
->lock_type
== READ_LOCK
||
1645 plock
->lock_type
== WRITE_LOCK
);
1647 strict_unlock_default(fsp
, plock
);
1650 /* NT ACL operations. */
1652 static NTSTATUS
vfswrap_fget_nt_acl(vfs_handle_struct
*handle
,
1654 uint32 security_info
,
1655 struct security_descriptor
**ppdesc
)
1659 START_PROFILE(fget_nt_acl
);
1660 result
= posix_fget_nt_acl(fsp
, security_info
, ppdesc
);
1661 END_PROFILE(fget_nt_acl
);
1665 static NTSTATUS
vfswrap_get_nt_acl(vfs_handle_struct
*handle
,
1667 uint32 security_info
,
1668 struct security_descriptor
**ppdesc
)
1672 START_PROFILE(get_nt_acl
);
1673 result
= posix_get_nt_acl(handle
->conn
, name
, security_info
, ppdesc
);
1674 END_PROFILE(get_nt_acl
);
1678 static NTSTATUS
vfswrap_fset_nt_acl(vfs_handle_struct
*handle
, files_struct
*fsp
, uint32 security_info_sent
, const struct security_descriptor
*psd
)
1682 START_PROFILE(fset_nt_acl
);
1683 result
= set_nt_acl(fsp
, security_info_sent
, psd
);
1684 END_PROFILE(fset_nt_acl
);
1688 static int vfswrap_chmod_acl(vfs_handle_struct
*handle
, const char *name
, mode_t mode
)
1696 START_PROFILE(chmod_acl
);
1697 result
= chmod_acl(handle
->conn
, name
, mode
);
1698 END_PROFILE(chmod_acl
);
1703 static int vfswrap_fchmod_acl(vfs_handle_struct
*handle
, files_struct
*fsp
, mode_t mode
)
1711 START_PROFILE(fchmod_acl
);
1712 result
= fchmod_acl(fsp
, mode
);
1713 END_PROFILE(fchmod_acl
);
1718 static int vfswrap_sys_acl_get_entry(vfs_handle_struct
*handle
, SMB_ACL_T theacl
, int entry_id
, SMB_ACL_ENTRY_T
*entry_p
)
1720 return sys_acl_get_entry(theacl
, entry_id
, entry_p
);
1723 static int vfswrap_sys_acl_get_tag_type(vfs_handle_struct
*handle
, SMB_ACL_ENTRY_T entry_d
, SMB_ACL_TAG_T
*tag_type_p
)
1725 return sys_acl_get_tag_type(entry_d
, tag_type_p
);
1728 static int vfswrap_sys_acl_get_permset(vfs_handle_struct
*handle
, SMB_ACL_ENTRY_T entry_d
, SMB_ACL_PERMSET_T
*permset_p
)
1730 return sys_acl_get_permset(entry_d
, permset_p
);
1733 static void * vfswrap_sys_acl_get_qualifier(vfs_handle_struct
*handle
, SMB_ACL_ENTRY_T entry_d
)
1735 return sys_acl_get_qualifier(entry_d
);
1738 static SMB_ACL_T
vfswrap_sys_acl_get_file(vfs_handle_struct
*handle
, const char *path_p
, SMB_ACL_TYPE_T type
)
1740 return sys_acl_get_file(handle
, path_p
, type
);
1743 static SMB_ACL_T
vfswrap_sys_acl_get_fd(vfs_handle_struct
*handle
, files_struct
*fsp
)
1745 return sys_acl_get_fd(handle
, fsp
);
1748 static int vfswrap_sys_acl_clear_perms(vfs_handle_struct
*handle
, SMB_ACL_PERMSET_T permset
)
1750 return sys_acl_clear_perms(permset
);
1753 static int vfswrap_sys_acl_add_perm(vfs_handle_struct
*handle
, SMB_ACL_PERMSET_T permset
, SMB_ACL_PERM_T perm
)
1755 return sys_acl_add_perm(permset
, perm
);
1758 static char * vfswrap_sys_acl_to_text(vfs_handle_struct
*handle
, SMB_ACL_T theacl
, ssize_t
*plen
)
1760 return sys_acl_to_text(theacl
, plen
);
1763 static SMB_ACL_T
vfswrap_sys_acl_init(vfs_handle_struct
*handle
, int count
)
1765 return sys_acl_init(count
);
1768 static int vfswrap_sys_acl_create_entry(vfs_handle_struct
*handle
, SMB_ACL_T
*pacl
, SMB_ACL_ENTRY_T
*pentry
)
1770 return sys_acl_create_entry(pacl
, pentry
);
1773 static int vfswrap_sys_acl_set_tag_type(vfs_handle_struct
*handle
, SMB_ACL_ENTRY_T entry
, SMB_ACL_TAG_T tagtype
)
1775 return sys_acl_set_tag_type(entry
, tagtype
);
1778 static int vfswrap_sys_acl_set_qualifier(vfs_handle_struct
*handle
, SMB_ACL_ENTRY_T entry
, void *qual
)
1780 return sys_acl_set_qualifier(entry
, qual
);
1783 static int vfswrap_sys_acl_set_permset(vfs_handle_struct
*handle
, SMB_ACL_ENTRY_T entry
, SMB_ACL_PERMSET_T permset
)
1785 return sys_acl_set_permset(entry
, permset
);
1788 static int vfswrap_sys_acl_valid(vfs_handle_struct
*handle
, SMB_ACL_T theacl
)
1790 return sys_acl_valid(theacl
);
1793 static int vfswrap_sys_acl_set_file(vfs_handle_struct
*handle
, const char *name
, SMB_ACL_TYPE_T acltype
, SMB_ACL_T theacl
)
1795 return sys_acl_set_file(handle
, name
, acltype
, theacl
);
1798 static int vfswrap_sys_acl_set_fd(vfs_handle_struct
*handle
, files_struct
*fsp
, SMB_ACL_T theacl
)
1800 return sys_acl_set_fd(handle
, fsp
, theacl
);
1803 static int vfswrap_sys_acl_delete_def_file(vfs_handle_struct
*handle
, const char *path
)
1805 return sys_acl_delete_def_file(handle
, path
);
1808 static int vfswrap_sys_acl_get_perm(vfs_handle_struct
*handle
, SMB_ACL_PERMSET_T permset
, SMB_ACL_PERM_T perm
)
1810 return sys_acl_get_perm(permset
, perm
);
1813 static int vfswrap_sys_acl_free_text(vfs_handle_struct
*handle
, char *text
)
1815 return sys_acl_free_text(text
);
1818 static int vfswrap_sys_acl_free_acl(vfs_handle_struct
*handle
, SMB_ACL_T posix_acl
)
1820 return sys_acl_free_acl(posix_acl
);
1823 static int vfswrap_sys_acl_free_qualifier(vfs_handle_struct
*handle
, void *qualifier
, SMB_ACL_TAG_T tagtype
)
1825 return sys_acl_free_qualifier(qualifier
, tagtype
);
1828 /****************************************************************
1829 Extended attribute operations.
1830 *****************************************************************/
1832 static ssize_t
vfswrap_getxattr(struct vfs_handle_struct
*handle
,const char *path
, const char *name
, void *value
, size_t size
)
1834 return sys_getxattr(path
, name
, value
, size
);
1837 static ssize_t
vfswrap_lgetxattr(struct vfs_handle_struct
*handle
,const char *path
, const char *name
, void *value
, size_t size
)
1839 return sys_lgetxattr(path
, name
, value
, size
);
1842 static ssize_t
vfswrap_fgetxattr(struct vfs_handle_struct
*handle
, struct files_struct
*fsp
, const char *name
, void *value
, size_t size
)
1844 return sys_fgetxattr(fsp
->fh
->fd
, name
, value
, size
);
1847 static ssize_t
vfswrap_listxattr(struct vfs_handle_struct
*handle
, const char *path
, char *list
, size_t size
)
1849 return sys_listxattr(path
, list
, size
);
1852 static ssize_t
vfswrap_llistxattr(struct vfs_handle_struct
*handle
, const char *path
, char *list
, size_t size
)
1854 return sys_llistxattr(path
, list
, size
);
1857 static ssize_t
vfswrap_flistxattr(struct vfs_handle_struct
*handle
, struct files_struct
*fsp
, char *list
, size_t size
)
1859 return sys_flistxattr(fsp
->fh
->fd
, list
, size
);
1862 static int vfswrap_removexattr(struct vfs_handle_struct
*handle
, const char *path
, const char *name
)
1864 return sys_removexattr(path
, name
);
1867 static int vfswrap_lremovexattr(struct vfs_handle_struct
*handle
, const char *path
, const char *name
)
1869 return sys_lremovexattr(path
, name
);
1872 static int vfswrap_fremovexattr(struct vfs_handle_struct
*handle
, struct files_struct
*fsp
, const char *name
)
1874 return sys_fremovexattr(fsp
->fh
->fd
, name
);
1877 static int vfswrap_setxattr(struct vfs_handle_struct
*handle
, const char *path
, const char *name
, const void *value
, size_t size
, int flags
)
1879 return sys_setxattr(path
, name
, value
, size
, flags
);
1882 static int vfswrap_lsetxattr(struct vfs_handle_struct
*handle
, const char *path
, const char *name
, const void *value
, size_t size
, int flags
)
1884 return sys_lsetxattr(path
, name
, value
, size
, flags
);
1887 static int vfswrap_fsetxattr(struct vfs_handle_struct
*handle
, struct files_struct
*fsp
, const char *name
, const void *value
, size_t size
, int flags
)
1889 return sys_fsetxattr(fsp
->fh
->fd
, name
, value
, size
, flags
);
1892 static int vfswrap_aio_read(struct vfs_handle_struct
*handle
, struct files_struct
*fsp
, SMB_STRUCT_AIOCB
*aiocb
)
1896 * aio_read must be done as root, because in the glibc aio
1897 * implementation the helper thread needs to be able to send a signal
1898 * to the main thread, even when it has done a seteuid() to a
1902 ret
= sys_aio_read(aiocb
);
1907 static int vfswrap_aio_write(struct vfs_handle_struct
*handle
, struct files_struct
*fsp
, SMB_STRUCT_AIOCB
*aiocb
)
1911 * aio_write must be done as root, because in the glibc aio
1912 * implementation the helper thread needs to be able to send a signal
1913 * to the main thread, even when it has done a seteuid() to a
1917 ret
= sys_aio_write(aiocb
);
1922 static ssize_t
vfswrap_aio_return(struct vfs_handle_struct
*handle
, struct files_struct
*fsp
, SMB_STRUCT_AIOCB
*aiocb
)
1924 return sys_aio_return(aiocb
);
1927 static int vfswrap_aio_cancel(struct vfs_handle_struct
*handle
, struct files_struct
*fsp
, SMB_STRUCT_AIOCB
*aiocb
)
1929 return sys_aio_cancel(fsp
->fh
->fd
, aiocb
);
1932 static int vfswrap_aio_error(struct vfs_handle_struct
*handle
, struct files_struct
*fsp
, SMB_STRUCT_AIOCB
*aiocb
)
1934 return sys_aio_error(aiocb
);
1937 static int vfswrap_aio_fsync(struct vfs_handle_struct
*handle
, struct files_struct
*fsp
, int op
, SMB_STRUCT_AIOCB
*aiocb
)
1939 return sys_aio_fsync(op
, aiocb
);
1942 static int vfswrap_aio_suspend(struct vfs_handle_struct
*handle
, struct files_struct
*fsp
, const SMB_STRUCT_AIOCB
* const aiocb
[], int n
, const struct timespec
*timeout
)
1944 return sys_aio_suspend(aiocb
, n
, timeout
);
1947 static bool vfswrap_aio_force(struct vfs_handle_struct
*handle
, struct files_struct
*fsp
)
1952 static bool vfswrap_is_offline(struct vfs_handle_struct
*handle
,
1953 const struct smb_filename
*fname
,
1954 SMB_STRUCT_STAT
*sbuf
)
1958 bool offline
= false;
1960 if (ISDOT(fname
->base_name
) || ISDOTDOT(fname
->base_name
)) {
1964 if (!lp_dmapi_support(SNUM(handle
->conn
)) || !dmapi_have_session()) {
1965 #if defined(ENOTSUP)
1971 status
= get_full_smb_filename(talloc_tos(), fname
, &path
);
1972 if (!NT_STATUS_IS_OK(status
)) {
1973 errno
= map_errno_from_nt_status(status
);
1977 offline
= (dmapi_file_flags(path
) & FILE_ATTRIBUTE_OFFLINE
) != 0;
1984 static int vfswrap_set_offline(struct vfs_handle_struct
*handle
,
1985 const struct smb_filename
*fname
)
1987 /* We don't know how to set offline bit by default, needs to be overriden in the vfs modules */
1988 #if defined(ENOTSUP)
1994 static struct vfs_fn_pointers vfs_default_fns
= {
1995 /* Disk operations */
1997 .connect_fn
= vfswrap_connect
,
1998 .disconnect
= vfswrap_disconnect
,
1999 .disk_free
= vfswrap_disk_free
,
2000 .get_quota
= vfswrap_get_quota
,
2001 .set_quota
= vfswrap_set_quota
,
2002 .get_shadow_copy_data
= vfswrap_get_shadow_copy_data
,
2003 .statvfs
= vfswrap_statvfs
,
2004 .fs_capabilities
= vfswrap_fs_capabilities
,
2006 /* Directory operations */
2008 .opendir
= vfswrap_opendir
,
2009 .fdopendir
= vfswrap_fdopendir
,
2010 .readdir
= vfswrap_readdir
,
2011 .seekdir
= vfswrap_seekdir
,
2012 .telldir
= vfswrap_telldir
,
2013 .rewind_dir
= vfswrap_rewinddir
,
2014 .mkdir
= vfswrap_mkdir
,
2015 .rmdir
= vfswrap_rmdir
,
2016 .closedir
= vfswrap_closedir
,
2017 .init_search_op
= vfswrap_init_search_op
,
2019 /* File operations */
2021 .open_fn
= vfswrap_open
,
2022 .create_file
= vfswrap_create_file
,
2023 .close_fn
= vfswrap_close
,
2024 .vfs_read
= vfswrap_read
,
2025 .pread
= vfswrap_pread
,
2026 .write
= vfswrap_write
,
2027 .pwrite
= vfswrap_pwrite
,
2028 .lseek
= vfswrap_lseek
,
2029 .sendfile
= vfswrap_sendfile
,
2030 .recvfile
= vfswrap_recvfile
,
2031 .rename
= vfswrap_rename
,
2032 .fsync
= vfswrap_fsync
,
2033 .stat
= vfswrap_stat
,
2034 .fstat
= vfswrap_fstat
,
2035 .lstat
= vfswrap_lstat
,
2036 .get_alloc_size
= vfswrap_get_alloc_size
,
2037 .unlink
= vfswrap_unlink
,
2038 .chmod
= vfswrap_chmod
,
2039 .fchmod
= vfswrap_fchmod
,
2040 .chown
= vfswrap_chown
,
2041 .fchown
= vfswrap_fchown
,
2042 .lchown
= vfswrap_lchown
,
2043 .chdir
= vfswrap_chdir
,
2044 .getwd
= vfswrap_getwd
,
2045 .ntimes
= vfswrap_ntimes
,
2046 .ftruncate
= vfswrap_ftruncate
,
2047 .fallocate
= vfswrap_fallocate
,
2048 .lock
= vfswrap_lock
,
2049 .kernel_flock
= vfswrap_kernel_flock
,
2050 .linux_setlease
= vfswrap_linux_setlease
,
2051 .getlock
= vfswrap_getlock
,
2052 .symlink
= vfswrap_symlink
,
2053 .vfs_readlink
= vfswrap_readlink
,
2054 .link
= vfswrap_link
,
2055 .mknod
= vfswrap_mknod
,
2056 .realpath
= vfswrap_realpath
,
2057 .notify_watch
= vfswrap_notify_watch
,
2058 .chflags
= vfswrap_chflags
,
2059 .file_id_create
= vfswrap_file_id_create
,
2060 .streaminfo
= vfswrap_streaminfo
,
2061 .get_real_filename
= vfswrap_get_real_filename
,
2062 .connectpath
= vfswrap_connectpath
,
2063 .brl_lock_windows
= vfswrap_brl_lock_windows
,
2064 .brl_unlock_windows
= vfswrap_brl_unlock_windows
,
2065 .brl_cancel_windows
= vfswrap_brl_cancel_windows
,
2066 .strict_lock
= vfswrap_strict_lock
,
2067 .strict_unlock
= vfswrap_strict_unlock
,
2068 .translate_name
= vfswrap_translate_name
,
2069 .fsctl
= vfswrap_fsctl
,
2071 /* NT ACL operations. */
2073 .fget_nt_acl
= vfswrap_fget_nt_acl
,
2074 .get_nt_acl
= vfswrap_get_nt_acl
,
2075 .fset_nt_acl
= vfswrap_fset_nt_acl
,
2077 /* POSIX ACL operations. */
2079 .chmod_acl
= vfswrap_chmod_acl
,
2080 .fchmod_acl
= vfswrap_fchmod_acl
,
2082 .sys_acl_get_entry
= vfswrap_sys_acl_get_entry
,
2083 .sys_acl_get_tag_type
= vfswrap_sys_acl_get_tag_type
,
2084 .sys_acl_get_permset
= vfswrap_sys_acl_get_permset
,
2085 .sys_acl_get_qualifier
= vfswrap_sys_acl_get_qualifier
,
2086 .sys_acl_get_file
= vfswrap_sys_acl_get_file
,
2087 .sys_acl_get_fd
= vfswrap_sys_acl_get_fd
,
2088 .sys_acl_clear_perms
= vfswrap_sys_acl_clear_perms
,
2089 .sys_acl_add_perm
= vfswrap_sys_acl_add_perm
,
2090 .sys_acl_to_text
= vfswrap_sys_acl_to_text
,
2091 .sys_acl_init
= vfswrap_sys_acl_init
,
2092 .sys_acl_create_entry
= vfswrap_sys_acl_create_entry
,
2093 .sys_acl_set_tag_type
= vfswrap_sys_acl_set_tag_type
,
2094 .sys_acl_set_qualifier
= vfswrap_sys_acl_set_qualifier
,
2095 .sys_acl_set_permset
= vfswrap_sys_acl_set_permset
,
2096 .sys_acl_valid
= vfswrap_sys_acl_valid
,
2097 .sys_acl_set_file
= vfswrap_sys_acl_set_file
,
2098 .sys_acl_set_fd
= vfswrap_sys_acl_set_fd
,
2099 .sys_acl_delete_def_file
= vfswrap_sys_acl_delete_def_file
,
2100 .sys_acl_get_perm
= vfswrap_sys_acl_get_perm
,
2101 .sys_acl_free_text
= vfswrap_sys_acl_free_text
,
2102 .sys_acl_free_acl
= vfswrap_sys_acl_free_acl
,
2103 .sys_acl_free_qualifier
= vfswrap_sys_acl_free_qualifier
,
2105 /* EA operations. */
2106 .getxattr
= vfswrap_getxattr
,
2107 .lgetxattr
= vfswrap_lgetxattr
,
2108 .fgetxattr
= vfswrap_fgetxattr
,
2109 .listxattr
= vfswrap_listxattr
,
2110 .llistxattr
= vfswrap_llistxattr
,
2111 .flistxattr
= vfswrap_flistxattr
,
2112 .removexattr
= vfswrap_removexattr
,
2113 .lremovexattr
= vfswrap_lremovexattr
,
2114 .fremovexattr
= vfswrap_fremovexattr
,
2115 .setxattr
= vfswrap_setxattr
,
2116 .lsetxattr
= vfswrap_lsetxattr
,
2117 .fsetxattr
= vfswrap_fsetxattr
,
2119 /* aio operations */
2120 .aio_read
= vfswrap_aio_read
,
2121 .aio_write
= vfswrap_aio_write
,
2122 .aio_return_fn
= vfswrap_aio_return
,
2123 .aio_cancel
= vfswrap_aio_cancel
,
2124 .aio_error_fn
= vfswrap_aio_error
,
2125 .aio_fsync
= vfswrap_aio_fsync
,
2126 .aio_suspend
= vfswrap_aio_suspend
,
2127 .aio_force
= vfswrap_aio_force
,
2129 /* offline operations */
2130 .is_offline
= vfswrap_is_offline
,
2131 .set_offline
= vfswrap_set_offline
2134 NTSTATUS
vfs_default_init(void);
2135 NTSTATUS
vfs_default_init(void)
2137 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
,
2138 DEFAULT_VFS_MODULE_NAME
, &vfs_default_fns
);