Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

221 lines
4.9 KiB

  1. //Copyright (c) Microsoft Corporation. All rights reserved.
  2. // EnumData.cpp: implementation of the CEnumData class.
  3. //
  4. //////////////////////////////////////////////////////////////////////
  5. //#include ""
  6. #include <tchar.h>
  7. #include "TlntSvr.h"
  8. #include "EnumData.h"
  9. #ifdef _DEBUG
  10. #undef THIS_FILE
  11. static char THIS_FILE[]=__FILE__;
  12. //#define new DEBUG_NEW
  13. #endif
  14. //////////////////////////////////////////////////////////////////////
  15. // Construction/Destruction
  16. //////////////////////////////////////////////////////////////////////
  17. CEnumData::CNode::CNode( LPWSTR lpszName, LPWSTR lpszDom ,
  18. LPWSTR lpszPeerHostname, SYSTEMTIME lgnTime, LONG lId ) : pNext( NULL )
  19. {
  20. lpszUserName = new WCHAR [ wcslen( lpszName ) + 1 ];
  21. if (lpszUserName)
  22. {
  23. wcscpy( lpszUserName, lpszName ); // Skip this functon, no bo here... Baskar
  24. }
  25. lpszDomain = new WCHAR [ wcslen( lpszDom ) + 1 ];
  26. if (lpszDomain)
  27. {
  28. wcscpy( lpszDomain, lpszDom );
  29. }
  30. lpszPeerHostName = new WCHAR [ wcslen( lpszPeerHostname ) + 1 ];
  31. if (lpszPeerHostName)
  32. {
  33. wcscpy( lpszPeerHostName, lpszPeerHostname );
  34. }
  35. logonTime = lgnTime;
  36. lUniqueId = lId;
  37. pProcessesHead = NULL;
  38. pProcessesTail = NULL;
  39. }
  40. CEnumData::CNode::~CNode( )
  41. {
  42. if (lpszUserName)
  43. {
  44. delete [] lpszUserName;
  45. lpszUserName = NULL;
  46. }
  47. if (lpszDomain)
  48. {
  49. delete [] lpszDomain;
  50. lpszDomain = NULL;
  51. }
  52. if (lpszPeerHostName)
  53. {
  54. delete [] lpszPeerHostName;
  55. lpszPeerHostName = NULL;
  56. }
  57. }
  58. CEnumData::CEnumData()
  59. : m_pPosition( NULL ), m_pHead( NULL )
  60. {
  61. }
  62. CEnumData::~CEnumData()
  63. {
  64. while( m_pHead )
  65. {
  66. m_pPosition = m_pHead->pNext;
  67. //delete the list of PIDs, Names.
  68. while( m_pHead->pProcessesHead )
  69. {
  70. m_pHead->pProcessesTail = m_pHead->pProcessesHead->pNextPId;
  71. delete m_pHead->pProcessesHead;
  72. m_pHead->pProcessesHead = m_pHead->pProcessesTail;
  73. }
  74. delete m_pHead;
  75. m_pHead = m_pPosition;
  76. }
  77. }
  78. void
  79. CEnumData::Add
  80. (
  81. LPWSTR lpszName,
  82. LPWSTR lpszDom,
  83. LPWSTR lpszPeerHostName,
  84. SYSTEMTIME lgnTime,
  85. LONG lId
  86. )
  87. {
  88. CNode* pNewNode = new CNode( lpszName, lpszDom, lpszPeerHostName, lgnTime, lId );
  89. if (NULL != pNewNode)
  90. {
  91. if( NULL == m_pHead )
  92. {
  93. m_pHead = pNewNode;
  94. }
  95. else
  96. {
  97. m_pPosition->pNext = pNewNode;
  98. }
  99. m_pPosition = pNewNode;
  100. }
  101. }
  102. void
  103. CEnumData::Add
  104. (
  105. LONG lId,
  106. DWORD dwId,
  107. WCHAR *lpszName
  108. )
  109. {
  110. PIdNode *pPIdNode;
  111. CNode *pCNode;
  112. pCNode = m_pHead;
  113. if ( !pCNode )
  114. return;
  115. pPIdNode = new PIdNode( dwId, lpszName );
  116. while( pCNode && pCNode->lUniqueId != lId )
  117. {
  118. pCNode = pCNode->pNext;
  119. }
  120. if (pPIdNode && pCNode && (pCNode->lUniqueId == lId) )
  121. {
  122. if ( !pCNode->pProcessesHead )
  123. {
  124. pCNode->pProcessesHead = pPIdNode;
  125. }
  126. else
  127. {
  128. pCNode->pProcessesTail->pNextPId = pPIdNode;
  129. }
  130. pCNode->pProcessesTail = pPIdNode;
  131. }
  132. else
  133. {
  134. delete pPIdNode;
  135. }
  136. }
  137. void CEnumData::Reset()
  138. {
  139. m_pPosition = m_pHead;
  140. }
  141. bool
  142. CEnumData::GetNext
  143. (
  144. CEnumData::CNode** ppNode
  145. )
  146. {
  147. PIdNode *pPIdNode = NULL;
  148. if( NULL == ppNode )
  149. {
  150. return ( false );
  151. }
  152. if( NULL == m_pPosition )
  153. {
  154. SYSTEMTIME lgnTime;
  155. ZeroMemory( &lgnTime, sizeof( SYSTEMTIME ) );
  156. *ppNode = new CNode( L"", L"", L"", lgnTime, 0 );
  157. return ( false );
  158. }
  159. *ppNode = new CNode( m_pPosition->lpszUserName, m_pPosition->lpszDomain,
  160. m_pPosition->lpszPeerHostName, m_pPosition->logonTime, m_pPosition->lUniqueId );
  161. if (NULL == *ppNode)
  162. {
  163. return (false);
  164. }
  165. if( m_pPosition->pProcessesHead )
  166. {
  167. pPIdNode = m_pPosition->pProcessesHead;
  168. ( *ppNode )->pProcessesHead = new
  169. PIdNode( pPIdNode->dwPId, pPIdNode->lpszProcessName );
  170. if (NULL == (*ppNode)->pProcessesHead)
  171. {
  172. delete *ppNode;
  173. *ppNode = NULL;
  174. return false;
  175. }
  176. ( *ppNode )->pProcessesTail = ( *ppNode )->pProcessesHead;
  177. pPIdNode = pPIdNode->pNextPId;
  178. while( pPIdNode )
  179. {
  180. ( *ppNode )->pProcessesTail->pNextPId = new
  181. PIdNode( pPIdNode->dwPId, pPIdNode->lpszProcessName );
  182. ( *ppNode )->pProcessesTail =
  183. ( *ppNode )->pProcessesTail->pNextPId;
  184. pPIdNode = pPIdNode->pNextPId;
  185. }
  186. }
  187. m_pPosition = m_pPosition->pNext;
  188. return ( true );
  189. }