From dc847e6b9e61475d5db1bea0b6df0857924837a4 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Tue, 26 Aug 2014 20:47:46 +0000 Subject: [PATCH] * path.h (path_conv::init_reopen_attr): Change from void to returning POBJECT_ATTRIBUTES. Take OBJECT_ATTRIBUTES reference as argument, not pointer. * fhandler_disk_file.cc: Throughout accommodate above change. * syscalls.cc: Ditto. * ntea.cc (read_ea): Don't set hdl to NULL if it's already NULL. Set attr with pc.init_reopen_attr before trying to reopen file. (write_ea): Ditto. * security.cc (get_file_sd): Use pc.init_reopen_attr rather than pc.get_object_attr when trying to reopen file. (set_file_sd): Ditto. --- winsup/cygwin/ChangeLog | 14 ++++++++++++++ winsup/cygwin/fhandler_disk_file.cc | 20 ++++++++++---------- winsup/cygwin/ntea.cc | 4 ++-- winsup/cygwin/path.h | 7 ++++--- winsup/cygwin/security.cc | 6 +++--- winsup/cygwin/syscalls.cc | 6 +++--- 6 files changed, 36 insertions(+), 21 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index a6ee9dd4e..e6b835a10 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,17 @@ +2014-08-26 Corinna Vinschen + + * path.h (path_conv::init_reopen_attr): Change from void to returning + POBJECT_ATTRIBUTES. Take OBJECT_ATTRIBUTES reference as argument, not + pointer. + * fhandler_disk_file.cc: Throughout accommodate above change. + * syscalls.cc: Ditto. + * ntea.cc (read_ea): Don't set hdl to NULL if it's already NULL. Set + attr with pc.init_reopen_attr before trying to reopen file. + (write_ea): Ditto. + * security.cc (get_file_sd): Use pc.init_reopen_attr rather than + pc.get_object_attr when trying to reopen file. + (set_file_sd): Ditto. + 2014-08-25 Corinna Vinschen * cygtls.cc (san::leave/x86_64): Implement. diff --git a/winsup/cygwin/fhandler_disk_file.cc b/winsup/cygwin/fhandler_disk_file.cc index 428d04c45..98475e5d9 100644 --- a/winsup/cygwin/fhandler_disk_file.cc +++ b/winsup/cygwin/fhandler_disk_file.cc @@ -672,9 +672,9 @@ fhandler_base::fstat_helper (struct stat *buf, DWORD nNumberOfLinks) /* We have to re-open the file. Either the file is not opened for reading, or the read will change the file position of the original handle. */ - pc.init_reopen_attr (&attr, h); status = NtOpenFile (&h, SYNCHRONIZE | FILE_READ_DATA, - &attr, &io, FILE_SHARE_VALID_FLAGS, + pc.init_reopen_attr (attr, h), &io, + FILE_SHARE_VALID_FLAGS, FILE_OPEN_FOR_BACKUP_INTENT | FILE_SYNCHRONOUS_IO_NONALERT); if (!NT_SUCCESS (status)) @@ -894,9 +894,9 @@ fhandler_disk_file::fchmod (mode_t mode) OBJECT_ATTRIBUTES attr; HANDLE fh; - pc.init_reopen_attr (&attr, get_handle ()); - if (NT_SUCCESS (NtOpenFile (&fh, FILE_WRITE_ATTRIBUTES, &attr, &io, - FILE_SHARE_VALID_FLAGS, + if (NT_SUCCESS (NtOpenFile (&fh, FILE_WRITE_ATTRIBUTES, + pc.init_reopen_attr (attr, get_handle ()), + &io, FILE_SHARE_VALID_FLAGS, FILE_OPEN_FOR_BACKUP_INTENT))) { NtSetAttributesFile (fh, pc.file_attributes ()); @@ -1384,9 +1384,9 @@ fhandler_base::utimens_fs (const struct timespec *tvp) OBJECT_ATTRIBUTES attr; HANDLE fh; - pc.init_reopen_attr (&attr, get_handle ()); - if (NT_SUCCESS (NtOpenFile (&fh, FILE_WRITE_ATTRIBUTES, &attr, &io, - FILE_SHARE_VALID_FLAGS, + if (NT_SUCCESS (NtOpenFile (&fh, FILE_WRITE_ATTRIBUTES, + pc.init_reopen_attr (attr, get_handle ()), + &io, FILE_SHARE_VALID_FLAGS, FILE_OPEN_FOR_BACKUP_INTENT))) { NtSetInformationFile (fh, &io, &fbi, sizeof fbi, @@ -1555,8 +1555,8 @@ fhandler_disk_file::prw_open (bool write) /* First try to open with the original access mask */ ACCESS_MASK access = get_access (); - pc.init_reopen_attr (&attr, get_handle ()); - status = NtOpenFile (&prw_handle, access, &attr, &io, + status = NtOpenFile (&prw_handle, access, + pc.init_reopen_attr (attr, get_handle ()), &io, FILE_SHARE_VALID_FLAGS, get_options ()); if (status == STATUS_ACCESS_DENIED) { diff --git a/winsup/cygwin/ntea.cc b/winsup/cygwin/ntea.cc index d0c50775e..b5851c410 100644 --- a/winsup/cygwin/ntea.cc +++ b/winsup/cygwin/ntea.cc @@ -80,7 +80,6 @@ read_ea (HANDLE hdl, path_conv &pc, const char *name, char *value, size_t size) __seterrno_from_nt_status (status); __leave; } - hdl = NULL; } fea = (PFILE_FULL_EA_INFORMATION) tp.w_get (); @@ -120,6 +119,7 @@ read_ea (HANDLE hdl, path_conv &pc, const char *name, char *value, size_t size) NULL, TRUE); if (status != STATUS_ACCESS_DENIED || !hdl) break; + pc.init_reopen_attr (attr, h); } status = NtOpenFile (&h, READ_CONTROL | FILE_READ_EA, &attr, &io, FILE_SHARE_VALID_FLAGS, @@ -265,7 +265,6 @@ write_ea (HANDLE hdl, path_conv &pc, const char *name, const char *value, __seterrno_from_nt_status (status); __leave; } - hdl = NULL; } /* For compatibility with Linux, we only allow user xattrs and @@ -323,6 +322,7 @@ write_ea (HANDLE hdl, path_conv &pc, const char *name, const char *value, status = NtSetEaFile (h, &io, fea, flen); if (status != STATUS_ACCESS_DENIED || !hdl) break; + pc.init_reopen_attr (attr, h); } status = NtOpenFile (&h, READ_CONTROL | FILE_WRITE_EA, &attr, &io, FILE_SHARE_VALID_FLAGS, diff --git a/winsup/cygwin/path.h b/winsup/cygwin/path.h index dfd8f0241..8d4525890 100644 --- a/winsup/cygwin/path.h +++ b/winsup/cygwin/path.h @@ -281,14 +281,15 @@ class path_conv NULL, sa.lpSecurityDescriptor); return &attr; } - inline void init_reopen_attr (POBJECT_ATTRIBUTES attr, HANDLE h) + inline POBJECT_ATTRIBUTES init_reopen_attr (OBJECT_ATTRIBUTES &attr, HANDLE h) { if (has_buggy_reopen ()) - InitializeObjectAttributes (attr, get_nt_native_path (), + InitializeObjectAttributes (&attr, get_nt_native_path (), objcaseinsensitive (), NULL, NULL) else - InitializeObjectAttributes (attr, &ro_u_empty, objcaseinsensitive (), + InitializeObjectAttributes (&attr, &ro_u_empty, objcaseinsensitive (), h, NULL); + return &attr; } inline size_t get_wide_win32_path_len () { diff --git a/winsup/cygwin/security.cc b/winsup/cygwin/security.cc index 07b3fa00d..8cee7e58b 100644 --- a/winsup/cygwin/security.cc +++ b/winsup/cygwin/security.cc @@ -68,7 +68,7 @@ get_file_sd (HANDLE fh, path_conv &pc, security_descriptor &sd, if (!fh) { status = NtOpenFile (&fh, READ_CONTROL, - pc.get_object_attr (attr, sec_none_nih), &io, + pc.init_reopen_attr (attr, fh), &io, FILE_SHARE_VALID_FLAGS, FILE_OPEN_FOR_BACKUP_INTENT); if (!NT_SUCCESS (status)) { @@ -216,8 +216,8 @@ set_file_sd (HANDLE fh, path_conv &pc, security_descriptor &sd, bool is_chown) OBJECT_ATTRIBUTES attr; IO_STATUS_BLOCK io; status = NtOpenFile (&fh, (is_chown ? WRITE_OWNER : 0) | WRITE_DAC, - pc.get_object_attr (attr, sec_none_nih), - &io, FILE_SHARE_VALID_FLAGS, + pc.init_reopen_attr (attr, fh), &io, + FILE_SHARE_VALID_FLAGS, FILE_OPEN_FOR_BACKUP_INTENT); if (!NT_SUCCESS (status)) { diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index fe3a88da3..15ebf4900 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -719,7 +719,7 @@ retry_open: if (!NT_SUCCESS (status2)) debug_printf ("Removing R/O on %S failed, status = %y", pc.get_nt_native_path (), status2); - pc.init_reopen_attr (&attr, fh_ro); + pc.init_reopen_attr (attr, fh_ro); } else { @@ -947,8 +947,8 @@ try_again: pc.get_nt_native_path ()); /* Re-open from handle so we open the correct file no matter if it has been moved to the bin or not. */ - pc.init_reopen_attr (&attr, fh); - status = NtOpenFile (&fh2, DELETE, &attr, &io, + status = NtOpenFile (&fh2, DELETE, + pc.init_reopen_attr (attr, fh), &io, bin_stat == move_to_bin ? FILE_SHARE_VALID_FLAGS : FILE_SHARE_DELETE, flags | FILE_DELETE_ON_CLOSE);