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.

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