From 76e9f7b9a1fbcf3d5087a441ff61ab7a36e624b5 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 19 Jan 2013 09:32:36 +0200 Subject: [PATCH] Make 'fstat' on MS-Windows behave more like 'stat' and 'lstat'. src/w32.c (fstat): Return owner and group like 'stat' and 'lstat' do. --- src/ChangeLog | 1 + src/w32.c | 24 +++++++++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 26773878753..3727e13d580 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -3,6 +3,7 @@ * w32.c (acl_set_file): Treat ERROR_ACCESS_DENIED from set_file_security as failure due to insufficient privileges. Reported by Fabrice Popineau . + (fstat): Return owner and group like 'stat' and 'lstat' do. 2013-01-19 Paul Eggert diff --git a/src/w32.c b/src/w32.c index 525b0a8e89b..be58dc5cd53 100644 --- a/src/w32.c +++ b/src/w32.c @@ -4164,13 +4164,23 @@ fstat (int desc, struct stat * buf) else buf->st_ino = fake_inode; - /* Consider files to belong to current user. - FIXME: this should use GetSecurityInfo API, but it is only - available for _WIN32_WINNT >= 0x501. */ - buf->st_uid = dflt_passwd.pw_uid; - buf->st_gid = dflt_passwd.pw_gid; - strcpy (buf->st_uname, dflt_passwd.pw_name); - strcpy (buf->st_gname, dflt_group.gr_name); + /* If the caller so requested, get the true file owner and group. + Otherwise, consider the file to belong to the current user. */ + if (!w32_stat_get_owner_group || is_windows_9x () == TRUE) + get_file_owner_and_group (NULL, buf); + else + { + PSECURITY_DESCRIPTOR psd = NULL; + + psd = get_file_security_desc_by_handle (fh); + if (psd) + { + get_file_owner_and_group (psd, buf); + LocalFree (psd); + } + else + get_file_owner_and_group (NULL, buf); + } buf->st_dev = info.dwVolumeSerialNumber; buf->st_rdev = info.dwVolumeSerialNumber; -- 2.11.4.GIT