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.

1150 lines
24 KiB

  1. #include "StdAfx.h"
  2. #include "ADMTScript.h"
  3. #include "Migration.h"
  4. #include "Error.h"
  5. #include "UserMigration.h"
  6. #include "GroupMigration.h"
  7. #include "ComputerMigration.h"
  8. #include "SecurityTranslation.h"
  9. #include "ServiceAccountEnumeration.h"
  10. #include "ReportGeneration.h"
  11. #include "RegistryHelper.h"
  12. #include <LM.h>
  13. #include <DsGetDC.h>
  14. #import <DBMgr.tlb> no_namespace
  15. #import <UpdateMOT.tlb> no_namespace
  16. using namespace _com_util;
  17. #ifndef tstring
  18. #include <string>
  19. typedef std::basic_string<_TCHAR> tstring;
  20. #endif
  21. //---------------------------------------------------------------------------
  22. // CMigration
  23. //---------------------------------------------------------------------------
  24. // Construction -------------------------------------------------------------
  25. // Constructor
  26. CMigration::CMigration() :
  27. m_bTestMigration(false),
  28. m_bIntraForest(false),
  29. m_lRenameOption(admtDoNotRename),
  30. m_lPasswordOption(admtComplexPassword),
  31. m_lConflictOptions(admtIgnoreConflicting)
  32. {
  33. }
  34. // Destructor
  35. CMigration::~CMigration()
  36. {
  37. }
  38. HRESULT CMigration::FinalConstruct()
  39. {
  40. HRESULT hr = S_OK;
  41. try
  42. {
  43. DWORD lRet = IsAdminLocal();
  44. if (lRet != ERROR_SUCCESS)
  45. AdmtThrowError(GUID_NULL, GUID_NULL, HRESULT_FROM_WIN32(lRet), IDS_E_LOCAL_ADMIN_CHECK_FAILED);
  46. lRet = MoveRegistry();
  47. if (lRet != ERROR_SUCCESS)
  48. AdmtThrowError(GUID_NULL, GUID_NULL, HRESULT_FROM_WIN32(lRet), IDS_E_UPDATE_REGISTRY_FAILED);
  49. UpdateDatabase();
  50. }
  51. catch (_com_error& ce)
  52. {
  53. hr = AdmtSetError(GUID_NULL, GUID_NULL, ce);
  54. }
  55. return hr;
  56. }
  57. void CMigration::FinalRelease()
  58. {
  59. }
  60. // IMigration Implementation ------------------------------------------------
  61. // TestMigration Property
  62. STDMETHODIMP CMigration::put_TestMigration(VARIANT_BOOL bTest)
  63. {
  64. m_bTestMigration = bTest ? true : false;
  65. return S_OK;
  66. }
  67. STDMETHODIMP CMigration::get_TestMigration(VARIANT_BOOL* pbTest)
  68. {
  69. *pbTest = m_bTestMigration ? VARIANT_TRUE : VARIANT_FALSE;
  70. return S_OK;
  71. }
  72. // IntraForest Property
  73. STDMETHODIMP CMigration::put_IntraForest(VARIANT_BOOL bIntraForest)
  74. {
  75. m_bIntraForest = bIntraForest ? true : false;
  76. return S_OK;
  77. }
  78. STDMETHODIMP CMigration::get_IntraForest(VARIANT_BOOL* pbIntraForest)
  79. {
  80. *pbIntraForest = m_bIntraForest ? VARIANT_TRUE : VARIANT_FALSE;
  81. return S_OK;
  82. }
  83. // SourceDomain Property
  84. STDMETHODIMP CMigration::put_SourceDomain(BSTR bstrDomain)
  85. {
  86. HRESULT hr = S_OK;
  87. try
  88. {
  89. m_bstrSourceDomain = bstrDomain;
  90. }
  91. catch (_com_error& ce)
  92. {
  93. hr = AdmtSetError(CLSID_Migration, IID_IMigration, ce);
  94. }
  95. catch (...)
  96. {
  97. hr = AdmtSetError(CLSID_Migration, IID_IMigration, E_FAIL);
  98. }
  99. return hr;
  100. }
  101. STDMETHODIMP CMigration::get_SourceDomain(BSTR* pbstrDomain)
  102. {
  103. HRESULT hr = S_OK;
  104. try
  105. {
  106. *pbstrDomain = m_bstrSourceDomain.copy();
  107. }
  108. catch (_com_error& ce)
  109. {
  110. hr = AdmtSetError(CLSID_Migration, IID_IMigration, ce);
  111. }
  112. catch (...)
  113. {
  114. hr = AdmtSetError(CLSID_Migration, IID_IMigration, E_FAIL);
  115. }
  116. return hr;
  117. }
  118. // SourceOu Property
  119. STDMETHODIMP CMigration::put_SourceOu(BSTR bstrOu)
  120. {
  121. HRESULT hr = S_OK;
  122. try
  123. {
  124. m_bstrSourceOu = bstrOu;
  125. }
  126. catch (_com_error& ce)
  127. {
  128. hr = AdmtSetError(CLSID_Migration, IID_IMigration, ce);
  129. }
  130. catch (...)
  131. {
  132. hr = AdmtSetError(CLSID_Migration, IID_IMigration, E_FAIL);
  133. }
  134. return hr;
  135. }
  136. STDMETHODIMP CMigration::get_SourceOu(BSTR* pbstrOu)
  137. {
  138. HRESULT hr = S_OK;
  139. try
  140. {
  141. *pbstrOu = m_bstrSourceOu.copy();
  142. }
  143. catch (_com_error& ce)
  144. {
  145. hr = AdmtSetError(CLSID_Migration, IID_IMigration, ce);
  146. }
  147. catch (...)
  148. {
  149. hr = AdmtSetError(CLSID_Migration, IID_IMigration, E_FAIL);
  150. }
  151. return hr;
  152. }
  153. // TargetDomain Property
  154. STDMETHODIMP CMigration::put_TargetDomain(BSTR bstrDomain)
  155. {
  156. HRESULT hr = S_OK;
  157. try
  158. {
  159. m_bstrTargetDomain = bstrDomain;
  160. }
  161. catch (_com_error& ce)
  162. {
  163. hr = AdmtSetError(CLSID_Migration, IID_IMigration, ce);
  164. }
  165. catch (...)
  166. {
  167. hr = AdmtSetError(CLSID_Migration, IID_IMigration, E_FAIL);
  168. }
  169. return hr;
  170. }
  171. STDMETHODIMP CMigration::get_TargetDomain(BSTR* pbstrDomain)
  172. {
  173. HRESULT hr = S_OK;
  174. try
  175. {
  176. *pbstrDomain = m_bstrTargetDomain.copy();
  177. }
  178. catch (_com_error& ce)
  179. {
  180. hr = AdmtSetError(CLSID_Migration, IID_IMigration, ce);
  181. }
  182. catch (...)
  183. {
  184. hr = AdmtSetError(CLSID_Migration, IID_IMigration, E_FAIL);
  185. }
  186. return hr;
  187. }
  188. // TargetOu Property
  189. STDMETHODIMP CMigration::put_TargetOu(BSTR bstrOu)
  190. {
  191. HRESULT hr = S_OK;
  192. try
  193. {
  194. m_bstrTargetOu = bstrOu;
  195. }
  196. catch (_com_error& ce)
  197. {
  198. hr = AdmtSetError(CLSID_Migration, IID_IMigration, ce);
  199. }
  200. catch (...)
  201. {
  202. hr = AdmtSetError(CLSID_Migration, IID_IMigration, E_FAIL);
  203. }
  204. return hr;
  205. }
  206. STDMETHODIMP CMigration::get_TargetOu(BSTR* pbstrOu)
  207. {
  208. HRESULT hr = S_OK;
  209. try
  210. {
  211. *pbstrOu = m_bstrTargetOu.copy();
  212. }
  213. catch (_com_error& ce)
  214. {
  215. hr = AdmtSetError(CLSID_Migration, IID_IMigration, ce);
  216. }
  217. catch (...)
  218. {
  219. hr = AdmtSetError(CLSID_Migration, IID_IMigration, E_FAIL);
  220. }
  221. return hr;
  222. }
  223. // RenameOption Property
  224. STDMETHODIMP CMigration::put_RenameOption(long lOption)
  225. {
  226. HRESULT hr = S_OK;
  227. if ((lOption >= admtDoNotRename) && (lOption <= admtRenameWithSuffix))
  228. {
  229. m_lRenameOption = lOption;
  230. }
  231. else
  232. {
  233. hr = AdmtSetError(CLSID_Migration, IID_IMigration, E_INVALIDARG, IDS_E_RENAME_OPTION_INVALID);
  234. }
  235. return hr;
  236. }
  237. STDMETHODIMP CMigration::get_RenameOption(long* plOption)
  238. {
  239. *plOption = m_lRenameOption;
  240. return S_OK;
  241. }
  242. // RenamePrefixOrSuffix Property
  243. STDMETHODIMP CMigration::put_RenamePrefixOrSuffix(BSTR bstrPrefixOrSuffix)
  244. {
  245. HRESULT hr = S_OK;
  246. try
  247. {
  248. m_bstrRenamePrefixOrSuffix = bstrPrefixOrSuffix;
  249. }
  250. catch (_com_error& ce)
  251. {
  252. hr = AdmtSetError(CLSID_Migration, IID_IMigration, ce);
  253. }
  254. catch (...)
  255. {
  256. hr = AdmtSetError(CLSID_Migration, IID_IMigration, E_FAIL);
  257. }
  258. return hr;
  259. }
  260. STDMETHODIMP CMigration::get_RenamePrefixOrSuffix(BSTR* pbstrPrefixOrSuffix)
  261. {
  262. HRESULT hr = S_OK;
  263. try
  264. {
  265. *pbstrPrefixOrSuffix = m_bstrRenamePrefixOrSuffix.copy();
  266. }
  267. catch (_com_error& ce)
  268. {
  269. hr = AdmtSetError(CLSID_Migration, IID_IMigration, ce);
  270. }
  271. catch (...)
  272. {
  273. hr = AdmtSetError(CLSID_Migration, IID_IMigration, E_FAIL);
  274. }
  275. return hr;
  276. }
  277. // PasswordOption Property
  278. STDMETHODIMP CMigration::put_PasswordOption(long lOption)
  279. {
  280. HRESULT hr = S_OK;
  281. if ((lOption >= admtPasswordFromName) && (lOption <= admtCopyPassword))
  282. {
  283. m_lPasswordOption = lOption;
  284. }
  285. else
  286. {
  287. hr = AdmtSetError(CLSID_Migration, IID_IMigration, E_INVALIDARG, IDS_E_PASSWORD_OPTION_INVALID);
  288. }
  289. return hr;
  290. }
  291. STDMETHODIMP CMigration::get_PasswordOption(long* plOption)
  292. {
  293. *plOption = m_lPasswordOption;
  294. return S_OK;
  295. }
  296. // PasswordServer Property
  297. STDMETHODIMP CMigration::put_PasswordServer(BSTR bstrServer)
  298. {
  299. HRESULT hr = S_OK;
  300. try
  301. {
  302. m_bstrPasswordServer = bstrServer;
  303. }
  304. catch (_com_error& ce)
  305. {
  306. hr = AdmtSetError(CLSID_Migration, IID_IMigration, ce);
  307. }
  308. catch (...)
  309. {
  310. hr = AdmtSetError(CLSID_Migration, IID_IMigration, E_FAIL);
  311. }
  312. return hr;
  313. }
  314. STDMETHODIMP CMigration::get_PasswordServer(BSTR* pbstrServer)
  315. {
  316. HRESULT hr = S_OK;
  317. try
  318. {
  319. *pbstrServer = m_bstrPasswordServer.copy();
  320. }
  321. catch (_com_error& ce)
  322. {
  323. hr = AdmtSetError(CLSID_Migration, IID_IMigration, ce);
  324. }
  325. catch (...)
  326. {
  327. hr = AdmtSetError(CLSID_Migration, IID_IMigration, E_FAIL);
  328. }
  329. return hr;
  330. }
  331. // GetValidDcName Method
  332. //
  333. // Retrieves name of domain controller in the given domain.
  334. _bstr_t CMigration::GetValidDcName(_bstr_t strDcName)
  335. {
  336. _bstr_t strName;
  337. PDOMAIN_CONTROLLER_INFO pdci;
  338. // attempt to retrieve DNS name of domain controller
  339. // Note: requires NT 4.0 SP6a
  340. DWORD dwError = DsGetDcName(strDcName, NULL, NULL, NULL, DS_RETURN_DNS_NAME, &pdci);
  341. // if domain controller not found, attempt to retrieve flat name of domain controller
  342. if (dwError == ERROR_NO_SUCH_DOMAIN)
  343. {
  344. dwError = DsGetDcName(strDcName, NULL, NULL, NULL, DS_RETURN_FLAT_NAME, &pdci);
  345. }
  346. // if domain controller found then save name otherwise generate error
  347. if (dwError == NO_ERROR)
  348. {
  349. // remove double backslash prefix to remain consistent with wizard
  350. strName = pdci->DomainControllerName + 2;
  351. NetApiBufferFree(pdci);
  352. }
  353. else
  354. {
  355. _com_issue_error(HRESULT_FROM_WIN32(dwError));
  356. }
  357. return strName;
  358. }
  359. // PasswordFile Property
  360. STDMETHODIMP CMigration::put_PasswordFile(BSTR bstrPath)
  361. {
  362. HRESULT hr = S_OK;
  363. try
  364. {
  365. _bstr_t strFile = bstrPath;
  366. if (strFile.length() > 0)
  367. {
  368. _TCHAR szPath[_MAX_PATH];
  369. LPTSTR pszFilePart;
  370. DWORD cchPath = GetFullPathName(strFile, _MAX_PATH, szPath, &pszFilePart);
  371. if ((cchPath == 0) || (cchPath >= _MAX_PATH))
  372. {
  373. //
  374. // If GetFullPathName returns 0 then extended error may be found by
  375. // calling GetLastError. If cchPath is greater than or equal to the
  376. // maximum supported path length set error equal to 'The file name
  377. // is too long' (ERROR_BUFFER_OVERFLOW). If GetLastError returns
  378. // ERROR_SUCCESS then set the error to 'The specified path is
  379. // invalid' (ERROR_BAD_PATHNAME).
  380. //
  381. DWORD dwError = (cchPath == 0) ? GetLastError() : ERROR_BUFFER_OVERFLOW;
  382. if (dwError == ERROR_SUCCESS)
  383. {
  384. dwError = ERROR_BAD_PATHNAME;
  385. }
  386. AdmtThrowError(
  387. GUID_NULL,
  388. GUID_NULL,
  389. HRESULT_FROM_WIN32(dwError),
  390. IDS_E_PASSWORD_FILE,
  391. (LPCTSTR)strFile
  392. );
  393. }
  394. HANDLE hFile = CreateFile(
  395. szPath,
  396. GENERIC_WRITE,
  397. FILE_SHARE_READ|FILE_SHARE_WRITE,
  398. NULL,
  399. OPEN_ALWAYS,
  400. FILE_ATTRIBUTE_NORMAL,
  401. NULL
  402. );
  403. if (hFile == INVALID_HANDLE_VALUE)
  404. {
  405. AdmtThrowError(
  406. GUID_NULL,
  407. GUID_NULL,
  408. HRESULT_FROM_WIN32(GetLastError()),
  409. IDS_E_PASSWORD_FILE,
  410. (LPCTSTR)strFile
  411. );
  412. }
  413. CloseHandle(hFile);
  414. m_bstrPasswordFile = szPath;
  415. }
  416. else
  417. {
  418. m_bstrPasswordFile = strFile;
  419. }
  420. }
  421. catch (_com_error& ce)
  422. {
  423. hr = AdmtSetError(CLSID_Migration, IID_IMigration, ce);
  424. }
  425. catch (...)
  426. {
  427. hr = AdmtSetError(CLSID_Migration, IID_IMigration, E_FAIL);
  428. }
  429. return hr;
  430. }
  431. STDMETHODIMP CMigration::get_PasswordFile(BSTR* pbstrPath)
  432. {
  433. HRESULT hr = S_OK;
  434. try
  435. {
  436. *pbstrPath = m_bstrPasswordFile.copy();
  437. }
  438. catch (_com_error& ce)
  439. {
  440. hr = AdmtSetError(CLSID_Migration, IID_IMigration, ce);
  441. }
  442. catch (...)
  443. {
  444. hr = AdmtSetError(CLSID_Migration, IID_IMigration, E_FAIL);
  445. }
  446. return hr;
  447. }
  448. // ConflictOptions Property
  449. STDMETHODIMP CMigration::put_ConflictOptions(long lOptions)
  450. {
  451. HRESULT hr = S_OK;
  452. long lOption = lOptions & 0x0F;
  453. long lFlags = lOptions & 0xF0;
  454. if ((lOption >= admtIgnoreConflicting) && (lOption <= admtRenameConflictingWithSuffix))
  455. {
  456. if ((lOption == admtReplaceConflicting) || (lFlags == 0))
  457. {
  458. m_lConflictOptions = lOptions;
  459. }
  460. else
  461. {
  462. hr = AdmtSetError(CLSID_Migration, IID_IMigration, E_INVALIDARG, IDS_E_CONFLICT_FLAGS_NOT_ALLOWED);
  463. }
  464. }
  465. else
  466. {
  467. hr = AdmtSetError(CLSID_Migration, IID_IMigration, E_INVALIDARG, IDS_E_CONFLICT_OPTION_INVALID);
  468. }
  469. return hr;
  470. }
  471. STDMETHODIMP CMigration::get_ConflictOptions(long* plOptions)
  472. {
  473. *plOptions = m_lConflictOptions;
  474. return S_OK;
  475. }
  476. // ConflictPrefixOrSuffix Property
  477. STDMETHODIMP CMigration::put_ConflictPrefixOrSuffix(BSTR bstrPrefixOrSuffix)
  478. {
  479. HRESULT hr = S_OK;
  480. try
  481. {
  482. m_bstrConflictPrefixOrSuffix = bstrPrefixOrSuffix;
  483. }
  484. catch (_com_error& ce)
  485. {
  486. hr = AdmtSetError(CLSID_Migration, IID_IMigration, ce);
  487. }
  488. catch (...)
  489. {
  490. hr = AdmtSetError(CLSID_Migration, IID_IMigration, E_FAIL);
  491. }
  492. return hr;
  493. }
  494. STDMETHODIMP CMigration::get_ConflictPrefixOrSuffix(BSTR* pbstrPrefixOrSuffix)
  495. {
  496. HRESULT hr = S_OK;
  497. try
  498. {
  499. *pbstrPrefixOrSuffix = m_bstrConflictPrefixOrSuffix.copy();
  500. }
  501. catch (_com_error& ce)
  502. {
  503. hr = AdmtSetError(CLSID_Migration, IID_IMigration, ce);
  504. }
  505. catch (...)
  506. {
  507. hr = AdmtSetError(CLSID_Migration, IID_IMigration, E_FAIL);
  508. }
  509. return hr;
  510. }
  511. // UserPropertiesToExclude Property
  512. STDMETHODIMP CMigration::put_UserPropertiesToExclude(BSTR bstrProperties)
  513. {
  514. HRESULT hr = S_OK;
  515. try
  516. {
  517. m_bstrUserPropertiesToExclude = GetParsedExcludeProperties(bstrProperties);
  518. }
  519. catch (_com_error& ce)
  520. {
  521. hr = AdmtSetError(CLSID_Migration, IID_IMigration, ce);
  522. }
  523. catch (...)
  524. {
  525. hr = AdmtSetError(CLSID_Migration, IID_IMigration, E_FAIL);
  526. }
  527. return hr;
  528. }
  529. STDMETHODIMP CMigration::get_UserPropertiesToExclude(BSTR* pbstrProperties)
  530. {
  531. HRESULT hr = S_OK;
  532. try
  533. {
  534. *pbstrProperties = m_bstrUserPropertiesToExclude.copy();
  535. }
  536. catch (_com_error& ce)
  537. {
  538. hr = AdmtSetError(CLSID_Migration, IID_IMigration, ce);
  539. }
  540. catch (...)
  541. {
  542. hr = AdmtSetError(CLSID_Migration, IID_IMigration, E_FAIL);
  543. }
  544. return hr;
  545. }
  546. // InetOrgPersonPropertiesToExclude Property
  547. STDMETHODIMP CMigration::put_InetOrgPersonPropertiesToExclude(BSTR bstrProperties)
  548. {
  549. HRESULT hr = S_OK;
  550. try
  551. {
  552. m_bstrInetOrgPersonPropertiesToExclude = GetParsedExcludeProperties(bstrProperties);
  553. }
  554. catch (_com_error& ce)
  555. {
  556. hr = AdmtSetError(CLSID_Migration, IID_IMigration, ce);
  557. }
  558. catch (...)
  559. {
  560. hr = AdmtSetError(CLSID_Migration, IID_IMigration, E_FAIL);
  561. }
  562. return hr;
  563. }
  564. STDMETHODIMP CMigration::get_InetOrgPersonPropertiesToExclude(BSTR* pbstrProperties)
  565. {
  566. HRESULT hr = S_OK;
  567. try
  568. {
  569. *pbstrProperties = m_bstrInetOrgPersonPropertiesToExclude.copy();
  570. }
  571. catch (_com_error& ce)
  572. {
  573. hr = AdmtSetError(CLSID_Migration, IID_IMigration, ce);
  574. }
  575. catch (...)
  576. {
  577. hr = AdmtSetError(CLSID_Migration, IID_IMigration, E_FAIL);
  578. }
  579. return hr;
  580. }
  581. // GroupPropertiesToExclude Property
  582. STDMETHODIMP CMigration::put_GroupPropertiesToExclude(BSTR bstrProperties)
  583. {
  584. HRESULT hr = S_OK;
  585. try
  586. {
  587. m_bstrGroupPropertiesToExclude = GetParsedExcludeProperties(bstrProperties);
  588. }
  589. catch (_com_error& ce)
  590. {
  591. hr = AdmtSetError(CLSID_Migration, IID_IMigration, ce);
  592. }
  593. catch (...)
  594. {
  595. hr = AdmtSetError(CLSID_Migration, IID_IMigration, E_FAIL);
  596. }
  597. return hr;
  598. }
  599. STDMETHODIMP CMigration::get_GroupPropertiesToExclude(BSTR* pbstrProperties)
  600. {
  601. HRESULT hr = S_OK;
  602. try
  603. {
  604. *pbstrProperties = m_bstrGroupPropertiesToExclude.copy();
  605. }
  606. catch (_com_error& ce)
  607. {
  608. hr = AdmtSetError(CLSID_Migration, IID_IMigration, ce);
  609. }
  610. catch (...)
  611. {
  612. hr = AdmtSetError(CLSID_Migration, IID_IMigration, E_FAIL);
  613. }
  614. return hr;
  615. }
  616. // ComputerPropertiesToExclude Property
  617. STDMETHODIMP CMigration::put_ComputerPropertiesToExclude(BSTR bstrProperties)
  618. {
  619. HRESULT hr = S_OK;
  620. try
  621. {
  622. m_bstrComputerPropertiesToExclude = GetParsedExcludeProperties(bstrProperties);
  623. }
  624. catch (_com_error& ce)
  625. {
  626. hr = AdmtSetError(CLSID_Migration, IID_IMigration, ce);
  627. }
  628. catch (...)
  629. {
  630. hr = AdmtSetError(CLSID_Migration, IID_IMigration, E_FAIL);
  631. }
  632. return hr;
  633. }
  634. STDMETHODIMP CMigration::get_ComputerPropertiesToExclude(BSTR* pbstrProperties)
  635. {
  636. HRESULT hr = S_OK;
  637. try
  638. {
  639. *pbstrProperties = m_bstrComputerPropertiesToExclude.copy();
  640. }
  641. catch (_com_error& ce)
  642. {
  643. hr = AdmtSetError(CLSID_Migration, IID_IMigration, ce);
  644. }
  645. catch (...)
  646. {
  647. hr = AdmtSetError(CLSID_Migration, IID_IMigration, E_FAIL);
  648. }
  649. return hr;
  650. }
  651. // SystemPropertiesToExclude Property
  652. STDMETHODIMP CMigration::put_SystemPropertiesToExclude(BSTR bstrProperties)
  653. {
  654. HRESULT hr = S_OK;
  655. try
  656. {
  657. IIManageDBPtr spIManageDB(__uuidof(IManageDB));
  658. IVarSetPtr spVarSet(__uuidof(VarSet));
  659. IUnknownPtr spUnknown(spVarSet);
  660. IUnknown* punk = spUnknown;
  661. spIManageDB->GetSettings(&punk);
  662. spVarSet->put(
  663. GET_BSTR(DCTVS_AccountOptions_ExcludedSystemProps),
  664. _variant_t(GetParsedExcludeProperties(bstrProperties))
  665. );
  666. spIManageDB->SaveSettings(punk);
  667. }
  668. catch (_com_error& ce)
  669. {
  670. hr = AdmtSetError(CLSID_Migration, IID_IMigration, ce);
  671. }
  672. catch (...)
  673. {
  674. hr = AdmtSetError(CLSID_Migration, IID_IMigration, E_FAIL);
  675. }
  676. return hr;
  677. }
  678. STDMETHODIMP CMigration::get_SystemPropertiesToExclude(BSTR* pbstrProperties)
  679. {
  680. HRESULT hr = S_OK;
  681. try
  682. {
  683. IIManageDBPtr spIManageDB(__uuidof(IManageDB));
  684. IVarSetPtr spVarSet(__uuidof(VarSet));
  685. IUnknownPtr spUnknown(spVarSet);
  686. IUnknown* punk = spUnknown;
  687. spIManageDB->GetSettings(&punk);
  688. _bstr_t str = spVarSet->get(GET_BSTR(DCTVS_AccountOptions_ExcludedSystemProps));
  689. *pbstrProperties = str.copy();
  690. }
  691. catch (_com_error& ce)
  692. {
  693. hr = AdmtSetError(CLSID_Migration, IID_IMigration, ce);
  694. }
  695. catch (...)
  696. {
  697. hr = AdmtSetError(CLSID_Migration, IID_IMigration, E_FAIL);
  698. }
  699. return hr;
  700. }
  701. // CreateUserMigration Method
  702. STDMETHODIMP CMigration::CreateUserMigration(IUserMigration** pitfUserMigration)
  703. {
  704. HRESULT hr = S_OK;
  705. try
  706. {
  707. CComObject<CUserMigration>* pUserMigration;
  708. CheckError(CComObject<CUserMigration>::CreateInstance(&pUserMigration));
  709. CheckError(pUserMigration->QueryInterface(__uuidof(IUserMigration), (void**)pitfUserMigration));
  710. pUserMigration->SetInternalInterface(this);
  711. }
  712. catch (_com_error& ce)
  713. {
  714. hr = AdmtSetError(CLSID_Migration, IID_IMigration, ce, IDS_E_CREATE_USER_MIGRATION);
  715. }
  716. catch (...)
  717. {
  718. hr = AdmtSetError(CLSID_Migration, IID_IMigration, E_FAIL, IDS_E_CREATE_USER_MIGRATION);
  719. }
  720. return hr;
  721. }
  722. // CreateGroupMigration Method
  723. STDMETHODIMP CMigration::CreateGroupMigration(IGroupMigration** pitfGroupMigration)
  724. {
  725. HRESULT hr = S_OK;
  726. try
  727. {
  728. CComObject<CGroupMigration>* pGroupMigration;
  729. CheckError(CComObject<CGroupMigration>::CreateInstance(&pGroupMigration));
  730. CheckError(pGroupMigration->QueryInterface(__uuidof(IGroupMigration), (void**)pitfGroupMigration));
  731. pGroupMigration->SetInternalInterface(this);
  732. }
  733. catch (_com_error& ce)
  734. {
  735. hr = AdmtSetError(CLSID_Migration, IID_IMigration, ce, IDS_E_CREATE_GROUP_MIGRATION);
  736. }
  737. catch (...)
  738. {
  739. hr = AdmtSetError(CLSID_Migration, IID_IMigration, E_FAIL, IDS_E_CREATE_GROUP_MIGRATION);
  740. }
  741. return hr;
  742. }
  743. // CreateComputerMigration Method
  744. STDMETHODIMP CMigration::CreateComputerMigration(IComputerMigration** pitfComputerMigration)
  745. {
  746. HRESULT hr = S_OK;
  747. try
  748. {
  749. CComObject<CComputerMigration>* pComputerMigration;
  750. CheckError(CComObject<CComputerMigration>::CreateInstance(&pComputerMigration));
  751. CheckError(pComputerMigration->QueryInterface(__uuidof(IComputerMigration), (void**)pitfComputerMigration));
  752. pComputerMigration->SetInternalInterface(this);
  753. }
  754. catch (_com_error& ce)
  755. {
  756. hr = AdmtSetError(CLSID_Migration, IID_IMigration, ce, IDS_E_CREATE_COMPUTER_MIGRATION);
  757. }
  758. catch (...)
  759. {
  760. hr = AdmtSetError(CLSID_Migration, IID_IMigration, E_FAIL, IDS_E_CREATE_COMPUTER_MIGRATION);
  761. }
  762. return hr;
  763. }
  764. // CreateSecurityTranslation Method
  765. STDMETHODIMP CMigration::CreateSecurityTranslation(ISecurityTranslation** pitfSecurityTranslation)
  766. {
  767. HRESULT hr = S_OK;
  768. try
  769. {
  770. CComObject<CSecurityTranslation>* pSecurityTranslation;
  771. CheckError(CComObject<CSecurityTranslation>::CreateInstance(&pSecurityTranslation));
  772. CheckError(pSecurityTranslation->QueryInterface(__uuidof(ISecurityTranslation), (void**)pitfSecurityTranslation));
  773. pSecurityTranslation->SetInternalInterface(this);
  774. }
  775. catch (_com_error& ce)
  776. {
  777. hr = AdmtSetError(CLSID_Migration, IID_IMigration, ce, IDS_E_CREATE_SECURITY_TRANSLATION);
  778. }
  779. catch (...)
  780. {
  781. hr = AdmtSetError(CLSID_Migration, IID_IMigration, E_FAIL, IDS_E_CREATE_SECURITY_TRANSLATION);
  782. }
  783. return hr;
  784. }
  785. // CreateServiceAccountEnumeration Method
  786. STDMETHODIMP CMigration::CreateServiceAccountEnumeration(IServiceAccountEnumeration** pitfServiceAccountEnumeration)
  787. {
  788. HRESULT hr = S_OK;
  789. try
  790. {
  791. CComObject<CServiceAccountEnumeration>* pServiceAccountEnumeration;
  792. CheckError(CComObject<CServiceAccountEnumeration>::CreateInstance(&pServiceAccountEnumeration));
  793. CheckError(pServiceAccountEnumeration->QueryInterface(__uuidof(IServiceAccountEnumeration), (void**)pitfServiceAccountEnumeration));
  794. pServiceAccountEnumeration->SetInternalInterface(this);
  795. }
  796. catch (_com_error& ce)
  797. {
  798. hr = AdmtSetError(CLSID_Migration, IID_IMigration, ce, IDS_E_CREATE_SERVICE_ACCOUNT_ENUMERATION);
  799. }
  800. catch (...)
  801. {
  802. hr = AdmtSetError(CLSID_Migration, IID_IMigration, E_FAIL, IDS_E_CREATE_SERVICE_ACCOUNT_ENUMERATION);
  803. }
  804. return hr;
  805. }
  806. // CreateReportGeneration Method
  807. STDMETHODIMP CMigration::CreateReportGeneration(IReportGeneration** pitfReportGeneration)
  808. {
  809. HRESULT hr = S_OK;
  810. try
  811. {
  812. CComObject<CReportGeneration>* pReportGeneration;
  813. CheckError(CComObject<CReportGeneration>::CreateInstance(&pReportGeneration));
  814. CheckError(pReportGeneration->QueryInterface(__uuidof(IReportGeneration), (void**)pitfReportGeneration));
  815. pReportGeneration->SetInternalInterface(this);
  816. }
  817. catch (_com_error& ce)
  818. {
  819. hr = AdmtSetError(CLSID_Migration, IID_IMigration, ce, IDS_E_CREATE_REPORT_GENERATION);
  820. }
  821. catch (...)
  822. {
  823. hr = AdmtSetError(CLSID_Migration, IID_IMigration, E_FAIL, IDS_E_CREATE_REPORT_GENERATION);
  824. }
  825. return hr;
  826. }
  827. // UpdateDatabase
  828. void CMigration::UpdateDatabase()
  829. {
  830. try
  831. {
  832. // verify and create if necessary a source domain
  833. // sid column in the migrated objects table
  834. ISrcSidUpdatePtr spSrcSidUpdate(__uuidof(SrcSidUpdate));
  835. if (spSrcSidUpdate->QueryForSrcSidColumn() == VARIANT_FALSE)
  836. {
  837. spSrcSidUpdate->CreateSrcSidColumn(VARIANT_TRUE);
  838. }
  839. // verify and create if necessary an account
  840. // sid column in the account references table
  841. IIManageDBPtr spIManageDB(__uuidof(IManageDB));
  842. if (spIManageDB->SidColumnInARTable() == VARIANT_FALSE)
  843. {
  844. spIManageDB->CreateSidColumnInAR();
  845. }
  846. }
  847. catch (_com_error& ce)
  848. {
  849. AdmtThrowError(GUID_NULL, GUID_NULL, ce, IDS_E_UNABLE_TO_UPDATE_DATABASE);
  850. }
  851. catch (...)
  852. {
  853. AdmtThrowError(GUID_NULL, GUID_NULL, E_FAIL, IDS_E_UNABLE_TO_UPDATE_DATABASE);
  854. }
  855. }
  856. //---------------------------------------------------------------------------
  857. // GetParsedExcludeProperties Method
  858. //
  859. // Trims whitespace from comma delimited properties.
  860. //
  861. // 2001-02-06 Mark Oluper - initial
  862. //---------------------------------------------------------------------------
  863. _bstr_t CMigration::GetParsedExcludeProperties(LPCTSTR pszOld)
  864. {
  865. tstring strNew;
  866. if (pszOld)
  867. {
  868. bool bInProperty = false;
  869. // for each character in input string
  870. for (LPCTSTR pch = pszOld; *pch; pch++)
  871. {
  872. // if not whitespace or comma
  873. if (!(_istspace(*pch) || (*pch == _T(','))))
  874. {
  875. // if not 'in property'
  876. if (!bInProperty)
  877. {
  878. // set 'in property'
  879. bInProperty = true;
  880. // if not first property add comma delimiter
  881. if (!strNew.empty())
  882. {
  883. strNew += _T(',');
  884. }
  885. }
  886. // add character to property
  887. strNew += *pch;
  888. }
  889. else
  890. {
  891. // if 'in property' reset
  892. if (bInProperty)
  893. {
  894. bInProperty = false;
  895. }
  896. }
  897. }
  898. }
  899. return strNew.c_str();
  900. }