Refactor GetProcessSid to remove do while FALSE
parent
7d1de9bc48
commit
c2578c1487
Binary file not shown.
Binary file not shown.
|
@ -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;
|
||||
}
|
||||
if (!OpenProcessToken(hProc, (TOKEN_READ), &hToken)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
GetTokenInformation(hToken, TokenUser, NULL, 0, &dwLength);
|
||||
tuUser = (TOKEN_USER *)malloc(dwLength);
|
||||
if (tuUser == NULL) {
|
||||
break;
|
||||
}
|
||||
GetTokenInformation(hToken, TokenUser, NULL, 0, &dwLength);
|
||||
tuUser = (TOKEN_USER *)malloc(dwLength);
|
||||
if (!tuUser) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!GetTokenInformation(hToken, TokenUser, tuUser, dwLength, &dwLength)) {
|
||||
break;
|
||||
}
|
||||
|
||||
szSid = GetLengthSid(tuUser->User.Sid);
|
||||
*pSid = LocalAlloc(LPTR, szSid);
|
||||
if (*pSid == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!CopySid((DWORD)szSid, *pSid, tuUser->User.Sid)) {
|
||||
LocalFree(*pSid);
|
||||
*pSid = NULL;
|
||||
}
|
||||
} while (FALSE);
|
||||
|
||||
if (tuUser != NULL) {
|
||||
if (!GetTokenInformation(hToken, TokenUser, tuUser, dwLength, &dwLength)) {
|
||||
free(tuUser);
|
||||
}
|
||||
if (hToken) {
|
||||
CloseHandle(hToken);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (*pSid != NULL) {
|
||||
return TRUE;
|
||||
szSid = GetLengthSid(tuUser->User.Sid);
|
||||
*pSid = LocalAlloc(LPTR, szSid);
|
||||
if ((*pSid) && (!CopySid((DWORD)szSid, *pSid, tuUser->User.Sid))) {
|
||||
LocalFree(*pSid);
|
||||
*pSid = NULL;
|
||||
}
|
||||
return FALSE;
|
||||
|
||||
free(tuUser);
|
||||
CloseHandle(hToken);
|
||||
return *pSid != NULL;
|
||||
}
|
||||
|
||||
BOOL IsProcessRunningAsSidString(HANDLE hProc, LPCTSTR sStringSid, PBOOL pbResult) {
|
||||
|
|
Loading…
Reference in New Issue