Remove useless blocks
Don't put the code inside two blocks for no reason. Change-Id: I54b8d6fbfab50a26ddcd8ec07ba689e5094bcad3 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
605d383a70
commit
f28e161361
@ -178,47 +178,43 @@ GlobalSid::~GlobalSid()
|
|||||||
|
|
||||||
GlobalSid::GlobalSid()
|
GlobalSid::GlobalSid()
|
||||||
{
|
{
|
||||||
{
|
// Create TRUSTEE for current user
|
||||||
{
|
HANDLE hnd = ::GetCurrentProcess();
|
||||||
// Create TRUSTEE for current user
|
HANDLE token = 0;
|
||||||
HANDLE hnd = ::GetCurrentProcess();
|
if (::OpenProcessToken(hnd, TOKEN_QUERY, &token)) {
|
||||||
HANDLE token = 0;
|
DWORD retsize = 0;
|
||||||
if (::OpenProcessToken(hnd, TOKEN_QUERY, &token)) {
|
// GetTokenInformation requires a buffer big enough for the TOKEN_USER struct and
|
||||||
DWORD retsize = 0;
|
// the SID struct. Since the SID struct can have variable number of subauthorities
|
||||||
// GetTokenInformation requires a buffer big enough for the TOKEN_USER struct and
|
// tacked at the end, its size is variable. Obtain the required size by first
|
||||||
// the SID struct. Since the SID struct can have variable number of subauthorities
|
// doing a dummy GetTokenInformation call.
|
||||||
// tacked at the end, its size is variable. Obtain the required size by first
|
::GetTokenInformation(token, TokenUser, 0, 0, &retsize);
|
||||||
// doing a dummy GetTokenInformation call.
|
if (retsize) {
|
||||||
::GetTokenInformation(token, TokenUser, 0, 0, &retsize);
|
void *tokenBuffer = malloc(retsize);
|
||||||
if (retsize) {
|
Q_CHECK_PTR(tokenBuffer);
|
||||||
void *tokenBuffer = malloc(retsize);
|
if (::GetTokenInformation(token, TokenUser, tokenBuffer, retsize, &retsize)) {
|
||||||
Q_CHECK_PTR(tokenBuffer);
|
PSID tokenSid = reinterpret_cast<PTOKEN_USER>(tokenBuffer)->User.Sid;
|
||||||
if (::GetTokenInformation(token, TokenUser, tokenBuffer, retsize, &retsize)) {
|
DWORD sidLen = ::GetLengthSid(tokenSid);
|
||||||
PSID tokenSid = reinterpret_cast<PTOKEN_USER>(tokenBuffer)->User.Sid;
|
currentUserSID = reinterpret_cast<PSID>(malloc(sidLen));
|
||||||
DWORD sidLen = ::GetLengthSid(tokenSid);
|
Q_CHECK_PTR(currentUserSID);
|
||||||
currentUserSID = reinterpret_cast<PSID>(malloc(sidLen));
|
if (::CopySid(sidLen, currentUserSID, tokenSid))
|
||||||
Q_CHECK_PTR(currentUserSID);
|
BuildTrusteeWithSid(¤tUserTrusteeW, currentUserSID);
|
||||||
if (::CopySid(sidLen, currentUserSID, tokenSid))
|
|
||||||
BuildTrusteeWithSid(¤tUserTrusteeW, currentUserSID);
|
|
||||||
}
|
|
||||||
free(tokenBuffer);
|
|
||||||
}
|
|
||||||
::CloseHandle(token);
|
|
||||||
}
|
|
||||||
|
|
||||||
token = nullptr;
|
|
||||||
if (::OpenProcessToken(hnd, TOKEN_IMPERSONATE | TOKEN_QUERY | TOKEN_DUPLICATE | STANDARD_RIGHTS_READ, &token)) {
|
|
||||||
::DuplicateToken(token, SecurityImpersonation, ¤tUserImpersonatedToken);
|
|
||||||
::CloseHandle(token);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
// Create TRUSTEE for Everyone (World)
|
|
||||||
SID_IDENTIFIER_AUTHORITY worldAuth = { SECURITY_WORLD_SID_AUTHORITY };
|
|
||||||
if (AllocateAndInitializeSid(&worldAuth, 1, SECURITY_WORLD_RID, 0, 0, 0, 0, 0, 0, 0, &worldSID))
|
|
||||||
BuildTrusteeWithSid(&worldTrusteeW, worldSID);
|
|
||||||
}
|
}
|
||||||
|
free(tokenBuffer);
|
||||||
}
|
}
|
||||||
|
::CloseHandle(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
token = nullptr;
|
||||||
|
if (::OpenProcessToken(hnd, TOKEN_IMPERSONATE | TOKEN_QUERY | TOKEN_DUPLICATE | STANDARD_RIGHTS_READ, &token)) {
|
||||||
|
::DuplicateToken(token, SecurityImpersonation, ¤tUserImpersonatedToken);
|
||||||
|
::CloseHandle(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// Create TRUSTEE for Everyone (World)
|
||||||
|
SID_IDENTIFIER_AUTHORITY worldAuth = { SECURITY_WORLD_SID_AUTHORITY };
|
||||||
|
if (AllocateAndInitializeSid(&worldAuth, 1, SECURITY_WORLD_RID, 0, 0, 0, 0, 0, 0, 0, &worldSID))
|
||||||
|
BuildTrusteeWithSid(&worldTrusteeW, worldSID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user