Fix bug #7892 - open_file_fchmod() leaves a stale lock.
authorJeremy Allison <jra@samba.org>
Wed, 29 Dec 2010 01:24:27 +0000 (17:24 -0800)
committerKarolin Seeger <kseeger@samba.org>
Sat, 5 Mar 2011 13:34:47 +0000 (14:34 +0100)
(cherry picked from commit 8d9ef26538a29ab9f5b0a3179c28beecab1a099a)

source3/include/proto.h
source3/smbd/dosmode.c
source3/smbd/open.c
source3/smbd/posix_acls.c

index 5dfd046671cb99af7e0c265a27c0bdf324e488ed..bfcd0122582ed8ea28ece6ee97e9b3abb2703503 100644 (file)
@@ -6630,10 +6630,9 @@ bool map_open_params_to_ntcreate(const struct smb_filename *smb_fname,
                                 uint32 *pshare_mode,
                                 uint32 *pcreate_disposition,
                                 uint32 *pcreate_options);
-NTSTATUS open_file_fchmod(struct smb_request *req, connection_struct *conn,
+NTSTATUS open_file_fchmod(connection_struct *conn,
                          struct smb_filename *smb_fname,
                          files_struct **result);
-NTSTATUS close_file_fchmod(struct smb_request *req, files_struct *fsp);
 NTSTATUS create_directory(connection_struct *conn, struct smb_request *req,
                          struct smb_filename *smb_dname);
 void msg_file_was_renamed(struct messaging_context *msg,
index c061b21822d9bb661b963e7cdad795dc8b789b7b..74f54a0b07d79dd65101f5f312c8b180aa42cb42 100644 (file)
@@ -411,7 +411,7 @@ static bool set_ea_dos_attribute(connection_struct *conn,
                 * are not violating security in doing the setxattr.
                 */
 
-               if (!NT_STATUS_IS_OK(open_file_fchmod(NULL, conn, smb_fname,
+               if (!NT_STATUS_IS_OK(open_file_fchmod(conn, smb_fname,
                                                      &fsp)))
                        return ret;
                become_root();
@@ -421,7 +421,7 @@ static bool set_ea_dos_attribute(connection_struct *conn,
                        ret = true;
                }
                unbecome_root();
-               close_file_fchmod(NULL, fsp);
+               close_file(NULL, fsp, NORMAL_CLOSE);
                return ret;
        }
        DEBUG(10,("set_ea_dos_attribute: set EA 0x%x on file %s\n",
@@ -820,18 +820,15 @@ int file_set_dosmode(connection_struct *conn, struct smb_filename *smb_fname,
                 * We need to open the file with write access whilst
                 * still in our current user context. This ensures we
                 * are not violating security in doing the fchmod.
-                * This file open does *not* break any oplocks we are
-                * holding. We need to review this.... may need to
-                * break batch oplocks open by others. JRA.
                 */
                files_struct *fsp;
-               if (!NT_STATUS_IS_OK(open_file_fchmod(NULL, conn, smb_fname,
+               if (!NT_STATUS_IS_OK(open_file_fchmod(conn, smb_fname,
                                     &fsp)))
                        return -1;
                become_root();
                ret = SMB_VFS_FCHMOD(fsp, unixmode);
                unbecome_root();
-               close_file_fchmod(NULL, fsp);
+               close_file(NULL, fsp, NORMAL_CLOSE);
                if (!newfile) {
                        notify_fname(conn, NOTIFY_ACTION_MODIFIED,
                                     FILE_NOTIFY_CHANGE_ATTRIBUTES,
index b85b0f732a0c811b1f8b2be70de92a272537ed34..f7ed495446345cd0b8e91934d5c3e95a9977ec68 100644 (file)
@@ -2271,23 +2271,15 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
  Open a file for for write to ensure that we can fchmod it.
 ****************************************************************************/
 
-NTSTATUS open_file_fchmod(struct smb_request *req, connection_struct *conn,
+NTSTATUS open_file_fchmod(connection_struct *conn,
                          struct smb_filename *smb_fname,
                          files_struct **result)
 {
-       files_struct *fsp = NULL;
-       NTSTATUS status;
-
        if (!VALID_STAT(smb_fname->st)) {
                return NT_STATUS_INVALID_PARAMETER;
        }
 
-       status = file_new(req, conn, &fsp);
-       if(!NT_STATUS_IS_OK(status)) {
-               return status;
-       }
-
-        status = SMB_VFS_CREATE_FILE(
+        return SMB_VFS_CREATE_FILE(
                conn,                                   /* conn */
                NULL,                                   /* req */
                0,                                      /* root_dir_fid */
@@ -2298,36 +2290,12 @@ NTSTATUS open_file_fchmod(struct smb_request *req, connection_struct *conn,
                FILE_OPEN,                              /* create_disposition*/
                0,                                      /* create_options */
                0,                                      /* file_attributes */
-               0,                                      /* oplock_request */
+               INTERNAL_OPEN_ONLY,                     /* oplock_request */
                0,                                      /* allocation_size */
                NULL,                                   /* sd */
                NULL,                                   /* ea_list */
-               &fsp,                                   /* result */
+               result,                                 /* result */
                NULL);                                  /* pinfo */
-
-       /*
-        * This is not a user visible file open.
-        * Don't set a share mode.
-        */
-
-       if (!NT_STATUS_IS_OK(status)) {
-               file_free(req, fsp);
-               return status;
-       }
-
-       *result = fsp;
-       return NT_STATUS_OK;
-}
-
-/****************************************************************************
- Close the fchmod file fd - ensure no locks are lost.
-****************************************************************************/
-
-NTSTATUS close_file_fchmod(struct smb_request *req, files_struct *fsp)
-{
-       NTSTATUS status = fd_close(fsp);
-       file_free(req, fsp);
-       return status;
 }
 
 static NTSTATUS mkdir_internal(connection_struct *conn,
index 39b1c0ea3c1de93b96b592724e11fa9ec134a424..aaca9f4a7f237601ee2d5221f058e40071805953 100644 (file)
@@ -3599,7 +3599,7 @@ int try_chown(connection_struct *conn, struct smb_filename *smb_fname,
                return -1;
        }
 
-       if (!NT_STATUS_IS_OK(open_file_fchmod(NULL, conn, smb_fname, &fsp))) {
+       if (!NT_STATUS_IS_OK(open_file_fchmod(conn, smb_fname, &fsp))) {
                return -1;
        }
 
@@ -3618,7 +3618,7 @@ int try_chown(connection_struct *conn, struct smb_filename *smb_fname,
        }
        unbecome_root();
 
-       close_file_fchmod(NULL, fsp);
+       close_file(NULL, fsp, NORMAL_CLOSE);
 
        return ret;
 }