]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Fix DELETE_ON_CLOSE behaviour on files with READ_ONLY attribute
authorChristof Schmitt <cs@samba.org>
Fri, 2 Nov 2018 19:08:23 +0000 (12:08 -0700)
committerKarolin Seeger <kseeger@samba.org>
Wed, 7 Nov 2018 07:44:31 +0000 (08:44 +0100)
MS-FSA states that a CREATE with FILE_DELETE_ON_CLOSE on an existing
file with READ_ONLY attribute has to return STATUS_CANNOT_DELETE. This
was missing in smbd as the check used the DOS attributes from the CREATE
instead of the DOS attributes on the existing file.

We need to handle the new file and existing file cases separately.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13673

Signed-off-by: Christof Schmitt <cs@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
(cherry picked from commit 162a5257c48f20d3752f644e86c9e626b46436c0)

selftest/knownfail
source3/smbd/open.c

index 781c14551fe9b46425bc6228565bc11bd57ecaa6..84776d4f35d0a6642edd54da587b76ee8f156b38 100644 (file)
 # Disabling NTLM means you can't use samr to change the password
 ^samba.tests.ntlmdisabled.python\(ktest\).ntlmdisabled.NtlmDisabledTests.test_samr_change_password\(ktest\)
 ^samba.tests.ntlmdisabled.python\(ad_dc_no_ntlm\).ntlmdisabled.NtlmDisabledTests.test_ntlm_connection\(ad_dc_no_ntlm\)
-^samba3.smb2.delete-on-close-perms.READONLY\(nt4_dc\)
-^samba3.smb2.delete-on-close-perms.READONLY\(ad_dc\)
index 8a9288dbdb4e852fe0febbe116fc6a81f38abd5f..97cf458a86455ef1eb57883f99d52f496e767b20 100644 (file)
@@ -3237,6 +3237,18 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
                request_time = fsp->open_time;
        }
 
+       if ((create_options & FILE_DELETE_ON_CLOSE) &&
+                       (flags2 & O_CREAT) &&
+                       !file_existed) {
+               /* Delete on close semantics for new files. */
+               status = can_set_delete_on_close(fsp,
+                                               new_dos_attributes);
+               if (!NT_STATUS_IS_OK(status)) {
+                       fd_close(fsp);
+                       return status;
+               }
+       }
+
        /*
         * Ensure we pay attention to default ACLs on directories if required.
         */
@@ -3689,15 +3701,17 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
 
        /* Handle strange delete on close create semantics. */
        if (create_options & FILE_DELETE_ON_CLOSE) {
+               if (!new_file_created) {
+                       status = can_set_delete_on_close(fsp,
+                                        existing_dos_attributes);
 
-               status = can_set_delete_on_close(fsp, new_dos_attributes);
-
-               if (!NT_STATUS_IS_OK(status)) {
-                       /* Remember to delete the mode we just added. */
-                       del_share_mode(lck, fsp);
-                       TALLOC_FREE(lck);
-                       fd_close(fsp);
-                       return status;
+                       if (!NT_STATUS_IS_OK(status)) {
+                               /* Remember to delete the mode we just added. */
+                               del_share_mode(lck, fsp);
+                               TALLOC_FREE(lck);
+                               fd_close(fsp);
+                               return status;
+                       }
                }
                /* Note that here we set the *inital* delete on close flag,
                   not the regular one. The magic gets handled in close. */