s3: smbd: Update smb_set_posix_acl() to always use an open file handle.
authorJeremy Allison <jra@samba.org>
Mon, 17 Jun 2019 22:34:13 +0000 (15:34 -0700)
committerJeremy Allison <jra@samba.org>
Mon, 24 Jun 2019 18:49:09 +0000 (18:49 +0000)
Uses get_posix_fsp() added in the previous commit.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
source3/smbd/trans2.c

index 7ec95e897c3fae35beb011a29d48721f009d1fbc..bcb40b3ccba5bee7776345c985b44c474fe2090a 100644 (file)
@@ -7288,6 +7288,7 @@ static NTSTATUS smb_set_posix_acl(connection_struct *conn,
        NTSTATUS status;
        unsigned int size_needed;
        unsigned int total_data;
+       bool close_fsp = false;
 
        if (total_data_in < 0) {
                status = NT_STATUS_INVALID_PARAMETER;
@@ -7348,6 +7349,32 @@ static NTSTATUS smb_set_posix_acl(connection_struct *conn,
                goto out;
        }
 
+       /*
+        * Ensure we always operate on a file descriptor, not just
+        * the filename.
+        */
+       if (fsp == NULL) {
+               uint32_t access_mask = SEC_STD_WRITE_OWNER|
+                                       SEC_STD_WRITE_DAC|
+                                       SEC_STD_READ_CONTROL|
+                                       FILE_READ_ATTRIBUTES|
+                                       FILE_WRITE_ATTRIBUTES;
+
+               status = get_posix_fsp(conn,
+                                       req,
+                                       smb_fname,
+                                       access_mask,
+                                       &fsp);
+
+               if (!NT_STATUS_IS_OK(status)) {
+                       goto out;
+               }
+               close_fsp = true;
+       }
+
+       /* Here we know fsp != NULL */
+       SMB_ASSERT(fsp != NULL);
+
        status = refuse_symlink(conn, fsp, smb_fname);
        if (!NT_STATUS_IS_OK(status)) {
                goto out;
@@ -7392,6 +7419,10 @@ static NTSTATUS smb_set_posix_acl(connection_struct *conn,
 
   out:
 
+       if (close_fsp) {
+               (void)close_file(req, fsp, NORMAL_CLOSE);
+               fsp = NULL;
+       }
        return status;
 }
 #endif