* ntea.cc (read_ea): Change left-over return to __leave. Fix

condition to close handle.  Call NtClose rather than CloseHandle.
	(write_ea): Fix condition to close handle.  Call NtClose rather than
	CloseHandle.
	* security.cc (get_file_sd): Call pc.init_reopen_attr if a valid
	incoming handle was given, pc.get_object_attr otherwise.
	(set_file_sd): Ditto.
This commit is contained in:
Corinna Vinschen 2014-08-27 09:39:44 +00:00
parent dc847e6b9e
commit db1ff3b932
3 changed files with 26 additions and 15 deletions

View File

@ -1,3 +1,13 @@
2014-08-27 Corinna Vinschen <corinna@vinschen.de>
* ntea.cc (read_ea): Change left-over return to __leave. Fix
condition to close handle. Call NtClose rather than CloseHandle.
(write_ea): Fix condition to close handle. Call NtClose rather than
CloseHandle.
* security.cc (get_file_sd): Call pc.init_reopen_attr if a valid
incoming handle was given, pc.get_object_attr otherwise.
(set_file_sd): Ditto.
2014-08-26 Corinna Vinschen <corinna@vinschen.de> 2014-08-26 Corinna Vinschen <corinna@vinschen.de>
* path.h (path_conv::init_reopen_attr): Change from void to returning * path.h (path_conv::init_reopen_attr): Change from void to returning

View File

@ -101,7 +101,7 @@ read_ea (HANDLE hdl, path_conv &pc, const char *name, char *value, size_t size)
if ((nlen = strlen (name)) >= MAX_EA_NAME_LEN) if ((nlen = strlen (name)) >= MAX_EA_NAME_LEN)
{ {
set_errno (EINVAL); set_errno (EINVAL);
return -1; __leave;
} }
glen = sizeof (FILE_GET_EA_INFORMATION) + nlen; glen = sizeof (FILE_GET_EA_INFORMATION) + nlen;
gea = (PFILE_GET_EA_INFORMATION) alloca (glen); gea = (PFILE_GET_EA_INFORMATION) alloca (glen);
@ -225,8 +225,8 @@ read_ea (HANDLE hdl, path_conv &pc, const char *name, char *value, size_t size)
} }
__except (EFAULT) {} __except (EFAULT) {}
__endtry __endtry
if (!hdl) if (!hdl && h)
CloseHandle (h); NtClose (h);
debug_printf ("%d = read_ea(%S, %s, %p, %lu)", debug_printf ("%d = read_ea(%S, %s, %p, %lu)",
ret, attr.ObjectName, name, value, size); ret, attr.ObjectName, name, value, size);
return ret; return ret;
@ -360,8 +360,8 @@ write_ea (HANDLE hdl, path_conv &pc, const char *name, const char *value,
} }
__except (EFAULT) {} __except (EFAULT) {}
__endtry __endtry
if (!hdl) if (!hdl && h)
CloseHandle (h); NtClose (h);
debug_printf ("%d = write_ea(%S, %s, %p, %lu, %d)", debug_printf ("%d = write_ea(%S, %s, %p, %lu, %d)",
ret, attr.ObjectName, name, value, size, flags); ret, attr.ObjectName, name, value, size, flags);
return ret; return ret;

View File

@ -39,7 +39,7 @@ LONG
get_file_sd (HANDLE fh, path_conv &pc, security_descriptor &sd, get_file_sd (HANDLE fh, path_conv &pc, security_descriptor &sd,
bool justcreated) bool justcreated)
{ {
NTSTATUS status; NTSTATUS status = STATUS_SUCCESS;
OBJECT_ATTRIBUTES attr; OBJECT_ATTRIBUTES attr;
IO_STATUS_BLOCK io; IO_STATUS_BLOCK io;
ULONG len = SD_MAXIMUM_SIZE, rlen; ULONG len = SD_MAXIMUM_SIZE, rlen;
@ -56,20 +56,19 @@ get_file_sd (HANDLE fh, path_conv &pc, security_descriptor &sd,
status = NtQuerySecurityObject (fh, ALL_SECURITY_INFORMATION, status = NtQuerySecurityObject (fh, ALL_SECURITY_INFORMATION,
sd, len, &rlen); sd, len, &rlen);
if (!NT_SUCCESS (status)) if (!NT_SUCCESS (status))
{ debug_printf ("NtQuerySecurityObject (%S), status %y",
debug_printf ("NtQuerySecurityObject (%S), status %y", pc.get_nt_native_path (), status);
pc.get_nt_native_path (), status);
fh = NULL;
}
} }
/* If the handle was NULL, or fetching with the original handle didn't work, /* If the handle was NULL, or fetching with the original handle didn't work,
try to reopen the file with READ_CONTROL and fetch the security descriptor try to reopen the file with READ_CONTROL and fetch the security descriptor
using that handle. */ using that handle. */
if (!fh) if (!fh || !NT_SUCCESS (status))
{ {
status = NtOpenFile (&fh, READ_CONTROL, status = NtOpenFile (&fh, READ_CONTROL,
pc.init_reopen_attr (attr, fh), &io, fh ? pc.init_reopen_attr (attr, fh)
FILE_SHARE_VALID_FLAGS, FILE_OPEN_FOR_BACKUP_INTENT); : pc.get_object_attr (attr, sec_none_nih),
&io, FILE_SHARE_VALID_FLAGS,
FILE_OPEN_FOR_BACKUP_INTENT);
if (!NT_SUCCESS (status)) if (!NT_SUCCESS (status))
{ {
sd.free (); sd.free ();
@ -216,7 +215,9 @@ set_file_sd (HANDLE fh, path_conv &pc, security_descriptor &sd, bool is_chown)
OBJECT_ATTRIBUTES attr; OBJECT_ATTRIBUTES attr;
IO_STATUS_BLOCK io; IO_STATUS_BLOCK io;
status = NtOpenFile (&fh, (is_chown ? WRITE_OWNER : 0) | WRITE_DAC, status = NtOpenFile (&fh, (is_chown ? WRITE_OWNER : 0) | WRITE_DAC,
pc.init_reopen_attr (attr, fh), &io, fh ? pc.init_reopen_attr (attr, fh)
: pc.get_object_attr (attr, sec_none_nih),
&io,
FILE_SHARE_VALID_FLAGS, FILE_SHARE_VALID_FLAGS,
FILE_OPEN_FOR_BACKUP_INTENT); FILE_OPEN_FOR_BACKUP_INTENT);
if (!NT_SUCCESS (status)) if (!NT_SUCCESS (status))