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.

577 lines
14 KiB

  1. #include "StdAfx.h"
  2. #include "Migration.h"
  3. #include "Switch.h"
  4. namespace
  5. {
  6. void __stdcall AdmtCheckError(HRESULT hr)
  7. {
  8. if (FAILED(hr))
  9. {
  10. IErrorInfo* pErrorInfo = NULL;
  11. if (GetErrorInfo(0, &pErrorInfo) == S_OK)
  12. {
  13. _com_raise_error(hr, pErrorInfo);
  14. }
  15. else
  16. {
  17. _com_issue_error(hr);
  18. }
  19. }
  20. }
  21. }
  22. //---------------------------------------------------------------------------
  23. // Migration Class
  24. //---------------------------------------------------------------------------
  25. void CMigration::Initialize(CParameterMap& mapParams)
  26. {
  27. bool bValue;
  28. long lValue;
  29. _bstr_t strValue;
  30. if (mapParams.GetValue(SWITCH_TEST_MIGRATION, bValue))
  31. {
  32. m_spMigration->TestMigration = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  33. }
  34. if (mapParams.GetValue(SWITCH_INTRA_FOREST, bValue))
  35. {
  36. m_spMigration->IntraForest = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  37. }
  38. if (mapParams.GetValue(SWITCH_SOURCE_DOMAIN, strValue))
  39. {
  40. m_spMigration->SourceDomain = strValue;
  41. }
  42. if (mapParams.GetValue(SWITCH_SOURCE_OU, strValue))
  43. {
  44. m_spMigration->SourceOu = strValue;
  45. }
  46. if (mapParams.GetValue(SWITCH_TARGET_DOMAIN, strValue))
  47. {
  48. m_spMigration->TargetDomain = strValue;
  49. }
  50. if (mapParams.GetValue(SWITCH_TARGET_OU, strValue))
  51. {
  52. m_spMigration->TargetOu = strValue;
  53. }
  54. if (mapParams.GetValue(SWITCH_RENAME_OPTION, lValue))
  55. {
  56. m_spMigration->RenameOption = lValue;
  57. }
  58. if (mapParams.GetValue(SWITCH_RENAME_PREFIX_OR_SUFFIX, strValue))
  59. {
  60. m_spMigration->RenamePrefixOrSuffix = strValue;
  61. }
  62. if (mapParams.GetValue(SWITCH_PASSWORD_OPTION, lValue))
  63. {
  64. m_spMigration->PasswordOption = lValue;
  65. }
  66. if (mapParams.GetValue(SWITCH_PASSWORD_SERVER, strValue))
  67. {
  68. AdmtCheckError(m_spMigration->put_PasswordServer(strValue));
  69. }
  70. if (mapParams.GetValue(SWITCH_PASSWORD_FILE, strValue))
  71. {
  72. m_spMigration->PasswordFile = strValue;
  73. }
  74. if (mapParams.GetValue(SWITCH_CONFLICT_OPTIONS, lValue))
  75. {
  76. m_spMigration->ConflictOptions = lValue;
  77. }
  78. if (mapParams.GetValue(SWITCH_CONFLICT_PREFIX_OR_SUFFIX, strValue))
  79. {
  80. m_spMigration->ConflictPrefixOrSuffix = strValue;
  81. }
  82. if (mapParams.GetValue(SWITCH_USER_PROPERTIES_TO_EXCLUDE, strValue))
  83. {
  84. m_spMigration->UserPropertiesToExclude = strValue;
  85. }
  86. if (mapParams.GetValue(SWITCH_GROUP_PROPERTIES_TO_EXCLUDE, strValue))
  87. {
  88. m_spMigration->GroupPropertiesToExclude = strValue;
  89. }
  90. if (mapParams.GetValue(SWITCH_COMPUTER_PROPERTIES_TO_EXCLUDE, strValue))
  91. {
  92. m_spMigration->ComputerPropertiesToExclude = strValue;
  93. }
  94. }
  95. //---------------------------------------------------------------------------
  96. // User Migration Class
  97. //---------------------------------------------------------------------------
  98. void CUserMigration::Initialize(CParameterMap& mapParams)
  99. {
  100. bool bValue;
  101. long lValue;
  102. if (mapParams.GetValue(SWITCH_DISABLE_OPTION, lValue))
  103. {
  104. m_spUser->DisableOption = lValue;
  105. }
  106. if (mapParams.GetValue(SWITCH_SOURCE_EXPIRATION, lValue))
  107. {
  108. m_spUser->SourceExpiration = lValue;
  109. }
  110. if (mapParams.GetValue(SWITCH_MIGRATE_SIDS, bValue))
  111. {
  112. m_spUser->MigrateSIDs = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  113. }
  114. if (mapParams.GetValue(SWITCH_TRANSLATE_ROAMING_PROFILE, bValue))
  115. {
  116. m_spUser->TranslateRoamingProfile = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  117. }
  118. if (mapParams.GetValue(SWITCH_UPDATE_USER_RIGHTS, bValue))
  119. {
  120. m_spUser->UpdateUserRights = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  121. }
  122. if (mapParams.GetValue(SWITCH_MIGRATE_GROUPS, bValue))
  123. {
  124. m_spUser->MigrateGroups = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  125. }
  126. if (mapParams.GetValue(SWITCH_UPDATE_PREVIOUSLY_MIGRATED_OBJECTS, bValue))
  127. {
  128. m_spUser->UpdatePreviouslyMigratedObjects = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  129. }
  130. if (mapParams.GetValue(SWITCH_FIX_GROUP_MEMBERSHIP, bValue))
  131. {
  132. m_spUser->FixGroupMembership = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  133. }
  134. if (mapParams.GetValue(SWITCH_MIGRATE_SERVICE_ACCOUNTS, bValue))
  135. {
  136. m_spUser->MigrateServiceAccounts = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  137. }
  138. if (mapParams.GetValue(SWITCH_SOURCE_EXPIRATION, lValue))
  139. {
  140. m_spUser->SourceExpiration = lValue;
  141. }
  142. _variant_t vntExcludeNames;
  143. if (!mapParams.GetValues(SWITCH_EXCLUDE_NAME, vntExcludeNames))
  144. {
  145. _bstr_t strExcludeFile;
  146. if (mapParams.GetValue(SWITCH_EXCLUDE_FILE, strExcludeFile))
  147. {
  148. vntExcludeNames = strExcludeFile;
  149. }
  150. }
  151. _variant_t vntIncludeNames;
  152. _bstr_t strIncludeFile;
  153. long lIncludeOption;
  154. if (mapParams.GetValues(SWITCH_INCLUDE_NAME, vntIncludeNames))
  155. {
  156. AdmtCheckError(m_spUser->raw_Migrate(admtData, vntIncludeNames, vntExcludeNames));
  157. }
  158. else if (mapParams.GetValue(SWITCH_INCLUDE_FILE, strIncludeFile))
  159. {
  160. AdmtCheckError(m_spUser->raw_Migrate(admtFile, _variant_t(strIncludeFile), vntExcludeNames));
  161. }
  162. else if (mapParams.GetValue(SWITCH_INCLUDE_DOMAIN, lIncludeOption))
  163. {
  164. AdmtCheckError(m_spUser->raw_Migrate(admtDomain | lIncludeOption, _variant_t(), vntExcludeNames));
  165. }
  166. else
  167. {
  168. ThrowError(E_INVALIDARG, IDS_E_NO_INCLUDE_OPTION_SPECIFIED);
  169. }
  170. }
  171. //---------------------------------------------------------------------------
  172. // Group Migration Class
  173. //---------------------------------------------------------------------------
  174. void CGroupMigration::Initialize(CParameterMap& mapParams)
  175. {
  176. bool bValue;
  177. long lValue;
  178. if (mapParams.GetValue(SWITCH_MIGRATE_SIDS, bValue))
  179. {
  180. m_spGroup->MigrateSIDs = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  181. }
  182. if (mapParams.GetValue(SWITCH_UPDATE_GROUP_RIGHTS, bValue))
  183. {
  184. m_spGroup->UpdateGroupRights = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  185. }
  186. if (mapParams.GetValue(SWITCH_UPDATE_PREVIOUSLY_MIGRATED_OBJECTS, bValue))
  187. {
  188. m_spGroup->UpdatePreviouslyMigratedObjects = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  189. }
  190. if (mapParams.GetValue(SWITCH_FIX_GROUP_MEMBERSHIP, bValue))
  191. {
  192. m_spGroup->FixGroupMembership = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  193. }
  194. if (mapParams.GetValue(SWITCH_MIGRATE_MEMBERS, bValue))
  195. {
  196. m_spGroup->MigrateMembers = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  197. }
  198. if (mapParams.GetValue(SWITCH_DISABLE_OPTION, lValue))
  199. {
  200. m_spGroup->DisableOption = lValue;
  201. }
  202. if (mapParams.GetValue(SWITCH_SOURCE_EXPIRATION, lValue))
  203. {
  204. m_spGroup->SourceExpiration = lValue;
  205. }
  206. if (mapParams.GetValue(SWITCH_TRANSLATE_ROAMING_PROFILE, bValue))
  207. {
  208. m_spGroup->TranslateRoamingProfile = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  209. }
  210. _variant_t vntExcludeNames;
  211. if (!mapParams.GetValues(SWITCH_EXCLUDE_NAME, vntExcludeNames))
  212. {
  213. _bstr_t strExcludeFile;
  214. if (mapParams.GetValue(SWITCH_EXCLUDE_FILE, strExcludeFile))
  215. {
  216. vntExcludeNames = strExcludeFile;
  217. }
  218. }
  219. _variant_t vntIncludeNames;
  220. _bstr_t strIncludeFile;
  221. long lIncludeOption;
  222. if (mapParams.GetValues(SWITCH_INCLUDE_NAME, vntIncludeNames))
  223. {
  224. AdmtCheckError(m_spGroup->raw_Migrate(admtData, vntIncludeNames, vntExcludeNames));
  225. }
  226. else if (mapParams.GetValue(SWITCH_INCLUDE_FILE, strIncludeFile))
  227. {
  228. AdmtCheckError(m_spGroup->raw_Migrate(admtFile, _variant_t(strIncludeFile), vntExcludeNames));
  229. }
  230. else if (mapParams.GetValue(SWITCH_INCLUDE_DOMAIN, lIncludeOption))
  231. {
  232. AdmtCheckError(m_spGroup->raw_Migrate(admtDomain | lIncludeOption, _variant_t(), vntExcludeNames));
  233. }
  234. else
  235. {
  236. ThrowError(E_INVALIDARG, IDS_E_NO_INCLUDE_OPTION_SPECIFIED);
  237. }
  238. }
  239. //---------------------------------------------------------------------------
  240. // Computer Migration Class
  241. //---------------------------------------------------------------------------
  242. void CComputerMigration::Initialize(CParameterMap& mapParams)
  243. {
  244. bool bValue;
  245. long lValue;
  246. if (mapParams.GetValue(SWITCH_TRANSLATION_OPTION, lValue))
  247. {
  248. m_spComputer->TranslationOption = lValue;
  249. }
  250. if (mapParams.GetValue(SWITCH_TRANSLATE_FILES_AND_FOLDERS, bValue))
  251. {
  252. m_spComputer->TranslateFilesAndFolders = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  253. }
  254. if (mapParams.GetValue(SWITCH_TRANSLATE_LOCAL_GROUPS, bValue))
  255. {
  256. m_spComputer->TranslateLocalGroups = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  257. }
  258. if (mapParams.GetValue(SWITCH_TRANSLATE_PRINTERS, bValue))
  259. {
  260. m_spComputer->TranslatePrinters = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  261. }
  262. if (mapParams.GetValue(SWITCH_TRANSLATE_REGISTRY, bValue))
  263. {
  264. m_spComputer->TranslateRegistry = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  265. }
  266. if (mapParams.GetValue(SWITCH_TRANSLATE_SHARES, bValue))
  267. {
  268. m_spComputer->TranslateShares = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  269. }
  270. if (mapParams.GetValue(SWITCH_TRANSLATE_USER_PROFILES, bValue))
  271. {
  272. m_spComputer->TranslateUserProfiles = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  273. }
  274. if (mapParams.GetValue(SWITCH_TRANSLATE_USER_RIGHTS, bValue))
  275. {
  276. m_spComputer->TranslateUserRights = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  277. }
  278. if (mapParams.GetValue(SWITCH_RESTART_DELAY, lValue))
  279. {
  280. m_spComputer->RestartDelay = lValue;
  281. }
  282. _variant_t vntExcludeNames;
  283. if (!mapParams.GetValues(SWITCH_EXCLUDE_NAME, vntExcludeNames))
  284. {
  285. _bstr_t strExcludeFile;
  286. if (mapParams.GetValue(SWITCH_EXCLUDE_FILE, strExcludeFile))
  287. {
  288. vntExcludeNames = strExcludeFile;
  289. }
  290. }
  291. _variant_t vntIncludeNames;
  292. _bstr_t strIncludeFile;
  293. long lIncludeOption;
  294. if (mapParams.GetValues(SWITCH_INCLUDE_NAME, vntIncludeNames))
  295. {
  296. AdmtCheckError(m_spComputer->raw_Migrate(admtData, vntIncludeNames, vntExcludeNames));
  297. }
  298. else if (mapParams.GetValue(SWITCH_INCLUDE_FILE, strIncludeFile))
  299. {
  300. AdmtCheckError(m_spComputer->raw_Migrate(admtFile, _variant_t(strIncludeFile), vntExcludeNames));
  301. }
  302. else if (mapParams.GetValue(SWITCH_INCLUDE_DOMAIN, lIncludeOption))
  303. {
  304. AdmtCheckError(m_spComputer->raw_Migrate(admtDomain | lIncludeOption, _variant_t(), vntExcludeNames));
  305. }
  306. else
  307. {
  308. ThrowError(E_INVALIDARG, IDS_E_NO_INCLUDE_OPTION_SPECIFIED);
  309. }
  310. }
  311. //---------------------------------------------------------------------------
  312. // Security Translation Class
  313. //---------------------------------------------------------------------------
  314. void CSecurityTranslation::Initialize(CParameterMap& mapParams)
  315. {
  316. bool bValue;
  317. long lValue;
  318. _bstr_t strValue;
  319. if (mapParams.GetValue(SWITCH_TRANSLATION_OPTION, lValue))
  320. {
  321. m_spSecurity->TranslationOption = lValue;
  322. }
  323. if (mapParams.GetValue(SWITCH_TRANSLATE_FILES_AND_FOLDERS, bValue))
  324. {
  325. m_spSecurity->TranslateFilesAndFolders = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  326. }
  327. if (mapParams.GetValue(SWITCH_TRANSLATE_LOCAL_GROUPS, bValue))
  328. {
  329. m_spSecurity->TranslateLocalGroups = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  330. }
  331. if (mapParams.GetValue(SWITCH_TRANSLATE_PRINTERS, bValue))
  332. {
  333. m_spSecurity->TranslatePrinters = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  334. }
  335. if (mapParams.GetValue(SWITCH_TRANSLATE_REGISTRY, bValue))
  336. {
  337. m_spSecurity->TranslateRegistry = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  338. }
  339. if (mapParams.GetValue(SWITCH_TRANSLATE_SHARES, bValue))
  340. {
  341. m_spSecurity->TranslateShares = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  342. }
  343. if (mapParams.GetValue(SWITCH_TRANSLATE_USER_PROFILES, bValue))
  344. {
  345. m_spSecurity->TranslateUserProfiles = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  346. }
  347. if (mapParams.GetValue(SWITCH_TRANSLATE_USER_RIGHTS, bValue))
  348. {
  349. m_spSecurity->TranslateUserRights = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  350. }
  351. if (mapParams.GetValue(SWITCH_SID_MAPPING_FILE, strValue))
  352. {
  353. AdmtCheckError(m_spSecurity->put_SidMappingFile(strValue));
  354. }
  355. _variant_t vntExcludeNames;
  356. if (!mapParams.GetValues(SWITCH_EXCLUDE_NAME, vntExcludeNames))
  357. {
  358. _bstr_t strExcludeFile;
  359. if (mapParams.GetValue(SWITCH_EXCLUDE_FILE, strExcludeFile))
  360. {
  361. vntExcludeNames = strExcludeFile;
  362. }
  363. }
  364. _variant_t vntIncludeNames;
  365. _bstr_t strIncludeFile;
  366. long lIncludeOption;
  367. if (mapParams.GetValues(SWITCH_INCLUDE_NAME, vntIncludeNames))
  368. {
  369. AdmtCheckError(m_spSecurity->raw_Translate(admtData, vntIncludeNames, vntExcludeNames));
  370. }
  371. else if (mapParams.GetValue(SWITCH_INCLUDE_FILE, strIncludeFile))
  372. {
  373. AdmtCheckError(m_spSecurity->raw_Translate(admtFile, _variant_t(strIncludeFile), vntExcludeNames));
  374. }
  375. else if (mapParams.GetValue(SWITCH_INCLUDE_DOMAIN, lIncludeOption))
  376. {
  377. AdmtCheckError(m_spSecurity->raw_Translate(admtDomain | lIncludeOption, _variant_t(), vntExcludeNames));
  378. }
  379. else
  380. {
  381. ThrowError(E_INVALIDARG, IDS_E_NO_INCLUDE_OPTION_SPECIFIED);
  382. }
  383. }
  384. //---------------------------------------------------------------------------
  385. // Service Enumeration Class
  386. //---------------------------------------------------------------------------
  387. void CServiceEnumeration::Initialize(CParameterMap& mapParams)
  388. {
  389. _variant_t vntExcludeNames;
  390. if (!mapParams.GetValues(SWITCH_EXCLUDE_NAME, vntExcludeNames))
  391. {
  392. _bstr_t strExcludeFile;
  393. if (mapParams.GetValue(SWITCH_EXCLUDE_FILE, strExcludeFile))
  394. {
  395. vntExcludeNames = strExcludeFile;
  396. }
  397. }
  398. _variant_t vntIncludeNames;
  399. _bstr_t strIncludeFile;
  400. long lIncludeOption;
  401. if (mapParams.GetValues(SWITCH_INCLUDE_NAME, vntIncludeNames))
  402. {
  403. AdmtCheckError(m_spService->raw_Enumerate(admtData, vntIncludeNames, vntExcludeNames));
  404. }
  405. else if (mapParams.GetValue(SWITCH_INCLUDE_FILE, strIncludeFile))
  406. {
  407. AdmtCheckError(m_spService->raw_Enumerate(admtFile, _variant_t(strIncludeFile), vntExcludeNames));
  408. }
  409. else if (mapParams.GetValue(SWITCH_INCLUDE_DOMAIN, lIncludeOption))
  410. {
  411. AdmtCheckError(m_spService->raw_Enumerate(admtDomain | lIncludeOption, _variant_t(), vntExcludeNames));
  412. }
  413. else
  414. {
  415. ThrowError(E_INVALIDARG, IDS_E_NO_INCLUDE_OPTION_SPECIFIED);
  416. }
  417. }
  418. //---------------------------------------------------------------------------
  419. // Report Generation Class
  420. //---------------------------------------------------------------------------
  421. void CReportGeneration::Initialize(CParameterMap& mapParams)
  422. {
  423. long lValue;
  424. _bstr_t strValue;
  425. if (mapParams.GetValue(SWITCH_REPORT_TYPE, lValue))
  426. {
  427. m_spReport->Type = lValue;
  428. }
  429. if (mapParams.GetValue(SWITCH_REPORT_FOLDER, strValue))
  430. {
  431. AdmtCheckError(m_spReport->put_Folder(strValue));
  432. }
  433. _variant_t vntExcludeNames;
  434. if (!mapParams.GetValues(SWITCH_EXCLUDE_NAME, vntExcludeNames))
  435. {
  436. _bstr_t strExcludeFile;
  437. if (mapParams.GetValue(SWITCH_EXCLUDE_FILE, strExcludeFile))
  438. {
  439. vntExcludeNames = strExcludeFile;
  440. }
  441. }
  442. _variant_t vntIncludeNames;
  443. _bstr_t strIncludeFile;
  444. long lIncludeOption;
  445. if (mapParams.GetValues(SWITCH_INCLUDE_NAME, vntIncludeNames))
  446. {
  447. AdmtCheckError(m_spReport->raw_Generate(admtData, vntIncludeNames, vntExcludeNames));
  448. }
  449. else if (mapParams.GetValue(SWITCH_INCLUDE_FILE, strIncludeFile))
  450. {
  451. AdmtCheckError(m_spReport->raw_Generate(admtFile, _variant_t(strIncludeFile), vntExcludeNames));
  452. }
  453. else if (mapParams.GetValue(SWITCH_INCLUDE_DOMAIN, lIncludeOption))
  454. {
  455. AdmtCheckError(m_spReport->raw_Generate(admtDomain | lIncludeOption, _variant_t(), vntExcludeNames));
  456. }
  457. else
  458. {
  459. AdmtCheckError(m_spReport->raw_Generate(admtNone, _variant_t(), _variant_t()));
  460. }
  461. }