Windows : fix call to LookupAccountNameW
The call to LookupAccountNameW from advapi32 was rewritten following the example: http://msdn.microsoft.com/en-us/library/aa392742%28v=vs.85%29.aspx This prevents the generation of a garbage pointer when accessing QWindowsSystemProxy::init() for Qt compiled as 64bit library with MinGW-w64. Task-number: QTBUG-39874 Task-number: QTBUG-38145 Change-Id: I620b2fa64941f84838f9a386851480285336e8d1 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> Reviewed-by: Richard J. Moore <rich@kde.org>
This commit is contained in:
parent
83a3292342
commit
dcedbce99a
@ -130,10 +130,17 @@ static bool currentProcessIsService()
|
|||||||
DWORD size = UNLEN;
|
DWORD size = UNLEN;
|
||||||
if (ptrGetUserName(userName, &size)) {
|
if (ptrGetUserName(userName, &size)) {
|
||||||
SID_NAME_USE type = SidTypeUser;
|
SID_NAME_USE type = SidTypeUser;
|
||||||
DWORD dummy = MAX_PATH;
|
DWORD sidSize = 0;
|
||||||
wchar_t dummyStr[MAX_PATH] = L"";
|
DWORD domainSize = 0;
|
||||||
PSID psid = 0;
|
// first call is to get the correct size
|
||||||
if (ptrLookupAccountName(NULL, userName, &psid, &dummy, dummyStr, &dummy, &type))
|
bool bRet = ptrLookupAccountName(NULL, userName, NULL, &sidSize, NULL, &domainSize, &type);
|
||||||
|
if (bRet == FALSE && ERROR_INSUFFICIENT_BUFFER != GetLastError())
|
||||||
|
return false;
|
||||||
|
QVarLengthArray<BYTE, 68> buff(sidSize);
|
||||||
|
QVarLengthArray<wchar_t, MAX_PATH> domainName(domainSize);
|
||||||
|
// second call to LookupAccountNameW actually gets the SID
|
||||||
|
// both the pointer to the buffer and the pointer to the domain name should not be NULL
|
||||||
|
if (ptrLookupAccountName(NULL, userName, buff.data(), &sidSize, domainName.data(), &domainSize, &type))
|
||||||
return type != SidTypeUser; //returns true if the current user is not a user
|
return type != SidTypeUser; //returns true if the current user is not a user
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user