From eceee297d5c2f508e247f803b32bf4817716bc38 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Wed, 5 Jun 2002 11:56:56 +0000 Subject: * grp.cc (read_etc_group): When emulating nonexisting group file on NT systems, read primary group SID from process token. Use that info to create correct group entry. On error or on 9x systems fallback to emulating Administrators group as before. (read_etc_passwd): When emulating nonexisting passwd file on NT systems, read user and primary group SID from process token. Use that info to create correct passwd entry. On error or on 9x systems fallback to emulating user with Administrator user id and Administrators group as before. --- winsup/cygwin/grp.cc | 52 +++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 11 deletions(-) (limited to 'winsup/cygwin/grp.cc') diff --git a/winsup/cygwin/grp.cc b/winsup/cygwin/grp.cc index 13f74dd64..25d2ff864 100644 --- a/winsup/cygwin/grp.cc +++ b/winsup/cygwin/grp.cc @@ -171,19 +171,49 @@ read_etc_group () SID_NAME_USE acType; static char linebuf [200]; - debug_printf ("Emulating /etc/group"); - strncpy (group_name, "Administrators", sizeof (group_name)); - if (! LookupAccountSidA (NULL, well_known_admins_sid, group_name, - &group_name_len, domain_name, - &domain_name_len, &acType)) + if (wincap.has_security ()) { - strcpy (group_name, "unknown"); - debug_printf ("Failed to get local admins group name. %E"); + HANDLE ptok; + cygsid tg; + DWORD siz; + + if (OpenProcessToken (GetCurrentProcess (), TOKEN_QUERY, &ptok)) + { + if (GetTokenInformation (ptok, TokenPrimaryGroup, &tg, + sizeof tg, &siz) + && LookupAccountSidA (NULL, tg, group_name, + &group_name_len, domain_name, + &domain_name_len, &acType)) + { + char strbuf[100]; + snprintf (linebuf, sizeof (linebuf), "%s:%s:%u:", + group_name, + tg.string (strbuf), + *GetSidSubAuthority(tg, + *GetSidSubAuthorityCount(tg) - 1)); + debug_printf ("Emulating /etc/group: %s", linebuf); + add_grp_line (linebuf); + group_state = emulated; + } + CloseHandle (ptok); + } + } + if (group_state != emulated) + { + strncpy (group_name, "Administrators", sizeof (group_name)); + if (!LookupAccountSidA (NULL, well_known_admins_sid, group_name, + &group_name_len, domain_name, + &domain_name_len, &acType)) + { + strcpy (group_name, "unknown"); + debug_printf ("Failed to get local admins group name. %E"); + } + snprintf (linebuf, sizeof (linebuf), "%s::%u:", group_name, + (unsigned) DEFAULT_GID); + debug_printf ("Emulating /etc/group: %s", linebuf); + add_grp_line (linebuf); + group_state = emulated; } - snprintf (linebuf, sizeof (linebuf), "%s::%u:\n", group_name, - (unsigned) DEFAULT_GID); - add_grp_line (linebuf); - group_state = emulated; } } -- cgit v1.2.3