]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: make it possible to call vfs_ChDir(conn, conn->cwd_fname);
authorStefan Metzmacher <metze@samba.org>
Fri, 15 Jun 2018 09:49:57 +0000 (11:49 +0200)
committerStefan Metzmacher <metze@samba.org>
Mon, 18 Jun 2018 06:59:16 +0000 (08:59 +0200)
We should only TALLOC_FREE(old_cwd) at the successful end.
This also avoids calling cp_smb_filename() on the old value.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/smbd/vfs.c

index c3f39f32474412b9a832b1a33a8271299066e7fd..ebe5ca5b86987a5689ba1208871ff66c4c06d7b2 100644 (file)
@@ -787,7 +787,7 @@ int vfs_ChDir(connection_struct *conn, const struct smb_filename *smb_fname)
 {
        int ret;
        int saved_errno = 0;
-       struct smb_filename *saved_cwd = NULL;
+       struct smb_filename *old_cwd = conn->cwd_fname;
 
        if (!LastDir) {
                LastDir = SMB_STRDUP("");
@@ -802,24 +802,10 @@ int vfs_ChDir(connection_struct *conn, const struct smb_filename *smb_fname)
                return 0;
        }
 
-       if (conn->cwd_fname != NULL) {
-               /*
-                * Save off where we are in case we need to return
-                * on vfs_GetWd() failure after successful SMB_VFS_CHDIR().
-                */
-               saved_cwd = cp_smb_filename(conn, conn->cwd_fname);
-               if (saved_cwd == NULL) {
-                       return -1;
-               }
-       }
-
        DEBUG(4,("vfs_ChDir to %s\n", smb_fname->base_name));
 
        ret = SMB_VFS_CHDIR(conn, smb_fname);
        if (ret != 0) {
-               saved_errno = errno;
-               TALLOC_FREE(saved_cwd);
-               errno = saved_errno;
                return -1;
        }
 
@@ -830,7 +816,6 @@ int vfs_ChDir(connection_struct *conn, const struct smb_filename *smb_fname)
         */
 
        /* conn cache. */
-       TALLOC_FREE(conn->cwd_fname);
        conn->cwd_fname = vfs_GetWd(conn, conn);
        if (conn->cwd_fname == NULL) {
                /*
@@ -841,7 +826,7 @@ int vfs_ChDir(connection_struct *conn, const struct smb_filename *smb_fname)
                 */
                saved_errno = errno;
 
-               if (saved_cwd == NULL) {
+               if (old_cwd == NULL) {
                        /*
                         * Failed on the very first chdir()+getwd()
                         * for this connection. We can't
@@ -851,16 +836,16 @@ int vfs_ChDir(connection_struct *conn, const struct smb_filename *smb_fname)
                        /* NOTREACHED */
                        return -1;
                }
+               /* Restore original conn->cwd_fname. */
+               conn->cwd_fname = old_cwd;
 
                /* Return to the previous $cwd. */
-               ret = SMB_VFS_CHDIR(conn, saved_cwd);
+               ret = SMB_VFS_CHDIR(conn, conn->cwd_fname);
                if (ret != 0) {
                        smb_panic("conn->cwd getwd failed\n");
                        /* NOTREACHED */
                        return -1;
                }
-               /* Restore original conn->cwd_fname. */
-               conn->cwd_fname = saved_cwd;
                errno = saved_errno;
                /* And fail the chdir(). */
                return -1;
@@ -873,7 +858,7 @@ int vfs_ChDir(connection_struct *conn, const struct smb_filename *smb_fname)
 
        DEBUG(4,("vfs_ChDir got %s\n", conn->cwd_fname->base_name));
 
-       TALLOC_FREE(saved_cwd);
+       TALLOC_FREE(old_cwd);
        if (saved_errno != 0) {
                errno = saved_errno;
        }