public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin/topic/posix_acl_funcs] cygpath: Avoid returning SysWOW64
@ 2016-01-24 10:30 Corinna Vinschen
  0 siblings, 0 replies; only message in thread
From: Corinna Vinschen @ 2016-01-24 10:30 UTC (permalink / raw)
  To: cygwin-cvs

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

commit 79b1b77b1fd1fcb036bbb2a9aeb6667f1cdcc1ef
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Thu Jan 21 18:40:30 2016 +0100

    cygpath: Avoid returning SysWOW64
    
    	On Cygwin 32 running under WOW64:
    
    	When case-correcting the path fetched with -S, the underlying
    	Windows function fetching the normalized path returns the real
    	path C:\Windows\SysWOW64 instead of the path redirection
    	enabled C:\Windows\System32 path.  This breaks using the result
    	of `cygpath -S' to fetch the POSIX path of the network related
    	files under SYSTEMROOT\drivers\etc.  This path is in fact under
    	the *real* C:\Windows\System32 and only mapped into the 32 bit
    	C:\Windows\System32 (aka C:\Windows\SysWOW64) via path redirection.
    	Sounds messy?
    
    	This patch checks if we're running under WOW64.  If so, it
    	changes the path returned by GetSystemDirectoryW from "system32"
    	to "Sysnative".  This in turn is changed to "System32" by
    	NtQueryInformationFile, so we're back to what we need.
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/utils/cygpath.cc | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/winsup/utils/cygpath.cc b/winsup/utils/cygpath.cc
index c0a5276..8df8eaa 100644
--- a/winsup/utils/cygpath.cc
+++ b/winsup/utils/cygpath.cc
@@ -539,6 +539,7 @@ do_sysfolders (char option)
 {
   WCHAR wbuf[MAX_PATH];
   char buf[PATH_MAX];
+  BOOL iswow64 = FALSE;
 
   wbuf[0] = L'\0';
   switch (option)
@@ -581,6 +582,18 @@ do_sysfolders (char option)
 
     case 'S':
       GetSystemDirectoryW (wbuf, MAX_PATH);
+      if (!windows_flag
+	  && IsWow64Process (GetCurrentProcess (), &iswow64) && iswow64)
+	{
+	  /* When calling NtQueryInformationFile(FileNameInformation) on WOW64,
+	     the returned path will point to SysWOW64.  This breaks path
+	     redirection to the network related files under device/etc.  This
+	     here is a bad hack to make sure that the conversion will convert
+	     the case *and* stick to System32. */
+	  PWCHAR last_bs = wcsrchr (wbuf, L'\\');
+	  if (last_bs)
+	    wcpcpy (last_bs + 1, L"Sysnative");
+	}
       break;
 
     case 'W':


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2016-01-24 10:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-24 10:30 [newlib-cygwin/topic/posix_acl_funcs] cygpath: Avoid returning SysWOW64 Corinna Vinschen

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).