diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2002-06-21 12:37:51 +0000 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2002-06-21 12:37:51 +0000 |
commit | dd0208eb34be4a5cc1cd6377d43c3dfba1736bdf (patch) | |
tree | a8d2aed61e2fa18a319f4a7719d4f7809282debe | |
parent | f42d18eaeb9ac67414fef997cc66ab0795f57bab (diff) | |
download | newlib-dd0208eb34be4a5cc1cd6377d43c3dfba1736bdf.zip newlib-dd0208eb34be4a5cc1cd6377d43c3dfba1736bdf.tar.gz newlib-dd0208eb34be4a5cc1cd6377d43c3dfba1736bdf.tar.bz2 |
* security.cc (alloc_sd): Remove unnecessary retrieval of owner name.
Check uid for current user first and use SIDs from cygheap if so.
Set errno to EINVAL if user SID isn't retrievable. Just print user SID
as debug output.
Don't bail out if group SID isn't retrievable. Change debug output
appropriately.
-rw-r--r-- | winsup/cygwin/ChangeLog | 9 | ||||
-rw-r--r-- | winsup/cygwin/security.cc | 46 |
2 files changed, 38 insertions, 17 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 4419ac6..e60fe84 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,12 @@ +2002-06-21 Corinna Vinschen <corinna@vinschen.de> + + * security.cc (alloc_sd): Remove unnecessary retrieval of owner name. + Check uid for current user first and use SIDs from cygheap if so. + Set errno to EINVAL if user SID isn't retrievable. Just print user SID + as debug output. + Don't bail out if group SID isn't retrievable. Change debug output + appropriately. + 2002-06-21 Christopher Faylor <cgf@redhat.com> * errno.cc: Change text description for EBADF throughout. diff --git a/winsup/cygwin/security.cc b/winsup/cygwin/security.cc index 473e62f..3cd0588 100644 --- a/winsup/cygwin/security.cc +++ b/winsup/cygwin/security.cc @@ -1367,27 +1367,39 @@ alloc_sd (__uid32_t uid, __gid32_t gid, int attribute, return NULL; } - /* Get SID and name of new owner. */ - char owner[UNLEN + 1]; + /* Get SID of owner. */ cygsid owner_sid; - struct passwd *pw = getpwuid32 (uid); - strcpy (owner, pw ? pw->pw_name : getlogin ()); - if (!pw || !owner_sid.getfrompw (pw)) - return NULL; - debug_printf ("owner: %s [%d]", owner, - *GetSidSubAuthority (owner_sid, - *GetSidSubAuthorityCount (owner_sid) - 1)); + /* Check for current user first */ + if (uid == myself->uid) + owner_sid = cygheap->user.sid (); + else if (uid == cygheap->user.orig_uid) + owner_sid = cygheap->user.orig_sid (); + else + { + /* Otherwise retrieve user data from /etc/passwd */ + struct passwd *pw = getpwuid32 (uid); + if (!pw) + { + debug_printf ("no /etc/passwd entry for %d", uid); + set_errno (EINVAL); + return NULL; + } + else if (!owner_sid.getfrompw (pw)) + { + debug_printf ("no SID for user %d", uid); + set_errno (EINVAL); + return NULL; + } + } + owner_sid.debug_print ("alloc_sd: owner SID ="); - /* Get SID and name of new group. */ + /* Get SID of new group. */ cygsid group_sid (NO_SID); struct __group32 *grp = getgrgid32 (gid); - if (grp) - { - if (!grp || !group_sid.getfromgr (grp)) - return NULL; - } - else - debug_printf ("no group"); + if (!grp) + debug_printf ("no /etc/group entry for %d", gid); + else if (!group_sid.getfromgr (grp)) + debug_printf ("no SID for group %d", gid); /* Initialize local security descriptor. */ SECURITY_DESCRIPTOR sd; |