Fix bug #8370 - vfs_chown_fsp broken -- returns in the wrong directory
[idra/samba.git] / source3 / smbd / vfs.c
index ed5009885be4523c577cbbc281a70e44f8036a76..c6edef282faaa806c349a1163d8edc01bebf15ac 100644 (file)
@@ -1501,7 +1501,7 @@ NTSTATUS vfs_chown_fsp(files_struct *fsp, uid_t uid, gid_t gid)
                }
 
                /* cd into the parent dir to pin it. */
-               ret = SMB_VFS_CHDIR(fsp->conn, parent_dir);
+               ret = vfs_ChDir(fsp->conn, parent_dir);
                if (ret == -1) {
                        return map_nt_error_from_unix(errno);
                }
@@ -1512,12 +1512,14 @@ NTSTATUS vfs_chown_fsp(files_struct *fsp, uid_t uid, gid_t gid)
                /* Must use lstat here. */
                ret = SMB_VFS_LSTAT(fsp->conn, &local_fname);
                if (ret == -1) {
-                       return map_nt_error_from_unix(errno);
+                       status = map_nt_error_from_unix(errno);
+                       goto out;
                }
 
                /* Ensure it matches the fsp stat. */
                if (!check_same_stat(&local_fname.st, &fsp->fsp_name->st)) {
-                        return NT_STATUS_ACCESS_DENIED;
+                        status = NT_STATUS_ACCESS_DENIED;
+                       goto out;
                 }
                 path = final_component;
         } else {
@@ -1540,6 +1542,8 @@ NTSTATUS vfs_chown_fsp(files_struct *fsp, uid_t uid, gid_t gid)
                status = map_nt_error_from_unix(errno);
        }
 
+  out:
+
        if (as_root) {
                vfs_ChDir(fsp->conn,saved_dir);
                TALLOC_FREE(saved_dir);