diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2002-06-05 15:56:56 +0400 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2002-06-05 15:56:56 +0400 |
commit | eceee297d5c2f508e247f803b32bf4817716bc38 (patch) | |
tree | 4cb954c333a09503063aee7f8aabea5b826ef6c7 /winsup/cygwin | |
parent | 38f39368891d83c63e6f4aa3b00b19b80444b041 (diff) |
* 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.
Diffstat (limited to 'winsup/cygwin')
-rw-r--r-- | winsup/cygwin/ChangeLog | 12 | ||||
-rw-r--r-- | winsup/cygwin/grp.cc | 52 | ||||
-rw-r--r-- | winsup/cygwin/passwd.cc | 48 |
3 files changed, 93 insertions, 19 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 95f7d5efd..fc0a07ad9 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,5 +1,17 @@ 2002-06-05 Corinna Vinschen <corinna@vinschen.de> + * 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. + +2002-06-05 Corinna Vinschen <corinna@vinschen.de> + * grp.cc (etc_group): Removed. (parse_grp): Make line parameter nonconst. Don't copy data into new allocated memory. Check for CR instead of LF to accomodate new 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; } } 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; + } } } |