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.

236 lines
6.6 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: C M U T I L . C P P
  7. //
  8. // Contents: Connection manager.
  9. //
  10. // Notes:
  11. //
  12. // Author: omiller 1 Jun 2000
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include "cmutil.h"
  18. #include <objbase.h>
  19. #include <ncmisc.h>
  20. // Create an instance of CMUTIL so that we can be global
  21. //
  22. CCMUtil CCMUtil::s_instance; //ISSUE: Evil, evil, evil. This can throw and cause a crash.
  23. CCMUtil::CCMUtil() throw(SE_Exception)
  24. {
  25. InitializeCriticalSection( &m_CriticalSection );
  26. }
  27. CCMUtil::~CCMUtil() throw()
  28. {
  29. DeleteCriticalSection( &m_CriticalSection );
  30. }
  31. //+---------------------------------------------------------------------------
  32. //
  33. // Function: GetIteratorFromGuid
  34. //
  35. // Purpose: Retrieve the guid, name and status of a Hidden connectiod
  36. //
  37. // Connection Manager has two stages: Dialup and VPN.
  38. // For the Dialup it creates a hidden connectoid that the
  39. // folder (netshell) does not see. However netman caches
  40. // the name, guid and status of this connectedoid. Both
  41. // the parent and child connectoid have the same name.
  42. //
  43. // Arguments:
  44. // guid [in] GUID of the hidden connectiod to search for
  45. //
  46. // Returns: S_OK -- Found the hidden connectoid
  47. //
  48. // Author: omiller 1 Jun 2000
  49. //
  50. // Notes:
  51. //
  52. CCMUtil::CMEntryTable::iterator CCMUtil::GetIteratorFromGuid(const GUID & guid)
  53. {
  54. CMEntryTable::iterator iter;
  55. // Search through the list of hidden connections
  56. //
  57. for (iter = m_Table.begin(); iter != m_Table.end(); iter++)
  58. {
  59. if( iter->m_guid == guid )
  60. {
  61. // Found the hidden connection that maps to this guid
  62. //
  63. return iter;
  64. }
  65. }
  66. return NULL;
  67. }
  68. //+---------------------------------------------------------------------------
  69. //
  70. // Function: HrGetEntry
  71. //
  72. // Purpose: Retrive the guid, name and status of a Hidden connectiod
  73. //
  74. // Connection Manager has two stages: Dialup and VPN.
  75. // For the Dialup it creates a hidden connectoid that the
  76. // folder (netshell) does not see. However netman caches
  77. // the name, guid and status of this connectedoid. Both
  78. // the parent and child connectoid have the same name.
  79. //
  80. // Arguments:
  81. // guid [in] GUID of the hidden connectiod to search for
  82. // cm [out] A copy to the hidden entry
  83. //
  84. // Returns: TRUE -- Found the hidden connectoid
  85. //
  86. // Author: omiller 1 Jun 2000
  87. //
  88. // Notes:
  89. //
  90. HRESULT CCMUtil::HrGetEntry(const GUID & guid, CMEntry & cm)
  91. {
  92. CMEntryTable::iterator iter;
  93. HRESULT hr = S_FALSE;
  94. CExceptionSafeLock esCritSec(&m_CriticalSection);
  95. iter = GetIteratorFromGuid(guid);
  96. if( iter )
  97. {
  98. cm = *iter;
  99. hr = S_OK;
  100. }
  101. return hr;
  102. }
  103. //+---------------------------------------------------------------------------
  104. //
  105. // Function: HrGetEntry
  106. //
  107. // Purpose: Retrive the guid, name and status of a Hidden connectiod
  108. //
  109. // Connection Manager has two stages: Dialup and VPN.
  110. // For the Dialup it creates a hidden connectoid that the
  111. // folder (netshell) does not see. However netman caches
  112. // the name, guid and status of this connectedoid. Both
  113. // the parent and child connectoid have the same name.
  114. //
  115. // Arguments:
  116. // szEntryName [in] Name of the connection to look for
  117. // cm [out] A copy to the hidden entry
  118. //
  119. // Returns: S_OK -- Found the hidden connectoid
  120. //
  121. // Author: omiller 1 Jun 2000
  122. //
  123. // Notes:
  124. //
  125. HRESULT CCMUtil::HrGetEntry(const WCHAR * szEntryName, CMEntry & cm)
  126. {
  127. CMEntryTable::iterator iter;
  128. CExceptionSafeLock esCritSec(&m_CriticalSection);
  129. for (iter = m_Table.begin(); iter != m_Table.end(); iter++)
  130. {
  131. if( lstrcmp(iter->m_szEntryName,szEntryName) == 0 )
  132. {
  133. // Found the Hidden connectoid that maps to that name
  134. //
  135. cm = *iter;
  136. return S_OK;
  137. }
  138. }
  139. return S_FALSE;
  140. }
  141. //+---------------------------------------------------------------------------
  142. //
  143. // Function: SetEntry
  144. //
  145. // Purpose: Stores or Updates the guid, name and status of a Hidden connectiod
  146. //
  147. // Connection Manager has two stages: Dialup and VPN.
  148. // For the Dialup it creates a hidden connectoid that the
  149. // folder (netshell) does not see. However netman caches
  150. // the name, guid and status of this connectedoid. Both
  151. // the parent and child connectoid have the same name.
  152. //
  153. // Arguments:
  154. // guid [in] Guid of the Hidden connectiod
  155. // szEntryName [in] Name of the Hidden connectiod
  156. // ncs [in] Status of the hidden connectiod
  157. //
  158. // Returns: nothing
  159. //
  160. // Author: omiller 1 Jun 2000
  161. //
  162. // Notes:
  163. //
  164. void CCMUtil::SetEntry(const GUID & guid, const WCHAR * szEntryName, const NETCON_STATUS ncs) throw (std::bad_alloc)
  165. {
  166. CMEntryTable::iterator iter;
  167. CExceptionSafeLock esCritSec(&m_CriticalSection);
  168. iter = GetIteratorFromGuid(guid);
  169. if( iter )
  170. {
  171. iter->Set(guid,szEntryName,ncs);
  172. }
  173. else
  174. {
  175. m_Table.push_back( CMEntry(guid,szEntryName,ncs) ); // can throw
  176. }
  177. }
  178. //+---------------------------------------------------------------------------
  179. //
  180. // Function: RemoveEntry
  181. //
  182. // Purpose: Removes a hidden connectiod from the list
  183. //
  184. // Connection Manager has two stages: Dialup and VPN.
  185. // For the Dialup it creates a hidden connectoid that the
  186. // folder (netshell) does not see. However netman caches
  187. // the name, guid and status of this connectedoid. Both
  188. // the parent and child connectoid have the same name.
  189. //
  190. // Arguments:
  191. // guid [in] Guid of the Hidden connectiod
  192. //
  193. // Returns: S_OK -- Found the hidden connectoid
  194. //
  195. // Author: omiller 1 Jun 2000
  196. //
  197. // Notes:
  198. //
  199. void CCMUtil::RemoveEntry(const GUID & guid) throw()
  200. {
  201. /*
  202. CMEntryTable::iterator iter;
  203. EnterCriticalSection(&m_CriticalSection);
  204. iter = GetIteratorFromGuid(guid);
  205. if( iter )
  206. {
  207. m_Table.erase(iter);
  208. }
  209. LeaveCriticalSection(&m_CriticalSection);
  210. */
  211. }