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.

388 lines
10 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1999.
  5. //
  6. // File: N E T C F G . H
  7. //
  8. // Contents: Defines the overall datatype for representing the network
  9. // bindings engine. This datatype, CNetConfig, is a
  10. // collection of components and their binding relationships
  11. // to each other.
  12. //
  13. // Notes:
  14. //
  15. // Author: shaunco 15 Jan 1999
  16. //
  17. //----------------------------------------------------------------------------
  18. #pragma once
  19. #include "complist.h"
  20. #include "diagctx.h"
  21. #include "install.h"
  22. #include "notify.h"
  23. #include "stable.h"
  24. #include "util.h"
  25. // Flags for HrGetBindingsXXX.
  26. //
  27. enum GB_FLAGS
  28. {
  29. GBF_DEFAULT = 0x00000000,
  30. GBF_ADD_TO_BINDSET = 0x00000001,
  31. GBF_PRUNE_DISABLED_BINDINGS = 0x00000002,
  32. GBF_ONLY_WHICH_CONTAIN_COMPONENT = 0x00000004,
  33. };
  34. // Flags for FIsBindPathDisabled.
  35. //
  36. enum IBD_FLAGS
  37. {
  38. IBD_EXACT_MATCH_ONLY = 0x00000001,
  39. IBD_MATCH_SUBPATHS_TOO = 0x00000002,
  40. };
  41. class CNetConfigCore
  42. {
  43. public:
  44. CComponentList Components;
  45. CStackTable StackTable;
  46. CBindingSet DisabledBindings;
  47. #if DBG
  48. private:
  49. BOOL m_fRemovedAComponent;
  50. #endif
  51. public:
  52. VOID Clear ();
  53. VOID Free ();
  54. BOOL FIsEmpty () const;
  55. BOOL
  56. FContainsFilterComponent () const;
  57. BOOL
  58. FIsBindPathDisabled (
  59. IN const CBindPath* pBindPath,
  60. IN DWORD dwFlags /* IBD_FLAGS */) const;
  61. BOOL
  62. FIsLength2BindPathDisabled (
  63. IN const CComponent* pUpper,
  64. IN const CComponent* pLower) const;
  65. VOID
  66. EnableBindPath (
  67. IN const CBindPath* pBindPath)
  68. {
  69. TraceFileFunc(ttidNetCfgBind);
  70. DisabledBindings.RemoveBindPath (pBindPath);
  71. DbgVerifyBindingSet (&DisabledBindings);
  72. }
  73. VOID
  74. EnsureComponentNotReferencedByOthers (
  75. IN const CComponent* pComponent);
  76. HRESULT
  77. HrDisableBindPath (
  78. IN const CBindPath* pBindPath);
  79. HRESULT
  80. HrCopyCore (
  81. IN const CNetConfigCore* pSourceCore);
  82. HRESULT
  83. HrGetBindingsInvolvingComponent (
  84. IN const CComponent* pComponent,
  85. IN DWORD dwFlags,
  86. IN OUT CBindingSet* pBindSet);
  87. HRESULT
  88. HrGetComponentBindings (
  89. IN const CComponent* pComponent,
  90. IN DWORD dwFlags /* GB_FLAGS */,
  91. OUT CBindingSet* pBindSet);
  92. HRESULT
  93. HrGetComponentUpperBindings (
  94. IN const CComponent* pComponent,
  95. IN DWORD dwFlags,
  96. OUT CBindingSet* pBindSet);
  97. HRESULT
  98. HrGetFiltersEnabledForAdapter (
  99. IN const CComponent* pAdapter,
  100. OUT CComponentList* pFilters);
  101. HRESULT
  102. HrAddComponentToCore (
  103. IN CComponent* pComponent,
  104. IN DWORD dwFlags /* INS_FLAGS */);
  105. VOID
  106. RemoveComponentFromCore (
  107. IN const CComponent* pComponent);
  108. #if DBG
  109. VOID DbgVerifyData () const;
  110. VOID DbgVerifyExternalDataLoadedForAllComponents () const;
  111. VOID DbgVerifyBindingSet (
  112. const CBindingSet* pBindSet) const;
  113. #else
  114. VOID DbgVerifyData () const {}
  115. VOID DbgVerifyExternalDataLoadedForAllComponents () const {}
  116. VOID DbgVerifyBindingSet (
  117. const CBindingSet* /*pBindSet*/) const {}
  118. #endif
  119. };
  120. class CNetConfig;
  121. class CFilterDevices;
  122. class CRegistryBindingsContext
  123. {
  124. private:
  125. CNetConfig* m_pNetConfig;
  126. CBindingSet m_BindSet;
  127. CDynamicBuffer m_BindValue;
  128. CDynamicBuffer m_ExportValue;
  129. CDynamicBuffer m_RouteValue;
  130. public:
  131. HRESULT
  132. HrPrepare (
  133. IN CNetConfig* pNetConfig);
  134. HRESULT
  135. HrGetAdapterUpperBindValue (
  136. IN const CComponent* pAdapter);
  137. HRESULT
  138. HrWriteBindingsForComponent (
  139. IN const CComponent* pComponent);
  140. HRESULT
  141. HrWriteBindingsForFilterDevices (
  142. IN CFilterDevices* pFilterDevices);
  143. HRESULT
  144. HrDeleteBindingsForComponent (
  145. IN const CComponent* pComponent);
  146. VOID
  147. PnpBindOrUnbindBindPaths (
  148. IN UINT unOperation,
  149. IN const CBindingSet* pBindSet,
  150. OUT BOOL* pfRebootNeeded);
  151. };
  152. enum IOR_ACTION
  153. {
  154. IOR_INSTALL,
  155. IOR_REMOVE,
  156. };
  157. enum EBO_FLAG
  158. {
  159. EBO_COMMIT_NOW = 1,
  160. EBO_DEFER_COMMIT_UNTIL_APPLY,
  161. };
  162. class CModifyContext
  163. {
  164. public:
  165. // This is the core data we started with before the modification began.
  166. // In the event the modification fails, we will revert to this data.
  167. // We also use this data when we apply the changes. We compare what
  168. // we started with to what we have as a result of the modification and
  169. // the differences represent the things we need to change.
  170. //
  171. CNetConfigCore m_CoreStartedWith;
  172. // These bindings are the added bindpaths (due to adding components)
  173. // These represent bindings that have been queried and notified to
  174. // notify objects.
  175. //
  176. CBindingSet m_AddedBindPaths;
  177. // These bindings are the deleted bindpaths (due to removing components)
  178. // These represent bindings that have been notified to notify objects.
  179. //
  180. CBindingSet m_DeletedBindPaths;
  181. // These components are all the components involved in m_AddedBindPaths
  182. // and m_DeletedBindPaths. As such, they are the components we need
  183. // to visit during Apply to write bindings for, delete bindings for,
  184. // or finish removal of depending on whether the components exist in
  185. // the core we started with. Components can get in this list if they
  186. // have had their bind order changed, or if they were involved in a
  187. // binding that has been enabled or disabled.
  188. //
  189. CComponentList m_DirtyComponents;
  190. // The purpose of the binding context is just to allow us to make one
  191. // allocation (and use it over and over) for the buffer which holds the
  192. // bind strings that get written to the registry. We make this allocation
  193. // up front when the modify context is prepared. Doing so minimizes the
  194. // risk of getting half-way through apply and then finding out we are so
  195. // low on memory that we cannot allocate a buffer to write the registry
  196. // bindings with.
  197. //
  198. CRegistryBindingsContext m_RegBindCtx;
  199. ULONG m_ulRecursionDepth;
  200. HRESULT m_hr;
  201. BOOLEAN m_fPrepared;
  202. // Set when a notify object says they need to reboot in order for changes
  203. // to take affect. Setting this will not REQUIRE us to reboot, it will
  204. // only cause NETCFG_S_REBOOT to be returned from the install or remove
  205. // operation.
  206. //
  207. BOOLEAN m_fRebootRecommended;
  208. // Set when a component that is being removed fails to stop. When it
  209. // does, its service will be marked as 'pending delete'. We cannot allow
  210. // any other config changes to happen when we are in this state because
  211. // if that service ever needs to be re-installed, we will fail.
  212. //
  213. BOOLEAN m_fRebootRequired;
  214. #if DBG
  215. // This flag indicates that we've dirtied a component outside of
  216. // ApplyChanges. We will do this when bind order changes, and when
  217. // INetCfgComponentPrivate::SetDirty or
  218. // INetCfgComponentPrivate::NotifyUpperEdgeConfigChange are called.
  219. // If this flag is TRUE, m_fDirtyComponents will not be empty upon
  220. // entering ApplyChanges. Normally, when this flag is FALSE,
  221. // m_fDirtyComponents should be empty when entering ApplyChanges.
  222. // If it were not, it would probably mean we forgot to empty it after
  223. // the last Apply or Cancel and are now risking applying changes to
  224. // components which really are not dirty.
  225. //
  226. BOOLEAN m_fComponentExplicitlyDirtied;
  227. #endif
  228. private:
  229. VOID
  230. PushRecursionDepth ();
  231. HRESULT
  232. HrPopRecursionDepth ();
  233. VOID
  234. ApplyChanges ();
  235. VOID
  236. InstallAndAddAndNotifyComponent (
  237. IN const COMPONENT_INSTALL_PARAMS& Params,
  238. OUT CComponent** ppComponent);
  239. VOID
  240. InstallConvenienceComponentsForUser (
  241. IN const CComponent* pComponent);
  242. VOID
  243. InstallOrRemoveRequiredComponents (
  244. IN CComponent* pComponent,
  245. IN IOR_ACTION Action);
  246. VOID
  247. NotifyAndRemoveComponent (
  248. IN CComponent* pComponent);
  249. HRESULT
  250. HrProcessWinsockRemove (
  251. IN const CComponent* pComponent);
  252. public:
  253. CNetConfig*
  254. PNetConfig ();
  255. HRESULT
  256. HrBeginBatchOperation ();
  257. HRESULT
  258. HrEndBatchOperation (
  259. IN EBO_FLAG Flag);
  260. HRESULT
  261. HrDirtyComponent (
  262. IN const CComponent* pComponent);
  263. HRESULT
  264. HrDirtyComponentAndComponentsAbove (
  265. IN const CComponent* pComponent);
  266. HRESULT
  267. HrApplyIfOkOrCancel (
  268. IN BOOL fApply);
  269. HRESULT
  270. HrPrepare ();
  271. HRESULT
  272. HrEnableOrDisableBindPath (
  273. IN DWORD dwChangeFlag,
  274. IN CBindPath* pBindPath,
  275. IN INetCfgBindingPath* pIPath OPTIONAL);
  276. HRESULT
  277. HrInstallNewOrReferenceExistingComponent (
  278. IN const COMPONENT_INSTALL_PARAMS& Params,
  279. OUT CComponent** ppComponent);
  280. HRESULT
  281. HrRemoveComponentIfNotReferenced (
  282. IN CComponent* pComponent,
  283. IN OBO_TOKEN* pOboToken OPTIONAL,
  284. OUT PWSTR* ppmszwRefs OPTIONAL);
  285. HRESULT
  286. HrUpdateComponent (
  287. IN CComponent* pComponent,
  288. IN DWORD dwSetupFlags,
  289. IN DWORD dwUpgradeFromBuildNo);
  290. };
  291. class CNetConfig
  292. {
  293. public:
  294. // This is the core data managed by this object. The reason it
  295. // is encapsulated by NETCFG_CORE is so that we can save it away before
  296. // we being any modify operation. (We save it into
  297. // CModifyContext.m_StartedWith.) In the event of a failure to modify
  298. // we restore the core data from what we started with.
  299. //
  300. CNetConfigCore Core;
  301. // The interface to all notify objects representing the components.
  302. //
  303. CGlobalNotifyInterface Notify;
  304. CModifyContext ModifyCtx;
  305. public:
  306. CNetConfig ()
  307. {
  308. TraceFileFunc(ttidNetcfgBase);
  309. ZeroMemory (this, sizeof(*this));
  310. }
  311. ~CNetConfig ();
  312. HRESULT
  313. HrEnsureExternalDataLoadedForAllComponents ();
  314. static HRESULT
  315. HrCreateInstance (
  316. IN class CImplINetCfg* pINetCfg,
  317. OUT CNetConfig** ppNetConfig);
  318. };