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.

264 lines
7.3 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: E N U M S A. C P P
  7. //
  8. // Contents: Implementation of Shared Access connection enumerator object
  9. //
  10. // Notes:
  11. //
  12. // Author: kenwic 8 Aug 2000
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include "enumsa.h"
  18. #include "saconob.h"
  19. LONG g_CountSharedAccessConnectionEnumerators;
  20. //+---------------------------------------------------------------------------
  21. //
  22. // Member: CSharedAccessConnectionManagerEnumConnection::~CSharedAccessConnectionManagerEnumConnection
  23. //
  24. // Purpose: Called when the enumeration object is released for the last
  25. // time.
  26. //
  27. // Arguments:
  28. // (none)
  29. //
  30. // Returns: Nothing
  31. //
  32. // Author: kenwic 8 Aug 2000
  33. //
  34. // Notes:
  35. //
  36. CSharedAccessConnectionManagerEnumConnection::~CSharedAccessConnectionManagerEnumConnection()
  37. {
  38. InterlockedDecrement(&g_CountSharedAccessConnectionEnumerators);
  39. }
  40. //+---------------------------------------------------------------------------
  41. // IEnumNetConnection
  42. //
  43. //+---------------------------------------------------------------------------
  44. //
  45. // Member: CSharedAccessConnectionManagerEnumConnection::Next
  46. //
  47. // Purpose: Retrieves the next celt SharedAccess connection objects
  48. //
  49. // Arguments:
  50. // celt [in] Number to retrieve
  51. // rgelt [out] Array of INetConnection objects retrieved
  52. // pceltFetched [out] Returns Number in array
  53. //
  54. // Returns: S_OK if succeeded, OLE or Win32 error otherwise
  55. //
  56. // Author: kenwic 8 Aug 2000
  57. //
  58. // Notes:
  59. //
  60. STDMETHODIMP CSharedAccessConnectionManagerEnumConnection::Next(ULONG celt,
  61. INetConnection **rgelt,
  62. ULONG *pceltFetched)
  63. {
  64. HRESULT hr = S_FALSE;
  65. // Validate parameters.
  66. //
  67. if (!rgelt || (!pceltFetched && (1 != celt)))
  68. {
  69. hr = E_POINTER;
  70. goto done;
  71. }
  72. if (pceltFetched)
  73. {
  74. // Initialize output parameters.
  75. //
  76. *pceltFetched = 0;
  77. ZeroMemory(rgelt, sizeof (*rgelt) * celt);
  78. if(FALSE == m_bEnumerated)
  79. {
  80. m_bEnumerated = TRUE;
  81. CComObject<CSharedAccessConnection>* pConnection;
  82. hr = CComObject<CSharedAccessConnection>::CreateInstance(&pConnection);
  83. if(SUCCEEDED(hr))
  84. {
  85. pConnection->AddRef();
  86. hr = pConnection->QueryInterface(IID_INetConnection, reinterpret_cast<void **>(rgelt));
  87. if(SUCCEEDED(hr))
  88. {
  89. // We should only get here if there is a shared access connection and this would essentially
  90. // mean that homenet is running
  91. CComPtr<INetConnectionUiUtilities> pNetConnUiUtil; // check group policy
  92. hr = CoCreateInstance(CLSID_NetConnectionUiUtilities, NULL, CLSCTX_INPROC,
  93. IID_INetConnectionUiUtilities, reinterpret_cast<void **>(&pNetConnUiUtil));
  94. if (SUCCEEDED(hr))
  95. {
  96. if (pNetConnUiUtil->UserHasPermission(NCPERM_ICSClientApp))
  97. {
  98. *pceltFetched = 1;
  99. }
  100. else
  101. {
  102. hr = S_FALSE;
  103. }
  104. }
  105. if (FAILED(hr) || (S_FALSE == hr))
  106. {
  107. (*rgelt)->Release();
  108. *rgelt = NULL;
  109. }
  110. }
  111. pConnection->Release();
  112. }
  113. else
  114. {
  115. hr = S_FALSE;
  116. }
  117. if(SUCCEEDED(hr))
  118. {
  119. if(1 != celt)
  120. {
  121. hr = S_FALSE;
  122. }
  123. }
  124. }
  125. }
  126. done:
  127. Assert (FImplies (S_OK == hr, (*pceltFetched == celt)));
  128. TraceError("CSharedAccessConnectionManagerEnumConnection::Next",
  129. (hr == S_FALSE || hr == HRESULT_FROM_WIN32(ERROR_DEVICE_NOT_CONNECTED)) ? S_OK : hr);
  130. return hr;
  131. }
  132. //+---------------------------------------------------------------------------
  133. //
  134. // Member: CSharedAccessConnectionManagerEnumConnection::Skip
  135. //
  136. // Purpose: Skips over celt number of connections
  137. //
  138. // Arguments:
  139. // celt [in] Number of connections to skip
  140. //
  141. // Returns: S_OK if successful, otherwise Win32 error
  142. //
  143. // Author: kenwic 8 Aug 2000
  144. //
  145. // Notes:
  146. //
  147. STDMETHODIMP CSharedAccessConnectionManagerEnumConnection::Skip(ULONG celt)
  148. {
  149. HRESULT hr = S_OK;
  150. if(0 != celt)
  151. {
  152. m_bEnumerated = TRUE;
  153. }
  154. TraceError("CSharedAccessConnectionManagerEnumConnection::Skip",
  155. (hr == S_FALSE) ? S_OK : hr);
  156. return hr;
  157. }
  158. //+---------------------------------------------------------------------------
  159. //
  160. // Member: CSharedAccessConnectionManagerEnumConnection::Reset
  161. //
  162. // Purpose: Resets the enumerator to the beginning
  163. //
  164. // Arguments:
  165. // (none)
  166. //
  167. // Returns: S_OK
  168. //
  169. // Author: kenwic 8 Aug 2000
  170. //
  171. // Notes:
  172. //
  173. STDMETHODIMP CSharedAccessConnectionManagerEnumConnection::Reset()
  174. {
  175. HRESULT hr = S_OK;
  176. m_bEnumerated = FALSE;
  177. TraceError("CSharedAccessConnectionManagerEnumConnection::Reset", hr);
  178. return hr;
  179. }
  180. //+---------------------------------------------------------------------------
  181. //
  182. // Member: CSharedAccessConnectionManagerEnumConnection::Clone
  183. //
  184. // Purpose: Creates a new enumeration object pointing at the same location
  185. // as this object
  186. //
  187. // Arguments:
  188. // ppenum [out] New enumeration object
  189. //
  190. // Returns: S_OK if successful, otherwise OLE or Win32 error
  191. //
  192. // Author: kenwic 8 Aug 2000
  193. //
  194. // Notes:
  195. //
  196. STDMETHODIMP CSharedAccessConnectionManagerEnumConnection::Clone(IEnumNetConnection **ppenum)
  197. {
  198. HRESULT hr = E_OUTOFMEMORY;
  199. // Validate parameters.
  200. //
  201. if (!ppenum)
  202. {
  203. hr = E_POINTER;
  204. }
  205. else
  206. {
  207. CSharedAccessConnectionManagerEnumConnection * pObj;
  208. // Initialize output parameter.
  209. //
  210. *ppenum = NULL;
  211. pObj = new CComObject <CSharedAccessConnectionManagerEnumConnection>;
  212. if (pObj)
  213. {
  214. hr = S_OK;
  215. CExceptionSafeComObjectLock EsLock (this);
  216. // Copy our internal state.
  217. //
  218. pObj->m_bEnumerated = m_bEnumerated;
  219. // Return the object with a ref count of 1 on this
  220. // interface.
  221. pObj->m_dwRef = 1;
  222. *ppenum = pObj;
  223. }
  224. }
  225. TraceError ("CSharedAccessConnectionManagerEnumConnection::Clone", hr);
  226. return hr;
  227. }
  228. HRESULT CSharedAccessConnectionManagerEnumConnection::FinalRelease(void)
  229. {
  230. HRESULT hr = S_OK;
  231. return hr;
  232. }