* 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.
This commit is contained in:
Corinna Vinschen 2014-08-26 20:47:46 +00:00
parent 12b244394c
commit dc847e6b9e
6 changed files with 36 additions and 21 deletions

View File

@ -1,3 +1,17 @@
2014-08-26 Corinna Vinschen <corinna@vinschen.de>
* 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 <corinna@vinschen.de>
* cygtls.cc (san::leave/x86_64): Implement.

View File

@ -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)
{

View File

@ -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,

View File

@ -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 ()
{

View File

@ -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))
{

View File

@ -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);