mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 02:25:40 +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
1 changed files with 32 additions and 6 deletions
|
@ -92,14 +92,16 @@ void PerfDataRefresh(void)
|
||||||
PPERFDATA pPDOld;
|
PPERFDATA pPDOld;
|
||||||
ULONG Idx, Idx2;
|
ULONG Idx, Idx2;
|
||||||
HANDLE hProcess;
|
HANDLE hProcess;
|
||||||
|
HANDLE hProcessToken;
|
||||||
SYSTEM_PERFORMANCE_INFORMATION SysPerfInfo;
|
SYSTEM_PERFORMANCE_INFORMATION SysPerfInfo;
|
||||||
SYSTEM_TIMEOFDAY_INFORMATION SysTimeInfo;
|
SYSTEM_TIMEOFDAY_INFORMATION SysTimeInfo;
|
||||||
SYSTEM_CACHE_INFORMATION SysCacheInfo;
|
SYSTEM_CACHE_INFORMATION SysCacheInfo;
|
||||||
LPBYTE SysHandleInfoData;
|
LPBYTE SysHandleInfoData;
|
||||||
PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION SysProcessorTimeInfo;
|
PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION SysProcessorTimeInfo;
|
||||||
double CurrentKernelTime;
|
double CurrentKernelTime;
|
||||||
PSECURITY_DESCRIPTOR ProcessSD = NULL;
|
PSECURITY_DESCRIPTOR ProcessSD;
|
||||||
PSID ProcessUser;
|
PSID ProcessUser;
|
||||||
|
ULONG Buffer[64]; /* must be 4 bytes aligned! */
|
||||||
|
|
||||||
/* Get new system time */
|
/* Get new system time */
|
||||||
status = NtQuerySystemInformation(SystemTimeOfDayInformation, &SysTimeInfo, sizeof(SysTimeInfo), 0);
|
status = NtQuerySystemInformation(SystemTimeOfDayInformation, &SysTimeInfo, sizeof(SysTimeInfo), 0);
|
||||||
|
@ -281,15 +283,41 @@ void PerfDataRefresh(void)
|
||||||
pPerfData[Idx].ThreadCount = pSPI->NumberOfThreads;
|
pPerfData[Idx].ThreadCount = pSPI->NumberOfThreads;
|
||||||
pPerfData[Idx].SessionId = pSPI->SessionId;
|
pPerfData[Idx].SessionId = pSPI->SessionId;
|
||||||
pPerfData[Idx].UserName[0] = _T('\0');
|
pPerfData[Idx].UserName[0] = _T('\0');
|
||||||
|
pPerfData[Idx].USERObjectCount = 0;
|
||||||
|
pPerfData[Idx].GDIObjectCount = 0;
|
||||||
ProcessUser = SystemUserSid;
|
ProcessUser = SystemUserSid;
|
||||||
|
ProcessSD = NULL;
|
||||||
|
|
||||||
if (pSPI->UniqueProcessId != NULL) {
|
if (pSPI->UniqueProcessId != NULL) {
|
||||||
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | READ_CONTROL, FALSE, PtrToUlong(pSPI->UniqueProcessId));
|
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | READ_CONTROL, FALSE, PtrToUlong(pSPI->UniqueProcessId));
|
||||||
if (hProcess) {
|
if (hProcess) {
|
||||||
GetSecurityInfo(hProcess, SE_KERNEL_OBJECT, OWNER_SECURITY_INFORMATION, &ProcessUser, NULL, NULL, NULL, &ProcessSD);
|
/* 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);
|
||||||
|
}
|
||||||
|
|
||||||
pPerfData[Idx].USERObjectCount = GetGuiResources(hProcess, GR_USEROBJECTS);
|
|
||||||
pPerfData[Idx].GDIObjectCount = GetGuiResources(hProcess, GR_GDIOBJECTS);
|
|
||||||
GetProcessIoCounters(hProcess, &pPerfData[Idx].IOCounters);
|
GetProcessIoCounters(hProcess, &pPerfData[Idx].IOCounters);
|
||||||
CloseHandle(hProcess);
|
CloseHandle(hProcess);
|
||||||
} else {
|
} else {
|
||||||
|
@ -298,8 +326,6 @@ void PerfDataRefresh(void)
|
||||||
} else {
|
} else {
|
||||||
ClearInfo:
|
ClearInfo:
|
||||||
/* clear information we were unable to fetch */
|
/* clear information we were unable to fetch */
|
||||||
pPerfData[Idx].USERObjectCount = 0;
|
|
||||||
pPerfData[Idx].GDIObjectCount = 0;
|
|
||||||
ZeroMemory(&pPerfData[Idx].IOCounters, sizeof(IO_COUNTERS));
|
ZeroMemory(&pPerfData[Idx].IOCounters, sizeof(IO_COUNTERS));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue