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.

6428 lines
202 KiB

  1. #include "stdafx.h"
  2. #include "GuiUtils.h"
  3. #include "TxtSid.h"
  4. #include "LSAUtils.h"
  5. #include "ErrDct.hpp"
  6. #include <ntdsapi.h>
  7. #include <ntldap.h> // LDAP_MATCHING_RULE_BIT_AND_W
  8. #include <DsRole.h>
  9. #include <lm.h>
  10. #include "GetDcName.h"
  11. #include <SamUtils.h>
  12. #include "HtmlHelpUtil.h"
  13. #include "VerifyConfiguration.h"
  14. #include "exldap.h"
  15. #include "StrHelp.h"
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. typedef UINT (CALLBACK* DSBINDFUNC)(TCHAR*, TCHAR*, HANDLE*);
  22. typedef UINT (CALLBACK* DSUNBINDFUNC)(HANDLE*);
  23. typedef NTDSAPI
  24. DWORD
  25. WINAPI
  26. DSCRACKNAMES(
  27. HANDLE hDS, // in
  28. DS_NAME_FLAGS flags, // in
  29. DS_NAME_FORMAT formatOffered, // in
  30. DS_NAME_FORMAT formatDesired, // in
  31. DWORD cNames, // in
  32. const LPCWSTR *rpNames, // in
  33. PDS_NAME_RESULTW *ppResult); // out
  34. typedef NTDSAPI
  35. void
  36. WINAPI
  37. DSFREENAMERESULT(
  38. DS_NAME_RESULTW *pResult
  39. );
  40. #ifndef IADsPtr
  41. _COM_SMARTPTR_TYPEDEF(IADs, IID_IADs);
  42. #endif
  43. #ifndef IADsUserPtr
  44. _COM_SMARTPTR_TYPEDEF(IADsUser, IID_IADsUser);
  45. #endif
  46. #ifndef IADsContainerPtr
  47. _COM_SMARTPTR_TYPEDEF(IADsContainer, IID_IADsContainer);
  48. #endif
  49. BOOL
  50. CanSkipVerification()
  51. {
  52. DWORD rc = 0;
  53. BOOL bFound = FALSE;
  54. TRegKey key;
  55. DWORD val = 0;
  56. rc = key.OpenRead(GET_STRING(IDS_HKLM_DomainAdmin_Key),HKEY_LOCAL_MACHINE);
  57. if (! rc )
  58. {
  59. rc = key.ValueGetDWORD(L"SkipGUIValidation",&val);
  60. if ( ! rc && ( val != 0 ) )
  61. {
  62. bFound = TRUE;
  63. }
  64. }
  65. return !bFound;
  66. }
  67. BOOL // ret - TRUE if directory found
  68. GetDirectory(
  69. WCHAR * filename // out - string buffer to store directory name
  70. )
  71. {
  72. DWORD rc = 0;
  73. BOOL bFound = FALSE;
  74. TRegKey key;
  75. rc = key.OpenRead(GET_STRING(IDS_HKLM_DomainAdmin_Key),HKEY_LOCAL_MACHINE);
  76. if ( ! rc )
  77. {
  78. rc = key.ValueGetStr(L"Directory",filename,MAX_PATH);
  79. if ( ! rc )
  80. {
  81. if ( *filename )
  82. bFound = TRUE;
  83. }
  84. }
  85. return bFound;
  86. }
  87. void OnTOGGLE(HWND hwndDlg)
  88. {
  89. int nItem;
  90. CString c,computer,account,service;
  91. CString skip,include;
  92. skip.LoadString(IDS_SKIP); include.LoadString(IDS_INCLUDE);
  93. nItem = m_serviceBox.GetNextItem(-1, LVNI_SELECTED);
  94. while (nItem != -1)
  95. {
  96. computer = m_serviceBox.GetItemText(nItem,0);
  97. service = m_serviceBox.GetItemText(nItem,1);
  98. account = m_serviceBox.GetItemText(nItem,2);
  99. c = m_serviceBox.GetItemText(nItem,3);
  100. if (c==skip)
  101. {
  102. c = include;
  103. if (migration == w_service)
  104. {
  105. CString sTgtAcct;
  106. if (HasAccountBeenMigrated(account, sTgtAcct))
  107. {
  108. enable(hwndDlg, IDC_UPDATE);
  109. }
  110. else
  111. {
  112. disable(hwndDlg, IDC_UPDATE);
  113. }
  114. }
  115. }
  116. else if (c== include)
  117. {
  118. c = skip;
  119. if (migration == w_service)
  120. {
  121. disable(hwndDlg, IDC_UPDATE);
  122. }
  123. }
  124. SetItemText(m_serviceBox,nItem,3,c);
  125. nItem = m_serviceBox.GetNextItem(nItem, LVNI_SELECTED);
  126. }
  127. }
  128. void OnRetryToggle()
  129. {
  130. int nItem;
  131. CString c;
  132. CString skip,include;
  133. skip.LoadString(IDS_SKIP); include.LoadString(IDS_INCLUDE);
  134. nItem = m_cancelBox.GetNextItem(-1, LVNI_SELECTED);
  135. while (nItem != -1)
  136. {
  137. c = m_cancelBox.GetItemText(nItem,5);
  138. if (c== skip)
  139. {
  140. c = include;
  141. }
  142. else if (c== include)
  143. {
  144. c = skip;
  145. }
  146. SetItemText(m_cancelBox,nItem,5,c);
  147. nItem = m_cancelBox.GetNextItem(nItem, LVNI_SELECTED);
  148. }
  149. }
  150. void OnUPDATE(HWND hwndDlg)
  151. {
  152. ISvcMgrPtr svcMgr;
  153. HRESULT hr = svcMgr.CreateInstance(CLSID_ServMigr);
  154. int nItem;
  155. CString updated,updatefailed,include;
  156. updated.LoadString(IDS_UPDATED);updatefailed.LoadString(IDS_UPDATEFAILED);
  157. include.LoadString(IDS_INCLUDE);
  158. CString computer,service,account,status;
  159. nItem = m_serviceBox.GetNextItem(-1, LVNI_SELECTED);
  160. while (nItem != -1)
  161. {
  162. status = m_serviceBox.GetItemText(nItem,3);
  163. if ((status == updatefailed) || (status == include))
  164. {
  165. CString sSrcAcct;
  166. computer = m_serviceBox.GetItemText(nItem,0);
  167. sSrcAcct= m_serviceBox.GetItemText(nItem,2);
  168. service = m_serviceBox.GetItemText(nItem,1);
  169. // get the target account
  170. if (HasAccountBeenMigrated(sSrcAcct, account))
  171. {
  172. hr = svcMgr->raw_TryUpdateSam(_bstr_t(computer),_bstr_t(service),_bstr_t(account));
  173. if (! SUCCEEDED(hr))
  174. {
  175. if (HRESULT_CODE(hr) == HRESULT_CODE(DCT_MSG_UPDATE_SCM_ENTRY_UNMATCHED_SSD))
  176. {
  177. CString msg, title, sTemp;
  178. sTemp.LoadString(IDS_MSG_SA_NO_MATCH);
  179. msg.Format((LPCTSTR)sTemp, (LPCTSTR)computer, (LPCTSTR)service, (LPCTSTR)account);
  180. title.LoadString(IDS_SA_MISMATCH_TITLE);
  181. MessageBox(hwndDlg,msg,title,MB_OK|MB_ICONSTOP);
  182. }
  183. else if (hr == HRESULT_FROM_WIN32(ERROR_NOT_FOUND))
  184. {
  185. CString sMsg, sTitle, sTemp;
  186. sTemp.LoadString(IDS_MSG_REMIGRATE_ACCOUNT);
  187. sMsg.Format((LPCTSTR) sTemp, (LPCTSTR) sSrcAcct);
  188. sTitle.LoadString(IDS_MSG_ERROR);
  189. MessageBox(hwndDlg, sMsg, sTitle, MB_OK|MB_ICONSTOP);
  190. }
  191. else
  192. {
  193. db->SetServiceAcctEntryStatus(_bstr_t(computer), _bstr_t(service), _bstr_t(sSrcAcct), SvcAcctStatus_UpdateFailed);
  194. SetItemText(m_serviceBox,nItem,3,updatefailed);
  195. ErrorWrapper(hwndDlg,hr);
  196. }
  197. }
  198. else
  199. {
  200. db->SetServiceAcctEntryStatus(_bstr_t(computer), _bstr_t(service), _bstr_t(account), SvcAcctStatus_Updated);
  201. SetItemText(m_serviceBox,nItem,2,account); // update to the target account
  202. SetItemText(m_serviceBox,nItem,3,updated);
  203. }
  204. }
  205. }
  206. nItem = m_serviceBox.GetNextItem(nItem, LVNI_SELECTED);
  207. }
  208. }
  209. DWORD VerifyPassword(PCWSTR pszUser, PCWSTR pszPassword, PCWSTR pszDomain)
  210. {
  211. DWORD dwError = ERROR_SUCCESS;
  212. if (gbNeedToVerify)
  213. {
  214. CWaitCursor wait;
  215. //
  216. // Verify that specified domain is valid.
  217. //
  218. //_bstr_t strDC;
  219. //dwError = GetAnyDcName5(pszDomain, strDC);
  220. //if (dwError == ERROR_SUCCESS)
  221. //{
  222. //
  223. // Obtain the name of the PDC in the source domain. The credentials must be validated
  224. // on the PDC as the underlying SamConnectWithCreds call requires SAM RPC calls over TCP
  225. // transport which is enabled by the TcpipClientSupport key. This is usually only enabled
  226. // on the PDC for DsAddSidHistory.
  227. //
  228. PCTSTR pszSourceDomain = GetSourceDomainName();
  229. _bstr_t strSourcePdc;
  230. dwError = GetDcName5(pszSourceDomain, DS_PDC_REQUIRED, strSourcePdc);
  231. if (dwError == ERROR_SUCCESS)
  232. {
  233. //
  234. // Verify that credentials are valid and have
  235. // administrative rights in the source domain.
  236. //
  237. dwError = VerifyAdminCredentials(pszSourceDomain, strSourcePdc, pszUser, pszPassword, pszDomain);
  238. }
  239. //}
  240. }
  241. return dwError;
  242. }
  243. //----------------------------------------------------------------------------
  244. // Function: VerifyExchangeServerCredential
  245. //
  246. // Synopsis: This function tries to use the provided credential to connect
  247. // to the exchange server ldap port. If successful, ERROR_SUCCESS
  248. // is returned; otherwise, some error code is returned
  249. //
  250. // Arguments:
  251. //
  252. // pszUser the username string
  253. // pszPassword the password string
  254. // pszDomain the domain name string
  255. //
  256. // Returns: ERROR_SUCCESS if successful; otherwise an error code
  257. //
  258. // Modifies: None.
  259. //
  260. //----------------------------------------------------------------------------
  261. DWORD VerifyExchangeServerCredential(HWND hwndDlg, PCWSTR pszUser, PCWSTR pszPassword, PCWSTR pszDomain)
  262. {
  263. // for exchange migration, we use the credential to connect to
  264. // exchange server
  265. CLdapEnum e;
  266. DWORD ldapPort, sslPort;
  267. DWORD rc;
  268. _bstr_t server = pVarSet->get(GET_BSTR(DCTVS_Security_TranslateContainers));
  269. GetLDAPPort(&ldapPort, &sslPort);
  270. WCHAR szIdentifier[256];
  271. rc = GeneratePasswordIdentifier(szIdentifier, countof(szIdentifier));
  272. if (rc == ERROR_SUCCESS)
  273. {
  274. rc = StorePassword(szIdentifier, pszPassword);
  275. if (rc == ERROR_SUCCESS)
  276. {
  277. e.m_connection.SetCredentials(pszDomain, pszUser, szIdentifier);
  278. BOOL sslEnabled = FALSE;
  279. // try SSL port first
  280. rc = e.InitSSLConnection(server,&sslEnabled,sslPort);
  281. if (rc != ERROR_SUCCESS || sslEnabled == FALSE)
  282. {
  283. rc = e.InitConnection(server, ldapPort);
  284. }
  285. StorePassword(szIdentifier, NULL);
  286. if (rc != ERROR_SUCCESS)
  287. {
  288. MessageBoxWrapper(hwndDlg, IDS_MSG_INVALID_EXCHANGE_SERVER_CREDENTIALS, IDS_MSG_ERROR);
  289. }
  290. }
  291. else
  292. {
  293. MessageBoxWrapper(hwndDlg, IDS_MSG_UNABLE_RETRIEVE_STORE_PASSWORD, IDS_MSG_ERROR);
  294. }
  295. }
  296. else
  297. {
  298. MessageBoxWrapper(hwndDlg, IDS_MSG_UNABLE_RETRIEVE_STORE_PASSWORD, IDS_MSG_ERROR);
  299. }
  300. return rc;
  301. }
  302. void activateTrustButton(HWND hwndDlg)
  303. {
  304. // int i = m_trustBox.GetSelectionMark();
  305. int i = m_trustBox.GetNextItem(-1, LVNI_SELECTED);//PRT
  306. CString c;
  307. if (i==-1)
  308. {
  309. disable(hwndDlg,IDC_MIGRATE) ;
  310. return;
  311. }
  312. else if ((c = m_trustBox.GetItemText(i,3)) == (WCHAR const *) yes)
  313. {
  314. disable(hwndDlg,IDC_MIGRATE) ;
  315. return;
  316. }
  317. enable(hwndDlg,IDC_MIGRATE);
  318. }
  319. void activateServiceButtons(HWND hwndDlg)
  320. {
  321. int nItem;
  322. CString checker;
  323. bool enableUpdate=false;
  324. bool enableToggle=false;
  325. CString skip,include,updated,updatefailed;
  326. skip.LoadString(IDS_SKIP); include.LoadString(IDS_INCLUDE); updated.LoadString(IDS_UPDATED);updatefailed.LoadString(IDS_UPDATEFAILED);
  327. // POSITION pos = m_serviceBox.GetFirstSelectedItemPosition();
  328. // while (pos)
  329. // {
  330. // nItem = m_serviceBox.GetNextSelectedItem(pos);
  331. nItem = m_serviceBox.GetNextItem(-1, LVNI_SELECTED);//PRT
  332. while (nItem != -1)//PRT
  333. {
  334. checker = m_serviceBox.GetItemText(nItem,3);
  335. enableToggle = enableToggle || (checker==skip|| checker==include);
  336. if (checker == include)
  337. {
  338. CString sSrcAcct, sTgtAcct;
  339. sSrcAcct = m_serviceBox.GetItemText(nItem, 2);
  340. if (HasAccountBeenMigrated(sSrcAcct, sTgtAcct))
  341. enableUpdate = true;
  342. }
  343. enableUpdate = enableUpdate || (checker==updatefailed);
  344. nItem = m_serviceBox.GetNextItem(nItem, LVNI_SELECTED);//PRT
  345. }
  346. enableToggle ? enable(hwndDlg,IDC_TOGGLE) : disable(hwndDlg,IDC_TOGGLE);
  347. enableUpdate ? enable(hwndDlg,IDC_UPDATE) : disable(hwndDlg,IDC_UPDATE);
  348. }
  349. void activateServiceButtons2(HWND hwndDlg)
  350. {
  351. int nItem;
  352. CString checker;
  353. bool enableToggle=false;
  354. CString skip,include;
  355. skip.LoadString(IDS_SKIP); include.LoadString(IDS_INCLUDE);
  356. nItem = m_serviceBox.GetNextItem(-1, LVNI_SELECTED);
  357. while (nItem != -1)
  358. {
  359. checker = m_serviceBox.GetItemText(nItem,3);
  360. enableToggle = enableToggle || (checker==skip || checker==include);
  361. nItem = m_serviceBox.GetNextItem(nItem, LVNI_SELECTED);
  362. }
  363. enableToggle ? enable(hwndDlg,IDC_TOGGLE) : disable(hwndDlg,IDC_TOGGLE);
  364. }
  365. void removeService(CString name)
  366. {
  367. name = name.Right((name.GetLength()-name.ReverseFind(L'\\')) -1);
  368. name.TrimLeft();name.TrimRight();
  369. _bstr_t text=get(DCTVS_Accounts_NumItems);
  370. CString base,base2,tocompare;
  371. int count = _ttoi((WCHAR * const) text);
  372. for (int i=0;i<count;i++)
  373. {
  374. base.Format(L"Accounts.%d.Name",i);
  375. text =pVarSet->get(_bstr_t(base));
  376. tocompare = (WCHAR * const) text;
  377. tocompare.TrimLeft();tocompare.TrimRight();
  378. if (!name.CompareNoCase(tocompare))
  379. {
  380. count--;
  381. base.Format(L"Accounts.%d",count);
  382. base2.Format(L"Accounts.%d",i);
  383. pVarSet->put(_bstr_t(base2),pVarSet->get(_bstr_t(base)));
  384. pVarSet->put(_bstr_t(base2+L".Name"),pVarSet->get(_bstr_t(base+L".Name")));
  385. pVarSet->put(_bstr_t(base2+L".Type"),pVarSet->get(_bstr_t(base+L".Type")));
  386. pVarSet->put(_bstr_t(base2+L".TargetName"),pVarSet->get(_bstr_t(base+L".TargetName")));
  387. pVarSet->put(_bstr_t(base),L"");
  388. pVarSet->put(_bstr_t(base+L".Name"),L"");
  389. pVarSet->put(_bstr_t(base+L".Type"),L"");
  390. pVarSet->put(_bstr_t(base+L".TargetName"),L"");
  391. put(DCTVS_Accounts_NumItems,(long) count);
  392. return;
  393. }
  394. }
  395. }
  396. void setDBStatusSkip()
  397. {
  398. CString computer,account,service;
  399. for (int i=0;i<m_serviceBox.GetItemCount();i++)
  400. {
  401. computer = m_serviceBox.GetItemText(i,0);
  402. service = m_serviceBox.GetItemText(i,1);
  403. account = m_serviceBox.GetItemText(i,2);
  404. db->SetServiceAcctEntryStatus(_bstr_t(computer), _bstr_t(service), _bstr_t(account),SvcAcctStatus_DoNotUpdate);
  405. removeService(account);
  406. }
  407. }
  408. bool setDBStatusInclude(HWND hwndDlg)
  409. {
  410. CString c,computer,account,service;
  411. CString skip,include;
  412. skip.LoadString(IDS_SKIP); include.LoadString(IDS_INCLUDE);
  413. bool messageDisplayed=false;
  414. for (int i=0;i<m_serviceBox.GetItemCount();i++)
  415. {
  416. computer = m_serviceBox.GetItemText(i,0);
  417. service = m_serviceBox.GetItemText(i,1);
  418. account = m_serviceBox.GetItemText(i,2);
  419. c = m_serviceBox.GetItemText(i,3);
  420. if (c== skip)
  421. {
  422. db->SetServiceAcctEntryStatus(_bstr_t(computer), _bstr_t(service), _bstr_t(account),SvcAcctStatus_DoNotUpdate);
  423. }
  424. else if (c==include)
  425. {
  426. messageDisplayed=true;
  427. db->SetServiceAcctEntryStatus(_bstr_t(computer), _bstr_t(service), _bstr_t(account), SvcAcctStatus_NotMigratedYet);
  428. }
  429. }
  430. return messageDisplayed;
  431. }
  432. void getService()
  433. {
  434. IUnknown * pUnk;
  435. CString skip,include,updated,updatefailed,cannotMigrate;
  436. skip.LoadString(IDS_SKIP); include.LoadString(IDS_INCLUDE); updated.LoadString(IDS_UPDATED); updatefailed.LoadString(IDS_UPDATEFAILED);
  437. cannotMigrate.LoadString(IDS_CANNOT);
  438. m_serviceBox.DeleteAllItems();
  439. if (migration!=w_account)
  440. {
  441. pVarSetService->QueryInterface(IID_IUnknown, (void**) &pUnk);
  442. db->GetServiceAccount(L"",&pUnk);
  443. pUnk->Release();
  444. }
  445. // pVarSetService is now containing all service acct information.
  446. _bstr_t text;
  447. text = pVarSetService->get(L"ServiceAccountEntries");
  448. int numItems=_ttoi((WCHAR const *)text);
  449. CString toLoad,temp;
  450. toLoad = (WCHAR const *)text;
  451. for (int i = 0; i< numItems;i++)
  452. {
  453. toLoad.Format(L"Computer.%d",i);
  454. text = pVarSetService->get(_bstr_t(toLoad));
  455. m_serviceBox.InsertItem(0,(WCHAR const *)text);
  456. toLoad.Format(L"Service.%d",i);
  457. text = pVarSetService->get(_bstr_t(toLoad));
  458. SetItemText(m_serviceBox,0,1,(WCHAR const *)text);
  459. toLoad.Format(L"ServiceAccount.%d",i);
  460. text = pVarSetService->get(_bstr_t(toLoad));
  461. SetItemText(m_serviceBox,0,2,(WCHAR const *)text);
  462. toLoad.Format(L"ServiceAccountStatus.%d",i);
  463. text = pVarSetService->get(_bstr_t(toLoad));
  464. if (!UStrCmp(text,L"0")) temp = include;
  465. else if (!UStrCmp(text,L"1")) temp = skip;
  466. else if (!UStrCmp(text,L"4")) temp = updatefailed;
  467. else if (!UStrCmp(text,L"2")) temp = updated;
  468. else if (!UStrCmp(text,L"8")) temp = cannotMigrate;
  469. else temp =L"~";
  470. SetItemText(m_serviceBox,0,3,temp);
  471. //new
  472. toLoad.Format(L"ServiceDisplayName.%d",i);
  473. text = pVarSetService->get(_bstr_t(toLoad));
  474. SetItemText(m_serviceBox,0,4,(WCHAR const *)text);
  475. }
  476. }
  477. void refreshDB(HWND hwndDlg)
  478. {
  479. // protect against re-entrancy which may occur
  480. // if wizard page button is clicked repeatedly
  481. static bool s_bInFunction = false;
  482. if (!s_bInFunction)
  483. {
  484. s_bInFunction = true;
  485. try
  486. {
  487. IPerformMigrationTaskPtr sp(__uuidof(Migrator));
  488. pVarSet->put(L"PlugIn.0", _variant_t(L"{9CC87460-461D-11D3-99F3-0010A4F77383}"));
  489. sp->PerformMigrationTask(IUnknownPtr(pVarSet), (LONG_PTR)hwndDlg);
  490. pVarSet->put(L"PlugIn.0", _variant_t(L""));
  491. }
  492. catch (const _com_error &ce)
  493. {
  494. // load the correct module state
  495. // for some reason the wrong module state may be current
  496. // which causes the LoadString to fail to find the string resource
  497. // this does occur if refreshDB is called a second time before the previous
  498. // call has returned from PerformMigrationTask
  499. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  500. if (ce.Error() == MIGRATOR_E_PROCESSES_STILL_RUNNING)
  501. {
  502. CString str;
  503. if (str.LoadString(IDS_ADMT_PROCESSES_STILL_RUNNING))
  504. {
  505. ::AfxMessageBox(str);
  506. }
  507. }
  508. else
  509. {
  510. _bstr_t bstrDescription;
  511. try
  512. {
  513. bstrDescription = ce.Description();
  514. }
  515. catch (_com_error &e)
  516. {
  517. }
  518. if (bstrDescription.length())
  519. ::AfxMessageBox(bstrDescription);
  520. else
  521. ::AfxMessageBox(ce.ErrorMessage());
  522. }
  523. }
  524. s_bInFunction = false;
  525. }
  526. }
  527. void initnoncollisionrename(HWND hwndDlg)
  528. {
  529. _bstr_t pre;
  530. _bstr_t suf;
  531. pre = get(DCTVS_Options_Prefix);
  532. suf = get(DCTVS_Options_Suffix);
  533. if (UStrICmp(pre,L""))
  534. {
  535. CheckRadioButton(hwndDlg,IDC_RADIO_NONE,IDC_RADIO_PRE,IDC_RADIO_PRE);
  536. enable(hwndDlg,IDC_PRE);
  537. disable(hwndDlg,IDC_SUF);
  538. }
  539. else if (UStrICmp(suf,L""))
  540. {
  541. CheckRadioButton(hwndDlg,IDC_RADIO_NONE,IDC_RADIO_SUF,IDC_RADIO_SUF);
  542. enable(hwndDlg,IDC_SUF);
  543. disable(hwndDlg,IDC_PRE);
  544. }
  545. else
  546. {
  547. CheckRadioButton(hwndDlg,IDC_RADIO_NONE,IDC_RADIO_SUF,IDC_RADIO_NONE);
  548. disable(hwndDlg,IDC_SUF);
  549. disable(hwndDlg,IDC_PRE);
  550. }
  551. initeditbox(hwndDlg,IDC_PRE,DCTVS_Options_Prefix);
  552. initeditbox(hwndDlg,IDC_SUF,DCTVS_Options_Suffix);
  553. }
  554. bool noncollisionrename(HWND hwndDlg)
  555. {
  556. CString P;
  557. CString S;
  558. if (IsDlgButtonChecked(hwndDlg,IDC_RADIO_SUF))
  559. {
  560. if (!validString(hwndDlg,IDC_SUF)) return false;
  561. if (IsDlgItemEmpty(hwndDlg,IDC_SUF)) return false;
  562. GetDlgItemText(hwndDlg,IDC_SUF,S.GetBuffer(1000),1000);
  563. S.ReleaseBuffer();
  564. P=L"";
  565. }
  566. else if (IsDlgButtonChecked(hwndDlg,IDC_RADIO_PRE))
  567. {
  568. if (!validString(hwndDlg,IDC_PRE)) return false;
  569. if (IsDlgItemEmpty(hwndDlg,IDC_PRE)) return false;
  570. GetDlgItemText(hwndDlg,IDC_PRE,P.GetBuffer(1000),1000);
  571. P.ReleaseBuffer();
  572. S=L"";
  573. }
  574. else
  575. {
  576. P=L"";
  577. S=L"";
  578. }
  579. if (P.GetLength() > 8 || S.GetLength() >8) return false;
  580. put(DCTVS_Options_Prefix,_bstr_t(P));
  581. put(DCTVS_Options_Suffix,_bstr_t(S));
  582. return true;
  583. }
  584. bool tooManyChars(HWND hwndDlg,int id)
  585. {
  586. _bstr_t text;
  587. CString temp;
  588. _variant_t varX;
  589. int i;
  590. GetDlgItemText( hwndDlg, id, temp.GetBuffer(1000),1000);
  591. temp.ReleaseBuffer();
  592. i=temp.GetLength();
  593. text = get(DCTVS_Options_Prefix);
  594. temp=(WCHAR const *) text;
  595. i+= temp.GetLength();
  596. text = get(DCTVS_Options_Suffix);
  597. temp=(WCHAR const *) text;
  598. i+= temp.GetLength();
  599. return (i>8);
  600. }
  601. bool someServiceAccounts(int accounts,HWND hwndDlg)
  602. {
  603. CWaitCursor c;
  604. if (migration==w_group) return false;
  605. IVarSetPtr pVarSetMerge(__uuidof(VarSet));
  606. IUnknown * pUnk;
  607. int count=0;
  608. pVarSetMerge->QueryInterface(IID_IUnknown, (void**) &pUnk);
  609. _bstr_t nameToCheck,text;
  610. CString parameterToCheck;
  611. bool some= false;
  612. pVarSetService->Clear();
  613. for (int i = 0;i<accounts;i++)
  614. {
  615. pVarSetMerge->Clear();
  616. parameterToCheck.Format(L"Accounts.%d",i);
  617. nameToCheck = pVarSet->get(_bstr_t(parameterToCheck));
  618. // Get the DOMAIN\Account form of the name
  619. WCHAR domAcct[500];
  620. WCHAR domAcctUPN[5000];
  621. domAcct[0] = 0;
  622. if ( ! wcsncmp(nameToCheck,L"WinNT://",UStrLen(L"WinNT://")) )
  623. {
  624. // the name is in the format: WinNT://DOMAIN/Account
  625. safecopy(domAcct,((WCHAR*)nameToCheck)+UStrLen(L"WinNT://"));
  626. // convert the / to a \ .
  627. WCHAR * slash = wcschr(domAcct,L'/');
  628. if ( slash )
  629. {
  630. (*slash) = L'\\';
  631. }
  632. }
  633. else
  634. {
  635. // this is the LDAP form of the name.
  636. IADsUserPtr pUser;
  637. HRESULT hr = ADsGetObject(nameToCheck,IID_IADsUser,(void**)&pUser);
  638. if ( SUCCEEDED(hr) )
  639. {
  640. VARIANT v;
  641. VariantInit(&v);
  642. hr = pUser->Get(_bstr_t(L"sAMAccountName"),&v);
  643. if ( SUCCEEDED(hr) )
  644. {
  645. if ( v.vt == VT_BSTR )
  646. {
  647. // we got the account name!
  648. swprintf(domAcct,L"%ls\\%ls",GetSourceDomainNameFlat(),(WCHAR*)v.bstrVal);
  649. }
  650. VariantClear(&v);
  651. }
  652. }
  653. else
  654. {
  655. CString toload,title;toload.LoadString(IDS_MSG_SA_FAILED);
  656. title.LoadString(IDS_MSG_ERROR);
  657. MessageBox(hwndDlg,toload,title,MB_OK|MB_ICONSTOP);
  658. return false;
  659. }
  660. }
  661. if ( *domAcct ) // if we weren't able to get the account name, just skip the DB check
  662. {
  663. HRESULT hr=db->raw_GetServiceAccount(domAcct,&pUnk);
  664. if (FAILED(hr)) {
  665. CString toload,title;toload.LoadString(IDS_MSG_SA_FAILED);
  666. title.LoadString(IDS_MSG_ERROR);
  667. MessageBox(hwndDlg,toload,title,MB_OK|MB_ICONSTOP);
  668. return false;
  669. }
  670. text = pVarSetMerge->get(L"ServiceAccountEntries");
  671. //adding code to handle service accounts in the database that
  672. //may be listed by their UPN name
  673. if ((!UStrCmp(text,L"0")) || (!UStrCmp(text,L"")))
  674. {
  675. PDS_NAME_RESULT pNamesOut = NULL;
  676. WCHAR * pNamesIn[1];
  677. HINSTANCE hLibrary = NULL;
  678. DSCRACKNAMES * DsCrackNames = NULL;
  679. DSFREENAMERESULT * DsFreeNameResult = NULL;
  680. DSBINDFUNC DsBind = NULL;
  681. DSUNBINDFUNC DsUnBind = NULL;
  682. HANDLE hDs = NULL;
  683. pNamesIn[0] = (WCHAR*)domAcct;
  684. hLibrary = LoadLibrary(L"NTDSAPI.DLL");
  685. if ( hLibrary )
  686. {
  687. DsBind = (DSBINDFUNC)GetProcAddress(hLibrary,"DsBindW");
  688. DsUnBind = (DSUNBINDFUNC)GetProcAddress(hLibrary,"DsUnBindW");
  689. DsCrackNames = (DSCRACKNAMES *)GetProcAddress(hLibrary,"DsCrackNamesW");
  690. DsFreeNameResult = (DSFREENAMERESULT *)GetProcAddress(hLibrary,"DsFreeNameResultW");
  691. }
  692. if ( DsBind && DsUnBind && DsCrackNames && DsFreeNameResult)
  693. {
  694. //bind to that source domain
  695. hr = (*DsBind)(NULL,const_cast<TCHAR*>(GetSourceDomainName()),&hDs);
  696. if ( !hr )
  697. {
  698. //get UPN name of this account from DSCrackNames
  699. hr = (*DsCrackNames)(hDs,DS_NAME_NO_FLAGS,DS_NT4_ACCOUNT_NAME,DS_USER_PRINCIPAL_NAME,1,pNamesIn,&pNamesOut);
  700. if ( !hr )
  701. { //if got the UPN name, retry DB query for that account in the
  702. //service account database
  703. if ( pNamesOut->rItems[0].status == DS_NAME_NO_ERROR )
  704. {
  705. wcscpy(domAcctUPN, pNamesOut->rItems[0].pName);
  706. //see if account in database by its UPN name
  707. hr=db->raw_GetServiceAccount(domAcctUPN,&pUnk);
  708. if (!SUCCEEDED (hr))
  709. {
  710. CString toload,title;toload.LoadString(IDS_MSG_SA_FAILED);
  711. title.LoadString(IDS_MSG_ERROR);
  712. MessageBox(hwndDlg,toload,title,MB_OK|MB_ICONSTOP);
  713. return false;
  714. }
  715. text = pVarSetMerge->get(L"ServiceAccountEntries");
  716. }
  717. (*DsFreeNameResult)(pNamesOut);
  718. }
  719. (*DsUnBind)(&hDs);
  720. }
  721. }
  722. if ( hLibrary )
  723. {
  724. FreeLibrary(hLibrary);
  725. }
  726. }
  727. if (UStrCmp(text,L"0") && UStrCmp(text,L""))
  728. {
  729. int number=_ttoi((WCHAR * const) text);
  730. CString base,loader;
  731. _bstr_t text;
  732. for (int i=0;i<number;i++)
  733. {
  734. some=true;
  735. base.Format(L"Computer.%d",i);
  736. text= pVarSetMerge->get(_bstr_t(base));
  737. loader.Format(L"Computer.%d",count);
  738. pVarSetService->put(_bstr_t(loader),text);
  739. base.Format(L"Service.%d",i);
  740. text= pVarSetMerge->get(_bstr_t(base));
  741. loader.Format(L"Service.%d",count);
  742. pVarSetService->put(_bstr_t(loader),text);
  743. base.Format(L"ServiceAccount.%d",i);
  744. text= pVarSetMerge->get(_bstr_t(base));
  745. //store the sAMAccountName in the varset and database rather
  746. //than the UPN name
  747. wcscpy((WCHAR*)text, domAcct);
  748. loader.Format(L"ServiceAccount.%d",count);
  749. pVarSetService->put(_bstr_t(loader),text);
  750. base.Format(L"ServiceAccountStatus.%d",i);
  751. text= pVarSetMerge->get(_bstr_t(base));
  752. loader.Format(L"ServiceAccountStatus.%d",count);
  753. pVarSetService->put(_bstr_t(loader),text);
  754. base.Format(L"ServiceDisplayName.%d",i);
  755. text= pVarSetMerge->get(_bstr_t(base));
  756. loader.Format(L"ServiceDisplayName.%d",count);
  757. pVarSetService->put(_bstr_t(loader),text);
  758. count++;
  759. pVarSetService->put(L"ServiceAccountEntries",(long) count);
  760. }
  761. }
  762. }
  763. }
  764. pUnk->Release();
  765. return some;
  766. }
  767. CString timeToCString(int varsetKey)
  768. {
  769. _bstr_t text;
  770. time_t t;
  771. CString s;
  772. CString t2;
  773. text = pVarSet->get(GET_BSTR(varsetKey));
  774. t2 = (WCHAR * ) text;
  775. t2.TrimLeft();t2.TrimRight();
  776. if ((t2.IsEmpty() != FALSE) || (!t2.CompareNoCase(L"0")))
  777. {
  778. s.LoadString(IDS_NOT_CREATED);
  779. }
  780. else
  781. {
  782. //* t = _ttoi((WCHAR const *)text);
  783. //* CTime T(t);
  784. //* s = T.Format( "%c" );
  785. t = _ttoi((WCHAR const *)text);
  786. SYSTEMTIME stime;
  787. CTime ctime;
  788. ctime = t;
  789. stime.wYear = (WORD) ctime.GetYear();
  790. stime.wMonth = (WORD) ctime.GetMonth();
  791. stime.wDayOfWeek = (WORD) ctime.GetDayOfWeek();
  792. stime.wDay = (WORD) ctime.GetDay();
  793. stime.wHour = (WORD) ctime.GetHour();
  794. stime.wMinute = (WORD) ctime.GetMinute();
  795. stime.wSecond = (WORD) ctime.GetSecond();
  796. stime.wMilliseconds = 0;
  797. //* if ( ctime.GetAsSystemTime(stime) )
  798. //* {
  799. CString t1;
  800. CString t2;
  801. GetTimeFormat(LOCALE_USER_DEFAULT,0,&stime,NULL,t1.GetBuffer(500),500);
  802. GetDateFormat(LOCALE_USER_DEFAULT,0,&stime,NULL,t2.GetBuffer(500),500);
  803. t1.ReleaseBuffer();
  804. t2.ReleaseBuffer();
  805. s = t2 + " " + t1;
  806. //* }
  807. }
  808. return s;
  809. }
  810. _variant_t get(int i)
  811. {
  812. return pVarSet->get(GET_BSTR(i));
  813. }
  814. void put(int i,_variant_t v)
  815. {
  816. pVarSet->put(GET_BSTR(i),v);
  817. }
  818. void getReporting()
  819. {
  820. _bstr_t temp;
  821. CString c;
  822. c.LoadString(IDS_COLUMN_NAMECONFLICTS);
  823. m_reportingBox.InsertItem(0,c);
  824. SetItemText(m_reportingBox,0, 1, timeToCString(DCTVS_Reports_NameConflicts_TimeGenerated));
  825. c.LoadString(IDS_COLUMN_ACCOUNTREFERENCES);
  826. m_reportingBox.InsertItem(0,c);
  827. SetItemText(m_reportingBox,0, 1, timeToCString(DCTVS_Reports_AccountReferences_TimeGenerated));
  828. c.LoadString(IDS_COLUMN_EXPIREDCOMPUTERS);
  829. m_reportingBox.InsertItem(0,c);
  830. SetItemText(m_reportingBox,0, 1, timeToCString(DCTVS_Reports_ExpiredComputers_TimeGenerated));
  831. c.LoadString(IDS_COLUMN_MIGRATEDCOMPUTERS);
  832. m_reportingBox.InsertItem(0,c);
  833. SetItemText(m_reportingBox,0, 1, timeToCString(DCTVS_Reports_MigratedComputers_TimeGenerated));
  834. c.LoadString(IDS_COLUMN_MIGRATEDACCOUNTS);
  835. m_reportingBox.InsertItem(0,c);
  836. SetItemText(m_reportingBox,0, 1, timeToCString(DCTVS_Reports_MigratedAccounts_TimeGenerated));
  837. }
  838. void putReporting()
  839. {
  840. _variant_t varX;
  841. int nItem;
  842. bool atleast1 =false;
  843. // POSITION pos = m_reportingBox.GetFirstSelectedItemPosition();
  844. // while (pos)
  845. // {
  846. // atleast1 = true;
  847. // nItem = m_reportingBox.GetNextSelectedItem(pos);
  848. nItem = m_reportingBox.GetNextItem(-1, LVNI_SELECTED);//PRT
  849. while (nItem != -1)//PRT
  850. {
  851. atleast1 = true;
  852. SetCheck(m_reportingBox,nItem,false);
  853. nItem = m_reportingBox.GetNextItem(nItem, LVNI_SELECTED);//PRT
  854. }
  855. varX = (!GetCheck(m_reportingBox,0)) ? yes : no;
  856. put(DCTVS_Reports_MigratedAccounts,varX);
  857. varX = (!GetCheck(m_reportingBox,1)) ? yes : no;
  858. put(DCTVS_Reports_MigratedComputers,varX);
  859. varX = (!GetCheck(m_reportingBox,2)) ? yes : no;
  860. put(DCTVS_Reports_ExpiredComputers,varX);
  861. varX = (!GetCheck(m_reportingBox,3)) ? yes : no;
  862. put(DCTVS_Reports_AccountReferences,varX);
  863. varX = (!GetCheck(m_reportingBox,4)) ? yes : no;
  864. put(DCTVS_Reports_NameConflicts,varX);
  865. varX = atleast1 ? yes : no;
  866. put(DCTVS_Reports_Generate,varX);
  867. for (int i = 0; i< m_reportingBox.GetItemCount();i++)
  868. SetCheck(m_reportingBox,i,true);
  869. }
  870. void populateReportingTime()
  871. {
  872. _variant_t varX;
  873. _bstr_t text;
  874. CString temp;
  875. time_t ltime;
  876. time(&ltime);
  877. temp.Format(L"%d",ltime);
  878. varX = temp;
  879. if (!UStrICmp((text = get(DCTVS_Reports_MigratedAccounts)),(WCHAR const *) yes))
  880. put(DCTVS_Reports_MigratedAccounts_TimeGenerated,varX);
  881. if (!UStrICmp((text = get(DCTVS_Reports_MigratedComputers)),(WCHAR const *) yes))
  882. put(DCTVS_Reports_MigratedComputers_TimeGenerated,varX);
  883. if (!UStrICmp((text = get(DCTVS_Reports_ExpiredComputers)),(WCHAR const *) yes))
  884. put(DCTVS_Reports_ExpiredComputers_TimeGenerated,varX);
  885. if (!UStrICmp((text = get(DCTVS_Reports_AccountReferences)),(WCHAR const *) yes))
  886. put(DCTVS_Reports_AccountReferences_TimeGenerated,varX);
  887. if (!UStrICmp((text = get(DCTVS_Reports_NameConflicts)),(WCHAR const *) yes))
  888. put(DCTVS_Reports_NameConflicts_TimeGenerated,varX);
  889. }
  890. void getFailed(HWND hwndDlg)
  891. {
  892. IVarSetPtr pVarSetFailed(__uuidof(VarSet));
  893. IUnknown * pUnk;
  894. pVarSetFailed->QueryInterface(IID_IUnknown, (void**) &pUnk);
  895. HRESULT hr = db->GetFailedDistributedActions(-1, &pUnk);
  896. pUnk->Release();
  897. if (FAILED(hr))
  898. MessageBoxWrapper(hwndDlg,IDS_MSG_FAILED,IDS_MSG_ERROR);
  899. else
  900. {
  901. CString toLoad;
  902. CString holder;
  903. _bstr_t text;
  904. CString skip;
  905. skip.LoadString(IDS_SKIP);
  906. int i=0;
  907. _bstr_t numItemsText = pVarSetFailed->get(L"DA");
  908. CString jobHelper;
  909. if (UStrCmp(numItemsText,L"0") && UStrCmp(numItemsText,L""))
  910. {
  911. int numItems = _ttoi( (WCHAR const *) numItemsText);
  912. while (i<numItems)
  913. {
  914. holder.Format(L"DA.%d" ,i);
  915. toLoad = holder + L".Server";
  916. text = pVarSetFailed->get(_bstr_t(toLoad));
  917. m_cancelBox.InsertItem(0,(WCHAR const *)text);
  918. toLoad = holder + L".JobFile";
  919. text = pVarSetFailed->get(_bstr_t(toLoad));
  920. SetItemText(m_cancelBox,0,1,(WCHAR const *)text);
  921. JobFileGetActionText((WCHAR * const) text,jobHelper);
  922. SetItemText(m_cancelBox,0,3,jobHelper);
  923. toLoad = holder + L".StatusText";
  924. text = pVarSetFailed->get(_bstr_t(toLoad));
  925. SetItemText(m_cancelBox,0,2,(WCHAR const *)text);
  926. toLoad = holder + L".ActionID";
  927. text = pVarSetFailed->get(_bstr_t(toLoad));
  928. SetItemText(m_cancelBox,0,4,(WCHAR const *)text);
  929. SetItemText(m_cancelBox,0,5,skip);
  930. i++;
  931. }
  932. }
  933. }
  934. }
  935. void handleCancel(HWND hwndDlg)
  936. {
  937. int nItem;
  938. HRESULT hr=S_OK;
  939. long lActionID;
  940. CString computer;
  941. CString actionID;
  942. // POSITION pos = m_cancelBox.GetFirstSelectedItemPosition();
  943. // while (pos)
  944. // {
  945. // nItem = m_cancelBox.GetNextSelectedItem(pos);
  946. nItem = m_cancelBox.GetNextItem(-1, LVNI_SELECTED);//PRT
  947. while (nItem != -1)//PRT
  948. {
  949. SetCheck(m_cancelBox,nItem,false);
  950. nItem = m_cancelBox.GetNextItem(nItem, LVNI_SELECTED);//PRT
  951. }
  952. for (int i=(m_cancelBox.GetItemCount()-1);i>=0;i--)
  953. {
  954. if (!GetCheck(m_cancelBox,i))
  955. {
  956. computer = m_cancelBox.GetItemText(i,0);
  957. actionID = m_cancelBox.GetItemText(i,4);
  958. lActionID = _ttol(actionID.GetBuffer(500));
  959. actionID.ReleaseBuffer();
  960. hr = db->CancelDistributedAction(lActionID, _bstr_t(computer));
  961. if (FAILED(hr))
  962. MessageBoxWrapper(hwndDlg,IDC_MSG_CANCEL,IDS_MSG_ERROR);
  963. else
  964. m_cancelBox.DeleteItem(i);
  965. }
  966. }
  967. }
  968. bool OnRETRY(HWND hwndDlg)
  969. {
  970. bool bRetry = true;
  971. int count =0;
  972. CString holder,c;
  973. _variant_t varX;
  974. CString include;
  975. include.LoadString(IDS_INCLUDE);
  976. for (int i=0;i<m_cancelBox.GetItemCount();i++)
  977. {
  978. c = m_cancelBox.GetItemText(i,5);
  979. if (c== include)
  980. {
  981. CString strActionId = m_cancelBox.GetItemText(i, 4);
  982. CString strName = L"\\\\" + m_cancelBox.GetItemText(i, 0);
  983. BSTR bstrDnsName = NULL;
  984. BSTR bstrFlatName = NULL;
  985. HRESULT hr = db->GetServerNamesFromActionHistory(
  986. _variant_t((PCWSTR)strActionId),
  987. _bstr_t((PCWSTR)strName),
  988. &bstrFlatName,
  989. &bstrDnsName
  990. );
  991. if (SUCCEEDED(hr))
  992. {
  993. if (hr == S_OK)
  994. {
  995. if (bstrFlatName)
  996. {
  997. holder.Format(L"Servers.%d",count);
  998. pVarSet->put(_bstr_t(holder),_bstr_t(bstrFlatName, false));
  999. if (bstrDnsName)
  1000. {
  1001. holder.Format(L"Servers.%d.DnsName",count);
  1002. pVarSet->put(_bstr_t(holder),_bstr_t(bstrDnsName, false));
  1003. }
  1004. varX = m_cancelBox.GetItemText(i,1);
  1005. holder.Format(L"Servers.%d.JobFile",count);
  1006. pVarSet->put(_bstr_t(holder),varX);
  1007. count++;
  1008. }
  1009. else
  1010. {
  1011. MessageBoxWrapperFormat1P(hwndDlg, IDS_MSG_UNABLE_RETRIEVE_SERVER_INFO, IDS_MSG_ERROR, m_cancelBox.GetItemText(i, 0));
  1012. bRetry = false;
  1013. break;
  1014. }
  1015. }
  1016. else
  1017. {
  1018. MessageBoxWrapperFormat1P(hwndDlg, IDS_MSG_UNABLE_RETRIEVE_SERVER_INFO, IDS_MSG_ERROR, m_cancelBox.GetItemText(i, 0));
  1019. bRetry = false;
  1020. break;
  1021. }
  1022. }
  1023. else
  1024. {
  1025. ErrorWrapper(hwndDlg, hr);
  1026. bRetry = false;
  1027. break;
  1028. }
  1029. }
  1030. }
  1031. holder = L"Servers.NumItems";
  1032. pVarSet->put(_bstr_t(holder),(long)count);
  1033. return bRetry;
  1034. }
  1035. void JobFileGetActionText(WCHAR const * filename // in - job file name
  1036. ,CString & text // in/out - text describing the action
  1037. )
  1038. {
  1039. // load the varset into a file
  1040. // Read the varset data from the file
  1041. IVarSetPtr pVarSet;
  1042. IStorage * store = NULL;
  1043. HRESULT hr;
  1044. // Try to create the COM objects
  1045. hr = pVarSet.CreateInstance(CLSID_VarSet);
  1046. if ( SUCCEEDED(hr) )
  1047. {
  1048. // Read the VarSet from the data file
  1049. hr = StgOpenStorage(filename,NULL,STGM_DIRECT | STGM_READ | STGM_SHARE_EXCLUSIVE,NULL,0,&store);
  1050. if ( SUCCEEDED(hr) )
  1051. {
  1052. // Load the data into a new varset
  1053. hr = OleLoad(store,IID_IUnknown,NULL,(void **)&pVarSet);
  1054. if ( SUCCEEDED(hr) )
  1055. {
  1056. _bstr_t wizard = pVarSet->get(GET_BSTR(DCTVS_Options_Wizard));
  1057. //* if ( !UStrICmp(wizard,(WCHAR const *) GET_BSTR1(IDS_WIZARD_COMPUTER) ))
  1058. if ( !UStrICmp(wizard, L"computer"))
  1059. {
  1060. text = GET_CSTRING(IDS_MIGRATE_COMPUTER);
  1061. }
  1062. //* else if ( !UStrICmp(wizard,(WCHAR const *)GET_BSTR1(IDS_WIZARD_SERVICE) ))
  1063. else if ( !UStrICmp(wizard, L"service"))
  1064. {
  1065. text = GET_CSTRING(IDS_GATHER_SERVICEACCOUNT);
  1066. }
  1067. //* else if ( ! UStrICmp(wizard,(WCHAR const *)GET_BSTR1(IDS_WIZARD_SECURITY) ))
  1068. else if ( ! UStrICmp(wizard, L"security"))
  1069. {
  1070. text = GET_CSTRING(IDS_TRANSLATE_SECURITY);
  1071. }
  1072. //* else if (! UStrICmp(wizard,(WCHAR const *) GET_BSTR1(IDS_WIZARD_REPORTING)) )
  1073. else if (! UStrICmp(wizard, L"reporting") )
  1074. {
  1075. text = GET_CSTRING(IDS_GATHER_INFORMATION);
  1076. }
  1077. else
  1078. {
  1079. text = (WCHAR*)wizard;
  1080. }
  1081. }
  1082. store->Release();
  1083. }
  1084. }
  1085. }
  1086. _bstr_t GET_BSTR1(int id)
  1087. {
  1088. CString yo;
  1089. yo.LoadString(id);
  1090. return (LPCTSTR)yo;
  1091. }
  1092. void activateCancelIfNecessary(HWND hwndDlg)
  1093. {
  1094. // POSITION pos = m_cancelBox.GetFirstSelectedItemPosition();
  1095. // if (pos)
  1096. int nItem = m_cancelBox.GetNextItem(-1, LVNI_SELECTED);//PRT
  1097. if (nItem != -1)//PRT
  1098. {
  1099. enable(hwndDlg,IDC_CANCEL);
  1100. enable(hwndDlg,IDC_TOGGLE);
  1101. }
  1102. else
  1103. {
  1104. disable(hwndDlg,IDC_CANCEL);
  1105. disable(hwndDlg,IDC_TOGGLE);
  1106. }
  1107. }
  1108. bool SomethingToRetry()
  1109. {
  1110. if (m_cancelBox.GetItemCount()==0) return false;
  1111. int count =0;
  1112. CString include;
  1113. include.LoadString(IDS_INCLUDE);
  1114. CString c;
  1115. for (int i=0;i<m_cancelBox.GetItemCount();i++)
  1116. {
  1117. c = m_cancelBox.GetItemText(i,5);
  1118. if (c== include)
  1119. {
  1120. return true;
  1121. }
  1122. }
  1123. return false;
  1124. }
  1125. void OnFileBrowse(HWND hwndDlg,int id)
  1126. {
  1127. CWnd yo;
  1128. yo.Attach(hwndDlg);
  1129. CString sDir = L"", sFile = L"", sPath = L"";
  1130. CFileDialog f(FALSE,
  1131. L"",
  1132. GET_CSTRING(IDS_PASSWORDS),
  1133. OFN_LONGNAMES | OFN_NOREADONLYRETURN,
  1134. GET_CSTRING(IDS_MASKS),
  1135. &yo);
  1136. GetDlgItemText(hwndDlg, id, sPath.GetBuffer(1000), 1000);
  1137. sPath.ReleaseBuffer();
  1138. if (sPath.GetLength())
  1139. GetValidPathPart(sPath, sDir, sFile);
  1140. f.m_ofn.lpstrInitialDir = sDir.GetBuffer(1000);
  1141. f.m_ofn.lpstrFile = sFile.GetBuffer(1000);
  1142. if ( f.DoModal() == IDOK )
  1143. {
  1144. SetDlgItemText(hwndDlg,id,f.GetPathName());
  1145. }
  1146. yo.Detach();
  1147. sFile.ReleaseBuffer();
  1148. sDir.ReleaseBuffer();
  1149. }
  1150. void ShowWarning(HWND hwndDlg)
  1151. {
  1152. CString warning,base,title;
  1153. IAccessCheckerPtr pAC;
  1154. HRESULT hr = pAC.CreateInstance(CLSID_AccessChecker);
  1155. long length;
  1156. hr = pAC->raw_GetPasswordPolicy(_bstr_t(GetTargetDomainName()),&length);
  1157. if ( !SUCCEEDED(hr) )
  1158. {
  1159. ErrorWrapper2(hwndDlg,hr);
  1160. }
  1161. else
  1162. {
  1163. if (length>0)
  1164. {
  1165. base.Format(L"%lu",length);
  1166. warning.LoadString(IDS_MSG_WARNING_LENGTH);
  1167. base+=warning;
  1168. title.LoadString(IDS_MSG_WARNING);
  1169. MessageBox(hwndDlg,base,title,MB_OK|MB_ICONINFORMATION);
  1170. }
  1171. }
  1172. }
  1173. bool obtainTrustCredentials(HWND hwndDlg,int spot, CString & domain, CString & account, CString & password)
  1174. {
  1175. bool toreturn;
  1176. CWnd yo;
  1177. yo.Attach(hwndDlg);
  1178. CTrusterDlg truster(&yo);
  1179. truster.len = MAX_PATH;
  1180. _bstr_t strNameDns;
  1181. _bstr_t strNameFlat;
  1182. DWORD dwError = GetDomainNames5(m_trustBox.GetItemText(spot,0), strNameFlat, strNameDns);
  1183. if (dwError == ERROR_SUCCESS)
  1184. {
  1185. truster.m_strDomain = (LPCTSTR)strNameFlat;
  1186. }
  1187. else
  1188. {
  1189. truster.m_strDomain = m_trustBox.GetItemText(spot,0);
  1190. }
  1191. truster.DoModal();
  1192. toreturn = truster.toreturn;
  1193. if ( toreturn )
  1194. {
  1195. domain = truster.m_strDomain;
  1196. account = truster.m_strUser;
  1197. password = truster.m_strPassword;
  1198. }
  1199. yo.Detach();
  1200. return toreturn;
  1201. }
  1202. CString GET_CSTRING(int id)
  1203. {
  1204. CString c;
  1205. c.LoadString(id);
  1206. return c;
  1207. }
  1208. HRESULT MigrateTrusts(HWND hwndDlg,bool& atleast1succeeded,CString& errorDomain)
  1209. {
  1210. ITrustPtr pTrusts;
  1211. IUnknown * pUnk = NULL;
  1212. // int i=m_trustBox.GetSelectionMark();
  1213. int i=m_trustBox.GetNextItem(-1, LVNI_SELECTED);//PRT
  1214. CString trusted,trusting,direction;
  1215. HRESULT hr = pTrusts.CreateInstance(CLSID_Trust);
  1216. CString strDomain,strAccount,strPassword;
  1217. atleast1succeeded=false;
  1218. BOOL bErrorFromTrusting;
  1219. BOOL bErrorFromTrusted;
  1220. errorDomain.Empty();
  1221. if ( SUCCEEDED(hr) )
  1222. {
  1223. CWaitCursor s;
  1224. direction = m_trustBox.GetItemText(i,1);
  1225. direction.TrimLeft();
  1226. direction.TrimRight();
  1227. if (direction == GET_CSTRING(IDS_OUTBOUND))
  1228. {
  1229. trusting = GetTargetDomainName();
  1230. trusted = m_trustBox.GetItemText(i,0);
  1231. hr = pTrusts->raw_CreateTrust(_bstr_t(trusting),_bstr_t(trusted),FALSE,(long*)&bErrorFromTrusting,(long*)&bErrorFromTrusted);
  1232. if (HRESULT_CODE(hr) == ERROR_ACCESS_DENIED)
  1233. if (obtainTrustCredentials(hwndDlg,i,strDomain, strAccount, strPassword))
  1234. hr = pTrusts->raw_CreateTrustWithCreds(_bstr_t(trusting),_bstr_t(trusted),
  1235. NULL,NULL,NULL,_bstr_t(strDomain),_bstr_t(strAccount),
  1236. _bstr_t(strPassword),FALSE,(long*)&bErrorFromTrusting,(long*)&bErrorFromTrusted);
  1237. }
  1238. else if (direction == GET_CSTRING(IDS_INBOUND))
  1239. {
  1240. trusting = m_trustBox.GetItemText(i,0);
  1241. trusted = GetTargetDomainName();
  1242. hr = pTrusts->raw_CreateTrust(_bstr_t(trusting),_bstr_t(trusted),FALSE,(long*)&bErrorFromTrusting,(long*)&bErrorFromTrusted);
  1243. if (HRESULT_CODE(hr) == ERROR_ACCESS_DENIED)
  1244. if (obtainTrustCredentials(hwndDlg,i,strDomain, strAccount, strPassword))
  1245. hr = pTrusts->raw_CreateTrustWithCreds(_bstr_t(trusting),_bstr_t(trusted),
  1246. _bstr_t(strDomain),_bstr_t(strAccount),
  1247. _bstr_t(strPassword),NULL,NULL,NULL,FALSE,(long*)&bErrorFromTrusting,(long*)&bErrorFromTrusted);
  1248. }
  1249. else if (direction == GET_CSTRING(IDS_BIDIRECTIONAL))
  1250. {
  1251. trusting = m_trustBox.GetItemText(i,0);
  1252. trusted = GetTargetDomainName();
  1253. hr = pTrusts->raw_CreateTrust(_bstr_t(trusting),_bstr_t(trusted),TRUE,(long*)&bErrorFromTrusting,(long*)&bErrorFromTrusted);
  1254. if (HRESULT_CODE(hr) == ERROR_ACCESS_DENIED)
  1255. if (obtainTrustCredentials(hwndDlg,i,strDomain, strAccount, strPassword))
  1256. hr = pTrusts->raw_CreateTrustWithCreds(_bstr_t(trusting),_bstr_t(trusted),
  1257. _bstr_t(strDomain),_bstr_t(strAccount),
  1258. _bstr_t(strPassword),NULL,NULL,NULL,TRUE,(long*)&bErrorFromTrusting,(long*)&bErrorFromTrusted);
  1259. }
  1260. if (direction == GET_CSTRING(IDS_DISABLED))
  1261. {
  1262. MessageBoxWrapper(hwndDlg,IDS_MSG_DISABLED_TRUST,IDS_MSG_ERROR);
  1263. }
  1264. else if (direction.IsEmpty() != FALSE)
  1265. {
  1266. MessageBoxWrapper(hwndDlg,IDS_MSG_DIRECTION_TRUST,IDS_MSG_ERROR);
  1267. }
  1268. else
  1269. {
  1270. if ( SUCCEEDED(hr) )
  1271. {
  1272. // update the UI to reflect that the trust now exists
  1273. m_trustBox.SetItemText(i,3,GET_BSTR(IDS_YES));
  1274. atleast1succeeded=true;
  1275. }
  1276. else
  1277. {
  1278. if (bErrorFromTrusting)
  1279. errorDomain = trusting;
  1280. else if (bErrorFromTrusted)
  1281. errorDomain = trusted;
  1282. }
  1283. }
  1284. }
  1285. return hr;
  1286. }
  1287. void getTrust()
  1288. {
  1289. // get the trust relationship data
  1290. ITrustPtr pTrusts;
  1291. // CWaitCursor wait;
  1292. HRESULT hr = pTrusts.CreateInstance(CLSID_Trust);
  1293. if ( SUCCEEDED(hr) )
  1294. {
  1295. IUnknown * pUnk = NULL;
  1296. CString dirname;
  1297. GetDirectory(dirname.GetBuffer(1000));
  1298. dirname.ReleaseBuffer();
  1299. dirname+= L"Logs\\trust.log";
  1300. hr = pTrusts->raw_QueryTrusts(_bstr_t(GetSourceDomainName()),_bstr_t(GetTargetDomainName()),_bstr_t(dirname),&pUnk);
  1301. if ( SUCCEEDED(hr) )
  1302. {
  1303. IVarSetPtr pVsTrusts;
  1304. pVsTrusts = pUnk;
  1305. pUnk->Release();
  1306. long nTrusts = pVsTrusts->get(L"Trusts");
  1307. for ( long i = 0 ; i < nTrusts ; i++ )
  1308. {
  1309. CString base;
  1310. CString sub;
  1311. base.Format(L"Trusts.%ld",i);
  1312. _bstr_t value = pVsTrusts->get(_bstr_t(base));
  1313. m_trustBox.InsertItem(0,value);
  1314. sub = base + L".Direction";
  1315. value = pVsTrusts->get(_bstr_t(sub));
  1316. SetItemText(m_trustBox,0,1,value);
  1317. sub = base + L".Type";
  1318. value = pVsTrusts->get(_bstr_t(sub));
  1319. SetItemText(m_trustBox,0,2,value);
  1320. sub = base + L".ExistsForTarget";
  1321. value = pVsTrusts->get(_bstr_t(sub));
  1322. SetItemText(m_trustBox,0,3,value);
  1323. }
  1324. }
  1325. }
  1326. }
  1327. bool number(CString num)
  1328. {
  1329. if (num.GetLength()==0) return false;
  1330. CString checker;
  1331. checker.LoadString(IDS_VALID_DIGITS);
  1332. for (int i=0;i<num.GetLength();i++)
  1333. {
  1334. if (checker.Find(num.GetAt(i)) == -1)
  1335. return false;
  1336. }
  1337. return true;
  1338. }
  1339. bool timeInABox(HWND hwndDlg,time_t& t)
  1340. {
  1341. CString s;
  1342. GetDlgItemText(hwndDlg,IDC_yo,s.GetBuffer(1000),1000);
  1343. s.ReleaseBuffer();
  1344. s.TrimLeft();s.TrimRight();
  1345. if (!number(s)) return false;
  1346. int num=_ttoi((LPTSTR const) s.GetBuffer(1000));
  1347. s.ReleaseBuffer();
  1348. if (num > THREE_YEARS || num < 1) return false;
  1349. DWORD nDays = num;
  1350. DWORD oneDay = 24 * 60 * 60; // number of seconds in 1 day
  1351. time_t currentTime = time(NULL);
  1352. time_t expireTime;
  1353. expireTime = currentTime + nDays * oneDay;
  1354. //expireTime-=currentTime%86400;
  1355. t= expireTime;
  1356. return true;
  1357. }
  1358. HRESULT GetHelpFileFullPath( BSTR *bstrHelp )
  1359. {
  1360. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1361. CString strPath, strName;
  1362. HRESULT hr = S_OK;
  1363. TCHAR szModule[2*_MAX_PATH];
  1364. DWORD dwReturn = 0;
  1365. GetDirectory(szModule);
  1366. strPath = szModule;
  1367. strPath += _T("\\");
  1368. strName.LoadString(IDS_HELPFILE);
  1369. strPath += strName;
  1370. *bstrHelp = SysAllocString(LPCTSTR(strPath));
  1371. return hr;
  1372. }
  1373. void helpWrapper(HWND hwndDlg, int t)
  1374. {
  1375. CComBSTR bstrTopic;
  1376. HRESULT hr = GetHelpFileFullPath( &bstrTopic);
  1377. if ( SUCCEEDED(hr) )
  1378. {
  1379. HWND h = HtmlHelp(hwndDlg, bstrTopic, HH_HELP_CONTEXT, t );
  1380. if (!IsInWorkArea(h))
  1381. PlaceInWorkArea(h);
  1382. }
  1383. else
  1384. {
  1385. CString r,e;
  1386. r.LoadString(IDS_MSG_HELP);
  1387. e.LoadString(IDS_MSG_ERROR);
  1388. MessageBox(hwndDlg,r,e,MB_OK|MB_ICONSTOP);
  1389. }
  1390. }
  1391. bool IsDlgItemEmpty(HWND hwndDlg, int id)
  1392. {
  1393. CString temp;
  1394. GetDlgItemText( hwndDlg, id, temp.GetBuffer(1000),1000);
  1395. temp.ReleaseBuffer();
  1396. temp.TrimLeft();
  1397. temp.TrimRight();
  1398. return (temp.IsEmpty()!= FALSE);
  1399. }
  1400. void calculateDate(HWND hwndDlg,CString s)
  1401. {
  1402. s.TrimLeft();s.TrimRight();
  1403. if (!number(s)) return;
  1404. long nDays=_ttol((LPTSTR const) s.GetBuffer(1000));
  1405. s.ReleaseBuffer();
  1406. long oneDay = 24 * 60 * 60; // number of seconds in 1 day
  1407. time_t currentTime = time(NULL);
  1408. time_t expireTime;
  1409. CTime ctime;
  1410. SYSTEMTIME stime;
  1411. CString strDate;
  1412. expireTime = currentTime + nDays * oneDay;
  1413. ctime = expireTime;
  1414. stime.wYear = (WORD) ctime.GetYear();
  1415. stime.wMonth = (WORD) ctime.GetMonth();
  1416. stime.wDayOfWeek = (WORD) ctime.GetDayOfWeek();
  1417. stime.wDay = (WORD) ctime.GetDay();
  1418. stime.wHour = (WORD) ctime.GetHour();
  1419. stime.wMinute = (WORD) ctime.GetMinute();
  1420. stime.wSecond = (WORD) ctime.GetSecond();
  1421. stime.wMilliseconds = 0;
  1422. GetDateFormat(LOCALE_USER_DEFAULT,0,&stime,NULL,strDate.GetBuffer(500),500);
  1423. strDate.ReleaseBuffer();
  1424. SetDlgItemText(hwndDlg,IDC_DATE,strDate);
  1425. }
  1426. void ErrorWrapper(HWND hwndDlg,HRESULT returncode)
  1427. {
  1428. CString y,e,text,title;
  1429. if (HRESULT_FACILITY(returncode)==FACILITY_WIN32)
  1430. {
  1431. returncode=HRESULT_CODE(returncode);
  1432. err.ErrorCodeToText(returncode,1000,y.GetBuffer(1000));
  1433. y.ReleaseBuffer();
  1434. text.LoadString(IDS_MSG_ERRORBUF);
  1435. e.Format(text,y,returncode);
  1436. title.LoadString(IDS_MSG_ERROR);
  1437. MessageBox(hwndDlg,e,title,MB_OK|MB_ICONSTOP);
  1438. }
  1439. else
  1440. {
  1441. err.ErrorCodeToText(returncode,1000,y.GetBuffer(1000));
  1442. y.ReleaseBuffer();
  1443. text.LoadString(IDS_MSG_ERRORBUF);
  1444. // text.Replace(L"%u",L"%x");
  1445. int index = text.Find(L"%u"); //PRT
  1446. text.SetAt(index+1, L'x'); //PRT
  1447. e.Format(text,y,returncode);
  1448. title.LoadString(IDS_MSG_ERROR);
  1449. MessageBox(hwndDlg,e,title,MB_OK|MB_ICONSTOP);
  1450. }
  1451. }
  1452. void ErrorWrapper2(HWND hwndDlg,HRESULT returncode)
  1453. {
  1454. CString y,e,text,title,message;
  1455. if (HRESULT_FACILITY(returncode)==FACILITY_WIN32)
  1456. {
  1457. returncode=HRESULT_CODE(returncode);
  1458. err.ErrorCodeToText(returncode,1000,y.GetBuffer(1000));
  1459. y.ReleaseBuffer();
  1460. message.LoadString(IDS_MSG_PASSWORD_POLICY);
  1461. text.LoadString(IDS_MSG_ERRORBUF20);
  1462. e.Format(text,message,y,returncode);
  1463. title.LoadString(IDS_MSG_WARNING);
  1464. MessageBox(hwndDlg,e,title,MB_OK|MB_ICONSTOP);
  1465. }
  1466. else
  1467. {
  1468. err.ErrorCodeToText(returncode,1000,y.GetBuffer(1000));
  1469. y.ReleaseBuffer();
  1470. message.LoadString(IDS_MSG_PASSWORD_POLICY);
  1471. text.LoadString(IDS_MSG_ERRORBUF20);
  1472. // text.Replace(L"%u",L"%x");
  1473. int index = text.Find(L"%u"); //PRT
  1474. text.SetAt(index+1, L'x'); //PRT
  1475. e.Format(text,message,y,returncode);
  1476. title.LoadString(IDS_MSG_WARNING);
  1477. MessageBox(hwndDlg,e,title,MB_OK|MB_ICONSTOP);
  1478. }
  1479. }
  1480. void ErrorWrapper3(HWND hwndDlg,HRESULT returncode,CString domainName)
  1481. {
  1482. CString y,e,text,title,formatter;
  1483. if (HRESULT_FACILITY(returncode)==FACILITY_WIN32)
  1484. {
  1485. returncode=HRESULT_CODE(returncode);
  1486. err.ErrorCodeToText(returncode,1000,e.GetBuffer(1000));
  1487. e.ReleaseBuffer();
  1488. formatter.LoadString(IDS_MSG_ERRORBUF3);
  1489. text.Format(formatter,e,returncode,domainName);
  1490. title.LoadString(IDS_MSG_ERROR);
  1491. MessageBox(hwndDlg,text,title,MB_OK|MB_ICONSTOP);
  1492. }
  1493. else
  1494. {
  1495. err.ErrorCodeToText(returncode,1000,e.GetBuffer(1000));
  1496. e.ReleaseBuffer();
  1497. formatter.LoadString(IDS_MSG_ERRORBUF3);
  1498. // formatter.Replace(L"%u",L"%x");
  1499. int index = formatter.Find(L"%u"); //PRT
  1500. formatter.SetAt(index+1, L'x'); //PRT
  1501. text.Format(formatter,e,returncode,domainName);
  1502. title.LoadString(IDS_MSG_ERROR);
  1503. MessageBox(hwndDlg,text,title,MB_OK|MB_ICONSTOP);
  1504. }
  1505. }
  1506. void ErrorWrapper4(HWND hwndDlg,HRESULT returncode,CString domainName)
  1507. {
  1508. CString y,e,text,title,formatter;
  1509. if (HRESULT_FACILITY(returncode)==FACILITY_WIN32)
  1510. {
  1511. returncode=HRESULT_CODE(returncode);
  1512. err.ErrorCodeToText(returncode,1000,e.GetBuffer(1000));
  1513. e.ReleaseBuffer();
  1514. formatter.LoadString(IDS_MSG_ERRORBUF2);
  1515. text.Format(formatter,e,returncode,domainName);
  1516. title.LoadString(IDS_MSG_ERROR);
  1517. MessageBox(hwndDlg,text,title,MB_OK|MB_ICONSTOP);
  1518. }
  1519. else
  1520. { err.ErrorCodeToText(returncode,1000,e.GetBuffer(1000));
  1521. e.ReleaseBuffer();
  1522. formatter.LoadString(IDS_MSG_ERRORBUF2);
  1523. // formatter.Replace(L"%u",L"%x");
  1524. int index = formatter.Find(L"%u"); //PRT
  1525. formatter.SetAt(index+1, L'x'); //PRT
  1526. text.Format(formatter,e,returncode,domainName);
  1527. title.LoadString(IDS_MSG_ERROR);
  1528. MessageBox(hwndDlg,text,title,MB_OK|MB_ICONSTOP);
  1529. }
  1530. }
  1531. bool validDir(CString str)
  1532. {
  1533. CFileFind finder;
  1534. // build a string with wildcards
  1535. str += _T("\\*.*");
  1536. // start working for files
  1537. BOOL bWorking = finder.FindFile(str);
  1538. if (bWorking==0)
  1539. {
  1540. finder.Close();
  1541. return false;
  1542. }
  1543. bWorking = finder.FindNextFile();
  1544. bool toreturn = (finder.IsDirectory()? true:false);
  1545. //some root drives do not have the directory flag set, so convert to
  1546. //the root path and use it
  1547. if (!toreturn)
  1548. {
  1549. str = finder.GetRoot();
  1550. if (str.GetLength())
  1551. toreturn = true;
  1552. }
  1553. finder.Close();
  1554. return toreturn;
  1555. }
  1556. bool validDirectoryString(HWND hwndDlg,int id)
  1557. {
  1558. CString str;
  1559. GetDlgItemText(hwndDlg,id,str.GetBuffer(1000),1000);
  1560. str.ReleaseBuffer();
  1561. CString sResult = CreatePath(str);
  1562. if (sResult.GetLength())
  1563. {
  1564. SetDlgItemText(hwndDlg, id, (LPCTSTR)sResult);
  1565. return true;
  1566. }
  1567. else
  1568. return false;
  1569. }
  1570. bool validString(HWND hwndDlg,int id)
  1571. {
  1572. //characters with ASCII values 1-31 are not allowed in addition to
  1573. //the characters in IDS_INVALID_STRING. ASCII characters, whose
  1574. //value is 1-31, are hardcoded here since Visual C++ improperly
  1575. //converts some of these
  1576. // WCHAR InvalidDownLevelChars[] = //TEXT("\"/\\[]:|<>+=;,?,*")
  1577. // TEXT("\001\002\003\004\005\006\007")
  1578. // TEXT("\010\011\012\013\014\015\016\017")
  1579. // TEXT("\020\021\022\023\024\025\026\027")
  1580. // TEXT("\030\031\032\033\034\035\036\037");
  1581. bool bValid;
  1582. CHAR ANSIStr[1000];
  1583. int numConverted;
  1584. CString c;
  1585. GetDlgItemText(hwndDlg,id,c.GetBuffer(1000),1000);
  1586. c.ReleaseBuffer();
  1587. //we now use the validation function in the common library that we share
  1588. //with the scripting code
  1589. bValid = IsValidPrefixOrSuffix(c);
  1590. /* CString check;
  1591. CHAR ANSIStr[1000];
  1592. //* check.LoadString(IDS_VALID_STRING);
  1593. check.LoadString(IDS_INVALID_STRING); //load viewable invalid characters
  1594. if (c.GetLength() > 8) return false;
  1595. for (int i=0;i<c.GetLength();i++)
  1596. {
  1597. //* if (check.Find(c.GetAt(i)) == -1)
  1598. //if any characters enetered by the user ar in the viewable
  1599. //invalid list, return false to display a messagebox
  1600. if (check.Find(c.GetAt(i)) != -1)
  1601. return false;
  1602. //if any chars have a value between 1-31, return false
  1603. for (UINT j=0; j<wcslen(InvalidDownLevelChars); j++)
  1604. {
  1605. if ((c.GetAt(i)) == (InvalidDownLevelChars[j]))
  1606. return false;
  1607. }
  1608. }
  1609. */
  1610. //convert the same user input so we can guard against <ALT>1
  1611. //- <ALT>31, which cause problems in ADMT
  1612. if (bValid)
  1613. {
  1614. numConverted = WideCharToMultiByte(CP_OEMCP, WC_COMPOSITECHECK, (LPCTSTR)c,
  1615. -1, ANSIStr, 1000, NULL, NULL);
  1616. if (numConverted)
  1617. {
  1618. WCHAR sUnicodeStr[1000];
  1619. UStrCpy(sUnicodeStr, ANSIStr);
  1620. bValid = IsValidPrefixOrSuffix(sUnicodeStr);
  1621. }
  1622. }
  1623. return bValid;
  1624. }
  1625. bool validReboot(HWND hwndDlg,int id)
  1626. {
  1627. const int REBOOT_MAX = 15; //MAX minutes before computer reboot on migration
  1628. CString c;
  1629. GetDlgItemText(hwndDlg,id,c.GetBuffer(1000),1000);
  1630. c.ReleaseBuffer();
  1631. CString check;
  1632. check.LoadString(IDS_VALID_REBOOT);
  1633. for (int i=0;i<c.GetLength();i++)
  1634. {
  1635. if (check.Find(c.GetAt(i)) == -1)
  1636. return false;
  1637. }
  1638. //check to make sure it doesn't exceed the MAX (15 minutes) (will not integer
  1639. //overflow since combobox is small and not scrollable
  1640. int num;
  1641. int nRead = swscanf((LPCTSTR)c, L"%d", &num);
  1642. if ((nRead == EOF) || (nRead == 0))
  1643. return false;
  1644. if ((num >= 0) && (num > REBOOT_MAX))
  1645. return false;
  1646. return true;
  1647. }
  1648. void enableRemoveIfNecessary(HWND hwndDlg)
  1649. {
  1650. // POSITION pos = m_listBox.GetFirstSelectedItemPosition();
  1651. // pos ? enable(hwndDlg,IDC_REMOVE_BUTTON) : disable(hwndDlg,IDC_REMOVE_BUTTON) ;
  1652. int nItem = m_listBox.GetNextItem(-1, LVNI_SELECTED);//PRT
  1653. (nItem != -1) ? enable(hwndDlg,IDC_REMOVE_BUTTON) : disable(hwndDlg,IDC_REMOVE_BUTTON) ;//PRT
  1654. }
  1655. bool enableNextIfNecessary(HWND hwndDlg,int id)
  1656. {
  1657. if (IsDlgItemEmpty(hwndDlg,id))
  1658. {
  1659. PostMessage(GetParent(hwndDlg), PSM_SETWIZBUTTONS, 0, PSWIZB_BACK);
  1660. return false;
  1661. }
  1662. else
  1663. {
  1664. PostMessage(GetParent(hwndDlg), PSM_SETWIZBUTTONS, 0, PSWIZB_BACK|PSWIZB_NEXT);
  1665. return true;
  1666. }
  1667. }
  1668. void enableNextIfObjectsSelected(HWND hwndDlg)
  1669. {
  1670. if (m_listBox.GetItemCount()==0)
  1671. {
  1672. PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK);
  1673. }
  1674. else
  1675. {
  1676. PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT);
  1677. }
  1678. }
  1679. void setupColumns(bool sourceIsNT4)
  1680. {
  1681. CString column;
  1682. DWORD nColumnCount = 0;
  1683. // Get how many columns are in the list box
  1684. nColumnCount = m_listBox.GetHeaderCtrl()->GetItemCount();
  1685. if (migration == w_security || migration==w_service || migration==w_reporting)
  1686. {
  1687. if(nColumnCount == 0)
  1688. {
  1689. column.LoadString(IDS_COLUMN_NAME); m_listBox.InsertColumn( 1, column,LVCFMT_LEFT,125,1);
  1690. column.LoadString(IDS_COLUMN_OBJECTPATH); m_listBox.InsertColumn( 2, column,LVCFMT_LEFT,0,1);
  1691. column.LoadString(IDS_COLUMN_SAMNAME); m_listBox.InsertColumn( 3, column,LVCFMT_LEFT,0,1);
  1692. column.LoadString(IDS_COLUMN_DESCRIPTION); m_listBox.InsertColumn( 4, column,LVCFMT_LEFT,125,1);
  1693. column.LoadString(IDS_COLUMN_DNSNAME); m_listBox.InsertColumn( 5, column,LVCFMT_LEFT,0,1);
  1694. }
  1695. }
  1696. else
  1697. {
  1698. if(nColumnCount != 0)
  1699. {
  1700. // Need to delete columns which are different between NT4 and upper domains (like win2k)
  1701. for(int i = 2;i < nColumnCount;i++)
  1702. {
  1703. m_listBox.DeleteColumn(2);
  1704. }
  1705. }
  1706. else
  1707. {
  1708. column.LoadString(IDS_COLUMN_NAME); m_listBox.InsertColumn( 1, column,LVCFMT_LEFT,125,1);
  1709. column.LoadString(IDS_COLUMN_OBJECTPATH); m_listBox.InsertColumn( 2, column,LVCFMT_LEFT,0,1);
  1710. }
  1711. if (sourceIsNT4)
  1712. {
  1713. if (migration==w_computer)
  1714. {
  1715. m_listBox.SetColumnWidth(0,455);
  1716. column.LoadString(IDS_COLUMN_SAMNAME); m_listBox.InsertColumn( 3, column,LVCFMT_LEFT,0,1);
  1717. column.LoadString(IDS_COLUMN_DESCRIPTION); m_listBox.InsertColumn( 4, column,LVCFMT_LEFT,0,1);
  1718. }
  1719. else if (migration==w_account)
  1720. {
  1721. column.LoadString(IDS_COLUMN_FULLNAME); m_listBox.InsertColumn( 3, column,LVCFMT_LEFT,125,1);
  1722. column.LoadString(IDS_COLUMN_DESCRIPTION); m_listBox.InsertColumn( 4, column,LVCFMT_LEFT,125,1);
  1723. }
  1724. else if (migration==w_group || migration==w_groupmapping)
  1725. {
  1726. column.LoadString(IDS_COLUMN_DESCRIPTION); m_listBox.InsertColumn( 3, column,LVCFMT_LEFT,320,1);
  1727. }
  1728. }
  1729. else
  1730. {
  1731. if (migration==w_computer)
  1732. {
  1733. m_listBox.SetColumnWidth(0, 126);
  1734. column.LoadString(IDS_COLUMN_SAMNAME); m_listBox.InsertColumn( 3, column,LVCFMT_LEFT,0,1);
  1735. column.LoadString(IDS_COLUMN_DESCRIPTION); m_listBox.InsertColumn( 4, column,LVCFMT_LEFT,125,1);
  1736. column.LoadString(IDS_COLUMN_DNSNAME); m_listBox.InsertColumn( 5, column,LVCFMT_LEFT,0,1);
  1737. }
  1738. else if (migration==w_account)
  1739. {
  1740. column.LoadString(IDS_COLUMN_SAMNAME); m_listBox.InsertColumn( 3, column,LVCFMT_LEFT,125,1);
  1741. column.LoadString(IDS_COLUMN_DESCRIPTION); m_listBox.InsertColumn( 4, column,LVCFMT_LEFT,125,1);
  1742. column.LoadString(IDS_COLUMN_UPN); m_listBox.InsertColumn( 5, column,LVCFMT_LEFT,0,1);
  1743. }
  1744. else if (migration==w_group || migration==w_groupmapping)
  1745. {
  1746. column.LoadString(IDS_COLUMN_SAMNAME); m_listBox.InsertColumn( 3, column,LVCFMT_LEFT,125,1);
  1747. column.LoadString(IDS_COLUMN_DESCRIPTION); m_listBox.InsertColumn( 4, column,LVCFMT_LEFT,205,1);
  1748. }
  1749. }
  1750. }
  1751. }
  1752. void sort(CListCtrl & listbox,int col,bool order)
  1753. {
  1754. CWaitCursor w;
  1755. LV_ITEM lvItem;
  1756. ZeroMemory(&lvItem, sizeof(lvItem));
  1757. LV_ITEM lvItem2;
  1758. ZeroMemory(&lvItem2, sizeof(lvItem2));
  1759. bool ahead;
  1760. CString temp1,temp2,temp3,temp4,temp5;
  1761. int numItems = listbox.GetItemCount();
  1762. for (int i = 0;i<numItems;i++)
  1763. {
  1764. for (int j=i;j<numItems;j++)
  1765. {
  1766. ahead = ((listbox.GetItemText(i,col)).CompareNoCase(listbox.GetItemText(j,col))> 0);
  1767. if ((order && ahead) || (!order && !ahead))
  1768. {
  1769. temp1 = listbox.GetItemText(i,0);
  1770. temp2 = listbox.GetItemText(i,1);
  1771. temp3 = listbox.GetItemText(i,2);
  1772. temp4 = listbox.GetItemText(i,3);
  1773. temp5 = listbox.GetItemText(i,4);
  1774. SetItemText(listbox,i,0,listbox.GetItemText(j,0));
  1775. SetItemText(listbox,i,1,listbox.GetItemText(j,1));
  1776. SetItemText(listbox,i,2,listbox.GetItemText(j,2));
  1777. SetItemText(listbox,i,3,listbox.GetItemText(j,3));
  1778. SetItemText(listbox,i,4,listbox.GetItemText(j,4));
  1779. SetItemText(listbox,j,0,temp1);
  1780. SetItemText(listbox,j,1,temp2);
  1781. SetItemText(listbox,j,2,temp3);
  1782. SetItemText(listbox,j,3,temp4);
  1783. SetItemText(listbox,j,4,temp5);
  1784. }
  1785. }
  1786. }
  1787. }
  1788. /*
  1789. void changePlaces(CListCtrl&listBox,int i,int j)
  1790. {
  1791. CString temp1,temp2,temp3,temp4,temp5;
  1792. temp1 = listbox.GetItemText(i,0);
  1793. temp2 = listbox.GetItemText(i,1);
  1794. temp3 = listbox.GetItemText(i,2);
  1795. temp4 = listbox.GetItemText(i,3);
  1796. temp5 = listbox.GetItemText(i,4);
  1797. SetItemText(listbox,i,0,listbox.GetItemText(j,0));
  1798. SetItemText(listbox,i,1,listbox.GetItemText(j,1));
  1799. SetItemText(listbox,i,2,listbox.GetItemText(j,2));
  1800. SetItemText(listbox,i,3,listbox.GetItemText(j,3));
  1801. SetItemText(listbox,i,4,listbox.GetItemText(j,4));
  1802. SetItemText(listbox,j,0,temp1);
  1803. SetItemText(listbox,j,1,temp2);
  1804. SetItemText(listbox,j,2,temp3);
  1805. SetItemText(listbox,j,3,temp4);
  1806. SetItemText(listbox,j,4,temp5);
  1807. }
  1808. int Partition(CListCtrl & listbox,int col,bool order,int p,int r)
  1809. {
  1810. CString x=listbox.GetItemText(p,col)
  1811. int i=p-1;
  1812. int j=r+1;
  1813. while (true)
  1814. {
  1815. do
  1816. {
  1817. j--;
  1818. }while(x.CompareNoCase(listBox.GetItemText(j,col) ) >= 0);
  1819. do
  1820. {
  1821. i++;
  1822. }while(x.CompareNoCase(listBox.GetItemText(i,col) ) <=0);
  1823. if (i<j)
  1824. changePlaces(listBox,i,j);
  1825. else
  1826. return j;
  1827. }
  1828. }
  1829. void sort(CListCtrl & listbox,int col,bool order)
  1830. {
  1831. CWaitCursor w;
  1832. LV_ITEM lvItem;
  1833. ZeroMemory(&lvItem, sizeof(lvItem));
  1834. LV_ITEM lvItem2;
  1835. ZeroMemory(&lvItem2, sizeof(lvItem2));
  1836. bool ahead;
  1837. CString temp1,temp2,temp3,temp4,temp5;
  1838. int numItems = listbox.GetItemCount();
  1839. for (int i = 0;i<numItems;i++)
  1840. {
  1841. for (int j=i;j<numItems;j++)
  1842. {
  1843. ahead = ((listbox.GetItemText(i,col)).CompareNoCase(listbox.GetItemText(j,col))> 0);
  1844. if ((order && ahead) || (!order && !ahead))
  1845. {
  1846. temp1 = listbox.GetItemText(i,0);
  1847. temp2 = listbox.GetItemText(i,1);
  1848. temp3 = listbox.GetItemText(i,2);
  1849. temp4 = listbox.GetItemText(i,3);
  1850. temp5 = listbox.GetItemText(i,4);
  1851. SetItemText(listbox,i,0,listbox.GetItemText(j,0));
  1852. SetItemText(listbox,i,1,listbox.GetItemText(j,1));
  1853. SetItemText(listbox,i,2,listbox.GetItemText(j,2));
  1854. SetItemText(listbox,i,3,listbox.GetItemText(j,3));
  1855. SetItemText(listbox,i,4,listbox.GetItemText(j,4));
  1856. SetItemText(listbox,j,0,temp1);
  1857. SetItemText(listbox,j,1,temp2);
  1858. SetItemText(listbox,j,2,temp3);
  1859. SetItemText(listbox,j,3,temp4);
  1860. SetItemText(listbox,j,4,temp5);
  1861. }
  1862. }
  1863. }
  1864. }
  1865. void QuickSort(CListCtrl & listbox,int col,bool order,int p,int r)
  1866. {
  1867. int q;
  1868. if (p<r)
  1869. {
  1870. q= Partition(listBox,col,order,p,q);
  1871. QuickSort(listBox,col,order,p,q);
  1872. QuickSort(listBox,col,order,q+1,r);
  1873. }
  1874. }
  1875. void sort(CListCtrl & listbox,int col,bool order)
  1876. {
  1877. CWaitCursor w;
  1878. QuickSort(listBox,col,order,1,listBox.GetItemCount());
  1879. }*/
  1880. void OnBROWSE(HWND hwndDlg,int id)
  1881. {
  1882. TCHAR path[MAX_PATH];
  1883. CString path2, sTitle;
  1884. BROWSEINFO b;
  1885. ZeroMemory(&b, sizeof(b));
  1886. sTitle.LoadString(IDS_BROWSE_REPORT_TITLE);
  1887. b.hwndOwner=hwndDlg;
  1888. b.pidlRoot=NULL;
  1889. b.pszDisplayName=path;
  1890. b.lpszTitle=(LPCTSTR)sTitle;
  1891. b.lpfn=NULL;
  1892. b.lParam=NULL;
  1893. b.iImage=NULL;
  1894. /**/b.ulFlags=0; //PRT - 4/3
  1895. LPITEMIDLIST l = SHBrowseForFolder(&b);
  1896. SHGetPathFromIDList(l,path2.GetBuffer(1000));
  1897. path2.ReleaseBuffer();
  1898. SetDlgItemText(hwndDlg,id,path2.GetBuffer(1000));
  1899. path2.ReleaseBuffer();
  1900. }
  1901. bool administrator(CString m_Computer,HRESULT& hr)
  1902. {
  1903. hr = S_OK;
  1904. return true;
  1905. }
  1906. HRESULT validDomain(CString m_Computer,bool& isNt4)
  1907. {
  1908. IAccessCheckerPtr pAccess;
  1909. HRESULT hr;
  1910. unsigned long maj,min,sp;
  1911. hr = pAccess.CreateInstance(CLSID_AccessChecker);
  1912. hr = pAccess->raw_GetOsVersion(_bstr_t(m_Computer),&maj,&min,&sp);
  1913. maj<5 ? isNt4=true :isNt4=false;
  1914. return hr;
  1915. }
  1916. bool targetNativeMode(_bstr_t b,HRESULT& hr)
  1917. {
  1918. IAccessCheckerPtr pAccess;
  1919. hr = pAccess.CreateInstance(CLSID_AccessChecker);
  1920. BOOL bTgtNative=FALSE;
  1921. hr=pAccess->raw_IsNativeMode(b, (long*)&bTgtNative);
  1922. return ( bTgtNative != FALSE);
  1923. }
  1924. bool CheckSameForest(CString& domain1,CString& domain2,HRESULT& hr)
  1925. {
  1926. IAccessCheckerPtr pAccess;
  1927. hr = pAccess.CreateInstance(CLSID_AccessChecker);
  1928. BOOL pbIsSame=FALSE;
  1929. hr = pAccess->raw_IsInSameForest(_bstr_t(domain1), _bstr_t(domain2), (long *) &pbIsSame);
  1930. return (pbIsSame!=FALSE);
  1931. }
  1932. HRESULT doSidHistory(HWND hwndDlg)
  1933. {
  1934. CWaitCursor c;
  1935. IAccessCheckerPtr pAC;
  1936. HRESULT hr;
  1937. CString info=L"";
  1938. long bIs=0;
  1939. DWORD dwStatus = 0;
  1940. hr = pAC.CreateInstance(CLSID_AccessChecker);
  1941. if (FAILED(hr))
  1942. {
  1943. return hr;
  1944. }
  1945. //
  1946. // Retrieve name of preferred target domain controller.
  1947. //
  1948. if (targetServer.IsEmpty())
  1949. {
  1950. _bstr_t strDcDns;
  1951. _bstr_t strDcFlat;
  1952. DWORD dwError = GetDcName5(GetTargetDomainName(), DS_DIRECTORY_SERVICE_REQUIRED, strDcDns, strDcFlat);
  1953. if (dwError != ERROR_SUCCESS)
  1954. {
  1955. return HRESULT_FROM_WIN32(dwError);
  1956. }
  1957. targetServer = (LPCTSTR)strDcFlat;
  1958. targetServerDns = (LPCTSTR)strDcDns;
  1959. }
  1960. hr = pAC->raw_CanUseAddSidHistory(
  1961. _bstr_t(GetSourceDomainName()),
  1962. _bstr_t(GetTargetDomainName()),
  1963. _bstr_t(GetTargetDcName()),
  1964. &bIs
  1965. );
  1966. if ( SUCCEEDED(hr) )
  1967. {
  1968. if ( bIs == 0 )
  1969. {
  1970. return S_OK;
  1971. }
  1972. else
  1973. {
  1974. // get primary domain controller in source domain
  1975. _bstr_t sourceDomainController;
  1976. dwStatus = GetDcName5(GetSourceDomainName(), DS_PDC_REQUIRED, sourceDomainController);
  1977. if (dwStatus != NO_ERROR)
  1978. {
  1979. hr = HRESULT_FROM_WIN32(dwStatus);
  1980. return hr;
  1981. }
  1982. if ( bIs & F_NO_AUDITING_SOURCE )
  1983. {
  1984. info.LoadString(IDS_MSG_ENABLE_SOURCE);
  1985. if (MessageBox(hwndDlg,info,0,MB_YESNOCANCEL|MB_ICONQUESTION) ==IDYES)
  1986. {
  1987. hr = pAC->raw_EnableAuditing(sourceDomainController);
  1988. if(FAILED(hr)) return hr;
  1989. }
  1990. else return E_ABORT;
  1991. }
  1992. if ( bIs & F_NO_AUDITING_TARGET )
  1993. {
  1994. info.LoadString(IDS_MSG_ENABLE_TARGET);
  1995. if (MessageBox(hwndDlg,info,0,MB_YESNOCANCEL|MB_ICONQUESTION) ==IDYES)
  1996. {
  1997. hr = pAC->raw_EnableAuditing(_bstr_t(GetTargetDcName()));
  1998. if(FAILED(hr)) return hr;
  1999. }
  2000. else return E_ABORT;
  2001. }
  2002. if ( bIs & F_NO_LOCAL_GROUP )
  2003. {
  2004. CString info2;
  2005. info2.LoadString(IDS_MSG_LOCAL_GROUP);
  2006. info.Format(info2,GetSourceDomainNameFlat(),GetSourceDomainName());
  2007. if (MessageBox(hwndDlg,info,0,MB_YESNOCANCEL|MB_ICONQUESTION) ==IDYES)
  2008. {
  2009. hr = pAC->raw_AddLocalGroup(_bstr_t(GetSourceDomainNameFlat()), sourceDomainController);
  2010. if(FAILED(hr)) return hr;
  2011. }
  2012. else return E_ABORT;
  2013. }
  2014. if ( bIs & F_NO_REG_KEY )
  2015. {
  2016. info.LoadString(IDS_MSG_REGKEY);
  2017. int bReboot=0;
  2018. if (MessageBox(hwndDlg,info,0,MB_YESNOCANCEL|MB_ICONQUESTION) ==IDYES)
  2019. {
  2020. CString msg;
  2021. info.LoadString(IDS_MSG_REBOOT_SID);
  2022. msg.Format((LPCTSTR)info, (LPCTSTR)sourceDomainController);
  2023. int answer = MessageBox(hwndDlg,msg,0,MB_YESNOCANCEL|MB_ICONQUESTION) ;
  2024. if (answer==IDYES)
  2025. bReboot=1;
  2026. else if (answer==IDNO)
  2027. bReboot=0;
  2028. else
  2029. return E_ABORT;
  2030. hr = pAC->raw_AddRegKey(sourceDomainController,bReboot);
  2031. if(FAILED(hr)) return hr;
  2032. //
  2033. // If domain controller has been re-started then warn user to wait
  2034. // for domain controller to re-start before continuing.
  2035. //
  2036. if (bReboot)
  2037. {
  2038. CString strTitle;
  2039. strTitle.LoadString(IDS_MSG_WARNING);
  2040. msg.Format(IDS_MSG_WAIT_FOR_RESTART, (LPCTSTR)sourceDomainController);
  2041. MessageBox(hwndDlg, msg, strTitle, MB_OK|MB_ICONWARNING);
  2042. }
  2043. }
  2044. else return E_ABORT;
  2045. }
  2046. if ( bIs & F_NOT_DOMAIN_ADMIN )
  2047. {
  2048. CString strMessage;
  2049. strMessage.LoadString(IDS_MSG_TARGET_DOMAIN_ADMIN);
  2050. MessageBox(hwndDlg, strMessage, 0, MB_OK|MB_ICONERROR);
  2051. return E_ABORT;
  2052. }
  2053. return S_OK;
  2054. }
  2055. }
  2056. else
  2057. {
  2058. if (HRESULT_CODE(hr) == ERROR_BAD_NETPATH)
  2059. {
  2060. CString msg;
  2061. info.LoadString(IDS_MSG_SIDHISTORY_NO_PDC);
  2062. msg.Format((LPCTSTR)info, GetSourceDomainName());
  2063. MessageBox(hwndDlg,msg,0,MB_ICONSTOP);
  2064. return E_ABORT;
  2065. }
  2066. else
  2067. {
  2068. CString msg;
  2069. info.LoadString(IDS_MSG_SID_HISTORY);
  2070. msg.Format((LPCTSTR)info, _com_error(hr).ErrorMessage());
  2071. MessageBox(hwndDlg,msg,0,MB_ICONSTOP);
  2072. return E_ABORT;
  2073. }
  2074. }
  2075. }
  2076. //----------------------------------------------------------------------------
  2077. // GetDomainInfoFromActionHistory Function
  2078. //
  2079. // Synopsis
  2080. // Retrieves a domain's name and SID information from the database.
  2081. //
  2082. // Arguments
  2083. // IN pszName - either a DNS or NetBIOS domain name
  2084. // OUT pszNetBiosName - domain NetBIOS name
  2085. // OUT pszDnsName - domain DNS name
  2086. // OUT pszSid - domain SID
  2087. // OUT pbSetForest - whether forest value was set
  2088. // OUT pbSetSrcOS - whether source OS version was set
  2089. //
  2090. // Note that function assumes that buffers are large enough.
  2091. //----------------------------------------------------------------------------
  2092. void GetDomainInfoFromActionHistory
  2093. (
  2094. PCWSTR pszName,
  2095. PWSTR pszNetBiosName,
  2096. PWSTR pszDnsName,
  2097. PWSTR pszSid,
  2098. bool* pbSetForest,
  2099. bool* pbSetSrcOS,
  2100. LPSHAREDWIZDATA pdata
  2101. )
  2102. {
  2103. //
  2104. // retrieve source domain information from database
  2105. //
  2106. IVarSetPtr spVarSet = db->GetSourceDomainInfo(_bstr_t(pszName));
  2107. if (spVarSet)
  2108. {
  2109. //
  2110. // if information retrieved then copy to buffers
  2111. //
  2112. _bstr_t strFlatName = spVarSet->get(_T("Options.SourceDomain"));
  2113. _bstr_t strDnsName = spVarSet->get(_T("Options.SourceDomainDns"));
  2114. _bstr_t strSid = spVarSet->get(_T("Options.SourceDomainSid"));
  2115. wcscpy(pszNetBiosName, strFlatName.length() ? strFlatName : L"");
  2116. wcscpy(pszDnsName, strDnsName.length() ? strDnsName : L"");
  2117. wcscpy(pszSid, strSid.length() ? strSid : L"");
  2118. //
  2119. // note that for security translation that
  2120. // the following information is not important
  2121. //
  2122. // therefore assume that the domains were not in the same forest
  2123. //
  2124. // the DNS name is set equal to the NetBIOS name for NT4 domains therefore
  2125. // assume that source domain was NT4 if DNS and NetBIOS names are same
  2126. //
  2127. *pbSetForest = true;
  2128. *pbSetSrcOS = true;
  2129. pdata->sameForest = false;
  2130. pdata->sourceIsNT4 = (strFlatName == strDnsName);
  2131. }
  2132. else
  2133. {
  2134. *pszNetBiosName = L'\0';
  2135. *pszDnsName = L'\0';
  2136. *pszSid = L'\0';
  2137. }
  2138. }
  2139. void cleanNames()
  2140. {
  2141. sourceDNS=L"";
  2142. sourceNetbios=L"";
  2143. targetNetbios=L"";
  2144. targetDNS=L"";
  2145. }
  2146. bool verifyprivs(HWND hwndDlg,CString& sourceDomainController,CString& targetDomainController,LPSHAREDWIZDATA& pdata)
  2147. {
  2148. CWaitCursor wait;
  2149. CString temp,temp2;
  2150. HRESULT hr;
  2151. bool result;
  2152. DWORD dwResult = NO_ERROR;
  2153. GetDlgItemText( hwndDlg, IDC_EDIT_DOMAIN, temp.GetBuffer(1000),1000);
  2154. GetDlgItemText( hwndDlg, IDC_EDIT_DOMAIN2, temp2.GetBuffer(1000),1000);
  2155. temp.ReleaseBuffer();
  2156. temp2.ReleaseBuffer();
  2157. temp.TrimLeft();temp.TrimRight();
  2158. temp2.TrimLeft();temp2.TrimRight();
  2159. // if the source domain has changed...
  2160. if ( temp.CompareNoCase(sourceDNS) && temp.CompareNoCase(sourceNetbios) )
  2161. {
  2162. pdata->newSource = true;
  2163. // Get the DNS and Netbios names for the domain name the user has entered
  2164. }
  2165. else
  2166. {
  2167. pdata->newSource = false;
  2168. }
  2169. _bstr_t strFlatName;
  2170. _bstr_t strDnsName;
  2171. dwResult = GetDomainNames5(temp, strFlatName, strDnsName);
  2172. if(dwResult != NO_ERROR)
  2173. {
  2174. ErrorWrapper3(hwndDlg,dwResult,temp);
  2175. if ( gbNeedToVerify )
  2176. {
  2177. cleanNames();
  2178. return false;
  2179. }
  2180. }
  2181. sourceDNS = (LPCTSTR)strDnsName;
  2182. sourceNetbios = (LPCTSTR)strFlatName;
  2183. dwResult = GetDomainNames5(temp2, strFlatName, strDnsName);
  2184. if(dwResult != NO_ERROR)
  2185. {
  2186. ErrorWrapper3(hwndDlg,dwResult,temp2);
  2187. if ( gbNeedToVerify )
  2188. {
  2189. cleanNames();
  2190. return false;
  2191. }
  2192. }
  2193. targetDNS = (LPCTSTR)strDnsName;
  2194. targetNetbios = (LPCTSTR)strFlatName;
  2195. if (!sourceNetbios.CompareNoCase(targetNetbios) || !sourceDNS.CompareNoCase(targetDNS))
  2196. {
  2197. MessageBoxWrapper3(hwndDlg,IDS_MSG_UNIQUE,IDS_MSG_ERROR,temp);
  2198. cleanNames();
  2199. return false;
  2200. }
  2201. _bstr_t text =get(DCTVS_Options_TargetDomain);
  2202. CString tocheck = (WCHAR * const) text;
  2203. tocheck.TrimLeft();tocheck.TrimRight();
  2204. pdata->resetOUPATH = !tocheck.CompareNoCase(GetTargetDomainName()) ? false: true;
  2205. _bstr_t strDc;
  2206. DWORD res = GetDcName5(GetSourceDomainName(), DS_DIRECTORY_SERVICE_PREFERRED, strDc);
  2207. if (res!=NO_ERROR)
  2208. {
  2209. ErrorWrapper3(hwndDlg,HRESULT_FROM_WIN32(res),temp);
  2210. if ( gbNeedToVerify )
  2211. {
  2212. cleanNames();
  2213. return false;
  2214. }
  2215. }
  2216. else
  2217. {
  2218. sourceDomainController = (LPCTSTR)strDc;
  2219. }
  2220. res = GetDcName5(GetTargetDomainName(), DS_DIRECTORY_SERVICE_REQUIRED, strDc);
  2221. if (res!=NO_ERROR)
  2222. {
  2223. ErrorWrapper3(hwndDlg,HRESULT_FROM_WIN32(res),temp2);
  2224. if ( gbNeedToVerify )
  2225. {
  2226. cleanNames();
  2227. return false;
  2228. }
  2229. }
  2230. else
  2231. {
  2232. targetDomainController = (LPCTSTR)strDc;
  2233. }
  2234. ///////////////////////////////////////////////////////////////////////////////////////////
  2235. bool nothing;
  2236. hr =validDomain(sourceDomainController,pdata->sourceIsNT4);
  2237. if (!SUCCEEDED(hr))
  2238. {
  2239. ErrorWrapper3(hwndDlg,hr,temp);
  2240. if ( gbNeedToVerify )
  2241. {
  2242. cleanNames();
  2243. return false;
  2244. }
  2245. }
  2246. hr =validDomain(targetDomainController,nothing);
  2247. if (!SUCCEEDED(hr))
  2248. {
  2249. ErrorWrapper3(hwndDlg,hr,temp2);
  2250. if ( gbNeedToVerify )
  2251. {
  2252. cleanNames();
  2253. return false;
  2254. }
  2255. }
  2256. result = administrator(sourceDomainController,hr);
  2257. if (!SUCCEEDED(hr))
  2258. {
  2259. ErrorWrapper3(hwndDlg,hr,temp);
  2260. if ( gbNeedToVerify )
  2261. {
  2262. cleanNames();
  2263. return false;
  2264. }
  2265. }
  2266. else if (!result)
  2267. {
  2268. MessageBoxWrapper3(hwndDlg,IDS_MSG_SOURCE_ADMIN,IDS_MSG_ERROR,temp);
  2269. if ( gbNeedToVerify )
  2270. {
  2271. cleanNames();
  2272. return false;
  2273. }
  2274. }
  2275. result=administrator(targetDomainController,hr);
  2276. if (!SUCCEEDED(hr))
  2277. {
  2278. ErrorWrapper3(hwndDlg,hr,temp2);
  2279. if ( gbNeedToVerify )
  2280. {
  2281. cleanNames();
  2282. return false;
  2283. }
  2284. }
  2285. else if (!result)
  2286. {
  2287. MessageBoxWrapper3(hwndDlg,IDS_MSG_TARGET_ADMIN,IDS_MSG_ERROR,temp2);
  2288. if ( gbNeedToVerify )
  2289. {
  2290. cleanNames();
  2291. return false;
  2292. }
  2293. }
  2294. result=targetNativeMode(GetTargetDomainName(),hr);
  2295. if (!SUCCEEDED(hr))
  2296. {
  2297. ErrorWrapper3(hwndDlg,hr,temp2);
  2298. if ( gbNeedToVerify )
  2299. {
  2300. cleanNames();
  2301. return false;
  2302. }
  2303. }
  2304. else if (!result)
  2305. {
  2306. MessageBoxWrapper3(hwndDlg,IDS_MSG_TARGET_NATIVE,IDS_MSG_ERROR,temp2);
  2307. if ( gbNeedToVerify )
  2308. {
  2309. cleanNames();
  2310. return false;
  2311. }
  2312. }
  2313. if (pdata->sourceIsNT4)
  2314. {
  2315. pdata->sameForest=false;
  2316. }
  2317. else
  2318. {
  2319. pdata->sameForest=CheckSameForest(CString(GetSourceDomainName()),CString(GetTargetDomainName()),hr);
  2320. if (!SUCCEEDED(hr))
  2321. {
  2322. ErrorWrapper3(hwndDlg,hr,temp);
  2323. if ( gbNeedToVerify )
  2324. {
  2325. cleanNames();
  2326. return false;
  2327. }
  2328. }
  2329. }
  2330. pdata->sameForest ? put(DCTVS_Options_IsIntraforest,yes) : put(DCTVS_Options_IsIntraforest,no);
  2331. return true;
  2332. }
  2333. bool verifyprivs2(HWND hwndDlg,CString& additionalDomainController,CString domainName)
  2334. {
  2335. CWaitCursor w;
  2336. _bstr_t strDc;
  2337. DWORD dwResult = GetDcName5(domainName, DS_DIRECTORY_SERVICE_PREFERRED, strDc);
  2338. if (dwResult!=NO_ERROR)
  2339. {
  2340. ErrorWrapper3(hwndDlg,HRESULT_FROM_WIN32(dwResult),domainName);
  2341. if ( gbNeedToVerify )
  2342. return false;
  2343. }
  2344. else
  2345. {
  2346. additionalDomainController = (LPCTSTR)strDc;
  2347. }
  2348. bool nothing;
  2349. HRESULT hr =validDomain(additionalDomainController,nothing);
  2350. if (!SUCCEEDED(hr))
  2351. {
  2352. ErrorWrapper3(hwndDlg,hr,domainName);
  2353. if ( gbNeedToVerify )
  2354. return false;
  2355. }
  2356. HRESULT result = administrator(additionalDomainController,hr);
  2357. if (!SUCCEEDED(hr))
  2358. {
  2359. ErrorWrapper3(hwndDlg,hr,domainName);
  2360. if ( gbNeedToVerify )
  2361. return false;
  2362. }
  2363. else if (!result)
  2364. {
  2365. MessageBoxWrapper3(hwndDlg,IDS_MSG_SOURCE_ADMIN,IDS_MSG_ERROR,domainName);
  2366. if ( gbNeedToVerify )
  2367. return false;
  2368. }
  2369. return true;
  2370. }
  2371. bool verifyprivsSTW(HWND hwndDlg,CString& sourceDomainController,CString& targetDomainController,LPSHAREDWIZDATA& pdata)
  2372. {
  2373. CWaitCursor wait;
  2374. CString temp,temp2;
  2375. HRESULT hr;
  2376. bool result, bSetSrcOS, bSetForest;
  2377. WCHAR txtSid[MAX_PATH] = L"";
  2378. DWORD dwResult = NO_ERROR;
  2379. GetDlgItemText( hwndDlg, IDC_EDIT_DOMAIN, temp.GetBuffer(1000),1000);
  2380. GetDlgItemText( hwndDlg, IDC_EDIT_DOMAIN2, temp2.GetBuffer(1000),1000);
  2381. temp.ReleaseBuffer();
  2382. temp2.ReleaseBuffer();
  2383. temp.TrimLeft();temp.TrimRight();
  2384. temp2.TrimLeft();temp2.TrimRight();
  2385. // if the source domain has changed...
  2386. if ( temp.CompareNoCase(sourceDNS) && temp.CompareNoCase(sourceNetbios) )
  2387. {
  2388. pdata->newSource = true;
  2389. // Get the DNS and Netbios names for the domain name the user has entered
  2390. }
  2391. else
  2392. {
  2393. pdata->newSource = false;
  2394. }
  2395. _bstr_t strFlatName;
  2396. _bstr_t strDnsName;
  2397. dwResult = GetDomainNames5(temp2, strFlatName, strDnsName);
  2398. if(dwResult != NO_ERROR)
  2399. {
  2400. ErrorWrapper3(hwndDlg,dwResult,temp);
  2401. cleanNames();
  2402. return false;
  2403. }
  2404. targetNetbios = (LPCTSTR)strFlatName;
  2405. targetDNS = (LPCTSTR)strDnsName;
  2406. //
  2407. // attempt to retrieve source domain information from the domain first
  2408. // if unsuccessful then retrieve the information from the database
  2409. //
  2410. if (GetDomainNames5(temp, strFlatName, strDnsName) == NO_ERROR)
  2411. {
  2412. sourceNetbios = (LPCTSTR)strFlatName;
  2413. sourceDNS = (LPCTSTR)strDnsName;
  2414. }
  2415. else
  2416. {
  2417. GetDomainInfoFromActionHistory(
  2418. &*temp,
  2419. sourceNetbios.GetBuffer(1000),
  2420. sourceDNS.GetBuffer(1000),
  2421. txtSid,
  2422. &bSetForest,
  2423. &bSetSrcOS,
  2424. pdata
  2425. );
  2426. sourceDNS.ReleaseBuffer();
  2427. sourceNetbios.ReleaseBuffer();
  2428. }
  2429. if ((sourceNetbios.IsEmpty()) && (sourceDNS.IsEmpty()))
  2430. {
  2431. MessageBoxWrapper3(hwndDlg,IDS_MSG_NOOBJECTS,IDS_MSG_ERROR,temp);
  2432. cleanNames();
  2433. return false;
  2434. }
  2435. if (!sourceNetbios.CompareNoCase(targetNetbios) || !sourceDNS.CompareNoCase(targetDNS))
  2436. {
  2437. MessageBoxWrapper3(hwndDlg,IDS_MSG_UNIQUE,IDS_MSG_ERROR,temp);
  2438. cleanNames();
  2439. return false;
  2440. }
  2441. //get the source domain's sid, display
  2442. //message if no sid
  2443. if (wcslen(txtSid) > 0)
  2444. pVarSet->put(GET_BSTR(DCTVS_Options_SourceDomainSid),txtSid);
  2445. else
  2446. {
  2447. PSID pSid = NULL;
  2448. _bstr_t domctrl;
  2449. DWORD lenTxt = DIM(txtSid);
  2450. BOOL bFailed = TRUE;
  2451. //try to get it from the source domain directly
  2452. if (GetDcName5(GetSourceDomainName(), DS_DIRECTORY_SERVICE_PREFERRED, domctrl) == ERROR_SUCCESS)
  2453. {
  2454. if(GetDomainSid(domctrl,&pSid))
  2455. {
  2456. if (GetTextualSid(pSid,txtSid,&lenTxt))
  2457. {
  2458. //add the sid to the varset
  2459. pVarSet->put(GET_BSTR(DCTVS_Options_SourceDomainSid),txtSid);
  2460. //populate the MigratedObjects table with this sid
  2461. db->PopulateSrcSidColumnByDomain(GetSourceDomainName(), _bstr_t(txtSid));
  2462. bFailed = FALSE;
  2463. }
  2464. if (pSid)
  2465. FreeSid(pSid);
  2466. }
  2467. }
  2468. if (bFailed)
  2469. {
  2470. MessageBoxWrapper3(hwndDlg,IDS_MSG_NOSOURCESID,IDS_MSG_ERROR,temp);
  2471. cleanNames();
  2472. return false;
  2473. }
  2474. }
  2475. _bstr_t text =get(DCTVS_Options_TargetDomain);
  2476. CString tocheck = (WCHAR * const) text;
  2477. tocheck.TrimLeft();tocheck.TrimRight();
  2478. pdata->resetOUPATH = !tocheck.CompareNoCase(GetTargetDomainName()) ? false: true;
  2479. _bstr_t strDc;
  2480. DWORD res = GetDcName5(GetSourceDomainName(), DS_DIRECTORY_SERVICE_PREFERRED, strDc);
  2481. if (res==NO_ERROR)
  2482. {
  2483. sourceDomainController = (LPCTSTR)strDc;
  2484. }
  2485. res = GetDcName5(GetTargetDomainName(), DS_DIRECTORY_SERVICE_REQUIRED, strDc);
  2486. if (res!=NO_ERROR)
  2487. {
  2488. ErrorWrapper3(hwndDlg,HRESULT_FROM_WIN32(res),temp2);
  2489. if ( gbNeedToVerify )
  2490. {
  2491. cleanNames();
  2492. return false;
  2493. }
  2494. }
  2495. else
  2496. {
  2497. targetDomainController = (LPCTSTR)strDc;
  2498. }
  2499. ///////////////////////////////////////////////////////////////////////////////////////////
  2500. bool nothing;
  2501. //if we were not able to determine the source domain's OS from the
  2502. //Action History table and we did get the source DC name, try to do
  2503. //it here. This will work if the source domain still exists. If
  2504. //the source domain no longer exists, set default.
  2505. if ((!bSetSrcOS) && (!sourceDomainController.IsEmpty()))
  2506. {
  2507. hr =validDomain(sourceDomainController,pdata->sourceIsNT4);
  2508. if (!SUCCEEDED(hr))
  2509. pdata->sourceIsNT4 = true;
  2510. }
  2511. hr =validDomain(targetDomainController,nothing);
  2512. if (!SUCCEEDED(hr))
  2513. {
  2514. ErrorWrapper3(hwndDlg,hr,temp2);
  2515. if ( gbNeedToVerify )
  2516. {
  2517. cleanNames();
  2518. return false;
  2519. }
  2520. }
  2521. result=administrator(targetDomainController,hr);
  2522. if (!SUCCEEDED(hr))
  2523. {
  2524. ErrorWrapper3(hwndDlg,hr,temp2);
  2525. if ( gbNeedToVerify )
  2526. {
  2527. cleanNames();
  2528. return false;
  2529. }
  2530. }
  2531. else if (!result)
  2532. {
  2533. MessageBoxWrapper3(hwndDlg,IDS_MSG_TARGET_ADMIN,IDS_MSG_ERROR,temp2);
  2534. if ( gbNeedToVerify )
  2535. {
  2536. cleanNames();
  2537. return false;
  2538. }
  2539. }
  2540. result=targetNativeMode(GetTargetDomainName(),hr);
  2541. if (!SUCCEEDED(hr))
  2542. {
  2543. ErrorWrapper3(hwndDlg,hr,temp2);
  2544. if ( gbNeedToVerify )
  2545. {
  2546. cleanNames();
  2547. return false;
  2548. }
  2549. }
  2550. else if (!result)
  2551. {
  2552. MessageBoxWrapper3(hwndDlg,IDS_MSG_TARGET_NATIVE,IDS_MSG_ERROR,temp2);
  2553. if ( gbNeedToVerify )
  2554. {
  2555. cleanNames();
  2556. return false;
  2557. }
  2558. }
  2559. //if we were not able to set the intraforest boolean variable by looking at
  2560. //the Action History table, then try to find out here. This will not work
  2561. //if the source domain no longer exists, in which case we set it to a default
  2562. //value.
  2563. if (!bSetForest)
  2564. {
  2565. if (pdata->sourceIsNT4)
  2566. {
  2567. pdata->sameForest=false;
  2568. }
  2569. else
  2570. {
  2571. pdata->sameForest=CheckSameForest(CString(GetSourceDomainName()),CString(GetTargetDomainName()),hr);
  2572. if (!SUCCEEDED(hr))
  2573. {
  2574. //if we cannot figure it out, assume it is intra-forest so we
  2575. //will prompt for target domain credentials
  2576. pdata->sameForest=true;
  2577. }
  2578. }
  2579. }
  2580. pdata->sameForest ? put(DCTVS_Options_IsIntraforest,yes) : put(DCTVS_Options_IsIntraforest,no);
  2581. return true;
  2582. }
  2583. //-----------------------------------------------------------------------------
  2584. // VerifyCallerDelegated Method
  2585. //
  2586. // Synopsis
  2587. // If an intra-forest move operation is being performed then verify that the
  2588. // calling user's account has not been marked as sensitive and therefore
  2589. // cannot be delegated. As the move operation is performed on the domain
  2590. // controller which has the RID master role in the source domain it is
  2591. // necessary to delegate the user's security context.
  2592. //
  2593. // Arguments
  2594. // hwndDlg - handle to wizard page dialog window
  2595. // pdata - pointer to shared wizard data
  2596. //
  2597. // Return Value
  2598. // The returned boolean value is true if caller's account may be delegated
  2599. // otherwise false.
  2600. //-----------------------------------------------------------------------------
  2601. bool __stdcall VerifyCallerDelegated(HWND hwndDlg, LPSHAREDWIZDATA pdata)
  2602. {
  2603. bool bDelegated = true;
  2604. //
  2605. // It is only necessary to check this for intra-forest.
  2606. //
  2607. if (pdata->sameForest)
  2608. {
  2609. bool bDelegatable = false;
  2610. HRESULT hr = IsCallerDelegatable(bDelegatable);
  2611. if (SUCCEEDED(hr))
  2612. {
  2613. if (bDelegatable == false)
  2614. {
  2615. //
  2616. // Caller's account is not delegatable. Retrieve name of domain controller
  2617. // in the source domain that holds the RID master role and the name of this
  2618. // computer.
  2619. //
  2620. _bstr_t strDnsName;
  2621. _bstr_t strFlatName;
  2622. hr = GetRidPoolAllocator4(GetSourceDomainName(), strDnsName, strFlatName);
  2623. if (SUCCEEDED(hr))
  2624. {
  2625. _TCHAR szComputerName[MAX_PATH];
  2626. DWORD cchComputerName = sizeof(szComputerName) / sizeof(szComputerName[0]);
  2627. if (GetComputerNameEx(ComputerNameDnsFullyQualified, szComputerName, &cchComputerName))
  2628. {
  2629. //
  2630. // If this computer is not the domain controller holding the
  2631. // RID master role in the source domain then generate error.
  2632. //
  2633. if (_tcsicmp(szComputerName, strDnsName) != 0)
  2634. {
  2635. MessageBoxWrapper(hwndDlg, IDS_MSG_CALLER_NOT_DELEGATED, IDS_MSG_ERROR);
  2636. bDelegated = false;
  2637. }
  2638. }
  2639. else
  2640. {
  2641. DWORD dwError = GetLastError();
  2642. hr = HRESULT_FROM_WIN32(dwError);
  2643. }
  2644. }
  2645. }
  2646. }
  2647. if (FAILED(hr))
  2648. {
  2649. CString strTitle;
  2650. strTitle.LoadString(AFX_IDS_APP_TITLE);
  2651. CString strFormat;
  2652. strFormat.LoadString(IDS_MSG_UNABLE_VERIFY_CALLER_NOT_DELEGATED);
  2653. CString strMessage;
  2654. strMessage.Format(strFormat, _com_error(hr).ErrorMessage());
  2655. MessageBox(hwndDlg, strMessage, strTitle, MB_ICONWARNING | MB_OK);
  2656. }
  2657. }
  2658. return bDelegated;
  2659. }
  2660. void OnADD(HWND hwndDlg,bool sourceIsNT4)
  2661. {
  2662. HRESULT hr = pDsObjectPicker->InvokeDialog(hwndDlg, &pdo);
  2663. if (FAILED(hr)) return;
  2664. if (hr == S_OK) {
  2665. ProcessSelectedObjects(pdo,hwndDlg,sourceIsNT4);
  2666. pdo->Release();
  2667. }
  2668. }
  2669. bool GetCheck(CListCtrl & yo,int nItem)
  2670. {
  2671. UINT nState = yo.GetItemState(nItem,LVIS_CUT);
  2672. return (nState ? false: true);
  2673. }
  2674. void SetCheck(CListCtrl & yo,int nItem,bool checkit)
  2675. {
  2676. !checkit ? yo.SetItemState(nItem,LVIS_CUT,LVIS_CUT) : yo.SetItemState(nItem,0,LVIS_CUT);
  2677. }
  2678. void SetItemText(CListCtrl& yo, int nItem, int subItem,CString& text)
  2679. {
  2680. CString f;
  2681. LV_ITEM lvItem;
  2682. ZeroMemory(&lvItem, sizeof(lvItem));
  2683. lvItem.mask = LVIF_TEXT;
  2684. lvItem.iItem = nItem;
  2685. lvItem.iSubItem= subItem;
  2686. f= text;
  2687. lvItem.pszText = f.GetBuffer(1000);
  2688. f.ReleaseBuffer();
  2689. yo.SetItem(&lvItem);
  2690. }
  2691. void SetItemText(CListCtrl& yo, int nItem, int subItem,TCHAR * text)
  2692. {
  2693. CString temp = text;
  2694. SetItemText(yo,nItem,subItem,temp);
  2695. }
  2696. void SetItemText(CListCtrl& yo, int nItem, int subItem,TCHAR const * text)
  2697. {
  2698. CString temp = text;
  2699. SetItemText(yo,nItem,subItem,temp);
  2700. }
  2701. void SetItemText(CListCtrl& yo, int nItem, int subItem,_bstr_t text)
  2702. {
  2703. CString temp = (WCHAR * const) text;
  2704. SetItemText(yo,nItem,subItem,temp);
  2705. }
  2706. void OnREMOVE(HWND hwndDlg)
  2707. {
  2708. int nItem;
  2709. // POSITION pos = m_listBox.GetFirstSelectedItemPosition();
  2710. // while (pos)
  2711. // {
  2712. // nItem = m_listBox.GetNextSelectedItem(pos);
  2713. nItem = m_listBox.GetNextItem(-1, LVNI_SELECTED);//PRT
  2714. while (nItem != -1)//PRT
  2715. {
  2716. SetCheck(m_listBox,nItem,false);
  2717. nItem = m_listBox.GetNextItem(nItem, LVNI_SELECTED);//PRT
  2718. }
  2719. for (int i=(m_listBox.GetItemCount()-1);i>=0;i--)
  2720. if (!GetCheck(m_listBox,i))
  2721. m_listBox.DeleteItem(i);
  2722. }
  2723. void OnMIGRATE(HWND hwndDlg,int& accounts,int&servers)
  2724. {
  2725. CString name,nameDns,spruced_name,varset_1,upnName;
  2726. accounts=0,servers=0;
  2727. int intCount=m_listBox.GetItemCount();
  2728. CString n;
  2729. for (int i=0;i<intCount;i++)
  2730. {
  2731. if (migration==w_computer || (migration ==w_security ||
  2732. (migration == w_reporting || migration == w_service)))
  2733. {
  2734. name= m_listBox.GetItemText(i, 2);
  2735. spruced_name = L"\\\\" + name;
  2736. varset_1.Format(L"Servers.%d",servers);
  2737. pVarSet->put(_bstr_t(varset_1),_bstr_t(spruced_name));
  2738. // DNS Name
  2739. nameDns = m_listBox.GetItemText(i, 4);
  2740. if (nameDns.IsEmpty() == FALSE)
  2741. {
  2742. spruced_name = L"\\\\" + nameDns;
  2743. pVarSet->put(_bstr_t(varset_1 + L".DnsName"), _bstr_t(spruced_name));
  2744. }
  2745. pVarSet->put(_bstr_t(varset_1 + L".MigrateOnly"),no);
  2746. if (migration==w_computer)
  2747. pVarSet->put(_bstr_t(varset_1 + L".MoveToTarget"),yes);
  2748. else if (migration==w_security)
  2749. {
  2750. pVarSet->put(_bstr_t(varset_1 + L".Reboot"),no);
  2751. pVarSet->put(_bstr_t(varset_1 + L".MoveToTarget"),no);
  2752. }
  2753. servers++;
  2754. }
  2755. else
  2756. {
  2757. name= m_listBox.GetItemText(i,1);
  2758. upnName = m_listBox.GetItemText(i,4);
  2759. }
  2760. if (name.IsEmpty())
  2761. {
  2762. MessageBoxWrapper(hwndDlg,IDS_MSG_PATH,IDS_MSG_ERROR);
  2763. }
  2764. varset_1.Format(L"Accounts.%d",accounts);
  2765. pVarSet->put(_bstr_t(varset_1),_bstr_t(name));
  2766. pVarSet->put(_bstr_t(varset_1+".TargetName"),L"");
  2767. switch(migration)
  2768. {
  2769. case w_account:
  2770. pVarSet->put(_bstr_t(varset_1+L".Type"),L"user");
  2771. pVarSet->put(_bstr_t(varset_1+L".UPNName"),_bstr_t(upnName));
  2772. break;
  2773. case w_group:pVarSet->put(_bstr_t(varset_1+L".Type"),L"group");break;
  2774. case w_groupmapping:
  2775. {
  2776. pVarSet->put(_bstr_t(varset_1+L".Type"),L"group");
  2777. _bstr_t temp = GET_BSTR(DCTVS_Accounts_D_OperationMask);
  2778. CString holder = (WCHAR * const) temp;
  2779. CString toenter;
  2780. toenter.Format(holder,i);
  2781. pVarSet->put(_bstr_t(toenter),(LONG)0x1d);
  2782. break;
  2783. }
  2784. case w_computer:pVarSet->put(_bstr_t(varset_1+L".Type"),L"computer");break;
  2785. case w_security:pVarSet->put(_bstr_t(varset_1+L".Type"),L"computer");break;
  2786. case w_reporting:pVarSet->put(_bstr_t(varset_1+L".Type"),L"computer");break;
  2787. case w_service:pVarSet->put(_bstr_t(varset_1+L".Type"),L"computer");break;
  2788. default: break;
  2789. }
  2790. n=m_listBox.GetItemText(i,0);
  2791. if (migration==w_account)
  2792. pVarSet->put(_bstr_t(varset_1+L".Name"), _bstr_t(n));
  2793. accounts++;
  2794. }
  2795. put(DCTVS_Accounts_NumItems,(LONG)accounts);
  2796. put(DCTVS_Servers_NumItems,(LONG)servers);
  2797. }
  2798. HRESULT InitObjectPicker2(IDsObjectPicker *pDsObjectPicker,bool multiselect,CString targetComputer,bool sourceIsNT4) {
  2799. static const int SCOPE_INIT_COUNT = 2;
  2800. DSOP_SCOPE_INIT_INFO aScopeInit[SCOPE_INIT_COUNT];
  2801. DSOP_INIT_INFO InitInfo;
  2802. ZeroMemory(aScopeInit,
  2803. sizeof(DSOP_SCOPE_INIT_INFO) * SCOPE_INIT_COUNT);
  2804. ZeroMemory(&InitInfo, sizeof(InitInfo));
  2805. aScopeInit[0].cbSize = sizeof(DSOP_SCOPE_INIT_INFO);
  2806. aScopeInit[1].cbSize = sizeof(DSOP_SCOPE_INIT_INFO);
  2807. InitInfo.cbSize = sizeof(InitInfo);
  2808. aScopeInit[0].FilterFlags.Uplevel.flBothModes = DSOP_FILTER_COMPUTERS;
  2809. aScopeInit[0].FilterFlags.flDownlevel = DSOP_DOWNLEVEL_FILTER_COMPUTERS;
  2810. aScopeInit[1].FilterFlags.Uplevel.flBothModes = DSOP_FILTER_COMPUTERS;
  2811. aScopeInit[1].FilterFlags.flDownlevel = DSOP_DOWNLEVEL_FILTER_COMPUTERS;
  2812. aScopeInit[0].flScope = DSOP_SCOPE_FLAG_WANT_PROVIDER_LDAP |DSOP_SCOPE_FLAG_WANT_PROVIDER_WINNT |DSOP_SCOPE_FLAG_STARTING_SCOPE;
  2813. aScopeInit[1].flScope = DSOP_SCOPE_FLAG_WANT_PROVIDER_LDAP |DSOP_SCOPE_FLAG_WANT_PROVIDER_WINNT;
  2814. aScopeInit[0].flType = DSOP_SCOPE_TYPE_UPLEVEL_JOINED_DOMAIN | DSOP_SCOPE_TYPE_DOWNLEVEL_JOINED_DOMAIN;
  2815. aScopeInit[1].flType = DSOP_SCOPE_TYPE_ENTERPRISE_DOMAIN
  2816. | DSOP_SCOPE_TYPE_EXTERNAL_UPLEVEL_DOMAIN
  2817. | DSOP_SCOPE_TYPE_EXTERNAL_DOWNLEVEL_DOMAIN
  2818. | DSOP_SCOPE_TYPE_USER_ENTERED_DOWNLEVEL_SCOPE
  2819. | DSOP_SCOPE_TYPE_USER_ENTERED_UPLEVEL_SCOPE;
  2820. InitInfo.pwzTargetComputer = targetComputer.GetBuffer(1000);// Target is the local computer.
  2821. targetComputer.ReleaseBuffer();
  2822. InitInfo.cDsScopeInfos = SCOPE_INIT_COUNT;
  2823. InitInfo.aDsScopeInfos = aScopeInit;
  2824. InitInfo.cAttributesToFetch = 3;
  2825. InitInfo.apwzAttributeNames = new PCWSTR[3];
  2826. InitInfo.apwzAttributeNames[0] =L"sAMAccountName";
  2827. InitInfo.apwzAttributeNames[1] =L"description";
  2828. InitInfo.apwzAttributeNames[2] =L"dNSHostName";
  2829. if (multiselect)
  2830. InitInfo.flOptions = DSOP_FLAG_MULTISELECT;
  2831. HRESULT hr= pDsObjectPicker->Initialize(&InitInfo);
  2832. delete [] InitInfo.apwzAttributeNames;
  2833. return hr;
  2834. }
  2835. HRESULT ReInitializeObjectPicker(IDsObjectPicker *pDsObjectPicker,bool multiselect,CString additionalDomainController,bool sourceIsNT4)
  2836. {CWaitCursor c;
  2837. // static const int SCOPE_INIT_COUNT = 3;
  2838. static const int SCOPE_INIT_COUNT = 2;
  2839. DSOP_SCOPE_INIT_INFO aScopeInit[SCOPE_INIT_COUNT];
  2840. DSOP_INIT_INFO InitInfo;
  2841. ZeroMemory(aScopeInit,
  2842. sizeof(DSOP_SCOPE_INIT_INFO) * SCOPE_INIT_COUNT);
  2843. ZeroMemory(&InitInfo, sizeof(InitInfo));
  2844. aScopeInit[0].cbSize = sizeof(DSOP_SCOPE_INIT_INFO);
  2845. aScopeInit[1].cbSize = sizeof(DSOP_SCOPE_INIT_INFO);
  2846. // aScopeInit[2].cbSize = sizeof(DSOP_SCOPE_INIT_INFO);
  2847. InitInfo.cbSize = sizeof(InitInfo);
  2848. aScopeInit[0].FilterFlags.Uplevel.flBothModes = DSOP_FILTER_COMPUTERS;
  2849. aScopeInit[0].FilterFlags.flDownlevel = DSOP_DOWNLEVEL_FILTER_COMPUTERS;
  2850. aScopeInit[1].FilterFlags.Uplevel.flBothModes = DSOP_FILTER_COMPUTERS;
  2851. aScopeInit[1].FilterFlags.flDownlevel = DSOP_DOWNLEVEL_FILTER_COMPUTERS;
  2852. // aScopeInit[2].FilterFlags.Uplevel.flBothModes = DSOP_FILTER_COMPUTERS;
  2853. // aScopeInit[2].FilterFlags.flDownlevel = DSOP_DOWNLEVEL_FILTER_COMPUTERS;
  2854. aScopeInit[0].flScope = DSOP_SCOPE_FLAG_WANT_PROVIDER_LDAP |DSOP_SCOPE_FLAG_WANT_PROVIDER_WINNT |DSOP_SCOPE_FLAG_STARTING_SCOPE;
  2855. aScopeInit[1].flScope = DSOP_SCOPE_FLAG_WANT_PROVIDER_LDAP |DSOP_SCOPE_FLAG_WANT_PROVIDER_WINNT;
  2856. // aScopeInit[2].flScope = DSOP_SCOPE_FLAG_WANT_PROVIDER_LDAP |DSOP_SCOPE_FLAG_WANT_PROVIDER_WINNT;
  2857. aScopeInit[0].flType = DSOP_SCOPE_TYPE_UPLEVEL_JOINED_DOMAIN | DSOP_SCOPE_TYPE_DOWNLEVEL_JOINED_DOMAIN;
  2858. aScopeInit[1].flType = DSOP_SCOPE_TYPE_ENTERPRISE_DOMAIN
  2859. | DSOP_SCOPE_TYPE_EXTERNAL_UPLEVEL_DOMAIN
  2860. | DSOP_SCOPE_TYPE_EXTERNAL_DOWNLEVEL_DOMAIN
  2861. | DSOP_SCOPE_TYPE_USER_ENTERED_DOWNLEVEL_SCOPE
  2862. | DSOP_SCOPE_TYPE_USER_ENTERED_UPLEVEL_SCOPE;
  2863. // aScopeInit[2].flType = DSOP_SCOPE_TYPE_UPLEVEL_JOINED_DOMAIN | DSOP_SCOPE_TYPE_DOWNLEVEL_JOINED_DOMAIN;
  2864. InitInfo.pwzTargetComputer = additionalDomainController.GetBuffer(1000);// Target is the local computer.
  2865. additionalDomainController.ReleaseBuffer();
  2866. InitInfo.cDsScopeInfos = SCOPE_INIT_COUNT;
  2867. InitInfo.aDsScopeInfos = aScopeInit;
  2868. if (sourceIsNT4)
  2869. {
  2870. }
  2871. else
  2872. {
  2873. InitInfo.cAttributesToFetch = 1;
  2874. InitInfo.apwzAttributeNames = new PCWSTR[1];
  2875. InitInfo.apwzAttributeNames[0] =L"Description";
  2876. }
  2877. if (multiselect)
  2878. InitInfo.flOptions = DSOP_FLAG_MULTISELECT;
  2879. HRESULT hr= pDsObjectPicker->Initialize(&InitInfo);
  2880. return hr;
  2881. }
  2882. HRESULT InitObjectPicker(IDsObjectPicker *pDsObjectPicker,bool multiselect,CString targetComputer,bool sourceIsNT4) {
  2883. static const int SCOPE_INIT_COUNT = 1;
  2884. DSOP_SCOPE_INIT_INFO aScopeInit[SCOPE_INIT_COUNT];
  2885. DSOP_INIT_INFO InitInfo;
  2886. ZeroMemory(aScopeInit,
  2887. sizeof(DSOP_SCOPE_INIT_INFO) * SCOPE_INIT_COUNT);
  2888. ZeroMemory(&InitInfo, sizeof(InitInfo));
  2889. aScopeInit[0].cbSize = sizeof(DSOP_SCOPE_INIT_INFO);
  2890. InitInfo.cbSize = sizeof(InitInfo);
  2891. aScopeInit[0].flType = DSOP_SCOPE_TYPE_UPLEVEL_JOINED_DOMAIN | DSOP_SCOPE_TYPE_DOWNLEVEL_JOINED_DOMAIN;
  2892. aScopeInit[0].flScope = DSOP_SCOPE_FLAG_WANT_PROVIDER_LDAP |DSOP_SCOPE_FLAG_WANT_PROVIDER_WINNT;
  2893. if (migration==w_computer || (migration==w_security ||
  2894. (migration==w_service || migration==w_reporting)))
  2895. {
  2896. aScopeInit[0].FilterFlags.Uplevel.flBothModes = DSOP_FILTER_COMPUTERS;
  2897. aScopeInit[0].FilterFlags.flDownlevel = DSOP_DOWNLEVEL_FILTER_COMPUTERS;
  2898. }
  2899. else if (migration==w_account)
  2900. {
  2901. aScopeInit[0].FilterFlags.Uplevel.flBothModes = DSOP_FILTER_USERS;
  2902. aScopeInit[0].FilterFlags.flDownlevel = DSOP_DOWNLEVEL_FILTER_USERS;
  2903. }
  2904. else if (migration==w_group || migration==w_groupmapping)
  2905. {
  2906. aScopeInit[0].FilterFlags.Uplevel.flBothModes = DSOP_FILTER_BUILTIN_GROUPS
  2907. | DSOP_FILTER_UNIVERSAL_GROUPS_SE | DSOP_FILTER_UNIVERSAL_GROUPS_DL
  2908. | DSOP_FILTER_GLOBAL_GROUPS_SE | DSOP_FILTER_GLOBAL_GROUPS_DL
  2909. | DSOP_FILTER_DOMAIN_LOCAL_GROUPS_SE | DSOP_FILTER_DOMAIN_LOCAL_GROUPS_DL;
  2910. aScopeInit[0].FilterFlags.flDownlevel = DSOP_DOWNLEVEL_FILTER_LOCAL_GROUPS | DSOP_DOWNLEVEL_FILTER_GLOBAL_GROUPS;
  2911. }
  2912. if (migration==w_security || (migration==w_reporting || migration==w_service))
  2913. {
  2914. aScopeInit[0].flType |= DSOP_SCOPE_TYPE_ENTERPRISE_DOMAIN
  2915. | DSOP_SCOPE_TYPE_EXTERNAL_UPLEVEL_DOMAIN
  2916. | DSOP_SCOPE_TYPE_EXTERNAL_DOWNLEVEL_DOMAIN
  2917. | DSOP_SCOPE_TYPE_USER_ENTERED_DOWNLEVEL_SCOPE
  2918. | DSOP_SCOPE_TYPE_USER_ENTERED_UPLEVEL_SCOPE /*| DSOP_SCOPE_TYPE_GLOBAL_CATALOG*/;
  2919. }
  2920. InitInfo.pwzTargetComputer = targetComputer.GetBuffer(1000);// Target is the local computer.
  2921. targetComputer.ReleaseBuffer();
  2922. InitInfo.cDsScopeInfos = SCOPE_INIT_COUNT;
  2923. InitInfo.aDsScopeInfos = aScopeInit;
  2924. if (sourceIsNT4)
  2925. {
  2926. if (migration==w_computer || (migration==w_security ||
  2927. (migration==w_service || migration==w_reporting)))
  2928. {
  2929. InitInfo.cAttributesToFetch = 2;
  2930. InitInfo.apwzAttributeNames = new PCWSTR[2];
  2931. InitInfo.apwzAttributeNames[0] =L"sAMAccountName";
  2932. InitInfo.apwzAttributeNames[1] =L"description";
  2933. }
  2934. else if (migration==w_account)
  2935. {
  2936. InitInfo.cAttributesToFetch = 2;
  2937. InitInfo.apwzAttributeNames = new PCWSTR[3];
  2938. InitInfo.apwzAttributeNames[0] =L"FullName";
  2939. InitInfo.apwzAttributeNames[1] =L"Description";
  2940. }
  2941. else if (migration==w_group || migration==w_groupmapping)
  2942. {
  2943. InitInfo.cAttributesToFetch = 1;
  2944. InitInfo.apwzAttributeNames = new PCWSTR[1];
  2945. InitInfo.apwzAttributeNames[0] =L"Description";
  2946. }
  2947. }
  2948. else
  2949. {
  2950. if (migration==w_computer || (migration==w_security ||
  2951. (migration==w_service || migration==w_reporting)))
  2952. {
  2953. InitInfo.cAttributesToFetch = 3;
  2954. InitInfo.apwzAttributeNames = new PCWSTR[3];
  2955. InitInfo.apwzAttributeNames[0] =L"sAMAccountName";
  2956. InitInfo.apwzAttributeNames[1] =L"Description";
  2957. InitInfo.apwzAttributeNames[2] =L"dNSHostName";
  2958. }
  2959. else if (migration==w_account)
  2960. {
  2961. InitInfo.cAttributesToFetch = 2;
  2962. InitInfo.apwzAttributeNames = new PCWSTR[2];
  2963. InitInfo.apwzAttributeNames[0] =L"sAMAccountName";
  2964. InitInfo.apwzAttributeNames[1] =L"Description";
  2965. }
  2966. else if (migration==w_group || migration==w_groupmapping)
  2967. {
  2968. InitInfo.cAttributesToFetch = 2;
  2969. InitInfo.apwzAttributeNames = new PCWSTR[2];
  2970. InitInfo.apwzAttributeNames[0] =L"sAMAccountName";
  2971. InitInfo.apwzAttributeNames[1] =L"Description";
  2972. }
  2973. }
  2974. if (multiselect)
  2975. InitInfo.flOptions = DSOP_FLAG_MULTISELECT;
  2976. HRESULT hr= pDsObjectPicker->Initialize(&InitInfo);
  2977. delete [] InitInfo.apwzAttributeNames;
  2978. return hr;
  2979. }
  2980. bool DC(WCHAR* computerName,CString sourceDomainController)
  2981. {
  2982. USER_INFO_1 * uinf1 = NULL;
  2983. bool toreturn =false;
  2984. NET_API_STATUS rc = NetUserGetInfo(sourceDomainController.GetBuffer(1000),computerName,1,(LPBYTE*)&uinf1);
  2985. sourceDomainController.ReleaseBuffer();
  2986. if ( ! rc )
  2987. {
  2988. if ( uinf1->usri1_flags & UF_SERVER_TRUST_ACCOUNT )
  2989. {
  2990. toreturn = true;
  2991. }
  2992. NetApiBufferFree(&uinf1);
  2993. }
  2994. return toreturn;
  2995. }
  2996. bool inList(CString m_name)
  2997. {CString temp;
  2998. m_name.TrimLeft();m_name.TrimRight();
  2999. int length=m_listBox.GetItemCount();
  3000. for (int i=0;i<length;i++)
  3001. {
  3002. temp=m_listBox.GetItemText(i,1);
  3003. temp.TrimLeft();temp.TrimRight();
  3004. if (!temp.CompareNoCase(m_name))return true;
  3005. }
  3006. return false;
  3007. }
  3008. void ProcessSelectedObjects(IDataObject *pdo,HWND hwndDlg,bool sourceIsNT4)
  3009. {
  3010. HRESULT hr = S_OK; BOOL fGotStgMedium = FALSE; PDS_SELECTION_LIST pDsSelList = NULL; ULONG i;
  3011. STGMEDIUM stgmedium = {TYMED_HGLOBAL, NULL, NULL};
  3012. FORMATETC formatetc = {(CLIPFORMAT) g_cfDsObjectPicker,NULL,DVASPECT_CONTENT,-1,TYMED_HGLOBAL};
  3013. hr = pdo->GetData(&formatetc, &stgmedium);
  3014. if (FAILED(hr)) return;
  3015. fGotStgMedium = TRUE;
  3016. pDsSelList = (PDS_SELECTION_LIST) GlobalLock(stgmedium.hGlobal);
  3017. if (!pDsSelList) return;
  3018. CString toinsert;
  3019. WCHAR temp[10000];
  3020. CString samName;
  3021. CString upnName;
  3022. bool atleast1dc=false;
  3023. bool continue1;
  3024. CString sourceDomainController;
  3025. if (migration==w_computer)
  3026. {
  3027. _bstr_t strDc;
  3028. DWORD res = GetDcName5(GetSourceDomainName(), DS_DIRECTORY_SERVICE_PREFERRED, strDc);
  3029. sourceDomainController=(LPCTSTR)strDc;
  3030. }
  3031. _bstr_t yo;
  3032. int a, ndx;
  3033. for (i = 0; i < pDsSelList->cItems; i++)
  3034. {
  3035. continue1=true;
  3036. toinsert = pDsSelList->aDsSelection[i].pwzName;
  3037. samName = pDsSelList->aDsSelection[i].pwzADsPath;
  3038. upnName = pDsSelList->aDsSelection[i].pwzUPN;
  3039. swprintf(temp,L"%s",(toinsert+L"$"));
  3040. if (migration ==w_computer)
  3041. {
  3042. if (DC(temp,sourceDomainController))
  3043. {
  3044. atleast1dc = true;
  3045. continue1=false;
  3046. }
  3047. }
  3048. if (!inList(samName)&&continue1)
  3049. {
  3050. a = m_listBox.GetItemCount();
  3051. ndx = m_listBox.InsertItem(a,toinsert);
  3052. if (ndx == -1)
  3053. continue;
  3054. SetItemText(m_listBox,ndx,1,samName);
  3055. if (migration==w_computer || (migration==w_security || (migration==w_service || migration==w_reporting)))
  3056. {
  3057. // set SAM account name column
  3058. // use sAMAccountName attribute if returned otherwise use name attribute
  3059. // uplevel objects will have the sAMAccountName attribute defined whereas
  3060. // downlevel objects will not have the sAMAccountName attribute defined but
  3061. // instead the name attribute is the SAM account name
  3062. _bstr_t strSamAccountName;
  3063. if (pDsSelList->cFetchedAttributes > 0)
  3064. {
  3065. VARIANT& varSamAccountName = pDsSelList->aDsSelection[i].pvarFetchedAttributes[0];
  3066. if ((V_VT(&varSamAccountName) == VT_BSTR) && (SysStringLen(V_BSTR(&varSamAccountName)) > 0))
  3067. {
  3068. strSamAccountName = V_BSTR(&varSamAccountName);
  3069. // remove trailing $ which indicates a computer account
  3070. // but ADMT core expects SAM name without $
  3071. if (strSamAccountName.length())
  3072. {
  3073. LPTSTR pch = (LPTSTR)strSamAccountName + strSamAccountName.length() - 1;
  3074. if (*pch == L'$')
  3075. {
  3076. *pch = L'\0';
  3077. }
  3078. }
  3079. }
  3080. else
  3081. {
  3082. strSamAccountName = toinsert;
  3083. }
  3084. }
  3085. else
  3086. {
  3087. strSamAccountName = toinsert;
  3088. }
  3089. SetItemText(m_listBox, ndx, 2, strSamAccountName);
  3090. // set description column
  3091. if (pDsSelList->cFetchedAttributes > 1)
  3092. {
  3093. VARIANT& varDescription = pDsSelList->aDsSelection[i].pvarFetchedAttributes[1];
  3094. if ((V_VT(&varDescription) == VT_BSTR) && (SysStringLen(V_BSTR(&varDescription)) > 0))
  3095. {
  3096. SetItemText(m_listBox, ndx, 3, _bstr_t(_variant_t(varDescription)));
  3097. }
  3098. }
  3099. // set DNS name column
  3100. if (pDsSelList->cFetchedAttributes > 2)
  3101. {
  3102. VARIANT& varDnsName = pDsSelList->aDsSelection[i].pvarFetchedAttributes[2];
  3103. if ((V_VT(&varDnsName) == VT_BSTR) && (SysStringLen(V_BSTR(&varDnsName)) > 0))
  3104. {
  3105. SetItemText(m_listBox, ndx, 4, _bstr_t(_variant_t(varDnsName)));
  3106. }
  3107. }
  3108. }
  3109. else
  3110. {
  3111. _variant_t v;
  3112. if (sourceIsNT4)
  3113. {
  3114. if (migration==w_account)
  3115. {
  3116. v = pDsSelList->aDsSelection[i].pvarFetchedAttributes[0];
  3117. yo = (_bstr_t) v;
  3118. SetItemText(m_listBox,ndx,2,yo);
  3119. v = pDsSelList->aDsSelection[i].pvarFetchedAttributes[1];
  3120. yo = (_bstr_t) v;
  3121. SetItemText(m_listBox,ndx,3,yo);
  3122. }
  3123. else if (migration==w_group || migration==w_groupmapping)
  3124. {
  3125. v = pDsSelList->aDsSelection[i].pvarFetchedAttributes[0];
  3126. yo = (_bstr_t) v;
  3127. SetItemText(m_listBox,ndx,2,yo);
  3128. }
  3129. }
  3130. else
  3131. {
  3132. if (migration==w_account)
  3133. {
  3134. v = pDsSelList->aDsSelection[i].pvarFetchedAttributes[0];
  3135. yo = (_bstr_t) v;
  3136. SetItemText(m_listBox,ndx,2,yo);
  3137. v = pDsSelList->aDsSelection[i].pvarFetchedAttributes[1];
  3138. yo = (_bstr_t) v;
  3139. SetItemText(m_listBox,ndx,3,yo);
  3140. SetItemText(m_listBox,ndx,4,upnName);
  3141. }
  3142. else if (migration==w_group || migration==w_groupmapping)
  3143. {
  3144. v = pDsSelList->aDsSelection[i].pvarFetchedAttributes[0];
  3145. yo = (_bstr_t) v;
  3146. SetItemText(m_listBox,ndx,2,yo);
  3147. v = pDsSelList->aDsSelection[i].pvarFetchedAttributes[1];
  3148. yo = (_bstr_t) v;
  3149. SetItemText(m_listBox,ndx,3,yo);
  3150. }
  3151. }
  3152. }
  3153. }
  3154. }
  3155. GlobalUnlock(stgmedium.hGlobal);
  3156. if (fGotStgMedium) ReleaseStgMedium(&stgmedium);
  3157. if (atleast1dc)
  3158. MessageBoxWrapper(hwndDlg,IDS_MSG_DC,IDS_MSG_ERROR);
  3159. }
  3160. bool checkFile(HWND hwndDlg)
  3161. {
  3162. CString h;GetDlgItemText(hwndDlg,IDC_PASSWORD_FILE,h.GetBuffer(1000),1000);h.ReleaseBuffer();
  3163. CFileFind finder;
  3164. bool exists = (finder.FindFile((LPCTSTR) h )!=0);
  3165. if (exists)
  3166. {
  3167. finder.FindNextFile();
  3168. CString fullpath = finder.GetFilePath();
  3169. if (fullpath.GetLength() != 0)
  3170. SetDlgItemText(hwndDlg, IDC_PASSWORD_FILE, (LPCTSTR)fullpath);
  3171. return !(finder.IsReadOnly()!=FALSE);
  3172. }
  3173. else
  3174. {
  3175. //remove the file off the path
  3176. int tosubtract = h.ReverseFind(L'\\');
  3177. int tosubtract2 = h.ReverseFind(L'/');
  3178. int final = (tosubtract > tosubtract2) ? tosubtract : tosubtract2;
  3179. if ((final==-1) || ((final+1)==h.GetLength()))return false;
  3180. CString dir = h.Left(final);
  3181. CString filename = h.Right(h.GetLength()-final); //save the filename
  3182. if ((dir.Right(1) == L':') && (validDir(dir)))
  3183. return true;
  3184. //call the helper function to make sure the path exists
  3185. CString sResult = CreatePath(dir);
  3186. if (sResult.GetLength())
  3187. {
  3188. //readd the filename to the resulting full path
  3189. sResult += filename;
  3190. SetDlgItemText(hwndDlg, IDC_PASSWORD_FILE, (LPCTSTR)sResult);
  3191. return true;
  3192. }
  3193. else
  3194. return false;
  3195. }
  3196. }
  3197. void ProcessSelectedObjects2(IDataObject *pdo,HWND hwndDlg)
  3198. {
  3199. HRESULT hr = S_OK; BOOL fGotStgMedium = FALSE; PDS_SELECTION_LIST pDsSelList = NULL;
  3200. STGMEDIUM stgmedium = {TYMED_HGLOBAL, NULL, NULL};
  3201. FORMATETC formatetc = {(CLIPFORMAT) g_cfDsObjectPicker,NULL,DVASPECT_CONTENT,-1,TYMED_HGLOBAL};
  3202. hr = pdo->GetData(&formatetc, &stgmedium);
  3203. if (FAILED(hr)) return;
  3204. fGotStgMedium = TRUE;
  3205. pDsSelList = (PDS_SELECTION_LIST) GlobalLock(stgmedium.hGlobal);
  3206. if (!pDsSelList) return;
  3207. SetDlgItemText(hwndDlg,IDC_TARGET_GROUP,pDsSelList->aDsSelection[0].pwzName);
  3208. GlobalUnlock(stgmedium.hGlobal);
  3209. if (fGotStgMedium) ReleaseStgMedium(&stgmedium);
  3210. }
  3211. void initpasswordbox(HWND hwndDlg,int id1,int id2,int id3, BSTR bstr1, BSTR bstr2)
  3212. {
  3213. _bstr_t text;
  3214. text = pVarSet->get(bstr2);
  3215. if (!UStrICmp(text,(WCHAR const *) yes))
  3216. {
  3217. CheckRadioButton(hwndDlg,id1,id3,id3);
  3218. }
  3219. else
  3220. {
  3221. text = pVarSet->get(bstr1);
  3222. if (!UStrICmp(text,(WCHAR const *) yes))
  3223. {
  3224. CheckRadioButton(hwndDlg,id1,id3,id1);
  3225. }
  3226. else
  3227. {
  3228. CheckRadioButton(hwndDlg,id1,id3,id2);
  3229. }
  3230. }
  3231. }
  3232. void initdisablesrcbox(HWND hwndDlg)
  3233. {
  3234. _bstr_t text;
  3235. CString toformat;
  3236. //init disable src checkbox
  3237. initcheckbox(hwndDlg,IDC_SRC_DISABLE_ACCOUNTS,DCTVS_AccountOptions_DisableSourceAccounts);
  3238. //set whether to expire accounts
  3239. text = pVarSet->get(GET_BSTR(DCTVS_AccountOptions_ExpireSourceAccounts));
  3240. //if invalid expire time, don't check it, set to 30 days, and disable the
  3241. //other sub controls
  3242. if ((!UStrICmp(text, L"")) || ((_wtol(text) == 0) && (UStrICmp(text,L"0"))) || (_wtol(text) > THREE_YEARS))
  3243. {
  3244. CheckDlgButton(hwndDlg, IDC_SRC_EXPIRE_ACCOUNTS, BST_UNCHECKED);
  3245. toformat.LoadString(IDS_30);
  3246. SetDlgItemText(hwndDlg,IDC_yo,toformat);
  3247. calculateDate(hwndDlg,toformat);
  3248. disable(hwndDlg,IDC_yo);
  3249. disable(hwndDlg,IDC_DATE);
  3250. disable(hwndDlg,IDC_TEXT);
  3251. }
  3252. else //else, check it, set to valid days, and enable sub controls
  3253. {
  3254. CheckDlgButton(hwndDlg, IDC_SRC_EXPIRE_ACCOUNTS, BST_CHECKED);
  3255. toformat = (WCHAR*)text;
  3256. SetDlgItemText(hwndDlg,IDC_yo,toformat);
  3257. calculateDate(hwndDlg,toformat);
  3258. enable(hwndDlg,IDC_yo);
  3259. enable(hwndDlg,IDC_DATE);
  3260. enable(hwndDlg,IDC_TEXT);
  3261. }
  3262. }
  3263. void inittgtstatebox(HWND hwndDlg)
  3264. {
  3265. _bstr_t text;
  3266. //if "Same as source" was set, check it
  3267. text = pVarSet->get(GET_BSTR(DCTVS_AccountOptions_TgtStateSameAsSrc));
  3268. if (!UStrICmp(text,(WCHAR const *) yes))
  3269. CheckRadioButton(hwndDlg,IDC_TGT_ENABLE_ACCOUNTS,IDC_TGT_SAME_AS_SOURCE,IDC_TGT_SAME_AS_SOURCE);
  3270. else //else set enable tgt or disable tgt
  3271. {
  3272. text = pVarSet->get(GET_BSTR(DCTVS_AccountOptions_DisableCopiedAccounts));
  3273. if (!UStrICmp(text,(WCHAR const *) yes))
  3274. CheckRadioButton(hwndDlg,IDC_TGT_ENABLE_ACCOUNTS,IDC_TGT_SAME_AS_SOURCE,IDC_TGT_DISABLE_ACCOUNTS);
  3275. else
  3276. CheckRadioButton(hwndDlg,IDC_TGT_ENABLE_ACCOUNTS,IDC_TGT_SAME_AS_SOURCE,IDC_TGT_ENABLE_ACCOUNTS);
  3277. }
  3278. }
  3279. void addrebootValues(HWND hwndDlg)
  3280. {
  3281. HWND hLC3= GetDlgItem(hwndDlg,IDC_COMBO2);
  3282. m_rebootBox.Attach(hLC3);
  3283. m_rebootBox.AddString(GET_CSTRING(IDS_ONE));
  3284. m_rebootBox.AddString(GET_CSTRING(IDS_FIVE));
  3285. m_rebootBox.AddString(GET_CSTRING(IDS_TEN));
  3286. }
  3287. void inittranslationbox(HWND hwndDlg,int id1,int id2,int id3,int i,bool sameForest)
  3288. {
  3289. _bstr_t text;
  3290. text = pVarSet->get(GET_BSTR(i));
  3291. _bstr_t b=pVarSet->get(GET_BSTR(DCTVS_Options_SourceDomain));
  3292. HRESULT hr;
  3293. if (sameForest && targetNativeMode(b,hr))
  3294. {
  3295. CheckRadioButton(hwndDlg,id1,id3,id1);
  3296. disable(hwndDlg,id2);
  3297. disable(hwndDlg,id3);
  3298. }
  3299. else
  3300. {
  3301. //* if (!UStrICmp(text,L"Replace"))
  3302. if (!UStrICmp(text,GET_STRING(IDS_Replace)))
  3303. CheckRadioButton(hwndDlg,id1,id3,id1);
  3304. //* else if (!UStrICmp(text,L"Add"))
  3305. else if (!UStrICmp(text,GET_STRING(IDS_Add)))
  3306. CheckRadioButton(hwndDlg,id1,id3,id2);
  3307. //* else if (!UStrICmp(text,L"Remove"))
  3308. else if (!UStrICmp(text,GET_STRING(IDS_Remove)))
  3309. CheckRadioButton(hwndDlg,id1,id3,id3);
  3310. else
  3311. CheckRadioButton(hwndDlg,id1,id3,id1);
  3312. }
  3313. }
  3314. void handleDB()
  3315. {
  3316. _variant_t vntIdentifier = get(DCTVS_AccountOptions_SidHistoryCredentials_Password);
  3317. put(DCTVS_AccountOptions_SidHistoryCredentials_Password,L"");
  3318. put(DCTVS_GatherInformation, L"");
  3319. db->SaveSettings(IUnknownPtr(pVarSet));
  3320. put(DCTVS_AccountOptions_SidHistoryCredentials_Password, vntIdentifier);
  3321. }
  3322. void populateTime(long rebootDelay,int servers )
  3323. {
  3324. _variant_t varX;
  3325. CString temp;
  3326. CString typeExtension;
  3327. time_t ltime;
  3328. if (migration==w_computer)
  3329. {
  3330. time(&ltime);
  3331. rebootDelay = rebootDelay;
  3332. temp.Format(L"%d",rebootDelay);
  3333. varX = temp;
  3334. for (int i =0;i<servers;i++)
  3335. {
  3336. typeExtension.Format(L"Servers.%d.RebootDelay",i);
  3337. pVarSet->put(_bstr_t(typeExtension), varX);
  3338. typeExtension.Format(L"Servers.%d.Reboot",i);
  3339. pVarSet->put(_bstr_t(typeExtension),yes);
  3340. }
  3341. }
  3342. }
  3343. void initcheckbox(HWND hwndDlg,int id,int varsetKey)
  3344. {
  3345. _bstr_t text;
  3346. text = pVarSet->get(GET_BSTR(varsetKey));
  3347. CheckDlgButton( hwndDlg,id, !UStrICmp(text,(WCHAR const * ) yes));
  3348. }
  3349. void initeditbox(HWND hwndDlg,int id,int varsetKey)
  3350. {
  3351. _bstr_t text;
  3352. text = pVarSet->get(GET_BSTR(varsetKey));
  3353. SetDlgItemText( hwndDlg,id, (WCHAR const *) text);
  3354. }
  3355. void initeditboxPassword(HWND hwndDlg, int id, int varsetKey)
  3356. {
  3357. WCHAR szPassword[LEN_Password];
  3358. szPassword[0] = L'\0';
  3359. _bstr_t strIdentifier = pVarSet->get(GET_BSTR(varsetKey));
  3360. if (strIdentifier.length() > 0)
  3361. {
  3362. DWORD dwError = RetrievePassword(strIdentifier, szPassword, countof(szPassword));
  3363. if (dwError != ERROR_SUCCESS)
  3364. {
  3365. StorePassword(strIdentifier, NULL);
  3366. pVarSet->put(GET_BSTR(varsetKey), L"");
  3367. }
  3368. }
  3369. SetDlgItemText(hwndDlg, id, szPassword);
  3370. SecureZeroMemory(szPassword, sizeof(szPassword));
  3371. }
  3372. void checkbox(HWND hwndDlg,int id,int varsetKey)
  3373. {
  3374. _variant_t varX;
  3375. varX = IsDlgButtonChecked( hwndDlg,id) ? yes : no;
  3376. pVarSet->put(GET_BSTR(varsetKey), varX);
  3377. }
  3378. void editbox(HWND hwndDlg,int id,int varsetKey)
  3379. {
  3380. _variant_t varX;
  3381. CString temp;
  3382. GetDlgItemText( hwndDlg, id, temp.GetBuffer(1000),1000);
  3383. temp.ReleaseBuffer();
  3384. varX = temp;
  3385. pVarSet->put(GET_BSTR(varsetKey), varX);
  3386. }
  3387. void editboxPassword(HWND hwndDlg, int id, int varsetKey)
  3388. {
  3389. //
  3390. // Retrieve password from editbox.
  3391. //
  3392. WCHAR szPassword[LEN_Password];
  3393. int cch = GetDlgItemText(hwndDlg, id, szPassword, countof(szPassword));
  3394. if (cch > 0)
  3395. {
  3396. if (cch < countof(szPassword))
  3397. {
  3398. //
  3399. // Retrieve password identifier. If not defined then generate new identifier.
  3400. //
  3401. _bstr_t strIdentifier = pVarSet->get(GET_BSTR(varsetKey));
  3402. if (strIdentifier.length() == 0)
  3403. {
  3404. WCHAR szIdentifier[256];
  3405. DWORD dwError = GeneratePasswordIdentifier(szIdentifier, countof(szIdentifier));
  3406. if (dwError == ERROR_SUCCESS)
  3407. {
  3408. strIdentifier = szIdentifier;
  3409. }
  3410. else
  3411. {
  3412. MessageBoxWrapper(hwndDlg, IDS_MSG_UNABLE_RETRIEVE_STORE_PASSWORD, IDS_MSG_ERROR);
  3413. }
  3414. }
  3415. //
  3416. // If identifier then store password.
  3417. //
  3418. if (strIdentifier.length() > 0)
  3419. {
  3420. DWORD dwError = StorePassword(strIdentifier, szPassword);
  3421. if (dwError == ERROR_SUCCESS)
  3422. {
  3423. pVarSet->put(GET_BSTR(varsetKey), strIdentifier);
  3424. }
  3425. else
  3426. {
  3427. StorePassword(strIdentifier, NULL);
  3428. pVarSet->put(GET_BSTR(varsetKey), L"");
  3429. MessageBoxWrapper(hwndDlg, IDS_MSG_UNABLE_RETRIEVE_STORE_PASSWORD, IDS_MSG_ERROR);
  3430. }
  3431. }
  3432. }
  3433. else
  3434. {
  3435. ErrorWrapper(hwndDlg, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER));
  3436. }
  3437. }
  3438. else
  3439. {
  3440. DWORD dwError = GetLastError();
  3441. if (dwError != ERROR_SUCCESS)
  3442. {
  3443. ErrorWrapper(hwndDlg, HRESULT_FROM_WIN32(dwError));
  3444. }
  3445. }
  3446. SecureZeroMemory(szPassword, sizeof(szPassword));
  3447. }
  3448. void translationbox(HWND hwndDlg,int id1,int id2,int id3,int varsetKey)
  3449. {
  3450. _variant_t varX;
  3451. if (IsDlgButtonChecked( hwndDlg, id1))
  3452. //* varX = L"Replace";
  3453. varX = GET_STRING(IDS_Replace);
  3454. else if(IsDlgButtonChecked( hwndDlg, id2))
  3455. //* varX = L"Add";
  3456. varX = GET_STRING(IDS_Add);
  3457. else if (IsDlgButtonChecked( hwndDlg, id3))
  3458. //* varX = L"Remove";
  3459. varX = GET_STRING(IDS_Remove);
  3460. pVarSet->put(GET_BSTR(varsetKey), varX);
  3461. }
  3462. long rebootbox(HWND hwndDlg,int id)
  3463. {
  3464. _variant_t varX;
  3465. int rebootDelay;
  3466. if (IsDlgItemEmpty(hwndDlg,id))
  3467. rebootDelay=0;
  3468. else
  3469. {
  3470. CString rebooter;
  3471. GetDlgItemText( hwndDlg, id, rebooter.GetBuffer(1000), 1000);
  3472. rebooter.ReleaseBuffer();
  3473. rebootDelay = _ttoi(rebooter.GetBuffer(1000));
  3474. rebooter.ReleaseBuffer();
  3475. }
  3476. rebootDelay =rebootDelay*60;
  3477. return rebootDelay;
  3478. }
  3479. void populateList(CComboBox& s)
  3480. {
  3481. DWORD fndNet=0; // number of nets found
  3482. DWORD rcNet; // net enum return code
  3483. HANDLE eNet = NULL; // enumerate net domains
  3484. EaWNetDomainInfo iNet; // net domain info
  3485. rcNet = EaWNetDomainEnumOpen( &eNet );
  3486. if (!rcNet )
  3487. {
  3488. for ( rcNet = EaWNetDomainEnumFirst( eNet, &iNet );
  3489. !rcNet;
  3490. rcNet = EaWNetDomainEnumNext( eNet, &iNet ) )
  3491. {
  3492. fndNet++;
  3493. s.AddString(iNet.name);
  3494. }
  3495. }
  3496. if (eNet)
  3497. {
  3498. EaWNetDomainEnumClose( eNet );
  3499. }
  3500. }
  3501. //
  3502. // void populateTrustingList(CString domainName, CComboBox& comboBox)
  3503. // This function populates the combo box list with trusting domains of the specified domain name.
  3504. //
  3505. // Arguments:
  3506. // domainName: the name of the domain for which the trusting domains will be looked up
  3507. // comboBox: the combo box object to which the trusting domains will be added to
  3508. //
  3509. void populateTrustingList(CString domainName, CComboBox& comboBox)
  3510. {
  3511. // clean up the list in combo box
  3512. comboBox.ResetContent();
  3513. // we are taking advantage of ITrust interface here
  3514. ITrustPtr pTrusts;
  3515. HRESULT hr = pTrusts.CreateInstance(CLSID_Trust);
  3516. if ( SUCCEEDED(hr) )
  3517. {
  3518. IUnknownPtr pUnk;
  3519. // set up logging for trust
  3520. CString dirname;
  3521. GetDirectory(dirname.GetBuffer(1000));
  3522. dirname.ReleaseBuffer();
  3523. dirname+= L"Logs\\trust.log";
  3524. // query trusts including trusting and trusted domains
  3525. hr = pTrusts->raw_QueryTrusts(_bstr_t(domainName),_bstr_t(domainName),_bstr_t(dirname),&pUnk);
  3526. if ( SUCCEEDED(hr) )
  3527. {
  3528. IVarSetPtr pVsTrusts(pUnk);
  3529. // pick trusting ones
  3530. long nTrusts = pVsTrusts->get(L"Trusts");
  3531. for ( long i = 0 ; i < nTrusts ; i++ )
  3532. {
  3533. CString base;
  3534. CString sub;
  3535. base.Format(L"Trusts.%ld",i);
  3536. _bstr_t value = pVsTrusts->get(_bstr_t(base));
  3537. sub = base + L".Direction";
  3538. _bstr_t direction = pVsTrusts->get(_bstr_t(sub));
  3539. // we are looking for either inbound or bidirectional trusts
  3540. if ((direction == GET_BSTR(IDS_TRUST_DIRECTION_BIDIRECTIONAL))
  3541. || (direction == GET_BSTR(IDS_TRUST_DIRECTION_INBOUND)))
  3542. comboBox.AddString(value);
  3543. }
  3544. }
  3545. }
  3546. }
  3547. void enable(HWND hwndDlg,int id)
  3548. {
  3549. HWND temp=GetDlgItem(hwndDlg,id);
  3550. EnableWindow(temp,true);
  3551. }
  3552. void disable(HWND hwndDlg,int id)
  3553. {
  3554. HWND temp=GetDlgItem(hwndDlg,id);
  3555. EnableWindow(temp,false);
  3556. }
  3557. void handleInitRename(HWND hwndDlg,bool sameForest,bool bCopyGroups)
  3558. {
  3559. _bstr_t text1,text2,text3;
  3560. text1 = get(DCTVS_AccountOptions_ReplaceExistingAccounts);
  3561. text2 = get(DCTVS_AccountOptions_Prefix);
  3562. text3 = get(DCTVS_AccountOptions_Suffix);
  3563. initeditbox(hwndDlg,IDC_PREFIX,DCTVS_AccountOptions_Prefix );
  3564. initeditbox(hwndDlg,IDC_SUFFIX,DCTVS_AccountOptions_Suffix );
  3565. initcheckbox(hwndDlg,IDC_REMOVE_EXISTING_USER_RIGHTS,DCTVS_AccountOptions_RemoveExistingUserRights);
  3566. initcheckbox(hwndDlg,IDC_REMOVE_EXISTING_LOCATION,DCTVS_AccountOptions_MoveReplacedAccounts);
  3567. if ((migration==w_computer) || (!bCopyGroups))
  3568. {
  3569. disable(hwndDlg,IDC_REPLACE_EXISTING_GROUP_MEMBERS);
  3570. CheckDlgButton( hwndDlg,IDC_REPLACE_EXISTING_GROUP_MEMBERS,false);
  3571. }
  3572. else
  3573. {
  3574. enable(hwndDlg,IDC_REPLACE_EXISTING_GROUP_MEMBERS);
  3575. initcheckbox(hwndDlg,IDC_REPLACE_EXISTING_GROUP_MEMBERS,DCTVS_AccountOptions_ReplaceExistingGroupMembers);
  3576. }
  3577. if (!UStrICmp(text1,(WCHAR const *) yes))
  3578. CheckRadioButton(hwndDlg,IDC_SKIP_CONFLICTING_ACCOUNTS,IDC_RENAME_CONFLICTING_ACCOUNTS,IDC_REPLACE_CONFLICTING_ACCOUNTS);
  3579. else if (UStrICmp(text2,L"") || UStrICmp(text3,L""))
  3580. CheckRadioButton(hwndDlg,IDC_SKIP_CONFLICTING_ACCOUNTS,IDC_RENAME_CONFLICTING_ACCOUNTS,IDC_RENAME_CONFLICTING_ACCOUNTS);
  3581. else
  3582. CheckRadioButton(hwndDlg,IDC_SKIP_CONFLICTING_ACCOUNTS,IDC_RENAME_CONFLICTING_ACCOUNTS,IDC_SKIP_CONFLICTING_ACCOUNTS);
  3583. if (IsDlgButtonChecked(hwndDlg,IDC_REPLACE_CONFLICTING_ACCOUNTS) &&
  3584. ((sameForest) && migration !=w_computer))
  3585. {
  3586. CheckRadioButton(hwndDlg,IDC_SKIP_CONFLICTING_ACCOUNTS,IDC_RENAME_CONFLICTING_ACCOUNTS,IDC_SKIP_CONFLICTING_ACCOUNTS);
  3587. disable(hwndDlg,IDC_REPLACE_CONFLICTING_ACCOUNTS);
  3588. }
  3589. else if (sameForest && migration !=w_computer)
  3590. disable(hwndDlg,IDC_REPLACE_CONFLICTING_ACCOUNTS);
  3591. }
  3592. void MessageBoxWrapper(HWND hwndDlg,int m,int t)
  3593. {
  3594. CString message;
  3595. CString title;
  3596. message.LoadString(m);
  3597. title.LoadString(t);
  3598. MessageBox(hwndDlg,message,title,MB_OK | MB_ICONSTOP);
  3599. }
  3600. void MessageBoxWrapper3(HWND hwndDlg,int m,int t,CString domainName)
  3601. {
  3602. CString message;
  3603. CString title;
  3604. message.LoadString(m);
  3605. title.LoadString(t);
  3606. CString messageFormatter;
  3607. messageFormatter.LoadString(IDS_FORMAT_MESSAGE);
  3608. CString text;
  3609. text.Format(messageFormatter,message,domainName);
  3610. MessageBox(hwndDlg,text,title,MB_OK|MB_ICONSTOP);
  3611. }
  3612. void MessageBoxWrapperFormat1(HWND hwndDlg,int f,int m, int t)
  3613. {
  3614. CString formatter;
  3615. CString insert;
  3616. CString message;
  3617. CString title;
  3618. formatter.LoadString(f);
  3619. insert.LoadString(m);
  3620. message.Format(formatter,insert);
  3621. title.LoadString(t);
  3622. MessageBox(hwndDlg,message,title,MB_OK | MB_ICONSTOP);
  3623. }
  3624. void MessageBoxWrapperFormat1P(HWND hwndDlg,int f, int t, CString sInsert11)
  3625. {
  3626. CString formatter;
  3627. CString message;
  3628. CString title;
  3629. formatter.LoadString(f);
  3630. message.Format(formatter,sInsert11);
  3631. title.LoadString(t);
  3632. MessageBox(hwndDlg,message,title,MB_OK | MB_ICONSTOP);
  3633. }
  3634. HRESULT BrowseForContainer(HWND hWnd,//Handle to window that should own the browse dialog.
  3635. LPOLESTR szRootPath, //Root of the browse tree. NULL for entire forest.
  3636. LPOLESTR *ppContainerADsPath, //Return the ADsPath of the selected container.
  3637. LPOLESTR *ppContainerClass //Return the ldapDisplayName of the container's class.
  3638. )
  3639. {
  3640. HRESULT hr = E_FAIL;
  3641. DSBROWSEINFO dsbi;
  3642. OLECHAR szPath[5000];
  3643. OLECHAR szClass[MAX_PATH];
  3644. DWORD result;
  3645. if (!ppContainerADsPath)
  3646. return E_POINTER;
  3647. ::ZeroMemory( &dsbi, sizeof(dsbi) );
  3648. dsbi.hwndOwner = hWnd;
  3649. dsbi.cbStruct = sizeof (DSBROWSEINFO);
  3650. CString temp1,temp2;
  3651. temp1.LoadString(IDS_BROWSER);
  3652. temp2.LoadString(IDS_SELECTOR);
  3653. dsbi.pszCaption = temp1.GetBuffer(1000);
  3654. temp1.ReleaseBuffer();
  3655. dsbi.pszTitle = temp2.GetBuffer(1000);
  3656. temp2.ReleaseBuffer();
  3657. // L"Browse for Container"; // The caption (titlebar text)
  3658. // dsbi.pszTitle = L"Select a target container."; //Text for the dialog.
  3659. dsbi.pszRoot = szRootPath; //ADsPath for the root of the tree to display in the browser.
  3660. //Specify NULL with DSBI_ENTIREDIRECTORY flag for entire forest.
  3661. //NULL without DSBI_ENTIREDIRECTORY flag displays current domain rooted at LDAP.
  3662. dsbi.pszPath = szPath; //Pointer to a unicode string buffer.
  3663. dsbi.cchPath = sizeof(szPath)/sizeof(OLECHAR);//count of characters for buffer.
  3664. dsbi.dwFlags = DSBI_RETURN_FORMAT | //Return the path to object in format specified in dwReturnFormat
  3665. DSBI_RETURNOBJECTCLASS; //Return the object class
  3666. dsbi.pfnCallback = NULL;
  3667. dsbi.lParam = 0;
  3668. dsbi.dwReturnFormat = ADS_FORMAT_X500; //Specify the format.
  3669. //This one returns an ADsPath. See ADS_FORMAT enum in IADS.H
  3670. dsbi.pszObjectClass = szClass; //Pointer to a unicode string buffer.
  3671. dsbi.cchObjectClass = sizeof(szClass)/sizeof(OLECHAR);//count of characters for buffer.
  3672. //if root path is NULL, make the forest the root.
  3673. if (!szRootPath)
  3674. dsbi.dwFlags |= DSBI_ENTIREDIRECTORY;
  3675. //Display browse dialog box.
  3676. result = DsBrowseForContainerX( &dsbi ); // returns -1, 0, IDOK or IDCANCEL
  3677. if (result == IDOK)
  3678. {
  3679. //Allocate memory for string
  3680. *ppContainerADsPath = (OLECHAR *)CoTaskMemAlloc (sizeof(OLECHAR)*(wcslen(szPath)+1));
  3681. if (*ppContainerADsPath)
  3682. {
  3683. hr = S_OK;
  3684. wcscpy(*ppContainerADsPath, szPath);
  3685. //Caller must free using CoTaskMemFree
  3686. //if the domain was selected, add the DC= stuff
  3687. CString sNewPath = szPath;
  3688. if (sNewPath.Find(L"DC=") == -1)
  3689. {
  3690. //try retrieving the ADsPath of the containier, which does include
  3691. //the full LDAP path with DC=
  3692. IADsPtr pCont;
  3693. BSTR sAdsPath;
  3694. hr = ADsGetObject(sNewPath,IID_IADs,(void**)&pCont);
  3695. if (SUCCEEDED(hr))
  3696. {
  3697. hr = pCont->get_ADsPath(&sAdsPath);
  3698. if (SUCCEEDED(hr))
  3699. {
  3700. sNewPath = (WCHAR*)sAdsPath;
  3701. SysFreeString(sAdsPath);
  3702. CoTaskMemFree(*ppContainerADsPath);
  3703. *ppContainerADsPath = (OLECHAR *)CoTaskMemAlloc (sizeof(OLECHAR)*(sNewPath.GetLength()+1));
  3704. if (*ppContainerADsPath)
  3705. wcscpy(*ppContainerADsPath, (LPCTSTR)sNewPath);
  3706. else
  3707. hr=E_FAIL;
  3708. }
  3709. }
  3710. }
  3711. }
  3712. else
  3713. hr=E_FAIL;
  3714. if (ppContainerClass)
  3715. {
  3716. //Allocate memory for string
  3717. *ppContainerClass = (OLECHAR *)CoTaskMemAlloc (sizeof(OLECHAR)*(wcslen(szClass)+1));
  3718. if (*ppContainerClass)
  3719. {
  3720. wcscpy(*ppContainerClass, szClass);
  3721. //Call must free using CoTaskMemFree
  3722. hr = S_OK;
  3723. }
  3724. else
  3725. hr=E_FAIL;
  3726. }
  3727. }
  3728. else
  3729. hr = E_FAIL;
  3730. return hr;
  3731. }
  3732. BOOL GetDomainAndUserFromUPN(WCHAR const * UPNname,CString& domainNetbios, CString& user)
  3733. {
  3734. HRESULT hr;
  3735. HINSTANCE hLibrary = NULL;
  3736. DSCRACKNAMES * DsCrackNames = NULL;
  3737. DSFREENAMERESULT * DsFreeNameResult = NULL;
  3738. DSBINDFUNC DsBind = NULL;
  3739. DSUNBINDFUNC DsUnBind = NULL;
  3740. HANDLE hDs = NULL;
  3741. BOOL bConverted = FALSE;
  3742. CString resultStr;
  3743. CString sDomainDNS;
  3744. // make sure the account name is in UPN format
  3745. if ( NULL != wcschr(UPNname,L'\\') )
  3746. return FALSE;
  3747. hLibrary = LoadLibrary(L"NTDSAPI.DLL");
  3748. if ( hLibrary )
  3749. {
  3750. DsBind = (DSBINDFUNC)GetProcAddress(hLibrary,"DsBindW");
  3751. DsUnBind = (DSUNBINDFUNC)GetProcAddress(hLibrary,"DsUnBindW");
  3752. DsCrackNames = (DSCRACKNAMES *)GetProcAddress(hLibrary,"DsCrackNamesW");
  3753. DsFreeNameResult = (DSFREENAMERESULT *)GetProcAddress(hLibrary,"DsFreeNameResultW");
  3754. }
  3755. if ( DsBind && DsUnBind && DsCrackNames && DsFreeNameResult)
  3756. {
  3757. hr = (*DsBind)(NULL,const_cast<TCHAR*>(GetTargetDomainName()),&hDs);
  3758. if ( !hr )
  3759. {
  3760. PDS_NAME_RESULT pNamesOut = NULL;
  3761. WCHAR * pNamesIn[1];
  3762. pNamesIn[0] = const_cast<WCHAR *>(UPNname);
  3763. hr = (*DsCrackNames)(hDs,DS_NAME_NO_FLAGS,DS_USER_PRINCIPAL_NAME,DS_NT4_ACCOUNT_NAME,1,pNamesIn,&pNamesOut);
  3764. (*DsUnBind)(&hDs);
  3765. if ( !hr )
  3766. {
  3767. if (pNamesOut->rItems[0].status == DS_NAME_NO_ERROR)
  3768. {
  3769. resultStr = pNamesOut->rItems[0].pName;
  3770. int index = resultStr.Find(L'\\');
  3771. if (index != -1)
  3772. domainNetbios = resultStr.Left(index); //parse off the domain netbios name
  3773. if (!domainNetbios.IsEmpty())
  3774. {
  3775. //get the user's sAMAccountName
  3776. user = resultStr.Right(resultStr.GetLength() - index - 1);
  3777. if (!user.IsEmpty())
  3778. bConverted = TRUE;
  3779. }
  3780. }
  3781. else if (pNamesOut->rItems[0].status == DS_NAME_ERROR_DOMAIN_ONLY)
  3782. {
  3783. sDomainDNS = pNamesOut->rItems[0].pDomain;
  3784. hr = (*DsBind)(NULL,sDomainDNS.GetBuffer(1000),&hDs);
  3785. sDomainDNS.ReleaseBuffer();
  3786. if ( !hr )
  3787. {
  3788. (*DsFreeNameResult)(pNamesOut);
  3789. pNamesOut = NULL;
  3790. hr = (*DsCrackNames)(hDs,DS_NAME_NO_FLAGS,DS_USER_PRINCIPAL_NAME,DS_NT4_ACCOUNT_NAME,1,pNamesIn,&pNamesOut);
  3791. if ( !hr )
  3792. {
  3793. if ( pNamesOut->rItems[0].status == DS_NAME_NO_ERROR )
  3794. {
  3795. resultStr = pNamesOut->rItems[0].pName;
  3796. int index = resultStr.Find(L'\\');
  3797. if (index != -1)
  3798. domainNetbios = resultStr.Left(index); //parse off the domain netbios name
  3799. if (!domainNetbios.IsEmpty())
  3800. {
  3801. //get the user's sAMAccountName
  3802. user = resultStr.Right(resultStr.GetLength() - index - 1);
  3803. if (!user.IsEmpty())
  3804. bConverted = TRUE;
  3805. }
  3806. }//end if no error
  3807. }//end if name cracked
  3808. (*DsUnBind)(&hDs);
  3809. }//end if bound to other domain
  3810. }
  3811. if (pNamesOut)
  3812. (*DsFreeNameResult)(pNamesOut);
  3813. }//end if name cracked
  3814. }//end if bound to target domain
  3815. }//end got functions
  3816. if ( hLibrary )
  3817. {
  3818. FreeLibrary(hLibrary);
  3819. }
  3820. return bConverted;
  3821. }
  3822. /*********************************************************************
  3823. * *
  3824. * Written by: Paul Thompson *
  3825. * Date: 31 AUG 2000 *
  3826. * *
  3827. * This function is responsible for switching between showing the*
  3828. * password file editbox and the password dc combobox. *
  3829. * *
  3830. *********************************************************************/
  3831. //BEGIN switchboxes
  3832. void switchboxes(HWND hwndDlg,int oldid, int newid)
  3833. {
  3834. /* local variables */
  3835. CWnd oldWnd;
  3836. CWnd newWnd;
  3837. /* function body */
  3838. oldWnd.Attach(GetDlgItem(hwndDlg, oldid));
  3839. newWnd.Attach(GetDlgItem(hwndDlg, newid));
  3840. oldWnd.ShowWindow(SW_HIDE);
  3841. newWnd.ShowWindow(SW_SHOW);
  3842. oldWnd.Detach();
  3843. newWnd.Detach();
  3844. }
  3845. //END switchboxes
  3846. /*********************************************************************
  3847. * *
  3848. * Written by: Paul Thompson *
  3849. * Date: 31 AUG 2000 *
  3850. * *
  3851. * This function is responsible for enumerating all DCs in the *
  3852. * given source domain and add them into the source domain combobox. *
  3853. * *
  3854. *********************************************************************/
  3855. //BEGIN populatePasswordDCs
  3856. bool populatePasswordDCs(HWND hwndDlg, int id, bool bNT4)
  3857. {
  3858. /* local variables */
  3859. CComboBox pwdCombo;
  3860. CString aDCName;
  3861. CString aDnName;
  3862. IEnumVARIANT * pEnumerator = NULL;
  3863. VARIANT var;
  3864. POSITION currentPos;
  3865. HRESULT hr = S_OK;
  3866. /* function body */
  3867. VariantInit(&var);
  3868. pwdCombo.Attach(GetDlgItem(hwndDlg, id));
  3869. //if we already have a list of DCs for this domain then add them
  3870. if (!DCList.IsEmpty())
  3871. {
  3872. //get the position and string of the first name in the list
  3873. currentPos = DCList.GetHeadPosition();
  3874. //while there is another entry to retrieve from the list, then
  3875. //get a name from the list and add it to the combobox
  3876. while (currentPos != NULL)
  3877. {
  3878. //get the next string in the list, starts with the first
  3879. aDCName = DCList.GetNext(currentPos);
  3880. if (pwdCombo.FindString(-1, aDCName) == CB_ERR)
  3881. pwdCombo.AddString(aDCName);//add the DC to the combobox
  3882. }
  3883. }
  3884. else //else enumerate DCs in the domain and add them
  3885. {
  3886. pwdCombo.ResetContent();//reset the combobox contents
  3887. //enumerate all domain controllers in the given domain
  3888. if (bNT4)
  3889. hr = QueryNT4DomainControllers(GetSourceDomainName(), pEnumerator);
  3890. else
  3891. hr = QueryW2KDomainControllers(GetSourceDomainName(), pEnumerator);
  3892. if (SUCCEEDED(hr))
  3893. {
  3894. unsigned long count = 0;
  3895. //for each computer see if a DC. If so, add to combobox
  3896. while ( pEnumerator->Next(1,&var,&count) == S_OK )
  3897. {
  3898. //get the sam account name for this computer
  3899. if ( var.vt == ( VT_ARRAY | VT_VARIANT ) )
  3900. {
  3901. VARIANT * pData;
  3902. _variant_t vnt;
  3903. _bstr_t abstr;
  3904. SafeArrayAccessData(var.parray,(void**)&pData);
  3905. // pData[0] has the sam account name list
  3906. vnt.Attach(pData[0]);
  3907. abstr = _bstr_t(vnt);
  3908. aDCName = (WCHAR *)abstr;
  3909. vnt.Detach();
  3910. SafeArrayUnaccessData(var.parray);
  3911. //computer sAMAccountNames end in $, lets get rid of that
  3912. int length = aDCName.GetLength();
  3913. if (aDCName[length-1] == L'$')
  3914. aDCName = aDCName.Left(length-1);
  3915. //add the DC to the combobox and the memory list, if not in already
  3916. if (pwdCombo.FindString(-1, aDCName) == CB_ERR)
  3917. pwdCombo.AddString(aDCName);
  3918. if (DCList.Find(aDCName) == NULL)
  3919. DCList.AddTail(aDCName);
  3920. }
  3921. }//end while more computers
  3922. pEnumerator->Release();
  3923. }
  3924. }//end if must get DCs
  3925. pwdCombo.Detach();
  3926. if (hr == S_OK)
  3927. return true;
  3928. else
  3929. return false;
  3930. }
  3931. //END populatePasswordDCs
  3932. /*********************************************************************
  3933. * *
  3934. * Written by: Paul Thompson *
  3935. * Date: 1 SEPT 2000 *
  3936. * *
  3937. * This worker function is responsible for enumerating all domain*
  3938. * controllers in the given Windows 2000 domain. The variant array *
  3939. * passed back is filled with the sAMAccountName for each domain *
  3940. * controller. *
  3941. * *
  3942. *********************************************************************/
  3943. //BEGIN QueryW2KDomainControllers
  3944. HRESULT QueryW2KDomainControllers(CString domainDNS, IEnumVARIANT*& pEnum)
  3945. {
  3946. CString sQuery;
  3947. WCHAR sCont[MAX_PATH];
  3948. SAFEARRAY * colNames = NULL;
  3949. SAFEARRAYBOUND bd = { 1, 0 };
  3950. HRESULT hr = S_OK;
  3951. try
  3952. {
  3953. INetObjEnumeratorPtr pQuery(__uuidof(NetObjEnumerator));
  3954. //query for all domain controllers in the domain
  3955. sQuery = L"(&(objectCategory=Computer)";
  3956. sQuery += L"(userAccountControl:";
  3957. sQuery += LDAP_MATCHING_RULE_BIT_AND_W;
  3958. sQuery += L":=8192))";
  3959. wsprintf(sCont, L"LDAP://%s", domainDNS);
  3960. //set columns to retrieve sAMAccountName
  3961. colNames = SafeArrayCreate(VT_BSTR, 1, &bd);
  3962. if (colNames == NULL)
  3963. _com_issue_error(E_OUTOFMEMORY);
  3964. long ndx[1];
  3965. ndx[0] = 0;
  3966. BSTR str = SysAllocString(L"sAMAccountName");
  3967. if (str == NULL)
  3968. _com_issue_error(E_OUTOFMEMORY);
  3969. hr = SafeArrayPutElement(colNames,ndx,str);
  3970. if (FAILED(hr))
  3971. {
  3972. SysFreeString(str);
  3973. _com_issue_error(hr);
  3974. }
  3975. //prepare and execute the query
  3976. pQuery->SetQuery(sCont, _bstr_t(domainDNS), _bstr_t(sQuery), ADS_SCOPE_SUBTREE, FALSE);
  3977. pQuery->SetColumns(colNames);
  3978. pQuery->Execute(&pEnum);
  3979. }
  3980. catch(_com_error& e)
  3981. {
  3982. hr = e.Error();
  3983. }
  3984. catch(...)
  3985. {
  3986. hr = E_FAIL;
  3987. }
  3988. if (colNames)
  3989. SafeArrayDestroy(colNames);
  3990. return hr;
  3991. }
  3992. //END QueryW2KDomainControllers
  3993. /*********************************************************************
  3994. * *
  3995. * Written by: Paul Thompson *
  3996. * Date: 1 SEPT 2000 *
  3997. * *
  3998. * This worker function is responsible for enumerating all domain*
  3999. * controllers in the given Windows NT4 domain. The variant array *
  4000. * passed back is filled with the sAMAccountName for each domain *
  4001. * controller. *
  4002. * *
  4003. *********************************************************************/
  4004. //BEGIN QueryNT4DomainControllers
  4005. HRESULT QueryNT4DomainControllers(CString domainDNS, IEnumVARIANT*& pEnum)
  4006. {
  4007. CString sCont;
  4008. SAFEARRAY * colNames = NULL;
  4009. SAFEARRAYBOUND bd = { 1, 0 };
  4010. HRESULT hr = S_OK;
  4011. try
  4012. {
  4013. INetObjEnumeratorPtr pQuery(__uuidof(NetObjEnumerator));
  4014. sCont = L"CN=DOMAIN CONTROLLERS";
  4015. //set columns to retrieve sAMAccountName
  4016. colNames = SafeArrayCreate(VT_BSTR, 1, &bd);
  4017. if (colNames == NULL)
  4018. _com_issue_error(E_OUTOFMEMORY);
  4019. long ndx[1];
  4020. ndx[0] = 0;
  4021. BSTR str = SysAllocString(L"sAMAccountName");
  4022. if (str == NULL)
  4023. _com_issue_error(E_OUTOFMEMORY);
  4024. hr = SafeArrayPutElement(colNames,ndx,str);
  4025. if (FAILED(hr))
  4026. {
  4027. SysFreeString(str);
  4028. _com_issue_error(hr);
  4029. }
  4030. //prepare and execute the query
  4031. pQuery->SetQuery(_bstr_t(sCont), _bstr_t(domainDNS), L"", ADS_SCOPE_SUBTREE, FALSE);
  4032. pQuery->SetColumns(colNames);
  4033. pQuery->Execute(&pEnum);
  4034. }
  4035. catch(_com_error& e)
  4036. {
  4037. hr = e.Error();
  4038. }
  4039. catch(...)
  4040. {
  4041. hr = E_FAIL;
  4042. }
  4043. if (colNames)
  4044. SafeArrayDestroy(colNames);
  4045. return hr;
  4046. }
  4047. //END QueryNT4DomainControllers
  4048. /*********************************************************************
  4049. * *
  4050. * Written by: Paul Thompson *
  4051. * Date: 1 SEPT 2000 *
  4052. * *
  4053. * This function is responsible for adding a given string to a *
  4054. * given combobox, if that string is not already in the combobox. *
  4055. * *
  4056. *********************************************************************/
  4057. //BEGIN addStringToComboBox
  4058. void addStringToComboBox(HWND hwndDlg, int id, CString s)
  4059. {
  4060. /* local variables */
  4061. CComboBox pwdCombo;
  4062. /* function body */
  4063. //if the DC starts with "\\", then remove them
  4064. if (!UStrICmp(s,L"\\\\",UStrLen(L"\\\\")))
  4065. s = s.Right(s.GetLength() - UStrLen(L"\\\\"));
  4066. pwdCombo.Attach(GetDlgItem(hwndDlg, id));
  4067. if (pwdCombo.FindString(-1, s) == CB_ERR)
  4068. pwdCombo.AddString(s);//add the string to the combobox
  4069. pwdCombo.Detach();
  4070. }
  4071. //END addStringToComboBox
  4072. /*********************************************************************
  4073. * *
  4074. * Written by: Paul Thompson *
  4075. * Date: 1 SEPT 2000 *
  4076. * *
  4077. * This function is responsible for selecting a string in a given*
  4078. * combobox. If we previously had a DC selected for this domain in *
  4079. * the varset, we select it. If not, then we set it to the DC found *
  4080. * in the Domain Selection dialog. *
  4081. * *
  4082. *********************************************************************/
  4083. //BEGIN initDCcombobox
  4084. void initDCcombobox(HWND hwndDlg, int id, int varsetKey)
  4085. {
  4086. /* local variables */
  4087. CComboBox pwdCombo;
  4088. CString prevDC;
  4089. CString sTemp;
  4090. _bstr_t text;
  4091. /* function body */
  4092. //strip the "\\" off the sourceDC default in case we need it
  4093. if (!UStrICmp(sourceDC,L"\\\\",UStrLen(L"\\\\")))
  4094. sTemp = sourceDC.Right(sourceDC.GetLength() - UStrLen(L"\\\\"));
  4095. pwdCombo.Attach(GetDlgItem(hwndDlg, id));
  4096. //get a previous DC
  4097. text = pVarSet->get(GET_BSTR(varsetKey));
  4098. prevDC = (WCHAR *)text;
  4099. prevDC.TrimLeft();prevDC.TrimRight();
  4100. //if not previous DC, use the one found during the Domain Selection
  4101. if (prevDC.IsEmpty())
  4102. prevDC = sTemp;
  4103. //select string in combobox
  4104. if (pwdCombo.SelectString(-1, prevDC) == CB_ERR)
  4105. pwdCombo.SelectString(-1, sTemp);
  4106. pwdCombo.Detach();
  4107. }
  4108. //END initDCcombobox
  4109. /*********************************************************************
  4110. * *
  4111. * Written by: Paul Thompson *
  4112. * Date: 3 OCT 2000 *
  4113. * *
  4114. * This function is responsible for initializing the Security *
  4115. * Translation Input dialog's radio buttons based on any previous *
  4116. * settings. *
  4117. * *
  4118. *********************************************************************/
  4119. //BEGIN initsecinputbox
  4120. void initsecinputbox(HWND hwndDlg,int id1,int id2,int varsetKey)
  4121. {
  4122. _bstr_t text;
  4123. text = pVarSet->get(GET_BSTR(varsetKey));
  4124. if (!UStrICmp(text,(WCHAR const *) yes))
  4125. CheckRadioButton(hwndDlg,id1,id2,id1);
  4126. else
  4127. CheckRadioButton(hwndDlg,id1,id2,id2);
  4128. }
  4129. //END initsecinputbox
  4130. /*********************************************************************
  4131. * *
  4132. * Written by: Paul Thompson *
  4133. * Date: 3 OCT 2000 *
  4134. * *
  4135. * This function is responsible for displaying and handling the *
  4136. * map file browse dialog. *
  4137. * *
  4138. *********************************************************************/
  4139. //BEGIN OnMapFileBrowse
  4140. void OnMapFileBrowse(HWND hwndDlg,int id)
  4141. {
  4142. CWnd yo ;
  4143. yo.Attach(hwndDlg);
  4144. CFileDialog f(TRUE,
  4145. NULL,
  4146. NULL,
  4147. OFN_LONGNAMES | OFN_NOREADONLYRETURN,
  4148. (L"Text Files (*.csv;*.txt)|*.csv;*.txt|All Files (*.*)|*.*||"),
  4149. &yo);
  4150. if ( f.DoModal() == IDOK )
  4151. {
  4152. SetDlgItemText(hwndDlg,id,f.GetPathName());
  4153. }
  4154. yo.Detach();
  4155. }
  4156. //END OnMapFileBrowse
  4157. /*********************************************************************
  4158. * *
  4159. * Written by: Paul Thompson *
  4160. * Date: 3 OCT 2000 *
  4161. * *
  4162. * This function is responsible for checking to see if the file *
  4163. * specified in the edit box on the given dialog is a valid file. We*
  4164. * will set the full path of the file if a relative path was given. *
  4165. * *
  4166. *********************************************************************/
  4167. //BEGIN checkMapFile
  4168. bool checkMapFile(HWND hwndDlg)
  4169. {
  4170. CString h;GetDlgItemText(hwndDlg,IDC_MAPPING_FILE,h.GetBuffer(1000),1000);h.ReleaseBuffer();
  4171. CFileFind finder;
  4172. bool exists = (finder.FindFile((LPCTSTR) h )!=0);
  4173. if (exists)
  4174. {
  4175. BOOL bmore = finder.FindNextFile();//must call to fill in path info
  4176. CString fullpath = finder.GetFilePath();
  4177. if (fullpath.GetLength() != 0)
  4178. SetDlgItemText(hwndDlg,IDC_MAPPING_FILE,fullpath);
  4179. }
  4180. return exists;
  4181. }
  4182. //END checkMapFile
  4183. /*********************************************************************
  4184. * *
  4185. * Written by: Paul Thompson *
  4186. * Date: 25 OCT 2000 *
  4187. * *
  4188. * This function is responsible for initializing the object *
  4189. * property exclusion dialog. *
  4190. * This function adds all common schema properties for the object*
  4191. * type to the listboxes. Previously excluded properties will be *
  4192. * placed in the excluded listbox and all other will be placed in the*
  4193. * included listbox. Since more than one object is allowable, we *
  4194. * have a combobox that holds the objects whose properties can be *
  4195. * enumerated, and the listboxes show the properties for the object *
  4196. * selected in the combobox. *
  4197. * *
  4198. *********************************************************************/
  4199. namespace
  4200. {
  4201. WCHAR DELIMITER[] = L",";//used to seperate names in the string
  4202. }
  4203. //BEGIN initpropdlg
  4204. void initpropdlg(HWND hwndDlg)
  4205. {
  4206. /* local variables */
  4207. CListCtrl propIncList;
  4208. CListCtrl propExcList;
  4209. CComboBox typeCombo;
  4210. CString sPropName;
  4211. CString sPropOID;
  4212. bool bExAll1 = false;
  4213. bool bExAll2 = false;
  4214. bool bExAll3 = false;
  4215. CString sExList1;
  4216. CString sExList2 = L"";
  4217. CString sExList3 = L"";
  4218. CString Type1, Type2 = L"", Type3 = L"";
  4219. CStringList ExList1, ExList2, ExList3;
  4220. _bstr_t text;
  4221. HRESULT hr;
  4222. long srcVer = 5;
  4223. POSITION currentPos;
  4224. sType1.Empty();
  4225. sType2.Empty();
  4226. sType3.Empty();
  4227. /* function body */
  4228. CWaitCursor wait;
  4229. /* get list(s) of previously excluded properties and set type
  4230. related variables */
  4231. if (migration==w_computer)
  4232. {
  4233. //get the previous computer exclusion list
  4234. text = pVarSet->get(GET_BSTR(DCTVS_AccountOptions_ExcludedComputerProps));
  4235. sExList1 = (WCHAR *)text;
  4236. Type1 = L"computer"; //set the type to computer
  4237. //set the parent text
  4238. sType1 = GET_STRING(IDS_COMPUTERPROPS);
  4239. }
  4240. else if (migration==w_account)
  4241. {
  4242. // initialize user and inetOrgPerson
  4243. Type1 = L"user";
  4244. sType1 = GET_STRING(IDS_USERPROPS);
  4245. sExList1 = (LPCTSTR)_bstr_t(pVarSet->get(GET_BSTR(DCTVS_AccountOptions_ExcludedUserProps)));
  4246. Type2 = L"InetOrgPerson";
  4247. sType2 = GET_STRING(IDS_INETORGPERSONPROPS);
  4248. sExList2 = (LPCTSTR)_bstr_t(pVarSet->get(GET_BSTR(DCTVS_AccountOptions_ExcludedInetOrgPersonProps)));
  4249. // if migrating groups
  4250. text = pVarSet->get(GET_BSTR(DCTVS_AccountOptions_CopyMemberOf));
  4251. if (!UStrICmp((WCHAR*)text,(WCHAR const *) yes))
  4252. {
  4253. // initialize group
  4254. Type3 = L"group";
  4255. sType3 = GET_STRING(IDS_GROUPPROPS);
  4256. sExList3 = (LPCTSTR)_bstr_t(pVarSet->get(GET_BSTR(DCTVS_AccountOptions_ExcludedGroupProps)));
  4257. }
  4258. }
  4259. else if (migration==w_group || migration==w_groupmapping)
  4260. {
  4261. //get the previous group exclusion list
  4262. text = pVarSet->get(GET_BSTR(DCTVS_AccountOptions_ExcludedGroupProps));
  4263. sExList1 = (WCHAR *)text;
  4264. //if also migrating users, set 2nd parent information
  4265. text = pVarSet->get(GET_BSTR(DCTVS_AccountOptions_CopyContainerContents));
  4266. if (!UStrICmp((WCHAR*)text,(WCHAR const *) yes))
  4267. {
  4268. //get the previous user exclusion list
  4269. text = pVarSet->get(GET_BSTR(DCTVS_AccountOptions_ExcludedUserProps));
  4270. sExList2 = (WCHAR *)text;
  4271. Type2 = L"user"; //set 2nd type to user
  4272. //set 2nd parent text
  4273. sType2 = GET_STRING(IDS_USERPROPS);
  4274. //get the previous inetOrgPerson exclusion list
  4275. sExList3 = (LPCTSTR)_bstr_t(pVarSet->get(GET_BSTR(DCTVS_AccountOptions_ExcludedInetOrgPersonProps)));
  4276. Type3 = L"InetOrgPerson";
  4277. sType3 = GET_STRING(IDS_INETORGPERSONPROPS);
  4278. }
  4279. Type1 = L"group"; //set type to group
  4280. //set the parent text
  4281. sType1 = GET_STRING(IDS_GROUPPROPS);
  4282. }
  4283. /* place comma seperated exclusion strings parts into lists */
  4284. //place each substring in the 1st exclusion string into a list
  4285. if (!sExList1.IsEmpty())
  4286. {
  4287. if (IsStringInDelimitedString(sExList1, L"*", DELIMITER[0]))
  4288. {
  4289. bExAll1 = true;
  4290. }
  4291. else
  4292. {
  4293. CString sTemp = sExList1;
  4294. WCHAR* pStr = sTemp.GetBuffer(0);
  4295. WCHAR* pTemp = wcstok(pStr, DELIMITER);
  4296. while (pTemp != NULL)
  4297. {
  4298. ExList1.AddTail(pTemp);
  4299. //get the next item
  4300. pTemp = wcstok(NULL, DELIMITER);
  4301. }
  4302. sTemp.ReleaseBuffer();
  4303. }
  4304. }
  4305. //place each substring in the 2nd exclusion string into a list
  4306. if (!sExList2.IsEmpty())
  4307. {
  4308. if (IsStringInDelimitedString(sExList2, L"*", DELIMITER[0]))
  4309. {
  4310. bExAll2 = true;
  4311. }
  4312. else
  4313. {
  4314. CString sTemp = sExList2;
  4315. WCHAR* pStr = sTemp.GetBuffer(0);
  4316. WCHAR* pTemp = wcstok(pStr, DELIMITER);
  4317. while (pTemp != NULL)
  4318. {
  4319. ExList2.AddTail(pTemp);
  4320. //get the next item
  4321. pTemp = wcstok(NULL, DELIMITER);
  4322. }
  4323. sTemp.ReleaseBuffer();
  4324. }
  4325. }
  4326. //place each substring in the 3rd exclusion string into a list
  4327. if (!sExList3.IsEmpty())
  4328. {
  4329. if (IsStringInDelimitedString(sExList3, L"*", DELIMITER[0]))
  4330. {
  4331. bExAll3 = true;
  4332. }
  4333. else
  4334. {
  4335. CString sTemp = sExList3;
  4336. WCHAR* pStr = sTemp.GetBuffer(0);
  4337. WCHAR* pTemp = wcstok(pStr, DELIMITER);
  4338. while (pTemp != NULL)
  4339. {
  4340. ExList3.AddTail(pTemp);
  4341. //get the next item
  4342. pTemp = wcstok(NULL, DELIMITER);
  4343. }
  4344. sTemp.ReleaseBuffer();
  4345. }
  4346. }
  4347. /* place the type(s) in the combobox */
  4348. typeCombo.Attach(GetDlgItem(hwndDlg, IDC_OBJECTCMBO));
  4349. typeCombo.ResetContent();
  4350. typeCombo.InsertString(-1, sType1);
  4351. if (!sType2.IsEmpty())
  4352. typeCombo.InsertString(-1, sType2);
  4353. if (!sType3.IsEmpty())
  4354. typeCombo.InsertString(-1, sType3);
  4355. //select type 1 in the combobox
  4356. typeCombo.SelectString(-1, sType1);
  4357. typeCombo.Detach();
  4358. //get a list of all properties names and their OIDs for this object type
  4359. PropIncMap1.clear();
  4360. PropExcMap1.clear();
  4361. hr = BuildPropertyMap(Type1, srcVer, bExAll1 ? &PropExcMap1 : &PropIncMap1);
  4362. /* remove excluded properties from the inclusion map and place that property in
  4363. the exclusion map */
  4364. if (!ExList1.IsEmpty())
  4365. {
  4366. //get the position and string of the first property in the previous
  4367. //exclusion list
  4368. currentPos = ExList1.GetHeadPosition();
  4369. //while there is another entry to retrieve from the list, then
  4370. //get a property name from the list,remove it from the inclusion map, and
  4371. //place it in the exclusion list
  4372. while (currentPos != NULL)
  4373. {
  4374. //get the next string in the list, starts with the first
  4375. sPropName = ExList1.GetNext(currentPos);
  4376. //if we find the property in the inclusion map, remove it and
  4377. //add to the exclusion map
  4378. CPropertyNameToOIDMap::iterator it = PropIncMap1.find(sPropName);
  4379. if (it != PropIncMap1.end())
  4380. {
  4381. PropExcMap1.insert(CPropertyNameToOIDMap::value_type(it->first, it->second));
  4382. PropIncMap1.erase(it); //remove it from the inc map
  4383. }//end if found in map
  4384. }
  4385. }
  4386. //
  4387. // initialize list controls
  4388. //
  4389. propIncList.Attach(GetDlgItem(hwndDlg, IDC_INCLUDELIST));
  4390. propExcList.Attach(GetDlgItem(hwndDlg, IDC_EXCLUDELIST));
  4391. // insert a column with an empty string as the header text
  4392. CString emptyColumn;
  4393. propIncList.InsertColumn(1, emptyColumn, LVCFMT_LEFT, 157, 1);
  4394. propExcList.InsertColumn(1, emptyColumn, LVCFMT_LEFT, 157, 1);
  4395. propIncList.Detach();
  4396. propExcList.Detach();
  4397. /* add the type1 properties to the appropriate listboxes */
  4398. listproperties(hwndDlg);
  4399. //init "Exclude Prop" checkbox
  4400. text = pVarSet->get(GET_BSTR(DCTVS_AccountOptions_ExcludeProps));
  4401. //if not checked, disable all other controls
  4402. if (UStrICmp(text,(WCHAR const * ) yes))
  4403. {
  4404. CheckDlgButton( hwndDlg,IDC_EXCLUDEPROPS, BST_UNCHECKED);
  4405. disable(hwndDlg,IDC_OBJECTCMBO);
  4406. disable(hwndDlg,IDC_INCLUDELIST);
  4407. disable(hwndDlg,IDC_EXCLUDELIST);
  4408. disable(hwndDlg,IDC_EXCLUDEBTN);
  4409. disable(hwndDlg,IDC_INCLUDEBTN);
  4410. }
  4411. else //eles enable them
  4412. {
  4413. CheckDlgButton( hwndDlg,IDC_EXCLUDEPROPS, BST_CHECKED);
  4414. enable(hwndDlg,IDC_OBJECTCMBO);
  4415. enable(hwndDlg,IDC_INCLUDELIST);
  4416. enable(hwndDlg,IDC_EXCLUDELIST);
  4417. enable(hwndDlg,IDC_EXCLUDEBTN);
  4418. enable(hwndDlg,IDC_INCLUDEBTN);
  4419. }
  4420. //if no 2nd type to be displayed, leave
  4421. if (Type2.IsEmpty())
  4422. return;
  4423. /* enumerate and add all mapped properties, for the 2nd type, to the maps */
  4424. //get a list of all properties names and their OIDs for this object type
  4425. PropIncMap2.clear(); //clear the property map
  4426. PropExcMap2.clear(); //clear the property map
  4427. hr = BuildPropertyMap(Type2, srcVer, bExAll2 ? &PropExcMap2 : &PropIncMap2);
  4428. /* remove excluded properties from the inclusion map and place that property in
  4429. the exclusion map */
  4430. if (!ExList2.IsEmpty())
  4431. {
  4432. //get the position and string of the first name in the previous
  4433. //exclusion list
  4434. currentPos = ExList2.GetHeadPosition();
  4435. //while there is another entry to retrieve from the list, then
  4436. //get a name from the list,remove it from the inclusion map, and
  4437. //place it in the exclusion list
  4438. while (currentPos != NULL)
  4439. {
  4440. //get the next string in the list, starts with the first
  4441. sPropName = ExList2.GetNext(currentPos);
  4442. //if we find the property in the inclusion map, remove it and
  4443. //add to the exclusion map
  4444. CPropertyNameToOIDMap::iterator it = PropIncMap2.find(sPropName);
  4445. if (it != PropIncMap2.end())
  4446. {
  4447. PropExcMap2.insert(CPropertyNameToOIDMap::value_type(it->first, it->second));
  4448. PropIncMap2.erase(it); //remove it from the inc map
  4449. }//end if found in map
  4450. }
  4451. }
  4452. //if no 3rd type to be displayed, leave
  4453. if (Type3.IsEmpty())
  4454. return;
  4455. /* enumerate and add all mapped properties, for the 3rd type, to the maps */
  4456. //get a list of all properties names and their OIDs for this object type
  4457. PropIncMap3.clear(); //clear the property map
  4458. PropExcMap3.clear(); //clear the property map
  4459. hr = BuildPropertyMap(Type3, srcVer, bExAll3 ? &PropExcMap3 : &PropIncMap3);
  4460. /* remove excluded properties from the inclusion map and place that property in
  4461. the exclusion map */
  4462. if (!ExList3.IsEmpty())
  4463. {
  4464. //get the position and string of the first name in the previous
  4465. //exclusion list
  4466. currentPos = ExList3.GetHeadPosition();
  4467. //while there is another entry to retrieve from the list, then
  4468. //get a name from the list,remove it from the inclusion map, and
  4469. //place it in the exclusion list
  4470. while (currentPos != NULL)
  4471. {
  4472. //get the next string in the list, starts with the first
  4473. sPropName = ExList3.GetNext(currentPos);
  4474. //if we find the property in the inclusion map, remove it and
  4475. //add to the exclusion map
  4476. CPropertyNameToOIDMap::iterator it = PropIncMap3.find(sPropName);
  4477. if (it != PropIncMap3.end())
  4478. {
  4479. PropExcMap3.insert(CPropertyNameToOIDMap::value_type(it->first, it->second));
  4480. PropIncMap3.erase(it); //remove it from the inc map
  4481. }//end if found in map
  4482. }
  4483. }
  4484. }
  4485. //END initpropdlg
  4486. /*********************************************************************
  4487. * *
  4488. * Written by: Paul Thompson *
  4489. * Date: 26 OCT 2000 *
  4490. * *
  4491. * This function is used by "initpropdlg" to retrieve a given *
  4492. * object's properties, and their associated OIDs, from the schema. *
  4493. * The property names and OIDs are placed in a given *
  4494. * string-to-string map using the OID as the key. Property *
  4495. * enumeration is accomplished using the ObjPropBuilder class. *
  4496. * *
  4497. *********************************************************************/
  4498. //BEGIN BuildPropertyMap
  4499. HRESULT BuildPropertyMap(CString Type, long lSrcVer, CPropertyNameToOIDMap * pPropMap)
  4500. {
  4501. /* local variables */
  4502. IObjPropBuilderPtr pObjProp(__uuidof(ObjPropBuilder));
  4503. IVarSetPtr pVarTemp(__uuidof(VarSet));
  4504. IUnknown * pUnk;
  4505. HRESULT hr;
  4506. long lRet=0;
  4507. SAFEARRAY * keys = NULL;
  4508. SAFEARRAY * vals = NULL;
  4509. VARIANT var;
  4510. CString sPropName;
  4511. CString sPropOID;
  4512. /* function body */
  4513. VariantInit(&var);
  4514. //get an IUnknown pointer to the Varset for passing it around.
  4515. hr = pVarTemp->QueryInterface(IID_IUnknown, (void**)&pUnk);
  4516. if (FAILED(hr))
  4517. return hr;
  4518. //fill the varset with a list of properties in common between the source
  4519. //and target domain for the first type being migrated
  4520. hr = pObjProp->raw_MapProperties(_bstr_t(Type), _bstr_t(GetSourceDomainName()),
  4521. lSrcVer, _bstr_t(Type), _bstr_t(GetTargetDomainName()),
  4522. 5, 1, &pUnk);
  4523. if (SUCCEEDED(hr) || (hr == DCT_MSG_PROPERTIES_NOT_MAPPED))
  4524. {
  4525. hr = pVarTemp->getItems(L"", L"", 1, 10000, &keys, &vals, &lRet);
  4526. if (SUCCEEDED(hr))
  4527. {
  4528. for ( long x = 0; x < lRet; x++ )
  4529. {
  4530. ::SafeArrayGetElement(keys, &x, &var);
  4531. if (V_VT(&var) != VT_EMPTY)
  4532. {
  4533. sPropOID = (WCHAR*)(var.bstrVal);
  4534. VariantClear(&var);
  4535. ::SafeArrayGetElement(vals, &x, &var);
  4536. if (V_VT(&var) != VT_EMPTY)
  4537. {
  4538. sPropName = (WCHAR*)(var.bstrVal);
  4539. VariantClear(&var);
  4540. //place the OID and Name in the map with the name as the key
  4541. pPropMap->insert(CPropertyNameToOIDMap::value_type(sPropName, sPropOID));
  4542. }
  4543. }
  4544. }
  4545. }
  4546. }
  4547. // retrieve system exclude attributes and remove them from the include map
  4548. // this prevents the user from manipulating them through this dialog
  4549. CString strSysExclude = (LPCTSTR)_bstr_t(pVarSet->get(GET_BSTR(DCTVS_AccountOptions_ExcludedSystemProps)));
  4550. if (!strSysExclude.IsEmpty())
  4551. {
  4552. WCHAR* psz = strSysExclude.GetBuffer(0);
  4553. for (psz = wcstok(psz, DELIMITER); psz; psz = wcstok(NULL, DELIMITER))
  4554. {
  4555. pPropMap->erase(CString(psz));
  4556. }
  4557. strSysExclude.ReleaseBuffer();
  4558. }
  4559. return hr;
  4560. }
  4561. //END BuildPropertyMap
  4562. /*********************************************************************
  4563. * *
  4564. * Written by: Paul Thompson *
  4565. * Date: 27 OCT 2000 *
  4566. * *
  4567. * This function is responsible for moving properties to and from*
  4568. * the inclusion and exclusion listboxes. If the boolean parameter *
  4569. * is true, then we are moving properties from the inclusion listbox *
  4570. * to the exclusion listbox. We will also move the properties from *
  4571. * the global inclusion and exclusion maps. *
  4572. * *
  4573. *********************************************************************/
  4574. //BEGIN moveproperties
  4575. void moveproperties(HWND hwndDlg, bool bExclude)
  4576. {
  4577. /* local variables */
  4578. CListCtrl propToList;
  4579. CListCtrl propFromList;
  4580. CComboBox typeCombo;
  4581. CPropertyNameToOIDMap* pPropFromMap;
  4582. CPropertyNameToOIDMap* pPropToMap;
  4583. CStringList sMoveList;
  4584. CString sPropName;
  4585. CString sTempName;
  4586. CString sTempOID;
  4587. POSITION currentPos;
  4588. int ndx;
  4589. int nFound;
  4590. /* function body */
  4591. /* find out whether type1 or type2 is having properties moved and
  4592. setup map pointer accordingly */
  4593. typeCombo.Attach(GetDlgItem(hwndDlg, IDC_OBJECTCMBO));
  4594. //if type1, use the type1 maps
  4595. if (typeCombo.FindString(-1, sType1) == typeCombo.GetCurSel())
  4596. {
  4597. if (bExclude)
  4598. {
  4599. pPropToMap = &PropExcMap1;
  4600. pPropFromMap = &PropIncMap1;
  4601. }
  4602. else
  4603. {
  4604. pPropToMap = &PropIncMap1;
  4605. pPropFromMap = &PropExcMap1;
  4606. }
  4607. }
  4608. else if (typeCombo.FindString(-1, sType2) == typeCombo.GetCurSel()) //else use type2 maps
  4609. {
  4610. if (bExclude)
  4611. {
  4612. pPropToMap = &PropExcMap2;
  4613. pPropFromMap = &PropIncMap2;
  4614. }
  4615. else
  4616. {
  4617. pPropToMap = &PropIncMap2;
  4618. pPropFromMap = &PropExcMap2;
  4619. }
  4620. }
  4621. else //else use type3 maps
  4622. {
  4623. if (bExclude)
  4624. {
  4625. pPropToMap = &PropExcMap3;
  4626. pPropFromMap = &PropIncMap3;
  4627. }
  4628. else
  4629. {
  4630. pPropToMap = &PropIncMap3;
  4631. pPropFromMap = &PropExcMap3;
  4632. }
  4633. }
  4634. typeCombo.Detach();
  4635. /* attach to the proper listboxes */
  4636. if (bExclude)
  4637. {
  4638. propToList.Attach(GetDlgItem(hwndDlg, IDC_EXCLUDELIST));
  4639. propFromList.Attach(GetDlgItem(hwndDlg, IDC_INCLUDELIST));
  4640. }
  4641. else
  4642. {
  4643. propToList.Attach(GetDlgItem(hwndDlg, IDC_INCLUDELIST));
  4644. propFromList.Attach(GetDlgItem(hwndDlg, IDC_EXCLUDELIST));
  4645. }
  4646. /* get the items selected for moving and place the names in a list */
  4647. sMoveList.RemoveAll();
  4648. currentPos = propFromList.GetFirstSelectedItemPosition();
  4649. while (currentPos != NULL)
  4650. {
  4651. ndx = propFromList.GetNextSelectedItem(currentPos);
  4652. sMoveList.AddTail(propFromList.GetItemText(ndx, 0));
  4653. }
  4654. // move the properties in the listboxes and the maps
  4655. if (!sMoveList.IsEmpty())
  4656. {
  4657. currentPos = sMoveList.GetHeadPosition();
  4658. //while there is another entry to retrieve from the move list, then
  4659. //get a name from the 'from' list, remove it from the 'from' map and
  4660. //list control, and place it in the 'to' map and list control
  4661. while (currentPos != NULL)
  4662. {
  4663. //get the next string in the list, starts with the first
  4664. sTempName = sMoveList.GetNext(currentPos);
  4665. //remove the property from the 'from' listbox
  4666. LVFINDINFO info;
  4667. info.flags = LVFI_STRING;
  4668. info.psz = sTempName;
  4669. // Delete all of the items that begin with the string sTempName.
  4670. if ((ndx = propFromList.FindItem(&info)) != -1)
  4671. {
  4672. propFromList.DeleteItem(ndx);
  4673. propToList.InsertItem(propToList.GetItemCount(), sTempName);
  4674. }
  4675. /* find the property in the 'from' map, remove it, and add it to the
  4676. 'to' map */
  4677. //if we find the property in the inclusion map, remove it and
  4678. //add to the exclusion map
  4679. CPropertyNameToOIDMap::iterator it = pPropFromMap->find(sTempName);
  4680. if (it != pPropFromMap->end())
  4681. {
  4682. pPropToMap->insert(CPropertyNameToOIDMap::value_type(it->first, it->second));//add it to the to map
  4683. pPropFromMap->erase(it); //remove it from the from map
  4684. }//end if found in map
  4685. }//end while more props to move
  4686. }//end if props to move
  4687. propToList.Detach();
  4688. propFromList.Detach();
  4689. }
  4690. //END moveproperties
  4691. /*********************************************************************
  4692. * *
  4693. * Written by: Paul Thompson *
  4694. * Date: 27 OCT 2000 *
  4695. * *
  4696. * This function is responsible for listing properties in the *
  4697. * inclusion and exclusion listboxes based on the current object type*
  4698. * selected in the combobox. *
  4699. * We will retrieve the properties from the global inclusion and *
  4700. * exclusion maps. *
  4701. * *
  4702. *********************************************************************/
  4703. //BEGIN listproperties
  4704. void listproperties(HWND hwndDlg)
  4705. {
  4706. /* local variables */
  4707. CListCtrl propIncList;
  4708. CListCtrl propExcList;
  4709. CComboBox typeCombo;
  4710. CPropertyNameToOIDMap* pPropIncMap;
  4711. CPropertyNameToOIDMap* pPropExcMap;
  4712. CPropertyNameToOIDMap::iterator it;
  4713. /* function body */
  4714. /* find out whether type1 or type2 is having properties listed and
  4715. setup map pointer accordingly */
  4716. typeCombo.Attach(GetDlgItem(hwndDlg, IDC_OBJECTCMBO));
  4717. //if type1, use the type1 maps
  4718. if (typeCombo.FindString(-1, sType1) == typeCombo.GetCurSel())
  4719. {
  4720. pPropIncMap = &PropIncMap1;
  4721. pPropExcMap = &PropExcMap1;
  4722. }
  4723. else if (typeCombo.FindString(-1, sType2) == typeCombo.GetCurSel())
  4724. {
  4725. pPropIncMap = &PropIncMap2;
  4726. pPropExcMap = &PropExcMap2;
  4727. }
  4728. else //else use type3 maps
  4729. {
  4730. pPropIncMap = &PropIncMap3;
  4731. pPropExcMap = &PropExcMap3;
  4732. }
  4733. typeCombo.Detach();
  4734. /* attach to the proper list controls */
  4735. propIncList.Attach(GetDlgItem(hwndDlg, IDC_INCLUDELIST));
  4736. propExcList.Attach(GetDlgItem(hwndDlg, IDC_EXCLUDELIST));
  4737. propIncList.DeleteAllItems();
  4738. propExcList.DeleteAllItems();
  4739. /* populate the include list control from the include map */
  4740. if (!pPropIncMap->empty())
  4741. {
  4742. //for each property in the include map, place it in
  4743. //the include list control
  4744. for (it = pPropIncMap->begin(); it != pPropIncMap->end(); it++)
  4745. {
  4746. propIncList.InsertItem(propIncList.GetItemCount(), it->first);
  4747. }//end while more to list
  4748. }//end if props to list
  4749. /* populate the exclude list control from the exclude map */
  4750. if (!pPropExcMap->empty())
  4751. {
  4752. //for each property in the include map, place it in
  4753. //the include list control
  4754. for (it = pPropExcMap->begin(); it != pPropExcMap->end(); it++)
  4755. {
  4756. propExcList.InsertItem(propExcList.GetItemCount(), it->first);
  4757. }//end while more to list
  4758. }//end if props to list
  4759. propIncList.Detach();
  4760. propExcList.Detach();
  4761. }
  4762. //END listproperties
  4763. /*********************************************************************
  4764. * *
  4765. * Written by: Paul Thompson *
  4766. * Date: 31 OCT 2000 *
  4767. * *
  4768. * This function is responsible for storing excluded properties *
  4769. * in the proper varset field. The excluded properties are retrieved*
  4770. * from the global exclusion maps. Properties are store in the *
  4771. * varset string as a comma-seperated string of the properties' IOD. *
  4772. * *
  4773. *********************************************************************/
  4774. //BEGIN saveproperties
  4775. void saveproperties(HWND hwndDlg)
  4776. {
  4777. /* local variables */
  4778. CComboBox typeCombo;
  4779. CString sPropName;
  4780. CString sPropOID;
  4781. CString sType3 = L"";
  4782. CString sType2 = L"";
  4783. CString sType;
  4784. CString sExList;
  4785. CPropertyNameToOIDMap::iterator it;
  4786. int ndx;
  4787. _bstr_t text;
  4788. _bstr_t key1;
  4789. _bstr_t key2;
  4790. _bstr_t key3;
  4791. /* function body */
  4792. /* see if there is a second type listed in the combobox */
  4793. typeCombo.Attach(GetDlgItem(hwndDlg, IDC_OBJECTCMBO));
  4794. for (ndx = 0; ndx < typeCombo.GetCount(); ndx++)
  4795. {
  4796. typeCombo.GetLBText(ndx, sType); //get the next type listed
  4797. switch (ndx)
  4798. {
  4799. case 0:
  4800. //sType1 = sType; global variable
  4801. break;
  4802. case 1:
  4803. sType2 = sType;
  4804. break;
  4805. case 2:
  4806. sType3 = sType;
  4807. break;
  4808. }
  4809. }
  4810. typeCombo.Detach();
  4811. /* find the proper varset key for each type */
  4812. if (sType1 == GET_STRING(IDS_USERPROPS))
  4813. key1 = GET_BSTR(DCTVS_AccountOptions_ExcludedUserProps);
  4814. else if (sType1 == GET_STRING(IDS_INETORGPERSONPROPS))
  4815. key1 = GET_BSTR(DCTVS_AccountOptions_ExcludedInetOrgPersonProps);
  4816. else if (sType1 == GET_STRING(IDS_GROUPPROPS))
  4817. key1 = GET_BSTR(DCTVS_AccountOptions_ExcludedGroupProps);
  4818. else if (sType1 == GET_STRING(IDS_COMPUTERPROPS))
  4819. key1 = GET_BSTR(DCTVS_AccountOptions_ExcludedComputerProps);
  4820. if (!sType2.IsEmpty())
  4821. {
  4822. if (sType2 == GET_STRING(IDS_USERPROPS))
  4823. key2 = GET_BSTR(DCTVS_AccountOptions_ExcludedUserProps);
  4824. else if (sType2 == GET_STRING(IDS_INETORGPERSONPROPS))
  4825. key2 = GET_BSTR(DCTVS_AccountOptions_ExcludedInetOrgPersonProps);
  4826. else if (sType2 == GET_STRING(IDS_GROUPPROPS))
  4827. key2 = GET_BSTR(DCTVS_AccountOptions_ExcludedGroupProps);
  4828. else if (sType2 == GET_STRING(IDS_COMPUTERPROPS))
  4829. key2 = GET_BSTR(DCTVS_AccountOptions_ExcludedComputerProps);
  4830. }
  4831. if (!sType3.IsEmpty())
  4832. {
  4833. if (sType3 == GET_STRING(IDS_USERPROPS))
  4834. key3 = GET_BSTR(DCTVS_AccountOptions_ExcludedUserProps);
  4835. else if (sType3 == GET_STRING(IDS_INETORGPERSONPROPS))
  4836. key3 = GET_BSTR(DCTVS_AccountOptions_ExcludedInetOrgPersonProps);
  4837. else if (sType3 == GET_STRING(IDS_GROUPPROPS))
  4838. key3 = GET_BSTR(DCTVS_AccountOptions_ExcludedGroupProps);
  4839. else if (sType3 == GET_STRING(IDS_COMPUTERPROPS))
  4840. key3 = GET_BSTR(DCTVS_AccountOptions_ExcludedComputerProps);
  4841. }
  4842. /* populate the varset key for Type1 from the exclusion map */
  4843. sExList = L"";
  4844. if (!PropExcMap1.empty())
  4845. {
  4846. //for each property in the exclusion map, place it's name in
  4847. //the comma-seperated varset string
  4848. for (it = PropExcMap1.begin(); it != PropExcMap1.end(); it++)
  4849. {
  4850. //get the next name and associated OID from the map, starts with the first
  4851. sExList += it->first;
  4852. sExList += L",";
  4853. }//end while more to add
  4854. //remove the trailing ','
  4855. sExList.SetAt((sExList.GetLength() - 1), L'\0');
  4856. }//end if props to record
  4857. /* store the Type1 excluded properties in the varset */
  4858. pVarSet->put(key1, _bstr_t(sExList));
  4859. /* if a Type2, populate the varset key for Type2 from the exclusion map */
  4860. if (!sType2.IsEmpty())
  4861. {
  4862. sExList = L"";
  4863. if (!PropExcMap2.empty())
  4864. {
  4865. //for each property in the exclusion map, place it's name in
  4866. //the comma-seperated varset string
  4867. for (it = PropExcMap2.begin(); it != PropExcMap2.end(); it++)
  4868. {
  4869. //get the next name and associated OID from the map, starts with the first
  4870. sExList += it->first;
  4871. sExList += L",";
  4872. }//end while more to add
  4873. //remove the trailing ','
  4874. sExList.SetAt((sExList.GetLength() - 1), L'\0');
  4875. }//end if props to record
  4876. }//end if props to record
  4877. /* if Type2, store the Type2 excluded properties in the varset */
  4878. if (!sType2.IsEmpty())
  4879. pVarSet->put(key2, _bstr_t(sExList));
  4880. /* if a Type3, populate the varset key for Type3 from the exclusion map */
  4881. if (!sType3.IsEmpty())
  4882. {
  4883. sExList = L"";
  4884. if (!PropExcMap3.empty())
  4885. {
  4886. //for each property in the exclusion map, place it's name in
  4887. //the comma-seperated varset string
  4888. for (it = PropExcMap3.begin(); it != PropExcMap3.end(); it++)
  4889. {
  4890. //get the next name and associated OID from the map, starts with the first
  4891. sExList += it->first;
  4892. sExList += L",";
  4893. }//end while more to add
  4894. //remove the trailing ','
  4895. sExList.SetAt((sExList.GetLength() - 1), L'\0');
  4896. }//end if props to record
  4897. }//end if props to record
  4898. /* if Type3, store the Type3 excluded properties in the varset */
  4899. if (!sType3.IsEmpty())
  4900. pVarSet->put(key3, _bstr_t(sExList));
  4901. }
  4902. //END saveproperties
  4903. /*********************************************************************
  4904. * *
  4905. * Written by: Paul Thompson *
  4906. * Date: 17 NOV 2000 *
  4907. * *
  4908. * This function is responsible for making an RPC call into the *
  4909. * given Password DC to see if it is ready to perform password *
  4910. * migrations. We return if it is ready or not. If the DC is not *
  4911. * ready, we also fill in the msg and title strings. *
  4912. * *
  4913. *********************************************************************/
  4914. //BEGIN IsPasswordDCReady
  4915. bool IsPasswordDCReady(CString server, CString& msg, CString& title, UINT *msgtype)
  4916. {
  4917. /* local variables */
  4918. IPasswordMigrationPtr pPwdMig(__uuidof(PasswordMigration));
  4919. HRESULT hr = S_OK;
  4920. DWORD rc = 0;
  4921. CString sTemp;
  4922. TErrorDct err;
  4923. _bstr_t sText;
  4924. WCHAR sMach[1000];
  4925. DWORD dwMachLen = 1000;
  4926. IErrorInfoPtr pErrorInfo = NULL;
  4927. BSTR bstrDescription;
  4928. /* function body */
  4929. //get a DC from this domain. We will set a VARSET key so that we use this DC for
  4930. //password migration (and other acctrepl operations)
  4931. if (targetServer.IsEmpty())
  4932. {
  4933. _bstr_t sTgtDCDns;
  4934. _bstr_t sTgtDCFlat;
  4935. rc = GetDcName5(GetTargetDomainName(), DS_DIRECTORY_SERVICE_REQUIRED, sTgtDCDns, sTgtDCFlat);
  4936. if (rc == NO_ERROR)
  4937. {
  4938. //store this DC to use later for the actual migration
  4939. targetServer = (LPCTSTR)sTgtDCFlat;
  4940. targetServerDns = (LPCTSTR)sTgtDCDns;
  4941. }
  4942. else
  4943. {
  4944. hr = HRESULT_FROM_WIN32(rc);
  4945. }
  4946. }
  4947. //
  4948. // Verify that the password server is in fact a domain controller for
  4949. // the source domain.
  4950. //
  4951. DSROLE_PRIMARY_DOMAIN_INFO_BASIC * pDomInfo = NULL;
  4952. DWORD dwerr = DsRoleGetPrimaryDomainInformation((LPCTSTR)server,
  4953. DsRolePrimaryDomainInfoBasic,
  4954. (PBYTE*)&pDomInfo);
  4955. if (dwerr != NO_ERROR)
  4956. {
  4957. sTemp.LoadString(IDS_MSG_PWDDC_CANT_GET_ROLE);
  4958. msg.Format((LPCTSTR)sTemp, (LPCTSTR)server);
  4959. title.LoadString(IDS_MSG_ERROR);
  4960. *msgtype = MB_ICONERROR | MB_OK;
  4961. return false;
  4962. }
  4963. else
  4964. {
  4965. if ((pDomInfo->MachineRole != DsRole_RolePrimaryDomainController) && (pDomInfo->MachineRole != DsRole_RoleBackupDomainController))
  4966. {
  4967. sTemp.LoadString(IDS_MSG_PWDDC_NOT_DC);
  4968. msg.Format(sTemp, (LPCTSTR)server);
  4969. title.LoadString(IDS_MSG_ERROR);
  4970. *msgtype = MB_ICONERROR | MB_OK;
  4971. DsRoleFreeMemory(pDomInfo);
  4972. return false;
  4973. }
  4974. }
  4975. // compare them
  4976. if ( ( (pDomInfo->DomainNameDns != NULL) &&
  4977. ((LPCTSTR)sourceDNS != NULL) &&
  4978. (_wcsicmp(pDomInfo->DomainNameDns, (LPCTSTR)sourceDNS)==0) ) ||
  4979. ( (pDomInfo->DomainNameFlat != NULL) &&
  4980. ((LPCTSTR)sourceNetbios != NULL) &&
  4981. (_wcsicmp(pDomInfo->DomainNameFlat, (LPCTSTR)sourceNetbios)==0) ) )
  4982. {
  4983. // at least one of them matches
  4984. DsRoleFreeMemory(pDomInfo);
  4985. }
  4986. else
  4987. {
  4988. // no match
  4989. DsRoleFreeMemory(pDomInfo);
  4990. sTemp.LoadString(IDS_MSG_PWDDC_WRONG_DOMAIN);
  4991. msg.Format((LPCTSTR)sTemp, (LPCTSTR)server, (LPCTSTR)sourceDNS);
  4992. title.LoadString(IDS_MSG_ERROR);
  4993. *msgtype = MB_ICONERROR | MB_OK;
  4994. return false;
  4995. }
  4996. if (SUCCEEDED(hr))
  4997. {
  4998. //try to establish the session, which will check all requirements
  4999. hr = pPwdMig->raw_EstablishSession(_bstr_t(server), _bstr_t(GetTargetDcName()));
  5000. if (SUCCEEDED(hr)) //if success, return true
  5001. return true;
  5002. }
  5003. //try to get the rich error information
  5004. if (SUCCEEDED(GetErrorInfo(0, &pErrorInfo)))
  5005. {
  5006. HRESULT hrTmp = pErrorInfo->GetDescription(&bstrDescription);
  5007. if (SUCCEEDED(hrTmp)) //if got rich error info, use it
  5008. sText = _bstr_t(bstrDescription, false);
  5009. else //else, prepare a standard message and return
  5010. {
  5011. sTemp.LoadString(IDS_MSG_PWDDC_NOT_READY);
  5012. msg.Format((LPCTSTR)sTemp, (LPCTSTR)server, (LPCTSTR)server);
  5013. title.LoadString(IDS_MSG_ERROR);
  5014. *msgtype = MB_ICONERROR | MB_OK;
  5015. return false;
  5016. }
  5017. }
  5018. else //else, prepare a standard message and return
  5019. {
  5020. sTemp.LoadString(IDS_MSG_PWDDC_NOT_READY);
  5021. msg.Format((LPCTSTR)sTemp, (LPCTSTR)server, (LPCTSTR)server);
  5022. title.LoadString(IDS_MSG_ERROR);
  5023. *msgtype = MB_ICONERROR | MB_OK;
  5024. return false;
  5025. }
  5026. //if not enabled on the src, add special question to error info
  5027. if (hr == PM_E_PASSWORD_MIGRATION_NOT_ENABLED)
  5028. {
  5029. sTemp.LoadString(IDS_MSG_PWDDC_DISABLED);
  5030. msg = (LPCTSTR)sText;
  5031. msg += sTemp; //add a question to the end of the error text
  5032. title.LoadString(IDS_MSG_WARNING);
  5033. *msgtype = MB_ICONQUESTION | MB_YESNO;
  5034. }
  5035. //else display the error info
  5036. else
  5037. {
  5038. msg = (LPCTSTR)sText;
  5039. title.LoadString(IDS_MSG_ERROR);
  5040. *msgtype = MB_ICONERROR | MB_OK;
  5041. }
  5042. return false;
  5043. }
  5044. //END IsPasswordDCReady
  5045. /*********************************************************************
  5046. * *
  5047. * Written by: Paul Thompson *
  5048. * Date: 7 FEB 2001 *
  5049. * *
  5050. * This function is a helper function responsible for checking *
  5051. * the existance of a directory path, and create any needed *
  5052. * directories for this path. The given path should not include a *
  5053. * file and should be a full path and not a relative path. *
  5054. * The function returns the newly created path. *
  5055. * *
  5056. *********************************************************************/
  5057. //BEGIN CreatePath
  5058. CString CreatePath(CString sDirPath)
  5059. {
  5060. /* local variables */
  5061. int tosubtract,tosubtract2, final;
  5062. CString dir;
  5063. CString root;
  5064. CString sEmpty = L"";
  5065. int nStart = 1;
  5066. /* function body */
  5067. //remove any trailing '\' or '/'
  5068. tosubtract = sDirPath.ReverseFind(L'\\');
  5069. tosubtract2 = sDirPath.ReverseFind(L'/');
  5070. final = (tosubtract > tosubtract2) ? tosubtract : tosubtract2;
  5071. if (final==-1)
  5072. return sEmpty;
  5073. if (sDirPath.GetLength() == (final+1))
  5074. dir = sDirPath.Left(final);
  5075. else
  5076. dir = sDirPath;
  5077. //try to convert a local relative dir path to a full path
  5078. if (dir.GetAt(0) != L'\\')
  5079. {
  5080. CString szPath;
  5081. LPTSTR pszFilePart;
  5082. CString tempPath = dir;
  5083. tempPath += "\\*.*";
  5084. DWORD cchPath = GetFullPathName(tempPath, 2000, szPath.GetBuffer(2000), &pszFilePart);
  5085. szPath.ReleaseBuffer();
  5086. if ((cchPath != 0) && (cchPath <= 2000))
  5087. {
  5088. final = szPath.ReverseFind(L'\\');
  5089. dir = szPath.Left(final);
  5090. }
  5091. }
  5092. else
  5093. nStart = 2;
  5094. if ((dir.Right(1) == L':') && (validDir(dir)))
  5095. return dir;
  5096. //find the first '\' or '/' past the "C:" or "\\" at the beginning
  5097. tosubtract = dir.Find(L'\\', nStart);
  5098. tosubtract2 = dir.Find(L'/', nStart);
  5099. if ((tosubtract != -1))
  5100. {
  5101. final = tosubtract;
  5102. if ((tosubtract2 != -1) && (tosubtract2 < final))
  5103. final = tosubtract2;
  5104. }
  5105. else if ((tosubtract2 != -1))
  5106. final = tosubtract2;
  5107. else
  5108. return sEmpty;
  5109. final++; //move to the next character
  5110. root = dir.Left(final);
  5111. dir = dir.Right(dir.GetLength()-final);
  5112. //create needed directories
  5113. final = dir.FindOneOf(L"\\/");
  5114. while (final!=-1)
  5115. {
  5116. root += dir.Left(final);
  5117. if (!validDir(root))
  5118. {
  5119. int create=CreateDirectory(root.GetBuffer(1000),NULL);
  5120. root.ReleaseBuffer();
  5121. if (create==0)return sEmpty;
  5122. }
  5123. root += L"\\";
  5124. dir = dir.Right(dir.GetLength()-final-1);
  5125. final = dir.FindOneOf(L"\\/");
  5126. }
  5127. root += dir;
  5128. if (!validDir(root))
  5129. {
  5130. int create=CreateDirectory(root.GetBuffer(1000),NULL);
  5131. root.ReleaseBuffer();
  5132. if (create==0)return sEmpty;
  5133. }
  5134. return root;
  5135. }
  5136. //END CreatePath
  5137. void GetValidPathPart(CString sFullPath, CString & sDirectory, CString & sFileName)
  5138. {
  5139. //remove the file off the path
  5140. int tosubtract = sFullPath.ReverseFind(L'\\');
  5141. int tosubtract2 = sFullPath.ReverseFind(L'/');
  5142. int final = (tosubtract > tosubtract2) ? tosubtract : tosubtract2;
  5143. if (final == -1)
  5144. {
  5145. sDirectory = L"";
  5146. sFileName = L"";
  5147. return;
  5148. }
  5149. sDirectory = sFullPath;
  5150. sFileName = sFullPath.Right(sFullPath.GetLength()-(final+1)); //save the filename
  5151. while (final != -1)
  5152. {
  5153. //see if this shorter path exists
  5154. sDirectory = sDirectory.Left(final);
  5155. if (validDir(sDirectory))
  5156. return;
  5157. //strip off the next directory from the path
  5158. tosubtract = sDirectory.ReverseFind(L'\\');
  5159. tosubtract2 = sDirectory.ReverseFind(L'/');
  5160. final = (tosubtract > tosubtract2) ? tosubtract : tosubtract2;
  5161. }
  5162. sDirectory = L"";
  5163. return;
  5164. }
  5165. /*********************************************************************
  5166. * *
  5167. * Written by: Paul Thompson *
  5168. * Date: 4 JUNE 2001 *
  5169. * *
  5170. * This function is a helper function responsible for checking *
  5171. * to see if the given account has previously been migrated. If it *
  5172. * has, the function returns TRUE, otherwise, FALSE. We also fill in *
  5173. * the given target account name CStrings. *
  5174. * *
  5175. *********************************************************************/
  5176. //BEGIN HasAccountBeenMigrated
  5177. BOOL HasAccountBeenMigrated(CString sAccount, CString& sTgtAcct)
  5178. {
  5179. /* local variables */
  5180. BOOL bMigrated = FALSE;
  5181. int index;
  5182. CString sUser=L"", sDomain=L"";
  5183. /* function body */
  5184. //if the account is given in NT4 format (Domain\user) then get the domain and username
  5185. if ((index = sAccount.Find(L'\\')) != -1)
  5186. {
  5187. sDomain = sAccount.Left(index);
  5188. sUser = sAccount.Mid(index + 1);
  5189. }
  5190. //else if in UPN format, so get the domain and username from it
  5191. else if ((index = sAccount.Find(L'@')) != -1)
  5192. {
  5193. GetDomainAndUserFromUPN((LPCTSTR)sAccount, sDomain, sUser);
  5194. }
  5195. //if we got the domain and user names, see if this account has been migrated
  5196. if ((sUser.GetLength()) && (sDomain.GetLength()))
  5197. {
  5198. IVarSetPtr pVsMO(__uuidof(VarSet));
  5199. IUnknown * pUnk = NULL;
  5200. HRESULT hr;
  5201. hr = pVsMO->QueryInterface(IID_IUnknown, (void**)&pUnk);
  5202. if (SUCCEEDED(hr))
  5203. {
  5204. _bstr_t strFlatName;
  5205. _bstr_t strDnsName;
  5206. DWORD dwError = GetDomainNames5(sDomain, strFlatName, strDnsName);
  5207. if (dwError == ERROR_SUCCESS)
  5208. {
  5209. //see if this account has been migrated to any target domain
  5210. hr = db->raw_GetAMigratedObjectToAnyDomain(_bstr_t(sUser), !strDnsName ? strFlatName : strDnsName, &pUnk);
  5211. pUnk->Release();
  5212. if (hr == S_OK)
  5213. {
  5214. _bstr_t sTemp;
  5215. //get the managed object's target adspath
  5216. sTemp = pVsMO->get(L"MigratedObjects.TargetDomain");
  5217. dwError = GetDomainNames5(sTemp, strFlatName, strDnsName);
  5218. if (dwError == ERROR_SUCCESS)
  5219. {
  5220. sTgtAcct = (WCHAR*)strFlatName;
  5221. sTgtAcct += L"\\";
  5222. sTemp = pVsMO->get(L"MigratedObjects.TargetSamName");
  5223. sTgtAcct += sTemp;
  5224. bMigrated = TRUE;
  5225. }
  5226. }
  5227. }
  5228. }
  5229. }
  5230. return bMigrated;
  5231. }
  5232. //END HasAccountBeenMigrated
  5233. /*********************************************************************
  5234. * *
  5235. * Written by: Paul Thompson *
  5236. * Date: 5 JUNE 2001 *
  5237. * *
  5238. * This function is a helper function responsible for confirming *
  5239. * a user's true intent to cancel out of a wizard. *
  5240. * *
  5241. *********************************************************************/
  5242. //BEGIN ReallyCancel
  5243. BOOL ReallyCancel(HWND hwndDlg)
  5244. {
  5245. /* local variables */
  5246. CString msg, title;
  5247. /* function body */
  5248. //get the text to display in the message
  5249. msg.LoadString(IDS_MSG_CANCEL_REALLY);
  5250. title.LoadString(IDS_CANCEL_TITLE);
  5251. //if they are sure they want to cancel, return TRUE
  5252. if (MessageBox(hwndDlg,msg,title,MB_YESNO|MB_ICONSTOP) == IDYES)
  5253. return TRUE;
  5254. else
  5255. return FALSE;
  5256. }
  5257. //END ReallyCancel
  5258. /*********************************************************************
  5259. * *
  5260. * Written by: Paul Thompson *
  5261. * Date: 5 JULY 2001 *
  5262. * *
  5263. * This function is a helper function responsible for checking to*
  5264. * see if the user has requested to retry more than one task on a *
  5265. * single machine. It returns the name of the first server found to *
  5266. * have more than one task included for it. If no machine has more *
  5267. * than one task includede then we return an empty string. *
  5268. * *
  5269. *********************************************************************/
  5270. //BEGIN GetServerWithMultipleTasks
  5271. CString GetServerWithMultipleTasks()
  5272. {
  5273. /* local variables */
  5274. CStringList nameList;
  5275. CString sServer, sStatus, sInclude;
  5276. CString sRetServer = L"";
  5277. BOOL bDup = FALSE;
  5278. int ndx = 0;
  5279. /* function body */
  5280. //while there are more selected tasks and no duplicate machine name
  5281. sInclude.LoadString(IDS_INCLUDE);
  5282. while ((ndx < m_cancelBox.GetItemCount()) && (!bDup))
  5283. {
  5284. //get the status and only check those marked "Include"
  5285. sStatus = m_cancelBox.GetItemText(ndx,5);
  5286. if (sStatus == sInclude)
  5287. {
  5288. //get the server name
  5289. sServer = m_cancelBox.GetItemText(ndx,0);
  5290. //if the server is not in the list, add it
  5291. if (nameList.Find(sServer) == NULL)
  5292. nameList.AddTail(sServer);
  5293. else //else it is in the list
  5294. {
  5295. bDup = TRUE; //set flag to leave loop
  5296. sRetServer = sServer; //set server to return it
  5297. }
  5298. }
  5299. ndx++;
  5300. }
  5301. nameList.RemoveAll(); //delete the list
  5302. return (sRetServer); //return server name if duplicate or empty string if not
  5303. }
  5304. //END GetServerWithMultipleTasks
  5305. void __stdcall SharedHelp(ADMTSHAREDHELP HelpTopic, HWND hwndDlg)
  5306. {
  5307. int HelpID;
  5308. switch(HelpTopic)
  5309. {
  5310. // help page is "Domain Selection"
  5311. case DOMAIN_SELECTION_HELP:
  5312. {
  5313. if(migration == w_computer)
  5314. HelpID = IDH_WINDOW_DOMAIN_SELECTION;
  5315. else if(migration == w_group)
  5316. HelpID = IDH_WINDOW_DOMAIN_SELECTION_GROUP;
  5317. else if(migration == w_groupmapping)
  5318. HelpID = IDH_WINDOW_DOMAIN_SELECTION_GROUPMAP;
  5319. else if(migration == w_reporting)
  5320. HelpID = IDH_WINDOW_DOMAIN_SELECTION_REPORT;
  5321. else if(migration == w_security)
  5322. HelpID = IDH_WINDOW_DOMAIN_SELECTION_SECURITY;
  5323. else if(migration == w_service)
  5324. HelpID = IDH_WINDOW_DOMAIN_SELECTION_SERVICE;
  5325. else if(migration == w_trust)
  5326. HelpID = IDH_WINDOW_DOMAIN_SELECTION_TRUST;
  5327. else if(migration == w_account)
  5328. HelpID = IDH_WINDOW_DOMAIN_SELECTION_USER;
  5329. else if(migration == w_exchangeDir)
  5330. HelpID = IDH_WINDOW_DOMAIN_SELECTION_EXCHANGE;
  5331. break;
  5332. }
  5333. // help page is "Group Selection"
  5334. case GROUP_SELECTION_HELP:
  5335. {
  5336. if(migration == w_group)
  5337. HelpID = IDH_WINDOW_GROUP_SELECTION;
  5338. else if(migration == w_groupmapping)
  5339. HelpID = IDH_WINDOW_GROUP_SELECTION_GROUPMAP;
  5340. break;
  5341. }
  5342. // help page is "Computer Selection"
  5343. case COMPUTER_SELECTION_HELP:
  5344. {
  5345. if(migration == w_computer)
  5346. HelpID = IDH_WINDOW_COMPUTER_SELECTION;
  5347. else if(migration == w_reporting)
  5348. HelpID = IDH_WINDOW_COMPUTER_SELECTION_REPORT;
  5349. else if(migration == w_security)
  5350. HelpID = IDH_WINDOW_COMPUTER_SELECTION_SECURITY;
  5351. break;
  5352. }
  5353. // help page is "Organizational Unit Selection"
  5354. case OU_SELECTION_HELP:
  5355. {
  5356. if(migration == w_computer)
  5357. HelpID = IDH_WINDOW_OU_SELECTION;
  5358. else if(migration == w_group)
  5359. HelpID = IDH_WINDOW_OU_SELECTION_GROUP;
  5360. else if(migration == w_groupmapping)
  5361. HelpID = IDH_WINDOW_OU_SELECTION_GROUPMAP;
  5362. else if(migration == w_account)
  5363. HelpID = IDH_WINDOW_OU_SELECTION_USER;
  5364. break;
  5365. }
  5366. // help page is "Translate Objects"
  5367. case TRANSLATE_OBJECTS_HELP:
  5368. {
  5369. if(migration == w_computer)
  5370. HelpID = IDH_WINDOW_OBJECTTYPE_SELECTION;
  5371. else if(migration == w_security)
  5372. HelpID = IDH_WINDOW_OBJECTTYPE_SELECTION_SECURITY;
  5373. break;
  5374. }
  5375. // help page is "Group Options"
  5376. case GROUP_OPTION_HELP:
  5377. {
  5378. if(migration == w_group)
  5379. HelpID = IDH_WINDOW_GROUP_OPTION;
  5380. else if(migration == w_groupmapping)
  5381. HelpID = IDH_WINDOW_GROUP_OPTION_GROUPMAP;
  5382. break;
  5383. }
  5384. // help page is "Security Translaton Options"
  5385. case SECURITY_OPTION_HELP:
  5386. {
  5387. if(migration == w_computer)
  5388. HelpID = IDH_WINDOW_SECURITY_OPTION;
  5389. else if(migration == w_security)
  5390. HelpID = IDH_WINDOW_SECURITY_OPTION_SECURITY;
  5391. else if(migration == w_exchangeDir)
  5392. HelpID = IDH_WINDOW_SECURITY_OPTION_EXCHANGE;
  5393. break;
  5394. }
  5395. // help page is "Naming Conflicts"
  5396. case NAME_CONFLICT_HELP:
  5397. {
  5398. if(migration == w_computer)
  5399. HelpID = IDH_WINDOW_NAME_CONFLICT;
  5400. else if(migration == w_group)
  5401. HelpID = IDH_WINDOW_NAME_CONFLICT_GROUP;
  5402. else if(migration == w_account)
  5403. HelpID = IDH_WINDOW_NAME_CONFLICT_USER;
  5404. break;
  5405. }
  5406. // help page is "Confirmation"
  5407. case CONFIRMATION_HELP:
  5408. {
  5409. if(migration == w_computer)
  5410. HelpID = IDH_WINDOW_CONFIRMATION;
  5411. else if(migration == w_group)
  5412. HelpID = IDH_WINDOW_CONFIRMATION_GROUP;
  5413. else if(migration == w_groupmapping)
  5414. HelpID = IDH_WINDOW_CONFIRMATION_GROUPMAP;
  5415. else if(migration == w_reporting)
  5416. HelpID = IDH_WINDOW_CONFIRMATION_REPORT;
  5417. else if(migration == w_retry)
  5418. HelpID = IDH_WINDOW_CONFIRMATION_RETRY;
  5419. else if(migration == w_security)
  5420. HelpID = IDH_WINDOW_CONFIRMATION_SECURITY;
  5421. else if(migration == w_service)
  5422. HelpID = IDH_WINDOW_CONFIRMATION_SERVICE;
  5423. else if(migration == w_undo)
  5424. HelpID = IDH_WINDOW_CONFIRMATION_UNDO;
  5425. else if(migration == w_account)
  5426. HelpID = IDH_WINDOW_CONFIRMATION_USER;
  5427. else if(migration == w_exchangeDir)
  5428. HelpID = IDH_WINDOW_CONFIRMATION_EXCHANGE;
  5429. else if(migration == w_trust)
  5430. HelpID = IDH_WINDOW_CONFIRMATION_TRUST;
  5431. break;
  5432. }
  5433. // help page is "Test or Make Changes"
  5434. case COMMIT_HELP:
  5435. {
  5436. if(migration == w_computer)
  5437. HelpID = IDH_WINDOW_COMMIT;
  5438. else if(migration == w_exchangeDir)
  5439. HelpID = IDH_WINDOW_COMMIT_EXCHANGE;
  5440. else if(migration == w_group)
  5441. HelpID = IDH_WINDOW_COMMIT_GROUP;
  5442. else if(migration == w_groupmapping)
  5443. HelpID = IDH_WINDOW_COMMIT_GROUPMAP;
  5444. else if(migration == w_security)
  5445. HelpID = IDH_WINDOW_COMMIT_SECURITY;
  5446. else if(migration == w_account)
  5447. HelpID = IDH_WINDOW_COMMIT_USER;
  5448. break;
  5449. }
  5450. // help page is "Object Property Exclusion"
  5451. case OBJECT_PROPERTY_EXCLUSION:
  5452. {
  5453. if(migration == w_computer)
  5454. HelpID = IDH_WINDOW_OBJECT_PROPERTY_EXCLUSION;
  5455. else if(migration == w_group)
  5456. HelpID = IDH_WINDOW_OBJECT_PROPERTY_EXCLUSION_GROUP;
  5457. else if(migration == w_account)
  5458. HelpID = IDH_WINDOW_OBJECT_PROPERTY_EXCLUSION_USER;
  5459. break;
  5460. }
  5461. // help page is "User Account"
  5462. case CREDENTIALS_HELP:
  5463. {
  5464. if(migration == w_group)
  5465. HelpID = IDH_WINDOW_SIDHISTORY_CREDENTIALS;
  5466. else if(migration == w_groupmapping)
  5467. HelpID = IDH_WINDOW_SIDHISTORY_CREDENTIALS_GROUPMAP;
  5468. else if(migration == w_account)
  5469. HelpID = IDH_WINDOW_SIDHISTORY_CREDENTIALS_USER;
  5470. else if(migration == w_undo)
  5471. HelpID = IDH_WINDOW_SIDHISTORY_CREDENTIALS_UNDO;
  5472. else if(migration == w_exchangeDir)
  5473. HelpID = IDH_WINDOW_USER_ACC_PASS;
  5474. break;
  5475. }
  5476. // help page is "Service Account Informatoin" in service wizard
  5477. case SERVICE_ACCOUNT_INFO:
  5478. {
  5479. HelpID = IDH_WINDOW_SERVICE_ACCOUNT_INFO;
  5480. break;
  5481. }
  5482. // help page is "User Service Account"
  5483. case USER_SERVICE_ACCOUNT:
  5484. {
  5485. if(migration == w_account)
  5486. HelpID = IDH_WINDOW_USER_SERVICE_ACCOUNT_INFO;
  5487. else if(migration == w_group)
  5488. HelpID = IDH_WINDOW_USER_SERVICE_ACCOUNT_GROUP;
  5489. break;
  5490. }
  5491. // help page is "Update Information" in Service wizard
  5492. case REFRESH_INFO_HELP:
  5493. {
  5494. HelpID = IDH_WINDOW_REFRESH_INFO;
  5495. break;
  5496. }
  5497. // help page is "Group Options"
  5498. case GROUP_MEMBER_OPTION:
  5499. {
  5500. HelpID = IDH_WINDOW_GROUP_MEMBER_OPTION;
  5501. break;
  5502. }
  5503. // help page is "User Options"
  5504. case USER_OPTION_HELP:
  5505. {
  5506. HelpID = IDH_WINDOW_USER_OPTION;
  5507. break;
  5508. }
  5509. case REPORT_SELECTION_HELP:
  5510. {
  5511. HelpID = IDH_WINDOW_REPORT_SELECTION;
  5512. break;
  5513. }
  5514. case TASK_SELECTION_HELP:
  5515. {
  5516. HelpID = IDH_WINDOW_TASK_SELECTION;
  5517. break;
  5518. }
  5519. case PASSWORD_OPTION_HELP:
  5520. {
  5521. HelpID = IDH_WINDOW_PASSWORD_OPTION;
  5522. break;
  5523. }
  5524. case TARGET_GROUP_SELECTION:
  5525. {
  5526. HelpID = IDH_WINDOW_TARGET_GROUP_SELECTION;
  5527. break;
  5528. }
  5529. case TRUST_INFO_HELP:
  5530. {
  5531. HelpID = IDH_WINDOW_TRUST_INFO;
  5532. break;
  5533. }
  5534. case COMPUTER_OPTION:
  5535. {
  5536. HelpID = IDH_WINDOW_COMPUTER_OPTION;
  5537. break;
  5538. }
  5539. case UNDO_HELP:
  5540. {
  5541. HelpID = IDH_WINDOW_UNDO;
  5542. break;
  5543. }
  5544. case WELCOME_HELP:
  5545. {
  5546. HelpID = IDH_WINDOW_WELCOME;
  5547. break;
  5548. }
  5549. case ACCOUNTTRANSITION_OPTION:
  5550. {
  5551. HelpID = IDH_WINDOW_ACCOUNTTRANSITION_OPTION;
  5552. break;
  5553. }
  5554. case EXCHANGE_SERVER_SELECTION:
  5555. {
  5556. HelpID = IDH_WINDOW_EXCHANGE_SERVER_SELECTION;
  5557. break;
  5558. }
  5559. case USER_SELECTION_HELP:
  5560. {
  5561. HelpID = IDH_WINDOW_USER_SELECTION;
  5562. break;
  5563. }
  5564. case SERVICE_ACCOUNT_SELECTION:
  5565. {
  5566. HelpID = IDH_WINDOW_SERVICE_ACCOUNT_SELECTION;
  5567. break;
  5568. }
  5569. case DIRECTORY_SELECTION_HELP:
  5570. {
  5571. HelpID = IDH_WINDOW_DIRECTORY_SELECTION;
  5572. break;
  5573. }
  5574. case TRANSLATION_OPTION:
  5575. {
  5576. HelpID = IDH_WINDOW_TRANSLATION_OPTION;
  5577. break;
  5578. }
  5579. default:
  5580. break;
  5581. }
  5582. helpWrapper(hwndDlg,HelpID);
  5583. }
  5584. //-----------------------------------------------------------------------------
  5585. // SetDefaultExcludedSystemProperties
  5586. //
  5587. // Synopsis
  5588. // Sets the default system property exclusion list if the list has not already
  5589. // been generated. Note that the default system property exclusion list consists of
  5590. // the mail, proxyAddresses and all attributes not marked as being part of
  5591. // the base schema.
  5592. //
  5593. // Arguments
  5594. // IN hwndDlg - handle to dialog which is used to display message box if error
  5595. // occurs
  5596. //
  5597. // Return Value
  5598. // None
  5599. //-----------------------------------------------------------------------------
  5600. void __stdcall SetDefaultExcludedSystemProperties(HWND hwndDlg)
  5601. {
  5602. try
  5603. {
  5604. //
  5605. // If system property exclusion set value is zero then generate
  5606. // and set default system property exclusion list.
  5607. //
  5608. IVarSetPtr spSettings(__uuidof(VarSet));
  5609. IUnknownPtr spUnknown(spSettings);
  5610. IUnknown* punk = spUnknown;
  5611. db->GetSettings(&punk);
  5612. long lSet = spSettings->get(GET_BSTR(DCTVS_AccountOptions_ExcludedSystemPropsSet));
  5613. if (lSet == 0)
  5614. {
  5615. IObjPropBuilderPtr spObjPropBuilder(__uuidof(ObjPropBuilder));
  5616. _bstr_t strNonBaseProperties = spObjPropBuilder->GetNonBaseProperties(GetTargetDomainName());
  5617. _bstr_t strProperties = _T("mail,proxyAddresses,") + strNonBaseProperties;
  5618. spSettings->put(GET_BSTR(DCTVS_AccountOptions_ExcludedSystemProps), strProperties);
  5619. db->SaveSettings(punk);
  5620. put(DCTVS_AccountOptions_ExcludedSystemProps, strProperties);
  5621. }
  5622. }
  5623. catch (_com_error& ce)
  5624. {
  5625. CString strTitle;
  5626. strTitle.LoadString(IDS_MSG_WARNING);
  5627. CString strFormat;
  5628. strFormat.LoadString(IDS_MSG_UNABLE_SET_EXCLUDED_SYSTEM_PROPERTIES);
  5629. CString strMessage;
  5630. strMessage.Format(strFormat, ce.ErrorMessage());
  5631. MessageBox(hwndDlg, strMessage, strTitle, MB_ICONWARNING|MB_OK);
  5632. }
  5633. }