public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org>
To: cygwin-cvs@sourceware.org
Subject: [newlib-cygwin] Cygwin: passwd/group: store account name case correct
Date: Wed, 13 Feb 2019 10:14:00 -0000	[thread overview]
Message-ID: <20190213101402.21245.qmail@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=9a3cc77b2afc52a2faa5e4daeb59dfd4506c0693

commit 9a3cc77b2afc52a2faa5e4daeb59dfd4506c0693
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Wed Feb 13 11:10:55 2019 +0100

    Cygwin: passwd/group: store account name case correct
    
    When looking up valid accounts by name, LookupAccountName returns
    a SID and a case-correct domain name.  However, the name was input
    and LookupAccountName is case-insensitive, so the name is not
    necessarily written the same way as in SAM or AD.
    
    Fix that by doing a reverse lookup on the just fetched SID.  This
    fetches the account name in the correct case.  Override the
    incoming name with the case correct name from LookupAccountSid.
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/release/3.0 |  4 ++++
 winsup/cygwin/uinfo.cc    | 10 ++++++++++
 2 files changed, 14 insertions(+)

diff --git a/winsup/cygwin/release/3.0 b/winsup/cygwin/release/3.0
index da35755..444e71a 100644
--- a/winsup/cygwin/release/3.0
+++ b/winsup/cygwin/release/3.0
@@ -109,3 +109,7 @@ Bug Fixes
 
 - Fix O_APPEND handling on files when calling non-Cygwin applications
   Addresses: https://cygwin.com/ml/cygwin/2019-02/msg00081.html
+
+- Fix case correctness of passwd/group entries fetched via getpwnam
+  or getgrnam.
+  Addresses: https://cygwin.com/ml/cygwin/2019-02/msg00109.html
diff --git a/winsup/cygwin/uinfo.cc b/winsup/cygwin/uinfo.cc
index 22cae5e..4a5fa34 100644
--- a/winsup/cygwin/uinfo.cc
+++ b/winsup/cygwin/uinfo.cc
@@ -2046,6 +2046,16 @@ pwdgrp::fetch_account_from_windows (fetch_user_arg_t &arg, cyg_ldap *pldap)
       /* We can skip the backslash in the rest of this function. */
       if (p)
 	name = p + 1;
+      /* Reverse lookup name from sid to make sure the username in
+	 our passwd/group data is written exactly as in the user DB. */
+      nlen = UNLEN + 1;
+      dlen = DNLEN + 1;
+      ret = LookupAccountSidW (NULL, sid, name, &nlen, dom, &dlen, &acc_type);
+      if (!ret)
+	{
+	  system_printf ("LookupAccountNameW (%W), %E", name);
+	  return NULL;
+	}
       /* Last but not least, some validity checks on the name style. */
       if (!fq_name)
 	{


                 reply	other threads:[~2019-02-13 10:14 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190213101402.21245.qmail@sourceware.org \
    --to=corinna@sourceware.org \
    --cc=cygwin-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).