Source code of Windows XP (NT5)
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.

290 lines
6.0 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2001.
  5. //
  6. // File: H N E T H L P . CPP
  7. //
  8. // Contents: Functions that is related to the unattended install
  9. // and upgrade of HomeNet settings
  10. //
  11. //
  12. // Author: NSun
  13. // Date: April 2001
  14. //
  15. //----------------------------------------------------------------------------
  16. #include "pch.h"
  17. #pragma hdrstop
  18. #include <atlbase.h>
  19. #include "hnetcfg.h"
  20. /*++
  21. Routine Description:
  22. Create a bridge
  23. Arguments:
  24. rgspNetConns [IN] the array with a NULL terminator. Contains the connections
  25. that needs to be bridged together
  26. ppBridge [OUT] the newly created bridge. The caller can pass a NULL in
  27. if the caller do not need this info
  28. Return Value:
  29. standard HRESULT
  30. --*/
  31. HRESULT HNetCreateBridge(
  32. IN INetConnection * rgspNetConns[],
  33. OUT IHNetBridge ** ppBridge
  34. )
  35. {
  36. if (ppBridge)
  37. {
  38. *ppBridge = NULL;
  39. }
  40. //calculate the count and ensure it's at least two
  41. for (int cnt = 0; NULL != rgspNetConns[cnt]; cnt++);
  42. if (cnt < 2)
  43. {
  44. return E_INVALIDARG;
  45. }
  46. HRESULT hr = S_OK;
  47. // Create Homenet Configuration Manager COM Instance
  48. // and obtain connection settings.
  49. CComPtr<IHNetCfgMgr> spIHNetCfgMgr;
  50. hr = CoCreateInstance(CLSID_HNetCfgMgr,
  51. NULL,
  52. CLSCTX_ALL,
  53. IID_IHNetCfgMgr,
  54. (LPVOID*)((IHNetCfgMgr**)&spIHNetCfgMgr));
  55. if (FAILED(hr))
  56. {
  57. return hr;
  58. }
  59. Assert(spIHNetCfgMgr.p);
  60. CComPtr<IHNetBridgeSettings> spIHNetBridgeSettings;
  61. hr = spIHNetCfgMgr->QueryInterface(IID_IHNetBridgeSettings,
  62. (void**)((IHNetBridgeSettings**) &spIHNetBridgeSettings));
  63. if (FAILED(hr))
  64. {
  65. return hr;
  66. }
  67. CComPtr<IHNetBridge> spHNetBridge;
  68. hr = spIHNetBridgeSettings->CreateBridge( &spHNetBridge );
  69. if (FAILED(hr))
  70. {
  71. return hr;
  72. }
  73. for (cnt = 0; NULL != rgspNetConns[cnt]; cnt++)
  74. {
  75. CComPtr<IHNetConnection> spHNetConnection;
  76. hr = spIHNetCfgMgr->GetIHNetConnectionForINetConnection(
  77. rgspNetConns[cnt],
  78. &spHNetConnection );
  79. if (FAILED(hr))
  80. {
  81. break;
  82. }
  83. CComPtr<IHNetBridgedConnection> spBridgedConn;
  84. hr = spHNetBridge->AddMember( spHNetConnection, &spBridgedConn );
  85. if (FAILED(hr))
  86. {
  87. break;
  88. }
  89. }
  90. //if failure, destroy the bridge that are just constructed
  91. if (FAILED(hr) && spHNetBridge.p)
  92. {
  93. spHNetBridge->Destroy();
  94. }
  95. if (SUCCEEDED(hr) && ppBridge)
  96. {
  97. *ppBridge = spHNetBridge;
  98. (*ppBridge)->AddRef();
  99. }
  100. return hr;
  101. }
  102. /*++
  103. Routine Description:
  104. Enable the Personal Firewall on the connections
  105. Arguments:
  106. rgspNetConns [IN] the array with a NULL terminator. Contains the connections
  107. that needs to turn firewall on
  108. Return Value:
  109. standard HRESULT
  110. --*/
  111. HRESULT HrEnablePersonalFirewall(
  112. IN INetConnection * rgspNetConns[]
  113. )
  114. {
  115. HRESULT hr = S_OK;
  116. // Create Homenet Configuration Manager COM Instance
  117. // and obtain connection settings.
  118. CComPtr<IHNetCfgMgr> spIHNetCfgMgr;
  119. hr = CoCreateInstance(CLSID_HNetCfgMgr,
  120. NULL,
  121. CLSCTX_ALL,
  122. IID_IHNetCfgMgr,
  123. (LPVOID*)((IHNetCfgMgr**)&spIHNetCfgMgr));
  124. if (FAILED(hr))
  125. {
  126. return hr;
  127. }
  128. Assert(spIHNetCfgMgr.p);
  129. HRESULT hrTemp = S_OK;
  130. CComPtr<IHNetConnection> spHNetConnection;
  131. for (int i = 0; NULL != rgspNetConns[i]; i++)
  132. {
  133. //release the ref count if we are holding one
  134. spHNetConnection = NULL;
  135. hrTemp = spIHNetCfgMgr->GetIHNetConnectionForINetConnection(
  136. rgspNetConns[i],
  137. &spHNetConnection );
  138. if (SUCCEEDED(hr))
  139. {
  140. hr = hrTemp;
  141. }
  142. if (FAILED(hrTemp))
  143. {
  144. continue;
  145. }
  146. CComPtr<IHNetFirewalledConnection> spFirewalledConn;
  147. hrTemp = spHNetConnection->Firewall( &spFirewalledConn );
  148. if (SUCCEEDED(hr))
  149. {
  150. hr = hrTemp;
  151. }
  152. }
  153. return hr;
  154. }
  155. /*++
  156. Routine Description:
  157. Enable ICS
  158. Arguments:
  159. pPublicConnection [IN] the public connection
  160. pPrivateConnection [IN] the private connection
  161. Return Value:
  162. standard HRESULT
  163. --*/
  164. HRESULT HrCreateICS(
  165. IN INetConnection * pPublicConnection,
  166. IN INetConnection * pPrivateConnection
  167. )
  168. {
  169. if (!pPublicConnection || !pPrivateConnection)
  170. {
  171. return E_INVALIDARG;
  172. }
  173. HRESULT hr = S_OK;
  174. CComPtr<IHNetCfgMgr> spIHNetCfgMgr;
  175. hr = CoCreateInstance(CLSID_HNetCfgMgr,
  176. NULL,
  177. CLSCTX_ALL,
  178. IID_IHNetCfgMgr,
  179. (LPVOID*)((IHNetCfgMgr**)&spIHNetCfgMgr));
  180. if (FAILED(hr))
  181. {
  182. return hr;
  183. }
  184. Assert(spIHNetCfgMgr.p);
  185. CComPtr<IHNetConnection> spHNetPubConn;
  186. hr = spIHNetCfgMgr->GetIHNetConnectionForINetConnection(
  187. pPublicConnection,
  188. &spHNetPubConn );
  189. if (FAILED(hr))
  190. {
  191. return hr;
  192. }
  193. CComPtr<IHNetConnection> spHNetPrivConn;
  194. hr = spIHNetCfgMgr->GetIHNetConnectionForINetConnection(
  195. pPrivateConnection,
  196. &spHNetPrivConn);
  197. if (FAILED(hr))
  198. {
  199. return hr;
  200. }
  201. CComPtr<IHNetIcsPublicConnection> spIcsPublicConn;
  202. hr = spHNetPubConn->SharePublic(&spIcsPublicConn);
  203. if (FAILED(hr))
  204. {
  205. return hr;
  206. }
  207. CComPtr<IHNetIcsPrivateConnection> spIcsPrivateConn;
  208. hr = spHNetPrivConn->SharePrivate(&spIcsPrivateConn);
  209. //roll back the changes if the operation failed
  210. if (FAILED(hr) && spIcsPublicConn.p)
  211. {
  212. spIcsPublicConn->Unshare();
  213. }
  214. return hr;
  215. }