Pass the get_real_filename operation through the VFS
[kai/samba.git] / source3 / modules / vfs_default.c
index e21136ccee9e0a10ef5464f0b54a87deb0a9dd40..8fa8f6ae0671bc51b9467dd2b078da702a8cf42b 100644 (file)
@@ -40,10 +40,10 @@ static void vfswrap_disconnect(vfs_handle_struct *handle)
 
 /* Disk operations */
 
-static SMB_BIG_UINT vfswrap_disk_free(vfs_handle_struct *handle,  const char *path, bool small_query, SMB_BIG_UINT *bsize,
-                              SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)
+static uint64_t vfswrap_disk_free(vfs_handle_struct *handle,  const char *path, bool small_query, uint64_t *bsize,
+                              uint64_t *dfree, uint64_t *dsize)
 {
-       SMB_BIG_UINT result;
+       uint64_t result;
 
        result = sys_disk_free(handle->conn, path, small_query, bsize, dfree, dsize);
        return result;
@@ -90,6 +90,17 @@ static int vfswrap_statvfs(struct vfs_handle_struct *handle,  const char *path,
        return sys_statvfs(path, statbuf);
 }
 
+static uint32_t vfswrap_fs_capabilities(struct vfs_handle_struct *handle)
+{
+#if defined(DARWINOS)
+       struct vfs_statvfs_struct statbuf;
+       ZERO_STRUCT(statbuf);
+       sys_statvfs(handle->conn->connectpath, &statbuf);
+       return statbuf.FsCapabilities;
+#endif
+       return FILE_CASE_SENSITIVE_SEARCH | FILE_CASE_PRESERVED_NAMES;
+}
+
 /* Directory operations */
 
 static SMB_STRUCT_DIR *vfswrap_opendir(vfs_handle_struct *handle,  const char *fname, const char *mask, uint32 attr)
@@ -197,13 +208,38 @@ static int vfswrap_open(vfs_handle_struct *handle,  const char *fname,
        return result;
 }
 
-static int vfswrap_close(vfs_handle_struct *handle, files_struct *fsp, int fd)
+static NTSTATUS vfswrap_create_file(vfs_handle_struct *handle,
+                                   struct smb_request *req,
+                                   uint16_t root_dir_fid,
+                                   const char *fname,
+                                   uint32_t create_file_flags,
+                                   uint32_t access_mask,
+                                   uint32_t share_access,
+                                   uint32_t create_disposition,
+                                   uint32_t create_options,
+                                   uint32_t file_attributes,
+                                   uint32_t oplock_request,
+                                   uint64_t allocation_size,
+                                   struct security_descriptor *sd,
+                                   struct ea_list *ea_list,
+                                   files_struct **result,
+                                   int *pinfo,
+                                   SMB_STRUCT_STAT *psbuf)
+{
+       return create_file_default(handle->conn, req, root_dir_fid, fname,
+                                  create_file_flags, access_mask, share_access,
+                                  create_disposition, create_options,
+                                  file_attributes, oplock_request,
+                                  allocation_size, sd, ea_list, result, pinfo,
+                                  psbuf);
+}
+
+static int vfswrap_close(vfs_handle_struct *handle, files_struct *fsp)
 {
        int result;
 
        START_PROFILE(syscall_close);
-
-       result = close(fd);
+       result = fd_close_posix(fsp);
        END_PROFILE(syscall_close);
        return result;
 }
@@ -457,7 +493,7 @@ static int vfswrap_rename(vfs_handle_struct *handle,  const char *oldname, const
 
        START_PROFILE(syscall_rename);
        result = rename(oldname, newname);
-       if (errno == EXDEV) {
+       if ((result == -1) && (errno == EXDEV)) {
                /* Rename across filesystems needed. */
                result = copy_reg(oldname, newname);
        }
@@ -586,7 +622,7 @@ static int vfswrap_chown(vfs_handle_struct *handle, const char *path, uid_t uid,
        int result;
 
        START_PROFILE(syscall_chown);
-       result = sys_chown(path, uid, gid);
+       result = chown(path, uid, gid);
        END_PROFILE(syscall_chown);
        return result;
 }
@@ -611,7 +647,7 @@ static int vfswrap_lchown(vfs_handle_struct *handle, const char *path, uid_t uid
        int result;
 
        START_PROFILE(syscall_lchown);
-       result = sys_lchown(path, uid, gid);
+       result = lchown(path, uid, gid);
        END_PROFILE(syscall_lchown);
        return result;
 }
@@ -647,18 +683,22 @@ static int vfswrap_ntimes(vfs_handle_struct *handle, const char *path, const str
 
        START_PROFILE(syscall_ntimes);
 #if defined(HAVE_UTIMES)
-       {
+       if (ts != NULL) {
                struct timeval tv[2];
                tv[0] = convert_timespec_to_timeval(ts[0]);
                tv[1] = convert_timespec_to_timeval(ts[1]);
                result = utimes(path, tv);
+       } else {
+               result = utimes(path, NULL);
        }
 #elif defined(HAVE_UTIME)
-       {
+       if (ts != NULL) {
                struct utimbuf times;
                times.actime = convert_timespec_to_time_t(ts[0]);
                times.modtime = convert_timespec_to_time_t(ts[1]);
                result = utime(path, times);
+       } else {
+               result = utime(path, NULL);
        }
 #else
        errno = ENOSYS;
@@ -855,7 +895,7 @@ static int vfswrap_symlink(vfs_handle_struct *handle,  const char *oldpath, cons
        int result;
 
        START_PROFILE(syscall_symlink);
-       result = sys_symlink(oldpath, newpath);
+       result = symlink(oldpath, newpath);
        END_PROFILE(syscall_symlink);
        return result;
 }
@@ -865,7 +905,7 @@ static int vfswrap_readlink(vfs_handle_struct *handle,  const char *path, char *
        int result;
 
        START_PROFILE(syscall_readlink);
-       result = sys_readlink(path, buf, bufsiz);
+       result = readlink(path, buf, bufsiz);
        END_PROFILE(syscall_readlink);
        return result;
 }
@@ -875,7 +915,7 @@ static int vfswrap_link(vfs_handle_struct *handle,  const char *oldpath, const c
        int result;
 
        START_PROFILE(syscall_link);
-       result = sys_link(oldpath, newpath);
+       result = link(oldpath, newpath);
        END_PROFILE(syscall_link);
        return result;
 }
@@ -895,7 +935,7 @@ static char *vfswrap_realpath(vfs_handle_struct *handle,  const char *path, char
        char *result;
 
        START_PROFILE(syscall_realpath);
-       result = sys_realpath(path, resolved_path);
+       result = realpath(path, resolved_path);
        END_PROFILE(syscall_realpath);
        return result;
 }
@@ -942,6 +982,72 @@ static struct file_id vfswrap_file_id_create(struct vfs_handle_struct *handle, S
        return file_id_create_dev(dev, inode);
 }
 
+static NTSTATUS vfswrap_streaminfo(vfs_handle_struct *handle,
+                                  struct files_struct *fsp,
+                                  const char *fname,
+                                  TALLOC_CTX *mem_ctx,
+                                  unsigned int *pnum_streams,
+                                  struct stream_struct **pstreams)
+{
+       SMB_STRUCT_STAT sbuf;
+       unsigned int num_streams = 0;
+       struct stream_struct *streams = NULL;
+       int ret;
+
+       if ((fsp != NULL) && (fsp->is_directory)) {
+               /*
+                * No default streams on directories
+                */
+               goto done;
+       }
+
+       if ((fsp != NULL) && (fsp->fh->fd != -1)) {
+               ret = SMB_VFS_FSTAT(fsp, &sbuf);
+       }
+       else {
+               ret = SMB_VFS_STAT(handle->conn, fname, &sbuf);
+       }
+
+       if (ret == -1) {
+               return map_nt_error_from_unix(errno);
+       }
+
+       if (S_ISDIR(sbuf.st_mode)) {
+               goto done;
+       }
+
+       streams = talloc(mem_ctx, struct stream_struct);
+
+       if (streams == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       streams->size = sbuf.st_size;
+       streams->alloc_size = get_allocation_size(handle->conn, fsp, &sbuf);
+
+       streams->name = talloc_strdup(streams, "::$DATA");
+       if (streams->name == NULL) {
+               TALLOC_FREE(streams);
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       num_streams = 1;
+ done:
+       *pnum_streams = num_streams;
+       *pstreams = streams;
+       return NT_STATUS_OK;
+}
+
+static int vfswrap_get_real_filename(struct vfs_handle_struct *handle,
+                                    const char *path,
+                                    const char *name,
+                                    TALLOC_CTX *mem_ctx,
+                                    char **found_name)
+{
+       return get_real_filename(handle->conn, path, name, mem_ctx,
+                                found_name);
+}
+
 static NTSTATUS vfswrap_fget_nt_acl(vfs_handle_struct *handle,
                                    files_struct *fsp,
                                    uint32 security_info, SEC_DESC **ppdesc)
@@ -966,7 +1072,7 @@ static NTSTATUS vfswrap_get_nt_acl(vfs_handle_struct *handle,
        return result;
 }
 
-static NTSTATUS vfswrap_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp, uint32 security_info_sent, SEC_DESC *psd)
+static NTSTATUS vfswrap_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp, uint32 security_info_sent, const SEC_DESC *psd)
 {
        NTSTATUS result;
 
@@ -976,16 +1082,6 @@ static NTSTATUS vfswrap_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp
        return result;
 }
 
-static NTSTATUS vfswrap_set_nt_acl(vfs_handle_struct *handle, files_struct *fsp, const char *name, uint32 security_info_sent, SEC_DESC *psd)
-{
-       NTSTATUS result;
-
-       START_PROFILE(set_nt_acl);
-       result = set_nt_acl(fsp, security_info_sent, psd);
-       END_PROFILE(set_nt_acl);
-       return result;
-}
-
 static int vfswrap_chmod_acl(vfs_handle_struct *handle,  const char *name, mode_t mode)
 {
 #ifdef HAVE_NO_ACL
@@ -1225,6 +1321,36 @@ static int vfswrap_aio_suspend(struct vfs_handle_struct *handle, struct files_st
        return sys_aio_suspend(aiocb, n, timeout);
 }
 
+static bool vfswrap_aio_force(struct vfs_handle_struct *handle, struct files_struct *fsp)
+{
+       return false;
+}
+
+static bool vfswrap_is_offline(struct vfs_handle_struct *handle, const char *path, SMB_STRUCT_STAT *sbuf)
+{
+       if (ISDOT(path) || ISDOTDOT(path)) {
+               return false;
+       }
+
+       if (!lp_dmapi_support(SNUM(handle->conn)) || !dmapi_have_session()) {
+#if defined(ENOTSUP)
+               errno = ENOTSUP;
+#endif
+               return false;
+       }
+
+       return (dmapi_file_flags(path) & FILE_ATTRIBUTE_OFFLINE) != 0;
+}
+
+static int vfswrap_set_offline(struct vfs_handle_struct *handle, const char *path)
+{
+       /* We don't know how to set offline bit by default, needs to be overriden in the vfs modules */
+#if defined(ENOTSUP)
+       errno = ENOTSUP;
+#endif
+       return -1;
+}
+
 static vfs_op_tuple vfs_default_ops[] = {
 
        /* Disk operations */
@@ -1243,6 +1369,8 @@ static vfs_op_tuple vfs_default_ops[] = {
         SMB_VFS_LAYER_OPAQUE},
        {SMB_VFS_OP(vfswrap_statvfs),   SMB_VFS_OP_STATVFS,
         SMB_VFS_LAYER_OPAQUE},
+       {SMB_VFS_OP(vfswrap_fs_capabilities), SMB_VFS_OP_FS_CAPABILITIES,
+        SMB_VFS_LAYER_OPAQUE},
 
        /* Directory operations */
 
@@ -1267,6 +1395,8 @@ static vfs_op_tuple vfs_default_ops[] = {
 
        {SMB_VFS_OP(vfswrap_open),      SMB_VFS_OP_OPEN,
         SMB_VFS_LAYER_OPAQUE},
+       {SMB_VFS_OP(vfswrap_create_file),       SMB_VFS_OP_CREATE_FILE,
+        SMB_VFS_LAYER_OPAQUE},
        {SMB_VFS_OP(vfswrap_close),     SMB_VFS_OP_CLOSE,
         SMB_VFS_LAYER_OPAQUE},
        {SMB_VFS_OP(vfswrap_read),      SMB_VFS_OP_READ,
@@ -1337,6 +1467,10 @@ static vfs_op_tuple vfs_default_ops[] = {
         SMB_VFS_LAYER_OPAQUE},
        {SMB_VFS_OP(vfswrap_file_id_create),    SMB_VFS_OP_FILE_ID_CREATE,
         SMB_VFS_LAYER_OPAQUE},
+       {SMB_VFS_OP(vfswrap_streaminfo),        SMB_VFS_OP_STREAMINFO,
+        SMB_VFS_LAYER_OPAQUE},
+       {SMB_VFS_OP(vfswrap_get_real_filename), SMB_VFS_OP_GET_REAL_FILENAME,
+        SMB_VFS_LAYER_OPAQUE},
 
        /* NT ACL operations. */
 
@@ -1346,8 +1480,6 @@ static vfs_op_tuple vfs_default_ops[] = {
         SMB_VFS_LAYER_OPAQUE},
        {SMB_VFS_OP(vfswrap_fset_nt_acl),       SMB_VFS_OP_FSET_NT_ACL,
         SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_set_nt_acl),        SMB_VFS_OP_SET_NT_ACL,
-        SMB_VFS_LAYER_OPAQUE},
 
        /* POSIX ACL operations. */
 
@@ -1442,6 +1574,14 @@ static vfs_op_tuple vfs_default_ops[] = {
        {SMB_VFS_OP(vfswrap_aio_suspend),SMB_VFS_OP_AIO_SUSPEND,
         SMB_VFS_LAYER_OPAQUE},
 
+       {SMB_VFS_OP(vfswrap_aio_force), SMB_VFS_OP_AIO_FORCE,
+        SMB_VFS_LAYER_OPAQUE},
+
+       {SMB_VFS_OP(vfswrap_is_offline),SMB_VFS_OP_IS_OFFLINE,
+        SMB_VFS_LAYER_OPAQUE},
+       {SMB_VFS_OP(vfswrap_set_offline),SMB_VFS_OP_SET_OFFLINE,
+        SMB_VFS_LAYER_OPAQUE},
+
        /* Finish VFS operations definition */
 
        {SMB_VFS_OP(NULL),              SMB_VFS_OP_NOOP,