* 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.
This commit is contained in:
Corinna Vinschen 2002-06-21 12:37:51 +00:00
parent f42d18eaeb
commit dd0208eb34
2 changed files with 38 additions and 17 deletions

View File

@ -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.

View File

@ -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;