smbd: add twrp arg to synthetic_smb_fname()
[amitay/samba.git] / source3 / modules / vfs_default.c
index 21bc9c7adf78099cd42b3a1eedd1a771d09d543b..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;
@@ -780,7 +775,6 @@ static ssize_t vfswrap_pwrite(vfs_handle_struct *handle, files_struct *fsp, cons
 }
 
 struct vfswrap_pread_state {
-       struct tevent_req *req;
        ssize_t ret;
        int fd;
        void *buf;
@@ -810,7 +804,6 @@ static struct tevent_req *vfswrap_pread_send(struct vfs_handle_struct *handle,
                return NULL;
        }
 
-       state->req = req;
        state->ret = -1;
        state->fd = fsp->fh->fd;
        state->buf = data;
@@ -827,7 +820,7 @@ static struct tevent_req *vfswrap_pread_send(struct vfs_handle_struct *handle,
        if (tevent_req_nomem(subreq, req)) {
                return tevent_req_post(req, ev);
        }
-       tevent_req_set_callback(subreq, vfs_pread_done, state);
+       tevent_req_set_callback(subreq, vfs_pread_done, req);
 
        talloc_set_destructor(state, vfs_pread_state_destructor);
 
@@ -863,40 +856,21 @@ static void vfs_pread_do(void *private_data)
 
 static int vfs_pread_state_destructor(struct vfswrap_pread_state *state)
 {
-       /*
-        * This destructor only gets called if the request is still
-        * in flight, which is why we deny it by returning -1. We
-        * also set the req pointer to NULL so the _done function
-        * can detect the caller doesn't want the result anymore.
-        *
-        * Forcing the fsp closed by a SHUTDOWN_CLOSE can cause this.
-        */
-       state->req = NULL;
        return -1;
 }
 
 static void vfs_pread_done(struct tevent_req *subreq)
 {
-       struct vfswrap_pread_state *state = tevent_req_callback_data(
-               subreq, struct vfswrap_pread_state);
-       struct tevent_req *req = state->req;
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       struct vfswrap_pread_state *state = tevent_req_data(
+               req, struct vfswrap_pread_state);
        int ret;
 
        ret = pthreadpool_tevent_job_recv(subreq);
        TALLOC_FREE(subreq);
        SMBPROFILE_BYTES_ASYNC_END(state->profile_bytes);
        talloc_set_destructor(state, NULL);
-       if (req == NULL) {
-               /*
-                * We were shutdown closed in flight. No one
-                * wants the result, and state has been reparented
-                * to the NULL context, so just free it so we
-                * don't leak memory.
-                */
-               DBG_NOTICE("pread request abandoned in flight\n");
-               TALLOC_FREE(state);
-               return;
-       }
        if (ret != 0) {
                if (ret != EAGAIN) {
                        tevent_req_error(req, ret);
@@ -2492,6 +2466,7 @@ static struct smb_filename *vfswrap_getwd(vfs_handle_struct *handle,
                                result,
                                NULL,
                                NULL,
+                               0,
                                0);
        /*
         * sys_getwd() *always* returns malloced memory.
@@ -2667,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;
@@ -2764,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);
        }
 
@@ -2834,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);
        }
 
@@ -2954,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;
@@ -3021,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
                 */
@@ -3674,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,