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.

342 lines
8.9 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1999.
  5. //
  6. // File: I C L A S S . C P P
  7. //
  8. // Contents: Implements the INetCfgClass and INetCfgClassSetup COM
  9. // interfaces on the NetCfgClass sub-level COM object.
  10. //
  11. // Notes:
  12. //
  13. // Author: shaunco 15 Jan 1999
  14. //
  15. //----------------------------------------------------------------------------
  16. #include <pch.h>
  17. #pragma hdrstop
  18. #include "iclass.h"
  19. #include "icomp.h"
  20. #include "ienum.h"
  21. #include "install.h"
  22. #include "netcfg.h"
  23. #include "obotoken.h"
  24. // static
  25. HRESULT
  26. CImplINetCfgClass::HrCreateInstance (
  27. IN CImplINetCfg* pINetCfg,
  28. IN NETCLASS Class,
  29. OUT INetCfgClass** ppIClass)
  30. {
  31. HRESULT hr = E_OUTOFMEMORY;
  32. CImplINetCfgClass* pObj;
  33. pObj = new CComObject <CImplINetCfgClass>;
  34. if (pObj)
  35. {
  36. // Initialize our members.
  37. //
  38. pObj->m_Class = Class;
  39. // Do the standard CComCreator::CreateInstance stuff.
  40. //
  41. pObj->SetVoid (NULL);
  42. pObj->InternalFinalConstructAddRef ();
  43. hr = pObj->FinalConstruct ();
  44. pObj->InternalFinalConstructRelease ();
  45. if (S_OK == hr)
  46. {
  47. hr = pObj->GetUnknown()->QueryInterface (IID_INetCfgClass,
  48. (VOID**)ppIClass);
  49. // The last thing we do is addref any interfaces we hold.
  50. // We only do this if we are returning success.
  51. //
  52. if (S_OK == hr)
  53. {
  54. pObj->HoldINetCfg (pINetCfg);
  55. }
  56. }
  57. if (S_OK != hr)
  58. {
  59. delete pObj;
  60. }
  61. }
  62. TraceHr (ttidError, FAL, hr, FALSE, "CImplINetCfgClass::HrCreateInstance");
  63. return hr;
  64. }
  65. //+---------------------------------------------------------------------------
  66. // INetCfgClass -
  67. //
  68. STDMETHODIMP
  69. CImplINetCfgClass::FindComponent (
  70. IN PCWSTR pszInfId,
  71. OUT INetCfgComponent** ppComp OPTIONAL)
  72. {
  73. HRESULT hr;
  74. // Validate parameters.
  75. //
  76. if (FBadInPtr(pszInfId) || FBadOutPtrOptional(ppComp))
  77. {
  78. hr = E_POINTER;
  79. }
  80. else
  81. {
  82. if (ppComp)
  83. {
  84. *ppComp = NULL;
  85. }
  86. hr = HrLockAndTestForValidInterface (IF_DEFAULT);
  87. if (S_OK == hr)
  88. {
  89. CComponent* pComponent;
  90. pComponent = m_pINetCfg->m_pNetConfig->Core.Components.
  91. PFindComponentByInfId (pszInfId, NULL);
  92. // Don't return interfaces to components that have had
  93. // problem loading.
  94. //
  95. if (pComponent &&
  96. pComponent->Ext.FLoadedOkayIfLoadedAtAll() &&
  97. (m_Class == pComponent->Class()))
  98. {
  99. hr = S_OK;
  100. if (ppComp)
  101. {
  102. hr = pComponent->HrGetINetCfgComponentInterface (
  103. m_pINetCfg, ppComp);
  104. }
  105. }
  106. else
  107. {
  108. hr = S_FALSE;
  109. }
  110. Unlock();
  111. }
  112. }
  113. TraceHr (ttidError, FAL, hr, (S_FALSE == hr),
  114. "CImplINetCfgClass::FindComponent");
  115. return hr;
  116. }
  117. STDMETHODIMP
  118. CImplINetCfgClass::EnumComponents (
  119. OUT IEnumNetCfgComponent** ppIEnum)
  120. {
  121. HRESULT hr;
  122. // Validate parameters.
  123. //
  124. if (FBadOutPtr(ppIEnum))
  125. {
  126. hr = E_POINTER;
  127. }
  128. else
  129. {
  130. *ppIEnum = NULL;
  131. hr = HrLockAndTestForValidInterface (IF_DEFAULT);
  132. if (S_OK == hr)
  133. {
  134. hr = CImplIEnumNetCfgComponent::HrCreateInstance (
  135. m_pINetCfg,
  136. m_Class,
  137. ppIEnum);
  138. Unlock();
  139. }
  140. }
  141. TraceHr (ttidError, FAL, hr, FALSE, "CImplINetCfgClass::EnumComponents");
  142. return hr;
  143. }
  144. //+---------------------------------------------------------------------------
  145. // INetCfgClassSetup -
  146. //
  147. STDMETHODIMP
  148. CImplINetCfgClass::SelectAndInstall (
  149. IN HWND hwndParent,
  150. IN OBO_TOKEN* pOboToken OPTIONAL,
  151. OUT INetCfgComponent** ppIComp OPTIONAL)
  152. {
  153. HRESULT hr = m_pINetCfg->SelectWithFilterAndInstall(
  154. hwndParent,
  155. MAP_NETCLASS_TO_GUID[m_Class],
  156. pOboToken,
  157. NULL,
  158. ppIComp);
  159. TraceHr (ttidError, FAL, hr,
  160. (HRESULT_FROM_WIN32(ERROR_CANCELLED) == hr) ||
  161. (NETCFG_S_REBOOT == hr),
  162. "CImplINetCfgClass::SelectAndInstall");
  163. return hr;
  164. }
  165. STDMETHODIMP
  166. CImplINetCfgClass::Install (
  167. IN PCWSTR pszwInfId,
  168. IN OBO_TOKEN* pOboToken OPTIONAL,
  169. IN DWORD dwSetupFlags OPTIONAL,
  170. IN DWORD dwUpgradeFromBuildNo OPTIONAL,
  171. IN PCWSTR pszAnswerFile OPTIONAL,
  172. IN PCWSTR pszAnswerSection OPTIONAL,
  173. OUT INetCfgComponent** ppIComp OPTIONAL)
  174. {
  175. HRESULT hr;
  176. // Validate parameters.
  177. //
  178. if (FBadInPtr (pszwInfId) ||
  179. !FOboTokenValidForClass(pOboToken, m_Class) ||
  180. FBadInPtrOptional (pszAnswerFile) ||
  181. FBadInPtrOptional (pszAnswerSection) ||
  182. FBadOutPtrOptional(ppIComp))
  183. {
  184. hr = E_POINTER;
  185. }
  186. // Must specifiy a non-empty INF id, and must either not specifiy,
  187. // or completely specifiy the answerfile and the section.
  188. //
  189. else if (!(*pszwInfId) ||
  190. ((!!pszAnswerFile) ^ (!!pszAnswerSection)))
  191. {
  192. hr = E_INVALIDARG;
  193. }
  194. else if (S_OK == (hr = HrProbeOboToken(pOboToken)))
  195. {
  196. if (ppIComp)
  197. {
  198. *ppIComp = NULL;
  199. }
  200. hr = HrLockAndTestForValidInterface (
  201. IF_NEED_WRITE_LOCK | IF_REFUSE_REENTRANCY |
  202. IF_ALLOW_INSTALL_OR_REMOVE);
  203. if (S_OK == hr)
  204. {
  205. Assert (m_pINetCfg->m_pNetConfig->ModifyCtx.m_fPrepared);
  206. NETWORK_INSTALL_PARAMS nip;
  207. COMPONENT_INSTALL_PARAMS Params;
  208. CComponent* pComponent;
  209. // Pack the network install parameters and call the common
  210. // function.
  211. //
  212. //$REVIEW: Just make this method take NETWORK_INSTALL_PARAMS?.
  213. //
  214. nip.dwSetupFlags = dwSetupFlags;
  215. nip.dwUpgradeFromBuildNo = dwUpgradeFromBuildNo;
  216. nip.pszAnswerFile = pszAnswerFile;
  217. nip.pszAnswerSection = pszAnswerSection;
  218. // Setup the component install parameters.
  219. //
  220. ZeroMemory (&Params, sizeof(Params));
  221. Params.Class = m_Class;
  222. Params.pszInfId = pszwInfId;
  223. Params.pOboToken = pOboToken;
  224. Params.pnip = &nip;
  225. hr = m_pINetCfg->m_pNetConfig->ModifyCtx.
  226. HrInstallNewOrReferenceExistingComponent (
  227. Params,
  228. &pComponent);
  229. // The above may return NETCFG_S_REBOOT so use SUCCEEDED instead
  230. // of checking for S_OK only.
  231. //
  232. if (SUCCEEDED(hr) && ppIComp)
  233. {
  234. pComponent->HrGetINetCfgComponentInterface (
  235. m_pINetCfg,
  236. ppIComp);
  237. }
  238. Unlock();
  239. }
  240. }
  241. TraceHr (ttidError, FAL, hr, (NETCFG_S_REBOOT == hr),
  242. "CImplINetCfgClass::Install");
  243. return hr;
  244. }
  245. STDMETHODIMP
  246. CImplINetCfgClass::DeInstall (
  247. IN INetCfgComponent* pIComp,
  248. IN OBO_TOKEN* pOboToken OPTIONAL,
  249. OUT PWSTR* ppmszwRefs OPTIONAL)
  250. {
  251. HRESULT hr;
  252. // Validate parameters.
  253. //
  254. if (FBadInPtr (pIComp) ||
  255. !FOboTokenValidForClass(pOboToken, m_Class) ||
  256. FBadOutPtrOptional(ppmszwRefs))
  257. {
  258. hr = E_POINTER;
  259. }
  260. else if (S_OK == (hr = HrProbeOboToken(pOboToken)))
  261. {
  262. if (ppmszwRefs)
  263. {
  264. *ppmszwRefs = NULL;
  265. }
  266. hr = HrLockAndTestForValidInterface (
  267. IF_NEED_WRITE_LOCK | IF_REFUSE_REENTRANCY |
  268. IF_ALLOW_INSTALL_OR_REMOVE);
  269. if (S_OK == hr)
  270. {
  271. Assert (m_pINetCfg->m_pNetConfig->ModifyCtx.m_fPrepared);
  272. CImplINetCfgComponent* pICompToRemove;
  273. pICompToRemove = (CImplINetCfgComponent*)pIComp;
  274. hr = pICompToRemove->HrIsValidInterface (IF_NEED_COMPONENT_DATA);
  275. if (S_OK == hr)
  276. {
  277. // We don't allow removals of physical adapters via INetCfg.
  278. //
  279. if (!FIsPhysicalAdapter (m_Class,
  280. pICompToRemove->m_pComponent->m_dwCharacter))
  281. {
  282. hr = m_pINetCfg->m_pNetConfig->ModifyCtx.
  283. HrRemoveComponentIfNotReferenced (
  284. pICompToRemove->m_pComponent,
  285. pOboToken,
  286. ppmszwRefs);
  287. }
  288. else
  289. {
  290. hr = SPAPI_E_INVALID_CLASS;
  291. }
  292. }
  293. Unlock();
  294. }
  295. }
  296. TraceHr (ttidError, FAL, hr,
  297. (NETCFG_S_REBOOT == hr) || (NETCFG_S_STILL_REFERENCED == hr),
  298. "CImplINetCfgClass::DeInstall");
  299. return hr;
  300. }