Cygwin: path: Add fallback for DFS mounted drive.
- If UNC path for DFS is mounted to a drive with drive letter, the error "Too many levels of symbolic links" occurs when accessing to that drive. This is because GetDosDeviceW() returns unexpected string such as "\Device\Mup\DfsClient\;Z:000000000003fb89\dfsserver \dfs\linkname" for the mounted UNC path "\??\UNC\fileserver\share". This patch adds a workaround for this issue. Addresses: https://cygwin.com/pipermail/cygwin/2022-March/250979.html
This commit is contained in:
parent
af8a7c13b5
commit
7df94e3b4f
|
@ -3527,7 +3527,7 @@ restart:
|
||||||
int remlen = QueryDosDeviceW (drive, remote, MAX_PATH);
|
int remlen = QueryDosDeviceW (drive, remote, MAX_PATH);
|
||||||
if (remlen < 3)
|
if (remlen < 3)
|
||||||
goto file_not_symlink; /* fallback */
|
goto file_not_symlink; /* fallback */
|
||||||
remlen -= 2;
|
remlen -= 2; /* Two L'\0' */
|
||||||
|
|
||||||
if (remote[remlen - 1] == L'\\')
|
if (remote[remlen - 1] == L'\\')
|
||||||
remlen--;
|
remlen--;
|
||||||
|
@ -3535,20 +3535,27 @@ restart:
|
||||||
UNICODE_STRING rpath;
|
UNICODE_STRING rpath;
|
||||||
RtlInitCountedUnicodeString (&rpath, remote,
|
RtlInitCountedUnicodeString (&rpath, remote,
|
||||||
remlen * sizeof (WCHAR));
|
remlen * sizeof (WCHAR));
|
||||||
|
const USHORT uncp_len =
|
||||||
|
ro_u_uncp.Length / sizeof (WCHAR) - 1;
|
||||||
if (RtlEqualUnicodePathPrefix (&rpath, &ro_u_uncp, TRUE))
|
if (RtlEqualUnicodePathPrefix (&rpath, &ro_u_uncp, TRUE))
|
||||||
remlen -= 6;
|
{
|
||||||
|
remlen -= uncp_len;
|
||||||
|
p = remote + uncp_len;
|
||||||
|
}
|
||||||
else if ((p = wcschr (remote, L';'))
|
else if ((p = wcschr (remote, L';'))
|
||||||
&& p + 3 < remote + remlen
|
&& p + 3 < remote + remlen
|
||||||
&& wcsncmp (p + 1, drive, 2) == 0
|
&& wcsncmp (p + 1, drive, 2) == 0
|
||||||
&& (p = wcschr (p + 3, L'\\')))
|
&& (p = wcschr (p + 3, L'\\')))
|
||||||
remlen -= p - remote - 1;
|
remlen -= p - remote;
|
||||||
else
|
else
|
||||||
goto file_not_symlink; /* fallback */
|
goto file_not_symlink; /* fallback */
|
||||||
|
if (wcsncasecmp (fpath.Buffer + uncp_len, p, remlen))
|
||||||
|
goto file_not_symlink; /* fallback (not expected) */
|
||||||
/* Hackfest */
|
/* Hackfest */
|
||||||
fpath.Buffer[4] = drive[0]; /* Drive letter */
|
fpath.Buffer[4] = drive[0]; /* Drive letter */
|
||||||
fpath.Buffer[5] = L':';
|
fpath.Buffer[5] = L':';
|
||||||
WCHAR *to = fpath.Buffer + 6;
|
WCHAR *to = fpath.Buffer + 6; /* Next to L':' */
|
||||||
WCHAR *from = to + remlen;
|
WCHAR *from = fpath.Buffer + uncp_len + remlen;
|
||||||
memmove (to, from,
|
memmove (to, from,
|
||||||
(wcslen (from) + 1) * sizeof (WCHAR));
|
(wcslen (from) + 1) * sizeof (WCHAR));
|
||||||
fpath.Length -= (from - to) * sizeof (WCHAR);
|
fpath.Length -= (from - to) * sizeof (WCHAR);
|
||||||
|
|
Loading…
Reference in New Issue