]> git.tdb.fi Git - libs/core.git/commitdiff
Fix GetSecurityInfo error checking and request appropriate access to the file
authorMikko Rasa <tdb@tdb.fi>
Mon, 9 Jul 2012 16:11:54 +0000 (19:11 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 9 Jul 2012 16:12:53 +0000 (19:12 +0300)
source/fs/stat.cpp

index d61081b95c9190732627c2e435223eb8f61ba73a..77564f0ecd2d6c49b3297db2733686423de870bb 100644 (file)
@@ -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)