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.

2482 lines
72 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: servwiz.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "preDNSsn.h"
  11. #include <SnapBase.h>
  12. #include "resource.h"
  13. #include "dnsutil.h"
  14. #include "DNSSnap.h"
  15. #include "snapdata.h"
  16. #include "server.h"
  17. #include "domain.h"
  18. #include "servwiz.h"
  19. #include "zone.h"
  20. #include "dnsmgr.h"
  21. #ifdef DEBUG_ALLOCATOR
  22. #ifdef _DEBUG
  23. #define new DEBUG_NEW
  24. #undef THIS_FILE
  25. static char THIS_FILE[] = __FILE__;
  26. #endif
  27. #endif
  28. //////////////////////////////////////////////////////////////////////
  29. // export function to be called from DC Promo
  30. STDAPI DnsSetup(LPCWSTR lpszFwdZoneName,
  31. LPCWSTR lpszFwdZoneFileName,
  32. LPCWSTR lpszRevZoneName,
  33. LPCWSTR lpszRevZoneFileName,
  34. DWORD dwFlags)
  35. {
  36. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  37. HRESULT hr = S_OK;
  38. IComponentData* pICD = NULL;
  39. //
  40. // create a dummy component data object:
  41. // need to have a proper contruction and destruction, so we behave
  42. // as a class factory would
  43. //
  44. CComObject<CDNSComponentDataObject>* pComponentData = NULL;
  45. CComObject<CDNSComponentDataObject>::CreateInstance(&pComponentData);
  46. //
  47. // Scoping so that the Log file will write exit function before
  48. // KillInstance is called
  49. //
  50. {
  51. TRACE_FUNCTION(DnsSetup);
  52. if (lpszFwdZoneName)
  53. {
  54. TRACE_LOGFILE(L"Forward Zone Name: %ws", lpszFwdZoneName);
  55. }
  56. else
  57. {
  58. TRACE_LOGFILE(L"Forward Zone Name: (null)");
  59. }
  60. if (lpszFwdZoneFileName)
  61. {
  62. TRACE_LOGFILE(L"Forward Zone File Name: %ws", lpszFwdZoneFileName);
  63. }
  64. else
  65. {
  66. TRACE_LOGFILE(L"Forward Zone File Name: (null)");
  67. }
  68. if (lpszRevZoneName)
  69. {
  70. TRACE_LOGFILE(L"Reverse Zone Name: %ws", lpszRevZoneName);
  71. }
  72. else
  73. {
  74. TRACE_LOGFILE(L"Reverse Zone Name: (null)");
  75. }
  76. if (lpszRevZoneFileName)
  77. {
  78. TRACE_LOGFILE(L"Reverse Zone File Name: %ws", lpszRevZoneFileName);
  79. }
  80. else
  81. {
  82. TRACE_LOGFILE(L"Reverse Zone File Name: (null)");
  83. }
  84. TRACE_LOGFILE(L"Flags: %d", dwFlags);
  85. ASSERT(pComponentData != NULL);
  86. if (pComponentData == NULL)
  87. {
  88. TRACE_LOGFILE(L"Failed to create and instance of CDNSComponentDataObject.");
  89. return E_OUTOFMEMORY;
  90. }
  91. hr = pComponentData->QueryInterface(IID_IComponentData, (void**)&pICD);
  92. if (FAILED(hr))
  93. {
  94. TRACE_LOGFILE(L"Failed QI on pComponentData for IID_IComponentData. return hr = 0x%x", hr);
  95. return hr;
  96. }
  97. ASSERT(pICD != NULL);
  98. //
  99. // get the root data node
  100. //
  101. CDNSRootData* pRootData = (CDNSRootData*)pComponentData->GetRootData();
  102. if (pRootData == NULL)
  103. {
  104. TRACE_LOGFILE(L"Failed to retrieve root data.");
  105. return E_FAIL;
  106. }
  107. ASSERT(pRootData != NULL);
  108. //
  109. // run the wizard
  110. //
  111. CDNSServerWizardHolder wiz(pRootData, pComponentData, NULL, /*bHideUI*/ TRUE);
  112. hr = wiz.DnsSetup(lpszFwdZoneName,
  113. lpszFwdZoneFileName,
  114. lpszRevZoneName,
  115. lpszRevZoneFileName,
  116. dwFlags);
  117. if (SUCCEEDED(hr))
  118. {
  119. TRACE_LOGFILE(L"DnsSetup completed successfully.");
  120. }
  121. else
  122. {
  123. TRACE_LOGFILE(L"An error occurred in DnsSetup, returning hr = 0x%x", hr);
  124. }
  125. }
  126. // final destruction
  127. pICD->Release();
  128. return hr;
  129. }
  130. //////////////////////////////////////////////////////////////////////
  131. void TraceRootHints(PDNS_RECORD pList)
  132. {
  133. PDNS_RECORD pCurrRec = pList;
  134. while (pCurrRec)
  135. {
  136. TRACE(_T("owner %s, type %d "), pCurrRec->pName, pCurrRec->wType);
  137. if (pCurrRec->wType == DNS_TYPE_NS)
  138. TRACE(_T("NS, host %s\n"), pCurrRec->Data.NS.pNameHost);
  139. else if (pCurrRec->wType == DNS_TYPE_A)
  140. {
  141. CString szTemp;
  142. FormatIpAddress(szTemp, pCurrRec->Data.A.IpAddress);
  143. TRACE(_T("A, IP %s\n"), (LPCTSTR)szTemp);
  144. }
  145. else
  146. TRACE(_T("\n"));
  147. pCurrRec = pCurrRec->pNext;
  148. }
  149. }
  150. ////////////////////////////////////////////////////////////////////////
  151. // CNewDialog
  152. class CNewServerDialog : public CHelpDialog
  153. {
  154. // Construction
  155. public:
  156. CNewServerDialog(CDNSServerWizardHolder* pHolder, CWnd* pParentWnd);
  157. BOOL m_bLocalMachine;
  158. BOOL m_bConfigure;
  159. // Dialog Data
  160. enum { IDD = IDD_CHOOSER_CHOOSE_MACHINE };
  161. CEdit m_serverNameCtrl;
  162. CString m_szServerName;
  163. // Implementation
  164. protected:
  165. // Generated message map functions
  166. virtual BOOL OnInitDialog();
  167. virtual void OnOK();
  168. afx_msg void OnEditChange();
  169. afx_msg void OnLocalMachineRadio();
  170. afx_msg void OnSpecificMachineRadio();
  171. DECLARE_MESSAGE_MAP()
  172. private:
  173. CDNSServerWizardHolder* m_pHolder;
  174. };
  175. BEGIN_MESSAGE_MAP(CNewServerDialog, CHelpDialog)
  176. ON_BN_CLICKED(IDC_CHOOSER_RADIO_LOCAL_MACHINE, OnLocalMachineRadio)
  177. ON_BN_CLICKED(IDC_CHOOSER_RADIO_SPECIFIC_MACHINE, OnSpecificMachineRadio)
  178. ON_EN_CHANGE(IDC_CHOOSER_EDIT_MACHINE_NAME,OnEditChange)
  179. END_MESSAGE_MAP()
  180. CNewServerDialog::CNewServerDialog(CDNSServerWizardHolder* pHolder, CWnd* pParentWnd)
  181. : CHelpDialog(CNewServerDialog::IDD, pParentWnd, pHolder->GetComponentData())
  182. {
  183. ASSERT(m_pHolder != NULL);
  184. m_pHolder = pHolder;
  185. m_bConfigure = TRUE;
  186. m_bLocalMachine = TRUE;
  187. }
  188. BOOL CNewServerDialog::OnInitDialog()
  189. {
  190. CHelpDialog::OnInitDialog();
  191. VERIFY(m_serverNameCtrl.SubclassDlgItem(IDC_CHOOSER_EDIT_MACHINE_NAME, this));
  192. CButton* pContactCheck = (CButton*)GetDlgItem(IDC_CHOOSER_CHECK_CONTACT);
  193. pContactCheck->SetCheck(m_bConfigure);
  194. //
  195. // Limit is actually 255 bytes but we will let 255 characters just to be safe
  196. //
  197. m_serverNameCtrl.SetLimitText(255);
  198. if (m_bLocalMachine)
  199. {
  200. ((CButton*)GetDlgItem(IDC_CHOOSER_RADIO_LOCAL_MACHINE))->SetCheck(TRUE);
  201. m_serverNameCtrl.EnableWindow(FALSE);
  202. }
  203. else
  204. {
  205. ((CButton*)GetDlgItem(IDC_CHOOSER_RADIO_SPECIFIC_MACHINE))->SetCheck(TRUE);
  206. GetDlgItem(IDOK)->EnableWindow(FALSE);
  207. }
  208. return TRUE; // return TRUE unless you set the focus to a control
  209. }
  210. void CNewServerDialog::OnLocalMachineRadio()
  211. {
  212. m_bLocalMachine = TRUE;
  213. m_serverNameCtrl.EnableWindow(FALSE);
  214. GetDlgItem(IDOK)->EnableWindow(TRUE);
  215. m_szServerName.Empty();
  216. }
  217. void CNewServerDialog::OnSpecificMachineRadio()
  218. {
  219. m_bLocalMachine = FALSE;
  220. m_serverNameCtrl.EnableWindow(TRUE);
  221. OnEditChange();
  222. }
  223. void CNewServerDialog::OnEditChange()
  224. {
  225. //
  226. // just check to be sure the editbox is not empty:
  227. //
  228. m_serverNameCtrl.GetWindowText(m_szServerName);
  229. m_szServerName.TrimLeft();
  230. m_szServerName.TrimRight();
  231. GetDlgItem(IDOK)->EnableWindow(!m_szServerName.IsEmpty());
  232. }
  233. void CNewServerDialog::OnOK()
  234. {
  235. CButton* pContactCheck = (CButton*)GetDlgItem(IDC_CHOOSER_CHECK_CONTACT);
  236. m_bConfigure = pContactCheck->GetCheck();
  237. BOOL bLocalHost = FALSE;
  238. if (m_bLocalMachine)
  239. {
  240. DWORD dwLen = MAX_COMPUTERNAME_LENGTH+1;
  241. BOOL bRes = ::GetComputerName(m_szServerName.GetBuffer(dwLen),
  242. &dwLen);
  243. ASSERT(dwLen <= MAX_COMPUTERNAME_LENGTH);
  244. m_szServerName.ReleaseBuffer();
  245. if (!bRes)
  246. {
  247. m_szServerName = _T("localhost.");
  248. }
  249. bLocalHost = TRUE;
  250. }
  251. else
  252. {
  253. m_serverNameCtrl.GetWindowText(m_szServerName);
  254. }
  255. CDNSRootData* pRootData = (CDNSRootData*)m_pHolder->GetRootData();
  256. if (!pRootData->VerifyServerName(m_szServerName))
  257. {
  258. // illegal name, warn the user and prompt again
  259. DNSMessageBox(IDS_DUPLICATE_SERVER, MB_OK | MB_ICONERROR);
  260. m_serverNameCtrl.SetSel(0,-1);
  261. m_serverNameCtrl.SetFocus();
  262. return;
  263. }
  264. m_pHolder->m_pServerNode->SetDisplayName(m_szServerName);
  265. m_pHolder->m_pServerNode->SetLocalServer(bLocalHost);
  266. if (m_bConfigure)
  267. {
  268. // try to contact server
  269. BOOL bAlreadyConfigured = FALSE;
  270. DWORD dwErr = m_pHolder->GetServerInfo(&bAlreadyConfigured, GetSafeHwnd());
  271. if (dwErr != 0)
  272. {
  273. CString szMessageFmt, szError, szMsg;
  274. szMessageFmt.LoadString(IDS_MSG_SERVWIZ_FAIL_CONTACT_ADD);
  275. if (dwErr == RPC_S_UNKNOWN_IF || dwErr == EPT_S_NOT_REGISTERED)
  276. {
  277. CString szResourceString;
  278. szResourceString.LoadString(IDS_MSG_SERVWIZ_NOT_NT5);
  279. szMsg.Format(szMessageFmt, szResourceString);
  280. }
  281. else
  282. {
  283. if (!CDNSErrorInfo::GetErrorString(dwErr, szError))
  284. {
  285. szError.Format(_T("Error 0x%x"), dwErr);
  286. }
  287. //
  288. // NTRAID#Windows Bugs-340841-2001/03/12-jeffjon : if the error
  289. // message already ends in a period we should remove it so that
  290. // the dialog only shows one
  291. //
  292. CString szPeriod;
  293. szPeriod.LoadString(IDS_PERIOD);
  294. if (szError.GetAt(szError.GetLength() - 1) == szPeriod)
  295. {
  296. szError.SetAt(szError.GetLength() - 1, L'\0');
  297. }
  298. szMsg.Format(szMessageFmt, (LPCTSTR)szError);
  299. }
  300. if (IDYES == DNSMessageBox(szMsg, MB_YESNO))
  301. {
  302. m_bConfigure = FALSE;
  303. }
  304. else
  305. {
  306. m_serverNameCtrl.SetSel(0,-1);
  307. m_serverNameCtrl.SetFocus();
  308. return; // maybe the user wants to change name...
  309. }
  310. }
  311. else
  312. {
  313. m_bConfigure = FALSE;
  314. }
  315. }
  316. if (!m_bConfigure)
  317. {
  318. m_pHolder->InsertServerIntoUI();
  319. }
  320. CHelpDialog::OnOK();
  321. }
  322. ///////////////////////////////////////////////////////////////////////////////
  323. // CDNSServerWiz_StartPropertyPage
  324. BEGIN_MESSAGE_MAP(CDNSServerWiz_StartPropertyPage, CPropertyPageBase)
  325. ON_BN_CLICKED(IDC_HELP_BUTTON, OnChecklist)
  326. END_MESSAGE_MAP()
  327. CDNSServerWiz_StartPropertyPage::CDNSServerWiz_StartPropertyPage()
  328. : CPropertyPageBase(CDNSServerWiz_StartPropertyPage::IDD)
  329. {
  330. InitWiz97(TRUE,0,0, true);
  331. }
  332. void CDNSServerWiz_StartPropertyPage::OnWizardHelp()
  333. {
  334. CComPtr<IDisplayHelp> spHelp;
  335. HRESULT hr = GetHolder()->GetComponentData()->GetConsole()->QueryInterface(IID_IDisplayHelp, (void **)&spHelp);
  336. if (SUCCEEDED(hr))
  337. spHelp->ShowTopic(L"DNSConcepts.chm::/sag_DNS_CYDNS_01.htm");
  338. }
  339. void CDNSServerWiz_StartPropertyPage::OnChecklist()
  340. {
  341. CComPtr<IDisplayHelp> spHelp;
  342. HRESULT hr = GetHolder()->GetComponentData()->GetConsole()->QueryInterface(IID_IDisplayHelp, (void **)&spHelp);
  343. if (SUCCEEDED(hr))
  344. spHelp->ShowTopic(L"DNSConcepts.chm::/sag_DNSChkConfig.htm");
  345. }
  346. BOOL CDNSServerWiz_StartPropertyPage::OnInitDialog()
  347. {
  348. CPropertyPageBase::OnInitDialog();
  349. SetBigBoldFont(m_hWnd, IDC_STATIC_WELCOME);
  350. return TRUE;
  351. }
  352. BOOL CDNSServerWiz_StartPropertyPage::OnSetActive()
  353. {
  354. GetHolder()->SetWizardButtonsFirst(TRUE);
  355. return TRUE;
  356. }
  357. LRESULT CDNSServerWiz_StartPropertyPage::OnWizardNext()
  358. {
  359. CDNSServerWizardHolder* pHolder = (CDNSServerWizardHolder*)GetHolder();
  360. UINT nNextPage = IDD; // default do not advance
  361. nNextPage = CDNSServerWiz_ScenarioPropertyPage::IDD;
  362. pHolder->m_pScenarioPage->m_nPrevPageID = IDD;
  363. return nNextPage;
  364. }
  365. ///////////////////////////////////////////////////////////////////////////////
  366. // CDNSServerWiz_ScenarioPropertyPage
  367. CDNSServerWiz_ScenarioPropertyPage::CDNSServerWiz_ScenarioPropertyPage()
  368. : CPropertyPageBase(CDNSServerWiz_ScenarioPropertyPage::IDD)
  369. {
  370. InitWiz97(FALSE,IDS_SERVWIZ_SCENARIO_TITLE,IDS_SERVWIZ_SCENARIO_SUBTITLE, true);
  371. }
  372. void CDNSServerWiz_ScenarioPropertyPage::OnWizardHelp()
  373. {
  374. CComPtr<IDisplayHelp> spHelp;
  375. HRESULT hr = GetHolder()->GetComponentData()->GetConsole()->QueryInterface(IID_IDisplayHelp, (void **)&spHelp);
  376. if (SUCCEEDED(hr))
  377. spHelp->ShowTopic(L"DNSConcepts.chm::/sag_DNS_CYDNS_02.htm");
  378. }
  379. BOOL CDNSServerWiz_ScenarioPropertyPage::OnInitDialog()
  380. {
  381. CPropertyPageBase::OnInitDialog();
  382. SendDlgItemMessage(IDC_SMALL_RADIO, BM_SETCHECK, BST_CHECKED, 0);
  383. return TRUE;
  384. }
  385. BOOL CDNSServerWiz_ScenarioPropertyPage::OnSetActive()
  386. {
  387. GetHolder()->SetWizardButtonsMiddle(TRUE);
  388. return TRUE;
  389. }
  390. LRESULT CDNSServerWiz_ScenarioPropertyPage::OnWizardNext()
  391. {
  392. CDNSServerWizardHolder* pHolder = (CDNSServerWizardHolder*)GetHolder();
  393. LRESULT lSmallRadioCheck = SendDlgItemMessage(IDC_SMALL_RADIO, BM_GETCHECK, 0, 0);
  394. LRESULT lMediumRadioCheck = SendDlgItemMessage(IDC_MEDIUM_RADIO, BM_GETCHECK, 0, 0);
  395. LRESULT lManuallyRadioCheck = SendDlgItemMessage(IDC_MANUALLY_RADIO, BM_GETCHECK, 0, 0);
  396. LRESULT nNextPage = 0;
  397. if (lSmallRadioCheck == BST_CHECKED)
  398. {
  399. nNextPage = CDNSServerWiz_SmallZoneTypePropertyPage::IDD;
  400. pHolder->m_pSmallZoneTypePage->m_nPrevPageID = IDD;
  401. pHolder->SetScenario(CDNSServerWizardHolder::SmallBusiness);
  402. }
  403. else if (lMediumRadioCheck == BST_CHECKED)
  404. {
  405. nNextPage = CDNSServerWiz_ConfigFwdZonePropertyPage::IDD;
  406. pHolder->m_pFwdZonePage->m_nPrevPageID = IDD;
  407. pHolder->SetScenario(CDNSServerWizardHolder::MediumBusiness);
  408. }
  409. else if (lManuallyRadioCheck == BST_CHECKED)
  410. {
  411. if (pHolder->QueryForRootServerRecords(NULL))
  412. {
  413. pHolder->m_bAddRootHints = TRUE;
  414. }
  415. nNextPage = CDNSServerWiz_FinishPropertyPage::IDD;
  416. pHolder->m_pFinishPage->m_nPrevPageID = IDD;
  417. pHolder->SetScenario(CDNSServerWizardHolder::Manually);
  418. }
  419. else
  420. {
  421. //
  422. // This shouldn't happen, don't change the page if it does
  423. //
  424. nNextPage = IDD;
  425. }
  426. return nNextPage;
  427. }
  428. LRESULT CDNSServerWiz_ScenarioPropertyPage::OnWizardBack()
  429. {
  430. return (LRESULT)m_nPrevPageID;
  431. }
  432. ///////////////////////////////////////////////////////////////////////////////
  433. // CDNSServerWiz_ForwardersPropertyPage
  434. BEGIN_MESSAGE_MAP(CDNSServerWiz_ForwardersPropertyPage, CPropertyPageBase)
  435. ON_BN_CLICKED(IDC_FORWARD_RADIO, OnChangeRadio)
  436. ON_BN_CLICKED(IDC_NO_FORWARDERS_RADIO, OnChangeRadio)
  437. ON_EN_CHANGE(IDC_IPEDIT, OnChangeRadio)
  438. END_MESSAGE_MAP()
  439. CDNSServerWiz_ForwardersPropertyPage::CDNSServerWiz_ForwardersPropertyPage()
  440. : CPropertyPageBase(CDNSServerWiz_ForwardersPropertyPage::IDD)
  441. {
  442. InitWiz97(FALSE,IDS_SERVWIZ_FORWARDERS_TITLE,IDS_SERVWIZ_FORWARDERS_SUBTITLE, true);
  443. }
  444. void CDNSServerWiz_ForwardersPropertyPage::OnWizardHelp()
  445. {
  446. CComPtr<IDisplayHelp> spHelp;
  447. HRESULT hr = GetHolder()->GetComponentData()->GetConsole()->QueryInterface(IID_IDisplayHelp, (void **)&spHelp);
  448. if (SUCCEEDED(hr))
  449. spHelp->ShowTopic(L"DNSConcepts.chm::/sag_DNS_CYDNS_07.htm");
  450. }
  451. BOOL CDNSServerWiz_ForwardersPropertyPage::OnInitDialog()
  452. {
  453. CPropertyPageBase::OnInitDialog();
  454. CDNSServerWizardHolder* pHolder = (CDNSServerWizardHolder*)GetHolder();
  455. if (pHolder != NULL)
  456. {
  457. UINT nScenario = pHolder->GetScenario();
  458. if (nScenario == CDNSServerWizardHolder::SmallBusiness)
  459. {
  460. SendDlgItemMessage(IDC_FORWARD_RADIO, BM_SETCHECK, BST_CHECKED, 0);
  461. SendDlgItemMessage(IDC_NO_FORWARDERS_RADIO, BM_SETCHECK, BST_UNCHECKED, 0);
  462. }
  463. else
  464. {
  465. SendDlgItemMessage(IDC_NO_FORWARDERS_RADIO, BM_SETCHECK, BST_CHECKED, 0);
  466. SendDlgItemMessage(IDC_FORWARD_RADIO, BM_SETCHECK, BST_UNCHECKED, 0);
  467. }
  468. }
  469. else
  470. {
  471. SendDlgItemMessage(IDC_FORWARD_RADIO, BM_SETCHECK, BST_CHECKED, 0);
  472. SendDlgItemMessage(IDC_NO_FORWARDERS_RADIO, BM_SETCHECK, BST_UNCHECKED, 0);
  473. }
  474. return TRUE;
  475. }
  476. void CDNSServerWiz_ForwardersPropertyPage::OnChangeRadio()
  477. {
  478. LRESULT lForwarderRadio = SendDlgItemMessage(IDC_FORWARD_RADIO, BM_GETCHECK, 0, 0);
  479. if (lForwarderRadio == BST_CHECKED)
  480. {
  481. GetDlgItem(IDC_IPEDIT)->EnableWindow(TRUE);
  482. GetDlgItem(IDC_IPEDIT2)->EnableWindow(TRUE);
  483. CDNSIPv4Control* pForwarderCtrl = (CDNSIPv4Control*)GetDlgItem(IDC_IPEDIT);
  484. if (pForwarderCtrl->IsEmpty())
  485. {
  486. GetHolder()->SetWizardButtonsMiddle(FALSE);
  487. }
  488. else
  489. {
  490. GetHolder()->SetWizardButtonsMiddle(TRUE);
  491. }
  492. }
  493. else
  494. {
  495. GetDlgItem(IDC_IPEDIT)->EnableWindow(FALSE);
  496. GetDlgItem(IDC_IPEDIT2)->EnableWindow(FALSE);
  497. GetHolder()->SetWizardButtonsMiddle(TRUE);
  498. }
  499. }
  500. BOOL CDNSServerWiz_ForwardersPropertyPage::OnSetActive()
  501. {
  502. GetHolder()->SetWizardButtonsMiddle(TRUE);
  503. OnChangeRadio();
  504. return TRUE;
  505. }
  506. LRESULT CDNSServerWiz_ForwardersPropertyPage::OnWizardNext()
  507. {
  508. CDNSServerWizardHolder* pHolder = (CDNSServerWizardHolder*)GetHolder();
  509. LRESULT nNextPage = -1;
  510. LRESULT lCheck = SendDlgItemMessage(IDC_FORWARD_RADIO, BM_GETCHECK, 0, 0);
  511. if (lCheck == BST_CHECKED)
  512. {
  513. pHolder->m_bAddForwarder = TRUE;
  514. }
  515. else
  516. {
  517. pHolder->m_bAddForwarder = FALSE;
  518. }
  519. //
  520. // Try to load the root hints
  521. //
  522. if (pHolder->QueryForRootServerRecords(NULL))
  523. {
  524. nNextPage = CDNSServerWiz_FinishPropertyPage::IDD;
  525. pHolder->m_pFinishPage->m_nPrevPageID = IDD;
  526. pHolder->m_bAddRootHints = TRUE;
  527. }
  528. else
  529. {
  530. //
  531. // If they provided a forwarder then we don't care if root hints failed
  532. //
  533. nNextPage = CDNSServerWiz_FinishPropertyPage::IDD;
  534. pHolder->m_pFinishPage->m_nPrevPageID = IDD;
  535. }
  536. return nNextPage;
  537. }
  538. LRESULT CDNSServerWiz_ForwardersPropertyPage::OnWizardBack()
  539. {
  540. CDNSServerWizardHolder* pHolder = (CDNSServerWizardHolder*)GetHolder();
  541. UINT nPrevPage = static_cast<UINT>(-1);
  542. //
  543. // if we did not add a FWD zone, we skipped the reverse one too
  544. //
  545. UINT nScenario = pHolder->GetScenario();
  546. if (nScenario == CDNSServerWizardHolder::SmallBusiness)
  547. {
  548. if (pHolder->m_bAddFwdZone)
  549. {
  550. nPrevPage = pHolder->m_pZoneWiz->GetLastEntryPointPageID();
  551. }
  552. else
  553. {
  554. nPrevPage = m_nPrevPageID;
  555. }
  556. }
  557. else if (nScenario == CDNSServerWizardHolder::MediumBusiness)
  558. {
  559. if (!pHolder->m_bAddFwdZone)
  560. {
  561. nPrevPage = CDNSServerWiz_ConfigFwdZonePropertyPage::IDD;
  562. }
  563. else if (pHolder->m_bAddRevZone)
  564. {
  565. nPrevPage = pHolder->m_pZoneWiz->GetLastEntryPointPageID();
  566. }
  567. else
  568. {
  569. nPrevPage = CDNSServerWiz_ConfigRevZonePropertyPage::IDD;
  570. }
  571. }
  572. else
  573. {
  574. //
  575. // We should never get here
  576. //
  577. ASSERT(FALSE);
  578. nPrevPage = IDD;
  579. }
  580. return (LRESULT)nPrevPage;
  581. }
  582. void CDNSServerWiz_ForwardersPropertyPage::GetForwarder(CString& strref)
  583. {
  584. CDNSIPv4Control* pIPEdit = (CDNSIPv4Control*)GetDlgItem(IDC_IPEDIT);
  585. if (pIPEdit != NULL)
  586. {
  587. DWORD dwIPVal = 0;
  588. pIPEdit->GetIPv4Val(&dwIPVal);
  589. strref.Format(L"%d.%d.%d.%d", dwIPVal & 0xff,
  590. (dwIPVal >> 8) & 0xff,
  591. (dwIPVal >> 16) & 0xff,
  592. (dwIPVal >> 24) & 0xff);
  593. }
  594. CDNSIPv4Control* pIPEdit2 = (CDNSIPv4Control*)GetDlgItem(IDC_IPEDIT2);
  595. if (pIPEdit2 != NULL)
  596. {
  597. DWORD dwIPVal = 0;
  598. pIPEdit2->GetIPv4Val(&dwIPVal);
  599. if (dwIPVal != 0)
  600. {
  601. CString optionalValue;
  602. optionalValue.Format(L" %d.%d.%d.%d", dwIPVal & 0xff,
  603. (dwIPVal >> 8) & 0xff,
  604. (dwIPVal >> 16) & 0xff,
  605. (dwIPVal >> 24) & 0xff);
  606. strref += optionalValue;
  607. }
  608. }
  609. }
  610. BOOL CDNSServerWiz_ForwardersPropertyPage::OnApply()
  611. {
  612. LRESULT lCheck = SendDlgItemMessage(IDC_FORWARD_RADIO, BM_GETCHECK, 0, 0);
  613. if (lCheck == BST_CHECKED)
  614. {
  615. //
  616. // Set the forwarders IP address on the server
  617. //
  618. CPropertyPageHolderBase* pHolder = GetHolder();
  619. CTreeNode* pTreeNode = pHolder->GetTreeNode();
  620. CDNSServerNode* pServerNode = dynamic_cast<CDNSServerNode*>(pTreeNode);
  621. if (pServerNode != NULL)
  622. {
  623. DWORD dwCount = 0;
  624. DWORD dwIPArray[2];
  625. ZeroMemory(dwIPArray, sizeof(DWORD) * 2);
  626. CDNSIPv4Control* pIPEdit = (CDNSIPv4Control*)GetDlgItem(IDC_IPEDIT);
  627. if (pIPEdit != NULL)
  628. {
  629. DWORD dwIP = 0;
  630. pIPEdit->GetIPv4Val(&dwIP);
  631. if (dwIP != 0)
  632. {
  633. dwIPArray[0] = dwIP;
  634. ++dwCount;
  635. }
  636. }
  637. CDNSIPv4Control* pIPEdit2 = (CDNSIPv4Control*)GetDlgItem(IDC_IPEDIT2);
  638. if (pIPEdit2 != NULL)
  639. {
  640. DWORD dwIP = 0;
  641. pIPEdit2->GetIPv4Val(&dwIP);
  642. if (dwIP != 0)
  643. {
  644. dwIPArray[dwCount] = dwIP;
  645. ++dwCount;
  646. }
  647. }
  648. if (dwCount)
  649. {
  650. DNS_STATUS err = pServerNode->ResetForwarders(dwCount,
  651. dwIPArray,
  652. DNS_DEFAULT_FORWARD_TIMEOUT,
  653. DNS_DEFAULT_SLAVE);
  654. if (err != 0)
  655. {
  656. ::SetLastError(err);
  657. return FALSE;
  658. }
  659. }
  660. }
  661. }
  662. return TRUE;
  663. }
  664. ///////////////////////////////////////////////////////////////////////////////
  665. // CDNSServerWiz_SmallZoneTypePropertyPage
  666. void CDNSServerWiz_SmallZoneTypePropertyPage::OnWizardHelp()
  667. {
  668. CComPtr<IDisplayHelp> spHelp;
  669. HRESULT hr = GetHolder()->GetComponentData()->GetConsole()->QueryInterface(IID_IDisplayHelp, (void **)&spHelp);
  670. if (SUCCEEDED(hr))
  671. spHelp->ShowTopic(L"DNSConcepts.chm::/sag_DNS_CYDNS_03.htm");
  672. }
  673. CDNSServerWiz_SmallZoneTypePropertyPage::CDNSServerWiz_SmallZoneTypePropertyPage()
  674. : CPropertyPageBase(CDNSServerWiz_SmallZoneTypePropertyPage::IDD)
  675. {
  676. InitWiz97(FALSE,IDS_SERVWIZ_SMALL_ZONE_TYPE_TITLE,IDS_SERVWIZ_SMALL_ZONE_TYPE_SUBTITLE, true);
  677. }
  678. BOOL CDNSServerWiz_SmallZoneTypePropertyPage::OnInitDialog()
  679. {
  680. CPropertyPageBase::OnInitDialog();
  681. SendDlgItemMessage(IDC_PRIMARY_RADIO, BM_SETCHECK, BST_CHECKED, 0);
  682. return TRUE;
  683. }
  684. BOOL CDNSServerWiz_SmallZoneTypePropertyPage::OnSetActive()
  685. {
  686. GetHolder()->SetWizardButtonsMiddle(TRUE);
  687. return TRUE;
  688. }
  689. LRESULT CDNSServerWiz_SmallZoneTypePropertyPage::OnWizardNext()
  690. {
  691. CDNSServerWizardHolder* pHolder = (CDNSServerWizardHolder*)GetHolder();
  692. UINT nNextPage = 0;
  693. LRESULT lPrimaryCheck = SendDlgItemMessage(IDC_PRIMARY_RADIO, BM_GETCHECK, 0, 0);
  694. LRESULT lSecondaryCheck = SendDlgItemMessage(IDC_SECONDARY_RADIO, BM_GETCHECK, 0, 0);
  695. if (lPrimaryCheck == BST_CHECKED)
  696. {
  697. //
  698. // Set the state of the zone wizard
  699. //
  700. pHolder->m_bAddFwdZone = TRUE;
  701. nNextPage = pHolder->SetZoneWizardContextEx(TRUE,
  702. DNS_ZONE_TYPE_PRIMARY,
  703. pHolder->GetServerNode()->CanUseADS(),
  704. CDNSServerWiz_ForwardersPropertyPage::IDD, // next after wiz
  705. CDNSServerWiz_SmallZoneTypePropertyPage::IDD); // prev from wiz
  706. }
  707. else if (lSecondaryCheck == BST_CHECKED)
  708. {
  709. //
  710. // Set the state of the zone wizard
  711. //
  712. pHolder->m_bAddFwdZone = TRUE;
  713. nNextPage = pHolder->SetZoneWizardContextEx(TRUE,
  714. DNS_ZONE_TYPE_SECONDARY,
  715. FALSE,
  716. CDNSServerWiz_ForwardersPropertyPage::IDD, // next after wiz
  717. CDNSServerWiz_SmallZoneTypePropertyPage::IDD); // prev from wiz
  718. }
  719. else
  720. {
  721. nNextPage = IDD;
  722. }
  723. return (LRESULT)nNextPage;
  724. }
  725. LRESULT CDNSServerWiz_SmallZoneTypePropertyPage::OnWizardBack()
  726. {
  727. return (LRESULT)m_nPrevPageID;
  728. }
  729. ///////////////////////////////////////////////////////////////////////////////
  730. // CDNSServerWiz_NamePropertyPage
  731. BEGIN_MESSAGE_MAP(CDNSServerWiz_NamePropertyPage, CPropertyPageBase)
  732. ON_EN_CHANGE(IDC_EDIT_DNSSERVER, OnServerNameChange)
  733. END_MESSAGE_MAP()
  734. CDNSServerWiz_NamePropertyPage::CDNSServerWiz_NamePropertyPage()
  735. : CPropertyPageBase(CDNSServerWiz_NamePropertyPage::IDD)
  736. {
  737. InitWiz97(FALSE,IDS_SERVWIZ_NAME_TITLE,IDS_SERVWIZ_NAME_SUBTITLE, true);
  738. }
  739. void CDNSServerWiz_NamePropertyPage::OnWizardHelp()
  740. {
  741. CComPtr<IDisplayHelp> spHelp;
  742. HRESULT hr = GetHolder()->GetComponentData()->GetConsole()->QueryInterface(IID_IDisplayHelp, (void **)&spHelp);
  743. if (SUCCEEDED(hr))
  744. spHelp->ShowTopic(L"DNSConcepts.chm::/sag_DNS_CYDNS_04.htm");
  745. }
  746. void CDNSServerWiz_NamePropertyPage::OnServerNameChange()
  747. {
  748. CDNSServerWizardHolder* pHolder = (CDNSServerWizardHolder*)GetHolder();
  749. //
  750. // just check to be sure the editbox is not empty:
  751. //
  752. GetServerNameEdit()->GetWindowText(m_szServerName);
  753. m_szServerName.TrimLeft();
  754. m_szServerName.TrimRight();
  755. pHolder->SetWizardButtonsFirst(IsValidServerName(m_szServerName));
  756. }
  757. BOOL CDNSServerWiz_NamePropertyPage::OnSetActive()
  758. {
  759. CDNSServerWizardHolder* pHolder = (CDNSServerWizardHolder*)GetHolder();
  760. pHolder->SetWizardButtonsMiddle(IsValidServerName(m_szServerName));
  761. return TRUE;
  762. }
  763. LRESULT CDNSServerWiz_NamePropertyPage::OnWizardNext()
  764. {
  765. CDNSServerWizardHolder* pHolder = (CDNSServerWizardHolder*)GetHolder();
  766. pHolder->m_pServerNode->SetDisplayName(m_szServerName);
  767. UINT nNextPage = IDD; // default do not advance
  768. if (pHolder->QueryForRootServerRecords(NULL))
  769. {
  770. pHolder->m_bAddRootHints = TRUE;
  771. }
  772. // go to configure zones
  773. nNextPage = CDNSServerWiz_ConfigFwdZonePropertyPage::IDD;
  774. pHolder->m_pFwdZonePage->m_nPrevPageID = IDD;
  775. return nNextPage;
  776. }
  777. LRESULT CDNSServerWiz_NamePropertyPage::OnWizardBack()
  778. {
  779. return (LRESULT)m_nPrevPageID;
  780. }
  781. ///////////////////////////////////////////////////////////////////////////////
  782. // CDNSServerWiz_ConfigFwdZonePropertyPage
  783. void CDNSServerWiz_ConfigFwdZonePropertyPage::OnWizardHelp()
  784. {
  785. CComPtr<IDisplayHelp> spHelp;
  786. HRESULT hr = GetHolder()->GetComponentData()->GetConsole()->QueryInterface(IID_IDisplayHelp, (void **)&spHelp);
  787. if (SUCCEEDED(hr))
  788. spHelp->ShowTopic(L"DNSConcepts.chm::/sag_DNS_CYDNS_11.htm");
  789. }
  790. CDNSServerWiz_ConfigFwdZonePropertyPage::CDNSServerWiz_ConfigFwdZonePropertyPage()
  791. : CPropertyPageBase(CDNSServerWiz_ConfigFwdZonePropertyPage::IDD)
  792. {
  793. InitWiz97(FALSE,IDS_SERVWIZ_FWD_ZONE_TITLE,IDS_SERVWIZ_FWD_ZONE_SUBTITLE, true);
  794. }
  795. BOOL CDNSServerWiz_ConfigFwdZonePropertyPage::OnInitDialog()
  796. {
  797. CPropertyPageBase::OnInitDialog();
  798. BOOL bAddFwdZone = TRUE; // default in the UI
  799. CheckRadioButton(IDC_ZONE_RADIO, IDC_NO_ZONE_RADIO,
  800. bAddFwdZone ? IDC_ZONE_RADIO : IDC_NO_ZONE_RADIO);
  801. return TRUE;
  802. }
  803. BOOL CDNSServerWiz_ConfigFwdZonePropertyPage::OnSetActive()
  804. {
  805. GetHolder()->SetWizardButtonsMiddle(TRUE);
  806. return TRUE;
  807. }
  808. LRESULT CDNSServerWiz_ConfigFwdZonePropertyPage::OnWizardNext()
  809. {
  810. CDNSServerWizardHolder* pHolder = (CDNSServerWizardHolder*)GetHolder();
  811. pHolder->m_bAddFwdZone =
  812. (GetCheckedRadioButton(IDC_ZONE_RADIO, IDC_NO_ZONE_RADIO) ==
  813. IDC_ZONE_RADIO);
  814. UINT nNextPage = static_cast<UINT>(-1);
  815. if (pHolder->m_bAddFwdZone)
  816. {
  817. // move to reverse zone creation page
  818. nNextPage = pHolder->SetZoneWizardContext(TRUE,
  819. CDNSServerWiz_ConfigRevZonePropertyPage::IDD, // next after wiz
  820. CDNSServerWiz_ConfigFwdZonePropertyPage::IDD); // prev from wiz
  821. }
  822. else
  823. {
  824. pHolder->m_bAddRevZone = FALSE;
  825. // move to the finish page
  826. pHolder->m_pFinishPage->m_nPrevPageID = IDD;
  827. if (pHolder->GetScenario() == CDNSServerWizardHolder::MediumBusiness)
  828. {
  829. nNextPage = CDNSServerWiz_ForwardersPropertyPage::IDD;
  830. }
  831. else
  832. {
  833. nNextPage = CDNSServerWiz_FinishPropertyPage::IDD;
  834. }
  835. }
  836. return (LRESULT) nNextPage;
  837. }
  838. LRESULT CDNSServerWiz_ConfigFwdZonePropertyPage::OnWizardBack()
  839. {
  840. return (LRESULT)m_nPrevPageID;
  841. }
  842. ///////////////////////////////////////////////////////////////////////////////
  843. // CDNSServerWiz_ConfigRevZonePropertyPage
  844. void CDNSServerWiz_ConfigRevZonePropertyPage::OnWizardHelp()
  845. {
  846. CComPtr<IDisplayHelp> spHelp;
  847. HRESULT hr = GetHolder()->GetComponentData()->GetConsole()->QueryInterface(IID_IDisplayHelp, (void **)&spHelp);
  848. if (SUCCEEDED(hr))
  849. spHelp->ShowTopic(L"DNSConcepts.chm::/sag_DNS_CYDNS_16.htm");
  850. }
  851. CDNSServerWiz_ConfigRevZonePropertyPage::CDNSServerWiz_ConfigRevZonePropertyPage()
  852. : CPropertyPageBase(CDNSServerWiz_ConfigRevZonePropertyPage::IDD)
  853. {
  854. InitWiz97(FALSE,IDS_SERVWIZ_REV_ZONE_TITLE, IDS_SERVWIZ_REV_ZONE_SUBTITLE, true);
  855. }
  856. BOOL CDNSServerWiz_ConfigRevZonePropertyPage::OnInitDialog()
  857. {
  858. CPropertyPageBase::OnInitDialog();
  859. BOOL bAddRevZone = TRUE; // default in the UI
  860. CheckRadioButton(IDC_ZONE_RADIO, IDC_NO_ZONE_RADIO,
  861. bAddRevZone ? IDC_ZONE_RADIO : IDC_NO_ZONE_RADIO);
  862. return TRUE;
  863. }
  864. BOOL CDNSServerWiz_ConfigRevZonePropertyPage::OnSetActive()
  865. {
  866. GetHolder()->SetWizardButtonsMiddle(TRUE);
  867. return TRUE;
  868. }
  869. LRESULT CDNSServerWiz_ConfigRevZonePropertyPage::OnWizardNext()
  870. {
  871. CDNSServerWizardHolder* pHolder = (CDNSServerWizardHolder*)GetHolder();
  872. pHolder->m_bAddRevZone =
  873. (GetCheckedRadioButton(IDC_ZONE_RADIO, IDC_NO_ZONE_RADIO) ==
  874. IDC_ZONE_RADIO);
  875. UINT nNextPage = static_cast<UINT>(-1);
  876. if (pHolder->m_bAddRevZone)
  877. {
  878. if (pHolder->GetScenario() == CDNSServerWizardHolder::MediumBusiness)
  879. {
  880. nNextPage = pHolder->SetZoneWizardContext(FALSE,
  881. CDNSServerWiz_ForwardersPropertyPage::IDD, // next after wiz
  882. CDNSServerWiz_ConfigRevZonePropertyPage::IDD); // prev from wiz
  883. }
  884. else
  885. {
  886. nNextPage = pHolder->SetZoneWizardContextEx(FALSE,
  887. DNS_ZONE_TYPE_PRIMARY,
  888. pHolder->GetServerNode()->CanUseADS(),
  889. CDNSServerWiz_FinishPropertyPage::IDD, // next after wiz
  890. CDNSServerWiz_ConfigRevZonePropertyPage::IDD); // prev from wiz
  891. }
  892. }
  893. else
  894. {
  895. pHolder->m_pFinishPage->m_nPrevPageID = IDD;
  896. if (pHolder->GetScenario() == CDNSServerWizardHolder::MediumBusiness)
  897. {
  898. nNextPage = CDNSServerWiz_ForwardersPropertyPage::IDD;
  899. }
  900. else
  901. {
  902. nNextPage = CDNSServerWiz_FinishPropertyPage::IDD;
  903. }
  904. }
  905. return (LRESULT) nNextPage;
  906. }
  907. LRESULT CDNSServerWiz_ConfigRevZonePropertyPage::OnWizardBack()
  908. {
  909. CDNSServerWizardHolder* pHolder = (CDNSServerWizardHolder*)GetHolder();
  910. if (pHolder->m_bAddFwdZone)
  911. {
  912. pHolder->SetZoneWizardContext(TRUE,
  913. CDNSServerWiz_ConfigRevZonePropertyPage::IDD, // next after wiz
  914. CDNSServerWiz_ConfigFwdZonePropertyPage::IDD); // prev from wiz
  915. //
  916. // fwd settings
  917. //
  918. return (LRESULT)pHolder->m_pZoneWiz->GetLastEntryPointPageID();
  919. }
  920. else
  921. {
  922. return (LRESULT)CDNSServerWiz_ConfigFwdZonePropertyPage::IDD;
  923. }
  924. }
  925. ///////////////////////////////////////////////////////////////////////////////
  926. // CDNSServerWiz_FinishPropertyPage
  927. void CDNSServerWiz_FinishPropertyPage::OnWizardHelp()
  928. {
  929. CComPtr<IDisplayHelp> spHelp;
  930. HRESULT hr = GetHolder()->GetComponentData()->GetConsole()->QueryInterface(IID_IDisplayHelp, (void **)&spHelp);
  931. if (SUCCEEDED(hr))
  932. spHelp->ShowTopic(L"DNSConcepts.chm::/sag_DNS_CYDNS_08.htm");
  933. }
  934. CDNSServerWiz_FinishPropertyPage::CDNSServerWiz_FinishPropertyPage()
  935. : CPropertyPageBase(CDNSServerWiz_FinishPropertyPage::IDD)
  936. {
  937. InitWiz97(TRUE,0,0, true);
  938. }
  939. BOOL CDNSServerWiz_FinishPropertyPage::OnInitDialog()
  940. {
  941. CPropertyPageBase::OnInitDialog();
  942. SetBigBoldFont(m_hWnd, IDC_STATIC_COMPLETE);
  943. return TRUE;
  944. }
  945. BOOL CDNSServerWiz_FinishPropertyPage::OnSetActive()
  946. {
  947. CDNSServerWizardHolder* pHolder = (CDNSServerWizardHolder*)GetHolder();
  948. pHolder->SetWizardButtonsLast(TRUE);
  949. DisplaySummaryInfo(pHolder);
  950. // NTRAID#NTBUG9-451182-2001/09/12-lucios
  951. // NTRAID#NTBUG9-605428-2002/04/19-artm
  952. // I'm leaving old code here (but commented out) b/c design
  953. // might decide at later date to reenable different messages.
  954. // I want to leave the framework readily available.
  955. //
  956. // Note that to save localization work I've removed the strings
  957. // from the string table. What the messages were is included inline
  958. // below.
  959. CStatic* pStatic = (CStatic*)GetDlgItem(IDC_FINISH_STATIC);
  960. ASSERT(pStatic!=NULL);
  961. CString preamble, suffix;
  962. BOOL success;
  963. // Load the string to use for all wizard scenarios.
  964. success = preamble.LoadString(IDS_SERVWIZ_FINISH_NOTE_PREAMBLE);
  965. ASSERT(success != FALSE);
  966. //
  967. // Load any suffix strings that depend on the wizard scenario.
  968. //
  969. // If we are creating a new primary lookup zone (reverse or forward),
  970. // we need to tell the user a little bit more.
  971. if ( (pHolder->m_bAddFwdZone && pHolder->m_pFwdZoneInfo->m_bPrimary) ||
  972. (pHolder->m_bAddRevZone && pHolder->m_pRevZoneInfo->m_bPrimary) )
  973. {
  974. success = suffix.LoadString(IDS_SERVWIZ_FINISH_NOTE_PRIMARY_SUFFIX);
  975. ASSERT(success != FALSE);
  976. }
  977. pStatic->SetWindowText(preamble + suffix);
  978. //switch(pHolder->GetScenario())
  979. //{
  980. // case CDNSServerWizardHolder::SmallBusiness:
  981. // ASSERT(note.LoadString(IDS_SMALL_OPTION_NOTE)!=0);
  982. // note.LoadString(IDS_SMALL_OPTION_NOTE);
  983. // pStatic->SetWindowText(note);
  984. // // String was: "Note: You should now add records to the zone or ensure that records are updated dynamically. Also, ensure DNS clients use this server as their preferred DNS server and then verify name resolution using nslookup."
  985. // break;
  986. // case CDNSServerWizardHolder::MediumBusiness:
  987. // ASSERT(note.LoadString(IDS_MEDIUM_OPTION_NOTE)!=0);
  988. // note.LoadString(IDS_MEDIUM_OPTION_NOTE);
  989. // pStatic->SetWindowText(note);
  990. // // String was: "Note: You should now add records to the zones or ensure that records are updated dynamically. You might want to configure DNS clients to use this server as their preferred DNS server. You can then verify name resolution using nslookup."
  991. // break;
  992. // case CDNSServerWizardHolder::Manually:
  993. // ASSERT(note.LoadString(IDS_MANUAL_OPTION_NOTE)!=0);
  994. // note.LoadString(IDS_MANUAL_OPTION_NOTE);
  995. // pStatic->SetWindowText(note);
  996. // // String was: "Note: You might want to configure DNS clients to use this server as their preferred DNS server."
  997. // break;
  998. // default:
  999. // // Unexpected. Leave original resource message
  1000. // // that will be perceived as a bug
  1001. // ASSERT
  1002. // (
  1003. // (pHolder->GetScenario()!=CDNSServerWizardHolder::SmallBusiness) &&
  1004. // (pHolder->GetScenario()!=CDNSServerWizardHolder::MediumBusiness) &&
  1005. // (pHolder->GetScenario()!=CDNSServerWizardHolder::Manually)
  1006. // );
  1007. //}
  1008. return TRUE;
  1009. }
  1010. LRESULT CDNSServerWiz_FinishPropertyPage::OnWizardBack()
  1011. {
  1012. CDNSServerWizardHolder* pHolder = (CDNSServerWizardHolder*)GetHolder();
  1013. if (pHolder->GetScenario() == CDNSServerWizardHolder::SmallBusiness)
  1014. {
  1015. //
  1016. // Small business scenario
  1017. //
  1018. return (LRESULT)m_nPrevPageID;
  1019. }
  1020. else if (pHolder->GetScenario() == CDNSServerWizardHolder::MediumBusiness)
  1021. {
  1022. //
  1023. // Medium business scenario
  1024. //
  1025. return (LRESULT)m_nPrevPageID;
  1026. }
  1027. else
  1028. {
  1029. //
  1030. // Configure manually
  1031. //
  1032. return CDNSServerWiz_ScenarioPropertyPage::IDD;
  1033. }
  1034. return CDNSServerWiz_ScenarioPropertyPage::IDD;
  1035. }
  1036. BOOL CDNSServerWiz_FinishPropertyPage::OnWizardFinish()
  1037. {
  1038. CDNSServerWizardHolder* pHolder = (CDNSServerWizardHolder*)GetHolder();
  1039. pHolder->OnFinish(); // it might return T/F,
  1040. return TRUE; // we do put up error messages, but the wizard gets dismissed
  1041. }
  1042. void CDNSServerWiz_FinishPropertyPage::DisplaySummaryInfo(CDNSServerWizardHolder* pHolder)
  1043. {
  1044. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1045. CStatic* pStatic = (CStatic*)GetDlgItem(IDC_SUMMARY_STATIC);
  1046. // NOTICE-2002/04/11-artm Rewrote to use string functions
  1047. // in favor of wsprintf() (flagged by prefast and dangerous fctn
  1048. // to boot).
  1049. CString summary, buffer;
  1050. CString szFmt;
  1051. szFmt.LoadString(IDS_MSG_SERVWIZ_FINISH_NAME);
  1052. summary.Format(
  1053. static_cast<LPCTSTR>(szFmt),
  1054. static_cast<LPCTSTR>(pHolder->m_pServerNode->GetDisplayName()));
  1055. if (pHolder->m_bRootServer)
  1056. {
  1057. szFmt.LoadString(IDS_MSG_SERVWIZ_FINISH_ROOT_SERVER);
  1058. summary += szFmt;
  1059. }
  1060. if (pHolder->GetScenario() != CDNSServerWizardHolder::Manually)
  1061. {
  1062. if (pHolder->m_bAddFwdZone)
  1063. {
  1064. szFmt.LoadString(IDS_MSG_SERVWIZ_FINISH_FWD_ZONE);
  1065. buffer.Format(
  1066. static_cast<LPCTSTR>(szFmt),
  1067. static_cast<LPCTSTR>(pHolder->m_pFwdZoneInfo->m_szZoneName));
  1068. summary += buffer;
  1069. }
  1070. if (pHolder->m_bAddRevZone)
  1071. {
  1072. szFmt.LoadString(IDS_MSG_SERVWIZ_FINISH_REV_ZONE);
  1073. buffer.Format(
  1074. static_cast<LPCTSTR>(szFmt),
  1075. static_cast<LPCTSTR>(pHolder->m_pRevZoneInfo->m_szZoneName));
  1076. summary += buffer;
  1077. }
  1078. if (pHolder->m_bAddForwarder)
  1079. {
  1080. CString szForwarder;
  1081. pHolder->m_pForwardersPage->GetForwarder(szForwarder);
  1082. if (!szForwarder.IsEmpty())
  1083. {
  1084. szFmt.LoadString(IDS_MSG_SERVWIZ_FINISH_FORWARDER);
  1085. buffer.Format(
  1086. static_cast<LPCTSTR>(szFmt),
  1087. static_cast<LPCTSTR>(szForwarder));
  1088. summary += buffer;
  1089. }
  1090. }
  1091. }
  1092. pStatic->SetWindowText(summary);
  1093. }
  1094. ///////////////////////////////////////////////////////////////////////////////
  1095. // CDNSServerWizardHolder
  1096. CDNSServerWizardHolder::CDNSServerWizardHolder(CDNSRootData* pRootData,
  1097. CComponentDataObject* pComponentData, CDNSServerNode* pServerNode, BOOL bHideUI)
  1098. : CPropertyPageHolderBase(pRootData, pServerNode, pComponentData)
  1099. {
  1100. m_bWizardMode = TRUE;
  1101. // assume this object will have to be destroyed from the autside
  1102. m_bAutoDelete = FALSE;
  1103. m_forceContextHelpButton = forceOff;
  1104. ASSERT(pRootData != NULL);
  1105. ASSERT(pComponentData != NULL);
  1106. m_bSkipNamePage = FALSE;
  1107. m_bHideUI = bHideUI;
  1108. m_dwDnsSetupFlags = 0;
  1109. // initialize options settings (by default do nothing)
  1110. m_bRootServer = FALSE;
  1111. m_bHasRootZone = FALSE;
  1112. m_bAddFwdZone = FALSE;
  1113. m_bAddRevZone = FALSE;
  1114. m_bAddRootHints = FALSE;
  1115. m_bAddForwarder = FALSE;
  1116. m_nScenario = SmallBusiness;
  1117. // execution state and error codes
  1118. if (pServerNode == NULL)
  1119. {
  1120. m_pServerNode = new CDNSServerNode(NULL);
  1121. m_bServerNodeExists = FALSE;
  1122. }
  1123. else
  1124. {
  1125. m_pServerNode = pServerNode;
  1126. m_bSkipNamePage = TRUE;
  1127. m_bServerNodeExists = TRUE;
  1128. }
  1129. m_bServerNodeAdded = FALSE;
  1130. m_bRootHintsAdded = FALSE;
  1131. m_bRootZoneAdded = FALSE;
  1132. m_bFwdZoneAdded = FALSE;
  1133. m_bRevZoneAdded = FALSE;
  1134. // always create
  1135. m_pFwdZoneInfo = new CDNSCreateZoneInfo;
  1136. m_pRevZoneInfo = new CDNSCreateZoneInfo;
  1137. if (m_pServerNode &&
  1138. m_pServerNode->GetDomainVersion() > DS_BEHAVIOR_WIN2000)
  1139. {
  1140. m_pFwdZoneInfo->m_replType = domain;
  1141. m_pRevZoneInfo->m_replType = domain;
  1142. }
  1143. else
  1144. {
  1145. m_pFwdZoneInfo->m_replType = w2k;
  1146. m_pRevZoneInfo->m_replType = w2k;
  1147. }
  1148. // embedded zone wizards hookup
  1149. if (m_bHideUI)
  1150. {
  1151. m_pZoneWiz = NULL;
  1152. }
  1153. else
  1154. {
  1155. m_pZoneWiz = new CDNSZoneWizardHolder(pComponentData);
  1156. m_pZoneWiz->SetServerNode(m_pServerNode);
  1157. m_pZoneWiz->Initialize(NULL, FALSE);
  1158. m_pZoneWiz->Attach(this);
  1159. }
  1160. m_pRootHintsRecordList = NULL;
  1161. // property pages insertion
  1162. if (m_bHideUI)
  1163. {
  1164. m_pStartPage = NULL;
  1165. m_pScenarioPage = NULL;
  1166. m_pSmallZoneTypePage = NULL;
  1167. m_pNamePage = NULL;
  1168. m_pFwdZonePage = NULL;
  1169. m_pRevZonePage = NULL;
  1170. m_pFinishPage = NULL;
  1171. }
  1172. else
  1173. {
  1174. m_pStartPage = new CDNSServerWiz_StartPropertyPage;
  1175. if (m_pStartPage)
  1176. {
  1177. AddPageToList((CPropertyPageBase*)m_pStartPage);
  1178. }
  1179. m_pScenarioPage = new CDNSServerWiz_ScenarioPropertyPage;
  1180. if (m_pScenarioPage)
  1181. {
  1182. AddPageToList((CPropertyPageBase*)m_pScenarioPage);
  1183. }
  1184. m_pForwardersPage = new CDNSServerWiz_ForwardersPropertyPage;
  1185. if (m_pForwardersPage)
  1186. {
  1187. AddPageToList((CPropertyPageBase*)m_pForwardersPage);
  1188. }
  1189. m_pSmallZoneTypePage = new CDNSServerWiz_SmallZoneTypePropertyPage;
  1190. if (m_pSmallZoneTypePage)
  1191. {
  1192. AddPageToList((CPropertyPageBase*)m_pSmallZoneTypePage);
  1193. }
  1194. m_pNamePage = new CDNSServerWiz_NamePropertyPage;
  1195. if (m_pNamePage)
  1196. {
  1197. AddPageToList((CPropertyPageBase*)m_pNamePage);
  1198. }
  1199. m_pFwdZonePage = new CDNSServerWiz_ConfigFwdZonePropertyPage;
  1200. if (m_pFwdZonePage)
  1201. {
  1202. AddPageToList((CPropertyPageBase*)m_pFwdZonePage);
  1203. }
  1204. m_pRevZonePage = new CDNSServerWiz_ConfigRevZonePropertyPage;
  1205. if (m_pRevZonePage)
  1206. {
  1207. AddPageToList((CPropertyPageBase*)m_pRevZonePage);
  1208. }
  1209. m_pFinishPage = new CDNSServerWiz_FinishPropertyPage;
  1210. if (m_pFinishPage)
  1211. {
  1212. AddPageToList((CPropertyPageBase*)m_pFinishPage);
  1213. }
  1214. }
  1215. }
  1216. CDNSServerWizardHolder::~CDNSServerWizardHolder()
  1217. {
  1218. delete m_pZoneWiz;
  1219. SetRootHintsRecordList(NULL);
  1220. if ( (m_pServerNode != NULL) && !m_bServerNodeAdded && !m_bServerNodeExists)
  1221. delete m_pServerNode;
  1222. }
  1223. void CDNSServerWizardHolder::DoModalConnect()
  1224. {
  1225. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1226. CThemeContextActivator activator;
  1227. HWND hWnd = GetMainWindow();
  1228. CWnd* pParentWnd = CWnd::FromHandle(hWnd);
  1229. CNewServerDialog dlg(this, pParentWnd);
  1230. if (IDOK != dlg.DoModal())
  1231. return; // canceled
  1232. if (!dlg.m_bConfigure)
  1233. return; // already added
  1234. // we have to configure, call the wizard
  1235. m_bSkipNamePage = TRUE;
  1236. DoModalWizard();
  1237. GetComponentData()->GetRootData()->SetDirtyFlag(TRUE);
  1238. }
  1239. void CDNSServerWizardHolder::DoModalConnectOnLocalComputer()
  1240. {
  1241. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1242. // get the name of the local machine
  1243. DWORD dwLen = MAX_COMPUTERNAME_LENGTH+1;
  1244. CString szServerName;
  1245. BOOL bRes = ::GetComputerName(szServerName.GetBuffer(dwLen),
  1246. &dwLen);
  1247. ASSERT(dwLen <= MAX_COMPUTERNAME_LENGTH);
  1248. szServerName.ReleaseBuffer();
  1249. if (!bRes)
  1250. {
  1251. szServerName = _T("localhost.");
  1252. }
  1253. m_pServerNode->SetDisplayName(szServerName);
  1254. m_pServerNode->SetLocalServer(TRUE);
  1255. // try to contact server
  1256. BOOL bAlreadyConfigured = FALSE;
  1257. HWND hWnd = GetMainWindow();
  1258. if (0 != GetServerInfo(&bAlreadyConfigured, hWnd))
  1259. {
  1260. // failed to contact local server, just call the
  1261. // normal "connect to" dialog and wizard
  1262. DoModalConnect();
  1263. }
  1264. else
  1265. {
  1266. // server successfully contacted
  1267. if (bAlreadyConfigured)
  1268. {
  1269. // server is already setup, just insert in the UI
  1270. InsertServerIntoUI();
  1271. }
  1272. else
  1273. {
  1274. // need to configure, invoke wizard proper
  1275. m_bSkipNamePage = TRUE;
  1276. InsertServerIntoUI();
  1277. }
  1278. }
  1279. }
  1280. UINT CDNSServerWizardHolder::SetZoneWizardContext(BOOL bForward,
  1281. UINT nNextPage,
  1282. UINT nPrevPage)
  1283. {
  1284. ASSERT(m_pFwdZoneInfo != NULL);
  1285. ASSERT(m_pRevZoneInfo != NULL);
  1286. TRACE(_T("SetZoneWizardContext(%d)\n"),bForward);
  1287. if (bForward)
  1288. {
  1289. m_pZoneWiz->SetZoneInfoPtr(m_pFwdZoneInfo);
  1290. m_pZoneWiz->SetContextPages(nNextPage, nPrevPage);
  1291. }
  1292. else
  1293. {
  1294. m_pZoneWiz->SetZoneInfoPtr(m_pRevZoneInfo);
  1295. m_pZoneWiz->SetContextPages(nNextPage, nPrevPage);
  1296. }
  1297. m_pZoneWiz->PreSetZoneLookupType(bForward);
  1298. return m_pZoneWiz->GetFirstEntryPointPageID();
  1299. }
  1300. UINT CDNSServerWizardHolder::SetZoneWizardContextEx(BOOL bForward,
  1301. UINT nZoneType,
  1302. BOOL bADIntegrated,
  1303. UINT nNextPage,
  1304. UINT nPrevPage)
  1305. {
  1306. ASSERT(m_pFwdZoneInfo != NULL);
  1307. ASSERT(m_pRevZoneInfo != NULL);
  1308. TRACE(_T("SetZoneWizardContext(%d)\n"),bForward);
  1309. if (bForward)
  1310. {
  1311. m_pZoneWiz->SetZoneInfoPtr(m_pFwdZoneInfo);
  1312. m_pZoneWiz->SetContextPages(nNextPage, nPrevPage);
  1313. }
  1314. else
  1315. {
  1316. m_pZoneWiz->SetZoneInfoPtr(m_pRevZoneInfo);
  1317. m_pZoneWiz->SetContextPages(nNextPage, nPrevPage);
  1318. }
  1319. m_pZoneWiz->PreSetZoneLookupTypeEx(bForward, nZoneType, bADIntegrated);
  1320. return m_pZoneWiz->GetFirstEntryPointPageID();
  1321. }
  1322. HRESULT CDNSServerWizardHolder::OnAddPage(int, CPropertyPageBase* pPage)
  1323. {
  1324. if (pPage != NULL)
  1325. {
  1326. UINT_PTR nPageID = (UINT_PTR)pPage->m_psp.pszTemplate;
  1327. if (nPageID == CDNSServerWiz_ConfigFwdZonePropertyPage::IDD)
  1328. {
  1329. ASSERT(m_pZoneWiz != NULL);
  1330. VERIFY(SUCCEEDED(m_pZoneWiz->AddAllPagesToSheet()));
  1331. }
  1332. }
  1333. return S_OK;
  1334. }
  1335. DWORD CDNSServerWizardHolder::GetServerInfo(BOOL* pbAlreadyConfigured, HWND parentHwnd)
  1336. {
  1337. TRACE_FUNCTION_IF_NO_UI(m_bHideUI, CDNSServerWizardHolder::GetServerInfo);
  1338. CThemeContextActivator activator;
  1339. CContactServerThread* pThreadObj =
  1340. new CContactServerThread(
  1341. m_pServerNode->GetRPCName(),
  1342. (pbAlreadyConfigured != NULL));
  1343. if (!pThreadObj)
  1344. {
  1345. return ERROR_OUTOFMEMORY;
  1346. }
  1347. CWnd* pParentWnd = CWnd::FromHandle(parentHwnd);
  1348. TRACE_LOGFILE_IF_NO_UI(m_bHideUI, L"Contacting server...");
  1349. CLongOperationDialog dlg(pThreadObj, pParentWnd, IDR_SEARCH_AVI);
  1350. VERIFY(dlg.LoadTitleString(IDS_MSG_SERVWIZ_CONTACT));
  1351. dlg.m_bExecuteNoUI = m_bHideUI;
  1352. dlg.DoModal();
  1353. DWORD dwErr = 0;
  1354. if (!dlg.m_bAbandoned)
  1355. {
  1356. dwErr = pThreadObj->GetError();
  1357. if (dwErr == 0)
  1358. {
  1359. CDNSServerInfoEx* pInfoEx = pThreadObj->DetachInfo();
  1360. ASSERT(pInfoEx != NULL);
  1361. m_pServerNode->AttachServerInfo(pInfoEx);
  1362. CDNSRootHintsNode* pNewRootHints = pThreadObj->DetachRootHintsNode();
  1363. if (pNewRootHints != NULL)
  1364. {
  1365. // root hints can be null on a root server
  1366. m_pServerNode->AttachRootHints(pNewRootHints);
  1367. TRACE_LOGFILE_IF_NO_UI(m_bHideUI, L"Attaching root hints...");
  1368. }
  1369. if (pbAlreadyConfigured != NULL)
  1370. {
  1371. *pbAlreadyConfigured = pThreadObj->IsAlreadyConfigured();
  1372. }
  1373. }
  1374. }
  1375. return dwErr;
  1376. }
  1377. BOOL CDNSServerWizardHolder::QueryForRootServerRecords(IP_ADDRESS* pIpAddr)
  1378. {
  1379. CThemeContextActivator activator;
  1380. // clear the current list of root hint info
  1381. SetRootHintsRecordList(NULL);
  1382. // create a thread object and set the name of servers to query
  1383. CRootHintsQueryThread* pThreadObj = new CRootHintsQueryThread;
  1384. if (pThreadObj == NULL)
  1385. {
  1386. ASSERT(FALSE);
  1387. return FALSE;
  1388. }
  1389. if (pIpAddr == NULL)
  1390. {
  1391. CRootData* pRootData = GetRootData();
  1392. if (!pRootData->HasChildren() && (m_pServerNode == NULL))
  1393. return FALSE;
  1394. VERIFY(pThreadObj->LoadServerNames(pRootData, m_pServerNode));
  1395. }
  1396. else
  1397. {
  1398. // if IP address given, try it
  1399. pThreadObj->LoadIPAddresses(1, pIpAddr);
  1400. }
  1401. // create a dialog and attach the thread to it
  1402. HWND hWnd = GetMainWindow();
  1403. CWnd* pParentWnd = CWnd::FromHandle(hWnd);
  1404. CLongOperationDialog dlg(pThreadObj, pParentWnd, IDR_SEARCH_AVI);
  1405. VERIFY(dlg.LoadTitleString(IDS_MSG_SERVWIZ_COLLECTINFO));
  1406. dlg.m_bExecuteNoUI = m_bHideUI;
  1407. dlg.DoModal();
  1408. if (!dlg.m_bAbandoned)
  1409. {
  1410. if (pThreadObj->GetError() != 0)
  1411. {
  1412. if (!m_bHideUI && (pIpAddr != NULL))
  1413. DNSMessageBox(IDS_MSG_SERVWIZ_FAIL_ROOT_HINTS);
  1414. }
  1415. else
  1416. {
  1417. // success, get the root hints info to the holder
  1418. SetRootHintsRecordList(pThreadObj->GetHintsRecordList());
  1419. TraceRootHints(m_pRootHintsRecordList);
  1420. }
  1421. return (pThreadObj->GetError() == 0);
  1422. }
  1423. return FALSE;
  1424. }
  1425. void CDNSServerWizardHolder::InsertServerIntoUI()
  1426. {
  1427. ASSERT(!m_bHideUI);
  1428. // insert the server in the UI
  1429. ASSERT(m_pServerNode != NULL);
  1430. if (!m_bServerNodeAdded)
  1431. {
  1432. GetRootData()->AddServer(m_pServerNode,GetComponentData());
  1433. m_bServerNodeAdded = TRUE;
  1434. }
  1435. }
  1436. BOOL CDNSServerWizardHolder::OnFinish()
  1437. {
  1438. USES_CONVERSION;
  1439. CString szLastErrorMessage;
  1440. BOOL bRet = TRUE;
  1441. DNS_STATUS dwErr = 0;
  1442. TRACE_FUNCTION_IF_NO_UI(m_bHideUI, CDNSServerWizardHolder::OnFinish);
  1443. do // false loop
  1444. {
  1445. if (m_bHideUI)
  1446. {
  1447. //
  1448. // insert into list of servers, but not in the UI
  1449. //
  1450. GetRootData()->AddChildToList(m_pServerNode);
  1451. m_bServerNodeAdded = TRUE;
  1452. }
  1453. else
  1454. {
  1455. //
  1456. // force the node to expand and wait for completion
  1457. // only if not called from the empty snapin scenario (auto insertion)
  1458. //
  1459. if (m_pServerNode->IsExpanded() && !m_bServerNodeExists)
  1460. {
  1461. EnumerateMTNodeHelper(m_pServerNode, GetComponentData());
  1462. }
  1463. }
  1464. if (m_bAddRootHints && m_pRootHintsRecordList != NULL)
  1465. {
  1466. //
  1467. // Root hints were detected automatically. Add them now.
  1468. //
  1469. dwErr = InitializeRootHintsList();
  1470. TRACE_LOGFILE_IF_NO_UI(m_bHideUI, L"InitializeRootHintsList() returned dwErr = 0x%x", dwErr);
  1471. if (dwErr == 0)
  1472. {
  1473. m_bRootHintsAdded = TRUE;
  1474. }
  1475. else
  1476. {
  1477. bRet = FALSE;
  1478. if (!m_bHideUI)
  1479. {
  1480. DNSErrorDialog(dwErr, IDS_MSG_SERVWIZ_FAIL_UPDATE_ROOT_HINTS);
  1481. }
  1482. else
  1483. {
  1484. ::SetLastError(dwErr);
  1485. }
  1486. DNSCreateErrorMessage(dwErr, IDS_MSG_SERVWIZ_FAIL_UPDATE_ROOT_HINTS, szLastErrorMessage);
  1487. break; // false loop
  1488. }
  1489. }
  1490. else
  1491. {
  1492. if (!m_bHideUI)
  1493. {
  1494. DNSMessageBox(IDS_ERR_PRIME_ROOT_HINTS, MB_OK | MB_ICONERROR);
  1495. }
  1496. }
  1497. //
  1498. // zone creation: root
  1499. //
  1500. if (m_bRootServer && !m_bRootZoneAdded && !m_bHideUI)
  1501. {
  1502. //
  1503. // for a root server, need to create a root zone
  1504. //
  1505. CDNSCreateZoneInfo rootZoneInfo;
  1506. rootZoneInfo.m_bPrimary = TRUE;
  1507. rootZoneInfo.m_bForward = TRUE;
  1508. rootZoneInfo.m_szZoneName = _T(".");
  1509. rootZoneInfo.m_szZoneStorage = _T("root.dns");
  1510. rootZoneInfo.m_storageType = CDNSCreateZoneInfo::newFile;
  1511. //
  1512. // dynamic turned off for security reasons...
  1513. //
  1514. rootZoneInfo.m_nDynamicUpdate = ZONE_UPDATE_OFF;
  1515. dwErr = CDNSZoneWizardHolder::CreateZoneHelper(m_pServerNode,
  1516. &rootZoneInfo,
  1517. GetComponentData());
  1518. TRACE_LOGFILE_IF_NO_UI(m_bHideUI, L"Root Zone creation returned dwErr = 0x%x", dwErr);
  1519. if (dwErr != 0)
  1520. {
  1521. bRet = FALSE;
  1522. if (!m_bHideUI)
  1523. {
  1524. DNSErrorDialog(dwErr, IDS_MSG_SERVWIZ_FAIL_ADD_ROOT_ZONE);
  1525. }
  1526. else
  1527. {
  1528. ::SetLastError(dwErr);
  1529. }
  1530. DNSCreateErrorMessage(dwErr, IDS_MSG_SERVWIZ_FAIL_ADD_ROOT_ZONE, szLastErrorMessage);
  1531. break; // false loop
  1532. }
  1533. else
  1534. {
  1535. m_bRootZoneAdded = TRUE;
  1536. }
  1537. }
  1538. // zone creation: forward lookup zone
  1539. if (m_bAddFwdZone &&
  1540. !m_bFwdZoneAdded &&
  1541. GetScenario() != CDNSServerWizardHolder::Manually)
  1542. {
  1543. if (m_bHideUI)
  1544. {
  1545. // Add a DCPromo zone
  1546. TRACE_LOGFILE(L"Creating forward lookup zone for DCPromo.");
  1547. dwErr =
  1548. ::DnssrvCreateZoneForDcPromoEx(
  1549. m_pServerNode->GetRPCName(),
  1550. W_TO_UTF8(m_pFwdZoneInfo->m_szZoneName),
  1551. W_TO_UTF8(m_pFwdZoneInfo->m_szZoneStorage),
  1552. DNS_ZONE_CREATE_FOR_DCPROMO);
  1553. // NTRAID#NTBUG9-359894-2001/06/09-sburns
  1554. if (dwErr == 0 && (m_dwDnsSetupFlags & DNS_SETUP_ZONE_CREATE_FOR_DCPROMO_FOREST))
  1555. {
  1556. // need to make string instances because the l_a_m_e W_TO_UTF8 macro
  1557. // can't take an expression as a parameter.
  1558. CString zone(L"_msdcs." + m_pFwdZoneInfo->m_szZoneName);
  1559. CString stor(L"_msdcs." + m_pFwdZoneInfo->m_szZoneStorage);
  1560. dwErr =
  1561. ::DnssrvCreateZoneForDcPromoEx(
  1562. m_pServerNode->GetRPCName(),
  1563. W_TO_UTF8(zone),
  1564. W_TO_UTF8(stor),
  1565. DNS_ZONE_CREATE_FOR_DCPROMO_FOREST);
  1566. }
  1567. if (m_dwDnsSetupFlags & DNS_SETUP_AUTOCONFIG_CLIENT)
  1568. {
  1569. // NTRAID#NTBUG9-489252-2001/11/08-sburns
  1570. DWORD dwflags = DNS_RPC_AUTOCONFIG_ALL;
  1571. dwErr =
  1572. ::DnssrvOperation(
  1573. m_pServerNode->GetRPCName(),
  1574. NULL,
  1575. DNSSRV_OP_AUTO_CONFIGURE,
  1576. DNSSRV_TYPEID_DWORD,
  1577. (PVOID) (DWORD_PTR) dwflags);
  1578. }
  1579. }
  1580. else
  1581. {
  1582. dwErr = CDNSZoneWizardHolder::CreateZoneHelper(m_pServerNode,
  1583. m_pFwdZoneInfo,
  1584. GetComponentData());
  1585. }
  1586. TRACE_LOGFILE_IF_NO_UI(m_bHideUI, L"FWD Zone creation returned dwErr = 0x%x", dwErr);
  1587. if (dwErr != 0)
  1588. {
  1589. bRet = FALSE;
  1590. if (!m_bHideUI)
  1591. {
  1592. DNSErrorDialog(dwErr, IDS_MSG_SERVWIZ_FAIL_ADD_FWD_ZONE);
  1593. }
  1594. else
  1595. {
  1596. ::SetLastError(dwErr);
  1597. }
  1598. DNSCreateErrorMessage(dwErr, IDS_MSG_SERVWIZ_FAIL_ADD_FWD_ZONE, szLastErrorMessage);
  1599. break; // false loop
  1600. }
  1601. else
  1602. {
  1603. m_bFwdZoneAdded = TRUE;
  1604. }
  1605. }
  1606. // zone creation: reverse lookup zone (only if FWD creation)
  1607. if (m_bAddRevZone &&
  1608. !m_bRevZoneAdded &&
  1609. GetScenario() != CDNSServerWizardHolder::Manually)
  1610. {
  1611. if (m_bHideUI)
  1612. {
  1613. // Add a DCPromo zone
  1614. TRACE_LOGFILE(L"Creating reverse lookup zone for DCPromo.");
  1615. dwErr =
  1616. ::DnssrvCreateZoneForDcPromoEx(
  1617. m_pServerNode->GetRPCName(),
  1618. W_TO_UTF8(m_pRevZoneInfo->m_szZoneName),
  1619. W_TO_UTF8(m_pRevZoneInfo->m_szZoneStorage),
  1620. 0);
  1621. }
  1622. else
  1623. {
  1624. dwErr = CDNSZoneWizardHolder::CreateZoneHelper(m_pServerNode,
  1625. m_pRevZoneInfo,
  1626. GetComponentData());
  1627. }
  1628. TRACE_LOGFILE_IF_NO_UI(m_bHideUI, L"REV Zone creation returned dwErr = 0x%x", dwErr);
  1629. if (dwErr != 0)
  1630. {
  1631. bRet = FALSE;
  1632. if (!m_bHideUI)
  1633. {
  1634. DNSErrorDialog(dwErr, IDS_MSG_SERVWIZ_FAIL_ADD_REV_ZONE);
  1635. }
  1636. else
  1637. {
  1638. ::SetLastError(dwErr);
  1639. }
  1640. DNSCreateErrorMessage(dwErr, IDS_MSG_SERVWIZ_FAIL_ADD_REV_ZONE, szLastErrorMessage);
  1641. break; // false loop
  1642. }
  1643. else
  1644. {
  1645. m_bRevZoneAdded = TRUE;
  1646. }
  1647. }
  1648. //
  1649. // Depending on the scenario we might need to add forwarders
  1650. //
  1651. if (!m_bHideUI)
  1652. {
  1653. switch (GetScenario())
  1654. {
  1655. case SmallBusiness:
  1656. case MediumBusiness:
  1657. {
  1658. if (m_pForwardersPage != NULL)
  1659. {
  1660. if (!m_pForwardersPage->OnApply())
  1661. {
  1662. bRet = FALSE;
  1663. dwErr = ::GetLastError();
  1664. if (dwErr != 0)
  1665. {
  1666. DNSErrorDialog(dwErr, IDS_MSG_SERVWIZ_FAIL_FORWARDERS);
  1667. DNSCreateErrorMessage(dwErr, IDS_MSG_SERVWIZ_FAIL_FORWARDERS, szLastErrorMessage);
  1668. }
  1669. }
  1670. }
  1671. }
  1672. break;
  1673. case Manually:
  1674. default:
  1675. break;
  1676. }
  1677. }
  1678. //
  1679. // Have the server set the regkey that says we are configured
  1680. //
  1681. dwErr = m_pServerNode->SetServerConfigured();
  1682. if (dwErr != 0)
  1683. {
  1684. bRet = FALSE;
  1685. if (!m_bHideUI)
  1686. {
  1687. DNSErrorDialog(dwErr, IDS_MSG_SERVWIZ_FAIL_SERVER_CONFIGURED);
  1688. }
  1689. else
  1690. {
  1691. ::SetLastError(dwErr);
  1692. }
  1693. DNSCreateErrorMessage(dwErr, IDS_MSG_SERVWIZ_FAIL_SERVER_CONFIGURED, szLastErrorMessage);
  1694. break; // false loop
  1695. }
  1696. } while (false);
  1697. //
  1698. // Now update the regkey with the error message if we failed
  1699. //
  1700. if (!bRet && !szLastErrorMessage.IsEmpty())
  1701. {
  1702. dwErr = WriteResultsToRegkeyForCYS(szLastErrorMessage);
  1703. ASSERT(dwErr == 0);
  1704. }
  1705. // Now refresh the server node so that we pick up all the changes
  1706. if (!m_bHideUI)
  1707. {
  1708. CNodeList nodeList;
  1709. nodeList.AddTail(m_pServerNode);
  1710. m_pServerNode->OnRefresh(
  1711. GetComponentData(),
  1712. &nodeList);
  1713. }
  1714. return bRet;
  1715. }
  1716. #define CYS_KEY L"Software\\Microsoft\\Windows NT\\CurrentVersion\\srvWiz"
  1717. #define DNSWIZ_KEY L"DnsWizResult"
  1718. LONG CDNSServerWizardHolder::WriteResultsToRegkeyForCYS(PCWSTR pszLastErrorMessage)
  1719. {
  1720. CRegKey regkeysrvWiz;
  1721. LONG lRes = regkeysrvWiz.Open(HKEY_LOCAL_MACHINE, CYS_KEY);
  1722. if (lRes == ERROR_SUCCESS)
  1723. {
  1724. lRes = regkeysrvWiz.SetValue(pszLastErrorMessage, DNSWIZ_KEY);
  1725. }
  1726. return lRes;
  1727. }
  1728. DNS_STATUS CDNSServerWizardHolder::InitializeRootHintsList()
  1729. {
  1730. ASSERT(m_pServerNode != NULL);
  1731. ASSERT(m_pRootHintsRecordList != NULL);
  1732. CDNSRootHintsNode* pRootHintsNode = m_pServerNode->GetRootHints();
  1733. ASSERT(pRootHintsNode != NULL);
  1734. if (pRootHintsNode == NULL)
  1735. {
  1736. return -1; // bogus ret code
  1737. }
  1738. return pRootHintsNode->InitializeFromDnsQueryData(m_pRootHintsRecordList);
  1739. }
  1740. HRESULT CDNSServerWizardHolder::DnsSetup(LPCWSTR lpszFwdZoneName,
  1741. LPCWSTR lpszFwdZoneFileName,
  1742. LPCWSTR lpszRevZoneName,
  1743. LPCWSTR lpszRevZoneFileName,
  1744. DWORD dwFlags)
  1745. {
  1746. TRACE_FUNCTION(CDNSServerWizardHolder::DnsSetup);
  1747. TRACE(L"CDNSServerWizardHolder::DnsSetup(\n%s,\n%s,\n%s,\n%s,\n0x%x)\n",
  1748. lpszFwdZoneName,
  1749. lpszFwdZoneFileName,
  1750. lpszRevZoneName,
  1751. lpszRevZoneFileName,
  1752. dwFlags);
  1753. // Save the flags for later use in OnFinish
  1754. m_dwDnsSetupFlags = dwFlags;
  1755. ASSERT(m_bHideUI);
  1756. // set the name of the server to configure to the local host
  1757. m_pServerNode->SetDisplayName(_T("127.0.0.1"));
  1758. // if needed, add forward lookup zone
  1759. if ((lpszFwdZoneName != NULL) && (lpszFwdZoneFileName != NULL))
  1760. {
  1761. TRACE_LOGFILE(L"Setting FWD lookup Zone Info");
  1762. m_pFwdZoneInfo->m_szZoneName = lpszFwdZoneName;
  1763. m_pFwdZoneInfo->m_szZoneStorage = lpszFwdZoneFileName;
  1764. m_pFwdZoneInfo->m_nDynamicUpdate = ZONE_UPDATE_UNSECURE;
  1765. m_bAddFwdZone = TRUE;
  1766. }
  1767. // if needed, add a reverse lookup zone
  1768. if ((lpszRevZoneName != NULL) && (lpszRevZoneFileName != NULL))
  1769. {
  1770. TRACE_LOGFILE(L"Setting REV lookup Zone Info");
  1771. m_pRevZoneInfo->m_bForward = FALSE;
  1772. m_pRevZoneInfo->m_szZoneName = lpszRevZoneName;
  1773. m_pRevZoneInfo->m_szZoneStorage = lpszRevZoneFileName;
  1774. m_pRevZoneInfo->m_nDynamicUpdate = ZONE_UPDATE_UNSECURE;
  1775. m_bAddRevZone = TRUE;
  1776. }
  1777. // try to contact server
  1778. BOOL bAlreadyConfigured = FALSE;
  1779. TRACE(L"calling GetServerInfo()\n");
  1780. HWND hWnd = GetMainWindow();
  1781. DWORD dwErr = GetServerInfo(&bAlreadyConfigured, hWnd);
  1782. if (0 != dwErr)
  1783. {
  1784. TRACE_LOGFILE(L"GetServerInfo() failed, dwErr = 0x%x", dwErr);
  1785. return HRESULT_FROM_WIN32(dwErr); // something is wrong, cannot contact
  1786. }
  1787. //
  1788. // Check to see if this is a root server
  1789. //
  1790. dwErr = ServerHasRootZone(m_pServerNode->GetRPCName(), &m_bHasRootZone);
  1791. if (m_bHasRootZone)
  1792. {
  1793. TRACE_LOGFILE(L"Has root zone: m_bHasRootZone = 0x%x", m_bHasRootZone);
  1794. m_bRootServer = FALSE;
  1795. }
  1796. else
  1797. {
  1798. TRACE_LOGFILE(L"Does not have root zone: m_bHasRootZone = 0x%x", m_bHasRootZone);
  1799. // need to configure server
  1800. // 1. try to find the root hints
  1801. BOOL bRootHints = QueryForRootServerRecords(NULL);
  1802. // if root hints not found, make it a root server
  1803. if (!bRootHints)
  1804. {
  1805. TRACE_LOGFILE(L"root hints not found");
  1806. TRACE_LOGFILE(L"Server needs root zone: m_bHasRootZone = 0x%x", m_bHasRootZone);
  1807. m_bRootServer = TRUE;
  1808. }
  1809. else
  1810. {
  1811. m_bAddRootHints = TRUE;
  1812. }
  1813. }
  1814. BOOL bFinish = OnFinish();
  1815. HRESULT hr = S_OK;
  1816. if (!bFinish)
  1817. {
  1818. dwErr = ::GetLastError();
  1819. TRACE_LOGFILE(L"OnFinish failed with error: 0x%x", dwErr);
  1820. hr = HRESULT_FROM_WIN32(dwErr);
  1821. }
  1822. return hr;
  1823. }
  1824. //////////////////////////////////////////////////////////////////////
  1825. // CContactServerThread
  1826. CContactServerThread::CContactServerThread(LPCTSTR lpszServerName,
  1827. BOOL bCheckConfigured)
  1828. {
  1829. ASSERT(lpszServerName != NULL);
  1830. m_szServerName = lpszServerName;
  1831. m_bCheckConfigured = bCheckConfigured;
  1832. m_bAlreadyConfigured = FALSE;
  1833. m_pServerInfoEx = new CDNSServerInfoEx;
  1834. m_pRootHintsNode = NULL;
  1835. }
  1836. CContactServerThread::~CContactServerThread()
  1837. {
  1838. if (m_pServerInfoEx != NULL)
  1839. delete m_pServerInfoEx;
  1840. if (m_pRootHintsNode != NULL)
  1841. delete m_pRootHintsNode;
  1842. }
  1843. CDNSServerInfoEx* CContactServerThread::DetachInfo()
  1844. {
  1845. CDNSServerInfoEx* pInfo = m_pServerInfoEx;
  1846. m_pServerInfoEx = NULL;
  1847. return pInfo;
  1848. }
  1849. CDNSRootHintsNode* CContactServerThread::DetachRootHintsNode()
  1850. {
  1851. CDNSRootHintsNode* pRootHints = m_pRootHintsNode;
  1852. m_pRootHintsNode = NULL;
  1853. return pRootHints;
  1854. }
  1855. void CContactServerThread::OnDoAction()
  1856. {
  1857. USES_CONVERSION;
  1858. // query the server to find out if it has a root zone
  1859. BOOL bHasRootZone = FALSE;
  1860. m_dwErr = ::ServerHasRootZone(m_szServerName, &bHasRootZone);
  1861. if (m_dwErr != 0)
  1862. return;
  1863. // if there is not a root zone, the server is not authoritated for the root
  1864. // so create the root hints folder and ask it to query for NS and A records
  1865. if (!bHasRootZone)
  1866. {
  1867. CDNSRootHintsNode* pRootHintsNode = new CDNSRootHintsNode;
  1868. if (pRootHintsNode)
  1869. {
  1870. m_dwErr = pRootHintsNode->QueryForRootHints(m_szServerName, 0x0 /*version not known yet*/);
  1871. }
  1872. else
  1873. {
  1874. m_dwErr = ERROR_OUTOFMEMORY;
  1875. }
  1876. if (m_dwErr != 0)
  1877. {
  1878. delete pRootHintsNode;
  1879. return;
  1880. }
  1881. m_pRootHintsNode = pRootHintsNode;
  1882. }
  1883. // get server info
  1884. m_dwErr = m_pServerInfoEx->Query(m_szServerName);
  1885. if (m_dwErr != 0)
  1886. return;
  1887. // if needed verify if the server has been configured
  1888. if (!m_bCheckConfigured)
  1889. return;
  1890. DWORD dwFilter = ZONE_REQUEST_FORWARD | ZONE_REQUEST_REVERSE |
  1891. ZONE_REQUEST_PRIMARY | ZONE_REQUEST_SECONDARY;
  1892. PDNS_RPC_ZONE_LIST pZoneList = NULL;
  1893. m_dwErr = ::DnssrvEnumZones(
  1894. m_szServerName,
  1895. dwFilter,
  1896. NULL /*pszLastZone, unused for the moment */,
  1897. &pZoneList);
  1898. if (m_dwErr == 0)
  1899. {
  1900. if (pZoneList != NULL)
  1901. {
  1902. m_bAlreadyConfigured = pZoneList->dwZoneCount > 0;
  1903. ::DnssrvFreeZoneList(pZoneList);
  1904. }
  1905. }
  1906. }
  1907. //////////////////////////////////////////////////////////////////////
  1908. // CRootHintsQueryThread
  1909. CRootHintsQueryThread::CRootHintsQueryThread()
  1910. {
  1911. m_pRootHintsRecordList = NULL;
  1912. m_pServerNamesArr = NULL;
  1913. m_nServerNames = 0;
  1914. m_nIPCount = 0;
  1915. m_ipArray = NULL;
  1916. }
  1917. CRootHintsQueryThread::~CRootHintsQueryThread()
  1918. {
  1919. if (m_pServerNamesArr != NULL)
  1920. delete[] m_pServerNamesArr;
  1921. if (m_ipArray != NULL)
  1922. free(m_ipArray);
  1923. if (m_pRootHintsRecordList != NULL)
  1924. DnsRecordListFree(m_pRootHintsRecordList, DnsFreeRecordListDeep);
  1925. }
  1926. BOOL CRootHintsQueryThread::LoadServerNames(CRootData* pRootData,
  1927. CDNSServerNode* pServerNode)
  1928. {
  1929. ASSERT(pRootData != NULL);
  1930. ASSERT(pServerNode != NULL);
  1931. CNodeList* pServerList = pRootData->GetContainerChildList();
  1932. INT_PTR nCount = pServerList->GetCount();
  1933. POSITION pos;
  1934. CNodeList* pChildList = pRootData->GetContainerChildList();
  1935. // look if the server node has been already added
  1936. BOOL bAddServer = TRUE;
  1937. for (pos = pChildList->GetHeadPosition(); pos != NULL; )
  1938. {
  1939. CDNSServerNode* pCurrServerNode = (CDNSServerNode*)pChildList->GetNext(pos);
  1940. if (pCurrServerNode == pServerNode)
  1941. {
  1942. bAddServer = FALSE;
  1943. break;
  1944. }
  1945. }
  1946. if (bAddServer)
  1947. nCount++;
  1948. if (nCount == 0)
  1949. return FALSE;
  1950. m_nServerNames = static_cast<DWORD>(nCount);
  1951. m_pServerNamesArr = new CString[nCount];
  1952. if (!m_pServerNamesArr)
  1953. {
  1954. return FALSE;
  1955. }
  1956. int k = 0;
  1957. // fill in the array of server names
  1958. for (pos = pChildList->GetHeadPosition(); pos != NULL; )
  1959. {
  1960. CDNSServerNode* pCurrServerNode = (CDNSServerNode*)pChildList->GetNext(pos);
  1961. m_pServerNamesArr[k] = pCurrServerNode->GetDisplayName();
  1962. k++;
  1963. }
  1964. if (bAddServer)
  1965. m_pServerNamesArr[m_nServerNames-1] = pServerNode->GetDisplayName();
  1966. return TRUE;
  1967. }
  1968. void CRootHintsQueryThread::LoadIPAddresses(DWORD cCount, PIP_ADDRESS ipArr)
  1969. {
  1970. ASSERT(cCount > 0);
  1971. ASSERT(ipArr != NULL);
  1972. ASSERT(m_nIPCount == 0);
  1973. ASSERT(m_ipArray == NULL);
  1974. m_nIPCount = cCount;
  1975. m_ipArray = (IP_ADDRESS*)malloc(m_nIPCount*sizeof(IP_ADDRESS));
  1976. if (m_ipArray != NULL)
  1977. {
  1978. memcpy(m_ipArray, ipArr, m_nIPCount*sizeof(IP_ADDRESS));
  1979. }
  1980. }
  1981. PDNS_RECORD CRootHintsQueryThread::GetHintsRecordList()
  1982. {
  1983. PDNS_RECORD pList = m_pRootHintsRecordList;
  1984. if (m_pRootHintsRecordList != NULL)
  1985. {
  1986. m_pRootHintsRecordList = NULL; // tansfer ownership
  1987. }
  1988. return pList;
  1989. }
  1990. void CRootHintsQueryThread::OnDoAction()
  1991. {
  1992. if (m_ipArray != NULL)
  1993. QueryServersOnIPArray();
  1994. else
  1995. {
  1996. // try first the default server on the wire
  1997. QueryAllServers();
  1998. if (m_dwErr != 0)
  1999. {
  2000. // try the list of servers provided
  2001. ASSERT(m_pRootHintsRecordList == NULL);
  2002. if (m_pServerNamesArr != NULL)
  2003. QueryServersOnServerNames();
  2004. }
  2005. }
  2006. }
  2007. void CRootHintsQueryThread::QueryAllServers()
  2008. {
  2009. m_dwErr = ::DnsQuery(_T("."), DNS_TYPE_NS, DNS_QUERY_STANDARD, NULL, &m_pRootHintsRecordList, NULL);
  2010. }
  2011. void CRootHintsQueryThread::QueryServersOnServerNames()
  2012. {
  2013. ASSERT(m_nIPCount == 0);
  2014. ASSERT(m_ipArray == NULL);
  2015. ASSERT(m_pServerNamesArr != NULL);
  2016. ASSERT(m_nServerNames > 0);
  2017. DNS_STATUS dwLastErr = 0;
  2018. // allocate array of A record lists
  2019. PDNS_RECORD* pHostRecordsArr = (PDNS_RECORD*)malloc(m_nServerNames*sizeof(PDNS_RECORD));
  2020. if (!pHostRecordsArr)
  2021. {
  2022. return;
  2023. }
  2024. memset(pHostRecordsArr, 0x0,m_nServerNames*sizeof(PDNS_RECORD));
  2025. // allocate an array of IP addresses possibly coming from server names
  2026. PIP_ADDRESS ipArrayFromNames = (PIP_ADDRESS)malloc(m_nServerNames*sizeof(IP_ADDRESS));
  2027. if (!ipArrayFromNames)
  2028. {
  2029. return;
  2030. }
  2031. do // false loop
  2032. {
  2033. DWORD nIPCountFromNames = 0;
  2034. // loop thru the list of names in the array
  2035. for (DWORD k = 0; k < m_nServerNames; k++)
  2036. {
  2037. IP_ADDRESS ipAddr = IPStringToAddr(m_pServerNamesArr[k]);
  2038. if (ipAddr == INADDR_NONE)
  2039. {
  2040. // host name, build a list of A records by calling DNSQuery()
  2041. dwLastErr = ::DnsQuery((LPTSTR)(LPCTSTR)m_pServerNamesArr[k], DNS_TYPE_A,
  2042. DNS_QUERY_STANDARD, NULL, &pHostRecordsArr[k], NULL);
  2043. }
  2044. else
  2045. {
  2046. // IP address, add to the list
  2047. ipArrayFromNames[nIPCountFromNames++] = ipAddr;
  2048. }
  2049. }
  2050. // count the # of IP Addresses we have in the A record list
  2051. DWORD nIPCountFromARec = 0;
  2052. for (k=0; k < m_nServerNames; k++)
  2053. {
  2054. PDNS_RECORD pTemp = pHostRecordsArr[k];
  2055. while (pTemp != NULL)
  2056. {
  2057. nIPCountFromARec++;
  2058. pTemp = pTemp->pNext;
  2059. }
  2060. }
  2061. m_nIPCount = nIPCountFromARec + nIPCountFromNames;
  2062. if (m_nIPCount == 0)
  2063. {
  2064. ASSERT(m_ipArray == NULL);
  2065. ASSERT(dwLastErr != 0);
  2066. m_dwErr = (DWORD)dwLastErr;
  2067. break; // we did not get any address to query with
  2068. }
  2069. // build an array of IP addresses to pass to DnsQuery()
  2070. m_ipArray = (IP_ADDRESS*)malloc(m_nIPCount*sizeof(IP_ADDRESS));
  2071. if (m_ipArray != NULL)
  2072. {
  2073. memset(m_ipArray, 0x0, m_nIPCount*sizeof(IP_ADDRESS));
  2074. }
  2075. else
  2076. {
  2077. break;
  2078. }
  2079. //scan the array of lists of A records we just found
  2080. PIP_ADDRESS pCurrAddr = m_ipArray;
  2081. for (k=0; k < m_nServerNames; k++)
  2082. {
  2083. PDNS_RECORD pTemp = pHostRecordsArr[k];
  2084. while (pTemp != NULL)
  2085. {
  2086. CString szTemp;
  2087. FormatIpAddress(szTemp, pTemp->Data.A.IpAddress);
  2088. TRACE(_T("found address[%d] = %s\n"), k, (LPCTSTR)szTemp);
  2089. *pCurrAddr = pTemp->Data.A.IpAddress;
  2090. pTemp = pTemp->pNext;
  2091. pCurrAddr++;
  2092. }
  2093. }
  2094. // if any, attach the original IP addresses from names
  2095. for (k=0; k < nIPCountFromNames; k++)
  2096. {
  2097. *pCurrAddr = ipArrayFromNames[k];
  2098. pCurrAddr++;
  2099. }
  2100. ASSERT(pCurrAddr == m_ipArray+m_nIPCount);
  2101. // free up the lists of A records
  2102. for (k=0; k < m_nServerNames; k++)
  2103. {
  2104. if (pHostRecordsArr[k] != NULL)
  2105. ::DnsRecordListFree(pHostRecordsArr[k], DnsFreeRecordListDeep);
  2106. }
  2107. // finally can query on IP array just created
  2108. QueryServersOnIPArray();
  2109. } while (false);
  2110. if (pHostRecordsArr)
  2111. {
  2112. free(pHostRecordsArr);
  2113. pHostRecordsArr = 0;
  2114. }
  2115. if (ipArrayFromNames)
  2116. {
  2117. free(ipArrayFromNames);
  2118. ipArrayFromNames = 0;
  2119. }
  2120. }
  2121. void CRootHintsQueryThread::QueryServersOnIPArray()
  2122. {
  2123. ASSERT(m_nIPCount > 0);
  2124. ASSERT(m_ipArray != NULL);
  2125. CString szTemp;
  2126. for(DWORD k = 0; k < m_nIPCount; k++)
  2127. {
  2128. FormatIpAddress(szTemp, m_ipArray[k]);
  2129. TRACE(_T("m_ipArray[%d] = %s\n"), k, (LPCTSTR)szTemp);
  2130. }
  2131. // have to syntesize an IP_ARRAY (hack)
  2132. PIP_ARRAY pipArr = (PIP_ARRAY)malloc(sizeof(DWORD)+sizeof(IP_ADDRESS)*m_nIPCount);
  2133. if (pipArr)
  2134. {
  2135. pipArr->AddrCount = m_nIPCount;
  2136. memcpy(pipArr->AddrArray, m_ipArray, sizeof(IP_ADDRESS)*m_nIPCount);
  2137. m_dwErr = ::DnsQuery(_T("."), DNS_TYPE_NS, DNS_QUERY_BYPASS_CACHE, pipArr, &m_pRootHintsRecordList, NULL);
  2138. free(pipArr);
  2139. pipArr = 0;
  2140. }
  2141. }