[newlib-cygwin] Cygwin: fhandler_process_fd: Fix spacing
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=9ba65ab8b5c5ece442931e585230d1e0422da538 commit 9ba65ab8b5c5ece442931e585230d1e0422da538 Author: Corinna Vinschen Date: Tue Jan 8 21:38:04 2019 +0100 Cygwin: fhandler_process_fd: Fix spacing Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/fhandler_process_fd.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/winsup/cygwin/fhandler_process_fd.cc b/winsup/cygwin/fhandler_process_fd.cc index a9d085a..a3691d9 100644 --- a/winsup/cygwin/fhandler_process_fd.cc +++ b/winsup/cygwin/fhandler_process_fd.cc @@ -70,7 +70,7 @@ fhandler_process_fd::fetch_fh (HANDLE &out_hdl, uint32_t flags) hdl = pc.deserialize (buf); } BOOL ret = DuplicateHandle (proc, hdl, GetCurrentProcess (), &hdl, -0, FALSE, DUPLICATE_SAME_ACCESS); + 0, FALSE, DUPLICATE_SAME_ACCESS); if (proc != GetCurrentProcess ()) CloseHandle (proc); if (!ret)
[newlib-cygwin] Cygwin: remove unused tmpbuf.h
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=2d015e0e68f45d7b1a96e63e39086d35df48344b commit 2d015e0e68f45d7b1a96e63e39086d35df48344b Author: Corinna Vinschen Date: Tue Jan 8 18:49:29 2019 +0100 Cygwin: remove unused tmpbuf.h Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/tmpbuf.h | 25 - 1 file changed, 25 deletions(-) diff --git a/winsup/cygwin/tmpbuf.h b/winsup/cygwin/tmpbuf.h deleted file mode 100644 index 1149ef9..000 --- a/winsup/cygwin/tmpbuf.h +++ /dev/null @@ -1,25 +0,0 @@ -/* tmpbuf.h - -This software is a copyrighted work licensed under the terms of the -Cygwin license. Please consult the file "CYGWIN_LICENSE" for -details. */ - -#ifndef _TMPBUF_H -#define _TMPBUF_H -class tmpbuf -{ - void *buf; -public: - tmpbuf (size_t size = NT_MAX_PATH) - { -buf = calloc (1, size); -if (!buf) - api_fatal ("allocation of temporary buffer failed"); - } - operator void * () {return buf;} - operator char * () {return (char *) buf;} - operator PSECURITY_DESCRIPTOR () {return (PSECURITY_DESCRIPTOR) buf;} - PSECURITY_DESCRIPTOR operator -> () {return (PSECURITY_DESCRIPTOR) buf;} - ~tmpbuf () {free (buf);} -}; -#endif /*_TMPBUF_H*/
[newlib-cygwin] Cygwin: open: workaround reopen file w/ delete disposition set
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=ec36c59f1a9349e690849e393251623f5936408c commit ec36c59f1a9349e690849e393251623f5936408c Author: Corinna Vinschen Date: Tue Jan 8 21:37:43 2019 +0100 Cygwin: open: workaround reopen file w/ delete disposition set On pre-W10 systems there's no way to reopen a file by handle if the delete disposition is set. We try to get around with duplicating the handle. Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/fhandler.cc | 17 + 1 file changed, 17 insertions(+) diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc index 9af08d7..9643373 100644 --- a/winsup/cygwin/fhandler.cc +++ b/winsup/cygwin/fhandler.cc @@ -693,6 +693,23 @@ fhandler_base::open (int flags, mode_t mode) status = NtCreateFile (&fh, access, &attr, &io, NULL, file_attributes, shared, create_disposition, options, p, plen); + /* Pre-W10, we can't open a file by handle with delete disposition + set, so we have to lie our ass off. */ + if (get_handle () && status == STATUS_DELETE_PENDING) +{ + BOOL ret = DuplicateHandle (GetCurrentProcess (), get_handle (), + GetCurrentProcess (), &fh, + access, !(flags & O_CLOEXEC), 0); + if (!ret) + ret = DuplicateHandle (GetCurrentProcess (), get_handle (), + GetCurrentProcess (), &fh, + 0, !(flags & O_CLOEXEC), + DUPLICATE_SAME_ACCESS); + if (!ret) + debug_printf ("DuplicateHandle after STATUS_DELETE_PENDING, %E"); + else + status = STATUS_SUCCESS; +} if (!NT_SUCCESS (status)) { /* Trying to create a directory should return EISDIR, not ENOENT. */
[newlib-cygwin] Cygwin: open: handle O_CLOEXEC when opening file from handle
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=0c545f3264c3d02d3ef785a2e2e9d77ed03f commit 0c545f3264c3d02d3ef785a2e2e9d77ed03f Author: Corinna Vinschen Date: Tue Jan 8 18:50:11 2019 +0100 Cygwin: open: handle O_CLOEXEC when opening file from handle Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/fhandler.cc | 6 +- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc index 9f5e009..9af08d7 100644 --- a/winsup/cygwin/fhandler.cc +++ b/winsup/cygwin/fhandler.cc @@ -555,7 +555,11 @@ fhandler_base::open (int flags, mode_t mode) /* Allow to reopen from handle. This is utilized by open ("/proc/PID/fd/DESCRIPTOR", ...); */ if (get_handle ()) -pc.init_reopen_attr (attr, get_handle ()); +{ + pc.init_reopen_attr (attr, get_handle ()); + if (!(flags & O_CLOEXEC)) + attr.Attributes |= OBJ_INHERIT; +} else pc.get_object_attr (attr, *sec_none_cloexec (flags));
[newlib-cygwin] Cygwin: try_to_bin: don't reopen the file
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=dee6cb133a5876c636ca1c544a5f95167dab5d09 commit dee6cb133a5876c636ca1c544a5f95167dab5d09 Author: Corinna Vinschen Date: Tue Jan 8 21:43:25 2019 +0100 Cygwin: try_to_bin: don't reopen the file So far we reopened the file if it was opened case sensitive to workaround the problem that the recycler could be named in camel back or all upper case, depending on who created it. That's a problem for O_TMPFILE on pre-W10. As soon as the original HANDLE gets closed, delete-on-close is converted to full delete disposition and all useful operations on the file cease to work (STATUS_ACCESS_DENIED or STATUS_FILE_DELETED). To avoid that problem drop the reopen code and check for the exact recycler filename, either $Recycle.Bin or $RECYCLE.BIN, if the file has been opened case sensitive. Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/syscalls.cc | 55 ++- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index cb62a62..fcf2d86 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -232,31 +232,6 @@ try_to_bin (path_conv &pc, HANDLE &fh, ACCESS_MASK access, ULONG flags) them into the recycler. */ if (pfni->FileNameLength == 2) /* root dir. */ goto out; - /* The recycler name is $Recycler.Bin by default. If the recycler dir - disappeared for some reason, the shell32.dll recreates the directory in - all upper case. So, we never know beforehand if the dir is written in - mixed case or in all upper case. That's a problem when using - casesensitivity. If the file handle given to FileRenameInformation - has been opened casesensitive, the call also handles the path to the - target dir casesensitive. Rather than trying to find the right name - of the recycler, we just reopen the file to move with OBJ_CASE_INSENSITIVE, - so the subsequent FileRenameInformation works caseinsensitive in terms of - the recycler directory name, too. */ - if (!pc.objcaseinsensitive ()) -{ - InitializeObjectAttributes (&attr, &ro_u_empty, OBJ_CASE_INSENSITIVE, - fh, NULL); - status = NtOpenFile (&tmp_fh, access, &attr, &io, FILE_SHARE_VALID_FLAGS, - flags); - if (!NT_SUCCESS (status)) - debug_printf ("NtOpenFile (%S) for reopening caseinsensitive failed, " - "status = %y", pc.get_nt_native_path (), status); - else - { - NtClose (fh); - fh = tmp_fh; - } -} /* Initialize recycler path. */ RtlInitEmptyUnicodeString (&recycler, recyclerbuf, sizeof recyclerbuf); if (!pc.isremote ()) @@ -312,6 +287,36 @@ try_to_bin (path_conv &pc, HANDLE &fh, ACCESS_MASK access, ULONG flags) recycler.Length -= sizeof (WCHAR); /* Store length of recycler base dir, if it's necessary to create it. */ recycler_base_len = recycler.Length; + /* The recycler name is $Recycler.Bin by default. If the recycler dir +disappears for some reason, shell32.dll recreates it in all upper +case. So we never know if the dir is written in camel back or in +upper case. That's a problem when using casesensitivity: If the +file handle given to FileRenameInformation has been opened +casesensitive, the call also handles the path to the target dir +casesensitive. Check for the right name here. + +Note that, originally, we reopened the file case insensitive instead. +But that's a problem for O_TMPFILE on pre-W10. As soon as the +original HANDLE gets closed, delete-on-close is converted to full +delete disposition and all useful operations on the file cease to +work (STATUS_ACCESS_DENIED or STATUS_FILE_DELETED). */ + if (!pc.objcaseinsensitive ()) + { + PFILE_BASIC_INFORMATION pfbi; + + InitializeObjectAttributes (&attr, &recycler, 0, rootdir, NULL); + pfbi = (PFILE_BASIC_INFORMATION) infobuf; + status = NtQueryAttributesFile (&attr, pfbi); + if (status == STATUS_OBJECT_NAME_NOT_FOUND) + { + wcscpy (recycler.Buffer, L"$RECYCLE.BIN\\"); + status = NtQueryAttributesFile (&attr, pfbi); + /* Keep the uppercase name if it exists, otherwise revert to +camel back to create a nicer name than shell32.dll. */ + if (status == STATUS_OBJECT_NAME_NOT_FOUND) + wcscpy (recycler.Buffer, L"$Recycle.Bin\\"); + } + } /* On NTFS or ReFS the recycler dir contains user specific subdirs, which are the actual recycle bins per user. The name of this dir is the string representation of the user SID. */