Third part of fix for bug #8663 - deleting a symlink fails if the symlink target...
authorJeremy Allison <jra@samba.org>
Fri, 16 Dec 2011 23:50:58 +0000 (15:50 -0800)
committerKarolin Seeger <kseeger@samba.org>
Mon, 23 Jan 2012 20:30:27 +0000 (21:30 +0100)
can_access_file_acl() - we can always delete a symlink.
can_delete_file_in_directory() - We don't need to do another STAT call
here, we know smb_fname->st is in a valid state.
smbd_check_open_rights() - we can always delete a symlink.
(cherry picked from commit c6bd2aa768ebf4308c53d057bc1db7adc2b67705)

source3/smbd/file_access.c
source3/smbd/open.c

index 74855649ea2fe2b4b971581b2660f3445f0373d7..9f95d68cf379c874278e9d514c1a30ec306008dc 100644 (file)
@@ -44,6 +44,13 @@ bool can_access_file_acl(struct connection_struct *conn,
                return true;
        }
 
+       if (access_mask == DELETE_ACCESS &&
+                       VALID_STAT(smb_fname->st) &&
+                       S_ISLNK(smb_fname->st.st_ex_mode)) {
+               /* We can always delete a symlink. */
+               return true;
+       }
+
        status = SMB_VFS_GET_NT_ACL(conn, smb_fname->base_name,
                                    (SECINFO_OWNER |
                                     SECINFO_GROUP |
@@ -130,18 +137,10 @@ bool can_delete_file_in_directory(connection_struct *conn,
        /* sticky bit means delete only by owner of file or by root or
         * by owner of directory. */
        if (smb_fname_parent->st.st_ex_mode & S_ISVTX) {
-               if(SMB_VFS_STAT(conn, smb_fname) != 0) {
-                       if (errno == ENOENT) {
-                               /* If the file doesn't already exist then
-                                * yes we'll be able to delete it. */
-                               ret = true;
-                               goto out;
-                       }
-                       DEBUG(10,("can_delete_file_in_directory: can't "
-                                 "stat file %s (%s)",
-                                 smb_fname_str_dbg(smb_fname),
-                                 strerror(errno) ));
-                       ret = false;
+               if (!VALID_STAT(smb_fname->st)) {
+                       /* If the file doesn't already exist then
+                        * yes we'll be able to delete it. */
+                       ret = true;
                        goto out;
                }
 
index ab54f28c352f174b2a673bc4fe37b64c9e740c31..ce86b4caf2ea1d8f4d743c3e5be71d4ff71a4249 100644 (file)
@@ -95,6 +95,16 @@ NTSTATUS smbd_check_open_rights(struct connection_struct *conn,
                return NT_STATUS_OK;
        }
 
+       if (access_mask == DELETE_ACCESS &&
+                       VALID_STAT(smb_fname->st) &&
+                       S_ISLNK(smb_fname->st.st_ex_mode)) {
+               /* We can always delete a symlink. */
+               DEBUG(10,("smbd_check_open_rights: not checking ACL "
+                       "on DELETE_ACCESS on symlink %s.\n",
+                       smb_fname_str_dbg(smb_fname) ));
+               return NT_STATUS_OK;
+       }
+
        status = SMB_VFS_GET_NT_ACL(conn, smb_fname->base_name,
                        (SECINFO_OWNER |
                        SECINFO_GROUP |