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

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