]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: after creating a directory, open the fsp as pathref fsp
authorRalph Boehme <slow@samba.org>
Wed, 16 Dec 2020 14:25:47 +0000 (15:25 +0100)
committerJeremy Allison <jra@samba.org>
Thu, 17 Dec 2020 18:56:29 +0000 (18:56 +0000)
After the directory has been created by SMB_VFS_MKDIRAT(), open the fsp on the
new directory as pathref fsp so we can use handle based VFS functions.

open_directory() will reopen the fsp as a full fsp, but that doesn't really hurt
thanks to the reopen_from_procfd() optimisation.

Note that smb_dname == fsp->fsp_name.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/smbd/open.c

index dfeb8b6907f48880f98d17c58bd4496f478d7bc6..0ef401bba467bb4e901014c334d76764bf840685 100644 (file)
@@ -4389,10 +4389,22 @@ static NTSTATUS mkdir_internal(connection_struct *conn,
                return map_nt_error_from_unix(errno);
        }
 
+       /*
+        * Make this a pathref fsp for now. open_directory() will reopen as a
+        * full fsp.
+        */
+       fsp->fsp_flags.is_pathref = true;
+
+       status = fd_openat(conn->cwd_fsp, smb_dname, fsp, O_RDONLY | O_DIRECTORY, 0);
+       if (!NT_STATUS_IS_OK(status)) {
+               TALLOC_FREE(parent_dir_fname);
+               return status;
+       }
+
        /* Ensure we're checking for a symlink here.... */
        /* We don't want to get caught by a symlink racer. */
 
-       if (SMB_VFS_LSTAT(conn, smb_dname) == -1) {
+       if (SMB_VFS_FSTAT(fsp, &smb_dname->st) == -1) {
                DEBUG(2, ("Could not stat directory '%s' just created: %s\n",
                          smb_fname_str_dbg(smb_dname), strerror(errno)));
                TALLOC_FREE(parent_dir_fname);
@@ -4439,7 +4451,7 @@ static NTSTATUS mkdir_internal(connection_struct *conn,
                 */
                if ((mode & ~(S_IRWXU|S_IRWXG|S_IRWXO)) &&
                    (mode & ~smb_dname->st.st_ex_mode)) {
-                       SMB_VFS_CHMOD(conn, smb_dname,
+                       SMB_VFS_FCHMOD(fsp,
                                      (smb_dname->st.st_ex_mode |
                                          (mode & ~smb_dname->st.st_ex_mode)));
                        need_re_stat = true;
@@ -4457,7 +4469,7 @@ static NTSTATUS mkdir_internal(connection_struct *conn,
        TALLOC_FREE(parent_dir_fname);
 
        if (need_re_stat) {
-               if (SMB_VFS_LSTAT(conn, smb_dname) == -1) {
+               if (SMB_VFS_FSTAT(fsp, &smb_dname->st) == -1) {
                        DEBUG(2, ("Could not stat directory '%s' just created: %s\n",
                          smb_fname_str_dbg(smb_dname), strerror(errno)));
                        return map_nt_error_from_unix(errno);