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

commit 03cd2c4efa191c2855591e23fec1e240460a0048
Author: Corinna Vinschen <[email protected]>
Date:   Tue Aug 28 11:26:52 2018 +0200

    Cygwin: Accommodate logon sessions on Windows 10
    
    Starting with Windows 10, LookupAccountSid/Name return valid
    info for the login session with new SID_NAME_USE value
    SidTypeLogonSession.  To return the same info as on pre-Windows 10,
    we have to handle this type.
    
    Signed-off-by: Corinna Vinschen <[email protected]>

Diff:
---
 winsup/cygwin/release/2.11.0 |  3 +++
 winsup/cygwin/uinfo.cc       | 32 +++++++++++++++++++++++++++++++-
 2 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/winsup/cygwin/release/2.11.0 b/winsup/cygwin/release/2.11.0
index 8f308c8..ca6c8b5 100644
--- a/winsup/cygwin/release/2.11.0
+++ b/winsup/cygwin/release/2.11.0
@@ -78,3 +78,6 @@ Bug Fixes
 - Fix handling of unknown accounts in file ACLs.  Add name->SID
   conversion for (most) self-constructed account names.
   Addresses: https://cygwin.com/ml/cygwin/2018-08/msg00295.html
+
+- Correctly handle Logon Session accounts on Windows 10.
+  Addresses: Found during debugging
diff --git a/winsup/cygwin/uinfo.cc b/winsup/cygwin/uinfo.cc
index eceacca..c2f4803 100644
--- a/winsup/cygwin/uinfo.cc
+++ b/winsup/cygwin/uinfo.cc
@@ -1821,6 +1821,14 @@ pwdgrp::construct_sid_from_name (cygsid &sid, wchar_t 
*name, wchar_t *sep)
        }
       return false;
     }
+  if (!sep && wcscmp (name, L"CurrentSession") == 0)
+    {
+      get_logon_sid ();
+      if (PSID (logon_sid) == NO_SID)
+       return false;
+      sid = logon_sid;
+      return true;
+    }
   if (!sep && wcscmp (name, L"Authentication authority asserted identity") == 
0)
     {
       sid.create (18, 1, 1);
@@ -1903,6 +1911,8 @@ pwdgrp::construct_sid_from_name (cygsid &sid, wchar_t 
*name, wchar_t *sep)
   return false;
 }
 
+/* CV 2018-08-28: SidTypeLogonSession is not yet defined in Mingw64. */
+#define SidTypeLogonSession 11
 
 char *
 pwdgrp::fetch_account_from_windows (fetch_user_arg_t &arg, cyg_ldap *pldap)
@@ -2268,7 +2278,7 @@ pwdgrp::fetch_account_from_windows (fetch_user_arg_t 
&arg, cyg_ldap *pldap)
       if (acc_type == SidTypeUser
          && (sid_sub_auth_count (sid) <= 3 || sid_id_auth (sid) == 11))
        acc_type = SidTypeWellKnownGroup;
-      switch (acc_type)
+      switch ((int) acc_type)
        {
        case SidTypeUser:
          if (is_group ())
@@ -2598,6 +2608,26 @@ pwdgrp::fetch_account_from_windows (fetch_user_arg_t 
&arg, cyg_ldap *pldap)
          if (uid == 0x10000 || uid == 0x10100)
            return NULL;
          break;
+       case SidTypeLogonSession:
+         /* Starting with Windows 10, LookupAccountSid/Name return valid
+            info for the login session with new SID_NAME_USE value
+            SidTypeLogonSession.  To return the same info as on
+            pre-Windows 10, we have to handle this type explicitely here
+            now and convert the name to "CurrentSession". */
+         get_logon_sid ();
+         if (PSID (logon_sid) == NO_SID)
+           return NULL;
+         if (RtlEqualSid (sid, logon_sid))
+           {
+             uid = 0xfff;
+             wcpcpy (name = namebuf, L"CurrentSession");
+           }
+         else
+           {
+             uid = 0xffe;
+             wcpcpy (name = namebuf, L"OtherSession");
+           }
+         break;
        case SidTypeLabel:
          uid = 0x60000 + sid_sub_auth_rid (sid);
          fully_qualified_name = cygheap->pg.nss_prefix_always ();

Reply via email to