Leaked source code of windows server 2003
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.

377 lines
13 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000-2002 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // CTaskUpgradeWhistler.cpp
  7. //
  8. // Header File:
  9. // CTaskUpgradeWhistler.h
  10. //
  11. // Description:
  12. // Implementation file for the CTaskUpgradeWindowsDotNet class.
  13. //
  14. // Maintained By:
  15. // David Potter (DavidP) 07-SEP-2001
  16. // Vij Vasu (Vvasu) 18-APR-2000
  17. //
  18. //////////////////////////////////////////////////////////////////////////////
  19. //////////////////////////////////////////////////////////////////////////////
  20. // Include Files
  21. //////////////////////////////////////////////////////////////////////////////
  22. // Precompiled header for this DLL.
  23. #include "Pch.h"
  24. // The header file for this module.
  25. #include "CTaskUpgradeWhistler.h"
  26. //////////////////////////////////////////////////////////////////////////////
  27. // Macro Definitions
  28. //////////////////////////////////////////////////////////////////////////////
  29. // Needed for tracing.
  30. DEFINE_THISCLASS( "CTaskUpgradeWindowsDotNet" )
  31. /////////////////////////////////////////////////////////////////////////////
  32. //++
  33. //
  34. // CTaskUpgradeWindowsDotNet::CTaskUpgradeWindowsDotNet
  35. //
  36. // Description:
  37. // Constructor of the CTaskUpgradeWindowsDotNet class.
  38. //
  39. // Arguments:
  40. // const CClusOCMApp & rAppIn
  41. // Reference to the CClusOCMApp object that is hosting this task.
  42. //
  43. // Return Value:
  44. // None.
  45. //
  46. //--
  47. /////////////////////////////////////////////////////////////////////////////
  48. CTaskUpgradeWindowsDotNet::CTaskUpgradeWindowsDotNet(
  49. const CClusOCMApp & rAppIn
  50. )
  51. : BaseClass( rAppIn )
  52. {
  53. TraceFunc( "" );
  54. TraceFuncExit();
  55. } //*** CTaskUpgradeWindowsDotNet::CTaskUpgradeWindowsDotNet
  56. /////////////////////////////////////////////////////////////////////////////
  57. //++
  58. //
  59. // CTaskUpgradeWindowsDotNet::~CTaskUpgradeWindowsDotNet
  60. //
  61. // Description:
  62. // Destructor of the CTaskUpgradeWindowsDotNet class.
  63. //
  64. // Arguments:
  65. // None.
  66. //
  67. // Return Value:
  68. // None.
  69. //
  70. //--
  71. /////////////////////////////////////////////////////////////////////////////
  72. CTaskUpgradeWindowsDotNet::~CTaskUpgradeWindowsDotNet( void )
  73. {
  74. TraceFunc( "" );
  75. TraceFuncExit();
  76. } //*** CTaskUpgradeWindowsDotNet::~CTaskUpgradeWindowsDotNet
  77. /////////////////////////////////////////////////////////////////////////////
  78. //++
  79. //
  80. // CTaskUpgradeWindowsDotNet::DwOcQueueFileOps
  81. //
  82. // Description:
  83. // This function handles the OC_QUEUE_FILE_OPS messages from the Optional
  84. // Components Manager. It installs the files needed for an upgrade from
  85. // Windows 2000.
  86. //
  87. // Arguments:
  88. // HSPFILEQ hSetupFileQueueIn
  89. // Handle to the file queue to operate upon.
  90. //
  91. // Return Value:
  92. // NO_ERROR if all went well.
  93. // Other Win32 error codes on failure.
  94. //
  95. //--
  96. /////////////////////////////////////////////////////////////////////////////
  97. DWORD
  98. CTaskUpgradeWindowsDotNet::DwOcQueueFileOps( HSPFILEQ hSetupFileQueueIn )
  99. {
  100. TraceFunc( "" );
  101. LogMsg( "Entering " __FUNCTION__ "()" );
  102. DWORD dwReturnValue = NO_ERROR;
  103. // Do different things based on whether this node is already part of a cluster or not.
  104. if ( RGetApp().CisGetClusterInstallState() == eClusterInstallStateFilesCopied )
  105. {
  106. LogMsg( "The cluster binaries are installed, but this node is not part of a cluster." );
  107. // The base class helper function does everything that we need to do here.
  108. // So, just call it.
  109. dwReturnValue = TW32( BaseClass::DwOcQueueFileOps( hSetupFileQueueIn, INF_SECTION_WHISTLER_UPGRADE_UNCLUSTERED_NODE ) );
  110. } // if: the node is not part of a cluster
  111. else
  112. {
  113. LogMsg( "This node is part of a cluster." );
  114. // The base class helper function does everything that we need to do here.
  115. // So, just call it.
  116. dwReturnValue = TW32( BaseClass::DwOcQueueFileOps( hSetupFileQueueIn, INF_SECTION_WHISTLER_UPGRADE ) );
  117. } // else: the node is part of a cluster
  118. LogMsg( "Return Value is %#x.", dwReturnValue );
  119. RETURN( dwReturnValue );
  120. } //*** CTaskUpgradeWindowsDotNet::DwOcQueueFileOps
  121. /////////////////////////////////////////////////////////////////////////////
  122. //++
  123. //
  124. // CTaskUpgradeWindowsDotNet::DwOcCompleteInstallation
  125. //
  126. // Description:
  127. // This function handles the OC_COMPLETE_INSTALLATION messages from the
  128. // Optional Components Manager during an upgrade from Windows 2000.
  129. //
  130. // Registry operations, COM component registrations, creation of servies
  131. // etc. are performed in this function.
  132. //
  133. // Arguments:
  134. // None.
  135. //
  136. // Return Value:
  137. // NO_ERROR if all went well.
  138. // Other Win32 error codes on failure.
  139. //
  140. //--
  141. /////////////////////////////////////////////////////////////////////////////
  142. DWORD
  143. CTaskUpgradeWindowsDotNet::DwOcCompleteInstallation( void )
  144. {
  145. TraceFunc( "" );
  146. LogMsg( "Entering " __FUNCTION__ "()" );
  147. DWORD dwReturnValue = NO_ERROR;
  148. // Do different things based on whether this node is already part of a cluster or not.
  149. if ( RGetApp().CisGetClusterInstallState() == eClusterInstallStateFilesCopied )
  150. {
  151. LogMsg( "The cluster binaries are installed, but this node is not part of a cluster." );
  152. // The base class helper function does everything that we need to do here.
  153. // So, just call it.
  154. dwReturnValue = TW32( BaseClass::DwOcCompleteInstallation( INF_SECTION_WHISTLER_UPGRADE_UNCLUSTERED_NODE ) );
  155. } // if: the node is not part of a cluster
  156. else
  157. {
  158. LogMsg( "This node is part of a cluster." );
  159. // The base class helper function does everything that we need to do here.
  160. // So, just call it.
  161. dwReturnValue = TW32( BaseClass::DwOcCompleteInstallation( INF_SECTION_WHISTLER_UPGRADE ) );
  162. } // else: the node is part of a cluster
  163. LogMsg( "Return Value is %#x.", dwReturnValue );
  164. RETURN( dwReturnValue );
  165. } //*** CTaskUpgradeWindowsDotNet::DwOcCompleteInstallation
  166. /////////////////////////////////////////////////////////////////////////////
  167. //++
  168. //
  169. // CTaskUpgradeWindowsDotNet::DwOcCleanup
  170. //
  171. // Description:
  172. // This function handles the OC_CLEANUP messages from the
  173. // Optional Components Manager during an upgrade from Windows 2000.
  174. //
  175. // If an error has previously occurred during this task, cleanup operations
  176. // are performed. Otherwise nothing is done by this function.
  177. //
  178. // Arguments:
  179. // None.
  180. //
  181. // Return Value:
  182. // NO_ERROR if all went well.
  183. // Other Win32 error codes on failure.
  184. //
  185. //--
  186. /////////////////////////////////////////////////////////////////////////////
  187. DWORD
  188. CTaskUpgradeWindowsDotNet::DwOcCleanup( void )
  189. {
  190. TraceFunc( "" );
  191. LogMsg( "Entering " __FUNCTION__ "()" );
  192. DWORD dwReturnValue = NO_ERROR;
  193. // Do different things based on whether this node is already part of a cluster or not.
  194. if ( RGetApp().CisGetClusterInstallState() == eClusterInstallStateFilesCopied )
  195. {
  196. LogMsg( "The cluster binaries are installed, but this node is not part of a cluster." );
  197. // The base class helper function does everything that we need to do here.
  198. // So, just call it.
  199. dwReturnValue = TW32( BaseClass::DwOcCleanup( INF_SECTION_WHISTLER_UPGRADE_UNCLUSTERED_NODE_CLEANUP ) );
  200. } // if: the node is not part of a cluster
  201. else
  202. {
  203. LogMsg( "This node is part of a cluster." );
  204. // The base class helper function does everything that we need to do here.
  205. // So, just call it.
  206. dwReturnValue = TW32( BaseClass::DwOcCleanup( INF_SECTION_WHISTLER_UPGRADE_CLEANUP ) );
  207. } // else: the node is part of a cluster
  208. LogMsg( "Return Value is %#x.", dwReturnValue );
  209. RETURN( dwReturnValue );
  210. } //*** CTaskUpgradeWindowsDotNet::DwOcCleanup
  211. /////////////////////////////////////////////////////////////////////////////
  212. //++
  213. //
  214. // CTaskUpgradeWindowsDotNet::DwSetDirectoryIds
  215. //
  216. // Description:
  217. // This function maps ids specified in the INF file to directories.
  218. // The location of the cluster binaries is read from the registry
  219. // and the cluster installation directory is mapped to this value.
  220. //
  221. // Arguments:
  222. // None.
  223. //
  224. // Return Value:
  225. // NO_ERROR if all went well.
  226. // Other Win32 error codes on failure.
  227. //
  228. //--
  229. /////////////////////////////////////////////////////////////////////////////
  230. DWORD
  231. CTaskUpgradeWindowsDotNet::DwSetDirectoryIds( void )
  232. {
  233. TraceFunc( "" );
  234. LogMsg( "Entering " __FUNCTION__ "()" );
  235. DWORD dwReturnValue = NO_ERROR;
  236. SmartRegistryKey srkNodeDataKey;
  237. SmartSz sszInstallDir;
  238. DWORD cbBufferSize = 0;
  239. DWORD dwType = REG_SZ;
  240. {
  241. HKEY hTempKey = NULL;
  242. // Open the node data registry key
  243. dwReturnValue = TW32(
  244. RegOpenKeyEx(
  245. HKEY_LOCAL_MACHINE
  246. , CLUSREG_KEYNAME_NODE_DATA
  247. , 0
  248. , KEY_READ
  249. , &hTempKey
  250. )
  251. );
  252. if ( dwReturnValue != NO_ERROR )
  253. {
  254. LogMsg( "Error %#x occurred trying open the registry key where the cluster install path is stored.", dwReturnValue );
  255. goto Cleanup;
  256. } // if: RegOpenKeyEx() failed
  257. // Store the opened key in a smart pointer for automatic close.
  258. srkNodeDataKey.Assign( hTempKey );
  259. }
  260. // Get the required size of the buffer.
  261. dwReturnValue = TW32(
  262. RegQueryValueExW(
  263. srkNodeDataKey.HHandle() // handle to key to query
  264. , CLUSREG_INSTALL_DIR_VALUE_NAME // name of value to query
  265. , 0 // reserved
  266. , NULL // address of buffer for value type
  267. , NULL // address of data buffer
  268. , &cbBufferSize // address of data buffer size
  269. )
  270. );
  271. if ( dwReturnValue != NO_ERROR )
  272. {
  273. LogMsg( "Error %#x occurred trying to read the registry value '%s'.", dwReturnValue, CLUSREG_INSTALL_DIR_VALUE_NAME );
  274. goto Cleanup;
  275. } // if: an error occurred trying to read the CLUSREG_INSTALL_DIR_VALUE_NAME registry value
  276. // Allocate the required buffer.
  277. sszInstallDir.Assign( reinterpret_cast< WCHAR * >( new BYTE[ cbBufferSize ] ) );
  278. if ( sszInstallDir.FIsEmpty() )
  279. {
  280. LogMsg( "An error occurred trying to allocate %d bytes of memory.", cbBufferSize );
  281. dwReturnValue = TW32( ERROR_NOT_ENOUGH_MEMORY );
  282. goto Cleanup;
  283. } // if: a memory allocation failure occurred
  284. // Read the value.
  285. dwReturnValue = TW32(
  286. RegQueryValueExW(
  287. srkNodeDataKey.HHandle() // handle to key to query
  288. , CLUSREG_INSTALL_DIR_VALUE_NAME // name of value to query
  289. , 0 // reserved
  290. , &dwType // address of buffer for value type
  291. , reinterpret_cast< LPBYTE >( sszInstallDir.PMem() ) // address of data buffer
  292. , &cbBufferSize // address of data buffer size
  293. )
  294. );
  295. Assert( ( dwType == REG_SZ ) || ( dwType == REG_EXPAND_SZ ) );
  296. // Was the key read properly?
  297. if ( dwReturnValue != NO_ERROR )
  298. {
  299. LogMsg( "Error %#x occurred trying to read the registry value '%s'.", dwReturnValue, CLUSREG_INSTALL_DIR_VALUE_NAME );
  300. goto Cleanup;
  301. } // if: RegQueryValueEx failed.
  302. // Create the mapping between the directory id and the path
  303. if ( SetupSetDirectoryId(
  304. RGetApp().RsicGetSetupInitComponent().ComponentInfHandle
  305. , CLUSTER_DEFAULT_INSTALL_DIRID
  306. , sszInstallDir.PMem()
  307. )
  308. == FALSE
  309. )
  310. {
  311. dwReturnValue = TW32( GetLastError() );
  312. LogMsg( "Error %#x occurred trying set the cluster install directory id.", dwReturnValue );
  313. goto Cleanup;
  314. } // if: SetupSetDirectoryId() failed
  315. LogMsg( "The id %d maps to '%s'.", CLUSTER_DEFAULT_INSTALL_DIRID, sszInstallDir.PMem() );
  316. Cleanup:
  317. LogMsg( "Return Value is %#x.", dwReturnValue );
  318. RETURN( dwReturnValue );
  319. } //*** CTaskUpgradeWindowsDotNet::DwSetDirectoryIds