From: Mikko Rasa Date: Mon, 9 Jul 2012 16:11:54 +0000 (+0300) Subject: Fix GetSecurityInfo error checking and request appropriate access to the file X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=330373a422c3b75d117e1a0eed72ca868bccb5b9;p=libs%2Fcore.git Fix GetSecurityInfo error checking and request appropriate access to the file --- diff --git a/source/fs/stat.cpp b/source/fs/stat.cpp index d61081b..77564f0 100644 --- a/source/fs/stat.cpp +++ b/source/fs/stat.cpp @@ -92,7 +92,7 @@ Stat Stat::stat(const Path &path) { #ifdef WIN32 HANDLE handle; - handle = CreateFile(path.str().c_str(), 0, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0); + handle = CreateFile(path.str().c_str(), READ_CONTROL, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_BACKUP_SEMANTICS, 0); if(handle==INVALID_HANDLE_VALUE) { DWORD err = GetLastError(); @@ -122,10 +122,12 @@ Stat Stat::stat(const Path &path) PSECURITY_DESCRIPTOR sec_desc; PSID owner = 0; PSID group = 0; - if(!GetSecurityInfo(handle, SE_FILE_OBJECT, OWNER_SECURITY_INFORMATION|GROUP_SECURITY_INFORMATION, &owner, &group, 0, 0, &sec_desc)) + const SECURITY_INFORMATION sec_info = OWNER_SECURITY_INFORMATION|GROUP_SECURITY_INFORMATION; + DWORD err = GetSecurityInfo(handle, SE_FILE_OBJECT, sec_info, &owner, &group, 0, 0, &sec_desc); + if(err) { CloseHandle(handle); - throw system_error("GetSecurityInfo"); + throw system_error("GetSecurityInfo", err); } if(owner)