summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRitt Konstantin <ritt.ks@gmail.com>2010-01-07 18:28:53 (GMT)
committerJoão Abecasis <joao@trolltech.com>2010-01-07 18:30:27 (GMT)
commit751de8211033b40c66d88140137eef76e6b20cfa (patch)
tree839ecf91a587168782e5aba4320f2af7a678de84 /src
parent428a624f73ed03a311f572386de1a518ad3d5d5a (diff)
downloadQt-751de8211033b40c66d88140137eef76e6b20cfa.zip
Qt-751de8211033b40c66d88140137eef76e6b20cfa.tar.gz
Qt-751de8211033b40c66d88140137eef76e6b20cfa.tar.bz2
Avoid repeatedly calling LookupAccountSid in QFSFileEngine::owner
Try to retrieve user/group name in a single call to LookupAccountSid, by using pre-allocated buffers. Only call a second time if the buffer size is insufficient. 64 bytes should be enough in common case. Previously, we would always call LookupAccountSid twice, even if ERROR_NONE_MAPPED occured first time. Merge-request: 815 Reviewed-by: João Abecasis <joao@trolltech.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/io/qfsfileengine_win.cpp31
1 files changed, 21 insertions, 10 deletions
diff --git a/src/corelib/io/qfsfileengine_win.cpp b/src/corelib/io/qfsfileengine_win.cpp
index c3ea08a..bec0075 100644
--- a/src/corelib/io/qfsfileengine_win.cpp
+++ b/src/corelib/io/qfsfileengine_win.cpp
@@ -1731,20 +1731,31 @@ QString QFSFileEngine::owner(FileOwner own) const
own == OwnerGroup ? GROUP_SECURITY_INFORMATION : OWNER_SECURITY_INFORMATION,
own == OwnerUser ? &pOwner : 0, own == OwnerGroup ? &pOwner : 0,
0, 0, &pSD) == ERROR_SUCCESS) {
- DWORD lowner = 0, ldomain = 0;
+ DWORD lowner = 64;
+ DWORD ldomain = 64;
+ QVarLengthArray<wchar_t, 64> owner(lowner);
+ QVarLengthArray<wchar_t, 64> domain(ldomain);
SID_NAME_USE use = SidTypeUnknown;
// First call, to determine size of the strings (with '\0').
- ptrLookupAccountSidW(NULL, pOwner, NULL, &lowner, NULL, &ldomain, (SID_NAME_USE*)&use);
- wchar_t *owner = new wchar_t[lowner];
- wchar_t *domain = new wchar_t[ldomain];
- // Second call, size is without '\0'
- if (ptrLookupAccountSidW(NULL, pOwner, (LPWSTR)owner, &lowner,
- (LPWSTR)domain, &ldomain, (SID_NAME_USE*)&use)) {
- name = QString::fromUtf16((ushort*)owner);
+ if (!ptrLookupAccountSidW(NULL, pOwner, (LPWSTR)owner.data(), &lowner,
+ (LPWSTR)domain.data(), &ldomain, (SID_NAME_USE*)&use)) {
+ if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
+ if (lowner > (DWORD)owner.size())
+ owner.resize(lowner);
+ if (ldomain > (DWORD)domain.size())
+ domain.resize(ldomain);
+ // Second call, try on resized buf-s
+ if (!ptrLookupAccountSidW(NULL, pOwner, (LPWSTR)owner.data(), &lowner,
+ (LPWSTR)domain.data(), &ldomain, (SID_NAME_USE*)&use)) {
+ lowner = 0;
+ }
+ } else {
+ lowner = 0;
+ }
}
+ if (lowner != 0)
+ name = QString::fromWCharArray(owner.data());
LocalFree(pSD);
- delete [] owner;
- delete [] domain;
}
}
}