smbd: add twrp arg to synthetic_smb_fname()
[amitay/samba.git] / source3 / modules / vfs_default.c
index b64071d6870c620fae219624bcd92db6aa57b19b..bfc84e1d20b5b717a41cda5ad89fce49860a9733 100644 (file)
@@ -131,8 +131,12 @@ static uint32_t vfswrap_fs_capabilities(struct vfs_handle_struct *handle,
        struct vfs_statvfs_struct statbuf;
        int ret;
 
-       smb_fname_cpath = synthetic_smb_fname(talloc_tos(), conn->connectpath,
-                                             NULL, NULL, 0);
+       smb_fname_cpath = synthetic_smb_fname(talloc_tos(),
+                                             conn->connectpath,
+                                             NULL,
+                                             NULL,
+                                             0,
+                                             0);
        if (smb_fname_cpath == NULL) {
                return caps;
        }
@@ -535,19 +539,6 @@ static NTSTATUS vfswrap_snap_delete(struct vfs_handle_struct *handle,
 
 /* Directory operations */
 
-static DIR *vfswrap_opendir(vfs_handle_struct *handle,
-                               const struct smb_filename *smb_fname,
-                               const char *mask,
-                               uint32_t attr)
-{
-       DIR *result;
-
-       START_PROFILE(syscall_opendir);
-       result = opendir(smb_fname->base_name);
-       END_PROFILE(syscall_opendir);
-       return result;
-}
-
 static DIR *vfswrap_fdopendir(vfs_handle_struct *handle,
                        files_struct *fsp,
                        const char *mask,
@@ -641,22 +632,26 @@ static int vfswrap_mkdirat(vfs_handle_struct *handle,
                        mode_t mode)
 {
        int result;
-       const char *path = smb_fname->base_name;
-       char *parent = NULL;
+       struct smb_filename *parent = NULL;
+       bool ok;
 
        START_PROFILE(syscall_mkdirat);
 
        SMB_ASSERT(dirfsp == dirfsp->conn->cwd_fsp);
 
-       if (lp_inherit_acls(SNUM(handle->conn))
-           && parent_dirname(talloc_tos(), path, &parent, NULL)
-           && directory_has_default_acl(handle->conn, parent)) {
-               mode = (0777 & lp_directory_mask(SNUM(handle->conn)));
+       if (lp_inherit_acls(SNUM(handle->conn))) {
+               ok = parent_smb_fname(talloc_tos(), smb_fname, &parent, NULL);
+               if (ok && directory_has_default_acl(handle->conn,
+                               dirfsp,
+                               parent))
+               {
+                       mode = (0777 & lp_directory_mask(SNUM(handle->conn)));
+               }
        }
 
        TALLOC_FREE(parent);
 
-       result = mkdirat(dirfsp->fh->fd, path, mode);
+       result = mkdirat(dirfsp->fh->fd, smb_fname->base_name, mode);
 
        END_PROFILE(syscall_mkdirat);
        return result;
@@ -1719,6 +1714,12 @@ static void vfswrap_get_dos_attributes_getxattr_done(struct tevent_req *subreq)
                struct vfswrap_get_dos_attributes_state);
        ssize_t xattr_size;
        DATA_BLOB blob = {0};
+       char *path = NULL;
+       char *tofree = NULL;
+       char pathbuf[PATH_MAX+1];
+       ssize_t pathlen;
+       struct smb_filename smb_fname;
+       bool offline;
        NTSTATUS status;
 
        xattr_size = SMB_VFS_GETXATTRAT_RECV(subreq,
@@ -1767,6 +1768,29 @@ static void vfswrap_get_dos_attributes_getxattr_done(struct tevent_req *subreq)
                return;
        }
 
+       pathlen = full_path_tos(state->dir_fsp->fsp_name->base_name,
+                               state->smb_fname->base_name,
+                               pathbuf,
+                               sizeof(pathbuf),
+                               &path,
+                               &tofree);
+       if (pathlen == -1) {
+               tevent_req_nterror(req, NT_STATUS_NO_MEMORY);
+               return;
+       }
+
+       smb_fname = (struct smb_filename) {
+               .base_name = path,
+               .st = state->smb_fname->st,
+               .flags = state->smb_fname->flags,
+       };
+
+       offline = vfswrap_is_offline(state->conn, &smb_fname);
+       if (offline) {
+               state->dosmode |= FILE_ATTRIBUTE_OFFLINE;
+       }
+       TALLOC_FREE(tofree);
+
        tevent_req_done(req);
        return;
 }
@@ -2442,6 +2466,7 @@ static struct smb_filename *vfswrap_getwd(vfs_handle_struct *handle,
                                result,
                                NULL,
                                NULL,
+                               0,
                                0);
        /*
         * sys_getwd() *always* returns malloced memory.
@@ -2617,7 +2642,7 @@ static int vfswrap_ftruncate(vfs_handle_struct *handle, files_struct *fsp, off_t
 
        START_PROFILE(syscall_ftruncate);
 
-       if (lp_strict_allocate(SNUM(fsp->conn)) && !fsp->is_sparse) {
+       if (lp_strict_allocate(SNUM(fsp->conn)) && !fsp->fsp_flags.is_sparse) {
                result = strict_allocate_ftruncate(handle, fsp, len);
                END_PROFILE(syscall_ftruncate);
                return result;
@@ -2714,7 +2739,7 @@ static bool vfswrap_lock(vfs_handle_struct *handle, files_struct *fsp, int op, o
 
        START_PROFILE(syscall_fcntl_lock);
 
-       if (fsp->use_ofd_locks) {
+       if (fsp->fsp_flags.use_ofd_locks) {
                op = map_process_lock_to_ofd_lock(op);
        }
 
@@ -2784,7 +2809,7 @@ static bool vfswrap_getlock(vfs_handle_struct *handle, files_struct *fsp, off_t
 
        START_PROFILE(syscall_fcntl_getlock);
 
-       if (fsp->use_ofd_locks) {
+       if (fsp->fsp_flags.use_ofd_locks) {
                op = map_process_lock_to_ofd_lock(op);
        }
 
@@ -2904,7 +2929,12 @@ static struct smb_filename *vfswrap_realpath(vfs_handle_struct *handle,
        result = sys_realpath(smb_fname->base_name);
        END_PROFILE(syscall_realpath);
        if (result) {
-               result_fname = synthetic_smb_fname(ctx, result, NULL, NULL, 0);
+               result_fname = synthetic_smb_fname(ctx,
+                                                  result,
+                                                  NULL,
+                                                  NULL,
+                                                  0,
+                                                  0);
                SAFE_FREE(result);
        }
        return result_fname;
@@ -2971,7 +3001,7 @@ static NTSTATUS vfswrap_streaminfo(vfs_handle_struct *handle,
        struct stream_struct *tmp_streams = NULL;
        int ret;
 
-       if ((fsp != NULL) && (fsp->is_directory)) {
+       if ((fsp != NULL) && (fsp->fsp_flags.is_directory)) {
                /*
                 * No default streams on directories
                 */
@@ -3325,12 +3355,12 @@ static struct tevent_req *vfswrap_getxattrat_send(
 
 static void vfswrap_getxattrat_do_sync(struct tevent_req *req)
 {
-       struct vfswrap_getxattrat_state *state = talloc_get_type_abort(
+       struct vfswrap_getxattrat_state *state = tevent_req_data(
                req, struct vfswrap_getxattrat_state);
        char *path = NULL;
        char *tofree = NULL;
        char pathbuf[PATH_MAX+1];
-       size_t pathlen;
+       ssize_t pathlen;
        int err;
 
        pathlen = full_path_tos(state->dir_fsp->fsp_name->base_name,
@@ -3624,7 +3654,6 @@ static struct vfs_fn_pointers vfs_default_fns = {
 
        /* Directory operations */
 
-       .opendir_fn = vfswrap_opendir,
        .fdopendir_fn = vfswrap_fdopendir,
        .readdir_fn = vfswrap_readdir,
        .readdir_attr_fn = vfswrap_readdir_attr,