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.

257 lines
10 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000.
  5. //
  6. // File: I C S U P G R D . H
  7. //
  8. // Contents: Functions that is related to
  9. // o upgrade of ICS from Win98 SE, WinMe and Win2K to Whistler
  10. // o unattended clean install of Homenet on Whistler or later
  11. //
  12. //
  13. // Date: 20-Sept-2000
  14. //
  15. //----------------------------------------------------------------------------
  16. #pragma once
  17. // entry point to upgrade ICS
  18. BOOL FDoIcsUpgradeIfNecessary();
  19. BOOL FIcsUpgrade(CWInfFile* pwifAnswerFile);
  20. //----------------------ICS Upgrade const literals begin------------------
  21. // Win2K ICS registry settings
  22. const TCHAR c_wszRegKeySharedAccessParams[] = L"SYSTEM\\CurrentControlSet\\Services\\SharedAccess\\Parameters";
  23. const TCHAR c_wszRegValSharedConnection[] = L"SharedConnection";
  24. const TCHAR c_wszRegValSharedPrivateLan[] = L"SharedPrivateLan";
  25. const WCHAR c_wszRegValBackupSharedConnection[] = L"BackupSharedConnection";
  26. const WCHAR c_wszRegValBackupSharedPrivateLan[] = L"BackupSharedPrivateLan";
  27. // ICS Upgrade named event
  28. const WCHAR c_wszIcsUpgradeEventName[] = L"IcsUpgradeEventName_";
  29. // Win2K ICS Application and Server PortMapping stuff
  30. const WCHAR c_wszPhoneBookPath[] = L"\\Microsoft\\Network\\Connections\\Pbk\\";
  31. const WCHAR c_wszFileSharedAccess[] = L"SharedAccess.ini";
  32. const WCHAR c_wszContentsServer[] = L"Contents.Server";
  33. const WCHAR c_wszContentsApplication[] = L"Contents.Application";
  34. const WCHAR c_wszServerPrefix[] = L"Server.";
  35. const WCHAR c_wszApplicationPrefix[] = L"Application.";
  36. const WCHAR c_wszInternalName[] = L"InternalName";
  37. const WCHAR c_wszTitle[] = L"Title";
  38. const WCHAR c_wszInternalPort[] = L"InternalPort";
  39. const WCHAR c_wszPort[] = L"Port";
  40. const WCHAR c_wszReservedAddress[] = L"ReservedAddress";
  41. const WCHAR c_wszProtocol[] = L"Protocol";
  42. const WCHAR c_wszBuiltIn[] = L"BuiltIn";
  43. const WCHAR c_wszTcpResponseList[] = L"TcpResponseList";
  44. const WCHAR c_wszUdpResponseList[] = L"UdpResponseList";
  45. const WCHAR c_wszTCP[] = L"TCP";
  46. const WCHAR c_wszUDP[] = L"UDP";
  47. // Tcp/Ip registry configuration
  48. const WCHAR c_wszEnableDHCP[] = L"EnableDHCP";
  49. const WCHAR c_wszInterfaces[] = L"Interfaces";
  50. const WCHAR c_wszIPAddress[] = L"IPAddress";
  51. const WCHAR c_wszSubnetMask[] = L"SubnetMask";
  52. const WCHAR c_wszTcpipParametersKey[] = L"SYSTEM\\CurrentControlSet\\Services"
  53. L"\\Tcpip\\Parameters";
  54. const WCHAR c_mszScopeAddress[] = L"192.168.0.1\0"; // multi_sz
  55. const WCHAR c_mszScopeMask[] = L"255.255.255.0\0"; // multi_sz
  56. // These are constant for Homenet Answer-File
  57. const WCHAR c_wszHomenetSection[] = L"Homenet"; // section name
  58. const WCHAR c_wszExternalAdapter[] = L"ExternalAdapter";
  59. const WCHAR c_wszExternalConnectionName[] = L"ExternalConnectionName";
  60. const WCHAR c_wszInternalAdapter[] = L"InternalAdapter";
  61. const WCHAR c_wszInternalAdapter2[] = L"InternalAdapter2";
  62. const WCHAR c_wszDialOnDemand[] = L"DialOnDemand";
  63. const WCHAR c_wszICSEnabled[] = L"EnableICS";
  64. const WCHAR c_wszShowTrayIcon[] = L"ShowTrayIcon";
  65. const WCHAR c_wszInternalIsBridge[] = L"InternalIsBridge";
  66. const WCHAR c_wszPersonalFirewall[] = L"InternetConnectionFirewall"; // multi_sz key
  67. const WCHAR c_wszBridge[] = L"Bridge"; // multi_sz key
  68. // keys which are not published
  69. const WCHAR c_wszIsW9xUpgrade[] = L"IsW9xUpgrade";
  70. // ShFolder.dll imports
  71. const WCHAR c_wszShFolder[] = L"SHFOLDER.DLL";
  72. const CHAR c_szSHGetFolderPathW[] = "SHGetFolderPathW";
  73. // hnetcfg.dll imports
  74. const WCHAR c_wszHNetCfgDll[] = L"hnetcfg.dll";
  75. const CHAR c_szHNetSetShareAndBridgeSettings[] = "HNetSetShareAndBridgeSettings";
  76. //--------- ICS Upgrade const literals end---------------------------
  77. //--------- ICS Upgrade helpers begin---------------------------
  78. #define HTONS(s) ((UCHAR)((s) >> 8) | ((UCHAR)(s) << 8))
  79. #define HTONL(l) ((HTONS(l) << 16) | HTONS((l) >> 16))
  80. #define NTOHS(s) HTONS(s)
  81. #define NTOHL(l) HTONL(l)
  82. // note: we are using the tstring from config\inc\ncstlstr.h
  83. // Application Protocol
  84. class CSharedAccessApplication
  85. {
  86. public:
  87. tstring m_szTitle;
  88. tstring m_szProtocol;
  89. WORD m_wPort;
  90. tstring m_szTcpResponseList;
  91. tstring m_szUdpResponseList;
  92. BOOL m_bBuiltIn;
  93. BOOL m_bSelected;
  94. DWORD m_dwSectionNum;
  95. };
  96. // Server PortMapping Protocol
  97. class CSharedAccessServer
  98. {
  99. public:
  100. CSharedAccessServer();
  101. tstring m_szTitle;
  102. tstring m_szProtocol;
  103. WORD m_wPort;
  104. WORD m_wInternalPort;
  105. tstring m_szInternalName;
  106. tstring m_szReservedAddress;
  107. BOOL m_bBuiltIn;
  108. BOOL m_bSelected;
  109. DWORD m_dwSectionNum;
  110. };
  111. // ICS upgrade settings
  112. typedef struct _ICS_UPGRADE_SETTINGS
  113. {
  114. RASSHARECONN rscExternal;
  115. list<CSharedAccessServer> listSvrPortmappings;
  116. list<CSharedAccessApplication> listAppPortmappings;
  117. list<GUID> listPersonalFirewall; // a list of interface guid to be firewall
  118. list<GUID> listBridge; // a list of interface guid to form a bridge
  119. GUID guidInternal; // internal interface guid of ICS
  120. BOOL fInternalAdapterFound; // guidInternal is valid
  121. BOOL fInternalIsBridge; // ICS private is a bridge
  122. BOOL fEnableICS; // ICS enabled
  123. BOOL fShowTrayIcon;
  124. BOOL fDialOnDemand;
  125. // flag to tell this is an upgrade from Win9x
  126. BOOL fWin9xUpgrade;
  127. // flag to tell at least one of the internal adapters couldn't be upgraded
  128. BOOL fWin9xUpgradeAtLeastOneInternalAdapterBroken;
  129. // flag to tell this is an upgrade from Windows 2000
  130. BOOL fWin2KUpgrade;
  131. // flag to tell this is an unattended Homenet clean setup on XP or later
  132. BOOL fXpUnattended;
  133. } ICS_UPGRADE_SETTINGS, *PICS_UPGRADE_SETTINGS;
  134. HRESULT GetPhonebookDirectory(TCHAR* pszPathBuf);
  135. HRESULT GetServerMappings(list<CSharedAccessServer> &lstSharedAccessServers);
  136. HRESULT GetApplicationMappings(list<CSharedAccessApplication> &lstSharedAccessApplications);
  137. HRESULT PutResponseStringIntoArray(CSharedAccessApplication& rsaaAppProt,
  138. USHORT* pdwcResponse, HNET_RESPONSE_RANGE** pphnrrResponseRange);
  139. HRESULT BuildIcsUpgradeSettingsFromWin2K(ICS_UPGRADE_SETTINGS* pIcsUpgrdSettings);
  140. HRESULT UpgradeIcsSettings(ICS_UPGRADE_SETTINGS * pIcsUpgrdSettings);
  141. HRESULT BackupAndDelIcsRegistryValuesOnWin2k();
  142. HRESULT LoadIcsSettingsFromAnswerFile(CWInfFile* pwifAnswerFile,
  143. PICS_UPGRADE_SETTINGS pSettings);
  144. HRESULT ConvertAdapterStringListToGuidList(IN TStringList& rslAdapters,
  145. IN OUT list<GUID>& rlistGuid);
  146. void FreeIcsUpgradeSettings(ICS_UPGRADE_SETTINGS* pIcsUpgrdSettings);
  147. void SetIcsDefaultSettings(ICS_UPGRADE_SETTINGS * pSettings);
  148. BOOL FNeedIcsUpgradeFromWin2K();
  149. BOOL FOsIsAdvServerOrHigher();
  150. extern HRESULT HNetCreateBridge(
  151. IN INetConnection * rgspNetConns[],
  152. OUT IHNetBridge ** ppBridge);
  153. extern HRESULT HrEnablePersonalFirewall(
  154. IN INetConnection * rgspNetConns[] );
  155. extern HRESULT HrCreateICS(
  156. IN INetConnection * pPublicConnection,
  157. IN INetConnection * pPrivateConnection);
  158. //--------- ICS Upgrade helpers end---------------------------
  159. //--------- HNet helpers begin---------------------------
  160. class CIcsUpgrade
  161. {
  162. public:
  163. CIcsUpgrade() : m_pIcsUpgradeSettings(0), m_spEnum(0),
  164. m_fInited(FALSE), m_fICSCreated(FALSE),
  165. m_hIcsUpgradeEvent(NULL), m_pExternalNetConn(0) {};
  166. ~CIcsUpgrade() {FinalRelease();};
  167. HRESULT Init(ICS_UPGRADE_SETTINGS* pIcsUpgradeSettings);
  168. HRESULT StartUpgrade();
  169. private:
  170. // disallow copy constructor and assignment
  171. CIcsUpgrade(CIcsUpgrade&);
  172. CIcsUpgrade& operator=(CIcsUpgrade&);
  173. void FinalRelease();
  174. HRESULT SetupHomenetConnections();
  175. HRESULT CIcsUpgrade::GetINetConnectionArray(
  176. IN list<GUID>& rlistGuid,
  177. IN OUT INetConnection*** pprgINetConn,
  178. IN OUT DWORD* pcINetConn);
  179. HRESULT GetExternalINetConnection(INetConnection** ppNetCon);
  180. HRESULT GetINetConnectionByGuid(GUID* pGuid, INetConnection** ppNetCon);
  181. HRESULT GetINetConnectionByName(WCHAR* pwszConnName, INetConnection** ppNetCon);
  182. HRESULT SetupApplicationProtocol();
  183. HRESULT SetupServerPortMapping();
  184. HRESULT SetupIcsMiscItems();
  185. HRESULT FindMatchingPortMappingProtocol(
  186. IHNetProtocolSettings* pHNetProtocolSettings,
  187. UCHAR ucProtocol,
  188. USHORT usPort,
  189. IHNetPortMappingProtocol** ppHNetPortMappingProtocol);
  190. HRESULT FindMatchingApplicationProtocol(
  191. IHNetProtocolSettings* pHNetProtocolSettings,
  192. UCHAR ucProtocol,
  193. USHORT usPort,
  194. IHNetApplicationProtocol** ppHNetApplicationProtocol);
  195. // named event to let HNetCfg know that we're in GUI Mode Setup
  196. HRESULT CreateIcsUpgradeNamedEvent();
  197. // methods to fix IP configuration of private interface on Win9x Upgrade
  198. HRESULT SetPrivateIpConfiguration(IN GUID& rInterfaceGuid);
  199. HRESULT GetBridgeGuid(OUT GUID& rInterfaceGuid);
  200. HRESULT GetBridgeINetConn(OUT INetConnection** ppINetConn);
  201. HRESULT OpenTcpipInterfaceKey(
  202. IN GUID& rGuid,
  203. OUT PHKEY phKey);
  204. // upgrade settings
  205. ICS_UPGRADE_SETTINGS* m_pIcsUpgradeSettings;
  206. // Init() called
  207. BOOL m_fInited;
  208. BOOL m_fICSCreated; // succeeded in creating ICS.
  209. // named event in GUI Mode setup,
  210. // hnetcfg will check this to avoid any problems in GUI Mode Setup
  211. HANDLE m_hIcsUpgradeEvent;
  212. // cached HNet stuff
  213. CComPtr<IEnumNetConnection> m_spEnum;
  214. INetConnection* m_pExternalNetConn;
  215. };
  216. //--------- HNet helpers end---------------------------