Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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