Skip to content

Commit bc444e5

Browse files
committed
Reapply POSIX ACL changes.
- New, unified implementation of POSIX permission and ACL handling. The new ACLs now store the POSIX ACL MASK/CLASS_OBJ permission mask, and they allow to inherit the S_ISGID bit. ACL inheritance now really works as desired, in a limited, but theoretically equivalent fashion even for non-Cygwin processes. To accommodate Windows default ACLs, the new code ignores SYSTEM and Administrators group permissions when computing the MASK/CLASS_OBJ permission mask on old ACLs, and it doesn't deny access to SYSTEM and Administrators group based on the value of MASK/CLASS_OBJ when creating the new ACLs. The new code now handles the S_ISGID bit on directories as on Linux: Setting S_ISGID on a directory causes new files and subdirs created within to inherit its group, rather than the primary group of the user who created the file. This only works for files and directories created by Cygwin processes. 2015-05-29 Corinna Vinschen <[email protected]> Reapply POSIX ACL changes. * utils.xml (setfacl): Show new option output. (getfacl): Show new option output. * sec_acl.cc (get_posix_access): Check for Cygwin "standard" ACL. Apply umask, if so. Align comments. * security.cc (set_created_file_access): Fix permission masking by incoming requested file mode. * sec_acl.cc (set_posix_access): Apply mask only in terms of execute bit for SYSTEM and Admins group. * sec_acl.cc (set_posix_access): Don't create DENY ACEs for USER and GROUP entries if they are the same as USER_OBJ or GROUP_OBJ. * fhandler.h (fhandler_pty_slave::facl): Add prototype. * fhandler_tty.cc (fhandler_pty_slave::facl): New method. (fhandler_pty_slave::fchown): Fix uid/gid handling. * sec_acl.cc (set_posix_access): Drop superfluous class_idx variable. Simplify and move around code in a few places. To improve ACL readability, add r/w permissions to Admins ACE appended to pty ACL. Add comment to explain Windows ACE Mask filtering being in the way of creating a real CLASS_OBJ. (get_posix_access): Fake CLASS_OBJ for ptys. Explain why. * security.cc (get_object_attribute): Add S_IFCHR flag to attributes when calling get_posix_access. * sec_acl.cc (set_posix_access): Move merging group perms into owner perms in case of owner == group after mask has been computed. Take mask into account when doing so to avoid unnecessary ACCESS_DENIED_ACE. * sec_acl.cc (get_posix_access): Only set saw_group_obj flag if we saw the ACCESS_ALLOWED_ACE. * fhandler_disk_file.cc (fhandler_disk_file::fchmod): Deliberatly set GROUP_OBJ and CLASS_OBJ perms to new group perms. Add comment to explain why. * security.cc (set_created_file_access): Ditto. * sec_acl.cc (set_posix_access): Replace previous patch. Return EINVAL if uid and/or guid is invalid and not backed by an actual Windows account. * sec_acl.cc (set_posix_access): Workaround owner/group SIDs being NULL. * sec_acl.cc (set_posix_access): Handle files with owner == group. Rephrase switch statement checking against unfiltered a_type value. (get_posix_access): Handle files with owner == group. * sec_acl.cc (get_posix_access): Don't use GROUP_OBJ access to fix up CLASS_OBJ mask on old-style ACLs. Fix a comment. * sec_acl.cc (set_posix_access): Always make sure Admins have WRITE_DAC and WRITE_OWNER permissions. * security.h (create_object_sd_from_attribute): Drop handle parameter from prototype. * security.cc (create_object_sd_from_attribute): Drop handle parameter. Just create the standard POSIXy security descriptor. (set_object_attribute): Accommodate dropped paramter in call to create_object_sd_from_attribute. * fhandler_tty.cc: Ditto, throughout. * fhandler_disk_file.cc (fhandler_disk_file::fchmod): Fix typo in mask computation. * fhandler.cc (fhandler_base::open_with_arch): Call open with mode not umasked. (fhandler_base::open): Explicitely umask mode on NFS here. Call new set_created_file_access rather than set_file_attribute. * fhandler_disk_file.cc (fhandler_disk_file::fchmod): Reimplement setting permissions on filesystems supporting ACLs using the new set_posix_access call. (fhandler_disk_file::fchown): Ditto. (fhandler_disk_file::mkdir): Call new set_created_file_access rather than set_file_attribute. * fhandler_socket.cc (fhandler_socket::bind): Don't umask here. Add WRITE_OWNER access to allow writing group in case of SGID bit set. Call new set_created_file_access rather than set_file_attribute. * path.cc (symlink_worker): Call new set_created_file_access rather than set_file_attribute. * sec_acl.cc (searchace): Un-staticize. (set_posix_access): New, complementary functionality to get_posix_access. (setacl): Implement in terms of get_posix_access/set_posix_access. (get_posix_access): Add handling for just created files requiring their first Cygwin ACL. Fix new_style recognition. Handle SGID bit. For old-style ACLs, ignore SYSTEM and Administrators when computing the {DEF_}CLASS_OBJ perms. * security.cc (get_file_sd): Revamp comment. Change and (hopefully) speed up inheritance processing for just created files. (alloc_sd): Remove. (set_security_attribute): Call set_posix_access instead of alloc_sd. (get_object_attribute): Fix return value. (create_object_sd_from_attribute): Call set_posix_access instead of alloc_sd. (set_file_attribute): Remove. (set_created_file_access): New function implemented in terms of get_posix_access/set_posix_access. * security.h (set_file_attribute): Remove prototype. (set_created_file_access): Add prototype. (searchace): Ditto. (set_posix_access): Ditto. * syscalls.cc (open): Call open_with_arch with mode not umasked. * sec_acl.cc: Change preceeding comment explaining new-style ACLs. Describe how to generate deny ACEs in more detail. Accommodate the fact that a NULL deny ACE is used for {DEF_}CLASS_OBJ, rather than a special Cygwin ACE. Improve further comments. (CYG_ACE_NEW_STYLE): Define. (get_posix_access): Change from Cygwin ACE to NULL deny ACE. Fix CLASS_OBJ handling to generate CLASS_OBJ and DEF_CLASS_OBJ from a single NULL deny ACE if the inheritance flags say so. * sec_helper.cc (well_known_cygwin_sid): Remove. * security.h (well_known_cygwin_sid): Drop declaration. * sec_acl.cc (CYG_ACE_ISBITS_TO_WIN): Fix typo. (get_posix_access): Rename index variable from i to idx. Define only once at top level. * security.cc (add_access_allowed_ace): Drop unused parameter "offset". Accommodate throughout. (add_access_denied_ace): Ditto. * sec_acl.cc: Accommodate above change throughout. * security.h (add_access_allowed_ace): Adjust prototype to above change. (add_access_denied_ace): Ditto. * sec_acl.cc (get_posix_access): Handle multiple ACEs for the owner and primary group of the file. Handle the default primary group ACE as DEF_GROUP_OBJ entry if the directory has the S_ISGID bit set. Add comments. Minor code rearrangements. Preliminary read side implementation of new permission handling. * acl.h (MAX_ACL_ENTRIES): Raise to 2730. Add comment to explain. * sec_acl.cc: Add leading comment to explain new ACL style. Add definitions and macros to use for bits in new Cygwin ACL. (DENY_RWX): New mask value for all temporary deny bits. (getace): Add bool parameter to decide when leaving all bits intact, rather than filtering them per the already set bits. (get_posix_access): New function, taking over functionality to read POSIX ACL from SECURITY_DESCRIPTOR. (getacl): Just call get_posix_access. * sec_helper.cc (well_known_cygwin_sid): Define. * security.cc (get_attribute_from_acl): Remove. (get_info_from_sd): Remove. (get_reg_sd): Call get_posix_access instead of get_info_from_sd. (get_file_attribute): Ditto. (get_object_attribute): Ditto. * security.h (well_known_cygwin_sid): Declare. (get_posix_access): Add prototype. * Throughout, use simpler ACE macros from Windows' accctrl.h. * getfacl.c (main): Special-case SYSTEM and Admins group. Add comments. * setfacl.c: Align more to Linux tool. (delacl): New function to delete acl entries only. (modacl): Drop delete functionality. Add handling of recomputing the mask and default mask values. (delallacl): Rename from delacl. (setfacl): Call delacl in Delete case. Call delallacl in DeleteAll and DeleteDef case. (usage): Accommodate new options. Rearrange and rephrase slightly. (longopts): Emit 'x' in --delete case. Add --no-mask and --mask options. (opts): Add -x and -n options. (main): Handle -d and -x the same. Handle -n and --mask options. Drop handling for -r option. * getfacl.c (usage): Align more closely to Linux version. Add new options -c, -e, -E. Change formatting to accommodate longer options. (longopts): Rename --noname to --numeric. Keep --noname for backward compatibility. Add --omit-header, --all-effective and --no-effective options. (opts): Add -c, -e and -E option. (main): Handle new -c, -e, and -E options. Signed-off-by: Corinna Vinschen <[email protected]>
1 parent 049eeec commit bc444e5

File tree

18 files changed

+1819
-1359
lines changed

18 files changed

+1819
-1359
lines changed

winsup/cygwin/ChangeLog

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,155 @@
1+
2015-11-18 Corinna Vinschen <[email protected]>
2+
3+
Reapply POSIX ACL changes.
4+
5+
* sec_acl.cc (get_posix_access): Check for Cygwin "standard" ACL.
6+
Apply umask, if so. Align comments.
7+
* security.cc (set_created_file_access): Fix permission masking by
8+
incoming requested file mode.
9+
10+
* sec_acl.cc (set_posix_access): Apply mask only in terms of execute bit
11+
for SYSTEM and Admins group.
12+
13+
* sec_acl.cc (set_posix_access): Don't create DENY ACEs for USER and
14+
GROUP entries if they are the same as USER_OBJ or GROUP_OBJ.
15+
16+
* fhandler.h (fhandler_pty_slave::facl): Add prototype.
17+
* fhandler_tty.cc (fhandler_pty_slave::facl): New method.
18+
(fhandler_pty_slave::fchown): Fix uid/gid handling.
19+
* sec_acl.cc (set_posix_access): Drop superfluous class_idx variable.
20+
Simplify and move around code in a few places. To improve ACL
21+
readability, add r/w permissions to Admins ACE appended to pty ACL.
22+
Add comment to explain Windows ACE Mask filtering being in the way of
23+
creating a real CLASS_OBJ.
24+
(get_posix_access): Fake CLASS_OBJ for ptys. Explain why.
25+
* security.cc (get_object_attribute): Add S_IFCHR flag to attributes
26+
when calling get_posix_access.
27+
28+
* sec_acl.cc (set_posix_access): Move merging group perms into owner
29+
perms in case of owner == group after mask has been computed. Take
30+
mask into account when doing so to avoid unnecessary ACCESS_DENIED_ACE.
31+
32+
* sec_acl.cc (get_posix_access): Only set saw_group_obj flag if we saw
33+
the ACCESS_ALLOWED_ACE.
34+
35+
* fhandler_disk_file.cc (fhandler_disk_file::fchmod): Deliberatly
36+
set GROUP_OBJ and CLASS_OBJ perms to new group perms. Add comment
37+
to explain why.
38+
* security.cc (set_created_file_access): Ditto.
39+
40+
* sec_acl.cc (set_posix_access): Replace previous patch. Return
41+
EINVAL if uid and/or guid is invalid and not backed by an actual
42+
Windows account.
43+
44+
* sec_acl.cc (set_posix_access): Workaround owner/group SIDs being NULL.
45+
46+
* sec_acl.cc (set_posix_access): Handle files with owner == group.
47+
Rephrase switch statement checking against unfiltered a_type value.
48+
(get_posix_access): Handle files with owner == group.
49+
50+
* sec_acl.cc (get_posix_access): Don't use GROUP_OBJ access to fix up
51+
CLASS_OBJ mask on old-style ACLs. Fix a comment.
52+
53+
* sec_acl.cc (set_posix_access): Always make sure Admins have
54+
WRITE_DAC and WRITE_OWNER permissions.
55+
* security.h (create_object_sd_from_attribute): Drop handle parameter
56+
from prototype.
57+
* security.cc (create_object_sd_from_attribute): Drop handle parameter.
58+
Just create the standard POSIXy security descriptor.
59+
(set_object_attribute): Accommodate dropped paramter in call to
60+
create_object_sd_from_attribute.
61+
* fhandler_tty.cc: Ditto, throughout.
62+
63+
* fhandler_disk_file.cc (fhandler_disk_file::fchmod): Fix typo in
64+
mask computation.
65+
66+
* fhandler.cc (fhandler_base::open_with_arch): Call open with mode
67+
not umasked.
68+
(fhandler_base::open): Explicitely umask mode on NFS here. Call new
69+
set_created_file_access rather than set_file_attribute.
70+
* fhandler_disk_file.cc (fhandler_disk_file::fchmod): Reimplement
71+
setting permissions on filesystems supporting ACLs using the new
72+
set_posix_access call.
73+
(fhandler_disk_file::fchown): Ditto.
74+
(fhandler_disk_file::mkdir): Call new set_created_file_access rather
75+
than set_file_attribute.
76+
* fhandler_socket.cc (fhandler_socket::bind): Don't umask here. Add
77+
WRITE_OWNER access to allow writing group in case of SGID bit set.
78+
Call new set_created_file_access rather than set_file_attribute.
79+
* path.cc (symlink_worker): Call new set_created_file_access rather
80+
than set_file_attribute.
81+
* sec_acl.cc (searchace): Un-staticize.
82+
(set_posix_access): New, complementary functionality to
83+
get_posix_access.
84+
(setacl): Implement in terms of get_posix_access/set_posix_access.
85+
(get_posix_access): Add handling for just created files requiring
86+
their first Cygwin ACL. Fix new_style recognition. Handle SGID
87+
bit. For old-style ACLs, ignore SYSTEM and Administrators when
88+
computing the {DEF_}CLASS_OBJ perms.
89+
* security.cc (get_file_sd): Revamp comment. Change and (hopefully)
90+
speed up inheritance processing for just created files.
91+
(alloc_sd): Remove.
92+
(set_security_attribute): Call set_posix_access instead of alloc_sd.
93+
(get_object_attribute): Fix return value.
94+
(create_object_sd_from_attribute): Call set_posix_access instead of
95+
alloc_sd.
96+
(set_file_attribute): Remove.
97+
(set_created_file_access): New function implemented in terms of
98+
get_posix_access/set_posix_access.
99+
* security.h (set_file_attribute): Remove prototype.
100+
(set_created_file_access): Add prototype.
101+
(searchace): Ditto.
102+
(set_posix_access): Ditto.
103+
* syscalls.cc (open): Call open_with_arch with mode not umasked.
104+
105+
* sec_acl.cc: Change preceeding comment explaining new-style ACLs.
106+
Describe how to generate deny ACEs in more detail. Accommodate the
107+
fact that a NULL deny ACE is used for {DEF_}CLASS_OBJ, rather than
108+
a special Cygwin ACE. Improve further comments.
109+
(CYG_ACE_NEW_STYLE): Define.
110+
(get_posix_access): Change from Cygwin ACE to NULL deny ACE. Fix
111+
CLASS_OBJ handling to generate CLASS_OBJ and DEF_CLASS_OBJ from a single
112+
NULL deny ACE if the inheritance flags say so.
113+
* sec_helper.cc (well_known_cygwin_sid): Remove.
114+
* security.h (well_known_cygwin_sid): Drop declaration.
115+
116+
* sec_acl.cc (CYG_ACE_ISBITS_TO_WIN): Fix typo.
117+
(get_posix_access): Rename index variable from i to idx. Define only
118+
once at top level.
119+
120+
* security.cc (add_access_allowed_ace): Drop unused parameter "offset".
121+
Accommodate throughout.
122+
(add_access_denied_ace): Ditto.
123+
* sec_acl.cc: Accommodate above change throughout.
124+
* security.h (add_access_allowed_ace): Adjust prototype to above change.
125+
(add_access_denied_ace): Ditto.
126+
127+
* sec_acl.cc (get_posix_access): Handle multiple ACEs for the
128+
owner and primary group of the file. Handle the default primary
129+
group ACE as DEF_GROUP_OBJ entry if the directory has the S_ISGID bit
130+
set. Add comments. Minor code rearrangements.
131+
132+
Preliminary read side implementation of new permission handling.
133+
* acl.h (MAX_ACL_ENTRIES): Raise to 2730. Add comment to explain.
134+
* sec_acl.cc: Add leading comment to explain new ACL style.
135+
Add definitions and macros to use for bits in new Cygwin ACL.
136+
(DENY_RWX): New mask value for all temporary deny bits.
137+
(getace): Add bool parameter to decide when leaving all bits intact,
138+
rather than filtering them per the already set bits.
139+
(get_posix_access): New function, taking over functionality to read
140+
POSIX ACL from SECURITY_DESCRIPTOR.
141+
(getacl): Just call get_posix_access.
142+
* sec_helper.cc (well_known_cygwin_sid): Define.
143+
* security.cc (get_attribute_from_acl): Remove.
144+
(get_info_from_sd): Remove.
145+
(get_reg_sd): Call get_posix_access instead of get_info_from_sd.
146+
(get_file_attribute): Ditto.
147+
(get_object_attribute): Ditto.
148+
* security.h (well_known_cygwin_sid): Declare.
149+
(get_posix_access): Add prototype.
150+
151+
* Throughout, use simpler ACE macros from Windows' accctrl.h.
152+
1153
2015-11-18 Corinna Vinschen <[email protected]>
2154

3155
* include/cygwin/version.h (CYGWIN_VERSION_DLL_MAJOR): Bump to 2004.

winsup/cygwin/fhandler.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ fhandler_base::open_with_arch (int flags, mode_t mode)
463463
{
464464
int res;
465465
if (!(res = (archetype && archetype->io_handle)
466-
|| open (flags, (mode & 07777) & ~cygheap->umask)))
466+
|| open (flags, mode & 07777)))
467467
{
468468
if (archetype)
469469
delete archetype;
@@ -662,9 +662,10 @@ fhandler_base::open (int flags, mode_t mode)
662662
+ p->EaNameLength + 1);
663663
memset (nfs_attr, 0, sizeof (fattr3));
664664
nfs_attr->type = NF3REG;
665-
nfs_attr->mode = mode;
665+
nfs_attr->mode = (mode & 07777) & ~cygheap->umask;
666666
}
667-
else if (!has_acls () && !(mode & (S_IWUSR | S_IWGRP | S_IWOTH)))
667+
else if (!has_acls ()
668+
&& !(mode & ~cygheap->umask & (S_IWUSR | S_IWGRP | S_IWOTH)))
668669
/* If mode has no write bits set, and ACLs are not used, we set
669670
the DOS R/O attribute. */
670671
file_attributes |= FILE_ATTRIBUTE_READONLY;
@@ -716,7 +717,7 @@ fhandler_base::open (int flags, mode_t mode)
716717
This is the result of a discussion on the samba-technical list, starting at
717718
http://lists.samba.org/archive/samba-technical/2008-July/060247.html */
718719
if (io.Information == FILE_CREATED && has_acls ())
719-
set_file_attribute (fh, pc, ILLEGAL_UID, ILLEGAL_GID, S_JUSTCREATED | mode);
720+
set_created_file_access (fh, pc, mode);
720721

721722
/* If you O_TRUNC a file on Linux, the data is truncated, but the EAs are
722723
preserved. If you open a file on Windows with FILE_OVERWRITE{_IF} or

winsup/cygwin/fhandler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,6 +1557,7 @@ class fhandler_pty_slave: public fhandler_pty_common
15571557
select_record *select_read (select_stuff *);
15581558
virtual char const *ttyname () { return pc.dev.name; }
15591559
int __reg2 fstat (struct stat *buf);
1560+
int __reg3 facl (int, int, struct acl *);
15601561
int __reg1 fchmod (mode_t mode);
15611562
int __reg2 fchown (uid_t uid, gid_t gid);
15621563

0 commit comments

Comments
 (0)