summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/sec_helper.cc
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2012-06-03 16:46:53 +0000
committerCorinna Vinschen <corinna@vinschen.de>2012-06-03 16:46:53 +0000
commit115d74b99e5beba493bff58384d0d167bcaf77c3 (patch)
tree32ef7edb03be8b1bff16ab06277fe6dd5dc994ef /winsup/cygwin/sec_helper.cc
parent6a713dabad2091f4a95f6ad567a5bb0dd2834b4b (diff)
downloadcygnal-115d74b99e5beba493bff58384d0d167bcaf77c3.tar.gz
cygnal-115d74b99e5beba493bff58384d0d167bcaf77c3.tar.bz2
cygnal-115d74b99e5beba493bff58384d0d167bcaf77c3.zip
* globals.cc (ro_u_refs): New R/O unicode string.
* mount.cc (fs_info::update): Recognize ReFS. * mount.h (enum fs_info_type): Add refs. (class fs_info): Add refs flag and accessor methods. * ntdll.h (RtlAddAccessAllowedAceEx): Declare. (RtlAddAccessDeniedAceEx): Declare. * path.h (path_conv::fs_is_refs): Define. * sec_helper.cc (_recycler_sd): New function to create security descriptors suitable for the recycler bin starting with Vista. * security.cc (add_access_allowed_ace): Use RtlAddAccessAllowedAceEx and drop code to set AceFlags explicitely. (add_access_denied_ace): Use RtlAddAccessDeniedAceEx and drop code to set AceFlags explicitely. * security.h (_recycler_sd): Declare. (recycler_sd): Define. * syscalls.cc (desktop_ini): Change formatting. (desktop_ini_ext): Define third line of recycler desktop.ini file since Vista, (try_to_bin): Handle ReFS just like NTFS. Write Vista and later Recycler in all uppercase, just like shell32 does when recreating it. Fix comments to include ReFS. Don't implicitely reuse object attributes from earlier NtOpenFile call, rather recreate it for safety. Use recycler_sd call when creating security descriptor for Recycler dirs and files on Vista and later. Write third line of desktop.ini when on Vista and later.
Diffstat (limited to 'winsup/cygwin/sec_helper.cc')
-rw-r--r--winsup/cygwin/sec_helper.cc60
1 files changed, 59 insertions, 1 deletions
diff --git a/winsup/cygwin/sec_helper.cc b/winsup/cygwin/sec_helper.cc
index eee4886b1..d44705b2f 100644
--- a/winsup/cygwin/sec_helper.cc
+++ b/winsup/cygwin/sec_helper.cc
@@ -1,7 +1,7 @@
/* sec_helper.cc: NT security helper functions
Copyright 2000, 2001, 2002, 2003, 2004, 2006, 2007, 2008, 2009,
- 2010, 2011 Red Hat, Inc.
+ 2010, 2011, 2012 Red Hat, Inc.
Written by Corinna Vinschen <corinna@vinschen.de>
@@ -578,6 +578,64 @@ __sec_user (PVOID sa_buf, PSID sid1, PSID sid2, DWORD access2, BOOL inherit)
return psa;
}
+/* Helper function to create a file security descriptor which allows
+ full access to admins, system, and the sid given as parameter. See
+ try_to_bin for how it's used. */
+
+PSECURITY_DESCRIPTOR
+_recycler_sd (void *buf, bool users, bool dir)
+{
+ NTSTATUS status;
+ PSECURITY_DESCRIPTOR psd = (PSECURITY_DESCRIPTOR) buf;
+
+ if (!psd)
+ return NULL;
+ RtlCreateSecurityDescriptor (psd, SECURITY_DESCRIPTOR_REVISION);
+ PACL dacl = (PACL) (psd + 1);
+ /* Pre-Vista, the per-user recycler dir has a rather too complicated
+ ACL by default, which has distinct ACEs for inheritable and non-inheritable
+ permissions. However, this ACL is practically equivalent to the ACL
+ created since Vista. Therefore we simplify our job here and create the
+ pre-Vista permissions the same way as on Vista and later. */
+ RtlCreateAcl (dacl, MAX_DACL_LEN (3), ACL_REVISION);
+ RtlAddAccessAllowedAceEx (dacl, ACL_REVISION,
+ dir ? CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE
+ : NO_INHERITANCE,
+ FILE_ALL_ACCESS, well_known_admins_sid);
+ RtlAddAccessAllowedAceEx (dacl, ACL_REVISION,
+ dir ? CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE
+ : NO_INHERITANCE,
+ FILE_ALL_ACCESS, well_known_system_sid);
+ if (users)
+ RtlAddAccessAllowedAceEx (dacl, ACL_REVISION, NO_PROPAGATE_INHERIT_ACE,
+ FILE_GENERIC_READ | FILE_GENERIC_EXECUTE
+ | FILE_APPEND_DATA | FILE_WRITE_ATTRIBUTES,
+ well_known_users_sid);
+ else
+ RtlAddAccessAllowedAceEx (dacl, ACL_REVISION,
+ dir ? CONTAINER_INHERIT_ACE
+ | OBJECT_INHERIT_ACE
+ : NO_INHERITANCE,
+ FILE_ALL_ACCESS, cygheap->user.sid ());
+ LPVOID ace;
+ status = RtlFirstFreeAce (dacl, &ace);
+ if (!NT_SUCCESS (status))
+ {
+ debug_printf ("RtlFirstFreeAce: %p", status);
+ return NULL;
+ }
+ dacl->AclSize = (char *) ace - (char *) dacl;
+ RtlSetDaclSecurityDescriptor (psd, TRUE, dacl, FALSE);
+ /* If the directory DACL is not marked as protected, shell32 thinks
+ the recycle dir is corrupted. As soon as Explorer accesses the
+ Recycler, the user will get a GUI dialog "The Recycle Bin on X:\
+ is corrupted. Do you want to empty the Recycle Bin for this drive?"
+ Of course we want to avoid that. */
+ if (dir)
+ psd->Control |= SE_DACL_PROTECTED;
+ return psd;
+}
+
/* Helper function to create an event security descriptor which only allows
specific access to everyone. Only the creating process has all access
rights. */