Cygwin: respect PC_SYM_FOLLOW and PC_SYM_NOFOLLOW_REP with inner links.
The new GetFinalPathNameW handling for native symlinks in inner path components is disabled if caller doesn't want to follow symlinks, or doesn't want to follow reparse points.
This commit is contained in:
parent
d0e42141b8
commit
4fca7b0da6
|
@ -722,9 +722,10 @@ path_conv::check (const char *src, unsigned opt,
|
||||||
int symlen = 0;
|
int symlen = 0;
|
||||||
|
|
||||||
/* Make sure to check certain flags on last component only. */
|
/* Make sure to check certain flags on last component only. */
|
||||||
for (unsigned pc_flags = opt & (PC_NO_ACCESS_CHECK | PC_KEEP_HANDLE);
|
for (unsigned pc_flags = opt & (PC_NO_ACCESS_CHECK | PC_KEEP_HANDLE
|
||||||
|
| PC_SYM_FOLLOW | PC_SYM_NOFOLLOW_REP);
|
||||||
;
|
;
|
||||||
pc_flags = 0)
|
pc_flags = opt & (PC_SYM_FOLLOW | PC_SYM_NOFOLLOW_REP))
|
||||||
{
|
{
|
||||||
const suffix_info *suff;
|
const suffix_info *suff;
|
||||||
char *full_path;
|
char *full_path;
|
||||||
|
@ -3480,48 +3481,49 @@ restart:
|
||||||
goto file_not_symlink;
|
goto file_not_symlink;
|
||||||
}
|
}
|
||||||
#endif /* __i386__ */
|
#endif /* __i386__ */
|
||||||
{
|
if ((pc_flags & (PC_SYM_FOLLOW | PC_SYM_NOFOLLOW_REP)) == PC_SYM_FOLLOW)
|
||||||
PWCHAR fpbuf = tp.w_get ();
|
{
|
||||||
DWORD ret;
|
PWCHAR fpbuf = tp.w_get ();
|
||||||
|
DWORD ret;
|
||||||
|
|
||||||
ret = GetFinalPathNameByHandleW (h, fpbuf, NT_MAX_PATH, 0);
|
ret = GetFinalPathNameByHandleW (h, fpbuf, NT_MAX_PATH, 0);
|
||||||
if (ret)
|
if (ret)
|
||||||
{
|
{
|
||||||
UNICODE_STRING fpath;
|
UNICODE_STRING fpath;
|
||||||
|
|
||||||
RtlInitCountedUnicodeString (&fpath, fpbuf, ret * sizeof (WCHAR));
|
RtlInitCountedUnicodeString (&fpath, fpbuf, ret * sizeof (WCHAR));
|
||||||
fpbuf[1] = L'?'; /* \\?\ --> \??\ */
|
fpbuf[1] = L'?'; /* \\?\ --> \??\ */
|
||||||
if (!RtlEqualUnicodeString (&upath, &fpath, !!ci_flag))
|
if (!RtlEqualUnicodeString (&upath, &fpath, !!ci_flag))
|
||||||
{
|
{
|
||||||
issymlink = true;
|
issymlink = true;
|
||||||
/* upath.Buffer is big enough and unused from this point on.
|
/* upath.Buffer is big enough and unused from this point on.
|
||||||
Reuse it here, avoiding yet another buffer allocation. */
|
Reuse it here, avoiding yet another buffer allocation. */
|
||||||
char *nfpath = (char *) upath.Buffer;
|
char *nfpath = (char *) upath.Buffer;
|
||||||
sys_wcstombs (nfpath, NT_MAX_PATH, fpbuf);
|
sys_wcstombs (nfpath, NT_MAX_PATH, fpbuf);
|
||||||
res = posixify (nfpath);
|
res = posixify (nfpath);
|
||||||
|
|
||||||
/* If the incoming path consisted of a drive prefix only,
|
/* If the incoming path consisted of a drive prefix only,
|
||||||
we just handle a virtual drive, created with, e.g.
|
we just handle a virtual drive, created with, e.g.
|
||||||
|
|
||||||
subst X: C:\foo\bar
|
subst X: C:\foo\bar
|
||||||
|
|
||||||
Treat it like a symlink. This is required to tell an
|
Treat it like a symlink. This is required to tell an
|
||||||
lstat caller that the "drive" is actually pointing
|
lstat caller that the "drive" is actually pointing
|
||||||
somewhere else, thus, it's a symlink in POSIX speak. */
|
somewhere else, thus, it's a symlink in POSIX speak. */
|
||||||
if (upath.Length == 14) /* \??\X:\ */
|
if (upath.Length == 14) /* \??\X:\ */
|
||||||
{
|
{
|
||||||
fileattr &= ~FILE_ATTRIBUTE_DIRECTORY;
|
fileattr &= ~FILE_ATTRIBUTE_DIRECTORY;
|
||||||
path_flags |= PATH_SYMLINK;
|
path_flags |= PATH_SYMLINK;
|
||||||
}
|
}
|
||||||
/* For final paths differing in inner path components return
|
/* For final paths differing in inner path components return
|
||||||
length as negative value. This informs path_conv::check
|
length as negative value. This informs path_conv::check
|
||||||
to skip realpath handling on the last path component. */
|
to skip realpath handling on the last path component. */
|
||||||
else
|
else
|
||||||
res = -res;
|
res = -res;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Normal file. */
|
/* Normal file. */
|
||||||
file_not_symlink:
|
file_not_symlink:
|
||||||
|
|
Loading…
Reference in New Issue