From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 4DA173858C53; Fri, 2 Dec 2022 15:52:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4DA173858C53 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1669996363; bh=ph7CHgS44ljWgWDrQiSPYmLi7GP/PTSwky05vgxjsEo=; h=From:To:Subject:Date:From; b=KcgwRaeLdOrPNXc1Usj24HfL+bitgMgw9gikpjRirKVvopb+LQNg9AH7bQE83XIK2 jME1XPUT7+F5GszeVTnhZBnwvc5BEVZI92gFE6e8c5aan8KyPFAE+r2Yr+THmxCiDD qbfWg9doghKDuGXaAMMAyV7DniH7InNqmevh9SgM= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: uinfo: don't special case current user X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/master X-Git-Oldrev: dc7b67316d01c77d81ad6561869b9b89527c2ac8 X-Git-Newrev: a5bcfe616c7e8f78f464bf045595d8213244876a Message-Id: <20221202155243.4DA173858C53@sourceware.org> Date: Fri, 2 Dec 2022 15:52:43 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3Da5bcfe616c7= e8f78f464bf045595d8213244876a commit a5bcfe616c7e8f78f464bf045595d8213244876a Author: Corinna Vinschen AuthorDate: Fri Dec 2 16:49:47 2022 +0100 Commit: Corinna Vinschen CommitDate: Fri Dec 2 16:49:47 2022 +0100 Cygwin: uinfo: don't special case current user =20 fetch_account_from_windows shortcuts the current user in that it takes the user's domain SID and just adds the matching RID from the token's primary group to create a group SID. =20 How wrong this is can be very simply reproduced: =20 Assuming you run a native process, like cmd, with primary group set to the Administrators builtin group. Run Cygwin's id(1) as child process. id(1) will print a non-existent group as primary group and also add it to the group list. =20 This can only be avoided by not special casing the current user and thus not creating a group SID from partial information. =20 Fixes: 6cc7c925ce86 ("(pwdgrp::fetch_account_from_windows): Default pri= mary group for the current user to primary group from user token.") Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/uinfo.cc | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/winsup/cygwin/uinfo.cc b/winsup/cygwin/uinfo.cc index db475d710eb2..6df8c7bbbbe9 100644 --- a/winsup/cygwin/uinfo.cc +++ b/winsup/cygwin/uinfo.cc @@ -1855,7 +1855,6 @@ pwdgrp::fetch_account_from_windows (fetch_user_arg_t = &arg, cyg_ldap *pldap) gid_t gid =3D ILLEGAL_GID; bool is_domain_account =3D true; PCWSTR domain =3D NULL; - bool is_current_user =3D false; char *shell =3D NULL; char *home =3D NULL; char *gecos =3D NULL; @@ -2314,18 +2313,9 @@ pwdgrp::fetch_account_from_windows (fetch_user_arg_t= &arg, cyg_ldap *pldap) uid =3D posix_offset + sid_sub_auth_rid (sid); if (!is_group () && acc_type =3D=3D SidTypeUser) { - /* Default primary group. If the sid is the current user, fetch - the default group from the current user token, otherwise make - the educated guess that the user is in group "Domain Users" - or "None". */ - if (sid =3D=3D cygheap->user.sid ()) - { - is_current_user =3D true; - gid =3D posix_offset - + sid_sub_auth_rid (cygheap->user.groups.pgsid); - } - else - gid =3D posix_offset + DOMAIN_GROUP_RID_USERS; + /* Default primary group. Make the educated guess that the user + is in group "Domain Users" or "None". */ + gid =3D posix_offset + DOMAIN_GROUP_RID_USERS; } =20 if (is_domain_account) @@ -2336,11 +2326,9 @@ pwdgrp::fetch_account_from_windows (fetch_user_arg_t= &arg, cyg_ldap *pldap) /* On AD machines, use LDAP to fetch domain account infos. */ if (cygheap->dom.primary_dns_name ()) { - /* For the current user we got correctly cased username and - the primary group via process token. For any other user - we fetch it from AD and overwrite it. */ - if (!is_current_user - && cldap->fetch_ad_account (sid, false, domain)) + /* Fetch primary group from AD and overwrite the one we + just guessed above. */ + if (cldap->fetch_ad_account (sid, false, domain)) { if ((val =3D cldap->get_account_name ())) wcscpy (name, val);