Fix bug #7892 - open_file_fchmod() leaves a stale lock.
authorJeremy Allison <jra@samba.org>
Wed, 29 Dec 2010 00:25:16 +0000 (16:25 -0800)
committerJeremy Allison <jra@samba.org>
Wed, 29 Dec 2010 01:15:23 +0000 (02:15 +0100)
Autobuild-User: Jeremy Allison <jra@samba.org>
Autobuild-Date: Wed Dec 29 02:15:23 CET 2010 on sn-devel-104

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

index 9b391ae7671216efe58a65c5abc5004b38a2b435..c469888940f4a23d045bfff5e73f3a1e206954a2 100644 (file)
@@ -5017,10 +5017,9 @@ bool map_open_params_to_ntcreate(const struct smb_filename *smb_fname,
                                 uint32_t *pprivate_flags);
 void remove_deferred_open_entry(struct file_id id, uint64_t mid,
                                struct server_id pid);
-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 cf95348583e1d7b26f0793845b8936a2ed8b30f6..838dec035e218fdc66e50b3ea28218f7588fa576 100644 (file)
@@ -415,7 +415,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();
@@ -425,7 +425,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",
@@ -823,18 +823,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 32a08b5967cf31f8343f4b53f7b3a7bbda2b5088..722e46106889c6058a8c6b9b16a5a9d80ed16d6c 100644 (file)
@@ -2291,23 +2291,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 */
@@ -2318,37 +2310,13 @@ 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 */
                0,                                      /* private_flags */
                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 54fa5bfdfcc9237bf2d47893c0ef8a08e08eb361..880d5b945258d4a30ebcad25d8f131e542ccf349 100644 (file)
@@ -3603,7 +3603,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;
        }
 
@@ -3622,7 +3622,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;
 }