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.

612 lines
15 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_INETORGPERSON_PROPERTIES_TO_EXCLUDE, strValue))
  87. {
  88. m_spMigration->InetOrgPersonPropertiesToExclude = strValue;
  89. }
  90. if (mapParams.GetValue(SWITCH_GROUP_PROPERTIES_TO_EXCLUDE, strValue))
  91. {
  92. m_spMigration->GroupPropertiesToExclude = strValue;
  93. }
  94. if (mapParams.GetValue(SWITCH_COMPUTER_PROPERTIES_TO_EXCLUDE, strValue))
  95. {
  96. m_spMigration->ComputerPropertiesToExclude = strValue;
  97. }
  98. }
  99. //---------------------------------------------------------------------------
  100. // User Migration Class
  101. //---------------------------------------------------------------------------
  102. void CUserMigration::Initialize(CParameterMap& mapParams)
  103. {
  104. bool bValue;
  105. long lValue;
  106. if (mapParams.GetValue(SWITCH_DISABLE_OPTION, lValue))
  107. {
  108. m_spUser->DisableOption = lValue;
  109. }
  110. if (mapParams.GetValue(SWITCH_SOURCE_EXPIRATION, lValue))
  111. {
  112. m_spUser->SourceExpiration = lValue;
  113. }
  114. if (mapParams.GetValue(SWITCH_MIGRATE_SIDS, bValue))
  115. {
  116. m_spUser->MigrateSIDs = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  117. }
  118. if (mapParams.GetValue(SWITCH_TRANSLATE_ROAMING_PROFILE, bValue))
  119. {
  120. m_spUser->TranslateRoamingProfile = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  121. }
  122. if (mapParams.GetValue(SWITCH_UPDATE_USER_RIGHTS, bValue))
  123. {
  124. m_spUser->UpdateUserRights = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  125. }
  126. if (mapParams.GetValue(SWITCH_MIGRATE_GROUPS, bValue))
  127. {
  128. m_spUser->MigrateGroups = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  129. }
  130. if (mapParams.GetValue(SWITCH_UPDATE_PREVIOUSLY_MIGRATED_OBJECTS, bValue))
  131. {
  132. m_spUser->UpdatePreviouslyMigratedObjects = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  133. }
  134. if (mapParams.GetValue(SWITCH_FIX_GROUP_MEMBERSHIP, bValue))
  135. {
  136. m_spUser->FixGroupMembership = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  137. }
  138. if (mapParams.GetValue(SWITCH_MIGRATE_SERVICE_ACCOUNTS, bValue))
  139. {
  140. m_spUser->MigrateServiceAccounts = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  141. }
  142. if (mapParams.GetValue(SWITCH_SOURCE_EXPIRATION, lValue))
  143. {
  144. m_spUser->SourceExpiration = lValue;
  145. }
  146. _variant_t vntExcludeNames;
  147. if (!mapParams.GetValues(SWITCH_EXCLUDE_NAME, vntExcludeNames))
  148. {
  149. _bstr_t strExcludeFile;
  150. if (mapParams.GetValue(SWITCH_EXCLUDE_FILE, strExcludeFile))
  151. {
  152. vntExcludeNames = strExcludeFile;
  153. }
  154. }
  155. StartMonitoring();
  156. _variant_t vntIncludeNames;
  157. _bstr_t strIncludeFile;
  158. long lIncludeOption;
  159. if (mapParams.GetValues(SWITCH_INCLUDE_NAME, vntIncludeNames))
  160. {
  161. m_spUser->raw_Migrate(admtData, vntIncludeNames, vntExcludeNames);
  162. }
  163. else if (mapParams.GetValue(SWITCH_INCLUDE_FILE, strIncludeFile))
  164. {
  165. m_spUser->raw_Migrate(admtFile, _variant_t(strIncludeFile), vntExcludeNames);
  166. }
  167. else if (mapParams.GetValue(SWITCH_INCLUDE_DOMAIN, lIncludeOption))
  168. {
  169. m_spUser->raw_Migrate(admtDomain | lIncludeOption, _variant_t(), vntExcludeNames);
  170. }
  171. else
  172. {
  173. ThrowError(E_INVALIDARG, IDS_E_NO_INCLUDE_OPTION_SPECIFIED);
  174. }
  175. StopMonitoring();
  176. }
  177. //---------------------------------------------------------------------------
  178. // Group Migration Class
  179. //---------------------------------------------------------------------------
  180. void CGroupMigration::Initialize(CParameterMap& mapParams)
  181. {
  182. bool bValue;
  183. long lValue;
  184. if (mapParams.GetValue(SWITCH_MIGRATE_SIDS, bValue))
  185. {
  186. m_spGroup->MigrateSIDs = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  187. }
  188. if (mapParams.GetValue(SWITCH_UPDATE_GROUP_RIGHTS, bValue))
  189. {
  190. m_spGroup->UpdateGroupRights = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  191. }
  192. if (mapParams.GetValue(SWITCH_UPDATE_PREVIOUSLY_MIGRATED_OBJECTS, bValue))
  193. {
  194. m_spGroup->UpdatePreviouslyMigratedObjects = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  195. }
  196. if (mapParams.GetValue(SWITCH_FIX_GROUP_MEMBERSHIP, bValue))
  197. {
  198. m_spGroup->FixGroupMembership = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  199. }
  200. if (mapParams.GetValue(SWITCH_MIGRATE_MEMBERS, bValue))
  201. {
  202. m_spGroup->MigrateMembers = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  203. }
  204. if (mapParams.GetValue(SWITCH_DISABLE_OPTION, lValue))
  205. {
  206. m_spGroup->DisableOption = lValue;
  207. }
  208. if (mapParams.GetValue(SWITCH_SOURCE_EXPIRATION, lValue))
  209. {
  210. m_spGroup->SourceExpiration = lValue;
  211. }
  212. if (mapParams.GetValue(SWITCH_TRANSLATE_ROAMING_PROFILE, bValue))
  213. {
  214. m_spGroup->TranslateRoamingProfile = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  215. }
  216. _variant_t vntExcludeNames;
  217. if (!mapParams.GetValues(SWITCH_EXCLUDE_NAME, vntExcludeNames))
  218. {
  219. _bstr_t strExcludeFile;
  220. if (mapParams.GetValue(SWITCH_EXCLUDE_FILE, strExcludeFile))
  221. {
  222. vntExcludeNames = strExcludeFile;
  223. }
  224. }
  225. StartMonitoring();
  226. _variant_t vntIncludeNames;
  227. _bstr_t strIncludeFile;
  228. long lIncludeOption;
  229. if (mapParams.GetValues(SWITCH_INCLUDE_NAME, vntIncludeNames))
  230. {
  231. m_spGroup->raw_Migrate(admtData, vntIncludeNames, vntExcludeNames);
  232. }
  233. else if (mapParams.GetValue(SWITCH_INCLUDE_FILE, strIncludeFile))
  234. {
  235. m_spGroup->raw_Migrate(admtFile, _variant_t(strIncludeFile), vntExcludeNames);
  236. }
  237. else if (mapParams.GetValue(SWITCH_INCLUDE_DOMAIN, lIncludeOption))
  238. {
  239. m_spGroup->raw_Migrate(admtDomain | lIncludeOption, _variant_t(), vntExcludeNames);
  240. }
  241. else
  242. {
  243. ThrowError(E_INVALIDARG, IDS_E_NO_INCLUDE_OPTION_SPECIFIED);
  244. }
  245. StopMonitoring();
  246. }
  247. //---------------------------------------------------------------------------
  248. // Computer Migration Class
  249. //---------------------------------------------------------------------------
  250. void CComputerMigration::Initialize(CParameterMap& mapParams)
  251. {
  252. bool bValue;
  253. long lValue;
  254. if (mapParams.GetValue(SWITCH_TRANSLATION_OPTION, lValue))
  255. {
  256. m_spComputer->TranslationOption = lValue;
  257. }
  258. if (mapParams.GetValue(SWITCH_TRANSLATE_FILES_AND_FOLDERS, bValue))
  259. {
  260. m_spComputer->TranslateFilesAndFolders = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  261. }
  262. if (mapParams.GetValue(SWITCH_TRANSLATE_LOCAL_GROUPS, bValue))
  263. {
  264. m_spComputer->TranslateLocalGroups = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  265. }
  266. if (mapParams.GetValue(SWITCH_TRANSLATE_PRINTERS, bValue))
  267. {
  268. m_spComputer->TranslatePrinters = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  269. }
  270. if (mapParams.GetValue(SWITCH_TRANSLATE_REGISTRY, bValue))
  271. {
  272. m_spComputer->TranslateRegistry = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  273. }
  274. if (mapParams.GetValue(SWITCH_TRANSLATE_SHARES, bValue))
  275. {
  276. m_spComputer->TranslateShares = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  277. }
  278. if (mapParams.GetValue(SWITCH_TRANSLATE_USER_PROFILES, bValue))
  279. {
  280. m_spComputer->TranslateUserProfiles = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  281. }
  282. if (mapParams.GetValue(SWITCH_TRANSLATE_USER_RIGHTS, bValue))
  283. {
  284. m_spComputer->TranslateUserRights = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  285. }
  286. if (mapParams.GetValue(SWITCH_RESTART_DELAY, lValue))
  287. {
  288. m_spComputer->RestartDelay = lValue;
  289. }
  290. _variant_t vntExcludeNames;
  291. if (!mapParams.GetValues(SWITCH_EXCLUDE_NAME, vntExcludeNames))
  292. {
  293. _bstr_t strExcludeFile;
  294. if (mapParams.GetValue(SWITCH_EXCLUDE_FILE, strExcludeFile))
  295. {
  296. vntExcludeNames = strExcludeFile;
  297. }
  298. }
  299. StartMonitoring();
  300. _variant_t vntIncludeNames;
  301. _bstr_t strIncludeFile;
  302. long lIncludeOption;
  303. if (mapParams.GetValues(SWITCH_INCLUDE_NAME, vntIncludeNames))
  304. {
  305. m_spComputer->raw_Migrate(admtData, vntIncludeNames, vntExcludeNames);
  306. }
  307. else if (mapParams.GetValue(SWITCH_INCLUDE_FILE, strIncludeFile))
  308. {
  309. m_spComputer->raw_Migrate(admtFile, _variant_t(strIncludeFile), vntExcludeNames);
  310. }
  311. else if (mapParams.GetValue(SWITCH_INCLUDE_DOMAIN, lIncludeOption))
  312. {
  313. m_spComputer->raw_Migrate(admtDomain | lIncludeOption, _variant_t(), vntExcludeNames);
  314. }
  315. else
  316. {
  317. ThrowError(E_INVALIDARG, IDS_E_NO_INCLUDE_OPTION_SPECIFIED);
  318. }
  319. StopMonitoring();
  320. }
  321. //---------------------------------------------------------------------------
  322. // Security Translation Class
  323. //---------------------------------------------------------------------------
  324. void CSecurityTranslation::Initialize(CParameterMap& mapParams)
  325. {
  326. bool bValue;
  327. long lValue;
  328. _bstr_t strValue;
  329. if (mapParams.GetValue(SWITCH_TRANSLATION_OPTION, lValue))
  330. {
  331. m_spSecurity->TranslationOption = lValue;
  332. }
  333. if (mapParams.GetValue(SWITCH_TRANSLATE_FILES_AND_FOLDERS, bValue))
  334. {
  335. m_spSecurity->TranslateFilesAndFolders = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  336. }
  337. if (mapParams.GetValue(SWITCH_TRANSLATE_LOCAL_GROUPS, bValue))
  338. {
  339. m_spSecurity->TranslateLocalGroups = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  340. }
  341. if (mapParams.GetValue(SWITCH_TRANSLATE_PRINTERS, bValue))
  342. {
  343. m_spSecurity->TranslatePrinters = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  344. }
  345. if (mapParams.GetValue(SWITCH_TRANSLATE_REGISTRY, bValue))
  346. {
  347. m_spSecurity->TranslateRegistry = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  348. }
  349. if (mapParams.GetValue(SWITCH_TRANSLATE_SHARES, bValue))
  350. {
  351. m_spSecurity->TranslateShares = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  352. }
  353. if (mapParams.GetValue(SWITCH_TRANSLATE_USER_PROFILES, bValue))
  354. {
  355. m_spSecurity->TranslateUserProfiles = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  356. }
  357. if (mapParams.GetValue(SWITCH_TRANSLATE_USER_RIGHTS, bValue))
  358. {
  359. m_spSecurity->TranslateUserRights = bValue ? VARIANT_TRUE : VARIANT_FALSE;
  360. }
  361. if (mapParams.GetValue(SWITCH_SID_MAPPING_FILE, strValue))
  362. {
  363. AdmtCheckError(m_spSecurity->put_SidMappingFile(strValue));
  364. }
  365. _variant_t vntExcludeNames;
  366. if (!mapParams.GetValues(SWITCH_EXCLUDE_NAME, vntExcludeNames))
  367. {
  368. _bstr_t strExcludeFile;
  369. if (mapParams.GetValue(SWITCH_EXCLUDE_FILE, strExcludeFile))
  370. {
  371. vntExcludeNames = strExcludeFile;
  372. }
  373. }
  374. StartMonitoring();
  375. _variant_t vntIncludeNames;
  376. _bstr_t strIncludeFile;
  377. long lIncludeOption;
  378. if (mapParams.GetValues(SWITCH_INCLUDE_NAME, vntIncludeNames))
  379. {
  380. m_spSecurity->raw_Translate(admtData, vntIncludeNames, vntExcludeNames);
  381. }
  382. else if (mapParams.GetValue(SWITCH_INCLUDE_FILE, strIncludeFile))
  383. {
  384. m_spSecurity->raw_Translate(admtFile, _variant_t(strIncludeFile), vntExcludeNames);
  385. }
  386. else if (mapParams.GetValue(SWITCH_INCLUDE_DOMAIN, lIncludeOption))
  387. {
  388. m_spSecurity->raw_Translate(admtDomain | lIncludeOption, _variant_t(), vntExcludeNames);
  389. }
  390. else
  391. {
  392. ThrowError(E_INVALIDARG, IDS_E_NO_INCLUDE_OPTION_SPECIFIED);
  393. }
  394. StopMonitoring();
  395. }
  396. //---------------------------------------------------------------------------
  397. // Service Enumeration Class
  398. //---------------------------------------------------------------------------
  399. void CServiceEnumeration::Initialize(CParameterMap& mapParams)
  400. {
  401. _variant_t vntExcludeNames;
  402. if (!mapParams.GetValues(SWITCH_EXCLUDE_NAME, vntExcludeNames))
  403. {
  404. _bstr_t strExcludeFile;
  405. if (mapParams.GetValue(SWITCH_EXCLUDE_FILE, strExcludeFile))
  406. {
  407. vntExcludeNames = strExcludeFile;
  408. }
  409. }
  410. StartMonitoring();
  411. _variant_t vntIncludeNames;
  412. _bstr_t strIncludeFile;
  413. long lIncludeOption;
  414. if (mapParams.GetValues(SWITCH_INCLUDE_NAME, vntIncludeNames))
  415. {
  416. m_spService->raw_Enumerate(admtData, vntIncludeNames, vntExcludeNames);
  417. }
  418. else if (mapParams.GetValue(SWITCH_INCLUDE_FILE, strIncludeFile))
  419. {
  420. m_spService->raw_Enumerate(admtFile, _variant_t(strIncludeFile), vntExcludeNames);
  421. }
  422. else if (mapParams.GetValue(SWITCH_INCLUDE_DOMAIN, lIncludeOption))
  423. {
  424. m_spService->raw_Enumerate(admtDomain | lIncludeOption, _variant_t(), vntExcludeNames);
  425. }
  426. else
  427. {
  428. ThrowError(E_INVALIDARG, IDS_E_NO_INCLUDE_OPTION_SPECIFIED);
  429. }
  430. StopMonitoring();
  431. }
  432. //---------------------------------------------------------------------------
  433. // Report Generation Class
  434. //---------------------------------------------------------------------------
  435. void CReportGeneration::Initialize(CParameterMap& mapParams)
  436. {
  437. long lValue;
  438. _bstr_t strValue;
  439. if (mapParams.GetValue(SWITCH_REPORT_TYPE, lValue))
  440. {
  441. m_spReport->Type = lValue;
  442. }
  443. if (mapParams.GetValue(SWITCH_REPORT_FOLDER, strValue))
  444. {
  445. AdmtCheckError(m_spReport->put_Folder(strValue));
  446. }
  447. _variant_t vntExcludeNames;
  448. if (!mapParams.GetValues(SWITCH_EXCLUDE_NAME, vntExcludeNames))
  449. {
  450. _bstr_t strExcludeFile;
  451. if (mapParams.GetValue(SWITCH_EXCLUDE_FILE, strExcludeFile))
  452. {
  453. vntExcludeNames = strExcludeFile;
  454. }
  455. }
  456. StartMonitoring();
  457. _variant_t vntIncludeNames;
  458. _bstr_t strIncludeFile;
  459. long lIncludeOption;
  460. if (mapParams.GetValues(SWITCH_INCLUDE_NAME, vntIncludeNames))
  461. {
  462. m_spReport->raw_Generate(admtData, vntIncludeNames, vntExcludeNames);
  463. }
  464. else if (mapParams.GetValue(SWITCH_INCLUDE_FILE, strIncludeFile))
  465. {
  466. m_spReport->raw_Generate(admtFile, _variant_t(strIncludeFile), vntExcludeNames);
  467. }
  468. else if (mapParams.GetValue(SWITCH_INCLUDE_DOMAIN, lIncludeOption))
  469. {
  470. m_spReport->raw_Generate(admtDomain | lIncludeOption, _variant_t(), vntExcludeNames);
  471. }
  472. else
  473. {
  474. m_spReport->raw_Generate(admtNone, _variant_t(), _variant_t());
  475. }
  476. StopMonitoring();
  477. }