Fix bug #8370 - vfs_chown_fsp broken -- returns in the wrong directory
[idra/samba.git] / source3 / modules / vfs_acl_common.c
index bee7966dfc93d87f30de3edf6bf5824a1fd3e4db..a4d712f5257c19c2f986bbc369d9cfc66a0d18d4 100644 (file)
@@ -23,6 +23,7 @@
 #include "system/filesys.h"
 #include "../libcli/security/security.h"
 #include "../librpc/gen_ndr/ndr_security.h"
+#include "../lib/util/bitmap.h"
 
 static NTSTATUS create_acl_blob(const struct security_descriptor *psd,
                        DATA_BLOB *pblob,
@@ -830,6 +831,13 @@ static int acl_common_remove_object(vfs_handle_struct *handle,
        const char *final_component = NULL;
        struct smb_filename local_fname;
        int saved_errno = 0;
+       char *saved_dir = NULL;
+
+       saved_dir = vfs_GetWd(talloc_tos(),conn);
+       if (!saved_dir) {
+               saved_errno = errno;
+               goto out;
+       }
 
        if (!parent_dirname(talloc_tos(), path,
                        &parent_dir, &final_component)) {
@@ -842,7 +850,7 @@ static int acl_common_remove_object(vfs_handle_struct *handle,
                parent_dir, final_component ));
 
        /* cd into the parent dir to pin it. */
-       ret = SMB_VFS_CHDIR(conn, parent_dir);
+       ret = vfs_ChDir(conn, parent_dir);
        if (ret == -1) {
                saved_errno = errno;
                goto out;
@@ -896,7 +904,9 @@ static int acl_common_remove_object(vfs_handle_struct *handle,
 
        TALLOC_FREE(parent_dir);
 
-       vfs_ChDir(conn, conn->connectpath);
+       if (saved_dir) {
+               vfs_ChDir(conn, saved_dir);
+       }
        if (saved_errno) {
                errno = saved_errno;
        }