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.

406 lines
14 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: T C P I P O B J . H
  7. //
  8. // Contents: Declaration of CTcpipcfg and helper functions.
  9. //
  10. // Notes:
  11. //
  12. //
  13. //----------------------------------------------------------------------------
  14. #pragma once
  15. #include <ncxbase.h>
  16. #include <nceh.h>
  17. #include <ncres.h>
  18. #include <notifval.h>
  19. #include "resource.h"
  20. #include "tcpip.h"
  21. #include "netconp.h"
  22. extern "C"
  23. {
  24. #include "dhcpcapi.h"
  25. };
  26. /////////////////////////////////////////////////////////////////////////////
  27. // Data types & Constants
  28. struct REG_BACKUP_INFO
  29. {
  30. DWORD dwOptionId;
  31. DWORD dwClassLen;
  32. DWORD dwDataLen;
  33. DWORD dwIsVendor;
  34. DWORD dwExpiryTime;
  35. DWORD dwData[1];
  36. };
  37. // when building the blob to be stored into the registry, the memory buffer
  38. // that holds it is enlarged dynamically with chunks of the size below
  39. // (for now, there are only 5 options of at most 2 dwords each - so prepare
  40. // the chunk such that only one allocation is needed)
  41. #define BUFFER_ENLARGEMENT_CHUNK 5*(sizeof(REG_BACKUP_INFO) + sizeof(DWORD))
  42. // Max number of property sheet pages on tcpip's property sheet
  43. static const INT c_cMaxTcpipPages = 6;
  44. extern HICON g_hiconUpArrow;
  45. extern HICON g_hiconDownArrow;
  46. /////////////////////////////////////////////////////////////////////////////
  47. // tcpipcfg
  48. class ATL_NO_VTABLE CTcpipcfg :
  49. public CComObjectRoot,
  50. public CComCoClass<CTcpipcfg, &CLSID_CTcpipcfg>,
  51. public INetCfgComponentControl,
  52. public INetCfgComponentSetup,
  53. public INetCfgComponentPropertyUi,
  54. public INetCfgComponentNotifyBinding,
  55. public INetCfgComponentUpperEdge,
  56. public INetRasConnectionIpUiInfo,
  57. public ITcpipProperties,
  58. public INetCfgComponentSysPrep
  59. {
  60. public:
  61. CTcpipcfg();
  62. ~CTcpipcfg() { FinalFree(); }
  63. BEGIN_COM_MAP(CTcpipcfg)
  64. COM_INTERFACE_ENTRY(INetCfgComponentControl)
  65. COM_INTERFACE_ENTRY(INetCfgComponentSetup)
  66. COM_INTERFACE_ENTRY(INetCfgComponentPropertyUi)
  67. COM_INTERFACE_ENTRY(INetCfgComponentNotifyBinding)
  68. COM_INTERFACE_ENTRY(INetCfgComponentUpperEdge)
  69. COM_INTERFACE_ENTRY(INetRasConnectionIpUiInfo)
  70. COM_INTERFACE_ENTRY(ITcpipProperties)
  71. COM_INTERFACE_ENTRY(INetCfgComponentSysPrep)
  72. END_COM_MAP()
  73. // DECLARE_NOT_AGGREGATABLE(CTcpipcfg)
  74. // Remove the comment from the line above if you don't want your object to
  75. // support aggregation. The default is to support it
  76. DECLARE_REGISTRY_RESOURCEID(IDR_REG_TCPIPCFG)
  77. // INetCfgComponentControl
  78. STDMETHOD (Initialize) (
  79. IN INetCfgComponent* pIComp,
  80. IN INetCfg* pINetCfg,
  81. IN BOOL fInstalling);
  82. STDMETHOD (ApplyRegistryChanges) ();
  83. STDMETHOD (ApplyPnpChanges) (
  84. IN INetCfgPnpReconfigCallback* pICallback);
  85. STDMETHOD (CancelChanges) ();
  86. STDMETHOD (Validate) ();
  87. // INetCfgComponentSetup
  88. STDMETHOD (Install) (DWORD dwSetupFlags);
  89. STDMETHOD (Upgrade) (DWORD dwSetupFlags,
  90. DWORD dwUpgradeFomBuildNo );
  91. STDMETHOD (ReadAnswerFile) (PCWSTR pszAnswerFile,
  92. PCWSTR pszAnswerSection);
  93. STDMETHOD (Removing)();
  94. // INetCfgProperties
  95. STDMETHOD (QueryPropertyUi) (
  96. IN IUnknown* pUnk) { return S_OK; }
  97. STDMETHOD (SetContext) (
  98. IN IUnknown* pUnk);
  99. STDMETHOD (MergePropPages) (
  100. IN OUT DWORD* pdwDefPages,
  101. OUT LPBYTE* pahpspPrivate,
  102. OUT UINT* pcPrivate,
  103. IN HWND hwndParent,
  104. OUT PCWSTR* pszStartPage);
  105. STDMETHOD (ValidateProperties) (
  106. HWND hwndSheet);
  107. STDMETHOD (CancelProperties) ();
  108. STDMETHOD (ApplyProperties) ();
  109. // INetCfgNotifyBinding
  110. STDMETHOD (QueryBindingPath) (DWORD dwChangeFlag, INetCfgBindingPath* pncbp);
  111. STDMETHOD (NotifyBindingPath) (DWORD dwChangeFlag, INetCfgBindingPath* pncbp);
  112. // INetCfgComponentUpperEdge
  113. STDMETHOD (GetInterfaceIdsForAdapter) (
  114. INetCfgComponent* pAdapter,
  115. DWORD* pdwNumInterfaces,
  116. GUID** ppguidInterfaceIds);
  117. STDMETHOD (AddInterfacesToAdapter) (
  118. INetCfgComponent* pAdapter,
  119. DWORD dwNumInterfaces);
  120. STDMETHOD (RemoveInterfacesFromAdapter) (
  121. INetCfgComponent* pAdapter,
  122. DWORD dwNumInterfaces,
  123. const GUID* pguidInterfaceIds);
  124. // INetRasConnectionIpUiInfo
  125. STDMETHOD (GetUiInfo) (RASCON_IPUI* pInfo);
  126. // ITcpipProperties
  127. STDMETHOD (GetIpInfoForAdapter) (const GUID* pguidAdapter,
  128. REMOTE_IPINFO** ppInfo);
  129. STDMETHOD (SetIpInfoForAdapter) (const GUID* pguidAdapter,
  130. REMOTE_IPINFO* pInfo);
  131. // INetCfgComponentSysPrep
  132. STDMETHOD (SaveAdapterParameters) (
  133. INetCfgSysPrep* pncsp,
  134. LPCWSTR pszwAnswerSections,
  135. GUID* pAdapterInstanceGuid);
  136. STDMETHOD (RestoreAdapterParameters) (
  137. LPCWSTR pszwAnswerFile,
  138. LPCWSTR pszwAnswerSection,
  139. GUID* pAdapterInstanceGuid);
  140. public:
  141. GLOBAL_INFO m_glbSecondMemoryGlobalInfo;
  142. // Place to keep pointer to INetCfg from Initialize
  143. INetCfg * m_pnc;
  144. // Place to keep the pointer to context
  145. IUnknown * m_pUnkContext;
  146. // Access methods to second memory state
  147. const GLOBAL_INFO * GetConstGlobalInfo() { return &m_glbSecondMemoryGlobalInfo; };
  148. GLOBAL_INFO * GetGlobalInfo() { return &m_glbSecondMemoryGlobalInfo; };
  149. const VCARD * GetConstAdapterInfoVector() { return &m_vcardAdapterInfo; };
  150. void SetReconfig() { m_fReconfig = TRUE; };
  151. void SetSecondMemoryLmhostsFileReset() { m_fSecondMemoryLmhostsFileReset = TRUE; };
  152. BOOL FIsSecondMemoryLmhostsFileReset() { return m_fSecondMemoryLmhostsFileReset; }
  153. //IPSec is removed from connection UI
  154. // void SetSecondMemoryIpsecPolicySet() { m_fSecondMemoryIpsecPolicySet = TRUE; };
  155. void SetSecondMemoryModified() { m_fSecondMemoryModified = TRUE; };
  156. private:
  157. GLOBAL_INFO m_glbGlobalInfo;
  158. VCARD m_vcardAdapterInfo;
  159. ADAPTER_INFO* m_pSecondMemoryAdapterInfo;
  160. VSTR m_vstrBindOrder;
  161. class CTcpAddrPage* m_ipaddr;
  162. INetCfgComponent* m_pnccTcpip;
  163. INetCfgComponentPrivate* m_pTcpipPrivate;
  164. INetCfgComponent* m_pnccWins;
  165. tstring m_strDnsServerList;
  166. tstring m_strUpgradeGlobalDnsDomain;
  167. // Connection type
  168. ConnectionType m_ConnType;
  169. GUID m_guidCurrentConnection;
  170. BOOL m_fSaveRegistry : 1;
  171. BOOL m_fRemoving : 1;
  172. BOOL m_fInstalling : 1;
  173. BOOL m_fUpgradeCleanupDnsKey : 1;
  174. BOOL m_fUpgradeGlobalDnsDomain : 1;
  175. // whether reconfig notification should be sent
  176. BOOL m_fReconfig : 1; // Call SendHandlePnpEvent
  177. // Is there any bound physical card on Initialize
  178. // This is needed for Add/Remove LmHosts service
  179. // at apply time
  180. BOOL m_fHasBoundCardOnInit : 1;
  181. BOOL m_fLmhostsFileSet : 1;
  182. BOOL m_fSecondMemoryLmhostsFileReset : 1;
  183. BOOL m_fSecondMemoryModified : 1;
  184. //IPSec is removed from connection UI
  185. //BOOL m_fIpsecPolicySet : 1;
  186. //BOOL m_fSecondMemoryIpsecPolicySet : 1;
  187. // Fix 406630: Only used for RAS connection to identify whether the USER has
  188. // write access to Global settings
  189. BOOL m_fRasNotAdmin : 1;
  190. private:
  191. void FinalFree();
  192. void ExitProperties();
  193. BOOL FHasBoundCard();
  194. ADAPTER_INFO* PAdapterFromInstanceGuid (const GUID* pGuid);
  195. ADAPTER_INFO* PAdapterFromNetcfgComponent (INetCfgComponent* pncc);
  196. HRESULT HrProcessAnswerFile(PCWSTR pszAnswerFile,
  197. PCWSTR pszAnswerSection);
  198. HRESULT HrLoadGlobalParamFromAnswerFile(HINF hinf,
  199. PCWSTR pszAnswerSection);
  200. HRESULT HrLoadAdapterParameterFromAnswerFile(HINF hinf,
  201. PCWSTR mszAdapterList);
  202. // Set router related parameters at install time
  203. // HRESULT HrInitRouterParamsAtInstall();
  204. // Initialize first in memory state
  205. HRESULT HrGetNetCards();
  206. // Load adapterinfo for bound cards from first memory to second memory
  207. HRESULT HrLoadAdapterInfo();
  208. // Save adapterinfo from second memory to first memory
  209. HRESULT HrSaveAdapterInfo();
  210. // Set connection context
  211. HRESULT HrSetConnectionContext();
  212. // Allocate and deallocate property pages
  213. HRESULT HrSetupPropSheets(HPROPSHEETPAGE **pahpsp, INT *cPages);
  214. VOID CleanupPropPages(VOID);
  215. // Handle Add/Remove/Enable/Disable adapters on BindingPathNotify
  216. HRESULT HrAdapterBindNotify(INetCfgComponent *pnccNetCard,
  217. DWORD dwChangeFlag,
  218. PCWSTR szInterfaceName);
  219. HRESULT HrAddCard(INetCfgComponent * pnccNetCard,
  220. PCWSTR szNetCardTcpipBindPath,
  221. PCWSTR szInterfaceName);
  222. HRESULT HrDeleteCard(const GUID* pguid);
  223. HRESULT HrBindCard (const GUID* pguid, BOOL fInitialize = FALSE);
  224. HRESULT HrUnBindCard(const GUID* pguid, BOOL fInitialize = FALSE);
  225. // Help functions to interface methods
  226. HRESULT MarkNewlyAddedCards(const HKEY hkeyTcpipParam);
  227. HRESULT HrGetListOfAddedNdisWanCards(const HKEY hkeyTcpipParam,
  228. VSTR * const pvstrAddedNdisWanCards);
  229. HRESULT HrLoadSettings();
  230. HRESULT HrLoadTcpipRegistry(const HKEY hkeyTcpipParam);
  231. HRESULT HrLoadWinsRegistry(const HKEY hkeyWinsParam);
  232. HRESULT HrSaveSettings();
  233. HRESULT HrSaveTcpipRegistry(const HKEY hkeyTcpipParam);
  234. HRESULT HrSaveMultipleInterfaceWanRegistry(const HKEY hkeyInterfaces, ADAPTER_INFO* pAdapter);
  235. HRESULT HrSaveWinsMultipleInterfaceWanRegistry(const HKEY hkeyInterfaces, ADAPTER_INFO* pAdapter);
  236. HRESULT HrSaveWinsRegistry(const HKEY hkeyWinsParam);
  237. HRESULT HrSetMisc(const HKEY hkeyTcpipParam, const HKEY hkeyWinsParam);
  238. HRESULT HrGetDhcpOptions(OUT VSTR * const GlobalOptions,
  239. OUT VSTR * const PerAdapterOptions);
  240. HRESULT HrSaveStaticWanRegistry(HKEY hkeyInterfaceParam);
  241. HRESULT HrSaveStaticAtmRegistry(HKEY hkeyInterfaceParam);
  242. // Dhcp functions
  243. HRESULT HrNotifyDhcp();
  244. HRESULT HrCallDhcpConfig(PWSTR ServerName,
  245. PWSTR AdapterName,
  246. GUID & guidAdapter,
  247. BOOL IsNewIpAddress,
  248. DWORD IpIndex,
  249. DWORD IpAddress,
  250. DWORD SubnetMask,
  251. SERVICE_ENABLE DhcpServiceEnabled);
  252. HRESULT HrCallDhcpHandlePnPEvent(ADAPTER_INFO * pAdapterInfo,
  253. LPDHCP_PNP_CHANGE pDhcpPnpChange);
  254. HRESULT HrDhcpRefreshFallbackParams(ADAPTER_INFO * pAdapterInfo);
  255. // Call SendNdisHandlePnpEvent to notify tcpip and netbt of
  256. // parameter changes
  257. HRESULT HrReconfigAtmArp(ADAPTER_INFO* pAdapterInfo,
  258. INetCfgPnpReconfigCallback* pICallback);
  259. HRESULT HrReconfigDns(BOOL fDoReconfigWithoutCheckingParams = FALSE);
  260. HRESULT HrReconfigIp(INetCfgPnpReconfigCallback* pICallback);
  261. HRESULT HrReconfigNbt(INetCfgPnpReconfigCallback* pICallback);
  262. HRESULT HrReconfigWanarp(ADAPTER_INFO* pAdapterInfo,
  263. INetCfgPnpReconfigCallback* pICallback);
  264. //IPSec is removed from connection UI
  265. // HRESULT HrSetActiveIpsecPolicy();
  266. //Some tcpip params are duplicated to the old Nt4 location to solve compatibility issues.
  267. HRESULT HrDuplicateToNT4Location(HKEY hkeyInterface, ADAPTER_INFO * pAdapter);
  268. //We need to clean it up when removing tcpip
  269. HRESULT HrRemoveNt4DuplicateRegistry();
  270. // Reinitialize internal state if Apply or Cancel is called
  271. void ReInitializeInternalState();
  272. // Upgrade registry in post pnp checkin cases
  273. HRESULT HrUpgradePostPnpRegKeyChange();
  274. // Add a new RAS fake GUID if the one set in context is not yet added.
  275. HRESULT UpdateRasAdapterInfo(
  276. const RASCON_IPUI& RasInfo);
  277. HRESULT HrLoadBindingOrder(VSTR *pvstrBindOrder);
  278. BOOL IsBindOrderChanged();
  279. HRESULT HrCleanUpPerformRouterDiscoveryFromRegistry();
  280. // Loads Fallback configuration from registry
  281. HRESULT HrLoadBackupTcpSettings(HKEY hkeyInterfaceParam, ADAPTER_INFO * pAdapter);
  282. // Loads one option from the registry blob into the BACKUP_CFG_INFO structure
  283. HRESULT HrLoadBackupOption(REG_BACKUP_INFO *pOption, BACKUP_CFG_INFO *pBackupInfo);
  284. // Saves Fallback configuration to registry
  285. HRESULT HrSaveBackupTcpSettings(HKEY hkeyInterfaceParam, ADAPTER_INFO * pAdapter);
  286. // Appends one option to the blob to be written into the registry
  287. HRESULT HrSaveBackupDwordOption (
  288. DWORD Option,
  289. DWORD OptionData[],
  290. DWORD OptionDataSz,
  291. LPBYTE *ppBuffer,
  292. LPDWORD pdwBlobSz,
  293. LPDWORD pdwBufferSz);
  294. HRESULT HrDeleteBackupSettingsInDhcp(LPCWSTR wszAdapterName);
  295. HRESULT HrOpenTcpipInterfaceKey(
  296. const GUID & guidInterface,
  297. HKEY * phKey,
  298. REGSAM sam);
  299. HRESULT HrOpenNetBtInterfaceKey(
  300. const GUID & guidInterface,
  301. HKEY * phKey,
  302. REGSAM sam);
  303. HRESULT HrSetSecurityForNetConfigOpsOnSubkeys(HKEY hkeyRoot, LPCWSTR strKeyName);
  304. public:
  305. ADAPTER_INFO * GetConnectionAdapterInfo()
  306. {
  307. return m_pSecondMemoryAdapterInfo;
  308. };
  309. ConnectionType GetConnectionType()
  310. {
  311. return m_ConnType;
  312. };
  313. BOOL IsRasNotAdmin()
  314. {
  315. return m_fRasNotAdmin;
  316. }
  317. };