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.

301 lines
8.6 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright(C) 2000 Microsoft Corporation all rights reserved.
  4. //
  5. // Module: DoUpgrade.cpp
  6. //
  7. // Project: Windows 2000 IAS
  8. //
  9. // Description: Implementation of CDoNT4OrCleanUpgrade, CUpgradeWin2k
  10. // and CUpgradeNT4
  11. //
  12. // Author: tperraut
  13. //
  14. // Revision 02/24/2000 created
  15. // 06/13/2000 Execute returns void,
  16. // private functions moved from CUpgradeWin2k
  17. // to CMigrateContent
  18. // CDoUpgrade used for "clean or NT4 upgrades" only.
  19. //
  20. /////////////////////////////////////////////////////////////////////////////
  21. #include "stdafx.h"
  22. #include "DoUpgrade.h"
  23. #include "migratemdb.h"
  24. #include "migratecontent.h"
  25. #include "Version.h"
  26. #include "iasdb.h"
  27. //////////////////////////////////////////////////////////////////////////////
  28. // Execute
  29. // Does either a clean NT4 upgrade or nothing (clean install)
  30. //////////////////////////////////////////////////////////////////////////////
  31. void CDoNT4OrCleanUpgrade::Execute()
  32. {
  33. if ( m_Utils.IsNT4Corp() || m_Utils.IsNT4Isp() )
  34. {
  35. CUpgradeNT4 UpgradeNT4;
  36. UpgradeNT4.Execute();
  37. }
  38. // else this is a clean install: nothing to do
  39. }
  40. //////////////////////////////////////////////////////////////////////////////
  41. // GetVersionNumber
  42. //////////////////////////////////////////////////////////////////////////////
  43. LONG CUpgradeWin2k::GetVersionNumber()
  44. {
  45. return m_GlobalData.m_pRefVersion->GetVersion();
  46. }
  47. //////////////////////////////////////////////////////////////////////////////
  48. // CLASS CUpgradeWin2k
  49. // expects the files:
  50. // iasold.mdb as a Whistler before proxy or a Win2k mdb file
  51. // ias.mdb to be a Whistler file (already good)
  52. //////////////////////////////////////////////////////////////////////////////
  53. ///////////////
  54. // Constructor
  55. ///////////////
  56. CUpgradeWin2k::CUpgradeWin2k()
  57. :m_Outcome(E_FAIL),
  58. m_GlobalTransaction(CGlobalTransaction::Instance()),
  59. m_Utils(CUtils::Instance())
  60. {
  61. /////////////////////////////////////////////////
  62. // Check %TMP% and create a directory if needed
  63. // That's to fix a bug with JET
  64. /////////////////////////////////////////////////
  65. IASCreateTmpDirectory();
  66. // Create the paths to the mdb files
  67. LONG Result = m_Utils.GetIAS2Directory(m_IASWhistlerPath);
  68. if ( Result != ERROR_SUCCESS )
  69. {
  70. _com_util::CheckError(HRESULT_FROM_WIN32(Result));
  71. }
  72. m_IASOldPath = m_IASWhistlerPath;
  73. m_IASOldPath += L"\\iasold.mdb";
  74. m_IASWhistlerPath += L"\\ias.mdb";
  75. //////////////////
  76. // Database inits
  77. //////////////////
  78. // Open the DataSource and session for ias.mdb
  79. // and Initialize the GlobalTransaction
  80. m_GlobalTransaction.OpenStdDataSource(m_IASWhistlerPath);
  81. // Open the DataSource and session for iasnew.mdb
  82. m_GlobalTransaction.OpenRefDataSource(m_IASOldPath);
  83. // create instances of CObjects and CProperties
  84. m_GlobalData.InitStandard(m_GlobalTransaction.GetStdSession());
  85. // create instances of CObjects and CProperties for the Ref database
  86. m_GlobalData.InitRef(m_GlobalTransaction.GetRefSession());
  87. };
  88. //////////////
  89. // Destructor
  90. //////////////
  91. CUpgradeWin2k::~CUpgradeWin2k()
  92. {
  93. m_GlobalData.Clean();
  94. if ( FAILED(m_Outcome) )
  95. {
  96. /////////////////////////
  97. // Abort the transaction
  98. /////////////////////////
  99. m_GlobalTransaction.Abort();
  100. SetLastError(E_FAIL);
  101. }
  102. else
  103. {
  104. ///////////
  105. // Success
  106. ///////////
  107. m_GlobalTransaction.Commit();
  108. }
  109. /////////////////////////////////////////////
  110. // close the session and then the datasource
  111. /////////////////////////////////////////////
  112. m_GlobalTransaction.MyCloseDataSources();
  113. };
  114. /////////////////////////////
  115. // Execute
  116. // IAS_WIN2K_VERSION = 0;
  117. // IAS_WHISTLER1_VERSION = 1;
  118. // IAS_WHISTLER_BETA1_VERSION = 2;
  119. // IAS_WHISTLER_BETA2_VERSION = 3;
  120. /////////////////////////////
  121. void CUpgradeWin2k::Execute()
  122. {
  123. CMigrateContent MigrateContent(m_Utils, m_GlobalData);
  124. ////////////////////////////////////////////////////
  125. // Check the version number (of iasold.mdb)
  126. ////////////////////////////////////////////////////
  127. LONG CurrentVersion = GetVersionNumber();
  128. ////////////////////////////////////////////////////
  129. // Migrate the content from iasold.mdb into ias.mdb
  130. ////////////////////////////////////////////////////
  131. switch (CurrentVersion)
  132. {
  133. case IAS_WIN2K_VERSION:
  134. case IAS_WHISTLER1_VERSION:
  135. {
  136. MigrateContent.Migrate();
  137. // Everything is ok. Set m_Outcome = S_OK to Commit the IAS.mdb
  138. m_Outcome = S_OK;
  139. break;
  140. }
  141. case IAS_WHISTLER_BETA1_VERSION:
  142. {
  143. // Update the MSChap Authentication types (password)
  144. MigrateContent.UpdateWhistler(true);
  145. // Everything is ok. Set m_Outcome = S_OK to Commit the IAS.mdb
  146. m_Outcome = S_OK;
  147. break;
  148. }
  149. case IAS_WHISTLER_BETA2_VERSION:
  150. {
  151. // do not touch the MSChap Authentication types (password)
  152. MigrateContent.UpdateWhistler(false);
  153. // Everything is ok. Set m_Outcome = S_OK to Commit the IAS.mdb
  154. m_Outcome = S_OK;
  155. break;
  156. }
  157. default:
  158. {
  159. }
  160. }
  161. }
  162. //////////////////////////////////////////////////////////////////////////////
  163. // CLASS CUpgradeNT4
  164. //////////////////////////////////////////////////////////////////////////////
  165. ///////////////
  166. // Constructor
  167. ///////////////
  168. CUpgradeNT4::CUpgradeNT4()
  169. :m_Outcome(E_FAIL),
  170. m_GlobalTransaction(CGlobalTransaction::Instance()),
  171. m_Utils(CUtils::Instance())
  172. {
  173. const WCHAR IAS_MDB_NAME[] = L"\\ias.mdb";
  174. const WCHAR DNARY_MDB_NAME[] = L"\\dnary.mdb";
  175. /////////////////////////////////////////////////
  176. // Check %TMP% and create a directory if needed
  177. // That's to fix a bug with JET
  178. /////////////////////////////////////////////////
  179. IASCreateTmpDirectory();
  180. ///////////////////////////////
  181. // Backup the pristine ias.mdb
  182. ///////////////////////////////
  183. LONG Result = m_Utils.GetIAS2Directory(m_Ias2MdbString);
  184. if ( Result != ERROR_SUCCESS )
  185. {
  186. _com_issue_error(HRESULT_FROM_WIN32(Result));
  187. }
  188. m_DnaryMdbString = m_Ias2MdbString;
  189. m_DnaryMdbString += DNARY_MDB_NAME;
  190. m_Ias2MdbString += IAS_MDB_NAME;
  191. Result = m_Utils.GetAuthSrvDirectory(m_AuthSrvMdbString);
  192. if ( Result != ERROR_SUCCESS )
  193. {
  194. _com_issue_error(HRESULT_FROM_WIN32(Result));
  195. }
  196. m_AuthSrvMdbString += L"\\_adminui.mdb";
  197. m_IASNT4Path = m_AuthSrvMdbString;
  198. m_IASWhistlerPath = m_Ias2MdbString;
  199. // Open the DataSource and session for _adminui.mdb
  200. m_GlobalTransaction.OpenNT4DataSource(m_IASNT4Path);
  201. // create instances of CRemoteRadiusServers and CRealms
  202. m_GlobalData.InitNT4(m_GlobalTransaction.GetNT4Session());
  203. // Open the DataSource and session for ias.mdb
  204. // and Initialize the GlobalTransaction
  205. m_GlobalTransaction.OpenStdDataSource(m_IASWhistlerPath);
  206. // create instances of CObjects and CProperties
  207. m_GlobalData.InitStandard(m_GlobalTransaction.GetStdSession());
  208. m_GlobalTransaction.OpenDnaryDataSource(m_DnaryMdbString);
  209. m_GlobalData.InitDnary(m_GlobalTransaction.GetDnarySession());
  210. };
  211. //////////////
  212. // Destructor
  213. //////////////
  214. CUpgradeNT4::~CUpgradeNT4()
  215. {
  216. //////////
  217. // Clean
  218. //////////
  219. // Abort or Commit depending on Result
  220. m_GlobalData.Clean();
  221. if ( SUCCEEDED(m_Outcome) )
  222. {
  223. m_GlobalTransaction.Commit(); // ignore return value
  224. }
  225. else
  226. {
  227. m_GlobalTransaction.Abort(); // ignore return value
  228. SetLastError(E_FAIL);
  229. }
  230. // close the sessions and then the datasources
  231. // for ias.mdb iasnew.mdb and _adminui.mdb
  232. m_GlobalTransaction.MyCloseDataSources();
  233. // Restore the pristine ias.mdb if the migration failed
  234. if ( SUCCEEDED(m_Outcome) )
  235. {
  236. // Success, the old files are deleted
  237. m_Utils.DeleteOldIASFiles();
  238. }
  239. };
  240. ///////////
  241. // Execute
  242. ///////////
  243. void CUpgradeNT4::Execute()
  244. {
  245. CMigrateMdb MigrateMdb(m_Utils, m_GlobalData);
  246. ////////////////////////////////////////
  247. // Migrate the MDB file
  248. // including the proxy servers
  249. ////////////////////////////////////////
  250. // Perform the migration into ias.mdb
  251. MigrateMdb.NewMigrate();
  252. // Set m_Outcome = S_OK to allow the Commit on the DB... in the
  253. // destructor
  254. m_Outcome = S_OK;
  255. }