Fix bug #7996 - sgid bit lost on folder rename.
authorJeremy Allison <jra@samba.org>
Thu, 31 Mar 2011 17:49:22 +0000 (10:49 -0700)
committerKarolin Seeger <kseeger@samba.org>
Fri, 1 Apr 2011 18:10:48 +0000 (20:10 +0200)
Refuse to set dos attributes into unix mode bits on such a
folder.

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

index a261310ea2e8942d533e2f755b256e1b60ceea71..6ff088293c5a9af6ba33370c3ab50191c283d61b 100644 (file)
@@ -6752,6 +6752,7 @@ uint32_t map_canon_ace_perms(int snum,
                                 mode_t perms,
                                 bool directory_ace);
 NTSTATUS unpack_nt_owners(int snum, uid_t *puser, gid_t *pgrp, uint32 security_info_sent, const SEC_DESC *psd);
+bool current_user_in_group(gid_t gid);
 SMB_ACL_T free_empty_sys_acl(connection_struct *conn, SMB_ACL_T the_acl);
 NTSTATUS posix_fget_nt_acl(struct files_struct *fsp, uint32_t security_info,
                           SEC_DESC **ppdesc);
index 74f54a0b07d79dd65101f5f312c8b180aa42cb42..94caaf6b35697c5e8db33f025edacd9d51aad1d5 100644 (file)
@@ -793,6 +793,28 @@ int file_set_dosmode(connection_struct *conn, struct smb_filename *smb_fname,
                unixmode |= (smb_fname->st.st_ex_mode & (S_IWUSR|S_IWGRP|S_IWOTH));
        }
 
+       /*
+        * From the chmod 2 man page:
+        *
+        * "If the calling process is not privileged, and the group of the file
+        * does not match the effective group ID of the process or one of its
+        * supplementary group IDs, the S_ISGID bit will be turned off, but
+        * this will not cause an error to be returned."
+        *
+        * Simply refuse to do the chmod in this case.
+        */
+
+       if (S_ISDIR(smb_fname->st.st_ex_mode) && (unixmode & S_ISGID) &&
+                       geteuid() != sec_initial_uid() &&
+                       !current_user_in_group(smb_fname->st.st_ex_gid)) {
+               DEBUG(3,("file_set_dosmode: setgid bit cannot be "
+                       "set for directory %s\n",
+                       smb_fname_str_dbg(smb_fname)));
+               errno = EPERM;
+               return -1;
+       }
+
+
        ret = SMB_VFS_CHMOD(conn, smb_fname->base_name, unixmode);
        if (ret == 0) {
                if(!newfile || (lret != -1)) {
index aaca9f4a7f237601ee2d5221f058e40071805953..714a4d34996b0793656b8cdcb5fd76e87691dd24 100644 (file)
@@ -2644,7 +2644,7 @@ static canon_ace *canonicalise_acl(struct connection_struct *conn,
  Check if the current user group list contains a given group.
 ****************************************************************************/
 
-static bool current_user_in_group(gid_t gid)
+bool current_user_in_group(gid_t gid)
 {
        int i;