Change well_known_admin_sid to well_known_admins_sid throughout.

* sec_acl.cc (setacl): Never set DELETE permission. Set
        FILE_DELETE_CHILD only on readable and executable directories.
        * sec_helper.cc: Add constructor for `well_known_null_sid'.
        * security.cc (get_nt_attribute): Set S_ISVTX for directories if
        FILE_WRITE_DATA and FILE_EXECUTE but not FILE_DELETE_CHILD is set.
        Add evaluation of S_ISVTX, S_ISGID and S_ISUID from NULL ACE.
        (alloc_sd): Never set DELETE permission. Set FILE_DELETE_CHILD
        only on readable and executable directories.
        Add creation of NULL ACE for S_ISVTX, S_ISGID and S_ISUID permissions.
        * security.h: Add extern declaration for `well_known_null_sid'.
This commit is contained in:
Corinna Vinschen 2001-07-15 22:40:07 +00:00
parent 4c61c04cd3
commit 3a157c0d0d
7 changed files with 73 additions and 35 deletions

View File

@ -1,3 +1,17 @@
Mon 16 Jul 2001 00:11:00 Corinna Vinschen <corinna@vinschen.de>
Change well_known_admin_sid to well_known_admins_sid throughout.
* sec_acl.cc (setacl): Never set DELETE permission. Set
FILE_DELETE_CHILD only on readable and executable directories.
* sec_helper.cc: Add constructor for `well_known_null_sid'.
* security.cc (get_nt_attribute): Set S_ISVTX for directories if
FILE_WRITE_DATA and FILE_EXECUTE but not FILE_DELETE_CHILD is set.
Add evaluation of S_ISVTX, S_ISGID and S_ISUID from NULL ACE.
(alloc_sd): Never set DELETE permission. Set FILE_DELETE_CHILD
only on readable and executable directories.
Add creation of NULL ACE for S_ISVTX, S_ISGID and S_ISUID permissions.
* security.h: Add extern declaration for `well_known_null_sid'.
Fri 13 Jul 2001 08:08:49 PM EDT Christopher Faylor <cgf@cygnus.com> Fri 13 Jul 2001 08:08:49 PM EDT Christopher Faylor <cgf@cygnus.com>
* syscalls.cc (stat_worker): Simplify previous change. * syscalls.cc (stat_worker): Simplify previous change.

View File

@ -174,7 +174,7 @@ read_etc_group ()
SID_NAME_USE acType; SID_NAME_USE acType;
debug_printf ("Emulating /etc/group"); debug_printf ("Emulating /etc/group");
if (! LookupAccountSidA (NULL , if (! LookupAccountSidA (NULL ,
well_known_admin_sid, well_known_admins_sid,
group_name, group_name,
&group_name_len, &group_name_len,
domain_name, domain_name,

View File

@ -121,10 +121,11 @@ setacl (const char *file, int nentries, aclent_t *aclbufp)
if (aclbufp[i].a_perm & S_IROTH) if (aclbufp[i].a_perm & S_IROTH)
allow |= FILE_GENERIC_READ; allow |= FILE_GENERIC_READ;
if (aclbufp[i].a_perm & S_IWOTH) if (aclbufp[i].a_perm & S_IWOTH)
allow |= STANDARD_RIGHTS_ALL | FILE_GENERIC_WRITE allow |= STANDARD_RIGHTS_ALL | FILE_GENERIC_WRITE;
| DELETE | FILE_DELETE_CHILD;
if (aclbufp[i].a_perm & S_IXOTH) if (aclbufp[i].a_perm & S_IXOTH)
allow |= FILE_GENERIC_EXECUTE; allow |= FILE_GENERIC_EXECUTE;
if ((aclbufp[i].a_perm & (S_IWOTH | S_IXOTH)) == (S_IWOTH | S_IXOTH))
allow |= FILE_DELETE_CHILD;
/* Set inherit property. */ /* Set inherit property. */
DWORD inheritance = (aclbufp[i].a_type & ACL_DEFAULT) DWORD inheritance = (aclbufp[i].a_type & ACL_DEFAULT)
? INHERIT_ONLY : DONT_INHERIT; ? INHERIT_ONLY : DONT_INHERIT;

View File

@ -44,6 +44,7 @@ SID_IDENTIFIER_AUTHORITY sid_auth[] = {
{SECURITY_NT_AUTHORITY} {SECURITY_NT_AUTHORITY}
}; };
cygsid well_known_null_sid ("S-1-0-0");
cygsid well_known_world_sid ("S-1-1-0"); cygsid well_known_world_sid ("S-1-1-0");
cygsid well_known_local_sid ("S-1-2-0"); cygsid well_known_local_sid ("S-1-2-0");
cygsid well_known_creator_owner_sid ("S-1-3-0"); cygsid well_known_creator_owner_sid ("S-1-3-0");
@ -54,7 +55,7 @@ cygsid well_known_interactive_sid ("S-1-5-4");
cygsid well_known_service_sid ("S-1-5-6"); cygsid well_known_service_sid ("S-1-5-6");
cygsid well_known_authenticated_users_sid ("S-1-5-11"); cygsid well_known_authenticated_users_sid ("S-1-5-11");
cygsid well_known_system_sid ("S-1-5-18"); cygsid well_known_system_sid ("S-1-5-18");
cygsid well_known_admin_sid ("S-1-5-32-544"); cygsid well_known_admins_sid ("S-1-5-32-544");
char * char *
cygsid::string (char *nsidstr) const cygsid::string (char *nsidstr) const

View File

@ -456,7 +456,7 @@ get_group_sidlist (const char *logonserver, cygsidlist &grp_list,
if (usersid == well_known_system_sid) if (usersid == well_known_system_sid)
{ {
grp_list += well_known_system_sid; grp_list += well_known_system_sid;
grp_list += well_known_admin_sid; grp_list += well_known_admins_sid;
} }
else else
{ {
@ -626,10 +626,10 @@ get_dacl (PACL acl, cygsid usersid, cygsidlist &grp_list)
__seterrno (); __seterrno ();
return FALSE; return FALSE;
} }
if (grp_list.contains (well_known_admin_sid)) if (grp_list.contains (well_known_admins_sid))
{ {
if (!AddAccessAllowedAce(acl, ACL_REVISION, GENERIC_ALL, if (!AddAccessAllowedAce(acl, ACL_REVISION, GENERIC_ALL,
well_known_admin_sid)) well_known_admins_sid))
{ {
__seterrno (); __seterrno ();
return FALSE; return FALSE;
@ -1162,15 +1162,24 @@ get_nt_attribute (const char *file, int *attribute,
*flags |= S_IXOTH *flags |= S_IXOTH
| ((!(*anti & S_IXGRP)) ? S_IXGRP : 0) | ((!(*anti & S_IXGRP)) ? S_IXGRP : 0)
| ((!(*anti & S_IXUSR)) ? S_IXUSR : 0); | ((!(*anti & S_IXUSR)) ? S_IXUSR : 0);
/* Sticky bit for directories according to linux rules. */
if (!(ace->Mask & FILE_DELETE_CHILD)
&& S_ISDIR(*attribute)
&& !(*anti & S_ISVTX))
*flags |= S_ISVTX;
} }
if ((*attribute & S_IFDIR) &&
(ace->Mask & (FILE_WRITE_DATA | FILE_EXECUTE | FILE_DELETE_CHILD))
== (FILE_WRITE_DATA | FILE_EXECUTE))
*flags |= S_ISVTX;
}
else if (ace_sid == well_known_null_sid)
{
/* Read SUID, SGID and VTX bits from NULL ACE. */
if (ace->Mask & FILE_READ_DATA)
*flags |= S_ISVTX;
if (ace->Mask & FILE_WRITE_DATA)
*flags |= S_ISGID;
if (ace->Mask & FILE_APPEND_DATA)
*flags |= S_ISUID;
} }
} }
*attribute &= ~(S_IRWXU|S_IRWXG|S_IRWXO|S_ISVTX); *attribute &= ~(S_IRWXU | S_IRWXG | S_IRWXO | S_ISVTX | S_ISGID | S_ISUID);
*attribute |= allow; *attribute |= allow;
*attribute &= ~deny; *attribute &= ~deny;
syscall_printf ("file: %s %x, uid %d, gid %d", file, *attribute, uid, gid); syscall_printf ("file: %s %x, uid %d, gid %d", file, *attribute, uid, gid);
@ -1335,16 +1344,6 @@ alloc_sd (uid_t uid, gid_t gid, const char *logsrv, int attribute,
return NULL; return NULL;
} }
/*
* VTX bit may only be set if executable for `other' is set.
* For correct handling under WinNT, FILE_DELETE_CHILD has to
* be (un)set in each ACE.
*/
if (!(attribute & S_IXOTH))
attribute &= ~S_ISVTX;
if (!(attribute & S_IFDIR))
attribute |= S_ISVTX;
/* From here fill ACL. */ /* From here fill ACL. */
size_t acl_len = sizeof (ACL); size_t acl_len = sizeof (ACL);
int ace_off = 0; int ace_off = 0;
@ -1355,10 +1354,11 @@ alloc_sd (uid_t uid, gid_t gid, const char *logsrv, int attribute,
if (attribute & S_IRUSR) if (attribute & S_IRUSR)
owner_allow |= FILE_GENERIC_READ; owner_allow |= FILE_GENERIC_READ;
if (attribute & S_IWUSR) if (attribute & S_IWUSR)
owner_allow |= FILE_GENERIC_WRITE | DELETE; owner_allow |= FILE_GENERIC_WRITE;
if (attribute & S_IXUSR) if (attribute & S_IXUSR)
owner_allow |= FILE_GENERIC_EXECUTE; owner_allow |= FILE_GENERIC_EXECUTE;
if (!(attribute & S_ISVTX)) if ((attribute & (S_IFDIR | S_IWUSR | S_IXUSR))
== (S_IFDIR | S_IWUSR | S_IXUSR))
owner_allow |= FILE_DELETE_CHILD; owner_allow |= FILE_DELETE_CHILD;
/* Construct allow attribute for group. */ /* Construct allow attribute for group. */
@ -1367,10 +1367,11 @@ alloc_sd (uid_t uid, gid_t gid, const char *logsrv, int attribute,
if (attribute & S_IRGRP) if (attribute & S_IRGRP)
group_allow |= FILE_GENERIC_READ; group_allow |= FILE_GENERIC_READ;
if (attribute & S_IWGRP) if (attribute & S_IWGRP)
group_allow |= STANDARD_RIGHTS_WRITE | FILE_GENERIC_WRITE | DELETE; group_allow |= STANDARD_RIGHTS_WRITE | FILE_GENERIC_WRITE;
if (attribute & S_IXGRP) if (attribute & S_IXGRP)
group_allow |= FILE_GENERIC_EXECUTE; group_allow |= FILE_GENERIC_EXECUTE;
if (!(attribute & S_ISVTX)) if ((attribute & (S_IFDIR | S_IWGRP | S_IXGRP))
== (S_IFDIR | S_IWGRP | S_IXGRP))
group_allow |= FILE_DELETE_CHILD; group_allow |= FILE_DELETE_CHILD;
/* Construct allow attribute for everyone. */ /* Construct allow attribute for everyone. */
@ -1379,12 +1380,26 @@ alloc_sd (uid_t uid, gid_t gid, const char *logsrv, int attribute,
if (attribute & S_IROTH) if (attribute & S_IROTH)
other_allow |= FILE_GENERIC_READ; other_allow |= FILE_GENERIC_READ;
if (attribute & S_IWOTH) if (attribute & S_IWOTH)
other_allow |= STANDARD_RIGHTS_WRITE | FILE_GENERIC_WRITE | DELETE; other_allow |= STANDARD_RIGHTS_WRITE | FILE_GENERIC_WRITE;
if (attribute & S_IXOTH) if (attribute & S_IXOTH)
other_allow |= FILE_GENERIC_EXECUTE; other_allow |= FILE_GENERIC_EXECUTE;
if (!(attribute & S_ISVTX)) if ((attribute & (S_IFDIR | S_IWOTH | S_IXOTH))
== (S_IFDIR | S_IWOTH | S_IXOTH)
&& !(attribute & S_ISVTX))
other_allow |= FILE_DELETE_CHILD; other_allow |= FILE_DELETE_CHILD;
/* Construct SUID, SGID and VTX bits in NULL ACE. */
DWORD null_allow = 0L;
if (attribute & (S_ISUID | S_ISGID | S_ISVTX))
{
if (attribute & S_ISUID)
null_allow |= FILE_APPEND_DATA;
if (attribute & S_ISGID)
null_allow |= FILE_WRITE_DATA;
if (attribute & S_ISVTX)
null_allow |= FILE_READ_DATA;
}
/* Construct deny attributes for owner and group. */ /* Construct deny attributes for owner and group. */
DWORD owner_deny = 0; DWORD owner_deny = 0;
if (is_grp_member (uid, gid)) if (is_grp_member (uid, gid))
@ -1420,7 +1435,7 @@ alloc_sd (uid_t uid, gid_t gid, const char *logsrv, int attribute,
if (owner_deny if (owner_deny
&& !add_access_denied_ace (acl, ace_off++, owner_deny, && !add_access_denied_ace (acl, ace_off++, owner_deny,
owner_sid, acl_len, inherit)) owner_sid, acl_len, inherit))
return NULL; return NULL;
/* Set allow ACE for owner. */ /* Set allow ACE for owner. */
if (!add_access_allowed_ace (acl, ace_off++, owner_allow, if (!add_access_allowed_ace (acl, ace_off++, owner_allow,
owner_sid, acl_len, inherit)) owner_sid, acl_len, inherit))
@ -1429,7 +1444,7 @@ alloc_sd (uid_t uid, gid_t gid, const char *logsrv, int attribute,
if (group_deny if (group_deny
&& !add_access_denied_ace (acl, ace_off++, group_deny, && !add_access_denied_ace (acl, ace_off++, group_deny,
group_sid, acl_len, inherit)) group_sid, acl_len, inherit))
return NULL; return NULL;
/* Set allow ACE for group. */ /* Set allow ACE for group. */
if (!add_access_allowed_ace (acl, ace_off++, group_allow, if (!add_access_allowed_ace (acl, ace_off++, group_allow,
group_sid, acl_len, inherit)) group_sid, acl_len, inherit))
@ -1439,6 +1454,11 @@ alloc_sd (uid_t uid, gid_t gid, const char *logsrv, int attribute,
if (!add_access_allowed_ace (acl, ace_off++, other_allow, if (!add_access_allowed_ace (acl, ace_off++, other_allow,
well_known_world_sid, acl_len, inherit)) well_known_world_sid, acl_len, inherit))
return NULL; return NULL;
/* Set null ACE for special bits. */
if (null_allow
&& !add_access_allowed_ace (acl, ace_off++, null_allow,
well_known_null_sid, acl_len, inherit))
return NULL;
/* Get owner and group from current security descriptor. */ /* Get owner and group from current security descriptor. */
PSID cur_owner_sid = NULL; PSID cur_owner_sid = NULL;
@ -1463,7 +1483,8 @@ alloc_sd (uid_t uid, gid_t gid, const char *logsrv, int attribute,
|| (owner_sid && ace_sid == owner_sid) || (owner_sid && ace_sid == owner_sid)
|| (cur_group_sid && ace_sid == cur_group_sid) || (cur_group_sid && ace_sid == cur_group_sid)
|| (group_sid && ace_sid == group_sid) || (group_sid && ace_sid == group_sid)
|| (ace_sid == well_known_world_sid)) || (ace_sid == well_known_world_sid)
|| (ace_sid == well_known_null_sid))
continue; continue;
/* /*
* Add unrelated ACCESS_DENIED_ACE to the beginning but * Add unrelated ACCESS_DENIED_ACE to the beginning but

View File

@ -131,6 +131,7 @@ public:
} }
}; };
extern cygsid well_known_null_sid;
extern cygsid well_known_world_sid; extern cygsid well_known_world_sid;
extern cygsid well_known_local_sid; extern cygsid well_known_local_sid;
extern cygsid well_known_creator_owner_sid; extern cygsid well_known_creator_owner_sid;
@ -141,7 +142,7 @@ extern cygsid well_known_interactive_sid;
extern cygsid well_known_service_sid; extern cygsid well_known_service_sid;
extern cygsid well_known_authenticated_users_sid; extern cygsid well_known_authenticated_users_sid;
extern cygsid well_known_system_sid; extern cygsid well_known_system_sid;
extern cygsid well_known_admin_sid; extern cygsid well_known_admins_sid;
inline BOOL inline BOOL
legal_sid_type (SID_NAME_USE type) legal_sid_type (SID_NAME_USE type)

View File

@ -249,7 +249,7 @@ sec_user (PVOID sa_buf, PSID sid2, BOOL inherit)
size_t acl_len = sizeof (ACL) size_t acl_len = sizeof (ACL)
+ 4 * (sizeof (ACCESS_ALLOWED_ACE) - sizeof (DWORD)) + 4 * (sizeof (ACCESS_ALLOWED_ACE) - sizeof (DWORD))
+ GetLengthSid (sid) + GetLengthSid (sid)
+ GetLengthSid (well_known_admin_sid) + GetLengthSid (well_known_admins_sid)
+ GetLengthSid (well_known_system_sid) + GetLengthSid (well_known_system_sid)
+ GetLengthSid (well_known_creator_owner_sid); + GetLengthSid (well_known_creator_owner_sid);
if (sid2) if (sid2)
@ -266,7 +266,7 @@ sec_user (PVOID sa_buf, PSID sid2, BOOL inherit)
if (! AddAccessAllowedAce (acl, ACL_REVISION, if (! AddAccessAllowedAce (acl, ACL_REVISION,
SPECIFIC_RIGHTS_ALL | STANDARD_RIGHTS_ALL, SPECIFIC_RIGHTS_ALL | STANDARD_RIGHTS_ALL,
well_known_admin_sid)) well_known_admins_sid))
debug_printf ("AddAccessAllowedAce(admin) %E"); debug_printf ("AddAccessAllowedAce(admin) %E");
if (! AddAccessAllowedAce (acl, ACL_REVISION, if (! AddAccessAllowedAce (acl, ACL_REVISION,