src/corelib/io/qfsfileengine_win.cpp
branchRCL_3
changeset 4 3b1da2848fc7
parent 3 41300fa6a67c
child 7 3f74d0d4af4c
equal deleted inserted replaced
3:41300fa6a67c 4:3b1da2848fc7
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the QtCore module of the Qt Toolkit.
     7 ** This file is part of the QtCore module of the Qt Toolkit.
     8 **
     8 **
  1417 {
  1417 {
  1418     QAbstractFileEngine::FileFlags ret = 0;
  1418     QAbstractFileEngine::FileFlags ret = 0;
  1419 
  1419 
  1420 #if !defined(QT_NO_LIBRARY)
  1420 #if !defined(QT_NO_LIBRARY)
  1421     if((qt_ntfs_permission_lookup > 0) && ((QSysInfo::WindowsVersion&QSysInfo::WV_NT_based) > QSysInfo::WV_NT)) {
  1421     if((qt_ntfs_permission_lookup > 0) && ((QSysInfo::WindowsVersion&QSysInfo::WV_NT_based) > QSysInfo::WV_NT)) {
  1422         PSID pOwner = 0;
       
  1423         PSID pGroup = 0;
       
  1424         PACL pDacl;
       
  1425         PSECURITY_DESCRIPTOR pSD;
       
  1426         ACCESS_MASK access_mask;
       
  1427 
       
  1428         enum { ReadMask = 0x00000001, WriteMask = 0x00000002, ExecMask = 0x00000020 };
       
  1429         resolveLibs();
  1422         resolveLibs();
  1430         if(ptrGetNamedSecurityInfoW && ptrBuildTrusteeWithSidW && ptrGetEffectiveRightsFromAclW) {
  1423         if(ptrGetNamedSecurityInfoW && ptrBuildTrusteeWithSidW && ptrGetEffectiveRightsFromAclW) {
       
  1424             enum { ReadMask = 0x00000001, WriteMask = 0x00000002, ExecMask = 0x00000020 };
  1431 
  1425 
  1432             QString fname = filePath.endsWith(QLatin1String(".lnk")) ? readLink(filePath) : filePath;
  1426             QString fname = filePath.endsWith(QLatin1String(".lnk")) ? readLink(filePath) : filePath;
       
  1427             PSID pOwner = 0;
       
  1428             PSID pGroup = 0;
       
  1429             PACL pDacl;
       
  1430             PSECURITY_DESCRIPTOR pSD;
  1433             DWORD res = ptrGetNamedSecurityInfoW((wchar_t*)fname.utf16(), SE_FILE_OBJECT,
  1431             DWORD res = ptrGetNamedSecurityInfoW((wchar_t*)fname.utf16(), SE_FILE_OBJECT,
  1434                                                  OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION,
  1432                                                  OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION,
  1435                                                  &pOwner, &pGroup, &pDacl, 0, &pSD);
  1433                                                  &pOwner, &pGroup, &pDacl, 0, &pSD);
  1436 
       
  1437             if(res == ERROR_SUCCESS) {
  1434             if(res == ERROR_SUCCESS) {
       
  1435                 ACCESS_MASK access_mask;
  1438                 TRUSTEE_W trustee;
  1436                 TRUSTEE_W trustee;
  1439                 { //user
  1437                 { //user
  1440                     if(ptrGetEffectiveRightsFromAclW(pDacl, &currentUserTrusteeW, &access_mask) != ERROR_SUCCESS)
  1438                     if(ptrGetEffectiveRightsFromAclW(pDacl, &currentUserTrusteeW, &access_mask) != ERROR_SUCCESS)
  1441                         access_mask = (ACCESS_MASK)-1;
  1439                         access_mask = (ACCESS_MASK)-1;
  1442                     if(access_mask & ReadMask)
  1440                     if(access_mask & ReadMask)
  1593     }
  1591     }
  1594     if (type & FlagsMask) {
  1592     if (type & FlagsMask) {
  1595         ret |= LocalDiskFlag;
  1593         ret |= LocalDiskFlag;
  1596         if (d->doStat()) {
  1594         if (d->doStat()) {
  1597             ret |= ExistsFlag;
  1595             ret |= ExistsFlag;
  1598             if (d->filePath == QLatin1String("/") || isDriveRoot(d->filePath) || isUncRoot(d->filePath)) {
  1596             if (d->filePath == QLatin1String("/") || isDriveRoot(d->filePath) || isUncRoot(d->filePath))
  1599                 ret |= RootFlag;
  1597                 ret |= RootFlag;
  1600             } else if (d->fileAttrib & FILE_ATTRIBUTE_HIDDEN) {
  1598             else if (d->fileAttrib & FILE_ATTRIBUTE_HIDDEN)
  1601                 QString baseName = fileName(BaseName);
  1599                 ret |= HiddenFlag;
  1602                 if (baseName != QLatin1String(".") && baseName != QLatin1String(".."))
       
  1603                     ret |= HiddenFlag;
       
  1604             }
       
  1605         }
  1600         }
  1606     }
  1601     }
  1607     return ret;
  1602     return ret;
  1608 }
  1603 }
  1609 
  1604 
  1721     return nobodyID;
  1716     return nobodyID;
  1722 }
  1717 }
  1723 
  1718 
  1724 QString QFSFileEngine::owner(FileOwner own) const
  1719 QString QFSFileEngine::owner(FileOwner own) const
  1725 {
  1720 {
       
  1721     QString name;
  1726 #if !defined(QT_NO_LIBRARY)
  1722 #if !defined(QT_NO_LIBRARY)
  1727     Q_D(const QFSFileEngine);
  1723     Q_D(const QFSFileEngine);
  1728     if((qt_ntfs_permission_lookup > 0) && ((QSysInfo::WindowsVersion&QSysInfo::WV_NT_based) > QSysInfo::WV_NT)) {
  1724 
  1729 	PSID pOwner = 0;
  1725     if ((qt_ntfs_permission_lookup > 0) && ((QSysInfo::WindowsVersion&QSysInfo::WV_NT_based) > QSysInfo::WV_NT)) {
  1730 	PSECURITY_DESCRIPTOR pSD;
  1726         QFSFileEnginePrivate::resolveLibs();
  1731 	QString name;
  1727         if (ptrGetNamedSecurityInfoW && ptrLookupAccountSidW) {
  1732 	QFSFileEnginePrivate::resolveLibs();
  1728             PSID pOwner = 0;
  1733 
  1729             PSECURITY_DESCRIPTOR pSD;
  1734 	if(ptrGetNamedSecurityInfoW && ptrLookupAccountSidW) {
  1730             if (ptrGetNamedSecurityInfoW((wchar_t*)d->filePath.utf16(), SE_FILE_OBJECT,
  1735 	    if(ptrGetNamedSecurityInfoW((wchar_t*)d->filePath.utf16(), SE_FILE_OBJECT,
  1731                                          own == OwnerGroup ? GROUP_SECURITY_INFORMATION : OWNER_SECURITY_INFORMATION,
  1736 					 own == OwnerGroup ? GROUP_SECURITY_INFORMATION : OWNER_SECURITY_INFORMATION,
  1732                                          own == OwnerUser ? &pOwner : 0, own == OwnerGroup ? &pOwner : 0,
  1737 					 NULL, &pOwner, NULL, NULL, &pSD) == ERROR_SUCCESS) {
  1733                                          0, 0, &pSD) == ERROR_SUCCESS) {
  1738 		DWORD lowner = 0, ldomain = 0;
  1734                 DWORD lowner = 64;
  1739 		SID_NAME_USE use;
  1735                 DWORD ldomain = 64;
  1740 		// First call, to determine size of the strings (with '\0').
  1736                 QVarLengthArray<wchar_t, 64> owner(lowner);
  1741 		ptrLookupAccountSidW(NULL, pOwner, NULL, &lowner, NULL, &ldomain, (SID_NAME_USE*)&use);
  1737                 QVarLengthArray<wchar_t, 64> domain(ldomain);
  1742 		wchar_t *owner = new wchar_t[lowner];
  1738                 SID_NAME_USE use = SidTypeUnknown;
  1743 		wchar_t *domain = new wchar_t[ldomain];
  1739                 // First call, to determine size of the strings (with '\0').
  1744 		// Second call, size is without '\0'
  1740                 if (!ptrLookupAccountSidW(NULL, pOwner, (LPWSTR)owner.data(), &lowner,
  1745 		if(ptrLookupAccountSidW(NULL, pOwner, (LPWSTR)owner, &lowner,
  1741                                           (LPWSTR)domain.data(), &ldomain, (SID_NAME_USE*)&use)) {
  1746 					 (LPWSTR)domain, &ldomain, (SID_NAME_USE*)&use)) {
  1742                     if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
  1747 		    name = QString::fromUtf16((ushort*)owner);
  1743                         if (lowner > (DWORD)owner.size())
  1748 		}
  1744                             owner.resize(lowner);
  1749 		LocalFree(pSD);
  1745                         if (ldomain > (DWORD)domain.size())
  1750 		delete [] owner;
  1746                             domain.resize(ldomain);
  1751 		delete [] domain;
  1747                         // Second call, try on resized buf-s
  1752 	    }
  1748                         if (!ptrLookupAccountSidW(NULL, pOwner, (LPWSTR)owner.data(), &lowner,
  1753 	}
  1749                                                   (LPWSTR)domain.data(), &ldomain, (SID_NAME_USE*)&use)) {
  1754 	return name;
  1750                             lowner = 0;
       
  1751                         }
       
  1752                     } else {
       
  1753                         lowner = 0;
       
  1754                     }
       
  1755                 }
       
  1756                 if (lowner != 0)
       
  1757                     name = QString::fromWCharArray(owner.data());
       
  1758                 LocalFree(pSD);
       
  1759             }
       
  1760         }
  1755     }
  1761     }
  1756 #else
  1762 #else
  1757     Q_UNUSED(own);
  1763     Q_UNUSED(own);
  1758 #endif
  1764 #endif
  1759     return QString();
  1765     return name;
  1760 }
  1766 }
  1761 
  1767 
  1762 bool QFSFileEngine::setPermissions(uint perms)
  1768 bool QFSFileEngine::setPermissions(uint perms)
  1763 {
  1769 {
  1764     Q_D(QFSFileEngine);
  1770     Q_D(QFSFileEngine);