Author: gschneider
Date: Sat Apr 10 17:51:31 2010
New Revision: 46816
URL:
http://svn.reactos.org/svn/reactos?rev=46816&view=rev
Log:
[TASKMGR]
- Implement a SID to user name cache, patch by Timo Kreuzer with some changes by me
See issue #4844 for more details.
Modified:
trunk/reactos/base/applications/taskmgr/perfdata.c
Modified: trunk/reactos/base/applications/taskmgr/perfdata.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/taskmgr/…
==============================================================================
--- trunk/reactos/base/applications/taskmgr/perfdata.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/taskmgr/perfdata.c [iso-8859-1] Sat Apr 10 17:51:31
2010
@@ -40,6 +40,15 @@
PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION SystemProcessorTimeInfo = NULL;
PSID SystemUserSid = NULL;
+typedef struct _SIDTOUSERNAME
+{
+ LIST_ENTRY List;
+ LPWSTR pszName;
+ BYTE Data[0];
+} SIDTOUSERNAME, *PSIDTOUSERNAME;
+
+static LIST_ENTRY SidToUserNameHead = {&SidToUserNameHead, &SidToUserNameHead};
+
BOOL PerfDataInitialize(void)
{
SID_IDENTIFIER_AUTHORITY NtSidAuthority = {SECURITY_NT_AUTHORITY};
@@ -63,6 +72,8 @@
void PerfDataUninitialize(void)
{
+ PLIST_ENTRY pCur;
+ PSIDTOUSERNAME pEntry;
if (pPerfData != NULL)
HeapFree(GetProcessHeap(), 0, pPerfData);
@@ -73,6 +84,15 @@
{
FreeSid(SystemUserSid);
SystemUserSid = NULL;
+ }
+
+ /* Free user names cache list */
+ pCur = SidToUserNameHead.Flink;
+ while (pCur != &SidToUserNameHead)
+ {
+ pEntry = CONTAINING_RECORD(pCur, SIDTOUSERNAME, List);
+ pCur = pCur->Flink;
+ HeapFree(GetProcessHeap(), 0, pEntry);
}
}
@@ -84,6 +104,56 @@
if (Sid != NULL)
LookupAccountSidW(NULL, Sid, szBuffer, &BufferSize, szDomainNameUnused,
&DomainNameLen, &Use);
+}
+
+VOID
+WINAPI
+CachedGetUserFromSid(
+ PSID pSid,
+ LPWSTR pUserName,
+ PULONG pcwcUserName)
+{
+ PLIST_ENTRY pCur;
+ PSIDTOUSERNAME pEntry;
+ ULONG cbSid, cwcUserName;
+
+ cwcUserName = *pcwcUserName;
+
+ /* Walk through the list */
+ for(pCur = SidToUserNameHead.Flink;
+ pCur != &SidToUserNameHead;
+ pCur = pCur->Flink)
+ {
+ pEntry = CONTAINING_RECORD(pCur, SIDTOUSERNAME, List);
+ if (EqualSid((PSID)&pEntry->Data, pSid))
+ {
+ wcsncpy(pUserName, pEntry->pszName, cwcUserName);
+ *pcwcUserName = cwcUserName;
+ return;
+ }
+ }
+
+ /* We didn't find the SID in the list, get the name conventional */
+ SidToUserName(pSid, pUserName, cwcUserName);
+
+ /* Allocate a new entry */
+ *pcwcUserName = wcslen(pUserName);
+ cwcUserName = *pcwcUserName + 1;
+ cbSid = GetLengthSid(pSid);
+ pEntry = HeapAlloc(GetProcessHeap(), 0, sizeof(SIDTOUSERNAME) + cbSid + cwcUserName *
sizeof(WCHAR));
+
+ /* Copy the Sid and name to our entry */
+ CopySid(cbSid, (PSID)&pEntry->Data, pSid);
+ pEntry->pszName = (LPWSTR)(pEntry->Data + cbSid);
+ wcsncpy(pEntry->pszName, pUserName, cwcUserName);
+
+ /* Insert the new entry */
+ pEntry->List.Flink = &SidToUserNameHead;
+ pEntry->List.Blink = SidToUserNameHead.Blink;
+ SidToUserNameHead.Blink->Flink = &pEntry->List;
+ SidToUserNameHead.Blink = &pEntry->List;
+
+ return;
}
void PerfDataRefresh(void)
@@ -106,6 +176,7 @@
PSECURITY_DESCRIPTOR ProcessSD;
PSID ProcessUser;
ULONG Buffer[64]; /* must be 4 bytes aligned!
*/
+ ULONG cwcUserName;
/* Get new system time */
status = NtQuerySystemInformation(SystemTimeOfDayInformation, &SysTimeInfo,
sizeof(SysTimeInfo), 0);
@@ -341,7 +412,8 @@
ZeroMemory(&pPerfData[Idx].IOCounters, sizeof(IO_COUNTERS));
}
- SidToUserName(ProcessUser, pPerfData[Idx].UserName, sizeof(pPerfData[0].UserName)
/ sizeof(pPerfData[0].UserName[0]));
+ cwcUserName = sizeof(pPerfData[0].UserName) / sizeof(pPerfData[0].UserName[0]);
+ CachedGetUserFromSid(ProcessUser, pPerfData[Idx].UserName, &cwcUserName);
if (ProcessSD != NULL)
{