Allow UNIX extensions client to act on open fsp instead of pathname if available.
authorJeremy Allison <jra@samba.org>
Wed, 21 Aug 2013 19:10:05 +0000 (12:10 -0700)
committerJeremy Allison <jra@samba.org>
Mon, 26 Aug 2013 16:01:22 +0000 (09:01 -0700)
Eliminates possible race condition on pathname op.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Simo Sorce <idra@samba.org>
source3/smbd/trans2.c

index 945fe434d96a4cb250417cace6f06484e92dae36..3cd21926b181335bc9a281a9ade1e0f89130fa8c 100644 (file)
@@ -7126,11 +7126,18 @@ static NTSTATUS smb_set_file_unix_basic(connection_struct *conn,
         */
 
        if (raw_unixmode != SMB_MODE_NO_CHANGE) {
+               int ret;
+
                DEBUG(10,("smb_set_file_unix_basic: SMB_SET_FILE_UNIX_BASIC "
                          "setting mode 0%o for file %s\n",
                          (unsigned int)unixmode,
                          smb_fname_str_dbg(smb_fname)));
-               if (SMB_VFS_CHMOD(conn, smb_fname->base_name, unixmode) != 0) {
+               if (fsp && fsp->fh->fd != -1) {
+                       ret = SMB_VFS_FCHMOD(fsp, unixmode);
+               } else {
+                       ret = SMB_VFS_CHMOD(conn, smb_fname->base_name, unixmode);
+               }
+               if (ret != 0) {
                        return map_nt_error_from_unix(errno);
                }
        }