Refactor GetProcessSid to remove do while FALSE

master
Spencer McIntyre 2017-11-07 19:11:24 -05:00
parent 7d1de9bc48
commit c2578c1487
3 changed files with 19 additions and 32 deletions

View File

@ -48,44 +48,31 @@ BOOL GetProcessSid(HANDLE hProc, PSID *pSid) {
SIZE_T szSid = 0;
*pSid = NULL;
do {
if (!OpenProcessToken(hProc, (TOKEN_READ), &hToken)) {
return FALSE;
}
GetTokenInformation(hToken, TokenUser, NULL, 0, &dwLength);
tuUser = (TOKEN_USER *)malloc(dwLength);
if (tuUser == NULL) {
break;
if (!tuUser) {
return FALSE;
}
if (!GetTokenInformation(hToken, TokenUser, tuUser, dwLength, &dwLength)) {
break;
free(tuUser);
return FALSE;
}
szSid = GetLengthSid(tuUser->User.Sid);
*pSid = LocalAlloc(LPTR, szSid);
if (*pSid == NULL) {
break;
}
if (!CopySid((DWORD)szSid, *pSid, tuUser->User.Sid)) {
if ((*pSid) && (!CopySid((DWORD)szSid, *pSid, tuUser->User.Sid))) {
LocalFree(*pSid);
*pSid = NULL;
}
} while (FALSE);
if (tuUser != NULL) {
free(tuUser);
}
if (hToken) {
CloseHandle(hToken);
}
if (*pSid != NULL) {
return TRUE;
}
return FALSE;
return *pSid != NULL;
}
BOOL IsProcessRunningAsSidString(HANDLE hProc, LPCTSTR sStringSid, PBOOL pbResult) {