Fix bug #7892 - open_file_fchmod() leaves a stale lock.
authorJeremy Allison <jra@samba.org>
Wed, 29 Dec 2010 02:11:33 +0000 (18:11 -0800)
committerKarolin Seeger <kseeger@samba.org>
Thu, 13 Jan 2011 16:58:54 +0000 (17:58 +0100)
(cherry picked from commit 023aa6f4aae29ba22b3d42c815027ba6a66f8ee2)

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

index f87d91af9c2ca4ac46eaa67437f3814a62d641d4..7c2893b1798b95b29427fd2345d4fb68efbe1676 100644 (file)
@@ -6637,10 +6637,9 @@ bool map_open_params_to_ntcreate(const char *fname, int deny_mode, int open_func
                                 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,
                          const char *fname,
                          SMB_STRUCT_STAT *psbuf, files_struct **result);
-NTSTATUS close_file_fchmod(struct smb_request *req, files_struct *fsp);
 NTSTATUS create_directory(connection_struct *conn, struct smb_request *req, const char *directory);
 void msg_file_was_renamed(struct messaging_context *msg,
                          void *private_data,
index 7b47fe62367100afd85efd5b6507af099fcd197e..2092712fbdecb9fd718931c614aa69b1432f7b9d 100644 (file)
@@ -301,7 +301,7 @@ static bool set_ea_dos_attribute(connection_struct *conn, const char *path, SMB_
                 * are not violating security in doing the setxattr.
                 */
 
-               if (!NT_STATUS_IS_OK(open_file_fchmod(NULL, conn, path, sbuf,
+               if (!NT_STATUS_IS_OK(open_file_fchmod(conn, path, sbuf,
                                                      &fsp)))
                        return ret;
                become_root();
@@ -309,7 +309,7 @@ static bool set_ea_dos_attribute(connection_struct *conn, const char *path, SMB_
                        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 %s on file %s\n", attrstr, path));
@@ -705,18 +705,15 @@ int file_set_dosmode(connection_struct *conn, const char *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, fname, st,
+               if (!NT_STATUS_IS_OK(open_file_fchmod(conn, fname, st,
                                                      &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, fname);
index ab3bf1ec757ecd89447c0a40ff4084b741449775..1722895e37b7d94e3c33c5e582de318cc48d6ab4 100644 (file)
@@ -2207,23 +2207,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,
                          const char *fname,
                          SMB_STRUCT_STAT *psbuf, files_struct **result)
 {
-       files_struct *fsp = NULL;
-       NTSTATUS status;
-
        if (!VALID_STAT(*psbuf)) {
                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 */
@@ -2235,37 +2227,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 */
                NULL,                                   /* sd */
                NULL,                                   /* ea_list */
-               &fsp,                                   /* result */
+               result,                                 /* result */
                NULL,                                   /* pinfo */
                psbuf);                                 /* psbuf */
-
-       /*
-        * 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 43edf21f7d10359f371be39e2ec8a15d222b625e..647497794d12730c62a401df153f8863f10aa812 100644 (file)
@@ -3472,7 +3472,7 @@ int try_chown(connection_struct *conn, const char *fname, uid_t uid, gid_t gid)
                return -1;
        }
 
-       if (!NT_STATUS_IS_OK(open_file_fchmod(NULL, conn, fname, &st, &fsp))) {
+       if (!NT_STATUS_IS_OK(open_file_fchmod(conn, fname, &st, &fsp))) {
                return -1;
        }
 
@@ -3481,7 +3481,7 @@ int try_chown(connection_struct *conn, const char *fname, uid_t uid, gid_t gid)
        ret = SMB_VFS_FCHOWN(fsp, uid, (gid_t)-1);
        unbecome_root();
 
-       close_file_fchmod(NULL, fsp);
+       close_file(NULL, fsp, NORMAL_CLOSE);
 
        return ret;
 }