Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'winsup/cygwin/passwd.cc')
-rw-r--r--winsup/cygwin/passwd.cc48
1 files changed, 40 insertions, 8 deletions
diff --git a/winsup/cygwin/passwd.cc b/winsup/cygwin/passwd.cc
index ac1ecf8f0..b251264b7 100644
--- a/winsup/cygwin/passwd.cc
+++ b/winsup/cygwin/passwd.cc
@@ -160,14 +160,46 @@ read_etc_passwd ()
}
else
{
- static char linebuf[400];
-
- debug_printf ("Emulating /etc/passwd");
- snprintf (linebuf, sizeof (linebuf), "%s::%u:%u::%s:/bin/sh",
- cygheap->user.name (), (unsigned) DEFAULT_UID,
- (unsigned) DEFAULT_GID, getenv ("HOME") ?: "/");
- add_pwd_line (linebuf);
- passwd_state = emulated;
+ static char linebuf[1024];
+
+ if (wincap.has_security ())
+ {
+ HANDLE ptok;
+ cygsid tu, tg;
+ DWORD siz;
+
+ if (OpenProcessToken (GetCurrentProcess (), TOKEN_QUERY, &ptok))
+ {
+ if (GetTokenInformation (ptok, TokenUser, &tu, sizeof tu,
+ &siz)
+ && GetTokenInformation (ptok, TokenPrimaryGroup, &tg,
+ sizeof tg, &siz))
+ {
+ char strbuf[100];
+ snprintf (linebuf, sizeof (linebuf),
+ "%s::%u:%u:%s:%s:/bin/sh",
+ cygheap->user.name (),
+ *GetSidSubAuthority(tu,
+ *GetSidSubAuthorityCount(tu) - 1),
+ *GetSidSubAuthority(tg,
+ *GetSidSubAuthorityCount(tg) - 1),
+ tu.string (strbuf), getenv ("HOME") ?: "/");
+ debug_printf ("Emulating /etc/passwd: %s", linebuf);
+ add_pwd_line (linebuf);
+ passwd_state = emulated;
+ }
+ CloseHandle (ptok);
+ }
+ }
+ if (passwd_state != emulated)
+ {
+ snprintf (linebuf, sizeof (linebuf), "%s::%u:%u::%s:/bin/sh",
+ cygheap->user.name (), (unsigned) DEFAULT_UID,
+ (unsigned) DEFAULT_GID, getenv ("HOME") ?: "/");
+ debug_printf ("Emulating /etc/passwd: %s", linebuf);
+ add_pwd_line (linebuf);
+ passwd_state = emulated;
+ }
}
}