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.

316 lines
9.5 KiB

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