mirror of
https://github.com/reactos/reactos.git
synced 2024-10-05 00:43:21 +00:00
try to get the user from the token and fall back to reading the owner from the process when needed
svn path=/trunk/; revision=20971
This commit is contained in:
parent
465156f383
commit
d8c8151df3
|
@ -92,14 +92,16 @@ void PerfDataRefresh(void)
|
|||
PPERFDATA pPDOld;
|
||||
ULONG Idx, Idx2;
|
||||
HANDLE hProcess;
|
||||
HANDLE hProcessToken;
|
||||
SYSTEM_PERFORMANCE_INFORMATION SysPerfInfo;
|
||||
SYSTEM_TIMEOFDAY_INFORMATION SysTimeInfo;
|
||||
SYSTEM_CACHE_INFORMATION SysCacheInfo;
|
||||
LPBYTE SysHandleInfoData;
|
||||
PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION SysProcessorTimeInfo;
|
||||
double CurrentKernelTime;
|
||||
PSECURITY_DESCRIPTOR ProcessSD = NULL;
|
||||
PSECURITY_DESCRIPTOR ProcessSD;
|
||||
PSID ProcessUser;
|
||||
ULONG Buffer[64]; /* must be 4 bytes aligned! */
|
||||
|
||||
/* Get new system time */
|
||||
status = NtQuerySystemInformation(SystemTimeOfDayInformation, &SysTimeInfo, sizeof(SysTimeInfo), 0);
|
||||
|
@ -281,15 +283,41 @@ void PerfDataRefresh(void)
|
|||
pPerfData[Idx].ThreadCount = pSPI->NumberOfThreads;
|
||||
pPerfData[Idx].SessionId = pSPI->SessionId;
|
||||
pPerfData[Idx].UserName[0] = _T('\0');
|
||||
pPerfData[Idx].USERObjectCount = 0;
|
||||
pPerfData[Idx].GDIObjectCount = 0;
|
||||
ProcessUser = SystemUserSid;
|
||||
ProcessSD = NULL;
|
||||
|
||||
if (pSPI->UniqueProcessId != NULL) {
|
||||
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | READ_CONTROL, FALSE, PtrToUlong(pSPI->UniqueProcessId));
|
||||
if (hProcess) {
|
||||
/* don't query the information of the system process. It's possible but
|
||||
returns Administrators as the owner of the process instead of SYSTEM */
|
||||
if (pSPI->UniqueProcessId != (HANDLE)0x4)
|
||||
{
|
||||
if (OpenProcessToken(hProcess, TOKEN_QUERY, &hProcessToken))
|
||||
{
|
||||
DWORD RetLen = 0;
|
||||
BOOL Ret;
|
||||
|
||||
Ret = GetTokenInformation(hProcessToken, TokenUser, (LPVOID)Buffer, sizeof(Buffer), &RetLen);
|
||||
CloseHandle(hProcessToken);
|
||||
|
||||
if (Ret)
|
||||
ProcessUser = ((PTOKEN_USER)Buffer)->User.Sid;
|
||||
else
|
||||
goto ReadProcOwner;
|
||||
}
|
||||
else
|
||||
{
|
||||
ReadProcOwner:
|
||||
GetSecurityInfo(hProcess, SE_KERNEL_OBJECT, OWNER_SECURITY_INFORMATION, &ProcessUser, NULL, NULL, NULL, &ProcessSD);
|
||||
}
|
||||
|
||||
pPerfData[Idx].USERObjectCount = GetGuiResources(hProcess, GR_USEROBJECTS);
|
||||
pPerfData[Idx].GDIObjectCount = GetGuiResources(hProcess, GR_GDIOBJECTS);
|
||||
}
|
||||
|
||||
GetProcessIoCounters(hProcess, &pPerfData[Idx].IOCounters);
|
||||
CloseHandle(hProcess);
|
||||
} else {
|
||||
|
@ -298,8 +326,6 @@ void PerfDataRefresh(void)
|
|||
} else {
|
||||
ClearInfo:
|
||||
/* clear information we were unable to fetch */
|
||||
pPerfData[Idx].USERObjectCount = 0;
|
||||
pPerfData[Idx].GDIObjectCount = 0;
|
||||
ZeroMemory(&pPerfData[Idx].IOCounters, sizeof(IO_COUNTERS));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue