From a9a5b2eab006f3479087bed7030a16b86cd791aa Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Thu, 8 Apr 2004 07:57:28 +0000 Subject: * fhandler.cc (fhandler_base::open): Set query access mode according to query_open setting. (fhandler_base::fhandler_base): Initialize query_open. * fhandler.h (FH_QUERYOPEN): Drop. (enum query_state): Add. (class fhandler_base): Add query_open member. (fhandler_base::get_query_open): Redefine to use query_open. (fhandler_base::set_query_open): Ditto. * fhandler_disk_file.cc (fhandler_base::fstat_fs): Remove O_DIROPEN from open_flags since it's added in open_fs anyway. Remove query_open_already. Use new query_open settings. Rearrange slightly. (fhandler_base::fstat_helper): Add get_io_handle as parameter to get_file_attribute. * security.cc (get_nt_object_attribute): Make returning an int. Return -1 on error, 0 otherwise. (get_file_attribute): Take an object handle as argument. Move down to allow calling get_nt_object_attribute in case a non-NULL handle is given. * security.h (get_file_attribute): Add handle to argument list. * syscalls.cc (chown_worker): Accomodate new definition of get_file_attribute. --- winsup/cygwin/security.cc | 76 +++++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 35 deletions(-) (limited to 'winsup/cygwin/security.cc') diff --git a/winsup/cygwin/security.cc b/winsup/cygwin/security.cc index 8195298ad..c7533dee0 100644 --- a/winsup/cygwin/security.cc +++ b/winsup/cygwin/security.cc @@ -1367,40 +1367,7 @@ get_nt_attribute (const char *file, mode_t *attribute, get_info_from_sd (sd, attribute, uidret, gidret); } -int -get_file_attribute (int use_ntsec, const char *file, - mode_t *attribute, __uid32_t *uidret, __gid32_t *gidret) -{ - int res; - syscall_printf ("file: %s", file); - - if (use_ntsec && allow_ntsec && wincap.has_security ()) - { - get_nt_attribute (file, attribute, uidret, gidret); - return 0; - } - - if (uidret) - *uidret = myself->uid; - if (gidret) - *gidret = myself->gid; - - if (!attribute) - return 0; - - if (allow_ntea) - { - int oatt = *attribute; - res = NTReadEA (file, ".UNIXATTR", (char *)attribute, sizeof (*attribute)); - *attribute |= oatt; - } - else - res = 0; - - return res > 0 ? 0 : -1; -} - -static void +static int get_nt_object_attribute (HANDLE handle, SE_OBJECT_TYPE object_type, mode_t *attribute, __uid32_t *uidret, __gid32_t *gidret) @@ -1436,12 +1403,16 @@ get_nt_object_attribute (HANDLE handle, SE_OBJECT_TYPE object_type, | GROUP_SECURITY_INFORMATION | OWNER_SECURITY_INFORMATION, NULL, NULL, NULL, NULL, &psd))) - __seterrno_from_win_error (ret); + { + __seterrno_from_win_error (ret); + return -1; + } else { get_info_from_sd (psd, attribute, uidret, gidret); LocalFree (psd); } + return 0; } int @@ -1457,6 +1428,41 @@ get_object_attribute (HANDLE handle, SE_OBJECT_TYPE object_type, return -1; } +int +get_file_attribute (int use_ntsec, HANDLE handle, const char *file, + mode_t *attribute, __uid32_t *uidret, __gid32_t *gidret) +{ + int res; + syscall_printf ("file: %s", file); + + if (use_ntsec && allow_ntsec && wincap.has_security ()) + { + if (handle && get_nt_object_attribute (handle, SE_FILE_OBJECT, + attribute, uidret, gidret)) + get_nt_attribute (file, attribute, uidret, gidret); + return 0; + } + + if (uidret) + *uidret = myself->uid; + if (gidret) + *gidret = myself->gid; + + if (!attribute) + return 0; + + if (allow_ntea) + { + int oatt = *attribute; + res = NTReadEA (file, ".UNIXATTR", (char *)attribute, sizeof (*attribute)); + *attribute |= oatt; + } + else + res = 0; + + return res > 0 ? 0 : -1; +} + bool add_access_allowed_ace (PACL acl, int offset, DWORD attributes, PSID sid, size_t &len_add, DWORD inherit) -- cgit v1.2.3