summaryrefslogtreecommitdiffstats
path: root/tests/auto/qfileinfo
diff options
context:
space:
mode:
authorPrasanth Ullattil <prasanth.ullattil@nokia.com>2010-12-06 14:46:22 +0100
committerPrasanth Ullattil <prasanth.ullattil@nokia.com>2010-12-06 15:00:18 +0100
commit37fdb437084a7a4acefefbe1d55adee4e7723b7a (patch)
tree8c1268043d8adb81113e5230e23a348f0337d1e4 /tests/auto/qfileinfo
parent5bdc4ec60655aba2972f0e6cb2b09ee5f012690b (diff)
Fix tst_QFileInfo owner() & group() failure on Windows.
The ownership of newly created files are transferred to the Administrator group only if the application is running with Admin privilages. This will happen only on Windows 7 & Vista, on XP user has the ownership. Reviewed-by: Joao
Diffstat (limited to 'tests/auto/qfileinfo')
-rw-r--r--tests/auto/qfileinfo/tst_qfileinfo.cpp63
1 files changed, 43 insertions, 20 deletions
diff --git a/tests/auto/qfileinfo/tst_qfileinfo.cpp b/tests/auto/qfileinfo/tst_qfileinfo.cpp
index 96a0d7729f..70ed84203d 100644
--- a/tests/auto/qfileinfo/tst_qfileinfo.cpp
+++ b/tests/auto/qfileinfo/tst_qfileinfo.cpp
@@ -1648,6 +1648,27 @@ void tst_QFileInfo::detachingOperations()
}
#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN)
+BOOL IsUserAdmin()
+{
+ BOOL b;
+ SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
+ PSID AdministratorsGroup;
+ b = AllocateAndInitializeSid(
+ &NtAuthority,
+ 2,
+ SECURITY_BUILTIN_DOMAIN_RID,
+ DOMAIN_ALIAS_RID_ADMINS,
+ 0, 0, 0, 0, 0, 0,
+ &AdministratorsGroup);
+ if (b) {
+ if (!CheckTokenMembership( NULL, AdministratorsGroup, &b))
+ b = FALSE;
+ FreeSid(AdministratorsGroup);
+ }
+
+ return(b);
+}
+
void tst_QFileInfo::owner()
{
QString userName;
@@ -1661,28 +1682,30 @@ void tst_QFileInfo::owner()
wchar_t usernameBuf[1024];
DWORD bufSize = 1024;
if (GetUserNameW(usernameBuf, &bufSize)) {
- userName = QString::fromWCharArray(usernameBuf, bufSize);
- // Special case : If the user is a member of Administrators group, all files
- // created by the current user are owned by the Administrators group.
- LPLOCALGROUP_USERS_INFO_0 pBuf = NULL;
- DWORD dwLevel = 0;
- DWORD dwFlags = LG_INCLUDE_INDIRECT ;
- DWORD dwPrefMaxLen = MAX_PREFERRED_LENGTH;
- DWORD dwEntriesRead = 0;
- DWORD dwTotalEntries = 0;
- NET_API_STATUS nStatus;
- nStatus = NetUserGetLocalGroups(0, usernameBuf, dwLevel, dwFlags, (LPBYTE *) &pBuf,
- dwPrefMaxLen, &dwEntriesRead, &dwTotalEntries);
- // Check if the current user is a member of Administrators group
- if (nStatus == NERR_Success && pBuf){
- for (int i = 0; i < dwEntriesRead; i++) {
- QString groupName = QString::fromWCharArray(pBuf[i].lgrui0_name);
- if (!groupName.compare(QLatin1String("Administrators")))
- userName = groupName;
+ userName = QString::fromWCharArray(usernameBuf);
+ if (QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA && IsUserAdmin()) {
+ // Special case : If the user is a member of Administrators group, all files
+ // created by the current user are owned by the Administrators group.
+ LPLOCALGROUP_USERS_INFO_0 pBuf = NULL;
+ DWORD dwLevel = 0;
+ DWORD dwFlags = LG_INCLUDE_INDIRECT ;
+ DWORD dwPrefMaxLen = MAX_PREFERRED_LENGTH;
+ DWORD dwEntriesRead = 0;
+ DWORD dwTotalEntries = 0;
+ NET_API_STATUS nStatus;
+ nStatus = NetUserGetLocalGroups(0, usernameBuf, dwLevel, dwFlags, (LPBYTE *) &pBuf,
+ dwPrefMaxLen, &dwEntriesRead, &dwTotalEntries);
+ // Check if the current user is a member of Administrators group
+ if (nStatus == NERR_Success && pBuf){
+ for (int i = 0; i < dwEntriesRead; i++) {
+ QString groupName = QString::fromWCharArray(pBuf[i].lgrui0_name);
+ if (!groupName.compare(QLatin1String("Administrators")))
+ userName = groupName;
+ }
}
+ if (pBuf != NULL)
+ NetApiBufferFree(pBuf);
}
- if (pBuf != NULL)
- NetApiBufferFree(pBuf);
}
extern Q_CORE_EXPORT int qt_ntfs_permission_lookup;
qt_ntfs_permission_lookup = 1;