From ae5055b4587f8f3861b987862eca025790750233 Mon Sep 17 00:00:00 2001 From: corinna Date: Tue, 13 Apr 2004 12:14:58 +0000 Subject: [PATCH] * autoload.cc (NtQuerySecurityObject): Add. * ntdll.h (STATUS_BUFFER_TOO_SMALL): Add definition. (NtQuerySecurityObject): Add declaration. * security.cc (get_nt_object_attribute): Always use NtQuerySecurityObject to retrieve security descriptor. --- winsup/cygwin/ChangeLog | 8 +++++++ winsup/cygwin/autoload.cc | 1 + winsup/cygwin/ntdll.h | 3 +++ winsup/cygwin/security.cc | 55 ++++++++++++++++++++--------------------------- 4 files changed, 35 insertions(+), 32 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 5ef03f5bf4..35bde4d68b 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,11 @@ +2004-04-13 Corinna Vinschen + + * autoload.cc (NtQuerySecurityObject): Add. + * ntdll.h (STATUS_BUFFER_TOO_SMALL): Add definition. + (NtQuerySecurityObject): Add declaration. + * security.cc (get_nt_object_attribute): Always use + NtQuerySecurityObject to retrieve security descriptor. + 2004-04-13 Gerd Spalink * fhandler_dsp.cc (fhandler_dev_dsp::Audio_out::stop): Add optional diff --git a/winsup/cygwin/autoload.cc b/winsup/cygwin/autoload.cc index d64674c0a4..c8916fe2b0 100644 --- a/winsup/cygwin/autoload.cc +++ b/winsup/cygwin/autoload.cc @@ -392,6 +392,7 @@ LoadDLLfuncEx (NtQueryInformationFile, 20, ntdll, 1) LoadDLLfuncEx (NtQueryInformationProcess, 20, ntdll, 1) LoadDLLfuncEx2 (NtQueryObject, 20, ntdll, 1, 1) LoadDLLfuncEx (NtQuerySystemInformation, 16, ntdll, 1) +LoadDLLfuncEx (NtQuerySecurityObject, 20, ntdll, 1) LoadDLLfuncEx (NtQueryVirtualMemory, 24, ntdll, 1) LoadDLLfuncEx (NtUnmapViewOfSection, 8, ntdll, 1) LoadDLLfuncEx (RtlInitUnicodeString, 8, ntdll, 1) diff --git a/winsup/cygwin/ntdll.h b/winsup/cygwin/ntdll.h index 33aa1296e7..1548443e60 100644 --- a/winsup/cygwin/ntdll.h +++ b/winsup/cygwin/ntdll.h @@ -9,6 +9,7 @@ details. */ #define STATUS_INFO_LENGTH_MISMATCH ((NTSTATUS) 0xc0000004) +#define STATUS_BUFFER_TOO_SMALL ((NTSTATUS) 0xc0000023) #define PDI_MODULES 0x01 #define PDI_HEAPS 0x04 #define LDRP_IMAGE_DLL 0x00000004 @@ -407,6 +408,8 @@ extern "C" ULONG, ULONG *); NTSTATUS NTAPI NtQuerySystemInformation (SYSTEM_INFORMATION_CLASS, PVOID, ULONG, PULONG); + NTSTATUS NTAPI NtQuerySecurityObject (HANDLE, SECURITY_INFORMATION, + PSECURITY_DESCRIPTOR, ULONG, PULONG); NTSTATUS NTAPI NtQueryVirtualMemory (HANDLE, PVOID, MEMORY_INFORMATION_CLASS, PVOID, ULONG, PULONG); NTSTATUS NTAPI NtUnmapViewOfSection (HANDLE, PVOID); diff --git a/winsup/cygwin/security.cc b/winsup/cygwin/security.cc index d9a1e5f850..8420f857b5 100644 --- a/winsup/cygwin/security.cc +++ b/winsup/cygwin/security.cc @@ -1374,44 +1374,35 @@ get_nt_object_attribute (HANDLE handle, SE_OBJECT_TYPE object_type, { security_descriptor sd; PSECURITY_DESCRIPTOR psd = NULL; - LONG ret; - - if (object_type == SE_REGISTRY_KEY) - { - /* use different code for registry handles, for performance reasons */ - DWORD len = 0; - if ((ret = RegGetKeySecurity ((HKEY) handle, - DACL_SECURITY_INFORMATION - | GROUP_SECURITY_INFORMATION - | OWNER_SECURITY_INFORMATION, - sd, &len)) != ERROR_INSUFFICIENT_BUFFER) - __seterrno_from_win_error (ret); - else if (!sd.malloc (len)) + + NTSTATUS ret; + ULONG len = 0; + ret = NtQuerySecurityObject (handle, + DACL_SECURITY_INFORMATION + | GROUP_SECURITY_INFORMATION + | OWNER_SECURITY_INFORMATION, + sd, len, &len); + if (ret == STATUS_BUFFER_TOO_SMALL) + { + if (!sd.malloc (len)) set_errno (ENOMEM); - else if ((ret = RegGetKeySecurity ((HKEY) handle, - DACL_SECURITY_INFORMATION - | GROUP_SECURITY_INFORMATION - | OWNER_SECURITY_INFORMATION, - sd, &len)) != ERROR_SUCCESS) - __seterrno_from_win_error (ret); else - psd = sd; - get_info_from_sd (psd, attribute, uidret, gidret); + ret = NtQuerySecurityObject (handle, + DACL_SECURITY_INFORMATION + | GROUP_SECURITY_INFORMATION + | OWNER_SECURITY_INFORMATION, + sd, len, &len); } - else if ((ret = GetSecurityInfo (handle, object_type, - DACL_SECURITY_INFORMATION - | GROUP_SECURITY_INFORMATION - | OWNER_SECURITY_INFORMATION, - NULL, NULL, NULL, NULL, &psd))) + if (ret != STATUS_SUCCESS) { - __seterrno_from_win_error (ret); - return -1; + __seterrno_from_win_error (RtlNtStatusToDosError (ret)); + if (object_type == SE_FILE_OBJECT) + return -1; } else - { - get_info_from_sd (psd, attribute, uidret, gidret); - LocalFree (psd); - } + psd = sd; + get_info_from_sd (psd, attribute, uidret, gidret); + return 0; } -- 2.11.0