From f28e1613617b519ff6442607c99033291623d38f Mon Sep 17 00:00:00 2001 From: Ievgenii Meshcheriakov Date: Wed, 10 Nov 2021 12:39:04 +0100 Subject: Remove useless blocks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Don't put the code inside two blocks for no reason. Change-Id: I54b8d6fbfab50a26ddcd8ec07ba689e5094bcad3 Reviewed-by: MÃ¥rten Nordheim --- src/corelib/io/qfilesystemengine_win.cpp | 72 +++++++++++++++----------------- 1 file changed, 34 insertions(+), 38 deletions(-) (limited to 'src/corelib/io') diff --git a/src/corelib/io/qfilesystemengine_win.cpp b/src/corelib/io/qfilesystemengine_win.cpp index d2da2082fa..f384e48572 100644 --- a/src/corelib/io/qfilesystemengine_win.cpp +++ b/src/corelib/io/qfilesystemengine_win.cpp @@ -178,47 +178,43 @@ GlobalSid::~GlobalSid() GlobalSid::GlobalSid() { - { - { - // Create TRUSTEE for current user - HANDLE hnd = ::GetCurrentProcess(); - HANDLE token = 0; - if (::OpenProcessToken(hnd, TOKEN_QUERY, &token)) { - DWORD retsize = 0; - // GetTokenInformation requires a buffer big enough for the TOKEN_USER struct and - // the SID struct. Since the SID struct can have variable number of subauthorities - // tacked at the end, its size is variable. Obtain the required size by first - // doing a dummy GetTokenInformation call. - ::GetTokenInformation(token, TokenUser, 0, 0, &retsize); - if (retsize) { - void *tokenBuffer = malloc(retsize); - Q_CHECK_PTR(tokenBuffer); - if (::GetTokenInformation(token, TokenUser, tokenBuffer, retsize, &retsize)) { - PSID tokenSid = reinterpret_cast(tokenBuffer)->User.Sid; - DWORD sidLen = ::GetLengthSid(tokenSid); - currentUserSID = reinterpret_cast(malloc(sidLen)); - Q_CHECK_PTR(currentUserSID); - if (::CopySid(sidLen, currentUserSID, tokenSid)) - BuildTrusteeWithSid(¤tUserTrusteeW, currentUserSID); - } - free(tokenBuffer); - } - ::CloseHandle(token); + // Create TRUSTEE for current user + HANDLE hnd = ::GetCurrentProcess(); + HANDLE token = 0; + if (::OpenProcessToken(hnd, TOKEN_QUERY, &token)) { + DWORD retsize = 0; + // GetTokenInformation requires a buffer big enough for the TOKEN_USER struct and + // the SID struct. Since the SID struct can have variable number of subauthorities + // tacked at the end, its size is variable. Obtain the required size by first + // doing a dummy GetTokenInformation call. + ::GetTokenInformation(token, TokenUser, 0, 0, &retsize); + if (retsize) { + void *tokenBuffer = malloc(retsize); + Q_CHECK_PTR(tokenBuffer); + if (::GetTokenInformation(token, TokenUser, tokenBuffer, retsize, &retsize)) { + PSID tokenSid = reinterpret_cast(tokenBuffer)->User.Sid; + DWORD sidLen = ::GetLengthSid(tokenSid); + currentUserSID = reinterpret_cast(malloc(sidLen)); + Q_CHECK_PTR(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); - } + 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); - } - } + { + // 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); } } -- cgit v1.2.3