summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--winsup/cygwin/ChangeLog9
-rw-r--r--winsup/cygwin/security.cc46
2 files changed, 38 insertions, 17 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 4419ac654..e60fe8438 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 473e62ff9..3cd0588d8 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;