]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
Second part of fix for bug #8443 - Default user entry is set to minimal permissions...
authorJeremy Allison <jra@samba.org>
Thu, 8 Sep 2011 21:10:16 +0000 (14:10 -0700)
committerKarolin Seeger <kseeger@samba.org>
Sat, 8 Oct 2011 18:05:59 +0000 (20:05 +0200)
Be smarter about setting default permissions when a ACL_USER_OBJ isn't given. Use the principle of least surprises for the user.

source3/smbd/posix_acls.c

index 1457ec1bde89f8c4e15887a3d1d6b35c57131682..555f9c00fd2495aa31d4de16e0935feab7ec2533 100644 (file)
@@ -1397,29 +1397,32 @@ static bool ensure_canon_entry_valid(canon_ace **pp_ace,
                pace->unix_ug.uid = pst->st_ex_uid;
                pace->trustee = *pfile_owner_sid;
                pace->attr = ALLOW_ACE;
+               /* Start with existing permissions, principle of least
+                  surprises for the user. */
+               pace->perms = pst->st_ex_mode;
 
                if (setting_acl) {
                        /* See if the owning user is in any of the other groups in
-                          the ACE. If so, OR in the permissions from that group. */
+                          the ACE, or if there's a matching user entry.
+                          If so, OR in the permissions from that entry. */
 
-                       bool group_matched = False;
                        canon_ace *pace_iter;
 
                        for (pace_iter = *pp_ace; pace_iter; pace_iter = pace_iter->next) {
-                               if (pace_iter->type == SMB_ACL_GROUP_OBJ || pace_iter->type == SMB_ACL_GROUP) {
+                               if (pace_iter->type == SMB_ACL_USER &&
+                                               pace_iter->unix_ug.uid == pace->unix_ug.uid) {
+                                       pace->perms |= pace_iter->perms;
+                               } else if (pace_iter->type == SMB_ACL_GROUP_OBJ || pace_iter->type == SMB_ACL_GROUP) {
                                        if (uid_entry_in_group(pace, pace_iter)) {
                                                pace->perms |= pace_iter->perms;
-                                               group_matched = True;
                                        }
                                }
                        }
 
-                       /* If we only got an "everyone" perm, just use that. */
-                       if (!group_matched) {
+                       if (pace->perms == 0) {
+                               /* If we only got an "everyone" perm, just use that. */
                                if (got_other)
                                        pace->perms = pace_other->perms;
-                               else
-                                       pace->perms = 0;
                        }
 
                        apply_default_perms(params, is_directory, pace, S_IRUSR);