Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1987 lines
54 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // DS Administration MMC snapin.
  4. //
  5. // Microsoft Windows
  6. // Copyright (C) Microsoft Corporation, 1992 - 1999
  7. //
  8. // File: DSDlgs.cpp
  9. //
  10. // Contents: TBD
  11. //
  12. // History: 02-Oct-96 WayneSc Created
  13. //
  14. //-----------------------------------------------------------------------------
  15. #include "stdafx.h"
  16. #include "resource.h"
  17. #include "dssnap.h"
  18. #include "uiutil.h"
  19. #include "DSDlgs.h"
  20. #include "helpids.h"
  21. #include "dsrole.h" // DsRoleGetPrimaryDomainInformation
  22. #include <lm.h>
  23. #include <dsgetdc.h>
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. #include "globals.h"
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CChangePassword dialog
  32. CChangePassword::CChangePassword(CWnd* pParent /*=NULL*/)
  33. : CHelpDialog(CChangePassword::IDD, pParent),
  34. m_ConfirmPwd(),
  35. m_NewPwd(),
  36. m_LastEncryptionResult(S_OK),
  37. m_bAllowMustChangePwdCheck(TRUE)
  38. {
  39. //{{AFX_DATA_INIT(CChangePassword)
  40. m_ChangePwd = FALSE;
  41. //}}AFX_DATA_INIT
  42. }
  43. BOOL CChangePassword::OnInitDialog()
  44. {
  45. CHelpDialog::OnInitDialog();
  46. SendDlgItemMessage(
  47. IDC_NEW_PASSWORD,
  48. EM_LIMITTEXT,
  49. (WPARAM)MAX_PASSWORD_LENGTH,
  50. 0);
  51. SendDlgItemMessage(
  52. IDC_CONFIRM_PASSWORD,
  53. EM_LIMITTEXT,
  54. (WPARAM)MAX_PASSWORD_LENGTH,
  55. 0);
  56. GetDlgItem(IDC_CHECK_PASSWORD_MUST_CHANGE)->EnableWindow(m_bAllowMustChangePwdCheck);
  57. return TRUE;
  58. }
  59. void CChangePassword::DoDataExchange(CDataExchange* pDX)
  60. {
  61. CHelpDialog::DoDataExchange(pDX);
  62. //{{AFX_DATA_MAP(CChangePassword)
  63. DDX_Check(pDX, IDC_CHECK_PASSWORD_MUST_CHANGE, m_ChangePwd);
  64. //}}AFX_DATA_MAP
  65. HRESULT hr1 = DDX_EncryptedText(pDX, IDC_CONFIRM_PASSWORD, m_ConfirmPwd);
  66. HRESULT hr2 = DDX_EncryptedText(pDX, IDC_NEW_PASSWORD, m_NewPwd);
  67. // NTRAID#NTBUG9-635046-2002/06/10-artm
  68. // If storing user entered values into encrypted buffer . . .
  69. if (pDX && pDX->m_bSaveAndValidate)
  70. {
  71. m_LastEncryptionResult = S_OK;
  72. // . . . check for an encryption failure. Either or both may fail,
  73. // but we only need to keep track of one failure.
  74. if (FAILED(hr1))
  75. {
  76. m_LastEncryptionResult = hr1;
  77. }
  78. if (FAILED(hr2))
  79. {
  80. m_LastEncryptionResult = hr2;
  81. }
  82. }
  83. // Double check that the max password length hasn't been
  84. // exceeded (by someone altering the validation code in
  85. // OnInitDialog()).
  86. ASSERT(m_ConfirmPwd.GetLength() <= MAX_PASSWORD_LENGTH);
  87. ASSERT(m_NewPwd.GetLength() <= MAX_PASSWORD_LENGTH);
  88. }
  89. void CChangePassword::Clear()
  90. {
  91. // Reset the passwords to empty.
  92. m_ConfirmPwd.Clear();
  93. m_NewPwd.Clear();
  94. // No possible problems with the password storage now.
  95. m_LastEncryptionResult = S_OK;
  96. // Reset the password boxes on the dialog.
  97. // NTRAID#NTBUG9-628311-2002/05/29-artm
  98. // You might be tempted to call UpdateData(FALSE) instead of having this extra logic.
  99. // It won't work though since DDX_Check() apparently cannot be called after the dialog
  100. // has been initialized.
  101. SetDlgItemText(IDC_CONFIRM_PASSWORD, L"");
  102. SetDlgItemText(IDC_NEW_PASSWORD, L"");
  103. }
  104. BEGIN_MESSAGE_MAP(CChangePassword, CHelpDialog)
  105. END_MESSAGE_MAP()
  106. void CChangePassword::DoContextHelp(HWND hWndControl)
  107. {
  108. if (hWndControl)
  109. {
  110. ::WinHelp(hWndControl,
  111. DSADMIN_CONTEXT_HELP_FILE,
  112. HELP_WM_HELP,
  113. (DWORD_PTR)(LPTSTR)g_aHelpIDs_IDD_CHANGE_PASSWORD);
  114. }
  115. }
  116. /////////////////////////////////////////////////////////////////////////////
  117. // Helper functions for CChooseDomainDlg and CChooseDCDlg
  118. //
  119. //+---------------------------------------------------------------------------
  120. //
  121. // Function: BrowseDomainTree
  122. //
  123. // Synopsis: This function invokes IDsBrowseDomainTree::BrowseTo(),
  124. // which brings up the domain tree browse dialog, and returns the
  125. // selected domain's DNS name
  126. //
  127. // NOTE: the OUT parameter needs to be LocalFreeString() by the caller
  128. // NOTE: this function will return S_FALSE if user clicks Cancel button
  129. //
  130. //----------------------------------------------------------------------------
  131. HRESULT BrowseDomainTree(
  132. IN HWND hwndParent,
  133. IN LPCTSTR pszServer,
  134. OUT LPTSTR *ppszDomainDnsName
  135. )
  136. {
  137. ASSERT(ppszDomainDnsName);
  138. ASSERT(!(*ppszDomainDnsName)); // prevent memory leak
  139. *ppszDomainDnsName = NULL;
  140. CComPtr<IDsBrowseDomainTree> spDsDomains;
  141. HRESULT hr = ::CoCreateInstance(CLSID_DsDomainTreeBrowser,
  142. NULL,
  143. CLSCTX_INPROC_SERVER,
  144. IID_IDsBrowseDomainTree,
  145. reinterpret_cast<void **>(&spDsDomains));
  146. if (SUCCEEDED(hr))
  147. {
  148. if (pszServer && *pszServer)
  149. hr = spDsDomains->SetComputer(pszServer, NULL, NULL); // use default credential
  150. if (SUCCEEDED(hr))
  151. {
  152. LPTSTR lpszDomainPath;
  153. hr = spDsDomains->BrowseTo(
  154. hwndParent, //HWND hwndParent
  155. &lpszDomainPath, // LPWSTR *ppszTargetPath
  156. DBDTF_RETURNINBOUND);
  157. if ( (hr == S_OK) && lpszDomainPath)
  158. {
  159. *ppszDomainDnsName = lpszDomainPath; //should be freed by CoTaskMemFree later
  160. }
  161. }
  162. }
  163. return hr;
  164. }
  165. HRESULT GetDCOfDomain(
  166. IN CString& csDomainName,
  167. OUT CString& csDCName,
  168. IN BOOL bForce
  169. )
  170. {
  171. ASSERT(csDomainName.IsEmpty() == FALSE);
  172. CString csServerName;
  173. DWORD dwErr = 0;
  174. csDCName.Empty();
  175. PDOMAIN_CONTROLLER_INFO pDCInfo = NULL;
  176. if (bForce)
  177. dwErr = DsGetDcName(NULL, csDomainName, NULL, NULL,
  178. DS_DIRECTORY_SERVICE_PREFERRED | DS_FORCE_REDISCOVERY, &pDCInfo);
  179. else
  180. dwErr = DsGetDcName(NULL, csDomainName, NULL, NULL,
  181. DS_DIRECTORY_SERVICE_PREFERRED, &pDCInfo);
  182. if (ERROR_SUCCESS == dwErr)
  183. {
  184. if ( !(pDCInfo->Flags & DS_DS_FLAG) )
  185. {
  186. // down level domain
  187. NetApiBufferFree(pDCInfo);
  188. return S_OK;
  189. }
  190. csDCName = pDCInfo->DomainControllerName;
  191. NetApiBufferFree(pDCInfo);
  192. }
  193. return HRESULT_FROM_WIN32(dwErr);
  194. }
  195. //+---------------------------------------------------------------------------
  196. //
  197. // Function: GetDnsNameOfDomainOrForest
  198. //
  199. // Synopsis: Given a server name or a domain name (either NETBIOS or DNS),
  200. // this function will return the DNS name for its domain or forest.
  201. //
  202. // Parameters:
  203. // csName, // a server name or a domain name
  204. // csDnsName, // hold the returning DNS name
  205. // bIsInputADomainName, // TRUE if csName is a domain name, FALSE if it's a server name
  206. // bRequireDomain // TRUE for a domain dns name, FALSE for a forest dns name
  207. //
  208. //----------------------------------------------------------------------------
  209. HRESULT GetDnsNameOfDomainOrForest(
  210. IN CString& csName,
  211. OUT CString& csDnsName,
  212. IN BOOL bIsInputADomainName,
  213. IN BOOL bRequireDomain
  214. )
  215. {
  216. BOOL bRetry = FALSE;
  217. PDSROLE_PRIMARY_DOMAIN_INFO_BASIC pBuffer = NULL;
  218. CString csServerName;
  219. DWORD dwErr = 0;
  220. csDnsName.Empty();
  221. do {
  222. if (bIsInputADomainName)
  223. {
  224. PDOMAIN_CONTROLLER_INFO pDCInfo = NULL;
  225. if (bRetry)
  226. dwErr = DsGetDcName(NULL, csName, NULL, NULL,
  227. DS_DIRECTORY_SERVICE_PREFERRED | DS_FORCE_REDISCOVERY, &pDCInfo);
  228. else
  229. dwErr = DsGetDcName(NULL, csName, NULL, NULL,
  230. DS_DIRECTORY_SERVICE_PREFERRED, &pDCInfo);
  231. if (ERROR_SUCCESS == dwErr)
  232. {
  233. if ( !(pDCInfo->Flags & DS_DS_FLAG) )
  234. {
  235. // down level domain
  236. NetApiBufferFree(pDCInfo);
  237. return S_OK;
  238. }
  239. DWORD dwExpectFlag = (bRequireDomain ?
  240. DS_DNS_DOMAIN_FLAG :
  241. DS_DNS_FOREST_FLAG);
  242. if (pDCInfo->Flags & dwExpectFlag)
  243. {
  244. // skip call to DsRoleGetPrimaryDomainInformation()
  245. csDnsName = (bRequireDomain ?
  246. pDCInfo->DomainName :
  247. pDCInfo->DnsForestName);
  248. NetApiBufferFree(pDCInfo);
  249. //
  250. // The DNS name is in absolute form, remove the ending dot
  251. //
  252. if (csDnsName.Right(1) == _T("."))
  253. csDnsName.SetAt(csDnsName.GetLength() - 1, _T('\0'));
  254. return S_OK;
  255. } else {
  256. csServerName = pDCInfo->DomainControllerName;
  257. NetApiBufferFree(pDCInfo);
  258. }
  259. } else
  260. {
  261. return HRESULT_FROM_WIN32(dwErr);
  262. }
  263. } else
  264. {
  265. csServerName = csName;
  266. }
  267. dwErr = DsRoleGetPrimaryDomainInformation(
  268. csServerName,
  269. DsRolePrimaryDomainInfoBasic,
  270. (PBYTE *)&pBuffer);
  271. if (RPC_S_SERVER_UNAVAILABLE == dwErr && bIsInputADomainName && !bRetry)
  272. bRetry = TRUE; // only retry once
  273. else
  274. break;
  275. } while (1);
  276. if (ERROR_SUCCESS == dwErr)
  277. {
  278. csDnsName = (bRequireDomain ?
  279. pBuffer->DomainNameDns :
  280. pBuffer->DomainForestName);
  281. if (csDnsName.IsEmpty())
  282. {
  283. if (pBuffer->Flags & DSROLE_PRIMARY_DS_RUNNING)
  284. csDnsName = pBuffer->DomainNameFlat;
  285. }
  286. DsRoleFreeMemory(pBuffer);
  287. //
  288. // In case the DNS name is in absolute form, remove the ending dot
  289. //
  290. if (csDnsName.Right(1) == _T("."))
  291. csDnsName.SetAt(csDnsName.GetLength() - 1, _T('\0'));
  292. }
  293. return HRESULT_FROM_WIN32(dwErr);
  294. }
  295. /////////////////////////////////////////////////////////////////////////////
  296. // CChooseDomainDlg dialog
  297. CChooseDomainDlg::CChooseDomainDlg(CWnd* pParent /*=NULL*/)
  298. : CHelpDialog(CChooseDomainDlg::IDD, pParent)
  299. {
  300. //{{AFX_DATA_INIT(CChooseDomainDlg)
  301. m_csTargetDomain = _T("");
  302. m_bSaveCurrent = FALSE;
  303. //}}AFX_DATA_INIT
  304. }
  305. void CChooseDomainDlg::DoDataExchange(CDataExchange* pDX)
  306. {
  307. CHelpDialog::DoDataExchange(pDX);
  308. //{{AFX_DATA_MAP(CChooseDomainDlg)
  309. DDX_Text(pDX, IDC_SELECTDOMAIN_DOMAIN, m_csTargetDomain);
  310. DDX_Check(pDX, IDC_SAVE_CURRENT_CHECK, m_bSaveCurrent);
  311. //}}AFX_DATA_MAP
  312. }
  313. BEGIN_MESSAGE_MAP(CChooseDomainDlg, CHelpDialog)
  314. //{{AFX_MSG_MAP(CChooseDomainDlg)
  315. ON_BN_CLICKED(IDC_SELECTDOMAIN_BROWSE, OnSelectdomainBrowse)
  316. //}}AFX_MSG_MAP
  317. END_MESSAGE_MAP()
  318. /////////////////////////////////////////////////////////////////////////////
  319. // CChooseDomainDlg message handlers
  320. void CChooseDomainDlg::OnSelectdomainBrowse()
  321. {
  322. CWaitCursor cwait;
  323. HRESULT hr = S_OK;
  324. LPTSTR lpszDomainDnsName = NULL;
  325. CString csDomainName, csDCName;
  326. GetDlgItemText(IDC_SELECTDOMAIN_DOMAIN, csDomainName);
  327. csDomainName.TrimLeft();
  328. csDomainName.TrimRight();
  329. if (!csDomainName.IsEmpty())
  330. hr = GetDCOfDomain(csDomainName, csDCName, FALSE);
  331. if (SUCCEEDED(hr))
  332. {
  333. hr = BrowseDomainTree(m_hWnd, csDCName, &lpszDomainDnsName);
  334. if ( FAILED(hr) &&
  335. !csDCName.IsEmpty() &&
  336. HRESULT_FROM_WIN32(RPC_S_SERVER_UNAVAILABLE) == hr )
  337. {
  338. // force the cached info in DsGetDcName to be refreshed
  339. hr = GetDCOfDomain(csDomainName, csDCName, TRUE);
  340. if (SUCCEEDED(hr))
  341. hr = BrowseDomainTree(m_hWnd, csDCName, &lpszDomainDnsName);
  342. }
  343. if ( (hr == S_OK) && lpszDomainDnsName )
  344. {
  345. SetDlgItemText(IDC_SELECTDOMAIN_DOMAIN, lpszDomainDnsName);
  346. CoTaskMemFree(lpszDomainDnsName);
  347. }
  348. }
  349. // JonN 9/05/01 464466
  350. // After a fail to Locate Domain Controllers, Browse button repeatedly fails.
  351. else
  352. {
  353. SetDlgItemText(IDC_SELECTDOMAIN_DOMAIN, L"");
  354. }
  355. if (FAILED(hr)) {
  356. PVOID apv[1];
  357. apv[0] = static_cast<PVOID>(const_cast<LPTSTR>(static_cast<LPCTSTR>(csDomainName)));
  358. ReportErrorEx(m_hWnd,IDS_CANT_BROWSE_DOMAIN, hr,
  359. MB_OK | MB_ICONERROR, apv, 1, 0);
  360. }
  361. GetDlgItem(IDC_SELECTDOMAIN_DOMAIN)->SetFocus();
  362. }
  363. void CChooseDomainDlg::OnOK()
  364. {
  365. CWaitCursor cwait;
  366. HRESULT hr = S_OK;
  367. CString csName, csDnsName;
  368. //
  369. // Validate contents in the domain edit box
  370. //
  371. GetDlgItemText(IDC_SELECTDOMAIN_DOMAIN, csName);
  372. if (csName.IsEmpty())
  373. {
  374. ReportMessageEx(m_hWnd, IDS_INCORRECT_INPUT,
  375. MB_OK | MB_ICONSTOP);
  376. (GetDlgItem(IDC_SELECTDOMAIN_DOMAIN))->SetFocus();
  377. return;
  378. }
  379. hr = GetDnsNameOfDomainOrForest(
  380. csName,
  381. csDnsName,
  382. TRUE,
  383. !m_bSiteRepl);
  384. if (csDnsName.IsEmpty())
  385. {
  386. PVOID apv[1];
  387. apv[0] = static_cast<PVOID>(const_cast<LPTSTR>(static_cast<LPCTSTR>(csName)));
  388. if (FAILED(hr))
  389. ReportErrorEx(m_hWnd, IDS_SELECTDOMAIN_INCORRECT_DOMAIN_DUETO, hr,
  390. MB_OK | MB_ICONSTOP, apv, 1, 0, FALSE);
  391. else
  392. ReportMessageEx(m_hWnd, IDS_SELECTDOMAIN_DOWNLEVEL_DOMAIN,
  393. MB_OK | MB_ICONSTOP, apv, 1, 0, FALSE);
  394. SendDlgItemMessage(IDC_SELECTDOMAIN_DOMAIN, EM_SETSEL, 0, -1);
  395. return;
  396. }
  397. //
  398. // When exiting from the dialog
  399. // use DNS domain name;
  400. //
  401. SetDlgItemText(IDC_SELECTDOMAIN_DOMAIN, csDnsName);
  402. CHelpDialog::OnOK();
  403. }
  404. BOOL CChooseDomainDlg::OnInitDialog()
  405. {
  406. CHelpDialog::OnInitDialog();
  407. // Limit the text to DNS_MAX_NAME_LENGTH
  408. SendDlgItemMessage(IDC_SELECTDOMAIN_DOMAIN, EM_SETLIMITTEXT, DNS_MAX_NAME_LENGTH, 0);
  409. //
  410. // for siterepl snapin only,
  411. // change dialog title to "Choose Target Forest"
  412. // change domain label to "Root domain:"
  413. // hide browse button
  414. //
  415. if (m_bSiteRepl)
  416. {
  417. CString csDlgTitle, csLabel;
  418. csDlgTitle.LoadString(IDS_SELECTDOMAIN_TITLE_FOREST);
  419. SetWindowText(csDlgTitle);
  420. csLabel.LoadString(IDS_SELECTDOMAIN_DOMAIN_LABEL);
  421. SetDlgItemText(IDC_SELECTDOMAIN_LABEL, csLabel);
  422. // Hide & Disable the Browse button for SiteRepl snapin
  423. (GetDlgItem(IDC_SELECTDOMAIN_BROWSE))->ShowWindow(SW_HIDE);
  424. (GetDlgItem(IDC_SELECTDOMAIN_BROWSE))->EnableWindow(FALSE);
  425. }
  426. return TRUE; // return TRUE unless you set the focus to a control
  427. // EXCEPTION: OCX Property Pages should return FALSE
  428. }
  429. void CChooseDomainDlg::DoContextHelp(HWND hWndControl)
  430. {
  431. if (hWndControl)
  432. {
  433. ::WinHelp(hWndControl,
  434. DSADMIN_CONTEXT_HELP_FILE,
  435. HELP_WM_HELP,
  436. (m_bSiteRepl) // 481964-JonN-2002/04/10
  437. ? (DWORD_PTR)(LPTSTR)g_aHelpIDs_IDD_SELECT_FOREST
  438. : (DWORD_PTR)(LPTSTR)g_aHelpIDs_IDD_SELECT_DOMAIN);
  439. }
  440. }
  441. /////////////////////////////////////////////////////////////////////////////
  442. // CChooseDCDlg dialog
  443. BEGIN_MESSAGE_MAP(CSelectDCEdit, CEdit)
  444. ON_WM_KILLFOCUS()
  445. END_MESSAGE_MAP()
  446. void CSelectDCEdit::OnKillFocus(CWnd* pNewWnd)
  447. {
  448. //
  449. // subclass the domain edit control.
  450. // When focus moves to OK/Cancel button, do not invoke
  451. // RefreshDCListView
  452. //
  453. // NTRAID#NTBUG9-472011-2001/10/22-JeffJon
  454. // Don't include the Browse button in this list because tabbing
  455. // from the edit control puts the focus on the Browse button
  456. m_bHandleKillFocus = TRUE;
  457. if (pNewWnd)
  458. {
  459. int id = pNewWnd->GetDlgCtrlID();
  460. if (id == IDOK ||
  461. id == IDCANCEL)
  462. {
  463. m_bHandleKillFocus = FALSE;
  464. }
  465. }
  466. CEdit::OnKillFocus(pNewWnd);
  467. }
  468. CChooseDCDlg::CChooseDCDlg(CWnd* pParent /*=NULL*/)
  469. : CHelpDialog(CChooseDCDlg::IDD, pParent)
  470. {
  471. //{{AFX_DATA_INIT(CChooseDCDlg)
  472. m_csTargetDomainController = _T("");
  473. m_csTargetDomain = _T("");
  474. //}}AFX_DATA_INIT
  475. m_csPrevDomain = _T("");
  476. m_pDCBufferManager = NULL;
  477. m_csAnyDC.LoadString(IDS_ANY_DOMAIN_CONTROLLER);
  478. m_csWaiting.LoadString(IDS_WAITING);
  479. m_csError.LoadString(IDS_ERROR);
  480. }
  481. CChooseDCDlg::~CChooseDCDlg()
  482. {
  483. TRACE(_T("CChooseDCDlg::~CChooseDCDlg\n"));
  484. if (m_pDCBufferManager)
  485. {
  486. //
  487. // signal all related running threads to terminate
  488. //
  489. m_pDCBufferManager->SignalExit();
  490. //
  491. // decrement the reference count on the CDCBufferManager instance
  492. //
  493. m_pDCBufferManager->Release();
  494. }
  495. }
  496. void CChooseDCDlg::DoDataExchange(CDataExchange* pDX)
  497. {
  498. CHelpDialog::DoDataExchange(pDX);
  499. //{{AFX_DATA_MAP(CChooseDCDlg)
  500. DDX_Control(pDX, IDC_SELECTDC_DCLISTVIEW, m_hDCListView);
  501. DDX_Text(pDX, IDC_SELECTDC_DCEDIT, m_csTargetDomainController);
  502. DDX_Text(pDX, IDC_SELECTDC_DOMAIN, m_csTargetDomain);
  503. //}}AFX_DATA_MAP
  504. }
  505. BEGIN_MESSAGE_MAP(CChooseDCDlg, CHelpDialog)
  506. //{{AFX_MSG_MAP(CChooseDCDlg)
  507. ON_NOTIFY(LVN_ITEMCHANGED, IDC_SELECTDC_DCLISTVIEW, OnItemchangedSelectdcDCListView)
  508. ON_EN_KILLFOCUS(IDC_SELECTDC_DOMAIN, OnKillfocusSelectdcDomain)
  509. ON_BN_CLICKED(IDC_SELECTDC_BROWSE, OnSelectdcBrowse)
  510. ON_NOTIFY(LVN_COLUMNCLICK, IDC_SELECTDC_DCLISTVIEW, OnColumnclickSelectdcDCListView)
  511. //}}AFX_MSG_MAP
  512. ON_MESSAGE(WM_USER_GETDC_THREAD_DONE, OnGetDCThreadDone)
  513. END_MESSAGE_MAP()
  514. /////////////////////////////////////////////////////////////////////////////
  515. // CChooseDCDlg message handlers
  516. typedef struct _DCListViewItem
  517. {
  518. CString csName;
  519. CString csSite;
  520. } DCLISTVIEWITEM;
  521. BOOL CChooseDCDlg::OnInitDialog()
  522. {
  523. CHelpDialog::OnInitDialog();
  524. //
  525. // sub-class the domain edit control, in order to intercept WM_KILLFOCUS
  526. // if the new focus will be set on Cancel button, don't process
  527. // EN_KILLFOCUS (i.e., don't start the thread to refresh DC list view )
  528. //
  529. VERIFY(m_selectDCEdit.SubclassDlgItem(IDC_SELECTDC_DOMAIN, this));
  530. // Limit the text to DNS_MAX_NAME_LENGTH
  531. m_selectDCEdit.SetLimitText(DNS_MAX_NAME_LENGTH);
  532. SendDlgItemMessage(IDC_SELECTDC_DCEDIT, EM_SETLIMITTEXT, DNS_MAX_NAME_LENGTH, 0);
  533. //
  534. // create instance of CDCBufferManager
  535. // m_pDCBufferManager will be set to NULL if CreateInstance() failed.
  536. //
  537. (void) CDCBufferManager::CreateInstance(m_hWnd, &m_pDCBufferManager);
  538. //
  539. // display currently targeted domain controller
  540. //
  541. SetDlgItemText(IDC_SELECTDC_DCEDIT_TITLE, m_csTargetDomainController);
  542. //
  543. // calculate the listview column width
  544. //
  545. RECT rect;
  546. ZeroMemory(&rect, sizeof(rect));
  547. (GetDlgItem(IDC_SELECTDC_DCLISTVIEW))->GetWindowRect(&rect);
  548. int nControlWidth = rect.right - rect.left;
  549. int nVScrollbarWidth = GetSystemMetrics(SM_CXVSCROLL);
  550. int nBorderWidth = GetSystemMetrics(SM_CXBORDER);
  551. int nControlNetWidth = nControlWidth - nVScrollbarWidth - 4 * nBorderWidth;
  552. int nWidth1 = nControlNetWidth / 2;
  553. int nWidth2 = nControlNetWidth - nWidth1;
  554. //
  555. // insert two columns of DC list view
  556. //
  557. LV_COLUMN col;
  558. CString cstrText;
  559. ZeroMemory(&col, sizeof(col));
  560. col.mask = LVCF_TEXT | LVCF_WIDTH;
  561. col.cx = nWidth1;
  562. cstrText.LoadString(IDS_SELECTDC_DCLISTVIEW_NAME);
  563. col.pszText = const_cast<LPTSTR>(static_cast<LPCTSTR>(cstrText));
  564. ListView_InsertColumn(m_hDCListView, 0, &col);
  565. col.cx = nWidth2;
  566. cstrText.LoadString(IDS_SELECTDC_DCLISTVIEW_SITE);
  567. col.pszText = const_cast<LPTSTR>(static_cast<LPCTSTR>(cstrText));
  568. ListView_InsertColumn(m_hDCListView, 1, &col);
  569. //
  570. // Set full row selection style
  571. //
  572. ListView_SetExtendedListViewStyleEx(m_hDCListView, LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);
  573. //
  574. // disable the list view control
  575. // In case we failed to create a CDCBufferManager instance, user can
  576. // still use this dialog to type in a domain name and a DC name.
  577. //
  578. m_hDCListView.EnableWindow(FALSE);
  579. //
  580. // insert items into DC list view
  581. //
  582. (void) RefreshDCListView();
  583. if (!m_bSiteRepl)
  584. {
  585. //
  586. // Disable domain edit box and hide&disable Browse button for non-siterepl snapins
  587. //
  588. (reinterpret_cast<CEdit *>(GetDlgItem(IDC_SELECTDC_DOMAIN)))->SetReadOnly(TRUE);
  589. (GetDlgItem(IDC_SELECTDC_BROWSE))->ShowWindow(SW_HIDE);
  590. (GetDlgItem(IDC_SELECTDC_BROWSE))->EnableWindow(FALSE);
  591. //
  592. // for non-siterepl snapins, set focus to the DC edit box;
  593. // for siterepl snapin, the focus will be set on the domain edit box.
  594. //
  595. (GetDlgItem(IDC_SELECTDC_DCEDIT))->SetFocus();
  596. return FALSE;
  597. }
  598. return TRUE;
  599. // return TRUE unless you set the focus to a control
  600. // EXCEPTION: OCX Property Pages should return FALSE
  601. }
  602. int CALLBACK ListViewCompareProc(
  603. IN LPARAM lParam1,
  604. IN LPARAM lParam2,
  605. IN LPARAM lParamSort)
  606. {
  607. DCLISTVIEWITEM *pItem1 = (DCLISTVIEWITEM *)lParam1;
  608. DCLISTVIEWITEM *pItem2 = (DCLISTVIEWITEM *)lParam2;
  609. int iResult = 0;
  610. if (pItem1 && pItem2)
  611. {
  612. switch( lParamSort)
  613. {
  614. case 0: // Sort by Name.
  615. iResult = pItem1->csName.CompareNoCase(pItem2->csName);
  616. break;
  617. case 1: // Sort by Site.
  618. iResult = pItem1->csSite.CompareNoCase(pItem2->csSite);
  619. break;
  620. default:
  621. iResult = 0;
  622. break;
  623. }
  624. }
  625. return(iResult);
  626. }
  627. void CChooseDCDlg::OnColumnclickSelectdcDCListView(NMHDR* pNMHDR, LRESULT* pResult)
  628. {
  629. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  630. ListView_SortItems( m_hDCListView,
  631. ListViewCompareProc,
  632. (LPARAM)(pNMListView->iSubItem));
  633. *pResult = 0;
  634. }
  635. #define MAX_LENGTH_DCNAME 1024
  636. void CChooseDCDlg::OnItemchangedSelectdcDCListView(NMHDR* pNMHDR, LRESULT* pResult)
  637. {
  638. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  639. //
  640. // set DC edit box to the currently selected item in the dc list view
  641. //
  642. if ( (pNMListView->uChanged & LVIF_STATE) &&
  643. (pNMListView->uNewState & LVIS_SELECTED) )
  644. {
  645. TCHAR pszBuffer[MAX_LENGTH_DCNAME];
  646. ListView_GetItemText(
  647. (GetDlgItem(IDC_SELECTDC_DCLISTVIEW))->GetSafeHwnd(),
  648. pNMListView->iItem,
  649. 0,
  650. pszBuffer,
  651. MAX_LENGTH_DCNAME * sizeof(TCHAR)
  652. );
  653. SetDlgItemText(IDC_SELECTDC_DCEDIT, pszBuffer);
  654. }
  655. *pResult = 0;
  656. }
  657. void CChooseDCDlg::OnKillfocusSelectdcDomain()
  658. {
  659. TRACE(_T("CChooseDCDlg::OnKillfocusSelectdcDomain\n"));
  660. //
  661. // when focus leaves domain edit box, refresh the items in the dc list view
  662. // we do this only for siterepl snapin whose domain edit box is enabled.
  663. //
  664. if (m_selectDCEdit.m_bHandleKillFocus)
  665. {
  666. if (m_bSiteRepl)
  667. (void) RefreshDCListView();
  668. }
  669. }
  670. void CChooseDCDlg::OnSelectdcBrowse()
  671. {
  672. CWaitCursor cwait;
  673. //
  674. // bring up the domain tree browse dialog
  675. //
  676. HRESULT hr = S_OK;
  677. LPTSTR lpszDomainDnsName = NULL;
  678. CString csDomainName, csDCName;
  679. GetDlgItemText(IDC_SELECTDC_DOMAIN, csDomainName);
  680. csDomainName.TrimLeft();
  681. csDomainName.TrimRight();
  682. if (!csDomainName.IsEmpty())
  683. hr = GetDCOfDomain(csDomainName, csDCName, FALSE);
  684. if (SUCCEEDED(hr))
  685. {
  686. hr = BrowseDomainTree(m_hWnd, csDCName, &lpszDomainDnsName);
  687. if ( FAILED(hr) &&
  688. !csDCName.IsEmpty() &&
  689. HRESULT_FROM_WIN32(RPC_S_SERVER_UNAVAILABLE) == hr )
  690. {
  691. // force the cached info in DsGetDcName to be refreshed
  692. hr = GetDCOfDomain(csDomainName, csDCName, TRUE);
  693. if (SUCCEEDED(hr))
  694. hr = BrowseDomainTree(m_hWnd, csDCName, &lpszDomainDnsName);
  695. }
  696. if ( (hr == S_OK) && lpszDomainDnsName )
  697. {
  698. SetDlgItemText(IDC_SELECTDC_DOMAIN, lpszDomainDnsName);
  699. CoTaskMemFree(lpszDomainDnsName);
  700. if (!RefreshDCListView())
  701. {
  702. SetDlgItemText(IDC_SELECTDC_DOMAIN, csDomainName);
  703. }
  704. }
  705. }
  706. // JonN 9/05/01 464466
  707. // After a fail to Locate Domain Controllers, Browse button repeatedly fails.
  708. else
  709. {
  710. SetDlgItemText(IDC_SELECTDC_DOMAIN, L"");
  711. }
  712. if (FAILED(hr)) {
  713. PVOID apv[1];
  714. apv[0] = static_cast<PVOID>(const_cast<LPTSTR>(static_cast<LPCTSTR>(csDomainName)));
  715. ReportErrorEx(m_hWnd,IDS_CANT_BROWSE_DOMAIN, hr,
  716. MB_OK | MB_ICONERROR, apv, 1, 0);
  717. }
  718. GetDlgItem(IDC_SELECTDC_DOMAIN)->SetFocus();
  719. }
  720. void CChooseDCDlg::OnOK()
  721. {
  722. TRACE(_T("CChooseDCDlg::OnOK\n"));
  723. CWaitCursor wait;
  724. HRESULT hr = S_OK;
  725. CString csDnsForSelectedDomain;
  726. CString csDnsForCurrentForest, csDnsForSelectedForest;
  727. if (m_bSiteRepl)
  728. {
  729. hr = GetDnsNameOfDomainOrForest(
  730. m_csTargetDomain,
  731. csDnsForCurrentForest,
  732. TRUE,
  733. FALSE); // get forest name
  734. if (csDnsForCurrentForest.IsEmpty())
  735. csDnsForCurrentForest = m_csTargetDomain;
  736. }
  737. //
  738. // Validate contents in the DC edit box
  739. //
  740. CString csDCEdit;
  741. GetDlgItemText(IDC_SELECTDC_DCEDIT, csDCEdit);
  742. // treat empty csDCEdit as same as m_csAnyDC
  743. if (!csDCEdit.IsEmpty() && m_csAnyDC.CompareNoCase(csDCEdit))
  744. {
  745. hr = GetDnsNameOfDomainOrForest(
  746. csDCEdit,
  747. csDnsForSelectedDomain,
  748. FALSE,
  749. TRUE); // get domain name
  750. if (SUCCEEDED(hr) && m_bSiteRepl)
  751. {
  752. hr = GetDnsNameOfDomainOrForest(
  753. csDCEdit,
  754. csDnsForSelectedForest,
  755. FALSE,
  756. FALSE); // get forest name
  757. }
  758. if (csDnsForSelectedDomain.IsEmpty() || (m_bSiteRepl && csDnsForSelectedForest.IsEmpty()) )
  759. {
  760. PVOID apv[1];
  761. apv[0] = static_cast<PVOID>(const_cast<LPTSTR>(static_cast<LPCTSTR>(csDCEdit)));
  762. if (FAILED(hr))
  763. // JonN 12/5/01 500074 TryADsIErrors = FALSE
  764. ReportErrorEx(m_hWnd, IDS_SELECTDC_INCORRECT_DC_DUETO, hr,
  765. MB_OK | MB_ICONSTOP, apv, 1, 0, FALSE);
  766. else
  767. // JonN 12/5/01 500074 TryADsIErrors = FALSE
  768. ReportMessageEx(m_hWnd, IDS_SELECTDC_DOWNLEVEL_DC,
  769. MB_OK | MB_ICONSTOP, apv, 1, 0, FALSE);
  770. (GetDlgItem(IDC_SELECTDC_DCEDIT))->SetFocus();
  771. return;
  772. }
  773. } else
  774. {
  775. //
  776. // Validate contents in the domain edit box
  777. //
  778. CString csDomain;
  779. GetDlgItemText(IDC_SELECTDC_DOMAIN, csDomain);
  780. if (csDomain.IsEmpty())
  781. {
  782. ReportMessageEx(m_hWnd, IDS_INCORRECT_INPUT,
  783. MB_OK | MB_ICONSTOP);
  784. (GetDlgItem(IDC_SELECTDC_DOMAIN))->SetFocus();
  785. return;
  786. }
  787. hr = GetDnsNameOfDomainOrForest(
  788. csDomain,
  789. csDnsForSelectedDomain,
  790. TRUE,
  791. TRUE); // get domain name
  792. if (SUCCEEDED(hr) && m_bSiteRepl)
  793. {
  794. hr = GetDnsNameOfDomainOrForest(
  795. csDomain,
  796. csDnsForSelectedForest,
  797. TRUE,
  798. FALSE); // get forest name
  799. }
  800. if (csDnsForSelectedDomain.IsEmpty() || (m_bSiteRepl && csDnsForSelectedForest.IsEmpty()) )
  801. {
  802. PVOID apv[1];
  803. apv[0] = static_cast<PVOID>(const_cast<LPTSTR>(static_cast<LPCTSTR>(csDomain)));
  804. if (FAILED(hr))
  805. ReportErrorEx(m_hWnd, IDS_SELECTDC_INCORRECT_DOMAIN_DUETO, hr,
  806. MB_OK | MB_ICONSTOP, apv, 1, 0, FALSE);
  807. else
  808. ReportMessageEx(m_hWnd, IDS_SELECTDC_DOWNLEVEL_DOMAIN,
  809. MB_OK | MB_ICONSTOP, apv, 1, 0, FALSE);
  810. SetDlgItemText(IDC_SELECTDC_DOMAIN, _T(""));
  811. (GetDlgItem(IDC_SELECTDC_DOMAIN))->SetFocus();
  812. return;
  813. }
  814. }
  815. //
  816. // if the current selected forest/domain does not belong to the current administering forest/domain,
  817. // ask user if he really wants to administer the selected forest/domain
  818. // via the selected DC (or any writable DC)?
  819. //
  820. if ( (m_bSiteRepl && csDnsForSelectedForest.CompareNoCase(csDnsForCurrentForest)) ||
  821. (!m_bSiteRepl && csDnsForSelectedDomain.CompareNoCase(m_csTargetDomain)) )
  822. {
  823. int nArgs = 0;
  824. int id = 0;
  825. PVOID apv[3];
  826. apv[0] = static_cast<PVOID>(const_cast<LPTSTR>(static_cast<LPCTSTR>(m_bSiteRepl ? csDnsForCurrentForest : m_csTargetDomain)));
  827. apv[1] = static_cast<PVOID>(const_cast<LPTSTR>(static_cast<LPCTSTR>(m_bSiteRepl ? csDnsForSelectedForest : csDnsForSelectedDomain)));
  828. if (m_csAnyDC.CompareNoCase(csDCEdit))
  829. {
  830. nArgs = 3;
  831. apv[2] = static_cast<PVOID>(const_cast<LPTSTR>(static_cast<LPCTSTR>(csDCEdit)));
  832. id = (m_bSiteRepl ?
  833. IDS_SELECTDC_UNMATCHED_DC_DOMAIN_SITEREPL :
  834. IDS_SELECTDC_UNMATCHED_DC_DOMAIN);
  835. } else
  836. {
  837. nArgs = 2;
  838. id = (m_bSiteRepl ?
  839. IDS_SELECTDC_UNMATCHED_DC_DOMAIN_SITEREPL_ANY :
  840. IDS_SELECTDC_UNMATCHED_DC_DOMAIN_ANY);
  841. }
  842. if (IDYES != ReportMessageEx(m_hWnd, id, MB_YESNO, apv, nArgs))
  843. {
  844. (GetDlgItem(IDC_SELECTDC_DCEDIT))->SetFocus();
  845. return;
  846. }
  847. }
  848. //
  849. // When exiting from the dialog
  850. // use DNS domain name;
  851. // use blank string if "Any Writable DC"
  852. // clean list view control
  853. //
  854. SetDlgItemText(IDC_SELECTDC_DOMAIN, csDnsForSelectedDomain);
  855. if (0 == m_csAnyDC.CompareNoCase(csDCEdit))
  856. SetDlgItemText(IDC_SELECTDC_DCEDIT, _T(""));
  857. FreeDCItems(m_hDCListView);
  858. CHelpDialog::OnOK();
  859. }
  860. void CChooseDCDlg::OnCancel()
  861. {
  862. TRACE(_T("CChooseDCDlg::OnCancel\n"));
  863. //
  864. // When exiting from the dialog
  865. // clean list view control
  866. //
  867. FreeDCItems(m_hDCListView);
  868. CHelpDialog::OnCancel();
  869. }
  870. //+---------------------------------------------------------------------------
  871. //
  872. // Function: CChooseDCDlg::InsertSpecialMsg
  873. //
  874. // Synopsis: Insert "Waiting..." or "Error" into the list view control,
  875. // and disable the control to prevent it from being selected.
  876. //
  877. //----------------------------------------------------------------------------
  878. void
  879. CChooseDCDlg::InsertSpecialMsg(
  880. IN BOOL bWaiting
  881. )
  882. {
  883. LV_ITEM item;
  884. //
  885. // clear DC list view
  886. //
  887. FreeDCItems(m_hDCListView);
  888. ZeroMemory(&item, sizeof(item));
  889. item.mask = LVIF_TEXT;
  890. item.pszText = const_cast<LPTSTR>(
  891. static_cast<LPCTSTR>(bWaiting ? m_csWaiting: m_csError));
  892. ListView_InsertItem(m_hDCListView, &item);
  893. //
  894. // disable the list view to prevent user from clicking on "Waiting..."
  895. //
  896. m_hDCListView.EnableWindow(FALSE);
  897. }
  898. //+---------------------------------------------------------------------------
  899. //
  900. // Function: CChooseDCDlg::InsertDCListView
  901. //
  902. // Synopsis: Insert items into the list view control of the owner dialog.
  903. //
  904. //----------------------------------------------------------------------------
  905. HRESULT
  906. CChooseDCDlg::InsertDCListView(
  907. IN CDCSITEINFO *pEntry
  908. )
  909. {
  910. ASSERT(pEntry);
  911. DWORD cInfo = pEntry->GetNumOfInfo();
  912. PDS_DOMAIN_CONTROLLER_INFO_1 pDCInfo = pEntry->GetDCInfo();
  913. ASSERT(cInfo > 0);
  914. ASSERT(pDCInfo);
  915. LV_ITEM item;
  916. int index = 0;
  917. DCLISTVIEWITEM *pItem = NULL;
  918. DWORD dwErr = 0;
  919. //
  920. // clear DC list view
  921. //
  922. FreeDCItems(m_hDCListView);
  923. //
  924. // insert DC list view
  925. //
  926. ZeroMemory(&item, sizeof(item));
  927. item.mask = LVIF_TEXT | LVIF_PARAM;
  928. for (DWORD i=0; i<cInfo; i++)
  929. {
  930. //
  931. // Don't add NT4 BDCs to the list
  932. //
  933. if (!pDCInfo[i].fDsEnabled)
  934. {
  935. continue;
  936. }
  937. ASSERT(pDCInfo[i].NetbiosName || pDCInfo[i].DnsHostName);
  938. if (pDCInfo[i].DnsHostName)
  939. item.pszText = pDCInfo[i].DnsHostName;
  940. else
  941. item.pszText = pDCInfo[i].NetbiosName;
  942. pItem = new DCLISTVIEWITEM;
  943. if (!pItem)
  944. {
  945. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  946. break;
  947. }
  948. pItem->csName = item.pszText;
  949. if (pDCInfo[i].SiteName)
  950. pItem->csSite = pDCInfo[i].SiteName;
  951. else
  952. pItem->csSite = _T("");
  953. item.lParam = reinterpret_cast<LPARAM>(pItem);
  954. index = ListView_InsertItem(m_hDCListView, &item);
  955. ListView_SetItemText(m_hDCListView, index, 1,
  956. const_cast<LPTSTR>(static_cast<LPCTSTR>(pItem->csSite)));
  957. }
  958. if (ERROR_NOT_ENOUGH_MEMORY != dwErr)
  959. {
  960. // add "All writable domain controllers" into the list-view .
  961. item.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE;
  962. item.pszText = const_cast<LPTSTR>(static_cast<LPCTSTR>(m_csAnyDC));
  963. item.state = LVIS_FOCUSED | LVIS_SELECTED;
  964. pItem = new DCLISTVIEWITEM;
  965. if (!pItem)
  966. {
  967. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  968. } else
  969. {
  970. pItem->csName = _T(""); // always sorted as the top item
  971. pItem->csSite = _T("");
  972. item.lParam = reinterpret_cast<LPARAM>(pItem);
  973. index = ListView_InsertItem(m_hDCListView, &item);
  974. ListView_SetItemText(m_hDCListView, index, 1,
  975. const_cast<LPTSTR>(static_cast<LPCTSTR>(pItem->csSite)));
  976. }
  977. }
  978. if (ERROR_NOT_ENOUGH_MEMORY == dwErr)
  979. {
  980. FreeDCItems(m_hDCListView);
  981. return E_OUTOFMEMORY;
  982. }
  983. m_hDCListView.EnableWindow(TRUE);
  984. return S_OK;
  985. }
  986. void CChooseDCDlg::OnGetDCThreadDone(WPARAM wParam, LPARAM lParam)
  987. {
  988. ASSERT(m_pDCBufferManager);
  989. CDCSITEINFO* pEntry = reinterpret_cast<CDCSITEINFO*>(wParam);
  990. HRESULT hr = (HRESULT)lParam;
  991. ASSERT(pEntry);
  992. CString csDomain = pEntry->GetDomainName();
  993. CString csCurrentDomain;
  994. GetDlgItemText(IDC_SELECTDC_DOMAIN, csCurrentDomain);
  995. TRACE(_T("CChooseDCDlg::OnGetDCThreadDone targetDomain=%s, currentDomain=%s, hr=%x\n"),
  996. csDomain, csCurrentDomain, hr);
  997. if (csCurrentDomain.CompareNoCase(csDomain) == 0)
  998. {
  999. switch (pEntry->GetEntryType())
  1000. {
  1001. case BUFFER_ENTRY_TYPE_VALID:
  1002. hr = InsertDCListView(pEntry);
  1003. if (SUCCEEDED(hr))
  1004. break;
  1005. // fall through if error
  1006. case BUFFER_ENTRY_TYPE_ERROR:
  1007. RefreshDCListViewErrorReport(csDomain, hr);
  1008. break;
  1009. default:
  1010. ASSERT(FALSE);
  1011. break;
  1012. }
  1013. }
  1014. }
  1015. void CChooseDCDlg::RefreshDCListViewErrorReport(
  1016. IN PCTSTR pszDomainName,
  1017. IN HRESULT hr
  1018. )
  1019. {
  1020. PVOID apv[1];
  1021. apv[0] = static_cast<PVOID>(const_cast<PTSTR>(pszDomainName));
  1022. ReportErrorEx(m_hWnd, IDS_NO_DCS_FOUND, hr,
  1023. MB_OK | MB_ICONINFORMATION, apv, 1, 0);
  1024. InsertSpecialMsg(FALSE); // insert "Error"
  1025. if (m_bSiteRepl)
  1026. (GetDlgItem(IDC_SELECTDC_DOMAIN))->SetFocus();
  1027. else
  1028. (GetDlgItem(IDC_SELECTDC_DCEDIT))->SetFocus();
  1029. }
  1030. // JonN 9/05/01 464466
  1031. // After a fail to Locate Domain Controllers, Browse button repeatedly fails.
  1032. // return success/failure
  1033. bool CChooseDCDlg::RefreshDCListView()
  1034. {
  1035. CString csDomain;
  1036. GetDlgItemText(IDC_SELECTDC_DOMAIN, csDomain);
  1037. if ( csDomain.IsEmpty() ||
  1038. (0 == csDomain.CompareNoCase(m_csPrevDomain)) )
  1039. return true;
  1040. TRACE(_T("CChooseDCDlg::RefreshDCListView for %s\n"), csDomain);
  1041. //
  1042. // update m_csPrevDomain
  1043. // to prevent LoadInfo() from being invoked multiple times when
  1044. // a serial of WM_KILLFOCUS happening on the same DomainName
  1045. //
  1046. m_csPrevDomain = csDomain;
  1047. //
  1048. // clear dc edit box
  1049. //
  1050. SetDlgItemText(IDC_SELECTDC_DCEDIT, _T(""));
  1051. //NTRAID#NTBUG9-456420-2001/09/28-lucios
  1052. // removed the code to update the title of the lsit box
  1053. // that now is static.
  1054. if (m_pDCBufferManager)
  1055. {
  1056. //
  1057. // insert "Waiting..." into the list view control
  1058. //
  1059. InsertSpecialMsg(TRUE);
  1060. UpdateWindow();
  1061. CWaitCursor cwait;
  1062. //
  1063. // Make sure csDomain is a valid domain name
  1064. //
  1065. CString csSelectedDomainDns;
  1066. HRESULT hr = GetDnsNameOfDomainOrForest(
  1067. csDomain,
  1068. csSelectedDomainDns,
  1069. TRUE,
  1070. TRUE); // We're interested in domain name not forest name here
  1071. if (FAILED(hr))
  1072. {
  1073. RefreshDCListViewErrorReport(csDomain, hr);
  1074. return false;
  1075. }
  1076. if (csSelectedDomainDns.IsEmpty())
  1077. {
  1078. // down-level domain
  1079. PVOID apv[1];
  1080. apv[0] = static_cast<PVOID>(const_cast<LPTSTR>(static_cast<LPCTSTR>(csDomain)));
  1081. ReportMessageEx(m_hWnd, IDS_SELECTDC_DOWNLEVEL_DOMAIN,
  1082. MB_OK | MB_ICONSTOP, apv, 1);
  1083. InsertSpecialMsg(FALSE); // insert "Error"
  1084. (GetDlgItem(IDC_SELECTDC_DOMAIN))->SetFocus();
  1085. return false;
  1086. }
  1087. //
  1088. // start the thread to calculate a list of DCs in the current selected domain
  1089. //
  1090. CDCSITEINFO *pEntry = NULL;
  1091. hr = m_pDCBufferManager->LoadInfo(csSelectedDomainDns, &pEntry);
  1092. if (SUCCEEDED(hr))
  1093. {
  1094. //
  1095. // Either we get a valid ptr back (ie. data is ready), insert it;
  1096. // or, a thread is alreay in progress, wait until a THREAD_DONE message.
  1097. //
  1098. if (pEntry)
  1099. {
  1100. ASSERT(pEntry->GetEntryType() == BUFFER_ENTRY_TYPE_VALID);
  1101. hr = InsertDCListView(pEntry);
  1102. }
  1103. }
  1104. if (FAILED(hr))
  1105. {
  1106. RefreshDCListViewErrorReport(csSelectedDomainDns, hr);
  1107. return false;
  1108. }
  1109. }
  1110. return true;
  1111. }
  1112. //+---------------------------------------------------------------------------
  1113. //
  1114. // Function: CChooseDCDlg::FreeDCItems
  1115. //
  1116. // Synopsis: Clear the lParam associated with each item in the list view control.
  1117. // The lParam is needed to support column-sorting.
  1118. //
  1119. //----------------------------------------------------------------------------
  1120. void
  1121. CChooseDCDlg::FreeDCItems(CListCtrl& clv)
  1122. {
  1123. int index = -1;
  1124. LPARAM lParam = 0;
  1125. while ( -1 != (index = clv.GetNextItem(index, LVNI_ALL)) )
  1126. {
  1127. lParam = clv.GetItemData(index);
  1128. if (lParam)
  1129. delete ((DCLISTVIEWITEM *)lParam);
  1130. }
  1131. ListView_DeleteAllItems(clv.GetSafeHwnd());
  1132. }
  1133. void CChooseDCDlg::DoContextHelp(HWND hWndControl)
  1134. {
  1135. if (hWndControl)
  1136. {
  1137. ::WinHelp(hWndControl,
  1138. DSADMIN_CONTEXT_HELP_FILE,
  1139. HELP_WM_HELP,
  1140. (DWORD_PTR)(LPTSTR)g_aHelpIDs_IDD_SELECT_DC);
  1141. }
  1142. }
  1143. /////////////////////////////////////////////////////////////////////////
  1144. // CDsAdminChooseDCObj
  1145. STDMETHODIMP CDsAdminChooseDCObj::InvokeDialog(
  1146. /*IN*/ HWND hwndParent,
  1147. /*IN*/ LPCWSTR lpszTargetDomain,
  1148. /*IN*/ LPCWSTR lpszTargetDomainController,
  1149. /*IN*/ ULONG uFlags,
  1150. /*OUT*/ BSTR* bstrSelectedDC)
  1151. {
  1152. TRACE(L"CDsAdminChooseDCObj::InvokeDialog(\n");
  1153. TRACE(L" HWND hwndParent = 0x%x\n", hwndParent);
  1154. TRACE(L" LPCWSTR lpszTargetDomain = %s\n", lpszTargetDomain);
  1155. TRACE(L" LPCWSTR lpszTargetDomainController = %s\n", lpszTargetDomainController);
  1156. TRACE(L" ULONG uFlags = 0x%x\n", uFlags);
  1157. TRACE(L" BSTR* bstrSelectedDC = 0x%x)\n", bstrSelectedDC);
  1158. if (!::IsWindow(hwndParent) || (bstrSelectedDC == NULL))
  1159. {
  1160. TRACE(L"InvokeDialog() Failed, invalid arg.\n");
  1161. return E_INVALIDARG;
  1162. }
  1163. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1164. CThemeContextActivator activator;
  1165. CChooseDCDlg DCdlg(CWnd::FromHandle(hwndParent));
  1166. // load current bind info
  1167. DCdlg.m_bSiteRepl = TRUE;
  1168. DCdlg.m_csTargetDomain = lpszTargetDomain;
  1169. DCdlg.m_csTargetDomainController = lpszTargetDomainController;
  1170. //
  1171. // invoke the dialog
  1172. //
  1173. HRESULT hr = S_FALSE;
  1174. if (DCdlg.DoModal() == IDOK)
  1175. {
  1176. TRACE(L"DCdlg.DoModal() returned IDOK\n");
  1177. TRACE(L"DCdlg.m_csTargetDomainController = <%s>\n", (LPCWSTR)(DCdlg.m_csTargetDomainController));
  1178. TRACE(L"DCdlg.m_csTargetDomain = <%s>\n", (LPCWSTR)(DCdlg.m_csTargetDomain));
  1179. LPCWSTR lpsz = NULL;
  1180. if (DCdlg.m_csTargetDomainController.IsEmpty())
  1181. {
  1182. lpsz = DCdlg.m_csTargetDomain;
  1183. }
  1184. else
  1185. {
  1186. lpsz = DCdlg.m_csTargetDomainController;
  1187. }
  1188. *bstrSelectedDC = ::SysAllocString(lpsz);
  1189. TRACE(L"returning *bstrSelectedDC = <%s>\n", *bstrSelectedDC);
  1190. hr = S_OK;
  1191. }
  1192. TRACE(L"InvokeDialog() returning hr = 0x%x\n", hr);
  1193. return hr;
  1194. }
  1195. /////////////////////////////////////////////////////////////////////////////
  1196. // CRenameUserDlg dialog
  1197. CRenameUserDlg::CRenameUserDlg(CDSComponentData* pComponentData, CWnd* pParent /*=NULL*/)
  1198. : m_pComponentData(pComponentData),
  1199. CHelpDialog(CRenameUserDlg::IDD, pParent)
  1200. {
  1201. //{{AFX_DATA_INIT(CRenameUserDlg)
  1202. m_login = _T("");
  1203. m_samaccountname = _T("");
  1204. m_domain = _T("");
  1205. m_dldomain = _T("");
  1206. m_first = _T("");
  1207. m_last = _T("");
  1208. m_cn = _T("");
  1209. m_oldcn = _T("");
  1210. m_displayname = _T("");
  1211. //}}AFX_DATA_INIT
  1212. }
  1213. void CRenameUserDlg::DoDataExchange(CDataExchange* pDX)
  1214. {
  1215. CHelpDialog::DoDataExchange(pDX);
  1216. //{{AFX_DATA_MAP(CRenameUserDlg)
  1217. DDX_Text(pDX, IDC_EDIT_OBJECT_NAME, m_cn);
  1218. DDX_Text(pDX, IDC_EDIT_DISPLAY_NAME, m_displayname);
  1219. DDX_Text(pDX, IDC_FIRST_NAME_EDIT, m_first);
  1220. DDX_Text(pDX, IDC_LAST_NAME_EDIT, m_last);
  1221. DDX_Text(pDX, IDC_NT5_USER_EDIT, m_login);
  1222. DDX_Text(pDX, IDC_NT4_USER_EDIT, m_samaccountname);
  1223. DDX_Text(pDX, IDC_NT4_DOMAIN_EDIT, m_dldomain);
  1224. DDX_CBString(pDX, IDC_NT5_DOMAIN_COMBO, m_domain);
  1225. //}}AFX_DATA_MAP
  1226. }
  1227. BEGIN_MESSAGE_MAP(CRenameUserDlg, CHelpDialog)
  1228. //{{AFX_MSG_MAP(CRenameUserDlg)
  1229. ON_EN_CHANGE(IDC_EDIT_OBJECT_NAME, OnObjectNameChange)
  1230. ON_EN_CHANGE(IDC_FIRST_NAME_EDIT, OnNameChange)
  1231. ON_EN_CHANGE(IDC_LAST_NAME_EDIT, OnNameChange)
  1232. ON_EN_CHANGE(IDC_NT5_USER_EDIT, OnUserNameChange)
  1233. //}}AFX_MSG_MAP
  1234. END_MESSAGE_MAP()
  1235. /////////////////////////////////////////////////////////////////////////////
  1236. // CRenameUserDlg message handlers
  1237. BOOL CRenameUserDlg::OnInitDialog()
  1238. {
  1239. CHelpDialog::OnInitDialog();
  1240. CString csdomain;
  1241. CComboBox* combobox = (CComboBox*)GetDlgItem (IDC_NT5_DOMAIN_COMBO);
  1242. ASSERT(combobox);
  1243. m_nameFormatter.Initialize(m_pComponentData->GetBasePathsInfo(),
  1244. L"user");
  1245. combobox->AddString (m_domain);
  1246. combobox->SetCurSel(0);
  1247. POSITION pos = m_domains.GetHeadPosition();
  1248. while (pos != NULL) {
  1249. csdomain = m_domains.GetNext(INOUT pos);
  1250. // since we added the UPN suffix for the user above, don't add it
  1251. // again
  1252. if (m_domain != csdomain)
  1253. {
  1254. combobox->AddString (csdomain);
  1255. }
  1256. }
  1257. UpdateComboBoxDropWidth(combobox);
  1258. ((CEdit *)GetDlgItem(IDC_EDIT_OBJECT_NAME))->SetLimitText(64);
  1259. ((CEdit *)GetDlgItem(IDC_FIRST_NAME_EDIT))->SetLimitText(64);
  1260. ((CEdit *)GetDlgItem(IDC_LAST_NAME_EDIT))->SetLimitText(64);
  1261. ((CEdit *)GetDlgItem(IDC_EDIT_DISPLAY_NAME))->SetLimitText(259);
  1262. ((CEdit *)GetDlgItem(IDC_NT4_USER_EDIT))->SetLimitText(MAX_NT4_LOGON_LENGTH);
  1263. CString szObjectName;
  1264. GetDlgItemText(IDC_EDIT_OBJECT_NAME, szObjectName);
  1265. szObjectName.TrimLeft();
  1266. szObjectName.TrimRight();
  1267. if (szObjectName.IsEmpty())
  1268. {
  1269. GetDlgItem(IDOK)->EnableWindow(FALSE);
  1270. }
  1271. return TRUE; // return TRUE unless you set the focus to a control
  1272. // EXCEPTION: OCX Property Pages should return FALSE
  1273. }
  1274. void
  1275. CRenameUserDlg::UpdateComboBoxDropWidth(CComboBox* comboBox)
  1276. {
  1277. if (!comboBox)
  1278. {
  1279. ASSERT(comboBox);
  1280. return;
  1281. }
  1282. int nHorzExtent = 0;
  1283. CClientDC dc(comboBox);
  1284. int nItems = comboBox->GetCount();
  1285. for (int i=0; i < nItems; i++)
  1286. {
  1287. CString szBuffer;
  1288. comboBox->GetLBText(i, szBuffer);
  1289. CSize ext = dc.GetTextExtent(szBuffer,szBuffer.GetLength());
  1290. nHorzExtent = max(ext.cx ,nHorzExtent);
  1291. }
  1292. comboBox->SetDroppedWidth(nHorzExtent);
  1293. }
  1294. void CRenameUserDlg::OnObjectNameChange()
  1295. {
  1296. CString szObjectName;
  1297. GetDlgItemText(IDC_EDIT_OBJECT_NAME, szObjectName);
  1298. szObjectName.TrimLeft();
  1299. szObjectName.TrimRight();
  1300. if (szObjectName.IsEmpty())
  1301. {
  1302. GetDlgItem(IDOK)->EnableWindow(FALSE);
  1303. }
  1304. else
  1305. {
  1306. GetDlgItem(IDOK)->EnableWindow(TRUE);
  1307. }
  1308. }
  1309. void CRenameUserDlg::OnNameChange()
  1310. {
  1311. GetDlgItemText(IDC_EDIT_FIRST_NAME, OUT m_first);
  1312. GetDlgItemText(IDC_EDIT_LAST_NAME, OUT m_last);
  1313. m_first.TrimLeft();
  1314. m_first.TrimRight();
  1315. m_last.TrimLeft();
  1316. m_last.TrimRight();
  1317. m_nameFormatter.FormatName(m_cn,
  1318. m_first.IsEmpty() ? NULL : (LPCWSTR)m_first,
  1319. NULL,
  1320. m_last.IsEmpty() ? NULL : (LPCWSTR)m_last);
  1321. SetDlgItemText(IDC_EDIT_DISPLAY_NAME, m_cn);
  1322. }
  1323. void CRenameUserDlg::OnUserNameChange()
  1324. {
  1325. GetDlgItemText(IDC_NT5_USER_EDIT, m_login);
  1326. // NTRAID#NTBUG9-650931-2002/06/28-artm
  1327. CString samName = m_login.Left(MAX_NT4_LOGON_LENGTH);
  1328. SetDlgItemText(IDC_NT4_USER_EDIT, samName);
  1329. }
  1330. void CRenameUserDlg::DoContextHelp(HWND hWndControl)
  1331. {
  1332. if (hWndControl)
  1333. {
  1334. ::WinHelp(hWndControl,
  1335. DSADMIN_CONTEXT_HELP_FILE,
  1336. HELP_WM_HELP,
  1337. (DWORD_PTR)(LPTSTR)g_aHelpIDs_IDD_RENAME_USER);
  1338. }
  1339. }
  1340. /////////////////////////////////////////////////////////////////////////////
  1341. // CRenameGroupDlg message handlers
  1342. BOOL CRenameGroupDlg::OnInitDialog()
  1343. {
  1344. CHelpDialog::OnInitDialog();
  1345. ((CEdit *)GetDlgItem(IDC_EDIT_OBJECT_NAME))->SetLimitText(64);
  1346. ((CEdit *)GetDlgItem(IDC_NT4_USER_EDIT))->SetLimitText(m_samtextlimit);
  1347. return TRUE; // return TRUE unless you set the focus to a control
  1348. // EXCEPTION: OCX Property Pages should return FALSE
  1349. }
  1350. /////////////////////////////////////////////////////////////////////////////
  1351. // CRenameGroupDlg dialog
  1352. CRenameGroupDlg::CRenameGroupDlg(CWnd* pParent /*=NULL*/)
  1353. : CHelpDialog(CRenameGroupDlg::IDD, pParent)
  1354. {
  1355. //{{AFX_DATA_INIT(CRenameGroupDlg)
  1356. m_samaccountname = _T("");
  1357. m_cn = _T("");
  1358. m_samtextlimit = 256;
  1359. //}}AFX_DATA_INIT
  1360. }
  1361. void CRenameGroupDlg::DoDataExchange(CDataExchange* pDX)
  1362. {
  1363. CHelpDialog::DoDataExchange(pDX);
  1364. //{{AFX_DATA_MAP(CRenameGroupDlg)
  1365. DDX_Text(pDX, IDC_NT4_USER_EDIT, m_samaccountname);
  1366. DDX_Text(pDX, IDC_EDIT_OBJECT_NAME, m_cn);
  1367. //}}AFX_DATA_MAP
  1368. }
  1369. BEGIN_MESSAGE_MAP(CRenameGroupDlg, CHelpDialog)
  1370. //{{AFX_MSG_MAP(CRenameGroupDlg)
  1371. //}}AFX_MSG_MAP
  1372. END_MESSAGE_MAP()
  1373. void CRenameGroupDlg::DoContextHelp(HWND hWndControl)
  1374. {
  1375. if (hWndControl)
  1376. {
  1377. ::WinHelp(hWndControl,
  1378. DSADMIN_CONTEXT_HELP_FILE,
  1379. HELP_WM_HELP,
  1380. (DWORD_PTR)(LPTSTR)g_aHelpIDs_IDD_RENAME_GROUP);
  1381. }
  1382. }
  1383. /////////////////////////////////////////////////////////////////////////////
  1384. // CRenameContactDlg message handlers
  1385. BOOL CRenameContactDlg::OnInitDialog()
  1386. {
  1387. CHelpDialog::OnInitDialog();
  1388. return TRUE; // return TRUE unless you set the focus to a control
  1389. // EXCEPTION: OCX Property Pages should return FALSE
  1390. }
  1391. void CRenameContactDlg::DoContextHelp(HWND hWndControl)
  1392. {
  1393. if (hWndControl)
  1394. {
  1395. ::WinHelp(hWndControl,
  1396. DSADMIN_CONTEXT_HELP_FILE,
  1397. HELP_WM_HELP,
  1398. (DWORD_PTR)(LPTSTR)g_aHelpIDs_IDD_RENAME_CONTACT);
  1399. }
  1400. }
  1401. /////////////////////////////////////////////////////////////////////////////
  1402. // CRenameContactDlg dialog
  1403. CRenameContactDlg::CRenameContactDlg(CWnd* pParent /*=NULL*/)
  1404. : CHelpDialog(CRenameContactDlg::IDD, pParent)
  1405. {
  1406. //{{AFX_DATA_INIT(CRenameContactDlg)
  1407. m_cn = _T("");
  1408. m_first = _T("");
  1409. m_last = _T("");
  1410. m_disp = _T("");
  1411. //}}AFX_DATA_INIT
  1412. }
  1413. void CRenameContactDlg::DoDataExchange(CDataExchange* pDX)
  1414. {
  1415. CHelpDialog::DoDataExchange(pDX);
  1416. //{{AFX_DATA_MAP(CRenameContactDlg)
  1417. DDX_Text(pDX, IDC_EDIT_OBJECT_NAME, m_cn);
  1418. DDX_Text(pDX, IDC_FIRST_NAME_EDIT, m_first);
  1419. DDX_Text(pDX, IDC_LAST_NAME_EDIT, m_last);
  1420. DDX_Text(pDX, IDC_DISP_NAME_EDIT, m_disp);
  1421. //}}AFX_DATA_MAP
  1422. }
  1423. BEGIN_MESSAGE_MAP(CRenameContactDlg, CHelpDialog)
  1424. //{{AFX_MSG_MAP(CRenameContactDlg)
  1425. //}}AFX_MSG_MAP
  1426. END_MESSAGE_MAP()
  1427. /////////////////////////////////////////////////////////////////////////////
  1428. // CRenameGenericDlg message handlers
  1429. BOOL CRenameGenericDlg::OnInitDialog()
  1430. {
  1431. CHelpDialog::OnInitDialog();
  1432. ((CEdit *)GetDlgItem(IDC_EDIT_OBJECT_NAME))->SetLimitText(64);
  1433. return TRUE; // return TRUE unless you set the focus to a control
  1434. // EXCEPTION: OCX Property Pages should return FALSE
  1435. }
  1436. /////////////////////////////////////////////////////////////////////////////
  1437. // CRenameGenericDlg dialog
  1438. CRenameGenericDlg::CRenameGenericDlg(CWnd* pParent /*=NULL*/)
  1439. : CHelpDialog(CRenameGenericDlg::IDD, pParent)
  1440. {
  1441. //{{AFX_DATA_INIT(CRenameGenericDlg)
  1442. m_cn = _T("");
  1443. //}}AFX_DATA_INIT
  1444. }
  1445. void CRenameGenericDlg::DoDataExchange(CDataExchange* pDX)
  1446. {
  1447. CHelpDialog::DoDataExchange(pDX);
  1448. //{{AFX_DATA_MAP(CRenameGenericDlg)
  1449. DDX_Text(pDX, IDC_EDIT_OBJECT_NAME, m_cn);
  1450. //}}AFX_DATA_MAP
  1451. }
  1452. BEGIN_MESSAGE_MAP(CRenameGenericDlg, CHelpDialog)
  1453. //{{AFX_MSG_MAP(CRenameGenericDlg)
  1454. //}}AFX_MSG_MAP
  1455. END_MESSAGE_MAP()
  1456. void CRenameGenericDlg::DoContextHelp(HWND hWndControl)
  1457. {
  1458. if (hWndControl)
  1459. {
  1460. ::WinHelp(hWndControl,
  1461. DSADMIN_CONTEXT_HELP_FILE,
  1462. HELP_WM_HELP,
  1463. (DWORD_PTR)(LPTSTR)g_aHelpIDs_IDD_RENAME_COMPUTER);
  1464. }
  1465. }
  1466. /////////////////////////////////////////////////////////////////////////////
  1467. // CSpecialMessageBox dialog
  1468. CSpecialMessageBox::CSpecialMessageBox(CWnd* pParent /*=NULL*/)
  1469. : CDialog(CSpecialMessageBox::IDD, pParent)
  1470. {
  1471. //{{AFX_DATA_INIT(CSpecialMessageBox)
  1472. m_title = _T("");
  1473. m_message = _T("");
  1474. //}}AFX_DATA_INIT
  1475. }
  1476. void CSpecialMessageBox::DoDataExchange(CDataExchange* pDX)
  1477. {
  1478. CDialog::DoDataExchange(pDX);
  1479. //{{AFX_DATA_MAP(CSpecialMessageBox)
  1480. DDX_Text(pDX, IDC_STATIC_MESSAGE, m_message);
  1481. //}}AFX_DATA_MAP
  1482. }
  1483. BEGIN_MESSAGE_MAP(CSpecialMessageBox, CDialog)
  1484. //{{AFX_MSG_MAP(CSpecialMessageBox)
  1485. ON_BN_CLICKED(IDC_BUTTON_YES, OnYesButton)
  1486. ON_BN_CLICKED(IDC_BUTTON_NO, OnNoButton)
  1487. ON_BN_CLICKED(IDC_BUTTON_YESTOALL, OnYesToAllButton)
  1488. //}}AFX_MSG_MAP
  1489. END_MESSAGE_MAP()
  1490. /////////////////////////////////////////////////////////////////////////////
  1491. // CSpecialMessageBox message handlers
  1492. BOOL CSpecialMessageBox::OnInitDialog()
  1493. {
  1494. CDialog::OnInitDialog();
  1495. if (!m_title.IsEmpty()) {
  1496. SetWindowText (m_title);
  1497. }
  1498. GetDlgItem(IDC_BUTTON_NO)->SetFocus();
  1499. return FALSE; // return TRUE unless you set the focus to a control
  1500. // EXCEPTION: OCX Property Pages should return FALSE
  1501. }
  1502. void
  1503. CSpecialMessageBox::OnYesButton()
  1504. {
  1505. CDialog::EndDialog (IDYES);
  1506. }
  1507. void
  1508. CSpecialMessageBox::OnNoButton()
  1509. {
  1510. CDialog::EndDialog (IDNO);
  1511. }
  1512. void
  1513. CSpecialMessageBox::OnYesToAllButton()
  1514. {
  1515. CDialog::EndDialog (IDC_BUTTON_YESTOALL);
  1516. }
  1517. #ifdef FIXUPDC
  1518. /////////////////////////////////////////////////////////////////////////////
  1519. // CFixupDC dialog
  1520. CFixupDC::CFixupDC(CWnd* pParent /*=NULL*/)
  1521. : CHelpDialog(CFixupDC::IDD, pParent)
  1522. {
  1523. //{{AFX_DATA_INIT(CFixupDC)
  1524. m_strServer = _T("");
  1525. //}}AFX_DATA_INIT
  1526. for (int i=0; i<NUM_FIXUP_OPTIONS; i++) {
  1527. m_bCheck[i] = FALSE;
  1528. }
  1529. }
  1530. void CFixupDC::DoDataExchange(CDataExchange* pDX)
  1531. {
  1532. CHelpDialog::DoDataExchange(pDX);
  1533. //{{AFX_DATA_MAP(CFixupDC)
  1534. DDX_Text(pDX, IDC_FIXUP_DC_SERVER, m_strServer);
  1535. //}}AFX_DATA_MAP
  1536. DDX_Check(pDX, IDC_FIXUP_DC_CHECK0, m_bCheck[0]);
  1537. DDX_Check(pDX, IDC_FIXUP_DC_CHECK1, m_bCheck[1]);
  1538. DDX_Check(pDX, IDC_FIXUP_DC_CHECK2, m_bCheck[2]);
  1539. DDX_Check(pDX, IDC_FIXUP_DC_CHECK3, m_bCheck[3]);
  1540. DDX_Check(pDX, IDC_FIXUP_DC_CHECK4, m_bCheck[4]);
  1541. DDX_Check(pDX, IDC_FIXUP_DC_CHECK5, m_bCheck[5]);
  1542. }
  1543. BEGIN_MESSAGE_MAP(CFixupDC, CHelpDialog)
  1544. //{{AFX_MSG_MAP(CFixupDC)
  1545. //}}AFX_MSG_MAP
  1546. END_MESSAGE_MAP()
  1547. /////////////////////////////////////////////////////////////////////////////
  1548. // CFixupDC message handlers
  1549. extern FixupOptionsMsg g_FixupOptionsMsg[];
  1550. BOOL CFixupDC::OnInitDialog()
  1551. {
  1552. CHelpDialog::OnInitDialog();
  1553. HWND hCheck = NULL;
  1554. GetDlgItem(IDC_FIXUP_DC_CHECK0, &hCheck);
  1555. ::SetFocus(hCheck);
  1556. for (int i=0; i<NUM_FIXUP_OPTIONS; i++)
  1557. m_bCheck[i] = g_FixupOptionsMsg[i].bDefaultOn;
  1558. UpdateData(FALSE);
  1559. return FALSE; // return TRUE unless you set the focus to a control
  1560. // EXCEPTION: OCX Property Pages should return FALSE
  1561. }
  1562. void CFixupDC::OnOK()
  1563. {
  1564. UpdateData(TRUE);
  1565. // make sure user has selected some checkboxes
  1566. BOOL bCheck = FALSE;
  1567. for (int i=0; !bCheck && (i<NUM_FIXUP_OPTIONS); i++) {
  1568. bCheck = bCheck || m_bCheck[i];
  1569. }
  1570. if (!bCheck)
  1571. {
  1572. ReportMessageEx(m_hWnd, IDS_FIXUP_DC_SELECTION_WARNING, MB_OK);
  1573. return;
  1574. }
  1575. CHelpDialog::OnOK();
  1576. }
  1577. void CFixupDC::DoContextHelp(HWND hWndControl)
  1578. {
  1579. if (hWndControl)
  1580. {
  1581. ::WinHelp(hWndControl,
  1582. DSADMIN_CONTEXT_HELP_FILE,
  1583. HELP_WM_HELP,
  1584. (DWORD_PTR)(LPTSTR)g_aHelpIDs_IDD_FIXUP_DC);
  1585. }
  1586. }
  1587. #endif // FIXUPDC
  1588. /////////////////////////////////////////////////////////////////////////////
  1589. // CPasswordDlg dialog
  1590. #ifdef FIXUPDC
  1591. // NOTICE-2002/04/12-artm
  1592. // When I was converting this class to use encrypted strings I noticed that
  1593. // it had no validation code to check that the length of the password <=
  1594. // MAX_PASSWORD_LENGTH.
  1595. //
  1596. // Further investigation revealed that the class is only used in code that is
  1597. // conditionally compiled in dssite.cpp, and in fact may never be compiled (b/c
  1598. // it needs work and the feature might not ever be released).
  1599. //
  1600. // Rather than spend unnecessary time understanding and fixing this I've
  1601. // used the same #ifdef to conditionally include it as the code that uses it.
  1602. //
  1603. // IF YOU NEED TO USE THIS class make sure you add password length validation
  1604. // code!
  1605. CPasswordDlg::CPasswordDlg(CWnd* pParent /*=NULL*/)
  1606. : CHelpDialog(CPasswordDlg::IDD, pParent),
  1607. m_password()
  1608. {
  1609. //{{AFX_DATA_INIT(CPasswordDlg)
  1610. m_strUserName = _T("");
  1611. //}}AFX_DATA_INIT
  1612. }
  1613. void CPasswordDlg::DoDataExchange(CDataExchange* pDX)
  1614. {
  1615. CHelpDialog::DoDataExchange(pDX);
  1616. //{{AFX_DATA_MAP(CPasswordDlg)
  1617. DDX_Text(pDX, IDC_USER_NAME, m_strUserName);
  1618. //}}AFX_DATA_MAP
  1619. DDX_EncryptedText(pDX, IDC_PASSWORD, m_password);
  1620. // Double check that password has not exceeded
  1621. // max length by someone removing validation code.
  1622. ASSERT(m_password.GetLength() <= MAX_PASSWORD_LENGTH);
  1623. }
  1624. BEGIN_MESSAGE_MAP(CPasswordDlg, CHelpDialog)
  1625. //{{AFX_MSG_MAP(CPasswordDlg)
  1626. //}}AFX_MSG_MAP
  1627. END_MESSAGE_MAP()
  1628. /////////////////////////////////////////////////////////////////////////////
  1629. // CPasswordDlg message handlers
  1630. void CPasswordDlg::OnOK()
  1631. {
  1632. UpdateData(TRUE);
  1633. if (m_strUserName.IsEmpty()) {
  1634. ReportMessageEx(m_hWnd, IDS_PASSWORD_DLG_WARNING, MB_OK);
  1635. return;
  1636. }
  1637. CHelpDialog::OnOK();
  1638. }
  1639. void CPasswordDlg::DoContextHelp(HWND hWndControl)
  1640. {
  1641. if (hWndControl)
  1642. {
  1643. ::WinHelp(hWndControl,
  1644. DSADMIN_CONTEXT_HELP_FILE,
  1645. HELP_WM_HELP,
  1646. (DWORD_PTR)(LPTSTR)g_aHelpIDs_IDD_PASSWORD);
  1647. }
  1648. }
  1649. #endif //FIXUPDC